2015-01-07 Robert Dewar <dewar@adacore.com>
[official-gcc.git] / gcc / ada / sem_prag.adb
blobacae793f17c7c302c987b61d9d91943059688d4c
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 Ghost; use Ghost;
45 with Lib; use Lib;
46 with Lib.Writ; use Lib.Writ;
47 with Lib.Xref; use Lib.Xref;
48 with Namet.Sp; use Namet.Sp;
49 with Nlists; use Nlists;
50 with Nmake; use Nmake;
51 with Output; use Output;
52 with Par_SCO; use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident; use Rident;
55 with Rtsfind; use Rtsfind;
56 with Sem; use Sem;
57 with Sem_Aux; use Sem_Aux;
58 with Sem_Ch3; use Sem_Ch3;
59 with Sem_Ch6; use Sem_Ch6;
60 with Sem_Ch8; use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res; use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_Warn; use Sem_Warn;
73 with Stand; use Stand;
74 with Sinfo; use Sinfo;
75 with Sinfo.CN; use Sinfo.CN;
76 with Sinput; use Sinput;
77 with Stringt; use Stringt;
78 with Stylesw; use Stylesw;
79 with Table;
80 with Targparm; use Targparm;
81 with Tbuild; use Tbuild;
82 with Ttypes;
83 with Uintp; use Uintp;
84 with Uname; use Uname;
85 with Urealp; use Urealp;
86 with Validsw; use Validsw;
87 with Warnsw; use Warnsw;
89 package body Sem_Prag is
91 ----------------------------------------------
92 -- Common Handling of Import-Export Pragmas --
93 ----------------------------------------------
95 -- In the following section, a number of Import_xxx and Export_xxx pragmas
96 -- are defined by GNAT. These are compatible with the DEC pragmas of the
97 -- same name, and all have the following common form and processing:
99 -- pragma Export_xxx
100 -- [Internal =>] LOCAL_NAME
101 -- [, [External =>] EXTERNAL_SYMBOL]
102 -- [, other optional parameters ]);
104 -- pragma Import_xxx
105 -- [Internal =>] LOCAL_NAME
106 -- [, [External =>] EXTERNAL_SYMBOL]
107 -- [, other optional parameters ]);
109 -- EXTERNAL_SYMBOL ::=
110 -- IDENTIFIER
111 -- | static_string_EXPRESSION
113 -- The internal LOCAL_NAME designates the entity that is imported or
114 -- exported, and must refer to an entity in the current declarative
115 -- part (as required by the rules for LOCAL_NAME).
117 -- The external linker name is designated by the External parameter if
118 -- given, or the Internal parameter if not (if there is no External
119 -- parameter, the External parameter is a copy of the Internal name).
121 -- If the External parameter is given as a string, then this string is
122 -- treated as an external name (exactly as though it had been given as an
123 -- External_Name parameter for a normal Import pragma).
125 -- If the External parameter is given as an identifier (or there is no
126 -- External parameter, so that the Internal identifier is used), then
127 -- the external name is the characters of the identifier, translated
128 -- to all lower case letters.
130 -- Note: the external name specified or implied by any of these special
131 -- Import_xxx or Export_xxx pragmas override an external or link name
132 -- specified in a previous Import or Export pragma.
134 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
135 -- named notation, following the standard rules for subprogram calls, i.e.
136 -- parameters can be given in any order if named notation is used, and
137 -- positional and named notation can be mixed, subject to the rule that all
138 -- positional parameters must appear first.
140 -- Note: All these pragmas are implemented exactly following the DEC design
141 -- and implementation and are intended to be fully compatible with the use
142 -- of these pragmas in the DEC Ada compiler.
144 --------------------------------------------
145 -- Checking for Duplicated External Names --
146 --------------------------------------------
148 -- It is suspicious if two separate Export pragmas use the same external
149 -- name. The following table is used to diagnose this situation so that
150 -- an appropriate warning can be issued.
152 -- The Node_Id stored is for the N_String_Literal node created to hold
153 -- the value of the external name. The Sloc of this node is used to
154 -- cross-reference the location of the duplication.
156 package Externals is new Table.Table (
157 Table_Component_Type => Node_Id,
158 Table_Index_Type => Int,
159 Table_Low_Bound => 0,
160 Table_Initial => 100,
161 Table_Increment => 100,
162 Table_Name => "Name_Externals");
164 -------------------------------------
165 -- Local Subprograms and Variables --
166 -------------------------------------
168 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id);
169 -- Subsidiary routine to the analysis of pragmas Depends, Global and
170 -- Refined_State. Append an entity to a list. If the list is empty, create
171 -- a new list.
173 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
174 -- This routine is used for possible casing adjustment of an explicit
175 -- external name supplied as a string literal (the node N), according to
176 -- the casing requirement of Opt.External_Name_Casing. If this is set to
177 -- As_Is, then the string literal is returned unchanged, but if it is set
178 -- to Uppercase or Lowercase, then a new string literal with appropriate
179 -- casing is constructed.
181 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
182 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
183 -- Query whether a particular item appears in a mixed list of nodes and
184 -- entities. It is assumed that all nodes in the list have entities.
186 function Check_Kind (Nam : Name_Id) return Name_Id;
187 -- This function is used in connection with pragmas Assert, Check,
188 -- and assertion aspects and pragmas, to determine if Check pragmas
189 -- (or corresponding assertion aspects or pragmas) are currently active
190 -- as determined by the presence of -gnata on the command line (which
191 -- sets the default), and the appearance of pragmas Check_Policy and
192 -- Assertion_Policy as configuration pragmas either in a configuration
193 -- pragma file, or at the start of the current unit, or locally given
194 -- Check_Policy and Assertion_Policy pragmas that are currently active.
196 -- The value returned is one of the names Check, Ignore, Disable (On
197 -- returns Check, and Off returns Ignore).
199 -- Note: for assertion kinds Pre'Class, Post'Class, Invariant'Class,
200 -- and Type_Invariant'Class, the name passed is Name_uPre, Name_uPost,
201 -- Name_uInvariant, or Name_uType_Invariant, which corresponds to _Pre,
202 -- _Post, _Invariant, or _Type_Invariant, which are special names used
203 -- in identifiers to represent these attribute references.
205 procedure Check_SPARK_Aspect_For_ASIS (N : Node_Id);
206 -- In ASIS mode we need to analyze the original expression in the aspect
207 -- specification. For Initializes, Global, and related SPARK aspects, the
208 -- expression has a sui-generis syntax which may be a list, an expression,
209 -- or an aggregate.
211 procedure Check_State_And_Constituent_Use
212 (States : Elist_Id;
213 Constits : Elist_Id;
214 Context : Node_Id);
215 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
216 -- Global and Initializes. Determine whether a state from list States and a
217 -- corresponding constituent from list Constits (if any) appear in the same
218 -- context denoted by Context. If this is the case, emit an error.
220 function Find_Related_Subprogram_Or_Body
221 (Prag : Node_Id;
222 Do_Checks : Boolean := False) return Node_Id;
223 -- Subsidiary to the analysis of pragmas Contract_Cases, Depends, Global,
224 -- Refined_Depends, Refined_Global and Refined_Post. Find the declaration
225 -- of the related subprogram [body or stub] subject to pragma Prag. If flag
226 -- Do_Checks is set, the routine reports duplicate pragmas and detects
227 -- improper use of refinement pragmas in stand alone expression functions.
228 -- The returned value depends on the related pragma as follows:
229 -- 1) Pragmas Contract_Cases, Depends and Global yield the corresponding
230 -- N_Subprogram_Declaration node or if the pragma applies to a stand
231 -- alone body, the N_Subprogram_Body node or Empty if illegal.
232 -- 2) Pragmas Refined_Depends, Refined_Global and Refined_Post yield
233 -- N_Subprogram_Body or N_Subprogram_Body_Stub nodes or Empty if
234 -- illegal.
236 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
237 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
238 -- original one, following the renaming chain) is returned. Otherwise the
239 -- entity is returned unchanged. Should be in Einfo???
241 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
242 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
243 -- Get_SPARK_Mode_Type. Convert a name into a corresponding value of type
244 -- SPARK_Mode_Type.
246 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
247 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
248 -- Determine whether dependency clause Clause is surrounded by extra
249 -- parentheses. If this is the case, issue an error message.
251 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
252 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
253 -- pragma Depends. Determine whether the type of dependency item Item is
254 -- tagged, unconstrained array, unconstrained record or a record with at
255 -- least one unconstrained component.
257 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id);
258 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
259 -- of a Test_Case pragma if present (possibly Empty). We treat these as
260 -- spec expressions (i.e. similar to a default expression).
262 procedure Record_Possible_Body_Reference
263 (State_Id : Entity_Id;
264 Ref : Node_Id);
265 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
266 -- Global. Given an abstract state denoted by State_Id and a reference Ref
267 -- to it, determine whether the reference appears in a package body that
268 -- will eventually refine the state. If this is the case, record the
269 -- reference for future checks (see Analyze_Refined_State_In_Decls).
271 procedure Resolve_State (N : Node_Id);
272 -- Handle the overloading of state names by functions. When N denotes a
273 -- function, this routine finds the corresponding state and sets the entity
274 -- of N to that of the state.
276 procedure Rewrite_Assertion_Kind (N : Node_Id);
277 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
278 -- then it is rewritten as an identifier with the corresponding special
279 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas
280 -- Check, Check_Policy.
282 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
283 -- Place semantic information on the argument of an Elaborate/Elaborate_All
284 -- pragma. Entity name for unit and its parents is taken from item in
285 -- previous with_clause that mentions the unit.
287 Dummy : Integer := 0;
288 pragma Volatile (Dummy);
289 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
291 procedure ip;
292 pragma No_Inline (ip);
293 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
294 -- is just to help debugging the front end. If a pragma Inspection_Point
295 -- is added to a source program, then breaking on ip will get you to that
296 -- point in the program.
298 procedure rv;
299 pragma No_Inline (rv);
300 -- This is a dummy function called by the processing for pragma Reviewable.
301 -- It is there for assisting front end debugging. By placing a Reviewable
302 -- pragma in the source program, a breakpoint on rv catches this place in
303 -- the source, allowing convenient stepping to the point of interest.
305 --------------
306 -- Add_Item --
307 --------------
309 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id) is
310 begin
311 Append_New_Elmt (Item, To => To_List);
312 end Add_Item;
314 -------------------------------
315 -- Adjust_External_Name_Case --
316 -------------------------------
318 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
319 CC : Char_Code;
321 begin
322 -- Adjust case of literal if required
324 if Opt.External_Name_Exp_Casing = As_Is then
325 return N;
327 else
328 -- Copy existing string
330 Start_String;
332 -- Set proper casing
334 for J in 1 .. String_Length (Strval (N)) loop
335 CC := Get_String_Char (Strval (N), J);
337 if Opt.External_Name_Exp_Casing = Uppercase
338 and then CC >= Get_Char_Code ('a')
339 and then CC <= Get_Char_Code ('z')
340 then
341 Store_String_Char (CC - 32);
343 elsif Opt.External_Name_Exp_Casing = Lowercase
344 and then CC >= Get_Char_Code ('A')
345 and then CC <= Get_Char_Code ('Z')
346 then
347 Store_String_Char (CC + 32);
349 else
350 Store_String_Char (CC);
351 end if;
352 end loop;
354 return
355 Make_String_Literal (Sloc (N),
356 Strval => End_String);
357 end if;
358 end Adjust_External_Name_Case;
360 -----------------------------------------
361 -- Analyze_Contract_Cases_In_Decl_Part --
362 -----------------------------------------
364 procedure Analyze_Contract_Cases_In_Decl_Part (N : Node_Id) is
365 Others_Seen : Boolean := False;
367 procedure Analyze_Contract_Case (CCase : Node_Id);
368 -- Verify the legality of a single contract case
370 ---------------------------
371 -- Analyze_Contract_Case --
372 ---------------------------
374 procedure Analyze_Contract_Case (CCase : Node_Id) is
375 Case_Guard : Node_Id;
376 Conseq : Node_Id;
377 Extra_Guard : Node_Id;
379 begin
380 if Nkind (CCase) = N_Component_Association then
381 Case_Guard := First (Choices (CCase));
382 Conseq := Expression (CCase);
384 -- Each contract case must have exactly one case guard
386 Extra_Guard := Next (Case_Guard);
388 if Present (Extra_Guard) then
389 Error_Msg_N
390 ("contract case must have exactly one case guard",
391 Extra_Guard);
392 end if;
394 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
396 if Nkind (Case_Guard) = N_Others_Choice then
397 if Others_Seen then
398 Error_Msg_N
399 ("only one others choice allowed in contract cases",
400 Case_Guard);
401 else
402 Others_Seen := True;
403 end if;
405 elsif Others_Seen then
406 Error_Msg_N
407 ("others must be the last choice in contract cases", N);
408 end if;
410 -- Preanalyze the case guard and consequence
412 if Nkind (Case_Guard) /= N_Others_Choice then
413 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
414 end if;
416 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
418 -- The contract case is malformed
420 else
421 Error_Msg_N ("wrong syntax in contract case", CCase);
422 end if;
423 end Analyze_Contract_Case;
425 -- Local variables
427 All_Cases : Node_Id;
428 CCase : Node_Id;
429 Subp_Decl : Node_Id;
430 Subp_Id : Entity_Id;
432 Restore_Scope : Boolean := False;
433 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
435 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
437 begin
438 Set_Analyzed (N);
440 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
441 Subp_Id := Defining_Entity (Subp_Decl);
442 All_Cases := Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
444 -- Single and multiple contract cases must appear in aggregate form. If
445 -- this is not the case, then either the parser of the analysis of the
446 -- pragma failed to produce an aggregate.
448 pragma Assert (Nkind (All_Cases) = N_Aggregate);
450 if No (Component_Associations (All_Cases)) then
451 Error_Msg_N ("wrong syntax for constract cases", N);
453 -- Individual contract cases appear as component associations
455 else
456 -- Ensure that the formal parameters are visible when analyzing all
457 -- clauses. This falls out of the general rule of aspects pertaining
458 -- to subprogram declarations. Skip the installation for subprogram
459 -- bodies because the formals are already visible.
461 if not In_Open_Scopes (Subp_Id) then
462 Restore_Scope := True;
463 Push_Scope (Subp_Id);
464 Install_Formals (Subp_Id);
465 end if;
467 CCase := First (Component_Associations (All_Cases));
468 while Present (CCase) loop
469 Analyze_Contract_Case (CCase);
470 Next (CCase);
471 end loop;
473 if Restore_Scope then
474 End_Scope;
475 end if;
476 end if;
477 end Analyze_Contract_Cases_In_Decl_Part;
479 ----------------------------------
480 -- Analyze_Depends_In_Decl_Part --
481 ----------------------------------
483 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
484 Loc : constant Source_Ptr := Sloc (N);
486 All_Inputs_Seen : Elist_Id := No_Elist;
487 -- A list containing the entities of all the inputs processed so far.
488 -- The list is populated with unique entities because the same input
489 -- may appear in multiple input lists.
491 All_Outputs_Seen : Elist_Id := No_Elist;
492 -- A list containing the entities of all the outputs processed so far.
493 -- The list is populated with unique entities because output items are
494 -- unique in a dependence relation.
496 Constits_Seen : Elist_Id := No_Elist;
497 -- A list containing the entities of all constituents processed so far.
498 -- It aids in detecting illegal usage of a state and a corresponding
499 -- constituent in pragma [Refinde_]Depends.
501 Global_Seen : Boolean := False;
502 -- A flag set when pragma Global has been processed
504 Null_Output_Seen : Boolean := False;
505 -- A flag used to track the legality of a null output
507 Result_Seen : Boolean := False;
508 -- A flag set when Subp_Id'Result is processed
510 Spec_Id : Entity_Id;
511 -- The entity of the subprogram subject to pragma [Refined_]Depends
513 States_Seen : Elist_Id := No_Elist;
514 -- A list containing the entities of all states processed so far. It
515 -- helps in detecting illegal usage of a state and a corresponding
516 -- constituent in pragma [Refined_]Depends.
518 Subp_Id : Entity_Id;
519 -- The entity of the subprogram [body or stub] subject to pragma
520 -- [Refined_]Depends.
522 Subp_Inputs : Elist_Id := No_Elist;
523 Subp_Outputs : Elist_Id := No_Elist;
524 -- Two lists containing the full set of inputs and output of the related
525 -- subprograms. Note that these lists contain both nodes and entities.
527 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
528 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
529 -- to the name buffer. The individual kinds are as follows:
530 -- E_Abstract_State - "state"
531 -- E_In_Parameter - "parameter"
532 -- E_In_Out_Parameter - "parameter"
533 -- E_Out_Parameter - "parameter"
534 -- E_Variable - "global"
536 procedure Analyze_Dependency_Clause
537 (Clause : Node_Id;
538 Is_Last : Boolean);
539 -- Verify the legality of a single dependency clause. Flag Is_Last
540 -- denotes whether Clause is the last clause in the relation.
542 procedure Check_Function_Return;
543 -- Verify that Funtion'Result appears as one of the outputs
544 -- (SPARK RM 6.1.5(10)).
546 procedure Check_Role
547 (Item : Node_Id;
548 Item_Id : Entity_Id;
549 Is_Input : Boolean;
550 Self_Ref : Boolean);
551 -- Ensure that an item fulfils its designated input and/or output role
552 -- as specified by pragma Global (if any) or the enclosing context. If
553 -- this is not the case, emit an error. Item and Item_Id denote the
554 -- attributes of an item. Flag Is_Input should be set when item comes
555 -- from an input list. Flag Self_Ref should be set when the item is an
556 -- output and the dependency clause has operator "+".
558 procedure Check_Usage
559 (Subp_Items : Elist_Id;
560 Used_Items : Elist_Id;
561 Is_Input : Boolean);
562 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
563 -- error if this is not the case.
565 procedure Normalize_Clause (Clause : Node_Id);
566 -- Remove a self-dependency "+" from the input list of a clause
568 -----------------------------
569 -- Add_Item_To_Name_Buffer --
570 -----------------------------
572 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
573 begin
574 if Ekind (Item_Id) = E_Abstract_State then
575 Add_Str_To_Name_Buffer ("state");
577 elsif Is_Formal (Item_Id) then
578 Add_Str_To_Name_Buffer ("parameter");
580 elsif Ekind (Item_Id) = E_Variable then
581 Add_Str_To_Name_Buffer ("global");
583 -- The routine should not be called with non-SPARK items
585 else
586 raise Program_Error;
587 end if;
588 end Add_Item_To_Name_Buffer;
590 -------------------------------
591 -- Analyze_Dependency_Clause --
592 -------------------------------
594 procedure Analyze_Dependency_Clause
595 (Clause : Node_Id;
596 Is_Last : Boolean)
598 procedure Analyze_Input_List (Inputs : Node_Id);
599 -- Verify the legality of a single input list
601 procedure Analyze_Input_Output
602 (Item : Node_Id;
603 Is_Input : Boolean;
604 Self_Ref : Boolean;
605 Top_Level : Boolean;
606 Seen : in out Elist_Id;
607 Null_Seen : in out Boolean;
608 Non_Null_Seen : in out Boolean);
609 -- Verify the legality of a single input or output item. Flag
610 -- Is_Input should be set whenever Item is an input, False when it
611 -- denotes an output. Flag Self_Ref should be set when the item is an
612 -- output and the dependency clause has a "+". Flag Top_Level should
613 -- be set whenever Item appears immediately within an input or output
614 -- list. Seen is a collection of all abstract states, variables and
615 -- formals processed so far. Flag Null_Seen denotes whether a null
616 -- input or output has been encountered. Flag Non_Null_Seen denotes
617 -- whether a non-null input or output has been encountered.
619 ------------------------
620 -- Analyze_Input_List --
621 ------------------------
623 procedure Analyze_Input_List (Inputs : Node_Id) is
624 Inputs_Seen : Elist_Id := No_Elist;
625 -- A list containing the entities of all inputs that appear in the
626 -- current input list.
628 Non_Null_Input_Seen : Boolean := False;
629 Null_Input_Seen : Boolean := False;
630 -- Flags used to check the legality of an input list
632 Input : Node_Id;
634 begin
635 -- Multiple inputs appear as an aggregate
637 if Nkind (Inputs) = N_Aggregate then
638 if Present (Component_Associations (Inputs)) then
639 SPARK_Msg_N
640 ("nested dependency relations not allowed", Inputs);
642 elsif Present (Expressions (Inputs)) then
643 Input := First (Expressions (Inputs));
644 while Present (Input) loop
645 Analyze_Input_Output
646 (Item => Input,
647 Is_Input => True,
648 Self_Ref => False,
649 Top_Level => False,
650 Seen => Inputs_Seen,
651 Null_Seen => Null_Input_Seen,
652 Non_Null_Seen => Non_Null_Input_Seen);
654 Next (Input);
655 end loop;
657 -- Syntax error, always report
659 else
660 Error_Msg_N ("malformed input dependency list", Inputs);
661 end if;
663 -- Process a solitary input
665 else
666 Analyze_Input_Output
667 (Item => Inputs,
668 Is_Input => True,
669 Self_Ref => False,
670 Top_Level => False,
671 Seen => Inputs_Seen,
672 Null_Seen => Null_Input_Seen,
673 Non_Null_Seen => Non_Null_Input_Seen);
674 end if;
676 -- Detect an illegal dependency clause of the form
678 -- (null =>[+] null)
680 if Null_Output_Seen and then Null_Input_Seen then
681 SPARK_Msg_N
682 ("null dependency clause cannot have a null input list",
683 Inputs);
684 end if;
685 end Analyze_Input_List;
687 --------------------------
688 -- Analyze_Input_Output --
689 --------------------------
691 procedure Analyze_Input_Output
692 (Item : Node_Id;
693 Is_Input : Boolean;
694 Self_Ref : Boolean;
695 Top_Level : Boolean;
696 Seen : in out Elist_Id;
697 Null_Seen : in out Boolean;
698 Non_Null_Seen : in out Boolean)
700 Is_Output : constant Boolean := not Is_Input;
701 Grouped : Node_Id;
702 Item_Id : Entity_Id;
704 begin
705 -- Multiple input or output items appear as an aggregate
707 if Nkind (Item) = N_Aggregate then
708 if not Top_Level then
709 SPARK_Msg_N ("nested grouping of items not allowed", Item);
711 elsif Present (Component_Associations (Item)) then
712 SPARK_Msg_N
713 ("nested dependency relations not allowed", Item);
715 -- Recursively analyze the grouped items
717 elsif Present (Expressions (Item)) then
718 Grouped := First (Expressions (Item));
719 while Present (Grouped) loop
720 Analyze_Input_Output
721 (Item => Grouped,
722 Is_Input => Is_Input,
723 Self_Ref => Self_Ref,
724 Top_Level => False,
725 Seen => Seen,
726 Null_Seen => Null_Seen,
727 Non_Null_Seen => Non_Null_Seen);
729 Next (Grouped);
730 end loop;
732 -- Syntax error, always report
734 else
735 Error_Msg_N ("malformed dependency list", Item);
736 end if;
738 -- Process Function'Result in the context of a dependency clause
740 elsif Is_Attribute_Result (Item) then
741 Non_Null_Seen := True;
743 -- It is sufficent to analyze the prefix of 'Result in order to
744 -- establish legality of the attribute.
746 Analyze (Prefix (Item));
748 -- The prefix of 'Result must denote the function for which
749 -- pragma Depends applies (SPARK RM 6.1.5(11)).
751 if not Is_Entity_Name (Prefix (Item))
752 or else Ekind (Spec_Id) /= E_Function
753 or else Entity (Prefix (Item)) /= Spec_Id
754 then
755 Error_Msg_Name_1 := Name_Result;
756 SPARK_Msg_N
757 ("prefix of attribute % must denote the enclosing "
758 & "function", Item);
760 -- Function'Result is allowed to appear on the output side of a
761 -- dependency clause (SPARK RM 6.1.5(6)).
763 elsif Is_Input then
764 SPARK_Msg_N ("function result cannot act as input", Item);
766 elsif Null_Seen then
767 SPARK_Msg_N
768 ("cannot mix null and non-null dependency items", Item);
770 else
771 Result_Seen := True;
772 end if;
774 -- Detect multiple uses of null in a single dependency list or
775 -- throughout the whole relation. Verify the placement of a null
776 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
778 elsif Nkind (Item) = N_Null then
779 if Null_Seen then
780 SPARK_Msg_N
781 ("multiple null dependency relations not allowed", Item);
783 elsif Non_Null_Seen then
784 SPARK_Msg_N
785 ("cannot mix null and non-null dependency items", Item);
787 else
788 Null_Seen := True;
790 if Is_Output then
791 if not Is_Last then
792 SPARK_Msg_N
793 ("null output list must be the last clause in a "
794 & "dependency relation", Item);
796 -- Catch a useless dependence of the form:
797 -- null =>+ ...
799 elsif Self_Ref then
800 SPARK_Msg_N
801 ("useless dependence, null depends on itself", Item);
802 end if;
803 end if;
804 end if;
806 -- Default case
808 else
809 Non_Null_Seen := True;
811 if Null_Seen then
812 SPARK_Msg_N ("cannot mix null and non-null items", Item);
813 end if;
815 Analyze (Item);
816 Resolve_State (Item);
818 -- Find the entity of the item. If this is a renaming, climb
819 -- the renaming chain to reach the root object. Renamings of
820 -- non-entire objects do not yield an entity (Empty).
822 Item_Id := Entity_Of (Item);
824 if Present (Item_Id) then
825 if Ekind_In (Item_Id, E_Abstract_State,
826 E_In_Parameter,
827 E_In_Out_Parameter,
828 E_Out_Parameter,
829 E_Variable)
830 then
831 -- Ensure that the item fulfils its role as input and/or
832 -- output as specified by pragma Global or the enclosing
833 -- context.
835 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
837 -- Detect multiple uses of the same state, variable or
838 -- formal parameter. If this is not the case, add the
839 -- item to the list of processed relations.
841 if Contains (Seen, Item_Id) then
842 SPARK_Msg_NE
843 ("duplicate use of item &", Item, Item_Id);
844 else
845 Add_Item (Item_Id, Seen);
846 end if;
848 -- Detect illegal use of an input related to a null
849 -- output. Such input items cannot appear in other
850 -- input lists (SPARK RM 6.1.5(13)).
852 if Is_Input
853 and then Null_Output_Seen
854 and then Contains (All_Inputs_Seen, Item_Id)
855 then
856 SPARK_Msg_N
857 ("input of a null output list cannot appear in "
858 & "multiple input lists", Item);
859 end if;
861 -- Add an input or a self-referential output to the list
862 -- of all processed inputs.
864 if Is_Input or else Self_Ref then
865 Add_Item (Item_Id, All_Inputs_Seen);
866 end if;
868 -- State related checks (SPARK RM 6.1.5(3))
870 if Ekind (Item_Id) = E_Abstract_State then
871 if Has_Visible_Refinement (Item_Id) then
872 SPARK_Msg_NE
873 ("cannot mention state & in global refinement",
874 Item, Item_Id);
875 SPARK_Msg_N
876 ("\use its constituents instead", Item);
877 return;
879 -- If the reference to the abstract state appears in
880 -- an enclosing package body that will eventually
881 -- refine the state, record the reference for future
882 -- checks.
884 else
885 Record_Possible_Body_Reference
886 (State_Id => Item_Id,
887 Ref => Item);
888 end if;
889 end if;
891 -- When the item renames an entire object, replace the
892 -- item with a reference to the object.
894 if Present (Renamed_Object (Entity (Item))) then
895 Rewrite (Item,
896 New_Occurrence_Of (Item_Id, Sloc (Item)));
897 Analyze (Item);
898 end if;
900 -- Add the entity of the current item to the list of
901 -- processed items.
903 if Ekind (Item_Id) = E_Abstract_State then
904 Add_Item (Item_Id, States_Seen);
905 end if;
907 if Ekind_In (Item_Id, E_Abstract_State, E_Variable)
908 and then Present (Encapsulating_State (Item_Id))
909 then
910 Add_Item (Item_Id, Constits_Seen);
911 end if;
913 -- All other input/output items are illegal
914 -- (SPARK RM 6.1.5(1)).
916 else
917 SPARK_Msg_N
918 ("item must denote parameter, variable, or state",
919 Item);
920 end if;
922 -- All other input/output items are illegal
923 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
925 else
926 Error_Msg_N
927 ("item must denote parameter, variable, or state", Item);
928 end if;
929 end if;
930 end Analyze_Input_Output;
932 -- Local variables
934 Inputs : Node_Id;
935 Output : Node_Id;
936 Self_Ref : Boolean;
938 Non_Null_Output_Seen : Boolean := False;
939 -- Flag used to check the legality of an output list
941 -- Start of processing for Analyze_Dependency_Clause
943 begin
944 Inputs := Expression (Clause);
945 Self_Ref := False;
947 -- An input list with a self-dependency appears as operator "+" where
948 -- the actuals inputs are the right operand.
950 if Nkind (Inputs) = N_Op_Plus then
951 Inputs := Right_Opnd (Inputs);
952 Self_Ref := True;
953 end if;
955 -- Process the output_list of a dependency_clause
957 Output := First (Choices (Clause));
958 while Present (Output) loop
959 Analyze_Input_Output
960 (Item => Output,
961 Is_Input => False,
962 Self_Ref => Self_Ref,
963 Top_Level => True,
964 Seen => All_Outputs_Seen,
965 Null_Seen => Null_Output_Seen,
966 Non_Null_Seen => Non_Null_Output_Seen);
968 Next (Output);
969 end loop;
971 -- Process the input_list of a dependency_clause
973 Analyze_Input_List (Inputs);
974 end Analyze_Dependency_Clause;
976 ---------------------------
977 -- Check_Function_Return --
978 ---------------------------
980 procedure Check_Function_Return is
981 begin
982 if Ekind (Spec_Id) = E_Function and then not Result_Seen then
983 SPARK_Msg_NE
984 ("result of & must appear in exactly one output list",
985 N, Spec_Id);
986 end if;
987 end Check_Function_Return;
989 ----------------
990 -- Check_Role --
991 ----------------
993 procedure Check_Role
994 (Item : Node_Id;
995 Item_Id : Entity_Id;
996 Is_Input : Boolean;
997 Self_Ref : Boolean)
999 procedure Find_Role
1000 (Item_Is_Input : out Boolean;
1001 Item_Is_Output : out Boolean);
1002 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1003 -- Item_Is_Output are set depending on the role.
1005 procedure Role_Error
1006 (Item_Is_Input : Boolean;
1007 Item_Is_Output : Boolean);
1008 -- Emit an error message concerning the incorrect use of Item in
1009 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1010 -- denote whether the item is an input and/or an output.
1012 ---------------
1013 -- Find_Role --
1014 ---------------
1016 procedure Find_Role
1017 (Item_Is_Input : out Boolean;
1018 Item_Is_Output : out Boolean)
1020 begin
1021 Item_Is_Input := False;
1022 Item_Is_Output := False;
1024 -- Abstract state cases
1026 if Ekind (Item_Id) = E_Abstract_State then
1028 -- When pragma Global is present, the mode of the state may be
1029 -- further constrained by setting a more restrictive mode.
1031 if Global_Seen then
1032 if Appears_In (Subp_Inputs, Item_Id) then
1033 Item_Is_Input := True;
1034 end if;
1036 if Appears_In (Subp_Outputs, Item_Id) then
1037 Item_Is_Output := True;
1038 end if;
1040 -- Otherwise the state has a default IN OUT mode
1042 else
1043 Item_Is_Input := True;
1044 Item_Is_Output := True;
1045 end if;
1047 -- Parameter cases
1049 elsif Ekind (Item_Id) = E_In_Parameter then
1050 Item_Is_Input := True;
1052 elsif Ekind (Item_Id) = E_In_Out_Parameter then
1053 Item_Is_Input := True;
1054 Item_Is_Output := True;
1056 elsif Ekind (Item_Id) = E_Out_Parameter then
1057 if Scope (Item_Id) = Spec_Id then
1059 -- An OUT parameter of the related subprogram has mode IN
1060 -- if its type is unconstrained or tagged because array
1061 -- bounds, discriminants or tags can be read.
1063 if Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1064 Item_Is_Input := True;
1065 end if;
1067 Item_Is_Output := True;
1069 -- An OUT parameter of an enclosing subprogram behaves as a
1070 -- read-write variable in which case the mode is IN OUT.
1072 else
1073 Item_Is_Input := True;
1074 Item_Is_Output := True;
1075 end if;
1077 -- Variable cases
1079 else pragma Assert (Ekind (Item_Id) = E_Variable);
1081 -- When pragma Global is present, the mode of the variable may
1082 -- be further constrained by setting a more restrictive mode.
1084 if Global_Seen then
1086 -- A variable has mode IN when its type is unconstrained or
1087 -- tagged because array bounds, discriminants or tags can be
1088 -- read.
1090 if Appears_In (Subp_Inputs, Item_Id)
1091 or else Is_Unconstrained_Or_Tagged_Item (Item_Id)
1092 then
1093 Item_Is_Input := True;
1094 end if;
1096 if Appears_In (Subp_Outputs, Item_Id) then
1097 Item_Is_Output := True;
1098 end if;
1100 -- Otherwise the variable has a default IN OUT mode
1102 else
1103 Item_Is_Input := True;
1104 Item_Is_Output := True;
1105 end if;
1106 end if;
1107 end Find_Role;
1109 ----------------
1110 -- Role_Error --
1111 ----------------
1113 procedure Role_Error
1114 (Item_Is_Input : Boolean;
1115 Item_Is_Output : Boolean)
1117 Error_Msg : Name_Id;
1119 begin
1120 Name_Len := 0;
1122 -- When the item is not part of the input and the output set of
1123 -- the related subprogram, then it appears as extra in pragma
1124 -- [Refined_]Depends.
1126 if not Item_Is_Input and then not Item_Is_Output then
1127 Add_Item_To_Name_Buffer (Item_Id);
1128 Add_Str_To_Name_Buffer
1129 (" & cannot appear in dependence relation");
1131 Error_Msg := Name_Find;
1132 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1134 Error_Msg_Name_1 := Chars (Subp_Id);
1135 SPARK_Msg_NE
1136 ("\& is not part of the input or output set of subprogram %",
1137 Item, Item_Id);
1139 -- The mode of the item and its role in pragma [Refined_]Depends
1140 -- are in conflict. Construct a detailed message explaining the
1141 -- illegality (SPARK RM 6.1.5(5-6)).
1143 else
1144 if Item_Is_Input then
1145 Add_Str_To_Name_Buffer ("read-only");
1146 else
1147 Add_Str_To_Name_Buffer ("write-only");
1148 end if;
1150 Add_Char_To_Name_Buffer (' ');
1151 Add_Item_To_Name_Buffer (Item_Id);
1152 Add_Str_To_Name_Buffer (" & cannot appear as ");
1154 if Item_Is_Input then
1155 Add_Str_To_Name_Buffer ("output");
1156 else
1157 Add_Str_To_Name_Buffer ("input");
1158 end if;
1160 Add_Str_To_Name_Buffer (" in dependence relation");
1161 Error_Msg := Name_Find;
1162 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1163 end if;
1164 end Role_Error;
1166 -- Local variables
1168 Item_Is_Input : Boolean;
1169 Item_Is_Output : Boolean;
1171 -- Start of processing for Check_Role
1173 begin
1174 Find_Role (Item_Is_Input, Item_Is_Output);
1176 -- Input item
1178 if Is_Input then
1179 if not Item_Is_Input then
1180 Role_Error (Item_Is_Input, Item_Is_Output);
1181 end if;
1183 -- Self-referential item
1185 elsif Self_Ref then
1186 if not Item_Is_Input or else not Item_Is_Output then
1187 Role_Error (Item_Is_Input, Item_Is_Output);
1188 end if;
1190 -- Output item
1192 elsif not Item_Is_Output then
1193 Role_Error (Item_Is_Input, Item_Is_Output);
1194 end if;
1195 end Check_Role;
1197 -----------------
1198 -- Check_Usage --
1199 -----------------
1201 procedure Check_Usage
1202 (Subp_Items : Elist_Id;
1203 Used_Items : Elist_Id;
1204 Is_Input : Boolean)
1206 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id);
1207 -- Emit an error concerning the illegal usage of an item
1209 -----------------
1210 -- Usage_Error --
1211 -----------------
1213 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id) is
1214 Error_Msg : Name_Id;
1216 begin
1217 -- Input case
1219 if Is_Input then
1221 -- Unconstrained and tagged items are not part of the explicit
1222 -- input set of the related subprogram, they do not have to be
1223 -- present in a dependence relation and should not be flagged
1224 -- (SPARK RM 6.1.5(8)).
1226 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1227 Name_Len := 0;
1229 Add_Item_To_Name_Buffer (Item_Id);
1230 Add_Str_To_Name_Buffer
1231 (" & must appear in at least one input dependence list");
1233 Error_Msg := Name_Find;
1234 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1235 end if;
1237 -- Output case (SPARK RM 6.1.5(10))
1239 else
1240 Name_Len := 0;
1242 Add_Item_To_Name_Buffer (Item_Id);
1243 Add_Str_To_Name_Buffer
1244 (" & must appear in exactly one output dependence list");
1246 Error_Msg := Name_Find;
1247 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1248 end if;
1249 end Usage_Error;
1251 -- Local variables
1253 Elmt : Elmt_Id;
1254 Item : Node_Id;
1255 Item_Id : Entity_Id;
1257 -- Start of processing for Check_Usage
1259 begin
1260 if No (Subp_Items) then
1261 return;
1262 end if;
1264 -- Each input or output of the subprogram must appear in a dependency
1265 -- relation.
1267 Elmt := First_Elmt (Subp_Items);
1268 while Present (Elmt) loop
1269 Item := Node (Elmt);
1271 if Nkind (Item) = N_Defining_Identifier then
1272 Item_Id := Item;
1273 else
1274 Item_Id := Entity_Of (Item);
1275 end if;
1277 -- The item does not appear in a dependency
1279 if Present (Item_Id)
1280 and then not Contains (Used_Items, Item_Id)
1281 then
1282 if Is_Formal (Item_Id) then
1283 Usage_Error (Item, Item_Id);
1285 -- States and global variables are not used properly only when
1286 -- the subprogram is subject to pragma Global.
1288 elsif Global_Seen then
1289 Usage_Error (Item, Item_Id);
1290 end if;
1291 end if;
1293 Next_Elmt (Elmt);
1294 end loop;
1295 end Check_Usage;
1297 ----------------------
1298 -- Normalize_Clause --
1299 ----------------------
1301 procedure Normalize_Clause (Clause : Node_Id) is
1302 procedure Create_Or_Modify_Clause
1303 (Output : Node_Id;
1304 Outputs : Node_Id;
1305 Inputs : Node_Id;
1306 After : Node_Id;
1307 In_Place : Boolean;
1308 Multiple : Boolean);
1309 -- Create a brand new clause to represent the self-reference or
1310 -- modify the input and/or output lists of an existing clause. Output
1311 -- denotes a self-referencial output. Outputs is the output list of a
1312 -- clause. Inputs is the input list of a clause. After denotes the
1313 -- clause after which the new clause is to be inserted. Flag In_Place
1314 -- should be set when normalizing the last output of an output list.
1315 -- Flag Multiple should be set when Output comes from a list with
1316 -- multiple items.
1318 -----------------------------
1319 -- Create_Or_Modify_Clause --
1320 -----------------------------
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)
1330 procedure Propagate_Output
1331 (Output : Node_Id;
1332 Inputs : Node_Id);
1333 -- Handle the various cases of output propagation to the input
1334 -- list. Output denotes a self-referencial output item. Inputs is
1335 -- the input list of a clause.
1337 ----------------------
1338 -- Propagate_Output --
1339 ----------------------
1341 procedure Propagate_Output
1342 (Output : Node_Id;
1343 Inputs : Node_Id)
1345 function In_Input_List
1346 (Item : Entity_Id;
1347 Inputs : List_Id) return Boolean;
1348 -- Determine whether a particulat item appears in the input
1349 -- list of a clause.
1351 -------------------
1352 -- In_Input_List --
1353 -------------------
1355 function In_Input_List
1356 (Item : Entity_Id;
1357 Inputs : List_Id) return Boolean
1359 Elmt : Node_Id;
1361 begin
1362 Elmt := First (Inputs);
1363 while Present (Elmt) loop
1364 if Entity_Of (Elmt) = Item then
1365 return True;
1366 end if;
1368 Next (Elmt);
1369 end loop;
1371 return False;
1372 end In_Input_List;
1374 -- Local variables
1376 Output_Id : constant Entity_Id := Entity_Of (Output);
1377 Grouped : List_Id;
1379 -- Start of processing for Propagate_Output
1381 begin
1382 -- The clause is of the form:
1384 -- (Output =>+ null)
1386 -- Remove null input and replace it with a copy of the output:
1388 -- (Output => Output)
1390 if Nkind (Inputs) = N_Null then
1391 Rewrite (Inputs, New_Copy_Tree (Output));
1393 -- The clause is of the form:
1395 -- (Output =>+ (Input1, ..., InputN))
1397 -- Determine whether the output is not already mentioned in the
1398 -- input list and if not, add it to the list of inputs:
1400 -- (Output => (Output, Input1, ..., InputN))
1402 elsif Nkind (Inputs) = N_Aggregate then
1403 Grouped := Expressions (Inputs);
1405 if not In_Input_List
1406 (Item => Output_Id,
1407 Inputs => Grouped)
1408 then
1409 Prepend_To (Grouped, New_Copy_Tree (Output));
1410 end if;
1412 -- The clause is of the form:
1414 -- (Output =>+ Input)
1416 -- If the input does not mention the output, group the two
1417 -- together:
1419 -- (Output => (Output, Input))
1421 elsif Entity_Of (Inputs) /= Output_Id then
1422 Rewrite (Inputs,
1423 Make_Aggregate (Loc,
1424 Expressions => New_List (
1425 New_Copy_Tree (Output),
1426 New_Copy_Tree (Inputs))));
1427 end if;
1428 end Propagate_Output;
1430 -- Local variables
1432 Loc : constant Source_Ptr := Sloc (Clause);
1433 New_Clause : Node_Id;
1435 -- Start of processing for Create_Or_Modify_Clause
1437 begin
1438 -- A null output depending on itself does not require any
1439 -- normalization.
1441 if Nkind (Output) = N_Null then
1442 return;
1444 -- A function result cannot depend on itself because it cannot
1445 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1447 elsif Is_Attribute_Result (Output) then
1448 SPARK_Msg_N ("function result cannot depend on itself", Output);
1449 return;
1450 end if;
1452 -- When performing the transformation in place, simply add the
1453 -- output to the list of inputs (if not already there). This case
1454 -- arises when dealing with the last output of an output list -
1455 -- we perform the normalization in place to avoid generating a
1456 -- malformed tree.
1458 if In_Place then
1459 Propagate_Output (Output, Inputs);
1461 -- A list with multiple outputs is slowly trimmed until only
1462 -- one element remains. When this happens, replace aggregate
1463 -- with the element itself.
1465 if Multiple then
1466 Remove (Output);
1467 Rewrite (Outputs, Output);
1468 end if;
1470 -- Default case
1472 else
1473 -- Unchain the output from its output list as it will appear in
1474 -- a new clause. Note that we cannot simply rewrite the output
1475 -- as null because this will violate the semantics of pragma
1476 -- Depends.
1478 Remove (Output);
1480 -- Generate a new clause of the form:
1481 -- (Output => Inputs)
1483 New_Clause :=
1484 Make_Component_Association (Loc,
1485 Choices => New_List (Output),
1486 Expression => New_Copy_Tree (Inputs));
1488 -- The new clause contains replicated content that has already
1489 -- been analyzed. There is not need to reanalyze it or
1490 -- renormalize it again.
1492 Set_Analyzed (New_Clause);
1494 Propagate_Output
1495 (Output => First (Choices (New_Clause)),
1496 Inputs => Expression (New_Clause));
1498 Insert_After (After, New_Clause);
1499 end if;
1500 end Create_Or_Modify_Clause;
1502 -- Local variables
1504 Outputs : constant Node_Id := First (Choices (Clause));
1505 Inputs : Node_Id;
1506 Last_Output : Node_Id;
1507 Next_Output : Node_Id;
1508 Output : Node_Id;
1510 -- Start of processing for Normalize_Clause
1512 begin
1513 -- A self-dependency appears as operator "+". Remove the "+" from the
1514 -- tree by moving the real inputs to their proper place.
1516 if Nkind (Expression (Clause)) = N_Op_Plus then
1517 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1518 Inputs := Expression (Clause);
1520 -- Multiple outputs appear as an aggregate
1522 if Nkind (Outputs) = N_Aggregate then
1523 Last_Output := Last (Expressions (Outputs));
1525 Output := First (Expressions (Outputs));
1526 while Present (Output) loop
1528 -- Normalization may remove an output from its list,
1529 -- preserve the subsequent output now.
1531 Next_Output := Next (Output);
1533 Create_Or_Modify_Clause
1534 (Output => Output,
1535 Outputs => Outputs,
1536 Inputs => Inputs,
1537 After => Clause,
1538 In_Place => Output = Last_Output,
1539 Multiple => True);
1541 Output := Next_Output;
1542 end loop;
1544 -- Solitary output
1546 else
1547 Create_Or_Modify_Clause
1548 (Output => Outputs,
1549 Outputs => Empty,
1550 Inputs => Inputs,
1551 After => Empty,
1552 In_Place => True,
1553 Multiple => False);
1554 end if;
1555 end if;
1556 end Normalize_Clause;
1558 -- Local variables
1560 Deps : constant Node_Id :=
1561 Get_Pragma_Arg
1562 (First (Pragma_Argument_Associations (N)));
1563 Clause : Node_Id;
1564 Errors : Nat;
1565 Last_Clause : Node_Id;
1566 Subp_Decl : Node_Id;
1568 Restore_Scope : Boolean := False;
1569 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
1571 -- Start of processing for Analyze_Depends_In_Decl_Part
1573 begin
1574 Set_Analyzed (N);
1576 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
1577 Subp_Id := Defining_Entity (Subp_Decl);
1579 -- The logic in this routine is used to analyze both pragma Depends and
1580 -- pragma Refined_Depends since they have the same syntax and base
1581 -- semantics. Find the entity of the corresponding spec when analyzing
1582 -- Refined_Depends.
1584 if Nkind (Subp_Decl) = N_Subprogram_Body
1585 and then Present (Corresponding_Spec (Subp_Decl))
1586 then
1587 Spec_Id := Corresponding_Spec (Subp_Decl);
1589 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
1590 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
1591 then
1592 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
1594 else
1595 Spec_Id := Subp_Id;
1596 end if;
1598 -- Empty dependency list
1600 if Nkind (Deps) = N_Null then
1602 -- Gather all states, variables and formal parameters that the
1603 -- subprogram may depend on. These items are obtained from the
1604 -- parameter profile or pragma [Refined_]Global (if available).
1606 Collect_Subprogram_Inputs_Outputs
1607 (Subp_Id => Subp_Id,
1608 Subp_Inputs => Subp_Inputs,
1609 Subp_Outputs => Subp_Outputs,
1610 Global_Seen => Global_Seen);
1612 -- Verify that every input or output of the subprogram appear in a
1613 -- dependency.
1615 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1616 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1617 Check_Function_Return;
1619 -- Dependency clauses appear as component associations of an aggregate
1621 elsif Nkind (Deps) = N_Aggregate then
1623 -- Do not attempt to perform analysis of a syntactically illegal
1624 -- clause as this will lead to misleading errors.
1626 if Has_Extra_Parentheses (Deps) then
1627 return;
1628 end if;
1630 if Present (Component_Associations (Deps)) then
1631 Last_Clause := Last (Component_Associations (Deps));
1633 -- Gather all states, variables and formal parameters that the
1634 -- subprogram may depend on. These items are obtained from the
1635 -- parameter profile or pragma [Refined_]Global (if available).
1637 Collect_Subprogram_Inputs_Outputs
1638 (Subp_Id => Subp_Id,
1639 Subp_Inputs => Subp_Inputs,
1640 Subp_Outputs => Subp_Outputs,
1641 Global_Seen => Global_Seen);
1643 -- Ensure that the formal parameters are visible when analyzing
1644 -- all clauses. This falls out of the general rule of aspects
1645 -- pertaining to subprogram declarations. Skip the installation
1646 -- for subprogram bodies because the formals are already visible.
1648 if not In_Open_Scopes (Spec_Id) then
1649 Restore_Scope := True;
1650 Push_Scope (Spec_Id);
1651 Install_Formals (Spec_Id);
1652 end if;
1654 Clause := First (Component_Associations (Deps));
1655 while Present (Clause) loop
1656 Errors := Serious_Errors_Detected;
1658 -- Normalization may create extra clauses that contain
1659 -- replicated input and output names. There is no need to
1660 -- reanalyze them.
1662 if not Analyzed (Clause) then
1663 Set_Analyzed (Clause);
1665 Analyze_Dependency_Clause
1666 (Clause => Clause,
1667 Is_Last => Clause = Last_Clause);
1668 end if;
1670 -- Do not normalize a clause if errors were detected (count
1671 -- of Serious_Errors has increased) because the inputs and/or
1672 -- outputs may denote illegal items. Normalization is disabled
1673 -- in ASIS mode as it alters the tree by introducing new nodes
1674 -- similar to expansion.
1676 if Serious_Errors_Detected = Errors and then not ASIS_Mode then
1677 Normalize_Clause (Clause);
1678 end if;
1680 Next (Clause);
1681 end loop;
1683 if Restore_Scope then
1684 End_Scope;
1685 end if;
1687 -- Verify that every input or output of the subprogram appear in a
1688 -- dependency.
1690 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1691 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1692 Check_Function_Return;
1694 -- The dependency list is malformed. This is a syntax error, always
1695 -- report.
1697 else
1698 Error_Msg_N ("malformed dependency relation", Deps);
1699 return;
1700 end if;
1702 -- The top level dependency relation is malformed. This is a syntax
1703 -- error, always report.
1705 else
1706 Error_Msg_N ("malformed dependency relation", Deps);
1707 return;
1708 end if;
1710 -- Ensure that a state and a corresponding constituent do not appear
1711 -- together in pragma [Refined_]Depends.
1713 Check_State_And_Constituent_Use
1714 (States => States_Seen,
1715 Constits => Constits_Seen,
1716 Context => N);
1717 end Analyze_Depends_In_Decl_Part;
1719 --------------------------------------------
1720 -- Analyze_External_Property_In_Decl_Part --
1721 --------------------------------------------
1723 procedure Analyze_External_Property_In_Decl_Part
1724 (N : Node_Id;
1725 Expr_Val : out Boolean)
1727 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
1728 Obj_Id : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
1729 Expr : constant Node_Id := Get_Pragma_Arg (Next (Arg1));
1731 begin
1732 Error_Msg_Name_1 := Pragma_Name (N);
1734 -- An external property pragma must apply to an effectively volatile
1735 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
1736 -- The check is performed at the end of the declarative region due to a
1737 -- possible out-of-order arrangement of pragmas:
1739 -- Obj : ...;
1740 -- pragma Async_Readers (Obj);
1741 -- pragma Volatile (Obj);
1743 if not Is_Effectively_Volatile (Obj_Id) then
1744 SPARK_Msg_N
1745 ("external property % must apply to a volatile object", N);
1746 end if;
1748 -- Ensure that the Boolean expression (if present) is static. A missing
1749 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
1751 Expr_Val := True;
1753 if Present (Expr) then
1754 Analyze_And_Resolve (Expr, Standard_Boolean);
1756 if Is_OK_Static_Expression (Expr) then
1757 Expr_Val := Is_True (Expr_Value (Expr));
1758 else
1759 SPARK_Msg_N ("expression of % must be static", Expr);
1760 end if;
1761 end if;
1762 end Analyze_External_Property_In_Decl_Part;
1764 ---------------------------------
1765 -- Analyze_Global_In_Decl_Part --
1766 ---------------------------------
1768 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
1769 Constits_Seen : Elist_Id := No_Elist;
1770 -- A list containing the entities of all constituents processed so far.
1771 -- It aids in detecting illegal usage of a state and a corresponding
1772 -- constituent in pragma [Refinde_]Global.
1774 Seen : Elist_Id := No_Elist;
1775 -- A list containing the entities of all the items processed so far. It
1776 -- plays a role in detecting distinct entities.
1778 Spec_Id : Entity_Id;
1779 -- The entity of the subprogram subject to pragma [Refined_]Global
1781 States_Seen : Elist_Id := No_Elist;
1782 -- A list containing the entities of all states processed so far. It
1783 -- helps in detecting illegal usage of a state and a corresponding
1784 -- constituent in pragma [Refined_]Global.
1786 Subp_Id : Entity_Id;
1787 -- The entity of the subprogram [body or stub] subject to pragma
1788 -- [Refined_]Global.
1790 In_Out_Seen : Boolean := False;
1791 Input_Seen : Boolean := False;
1792 Output_Seen : Boolean := False;
1793 Proof_Seen : Boolean := False;
1794 -- Flags used to verify the consistency of modes
1796 procedure Analyze_Global_List
1797 (List : Node_Id;
1798 Global_Mode : Name_Id := Name_Input);
1799 -- Verify the legality of a single global list declaration. Global_Mode
1800 -- denotes the current mode in effect.
1802 -------------------------
1803 -- Analyze_Global_List --
1804 -------------------------
1806 procedure Analyze_Global_List
1807 (List : Node_Id;
1808 Global_Mode : Name_Id := Name_Input)
1810 procedure Analyze_Global_Item
1811 (Item : Node_Id;
1812 Global_Mode : Name_Id);
1813 -- Verify the legality of a single global item declaration.
1814 -- Global_Mode denotes the current mode in effect.
1816 procedure Check_Duplicate_Mode
1817 (Mode : Node_Id;
1818 Status : in out Boolean);
1819 -- Flag Status denotes whether a particular mode has been seen while
1820 -- processing a global list. This routine verifies that Mode is not a
1821 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
1823 procedure Check_Mode_Restriction_In_Enclosing_Context
1824 (Item : Node_Id;
1825 Item_Id : Entity_Id);
1826 -- Verify that an item of mode In_Out or Output does not appear as an
1827 -- input in the Global aspect of an enclosing subprogram. If this is
1828 -- the case, emit an error. Item and Item_Id are respectively the
1829 -- item and its entity.
1831 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
1832 -- Mode denotes either In_Out or Output. Depending on the kind of the
1833 -- related subprogram, emit an error if those two modes apply to a
1834 -- function (SPARK RM 6.1.4(10)).
1836 -------------------------
1837 -- Analyze_Global_Item --
1838 -------------------------
1840 procedure Analyze_Global_Item
1841 (Item : Node_Id;
1842 Global_Mode : Name_Id)
1844 Item_Id : Entity_Id;
1846 begin
1847 -- Detect one of the following cases
1849 -- with Global => (null, Name)
1850 -- with Global => (Name_1, null, Name_2)
1851 -- with Global => (Name, null)
1853 if Nkind (Item) = N_Null then
1854 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
1855 return;
1856 end if;
1858 Analyze (Item);
1859 Resolve_State (Item);
1861 -- Find the entity of the item. If this is a renaming, climb the
1862 -- renaming chain to reach the root object. Renamings of non-
1863 -- entire objects do not yield an entity (Empty).
1865 Item_Id := Entity_Of (Item);
1867 if Present (Item_Id) then
1869 -- A global item may denote a formal parameter of an enclosing
1870 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
1871 -- provide a better error diagnostic.
1873 if Is_Formal (Item_Id) then
1874 if Scope (Item_Id) = Spec_Id then
1875 SPARK_Msg_NE
1876 ("global item cannot reference parameter of subprogram",
1877 Item, Spec_Id);
1878 return;
1879 end if;
1881 -- A constant cannot act as a global item (SPARK RM 6.1.4(7)).
1882 -- Do this check first to provide a better error diagnostic.
1884 elsif Ekind (Item_Id) = E_Constant then
1885 SPARK_Msg_N ("global item cannot denote a constant", Item);
1887 -- A formal object may act as a global item inside a generic
1889 elsif Is_Formal_Object (Item_Id) then
1890 null;
1892 -- The only legal references are those to abstract states and
1893 -- variables (SPARK RM 6.1.4(4)).
1895 elsif not Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
1896 SPARK_Msg_N
1897 ("global item must denote variable or state", Item);
1898 return;
1899 end if;
1901 -- State related checks
1903 if Ekind (Item_Id) = E_Abstract_State then
1905 -- An abstract state with visible refinement cannot appear
1906 -- in pragma [Refined_]Global as its place must be taken by
1907 -- some of its constituents (SPARK RM 6.1.4(8)).
1909 if Has_Visible_Refinement (Item_Id) then
1910 SPARK_Msg_NE
1911 ("cannot mention state & in global refinement",
1912 Item, Item_Id);
1913 SPARK_Msg_N ("\use its constituents instead", Item);
1914 return;
1916 -- If the reference to the abstract state appears in an
1917 -- enclosing package body that will eventually refine the
1918 -- state, record the reference for future checks.
1920 else
1921 Record_Possible_Body_Reference
1922 (State_Id => Item_Id,
1923 Ref => Item);
1924 end if;
1926 -- Variable related checks. These are only relevant when
1927 -- SPARK_Mode is on as they are not standard Ada legality
1928 -- rules.
1930 elsif SPARK_Mode = On
1931 and then Is_Effectively_Volatile (Item_Id)
1932 then
1933 -- An effectively volatile object cannot appear as a global
1934 -- item of a function (SPARK RM 7.1.3(9)).
1936 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
1937 Error_Msg_NE
1938 ("volatile object & cannot act as global item of a "
1939 & "function", Item, Item_Id);
1940 return;
1942 -- An effectively volatile object with external property
1943 -- Effective_Reads set to True must have mode Output or
1944 -- In_Out.
1946 elsif Effective_Reads_Enabled (Item_Id)
1947 and then Global_Mode = Name_Input
1948 then
1949 Error_Msg_NE
1950 ("volatile object & with property Effective_Reads must "
1951 & "have mode In_Out or Output (SPARK RM 7.1.3(11))",
1952 Item, Item_Id);
1953 return;
1954 end if;
1955 end if;
1957 -- When the item renames an entire object, replace the item
1958 -- with a reference to the object.
1960 if Present (Renamed_Object (Entity (Item))) then
1961 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
1962 Analyze (Item);
1963 end if;
1965 -- Some form of illegal construct masquerading as a name
1966 -- (SPARK RM 6.1.4(4)).
1968 else
1969 Error_Msg_N ("global item must denote variable or state", Item);
1970 return;
1971 end if;
1973 -- Verify that an output does not appear as an input in an
1974 -- enclosing subprogram.
1976 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
1977 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
1978 end if;
1980 -- The same entity might be referenced through various way.
1981 -- Check the entity of the item rather than the item itself
1982 -- (SPARK RM 6.1.4(11)).
1984 if Contains (Seen, Item_Id) then
1985 SPARK_Msg_N ("duplicate global item", Item);
1987 -- Add the entity of the current item to the list of processed
1988 -- items.
1990 else
1991 Add_Item (Item_Id, Seen);
1993 if Ekind (Item_Id) = E_Abstract_State then
1994 Add_Item (Item_Id, States_Seen);
1995 end if;
1997 if Ekind_In (Item_Id, E_Abstract_State, E_Variable)
1998 and then Present (Encapsulating_State (Item_Id))
1999 then
2000 Add_Item (Item_Id, Constits_Seen);
2001 end if;
2002 end if;
2003 end Analyze_Global_Item;
2005 --------------------------
2006 -- Check_Duplicate_Mode --
2007 --------------------------
2009 procedure Check_Duplicate_Mode
2010 (Mode : Node_Id;
2011 Status : in out Boolean)
2013 begin
2014 if Status then
2015 SPARK_Msg_N ("duplicate global mode", Mode);
2016 end if;
2018 Status := True;
2019 end Check_Duplicate_Mode;
2021 -------------------------------------------------
2022 -- Check_Mode_Restriction_In_Enclosing_Context --
2023 -------------------------------------------------
2025 procedure Check_Mode_Restriction_In_Enclosing_Context
2026 (Item : Node_Id;
2027 Item_Id : Entity_Id)
2029 Context : Entity_Id;
2030 Dummy : Boolean;
2031 Inputs : Elist_Id := No_Elist;
2032 Outputs : Elist_Id := No_Elist;
2034 begin
2035 -- Traverse the scope stack looking for enclosing subprograms
2036 -- subject to pragma [Refined_]Global.
2038 Context := Scope (Subp_Id);
2039 while Present (Context) and then Context /= Standard_Standard loop
2040 if Is_Subprogram (Context)
2041 and then
2042 (Present (Get_Pragma (Context, Pragma_Global))
2043 or else
2044 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2045 then
2046 Collect_Subprogram_Inputs_Outputs
2047 (Subp_Id => Context,
2048 Subp_Inputs => Inputs,
2049 Subp_Outputs => Outputs,
2050 Global_Seen => Dummy);
2052 -- The item is classified as In_Out or Output but appears as
2053 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(12)).
2055 if Appears_In (Inputs, Item_Id)
2056 and then not Appears_In (Outputs, Item_Id)
2057 then
2058 SPARK_Msg_NE
2059 ("global item & cannot have mode In_Out or Output",
2060 Item, Item_Id);
2061 SPARK_Msg_NE
2062 ("\item already appears as input of subprogram &",
2063 Item, Context);
2065 -- Stop the traversal once an error has been detected
2067 exit;
2068 end if;
2069 end if;
2071 Context := Scope (Context);
2072 end loop;
2073 end Check_Mode_Restriction_In_Enclosing_Context;
2075 ----------------------------------------
2076 -- Check_Mode_Restriction_In_Function --
2077 ----------------------------------------
2079 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2080 begin
2081 if Ekind (Spec_Id) = E_Function then
2082 SPARK_Msg_N
2083 ("global mode & is not applicable to functions", Mode);
2084 end if;
2085 end Check_Mode_Restriction_In_Function;
2087 -- Local variables
2089 Assoc : Node_Id;
2090 Item : Node_Id;
2091 Mode : Node_Id;
2093 -- Start of processing for Analyze_Global_List
2095 begin
2096 if Nkind (List) = N_Null then
2097 Set_Analyzed (List);
2099 -- Single global item declaration
2101 elsif Nkind_In (List, N_Expanded_Name,
2102 N_Identifier,
2103 N_Selected_Component)
2104 then
2105 Analyze_Global_Item (List, Global_Mode);
2107 -- Simple global list or moded global list declaration
2109 elsif Nkind (List) = N_Aggregate then
2110 Set_Analyzed (List);
2112 -- The declaration of a simple global list appear as a collection
2113 -- of expressions.
2115 if Present (Expressions (List)) then
2116 if Present (Component_Associations (List)) then
2117 SPARK_Msg_N
2118 ("cannot mix moded and non-moded global lists", List);
2119 end if;
2121 Item := First (Expressions (List));
2122 while Present (Item) loop
2123 Analyze_Global_Item (Item, Global_Mode);
2125 Next (Item);
2126 end loop;
2128 -- The declaration of a moded global list appears as a collection
2129 -- of component associations where individual choices denote
2130 -- modes.
2132 elsif Present (Component_Associations (List)) then
2133 if Present (Expressions (List)) then
2134 SPARK_Msg_N
2135 ("cannot mix moded and non-moded global lists", List);
2136 end if;
2138 Assoc := First (Component_Associations (List));
2139 while Present (Assoc) loop
2140 Mode := First (Choices (Assoc));
2142 if Nkind (Mode) = N_Identifier then
2143 if Chars (Mode) = Name_In_Out then
2144 Check_Duplicate_Mode (Mode, In_Out_Seen);
2145 Check_Mode_Restriction_In_Function (Mode);
2147 elsif Chars (Mode) = Name_Input then
2148 Check_Duplicate_Mode (Mode, Input_Seen);
2150 elsif Chars (Mode) = Name_Output then
2151 Check_Duplicate_Mode (Mode, Output_Seen);
2152 Check_Mode_Restriction_In_Function (Mode);
2154 elsif Chars (Mode) = Name_Proof_In then
2155 Check_Duplicate_Mode (Mode, Proof_Seen);
2157 else
2158 SPARK_Msg_N ("invalid mode selector", Mode);
2159 end if;
2161 else
2162 SPARK_Msg_N ("invalid mode selector", Mode);
2163 end if;
2165 -- Items in a moded list appear as a collection of
2166 -- expressions. Reuse the existing machinery to analyze
2167 -- them.
2169 Analyze_Global_List
2170 (List => Expression (Assoc),
2171 Global_Mode => Chars (Mode));
2173 Next (Assoc);
2174 end loop;
2176 -- Invalid tree
2178 else
2179 raise Program_Error;
2180 end if;
2182 -- Any other attempt to declare a global item is illegal. This is a
2183 -- syntax error, always report.
2185 else
2186 Error_Msg_N ("malformed global list", List);
2187 end if;
2188 end Analyze_Global_List;
2190 -- Local variables
2192 Items : constant Node_Id :=
2193 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2194 Subp_Decl : Node_Id;
2196 Restore_Scope : Boolean := False;
2197 -- Set True if we do a Push_Scope requiring a Pop_Scope on exit
2199 -- Start of processing for Analyze_Global_In_Decl_List
2201 begin
2202 Set_Analyzed (N);
2203 Check_SPARK_Aspect_For_ASIS (N);
2205 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
2206 Subp_Id := Defining_Entity (Subp_Decl);
2208 -- The logic in this routine is used to analyze both pragma Global and
2209 -- pragma Refined_Global since they have the same syntax and base
2210 -- semantics. Find the entity of the corresponding spec when analyzing
2211 -- Refined_Global.
2213 if Nkind (Subp_Decl) = N_Subprogram_Body
2214 and then Present (Corresponding_Spec (Subp_Decl))
2215 then
2216 Spec_Id := Corresponding_Spec (Subp_Decl);
2218 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
2219 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
2220 then
2221 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
2223 else
2224 Spec_Id := Subp_Id;
2225 end if;
2227 -- There is nothing to be done for a null global list
2229 if Nkind (Items) = N_Null then
2230 Set_Analyzed (Items);
2232 -- Analyze the various forms of global lists and items. Note that some
2233 -- of these may be malformed in which case the analysis emits error
2234 -- messages.
2236 else
2237 -- Ensure that the formal parameters are visible when processing an
2238 -- item. This falls out of the general rule of aspects pertaining to
2239 -- subprogram declarations.
2241 if not In_Open_Scopes (Spec_Id) then
2242 Restore_Scope := True;
2243 Push_Scope (Spec_Id);
2244 Install_Formals (Spec_Id);
2245 end if;
2247 Analyze_Global_List (Items);
2249 if Restore_Scope then
2250 End_Scope;
2251 end if;
2252 end if;
2254 -- Ensure that a state and a corresponding constituent do not appear
2255 -- together in pragma [Refined_]Global.
2257 Check_State_And_Constituent_Use
2258 (States => States_Seen,
2259 Constits => Constits_Seen,
2260 Context => N);
2261 end Analyze_Global_In_Decl_Part;
2263 --------------------------------------------
2264 -- Analyze_Initial_Condition_In_Decl_Part --
2265 --------------------------------------------
2267 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2268 Expr : constant Node_Id :=
2269 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2271 begin
2272 Set_Analyzed (N);
2274 -- The expression is preanalyzed because it has not been moved to its
2275 -- final place yet. A direct analysis may generate side effects and this
2276 -- is not desired at this point.
2278 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2279 end Analyze_Initial_Condition_In_Decl_Part;
2281 --------------------------------------
2282 -- Analyze_Initializes_In_Decl_Part --
2283 --------------------------------------
2285 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2286 Pack_Spec : constant Node_Id := Parent (N);
2287 Pack_Id : constant Entity_Id := Defining_Entity (Parent (Pack_Spec));
2289 Constits_Seen : Elist_Id := No_Elist;
2290 -- A list containing the entities of all constituents processed so far.
2291 -- It aids in detecting illegal usage of a state and a corresponding
2292 -- constituent in pragma Initializes.
2294 Items_Seen : Elist_Id := No_Elist;
2295 -- A list of all initialization items processed so far. This list is
2296 -- used to detect duplicate items.
2298 Non_Null_Seen : Boolean := False;
2299 Null_Seen : Boolean := False;
2300 -- Flags used to check the legality of a null initialization list
2302 States_And_Vars : Elist_Id := No_Elist;
2303 -- A list of all abstract states and variables declared in the visible
2304 -- declarations of the related package. This list is used to detect the
2305 -- legality of initialization items.
2307 States_Seen : Elist_Id := No_Elist;
2308 -- A list containing the entities of all states processed so far. It
2309 -- helps in detecting illegal usage of a state and a corresponding
2310 -- constituent in pragma Initializes.
2312 procedure Analyze_Initialization_Item (Item : Node_Id);
2313 -- Verify the legality of a single initialization item
2315 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2316 -- Verify the legality of a single initialization item followed by a
2317 -- list of input items.
2319 procedure Collect_States_And_Variables;
2320 -- Inspect the visible declarations of the related package and gather
2321 -- the entities of all abstract states and variables in States_And_Vars.
2323 ---------------------------------
2324 -- Analyze_Initialization_Item --
2325 ---------------------------------
2327 procedure Analyze_Initialization_Item (Item : Node_Id) is
2328 Item_Id : Entity_Id;
2330 begin
2331 -- Null initialization list
2333 if Nkind (Item) = N_Null then
2334 if Null_Seen then
2335 SPARK_Msg_N ("multiple null initializations not allowed", Item);
2337 elsif Non_Null_Seen then
2338 SPARK_Msg_N
2339 ("cannot mix null and non-null initialization items", Item);
2340 else
2341 Null_Seen := True;
2342 end if;
2344 -- Initialization item
2346 else
2347 Non_Null_Seen := True;
2349 if Null_Seen then
2350 SPARK_Msg_N
2351 ("cannot mix null and non-null initialization items", Item);
2352 end if;
2354 Analyze (Item);
2355 Resolve_State (Item);
2357 if Is_Entity_Name (Item) then
2358 Item_Id := Entity_Of (Item);
2360 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
2362 -- The state or variable must be declared in the visible
2363 -- declarations of the package (SPARK RM 7.1.5(7)).
2365 if not Contains (States_And_Vars, Item_Id) then
2366 Error_Msg_Name_1 := Chars (Pack_Id);
2367 SPARK_Msg_NE
2368 ("initialization item & must appear in the visible "
2369 & "declarations of package %", Item, Item_Id);
2371 -- Detect a duplicate use of the same initialization item
2372 -- (SPARK RM 7.1.5(5)).
2374 elsif Contains (Items_Seen, Item_Id) then
2375 SPARK_Msg_N ("duplicate initialization item", Item);
2377 -- The item is legal, add it to the list of processed states
2378 -- and variables.
2380 else
2381 Add_Item (Item_Id, Items_Seen);
2383 if Ekind (Item_Id) = E_Abstract_State then
2384 Add_Item (Item_Id, States_Seen);
2385 end if;
2387 if Present (Encapsulating_State (Item_Id)) then
2388 Add_Item (Item_Id, Constits_Seen);
2389 end if;
2390 end if;
2392 -- The item references something that is not a state or a
2393 -- variable (SPARK RM 7.1.5(3)).
2395 else
2396 SPARK_Msg_N
2397 ("initialization item must denote variable or state",
2398 Item);
2399 end if;
2401 -- Some form of illegal construct masquerading as a name
2402 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2404 else
2405 Error_Msg_N
2406 ("initialization item must denote variable or state", Item);
2407 end if;
2408 end if;
2409 end Analyze_Initialization_Item;
2411 ---------------------------------------------
2412 -- Analyze_Initialization_Item_With_Inputs --
2413 ---------------------------------------------
2415 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2416 Inputs_Seen : Elist_Id := No_Elist;
2417 -- A list of all inputs processed so far. This list is used to detect
2418 -- duplicate uses of an input.
2420 Non_Null_Seen : Boolean := False;
2421 Null_Seen : Boolean := False;
2422 -- Flags used to check the legality of an input list
2424 procedure Analyze_Input_Item (Input : Node_Id);
2425 -- Verify the legality of a single input item
2427 ------------------------
2428 -- Analyze_Input_Item --
2429 ------------------------
2431 procedure Analyze_Input_Item (Input : Node_Id) is
2432 Input_Id : Entity_Id;
2434 begin
2435 -- Null input list
2437 if Nkind (Input) = N_Null then
2438 if Null_Seen then
2439 SPARK_Msg_N
2440 ("multiple null initializations not allowed", Item);
2442 elsif Non_Null_Seen then
2443 SPARK_Msg_N
2444 ("cannot mix null and non-null initialization item", Item);
2445 else
2446 Null_Seen := True;
2447 end if;
2449 -- Input item
2451 else
2452 Non_Null_Seen := True;
2454 if Null_Seen then
2455 SPARK_Msg_N
2456 ("cannot mix null and non-null initialization item", Item);
2457 end if;
2459 Analyze (Input);
2460 Resolve_State (Input);
2462 if Is_Entity_Name (Input) then
2463 Input_Id := Entity_Of (Input);
2465 if Ekind_In (Input_Id, E_Abstract_State,
2466 E_In_Parameter,
2467 E_In_Out_Parameter,
2468 E_Out_Parameter,
2469 E_Variable)
2470 then
2471 -- The input cannot denote states or variables declared
2472 -- within the related package.
2474 if Within_Scope (Input_Id, Current_Scope) then
2475 Error_Msg_Name_1 := Chars (Pack_Id);
2476 SPARK_Msg_NE
2477 ("input item & cannot denote a visible variable or "
2478 & "state of package % (SPARK RM 7.1.5(4))",
2479 Input, Input_Id);
2481 -- Detect a duplicate use of the same input item
2482 -- (SPARK RM 7.1.5(5)).
2484 elsif Contains (Inputs_Seen, Input_Id) then
2485 SPARK_Msg_N ("duplicate input item", Input);
2487 -- Input is legal, add it to the list of processed inputs
2489 else
2490 Add_Item (Input_Id, Inputs_Seen);
2492 if Ekind (Input_Id) = E_Abstract_State then
2493 Add_Item (Input_Id, States_Seen);
2494 end if;
2496 if Ekind_In (Input_Id, E_Abstract_State, E_Variable)
2497 and then Present (Encapsulating_State (Input_Id))
2498 then
2499 Add_Item (Input_Id, Constits_Seen);
2500 end if;
2501 end if;
2503 -- The input references something that is not a state or a
2504 -- variable (SPARK RM 7.1.5(3)).
2506 else
2507 SPARK_Msg_N
2508 ("input item must denote variable or state", Input);
2509 end if;
2511 -- Some form of illegal construct masquerading as a name
2512 -- (SPARK RM 7.1.5(3)).
2514 else
2515 SPARK_Msg_N
2516 ("input item must denote variable or state", Input);
2517 end if;
2518 end if;
2519 end Analyze_Input_Item;
2521 -- Local variables
2523 Inputs : constant Node_Id := Expression (Item);
2524 Elmt : Node_Id;
2525 Input : Node_Id;
2527 Name_Seen : Boolean := False;
2528 -- A flag used to detect multiple item names
2530 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2532 begin
2533 -- Inspect the name of an item with inputs
2535 Elmt := First (Choices (Item));
2536 while Present (Elmt) loop
2537 if Name_Seen then
2538 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
2539 else
2540 Name_Seen := True;
2541 Analyze_Initialization_Item (Elmt);
2542 end if;
2544 Next (Elmt);
2545 end loop;
2547 -- Multiple input items appear as an aggregate
2549 if Nkind (Inputs) = N_Aggregate then
2550 if Present (Expressions (Inputs)) then
2551 Input := First (Expressions (Inputs));
2552 while Present (Input) loop
2553 Analyze_Input_Item (Input);
2554 Next (Input);
2555 end loop;
2556 end if;
2558 if Present (Component_Associations (Inputs)) then
2559 SPARK_Msg_N
2560 ("inputs must appear in named association form", Inputs);
2561 end if;
2563 -- Single input item
2565 else
2566 Analyze_Input_Item (Inputs);
2567 end if;
2568 end Analyze_Initialization_Item_With_Inputs;
2570 ----------------------------------
2571 -- Collect_States_And_Variables --
2572 ----------------------------------
2574 procedure Collect_States_And_Variables is
2575 Decl : Node_Id;
2577 begin
2578 -- Collect the abstract states defined in the package (if any)
2580 if Present (Abstract_States (Pack_Id)) then
2581 States_And_Vars := New_Copy_Elist (Abstract_States (Pack_Id));
2582 end if;
2584 -- Collect all variables the appear in the visible declarations of
2585 -- the related package.
2587 if Present (Visible_Declarations (Pack_Spec)) then
2588 Decl := First (Visible_Declarations (Pack_Spec));
2589 while Present (Decl) loop
2590 if Nkind (Decl) = N_Object_Declaration
2591 and then Ekind (Defining_Entity (Decl)) = E_Variable
2592 and then Comes_From_Source (Decl)
2593 then
2594 Add_Item (Defining_Entity (Decl), States_And_Vars);
2595 end if;
2597 Next (Decl);
2598 end loop;
2599 end if;
2600 end Collect_States_And_Variables;
2602 -- Local variables
2604 Inits : constant Node_Id :=
2605 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2606 Init : Node_Id;
2608 -- Start of processing for Analyze_Initializes_In_Decl_Part
2610 begin
2611 Set_Analyzed (N);
2613 Check_SPARK_Aspect_For_ASIS (N);
2615 -- Nothing to do when the initialization list is empty
2617 if Nkind (Inits) = N_Null then
2618 return;
2619 end if;
2621 -- Single and multiple initialization clauses appear as an aggregate. If
2622 -- this is not the case, then either the parser or the analysis of the
2623 -- pragma failed to produce an aggregate.
2625 pragma Assert (Nkind (Inits) = N_Aggregate);
2627 -- Initialize the various lists used during analysis
2629 Collect_States_And_Variables;
2631 if Present (Expressions (Inits)) then
2632 Init := First (Expressions (Inits));
2633 while Present (Init) loop
2634 Analyze_Initialization_Item (Init);
2635 Next (Init);
2636 end loop;
2637 end if;
2639 if Present (Component_Associations (Inits)) then
2640 Init := First (Component_Associations (Inits));
2641 while Present (Init) loop
2642 Analyze_Initialization_Item_With_Inputs (Init);
2643 Next (Init);
2644 end loop;
2645 end if;
2647 -- Ensure that a state and a corresponding constituent do not appear
2648 -- together in pragma Initializes.
2650 Check_State_And_Constituent_Use
2651 (States => States_Seen,
2652 Constits => Constits_Seen,
2653 Context => N);
2654 end Analyze_Initializes_In_Decl_Part;
2656 --------------------
2657 -- Analyze_Pragma --
2658 --------------------
2660 procedure Analyze_Pragma (N : Node_Id) is
2661 Loc : constant Source_Ptr := Sloc (N);
2662 Prag_Id : Pragma_Id;
2664 Pname : Name_Id;
2665 -- Name of the source pragma, or name of the corresponding aspect for
2666 -- pragmas which originate in a source aspect. In the latter case, the
2667 -- name may be different from the pragma name.
2669 Pragma_Exit : exception;
2670 -- This exception is used to exit pragma processing completely. It
2671 -- is used when an error is detected, and no further processing is
2672 -- required. It is also used if an earlier error has left the tree in
2673 -- a state where the pragma should not be processed.
2675 Arg_Count : Nat;
2676 -- Number of pragma argument associations
2678 Arg1 : Node_Id;
2679 Arg2 : Node_Id;
2680 Arg3 : Node_Id;
2681 Arg4 : Node_Id;
2682 -- First four pragma arguments (pragma argument association nodes, or
2683 -- Empty if the corresponding argument does not exist).
2685 type Name_List is array (Natural range <>) of Name_Id;
2686 type Args_List is array (Natural range <>) of Node_Id;
2687 -- Types used for arguments to Check_Arg_Order and Gather_Associations
2689 -----------------------
2690 -- Local Subprograms --
2691 -----------------------
2693 procedure Acquire_Warning_Match_String (Arg : Node_Id);
2694 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
2695 -- get the given string argument, and place it in Name_Buffer, adding
2696 -- leading and trailing asterisks if they are not already present. The
2697 -- caller has already checked that Arg is a static string expression.
2699 procedure Ada_2005_Pragma;
2700 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
2701 -- Ada 95 mode, these are implementation defined pragmas, so should be
2702 -- caught by the No_Implementation_Pragmas restriction.
2704 procedure Ada_2012_Pragma;
2705 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
2706 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
2707 -- should be caught by the No_Implementation_Pragmas restriction.
2709 procedure Analyze_Part_Of
2710 (Item_Id : Entity_Id;
2711 State : Node_Id;
2712 Indic : Node_Id;
2713 Legal : out Boolean);
2714 -- Subsidiary to the analysis of pragmas Abstract_State and Part_Of.
2715 -- Perform full analysis of indicator Part_Of. Item_Id is the entity of
2716 -- an abstract state, variable or package instantiation. State is the
2717 -- encapsulating state. Indic is the Part_Of indicator. Flag Legal is
2718 -- set when the indicator is legal.
2720 procedure Analyze_Refined_Pragma
2721 (Spec_Id : out Entity_Id;
2722 Body_Id : out Entity_Id;
2723 Legal : out Boolean);
2724 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
2725 -- Refined_Global and Refined_Post. Check the placement and related
2726 -- context of the pragma. Spec_Id is the entity of the related
2727 -- subprogram. Body_Id is the entity of the subprogram body. Flag
2728 -- Legal is set when the pragma is properly placed.
2730 procedure Check_Ada_83_Warning;
2731 -- Issues a warning message for the current pragma if operating in Ada
2732 -- 83 mode (used for language pragmas that are not a standard part of
2733 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
2734 -- of 95 pragma.
2736 procedure Check_Arg_Count (Required : Nat);
2737 -- Check argument count for pragma is equal to given parameter. If not,
2738 -- then issue an error message and raise Pragma_Exit.
2740 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
2741 -- Arg which can either be a pragma argument association, in which case
2742 -- the check is applied to the expression of the association or an
2743 -- expression directly.
2745 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
2746 -- Check that an argument has the right form for an EXTERNAL_NAME
2747 -- parameter of an extended import/export pragma. The rule is that the
2748 -- name must be an identifier or string literal (in Ada 83 mode) or a
2749 -- static string expression (in Ada 95 mode).
2751 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
2752 -- Check the specified argument Arg to make sure that it is an
2753 -- identifier. If not give error and raise Pragma_Exit.
2755 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
2756 -- Check the specified argument Arg to make sure that it is an integer
2757 -- literal. If not give error and raise Pragma_Exit.
2759 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
2760 -- Check the specified argument Arg to make sure that it has the proper
2761 -- syntactic form for a local name and meets the semantic requirements
2762 -- for a local name. The local name is analyzed as part of the
2763 -- processing for this call. In addition, the local name is required
2764 -- to represent an entity at the library level.
2766 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
2767 -- Check the specified argument Arg to make sure that it has the proper
2768 -- syntactic form for a local name and meets the semantic requirements
2769 -- for a local name. The local name is analyzed as part of the
2770 -- processing for this call.
2772 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
2773 -- Check the specified argument Arg to make sure that it is a valid
2774 -- locking policy name. If not give error and raise Pragma_Exit.
2776 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
2777 -- Check the specified argument Arg to make sure that it is a valid
2778 -- elaboration policy name. If not give error and raise Pragma_Exit.
2780 procedure Check_Arg_Is_One_Of
2781 (Arg : Node_Id;
2782 N1, N2 : Name_Id);
2783 procedure Check_Arg_Is_One_Of
2784 (Arg : Node_Id;
2785 N1, N2, N3 : Name_Id);
2786 procedure Check_Arg_Is_One_Of
2787 (Arg : Node_Id;
2788 N1, N2, N3, N4 : Name_Id);
2789 procedure Check_Arg_Is_One_Of
2790 (Arg : Node_Id;
2791 N1, N2, N3, N4, N5 : Name_Id);
2792 -- Check the specified argument Arg to make sure that it is an
2793 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
2794 -- present). If not then give error and raise Pragma_Exit.
2796 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
2797 -- Check the specified argument Arg to make sure that it is a valid
2798 -- queuing policy name. If not give error and raise Pragma_Exit.
2800 procedure Check_Arg_Is_OK_Static_Expression
2801 (Arg : Node_Id;
2802 Typ : Entity_Id := Empty);
2803 -- Check the specified argument Arg to make sure that it is a static
2804 -- expression of the given type (i.e. it will be analyzed and resolved
2805 -- using this type, which can be any valid argument to Resolve, e.g.
2806 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2807 -- Typ is left Empty, then any static expression is allowed. Includes
2808 -- checking that the argument does not raise Constraint_Error.
2810 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
2811 -- Check the specified argument Arg to make sure that it is a valid task
2812 -- dispatching policy name. If not give error and raise Pragma_Exit.
2814 procedure Check_Arg_Order (Names : Name_List);
2815 -- Checks for an instance of two arguments with identifiers for the
2816 -- current pragma which are not in the sequence indicated by Names,
2817 -- and if so, generates a fatal message about bad order of arguments.
2819 procedure Check_At_Least_N_Arguments (N : Nat);
2820 -- Check there are at least N arguments present
2822 procedure Check_At_Most_N_Arguments (N : Nat);
2823 -- Check there are no more than N arguments present
2825 procedure Check_Component
2826 (Comp : Node_Id;
2827 UU_Typ : Entity_Id;
2828 In_Variant_Part : Boolean := False);
2829 -- Examine an Unchecked_Union component for correct use of per-object
2830 -- constrained subtypes, and for restrictions on finalizable components.
2831 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
2832 -- should be set when Comp comes from a record variant.
2834 procedure Check_Declaration_Order (First : Node_Id; Second : Node_Id);
2835 -- Subsidiary routine to the analysis of pragmas Abstract_State,
2836 -- Initial_Condition and Initializes. Determine whether pragma First
2837 -- appears before pragma Second. If this is not the case, emit an error.
2839 procedure Check_Duplicate_Pragma (E : Entity_Id);
2840 -- Check if a rep item of the same name as the current pragma is already
2841 -- chained as a rep pragma to the given entity. If so give a message
2842 -- about the duplicate, and then raise Pragma_Exit so does not return.
2843 -- Note that if E is a type, then this routine avoids flagging a pragma
2844 -- which applies to a parent type from which E is derived.
2846 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
2847 -- Nam is an N_String_Literal node containing the external name set by
2848 -- an Import or Export pragma (or extended Import or Export pragma).
2849 -- This procedure checks for possible duplications if this is the export
2850 -- case, and if found, issues an appropriate error message.
2852 procedure Check_Expr_Is_OK_Static_Expression
2853 (Expr : Node_Id;
2854 Typ : Entity_Id := Empty);
2855 -- Check the specified expression Expr to make sure that it is a static
2856 -- expression of the given type (i.e. it will be analyzed and resolved
2857 -- using this type, which can be any valid argument to Resolve, e.g.
2858 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2859 -- Typ is left Empty, then any static expression is allowed. Includes
2860 -- checking that the expression does not raise Constraint_Error.
2862 procedure Check_First_Subtype (Arg : Node_Id);
2863 -- Checks that Arg, whose expression is an entity name, references a
2864 -- first subtype.
2866 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
2867 -- Checks that the given argument has an identifier, and if so, requires
2868 -- it to match the given identifier name. If there is no identifier, or
2869 -- a non-matching identifier, then an error message is given and
2870 -- Pragma_Exit is raised.
2872 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
2873 -- Checks that the given argument has an identifier, and if so, requires
2874 -- it to match one of the given identifier names. If there is no
2875 -- identifier, or a non-matching identifier, then an error message is
2876 -- given and Pragma_Exit is raised.
2878 procedure Check_In_Main_Program;
2879 -- Common checks for pragmas that appear within a main program
2880 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
2882 procedure Check_Interrupt_Or_Attach_Handler;
2883 -- Common processing for first argument of pragma Interrupt_Handler or
2884 -- pragma Attach_Handler.
2886 procedure Check_Loop_Pragma_Placement;
2887 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
2888 -- appear immediately within a construct restricted to loops, and that
2889 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
2891 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
2892 -- Check that pragma appears in a declarative part, or in a package
2893 -- specification, i.e. that it does not occur in a statement sequence
2894 -- in a body.
2896 procedure Check_No_Identifier (Arg : Node_Id);
2897 -- Checks that the given argument does not have an identifier. If
2898 -- an identifier is present, then an error message is issued, and
2899 -- Pragma_Exit is raised.
2901 procedure Check_No_Identifiers;
2902 -- Checks that none of the arguments to the pragma has an identifier.
2903 -- If any argument has an identifier, then an error message is issued,
2904 -- and Pragma_Exit is raised.
2906 procedure Check_No_Link_Name;
2907 -- Checks that no link name is specified
2909 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
2910 -- Checks if the given argument has an identifier, and if so, requires
2911 -- it to match the given identifier name. If there is a non-matching
2912 -- identifier, then an error message is given and Pragma_Exit is raised.
2914 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
2915 -- Checks if the given argument has an identifier, and if so, requires
2916 -- it to match the given identifier name. If there is a non-matching
2917 -- identifier, then an error message is given and Pragma_Exit is raised.
2918 -- In this version of the procedure, the identifier name is given as
2919 -- a string with lower case letters.
2921 procedure Check_Pre_Post;
2922 -- Called to perform checks for Pre, Pre_Class, Post, Post_Class
2923 -- pragmas. These are processed by transformation to equivalent
2924 -- Precondition and Postcondition pragmas, but Pre and Post need an
2925 -- additional check that they are not used in a subprogram body when
2926 -- there is a separate spec present.
2928 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
2929 -- Called to process a precondition or postcondition pragma. There are
2930 -- three cases:
2932 -- The pragma appears after a subprogram spec
2934 -- If the corresponding check is not enabled, the pragma is analyzed
2935 -- but otherwise ignored and control returns with In_Body set False.
2937 -- If the check is enabled, then the first step is to analyze the
2938 -- pragma, but this is skipped if the subprogram spec appears within
2939 -- a package specification (because this is the case where we delay
2940 -- analysis till the end of the spec). Then (whether or not it was
2941 -- analyzed), the pragma is chained to the subprogram in question
2942 -- (using Pre_Post_Conditions and Next_Pragma) and control returns
2943 -- to the caller with In_Body set False.
2945 -- The pragma appears at the start of subprogram body declarations
2947 -- In this case an immediate return to the caller is made with
2948 -- In_Body set True, and the pragma is NOT analyzed.
2950 -- In all other cases, an error message for bad placement is given
2952 procedure Check_Static_Constraint (Constr : Node_Id);
2953 -- Constr is a constraint from an N_Subtype_Indication node from a
2954 -- component constraint in an Unchecked_Union type. This routine checks
2955 -- that the constraint is static as required by the restrictions for
2956 -- Unchecked_Union.
2958 procedure Check_Test_Case;
2959 -- Called to process a test-case pragma. It starts with checking pragma
2960 -- arguments, and the rest of the treatment is similar to the one for
2961 -- pre- and postcondition in Check_Precondition_Postcondition, except
2962 -- the placement rules for the test-case pragma are stricter. These
2963 -- pragmas may only occur after a subprogram spec declared directly
2964 -- in a package spec unit. In this case, the pragma is chained to the
2965 -- subprogram in question (using Contract_Test_Cases and Next_Pragma)
2966 -- and analysis of the pragma is delayed till the end of the spec. In
2967 -- all other cases, an error message for bad placement is given.
2969 procedure Check_Valid_Configuration_Pragma;
2970 -- Legality checks for placement of a configuration pragma
2972 procedure Check_Valid_Library_Unit_Pragma;
2973 -- Legality checks for library unit pragmas. A special case arises for
2974 -- pragmas in generic instances that come from copies of the original
2975 -- library unit pragmas in the generic templates. In the case of other
2976 -- than library level instantiations these can appear in contexts which
2977 -- would normally be invalid (they only apply to the original template
2978 -- and to library level instantiations), and they are simply ignored,
2979 -- which is implemented by rewriting them as null statements.
2981 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
2982 -- Check an Unchecked_Union variant for lack of nested variants and
2983 -- presence of at least one component. UU_Typ is the related Unchecked_
2984 -- Union type.
2986 procedure Ensure_Aggregate_Form (Arg : Node_Id);
2987 -- Subsidiary routine to the processing of pragmas Abstract_State,
2988 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
2989 -- Refined_Global and Refined_State. Transform argument Arg into an
2990 -- aggregate if not one already. N_Null is never transformed.
2992 procedure Error_Pragma (Msg : String);
2993 pragma No_Return (Error_Pragma);
2994 -- Outputs error message for current pragma. The message contains a %
2995 -- that will be replaced with the pragma name, and the flag is placed
2996 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
2997 -- calls Fix_Error (see spec of that procedure for details).
2999 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
3000 pragma No_Return (Error_Pragma_Arg);
3001 -- Outputs error message for current pragma. The message may contain
3002 -- a % that will be replaced with the pragma name. The parameter Arg
3003 -- may either be a pragma argument association, in which case the flag
3004 -- is placed on the expression of this association, or an expression,
3005 -- in which case the flag is placed directly on the expression. The
3006 -- message is placed using Error_Msg_N, so the message may also contain
3007 -- an & insertion character which will reference the given Arg value.
3008 -- After placing the message, Pragma_Exit is raised. Note: this routine
3009 -- calls Fix_Error (see spec of that procedure for details).
3011 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
3012 pragma No_Return (Error_Pragma_Arg);
3013 -- Similar to above form of Error_Pragma_Arg except that two messages
3014 -- are provided, the second is a continuation comment starting with \.
3016 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
3017 pragma No_Return (Error_Pragma_Arg_Ident);
3018 -- Outputs error message for current pragma. The message may contain a %
3019 -- that will be replaced with the pragma name. The parameter Arg must be
3020 -- a pragma argument association with a non-empty identifier (i.e. its
3021 -- Chars field must be set), and the error message is placed on the
3022 -- identifier. The message is placed using Error_Msg_N so the message
3023 -- may also contain an & insertion character which will reference
3024 -- the identifier. After placing the message, Pragma_Exit is raised.
3025 -- Note: this routine calls Fix_Error (see spec of that procedure for
3026 -- details).
3028 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
3029 pragma No_Return (Error_Pragma_Ref);
3030 -- Outputs error message for current pragma. The message may contain
3031 -- a % that will be replaced with the pragma name. The parameter Ref
3032 -- must be an entity whose name can be referenced by & and sloc by #.
3033 -- After placing the message, Pragma_Exit is raised. Note: this routine
3034 -- calls Fix_Error (see spec of that procedure for details).
3036 function Find_Lib_Unit_Name return Entity_Id;
3037 -- Used for a library unit pragma to find the entity to which the
3038 -- library unit pragma applies, returns the entity found.
3040 procedure Find_Program_Unit_Name (Id : Node_Id);
3041 -- If the pragma is a compilation unit pragma, the id must denote the
3042 -- compilation unit in the same compilation, and the pragma must appear
3043 -- in the list of preceding or trailing pragmas. If it is a program
3044 -- unit pragma that is not a compilation unit pragma, then the
3045 -- identifier must be visible.
3047 function Find_Unique_Parameterless_Procedure
3048 (Name : Entity_Id;
3049 Arg : Node_Id) return Entity_Id;
3050 -- Used for a procedure pragma to find the unique parameterless
3051 -- procedure identified by Name, returns it if it exists, otherwise
3052 -- errors out and uses Arg as the pragma argument for the message.
3054 function Fix_Error (Msg : String) return String;
3055 -- This is called prior to issuing an error message. Msg is the normal
3056 -- error message issued in the pragma case. This routine checks for the
3057 -- case of a pragma coming from an aspect in the source, and returns a
3058 -- message suitable for the aspect case as follows:
3060 -- Each substring "pragma" is replaced by "aspect"
3062 -- If "argument of" is at the start of the error message text, it is
3063 -- replaced by "entity for".
3065 -- If "argument" is at the start of the error message text, it is
3066 -- replaced by "entity".
3068 -- So for example, "argument of pragma X must be discrete type"
3069 -- returns "entity for aspect X must be a discrete type".
3071 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
3072 -- be different from the pragma name). If the current pragma results
3073 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
3074 -- original pragma name.
3076 procedure Gather_Associations
3077 (Names : Name_List;
3078 Args : out Args_List);
3079 -- This procedure is used to gather the arguments for a pragma that
3080 -- permits arbitrary ordering of parameters using the normal rules
3081 -- for named and positional parameters. The Names argument is a list
3082 -- of Name_Id values that corresponds to the allowed pragma argument
3083 -- association identifiers in order. The result returned in Args is
3084 -- a list of corresponding expressions that are the pragma arguments.
3085 -- Note that this is a list of expressions, not of pragma argument
3086 -- associations (Gather_Associations has completely checked all the
3087 -- optional identifiers when it returns). An entry in Args is Empty
3088 -- on return if the corresponding argument is not present.
3090 procedure GNAT_Pragma;
3091 -- Called for all GNAT defined pragmas to check the relevant restriction
3092 -- (No_Implementation_Pragmas).
3094 function Is_Before_First_Decl
3095 (Pragma_Node : Node_Id;
3096 Decls : List_Id) return Boolean;
3097 -- Return True if Pragma_Node is before the first declarative item in
3098 -- Decls where Decls is the list of declarative items.
3100 function Is_Configuration_Pragma return Boolean;
3101 -- Determines if the placement of the current pragma is appropriate
3102 -- for a configuration pragma.
3104 function Is_In_Context_Clause return Boolean;
3105 -- Returns True if pragma appears within the context clause of a unit,
3106 -- and False for any other placement (does not generate any messages).
3108 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
3109 -- Analyzes the argument, and determines if it is a static string
3110 -- expression, returns True if so, False if non-static or not String.
3111 -- A special case is that a string literal returns True in Ada 83 mode
3112 -- (which has no such thing as static string expressions).
3114 procedure Pragma_Misplaced;
3115 pragma No_Return (Pragma_Misplaced);
3116 -- Issue fatal error message for misplaced pragma
3118 procedure Process_Atomic_Independent_Shared_Volatile;
3119 -- Common processing for pragmas Atomic, Independent, Shared, Volatile.
3120 -- Note that Shared is an obsolete Ada 83 pragma and treated as being
3121 -- identical in effect to pragma Atomic.
3123 procedure Process_Compile_Time_Warning_Or_Error;
3124 -- Common processing for Compile_Time_Error and Compile_Time_Warning
3126 procedure Process_Convention
3127 (C : out Convention_Id;
3128 Ent : out Entity_Id);
3129 -- Common processing for Convention, Interface, Import and Export.
3130 -- Checks first two arguments of pragma, and sets the appropriate
3131 -- convention value in the specified entity or entities. On return
3132 -- C is the convention, Ent is the referenced entity.
3134 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
3135 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
3136 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
3138 procedure Process_Extended_Import_Export_Object_Pragma
3139 (Arg_Internal : Node_Id;
3140 Arg_External : Node_Id;
3141 Arg_Size : Node_Id);
3142 -- Common processing for the pragmas Import/Export_Object. The three
3143 -- arguments correspond to the three named parameters of the pragmas. An
3144 -- argument is empty if the corresponding parameter is not present in
3145 -- the pragma.
3147 procedure Process_Extended_Import_Export_Internal_Arg
3148 (Arg_Internal : Node_Id := Empty);
3149 -- Common processing for all extended Import and Export pragmas. The
3150 -- argument is the pragma parameter for the Internal argument. If
3151 -- Arg_Internal is empty or inappropriate, an error message is posted.
3152 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
3153 -- set to identify the referenced entity.
3155 procedure Process_Extended_Import_Export_Subprogram_Pragma
3156 (Arg_Internal : Node_Id;
3157 Arg_External : Node_Id;
3158 Arg_Parameter_Types : Node_Id;
3159 Arg_Result_Type : Node_Id := Empty;
3160 Arg_Mechanism : Node_Id;
3161 Arg_Result_Mechanism : Node_Id := Empty);
3162 -- Common processing for all extended Import and Export pragmas applying
3163 -- to subprograms. The caller omits any arguments that do not apply to
3164 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
3165 -- only in the Import_Function and Export_Function cases). The argument
3166 -- names correspond to the allowed pragma association identifiers.
3168 procedure Process_Generic_List;
3169 -- Common processing for Share_Generic and Inline_Generic
3171 procedure Process_Import_Or_Interface;
3172 -- Common processing for Import of Interface
3174 procedure Process_Import_Predefined_Type;
3175 -- Processing for completing a type with pragma Import. This is used
3176 -- to declare types that match predefined C types, especially for cases
3177 -- without corresponding Ada predefined type.
3179 type Inline_Status is (Suppressed, Disabled, Enabled);
3180 -- Inline status of a subprogram, indicated as follows:
3181 -- Suppressed: inlining is suppressed for the subprogram
3182 -- Disabled: no inlining is requested for the subprogram
3183 -- Enabled: inlining is requested/required for the subprogram
3185 procedure Process_Inline (Status : Inline_Status);
3186 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
3187 -- indicates the inline status specified by the pragma.
3189 procedure Process_Interface_Name
3190 (Subprogram_Def : Entity_Id;
3191 Ext_Arg : Node_Id;
3192 Link_Arg : Node_Id);
3193 -- Given the last two arguments of pragma Import, pragma Export, or
3194 -- pragma Interface_Name, performs validity checks and sets the
3195 -- Interface_Name field of the given subprogram entity to the
3196 -- appropriate external or link name, depending on the arguments given.
3197 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
3198 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
3199 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
3200 -- nor Link_Arg is present, the interface name is set to the default
3201 -- from the subprogram name.
3203 procedure Process_Interrupt_Or_Attach_Handler;
3204 -- Common processing for Interrupt and Attach_Handler pragmas
3206 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
3207 -- Common processing for Restrictions and Restriction_Warnings pragmas.
3208 -- Warn is True for Restriction_Warnings, or for Restrictions if the
3209 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
3210 -- is not set in the Restrictions case.
3212 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
3213 -- Common processing for Suppress and Unsuppress. The boolean parameter
3214 -- Suppress_Case is True for the Suppress case, and False for the
3215 -- Unsuppress case.
3217 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
3218 -- This procedure sets the Is_Exported flag for the given entity,
3219 -- checking that the entity was not previously imported. Arg is
3220 -- the argument that specified the entity. A check is also made
3221 -- for exporting inappropriate entities.
3223 procedure Set_Extended_Import_Export_External_Name
3224 (Internal_Ent : Entity_Id;
3225 Arg_External : Node_Id);
3226 -- Common processing for all extended import export pragmas. The first
3227 -- argument, Internal_Ent, is the internal entity, which has already
3228 -- been checked for validity by the caller. Arg_External is from the
3229 -- Import or Export pragma, and may be null if no External parameter
3230 -- was present. If Arg_External is present and is a non-null string
3231 -- (a null string is treated as the default), then the Interface_Name
3232 -- field of Internal_Ent is set appropriately.
3234 procedure Set_Imported (E : Entity_Id);
3235 -- This procedure sets the Is_Imported flag for the given entity,
3236 -- checking that it is not previously exported or imported.
3238 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
3239 -- Mech is a parameter passing mechanism (see Import_Function syntax
3240 -- for MECHANISM_NAME). This routine checks that the mechanism argument
3241 -- has the right form, and if not issues an error message. If the
3242 -- argument has the right form then the Mechanism field of Ent is
3243 -- set appropriately.
3245 procedure Set_Rational_Profile;
3246 -- Activate the set of configuration pragmas and permissions that make
3247 -- up the Rational profile.
3249 procedure Set_Ravenscar_Profile (N : Node_Id);
3250 -- Activate the set of configuration pragmas and restrictions that make
3251 -- up the Ravenscar Profile. N is the corresponding pragma node, which
3252 -- is used for error messages on any constructs violating the profile.
3254 ----------------------------------
3255 -- Acquire_Warning_Match_String --
3256 ----------------------------------
3258 procedure Acquire_Warning_Match_String (Arg : Node_Id) is
3259 begin
3260 String_To_Name_Buffer
3261 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
3263 -- Add asterisk at start if not already there
3265 if Name_Len > 0 and then Name_Buffer (1) /= '*' then
3266 Name_Buffer (2 .. Name_Len + 1) :=
3267 Name_Buffer (1 .. Name_Len);
3268 Name_Buffer (1) := '*';
3269 Name_Len := Name_Len + 1;
3270 end if;
3272 -- Add asterisk at end if not already there
3274 if Name_Buffer (Name_Len) /= '*' then
3275 Name_Len := Name_Len + 1;
3276 Name_Buffer (Name_Len) := '*';
3277 end if;
3278 end Acquire_Warning_Match_String;
3280 ---------------------
3281 -- Ada_2005_Pragma --
3282 ---------------------
3284 procedure Ada_2005_Pragma is
3285 begin
3286 if Ada_Version <= Ada_95 then
3287 Check_Restriction (No_Implementation_Pragmas, N);
3288 end if;
3289 end Ada_2005_Pragma;
3291 ---------------------
3292 -- Ada_2012_Pragma --
3293 ---------------------
3295 procedure Ada_2012_Pragma is
3296 begin
3297 if Ada_Version <= Ada_2005 then
3298 Check_Restriction (No_Implementation_Pragmas, N);
3299 end if;
3300 end Ada_2012_Pragma;
3302 ---------------------
3303 -- Analyze_Part_Of --
3304 ---------------------
3306 procedure Analyze_Part_Of
3307 (Item_Id : Entity_Id;
3308 State : Node_Id;
3309 Indic : Node_Id;
3310 Legal : out Boolean)
3312 Pack_Id : Entity_Id;
3313 Placement : State_Space_Kind;
3314 Parent_Unit : Entity_Id;
3315 State_Id : Entity_Id;
3317 begin
3318 -- Assume that the pragma/option is illegal
3320 Legal := False;
3322 if Nkind_In (State, N_Expanded_Name,
3323 N_Identifier,
3324 N_Selected_Component)
3325 then
3326 Analyze (State);
3327 Resolve_State (State);
3329 if Is_Entity_Name (State)
3330 and then Ekind (Entity (State)) = E_Abstract_State
3331 then
3332 State_Id := Entity (State);
3334 else
3335 SPARK_Msg_N
3336 ("indicator Part_Of must denote an abstract state", State);
3337 return;
3338 end if;
3340 -- This is a syntax error, always report
3342 else
3343 Error_Msg_N
3344 ("indicator Part_Of must denote an abstract state", State);
3345 return;
3346 end if;
3348 -- Determine where the state, variable or the package instantiation
3349 -- lives with respect to the enclosing packages or package bodies (if
3350 -- any). This placement dictates the legality of the encapsulating
3351 -- state.
3353 Find_Placement_In_State_Space
3354 (Item_Id => Item_Id,
3355 Placement => Placement,
3356 Pack_Id => Pack_Id);
3358 -- The item appears in a non-package construct with a declarative
3359 -- part (subprogram, block, etc). As such, the item is not allowed
3360 -- to be a part of an encapsulating state because the item is not
3361 -- visible.
3363 if Placement = Not_In_Package then
3364 SPARK_Msg_N
3365 ("indicator Part_Of cannot appear in this context "
3366 & "(SPARK RM 7.2.6(5))", Indic);
3367 Error_Msg_Name_1 := Chars (Scope (State_Id));
3368 SPARK_Msg_NE
3369 ("\& is not part of the hidden state of package %",
3370 Indic, Item_Id);
3372 -- The item appears in the visible state space of some package. In
3373 -- general this scenario does not warrant Part_Of except when the
3374 -- package is a private child unit and the encapsulating state is
3375 -- declared in a parent unit or a public descendant of that parent
3376 -- unit.
3378 elsif Placement = Visible_State_Space then
3379 if Is_Child_Unit (Pack_Id)
3380 and then Is_Private_Descendant (Pack_Id)
3381 then
3382 -- A variable or state abstraction which is part of the
3383 -- visible state of a private child unit (or one of its public
3384 -- descendants) must have its Part_Of indicator specified. The
3385 -- Part_Of indicator must denote a state abstraction declared
3386 -- by either the parent unit of the private unit or by a public
3387 -- descendant of that parent unit.
3389 -- Find nearest private ancestor (which can be the current unit
3390 -- itself).
3392 Parent_Unit := Pack_Id;
3393 while Present (Parent_Unit) loop
3394 exit when Private_Present
3395 (Parent (Unit_Declaration_Node (Parent_Unit)));
3396 Parent_Unit := Scope (Parent_Unit);
3397 end loop;
3399 Parent_Unit := Scope (Parent_Unit);
3401 if not Is_Child_Or_Sibling (Pack_Id, Scope (State_Id)) then
3402 SPARK_Msg_NE
3403 ("indicator Part_Of must denote an abstract state of& "
3404 & "or public descendant (SPARK RM 7.2.6(3))",
3405 Indic, Parent_Unit);
3407 elsif Scope (State_Id) = Parent_Unit
3408 or else (Is_Ancestor_Package (Parent_Unit, Scope (State_Id))
3409 and then
3410 not Is_Private_Descendant (Scope (State_Id)))
3411 then
3412 null;
3414 else
3415 SPARK_Msg_NE
3416 ("indicator Part_Of must denote an abstract state of& "
3417 & "or public descendant (SPARK RM 7.2.6(3))",
3418 Indic, Parent_Unit);
3419 end if;
3421 -- Indicator Part_Of is not needed when the related package is not
3422 -- a private child unit or a public descendant thereof.
3424 else
3425 SPARK_Msg_N
3426 ("indicator Part_Of cannot appear in this context "
3427 & "(SPARK RM 7.2.6(5))", Indic);
3428 Error_Msg_Name_1 := Chars (Pack_Id);
3429 SPARK_Msg_NE
3430 ("\& is declared in the visible part of package %",
3431 Indic, Item_Id);
3432 end if;
3434 -- When the item appears in the private state space of a package, the
3435 -- encapsulating state must be declared in the same package.
3437 elsif Placement = Private_State_Space then
3438 if Scope (State_Id) /= Pack_Id then
3439 SPARK_Msg_NE
3440 ("indicator Part_Of must designate an abstract state of "
3441 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3442 Error_Msg_Name_1 := Chars (Pack_Id);
3443 SPARK_Msg_NE
3444 ("\& is declared in the private part of package %",
3445 Indic, Item_Id);
3446 end if;
3448 -- Items declared in the body state space of a package do not need
3449 -- Part_Of indicators as the refinement has already been seen.
3451 else
3452 SPARK_Msg_N
3453 ("indicator Part_Of cannot appear in this context "
3454 & "(SPARK RM 7.2.6(5))", Indic);
3456 if Scope (State_Id) = Pack_Id then
3457 Error_Msg_Name_1 := Chars (Pack_Id);
3458 SPARK_Msg_NE
3459 ("\& is declared in the body of package %", Indic, Item_Id);
3460 end if;
3461 end if;
3463 Legal := True;
3464 end Analyze_Part_Of;
3466 ----------------------------
3467 -- Analyze_Refined_Pragma --
3468 ----------------------------
3470 procedure Analyze_Refined_Pragma
3471 (Spec_Id : out Entity_Id;
3472 Body_Id : out Entity_Id;
3473 Legal : out Boolean)
3475 Body_Decl : Node_Id;
3476 Spec_Decl : Node_Id;
3478 begin
3479 -- Assume that the pragma is illegal
3481 Spec_Id := Empty;
3482 Body_Id := Empty;
3483 Legal := False;
3485 GNAT_Pragma;
3486 Check_Arg_Count (1);
3487 Check_No_Identifiers;
3489 if Nam_In (Pname, Name_Refined_Depends,
3490 Name_Refined_Global,
3491 Name_Refined_State)
3492 then
3493 Ensure_Aggregate_Form (Arg1);
3494 end if;
3496 -- Verify the placement of the pragma and check for duplicates. The
3497 -- pragma must apply to a subprogram body [stub].
3499 Body_Decl := Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
3501 -- Extract the entities of the spec and body
3503 if Nkind (Body_Decl) = N_Subprogram_Body then
3504 Body_Id := Defining_Entity (Body_Decl);
3505 Spec_Id := Corresponding_Spec (Body_Decl);
3507 elsif Nkind (Body_Decl) = N_Subprogram_Body_Stub then
3508 Body_Id := Defining_Entity (Body_Decl);
3509 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
3511 else
3512 Pragma_Misplaced;
3513 return;
3514 end if;
3516 -- The pragma must apply to the second declaration of a subprogram.
3517 -- In other words, the body [stub] cannot acts as a spec.
3519 if No (Spec_Id) then
3520 Error_Pragma ("pragma % cannot apply to a stand alone body");
3521 return;
3523 -- Catch the case where the subprogram body is a subunit and acts as
3524 -- the third declaration of the subprogram.
3526 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
3527 Error_Pragma ("pragma % cannot apply to a subunit");
3528 return;
3529 end if;
3531 -- The pragma can only apply to the body [stub] of a subprogram
3532 -- declared in the visible part of a package. Retrieve the context of
3533 -- the subprogram declaration.
3535 Spec_Decl := Parent (Parent (Spec_Id));
3537 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
3538 Error_Pragma
3539 ("pragma % must apply to the body of a subprogram declared in a "
3540 & "package specification");
3541 return;
3542 end if;
3544 -- If we get here, then the pragma is legal
3546 Legal := True;
3547 end Analyze_Refined_Pragma;
3549 --------------------------
3550 -- Check_Ada_83_Warning --
3551 --------------------------
3553 procedure Check_Ada_83_Warning is
3554 begin
3555 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
3556 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
3557 end if;
3558 end Check_Ada_83_Warning;
3560 ---------------------
3561 -- Check_Arg_Count --
3562 ---------------------
3564 procedure Check_Arg_Count (Required : Nat) is
3565 begin
3566 if Arg_Count /= Required then
3567 Error_Pragma ("wrong number of arguments for pragma%");
3568 end if;
3569 end Check_Arg_Count;
3571 --------------------------------
3572 -- Check_Arg_Is_External_Name --
3573 --------------------------------
3575 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
3576 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3578 begin
3579 if Nkind (Argx) = N_Identifier then
3580 return;
3582 else
3583 Analyze_And_Resolve (Argx, Standard_String);
3585 if Is_OK_Static_Expression (Argx) then
3586 return;
3588 elsif Etype (Argx) = Any_Type then
3589 raise Pragma_Exit;
3591 -- An interesting special case, if we have a string literal and
3592 -- we are in Ada 83 mode, then we allow it even though it will
3593 -- not be flagged as static. This allows expected Ada 83 mode
3594 -- use of external names which are string literals, even though
3595 -- technically these are not static in Ada 83.
3597 elsif Ada_Version = Ada_83
3598 and then Nkind (Argx) = N_String_Literal
3599 then
3600 return;
3602 -- Static expression that raises Constraint_Error. This has
3603 -- already been flagged, so just exit from pragma processing.
3605 elsif Is_OK_Static_Expression (Argx) then
3606 raise Pragma_Exit;
3608 -- Here we have a real error (non-static expression)
3610 else
3611 Error_Msg_Name_1 := Pname;
3613 declare
3614 Msg : constant String :=
3615 "argument for pragma% must be a identifier or "
3616 & "static string expression!";
3617 begin
3618 Flag_Non_Static_Expr (Fix_Error (Msg), Argx);
3619 raise Pragma_Exit;
3620 end;
3621 end if;
3622 end if;
3623 end Check_Arg_Is_External_Name;
3625 -----------------------------
3626 -- Check_Arg_Is_Identifier --
3627 -----------------------------
3629 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
3630 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3631 begin
3632 if Nkind (Argx) /= N_Identifier then
3633 Error_Pragma_Arg
3634 ("argument for pragma% must be identifier", Argx);
3635 end if;
3636 end Check_Arg_Is_Identifier;
3638 ----------------------------------
3639 -- Check_Arg_Is_Integer_Literal --
3640 ----------------------------------
3642 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
3643 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3644 begin
3645 if Nkind (Argx) /= N_Integer_Literal then
3646 Error_Pragma_Arg
3647 ("argument for pragma% must be integer literal", Argx);
3648 end if;
3649 end Check_Arg_Is_Integer_Literal;
3651 -------------------------------------------
3652 -- Check_Arg_Is_Library_Level_Local_Name --
3653 -------------------------------------------
3655 -- LOCAL_NAME ::=
3656 -- DIRECT_NAME
3657 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3658 -- | library_unit_NAME
3660 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
3661 begin
3662 Check_Arg_Is_Local_Name (Arg);
3664 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
3665 and then Comes_From_Source (N)
3666 then
3667 Error_Pragma_Arg
3668 ("argument for pragma% must be library level entity", Arg);
3669 end if;
3670 end Check_Arg_Is_Library_Level_Local_Name;
3672 -----------------------------
3673 -- Check_Arg_Is_Local_Name --
3674 -----------------------------
3676 -- LOCAL_NAME ::=
3677 -- DIRECT_NAME
3678 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3679 -- | library_unit_NAME
3681 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
3682 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3684 begin
3685 Analyze (Argx);
3687 if Nkind (Argx) not in N_Direct_Name
3688 and then (Nkind (Argx) /= N_Attribute_Reference
3689 or else Present (Expressions (Argx))
3690 or else Nkind (Prefix (Argx)) /= N_Identifier)
3691 and then (not Is_Entity_Name (Argx)
3692 or else not Is_Compilation_Unit (Entity (Argx)))
3693 then
3694 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
3695 end if;
3697 -- No further check required if not an entity name
3699 if not Is_Entity_Name (Argx) then
3700 null;
3702 else
3703 declare
3704 OK : Boolean;
3705 Ent : constant Entity_Id := Entity (Argx);
3706 Scop : constant Entity_Id := Scope (Ent);
3708 begin
3709 -- Case of a pragma applied to a compilation unit: pragma must
3710 -- occur immediately after the program unit in the compilation.
3712 if Is_Compilation_Unit (Ent) then
3713 declare
3714 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
3716 begin
3717 -- Case of pragma placed immediately after spec
3719 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
3720 OK := True;
3722 -- Case of pragma placed immediately after body
3724 elsif Nkind (Decl) = N_Subprogram_Declaration
3725 and then Present (Corresponding_Body (Decl))
3726 then
3727 OK := Parent (N) =
3728 Aux_Decls_Node
3729 (Parent (Unit_Declaration_Node
3730 (Corresponding_Body (Decl))));
3732 -- All other cases are illegal
3734 else
3735 OK := False;
3736 end if;
3737 end;
3739 -- Special restricted placement rule from 10.2.1(11.8/2)
3741 elsif Is_Generic_Formal (Ent)
3742 and then Prag_Id = Pragma_Preelaborable_Initialization
3743 then
3744 OK := List_Containing (N) =
3745 Generic_Formal_Declarations
3746 (Unit_Declaration_Node (Scop));
3748 -- If this is an aspect applied to a subprogram body, the
3749 -- pragma is inserted in its declarative part.
3751 elsif From_Aspect_Specification (N)
3752 and then Ent = Current_Scope
3753 and then
3754 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
3755 then
3756 OK := True;
3758 -- If the aspect is a predicate (possibly others ???) and the
3759 -- context is a record type, this is a discriminant expression
3760 -- within a type declaration, that freezes the predicated
3761 -- subtype.
3763 elsif From_Aspect_Specification (N)
3764 and then Prag_Id = Pragma_Predicate
3765 and then Ekind (Current_Scope) = E_Record_Type
3766 and then Scop = Scope (Current_Scope)
3767 then
3768 OK := True;
3770 -- Default case, just check that the pragma occurs in the scope
3771 -- of the entity denoted by the name.
3773 else
3774 OK := Current_Scope = Scop;
3775 end if;
3777 if not OK then
3778 Error_Pragma_Arg
3779 ("pragma% argument must be in same declarative part", Arg);
3780 end if;
3781 end;
3782 end if;
3783 end Check_Arg_Is_Local_Name;
3785 ---------------------------------
3786 -- Check_Arg_Is_Locking_Policy --
3787 ---------------------------------
3789 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
3790 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3792 begin
3793 Check_Arg_Is_Identifier (Argx);
3795 if not Is_Locking_Policy_Name (Chars (Argx)) then
3796 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
3797 end if;
3798 end Check_Arg_Is_Locking_Policy;
3800 -----------------------------------------------
3801 -- Check_Arg_Is_Partition_Elaboration_Policy --
3802 -----------------------------------------------
3804 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
3805 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3807 begin
3808 Check_Arg_Is_Identifier (Argx);
3810 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
3811 Error_Pragma_Arg
3812 ("& is not a valid partition elaboration policy name", Argx);
3813 end if;
3814 end Check_Arg_Is_Partition_Elaboration_Policy;
3816 -------------------------
3817 -- Check_Arg_Is_One_Of --
3818 -------------------------
3820 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
3821 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3823 begin
3824 Check_Arg_Is_Identifier (Argx);
3826 if not Nam_In (Chars (Argx), N1, N2) then
3827 Error_Msg_Name_2 := N1;
3828 Error_Msg_Name_3 := N2;
3829 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
3830 end if;
3831 end Check_Arg_Is_One_Of;
3833 procedure Check_Arg_Is_One_Of
3834 (Arg : Node_Id;
3835 N1, N2, N3 : Name_Id)
3837 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3839 begin
3840 Check_Arg_Is_Identifier (Argx);
3842 if not Nam_In (Chars (Argx), N1, N2, N3) then
3843 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3844 end if;
3845 end Check_Arg_Is_One_Of;
3847 procedure Check_Arg_Is_One_Of
3848 (Arg : Node_Id;
3849 N1, N2, N3, N4 : Name_Id)
3851 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3853 begin
3854 Check_Arg_Is_Identifier (Argx);
3856 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
3857 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3858 end if;
3859 end Check_Arg_Is_One_Of;
3861 procedure Check_Arg_Is_One_Of
3862 (Arg : Node_Id;
3863 N1, N2, N3, N4, N5 : Name_Id)
3865 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3867 begin
3868 Check_Arg_Is_Identifier (Argx);
3870 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
3871 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3872 end if;
3873 end Check_Arg_Is_One_Of;
3875 ---------------------------------
3876 -- Check_Arg_Is_Queuing_Policy --
3877 ---------------------------------
3879 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
3880 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3882 begin
3883 Check_Arg_Is_Identifier (Argx);
3885 if not Is_Queuing_Policy_Name (Chars (Argx)) then
3886 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
3887 end if;
3888 end Check_Arg_Is_Queuing_Policy;
3890 ---------------------------------------
3891 -- Check_Arg_Is_OK_Static_Expression --
3892 ---------------------------------------
3894 procedure Check_Arg_Is_OK_Static_Expression
3895 (Arg : Node_Id;
3896 Typ : Entity_Id := Empty)
3898 begin
3899 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
3900 end Check_Arg_Is_OK_Static_Expression;
3902 ------------------------------------------
3903 -- Check_Arg_Is_Task_Dispatching_Policy --
3904 ------------------------------------------
3906 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
3907 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3909 begin
3910 Check_Arg_Is_Identifier (Argx);
3912 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
3913 Error_Pragma_Arg
3914 ("& is not an allowed task dispatching policy name", Argx);
3915 end if;
3916 end Check_Arg_Is_Task_Dispatching_Policy;
3918 ---------------------
3919 -- Check_Arg_Order --
3920 ---------------------
3922 procedure Check_Arg_Order (Names : Name_List) is
3923 Arg : Node_Id;
3925 Highest_So_Far : Natural := 0;
3926 -- Highest index in Names seen do far
3928 begin
3929 Arg := Arg1;
3930 for J in 1 .. Arg_Count loop
3931 if Chars (Arg) /= No_Name then
3932 for K in Names'Range loop
3933 if Chars (Arg) = Names (K) then
3934 if K < Highest_So_Far then
3935 Error_Msg_Name_1 := Pname;
3936 Error_Msg_N
3937 ("parameters out of order for pragma%", Arg);
3938 Error_Msg_Name_1 := Names (K);
3939 Error_Msg_Name_2 := Names (Highest_So_Far);
3940 Error_Msg_N ("\% must appear before %", Arg);
3941 raise Pragma_Exit;
3943 else
3944 Highest_So_Far := K;
3945 end if;
3946 end if;
3947 end loop;
3948 end if;
3950 Arg := Next (Arg);
3951 end loop;
3952 end Check_Arg_Order;
3954 --------------------------------
3955 -- Check_At_Least_N_Arguments --
3956 --------------------------------
3958 procedure Check_At_Least_N_Arguments (N : Nat) is
3959 begin
3960 if Arg_Count < N then
3961 Error_Pragma ("too few arguments for pragma%");
3962 end if;
3963 end Check_At_Least_N_Arguments;
3965 -------------------------------
3966 -- Check_At_Most_N_Arguments --
3967 -------------------------------
3969 procedure Check_At_Most_N_Arguments (N : Nat) is
3970 Arg : Node_Id;
3971 begin
3972 if Arg_Count > N then
3973 Arg := Arg1;
3974 for J in 1 .. N loop
3975 Next (Arg);
3976 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
3977 end loop;
3978 end if;
3979 end Check_At_Most_N_Arguments;
3981 ---------------------
3982 -- Check_Component --
3983 ---------------------
3985 procedure Check_Component
3986 (Comp : Node_Id;
3987 UU_Typ : Entity_Id;
3988 In_Variant_Part : Boolean := False)
3990 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
3991 Sindic : constant Node_Id :=
3992 Subtype_Indication (Component_Definition (Comp));
3993 Typ : constant Entity_Id := Etype (Comp_Id);
3995 begin
3996 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
3997 -- object constraint, then the component type shall be an Unchecked_
3998 -- Union.
4000 if Nkind (Sindic) = N_Subtype_Indication
4001 and then Has_Per_Object_Constraint (Comp_Id)
4002 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
4003 then
4004 Error_Msg_N
4005 ("component subtype subject to per-object constraint "
4006 & "must be an Unchecked_Union", Comp);
4008 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
4009 -- the body of a generic unit, or within the body of any of its
4010 -- descendant library units, no part of the type of a component
4011 -- declared in a variant_part of the unchecked union type shall be of
4012 -- a formal private type or formal private extension declared within
4013 -- the formal part of the generic unit.
4015 elsif Ada_Version >= Ada_2012
4016 and then In_Generic_Body (UU_Typ)
4017 and then In_Variant_Part
4018 and then Is_Private_Type (Typ)
4019 and then Is_Generic_Type (Typ)
4020 then
4021 Error_Msg_N
4022 ("component of unchecked union cannot be of generic type", Comp);
4024 elsif Needs_Finalization (Typ) then
4025 Error_Msg_N
4026 ("component of unchecked union cannot be controlled", Comp);
4028 elsif Has_Task (Typ) then
4029 Error_Msg_N
4030 ("component of unchecked union cannot have tasks", Comp);
4031 end if;
4032 end Check_Component;
4034 -----------------------------
4035 -- Check_Declaration_Order --
4036 -----------------------------
4038 procedure Check_Declaration_Order (First : Node_Id; Second : Node_Id) is
4039 procedure Check_Aspect_Specification_Order;
4040 -- Inspect the aspect specifications of the context to determine the
4041 -- proper order.
4043 --------------------------------------
4044 -- Check_Aspect_Specification_Order --
4045 --------------------------------------
4047 procedure Check_Aspect_Specification_Order is
4048 Asp_First : constant Node_Id := Corresponding_Aspect (First);
4049 Asp_Second : constant Node_Id := Corresponding_Aspect (Second);
4050 Asp : Node_Id;
4052 begin
4053 -- Both aspects must be part of the same aspect specification list
4055 pragma Assert
4056 (List_Containing (Asp_First) = List_Containing (Asp_Second));
4058 -- Try to reach Second starting from First in a left to right
4059 -- traversal of the aspect specifications.
4061 Asp := Next (Asp_First);
4062 while Present (Asp) loop
4064 -- The order is ok, First is followed by Second
4066 if Asp = Asp_Second then
4067 return;
4068 end if;
4070 Next (Asp);
4071 end loop;
4073 -- If we get here, then the aspects are out of order
4075 SPARK_Msg_N ("aspect % cannot come after aspect %", First);
4076 end Check_Aspect_Specification_Order;
4078 -- Local variables
4080 Stmt : Node_Id;
4082 -- Start of processing for Check_Declaration_Order
4084 begin
4085 -- Cannot check the order if one of the pragmas is missing
4087 if No (First) or else No (Second) then
4088 return;
4089 end if;
4091 -- Set up the error names in case the order is incorrect
4093 Error_Msg_Name_1 := Pragma_Name (First);
4094 Error_Msg_Name_2 := Pragma_Name (Second);
4096 if From_Aspect_Specification (First) then
4098 -- Both pragmas are actually aspects, check their declaration
4099 -- order in the associated aspect specification list. Otherwise
4100 -- First is an aspect and Second a source pragma.
4102 if From_Aspect_Specification (Second) then
4103 Check_Aspect_Specification_Order;
4104 end if;
4106 -- Abstract_States is a source pragma
4108 else
4109 if From_Aspect_Specification (Second) then
4110 SPARK_Msg_N ("pragma % cannot come after aspect %", First);
4112 -- Both pragmas are source constructs. Try to reach First from
4113 -- Second by traversing the declarations backwards.
4115 else
4116 Stmt := Prev (Second);
4117 while Present (Stmt) loop
4119 -- The order is ok, First is followed by Second
4121 if Stmt = First then
4122 return;
4123 end if;
4125 Prev (Stmt);
4126 end loop;
4128 -- If we get here, then the pragmas are out of order
4130 SPARK_Msg_N ("pragma % cannot come after pragma %", First);
4131 end if;
4132 end if;
4133 end Check_Declaration_Order;
4135 ----------------------------
4136 -- Check_Duplicate_Pragma --
4137 ----------------------------
4139 procedure Check_Duplicate_Pragma (E : Entity_Id) is
4140 Id : Entity_Id := E;
4141 P : Node_Id;
4143 begin
4144 -- Nothing to do if this pragma comes from an aspect specification,
4145 -- since we could not be duplicating a pragma, and we dealt with the
4146 -- case of duplicated aspects in Analyze_Aspect_Specifications.
4148 if From_Aspect_Specification (N) then
4149 return;
4150 end if;
4152 -- Otherwise current pragma may duplicate previous pragma or a
4153 -- previously given aspect specification or attribute definition
4154 -- clause for the same pragma.
4156 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
4158 if Present (P) then
4160 -- If the entity is a type, then we have to make sure that the
4161 -- ostensible duplicate is not for a parent type from which this
4162 -- type is derived.
4164 if Is_Type (E) then
4165 if Nkind (P) = N_Pragma then
4166 declare
4167 Args : constant List_Id :=
4168 Pragma_Argument_Associations (P);
4169 begin
4170 if Present (Args)
4171 and then Is_Entity_Name (Expression (First (Args)))
4172 and then Is_Type (Entity (Expression (First (Args))))
4173 and then Entity (Expression (First (Args))) /= E
4174 then
4175 return;
4176 end if;
4177 end;
4179 elsif Nkind (P) = N_Aspect_Specification
4180 and then Is_Type (Entity (P))
4181 and then Entity (P) /= E
4182 then
4183 return;
4184 end if;
4185 end if;
4187 -- Here we have a definite duplicate
4189 Error_Msg_Name_1 := Pragma_Name (N);
4190 Error_Msg_Sloc := Sloc (P);
4192 -- For a single protected or a single task object, the error is
4193 -- issued on the original entity.
4195 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
4196 Id := Defining_Identifier (Original_Node (Parent (Id)));
4197 end if;
4199 if Nkind (P) = N_Aspect_Specification
4200 or else From_Aspect_Specification (P)
4201 then
4202 Error_Msg_NE ("aspect% for & previously given#", N, Id);
4203 else
4204 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
4205 end if;
4207 raise Pragma_Exit;
4208 end if;
4209 end Check_Duplicate_Pragma;
4211 ----------------------------------
4212 -- Check_Duplicated_Export_Name --
4213 ----------------------------------
4215 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
4216 String_Val : constant String_Id := Strval (Nam);
4218 begin
4219 -- We are only interested in the export case, and in the case of
4220 -- generics, it is the instance, not the template, that is the
4221 -- problem (the template will generate a warning in any case).
4223 if not Inside_A_Generic
4224 and then (Prag_Id = Pragma_Export
4225 or else
4226 Prag_Id = Pragma_Export_Procedure
4227 or else
4228 Prag_Id = Pragma_Export_Valued_Procedure
4229 or else
4230 Prag_Id = Pragma_Export_Function)
4231 then
4232 for J in Externals.First .. Externals.Last loop
4233 if String_Equal (String_Val, Strval (Externals.Table (J))) then
4234 Error_Msg_Sloc := Sloc (Externals.Table (J));
4235 Error_Msg_N ("external name duplicates name given#", Nam);
4236 exit;
4237 end if;
4238 end loop;
4240 Externals.Append (Nam);
4241 end if;
4242 end Check_Duplicated_Export_Name;
4244 ----------------------------------------
4245 -- Check_Expr_Is_OK_Static_Expression --
4246 ----------------------------------------
4248 procedure Check_Expr_Is_OK_Static_Expression
4249 (Expr : Node_Id;
4250 Typ : Entity_Id := Empty)
4252 begin
4253 if Present (Typ) then
4254 Analyze_And_Resolve (Expr, Typ);
4255 else
4256 Analyze_And_Resolve (Expr);
4257 end if;
4259 if Is_OK_Static_Expression (Expr) then
4260 return;
4262 elsif Etype (Expr) = Any_Type then
4263 raise Pragma_Exit;
4265 -- An interesting special case, if we have a string literal and we
4266 -- are in Ada 83 mode, then we allow it even though it will not be
4267 -- flagged as static. This allows the use of Ada 95 pragmas like
4268 -- Import in Ada 83 mode. They will of course be flagged with
4269 -- warnings as usual, but will not cause errors.
4271 elsif Ada_Version = Ada_83
4272 and then Nkind (Expr) = N_String_Literal
4273 then
4274 return;
4276 -- Static expression that raises Constraint_Error. This has already
4277 -- been flagged, so just exit from pragma processing.
4279 elsif Is_OK_Static_Expression (Expr) then
4280 raise Pragma_Exit;
4282 -- Finally, we have a real error
4284 else
4285 Error_Msg_Name_1 := Pname;
4286 Flag_Non_Static_Expr
4287 (Fix_Error ("argument for pragma% must be a static expression!"),
4288 Expr);
4289 raise Pragma_Exit;
4290 end if;
4291 end Check_Expr_Is_OK_Static_Expression;
4293 -------------------------
4294 -- Check_First_Subtype --
4295 -------------------------
4297 procedure Check_First_Subtype (Arg : Node_Id) is
4298 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4299 Ent : constant Entity_Id := Entity (Argx);
4301 begin
4302 if Is_First_Subtype (Ent) then
4303 null;
4305 elsif Is_Type (Ent) then
4306 Error_Pragma_Arg
4307 ("pragma% cannot apply to subtype", Argx);
4309 elsif Is_Object (Ent) then
4310 Error_Pragma_Arg
4311 ("pragma% cannot apply to object, requires a type", Argx);
4313 else
4314 Error_Pragma_Arg
4315 ("pragma% cannot apply to&, requires a type", Argx);
4316 end if;
4317 end Check_First_Subtype;
4319 ----------------------
4320 -- Check_Identifier --
4321 ----------------------
4323 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
4324 begin
4325 if Present (Arg)
4326 and then Nkind (Arg) = N_Pragma_Argument_Association
4327 then
4328 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
4329 Error_Msg_Name_1 := Pname;
4330 Error_Msg_Name_2 := Id;
4331 Error_Msg_N ("pragma% argument expects identifier%", Arg);
4332 raise Pragma_Exit;
4333 end if;
4334 end if;
4335 end Check_Identifier;
4337 --------------------------------
4338 -- Check_Identifier_Is_One_Of --
4339 --------------------------------
4341 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
4342 begin
4343 if Present (Arg)
4344 and then Nkind (Arg) = N_Pragma_Argument_Association
4345 then
4346 if Chars (Arg) = No_Name then
4347 Error_Msg_Name_1 := Pname;
4348 Error_Msg_N ("pragma% argument expects an identifier", Arg);
4349 raise Pragma_Exit;
4351 elsif Chars (Arg) /= N1
4352 and then Chars (Arg) /= N2
4353 then
4354 Error_Msg_Name_1 := Pname;
4355 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
4356 raise Pragma_Exit;
4357 end if;
4358 end if;
4359 end Check_Identifier_Is_One_Of;
4361 ---------------------------
4362 -- Check_In_Main_Program --
4363 ---------------------------
4365 procedure Check_In_Main_Program is
4366 P : constant Node_Id := Parent (N);
4368 begin
4369 -- Must be at in subprogram body
4371 if Nkind (P) /= N_Subprogram_Body then
4372 Error_Pragma ("% pragma allowed only in subprogram");
4374 -- Otherwise warn if obviously not main program
4376 elsif Present (Parameter_Specifications (Specification (P)))
4377 or else not Is_Compilation_Unit (Defining_Entity (P))
4378 then
4379 Error_Msg_Name_1 := Pname;
4380 Error_Msg_N
4381 ("??pragma% is only effective in main program", N);
4382 end if;
4383 end Check_In_Main_Program;
4385 ---------------------------------------
4386 -- Check_Interrupt_Or_Attach_Handler --
4387 ---------------------------------------
4389 procedure Check_Interrupt_Or_Attach_Handler is
4390 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4391 Handler_Proc, Proc_Scope : Entity_Id;
4393 begin
4394 Analyze (Arg1_X);
4396 if Prag_Id = Pragma_Interrupt_Handler then
4397 Check_Restriction (No_Dynamic_Attachment, N);
4398 end if;
4400 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
4401 Proc_Scope := Scope (Handler_Proc);
4403 -- On AAMP only, a pragma Interrupt_Handler is supported for
4404 -- nonprotected parameterless procedures.
4406 if not AAMP_On_Target
4407 or else Prag_Id = Pragma_Attach_Handler
4408 then
4409 if Ekind (Proc_Scope) /= E_Protected_Type then
4410 Error_Pragma_Arg
4411 ("argument of pragma% must be protected procedure", Arg1);
4412 end if;
4414 -- For pragma case (as opposed to access case), check placement.
4415 -- We don't need to do that for aspects, because we have the
4416 -- check that they aspect applies an appropriate procedure.
4418 if not From_Aspect_Specification (N)
4419 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
4420 then
4421 Error_Pragma ("pragma% must be in protected definition");
4422 end if;
4423 end if;
4425 if not Is_Library_Level_Entity (Proc_Scope)
4426 or else (AAMP_On_Target
4427 and then not Is_Library_Level_Entity (Handler_Proc))
4428 then
4429 Error_Pragma_Arg
4430 ("argument for pragma% must be library level entity", Arg1);
4431 end if;
4433 -- AI05-0033: A pragma cannot appear within a generic body, because
4434 -- instance can be in a nested scope. The check that protected type
4435 -- is itself a library-level declaration is done elsewhere.
4437 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
4438 -- handle code prior to AI-0033. Analysis tools typically are not
4439 -- interested in this pragma in any case, so no need to worry too
4440 -- much about its placement.
4442 if Inside_A_Generic then
4443 if Ekind (Scope (Current_Scope)) = E_Generic_Package
4444 and then In_Package_Body (Scope (Current_Scope))
4445 and then not Relaxed_RM_Semantics
4446 then
4447 Error_Pragma ("pragma% cannot be used inside a generic");
4448 end if;
4449 end if;
4450 end Check_Interrupt_Or_Attach_Handler;
4452 ---------------------------------
4453 -- Check_Loop_Pragma_Placement --
4454 ---------------------------------
4456 procedure Check_Loop_Pragma_Placement is
4457 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
4458 -- Verify whether the current pragma is properly grouped with other
4459 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
4460 -- related loop where the pragma appears.
4462 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
4463 -- Determine whether an arbitrary statement Stmt denotes pragma
4464 -- Loop_Invariant or Loop_Variant.
4466 procedure Placement_Error (Constr : Node_Id);
4467 pragma No_Return (Placement_Error);
4468 -- Node Constr denotes the last loop restricted construct before we
4469 -- encountered an illegal relation between enclosing constructs. Emit
4470 -- an error depending on what Constr was.
4472 --------------------------------
4473 -- Check_Loop_Pragma_Grouping --
4474 --------------------------------
4476 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
4477 Stop_Search : exception;
4478 -- This exception is used to terminate the recursive descent of
4479 -- routine Check_Grouping.
4481 procedure Check_Grouping (L : List_Id);
4482 -- Find the first group of pragmas in list L and if successful,
4483 -- ensure that the current pragma is part of that group. The
4484 -- routine raises Stop_Search once such a check is performed to
4485 -- halt the recursive descent.
4487 procedure Grouping_Error (Prag : Node_Id);
4488 pragma No_Return (Grouping_Error);
4489 -- Emit an error concerning the current pragma indicating that it
4490 -- should be placed after pragma Prag.
4492 --------------------
4493 -- Check_Grouping --
4494 --------------------
4496 procedure Check_Grouping (L : List_Id) is
4497 HSS : Node_Id;
4498 Prag : Node_Id;
4499 Stmt : Node_Id;
4501 begin
4502 -- Inspect the list of declarations or statements looking for
4503 -- the first grouping of pragmas:
4505 -- loop
4506 -- pragma Loop_Invariant ...;
4507 -- pragma Loop_Variant ...;
4508 -- . . . -- (1)
4509 -- pragma Loop_Variant ...; -- current pragma
4511 -- If the current pragma is not in the grouping, then it must
4512 -- either appear in a different declarative or statement list
4513 -- or the construct at (1) is separating the pragma from the
4514 -- grouping.
4516 Stmt := First (L);
4517 while Present (Stmt) loop
4519 -- Pragmas Loop_Invariant and Loop_Variant may only appear
4520 -- inside a loop or a block housed inside a loop. Inspect
4521 -- the declarations and statements of the block as they may
4522 -- contain the first grouping.
4524 if Nkind (Stmt) = N_Block_Statement then
4525 HSS := Handled_Statement_Sequence (Stmt);
4527 Check_Grouping (Declarations (Stmt));
4529 if Present (HSS) then
4530 Check_Grouping (Statements (HSS));
4531 end if;
4533 -- First pragma of the first topmost grouping has been found
4535 elsif Is_Loop_Pragma (Stmt) then
4537 -- The group and the current pragma are not in the same
4538 -- declarative or statement list.
4540 if List_Containing (Stmt) /= List_Containing (N) then
4541 Grouping_Error (Stmt);
4543 -- Try to reach the current pragma from the first pragma
4544 -- of the grouping while skipping other members:
4546 -- pragma Loop_Invariant ...; -- first pragma
4547 -- pragma Loop_Variant ...; -- member
4548 -- . . .
4549 -- pragma Loop_Variant ...; -- current pragma
4551 else
4552 while Present (Stmt) loop
4554 -- The current pragma is either the first pragma
4555 -- of the group or is a member of the group. Stop
4556 -- the search as the placement is legal.
4558 if Stmt = N then
4559 raise Stop_Search;
4561 -- Skip group members, but keep track of the last
4562 -- pragma in the group.
4564 elsif Is_Loop_Pragma (Stmt) then
4565 Prag := Stmt;
4567 -- A non-pragma is separating the group from the
4568 -- current pragma, the placement is illegal.
4570 else
4571 Grouping_Error (Prag);
4572 end if;
4574 Next (Stmt);
4575 end loop;
4577 -- If the traversal did not reach the current pragma,
4578 -- then the list must be malformed.
4580 raise Program_Error;
4581 end if;
4582 end if;
4584 Next (Stmt);
4585 end loop;
4586 end Check_Grouping;
4588 --------------------
4589 -- Grouping_Error --
4590 --------------------
4592 procedure Grouping_Error (Prag : Node_Id) is
4593 begin
4594 Error_Msg_Sloc := Sloc (Prag);
4595 Error_Pragma ("pragma% must appear next to pragma#");
4596 end Grouping_Error;
4598 -- Start of processing for Check_Loop_Pragma_Grouping
4600 begin
4601 -- Inspect the statements of the loop or nested blocks housed
4602 -- within to determine whether the current pragma is part of the
4603 -- first topmost grouping of Loop_Invariant and Loop_Variant.
4605 Check_Grouping (Statements (Loop_Stmt));
4607 exception
4608 when Stop_Search => null;
4609 end Check_Loop_Pragma_Grouping;
4611 --------------------
4612 -- Is_Loop_Pragma --
4613 --------------------
4615 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
4616 begin
4617 -- Inspect the original node as Loop_Invariant and Loop_Variant
4618 -- pragmas are rewritten to null when assertions are disabled.
4620 if Nkind (Original_Node (Stmt)) = N_Pragma then
4621 return
4622 Nam_In (Pragma_Name (Original_Node (Stmt)),
4623 Name_Loop_Invariant,
4624 Name_Loop_Variant);
4625 else
4626 return False;
4627 end if;
4628 end Is_Loop_Pragma;
4630 ---------------------
4631 -- Placement_Error --
4632 ---------------------
4634 procedure Placement_Error (Constr : Node_Id) is
4635 LA : constant String := " with Loop_Entry";
4637 begin
4638 if Prag_Id = Pragma_Assert then
4639 Error_Msg_String (1 .. LA'Length) := LA;
4640 Error_Msg_Strlen := LA'Length;
4641 else
4642 Error_Msg_Strlen := 0;
4643 end if;
4645 if Nkind (Constr) = N_Pragma then
4646 Error_Pragma
4647 ("pragma %~ must appear immediately within the statements "
4648 & "of a loop");
4649 else
4650 Error_Pragma_Arg
4651 ("block containing pragma %~ must appear immediately within "
4652 & "the statements of a loop", Constr);
4653 end if;
4654 end Placement_Error;
4656 -- Local declarations
4658 Prev : Node_Id;
4659 Stmt : Node_Id;
4661 -- Start of processing for Check_Loop_Pragma_Placement
4663 begin
4664 -- Check that pragma appears immediately within a loop statement,
4665 -- ignoring intervening block statements.
4667 Prev := N;
4668 Stmt := Parent (N);
4669 while Present (Stmt) loop
4671 -- The pragma or previous block must appear immediately within the
4672 -- current block's declarative or statement part.
4674 if Nkind (Stmt) = N_Block_Statement then
4675 if (No (Declarations (Stmt))
4676 or else List_Containing (Prev) /= Declarations (Stmt))
4677 and then
4678 List_Containing (Prev) /=
4679 Statements (Handled_Statement_Sequence (Stmt))
4680 then
4681 Placement_Error (Prev);
4682 return;
4684 -- Keep inspecting the parents because we are now within a
4685 -- chain of nested blocks.
4687 else
4688 Prev := Stmt;
4689 Stmt := Parent (Stmt);
4690 end if;
4692 -- The pragma or previous block must appear immediately within the
4693 -- statements of the loop.
4695 elsif Nkind (Stmt) = N_Loop_Statement then
4696 if List_Containing (Prev) /= Statements (Stmt) then
4697 Placement_Error (Prev);
4698 end if;
4700 -- Stop the traversal because we reached the innermost loop
4701 -- regardless of whether we encountered an error or not.
4703 exit;
4705 -- Ignore a handled statement sequence. Note that this node may
4706 -- be related to a subprogram body in which case we will emit an
4707 -- error on the next iteration of the search.
4709 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
4710 Stmt := Parent (Stmt);
4712 -- Any other statement breaks the chain from the pragma to the
4713 -- loop.
4715 else
4716 Placement_Error (Prev);
4717 return;
4718 end if;
4719 end loop;
4721 -- Check that the current pragma Loop_Invariant or Loop_Variant is
4722 -- grouped together with other such pragmas.
4724 if Is_Loop_Pragma (N) then
4726 -- The previous check should have located the related loop
4728 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
4729 Check_Loop_Pragma_Grouping (Stmt);
4730 end if;
4731 end Check_Loop_Pragma_Placement;
4733 -------------------------------------------
4734 -- Check_Is_In_Decl_Part_Or_Package_Spec --
4735 -------------------------------------------
4737 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
4738 P : Node_Id;
4740 begin
4741 P := Parent (N);
4742 loop
4743 if No (P) then
4744 exit;
4746 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
4747 exit;
4749 elsif Nkind_In (P, N_Package_Specification,
4750 N_Block_Statement)
4751 then
4752 return;
4754 -- Note: the following tests seem a little peculiar, because
4755 -- they test for bodies, but if we were in the statement part
4756 -- of the body, we would already have hit the handled statement
4757 -- sequence, so the only way we get here is by being in the
4758 -- declarative part of the body.
4760 elsif Nkind_In (P, N_Subprogram_Body,
4761 N_Package_Body,
4762 N_Task_Body,
4763 N_Entry_Body)
4764 then
4765 return;
4766 end if;
4768 P := Parent (P);
4769 end loop;
4771 Error_Pragma ("pragma% is not in declarative part or package spec");
4772 end Check_Is_In_Decl_Part_Or_Package_Spec;
4774 -------------------------
4775 -- Check_No_Identifier --
4776 -------------------------
4778 procedure Check_No_Identifier (Arg : Node_Id) is
4779 begin
4780 if Nkind (Arg) = N_Pragma_Argument_Association
4781 and then Chars (Arg) /= No_Name
4782 then
4783 Error_Pragma_Arg_Ident
4784 ("pragma% does not permit identifier& here", Arg);
4785 end if;
4786 end Check_No_Identifier;
4788 --------------------------
4789 -- Check_No_Identifiers --
4790 --------------------------
4792 procedure Check_No_Identifiers is
4793 Arg_Node : Node_Id;
4794 begin
4795 Arg_Node := Arg1;
4796 for J in 1 .. Arg_Count loop
4797 Check_No_Identifier (Arg_Node);
4798 Next (Arg_Node);
4799 end loop;
4800 end Check_No_Identifiers;
4802 ------------------------
4803 -- Check_No_Link_Name --
4804 ------------------------
4806 procedure Check_No_Link_Name is
4807 begin
4808 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
4809 Arg4 := Arg3;
4810 end if;
4812 if Present (Arg4) then
4813 Error_Pragma_Arg
4814 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
4815 end if;
4816 end Check_No_Link_Name;
4818 -------------------------------
4819 -- Check_Optional_Identifier --
4820 -------------------------------
4822 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
4823 begin
4824 if Present (Arg)
4825 and then Nkind (Arg) = N_Pragma_Argument_Association
4826 and then Chars (Arg) /= No_Name
4827 then
4828 if Chars (Arg) /= Id then
4829 Error_Msg_Name_1 := Pname;
4830 Error_Msg_Name_2 := Id;
4831 Error_Msg_N ("pragma% argument expects identifier%", Arg);
4832 raise Pragma_Exit;
4833 end if;
4834 end if;
4835 end Check_Optional_Identifier;
4837 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
4838 begin
4839 Name_Buffer (1 .. Id'Length) := Id;
4840 Name_Len := Id'Length;
4841 Check_Optional_Identifier (Arg, Name_Find);
4842 end Check_Optional_Identifier;
4844 --------------------
4845 -- Check_Pre_Post --
4846 --------------------
4848 procedure Check_Pre_Post is
4849 P : Node_Id;
4850 PO : Node_Id;
4852 begin
4853 if not Is_List_Member (N) then
4854 Pragma_Misplaced;
4855 end if;
4857 -- If we are within an inlined body, the legality of the pragma
4858 -- has been checked already.
4860 if In_Inlined_Body then
4861 return;
4862 end if;
4864 -- Search prior declarations
4866 P := N;
4867 while Present (Prev (P)) loop
4868 P := Prev (P);
4870 -- If the previous node is a generic subprogram, do not go to to
4871 -- the original node, which is the unanalyzed tree: we need to
4872 -- attach the pre/postconditions to the analyzed version at this
4873 -- point. They get propagated to the original tree when analyzing
4874 -- the corresponding body.
4876 if Nkind (P) not in N_Generic_Declaration then
4877 PO := Original_Node (P);
4878 else
4879 PO := P;
4880 end if;
4882 -- Skip past prior pragma
4884 if Nkind (PO) = N_Pragma then
4885 null;
4887 -- Skip stuff not coming from source
4889 elsif not Comes_From_Source (PO) then
4891 -- The condition may apply to a subprogram instantiation
4893 if Nkind (PO) = N_Subprogram_Declaration
4894 and then Present (Generic_Parent (Specification (PO)))
4895 then
4896 return;
4898 elsif Nkind (PO) = N_Subprogram_Declaration
4899 and then In_Instance
4900 then
4901 return;
4903 -- For all other cases of non source code, do nothing
4905 else
4906 null;
4907 end if;
4909 -- Only remaining possibility is subprogram declaration
4911 else
4912 return;
4913 end if;
4914 end loop;
4916 -- If we fall through loop, pragma is at start of list, so see if it
4917 -- is at the start of declarations of a subprogram body.
4919 PO := Parent (N);
4921 if Nkind (PO) = N_Subprogram_Body
4922 and then List_Containing (N) = Declarations (PO)
4923 then
4924 -- This is only allowed if there is no separate specification
4926 if Present (Corresponding_Spec (PO)) then
4927 Error_Pragma
4928 ("pragma% must apply to subprogram specification");
4929 end if;
4931 return;
4932 end if;
4933 end Check_Pre_Post;
4935 --------------------------------------
4936 -- Check_Precondition_Postcondition --
4937 --------------------------------------
4939 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
4940 P : Node_Id;
4941 PO : Node_Id;
4943 procedure Chain_PPC (PO : Node_Id);
4944 -- If PO is an entry or a [generic] subprogram declaration node, then
4945 -- the precondition/postcondition applies to this subprogram and the
4946 -- processing for the pragma is completed. Otherwise the pragma is
4947 -- misplaced.
4949 ---------------
4950 -- Chain_PPC --
4951 ---------------
4953 procedure Chain_PPC (PO : Node_Id) is
4954 S : Entity_Id;
4956 begin
4957 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
4958 if not From_Aspect_Specification (N) then
4959 Error_Pragma
4960 ("pragma% cannot be applied to abstract subprogram");
4962 elsif Class_Present (N) then
4963 null;
4965 else
4966 Error_Pragma
4967 ("aspect % requires ''Class for abstract subprogram");
4968 end if;
4970 -- AI05-0230: The same restriction applies to null procedures. For
4971 -- compatibility with earlier uses of the Ada pragma, apply this
4972 -- rule only to aspect specifications.
4974 -- The above discrepency needs documentation. Robert is dubious
4975 -- about whether it is a good idea ???
4977 elsif Nkind (PO) = N_Subprogram_Declaration
4978 and then Nkind (Specification (PO)) = N_Procedure_Specification
4979 and then Null_Present (Specification (PO))
4980 and then From_Aspect_Specification (N)
4981 and then not Class_Present (N)
4982 then
4983 Error_Pragma
4984 ("aspect % requires ''Class for null procedure");
4986 -- Pre/postconditions are legal on a subprogram body if it is not
4987 -- a completion of a declaration. They are also legal on a stub
4988 -- with no previous declarations (this is checked when processing
4989 -- the corresponding aspects).
4991 elsif Nkind (PO) = N_Subprogram_Body
4992 and then Acts_As_Spec (PO)
4993 then
4994 null;
4996 elsif Nkind (PO) = N_Subprogram_Body_Stub then
4997 null;
4999 elsif not Nkind_In (PO, N_Subprogram_Declaration,
5000 N_Expression_Function,
5001 N_Generic_Subprogram_Declaration,
5002 N_Entry_Declaration)
5003 then
5004 Pragma_Misplaced;
5005 end if;
5007 -- Here if we have [generic] subprogram or entry declaration
5009 if Nkind (PO) = N_Entry_Declaration then
5010 S := Defining_Entity (PO);
5011 else
5012 S := Defining_Unit_Name (Specification (PO));
5014 if Nkind (S) = N_Defining_Program_Unit_Name then
5015 S := Defining_Identifier (S);
5016 end if;
5017 end if;
5019 -- Note: we do not analyze the pragma at this point. Instead we
5020 -- delay this analysis until the end of the declarative part in
5021 -- which the pragma appears. This implements the required delay
5022 -- in this analysis, allowing forward references. The analysis
5023 -- happens at the end of Analyze_Declarations.
5025 -- Chain spec PPC pragma to list for subprogram
5027 Add_Contract_Item (N, S);
5029 -- Return indicating spec case
5031 In_Body := False;
5032 return;
5033 end Chain_PPC;
5035 -- Start of processing for Check_Precondition_Postcondition
5037 begin
5038 if not Is_List_Member (N) then
5039 Pragma_Misplaced;
5040 end if;
5042 -- Preanalyze message argument if present. Visibility in this
5043 -- argument is established at the point of pragma occurrence.
5045 if Arg_Count = 2 then
5046 Check_Optional_Identifier (Arg2, Name_Message);
5047 Preanalyze_Spec_Expression
5048 (Get_Pragma_Arg (Arg2), Standard_String);
5049 end if;
5051 -- For a pragma PPC in the extended main source unit, record enabled
5052 -- status in SCO.
5054 if Is_Checked (N) and then not Split_PPC (N) then
5055 Set_SCO_Pragma_Enabled (Loc);
5056 end if;
5058 -- If we are within an inlined body, the legality of the pragma
5059 -- has been checked already.
5061 if In_Inlined_Body then
5062 In_Body := True;
5063 return;
5064 end if;
5066 -- Search prior declarations
5068 P := N;
5069 while Present (Prev (P)) loop
5070 P := Prev (P);
5072 -- If the previous node is a generic subprogram, do not go to to
5073 -- the original node, which is the unanalyzed tree: we need to
5074 -- attach the pre/postconditions to the analyzed version at this
5075 -- point. They get propagated to the original tree when analyzing
5076 -- the corresponding body.
5078 if Nkind (P) not in N_Generic_Declaration then
5079 PO := Original_Node (P);
5080 else
5081 PO := P;
5082 end if;
5084 -- Skip past prior pragma
5086 if Nkind (PO) = N_Pragma then
5087 null;
5089 -- Skip stuff not coming from source
5091 elsif not Comes_From_Source (PO) then
5093 -- The condition may apply to a subprogram instantiation
5095 if Nkind (PO) = N_Subprogram_Declaration
5096 and then Present (Generic_Parent (Specification (PO)))
5097 then
5098 Chain_PPC (PO);
5099 return;
5101 elsif Nkind (PO) = N_Subprogram_Declaration
5102 and then In_Instance
5103 then
5104 Chain_PPC (PO);
5105 return;
5107 -- For all other cases of non source code, do nothing
5109 else
5110 null;
5111 end if;
5113 -- Only remaining possibility is subprogram declaration
5115 else
5116 Chain_PPC (PO);
5117 return;
5118 end if;
5119 end loop;
5121 -- If we fall through loop, pragma is at start of list, so see if it
5122 -- is at the start of declarations of a subprogram body.
5124 PO := Parent (N);
5126 if Nkind (PO) = N_Subprogram_Body
5127 and then List_Containing (N) = Declarations (PO)
5128 then
5129 if Operating_Mode /= Generate_Code or else Inside_A_Generic then
5131 -- Analyze pragma expression for correctness and for ASIS use
5133 Preanalyze_Assert_Expression
5134 (Get_Pragma_Arg (Arg1), Standard_Boolean);
5136 -- In ASIS mode, for a pragma generated from a source aspect,
5137 -- also analyze the original aspect expression.
5139 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
5140 Preanalyze_Assert_Expression
5141 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
5142 end if;
5143 end if;
5145 -- Retain copy of the pre/postcondition pragma in GNATprove mode.
5146 -- The copy is needed because the pragma is expanded into other
5147 -- constructs which are not acceptable in the N_Contract node.
5149 if Acts_As_Spec (PO) and then GNATprove_Mode then
5150 declare
5151 Prag : constant Node_Id := New_Copy_Tree (N);
5153 begin
5154 -- Preanalyze the pragma
5156 Preanalyze_Assert_Expression
5157 (Get_Pragma_Arg
5158 (First (Pragma_Argument_Associations (Prag))),
5159 Standard_Boolean);
5161 -- Preanalyze the corresponding aspect (if any)
5163 if Present (Corresponding_Aspect (Prag)) then
5164 Preanalyze_Assert_Expression
5165 (Expression (Corresponding_Aspect (Prag)),
5166 Standard_Boolean);
5167 end if;
5169 -- Chain the copy on the contract of the body
5171 Add_Contract_Item
5172 (Prag, Defining_Unit_Name (Specification (PO)));
5173 end;
5174 end if;
5176 In_Body := True;
5177 return;
5179 -- See if it is in the pragmas after a library level subprogram
5181 elsif Nkind (PO) = N_Compilation_Unit_Aux then
5183 -- In GNATprove mode, analyze pragma expression for correctness,
5184 -- as it is not expanded later. Ditto in ASIS_Mode where there is
5185 -- no later point at which the aspect will be analyzed.
5187 if GNATprove_Mode or ASIS_Mode then
5188 Analyze_Pre_Post_Condition_In_Decl_Part
5189 (N, Defining_Entity (Unit (Parent (PO))));
5190 end if;
5192 Chain_PPC (Unit (Parent (PO)));
5193 return;
5194 end if;
5196 -- If we fall through, pragma was misplaced
5198 Pragma_Misplaced;
5199 end Check_Precondition_Postcondition;
5201 -----------------------------
5202 -- Check_Static_Constraint --
5203 -----------------------------
5205 -- Note: for convenience in writing this procedure, in addition to
5206 -- the officially (i.e. by spec) allowed argument which is always a
5207 -- constraint, it also allows ranges and discriminant associations.
5208 -- Above is not clear ???
5210 procedure Check_Static_Constraint (Constr : Node_Id) is
5212 procedure Require_Static (E : Node_Id);
5213 -- Require given expression to be static expression
5215 --------------------
5216 -- Require_Static --
5217 --------------------
5219 procedure Require_Static (E : Node_Id) is
5220 begin
5221 if not Is_OK_Static_Expression (E) then
5222 Flag_Non_Static_Expr
5223 ("non-static constraint not allowed in Unchecked_Union!", E);
5224 raise Pragma_Exit;
5225 end if;
5226 end Require_Static;
5228 -- Start of processing for Check_Static_Constraint
5230 begin
5231 case Nkind (Constr) is
5232 when N_Discriminant_Association =>
5233 Require_Static (Expression (Constr));
5235 when N_Range =>
5236 Require_Static (Low_Bound (Constr));
5237 Require_Static (High_Bound (Constr));
5239 when N_Attribute_Reference =>
5240 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
5241 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
5243 when N_Range_Constraint =>
5244 Check_Static_Constraint (Range_Expression (Constr));
5246 when N_Index_Or_Discriminant_Constraint =>
5247 declare
5248 IDC : Entity_Id;
5249 begin
5250 IDC := First (Constraints (Constr));
5251 while Present (IDC) loop
5252 Check_Static_Constraint (IDC);
5253 Next (IDC);
5254 end loop;
5255 end;
5257 when others =>
5258 null;
5259 end case;
5260 end Check_Static_Constraint;
5262 ---------------------
5263 -- Check_Test_Case --
5264 ---------------------
5266 procedure Check_Test_Case is
5267 P : Node_Id;
5268 PO : Node_Id;
5270 procedure Chain_CTC (PO : Node_Id);
5271 -- If PO is a [generic] subprogram declaration node, then the
5272 -- test-case applies to this subprogram and the processing for
5273 -- the pragma is completed. Otherwise the pragma is misplaced.
5275 ---------------
5276 -- Chain_CTC --
5277 ---------------
5279 procedure Chain_CTC (PO : Node_Id) is
5280 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
5281 CTC : Node_Id;
5282 S : Entity_Id;
5284 begin
5285 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
5286 Error_Pragma
5287 ("pragma% cannot be applied to abstract subprogram");
5289 elsif Nkind (PO) = N_Entry_Declaration then
5290 Error_Pragma ("pragma% cannot be applied to entry");
5292 elsif not Nkind_In (PO, N_Subprogram_Declaration,
5293 N_Generic_Subprogram_Declaration)
5294 then
5295 Pragma_Misplaced;
5296 end if;
5298 -- Here if we have [generic] subprogram declaration
5300 S := Defining_Unit_Name (Specification (PO));
5302 -- Note: we do not analyze the pragma at this point. Instead we
5303 -- delay this analysis until the end of the declarative part in
5304 -- which the pragma appears. This implements the required delay
5305 -- in this analysis, allowing forward references. The analysis
5306 -- happens at the end of Analyze_Declarations.
5308 -- There should not be another test-case with the same name
5309 -- associated to this subprogram.
5311 CTC := Contract_Test_Cases (Contract (S));
5312 while Present (CTC) loop
5314 -- Omit pragma Contract_Cases because it does not introduce
5315 -- a unique case name and it does not follow the syntax of
5316 -- Test_Case.
5318 if Pragma_Name (CTC) = Name_Contract_Cases then
5319 null;
5321 elsif String_Equal (Name, Get_Name_From_CTC_Pragma (CTC)) then
5322 Error_Msg_Sloc := Sloc (CTC);
5323 Error_Pragma ("name for pragma% is already used#");
5324 end if;
5326 CTC := Next_Pragma (CTC);
5327 end loop;
5329 -- Chain spec CTC pragma to list for subprogram
5331 Add_Contract_Item (N, S);
5332 end Chain_CTC;
5334 -- Start of processing for Check_Test_Case
5336 begin
5337 -- First check pragma arguments
5339 Check_At_Least_N_Arguments (2);
5340 Check_At_Most_N_Arguments (4);
5341 Check_Arg_Order
5342 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
5344 Check_Optional_Identifier (Arg1, Name_Name);
5345 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
5347 -- In ASIS mode, for a pragma generated from a source aspect, also
5348 -- analyze the original aspect expression.
5350 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
5351 Check_Expr_Is_OK_Static_Expression
5352 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
5353 end if;
5355 Check_Optional_Identifier (Arg2, Name_Mode);
5356 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
5358 if Arg_Count = 4 then
5359 Check_Identifier (Arg3, Name_Requires);
5360 Check_Identifier (Arg4, Name_Ensures);
5362 elsif Arg_Count = 3 then
5363 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
5364 end if;
5366 -- Check pragma placement
5368 if not Is_List_Member (N) then
5369 Pragma_Misplaced;
5370 end if;
5372 -- Test-case should only appear in package spec unit
5374 if Get_Source_Unit (N) = No_Unit
5375 or else not Nkind_In (Sinfo.Unit (Cunit (Current_Sem_Unit)),
5376 N_Package_Declaration,
5377 N_Generic_Package_Declaration)
5378 then
5379 Pragma_Misplaced;
5380 end if;
5382 -- Search prior declarations
5384 P := N;
5385 while Present (Prev (P)) loop
5386 P := Prev (P);
5388 -- If the previous node is a generic subprogram, do not go to to
5389 -- the original node, which is the unanalyzed tree: we need to
5390 -- attach the test-case to the analyzed version at this point.
5391 -- They get propagated to the original tree when analyzing the
5392 -- corresponding body.
5394 if Nkind (P) not in N_Generic_Declaration then
5395 PO := Original_Node (P);
5396 else
5397 PO := P;
5398 end if;
5400 -- Skip past prior pragma
5402 if Nkind (PO) = N_Pragma then
5403 null;
5405 -- Skip stuff not coming from source
5407 elsif not Comes_From_Source (PO) then
5408 null;
5410 -- Only remaining possibility is subprogram declaration. First
5411 -- check that it is declared directly in a package declaration.
5412 -- This may be either the package declaration for the current unit
5413 -- being defined or a local package declaration.
5415 elsif not Present (Parent (Parent (PO)))
5416 or else not Present (Parent (Parent (Parent (PO))))
5417 or else not Nkind_In (Parent (Parent (PO)),
5418 N_Package_Declaration,
5419 N_Generic_Package_Declaration)
5420 then
5421 Pragma_Misplaced;
5423 else
5424 Chain_CTC (PO);
5425 return;
5426 end if;
5427 end loop;
5429 -- If we fall through, pragma was misplaced
5431 Pragma_Misplaced;
5432 end Check_Test_Case;
5434 --------------------------------------
5435 -- Check_Valid_Configuration_Pragma --
5436 --------------------------------------
5438 -- A configuration pragma must appear in the context clause of a
5439 -- compilation unit, and only other pragmas may precede it. Note that
5440 -- the test also allows use in a configuration pragma file.
5442 procedure Check_Valid_Configuration_Pragma is
5443 begin
5444 if not Is_Configuration_Pragma then
5445 Error_Pragma ("incorrect placement for configuration pragma%");
5446 end if;
5447 end Check_Valid_Configuration_Pragma;
5449 -------------------------------------
5450 -- Check_Valid_Library_Unit_Pragma --
5451 -------------------------------------
5453 procedure Check_Valid_Library_Unit_Pragma is
5454 Plist : List_Id;
5455 Parent_Node : Node_Id;
5456 Unit_Name : Entity_Id;
5457 Unit_Kind : Node_Kind;
5458 Unit_Node : Node_Id;
5459 Sindex : Source_File_Index;
5461 begin
5462 if not Is_List_Member (N) then
5463 Pragma_Misplaced;
5465 else
5466 Plist := List_Containing (N);
5467 Parent_Node := Parent (Plist);
5469 if Parent_Node = Empty then
5470 Pragma_Misplaced;
5472 -- Case of pragma appearing after a compilation unit. In this case
5473 -- it must have an argument with the corresponding name and must
5474 -- be part of the following pragmas of its parent.
5476 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
5477 if Plist /= Pragmas_After (Parent_Node) then
5478 Pragma_Misplaced;
5480 elsif Arg_Count = 0 then
5481 Error_Pragma
5482 ("argument required if outside compilation unit");
5484 else
5485 Check_No_Identifiers;
5486 Check_Arg_Count (1);
5487 Unit_Node := Unit (Parent (Parent_Node));
5488 Unit_Kind := Nkind (Unit_Node);
5490 Analyze (Get_Pragma_Arg (Arg1));
5492 if Unit_Kind = N_Generic_Subprogram_Declaration
5493 or else Unit_Kind = N_Subprogram_Declaration
5494 then
5495 Unit_Name := Defining_Entity (Unit_Node);
5497 elsif Unit_Kind in N_Generic_Instantiation then
5498 Unit_Name := Defining_Entity (Unit_Node);
5500 else
5501 Unit_Name := Cunit_Entity (Current_Sem_Unit);
5502 end if;
5504 if Chars (Unit_Name) /=
5505 Chars (Entity (Get_Pragma_Arg (Arg1)))
5506 then
5507 Error_Pragma_Arg
5508 ("pragma% argument is not current unit name", Arg1);
5509 end if;
5511 if Ekind (Unit_Name) = E_Package
5512 and then Present (Renamed_Entity (Unit_Name))
5513 then
5514 Error_Pragma ("pragma% not allowed for renamed package");
5515 end if;
5516 end if;
5518 -- Pragma appears other than after a compilation unit
5520 else
5521 -- Here we check for the generic instantiation case and also
5522 -- for the case of processing a generic formal package. We
5523 -- detect these cases by noting that the Sloc on the node
5524 -- does not belong to the current compilation unit.
5526 Sindex := Source_Index (Current_Sem_Unit);
5528 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
5529 Rewrite (N, Make_Null_Statement (Loc));
5530 return;
5532 -- If before first declaration, the pragma applies to the
5533 -- enclosing unit, and the name if present must be this name.
5535 elsif Is_Before_First_Decl (N, Plist) then
5536 Unit_Node := Unit_Declaration_Node (Current_Scope);
5537 Unit_Kind := Nkind (Unit_Node);
5539 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
5540 Pragma_Misplaced;
5542 elsif Unit_Kind = N_Subprogram_Body
5543 and then not Acts_As_Spec (Unit_Node)
5544 then
5545 Pragma_Misplaced;
5547 elsif Nkind (Parent_Node) = N_Package_Body then
5548 Pragma_Misplaced;
5550 elsif Nkind (Parent_Node) = N_Package_Specification
5551 and then Plist = Private_Declarations (Parent_Node)
5552 then
5553 Pragma_Misplaced;
5555 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
5556 or else Nkind (Parent_Node) =
5557 N_Generic_Subprogram_Declaration)
5558 and then Plist = Generic_Formal_Declarations (Parent_Node)
5559 then
5560 Pragma_Misplaced;
5562 elsif Arg_Count > 0 then
5563 Analyze (Get_Pragma_Arg (Arg1));
5565 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
5566 Error_Pragma_Arg
5567 ("name in pragma% must be enclosing unit", Arg1);
5568 end if;
5570 -- It is legal to have no argument in this context
5572 else
5573 return;
5574 end if;
5576 -- Error if not before first declaration. This is because a
5577 -- library unit pragma argument must be the name of a library
5578 -- unit (RM 10.1.5(7)), but the only names permitted in this
5579 -- context are (RM 10.1.5(6)) names of subprogram declarations,
5580 -- generic subprogram declarations or generic instantiations.
5582 else
5583 Error_Pragma
5584 ("pragma% misplaced, must be before first declaration");
5585 end if;
5586 end if;
5587 end if;
5588 end Check_Valid_Library_Unit_Pragma;
5590 -------------------
5591 -- Check_Variant --
5592 -------------------
5594 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
5595 Clist : constant Node_Id := Component_List (Variant);
5596 Comp : Node_Id;
5598 begin
5599 Comp := First (Component_Items (Clist));
5600 while Present (Comp) loop
5601 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
5602 Next (Comp);
5603 end loop;
5604 end Check_Variant;
5606 ---------------------------
5607 -- Ensure_Aggregate_Form --
5608 ---------------------------
5610 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
5611 Expr : constant Node_Id := Get_Pragma_Arg (Arg);
5612 Loc : constant Source_Ptr := Sloc (Arg);
5613 Nam : constant Name_Id := Chars (Arg);
5614 Comps : List_Id := No_List;
5615 Exprs : List_Id := No_List;
5617 CFSD : constant Boolean := Get_Comes_From_Source_Default;
5618 -- Used to restore Comes_From_Source_Default
5620 begin
5621 -- The argument is already in aggregate form, but the presence of a
5622 -- name causes this to be interpreted as a named association which in
5623 -- turn must be converted into an aggregate.
5625 -- pragma Global (In_Out => (A, B, C))
5626 -- ^ ^
5627 -- name aggregate
5629 -- pragma Global ((In_Out => (A, B, C)))
5630 -- ^ ^
5631 -- aggregate aggregate
5633 if Nkind (Expr) = N_Aggregate then
5634 if Nam = No_Name then
5635 return;
5636 end if;
5638 -- Do not transform a null argument into an aggregate as N_Null has
5639 -- special meaning in formal verification pragmas.
5641 elsif Nkind (Expr) = N_Null then
5642 return;
5643 end if;
5645 -- Everything comes from source if the original comes from source
5647 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
5649 -- Positional argument is transformed into an aggregate with an
5650 -- Expressions list.
5652 if Nam = No_Name then
5653 Exprs := New_List (Relocate_Node (Expr));
5655 -- An associative argument is transformed into an aggregate with
5656 -- Component_Associations.
5658 else
5659 Comps := New_List (
5660 Make_Component_Association (Loc,
5661 Choices => New_List (Make_Identifier (Loc, Chars (Arg))),
5662 Expression => Relocate_Node (Expr)));
5663 end if;
5665 -- Remove the pragma argument name as this information has been
5666 -- captured in the aggregate.
5668 Set_Chars (Arg, No_Name);
5670 Set_Expression (Arg,
5671 Make_Aggregate (Loc,
5672 Component_Associations => Comps,
5673 Expressions => Exprs));
5675 -- Restore Comes_From_Source default
5677 Set_Comes_From_Source_Default (CFSD);
5678 end Ensure_Aggregate_Form;
5680 ------------------
5681 -- Error_Pragma --
5682 ------------------
5684 procedure Error_Pragma (Msg : String) is
5685 begin
5686 Error_Msg_Name_1 := Pname;
5687 Error_Msg_N (Fix_Error (Msg), N);
5688 raise Pragma_Exit;
5689 end Error_Pragma;
5691 ----------------------
5692 -- Error_Pragma_Arg --
5693 ----------------------
5695 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
5696 begin
5697 Error_Msg_Name_1 := Pname;
5698 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
5699 raise Pragma_Exit;
5700 end Error_Pragma_Arg;
5702 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
5703 begin
5704 Error_Msg_Name_1 := Pname;
5705 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
5706 Error_Pragma_Arg (Msg2, Arg);
5707 end Error_Pragma_Arg;
5709 ----------------------------
5710 -- Error_Pragma_Arg_Ident --
5711 ----------------------------
5713 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
5714 begin
5715 Error_Msg_Name_1 := Pname;
5716 Error_Msg_N (Fix_Error (Msg), Arg);
5717 raise Pragma_Exit;
5718 end Error_Pragma_Arg_Ident;
5720 ----------------------
5721 -- Error_Pragma_Ref --
5722 ----------------------
5724 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
5725 begin
5726 Error_Msg_Name_1 := Pname;
5727 Error_Msg_Sloc := Sloc (Ref);
5728 Error_Msg_NE (Fix_Error (Msg), N, Ref);
5729 raise Pragma_Exit;
5730 end Error_Pragma_Ref;
5732 ------------------------
5733 -- Find_Lib_Unit_Name --
5734 ------------------------
5736 function Find_Lib_Unit_Name return Entity_Id is
5737 begin
5738 -- Return inner compilation unit entity, for case of nested
5739 -- categorization pragmas. This happens in generic unit.
5741 if Nkind (Parent (N)) = N_Package_Specification
5742 and then Defining_Entity (Parent (N)) /= Current_Scope
5743 then
5744 return Defining_Entity (Parent (N));
5745 else
5746 return Current_Scope;
5747 end if;
5748 end Find_Lib_Unit_Name;
5750 ----------------------------
5751 -- Find_Program_Unit_Name --
5752 ----------------------------
5754 procedure Find_Program_Unit_Name (Id : Node_Id) is
5755 Unit_Name : Entity_Id;
5756 Unit_Kind : Node_Kind;
5757 P : constant Node_Id := Parent (N);
5759 begin
5760 if Nkind (P) = N_Compilation_Unit then
5761 Unit_Kind := Nkind (Unit (P));
5763 if Nkind_In (Unit_Kind, N_Subprogram_Declaration,
5764 N_Package_Declaration)
5765 or else Unit_Kind in N_Generic_Declaration
5766 then
5767 Unit_Name := Defining_Entity (Unit (P));
5769 if Chars (Id) = Chars (Unit_Name) then
5770 Set_Entity (Id, Unit_Name);
5771 Set_Etype (Id, Etype (Unit_Name));
5772 else
5773 Set_Etype (Id, Any_Type);
5774 Error_Pragma
5775 ("cannot find program unit referenced by pragma%");
5776 end if;
5778 else
5779 Set_Etype (Id, Any_Type);
5780 Error_Pragma ("pragma% inapplicable to this unit");
5781 end if;
5783 else
5784 Analyze (Id);
5785 end if;
5786 end Find_Program_Unit_Name;
5788 -----------------------------------------
5789 -- Find_Unique_Parameterless_Procedure --
5790 -----------------------------------------
5792 function Find_Unique_Parameterless_Procedure
5793 (Name : Entity_Id;
5794 Arg : Node_Id) return Entity_Id
5796 Proc : Entity_Id := Empty;
5798 begin
5799 -- The body of this procedure needs some comments ???
5801 if not Is_Entity_Name (Name) then
5802 Error_Pragma_Arg
5803 ("argument of pragma% must be entity name", Arg);
5805 elsif not Is_Overloaded (Name) then
5806 Proc := Entity (Name);
5808 if Ekind (Proc) /= E_Procedure
5809 or else Present (First_Formal (Proc))
5810 then
5811 Error_Pragma_Arg
5812 ("argument of pragma% must be parameterless procedure", Arg);
5813 end if;
5815 else
5816 declare
5817 Found : Boolean := False;
5818 It : Interp;
5819 Index : Interp_Index;
5821 begin
5822 Get_First_Interp (Name, Index, It);
5823 while Present (It.Nam) loop
5824 Proc := It.Nam;
5826 if Ekind (Proc) = E_Procedure
5827 and then No (First_Formal (Proc))
5828 then
5829 if not Found then
5830 Found := True;
5831 Set_Entity (Name, Proc);
5832 Set_Is_Overloaded (Name, False);
5833 else
5834 Error_Pragma_Arg
5835 ("ambiguous handler name for pragma% ", Arg);
5836 end if;
5837 end if;
5839 Get_Next_Interp (Index, It);
5840 end loop;
5842 if not Found then
5843 Error_Pragma_Arg
5844 ("argument of pragma% must be parameterless procedure",
5845 Arg);
5846 else
5847 Proc := Entity (Name);
5848 end if;
5849 end;
5850 end if;
5852 return Proc;
5853 end Find_Unique_Parameterless_Procedure;
5855 ---------------
5856 -- Fix_Error --
5857 ---------------
5859 function Fix_Error (Msg : String) return String is
5860 Res : String (Msg'Range) := Msg;
5861 Res_Last : Natural := Msg'Last;
5862 J : Natural;
5864 begin
5865 -- If we have a rewriting of another pragma, go to that pragma
5867 if Is_Rewrite_Substitution (N)
5868 and then Nkind (Original_Node (N)) = N_Pragma
5869 then
5870 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
5871 end if;
5873 -- Case where pragma comes from an aspect specification
5875 if From_Aspect_Specification (N) then
5877 -- Change appearence of "pragma" in message to "aspect"
5879 J := Res'First;
5880 while J <= Res_Last - 5 loop
5881 if Res (J .. J + 5) = "pragma" then
5882 Res (J .. J + 5) := "aspect";
5883 J := J + 6;
5885 else
5886 J := J + 1;
5887 end if;
5888 end loop;
5890 -- Change "argument of" at start of message to "entity for"
5892 if Res'Length > 11
5893 and then Res (Res'First .. Res'First + 10) = "argument of"
5894 then
5895 Res (Res'First .. Res'First + 9) := "entity for";
5896 Res (Res'First + 10 .. Res_Last - 1) :=
5897 Res (Res'First + 11 .. Res_Last);
5898 Res_Last := Res_Last - 1;
5899 end if;
5901 -- Change "argument" at start of message to "entity"
5903 if Res'Length > 8
5904 and then Res (Res'First .. Res'First + 7) = "argument"
5905 then
5906 Res (Res'First .. Res'First + 5) := "entity";
5907 Res (Res'First + 6 .. Res_Last - 2) :=
5908 Res (Res'First + 8 .. Res_Last);
5909 Res_Last := Res_Last - 2;
5910 end if;
5912 -- Get name from corresponding aspect
5914 Error_Msg_Name_1 := Original_Aspect_Name (N);
5915 end if;
5917 -- Return possibly modified message
5919 return Res (Res'First .. Res_Last);
5920 end Fix_Error;
5922 -------------------------
5923 -- Gather_Associations --
5924 -------------------------
5926 procedure Gather_Associations
5927 (Names : Name_List;
5928 Args : out Args_List)
5930 Arg : Node_Id;
5932 begin
5933 -- Initialize all parameters to Empty
5935 for J in Args'Range loop
5936 Args (J) := Empty;
5937 end loop;
5939 -- That's all we have to do if there are no argument associations
5941 if No (Pragma_Argument_Associations (N)) then
5942 return;
5943 end if;
5945 -- Otherwise first deal with any positional parameters present
5947 Arg := First (Pragma_Argument_Associations (N));
5948 for Index in Args'Range loop
5949 exit when No (Arg) or else Chars (Arg) /= No_Name;
5950 Args (Index) := Get_Pragma_Arg (Arg);
5951 Next (Arg);
5952 end loop;
5954 -- Positional parameters all processed, if any left, then we
5955 -- have too many positional parameters.
5957 if Present (Arg) and then Chars (Arg) = No_Name then
5958 Error_Pragma_Arg
5959 ("too many positional associations for pragma%", Arg);
5960 end if;
5962 -- Process named parameters if any are present
5964 while Present (Arg) loop
5965 if Chars (Arg) = No_Name then
5966 Error_Pragma_Arg
5967 ("positional association cannot follow named association",
5968 Arg);
5970 else
5971 for Index in Names'Range loop
5972 if Names (Index) = Chars (Arg) then
5973 if Present (Args (Index)) then
5974 Error_Pragma_Arg
5975 ("duplicate argument association for pragma%", Arg);
5976 else
5977 Args (Index) := Get_Pragma_Arg (Arg);
5978 exit;
5979 end if;
5980 end if;
5982 if Index = Names'Last then
5983 Error_Msg_Name_1 := Pname;
5984 Error_Msg_N ("pragma% does not allow & argument", Arg);
5986 -- Check for possible misspelling
5988 for Index1 in Names'Range loop
5989 if Is_Bad_Spelling_Of
5990 (Chars (Arg), Names (Index1))
5991 then
5992 Error_Msg_Name_1 := Names (Index1);
5993 Error_Msg_N -- CODEFIX
5994 ("\possible misspelling of%", Arg);
5995 exit;
5996 end if;
5997 end loop;
5999 raise Pragma_Exit;
6000 end if;
6001 end loop;
6002 end if;
6004 Next (Arg);
6005 end loop;
6006 end Gather_Associations;
6008 -----------------
6009 -- GNAT_Pragma --
6010 -----------------
6012 procedure GNAT_Pragma is
6013 begin
6014 -- We need to check the No_Implementation_Pragmas restriction for
6015 -- the case of a pragma from source. Note that the case of aspects
6016 -- generating corresponding pragmas marks these pragmas as not being
6017 -- from source, so this test also catches that case.
6019 if Comes_From_Source (N) then
6020 Check_Restriction (No_Implementation_Pragmas, N);
6021 end if;
6022 end GNAT_Pragma;
6024 --------------------------
6025 -- Is_Before_First_Decl --
6026 --------------------------
6028 function Is_Before_First_Decl
6029 (Pragma_Node : Node_Id;
6030 Decls : List_Id) return Boolean
6032 Item : Node_Id := First (Decls);
6034 begin
6035 -- Only other pragmas can come before this pragma
6037 loop
6038 if No (Item) or else Nkind (Item) /= N_Pragma then
6039 return False;
6041 elsif Item = Pragma_Node then
6042 return True;
6043 end if;
6045 Next (Item);
6046 end loop;
6047 end Is_Before_First_Decl;
6049 -----------------------------
6050 -- Is_Configuration_Pragma --
6051 -----------------------------
6053 -- A configuration pragma must appear in the context clause of a
6054 -- compilation unit, and only other pragmas may precede it. Note that
6055 -- the test below also permits use in a configuration pragma file.
6057 function Is_Configuration_Pragma return Boolean is
6058 Lis : constant List_Id := List_Containing (N);
6059 Par : constant Node_Id := Parent (N);
6060 Prg : Node_Id;
6062 begin
6063 -- If no parent, then we are in the configuration pragma file,
6064 -- so the placement is definitely appropriate.
6066 if No (Par) then
6067 return True;
6069 -- Otherwise we must be in the context clause of a compilation unit
6070 -- and the only thing allowed before us in the context list is more
6071 -- configuration pragmas.
6073 elsif Nkind (Par) = N_Compilation_Unit
6074 and then Context_Items (Par) = Lis
6075 then
6076 Prg := First (Lis);
6078 loop
6079 if Prg = N then
6080 return True;
6081 elsif Nkind (Prg) /= N_Pragma then
6082 return False;
6083 end if;
6085 Next (Prg);
6086 end loop;
6088 else
6089 return False;
6090 end if;
6091 end Is_Configuration_Pragma;
6093 --------------------------
6094 -- Is_In_Context_Clause --
6095 --------------------------
6097 function Is_In_Context_Clause return Boolean is
6098 Plist : List_Id;
6099 Parent_Node : Node_Id;
6101 begin
6102 if not Is_List_Member (N) then
6103 return False;
6105 else
6106 Plist := List_Containing (N);
6107 Parent_Node := Parent (Plist);
6109 if Parent_Node = Empty
6110 or else Nkind (Parent_Node) /= N_Compilation_Unit
6111 or else Context_Items (Parent_Node) /= Plist
6112 then
6113 return False;
6114 end if;
6115 end if;
6117 return True;
6118 end Is_In_Context_Clause;
6120 ---------------------------------
6121 -- Is_Static_String_Expression --
6122 ---------------------------------
6124 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
6125 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6126 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
6128 begin
6129 Analyze_And_Resolve (Argx);
6131 -- Special case Ada 83, where the expression will never be static,
6132 -- but we will return true if we had a string literal to start with.
6134 if Ada_Version = Ada_83 then
6135 return Lit;
6137 -- Normal case, true only if we end up with a string literal that
6138 -- is marked as being the result of evaluating a static expression.
6140 else
6141 return Is_OK_Static_Expression (Argx)
6142 and then Nkind (Argx) = N_String_Literal;
6143 end if;
6145 end Is_Static_String_Expression;
6147 ----------------------
6148 -- Pragma_Misplaced --
6149 ----------------------
6151 procedure Pragma_Misplaced is
6152 begin
6153 Error_Pragma ("incorrect placement of pragma%");
6154 end Pragma_Misplaced;
6156 ------------------------------------------------
6157 -- Process_Atomic_Independent_Shared_Volatile --
6158 ------------------------------------------------
6160 procedure Process_Atomic_Independent_Shared_Volatile is
6161 E_Id : Node_Id;
6162 E : Entity_Id;
6163 D : Node_Id;
6164 K : Node_Kind;
6165 Utyp : Entity_Id;
6167 procedure Set_Atomic (E : Entity_Id);
6168 -- Set given type as atomic, and if no explicit alignment was given,
6169 -- set alignment to unknown, since back end knows what the alignment
6170 -- requirements are for atomic arrays. Note: this step is necessary
6171 -- for derived types.
6173 ----------------
6174 -- Set_Atomic --
6175 ----------------
6177 procedure Set_Atomic (E : Entity_Id) is
6178 begin
6179 Set_Is_Atomic (E);
6181 if not Has_Alignment_Clause (E) then
6182 Set_Alignment (E, Uint_0);
6183 end if;
6184 end Set_Atomic;
6186 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
6188 begin
6189 Check_Ada_83_Warning;
6190 Check_No_Identifiers;
6191 Check_Arg_Count (1);
6192 Check_Arg_Is_Local_Name (Arg1);
6193 E_Id := Get_Pragma_Arg (Arg1);
6195 if Etype (E_Id) = Any_Type then
6196 return;
6197 end if;
6199 E := Entity (E_Id);
6200 D := Declaration_Node (E);
6201 K := Nkind (D);
6203 -- Check duplicate before we chain ourselves
6205 Check_Duplicate_Pragma (E);
6207 -- Now check appropriateness of the entity
6209 if Is_Type (E) then
6210 if Rep_Item_Too_Early (E, N)
6211 or else
6212 Rep_Item_Too_Late (E, N)
6213 then
6214 return;
6215 else
6216 Check_First_Subtype (Arg1);
6217 end if;
6219 if Prag_Id = Pragma_Atomic or else Prag_Id = Pragma_Shared then
6220 Set_Atomic (E);
6221 Set_Atomic (Underlying_Type (E));
6222 Set_Atomic (Base_Type (E));
6223 end if;
6225 -- Atomic/Shared imply both Independent and Volatile
6227 if Prag_Id /= Pragma_Volatile then
6228 Set_Is_Independent (E);
6229 Set_Is_Independent (Underlying_Type (E));
6230 Set_Is_Independent (Base_Type (E));
6232 if Prag_Id = Pragma_Independent then
6233 Independence_Checks.Append ((N, Base_Type (E)));
6234 end if;
6235 end if;
6237 -- Attribute belongs on the base type. If the view of the type is
6238 -- currently private, it also belongs on the underlying type.
6240 if Prag_Id /= Pragma_Independent then
6241 Set_Is_Volatile (Base_Type (E));
6242 Set_Is_Volatile (Underlying_Type (E));
6244 Set_Treat_As_Volatile (E);
6245 Set_Treat_As_Volatile (Underlying_Type (E));
6246 end if;
6248 elsif K = N_Object_Declaration
6249 or else (K = N_Component_Declaration
6250 and then Original_Record_Component (E) = E)
6251 then
6252 if Rep_Item_Too_Late (E, N) then
6253 return;
6254 end if;
6256 if Prag_Id = Pragma_Atomic or else Prag_Id = Pragma_Shared then
6257 Set_Is_Atomic (E);
6259 -- If the object declaration has an explicit initialization, a
6260 -- temporary may have to be created to hold the expression, to
6261 -- ensure that access to the object remain atomic.
6263 if Nkind (Parent (E)) = N_Object_Declaration
6264 and then Present (Expression (Parent (E)))
6265 then
6266 Set_Has_Delayed_Freeze (E);
6267 end if;
6269 -- An interesting improvement here. If an object of composite
6270 -- type X is declared atomic, and the type X isn't, that's a
6271 -- pity, since it may not have appropriate alignment etc. We
6272 -- can rescue this in the special case where the object and
6273 -- type are in the same unit by just setting the type as
6274 -- atomic, so that the back end will process it as atomic.
6276 -- Note: we used to do this for elementary types as well,
6277 -- but that turns out to be a bad idea and can have unwanted
6278 -- effects, most notably if the type is elementary, the object
6279 -- a simple component within a record, and both are in a spec:
6280 -- every object of this type in the entire program will be
6281 -- treated as atomic, thus incurring a potentially costly
6282 -- synchronization operation for every access.
6284 -- Of course it would be best if the back end could just adjust
6285 -- the alignment etc for the specific object, but that's not
6286 -- something we are capable of doing at this point.
6288 Utyp := Underlying_Type (Etype (E));
6290 if Present (Utyp)
6291 and then Is_Composite_Type (Utyp)
6292 and then Sloc (E) > No_Location
6293 and then Sloc (Utyp) > No_Location
6294 and then
6295 Get_Source_File_Index (Sloc (E)) =
6296 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
6297 then
6298 Set_Is_Atomic (Underlying_Type (Etype (E)));
6299 end if;
6300 end if;
6302 -- Atomic/Shared imply both Independent and Volatile
6304 if Prag_Id /= Pragma_Volatile then
6305 Set_Is_Independent (E);
6307 if Prag_Id = Pragma_Independent then
6308 Independence_Checks.Append ((N, E));
6309 end if;
6310 end if;
6312 if Prag_Id /= Pragma_Independent then
6313 Set_Is_Volatile (E);
6314 Set_Treat_As_Volatile (E);
6315 end if;
6317 else
6318 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6319 end if;
6321 -- The following check is only relevant when SPARK_Mode is on as
6322 -- this is not a standard Ada legality rule. Pragma Volatile can
6323 -- only apply to a full type declaration or an object declaration
6324 -- (SPARK RM C.6(1)).
6326 if SPARK_Mode = On
6327 and then Prag_Id = Pragma_Volatile
6328 and then not Nkind_In (K, N_Full_Type_Declaration,
6329 N_Object_Declaration)
6330 then
6331 Error_Pragma_Arg
6332 ("argument of pragma % must denote a full type or object "
6333 & "declaration", Arg1);
6334 end if;
6335 end Process_Atomic_Independent_Shared_Volatile;
6337 -------------------------------------------
6338 -- Process_Compile_Time_Warning_Or_Error --
6339 -------------------------------------------
6341 procedure Process_Compile_Time_Warning_Or_Error is
6342 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
6344 begin
6345 Check_Arg_Count (2);
6346 Check_No_Identifiers;
6347 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
6348 Analyze_And_Resolve (Arg1x, Standard_Boolean);
6350 if Compile_Time_Known_Value (Arg1x) then
6351 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
6352 declare
6353 Str : constant String_Id :=
6354 Strval (Get_Pragma_Arg (Arg2));
6355 Len : constant Int := String_Length (Str);
6356 Cont : Boolean;
6357 Ptr : Nat;
6358 CC : Char_Code;
6359 C : Character;
6360 Cent : constant Entity_Id :=
6361 Cunit_Entity (Current_Sem_Unit);
6363 Force : constant Boolean :=
6364 Prag_Id = Pragma_Compile_Time_Warning
6365 and then
6366 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
6367 and then (Ekind (Cent) /= E_Package
6368 or else not In_Private_Part (Cent));
6369 -- Set True if this is the warning case, and we are in the
6370 -- visible part of a package spec, or in a subprogram spec,
6371 -- in which case we want to force the client to see the
6372 -- warning, even though it is not in the main unit.
6374 begin
6375 -- Loop through segments of message separated by line feeds.
6376 -- We output these segments as separate messages with
6377 -- continuation marks for all but the first.
6379 Cont := False;
6380 Ptr := 1;
6381 loop
6382 Error_Msg_Strlen := 0;
6384 -- Loop to copy characters from argument to error message
6385 -- string buffer.
6387 loop
6388 exit when Ptr > Len;
6389 CC := Get_String_Char (Str, Ptr);
6390 Ptr := Ptr + 1;
6392 -- Ignore wide chars ??? else store character
6394 if In_Character_Range (CC) then
6395 C := Get_Character (CC);
6396 exit when C = ASCII.LF;
6397 Error_Msg_Strlen := Error_Msg_Strlen + 1;
6398 Error_Msg_String (Error_Msg_Strlen) := C;
6399 end if;
6400 end loop;
6402 -- Here with one line ready to go
6404 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
6406 -- If this is a warning in a spec, then we want clients
6407 -- to see the warning, so mark the message with the
6408 -- special sequence !! to force the warning. In the case
6409 -- of a package spec, we do not force this if we are in
6410 -- the private part of the spec.
6412 if Force then
6413 if Cont = False then
6414 Error_Msg_N ("<<~!!", Arg1);
6415 Cont := True;
6416 else
6417 Error_Msg_N ("\<<~!!", Arg1);
6418 end if;
6420 -- Error, rather than warning, or in a body, so we do not
6421 -- need to force visibility for client (error will be
6422 -- output in any case, and this is the situation in which
6423 -- we do not want a client to get a warning, since the
6424 -- warning is in the body or the spec private part).
6426 else
6427 if Cont = False then
6428 Error_Msg_N ("<<~", Arg1);
6429 Cont := True;
6430 else
6431 Error_Msg_N ("\<<~", Arg1);
6432 end if;
6433 end if;
6435 exit when Ptr > Len;
6436 end loop;
6437 end;
6438 end if;
6439 end if;
6440 end Process_Compile_Time_Warning_Or_Error;
6442 ------------------------
6443 -- Process_Convention --
6444 ------------------------
6446 procedure Process_Convention
6447 (C : out Convention_Id;
6448 Ent : out Entity_Id)
6450 Cname : Name_Id;
6452 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
6453 -- Called if we have more than one Export/Import/Convention pragma.
6454 -- This is generally illegal, but we have a special case of allowing
6455 -- Import and Interface to coexist if they specify the convention in
6456 -- a consistent manner. We are allowed to do this, since Interface is
6457 -- an implementation defined pragma, and we choose to do it since we
6458 -- know Rational allows this combination. S is the entity id of the
6459 -- subprogram in question. This procedure also sets the special flag
6460 -- Import_Interface_Present in both pragmas in the case where we do
6461 -- have matching Import and Interface pragmas.
6463 procedure Set_Convention_From_Pragma (E : Entity_Id);
6464 -- Set convention in entity E, and also flag that the entity has a
6465 -- convention pragma. If entity is for a private or incomplete type,
6466 -- also set convention and flag on underlying type. This procedure
6467 -- also deals with the special case of C_Pass_By_Copy convention,
6468 -- and error checks for inappropriate convention specification.
6470 -------------------------------
6471 -- Diagnose_Multiple_Pragmas --
6472 -------------------------------
6474 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
6475 Pdec : constant Node_Id := Declaration_Node (S);
6476 Decl : Node_Id;
6477 Err : Boolean;
6479 function Same_Convention (Decl : Node_Id) return Boolean;
6480 -- Decl is a pragma node. This function returns True if this
6481 -- pragma has a first argument that is an identifier with a
6482 -- Chars field corresponding to the Convention_Id C.
6484 function Same_Name (Decl : Node_Id) return Boolean;
6485 -- Decl is a pragma node. This function returns True if this
6486 -- pragma has a second argument that is an identifier with a
6487 -- Chars field that matches the Chars of the current subprogram.
6489 ---------------------
6490 -- Same_Convention --
6491 ---------------------
6493 function Same_Convention (Decl : Node_Id) return Boolean is
6494 Arg1 : constant Node_Id :=
6495 First (Pragma_Argument_Associations (Decl));
6497 begin
6498 if Present (Arg1) then
6499 declare
6500 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
6501 begin
6502 if Nkind (Arg) = N_Identifier
6503 and then Is_Convention_Name (Chars (Arg))
6504 and then Get_Convention_Id (Chars (Arg)) = C
6505 then
6506 return True;
6507 end if;
6508 end;
6509 end if;
6511 return False;
6512 end Same_Convention;
6514 ---------------
6515 -- Same_Name --
6516 ---------------
6518 function Same_Name (Decl : Node_Id) return Boolean is
6519 Arg1 : constant Node_Id :=
6520 First (Pragma_Argument_Associations (Decl));
6521 Arg2 : Node_Id;
6523 begin
6524 if No (Arg1) then
6525 return False;
6526 end if;
6528 Arg2 := Next (Arg1);
6530 if No (Arg2) then
6531 return False;
6532 end if;
6534 declare
6535 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
6536 begin
6537 if Nkind (Arg) = N_Identifier
6538 and then Chars (Arg) = Chars (S)
6539 then
6540 return True;
6541 end if;
6542 end;
6544 return False;
6545 end Same_Name;
6547 -- Start of processing for Diagnose_Multiple_Pragmas
6549 begin
6550 Err := True;
6552 -- Definitely give message if we have Convention/Export here
6554 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
6555 null;
6557 -- If we have an Import or Export, scan back from pragma to
6558 -- find any previous pragma applying to the same procedure.
6559 -- The scan will be terminated by the start of the list, or
6560 -- hitting the subprogram declaration. This won't allow one
6561 -- pragma to appear in the public part and one in the private
6562 -- part, but that seems very unlikely in practice.
6564 else
6565 Decl := Prev (N);
6566 while Present (Decl) and then Decl /= Pdec loop
6568 -- Look for pragma with same name as us
6570 if Nkind (Decl) = N_Pragma
6571 and then Same_Name (Decl)
6572 then
6573 -- Give error if same as our pragma or Export/Convention
6575 if Nam_In (Pragma_Name (Decl), Name_Export,
6576 Name_Convention,
6577 Pragma_Name (N))
6578 then
6579 exit;
6581 -- Case of Import/Interface or the other way round
6583 elsif Nam_In (Pragma_Name (Decl), Name_Interface,
6584 Name_Import)
6585 then
6586 -- Here we know that we have Import and Interface. It
6587 -- doesn't matter which way round they are. See if
6588 -- they specify the same convention. If so, all OK,
6589 -- and set special flags to stop other messages
6591 if Same_Convention (Decl) then
6592 Set_Import_Interface_Present (N);
6593 Set_Import_Interface_Present (Decl);
6594 Err := False;
6596 -- If different conventions, special message
6598 else
6599 Error_Msg_Sloc := Sloc (Decl);
6600 Error_Pragma_Arg
6601 ("convention differs from that given#", Arg1);
6602 return;
6603 end if;
6604 end if;
6605 end if;
6607 Next (Decl);
6608 end loop;
6609 end if;
6611 -- Give message if needed if we fall through those tests
6612 -- except on Relaxed_RM_Semantics where we let go: either this
6613 -- is a case accepted/ignored by other Ada compilers (e.g.
6614 -- a mix of Convention and Import), or another error will be
6615 -- generated later (e.g. using both Import and Export).
6617 if Err and not Relaxed_RM_Semantics then
6618 Error_Pragma_Arg
6619 ("at most one Convention/Export/Import pragma is allowed",
6620 Arg2);
6621 end if;
6622 end Diagnose_Multiple_Pragmas;
6624 --------------------------------
6625 -- Set_Convention_From_Pragma --
6626 --------------------------------
6628 procedure Set_Convention_From_Pragma (E : Entity_Id) is
6629 begin
6630 -- Ada 2005 (AI-430): Check invalid attempt to change convention
6631 -- for an overridden dispatching operation. Technically this is
6632 -- an amendment and should only be done in Ada 2005 mode. However,
6633 -- this is clearly a mistake, since the problem that is addressed
6634 -- by this AI is that there is a clear gap in the RM.
6636 if Is_Dispatching_Operation (E)
6637 and then Present (Overridden_Operation (E))
6638 and then C /= Convention (Overridden_Operation (E))
6639 then
6640 Error_Pragma_Arg
6641 ("cannot change convention for overridden dispatching "
6642 & "operation", Arg1);
6643 end if;
6645 -- Special checks for Convention_Stdcall
6647 if C = Convention_Stdcall then
6649 -- A dispatching call is not allowed. A dispatching subprogram
6650 -- cannot be used to interface to the Win32 API, so in fact
6651 -- this check does not impose any effective restriction.
6653 if Is_Dispatching_Operation (E) then
6654 Error_Msg_Sloc := Sloc (E);
6656 -- Note: make this unconditional so that if there is more
6657 -- than one call to which the pragma applies, we get a
6658 -- message for each call. Also don't use Error_Pragma,
6659 -- so that we get multiple messages.
6661 Error_Msg_N
6662 ("dispatching subprogram# cannot use Stdcall convention!",
6663 Arg1);
6665 -- Subprograms are not allowed
6667 elsif not Is_Subprogram_Or_Generic_Subprogram (E)
6669 -- A variable is OK
6671 and then Ekind (E) /= E_Variable
6673 -- An access to subprogram is also allowed
6675 and then not
6676 (Is_Access_Type (E)
6677 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
6679 -- Allow internal call to set convention of subprogram type
6681 and then not (Ekind (E) = E_Subprogram_Type)
6682 then
6683 Error_Pragma_Arg
6684 ("second argument of pragma% must be subprogram (type)",
6685 Arg2);
6686 end if;
6687 end if;
6689 -- Set the convention
6691 Set_Convention (E, C);
6692 Set_Has_Convention_Pragma (E);
6694 -- For the case of a record base type, also set the convention of
6695 -- any anonymous access types declared in the record which do not
6696 -- currently have a specified convention.
6698 if Is_Record_Type (E) and then Is_Base_Type (E) then
6699 declare
6700 Comp : Node_Id;
6702 begin
6703 Comp := First_Component (E);
6704 while Present (Comp) loop
6705 if Present (Etype (Comp))
6706 and then Ekind_In (Etype (Comp),
6707 E_Anonymous_Access_Type,
6708 E_Anonymous_Access_Subprogram_Type)
6709 and then not Has_Convention_Pragma (Comp)
6710 then
6711 Set_Convention (Comp, C);
6712 end if;
6714 Next_Component (Comp);
6715 end loop;
6716 end;
6717 end if;
6719 -- Deal with incomplete/private type case, where underlying type
6720 -- is available, so set convention of that underlying type.
6722 if Is_Incomplete_Or_Private_Type (E)
6723 and then Present (Underlying_Type (E))
6724 then
6725 Set_Convention (Underlying_Type (E), C);
6726 Set_Has_Convention_Pragma (Underlying_Type (E), True);
6727 end if;
6729 -- A class-wide type should inherit the convention of the specific
6730 -- root type (although this isn't specified clearly by the RM).
6732 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
6733 Set_Convention (Class_Wide_Type (E), C);
6734 end if;
6736 -- If the entity is a record type, then check for special case of
6737 -- C_Pass_By_Copy, which is treated the same as C except that the
6738 -- special record flag is set. This convention is only permitted
6739 -- on record types (see AI95-00131).
6741 if Cname = Name_C_Pass_By_Copy then
6742 if Is_Record_Type (E) then
6743 Set_C_Pass_By_Copy (Base_Type (E));
6744 elsif Is_Incomplete_Or_Private_Type (E)
6745 and then Is_Record_Type (Underlying_Type (E))
6746 then
6747 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
6748 else
6749 Error_Pragma_Arg
6750 ("C_Pass_By_Copy convention allowed only for record type",
6751 Arg2);
6752 end if;
6753 end if;
6755 -- If the entity is a derived boolean type, check for the special
6756 -- case of convention C, C++, or Fortran, where we consider any
6757 -- nonzero value to represent true.
6759 if Is_Discrete_Type (E)
6760 and then Root_Type (Etype (E)) = Standard_Boolean
6761 and then
6762 (C = Convention_C
6763 or else
6764 C = Convention_CPP
6765 or else
6766 C = Convention_Fortran)
6767 then
6768 Set_Nonzero_Is_True (Base_Type (E));
6769 end if;
6770 end Set_Convention_From_Pragma;
6772 -- Local variables
6774 Comp_Unit : Unit_Number_Type;
6775 E : Entity_Id;
6776 E1 : Entity_Id;
6777 Id : Node_Id;
6779 -- Start of processing for Process_Convention
6781 begin
6782 Check_At_Least_N_Arguments (2);
6783 Check_Optional_Identifier (Arg1, Name_Convention);
6784 Check_Arg_Is_Identifier (Arg1);
6785 Cname := Chars (Get_Pragma_Arg (Arg1));
6787 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
6788 -- tested again below to set the critical flag).
6790 if Cname = Name_C_Pass_By_Copy then
6791 C := Convention_C;
6793 -- Otherwise we must have something in the standard convention list
6795 elsif Is_Convention_Name (Cname) then
6796 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
6798 -- Otherwise warn on unrecognized convention
6800 else
6801 if Warn_On_Export_Import then
6802 Error_Msg_N
6803 ("??unrecognized convention name, C assumed",
6804 Get_Pragma_Arg (Arg1));
6805 end if;
6807 C := Convention_C;
6808 end if;
6810 Check_Optional_Identifier (Arg2, Name_Entity);
6811 Check_Arg_Is_Local_Name (Arg2);
6813 Id := Get_Pragma_Arg (Arg2);
6814 Analyze (Id);
6816 if not Is_Entity_Name (Id) then
6817 Error_Pragma_Arg ("entity name required", Arg2);
6818 end if;
6820 E := Entity (Id);
6822 -- Set entity to return
6824 Ent := E;
6826 -- Ada_Pass_By_Copy special checking
6828 if C = Convention_Ada_Pass_By_Copy then
6829 if not Is_First_Subtype (E) then
6830 Error_Pragma_Arg
6831 ("convention `Ada_Pass_By_Copy` only allowed for types",
6832 Arg2);
6833 end if;
6835 if Is_By_Reference_Type (E) then
6836 Error_Pragma_Arg
6837 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
6838 & "type", Arg1);
6839 end if;
6841 -- Ada_Pass_By_Reference special checking
6843 elsif C = Convention_Ada_Pass_By_Reference then
6844 if not Is_First_Subtype (E) then
6845 Error_Pragma_Arg
6846 ("convention `Ada_Pass_By_Reference` only allowed for types",
6847 Arg2);
6848 end if;
6850 if Is_By_Copy_Type (E) then
6851 Error_Pragma_Arg
6852 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
6853 & "type", Arg1);
6854 end if;
6855 end if;
6857 -- Go to renamed subprogram if present, since convention applies to
6858 -- the actual renamed entity, not to the renaming entity. If the
6859 -- subprogram is inherited, go to parent subprogram.
6861 if Is_Subprogram (E)
6862 and then Present (Alias (E))
6863 then
6864 if Nkind (Parent (Declaration_Node (E))) =
6865 N_Subprogram_Renaming_Declaration
6866 then
6867 if Scope (E) /= Scope (Alias (E)) then
6868 Error_Pragma_Ref
6869 ("cannot apply pragma% to non-local entity&#", E);
6870 end if;
6872 E := Alias (E);
6874 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
6875 N_Private_Extension_Declaration)
6876 and then Scope (E) = Scope (Alias (E))
6877 then
6878 E := Alias (E);
6880 -- Return the parent subprogram the entity was inherited from
6882 Ent := E;
6883 end if;
6884 end if;
6886 -- Check that we are not applying this to a specless body. Relax this
6887 -- check if Relaxed_RM_Semantics to accomodate other Ada compilers.
6889 if Is_Subprogram (E)
6890 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
6891 and then not Relaxed_RM_Semantics
6892 then
6893 Error_Pragma
6894 ("pragma% requires separate spec and must come before body");
6895 end if;
6897 -- Check that we are not applying this to a named constant
6899 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
6900 Error_Msg_Name_1 := Pname;
6901 Error_Msg_N
6902 ("cannot apply pragma% to named constant!",
6903 Get_Pragma_Arg (Arg2));
6904 Error_Pragma_Arg
6905 ("\supply appropriate type for&!", Arg2);
6906 end if;
6908 if Ekind (E) = E_Enumeration_Literal then
6909 Error_Pragma ("enumeration literal not allowed for pragma%");
6910 end if;
6912 -- Check for rep item appearing too early or too late
6914 if Etype (E) = Any_Type
6915 or else Rep_Item_Too_Early (E, N)
6916 then
6917 raise Pragma_Exit;
6919 elsif Present (Underlying_Type (E)) then
6920 E := Underlying_Type (E);
6921 end if;
6923 if Rep_Item_Too_Late (E, N) then
6924 raise Pragma_Exit;
6925 end if;
6927 if Has_Convention_Pragma (E) then
6928 Diagnose_Multiple_Pragmas (E);
6930 elsif Convention (E) = Convention_Protected
6931 or else Ekind (Scope (E)) = E_Protected_Type
6932 then
6933 Error_Pragma_Arg
6934 ("a protected operation cannot be given a different convention",
6935 Arg2);
6936 end if;
6938 -- For Intrinsic, a subprogram is required
6940 if C = Convention_Intrinsic
6941 and then not Is_Subprogram_Or_Generic_Subprogram (E)
6942 then
6943 Error_Pragma_Arg
6944 ("second argument of pragma% must be a subprogram", Arg2);
6945 end if;
6947 -- Deal with non-subprogram cases
6949 if not Is_Subprogram_Or_Generic_Subprogram (E) then
6950 Set_Convention_From_Pragma (E);
6952 if Is_Type (E) then
6953 Check_First_Subtype (Arg2);
6954 Set_Convention_From_Pragma (Base_Type (E));
6956 -- For access subprograms, we must set the convention on the
6957 -- internally generated directly designated type as well.
6959 if Ekind (E) = E_Access_Subprogram_Type then
6960 Set_Convention_From_Pragma (Directly_Designated_Type (E));
6961 end if;
6962 end if;
6964 -- For the subprogram case, set proper convention for all homonyms
6965 -- in same scope and the same declarative part, i.e. the same
6966 -- compilation unit.
6968 else
6969 Comp_Unit := Get_Source_Unit (E);
6970 Set_Convention_From_Pragma (E);
6972 -- Treat a pragma Import as an implicit body, and pragma import
6973 -- as implicit reference (for navigation in GPS).
6975 if Prag_Id = Pragma_Import then
6976 Generate_Reference (E, Id, 'b');
6978 -- For exported entities we restrict the generation of references
6979 -- to entities exported to foreign languages since entities
6980 -- exported to Ada do not provide further information to GPS and
6981 -- add undesired references to the output of the gnatxref tool.
6983 elsif Prag_Id = Pragma_Export
6984 and then Convention (E) /= Convention_Ada
6985 then
6986 Generate_Reference (E, Id, 'i');
6987 end if;
6989 -- If the pragma comes from from an aspect, it only applies to the
6990 -- given entity, not its homonyms.
6992 if From_Aspect_Specification (N) then
6993 return;
6994 end if;
6996 -- Otherwise Loop through the homonyms of the pragma argument's
6997 -- entity, an apply convention to those in the current scope.
6999 E1 := Ent;
7001 loop
7002 E1 := Homonym (E1);
7003 exit when No (E1) or else Scope (E1) /= Current_Scope;
7005 -- Ignore entry for which convention is already set
7007 if Has_Convention_Pragma (E1) then
7008 goto Continue;
7009 end if;
7011 -- Do not set the pragma on inherited operations or on formal
7012 -- subprograms.
7014 if Comes_From_Source (E1)
7015 and then Comp_Unit = Get_Source_Unit (E1)
7016 and then not Is_Formal_Subprogram (E1)
7017 and then Nkind (Original_Node (Parent (E1))) /=
7018 N_Full_Type_Declaration
7019 then
7020 if Present (Alias (E1))
7021 and then Scope (E1) /= Scope (Alias (E1))
7022 then
7023 Error_Pragma_Ref
7024 ("cannot apply pragma% to non-local entity& declared#",
7025 E1);
7026 end if;
7028 Set_Convention_From_Pragma (E1);
7030 if Prag_Id = Pragma_Import then
7031 Generate_Reference (E1, Id, 'b');
7032 end if;
7033 end if;
7035 <<Continue>>
7036 null;
7037 end loop;
7038 end if;
7039 end Process_Convention;
7041 ----------------------------------------
7042 -- Process_Disable_Enable_Atomic_Sync --
7043 ----------------------------------------
7045 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
7046 begin
7047 Check_No_Identifiers;
7048 Check_At_Most_N_Arguments (1);
7050 -- Modeled internally as
7051 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
7053 Rewrite (N,
7054 Make_Pragma (Loc,
7055 Pragma_Identifier =>
7056 Make_Identifier (Loc, Nam),
7057 Pragma_Argument_Associations => New_List (
7058 Make_Pragma_Argument_Association (Loc,
7059 Expression =>
7060 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
7062 if Present (Arg1) then
7063 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
7064 end if;
7066 Analyze (N);
7067 end Process_Disable_Enable_Atomic_Sync;
7069 -------------------------------------------------
7070 -- Process_Extended_Import_Export_Internal_Arg --
7071 -------------------------------------------------
7073 procedure Process_Extended_Import_Export_Internal_Arg
7074 (Arg_Internal : Node_Id := Empty)
7076 begin
7077 if No (Arg_Internal) then
7078 Error_Pragma ("Internal parameter required for pragma%");
7079 end if;
7081 if Nkind (Arg_Internal) = N_Identifier then
7082 null;
7084 elsif Nkind (Arg_Internal) = N_Operator_Symbol
7085 and then (Prag_Id = Pragma_Import_Function
7086 or else
7087 Prag_Id = Pragma_Export_Function)
7088 then
7089 null;
7091 else
7092 Error_Pragma_Arg
7093 ("wrong form for Internal parameter for pragma%", Arg_Internal);
7094 end if;
7096 Check_Arg_Is_Local_Name (Arg_Internal);
7097 end Process_Extended_Import_Export_Internal_Arg;
7099 --------------------------------------------------
7100 -- Process_Extended_Import_Export_Object_Pragma --
7101 --------------------------------------------------
7103 procedure Process_Extended_Import_Export_Object_Pragma
7104 (Arg_Internal : Node_Id;
7105 Arg_External : Node_Id;
7106 Arg_Size : Node_Id)
7108 Def_Id : Entity_Id;
7110 begin
7111 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7112 Def_Id := Entity (Arg_Internal);
7114 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
7115 Error_Pragma_Arg
7116 ("pragma% must designate an object", Arg_Internal);
7117 end if;
7119 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
7120 or else
7121 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
7122 then
7123 Error_Pragma_Arg
7124 ("previous Common/Psect_Object applies, pragma % not permitted",
7125 Arg_Internal);
7126 end if;
7128 if Rep_Item_Too_Late (Def_Id, N) then
7129 raise Pragma_Exit;
7130 end if;
7132 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
7134 if Present (Arg_Size) then
7135 Check_Arg_Is_External_Name (Arg_Size);
7136 end if;
7138 -- Export_Object case
7140 if Prag_Id = Pragma_Export_Object then
7141 if not Is_Library_Level_Entity (Def_Id) then
7142 Error_Pragma_Arg
7143 ("argument for pragma% must be library level entity",
7144 Arg_Internal);
7145 end if;
7147 if Ekind (Current_Scope) = E_Generic_Package then
7148 Error_Pragma ("pragma& cannot appear in a generic unit");
7149 end if;
7151 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
7152 Error_Pragma_Arg
7153 ("exported object must have compile time known size",
7154 Arg_Internal);
7155 end if;
7157 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
7158 Error_Msg_N ("??duplicate Export_Object pragma", N);
7159 else
7160 Set_Exported (Def_Id, Arg_Internal);
7161 end if;
7163 -- Import_Object case
7165 else
7166 if Is_Concurrent_Type (Etype (Def_Id)) then
7167 Error_Pragma_Arg
7168 ("cannot use pragma% for task/protected object",
7169 Arg_Internal);
7170 end if;
7172 if Ekind (Def_Id) = E_Constant then
7173 Error_Pragma_Arg
7174 ("cannot import a constant", Arg_Internal);
7175 end if;
7177 if Warn_On_Export_Import
7178 and then Has_Discriminants (Etype (Def_Id))
7179 then
7180 Error_Msg_N
7181 ("imported value must be initialized??", Arg_Internal);
7182 end if;
7184 if Warn_On_Export_Import
7185 and then Is_Access_Type (Etype (Def_Id))
7186 then
7187 Error_Pragma_Arg
7188 ("cannot import object of an access type??", Arg_Internal);
7189 end if;
7191 if Warn_On_Export_Import
7192 and then Is_Imported (Def_Id)
7193 then
7194 Error_Msg_N ("??duplicate Import_Object pragma", N);
7196 -- Check for explicit initialization present. Note that an
7197 -- initialization generated by the code generator, e.g. for an
7198 -- access type, does not count here.
7200 elsif Present (Expression (Parent (Def_Id)))
7201 and then
7202 Comes_From_Source
7203 (Original_Node (Expression (Parent (Def_Id))))
7204 then
7205 Error_Msg_Sloc := Sloc (Def_Id);
7206 Error_Pragma_Arg
7207 ("imported entities cannot be initialized (RM B.1(24))",
7208 "\no initialization allowed for & declared#", Arg1);
7209 else
7210 Set_Imported (Def_Id);
7211 Note_Possible_Modification (Arg_Internal, Sure => False);
7212 end if;
7213 end if;
7214 end Process_Extended_Import_Export_Object_Pragma;
7216 ------------------------------------------------------
7217 -- Process_Extended_Import_Export_Subprogram_Pragma --
7218 ------------------------------------------------------
7220 procedure Process_Extended_Import_Export_Subprogram_Pragma
7221 (Arg_Internal : Node_Id;
7222 Arg_External : Node_Id;
7223 Arg_Parameter_Types : Node_Id;
7224 Arg_Result_Type : Node_Id := Empty;
7225 Arg_Mechanism : Node_Id;
7226 Arg_Result_Mechanism : Node_Id := Empty)
7228 Ent : Entity_Id;
7229 Def_Id : Entity_Id;
7230 Hom_Id : Entity_Id;
7231 Formal : Entity_Id;
7232 Ambiguous : Boolean;
7233 Match : Boolean;
7235 function Same_Base_Type
7236 (Ptype : Node_Id;
7237 Formal : Entity_Id) return Boolean;
7238 -- Determines if Ptype references the type of Formal. Note that only
7239 -- the base types need to match according to the spec. Ptype here is
7240 -- the argument from the pragma, which is either a type name, or an
7241 -- access attribute.
7243 --------------------
7244 -- Same_Base_Type --
7245 --------------------
7247 function Same_Base_Type
7248 (Ptype : Node_Id;
7249 Formal : Entity_Id) return Boolean
7251 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
7252 Pref : Node_Id;
7254 begin
7255 -- Case where pragma argument is typ'Access
7257 if Nkind (Ptype) = N_Attribute_Reference
7258 and then Attribute_Name (Ptype) = Name_Access
7259 then
7260 Pref := Prefix (Ptype);
7261 Find_Type (Pref);
7263 if not Is_Entity_Name (Pref)
7264 or else Entity (Pref) = Any_Type
7265 then
7266 raise Pragma_Exit;
7267 end if;
7269 -- We have a match if the corresponding argument is of an
7270 -- anonymous access type, and its designated type matches the
7271 -- type of the prefix of the access attribute
7273 return Ekind (Ftyp) = E_Anonymous_Access_Type
7274 and then Base_Type (Entity (Pref)) =
7275 Base_Type (Etype (Designated_Type (Ftyp)));
7277 -- Case where pragma argument is a type name
7279 else
7280 Find_Type (Ptype);
7282 if not Is_Entity_Name (Ptype)
7283 or else Entity (Ptype) = Any_Type
7284 then
7285 raise Pragma_Exit;
7286 end if;
7288 -- We have a match if the corresponding argument is of the type
7289 -- given in the pragma (comparing base types)
7291 return Base_Type (Entity (Ptype)) = Ftyp;
7292 end if;
7293 end Same_Base_Type;
7295 -- Start of processing for
7296 -- Process_Extended_Import_Export_Subprogram_Pragma
7298 begin
7299 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7300 Ent := Empty;
7301 Ambiguous := False;
7303 -- Loop through homonyms (overloadings) of the entity
7305 Hom_Id := Entity (Arg_Internal);
7306 while Present (Hom_Id) loop
7307 Def_Id := Get_Base_Subprogram (Hom_Id);
7309 -- We need a subprogram in the current scope
7311 if not Is_Subprogram (Def_Id)
7312 or else Scope (Def_Id) /= Current_Scope
7313 then
7314 null;
7316 else
7317 Match := True;
7319 -- Pragma cannot apply to subprogram body
7321 if Is_Subprogram (Def_Id)
7322 and then Nkind (Parent (Declaration_Node (Def_Id))) =
7323 N_Subprogram_Body
7324 then
7325 Error_Pragma
7326 ("pragma% requires separate spec"
7327 & " and must come before body");
7328 end if;
7330 -- Test result type if given, note that the result type
7331 -- parameter can only be present for the function cases.
7333 if Present (Arg_Result_Type)
7334 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
7335 then
7336 Match := False;
7338 elsif Etype (Def_Id) /= Standard_Void_Type
7339 and then
7340 Nam_In (Pname, Name_Export_Procedure, Name_Import_Procedure)
7341 then
7342 Match := False;
7344 -- Test parameter types if given. Note that this parameter
7345 -- has not been analyzed (and must not be, since it is
7346 -- semantic nonsense), so we get it as the parser left it.
7348 elsif Present (Arg_Parameter_Types) then
7349 Check_Matching_Types : declare
7350 Formal : Entity_Id;
7351 Ptype : Node_Id;
7353 begin
7354 Formal := First_Formal (Def_Id);
7356 if Nkind (Arg_Parameter_Types) = N_Null then
7357 if Present (Formal) then
7358 Match := False;
7359 end if;
7361 -- A list of one type, e.g. (List) is parsed as
7362 -- a parenthesized expression.
7364 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
7365 and then Paren_Count (Arg_Parameter_Types) = 1
7366 then
7367 if No (Formal)
7368 or else Present (Next_Formal (Formal))
7369 then
7370 Match := False;
7371 else
7372 Match :=
7373 Same_Base_Type (Arg_Parameter_Types, Formal);
7374 end if;
7376 -- A list of more than one type is parsed as a aggregate
7378 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
7379 and then Paren_Count (Arg_Parameter_Types) = 0
7380 then
7381 Ptype := First (Expressions (Arg_Parameter_Types));
7382 while Present (Ptype) or else Present (Formal) loop
7383 if No (Ptype)
7384 or else No (Formal)
7385 or else not Same_Base_Type (Ptype, Formal)
7386 then
7387 Match := False;
7388 exit;
7389 else
7390 Next_Formal (Formal);
7391 Next (Ptype);
7392 end if;
7393 end loop;
7395 -- Anything else is of the wrong form
7397 else
7398 Error_Pragma_Arg
7399 ("wrong form for Parameter_Types parameter",
7400 Arg_Parameter_Types);
7401 end if;
7402 end Check_Matching_Types;
7403 end if;
7405 -- Match is now False if the entry we found did not match
7406 -- either a supplied Parameter_Types or Result_Types argument
7408 if Match then
7409 if No (Ent) then
7410 Ent := Def_Id;
7412 -- Ambiguous case, the flag Ambiguous shows if we already
7413 -- detected this and output the initial messages.
7415 else
7416 if not Ambiguous then
7417 Ambiguous := True;
7418 Error_Msg_Name_1 := Pname;
7419 Error_Msg_N
7420 ("pragma% does not uniquely identify subprogram!",
7422 Error_Msg_Sloc := Sloc (Ent);
7423 Error_Msg_N ("matching subprogram #!", N);
7424 Ent := Empty;
7425 end if;
7427 Error_Msg_Sloc := Sloc (Def_Id);
7428 Error_Msg_N ("matching subprogram #!", N);
7429 end if;
7430 end if;
7431 end if;
7433 Hom_Id := Homonym (Hom_Id);
7434 end loop;
7436 -- See if we found an entry
7438 if No (Ent) then
7439 if not Ambiguous then
7440 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
7441 Error_Pragma
7442 ("pragma% cannot be given for generic subprogram");
7443 else
7444 Error_Pragma
7445 ("pragma% does not identify local subprogram");
7446 end if;
7447 end if;
7449 return;
7450 end if;
7452 -- Import pragmas must be for imported entities
7454 if Prag_Id = Pragma_Import_Function
7455 or else
7456 Prag_Id = Pragma_Import_Procedure
7457 or else
7458 Prag_Id = Pragma_Import_Valued_Procedure
7459 then
7460 if not Is_Imported (Ent) then
7461 Error_Pragma
7462 ("pragma Import or Interface must precede pragma%");
7463 end if;
7465 -- Here we have the Export case which can set the entity as exported
7467 -- But does not do so if the specified external name is null, since
7468 -- that is taken as a signal in DEC Ada 83 (with which we want to be
7469 -- compatible) to request no external name.
7471 elsif Nkind (Arg_External) = N_String_Literal
7472 and then String_Length (Strval (Arg_External)) = 0
7473 then
7474 null;
7476 -- In all other cases, set entity as exported
7478 else
7479 Set_Exported (Ent, Arg_Internal);
7480 end if;
7482 -- Special processing for Valued_Procedure cases
7484 if Prag_Id = Pragma_Import_Valued_Procedure
7485 or else
7486 Prag_Id = Pragma_Export_Valued_Procedure
7487 then
7488 Formal := First_Formal (Ent);
7490 if No (Formal) then
7491 Error_Pragma ("at least one parameter required for pragma%");
7493 elsif Ekind (Formal) /= E_Out_Parameter then
7494 Error_Pragma ("first parameter must have mode out for pragma%");
7496 else
7497 Set_Is_Valued_Procedure (Ent);
7498 end if;
7499 end if;
7501 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
7503 -- Process Result_Mechanism argument if present. We have already
7504 -- checked that this is only allowed for the function case.
7506 if Present (Arg_Result_Mechanism) then
7507 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
7508 end if;
7510 -- Process Mechanism parameter if present. Note that this parameter
7511 -- is not analyzed, and must not be analyzed since it is semantic
7512 -- nonsense, so we get it in exactly as the parser left it.
7514 if Present (Arg_Mechanism) then
7515 declare
7516 Formal : Entity_Id;
7517 Massoc : Node_Id;
7518 Mname : Node_Id;
7519 Choice : Node_Id;
7521 begin
7522 -- A single mechanism association without a formal parameter
7523 -- name is parsed as a parenthesized expression. All other
7524 -- cases are parsed as aggregates, so we rewrite the single
7525 -- parameter case as an aggregate for consistency.
7527 if Nkind (Arg_Mechanism) /= N_Aggregate
7528 and then Paren_Count (Arg_Mechanism) = 1
7529 then
7530 Rewrite (Arg_Mechanism,
7531 Make_Aggregate (Sloc (Arg_Mechanism),
7532 Expressions => New_List (
7533 Relocate_Node (Arg_Mechanism))));
7534 end if;
7536 -- Case of only mechanism name given, applies to all formals
7538 if Nkind (Arg_Mechanism) /= N_Aggregate then
7539 Formal := First_Formal (Ent);
7540 while Present (Formal) loop
7541 Set_Mechanism_Value (Formal, Arg_Mechanism);
7542 Next_Formal (Formal);
7543 end loop;
7545 -- Case of list of mechanism associations given
7547 else
7548 if Null_Record_Present (Arg_Mechanism) then
7549 Error_Pragma_Arg
7550 ("inappropriate form for Mechanism parameter",
7551 Arg_Mechanism);
7552 end if;
7554 -- Deal with positional ones first
7556 Formal := First_Formal (Ent);
7558 if Present (Expressions (Arg_Mechanism)) then
7559 Mname := First (Expressions (Arg_Mechanism));
7560 while Present (Mname) loop
7561 if No (Formal) then
7562 Error_Pragma_Arg
7563 ("too many mechanism associations", Mname);
7564 end if;
7566 Set_Mechanism_Value (Formal, Mname);
7567 Next_Formal (Formal);
7568 Next (Mname);
7569 end loop;
7570 end if;
7572 -- Deal with named entries
7574 if Present (Component_Associations (Arg_Mechanism)) then
7575 Massoc := First (Component_Associations (Arg_Mechanism));
7576 while Present (Massoc) loop
7577 Choice := First (Choices (Massoc));
7579 if Nkind (Choice) /= N_Identifier
7580 or else Present (Next (Choice))
7581 then
7582 Error_Pragma_Arg
7583 ("incorrect form for mechanism association",
7584 Massoc);
7585 end if;
7587 Formal := First_Formal (Ent);
7588 loop
7589 if No (Formal) then
7590 Error_Pragma_Arg
7591 ("parameter name & not present", Choice);
7592 end if;
7594 if Chars (Choice) = Chars (Formal) then
7595 Set_Mechanism_Value
7596 (Formal, Expression (Massoc));
7598 -- Set entity on identifier (needed by ASIS)
7600 Set_Entity (Choice, Formal);
7602 exit;
7603 end if;
7605 Next_Formal (Formal);
7606 end loop;
7608 Next (Massoc);
7609 end loop;
7610 end if;
7611 end if;
7612 end;
7613 end if;
7614 end Process_Extended_Import_Export_Subprogram_Pragma;
7616 --------------------------
7617 -- Process_Generic_List --
7618 --------------------------
7620 procedure Process_Generic_List is
7621 Arg : Node_Id;
7622 Exp : Node_Id;
7624 begin
7625 Check_No_Identifiers;
7626 Check_At_Least_N_Arguments (1);
7628 -- Check all arguments are names of generic units or instances
7630 Arg := Arg1;
7631 while Present (Arg) loop
7632 Exp := Get_Pragma_Arg (Arg);
7633 Analyze (Exp);
7635 if not Is_Entity_Name (Exp)
7636 or else
7637 (not Is_Generic_Instance (Entity (Exp))
7638 and then
7639 not Is_Generic_Unit (Entity (Exp)))
7640 then
7641 Error_Pragma_Arg
7642 ("pragma% argument must be name of generic unit/instance",
7643 Arg);
7644 end if;
7646 Next (Arg);
7647 end loop;
7648 end Process_Generic_List;
7650 ------------------------------------
7651 -- Process_Import_Predefined_Type --
7652 ------------------------------------
7654 procedure Process_Import_Predefined_Type is
7655 Loc : constant Source_Ptr := Sloc (N);
7656 Elmt : Elmt_Id;
7657 Ftyp : Node_Id := Empty;
7658 Decl : Node_Id;
7659 Def : Node_Id;
7660 Nam : Name_Id;
7662 begin
7663 String_To_Name_Buffer (Strval (Expression (Arg3)));
7664 Nam := Name_Find;
7666 Elmt := First_Elmt (Predefined_Float_Types);
7667 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
7668 Next_Elmt (Elmt);
7669 end loop;
7671 Ftyp := Node (Elmt);
7673 if Present (Ftyp) then
7675 -- Don't build a derived type declaration, because predefined C
7676 -- types have no declaration anywhere, so cannot really be named.
7677 -- Instead build a full type declaration, starting with an
7678 -- appropriate type definition is built
7680 if Is_Floating_Point_Type (Ftyp) then
7681 Def := Make_Floating_Point_Definition (Loc,
7682 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
7683 Make_Real_Range_Specification (Loc,
7684 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
7685 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
7687 -- Should never have a predefined type we cannot handle
7689 else
7690 raise Program_Error;
7691 end if;
7693 -- Build and insert a Full_Type_Declaration, which will be
7694 -- analyzed as soon as this list entry has been analyzed.
7696 Decl := Make_Full_Type_Declaration (Loc,
7697 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
7698 Type_Definition => Def);
7700 Insert_After (N, Decl);
7701 Mark_Rewrite_Insertion (Decl);
7703 else
7704 Error_Pragma_Arg ("no matching type found for pragma%",
7705 Arg2);
7706 end if;
7707 end Process_Import_Predefined_Type;
7709 ---------------------------------
7710 -- Process_Import_Or_Interface --
7711 ---------------------------------
7713 procedure Process_Import_Or_Interface is
7714 C : Convention_Id;
7715 Def_Id : Entity_Id;
7716 Hom_Id : Entity_Id;
7718 begin
7719 -- In Relaxed_RM_Semantics, support old Ada 83 style:
7720 -- pragma Import (Entity, "external name");
7722 if Relaxed_RM_Semantics
7723 and then Arg_Count = 2
7724 and then Prag_Id = Pragma_Import
7725 and then Nkind (Expression (Arg2)) = N_String_Literal
7726 then
7727 C := Convention_C;
7728 Def_Id := Get_Pragma_Arg (Arg1);
7729 Analyze (Def_Id);
7731 if not Is_Entity_Name (Def_Id) then
7732 Error_Pragma_Arg ("entity name required", Arg1);
7733 end if;
7735 Def_Id := Entity (Def_Id);
7736 Kill_Size_Check_Code (Def_Id);
7737 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
7739 else
7740 Process_Convention (C, Def_Id);
7741 Kill_Size_Check_Code (Def_Id);
7742 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
7743 end if;
7745 if Ekind_In (Def_Id, E_Variable, E_Constant) then
7747 -- We do not permit Import to apply to a renaming declaration
7749 if Present (Renamed_Object (Def_Id)) then
7750 Error_Pragma_Arg
7751 ("pragma% not allowed for object renaming", Arg2);
7753 -- User initialization is not allowed for imported object, but
7754 -- the object declaration may contain a default initialization,
7755 -- that will be discarded. Note that an explicit initialization
7756 -- only counts if it comes from source, otherwise it is simply
7757 -- the code generator making an implicit initialization explicit.
7759 elsif Present (Expression (Parent (Def_Id)))
7760 and then Comes_From_Source
7761 (Original_Node (Expression (Parent (Def_Id))))
7762 then
7763 -- Set imported flag to prevent cascaded errors
7765 Set_Is_Imported (Def_Id);
7767 Error_Msg_Sloc := Sloc (Def_Id);
7768 Error_Pragma_Arg
7769 ("no initialization allowed for declaration of& #",
7770 "\imported entities cannot be initialized (RM B.1(24))",
7771 Arg2);
7773 else
7774 -- If the pragma comes from an aspect specification the
7775 -- Is_Imported flag has already been set.
7777 if not From_Aspect_Specification (N) then
7778 Set_Imported (Def_Id);
7779 end if;
7781 Process_Interface_Name (Def_Id, Arg3, Arg4);
7783 -- Note that we do not set Is_Public here. That's because we
7784 -- only want to set it if there is no address clause, and we
7785 -- don't know that yet, so we delay that processing till
7786 -- freeze time.
7788 -- pragma Import completes deferred constants
7790 if Ekind (Def_Id) = E_Constant then
7791 Set_Has_Completion (Def_Id);
7792 end if;
7794 -- It is not possible to import a constant of an unconstrained
7795 -- array type (e.g. string) because there is no simple way to
7796 -- write a meaningful subtype for it.
7798 if Is_Array_Type (Etype (Def_Id))
7799 and then not Is_Constrained (Etype (Def_Id))
7800 then
7801 Error_Msg_NE
7802 ("imported constant& must have a constrained subtype",
7803 N, Def_Id);
7804 end if;
7805 end if;
7807 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
7809 -- If the name is overloaded, pragma applies to all of the denoted
7810 -- entities in the same declarative part, unless the pragma comes
7811 -- from an aspect specification or was generated by the compiler
7812 -- (such as for pragma Provide_Shift_Operators).
7814 Hom_Id := Def_Id;
7815 while Present (Hom_Id) loop
7817 Def_Id := Get_Base_Subprogram (Hom_Id);
7819 -- Ignore inherited subprograms because the pragma will apply
7820 -- to the parent operation, which is the one called.
7822 if Is_Overloadable (Def_Id)
7823 and then Present (Alias (Def_Id))
7824 then
7825 null;
7827 -- If it is not a subprogram, it must be in an outer scope and
7828 -- pragma does not apply.
7830 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
7831 null;
7833 -- The pragma does not apply to primitives of interfaces
7835 elsif Is_Dispatching_Operation (Def_Id)
7836 and then Present (Find_Dispatching_Type (Def_Id))
7837 and then Is_Interface (Find_Dispatching_Type (Def_Id))
7838 then
7839 null;
7841 -- Verify that the homonym is in the same declarative part (not
7842 -- just the same scope). If the pragma comes from an aspect
7843 -- specification we know that it is part of the declaration.
7845 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
7846 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
7847 and then not From_Aspect_Specification (N)
7848 then
7849 exit;
7851 else
7852 -- If the pragma comes from an aspect specification the
7853 -- Is_Imported flag has already been set.
7855 if not From_Aspect_Specification (N) then
7856 Set_Imported (Def_Id);
7857 end if;
7859 -- Reject an Import applied to an abstract subprogram
7861 if Is_Subprogram (Def_Id)
7862 and then Is_Abstract_Subprogram (Def_Id)
7863 then
7864 Error_Msg_Sloc := Sloc (Def_Id);
7865 Error_Msg_NE
7866 ("cannot import abstract subprogram& declared#",
7867 Arg2, Def_Id);
7868 end if;
7870 -- Special processing for Convention_Intrinsic
7872 if C = Convention_Intrinsic then
7874 -- Link_Name argument not allowed for intrinsic
7876 Check_No_Link_Name;
7878 Set_Is_Intrinsic_Subprogram (Def_Id);
7880 -- If no external name is present, then check that this
7881 -- is a valid intrinsic subprogram. If an external name
7882 -- is present, then this is handled by the back end.
7884 if No (Arg3) then
7885 Check_Intrinsic_Subprogram
7886 (Def_Id, Get_Pragma_Arg (Arg2));
7887 end if;
7888 end if;
7890 -- Verify that the subprogram does not have a completion
7891 -- through a renaming declaration. For other completions the
7892 -- pragma appears as a too late representation.
7894 declare
7895 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
7897 begin
7898 if Present (Decl)
7899 and then Nkind (Decl) = N_Subprogram_Declaration
7900 and then Present (Corresponding_Body (Decl))
7901 and then Nkind (Unit_Declaration_Node
7902 (Corresponding_Body (Decl))) =
7903 N_Subprogram_Renaming_Declaration
7904 then
7905 Error_Msg_Sloc := Sloc (Def_Id);
7906 Error_Msg_NE
7907 ("cannot import&, renaming already provided for "
7908 & "declaration #", N, Def_Id);
7909 end if;
7910 end;
7912 -- If the pragma comes from an aspect specification, there
7913 -- must be an Import aspect specified as well. In the rare
7914 -- case where Import is set to False, the suprogram needs to
7915 -- have a local completion.
7917 declare
7918 Imp_Aspect : constant Node_Id :=
7919 Find_Aspect (Def_Id, Aspect_Import);
7920 Expr : Node_Id;
7922 begin
7923 if Present (Imp_Aspect)
7924 and then Present (Expression (Imp_Aspect))
7925 then
7926 Expr := Expression (Imp_Aspect);
7927 Analyze_And_Resolve (Expr, Standard_Boolean);
7929 if Is_Entity_Name (Expr)
7930 and then Entity (Expr) = Standard_True
7931 then
7932 Set_Has_Completion (Def_Id);
7933 end if;
7935 -- If there is no expression, the default is True, as for
7936 -- all boolean aspects. Same for the older pragma.
7938 else
7939 Set_Has_Completion (Def_Id);
7940 end if;
7941 end;
7943 Process_Interface_Name (Def_Id, Arg3, Arg4);
7944 end if;
7946 if Is_Compilation_Unit (Hom_Id) then
7948 -- Its possible homonyms are not affected by the pragma.
7949 -- Such homonyms might be present in the context of other
7950 -- units being compiled.
7952 exit;
7954 elsif From_Aspect_Specification (N) then
7955 exit;
7957 -- If the pragma was created by the compiler, then we don't
7958 -- want it to apply to other homonyms. This kind of case can
7959 -- occur when using pragma Provide_Shift_Operators, which
7960 -- generates implicit shift and rotate operators with Import
7961 -- pragmas that might apply to earlier explicit or implicit
7962 -- declarations marked with Import (for example, coming from
7963 -- an earlier pragma Provide_Shift_Operators for another type),
7964 -- and we don't generally want other homonyms being treated
7965 -- as imported or the pragma flagged as an illegal duplicate.
7967 elsif not Comes_From_Source (N) then
7968 exit;
7970 else
7971 Hom_Id := Homonym (Hom_Id);
7972 end if;
7973 end loop;
7975 -- When the convention is Java or CIL, we also allow Import to
7976 -- be given for packages, generic packages, exceptions, record
7977 -- components, and access to subprograms.
7979 elsif (C = Convention_Java or else C = Convention_CIL)
7980 and then
7981 (Is_Package_Or_Generic_Package (Def_Id)
7982 or else Ekind (Def_Id) = E_Exception
7983 or else Ekind (Def_Id) = E_Access_Subprogram_Type
7984 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
7985 then
7986 Set_Imported (Def_Id);
7987 Set_Is_Public (Def_Id);
7988 Process_Interface_Name (Def_Id, Arg3, Arg4);
7990 -- Import a CPP class
7992 elsif C = Convention_CPP
7993 and then (Is_Record_Type (Def_Id)
7994 or else Ekind (Def_Id) = E_Incomplete_Type)
7995 then
7996 if Ekind (Def_Id) = E_Incomplete_Type then
7997 if Present (Full_View (Def_Id)) then
7998 Def_Id := Full_View (Def_Id);
8000 else
8001 Error_Msg_N
8002 ("cannot import 'C'P'P type before full declaration seen",
8003 Get_Pragma_Arg (Arg2));
8005 -- Although we have reported the error we decorate it as
8006 -- CPP_Class to avoid reporting spurious errors
8008 Set_Is_CPP_Class (Def_Id);
8009 return;
8010 end if;
8011 end if;
8013 -- Types treated as CPP classes must be declared limited (note:
8014 -- this used to be a warning but there is no real benefit to it
8015 -- since we did effectively intend to treat the type as limited
8016 -- anyway).
8018 if not Is_Limited_Type (Def_Id) then
8019 Error_Msg_N
8020 ("imported 'C'P'P type must be limited",
8021 Get_Pragma_Arg (Arg2));
8022 end if;
8024 if Etype (Def_Id) /= Def_Id
8025 and then not Is_CPP_Class (Root_Type (Def_Id))
8026 then
8027 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
8028 end if;
8030 Set_Is_CPP_Class (Def_Id);
8032 -- Imported CPP types must not have discriminants (because C++
8033 -- classes do not have discriminants).
8035 if Has_Discriminants (Def_Id) then
8036 Error_Msg_N
8037 ("imported 'C'P'P type cannot have discriminants",
8038 First (Discriminant_Specifications
8039 (Declaration_Node (Def_Id))));
8040 end if;
8042 -- Check that components of imported CPP types do not have default
8043 -- expressions. For private types this check is performed when the
8044 -- full view is analyzed (see Process_Full_View).
8046 if not Is_Private_Type (Def_Id) then
8047 Check_CPP_Type_Has_No_Defaults (Def_Id);
8048 end if;
8050 -- Import a CPP exception
8052 elsif C = Convention_CPP
8053 and then Ekind (Def_Id) = E_Exception
8054 then
8055 if No (Arg3) then
8056 Error_Pragma_Arg
8057 ("'External_'Name arguments is required for 'Cpp exception",
8058 Arg3);
8059 else
8060 -- As only a string is allowed, Check_Arg_Is_External_Name
8061 -- isn't called.
8063 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8064 end if;
8066 if Present (Arg4) then
8067 Error_Pragma_Arg
8068 ("Link_Name argument not allowed for imported Cpp exception",
8069 Arg4);
8070 end if;
8072 -- Do not call Set_Interface_Name as the name of the exception
8073 -- shouldn't be modified (and in particular it shouldn't be
8074 -- the External_Name). For exceptions, the External_Name is the
8075 -- name of the RTTI structure.
8077 -- ??? Emit an error if pragma Import/Export_Exception is present
8079 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
8080 Check_No_Link_Name;
8081 Check_Arg_Count (3);
8082 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8084 Process_Import_Predefined_Type;
8086 else
8087 Error_Pragma_Arg
8088 ("second argument of pragma% must be object, subprogram "
8089 & "or incomplete type",
8090 Arg2);
8091 end if;
8093 -- If this pragma applies to a compilation unit, then the unit, which
8094 -- is a subprogram, does not require (or allow) a body. We also do
8095 -- not need to elaborate imported procedures.
8097 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
8098 declare
8099 Cunit : constant Node_Id := Parent (Parent (N));
8100 begin
8101 Set_Body_Required (Cunit, False);
8102 end;
8103 end if;
8104 end Process_Import_Or_Interface;
8106 --------------------
8107 -- Process_Inline --
8108 --------------------
8110 procedure Process_Inline (Status : Inline_Status) is
8111 Assoc : Node_Id;
8112 Decl : Node_Id;
8113 Subp_Id : Node_Id;
8114 Subp : Entity_Id;
8115 Applies : Boolean;
8117 procedure Make_Inline (Subp : Entity_Id);
8118 -- Subp is the defining unit name of the subprogram declaration. Set
8119 -- the flag, as well as the flag in the corresponding body, if there
8120 -- is one present.
8122 procedure Set_Inline_Flags (Subp : Entity_Id);
8123 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
8124 -- Has_Pragma_Inline_Always for the Inline_Always case.
8126 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
8127 -- Returns True if it can be determined at this stage that inlining
8128 -- is not possible, for example if the body is available and contains
8129 -- exception handlers, we prevent inlining, since otherwise we can
8130 -- get undefined symbols at link time. This function also emits a
8131 -- warning if front-end inlining is enabled and the pragma appears
8132 -- too late.
8134 -- ??? is business with link symbols still valid, or does it relate
8135 -- to front end ZCX which is being phased out ???
8137 ---------------------------
8138 -- Inlining_Not_Possible --
8139 ---------------------------
8141 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
8142 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
8143 Stats : Node_Id;
8145 begin
8146 if Nkind (Decl) = N_Subprogram_Body then
8147 Stats := Handled_Statement_Sequence (Decl);
8148 return Present (Exception_Handlers (Stats))
8149 or else Present (At_End_Proc (Stats));
8151 elsif Nkind (Decl) = N_Subprogram_Declaration
8152 and then Present (Corresponding_Body (Decl))
8153 then
8154 if Front_End_Inlining
8155 and then Analyzed (Corresponding_Body (Decl))
8156 then
8157 Error_Msg_N ("pragma appears too late, ignored??", N);
8158 return True;
8160 -- If the subprogram is a renaming as body, the body is just a
8161 -- call to the renamed subprogram, and inlining is trivially
8162 -- possible.
8164 elsif
8165 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
8166 N_Subprogram_Renaming_Declaration
8167 then
8168 return False;
8170 else
8171 Stats :=
8172 Handled_Statement_Sequence
8173 (Unit_Declaration_Node (Corresponding_Body (Decl)));
8175 return
8176 Present (Exception_Handlers (Stats))
8177 or else Present (At_End_Proc (Stats));
8178 end if;
8180 else
8181 -- If body is not available, assume the best, the check is
8182 -- performed again when compiling enclosing package bodies.
8184 return False;
8185 end if;
8186 end Inlining_Not_Possible;
8188 -----------------
8189 -- Make_Inline --
8190 -----------------
8192 procedure Make_Inline (Subp : Entity_Id) is
8193 Kind : constant Entity_Kind := Ekind (Subp);
8194 Inner_Subp : Entity_Id := Subp;
8196 begin
8197 -- Ignore if bad type, avoid cascaded error
8199 if Etype (Subp) = Any_Type then
8200 Applies := True;
8201 return;
8203 -- Ignore if all inlining is suppressed
8205 elsif Suppress_All_Inlining then
8206 Applies := True;
8207 return;
8209 -- If inlining is not possible, for now do not treat as an error
8211 elsif Status /= Suppressed
8212 and then Inlining_Not_Possible (Subp)
8213 then
8214 Applies := True;
8215 return;
8217 -- Here we have a candidate for inlining, but we must exclude
8218 -- derived operations. Otherwise we would end up trying to inline
8219 -- a phantom declaration, and the result would be to drag in a
8220 -- body which has no direct inlining associated with it. That
8221 -- would not only be inefficient but would also result in the
8222 -- backend doing cross-unit inlining in cases where it was
8223 -- definitely inappropriate to do so.
8225 -- However, a simple Comes_From_Source test is insufficient, since
8226 -- we do want to allow inlining of generic instances which also do
8227 -- not come from source. We also need to recognize specs generated
8228 -- by the front-end for bodies that carry the pragma. Finally,
8229 -- predefined operators do not come from source but are not
8230 -- inlineable either.
8232 elsif Is_Generic_Instance (Subp)
8233 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
8234 then
8235 null;
8237 elsif not Comes_From_Source (Subp)
8238 and then Scope (Subp) /= Standard_Standard
8239 then
8240 Applies := True;
8241 return;
8242 end if;
8244 -- The referenced entity must either be the enclosing entity, or
8245 -- an entity declared within the current open scope.
8247 if Present (Scope (Subp))
8248 and then Scope (Subp) /= Current_Scope
8249 and then Subp /= Current_Scope
8250 then
8251 Error_Pragma_Arg
8252 ("argument of% must be entity in current scope", Assoc);
8253 return;
8254 end if;
8256 -- Processing for procedure, operator or function. If subprogram
8257 -- is aliased (as for an instance) indicate that the renamed
8258 -- entity (if declared in the same unit) is inlined.
8260 if Is_Subprogram (Subp) then
8261 Inner_Subp := Ultimate_Alias (Inner_Subp);
8263 if In_Same_Source_Unit (Subp, Inner_Subp) then
8264 Set_Inline_Flags (Inner_Subp);
8266 Decl := Parent (Parent (Inner_Subp));
8268 if Nkind (Decl) = N_Subprogram_Declaration
8269 and then Present (Corresponding_Body (Decl))
8270 then
8271 Set_Inline_Flags (Corresponding_Body (Decl));
8273 elsif Is_Generic_Instance (Subp) then
8275 -- Indicate that the body needs to be created for
8276 -- inlining subsequent calls. The instantiation node
8277 -- follows the declaration of the wrapper package
8278 -- created for it.
8280 if Scope (Subp) /= Standard_Standard
8281 and then
8282 Need_Subprogram_Instance_Body
8283 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
8284 Subp)
8285 then
8286 null;
8287 end if;
8289 -- Inline is a program unit pragma (RM 10.1.5) and cannot
8290 -- appear in a formal part to apply to a formal subprogram.
8291 -- Do not apply check within an instance or a formal package
8292 -- the test will have been applied to the original generic.
8294 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
8295 and then List_Containing (Decl) = List_Containing (N)
8296 and then not In_Instance
8297 then
8298 Error_Msg_N
8299 ("Inline cannot apply to a formal subprogram", N);
8301 -- If Subp is a renaming, it is the renamed entity that
8302 -- will appear in any call, and be inlined. However, for
8303 -- ASIS uses it is convenient to indicate that the renaming
8304 -- itself is an inlined subprogram, so that some gnatcheck
8305 -- rules can be applied in the absence of expansion.
8307 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
8308 Set_Inline_Flags (Subp);
8309 end if;
8310 end if;
8312 Applies := True;
8314 -- For a generic subprogram set flag as well, for use at the point
8315 -- of instantiation, to determine whether the body should be
8316 -- generated.
8318 elsif Is_Generic_Subprogram (Subp) then
8319 Set_Inline_Flags (Subp);
8320 Applies := True;
8322 -- Literals are by definition inlined
8324 elsif Kind = E_Enumeration_Literal then
8325 null;
8327 -- Anything else is an error
8329 else
8330 Error_Pragma_Arg
8331 ("expect subprogram name for pragma%", Assoc);
8332 end if;
8333 end Make_Inline;
8335 ----------------------
8336 -- Set_Inline_Flags --
8337 ----------------------
8339 procedure Set_Inline_Flags (Subp : Entity_Id) is
8340 begin
8341 -- First set the Has_Pragma_XXX flags and issue the appropriate
8342 -- errors and warnings for suspicious combinations.
8344 if Prag_Id = Pragma_No_Inline then
8345 if Has_Pragma_Inline_Always (Subp) then
8346 Error_Msg_N
8347 ("Inline_Always and No_Inline are mutually exclusive", N);
8348 elsif Has_Pragma_Inline (Subp) then
8349 Error_Msg_NE
8350 ("Inline and No_Inline both specified for& ??",
8351 N, Entity (Subp_Id));
8352 end if;
8354 Set_Has_Pragma_No_Inline (Subp);
8355 else
8356 if Prag_Id = Pragma_Inline_Always then
8357 if Has_Pragma_No_Inline (Subp) then
8358 Error_Msg_N
8359 ("Inline_Always and No_Inline are mutually exclusive",
8361 end if;
8363 Set_Has_Pragma_Inline_Always (Subp);
8364 else
8365 if Has_Pragma_No_Inline (Subp) then
8366 Error_Msg_NE
8367 ("Inline and No_Inline both specified for& ??",
8368 N, Entity (Subp_Id));
8369 end if;
8370 end if;
8372 if not Has_Pragma_Inline (Subp) then
8373 Set_Has_Pragma_Inline (Subp);
8374 end if;
8375 end if;
8377 -- Then adjust the Is_Inlined flag. It can never be set if the
8378 -- subprogram is subject to pragma No_Inline.
8380 case Status is
8381 when Suppressed =>
8382 Set_Is_Inlined (Subp, False);
8383 when Disabled =>
8384 null;
8385 when Enabled =>
8386 if not Has_Pragma_No_Inline (Subp) then
8387 Set_Is_Inlined (Subp, True);
8388 end if;
8389 end case;
8390 end Set_Inline_Flags;
8392 -- Start of processing for Process_Inline
8394 begin
8395 Check_No_Identifiers;
8396 Check_At_Least_N_Arguments (1);
8398 if Status = Enabled then
8399 Inline_Processing_Required := True;
8400 end if;
8402 Assoc := Arg1;
8403 while Present (Assoc) loop
8404 Subp_Id := Get_Pragma_Arg (Assoc);
8405 Analyze (Subp_Id);
8406 Applies := False;
8408 if Is_Entity_Name (Subp_Id) then
8409 Subp := Entity (Subp_Id);
8411 if Subp = Any_Id then
8413 -- If previous error, avoid cascaded errors
8415 Check_Error_Detected;
8416 Applies := True;
8418 else
8419 Make_Inline (Subp);
8421 -- For the pragma case, climb homonym chain. This is
8422 -- what implements allowing the pragma in the renaming
8423 -- case, with the result applying to the ancestors, and
8424 -- also allows Inline to apply to all previous homonyms.
8426 if not From_Aspect_Specification (N) then
8427 while Present (Homonym (Subp))
8428 and then Scope (Homonym (Subp)) = Current_Scope
8429 loop
8430 Make_Inline (Homonym (Subp));
8431 Subp := Homonym (Subp);
8432 end loop;
8433 end if;
8434 end if;
8435 end if;
8437 if not Applies then
8438 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
8439 end if;
8441 Next (Assoc);
8442 end loop;
8443 end Process_Inline;
8445 ----------------------------
8446 -- Process_Interface_Name --
8447 ----------------------------
8449 procedure Process_Interface_Name
8450 (Subprogram_Def : Entity_Id;
8451 Ext_Arg : Node_Id;
8452 Link_Arg : Node_Id)
8454 Ext_Nam : Node_Id;
8455 Link_Nam : Node_Id;
8456 String_Val : String_Id;
8458 procedure Check_Form_Of_Interface_Name
8459 (SN : Node_Id;
8460 Ext_Name_Case : Boolean);
8461 -- SN is a string literal node for an interface name. This routine
8462 -- performs some minimal checks that the name is reasonable. In
8463 -- particular that no spaces or other obviously incorrect characters
8464 -- appear. This is only a warning, since any characters are allowed.
8465 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
8467 ----------------------------------
8468 -- Check_Form_Of_Interface_Name --
8469 ----------------------------------
8471 procedure Check_Form_Of_Interface_Name
8472 (SN : Node_Id;
8473 Ext_Name_Case : Boolean)
8475 S : constant String_Id := Strval (Expr_Value_S (SN));
8476 SL : constant Nat := String_Length (S);
8477 C : Char_Code;
8479 begin
8480 if SL = 0 then
8481 Error_Msg_N ("interface name cannot be null string", SN);
8482 end if;
8484 for J in 1 .. SL loop
8485 C := Get_String_Char (S, J);
8487 -- Look for dubious character and issue unconditional warning.
8488 -- Definitely dubious if not in character range.
8490 if not In_Character_Range (C)
8492 -- For all cases except CLI target,
8493 -- commas, spaces and slashes are dubious (in CLI, we use
8494 -- commas and backslashes in external names to specify
8495 -- assembly version and public key, while slashes and spaces
8496 -- can be used in names to mark nested classes and
8497 -- valuetypes).
8499 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
8500 and then (Get_Character (C) = ','
8501 or else
8502 Get_Character (C) = '\'))
8503 or else (VM_Target /= CLI_Target
8504 and then (Get_Character (C) = ' '
8505 or else
8506 Get_Character (C) = '/'))
8507 then
8508 Error_Msg
8509 ("??interface name contains illegal character",
8510 Sloc (SN) + Source_Ptr (J));
8511 end if;
8512 end loop;
8513 end Check_Form_Of_Interface_Name;
8515 -- Start of processing for Process_Interface_Name
8517 begin
8518 if No (Link_Arg) then
8519 if No (Ext_Arg) then
8520 if VM_Target = CLI_Target
8521 and then Ekind (Subprogram_Def) = E_Package
8522 and then Nkind (Parent (Subprogram_Def)) =
8523 N_Package_Specification
8524 and then Present (Generic_Parent (Parent (Subprogram_Def)))
8525 then
8526 Set_Interface_Name
8527 (Subprogram_Def,
8528 Interface_Name
8529 (Generic_Parent (Parent (Subprogram_Def))));
8530 end if;
8532 return;
8534 elsif Chars (Ext_Arg) = Name_Link_Name then
8535 Ext_Nam := Empty;
8536 Link_Nam := Expression (Ext_Arg);
8538 else
8539 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8540 Ext_Nam := Expression (Ext_Arg);
8541 Link_Nam := Empty;
8542 end if;
8544 else
8545 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8546 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
8547 Ext_Nam := Expression (Ext_Arg);
8548 Link_Nam := Expression (Link_Arg);
8549 end if;
8551 -- Check expressions for external name and link name are static
8553 if Present (Ext_Nam) then
8554 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
8555 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
8557 -- Verify that external name is not the name of a local entity,
8558 -- which would hide the imported one and could lead to run-time
8559 -- surprises. The problem can only arise for entities declared in
8560 -- a package body (otherwise the external name is fully qualified
8561 -- and will not conflict).
8563 declare
8564 Nam : Name_Id;
8565 E : Entity_Id;
8566 Par : Node_Id;
8568 begin
8569 if Prag_Id = Pragma_Import then
8570 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
8571 Nam := Name_Find;
8572 E := Entity_Id (Get_Name_Table_Int (Nam));
8574 if Nam /= Chars (Subprogram_Def)
8575 and then Present (E)
8576 and then not Is_Overloadable (E)
8577 and then Is_Immediately_Visible (E)
8578 and then not Is_Imported (E)
8579 and then Ekind (Scope (E)) = E_Package
8580 then
8581 Par := Parent (E);
8582 while Present (Par) loop
8583 if Nkind (Par) = N_Package_Body then
8584 Error_Msg_Sloc := Sloc (E);
8585 Error_Msg_NE
8586 ("imported entity is hidden by & declared#",
8587 Ext_Arg, E);
8588 exit;
8589 end if;
8591 Par := Parent (Par);
8592 end loop;
8593 end if;
8594 end if;
8595 end;
8596 end if;
8598 if Present (Link_Nam) then
8599 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
8600 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
8601 end if;
8603 -- If there is no link name, just set the external name
8605 if No (Link_Nam) then
8606 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
8608 -- For the Link_Name case, the given literal is preceded by an
8609 -- asterisk, which indicates to GCC that the given name should be
8610 -- taken literally, and in particular that no prepending of
8611 -- underlines should occur, even in systems where this is the
8612 -- normal default.
8614 else
8615 Start_String;
8617 if VM_Target = No_VM then
8618 Store_String_Char (Get_Char_Code ('*'));
8619 end if;
8621 String_Val := Strval (Expr_Value_S (Link_Nam));
8622 Store_String_Chars (String_Val);
8623 Link_Nam :=
8624 Make_String_Literal (Sloc (Link_Nam),
8625 Strval => End_String);
8626 end if;
8628 -- Set the interface name. If the entity is a generic instance, use
8629 -- its alias, which is the callable entity.
8631 if Is_Generic_Instance (Subprogram_Def) then
8632 Set_Encoded_Interface_Name
8633 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
8634 else
8635 Set_Encoded_Interface_Name
8636 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
8637 end if;
8639 -- We allow duplicated export names in CIL/Java, as they are always
8640 -- enclosed in a namespace that differentiates them, and overloaded
8641 -- entities are supported by the VM.
8643 if Convention (Subprogram_Def) /= Convention_CIL
8644 and then
8645 Convention (Subprogram_Def) /= Convention_Java
8646 then
8647 Check_Duplicated_Export_Name (Link_Nam);
8648 end if;
8649 end Process_Interface_Name;
8651 -----------------------------------------
8652 -- Process_Interrupt_Or_Attach_Handler --
8653 -----------------------------------------
8655 procedure Process_Interrupt_Or_Attach_Handler is
8656 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
8657 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
8658 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
8660 begin
8661 Set_Is_Interrupt_Handler (Handler_Proc);
8663 -- If the pragma is not associated with a handler procedure within a
8664 -- protected type, then it must be for a nonprotected procedure for
8665 -- the AAMP target, in which case we don't associate a representation
8666 -- item with the procedure's scope.
8668 if Ekind (Proc_Scope) = E_Protected_Type then
8669 if Prag_Id = Pragma_Interrupt_Handler
8670 or else
8671 Prag_Id = Pragma_Attach_Handler
8672 then
8673 Record_Rep_Item (Proc_Scope, N);
8674 end if;
8675 end if;
8676 end Process_Interrupt_Or_Attach_Handler;
8678 --------------------------------------------------
8679 -- Process_Restrictions_Or_Restriction_Warnings --
8680 --------------------------------------------------
8682 -- Note: some of the simple identifier cases were handled in par-prag,
8683 -- but it is harmless (and more straightforward) to simply handle all
8684 -- cases here, even if it means we repeat a bit of work in some cases.
8686 procedure Process_Restrictions_Or_Restriction_Warnings
8687 (Warn : Boolean)
8689 Arg : Node_Id;
8690 R_Id : Restriction_Id;
8691 Id : Name_Id;
8692 Expr : Node_Id;
8693 Val : Uint;
8695 begin
8696 -- Ignore all Restrictions pragmas in CodePeer mode
8698 if CodePeer_Mode then
8699 return;
8700 end if;
8702 Check_Ada_83_Warning;
8703 Check_At_Least_N_Arguments (1);
8704 Check_Valid_Configuration_Pragma;
8706 Arg := Arg1;
8707 while Present (Arg) loop
8708 Id := Chars (Arg);
8709 Expr := Get_Pragma_Arg (Arg);
8711 -- Case of no restriction identifier present
8713 if Id = No_Name then
8714 if Nkind (Expr) /= N_Identifier then
8715 Error_Pragma_Arg
8716 ("invalid form for restriction", Arg);
8717 end if;
8719 R_Id :=
8720 Get_Restriction_Id
8721 (Process_Restriction_Synonyms (Expr));
8723 if R_Id not in All_Boolean_Restrictions then
8724 Error_Msg_Name_1 := Pname;
8725 Error_Msg_N
8726 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
8728 -- Check for possible misspelling
8730 for J in Restriction_Id loop
8731 declare
8732 Rnm : constant String := Restriction_Id'Image (J);
8734 begin
8735 Name_Buffer (1 .. Rnm'Length) := Rnm;
8736 Name_Len := Rnm'Length;
8737 Set_Casing (All_Lower_Case);
8739 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
8740 Set_Casing
8741 (Identifier_Casing (Current_Source_File));
8742 Error_Msg_String (1 .. Rnm'Length) :=
8743 Name_Buffer (1 .. Name_Len);
8744 Error_Msg_Strlen := Rnm'Length;
8745 Error_Msg_N -- CODEFIX
8746 ("\possible misspelling of ""~""",
8747 Get_Pragma_Arg (Arg));
8748 exit;
8749 end if;
8750 end;
8751 end loop;
8753 raise Pragma_Exit;
8754 end if;
8756 if Implementation_Restriction (R_Id) then
8757 Check_Restriction (No_Implementation_Restrictions, Arg);
8758 end if;
8760 -- Special processing for No_Elaboration_Code restriction
8762 if R_Id = No_Elaboration_Code then
8764 -- Restriction is only recognized within a configuration
8765 -- pragma file, or within a unit of the main extended
8766 -- program. Note: the test for Main_Unit is needed to
8767 -- properly include the case of configuration pragma files.
8769 if not (Current_Sem_Unit = Main_Unit
8770 or else In_Extended_Main_Source_Unit (N))
8771 then
8772 return;
8774 -- Don't allow in a subunit unless already specified in
8775 -- body or spec.
8777 elsif Nkind (Parent (N)) = N_Compilation_Unit
8778 and then Nkind (Unit (Parent (N))) = N_Subunit
8779 and then not Restriction_Active (No_Elaboration_Code)
8780 then
8781 Error_Msg_N
8782 ("invalid specification of ""No_Elaboration_Code""",
8784 Error_Msg_N
8785 ("\restriction cannot be specified in a subunit", N);
8786 Error_Msg_N
8787 ("\unless also specified in body or spec", N);
8788 return;
8790 -- If we accept a No_Elaboration_Code restriction, then it
8791 -- needs to be added to the configuration restriction set so
8792 -- that we get proper application to other units in the main
8793 -- extended source as required.
8795 else
8796 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
8797 end if;
8798 end if;
8800 -- If this is a warning, then set the warning unless we already
8801 -- have a real restriction active (we never want a warning to
8802 -- override a real restriction).
8804 if Warn then
8805 if not Restriction_Active (R_Id) then
8806 Set_Restriction (R_Id, N);
8807 Restriction_Warnings (R_Id) := True;
8808 end if;
8810 -- If real restriction case, then set it and make sure that the
8811 -- restriction warning flag is off, since a real restriction
8812 -- always overrides a warning.
8814 else
8815 Set_Restriction (R_Id, N);
8816 Restriction_Warnings (R_Id) := False;
8817 end if;
8819 -- Check for obsolescent restrictions in Ada 2005 mode
8821 if not Warn
8822 and then Ada_Version >= Ada_2005
8823 and then (R_Id = No_Asynchronous_Control
8824 or else
8825 R_Id = No_Unchecked_Deallocation
8826 or else
8827 R_Id = No_Unchecked_Conversion)
8828 then
8829 Check_Restriction (No_Obsolescent_Features, N);
8830 end if;
8832 -- A very special case that must be processed here: pragma
8833 -- Restrictions (No_Exceptions) turns off all run-time
8834 -- checking. This is a bit dubious in terms of the formal
8835 -- language definition, but it is what is intended by RM
8836 -- H.4(12). Restriction_Warnings never affects generated code
8837 -- so this is done only in the real restriction case.
8839 -- Atomic_Synchronization is not a real check, so it is not
8840 -- affected by this processing).
8842 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
8843 -- run-time checks in CodePeer and GNATprove modes: we want to
8844 -- generate checks for analysis purposes, as set respectively
8845 -- by -gnatC and -gnatd.F
8847 if not Warn
8848 and then not (CodePeer_Mode or GNATprove_Mode)
8849 and then R_Id = No_Exceptions
8850 then
8851 for J in Scope_Suppress.Suppress'Range loop
8852 if J /= Atomic_Synchronization then
8853 Scope_Suppress.Suppress (J) := True;
8854 end if;
8855 end loop;
8856 end if;
8858 -- Case of No_Dependence => unit-name. Note that the parser
8859 -- already made the necessary entry in the No_Dependence table.
8861 elsif Id = Name_No_Dependence then
8862 if not OK_No_Dependence_Unit_Name (Expr) then
8863 raise Pragma_Exit;
8864 end if;
8866 -- Case of No_Specification_Of_Aspect => aspect-identifier
8868 elsif Id = Name_No_Specification_Of_Aspect then
8869 declare
8870 A_Id : Aspect_Id;
8872 begin
8873 if Nkind (Expr) /= N_Identifier then
8874 A_Id := No_Aspect;
8875 else
8876 A_Id := Get_Aspect_Id (Chars (Expr));
8877 end if;
8879 if A_Id = No_Aspect then
8880 Error_Pragma_Arg ("invalid restriction name", Arg);
8881 else
8882 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
8883 end if;
8884 end;
8886 -- Case of No_Use_Of_Attribute => attribute-identifier
8888 elsif Id = Name_No_Use_Of_Attribute then
8889 if Nkind (Expr) /= N_Identifier
8890 or else not Is_Attribute_Name (Chars (Expr))
8891 then
8892 Error_Msg_N ("unknown attribute name??", Expr);
8894 else
8895 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
8896 end if;
8898 -- Case of No_Use_Of_Entity => fully-qualified-name
8900 elsif Id = Name_No_Use_Of_Entity then
8902 -- Restriction is only recognized within a configuration
8903 -- pragma file, or within a unit of the main extended
8904 -- program. Note: the test for Main_Unit is needed to
8905 -- properly include the case of configuration pragma files.
8907 if Current_Sem_Unit = Main_Unit
8908 or else In_Extended_Main_Source_Unit (N)
8909 then
8910 if not OK_No_Dependence_Unit_Name (Expr) then
8911 Error_Msg_N ("wrong form for entity name", Expr);
8912 else
8913 Set_Restriction_No_Use_Of_Entity
8914 (Expr, Warn, No_Profile);
8915 end if;
8916 end if;
8918 -- Case of No_Use_Of_Pragma => pragma-identifier
8920 elsif Id = Name_No_Use_Of_Pragma then
8921 if Nkind (Expr) /= N_Identifier
8922 or else not Is_Pragma_Name (Chars (Expr))
8923 then
8924 Error_Msg_N ("unknown pragma name??", Expr);
8925 else
8926 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
8927 end if;
8929 -- All other cases of restriction identifier present
8931 else
8932 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
8933 Analyze_And_Resolve (Expr, Any_Integer);
8935 if R_Id not in All_Parameter_Restrictions then
8936 Error_Pragma_Arg
8937 ("invalid restriction parameter identifier", Arg);
8939 elsif not Is_OK_Static_Expression (Expr) then
8940 Flag_Non_Static_Expr
8941 ("value must be static expression!", Expr);
8942 raise Pragma_Exit;
8944 elsif not Is_Integer_Type (Etype (Expr))
8945 or else Expr_Value (Expr) < 0
8946 then
8947 Error_Pragma_Arg
8948 ("value must be non-negative integer", Arg);
8949 end if;
8951 -- Restriction pragma is active
8953 Val := Expr_Value (Expr);
8955 if not UI_Is_In_Int_Range (Val) then
8956 Error_Pragma_Arg
8957 ("pragma ignored, value too large??", Arg);
8958 end if;
8960 -- Warning case. If the real restriction is active, then we
8961 -- ignore the request, since warning never overrides a real
8962 -- restriction. Otherwise we set the proper warning. Note that
8963 -- this circuit sets the warning again if it is already set,
8964 -- which is what we want, since the constant may have changed.
8966 if Warn then
8967 if not Restriction_Active (R_Id) then
8968 Set_Restriction
8969 (R_Id, N, Integer (UI_To_Int (Val)));
8970 Restriction_Warnings (R_Id) := True;
8971 end if;
8973 -- Real restriction case, set restriction and make sure warning
8974 -- flag is off since real restriction always overrides warning.
8976 else
8977 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
8978 Restriction_Warnings (R_Id) := False;
8979 end if;
8980 end if;
8982 Next (Arg);
8983 end loop;
8984 end Process_Restrictions_Or_Restriction_Warnings;
8986 ---------------------------------
8987 -- Process_Suppress_Unsuppress --
8988 ---------------------------------
8990 -- Note: this procedure makes entries in the check suppress data
8991 -- structures managed by Sem. See spec of package Sem for full
8992 -- details on how we handle recording of check suppression.
8994 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
8995 C : Check_Id;
8996 E_Id : Node_Id;
8997 E : Entity_Id;
8999 In_Package_Spec : constant Boolean :=
9000 Is_Package_Or_Generic_Package (Current_Scope)
9001 and then not In_Package_Body (Current_Scope);
9003 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
9004 -- Used to suppress a single check on the given entity
9006 --------------------------------
9007 -- Suppress_Unsuppress_Echeck --
9008 --------------------------------
9010 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
9011 begin
9012 -- Check for error of trying to set atomic synchronization for
9013 -- a non-atomic variable.
9015 if C = Atomic_Synchronization
9016 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
9017 then
9018 Error_Msg_N
9019 ("pragma & requires atomic type or variable",
9020 Pragma_Identifier (Original_Node (N)));
9021 end if;
9023 Set_Checks_May_Be_Suppressed (E);
9025 if In_Package_Spec then
9026 Push_Global_Suppress_Stack_Entry
9027 (Entity => E,
9028 Check => C,
9029 Suppress => Suppress_Case);
9030 else
9031 Push_Local_Suppress_Stack_Entry
9032 (Entity => E,
9033 Check => C,
9034 Suppress => Suppress_Case);
9035 end if;
9037 -- If this is a first subtype, and the base type is distinct,
9038 -- then also set the suppress flags on the base type.
9040 if Is_First_Subtype (E) and then Etype (E) /= E then
9041 Suppress_Unsuppress_Echeck (Etype (E), C);
9042 end if;
9043 end Suppress_Unsuppress_Echeck;
9045 -- Start of processing for Process_Suppress_Unsuppress
9047 begin
9048 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
9049 -- on user code: we want to generate checks for analysis purposes, as
9050 -- set respectively by -gnatC and -gnatd.F
9052 if (CodePeer_Mode or GNATprove_Mode)
9053 and then Comes_From_Source (N)
9054 then
9055 return;
9056 end if;
9058 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
9059 -- declarative part or a package spec (RM 11.5(5)).
9061 if not Is_Configuration_Pragma then
9062 Check_Is_In_Decl_Part_Or_Package_Spec;
9063 end if;
9065 Check_At_Least_N_Arguments (1);
9066 Check_At_Most_N_Arguments (2);
9067 Check_No_Identifier (Arg1);
9068 Check_Arg_Is_Identifier (Arg1);
9070 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
9072 if C = No_Check_Id then
9073 Error_Pragma_Arg
9074 ("argument of pragma% is not valid check name", Arg1);
9075 end if;
9077 -- Warn that suppress of Elaboration_Check has no effect in SPARK
9079 if C = Elaboration_Check and then SPARK_Mode = On then
9080 Error_Pragma_Arg
9081 ("Suppress of Elaboration_Check ignored in SPARK??",
9082 "\elaboration checking rules are statically enforced "
9083 & "(SPARK RM 7.7)", Arg1);
9084 end if;
9086 -- One-argument case
9088 if Arg_Count = 1 then
9090 -- Make an entry in the local scope suppress table. This is the
9091 -- table that directly shows the current value of the scope
9092 -- suppress check for any check id value.
9094 if C = All_Checks then
9096 -- For All_Checks, we set all specific predefined checks with
9097 -- the exception of Elaboration_Check, which is handled
9098 -- specially because of not wanting All_Checks to have the
9099 -- effect of deactivating static elaboration order processing.
9100 -- Atomic_Synchronization is also not affected, since this is
9101 -- not a real check.
9103 for J in Scope_Suppress.Suppress'Range loop
9104 if J /= Elaboration_Check
9105 and then
9106 J /= Atomic_Synchronization
9107 then
9108 Scope_Suppress.Suppress (J) := Suppress_Case;
9109 end if;
9110 end loop;
9112 -- If not All_Checks, and predefined check, then set appropriate
9113 -- scope entry. Note that we will set Elaboration_Check if this
9114 -- is explicitly specified. Atomic_Synchronization is allowed
9115 -- only if internally generated and entity is atomic.
9117 elsif C in Predefined_Check_Id
9118 and then (not Comes_From_Source (N)
9119 or else C /= Atomic_Synchronization)
9120 then
9121 Scope_Suppress.Suppress (C) := Suppress_Case;
9122 end if;
9124 -- Also make an entry in the Local_Entity_Suppress table
9126 Push_Local_Suppress_Stack_Entry
9127 (Entity => Empty,
9128 Check => C,
9129 Suppress => Suppress_Case);
9131 -- Case of two arguments present, where the check is suppressed for
9132 -- a specified entity (given as the second argument of the pragma)
9134 else
9135 -- This is obsolescent in Ada 2005 mode
9137 if Ada_Version >= Ada_2005 then
9138 Check_Restriction (No_Obsolescent_Features, Arg2);
9139 end if;
9141 Check_Optional_Identifier (Arg2, Name_On);
9142 E_Id := Get_Pragma_Arg (Arg2);
9143 Analyze (E_Id);
9145 if not Is_Entity_Name (E_Id) then
9146 Error_Pragma_Arg
9147 ("second argument of pragma% must be entity name", Arg2);
9148 end if;
9150 E := Entity (E_Id);
9152 if E = Any_Id then
9153 return;
9154 end if;
9156 -- Enforce RM 11.5(7) which requires that for a pragma that
9157 -- appears within a package spec, the named entity must be
9158 -- within the package spec. We allow the package name itself
9159 -- to be mentioned since that makes sense, although it is not
9160 -- strictly allowed by 11.5(7).
9162 if In_Package_Spec
9163 and then E /= Current_Scope
9164 and then Scope (E) /= Current_Scope
9165 then
9166 Error_Pragma_Arg
9167 ("entity in pragma% is not in package spec (RM 11.5(7))",
9168 Arg2);
9169 end if;
9171 -- Loop through homonyms. As noted below, in the case of a package
9172 -- spec, only homonyms within the package spec are considered.
9174 loop
9175 Suppress_Unsuppress_Echeck (E, C);
9177 if Is_Generic_Instance (E)
9178 and then Is_Subprogram (E)
9179 and then Present (Alias (E))
9180 then
9181 Suppress_Unsuppress_Echeck (Alias (E), C);
9182 end if;
9184 -- Move to next homonym if not aspect spec case
9186 exit when From_Aspect_Specification (N);
9187 E := Homonym (E);
9188 exit when No (E);
9190 -- If we are within a package specification, the pragma only
9191 -- applies to homonyms in the same scope.
9193 exit when In_Package_Spec
9194 and then Scope (E) /= Current_Scope;
9195 end loop;
9196 end if;
9197 end Process_Suppress_Unsuppress;
9199 ------------------
9200 -- Set_Exported --
9201 ------------------
9203 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
9204 begin
9205 if Is_Imported (E) then
9206 Error_Pragma_Arg
9207 ("cannot export entity& that was previously imported", Arg);
9209 elsif Present (Address_Clause (E))
9210 and then not Relaxed_RM_Semantics
9211 then
9212 Error_Pragma_Arg
9213 ("cannot export entity& that has an address clause", Arg);
9214 end if;
9216 Set_Is_Exported (E);
9218 -- Generate a reference for entity explicitly, because the
9219 -- identifier may be overloaded and name resolution will not
9220 -- generate one.
9222 Generate_Reference (E, Arg);
9224 -- Deal with exporting non-library level entity
9226 if not Is_Library_Level_Entity (E) then
9228 -- Not allowed at all for subprograms
9230 if Is_Subprogram (E) then
9231 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
9233 -- Otherwise set public and statically allocated
9235 else
9236 Set_Is_Public (E);
9237 Set_Is_Statically_Allocated (E);
9239 -- Warn if the corresponding W flag is set
9241 if Warn_On_Export_Import
9243 -- Only do this for something that was in the source. Not
9244 -- clear if this can be False now (there used for sure to be
9245 -- cases on some systems where it was False), but anyway the
9246 -- test is harmless if not needed, so it is retained.
9248 and then Comes_From_Source (Arg)
9249 then
9250 Error_Msg_NE
9251 ("?x?& has been made static as a result of Export",
9252 Arg, E);
9253 Error_Msg_N
9254 ("\?x?this usage is non-standard and non-portable",
9255 Arg);
9256 end if;
9257 end if;
9258 end if;
9260 if Warn_On_Export_Import and then Is_Type (E) then
9261 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
9262 end if;
9264 if Warn_On_Export_Import and Inside_A_Generic then
9265 Error_Msg_NE
9266 ("all instances of& will have the same external name?x?",
9267 Arg, E);
9268 end if;
9269 end Set_Exported;
9271 ----------------------------------------------
9272 -- Set_Extended_Import_Export_External_Name --
9273 ----------------------------------------------
9275 procedure Set_Extended_Import_Export_External_Name
9276 (Internal_Ent : Entity_Id;
9277 Arg_External : Node_Id)
9279 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
9280 New_Name : Node_Id;
9282 begin
9283 if No (Arg_External) then
9284 return;
9285 end if;
9287 Check_Arg_Is_External_Name (Arg_External);
9289 if Nkind (Arg_External) = N_String_Literal then
9290 if String_Length (Strval (Arg_External)) = 0 then
9291 return;
9292 else
9293 New_Name := Adjust_External_Name_Case (Arg_External);
9294 end if;
9296 elsif Nkind (Arg_External) = N_Identifier then
9297 New_Name := Get_Default_External_Name (Arg_External);
9299 -- Check_Arg_Is_External_Name should let through only identifiers and
9300 -- string literals or static string expressions (which are folded to
9301 -- string literals).
9303 else
9304 raise Program_Error;
9305 end if;
9307 -- If we already have an external name set (by a prior normal Import
9308 -- or Export pragma), then the external names must match
9310 if Present (Interface_Name (Internal_Ent)) then
9312 -- Ignore mismatching names in CodePeer mode, to support some
9313 -- old compilers which would export the same procedure under
9314 -- different names, e.g:
9315 -- procedure P;
9316 -- pragma Export_Procedure (P, "a");
9317 -- pragma Export_Procedure (P, "b");
9319 if CodePeer_Mode then
9320 return;
9321 end if;
9323 Check_Matching_Internal_Names : declare
9324 S1 : constant String_Id := Strval (Old_Name);
9325 S2 : constant String_Id := Strval (New_Name);
9327 procedure Mismatch;
9328 pragma No_Return (Mismatch);
9329 -- Called if names do not match
9331 --------------
9332 -- Mismatch --
9333 --------------
9335 procedure Mismatch is
9336 begin
9337 Error_Msg_Sloc := Sloc (Old_Name);
9338 Error_Pragma_Arg
9339 ("external name does not match that given #",
9340 Arg_External);
9341 end Mismatch;
9343 -- Start of processing for Check_Matching_Internal_Names
9345 begin
9346 if String_Length (S1) /= String_Length (S2) then
9347 Mismatch;
9349 else
9350 for J in 1 .. String_Length (S1) loop
9351 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
9352 Mismatch;
9353 end if;
9354 end loop;
9355 end if;
9356 end Check_Matching_Internal_Names;
9358 -- Otherwise set the given name
9360 else
9361 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
9362 Check_Duplicated_Export_Name (New_Name);
9363 end if;
9364 end Set_Extended_Import_Export_External_Name;
9366 ------------------
9367 -- Set_Imported --
9368 ------------------
9370 procedure Set_Imported (E : Entity_Id) is
9371 begin
9372 -- Error message if already imported or exported
9374 if Is_Exported (E) or else Is_Imported (E) then
9376 -- Error if being set Exported twice
9378 if Is_Exported (E) then
9379 Error_Msg_NE ("entity& was previously exported", N, E);
9381 -- Ignore error in CodePeer mode where we treat all imported
9382 -- subprograms as unknown.
9384 elsif CodePeer_Mode then
9385 goto OK;
9387 -- OK if Import/Interface case
9389 elsif Import_Interface_Present (N) then
9390 goto OK;
9392 -- Error if being set Imported twice
9394 else
9395 Error_Msg_NE ("entity& was previously imported", N, E);
9396 end if;
9398 Error_Msg_Name_1 := Pname;
9399 Error_Msg_N
9400 ("\(pragma% applies to all previous entities)", N);
9402 Error_Msg_Sloc := Sloc (E);
9403 Error_Msg_NE ("\import not allowed for& declared#", N, E);
9405 -- Here if not previously imported or exported, OK to import
9407 else
9408 Set_Is_Imported (E);
9410 -- For subprogram, set Import_Pragma field
9412 if Is_Subprogram (E) then
9413 Set_Import_Pragma (E, N);
9414 end if;
9416 -- If the entity is an object that is not at the library level,
9417 -- then it is statically allocated. We do not worry about objects
9418 -- with address clauses in this context since they are not really
9419 -- imported in the linker sense.
9421 if Is_Object (E)
9422 and then not Is_Library_Level_Entity (E)
9423 and then No (Address_Clause (E))
9424 then
9425 Set_Is_Statically_Allocated (E);
9426 end if;
9427 end if;
9429 <<OK>> null;
9430 end Set_Imported;
9432 -------------------------
9433 -- Set_Mechanism_Value --
9434 -------------------------
9436 -- Note: the mechanism name has not been analyzed (and cannot indeed be
9437 -- analyzed, since it is semantic nonsense), so we get it in the exact
9438 -- form created by the parser.
9440 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
9441 procedure Bad_Mechanism;
9442 pragma No_Return (Bad_Mechanism);
9443 -- Signal bad mechanism name
9445 -------------------------
9446 -- Bad_Mechanism_Value --
9447 -------------------------
9449 procedure Bad_Mechanism is
9450 begin
9451 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
9452 end Bad_Mechanism;
9454 -- Start of processing for Set_Mechanism_Value
9456 begin
9457 if Mechanism (Ent) /= Default_Mechanism then
9458 Error_Msg_NE
9459 ("mechanism for & has already been set", Mech_Name, Ent);
9460 end if;
9462 -- MECHANISM_NAME ::= value | reference
9464 if Nkind (Mech_Name) = N_Identifier then
9465 if Chars (Mech_Name) = Name_Value then
9466 Set_Mechanism (Ent, By_Copy);
9467 return;
9469 elsif Chars (Mech_Name) = Name_Reference then
9470 Set_Mechanism (Ent, By_Reference);
9471 return;
9473 elsif Chars (Mech_Name) = Name_Copy then
9474 Error_Pragma_Arg
9475 ("bad mechanism name, Value assumed", Mech_Name);
9477 else
9478 Bad_Mechanism;
9479 end if;
9481 else
9482 Bad_Mechanism;
9483 end if;
9484 end Set_Mechanism_Value;
9486 --------------------------
9487 -- Set_Rational_Profile --
9488 --------------------------
9490 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
9491 -- and extension to the semantics of renaming declarations.
9493 procedure Set_Rational_Profile is
9494 begin
9495 Implicit_Packing := True;
9496 Overriding_Renamings := True;
9497 Use_VADS_Size := True;
9498 end Set_Rational_Profile;
9500 ---------------------------
9501 -- Set_Ravenscar_Profile --
9502 ---------------------------
9504 -- The tasks to be done here are
9506 -- Set required policies
9508 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9509 -- pragma Locking_Policy (Ceiling_Locking)
9511 -- Set Detect_Blocking mode
9513 -- Set required restrictions (see System.Rident for detailed list)
9515 -- Set the No_Dependence rules
9516 -- No_Dependence => Ada.Asynchronous_Task_Control
9517 -- No_Dependence => Ada.Calendar
9518 -- No_Dependence => Ada.Execution_Time.Group_Budget
9519 -- No_Dependence => Ada.Execution_Time.Timers
9520 -- No_Dependence => Ada.Task_Attributes
9521 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9523 procedure Set_Ravenscar_Profile (N : Node_Id) is
9524 Prefix_Entity : Entity_Id;
9525 Selector_Entity : Entity_Id;
9526 Prefix_Node : Node_Id;
9527 Node : Node_Id;
9529 begin
9530 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9532 if Task_Dispatching_Policy /= ' '
9533 and then Task_Dispatching_Policy /= 'F'
9534 then
9535 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9536 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
9538 -- Set the FIFO_Within_Priorities policy, but always preserve
9539 -- System_Location since we like the error message with the run time
9540 -- name.
9542 else
9543 Task_Dispatching_Policy := 'F';
9545 if Task_Dispatching_Policy_Sloc /= System_Location then
9546 Task_Dispatching_Policy_Sloc := Loc;
9547 end if;
9548 end if;
9550 -- pragma Locking_Policy (Ceiling_Locking)
9552 if Locking_Policy /= ' '
9553 and then Locking_Policy /= 'C'
9554 then
9555 Error_Msg_Sloc := Locking_Policy_Sloc;
9556 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
9558 -- Set the Ceiling_Locking policy, but preserve System_Location since
9559 -- we like the error message with the run time name.
9561 else
9562 Locking_Policy := 'C';
9564 if Locking_Policy_Sloc /= System_Location then
9565 Locking_Policy_Sloc := Loc;
9566 end if;
9567 end if;
9569 -- pragma Detect_Blocking
9571 Detect_Blocking := True;
9573 -- Set the corresponding restrictions
9575 Set_Profile_Restrictions
9576 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
9578 -- Set the No_Dependence restrictions
9580 -- The following No_Dependence restrictions:
9581 -- No_Dependence => Ada.Asynchronous_Task_Control
9582 -- No_Dependence => Ada.Calendar
9583 -- No_Dependence => Ada.Task_Attributes
9584 -- are already set by previous call to Set_Profile_Restrictions.
9586 -- Set the following restrictions which were added to Ada 2005:
9587 -- No_Dependence => Ada.Execution_Time.Group_Budget
9588 -- No_Dependence => Ada.Execution_Time.Timers
9590 if Ada_Version >= Ada_2005 then
9591 Name_Buffer (1 .. 3) := "ada";
9592 Name_Len := 3;
9594 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9596 Name_Buffer (1 .. 14) := "execution_time";
9597 Name_Len := 14;
9599 Selector_Entity := Make_Identifier (Loc, Name_Find);
9601 Prefix_Node :=
9602 Make_Selected_Component
9603 (Sloc => Loc,
9604 Prefix => Prefix_Entity,
9605 Selector_Name => Selector_Entity);
9607 Name_Buffer (1 .. 13) := "group_budgets";
9608 Name_Len := 13;
9610 Selector_Entity := Make_Identifier (Loc, Name_Find);
9612 Node :=
9613 Make_Selected_Component
9614 (Sloc => Loc,
9615 Prefix => Prefix_Node,
9616 Selector_Name => Selector_Entity);
9618 Set_Restriction_No_Dependence
9619 (Unit => Node,
9620 Warn => Treat_Restrictions_As_Warnings,
9621 Profile => Ravenscar);
9623 Name_Buffer (1 .. 6) := "timers";
9624 Name_Len := 6;
9626 Selector_Entity := Make_Identifier (Loc, Name_Find);
9628 Node :=
9629 Make_Selected_Component
9630 (Sloc => Loc,
9631 Prefix => Prefix_Node,
9632 Selector_Name => Selector_Entity);
9634 Set_Restriction_No_Dependence
9635 (Unit => Node,
9636 Warn => Treat_Restrictions_As_Warnings,
9637 Profile => Ravenscar);
9638 end if;
9640 -- Set the following restrictions which was added to Ada 2012 (see
9641 -- AI-0171):
9642 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9644 if Ada_Version >= Ada_2012 then
9645 Name_Buffer (1 .. 6) := "system";
9646 Name_Len := 6;
9648 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9650 Name_Buffer (1 .. 15) := "multiprocessors";
9651 Name_Len := 15;
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 .. 19) := "dispatching_domains";
9662 Name_Len := 19;
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);
9676 end if;
9677 end Set_Ravenscar_Profile;
9679 -- Start of processing for Analyze_Pragma
9681 begin
9682 -- The following code is a defense against recursion. Not clear that
9683 -- this can happen legitimately, but perhaps some error situations
9684 -- can cause it, and we did see this recursion during testing.
9686 if Analyzed (N) then
9687 return;
9688 else
9689 Set_Analyzed (N, True);
9690 end if;
9692 -- Deal with unrecognized pragma
9694 Pname := Pragma_Name (N);
9696 if not Is_Pragma_Name (Pname) then
9697 if Warn_On_Unrecognized_Pragma then
9698 Error_Msg_Name_1 := Pname;
9699 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
9701 for PN in First_Pragma_Name .. Last_Pragma_Name loop
9702 if Is_Bad_Spelling_Of (Pname, PN) then
9703 Error_Msg_Name_1 := PN;
9704 Error_Msg_N -- CODEFIX
9705 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
9706 exit;
9707 end if;
9708 end loop;
9709 end if;
9711 return;
9712 end if;
9714 -- Here to start processing for recognized pragma
9716 Prag_Id := Get_Pragma_Id (Pname);
9717 Pname := Original_Aspect_Name (N);
9719 -- Capture setting of Opt.Uneval_Old
9721 case Opt.Uneval_Old is
9722 when 'A' =>
9723 Set_Uneval_Old_Accept (N);
9724 when 'E' =>
9725 null;
9726 when 'W' =>
9727 Set_Uneval_Old_Warn (N);
9728 when others =>
9729 raise Program_Error;
9730 end case;
9732 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
9733 -- is already set, indicating that we have already checked the policy
9734 -- at the right point. This happens for example in the case of a pragma
9735 -- that is derived from an Aspect.
9737 if Is_Ignored (N) or else Is_Checked (N) then
9738 null;
9740 -- For a pragma that is a rewriting of another pragma, copy the
9741 -- Is_Checked/Is_Ignored status from the rewritten pragma.
9743 elsif Is_Rewrite_Substitution (N)
9744 and then Nkind (Original_Node (N)) = N_Pragma
9745 and then Original_Node (N) /= N
9746 then
9747 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
9748 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
9750 -- Otherwise query the applicable policy at this point
9752 else
9753 Check_Applicable_Policy (N);
9755 -- If pragma is disabled, rewrite as NULL and skip analysis
9757 if Is_Disabled (N) then
9758 Rewrite (N, Make_Null_Statement (Loc));
9759 Analyze (N);
9760 raise Pragma_Exit;
9761 end if;
9762 end if;
9764 -- Preset arguments
9766 Arg_Count := 0;
9767 Arg1 := Empty;
9768 Arg2 := Empty;
9769 Arg3 := Empty;
9770 Arg4 := Empty;
9772 if Present (Pragma_Argument_Associations (N)) then
9773 Arg_Count := List_Length (Pragma_Argument_Associations (N));
9774 Arg1 := First (Pragma_Argument_Associations (N));
9776 if Present (Arg1) then
9777 Arg2 := Next (Arg1);
9779 if Present (Arg2) then
9780 Arg3 := Next (Arg2);
9782 if Present (Arg3) then
9783 Arg4 := Next (Arg3);
9784 end if;
9785 end if;
9786 end if;
9787 end if;
9789 Check_Restriction_No_Use_Of_Pragma (N);
9791 -- An enumeration type defines the pragmas that are supported by the
9792 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
9793 -- into the corresponding enumeration value for the following case.
9795 case Prag_Id is
9797 -----------------
9798 -- Abort_Defer --
9799 -----------------
9801 -- pragma Abort_Defer;
9803 when Pragma_Abort_Defer =>
9804 GNAT_Pragma;
9805 Check_Arg_Count (0);
9807 -- The only required semantic processing is to check the
9808 -- placement. This pragma must appear at the start of the
9809 -- statement sequence of a handled sequence of statements.
9811 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
9812 or else N /= First (Statements (Parent (N)))
9813 then
9814 Pragma_Misplaced;
9815 end if;
9817 --------------------
9818 -- Abstract_State --
9819 --------------------
9821 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
9823 -- ABSTRACT_STATE_LIST ::=
9824 -- null
9825 -- | STATE_NAME_WITH_OPTIONS
9826 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS} )
9828 -- STATE_NAME_WITH_OPTIONS ::=
9829 -- STATE_NAME
9830 -- | (STATE_NAME with OPTION_LIST)
9832 -- OPTION_LIST ::= OPTION {, OPTION}
9834 -- OPTION ::=
9835 -- SIMPLE_OPTION
9836 -- | NAME_VALUE_OPTION
9838 -- SIMPLE_OPTION ::= Ghost
9840 -- NAME_VALUE_OPTION ::=
9841 -- Part_Of => ABSTRACT_STATE
9842 -- | External [=> EXTERNAL_PROPERTY_LIST]
9844 -- EXTERNAL_PROPERTY_LIST ::=
9845 -- EXTERNAL_PROPERTY
9846 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY} )
9848 -- EXTERNAL_PROPERTY ::=
9849 -- Async_Readers [=> boolean_EXPRESSION]
9850 -- | Async_Writers [=> boolean_EXPRESSION]
9851 -- | Effective_Reads [=> boolean_EXPRESSION]
9852 -- | Effective_Writes [=> boolean_EXPRESSION]
9853 -- others => boolean_EXPRESSION
9855 -- STATE_NAME ::= defining_identifier
9857 -- ABSTRACT_STATE ::= name
9859 when Pragma_Abstract_State => Abstract_State : declare
9860 Missing_Parentheses : Boolean := False;
9861 -- Flag set when a state declaration with options is not properly
9862 -- parenthesized.
9864 -- Flags used to verify the consistency of states
9866 Non_Null_Seen : Boolean := False;
9867 Null_Seen : Boolean := False;
9869 procedure Analyze_Abstract_State
9870 (State : Node_Id;
9871 Pack_Id : Entity_Id);
9872 -- Verify the legality of a single state declaration. Create and
9873 -- decorate a state abstraction entity and introduce it into the
9874 -- visibility chain. Pack_Id denotes the entity or the related
9875 -- package where pragma Abstract_State appears.
9877 ----------------------------
9878 -- Analyze_Abstract_State --
9879 ----------------------------
9881 procedure Analyze_Abstract_State
9882 (State : Node_Id;
9883 Pack_Id : Entity_Id)
9885 -- Flags used to verify the consistency of options
9887 AR_Seen : Boolean := False;
9888 AW_Seen : Boolean := False;
9889 ER_Seen : Boolean := False;
9890 EW_Seen : Boolean := False;
9891 External_Seen : Boolean := False;
9892 Others_Seen : Boolean := False;
9893 Part_Of_Seen : Boolean := False;
9895 -- Flags used to store the static value of all external states'
9896 -- expressions.
9898 AR_Val : Boolean := False;
9899 AW_Val : Boolean := False;
9900 ER_Val : Boolean := False;
9901 EW_Val : Boolean := False;
9903 State_Id : Entity_Id := Empty;
9904 -- The entity to be generated for the current state declaration
9906 procedure Analyze_External_Option (Opt : Node_Id);
9907 -- Verify the legality of option External
9909 procedure Analyze_External_Property
9910 (Prop : Node_Id;
9911 Expr : Node_Id := Empty);
9912 -- Verify the legailty of a single external property. Prop
9913 -- denotes the external property. Expr is the expression used
9914 -- to set the property.
9916 procedure Analyze_Part_Of_Option (Opt : Node_Id);
9917 -- Verify the legality of option Part_Of
9919 procedure Check_Duplicate_Option
9920 (Opt : Node_Id;
9921 Status : in out Boolean);
9922 -- Flag Status denotes whether a particular option has been
9923 -- seen while processing a state. This routine verifies that
9924 -- Opt is not a duplicate option and sets the flag Status
9925 -- (SPARK RM 7.1.4(1)).
9927 procedure Check_Duplicate_Property
9928 (Prop : Node_Id;
9929 Status : in out Boolean);
9930 -- Flag Status denotes whether a particular property has been
9931 -- seen while processing option External. This routine verifies
9932 -- that Prop is not a duplicate property and sets flag Status.
9933 -- Opt is not a duplicate property and sets the flag Status.
9934 -- (SPARK RM 7.1.4(2))
9936 procedure Create_Abstract_State
9937 (Nam : Name_Id;
9938 Decl : Node_Id;
9939 Loc : Source_Ptr;
9940 Is_Null : Boolean);
9941 -- Generate an abstract state entity with name Nam and enter it
9942 -- into visibility. Decl is the "declaration" of the state as
9943 -- it appears in pragma Abstract_State. Loc is the location of
9944 -- the related state "declaration". Flag Is_Null should be set
9945 -- when the associated Abstract_State pragma defines a null
9946 -- state.
9948 -----------------------------
9949 -- Analyze_External_Option --
9950 -----------------------------
9952 procedure Analyze_External_Option (Opt : Node_Id) is
9953 Errors : constant Nat := Serious_Errors_Detected;
9954 Prop : Node_Id;
9955 Props : Node_Id := Empty;
9957 begin
9958 Check_Duplicate_Option (Opt, External_Seen);
9960 if Nkind (Opt) = N_Component_Association then
9961 Props := Expression (Opt);
9962 end if;
9964 -- External state with properties
9966 if Present (Props) then
9968 -- Multiple properties appear as an aggregate
9970 if Nkind (Props) = N_Aggregate then
9972 -- Simple property form
9974 Prop := First (Expressions (Props));
9975 while Present (Prop) loop
9976 Analyze_External_Property (Prop);
9977 Next (Prop);
9978 end loop;
9980 -- Property with expression form
9982 Prop := First (Component_Associations (Props));
9983 while Present (Prop) loop
9984 Analyze_External_Property
9985 (Prop => First (Choices (Prop)),
9986 Expr => Expression (Prop));
9988 Next (Prop);
9989 end loop;
9991 -- Single property
9993 else
9994 Analyze_External_Property (Props);
9995 end if;
9997 -- An external state defined without any properties defaults
9998 -- all properties to True.
10000 else
10001 AR_Val := True;
10002 AW_Val := True;
10003 ER_Val := True;
10004 EW_Val := True;
10005 end if;
10007 -- Once all external properties have been processed, verify
10008 -- their mutual interaction. Do not perform the check when
10009 -- at least one of the properties is illegal as this will
10010 -- produce a bogus error.
10012 if Errors = Serious_Errors_Detected then
10013 Check_External_Properties
10014 (State, AR_Val, AW_Val, ER_Val, EW_Val);
10015 end if;
10016 end Analyze_External_Option;
10018 -------------------------------
10019 -- Analyze_External_Property --
10020 -------------------------------
10022 procedure Analyze_External_Property
10023 (Prop : Node_Id;
10024 Expr : Node_Id := Empty)
10026 Expr_Val : Boolean;
10028 begin
10029 -- Check the placement of "others" (if available)
10031 if Nkind (Prop) = N_Others_Choice then
10032 if Others_Seen then
10033 SPARK_Msg_N
10034 ("only one others choice allowed in option External",
10035 Prop);
10036 else
10037 Others_Seen := True;
10038 end if;
10040 elsif Others_Seen then
10041 SPARK_Msg_N
10042 ("others must be the last property in option External",
10043 Prop);
10045 -- The only remaining legal options are the four predefined
10046 -- external properties.
10048 elsif Nkind (Prop) = N_Identifier
10049 and then Nam_In (Chars (Prop), Name_Async_Readers,
10050 Name_Async_Writers,
10051 Name_Effective_Reads,
10052 Name_Effective_Writes)
10053 then
10054 null;
10056 -- Otherwise the construct is not a valid property
10058 else
10059 SPARK_Msg_N ("invalid external state property", Prop);
10060 return;
10061 end if;
10063 -- Ensure that the expression of the external state property
10064 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
10066 if Present (Expr) then
10067 Analyze_And_Resolve (Expr, Standard_Boolean);
10069 if Is_OK_Static_Expression (Expr) then
10070 Expr_Val := Is_True (Expr_Value (Expr));
10071 else
10072 SPARK_Msg_N
10073 ("expression of external state property must be "
10074 & "static", Expr);
10075 end if;
10077 -- The lack of expression defaults the property to True
10079 else
10080 Expr_Val := True;
10081 end if;
10083 -- Named properties
10085 if Nkind (Prop) = N_Identifier then
10086 if Chars (Prop) = Name_Async_Readers then
10087 Check_Duplicate_Property (Prop, AR_Seen);
10088 AR_Val := Expr_Val;
10090 elsif Chars (Prop) = Name_Async_Writers then
10091 Check_Duplicate_Property (Prop, AW_Seen);
10092 AW_Val := Expr_Val;
10094 elsif Chars (Prop) = Name_Effective_Reads then
10095 Check_Duplicate_Property (Prop, ER_Seen);
10096 ER_Val := Expr_Val;
10098 else
10099 Check_Duplicate_Property (Prop, EW_Seen);
10100 EW_Val := Expr_Val;
10101 end if;
10103 -- The handling of property "others" must take into account
10104 -- all other named properties that have been encountered so
10105 -- far. Only those that have not been seen are affected by
10106 -- "others".
10108 else
10109 if not AR_Seen then
10110 AR_Val := Expr_Val;
10111 end if;
10113 if not AW_Seen then
10114 AW_Val := Expr_Val;
10115 end if;
10117 if not ER_Seen then
10118 ER_Val := Expr_Val;
10119 end if;
10121 if not EW_Seen then
10122 EW_Val := Expr_Val;
10123 end if;
10124 end if;
10125 end Analyze_External_Property;
10127 ----------------------------
10128 -- Analyze_Part_Of_Option --
10129 ----------------------------
10131 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
10132 Encaps : constant Node_Id := Expression (Opt);
10133 Encaps_Id : Entity_Id;
10134 Legal : Boolean;
10136 begin
10137 Check_Duplicate_Option (Opt, Part_Of_Seen);
10139 Analyze_Part_Of
10140 (Item_Id => State_Id,
10141 State => Encaps,
10142 Indic => First (Choices (Opt)),
10143 Legal => Legal);
10145 -- The Part_Of indicator turns an abstract state into a
10146 -- constituent of the encapsulating state.
10148 if Legal then
10149 Encaps_Id := Entity (Encaps);
10151 Append_Elmt (State_Id, Part_Of_Constituents (Encaps_Id));
10152 Set_Encapsulating_State (State_Id, Encaps_Id);
10153 end if;
10154 end Analyze_Part_Of_Option;
10156 ----------------------------
10157 -- Check_Duplicate_Option --
10158 ----------------------------
10160 procedure Check_Duplicate_Option
10161 (Opt : Node_Id;
10162 Status : in out Boolean)
10164 begin
10165 if Status then
10166 SPARK_Msg_N ("duplicate state option", Opt);
10167 end if;
10169 Status := True;
10170 end Check_Duplicate_Option;
10172 ------------------------------
10173 -- Check_Duplicate_Property --
10174 ------------------------------
10176 procedure Check_Duplicate_Property
10177 (Prop : Node_Id;
10178 Status : in out Boolean)
10180 begin
10181 if Status then
10182 SPARK_Msg_N ("duplicate external property", Prop);
10183 end if;
10185 Status := True;
10186 end Check_Duplicate_Property;
10188 ---------------------------
10189 -- Create_Abstract_State --
10190 ---------------------------
10192 procedure Create_Abstract_State
10193 (Nam : Name_Id;
10194 Decl : Node_Id;
10195 Loc : Source_Ptr;
10196 Is_Null : Boolean)
10198 begin
10199 -- The abstract state may be semi-declared when the related
10200 -- package was withed through a limited with clause. In that
10201 -- case reuse the entity to fully declare the state.
10203 if Present (Decl) and then Present (Entity (Decl)) then
10204 State_Id := Entity (Decl);
10206 -- Otherwise the elaboration of pragma Abstract_State
10207 -- declares the state.
10209 else
10210 State_Id := Make_Defining_Identifier (Loc, Nam);
10212 if Present (Decl) then
10213 Set_Entity (Decl, State_Id);
10214 end if;
10215 end if;
10217 -- Null states never come from source
10219 Set_Comes_From_Source (State_Id, not Is_Null);
10220 Set_Parent (State_Id, State);
10221 Set_Ekind (State_Id, E_Abstract_State);
10222 Set_Etype (State_Id, Standard_Void_Type);
10223 Set_Encapsulating_State (State_Id, Empty);
10224 Set_Refinement_Constituents (State_Id, New_Elmt_List);
10225 Set_Part_Of_Constituents (State_Id, New_Elmt_List);
10227 -- An abstract state declared within a Ghost region becomes
10228 -- Ghost (SPARK RM 6.9(2)).
10230 if Ghost_Mode > None then
10231 Set_Is_Ghost_Entity (State_Id);
10232 end if;
10234 -- Establish a link between the state declaration and the
10235 -- abstract state entity. Note that a null state remains as
10236 -- N_Null and does not carry any linkages.
10238 if not Is_Null then
10239 if Present (Decl) then
10240 Set_Entity (Decl, State_Id);
10241 Set_Etype (Decl, Standard_Void_Type);
10242 end if;
10244 -- Every non-null state must be defined, nameable and
10245 -- resolvable.
10247 Push_Scope (Pack_Id);
10248 Generate_Definition (State_Id);
10249 Enter_Name (State_Id);
10250 Pop_Scope;
10251 end if;
10252 end Create_Abstract_State;
10254 -- Local variables
10256 Opt : Node_Id;
10257 Opt_Nam : Node_Id;
10259 -- Start of processing for Analyze_Abstract_State
10261 begin
10262 -- A package with a null abstract state is not allowed to
10263 -- declare additional states.
10265 if Null_Seen then
10266 SPARK_Msg_NE
10267 ("package & has null abstract state", State, Pack_Id);
10269 -- Null states appear as internally generated entities
10271 elsif Nkind (State) = N_Null then
10272 Create_Abstract_State
10273 (Nam => New_Internal_Name ('S'),
10274 Decl => Empty,
10275 Loc => Sloc (State),
10276 Is_Null => True);
10277 Null_Seen := True;
10279 -- Catch a case where a null state appears in a list of
10280 -- non-null states.
10282 if Non_Null_Seen then
10283 SPARK_Msg_NE
10284 ("package & has non-null abstract state",
10285 State, Pack_Id);
10286 end if;
10288 -- Simple state declaration
10290 elsif Nkind (State) = N_Identifier then
10291 Create_Abstract_State
10292 (Nam => Chars (State),
10293 Decl => State,
10294 Loc => Sloc (State),
10295 Is_Null => False);
10296 Non_Null_Seen := True;
10298 -- State declaration with various options. This construct
10299 -- appears as an extension aggregate in the tree.
10301 elsif Nkind (State) = N_Extension_Aggregate then
10302 if Nkind (Ancestor_Part (State)) = N_Identifier then
10303 Create_Abstract_State
10304 (Nam => Chars (Ancestor_Part (State)),
10305 Decl => Ancestor_Part (State),
10306 Loc => Sloc (Ancestor_Part (State)),
10307 Is_Null => False);
10308 Non_Null_Seen := True;
10309 else
10310 SPARK_Msg_N
10311 ("state name must be an identifier",
10312 Ancestor_Part (State));
10313 end if;
10315 -- Options External and Ghost appear as expressions
10317 Opt := First (Expressions (State));
10318 while Present (Opt) loop
10319 if Nkind (Opt) = N_Identifier then
10320 if Chars (Opt) = Name_External then
10321 Analyze_External_Option (Opt);
10323 elsif Chars (Opt) = Name_Ghost then
10324 if Present (State_Id) then
10325 Set_Is_Ghost_Entity (State_Id);
10326 end if;
10328 -- Option Part_Of without an encapsulating state is
10329 -- illegal. (SPARK RM 7.1.4(9)).
10331 elsif Chars (Opt) = Name_Part_Of then
10332 SPARK_Msg_N
10333 ("indicator Part_Of must denote an abstract "
10334 & "state", Opt);
10336 -- Do not emit an error message when a previous state
10337 -- declaration with options was not parenthesized as
10338 -- the option is actually another state declaration.
10340 -- with Abstract_State
10341 -- (State_1 with ..., -- missing parentheses
10342 -- (State_2 with ...),
10343 -- State_3) -- ok state declaration
10345 elsif Missing_Parentheses then
10346 null;
10348 -- Otherwise the option is not allowed. Note that it
10349 -- is not possible to distinguish between an option
10350 -- and a state declaration when a previous state with
10351 -- options not properly parentheses.
10353 -- with Abstract_State
10354 -- (State_1 with ..., -- missing parentheses
10355 -- State_2); -- could be an option
10357 else
10358 SPARK_Msg_N
10359 ("simple option not allowed in state declaration",
10360 Opt);
10361 end if;
10363 -- Catch a case where missing parentheses around a state
10364 -- declaration with options cause a subsequent state
10365 -- declaration with options to be treated as an option.
10367 -- with Abstract_State
10368 -- (State_1 with ..., -- missing parentheses
10369 -- (State_2 with ...))
10371 elsif Nkind (Opt) = N_Extension_Aggregate then
10372 Missing_Parentheses := True;
10373 SPARK_Msg_N
10374 ("state declaration must be parenthesized",
10375 Ancestor_Part (State));
10377 -- Otherwise the option is malformed
10379 else
10380 SPARK_Msg_N ("malformed option", Opt);
10381 end if;
10383 Next (Opt);
10384 end loop;
10386 -- Options External and Part_Of appear as component
10387 -- associations.
10389 Opt := First (Component_Associations (State));
10390 while Present (Opt) loop
10391 Opt_Nam := First (Choices (Opt));
10393 if Nkind (Opt_Nam) = N_Identifier then
10394 if Chars (Opt_Nam) = Name_External then
10395 Analyze_External_Option (Opt);
10397 elsif Chars (Opt_Nam) = Name_Part_Of then
10398 Analyze_Part_Of_Option (Opt);
10400 else
10401 SPARK_Msg_N ("invalid state option", Opt);
10402 end if;
10403 else
10404 SPARK_Msg_N ("invalid state option", Opt);
10405 end if;
10407 Next (Opt);
10408 end loop;
10410 -- Any other attempt to declare a state is illegal. This is a
10411 -- syntax error, always report.
10413 else
10414 Error_Msg_N ("malformed abstract state declaration", State);
10415 return;
10416 end if;
10418 -- Guard against a junk state. In such cases no entity is
10419 -- generated and the subsequent checks cannot be applied.
10421 if Present (State_Id) then
10423 -- Verify whether the state does not introduce an illegal
10424 -- hidden state within a package subject to a null abstract
10425 -- state.
10427 Check_No_Hidden_State (State_Id);
10429 -- Check whether the lack of option Part_Of agrees with the
10430 -- placement of the abstract state with respect to the state
10431 -- space.
10433 if not Part_Of_Seen then
10434 Check_Missing_Part_Of (State_Id);
10435 end if;
10437 -- Associate the state with its related package
10439 if No (Abstract_States (Pack_Id)) then
10440 Set_Abstract_States (Pack_Id, New_Elmt_List);
10441 end if;
10443 Append_Elmt (State_Id, Abstract_States (Pack_Id));
10444 end if;
10445 end Analyze_Abstract_State;
10447 -- Local variables
10449 Context : constant Node_Id := Parent (Parent (N));
10450 Pack_Id : Entity_Id;
10451 State : Node_Id;
10453 -- Start of processing for Abstract_State
10455 begin
10456 GNAT_Pragma;
10457 Check_No_Identifiers;
10458 Check_Arg_Count (1);
10459 Ensure_Aggregate_Form (Arg1);
10461 -- Ensure the proper placement of the pragma. Abstract states must
10462 -- be associated with a package declaration.
10464 if not Nkind_In (Context, N_Generic_Package_Declaration,
10465 N_Package_Declaration)
10466 then
10467 Pragma_Misplaced;
10468 return;
10469 end if;
10471 State := Expression (Arg1);
10472 Pack_Id := Defining_Entity (Context);
10474 -- Mark the associated package as Ghost if it is subject to aspect
10475 -- or pragma Ghost as this affects the declaration of an abstract
10476 -- state.
10478 if Is_Subject_To_Ghost (Unit_Declaration_Node (Pack_Id)) then
10479 Set_Is_Ghost_Entity (Pack_Id);
10480 end if;
10482 -- Multiple non-null abstract states appear as an aggregate
10484 if Nkind (State) = N_Aggregate then
10485 State := First (Expressions (State));
10486 while Present (State) loop
10487 Analyze_Abstract_State (State, Pack_Id);
10488 Next (State);
10489 end loop;
10491 -- Various forms of a single abstract state. Note that these may
10492 -- include malformed state declarations.
10494 else
10495 Analyze_Abstract_State (State, Pack_Id);
10496 end if;
10498 -- Save the pragma for retrieval by other tools
10500 Add_Contract_Item (N, Pack_Id);
10502 -- Verify the declaration order of pragmas Abstract_State and
10503 -- Initializes.
10505 Check_Declaration_Order
10506 (First => N,
10507 Second => Get_Pragma (Pack_Id, Pragma_Initializes));
10508 end Abstract_State;
10510 ------------
10511 -- Ada_83 --
10512 ------------
10514 -- pragma Ada_83;
10516 -- Note: this pragma also has some specific processing in Par.Prag
10517 -- because we want to set the Ada version mode during parsing.
10519 when Pragma_Ada_83 =>
10520 GNAT_Pragma;
10521 Check_Arg_Count (0);
10523 -- We really should check unconditionally for proper configuration
10524 -- pragma placement, since we really don't want mixed Ada modes
10525 -- within a single unit, and the GNAT reference manual has always
10526 -- said this was a configuration pragma, but we did not check and
10527 -- are hesitant to add the check now.
10529 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
10530 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
10531 -- or Ada 2012 mode.
10533 if Ada_Version >= Ada_2005 then
10534 Check_Valid_Configuration_Pragma;
10535 end if;
10537 -- Now set Ada 83 mode
10539 Ada_Version := Ada_83;
10540 Ada_Version_Explicit := Ada_83;
10541 Ada_Version_Pragma := N;
10543 ------------
10544 -- Ada_95 --
10545 ------------
10547 -- pragma Ada_95;
10549 -- Note: this pragma also has some specific processing in Par.Prag
10550 -- because we want to set the Ada 83 version mode during parsing.
10552 when Pragma_Ada_95 =>
10553 GNAT_Pragma;
10554 Check_Arg_Count (0);
10556 -- We really should check unconditionally for proper configuration
10557 -- pragma placement, since we really don't want mixed Ada modes
10558 -- within a single unit, and the GNAT reference manual has always
10559 -- said this was a configuration pragma, but we did not check and
10560 -- are hesitant to add the check now.
10562 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
10563 -- or Ada 95, so we must check if we are in Ada 2005 mode.
10565 if Ada_Version >= Ada_2005 then
10566 Check_Valid_Configuration_Pragma;
10567 end if;
10569 -- Now set Ada 95 mode
10571 Ada_Version := Ada_95;
10572 Ada_Version_Explicit := Ada_95;
10573 Ada_Version_Pragma := N;
10575 ---------------------
10576 -- Ada_05/Ada_2005 --
10577 ---------------------
10579 -- pragma Ada_05;
10580 -- pragma Ada_05 (LOCAL_NAME);
10582 -- pragma Ada_2005;
10583 -- pragma Ada_2005 (LOCAL_NAME):
10585 -- Note: these pragmas also have some specific processing in Par.Prag
10586 -- because we want to set the Ada 2005 version mode during parsing.
10588 -- The one argument form is used for managing the transition from
10589 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
10590 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
10591 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
10592 -- mode, a preference rule is established which does not choose
10593 -- such an entity unless it is unambiguously specified. This avoids
10594 -- extra subprograms marked this way from generating ambiguities in
10595 -- otherwise legal pre-Ada_2005 programs. The one argument form is
10596 -- intended for exclusive use in the GNAT run-time library.
10598 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
10599 E_Id : Node_Id;
10601 begin
10602 GNAT_Pragma;
10604 if Arg_Count = 1 then
10605 Check_Arg_Is_Local_Name (Arg1);
10606 E_Id := Get_Pragma_Arg (Arg1);
10608 if Etype (E_Id) = Any_Type then
10609 return;
10610 end if;
10612 Set_Is_Ada_2005_Only (Entity (E_Id));
10613 Record_Rep_Item (Entity (E_Id), N);
10615 else
10616 Check_Arg_Count (0);
10618 -- For Ada_2005 we unconditionally enforce the documented
10619 -- configuration pragma placement, since we do not want to
10620 -- tolerate mixed modes in a unit involving Ada 2005. That
10621 -- would cause real difficulties for those cases where there
10622 -- are incompatibilities between Ada 95 and Ada 2005.
10624 Check_Valid_Configuration_Pragma;
10626 -- Now set appropriate Ada mode
10628 Ada_Version := Ada_2005;
10629 Ada_Version_Explicit := Ada_2005;
10630 Ada_Version_Pragma := N;
10631 end if;
10632 end;
10634 ---------------------
10635 -- Ada_12/Ada_2012 --
10636 ---------------------
10638 -- pragma Ada_12;
10639 -- pragma Ada_12 (LOCAL_NAME);
10641 -- pragma Ada_2012;
10642 -- pragma Ada_2012 (LOCAL_NAME):
10644 -- Note: these pragmas also have some specific processing in Par.Prag
10645 -- because we want to set the Ada 2012 version mode during parsing.
10647 -- The one argument form is used for managing the transition from Ada
10648 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
10649 -- as Ada_201 only, then referencing the entity in any pre-Ada_2012
10650 -- mode will generate a warning. In addition, in any pre-Ada_2012
10651 -- mode, a preference rule is established which does not choose
10652 -- such an entity unless it is unambiguously specified. This avoids
10653 -- extra subprograms marked this way from generating ambiguities in
10654 -- otherwise legal pre-Ada_2012 programs. The one argument form is
10655 -- intended for exclusive use in the GNAT run-time library.
10657 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
10658 E_Id : Node_Id;
10660 begin
10661 GNAT_Pragma;
10663 if Arg_Count = 1 then
10664 Check_Arg_Is_Local_Name (Arg1);
10665 E_Id := Get_Pragma_Arg (Arg1);
10667 if Etype (E_Id) = Any_Type then
10668 return;
10669 end if;
10671 Set_Is_Ada_2012_Only (Entity (E_Id));
10672 Record_Rep_Item (Entity (E_Id), N);
10674 else
10675 Check_Arg_Count (0);
10677 -- For Ada_2012 we unconditionally enforce the documented
10678 -- configuration pragma placement, since we do not want to
10679 -- tolerate mixed modes in a unit involving Ada 2012. That
10680 -- would cause real difficulties for those cases where there
10681 -- are incompatibilities between Ada 95 and Ada 2012. We could
10682 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
10684 Check_Valid_Configuration_Pragma;
10686 -- Now set appropriate Ada mode
10688 Ada_Version := Ada_2012;
10689 Ada_Version_Explicit := Ada_2012;
10690 Ada_Version_Pragma := N;
10691 end if;
10692 end;
10694 ----------------------
10695 -- All_Calls_Remote --
10696 ----------------------
10698 -- pragma All_Calls_Remote [(library_package_NAME)];
10700 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
10701 Lib_Entity : Entity_Id;
10703 begin
10704 Check_Ada_83_Warning;
10705 Check_Valid_Library_Unit_Pragma;
10707 if Nkind (N) = N_Null_Statement then
10708 return;
10709 end if;
10711 Lib_Entity := Find_Lib_Unit_Name;
10713 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
10715 if Present (Lib_Entity)
10716 and then not Debug_Flag_U
10717 then
10718 if not Is_Remote_Call_Interface (Lib_Entity) then
10719 Error_Pragma ("pragma% only apply to rci unit");
10721 -- Set flag for entity of the library unit
10723 else
10724 Set_Has_All_Calls_Remote (Lib_Entity);
10725 end if;
10727 end if;
10728 end All_Calls_Remote;
10730 ---------------------------
10731 -- Allow_Integer_Address --
10732 ---------------------------
10734 -- pragma Allow_Integer_Address;
10736 when Pragma_Allow_Integer_Address =>
10737 GNAT_Pragma;
10738 Check_Valid_Configuration_Pragma;
10739 Check_Arg_Count (0);
10741 -- If Address is a private type, then set the flag to allow
10742 -- integer address values. If Address is not private, then this
10743 -- pragma has no purpose, so it is simply ignored. Not clear if
10744 -- there are any such targets now.
10746 if Opt.Address_Is_Private then
10747 Opt.Allow_Integer_Address := True;
10748 end if;
10750 --------------
10751 -- Annotate --
10752 --------------
10754 -- pragma Annotate
10755 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
10756 -- ARG ::= NAME | EXPRESSION
10758 -- The first two arguments are by convention intended to refer to an
10759 -- external tool and a tool-specific function. These arguments are
10760 -- not analyzed.
10762 when Pragma_Annotate => Annotate : declare
10763 Arg : Node_Id;
10764 Exp : Node_Id;
10766 begin
10767 GNAT_Pragma;
10768 Check_At_Least_N_Arguments (1);
10770 -- See if last argument is Entity => local_Name, and if so process
10771 -- and then remove it for remaining processing.
10773 declare
10774 Last_Arg : constant Node_Id :=
10775 Last (Pragma_Argument_Associations (N));
10777 begin
10778 if Nkind (Last_Arg) = N_Pragma_Argument_Association
10779 and then Chars (Last_Arg) = Name_Entity
10780 then
10781 Check_Arg_Is_Local_Name (Last_Arg);
10782 Arg_Count := Arg_Count - 1;
10784 -- Not allowed in compiler units (bootstrap issues)
10786 Check_Compiler_Unit ("Entity for pragma Annotate", N);
10787 end if;
10788 end;
10790 -- Continue processing with last argument removed for now
10792 Check_Arg_Is_Identifier (Arg1);
10793 Check_No_Identifiers;
10794 Store_Note (N);
10796 -- Second parameter is optional, it is never analyzed
10798 if No (Arg2) then
10799 null;
10801 -- Here if we have a second parameter
10803 else
10804 -- Second parameter must be identifier
10806 Check_Arg_Is_Identifier (Arg2);
10808 -- Process remaining parameters if any
10810 Arg := Next (Arg2);
10811 while Present (Arg) loop
10812 Exp := Get_Pragma_Arg (Arg);
10813 Analyze (Exp);
10815 if Is_Entity_Name (Exp) then
10816 null;
10818 -- For string literals, we assume Standard_String as the
10819 -- type, unless the string contains wide or wide_wide
10820 -- characters.
10822 elsif Nkind (Exp) = N_String_Literal then
10823 if Has_Wide_Wide_Character (Exp) then
10824 Resolve (Exp, Standard_Wide_Wide_String);
10825 elsif Has_Wide_Character (Exp) then
10826 Resolve (Exp, Standard_Wide_String);
10827 else
10828 Resolve (Exp, Standard_String);
10829 end if;
10831 elsif Is_Overloaded (Exp) then
10832 Error_Pragma_Arg
10833 ("ambiguous argument for pragma%", Exp);
10835 else
10836 Resolve (Exp);
10837 end if;
10839 Next (Arg);
10840 end loop;
10841 end if;
10842 end Annotate;
10844 -------------------------------------------------
10845 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
10846 -------------------------------------------------
10848 -- pragma Assert
10849 -- ( [Check => ] Boolean_EXPRESSION
10850 -- [, [Message =>] Static_String_EXPRESSION]);
10852 -- pragma Assert_And_Cut
10853 -- ( [Check => ] Boolean_EXPRESSION
10854 -- [, [Message =>] Static_String_EXPRESSION]);
10856 -- pragma Assume
10857 -- ( [Check => ] Boolean_EXPRESSION
10858 -- [, [Message =>] Static_String_EXPRESSION]);
10860 -- pragma Loop_Invariant
10861 -- ( [Check => ] Boolean_EXPRESSION
10862 -- [, [Message =>] Static_String_EXPRESSION]);
10864 when Pragma_Assert |
10865 Pragma_Assert_And_Cut |
10866 Pragma_Assume |
10867 Pragma_Loop_Invariant =>
10868 Assert : declare
10869 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
10870 -- Determine whether expression Expr contains a Loop_Entry
10871 -- attribute reference.
10873 -------------------------
10874 -- Contains_Loop_Entry --
10875 -------------------------
10877 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
10878 Has_Loop_Entry : Boolean := False;
10880 function Process (N : Node_Id) return Traverse_Result;
10881 -- Process function for traversal to look for Loop_Entry
10883 -------------
10884 -- Process --
10885 -------------
10887 function Process (N : Node_Id) return Traverse_Result is
10888 begin
10889 if Nkind (N) = N_Attribute_Reference
10890 and then Attribute_Name (N) = Name_Loop_Entry
10891 then
10892 Has_Loop_Entry := True;
10893 return Abandon;
10894 else
10895 return OK;
10896 end if;
10897 end Process;
10899 procedure Traverse is new Traverse_Proc (Process);
10901 -- Start of processing for Contains_Loop_Entry
10903 begin
10904 Traverse (Expr);
10905 return Has_Loop_Entry;
10906 end Contains_Loop_Entry;
10908 -- Local variables
10910 Expr : Node_Id;
10911 Newa : List_Id;
10913 -- Start of processing for Assert
10915 begin
10916 -- Assert is an Ada 2005 RM-defined pragma
10918 if Prag_Id = Pragma_Assert then
10919 Ada_2005_Pragma;
10921 -- The remaining ones are GNAT pragmas
10923 else
10924 GNAT_Pragma;
10925 end if;
10927 Check_At_Least_N_Arguments (1);
10928 Check_At_Most_N_Arguments (2);
10929 Check_Arg_Order ((Name_Check, Name_Message));
10930 Check_Optional_Identifier (Arg1, Name_Check);
10931 Expr := Get_Pragma_Arg (Arg1);
10933 -- Special processing for Loop_Invariant, Loop_Variant or for
10934 -- other cases where a Loop_Entry attribute is present. If the
10935 -- assertion pragma contains attribute Loop_Entry, ensure that
10936 -- the related pragma is within a loop.
10938 if Prag_Id = Pragma_Loop_Invariant
10939 or else Prag_Id = Pragma_Loop_Variant
10940 or else Contains_Loop_Entry (Expr)
10941 then
10942 Check_Loop_Pragma_Placement;
10944 -- Perform preanalysis to deal with embedded Loop_Entry
10945 -- attributes.
10947 Preanalyze_Assert_Expression (Expression (Arg1), Any_Boolean);
10948 end if;
10950 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
10951 -- a corresponding Check pragma:
10953 -- pragma Check (name, condition [, msg]);
10955 -- Where name is the identifier matching the pragma name. So
10956 -- rewrite pragma in this manner, transfer the message argument
10957 -- if present, and analyze the result
10959 -- Note: When dealing with a semantically analyzed tree, the
10960 -- information that a Check node N corresponds to a source Assert,
10961 -- Assume, or Assert_And_Cut pragma can be retrieved from the
10962 -- pragma kind of Original_Node(N).
10964 Newa := New_List (
10965 Make_Pragma_Argument_Association (Loc,
10966 Expression => Make_Identifier (Loc, Pname)),
10967 Make_Pragma_Argument_Association (Sloc (Expr),
10968 Expression => Expr));
10970 if Arg_Count > 1 then
10971 Check_Optional_Identifier (Arg2, Name_Message);
10973 -- Provide semantic annnotations for optional argument, for
10974 -- ASIS use, before rewriting.
10976 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
10977 Append_To (Newa, New_Copy_Tree (Arg2));
10978 end if;
10980 -- Rewrite as Check pragma
10982 Rewrite (N,
10983 Make_Pragma (Loc,
10984 Chars => Name_Check,
10985 Pragma_Argument_Associations => Newa));
10986 Analyze (N);
10987 end Assert;
10989 ----------------------
10990 -- Assertion_Policy --
10991 ----------------------
10993 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
10995 -- The following form is Ada 2012 only, but we allow it in all modes
10997 -- Pragma Assertion_Policy (
10998 -- ASSERTION_KIND => POLICY_IDENTIFIER
10999 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
11001 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
11003 -- RM_ASSERTION_KIND ::= Assert |
11004 -- Static_Predicate |
11005 -- Dynamic_Predicate |
11006 -- Pre |
11007 -- Pre'Class |
11008 -- Post |
11009 -- Post'Class |
11010 -- Type_Invariant |
11011 -- Type_Invariant'Class
11013 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
11014 -- Assume |
11015 -- Contract_Cases |
11016 -- Debug |
11017 -- Default_Initial_Condition |
11018 -- Ghost |
11019 -- Initial_Condition |
11020 -- Loop_Invariant |
11021 -- Loop_Variant |
11022 -- Postcondition |
11023 -- Precondition |
11024 -- Predicate |
11025 -- Refined_Post |
11026 -- Statement_Assertions
11028 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
11029 -- ID_ASSERTION_KIND list contains implementation-defined additions
11030 -- recognized by GNAT. The effect is to control the behavior of
11031 -- identically named aspects and pragmas, depending on the specified
11032 -- policy identifier:
11034 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
11036 -- Note: Check and Ignore are language-defined. Disable is a GNAT
11037 -- implementation defined addition that results in totally ignoring
11038 -- the corresponding assertion. If Disable is specified, then the
11039 -- argument of the assertion is not even analyzed. This is useful
11040 -- when the aspect/pragma argument references entities in a with'ed
11041 -- package that is replaced by a dummy package in the final build.
11043 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
11044 -- and Type_Invariant'Class were recognized by the parser and
11045 -- transformed into references to the special internal identifiers
11046 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
11047 -- processing is required here.
11049 when Pragma_Assertion_Policy => Assertion_Policy : declare
11050 Arg : Node_Id;
11051 Kind : Name_Id;
11052 LocP : Source_Ptr;
11053 Policy : Node_Id;
11055 begin
11056 Ada_2005_Pragma;
11058 -- This can always appear as a configuration pragma
11060 if Is_Configuration_Pragma then
11061 null;
11063 -- It can also appear in a declarative part or package spec in Ada
11064 -- 2012 mode. We allow this in other modes, but in that case we
11065 -- consider that we have an Ada 2012 pragma on our hands.
11067 else
11068 Check_Is_In_Decl_Part_Or_Package_Spec;
11069 Ada_2012_Pragma;
11070 end if;
11072 -- One argument case with no identifier (first form above)
11074 if Arg_Count = 1
11075 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
11076 or else Chars (Arg1) = No_Name)
11077 then
11078 Check_Arg_Is_One_Of
11079 (Arg1, Name_Check, Name_Disable, Name_Ignore);
11081 -- Treat one argument Assertion_Policy as equivalent to:
11083 -- pragma Check_Policy (Assertion, policy)
11085 -- So rewrite pragma in that manner and link on to the chain
11086 -- of Check_Policy pragmas, marking the pragma as analyzed.
11088 Policy := Get_Pragma_Arg (Arg1);
11090 Rewrite (N,
11091 Make_Pragma (Loc,
11092 Chars => Name_Check_Policy,
11093 Pragma_Argument_Associations => New_List (
11094 Make_Pragma_Argument_Association (Loc,
11095 Expression => Make_Identifier (Loc, Name_Assertion)),
11097 Make_Pragma_Argument_Association (Loc,
11098 Expression =>
11099 Make_Identifier (Sloc (Policy), Chars (Policy))))));
11100 Analyze (N);
11102 -- Here if we have two or more arguments
11104 else
11105 Check_At_Least_N_Arguments (1);
11106 Ada_2012_Pragma;
11108 -- Loop through arguments
11110 Arg := Arg1;
11111 while Present (Arg) loop
11112 LocP := Sloc (Arg);
11114 -- Kind must be specified
11116 if Nkind (Arg) /= N_Pragma_Argument_Association
11117 or else Chars (Arg) = No_Name
11118 then
11119 Error_Pragma_Arg
11120 ("missing assertion kind for pragma%", Arg);
11121 end if;
11123 -- Check Kind and Policy have allowed forms
11125 Kind := Chars (Arg);
11127 if not Is_Valid_Assertion_Kind (Kind) then
11128 Error_Pragma_Arg
11129 ("invalid assertion kind for pragma%", Arg);
11130 end if;
11132 Check_Arg_Is_One_Of
11133 (Arg, Name_Check, Name_Disable, Name_Ignore);
11135 -- Rewrite the Assertion_Policy pragma as a series of
11136 -- Check_Policy pragmas of the form:
11138 -- Check_Policy (Kind, Policy);
11140 -- Note: the insertion of the pragmas cannot be done with
11141 -- Insert_Action because in the configuration case, there
11142 -- are no scopes on the scope stack and the mechanism will
11143 -- fail.
11145 Insert_Before_And_Analyze (N,
11146 Make_Pragma (LocP,
11147 Chars => Name_Check_Policy,
11148 Pragma_Argument_Associations => New_List (
11149 Make_Pragma_Argument_Association (LocP,
11150 Expression => Make_Identifier (LocP, Kind)),
11151 Make_Pragma_Argument_Association (LocP,
11152 Expression => Get_Pragma_Arg (Arg)))));
11154 Arg := Next (Arg);
11155 end loop;
11157 -- Rewrite the Assertion_Policy pragma as null since we have
11158 -- now inserted all the equivalent Check pragmas.
11160 Rewrite (N, Make_Null_Statement (Loc));
11161 Analyze (N);
11162 end if;
11163 end Assertion_Policy;
11165 ------------------------------
11166 -- Assume_No_Invalid_Values --
11167 ------------------------------
11169 -- pragma Assume_No_Invalid_Values (On | Off);
11171 when Pragma_Assume_No_Invalid_Values =>
11172 GNAT_Pragma;
11173 Check_Valid_Configuration_Pragma;
11174 Check_Arg_Count (1);
11175 Check_No_Identifiers;
11176 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11178 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
11179 Assume_No_Invalid_Values := True;
11180 else
11181 Assume_No_Invalid_Values := False;
11182 end if;
11184 --------------------------
11185 -- Attribute_Definition --
11186 --------------------------
11188 -- pragma Attribute_Definition
11189 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
11190 -- [Entity =>] LOCAL_NAME,
11191 -- [Expression =>] EXPRESSION | NAME);
11193 when Pragma_Attribute_Definition => Attribute_Definition : declare
11194 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
11195 Aname : Name_Id;
11197 begin
11198 GNAT_Pragma;
11199 Check_Arg_Count (3);
11200 Check_Optional_Identifier (Arg1, "attribute");
11201 Check_Optional_Identifier (Arg2, "entity");
11202 Check_Optional_Identifier (Arg3, "expression");
11204 if Nkind (Attribute_Designator) /= N_Identifier then
11205 Error_Msg_N ("attribute name expected", Attribute_Designator);
11206 return;
11207 end if;
11209 Check_Arg_Is_Local_Name (Arg2);
11211 -- If the attribute is not recognized, then issue a warning (not
11212 -- an error), and ignore the pragma.
11214 Aname := Chars (Attribute_Designator);
11216 if not Is_Attribute_Name (Aname) then
11217 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
11218 return;
11219 end if;
11221 -- Otherwise, rewrite the pragma as an attribute definition clause
11223 Rewrite (N,
11224 Make_Attribute_Definition_Clause (Loc,
11225 Name => Get_Pragma_Arg (Arg2),
11226 Chars => Aname,
11227 Expression => Get_Pragma_Arg (Arg3)));
11228 Analyze (N);
11229 end Attribute_Definition;
11231 ------------------------------------------------------------------
11232 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
11233 ------------------------------------------------------------------
11235 -- pragma Asynch_Readers ( object_LOCAL_NAME [, FLAG] );
11236 -- pragma Asynch_Writers ( object_LOCAL_NAME [, FLAG] );
11237 -- pragma Effective_Reads ( object_LOCAL_NAME [, FLAG] );
11238 -- pragma Effective_Writes ( object_LOCAL_NAME [, FLAG] );
11240 -- FLAG ::= boolean_EXPRESSION
11242 when Pragma_Async_Readers |
11243 Pragma_Async_Writers |
11244 Pragma_Effective_Reads |
11245 Pragma_Effective_Writes =>
11246 Async_Effective : declare
11247 Duplic : Node_Id;
11248 Expr : Node_Id;
11249 Obj : Node_Id;
11250 Obj_Id : Entity_Id;
11252 begin
11253 GNAT_Pragma;
11254 Check_No_Identifiers;
11255 Check_At_Least_N_Arguments (1);
11256 Check_At_Most_N_Arguments (2);
11257 Check_Arg_Is_Local_Name (Arg1);
11258 Error_Msg_Name_1 := Pname;
11260 Obj := Get_Pragma_Arg (Arg1);
11261 Expr := Get_Pragma_Arg (Arg2);
11263 -- Perform minimal verification to ensure that the argument is at
11264 -- least a variable. Subsequent finer grained checks will be done
11265 -- at the end of the declarative region the contains the pragma.
11267 if Is_Entity_Name (Obj)
11268 and then Present (Entity (Obj))
11269 and then Ekind (Entity (Obj)) = E_Variable
11270 then
11271 Obj_Id := Entity (Obj);
11273 -- Detect a duplicate pragma. Note that it is not efficient to
11274 -- examine preceding statements as Boolean aspects may appear
11275 -- anywhere between the related object declaration and its
11276 -- freeze point. As an alternative, inspect the contents of the
11277 -- variable contract.
11279 Duplic := Get_Pragma (Obj_Id, Prag_Id);
11281 if Present (Duplic) then
11282 Error_Msg_Sloc := Sloc (Duplic);
11283 Error_Msg_N ("pragma % duplicates pragma declared #", N);
11285 -- No duplicate detected
11287 else
11288 if Present (Expr) then
11289 Preanalyze_And_Resolve (Expr, Standard_Boolean);
11290 end if;
11292 -- Chain the pragma on the contract for further processing
11294 Add_Contract_Item (N, Obj_Id);
11295 end if;
11296 else
11297 Error_Pragma ("pragma % must apply to a volatile object");
11298 end if;
11299 end Async_Effective;
11301 ------------------
11302 -- Asynchronous --
11303 ------------------
11305 -- pragma Asynchronous (LOCAL_NAME);
11307 when Pragma_Asynchronous => Asynchronous : declare
11308 Nm : Entity_Id;
11309 C_Ent : Entity_Id;
11310 L : List_Id;
11311 S : Node_Id;
11312 N : Node_Id;
11313 Formal : Entity_Id;
11315 procedure Process_Async_Pragma;
11316 -- Common processing for procedure and access-to-procedure case
11318 --------------------------
11319 -- Process_Async_Pragma --
11320 --------------------------
11322 procedure Process_Async_Pragma is
11323 begin
11324 if No (L) then
11325 Set_Is_Asynchronous (Nm);
11326 return;
11327 end if;
11329 -- The formals should be of mode IN (RM E.4.1(6))
11331 S := First (L);
11332 while Present (S) loop
11333 Formal := Defining_Identifier (S);
11335 if Nkind (Formal) = N_Defining_Identifier
11336 and then Ekind (Formal) /= E_In_Parameter
11337 then
11338 Error_Pragma_Arg
11339 ("pragma% procedure can only have IN parameter",
11340 Arg1);
11341 end if;
11343 Next (S);
11344 end loop;
11346 Set_Is_Asynchronous (Nm);
11347 end Process_Async_Pragma;
11349 -- Start of processing for pragma Asynchronous
11351 begin
11352 Check_Ada_83_Warning;
11353 Check_No_Identifiers;
11354 Check_Arg_Count (1);
11355 Check_Arg_Is_Local_Name (Arg1);
11357 if Debug_Flag_U then
11358 return;
11359 end if;
11361 C_Ent := Cunit_Entity (Current_Sem_Unit);
11362 Analyze (Get_Pragma_Arg (Arg1));
11363 Nm := Entity (Get_Pragma_Arg (Arg1));
11365 if not Is_Remote_Call_Interface (C_Ent)
11366 and then not Is_Remote_Types (C_Ent)
11367 then
11368 -- This pragma should only appear in an RCI or Remote Types
11369 -- unit (RM E.4.1(4)).
11371 Error_Pragma
11372 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
11373 end if;
11375 if Ekind (Nm) = E_Procedure
11376 and then Nkind (Parent (Nm)) = N_Procedure_Specification
11377 then
11378 if not Is_Remote_Call_Interface (Nm) then
11379 Error_Pragma_Arg
11380 ("pragma% cannot be applied on non-remote procedure",
11381 Arg1);
11382 end if;
11384 L := Parameter_Specifications (Parent (Nm));
11385 Process_Async_Pragma;
11386 return;
11388 elsif Ekind (Nm) = E_Function then
11389 Error_Pragma_Arg
11390 ("pragma% cannot be applied to function", Arg1);
11392 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
11393 if Is_Record_Type (Nm) then
11395 -- A record type that is the Equivalent_Type for a remote
11396 -- access-to-subprogram type.
11398 N := Declaration_Node (Corresponding_Remote_Type (Nm));
11400 else
11401 -- A non-expanded RAS type (distribution is not enabled)
11403 N := Declaration_Node (Nm);
11404 end if;
11406 if Nkind (N) = N_Full_Type_Declaration
11407 and then Nkind (Type_Definition (N)) =
11408 N_Access_Procedure_Definition
11409 then
11410 L := Parameter_Specifications (Type_Definition (N));
11411 Process_Async_Pragma;
11413 if Is_Asynchronous (Nm)
11414 and then Expander_Active
11415 and then Get_PCS_Name /= Name_No_DSA
11416 then
11417 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
11418 end if;
11420 else
11421 Error_Pragma_Arg
11422 ("pragma% cannot reference access-to-function type",
11423 Arg1);
11424 end if;
11426 -- Only other possibility is Access-to-class-wide type
11428 elsif Is_Access_Type (Nm)
11429 and then Is_Class_Wide_Type (Designated_Type (Nm))
11430 then
11431 Check_First_Subtype (Arg1);
11432 Set_Is_Asynchronous (Nm);
11433 if Expander_Active then
11434 RACW_Type_Is_Asynchronous (Nm);
11435 end if;
11437 else
11438 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
11439 end if;
11440 end Asynchronous;
11442 ------------
11443 -- Atomic --
11444 ------------
11446 -- pragma Atomic (LOCAL_NAME);
11448 when Pragma_Atomic =>
11449 Process_Atomic_Independent_Shared_Volatile;
11451 -----------------------
11452 -- Atomic_Components --
11453 -----------------------
11455 -- pragma Atomic_Components (array_LOCAL_NAME);
11457 -- This processing is shared by Volatile_Components
11459 when Pragma_Atomic_Components |
11460 Pragma_Volatile_Components =>
11462 Atomic_Components : declare
11463 E_Id : Node_Id;
11464 E : Entity_Id;
11465 D : Node_Id;
11466 K : Node_Kind;
11468 begin
11469 Check_Ada_83_Warning;
11470 Check_No_Identifiers;
11471 Check_Arg_Count (1);
11472 Check_Arg_Is_Local_Name (Arg1);
11473 E_Id := Get_Pragma_Arg (Arg1);
11475 if Etype (E_Id) = Any_Type then
11476 return;
11477 end if;
11479 E := Entity (E_Id);
11481 Check_Duplicate_Pragma (E);
11483 if Rep_Item_Too_Early (E, N)
11484 or else
11485 Rep_Item_Too_Late (E, N)
11486 then
11487 return;
11488 end if;
11490 D := Declaration_Node (E);
11491 K := Nkind (D);
11493 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
11494 or else
11495 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
11496 and then Nkind (D) = N_Object_Declaration
11497 and then Nkind (Object_Definition (D)) =
11498 N_Constrained_Array_Definition)
11499 then
11500 -- The flag is set on the object, or on the base type
11502 if Nkind (D) /= N_Object_Declaration then
11503 E := Base_Type (E);
11504 end if;
11506 -- Atomic implies both Independent and Volatile
11508 if Prag_Id = Pragma_Atomic_Components then
11509 Set_Has_Atomic_Components (E);
11510 Set_Has_Independent_Components (E);
11511 end if;
11513 Set_Has_Volatile_Components (E);
11515 else
11516 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
11517 end if;
11518 end Atomic_Components;
11520 --------------------
11521 -- Attach_Handler --
11522 --------------------
11524 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
11526 when Pragma_Attach_Handler =>
11527 Check_Ada_83_Warning;
11528 Check_No_Identifiers;
11529 Check_Arg_Count (2);
11531 if No_Run_Time_Mode then
11532 Error_Msg_CRT ("Attach_Handler pragma", N);
11533 else
11534 Check_Interrupt_Or_Attach_Handler;
11536 -- The expression that designates the attribute may depend on a
11537 -- discriminant, and is therefore a per-object expression, to
11538 -- be expanded in the init proc. If expansion is enabled, then
11539 -- perform semantic checks on a copy only.
11541 declare
11542 Temp : Node_Id;
11543 Typ : Node_Id;
11544 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
11546 begin
11547 -- In Relaxed_RM_Semantics mode, we allow any static
11548 -- integer value, for compatibility with other compilers.
11550 if Relaxed_RM_Semantics
11551 and then Nkind (Parg2) = N_Integer_Literal
11552 then
11553 Typ := Standard_Integer;
11554 else
11555 Typ := RTE (RE_Interrupt_ID);
11556 end if;
11558 if Expander_Active then
11559 Temp := New_Copy_Tree (Parg2);
11560 Set_Parent (Temp, N);
11561 Preanalyze_And_Resolve (Temp, Typ);
11562 else
11563 Analyze (Parg2);
11564 Resolve (Parg2, Typ);
11565 end if;
11566 end;
11568 Process_Interrupt_Or_Attach_Handler;
11569 end if;
11571 --------------------
11572 -- C_Pass_By_Copy --
11573 --------------------
11575 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
11577 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
11578 Arg : Node_Id;
11579 Val : Uint;
11581 begin
11582 GNAT_Pragma;
11583 Check_Valid_Configuration_Pragma;
11584 Check_Arg_Count (1);
11585 Check_Optional_Identifier (Arg1, "max_size");
11587 Arg := Get_Pragma_Arg (Arg1);
11588 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
11590 Val := Expr_Value (Arg);
11592 if Val <= 0 then
11593 Error_Pragma_Arg
11594 ("maximum size for pragma% must be positive", Arg1);
11596 elsif UI_Is_In_Int_Range (Val) then
11597 Default_C_Record_Mechanism := UI_To_Int (Val);
11599 -- If a giant value is given, Int'Last will do well enough.
11600 -- If sometime someone complains that a record larger than
11601 -- two gigabytes is not copied, we will worry about it then.
11603 else
11604 Default_C_Record_Mechanism := Mechanism_Type'Last;
11605 end if;
11606 end C_Pass_By_Copy;
11608 -----------
11609 -- Check --
11610 -----------
11612 -- pragma Check ([Name =>] CHECK_KIND,
11613 -- [Check =>] Boolean_EXPRESSION
11614 -- [,[Message =>] String_EXPRESSION]);
11616 -- CHECK_KIND ::= IDENTIFIER |
11617 -- Pre'Class |
11618 -- Post'Class |
11619 -- Invariant'Class |
11620 -- Type_Invariant'Class
11622 -- The identifiers Assertions and Statement_Assertions are not
11623 -- allowed, since they have special meaning for Check_Policy.
11625 when Pragma_Check => Check : declare
11626 Expr : Node_Id;
11627 Eloc : Source_Ptr;
11628 Cname : Name_Id;
11629 Str : Node_Id;
11631 begin
11632 GNAT_Pragma;
11633 Check_At_Least_N_Arguments (2);
11634 Check_At_Most_N_Arguments (3);
11635 Check_Optional_Identifier (Arg1, Name_Name);
11636 Check_Optional_Identifier (Arg2, Name_Check);
11638 if Arg_Count = 3 then
11639 Check_Optional_Identifier (Arg3, Name_Message);
11640 Str := Get_Pragma_Arg (Arg3);
11641 end if;
11643 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
11644 Check_Arg_Is_Identifier (Arg1);
11645 Cname := Chars (Get_Pragma_Arg (Arg1));
11647 -- Check forbidden name Assertions or Statement_Assertions
11649 case Cname is
11650 when Name_Assertions =>
11651 Error_Pragma_Arg
11652 ("""Assertions"" is not allowed as a check kind "
11653 & "for pragma%", Arg1);
11655 when Name_Statement_Assertions =>
11656 Error_Pragma_Arg
11657 ("""Statement_Assertions"" is not allowed as a check kind "
11658 & "for pragma%", Arg1);
11660 when others =>
11661 null;
11662 end case;
11664 -- Check applicable policy. We skip this if Checked/Ignored status
11665 -- is already set (e.g. in the casse of a pragma from an aspect).
11667 if Is_Checked (N) or else Is_Ignored (N) then
11668 null;
11670 -- For a non-source pragma that is a rewriting of another pragma,
11671 -- copy the Is_Checked/Ignored status from the rewritten pragma.
11673 elsif Is_Rewrite_Substitution (N)
11674 and then Nkind (Original_Node (N)) = N_Pragma
11675 and then Original_Node (N) /= N
11676 then
11677 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
11678 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
11680 -- Otherwise query the applicable policy at this point
11682 else
11683 case Check_Kind (Cname) is
11684 when Name_Ignore =>
11685 Set_Is_Ignored (N, True);
11686 Set_Is_Checked (N, False);
11688 when Name_Check =>
11689 Set_Is_Ignored (N, False);
11690 Set_Is_Checked (N, True);
11692 -- For disable, rewrite pragma as null statement and skip
11693 -- rest of the analysis of the pragma.
11695 when Name_Disable =>
11696 Rewrite (N, Make_Null_Statement (Loc));
11697 Analyze (N);
11698 raise Pragma_Exit;
11700 -- No other possibilities
11702 when others =>
11703 raise Program_Error;
11704 end case;
11705 end if;
11707 -- If check kind was not Disable, then continue pragma analysis
11709 Expr := Get_Pragma_Arg (Arg2);
11711 -- Deal with SCO generation
11713 case Cname is
11714 when Name_Predicate |
11715 Name_Invariant =>
11717 -- Nothing to do: since checks occur in client units,
11718 -- the SCO for the aspect in the declaration unit is
11719 -- conservatively always enabled.
11721 null;
11723 when others =>
11725 if Is_Checked (N) and then not Split_PPC (N) then
11727 -- Mark aspect/pragma SCO as enabled
11729 Set_SCO_Pragma_Enabled (Loc);
11730 end if;
11731 end case;
11733 -- Deal with analyzing the string argument.
11735 if Arg_Count = 3 then
11737 -- If checks are not on we don't want any expansion (since
11738 -- such expansion would not get properly deleted) but
11739 -- we do want to analyze (to get proper references).
11740 -- The Preanalyze_And_Resolve routine does just what we want
11742 if Is_Ignored (N) then
11743 Preanalyze_And_Resolve (Str, Standard_String);
11745 -- Otherwise we need a proper analysis and expansion
11747 else
11748 Analyze_And_Resolve (Str, Standard_String);
11749 end if;
11750 end if;
11752 -- Now you might think we could just do the same with the Boolean
11753 -- expression if checks are off (and expansion is on) and then
11754 -- rewrite the check as a null statement. This would work but we
11755 -- would lose the useful warnings about an assertion being bound
11756 -- to fail even if assertions are turned off.
11758 -- So instead we wrap the boolean expression in an if statement
11759 -- that looks like:
11761 -- if False and then condition then
11762 -- null;
11763 -- end if;
11765 -- The reason we do this rewriting during semantic analysis rather
11766 -- than as part of normal expansion is that we cannot analyze and
11767 -- expand the code for the boolean expression directly, or it may
11768 -- cause insertion of actions that would escape the attempt to
11769 -- suppress the check code.
11771 -- Note that the Sloc for the if statement corresponds to the
11772 -- argument condition, not the pragma itself. The reason for
11773 -- this is that we may generate a warning if the condition is
11774 -- False at compile time, and we do not want to delete this
11775 -- warning when we delete the if statement.
11777 if Expander_Active and Is_Ignored (N) then
11778 Eloc := Sloc (Expr);
11780 Rewrite (N,
11781 Make_If_Statement (Eloc,
11782 Condition =>
11783 Make_And_Then (Eloc,
11784 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
11785 Right_Opnd => Expr),
11786 Then_Statements => New_List (
11787 Make_Null_Statement (Eloc))));
11789 In_Assertion_Expr := In_Assertion_Expr + 1;
11790 Analyze (N);
11791 In_Assertion_Expr := In_Assertion_Expr - 1;
11793 -- Check is active or expansion not active. In these cases we can
11794 -- just go ahead and analyze the boolean with no worries.
11796 else
11797 In_Assertion_Expr := In_Assertion_Expr + 1;
11798 Analyze_And_Resolve (Expr, Any_Boolean);
11799 In_Assertion_Expr := In_Assertion_Expr - 1;
11800 end if;
11801 end Check;
11803 --------------------------
11804 -- Check_Float_Overflow --
11805 --------------------------
11807 -- pragma Check_Float_Overflow;
11809 when Pragma_Check_Float_Overflow =>
11810 GNAT_Pragma;
11811 Check_Valid_Configuration_Pragma;
11812 Check_Arg_Count (0);
11813 Check_Float_Overflow := not Machine_Overflows_On_Target;
11815 ----------------
11816 -- Check_Name --
11817 ----------------
11819 -- pragma Check_Name (check_IDENTIFIER);
11821 when Pragma_Check_Name =>
11822 GNAT_Pragma;
11823 Check_No_Identifiers;
11824 Check_Valid_Configuration_Pragma;
11825 Check_Arg_Count (1);
11826 Check_Arg_Is_Identifier (Arg1);
11828 declare
11829 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11831 begin
11832 for J in Check_Names.First .. Check_Names.Last loop
11833 if Check_Names.Table (J) = Nam then
11834 return;
11835 end if;
11836 end loop;
11838 Check_Names.Append (Nam);
11839 end;
11841 ------------------
11842 -- Check_Policy --
11843 ------------------
11845 -- This is the old style syntax, which is still allowed in all modes:
11847 -- pragma Check_Policy ([Name =>] CHECK_KIND
11848 -- [Policy =>] POLICY_IDENTIFIER);
11850 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
11852 -- CHECK_KIND ::= IDENTIFIER |
11853 -- Pre'Class |
11854 -- Post'Class |
11855 -- Type_Invariant'Class |
11856 -- Invariant'Class
11858 -- This is the new style syntax, compatible with Assertion_Policy
11859 -- and also allowed in all modes.
11861 -- Pragma Check_Policy (
11862 -- CHECK_KIND => POLICY_IDENTIFIER
11863 -- {, CHECK_KIND => POLICY_IDENTIFIER});
11865 -- Note: the identifiers Name and Policy are not allowed as
11866 -- Check_Kind values. This avoids ambiguities between the old and
11867 -- new form syntax.
11869 when Pragma_Check_Policy => Check_Policy : declare
11870 Ident : Node_Id;
11871 Kind : Node_Id;
11873 begin
11874 GNAT_Pragma;
11875 Check_At_Least_N_Arguments (1);
11877 -- A Check_Policy pragma can appear either as a configuration
11878 -- pragma, or in a declarative part or a package spec (see RM
11879 -- 11.5(5) for rules for Suppress/Unsuppress which are also
11880 -- followed for Check_Policy).
11882 if not Is_Configuration_Pragma then
11883 Check_Is_In_Decl_Part_Or_Package_Spec;
11884 end if;
11886 -- Figure out if we have the old or new syntax. We have the
11887 -- old syntax if the first argument has no identifier, or the
11888 -- identifier is Name.
11890 if Nkind (Arg1) /= N_Pragma_Argument_Association
11891 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
11892 then
11893 -- Old syntax
11895 Check_Arg_Count (2);
11896 Check_Optional_Identifier (Arg1, Name_Name);
11897 Kind := Get_Pragma_Arg (Arg1);
11898 Rewrite_Assertion_Kind (Kind);
11899 Check_Arg_Is_Identifier (Arg1);
11901 -- Check forbidden check kind
11903 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
11904 Error_Msg_Name_2 := Chars (Kind);
11905 Error_Pragma_Arg
11906 ("pragma% does not allow% as check name", Arg1);
11907 end if;
11909 -- Check policy
11911 Check_Optional_Identifier (Arg2, Name_Policy);
11912 Check_Arg_Is_One_Of
11913 (Arg2,
11914 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
11915 Ident := Get_Pragma_Arg (Arg2);
11917 if Chars (Kind) = Name_Ghost then
11919 -- Pragma Check_Policy specifying a Ghost policy cannot
11920 -- occur within a ghost subprogram or package.
11922 if Ghost_Mode > None then
11923 Error_Pragma
11924 ("pragma % cannot appear within ghost subprogram or "
11925 & "package");
11927 -- The policy identifier of pragma Ghost must be either
11928 -- Check or Ignore (SPARK RM 6.9(7)).
11930 elsif not Nam_In (Chars (Ident), Name_Check,
11931 Name_Ignore)
11932 then
11933 Error_Pragma_Arg
11934 ("argument of pragma % Ghost must be Check or Ignore",
11935 Arg2);
11936 end if;
11937 end if;
11939 -- And chain pragma on the Check_Policy_List for search
11941 Set_Next_Pragma (N, Opt.Check_Policy_List);
11942 Opt.Check_Policy_List := N;
11944 -- For the new syntax, what we do is to convert each argument to
11945 -- an old syntax equivalent. We do that because we want to chain
11946 -- old style Check_Policy pragmas for the search (we don't want
11947 -- to have to deal with multiple arguments in the search).
11949 else
11950 declare
11951 Arg : Node_Id;
11952 Argx : Node_Id;
11953 LocP : Source_Ptr;
11955 begin
11956 Arg := Arg1;
11957 while Present (Arg) loop
11958 LocP := Sloc (Arg);
11959 Argx := Get_Pragma_Arg (Arg);
11961 -- Kind must be specified
11963 if Nkind (Arg) /= N_Pragma_Argument_Association
11964 or else Chars (Arg) = No_Name
11965 then
11966 Error_Pragma_Arg
11967 ("missing assertion kind for pragma%", Arg);
11968 end if;
11970 -- Construct equivalent old form syntax Check_Policy
11971 -- pragma and insert it to get remaining checks.
11973 Insert_Action (N,
11974 Make_Pragma (LocP,
11975 Chars => Name_Check_Policy,
11976 Pragma_Argument_Associations => New_List (
11977 Make_Pragma_Argument_Association (LocP,
11978 Expression =>
11979 Make_Identifier (LocP, Chars (Arg))),
11980 Make_Pragma_Argument_Association (Sloc (Argx),
11981 Expression => Argx))));
11983 Arg := Next (Arg);
11984 end loop;
11986 -- Rewrite original Check_Policy pragma to null, since we
11987 -- have converted it into a series of old syntax pragmas.
11989 Rewrite (N, Make_Null_Statement (Loc));
11990 Analyze (N);
11991 end;
11992 end if;
11993 end Check_Policy;
11995 ---------------------
11996 -- CIL_Constructor --
11997 ---------------------
11999 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
12001 -- Processing for this pragma is shared with Java_Constructor
12003 -------------
12004 -- Comment --
12005 -------------
12007 -- pragma Comment (static_string_EXPRESSION)
12009 -- Processing for pragma Comment shares the circuitry for pragma
12010 -- Ident. The only differences are that Ident enforces a limit of 31
12011 -- characters on its argument, and also enforces limitations on
12012 -- placement for DEC compatibility. Pragma Comment shares neither of
12013 -- these restrictions.
12015 -------------------
12016 -- Common_Object --
12017 -------------------
12019 -- pragma Common_Object (
12020 -- [Internal =>] LOCAL_NAME
12021 -- [, [External =>] EXTERNAL_SYMBOL]
12022 -- [, [Size =>] EXTERNAL_SYMBOL]);
12024 -- Processing for this pragma is shared with Psect_Object
12026 ------------------------
12027 -- Compile_Time_Error --
12028 ------------------------
12030 -- pragma Compile_Time_Error
12031 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12033 when Pragma_Compile_Time_Error =>
12034 GNAT_Pragma;
12035 Process_Compile_Time_Warning_Or_Error;
12037 --------------------------
12038 -- Compile_Time_Warning --
12039 --------------------------
12041 -- pragma Compile_Time_Warning
12042 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12044 when Pragma_Compile_Time_Warning =>
12045 GNAT_Pragma;
12046 Process_Compile_Time_Warning_Or_Error;
12048 ---------------------------
12049 -- Compiler_Unit_Warning --
12050 ---------------------------
12052 -- pragma Compiler_Unit_Warning;
12054 -- Historical note
12056 -- Originally, we had only pragma Compiler_Unit, and it resulted in
12057 -- errors not warnings. This means that we had introduced a big extra
12058 -- inertia to compiler changes, since even if we implemented a new
12059 -- feature, and even if all versions to be used for bootstrapping
12060 -- implemented this new feature, we could not use it, since old
12061 -- compilers would give errors for using this feature in units
12062 -- having Compiler_Unit pragmas.
12064 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
12065 -- problem. We no longer have any units mentioning Compiler_Unit,
12066 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
12067 -- and thus generates a warning which can be ignored. So that deals
12068 -- with the problem of old compilers not implementing the newer form
12069 -- of the pragma.
12071 -- Newer compilers recognize the new pragma, but generate warning
12072 -- messages instead of errors, which again can be ignored in the
12073 -- case of an old compiler which implements a wanted new feature
12074 -- but at the time felt like warning about it for older compilers.
12076 -- We retain Compiler_Unit so that new compilers can be used to build
12077 -- older run-times that use this pragma. That's an unusual case, but
12078 -- it's easy enough to handle, so why not?
12080 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning =>
12081 GNAT_Pragma;
12082 Check_Arg_Count (0);
12084 -- Only recognized in main unit
12086 if Current_Sem_Unit = Main_Unit then
12087 Compiler_Unit := True;
12088 end if;
12090 -----------------------------
12091 -- Complete_Representation --
12092 -----------------------------
12094 -- pragma Complete_Representation;
12096 when Pragma_Complete_Representation =>
12097 GNAT_Pragma;
12098 Check_Arg_Count (0);
12100 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
12101 Error_Pragma
12102 ("pragma & must appear within record representation clause");
12103 end if;
12105 ----------------------------
12106 -- Complex_Representation --
12107 ----------------------------
12109 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
12111 when Pragma_Complex_Representation => Complex_Representation : declare
12112 E_Id : Entity_Id;
12113 E : Entity_Id;
12114 Ent : Entity_Id;
12116 begin
12117 GNAT_Pragma;
12118 Check_Arg_Count (1);
12119 Check_Optional_Identifier (Arg1, Name_Entity);
12120 Check_Arg_Is_Local_Name (Arg1);
12121 E_Id := Get_Pragma_Arg (Arg1);
12123 if Etype (E_Id) = Any_Type then
12124 return;
12125 end if;
12127 E := Entity (E_Id);
12129 if not Is_Record_Type (E) then
12130 Error_Pragma_Arg
12131 ("argument for pragma% must be record type", Arg1);
12132 end if;
12134 Ent := First_Entity (E);
12136 if No (Ent)
12137 or else No (Next_Entity (Ent))
12138 or else Present (Next_Entity (Next_Entity (Ent)))
12139 or else not Is_Floating_Point_Type (Etype (Ent))
12140 or else Etype (Ent) /= Etype (Next_Entity (Ent))
12141 then
12142 Error_Pragma_Arg
12143 ("record for pragma% must have two fields of the same "
12144 & "floating-point type", Arg1);
12146 else
12147 Set_Has_Complex_Representation (Base_Type (E));
12149 -- We need to treat the type has having a non-standard
12150 -- representation, for back-end purposes, even though in
12151 -- general a complex will have the default representation
12152 -- of a record with two real components.
12154 Set_Has_Non_Standard_Rep (Base_Type (E));
12155 end if;
12156 end Complex_Representation;
12158 -------------------------
12159 -- Component_Alignment --
12160 -------------------------
12162 -- pragma Component_Alignment (
12163 -- [Form =>] ALIGNMENT_CHOICE
12164 -- [, [Name =>] type_LOCAL_NAME]);
12166 -- ALIGNMENT_CHOICE ::=
12167 -- Component_Size
12168 -- | Component_Size_4
12169 -- | Storage_Unit
12170 -- | Default
12172 when Pragma_Component_Alignment => Component_AlignmentP : declare
12173 Args : Args_List (1 .. 2);
12174 Names : constant Name_List (1 .. 2) := (
12175 Name_Form,
12176 Name_Name);
12178 Form : Node_Id renames Args (1);
12179 Name : Node_Id renames Args (2);
12181 Atype : Component_Alignment_Kind;
12182 Typ : Entity_Id;
12184 begin
12185 GNAT_Pragma;
12186 Gather_Associations (Names, Args);
12188 if No (Form) then
12189 Error_Pragma ("missing Form argument for pragma%");
12190 end if;
12192 Check_Arg_Is_Identifier (Form);
12194 -- Get proper alignment, note that Default = Component_Size on all
12195 -- machines we have so far, and we want to set this value rather
12196 -- than the default value to indicate that it has been explicitly
12197 -- set (and thus will not get overridden by the default component
12198 -- alignment for the current scope)
12200 if Chars (Form) = Name_Component_Size then
12201 Atype := Calign_Component_Size;
12203 elsif Chars (Form) = Name_Component_Size_4 then
12204 Atype := Calign_Component_Size_4;
12206 elsif Chars (Form) = Name_Default then
12207 Atype := Calign_Component_Size;
12209 elsif Chars (Form) = Name_Storage_Unit then
12210 Atype := Calign_Storage_Unit;
12212 else
12213 Error_Pragma_Arg
12214 ("invalid Form parameter for pragma%", Form);
12215 end if;
12217 -- Case with no name, supplied, affects scope table entry
12219 if No (Name) then
12220 Scope_Stack.Table
12221 (Scope_Stack.Last).Component_Alignment_Default := Atype;
12223 -- Case of name supplied
12225 else
12226 Check_Arg_Is_Local_Name (Name);
12227 Find_Type (Name);
12228 Typ := Entity (Name);
12230 if Typ = Any_Type
12231 or else Rep_Item_Too_Early (Typ, N)
12232 then
12233 return;
12234 else
12235 Typ := Underlying_Type (Typ);
12236 end if;
12238 if not Is_Record_Type (Typ)
12239 and then not Is_Array_Type (Typ)
12240 then
12241 Error_Pragma_Arg
12242 ("Name parameter of pragma% must identify record or "
12243 & "array type", Name);
12244 end if;
12246 -- An explicit Component_Alignment pragma overrides an
12247 -- implicit pragma Pack, but not an explicit one.
12249 if not Has_Pragma_Pack (Base_Type (Typ)) then
12250 Set_Is_Packed (Base_Type (Typ), False);
12251 Set_Component_Alignment (Base_Type (Typ), Atype);
12252 end if;
12253 end if;
12254 end Component_AlignmentP;
12256 --------------------
12257 -- Contract_Cases --
12258 --------------------
12260 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
12262 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
12264 -- CASE_GUARD ::= boolean_EXPRESSION | others
12266 -- CONSEQUENCE ::= boolean_EXPRESSION
12268 when Pragma_Contract_Cases => Contract_Cases : declare
12269 Subp_Decl : Node_Id;
12271 begin
12272 GNAT_Pragma;
12273 Check_No_Identifiers;
12274 Check_Arg_Count (1);
12275 Ensure_Aggregate_Form (Arg1);
12277 -- The pragma is analyzed at the end of the declarative part which
12278 -- contains the related subprogram. Reset the analyzed flag.
12280 Set_Analyzed (N, False);
12282 -- Ensure the proper placement of the pragma. Contract_Cases must
12283 -- be associated with a subprogram declaration or a body that acts
12284 -- as a spec.
12286 Subp_Decl :=
12287 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
12289 if Nkind (Subp_Decl) = N_Subprogram_Declaration then
12290 null;
12292 -- Body acts as spec
12294 elsif Nkind (Subp_Decl) = N_Subprogram_Body
12295 and then No (Corresponding_Spec (Subp_Decl))
12296 then
12297 null;
12299 -- Body stub acts as spec
12301 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
12302 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
12303 then
12304 null;
12306 else
12307 Pragma_Misplaced;
12308 return;
12309 end if;
12311 -- When the pragma appears on a subprogram body, perform the full
12312 -- analysis now.
12314 if Nkind (Subp_Decl) = N_Subprogram_Body then
12315 Analyze_Contract_Cases_In_Decl_Part (N);
12317 -- When Contract_Cases applies to a subprogram compilation unit,
12318 -- the corresponding pragma is placed after the unit's declaration
12319 -- node and needs to be analyzed immediately.
12321 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
12322 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
12323 then
12324 Analyze_Contract_Cases_In_Decl_Part (N);
12325 end if;
12327 -- Chain the pragma on the contract for further processing
12329 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
12330 end Contract_Cases;
12332 ----------------
12333 -- Controlled --
12334 ----------------
12336 -- pragma Controlled (first_subtype_LOCAL_NAME);
12338 when Pragma_Controlled => Controlled : declare
12339 Arg : Node_Id;
12341 begin
12342 Check_No_Identifiers;
12343 Check_Arg_Count (1);
12344 Check_Arg_Is_Local_Name (Arg1);
12345 Arg := Get_Pragma_Arg (Arg1);
12347 if not Is_Entity_Name (Arg)
12348 or else not Is_Access_Type (Entity (Arg))
12349 then
12350 Error_Pragma_Arg ("pragma% requires access type", Arg1);
12351 else
12352 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
12353 end if;
12354 end Controlled;
12356 ----------------
12357 -- Convention --
12358 ----------------
12360 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
12361 -- [Entity =>] LOCAL_NAME);
12363 when Pragma_Convention => Convention : declare
12364 C : Convention_Id;
12365 E : Entity_Id;
12366 pragma Warnings (Off, C);
12367 pragma Warnings (Off, E);
12368 begin
12369 Check_Arg_Order ((Name_Convention, Name_Entity));
12370 Check_Ada_83_Warning;
12371 Check_Arg_Count (2);
12372 Process_Convention (C, E);
12373 end Convention;
12375 ---------------------------
12376 -- Convention_Identifier --
12377 ---------------------------
12379 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
12380 -- [Convention =>] convention_IDENTIFIER);
12382 when Pragma_Convention_Identifier => Convention_Identifier : declare
12383 Idnam : Name_Id;
12384 Cname : Name_Id;
12386 begin
12387 GNAT_Pragma;
12388 Check_Arg_Order ((Name_Name, Name_Convention));
12389 Check_Arg_Count (2);
12390 Check_Optional_Identifier (Arg1, Name_Name);
12391 Check_Optional_Identifier (Arg2, Name_Convention);
12392 Check_Arg_Is_Identifier (Arg1);
12393 Check_Arg_Is_Identifier (Arg2);
12394 Idnam := Chars (Get_Pragma_Arg (Arg1));
12395 Cname := Chars (Get_Pragma_Arg (Arg2));
12397 if Is_Convention_Name (Cname) then
12398 Record_Convention_Identifier
12399 (Idnam, Get_Convention_Id (Cname));
12400 else
12401 Error_Pragma_Arg
12402 ("second arg for % pragma must be convention", Arg2);
12403 end if;
12404 end Convention_Identifier;
12406 ---------------
12407 -- CPP_Class --
12408 ---------------
12410 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
12412 when Pragma_CPP_Class => CPP_Class : declare
12413 begin
12414 GNAT_Pragma;
12416 if Warn_On_Obsolescent_Feature then
12417 Error_Msg_N
12418 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
12419 & "effect; replace it by pragma import?j?", N);
12420 end if;
12422 Check_Arg_Count (1);
12424 Rewrite (N,
12425 Make_Pragma (Loc,
12426 Chars => Name_Import,
12427 Pragma_Argument_Associations => New_List (
12428 Make_Pragma_Argument_Association (Loc,
12429 Expression => Make_Identifier (Loc, Name_CPP)),
12430 New_Copy (First (Pragma_Argument_Associations (N))))));
12431 Analyze (N);
12432 end CPP_Class;
12434 ---------------------
12435 -- CPP_Constructor --
12436 ---------------------
12438 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
12439 -- [, [External_Name =>] static_string_EXPRESSION ]
12440 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12442 when Pragma_CPP_Constructor => CPP_Constructor : declare
12443 Elmt : Elmt_Id;
12444 Id : Entity_Id;
12445 Def_Id : Entity_Id;
12446 Tag_Typ : Entity_Id;
12448 begin
12449 GNAT_Pragma;
12450 Check_At_Least_N_Arguments (1);
12451 Check_At_Most_N_Arguments (3);
12452 Check_Optional_Identifier (Arg1, Name_Entity);
12453 Check_Arg_Is_Local_Name (Arg1);
12455 Id := Get_Pragma_Arg (Arg1);
12456 Find_Program_Unit_Name (Id);
12458 -- If we did not find the name, we are done
12460 if Etype (Id) = Any_Type then
12461 return;
12462 end if;
12464 Def_Id := Entity (Id);
12466 -- Check if already defined as constructor
12468 if Is_Constructor (Def_Id) then
12469 Error_Msg_N
12470 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
12471 return;
12472 end if;
12474 if Ekind (Def_Id) = E_Function
12475 and then (Is_CPP_Class (Etype (Def_Id))
12476 or else (Is_Class_Wide_Type (Etype (Def_Id))
12477 and then
12478 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
12479 then
12480 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
12481 Error_Msg_N
12482 ("'C'P'P constructor must be defined in the scope of "
12483 & "its returned type", Arg1);
12484 end if;
12486 if Arg_Count >= 2 then
12487 Set_Imported (Def_Id);
12488 Set_Is_Public (Def_Id);
12489 Process_Interface_Name (Def_Id, Arg2, Arg3);
12490 end if;
12492 Set_Has_Completion (Def_Id);
12493 Set_Is_Constructor (Def_Id);
12494 Set_Convention (Def_Id, Convention_CPP);
12496 -- Imported C++ constructors are not dispatching primitives
12497 -- because in C++ they don't have a dispatch table slot.
12498 -- However, in Ada the constructor has the profile of a
12499 -- function that returns a tagged type and therefore it has
12500 -- been treated as a primitive operation during semantic
12501 -- analysis. We now remove it from the list of primitive
12502 -- operations of the type.
12504 if Is_Tagged_Type (Etype (Def_Id))
12505 and then not Is_Class_Wide_Type (Etype (Def_Id))
12506 and then Is_Dispatching_Operation (Def_Id)
12507 then
12508 Tag_Typ := Etype (Def_Id);
12510 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
12511 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
12512 Next_Elmt (Elmt);
12513 end loop;
12515 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
12516 Set_Is_Dispatching_Operation (Def_Id, False);
12517 end if;
12519 -- For backward compatibility, if the constructor returns a
12520 -- class wide type, and we internally change the return type to
12521 -- the corresponding root type.
12523 if Is_Class_Wide_Type (Etype (Def_Id)) then
12524 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
12525 end if;
12526 else
12527 Error_Pragma_Arg
12528 ("pragma% requires function returning a 'C'P'P_Class type",
12529 Arg1);
12530 end if;
12531 end CPP_Constructor;
12533 -----------------
12534 -- CPP_Virtual --
12535 -----------------
12537 when Pragma_CPP_Virtual => CPP_Virtual : declare
12538 begin
12539 GNAT_Pragma;
12541 if Warn_On_Obsolescent_Feature then
12542 Error_Msg_N
12543 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
12544 & "effect?j?", N);
12545 end if;
12546 end CPP_Virtual;
12548 ----------------
12549 -- CPP_Vtable --
12550 ----------------
12552 when Pragma_CPP_Vtable => CPP_Vtable : declare
12553 begin
12554 GNAT_Pragma;
12556 if Warn_On_Obsolescent_Feature then
12557 Error_Msg_N
12558 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
12559 & "effect?j?", N);
12560 end if;
12561 end CPP_Vtable;
12563 ---------
12564 -- CPU --
12565 ---------
12567 -- pragma CPU (EXPRESSION);
12569 when Pragma_CPU => CPU : declare
12570 P : constant Node_Id := Parent (N);
12571 Arg : Node_Id;
12572 Ent : Entity_Id;
12574 begin
12575 Ada_2012_Pragma;
12576 Check_No_Identifiers;
12577 Check_Arg_Count (1);
12579 -- Subprogram case
12581 if Nkind (P) = N_Subprogram_Body then
12582 Check_In_Main_Program;
12584 Arg := Get_Pragma_Arg (Arg1);
12585 Analyze_And_Resolve (Arg, Any_Integer);
12587 Ent := Defining_Unit_Name (Specification (P));
12589 if Nkind (Ent) = N_Defining_Program_Unit_Name then
12590 Ent := Defining_Identifier (Ent);
12591 end if;
12593 -- Must be static
12595 if not Is_OK_Static_Expression (Arg) then
12596 Flag_Non_Static_Expr
12597 ("main subprogram affinity is not static!", Arg);
12598 raise Pragma_Exit;
12600 -- If constraint error, then we already signalled an error
12602 elsif Raises_Constraint_Error (Arg) then
12603 null;
12605 -- Otherwise check in range
12607 else
12608 declare
12609 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
12610 -- This is the entity System.Multiprocessors.CPU_Range;
12612 Val : constant Uint := Expr_Value (Arg);
12614 begin
12615 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
12616 or else
12617 Val > Expr_Value (Type_High_Bound (CPU_Id))
12618 then
12619 Error_Pragma_Arg
12620 ("main subprogram CPU is out of range", Arg1);
12621 end if;
12622 end;
12623 end if;
12625 Set_Main_CPU
12626 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12628 -- Task case
12630 elsif Nkind (P) = N_Task_Definition then
12631 Arg := Get_Pragma_Arg (Arg1);
12632 Ent := Defining_Identifier (Parent (P));
12634 -- The expression must be analyzed in the special manner
12635 -- described in "Handling of Default and Per-Object
12636 -- Expressions" in sem.ads.
12638 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
12640 -- Anything else is incorrect
12642 else
12643 Pragma_Misplaced;
12644 end if;
12646 -- Check duplicate pragma before we chain the pragma in the Rep
12647 -- Item chain of Ent.
12649 Check_Duplicate_Pragma (Ent);
12650 Record_Rep_Item (Ent, N);
12651 end CPU;
12653 -----------
12654 -- Debug --
12655 -----------
12657 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
12659 when Pragma_Debug => Debug : declare
12660 Cond : Node_Id;
12661 Call : Node_Id;
12663 begin
12664 GNAT_Pragma;
12666 -- The condition for executing the call is that the expander
12667 -- is active and that we are not ignoring this debug pragma.
12669 Cond :=
12670 New_Occurrence_Of
12671 (Boolean_Literals
12672 (Expander_Active and then not Is_Ignored (N)),
12673 Loc);
12675 if not Is_Ignored (N) then
12676 Set_SCO_Pragma_Enabled (Loc);
12677 end if;
12679 if Arg_Count = 2 then
12680 Cond :=
12681 Make_And_Then (Loc,
12682 Left_Opnd => Relocate_Node (Cond),
12683 Right_Opnd => Get_Pragma_Arg (Arg1));
12684 Call := Get_Pragma_Arg (Arg2);
12685 else
12686 Call := Get_Pragma_Arg (Arg1);
12687 end if;
12689 if Nkind_In (Call,
12690 N_Indexed_Component,
12691 N_Function_Call,
12692 N_Identifier,
12693 N_Expanded_Name,
12694 N_Selected_Component)
12695 then
12696 -- If this pragma Debug comes from source, its argument was
12697 -- parsed as a name form (which is syntactically identical).
12698 -- In a generic context a parameterless call will be left as
12699 -- an expanded name (if global) or selected_component if local.
12700 -- Change it to a procedure call statement now.
12702 Change_Name_To_Procedure_Call_Statement (Call);
12704 elsif Nkind (Call) = N_Procedure_Call_Statement then
12706 -- Already in the form of a procedure call statement: nothing
12707 -- to do (could happen in case of an internally generated
12708 -- pragma Debug).
12710 null;
12712 else
12713 -- All other cases: diagnose error
12715 Error_Msg
12716 ("argument of pragma ""Debug"" is not procedure call",
12717 Sloc (Call));
12718 return;
12719 end if;
12721 -- Rewrite into a conditional with an appropriate condition. We
12722 -- wrap the procedure call in a block so that overhead from e.g.
12723 -- use of the secondary stack does not generate execution overhead
12724 -- for suppressed conditions.
12726 -- Normally the analysis that follows will freeze the subprogram
12727 -- being called. However, if the call is to a null procedure,
12728 -- we want to freeze it before creating the block, because the
12729 -- analysis that follows may be done with expansion disabled, in
12730 -- which case the body will not be generated, leading to spurious
12731 -- errors.
12733 if Nkind (Call) = N_Procedure_Call_Statement
12734 and then Is_Entity_Name (Name (Call))
12735 then
12736 Analyze (Name (Call));
12737 Freeze_Before (N, Entity (Name (Call)));
12738 end if;
12740 Rewrite (N,
12741 Make_Implicit_If_Statement (N,
12742 Condition => Cond,
12743 Then_Statements => New_List (
12744 Make_Block_Statement (Loc,
12745 Handled_Statement_Sequence =>
12746 Make_Handled_Sequence_Of_Statements (Loc,
12747 Statements => New_List (Relocate_Node (Call)))))));
12748 Analyze (N);
12750 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
12751 -- after analysis of the normally rewritten node, to capture all
12752 -- references to entities, which avoids issuing wrong warnings
12753 -- about unused entities.
12755 if GNATprove_Mode then
12756 Rewrite (N, Make_Null_Statement (Loc));
12757 end if;
12758 end Debug;
12760 ------------------
12761 -- Debug_Policy --
12762 ------------------
12764 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
12766 when Pragma_Debug_Policy =>
12767 GNAT_Pragma;
12768 Check_Arg_Count (1);
12769 Check_No_Identifiers;
12770 Check_Arg_Is_Identifier (Arg1);
12772 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
12773 -- rewrite it that way, and let the rest of the checking come
12774 -- from analyzing the rewritten pragma.
12776 Rewrite (N,
12777 Make_Pragma (Loc,
12778 Chars => Name_Check_Policy,
12779 Pragma_Argument_Associations => New_List (
12780 Make_Pragma_Argument_Association (Loc,
12781 Expression => Make_Identifier (Loc, Name_Debug)),
12783 Make_Pragma_Argument_Association (Loc,
12784 Expression => Get_Pragma_Arg (Arg1)))));
12785 Analyze (N);
12787 -------------------------------
12788 -- Default_Initial_Condition --
12789 -------------------------------
12791 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
12793 when Pragma_Default_Initial_Condition => Default_Init_Cond : declare
12794 Discard : Boolean;
12795 Stmt : Node_Id;
12796 Typ : Entity_Id;
12798 begin
12799 GNAT_Pragma;
12800 Check_No_Identifiers;
12801 Check_At_Most_N_Arguments (1);
12803 Stmt := Prev (N);
12804 while Present (Stmt) loop
12806 -- Skip prior pragmas, but check for duplicates
12808 if Nkind (Stmt) = N_Pragma then
12809 if Pragma_Name (Stmt) = Pname then
12810 Error_Msg_Name_1 := Pname;
12811 Error_Msg_Sloc := Sloc (Stmt);
12812 Error_Msg_N ("pragma % duplicates pragma declared#", N);
12813 end if;
12815 -- Skip internally generated code
12817 elsif not Comes_From_Source (Stmt) then
12818 null;
12820 -- The associated private type [extension] has been found, stop
12821 -- the search.
12823 elsif Nkind_In (Stmt, N_Private_Extension_Declaration,
12824 N_Private_Type_Declaration)
12825 then
12826 Typ := Defining_Entity (Stmt);
12827 exit;
12829 -- The pragma does not apply to a legal construct, issue an
12830 -- error and stop the analysis.
12832 else
12833 Pragma_Misplaced;
12834 return;
12835 end if;
12837 Stmt := Prev (Stmt);
12838 end loop;
12840 Set_Has_Default_Init_Cond (Typ);
12841 Set_Has_Inherited_Default_Init_Cond (Typ, False);
12843 -- Chain the pragma on the rep item chain for further processing
12845 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12846 end Default_Init_Cond;
12848 ----------------------------------
12849 -- Default_Scalar_Storage_Order --
12850 ----------------------------------
12852 -- pragma Default_Scalar_Storage_Order
12853 -- (High_Order_First | Low_Order_First);
12855 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
12856 Default : Character;
12858 begin
12859 GNAT_Pragma;
12860 Check_Arg_Count (1);
12862 -- Default_Scalar_Storage_Order can appear as a configuration
12863 -- pragma, or in a declarative part of a package spec.
12865 if not Is_Configuration_Pragma then
12866 Check_Is_In_Decl_Part_Or_Package_Spec;
12867 end if;
12869 Check_No_Identifiers;
12870 Check_Arg_Is_One_Of
12871 (Arg1, Name_High_Order_First, Name_Low_Order_First);
12872 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12873 Default := Fold_Upper (Name_Buffer (1));
12875 if not Support_Nondefault_SSO_On_Target
12876 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
12877 then
12878 if Warn_On_Unrecognized_Pragma then
12879 Error_Msg_N
12880 ("non-default Scalar_Storage_Order not supported "
12881 & "on target?g?", N);
12882 Error_Msg_N
12883 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
12884 end if;
12886 -- Here set the specified default
12888 else
12889 Opt.Default_SSO := Default;
12890 end if;
12891 end DSSO;
12893 --------------------------
12894 -- Default_Storage_Pool --
12895 --------------------------
12897 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
12899 when Pragma_Default_Storage_Pool =>
12900 Ada_2012_Pragma;
12901 Check_Arg_Count (1);
12903 -- Default_Storage_Pool can appear as a configuration pragma, or
12904 -- in a declarative part of a package spec.
12906 if not Is_Configuration_Pragma then
12907 Check_Is_In_Decl_Part_Or_Package_Spec;
12908 end if;
12910 -- Case of Default_Storage_Pool (null);
12912 if Nkind (Expression (Arg1)) = N_Null then
12913 Analyze (Expression (Arg1));
12915 -- This is an odd case, this is not really an expression, so
12916 -- we don't have a type for it. So just set the type to Empty.
12918 Set_Etype (Expression (Arg1), Empty);
12920 -- Case of Default_Storage_Pool (storage_pool_NAME);
12922 else
12923 -- If it's a configuration pragma, then the only allowed
12924 -- argument is "null".
12926 if Is_Configuration_Pragma then
12927 Error_Pragma_Arg ("NULL expected", Arg1);
12928 end if;
12930 -- The expected type for a non-"null" argument is
12931 -- Root_Storage_Pool'Class, and the pool must be a variable.
12933 Analyze_And_Resolve
12934 (Get_Pragma_Arg (Arg1),
12935 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
12937 if not Is_Variable (Expression (Arg1)) then
12938 Error_Pragma_Arg
12939 ("default storage pool must be a variable", Arg1);
12940 end if;
12941 end if;
12943 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
12944 -- for an access type will use this information to set the
12945 -- appropriate attributes of the access type.
12947 Default_Pool := Expression (Arg1);
12949 -------------
12950 -- Depends --
12951 -------------
12953 -- pragma Depends (DEPENDENCY_RELATION);
12955 -- DEPENDENCY_RELATION ::=
12956 -- null
12957 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
12959 -- DEPENDENCY_CLAUSE ::=
12960 -- OUTPUT_LIST =>[+] INPUT_LIST
12961 -- | NULL_DEPENDENCY_CLAUSE
12963 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
12965 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
12967 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
12969 -- OUTPUT ::= NAME | FUNCTION_RESULT
12970 -- INPUT ::= NAME
12972 -- where FUNCTION_RESULT is a function Result attribute_reference
12974 when Pragma_Depends => Depends : declare
12975 Subp_Decl : Node_Id;
12977 begin
12978 GNAT_Pragma;
12979 Check_Arg_Count (1);
12980 Ensure_Aggregate_Form (Arg1);
12982 -- Ensure the proper placement of the pragma. Depends must be
12983 -- associated with a subprogram declaration or a body that acts
12984 -- as a spec.
12986 Subp_Decl :=
12987 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
12989 if Nkind (Subp_Decl) = N_Subprogram_Declaration then
12990 null;
12992 -- Body acts as spec
12994 elsif Nkind (Subp_Decl) = N_Subprogram_Body
12995 and then No (Corresponding_Spec (Subp_Decl))
12996 then
12997 null;
12999 -- Body stub acts as spec
13001 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
13002 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
13003 then
13004 null;
13006 else
13007 Pragma_Misplaced;
13008 return;
13009 end if;
13011 -- When the pragma appears on a subprogram body, perform the full
13012 -- analysis now.
13014 if Nkind (Subp_Decl) = N_Subprogram_Body then
13015 Analyze_Depends_In_Decl_Part (N);
13017 -- When Depends applies to a subprogram compilation unit, the
13018 -- corresponding pragma is placed after the unit's declaration
13019 -- node and needs to be analyzed immediately.
13021 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
13022 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
13023 then
13024 Analyze_Depends_In_Decl_Part (N);
13025 end if;
13027 -- Chain the pragma on the contract for further processing
13029 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
13030 end Depends;
13032 ---------------------
13033 -- Detect_Blocking --
13034 ---------------------
13036 -- pragma Detect_Blocking;
13038 when Pragma_Detect_Blocking =>
13039 Ada_2005_Pragma;
13040 Check_Arg_Count (0);
13041 Check_Valid_Configuration_Pragma;
13042 Detect_Blocking := True;
13044 ------------------------------------
13045 -- Disable_Atomic_Synchronization --
13046 ------------------------------------
13048 -- pragma Disable_Atomic_Synchronization [(Entity)];
13050 when Pragma_Disable_Atomic_Synchronization =>
13051 GNAT_Pragma;
13052 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
13054 -------------------
13055 -- Discard_Names --
13056 -------------------
13058 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
13060 when Pragma_Discard_Names => Discard_Names : declare
13061 E : Entity_Id;
13062 E_Id : Entity_Id;
13064 begin
13065 Check_Ada_83_Warning;
13067 -- Deal with configuration pragma case
13069 if Arg_Count = 0 and then Is_Configuration_Pragma then
13070 Global_Discard_Names := True;
13071 return;
13073 -- Otherwise, check correct appropriate context
13075 else
13076 Check_Is_In_Decl_Part_Or_Package_Spec;
13078 if Arg_Count = 0 then
13080 -- If there is no parameter, then from now on this pragma
13081 -- applies to any enumeration, exception or tagged type
13082 -- defined in the current declarative part, and recursively
13083 -- to any nested scope.
13085 Set_Discard_Names (Current_Scope);
13086 return;
13088 else
13089 Check_Arg_Count (1);
13090 Check_Optional_Identifier (Arg1, Name_On);
13091 Check_Arg_Is_Local_Name (Arg1);
13093 E_Id := Get_Pragma_Arg (Arg1);
13095 if Etype (E_Id) = Any_Type then
13096 return;
13097 else
13098 E := Entity (E_Id);
13099 end if;
13101 if (Is_First_Subtype (E)
13102 and then
13103 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
13104 or else Ekind (E) = E_Exception
13105 then
13106 Set_Discard_Names (E);
13107 Record_Rep_Item (E, N);
13109 else
13110 Error_Pragma_Arg
13111 ("inappropriate entity for pragma%", Arg1);
13112 end if;
13114 end if;
13115 end if;
13116 end Discard_Names;
13118 ------------------------
13119 -- Dispatching_Domain --
13120 ------------------------
13122 -- pragma Dispatching_Domain (EXPRESSION);
13124 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
13125 P : constant Node_Id := Parent (N);
13126 Arg : Node_Id;
13127 Ent : Entity_Id;
13129 begin
13130 Ada_2012_Pragma;
13131 Check_No_Identifiers;
13132 Check_Arg_Count (1);
13134 -- This pragma is born obsolete, but not the aspect
13136 if not From_Aspect_Specification (N) then
13137 Check_Restriction
13138 (No_Obsolescent_Features, Pragma_Identifier (N));
13139 end if;
13141 if Nkind (P) = N_Task_Definition then
13142 Arg := Get_Pragma_Arg (Arg1);
13143 Ent := Defining_Identifier (Parent (P));
13145 -- The expression must be analyzed in the special manner
13146 -- described in "Handling of Default and Per-Object
13147 -- Expressions" in sem.ads.
13149 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
13151 -- Check duplicate pragma before we chain the pragma in the Rep
13152 -- Item chain of Ent.
13154 Check_Duplicate_Pragma (Ent);
13155 Record_Rep_Item (Ent, N);
13157 -- Anything else is incorrect
13159 else
13160 Pragma_Misplaced;
13161 end if;
13162 end Dispatching_Domain;
13164 ---------------
13165 -- Elaborate --
13166 ---------------
13168 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
13170 when Pragma_Elaborate => Elaborate : declare
13171 Arg : Node_Id;
13172 Citem : Node_Id;
13174 begin
13175 -- Pragma must be in context items list of a compilation unit
13177 if not Is_In_Context_Clause then
13178 Pragma_Misplaced;
13179 end if;
13181 -- Must be at least one argument
13183 if Arg_Count = 0 then
13184 Error_Pragma ("pragma% requires at least one argument");
13185 end if;
13187 -- In Ada 83 mode, there can be no items following it in the
13188 -- context list except other pragmas and implicit with clauses
13189 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
13190 -- placement rule does not apply.
13192 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
13193 Citem := Next (N);
13194 while Present (Citem) loop
13195 if Nkind (Citem) = N_Pragma
13196 or else (Nkind (Citem) = N_With_Clause
13197 and then Implicit_With (Citem))
13198 then
13199 null;
13200 else
13201 Error_Pragma
13202 ("(Ada 83) pragma% must be at end of context clause");
13203 end if;
13205 Next (Citem);
13206 end loop;
13207 end if;
13209 -- Finally, the arguments must all be units mentioned in a with
13210 -- clause in the same context clause. Note we already checked (in
13211 -- Par.Prag) that the arguments are all identifiers or selected
13212 -- components.
13214 Arg := Arg1;
13215 Outer : while Present (Arg) loop
13216 Citem := First (List_Containing (N));
13217 Inner : while Citem /= N loop
13218 if Nkind (Citem) = N_With_Clause
13219 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
13220 then
13221 Set_Elaborate_Present (Citem, True);
13222 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
13223 Generate_Reference (Entity (Name (Citem)), Citem);
13225 -- With the pragma present, elaboration calls on
13226 -- subprograms from the named unit need no further
13227 -- checks, as long as the pragma appears in the current
13228 -- compilation unit. If the pragma appears in some unit
13229 -- in the context, there might still be a need for an
13230 -- Elaborate_All_Desirable from the current compilation
13231 -- to the named unit, so we keep the check enabled.
13233 if In_Extended_Main_Source_Unit (N) then
13235 -- This does not apply in SPARK mode, where we allow
13236 -- pragma Elaborate, but we don't trust it to be right
13237 -- so we will still insist on the Elaborate_All.
13239 if SPARK_Mode /= On then
13240 Set_Suppress_Elaboration_Warnings
13241 (Entity (Name (Citem)));
13242 end if;
13243 end if;
13245 exit Inner;
13246 end if;
13248 Next (Citem);
13249 end loop Inner;
13251 if Citem = N then
13252 Error_Pragma_Arg
13253 ("argument of pragma% is not withed unit", Arg);
13254 end if;
13256 Next (Arg);
13257 end loop Outer;
13259 -- Give a warning if operating in static mode with one of the
13260 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
13262 if Elab_Warnings
13263 and not Dynamic_Elaboration_Checks
13265 -- pragma Elaborate not allowed in SPARK mode anyway. We
13266 -- already complained about it, no point in generating any
13267 -- further complaint.
13269 and SPARK_Mode /= On
13270 then
13271 Error_Msg_N
13272 ("?l?use of pragma Elaborate may not be safe", N);
13273 Error_Msg_N
13274 ("?l?use pragma Elaborate_All instead if possible", N);
13275 end if;
13276 end Elaborate;
13278 -------------------
13279 -- Elaborate_All --
13280 -------------------
13282 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
13284 when Pragma_Elaborate_All => Elaborate_All : declare
13285 Arg : Node_Id;
13286 Citem : Node_Id;
13288 begin
13289 Check_Ada_83_Warning;
13291 -- Pragma must be in context items list of a compilation unit
13293 if not Is_In_Context_Clause then
13294 Pragma_Misplaced;
13295 end if;
13297 -- Must be at least one argument
13299 if Arg_Count = 0 then
13300 Error_Pragma ("pragma% requires at least one argument");
13301 end if;
13303 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
13304 -- have to appear at the end of the context clause, but may
13305 -- appear mixed in with other items, even in Ada 83 mode.
13307 -- Final check: the arguments must all be units mentioned in
13308 -- a with clause in the same context clause. Note that we
13309 -- already checked (in Par.Prag) that all the arguments are
13310 -- either identifiers or selected components.
13312 Arg := Arg1;
13313 Outr : while Present (Arg) loop
13314 Citem := First (List_Containing (N));
13315 Innr : while Citem /= N loop
13316 if Nkind (Citem) = N_With_Clause
13317 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
13318 then
13319 Set_Elaborate_All_Present (Citem, True);
13320 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
13322 -- Suppress warnings and elaboration checks on the named
13323 -- unit if the pragma is in the current compilation, as
13324 -- for pragma Elaborate.
13326 if In_Extended_Main_Source_Unit (N) then
13327 Set_Suppress_Elaboration_Warnings
13328 (Entity (Name (Citem)));
13329 end if;
13330 exit Innr;
13331 end if;
13333 Next (Citem);
13334 end loop Innr;
13336 if Citem = N then
13337 Set_Error_Posted (N);
13338 Error_Pragma_Arg
13339 ("argument of pragma% is not withed unit", Arg);
13340 end if;
13342 Next (Arg);
13343 end loop Outr;
13344 end Elaborate_All;
13346 --------------------
13347 -- Elaborate_Body --
13348 --------------------
13350 -- pragma Elaborate_Body [( library_unit_NAME )];
13352 when Pragma_Elaborate_Body => Elaborate_Body : declare
13353 Cunit_Node : Node_Id;
13354 Cunit_Ent : Entity_Id;
13356 begin
13357 Check_Ada_83_Warning;
13358 Check_Valid_Library_Unit_Pragma;
13360 if Nkind (N) = N_Null_Statement then
13361 return;
13362 end if;
13364 Cunit_Node := Cunit (Current_Sem_Unit);
13365 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13367 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
13368 N_Subprogram_Body)
13369 then
13370 Error_Pragma ("pragma% must refer to a spec, not a body");
13371 else
13372 Set_Body_Required (Cunit_Node, True);
13373 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
13375 -- If we are in dynamic elaboration mode, then we suppress
13376 -- elaboration warnings for the unit, since it is definitely
13377 -- fine NOT to do dynamic checks at the first level (and such
13378 -- checks will be suppressed because no elaboration boolean
13379 -- is created for Elaborate_Body packages).
13381 -- But in the static model of elaboration, Elaborate_Body is
13382 -- definitely NOT good enough to ensure elaboration safety on
13383 -- its own, since the body may WITH other units that are not
13384 -- safe from an elaboration point of view, so a client must
13385 -- still do an Elaborate_All on such units.
13387 -- Debug flag -gnatdD restores the old behavior of 3.13, where
13388 -- Elaborate_Body always suppressed elab warnings.
13390 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
13391 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
13392 end if;
13393 end if;
13394 end Elaborate_Body;
13396 ------------------------
13397 -- Elaboration_Checks --
13398 ------------------------
13400 -- pragma Elaboration_Checks (Static | Dynamic);
13402 when Pragma_Elaboration_Checks =>
13403 GNAT_Pragma;
13404 Check_Arg_Count (1);
13405 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
13407 -- Set flag accordingly (ignore attempt at dynamic elaboration
13408 -- checks in SPARK mode).
13410 Dynamic_Elaboration_Checks :=
13411 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic)
13412 and then SPARK_Mode /= On;
13414 ---------------
13415 -- Eliminate --
13416 ---------------
13418 -- pragma Eliminate (
13419 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
13420 -- [,[Entity =>] IDENTIFIER |
13421 -- SELECTED_COMPONENT |
13422 -- STRING_LITERAL]
13423 -- [, OVERLOADING_RESOLUTION]);
13425 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
13426 -- SOURCE_LOCATION
13428 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
13429 -- FUNCTION_PROFILE
13431 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
13433 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
13434 -- Result_Type => result_SUBTYPE_NAME]
13436 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
13437 -- SUBTYPE_NAME ::= STRING_LITERAL
13439 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
13440 -- SOURCE_TRACE ::= STRING_LITERAL
13442 when Pragma_Eliminate => Eliminate : declare
13443 Args : Args_List (1 .. 5);
13444 Names : constant Name_List (1 .. 5) := (
13445 Name_Unit_Name,
13446 Name_Entity,
13447 Name_Parameter_Types,
13448 Name_Result_Type,
13449 Name_Source_Location);
13451 Unit_Name : Node_Id renames Args (1);
13452 Entity : Node_Id renames Args (2);
13453 Parameter_Types : Node_Id renames Args (3);
13454 Result_Type : Node_Id renames Args (4);
13455 Source_Location : Node_Id renames Args (5);
13457 begin
13458 GNAT_Pragma;
13459 Check_Valid_Configuration_Pragma;
13460 Gather_Associations (Names, Args);
13462 if No (Unit_Name) then
13463 Error_Pragma ("missing Unit_Name argument for pragma%");
13464 end if;
13466 if No (Entity)
13467 and then (Present (Parameter_Types)
13468 or else
13469 Present (Result_Type)
13470 or else
13471 Present (Source_Location))
13472 then
13473 Error_Pragma ("missing Entity argument for pragma%");
13474 end if;
13476 if (Present (Parameter_Types)
13477 or else
13478 Present (Result_Type))
13479 and then
13480 Present (Source_Location)
13481 then
13482 Error_Pragma
13483 ("parameter profile and source location cannot be used "
13484 & "together in pragma%");
13485 end if;
13487 Process_Eliminate_Pragma
13489 Unit_Name,
13490 Entity,
13491 Parameter_Types,
13492 Result_Type,
13493 Source_Location);
13494 end Eliminate;
13496 -----------------------------------
13497 -- Enable_Atomic_Synchronization --
13498 -----------------------------------
13500 -- pragma Enable_Atomic_Synchronization [(Entity)];
13502 when Pragma_Enable_Atomic_Synchronization =>
13503 GNAT_Pragma;
13504 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
13506 ------------
13507 -- Export --
13508 ------------
13510 -- pragma Export (
13511 -- [ Convention =>] convention_IDENTIFIER,
13512 -- [ Entity =>] LOCAL_NAME
13513 -- [, [External_Name =>] static_string_EXPRESSION ]
13514 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13516 when Pragma_Export => Export : declare
13517 C : Convention_Id;
13518 Def_Id : Entity_Id;
13520 pragma Warnings (Off, C);
13522 begin
13523 Check_Ada_83_Warning;
13524 Check_Arg_Order
13525 ((Name_Convention,
13526 Name_Entity,
13527 Name_External_Name,
13528 Name_Link_Name));
13530 Check_At_Least_N_Arguments (2);
13531 Check_At_Most_N_Arguments (4);
13533 -- In Relaxed_RM_Semantics, support old Ada 83 style:
13534 -- pragma Export (Entity, "external name");
13536 if Relaxed_RM_Semantics
13537 and then Arg_Count = 2
13538 and then Nkind (Expression (Arg2)) = N_String_Literal
13539 then
13540 C := Convention_C;
13541 Def_Id := Get_Pragma_Arg (Arg1);
13542 Analyze (Def_Id);
13544 if not Is_Entity_Name (Def_Id) then
13545 Error_Pragma_Arg ("entity name required", Arg1);
13546 end if;
13548 Def_Id := Entity (Def_Id);
13549 Set_Exported (Def_Id, Arg1);
13551 else
13552 Process_Convention (C, Def_Id);
13554 if Ekind (Def_Id) /= E_Constant then
13555 Note_Possible_Modification
13556 (Get_Pragma_Arg (Arg2), Sure => False);
13557 end if;
13559 Process_Interface_Name (Def_Id, Arg3, Arg4);
13560 Set_Exported (Def_Id, Arg2);
13561 end if;
13563 -- If the entity is a deferred constant, propagate the information
13564 -- to the full view, because gigi elaborates the full view only.
13566 if Ekind (Def_Id) = E_Constant
13567 and then Present (Full_View (Def_Id))
13568 then
13569 declare
13570 Id2 : constant Entity_Id := Full_View (Def_Id);
13571 begin
13572 Set_Is_Exported (Id2, Is_Exported (Def_Id));
13573 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
13574 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
13575 end;
13576 end if;
13577 end Export;
13579 ---------------------
13580 -- Export_Function --
13581 ---------------------
13583 -- pragma Export_Function (
13584 -- [Internal =>] LOCAL_NAME
13585 -- [, [External =>] EXTERNAL_SYMBOL]
13586 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13587 -- [, [Result_Type =>] TYPE_DESIGNATOR]
13588 -- [, [Mechanism =>] MECHANISM]
13589 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
13591 -- EXTERNAL_SYMBOL ::=
13592 -- IDENTIFIER
13593 -- | static_string_EXPRESSION
13595 -- PARAMETER_TYPES ::=
13596 -- null
13597 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13599 -- TYPE_DESIGNATOR ::=
13600 -- subtype_NAME
13601 -- | subtype_Name ' Access
13603 -- MECHANISM ::=
13604 -- MECHANISM_NAME
13605 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13607 -- MECHANISM_ASSOCIATION ::=
13608 -- [formal_parameter_NAME =>] MECHANISM_NAME
13610 -- MECHANISM_NAME ::=
13611 -- Value
13612 -- | Reference
13614 when Pragma_Export_Function => Export_Function : declare
13615 Args : Args_List (1 .. 6);
13616 Names : constant Name_List (1 .. 6) := (
13617 Name_Internal,
13618 Name_External,
13619 Name_Parameter_Types,
13620 Name_Result_Type,
13621 Name_Mechanism,
13622 Name_Result_Mechanism);
13624 Internal : Node_Id renames Args (1);
13625 External : Node_Id renames Args (2);
13626 Parameter_Types : Node_Id renames Args (3);
13627 Result_Type : Node_Id renames Args (4);
13628 Mechanism : Node_Id renames Args (5);
13629 Result_Mechanism : Node_Id renames Args (6);
13631 begin
13632 GNAT_Pragma;
13633 Gather_Associations (Names, Args);
13634 Process_Extended_Import_Export_Subprogram_Pragma (
13635 Arg_Internal => Internal,
13636 Arg_External => External,
13637 Arg_Parameter_Types => Parameter_Types,
13638 Arg_Result_Type => Result_Type,
13639 Arg_Mechanism => Mechanism,
13640 Arg_Result_Mechanism => Result_Mechanism);
13641 end Export_Function;
13643 -------------------
13644 -- Export_Object --
13645 -------------------
13647 -- pragma Export_Object (
13648 -- [Internal =>] LOCAL_NAME
13649 -- [, [External =>] EXTERNAL_SYMBOL]
13650 -- [, [Size =>] EXTERNAL_SYMBOL]);
13652 -- EXTERNAL_SYMBOL ::=
13653 -- IDENTIFIER
13654 -- | static_string_EXPRESSION
13656 -- PARAMETER_TYPES ::=
13657 -- null
13658 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13660 -- TYPE_DESIGNATOR ::=
13661 -- subtype_NAME
13662 -- | subtype_Name ' Access
13664 -- MECHANISM ::=
13665 -- MECHANISM_NAME
13666 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13668 -- MECHANISM_ASSOCIATION ::=
13669 -- [formal_parameter_NAME =>] MECHANISM_NAME
13671 -- MECHANISM_NAME ::=
13672 -- Value
13673 -- | Reference
13675 when Pragma_Export_Object => Export_Object : declare
13676 Args : Args_List (1 .. 3);
13677 Names : constant Name_List (1 .. 3) := (
13678 Name_Internal,
13679 Name_External,
13680 Name_Size);
13682 Internal : Node_Id renames Args (1);
13683 External : Node_Id renames Args (2);
13684 Size : Node_Id renames Args (3);
13686 begin
13687 GNAT_Pragma;
13688 Gather_Associations (Names, Args);
13689 Process_Extended_Import_Export_Object_Pragma (
13690 Arg_Internal => Internal,
13691 Arg_External => External,
13692 Arg_Size => Size);
13693 end Export_Object;
13695 ----------------------
13696 -- Export_Procedure --
13697 ----------------------
13699 -- pragma Export_Procedure (
13700 -- [Internal =>] LOCAL_NAME
13701 -- [, [External =>] EXTERNAL_SYMBOL]
13702 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13703 -- [, [Mechanism =>] MECHANISM]);
13705 -- EXTERNAL_SYMBOL ::=
13706 -- IDENTIFIER
13707 -- | static_string_EXPRESSION
13709 -- PARAMETER_TYPES ::=
13710 -- null
13711 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13713 -- TYPE_DESIGNATOR ::=
13714 -- subtype_NAME
13715 -- | subtype_Name ' Access
13717 -- MECHANISM ::=
13718 -- MECHANISM_NAME
13719 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13721 -- MECHANISM_ASSOCIATION ::=
13722 -- [formal_parameter_NAME =>] MECHANISM_NAME
13724 -- MECHANISM_NAME ::=
13725 -- Value
13726 -- | Reference
13728 when Pragma_Export_Procedure => Export_Procedure : declare
13729 Args : Args_List (1 .. 4);
13730 Names : constant Name_List (1 .. 4) := (
13731 Name_Internal,
13732 Name_External,
13733 Name_Parameter_Types,
13734 Name_Mechanism);
13736 Internal : Node_Id renames Args (1);
13737 External : Node_Id renames Args (2);
13738 Parameter_Types : Node_Id renames Args (3);
13739 Mechanism : Node_Id renames Args (4);
13741 begin
13742 GNAT_Pragma;
13743 Gather_Associations (Names, Args);
13744 Process_Extended_Import_Export_Subprogram_Pragma (
13745 Arg_Internal => Internal,
13746 Arg_External => External,
13747 Arg_Parameter_Types => Parameter_Types,
13748 Arg_Mechanism => Mechanism);
13749 end Export_Procedure;
13751 ------------------
13752 -- Export_Value --
13753 ------------------
13755 -- pragma Export_Value (
13756 -- [Value =>] static_integer_EXPRESSION,
13757 -- [Link_Name =>] static_string_EXPRESSION);
13759 when Pragma_Export_Value =>
13760 GNAT_Pragma;
13761 Check_Arg_Order ((Name_Value, Name_Link_Name));
13762 Check_Arg_Count (2);
13764 Check_Optional_Identifier (Arg1, Name_Value);
13765 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
13767 Check_Optional_Identifier (Arg2, Name_Link_Name);
13768 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
13770 -----------------------------
13771 -- Export_Valued_Procedure --
13772 -----------------------------
13774 -- pragma Export_Valued_Procedure (
13775 -- [Internal =>] LOCAL_NAME
13776 -- [, [External =>] EXTERNAL_SYMBOL,]
13777 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13778 -- [, [Mechanism =>] MECHANISM]);
13780 -- EXTERNAL_SYMBOL ::=
13781 -- IDENTIFIER
13782 -- | static_string_EXPRESSION
13784 -- PARAMETER_TYPES ::=
13785 -- null
13786 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13788 -- TYPE_DESIGNATOR ::=
13789 -- subtype_NAME
13790 -- | subtype_Name ' Access
13792 -- MECHANISM ::=
13793 -- MECHANISM_NAME
13794 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13796 -- MECHANISM_ASSOCIATION ::=
13797 -- [formal_parameter_NAME =>] MECHANISM_NAME
13799 -- MECHANISM_NAME ::=
13800 -- Value
13801 -- | Reference
13803 when Pragma_Export_Valued_Procedure =>
13804 Export_Valued_Procedure : declare
13805 Args : Args_List (1 .. 4);
13806 Names : constant Name_List (1 .. 4) := (
13807 Name_Internal,
13808 Name_External,
13809 Name_Parameter_Types,
13810 Name_Mechanism);
13812 Internal : Node_Id renames Args (1);
13813 External : Node_Id renames Args (2);
13814 Parameter_Types : Node_Id renames Args (3);
13815 Mechanism : Node_Id renames Args (4);
13817 begin
13818 GNAT_Pragma;
13819 Gather_Associations (Names, Args);
13820 Process_Extended_Import_Export_Subprogram_Pragma (
13821 Arg_Internal => Internal,
13822 Arg_External => External,
13823 Arg_Parameter_Types => Parameter_Types,
13824 Arg_Mechanism => Mechanism);
13825 end Export_Valued_Procedure;
13827 -------------------
13828 -- Extend_System --
13829 -------------------
13831 -- pragma Extend_System ([Name =>] Identifier);
13833 when Pragma_Extend_System => Extend_System : declare
13834 begin
13835 GNAT_Pragma;
13836 Check_Valid_Configuration_Pragma;
13837 Check_Arg_Count (1);
13838 Check_Optional_Identifier (Arg1, Name_Name);
13839 Check_Arg_Is_Identifier (Arg1);
13841 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13843 if Name_Len > 4
13844 and then Name_Buffer (1 .. 4) = "aux_"
13845 then
13846 if Present (System_Extend_Pragma_Arg) then
13847 if Chars (Get_Pragma_Arg (Arg1)) =
13848 Chars (Expression (System_Extend_Pragma_Arg))
13849 then
13850 null;
13851 else
13852 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
13853 Error_Pragma ("pragma% conflicts with that #");
13854 end if;
13856 else
13857 System_Extend_Pragma_Arg := Arg1;
13859 if not GNAT_Mode then
13860 System_Extend_Unit := Arg1;
13861 end if;
13862 end if;
13863 else
13864 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
13865 end if;
13866 end Extend_System;
13868 ------------------------
13869 -- Extensions_Allowed --
13870 ------------------------
13872 -- pragma Extensions_Allowed (ON | OFF);
13874 when Pragma_Extensions_Allowed =>
13875 GNAT_Pragma;
13876 Check_Arg_Count (1);
13877 Check_No_Identifiers;
13878 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13880 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
13881 Extensions_Allowed := True;
13882 Ada_Version := Ada_Version_Type'Last;
13884 else
13885 Extensions_Allowed := False;
13886 Ada_Version := Ada_Version_Explicit;
13887 Ada_Version_Pragma := Empty;
13888 end if;
13890 ------------------------
13891 -- Extensions_Visible --
13892 ------------------------
13894 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
13896 when Pragma_Extensions_Visible => Extensions_Visible : declare
13897 Context : constant Node_Id := Parent (N);
13898 Expr : Node_Id;
13899 Formal : Entity_Id;
13900 Orig_Stmt : Node_Id;
13901 Subp : Entity_Id;
13902 Stmt : Node_Id;
13904 Has_OK_Formal : Boolean := False;
13906 begin
13907 GNAT_Pragma;
13908 Check_No_Identifiers;
13909 Check_At_Most_N_Arguments (1);
13911 Subp := Empty;
13912 Stmt := Prev (N);
13913 while Present (Stmt) loop
13915 -- Skip prior pragmas, but check for duplicates
13917 if Nkind (Stmt) = N_Pragma then
13918 if Pragma_Name (Stmt) = Pname then
13919 Error_Msg_Name_1 := Pname;
13920 Error_Msg_Sloc := Sloc (Stmt);
13921 Error_Msg_N ("pragma % duplicates pragma declared#", N);
13922 end if;
13924 -- Skip internally generated code
13926 elsif not Comes_From_Source (Stmt) then
13927 Orig_Stmt := Original_Node (Stmt);
13929 -- When pragma Ghost applies to an expression function, the
13930 -- expression function is transformed into a subprogram.
13932 if Nkind (Stmt) = N_Subprogram_Declaration
13933 and then Comes_From_Source (Orig_Stmt)
13934 and then Nkind (Orig_Stmt) = N_Expression_Function
13935 then
13936 Subp := Defining_Entity (Stmt);
13937 exit;
13938 end if;
13940 -- The associated [generic] subprogram declaration has been
13941 -- found, stop the search.
13943 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
13944 N_Subprogram_Declaration)
13945 then
13946 Subp := Defining_Entity (Stmt);
13947 exit;
13949 -- The pragma does not apply to a legal construct, issue an
13950 -- error and stop the analysis.
13952 else
13953 Error_Pragma ("pragma % must apply to a subprogram");
13954 return;
13955 end if;
13957 Stmt := Prev (Stmt);
13958 end loop;
13960 -- When the pragma applies to a stand alone subprogram body, it
13961 -- appears within the declarations of the body. In that case the
13962 -- enclosing construct is the proper context. This check is done
13963 -- after the traversal above to allow for duplicate detection.
13965 if No (Subp)
13966 and then Nkind (Context) = N_Subprogram_Body
13967 and then No (Corresponding_Spec (Context))
13968 then
13969 Subp := Defining_Entity (Context);
13970 end if;
13972 if No (Subp) then
13973 Error_Pragma ("pragma % must apply to a subprogram");
13974 return;
13975 end if;
13977 -- Examine the formals of the related subprogram
13979 Formal := First_Formal (Subp);
13980 while Present (Formal) loop
13982 -- At least one of the formals is of a specific tagged type,
13983 -- the pragma is legal.
13985 if Is_Specific_Tagged_Type (Etype (Formal)) then
13986 Has_OK_Formal := True;
13987 exit;
13989 -- A generic subprogram with at least one formal of a private
13990 -- type ensures the legality of the pragma because the actual
13991 -- may be specifically tagged. Note that this is verified by
13992 -- the check above at instantiation time.
13994 elsif Is_Private_Type (Etype (Formal))
13995 and then Is_Generic_Type (Etype (Formal))
13996 then
13997 Has_OK_Formal := True;
13998 exit;
13999 end if;
14001 Next_Formal (Formal);
14002 end loop;
14004 if not Has_OK_Formal then
14005 Error_Msg_Name_1 := Pname;
14006 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
14007 Error_Msg_NE
14008 ("\subprogram & lacks parameter of specific tagged or "
14009 & "generic private type", N, Subp);
14010 return;
14011 end if;
14013 -- Analyze the Boolean expression (if any)
14015 if Present (Arg1) then
14016 Expr := Get_Pragma_Arg (Arg1);
14018 Analyze_And_Resolve (Expr, Standard_Boolean);
14020 if not Is_OK_Static_Expression (Expr) then
14021 Error_Pragma_Arg
14022 ("expression of pragma % must be static", Expr);
14023 return;
14024 end if;
14025 end if;
14027 -- Chain the pragma on the contract for further processing
14029 Add_Contract_Item (N, Subp);
14030 end Extensions_Visible;
14032 --------------
14033 -- External --
14034 --------------
14036 -- pragma External (
14037 -- [ Convention =>] convention_IDENTIFIER,
14038 -- [ Entity =>] LOCAL_NAME
14039 -- [, [External_Name =>] static_string_EXPRESSION ]
14040 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14042 when Pragma_External => External : declare
14043 Def_Id : Entity_Id;
14045 C : Convention_Id;
14046 pragma Warnings (Off, C);
14048 begin
14049 GNAT_Pragma;
14050 Check_Arg_Order
14051 ((Name_Convention,
14052 Name_Entity,
14053 Name_External_Name,
14054 Name_Link_Name));
14055 Check_At_Least_N_Arguments (2);
14056 Check_At_Most_N_Arguments (4);
14057 Process_Convention (C, Def_Id);
14058 Note_Possible_Modification
14059 (Get_Pragma_Arg (Arg2), Sure => False);
14060 Process_Interface_Name (Def_Id, Arg3, Arg4);
14061 Set_Exported (Def_Id, Arg2);
14062 end External;
14064 --------------------------
14065 -- External_Name_Casing --
14066 --------------------------
14068 -- pragma External_Name_Casing (
14069 -- UPPERCASE | LOWERCASE
14070 -- [, AS_IS | UPPERCASE | LOWERCASE]);
14072 when Pragma_External_Name_Casing => External_Name_Casing : declare
14073 begin
14074 GNAT_Pragma;
14075 Check_No_Identifiers;
14077 if Arg_Count = 2 then
14078 Check_Arg_Is_One_Of
14079 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
14081 case Chars (Get_Pragma_Arg (Arg2)) is
14082 when Name_As_Is =>
14083 Opt.External_Name_Exp_Casing := As_Is;
14085 when Name_Uppercase =>
14086 Opt.External_Name_Exp_Casing := Uppercase;
14088 when Name_Lowercase =>
14089 Opt.External_Name_Exp_Casing := Lowercase;
14091 when others =>
14092 null;
14093 end case;
14095 else
14096 Check_Arg_Count (1);
14097 end if;
14099 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
14101 case Chars (Get_Pragma_Arg (Arg1)) is
14102 when Name_Uppercase =>
14103 Opt.External_Name_Imp_Casing := Uppercase;
14105 when Name_Lowercase =>
14106 Opt.External_Name_Imp_Casing := Lowercase;
14108 when others =>
14109 null;
14110 end case;
14111 end External_Name_Casing;
14113 ---------------
14114 -- Fast_Math --
14115 ---------------
14117 -- pragma Fast_Math;
14119 when Pragma_Fast_Math =>
14120 GNAT_Pragma;
14121 Check_No_Identifiers;
14122 Check_Valid_Configuration_Pragma;
14123 Fast_Math := True;
14125 --------------------------
14126 -- Favor_Top_Level --
14127 --------------------------
14129 -- pragma Favor_Top_Level (type_NAME);
14131 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
14132 Named_Entity : Entity_Id;
14134 begin
14135 GNAT_Pragma;
14136 Check_No_Identifiers;
14137 Check_Arg_Count (1);
14138 Check_Arg_Is_Local_Name (Arg1);
14139 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
14141 -- If it's an access-to-subprogram type (in particular, not a
14142 -- subtype), set the flag on that type.
14144 if Is_Access_Subprogram_Type (Named_Entity) then
14145 Set_Can_Use_Internal_Rep (Named_Entity, False);
14147 -- Otherwise it's an error (name denotes the wrong sort of entity)
14149 else
14150 Error_Pragma_Arg
14151 ("access-to-subprogram type expected",
14152 Get_Pragma_Arg (Arg1));
14153 end if;
14154 end Favor_Top_Level;
14156 ---------------------------
14157 -- Finalize_Storage_Only --
14158 ---------------------------
14160 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
14162 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
14163 Assoc : constant Node_Id := Arg1;
14164 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
14165 Typ : Entity_Id;
14167 begin
14168 GNAT_Pragma;
14169 Check_No_Identifiers;
14170 Check_Arg_Count (1);
14171 Check_Arg_Is_Local_Name (Arg1);
14173 Find_Type (Type_Id);
14174 Typ := Entity (Type_Id);
14176 if Typ = Any_Type
14177 or else Rep_Item_Too_Early (Typ, N)
14178 then
14179 return;
14180 else
14181 Typ := Underlying_Type (Typ);
14182 end if;
14184 if not Is_Controlled (Typ) then
14185 Error_Pragma ("pragma% must specify controlled type");
14186 end if;
14188 Check_First_Subtype (Arg1);
14190 if Finalize_Storage_Only (Typ) then
14191 Error_Pragma ("duplicate pragma%, only one allowed");
14193 elsif not Rep_Item_Too_Late (Typ, N) then
14194 Set_Finalize_Storage_Only (Base_Type (Typ), True);
14195 end if;
14196 end Finalize_Storage;
14198 -----------
14199 -- Ghost --
14200 -----------
14202 -- pragma Ghost [ (boolean_EXPRESSION) ];
14204 when Pragma_Ghost => Ghost : declare
14205 Context : Node_Id;
14206 Expr : Node_Id;
14207 Id : Entity_Id;
14208 Orig_Stmt : Node_Id;
14209 Prev_Id : Entity_Id;
14210 Stmt : Node_Id;
14212 begin
14213 GNAT_Pragma;
14214 Check_No_Identifiers;
14215 Check_At_Most_N_Arguments (1);
14217 Context := Parent (N);
14219 -- Handle compilation units
14221 if Nkind (Context) = N_Compilation_Unit_Aux then
14222 Context := Unit (Parent (Context));
14223 end if;
14225 Id := Empty;
14226 Stmt := Prev (N);
14227 while Present (Stmt) loop
14229 -- Skip prior pragmas, but check for duplicates
14231 if Nkind (Stmt) = N_Pragma then
14232 if Pragma_Name (Stmt) = Pname then
14233 Error_Msg_Name_1 := Pname;
14234 Error_Msg_Sloc := Sloc (Stmt);
14235 Error_Msg_N ("pragma % duplicates pragma declared#", N);
14236 end if;
14238 -- Protected and task types cannot be subject to pragma Ghost
14240 elsif Nkind (Stmt) = N_Protected_Type_Declaration then
14241 Error_Pragma ("pragma % cannot apply to a protected type");
14242 return;
14244 elsif Nkind (Stmt) = N_Task_Type_Declaration then
14245 Error_Pragma ("pragma % cannot apply to a task type");
14246 return;
14248 -- Skip internally generated code
14250 elsif not Comes_From_Source (Stmt) then
14251 Orig_Stmt := Original_Node (Stmt);
14253 -- When pragma Ghost applies to an untagged derivation, the
14254 -- derivation is transformed into a [sub]type declaration.
14256 if Nkind_In (Stmt, N_Full_Type_Declaration,
14257 N_Subtype_Declaration)
14258 and then Comes_From_Source (Orig_Stmt)
14259 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
14260 and then Nkind (Type_Definition (Orig_Stmt)) =
14261 N_Derived_Type_Definition
14262 then
14263 Id := Defining_Entity (Stmt);
14264 exit;
14266 -- When pragma Ghost applies to an expression function, the
14267 -- expression function is transformed into a subprogram.
14269 elsif Nkind (Stmt) = N_Subprogram_Declaration
14270 and then Comes_From_Source (Orig_Stmt)
14271 and then Nkind (Orig_Stmt) = N_Expression_Function
14272 then
14273 Id := Defining_Entity (Stmt);
14274 exit;
14275 end if;
14277 -- The pragma applies to a legal construct, stop the traversal
14279 elsif Nkind_In (Stmt, N_Abstract_Subprogram_Declaration,
14280 N_Full_Type_Declaration,
14281 N_Generic_Subprogram_Declaration,
14282 N_Object_Declaration,
14283 N_Private_Extension_Declaration,
14284 N_Private_Type_Declaration,
14285 N_Subprogram_Declaration,
14286 N_Subtype_Declaration)
14287 then
14288 Id := Defining_Entity (Stmt);
14289 exit;
14291 -- The pragma does not apply to a legal construct, issue an
14292 -- error and stop the analysis.
14294 else
14295 Error_Pragma
14296 ("pragma % must apply to an object, package, subprogram "
14297 & "or type");
14298 return;
14299 end if;
14301 Stmt := Prev (Stmt);
14302 end loop;
14304 if No (Id) then
14306 -- When pragma Ghost is associated with a [generic] package, it
14307 -- appears in the visible declarations.
14309 if Nkind (Context) = N_Package_Specification
14310 and then Present (Visible_Declarations (Context))
14311 and then List_Containing (N) = Visible_Declarations (Context)
14312 then
14313 Id := Defining_Entity (Context);
14315 -- Pragma Ghost applies to a stand alone subprogram body
14317 elsif Nkind (Context) = N_Subprogram_Body
14318 and then No (Corresponding_Spec (Context))
14319 then
14320 Id := Defining_Entity (Context);
14321 end if;
14322 end if;
14324 if No (Id) then
14325 Error_Pragma
14326 ("pragma % must apply to an object, package, subprogram or "
14327 & "type");
14328 return;
14329 end if;
14331 -- A derived type or type extension cannot be subject to pragma
14332 -- Ghost if either the parent type or one of the progenitor types
14333 -- is not Ghost (SPARK RM 6.9(9)).
14335 if Is_Derived_Type (Id) then
14336 Check_Ghost_Derivation (Id);
14337 end if;
14339 -- Handle completions of types and constants that are subject to
14340 -- pragma Ghost.
14342 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
14343 Prev_Id := Incomplete_Or_Partial_View (Id);
14345 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
14346 Error_Msg_Name_1 := Pname;
14348 -- The full declaration of a deferred constant cannot be
14349 -- subject to pragma Ghost unless the deferred declaration
14350 -- is also Ghost (SPARK RM 6.9(10)).
14352 if Ekind (Prev_Id) = E_Constant then
14353 Error_Msg_Name_1 := Pname;
14354 Error_Msg_NE (Fix_Error
14355 ("pragma % must apply to declaration of deferred "
14356 & "constant &"), N, Id);
14357 return;
14359 -- Pragma Ghost may appear on the full view of an incomplete
14360 -- type because the incomplete declaration lacks aspects and
14361 -- cannot be subject to pragma Ghost.
14363 elsif Ekind (Prev_Id) = E_Incomplete_Type then
14364 null;
14366 -- The full declaration of a type cannot be subject to
14367 -- pragma Ghost unless the partial view is also Ghost
14368 -- (SPARK RM 6.9(10)).
14370 else
14371 Error_Msg_NE (Fix_Error
14372 ("pragma % must apply to partial view of type &"),
14373 N, Id);
14374 return;
14375 end if;
14376 end if;
14377 end if;
14379 -- Analyze the Boolean expression (if any)
14381 if Present (Arg1) then
14382 Expr := Get_Pragma_Arg (Arg1);
14384 Analyze_And_Resolve (Expr, Standard_Boolean);
14386 if Is_OK_Static_Expression (Expr) then
14388 -- "Ghostness" cannot be turned off once enabled within a
14389 -- region (SPARK RM 6.9(7)).
14391 if Is_False (Expr_Value (Expr))
14392 and then Ghost_Mode > None
14393 then
14394 Error_Pragma
14395 ("pragma % with value False cannot appear in enabled "
14396 & "ghost region");
14397 return;
14398 end if;
14400 -- Otherwie the expression is not static
14402 else
14403 Error_Pragma_Arg
14404 ("expression of pragma % must be static", Expr);
14405 return;
14406 end if;
14407 end if;
14409 Set_Is_Ghost_Entity (Id);
14410 end Ghost;
14412 ------------
14413 -- Global --
14414 ------------
14416 -- pragma Global (GLOBAL_SPECIFICATION);
14418 -- GLOBAL_SPECIFICATION ::=
14419 -- null
14420 -- | GLOBAL_LIST
14421 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
14423 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
14425 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
14426 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
14427 -- GLOBAL_ITEM ::= NAME
14429 when Pragma_Global => Global : declare
14430 Subp_Decl : Node_Id;
14432 begin
14433 GNAT_Pragma;
14434 Check_Arg_Count (1);
14435 Ensure_Aggregate_Form (Arg1);
14437 -- Ensure the proper placement of the pragma. Global must be
14438 -- associated with a subprogram declaration or a body that acts
14439 -- as a spec.
14441 Subp_Decl :=
14442 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
14444 if Nkind (Subp_Decl) = N_Subprogram_Declaration then
14445 null;
14447 -- Body acts as spec
14449 elsif Nkind (Subp_Decl) = N_Subprogram_Body
14450 and then No (Corresponding_Spec (Subp_Decl))
14451 then
14452 null;
14454 -- Body stub acts as spec
14456 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
14457 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
14458 then
14459 null;
14461 else
14462 Pragma_Misplaced;
14463 return;
14464 end if;
14466 -- When the pragma appears on a subprogram body, perform the full
14467 -- analysis now.
14469 if Nkind (Subp_Decl) = N_Subprogram_Body then
14470 Analyze_Global_In_Decl_Part (N);
14472 -- When Global applies to a subprogram compilation unit, the
14473 -- corresponding pragma is placed after the unit's declaration
14474 -- node and needs to be analyzed immediately.
14476 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
14477 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
14478 then
14479 Analyze_Global_In_Decl_Part (N);
14480 end if;
14482 -- Chain the pragma on the contract for further processing
14484 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
14485 end Global;
14487 -----------
14488 -- Ident --
14489 -----------
14491 -- pragma Ident (static_string_EXPRESSION)
14493 -- Note: pragma Comment shares this processing. Pragma Ident is
14494 -- identical in effect to pragma Commment.
14496 when Pragma_Ident | Pragma_Comment => Ident : declare
14497 Str : Node_Id;
14499 begin
14500 GNAT_Pragma;
14501 Check_Arg_Count (1);
14502 Check_No_Identifiers;
14503 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
14504 Store_Note (N);
14506 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
14508 declare
14509 CS : Node_Id;
14510 GP : Node_Id;
14512 begin
14513 GP := Parent (Parent (N));
14515 if Nkind_In (GP, N_Package_Declaration,
14516 N_Generic_Package_Declaration)
14517 then
14518 GP := Parent (GP);
14519 end if;
14521 -- If we have a compilation unit, then record the ident value,
14522 -- checking for improper duplication.
14524 if Nkind (GP) = N_Compilation_Unit then
14525 CS := Ident_String (Current_Sem_Unit);
14527 if Present (CS) then
14529 -- If we have multiple instances, concatenate them, but
14530 -- not in ASIS, where we want the original tree.
14532 if not ASIS_Mode then
14533 Start_String (Strval (CS));
14534 Store_String_Char (' ');
14535 Store_String_Chars (Strval (Str));
14536 Set_Strval (CS, End_String);
14537 end if;
14539 else
14540 Set_Ident_String (Current_Sem_Unit, Str);
14541 end if;
14543 -- For subunits, we just ignore the Ident, since in GNAT these
14544 -- are not separate object files, and hence not separate units
14545 -- in the unit table.
14547 elsif Nkind (GP) = N_Subunit then
14548 null;
14549 end if;
14550 end;
14551 end Ident;
14553 ----------------------------
14554 -- Implementation_Defined --
14555 ----------------------------
14557 -- pragma Implementation_Defined (LOCAL_NAME);
14559 -- Marks previously declared entity as implementation defined. For
14560 -- an overloaded entity, applies to the most recent homonym.
14562 -- pragma Implementation_Defined;
14564 -- The form with no arguments appears anywhere within a scope, most
14565 -- typically a package spec, and indicates that all entities that are
14566 -- defined within the package spec are Implementation_Defined.
14568 when Pragma_Implementation_Defined => Implementation_Defined : declare
14569 Ent : Entity_Id;
14571 begin
14572 GNAT_Pragma;
14573 Check_No_Identifiers;
14575 -- Form with no arguments
14577 if Arg_Count = 0 then
14578 Set_Is_Implementation_Defined (Current_Scope);
14580 -- Form with one argument
14582 else
14583 Check_Arg_Count (1);
14584 Check_Arg_Is_Local_Name (Arg1);
14585 Ent := Entity (Get_Pragma_Arg (Arg1));
14586 Set_Is_Implementation_Defined (Ent);
14587 end if;
14588 end Implementation_Defined;
14590 -----------------
14591 -- Implemented --
14592 -----------------
14594 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
14596 -- IMPLEMENTATION_KIND ::=
14597 -- By_Entry | By_Protected_Procedure | By_Any | Optional
14599 -- "By_Any" and "Optional" are treated as synonyms in order to
14600 -- support Ada 2012 aspect Synchronization.
14602 when Pragma_Implemented => Implemented : declare
14603 Proc_Id : Entity_Id;
14604 Typ : Entity_Id;
14606 begin
14607 Ada_2012_Pragma;
14608 Check_Arg_Count (2);
14609 Check_No_Identifiers;
14610 Check_Arg_Is_Identifier (Arg1);
14611 Check_Arg_Is_Local_Name (Arg1);
14612 Check_Arg_Is_One_Of (Arg2,
14613 Name_By_Any,
14614 Name_By_Entry,
14615 Name_By_Protected_Procedure,
14616 Name_Optional);
14618 -- Extract the name of the local procedure
14620 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
14622 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
14623 -- primitive procedure of a synchronized tagged type.
14625 if Ekind (Proc_Id) = E_Procedure
14626 and then Is_Primitive (Proc_Id)
14627 and then Present (First_Formal (Proc_Id))
14628 then
14629 Typ := Etype (First_Formal (Proc_Id));
14631 if Is_Tagged_Type (Typ)
14632 and then
14634 -- Check for a protected, a synchronized or a task interface
14636 ((Is_Interface (Typ)
14637 and then Is_Synchronized_Interface (Typ))
14639 -- Check for a protected type or a task type that implements
14640 -- an interface.
14642 or else
14643 (Is_Concurrent_Record_Type (Typ)
14644 and then Present (Interfaces (Typ)))
14646 -- In analysis-only mode, examine original protected type
14648 or else
14649 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
14650 and then Present (Interface_List (Parent (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 (LOCAL_NAME);
14949 when Pragma_Independent =>
14950 Process_Atomic_Independent_Shared_Volatile;
14952 ----------------------------
14953 -- Independent_Components --
14954 ----------------------------
14956 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
14958 when Pragma_Independent_Components => Independent_Components : declare
14959 E_Id : Node_Id;
14960 E : Entity_Id;
14961 D : Node_Id;
14962 K : Node_Kind;
14963 C : Node_Id;
14965 begin
14966 Check_Ada_83_Warning;
14967 Ada_2012_Pragma;
14968 Check_No_Identifiers;
14969 Check_Arg_Count (1);
14970 Check_Arg_Is_Local_Name (Arg1);
14971 E_Id := Get_Pragma_Arg (Arg1);
14973 if Etype (E_Id) = Any_Type then
14974 return;
14975 end if;
14977 E := Entity (E_Id);
14979 -- Check duplicate before we chain ourselves
14981 Check_Duplicate_Pragma (E);
14983 -- Check appropriate entity
14985 if Rep_Item_Too_Early (E, N)
14986 or else
14987 Rep_Item_Too_Late (E, N)
14988 then
14989 return;
14990 end if;
14992 D := Declaration_Node (E);
14993 K := Nkind (D);
14995 -- The flag is set on the base type, or on the object
14997 if K = N_Full_Type_Declaration
14998 and then (Is_Array_Type (E) or else Is_Record_Type (E))
14999 then
15000 Set_Has_Independent_Components (Base_Type (E));
15001 Independence_Checks.Append ((N, Base_Type (E)));
15003 -- For record type, set all components independent
15005 if Is_Record_Type (E) then
15006 C := First_Component (E);
15007 while Present (C) loop
15008 Set_Is_Independent (C);
15009 Next_Component (C);
15010 end loop;
15011 end if;
15013 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
15014 and then Nkind (D) = N_Object_Declaration
15015 and then Nkind (Object_Definition (D)) =
15016 N_Constrained_Array_Definition
15017 then
15018 Set_Has_Independent_Components (E);
15019 Independence_Checks.Append ((N, E));
15021 else
15022 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
15023 end if;
15024 end Independent_Components;
15026 -----------------------
15027 -- Initial_Condition --
15028 -----------------------
15030 -- pragma Initial_Condition (boolean_EXPRESSION);
15032 when Pragma_Initial_Condition => Initial_Condition : declare
15033 Context : constant Node_Id := Parent (Parent (N));
15034 Pack_Id : Entity_Id;
15035 Stmt : Node_Id;
15037 begin
15038 GNAT_Pragma;
15039 Check_No_Identifiers;
15040 Check_Arg_Count (1);
15042 -- Ensure the proper placement of the pragma. Initial_Condition
15043 -- must be associated with a package declaration.
15045 if not Nkind_In (Context, N_Generic_Package_Declaration,
15046 N_Package_Declaration)
15047 then
15048 Pragma_Misplaced;
15049 return;
15050 end if;
15052 Stmt := Prev (N);
15053 while Present (Stmt) loop
15055 -- Skip prior pragmas, but check for duplicates
15057 if Nkind (Stmt) = N_Pragma then
15058 if Pragma_Name (Stmt) = Pname then
15059 Error_Msg_Name_1 := Pname;
15060 Error_Msg_Sloc := Sloc (Stmt);
15061 Error_Msg_N ("pragma % duplicates pragma declared #", N);
15062 end if;
15064 -- Skip internally generated code
15066 elsif not Comes_From_Source (Stmt) then
15067 null;
15069 -- The pragma does not apply to a legal construct, issue an
15070 -- error and stop the analysis.
15072 else
15073 Pragma_Misplaced;
15074 return;
15075 end if;
15077 Stmt := Prev (Stmt);
15078 end loop;
15080 -- The pragma must be analyzed at the end of the visible
15081 -- declarations of the related package. Save the pragma for later
15082 -- (see Analyze_Initial_Condition_In_Decl_Part) by adding it to
15083 -- the contract of the package.
15085 Pack_Id := Defining_Entity (Context);
15086 Add_Contract_Item (N, Pack_Id);
15088 -- Verify the declaration order of pragma Initial_Condition with
15089 -- respect to pragmas Abstract_State and Initializes when SPARK
15090 -- checks are enabled.
15092 if SPARK_Mode /= Off then
15093 Check_Declaration_Order
15094 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
15095 Second => N);
15097 Check_Declaration_Order
15098 (First => Get_Pragma (Pack_Id, Pragma_Initializes),
15099 Second => N);
15100 end if;
15101 end Initial_Condition;
15103 ------------------------
15104 -- Initialize_Scalars --
15105 ------------------------
15107 -- pragma Initialize_Scalars;
15109 when Pragma_Initialize_Scalars =>
15110 GNAT_Pragma;
15111 Check_Arg_Count (0);
15112 Check_Valid_Configuration_Pragma;
15113 Check_Restriction (No_Initialize_Scalars, N);
15115 -- Initialize_Scalars creates false positives in CodePeer, and
15116 -- incorrect negative results in GNATprove mode, so ignore this
15117 -- pragma in these modes.
15119 if not Restriction_Active (No_Initialize_Scalars)
15120 and then not (CodePeer_Mode or GNATprove_Mode)
15121 then
15122 Init_Or_Norm_Scalars := True;
15123 Initialize_Scalars := True;
15124 end if;
15126 -----------------
15127 -- Initializes --
15128 -----------------
15130 -- pragma Initializes (INITIALIZATION_SPEC);
15132 -- INITIALIZATION_SPEC ::= null | INITIALIZATION_LIST
15134 -- INITIALIZATION_LIST ::=
15135 -- INITIALIZATION_ITEM
15136 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
15138 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
15140 -- INPUT_LIST ::=
15141 -- null
15142 -- | INPUT
15143 -- | (INPUT {, INPUT})
15145 -- INPUT ::= name
15147 when Pragma_Initializes => Initializes : declare
15148 Context : constant Node_Id := Parent (Parent (N));
15149 Pack_Id : Entity_Id;
15150 Stmt : Node_Id;
15152 begin
15153 GNAT_Pragma;
15154 Check_No_Identifiers;
15155 Check_Arg_Count (1);
15156 Ensure_Aggregate_Form (Arg1);
15158 -- Ensure the proper placement of the pragma. Initializes must be
15159 -- associated with a package declaration.
15161 if not Nkind_In (Context, N_Generic_Package_Declaration,
15162 N_Package_Declaration)
15163 then
15164 Pragma_Misplaced;
15165 return;
15166 end if;
15168 Stmt := Prev (N);
15169 while Present (Stmt) loop
15171 -- Skip prior pragmas, but check for duplicates
15173 if Nkind (Stmt) = N_Pragma then
15174 if Pragma_Name (Stmt) = Pname then
15175 Error_Msg_Name_1 := Pname;
15176 Error_Msg_Sloc := Sloc (Stmt);
15177 Error_Msg_N ("pragma % duplicates pragma declared #", N);
15178 end if;
15180 -- Skip internally generated code
15182 elsif not Comes_From_Source (Stmt) then
15183 null;
15185 -- The pragma does not apply to a legal construct, issue an
15186 -- error and stop the analysis.
15188 else
15189 Pragma_Misplaced;
15190 return;
15191 end if;
15193 Stmt := Prev (Stmt);
15194 end loop;
15196 -- The pragma must be analyzed at the end of the visible
15197 -- declarations of the related package. Save the pragma for later
15198 -- (see Analyze_Initializes_In_Decl_Part) by adding it to the
15199 -- contract of the package.
15201 Pack_Id := Defining_Entity (Context);
15202 Add_Contract_Item (N, Pack_Id);
15204 -- Verify the declaration order of pragmas Abstract_State and
15205 -- Initializes when SPARK checks are enabled.
15207 if SPARK_Mode /= Off then
15208 Check_Declaration_Order
15209 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
15210 Second => N);
15211 end if;
15212 end Initializes;
15214 ------------
15215 -- Inline --
15216 ------------
15218 -- pragma Inline ( NAME {, NAME} );
15220 when Pragma_Inline =>
15222 -- Pragma always active unless in GNATprove mode. It is disabled
15223 -- in GNATprove mode because frontend inlining is applied
15224 -- independently of pragmas Inline and Inline_Always for
15225 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
15226 -- in inline.ads.
15228 if not GNATprove_Mode then
15230 -- Inline status is Enabled if inlining option is active
15232 if Inline_Active then
15233 Process_Inline (Enabled);
15234 else
15235 Process_Inline (Disabled);
15236 end if;
15237 end if;
15239 -------------------
15240 -- Inline_Always --
15241 -------------------
15243 -- pragma Inline_Always ( NAME {, NAME} );
15245 when Pragma_Inline_Always =>
15246 GNAT_Pragma;
15248 -- Pragma always active unless in CodePeer mode or GNATprove
15249 -- mode. It is disabled in CodePeer mode because inlining is
15250 -- not helpful, and enabling it caused walk order issues. It
15251 -- is disabled in GNATprove mode because frontend inlining is
15252 -- applied independently of pragmas Inline and Inline_Always for
15253 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
15254 -- inline.ads.
15256 if not CodePeer_Mode and not GNATprove_Mode then
15257 Process_Inline (Enabled);
15258 end if;
15260 --------------------
15261 -- Inline_Generic --
15262 --------------------
15264 -- pragma Inline_Generic (NAME {, NAME});
15266 when Pragma_Inline_Generic =>
15267 GNAT_Pragma;
15268 Process_Generic_List;
15270 ----------------------
15271 -- Inspection_Point --
15272 ----------------------
15274 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
15276 when Pragma_Inspection_Point => Inspection_Point : declare
15277 Arg : Node_Id;
15278 Exp : Node_Id;
15280 begin
15283 if Arg_Count > 0 then
15284 Arg := Arg1;
15285 loop
15286 Exp := Get_Pragma_Arg (Arg);
15287 Analyze (Exp);
15289 if not Is_Entity_Name (Exp)
15290 or else not Is_Object (Entity (Exp))
15291 then
15292 Error_Pragma_Arg ("object name required", Arg);
15293 end if;
15295 Next (Arg);
15296 exit when No (Arg);
15297 end loop;
15298 end if;
15299 end Inspection_Point;
15301 ---------------
15302 -- Interface --
15303 ---------------
15305 -- pragma Interface (
15306 -- [ Convention =>] convention_IDENTIFIER,
15307 -- [ Entity =>] LOCAL_NAME
15308 -- [, [External_Name =>] static_string_EXPRESSION ]
15309 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15311 when Pragma_Interface =>
15312 GNAT_Pragma;
15313 Check_Arg_Order
15314 ((Name_Convention,
15315 Name_Entity,
15316 Name_External_Name,
15317 Name_Link_Name));
15318 Check_At_Least_N_Arguments (2);
15319 Check_At_Most_N_Arguments (4);
15320 Process_Import_Or_Interface;
15322 -- In Ada 2005, the permission to use Interface (a reserved word)
15323 -- as a pragma name is considered an obsolescent feature, and this
15324 -- pragma was already obsolescent in Ada 95.
15326 if Ada_Version >= Ada_95 then
15327 Check_Restriction
15328 (No_Obsolescent_Features, Pragma_Identifier (N));
15330 if Warn_On_Obsolescent_Feature then
15331 Error_Msg_N
15332 ("pragma Interface is an obsolescent feature?j?", N);
15333 Error_Msg_N
15334 ("|use pragma Import instead?j?", N);
15335 end if;
15336 end if;
15338 --------------------
15339 -- Interface_Name --
15340 --------------------
15342 -- pragma Interface_Name (
15343 -- [ Entity =>] LOCAL_NAME
15344 -- [,[External_Name =>] static_string_EXPRESSION ]
15345 -- [,[Link_Name =>] static_string_EXPRESSION ]);
15347 when Pragma_Interface_Name => Interface_Name : declare
15348 Id : Node_Id;
15349 Def_Id : Entity_Id;
15350 Hom_Id : Entity_Id;
15351 Found : Boolean;
15353 begin
15354 GNAT_Pragma;
15355 Check_Arg_Order
15356 ((Name_Entity, Name_External_Name, Name_Link_Name));
15357 Check_At_Least_N_Arguments (2);
15358 Check_At_Most_N_Arguments (3);
15359 Id := Get_Pragma_Arg (Arg1);
15360 Analyze (Id);
15362 -- This is obsolete from Ada 95 on, but it is an implementation
15363 -- defined pragma, so we do not consider that it violates the
15364 -- restriction (No_Obsolescent_Features).
15366 if Ada_Version >= Ada_95 then
15367 if Warn_On_Obsolescent_Feature then
15368 Error_Msg_N
15369 ("pragma Interface_Name is an obsolescent feature?j?", N);
15370 Error_Msg_N
15371 ("|use pragma Import instead?j?", N);
15372 end if;
15373 end if;
15375 if not Is_Entity_Name (Id) then
15376 Error_Pragma_Arg
15377 ("first argument for pragma% must be entity name", Arg1);
15378 elsif Etype (Id) = Any_Type then
15379 return;
15380 else
15381 Def_Id := Entity (Id);
15382 end if;
15384 -- Special DEC-compatible processing for the object case, forces
15385 -- object to be imported.
15387 if Ekind (Def_Id) = E_Variable then
15388 Kill_Size_Check_Code (Def_Id);
15389 Note_Possible_Modification (Id, Sure => False);
15391 -- Initialization is not allowed for imported variable
15393 if Present (Expression (Parent (Def_Id)))
15394 and then Comes_From_Source (Expression (Parent (Def_Id)))
15395 then
15396 Error_Msg_Sloc := Sloc (Def_Id);
15397 Error_Pragma_Arg
15398 ("no initialization allowed for declaration of& #",
15399 Arg2);
15401 else
15402 -- For compatibility, support VADS usage of providing both
15403 -- pragmas Interface and Interface_Name to obtain the effect
15404 -- of a single Import pragma.
15406 if Is_Imported (Def_Id)
15407 and then Present (First_Rep_Item (Def_Id))
15408 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
15409 and then
15410 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
15411 then
15412 null;
15413 else
15414 Set_Imported (Def_Id);
15415 end if;
15417 Set_Is_Public (Def_Id);
15418 Process_Interface_Name (Def_Id, Arg2, Arg3);
15419 end if;
15421 -- Otherwise must be subprogram
15423 elsif not Is_Subprogram (Def_Id) then
15424 Error_Pragma_Arg
15425 ("argument of pragma% is not subprogram", Arg1);
15427 else
15428 Check_At_Most_N_Arguments (3);
15429 Hom_Id := Def_Id;
15430 Found := False;
15432 -- Loop through homonyms
15434 loop
15435 Def_Id := Get_Base_Subprogram (Hom_Id);
15437 if Is_Imported (Def_Id) then
15438 Process_Interface_Name (Def_Id, Arg2, Arg3);
15439 Found := True;
15440 end if;
15442 exit when From_Aspect_Specification (N);
15443 Hom_Id := Homonym (Hom_Id);
15445 exit when No (Hom_Id)
15446 or else Scope (Hom_Id) /= Current_Scope;
15447 end loop;
15449 if not Found then
15450 Error_Pragma_Arg
15451 ("argument of pragma% is not imported subprogram",
15452 Arg1);
15453 end if;
15454 end if;
15455 end Interface_Name;
15457 -----------------------
15458 -- Interrupt_Handler --
15459 -----------------------
15461 -- pragma Interrupt_Handler (handler_NAME);
15463 when Pragma_Interrupt_Handler =>
15464 Check_Ada_83_Warning;
15465 Check_Arg_Count (1);
15466 Check_No_Identifiers;
15468 if No_Run_Time_Mode then
15469 Error_Msg_CRT ("Interrupt_Handler pragma", N);
15470 else
15471 Check_Interrupt_Or_Attach_Handler;
15472 Process_Interrupt_Or_Attach_Handler;
15473 end if;
15475 ------------------------
15476 -- Interrupt_Priority --
15477 ------------------------
15479 -- pragma Interrupt_Priority [(EXPRESSION)];
15481 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
15482 P : constant Node_Id := Parent (N);
15483 Arg : Node_Id;
15484 Ent : Entity_Id;
15486 begin
15487 Check_Ada_83_Warning;
15489 if Arg_Count /= 0 then
15490 Arg := Get_Pragma_Arg (Arg1);
15491 Check_Arg_Count (1);
15492 Check_No_Identifiers;
15494 -- The expression must be analyzed in the special manner
15495 -- described in "Handling of Default and Per-Object
15496 -- Expressions" in sem.ads.
15498 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
15499 end if;
15501 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
15502 Pragma_Misplaced;
15503 return;
15505 else
15506 Ent := Defining_Identifier (Parent (P));
15508 -- Check duplicate pragma before we chain the pragma in the Rep
15509 -- Item chain of Ent.
15511 Check_Duplicate_Pragma (Ent);
15512 Record_Rep_Item (Ent, N);
15513 end if;
15514 end Interrupt_Priority;
15516 ---------------------
15517 -- Interrupt_State --
15518 ---------------------
15520 -- pragma Interrupt_State (
15521 -- [Name =>] INTERRUPT_ID,
15522 -- [State =>] INTERRUPT_STATE);
15524 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
15525 -- INTERRUPT_STATE => System | Runtime | User
15527 -- Note: if the interrupt id is given as an identifier, then it must
15528 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
15529 -- given as a static integer expression which must be in the range of
15530 -- Ada.Interrupts.Interrupt_ID.
15532 when Pragma_Interrupt_State => Interrupt_State : declare
15533 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
15534 -- This is the entity Ada.Interrupts.Interrupt_ID;
15536 State_Type : Character;
15537 -- Set to 's'/'r'/'u' for System/Runtime/User
15539 IST_Num : Pos;
15540 -- Index to entry in Interrupt_States table
15542 Int_Val : Uint;
15543 -- Value of interrupt
15545 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
15546 -- The first argument to the pragma
15548 Int_Ent : Entity_Id;
15549 -- Interrupt entity in Ada.Interrupts.Names
15551 begin
15552 GNAT_Pragma;
15553 Check_Arg_Order ((Name_Name, Name_State));
15554 Check_Arg_Count (2);
15556 Check_Optional_Identifier (Arg1, Name_Name);
15557 Check_Optional_Identifier (Arg2, Name_State);
15558 Check_Arg_Is_Identifier (Arg2);
15560 -- First argument is identifier
15562 if Nkind (Arg1X) = N_Identifier then
15564 -- Search list of names in Ada.Interrupts.Names
15566 Int_Ent := First_Entity (RTE (RE_Names));
15567 loop
15568 if No (Int_Ent) then
15569 Error_Pragma_Arg ("invalid interrupt name", Arg1);
15571 elsif Chars (Int_Ent) = Chars (Arg1X) then
15572 Int_Val := Expr_Value (Constant_Value (Int_Ent));
15573 exit;
15574 end if;
15576 Next_Entity (Int_Ent);
15577 end loop;
15579 -- First argument is not an identifier, so it must be a static
15580 -- expression of type Ada.Interrupts.Interrupt_ID.
15582 else
15583 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
15584 Int_Val := Expr_Value (Arg1X);
15586 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
15587 or else
15588 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
15589 then
15590 Error_Pragma_Arg
15591 ("value not in range of type "
15592 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
15593 end if;
15594 end if;
15596 -- Check OK state
15598 case Chars (Get_Pragma_Arg (Arg2)) is
15599 when Name_Runtime => State_Type := 'r';
15600 when Name_System => State_Type := 's';
15601 when Name_User => State_Type := 'u';
15603 when others =>
15604 Error_Pragma_Arg ("invalid interrupt state", Arg2);
15605 end case;
15607 -- Check if entry is already stored
15609 IST_Num := Interrupt_States.First;
15610 loop
15611 -- If entry not found, add it
15613 if IST_Num > Interrupt_States.Last then
15614 Interrupt_States.Append
15615 ((Interrupt_Number => UI_To_Int (Int_Val),
15616 Interrupt_State => State_Type,
15617 Pragma_Loc => Loc));
15618 exit;
15620 -- Case of entry for the same entry
15622 elsif Int_Val = Interrupt_States.Table (IST_Num).
15623 Interrupt_Number
15624 then
15625 -- If state matches, done, no need to make redundant entry
15627 exit when
15628 State_Type = Interrupt_States.Table (IST_Num).
15629 Interrupt_State;
15631 -- Otherwise if state does not match, error
15633 Error_Msg_Sloc :=
15634 Interrupt_States.Table (IST_Num).Pragma_Loc;
15635 Error_Pragma_Arg
15636 ("state conflicts with that given #", Arg2);
15637 exit;
15638 end if;
15640 IST_Num := IST_Num + 1;
15641 end loop;
15642 end Interrupt_State;
15644 ---------------
15645 -- Invariant --
15646 ---------------
15648 -- pragma Invariant
15649 -- ([Entity =>] type_LOCAL_NAME,
15650 -- [Check =>] EXPRESSION
15651 -- [,[Message =>] String_Expression]);
15653 when Pragma_Invariant => Invariant : declare
15654 Type_Id : Node_Id;
15655 Typ : Entity_Id;
15656 Discard : Boolean;
15658 begin
15659 GNAT_Pragma;
15660 Check_At_Least_N_Arguments (2);
15661 Check_At_Most_N_Arguments (3);
15662 Check_Optional_Identifier (Arg1, Name_Entity);
15663 Check_Optional_Identifier (Arg2, Name_Check);
15665 if Arg_Count = 3 then
15666 Check_Optional_Identifier (Arg3, Name_Message);
15667 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
15668 end if;
15670 Check_Arg_Is_Local_Name (Arg1);
15672 Type_Id := Get_Pragma_Arg (Arg1);
15673 Find_Type (Type_Id);
15674 Typ := Entity (Type_Id);
15676 if Typ = Any_Type then
15677 return;
15679 -- An invariant must apply to a private type, or appear in the
15680 -- private part of a package spec and apply to a completion.
15681 -- a class-wide invariant can only appear on a private declaration
15682 -- or private extension, not a completion.
15684 elsif Ekind_In (Typ, E_Private_Type,
15685 E_Record_Type_With_Private,
15686 E_Limited_Private_Type)
15687 then
15688 null;
15690 elsif In_Private_Part (Current_Scope)
15691 and then Has_Private_Declaration (Typ)
15692 and then not Class_Present (N)
15693 then
15694 null;
15696 elsif In_Private_Part (Current_Scope) then
15697 Error_Pragma_Arg
15698 ("pragma% only allowed for private type declared in "
15699 & "visible part", Arg1);
15701 else
15702 Error_Pragma_Arg
15703 ("pragma% only allowed for private type", Arg1);
15704 end if;
15706 -- Note that the type has at least one invariant, and also that
15707 -- it has inheritable invariants if we have Invariant'Class
15708 -- or Type_Invariant'Class. Build the corresponding invariant
15709 -- procedure declaration, so that calls to it can be generated
15710 -- before the body is built (e.g. within an expression function).
15712 Insert_After_And_Analyze
15713 (N, Build_Invariant_Procedure_Declaration (Typ));
15715 if Class_Present (N) then
15716 Set_Has_Inheritable_Invariants (Typ);
15717 end if;
15719 -- The remaining processing is simply to link the pragma on to
15720 -- the rep item chain, for processing when the type is frozen.
15721 -- This is accomplished by a call to Rep_Item_Too_Late.
15723 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15724 end Invariant;
15726 ----------------------
15727 -- Java_Constructor --
15728 ----------------------
15730 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
15732 -- Also handles pragma CIL_Constructor
15734 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
15735 Java_Constructor : declare
15736 Convention : Convention_Id;
15737 Def_Id : Entity_Id;
15738 Hom_Id : Entity_Id;
15739 Id : Entity_Id;
15740 This_Formal : Entity_Id;
15742 begin
15743 GNAT_Pragma;
15744 Check_Arg_Count (1);
15745 Check_Optional_Identifier (Arg1, Name_Entity);
15746 Check_Arg_Is_Local_Name (Arg1);
15748 Id := Get_Pragma_Arg (Arg1);
15749 Find_Program_Unit_Name (Id);
15751 -- If we did not find the name, we are done
15753 if Etype (Id) = Any_Type then
15754 return;
15755 end if;
15757 -- Check wrong use of pragma in wrong VM target
15759 if VM_Target = No_VM then
15760 return;
15762 elsif VM_Target = CLI_Target
15763 and then Prag_Id = Pragma_Java_Constructor
15764 then
15765 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
15767 elsif VM_Target = JVM_Target
15768 and then Prag_Id = Pragma_CIL_Constructor
15769 then
15770 Error_Pragma ("must use pragma 'Java_'Constructor");
15771 end if;
15773 case Prag_Id is
15774 when Pragma_CIL_Constructor => Convention := Convention_CIL;
15775 when Pragma_Java_Constructor => Convention := Convention_Java;
15776 when others => null;
15777 end case;
15779 Hom_Id := Entity (Id);
15781 -- Loop through homonyms
15783 loop
15784 Def_Id := Get_Base_Subprogram (Hom_Id);
15786 -- The constructor is required to be a function
15788 if Ekind (Def_Id) /= E_Function then
15789 if VM_Target = JVM_Target then
15790 Error_Pragma_Arg
15791 ("pragma% requires function returning a 'Java access "
15792 & "type", Def_Id);
15793 else
15794 Error_Pragma_Arg
15795 ("pragma% requires function returning a 'C'I'L access "
15796 & "type", Def_Id);
15797 end if;
15798 end if;
15800 -- Check arguments: For tagged type the first formal must be
15801 -- named "this" and its type must be a named access type
15802 -- designating a class-wide tagged type that has convention
15803 -- CIL/Java. The first formal must also have a null default
15804 -- value. For example:
15806 -- type Typ is tagged ...
15807 -- type Ref is access all Typ;
15808 -- pragma Convention (CIL, Typ);
15810 -- function New_Typ (This : Ref) return Ref;
15811 -- function New_Typ (This : Ref; I : Integer) return Ref;
15812 -- pragma Cil_Constructor (New_Typ);
15814 -- Reason: The first formal must NOT be a primitive of the
15815 -- tagged type.
15817 -- This rule also applies to constructors of delegates used
15818 -- to interface with standard target libraries. For example:
15820 -- type Delegate is access procedure ...
15821 -- pragma Import (CIL, Delegate, ...);
15823 -- function new_Delegate
15824 -- (This : Delegate := null; ... ) return Delegate;
15826 -- For value-types this rule does not apply.
15828 if not Is_Value_Type (Etype (Def_Id)) then
15829 if No (First_Formal (Def_Id)) then
15830 Error_Msg_Name_1 := Pname;
15831 Error_Msg_N ("% function must have parameters", Def_Id);
15832 return;
15833 end if;
15835 -- In the JRE library we have several occurrences in which
15836 -- the "this" parameter is not the first formal.
15838 This_Formal := First_Formal (Def_Id);
15840 -- In the JRE library we have several occurrences in which
15841 -- the "this" parameter is not the first formal. Search for
15842 -- it.
15844 if VM_Target = JVM_Target then
15845 while Present (This_Formal)
15846 and then Get_Name_String (Chars (This_Formal)) /= "this"
15847 loop
15848 Next_Formal (This_Formal);
15849 end loop;
15851 if No (This_Formal) then
15852 This_Formal := First_Formal (Def_Id);
15853 end if;
15854 end if;
15856 -- Warning: The first parameter should be named "this".
15857 -- We temporarily allow it because we have the following
15858 -- case in the Java runtime (file s-osinte.ads) ???
15860 -- function new_Thread
15861 -- (Self_Id : System.Address) return Thread_Id;
15862 -- pragma Java_Constructor (new_Thread);
15864 if VM_Target = JVM_Target
15865 and then Get_Name_String (Chars (First_Formal (Def_Id)))
15866 = "self_id"
15867 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
15868 then
15869 null;
15871 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
15872 Error_Msg_Name_1 := Pname;
15873 Error_Msg_N
15874 ("first formal of % function must be named `this`",
15875 Parent (This_Formal));
15877 elsif not Is_Access_Type (Etype (This_Formal)) then
15878 Error_Msg_Name_1 := Pname;
15879 Error_Msg_N
15880 ("first formal of % function must be an access type",
15881 Parameter_Type (Parent (This_Formal)));
15883 -- For delegates the type of the first formal must be a
15884 -- named access-to-subprogram type (see previous example)
15886 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
15887 and then Ekind (Etype (This_Formal))
15888 /= E_Access_Subprogram_Type
15889 then
15890 Error_Msg_Name_1 := Pname;
15891 Error_Msg_N
15892 ("first formal of % function must be a named access "
15893 & "to subprogram type",
15894 Parameter_Type (Parent (This_Formal)));
15896 -- Warning: We should reject anonymous access types because
15897 -- the constructor must not be handled as a primitive of the
15898 -- tagged type. We temporarily allow it because this profile
15899 -- is currently generated by cil2ada???
15901 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
15902 and then not Ekind_In (Etype (This_Formal),
15903 E_Access_Type,
15904 E_General_Access_Type,
15905 E_Anonymous_Access_Type)
15906 then
15907 Error_Msg_Name_1 := Pname;
15908 Error_Msg_N
15909 ("first formal of % function must be a named access "
15910 & "type", Parameter_Type (Parent (This_Formal)));
15912 elsif Atree.Convention
15913 (Designated_Type (Etype (This_Formal))) /= Convention
15914 then
15915 Error_Msg_Name_1 := Pname;
15917 if Convention = Convention_Java then
15918 Error_Msg_N
15919 ("pragma% requires convention 'Cil in designated "
15920 & "type", Parameter_Type (Parent (This_Formal)));
15921 else
15922 Error_Msg_N
15923 ("pragma% requires convention 'Java in designated "
15924 & "type", Parameter_Type (Parent (This_Formal)));
15925 end if;
15927 elsif No (Expression (Parent (This_Formal)))
15928 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
15929 then
15930 Error_Msg_Name_1 := Pname;
15931 Error_Msg_N
15932 ("pragma% requires first formal with default `null`",
15933 Parameter_Type (Parent (This_Formal)));
15934 end if;
15935 end if;
15937 -- Check result type: the constructor must be a function
15938 -- returning:
15939 -- * a value type (only allowed in the CIL compiler)
15940 -- * an access-to-subprogram type with convention Java/CIL
15941 -- * an access-type designating a type that has convention
15942 -- Java/CIL.
15944 if Is_Value_Type (Etype (Def_Id)) then
15945 null;
15947 -- Access-to-subprogram type with convention Java/CIL
15949 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
15950 if Atree.Convention (Etype (Def_Id)) /= Convention then
15951 if Convention = Convention_Java then
15952 Error_Pragma_Arg
15953 ("pragma% requires function returning a 'Java "
15954 & "access type", Arg1);
15955 else
15956 pragma Assert (Convention = Convention_CIL);
15957 Error_Pragma_Arg
15958 ("pragma% requires function returning a 'C'I'L "
15959 & "access type", Arg1);
15960 end if;
15961 end if;
15963 elsif Is_Access_Type (Etype (Def_Id)) then
15964 if not Ekind_In (Etype (Def_Id), E_Access_Type,
15965 E_General_Access_Type)
15966 or else
15967 Atree.Convention
15968 (Designated_Type (Etype (Def_Id))) /= Convention
15969 then
15970 Error_Msg_Name_1 := Pname;
15972 if Convention = Convention_Java then
15973 Error_Pragma_Arg
15974 ("pragma% requires function returning a named "
15975 & "'Java access type", Arg1);
15976 else
15977 Error_Pragma_Arg
15978 ("pragma% requires function returning a named "
15979 & "'C'I'L access type", Arg1);
15980 end if;
15981 end if;
15982 end if;
15984 Set_Is_Constructor (Def_Id);
15985 Set_Convention (Def_Id, Convention);
15986 Set_Is_Imported (Def_Id);
15988 exit when From_Aspect_Specification (N);
15989 Hom_Id := Homonym (Hom_Id);
15991 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
15992 end loop;
15993 end Java_Constructor;
15995 ----------------------
15996 -- Java_Interface --
15997 ----------------------
15999 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
16001 when Pragma_Java_Interface => Java_Interface : declare
16002 Arg : Node_Id;
16003 Typ : Entity_Id;
16005 begin
16006 GNAT_Pragma;
16007 Check_Arg_Count (1);
16008 Check_Optional_Identifier (Arg1, Name_Entity);
16009 Check_Arg_Is_Local_Name (Arg1);
16011 Arg := Get_Pragma_Arg (Arg1);
16012 Analyze (Arg);
16014 if Etype (Arg) = Any_Type then
16015 return;
16016 end if;
16018 if not Is_Entity_Name (Arg)
16019 or else not Is_Type (Entity (Arg))
16020 then
16021 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
16022 end if;
16024 Typ := Underlying_Type (Entity (Arg));
16026 -- For now simply check some of the semantic constraints on the
16027 -- type. This currently leaves out some restrictions on interface
16028 -- types, namely that the parent type must be java.lang.Object.Typ
16029 -- and that all primitives of the type should be declared
16030 -- abstract. ???
16032 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
16033 Error_Pragma_Arg
16034 ("pragma% requires an abstract tagged type", Arg1);
16036 elsif not Has_Discriminants (Typ)
16037 or else Ekind (Etype (First_Discriminant (Typ)))
16038 /= E_Anonymous_Access_Type
16039 or else
16040 not Is_Class_Wide_Type
16041 (Designated_Type (Etype (First_Discriminant (Typ))))
16042 then
16043 Error_Pragma_Arg
16044 ("type must have a class-wide access discriminant", Arg1);
16045 end if;
16046 end Java_Interface;
16048 ----------------
16049 -- Keep_Names --
16050 ----------------
16052 -- pragma Keep_Names ([On => ] LOCAL_NAME);
16054 when Pragma_Keep_Names => Keep_Names : declare
16055 Arg : Node_Id;
16057 begin
16058 GNAT_Pragma;
16059 Check_Arg_Count (1);
16060 Check_Optional_Identifier (Arg1, Name_On);
16061 Check_Arg_Is_Local_Name (Arg1);
16063 Arg := Get_Pragma_Arg (Arg1);
16064 Analyze (Arg);
16066 if Etype (Arg) = Any_Type then
16067 return;
16068 end if;
16070 if not Is_Entity_Name (Arg)
16071 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
16072 then
16073 Error_Pragma_Arg
16074 ("pragma% requires a local enumeration type", Arg1);
16075 end if;
16077 Set_Discard_Names (Entity (Arg), False);
16078 end Keep_Names;
16080 -------------
16081 -- License --
16082 -------------
16084 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
16086 when Pragma_License =>
16087 GNAT_Pragma;
16089 -- Do not analyze pragma any further in CodePeer mode, to avoid
16090 -- extraneous errors in this implementation-dependent pragma,
16091 -- which has a different profile on other compilers.
16093 if CodePeer_Mode then
16094 return;
16095 end if;
16097 Check_Arg_Count (1);
16098 Check_No_Identifiers;
16099 Check_Valid_Configuration_Pragma;
16100 Check_Arg_Is_Identifier (Arg1);
16102 declare
16103 Sind : constant Source_File_Index :=
16104 Source_Index (Current_Sem_Unit);
16106 begin
16107 case Chars (Get_Pragma_Arg (Arg1)) is
16108 when Name_GPL =>
16109 Set_License (Sind, GPL);
16111 when Name_Modified_GPL =>
16112 Set_License (Sind, Modified_GPL);
16114 when Name_Restricted =>
16115 Set_License (Sind, Restricted);
16117 when Name_Unrestricted =>
16118 Set_License (Sind, Unrestricted);
16120 when others =>
16121 Error_Pragma_Arg ("invalid license name", Arg1);
16122 end case;
16123 end;
16125 ---------------
16126 -- Link_With --
16127 ---------------
16129 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
16131 when Pragma_Link_With => Link_With : declare
16132 Arg : Node_Id;
16134 begin
16135 GNAT_Pragma;
16137 if Operating_Mode = Generate_Code
16138 and then In_Extended_Main_Source_Unit (N)
16139 then
16140 Check_At_Least_N_Arguments (1);
16141 Check_No_Identifiers;
16142 Check_Is_In_Decl_Part_Or_Package_Spec;
16143 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16144 Start_String;
16146 Arg := Arg1;
16147 while Present (Arg) loop
16148 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
16150 -- Store argument, converting sequences of spaces to a
16151 -- single null character (this is one of the differences
16152 -- in processing between Link_With and Linker_Options).
16154 Arg_Store : declare
16155 C : constant Char_Code := Get_Char_Code (' ');
16156 S : constant String_Id :=
16157 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
16158 L : constant Nat := String_Length (S);
16159 F : Nat := 1;
16161 procedure Skip_Spaces;
16162 -- Advance F past any spaces
16164 -----------------
16165 -- Skip_Spaces --
16166 -----------------
16168 procedure Skip_Spaces is
16169 begin
16170 while F <= L and then Get_String_Char (S, F) = C loop
16171 F := F + 1;
16172 end loop;
16173 end Skip_Spaces;
16175 -- Start of processing for Arg_Store
16177 begin
16178 Skip_Spaces; -- skip leading spaces
16180 -- Loop through characters, changing any embedded
16181 -- sequence of spaces to a single null character (this
16182 -- is how Link_With/Linker_Options differ)
16184 while F <= L loop
16185 if Get_String_Char (S, F) = C then
16186 Skip_Spaces;
16187 exit when F > L;
16188 Store_String_Char (ASCII.NUL);
16190 else
16191 Store_String_Char (Get_String_Char (S, F));
16192 F := F + 1;
16193 end if;
16194 end loop;
16195 end Arg_Store;
16197 Arg := Next (Arg);
16199 if Present (Arg) then
16200 Store_String_Char (ASCII.NUL);
16201 end if;
16202 end loop;
16204 Store_Linker_Option_String (End_String);
16205 end if;
16206 end Link_With;
16208 ------------------
16209 -- Linker_Alias --
16210 ------------------
16212 -- pragma Linker_Alias (
16213 -- [Entity =>] LOCAL_NAME
16214 -- [Target =>] static_string_EXPRESSION);
16216 when Pragma_Linker_Alias =>
16217 GNAT_Pragma;
16218 Check_Arg_Order ((Name_Entity, Name_Target));
16219 Check_Arg_Count (2);
16220 Check_Optional_Identifier (Arg1, Name_Entity);
16221 Check_Optional_Identifier (Arg2, Name_Target);
16222 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16223 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16225 -- The only processing required is to link this item on to the
16226 -- list of rep items for the given entity. This is accomplished
16227 -- by the call to Rep_Item_Too_Late (when no error is detected
16228 -- and False is returned).
16230 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
16231 return;
16232 else
16233 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
16234 end if;
16236 ------------------------
16237 -- Linker_Constructor --
16238 ------------------------
16240 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
16242 -- Code is shared with Linker_Destructor
16244 -----------------------
16245 -- Linker_Destructor --
16246 -----------------------
16248 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
16250 when Pragma_Linker_Constructor |
16251 Pragma_Linker_Destructor =>
16252 Linker_Constructor : declare
16253 Arg1_X : Node_Id;
16254 Proc : Entity_Id;
16256 begin
16257 GNAT_Pragma;
16258 Check_Arg_Count (1);
16259 Check_No_Identifiers;
16260 Check_Arg_Is_Local_Name (Arg1);
16261 Arg1_X := Get_Pragma_Arg (Arg1);
16262 Analyze (Arg1_X);
16263 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
16265 if not Is_Library_Level_Entity (Proc) then
16266 Error_Pragma_Arg
16267 ("argument for pragma% must be library level entity", Arg1);
16268 end if;
16270 -- The only processing required is to link this item on to the
16271 -- list of rep items for the given entity. This is accomplished
16272 -- by the call to Rep_Item_Too_Late (when no error is detected
16273 -- and False is returned).
16275 if Rep_Item_Too_Late (Proc, N) then
16276 return;
16277 else
16278 Set_Has_Gigi_Rep_Item (Proc);
16279 end if;
16280 end Linker_Constructor;
16282 --------------------
16283 -- Linker_Options --
16284 --------------------
16286 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
16288 when Pragma_Linker_Options => Linker_Options : declare
16289 Arg : Node_Id;
16291 begin
16292 Check_Ada_83_Warning;
16293 Check_No_Identifiers;
16294 Check_Arg_Count (1);
16295 Check_Is_In_Decl_Part_Or_Package_Spec;
16296 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16297 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
16299 Arg := Arg2;
16300 while Present (Arg) loop
16301 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
16302 Store_String_Char (ASCII.NUL);
16303 Store_String_Chars
16304 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
16305 Arg := Next (Arg);
16306 end loop;
16308 if Operating_Mode = Generate_Code
16309 and then In_Extended_Main_Source_Unit (N)
16310 then
16311 Store_Linker_Option_String (End_String);
16312 end if;
16313 end Linker_Options;
16315 --------------------
16316 -- Linker_Section --
16317 --------------------
16319 -- pragma Linker_Section (
16320 -- [Entity =>] LOCAL_NAME
16321 -- [Section =>] static_string_EXPRESSION);
16323 when Pragma_Linker_Section => Linker_Section : declare
16324 Arg : Node_Id;
16325 Ent : Entity_Id;
16326 LPE : Node_Id;
16328 begin
16329 GNAT_Pragma;
16330 Check_Arg_Order ((Name_Entity, Name_Section));
16331 Check_Arg_Count (2);
16332 Check_Optional_Identifier (Arg1, Name_Entity);
16333 Check_Optional_Identifier (Arg2, Name_Section);
16334 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16335 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16337 -- Check kind of entity
16339 Arg := Get_Pragma_Arg (Arg1);
16340 Ent := Entity (Arg);
16342 case Ekind (Ent) is
16344 -- Objects (constants and variables) and types. For these cases
16345 -- all we need to do is to set the Linker_Section_pragma field,
16346 -- checking that we do not have a duplicate.
16348 when E_Constant | E_Variable | Type_Kind =>
16349 LPE := Linker_Section_Pragma (Ent);
16351 if Present (LPE) then
16352 Error_Msg_Sloc := Sloc (LPE);
16353 Error_Msg_NE
16354 ("Linker_Section already specified for &#", Arg1, Ent);
16355 end if;
16357 Set_Linker_Section_Pragma (Ent, N);
16359 -- Subprograms
16361 when Subprogram_Kind =>
16363 -- Aspect case, entity already set
16365 if From_Aspect_Specification (N) then
16366 Set_Linker_Section_Pragma
16367 (Entity (Corresponding_Aspect (N)), N);
16369 -- Pragma case, we must climb the homonym chain, but skip
16370 -- any for which the linker section is already set.
16372 else
16373 loop
16374 if No (Linker_Section_Pragma (Ent)) then
16375 Set_Linker_Section_Pragma (Ent, N);
16376 end if;
16378 Ent := Homonym (Ent);
16379 exit when No (Ent)
16380 or else Scope (Ent) /= Current_Scope;
16381 end loop;
16382 end if;
16384 -- All other cases are illegal
16386 when others =>
16387 Error_Pragma_Arg
16388 ("pragma% applies only to objects, subprograms, and types",
16389 Arg1);
16390 end case;
16391 end Linker_Section;
16393 ----------
16394 -- List --
16395 ----------
16397 -- pragma List (On | Off)
16399 -- There is nothing to do here, since we did all the processing for
16400 -- this pragma in Par.Prag (so that it works properly even in syntax
16401 -- only mode).
16403 when Pragma_List =>
16404 null;
16406 ---------------
16407 -- Lock_Free --
16408 ---------------
16410 -- pragma Lock_Free [(Boolean_EXPRESSION)];
16412 when Pragma_Lock_Free => Lock_Free : declare
16413 P : constant Node_Id := Parent (N);
16414 Arg : Node_Id;
16415 Ent : Entity_Id;
16416 Val : Boolean;
16418 begin
16419 Check_No_Identifiers;
16420 Check_At_Most_N_Arguments (1);
16422 -- Protected definition case
16424 if Nkind (P) = N_Protected_Definition then
16425 Ent := Defining_Identifier (Parent (P));
16427 -- One argument
16429 if Arg_Count = 1 then
16430 Arg := Get_Pragma_Arg (Arg1);
16431 Val := Is_True (Static_Boolean (Arg));
16433 -- No arguments (expression is considered to be True)
16435 else
16436 Val := True;
16437 end if;
16439 -- Check duplicate pragma before we chain the pragma in the Rep
16440 -- Item chain of Ent.
16442 Check_Duplicate_Pragma (Ent);
16443 Record_Rep_Item (Ent, N);
16444 Set_Uses_Lock_Free (Ent, Val);
16446 -- Anything else is incorrect placement
16448 else
16449 Pragma_Misplaced;
16450 end if;
16451 end Lock_Free;
16453 --------------------
16454 -- Locking_Policy --
16455 --------------------
16457 -- pragma Locking_Policy (policy_IDENTIFIER);
16459 when Pragma_Locking_Policy => declare
16460 subtype LP_Range is Name_Id
16461 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
16462 LP_Val : LP_Range;
16463 LP : Character;
16465 begin
16466 Check_Ada_83_Warning;
16467 Check_Arg_Count (1);
16468 Check_No_Identifiers;
16469 Check_Arg_Is_Locking_Policy (Arg1);
16470 Check_Valid_Configuration_Pragma;
16471 LP_Val := Chars (Get_Pragma_Arg (Arg1));
16473 case LP_Val is
16474 when Name_Ceiling_Locking =>
16475 LP := 'C';
16476 when Name_Inheritance_Locking =>
16477 LP := 'I';
16478 when Name_Concurrent_Readers_Locking =>
16479 LP := 'R';
16480 end case;
16482 if Locking_Policy /= ' '
16483 and then Locking_Policy /= LP
16484 then
16485 Error_Msg_Sloc := Locking_Policy_Sloc;
16486 Error_Pragma ("locking policy incompatible with policy#");
16488 -- Set new policy, but always preserve System_Location since we
16489 -- like the error message with the run time name.
16491 else
16492 Locking_Policy := LP;
16494 if Locking_Policy_Sloc /= System_Location then
16495 Locking_Policy_Sloc := Loc;
16496 end if;
16497 end if;
16498 end;
16500 -------------------
16501 -- Loop_Optimize --
16502 -------------------
16504 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
16506 -- OPTIMIZATION_HINT ::=
16507 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
16509 when Pragma_Loop_Optimize => Loop_Optimize : declare
16510 Hint : Node_Id;
16512 begin
16513 GNAT_Pragma;
16514 Check_At_Least_N_Arguments (1);
16515 Check_No_Identifiers;
16517 Hint := First (Pragma_Argument_Associations (N));
16518 while Present (Hint) loop
16519 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
16520 Name_No_Unroll,
16521 Name_Unroll,
16522 Name_No_Vector,
16523 Name_Vector);
16524 Next (Hint);
16525 end loop;
16527 Check_Loop_Pragma_Placement;
16528 end Loop_Optimize;
16530 ------------------
16531 -- Loop_Variant --
16532 ------------------
16534 -- pragma Loop_Variant
16535 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
16537 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
16539 -- CHANGE_DIRECTION ::= Increases | Decreases
16541 when Pragma_Loop_Variant => Loop_Variant : declare
16542 Variant : Node_Id;
16544 begin
16545 GNAT_Pragma;
16546 Check_At_Least_N_Arguments (1);
16547 Check_Loop_Pragma_Placement;
16549 -- Process all increasing / decreasing expressions
16551 Variant := First (Pragma_Argument_Associations (N));
16552 while Present (Variant) loop
16553 if not Nam_In (Chars (Variant), Name_Decreases,
16554 Name_Increases)
16555 then
16556 Error_Pragma_Arg ("wrong change modifier", Variant);
16557 end if;
16559 Preanalyze_Assert_Expression
16560 (Expression (Variant), Any_Discrete);
16562 Next (Variant);
16563 end loop;
16564 end Loop_Variant;
16566 -----------------------
16567 -- Machine_Attribute --
16568 -----------------------
16570 -- pragma Machine_Attribute (
16571 -- [Entity =>] LOCAL_NAME,
16572 -- [Attribute_Name =>] static_string_EXPRESSION
16573 -- [, [Info =>] static_EXPRESSION] );
16575 when Pragma_Machine_Attribute => Machine_Attribute : declare
16576 Def_Id : Entity_Id;
16578 begin
16579 GNAT_Pragma;
16580 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
16582 if Arg_Count = 3 then
16583 Check_Optional_Identifier (Arg3, Name_Info);
16584 Check_Arg_Is_OK_Static_Expression (Arg3);
16585 else
16586 Check_Arg_Count (2);
16587 end if;
16589 Check_Optional_Identifier (Arg1, Name_Entity);
16590 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
16591 Check_Arg_Is_Local_Name (Arg1);
16592 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16593 Def_Id := Entity (Get_Pragma_Arg (Arg1));
16595 if Is_Access_Type (Def_Id) then
16596 Def_Id := Designated_Type (Def_Id);
16597 end if;
16599 if Rep_Item_Too_Early (Def_Id, N) then
16600 return;
16601 end if;
16603 Def_Id := Underlying_Type (Def_Id);
16605 -- The only processing required is to link this item on to the
16606 -- list of rep items for the given entity. This is accomplished
16607 -- by the call to Rep_Item_Too_Late (when no error is detected
16608 -- and False is returned).
16610 if Rep_Item_Too_Late (Def_Id, N) then
16611 return;
16612 else
16613 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
16614 end if;
16615 end Machine_Attribute;
16617 ----------
16618 -- Main --
16619 ----------
16621 -- pragma Main
16622 -- (MAIN_OPTION [, MAIN_OPTION]);
16624 -- MAIN_OPTION ::=
16625 -- [STACK_SIZE =>] static_integer_EXPRESSION
16626 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
16627 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
16629 when Pragma_Main => Main : declare
16630 Args : Args_List (1 .. 3);
16631 Names : constant Name_List (1 .. 3) := (
16632 Name_Stack_Size,
16633 Name_Task_Stack_Size_Default,
16634 Name_Time_Slicing_Enabled);
16636 Nod : Node_Id;
16638 begin
16639 GNAT_Pragma;
16640 Gather_Associations (Names, Args);
16642 for J in 1 .. 2 loop
16643 if Present (Args (J)) then
16644 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
16645 end if;
16646 end loop;
16648 if Present (Args (3)) then
16649 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
16650 end if;
16652 Nod := Next (N);
16653 while Present (Nod) loop
16654 if Nkind (Nod) = N_Pragma
16655 and then Pragma_Name (Nod) = Name_Main
16656 then
16657 Error_Msg_Name_1 := Pname;
16658 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16659 end if;
16661 Next (Nod);
16662 end loop;
16663 end Main;
16665 ------------------
16666 -- Main_Storage --
16667 ------------------
16669 -- pragma Main_Storage
16670 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
16672 -- MAIN_STORAGE_OPTION ::=
16673 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
16674 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
16676 when Pragma_Main_Storage => Main_Storage : declare
16677 Args : Args_List (1 .. 2);
16678 Names : constant Name_List (1 .. 2) := (
16679 Name_Working_Storage,
16680 Name_Top_Guard);
16682 Nod : Node_Id;
16684 begin
16685 GNAT_Pragma;
16686 Gather_Associations (Names, Args);
16688 for J in 1 .. 2 loop
16689 if Present (Args (J)) then
16690 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
16691 end if;
16692 end loop;
16694 Check_In_Main_Program;
16696 Nod := Next (N);
16697 while Present (Nod) loop
16698 if Nkind (Nod) = N_Pragma
16699 and then Pragma_Name (Nod) = Name_Main_Storage
16700 then
16701 Error_Msg_Name_1 := Pname;
16702 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16703 end if;
16705 Next (Nod);
16706 end loop;
16707 end Main_Storage;
16709 -----------------
16710 -- Memory_Size --
16711 -----------------
16713 -- pragma Memory_Size (NUMERIC_LITERAL)
16715 when Pragma_Memory_Size =>
16716 GNAT_Pragma;
16718 -- Memory size is simply ignored
16720 Check_No_Identifiers;
16721 Check_Arg_Count (1);
16722 Check_Arg_Is_Integer_Literal (Arg1);
16724 -------------
16725 -- No_Body --
16726 -------------
16728 -- pragma No_Body;
16730 -- The only correct use of this pragma is on its own in a file, in
16731 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
16732 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
16733 -- check for a file containing nothing but a No_Body pragma). If we
16734 -- attempt to process it during normal semantics processing, it means
16735 -- it was misplaced.
16737 when Pragma_No_Body =>
16738 GNAT_Pragma;
16739 Pragma_Misplaced;
16741 -----------------------------
16742 -- No_Elaboration_Code_All --
16743 -----------------------------
16745 -- pragma No_Elaboration_Code_All;
16747 when Pragma_No_Elaboration_Code_All => NECA : declare
16748 begin
16749 GNAT_Pragma;
16750 Check_Valid_Library_Unit_Pragma;
16752 if Nkind (N) = N_Null_Statement then
16753 return;
16754 end if;
16756 -- Must appear for a spec or generic spec
16758 if not Nkind_In (Unit (Cunit (Current_Sem_Unit)),
16759 N_Generic_Package_Declaration,
16760 N_Generic_Subprogram_Declaration,
16761 N_Package_Declaration,
16762 N_Subprogram_Declaration)
16763 then
16764 Error_Pragma
16765 (Fix_Error
16766 ("pragma% can only occur for package "
16767 & "or subprogram spec"));
16768 end if;
16770 -- Set flag in unit table
16772 Set_No_Elab_Code_All (Current_Sem_Unit);
16774 -- Set restriction No_Elaboration_Code if this is the main unit
16776 if Current_Sem_Unit = Main_Unit then
16777 Set_Restriction (No_Elaboration_Code, N);
16778 end if;
16780 -- If we are in the main unit or in an extended main source unit,
16781 -- then we also add it to the configuration restrictions so that
16782 -- it will apply to all units in the extended main source.
16784 if Current_Sem_Unit = Main_Unit
16785 or else In_Extended_Main_Source_Unit (N)
16786 then
16787 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
16788 end if;
16790 -- If in main extended unit, activate transitive with test
16792 if In_Extended_Main_Source_Unit (N) then
16793 Opt.No_Elab_Code_All_Pragma := N;
16794 end if;
16795 end NECA;
16797 ---------------
16798 -- No_Inline --
16799 ---------------
16801 -- pragma No_Inline ( NAME {, NAME} );
16803 when Pragma_No_Inline =>
16804 GNAT_Pragma;
16805 Process_Inline (Suppressed);
16807 ---------------
16808 -- No_Return --
16809 ---------------
16811 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
16813 when Pragma_No_Return => No_Return : declare
16814 Id : Node_Id;
16815 E : Entity_Id;
16816 Found : Boolean;
16817 Arg : Node_Id;
16819 begin
16820 Ada_2005_Pragma;
16821 Check_At_Least_N_Arguments (1);
16823 -- Loop through arguments of pragma
16825 Arg := Arg1;
16826 while Present (Arg) loop
16827 Check_Arg_Is_Local_Name (Arg);
16828 Id := Get_Pragma_Arg (Arg);
16829 Analyze (Id);
16831 if not Is_Entity_Name (Id) then
16832 Error_Pragma_Arg ("entity name required", Arg);
16833 end if;
16835 if Etype (Id) = Any_Type then
16836 raise Pragma_Exit;
16837 end if;
16839 -- Loop to find matching procedures
16841 E := Entity (Id);
16842 Found := False;
16843 while Present (E)
16844 and then Scope (E) = Current_Scope
16845 loop
16846 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
16847 Set_No_Return (E);
16849 -- Set flag on any alias as well
16851 if Is_Overloadable (E) and then Present (Alias (E)) then
16852 Set_No_Return (Alias (E));
16853 end if;
16855 Found := True;
16856 end if;
16858 exit when From_Aspect_Specification (N);
16859 E := Homonym (E);
16860 end loop;
16862 -- If entity in not in current scope it may be the enclosing
16863 -- suprogram body to which the aspect applies.
16865 if not Found then
16866 if Entity (Id) = Current_Scope
16867 and then From_Aspect_Specification (N)
16868 then
16869 Set_No_Return (Entity (Id));
16870 else
16871 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
16872 end if;
16873 end if;
16875 Next (Arg);
16876 end loop;
16877 end No_Return;
16879 -----------------
16880 -- No_Run_Time --
16881 -----------------
16883 -- pragma No_Run_Time;
16885 -- Note: this pragma is retained for backwards compatibility. See
16886 -- body of Rtsfind for full details on its handling.
16888 when Pragma_No_Run_Time =>
16889 GNAT_Pragma;
16890 Check_Valid_Configuration_Pragma;
16891 Check_Arg_Count (0);
16893 No_Run_Time_Mode := True;
16894 Configurable_Run_Time_Mode := True;
16896 -- Set Duration to 32 bits if word size is 32
16898 if Ttypes.System_Word_Size = 32 then
16899 Duration_32_Bits_On_Target := True;
16900 end if;
16902 -- Set appropriate restrictions
16904 Set_Restriction (No_Finalization, N);
16905 Set_Restriction (No_Exception_Handlers, N);
16906 Set_Restriction (Max_Tasks, N, 0);
16907 Set_Restriction (No_Tasking, N);
16909 -----------------------
16910 -- No_Tagged_Streams --
16911 -----------------------
16913 -- pragma No_Tagged_Streams;
16914 -- pragma No_Tagged_Streams ([Entity => ]tagged_type_local_NAME);
16916 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
16917 E_Id : Node_Id;
16918 E : Entity_Id;
16920 begin
16921 GNAT_Pragma;
16922 Check_At_Most_N_Arguments (1);
16924 -- One argument case
16926 if Arg_Count = 1 then
16927 Check_Optional_Identifier (Arg1, Name_Entity);
16928 Check_Arg_Is_Local_Name (Arg1);
16929 E_Id := Get_Pragma_Arg (Arg1);
16931 if Etype (E_Id) = Any_Type then
16932 return;
16933 end if;
16935 E := Entity (E_Id);
16937 Check_Duplicate_Pragma (E);
16939 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
16940 Error_Pragma_Arg
16941 ("argument for pragma% must be root tagged type", Arg1);
16942 end if;
16944 if Rep_Item_Too_Early (E, N)
16945 or else
16946 Rep_Item_Too_Late (E, N)
16947 then
16948 return;
16949 else
16950 Set_No_Tagged_Streams_Pragma (E, N);
16951 end if;
16953 -- Zero argument case
16955 else
16956 Check_Is_In_Decl_Part_Or_Package_Spec;
16957 No_Tagged_Streams := N;
16958 end if;
16959 end No_Tagged_Strms;
16961 ------------------------
16962 -- No_Strict_Aliasing --
16963 ------------------------
16965 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
16967 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
16968 E_Id : Entity_Id;
16970 begin
16971 GNAT_Pragma;
16972 Check_At_Most_N_Arguments (1);
16974 if Arg_Count = 0 then
16975 Check_Valid_Configuration_Pragma;
16976 Opt.No_Strict_Aliasing := True;
16978 else
16979 Check_Optional_Identifier (Arg2, Name_Entity);
16980 Check_Arg_Is_Local_Name (Arg1);
16981 E_Id := Entity (Get_Pragma_Arg (Arg1));
16983 if E_Id = Any_Type then
16984 return;
16985 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
16986 Error_Pragma_Arg ("pragma% requires access type", Arg1);
16987 end if;
16989 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
16990 end if;
16991 end No_Strict_Aliasing;
16993 -----------------------
16994 -- Normalize_Scalars --
16995 -----------------------
16997 -- pragma Normalize_Scalars;
16999 when Pragma_Normalize_Scalars =>
17000 Check_Ada_83_Warning;
17001 Check_Arg_Count (0);
17002 Check_Valid_Configuration_Pragma;
17004 -- Normalize_Scalars creates false positives in CodePeer, and
17005 -- incorrect negative results in GNATprove mode, so ignore this
17006 -- pragma in these modes.
17008 if not (CodePeer_Mode or GNATprove_Mode) then
17009 Normalize_Scalars := True;
17010 Init_Or_Norm_Scalars := True;
17011 end if;
17013 -----------------
17014 -- Obsolescent --
17015 -----------------
17017 -- pragma Obsolescent;
17019 -- pragma Obsolescent (
17020 -- [Message =>] static_string_EXPRESSION
17021 -- [,[Version =>] Ada_05]]);
17023 -- pragma Obsolescent (
17024 -- [Entity =>] NAME
17025 -- [,[Message =>] static_string_EXPRESSION
17026 -- [,[Version =>] Ada_05]] );
17028 when Pragma_Obsolescent => Obsolescent : declare
17029 Ename : Node_Id;
17030 Decl : Node_Id;
17032 procedure Set_Obsolescent (E : Entity_Id);
17033 -- Given an entity Ent, mark it as obsolescent if appropriate
17035 ---------------------
17036 -- Set_Obsolescent --
17037 ---------------------
17039 procedure Set_Obsolescent (E : Entity_Id) is
17040 Active : Boolean;
17041 Ent : Entity_Id;
17042 S : String_Id;
17044 begin
17045 Active := True;
17046 Ent := E;
17048 -- Entity name was given
17050 if Present (Ename) then
17052 -- If entity name matches, we are fine. Save entity in
17053 -- pragma argument, for ASIS use.
17055 if Chars (Ename) = Chars (Ent) then
17056 Set_Entity (Ename, Ent);
17057 Generate_Reference (Ent, Ename);
17059 -- If entity name does not match, only possibility is an
17060 -- enumeration literal from an enumeration type declaration.
17062 elsif Ekind (Ent) /= E_Enumeration_Type then
17063 Error_Pragma
17064 ("pragma % entity name does not match declaration");
17066 else
17067 Ent := First_Literal (E);
17068 loop
17069 if No (Ent) then
17070 Error_Pragma
17071 ("pragma % entity name does not match any "
17072 & "enumeration literal");
17074 elsif Chars (Ent) = Chars (Ename) then
17075 Set_Entity (Ename, Ent);
17076 Generate_Reference (Ent, Ename);
17077 exit;
17079 else
17080 Ent := Next_Literal (Ent);
17081 end if;
17082 end loop;
17083 end if;
17084 end if;
17086 -- Ent points to entity to be marked
17088 if Arg_Count >= 1 then
17090 -- Deal with static string argument
17092 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17093 S := Strval (Get_Pragma_Arg (Arg1));
17095 for J in 1 .. String_Length (S) loop
17096 if not In_Character_Range (Get_String_Char (S, J)) then
17097 Error_Pragma_Arg
17098 ("pragma% argument does not allow wide characters",
17099 Arg1);
17100 end if;
17101 end loop;
17103 Obsolescent_Warnings.Append
17104 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
17106 -- Check for Ada_05 parameter
17108 if Arg_Count /= 1 then
17109 Check_Arg_Count (2);
17111 declare
17112 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
17114 begin
17115 Check_Arg_Is_Identifier (Argx);
17117 if Chars (Argx) /= Name_Ada_05 then
17118 Error_Msg_Name_2 := Name_Ada_05;
17119 Error_Pragma_Arg
17120 ("only allowed argument for pragma% is %", Argx);
17121 end if;
17123 if Ada_Version_Explicit < Ada_2005
17124 or else not Warn_On_Ada_2005_Compatibility
17125 then
17126 Active := False;
17127 end if;
17128 end;
17129 end if;
17130 end if;
17132 -- Set flag if pragma active
17134 if Active then
17135 Set_Is_Obsolescent (Ent);
17136 end if;
17138 return;
17139 end Set_Obsolescent;
17141 -- Start of processing for pragma Obsolescent
17143 begin
17144 GNAT_Pragma;
17146 Check_At_Most_N_Arguments (3);
17148 -- See if first argument specifies an entity name
17150 if Arg_Count >= 1
17151 and then
17152 (Chars (Arg1) = Name_Entity
17153 or else
17154 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
17155 N_Identifier,
17156 N_Operator_Symbol))
17157 then
17158 Ename := Get_Pragma_Arg (Arg1);
17160 -- Eliminate first argument, so we can share processing
17162 Arg1 := Arg2;
17163 Arg2 := Arg3;
17164 Arg_Count := Arg_Count - 1;
17166 -- No Entity name argument given
17168 else
17169 Ename := Empty;
17170 end if;
17172 if Arg_Count >= 1 then
17173 Check_Optional_Identifier (Arg1, Name_Message);
17175 if Arg_Count = 2 then
17176 Check_Optional_Identifier (Arg2, Name_Version);
17177 end if;
17178 end if;
17180 -- Get immediately preceding declaration
17182 Decl := Prev (N);
17183 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
17184 Prev (Decl);
17185 end loop;
17187 -- Cases where we do not follow anything other than another pragma
17189 if No (Decl) then
17191 -- First case: library level compilation unit declaration with
17192 -- the pragma immediately following the declaration.
17194 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
17195 Set_Obsolescent
17196 (Defining_Entity (Unit (Parent (Parent (N)))));
17197 return;
17199 -- Case 2: library unit placement for package
17201 else
17202 declare
17203 Ent : constant Entity_Id := Find_Lib_Unit_Name;
17204 begin
17205 if Is_Package_Or_Generic_Package (Ent) then
17206 Set_Obsolescent (Ent);
17207 return;
17208 end if;
17209 end;
17210 end if;
17212 -- Cases where we must follow a declaration
17214 else
17215 if Nkind (Decl) not in N_Declaration
17216 and then Nkind (Decl) not in N_Later_Decl_Item
17217 and then Nkind (Decl) not in N_Generic_Declaration
17218 and then Nkind (Decl) not in N_Renaming_Declaration
17219 then
17220 Error_Pragma
17221 ("pragma% misplaced, "
17222 & "must immediately follow a declaration");
17224 else
17225 Set_Obsolescent (Defining_Entity (Decl));
17226 return;
17227 end if;
17228 end if;
17229 end Obsolescent;
17231 --------------
17232 -- Optimize --
17233 --------------
17235 -- pragma Optimize (Time | Space | Off);
17237 -- The actual check for optimize is done in Gigi. Note that this
17238 -- pragma does not actually change the optimization setting, it
17239 -- simply checks that it is consistent with the pragma.
17241 when Pragma_Optimize =>
17242 Check_No_Identifiers;
17243 Check_Arg_Count (1);
17244 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
17246 ------------------------
17247 -- Optimize_Alignment --
17248 ------------------------
17250 -- pragma Optimize_Alignment (Time | Space | Off);
17252 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
17253 GNAT_Pragma;
17254 Check_No_Identifiers;
17255 Check_Arg_Count (1);
17256 Check_Valid_Configuration_Pragma;
17258 declare
17259 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
17260 begin
17261 case Nam is
17262 when Name_Time =>
17263 Opt.Optimize_Alignment := 'T';
17264 when Name_Space =>
17265 Opt.Optimize_Alignment := 'S';
17266 when Name_Off =>
17267 Opt.Optimize_Alignment := 'O';
17268 when others =>
17269 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
17270 end case;
17271 end;
17273 -- Set indication that mode is set locally. If we are in fact in a
17274 -- configuration pragma file, this setting is harmless since the
17275 -- switch will get reset anyway at the start of each unit.
17277 Optimize_Alignment_Local := True;
17278 end Optimize_Alignment;
17280 -------------
17281 -- Ordered --
17282 -------------
17284 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
17286 when Pragma_Ordered => Ordered : declare
17287 Assoc : constant Node_Id := Arg1;
17288 Type_Id : Node_Id;
17289 Typ : Entity_Id;
17291 begin
17292 GNAT_Pragma;
17293 Check_No_Identifiers;
17294 Check_Arg_Count (1);
17295 Check_Arg_Is_Local_Name (Arg1);
17297 Type_Id := Get_Pragma_Arg (Assoc);
17298 Find_Type (Type_Id);
17299 Typ := Entity (Type_Id);
17301 if Typ = Any_Type then
17302 return;
17303 else
17304 Typ := Underlying_Type (Typ);
17305 end if;
17307 if not Is_Enumeration_Type (Typ) then
17308 Error_Pragma ("pragma% must specify enumeration type");
17309 end if;
17311 Check_First_Subtype (Arg1);
17312 Set_Has_Pragma_Ordered (Base_Type (Typ));
17313 end Ordered;
17315 -------------------
17316 -- Overflow_Mode --
17317 -------------------
17319 -- pragma Overflow_Mode
17320 -- ([General => ] MODE [, [Assertions => ] MODE]);
17322 -- MODE := STRICT | MINIMIZED | ELIMINATED
17324 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
17325 -- since System.Bignums makes this assumption. This is true of nearly
17326 -- all (all?) targets.
17328 when Pragma_Overflow_Mode => Overflow_Mode : declare
17329 function Get_Overflow_Mode
17330 (Name : Name_Id;
17331 Arg : Node_Id) return Overflow_Mode_Type;
17332 -- Function to process one pragma argument, Arg. If an identifier
17333 -- is present, it must be Name. Mode type is returned if a valid
17334 -- argument exists, otherwise an error is signalled.
17336 -----------------------
17337 -- Get_Overflow_Mode --
17338 -----------------------
17340 function Get_Overflow_Mode
17341 (Name : Name_Id;
17342 Arg : Node_Id) return Overflow_Mode_Type
17344 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
17346 begin
17347 Check_Optional_Identifier (Arg, Name);
17348 Check_Arg_Is_Identifier (Argx);
17350 if Chars (Argx) = Name_Strict then
17351 return Strict;
17353 elsif Chars (Argx) = Name_Minimized then
17354 return Minimized;
17356 elsif Chars (Argx) = Name_Eliminated then
17357 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
17358 Error_Pragma_Arg
17359 ("Eliminated not implemented on this target", Argx);
17360 else
17361 return Eliminated;
17362 end if;
17364 else
17365 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
17366 end if;
17367 end Get_Overflow_Mode;
17369 -- Start of processing for Overflow_Mode
17371 begin
17372 GNAT_Pragma;
17373 Check_At_Least_N_Arguments (1);
17374 Check_At_Most_N_Arguments (2);
17376 -- Process first argument
17378 Scope_Suppress.Overflow_Mode_General :=
17379 Get_Overflow_Mode (Name_General, Arg1);
17381 -- Case of only one argument
17383 if Arg_Count = 1 then
17384 Scope_Suppress.Overflow_Mode_Assertions :=
17385 Scope_Suppress.Overflow_Mode_General;
17387 -- Case of two arguments present
17389 else
17390 Scope_Suppress.Overflow_Mode_Assertions :=
17391 Get_Overflow_Mode (Name_Assertions, Arg2);
17392 end if;
17393 end Overflow_Mode;
17395 --------------------------
17396 -- Overriding Renamings --
17397 --------------------------
17399 -- pragma Overriding_Renamings;
17401 when Pragma_Overriding_Renamings =>
17402 GNAT_Pragma;
17403 Check_Arg_Count (0);
17404 Check_Valid_Configuration_Pragma;
17405 Overriding_Renamings := True;
17407 ----------
17408 -- Pack --
17409 ----------
17411 -- pragma Pack (first_subtype_LOCAL_NAME);
17413 when Pragma_Pack => Pack : declare
17414 Assoc : constant Node_Id := Arg1;
17415 Type_Id : Node_Id;
17416 Typ : Entity_Id;
17417 Ctyp : Entity_Id;
17418 Ignore : Boolean := False;
17420 begin
17421 Check_No_Identifiers;
17422 Check_Arg_Count (1);
17423 Check_Arg_Is_Local_Name (Arg1);
17424 Type_Id := Get_Pragma_Arg (Assoc);
17426 if not Is_Entity_Name (Type_Id)
17427 or else not Is_Type (Entity (Type_Id))
17428 then
17429 Error_Pragma_Arg
17430 ("argument for pragma% must be type or subtype", Arg1);
17431 end if;
17433 Find_Type (Type_Id);
17434 Typ := Entity (Type_Id);
17436 if Typ = Any_Type
17437 or else Rep_Item_Too_Early (Typ, N)
17438 then
17439 return;
17440 else
17441 Typ := Underlying_Type (Typ);
17442 end if;
17444 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
17445 Error_Pragma ("pragma% must specify array or record type");
17446 end if;
17448 Check_First_Subtype (Arg1);
17449 Check_Duplicate_Pragma (Typ);
17451 -- Array type
17453 if Is_Array_Type (Typ) then
17454 Ctyp := Component_Type (Typ);
17456 -- Ignore pack that does nothing
17458 if Known_Static_Esize (Ctyp)
17459 and then Known_Static_RM_Size (Ctyp)
17460 and then Esize (Ctyp) = RM_Size (Ctyp)
17461 and then Addressable (Esize (Ctyp))
17462 then
17463 Ignore := True;
17464 end if;
17466 -- Process OK pragma Pack. Note that if there is a separate
17467 -- component clause present, the Pack will be cancelled. This
17468 -- processing is in Freeze.
17470 if not Rep_Item_Too_Late (Typ, N) then
17472 -- In CodePeer mode, we do not need complex front-end
17473 -- expansions related to pragma Pack, so disable handling
17474 -- of pragma Pack.
17476 if CodePeer_Mode then
17477 null;
17479 -- Don't attempt any packing for VM targets. We possibly
17480 -- could deal with some cases of array bit-packing, but we
17481 -- don't bother, since this is not a typical kind of
17482 -- representation in the VM context anyway (and would not
17483 -- for example work nicely with the debugger).
17485 elsif VM_Target /= No_VM then
17486 if not GNAT_Mode then
17487 Error_Pragma
17488 ("??pragma% ignored in this configuration");
17489 end if;
17491 -- Normal case where we do the pack action
17493 else
17494 if not Ignore then
17495 Set_Is_Packed (Base_Type (Typ));
17496 Set_Has_Non_Standard_Rep (Base_Type (Typ));
17497 end if;
17499 Set_Has_Pragma_Pack (Base_Type (Typ));
17500 end if;
17501 end if;
17503 -- For record types, the pack is always effective
17505 else pragma Assert (Is_Record_Type (Typ));
17506 if not Rep_Item_Too_Late (Typ, N) then
17508 -- Ignore pack request with warning in VM mode (skip warning
17509 -- if we are compiling GNAT run time library).
17511 if VM_Target /= No_VM then
17512 if not GNAT_Mode then
17513 Error_Pragma
17514 ("??pragma% ignored in this configuration");
17515 end if;
17517 -- Normal case of pack request active
17519 else
17520 Set_Is_Packed (Base_Type (Typ));
17521 Set_Has_Pragma_Pack (Base_Type (Typ));
17522 Set_Has_Non_Standard_Rep (Base_Type (Typ));
17523 end if;
17524 end if;
17525 end if;
17526 end Pack;
17528 ----------
17529 -- Page --
17530 ----------
17532 -- pragma Page;
17534 -- There is nothing to do here, since we did all the processing for
17535 -- this pragma in Par.Prag (so that it works properly even in syntax
17536 -- only mode).
17538 when Pragma_Page =>
17539 null;
17541 -------------
17542 -- Part_Of --
17543 -------------
17545 -- pragma Part_Of (ABSTRACT_STATE);
17547 -- ABSTRACT_STATE ::= NAME
17549 when Pragma_Part_Of => Part_Of : declare
17550 procedure Propagate_Part_Of
17551 (Pack_Id : Entity_Id;
17552 State_Id : Entity_Id;
17553 Instance : Node_Id);
17554 -- Propagate the Part_Of indicator to all abstract states and
17555 -- variables declared in the visible state space of a package
17556 -- denoted by Pack_Id. State_Id is the encapsulating state.
17557 -- Instance is the package instantiation node.
17559 -----------------------
17560 -- Propagate_Part_Of --
17561 -----------------------
17563 procedure Propagate_Part_Of
17564 (Pack_Id : Entity_Id;
17565 State_Id : Entity_Id;
17566 Instance : Node_Id)
17568 Has_Item : Boolean := False;
17569 -- Flag set when the visible state space contains at least one
17570 -- abstract state or variable.
17572 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
17573 -- Propagate the Part_Of indicator to all abstract states and
17574 -- variables declared in the visible state space of a package
17575 -- denoted by Pack_Id.
17577 -----------------------
17578 -- Propagate_Part_Of --
17579 -----------------------
17581 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
17582 Item_Id : Entity_Id;
17584 begin
17585 -- Traverse the entity chain of the package and set relevant
17586 -- attributes of abstract states and variables declared in
17587 -- the visible state space of the package.
17589 Item_Id := First_Entity (Pack_Id);
17590 while Present (Item_Id)
17591 and then not In_Private_Part (Item_Id)
17592 loop
17593 -- Do not consider internally generated items
17595 if not Comes_From_Source (Item_Id) then
17596 null;
17598 -- The Part_Of indicator turns an abstract state or
17599 -- variable into a constituent of the encapsulating
17600 -- state.
17602 elsif Ekind_In (Item_Id, E_Abstract_State,
17603 E_Variable)
17604 then
17605 Has_Item := True;
17607 Append_Elmt (Item_Id, Part_Of_Constituents (State_Id));
17608 Set_Encapsulating_State (Item_Id, State_Id);
17610 -- Recursively handle nested packages and instantiations
17612 elsif Ekind (Item_Id) = E_Package then
17613 Propagate_Part_Of (Item_Id);
17614 end if;
17616 Next_Entity (Item_Id);
17617 end loop;
17618 end Propagate_Part_Of;
17620 -- Start of processing for Propagate_Part_Of
17622 begin
17623 Propagate_Part_Of (Pack_Id);
17625 -- Detect a package instantiation that is subject to a Part_Of
17626 -- indicator, but has no visible state.
17628 if not Has_Item then
17629 SPARK_Msg_NE
17630 ("package instantiation & has Part_Of indicator but "
17631 & "lacks visible state", Instance, Pack_Id);
17632 end if;
17633 end Propagate_Part_Of;
17635 -- Local variables
17637 Item_Id : Entity_Id;
17638 Legal : Boolean;
17639 State : Node_Id;
17640 State_Id : Entity_Id;
17641 Stmt : Node_Id;
17643 -- Start of processing for Part_Of
17645 begin
17646 GNAT_Pragma;
17647 Check_No_Identifiers;
17648 Check_Arg_Count (1);
17650 -- Ensure the proper placement of the pragma. Part_Of must appear
17651 -- on a variable declaration or a package instantiation.
17653 Stmt := Prev (N);
17654 while Present (Stmt) loop
17656 -- Skip prior pragmas, but check for duplicates
17658 if Nkind (Stmt) = N_Pragma then
17659 if Pragma_Name (Stmt) = Pname then
17660 Error_Msg_Name_1 := Pname;
17661 Error_Msg_Sloc := Sloc (Stmt);
17662 Error_Msg_N ("pragma% duplicates pragma declared#", N);
17663 end if;
17665 -- Skip internally generated code
17667 elsif not Comes_From_Source (Stmt) then
17668 null;
17670 -- The pragma applies to an object declaration (possibly a
17671 -- variable) or a package instantiation. Stop the traversal
17672 -- and continue the analysis.
17674 elsif Nkind_In (Stmt, N_Object_Declaration,
17675 N_Package_Instantiation)
17676 then
17677 exit;
17679 -- The pragma does not apply to a legal construct, issue an
17680 -- error and stop the analysis.
17682 else
17683 Pragma_Misplaced;
17684 return;
17685 end if;
17687 Stmt := Prev (Stmt);
17688 end loop;
17690 -- When the context is an object declaration, ensure that we are
17691 -- dealing with a variable.
17693 if Nkind (Stmt) = N_Object_Declaration
17694 and then Ekind (Defining_Entity (Stmt)) /= E_Variable
17695 then
17696 SPARK_Msg_N ("indicator Part_Of must apply to a variable", N);
17697 return;
17698 end if;
17700 -- Extract the entity of the related object declaration or package
17701 -- instantiation. In the case of the instantiation, use the entity
17702 -- of the instance spec.
17704 if Nkind (Stmt) = N_Package_Instantiation then
17705 Stmt := Instance_Spec (Stmt);
17706 end if;
17708 Item_Id := Defining_Entity (Stmt);
17709 State := Get_Pragma_Arg (Arg1);
17711 -- Detect any discrepancies between the placement of the object
17712 -- or package instantiation with respect to state space and the
17713 -- encapsulating state.
17715 Analyze_Part_Of
17716 (Item_Id => Item_Id,
17717 State => State,
17718 Indic => N,
17719 Legal => Legal);
17721 if Legal then
17722 State_Id := Entity (State);
17724 -- Add the pragma to the contract of the item. This aids with
17725 -- the detection of a missing but required Part_Of indicator.
17727 Add_Contract_Item (N, Item_Id);
17729 -- The Part_Of indicator turns a variable into a constituent
17730 -- of the encapsulating state.
17732 if Ekind (Item_Id) = E_Variable then
17733 Append_Elmt (Item_Id, Part_Of_Constituents (State_Id));
17734 Set_Encapsulating_State (Item_Id, State_Id);
17736 -- Propagate the Part_Of indicator to the visible state space
17737 -- of the package instantiation.
17739 else
17740 Propagate_Part_Of
17741 (Pack_Id => Item_Id,
17742 State_Id => State_Id,
17743 Instance => Stmt);
17744 end if;
17745 end if;
17746 end Part_Of;
17748 ----------------------------------
17749 -- Partition_Elaboration_Policy --
17750 ----------------------------------
17752 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
17754 when Pragma_Partition_Elaboration_Policy => declare
17755 subtype PEP_Range is Name_Id
17756 range First_Partition_Elaboration_Policy_Name
17757 .. Last_Partition_Elaboration_Policy_Name;
17758 PEP_Val : PEP_Range;
17759 PEP : Character;
17761 begin
17762 Ada_2005_Pragma;
17763 Check_Arg_Count (1);
17764 Check_No_Identifiers;
17765 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
17766 Check_Valid_Configuration_Pragma;
17767 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
17769 case PEP_Val is
17770 when Name_Concurrent =>
17771 PEP := 'C';
17772 when Name_Sequential =>
17773 PEP := 'S';
17774 end case;
17776 if Partition_Elaboration_Policy /= ' '
17777 and then Partition_Elaboration_Policy /= PEP
17778 then
17779 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
17780 Error_Pragma
17781 ("partition elaboration policy incompatible with policy#");
17783 -- Set new policy, but always preserve System_Location since we
17784 -- like the error message with the run time name.
17786 else
17787 Partition_Elaboration_Policy := PEP;
17789 if Partition_Elaboration_Policy_Sloc /= System_Location then
17790 Partition_Elaboration_Policy_Sloc := Loc;
17791 end if;
17792 end if;
17793 end;
17795 -------------
17796 -- Passive --
17797 -------------
17799 -- pragma Passive [(PASSIVE_FORM)];
17801 -- PASSIVE_FORM ::= Semaphore | No
17803 when Pragma_Passive =>
17804 GNAT_Pragma;
17806 if Nkind (Parent (N)) /= N_Task_Definition then
17807 Error_Pragma ("pragma% must be within task definition");
17808 end if;
17810 if Arg_Count /= 0 then
17811 Check_Arg_Count (1);
17812 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
17813 end if;
17815 ----------------------------------
17816 -- Preelaborable_Initialization --
17817 ----------------------------------
17819 -- pragma Preelaborable_Initialization (DIRECT_NAME);
17821 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
17822 Ent : Entity_Id;
17824 begin
17825 Ada_2005_Pragma;
17826 Check_Arg_Count (1);
17827 Check_No_Identifiers;
17828 Check_Arg_Is_Identifier (Arg1);
17829 Check_Arg_Is_Local_Name (Arg1);
17830 Check_First_Subtype (Arg1);
17831 Ent := Entity (Get_Pragma_Arg (Arg1));
17833 -- The pragma may come from an aspect on a private declaration,
17834 -- even if the freeze point at which this is analyzed in the
17835 -- private part after the full view.
17837 if Has_Private_Declaration (Ent)
17838 and then From_Aspect_Specification (N)
17839 then
17840 null;
17842 -- Check appropriate type argument
17844 elsif Is_Private_Type (Ent)
17845 or else Is_Protected_Type (Ent)
17846 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
17848 -- AI05-0028: The pragma applies to all composite types. Note
17849 -- that we apply this binding intepretation to previous verions
17850 -- of Ada so there is no Ada 2012 guard. Seems a reasonable
17851 -- choice since there are other compilers that do the same.
17853 or else Is_Composite_Type (Ent)
17854 then
17855 null;
17857 else
17858 Error_Pragma_Arg
17859 ("pragma % can only be applied to private, formal derived, "
17860 & "protected, or composite type", Arg1);
17861 end if;
17863 -- Give an error if the pragma is applied to a protected type that
17864 -- does not qualify (due to having entries, or due to components
17865 -- that do not qualify).
17867 if Is_Protected_Type (Ent)
17868 and then not Has_Preelaborable_Initialization (Ent)
17869 then
17870 Error_Msg_N
17871 ("protected type & does not have preelaborable "
17872 & "initialization", Ent);
17874 -- Otherwise mark the type as definitely having preelaborable
17875 -- initialization.
17877 else
17878 Set_Known_To_Have_Preelab_Init (Ent);
17879 end if;
17881 if Has_Pragma_Preelab_Init (Ent)
17882 and then Warn_On_Redundant_Constructs
17883 then
17884 Error_Pragma ("?r?duplicate pragma%!");
17885 else
17886 Set_Has_Pragma_Preelab_Init (Ent);
17887 end if;
17888 end Preelab_Init;
17890 --------------------
17891 -- Persistent_BSS --
17892 --------------------
17894 -- pragma Persistent_BSS [(object_NAME)];
17896 when Pragma_Persistent_BSS => Persistent_BSS : declare
17897 Decl : Node_Id;
17898 Ent : Entity_Id;
17899 Prag : Node_Id;
17901 begin
17902 GNAT_Pragma;
17903 Check_At_Most_N_Arguments (1);
17905 -- Case of application to specific object (one argument)
17907 if Arg_Count = 1 then
17908 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17910 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
17911 or else not
17912 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
17913 E_Constant)
17914 then
17915 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
17916 end if;
17918 Ent := Entity (Get_Pragma_Arg (Arg1));
17919 Decl := Parent (Ent);
17921 -- Check for duplication before inserting in list of
17922 -- representation items.
17924 Check_Duplicate_Pragma (Ent);
17926 if Rep_Item_Too_Late (Ent, N) then
17927 return;
17928 end if;
17930 if Present (Expression (Decl)) then
17931 Error_Pragma_Arg
17932 ("object for pragma% cannot have initialization", Arg1);
17933 end if;
17935 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
17936 Error_Pragma_Arg
17937 ("object type for pragma% is not potentially persistent",
17938 Arg1);
17939 end if;
17941 Prag :=
17942 Make_Linker_Section_Pragma
17943 (Ent, Sloc (N), ".persistent.bss");
17944 Insert_After (N, Prag);
17945 Analyze (Prag);
17947 -- Case of use as configuration pragma with no arguments
17949 else
17950 Check_Valid_Configuration_Pragma;
17951 Persistent_BSS_Mode := True;
17952 end if;
17953 end Persistent_BSS;
17955 -------------
17956 -- Polling --
17957 -------------
17959 -- pragma Polling (ON | OFF);
17961 when Pragma_Polling =>
17962 GNAT_Pragma;
17963 Check_Arg_Count (1);
17964 Check_No_Identifiers;
17965 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
17966 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
17968 ------------------
17969 -- Post[_Class] --
17970 ------------------
17972 -- pragma Post (Boolean_EXPRESSION);
17973 -- pragma Post_Class (Boolean_EXPRESSION);
17975 when Pragma_Post | Pragma_Post_Class => Post : declare
17976 PC_Pragma : Node_Id;
17978 begin
17979 GNAT_Pragma;
17980 Check_Arg_Count (1);
17981 Check_No_Identifiers;
17982 Check_Pre_Post;
17984 -- Rewrite Post[_Class] pragma as Postcondition pragma setting the
17985 -- flag Class_Present to True for the Post_Class case.
17987 Set_Class_Present (N, Prag_Id = Pragma_Post_Class);
17988 PC_Pragma := New_Copy (N);
17989 Set_Pragma_Identifier
17990 (PC_Pragma, Make_Identifier (Loc, Name_Postcondition));
17991 Rewrite (N, PC_Pragma);
17992 Set_Analyzed (N, False);
17993 Analyze (N);
17994 end Post;
17996 -------------------
17997 -- Postcondition --
17998 -------------------
18000 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
18001 -- [,[Message =>] String_EXPRESSION]);
18003 when Pragma_Postcondition => Postcondition : declare
18004 In_Body : Boolean;
18006 begin
18007 GNAT_Pragma;
18008 Check_At_Least_N_Arguments (1);
18009 Check_At_Most_N_Arguments (2);
18010 Check_Optional_Identifier (Arg1, Name_Check);
18012 -- Verify the proper placement of the pragma. The remainder of the
18013 -- processing is found in Sem_Ch6/Sem_Ch7.
18015 Check_Precondition_Postcondition (In_Body);
18017 -- When the pragma is a source construct appearing inside a body,
18018 -- preanalyze the boolean_expression to detect illegal forward
18019 -- references:
18021 -- procedure P is
18022 -- pragma Postcondition (X'Old ...);
18023 -- X : ...
18025 if Comes_From_Source (N) and then In_Body then
18026 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
18027 end if;
18028 end Postcondition;
18030 -----------------
18031 -- Pre[_Class] --
18032 -----------------
18034 -- pragma Pre (Boolean_EXPRESSION);
18035 -- pragma Pre_Class (Boolean_EXPRESSION);
18037 when Pragma_Pre | Pragma_Pre_Class => Pre : declare
18038 PC_Pragma : Node_Id;
18040 begin
18041 GNAT_Pragma;
18042 Check_Arg_Count (1);
18043 Check_No_Identifiers;
18044 Check_Pre_Post;
18046 -- Rewrite Pre[_Class] pragma as Precondition pragma setting the
18047 -- flag Class_Present to True for the Pre_Class case.
18049 Set_Class_Present (N, Prag_Id = Pragma_Pre_Class);
18050 PC_Pragma := New_Copy (N);
18051 Set_Pragma_Identifier
18052 (PC_Pragma, Make_Identifier (Loc, Name_Precondition));
18053 Rewrite (N, PC_Pragma);
18054 Set_Analyzed (N, False);
18055 Analyze (N);
18056 end Pre;
18058 ------------------
18059 -- Precondition --
18060 ------------------
18062 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
18063 -- [,[Message =>] String_EXPRESSION]);
18065 when Pragma_Precondition => Precondition : declare
18066 In_Body : Boolean;
18068 begin
18069 GNAT_Pragma;
18070 Check_At_Least_N_Arguments (1);
18071 Check_At_Most_N_Arguments (2);
18072 Check_Optional_Identifier (Arg1, Name_Check);
18073 Check_Precondition_Postcondition (In_Body);
18075 -- If in spec, nothing more to do. If in body, then we convert
18076 -- the pragma to an equivalent pragma Check. That works fine since
18077 -- pragma Check will analyze the condition in the proper context.
18079 -- The form of the pragma Check is either:
18081 -- pragma Check (Precondition, cond [, msg])
18082 -- or
18083 -- pragma Check (Pre, cond [, msg])
18085 -- We use the Pre form if this pragma derived from a Pre aspect.
18086 -- This is needed to make sure that the right set of Policy
18087 -- pragmas are checked.
18089 if In_Body then
18091 -- Rewrite as Check pragma
18093 Rewrite (N,
18094 Make_Pragma (Loc,
18095 Chars => Name_Check,
18096 Pragma_Argument_Associations => New_List (
18097 Make_Pragma_Argument_Association (Loc,
18098 Expression => Make_Identifier (Loc, Pname)),
18100 Make_Pragma_Argument_Association (Sloc (Arg1),
18101 Expression =>
18102 Relocate_Node (Get_Pragma_Arg (Arg1))))));
18104 if Arg_Count = 2 then
18105 Append_To (Pragma_Argument_Associations (N),
18106 Make_Pragma_Argument_Association (Sloc (Arg2),
18107 Expression =>
18108 Relocate_Node (Get_Pragma_Arg (Arg2))));
18109 end if;
18111 Analyze (N);
18112 end if;
18113 end Precondition;
18115 ---------------
18116 -- Predicate --
18117 ---------------
18119 -- pragma Predicate
18120 -- ([Entity =>] type_LOCAL_NAME,
18121 -- [Check =>] boolean_EXPRESSION);
18123 when Pragma_Predicate => Predicate : declare
18124 Type_Id : Node_Id;
18125 Typ : Entity_Id;
18126 Discard : Boolean;
18128 begin
18129 GNAT_Pragma;
18130 Check_Arg_Count (2);
18131 Check_Optional_Identifier (Arg1, Name_Entity);
18132 Check_Optional_Identifier (Arg2, Name_Check);
18134 Check_Arg_Is_Local_Name (Arg1);
18136 Type_Id := Get_Pragma_Arg (Arg1);
18137 Find_Type (Type_Id);
18138 Typ := Entity (Type_Id);
18140 if Typ = Any_Type then
18141 return;
18142 end if;
18144 -- The remaining processing is simply to link the pragma on to
18145 -- the rep item chain, for processing when the type is frozen.
18146 -- This is accomplished by a call to Rep_Item_Too_Late. We also
18147 -- mark the type as having predicates.
18149 Set_Has_Predicates (Typ);
18150 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18151 end Predicate;
18153 ------------------
18154 -- Preelaborate --
18155 ------------------
18157 -- pragma Preelaborate [(library_unit_NAME)];
18159 -- Set the flag Is_Preelaborated of program unit name entity
18161 when Pragma_Preelaborate => Preelaborate : declare
18162 Pa : constant Node_Id := Parent (N);
18163 Pk : constant Node_Kind := Nkind (Pa);
18164 Ent : Entity_Id;
18166 begin
18167 Check_Ada_83_Warning;
18168 Check_Valid_Library_Unit_Pragma;
18170 if Nkind (N) = N_Null_Statement then
18171 return;
18172 end if;
18174 Ent := Find_Lib_Unit_Name;
18175 Check_Duplicate_Pragma (Ent);
18177 -- This filters out pragmas inside generic parents that show up
18178 -- inside instantiations. Pragmas that come from aspects in the
18179 -- unit are not ignored.
18181 if Present (Ent) then
18182 if Pk = N_Package_Specification
18183 and then Present (Generic_Parent (Pa))
18184 and then not From_Aspect_Specification (N)
18185 then
18186 null;
18188 else
18189 if not Debug_Flag_U then
18190 Set_Is_Preelaborated (Ent);
18191 Set_Suppress_Elaboration_Warnings (Ent);
18192 end if;
18193 end if;
18194 end if;
18195 end Preelaborate;
18197 -------------------------------
18198 -- Prefix_Exception_Messages --
18199 -------------------------------
18201 -- pragma Prefix_Exception_Messages;
18203 when Pragma_Prefix_Exception_Messages =>
18204 GNAT_Pragma;
18205 Check_Valid_Configuration_Pragma;
18206 Check_Arg_Count (0);
18207 Prefix_Exception_Messages := True;
18209 --------------
18210 -- Priority --
18211 --------------
18213 -- pragma Priority (EXPRESSION);
18215 when Pragma_Priority => Priority : declare
18216 P : constant Node_Id := Parent (N);
18217 Arg : Node_Id;
18218 Ent : Entity_Id;
18220 begin
18221 Check_No_Identifiers;
18222 Check_Arg_Count (1);
18224 -- Subprogram case
18226 if Nkind (P) = N_Subprogram_Body then
18227 Check_In_Main_Program;
18229 Ent := Defining_Unit_Name (Specification (P));
18231 if Nkind (Ent) = N_Defining_Program_Unit_Name then
18232 Ent := Defining_Identifier (Ent);
18233 end if;
18235 Arg := Get_Pragma_Arg (Arg1);
18236 Analyze_And_Resolve (Arg, Standard_Integer);
18238 -- Must be static
18240 if not Is_OK_Static_Expression (Arg) then
18241 Flag_Non_Static_Expr
18242 ("main subprogram priority is not static!", Arg);
18243 raise Pragma_Exit;
18245 -- If constraint error, then we already signalled an error
18247 elsif Raises_Constraint_Error (Arg) then
18248 null;
18250 -- Otherwise check in range except if Relaxed_RM_Semantics
18251 -- where we ignore the value if out of range.
18253 else
18254 declare
18255 Val : constant Uint := Expr_Value (Arg);
18256 begin
18257 if not Relaxed_RM_Semantics
18258 and then
18259 (Val < 0
18260 or else Val > Expr_Value (Expression
18261 (Parent (RTE (RE_Max_Priority)))))
18262 then
18263 Error_Pragma_Arg
18264 ("main subprogram priority is out of range", Arg1);
18265 else
18266 Set_Main_Priority
18267 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
18268 end if;
18269 end;
18270 end if;
18272 -- Load an arbitrary entity from System.Tasking.Stages or
18273 -- System.Tasking.Restricted.Stages (depending on the
18274 -- supported profile) to make sure that one of these packages
18275 -- is implicitly with'ed, since we need to have the tasking
18276 -- run time active for the pragma Priority to have any effect.
18277 -- Previously we with'ed the package System.Tasking, but this
18278 -- package does not trigger the required initialization of the
18279 -- run-time library.
18281 declare
18282 Discard : Entity_Id;
18283 pragma Warnings (Off, Discard);
18284 begin
18285 if Restricted_Profile then
18286 Discard := RTE (RE_Activate_Restricted_Tasks);
18287 else
18288 Discard := RTE (RE_Activate_Tasks);
18289 end if;
18290 end;
18292 -- Task or Protected, must be of type Integer
18294 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
18295 Arg := Get_Pragma_Arg (Arg1);
18296 Ent := Defining_Identifier (Parent (P));
18298 -- The expression must be analyzed in the special manner
18299 -- described in "Handling of Default and Per-Object
18300 -- Expressions" in sem.ads.
18302 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
18304 if not Is_OK_Static_Expression (Arg) then
18305 Check_Restriction (Static_Priorities, Arg);
18306 end if;
18308 -- Anything else is incorrect
18310 else
18311 Pragma_Misplaced;
18312 end if;
18314 -- Check duplicate pragma before we chain the pragma in the Rep
18315 -- Item chain of Ent.
18317 Check_Duplicate_Pragma (Ent);
18318 Record_Rep_Item (Ent, N);
18319 end Priority;
18321 -----------------------------------
18322 -- Priority_Specific_Dispatching --
18323 -----------------------------------
18325 -- pragma Priority_Specific_Dispatching (
18326 -- policy_IDENTIFIER,
18327 -- first_priority_EXPRESSION,
18328 -- last_priority_EXPRESSION);
18330 when Pragma_Priority_Specific_Dispatching =>
18331 Priority_Specific_Dispatching : declare
18332 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
18333 -- This is the entity System.Any_Priority;
18335 DP : Character;
18336 Lower_Bound : Node_Id;
18337 Upper_Bound : Node_Id;
18338 Lower_Val : Uint;
18339 Upper_Val : Uint;
18341 begin
18342 Ada_2005_Pragma;
18343 Check_Arg_Count (3);
18344 Check_No_Identifiers;
18345 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
18346 Check_Valid_Configuration_Pragma;
18347 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
18348 DP := Fold_Upper (Name_Buffer (1));
18350 Lower_Bound := Get_Pragma_Arg (Arg2);
18351 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
18352 Lower_Val := Expr_Value (Lower_Bound);
18354 Upper_Bound := Get_Pragma_Arg (Arg3);
18355 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
18356 Upper_Val := Expr_Value (Upper_Bound);
18358 -- It is not allowed to use Task_Dispatching_Policy and
18359 -- Priority_Specific_Dispatching in the same partition.
18361 if Task_Dispatching_Policy /= ' ' then
18362 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
18363 Error_Pragma
18364 ("pragma% incompatible with Task_Dispatching_Policy#");
18366 -- Check lower bound in range
18368 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
18369 or else
18370 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
18371 then
18372 Error_Pragma_Arg
18373 ("first_priority is out of range", Arg2);
18375 -- Check upper bound in range
18377 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
18378 or else
18379 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
18380 then
18381 Error_Pragma_Arg
18382 ("last_priority is out of range", Arg3);
18384 -- Check that the priority range is valid
18386 elsif Lower_Val > Upper_Val then
18387 Error_Pragma
18388 ("last_priority_expression must be greater than or equal to "
18389 & "first_priority_expression");
18391 -- Store the new policy, but always preserve System_Location since
18392 -- we like the error message with the run-time name.
18394 else
18395 -- Check overlapping in the priority ranges specified in other
18396 -- Priority_Specific_Dispatching pragmas within the same
18397 -- partition. We can only check those we know about.
18399 for J in
18400 Specific_Dispatching.First .. Specific_Dispatching.Last
18401 loop
18402 if Specific_Dispatching.Table (J).First_Priority in
18403 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
18404 or else Specific_Dispatching.Table (J).Last_Priority in
18405 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
18406 then
18407 Error_Msg_Sloc :=
18408 Specific_Dispatching.Table (J).Pragma_Loc;
18409 Error_Pragma
18410 ("priority range overlaps with "
18411 & "Priority_Specific_Dispatching#");
18412 end if;
18413 end loop;
18415 -- The use of Priority_Specific_Dispatching is incompatible
18416 -- with Task_Dispatching_Policy.
18418 if Task_Dispatching_Policy /= ' ' then
18419 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
18420 Error_Pragma
18421 ("Priority_Specific_Dispatching incompatible "
18422 & "with Task_Dispatching_Policy#");
18423 end if;
18425 -- The use of Priority_Specific_Dispatching forces ceiling
18426 -- locking policy.
18428 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
18429 Error_Msg_Sloc := Locking_Policy_Sloc;
18430 Error_Pragma
18431 ("Priority_Specific_Dispatching incompatible "
18432 & "with Locking_Policy#");
18434 -- Set the Ceiling_Locking policy, but preserve System_Location
18435 -- since we like the error message with the run time name.
18437 else
18438 Locking_Policy := 'C';
18440 if Locking_Policy_Sloc /= System_Location then
18441 Locking_Policy_Sloc := Loc;
18442 end if;
18443 end if;
18445 -- Add entry in the table
18447 Specific_Dispatching.Append
18448 ((Dispatching_Policy => DP,
18449 First_Priority => UI_To_Int (Lower_Val),
18450 Last_Priority => UI_To_Int (Upper_Val),
18451 Pragma_Loc => Loc));
18452 end if;
18453 end Priority_Specific_Dispatching;
18455 -------------
18456 -- Profile --
18457 -------------
18459 -- pragma Profile (profile_IDENTIFIER);
18461 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
18463 when Pragma_Profile =>
18464 Ada_2005_Pragma;
18465 Check_Arg_Count (1);
18466 Check_Valid_Configuration_Pragma;
18467 Check_No_Identifiers;
18469 declare
18470 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
18472 begin
18473 if Chars (Argx) = Name_Ravenscar then
18474 Set_Ravenscar_Profile (N);
18476 elsif Chars (Argx) = Name_Restricted then
18477 Set_Profile_Restrictions
18478 (Restricted,
18479 N, Warn => Treat_Restrictions_As_Warnings);
18481 elsif Chars (Argx) = Name_Rational then
18482 Set_Rational_Profile;
18484 elsif Chars (Argx) = Name_No_Implementation_Extensions then
18485 Set_Profile_Restrictions
18486 (No_Implementation_Extensions,
18487 N, Warn => Treat_Restrictions_As_Warnings);
18489 else
18490 Error_Pragma_Arg ("& is not a valid profile", Argx);
18491 end if;
18492 end;
18494 ----------------------
18495 -- Profile_Warnings --
18496 ----------------------
18498 -- pragma Profile_Warnings (profile_IDENTIFIER);
18500 -- profile_IDENTIFIER => Restricted | Ravenscar
18502 when Pragma_Profile_Warnings =>
18503 GNAT_Pragma;
18504 Check_Arg_Count (1);
18505 Check_Valid_Configuration_Pragma;
18506 Check_No_Identifiers;
18508 declare
18509 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
18511 begin
18512 if Chars (Argx) = Name_Ravenscar then
18513 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
18515 elsif Chars (Argx) = Name_Restricted then
18516 Set_Profile_Restrictions (Restricted, N, Warn => True);
18518 elsif Chars (Argx) = Name_No_Implementation_Extensions then
18519 Set_Profile_Restrictions
18520 (No_Implementation_Extensions, N, Warn => True);
18522 else
18523 Error_Pragma_Arg ("& is not a valid profile", Argx);
18524 end if;
18525 end;
18527 --------------------------
18528 -- Propagate_Exceptions --
18529 --------------------------
18531 -- pragma Propagate_Exceptions;
18533 -- Note: this pragma is obsolete and has no effect
18535 when Pragma_Propagate_Exceptions =>
18536 GNAT_Pragma;
18537 Check_Arg_Count (0);
18539 if Warn_On_Obsolescent_Feature then
18540 Error_Msg_N
18541 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
18542 "and has no effect?j?", N);
18543 end if;
18545 -----------------------------
18546 -- Provide_Shift_Operators --
18547 -----------------------------
18549 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
18551 when Pragma_Provide_Shift_Operators =>
18552 Provide_Shift_Operators : declare
18553 Ent : Entity_Id;
18555 procedure Declare_Shift_Operator (Nam : Name_Id);
18556 -- Insert declaration and pragma Instrinsic for named shift op
18558 ----------------------------
18559 -- Declare_Shift_Operator --
18560 ----------------------------
18562 procedure Declare_Shift_Operator (Nam : Name_Id) is
18563 Func : Node_Id;
18564 Import : Node_Id;
18566 begin
18567 Func :=
18568 Make_Subprogram_Declaration (Loc,
18569 Make_Function_Specification (Loc,
18570 Defining_Unit_Name =>
18571 Make_Defining_Identifier (Loc, Chars => Nam),
18573 Result_Definition =>
18574 Make_Identifier (Loc, Chars => Chars (Ent)),
18576 Parameter_Specifications => New_List (
18577 Make_Parameter_Specification (Loc,
18578 Defining_Identifier =>
18579 Make_Defining_Identifier (Loc, Name_Value),
18580 Parameter_Type =>
18581 Make_Identifier (Loc, Chars => Chars (Ent))),
18583 Make_Parameter_Specification (Loc,
18584 Defining_Identifier =>
18585 Make_Defining_Identifier (Loc, Name_Amount),
18586 Parameter_Type =>
18587 New_Occurrence_Of (Standard_Natural, Loc)))));
18589 Import :=
18590 Make_Pragma (Loc,
18591 Pragma_Identifier => Make_Identifier (Loc, Name_Import),
18592 Pragma_Argument_Associations => New_List (
18593 Make_Pragma_Argument_Association (Loc,
18594 Expression => Make_Identifier (Loc, Name_Intrinsic)),
18595 Make_Pragma_Argument_Association (Loc,
18596 Expression => Make_Identifier (Loc, Nam))));
18598 Insert_After (N, Import);
18599 Insert_After (N, Func);
18600 end Declare_Shift_Operator;
18602 -- Start of processing for Provide_Shift_Operators
18604 begin
18605 GNAT_Pragma;
18606 Check_Arg_Count (1);
18607 Check_Arg_Is_Local_Name (Arg1);
18609 Arg1 := Get_Pragma_Arg (Arg1);
18611 -- We must have an entity name
18613 if not Is_Entity_Name (Arg1) then
18614 Error_Pragma_Arg
18615 ("pragma % must apply to integer first subtype", Arg1);
18616 end if;
18618 -- If no Entity, means there was a prior error so ignore
18620 if Present (Entity (Arg1)) then
18621 Ent := Entity (Arg1);
18623 -- Apply error checks
18625 if not Is_First_Subtype (Ent) then
18626 Error_Pragma_Arg
18627 ("cannot apply pragma %",
18628 "\& is not a first subtype",
18629 Arg1);
18631 elsif not Is_Integer_Type (Ent) then
18632 Error_Pragma_Arg
18633 ("cannot apply pragma %",
18634 "\& is not an integer type",
18635 Arg1);
18637 elsif Has_Shift_Operator (Ent) then
18638 Error_Pragma_Arg
18639 ("cannot apply pragma %",
18640 "\& already has declared shift operators",
18641 Arg1);
18643 elsif Is_Frozen (Ent) then
18644 Error_Pragma_Arg
18645 ("pragma % appears too late",
18646 "\& is already frozen",
18647 Arg1);
18648 end if;
18650 -- Now declare the operators. We do this during analysis rather
18651 -- than expansion, since we want the operators available if we
18652 -- are operating in -gnatc or ASIS mode.
18654 Declare_Shift_Operator (Name_Rotate_Left);
18655 Declare_Shift_Operator (Name_Rotate_Right);
18656 Declare_Shift_Operator (Name_Shift_Left);
18657 Declare_Shift_Operator (Name_Shift_Right);
18658 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
18659 end if;
18660 end Provide_Shift_Operators;
18662 ------------------
18663 -- Psect_Object --
18664 ------------------
18666 -- pragma Psect_Object (
18667 -- [Internal =>] LOCAL_NAME,
18668 -- [, [External =>] EXTERNAL_SYMBOL]
18669 -- [, [Size =>] EXTERNAL_SYMBOL]);
18671 when Pragma_Psect_Object | Pragma_Common_Object =>
18672 Psect_Object : declare
18673 Args : Args_List (1 .. 3);
18674 Names : constant Name_List (1 .. 3) := (
18675 Name_Internal,
18676 Name_External,
18677 Name_Size);
18679 Internal : Node_Id renames Args (1);
18680 External : Node_Id renames Args (2);
18681 Size : Node_Id renames Args (3);
18683 Def_Id : Entity_Id;
18685 procedure Check_Arg (Arg : Node_Id);
18686 -- Checks that argument is either a string literal or an
18687 -- identifier, and posts error message if not.
18689 ---------------
18690 -- Check_Arg --
18691 ---------------
18693 procedure Check_Arg (Arg : Node_Id) is
18694 begin
18695 if not Nkind_In (Original_Node (Arg),
18696 N_String_Literal,
18697 N_Identifier)
18698 then
18699 Error_Pragma_Arg
18700 ("inappropriate argument for pragma %", Arg);
18701 end if;
18702 end Check_Arg;
18704 -- Start of processing for Common_Object/Psect_Object
18706 begin
18707 GNAT_Pragma;
18708 Gather_Associations (Names, Args);
18709 Process_Extended_Import_Export_Internal_Arg (Internal);
18711 Def_Id := Entity (Internal);
18713 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
18714 Error_Pragma_Arg
18715 ("pragma% must designate an object", Internal);
18716 end if;
18718 Check_Arg (Internal);
18720 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
18721 Error_Pragma_Arg
18722 ("cannot use pragma% for imported/exported object",
18723 Internal);
18724 end if;
18726 if Is_Concurrent_Type (Etype (Internal)) then
18727 Error_Pragma_Arg
18728 ("cannot specify pragma % for task/protected object",
18729 Internal);
18730 end if;
18732 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
18733 or else
18734 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
18735 then
18736 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
18737 end if;
18739 if Ekind (Def_Id) = E_Constant then
18740 Error_Pragma_Arg
18741 ("cannot specify pragma % for a constant", Internal);
18742 end if;
18744 if Is_Record_Type (Etype (Internal)) then
18745 declare
18746 Ent : Entity_Id;
18747 Decl : Entity_Id;
18749 begin
18750 Ent := First_Entity (Etype (Internal));
18751 while Present (Ent) loop
18752 Decl := Declaration_Node (Ent);
18754 if Ekind (Ent) = E_Component
18755 and then Nkind (Decl) = N_Component_Declaration
18756 and then Present (Expression (Decl))
18757 and then Warn_On_Export_Import
18758 then
18759 Error_Msg_N
18760 ("?x?object for pragma % has defaults", Internal);
18761 exit;
18763 else
18764 Next_Entity (Ent);
18765 end if;
18766 end loop;
18767 end;
18768 end if;
18770 if Present (Size) then
18771 Check_Arg (Size);
18772 end if;
18774 if Present (External) then
18775 Check_Arg_Is_External_Name (External);
18776 end if;
18778 -- If all error tests pass, link pragma on to the rep item chain
18780 Record_Rep_Item (Def_Id, N);
18781 end Psect_Object;
18783 ----------
18784 -- Pure --
18785 ----------
18787 -- pragma Pure [(library_unit_NAME)];
18789 when Pragma_Pure => Pure : declare
18790 Ent : Entity_Id;
18792 begin
18793 Check_Ada_83_Warning;
18794 Check_Valid_Library_Unit_Pragma;
18796 if Nkind (N) = N_Null_Statement then
18797 return;
18798 end if;
18800 Ent := Find_Lib_Unit_Name;
18801 Set_Is_Pure (Ent);
18802 Set_Has_Pragma_Pure (Ent);
18803 Set_Suppress_Elaboration_Warnings (Ent);
18804 end Pure;
18806 -------------------
18807 -- Pure_Function --
18808 -------------------
18810 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
18812 when Pragma_Pure_Function => Pure_Function : declare
18813 E_Id : Node_Id;
18814 E : Entity_Id;
18815 Def_Id : Entity_Id;
18816 Effective : Boolean := False;
18818 begin
18819 GNAT_Pragma;
18820 Check_Arg_Count (1);
18821 Check_Optional_Identifier (Arg1, Name_Entity);
18822 Check_Arg_Is_Local_Name (Arg1);
18823 E_Id := Get_Pragma_Arg (Arg1);
18825 if Error_Posted (E_Id) then
18826 return;
18827 end if;
18829 -- Loop through homonyms (overloadings) of referenced entity
18831 E := Entity (E_Id);
18833 if Present (E) then
18834 loop
18835 Def_Id := Get_Base_Subprogram (E);
18837 if not Ekind_In (Def_Id, E_Function,
18838 E_Generic_Function,
18839 E_Operator)
18840 then
18841 Error_Pragma_Arg
18842 ("pragma% requires a function name", Arg1);
18843 end if;
18845 Set_Is_Pure (Def_Id);
18847 if not Has_Pragma_Pure_Function (Def_Id) then
18848 Set_Has_Pragma_Pure_Function (Def_Id);
18849 Effective := True;
18850 end if;
18852 exit when From_Aspect_Specification (N);
18853 E := Homonym (E);
18854 exit when No (E) or else Scope (E) /= Current_Scope;
18855 end loop;
18857 if not Effective
18858 and then Warn_On_Redundant_Constructs
18859 then
18860 Error_Msg_NE
18861 ("pragma Pure_Function on& is redundant?r?",
18862 N, Entity (E_Id));
18863 end if;
18864 end if;
18865 end Pure_Function;
18867 --------------------
18868 -- Queuing_Policy --
18869 --------------------
18871 -- pragma Queuing_Policy (policy_IDENTIFIER);
18873 when Pragma_Queuing_Policy => declare
18874 QP : Character;
18876 begin
18877 Check_Ada_83_Warning;
18878 Check_Arg_Count (1);
18879 Check_No_Identifiers;
18880 Check_Arg_Is_Queuing_Policy (Arg1);
18881 Check_Valid_Configuration_Pragma;
18882 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
18883 QP := Fold_Upper (Name_Buffer (1));
18885 if Queuing_Policy /= ' '
18886 and then Queuing_Policy /= QP
18887 then
18888 Error_Msg_Sloc := Queuing_Policy_Sloc;
18889 Error_Pragma ("queuing policy incompatible with policy#");
18891 -- Set new policy, but always preserve System_Location since we
18892 -- like the error message with the run time name.
18894 else
18895 Queuing_Policy := QP;
18897 if Queuing_Policy_Sloc /= System_Location then
18898 Queuing_Policy_Sloc := Loc;
18899 end if;
18900 end if;
18901 end;
18903 --------------
18904 -- Rational --
18905 --------------
18907 -- pragma Rational, for compatibility with foreign compiler
18909 when Pragma_Rational =>
18910 Set_Rational_Profile;
18912 ------------------------------------
18913 -- Refined_Depends/Refined_Global --
18914 ------------------------------------
18916 -- pragma Refined_Depends (DEPENDENCY_RELATION);
18918 -- DEPENDENCY_RELATION ::=
18919 -- null
18920 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
18922 -- DEPENDENCY_CLAUSE ::=
18923 -- OUTPUT_LIST =>[+] INPUT_LIST
18924 -- | NULL_DEPENDENCY_CLAUSE
18926 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
18928 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
18930 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
18932 -- OUTPUT ::= NAME | FUNCTION_RESULT
18933 -- INPUT ::= NAME
18935 -- where FUNCTION_RESULT is a function Result attribute_reference
18937 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
18939 -- GLOBAL_SPECIFICATION ::=
18940 -- null
18941 -- | GLOBAL_LIST
18942 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
18944 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
18946 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
18947 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
18948 -- GLOBAL_ITEM ::= NAME
18950 when Pragma_Refined_Depends |
18951 Pragma_Refined_Global => Refined_Depends_Global :
18952 declare
18953 Body_Id : Entity_Id;
18954 Legal : Boolean;
18955 Spec_Id : Entity_Id;
18957 begin
18958 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
18960 -- Save the pragma in the contract of the subprogram body. The
18961 -- remaining analysis is performed at the end of the enclosing
18962 -- declarations.
18964 if Legal then
18965 Add_Contract_Item (N, Body_Id);
18966 end if;
18967 end Refined_Depends_Global;
18969 ------------------
18970 -- Refined_Post --
18971 ------------------
18973 -- pragma Refined_Post (boolean_EXPRESSION);
18975 when Pragma_Refined_Post => Refined_Post : declare
18976 Body_Id : Entity_Id;
18977 Legal : Boolean;
18978 Result_Seen : Boolean := False;
18979 Spec_Id : Entity_Id;
18981 begin
18982 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
18984 -- Analyze the boolean expression as a "spec expression"
18986 if Legal then
18987 Analyze_Pre_Post_Condition_In_Decl_Part (N, Spec_Id);
18989 -- Verify that the refined postcondition mentions attribute
18990 -- 'Result and its expression introduces a post-state.
18992 if Warn_On_Suspicious_Contract
18993 and then Ekind_In (Spec_Id, E_Function, E_Generic_Function)
18994 then
18995 Check_Result_And_Post_State (N, Result_Seen);
18997 if not Result_Seen then
18998 Error_Pragma
18999 ("pragma % does not mention function result?T?");
19000 end if;
19001 end if;
19003 -- Chain the pragma on the contract for easy retrieval
19005 Add_Contract_Item (N, Body_Id);
19006 end if;
19007 end Refined_Post;
19009 -------------------
19010 -- Refined_State --
19011 -------------------
19013 -- pragma Refined_State (REFINEMENT_LIST);
19015 -- REFINEMENT_LIST ::=
19016 -- REFINEMENT_CLAUSE
19017 -- | (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
19019 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
19021 -- CONSTITUENT_LIST ::=
19022 -- null
19023 -- | CONSTITUENT
19024 -- | (CONSTITUENT {, CONSTITUENT})
19026 -- CONSTITUENT ::= object_NAME | state_NAME
19028 when Pragma_Refined_State => Refined_State : declare
19029 Context : constant Node_Id := Parent (N);
19030 Spec_Id : Entity_Id;
19031 Stmt : Node_Id;
19033 begin
19034 GNAT_Pragma;
19035 Check_No_Identifiers;
19036 Check_Arg_Count (1);
19038 -- Ensure the proper placement of the pragma. Refined states must
19039 -- be associated with a package body.
19041 if Nkind (Context) /= N_Package_Body then
19042 Pragma_Misplaced;
19043 return;
19044 end if;
19046 Stmt := Prev (N);
19047 while Present (Stmt) loop
19049 -- Skip prior pragmas, but check for duplicates
19051 if Nkind (Stmt) = N_Pragma then
19052 if Pragma_Name (Stmt) = Pname then
19053 Error_Msg_Name_1 := Pname;
19054 Error_Msg_Sloc := Sloc (Stmt);
19055 Error_Msg_N ("pragma % duplicates pragma declared #", N);
19056 end if;
19058 -- Skip internally generated code
19060 elsif not Comes_From_Source (Stmt) then
19061 null;
19063 -- The pragma does not apply to a legal construct, issue an
19064 -- error and stop the analysis.
19066 else
19067 Pragma_Misplaced;
19068 return;
19069 end if;
19071 Stmt := Prev (Stmt);
19072 end loop;
19074 Spec_Id := Corresponding_Spec (Context);
19076 -- State refinement is allowed only when the corresponding package
19077 -- declaration has non-null pragma Abstract_State. Refinement not
19078 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
19080 if SPARK_Mode /= Off
19081 and then
19082 (No (Abstract_States (Spec_Id))
19083 or else Has_Null_Abstract_State (Spec_Id))
19084 then
19085 Error_Msg_NE
19086 ("useless refinement, package & does not define abstract "
19087 & "states", N, Spec_Id);
19088 return;
19089 end if;
19091 -- The pragma must be analyzed at the end of the declarations as
19092 -- it has visibility over the whole declarative region. Save the
19093 -- pragma for later (see Analyze_Refined_Depends_In_Decl_Part) by
19094 -- adding it to the contract of the package body.
19096 Add_Contract_Item (N, Defining_Entity (Context));
19097 end Refined_State;
19099 -----------------------
19100 -- Relative_Deadline --
19101 -----------------------
19103 -- pragma Relative_Deadline (time_span_EXPRESSION);
19105 when Pragma_Relative_Deadline => Relative_Deadline : declare
19106 P : constant Node_Id := Parent (N);
19107 Arg : Node_Id;
19109 begin
19110 Ada_2005_Pragma;
19111 Check_No_Identifiers;
19112 Check_Arg_Count (1);
19114 Arg := Get_Pragma_Arg (Arg1);
19116 -- The expression must be analyzed in the special manner described
19117 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
19119 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
19121 -- Subprogram case
19123 if Nkind (P) = N_Subprogram_Body then
19124 Check_In_Main_Program;
19126 -- Only Task and subprogram cases allowed
19128 elsif Nkind (P) /= N_Task_Definition then
19129 Pragma_Misplaced;
19130 end if;
19132 -- Check duplicate pragma before we set the corresponding flag
19134 if Has_Relative_Deadline_Pragma (P) then
19135 Error_Pragma ("duplicate pragma% not allowed");
19136 end if;
19138 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
19139 -- Relative_Deadline pragma node cannot be inserted in the Rep
19140 -- Item chain of Ent since it is rewritten by the expander as a
19141 -- procedure call statement that will break the chain.
19143 Set_Has_Relative_Deadline_Pragma (P, True);
19144 end Relative_Deadline;
19146 ------------------------
19147 -- Remote_Access_Type --
19148 ------------------------
19150 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
19152 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
19153 E : Entity_Id;
19155 begin
19156 GNAT_Pragma;
19157 Check_Arg_Count (1);
19158 Check_Optional_Identifier (Arg1, Name_Entity);
19159 Check_Arg_Is_Local_Name (Arg1);
19161 E := Entity (Get_Pragma_Arg (Arg1));
19163 if Nkind (Parent (E)) = N_Formal_Type_Declaration
19164 and then Ekind (E) = E_General_Access_Type
19165 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
19166 and then Scope (Root_Type (Directly_Designated_Type (E)))
19167 = Scope (E)
19168 and then Is_Valid_Remote_Object_Type
19169 (Root_Type (Directly_Designated_Type (E)))
19170 then
19171 Set_Is_Remote_Types (E);
19173 else
19174 Error_Pragma_Arg
19175 ("pragma% applies only to formal access to classwide types",
19176 Arg1);
19177 end if;
19178 end Remote_Access_Type;
19180 ---------------------------
19181 -- Remote_Call_Interface --
19182 ---------------------------
19184 -- pragma Remote_Call_Interface [(library_unit_NAME)];
19186 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
19187 Cunit_Node : Node_Id;
19188 Cunit_Ent : Entity_Id;
19189 K : Node_Kind;
19191 begin
19192 Check_Ada_83_Warning;
19193 Check_Valid_Library_Unit_Pragma;
19195 if Nkind (N) = N_Null_Statement then
19196 return;
19197 end if;
19199 Cunit_Node := Cunit (Current_Sem_Unit);
19200 K := Nkind (Unit (Cunit_Node));
19201 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19203 if K = N_Package_Declaration
19204 or else K = N_Generic_Package_Declaration
19205 or else K = N_Subprogram_Declaration
19206 or else K = N_Generic_Subprogram_Declaration
19207 or else (K = N_Subprogram_Body
19208 and then Acts_As_Spec (Unit (Cunit_Node)))
19209 then
19210 null;
19211 else
19212 Error_Pragma (
19213 "pragma% must apply to package or subprogram declaration");
19214 end if;
19216 Set_Is_Remote_Call_Interface (Cunit_Ent);
19217 end Remote_Call_Interface;
19219 ------------------
19220 -- Remote_Types --
19221 ------------------
19223 -- pragma Remote_Types [(library_unit_NAME)];
19225 when Pragma_Remote_Types => Remote_Types : declare
19226 Cunit_Node : Node_Id;
19227 Cunit_Ent : Entity_Id;
19229 begin
19230 Check_Ada_83_Warning;
19231 Check_Valid_Library_Unit_Pragma;
19233 if Nkind (N) = N_Null_Statement then
19234 return;
19235 end if;
19237 Cunit_Node := Cunit (Current_Sem_Unit);
19238 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19240 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
19241 N_Generic_Package_Declaration)
19242 then
19243 Error_Pragma
19244 ("pragma% can only apply to a package declaration");
19245 end if;
19247 Set_Is_Remote_Types (Cunit_Ent);
19248 end Remote_Types;
19250 ---------------
19251 -- Ravenscar --
19252 ---------------
19254 -- pragma Ravenscar;
19256 when Pragma_Ravenscar =>
19257 GNAT_Pragma;
19258 Check_Arg_Count (0);
19259 Check_Valid_Configuration_Pragma;
19260 Set_Ravenscar_Profile (N);
19262 if Warn_On_Obsolescent_Feature then
19263 Error_Msg_N
19264 ("pragma Ravenscar is an obsolescent feature?j?", N);
19265 Error_Msg_N
19266 ("|use pragma Profile (Ravenscar) instead?j?", N);
19267 end if;
19269 -------------------------
19270 -- Restricted_Run_Time --
19271 -------------------------
19273 -- pragma Restricted_Run_Time;
19275 when Pragma_Restricted_Run_Time =>
19276 GNAT_Pragma;
19277 Check_Arg_Count (0);
19278 Check_Valid_Configuration_Pragma;
19279 Set_Profile_Restrictions
19280 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
19282 if Warn_On_Obsolescent_Feature then
19283 Error_Msg_N
19284 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
19286 Error_Msg_N
19287 ("|use pragma Profile (Restricted) instead?j?", N);
19288 end if;
19290 ------------------
19291 -- Restrictions --
19292 ------------------
19294 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
19296 -- RESTRICTION ::=
19297 -- restriction_IDENTIFIER
19298 -- | restriction_parameter_IDENTIFIER => EXPRESSION
19300 when Pragma_Restrictions =>
19301 Process_Restrictions_Or_Restriction_Warnings
19302 (Warn => Treat_Restrictions_As_Warnings);
19304 --------------------------
19305 -- Restriction_Warnings --
19306 --------------------------
19308 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
19310 -- RESTRICTION ::=
19311 -- restriction_IDENTIFIER
19312 -- | restriction_parameter_IDENTIFIER => EXPRESSION
19314 when Pragma_Restriction_Warnings =>
19315 GNAT_Pragma;
19316 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
19318 ----------------
19319 -- Reviewable --
19320 ----------------
19322 -- pragma Reviewable;
19324 when Pragma_Reviewable =>
19325 Check_Ada_83_Warning;
19326 Check_Arg_Count (0);
19328 -- Call dummy debugging function rv. This is done to assist front
19329 -- end debugging. By placing a Reviewable pragma in the source
19330 -- program, a breakpoint on rv catches this place in the source,
19331 -- allowing convenient stepping to the point of interest.
19335 --------------------------
19336 -- Short_Circuit_And_Or --
19337 --------------------------
19339 -- pragma Short_Circuit_And_Or;
19341 when Pragma_Short_Circuit_And_Or =>
19342 GNAT_Pragma;
19343 Check_Arg_Count (0);
19344 Check_Valid_Configuration_Pragma;
19345 Short_Circuit_And_Or := True;
19347 -------------------
19348 -- Share_Generic --
19349 -------------------
19351 -- pragma Share_Generic (GNAME {, GNAME});
19353 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
19355 when Pragma_Share_Generic =>
19356 GNAT_Pragma;
19357 Process_Generic_List;
19359 ------------
19360 -- Shared --
19361 ------------
19363 -- pragma Shared (LOCAL_NAME);
19365 when Pragma_Shared =>
19366 GNAT_Pragma;
19367 Process_Atomic_Independent_Shared_Volatile;
19369 --------------------
19370 -- Shared_Passive --
19371 --------------------
19373 -- pragma Shared_Passive [(library_unit_NAME)];
19375 -- Set the flag Is_Shared_Passive of program unit name entity
19377 when Pragma_Shared_Passive => Shared_Passive : declare
19378 Cunit_Node : Node_Id;
19379 Cunit_Ent : Entity_Id;
19381 begin
19382 Check_Ada_83_Warning;
19383 Check_Valid_Library_Unit_Pragma;
19385 if Nkind (N) = N_Null_Statement then
19386 return;
19387 end if;
19389 Cunit_Node := Cunit (Current_Sem_Unit);
19390 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19392 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
19393 N_Generic_Package_Declaration)
19394 then
19395 Error_Pragma
19396 ("pragma% can only apply to a package declaration");
19397 end if;
19399 Set_Is_Shared_Passive (Cunit_Ent);
19400 end Shared_Passive;
19402 -----------------------
19403 -- Short_Descriptors --
19404 -----------------------
19406 -- pragma Short_Descriptors;
19408 -- Recognize and validate, but otherwise ignore
19410 when Pragma_Short_Descriptors =>
19411 GNAT_Pragma;
19412 Check_Arg_Count (0);
19413 Check_Valid_Configuration_Pragma;
19415 ------------------------------
19416 -- Simple_Storage_Pool_Type --
19417 ------------------------------
19419 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
19421 when Pragma_Simple_Storage_Pool_Type =>
19422 Simple_Storage_Pool_Type : declare
19423 Type_Id : Node_Id;
19424 Typ : Entity_Id;
19426 begin
19427 GNAT_Pragma;
19428 Check_Arg_Count (1);
19429 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19431 Type_Id := Get_Pragma_Arg (Arg1);
19432 Find_Type (Type_Id);
19433 Typ := Entity (Type_Id);
19435 if Typ = Any_Type then
19436 return;
19437 end if;
19439 -- We require the pragma to apply to a type declared in a package
19440 -- declaration, but not (immediately) within a package body.
19442 if Ekind (Current_Scope) /= E_Package
19443 or else In_Package_Body (Current_Scope)
19444 then
19445 Error_Pragma
19446 ("pragma% can only apply to type declared immediately "
19447 & "within a package declaration");
19448 end if;
19450 -- A simple storage pool type must be an immutably limited record
19451 -- or private type. If the pragma is given for a private type,
19452 -- the full type is similarly restricted (which is checked later
19453 -- in Freeze_Entity).
19455 if Is_Record_Type (Typ)
19456 and then not Is_Limited_View (Typ)
19457 then
19458 Error_Pragma
19459 ("pragma% can only apply to explicitly limited record type");
19461 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
19462 Error_Pragma
19463 ("pragma% can only apply to a private type that is limited");
19465 elsif not Is_Record_Type (Typ)
19466 and then not Is_Private_Type (Typ)
19467 then
19468 Error_Pragma
19469 ("pragma% can only apply to limited record or private type");
19470 end if;
19472 Record_Rep_Item (Typ, N);
19473 end Simple_Storage_Pool_Type;
19475 ----------------------
19476 -- Source_File_Name --
19477 ----------------------
19479 -- There are five forms for this pragma:
19481 -- pragma Source_File_Name (
19482 -- [UNIT_NAME =>] unit_NAME,
19483 -- BODY_FILE_NAME => STRING_LITERAL
19484 -- [, [INDEX =>] INTEGER_LITERAL]);
19486 -- pragma Source_File_Name (
19487 -- [UNIT_NAME =>] unit_NAME,
19488 -- SPEC_FILE_NAME => STRING_LITERAL
19489 -- [, [INDEX =>] INTEGER_LITERAL]);
19491 -- pragma Source_File_Name (
19492 -- BODY_FILE_NAME => STRING_LITERAL
19493 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19494 -- [, CASING => CASING_SPEC]);
19496 -- pragma Source_File_Name (
19497 -- SPEC_FILE_NAME => STRING_LITERAL
19498 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19499 -- [, CASING => CASING_SPEC]);
19501 -- pragma Source_File_Name (
19502 -- SUBUNIT_FILE_NAME => STRING_LITERAL
19503 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19504 -- [, CASING => CASING_SPEC]);
19506 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
19508 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
19509 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
19510 -- only be used when no project file is used, while SFNP can only be
19511 -- used when a project file is used.
19513 -- No processing here. Processing was completed during parsing, since
19514 -- we need to have file names set as early as possible. Units are
19515 -- loaded well before semantic processing starts.
19517 -- The only processing we defer to this point is the check for
19518 -- correct placement.
19520 when Pragma_Source_File_Name =>
19521 GNAT_Pragma;
19522 Check_Valid_Configuration_Pragma;
19524 ------------------------------
19525 -- Source_File_Name_Project --
19526 ------------------------------
19528 -- See Source_File_Name for syntax
19530 -- No processing here. Processing was completed during parsing, since
19531 -- we need to have file names set as early as possible. Units are
19532 -- loaded well before semantic processing starts.
19534 -- The only processing we defer to this point is the check for
19535 -- correct placement.
19537 when Pragma_Source_File_Name_Project =>
19538 GNAT_Pragma;
19539 Check_Valid_Configuration_Pragma;
19541 -- Check that a pragma Source_File_Name_Project is used only in a
19542 -- configuration pragmas file.
19544 -- Pragmas Source_File_Name_Project should only be generated by
19545 -- the Project Manager in configuration pragmas files.
19547 -- This is really an ugly test. It seems to depend on some
19548 -- accidental and undocumented property. At the very least it
19549 -- needs to be documented, but it would be better to have a
19550 -- clean way of testing if we are in a configuration file???
19552 if Present (Parent (N)) then
19553 Error_Pragma
19554 ("pragma% can only appear in a configuration pragmas file");
19555 end if;
19557 ----------------------
19558 -- Source_Reference --
19559 ----------------------
19561 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
19563 -- Nothing to do, all processing completed in Par.Prag, since we need
19564 -- the information for possible parser messages that are output.
19566 when Pragma_Source_Reference =>
19567 GNAT_Pragma;
19569 ----------------
19570 -- SPARK_Mode --
19571 ----------------
19573 -- pragma SPARK_Mode [(On | Off)];
19575 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
19576 Mode_Id : SPARK_Mode_Type;
19578 procedure Check_Pragma_Conformance
19579 (Context_Pragma : Node_Id;
19580 Entity_Pragma : Node_Id;
19581 Entity : Entity_Id);
19582 -- If Context_Pragma is not Empty, verify that the new pragma N
19583 -- is compatible with the pragma Context_Pragma that was inherited
19584 -- from the context:
19585 -- . if Context_Pragma is ON, then the new mode can be anything
19586 -- . if Context_Pragma is OFF, then the only allowed new mode is
19587 -- also OFF.
19589 -- If Entity is not Empty, verify that the new pragma N is
19590 -- compatible with Entity_Pragma, the SPARK_Mode previously set
19591 -- for Entity (which may be Empty):
19592 -- . if Entity_Pragma is ON, then the new mode can be anything
19593 -- . if Entity_Pragma is OFF, then the only allowed new mode is
19594 -- also OFF.
19595 -- . if Entity_Pragma is Empty, we always issue an error, as this
19596 -- corresponds to a case where a previous section of Entity
19597 -- had no SPARK_Mode set.
19599 procedure Check_Library_Level_Entity (E : Entity_Id);
19600 -- Verify that pragma is applied to library-level entity E
19602 procedure Set_SPARK_Flags;
19603 -- Sets SPARK_Mode from Mode_Id and SPARK_Mode_Pragma from N,
19604 -- and ensures that Dynamic_Elaboration_Checks are off if the
19605 -- call sets SPARK_Mode On.
19607 ------------------------------
19608 -- Check_Pragma_Conformance --
19609 ------------------------------
19611 procedure Check_Pragma_Conformance
19612 (Context_Pragma : Node_Id;
19613 Entity_Pragma : Node_Id;
19614 Entity : Entity_Id)
19616 begin
19617 if Present (Context_Pragma) then
19618 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
19620 -- New mode less restrictive than the established mode
19622 if Get_SPARK_Mode_From_Pragma (Context_Pragma) = Off
19623 and then Get_SPARK_Mode_From_Pragma (N) = On
19624 then
19625 Error_Msg_N
19626 ("cannot change SPARK_Mode from Off to On", Arg1);
19627 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
19628 Error_Msg_N ("\SPARK_Mode was set to Off#", Arg1);
19629 raise Pragma_Exit;
19630 end if;
19631 end if;
19633 if Present (Entity) then
19634 if Present (Entity_Pragma) then
19635 if Get_SPARK_Mode_From_Pragma (Entity_Pragma) = Off
19636 and then Get_SPARK_Mode_From_Pragma (N) = On
19637 then
19638 Error_Msg_N ("incorrect use of SPARK_Mode", Arg1);
19639 Error_Msg_Sloc := Sloc (Entity_Pragma);
19640 Error_Msg_NE
19641 ("\value Off was set for SPARK_Mode on&#",
19642 Arg1, Entity);
19643 raise Pragma_Exit;
19644 end if;
19646 else
19647 Error_Msg_N ("incorrect use of SPARK_Mode", Arg1);
19648 Error_Msg_Sloc := Sloc (Entity);
19649 Error_Msg_NE
19650 ("\no value was set for SPARK_Mode on&#",
19651 Arg1, Entity);
19652 raise Pragma_Exit;
19653 end if;
19654 end if;
19655 end Check_Pragma_Conformance;
19657 --------------------------------
19658 -- Check_Library_Level_Entity --
19659 --------------------------------
19661 procedure Check_Library_Level_Entity (E : Entity_Id) is
19662 MsgF : constant String := "incorrect placement of pragma%";
19664 begin
19665 if not Is_Library_Level_Entity (E) then
19666 Error_Msg_Name_1 := Pname;
19667 Error_Msg_N (Fix_Error (MsgF), N);
19669 if Ekind_In (E, E_Generic_Package,
19670 E_Package,
19671 E_Package_Body)
19672 then
19673 Error_Msg_NE
19674 ("\& is not a library-level package", N, E);
19675 else
19676 Error_Msg_NE
19677 ("\& is not a library-level subprogram", N, E);
19678 end if;
19680 raise Pragma_Exit;
19681 end if;
19682 end Check_Library_Level_Entity;
19684 ---------------------
19685 -- Set_SPARK_Flags --
19686 ---------------------
19688 procedure Set_SPARK_Flags is
19689 begin
19690 SPARK_Mode := Mode_Id;
19691 SPARK_Mode_Pragma := N;
19693 if SPARK_Mode = On then
19694 Dynamic_Elaboration_Checks := False;
19695 end if;
19696 end Set_SPARK_Flags;
19698 -- Local variables
19700 Body_Id : Entity_Id;
19701 Context : Node_Id;
19702 Mode : Name_Id;
19703 Spec_Id : Entity_Id;
19704 Stmt : Node_Id;
19706 -- Start of processing for Do_SPARK_Mode
19708 begin
19709 -- When a SPARK_Mode pragma appears inside an instantiation whose
19710 -- enclosing context has SPARK_Mode set to "off", the pragma has
19711 -- no semantic effect.
19713 if Ignore_Pragma_SPARK_Mode then
19714 Rewrite (N, Make_Null_Statement (Loc));
19715 Analyze (N);
19716 return;
19717 end if;
19719 GNAT_Pragma;
19720 Check_No_Identifiers;
19721 Check_At_Most_N_Arguments (1);
19723 -- Check the legality of the mode (no argument = ON)
19725 if Arg_Count = 1 then
19726 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
19727 Mode := Chars (Get_Pragma_Arg (Arg1));
19728 else
19729 Mode := Name_On;
19730 end if;
19732 Mode_Id := Get_SPARK_Mode_Type (Mode);
19733 Context := Parent (N);
19735 -- The pragma appears in a configuration pragmas file
19737 if No (Context) then
19738 Check_Valid_Configuration_Pragma;
19740 if Present (SPARK_Mode_Pragma) then
19741 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
19742 Error_Msg_N ("pragma% duplicates pragma declared#", N);
19743 raise Pragma_Exit;
19744 end if;
19746 Set_SPARK_Flags;
19748 -- The pragma acts as a configuration pragma in a compilation unit
19750 -- pragma SPARK_Mode ...;
19751 -- package Pack is ...;
19753 elsif Nkind (Context) = N_Compilation_Unit
19754 and then List_Containing (N) = Context_Items (Context)
19755 then
19756 Check_Valid_Configuration_Pragma;
19757 Set_SPARK_Flags;
19759 -- Otherwise the placement of the pragma within the tree dictates
19760 -- its associated construct. Inspect the declarative list where
19761 -- the pragma resides to find a potential construct.
19763 else
19764 Stmt := Prev (N);
19765 while Present (Stmt) loop
19767 -- Skip prior pragmas, but check for duplicates
19769 if Nkind (Stmt) = N_Pragma then
19770 if Pragma_Name (Stmt) = Pname then
19771 Error_Msg_Name_1 := Pname;
19772 Error_Msg_Sloc := Sloc (Stmt);
19773 Error_Msg_N ("pragma% duplicates pragma declared#", N);
19774 raise Pragma_Exit;
19775 end if;
19777 -- The pragma applies to a [generic] subprogram declaration.
19778 -- Note that this case covers an internally generated spec
19779 -- for a stand alone body.
19781 -- [generic]
19782 -- procedure Proc ...;
19783 -- pragma SPARK_Mode ..;
19785 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
19786 N_Subprogram_Declaration)
19787 then
19788 Spec_Id := Defining_Entity (Stmt);
19789 Check_Library_Level_Entity (Spec_Id);
19790 Check_Pragma_Conformance
19791 (Context_Pragma => SPARK_Pragma (Spec_Id),
19792 Entity_Pragma => Empty,
19793 Entity => Empty);
19795 Set_SPARK_Pragma (Spec_Id, N);
19796 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19797 return;
19799 -- Skip internally generated code
19801 elsif not Comes_From_Source (Stmt) then
19802 null;
19804 -- Otherwise the pragma does not apply to a legal construct
19805 -- or it does not appear at the top of a declarative or a
19806 -- statement list. Issue an error and stop the analysis.
19808 else
19809 Pragma_Misplaced;
19810 exit;
19811 end if;
19813 Prev (Stmt);
19814 end loop;
19816 -- The pragma applies to a package or a subprogram that acts as
19817 -- a compilation unit.
19819 -- procedure Proc ...;
19820 -- pragma SPARK_Mode ...;
19822 if Nkind (Context) = N_Compilation_Unit_Aux then
19823 Context := Unit (Parent (Context));
19824 end if;
19826 -- The pragma appears within package declarations
19828 if Nkind (Context) = N_Package_Specification then
19829 Spec_Id := Defining_Entity (Context);
19830 Check_Library_Level_Entity (Spec_Id);
19832 -- The pragma is at the top of the visible declarations
19834 -- package Pack is
19835 -- pragma SPARK_Mode ...;
19837 if List_Containing (N) = Visible_Declarations (Context) then
19838 Check_Pragma_Conformance
19839 (Context_Pragma => SPARK_Pragma (Spec_Id),
19840 Entity_Pragma => Empty,
19841 Entity => Empty);
19842 Set_SPARK_Flags;
19844 Set_SPARK_Pragma (Spec_Id, N);
19845 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19846 Set_SPARK_Aux_Pragma (Spec_Id, N);
19847 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
19849 -- The pragma is at the top of the private declarations
19851 -- package Pack is
19852 -- private
19853 -- pragma SPARK_Mode ...;
19855 else
19856 Check_Pragma_Conformance
19857 (Context_Pragma => Empty,
19858 Entity_Pragma => SPARK_Pragma (Spec_Id),
19859 Entity => Spec_Id);
19860 Set_SPARK_Flags;
19862 Set_SPARK_Aux_Pragma (Spec_Id, N);
19863 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
19864 end if;
19866 -- The pragma appears at the top of package body declarations
19868 -- package body Pack is
19869 -- pragma SPARK_Mode ...;
19871 elsif Nkind (Context) = N_Package_Body then
19872 Spec_Id := Corresponding_Spec (Context);
19873 Body_Id := Defining_Entity (Context);
19874 Check_Library_Level_Entity (Body_Id);
19875 Check_Pragma_Conformance
19876 (Context_Pragma => SPARK_Pragma (Body_Id),
19877 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id),
19878 Entity => Spec_Id);
19879 Set_SPARK_Flags;
19881 Set_SPARK_Pragma (Body_Id, N);
19882 Set_SPARK_Pragma_Inherited (Body_Id, False);
19883 Set_SPARK_Aux_Pragma (Body_Id, N);
19884 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
19886 -- The pragma appears at the top of package body statements
19888 -- package body Pack is
19889 -- begin
19890 -- pragma SPARK_Mode;
19892 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
19893 and then Nkind (Parent (Context)) = N_Package_Body
19894 then
19895 Context := Parent (Context);
19896 Spec_Id := Corresponding_Spec (Context);
19897 Body_Id := Defining_Entity (Context);
19898 Check_Library_Level_Entity (Body_Id);
19899 Check_Pragma_Conformance
19900 (Context_Pragma => Empty,
19901 Entity_Pragma => SPARK_Pragma (Body_Id),
19902 Entity => Body_Id);
19903 Set_SPARK_Flags;
19905 Set_SPARK_Aux_Pragma (Body_Id, N);
19906 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
19908 -- The pragma appeared as an aspect of a [generic] subprogram
19909 -- declaration that acts as a compilation unit.
19911 -- [generic]
19912 -- procedure Proc ...;
19913 -- pragma SPARK_Mode ...;
19915 elsif Nkind_In (Context, N_Generic_Subprogram_Declaration,
19916 N_Subprogram_Declaration)
19917 then
19918 Spec_Id := Defining_Entity (Context);
19919 Check_Library_Level_Entity (Spec_Id);
19920 Check_Pragma_Conformance
19921 (Context_Pragma => SPARK_Pragma (Spec_Id),
19922 Entity_Pragma => Empty,
19923 Entity => Empty);
19925 Set_SPARK_Pragma (Spec_Id, N);
19926 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19928 -- The pragma appears at the top of subprogram body
19929 -- declarations.
19931 -- procedure Proc ... is
19932 -- pragma SPARK_Mode;
19934 elsif Nkind (Context) = N_Subprogram_Body then
19935 Spec_Id := Corresponding_Spec (Context);
19936 Context := Specification (Context);
19937 Body_Id := Defining_Entity (Context);
19939 -- Ignore pragma when applied to the special body created
19940 -- for inlining, recognized by its internal name _Parent.
19942 if Chars (Body_Id) = Name_uParent then
19943 return;
19944 end if;
19946 Check_Library_Level_Entity (Body_Id);
19948 -- The body is a completion of a previous declaration
19950 if Present (Spec_Id) then
19951 Check_Pragma_Conformance
19952 (Context_Pragma => SPARK_Pragma (Body_Id),
19953 Entity_Pragma => SPARK_Pragma (Spec_Id),
19954 Entity => Spec_Id);
19956 -- The body acts as spec
19958 else
19959 Check_Pragma_Conformance
19960 (Context_Pragma => SPARK_Pragma (Body_Id),
19961 Entity_Pragma => Empty,
19962 Entity => Empty);
19963 end if;
19965 Set_SPARK_Flags;
19967 Set_SPARK_Pragma (Body_Id, N);
19968 Set_SPARK_Pragma_Inherited (Body_Id, False);
19970 -- The pragma does not apply to a legal construct, issue error
19972 else
19973 Pragma_Misplaced;
19974 end if;
19975 end if;
19976 end Do_SPARK_Mode;
19978 --------------------------------
19979 -- Static_Elaboration_Desired --
19980 --------------------------------
19982 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
19984 when Pragma_Static_Elaboration_Desired =>
19985 GNAT_Pragma;
19986 Check_At_Most_N_Arguments (1);
19988 if Is_Compilation_Unit (Current_Scope)
19989 and then Ekind (Current_Scope) = E_Package
19990 then
19991 Set_Static_Elaboration_Desired (Current_Scope, True);
19992 else
19993 Error_Pragma ("pragma% must apply to a library-level package");
19994 end if;
19996 ------------------
19997 -- Storage_Size --
19998 ------------------
20000 -- pragma Storage_Size (EXPRESSION);
20002 when Pragma_Storage_Size => Storage_Size : declare
20003 P : constant Node_Id := Parent (N);
20004 Arg : Node_Id;
20006 begin
20007 Check_No_Identifiers;
20008 Check_Arg_Count (1);
20010 -- The expression must be analyzed in the special manner described
20011 -- in "Handling of Default Expressions" in sem.ads.
20013 Arg := Get_Pragma_Arg (Arg1);
20014 Preanalyze_Spec_Expression (Arg, Any_Integer);
20016 if not Is_OK_Static_Expression (Arg) then
20017 Check_Restriction (Static_Storage_Size, Arg);
20018 end if;
20020 if Nkind (P) /= N_Task_Definition then
20021 Pragma_Misplaced;
20022 return;
20024 else
20025 if Has_Storage_Size_Pragma (P) then
20026 Error_Pragma ("duplicate pragma% not allowed");
20027 else
20028 Set_Has_Storage_Size_Pragma (P, True);
20029 end if;
20031 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
20032 end if;
20033 end Storage_Size;
20035 ------------------
20036 -- Storage_Unit --
20037 ------------------
20039 -- pragma Storage_Unit (NUMERIC_LITERAL);
20041 -- Only permitted argument is System'Storage_Unit value
20043 when Pragma_Storage_Unit =>
20044 Check_No_Identifiers;
20045 Check_Arg_Count (1);
20046 Check_Arg_Is_Integer_Literal (Arg1);
20048 if Intval (Get_Pragma_Arg (Arg1)) /=
20049 UI_From_Int (Ttypes.System_Storage_Unit)
20050 then
20051 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
20052 Error_Pragma_Arg
20053 ("the only allowed argument for pragma% is ^", Arg1);
20054 end if;
20056 --------------------
20057 -- Stream_Convert --
20058 --------------------
20060 -- pragma Stream_Convert (
20061 -- [Entity =>] type_LOCAL_NAME,
20062 -- [Read =>] function_NAME,
20063 -- [Write =>] function NAME);
20065 when Pragma_Stream_Convert => Stream_Convert : declare
20067 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
20068 -- Check that the given argument is the name of a local function
20069 -- of one argument that is not overloaded earlier in the current
20070 -- local scope. A check is also made that the argument is a
20071 -- function with one parameter.
20073 --------------------------------------
20074 -- Check_OK_Stream_Convert_Function --
20075 --------------------------------------
20077 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
20078 Ent : Entity_Id;
20080 begin
20081 Check_Arg_Is_Local_Name (Arg);
20082 Ent := Entity (Get_Pragma_Arg (Arg));
20084 if Has_Homonym (Ent) then
20085 Error_Pragma_Arg
20086 ("argument for pragma% may not be overloaded", Arg);
20087 end if;
20089 if Ekind (Ent) /= E_Function
20090 or else No (First_Formal (Ent))
20091 or else Present (Next_Formal (First_Formal (Ent)))
20092 then
20093 Error_Pragma_Arg
20094 ("argument for pragma% must be function of one argument",
20095 Arg);
20096 end if;
20097 end Check_OK_Stream_Convert_Function;
20099 -- Start of processing for Stream_Convert
20101 begin
20102 GNAT_Pragma;
20103 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
20104 Check_Arg_Count (3);
20105 Check_Optional_Identifier (Arg1, Name_Entity);
20106 Check_Optional_Identifier (Arg2, Name_Read);
20107 Check_Optional_Identifier (Arg3, Name_Write);
20108 Check_Arg_Is_Local_Name (Arg1);
20109 Check_OK_Stream_Convert_Function (Arg2);
20110 Check_OK_Stream_Convert_Function (Arg3);
20112 declare
20113 Typ : constant Entity_Id :=
20114 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
20115 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
20116 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
20118 begin
20119 Check_First_Subtype (Arg1);
20121 -- Check for too early or too late. Note that we don't enforce
20122 -- the rule about primitive operations in this case, since, as
20123 -- is the case for explicit stream attributes themselves, these
20124 -- restrictions are not appropriate. Note that the chaining of
20125 -- the pragma by Rep_Item_Too_Late is actually the critical
20126 -- processing done for this pragma.
20128 if Rep_Item_Too_Early (Typ, N)
20129 or else
20130 Rep_Item_Too_Late (Typ, N, FOnly => True)
20131 then
20132 return;
20133 end if;
20135 -- Return if previous error
20137 if Etype (Typ) = Any_Type
20138 or else
20139 Etype (Read) = Any_Type
20140 or else
20141 Etype (Write) = Any_Type
20142 then
20143 return;
20144 end if;
20146 -- Error checks
20148 if Underlying_Type (Etype (Read)) /= Typ then
20149 Error_Pragma_Arg
20150 ("incorrect return type for function&", Arg2);
20151 end if;
20153 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
20154 Error_Pragma_Arg
20155 ("incorrect parameter type for function&", Arg3);
20156 end if;
20158 if Underlying_Type (Etype (First_Formal (Read))) /=
20159 Underlying_Type (Etype (Write))
20160 then
20161 Error_Pragma_Arg
20162 ("result type of & does not match Read parameter type",
20163 Arg3);
20164 end if;
20165 end;
20166 end Stream_Convert;
20168 ------------------
20169 -- Style_Checks --
20170 ------------------
20172 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
20174 -- This is processed by the parser since some of the style checks
20175 -- take place during source scanning and parsing. This means that
20176 -- we don't need to issue error messages here.
20178 when Pragma_Style_Checks => Style_Checks : declare
20179 A : constant Node_Id := Get_Pragma_Arg (Arg1);
20180 S : String_Id;
20181 C : Char_Code;
20183 begin
20184 GNAT_Pragma;
20185 Check_No_Identifiers;
20187 -- Two argument form
20189 if Arg_Count = 2 then
20190 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
20192 declare
20193 E_Id : Node_Id;
20194 E : Entity_Id;
20196 begin
20197 E_Id := Get_Pragma_Arg (Arg2);
20198 Analyze (E_Id);
20200 if not Is_Entity_Name (E_Id) then
20201 Error_Pragma_Arg
20202 ("second argument of pragma% must be entity name",
20203 Arg2);
20204 end if;
20206 E := Entity (E_Id);
20208 if not Ignore_Style_Checks_Pragmas then
20209 if E = Any_Id then
20210 return;
20211 else
20212 loop
20213 Set_Suppress_Style_Checks
20214 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
20215 exit when No (Homonym (E));
20216 E := Homonym (E);
20217 end loop;
20218 end if;
20219 end if;
20220 end;
20222 -- One argument form
20224 else
20225 Check_Arg_Count (1);
20227 if Nkind (A) = N_String_Literal then
20228 S := Strval (A);
20230 declare
20231 Slen : constant Natural := Natural (String_Length (S));
20232 Options : String (1 .. Slen);
20233 J : Natural;
20235 begin
20236 J := 1;
20237 loop
20238 C := Get_String_Char (S, Int (J));
20239 exit when not In_Character_Range (C);
20240 Options (J) := Get_Character (C);
20242 -- If at end of string, set options. As per discussion
20243 -- above, no need to check for errors, since we issued
20244 -- them in the parser.
20246 if J = Slen then
20247 if not Ignore_Style_Checks_Pragmas then
20248 Set_Style_Check_Options (Options);
20249 end if;
20251 exit;
20252 end if;
20254 J := J + 1;
20255 end loop;
20256 end;
20258 elsif Nkind (A) = N_Identifier then
20259 if Chars (A) = Name_All_Checks then
20260 if not Ignore_Style_Checks_Pragmas then
20261 if GNAT_Mode then
20262 Set_GNAT_Style_Check_Options;
20263 else
20264 Set_Default_Style_Check_Options;
20265 end if;
20266 end if;
20268 elsif Chars (A) = Name_On then
20269 if not Ignore_Style_Checks_Pragmas then
20270 Style_Check := True;
20271 end if;
20273 elsif Chars (A) = Name_Off then
20274 if not Ignore_Style_Checks_Pragmas then
20275 Style_Check := False;
20276 end if;
20277 end if;
20278 end if;
20279 end if;
20280 end Style_Checks;
20282 --------------
20283 -- Subtitle --
20284 --------------
20286 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
20288 when Pragma_Subtitle =>
20289 GNAT_Pragma;
20290 Check_Arg_Count (1);
20291 Check_Optional_Identifier (Arg1, Name_Subtitle);
20292 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
20293 Store_Note (N);
20295 --------------
20296 -- Suppress --
20297 --------------
20299 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
20301 when Pragma_Suppress =>
20302 Process_Suppress_Unsuppress (Suppress_Case => True);
20304 ------------------
20305 -- Suppress_All --
20306 ------------------
20308 -- pragma Suppress_All;
20310 -- The only check made here is that the pragma has no arguments.
20311 -- There are no placement rules, and the processing required (setting
20312 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
20313 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
20314 -- then creates and inserts a pragma Suppress (All_Checks).
20316 when Pragma_Suppress_All =>
20317 GNAT_Pragma;
20318 Check_Arg_Count (0);
20320 -------------------------
20321 -- Suppress_Debug_Info --
20322 -------------------------
20324 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
20326 when Pragma_Suppress_Debug_Info =>
20327 GNAT_Pragma;
20328 Check_Arg_Count (1);
20329 Check_Optional_Identifier (Arg1, Name_Entity);
20330 Check_Arg_Is_Local_Name (Arg1);
20331 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
20333 ----------------------------------
20334 -- Suppress_Exception_Locations --
20335 ----------------------------------
20337 -- pragma Suppress_Exception_Locations;
20339 when Pragma_Suppress_Exception_Locations =>
20340 GNAT_Pragma;
20341 Check_Arg_Count (0);
20342 Check_Valid_Configuration_Pragma;
20343 Exception_Locations_Suppressed := True;
20345 -----------------------------
20346 -- Suppress_Initialization --
20347 -----------------------------
20349 -- pragma Suppress_Initialization ([Entity =>] type_Name);
20351 when Pragma_Suppress_Initialization => Suppress_Init : declare
20352 E_Id : Node_Id;
20353 E : Entity_Id;
20355 begin
20356 GNAT_Pragma;
20357 Check_Arg_Count (1);
20358 Check_Optional_Identifier (Arg1, Name_Entity);
20359 Check_Arg_Is_Local_Name (Arg1);
20361 E_Id := Get_Pragma_Arg (Arg1);
20363 if Etype (E_Id) = Any_Type then
20364 return;
20365 end if;
20367 E := Entity (E_Id);
20369 if not Is_Type (E) and then Ekind (E) /= E_Variable then
20370 Error_Pragma_Arg
20371 ("pragma% requires variable, type or subtype", Arg1);
20372 end if;
20374 if Rep_Item_Too_Early (E, N)
20375 or else
20376 Rep_Item_Too_Late (E, N, FOnly => True)
20377 then
20378 return;
20379 end if;
20381 -- For incomplete/private type, set flag on full view
20383 if Is_Incomplete_Or_Private_Type (E) then
20384 if No (Full_View (Base_Type (E))) then
20385 Error_Pragma_Arg
20386 ("argument of pragma% cannot be an incomplete type", Arg1);
20387 else
20388 Set_Suppress_Initialization (Full_View (Base_Type (E)));
20389 end if;
20391 -- For first subtype, set flag on base type
20393 elsif Is_First_Subtype (E) then
20394 Set_Suppress_Initialization (Base_Type (E));
20396 -- For other than first subtype, set flag on subtype or variable
20398 else
20399 Set_Suppress_Initialization (E);
20400 end if;
20401 end Suppress_Init;
20403 -----------------
20404 -- System_Name --
20405 -----------------
20407 -- pragma System_Name (DIRECT_NAME);
20409 -- Syntax check: one argument, which must be the identifier GNAT or
20410 -- the identifier GCC, no other identifiers are acceptable.
20412 when Pragma_System_Name =>
20413 GNAT_Pragma;
20414 Check_No_Identifiers;
20415 Check_Arg_Count (1);
20416 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
20418 -----------------------------
20419 -- Task_Dispatching_Policy --
20420 -----------------------------
20422 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
20424 when Pragma_Task_Dispatching_Policy => declare
20425 DP : Character;
20427 begin
20428 Check_Ada_83_Warning;
20429 Check_Arg_Count (1);
20430 Check_No_Identifiers;
20431 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
20432 Check_Valid_Configuration_Pragma;
20433 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
20434 DP := Fold_Upper (Name_Buffer (1));
20436 if Task_Dispatching_Policy /= ' '
20437 and then Task_Dispatching_Policy /= DP
20438 then
20439 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
20440 Error_Pragma
20441 ("task dispatching policy incompatible with policy#");
20443 -- Set new policy, but always preserve System_Location since we
20444 -- like the error message with the run time name.
20446 else
20447 Task_Dispatching_Policy := DP;
20449 if Task_Dispatching_Policy_Sloc /= System_Location then
20450 Task_Dispatching_Policy_Sloc := Loc;
20451 end if;
20452 end if;
20453 end;
20455 ---------------
20456 -- Task_Info --
20457 ---------------
20459 -- pragma Task_Info (EXPRESSION);
20461 when Pragma_Task_Info => Task_Info : declare
20462 P : constant Node_Id := Parent (N);
20463 Ent : Entity_Id;
20465 begin
20466 GNAT_Pragma;
20468 if Warn_On_Obsolescent_Feature then
20469 Error_Msg_N
20470 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
20471 & "instead?j?", N);
20472 end if;
20474 if Nkind (P) /= N_Task_Definition then
20475 Error_Pragma ("pragma% must appear in task definition");
20476 end if;
20478 Check_No_Identifiers;
20479 Check_Arg_Count (1);
20481 Analyze_And_Resolve
20482 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
20484 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
20485 return;
20486 end if;
20488 Ent := Defining_Identifier (Parent (P));
20490 -- Check duplicate pragma before we chain the pragma in the Rep
20491 -- Item chain of Ent.
20493 if Has_Rep_Pragma
20494 (Ent, Name_Task_Info, Check_Parents => False)
20495 then
20496 Error_Pragma ("duplicate pragma% not allowed");
20497 end if;
20499 Record_Rep_Item (Ent, N);
20500 end Task_Info;
20502 ---------------
20503 -- Task_Name --
20504 ---------------
20506 -- pragma Task_Name (string_EXPRESSION);
20508 when Pragma_Task_Name => Task_Name : declare
20509 P : constant Node_Id := Parent (N);
20510 Arg : Node_Id;
20511 Ent : Entity_Id;
20513 begin
20514 Check_No_Identifiers;
20515 Check_Arg_Count (1);
20517 Arg := Get_Pragma_Arg (Arg1);
20519 -- The expression is used in the call to Create_Task, and must be
20520 -- expanded there, not in the context of the current spec. It must
20521 -- however be analyzed to capture global references, in case it
20522 -- appears in a generic context.
20524 Preanalyze_And_Resolve (Arg, Standard_String);
20526 if Nkind (P) /= N_Task_Definition then
20527 Pragma_Misplaced;
20528 end if;
20530 Ent := Defining_Identifier (Parent (P));
20532 -- Check duplicate pragma before we chain the pragma in the Rep
20533 -- Item chain of Ent.
20535 if Has_Rep_Pragma
20536 (Ent, Name_Task_Name, Check_Parents => False)
20537 then
20538 Error_Pragma ("duplicate pragma% not allowed");
20539 end if;
20541 Record_Rep_Item (Ent, N);
20542 end Task_Name;
20544 ------------------
20545 -- Task_Storage --
20546 ------------------
20548 -- pragma Task_Storage (
20549 -- [Task_Type =>] LOCAL_NAME,
20550 -- [Top_Guard =>] static_integer_EXPRESSION);
20552 when Pragma_Task_Storage => Task_Storage : declare
20553 Args : Args_List (1 .. 2);
20554 Names : constant Name_List (1 .. 2) := (
20555 Name_Task_Type,
20556 Name_Top_Guard);
20558 Task_Type : Node_Id renames Args (1);
20559 Top_Guard : Node_Id renames Args (2);
20561 Ent : Entity_Id;
20563 begin
20564 GNAT_Pragma;
20565 Gather_Associations (Names, Args);
20567 if No (Task_Type) then
20568 Error_Pragma
20569 ("missing task_type argument for pragma%");
20570 end if;
20572 Check_Arg_Is_Local_Name (Task_Type);
20574 Ent := Entity (Task_Type);
20576 if not Is_Task_Type (Ent) then
20577 Error_Pragma_Arg
20578 ("argument for pragma% must be task type", Task_Type);
20579 end if;
20581 if No (Top_Guard) then
20582 Error_Pragma_Arg
20583 ("pragma% takes two arguments", Task_Type);
20584 else
20585 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
20586 end if;
20588 Check_First_Subtype (Task_Type);
20590 if Rep_Item_Too_Late (Ent, N) then
20591 raise Pragma_Exit;
20592 end if;
20593 end Task_Storage;
20595 ---------------
20596 -- Test_Case --
20597 ---------------
20599 -- pragma Test_Case
20600 -- ([Name =>] Static_String_EXPRESSION
20601 -- ,[Mode =>] MODE_TYPE
20602 -- [, Requires => Boolean_EXPRESSION]
20603 -- [, Ensures => Boolean_EXPRESSION]);
20605 -- MODE_TYPE ::= Nominal | Robustness
20607 when Pragma_Test_Case =>
20608 GNAT_Pragma;
20609 Check_Test_Case;
20611 --------------------------
20612 -- Thread_Local_Storage --
20613 --------------------------
20615 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
20617 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
20618 Id : Node_Id;
20619 E : Entity_Id;
20621 begin
20622 GNAT_Pragma;
20623 Check_Arg_Count (1);
20624 Check_Optional_Identifier (Arg1, Name_Entity);
20625 Check_Arg_Is_Library_Level_Local_Name (Arg1);
20627 Id := Get_Pragma_Arg (Arg1);
20628 Analyze (Id);
20630 if not Is_Entity_Name (Id)
20631 or else Ekind (Entity (Id)) /= E_Variable
20632 then
20633 Error_Pragma_Arg ("local variable name required", Arg1);
20634 end if;
20636 E := Entity (Id);
20638 if Rep_Item_Too_Early (E, N)
20639 or else Rep_Item_Too_Late (E, N)
20640 then
20641 raise Pragma_Exit;
20642 end if;
20644 Set_Has_Pragma_Thread_Local_Storage (E);
20645 Set_Has_Gigi_Rep_Item (E);
20646 end Thread_Local_Storage;
20648 ----------------
20649 -- Time_Slice --
20650 ----------------
20652 -- pragma Time_Slice (static_duration_EXPRESSION);
20654 when Pragma_Time_Slice => Time_Slice : declare
20655 Val : Ureal;
20656 Nod : Node_Id;
20658 begin
20659 GNAT_Pragma;
20660 Check_Arg_Count (1);
20661 Check_No_Identifiers;
20662 Check_In_Main_Program;
20663 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
20665 if not Error_Posted (Arg1) then
20666 Nod := Next (N);
20667 while Present (Nod) loop
20668 if Nkind (Nod) = N_Pragma
20669 and then Pragma_Name (Nod) = Name_Time_Slice
20670 then
20671 Error_Msg_Name_1 := Pname;
20672 Error_Msg_N ("duplicate pragma% not permitted", Nod);
20673 end if;
20675 Next (Nod);
20676 end loop;
20677 end if;
20679 -- Process only if in main unit
20681 if Get_Source_Unit (Loc) = Main_Unit then
20682 Opt.Time_Slice_Set := True;
20683 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
20685 if Val <= Ureal_0 then
20686 Opt.Time_Slice_Value := 0;
20688 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
20689 Opt.Time_Slice_Value := 1_000_000_000;
20691 else
20692 Opt.Time_Slice_Value :=
20693 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
20694 end if;
20695 end if;
20696 end Time_Slice;
20698 -----------
20699 -- Title --
20700 -----------
20702 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
20704 -- TITLING_OPTION ::=
20705 -- [Title =>] STRING_LITERAL
20706 -- | [Subtitle =>] STRING_LITERAL
20708 when Pragma_Title => Title : declare
20709 Args : Args_List (1 .. 2);
20710 Names : constant Name_List (1 .. 2) := (
20711 Name_Title,
20712 Name_Subtitle);
20714 begin
20715 GNAT_Pragma;
20716 Gather_Associations (Names, Args);
20717 Store_Note (N);
20719 for J in 1 .. 2 loop
20720 if Present (Args (J)) then
20721 Check_Arg_Is_OK_Static_Expression
20722 (Args (J), Standard_String);
20723 end if;
20724 end loop;
20725 end Title;
20727 ----------------------------
20728 -- Type_Invariant[_Class] --
20729 ----------------------------
20731 -- pragma Type_Invariant[_Class]
20732 -- ([Entity =>] type_LOCAL_NAME,
20733 -- [Check =>] EXPRESSION);
20735 when Pragma_Type_Invariant |
20736 Pragma_Type_Invariant_Class =>
20737 Type_Invariant : declare
20738 I_Pragma : Node_Id;
20740 begin
20741 Check_Arg_Count (2);
20743 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
20744 -- setting Class_Present for the Type_Invariant_Class case.
20746 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
20747 I_Pragma := New_Copy (N);
20748 Set_Pragma_Identifier
20749 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
20750 Rewrite (N, I_Pragma);
20751 Set_Analyzed (N, False);
20752 Analyze (N);
20753 end Type_Invariant;
20755 ---------------------
20756 -- Unchecked_Union --
20757 ---------------------
20759 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
20761 when Pragma_Unchecked_Union => Unchecked_Union : declare
20762 Assoc : constant Node_Id := Arg1;
20763 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
20764 Typ : Entity_Id;
20765 Tdef : Node_Id;
20766 Clist : Node_Id;
20767 Vpart : Node_Id;
20768 Comp : Node_Id;
20769 Variant : Node_Id;
20771 begin
20772 Ada_2005_Pragma;
20773 Check_No_Identifiers;
20774 Check_Arg_Count (1);
20775 Check_Arg_Is_Local_Name (Arg1);
20777 Find_Type (Type_Id);
20779 Typ := Entity (Type_Id);
20781 if Typ = Any_Type
20782 or else Rep_Item_Too_Early (Typ, N)
20783 then
20784 return;
20785 else
20786 Typ := Underlying_Type (Typ);
20787 end if;
20789 if Rep_Item_Too_Late (Typ, N) then
20790 return;
20791 end if;
20793 Check_First_Subtype (Arg1);
20795 -- Note remaining cases are references to a type in the current
20796 -- declarative part. If we find an error, we post the error on
20797 -- the relevant type declaration at an appropriate point.
20799 if not Is_Record_Type (Typ) then
20800 Error_Msg_N ("unchecked union must be record type", Typ);
20801 return;
20803 elsif Is_Tagged_Type (Typ) then
20804 Error_Msg_N ("unchecked union must not be tagged", Typ);
20805 return;
20807 elsif not Has_Discriminants (Typ) then
20808 Error_Msg_N
20809 ("unchecked union must have one discriminant", Typ);
20810 return;
20812 -- Note: in previous versions of GNAT we used to check for limited
20813 -- types and give an error, but in fact the standard does allow
20814 -- Unchecked_Union on limited types, so this check was removed.
20816 -- Similarly, GNAT used to require that all discriminants have
20817 -- default values, but this is not mandated by the RM.
20819 -- Proceed with basic error checks completed
20821 else
20822 Tdef := Type_Definition (Declaration_Node (Typ));
20823 Clist := Component_List (Tdef);
20825 -- Check presence of component list and variant part
20827 if No (Clist) or else No (Variant_Part (Clist)) then
20828 Error_Msg_N
20829 ("unchecked union must have variant part", Tdef);
20830 return;
20831 end if;
20833 -- Check components
20835 Comp := First (Component_Items (Clist));
20836 while Present (Comp) loop
20837 Check_Component (Comp, Typ);
20838 Next (Comp);
20839 end loop;
20841 -- Check variant part
20843 Vpart := Variant_Part (Clist);
20845 Variant := First (Variants (Vpart));
20846 while Present (Variant) loop
20847 Check_Variant (Variant, Typ);
20848 Next (Variant);
20849 end loop;
20850 end if;
20852 Set_Is_Unchecked_Union (Typ);
20853 Set_Convention (Typ, Convention_C);
20854 Set_Has_Unchecked_Union (Base_Type (Typ));
20855 Set_Is_Unchecked_Union (Base_Type (Typ));
20856 end Unchecked_Union;
20858 ------------------------
20859 -- Unimplemented_Unit --
20860 ------------------------
20862 -- pragma Unimplemented_Unit;
20864 -- Note: this only gives an error if we are generating code, or if
20865 -- we are in a generic library unit (where the pragma appears in the
20866 -- body, not in the spec).
20868 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
20869 Cunitent : constant Entity_Id :=
20870 Cunit_Entity (Get_Source_Unit (Loc));
20871 Ent_Kind : constant Entity_Kind :=
20872 Ekind (Cunitent);
20874 begin
20875 GNAT_Pragma;
20876 Check_Arg_Count (0);
20878 if Operating_Mode = Generate_Code
20879 or else Ent_Kind = E_Generic_Function
20880 or else Ent_Kind = E_Generic_Procedure
20881 or else Ent_Kind = E_Generic_Package
20882 then
20883 Get_Name_String (Chars (Cunitent));
20884 Set_Casing (Mixed_Case);
20885 Write_Str (Name_Buffer (1 .. Name_Len));
20886 Write_Str (" is not supported in this configuration");
20887 Write_Eol;
20888 raise Unrecoverable_Error;
20889 end if;
20890 end Unimplemented_Unit;
20892 ------------------------
20893 -- Universal_Aliasing --
20894 ------------------------
20896 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
20898 when Pragma_Universal_Aliasing => Universal_Alias : declare
20899 E_Id : Entity_Id;
20901 begin
20902 GNAT_Pragma;
20903 Check_Arg_Count (1);
20904 Check_Optional_Identifier (Arg2, Name_Entity);
20905 Check_Arg_Is_Local_Name (Arg1);
20906 E_Id := Entity (Get_Pragma_Arg (Arg1));
20908 if E_Id = Any_Type then
20909 return;
20910 elsif No (E_Id) or else not Is_Type (E_Id) then
20911 Error_Pragma_Arg ("pragma% requires type", Arg1);
20912 end if;
20914 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
20915 Record_Rep_Item (E_Id, N);
20916 end Universal_Alias;
20918 --------------------
20919 -- Universal_Data --
20920 --------------------
20922 -- pragma Universal_Data [(library_unit_NAME)];
20924 when Pragma_Universal_Data =>
20925 GNAT_Pragma;
20927 -- If this is a configuration pragma, then set the universal
20928 -- addressing option, otherwise confirm that the pragma satisfies
20929 -- the requirements of library unit pragma placement and leave it
20930 -- to the GNAAMP back end to detect the pragma (avoids transitive
20931 -- setting of the option due to withed units).
20933 if Is_Configuration_Pragma then
20934 Universal_Addressing_On_AAMP := True;
20935 else
20936 Check_Valid_Library_Unit_Pragma;
20937 end if;
20939 if not AAMP_On_Target then
20940 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
20941 end if;
20943 ----------------
20944 -- Unmodified --
20945 ----------------
20947 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
20949 when Pragma_Unmodified => Unmodified : declare
20950 Arg_Node : Node_Id;
20951 Arg_Expr : Node_Id;
20952 Arg_Ent : Entity_Id;
20954 begin
20955 GNAT_Pragma;
20956 Check_At_Least_N_Arguments (1);
20958 -- Loop through arguments
20960 Arg_Node := Arg1;
20961 while Present (Arg_Node) loop
20962 Check_No_Identifier (Arg_Node);
20964 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
20965 -- in fact generate reference, so that the entity will have a
20966 -- reference, which will inhibit any warnings about it not
20967 -- being referenced, and also properly show up in the ali file
20968 -- as a reference. But this reference is recorded before the
20969 -- Has_Pragma_Unreferenced flag is set, so that no warning is
20970 -- generated for this reference.
20972 Check_Arg_Is_Local_Name (Arg_Node);
20973 Arg_Expr := Get_Pragma_Arg (Arg_Node);
20975 if Is_Entity_Name (Arg_Expr) then
20976 Arg_Ent := Entity (Arg_Expr);
20978 if not Is_Assignable (Arg_Ent) then
20979 Error_Pragma_Arg
20980 ("pragma% can only be applied to a variable",
20981 Arg_Expr);
20982 else
20983 Set_Has_Pragma_Unmodified (Arg_Ent);
20984 end if;
20985 end if;
20987 Next (Arg_Node);
20988 end loop;
20989 end Unmodified;
20991 ------------------
20992 -- Unreferenced --
20993 ------------------
20995 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
20997 -- or when used in a context clause:
20999 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
21001 when Pragma_Unreferenced => Unreferenced : declare
21002 Arg_Node : Node_Id;
21003 Arg_Expr : Node_Id;
21004 Arg_Ent : Entity_Id;
21005 Citem : Node_Id;
21007 begin
21008 GNAT_Pragma;
21009 Check_At_Least_N_Arguments (1);
21011 -- Check case of appearing within context clause
21013 if Is_In_Context_Clause then
21015 -- The arguments must all be units mentioned in a with clause
21016 -- in the same context clause. Note we already checked (in
21017 -- Par.Prag) that the arguments are either identifiers or
21018 -- selected components.
21020 Arg_Node := Arg1;
21021 while Present (Arg_Node) loop
21022 Citem := First (List_Containing (N));
21023 while Citem /= N loop
21024 if Nkind (Citem) = N_With_Clause
21025 and then
21026 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
21027 then
21028 Set_Has_Pragma_Unreferenced
21029 (Cunit_Entity
21030 (Get_Source_Unit
21031 (Library_Unit (Citem))));
21032 Set_Unit_Name
21033 (Get_Pragma_Arg (Arg_Node), Name (Citem));
21034 exit;
21035 end if;
21037 Next (Citem);
21038 end loop;
21040 if Citem = N then
21041 Error_Pragma_Arg
21042 ("argument of pragma% is not withed unit", Arg_Node);
21043 end if;
21045 Next (Arg_Node);
21046 end loop;
21048 -- Case of not in list of context items
21050 else
21051 Arg_Node := Arg1;
21052 while Present (Arg_Node) loop
21053 Check_No_Identifier (Arg_Node);
21055 -- Note: the analyze call done by Check_Arg_Is_Local_Name
21056 -- will in fact generate reference, so that the entity will
21057 -- have a reference, which will inhibit any warnings about
21058 -- it not being referenced, and also properly show up in the
21059 -- ali file as a reference. But this reference is recorded
21060 -- before the Has_Pragma_Unreferenced flag is set, so that
21061 -- no warning is generated for this reference.
21063 Check_Arg_Is_Local_Name (Arg_Node);
21064 Arg_Expr := Get_Pragma_Arg (Arg_Node);
21066 if Is_Entity_Name (Arg_Expr) then
21067 Arg_Ent := Entity (Arg_Expr);
21069 -- If the entity is overloaded, the pragma applies to the
21070 -- most recent overloading, as documented. In this case,
21071 -- name resolution does not generate a reference, so it
21072 -- must be done here explicitly.
21074 if Is_Overloaded (Arg_Expr) then
21075 Generate_Reference (Arg_Ent, N);
21076 end if;
21078 Set_Has_Pragma_Unreferenced (Arg_Ent);
21079 end if;
21081 Next (Arg_Node);
21082 end loop;
21083 end if;
21084 end Unreferenced;
21086 --------------------------
21087 -- Unreferenced_Objects --
21088 --------------------------
21090 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
21092 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
21093 Arg_Node : Node_Id;
21094 Arg_Expr : Node_Id;
21096 begin
21097 GNAT_Pragma;
21098 Check_At_Least_N_Arguments (1);
21100 Arg_Node := Arg1;
21101 while Present (Arg_Node) loop
21102 Check_No_Identifier (Arg_Node);
21103 Check_Arg_Is_Local_Name (Arg_Node);
21104 Arg_Expr := Get_Pragma_Arg (Arg_Node);
21106 if not Is_Entity_Name (Arg_Expr)
21107 or else not Is_Type (Entity (Arg_Expr))
21108 then
21109 Error_Pragma_Arg
21110 ("argument for pragma% must be type or subtype", Arg_Node);
21111 end if;
21113 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
21114 Next (Arg_Node);
21115 end loop;
21116 end Unreferenced_Objects;
21118 ------------------------------
21119 -- Unreserve_All_Interrupts --
21120 ------------------------------
21122 -- pragma Unreserve_All_Interrupts;
21124 when Pragma_Unreserve_All_Interrupts =>
21125 GNAT_Pragma;
21126 Check_Arg_Count (0);
21128 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
21129 Unreserve_All_Interrupts := True;
21130 end if;
21132 ----------------
21133 -- Unsuppress --
21134 ----------------
21136 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
21138 when Pragma_Unsuppress =>
21139 Ada_2005_Pragma;
21140 Process_Suppress_Unsuppress (Suppress_Case => False);
21142 ----------------------------
21143 -- Unevaluated_Use_Of_Old --
21144 ----------------------------
21146 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
21148 when Pragma_Unevaluated_Use_Of_Old =>
21149 GNAT_Pragma;
21150 Check_Arg_Count (1);
21151 Check_No_Identifiers;
21152 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
21154 -- Suppress/Unsuppress can appear as a configuration pragma, or in
21155 -- a declarative part or a package spec.
21157 if not Is_Configuration_Pragma then
21158 Check_Is_In_Decl_Part_Or_Package_Spec;
21159 end if;
21161 -- Store proper setting of Uneval_Old
21163 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21164 Uneval_Old := Fold_Upper (Name_Buffer (1));
21166 -------------------
21167 -- Use_VADS_Size --
21168 -------------------
21170 -- pragma Use_VADS_Size;
21172 when Pragma_Use_VADS_Size =>
21173 GNAT_Pragma;
21174 Check_Arg_Count (0);
21175 Check_Valid_Configuration_Pragma;
21176 Use_VADS_Size := True;
21178 ---------------------
21179 -- Validity_Checks --
21180 ---------------------
21182 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
21184 when Pragma_Validity_Checks => Validity_Checks : declare
21185 A : constant Node_Id := Get_Pragma_Arg (Arg1);
21186 S : String_Id;
21187 C : Char_Code;
21189 begin
21190 GNAT_Pragma;
21191 Check_Arg_Count (1);
21192 Check_No_Identifiers;
21194 -- Pragma always active unless in CodePeer or GNATprove modes,
21195 -- which use a fixed configuration of validity checks.
21197 if not (CodePeer_Mode or GNATprove_Mode) then
21198 if Nkind (A) = N_String_Literal then
21199 S := Strval (A);
21201 declare
21202 Slen : constant Natural := Natural (String_Length (S));
21203 Options : String (1 .. Slen);
21204 J : Natural;
21206 begin
21207 -- Couldn't we use a for loop here over Options'Range???
21209 J := 1;
21210 loop
21211 C := Get_String_Char (S, Int (J));
21213 -- This is a weird test, it skips setting validity
21214 -- checks entirely if any element of S is out of
21215 -- range of Character, what is that about ???
21217 exit when not In_Character_Range (C);
21218 Options (J) := Get_Character (C);
21220 if J = Slen then
21221 Set_Validity_Check_Options (Options);
21222 exit;
21223 else
21224 J := J + 1;
21225 end if;
21226 end loop;
21227 end;
21229 elsif Nkind (A) = N_Identifier then
21230 if Chars (A) = Name_All_Checks then
21231 Set_Validity_Check_Options ("a");
21232 elsif Chars (A) = Name_On then
21233 Validity_Checks_On := True;
21234 elsif Chars (A) = Name_Off then
21235 Validity_Checks_On := False;
21236 end if;
21237 end if;
21238 end if;
21239 end Validity_Checks;
21241 --------------
21242 -- Volatile --
21243 --------------
21245 -- pragma Volatile (LOCAL_NAME);
21247 when Pragma_Volatile =>
21248 Process_Atomic_Independent_Shared_Volatile;
21250 -------------------------
21251 -- Volatile_Components --
21252 -------------------------
21254 -- pragma Volatile_Components (array_LOCAL_NAME);
21256 -- Volatile is handled by the same circuit as Atomic_Components
21258 ----------------------
21259 -- Warning_As_Error --
21260 ----------------------
21262 -- pragma Warning_As_Error (static_string_EXPRESSION);
21264 when Pragma_Warning_As_Error =>
21265 GNAT_Pragma;
21266 Check_Arg_Count (1);
21267 Check_No_Identifiers;
21268 Check_Valid_Configuration_Pragma;
21270 if not Is_Static_String_Expression (Arg1) then
21271 Error_Pragma_Arg
21272 ("argument of pragma% must be static string expression",
21273 Arg1);
21275 -- OK static string expression
21277 else
21278 Acquire_Warning_Match_String (Arg1);
21279 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
21280 Warnings_As_Errors (Warnings_As_Errors_Count) :=
21281 new String'(Name_Buffer (1 .. Name_Len));
21282 end if;
21284 --------------
21285 -- Warnings --
21286 --------------
21288 -- pragma Warnings (On | Off [,REASON]);
21289 -- pragma Warnings (On | Off, LOCAL_NAME [,REASON]);
21290 -- pragma Warnings (static_string_EXPRESSION [,REASON]);
21291 -- pragma Warnings (On | Off, STRING_LITERAL [,REASON]);
21293 -- REASON ::= Reason => Static_String_Expression
21295 when Pragma_Warnings => Warnings : declare
21296 Reason : String_Id;
21298 begin
21299 GNAT_Pragma;
21300 Check_At_Least_N_Arguments (1);
21302 -- See if last argument is labeled Reason. If so, make sure we
21303 -- have a static string expression, and acquire the REASON string.
21304 -- Then remove the REASON argument by decreasing Num_Args by one;
21305 -- Remaining processing looks only at first Num_Args arguments).
21307 declare
21308 Last_Arg : constant Node_Id :=
21309 Last (Pragma_Argument_Associations (N));
21311 begin
21312 if Nkind (Last_Arg) = N_Pragma_Argument_Association
21313 and then Chars (Last_Arg) = Name_Reason
21314 then
21315 Start_String;
21316 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
21317 Reason := End_String;
21318 Arg_Count := Arg_Count - 1;
21320 -- Not allowed in compiler units (bootstrap issues)
21322 Check_Compiler_Unit ("Reason for pragma Warnings", N);
21324 -- No REASON string, set null string as reason
21326 else
21327 Reason := Null_String_Id;
21328 end if;
21329 end;
21331 -- Now proceed with REASON taken care of and eliminated
21333 Check_No_Identifiers;
21335 -- If debug flag -gnatd.i is set, pragma is ignored
21337 if Debug_Flag_Dot_I then
21338 return;
21339 end if;
21341 -- Process various forms of the pragma
21343 declare
21344 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21346 begin
21347 -- One argument case
21349 if Arg_Count = 1 then
21351 -- On/Off one argument case was processed by parser
21353 if Nkind (Argx) = N_Identifier
21354 and then Nam_In (Chars (Argx), Name_On, Name_Off)
21355 then
21356 null;
21358 -- One argument case must be ON/OFF or static string expr
21360 elsif not Is_Static_String_Expression (Arg1) then
21361 Error_Pragma_Arg
21362 ("argument of pragma% must be On/Off or static string "
21363 & "expression", Arg1);
21365 -- One argument string expression case
21367 else
21368 declare
21369 Lit : constant Node_Id := Expr_Value_S (Argx);
21370 Str : constant String_Id := Strval (Lit);
21371 Len : constant Nat := String_Length (Str);
21372 C : Char_Code;
21373 J : Nat;
21374 OK : Boolean;
21375 Chr : Character;
21377 begin
21378 J := 1;
21379 while J <= Len loop
21380 C := Get_String_Char (Str, J);
21381 OK := In_Character_Range (C);
21383 if OK then
21384 Chr := Get_Character (C);
21386 -- Dash case: only -Wxxx is accepted
21388 if J = 1
21389 and then J < Len
21390 and then Chr = '-'
21391 then
21392 J := J + 1;
21393 C := Get_String_Char (Str, J);
21394 Chr := Get_Character (C);
21395 exit when Chr = 'W';
21396 OK := False;
21398 -- Dot case
21400 elsif J < Len and then Chr = '.' then
21401 J := J + 1;
21402 C := Get_String_Char (Str, J);
21403 Chr := Get_Character (C);
21405 if not Set_Dot_Warning_Switch (Chr) then
21406 Error_Pragma_Arg
21407 ("invalid warning switch character "
21408 & '.' & Chr, Arg1);
21409 end if;
21411 -- Non-Dot case
21413 else
21414 OK := Set_Warning_Switch (Chr);
21415 end if;
21416 end if;
21418 if not OK then
21419 Error_Pragma_Arg
21420 ("invalid warning switch character " & Chr,
21421 Arg1);
21422 end if;
21424 J := J + 1;
21425 end loop;
21426 end;
21427 end if;
21429 -- Two or more arguments (must be two)
21431 else
21432 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
21433 Check_Arg_Count (2);
21435 declare
21436 E_Id : Node_Id;
21437 E : Entity_Id;
21438 Err : Boolean;
21440 begin
21441 E_Id := Get_Pragma_Arg (Arg2);
21442 Analyze (E_Id);
21444 -- In the expansion of an inlined body, a reference to
21445 -- the formal may be wrapped in a conversion if the
21446 -- actual is a conversion. Retrieve the real entity name.
21448 if (In_Instance_Body or In_Inlined_Body)
21449 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
21450 then
21451 E_Id := Expression (E_Id);
21452 end if;
21454 -- Entity name case
21456 if Is_Entity_Name (E_Id) then
21457 E := Entity (E_Id);
21459 if E = Any_Id then
21460 return;
21461 else
21462 loop
21463 Set_Warnings_Off
21464 (E, (Chars (Get_Pragma_Arg (Arg1)) =
21465 Name_Off));
21467 -- For OFF case, make entry in warnings off
21468 -- pragma table for later processing. But we do
21469 -- not do that within an instance, since these
21470 -- warnings are about what is needed in the
21471 -- template, not an instance of it.
21473 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
21474 and then Warn_On_Warnings_Off
21475 and then not In_Instance
21476 then
21477 Warnings_Off_Pragmas.Append ((N, E, Reason));
21478 end if;
21480 if Is_Enumeration_Type (E) then
21481 declare
21482 Lit : Entity_Id;
21483 begin
21484 Lit := First_Literal (E);
21485 while Present (Lit) loop
21486 Set_Warnings_Off (Lit);
21487 Next_Literal (Lit);
21488 end loop;
21489 end;
21490 end if;
21492 exit when No (Homonym (E));
21493 E := Homonym (E);
21494 end loop;
21495 end if;
21497 -- Error if not entity or static string expression case
21499 elsif not Is_Static_String_Expression (Arg2) then
21500 Error_Pragma_Arg
21501 ("second argument of pragma% must be entity name "
21502 & "or static string expression", Arg2);
21504 -- Static string expression case
21506 else
21507 Acquire_Warning_Match_String (Arg2);
21509 -- Note on configuration pragma case: If this is a
21510 -- configuration pragma, then for an OFF pragma, we
21511 -- just set Config True in the call, which is all
21512 -- that needs to be done. For the case of ON, this
21513 -- is normally an error, unless it is canceling the
21514 -- effect of a previous OFF pragma in the same file.
21515 -- In any other case, an error will be signalled (ON
21516 -- with no matching OFF).
21518 -- Note: We set Used if we are inside a generic to
21519 -- disable the test that the non-config case actually
21520 -- cancels a warning. That's because we can't be sure
21521 -- there isn't an instantiation in some other unit
21522 -- where a warning is suppressed.
21524 -- We could do a little better here by checking if the
21525 -- generic unit we are inside is public, but for now
21526 -- we don't bother with that refinement.
21528 if Chars (Argx) = Name_Off then
21529 Set_Specific_Warning_Off
21530 (Loc, Name_Buffer (1 .. Name_Len), Reason,
21531 Config => Is_Configuration_Pragma,
21532 Used => Inside_A_Generic or else In_Instance);
21534 elsif Chars (Argx) = Name_On then
21535 Set_Specific_Warning_On
21536 (Loc, Name_Buffer (1 .. Name_Len), Err);
21538 if Err then
21539 Error_Msg
21540 ("??pragma Warnings On with no matching "
21541 & "Warnings Off", Loc);
21542 end if;
21543 end if;
21544 end if;
21545 end;
21546 end if;
21547 end;
21548 end Warnings;
21550 -------------------
21551 -- Weak_External --
21552 -------------------
21554 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
21556 when Pragma_Weak_External => Weak_External : declare
21557 Ent : Entity_Id;
21559 begin
21560 GNAT_Pragma;
21561 Check_Arg_Count (1);
21562 Check_Optional_Identifier (Arg1, Name_Entity);
21563 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21564 Ent := Entity (Get_Pragma_Arg (Arg1));
21566 if Rep_Item_Too_Early (Ent, N) then
21567 return;
21568 else
21569 Ent := Underlying_Type (Ent);
21570 end if;
21572 -- The only processing required is to link this item on to the
21573 -- list of rep items for the given entity. This is accomplished
21574 -- by the call to Rep_Item_Too_Late (when no error is detected
21575 -- and False is returned).
21577 if Rep_Item_Too_Late (Ent, N) then
21578 return;
21579 else
21580 Set_Has_Gigi_Rep_Item (Ent);
21581 end if;
21582 end Weak_External;
21584 -----------------------------
21585 -- Wide_Character_Encoding --
21586 -----------------------------
21588 -- pragma Wide_Character_Encoding (IDENTIFIER);
21590 when Pragma_Wide_Character_Encoding =>
21591 GNAT_Pragma;
21593 -- Nothing to do, handled in parser. Note that we do not enforce
21594 -- configuration pragma placement, this pragma can appear at any
21595 -- place in the source, allowing mixed encodings within a single
21596 -- source program.
21598 null;
21600 --------------------
21601 -- Unknown_Pragma --
21602 --------------------
21604 -- Should be impossible, since the case of an unknown pragma is
21605 -- separately processed before the case statement is entered.
21607 when Unknown_Pragma =>
21608 raise Program_Error;
21609 end case;
21611 -- AI05-0144: detect dangerous order dependence. Disabled for now,
21612 -- until AI is formally approved.
21614 -- Check_Order_Dependence;
21616 exception
21617 when Pragma_Exit => null;
21618 end Analyze_Pragma;
21620 ---------------------------------------------
21621 -- Analyze_Pre_Post_Condition_In_Decl_Part --
21622 ---------------------------------------------
21624 procedure Analyze_Pre_Post_Condition_In_Decl_Part
21625 (Prag : Node_Id;
21626 Subp_Id : Entity_Id)
21628 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (Prag));
21629 Nam : constant Name_Id := Original_Aspect_Name (Prag);
21630 Expr : Node_Id;
21632 Restore_Scope : Boolean := False;
21633 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
21635 begin
21636 -- Ensure that the subprogram and its formals are visible when analyzing
21637 -- the expression of the pragma.
21639 if not In_Open_Scopes (Subp_Id) then
21640 Restore_Scope := True;
21641 Push_Scope (Subp_Id);
21642 Install_Formals (Subp_Id);
21643 end if;
21645 -- Preanalyze the boolean expression, we treat this as a spec expression
21646 -- (i.e. similar to a default expression).
21648 Expr := Get_Pragma_Arg (Arg1);
21650 -- In ASIS mode, for a pragma generated from a source aspect, analyze
21651 -- the original aspect expression, which is shared with the generated
21652 -- pragma.
21654 if ASIS_Mode and then Present (Corresponding_Aspect (Prag)) then
21655 Expr := Expression (Corresponding_Aspect (Prag));
21656 end if;
21658 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
21660 -- For a class-wide condition, a reference to a controlling formal must
21661 -- be interpreted as having the class-wide type (or an access to such)
21662 -- so that the inherited condition can be properly applied to any
21663 -- overriding operation (see ARM12 6.6.1 (7)).
21665 if Class_Present (Prag) then
21666 Class_Wide_Condition : declare
21667 T : constant Entity_Id := Find_Dispatching_Type (Subp_Id);
21669 ACW : Entity_Id := Empty;
21670 -- Access to T'class, created if there is a controlling formal
21671 -- that is an access parameter.
21673 function Get_ACW return Entity_Id;
21674 -- If the expression has a reference to an controlling access
21675 -- parameter, create an access to T'class for the necessary
21676 -- conversions if one does not exist.
21678 function Process (N : Node_Id) return Traverse_Result;
21679 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
21680 -- aspect for a primitive subprogram of a tagged type T, a name
21681 -- that denotes a formal parameter of type T is interpreted as
21682 -- having type T'Class. Similarly, a name that denotes a formal
21683 -- accessparameter of type access-to-T is interpreted as having
21684 -- type access-to-T'Class. This ensures the expression is well-
21685 -- defined for a primitive subprogram of a type descended from T.
21686 -- Note that this replacement is not done for selector names in
21687 -- parameter associations. These carry an entity for reference
21688 -- purposes, but semantically they are just identifiers.
21690 -------------
21691 -- Get_ACW --
21692 -------------
21694 function Get_ACW return Entity_Id is
21695 Loc : constant Source_Ptr := Sloc (Prag);
21696 Decl : Node_Id;
21698 begin
21699 if No (ACW) then
21700 Decl :=
21701 Make_Full_Type_Declaration (Loc,
21702 Defining_Identifier => Make_Temporary (Loc, 'T'),
21703 Type_Definition =>
21704 Make_Access_To_Object_Definition (Loc,
21705 Subtype_Indication =>
21706 New_Occurrence_Of (Class_Wide_Type (T), Loc),
21707 All_Present => True));
21709 Insert_Before (Unit_Declaration_Node (Subp_Id), Decl);
21710 Analyze (Decl);
21711 ACW := Defining_Identifier (Decl);
21712 Freeze_Before (Unit_Declaration_Node (Subp_Id), ACW);
21713 end if;
21715 return ACW;
21716 end Get_ACW;
21718 -------------
21719 -- Process --
21720 -------------
21722 function Process (N : Node_Id) return Traverse_Result is
21723 Loc : constant Source_Ptr := Sloc (N);
21724 Typ : Entity_Id;
21726 begin
21727 if Is_Entity_Name (N)
21728 and then Present (Entity (N))
21729 and then Is_Formal (Entity (N))
21730 and then Nkind (Parent (N)) /= N_Type_Conversion
21731 and then
21732 (Nkind (Parent (N)) /= N_Parameter_Association
21733 or else N /= Selector_Name (Parent (N)))
21734 then
21735 if Etype (Entity (N)) = T then
21736 Typ := Class_Wide_Type (T);
21738 elsif Is_Access_Type (Etype (Entity (N)))
21739 and then Designated_Type (Etype (Entity (N))) = T
21740 then
21741 Typ := Get_ACW;
21742 else
21743 Typ := Empty;
21744 end if;
21746 if Present (Typ) then
21747 Rewrite (N,
21748 Make_Type_Conversion (Loc,
21749 Subtype_Mark =>
21750 New_Occurrence_Of (Typ, Loc),
21751 Expression => New_Occurrence_Of (Entity (N), Loc)));
21752 Set_Etype (N, Typ);
21753 end if;
21754 end if;
21756 return OK;
21757 end Process;
21759 procedure Replace_Type is new Traverse_Proc (Process);
21761 -- Start of processing for Class_Wide_Condition
21763 begin
21764 if not Present (T) then
21766 -- Pre'Class/Post'Class aspect cases
21768 if From_Aspect_Specification (Prag) then
21769 if Nam = Name_uPre then
21770 Error_Msg_Name_1 := Name_Pre;
21771 else
21772 Error_Msg_Name_1 := Name_Post;
21773 end if;
21775 Error_Msg_Name_2 := Name_Class;
21777 Error_Msg_N
21778 ("aspect `%''%` can only be specified for a primitive "
21779 & "operation of a tagged type",
21780 Corresponding_Aspect (Prag));
21782 -- Pre_Class, Post_Class pragma cases
21784 else
21785 if Nam = Name_uPre then
21786 Error_Msg_Name_1 := Name_Pre_Class;
21787 else
21788 Error_Msg_Name_1 := Name_Post_Class;
21789 end if;
21791 Error_Msg_N
21792 ("pragma% can only be specified for a primitive "
21793 & "operation of a tagged type",
21794 Corresponding_Aspect (Prag));
21795 end if;
21796 end if;
21798 Replace_Type (Get_Pragma_Arg (Arg1));
21799 end Class_Wide_Condition;
21800 end if;
21802 -- Remove the subprogram from the scope stack now that the pre-analysis
21803 -- of the precondition/postcondition is done.
21805 if Restore_Scope then
21806 End_Scope;
21807 end if;
21808 end Analyze_Pre_Post_Condition_In_Decl_Part;
21810 ------------------------------------------
21811 -- Analyze_Refined_Depends_In_Decl_Part --
21812 ------------------------------------------
21814 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
21815 Body_Inputs : Elist_Id := No_Elist;
21816 Body_Outputs : Elist_Id := No_Elist;
21817 -- The inputs and outputs of the subprogram body synthesized from pragma
21818 -- Refined_Depends.
21820 Dependencies : List_Id := No_List;
21821 Depends : Node_Id;
21822 -- The corresponding Depends pragma along with its clauses
21824 Matched_Items : Elist_Id := No_Elist;
21825 -- A list containing the entities of all successfully matched items
21826 -- found in pragma Depends.
21828 Refinements : List_Id := No_List;
21829 -- The clauses of pragma Refined_Depends
21831 Spec_Id : Entity_Id;
21832 -- The entity of the subprogram subject to pragma Refined_Depends
21834 Spec_Inputs : Elist_Id := No_Elist;
21835 Spec_Outputs : Elist_Id := No_Elist;
21836 -- The inputs and outputs of the subprogram spec synthesized from pragma
21837 -- Depends.
21839 procedure Check_Dependency_Clause (Dep_Clause : Node_Id);
21840 -- Try to match a single dependency clause Dep_Clause against one or
21841 -- more refinement clauses found in list Refinements. Each successful
21842 -- match eliminates at least one refinement clause from Refinements.
21844 procedure Check_Output_States;
21845 -- Determine whether pragma Depends contains an output state with a
21846 -- visible refinement and if so, ensure that pragma Refined_Depends
21847 -- mentions all its constituents as outputs.
21849 procedure Normalize_Clauses (Clauses : List_Id);
21850 -- Given a list of dependence or refinement clauses Clauses, normalize
21851 -- each clause by creating multiple dependencies with exactly one input
21852 -- and one output.
21854 procedure Report_Extra_Clauses;
21855 -- Emit an error for each extra clause found in list Refinements
21857 -----------------------------
21858 -- Check_Dependency_Clause --
21859 -----------------------------
21861 procedure Check_Dependency_Clause (Dep_Clause : Node_Id) is
21862 Dep_Input : constant Node_Id := Expression (Dep_Clause);
21863 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
21865 function Is_In_Out_State_Clause return Boolean;
21866 -- Determine whether dependence clause Dep_Clause denotes an abstract
21867 -- state that depends on itself (State => State).
21869 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
21870 -- Determine whether item Item denotes an abstract state with visible
21871 -- null refinement.
21873 procedure Match_Items
21874 (Dep_Item : Node_Id;
21875 Ref_Item : Node_Id;
21876 Matched : out Boolean);
21877 -- Try to match dependence item Dep_Item against refinement item
21878 -- Ref_Item. To match against a possible null refinement (see 2, 7),
21879 -- set Ref_Item to Empty. Flag Matched is set to True when one of
21880 -- the following conformance scenarios is in effect:
21881 -- 1) Both items denote null
21882 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
21883 -- 3) Both items denote attribute 'Result
21884 -- 4) Both items denote the same formal parameter
21885 -- 5) Both items denote the same variable
21886 -- 6) Dep_Item is an abstract state with visible null refinement
21887 -- and Ref_Item denotes null.
21888 -- 7) Dep_Item is an abstract state with visible null refinement
21889 -- and Ref_Item is Empty (special case).
21890 -- 8) Dep_Item is an abstract state with visible non-null
21891 -- refinement and Ref_Item denotes one of its constituents.
21892 -- 9) Dep_Item is an abstract state without a visible refinement
21893 -- and Ref_Item denotes the same state.
21894 -- When scenario 8 is in effect, the entity of the abstract state
21895 -- denoted by Dep_Item is added to list Refined_States.
21897 procedure Record_Item (Item_Id : Entity_Id);
21898 -- Store the entity of an item denoted by Item_Id in Matched_Items
21900 ----------------------------
21901 -- Is_In_Out_State_Clause --
21902 ----------------------------
21904 function Is_In_Out_State_Clause return Boolean is
21905 Dep_Input_Id : Entity_Id;
21906 Dep_Output_Id : Entity_Id;
21908 begin
21909 -- Detect the following clause:
21910 -- State => State
21912 if Is_Entity_Name (Dep_Input)
21913 and then Is_Entity_Name (Dep_Output)
21914 then
21915 -- Handle abstract views generated for limited with clauses
21917 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
21918 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
21920 return
21921 Ekind (Dep_Input_Id) = E_Abstract_State
21922 and then Dep_Input_Id = Dep_Output_Id;
21923 else
21924 return False;
21925 end if;
21926 end Is_In_Out_State_Clause;
21928 ---------------------------
21929 -- Is_Null_Refined_State --
21930 ---------------------------
21932 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
21933 Item_Id : Entity_Id;
21935 begin
21936 if Is_Entity_Name (Item) then
21938 -- Handle abstract views generated for limited with clauses
21940 Item_Id := Available_View (Entity_Of (Item));
21942 return Ekind (Item_Id) = E_Abstract_State
21943 and then Has_Null_Refinement (Item_Id);
21945 else
21946 return False;
21947 end if;
21948 end Is_Null_Refined_State;
21950 -----------------
21951 -- Match_Items --
21952 -----------------
21954 procedure Match_Items
21955 (Dep_Item : Node_Id;
21956 Ref_Item : Node_Id;
21957 Matched : out Boolean)
21959 Dep_Item_Id : Entity_Id;
21960 Ref_Item_Id : Entity_Id;
21962 begin
21963 -- Assume that the two items do not match
21965 Matched := False;
21967 -- A null matches null or Empty (special case)
21969 if Nkind (Dep_Item) = N_Null
21970 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
21971 then
21972 Matched := True;
21974 -- Attribute 'Result matches attribute 'Result
21976 elsif Is_Attribute_Result (Dep_Item)
21977 and then Is_Attribute_Result (Dep_Item)
21978 then
21979 Matched := True;
21981 -- Abstract states, formal parameters and variables
21983 elsif Is_Entity_Name (Dep_Item) then
21985 -- Handle abstract views generated for limited with clauses
21987 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
21989 if Ekind (Dep_Item_Id) = E_Abstract_State then
21991 -- An abstract state with visible null refinement matches
21992 -- null or Empty (special case).
21994 if Has_Null_Refinement (Dep_Item_Id)
21995 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
21996 then
21997 Record_Item (Dep_Item_Id);
21998 Matched := True;
22000 -- An abstract state with visible non-null refinement
22001 -- matches one of its constituents.
22003 elsif Has_Non_Null_Refinement (Dep_Item_Id) then
22004 if Is_Entity_Name (Ref_Item) then
22005 Ref_Item_Id := Entity_Of (Ref_Item);
22007 if Ekind_In (Ref_Item_Id, E_Abstract_State, E_Variable)
22008 and then Present (Encapsulating_State (Ref_Item_Id))
22009 and then Encapsulating_State (Ref_Item_Id) =
22010 Dep_Item_Id
22011 then
22012 Record_Item (Dep_Item_Id);
22013 Matched := True;
22014 end if;
22015 end if;
22017 -- An abstract state without a visible refinement matches
22018 -- itself.
22020 elsif Is_Entity_Name (Ref_Item)
22021 and then Entity_Of (Ref_Item) = Dep_Item_Id
22022 then
22023 Record_Item (Dep_Item_Id);
22024 Matched := True;
22025 end if;
22027 -- A formal parameter or a variable matches itself
22029 elsif Is_Entity_Name (Ref_Item)
22030 and then Entity_Of (Ref_Item) = Dep_Item_Id
22031 then
22032 Record_Item (Dep_Item_Id);
22033 Matched := True;
22034 end if;
22035 end if;
22036 end Match_Items;
22038 -----------------
22039 -- Record_Item --
22040 -----------------
22042 procedure Record_Item (Item_Id : Entity_Id) is
22043 begin
22044 if not Contains (Matched_Items, Item_Id) then
22045 Add_Item (Item_Id, Matched_Items);
22046 end if;
22047 end Record_Item;
22049 -- Local variables
22051 Clause_Matched : Boolean := False;
22052 Dummy : Boolean := False;
22053 Inputs_Match : Boolean;
22054 Next_Ref_Clause : Node_Id;
22055 Outputs_Match : Boolean;
22056 Ref_Clause : Node_Id;
22057 Ref_Input : Node_Id;
22058 Ref_Output : Node_Id;
22060 -- Start of processing for Check_Dependency_Clause
22062 begin
22063 -- Examine all refinement clauses and compare them against the
22064 -- dependence clause.
22066 Ref_Clause := First (Refinements);
22067 while Present (Ref_Clause) loop
22068 Next_Ref_Clause := Next (Ref_Clause);
22070 -- Obtain the attributes of the current refinement clause
22072 Ref_Input := Expression (Ref_Clause);
22073 Ref_Output := First (Choices (Ref_Clause));
22075 -- The current refinement clause matches the dependence clause
22076 -- when both outputs match and both inputs match. See routine
22077 -- Match_Items for all possible conformance scenarios.
22079 -- Depends Dep_Output => Dep_Input
22080 -- ^ ^
22081 -- match ? match ?
22082 -- v v
22083 -- Refined_Depends Ref_Output => Ref_Input
22085 Match_Items
22086 (Dep_Item => Dep_Input,
22087 Ref_Item => Ref_Input,
22088 Matched => Inputs_Match);
22090 Match_Items
22091 (Dep_Item => Dep_Output,
22092 Ref_Item => Ref_Output,
22093 Matched => Outputs_Match);
22095 -- An In_Out state clause may be matched against a refinement with
22096 -- a null input or null output as long as the non-null side of the
22097 -- relation contains a valid constituent of the In_Out_State.
22099 if Is_In_Out_State_Clause then
22101 -- Depends => (State => State)
22102 -- Refined_Depends => (null => Constit) -- OK
22104 if Inputs_Match
22105 and then not Outputs_Match
22106 and then Nkind (Ref_Output) = N_Null
22107 then
22108 Outputs_Match := True;
22109 end if;
22111 -- Depends => (State => State)
22112 -- Refined_Depends => (Constit => null) -- OK
22114 if not Inputs_Match
22115 and then Outputs_Match
22116 and then Nkind (Ref_Input) = N_Null
22117 then
22118 Inputs_Match := True;
22119 end if;
22120 end if;
22122 -- The current refinement clause is legally constructed following
22123 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
22124 -- the pool of candidates. The seach continues because a single
22125 -- dependence clause may have multiple matching refinements.
22127 if Inputs_Match and then Outputs_Match then
22128 Clause_Matched := True;
22129 Remove (Ref_Clause);
22130 end if;
22132 Ref_Clause := Next_Ref_Clause;
22133 end loop;
22135 -- Depending on the order or composition of refinement clauses, an
22136 -- In_Out state clause may not be directly refinable.
22138 -- Depends => ((Output, State) => (Input, State))
22139 -- Refined_State => (State => (Constit_1, Constit_2))
22140 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
22142 -- Matching normalized clause (State => State) fails because there is
22143 -- no direct refinement capable of satisfying this relation. Another
22144 -- similar case arises when clauses (Constit_1 => Input) and (Output
22145 -- => Constit_2) are matched first, leaving no candidates for clause
22146 -- (State => State). Both scenarios are legal as long as one of the
22147 -- previous clauses mentioned a valid constituent of State.
22149 if not Clause_Matched
22150 and then Is_In_Out_State_Clause
22151 and then
22152 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
22153 then
22154 Clause_Matched := True;
22155 end if;
22157 -- A clause where the input is an abstract state with visible null
22158 -- refinement is implicitly matched when the output has already been
22159 -- matched in a previous clause.
22161 -- Depends => (Output => State) -- implicitly OK
22162 -- Refined_State => (State => null)
22163 -- Refined_Depends => (Output => ...)
22165 if not Clause_Matched
22166 and then Is_Null_Refined_State (Dep_Input)
22167 and then Is_Entity_Name (Dep_Output)
22168 and then
22169 Contains (Matched_Items, Available_View (Entity_Of (Dep_Output)))
22170 then
22171 Clause_Matched := True;
22172 end if;
22174 -- A clause where the output is an abstract state with visible null
22175 -- refinement is implicitly matched when the input has already been
22176 -- matched in a previous clause.
22178 -- Depends => (State => Input) -- implicitly OK
22179 -- Refined_State => (State => null)
22180 -- Refined_Depends => (... => Input)
22182 if not Clause_Matched
22183 and then Is_Null_Refined_State (Dep_Output)
22184 and then Is_Entity_Name (Dep_Input)
22185 and then
22186 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
22187 then
22188 Clause_Matched := True;
22189 end if;
22191 -- At this point either all refinement clauses have been examined or
22192 -- pragma Refined_Depends contains a solitary null. Only an abstract
22193 -- state with null refinement can possibly match these cases.
22195 -- Depends => (State => null)
22196 -- Refined_State => (State => null)
22197 -- Refined_Depends => null -- OK
22199 if not Clause_Matched then
22200 Match_Items
22201 (Dep_Item => Dep_Input,
22202 Ref_Item => Empty,
22203 Matched => Inputs_Match);
22205 Match_Items
22206 (Dep_Item => Dep_Output,
22207 Ref_Item => Empty,
22208 Matched => Outputs_Match);
22210 Clause_Matched := Inputs_Match and Outputs_Match;
22211 end if;
22213 -- If the contents of Refined_Depends are legal, then the current
22214 -- dependence clause should be satisfied either by an explicit match
22215 -- or by one of the special cases.
22217 if not Clause_Matched then
22218 SPARK_Msg_NE
22219 ("dependence clause of subprogram & has no matching refinement "
22220 & "in body", Dep_Clause, Spec_Id);
22221 end if;
22222 end Check_Dependency_Clause;
22224 -------------------------
22225 -- Check_Output_States --
22226 -------------------------
22228 procedure Check_Output_States is
22229 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22230 -- Determine whether all constituents of state State_Id with visible
22231 -- refinement are used as outputs in pragma Refined_Depends. Emit an
22232 -- error if this is not the case.
22234 -----------------------------
22235 -- Check_Constituent_Usage --
22236 -----------------------------
22238 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22239 Constit_Elmt : Elmt_Id;
22240 Constit_Id : Entity_Id;
22241 Posted : Boolean := False;
22243 begin
22244 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22245 while Present (Constit_Elmt) loop
22246 Constit_Id := Node (Constit_Elmt);
22248 -- The constituent acts as an input (SPARK RM 7.2.5(3))
22250 if Present (Body_Inputs)
22251 and then Appears_In (Body_Inputs, Constit_Id)
22252 then
22253 Error_Msg_Name_1 := Chars (State_Id);
22254 SPARK_Msg_NE
22255 ("constituent & of state % must act as output in "
22256 & "dependence refinement", N, Constit_Id);
22258 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
22260 elsif No (Body_Outputs)
22261 or else not Appears_In (Body_Outputs, Constit_Id)
22262 then
22263 if not Posted then
22264 Posted := True;
22265 SPARK_Msg_NE
22266 ("output state & must be replaced by all its "
22267 & "constituents in dependence refinement",
22268 N, State_Id);
22269 end if;
22271 SPARK_Msg_NE
22272 ("\constituent & is missing in output list",
22273 N, Constit_Id);
22274 end if;
22276 Next_Elmt (Constit_Elmt);
22277 end loop;
22278 end Check_Constituent_Usage;
22280 -- Local variables
22282 Item : Node_Id;
22283 Item_Elmt : Elmt_Id;
22284 Item_Id : Entity_Id;
22286 -- Start of processing for Check_Output_States
22288 begin
22289 -- Inspect the outputs of pragma Depends looking for a state with a
22290 -- visible refinement.
22292 if Present (Spec_Outputs) then
22293 Item_Elmt := First_Elmt (Spec_Outputs);
22294 while Present (Item_Elmt) loop
22295 Item := Node (Item_Elmt);
22297 -- Deal with the mixed nature of the input and output lists
22299 if Nkind (Item) = N_Defining_Identifier then
22300 Item_Id := Item;
22301 else
22302 Item_Id := Available_View (Entity_Of (Item));
22303 end if;
22305 if Ekind (Item_Id) = E_Abstract_State then
22307 -- The state acts as an input-output, skip it
22309 if Present (Spec_Inputs)
22310 and then Appears_In (Spec_Inputs, Item_Id)
22311 then
22312 null;
22314 -- Ensure that all of the constituents are utilized as
22315 -- outputs in pragma Refined_Depends.
22317 elsif Has_Non_Null_Refinement (Item_Id) then
22318 Check_Constituent_Usage (Item_Id);
22319 end if;
22320 end if;
22322 Next_Elmt (Item_Elmt);
22323 end loop;
22324 end if;
22325 end Check_Output_States;
22327 -----------------------
22328 -- Normalize_Clauses --
22329 -----------------------
22331 procedure Normalize_Clauses (Clauses : List_Id) is
22332 procedure Normalize_Inputs (Clause : Node_Id);
22333 -- Normalize clause Clause by creating multiple clauses for each
22334 -- input item of Clause. It is assumed that Clause has exactly one
22335 -- output. The transformation is as follows:
22337 -- Output => (Input_1, Input_2) -- original
22339 -- Output => Input_1 -- normalizations
22340 -- Output => Input_2
22342 procedure Normalize_Outputs (Clause : Node_Id);
22343 -- Normalize clause Clause by creating multiple clause for each
22344 -- output item of Clause. The transformation is as follows:
22346 -- (Output_1, Output_2) => Input -- original
22348 -- Output_1 => Input -- normalization
22349 -- Output_2 => Input
22351 ----------------------
22352 -- Normalize_Inputs --
22353 ----------------------
22355 procedure Normalize_Inputs (Clause : Node_Id) is
22356 Inputs : constant Node_Id := Expression (Clause);
22357 Loc : constant Source_Ptr := Sloc (Clause);
22358 Output : constant List_Id := Choices (Clause);
22359 Last_Input : Node_Id;
22360 Input : Node_Id;
22361 New_Clause : Node_Id;
22362 Next_Input : Node_Id;
22364 begin
22365 -- Normalization is performed only when the original clause has
22366 -- more than one input. Multiple inputs appear as an aggregate.
22368 if Nkind (Inputs) = N_Aggregate then
22369 Last_Input := Last (Expressions (Inputs));
22371 -- Create a new clause for each input
22373 Input := First (Expressions (Inputs));
22374 while Present (Input) loop
22375 Next_Input := Next (Input);
22377 -- Unhook the current input from the original input list
22378 -- because it will be relocated to a new clause.
22380 Remove (Input);
22382 -- Special processing for the last input. At this point the
22383 -- original aggregate has been stripped down to one element.
22384 -- Replace the aggregate by the element itself.
22386 if Input = Last_Input then
22387 Rewrite (Inputs, Input);
22389 -- Generate a clause of the form:
22390 -- Output => Input
22392 else
22393 New_Clause :=
22394 Make_Component_Association (Loc,
22395 Choices => New_Copy_List_Tree (Output),
22396 Expression => Input);
22398 -- The new clause contains replicated content that has
22399 -- already been analyzed, mark the clause as analyzed.
22401 Set_Analyzed (New_Clause);
22402 Insert_After (Clause, New_Clause);
22403 end if;
22405 Input := Next_Input;
22406 end loop;
22407 end if;
22408 end Normalize_Inputs;
22410 -----------------------
22411 -- Normalize_Outputs --
22412 -----------------------
22414 procedure Normalize_Outputs (Clause : Node_Id) is
22415 Inputs : constant Node_Id := Expression (Clause);
22416 Loc : constant Source_Ptr := Sloc (Clause);
22417 Outputs : constant Node_Id := First (Choices (Clause));
22418 Last_Output : Node_Id;
22419 New_Clause : Node_Id;
22420 Next_Output : Node_Id;
22421 Output : Node_Id;
22423 begin
22424 -- Multiple outputs appear as an aggregate. Nothing to do when
22425 -- the clause has exactly one output.
22427 if Nkind (Outputs) = N_Aggregate then
22428 Last_Output := Last (Expressions (Outputs));
22430 -- Create a clause for each output. Note that each time a new
22431 -- clause is created, the original output list slowly shrinks
22432 -- until there is one item left.
22434 Output := First (Expressions (Outputs));
22435 while Present (Output) loop
22436 Next_Output := Next (Output);
22438 -- Unhook the output from the original output list as it
22439 -- will be relocated to a new clause.
22441 Remove (Output);
22443 -- Special processing for the last output. At this point
22444 -- the original aggregate has been stripped down to one
22445 -- element. Replace the aggregate by the element itself.
22447 if Output = Last_Output then
22448 Rewrite (Outputs, Output);
22450 else
22451 -- Generate a clause of the form:
22452 -- (Output => Inputs)
22454 New_Clause :=
22455 Make_Component_Association (Loc,
22456 Choices => New_List (Output),
22457 Expression => New_Copy_Tree (Inputs));
22459 -- The new clause contains replicated content that has
22460 -- already been analyzed. There is not need to reanalyze
22461 -- them.
22463 Set_Analyzed (New_Clause);
22464 Insert_After (Clause, New_Clause);
22465 end if;
22467 Output := Next_Output;
22468 end loop;
22469 end if;
22470 end Normalize_Outputs;
22472 -- Local variables
22474 Clause : Node_Id;
22476 -- Start of processing for Normalize_Clauses
22478 begin
22479 Clause := First (Clauses);
22480 while Present (Clause) loop
22481 Normalize_Outputs (Clause);
22482 Next (Clause);
22483 end loop;
22485 Clause := First (Clauses);
22486 while Present (Clause) loop
22487 Normalize_Inputs (Clause);
22488 Next (Clause);
22489 end loop;
22490 end Normalize_Clauses;
22492 --------------------------
22493 -- Report_Extra_Clauses --
22494 --------------------------
22496 procedure Report_Extra_Clauses is
22497 Clause : Node_Id;
22499 begin
22500 if Present (Refinements) then
22501 Clause := First (Refinements);
22502 while Present (Clause) loop
22504 -- Do not complain about a null input refinement, since a null
22505 -- input legitimately matches anything.
22507 if Nkind (Clause) /= N_Component_Association
22508 or else Nkind (Expression (Clause)) /= N_Null
22509 then
22510 SPARK_Msg_N
22511 ("unmatched or extra clause in dependence refinement",
22512 Clause);
22513 end if;
22515 Next (Clause);
22516 end loop;
22517 end if;
22518 end Report_Extra_Clauses;
22520 -- Local variables
22522 Body_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
22523 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
22524 Errors : constant Nat := Serious_Errors_Detected;
22525 Refs : constant Node_Id :=
22526 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
22527 Clause : Node_Id;
22528 Deps : Node_Id;
22529 Dummy : Boolean;
22531 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
22533 begin
22534 if Nkind (Body_Decl) = N_Subprogram_Body_Stub then
22535 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
22536 else
22537 Spec_Id := Corresponding_Spec (Body_Decl);
22538 end if;
22540 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
22542 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
22543 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
22545 if No (Depends) then
22546 SPARK_Msg_NE
22547 ("useless refinement, declaration of subprogram & lacks aspect or "
22548 & "pragma Depends", N, Spec_Id);
22549 return;
22550 end if;
22552 Deps := Get_Pragma_Arg (First (Pragma_Argument_Associations (Depends)));
22554 -- A null dependency relation renders the refinement useless because it
22555 -- cannot possibly mention abstract states with visible refinement. Note
22556 -- that the inverse is not true as states may be refined to null
22557 -- (SPARK RM 7.2.5(2)).
22559 if Nkind (Deps) = N_Null then
22560 SPARK_Msg_NE
22561 ("useless refinement, subprogram & does not depend on abstract "
22562 & "state with visible refinement", N, Spec_Id);
22563 return;
22564 end if;
22566 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
22567 -- This ensures that the categorization of all refined dependency items
22568 -- is consistent with their role.
22570 Analyze_Depends_In_Decl_Part (N);
22572 -- Do not match dependencies against refinements if Refined_Depends is
22573 -- illegal to avoid emitting misleading error.
22575 if Serious_Errors_Detected = Errors then
22577 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
22578 -- the inputs and outputs of the subprogram spec and body to verify
22579 -- the use of states with visible refinement and their constituents.
22581 if No (Get_Pragma (Spec_Id, Pragma_Global))
22582 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
22583 then
22584 Collect_Subprogram_Inputs_Outputs
22585 (Subp_Id => Spec_Id,
22586 Synthesize => True,
22587 Subp_Inputs => Spec_Inputs,
22588 Subp_Outputs => Spec_Outputs,
22589 Global_Seen => Dummy);
22591 Collect_Subprogram_Inputs_Outputs
22592 (Subp_Id => Body_Id,
22593 Synthesize => True,
22594 Subp_Inputs => Body_Inputs,
22595 Subp_Outputs => Body_Outputs,
22596 Global_Seen => Dummy);
22598 -- For an output state with a visible refinement, ensure that all
22599 -- constituents appear as outputs in the dependency refinement.
22601 Check_Output_States;
22602 end if;
22604 -- Matching is disabled in ASIS because clauses are not normalized as
22605 -- this is a tree altering activity similar to expansion.
22607 if ASIS_Mode then
22608 return;
22609 end if;
22611 -- Multiple dependency clauses appear as component associations of an
22612 -- aggregate. Note that the clauses are copied because the algorithm
22613 -- modifies them and this should not be visible in Depends.
22615 pragma Assert (Nkind (Deps) = N_Aggregate);
22616 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
22617 Normalize_Clauses (Dependencies);
22619 if Nkind (Refs) = N_Null then
22620 Refinements := No_List;
22622 -- Multiple dependency clauses appear as component associations of an
22623 -- aggregate. Note that the clauses are copied because the algorithm
22624 -- modifies them and this should not be visible in Refined_Depends.
22626 else pragma Assert (Nkind (Refs) = N_Aggregate);
22627 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
22628 Normalize_Clauses (Refinements);
22629 end if;
22631 -- At this point the clauses of pragmas Depends and Refined_Depends
22632 -- have been normalized into simple dependencies between one output
22633 -- and one input. Examine all clauses of pragma Depends looking for
22634 -- matching clauses in pragma Refined_Depends.
22636 Clause := First (Dependencies);
22637 while Present (Clause) loop
22638 Check_Dependency_Clause (Clause);
22639 Next (Clause);
22640 end loop;
22642 if Serious_Errors_Detected = Errors then
22643 Report_Extra_Clauses;
22644 end if;
22645 end if;
22646 end Analyze_Refined_Depends_In_Decl_Part;
22648 -----------------------------------------
22649 -- Analyze_Refined_Global_In_Decl_Part --
22650 -----------------------------------------
22652 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
22653 Global : Node_Id;
22654 -- The corresponding Global pragma
22656 Has_In_State : Boolean := False;
22657 Has_In_Out_State : Boolean := False;
22658 Has_Out_State : Boolean := False;
22659 Has_Proof_In_State : Boolean := False;
22660 -- These flags are set when the corresponding Global pragma has a state
22661 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
22662 -- refinement.
22664 Has_Null_State : Boolean := False;
22665 -- This flag is set when the corresponding Global pragma has at least
22666 -- one state with a null refinement.
22668 In_Constits : Elist_Id := No_Elist;
22669 In_Out_Constits : Elist_Id := No_Elist;
22670 Out_Constits : Elist_Id := No_Elist;
22671 Proof_In_Constits : Elist_Id := No_Elist;
22672 -- These lists contain the entities of all Input, In_Out, Output and
22673 -- Proof_In constituents that appear in Refined_Global and participate
22674 -- in state refinement.
22676 In_Items : Elist_Id := No_Elist;
22677 In_Out_Items : Elist_Id := No_Elist;
22678 Out_Items : Elist_Id := No_Elist;
22679 Proof_In_Items : Elist_Id := No_Elist;
22680 -- These list contain the entities of all Input, In_Out, Output and
22681 -- Proof_In items defined in the corresponding Global pragma.
22683 procedure Check_In_Out_States;
22684 -- Determine whether the corresponding Global pragma mentions In_Out
22685 -- states with visible refinement and if so, ensure that one of the
22686 -- following completions apply to the constituents of the state:
22687 -- 1) there is at least one constituent of mode In_Out
22688 -- 2) there is at least one Input and one Output constituent
22689 -- 3) not all constituents are present and one of them is of mode
22690 -- Output.
22691 -- This routine may remove elements from In_Constits, In_Out_Constits,
22692 -- Out_Constits and Proof_In_Constits.
22694 procedure Check_Input_States;
22695 -- Determine whether the corresponding Global pragma mentions Input
22696 -- states with visible refinement and if so, ensure that at least one of
22697 -- its constituents appears as an Input item in Refined_Global.
22698 -- This routine may remove elements from In_Constits, In_Out_Constits,
22699 -- Out_Constits and Proof_In_Constits.
22701 procedure Check_Output_States;
22702 -- Determine whether the corresponding Global pragma mentions Output
22703 -- states with visible refinement and if so, ensure that all of its
22704 -- constituents appear as Output items in Refined_Global.
22705 -- This routine may remove elements from In_Constits, In_Out_Constits,
22706 -- Out_Constits and Proof_In_Constits.
22708 procedure Check_Proof_In_States;
22709 -- Determine whether the corresponding Global pragma mentions Proof_In
22710 -- states with visible refinement and if so, ensure that at least one of
22711 -- its constituents appears as a Proof_In item in Refined_Global.
22712 -- This routine may remove elements from In_Constits, In_Out_Constits,
22713 -- Out_Constits and Proof_In_Constits.
22715 procedure Check_Refined_Global_List
22716 (List : Node_Id;
22717 Global_Mode : Name_Id := Name_Input);
22718 -- Verify the legality of a single global list declaration. Global_Mode
22719 -- denotes the current mode in effect.
22721 procedure Collect_Global_Items (Prag : Node_Id);
22722 -- Gather all input, in out, output and Proof_In items of pragma Prag
22723 -- in lists In_Items, In_Out_Items, Out_Items and Proof_In_Items. Flags
22724 -- Has_In_State, Has_In_Out_State, Has_Out_State and Has_Proof_In_State
22725 -- are set when there is at least one abstract state with visible
22726 -- refinement available in the corresponding mode. Flag Has_Null_State
22727 -- is set when at least state has a null refinement.
22729 function Present_Then_Remove
22730 (List : Elist_Id;
22731 Item : Entity_Id) return Boolean;
22732 -- Search List for a particular entity Item. If Item has been found,
22733 -- remove it from List. This routine is used to strip lists In_Constits,
22734 -- In_Out_Constits and Out_Constits of valid constituents.
22736 procedure Report_Extra_Constituents;
22737 -- Emit an error for each constituent found in lists In_Constits,
22738 -- In_Out_Constits and Out_Constits.
22740 -------------------------
22741 -- Check_In_Out_States --
22742 -------------------------
22744 procedure Check_In_Out_States is
22745 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22746 -- Determine whether one of the following coverage scenarios is in
22747 -- effect:
22748 -- 1) there is at least one constituent of mode In_Out
22749 -- 2) there is at least one Input and one Output constituent
22750 -- 3) not all constituents are present and one of them is of mode
22751 -- Output.
22752 -- If this is not the case, emit an error.
22754 -----------------------------
22755 -- Check_Constituent_Usage --
22756 -----------------------------
22758 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22759 Constit_Elmt : Elmt_Id;
22760 Constit_Id : Entity_Id;
22761 Has_Missing : Boolean := False;
22762 In_Out_Seen : Boolean := False;
22763 In_Seen : Boolean := False;
22764 Out_Seen : Boolean := False;
22766 begin
22767 -- Process all the constituents of the state and note their modes
22768 -- within the global refinement.
22770 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22771 while Present (Constit_Elmt) loop
22772 Constit_Id := Node (Constit_Elmt);
22774 if Present_Then_Remove (In_Constits, Constit_Id) then
22775 In_Seen := True;
22777 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
22778 In_Out_Seen := True;
22780 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
22781 Out_Seen := True;
22783 -- A Proof_In constituent cannot participate in the completion
22784 -- of an Output state (SPARK RM 7.2.4(5)).
22786 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id) then
22787 Error_Msg_Name_1 := Chars (State_Id);
22788 SPARK_Msg_NE
22789 ("constituent & of state % must have mode Input, In_Out "
22790 & "or Output in global refinement",
22791 N, Constit_Id);
22793 else
22794 Has_Missing := True;
22795 end if;
22797 Next_Elmt (Constit_Elmt);
22798 end loop;
22800 -- A single In_Out constituent is a valid completion
22802 if In_Out_Seen then
22803 null;
22805 -- A pair of one Input and one Output constituent is a valid
22806 -- completion.
22808 elsif In_Seen and then Out_Seen then
22809 null;
22811 -- A single Output constituent is a valid completion only when
22812 -- some of the other constituents are missing (SPARK RM 7.2.4(5)).
22814 elsif Has_Missing and then Out_Seen then
22815 null;
22817 else
22818 SPARK_Msg_NE
22819 ("global refinement of state & redefines the mode of its "
22820 & "constituents", N, State_Id);
22821 end if;
22822 end Check_Constituent_Usage;
22824 -- Local variables
22826 Item_Elmt : Elmt_Id;
22827 Item_Id : Entity_Id;
22829 -- Start of processing for Check_In_Out_States
22831 begin
22832 -- Inspect the In_Out items of the corresponding Global pragma
22833 -- looking for a state with a visible refinement.
22835 if Has_In_Out_State and then Present (In_Out_Items) then
22836 Item_Elmt := First_Elmt (In_Out_Items);
22837 while Present (Item_Elmt) loop
22838 Item_Id := Node (Item_Elmt);
22840 -- Ensure that one of the three coverage variants is satisfied
22842 if Ekind (Item_Id) = E_Abstract_State
22843 and then Has_Non_Null_Refinement (Item_Id)
22844 then
22845 Check_Constituent_Usage (Item_Id);
22846 end if;
22848 Next_Elmt (Item_Elmt);
22849 end loop;
22850 end if;
22851 end Check_In_Out_States;
22853 ------------------------
22854 -- Check_Input_States --
22855 ------------------------
22857 procedure Check_Input_States is
22858 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22859 -- Determine whether at least one constituent of state State_Id with
22860 -- visible refinement is used and has mode Input. Ensure that the
22861 -- remaining constituents do not have In_Out, Output or Proof_In
22862 -- modes.
22864 -----------------------------
22865 -- Check_Constituent_Usage --
22866 -----------------------------
22868 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22869 Constit_Elmt : Elmt_Id;
22870 Constit_Id : Entity_Id;
22871 In_Seen : Boolean := False;
22873 begin
22874 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22875 while Present (Constit_Elmt) loop
22876 Constit_Id := Node (Constit_Elmt);
22878 -- At least one of the constituents appears as an Input
22880 if Present_Then_Remove (In_Constits, Constit_Id) then
22881 In_Seen := True;
22883 -- The constituent appears in the global refinement, but has
22884 -- mode In_Out, Output or Proof_In (SPARK RM 7.2.4(5)).
22886 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
22887 or else Present_Then_Remove (Out_Constits, Constit_Id)
22888 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
22889 then
22890 Error_Msg_Name_1 := Chars (State_Id);
22891 SPARK_Msg_NE
22892 ("constituent & of state % must have mode Input in global "
22893 & "refinement", N, Constit_Id);
22894 end if;
22896 Next_Elmt (Constit_Elmt);
22897 end loop;
22899 -- Not one of the constituents appeared as Input
22901 if not In_Seen then
22902 SPARK_Msg_NE
22903 ("global refinement of state & must include at least one "
22904 & "constituent of mode Input", N, State_Id);
22905 end if;
22906 end Check_Constituent_Usage;
22908 -- Local variables
22910 Item_Elmt : Elmt_Id;
22911 Item_Id : Entity_Id;
22913 -- Start of processing for Check_Input_States
22915 begin
22916 -- Inspect the Input items of the corresponding Global pragma
22917 -- looking for a state with a visible refinement.
22919 if Has_In_State and then Present (In_Items) then
22920 Item_Elmt := First_Elmt (In_Items);
22921 while Present (Item_Elmt) loop
22922 Item_Id := Node (Item_Elmt);
22924 -- Ensure that at least one of the constituents is utilized and
22925 -- is of mode Input.
22927 if Ekind (Item_Id) = E_Abstract_State
22928 and then Has_Non_Null_Refinement (Item_Id)
22929 then
22930 Check_Constituent_Usage (Item_Id);
22931 end if;
22933 Next_Elmt (Item_Elmt);
22934 end loop;
22935 end if;
22936 end Check_Input_States;
22938 -------------------------
22939 -- Check_Output_States --
22940 -------------------------
22942 procedure Check_Output_States is
22943 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22944 -- Determine whether all constituents of state State_Id with visible
22945 -- refinement are used and have mode Output. Emit an error if this is
22946 -- not the case.
22948 -----------------------------
22949 -- Check_Constituent_Usage --
22950 -----------------------------
22952 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22953 Constit_Elmt : Elmt_Id;
22954 Constit_Id : Entity_Id;
22955 Posted : Boolean := False;
22957 begin
22958 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22959 while Present (Constit_Elmt) loop
22960 Constit_Id := Node (Constit_Elmt);
22962 if Present_Then_Remove (Out_Constits, Constit_Id) then
22963 null;
22965 -- The constituent appears in the global refinement, but has
22966 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
22968 elsif Present_Then_Remove (In_Constits, Constit_Id)
22969 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
22970 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
22971 then
22972 Error_Msg_Name_1 := Chars (State_Id);
22973 SPARK_Msg_NE
22974 ("constituent & of state % must have mode Output in "
22975 & "global refinement", N, Constit_Id);
22977 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
22979 else
22980 if not Posted then
22981 Posted := True;
22982 SPARK_Msg_NE
22983 ("output state & must be replaced by all its "
22984 & "constituents in global refinement", N, State_Id);
22985 end if;
22987 SPARK_Msg_NE
22988 ("\constituent & is missing in output list",
22989 N, Constit_Id);
22990 end if;
22992 Next_Elmt (Constit_Elmt);
22993 end loop;
22994 end Check_Constituent_Usage;
22996 -- Local variables
22998 Item_Elmt : Elmt_Id;
22999 Item_Id : Entity_Id;
23001 -- Start of processing for Check_Output_States
23003 begin
23004 -- Inspect the Output items of the corresponding Global pragma
23005 -- looking for a state with a visible refinement.
23007 if Has_Out_State and then Present (Out_Items) then
23008 Item_Elmt := First_Elmt (Out_Items);
23009 while Present (Item_Elmt) loop
23010 Item_Id := Node (Item_Elmt);
23012 -- Ensure that all of the constituents are utilized and they
23013 -- have mode Output.
23015 if Ekind (Item_Id) = E_Abstract_State
23016 and then Has_Non_Null_Refinement (Item_Id)
23017 then
23018 Check_Constituent_Usage (Item_Id);
23019 end if;
23021 Next_Elmt (Item_Elmt);
23022 end loop;
23023 end if;
23024 end Check_Output_States;
23026 ---------------------------
23027 -- Check_Proof_In_States --
23028 ---------------------------
23030 procedure Check_Proof_In_States is
23031 procedure Check_Constituent_Usage (State_Id : Entity_Id);
23032 -- Determine whether at least one constituent of state State_Id with
23033 -- visible refinement is used and has mode Proof_In. Ensure that the
23034 -- remaining constituents do not have Input, In_Out or Output modes.
23036 -----------------------------
23037 -- Check_Constituent_Usage --
23038 -----------------------------
23040 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
23041 Constit_Elmt : Elmt_Id;
23042 Constit_Id : Entity_Id;
23043 Proof_In_Seen : Boolean := False;
23045 begin
23046 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
23047 while Present (Constit_Elmt) loop
23048 Constit_Id := Node (Constit_Elmt);
23050 -- At least one of the constituents appears as Proof_In
23052 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
23053 Proof_In_Seen := True;
23055 -- The constituent appears in the global refinement, but has
23056 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
23058 elsif Present_Then_Remove (In_Constits, Constit_Id)
23059 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
23060 or else Present_Then_Remove (Out_Constits, Constit_Id)
23061 then
23062 Error_Msg_Name_1 := Chars (State_Id);
23063 SPARK_Msg_NE
23064 ("constituent & of state % must have mode Proof_In in "
23065 & "global refinement", N, Constit_Id);
23066 end if;
23068 Next_Elmt (Constit_Elmt);
23069 end loop;
23071 -- Not one of the constituents appeared as Proof_In
23073 if not Proof_In_Seen then
23074 SPARK_Msg_NE
23075 ("global refinement of state & must include at least one "
23076 & "constituent of mode Proof_In", N, State_Id);
23077 end if;
23078 end Check_Constituent_Usage;
23080 -- Local variables
23082 Item_Elmt : Elmt_Id;
23083 Item_Id : Entity_Id;
23085 -- Start of processing for Check_Proof_In_States
23087 begin
23088 -- Inspect the Proof_In items of the corresponding Global pragma
23089 -- looking for a state with a visible refinement.
23091 if Has_Proof_In_State and then Present (Proof_In_Items) then
23092 Item_Elmt := First_Elmt (Proof_In_Items);
23093 while Present (Item_Elmt) loop
23094 Item_Id := Node (Item_Elmt);
23096 -- Ensure that at least one of the constituents is utilized and
23097 -- is of mode Proof_In
23099 if Ekind (Item_Id) = E_Abstract_State
23100 and then Has_Non_Null_Refinement (Item_Id)
23101 then
23102 Check_Constituent_Usage (Item_Id);
23103 end if;
23105 Next_Elmt (Item_Elmt);
23106 end loop;
23107 end if;
23108 end Check_Proof_In_States;
23110 -------------------------------
23111 -- Check_Refined_Global_List --
23112 -------------------------------
23114 procedure Check_Refined_Global_List
23115 (List : Node_Id;
23116 Global_Mode : Name_Id := Name_Input)
23118 procedure Check_Refined_Global_Item
23119 (Item : Node_Id;
23120 Global_Mode : Name_Id);
23121 -- Verify the legality of a single global item declaration. Parameter
23122 -- Global_Mode denotes the current mode in effect.
23124 -------------------------------
23125 -- Check_Refined_Global_Item --
23126 -------------------------------
23128 procedure Check_Refined_Global_Item
23129 (Item : Node_Id;
23130 Global_Mode : Name_Id)
23132 Item_Id : constant Entity_Id := Entity_Of (Item);
23134 procedure Inconsistent_Mode_Error (Expect : Name_Id);
23135 -- Issue a common error message for all mode mismatches. Expect
23136 -- denotes the expected mode.
23138 -----------------------------
23139 -- Inconsistent_Mode_Error --
23140 -----------------------------
23142 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
23143 begin
23144 SPARK_Msg_NE
23145 ("global item & has inconsistent modes", Item, Item_Id);
23147 Error_Msg_Name_1 := Global_Mode;
23148 Error_Msg_Name_2 := Expect;
23149 SPARK_Msg_N ("\expected mode %, found mode %", Item);
23150 end Inconsistent_Mode_Error;
23152 -- Start of processing for Check_Refined_Global_Item
23154 begin
23155 -- When the state or variable acts as a constituent of another
23156 -- state with a visible refinement, collect it for the state
23157 -- completeness checks performed later on.
23159 if Present (Encapsulating_State (Item_Id))
23160 and then Has_Visible_Refinement (Encapsulating_State (Item_Id))
23161 then
23162 if Global_Mode = Name_Input then
23163 Add_Item (Item_Id, In_Constits);
23165 elsif Global_Mode = Name_In_Out then
23166 Add_Item (Item_Id, In_Out_Constits);
23168 elsif Global_Mode = Name_Output then
23169 Add_Item (Item_Id, Out_Constits);
23171 elsif Global_Mode = Name_Proof_In then
23172 Add_Item (Item_Id, Proof_In_Constits);
23173 end if;
23175 -- When not a constituent, ensure that both occurrences of the
23176 -- item in pragmas Global and Refined_Global match.
23178 elsif Contains (In_Items, Item_Id) then
23179 if Global_Mode /= Name_Input then
23180 Inconsistent_Mode_Error (Name_Input);
23181 end if;
23183 elsif Contains (In_Out_Items, Item_Id) then
23184 if Global_Mode /= Name_In_Out then
23185 Inconsistent_Mode_Error (Name_In_Out);
23186 end if;
23188 elsif Contains (Out_Items, Item_Id) then
23189 if Global_Mode /= Name_Output then
23190 Inconsistent_Mode_Error (Name_Output);
23191 end if;
23193 elsif Contains (Proof_In_Items, Item_Id) then
23194 null;
23196 -- The item does not appear in the corresponding Global pragma,
23197 -- it must be an extra (SPARK RM 7.2.4(3)).
23199 else
23200 SPARK_Msg_NE ("extra global item &", Item, Item_Id);
23201 end if;
23202 end Check_Refined_Global_Item;
23204 -- Local variables
23206 Item : Node_Id;
23208 -- Start of processing for Check_Refined_Global_List
23210 begin
23211 if Nkind (List) = N_Null then
23212 null;
23214 -- Single global item declaration
23216 elsif Nkind_In (List, N_Expanded_Name,
23217 N_Identifier,
23218 N_Selected_Component)
23219 then
23220 Check_Refined_Global_Item (List, Global_Mode);
23222 -- Simple global list or moded global list declaration
23224 elsif Nkind (List) = N_Aggregate then
23226 -- The declaration of a simple global list appear as a collection
23227 -- of expressions.
23229 if Present (Expressions (List)) then
23230 Item := First (Expressions (List));
23231 while Present (Item) loop
23232 Check_Refined_Global_Item (Item, Global_Mode);
23234 Next (Item);
23235 end loop;
23237 -- The declaration of a moded global list appears as a collection
23238 -- of component associations where individual choices denote
23239 -- modes.
23241 elsif Present (Component_Associations (List)) then
23242 Item := First (Component_Associations (List));
23243 while Present (Item) loop
23244 Check_Refined_Global_List
23245 (List => Expression (Item),
23246 Global_Mode => Chars (First (Choices (Item))));
23248 Next (Item);
23249 end loop;
23251 -- Invalid tree
23253 else
23254 raise Program_Error;
23255 end if;
23257 -- Invalid list
23259 else
23260 raise Program_Error;
23261 end if;
23262 end Check_Refined_Global_List;
23264 --------------------------
23265 -- Collect_Global_Items --
23266 --------------------------
23268 procedure Collect_Global_Items (Prag : Node_Id) is
23269 procedure Process_Global_List
23270 (List : Node_Id;
23271 Mode : Name_Id := Name_Input);
23272 -- Collect all items housed in a global list. Formal Mode denotes the
23273 -- current mode in effect.
23275 -------------------------
23276 -- Process_Global_List --
23277 -------------------------
23279 procedure Process_Global_List
23280 (List : Node_Id;
23281 Mode : Name_Id := Name_Input)
23283 procedure Process_Global_Item (Item : Node_Id; Mode : Name_Id);
23284 -- Add a single item to the appropriate list. Formal Mode denotes
23285 -- the current mode in effect.
23287 -------------------------
23288 -- Process_Global_Item --
23289 -------------------------
23291 procedure Process_Global_Item (Item : Node_Id; Mode : Name_Id) is
23292 Item_Id : constant Entity_Id :=
23293 Available_View (Entity_Of (Item));
23294 -- The above handles abstract views of variables and states
23295 -- built for limited with clauses.
23297 begin
23298 -- Signal that the global list contains at least one abstract
23299 -- state with a visible refinement. Note that the refinement
23300 -- may be null in which case there are no constituents.
23302 if Ekind (Item_Id) = E_Abstract_State then
23303 if Has_Null_Refinement (Item_Id) then
23304 Has_Null_State := True;
23306 elsif Has_Non_Null_Refinement (Item_Id) then
23307 if Mode = Name_Input then
23308 Has_In_State := True;
23309 elsif Mode = Name_In_Out then
23310 Has_In_Out_State := True;
23311 elsif Mode = Name_Output then
23312 Has_Out_State := True;
23313 elsif Mode = Name_Proof_In then
23314 Has_Proof_In_State := True;
23315 end if;
23316 end if;
23317 end if;
23319 -- Add the item to the proper list
23321 if Mode = Name_Input then
23322 Add_Item (Item_Id, In_Items);
23323 elsif Mode = Name_In_Out then
23324 Add_Item (Item_Id, In_Out_Items);
23325 elsif Mode = Name_Output then
23326 Add_Item (Item_Id, Out_Items);
23327 elsif Mode = Name_Proof_In then
23328 Add_Item (Item_Id, Proof_In_Items);
23329 end if;
23330 end Process_Global_Item;
23332 -- Local variables
23334 Item : Node_Id;
23336 -- Start of processing for Process_Global_List
23338 begin
23339 if Nkind (List) = N_Null then
23340 null;
23342 -- Single global item declaration
23344 elsif Nkind_In (List, N_Expanded_Name,
23345 N_Identifier,
23346 N_Selected_Component)
23347 then
23348 Process_Global_Item (List, Mode);
23350 -- Single global list or moded global list declaration
23352 elsif Nkind (List) = N_Aggregate then
23354 -- The declaration of a simple global list appear as a
23355 -- collection of expressions.
23357 if Present (Expressions (List)) then
23358 Item := First (Expressions (List));
23359 while Present (Item) loop
23360 Process_Global_Item (Item, Mode);
23361 Next (Item);
23362 end loop;
23364 -- The declaration of a moded global list appears as a
23365 -- collection of component associations where individual
23366 -- choices denote mode.
23368 elsif Present (Component_Associations (List)) then
23369 Item := First (Component_Associations (List));
23370 while Present (Item) loop
23371 Process_Global_List
23372 (List => Expression (Item),
23373 Mode => Chars (First (Choices (Item))));
23375 Next (Item);
23376 end loop;
23378 -- Invalid tree
23380 else
23381 raise Program_Error;
23382 end if;
23384 -- To accomodate partial decoration of disabled SPARK features,
23385 -- this routine may be called with illegal input. If this is the
23386 -- case, do not raise Program_Error.
23388 else
23389 null;
23390 end if;
23391 end Process_Global_List;
23393 -- Start of processing for Collect_Global_Items
23395 begin
23396 Process_Global_List
23397 (Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag))));
23398 end Collect_Global_Items;
23400 -------------------------
23401 -- Present_Then_Remove --
23402 -------------------------
23404 function Present_Then_Remove
23405 (List : Elist_Id;
23406 Item : Entity_Id) return Boolean
23408 Elmt : Elmt_Id;
23410 begin
23411 if Present (List) then
23412 Elmt := First_Elmt (List);
23413 while Present (Elmt) loop
23414 if Node (Elmt) = Item then
23415 Remove_Elmt (List, Elmt);
23416 return True;
23417 end if;
23419 Next_Elmt (Elmt);
23420 end loop;
23421 end if;
23423 return False;
23424 end Present_Then_Remove;
23426 -------------------------------
23427 -- Report_Extra_Constituents --
23428 -------------------------------
23430 procedure Report_Extra_Constituents is
23431 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
23432 -- Emit an error for every element of List
23434 ---------------------------------------
23435 -- Report_Extra_Constituents_In_List --
23436 ---------------------------------------
23438 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
23439 Constit_Elmt : Elmt_Id;
23441 begin
23442 if Present (List) then
23443 Constit_Elmt := First_Elmt (List);
23444 while Present (Constit_Elmt) loop
23445 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
23446 Next_Elmt (Constit_Elmt);
23447 end loop;
23448 end if;
23449 end Report_Extra_Constituents_In_List;
23451 -- Start of processing for Report_Extra_Constituents
23453 begin
23454 Report_Extra_Constituents_In_List (In_Constits);
23455 Report_Extra_Constituents_In_List (In_Out_Constits);
23456 Report_Extra_Constituents_In_List (Out_Constits);
23457 Report_Extra_Constituents_In_List (Proof_In_Constits);
23458 end Report_Extra_Constituents;
23460 -- Local variables
23462 Body_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
23463 Errors : constant Nat := Serious_Errors_Detected;
23464 Items : constant Node_Id :=
23465 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
23466 Spec_Id : Entity_Id;
23468 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
23470 begin
23471 if Nkind (Body_Decl) = N_Subprogram_Body_Stub then
23472 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
23473 else
23474 Spec_Id := Corresponding_Spec (Body_Decl);
23475 end if;
23477 Global := Get_Pragma (Spec_Id, Pragma_Global);
23479 -- The subprogram declaration lacks pragma Global. This renders
23480 -- Refined_Global useless as there is nothing to refine.
23482 if No (Global) then
23483 SPARK_Msg_NE
23484 ("useless refinement, declaration of subprogram & lacks aspect or "
23485 & "pragma Global", N, Spec_Id);
23486 return;
23487 end if;
23489 -- Extract all relevant items from the corresponding Global pragma
23491 Collect_Global_Items (Global);
23493 -- Corresponding Global pragma must mention at least one state witha
23494 -- visible refinement at the point Refined_Global is processed. States
23495 -- with null refinements need Refined_Global pragma (SPARK RM 7.2.4(2)).
23497 if not Has_In_State
23498 and then not Has_In_Out_State
23499 and then not Has_Out_State
23500 and then not Has_Proof_In_State
23501 and then not Has_Null_State
23502 then
23503 SPARK_Msg_NE
23504 ("useless refinement, subprogram & does not depend on abstract "
23505 & "state with visible refinement", N, Spec_Id);
23506 return;
23507 end if;
23509 -- The global refinement of inputs and outputs cannot be null when the
23510 -- corresponding Global pragma contains at least one item except in the
23511 -- case where we have states with null refinements.
23513 if Nkind (Items) = N_Null
23514 and then
23515 (Present (In_Items)
23516 or else Present (In_Out_Items)
23517 or else Present (Out_Items)
23518 or else Present (Proof_In_Items))
23519 and then not Has_Null_State
23520 then
23521 SPARK_Msg_NE
23522 ("refinement cannot be null, subprogram & has global items",
23523 N, Spec_Id);
23524 return;
23525 end if;
23527 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
23528 -- This ensures that the categorization of all refined global items is
23529 -- consistent with their role.
23531 Analyze_Global_In_Decl_Part (N);
23533 -- Perform all refinement checks with respect to completeness and mode
23534 -- matching.
23536 if Serious_Errors_Detected = Errors then
23537 Check_Refined_Global_List (Items);
23538 end if;
23540 -- For Input states with visible refinement, at least one constituent
23541 -- must be used as an Input in the global refinement.
23543 if Serious_Errors_Detected = Errors then
23544 Check_Input_States;
23545 end if;
23547 -- Verify all possible completion variants for In_Out states with
23548 -- visible refinement.
23550 if Serious_Errors_Detected = Errors then
23551 Check_In_Out_States;
23552 end if;
23554 -- For Output states with visible refinement, all constituents must be
23555 -- used as Outputs in the global refinement.
23557 if Serious_Errors_Detected = Errors then
23558 Check_Output_States;
23559 end if;
23561 -- For Proof_In states with visible refinement, at least one constituent
23562 -- must be used as Proof_In in the global refinement.
23564 if Serious_Errors_Detected = Errors then
23565 Check_Proof_In_States;
23566 end if;
23568 -- Emit errors for all constituents that belong to other states with
23569 -- visible refinement that do not appear in Global.
23571 if Serious_Errors_Detected = Errors then
23572 Report_Extra_Constituents;
23573 end if;
23574 end Analyze_Refined_Global_In_Decl_Part;
23576 ----------------------------------------
23577 -- Analyze_Refined_State_In_Decl_Part --
23578 ----------------------------------------
23580 procedure Analyze_Refined_State_In_Decl_Part (N : Node_Id) is
23581 Available_States : Elist_Id := No_Elist;
23582 -- A list of all abstract states defined in the package declaration that
23583 -- are available for refinement. The list is used to report unrefined
23584 -- states.
23586 Body_Id : Entity_Id;
23587 -- The body entity of the package subject to pragma Refined_State
23589 Body_States : Elist_Id := No_Elist;
23590 -- A list of all hidden states that appear in the body of the related
23591 -- package. The list is used to report unused hidden states.
23593 Constituents_Seen : Elist_Id := No_Elist;
23594 -- A list that contains all constituents processed so far. The list is
23595 -- used to detect multiple uses of the same constituent.
23597 Refined_States_Seen : Elist_Id := No_Elist;
23598 -- A list that contains all refined states processed so far. The list is
23599 -- used to detect duplicate refinements.
23601 Spec_Id : Entity_Id;
23602 -- The spec entity of the package subject to pragma Refined_State
23604 procedure Analyze_Refinement_Clause (Clause : Node_Id);
23605 -- Perform full analysis of a single refinement clause
23607 function Collect_Body_States (Pack_Id : Entity_Id) return Elist_Id;
23608 -- Gather the entities of all abstract states and variables declared in
23609 -- the body state space of package Pack_Id.
23611 procedure Report_Unrefined_States (States : Elist_Id);
23612 -- Emit errors for all unrefined abstract states found in list States
23614 procedure Report_Unused_States (States : Elist_Id);
23615 -- Emit errors for all unused states found in list States
23617 -------------------------------
23618 -- Analyze_Refinement_Clause --
23619 -------------------------------
23621 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
23622 AR_Constit : Entity_Id := Empty;
23623 AW_Constit : Entity_Id := Empty;
23624 ER_Constit : Entity_Id := Empty;
23625 EW_Constit : Entity_Id := Empty;
23626 -- The entities of external constituents that contain one of the
23627 -- following enabled properties: Async_Readers, Async_Writers,
23628 -- Effective_Reads and Effective_Writes.
23630 External_Constit_Seen : Boolean := False;
23631 -- Flag used to mark when at least one external constituent is part
23632 -- of the state refinement.
23634 Non_Null_Seen : Boolean := False;
23635 Null_Seen : Boolean := False;
23636 -- Flags used to detect multiple uses of null in a single clause or a
23637 -- mixture of null and non-null constituents.
23639 Part_Of_Constits : Elist_Id := No_Elist;
23640 -- A list of all candidate constituents subject to indicator Part_Of
23641 -- where the encapsulating state is the current state.
23643 State : Node_Id;
23644 State_Id : Entity_Id;
23645 -- The current state being refined
23647 procedure Analyze_Constituent (Constit : Node_Id);
23648 -- Perform full analysis of a single constituent
23650 procedure Check_External_Property
23651 (Prop_Nam : Name_Id;
23652 Enabled : Boolean;
23653 Constit : Entity_Id);
23654 -- Determine whether a property denoted by name Prop_Nam is present
23655 -- in both the refined state and constituent Constit. Flag Enabled
23656 -- should be set when the property applies to the refined state. If
23657 -- this is not the case, emit an error message.
23659 procedure Check_Matching_State;
23660 -- Determine whether the state being refined appears in list
23661 -- Available_States. Emit an error when attempting to re-refine the
23662 -- state or when the state is not defined in the package declaration,
23663 -- otherwise remove the state from Available_States.
23665 procedure Report_Unused_Constituents (Constits : Elist_Id);
23666 -- Emit errors for all unused Part_Of constituents in list Constits
23668 -------------------------
23669 -- Analyze_Constituent --
23670 -------------------------
23672 procedure Analyze_Constituent (Constit : Node_Id) is
23673 procedure Check_Ghost_Constituent (Constit_Id : Entity_Id);
23674 -- Verify that the constituent Constit_Id is a Ghost entity if the
23675 -- abstract state being refined is also Ghost. If this is the case
23676 -- verify that the Ghost policy in effect at the point of state
23677 -- and constituent declaration is the same.
23679 procedure Check_Matching_Constituent (Constit_Id : Entity_Id);
23680 -- Determine whether constituent Constit denoted by its entity
23681 -- Constit_Id appears in Hidden_States. Emit an error when the
23682 -- constituent is not a valid hidden state of the related package
23683 -- or when it is used more than once. Otherwise remove the
23684 -- constituent from Hidden_States.
23686 --------------------------------
23687 -- Check_Matching_Constituent --
23688 --------------------------------
23690 procedure Check_Matching_Constituent (Constit_Id : Entity_Id) is
23691 procedure Collect_Constituent;
23692 -- Add constituent Constit_Id to the refinements of State_Id
23694 -------------------------
23695 -- Collect_Constituent --
23696 -------------------------
23698 procedure Collect_Constituent is
23699 begin
23700 -- Add the constituent to the list of processed items to aid
23701 -- with the detection of duplicates.
23703 Add_Item (Constit_Id, Constituents_Seen);
23705 -- Collect the constituent in the list of refinement items
23706 -- and establish a relation between the refined state and
23707 -- the item.
23709 Append_Elmt (Constit_Id, Refinement_Constituents (State_Id));
23710 Set_Encapsulating_State (Constit_Id, State_Id);
23712 -- The state has at least one legal constituent, mark the
23713 -- start of the refinement region. The region ends when the
23714 -- body declarations end (see routine Analyze_Declarations).
23716 Set_Has_Visible_Refinement (State_Id);
23718 -- When the constituent is external, save its relevant
23719 -- property for further checks.
23721 if Async_Readers_Enabled (Constit_Id) then
23722 AR_Constit := Constit_Id;
23723 External_Constit_Seen := True;
23724 end if;
23726 if Async_Writers_Enabled (Constit_Id) then
23727 AW_Constit := Constit_Id;
23728 External_Constit_Seen := True;
23729 end if;
23731 if Effective_Reads_Enabled (Constit_Id) then
23732 ER_Constit := Constit_Id;
23733 External_Constit_Seen := True;
23734 end if;
23736 if Effective_Writes_Enabled (Constit_Id) then
23737 EW_Constit := Constit_Id;
23738 External_Constit_Seen := True;
23739 end if;
23740 end Collect_Constituent;
23742 -- Local variables
23744 State_Elmt : Elmt_Id;
23746 -- Start of processing for Check_Matching_Constituent
23748 begin
23749 -- Detect a duplicate use of a constituent
23751 if Contains (Constituents_Seen, Constit_Id) then
23752 SPARK_Msg_NE
23753 ("duplicate use of constituent &", Constit, Constit_Id);
23754 return;
23755 end if;
23757 -- The constituent is subject to a Part_Of indicator
23759 if Present (Encapsulating_State (Constit_Id)) then
23760 if Encapsulating_State (Constit_Id) = State_Id then
23761 Check_Ghost_Constituent (Constit_Id);
23762 Remove (Part_Of_Constits, Constit_Id);
23763 Collect_Constituent;
23765 -- The constituent is part of another state and is used
23766 -- incorrectly in the refinement of the current state.
23768 else
23769 Error_Msg_Name_1 := Chars (State_Id);
23770 SPARK_Msg_NE
23771 ("& cannot act as constituent of state %",
23772 Constit, Constit_Id);
23773 SPARK_Msg_NE
23774 ("\Part_Of indicator specifies & as encapsulating "
23775 & "state", Constit, Encapsulating_State (Constit_Id));
23776 end if;
23778 -- The only other source of legal constituents is the body
23779 -- state space of the related package.
23781 else
23782 if Present (Body_States) then
23783 State_Elmt := First_Elmt (Body_States);
23784 while Present (State_Elmt) loop
23786 -- Consume a valid constituent to signal that it has
23787 -- been encountered.
23789 if Node (State_Elmt) = Constit_Id then
23790 Check_Ghost_Constituent (Constit_Id);
23792 Remove_Elmt (Body_States, State_Elmt);
23793 Collect_Constituent;
23794 return;
23795 end if;
23797 Next_Elmt (State_Elmt);
23798 end loop;
23799 end if;
23801 -- If we get here, then the constituent is not a hidden
23802 -- state of the related package and may not be used in a
23803 -- refinement (SPARK RM 7.2.2(9)).
23805 Error_Msg_Name_1 := Chars (Spec_Id);
23806 SPARK_Msg_NE
23807 ("cannot use & in refinement, constituent is not a hidden "
23808 & "state of package %", Constit, Constit_Id);
23809 end if;
23810 end Check_Matching_Constituent;
23812 -----------------------------
23813 -- Check_Ghost_Constituent --
23814 -----------------------------
23816 procedure Check_Ghost_Constituent (Constit_Id : Entity_Id) is
23817 begin
23818 if Is_Ghost_Entity (State_Id) then
23819 if Is_Ghost_Entity (Constit_Id) then
23821 -- The Ghost policy in effect at the point of abstract
23822 -- state declaration and constituent must match
23823 -- (SPARK RM 6.9(16)).
23825 if Is_Checked_Ghost_Entity (State_Id)
23826 and then Is_Ignored_Ghost_Entity (Constit_Id)
23827 then
23828 Error_Msg_Sloc := Sloc (Constit);
23830 SPARK_Msg_N
23831 ("incompatible ghost policies in effect", State);
23832 SPARK_Msg_NE
23833 ("\abstract state & declared with ghost policy "
23834 & "Check", State, State_Id);
23835 SPARK_Msg_NE
23836 ("\constituent & declared # with ghost policy "
23837 & "Ignore", State, Constit_Id);
23839 elsif Is_Ignored_Ghost_Entity (State_Id)
23840 and then Is_Checked_Ghost_Entity (Constit_Id)
23841 then
23842 Error_Msg_Sloc := Sloc (Constit);
23844 SPARK_Msg_N
23845 ("incompatible ghost policies in effect", State);
23846 SPARK_Msg_NE
23847 ("\abstract state & declared with ghost policy "
23848 & "Ignore", State, State_Id);
23849 SPARK_Msg_NE
23850 ("\constituent & declared # with ghost policy "
23851 & "Check", State, Constit_Id);
23852 end if;
23854 -- A constituent of a Ghost abstract state must be a Ghost
23855 -- entity (SPARK RM 7.2.2(12)).
23857 else
23858 SPARK_Msg_NE
23859 ("constituent of ghost state & must be ghost",
23860 Constit, State_Id);
23861 end if;
23862 end if;
23863 end Check_Ghost_Constituent;
23865 -- Local variables
23867 Constit_Id : Entity_Id;
23869 -- Start of processing for Analyze_Constituent
23871 begin
23872 -- Detect multiple uses of null in a single refinement clause or a
23873 -- mixture of null and non-null constituents.
23875 if Nkind (Constit) = N_Null then
23876 if Null_Seen then
23877 SPARK_Msg_N
23878 ("multiple null constituents not allowed", Constit);
23880 elsif Non_Null_Seen then
23881 SPARK_Msg_N
23882 ("cannot mix null and non-null constituents", Constit);
23884 else
23885 Null_Seen := True;
23887 -- Collect the constituent in the list of refinement items
23889 Append_Elmt (Constit, Refinement_Constituents (State_Id));
23891 -- The state has at least one legal constituent, mark the
23892 -- start of the refinement region. The region ends when the
23893 -- body declarations end (see Analyze_Declarations).
23895 Set_Has_Visible_Refinement (State_Id);
23896 end if;
23898 -- Non-null constituents
23900 else
23901 Non_Null_Seen := True;
23903 if Null_Seen then
23904 SPARK_Msg_N
23905 ("cannot mix null and non-null constituents", Constit);
23906 end if;
23908 Analyze (Constit);
23909 Resolve_State (Constit);
23911 -- Ensure that the constituent denotes a valid state or a
23912 -- whole variable.
23914 if Is_Entity_Name (Constit) then
23915 Constit_Id := Entity_Of (Constit);
23917 if Ekind_In (Constit_Id, E_Abstract_State, E_Variable) then
23918 Check_Matching_Constituent (Constit_Id);
23920 else
23921 SPARK_Msg_NE
23922 ("constituent & must denote a variable or state (SPARK "
23923 & "RM 7.2.2(5))", Constit, Constit_Id);
23924 end if;
23926 -- The constituent is illegal
23928 else
23929 SPARK_Msg_N ("malformed constituent", Constit);
23930 end if;
23931 end if;
23932 end Analyze_Constituent;
23934 -----------------------------
23935 -- Check_External_Property --
23936 -----------------------------
23938 procedure Check_External_Property
23939 (Prop_Nam : Name_Id;
23940 Enabled : Boolean;
23941 Constit : Entity_Id)
23943 begin
23944 Error_Msg_Name_1 := Prop_Nam;
23946 -- The property is enabled in the related Abstract_State pragma
23947 -- that defines the state (SPARK RM 7.2.8(3)).
23949 if Enabled then
23950 if No (Constit) then
23951 SPARK_Msg_NE
23952 ("external state & requires at least one constituent with "
23953 & "property %", State, State_Id);
23954 end if;
23956 -- The property is missing in the declaration of the state, but
23957 -- a constituent is introducing it in the state refinement
23958 -- (SPARK RM 7.2.8(3)).
23960 elsif Present (Constit) then
23961 Error_Msg_Name_2 := Chars (Constit);
23962 SPARK_Msg_NE
23963 ("external state & lacks property % set by constituent %",
23964 State, State_Id);
23965 end if;
23966 end Check_External_Property;
23968 --------------------------
23969 -- Check_Matching_State --
23970 --------------------------
23972 procedure Check_Matching_State is
23973 State_Elmt : Elmt_Id;
23975 begin
23976 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
23978 if Contains (Refined_States_Seen, State_Id) then
23979 SPARK_Msg_NE
23980 ("duplicate refinement of state &", State, State_Id);
23981 return;
23982 end if;
23984 -- Inspect the abstract states defined in the package declaration
23985 -- looking for a match.
23987 State_Elmt := First_Elmt (Available_States);
23988 while Present (State_Elmt) loop
23990 -- A valid abstract state is being refined in the body. Add
23991 -- the state to the list of processed refined states to aid
23992 -- with the detection of duplicate refinements. Remove the
23993 -- state from Available_States to signal that it has already
23994 -- been refined.
23996 if Node (State_Elmt) = State_Id then
23997 Add_Item (State_Id, Refined_States_Seen);
23998 Remove_Elmt (Available_States, State_Elmt);
23999 return;
24000 end if;
24002 Next_Elmt (State_Elmt);
24003 end loop;
24005 -- If we get here, we are refining a state that is not defined in
24006 -- the package declaration.
24008 Error_Msg_Name_1 := Chars (Spec_Id);
24009 SPARK_Msg_NE
24010 ("cannot refine state, & is not defined in package %",
24011 State, State_Id);
24012 end Check_Matching_State;
24014 --------------------------------
24015 -- Report_Unused_Constituents --
24016 --------------------------------
24018 procedure Report_Unused_Constituents (Constits : Elist_Id) is
24019 Constit_Elmt : Elmt_Id;
24020 Constit_Id : Entity_Id;
24021 Posted : Boolean := False;
24023 begin
24024 if Present (Constits) then
24025 Constit_Elmt := First_Elmt (Constits);
24026 while Present (Constit_Elmt) loop
24027 Constit_Id := Node (Constit_Elmt);
24029 -- Generate an error message of the form:
24031 -- state ... has unused Part_Of constituents
24032 -- abstract state ... defined at ...
24033 -- variable ... defined at ...
24035 if not Posted then
24036 Posted := True;
24037 SPARK_Msg_NE
24038 ("state & has unused Part_Of constituents",
24039 State, State_Id);
24040 end if;
24042 Error_Msg_Sloc := Sloc (Constit_Id);
24044 if Ekind (Constit_Id) = E_Abstract_State then
24045 SPARK_Msg_NE
24046 ("\abstract state & defined #", State, Constit_Id);
24047 else
24048 SPARK_Msg_NE
24049 ("\variable & defined #", State, Constit_Id);
24050 end if;
24052 Next_Elmt (Constit_Elmt);
24053 end loop;
24054 end if;
24055 end Report_Unused_Constituents;
24057 -- Local declarations
24059 Body_Ref : Node_Id;
24060 Body_Ref_Elmt : Elmt_Id;
24061 Constit : Node_Id;
24062 Extra_State : Node_Id;
24064 -- Start of processing for Analyze_Refinement_Clause
24066 begin
24067 -- A refinement clause appears as a component association where the
24068 -- sole choice is the state and the expressions are the constituents.
24069 -- This is a syntax error, always report.
24071 if Nkind (Clause) /= N_Component_Association then
24072 Error_Msg_N ("malformed state refinement clause", Clause);
24073 return;
24074 end if;
24076 -- Analyze the state name of a refinement clause
24078 State := First (Choices (Clause));
24080 Analyze (State);
24081 Resolve_State (State);
24083 -- Ensure that the state name denotes a valid abstract state that is
24084 -- defined in the spec of the related package.
24086 if Is_Entity_Name (State) then
24087 State_Id := Entity_Of (State);
24089 -- Catch any attempts to re-refine a state or refine a state that
24090 -- is not defined in the package declaration.
24092 if Ekind (State_Id) = E_Abstract_State then
24093 Check_Matching_State;
24094 else
24095 SPARK_Msg_NE
24096 ("& must denote an abstract state", State, State_Id);
24097 return;
24098 end if;
24100 -- References to a state with visible refinement are illegal.
24101 -- When nested packages are involved, detecting such references is
24102 -- tricky because pragma Refined_State is analyzed later than the
24103 -- offending pragma Depends or Global. References that occur in
24104 -- such nested context are stored in a list. Emit errors for all
24105 -- references found in Body_References (SPARK RM 6.1.4(8)).
24107 if Present (Body_References (State_Id)) then
24108 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
24109 while Present (Body_Ref_Elmt) loop
24110 Body_Ref := Node (Body_Ref_Elmt);
24112 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
24113 Error_Msg_Sloc := Sloc (State);
24114 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
24116 Next_Elmt (Body_Ref_Elmt);
24117 end loop;
24118 end if;
24120 -- The state name is illegal. This is a syntax error, always report.
24122 else
24123 Error_Msg_N ("malformed state name in refinement clause", State);
24124 return;
24125 end if;
24127 -- A refinement clause may only refine one state at a time
24129 Extra_State := Next (State);
24131 if Present (Extra_State) then
24132 SPARK_Msg_N
24133 ("refinement clause cannot cover multiple states", Extra_State);
24134 end if;
24136 -- Replicate the Part_Of constituents of the refined state because
24137 -- the algorithm will consume items.
24139 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
24141 -- Analyze all constituents of the refinement. Multiple constituents
24142 -- appear as an aggregate.
24144 Constit := Expression (Clause);
24146 if Nkind (Constit) = N_Aggregate then
24147 if Present (Component_Associations (Constit)) then
24148 SPARK_Msg_N
24149 ("constituents of refinement clause must appear in "
24150 & "positional form", Constit);
24152 else pragma Assert (Present (Expressions (Constit)));
24153 Constit := First (Expressions (Constit));
24154 while Present (Constit) loop
24155 Analyze_Constituent (Constit);
24157 Next (Constit);
24158 end loop;
24159 end if;
24161 -- Various forms of a single constituent. Note that these may include
24162 -- malformed constituents.
24164 else
24165 Analyze_Constituent (Constit);
24166 end if;
24168 -- A refined external state is subject to special rules with respect
24169 -- to its properties and constituents.
24171 if Is_External_State (State_Id) then
24173 -- The set of properties that all external constituents yield must
24174 -- match that of the refined state. There are two cases to detect:
24175 -- the refined state lacks a property or has an extra property.
24177 if External_Constit_Seen then
24178 Check_External_Property
24179 (Prop_Nam => Name_Async_Readers,
24180 Enabled => Async_Readers_Enabled (State_Id),
24181 Constit => AR_Constit);
24183 Check_External_Property
24184 (Prop_Nam => Name_Async_Writers,
24185 Enabled => Async_Writers_Enabled (State_Id),
24186 Constit => AW_Constit);
24188 Check_External_Property
24189 (Prop_Nam => Name_Effective_Reads,
24190 Enabled => Effective_Reads_Enabled (State_Id),
24191 Constit => ER_Constit);
24193 Check_External_Property
24194 (Prop_Nam => Name_Effective_Writes,
24195 Enabled => Effective_Writes_Enabled (State_Id),
24196 Constit => EW_Constit);
24198 -- An external state may be refined to null (SPARK RM 7.2.8(2))
24200 elsif Null_Seen then
24201 null;
24203 -- The external state has constituents, but none of them are
24204 -- external (SPARK RM 7.2.8(2)).
24206 else
24207 SPARK_Msg_NE
24208 ("external state & requires at least one external "
24209 & "constituent or null refinement", State, State_Id);
24210 end if;
24212 -- When a refined state is not external, it should not have external
24213 -- constituents (SPARK RM 7.2.8(1)).
24215 elsif External_Constit_Seen then
24216 SPARK_Msg_NE
24217 ("non-external state & cannot contain external constituents in "
24218 & "refinement", State, State_Id);
24219 end if;
24221 -- Ensure that all Part_Of candidate constituents have been mentioned
24222 -- in the refinement clause.
24224 Report_Unused_Constituents (Part_Of_Constits);
24225 end Analyze_Refinement_Clause;
24227 -------------------------
24228 -- Collect_Body_States --
24229 -------------------------
24231 function Collect_Body_States (Pack_Id : Entity_Id) return Elist_Id is
24232 Result : Elist_Id := No_Elist;
24233 -- A list containing all body states of Pack_Id
24235 procedure Collect_Visible_States (Pack_Id : Entity_Id);
24236 -- Gather the entities of all abstract states and variables declared
24237 -- in the visible state space of package Pack_Id.
24239 ----------------------------
24240 -- Collect_Visible_States --
24241 ----------------------------
24243 procedure Collect_Visible_States (Pack_Id : Entity_Id) is
24244 Item_Id : Entity_Id;
24246 begin
24247 -- Traverse the entity chain of the package and inspect all
24248 -- visible items.
24250 Item_Id := First_Entity (Pack_Id);
24251 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
24253 -- Do not consider internally generated items as those cannot
24254 -- be named and participate in refinement.
24256 if not Comes_From_Source (Item_Id) then
24257 null;
24259 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
24260 Add_Item (Item_Id, Result);
24262 -- Recursively gather the visible states of a nested package
24264 elsif Ekind (Item_Id) = E_Package then
24265 Collect_Visible_States (Item_Id);
24266 end if;
24268 Next_Entity (Item_Id);
24269 end loop;
24270 end Collect_Visible_States;
24272 -- Local variables
24274 Pack_Body : constant Node_Id :=
24275 Declaration_Node (Body_Entity (Pack_Id));
24276 Decl : Node_Id;
24277 Item_Id : Entity_Id;
24279 -- Start of processing for Collect_Body_States
24281 begin
24282 -- Inspect the declarations of the body looking for source variables,
24283 -- packages and package instantiations.
24285 Decl := First (Declarations (Pack_Body));
24286 while Present (Decl) loop
24287 if Nkind (Decl) = N_Object_Declaration then
24288 Item_Id := Defining_Entity (Decl);
24290 -- Capture source variables only as internally generated
24291 -- temporaries cannot be named and participate in refinement.
24293 if Ekind (Item_Id) = E_Variable
24294 and then Comes_From_Source (Item_Id)
24295 then
24296 Add_Item (Item_Id, Result);
24297 end if;
24299 elsif Nkind (Decl) = N_Package_Declaration then
24300 Item_Id := Defining_Entity (Decl);
24302 -- Capture the visible abstract states and variables of a
24303 -- source package [instantiation].
24305 if Comes_From_Source (Item_Id) then
24306 Collect_Visible_States (Item_Id);
24307 end if;
24308 end if;
24310 Next (Decl);
24311 end loop;
24313 return Result;
24314 end Collect_Body_States;
24316 -----------------------------
24317 -- Report_Unrefined_States --
24318 -----------------------------
24320 procedure Report_Unrefined_States (States : Elist_Id) is
24321 State_Elmt : Elmt_Id;
24323 begin
24324 if Present (States) then
24325 State_Elmt := First_Elmt (States);
24326 while Present (State_Elmt) loop
24327 SPARK_Msg_N
24328 ("abstract state & must be refined", Node (State_Elmt));
24330 Next_Elmt (State_Elmt);
24331 end loop;
24332 end if;
24333 end Report_Unrefined_States;
24335 --------------------------
24336 -- Report_Unused_States --
24337 --------------------------
24339 procedure Report_Unused_States (States : Elist_Id) is
24340 Posted : Boolean := False;
24341 State_Elmt : Elmt_Id;
24342 State_Id : Entity_Id;
24344 begin
24345 if Present (States) then
24346 State_Elmt := First_Elmt (States);
24347 while Present (State_Elmt) loop
24348 State_Id := Node (State_Elmt);
24350 -- Generate an error message of the form:
24352 -- body of package ... has unused hidden states
24353 -- abstract state ... defined at ...
24354 -- variable ... defined at ...
24356 if not Posted then
24357 Posted := True;
24358 SPARK_Msg_N
24359 ("body of package & has unused hidden states", Body_Id);
24360 end if;
24362 Error_Msg_Sloc := Sloc (State_Id);
24364 if Ekind (State_Id) = E_Abstract_State then
24365 SPARK_Msg_NE
24366 ("\abstract state & defined #", Body_Id, State_Id);
24367 else
24368 SPARK_Msg_NE
24369 ("\variable & defined #", Body_Id, State_Id);
24370 end if;
24372 Next_Elmt (State_Elmt);
24373 end loop;
24374 end if;
24375 end Report_Unused_States;
24377 -- Local declarations
24379 Body_Decl : constant Node_Id := Parent (N);
24380 Clauses : constant Node_Id :=
24381 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
24382 Clause : Node_Id;
24384 -- Start of processing for Analyze_Refined_State_In_Decl_Part
24386 begin
24387 Set_Analyzed (N);
24389 Body_Id := Defining_Entity (Body_Decl);
24390 Spec_Id := Corresponding_Spec (Body_Decl);
24392 -- Replicate the abstract states declared by the package because the
24393 -- matching algorithm will consume states.
24395 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
24397 -- Gather all abstract states and variables declared in the visible
24398 -- state space of the package body. These items must be utilized as
24399 -- constituents in a state refinement.
24401 Body_States := Collect_Body_States (Spec_Id);
24403 -- Multiple non-null state refinements appear as an aggregate
24405 if Nkind (Clauses) = N_Aggregate then
24406 if Present (Expressions (Clauses)) then
24407 SPARK_Msg_N
24408 ("state refinements must appear as component associations",
24409 Clauses);
24411 else pragma Assert (Present (Component_Associations (Clauses)));
24412 Clause := First (Component_Associations (Clauses));
24413 while Present (Clause) loop
24414 Analyze_Refinement_Clause (Clause);
24416 Next (Clause);
24417 end loop;
24418 end if;
24420 -- Various forms of a single state refinement. Note that these may
24421 -- include malformed refinements.
24423 else
24424 Analyze_Refinement_Clause (Clauses);
24425 end if;
24427 -- List all abstract states that were left unrefined
24429 Report_Unrefined_States (Available_States);
24431 -- Ensure that all abstract states and variables declared in the body
24432 -- state space of the related package are utilized as constituents.
24434 Report_Unused_States (Body_States);
24435 end Analyze_Refined_State_In_Decl_Part;
24437 ------------------------------------
24438 -- Analyze_Test_Case_In_Decl_Part --
24439 ------------------------------------
24441 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id; S : Entity_Id) is
24442 begin
24443 -- Install formals and push subprogram spec onto scope stack so that we
24444 -- can see the formals from the pragma.
24446 Push_Scope (S);
24447 Install_Formals (S);
24449 -- Preanalyze the boolean expressions, we treat these as spec
24450 -- expressions (i.e. similar to a default expression).
24452 if Pragma_Name (N) = Name_Test_Case then
24453 Preanalyze_CTC_Args
24455 Get_Requires_From_CTC_Pragma (N),
24456 Get_Ensures_From_CTC_Pragma (N));
24457 end if;
24459 -- Remove the subprogram from the scope stack now that the pre-analysis
24460 -- of the expressions in the contract case or test case is done.
24462 End_Scope;
24463 end Analyze_Test_Case_In_Decl_Part;
24465 ----------------
24466 -- Appears_In --
24467 ----------------
24469 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
24470 Elmt : Elmt_Id;
24471 Id : Entity_Id;
24473 begin
24474 if Present (List) then
24475 Elmt := First_Elmt (List);
24476 while Present (Elmt) loop
24477 if Nkind (Node (Elmt)) = N_Defining_Identifier then
24478 Id := Node (Elmt);
24479 else
24480 Id := Entity_Of (Node (Elmt));
24481 end if;
24483 if Id = Item_Id then
24484 return True;
24485 end if;
24487 Next_Elmt (Elmt);
24488 end loop;
24489 end if;
24491 return False;
24492 end Appears_In;
24494 -----------------------------
24495 -- Check_Applicable_Policy --
24496 -----------------------------
24498 procedure Check_Applicable_Policy (N : Node_Id) is
24499 PP : Node_Id;
24500 Policy : Name_Id;
24502 Ename : constant Name_Id := Original_Aspect_Name (N);
24504 begin
24505 -- No effect if not valid assertion kind name
24507 if not Is_Valid_Assertion_Kind (Ename) then
24508 return;
24509 end if;
24511 -- Loop through entries in check policy list
24513 PP := Opt.Check_Policy_List;
24514 while Present (PP) loop
24515 declare
24516 PPA : constant List_Id := Pragma_Argument_Associations (PP);
24517 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
24519 begin
24520 if Ename = Pnm
24521 or else Pnm = Name_Assertion
24522 or else (Pnm = Name_Statement_Assertions
24523 and then Nam_In (Ename, Name_Assert,
24524 Name_Assert_And_Cut,
24525 Name_Assume,
24526 Name_Loop_Invariant,
24527 Name_Loop_Variant))
24528 then
24529 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
24531 case Policy is
24532 when Name_Off | Name_Ignore =>
24533 Set_Is_Ignored (N, True);
24534 Set_Is_Checked (N, False);
24536 when Name_On | Name_Check =>
24537 Set_Is_Checked (N, True);
24538 Set_Is_Ignored (N, False);
24540 when Name_Disable =>
24541 Set_Is_Ignored (N, True);
24542 Set_Is_Checked (N, False);
24543 Set_Is_Disabled (N, True);
24545 -- That should be exhaustive, the null here is a defence
24546 -- against a malformed tree from previous errors.
24548 when others =>
24549 null;
24550 end case;
24552 return;
24553 end if;
24555 PP := Next_Pragma (PP);
24556 end;
24557 end loop;
24559 -- If there are no specific entries that matched, then we let the
24560 -- setting of assertions govern. Note that this provides the needed
24561 -- compatibility with the RM for the cases of assertion, invariant,
24562 -- precondition, predicate, and postcondition.
24564 if Assertions_Enabled then
24565 Set_Is_Checked (N, True);
24566 Set_Is_Ignored (N, False);
24567 else
24568 Set_Is_Checked (N, False);
24569 Set_Is_Ignored (N, True);
24570 end if;
24571 end Check_Applicable_Policy;
24573 -------------------------------
24574 -- Check_External_Properties --
24575 -------------------------------
24577 procedure Check_External_Properties
24578 (Item : Node_Id;
24579 AR : Boolean;
24580 AW : Boolean;
24581 ER : Boolean;
24582 EW : Boolean)
24584 begin
24585 -- All properties enabled
24587 if AR and AW and ER and EW then
24588 null;
24590 -- Async_Readers + Effective_Writes
24591 -- Async_Readers + Async_Writers + Effective_Writes
24593 elsif AR and EW and not ER then
24594 null;
24596 -- Async_Writers + Effective_Reads
24597 -- Async_Readers + Async_Writers + Effective_Reads
24599 elsif AW and ER and not EW then
24600 null;
24602 -- Async_Readers + Async_Writers
24604 elsif AR and AW and not ER and not EW then
24605 null;
24607 -- Async_Readers
24609 elsif AR and not AW and not ER and not EW then
24610 null;
24612 -- Async_Writers
24614 elsif AW and not AR and not ER and not EW then
24615 null;
24617 else
24618 SPARK_Msg_N
24619 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
24620 Item);
24621 end if;
24622 end Check_External_Properties;
24624 ----------------
24625 -- Check_Kind --
24626 ----------------
24628 function Check_Kind (Nam : Name_Id) return Name_Id is
24629 PP : Node_Id;
24631 begin
24632 -- Loop through entries in check policy list
24634 PP := Opt.Check_Policy_List;
24635 while Present (PP) loop
24636 declare
24637 PPA : constant List_Id := Pragma_Argument_Associations (PP);
24638 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
24640 begin
24641 if Nam = Pnm
24642 or else (Pnm = Name_Assertion
24643 and then Is_Valid_Assertion_Kind (Nam))
24644 or else (Pnm = Name_Statement_Assertions
24645 and then Nam_In (Nam, Name_Assert,
24646 Name_Assert_And_Cut,
24647 Name_Assume,
24648 Name_Loop_Invariant,
24649 Name_Loop_Variant))
24650 then
24651 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
24652 when Name_On | Name_Check =>
24653 return Name_Check;
24654 when Name_Off | Name_Ignore =>
24655 return Name_Ignore;
24656 when Name_Disable =>
24657 return Name_Disable;
24658 when others =>
24659 raise Program_Error;
24660 end case;
24662 else
24663 PP := Next_Pragma (PP);
24664 end if;
24665 end;
24666 end loop;
24668 -- If there are no specific entries that matched, then we let the
24669 -- setting of assertions govern. Note that this provides the needed
24670 -- compatibility with the RM for the cases of assertion, invariant,
24671 -- precondition, predicate, and postcondition.
24673 if Assertions_Enabled then
24674 return Name_Check;
24675 else
24676 return Name_Ignore;
24677 end if;
24678 end Check_Kind;
24680 ---------------------------
24681 -- Check_Missing_Part_Of --
24682 ---------------------------
24684 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
24685 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
24686 -- Determine whether a package denoted by Pack_Id declares at least one
24687 -- visible state.
24689 -----------------------
24690 -- Has_Visible_State --
24691 -----------------------
24693 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
24694 Item_Id : Entity_Id;
24696 begin
24697 -- Traverse the entity chain of the package trying to find at least
24698 -- one visible abstract state, variable or a package [instantiation]
24699 -- that declares a visible state.
24701 Item_Id := First_Entity (Pack_Id);
24702 while Present (Item_Id)
24703 and then not In_Private_Part (Item_Id)
24704 loop
24705 -- Do not consider internally generated items
24707 if not Comes_From_Source (Item_Id) then
24708 null;
24710 -- A visible state has been found
24712 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
24713 return True;
24715 -- Recursively peek into nested packages and instantiations
24717 elsif Ekind (Item_Id) = E_Package
24718 and then Has_Visible_State (Item_Id)
24719 then
24720 return True;
24721 end if;
24723 Next_Entity (Item_Id);
24724 end loop;
24726 return False;
24727 end Has_Visible_State;
24729 -- Local variables
24731 Pack_Id : Entity_Id;
24732 Placement : State_Space_Kind;
24734 -- Start of processing for Check_Missing_Part_Of
24736 begin
24737 -- Do not consider abstract states, variables or package instantiations
24738 -- coming from an instance as those always inherit the Part_Of indicator
24739 -- of the instance itself.
24741 if In_Instance then
24742 return;
24744 -- Do not consider internally generated entities as these can never
24745 -- have a Part_Of indicator.
24747 elsif not Comes_From_Source (Item_Id) then
24748 return;
24750 -- Perform these checks only when SPARK_Mode is enabled as they will
24751 -- interfere with standard Ada rules and produce false positives.
24753 elsif SPARK_Mode /= On then
24754 return;
24755 end if;
24757 -- Find where the abstract state, variable or package instantiation
24758 -- lives with respect to the state space.
24760 Find_Placement_In_State_Space
24761 (Item_Id => Item_Id,
24762 Placement => Placement,
24763 Pack_Id => Pack_Id);
24765 -- Items that appear in a non-package construct (subprogram, block, etc)
24766 -- do not require a Part_Of indicator because they can never act as a
24767 -- hidden state.
24769 if Placement = Not_In_Package then
24770 null;
24772 -- An item declared in the body state space of a package always act as a
24773 -- constituent and does not need explicit Part_Of indicator.
24775 elsif Placement = Body_State_Space then
24776 null;
24778 -- In general an item declared in the visible state space of a package
24779 -- does not require a Part_Of indicator. The only exception is when the
24780 -- related package is a private child unit in which case Part_Of must
24781 -- denote a state in the parent unit or in one of its descendants.
24783 elsif Placement = Visible_State_Space then
24784 if Is_Child_Unit (Pack_Id)
24785 and then Is_Private_Descendant (Pack_Id)
24786 then
24787 -- A package instantiation does not need a Part_Of indicator when
24788 -- the related generic template has no visible state.
24790 if Ekind (Item_Id) = E_Package
24791 and then Is_Generic_Instance (Item_Id)
24792 and then not Has_Visible_State (Item_Id)
24793 then
24794 null;
24796 -- All other cases require Part_Of
24798 else
24799 Error_Msg_N
24800 ("indicator Part_Of is required in this context "
24801 & "(SPARK RM 7.2.6(3))", Item_Id);
24802 Error_Msg_Name_1 := Chars (Pack_Id);
24803 Error_Msg_N
24804 ("\& is declared in the visible part of private child "
24805 & "unit %", Item_Id);
24806 end if;
24807 end if;
24809 -- When the item appears in the private state space of a packge, it must
24810 -- be a part of some state declared by the said package.
24812 else pragma Assert (Placement = Private_State_Space);
24814 -- The related package does not declare a state, the item cannot act
24815 -- as a Part_Of constituent.
24817 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
24818 null;
24820 -- A package instantiation does not need a Part_Of indicator when the
24821 -- related generic template has no visible state.
24823 elsif Ekind (Pack_Id) = E_Package
24824 and then Is_Generic_Instance (Pack_Id)
24825 and then not Has_Visible_State (Pack_Id)
24826 then
24827 null;
24829 -- All other cases require Part_Of
24831 else
24832 Error_Msg_N
24833 ("indicator Part_Of is required in this context "
24834 & "(SPARK RM 7.2.6(2))", Item_Id);
24835 Error_Msg_Name_1 := Chars (Pack_Id);
24836 Error_Msg_N
24837 ("\& is declared in the private part of package %", Item_Id);
24838 end if;
24839 end if;
24840 end Check_Missing_Part_Of;
24842 ---------------------------------
24843 -- Check_SPARK_Aspect_For_ASIS --
24844 ---------------------------------
24846 procedure Check_SPARK_Aspect_For_ASIS (N : Node_Id) is
24847 Expr : Node_Id;
24849 begin
24850 if ASIS_Mode and then From_Aspect_Specification (N) then
24851 Expr := Expression (Corresponding_Aspect (N));
24852 if Nkind (Expr) /= N_Aggregate then
24853 Preanalyze_And_Resolve (Expr);
24855 else
24856 declare
24857 Comps : constant List_Id := Component_Associations (Expr);
24858 Exprs : constant List_Id := Expressions (Expr);
24859 C : Node_Id;
24860 E : Node_Id;
24862 begin
24863 E := First (Exprs);
24864 while Present (E) loop
24865 Analyze (E);
24866 Next (E);
24867 end loop;
24869 C := First (Comps);
24870 while Present (C) loop
24871 Analyze (Expression (C));
24872 Next (C);
24873 end loop;
24874 end;
24875 end if;
24876 end if;
24877 end Check_SPARK_Aspect_For_ASIS;
24879 -------------------------------------
24880 -- Check_State_And_Constituent_Use --
24881 -------------------------------------
24883 procedure Check_State_And_Constituent_Use
24884 (States : Elist_Id;
24885 Constits : Elist_Id;
24886 Context : Node_Id)
24888 function Find_Encapsulating_State
24889 (Constit_Id : Entity_Id) return Entity_Id;
24890 -- Given the entity of a constituent, try to find a corresponding
24891 -- encapsulating state that appears in the same context. The routine
24892 -- returns Empty is no such state is found.
24894 ------------------------------
24895 -- Find_Encapsulating_State --
24896 ------------------------------
24898 function Find_Encapsulating_State
24899 (Constit_Id : Entity_Id) return Entity_Id
24901 State_Id : Entity_Id;
24903 begin
24904 -- Since a constituent may be part of a larger constituent set, climb
24905 -- the encapsulated state chain looking for a state that appears in
24906 -- the same context.
24908 State_Id := Encapsulating_State (Constit_Id);
24909 while Present (State_Id) loop
24910 if Contains (States, State_Id) then
24911 return State_Id;
24912 end if;
24914 State_Id := Encapsulating_State (State_Id);
24915 end loop;
24917 return Empty;
24918 end Find_Encapsulating_State;
24920 -- Local variables
24922 Constit_Elmt : Elmt_Id;
24923 Constit_Id : Entity_Id;
24924 State_Id : Entity_Id;
24926 -- Start of processing for Check_State_And_Constituent_Use
24928 begin
24929 -- Nothing to do if there are no states or constituents
24931 if No (States) or else No (Constits) then
24932 return;
24933 end if;
24935 -- Inspect the list of constituents and try to determine whether its
24936 -- encapsulating state is in list States.
24938 Constit_Elmt := First_Elmt (Constits);
24939 while Present (Constit_Elmt) loop
24940 Constit_Id := Node (Constit_Elmt);
24942 -- Determine whether the constituent is part of an encapsulating
24943 -- state that appears in the same context and if this is the case,
24944 -- emit an error (SPARK RM 7.2.6(7)).
24946 State_Id := Find_Encapsulating_State (Constit_Id);
24948 if Present (State_Id) then
24949 Error_Msg_Name_1 := Chars (Constit_Id);
24950 SPARK_Msg_NE
24951 ("cannot mention state & and its constituent % in the same "
24952 & "context", Context, State_Id);
24953 exit;
24954 end if;
24956 Next_Elmt (Constit_Elmt);
24957 end loop;
24958 end Check_State_And_Constituent_Use;
24960 ---------------------------------------
24961 -- Collect_Subprogram_Inputs_Outputs --
24962 ---------------------------------------
24964 procedure Collect_Subprogram_Inputs_Outputs
24965 (Subp_Id : Entity_Id;
24966 Synthesize : Boolean := False;
24967 Subp_Inputs : in out Elist_Id;
24968 Subp_Outputs : in out Elist_Id;
24969 Global_Seen : out Boolean)
24971 procedure Collect_Dependency_Clause (Clause : Node_Id);
24972 -- Collect all relevant items from a dependency clause
24974 procedure Collect_Global_List
24975 (List : Node_Id;
24976 Mode : Name_Id := Name_Input);
24977 -- Collect all relevant items from a global list
24979 -------------------------------
24980 -- Collect_Dependency_Clause --
24981 -------------------------------
24983 procedure Collect_Dependency_Clause (Clause : Node_Id) is
24984 procedure Collect_Dependency_Item
24985 (Item : Node_Id;
24986 Is_Input : Boolean);
24987 -- Add an item to the proper subprogram input or output collection
24989 -----------------------------
24990 -- Collect_Dependency_Item --
24991 -----------------------------
24993 procedure Collect_Dependency_Item
24994 (Item : Node_Id;
24995 Is_Input : Boolean)
24997 Extra : Node_Id;
24999 begin
25000 -- Nothing to collect when the item is null
25002 if Nkind (Item) = N_Null then
25003 null;
25005 -- Ditto for attribute 'Result
25007 elsif Is_Attribute_Result (Item) then
25008 null;
25010 -- Multiple items appear as an aggregate
25012 elsif Nkind (Item) = N_Aggregate then
25013 Extra := First (Expressions (Item));
25014 while Present (Extra) loop
25015 Collect_Dependency_Item (Extra, Is_Input);
25016 Next (Extra);
25017 end loop;
25019 -- Otherwise this is a solitary item
25021 else
25022 if Is_Input then
25023 Add_Item (Item, Subp_Inputs);
25024 else
25025 Add_Item (Item, Subp_Outputs);
25026 end if;
25027 end if;
25028 end Collect_Dependency_Item;
25030 -- Start of processing for Collect_Dependency_Clause
25032 begin
25033 if Nkind (Clause) = N_Null then
25034 null;
25036 -- A dependency cause appears as component association
25038 elsif Nkind (Clause) = N_Component_Association then
25039 Collect_Dependency_Item
25040 (Expression (Clause), Is_Input => True);
25041 Collect_Dependency_Item
25042 (First (Choices (Clause)), Is_Input => False);
25044 -- To accomodate partial decoration of disabled SPARK features, this
25045 -- routine may be called with illegal input. If this is the case, do
25046 -- not raise Program_Error.
25048 else
25049 null;
25050 end if;
25051 end Collect_Dependency_Clause;
25053 -------------------------
25054 -- Collect_Global_List --
25055 -------------------------
25057 procedure Collect_Global_List
25058 (List : Node_Id;
25059 Mode : Name_Id := Name_Input)
25061 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
25062 -- Add an item to the proper subprogram input or output collection
25064 -------------------------
25065 -- Collect_Global_Item --
25066 -------------------------
25068 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
25069 begin
25070 if Nam_In (Mode, Name_In_Out, Name_Input) then
25071 Add_Item (Item, Subp_Inputs);
25072 end if;
25074 if Nam_In (Mode, Name_In_Out, Name_Output) then
25075 Add_Item (Item, Subp_Outputs);
25076 end if;
25077 end Collect_Global_Item;
25079 -- Local variables
25081 Assoc : Node_Id;
25082 Item : Node_Id;
25084 -- Start of processing for Collect_Global_List
25086 begin
25087 if Nkind (List) = N_Null then
25088 null;
25090 -- Single global item declaration
25092 elsif Nkind_In (List, N_Expanded_Name,
25093 N_Identifier,
25094 N_Selected_Component)
25095 then
25096 Collect_Global_Item (List, Mode);
25098 -- Simple global list or moded global list declaration
25100 elsif Nkind (List) = N_Aggregate then
25101 if Present (Expressions (List)) then
25102 Item := First (Expressions (List));
25103 while Present (Item) loop
25104 Collect_Global_Item (Item, Mode);
25105 Next (Item);
25106 end loop;
25108 else
25109 Assoc := First (Component_Associations (List));
25110 while Present (Assoc) loop
25111 Collect_Global_List
25112 (List => Expression (Assoc),
25113 Mode => Chars (First (Choices (Assoc))));
25114 Next (Assoc);
25115 end loop;
25116 end if;
25118 -- To accomodate partial decoration of disabled SPARK features, this
25119 -- routine may be called with illegal input. If this is the case, do
25120 -- not raise Program_Error.
25122 else
25123 null;
25124 end if;
25125 end Collect_Global_List;
25127 -- Local variables
25129 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
25130 Clause : Node_Id;
25131 Clauses : Node_Id;
25132 Depends : Node_Id;
25133 Formal : Entity_Id;
25134 Global : Node_Id;
25135 List : Node_Id;
25136 Spec_Id : Entity_Id;
25138 -- Start of processing for Collect_Subprogram_Inputs_Outputs
25140 begin
25141 Global_Seen := False;
25143 -- Find the entity of the corresponding spec when processing a body
25145 if Nkind (Subp_Decl) = N_Subprogram_Body
25146 and then Present (Corresponding_Spec (Subp_Decl))
25147 then
25148 Spec_Id := Corresponding_Spec (Subp_Decl);
25150 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
25151 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
25152 then
25153 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
25155 else
25156 Spec_Id := Subp_Id;
25157 end if;
25159 -- Process all formal parameters
25161 Formal := First_Formal (Spec_Id);
25162 while Present (Formal) loop
25163 if Ekind_In (Formal, E_In_Out_Parameter, E_In_Parameter) then
25164 Add_Item (Formal, Subp_Inputs);
25165 end if;
25167 if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
25168 Add_Item (Formal, Subp_Outputs);
25170 -- Out parameters can act as inputs when the related type is
25171 -- tagged, unconstrained array, unconstrained record or record
25172 -- with unconstrained components.
25174 if Ekind (Formal) = E_Out_Parameter
25175 and then Is_Unconstrained_Or_Tagged_Item (Formal)
25176 then
25177 Add_Item (Formal, Subp_Inputs);
25178 end if;
25179 end if;
25181 Next_Formal (Formal);
25182 end loop;
25184 -- When processing a subprogram body, look for pragmas Refined_Depends
25185 -- and Refined_Global as they specify the inputs and outputs.
25187 if Ekind (Subp_Id) = E_Subprogram_Body then
25188 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
25189 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
25191 -- Subprogram declaration case, look for pragmas Depends and Global
25193 else
25194 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
25195 Global := Get_Pragma (Spec_Id, Pragma_Global);
25196 end if;
25198 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
25199 -- because it provides finer granularity of inputs and outputs.
25201 if Present (Global) then
25202 Global_Seen := True;
25203 List := Expression (First (Pragma_Argument_Associations (Global)));
25205 -- The pragma may not have been analyzed because of the arbitrary
25206 -- declaration order of aspects. Make sure that it is analyzed for
25207 -- the purposes of item extraction.
25209 if not Analyzed (List) then
25210 if Pragma_Name (Global) = Name_Refined_Global then
25211 Analyze_Refined_Global_In_Decl_Part (Global);
25212 else
25213 Analyze_Global_In_Decl_Part (Global);
25214 end if;
25215 end if;
25217 Collect_Global_List (List);
25219 -- When the related subprogram lacks pragma [Refined_]Global, fall back
25220 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
25221 -- the inputs and outputs from [Refined_]Depends.
25223 elsif Synthesize and then Present (Depends) then
25224 Clauses :=
25225 Get_Pragma_Arg (First (Pragma_Argument_Associations (Depends)));
25227 -- Multiple dependency clauses appear as an aggregate
25229 if Nkind (Clauses) = N_Aggregate then
25230 Clause := First (Component_Associations (Clauses));
25231 while Present (Clause) loop
25232 Collect_Dependency_Clause (Clause);
25233 Next (Clause);
25234 end loop;
25236 -- Otherwise this is a single dependency clause
25238 else
25239 Collect_Dependency_Clause (Clauses);
25240 end if;
25241 end if;
25242 end Collect_Subprogram_Inputs_Outputs;
25244 ---------------------------------
25245 -- Delay_Config_Pragma_Analyze --
25246 ---------------------------------
25248 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
25249 begin
25250 return Nam_In (Pragma_Name (N), Name_Interrupt_State,
25251 Name_Priority_Specific_Dispatching);
25252 end Delay_Config_Pragma_Analyze;
25254 -------------------------------------
25255 -- Find_Related_Subprogram_Or_Body --
25256 -------------------------------------
25258 function Find_Related_Subprogram_Or_Body
25259 (Prag : Node_Id;
25260 Do_Checks : Boolean := False) return Node_Id
25262 Context : constant Node_Id := Parent (Prag);
25263 Nam : constant Name_Id := Pragma_Name (Prag);
25264 Stmt : Node_Id;
25266 Look_For_Body : constant Boolean :=
25267 Nam_In (Nam, Name_Refined_Depends,
25268 Name_Refined_Global,
25269 Name_Refined_Post);
25270 -- Refinement pragmas must be associated with a subprogram body [stub]
25272 begin
25273 pragma Assert (Nkind (Prag) = N_Pragma);
25275 -- If the pragma is a byproduct of aspect expansion, return the related
25276 -- context of the original aspect.
25278 if Present (Corresponding_Aspect (Prag)) then
25279 return Parent (Corresponding_Aspect (Prag));
25280 end if;
25282 -- Otherwise the pragma is a source construct, most likely part of a
25283 -- declarative list. Skip preceding declarations while looking for a
25284 -- proper subprogram declaration.
25286 pragma Assert (Is_List_Member (Prag));
25288 Stmt := Prev (Prag);
25289 while Present (Stmt) loop
25291 -- Skip prior pragmas, but check for duplicates
25293 if Nkind (Stmt) = N_Pragma then
25294 if Do_Checks and then Pragma_Name (Stmt) = Nam then
25295 Error_Msg_Name_1 := Nam;
25296 Error_Msg_Sloc := Sloc (Stmt);
25297 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
25298 end if;
25300 -- Emit an error when a refinement pragma appears on an expression
25301 -- function without a completion.
25303 elsif Do_Checks
25304 and then Look_For_Body
25305 and then Nkind (Stmt) = N_Subprogram_Declaration
25306 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
25307 and then not Has_Completion (Defining_Entity (Stmt))
25308 then
25309 Error_Msg_Name_1 := Nam;
25310 Error_Msg_N
25311 ("pragma % cannot apply to a stand alone expression function",
25312 Prag);
25314 return Empty;
25316 -- The refinement pragma applies to a subprogram body stub
25318 elsif Look_For_Body
25319 and then Nkind (Stmt) = N_Subprogram_Body_Stub
25320 then
25321 return Stmt;
25323 -- Skip internally generated code
25325 elsif not Comes_From_Source (Stmt) then
25326 null;
25328 -- Return the current construct which is either a subprogram body,
25329 -- a subprogram declaration or is illegal.
25331 else
25332 return Stmt;
25333 end if;
25335 Prev (Stmt);
25336 end loop;
25338 -- If we fall through, then the pragma was either the first declaration
25339 -- or it was preceded by other pragmas and no source constructs.
25341 -- The pragma is associated with a library-level subprogram
25343 if Nkind (Context) = N_Compilation_Unit_Aux then
25344 return Unit (Parent (Context));
25346 -- The pragma appears inside the declarative part of a subprogram body
25348 elsif Nkind (Context) = N_Subprogram_Body then
25349 return Context;
25351 -- No candidate subprogram [body] found
25353 else
25354 return Empty;
25355 end if;
25356 end Find_Related_Subprogram_Or_Body;
25358 -------------------------
25359 -- Get_Base_Subprogram --
25360 -------------------------
25362 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
25363 Result : Entity_Id;
25365 begin
25366 -- Follow subprogram renaming chain
25368 Result := Def_Id;
25370 if Is_Subprogram (Result)
25371 and then
25372 Nkind (Parent (Declaration_Node (Result))) =
25373 N_Subprogram_Renaming_Declaration
25374 and then Present (Alias (Result))
25375 then
25376 Result := Alias (Result);
25377 end if;
25379 return Result;
25380 end Get_Base_Subprogram;
25382 -----------------------
25383 -- Get_SPARK_Mode_Type --
25384 -----------------------
25386 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
25387 begin
25388 if N = Name_On then
25389 return On;
25390 elsif N = Name_Off then
25391 return Off;
25393 -- Any other argument is illegal
25395 else
25396 raise Program_Error;
25397 end if;
25398 end Get_SPARK_Mode_Type;
25400 --------------------------------
25401 -- Get_SPARK_Mode_From_Pragma --
25402 --------------------------------
25404 function Get_SPARK_Mode_From_Pragma (N : Node_Id) return SPARK_Mode_Type is
25405 Args : List_Id;
25406 Mode : Node_Id;
25408 begin
25409 pragma Assert (Nkind (N) = N_Pragma);
25410 Args := Pragma_Argument_Associations (N);
25412 -- Extract the mode from the argument list
25414 if Present (Args) then
25415 Mode := First (Pragma_Argument_Associations (N));
25416 return Get_SPARK_Mode_Type (Chars (Get_Pragma_Arg (Mode)));
25418 -- If SPARK_Mode pragma has no argument, default is ON
25420 else
25421 return On;
25422 end if;
25423 end Get_SPARK_Mode_From_Pragma;
25425 ---------------------------
25426 -- Has_Extra_Parentheses --
25427 ---------------------------
25429 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
25430 Expr : Node_Id;
25432 begin
25433 -- The aggregate should not have an expression list because a clause
25434 -- is always interpreted as a component association. The only way an
25435 -- expression list can sneak in is by adding extra parentheses around
25436 -- the individual clauses:
25438 -- Depends (Output => Input) -- proper form
25439 -- Depends ((Output => Input)) -- extra parentheses
25441 -- Since the extra parentheses are not allowed by the syntax of the
25442 -- pragma, flag them now to avoid emitting misleading errors down the
25443 -- line.
25445 if Nkind (Clause) = N_Aggregate
25446 and then Present (Expressions (Clause))
25447 then
25448 Expr := First (Expressions (Clause));
25449 while Present (Expr) loop
25451 -- A dependency clause surrounded by extra parentheses appears
25452 -- as an aggregate of component associations with an optional
25453 -- Paren_Count set.
25455 if Nkind (Expr) = N_Aggregate
25456 and then Present (Component_Associations (Expr))
25457 then
25458 SPARK_Msg_N
25459 ("dependency clause contains extra parentheses", Expr);
25461 -- Otherwise the expression is a malformed construct
25463 else
25464 SPARK_Msg_N ("malformed dependency clause", Expr);
25465 end if;
25467 Next (Expr);
25468 end loop;
25470 return True;
25471 end if;
25473 return False;
25474 end Has_Extra_Parentheses;
25476 ----------------
25477 -- Initialize --
25478 ----------------
25480 procedure Initialize is
25481 begin
25482 Externals.Init;
25483 end Initialize;
25485 --------
25486 -- ip --
25487 --------
25489 procedure ip is
25490 begin
25491 Dummy := Dummy + 1;
25492 end ip;
25494 -----------------------------
25495 -- Is_Config_Static_String --
25496 -----------------------------
25498 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
25500 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
25501 -- This is an internal recursive function that is just like the outer
25502 -- function except that it adds the string to the name buffer rather
25503 -- than placing the string in the name buffer.
25505 ------------------------------
25506 -- Add_Config_Static_String --
25507 ------------------------------
25509 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
25510 N : Node_Id;
25511 C : Char_Code;
25513 begin
25514 N := Arg;
25516 if Nkind (N) = N_Op_Concat then
25517 if Add_Config_Static_String (Left_Opnd (N)) then
25518 N := Right_Opnd (N);
25519 else
25520 return False;
25521 end if;
25522 end if;
25524 if Nkind (N) /= N_String_Literal then
25525 Error_Msg_N ("string literal expected for pragma argument", N);
25526 return False;
25528 else
25529 for J in 1 .. String_Length (Strval (N)) loop
25530 C := Get_String_Char (Strval (N), J);
25532 if not In_Character_Range (C) then
25533 Error_Msg
25534 ("string literal contains invalid wide character",
25535 Sloc (N) + 1 + Source_Ptr (J));
25536 return False;
25537 end if;
25539 Add_Char_To_Name_Buffer (Get_Character (C));
25540 end loop;
25541 end if;
25543 return True;
25544 end Add_Config_Static_String;
25546 -- Start of processing for Is_Config_Static_String
25548 begin
25549 Name_Len := 0;
25551 return Add_Config_Static_String (Arg);
25552 end Is_Config_Static_String;
25554 -------------------------------
25555 -- Is_Elaboration_SPARK_Mode --
25556 -------------------------------
25558 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
25559 begin
25560 pragma Assert
25561 (Nkind (N) = N_Pragma
25562 and then Pragma_Name (N) = Name_SPARK_Mode
25563 and then Is_List_Member (N));
25565 -- Pragma SPARK_Mode affects the elaboration of a package body when it
25566 -- appears in the statement part of the body.
25568 return
25569 Present (Parent (N))
25570 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
25571 and then List_Containing (N) = Statements (Parent (N))
25572 and then Present (Parent (Parent (N)))
25573 and then Nkind (Parent (Parent (N))) = N_Package_Body;
25574 end Is_Elaboration_SPARK_Mode;
25576 -----------------------------------------
25577 -- Is_Non_Significant_Pragma_Reference --
25578 -----------------------------------------
25580 -- This function makes use of the following static table which indicates
25581 -- whether appearance of some name in a given pragma is to be considered
25582 -- as a reference for the purposes of warnings about unreferenced objects.
25584 -- -1 indicates that appearence in any argument is significant
25585 -- 0 indicates that appearance in any argument is not significant
25586 -- +n indicates that appearance as argument n is significant, but all
25587 -- other arguments are not significant
25588 -- 9n arguments from n on are significant, before n inisignificant
25590 Sig_Flags : constant array (Pragma_Id) of Int :=
25591 (Pragma_Abort_Defer => -1,
25592 Pragma_Abstract_State => -1,
25593 Pragma_Ada_83 => -1,
25594 Pragma_Ada_95 => -1,
25595 Pragma_Ada_05 => -1,
25596 Pragma_Ada_2005 => -1,
25597 Pragma_Ada_12 => -1,
25598 Pragma_Ada_2012 => -1,
25599 Pragma_All_Calls_Remote => -1,
25600 Pragma_Allow_Integer_Address => -1,
25601 Pragma_Annotate => 93,
25602 Pragma_Assert => -1,
25603 Pragma_Assert_And_Cut => -1,
25604 Pragma_Assertion_Policy => 0,
25605 Pragma_Assume => -1,
25606 Pragma_Assume_No_Invalid_Values => 0,
25607 Pragma_Async_Readers => 0,
25608 Pragma_Async_Writers => 0,
25609 Pragma_Asynchronous => 0,
25610 Pragma_Atomic => 0,
25611 Pragma_Atomic_Components => 0,
25612 Pragma_Attach_Handler => -1,
25613 Pragma_Attribute_Definition => 92,
25614 Pragma_Check => -1,
25615 Pragma_Check_Float_Overflow => 0,
25616 Pragma_Check_Name => 0,
25617 Pragma_Check_Policy => 0,
25618 Pragma_CIL_Constructor => 0,
25619 Pragma_CPP_Class => 0,
25620 Pragma_CPP_Constructor => 0,
25621 Pragma_CPP_Virtual => 0,
25622 Pragma_CPP_Vtable => 0,
25623 Pragma_CPU => -1,
25624 Pragma_C_Pass_By_Copy => 0,
25625 Pragma_Comment => -1,
25626 Pragma_Common_Object => 0,
25627 Pragma_Compile_Time_Error => -1,
25628 Pragma_Compile_Time_Warning => -1,
25629 Pragma_Compiler_Unit => -1,
25630 Pragma_Compiler_Unit_Warning => -1,
25631 Pragma_Complete_Representation => 0,
25632 Pragma_Complex_Representation => 0,
25633 Pragma_Component_Alignment => 0,
25634 Pragma_Contract_Cases => -1,
25635 Pragma_Controlled => 0,
25636 Pragma_Convention => 0,
25637 Pragma_Convention_Identifier => 0,
25638 Pragma_Debug => -1,
25639 Pragma_Debug_Policy => 0,
25640 Pragma_Detect_Blocking => 0,
25641 Pragma_Default_Initial_Condition => -1,
25642 Pragma_Default_Scalar_Storage_Order => 0,
25643 Pragma_Default_Storage_Pool => 0,
25644 Pragma_Depends => -1,
25645 Pragma_Disable_Atomic_Synchronization => 0,
25646 Pragma_Discard_Names => 0,
25647 Pragma_Dispatching_Domain => -1,
25648 Pragma_Effective_Reads => 0,
25649 Pragma_Effective_Writes => 0,
25650 Pragma_Elaborate => 0,
25651 Pragma_Elaborate_All => 0,
25652 Pragma_Elaborate_Body => 0,
25653 Pragma_Elaboration_Checks => 0,
25654 Pragma_Eliminate => 0,
25655 Pragma_Enable_Atomic_Synchronization => 0,
25656 Pragma_Export => -1,
25657 Pragma_Export_Function => -1,
25658 Pragma_Export_Object => -1,
25659 Pragma_Export_Procedure => -1,
25660 Pragma_Export_Value => -1,
25661 Pragma_Export_Valued_Procedure => -1,
25662 Pragma_Extend_System => -1,
25663 Pragma_Extensions_Allowed => 0,
25664 Pragma_Extensions_Visible => 0,
25665 Pragma_External => -1,
25666 Pragma_Favor_Top_Level => 0,
25667 Pragma_External_Name_Casing => 0,
25668 Pragma_Fast_Math => 0,
25669 Pragma_Finalize_Storage_Only => 0,
25670 Pragma_Ghost => 0,
25671 Pragma_Global => -1,
25672 Pragma_Ident => -1,
25673 Pragma_Implementation_Defined => -1,
25674 Pragma_Implemented => -1,
25675 Pragma_Implicit_Packing => 0,
25676 Pragma_Import => 93,
25677 Pragma_Import_Function => 0,
25678 Pragma_Import_Object => 0,
25679 Pragma_Import_Procedure => 0,
25680 Pragma_Import_Valued_Procedure => 0,
25681 Pragma_Independent => 0,
25682 Pragma_Independent_Components => 0,
25683 Pragma_Initial_Condition => -1,
25684 Pragma_Initialize_Scalars => 0,
25685 Pragma_Initializes => -1,
25686 Pragma_Inline => 0,
25687 Pragma_Inline_Always => 0,
25688 Pragma_Inline_Generic => 0,
25689 Pragma_Inspection_Point => -1,
25690 Pragma_Interface => 92,
25691 Pragma_Interface_Name => 0,
25692 Pragma_Interrupt_Handler => -1,
25693 Pragma_Interrupt_Priority => -1,
25694 Pragma_Interrupt_State => -1,
25695 Pragma_Invariant => -1,
25696 Pragma_Java_Constructor => -1,
25697 Pragma_Java_Interface => -1,
25698 Pragma_Keep_Names => 0,
25699 Pragma_License => 0,
25700 Pragma_Link_With => -1,
25701 Pragma_Linker_Alias => -1,
25702 Pragma_Linker_Constructor => -1,
25703 Pragma_Linker_Destructor => -1,
25704 Pragma_Linker_Options => -1,
25705 Pragma_Linker_Section => 0,
25706 Pragma_List => 0,
25707 Pragma_Lock_Free => 0,
25708 Pragma_Locking_Policy => 0,
25709 Pragma_Loop_Invariant => -1,
25710 Pragma_Loop_Optimize => 0,
25711 Pragma_Loop_Variant => -1,
25712 Pragma_Machine_Attribute => -1,
25713 Pragma_Main => -1,
25714 Pragma_Main_Storage => -1,
25715 Pragma_Memory_Size => 0,
25716 Pragma_No_Return => 0,
25717 Pragma_No_Body => 0,
25718 Pragma_No_Elaboration_Code_All => 0,
25719 Pragma_No_Inline => 0,
25720 Pragma_No_Run_Time => -1,
25721 Pragma_No_Strict_Aliasing => -1,
25722 Pragma_No_Tagged_Streams => 0,
25723 Pragma_Normalize_Scalars => 0,
25724 Pragma_Obsolescent => 0,
25725 Pragma_Optimize => 0,
25726 Pragma_Optimize_Alignment => 0,
25727 Pragma_Overflow_Mode => 0,
25728 Pragma_Overriding_Renamings => 0,
25729 Pragma_Ordered => 0,
25730 Pragma_Pack => 0,
25731 Pragma_Page => 0,
25732 Pragma_Part_Of => 0,
25733 Pragma_Partition_Elaboration_Policy => 0,
25734 Pragma_Passive => 0,
25735 Pragma_Persistent_BSS => 0,
25736 Pragma_Polling => 0,
25737 Pragma_Prefix_Exception_Messages => 0,
25738 Pragma_Post => -1,
25739 Pragma_Postcondition => -1,
25740 Pragma_Post_Class => -1,
25741 Pragma_Pre => -1,
25742 Pragma_Precondition => -1,
25743 Pragma_Predicate => -1,
25744 Pragma_Preelaborable_Initialization => -1,
25745 Pragma_Preelaborate => 0,
25746 Pragma_Pre_Class => -1,
25747 Pragma_Priority => -1,
25748 Pragma_Priority_Specific_Dispatching => 0,
25749 Pragma_Profile => 0,
25750 Pragma_Profile_Warnings => 0,
25751 Pragma_Propagate_Exceptions => 0,
25752 Pragma_Provide_Shift_Operators => 0,
25753 Pragma_Psect_Object => 0,
25754 Pragma_Pure => 0,
25755 Pragma_Pure_Function => 0,
25756 Pragma_Queuing_Policy => 0,
25757 Pragma_Rational => 0,
25758 Pragma_Ravenscar => 0,
25759 Pragma_Refined_Depends => -1,
25760 Pragma_Refined_Global => -1,
25761 Pragma_Refined_Post => -1,
25762 Pragma_Refined_State => -1,
25763 Pragma_Relative_Deadline => 0,
25764 Pragma_Remote_Access_Type => -1,
25765 Pragma_Remote_Call_Interface => -1,
25766 Pragma_Remote_Types => -1,
25767 Pragma_Restricted_Run_Time => 0,
25768 Pragma_Restriction_Warnings => 0,
25769 Pragma_Restrictions => 0,
25770 Pragma_Reviewable => -1,
25771 Pragma_Short_Circuit_And_Or => 0,
25772 Pragma_Share_Generic => 0,
25773 Pragma_Shared => 0,
25774 Pragma_Shared_Passive => 0,
25775 Pragma_Short_Descriptors => 0,
25776 Pragma_Simple_Storage_Pool_Type => 0,
25777 Pragma_Source_File_Name => 0,
25778 Pragma_Source_File_Name_Project => 0,
25779 Pragma_Source_Reference => 0,
25780 Pragma_SPARK_Mode => 0,
25781 Pragma_Storage_Size => -1,
25782 Pragma_Storage_Unit => 0,
25783 Pragma_Static_Elaboration_Desired => 0,
25784 Pragma_Stream_Convert => 0,
25785 Pragma_Style_Checks => 0,
25786 Pragma_Subtitle => 0,
25787 Pragma_Suppress => 0,
25788 Pragma_Suppress_Exception_Locations => 0,
25789 Pragma_Suppress_All => 0,
25790 Pragma_Suppress_Debug_Info => 0,
25791 Pragma_Suppress_Initialization => 0,
25792 Pragma_System_Name => 0,
25793 Pragma_Task_Dispatching_Policy => 0,
25794 Pragma_Task_Info => -1,
25795 Pragma_Task_Name => -1,
25796 Pragma_Task_Storage => -1,
25797 Pragma_Test_Case => -1,
25798 Pragma_Thread_Local_Storage => -1,
25799 Pragma_Time_Slice => -1,
25800 Pragma_Title => 0,
25801 Pragma_Type_Invariant => -1,
25802 Pragma_Type_Invariant_Class => -1,
25803 Pragma_Unchecked_Union => 0,
25804 Pragma_Unimplemented_Unit => 0,
25805 Pragma_Universal_Aliasing => 0,
25806 Pragma_Universal_Data => 0,
25807 Pragma_Unmodified => 0,
25808 Pragma_Unreferenced => 0,
25809 Pragma_Unreferenced_Objects => 0,
25810 Pragma_Unreserve_All_Interrupts => 0,
25811 Pragma_Unsuppress => 0,
25812 Pragma_Unevaluated_Use_Of_Old => 0,
25813 Pragma_Use_VADS_Size => 0,
25814 Pragma_Validity_Checks => 0,
25815 Pragma_Volatile => 0,
25816 Pragma_Volatile_Components => 0,
25817 Pragma_Warning_As_Error => 0,
25818 Pragma_Warnings => 0,
25819 Pragma_Weak_External => 0,
25820 Pragma_Wide_Character_Encoding => 0,
25821 Unknown_Pragma => 0);
25823 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
25824 Id : Pragma_Id;
25825 P : Node_Id;
25826 C : Int;
25827 AN : Nat;
25829 function Arg_No return Nat;
25830 -- Returns an integer showing what argument we are in. A value of
25831 -- zero means we are not in any of the arguments.
25833 ------------
25834 -- Arg_No --
25835 ------------
25837 function Arg_No return Nat is
25838 A : Node_Id;
25839 N : Nat;
25841 begin
25842 A := First (Pragma_Argument_Associations (Parent (P)));
25843 N := 1;
25844 loop
25845 if No (A) then
25846 return 0;
25847 elsif A = P then
25848 return N;
25849 end if;
25851 Next (A);
25852 N := N + 1;
25853 end loop;
25854 end Arg_No;
25856 -- Start of processing for Non_Significant_Pragma_Reference
25858 begin
25859 P := Parent (N);
25861 if Nkind (P) /= N_Pragma_Argument_Association then
25862 return False;
25864 else
25865 Id := Get_Pragma_Id (Parent (P));
25866 C := Sig_Flags (Id);
25867 AN := Arg_No;
25869 if AN = 0 then
25870 return False;
25871 end if;
25873 case C is
25874 when -1 =>
25875 return False;
25877 when 0 =>
25878 return True;
25880 when 92 .. 99 =>
25881 return AN < (C - 90);
25883 when others =>
25884 return AN /= C;
25885 end case;
25886 end if;
25887 end Is_Non_Significant_Pragma_Reference;
25889 ------------------------------
25890 -- Is_Pragma_String_Literal --
25891 ------------------------------
25893 -- This function returns true if the corresponding pragma argument is a
25894 -- static string expression. These are the only cases in which string
25895 -- literals can appear as pragma arguments. We also allow a string literal
25896 -- as the first argument to pragma Assert (although it will of course
25897 -- always generate a type error).
25899 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
25900 Pragn : constant Node_Id := Parent (Par);
25901 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
25902 Pname : constant Name_Id := Pragma_Name (Pragn);
25903 Argn : Natural;
25904 N : Node_Id;
25906 begin
25907 Argn := 1;
25908 N := First (Assoc);
25909 loop
25910 exit when N = Par;
25911 Argn := Argn + 1;
25912 Next (N);
25913 end loop;
25915 if Pname = Name_Assert then
25916 return True;
25918 elsif Pname = Name_Export then
25919 return Argn > 2;
25921 elsif Pname = Name_Ident then
25922 return Argn = 1;
25924 elsif Pname = Name_Import then
25925 return Argn > 2;
25927 elsif Pname = Name_Interface_Name then
25928 return Argn > 1;
25930 elsif Pname = Name_Linker_Alias then
25931 return Argn = 2;
25933 elsif Pname = Name_Linker_Section then
25934 return Argn = 2;
25936 elsif Pname = Name_Machine_Attribute then
25937 return Argn = 2;
25939 elsif Pname = Name_Source_File_Name then
25940 return True;
25942 elsif Pname = Name_Source_Reference then
25943 return Argn = 2;
25945 elsif Pname = Name_Title then
25946 return True;
25948 elsif Pname = Name_Subtitle then
25949 return True;
25951 else
25952 return False;
25953 end if;
25954 end Is_Pragma_String_Literal;
25956 ---------------------------
25957 -- Is_Private_SPARK_Mode --
25958 ---------------------------
25960 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
25961 begin
25962 pragma Assert
25963 (Nkind (N) = N_Pragma
25964 and then Pragma_Name (N) = Name_SPARK_Mode
25965 and then Is_List_Member (N));
25967 -- For pragma SPARK_Mode to be private, it has to appear in the private
25968 -- declarations of a package.
25970 return
25971 Present (Parent (N))
25972 and then Nkind (Parent (N)) = N_Package_Specification
25973 and then List_Containing (N) = Private_Declarations (Parent (N));
25974 end Is_Private_SPARK_Mode;
25976 -------------------------------------
25977 -- Is_Unconstrained_Or_Tagged_Item --
25978 -------------------------------------
25980 function Is_Unconstrained_Or_Tagged_Item
25981 (Item : Entity_Id) return Boolean
25983 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
25984 -- Determine whether record type Typ has at least one unconstrained
25985 -- component.
25987 ---------------------------------
25988 -- Has_Unconstrained_Component --
25989 ---------------------------------
25991 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
25992 Comp : Entity_Id;
25994 begin
25995 Comp := First_Component (Typ);
25996 while Present (Comp) loop
25997 if Is_Unconstrained_Or_Tagged_Item (Comp) then
25998 return True;
25999 end if;
26001 Next_Component (Comp);
26002 end loop;
26004 return False;
26005 end Has_Unconstrained_Component;
26007 -- Local variables
26009 Typ : constant Entity_Id := Etype (Item);
26011 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
26013 begin
26014 if Is_Tagged_Type (Typ) then
26015 return True;
26017 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
26018 return True;
26020 elsif Is_Record_Type (Typ) then
26021 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
26022 return True;
26023 else
26024 return Has_Unconstrained_Component (Typ);
26025 end if;
26027 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
26028 return True;
26030 else
26031 return False;
26032 end if;
26033 end Is_Unconstrained_Or_Tagged_Item;
26035 -----------------------------
26036 -- Is_Valid_Assertion_Kind --
26037 -----------------------------
26039 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
26040 begin
26041 case Nam is
26042 when
26043 -- RM defined
26045 Name_Assert |
26046 Name_Static_Predicate |
26047 Name_Dynamic_Predicate |
26048 Name_Pre |
26049 Name_uPre |
26050 Name_Post |
26051 Name_uPost |
26052 Name_Type_Invariant |
26053 Name_uType_Invariant |
26055 -- Impl defined
26057 Name_Assert_And_Cut |
26058 Name_Assume |
26059 Name_Contract_Cases |
26060 Name_Debug |
26061 Name_Default_Initial_Condition |
26062 Name_Ghost |
26063 Name_Initial_Condition |
26064 Name_Invariant |
26065 Name_uInvariant |
26066 Name_Loop_Invariant |
26067 Name_Loop_Variant |
26068 Name_Postcondition |
26069 Name_Precondition |
26070 Name_Predicate |
26071 Name_Refined_Post |
26072 Name_Statement_Assertions => return True;
26074 when others => return False;
26075 end case;
26076 end Is_Valid_Assertion_Kind;
26078 -----------------------------------------
26079 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
26080 -----------------------------------------
26082 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
26083 Aspects : constant List_Id := New_List;
26084 Loc : constant Source_Ptr := Sloc (Decl);
26085 Or_Decl : constant Node_Id := Original_Node (Decl);
26087 Original_Aspects : List_Id;
26088 -- To capture global references, a copy of the created aspects must be
26089 -- inserted in the original tree.
26091 Prag : Node_Id;
26092 Prag_Arg_Ass : Node_Id;
26093 Prag_Id : Pragma_Id;
26095 begin
26096 -- Check for any PPC pragmas that appear within Decl
26098 Prag := Next (Decl);
26099 while Nkind (Prag) = N_Pragma loop
26100 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
26102 case Prag_Id is
26103 when Pragma_Postcondition | Pragma_Precondition =>
26104 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
26106 -- Make an aspect from any PPC pragma
26108 Append_To (Aspects,
26109 Make_Aspect_Specification (Loc,
26110 Identifier =>
26111 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
26112 Expression =>
26113 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
26115 -- Generate the analysis information in the pragma expression
26116 -- and then set the pragma node analyzed to avoid any further
26117 -- analysis.
26119 Analyze (Expression (Prag_Arg_Ass));
26120 Set_Analyzed (Prag, True);
26122 when others => null;
26123 end case;
26125 Next (Prag);
26126 end loop;
26128 -- Set all new aspects into the generic declaration node
26130 if Is_Non_Empty_List (Aspects) then
26132 -- Create the list of aspects to be inserted in the original tree
26134 Original_Aspects := Copy_Separate_List (Aspects);
26136 -- Check if Decl already has aspects
26138 -- Attach the new lists of aspects to both the generic copy and the
26139 -- original tree.
26141 if Has_Aspects (Decl) then
26142 Append_List (Aspects, Aspect_Specifications (Decl));
26143 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
26145 else
26146 Set_Parent (Aspects, Decl);
26147 Set_Aspect_Specifications (Decl, Aspects);
26148 Set_Parent (Original_Aspects, Or_Decl);
26149 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
26150 end if;
26151 end if;
26152 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
26154 -------------------------
26155 -- Preanalyze_CTC_Args --
26156 -------------------------
26158 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
26159 begin
26160 -- Preanalyze the boolean expressions, we treat these as spec
26161 -- expressions (i.e. similar to a default expression).
26163 if Present (Arg_Req) then
26164 Preanalyze_Assert_Expression
26165 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
26167 -- In ASIS mode, for a pragma generated from a source aspect, also
26168 -- analyze the original aspect expression.
26170 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
26171 Preanalyze_Assert_Expression
26172 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
26173 end if;
26174 end if;
26176 if Present (Arg_Ens) then
26177 Preanalyze_Assert_Expression
26178 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
26180 -- In ASIS mode, for a pragma generated from a source aspect, also
26181 -- analyze the original aspect expression.
26183 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
26184 Preanalyze_Assert_Expression
26185 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
26186 end if;
26187 end if;
26188 end Preanalyze_CTC_Args;
26190 --------------------------------------
26191 -- Process_Compilation_Unit_Pragmas --
26192 --------------------------------------
26194 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
26195 begin
26196 -- A special check for pragma Suppress_All, a very strange DEC pragma,
26197 -- strange because it comes at the end of the unit. Rational has the
26198 -- same name for a pragma, but treats it as a program unit pragma, In
26199 -- GNAT we just decide to allow it anywhere at all. If it appeared then
26200 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
26201 -- node, and we insert a pragma Suppress (All_Checks) at the start of
26202 -- the context clause to ensure the correct processing.
26204 if Has_Pragma_Suppress_All (N) then
26205 Prepend_To (Context_Items (N),
26206 Make_Pragma (Sloc (N),
26207 Chars => Name_Suppress,
26208 Pragma_Argument_Associations => New_List (
26209 Make_Pragma_Argument_Association (Sloc (N),
26210 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
26211 end if;
26213 -- Nothing else to do at the current time
26215 end Process_Compilation_Unit_Pragmas;
26217 ------------------------------------
26218 -- Record_Possible_Body_Reference --
26219 ------------------------------------
26221 procedure Record_Possible_Body_Reference
26222 (State_Id : Entity_Id;
26223 Ref : Node_Id)
26225 Context : Node_Id;
26226 Spec_Id : Entity_Id;
26228 begin
26229 -- Ensure that we are dealing with a reference to a state
26231 pragma Assert (Ekind (State_Id) = E_Abstract_State);
26233 -- Climb the tree starting from the reference looking for a package body
26234 -- whose spec declares the referenced state. This criteria automatically
26235 -- excludes references in package specs which are legal. Note that it is
26236 -- not wise to emit an error now as the package body may lack pragma
26237 -- Refined_State or the referenced state may not be mentioned in the
26238 -- refinement. This approach avoids the generation of misleading errors.
26240 Context := Ref;
26241 while Present (Context) loop
26242 if Nkind (Context) = N_Package_Body then
26243 Spec_Id := Corresponding_Spec (Context);
26245 if Present (Abstract_States (Spec_Id))
26246 and then Contains (Abstract_States (Spec_Id), State_Id)
26247 then
26248 if No (Body_References (State_Id)) then
26249 Set_Body_References (State_Id, New_Elmt_List);
26250 end if;
26252 Append_Elmt (Ref, To => Body_References (State_Id));
26253 exit;
26254 end if;
26255 end if;
26257 Context := Parent (Context);
26258 end loop;
26259 end Record_Possible_Body_Reference;
26261 ------------------------------
26262 -- Relocate_Pragmas_To_Body --
26263 ------------------------------
26265 procedure Relocate_Pragmas_To_Body
26266 (Subp_Body : Node_Id;
26267 Target_Body : Node_Id := Empty)
26269 procedure Relocate_Pragma (Prag : Node_Id);
26270 -- Remove a single pragma from its current list and add it to the
26271 -- declarations of the proper body (either Subp_Body or Target_Body).
26273 ---------------------
26274 -- Relocate_Pragma --
26275 ---------------------
26277 procedure Relocate_Pragma (Prag : Node_Id) is
26278 Decls : List_Id;
26279 Target : Node_Id;
26281 begin
26282 -- When subprogram stubs or expression functions are involves, the
26283 -- destination declaration list belongs to the proper body.
26285 if Present (Target_Body) then
26286 Target := Target_Body;
26287 else
26288 Target := Subp_Body;
26289 end if;
26291 Decls := Declarations (Target);
26293 if No (Decls) then
26294 Decls := New_List;
26295 Set_Declarations (Target, Decls);
26296 end if;
26298 -- Unhook the pragma from its current list
26300 Remove (Prag);
26301 Prepend (Prag, Decls);
26302 end Relocate_Pragma;
26304 -- Local variables
26306 Body_Id : constant Entity_Id :=
26307 Defining_Unit_Name (Specification (Subp_Body));
26308 Next_Stmt : Node_Id;
26309 Stmt : Node_Id;
26311 -- Start of processing for Relocate_Pragmas_To_Body
26313 begin
26314 -- Do not process a body that comes from a separate unit as no construct
26315 -- can possibly follow it.
26317 if not Is_List_Member (Subp_Body) then
26318 return;
26320 -- Do not relocate pragmas that follow a stub if the stub does not have
26321 -- a proper body.
26323 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
26324 and then No (Target_Body)
26325 then
26326 return;
26328 -- Do not process internally generated routine _Postconditions
26330 elsif Ekind (Body_Id) = E_Procedure
26331 and then Chars (Body_Id) = Name_uPostconditions
26332 then
26333 return;
26334 end if;
26336 -- Look at what is following the body. We are interested in certain kind
26337 -- of pragmas (either from source or byproducts of expansion) that can
26338 -- apply to a body [stub].
26340 Stmt := Next (Subp_Body);
26341 while Present (Stmt) loop
26343 -- Preserve the following statement for iteration purposes due to a
26344 -- possible relocation of a pragma.
26346 Next_Stmt := Next (Stmt);
26348 -- Move a candidate pragma following the body to the declarations of
26349 -- the body.
26351 if Nkind (Stmt) = N_Pragma
26352 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
26353 then
26354 Relocate_Pragma (Stmt);
26356 -- Skip internally generated code
26358 elsif not Comes_From_Source (Stmt) then
26359 null;
26361 -- No candidate pragmas are available for relocation
26363 else
26364 exit;
26365 end if;
26367 Stmt := Next_Stmt;
26368 end loop;
26369 end Relocate_Pragmas_To_Body;
26371 -------------------
26372 -- Resolve_State --
26373 -------------------
26375 procedure Resolve_State (N : Node_Id) is
26376 Func : Entity_Id;
26377 State : Entity_Id;
26379 begin
26380 if Is_Entity_Name (N) and then Present (Entity (N)) then
26381 Func := Entity (N);
26383 -- Handle overloading of state names by functions. Traverse the
26384 -- homonym chain looking for an abstract state.
26386 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
26387 State := Homonym (Func);
26388 while Present (State) loop
26390 -- Resolve the overloading by setting the proper entity of the
26391 -- reference to that of the state.
26393 if Ekind (State) = E_Abstract_State then
26394 Set_Etype (N, Standard_Void_Type);
26395 Set_Entity (N, State);
26396 Set_Associated_Node (N, State);
26397 return;
26398 end if;
26400 State := Homonym (State);
26401 end loop;
26403 -- A function can never act as a state. If the homonym chain does
26404 -- not contain a corresponding state, then something went wrong in
26405 -- the overloading mechanism.
26407 raise Program_Error;
26408 end if;
26409 end if;
26410 end Resolve_State;
26412 ----------------------------
26413 -- Rewrite_Assertion_Kind --
26414 ----------------------------
26416 procedure Rewrite_Assertion_Kind (N : Node_Id) is
26417 Nam : Name_Id;
26419 begin
26420 if Nkind (N) = N_Attribute_Reference
26421 and then Attribute_Name (N) = Name_Class
26422 and then Nkind (Prefix (N)) = N_Identifier
26423 then
26424 case Chars (Prefix (N)) is
26425 when Name_Pre =>
26426 Nam := Name_uPre;
26427 when Name_Post =>
26428 Nam := Name_uPost;
26429 when Name_Type_Invariant =>
26430 Nam := Name_uType_Invariant;
26431 when Name_Invariant =>
26432 Nam := Name_uInvariant;
26433 when others =>
26434 return;
26435 end case;
26437 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
26438 end if;
26439 end Rewrite_Assertion_Kind;
26441 --------
26442 -- rv --
26443 --------
26445 procedure rv is
26446 begin
26447 Dummy := Dummy + 1;
26448 end rv;
26450 --------------------------------
26451 -- Set_Encoded_Interface_Name --
26452 --------------------------------
26454 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
26455 Str : constant String_Id := Strval (S);
26456 Len : constant Int := String_Length (Str);
26457 CC : Char_Code;
26458 C : Character;
26459 J : Int;
26461 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
26463 procedure Encode;
26464 -- Stores encoded value of character code CC. The encoding we use an
26465 -- underscore followed by four lower case hex digits.
26467 ------------
26468 -- Encode --
26469 ------------
26471 procedure Encode is
26472 begin
26473 Store_String_Char (Get_Char_Code ('_'));
26474 Store_String_Char
26475 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
26476 Store_String_Char
26477 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
26478 Store_String_Char
26479 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
26480 Store_String_Char
26481 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
26482 end Encode;
26484 -- Start of processing for Set_Encoded_Interface_Name
26486 begin
26487 -- If first character is asterisk, this is a link name, and we leave it
26488 -- completely unmodified. We also ignore null strings (the latter case
26489 -- happens only in error cases) and no encoding should occur for Java or
26490 -- AAMP interface names.
26492 if Len = 0
26493 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
26494 or else VM_Target /= No_VM
26495 or else AAMP_On_Target
26496 then
26497 Set_Interface_Name (E, S);
26499 else
26500 J := 1;
26501 loop
26502 CC := Get_String_Char (Str, J);
26504 exit when not In_Character_Range (CC);
26506 C := Get_Character (CC);
26508 exit when C /= '_' and then C /= '$'
26509 and then C not in '0' .. '9'
26510 and then C not in 'a' .. 'z'
26511 and then C not in 'A' .. 'Z';
26513 if J = Len then
26514 Set_Interface_Name (E, S);
26515 return;
26517 else
26518 J := J + 1;
26519 end if;
26520 end loop;
26522 -- Here we need to encode. The encoding we use as follows:
26523 -- three underscores + four hex digits (lower case)
26525 Start_String;
26527 for J in 1 .. String_Length (Str) loop
26528 CC := Get_String_Char (Str, J);
26530 if not In_Character_Range (CC) then
26531 Encode;
26532 else
26533 C := Get_Character (CC);
26535 if C = '_' or else C = '$'
26536 or else C in '0' .. '9'
26537 or else C in 'a' .. 'z'
26538 or else C in 'A' .. 'Z'
26539 then
26540 Store_String_Char (CC);
26541 else
26542 Encode;
26543 end if;
26544 end if;
26545 end loop;
26547 Set_Interface_Name (E,
26548 Make_String_Literal (Sloc (S),
26549 Strval => End_String));
26550 end if;
26551 end Set_Encoded_Interface_Name;
26553 -------------------
26554 -- Set_Unit_Name --
26555 -------------------
26557 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
26558 Pref : Node_Id;
26559 Scop : Entity_Id;
26561 begin
26562 if Nkind (N) = N_Identifier
26563 and then Nkind (With_Item) = N_Identifier
26564 then
26565 Set_Entity (N, Entity (With_Item));
26567 elsif Nkind (N) = N_Selected_Component then
26568 Change_Selected_Component_To_Expanded_Name (N);
26569 Set_Entity (N, Entity (With_Item));
26570 Set_Entity (Selector_Name (N), Entity (N));
26572 Pref := Prefix (N);
26573 Scop := Scope (Entity (N));
26574 while Nkind (Pref) = N_Selected_Component loop
26575 Change_Selected_Component_To_Expanded_Name (Pref);
26576 Set_Entity (Selector_Name (Pref), Scop);
26577 Set_Entity (Pref, Scop);
26578 Pref := Prefix (Pref);
26579 Scop := Scope (Scop);
26580 end loop;
26582 Set_Entity (Pref, Scop);
26583 end if;
26584 end Set_Unit_Name;
26586 end Sem_Prag;