]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/sem_prag.adb
[Ada] Iterate with procedural versions of Next_... routines where possible
[thirdparty/gcc.git] / gcc / ada / sem_prag.adb
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-2020, 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 ------------------------------------------------------------------------------
25
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).
31
32 with Aspects; use Aspects;
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Checks; use Checks;
36 with Contracts; use Contracts;
37 with Csets; use Csets;
38 with Debug; use Debug;
39 with Einfo; use Einfo;
40 with Elists; use Elists;
41 with Errout; use Errout;
42 with Exp_Dist; use Exp_Dist;
43 with Exp_Util; use Exp_Util;
44 with Expander; use Expander;
45 with Freeze; use Freeze;
46 with Ghost; use Ghost;
47 with Gnatvsn; use Gnatvsn;
48 with Lib; use Lib;
49 with Lib.Writ; use Lib.Writ;
50 with Lib.Xref; use Lib.Xref;
51 with Namet.Sp; use Namet.Sp;
52 with Nlists; use Nlists;
53 with Nmake; use Nmake;
54 with Output; use Output;
55 with Par_SCO; use Par_SCO;
56 with Restrict; use Restrict;
57 with Rident; use Rident;
58 with Rtsfind; use Rtsfind;
59 with Sem; use Sem;
60 with Sem_Aux; use Sem_Aux;
61 with Sem_Ch3; use Sem_Ch3;
62 with Sem_Ch6; use Sem_Ch6;
63 with Sem_Ch8; use Sem_Ch8;
64 with Sem_Ch12; use Sem_Ch12;
65 with Sem_Ch13; use Sem_Ch13;
66 with Sem_Disp; use Sem_Disp;
67 with Sem_Dist; use Sem_Dist;
68 with Sem_Elab; use Sem_Elab;
69 with Sem_Elim; use Sem_Elim;
70 with Sem_Eval; use Sem_Eval;
71 with Sem_Intr; use Sem_Intr;
72 with Sem_Mech; use Sem_Mech;
73 with Sem_Res; use Sem_Res;
74 with Sem_Type; use Sem_Type;
75 with Sem_Util; use Sem_Util;
76 with Sem_Warn; use Sem_Warn;
77 with Stand; use Stand;
78 with Sinfo; use Sinfo;
79 with Sinfo.CN; use Sinfo.CN;
80 with Sinput; use Sinput;
81 with Stringt; use Stringt;
82 with Stylesw; use Stylesw;
83 with Table;
84 with Targparm; use Targparm;
85 with Tbuild; use Tbuild;
86 with Ttypes;
87 with Uintp; use Uintp;
88 with Uname; use Uname;
89 with Urealp; use Urealp;
90 with Validsw; use Validsw;
91 with Warnsw; use Warnsw;
92
93 with System.Case_Util;
94
95 package body Sem_Prag is
96
97 ----------------------------------------------
98 -- Common Handling of Import-Export Pragmas --
99 ----------------------------------------------
100
101 -- In the following section, a number of Import_xxx and Export_xxx pragmas
102 -- are defined by GNAT. These are compatible with the DEC pragmas of the
103 -- same name, and all have the following common form and processing:
104
105 -- pragma Export_xxx
106 -- [Internal =>] LOCAL_NAME
107 -- [, [External =>] EXTERNAL_SYMBOL]
108 -- [, other optional parameters ]);
109
110 -- pragma Import_xxx
111 -- [Internal =>] LOCAL_NAME
112 -- [, [External =>] EXTERNAL_SYMBOL]
113 -- [, other optional parameters ]);
114
115 -- EXTERNAL_SYMBOL ::=
116 -- IDENTIFIER
117 -- | static_string_EXPRESSION
118
119 -- The internal LOCAL_NAME designates the entity that is imported or
120 -- exported, and must refer to an entity in the current declarative
121 -- part (as required by the rules for LOCAL_NAME).
122
123 -- The external linker name is designated by the External parameter if
124 -- given, or the Internal parameter if not (if there is no External
125 -- parameter, the External parameter is a copy of the Internal name).
126
127 -- If the External parameter is given as a string, then this string is
128 -- treated as an external name (exactly as though it had been given as an
129 -- External_Name parameter for a normal Import pragma).
130
131 -- If the External parameter is given as an identifier (or there is no
132 -- External parameter, so that the Internal identifier is used), then
133 -- the external name is the characters of the identifier, translated
134 -- to all lower case letters.
135
136 -- Note: the external name specified or implied by any of these special
137 -- Import_xxx or Export_xxx pragmas override an external or link name
138 -- specified in a previous Import or Export pragma.
139
140 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
141 -- named notation, following the standard rules for subprogram calls, i.e.
142 -- parameters can be given in any order if named notation is used, and
143 -- positional and named notation can be mixed, subject to the rule that all
144 -- positional parameters must appear first.
145
146 -- Note: All these pragmas are implemented exactly following the DEC design
147 -- and implementation and are intended to be fully compatible with the use
148 -- of these pragmas in the DEC Ada compiler.
149
150 --------------------------------------------
151 -- Checking for Duplicated External Names --
152 --------------------------------------------
153
154 -- It is suspicious if two separate Export pragmas use the same external
155 -- name. The following table is used to diagnose this situation so that
156 -- an appropriate warning can be issued.
157
158 -- The Node_Id stored is for the N_String_Literal node created to hold
159 -- the value of the external name. The Sloc of this node is used to
160 -- cross-reference the location of the duplication.
161
162 package Externals is new Table.Table (
163 Table_Component_Type => Node_Id,
164 Table_Index_Type => Int,
165 Table_Low_Bound => 0,
166 Table_Initial => 100,
167 Table_Increment => 100,
168 Table_Name => "Name_Externals");
169
170 -------------------------------------
171 -- Local Subprograms and Variables --
172 -------------------------------------
173
174 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
175 -- This routine is used for possible casing adjustment of an explicit
176 -- external name supplied as a string literal (the node N), according to
177 -- the casing requirement of Opt.External_Name_Casing. If this is set to
178 -- As_Is, then the string literal is returned unchanged, but if it is set
179 -- to Uppercase or Lowercase, then a new string literal with appropriate
180 -- casing is constructed.
181
182 procedure Analyze_Part_Of
183 (Indic : Node_Id;
184 Item_Id : Entity_Id;
185 Encap : Node_Id;
186 Encap_Id : out Entity_Id;
187 Legal : out Boolean);
188 -- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and
189 -- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the
190 -- Part_Of indicator. Item_Id is the entity of an abstract state, object or
191 -- package instantiation. Encap denotes the encapsulating state or single
192 -- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when
193 -- the indicator is legal.
194
195 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
196 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
197 -- Query whether a particular item appears in a mixed list of nodes and
198 -- entities. It is assumed that all nodes in the list have entities.
199
200 procedure Check_Postcondition_Use_In_Inlined_Subprogram
201 (Prag : Node_Id;
202 Spec_Id : Entity_Id);
203 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
204 -- Precondition, Refined_Post, and Test_Case. Emit a warning when pragma
205 -- Prag is associated with subprogram Spec_Id subject to Inline_Always,
206 -- and assertions are enabled.
207
208 procedure Check_State_And_Constituent_Use
209 (States : Elist_Id;
210 Constits : Elist_Id;
211 Context : Node_Id);
212 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
213 -- Global and Initializes. Determine whether a state from list States and a
214 -- corresponding constituent from list Constits (if any) appear in the same
215 -- context denoted by Context. If this is the case, emit an error.
216
217 procedure Contract_Freeze_Error
218 (Contract_Id : Entity_Id;
219 Freeze_Id : Entity_Id);
220 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and
221 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity
222 -- of a body which caused contract freezing and Contract_Id denotes the
223 -- entity of the affected contstruct.
224
225 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id);
226 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma
227 -- Prag that duplicates previous pragma Prev.
228
229 function Find_Encapsulating_State
230 (States : Elist_Id;
231 Constit_Id : Entity_Id) return Entity_Id;
232 -- Given the entity of a constituent Constit_Id, find the corresponding
233 -- encapsulating state which appears in States. The routine returns Empty
234 -- if no such state is found.
235
236 function Find_Related_Context
237 (Prag : Node_Id;
238 Do_Checks : Boolean := False) return Node_Id;
239 -- Subsidiary to the analysis of pragmas
240 -- Async_Readers
241 -- Async_Writers
242 -- Constant_After_Elaboration
243 -- Effective_Reads
244 -- Effective_Writers
245 -- Part_Of
246 -- Find the first source declaration or statement found while traversing
247 -- the previous node chain starting from pragma Prag. If flag Do_Checks is
248 -- set, the routine reports duplicate pragmas. The routine returns Empty
249 -- when reaching the start of the node chain.
250
251 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
252 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
253 -- original one, following the renaming chain) is returned. Otherwise the
254 -- entity is returned unchanged. Should be in Einfo???
255
256 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
257 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
258 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
259 -- value of type SPARK_Mode_Type.
260
261 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
262 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
263 -- Determine whether dependency clause Clause is surrounded by extra
264 -- parentheses. If this is the case, issue an error message.
265
266 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
267 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
268 -- pragma Depends. Determine whether the type of dependency item Item is
269 -- tagged, unconstrained array, unconstrained record or a record with at
270 -- least one unconstrained component.
271
272 procedure Record_Possible_Body_Reference
273 (State_Id : Entity_Id;
274 Ref : Node_Id);
275 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
276 -- Global. Given an abstract state denoted by State_Id and a reference Ref
277 -- to it, determine whether the reference appears in a package body that
278 -- will eventually refine the state. If this is the case, record the
279 -- reference for future checks (see Analyze_Refined_State_In_Decls).
280
281 procedure Resolve_State (N : Node_Id);
282 -- Handle the overloading of state names by functions. When N denotes a
283 -- function, this routine finds the corresponding state and sets the entity
284 -- of N to that of the state.
285
286 procedure Rewrite_Assertion_Kind
287 (N : Node_Id;
288 From_Policy : Boolean := False);
289 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
290 -- then it is rewritten as an identifier with the corresponding special
291 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
292 -- and Check_Policy. If the names are Precondition or Postcondition, this
293 -- combination is deprecated in favor of Assertion_Policy and Ada2012
294 -- Aspect names. The parameter From_Policy indicates that the pragma
295 -- is the old non-standard Check_Policy and not a rewritten pragma.
296
297 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
298 -- Place semantic information on the argument of an Elaborate/Elaborate_All
299 -- pragma. Entity name for unit and its parents is taken from item in
300 -- previous with_clause that mentions the unit.
301
302 procedure Validate_Compile_Time_Warning_Or_Error
303 (N : Node_Id;
304 Eloc : Source_Ptr);
305 -- Common processing for Compile_Time_Error and Compile_Time_Warning of
306 -- pragma N. Called when the pragma is processed as part of its regular
307 -- analysis but also called after calling the back end to validate these
308 -- pragmas for size and alignment appropriateness.
309
310 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id);
311 -- N is a pragma Compile_Time_Error or Compile_Warning_Error whose boolean
312 -- expression is not known at compile time during the front end. This
313 -- procedure makes an entry in a table. The actual checking is performed by
314 -- Validate_Compile_Time_Warning_Errors, which is invoked after calling the
315 -- back end.
316
317 Dummy : Integer := 0;
318 pragma Volatile (Dummy);
319 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
320
321 procedure ip;
322 pragma No_Inline (ip);
323 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
324 -- is just to help debugging the front end. If a pragma Inspection_Point
325 -- is added to a source program, then breaking on ip will get you to that
326 -- point in the program.
327
328 procedure rv;
329 pragma No_Inline (rv);
330 -- This is a dummy function called by the processing for pragma Reviewable.
331 -- It is there for assisting front end debugging. By placing a Reviewable
332 -- pragma in the source program, a breakpoint on rv catches this place in
333 -- the source, allowing convenient stepping to the point of interest.
334
335 ------------------------------------------------------
336 -- Table for Defer_Compile_Time_Warning_Error_To_BE --
337 ------------------------------------------------------
338
339 -- The following table collects pragmas Compile_Time_Error and Compile_
340 -- Time_Warning for validation. Entries are made by calls to subprogram
341 -- Defer_Compile_Time_Warning_Error_To_BE, and the call to the procedure
342 -- Validate_Compile_Time_Warning_Errors does the actual error checking
343 -- and posting of warning and error messages. The reason for this delayed
344 -- processing is to take advantage of back-annotations of attributes size
345 -- and alignment values performed by the back end.
346
347 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
348 -- that by the time Validate_Compile_Time_Warning_Errors is called, Sprint
349 -- will already have modified all Sloc values if the -gnatD option is set.
350
351 type CTWE_Entry is record
352 Eloc : Source_Ptr;
353 -- Source location used in warnings and error messages
354
355 Prag : Node_Id;
356 -- Pragma Compile_Time_Error or Compile_Time_Warning
357
358 Scope : Node_Id;
359 -- The scope which encloses the pragma
360 end record;
361
362 package Compile_Time_Warnings_Errors is new Table.Table (
363 Table_Component_Type => CTWE_Entry,
364 Table_Index_Type => Int,
365 Table_Low_Bound => 1,
366 Table_Initial => 50,
367 Table_Increment => 200,
368 Table_Name => "Compile_Time_Warnings_Errors");
369
370 -------------------------------
371 -- Adjust_External_Name_Case --
372 -------------------------------
373
374 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
375 CC : Char_Code;
376
377 begin
378 -- Adjust case of literal if required
379
380 if Opt.External_Name_Exp_Casing = As_Is then
381 return N;
382
383 else
384 -- Copy existing string
385
386 Start_String;
387
388 -- Set proper casing
389
390 for J in 1 .. String_Length (Strval (N)) loop
391 CC := Get_String_Char (Strval (N), J);
392
393 if Opt.External_Name_Exp_Casing = Uppercase
394 and then CC >= Get_Char_Code ('a')
395 and then CC <= Get_Char_Code ('z')
396 then
397 Store_String_Char (CC - 32);
398
399 elsif Opt.External_Name_Exp_Casing = Lowercase
400 and then CC >= Get_Char_Code ('A')
401 and then CC <= Get_Char_Code ('Z')
402 then
403 Store_String_Char (CC + 32);
404
405 else
406 Store_String_Char (CC);
407 end if;
408 end loop;
409
410 return
411 Make_String_Literal (Sloc (N),
412 Strval => End_String);
413 end if;
414 end Adjust_External_Name_Case;
415
416 -----------------------------------------
417 -- Analyze_Contract_Cases_In_Decl_Part --
418 -----------------------------------------
419
420 -- WARNING: This routine manages Ghost regions. Return statements must be
421 -- replaced by gotos which jump to the end of the routine and restore the
422 -- Ghost mode.
423
424 procedure Analyze_Contract_Cases_In_Decl_Part
425 (N : Node_Id;
426 Freeze_Id : Entity_Id := Empty)
427 is
428 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
429 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
430
431 Others_Seen : Boolean := False;
432 -- This flag is set when an "others" choice is encountered. It is used
433 -- to detect multiple illegal occurrences of "others".
434
435 procedure Analyze_Contract_Case (CCase : Node_Id);
436 -- Verify the legality of a single contract case
437
438 ---------------------------
439 -- Analyze_Contract_Case --
440 ---------------------------
441
442 procedure Analyze_Contract_Case (CCase : Node_Id) is
443 Case_Guard : Node_Id;
444 Conseq : Node_Id;
445 Errors : Nat;
446 Extra_Guard : Node_Id;
447
448 begin
449 if Nkind (CCase) = N_Component_Association then
450 Case_Guard := First (Choices (CCase));
451 Conseq := Expression (CCase);
452
453 -- Each contract case must have exactly one case guard
454
455 Extra_Guard := Next (Case_Guard);
456
457 if Present (Extra_Guard) then
458 Error_Msg_N
459 ("contract case must have exactly one case guard",
460 Extra_Guard);
461 end if;
462
463 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
464
465 if Nkind (Case_Guard) = N_Others_Choice then
466 if Others_Seen then
467 Error_Msg_N
468 ("only one others choice allowed in contract cases",
469 Case_Guard);
470 else
471 Others_Seen := True;
472 end if;
473
474 elsif Others_Seen then
475 Error_Msg_N
476 ("others must be the last choice in contract cases", N);
477 end if;
478
479 -- Preanalyze the case guard and consequence
480
481 if Nkind (Case_Guard) /= N_Others_Choice then
482 Errors := Serious_Errors_Detected;
483 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
484
485 -- Emit a clarification message when the case guard contains
486 -- at least one undefined reference, possibly due to contract
487 -- freezing.
488
489 if Errors /= Serious_Errors_Detected
490 and then Present (Freeze_Id)
491 and then Has_Undefined_Reference (Case_Guard)
492 then
493 Contract_Freeze_Error (Spec_Id, Freeze_Id);
494 end if;
495 end if;
496
497 Errors := Serious_Errors_Detected;
498 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
499
500 -- Emit a clarification message when the consequence contains
501 -- at least one undefined reference, possibly due to contract
502 -- freezing.
503
504 if Errors /= Serious_Errors_Detected
505 and then Present (Freeze_Id)
506 and then Has_Undefined_Reference (Conseq)
507 then
508 Contract_Freeze_Error (Spec_Id, Freeze_Id);
509 end if;
510
511 -- The contract case is malformed
512
513 else
514 Error_Msg_N ("wrong syntax in contract case", CCase);
515 end if;
516 end Analyze_Contract_Case;
517
518 -- Local variables
519
520 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
521
522 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
523 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
524 -- Save the Ghost-related attributes to restore on exit
525
526 CCase : Node_Id;
527 Restore_Scope : Boolean := False;
528
529 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
530
531 begin
532 -- Do not analyze the pragma multiple times
533
534 if Is_Analyzed_Pragma (N) then
535 return;
536 end if;
537
538 -- Set the Ghost mode in effect from the pragma. Due to the delayed
539 -- analysis of the pragma, the Ghost mode at point of declaration and
540 -- point of analysis may not necessarily be the same. Use the mode in
541 -- effect at the point of declaration.
542
543 Set_Ghost_Mode (N);
544
545 -- Single and multiple contract cases must appear in aggregate form. If
546 -- this is not the case, then either the parser of the analysis of the
547 -- pragma failed to produce an aggregate.
548
549 pragma Assert (Nkind (CCases) = N_Aggregate);
550
551 if Present (Component_Associations (CCases)) then
552
553 -- Ensure that the formal parameters are visible when analyzing all
554 -- clauses. This falls out of the general rule of aspects pertaining
555 -- to subprogram declarations.
556
557 if not In_Open_Scopes (Spec_Id) then
558 Restore_Scope := True;
559 Push_Scope (Spec_Id);
560
561 if Is_Generic_Subprogram (Spec_Id) then
562 Install_Generic_Formals (Spec_Id);
563 else
564 Install_Formals (Spec_Id);
565 end if;
566 end if;
567
568 CCase := First (Component_Associations (CCases));
569 while Present (CCase) loop
570 Analyze_Contract_Case (CCase);
571 Next (CCase);
572 end loop;
573
574 if Restore_Scope then
575 End_Scope;
576 end if;
577
578 -- Currently it is not possible to inline pre/postconditions on a
579 -- subprogram subject to pragma Inline_Always.
580
581 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
582
583 -- Otherwise the pragma is illegal
584
585 else
586 Error_Msg_N ("wrong syntax for constract cases", N);
587 end if;
588
589 Set_Is_Analyzed_Pragma (N);
590
591 Restore_Ghost_Region (Saved_GM, Saved_IGR);
592 end Analyze_Contract_Cases_In_Decl_Part;
593
594 ----------------------------------
595 -- Analyze_Depends_In_Decl_Part --
596 ----------------------------------
597
598 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
599 Loc : constant Source_Ptr := Sloc (N);
600 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
601 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
602
603 All_Inputs_Seen : Elist_Id := No_Elist;
604 -- A list containing the entities of all the inputs processed so far.
605 -- The list is populated with unique entities because the same input
606 -- may appear in multiple input lists.
607
608 All_Outputs_Seen : Elist_Id := No_Elist;
609 -- A list containing the entities of all the outputs processed so far.
610 -- The list is populated with unique entities because output items are
611 -- unique in a dependence relation.
612
613 Constits_Seen : Elist_Id := No_Elist;
614 -- A list containing the entities of all constituents processed so far.
615 -- It aids in detecting illegal usage of a state and a corresponding
616 -- constituent in pragma [Refinde_]Depends.
617
618 Global_Seen : Boolean := False;
619 -- A flag set when pragma Global has been processed
620
621 Null_Output_Seen : Boolean := False;
622 -- A flag used to track the legality of a null output
623
624 Result_Seen : Boolean := False;
625 -- A flag set when Spec_Id'Result is processed
626
627 States_Seen : Elist_Id := No_Elist;
628 -- A list containing the entities of all states processed so far. It
629 -- helps in detecting illegal usage of a state and a corresponding
630 -- constituent in pragma [Refined_]Depends.
631
632 Subp_Inputs : Elist_Id := No_Elist;
633 Subp_Outputs : Elist_Id := No_Elist;
634 -- Two lists containing the full set of inputs and output of the related
635 -- subprograms. Note that these lists contain both nodes and entities.
636
637 Task_Input_Seen : Boolean := False;
638 Task_Output_Seen : Boolean := False;
639 -- Flags used to track the implicit dependence of a task unit on itself
640
641 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
642 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
643 -- to the name buffer. The individual kinds are as follows:
644 -- E_Abstract_State - "state"
645 -- E_Constant - "constant"
646 -- E_Generic_In_Out_Parameter - "generic parameter"
647 -- E_Generic_In_Parameter - "generic parameter"
648 -- E_In_Parameter - "parameter"
649 -- E_In_Out_Parameter - "parameter"
650 -- E_Loop_Parameter - "loop parameter"
651 -- E_Out_Parameter - "parameter"
652 -- E_Protected_Type - "current instance of protected type"
653 -- E_Task_Type - "current instance of task type"
654 -- E_Variable - "global"
655
656 procedure Analyze_Dependency_Clause
657 (Clause : Node_Id;
658 Is_Last : Boolean);
659 -- Verify the legality of a single dependency clause. Flag Is_Last
660 -- denotes whether Clause is the last clause in the relation.
661
662 procedure Check_Function_Return;
663 -- Verify that Funtion'Result appears as one of the outputs
664 -- (SPARK RM 6.1.5(10)).
665
666 procedure Check_Role
667 (Item : Node_Id;
668 Item_Id : Entity_Id;
669 Is_Input : Boolean;
670 Self_Ref : Boolean);
671 -- Ensure that an item fulfills its designated input and/or output role
672 -- as specified by pragma Global (if any) or the enclosing context. If
673 -- this is not the case, emit an error. Item and Item_Id denote the
674 -- attributes of an item. Flag Is_Input should be set when item comes
675 -- from an input list. Flag Self_Ref should be set when the item is an
676 -- output and the dependency clause has operator "+".
677
678 procedure Check_Usage
679 (Subp_Items : Elist_Id;
680 Used_Items : Elist_Id;
681 Is_Input : Boolean);
682 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
683 -- error if this is not the case.
684
685 procedure Normalize_Clause (Clause : Node_Id);
686 -- Remove a self-dependency "+" from the input list of a clause
687
688 -----------------------------
689 -- Add_Item_To_Name_Buffer --
690 -----------------------------
691
692 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
693 begin
694 if Ekind (Item_Id) = E_Abstract_State then
695 Add_Str_To_Name_Buffer ("state");
696
697 elsif Ekind (Item_Id) = E_Constant then
698 Add_Str_To_Name_Buffer ("constant");
699
700 elsif Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
701 E_Generic_In_Parameter)
702 then
703 Add_Str_To_Name_Buffer ("generic parameter");
704
705 elsif Is_Formal (Item_Id) then
706 Add_Str_To_Name_Buffer ("parameter");
707
708 elsif Ekind (Item_Id) = E_Loop_Parameter then
709 Add_Str_To_Name_Buffer ("loop parameter");
710
711 elsif Ekind (Item_Id) = E_Protected_Type
712 or else Is_Single_Protected_Object (Item_Id)
713 then
714 Add_Str_To_Name_Buffer ("current instance of protected type");
715
716 elsif Ekind (Item_Id) = E_Task_Type
717 or else Is_Single_Task_Object (Item_Id)
718 then
719 Add_Str_To_Name_Buffer ("current instance of task type");
720
721 elsif Ekind (Item_Id) = E_Variable then
722 Add_Str_To_Name_Buffer ("global");
723
724 -- The routine should not be called with non-SPARK items
725
726 else
727 raise Program_Error;
728 end if;
729 end Add_Item_To_Name_Buffer;
730
731 -------------------------------
732 -- Analyze_Dependency_Clause --
733 -------------------------------
734
735 procedure Analyze_Dependency_Clause
736 (Clause : Node_Id;
737 Is_Last : Boolean)
738 is
739 procedure Analyze_Input_List (Inputs : Node_Id);
740 -- Verify the legality of a single input list
741
742 procedure Analyze_Input_Output
743 (Item : Node_Id;
744 Is_Input : Boolean;
745 Self_Ref : Boolean;
746 Top_Level : Boolean;
747 Seen : in out Elist_Id;
748 Null_Seen : in out Boolean;
749 Non_Null_Seen : in out Boolean);
750 -- Verify the legality of a single input or output item. Flag
751 -- Is_Input should be set whenever Item is an input, False when it
752 -- denotes an output. Flag Self_Ref should be set when the item is an
753 -- output and the dependency clause has a "+". Flag Top_Level should
754 -- be set whenever Item appears immediately within an input or output
755 -- list. Seen is a collection of all abstract states, objects and
756 -- formals processed so far. Flag Null_Seen denotes whether a null
757 -- input or output has been encountered. Flag Non_Null_Seen denotes
758 -- whether a non-null input or output has been encountered.
759
760 ------------------------
761 -- Analyze_Input_List --
762 ------------------------
763
764 procedure Analyze_Input_List (Inputs : Node_Id) is
765 Inputs_Seen : Elist_Id := No_Elist;
766 -- A list containing the entities of all inputs that appear in the
767 -- current input list.
768
769 Non_Null_Input_Seen : Boolean := False;
770 Null_Input_Seen : Boolean := False;
771 -- Flags used to check the legality of an input list
772
773 Input : Node_Id;
774
775 begin
776 -- Multiple inputs appear as an aggregate
777
778 if Nkind (Inputs) = N_Aggregate then
779 if Present (Component_Associations (Inputs)) then
780 SPARK_Msg_N
781 ("nested dependency relations not allowed", Inputs);
782
783 elsif Present (Expressions (Inputs)) then
784 Input := First (Expressions (Inputs));
785 while Present (Input) loop
786 Analyze_Input_Output
787 (Item => Input,
788 Is_Input => True,
789 Self_Ref => False,
790 Top_Level => False,
791 Seen => Inputs_Seen,
792 Null_Seen => Null_Input_Seen,
793 Non_Null_Seen => Non_Null_Input_Seen);
794
795 Next (Input);
796 end loop;
797
798 -- Syntax error, always report
799
800 else
801 Error_Msg_N ("malformed input dependency list", Inputs);
802 end if;
803
804 -- Process a solitary input
805
806 else
807 Analyze_Input_Output
808 (Item => Inputs,
809 Is_Input => True,
810 Self_Ref => False,
811 Top_Level => False,
812 Seen => Inputs_Seen,
813 Null_Seen => Null_Input_Seen,
814 Non_Null_Seen => Non_Null_Input_Seen);
815 end if;
816
817 -- Detect an illegal dependency clause of the form
818
819 -- (null =>[+] null)
820
821 if Null_Output_Seen and then Null_Input_Seen then
822 SPARK_Msg_N
823 ("null dependency clause cannot have a null input list",
824 Inputs);
825 end if;
826 end Analyze_Input_List;
827
828 --------------------------
829 -- Analyze_Input_Output --
830 --------------------------
831
832 procedure Analyze_Input_Output
833 (Item : Node_Id;
834 Is_Input : Boolean;
835 Self_Ref : Boolean;
836 Top_Level : Boolean;
837 Seen : in out Elist_Id;
838 Null_Seen : in out Boolean;
839 Non_Null_Seen : in out Boolean)
840 is
841 procedure Current_Task_Instance_Seen;
842 -- Set the appropriate global flag when the current instance of a
843 -- task unit is encountered.
844
845 --------------------------------
846 -- Current_Task_Instance_Seen --
847 --------------------------------
848
849 procedure Current_Task_Instance_Seen is
850 begin
851 if Is_Input then
852 Task_Input_Seen := True;
853 else
854 Task_Output_Seen := True;
855 end if;
856 end Current_Task_Instance_Seen;
857
858 -- Local variables
859
860 Is_Output : constant Boolean := not Is_Input;
861 Grouped : Node_Id;
862 Item_Id : Entity_Id;
863
864 -- Start of processing for Analyze_Input_Output
865
866 begin
867 -- Multiple input or output items appear as an aggregate
868
869 if Nkind (Item) = N_Aggregate then
870 if not Top_Level then
871 SPARK_Msg_N ("nested grouping of items not allowed", Item);
872
873 elsif Present (Component_Associations (Item)) then
874 SPARK_Msg_N
875 ("nested dependency relations not allowed", Item);
876
877 -- Recursively analyze the grouped items
878
879 elsif Present (Expressions (Item)) then
880 Grouped := First (Expressions (Item));
881 while Present (Grouped) loop
882 Analyze_Input_Output
883 (Item => Grouped,
884 Is_Input => Is_Input,
885 Self_Ref => Self_Ref,
886 Top_Level => False,
887 Seen => Seen,
888 Null_Seen => Null_Seen,
889 Non_Null_Seen => Non_Null_Seen);
890
891 Next (Grouped);
892 end loop;
893
894 -- Syntax error, always report
895
896 else
897 Error_Msg_N ("malformed dependency list", Item);
898 end if;
899
900 -- Process attribute 'Result in the context of a dependency clause
901
902 elsif Is_Attribute_Result (Item) then
903 Non_Null_Seen := True;
904
905 Analyze (Item);
906
907 -- Attribute 'Result is allowed to appear on the output side of
908 -- a dependency clause (SPARK RM 6.1.5(6)).
909
910 if Is_Input then
911 SPARK_Msg_N ("function result cannot act as input", Item);
912
913 elsif Null_Seen then
914 SPARK_Msg_N
915 ("cannot mix null and non-null dependency items", Item);
916
917 else
918 Result_Seen := True;
919 end if;
920
921 -- Detect multiple uses of null in a single dependency list or
922 -- throughout the whole relation. Verify the placement of a null
923 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
924
925 elsif Nkind (Item) = N_Null then
926 if Null_Seen then
927 SPARK_Msg_N
928 ("multiple null dependency relations not allowed", Item);
929
930 elsif Non_Null_Seen then
931 SPARK_Msg_N
932 ("cannot mix null and non-null dependency items", Item);
933
934 else
935 Null_Seen := True;
936
937 if Is_Output then
938 if not Is_Last then
939 SPARK_Msg_N
940 ("null output list must be the last clause in a "
941 & "dependency relation", Item);
942
943 -- Catch a useless dependence of the form:
944 -- null =>+ ...
945
946 elsif Self_Ref then
947 SPARK_Msg_N
948 ("useless dependence, null depends on itself", Item);
949 end if;
950 end if;
951 end if;
952
953 -- Default case
954
955 else
956 Non_Null_Seen := True;
957
958 if Null_Seen then
959 SPARK_Msg_N ("cannot mix null and non-null items", Item);
960 end if;
961
962 Analyze (Item);
963 Resolve_State (Item);
964
965 -- Find the entity of the item. If this is a renaming, climb
966 -- the renaming chain to reach the root object. Renamings of
967 -- non-entire objects do not yield an entity (Empty).
968
969 Item_Id := Entity_Of (Item);
970
971 if Present (Item_Id) then
972
973 -- Constants
974
975 if Ekind_In (Item_Id, E_Constant, E_Loop_Parameter)
976 or else
977
978 -- Current instances of concurrent types
979
980 Ekind_In (Item_Id, E_Protected_Type, E_Task_Type)
981 or else
982
983 -- Formal parameters
984
985 Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
986 E_Generic_In_Parameter,
987 E_In_Parameter,
988 E_In_Out_Parameter,
989 E_Out_Parameter)
990 or else
991
992 -- States, variables
993
994 Ekind_In (Item_Id, E_Abstract_State, E_Variable)
995 then
996 -- A [generic] function is not allowed to have Output
997 -- items in its dependency relations. Note that "null"
998 -- and attribute 'Result are still valid items.
999
1000 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
1001 and then not Is_Input
1002 then
1003 SPARK_Msg_N
1004 ("output item is not applicable to function", Item);
1005 end if;
1006
1007 -- The item denotes a concurrent type. Note that single
1008 -- protected/task types are not considered here because
1009 -- they behave as objects in the context of pragma
1010 -- [Refined_]Depends.
1011
1012 if Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
1013
1014 -- This use is legal as long as the concurrent type is
1015 -- the current instance of an enclosing type.
1016
1017 if Is_CCT_Instance (Item_Id, Spec_Id) then
1018
1019 -- The dependence of a task unit on itself is
1020 -- implicit and may or may not be explicitly
1021 -- specified (SPARK RM 6.1.4).
1022
1023 if Ekind (Item_Id) = E_Task_Type then
1024 Current_Task_Instance_Seen;
1025 end if;
1026
1027 -- Otherwise this is not the current instance
1028
1029 else
1030 SPARK_Msg_N
1031 ("invalid use of subtype mark in dependency "
1032 & "relation", Item);
1033 end if;
1034
1035 -- The dependency of a task unit on itself is implicit
1036 -- and may or may not be explicitly specified
1037 -- (SPARK RM 6.1.4).
1038
1039 elsif Is_Single_Task_Object (Item_Id)
1040 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
1041 then
1042 Current_Task_Instance_Seen;
1043 end if;
1044
1045 -- Ensure that the item fulfills its role as input and/or
1046 -- output as specified by pragma Global or the enclosing
1047 -- context.
1048
1049 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
1050
1051 -- Detect multiple uses of the same state, variable or
1052 -- formal parameter. If this is not the case, add the
1053 -- item to the list of processed relations.
1054
1055 if Contains (Seen, Item_Id) then
1056 SPARK_Msg_NE
1057 ("duplicate use of item &", Item, Item_Id);
1058 else
1059 Append_New_Elmt (Item_Id, Seen);
1060 end if;
1061
1062 -- Detect illegal use of an input related to a null
1063 -- output. Such input items cannot appear in other
1064 -- input lists (SPARK RM 6.1.5(13)).
1065
1066 if Is_Input
1067 and then Null_Output_Seen
1068 and then Contains (All_Inputs_Seen, Item_Id)
1069 then
1070 SPARK_Msg_N
1071 ("input of a null output list cannot appear in "
1072 & "multiple input lists", Item);
1073 end if;
1074
1075 -- Add an input or a self-referential output to the list
1076 -- of all processed inputs.
1077
1078 if Is_Input or else Self_Ref then
1079 Append_New_Elmt (Item_Id, All_Inputs_Seen);
1080 end if;
1081
1082 -- State related checks (SPARK RM 6.1.5(3))
1083
1084 if Ekind (Item_Id) = E_Abstract_State then
1085
1086 -- Package and subprogram bodies are instantiated
1087 -- individually in a separate compiler pass. Due to
1088 -- this mode of instantiation, the refinement of a
1089 -- state may no longer be visible when a subprogram
1090 -- body contract is instantiated. Since the generic
1091 -- template is legal, do not perform this check in
1092 -- the instance to circumvent this oddity.
1093
1094 if In_Instance then
1095 null;
1096
1097 -- An abstract state with visible refinement cannot
1098 -- appear in pragma [Refined_]Depends as its place
1099 -- must be taken by some of its constituents
1100 -- (SPARK RM 6.1.4(7)).
1101
1102 elsif Has_Visible_Refinement (Item_Id) then
1103 SPARK_Msg_NE
1104 ("cannot mention state & in dependence relation",
1105 Item, Item_Id);
1106 SPARK_Msg_N ("\use its constituents instead", Item);
1107 return;
1108
1109 -- If the reference to the abstract state appears in
1110 -- an enclosing package body that will eventually
1111 -- refine the state, record the reference for future
1112 -- checks.
1113
1114 else
1115 Record_Possible_Body_Reference
1116 (State_Id => Item_Id,
1117 Ref => Item);
1118 end if;
1119 end if;
1120
1121 -- When the item renames an entire object, replace the
1122 -- item with a reference to the object.
1123
1124 if Entity (Item) /= Item_Id then
1125 Rewrite (Item,
1126 New_Occurrence_Of (Item_Id, Sloc (Item)));
1127 Analyze (Item);
1128 end if;
1129
1130 -- Add the entity of the current item to the list of
1131 -- processed items.
1132
1133 if Ekind (Item_Id) = E_Abstract_State then
1134 Append_New_Elmt (Item_Id, States_Seen);
1135
1136 -- The variable may eventually become a constituent of a
1137 -- single protected/task type. Record the reference now
1138 -- and verify its legality when analyzing the contract of
1139 -- the variable (SPARK RM 9.3).
1140
1141 elsif Ekind (Item_Id) = E_Variable then
1142 Record_Possible_Part_Of_Reference
1143 (Var_Id => Item_Id,
1144 Ref => Item);
1145 end if;
1146
1147 if Ekind_In (Item_Id, E_Abstract_State,
1148 E_Constant,
1149 E_Variable)
1150 and then Present (Encapsulating_State (Item_Id))
1151 then
1152 Append_New_Elmt (Item_Id, Constits_Seen);
1153 end if;
1154
1155 -- All other input/output items are illegal
1156 -- (SPARK RM 6.1.5(1)).
1157
1158 else
1159 SPARK_Msg_N
1160 ("item must denote parameter, variable, state or "
1161 & "current instance of concurrent type", Item);
1162 end if;
1163
1164 -- All other input/output items are illegal
1165 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1166
1167 else
1168 Error_Msg_N
1169 ("item must denote parameter, variable, state or current "
1170 & "instance of concurrent type", Item);
1171 end if;
1172 end if;
1173 end Analyze_Input_Output;
1174
1175 -- Local variables
1176
1177 Inputs : Node_Id;
1178 Output : Node_Id;
1179 Self_Ref : Boolean;
1180
1181 Non_Null_Output_Seen : Boolean := False;
1182 -- Flag used to check the legality of an output list
1183
1184 -- Start of processing for Analyze_Dependency_Clause
1185
1186 begin
1187 Inputs := Expression (Clause);
1188 Self_Ref := False;
1189
1190 -- An input list with a self-dependency appears as operator "+" where
1191 -- the actuals inputs are the right operand.
1192
1193 if Nkind (Inputs) = N_Op_Plus then
1194 Inputs := Right_Opnd (Inputs);
1195 Self_Ref := True;
1196 end if;
1197
1198 -- Process the output_list of a dependency_clause
1199
1200 Output := First (Choices (Clause));
1201 while Present (Output) loop
1202 Analyze_Input_Output
1203 (Item => Output,
1204 Is_Input => False,
1205 Self_Ref => Self_Ref,
1206 Top_Level => True,
1207 Seen => All_Outputs_Seen,
1208 Null_Seen => Null_Output_Seen,
1209 Non_Null_Seen => Non_Null_Output_Seen);
1210
1211 Next (Output);
1212 end loop;
1213
1214 -- Process the input_list of a dependency_clause
1215
1216 Analyze_Input_List (Inputs);
1217 end Analyze_Dependency_Clause;
1218
1219 ---------------------------
1220 -- Check_Function_Return --
1221 ---------------------------
1222
1223 procedure Check_Function_Return is
1224 begin
1225 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
1226 and then not Result_Seen
1227 then
1228 SPARK_Msg_NE
1229 ("result of & must appear in exactly one output list",
1230 N, Spec_Id);
1231 end if;
1232 end Check_Function_Return;
1233
1234 ----------------
1235 -- Check_Role --
1236 ----------------
1237
1238 procedure Check_Role
1239 (Item : Node_Id;
1240 Item_Id : Entity_Id;
1241 Is_Input : Boolean;
1242 Self_Ref : Boolean)
1243 is
1244 procedure Find_Role
1245 (Item_Is_Input : out Boolean;
1246 Item_Is_Output : out Boolean);
1247 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1248 -- Item_Is_Output are set depending on the role.
1249
1250 procedure Role_Error
1251 (Item_Is_Input : Boolean;
1252 Item_Is_Output : Boolean);
1253 -- Emit an error message concerning the incorrect use of Item in
1254 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1255 -- denote whether the item is an input and/or an output.
1256
1257 ---------------
1258 -- Find_Role --
1259 ---------------
1260
1261 procedure Find_Role
1262 (Item_Is_Input : out Boolean;
1263 Item_Is_Output : out Boolean)
1264 is
1265 -- A constant or IN parameter of access type should be handled
1266 -- like a variable, as the underlying memory pointed-to can be
1267 -- modified. Use Adjusted_Kind to do this adjustment.
1268
1269 Adjusted_Kind : Entity_Kind := Ekind (Item_Id);
1270
1271 begin
1272 if Ekind_In (Item_Id, E_Constant,
1273 E_Generic_In_Parameter,
1274 E_In_Parameter)
1275 and then Is_Access_Type (Etype (Item_Id))
1276 then
1277 Adjusted_Kind := E_Variable;
1278 end if;
1279
1280 case Adjusted_Kind is
1281
1282 -- Abstract states
1283
1284 when E_Abstract_State =>
1285
1286 -- When pragma Global is present it determines the mode of
1287 -- the abstract state.
1288
1289 if Global_Seen then
1290 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1291 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1292
1293 -- Otherwise the state has a default IN OUT mode, because it
1294 -- behaves as a variable.
1295
1296 else
1297 Item_Is_Input := True;
1298 Item_Is_Output := True;
1299 end if;
1300
1301 -- Constants and IN parameters
1302
1303 when E_Constant
1304 | E_Generic_In_Parameter
1305 | E_In_Parameter
1306 | E_Loop_Parameter
1307 =>
1308 -- When pragma Global is present it determines the mode
1309 -- of constant objects as inputs (and such objects cannot
1310 -- appear as outputs in the Global contract).
1311
1312 if Global_Seen then
1313 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1314 else
1315 Item_Is_Input := True;
1316 end if;
1317
1318 Item_Is_Output := False;
1319
1320 -- Variables and IN OUT parameters, as well as constants and
1321 -- IN parameters of access type which are handled like
1322 -- variables.
1323
1324 when E_Generic_In_Out_Parameter
1325 | E_In_Out_Parameter
1326 | E_Variable
1327 =>
1328 -- When pragma Global is present it determines the mode of
1329 -- the object.
1330
1331 if Global_Seen then
1332
1333 -- A variable has mode IN when its type is unconstrained
1334 -- or tagged because array bounds, discriminants or tags
1335 -- can be read.
1336
1337 Item_Is_Input :=
1338 Appears_In (Subp_Inputs, Item_Id)
1339 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1340
1341 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1342
1343 -- Otherwise the variable has a default IN OUT mode
1344
1345 else
1346 Item_Is_Input := True;
1347 Item_Is_Output := True;
1348 end if;
1349
1350 when E_Out_Parameter =>
1351
1352 -- An OUT parameter of the related subprogram; it cannot
1353 -- appear in Global.
1354
1355 if Scope (Item_Id) = Spec_Id then
1356
1357 -- The parameter has mode IN if its type is unconstrained
1358 -- or tagged because array bounds, discriminants or tags
1359 -- can be read.
1360
1361 Item_Is_Input :=
1362 Is_Unconstrained_Or_Tagged_Item (Item_Id);
1363
1364 Item_Is_Output := True;
1365
1366 -- An OUT parameter of an enclosing subprogram; it can
1367 -- appear in Global and behaves as a read-write variable.
1368
1369 else
1370 -- When pragma Global is present it determines the mode
1371 -- of the object.
1372
1373 if Global_Seen then
1374
1375 -- A variable has mode IN when its type is
1376 -- unconstrained or tagged because array
1377 -- bounds, discriminants or tags can be read.
1378
1379 Item_Is_Input :=
1380 Appears_In (Subp_Inputs, Item_Id)
1381 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1382
1383 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1384
1385 -- Otherwise the variable has a default IN OUT mode
1386
1387 else
1388 Item_Is_Input := True;
1389 Item_Is_Output := True;
1390 end if;
1391 end if;
1392
1393 -- Protected types
1394
1395 when E_Protected_Type =>
1396 if Global_Seen then
1397
1398 -- A variable has mode IN when its type is unconstrained
1399 -- or tagged because array bounds, discriminants or tags
1400 -- can be read.
1401
1402 Item_Is_Input :=
1403 Appears_In (Subp_Inputs, Item_Id)
1404 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1405
1406 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1407
1408 else
1409 -- A protected type acts as a formal parameter of mode IN
1410 -- when it applies to a protected function.
1411
1412 if Ekind (Spec_Id) = E_Function then
1413 Item_Is_Input := True;
1414 Item_Is_Output := False;
1415
1416 -- Otherwise the protected type acts as a formal of mode
1417 -- IN OUT.
1418
1419 else
1420 Item_Is_Input := True;
1421 Item_Is_Output := True;
1422 end if;
1423 end if;
1424
1425 -- Task types
1426
1427 when E_Task_Type =>
1428
1429 -- When pragma Global is present it determines the mode of
1430 -- the object.
1431
1432 if Global_Seen then
1433 Item_Is_Input :=
1434 Appears_In (Subp_Inputs, Item_Id)
1435 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1436
1437 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1438
1439 -- Otherwise task types act as IN OUT parameters
1440
1441 else
1442 Item_Is_Input := True;
1443 Item_Is_Output := True;
1444 end if;
1445
1446 when others =>
1447 raise Program_Error;
1448 end case;
1449 end Find_Role;
1450
1451 ----------------
1452 -- Role_Error --
1453 ----------------
1454
1455 procedure Role_Error
1456 (Item_Is_Input : Boolean;
1457 Item_Is_Output : Boolean)
1458 is
1459 Error_Msg : Name_Id;
1460
1461 begin
1462 Name_Len := 0;
1463
1464 -- When the item is not part of the input and the output set of
1465 -- the related subprogram, then it appears as extra in pragma
1466 -- [Refined_]Depends.
1467
1468 if not Item_Is_Input and then not Item_Is_Output then
1469 Add_Item_To_Name_Buffer (Item_Id);
1470 Add_Str_To_Name_Buffer
1471 (" & cannot appear in dependence relation");
1472
1473 Error_Msg := Name_Find;
1474 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1475
1476 Error_Msg_Name_1 := Chars (Spec_Id);
1477 SPARK_Msg_NE
1478 (Fix_Msg (Spec_Id, "\& is not part of the input or output "
1479 & "set of subprogram %"), Item, Item_Id);
1480
1481 -- The mode of the item and its role in pragma [Refined_]Depends
1482 -- are in conflict. Construct a detailed message explaining the
1483 -- illegality (SPARK RM 6.1.5(5-6)).
1484
1485 else
1486 if Item_Is_Input then
1487 Add_Str_To_Name_Buffer ("read-only");
1488 else
1489 Add_Str_To_Name_Buffer ("write-only");
1490 end if;
1491
1492 Add_Char_To_Name_Buffer (' ');
1493 Add_Item_To_Name_Buffer (Item_Id);
1494 Add_Str_To_Name_Buffer (" & cannot appear as ");
1495
1496 if Item_Is_Input then
1497 Add_Str_To_Name_Buffer ("output");
1498 else
1499 Add_Str_To_Name_Buffer ("input");
1500 end if;
1501
1502 Add_Str_To_Name_Buffer (" in dependence relation");
1503 Error_Msg := Name_Find;
1504 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1505 end if;
1506 end Role_Error;
1507
1508 -- Local variables
1509
1510 Item_Is_Input : Boolean;
1511 Item_Is_Output : Boolean;
1512
1513 -- Start of processing for Check_Role
1514
1515 begin
1516 Find_Role (Item_Is_Input, Item_Is_Output);
1517
1518 -- Input item
1519
1520 if Is_Input then
1521 if not Item_Is_Input then
1522 Role_Error (Item_Is_Input, Item_Is_Output);
1523 end if;
1524
1525 -- Self-referential item
1526
1527 elsif Self_Ref then
1528 if not Item_Is_Input or else not Item_Is_Output then
1529 Role_Error (Item_Is_Input, Item_Is_Output);
1530 end if;
1531
1532 -- Output item
1533
1534 elsif not Item_Is_Output then
1535 Role_Error (Item_Is_Input, Item_Is_Output);
1536 end if;
1537 end Check_Role;
1538
1539 -----------------
1540 -- Check_Usage --
1541 -----------------
1542
1543 procedure Check_Usage
1544 (Subp_Items : Elist_Id;
1545 Used_Items : Elist_Id;
1546 Is_Input : Boolean)
1547 is
1548 procedure Usage_Error (Item_Id : Entity_Id);
1549 -- Emit an error concerning the illegal usage of an item
1550
1551 -----------------
1552 -- Usage_Error --
1553 -----------------
1554
1555 procedure Usage_Error (Item_Id : Entity_Id) is
1556 Error_Msg : Name_Id;
1557
1558 begin
1559 -- Input case
1560
1561 if Is_Input then
1562
1563 -- Unconstrained and tagged items are not part of the explicit
1564 -- input set of the related subprogram, they do not have to be
1565 -- present in a dependence relation and should not be flagged
1566 -- (SPARK RM 6.1.5(5)).
1567
1568 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1569 Name_Len := 0;
1570
1571 Add_Item_To_Name_Buffer (Item_Id);
1572 Add_Str_To_Name_Buffer
1573 (" & is missing from input dependence list");
1574
1575 Error_Msg := Name_Find;
1576 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1577 SPARK_Msg_NE
1578 ("\add `null ='> &` dependency to ignore this input",
1579 N, Item_Id);
1580 end if;
1581
1582 -- Output case (SPARK RM 6.1.5(10))
1583
1584 else
1585 Name_Len := 0;
1586
1587 Add_Item_To_Name_Buffer (Item_Id);
1588 Add_Str_To_Name_Buffer
1589 (" & is missing from output dependence list");
1590
1591 Error_Msg := Name_Find;
1592 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1593 end if;
1594 end Usage_Error;
1595
1596 -- Local variables
1597
1598 Elmt : Elmt_Id;
1599 Item : Node_Id;
1600 Item_Id : Entity_Id;
1601
1602 -- Start of processing for Check_Usage
1603
1604 begin
1605 if No (Subp_Items) then
1606 return;
1607 end if;
1608
1609 -- Each input or output of the subprogram must appear in a dependency
1610 -- relation.
1611
1612 Elmt := First_Elmt (Subp_Items);
1613 while Present (Elmt) loop
1614 Item := Node (Elmt);
1615
1616 if Nkind (Item) = N_Defining_Identifier then
1617 Item_Id := Item;
1618 else
1619 Item_Id := Entity_Of (Item);
1620 end if;
1621
1622 -- The item does not appear in a dependency
1623
1624 if Present (Item_Id)
1625 and then not Contains (Used_Items, Item_Id)
1626 then
1627 if Is_Formal (Item_Id) then
1628 Usage_Error (Item_Id);
1629
1630 -- The current instance of a protected type behaves as a formal
1631 -- parameter (SPARK RM 6.1.4).
1632
1633 elsif Ekind (Item_Id) = E_Protected_Type
1634 or else Is_Single_Protected_Object (Item_Id)
1635 then
1636 Usage_Error (Item_Id);
1637
1638 -- The current instance of a task type behaves as a formal
1639 -- parameter (SPARK RM 6.1.4).
1640
1641 elsif Ekind (Item_Id) = E_Task_Type
1642 or else Is_Single_Task_Object (Item_Id)
1643 then
1644 -- The dependence of a task unit on itself is implicit and
1645 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1646 -- Emit an error if only one input/output is present.
1647
1648 if Task_Input_Seen /= Task_Output_Seen then
1649 Usage_Error (Item_Id);
1650 end if;
1651
1652 -- States and global objects are not used properly only when
1653 -- the subprogram is subject to pragma Global.
1654
1655 elsif Global_Seen then
1656 Usage_Error (Item_Id);
1657 end if;
1658 end if;
1659
1660 Next_Elmt (Elmt);
1661 end loop;
1662 end Check_Usage;
1663
1664 ----------------------
1665 -- Normalize_Clause --
1666 ----------------------
1667
1668 procedure Normalize_Clause (Clause : Node_Id) is
1669 procedure Create_Or_Modify_Clause
1670 (Output : Node_Id;
1671 Outputs : Node_Id;
1672 Inputs : Node_Id;
1673 After : Node_Id;
1674 In_Place : Boolean;
1675 Multiple : Boolean);
1676 -- Create a brand new clause to represent the self-reference or
1677 -- modify the input and/or output lists of an existing clause. Output
1678 -- denotes a self-referencial output. Outputs is the output list of a
1679 -- clause. Inputs is the input list of a clause. After denotes the
1680 -- clause after which the new clause is to be inserted. Flag In_Place
1681 -- should be set when normalizing the last output of an output list.
1682 -- Flag Multiple should be set when Output comes from a list with
1683 -- multiple items.
1684
1685 -----------------------------
1686 -- Create_Or_Modify_Clause --
1687 -----------------------------
1688
1689 procedure Create_Or_Modify_Clause
1690 (Output : Node_Id;
1691 Outputs : Node_Id;
1692 Inputs : Node_Id;
1693 After : Node_Id;
1694 In_Place : Boolean;
1695 Multiple : Boolean)
1696 is
1697 procedure Propagate_Output
1698 (Output : Node_Id;
1699 Inputs : Node_Id);
1700 -- Handle the various cases of output propagation to the input
1701 -- list. Output denotes a self-referencial output item. Inputs
1702 -- is the input list of a clause.
1703
1704 ----------------------
1705 -- Propagate_Output --
1706 ----------------------
1707
1708 procedure Propagate_Output
1709 (Output : Node_Id;
1710 Inputs : Node_Id)
1711 is
1712 function In_Input_List
1713 (Item : Entity_Id;
1714 Inputs : List_Id) return Boolean;
1715 -- Determine whether a particulat item appears in the input
1716 -- list of a clause.
1717
1718 -------------------
1719 -- In_Input_List --
1720 -------------------
1721
1722 function In_Input_List
1723 (Item : Entity_Id;
1724 Inputs : List_Id) return Boolean
1725 is
1726 Elmt : Node_Id;
1727
1728 begin
1729 Elmt := First (Inputs);
1730 while Present (Elmt) loop
1731 if Entity_Of (Elmt) = Item then
1732 return True;
1733 end if;
1734
1735 Next (Elmt);
1736 end loop;
1737
1738 return False;
1739 end In_Input_List;
1740
1741 -- Local variables
1742
1743 Output_Id : constant Entity_Id := Entity_Of (Output);
1744 Grouped : List_Id;
1745
1746 -- Start of processing for Propagate_Output
1747
1748 begin
1749 -- The clause is of the form:
1750
1751 -- (Output =>+ null)
1752
1753 -- Remove null input and replace it with a copy of the output:
1754
1755 -- (Output => Output)
1756
1757 if Nkind (Inputs) = N_Null then
1758 Rewrite (Inputs, New_Copy_Tree (Output));
1759
1760 -- The clause is of the form:
1761
1762 -- (Output =>+ (Input1, ..., InputN))
1763
1764 -- Determine whether the output is not already mentioned in the
1765 -- input list and if not, add it to the list of inputs:
1766
1767 -- (Output => (Output, Input1, ..., InputN))
1768
1769 elsif Nkind (Inputs) = N_Aggregate then
1770 Grouped := Expressions (Inputs);
1771
1772 if not In_Input_List
1773 (Item => Output_Id,
1774 Inputs => Grouped)
1775 then
1776 Prepend_To (Grouped, New_Copy_Tree (Output));
1777 end if;
1778
1779 -- The clause is of the form:
1780
1781 -- (Output =>+ Input)
1782
1783 -- If the input does not mention the output, group the two
1784 -- together:
1785
1786 -- (Output => (Output, Input))
1787
1788 elsif Entity_Of (Inputs) /= Output_Id then
1789 Rewrite (Inputs,
1790 Make_Aggregate (Loc,
1791 Expressions => New_List (
1792 New_Copy_Tree (Output),
1793 New_Copy_Tree (Inputs))));
1794 end if;
1795 end Propagate_Output;
1796
1797 -- Local variables
1798
1799 Loc : constant Source_Ptr := Sloc (Clause);
1800 New_Clause : Node_Id;
1801
1802 -- Start of processing for Create_Or_Modify_Clause
1803
1804 begin
1805 -- A null output depending on itself does not require any
1806 -- normalization.
1807
1808 if Nkind (Output) = N_Null then
1809 return;
1810
1811 -- A function result cannot depend on itself because it cannot
1812 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1813
1814 elsif Is_Attribute_Result (Output) then
1815 SPARK_Msg_N ("function result cannot depend on itself", Output);
1816 return;
1817 end if;
1818
1819 -- When performing the transformation in place, simply add the
1820 -- output to the list of inputs (if not already there). This
1821 -- case arises when dealing with the last output of an output
1822 -- list. Perform the normalization in place to avoid generating
1823 -- a malformed tree.
1824
1825 if In_Place then
1826 Propagate_Output (Output, Inputs);
1827
1828 -- A list with multiple outputs is slowly trimmed until only
1829 -- one element remains. When this happens, replace aggregate
1830 -- with the element itself.
1831
1832 if Multiple then
1833 Remove (Output);
1834 Rewrite (Outputs, Output);
1835 end if;
1836
1837 -- Default case
1838
1839 else
1840 -- Unchain the output from its output list as it will appear in
1841 -- a new clause. Note that we cannot simply rewrite the output
1842 -- as null because this will violate the semantics of pragma
1843 -- Depends.
1844
1845 Remove (Output);
1846
1847 -- Generate a new clause of the form:
1848 -- (Output => Inputs)
1849
1850 New_Clause :=
1851 Make_Component_Association (Loc,
1852 Choices => New_List (Output),
1853 Expression => New_Copy_Tree (Inputs));
1854
1855 -- The new clause contains replicated content that has already
1856 -- been analyzed. There is not need to reanalyze or renormalize
1857 -- it again.
1858
1859 Set_Analyzed (New_Clause);
1860
1861 Propagate_Output
1862 (Output => First (Choices (New_Clause)),
1863 Inputs => Expression (New_Clause));
1864
1865 Insert_After (After, New_Clause);
1866 end if;
1867 end Create_Or_Modify_Clause;
1868
1869 -- Local variables
1870
1871 Outputs : constant Node_Id := First (Choices (Clause));
1872 Inputs : Node_Id;
1873 Last_Output : Node_Id;
1874 Next_Output : Node_Id;
1875 Output : Node_Id;
1876
1877 -- Start of processing for Normalize_Clause
1878
1879 begin
1880 -- A self-dependency appears as operator "+". Remove the "+" from the
1881 -- tree by moving the real inputs to their proper place.
1882
1883 if Nkind (Expression (Clause)) = N_Op_Plus then
1884 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1885 Inputs := Expression (Clause);
1886
1887 -- Multiple outputs appear as an aggregate
1888
1889 if Nkind (Outputs) = N_Aggregate then
1890 Last_Output := Last (Expressions (Outputs));
1891
1892 Output := First (Expressions (Outputs));
1893 while Present (Output) loop
1894
1895 -- Normalization may remove an output from its list,
1896 -- preserve the subsequent output now.
1897
1898 Next_Output := Next (Output);
1899
1900 Create_Or_Modify_Clause
1901 (Output => Output,
1902 Outputs => Outputs,
1903 Inputs => Inputs,
1904 After => Clause,
1905 In_Place => Output = Last_Output,
1906 Multiple => True);
1907
1908 Output := Next_Output;
1909 end loop;
1910
1911 -- Solitary output
1912
1913 else
1914 Create_Or_Modify_Clause
1915 (Output => Outputs,
1916 Outputs => Empty,
1917 Inputs => Inputs,
1918 After => Empty,
1919 In_Place => True,
1920 Multiple => False);
1921 end if;
1922 end if;
1923 end Normalize_Clause;
1924
1925 -- Local variables
1926
1927 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
1928 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1929
1930 Clause : Node_Id;
1931 Errors : Nat;
1932 Last_Clause : Node_Id;
1933 Restore_Scope : Boolean := False;
1934
1935 -- Start of processing for Analyze_Depends_In_Decl_Part
1936
1937 begin
1938 -- Do not analyze the pragma multiple times
1939
1940 if Is_Analyzed_Pragma (N) then
1941 return;
1942 end if;
1943
1944 -- Empty dependency list
1945
1946 if Nkind (Deps) = N_Null then
1947
1948 -- Gather all states, objects and formal parameters that the
1949 -- subprogram may depend on. These items are obtained from the
1950 -- parameter profile or pragma [Refined_]Global (if available).
1951
1952 Collect_Subprogram_Inputs_Outputs
1953 (Subp_Id => Subp_Id,
1954 Subp_Inputs => Subp_Inputs,
1955 Subp_Outputs => Subp_Outputs,
1956 Global_Seen => Global_Seen);
1957
1958 -- Verify that every input or output of the subprogram appear in a
1959 -- dependency.
1960
1961 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1962 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1963 Check_Function_Return;
1964
1965 -- Dependency clauses appear as component associations of an aggregate
1966
1967 elsif Nkind (Deps) = N_Aggregate then
1968
1969 -- Do not attempt to perform analysis of a syntactically illegal
1970 -- clause as this will lead to misleading errors.
1971
1972 if Has_Extra_Parentheses (Deps) then
1973 return;
1974 end if;
1975
1976 if Present (Component_Associations (Deps)) then
1977 Last_Clause := Last (Component_Associations (Deps));
1978
1979 -- Gather all states, objects and formal parameters that the
1980 -- subprogram may depend on. These items are obtained from the
1981 -- parameter profile or pragma [Refined_]Global (if available).
1982
1983 Collect_Subprogram_Inputs_Outputs
1984 (Subp_Id => Subp_Id,
1985 Subp_Inputs => Subp_Inputs,
1986 Subp_Outputs => Subp_Outputs,
1987 Global_Seen => Global_Seen);
1988
1989 -- When pragma [Refined_]Depends appears on a single concurrent
1990 -- type, it is relocated to the anonymous object.
1991
1992 if Is_Single_Concurrent_Object (Spec_Id) then
1993 null;
1994
1995 -- Ensure that the formal parameters are visible when analyzing
1996 -- all clauses. This falls out of the general rule of aspects
1997 -- pertaining to subprogram declarations.
1998
1999 elsif not In_Open_Scopes (Spec_Id) then
2000 Restore_Scope := True;
2001 Push_Scope (Spec_Id);
2002
2003 if Ekind (Spec_Id) = E_Task_Type then
2004 if Has_Discriminants (Spec_Id) then
2005 Install_Discriminants (Spec_Id);
2006 end if;
2007
2008 elsif Is_Generic_Subprogram (Spec_Id) then
2009 Install_Generic_Formals (Spec_Id);
2010
2011 else
2012 Install_Formals (Spec_Id);
2013 end if;
2014 end if;
2015
2016 Clause := First (Component_Associations (Deps));
2017 while Present (Clause) loop
2018 Errors := Serious_Errors_Detected;
2019
2020 -- The normalization mechanism may create extra clauses that
2021 -- contain replicated input and output names. There is no need
2022 -- to reanalyze them.
2023
2024 if not Analyzed (Clause) then
2025 Set_Analyzed (Clause);
2026
2027 Analyze_Dependency_Clause
2028 (Clause => Clause,
2029 Is_Last => Clause = Last_Clause);
2030 end if;
2031
2032 -- Do not normalize a clause if errors were detected (count
2033 -- of Serious_Errors has increased) because the inputs and/or
2034 -- outputs may denote illegal items.
2035
2036 if Serious_Errors_Detected = Errors then
2037 Normalize_Clause (Clause);
2038 end if;
2039
2040 Next (Clause);
2041 end loop;
2042
2043 if Restore_Scope then
2044 End_Scope;
2045 end if;
2046
2047 -- Verify that every input or output of the subprogram appear in a
2048 -- dependency.
2049
2050 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
2051 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
2052 Check_Function_Return;
2053
2054 -- The dependency list is malformed. This is a syntax error, always
2055 -- report.
2056
2057 else
2058 Error_Msg_N ("malformed dependency relation", Deps);
2059 return;
2060 end if;
2061
2062 -- The top level dependency relation is malformed. This is a syntax
2063 -- error, always report.
2064
2065 else
2066 Error_Msg_N ("malformed dependency relation", Deps);
2067 goto Leave;
2068 end if;
2069
2070 -- Ensure that a state and a corresponding constituent do not appear
2071 -- together in pragma [Refined_]Depends.
2072
2073 Check_State_And_Constituent_Use
2074 (States => States_Seen,
2075 Constits => Constits_Seen,
2076 Context => N);
2077
2078 <<Leave>>
2079 Set_Is_Analyzed_Pragma (N);
2080 end Analyze_Depends_In_Decl_Part;
2081
2082 --------------------------------------------
2083 -- Analyze_External_Property_In_Decl_Part --
2084 --------------------------------------------
2085
2086 procedure Analyze_External_Property_In_Decl_Part
2087 (N : Node_Id;
2088 Expr_Val : out Boolean)
2089 is
2090 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pragma_Name (N));
2091 Arg1 : constant Node_Id :=
2092 First (Pragma_Argument_Associations (N));
2093 Obj_Decl : constant Node_Id := Find_Related_Context (N);
2094 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
2095 Expr : Node_Id;
2096
2097 begin
2098 Expr_Val := False;
2099
2100 -- Do not analyze the pragma multiple times
2101
2102 if Is_Analyzed_Pragma (N) then
2103 return;
2104 end if;
2105
2106 Error_Msg_Name_1 := Pragma_Name (N);
2107
2108 -- An external property pragma must apply to an effectively volatile
2109 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
2110 -- The check is performed at the end of the declarative region due to a
2111 -- possible out-of-order arrangement of pragmas:
2112
2113 -- Obj : ...;
2114 -- pragma Async_Readers (Obj);
2115 -- pragma Volatile (Obj);
2116
2117 if Prag_Id /= Pragma_No_Caching
2118 and then not Is_Effectively_Volatile (Obj_Id)
2119 then
2120 if No_Caching_Enabled (Obj_Id) then
2121 SPARK_Msg_N
2122 ("illegal combination of external property % and property "
2123 & """No_Caching"" (SPARK RM 7.1.2(6))", N);
2124 else
2125 SPARK_Msg_N
2126 ("external property % must apply to a volatile object", N);
2127 end if;
2128
2129 -- Pragma No_Caching should only apply to volatile variables of
2130 -- a non-effectively volatile type (SPARK RM 7.1.2).
2131
2132 elsif Prag_Id = Pragma_No_Caching then
2133 if Is_Effectively_Volatile (Etype (Obj_Id)) then
2134 SPARK_Msg_N ("property % must not apply to an object of "
2135 & "an effectively volatile type", N);
2136 elsif not Is_Volatile (Obj_Id) then
2137 SPARK_Msg_N ("property % must apply to a volatile object", N);
2138 end if;
2139 end if;
2140
2141 -- Ensure that the Boolean expression (if present) is static. A missing
2142 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2143
2144 Expr_Val := True;
2145
2146 if Present (Arg1) then
2147 Expr := Get_Pragma_Arg (Arg1);
2148
2149 if Is_OK_Static_Expression (Expr) then
2150 Expr_Val := Is_True (Expr_Value (Expr));
2151 end if;
2152 end if;
2153
2154 Set_Is_Analyzed_Pragma (N);
2155 end Analyze_External_Property_In_Decl_Part;
2156
2157 ---------------------------------
2158 -- Analyze_Global_In_Decl_Part --
2159 ---------------------------------
2160
2161 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
2162 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2163 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2164 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2165
2166 Constits_Seen : Elist_Id := No_Elist;
2167 -- A list containing the entities of all constituents processed so far.
2168 -- It aids in detecting illegal usage of a state and a corresponding
2169 -- constituent in pragma [Refinde_]Global.
2170
2171 Seen : Elist_Id := No_Elist;
2172 -- A list containing the entities of all the items processed so far. It
2173 -- plays a role in detecting distinct entities.
2174
2175 States_Seen : Elist_Id := No_Elist;
2176 -- A list containing the entities of all states processed so far. It
2177 -- helps in detecting illegal usage of a state and a corresponding
2178 -- constituent in pragma [Refined_]Global.
2179
2180 In_Out_Seen : Boolean := False;
2181 Input_Seen : Boolean := False;
2182 Output_Seen : Boolean := False;
2183 Proof_Seen : Boolean := False;
2184 -- Flags used to verify the consistency of modes
2185
2186 procedure Analyze_Global_List
2187 (List : Node_Id;
2188 Global_Mode : Name_Id := Name_Input);
2189 -- Verify the legality of a single global list declaration. Global_Mode
2190 -- denotes the current mode in effect.
2191
2192 -------------------------
2193 -- Analyze_Global_List --
2194 -------------------------
2195
2196 procedure Analyze_Global_List
2197 (List : Node_Id;
2198 Global_Mode : Name_Id := Name_Input)
2199 is
2200 procedure Analyze_Global_Item
2201 (Item : Node_Id;
2202 Global_Mode : Name_Id);
2203 -- Verify the legality of a single global item declaration denoted by
2204 -- Item. Global_Mode denotes the current mode in effect.
2205
2206 procedure Check_Duplicate_Mode
2207 (Mode : Node_Id;
2208 Status : in out Boolean);
2209 -- Flag Status denotes whether a particular mode has been seen while
2210 -- processing a global list. This routine verifies that Mode is not a
2211 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2212
2213 procedure Check_Mode_Restriction_In_Enclosing_Context
2214 (Item : Node_Id;
2215 Item_Id : Entity_Id);
2216 -- Verify that an item of mode In_Out or Output does not appear as
2217 -- an input in the Global aspect of an enclosing subprogram or task
2218 -- unit. If this is the case, emit an error. Item and Item_Id are
2219 -- respectively the item and its entity.
2220
2221 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
2222 -- Mode denotes either In_Out or Output. Depending on the kind of the
2223 -- related subprogram, emit an error if those two modes apply to a
2224 -- function (SPARK RM 6.1.4(10)).
2225
2226 -------------------------
2227 -- Analyze_Global_Item --
2228 -------------------------
2229
2230 procedure Analyze_Global_Item
2231 (Item : Node_Id;
2232 Global_Mode : Name_Id)
2233 is
2234 Item_Id : Entity_Id;
2235
2236 begin
2237 -- Detect one of the following cases
2238
2239 -- with Global => (null, Name)
2240 -- with Global => (Name_1, null, Name_2)
2241 -- with Global => (Name, null)
2242
2243 if Nkind (Item) = N_Null then
2244 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
2245 return;
2246 end if;
2247
2248 Analyze (Item);
2249 Resolve_State (Item);
2250
2251 -- Find the entity of the item. If this is a renaming, climb the
2252 -- renaming chain to reach the root object. Renamings of non-
2253 -- entire objects do not yield an entity (Empty).
2254
2255 Item_Id := Entity_Of (Item);
2256
2257 if Present (Item_Id) then
2258
2259 -- A global item may denote a formal parameter of an enclosing
2260 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2261 -- provide a better error diagnostic.
2262
2263 if Is_Formal (Item_Id) then
2264 if Scope (Item_Id) = Spec_Id then
2265 SPARK_Msg_NE
2266 (Fix_Msg (Spec_Id, "global item cannot reference "
2267 & "parameter of subprogram &"), Item, Spec_Id);
2268 return;
2269 end if;
2270
2271 -- A global item may denote a concurrent type as long as it is
2272 -- the current instance of an enclosing protected or task type
2273 -- (SPARK RM 6.1.4).
2274
2275 elsif Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
2276 if Is_CCT_Instance (Item_Id, Spec_Id) then
2277
2278 -- Pragma [Refined_]Global associated with a protected
2279 -- subprogram cannot mention the current instance of a
2280 -- protected type because the instance behaves as a
2281 -- formal parameter.
2282
2283 if Ekind (Item_Id) = E_Protected_Type then
2284 if Scope (Spec_Id) = Item_Id then
2285 Error_Msg_Name_1 := Chars (Item_Id);
2286 SPARK_Msg_NE
2287 (Fix_Msg (Spec_Id, "global item of subprogram & "
2288 & "cannot reference current instance of "
2289 & "protected type %"), Item, Spec_Id);
2290 return;
2291 end if;
2292
2293 -- Pragma [Refined_]Global associated with a task type
2294 -- cannot mention the current instance of a task type
2295 -- because the instance behaves as a formal parameter.
2296
2297 else pragma Assert (Ekind (Item_Id) = E_Task_Type);
2298 if Spec_Id = Item_Id then
2299 Error_Msg_Name_1 := Chars (Item_Id);
2300 SPARK_Msg_NE
2301 (Fix_Msg (Spec_Id, "global item of subprogram & "
2302 & "cannot reference current instance of task "
2303 & "type %"), Item, Spec_Id);
2304 return;
2305 end if;
2306 end if;
2307
2308 -- Otherwise the global item denotes a subtype mark that is
2309 -- not a current instance.
2310
2311 else
2312 SPARK_Msg_N
2313 ("invalid use of subtype mark in global list", Item);
2314 return;
2315 end if;
2316
2317 -- A global item may denote the anonymous object created for a
2318 -- single protected/task type as long as the current instance
2319 -- is the same single type (SPARK RM 6.1.4).
2320
2321 elsif Is_Single_Concurrent_Object (Item_Id)
2322 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
2323 then
2324 -- Pragma [Refined_]Global associated with a protected
2325 -- subprogram cannot mention the current instance of a
2326 -- protected type because the instance behaves as a formal
2327 -- parameter.
2328
2329 if Is_Single_Protected_Object (Item_Id) then
2330 if Scope (Spec_Id) = Etype (Item_Id) then
2331 Error_Msg_Name_1 := Chars (Item_Id);
2332 SPARK_Msg_NE
2333 (Fix_Msg (Spec_Id, "global item of subprogram & "
2334 & "cannot reference current instance of protected "
2335 & "type %"), Item, Spec_Id);
2336 return;
2337 end if;
2338
2339 -- Pragma [Refined_]Global associated with a task type
2340 -- cannot mention the current instance of a task type
2341 -- because the instance behaves as a formal parameter.
2342
2343 else pragma Assert (Is_Single_Task_Object (Item_Id));
2344 if Spec_Id = Item_Id then
2345 Error_Msg_Name_1 := Chars (Item_Id);
2346 SPARK_Msg_NE
2347 (Fix_Msg (Spec_Id, "global item of subprogram & "
2348 & "cannot reference current instance of task "
2349 & "type %"), Item, Spec_Id);
2350 return;
2351 end if;
2352 end if;
2353
2354 -- A formal object may act as a global item inside a generic
2355
2356 elsif Is_Formal_Object (Item_Id) then
2357 null;
2358
2359 -- The only legal references are those to abstract states,
2360 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2361
2362 elsif not Ekind_In (Item_Id, E_Abstract_State,
2363 E_Constant,
2364 E_Loop_Parameter,
2365 E_Variable)
2366 then
2367 SPARK_Msg_N
2368 ("global item must denote object, state or current "
2369 & "instance of concurrent type", Item);
2370
2371 if Ekind (Item_Id) in Named_Kind then
2372 SPARK_Msg_NE
2373 ("\named number & is not an object", Item, Item);
2374 end if;
2375
2376 return;
2377 end if;
2378
2379 -- State related checks
2380
2381 if Ekind (Item_Id) = E_Abstract_State then
2382
2383 -- Package and subprogram bodies are instantiated
2384 -- individually in a separate compiler pass. Due to this
2385 -- mode of instantiation, the refinement of a state may
2386 -- no longer be visible when a subprogram body contract
2387 -- is instantiated. Since the generic template is legal,
2388 -- do not perform this check in the instance to circumvent
2389 -- this oddity.
2390
2391 if In_Instance then
2392 null;
2393
2394 -- An abstract state with visible refinement cannot appear
2395 -- in pragma [Refined_]Global as its place must be taken by
2396 -- some of its constituents (SPARK RM 6.1.4(7)).
2397
2398 elsif Has_Visible_Refinement (Item_Id) then
2399 SPARK_Msg_NE
2400 ("cannot mention state & in global refinement",
2401 Item, Item_Id);
2402 SPARK_Msg_N ("\use its constituents instead", Item);
2403 return;
2404
2405 -- An external state cannot appear as a global item of a
2406 -- nonvolatile function (SPARK RM 7.1.3(8)).
2407
2408 elsif Is_External_State (Item_Id)
2409 and then Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2410 and then not Is_Volatile_Function (Spec_Id)
2411 then
2412 SPARK_Msg_NE
2413 ("external state & cannot act as global item of "
2414 & "nonvolatile function", Item, Item_Id);
2415 return;
2416
2417 -- If the reference to the abstract state appears in an
2418 -- enclosing package body that will eventually refine the
2419 -- state, record the reference for future checks.
2420
2421 else
2422 Record_Possible_Body_Reference
2423 (State_Id => Item_Id,
2424 Ref => Item);
2425 end if;
2426
2427 -- Constant related checks
2428
2429 elsif Ekind (Item_Id) = E_Constant
2430 and then not Is_Access_Type (Etype (Item_Id))
2431 then
2432
2433 -- Unless it is of an access type, a constant is a read-only
2434 -- item, therefore it cannot act as an output.
2435
2436 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2437 SPARK_Msg_NE
2438 ("constant & cannot act as output", Item, Item_Id);
2439 return;
2440 end if;
2441
2442 -- Loop parameter related checks
2443
2444 elsif Ekind (Item_Id) = E_Loop_Parameter then
2445
2446 -- A loop parameter is a read-only item, therefore it cannot
2447 -- act as an output.
2448
2449 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2450 SPARK_Msg_NE
2451 ("loop parameter & cannot act as output",
2452 Item, Item_Id);
2453 return;
2454 end if;
2455
2456 -- Variable related checks. These are only relevant when
2457 -- SPARK_Mode is on as they are not standard Ada legality
2458 -- rules.
2459
2460 elsif SPARK_Mode = On
2461 and then Ekind (Item_Id) = E_Variable
2462 and then Is_Effectively_Volatile (Item_Id)
2463 then
2464 -- An effectively volatile object cannot appear as a global
2465 -- item of a nonvolatile function (SPARK RM 7.1.3(8)).
2466
2467 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2468 and then not Is_Volatile_Function (Spec_Id)
2469 then
2470 Error_Msg_NE
2471 ("volatile object & cannot act as global item of a "
2472 & "function", Item, Item_Id);
2473 return;
2474
2475 -- An effectively volatile object with external property
2476 -- Effective_Reads set to True must have mode Output or
2477 -- In_Out (SPARK RM 7.1.3(10)).
2478
2479 elsif Effective_Reads_Enabled (Item_Id)
2480 and then Global_Mode = Name_Input
2481 then
2482 Error_Msg_NE
2483 ("volatile object & with property Effective_Reads must "
2484 & "have mode In_Out or Output", Item, Item_Id);
2485 return;
2486 end if;
2487 end if;
2488
2489 -- When the item renames an entire object, replace the item
2490 -- with a reference to the object.
2491
2492 if Entity (Item) /= Item_Id then
2493 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2494 Analyze (Item);
2495 end if;
2496
2497 -- Some form of illegal construct masquerading as a name
2498 -- (SPARK RM 6.1.4(4)).
2499
2500 else
2501 Error_Msg_N
2502 ("global item must denote object, state or current instance "
2503 & "of concurrent type", Item);
2504 return;
2505 end if;
2506
2507 -- Verify that an output does not appear as an input in an
2508 -- enclosing subprogram.
2509
2510 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2511 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2512 end if;
2513
2514 -- The same entity might be referenced through various way.
2515 -- Check the entity of the item rather than the item itself
2516 -- (SPARK RM 6.1.4(10)).
2517
2518 if Contains (Seen, Item_Id) then
2519 SPARK_Msg_N ("duplicate global item", Item);
2520
2521 -- Add the entity of the current item to the list of processed
2522 -- items.
2523
2524 else
2525 Append_New_Elmt (Item_Id, Seen);
2526
2527 if Ekind (Item_Id) = E_Abstract_State then
2528 Append_New_Elmt (Item_Id, States_Seen);
2529
2530 -- The variable may eventually become a constituent of a single
2531 -- protected/task type. Record the reference now and verify its
2532 -- legality when analyzing the contract of the variable
2533 -- (SPARK RM 9.3).
2534
2535 elsif Ekind (Item_Id) = E_Variable then
2536 Record_Possible_Part_Of_Reference
2537 (Var_Id => Item_Id,
2538 Ref => Item);
2539 end if;
2540
2541 if Ekind_In (Item_Id, E_Abstract_State, E_Constant, E_Variable)
2542 and then Present (Encapsulating_State (Item_Id))
2543 then
2544 Append_New_Elmt (Item_Id, Constits_Seen);
2545 end if;
2546 end if;
2547 end Analyze_Global_Item;
2548
2549 --------------------------
2550 -- Check_Duplicate_Mode --
2551 --------------------------
2552
2553 procedure Check_Duplicate_Mode
2554 (Mode : Node_Id;
2555 Status : in out Boolean)
2556 is
2557 begin
2558 if Status then
2559 SPARK_Msg_N ("duplicate global mode", Mode);
2560 end if;
2561
2562 Status := True;
2563 end Check_Duplicate_Mode;
2564
2565 -------------------------------------------------
2566 -- Check_Mode_Restriction_In_Enclosing_Context --
2567 -------------------------------------------------
2568
2569 procedure Check_Mode_Restriction_In_Enclosing_Context
2570 (Item : Node_Id;
2571 Item_Id : Entity_Id)
2572 is
2573 Context : Entity_Id;
2574 Dummy : Boolean;
2575 Inputs : Elist_Id := No_Elist;
2576 Outputs : Elist_Id := No_Elist;
2577
2578 begin
2579 -- Traverse the scope stack looking for enclosing subprograms or
2580 -- tasks subject to pragma [Refined_]Global.
2581
2582 Context := Scope (Subp_Id);
2583 while Present (Context) and then Context /= Standard_Standard loop
2584
2585 -- For a single task type, retrieve the corresponding object to
2586 -- which pragma [Refined_]Global is attached.
2587
2588 if Ekind (Context) = E_Task_Type
2589 and then Is_Single_Concurrent_Type (Context)
2590 then
2591 Context := Anonymous_Object (Context);
2592 end if;
2593
2594 if (Is_Subprogram (Context)
2595 or else Ekind (Context) = E_Task_Type
2596 or else Is_Single_Task_Object (Context))
2597 and then
2598 (Present (Get_Pragma (Context, Pragma_Global))
2599 or else
2600 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2601 then
2602 Collect_Subprogram_Inputs_Outputs
2603 (Subp_Id => Context,
2604 Subp_Inputs => Inputs,
2605 Subp_Outputs => Outputs,
2606 Global_Seen => Dummy);
2607
2608 -- The item is classified as In_Out or Output but appears as
2609 -- an Input in an enclosing subprogram or task unit (SPARK
2610 -- RM 6.1.4(12)).
2611
2612 if Appears_In (Inputs, Item_Id)
2613 and then not Appears_In (Outputs, Item_Id)
2614 then
2615 SPARK_Msg_NE
2616 ("global item & cannot have mode In_Out or Output",
2617 Item, Item_Id);
2618
2619 if Is_Subprogram (Context) then
2620 SPARK_Msg_NE
2621 (Fix_Msg (Subp_Id, "\item already appears as input "
2622 & "of subprogram &"), Item, Context);
2623 else
2624 SPARK_Msg_NE
2625 (Fix_Msg (Subp_Id, "\item already appears as input "
2626 & "of task &"), Item, Context);
2627 end if;
2628
2629 -- Stop the traversal once an error has been detected
2630
2631 exit;
2632 end if;
2633 end if;
2634
2635 Context := Scope (Context);
2636 end loop;
2637 end Check_Mode_Restriction_In_Enclosing_Context;
2638
2639 ----------------------------------------
2640 -- Check_Mode_Restriction_In_Function --
2641 ----------------------------------------
2642
2643 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2644 begin
2645 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
2646 SPARK_Msg_N
2647 ("global mode & is not applicable to functions", Mode);
2648 end if;
2649 end Check_Mode_Restriction_In_Function;
2650
2651 -- Local variables
2652
2653 Assoc : Node_Id;
2654 Item : Node_Id;
2655 Mode : Node_Id;
2656
2657 -- Start of processing for Analyze_Global_List
2658
2659 begin
2660 if Nkind (List) = N_Null then
2661 Set_Analyzed (List);
2662
2663 -- Single global item declaration
2664
2665 elsif Nkind_In (List, N_Expanded_Name,
2666 N_Identifier,
2667 N_Selected_Component)
2668 then
2669 Analyze_Global_Item (List, Global_Mode);
2670
2671 -- Simple global list or moded global list declaration
2672
2673 elsif Nkind (List) = N_Aggregate then
2674 Set_Analyzed (List);
2675
2676 -- The declaration of a simple global list appear as a collection
2677 -- of expressions.
2678
2679 if Present (Expressions (List)) then
2680 if Present (Component_Associations (List)) then
2681 SPARK_Msg_N
2682 ("cannot mix moded and non-moded global lists", List);
2683 end if;
2684
2685 Item := First (Expressions (List));
2686 while Present (Item) loop
2687 Analyze_Global_Item (Item, Global_Mode);
2688 Next (Item);
2689 end loop;
2690
2691 -- The declaration of a moded global list appears as a collection
2692 -- of component associations where individual choices denote
2693 -- modes.
2694
2695 elsif Present (Component_Associations (List)) then
2696 if Present (Expressions (List)) then
2697 SPARK_Msg_N
2698 ("cannot mix moded and non-moded global lists", List);
2699 end if;
2700
2701 Assoc := First (Component_Associations (List));
2702 while Present (Assoc) loop
2703 Mode := First (Choices (Assoc));
2704
2705 if Nkind (Mode) = N_Identifier then
2706 if Chars (Mode) = Name_In_Out then
2707 Check_Duplicate_Mode (Mode, In_Out_Seen);
2708 Check_Mode_Restriction_In_Function (Mode);
2709
2710 elsif Chars (Mode) = Name_Input then
2711 Check_Duplicate_Mode (Mode, Input_Seen);
2712
2713 elsif Chars (Mode) = Name_Output then
2714 Check_Duplicate_Mode (Mode, Output_Seen);
2715 Check_Mode_Restriction_In_Function (Mode);
2716
2717 elsif Chars (Mode) = Name_Proof_In then
2718 Check_Duplicate_Mode (Mode, Proof_Seen);
2719
2720 else
2721 SPARK_Msg_N ("invalid mode selector", Mode);
2722 end if;
2723
2724 else
2725 SPARK_Msg_N ("invalid mode selector", Mode);
2726 end if;
2727
2728 -- Items in a moded list appear as a collection of
2729 -- expressions. Reuse the existing machinery to analyze
2730 -- them.
2731
2732 Analyze_Global_List
2733 (List => Expression (Assoc),
2734 Global_Mode => Chars (Mode));
2735
2736 Next (Assoc);
2737 end loop;
2738
2739 -- Invalid tree
2740
2741 else
2742 raise Program_Error;
2743 end if;
2744
2745 -- Any other attempt to declare a global item is illegal. This is a
2746 -- syntax error, always report.
2747
2748 else
2749 Error_Msg_N ("malformed global list", List);
2750 end if;
2751 end Analyze_Global_List;
2752
2753 -- Local variables
2754
2755 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2756
2757 Restore_Scope : Boolean := False;
2758
2759 -- Start of processing for Analyze_Global_In_Decl_Part
2760
2761 begin
2762 -- Do not analyze the pragma multiple times
2763
2764 if Is_Analyzed_Pragma (N) then
2765 return;
2766 end if;
2767
2768 -- There is nothing to be done for a null global list
2769
2770 if Nkind (Items) = N_Null then
2771 Set_Analyzed (Items);
2772
2773 -- Analyze the various forms of global lists and items. Note that some
2774 -- of these may be malformed in which case the analysis emits error
2775 -- messages.
2776
2777 else
2778 -- When pragma [Refined_]Global appears on a single concurrent type,
2779 -- it is relocated to the anonymous object.
2780
2781 if Is_Single_Concurrent_Object (Spec_Id) then
2782 null;
2783
2784 -- Ensure that the formal parameters are visible when processing an
2785 -- item. This falls out of the general rule of aspects pertaining to
2786 -- subprogram declarations.
2787
2788 elsif not In_Open_Scopes (Spec_Id) then
2789 Restore_Scope := True;
2790 Push_Scope (Spec_Id);
2791
2792 if Ekind (Spec_Id) = E_Task_Type then
2793 if Has_Discriminants (Spec_Id) then
2794 Install_Discriminants (Spec_Id);
2795 end if;
2796
2797 elsif Is_Generic_Subprogram (Spec_Id) then
2798 Install_Generic_Formals (Spec_Id);
2799
2800 else
2801 Install_Formals (Spec_Id);
2802 end if;
2803 end if;
2804
2805 Analyze_Global_List (Items);
2806
2807 if Restore_Scope then
2808 End_Scope;
2809 end if;
2810 end if;
2811
2812 -- Ensure that a state and a corresponding constituent do not appear
2813 -- together in pragma [Refined_]Global.
2814
2815 Check_State_And_Constituent_Use
2816 (States => States_Seen,
2817 Constits => Constits_Seen,
2818 Context => N);
2819
2820 Set_Is_Analyzed_Pragma (N);
2821 end Analyze_Global_In_Decl_Part;
2822
2823 --------------------------------------------
2824 -- Analyze_Initial_Condition_In_Decl_Part --
2825 --------------------------------------------
2826
2827 -- WARNING: This routine manages Ghost regions. Return statements must be
2828 -- replaced by gotos which jump to the end of the routine and restore the
2829 -- Ghost mode.
2830
2831 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2832 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2833 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2834 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2835
2836 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
2837 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
2838 -- Save the Ghost-related attributes to restore on exit
2839
2840 begin
2841 -- Do not analyze the pragma multiple times
2842
2843 if Is_Analyzed_Pragma (N) then
2844 return;
2845 end if;
2846
2847 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2848 -- analysis of the pragma, the Ghost mode at point of declaration and
2849 -- point of analysis may not necessarily be the same. Use the mode in
2850 -- effect at the point of declaration.
2851
2852 Set_Ghost_Mode (N);
2853
2854 -- The expression is preanalyzed because it has not been moved to its
2855 -- final place yet. A direct analysis may generate side effects and this
2856 -- is not desired at this point.
2857
2858 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2859 Set_Is_Analyzed_Pragma (N);
2860
2861 Restore_Ghost_Region (Saved_GM, Saved_IGR);
2862 end Analyze_Initial_Condition_In_Decl_Part;
2863
2864 --------------------------------------
2865 -- Analyze_Initializes_In_Decl_Part --
2866 --------------------------------------
2867
2868 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2869 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2870 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2871
2872 Constits_Seen : Elist_Id := No_Elist;
2873 -- A list containing the entities of all constituents processed so far.
2874 -- It aids in detecting illegal usage of a state and a corresponding
2875 -- constituent in pragma Initializes.
2876
2877 Items_Seen : Elist_Id := No_Elist;
2878 -- A list of all initialization items processed so far. This list is
2879 -- used to detect duplicate items.
2880
2881 States_And_Objs : Elist_Id := No_Elist;
2882 -- A list of all abstract states and objects declared in the visible
2883 -- declarations of the related package. This list is used to detect the
2884 -- legality of initialization items.
2885
2886 States_Seen : Elist_Id := No_Elist;
2887 -- A list containing the entities of all states processed so far. It
2888 -- helps in detecting illegal usage of a state and a corresponding
2889 -- constituent in pragma Initializes.
2890
2891 procedure Analyze_Initialization_Item (Item : Node_Id);
2892 -- Verify the legality of a single initialization item
2893
2894 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2895 -- Verify the legality of a single initialization item followed by a
2896 -- list of input items.
2897
2898 procedure Collect_States_And_Objects (Pack_Decl : Node_Id);
2899 -- Inspect the visible declarations of the related package and gather
2900 -- the entities of all abstract states and objects in States_And_Objs.
2901
2902 ---------------------------------
2903 -- Analyze_Initialization_Item --
2904 ---------------------------------
2905
2906 procedure Analyze_Initialization_Item (Item : Node_Id) is
2907 Item_Id : Entity_Id;
2908
2909 begin
2910 Analyze (Item);
2911 Resolve_State (Item);
2912
2913 if Is_Entity_Name (Item) then
2914 Item_Id := Entity_Of (Item);
2915
2916 if Present (Item_Id)
2917 and then Ekind_In (Item_Id, E_Abstract_State,
2918 E_Constant,
2919 E_Variable)
2920 then
2921 -- When the initialization item is undefined, it appears as
2922 -- Any_Id. Do not continue with the analysis of the item.
2923
2924 if Item_Id = Any_Id then
2925 null;
2926
2927 -- The state or variable must be declared in the visible
2928 -- declarations of the package (SPARK RM 7.1.5(7)).
2929
2930 elsif not Contains (States_And_Objs, Item_Id) then
2931 Error_Msg_Name_1 := Chars (Pack_Id);
2932 SPARK_Msg_NE
2933 ("initialization item & must appear in the visible "
2934 & "declarations of package %", Item, Item_Id);
2935
2936 -- Detect a duplicate use of the same initialization item
2937 -- (SPARK RM 7.1.5(5)).
2938
2939 elsif Contains (Items_Seen, Item_Id) then
2940 SPARK_Msg_N ("duplicate initialization item", Item);
2941
2942 -- The item is legal, add it to the list of processed states
2943 -- and variables.
2944
2945 else
2946 Append_New_Elmt (Item_Id, Items_Seen);
2947
2948 if Ekind (Item_Id) = E_Abstract_State then
2949 Append_New_Elmt (Item_Id, States_Seen);
2950 end if;
2951
2952 if Present (Encapsulating_State (Item_Id)) then
2953 Append_New_Elmt (Item_Id, Constits_Seen);
2954 end if;
2955 end if;
2956
2957 -- The item references something that is not a state or object
2958 -- (SPARK RM 7.1.5(3)).
2959
2960 else
2961 SPARK_Msg_N
2962 ("initialization item must denote object or state", Item);
2963 end if;
2964
2965 -- Some form of illegal construct masquerading as a name
2966 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2967
2968 else
2969 Error_Msg_N
2970 ("initialization item must denote object or state", Item);
2971 end if;
2972 end Analyze_Initialization_Item;
2973
2974 ---------------------------------------------
2975 -- Analyze_Initialization_Item_With_Inputs --
2976 ---------------------------------------------
2977
2978 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2979 Inputs_Seen : Elist_Id := No_Elist;
2980 -- A list of all inputs processed so far. This list is used to detect
2981 -- duplicate uses of an input.
2982
2983 Non_Null_Seen : Boolean := False;
2984 Null_Seen : Boolean := False;
2985 -- Flags used to check the legality of an input list
2986
2987 procedure Analyze_Input_Item (Input : Node_Id);
2988 -- Verify the legality of a single input item
2989
2990 ------------------------
2991 -- Analyze_Input_Item --
2992 ------------------------
2993
2994 procedure Analyze_Input_Item (Input : Node_Id) is
2995 Input_Id : Entity_Id;
2996
2997 begin
2998 -- Null input list
2999
3000 if Nkind (Input) = N_Null then
3001 if Null_Seen then
3002 SPARK_Msg_N
3003 ("multiple null initializations not allowed", Item);
3004
3005 elsif Non_Null_Seen then
3006 SPARK_Msg_N
3007 ("cannot mix null and non-null initialization item", Item);
3008 else
3009 Null_Seen := True;
3010 end if;
3011
3012 -- Input item
3013
3014 else
3015 Non_Null_Seen := True;
3016
3017 if Null_Seen then
3018 SPARK_Msg_N
3019 ("cannot mix null and non-null initialization item", Item);
3020 end if;
3021
3022 Analyze (Input);
3023 Resolve_State (Input);
3024
3025 if Is_Entity_Name (Input) then
3026 Input_Id := Entity_Of (Input);
3027
3028 if Present (Input_Id)
3029 and then Ekind_In (Input_Id, E_Abstract_State,
3030 E_Constant,
3031 E_Generic_In_Out_Parameter,
3032 E_Generic_In_Parameter,
3033 E_In_Parameter,
3034 E_In_Out_Parameter,
3035 E_Out_Parameter,
3036 E_Protected_Type,
3037 E_Task_Type,
3038 E_Variable)
3039 then
3040 -- The input cannot denote states or objects declared
3041 -- within the related package (SPARK RM 7.1.5(4)).
3042
3043 if Within_Scope (Input_Id, Current_Scope) then
3044
3045 -- Do not consider generic formal parameters or their
3046 -- respective mappings to generic formals. Even though
3047 -- the formals appear within the scope of the package,
3048 -- it is allowed for an initialization item to depend
3049 -- on an input item.
3050
3051 if Ekind_In (Input_Id, E_Generic_In_Out_Parameter,
3052 E_Generic_In_Parameter)
3053 then
3054 null;
3055
3056 elsif Ekind_In (Input_Id, E_Constant, E_Variable)
3057 and then Present (Corresponding_Generic_Association
3058 (Declaration_Node (Input_Id)))
3059 then
3060 null;
3061
3062 else
3063 Error_Msg_Name_1 := Chars (Pack_Id);
3064 SPARK_Msg_NE
3065 ("input item & cannot denote a visible object or "
3066 & "state of package %", Input, Input_Id);
3067 return;
3068 end if;
3069 end if;
3070
3071 -- Detect a duplicate use of the same input item
3072 -- (SPARK RM 7.1.5(5)).
3073
3074 if Contains (Inputs_Seen, Input_Id) then
3075 SPARK_Msg_N ("duplicate input item", Input);
3076 return;
3077 end if;
3078
3079 -- At this point it is known that the input is legal. Add
3080 -- it to the list of processed inputs.
3081
3082 Append_New_Elmt (Input_Id, Inputs_Seen);
3083
3084 if Ekind (Input_Id) = E_Abstract_State then
3085 Append_New_Elmt (Input_Id, States_Seen);
3086 end if;
3087
3088 if Ekind_In (Input_Id, E_Abstract_State,
3089 E_Constant,
3090 E_Variable)
3091 and then Present (Encapsulating_State (Input_Id))
3092 then
3093 Append_New_Elmt (Input_Id, Constits_Seen);
3094 end if;
3095
3096 -- The input references something that is not a state or an
3097 -- object (SPARK RM 7.1.5(3)).
3098
3099 else
3100 SPARK_Msg_N
3101 ("input item must denote object or state", Input);
3102 end if;
3103
3104 -- Some form of illegal construct masquerading as a name
3105 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
3106
3107 else
3108 Error_Msg_N
3109 ("input item must denote object or state", Input);
3110 end if;
3111 end if;
3112 end Analyze_Input_Item;
3113
3114 -- Local variables
3115
3116 Inputs : constant Node_Id := Expression (Item);
3117 Elmt : Node_Id;
3118 Input : Node_Id;
3119
3120 Name_Seen : Boolean := False;
3121 -- A flag used to detect multiple item names
3122
3123 -- Start of processing for Analyze_Initialization_Item_With_Inputs
3124
3125 begin
3126 -- Inspect the name of an item with inputs
3127
3128 Elmt := First (Choices (Item));
3129 while Present (Elmt) loop
3130 if Name_Seen then
3131 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
3132 else
3133 Name_Seen := True;
3134 Analyze_Initialization_Item (Elmt);
3135 end if;
3136
3137 Next (Elmt);
3138 end loop;
3139
3140 -- Multiple input items appear as an aggregate
3141
3142 if Nkind (Inputs) = N_Aggregate then
3143 if Present (Expressions (Inputs)) then
3144 Input := First (Expressions (Inputs));
3145 while Present (Input) loop
3146 Analyze_Input_Item (Input);
3147 Next (Input);
3148 end loop;
3149 end if;
3150
3151 if Present (Component_Associations (Inputs)) then
3152 SPARK_Msg_N
3153 ("inputs must appear in named association form", Inputs);
3154 end if;
3155
3156 -- Single input item
3157
3158 else
3159 Analyze_Input_Item (Inputs);
3160 end if;
3161 end Analyze_Initialization_Item_With_Inputs;
3162
3163 --------------------------------
3164 -- Collect_States_And_Objects --
3165 --------------------------------
3166
3167 procedure Collect_States_And_Objects (Pack_Decl : Node_Id) is
3168 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
3169 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
3170 Decl : Node_Id;
3171 State_Elmt : Elmt_Id;
3172
3173 begin
3174 -- Collect the abstract states defined in the package (if any)
3175
3176 if Has_Non_Null_Abstract_State (Pack_Id) then
3177 State_Elmt := First_Elmt (Abstract_States (Pack_Id));
3178 while Present (State_Elmt) loop
3179 Append_New_Elmt (Node (State_Elmt), States_And_Objs);
3180 Next_Elmt (State_Elmt);
3181 end loop;
3182 end if;
3183
3184 -- Collect all objects that appear in the visible declarations of the
3185 -- related package.
3186
3187 if Present (Visible_Declarations (Pack_Spec)) then
3188 Decl := First (Visible_Declarations (Pack_Spec));
3189 while Present (Decl) loop
3190 if Comes_From_Source (Decl)
3191 and then Nkind_In (Decl, N_Object_Declaration,
3192 N_Object_Renaming_Declaration)
3193 then
3194 Append_New_Elmt (Defining_Entity (Decl), States_And_Objs);
3195
3196 elsif Nkind (Decl) = N_Package_Declaration then
3197 Collect_States_And_Objects (Decl);
3198
3199 elsif Is_Single_Concurrent_Type_Declaration (Decl) then
3200 Append_New_Elmt
3201 (Anonymous_Object (Defining_Entity (Decl)),
3202 States_And_Objs);
3203 end if;
3204
3205 Next (Decl);
3206 end loop;
3207 end if;
3208 end Collect_States_And_Objects;
3209
3210 -- Local variables
3211
3212 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3213 Init : Node_Id;
3214
3215 -- Start of processing for Analyze_Initializes_In_Decl_Part
3216
3217 begin
3218 -- Do not analyze the pragma multiple times
3219
3220 if Is_Analyzed_Pragma (N) then
3221 return;
3222 end if;
3223
3224 -- Nothing to do when the initialization list is empty
3225
3226 if Nkind (Inits) = N_Null then
3227 return;
3228 end if;
3229
3230 -- Single and multiple initialization clauses appear as an aggregate. If
3231 -- this is not the case, then either the parser or the analysis of the
3232 -- pragma failed to produce an aggregate.
3233
3234 pragma Assert (Nkind (Inits) = N_Aggregate);
3235
3236 -- Initialize the various lists used during analysis
3237
3238 Collect_States_And_Objects (Pack_Decl);
3239
3240 if Present (Expressions (Inits)) then
3241 Init := First (Expressions (Inits));
3242 while Present (Init) loop
3243 Analyze_Initialization_Item (Init);
3244 Next (Init);
3245 end loop;
3246 end if;
3247
3248 if Present (Component_Associations (Inits)) then
3249 Init := First (Component_Associations (Inits));
3250 while Present (Init) loop
3251 Analyze_Initialization_Item_With_Inputs (Init);
3252 Next (Init);
3253 end loop;
3254 end if;
3255
3256 -- Ensure that a state and a corresponding constituent do not appear
3257 -- together in pragma Initializes.
3258
3259 Check_State_And_Constituent_Use
3260 (States => States_Seen,
3261 Constits => Constits_Seen,
3262 Context => N);
3263
3264 Set_Is_Analyzed_Pragma (N);
3265 end Analyze_Initializes_In_Decl_Part;
3266
3267 ---------------------
3268 -- Analyze_Part_Of --
3269 ---------------------
3270
3271 procedure Analyze_Part_Of
3272 (Indic : Node_Id;
3273 Item_Id : Entity_Id;
3274 Encap : Node_Id;
3275 Encap_Id : out Entity_Id;
3276 Legal : out Boolean)
3277 is
3278 procedure Check_Part_Of_Abstract_State;
3279 pragma Inline (Check_Part_Of_Abstract_State);
3280 -- Verify the legality of indicator Part_Of when the encapsulator is an
3281 -- abstract state.
3282
3283 procedure Check_Part_Of_Concurrent_Type;
3284 pragma Inline (Check_Part_Of_Concurrent_Type);
3285 -- Verify the legality of indicator Part_Of when the encapsulator is a
3286 -- single concurrent type.
3287
3288 ----------------------------------
3289 -- Check_Part_Of_Abstract_State --
3290 ----------------------------------
3291
3292 procedure Check_Part_Of_Abstract_State is
3293 Pack_Id : Entity_Id;
3294 Placement : State_Space_Kind;
3295 Parent_Unit : Entity_Id;
3296
3297 begin
3298 -- Determine where the object, package instantiation or state lives
3299 -- with respect to the enclosing packages or package bodies.
3300
3301 Find_Placement_In_State_Space
3302 (Item_Id => Item_Id,
3303 Placement => Placement,
3304 Pack_Id => Pack_Id);
3305
3306 -- The item appears in a non-package construct with a declarative
3307 -- part (subprogram, block, etc). As such, the item is not allowed
3308 -- to be a part of an encapsulating state because the item is not
3309 -- visible.
3310
3311 if Placement = Not_In_Package then
3312 SPARK_Msg_N
3313 ("indicator Part_Of cannot appear in this context "
3314 & "(SPARK RM 7.2.6(5))", Indic);
3315
3316 Error_Msg_Name_1 := Chars (Scope (Encap_Id));
3317 SPARK_Msg_NE
3318 ("\& is not part of the hidden state of package %",
3319 Indic, Item_Id);
3320 return;
3321
3322 -- The item appears in the visible state space of some package. In
3323 -- general this scenario does not warrant Part_Of except when the
3324 -- package is a nongeneric private child unit and the encapsulating
3325 -- state is declared in a parent unit or a public descendant of that
3326 -- parent unit.
3327
3328 elsif Placement = Visible_State_Space then
3329 if Is_Child_Unit (Pack_Id)
3330 and then not Is_Generic_Unit (Pack_Id)
3331 and then Is_Private_Descendant (Pack_Id)
3332 then
3333 -- A variable or state abstraction which is part of the visible
3334 -- state of a nongeneric private child unit or its public
3335 -- descendants must have its Part_Of indicator specified. The
3336 -- Part_Of indicator must denote a state declared by either the
3337 -- parent unit of the private unit or by a public descendant of
3338 -- that parent unit.
3339
3340 -- Find the nearest private ancestor (which can be the current
3341 -- unit itself).
3342
3343 Parent_Unit := Pack_Id;
3344 while Present (Parent_Unit) loop
3345 exit when
3346 Private_Present
3347 (Parent (Unit_Declaration_Node (Parent_Unit)));
3348 Parent_Unit := Scope (Parent_Unit);
3349 end loop;
3350
3351 Parent_Unit := Scope (Parent_Unit);
3352
3353 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
3354 SPARK_Msg_NE
3355 ("indicator Part_Of must denote abstract state of & or of "
3356 & "its public descendant (SPARK RM 7.2.6(3))",
3357 Indic, Parent_Unit);
3358 return;
3359
3360 elsif Scope (Encap_Id) = Parent_Unit
3361 or else
3362 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id))
3363 and then not Is_Private_Descendant (Scope (Encap_Id)))
3364 then
3365 null;
3366
3367 else
3368 SPARK_Msg_NE
3369 ("indicator Part_Of must denote abstract state of & or of "
3370 & "its public descendant (SPARK RM 7.2.6(3))",
3371 Indic, Parent_Unit);
3372 return;
3373 end if;
3374
3375 -- Indicator Part_Of is not needed when the related package is
3376 -- not a nongeneric private child unit or a public descendant
3377 -- thereof.
3378
3379 else
3380 SPARK_Msg_N
3381 ("indicator Part_Of cannot appear in this context "
3382 & "(SPARK RM 7.2.6(5))", Indic);
3383
3384 Error_Msg_Name_1 := Chars (Pack_Id);
3385 SPARK_Msg_NE
3386 ("\& is declared in the visible part of package %",
3387 Indic, Item_Id);
3388 return;
3389 end if;
3390
3391 -- When the item appears in the private state space of a package, the
3392 -- encapsulating state must be declared in the same package.
3393
3394 elsif Placement = Private_State_Space then
3395 if Scope (Encap_Id) /= Pack_Id then
3396 SPARK_Msg_NE
3397 ("indicator Part_Of must denote an abstract state of "
3398 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3399
3400 Error_Msg_Name_1 := Chars (Pack_Id);
3401 SPARK_Msg_NE
3402 ("\& is declared in the private part of package %",
3403 Indic, Item_Id);
3404 return;
3405 end if;
3406
3407 -- Items declared in the body state space of a package do not need
3408 -- Part_Of indicators as the refinement has already been seen.
3409
3410 else
3411 SPARK_Msg_N
3412 ("indicator Part_Of cannot appear in this context "
3413 & "(SPARK RM 7.2.6(5))", Indic);
3414
3415 if Scope (Encap_Id) = Pack_Id then
3416 Error_Msg_Name_1 := Chars (Pack_Id);
3417 SPARK_Msg_NE
3418 ("\& is declared in the body of package %", Indic, Item_Id);
3419 end if;
3420
3421 return;
3422 end if;
3423
3424 -- At this point it is known that the Part_Of indicator is legal
3425
3426 Legal := True;
3427 end Check_Part_Of_Abstract_State;
3428
3429 -----------------------------------
3430 -- Check_Part_Of_Concurrent_Type --
3431 -----------------------------------
3432
3433 procedure Check_Part_Of_Concurrent_Type is
3434 function In_Proper_Order
3435 (First : Node_Id;
3436 Second : Node_Id) return Boolean;
3437 pragma Inline (In_Proper_Order);
3438 -- Determine whether node First precedes node Second
3439
3440 procedure Placement_Error;
3441 pragma Inline (Placement_Error);
3442 -- Emit an error concerning the illegal placement of the item with
3443 -- respect to the single concurrent type.
3444
3445 ---------------------
3446 -- In_Proper_Order --
3447 ---------------------
3448
3449 function In_Proper_Order
3450 (First : Node_Id;
3451 Second : Node_Id) return Boolean
3452 is
3453 N : Node_Id;
3454
3455 begin
3456 if List_Containing (First) = List_Containing (Second) then
3457 N := First;
3458 while Present (N) loop
3459 if N = Second then
3460 return True;
3461 end if;
3462
3463 Next (N);
3464 end loop;
3465 end if;
3466
3467 return False;
3468 end In_Proper_Order;
3469
3470 ---------------------
3471 -- Placement_Error --
3472 ---------------------
3473
3474 procedure Placement_Error is
3475 begin
3476 SPARK_Msg_N
3477 ("indicator Part_Of must denote a previously declared single "
3478 & "protected type or single task type", Encap);
3479 end Placement_Error;
3480
3481 -- Local variables
3482
3483 Conc_Typ : constant Entity_Id := Etype (Encap_Id);
3484 Encap_Decl : constant Node_Id := Declaration_Node (Encap_Id);
3485 Encap_Context : constant Node_Id := Parent (Encap_Decl);
3486
3487 Item_Context : Node_Id;
3488 Item_Decl : Node_Id;
3489 Prv_Decls : List_Id;
3490 Vis_Decls : List_Id;
3491
3492 -- Start of processing for Check_Part_Of_Concurrent_Type
3493
3494 begin
3495 -- Only abstract states and variables can act as constituents of an
3496 -- encapsulating single concurrent type.
3497
3498 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
3499 null;
3500
3501 -- The constituent is a constant
3502
3503 elsif Ekind (Item_Id) = E_Constant then
3504 Error_Msg_Name_1 := Chars (Encap_Id);
3505 SPARK_Msg_NE
3506 (Fix_Msg (Conc_Typ, "constant & cannot act as constituent of "
3507 & "single protected type %"), Indic, Item_Id);
3508 return;
3509
3510 -- The constituent is a package instantiation
3511
3512 else
3513 Error_Msg_Name_1 := Chars (Encap_Id);
3514 SPARK_Msg_NE
3515 (Fix_Msg (Conc_Typ, "package instantiation & cannot act as "
3516 & "constituent of single protected type %"), Indic, Item_Id);
3517 return;
3518 end if;
3519
3520 -- When the item denotes an abstract state of a nested package, use
3521 -- the declaration of the package to detect proper placement.
3522
3523 -- package Pack is
3524 -- task T;
3525 -- package Nested
3526 -- with Abstract_State => (State with Part_Of => T)
3527
3528 if Ekind (Item_Id) = E_Abstract_State then
3529 Item_Decl := Unit_Declaration_Node (Scope (Item_Id));
3530 else
3531 Item_Decl := Declaration_Node (Item_Id);
3532 end if;
3533
3534 Item_Context := Parent (Item_Decl);
3535
3536 -- The item and the single concurrent type must appear in the same
3537 -- declarative region, with the item following the declaration of
3538 -- the single concurrent type (SPARK RM 9(3)).
3539
3540 if Item_Context = Encap_Context then
3541 if Nkind_In (Item_Context, N_Package_Specification,
3542 N_Protected_Definition,
3543 N_Task_Definition)
3544 then
3545 Prv_Decls := Private_Declarations (Item_Context);
3546 Vis_Decls := Visible_Declarations (Item_Context);
3547
3548 -- The placement is OK when the single concurrent type appears
3549 -- within the visible declarations and the item in the private
3550 -- declarations.
3551 --
3552 -- package Pack is
3553 -- protected PO ...
3554 -- private
3555 -- Constit : ... with Part_Of => PO;
3556 -- end Pack;
3557
3558 if List_Containing (Encap_Decl) = Vis_Decls
3559 and then List_Containing (Item_Decl) = Prv_Decls
3560 then
3561 null;
3562
3563 -- The placement is illegal when the item appears within the
3564 -- visible declarations and the single concurrent type is in
3565 -- the private declarations.
3566 --
3567 -- package Pack is
3568 -- Constit : ... with Part_Of => PO;
3569 -- private
3570 -- protected PO ...
3571 -- end Pack;
3572
3573 elsif List_Containing (Item_Decl) = Vis_Decls
3574 and then List_Containing (Encap_Decl) = Prv_Decls
3575 then
3576 Placement_Error;
3577 return;
3578
3579 -- Otherwise both the item and the single concurrent type are
3580 -- in the same list. Ensure that the declaration of the single
3581 -- concurrent type precedes that of the item.
3582
3583 elsif not In_Proper_Order
3584 (First => Encap_Decl,
3585 Second => Item_Decl)
3586 then
3587 Placement_Error;
3588 return;
3589 end if;
3590
3591 -- Otherwise both the item and the single concurrent type are
3592 -- in the same list. Ensure that the declaration of the single
3593 -- concurrent type precedes that of the item.
3594
3595 elsif not In_Proper_Order
3596 (First => Encap_Decl,
3597 Second => Item_Decl)
3598 then
3599 Placement_Error;
3600 return;
3601 end if;
3602
3603 -- Otherwise the item and the single concurrent type reside within
3604 -- unrelated regions.
3605
3606 else
3607 Error_Msg_Name_1 := Chars (Encap_Id);
3608 SPARK_Msg_NE
3609 (Fix_Msg (Conc_Typ, "constituent & must be declared "
3610 & "immediately within the same region as single protected "
3611 & "type %"), Indic, Item_Id);
3612 return;
3613 end if;
3614
3615 -- At this point it is known that the Part_Of indicator is legal
3616
3617 Legal := True;
3618 end Check_Part_Of_Concurrent_Type;
3619
3620 -- Start of processing for Analyze_Part_Of
3621
3622 begin
3623 -- Assume that the indicator is illegal
3624
3625 Encap_Id := Empty;
3626 Legal := False;
3627
3628 if Nkind_In (Encap, N_Expanded_Name,
3629 N_Identifier,
3630 N_Selected_Component)
3631 then
3632 Analyze (Encap);
3633 Resolve_State (Encap);
3634
3635 Encap_Id := Entity (Encap);
3636
3637 -- The encapsulator is an abstract state
3638
3639 if Ekind (Encap_Id) = E_Abstract_State then
3640 null;
3641
3642 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3643
3644 elsif Is_Single_Concurrent_Object (Encap_Id) then
3645 null;
3646
3647 -- Otherwise the encapsulator is not a legal choice
3648
3649 else
3650 SPARK_Msg_N
3651 ("indicator Part_Of must denote abstract state, single "
3652 & "protected type or single task type", Encap);
3653 return;
3654 end if;
3655
3656 -- This is a syntax error, always report
3657
3658 else
3659 Error_Msg_N
3660 ("indicator Part_Of must denote abstract state, single protected "
3661 & "type or single task type", Encap);
3662 return;
3663 end if;
3664
3665 -- Catch a case where indicator Part_Of denotes the abstract view of a
3666 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3667
3668 if From_Limited_With (Encap_Id)
3669 and then Present (Non_Limited_View (Encap_Id))
3670 and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable
3671 then
3672 SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap);
3673 SPARK_Msg_N ("\& denotes abstract view of object", Encap);
3674 return;
3675 end if;
3676
3677 -- The encapsulator is an abstract state
3678
3679 if Ekind (Encap_Id) = E_Abstract_State then
3680 Check_Part_Of_Abstract_State;
3681
3682 -- The encapsulator is a single concurrent type
3683
3684 else
3685 Check_Part_Of_Concurrent_Type;
3686 end if;
3687 end Analyze_Part_Of;
3688
3689 ----------------------------------
3690 -- Analyze_Part_Of_In_Decl_Part --
3691 ----------------------------------
3692
3693 procedure Analyze_Part_Of_In_Decl_Part
3694 (N : Node_Id;
3695 Freeze_Id : Entity_Id := Empty)
3696 is
3697 Encap : constant Node_Id :=
3698 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
3699 Errors : constant Nat := Serious_Errors_Detected;
3700 Var_Decl : constant Node_Id := Find_Related_Context (N);
3701 Var_Id : constant Entity_Id := Defining_Entity (Var_Decl);
3702 Constits : Elist_Id;
3703 Encap_Id : Entity_Id;
3704 Legal : Boolean;
3705
3706 begin
3707 -- Detect any discrepancies between the placement of the variable with
3708 -- respect to general state space and the encapsulating state or single
3709 -- concurrent type.
3710
3711 Analyze_Part_Of
3712 (Indic => N,
3713 Item_Id => Var_Id,
3714 Encap => Encap,
3715 Encap_Id => Encap_Id,
3716 Legal => Legal);
3717
3718 -- The Part_Of indicator turns the variable into a constituent of the
3719 -- encapsulating state or single concurrent type.
3720
3721 if Legal then
3722 pragma Assert (Present (Encap_Id));
3723 Constits := Part_Of_Constituents (Encap_Id);
3724
3725 if No (Constits) then
3726 Constits := New_Elmt_List;
3727 Set_Part_Of_Constituents (Encap_Id, Constits);
3728 end if;
3729
3730 Append_Elmt (Var_Id, Constits);
3731 Set_Encapsulating_State (Var_Id, Encap_Id);
3732
3733 -- A Part_Of constituent partially refines an abstract state. This
3734 -- property does not apply to protected or task units.
3735
3736 if Ekind (Encap_Id) = E_Abstract_State then
3737 Set_Has_Partial_Visible_Refinement (Encap_Id);
3738 end if;
3739 end if;
3740
3741 -- Emit a clarification message when the encapsulator is undefined,
3742 -- possibly due to contract freezing.
3743
3744 if Errors /= Serious_Errors_Detected
3745 and then Present (Freeze_Id)
3746 and then Has_Undefined_Reference (Encap)
3747 then
3748 Contract_Freeze_Error (Var_Id, Freeze_Id);
3749 end if;
3750 end Analyze_Part_Of_In_Decl_Part;
3751
3752 --------------------
3753 -- Analyze_Pragma --
3754 --------------------
3755
3756 procedure Analyze_Pragma (N : Node_Id) is
3757 Loc : constant Source_Ptr := Sloc (N);
3758
3759 Pname : Name_Id := Pragma_Name (N);
3760 -- Name of the source pragma, or name of the corresponding aspect for
3761 -- pragmas which originate in a source aspect. In the latter case, the
3762 -- name may be different from the pragma name.
3763
3764 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
3765
3766 Pragma_Exit : exception;
3767 -- This exception is used to exit pragma processing completely. It
3768 -- is used when an error is detected, and no further processing is
3769 -- required. It is also used if an earlier error has left the tree in
3770 -- a state where the pragma should not be processed.
3771
3772 Arg_Count : Nat;
3773 -- Number of pragma argument associations
3774
3775 Arg1 : Node_Id;
3776 Arg2 : Node_Id;
3777 Arg3 : Node_Id;
3778 Arg4 : Node_Id;
3779 -- First four pragma arguments (pragma argument association nodes, or
3780 -- Empty if the corresponding argument does not exist).
3781
3782 type Name_List is array (Natural range <>) of Name_Id;
3783 type Args_List is array (Natural range <>) of Node_Id;
3784 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3785
3786 -----------------------
3787 -- Local Subprograms --
3788 -----------------------
3789
3790 function Acc_First (N : Node_Id) return Node_Id;
3791 -- Helper function to iterate over arguments given to OpenAcc pragmas
3792
3793 function Acc_Next (N : Node_Id) return Node_Id;
3794 -- Helper function to iterate over arguments given to OpenAcc pragmas
3795
3796 procedure Ada_2005_Pragma;
3797 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3798 -- Ada 95 mode, these are implementation defined pragmas, so should be
3799 -- caught by the No_Implementation_Pragmas restriction.
3800
3801 procedure Ada_2012_Pragma;
3802 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3803 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3804 -- should be caught by the No_Implementation_Pragmas restriction.
3805
3806 procedure Analyze_Depends_Global
3807 (Spec_Id : out Entity_Id;
3808 Subp_Decl : out Node_Id;
3809 Legal : out Boolean);
3810 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3811 -- legality of the placement and related context of the pragma. Spec_Id
3812 -- is the entity of the related subprogram. Subp_Decl is the declaration
3813 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3814
3815 procedure Analyze_If_Present (Id : Pragma_Id);
3816 -- Inspect the remainder of the list containing pragma N and look for
3817 -- a pragma that matches Id. If found, analyze the pragma.
3818
3819 procedure Analyze_Pre_Post_Condition;
3820 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3821
3822 procedure Analyze_Refined_Depends_Global_Post
3823 (Spec_Id : out Entity_Id;
3824 Body_Id : out Entity_Id;
3825 Legal : out Boolean);
3826 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3827 -- Refined_Global and Refined_Post. Verify the legality of the placement
3828 -- and related context of the pragma. Spec_Id is the entity of the
3829 -- related subprogram. Body_Id is the entity of the subprogram body.
3830 -- Flag Legal is set when the pragma is legal.
3831
3832 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False);
3833 -- Perform full analysis of pragma Unmodified and the write aspect of
3834 -- pragma Unused. Flag Is_Unused should be set when verifying the
3835 -- semantics of pragma Unused.
3836
3837 procedure Analyze_Unreferenced_Or_Unused (Is_Unused : Boolean := False);
3838 -- Perform full analysis of pragma Unreferenced and the read aspect of
3839 -- pragma Unused. Flag Is_Unused should be set when verifying the
3840 -- semantics of pragma Unused.
3841
3842 procedure Check_Ada_83_Warning;
3843 -- Issues a warning message for the current pragma if operating in Ada
3844 -- 83 mode (used for language pragmas that are not a standard part of
3845 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3846 -- of 95 pragma.
3847
3848 procedure Check_Arg_Count (Required : Nat);
3849 -- Check argument count for pragma is equal to given parameter. If not,
3850 -- then issue an error message and raise Pragma_Exit.
3851
3852 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3853 -- Arg which can either be a pragma argument association, in which case
3854 -- the check is applied to the expression of the association or an
3855 -- expression directly.
3856
3857 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
3858 -- Check that an argument has the right form for an EXTERNAL_NAME
3859 -- parameter of an extended import/export pragma. The rule is that the
3860 -- name must be an identifier or string literal (in Ada 83 mode) or a
3861 -- static string expression (in Ada 95 mode).
3862
3863 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
3864 -- Check the specified argument Arg to make sure that it is an
3865 -- identifier. If not give error and raise Pragma_Exit.
3866
3867 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
3868 -- Check the specified argument Arg to make sure that it is an integer
3869 -- literal. If not give error and raise Pragma_Exit.
3870
3871 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
3872 -- Check the specified argument Arg to make sure that it has the proper
3873 -- syntactic form for a local name and meets the semantic requirements
3874 -- for a local name. The local name is analyzed as part of the
3875 -- processing for this call. In addition, the local name is required
3876 -- to represent an entity at the library level.
3877
3878 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
3879 -- Check the specified argument Arg to make sure that it has the proper
3880 -- syntactic form for a local name and meets the semantic requirements
3881 -- for a local name. The local name is analyzed as part of the
3882 -- processing for this call.
3883
3884 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
3885 -- Check the specified argument Arg to make sure that it is a valid
3886 -- locking policy name. If not give error and raise Pragma_Exit.
3887
3888 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
3889 -- Check the specified argument Arg to make sure that it is a valid
3890 -- elaboration policy name. If not give error and raise Pragma_Exit.
3891
3892 procedure Check_Arg_Is_One_Of
3893 (Arg : Node_Id;
3894 N1, N2 : Name_Id);
3895 procedure Check_Arg_Is_One_Of
3896 (Arg : Node_Id;
3897 N1, N2, N3 : Name_Id);
3898 procedure Check_Arg_Is_One_Of
3899 (Arg : Node_Id;
3900 N1, N2, N3, N4 : Name_Id);
3901 procedure Check_Arg_Is_One_Of
3902 (Arg : Node_Id;
3903 N1, N2, N3, N4, N5 : Name_Id);
3904 -- Check the specified argument Arg to make sure that it is an
3905 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3906 -- present). If not then give error and raise Pragma_Exit.
3907
3908 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
3909 -- Check the specified argument Arg to make sure that it is a valid
3910 -- queuing policy name. If not give error and raise Pragma_Exit.
3911
3912 procedure Check_Arg_Is_OK_Static_Expression
3913 (Arg : Node_Id;
3914 Typ : Entity_Id := Empty);
3915 -- Check the specified argument Arg to make sure that it is a static
3916 -- expression of the given type (i.e. it will be analyzed and resolved
3917 -- using this type, which can be any valid argument to Resolve, e.g.
3918 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3919 -- Typ is left Empty, then any static expression is allowed. Includes
3920 -- checking that the argument does not raise Constraint_Error.
3921
3922 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
3923 -- Check the specified argument Arg to make sure that it is a valid task
3924 -- dispatching policy name. If not give error and raise Pragma_Exit.
3925
3926 procedure Check_Arg_Order (Names : Name_List);
3927 -- Checks for an instance of two arguments with identifiers for the
3928 -- current pragma which are not in the sequence indicated by Names,
3929 -- and if so, generates a fatal message about bad order of arguments.
3930
3931 procedure Check_At_Least_N_Arguments (N : Nat);
3932 -- Check there are at least N arguments present
3933
3934 procedure Check_At_Most_N_Arguments (N : Nat);
3935 -- Check there are no more than N arguments present
3936
3937 procedure Check_Atomic_VFA (E : Entity_Id; VFA : Boolean);
3938 -- Apply legality checks to type or object E subject to an Atomic aspect
3939 -- in Ada 2020 (RM C.6(13)) or to a Volatile_Full_Access aspect.
3940
3941 procedure Check_Component
3942 (Comp : Node_Id;
3943 UU_Typ : Entity_Id;
3944 In_Variant_Part : Boolean := False);
3945 -- Examine an Unchecked_Union component for correct use of per-object
3946 -- constrained subtypes, and for restrictions on finalizable components.
3947 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3948 -- should be set when Comp comes from a record variant.
3949
3950 procedure Check_Duplicate_Pragma (E : Entity_Id);
3951 -- Check if a rep item of the same name as the current pragma is already
3952 -- chained as a rep pragma to the given entity. If so give a message
3953 -- about the duplicate, and then raise Pragma_Exit so does not return.
3954 -- Note that if E is a type, then this routine avoids flagging a pragma
3955 -- which applies to a parent type from which E is derived.
3956
3957 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
3958 -- Nam is an N_String_Literal node containing the external name set by
3959 -- an Import or Export pragma (or extended Import or Export pragma).
3960 -- This procedure checks for possible duplications if this is the export
3961 -- case, and if found, issues an appropriate error message.
3962
3963 procedure Check_Expr_Is_OK_Static_Expression
3964 (Expr : Node_Id;
3965 Typ : Entity_Id := Empty);
3966 -- Check the specified expression Expr to make sure that it is a static
3967 -- expression of the given type (i.e. it will be analyzed and resolved
3968 -- using this type, which can be any valid argument to Resolve, e.g.
3969 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3970 -- Typ is left Empty, then any static expression is allowed. Includes
3971 -- checking that the expression does not raise Constraint_Error.
3972
3973 procedure Check_First_Subtype (Arg : Node_Id);
3974 -- Checks that Arg, whose expression is an entity name, references a
3975 -- first subtype.
3976
3977 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
3978 -- Checks that the given argument has an identifier, and if so, requires
3979 -- it to match the given identifier name. If there is no identifier, or
3980 -- a non-matching identifier, then an error message is given and
3981 -- Pragma_Exit is raised.
3982
3983 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
3984 -- Checks that the given argument has an identifier, and if so, requires
3985 -- it to match one of the given identifier names. If there is no
3986 -- identifier, or a non-matching identifier, then an error message is
3987 -- given and Pragma_Exit is raised.
3988
3989 procedure Check_In_Main_Program;
3990 -- Common checks for pragmas that appear within a main program
3991 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3992
3993 procedure Check_Interrupt_Or_Attach_Handler;
3994 -- Common processing for first argument of pragma Interrupt_Handler or
3995 -- pragma Attach_Handler.
3996
3997 procedure Check_Loop_Pragma_Placement;
3998 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
3999 -- appear immediately within a construct restricted to loops, and that
4000 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
4001
4002 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
4003 -- Check that pragma appears in a declarative part, or in a package
4004 -- specification, i.e. that it does not occur in a statement sequence
4005 -- in a body.
4006
4007 procedure Check_No_Identifier (Arg : Node_Id);
4008 -- Checks that the given argument does not have an identifier. If
4009 -- an identifier is present, then an error message is issued, and
4010 -- Pragma_Exit is raised.
4011
4012 procedure Check_No_Identifiers;
4013 -- Checks that none of the arguments to the pragma has an identifier.
4014 -- If any argument has an identifier, then an error message is issued,
4015 -- and Pragma_Exit is raised.
4016
4017 procedure Check_No_Link_Name;
4018 -- Checks that no link name is specified
4019
4020 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
4021 -- Checks if the given argument has an identifier, and if so, requires
4022 -- it to match the given identifier name. If there is a non-matching
4023 -- identifier, then an error message is given and Pragma_Exit is raised.
4024
4025 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
4026 -- Checks if the given argument has an identifier, and if so, requires
4027 -- it to match the given identifier name. If there is a non-matching
4028 -- identifier, then an error message is given and Pragma_Exit is raised.
4029 -- In this version of the procedure, the identifier name is given as
4030 -- a string with lower case letters.
4031
4032 procedure Check_Static_Boolean_Expression (Expr : Node_Id);
4033 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
4034 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
4035 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
4036 -- is an OK static boolean expression. Emit an error if this is not the
4037 -- case.
4038
4039 procedure Check_Static_Constraint (Constr : Node_Id);
4040 -- Constr is a constraint from an N_Subtype_Indication node from a
4041 -- component constraint in an Unchecked_Union type. This routine checks
4042 -- that the constraint is static as required by the restrictions for
4043 -- Unchecked_Union.
4044
4045 procedure Check_Valid_Configuration_Pragma;
4046 -- Legality checks for placement of a configuration pragma
4047
4048 procedure Check_Valid_Library_Unit_Pragma;
4049 -- Legality checks for library unit pragmas. A special case arises for
4050 -- pragmas in generic instances that come from copies of the original
4051 -- library unit pragmas in the generic templates. In the case of other
4052 -- than library level instantiations these can appear in contexts which
4053 -- would normally be invalid (they only apply to the original template
4054 -- and to library level instantiations), and they are simply ignored,
4055 -- which is implemented by rewriting them as null statements.
4056
4057 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
4058 -- Check an Unchecked_Union variant for lack of nested variants and
4059 -- presence of at least one component. UU_Typ is the related Unchecked_
4060 -- Union type.
4061
4062 procedure Ensure_Aggregate_Form (Arg : Node_Id);
4063 -- Subsidiary routine to the processing of pragmas Abstract_State,
4064 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
4065 -- Refined_Global and Refined_State. Transform argument Arg into
4066 -- an aggregate if not one already. N_Null is never transformed.
4067 -- Arg may denote an aspect specification or a pragma argument
4068 -- association.
4069
4070 procedure Error_Pragma (Msg : String);
4071 pragma No_Return (Error_Pragma);
4072 -- Outputs error message for current pragma. The message contains a %
4073 -- that will be replaced with the pragma name, and the flag is placed
4074 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
4075 -- calls Fix_Error (see spec of that procedure for details).
4076
4077 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
4078 pragma No_Return (Error_Pragma_Arg);
4079 -- Outputs error message for current pragma. The message may contain
4080 -- a % that will be replaced with the pragma name. The parameter Arg
4081 -- may either be a pragma argument association, in which case the flag
4082 -- is placed on the expression of this association, or an expression,
4083 -- in which case the flag is placed directly on the expression. The
4084 -- message is placed using Error_Msg_N, so the message may also contain
4085 -- an & insertion character which will reference the given Arg value.
4086 -- After placing the message, Pragma_Exit is raised. Note: this routine
4087 -- calls Fix_Error (see spec of that procedure for details).
4088
4089 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
4090 pragma No_Return (Error_Pragma_Arg);
4091 -- Similar to above form of Error_Pragma_Arg except that two messages
4092 -- are provided, the second is a continuation comment starting with \.
4093
4094 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
4095 pragma No_Return (Error_Pragma_Arg_Ident);
4096 -- Outputs error message for current pragma. The message may contain a %
4097 -- that will be replaced with the pragma name. The parameter Arg must be
4098 -- a pragma argument association with a non-empty identifier (i.e. its
4099 -- Chars field must be set), and the error message is placed on the
4100 -- identifier. The message is placed using Error_Msg_N so the message
4101 -- may also contain an & insertion character which will reference
4102 -- the identifier. After placing the message, Pragma_Exit is raised.
4103 -- Note: this routine calls Fix_Error (see spec of that procedure for
4104 -- details).
4105
4106 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
4107 pragma No_Return (Error_Pragma_Ref);
4108 -- Outputs error message for current pragma. The message may contain
4109 -- a % that will be replaced with the pragma name. The parameter Ref
4110 -- must be an entity whose name can be referenced by & and sloc by #.
4111 -- After placing the message, Pragma_Exit is raised. Note: this routine
4112 -- calls Fix_Error (see spec of that procedure for details).
4113
4114 function Find_Lib_Unit_Name return Entity_Id;
4115 -- Used for a library unit pragma to find the entity to which the
4116 -- library unit pragma applies, returns the entity found.
4117
4118 procedure Find_Program_Unit_Name (Id : Node_Id);
4119 -- If the pragma is a compilation unit pragma, the id must denote the
4120 -- compilation unit in the same compilation, and the pragma must appear
4121 -- in the list of preceding or trailing pragmas. If it is a program
4122 -- unit pragma that is not a compilation unit pragma, then the
4123 -- identifier must be visible.
4124
4125 function Find_Unique_Parameterless_Procedure
4126 (Name : Entity_Id;
4127 Arg : Node_Id) return Entity_Id;
4128 -- Used for a procedure pragma to find the unique parameterless
4129 -- procedure identified by Name, returns it if it exists, otherwise
4130 -- errors out and uses Arg as the pragma argument for the message.
4131
4132 function Fix_Error (Msg : String) return String;
4133 -- This is called prior to issuing an error message. Msg is the normal
4134 -- error message issued in the pragma case. This routine checks for the
4135 -- case of a pragma coming from an aspect in the source, and returns a
4136 -- message suitable for the aspect case as follows:
4137 --
4138 -- Each substring "pragma" is replaced by "aspect"
4139 --
4140 -- If "argument of" is at the start of the error message text, it is
4141 -- replaced by "entity for".
4142 --
4143 -- If "argument" is at the start of the error message text, it is
4144 -- replaced by "entity".
4145 --
4146 -- So for example, "argument of pragma X must be discrete type"
4147 -- returns "entity for aspect X must be a discrete type".
4148
4149 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
4150 -- be different from the pragma name). If the current pragma results
4151 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
4152 -- original pragma name.
4153
4154 procedure Gather_Associations
4155 (Names : Name_List;
4156 Args : out Args_List);
4157 -- This procedure is used to gather the arguments for a pragma that
4158 -- permits arbitrary ordering of parameters using the normal rules
4159 -- for named and positional parameters. The Names argument is a list
4160 -- of Name_Id values that corresponds to the allowed pragma argument
4161 -- association identifiers in order. The result returned in Args is
4162 -- a list of corresponding expressions that are the pragma arguments.
4163 -- Note that this is a list of expressions, not of pragma argument
4164 -- associations (Gather_Associations has completely checked all the
4165 -- optional identifiers when it returns). An entry in Args is Empty
4166 -- on return if the corresponding argument is not present.
4167
4168 procedure GNAT_Pragma;
4169 -- Called for all GNAT defined pragmas to check the relevant restriction
4170 -- (No_Implementation_Pragmas).
4171
4172 function Is_Before_First_Decl
4173 (Pragma_Node : Node_Id;
4174 Decls : List_Id) return Boolean;
4175 -- Return True if Pragma_Node is before the first declarative item in
4176 -- Decls where Decls is the list of declarative items.
4177
4178 function Is_Configuration_Pragma return Boolean;
4179 -- Determines if the placement of the current pragma is appropriate
4180 -- for a configuration pragma.
4181
4182 function Is_In_Context_Clause return Boolean;
4183 -- Returns True if pragma appears within the context clause of a unit,
4184 -- and False for any other placement (does not generate any messages).
4185
4186 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
4187 -- Analyzes the argument, and determines if it is a static string
4188 -- expression, returns True if so, False if non-static or not String.
4189 -- A special case is that a string literal returns True in Ada 83 mode
4190 -- (which has no such thing as static string expressions). Note that
4191 -- the call analyzes its argument, so this cannot be used for the case
4192 -- where an identifier might not be declared.
4193
4194 procedure Pragma_Misplaced;
4195 pragma No_Return (Pragma_Misplaced);
4196 -- Issue fatal error message for misplaced pragma
4197
4198 procedure Process_Atomic_Independent_Shared_Volatile;
4199 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
4200 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
4201 -- and treated as being identical in effect to pragma Atomic.
4202
4203 procedure Process_Compile_Time_Warning_Or_Error;
4204 -- Common processing for Compile_Time_Error and Compile_Time_Warning
4205
4206 procedure Process_Convention
4207 (C : out Convention_Id;
4208 Ent : out Entity_Id);
4209 -- Common processing for Convention, Interface, Import and Export.
4210 -- Checks first two arguments of pragma, and sets the appropriate
4211 -- convention value in the specified entity or entities. On return
4212 -- C is the convention, Ent is the referenced entity.
4213
4214 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
4215 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
4216 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
4217
4218 procedure Process_Extended_Import_Export_Object_Pragma
4219 (Arg_Internal : Node_Id;
4220 Arg_External : Node_Id;
4221 Arg_Size : Node_Id);
4222 -- Common processing for the pragmas Import/Export_Object. The three
4223 -- arguments correspond to the three named parameters of the pragmas. An
4224 -- argument is empty if the corresponding parameter is not present in
4225 -- the pragma.
4226
4227 procedure Process_Extended_Import_Export_Internal_Arg
4228 (Arg_Internal : Node_Id := Empty);
4229 -- Common processing for all extended Import and Export pragmas. The
4230 -- argument is the pragma parameter for the Internal argument. If
4231 -- Arg_Internal is empty or inappropriate, an error message is posted.
4232 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
4233 -- set to identify the referenced entity.
4234
4235 procedure Process_Extended_Import_Export_Subprogram_Pragma
4236 (Arg_Internal : Node_Id;
4237 Arg_External : Node_Id;
4238 Arg_Parameter_Types : Node_Id;
4239 Arg_Result_Type : Node_Id := Empty;
4240 Arg_Mechanism : Node_Id;
4241 Arg_Result_Mechanism : Node_Id := Empty);
4242 -- Common processing for all extended Import and Export pragmas applying
4243 -- to subprograms. The caller omits any arguments that do not apply to
4244 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
4245 -- only in the Import_Function and Export_Function cases). The argument
4246 -- names correspond to the allowed pragma association identifiers.
4247
4248 procedure Process_Generic_List;
4249 -- Common processing for Share_Generic and Inline_Generic
4250
4251 procedure Process_Import_Or_Interface;
4252 -- Common processing for Import or Interface
4253
4254 procedure Process_Import_Predefined_Type;
4255 -- Processing for completing a type with pragma Import. This is used
4256 -- to declare types that match predefined C types, especially for cases
4257 -- without corresponding Ada predefined type.
4258
4259 type Inline_Status is (Suppressed, Disabled, Enabled);
4260 -- Inline status of a subprogram, indicated as follows:
4261 -- Suppressed: inlining is suppressed for the subprogram
4262 -- Disabled: no inlining is requested for the subprogram
4263 -- Enabled: inlining is requested/required for the subprogram
4264
4265 procedure Process_Inline (Status : Inline_Status);
4266 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
4267 -- indicates the inline status specified by the pragma.
4268
4269 procedure Process_Interface_Name
4270 (Subprogram_Def : Entity_Id;
4271 Ext_Arg : Node_Id;
4272 Link_Arg : Node_Id;
4273 Prag : Node_Id);
4274 -- Given the last two arguments of pragma Import, pragma Export, or
4275 -- pragma Interface_Name, performs validity checks and sets the
4276 -- Interface_Name field of the given subprogram entity to the
4277 -- appropriate external or link name, depending on the arguments given.
4278 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
4279 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
4280 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
4281 -- nor Link_Arg is present, the interface name is set to the default
4282 -- from the subprogram name. In addition, the pragma itself is passed
4283 -- to analyze any expressions in the case the pragma came from an aspect
4284 -- specification.
4285
4286 procedure Process_Interrupt_Or_Attach_Handler;
4287 -- Common processing for Interrupt and Attach_Handler pragmas
4288
4289 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
4290 -- Common processing for Restrictions and Restriction_Warnings pragmas.
4291 -- Warn is True for Restriction_Warnings, or for Restrictions if the
4292 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
4293 -- is not set in the Restrictions case.
4294
4295 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
4296 -- Common processing for Suppress and Unsuppress. The boolean parameter
4297 -- Suppress_Case is True for the Suppress case, and False for the
4298 -- Unsuppress case.
4299
4300 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
4301 -- Subsidiary to the analysis of pragmas Independent[_Components].
4302 -- Record such a pragma N applied to entity E for future checks.
4303
4304 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
4305 -- This procedure sets the Is_Exported flag for the given entity,
4306 -- checking that the entity was not previously imported. Arg is
4307 -- the argument that specified the entity. A check is also made
4308 -- for exporting inappropriate entities.
4309
4310 procedure Set_Extended_Import_Export_External_Name
4311 (Internal_Ent : Entity_Id;
4312 Arg_External : Node_Id);
4313 -- Common processing for all extended import export pragmas. The first
4314 -- argument, Internal_Ent, is the internal entity, which has already
4315 -- been checked for validity by the caller. Arg_External is from the
4316 -- Import or Export pragma, and may be null if no External parameter
4317 -- was present. If Arg_External is present and is a non-null string
4318 -- (a null string is treated as the default), then the Interface_Name
4319 -- field of Internal_Ent is set appropriately.
4320
4321 procedure Set_Imported (E : Entity_Id);
4322 -- This procedure sets the Is_Imported flag for the given entity,
4323 -- checking that it is not previously exported or imported.
4324
4325 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
4326 -- Mech is a parameter passing mechanism (see Import_Function syntax
4327 -- for MECHANISM_NAME). This routine checks that the mechanism argument
4328 -- has the right form, and if not issues an error message. If the
4329 -- argument has the right form then the Mechanism field of Ent is
4330 -- set appropriately.
4331
4332 procedure Set_Rational_Profile;
4333 -- Activate the set of configuration pragmas and permissions that make
4334 -- up the Rational profile.
4335
4336 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id);
4337 -- Activate the set of configuration pragmas and restrictions that make
4338 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
4339 -- GNAT_Ravenscar_EDF, or Ravenscar. N is the corresponding pragma node,
4340 -- which is used for error messages on any constructs violating the
4341 -- profile.
4342
4343 procedure Validate_Acc_Condition_Clause (Clause : Node_Id);
4344 -- Make sure the argument of a given Acc_If clause is a Boolean
4345
4346 procedure Validate_Acc_Data_Clause (Clause : Node_Id);
4347 -- Make sure the argument of an OpenAcc data clause (e.g. Copy, Copyin,
4348 -- Copyout...) is an identifier or an aggregate of identifiers.
4349
4350 procedure Validate_Acc_Int_Expr_Clause (Clause : Node_Id);
4351 -- Make sure the argument of an OpenAcc clause is an Integer expression
4352
4353 procedure Validate_Acc_Int_Expr_List_Clause (Clause : Node_Id);
4354 -- Make sure the argument of an OpenAcc clause is an Integer expression
4355 -- or a list of Integer expressions.
4356
4357 procedure Validate_Acc_Loop_Collapse (Clause : Node_Id);
4358 -- Make sure that the parent loop of the Acc_Loop(Collapse => N) pragma
4359 -- contains at least N-1 nested loops.
4360
4361 procedure Validate_Acc_Loop_Gang (Clause : Node_Id);
4362 -- Make sure the argument of the Gang clause of a Loop directive is
4363 -- either an integer expression or a (Static => integer expressions)
4364 -- aggregate.
4365
4366 procedure Validate_Acc_Loop_Vector (Clause : Node_Id);
4367 -- When this procedure is called in a construct offloaded by an
4368 -- Acc_Kernels pragma, makes sure that a Vector_Length clause does
4369 -- not exist on said pragma. In all cases, make sure the argument
4370 -- is an Integer expression.
4371
4372 procedure Validate_Acc_Loop_Worker (Clause : Node_Id);
4373 -- When this procedure is called in a construct offloaded by an
4374 -- Acc_Parallel pragma, makes sure that no argument has been given.
4375 -- When this procedure is called in a construct offloaded by an
4376 -- Acc_Kernels pragma and if Loop_Worker was given an argument,
4377 -- makes sure that the Num_Workers clause does not appear on the
4378 -- Acc_Kernels pragma and that the argument is an integer.
4379
4380 procedure Validate_Acc_Name_Reduction (Clause : Node_Id);
4381 -- Make sure the reduction clause is an aggregate made of a string
4382 -- representing a supported reduction operation (i.e. "+", "*", "and",
4383 -- "or", "min" or "max") and either an identifier or aggregate of
4384 -- identifiers.
4385
4386 procedure Validate_Acc_Size_Expressions (Clause : Node_Id);
4387 -- Makes sure that Clause is either an integer expression or an
4388 -- association with a Static as name and a list of integer expressions
4389 -- or "*" strings on the right hand side.
4390
4391 ---------------
4392 -- Acc_First --
4393 ---------------
4394
4395 function Acc_First (N : Node_Id) return Node_Id is
4396 begin
4397 if Nkind (N) = N_Aggregate then
4398 if Present (Expressions (N)) then
4399 return First (Expressions (N));
4400
4401 elsif Present (Component_Associations (N)) then
4402 return Expression (First (Component_Associations (N)));
4403 end if;
4404 end if;
4405
4406 return N;
4407 end Acc_First;
4408
4409 --------------
4410 -- Acc_Next --
4411 --------------
4412
4413 function Acc_Next (N : Node_Id) return Node_Id is
4414 begin
4415 if Nkind (Parent (N)) = N_Component_Association then
4416 return Expression (Next (Parent (N)));
4417
4418 elsif Nkind (Parent (N)) = N_Aggregate then
4419 return Next (N);
4420
4421 else
4422 return Empty;
4423 end if;
4424 end Acc_Next;
4425
4426 ---------------------
4427 -- Ada_2005_Pragma --
4428 ---------------------
4429
4430 procedure Ada_2005_Pragma is
4431 begin
4432 if Ada_Version <= Ada_95 then
4433 Check_Restriction (No_Implementation_Pragmas, N);
4434 end if;
4435 end Ada_2005_Pragma;
4436
4437 ---------------------
4438 -- Ada_2012_Pragma --
4439 ---------------------
4440
4441 procedure Ada_2012_Pragma is
4442 begin
4443 if Ada_Version <= Ada_2005 then
4444 Check_Restriction (No_Implementation_Pragmas, N);
4445 end if;
4446 end Ada_2012_Pragma;
4447
4448 ----------------------------
4449 -- Analyze_Depends_Global --
4450 ----------------------------
4451
4452 procedure Analyze_Depends_Global
4453 (Spec_Id : out Entity_Id;
4454 Subp_Decl : out Node_Id;
4455 Legal : out Boolean)
4456 is
4457 begin
4458 -- Assume that the pragma is illegal
4459
4460 Spec_Id := Empty;
4461 Subp_Decl := Empty;
4462 Legal := False;
4463
4464 GNAT_Pragma;
4465 Check_Arg_Count (1);
4466
4467 -- Ensure the proper placement of the pragma. Depends/Global must be
4468 -- associated with a subprogram declaration or a body that acts as a
4469 -- spec.
4470
4471 Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4472
4473 -- Entry
4474
4475 if Nkind (Subp_Decl) = N_Entry_Declaration then
4476 null;
4477
4478 -- Generic subprogram
4479
4480 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4481 null;
4482
4483 -- Object declaration of a single concurrent type
4484
4485 elsif Nkind (Subp_Decl) = N_Object_Declaration
4486 and then Is_Single_Concurrent_Object
4487 (Unique_Defining_Entity (Subp_Decl))
4488 then
4489 null;
4490
4491 -- Single task type
4492
4493 elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then
4494 null;
4495
4496 -- Subprogram body acts as spec
4497
4498 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4499 and then No (Corresponding_Spec (Subp_Decl))
4500 then
4501 null;
4502
4503 -- Subprogram body stub acts as spec
4504
4505 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4506 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
4507 then
4508 null;
4509
4510 -- Subprogram declaration
4511
4512 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4513 null;
4514
4515 -- Task type
4516
4517 elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then
4518 null;
4519
4520 else
4521 Pragma_Misplaced;
4522 return;
4523 end if;
4524
4525 -- If we get here, then the pragma is legal
4526
4527 Legal := True;
4528 Spec_Id := Unique_Defining_Entity (Subp_Decl);
4529
4530 -- When the related context is an entry, the entry must belong to a
4531 -- protected unit (SPARK RM 6.1.4(6)).
4532
4533 if Is_Entry_Declaration (Spec_Id)
4534 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
4535 then
4536 Pragma_Misplaced;
4537 return;
4538
4539 -- When the related context is an anonymous object created for a
4540 -- simple concurrent type, the type must be a task
4541 -- (SPARK RM 6.1.4(6)).
4542
4543 elsif Is_Single_Concurrent_Object (Spec_Id)
4544 and then Ekind (Etype (Spec_Id)) /= E_Task_Type
4545 then
4546 Pragma_Misplaced;
4547 return;
4548 end if;
4549
4550 -- A pragma that applies to a Ghost entity becomes Ghost for the
4551 -- purposes of legality checks and removal of ignored Ghost code.
4552
4553 Mark_Ghost_Pragma (N, Spec_Id);
4554 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4555 end Analyze_Depends_Global;
4556
4557 ------------------------
4558 -- Analyze_If_Present --
4559 ------------------------
4560
4561 procedure Analyze_If_Present (Id : Pragma_Id) is
4562 Stmt : Node_Id;
4563
4564 begin
4565 pragma Assert (Is_List_Member (N));
4566
4567 -- Inspect the declarations or statements following pragma N looking
4568 -- for another pragma whose Id matches the caller's request. If it is
4569 -- available, analyze it.
4570
4571 Stmt := Next (N);
4572 while Present (Stmt) loop
4573 if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then
4574 Analyze_Pragma (Stmt);
4575 exit;
4576
4577 -- The first source declaration or statement immediately following
4578 -- N ends the region where a pragma may appear.
4579
4580 elsif Comes_From_Source (Stmt) then
4581 exit;
4582 end if;
4583
4584 Next (Stmt);
4585 end loop;
4586 end Analyze_If_Present;
4587
4588 --------------------------------
4589 -- Analyze_Pre_Post_Condition --
4590 --------------------------------
4591
4592 procedure Analyze_Pre_Post_Condition is
4593 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
4594 Subp_Decl : Node_Id;
4595 Subp_Id : Entity_Id;
4596
4597 Duplicates_OK : Boolean := False;
4598 -- Flag set when a pre/postcondition allows multiple pragmas of the
4599 -- same kind.
4600
4601 In_Body_OK : Boolean := False;
4602 -- Flag set when a pre/postcondition is allowed to appear on a body
4603 -- even though the subprogram may have a spec.
4604
4605 Is_Pre_Post : Boolean := False;
4606 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4607 -- Post_Class.
4608
4609 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean;
4610 -- Implement rules in AI12-0131: an overriding operation can have
4611 -- a class-wide precondition only if one of its ancestors has an
4612 -- explicit class-wide precondition.
4613
4614 -----------------------------
4615 -- Inherits_Class_Wide_Pre --
4616 -----------------------------
4617
4618 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean is
4619 Typ : constant Entity_Id := Find_Dispatching_Type (E);
4620 Cont : Node_Id;
4621 Prag : Node_Id;
4622 Prev : Entity_Id := Overridden_Operation (E);
4623
4624 begin
4625 -- Check ancestors on the overriding operation to examine the
4626 -- preconditions that may apply to them.
4627
4628 while Present (Prev) loop
4629 Cont := Contract (Prev);
4630 if Present (Cont) then
4631 Prag := Pre_Post_Conditions (Cont);
4632 while Present (Prag) loop
4633 if Pragma_Name (Prag) = Name_Precondition
4634 and then Class_Present (Prag)
4635 then
4636 return True;
4637 end if;
4638
4639 Prag := Next_Pragma (Prag);
4640 end loop;
4641 end if;
4642
4643 -- For a type derived from a generic formal type, the operation
4644 -- inheriting the condition is a renaming, not an overriding of
4645 -- the operation of the formal. Ditto for an inherited
4646 -- operation which has no explicit contracts.
4647
4648 if Is_Generic_Type (Find_Dispatching_Type (Prev))
4649 or else not Comes_From_Source (Prev)
4650 then
4651 Prev := Alias (Prev);
4652 else
4653 Prev := Overridden_Operation (Prev);
4654 end if;
4655 end loop;
4656
4657 -- If the controlling type of the subprogram has progenitors, an
4658 -- interface operation implemented by the current operation may
4659 -- have a class-wide precondition.
4660
4661 if Has_Interfaces (Typ) then
4662 declare
4663 Elmt : Elmt_Id;
4664 Ints : Elist_Id;
4665 Prim : Entity_Id;
4666 Prim_Elmt : Elmt_Id;
4667 Prim_List : Elist_Id;
4668
4669 begin
4670 Collect_Interfaces (Typ, Ints);
4671 Elmt := First_Elmt (Ints);
4672
4673 -- Iterate over the primitive operations of each interface
4674
4675 while Present (Elmt) loop
4676 Prim_List := Direct_Primitive_Operations (Node (Elmt));
4677 Prim_Elmt := First_Elmt (Prim_List);
4678 while Present (Prim_Elmt) loop
4679 Prim := Node (Prim_Elmt);
4680 if Chars (Prim) = Chars (E)
4681 and then Present (Contract (Prim))
4682 and then Class_Present
4683 (Pre_Post_Conditions (Contract (Prim)))
4684 then
4685 return True;
4686 end if;
4687
4688 Next_Elmt (Prim_Elmt);
4689 end loop;
4690
4691 Next_Elmt (Elmt);
4692 end loop;
4693 end;
4694 end if;
4695
4696 return False;
4697 end Inherits_Class_Wide_Pre;
4698
4699 -- Start of processing for Analyze_Pre_Post_Condition
4700
4701 begin
4702 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4703 -- offer uniformity among the various kinds of pre/postconditions by
4704 -- rewriting the pragma identifier. This allows the retrieval of the
4705 -- original pragma name by routine Original_Aspect_Pragma_Name.
4706
4707 if Comes_From_Source (N) then
4708 if Nam_In (Pname, Name_Pre, Name_Pre_Class) then
4709 Is_Pre_Post := True;
4710 Set_Class_Present (N, Pname = Name_Pre_Class);
4711 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
4712
4713 elsif Nam_In (Pname, Name_Post, Name_Post_Class) then
4714 Is_Pre_Post := True;
4715 Set_Class_Present (N, Pname = Name_Post_Class);
4716 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
4717 end if;
4718 end if;
4719
4720 -- Determine the semantics with respect to duplicates and placement
4721 -- in a body. Pragmas Precondition and Postcondition were introduced
4722 -- before aspects and are not subject to the same aspect-like rules.
4723
4724 if Nam_In (Pname, Name_Precondition, Name_Postcondition) then
4725 Duplicates_OK := True;
4726 In_Body_OK := True;
4727 end if;
4728
4729 GNAT_Pragma;
4730
4731 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4732 -- argument without an identifier.
4733
4734 if Is_Pre_Post then
4735 Check_Arg_Count (1);
4736 Check_No_Identifiers;
4737
4738 -- Pragmas Precondition and Postcondition have complex argument
4739 -- profile.
4740
4741 else
4742 Check_At_Least_N_Arguments (1);
4743 Check_At_Most_N_Arguments (2);
4744 Check_Optional_Identifier (Arg1, Name_Check);
4745
4746 if Present (Arg2) then
4747 Check_Optional_Identifier (Arg2, Name_Message);
4748 Preanalyze_Spec_Expression
4749 (Get_Pragma_Arg (Arg2), Standard_String);
4750 end if;
4751 end if;
4752
4753 -- For a pragma PPC in the extended main source unit, record enabled
4754 -- status in SCO.
4755 -- ??? nothing checks that the pragma is in the main source unit
4756
4757 if Is_Checked (N) and then not Split_PPC (N) then
4758 Set_SCO_Pragma_Enabled (Loc);
4759 end if;
4760
4761 -- Ensure the proper placement of the pragma
4762
4763 Subp_Decl :=
4764 Find_Related_Declaration_Or_Body
4765 (N, Do_Checks => not Duplicates_OK);
4766
4767 -- When a pre/postcondition pragma applies to an abstract subprogram,
4768 -- its original form must be an aspect with 'Class.
4769
4770 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4771 if not From_Aspect_Specification (N) then
4772 Error_Pragma
4773 ("pragma % cannot be applied to abstract subprogram");
4774
4775 elsif not Class_Present (N) then
4776 Error_Pragma
4777 ("aspect % requires ''Class for abstract subprogram");
4778 end if;
4779
4780 -- Entry declaration
4781
4782 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
4783 null;
4784
4785 -- Generic subprogram declaration
4786
4787 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4788 null;
4789
4790 -- Subprogram body
4791
4792 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4793 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
4794 then
4795 null;
4796
4797 -- Subprogram body stub
4798
4799 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4800 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
4801 then
4802 null;
4803
4804 -- Subprogram declaration
4805
4806 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4807
4808 -- AI05-0230: When a pre/postcondition pragma applies to a null
4809 -- procedure, its original form must be an aspect with 'Class.
4810
4811 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4812 and then Null_Present (Specification (Subp_Decl))
4813 and then From_Aspect_Specification (N)
4814 and then not Class_Present (N)
4815 then
4816 Error_Pragma ("aspect % requires ''Class for null procedure");
4817 end if;
4818
4819 -- Implement the legality checks mandated by AI12-0131:
4820 -- Pre'Class shall not be specified for an overriding primitive
4821 -- subprogram of a tagged type T unless the Pre'Class aspect is
4822 -- specified for the corresponding primitive subprogram of some
4823 -- ancestor of T.
4824
4825 declare
4826 E : constant Entity_Id := Defining_Entity (Subp_Decl);
4827
4828 begin
4829 if Class_Present (N)
4830 and then Pragma_Name (N) = Name_Precondition
4831 and then Present (Overridden_Operation (E))
4832 and then not Inherits_Class_Wide_Pre (E)
4833 then
4834 Error_Msg_N
4835 ("illegal class-wide precondition on overriding operation",
4836 Corresponding_Aspect (N));
4837 end if;
4838 end;
4839
4840 -- A renaming declaration may inherit a generated pragma, its
4841 -- placement comes from expansion, not from source.
4842
4843 elsif Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
4844 and then not Comes_From_Source (N)
4845 then
4846 null;
4847
4848 -- Otherwise the placement is illegal
4849
4850 else
4851 Pragma_Misplaced;
4852 return;
4853 end if;
4854
4855 Subp_Id := Defining_Entity (Subp_Decl);
4856
4857 -- A pragma that applies to a Ghost entity becomes Ghost for the
4858 -- purposes of legality checks and removal of ignored Ghost code.
4859
4860 Mark_Ghost_Pragma (N, Subp_Id);
4861
4862 -- Chain the pragma on the contract for further processing by
4863 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4864
4865 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
4866
4867 -- Fully analyze the pragma when it appears inside an entry or
4868 -- subprogram body because it cannot benefit from forward references.
4869
4870 if Nkind_In (Subp_Decl, N_Entry_Body,
4871 N_Subprogram_Body,
4872 N_Subprogram_Body_Stub)
4873 then
4874 -- The legality checks of pragmas Precondition and Postcondition
4875 -- are affected by the SPARK mode in effect and the volatility of
4876 -- the context. Analyze all pragmas in a specific order.
4877
4878 Analyze_If_Present (Pragma_SPARK_Mode);
4879 Analyze_If_Present (Pragma_Volatile_Function);
4880 Analyze_Pre_Post_Condition_In_Decl_Part (N);
4881 end if;
4882 end Analyze_Pre_Post_Condition;
4883
4884 -----------------------------------------
4885 -- Analyze_Refined_Depends_Global_Post --
4886 -----------------------------------------
4887
4888 procedure Analyze_Refined_Depends_Global_Post
4889 (Spec_Id : out Entity_Id;
4890 Body_Id : out Entity_Id;
4891 Legal : out Boolean)
4892 is
4893 Body_Decl : Node_Id;
4894 Spec_Decl : Node_Id;
4895
4896 begin
4897 -- Assume that the pragma is illegal
4898
4899 Spec_Id := Empty;
4900 Body_Id := Empty;
4901 Legal := False;
4902
4903 GNAT_Pragma;
4904 Check_Arg_Count (1);
4905 Check_No_Identifiers;
4906
4907 -- Verify the placement of the pragma and check for duplicates. The
4908 -- pragma must apply to a subprogram body [stub].
4909
4910 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4911
4912 if not Nkind_In (Body_Decl, N_Entry_Body,
4913 N_Subprogram_Body,
4914 N_Subprogram_Body_Stub,
4915 N_Task_Body,
4916 N_Task_Body_Stub)
4917 then
4918 Pragma_Misplaced;
4919 return;
4920 end if;
4921
4922 Body_Id := Defining_Entity (Body_Decl);
4923 Spec_Id := Unique_Defining_Entity (Body_Decl);
4924
4925 -- The pragma must apply to the second declaration of a subprogram.
4926 -- In other words, the body [stub] cannot acts as a spec.
4927
4928 if No (Spec_Id) then
4929 Error_Pragma ("pragma % cannot apply to a stand alone body");
4930 return;
4931
4932 -- Catch the case where the subprogram body is a subunit and acts as
4933 -- the third declaration of the subprogram.
4934
4935 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
4936 Error_Pragma ("pragma % cannot apply to a subunit");
4937 return;
4938 end if;
4939
4940 -- A refined pragma can only apply to the body [stub] of a subprogram
4941 -- declared in the visible part of a package. Retrieve the context of
4942 -- the subprogram declaration.
4943
4944 Spec_Decl := Unit_Declaration_Node (Spec_Id);
4945
4946 -- When dealing with protected entries or protected subprograms, use
4947 -- the enclosing protected type as the proper context.
4948
4949 if Ekind_In (Spec_Id, E_Entry,
4950 E_Entry_Family,
4951 E_Function,
4952 E_Procedure)
4953 and then Ekind (Scope (Spec_Id)) = E_Protected_Type
4954 then
4955 Spec_Decl := Declaration_Node (Scope (Spec_Id));
4956 end if;
4957
4958 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
4959 Error_Pragma
4960 (Fix_Msg (Spec_Id, "pragma % must apply to the body of "
4961 & "subprogram declared in a package specification"));
4962 return;
4963 end if;
4964
4965 -- If we get here, then the pragma is legal
4966
4967 Legal := True;
4968
4969 -- A pragma that applies to a Ghost entity becomes Ghost for the
4970 -- purposes of legality checks and removal of ignored Ghost code.
4971
4972 Mark_Ghost_Pragma (N, Spec_Id);
4973
4974 if Nam_In (Pname, Name_Refined_Depends, Name_Refined_Global) then
4975 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4976 end if;
4977 end Analyze_Refined_Depends_Global_Post;
4978
4979 ----------------------------------
4980 -- Analyze_Unmodified_Or_Unused --
4981 ----------------------------------
4982
4983 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False) is
4984 Arg : Node_Id;
4985 Arg_Expr : Node_Id;
4986 Arg_Id : Entity_Id;
4987
4988 Ghost_Error_Posted : Boolean := False;
4989 -- Flag set when an error concerning the illegal mix of Ghost and
4990 -- non-Ghost variables is emitted.
4991
4992 Ghost_Id : Entity_Id := Empty;
4993 -- The entity of the first Ghost variable encountered while
4994 -- processing the arguments of the pragma.
4995
4996 begin
4997 GNAT_Pragma;
4998 Check_At_Least_N_Arguments (1);
4999
5000 -- Loop through arguments
5001
5002 Arg := Arg1;
5003 while Present (Arg) loop
5004 Check_No_Identifier (Arg);
5005
5006 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
5007 -- in fact generate reference, so that the entity will have a
5008 -- reference, which will inhibit any warnings about it not
5009 -- being referenced, and also properly show up in the ali file
5010 -- as a reference. But this reference is recorded before the
5011 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5012 -- generated for this reference.
5013
5014 Check_Arg_Is_Local_Name (Arg);
5015 Arg_Expr := Get_Pragma_Arg (Arg);
5016
5017 if Is_Entity_Name (Arg_Expr) then
5018 Arg_Id := Entity (Arg_Expr);
5019
5020 -- Skip processing the argument if already flagged
5021
5022 if Is_Assignable (Arg_Id)
5023 and then not Has_Pragma_Unmodified (Arg_Id)
5024 and then not Has_Pragma_Unused (Arg_Id)
5025 then
5026 Set_Has_Pragma_Unmodified (Arg_Id);
5027
5028 if Is_Unused then
5029 Set_Has_Pragma_Unused (Arg_Id);
5030 end if;
5031
5032 -- A pragma that applies to a Ghost entity becomes Ghost for
5033 -- the purposes of legality checks and removal of ignored
5034 -- Ghost code.
5035
5036 Mark_Ghost_Pragma (N, Arg_Id);
5037
5038 -- Capture the entity of the first Ghost variable being
5039 -- processed for error detection purposes.
5040
5041 if Is_Ghost_Entity (Arg_Id) then
5042 if No (Ghost_Id) then
5043 Ghost_Id := Arg_Id;
5044 end if;
5045
5046 -- Otherwise the variable is non-Ghost. It is illegal to mix
5047 -- references to Ghost and non-Ghost entities
5048 -- (SPARK RM 6.9).
5049
5050 elsif Present (Ghost_Id)
5051 and then not Ghost_Error_Posted
5052 then
5053 Ghost_Error_Posted := True;
5054
5055 Error_Msg_Name_1 := Pname;
5056 Error_Msg_N
5057 ("pragma % cannot mention ghost and non-ghost "
5058 & "variables", N);
5059
5060 Error_Msg_Sloc := Sloc (Ghost_Id);
5061 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
5062
5063 Error_Msg_Sloc := Sloc (Arg_Id);
5064 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
5065 end if;
5066
5067 -- Warn if already flagged as Unused or Unmodified
5068
5069 elsif Has_Pragma_Unmodified (Arg_Id) then
5070 if Has_Pragma_Unused (Arg_Id) then
5071 Error_Msg_NE
5072 ("??pragma Unused already given for &!", Arg_Expr,
5073 Arg_Id);
5074 else
5075 Error_Msg_NE
5076 ("??pragma Unmodified already given for &!", Arg_Expr,
5077 Arg_Id);
5078 end if;
5079
5080 -- Otherwise the pragma referenced an illegal entity
5081
5082 else
5083 Error_Pragma_Arg
5084 ("pragma% can only be applied to a variable", Arg_Expr);
5085 end if;
5086 end if;
5087
5088 Next (Arg);
5089 end loop;
5090 end Analyze_Unmodified_Or_Unused;
5091
5092 ------------------------------------
5093 -- Analyze_Unreferenced_Or_Unused --
5094 ------------------------------------
5095
5096 procedure Analyze_Unreferenced_Or_Unused
5097 (Is_Unused : Boolean := False)
5098 is
5099 Arg : Node_Id;
5100 Arg_Expr : Node_Id;
5101 Arg_Id : Entity_Id;
5102 Citem : Node_Id;
5103
5104 Ghost_Error_Posted : Boolean := False;
5105 -- Flag set when an error concerning the illegal mix of Ghost and
5106 -- non-Ghost names is emitted.
5107
5108 Ghost_Id : Entity_Id := Empty;
5109 -- The entity of the first Ghost name encountered while processing
5110 -- the arguments of the pragma.
5111
5112 begin
5113 GNAT_Pragma;
5114 Check_At_Least_N_Arguments (1);
5115
5116 -- Check case of appearing within context clause
5117
5118 if not Is_Unused and then Is_In_Context_Clause then
5119
5120 -- The arguments must all be units mentioned in a with clause in
5121 -- the same context clause. Note that Par.Prag already checked
5122 -- that the arguments are either identifiers or selected
5123 -- components.
5124
5125 Arg := Arg1;
5126 while Present (Arg) loop
5127 Citem := First (List_Containing (N));
5128 while Citem /= N loop
5129 Arg_Expr := Get_Pragma_Arg (Arg);
5130
5131 if Nkind (Citem) = N_With_Clause
5132 and then Same_Name (Name (Citem), Arg_Expr)
5133 then
5134 Set_Has_Pragma_Unreferenced
5135 (Cunit_Entity
5136 (Get_Source_Unit
5137 (Library_Unit (Citem))));
5138 Set_Elab_Unit_Name (Arg_Expr, Name (Citem));
5139 exit;
5140 end if;
5141
5142 Next (Citem);
5143 end loop;
5144
5145 if Citem = N then
5146 Error_Pragma_Arg
5147 ("argument of pragma% is not withed unit", Arg);
5148 end if;
5149
5150 Next (Arg);
5151 end loop;
5152
5153 -- Case of not in list of context items
5154
5155 else
5156 Arg := Arg1;
5157 while Present (Arg) loop
5158 Check_No_Identifier (Arg);
5159
5160 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
5161 -- in fact generate reference, so that the entity will have a
5162 -- reference, which will inhibit any warnings about it not
5163 -- being referenced, and also properly show up in the ali file
5164 -- as a reference. But this reference is recorded before the
5165 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5166 -- generated for this reference.
5167
5168 Check_Arg_Is_Local_Name (Arg);
5169 Arg_Expr := Get_Pragma_Arg (Arg);
5170
5171 if Is_Entity_Name (Arg_Expr) then
5172 Arg_Id := Entity (Arg_Expr);
5173
5174 -- Warn if already flagged as Unused or Unreferenced and
5175 -- skip processing the argument.
5176
5177 if Has_Pragma_Unreferenced (Arg_Id) then
5178 if Has_Pragma_Unused (Arg_Id) then
5179 Error_Msg_NE
5180 ("??pragma Unused already given for &!", Arg_Expr,
5181 Arg_Id);
5182 else
5183 Error_Msg_NE
5184 ("??pragma Unreferenced already given for &!",
5185 Arg_Expr, Arg_Id);
5186 end if;
5187
5188 -- Apply Unreferenced to the entity
5189
5190 else
5191 -- If the entity is overloaded, the pragma applies to the
5192 -- most recent overloading, as documented. In this case,
5193 -- name resolution does not generate a reference, so it
5194 -- must be done here explicitly.
5195
5196 if Is_Overloaded (Arg_Expr) then
5197 Generate_Reference (Arg_Id, N);
5198 end if;
5199
5200 Set_Has_Pragma_Unreferenced (Arg_Id);
5201
5202 if Is_Unused then
5203 Set_Has_Pragma_Unused (Arg_Id);
5204 end if;
5205
5206 -- A pragma that applies to a Ghost entity becomes Ghost
5207 -- for the purposes of legality checks and removal of
5208 -- ignored Ghost code.
5209
5210 Mark_Ghost_Pragma (N, Arg_Id);
5211
5212 -- Capture the entity of the first Ghost name being
5213 -- processed for error detection purposes.
5214
5215 if Is_Ghost_Entity (Arg_Id) then
5216 if No (Ghost_Id) then
5217 Ghost_Id := Arg_Id;
5218 end if;
5219
5220 -- Otherwise the name is non-Ghost. It is illegal to mix
5221 -- references to Ghost and non-Ghost entities
5222 -- (SPARK RM 6.9).
5223
5224 elsif Present (Ghost_Id)
5225 and then not Ghost_Error_Posted
5226 then
5227 Ghost_Error_Posted := True;
5228
5229 Error_Msg_Name_1 := Pname;
5230 Error_Msg_N
5231 ("pragma % cannot mention ghost and non-ghost "
5232 & "names", N);
5233
5234 Error_Msg_Sloc := Sloc (Ghost_Id);
5235 Error_Msg_NE
5236 ("\& # declared as ghost", N, Ghost_Id);
5237
5238 Error_Msg_Sloc := Sloc (Arg_Id);
5239 Error_Msg_NE
5240 ("\& # declared as non-ghost", N, Arg_Id);
5241 end if;
5242 end if;
5243 end if;
5244
5245 Next (Arg);
5246 end loop;
5247 end if;
5248 end Analyze_Unreferenced_Or_Unused;
5249
5250 --------------------------
5251 -- Check_Ada_83_Warning --
5252 --------------------------
5253
5254 procedure Check_Ada_83_Warning is
5255 begin
5256 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5257 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
5258 end if;
5259 end Check_Ada_83_Warning;
5260
5261 ---------------------
5262 -- Check_Arg_Count --
5263 ---------------------
5264
5265 procedure Check_Arg_Count (Required : Nat) is
5266 begin
5267 if Arg_Count /= Required then
5268 Error_Pragma ("wrong number of arguments for pragma%");
5269 end if;
5270 end Check_Arg_Count;
5271
5272 --------------------------------
5273 -- Check_Arg_Is_External_Name --
5274 --------------------------------
5275
5276 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
5277 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5278
5279 begin
5280 if Nkind (Argx) = N_Identifier then
5281 return;
5282
5283 else
5284 Analyze_And_Resolve (Argx, Standard_String);
5285
5286 if Is_OK_Static_Expression (Argx) then
5287 return;
5288
5289 elsif Etype (Argx) = Any_Type then
5290 raise Pragma_Exit;
5291
5292 -- An interesting special case, if we have a string literal and
5293 -- we are in Ada 83 mode, then we allow it even though it will
5294 -- not be flagged as static. This allows expected Ada 83 mode
5295 -- use of external names which are string literals, even though
5296 -- technically these are not static in Ada 83.
5297
5298 elsif Ada_Version = Ada_83
5299 and then Nkind (Argx) = N_String_Literal
5300 then
5301 return;
5302
5303 -- Here we have a real error (non-static expression)
5304
5305 else
5306 Error_Msg_Name_1 := Pname;
5307 Flag_Non_Static_Expr
5308 (Fix_Error ("argument for pragma% must be a identifier or "
5309 & "static string expression!"), Argx);
5310
5311 raise Pragma_Exit;
5312 end if;
5313 end if;
5314 end Check_Arg_Is_External_Name;
5315
5316 -----------------------------
5317 -- Check_Arg_Is_Identifier --
5318 -----------------------------
5319
5320 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
5321 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5322 begin
5323 if Nkind (Argx) /= N_Identifier then
5324 Error_Pragma_Arg ("argument for pragma% must be identifier", Argx);
5325 end if;
5326 end Check_Arg_Is_Identifier;
5327
5328 ----------------------------------
5329 -- Check_Arg_Is_Integer_Literal --
5330 ----------------------------------
5331
5332 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
5333 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5334 begin
5335 if Nkind (Argx) /= N_Integer_Literal then
5336 Error_Pragma_Arg
5337 ("argument for pragma% must be integer literal", Argx);
5338 end if;
5339 end Check_Arg_Is_Integer_Literal;
5340
5341 -------------------------------------------
5342 -- Check_Arg_Is_Library_Level_Local_Name --
5343 -------------------------------------------
5344
5345 -- LOCAL_NAME ::=
5346 -- DIRECT_NAME
5347 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5348 -- | library_unit_NAME
5349
5350 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
5351 begin
5352 Check_Arg_Is_Local_Name (Arg);
5353
5354 -- If it came from an aspect, we want to give the error just as if it
5355 -- came from source.
5356
5357 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
5358 and then (Comes_From_Source (N)
5359 or else Present (Corresponding_Aspect (Parent (Arg))))
5360 then
5361 Error_Pragma_Arg
5362 ("argument for pragma% must be library level entity", Arg);
5363 end if;
5364 end Check_Arg_Is_Library_Level_Local_Name;
5365
5366 -----------------------------
5367 -- Check_Arg_Is_Local_Name --
5368 -----------------------------
5369
5370 -- LOCAL_NAME ::=
5371 -- DIRECT_NAME
5372 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5373 -- | library_unit_NAME
5374
5375 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
5376 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5377
5378 begin
5379 -- If this pragma came from an aspect specification, we don't want to
5380 -- check for this error, because that would cause spurious errors, in
5381 -- case a type is frozen in a scope more nested than the type. The
5382 -- aspect itself of course can't be anywhere but on the declaration
5383 -- itself.
5384
5385 if Nkind (Arg) = N_Pragma_Argument_Association then
5386 if From_Aspect_Specification (Parent (Arg)) then
5387 return;
5388 end if;
5389
5390 -- Arg is the Expression of an N_Pragma_Argument_Association
5391
5392 else
5393 if From_Aspect_Specification (Parent (Parent (Arg))) then
5394 return;
5395 end if;
5396 end if;
5397
5398 Analyze (Argx);
5399
5400 if Nkind (Argx) not in N_Direct_Name
5401 and then (Nkind (Argx) /= N_Attribute_Reference
5402 or else Present (Expressions (Argx))
5403 or else Nkind (Prefix (Argx)) /= N_Identifier)
5404 and then (not Is_Entity_Name (Argx)
5405 or else not Is_Compilation_Unit (Entity (Argx)))
5406 then
5407 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
5408 end if;
5409
5410 -- No further check required if not an entity name
5411
5412 if not Is_Entity_Name (Argx) then
5413 null;
5414
5415 else
5416 declare
5417 OK : Boolean;
5418 Ent : constant Entity_Id := Entity (Argx);
5419 Scop : constant Entity_Id := Scope (Ent);
5420
5421 begin
5422 -- Case of a pragma applied to a compilation unit: pragma must
5423 -- occur immediately after the program unit in the compilation.
5424
5425 if Is_Compilation_Unit (Ent) then
5426 declare
5427 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
5428
5429 begin
5430 -- Case of pragma placed immediately after spec
5431
5432 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
5433 OK := True;
5434
5435 -- Case of pragma placed immediately after body
5436
5437 elsif Nkind (Decl) = N_Subprogram_Declaration
5438 and then Present (Corresponding_Body (Decl))
5439 then
5440 OK := Parent (N) =
5441 Aux_Decls_Node
5442 (Parent (Unit_Declaration_Node
5443 (Corresponding_Body (Decl))));
5444
5445 -- All other cases are illegal
5446
5447 else
5448 OK := False;
5449 end if;
5450 end;
5451
5452 -- Special restricted placement rule from 10.2.1(11.8/2)
5453
5454 elsif Is_Generic_Formal (Ent)
5455 and then Prag_Id = Pragma_Preelaborable_Initialization
5456 then
5457 OK := List_Containing (N) =
5458 Generic_Formal_Declarations
5459 (Unit_Declaration_Node (Scop));
5460
5461 -- If this is an aspect applied to a subprogram body, the
5462 -- pragma is inserted in its declarative part.
5463
5464 elsif From_Aspect_Specification (N)
5465 and then Ent = Current_Scope
5466 and then
5467 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
5468 then
5469 OK := True;
5470
5471 -- If the aspect is a predicate (possibly others ???) and the
5472 -- context is a record type, this is a discriminant expression
5473 -- within a type declaration, that freezes the predicated
5474 -- subtype.
5475
5476 elsif From_Aspect_Specification (N)
5477 and then Prag_Id = Pragma_Predicate
5478 and then Ekind (Current_Scope) = E_Record_Type
5479 and then Scop = Scope (Current_Scope)
5480 then
5481 OK := True;
5482
5483 -- Default case, just check that the pragma occurs in the scope
5484 -- of the entity denoted by the name.
5485
5486 else
5487 OK := Current_Scope = Scop;
5488 end if;
5489
5490 if not OK then
5491 Error_Pragma_Arg
5492 ("pragma% argument must be in same declarative part", Arg);
5493 end if;
5494 end;
5495 end if;
5496 end Check_Arg_Is_Local_Name;
5497
5498 ---------------------------------
5499 -- Check_Arg_Is_Locking_Policy --
5500 ---------------------------------
5501
5502 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
5503 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5504
5505 begin
5506 Check_Arg_Is_Identifier (Argx);
5507
5508 if not Is_Locking_Policy_Name (Chars (Argx)) then
5509 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
5510 end if;
5511 end Check_Arg_Is_Locking_Policy;
5512
5513 -----------------------------------------------
5514 -- Check_Arg_Is_Partition_Elaboration_Policy --
5515 -----------------------------------------------
5516
5517 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
5518 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5519
5520 begin
5521 Check_Arg_Is_Identifier (Argx);
5522
5523 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
5524 Error_Pragma_Arg
5525 ("& is not a valid partition elaboration policy name", Argx);
5526 end if;
5527 end Check_Arg_Is_Partition_Elaboration_Policy;
5528
5529 -------------------------
5530 -- Check_Arg_Is_One_Of --
5531 -------------------------
5532
5533 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5534 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5535
5536 begin
5537 Check_Arg_Is_Identifier (Argx);
5538
5539 if not Nam_In (Chars (Argx), N1, N2) then
5540 Error_Msg_Name_2 := N1;
5541 Error_Msg_Name_3 := N2;
5542 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
5543 end if;
5544 end Check_Arg_Is_One_Of;
5545
5546 procedure Check_Arg_Is_One_Of
5547 (Arg : Node_Id;
5548 N1, N2, N3 : Name_Id)
5549 is
5550 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5551
5552 begin
5553 Check_Arg_Is_Identifier (Argx);
5554
5555 if not Nam_In (Chars (Argx), N1, N2, N3) then
5556 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5557 end if;
5558 end Check_Arg_Is_One_Of;
5559
5560 procedure Check_Arg_Is_One_Of
5561 (Arg : Node_Id;
5562 N1, N2, N3, N4 : Name_Id)
5563 is
5564 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5565
5566 begin
5567 Check_Arg_Is_Identifier (Argx);
5568
5569 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
5570 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5571 end if;
5572 end Check_Arg_Is_One_Of;
5573
5574 procedure Check_Arg_Is_One_Of
5575 (Arg : Node_Id;
5576 N1, N2, N3, N4, N5 : Name_Id)
5577 is
5578 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5579
5580 begin
5581 Check_Arg_Is_Identifier (Argx);
5582
5583 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
5584 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5585 end if;
5586 end Check_Arg_Is_One_Of;
5587
5588 ---------------------------------
5589 -- Check_Arg_Is_Queuing_Policy --
5590 ---------------------------------
5591
5592 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
5593 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5594
5595 begin
5596 Check_Arg_Is_Identifier (Argx);
5597
5598 if not Is_Queuing_Policy_Name (Chars (Argx)) then
5599 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
5600 end if;
5601 end Check_Arg_Is_Queuing_Policy;
5602
5603 ---------------------------------------
5604 -- Check_Arg_Is_OK_Static_Expression --
5605 ---------------------------------------
5606
5607 procedure Check_Arg_Is_OK_Static_Expression
5608 (Arg : Node_Id;
5609 Typ : Entity_Id := Empty)
5610 is
5611 begin
5612 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
5613 end Check_Arg_Is_OK_Static_Expression;
5614
5615 ------------------------------------------
5616 -- Check_Arg_Is_Task_Dispatching_Policy --
5617 ------------------------------------------
5618
5619 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
5620 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5621
5622 begin
5623 Check_Arg_Is_Identifier (Argx);
5624
5625 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
5626 Error_Pragma_Arg
5627 ("& is not an allowed task dispatching policy name", Argx);
5628 end if;
5629 end Check_Arg_Is_Task_Dispatching_Policy;
5630
5631 ---------------------
5632 -- Check_Arg_Order --
5633 ---------------------
5634
5635 procedure Check_Arg_Order (Names : Name_List) is
5636 Arg : Node_Id;
5637
5638 Highest_So_Far : Natural := 0;
5639 -- Highest index in Names seen do far
5640
5641 begin
5642 Arg := Arg1;
5643 for J in 1 .. Arg_Count loop
5644 if Chars (Arg) /= No_Name then
5645 for K in Names'Range loop
5646 if Chars (Arg) = Names (K) then
5647 if K < Highest_So_Far then
5648 Error_Msg_Name_1 := Pname;
5649 Error_Msg_N
5650 ("parameters out of order for pragma%", Arg);
5651 Error_Msg_Name_1 := Names (K);
5652 Error_Msg_Name_2 := Names (Highest_So_Far);
5653 Error_Msg_N ("\% must appear before %", Arg);
5654 raise Pragma_Exit;
5655
5656 else
5657 Highest_So_Far := K;
5658 end if;
5659 end if;
5660 end loop;
5661 end if;
5662
5663 Arg := Next (Arg);
5664 end loop;
5665 end Check_Arg_Order;
5666
5667 --------------------------------
5668 -- Check_At_Least_N_Arguments --
5669 --------------------------------
5670
5671 procedure Check_At_Least_N_Arguments (N : Nat) is
5672 begin
5673 if Arg_Count < N then
5674 Error_Pragma ("too few arguments for pragma%");
5675 end if;
5676 end Check_At_Least_N_Arguments;
5677
5678 -------------------------------
5679 -- Check_At_Most_N_Arguments --
5680 -------------------------------
5681
5682 procedure Check_At_Most_N_Arguments (N : Nat) is
5683 Arg : Node_Id;
5684 begin
5685 if Arg_Count > N then
5686 Arg := Arg1;
5687 for J in 1 .. N loop
5688 Next (Arg);
5689 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
5690 end loop;
5691 end if;
5692 end Check_At_Most_N_Arguments;
5693
5694 ------------------------
5695 -- Check_Atomic_VFA --
5696 ------------------------
5697
5698 procedure Check_Atomic_VFA (E : Entity_Id; VFA : Boolean) is
5699
5700 Aliased_Subcomponent : exception;
5701 -- Exception raised if an aliased subcomponent is found in E
5702
5703 Independent_Subcomponent : exception;
5704 -- Exception raised if an independent subcomponent is found in E
5705
5706 procedure Check_Subcomponents (Typ : Entity_Id);
5707 -- Apply checks to subcomponents for Atomic and Volatile_Full_Access
5708
5709 -------------------------
5710 -- Check_Subcomponents --
5711 -------------------------
5712
5713 procedure Check_Subcomponents (Typ : Entity_Id) is
5714 Comp : Entity_Id;
5715
5716 begin
5717 if Is_Array_Type (Typ) then
5718 Comp := Component_Type (Typ);
5719
5720 -- For Atomic we accept any atomic subcomponents
5721
5722 if not VFA
5723 and then (Has_Atomic_Components (Typ)
5724 or else Is_Atomic (Comp))
5725 then
5726 null;
5727
5728 -- Give an error if the components are aliased
5729
5730 elsif Has_Aliased_Components (Typ)
5731 or else Is_Aliased (Comp)
5732 then
5733 raise Aliased_Subcomponent;
5734
5735 -- For VFA we accept non-aliased VFA subcomponents
5736
5737 elsif VFA
5738 and then Is_Volatile_Full_Access (Comp)
5739 then
5740 null;
5741
5742 -- Give an error if the components are independent
5743
5744 elsif Has_Independent_Components (Typ)
5745 or else Is_Independent (Comp)
5746 then
5747 raise Independent_Subcomponent;
5748 end if;
5749
5750 -- Recurse on the component type
5751
5752 Check_Subcomponents (Comp);
5753
5754 -- Note: Has_Aliased_Components, like Has_Atomic_Components,
5755 -- and Has_Independent_Components, applies only to arrays.
5756 -- However, this flag does not have a corresponding pragma, so
5757 -- perhaps it should be possible to apply it to record types as
5758 -- well. Should this be done ???
5759
5760 elsif Is_Record_Type (Typ) then
5761 -- It is possible to have an aliased discriminant, so they
5762 -- must be checked along with normal components.
5763
5764 Comp := First_Component_Or_Discriminant (Typ);
5765 while Present (Comp) loop
5766
5767 -- For Atomic we accept any atomic subcomponents
5768
5769 if not VFA
5770 and then (Is_Atomic (Comp)
5771 or else Is_Atomic (Etype (Comp)))
5772 then
5773 null;
5774
5775 -- Give an error if the component is aliased
5776
5777 elsif Is_Aliased (Comp)
5778 or else Is_Aliased (Etype (Comp))
5779 then
5780 raise Aliased_Subcomponent;
5781
5782 -- For VFA we accept non-aliased VFA subcomponents
5783
5784 elsif VFA
5785 and then (Is_Volatile_Full_Access (Comp)
5786 or else Is_Volatile_Full_Access (Etype (Comp)))
5787 then
5788 null;
5789
5790 -- Give an error if the component is independent
5791
5792 elsif Is_Independent (Comp)
5793 or else Is_Independent (Etype (Comp))
5794 then
5795 raise Independent_Subcomponent;
5796 end if;
5797
5798 -- Recurse on the component type
5799
5800 Check_Subcomponents (Etype (Comp));
5801
5802 Next_Component_Or_Discriminant (Comp);
5803 end loop;
5804 end if;
5805 end Check_Subcomponents;
5806
5807 Typ : Entity_Id;
5808
5809 begin
5810 -- Fetch the type in case we are dealing with an object or component
5811
5812 if Is_Type (E) then
5813 Typ := E;
5814 else
5815 pragma Assert (Is_Object (E)
5816 or else
5817 Nkind (Declaration_Node (E)) = N_Component_Declaration);
5818
5819 Typ := Etype (E);
5820 end if;
5821
5822 -- Check all the subcomponents of the type recursively, if any
5823
5824 Check_Subcomponents (Typ);
5825
5826 exception
5827 when Aliased_Subcomponent =>
5828 if VFA then
5829 Error_Pragma
5830 ("cannot apply Volatile_Full_Access with aliased "
5831 & "subcomponent ");
5832 else
5833 Error_Pragma
5834 ("cannot apply Atomic with aliased subcomponent "
5835 & "(RM C.6(13))");
5836 end if;
5837
5838 when Independent_Subcomponent =>
5839 if VFA then
5840 Error_Pragma
5841 ("cannot apply Volatile_Full_Access with independent "
5842 & "subcomponent ");
5843 else
5844 Error_Pragma
5845 ("cannot apply Atomic with independent subcomponent "
5846 & "(RM C.6(13))");
5847 end if;
5848
5849 when others =>
5850 raise Program_Error;
5851 end Check_Atomic_VFA;
5852
5853 ---------------------
5854 -- Check_Component --
5855 ---------------------
5856
5857 procedure Check_Component
5858 (Comp : Node_Id;
5859 UU_Typ : Entity_Id;
5860 In_Variant_Part : Boolean := False)
5861 is
5862 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
5863 Sindic : constant Node_Id :=
5864 Subtype_Indication (Component_Definition (Comp));
5865 Typ : constant Entity_Id := Etype (Comp_Id);
5866
5867 begin
5868 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
5869 -- object constraint, then the component type shall be an Unchecked_
5870 -- Union.
5871
5872 if Nkind (Sindic) = N_Subtype_Indication
5873 and then Has_Per_Object_Constraint (Comp_Id)
5874 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
5875 then
5876 Error_Msg_N
5877 ("component subtype subject to per-object constraint "
5878 & "must be an Unchecked_Union", Comp);
5879
5880 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
5881 -- the body of a generic unit, or within the body of any of its
5882 -- descendant library units, no part of the type of a component
5883 -- declared in a variant_part of the unchecked union type shall be of
5884 -- a formal private type or formal private extension declared within
5885 -- the formal part of the generic unit.
5886
5887 elsif Ada_Version >= Ada_2012
5888 and then In_Generic_Body (UU_Typ)
5889 and then In_Variant_Part
5890 and then Is_Private_Type (Typ)
5891 and then Is_Generic_Type (Typ)
5892 then
5893 Error_Msg_N
5894 ("component of unchecked union cannot be of generic type", Comp);
5895
5896 elsif Needs_Finalization (Typ) then
5897 Error_Msg_N
5898 ("component of unchecked union cannot be controlled", Comp);
5899
5900 elsif Has_Task (Typ) then
5901 Error_Msg_N
5902 ("component of unchecked union cannot have tasks", Comp);
5903 end if;
5904 end Check_Component;
5905
5906 ----------------------------
5907 -- Check_Duplicate_Pragma --
5908 ----------------------------
5909
5910 procedure Check_Duplicate_Pragma (E : Entity_Id) is
5911 Id : Entity_Id := E;
5912 P : Node_Id;
5913
5914 begin
5915 -- Nothing to do if this pragma comes from an aspect specification,
5916 -- since we could not be duplicating a pragma, and we dealt with the
5917 -- case of duplicated aspects in Analyze_Aspect_Specifications.
5918
5919 if From_Aspect_Specification (N) then
5920 return;
5921 end if;
5922
5923 -- Otherwise current pragma may duplicate previous pragma or a
5924 -- previously given aspect specification or attribute definition
5925 -- clause for the same pragma.
5926
5927 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
5928
5929 if Present (P) then
5930
5931 -- If the entity is a type, then we have to make sure that the
5932 -- ostensible duplicate is not for a parent type from which this
5933 -- type is derived.
5934
5935 if Is_Type (E) then
5936 if Nkind (P) = N_Pragma then
5937 declare
5938 Args : constant List_Id :=
5939 Pragma_Argument_Associations (P);
5940 begin
5941 if Present (Args)
5942 and then Is_Entity_Name (Expression (First (Args)))
5943 and then Is_Type (Entity (Expression (First (Args))))
5944 and then Entity (Expression (First (Args))) /= E
5945 then
5946 return;
5947 end if;
5948 end;
5949
5950 elsif Nkind (P) = N_Aspect_Specification
5951 and then Is_Type (Entity (P))
5952 and then Entity (P) /= E
5953 then
5954 return;
5955 end if;
5956 end if;
5957
5958 -- Here we have a definite duplicate
5959
5960 Error_Msg_Name_1 := Pragma_Name (N);
5961 Error_Msg_Sloc := Sloc (P);
5962
5963 -- For a single protected or a single task object, the error is
5964 -- issued on the original entity.
5965
5966 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
5967 Id := Defining_Identifier (Original_Node (Parent (Id)));
5968 end if;
5969
5970 if Nkind (P) = N_Aspect_Specification
5971 or else From_Aspect_Specification (P)
5972 then
5973 Error_Msg_NE ("aspect% for & previously given#", N, Id);
5974 else
5975 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
5976 end if;
5977
5978 raise Pragma_Exit;
5979 end if;
5980 end Check_Duplicate_Pragma;
5981
5982 ----------------------------------
5983 -- Check_Duplicated_Export_Name --
5984 ----------------------------------
5985
5986 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
5987 String_Val : constant String_Id := Strval (Nam);
5988
5989 begin
5990 -- We are only interested in the export case, and in the case of
5991 -- generics, it is the instance, not the template, that is the
5992 -- problem (the template will generate a warning in any case).
5993
5994 if not Inside_A_Generic
5995 and then (Prag_Id = Pragma_Export
5996 or else
5997 Prag_Id = Pragma_Export_Procedure
5998 or else
5999 Prag_Id = Pragma_Export_Valued_Procedure
6000 or else
6001 Prag_Id = Pragma_Export_Function)
6002 then
6003 for J in Externals.First .. Externals.Last loop
6004 if String_Equal (String_Val, Strval (Externals.Table (J))) then
6005 Error_Msg_Sloc := Sloc (Externals.Table (J));
6006 Error_Msg_N ("external name duplicates name given#", Nam);
6007 exit;
6008 end if;
6009 end loop;
6010
6011 Externals.Append (Nam);
6012 end if;
6013 end Check_Duplicated_Export_Name;
6014
6015 ----------------------------------------
6016 -- Check_Expr_Is_OK_Static_Expression --
6017 ----------------------------------------
6018
6019 procedure Check_Expr_Is_OK_Static_Expression
6020 (Expr : Node_Id;
6021 Typ : Entity_Id := Empty)
6022 is
6023 begin
6024 if Present (Typ) then
6025 Analyze_And_Resolve (Expr, Typ);
6026 else
6027 Analyze_And_Resolve (Expr);
6028 end if;
6029
6030 -- An expression cannot be considered static if its resolution failed
6031 -- or if it's erroneous. Stop the analysis of the related pragma.
6032
6033 if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
6034 raise Pragma_Exit;
6035
6036 elsif Is_OK_Static_Expression (Expr) then
6037 return;
6038
6039 -- An interesting special case, if we have a string literal and we
6040 -- are in Ada 83 mode, then we allow it even though it will not be
6041 -- flagged as static. This allows the use of Ada 95 pragmas like
6042 -- Import in Ada 83 mode. They will of course be flagged with
6043 -- warnings as usual, but will not cause errors.
6044
6045 elsif Ada_Version = Ada_83
6046 and then Nkind (Expr) = N_String_Literal
6047 then
6048 return;
6049
6050 -- Finally, we have a real error
6051
6052 else
6053 Error_Msg_Name_1 := Pname;
6054 Flag_Non_Static_Expr
6055 (Fix_Error ("argument for pragma% must be a static expression!"),
6056 Expr);
6057 raise Pragma_Exit;
6058 end if;
6059 end Check_Expr_Is_OK_Static_Expression;
6060
6061 -------------------------
6062 -- Check_First_Subtype --
6063 -------------------------
6064
6065 procedure Check_First_Subtype (Arg : Node_Id) is
6066 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6067 Ent : constant Entity_Id := Entity (Argx);
6068
6069 begin
6070 if Is_First_Subtype (Ent) then
6071 null;
6072
6073 elsif Is_Type (Ent) then
6074 Error_Pragma_Arg
6075 ("pragma% cannot apply to subtype", Argx);
6076
6077 elsif Is_Object (Ent) then
6078 Error_Pragma_Arg
6079 ("pragma% cannot apply to object, requires a type", Argx);
6080
6081 else
6082 Error_Pragma_Arg
6083 ("pragma% cannot apply to&, requires a type", Argx);
6084 end if;
6085 end Check_First_Subtype;
6086
6087 ----------------------
6088 -- Check_Identifier --
6089 ----------------------
6090
6091 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
6092 begin
6093 if Present (Arg)
6094 and then Nkind (Arg) = N_Pragma_Argument_Association
6095 then
6096 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
6097 Error_Msg_Name_1 := Pname;
6098 Error_Msg_Name_2 := Id;
6099 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6100 raise Pragma_Exit;
6101 end if;
6102 end if;
6103 end Check_Identifier;
6104
6105 --------------------------------
6106 -- Check_Identifier_Is_One_Of --
6107 --------------------------------
6108
6109 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
6110 begin
6111 if Present (Arg)
6112 and then Nkind (Arg) = N_Pragma_Argument_Association
6113 then
6114 if Chars (Arg) = No_Name then
6115 Error_Msg_Name_1 := Pname;
6116 Error_Msg_N ("pragma% argument expects an identifier", Arg);
6117 raise Pragma_Exit;
6118
6119 elsif Chars (Arg) /= N1
6120 and then Chars (Arg) /= N2
6121 then
6122 Error_Msg_Name_1 := Pname;
6123 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
6124 raise Pragma_Exit;
6125 end if;
6126 end if;
6127 end Check_Identifier_Is_One_Of;
6128
6129 ---------------------------
6130 -- Check_In_Main_Program --
6131 ---------------------------
6132
6133 procedure Check_In_Main_Program is
6134 P : constant Node_Id := Parent (N);
6135
6136 begin
6137 -- Must be in subprogram body
6138
6139 if Nkind (P) /= N_Subprogram_Body then
6140 Error_Pragma ("% pragma allowed only in subprogram");
6141
6142 -- Otherwise warn if obviously not main program
6143
6144 elsif Present (Parameter_Specifications (Specification (P)))
6145 or else not Is_Compilation_Unit (Defining_Entity (P))
6146 then
6147 Error_Msg_Name_1 := Pname;
6148 Error_Msg_N
6149 ("??pragma% is only effective in main program", N);
6150 end if;
6151 end Check_In_Main_Program;
6152
6153 ---------------------------------------
6154 -- Check_Interrupt_Or_Attach_Handler --
6155 ---------------------------------------
6156
6157 procedure Check_Interrupt_Or_Attach_Handler is
6158 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
6159 Handler_Proc, Proc_Scope : Entity_Id;
6160
6161 begin
6162 Analyze (Arg1_X);
6163
6164 if Prag_Id = Pragma_Interrupt_Handler then
6165 Check_Restriction (No_Dynamic_Attachment, N);
6166 end if;
6167
6168 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
6169 Proc_Scope := Scope (Handler_Proc);
6170
6171 if Ekind (Proc_Scope) /= E_Protected_Type then
6172 Error_Pragma_Arg
6173 ("argument of pragma% must be protected procedure", Arg1);
6174 end if;
6175
6176 -- For pragma case (as opposed to access case), check placement.
6177 -- We don't need to do that for aspects, because we have the
6178 -- check that they aspect applies an appropriate procedure.
6179
6180 if not From_Aspect_Specification (N)
6181 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
6182 then
6183 Error_Pragma ("pragma% must be in protected definition");
6184 end if;
6185
6186 if not Is_Library_Level_Entity (Proc_Scope) then
6187 Error_Pragma_Arg
6188 ("argument for pragma% must be library level entity", Arg1);
6189 end if;
6190
6191 -- AI05-0033: A pragma cannot appear within a generic body, because
6192 -- instance can be in a nested scope. The check that protected type
6193 -- is itself a library-level declaration is done elsewhere.
6194
6195 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
6196 -- handle code prior to AI-0033. Analysis tools typically are not
6197 -- interested in this pragma in any case, so no need to worry too
6198 -- much about its placement.
6199
6200 if Inside_A_Generic then
6201 if Ekind (Scope (Current_Scope)) = E_Generic_Package
6202 and then In_Package_Body (Scope (Current_Scope))
6203 and then not Relaxed_RM_Semantics
6204 then
6205 Error_Pragma ("pragma% cannot be used inside a generic");
6206 end if;
6207 end if;
6208 end Check_Interrupt_Or_Attach_Handler;
6209
6210 ---------------------------------
6211 -- Check_Loop_Pragma_Placement --
6212 ---------------------------------
6213
6214 procedure Check_Loop_Pragma_Placement is
6215 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
6216 -- Verify whether the current pragma is properly grouped with other
6217 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
6218 -- related loop where the pragma appears.
6219
6220 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
6221 -- Determine whether an arbitrary statement Stmt denotes pragma
6222 -- Loop_Invariant or Loop_Variant.
6223
6224 procedure Placement_Error (Constr : Node_Id);
6225 pragma No_Return (Placement_Error);
6226 -- Node Constr denotes the last loop restricted construct before we
6227 -- encountered an illegal relation between enclosing constructs. Emit
6228 -- an error depending on what Constr was.
6229
6230 --------------------------------
6231 -- Check_Loop_Pragma_Grouping --
6232 --------------------------------
6233
6234 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
6235 Stop_Search : exception;
6236 -- This exception is used to terminate the recursive descent of
6237 -- routine Check_Grouping.
6238
6239 procedure Check_Grouping (L : List_Id);
6240 -- Find the first group of pragmas in list L and if successful,
6241 -- ensure that the current pragma is part of that group. The
6242 -- routine raises Stop_Search once such a check is performed to
6243 -- halt the recursive descent.
6244
6245 procedure Grouping_Error (Prag : Node_Id);
6246 pragma No_Return (Grouping_Error);
6247 -- Emit an error concerning the current pragma indicating that it
6248 -- should be placed after pragma Prag.
6249
6250 --------------------
6251 -- Check_Grouping --
6252 --------------------
6253
6254 procedure Check_Grouping (L : List_Id) is
6255 HSS : Node_Id;
6256 Stmt : Node_Id;
6257 Prag : Node_Id := Empty; -- init to avoid warning
6258
6259 begin
6260 -- Inspect the list of declarations or statements looking for
6261 -- the first grouping of pragmas:
6262
6263 -- loop
6264 -- pragma Loop_Invariant ...;
6265 -- pragma Loop_Variant ...;
6266 -- . . . -- (1)
6267 -- pragma Loop_Variant ...; -- current pragma
6268
6269 -- If the current pragma is not in the grouping, then it must
6270 -- either appear in a different declarative or statement list
6271 -- or the construct at (1) is separating the pragma from the
6272 -- grouping.
6273
6274 Stmt := First (L);
6275 while Present (Stmt) loop
6276
6277 -- First pragma of the first topmost grouping has been found
6278
6279 if Is_Loop_Pragma (Stmt) then
6280
6281 -- The group and the current pragma are not in the same
6282 -- declarative or statement list.
6283
6284 if List_Containing (Stmt) /= List_Containing (N) then
6285 Grouping_Error (Stmt);
6286
6287 -- Try to reach the current pragma from the first pragma
6288 -- of the grouping while skipping other members:
6289
6290 -- pragma Loop_Invariant ...; -- first pragma
6291 -- pragma Loop_Variant ...; -- member
6292 -- . . .
6293 -- pragma Loop_Variant ...; -- current pragma
6294
6295 else
6296 while Present (Stmt) loop
6297 -- The current pragma is either the first pragma
6298 -- of the group or is a member of the group.
6299 -- Stop the search as the placement is legal.
6300
6301 if Stmt = N then
6302 raise Stop_Search;
6303
6304 -- Skip group members, but keep track of the
6305 -- last pragma in the group.
6306
6307 elsif Is_Loop_Pragma (Stmt) then
6308 Prag := Stmt;
6309
6310 -- Skip declarations and statements generated by
6311 -- the compiler during expansion. Note that some
6312 -- source statements (e.g. pragma Assert) may have
6313 -- been transformed so that they do not appear as
6314 -- coming from source anymore, so we instead look
6315 -- at their Original_Node.
6316
6317 elsif not Comes_From_Source (Original_Node (Stmt))
6318 then
6319 null;
6320
6321 -- A non-pragma is separating the group from the
6322 -- current pragma, the placement is illegal.
6323
6324 else
6325 Grouping_Error (Prag);
6326 end if;
6327
6328 Next (Stmt);
6329 end loop;
6330
6331 -- If the traversal did not reach the current pragma,
6332 -- then the list must be malformed.
6333
6334 raise Program_Error;
6335 end if;
6336
6337 -- Pragmas Loop_Invariant and Loop_Variant may only appear
6338 -- inside a loop or a block housed inside a loop. Inspect
6339 -- the declarations and statements of the block as they may
6340 -- contain the first grouping. This case follows the one for
6341 -- loop pragmas, as block statements which originate in a
6342 -- loop pragma (and so Is_Loop_Pragma will return True on
6343 -- that block statement) should be treated in the previous
6344 -- case.
6345
6346 elsif Nkind (Stmt) = N_Block_Statement then
6347 HSS := Handled_Statement_Sequence (Stmt);
6348
6349 Check_Grouping (Declarations (Stmt));
6350
6351 if Present (HSS) then
6352 Check_Grouping (Statements (HSS));
6353 end if;
6354 end if;
6355
6356 Next (Stmt);
6357 end loop;
6358 end Check_Grouping;
6359
6360 --------------------
6361 -- Grouping_Error --
6362 --------------------
6363
6364 procedure Grouping_Error (Prag : Node_Id) is
6365 begin
6366 Error_Msg_Sloc := Sloc (Prag);
6367 Error_Pragma ("pragma% must appear next to pragma#");
6368 end Grouping_Error;
6369
6370 -- Start of processing for Check_Loop_Pragma_Grouping
6371
6372 begin
6373 -- Inspect the statements of the loop or nested blocks housed
6374 -- within to determine whether the current pragma is part of the
6375 -- first topmost grouping of Loop_Invariant and Loop_Variant.
6376
6377 Check_Grouping (Statements (Loop_Stmt));
6378
6379 exception
6380 when Stop_Search => null;
6381 end Check_Loop_Pragma_Grouping;
6382
6383 --------------------
6384 -- Is_Loop_Pragma --
6385 --------------------
6386
6387 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
6388 begin
6389 -- Inspect the original node as Loop_Invariant and Loop_Variant
6390 -- pragmas are rewritten to null when assertions are disabled.
6391
6392 if Nkind (Original_Node (Stmt)) = N_Pragma then
6393 return
6394 Nam_In (Pragma_Name_Unmapped (Original_Node (Stmt)),
6395 Name_Loop_Invariant,
6396 Name_Loop_Variant);
6397 else
6398 return False;
6399 end if;
6400 end Is_Loop_Pragma;
6401
6402 ---------------------
6403 -- Placement_Error --
6404 ---------------------
6405
6406 procedure Placement_Error (Constr : Node_Id) is
6407 LA : constant String := " with Loop_Entry";
6408
6409 begin
6410 if Prag_Id = Pragma_Assert then
6411 Error_Msg_String (1 .. LA'Length) := LA;
6412 Error_Msg_Strlen := LA'Length;
6413 else
6414 Error_Msg_Strlen := 0;
6415 end if;
6416
6417 if Nkind (Constr) = N_Pragma then
6418 Error_Pragma
6419 ("pragma %~ must appear immediately within the statements "
6420 & "of a loop");
6421 else
6422 Error_Pragma_Arg
6423 ("block containing pragma %~ must appear immediately within "
6424 & "the statements of a loop", Constr);
6425 end if;
6426 end Placement_Error;
6427
6428 -- Local declarations
6429
6430 Prev : Node_Id;
6431 Stmt : Node_Id;
6432
6433 -- Start of processing for Check_Loop_Pragma_Placement
6434
6435 begin
6436 -- Check that pragma appears immediately within a loop statement,
6437 -- ignoring intervening block statements.
6438
6439 Prev := N;
6440 Stmt := Parent (N);
6441 while Present (Stmt) loop
6442
6443 -- The pragma or previous block must appear immediately within the
6444 -- current block's declarative or statement part.
6445
6446 if Nkind (Stmt) = N_Block_Statement then
6447 if (No (Declarations (Stmt))
6448 or else List_Containing (Prev) /= Declarations (Stmt))
6449 and then
6450 List_Containing (Prev) /=
6451 Statements (Handled_Statement_Sequence (Stmt))
6452 then
6453 Placement_Error (Prev);
6454 return;
6455
6456 -- Keep inspecting the parents because we are now within a
6457 -- chain of nested blocks.
6458
6459 else
6460 Prev := Stmt;
6461 Stmt := Parent (Stmt);
6462 end if;
6463
6464 -- The pragma or previous block must appear immediately within the
6465 -- statements of the loop.
6466
6467 elsif Nkind (Stmt) = N_Loop_Statement then
6468 if List_Containing (Prev) /= Statements (Stmt) then
6469 Placement_Error (Prev);
6470 end if;
6471
6472 -- Stop the traversal because we reached the innermost loop
6473 -- regardless of whether we encountered an error or not.
6474
6475 exit;
6476
6477 -- Ignore a handled statement sequence. Note that this node may
6478 -- be related to a subprogram body in which case we will emit an
6479 -- error on the next iteration of the search.
6480
6481 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
6482 Stmt := Parent (Stmt);
6483
6484 -- Any other statement breaks the chain from the pragma to the
6485 -- loop.
6486
6487 else
6488 Placement_Error (Prev);
6489 return;
6490 end if;
6491 end loop;
6492
6493 -- Check that the current pragma Loop_Invariant or Loop_Variant is
6494 -- grouped together with other such pragmas.
6495
6496 if Is_Loop_Pragma (N) then
6497
6498 -- The previous check should have located the related loop
6499
6500 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
6501 Check_Loop_Pragma_Grouping (Stmt);
6502 end if;
6503 end Check_Loop_Pragma_Placement;
6504
6505 -------------------------------------------
6506 -- Check_Is_In_Decl_Part_Or_Package_Spec --
6507 -------------------------------------------
6508
6509 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
6510 P : Node_Id;
6511
6512 begin
6513 P := Parent (N);
6514 loop
6515 if No (P) then
6516 exit;
6517
6518 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
6519 exit;
6520
6521 elsif Nkind_In (P, N_Package_Specification,
6522 N_Block_Statement)
6523 then
6524 return;
6525
6526 -- Note: the following tests seem a little peculiar, because
6527 -- they test for bodies, but if we were in the statement part
6528 -- of the body, we would already have hit the handled statement
6529 -- sequence, so the only way we get here is by being in the
6530 -- declarative part of the body.
6531
6532 elsif Nkind_In (P, N_Subprogram_Body,
6533 N_Package_Body,
6534 N_Task_Body,
6535 N_Entry_Body)
6536 then
6537 return;
6538 end if;
6539
6540 P := Parent (P);
6541 end loop;
6542
6543 Error_Pragma ("pragma% is not in declarative part or package spec");
6544 end Check_Is_In_Decl_Part_Or_Package_Spec;
6545
6546 -------------------------
6547 -- Check_No_Identifier --
6548 -------------------------
6549
6550 procedure Check_No_Identifier (Arg : Node_Id) is
6551 begin
6552 if Nkind (Arg) = N_Pragma_Argument_Association
6553 and then Chars (Arg) /= No_Name
6554 then
6555 Error_Pragma_Arg_Ident
6556 ("pragma% does not permit identifier& here", Arg);
6557 end if;
6558 end Check_No_Identifier;
6559
6560 --------------------------
6561 -- Check_No_Identifiers --
6562 --------------------------
6563
6564 procedure Check_No_Identifiers is
6565 Arg_Node : Node_Id;
6566 begin
6567 Arg_Node := Arg1;
6568 for J in 1 .. Arg_Count loop
6569 Check_No_Identifier (Arg_Node);
6570 Next (Arg_Node);
6571 end loop;
6572 end Check_No_Identifiers;
6573
6574 ------------------------
6575 -- Check_No_Link_Name --
6576 ------------------------
6577
6578 procedure Check_No_Link_Name is
6579 begin
6580 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
6581 Arg4 := Arg3;
6582 end if;
6583
6584 if Present (Arg4) then
6585 Error_Pragma_Arg
6586 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
6587 end if;
6588 end Check_No_Link_Name;
6589
6590 -------------------------------
6591 -- Check_Optional_Identifier --
6592 -------------------------------
6593
6594 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
6595 begin
6596 if Present (Arg)
6597 and then Nkind (Arg) = N_Pragma_Argument_Association
6598 and then Chars (Arg) /= No_Name
6599 then
6600 if Chars (Arg) /= Id then
6601 Error_Msg_Name_1 := Pname;
6602 Error_Msg_Name_2 := Id;
6603 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6604 raise Pragma_Exit;
6605 end if;
6606 end if;
6607 end Check_Optional_Identifier;
6608
6609 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
6610 begin
6611 Check_Optional_Identifier (Arg, Name_Find (Id));
6612 end Check_Optional_Identifier;
6613
6614 -------------------------------------
6615 -- Check_Static_Boolean_Expression --
6616 -------------------------------------
6617
6618 procedure Check_Static_Boolean_Expression (Expr : Node_Id) is
6619 begin
6620 if Present (Expr) then
6621 Analyze_And_Resolve (Expr, Standard_Boolean);
6622
6623 if not Is_OK_Static_Expression (Expr) then
6624 Error_Pragma_Arg
6625 ("expression of pragma % must be static", Expr);
6626 end if;
6627 end if;
6628 end Check_Static_Boolean_Expression;
6629
6630 -----------------------------
6631 -- Check_Static_Constraint --
6632 -----------------------------
6633
6634 -- Note: for convenience in writing this procedure, in addition to
6635 -- the officially (i.e. by spec) allowed argument which is always a
6636 -- constraint, it also allows ranges and discriminant associations.
6637 -- Above is not clear ???
6638
6639 procedure Check_Static_Constraint (Constr : Node_Id) is
6640
6641 procedure Require_Static (E : Node_Id);
6642 -- Require given expression to be static expression
6643
6644 --------------------
6645 -- Require_Static --
6646 --------------------
6647
6648 procedure Require_Static (E : Node_Id) is
6649 begin
6650 if not Is_OK_Static_Expression (E) then
6651 Flag_Non_Static_Expr
6652 ("non-static constraint not allowed in Unchecked_Union!", E);
6653 raise Pragma_Exit;
6654 end if;
6655 end Require_Static;
6656
6657 -- Start of processing for Check_Static_Constraint
6658
6659 begin
6660 case Nkind (Constr) is
6661 when N_Discriminant_Association =>
6662 Require_Static (Expression (Constr));
6663
6664 when N_Range =>
6665 Require_Static (Low_Bound (Constr));
6666 Require_Static (High_Bound (Constr));
6667
6668 when N_Attribute_Reference =>
6669 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
6670 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
6671
6672 when N_Range_Constraint =>
6673 Check_Static_Constraint (Range_Expression (Constr));
6674
6675 when N_Index_Or_Discriminant_Constraint =>
6676 declare
6677 IDC : Entity_Id;
6678 begin
6679 IDC := First (Constraints (Constr));
6680 while Present (IDC) loop
6681 Check_Static_Constraint (IDC);
6682 Next (IDC);
6683 end loop;
6684 end;
6685
6686 when others =>
6687 null;
6688 end case;
6689 end Check_Static_Constraint;
6690
6691 --------------------------------------
6692 -- Check_Valid_Configuration_Pragma --
6693 --------------------------------------
6694
6695 -- A configuration pragma must appear in the context clause of a
6696 -- compilation unit, and only other pragmas may precede it. Note that
6697 -- the test also allows use in a configuration pragma file.
6698
6699 procedure Check_Valid_Configuration_Pragma is
6700 begin
6701 if not Is_Configuration_Pragma then
6702 Error_Pragma ("incorrect placement for configuration pragma%");
6703 end if;
6704 end Check_Valid_Configuration_Pragma;
6705
6706 -------------------------------------
6707 -- Check_Valid_Library_Unit_Pragma --
6708 -------------------------------------
6709
6710 procedure Check_Valid_Library_Unit_Pragma is
6711 Plist : List_Id;
6712 Parent_Node : Node_Id;
6713 Unit_Name : Entity_Id;
6714 Unit_Kind : Node_Kind;
6715 Unit_Node : Node_Id;
6716 Sindex : Source_File_Index;
6717
6718 begin
6719 if not Is_List_Member (N) then
6720 Pragma_Misplaced;
6721
6722 else
6723 Plist := List_Containing (N);
6724 Parent_Node := Parent (Plist);
6725
6726 if Parent_Node = Empty then
6727 Pragma_Misplaced;
6728
6729 -- Case of pragma appearing after a compilation unit. In this case
6730 -- it must have an argument with the corresponding name and must
6731 -- be part of the following pragmas of its parent.
6732
6733 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
6734 if Plist /= Pragmas_After (Parent_Node) then
6735 Pragma_Misplaced;
6736
6737 elsif Arg_Count = 0 then
6738 Error_Pragma
6739 ("argument required if outside compilation unit");
6740
6741 else
6742 Check_No_Identifiers;
6743 Check_Arg_Count (1);
6744 Unit_Node := Unit (Parent (Parent_Node));
6745 Unit_Kind := Nkind (Unit_Node);
6746
6747 Analyze (Get_Pragma_Arg (Arg1));
6748
6749 if Unit_Kind = N_Generic_Subprogram_Declaration
6750 or else Unit_Kind = N_Subprogram_Declaration
6751 then
6752 Unit_Name := Defining_Entity (Unit_Node);
6753
6754 elsif Unit_Kind in N_Generic_Instantiation then
6755 Unit_Name := Defining_Entity (Unit_Node);
6756
6757 else
6758 Unit_Name := Cunit_Entity (Current_Sem_Unit);
6759 end if;
6760
6761 if Chars (Unit_Name) /=
6762 Chars (Entity (Get_Pragma_Arg (Arg1)))
6763 then
6764 Error_Pragma_Arg
6765 ("pragma% argument is not current unit name", Arg1);
6766 end if;
6767
6768 if Ekind (Unit_Name) = E_Package
6769 and then Present (Renamed_Entity (Unit_Name))
6770 then
6771 Error_Pragma ("pragma% not allowed for renamed package");
6772 end if;
6773 end if;
6774
6775 -- Pragma appears other than after a compilation unit
6776
6777 else
6778 -- Here we check for the generic instantiation case and also
6779 -- for the case of processing a generic formal package. We
6780 -- detect these cases by noting that the Sloc on the node
6781 -- does not belong to the current compilation unit.
6782
6783 Sindex := Source_Index (Current_Sem_Unit);
6784
6785 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
6786 Rewrite (N, Make_Null_Statement (Loc));
6787 return;
6788
6789 -- If before first declaration, the pragma applies to the
6790 -- enclosing unit, and the name if present must be this name.
6791
6792 elsif Is_Before_First_Decl (N, Plist) then
6793 Unit_Node := Unit_Declaration_Node (Current_Scope);
6794 Unit_Kind := Nkind (Unit_Node);
6795
6796 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
6797 Pragma_Misplaced;
6798
6799 elsif Unit_Kind = N_Subprogram_Body
6800 and then not Acts_As_Spec (Unit_Node)
6801 then
6802 Pragma_Misplaced;
6803
6804 elsif Nkind (Parent_Node) = N_Package_Body then
6805 Pragma_Misplaced;
6806
6807 elsif Nkind (Parent_Node) = N_Package_Specification
6808 and then Plist = Private_Declarations (Parent_Node)
6809 then
6810 Pragma_Misplaced;
6811
6812 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
6813 or else Nkind (Parent_Node) =
6814 N_Generic_Subprogram_Declaration)
6815 and then Plist = Generic_Formal_Declarations (Parent_Node)
6816 then
6817 Pragma_Misplaced;
6818
6819 elsif Arg_Count > 0 then
6820 Analyze (Get_Pragma_Arg (Arg1));
6821
6822 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
6823 Error_Pragma_Arg
6824 ("name in pragma% must be enclosing unit", Arg1);
6825 end if;
6826
6827 -- It is legal to have no argument in this context
6828
6829 else
6830 return;
6831 end if;
6832
6833 -- Error if not before first declaration. This is because a
6834 -- library unit pragma argument must be the name of a library
6835 -- unit (RM 10.1.5(7)), but the only names permitted in this
6836 -- context are (RM 10.1.5(6)) names of subprogram declarations,
6837 -- generic subprogram declarations or generic instantiations.
6838
6839 else
6840 Error_Pragma
6841 ("pragma% misplaced, must be before first declaration");
6842 end if;
6843 end if;
6844 end if;
6845 end Check_Valid_Library_Unit_Pragma;
6846
6847 -------------------
6848 -- Check_Variant --
6849 -------------------
6850
6851 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
6852 Clist : constant Node_Id := Component_List (Variant);
6853 Comp : Node_Id;
6854
6855 begin
6856 Comp := First_Non_Pragma (Component_Items (Clist));
6857 while Present (Comp) loop
6858 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
6859 Next_Non_Pragma (Comp);
6860 end loop;
6861 end Check_Variant;
6862
6863 ---------------------------
6864 -- Ensure_Aggregate_Form --
6865 ---------------------------
6866
6867 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
6868 CFSD : constant Boolean := Get_Comes_From_Source_Default;
6869 Expr : constant Node_Id := Expression (Arg);
6870 Loc : constant Source_Ptr := Sloc (Expr);
6871 Comps : List_Id := No_List;
6872 Exprs : List_Id := No_List;
6873 Nam : Name_Id := No_Name;
6874 Nam_Loc : Source_Ptr;
6875
6876 begin
6877 -- The pragma argument is in positional form:
6878
6879 -- pragma Depends (Nam => ...)
6880 -- ^
6881 -- Chars field
6882
6883 -- Note that the Sloc of the Chars field is the Sloc of the pragma
6884 -- argument association.
6885
6886 if Nkind (Arg) = N_Pragma_Argument_Association then
6887 Nam := Chars (Arg);
6888 Nam_Loc := Sloc (Arg);
6889
6890 -- Remove the pragma argument name as this will be captured in the
6891 -- aggregate.
6892
6893 Set_Chars (Arg, No_Name);
6894 end if;
6895
6896 -- The argument is already in aggregate form, but the presence of a
6897 -- name causes this to be interpreted as named association which in
6898 -- turn must be converted into an aggregate.
6899
6900 -- pragma Global (In_Out => (A, B, C))
6901 -- ^ ^
6902 -- name aggregate
6903
6904 -- pragma Global ((In_Out => (A, B, C)))
6905 -- ^ ^
6906 -- aggregate aggregate
6907
6908 if Nkind (Expr) = N_Aggregate then
6909 if Nam = No_Name then
6910 return;
6911 end if;
6912
6913 -- Do not transform a null argument into an aggregate as N_Null has
6914 -- special meaning in formal verification pragmas.
6915
6916 elsif Nkind (Expr) = N_Null then
6917 return;
6918 end if;
6919
6920 -- Everything comes from source if the original comes from source
6921
6922 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
6923
6924 -- Positional argument is transformed into an aggregate with an
6925 -- Expressions list.
6926
6927 if Nam = No_Name then
6928 Exprs := New_List (Relocate_Node (Expr));
6929
6930 -- An associative argument is transformed into an aggregate with
6931 -- Component_Associations.
6932
6933 else
6934 Comps := New_List (
6935 Make_Component_Association (Loc,
6936 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
6937 Expression => Relocate_Node (Expr)));
6938 end if;
6939
6940 Set_Expression (Arg,
6941 Make_Aggregate (Loc,
6942 Component_Associations => Comps,
6943 Expressions => Exprs));
6944
6945 -- Restore Comes_From_Source default
6946
6947 Set_Comes_From_Source_Default (CFSD);
6948 end Ensure_Aggregate_Form;
6949
6950 ------------------
6951 -- Error_Pragma --
6952 ------------------
6953
6954 procedure Error_Pragma (Msg : String) is
6955 begin
6956 Error_Msg_Name_1 := Pname;
6957 Error_Msg_N (Fix_Error (Msg), N);
6958 raise Pragma_Exit;
6959 end Error_Pragma;
6960
6961 ----------------------
6962 -- Error_Pragma_Arg --
6963 ----------------------
6964
6965 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
6966 begin
6967 Error_Msg_Name_1 := Pname;
6968 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
6969 raise Pragma_Exit;
6970 end Error_Pragma_Arg;
6971
6972 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
6973 begin
6974 Error_Msg_Name_1 := Pname;
6975 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
6976 Error_Pragma_Arg (Msg2, Arg);
6977 end Error_Pragma_Arg;
6978
6979 ----------------------------
6980 -- Error_Pragma_Arg_Ident --
6981 ----------------------------
6982
6983 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
6984 begin
6985 Error_Msg_Name_1 := Pname;
6986 Error_Msg_N (Fix_Error (Msg), Arg);
6987 raise Pragma_Exit;
6988 end Error_Pragma_Arg_Ident;
6989
6990 ----------------------
6991 -- Error_Pragma_Ref --
6992 ----------------------
6993
6994 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
6995 begin
6996 Error_Msg_Name_1 := Pname;
6997 Error_Msg_Sloc := Sloc (Ref);
6998 Error_Msg_NE (Fix_Error (Msg), N, Ref);
6999 raise Pragma_Exit;
7000 end Error_Pragma_Ref;
7001
7002 ------------------------
7003 -- Find_Lib_Unit_Name --
7004 ------------------------
7005
7006 function Find_Lib_Unit_Name return Entity_Id is
7007 begin
7008 -- Return inner compilation unit entity, for case of nested
7009 -- categorization pragmas. This happens in generic unit.
7010
7011 if Nkind (Parent (N)) = N_Package_Specification
7012 and then Defining_Entity (Parent (N)) /= Current_Scope
7013 then
7014 return Defining_Entity (Parent (N));
7015 else
7016 return Current_Scope;
7017 end if;
7018 end Find_Lib_Unit_Name;
7019
7020 ----------------------------
7021 -- Find_Program_Unit_Name --
7022 ----------------------------
7023
7024 procedure Find_Program_Unit_Name (Id : Node_Id) is
7025 Unit_Name : Entity_Id;
7026 Unit_Kind : Node_Kind;
7027 P : constant Node_Id := Parent (N);
7028
7029 begin
7030 if Nkind (P) = N_Compilation_Unit then
7031 Unit_Kind := Nkind (Unit (P));
7032
7033 if Nkind_In (Unit_Kind, N_Subprogram_Declaration,
7034 N_Package_Declaration)
7035 or else Unit_Kind in N_Generic_Declaration
7036 then
7037 Unit_Name := Defining_Entity (Unit (P));
7038
7039 if Chars (Id) = Chars (Unit_Name) then
7040 Set_Entity (Id, Unit_Name);
7041 Set_Etype (Id, Etype (Unit_Name));
7042 else
7043 Set_Etype (Id, Any_Type);
7044 Error_Pragma
7045 ("cannot find program unit referenced by pragma%");
7046 end if;
7047
7048 else
7049 Set_Etype (Id, Any_Type);
7050 Error_Pragma ("pragma% inapplicable to this unit");
7051 end if;
7052
7053 else
7054 Analyze (Id);
7055 end if;
7056 end Find_Program_Unit_Name;
7057
7058 -----------------------------------------
7059 -- Find_Unique_Parameterless_Procedure --
7060 -----------------------------------------
7061
7062 function Find_Unique_Parameterless_Procedure
7063 (Name : Entity_Id;
7064 Arg : Node_Id) return Entity_Id
7065 is
7066 Proc : Entity_Id := Empty;
7067
7068 begin
7069 -- The body of this procedure needs some comments ???
7070
7071 if not Is_Entity_Name (Name) then
7072 Error_Pragma_Arg
7073 ("argument of pragma% must be entity name", Arg);
7074
7075 elsif not Is_Overloaded (Name) then
7076 Proc := Entity (Name);
7077
7078 if Ekind (Proc) /= E_Procedure
7079 or else Present (First_Formal (Proc))
7080 then
7081 Error_Pragma_Arg
7082 ("argument of pragma% must be parameterless procedure", Arg);
7083 end if;
7084
7085 else
7086 declare
7087 Found : Boolean := False;
7088 It : Interp;
7089 Index : Interp_Index;
7090
7091 begin
7092 Get_First_Interp (Name, Index, It);
7093 while Present (It.Nam) loop
7094 Proc := It.Nam;
7095
7096 if Ekind (Proc) = E_Procedure
7097 and then No (First_Formal (Proc))
7098 then
7099 if not Found then
7100 Found := True;
7101 Set_Entity (Name, Proc);
7102 Set_Is_Overloaded (Name, False);
7103 else
7104 Error_Pragma_Arg
7105 ("ambiguous handler name for pragma% ", Arg);
7106 end if;
7107 end if;
7108
7109 Get_Next_Interp (Index, It);
7110 end loop;
7111
7112 if not Found then
7113 Error_Pragma_Arg
7114 ("argument of pragma% must be parameterless procedure",
7115 Arg);
7116 else
7117 Proc := Entity (Name);
7118 end if;
7119 end;
7120 end if;
7121
7122 return Proc;
7123 end Find_Unique_Parameterless_Procedure;
7124
7125 ---------------
7126 -- Fix_Error --
7127 ---------------
7128
7129 function Fix_Error (Msg : String) return String is
7130 Res : String (Msg'Range) := Msg;
7131 Res_Last : Natural := Msg'Last;
7132 J : Natural;
7133
7134 begin
7135 -- If we have a rewriting of another pragma, go to that pragma
7136
7137 if Is_Rewrite_Substitution (N)
7138 and then Nkind (Original_Node (N)) = N_Pragma
7139 then
7140 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
7141 end if;
7142
7143 -- Case where pragma comes from an aspect specification
7144
7145 if From_Aspect_Specification (N) then
7146
7147 -- Change appearence of "pragma" in message to "aspect"
7148
7149 J := Res'First;
7150 while J <= Res_Last - 5 loop
7151 if Res (J .. J + 5) = "pragma" then
7152 Res (J .. J + 5) := "aspect";
7153 J := J + 6;
7154
7155 else
7156 J := J + 1;
7157 end if;
7158 end loop;
7159
7160 -- Change "argument of" at start of message to "entity for"
7161
7162 if Res'Length > 11
7163 and then Res (Res'First .. Res'First + 10) = "argument of"
7164 then
7165 Res (Res'First .. Res'First + 9) := "entity for";
7166 Res (Res'First + 10 .. Res_Last - 1) :=
7167 Res (Res'First + 11 .. Res_Last);
7168 Res_Last := Res_Last - 1;
7169 end if;
7170
7171 -- Change "argument" at start of message to "entity"
7172
7173 if Res'Length > 8
7174 and then Res (Res'First .. Res'First + 7) = "argument"
7175 then
7176 Res (Res'First .. Res'First + 5) := "entity";
7177 Res (Res'First + 6 .. Res_Last - 2) :=
7178 Res (Res'First + 8 .. Res_Last);
7179 Res_Last := Res_Last - 2;
7180 end if;
7181
7182 -- Get name from corresponding aspect
7183
7184 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
7185 end if;
7186
7187 -- Return possibly modified message
7188
7189 return Res (Res'First .. Res_Last);
7190 end Fix_Error;
7191
7192 -------------------------
7193 -- Gather_Associations --
7194 -------------------------
7195
7196 procedure Gather_Associations
7197 (Names : Name_List;
7198 Args : out Args_List)
7199 is
7200 Arg : Node_Id;
7201
7202 begin
7203 -- Initialize all parameters to Empty
7204
7205 for J in Args'Range loop
7206 Args (J) := Empty;
7207 end loop;
7208
7209 -- That's all we have to do if there are no argument associations
7210
7211 if No (Pragma_Argument_Associations (N)) then
7212 return;
7213 end if;
7214
7215 -- Otherwise first deal with any positional parameters present
7216
7217 Arg := First (Pragma_Argument_Associations (N));
7218 for Index in Args'Range loop
7219 exit when No (Arg) or else Chars (Arg) /= No_Name;
7220 Args (Index) := Get_Pragma_Arg (Arg);
7221 Next (Arg);
7222 end loop;
7223
7224 -- Positional parameters all processed, if any left, then we
7225 -- have too many positional parameters.
7226
7227 if Present (Arg) and then Chars (Arg) = No_Name then
7228 Error_Pragma_Arg
7229 ("too many positional associations for pragma%", Arg);
7230 end if;
7231
7232 -- Process named parameters if any are present
7233
7234 while Present (Arg) loop
7235 if Chars (Arg) = No_Name then
7236 Error_Pragma_Arg
7237 ("positional association cannot follow named association",
7238 Arg);
7239
7240 else
7241 for Index in Names'Range loop
7242 if Names (Index) = Chars (Arg) then
7243 if Present (Args (Index)) then
7244 Error_Pragma_Arg
7245 ("duplicate argument association for pragma%", Arg);
7246 else
7247 Args (Index) := Get_Pragma_Arg (Arg);
7248 exit;
7249 end if;
7250 end if;
7251
7252 if Index = Names'Last then
7253 Error_Msg_Name_1 := Pname;
7254 Error_Msg_N ("pragma% does not allow & argument", Arg);
7255
7256 -- Check for possible misspelling
7257
7258 for Index1 in Names'Range loop
7259 if Is_Bad_Spelling_Of
7260 (Chars (Arg), Names (Index1))
7261 then
7262 Error_Msg_Name_1 := Names (Index1);
7263 Error_Msg_N -- CODEFIX
7264 ("\possible misspelling of%", Arg);
7265 exit;
7266 end if;
7267 end loop;
7268
7269 raise Pragma_Exit;
7270 end if;
7271 end loop;
7272 end if;
7273
7274 Next (Arg);
7275 end loop;
7276 end Gather_Associations;
7277
7278 -----------------
7279 -- GNAT_Pragma --
7280 -----------------
7281
7282 procedure GNAT_Pragma is
7283 begin
7284 -- We need to check the No_Implementation_Pragmas restriction for
7285 -- the case of a pragma from source. Note that the case of aspects
7286 -- generating corresponding pragmas marks these pragmas as not being
7287 -- from source, so this test also catches that case.
7288
7289 if Comes_From_Source (N) then
7290 Check_Restriction (No_Implementation_Pragmas, N);
7291 end if;
7292 end GNAT_Pragma;
7293
7294 --------------------------
7295 -- Is_Before_First_Decl --
7296 --------------------------
7297
7298 function Is_Before_First_Decl
7299 (Pragma_Node : Node_Id;
7300 Decls : List_Id) return Boolean
7301 is
7302 Item : Node_Id := First (Decls);
7303
7304 begin
7305 -- Only other pragmas can come before this pragma, but they might
7306 -- have been rewritten so check the original node.
7307
7308 loop
7309 if No (Item) or else Nkind (Original_Node (Item)) /= N_Pragma then
7310 return False;
7311
7312 elsif Item = Pragma_Node then
7313 return True;
7314 end if;
7315
7316 Next (Item);
7317 end loop;
7318 end Is_Before_First_Decl;
7319
7320 -----------------------------
7321 -- Is_Configuration_Pragma --
7322 -----------------------------
7323
7324 -- A configuration pragma must appear in the context clause of a
7325 -- compilation unit, and only other pragmas may precede it. Note that
7326 -- the test below also permits use in a configuration pragma file.
7327
7328 function Is_Configuration_Pragma return Boolean is
7329 Lis : constant List_Id := List_Containing (N);
7330 Par : constant Node_Id := Parent (N);
7331 Prg : Node_Id;
7332
7333 begin
7334 -- If no parent, then we are in the configuration pragma file,
7335 -- so the placement is definitely appropriate.
7336
7337 if No (Par) then
7338 return True;
7339
7340 -- Otherwise we must be in the context clause of a compilation unit
7341 -- and the only thing allowed before us in the context list is more
7342 -- configuration pragmas.
7343
7344 elsif Nkind (Par) = N_Compilation_Unit
7345 and then Context_Items (Par) = Lis
7346 then
7347 Prg := First (Lis);
7348
7349 loop
7350 if Prg = N then
7351 return True;
7352 elsif Nkind (Prg) /= N_Pragma then
7353 return False;
7354 end if;
7355
7356 Next (Prg);
7357 end loop;
7358
7359 else
7360 return False;
7361 end if;
7362 end Is_Configuration_Pragma;
7363
7364 --------------------------
7365 -- Is_In_Context_Clause --
7366 --------------------------
7367
7368 function Is_In_Context_Clause return Boolean is
7369 Plist : List_Id;
7370 Parent_Node : Node_Id;
7371
7372 begin
7373 if not Is_List_Member (N) then
7374 return False;
7375
7376 else
7377 Plist := List_Containing (N);
7378 Parent_Node := Parent (Plist);
7379
7380 if Parent_Node = Empty
7381 or else Nkind (Parent_Node) /= N_Compilation_Unit
7382 or else Context_Items (Parent_Node) /= Plist
7383 then
7384 return False;
7385 end if;
7386 end if;
7387
7388 return True;
7389 end Is_In_Context_Clause;
7390
7391 ---------------------------------
7392 -- Is_Static_String_Expression --
7393 ---------------------------------
7394
7395 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
7396 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
7397 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
7398
7399 begin
7400 Analyze_And_Resolve (Argx);
7401
7402 -- Special case Ada 83, where the expression will never be static,
7403 -- but we will return true if we had a string literal to start with.
7404
7405 if Ada_Version = Ada_83 then
7406 return Lit;
7407
7408 -- Normal case, true only if we end up with a string literal that
7409 -- is marked as being the result of evaluating a static expression.
7410
7411 else
7412 return Is_OK_Static_Expression (Argx)
7413 and then Nkind (Argx) = N_String_Literal;
7414 end if;
7415
7416 end Is_Static_String_Expression;
7417
7418 ----------------------
7419 -- Pragma_Misplaced --
7420 ----------------------
7421
7422 procedure Pragma_Misplaced is
7423 begin
7424 Error_Pragma ("incorrect placement of pragma%");
7425 end Pragma_Misplaced;
7426
7427 ------------------------------------------------
7428 -- Process_Atomic_Independent_Shared_Volatile --
7429 ------------------------------------------------
7430
7431 procedure Process_Atomic_Independent_Shared_Volatile is
7432 procedure Check_VFA_Conflicts (Ent : Entity_Id);
7433 -- Check that Volatile_Full_Access and VFA do not conflict
7434
7435 procedure Mark_Component_Or_Object (Ent : Entity_Id);
7436 -- Appropriately set flags on the given entity, either an array or
7437 -- record component, or an object declaration) according to the
7438 -- current pragma.
7439
7440 procedure Mark_Type (Ent : Entity_Id);
7441 -- Appropriately set flags on the given entity, a type
7442
7443 procedure Set_Atomic_VFA (Ent : Entity_Id);
7444 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
7445 -- no explicit alignment was given, set alignment to unknown, since
7446 -- back end knows what the alignment requirements are for atomic and
7447 -- full access arrays. Note: this is necessary for derived types.
7448
7449 -------------------------
7450 -- Check_VFA_Conflicts --
7451 -------------------------
7452
7453 procedure Check_VFA_Conflicts (Ent : Entity_Id) is
7454 Comp : Entity_Id;
7455 Typ : Entity_Id;
7456
7457 VFA_And_Atomic : Boolean := False;
7458 -- Set True if both VFA and Atomic present
7459
7460 begin
7461 -- Fetch the type in case we are dealing with an object or
7462 -- component.
7463
7464 if Is_Type (Ent) then
7465 Typ := Ent;
7466 else
7467 pragma Assert (Is_Object (Ent)
7468 or else
7469 Nkind (Declaration_Node (Ent)) = N_Component_Declaration);
7470
7471 Typ := Etype (Ent);
7472 end if;
7473
7474 -- Check Atomic and VFA used together
7475
7476 if Prag_Id = Pragma_Volatile_Full_Access
7477 or else Is_Volatile_Full_Access (Ent)
7478 then
7479 if Prag_Id = Pragma_Atomic
7480 or else Prag_Id = Pragma_Shared
7481 or else Is_Atomic (Ent)
7482 then
7483 VFA_And_Atomic := True;
7484
7485 elsif Is_Array_Type (Typ) then
7486 VFA_And_Atomic := Has_Atomic_Components (Typ);
7487
7488 -- Note: Has_Atomic_Components is not used below, as this flag
7489 -- represents the pragma of the same name, Atomic_Components,
7490 -- which only applies to arrays.
7491
7492 elsif Is_Record_Type (Typ) then
7493 -- Attributes cannot be applied to discriminants, only
7494 -- regular record components.
7495
7496 Comp := First_Component (Typ);
7497 while Present (Comp) loop
7498 if Is_Atomic (Comp)
7499 or else Is_Atomic (Typ)
7500 then
7501 VFA_And_Atomic := True;
7502
7503 exit;
7504 end if;
7505
7506 Next_Component (Comp);
7507 end loop;
7508 end if;
7509
7510 if VFA_And_Atomic then
7511 Error_Pragma
7512 ("cannot have Volatile_Full_Access and Atomic for same "
7513 & "entity");
7514 end if;
7515 end if;
7516 end Check_VFA_Conflicts;
7517
7518 ------------------------------
7519 -- Mark_Component_Or_Object --
7520 ------------------------------
7521
7522 procedure Mark_Component_Or_Object (Ent : Entity_Id) is
7523 begin
7524 if Prag_Id = Pragma_Atomic
7525 or else Prag_Id = Pragma_Shared
7526 or else Prag_Id = Pragma_Volatile_Full_Access
7527 then
7528 if Prag_Id = Pragma_Volatile_Full_Access then
7529 Set_Is_Volatile_Full_Access (Ent);
7530 else
7531 Set_Is_Atomic (Ent);
7532 end if;
7533
7534 -- If the object declaration has an explicit initialization, a
7535 -- temporary may have to be created to hold the expression, to
7536 -- ensure that access to the object remains atomic.
7537
7538 if Nkind (Parent (Ent)) = N_Object_Declaration
7539 and then Present (Expression (Parent (Ent)))
7540 then
7541 Set_Has_Delayed_Freeze (Ent);
7542 end if;
7543 end if;
7544
7545 -- Atomic/Shared/Volatile_Full_Access imply Independent
7546
7547 if Prag_Id /= Pragma_Volatile then
7548 Set_Is_Independent (Ent);
7549
7550 if Prag_Id = Pragma_Independent then
7551 Record_Independence_Check (N, Ent);
7552 end if;
7553 end if;
7554
7555 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7556
7557 if Prag_Id /= Pragma_Independent then
7558 Set_Is_Volatile (Ent);
7559 Set_Treat_As_Volatile (Ent);
7560 end if;
7561 end Mark_Component_Or_Object;
7562
7563 ---------------
7564 -- Mark_Type --
7565 ---------------
7566
7567 procedure Mark_Type (Ent : Entity_Id) is
7568 begin
7569 -- Attribute belongs on the base type. If the view of the type is
7570 -- currently private, it also belongs on the underlying type.
7571
7572 -- In Ada_2020, the pragma can apply to a formal type, for which
7573 -- there may be no underlying type.
7574
7575 if Prag_Id = Pragma_Atomic
7576 or else Prag_Id = Pragma_Shared
7577 or else Prag_Id = Pragma_Volatile_Full_Access
7578 then
7579 Set_Atomic_VFA (Ent);
7580 Set_Atomic_VFA (Base_Type (Ent));
7581
7582 if not Is_Generic_Type (Ent) then
7583 Set_Atomic_VFA (Underlying_Type (Ent));
7584 end if;
7585 end if;
7586
7587 -- Atomic/Shared/Volatile_Full_Access imply Independent
7588
7589 if Prag_Id /= Pragma_Volatile then
7590 Set_Is_Independent (Ent);
7591 Set_Is_Independent (Base_Type (Ent));
7592
7593 if not Is_Generic_Type (Ent) then
7594 Set_Is_Independent (Underlying_Type (Ent));
7595
7596 if Prag_Id = Pragma_Independent then
7597 Record_Independence_Check (N, Base_Type (Ent));
7598 end if;
7599 end if;
7600 end if;
7601
7602 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7603
7604 if Prag_Id /= Pragma_Independent then
7605 Set_Is_Volatile (Ent);
7606 Set_Is_Volatile (Base_Type (Ent));
7607
7608 if not Is_Generic_Type (Ent) then
7609 Set_Is_Volatile (Underlying_Type (Ent));
7610 Set_Treat_As_Volatile (Underlying_Type (Ent));
7611 end if;
7612
7613 Set_Treat_As_Volatile (Ent);
7614 end if;
7615
7616 -- Apply Volatile to the composite type's individual components,
7617 -- (RM C.6(8/3)).
7618
7619 if Prag_Id = Pragma_Volatile
7620 and then Is_Record_Type (Etype (Ent))
7621 then
7622 declare
7623 Comp : Entity_Id;
7624 begin
7625 Comp := First_Component (Ent);
7626 while Present (Comp) loop
7627 Mark_Component_Or_Object (Comp);
7628
7629 Next_Component (Comp);
7630 end loop;
7631 end;
7632 end if;
7633 end Mark_Type;
7634
7635 --------------------
7636 -- Set_Atomic_VFA --
7637 --------------------
7638
7639 procedure Set_Atomic_VFA (Ent : Entity_Id) is
7640 begin
7641 if Prag_Id = Pragma_Volatile_Full_Access then
7642 Set_Is_Volatile_Full_Access (Ent);
7643 else
7644 Set_Is_Atomic (Ent);
7645 end if;
7646
7647 if not Has_Alignment_Clause (Ent) then
7648 Set_Alignment (Ent, Uint_0);
7649 end if;
7650 end Set_Atomic_VFA;
7651
7652 -- Local variables
7653
7654 Decl : Node_Id;
7655 E : Entity_Id;
7656 E_Arg : Node_Id;
7657
7658 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
7659
7660 begin
7661 Check_Ada_83_Warning;
7662 Check_No_Identifiers;
7663 Check_Arg_Count (1);
7664 Check_Arg_Is_Local_Name (Arg1);
7665 E_Arg := Get_Pragma_Arg (Arg1);
7666
7667 if Etype (E_Arg) = Any_Type then
7668 return;
7669 end if;
7670
7671 E := Entity (E_Arg);
7672
7673 -- A pragma that applies to a Ghost entity becomes Ghost for the
7674 -- purposes of legality checks and removal of ignored Ghost code.
7675
7676 Mark_Ghost_Pragma (N, E);
7677
7678 -- Check duplicate before we chain ourselves
7679
7680 Check_Duplicate_Pragma (E);
7681
7682 -- Check appropriateness of the entity
7683
7684 Decl := Declaration_Node (E);
7685
7686 -- Deal with the case where the pragma/attribute is applied to a type
7687
7688 if Is_Type (E) then
7689 if Rep_Item_Too_Early (E, N)
7690 or else Rep_Item_Too_Late (E, N)
7691 then
7692 return;
7693 else
7694 Check_First_Subtype (Arg1);
7695 end if;
7696
7697 Mark_Type (E);
7698
7699 -- Deal with the case where the pragma/attribute applies to a
7700 -- component or object declaration.
7701
7702 elsif Nkind (Decl) = N_Object_Declaration
7703 or else (Nkind (Decl) = N_Component_Declaration
7704 and then Original_Record_Component (E) = E)
7705 then
7706 if Rep_Item_Too_Late (E, N) then
7707 return;
7708 end if;
7709
7710 Mark_Component_Or_Object (E);
7711
7712 -- In other cases give an error
7713
7714 else
7715 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7716 end if;
7717
7718 -- Check that Volatile_Full_Access and Atomic do not conflict
7719
7720 Check_VFA_Conflicts (E);
7721
7722 -- Check for the application of Atomic or Volatile_Full_Access to
7723 -- an entity that has [nonatomic] aliased, or else specified to be
7724 -- independently addressable, subcomponents.
7725
7726 if (Prag_Id = Pragma_Atomic and then Ada_Version >= Ada_2020)
7727 or else Prag_Id = Pragma_Volatile_Full_Access
7728 then
7729 Check_Atomic_VFA (E, VFA => Prag_Id = Pragma_Volatile_Full_Access);
7730 end if;
7731
7732 -- The following check is only relevant when SPARK_Mode is on as
7733 -- this is not a standard Ada legality rule. Pragma Volatile can
7734 -- only apply to a full type declaration or an object declaration
7735 -- (SPARK RM 7.1.3(2)). Original_Node is necessary to account for
7736 -- untagged derived types that are rewritten as subtypes of their
7737 -- respective root types.
7738
7739 if SPARK_Mode = On
7740 and then Prag_Id = Pragma_Volatile
7741 and then not Nkind_In (Original_Node (Decl),
7742 N_Full_Type_Declaration,
7743 N_Object_Declaration,
7744 N_Single_Protected_Declaration,
7745 N_Single_Task_Declaration)
7746 then
7747 Error_Pragma_Arg
7748 ("argument of pragma % must denote a full type or object "
7749 & "declaration", Arg1);
7750 end if;
7751 end Process_Atomic_Independent_Shared_Volatile;
7752
7753 -------------------------------------------
7754 -- Process_Compile_Time_Warning_Or_Error --
7755 -------------------------------------------
7756
7757 procedure Process_Compile_Time_Warning_Or_Error is
7758 P : Node_Id := Parent (N);
7759 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
7760
7761 begin
7762 Check_Arg_Count (2);
7763 Check_No_Identifiers;
7764 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
7765 Analyze_And_Resolve (Arg1x, Standard_Boolean);
7766
7767 -- In GNATprove mode, pragma Compile_Time_Error is translated as
7768 -- a Check pragma in GNATprove mode, handled as an assumption in
7769 -- GNATprove. This is correct as the compiler will issue an error
7770 -- if the condition cannot be statically evaluated to False.
7771 -- Compile_Time_Warning are ignored, as the analyzer may not have the
7772 -- same information as the compiler (in particular regarding size of
7773 -- objects decided in gigi) so it makes no sense to issue a warning
7774 -- in GNATprove.
7775
7776 if GNATprove_Mode then
7777 if Prag_Id = Pragma_Compile_Time_Error then
7778 declare
7779 New_Args : List_Id;
7780 begin
7781 -- Implement Compile_Time_Error by generating
7782 -- a corresponding Check pragma:
7783
7784 -- pragma Check (name, condition);
7785
7786 -- where name is the identifier matching the pragma name. So
7787 -- rewrite pragma in this manner and analyze the result.
7788
7789 New_Args := New_List
7790 (Make_Pragma_Argument_Association
7791 (Loc,
7792 Expression => Make_Identifier (Loc, Pname)),
7793 Make_Pragma_Argument_Association
7794 (Sloc (Arg1x),
7795 Expression => Arg1x));
7796
7797 -- Rewrite as Check pragma
7798
7799 Rewrite (N,
7800 Make_Pragma (Loc,
7801 Chars => Name_Check,
7802 Pragma_Argument_Associations => New_Args));
7803
7804 Analyze (N);
7805 end;
7806
7807 else
7808 Rewrite (N, Make_Null_Statement (Loc));
7809 end if;
7810
7811 return;
7812 end if;
7813
7814 -- If the condition is known at compile time (now), validate it now.
7815 -- Otherwise, register the expression for validation after the back
7816 -- end has been called, because it might be known at compile time
7817 -- then. For example, if the expression is "Record_Type'Size /= 32"
7818 -- it might be known after the back end has determined the size of
7819 -- Record_Type. We do not defer validation if we're inside a generic
7820 -- unit, because we will have more information in the instances.
7821
7822 if Compile_Time_Known_Value (Arg1x) then
7823 Validate_Compile_Time_Warning_Or_Error (N, Sloc (Arg1));
7824 else
7825 while Present (P) and then Nkind (P) not in N_Generic_Declaration
7826 loop
7827 if Nkind_In (P, N_Package_Body, N_Subprogram_Body) then
7828 P := Corresponding_Spec (P);
7829 else
7830 P := Parent (P);
7831 end if;
7832 end loop;
7833
7834 if No (P) then
7835 Defer_Compile_Time_Warning_Error_To_BE (N);
7836 end if;
7837 end if;
7838 end Process_Compile_Time_Warning_Or_Error;
7839
7840 ------------------------
7841 -- Process_Convention --
7842 ------------------------
7843
7844 procedure Process_Convention
7845 (C : out Convention_Id;
7846 Ent : out Entity_Id)
7847 is
7848 Cname : Name_Id;
7849
7850 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
7851 -- Called if we have more than one Export/Import/Convention pragma.
7852 -- This is generally illegal, but we have a special case of allowing
7853 -- Import and Interface to coexist if they specify the convention in
7854 -- a consistent manner. We are allowed to do this, since Interface is
7855 -- an implementation defined pragma, and we choose to do it since we
7856 -- know Rational allows this combination. S is the entity id of the
7857 -- subprogram in question. This procedure also sets the special flag
7858 -- Import_Interface_Present in both pragmas in the case where we do
7859 -- have matching Import and Interface pragmas.
7860
7861 procedure Set_Convention_From_Pragma (E : Entity_Id);
7862 -- Set convention in entity E, and also flag that the entity has a
7863 -- convention pragma. If entity is for a private or incomplete type,
7864 -- also set convention and flag on underlying type. This procedure
7865 -- also deals with the special case of C_Pass_By_Copy convention,
7866 -- and error checks for inappropriate convention specification.
7867
7868 -------------------------------
7869 -- Diagnose_Multiple_Pragmas --
7870 -------------------------------
7871
7872 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
7873 Pdec : constant Node_Id := Declaration_Node (S);
7874 Decl : Node_Id;
7875 Err : Boolean;
7876
7877 function Same_Convention (Decl : Node_Id) return Boolean;
7878 -- Decl is a pragma node. This function returns True if this
7879 -- pragma has a first argument that is an identifier with a
7880 -- Chars field corresponding to the Convention_Id C.
7881
7882 function Same_Name (Decl : Node_Id) return Boolean;
7883 -- Decl is a pragma node. This function returns True if this
7884 -- pragma has a second argument that is an identifier with a
7885 -- Chars field that matches the Chars of the current subprogram.
7886
7887 ---------------------
7888 -- Same_Convention --
7889 ---------------------
7890
7891 function Same_Convention (Decl : Node_Id) return Boolean is
7892 Arg1 : constant Node_Id :=
7893 First (Pragma_Argument_Associations (Decl));
7894
7895 begin
7896 if Present (Arg1) then
7897 declare
7898 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
7899 begin
7900 if Nkind (Arg) = N_Identifier
7901 and then Is_Convention_Name (Chars (Arg))
7902 and then Get_Convention_Id (Chars (Arg)) = C
7903 then
7904 return True;
7905 end if;
7906 end;
7907 end if;
7908
7909 return False;
7910 end Same_Convention;
7911
7912 ---------------
7913 -- Same_Name --
7914 ---------------
7915
7916 function Same_Name (Decl : Node_Id) return Boolean is
7917 Arg1 : constant Node_Id :=
7918 First (Pragma_Argument_Associations (Decl));
7919 Arg2 : Node_Id;
7920
7921 begin
7922 if No (Arg1) then
7923 return False;
7924 end if;
7925
7926 Arg2 := Next (Arg1);
7927
7928 if No (Arg2) then
7929 return False;
7930 end if;
7931
7932 declare
7933 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
7934 begin
7935 if Nkind (Arg) = N_Identifier
7936 and then Chars (Arg) = Chars (S)
7937 then
7938 return True;
7939 end if;
7940 end;
7941
7942 return False;
7943 end Same_Name;
7944
7945 -- Start of processing for Diagnose_Multiple_Pragmas
7946
7947 begin
7948 Err := True;
7949
7950 -- Definitely give message if we have Convention/Export here
7951
7952 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
7953 null;
7954
7955 -- If we have an Import or Export, scan back from pragma to
7956 -- find any previous pragma applying to the same procedure.
7957 -- The scan will be terminated by the start of the list, or
7958 -- hitting the subprogram declaration. This won't allow one
7959 -- pragma to appear in the public part and one in the private
7960 -- part, but that seems very unlikely in practice.
7961
7962 else
7963 Decl := Prev (N);
7964 while Present (Decl) and then Decl /= Pdec loop
7965
7966 -- Look for pragma with same name as us
7967
7968 if Nkind (Decl) = N_Pragma
7969 and then Same_Name (Decl)
7970 then
7971 -- Give error if same as our pragma or Export/Convention
7972
7973 if Nam_In (Pragma_Name_Unmapped (Decl),
7974 Name_Export,
7975 Name_Convention,
7976 Pragma_Name_Unmapped (N))
7977 then
7978 exit;
7979
7980 -- Case of Import/Interface or the other way round
7981
7982 elsif Nam_In (Pragma_Name_Unmapped (Decl),
7983 Name_Interface, Name_Import)
7984 then
7985 -- Here we know that we have Import and Interface. It
7986 -- doesn't matter which way round they are. See if
7987 -- they specify the same convention. If so, all OK,
7988 -- and set special flags to stop other messages
7989
7990 if Same_Convention (Decl) then
7991 Set_Import_Interface_Present (N);
7992 Set_Import_Interface_Present (Decl);
7993 Err := False;
7994
7995 -- If different conventions, special message
7996
7997 else
7998 Error_Msg_Sloc := Sloc (Decl);
7999 Error_Pragma_Arg
8000 ("convention differs from that given#", Arg1);
8001 return;
8002 end if;
8003 end if;
8004 end if;
8005
8006 Next (Decl);
8007 end loop;
8008 end if;
8009
8010 -- Give message if needed if we fall through those tests
8011 -- except on Relaxed_RM_Semantics where we let go: either this
8012 -- is a case accepted/ignored by other Ada compilers (e.g.
8013 -- a mix of Convention and Import), or another error will be
8014 -- generated later (e.g. using both Import and Export).
8015
8016 if Err and not Relaxed_RM_Semantics then
8017 Error_Pragma_Arg
8018 ("at most one Convention/Export/Import pragma is allowed",
8019 Arg2);
8020 end if;
8021 end Diagnose_Multiple_Pragmas;
8022
8023 --------------------------------
8024 -- Set_Convention_From_Pragma --
8025 --------------------------------
8026
8027 procedure Set_Convention_From_Pragma (E : Entity_Id) is
8028 begin
8029 -- Ada 2005 (AI-430): Check invalid attempt to change convention
8030 -- for an overridden dispatching operation. Technically this is
8031 -- an amendment and should only be done in Ada 2005 mode. However,
8032 -- this is clearly a mistake, since the problem that is addressed
8033 -- by this AI is that there is a clear gap in the RM.
8034
8035 if Is_Dispatching_Operation (E)
8036 and then Present (Overridden_Operation (E))
8037 and then C /= Convention (Overridden_Operation (E))
8038 then
8039 Error_Pragma_Arg
8040 ("cannot change convention for overridden dispatching "
8041 & "operation", Arg1);
8042 end if;
8043
8044 -- Special checks for Convention_Stdcall
8045
8046 if C = Convention_Stdcall then
8047
8048 -- A dispatching call is not allowed. A dispatching subprogram
8049 -- cannot be used to interface to the Win32 API, so in fact
8050 -- this check does not impose any effective restriction.
8051
8052 if Is_Dispatching_Operation (E) then
8053 Error_Msg_Sloc := Sloc (E);
8054
8055 -- Note: make this unconditional so that if there is more
8056 -- than one call to which the pragma applies, we get a
8057 -- message for each call. Also don't use Error_Pragma,
8058 -- so that we get multiple messages.
8059
8060 Error_Msg_N
8061 ("dispatching subprogram# cannot use Stdcall convention!",
8062 Arg1);
8063
8064 -- Several allowed cases
8065
8066 elsif Is_Subprogram_Or_Generic_Subprogram (E)
8067
8068 -- A variable is OK
8069
8070 or else Ekind (E) = E_Variable
8071
8072 -- A component as well. The entity does not have its Ekind
8073 -- set until the enclosing record declaration is fully
8074 -- analyzed.
8075
8076 or else Nkind (Parent (E)) = N_Component_Declaration
8077
8078 -- An access to subprogram is also allowed
8079
8080 or else
8081 (Is_Access_Type (E)
8082 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
8083
8084 -- Allow internal call to set convention of subprogram type
8085
8086 or else Ekind (E) = E_Subprogram_Type
8087 then
8088 null;
8089
8090 else
8091 Error_Pragma_Arg
8092 ("second argument of pragma% must be subprogram (type)",
8093 Arg2);
8094 end if;
8095 end if;
8096
8097 -- Set the convention
8098
8099 Set_Convention (E, C);
8100 Set_Has_Convention_Pragma (E);
8101
8102 -- For the case of a record base type, also set the convention of
8103 -- any anonymous access types declared in the record which do not
8104 -- currently have a specified convention.
8105
8106 if Is_Record_Type (E) and then Is_Base_Type (E) then
8107 declare
8108 Comp : Node_Id;
8109
8110 begin
8111 Comp := First_Component (E);
8112 while Present (Comp) loop
8113 if Present (Etype (Comp))
8114 and then Ekind_In (Etype (Comp),
8115 E_Anonymous_Access_Type,
8116 E_Anonymous_Access_Subprogram_Type)
8117 and then not Has_Convention_Pragma (Comp)
8118 then
8119 Set_Convention (Comp, C);
8120 end if;
8121
8122 Next_Component (Comp);
8123 end loop;
8124 end;
8125 end if;
8126
8127 -- Deal with incomplete/private type case, where underlying type
8128 -- is available, so set convention of that underlying type.
8129
8130 if Is_Incomplete_Or_Private_Type (E)
8131 and then Present (Underlying_Type (E))
8132 then
8133 Set_Convention (Underlying_Type (E), C);
8134 Set_Has_Convention_Pragma (Underlying_Type (E), True);
8135 end if;
8136
8137 -- A class-wide type should inherit the convention of the specific
8138 -- root type (although this isn't specified clearly by the RM).
8139
8140 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
8141 Set_Convention (Class_Wide_Type (E), C);
8142 end if;
8143
8144 -- If the entity is a record type, then check for special case of
8145 -- C_Pass_By_Copy, which is treated the same as C except that the
8146 -- special record flag is set. This convention is only permitted
8147 -- on record types (see AI95-00131).
8148
8149 if Cname = Name_C_Pass_By_Copy then
8150 if Is_Record_Type (E) then
8151 Set_C_Pass_By_Copy (Base_Type (E));
8152 elsif Is_Incomplete_Or_Private_Type (E)
8153 and then Is_Record_Type (Underlying_Type (E))
8154 then
8155 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
8156 else
8157 Error_Pragma_Arg
8158 ("C_Pass_By_Copy convention allowed only for record type",
8159 Arg2);
8160 end if;
8161 end if;
8162
8163 -- If the entity is a derived boolean type, check for the special
8164 -- case of convention C, C++, or Fortran, where we consider any
8165 -- nonzero value to represent true.
8166
8167 if Is_Discrete_Type (E)
8168 and then Root_Type (Etype (E)) = Standard_Boolean
8169 and then
8170 (C = Convention_C
8171 or else
8172 C = Convention_CPP
8173 or else
8174 C = Convention_Fortran)
8175 then
8176 Set_Nonzero_Is_True (Base_Type (E));
8177 end if;
8178 end Set_Convention_From_Pragma;
8179
8180 -- Local variables
8181
8182 Comp_Unit : Unit_Number_Type;
8183 E : Entity_Id;
8184 E1 : Entity_Id;
8185 Id : Node_Id;
8186
8187 -- Start of processing for Process_Convention
8188
8189 begin
8190 Check_At_Least_N_Arguments (2);
8191 Check_Optional_Identifier (Arg1, Name_Convention);
8192 Check_Arg_Is_Identifier (Arg1);
8193 Cname := Chars (Get_Pragma_Arg (Arg1));
8194
8195 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
8196 -- tested again below to set the critical flag).
8197
8198 if Cname = Name_C_Pass_By_Copy then
8199 C := Convention_C;
8200
8201 -- Otherwise we must have something in the standard convention list
8202
8203 elsif Is_Convention_Name (Cname) then
8204 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
8205
8206 -- Otherwise warn on unrecognized convention
8207
8208 else
8209 if Warn_On_Export_Import then
8210 Error_Msg_N
8211 ("??unrecognized convention name, C assumed",
8212 Get_Pragma_Arg (Arg1));
8213 end if;
8214
8215 C := Convention_C;
8216 end if;
8217
8218 Check_Optional_Identifier (Arg2, Name_Entity);
8219 Check_Arg_Is_Local_Name (Arg2);
8220
8221 Id := Get_Pragma_Arg (Arg2);
8222 Analyze (Id);
8223
8224 if not Is_Entity_Name (Id) then
8225 Error_Pragma_Arg ("entity name required", Arg2);
8226 end if;
8227
8228 E := Entity (Id);
8229
8230 -- Set entity to return
8231
8232 Ent := E;
8233
8234 -- Ada_Pass_By_Copy special checking
8235
8236 if C = Convention_Ada_Pass_By_Copy then
8237 if not Is_First_Subtype (E) then
8238 Error_Pragma_Arg
8239 ("convention `Ada_Pass_By_Copy` only allowed for types",
8240 Arg2);
8241 end if;
8242
8243 if Is_By_Reference_Type (E) then
8244 Error_Pragma_Arg
8245 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
8246 & "type", Arg1);
8247 end if;
8248
8249 -- Ada_Pass_By_Reference special checking
8250
8251 elsif C = Convention_Ada_Pass_By_Reference then
8252 if not Is_First_Subtype (E) then
8253 Error_Pragma_Arg
8254 ("convention `Ada_Pass_By_Reference` only allowed for types",
8255 Arg2);
8256 end if;
8257
8258 if Is_By_Copy_Type (E) then
8259 Error_Pragma_Arg
8260 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
8261 & "type", Arg1);
8262 end if;
8263 end if;
8264
8265 -- Go to renamed subprogram if present, since convention applies to
8266 -- the actual renamed entity, not to the renaming entity. If the
8267 -- subprogram is inherited, go to parent subprogram.
8268
8269 if Is_Subprogram (E)
8270 and then Present (Alias (E))
8271 then
8272 if Nkind (Parent (Declaration_Node (E))) =
8273 N_Subprogram_Renaming_Declaration
8274 then
8275 if Scope (E) /= Scope (Alias (E)) then
8276 Error_Pragma_Ref
8277 ("cannot apply pragma% to non-local entity&#", E);
8278 end if;
8279
8280 E := Alias (E);
8281
8282 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
8283 N_Private_Extension_Declaration)
8284 and then Scope (E) = Scope (Alias (E))
8285 then
8286 E := Alias (E);
8287
8288 -- Return the parent subprogram the entity was inherited from
8289
8290 Ent := E;
8291 end if;
8292 end if;
8293
8294 -- Check that we are not applying this to a specless body. Relax this
8295 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
8296
8297 if Is_Subprogram (E)
8298 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
8299 and then not Relaxed_RM_Semantics
8300 then
8301 Error_Pragma
8302 ("pragma% requires separate spec and must come before body");
8303 end if;
8304
8305 -- Check that we are not applying this to a named constant
8306
8307 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
8308 Error_Msg_Name_1 := Pname;
8309 Error_Msg_N
8310 ("cannot apply pragma% to named constant!",
8311 Get_Pragma_Arg (Arg2));
8312 Error_Pragma_Arg
8313 ("\supply appropriate type for&!", Arg2);
8314 end if;
8315
8316 if Ekind (E) = E_Enumeration_Literal then
8317 Error_Pragma ("enumeration literal not allowed for pragma%");
8318 end if;
8319
8320 -- Check for rep item appearing too early or too late
8321
8322 if Etype (E) = Any_Type
8323 or else Rep_Item_Too_Early (E, N)
8324 then
8325 raise Pragma_Exit;
8326
8327 elsif Present (Underlying_Type (E)) then
8328 E := Underlying_Type (E);
8329 end if;
8330
8331 if Rep_Item_Too_Late (E, N) then
8332 raise Pragma_Exit;
8333 end if;
8334
8335 if Has_Convention_Pragma (E) then
8336 Diagnose_Multiple_Pragmas (E);
8337
8338 elsif Convention (E) = Convention_Protected
8339 or else Ekind (Scope (E)) = E_Protected_Type
8340 then
8341 Error_Pragma_Arg
8342 ("a protected operation cannot be given a different convention",
8343 Arg2);
8344 end if;
8345
8346 -- For Intrinsic, a subprogram is required
8347
8348 if C = Convention_Intrinsic
8349 and then not Is_Subprogram_Or_Generic_Subprogram (E)
8350 then
8351 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
8352
8353 if not (Is_Type (E) and then Relaxed_RM_Semantics) then
8354 Error_Pragma_Arg
8355 ("second argument of pragma% must be a subprogram", Arg2);
8356 end if;
8357 end if;
8358
8359 -- Deal with non-subprogram cases
8360
8361 if not Is_Subprogram_Or_Generic_Subprogram (E) then
8362 Set_Convention_From_Pragma (E);
8363
8364 if Is_Type (E) then
8365
8366 -- The pragma must apply to a first subtype, but it can also
8367 -- apply to a generic type in a generic formal part, in which
8368 -- case it will also appear in the corresponding instance.
8369
8370 if Is_Generic_Type (E) or else In_Instance then
8371 null;
8372 else
8373 Check_First_Subtype (Arg2);
8374 end if;
8375
8376 Set_Convention_From_Pragma (Base_Type (E));
8377
8378 -- For access subprograms, we must set the convention on the
8379 -- internally generated directly designated type as well.
8380
8381 if Ekind (E) = E_Access_Subprogram_Type then
8382 Set_Convention_From_Pragma (Directly_Designated_Type (E));
8383 end if;
8384 end if;
8385
8386 -- For the subprogram case, set proper convention for all homonyms
8387 -- in same scope and the same declarative part, i.e. the same
8388 -- compilation unit.
8389
8390 else
8391 Comp_Unit := Get_Source_Unit (E);
8392 Set_Convention_From_Pragma (E);
8393
8394 -- Treat a pragma Import as an implicit body, and pragma import
8395 -- as implicit reference (for navigation in GNAT Studio).
8396
8397 if Prag_Id = Pragma_Import then
8398 Generate_Reference (E, Id, 'b');
8399
8400 -- For exported entities we restrict the generation of references
8401 -- to entities exported to foreign languages since entities
8402 -- exported to Ada do not provide further information to
8403 -- GNAT Studio and add undesired references to the output of the
8404 -- gnatxref tool.
8405
8406 elsif Prag_Id = Pragma_Export
8407 and then Convention (E) /= Convention_Ada
8408 then
8409 Generate_Reference (E, Id, 'i');
8410 end if;
8411
8412 -- If the pragma comes from an aspect, it only applies to the
8413 -- given entity, not its homonyms.
8414
8415 if From_Aspect_Specification (N) then
8416 if C = Convention_Intrinsic
8417 and then Nkind (Ent) = N_Defining_Operator_Symbol
8418 then
8419 if Is_Fixed_Point_Type (Etype (Ent))
8420 or else Is_Fixed_Point_Type (Etype (First_Entity (Ent)))
8421 or else Is_Fixed_Point_Type (Etype (Last_Entity (Ent)))
8422 then
8423 Error_Msg_N
8424 ("no intrinsic operator available for this fixed-point "
8425 & "operation", N);
8426 Error_Msg_N
8427 ("\use expression functions with the desired "
8428 & "conversions made explicit", N);
8429 end if;
8430 end if;
8431
8432 return;
8433 end if;
8434
8435 -- Otherwise Loop through the homonyms of the pragma argument's
8436 -- entity, an apply convention to those in the current scope.
8437
8438 E1 := Ent;
8439
8440 loop
8441 E1 := Homonym (E1);
8442 exit when No (E1) or else Scope (E1) /= Current_Scope;
8443
8444 -- Ignore entry for which convention is already set
8445
8446 if Has_Convention_Pragma (E1) then
8447 goto Continue;
8448 end if;
8449
8450 if Is_Subprogram (E1)
8451 and then Nkind (Parent (Declaration_Node (E1))) =
8452 N_Subprogram_Body
8453 and then not Relaxed_RM_Semantics
8454 then
8455 Set_Has_Completion (E); -- to prevent cascaded error
8456 Error_Pragma_Ref
8457 ("pragma% requires separate spec and must come before "
8458 & "body#", E1);
8459 end if;
8460
8461 -- Do not set the pragma on inherited operations or on formal
8462 -- subprograms.
8463
8464 if Comes_From_Source (E1)
8465 and then Comp_Unit = Get_Source_Unit (E1)
8466 and then not Is_Formal_Subprogram (E1)
8467 and then Nkind (Original_Node (Parent (E1))) /=
8468 N_Full_Type_Declaration
8469 then
8470 if Present (Alias (E1))
8471 and then Scope (E1) /= Scope (Alias (E1))
8472 then
8473 Error_Pragma_Ref
8474 ("cannot apply pragma% to non-local entity& declared#",
8475 E1);
8476 end if;
8477
8478 Set_Convention_From_Pragma (E1);
8479
8480 if Prag_Id = Pragma_Import then
8481 Generate_Reference (E1, Id, 'b');
8482 end if;
8483 end if;
8484
8485 <<Continue>>
8486 null;
8487 end loop;
8488 end if;
8489 end Process_Convention;
8490
8491 ----------------------------------------
8492 -- Process_Disable_Enable_Atomic_Sync --
8493 ----------------------------------------
8494
8495 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
8496 begin
8497 Check_No_Identifiers;
8498 Check_At_Most_N_Arguments (1);
8499
8500 -- Modeled internally as
8501 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
8502
8503 Rewrite (N,
8504 Make_Pragma (Loc,
8505 Chars => Nam,
8506 Pragma_Argument_Associations => New_List (
8507 Make_Pragma_Argument_Association (Loc,
8508 Expression =>
8509 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
8510
8511 if Present (Arg1) then
8512 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
8513 end if;
8514
8515 Analyze (N);
8516 end Process_Disable_Enable_Atomic_Sync;
8517
8518 -------------------------------------------------
8519 -- Process_Extended_Import_Export_Internal_Arg --
8520 -------------------------------------------------
8521
8522 procedure Process_Extended_Import_Export_Internal_Arg
8523 (Arg_Internal : Node_Id := Empty)
8524 is
8525 begin
8526 if No (Arg_Internal) then
8527 Error_Pragma ("Internal parameter required for pragma%");
8528 end if;
8529
8530 if Nkind (Arg_Internal) = N_Identifier then
8531 null;
8532
8533 elsif Nkind (Arg_Internal) = N_Operator_Symbol
8534 and then (Prag_Id = Pragma_Import_Function
8535 or else
8536 Prag_Id = Pragma_Export_Function)
8537 then
8538 null;
8539
8540 else
8541 Error_Pragma_Arg
8542 ("wrong form for Internal parameter for pragma%", Arg_Internal);
8543 end if;
8544
8545 Check_Arg_Is_Local_Name (Arg_Internal);
8546 end Process_Extended_Import_Export_Internal_Arg;
8547
8548 --------------------------------------------------
8549 -- Process_Extended_Import_Export_Object_Pragma --
8550 --------------------------------------------------
8551
8552 procedure Process_Extended_Import_Export_Object_Pragma
8553 (Arg_Internal : Node_Id;
8554 Arg_External : Node_Id;
8555 Arg_Size : Node_Id)
8556 is
8557 Def_Id : Entity_Id;
8558
8559 begin
8560 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8561 Def_Id := Entity (Arg_Internal);
8562
8563 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
8564 Error_Pragma_Arg
8565 ("pragma% must designate an object", Arg_Internal);
8566 end if;
8567
8568 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
8569 or else
8570 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
8571 then
8572 Error_Pragma_Arg
8573 ("previous Common/Psect_Object applies, pragma % not permitted",
8574 Arg_Internal);
8575 end if;
8576
8577 if Rep_Item_Too_Late (Def_Id, N) then
8578 raise Pragma_Exit;
8579 end if;
8580
8581 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
8582
8583 if Present (Arg_Size) then
8584 Check_Arg_Is_External_Name (Arg_Size);
8585 end if;
8586
8587 -- Export_Object case
8588
8589 if Prag_Id = Pragma_Export_Object then
8590 if not Is_Library_Level_Entity (Def_Id) then
8591 Error_Pragma_Arg
8592 ("argument for pragma% must be library level entity",
8593 Arg_Internal);
8594 end if;
8595
8596 if Ekind (Current_Scope) = E_Generic_Package then
8597 Error_Pragma ("pragma& cannot appear in a generic unit");
8598 end if;
8599
8600 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
8601 Error_Pragma_Arg
8602 ("exported object must have compile time known size",
8603 Arg_Internal);
8604 end if;
8605
8606 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
8607 Error_Msg_N ("??duplicate Export_Object pragma", N);
8608 else
8609 Set_Exported (Def_Id, Arg_Internal);
8610 end if;
8611
8612 -- Import_Object case
8613
8614 else
8615 if Is_Concurrent_Type (Etype (Def_Id)) then
8616 Error_Pragma_Arg
8617 ("cannot use pragma% for task/protected object",
8618 Arg_Internal);
8619 end if;
8620
8621 if Ekind (Def_Id) = E_Constant then
8622 Error_Pragma_Arg
8623 ("cannot import a constant", Arg_Internal);
8624 end if;
8625
8626 if Warn_On_Export_Import
8627 and then Has_Discriminants (Etype (Def_Id))
8628 then
8629 Error_Msg_N
8630 ("imported value must be initialized??", Arg_Internal);
8631 end if;
8632
8633 if Warn_On_Export_Import
8634 and then Is_Access_Type (Etype (Def_Id))
8635 then
8636 Error_Pragma_Arg
8637 ("cannot import object of an access type??", Arg_Internal);
8638 end if;
8639
8640 if Warn_On_Export_Import
8641 and then Is_Imported (Def_Id)
8642 then
8643 Error_Msg_N ("??duplicate Import_Object pragma", N);
8644
8645 -- Check for explicit initialization present. Note that an
8646 -- initialization generated by the code generator, e.g. for an
8647 -- access type, does not count here.
8648
8649 elsif Present (Expression (Parent (Def_Id)))
8650 and then
8651 Comes_From_Source
8652 (Original_Node (Expression (Parent (Def_Id))))
8653 then
8654 Error_Msg_Sloc := Sloc (Def_Id);
8655 Error_Pragma_Arg
8656 ("imported entities cannot be initialized (RM B.1(24))",
8657 "\no initialization allowed for & declared#", Arg1);
8658 else
8659 Set_Imported (Def_Id);
8660 Note_Possible_Modification (Arg_Internal, Sure => False);
8661 end if;
8662 end if;
8663 end Process_Extended_Import_Export_Object_Pragma;
8664
8665 ------------------------------------------------------
8666 -- Process_Extended_Import_Export_Subprogram_Pragma --
8667 ------------------------------------------------------
8668
8669 procedure Process_Extended_Import_Export_Subprogram_Pragma
8670 (Arg_Internal : Node_Id;
8671 Arg_External : Node_Id;
8672 Arg_Parameter_Types : Node_Id;
8673 Arg_Result_Type : Node_Id := Empty;
8674 Arg_Mechanism : Node_Id;
8675 Arg_Result_Mechanism : Node_Id := Empty)
8676 is
8677 Ent : Entity_Id;
8678 Def_Id : Entity_Id;
8679 Hom_Id : Entity_Id;
8680 Formal : Entity_Id;
8681 Ambiguous : Boolean;
8682 Match : Boolean;
8683
8684 function Same_Base_Type
8685 (Ptype : Node_Id;
8686 Formal : Entity_Id) return Boolean;
8687 -- Determines if Ptype references the type of Formal. Note that only
8688 -- the base types need to match according to the spec. Ptype here is
8689 -- the argument from the pragma, which is either a type name, or an
8690 -- access attribute.
8691
8692 --------------------
8693 -- Same_Base_Type --
8694 --------------------
8695
8696 function Same_Base_Type
8697 (Ptype : Node_Id;
8698 Formal : Entity_Id) return Boolean
8699 is
8700 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
8701 Pref : Node_Id;
8702
8703 begin
8704 -- Case where pragma argument is typ'Access
8705
8706 if Nkind (Ptype) = N_Attribute_Reference
8707 and then Attribute_Name (Ptype) = Name_Access
8708 then
8709 Pref := Prefix (Ptype);
8710 Find_Type (Pref);
8711
8712 if not Is_Entity_Name (Pref)
8713 or else Entity (Pref) = Any_Type
8714 then
8715 raise Pragma_Exit;
8716 end if;
8717
8718 -- We have a match if the corresponding argument is of an
8719 -- anonymous access type, and its designated type matches the
8720 -- type of the prefix of the access attribute
8721
8722 return Ekind (Ftyp) = E_Anonymous_Access_Type
8723 and then Base_Type (Entity (Pref)) =
8724 Base_Type (Etype (Designated_Type (Ftyp)));
8725
8726 -- Case where pragma argument is a type name
8727
8728 else
8729 Find_Type (Ptype);
8730
8731 if not Is_Entity_Name (Ptype)
8732 or else Entity (Ptype) = Any_Type
8733 then
8734 raise Pragma_Exit;
8735 end if;
8736
8737 -- We have a match if the corresponding argument is of the type
8738 -- given in the pragma (comparing base types)
8739
8740 return Base_Type (Entity (Ptype)) = Ftyp;
8741 end if;
8742 end Same_Base_Type;
8743
8744 -- Start of processing for
8745 -- Process_Extended_Import_Export_Subprogram_Pragma
8746
8747 begin
8748 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8749 Ent := Empty;
8750 Ambiguous := False;
8751
8752 -- Loop through homonyms (overloadings) of the entity
8753
8754 Hom_Id := Entity (Arg_Internal);
8755 while Present (Hom_Id) loop
8756 Def_Id := Get_Base_Subprogram (Hom_Id);
8757
8758 -- We need a subprogram in the current scope
8759
8760 if not Is_Subprogram (Def_Id)
8761 or else Scope (Def_Id) /= Current_Scope
8762 then
8763 null;
8764
8765 else
8766 Match := True;
8767
8768 -- Pragma cannot apply to subprogram body
8769
8770 if Is_Subprogram (Def_Id)
8771 and then Nkind (Parent (Declaration_Node (Def_Id))) =
8772 N_Subprogram_Body
8773 then
8774 Error_Pragma
8775 ("pragma% requires separate spec and must come before "
8776 & "body");
8777 end if;
8778
8779 -- Test result type if given, note that the result type
8780 -- parameter can only be present for the function cases.
8781
8782 if Present (Arg_Result_Type)
8783 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
8784 then
8785 Match := False;
8786
8787 elsif Etype (Def_Id) /= Standard_Void_Type
8788 and then Nam_In (Pname, Name_Export_Procedure,
8789 Name_Import_Procedure)
8790 then
8791 Match := False;
8792
8793 -- Test parameter types if given. Note that this parameter has
8794 -- not been analyzed (and must not be, since it is semantic
8795 -- nonsense), so we get it as the parser left it.
8796
8797 elsif Present (Arg_Parameter_Types) then
8798 Check_Matching_Types : declare
8799 Formal : Entity_Id;
8800 Ptype : Node_Id;
8801
8802 begin
8803 Formal := First_Formal (Def_Id);
8804
8805 if Nkind (Arg_Parameter_Types) = N_Null then
8806 if Present (Formal) then
8807 Match := False;
8808 end if;
8809
8810 -- A list of one type, e.g. (List) is parsed as a
8811 -- parenthesized expression.
8812
8813 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
8814 and then Paren_Count (Arg_Parameter_Types) = 1
8815 then
8816 if No (Formal)
8817 or else Present (Next_Formal (Formal))
8818 then
8819 Match := False;
8820 else
8821 Match :=
8822 Same_Base_Type (Arg_Parameter_Types, Formal);
8823 end if;
8824
8825 -- A list of more than one type is parsed as a aggregate
8826
8827 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
8828 and then Paren_Count (Arg_Parameter_Types) = 0
8829 then
8830 Ptype := First (Expressions (Arg_Parameter_Types));
8831 while Present (Ptype) or else Present (Formal) loop
8832 if No (Ptype)
8833 or else No (Formal)
8834 or else not Same_Base_Type (Ptype, Formal)
8835 then
8836 Match := False;
8837 exit;
8838 else
8839 Next_Formal (Formal);
8840 Next (Ptype);
8841 end if;
8842 end loop;
8843
8844 -- Anything else is of the wrong form
8845
8846 else
8847 Error_Pragma_Arg
8848 ("wrong form for Parameter_Types parameter",
8849 Arg_Parameter_Types);
8850 end if;
8851 end Check_Matching_Types;
8852 end if;
8853
8854 -- Match is now False if the entry we found did not match
8855 -- either a supplied Parameter_Types or Result_Types argument
8856
8857 if Match then
8858 if No (Ent) then
8859 Ent := Def_Id;
8860
8861 -- Ambiguous case, the flag Ambiguous shows if we already
8862 -- detected this and output the initial messages.
8863
8864 else
8865 if not Ambiguous then
8866 Ambiguous := True;
8867 Error_Msg_Name_1 := Pname;
8868 Error_Msg_N
8869 ("pragma% does not uniquely identify subprogram!",
8870 N);
8871 Error_Msg_Sloc := Sloc (Ent);
8872 Error_Msg_N ("matching subprogram #!", N);
8873 Ent := Empty;
8874 end if;
8875
8876 Error_Msg_Sloc := Sloc (Def_Id);
8877 Error_Msg_N ("matching subprogram #!", N);
8878 end if;
8879 end if;
8880 end if;
8881
8882 Hom_Id := Homonym (Hom_Id);
8883 end loop;
8884
8885 -- See if we found an entry
8886
8887 if No (Ent) then
8888 if not Ambiguous then
8889 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
8890 Error_Pragma
8891 ("pragma% cannot be given for generic subprogram");
8892 else
8893 Error_Pragma
8894 ("pragma% does not identify local subprogram");
8895 end if;
8896 end if;
8897
8898 return;
8899 end if;
8900
8901 -- Import pragmas must be for imported entities
8902
8903 if Prag_Id = Pragma_Import_Function
8904 or else
8905 Prag_Id = Pragma_Import_Procedure
8906 or else
8907 Prag_Id = Pragma_Import_Valued_Procedure
8908 then
8909 if not Is_Imported (Ent) then
8910 Error_Pragma
8911 ("pragma Import or Interface must precede pragma%");
8912 end if;
8913
8914 -- Here we have the Export case which can set the entity as exported
8915
8916 -- But does not do so if the specified external name is null, since
8917 -- that is taken as a signal in DEC Ada 83 (with which we want to be
8918 -- compatible) to request no external name.
8919
8920 elsif Nkind (Arg_External) = N_String_Literal
8921 and then String_Length (Strval (Arg_External)) = 0
8922 then
8923 null;
8924
8925 -- In all other cases, set entity as exported
8926
8927 else
8928 Set_Exported (Ent, Arg_Internal);
8929 end if;
8930
8931 -- Special processing for Valued_Procedure cases
8932
8933 if Prag_Id = Pragma_Import_Valued_Procedure
8934 or else
8935 Prag_Id = Pragma_Export_Valued_Procedure
8936 then
8937 Formal := First_Formal (Ent);
8938
8939 if No (Formal) then
8940 Error_Pragma ("at least one parameter required for pragma%");
8941
8942 elsif Ekind (Formal) /= E_Out_Parameter then
8943 Error_Pragma ("first parameter must have mode out for pragma%");
8944
8945 else
8946 Set_Is_Valued_Procedure (Ent);
8947 end if;
8948 end if;
8949
8950 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
8951
8952 -- Process Result_Mechanism argument if present. We have already
8953 -- checked that this is only allowed for the function case.
8954
8955 if Present (Arg_Result_Mechanism) then
8956 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
8957 end if;
8958
8959 -- Process Mechanism parameter if present. Note that this parameter
8960 -- is not analyzed, and must not be analyzed since it is semantic
8961 -- nonsense, so we get it in exactly as the parser left it.
8962
8963 if Present (Arg_Mechanism) then
8964 declare
8965 Formal : Entity_Id;
8966 Massoc : Node_Id;
8967 Mname : Node_Id;
8968 Choice : Node_Id;
8969
8970 begin
8971 -- A single mechanism association without a formal parameter
8972 -- name is parsed as a parenthesized expression. All other
8973 -- cases are parsed as aggregates, so we rewrite the single
8974 -- parameter case as an aggregate for consistency.
8975
8976 if Nkind (Arg_Mechanism) /= N_Aggregate
8977 and then Paren_Count (Arg_Mechanism) = 1
8978 then
8979 Rewrite (Arg_Mechanism,
8980 Make_Aggregate (Sloc (Arg_Mechanism),
8981 Expressions => New_List (
8982 Relocate_Node (Arg_Mechanism))));
8983 end if;
8984
8985 -- Case of only mechanism name given, applies to all formals
8986
8987 if Nkind (Arg_Mechanism) /= N_Aggregate then
8988 Formal := First_Formal (Ent);
8989 while Present (Formal) loop
8990 Set_Mechanism_Value (Formal, Arg_Mechanism);
8991 Next_Formal (Formal);
8992 end loop;
8993
8994 -- Case of list of mechanism associations given
8995
8996 else
8997 if Null_Record_Present (Arg_Mechanism) then
8998 Error_Pragma_Arg
8999 ("inappropriate form for Mechanism parameter",
9000 Arg_Mechanism);
9001 end if;
9002
9003 -- Deal with positional ones first
9004
9005 Formal := First_Formal (Ent);
9006
9007 if Present (Expressions (Arg_Mechanism)) then
9008 Mname := First (Expressions (Arg_Mechanism));
9009 while Present (Mname) loop
9010 if No (Formal) then
9011 Error_Pragma_Arg
9012 ("too many mechanism associations", Mname);
9013 end if;
9014
9015 Set_Mechanism_Value (Formal, Mname);
9016 Next_Formal (Formal);
9017 Next (Mname);
9018 end loop;
9019 end if;
9020
9021 -- Deal with named entries
9022
9023 if Present (Component_Associations (Arg_Mechanism)) then
9024 Massoc := First (Component_Associations (Arg_Mechanism));
9025 while Present (Massoc) loop
9026 Choice := First (Choices (Massoc));
9027
9028 if Nkind (Choice) /= N_Identifier
9029 or else Present (Next (Choice))
9030 then
9031 Error_Pragma_Arg
9032 ("incorrect form for mechanism association",
9033 Massoc);
9034 end if;
9035
9036 Formal := First_Formal (Ent);
9037 loop
9038 if No (Formal) then
9039 Error_Pragma_Arg
9040 ("parameter name & not present", Choice);
9041 end if;
9042
9043 if Chars (Choice) = Chars (Formal) then
9044 Set_Mechanism_Value
9045 (Formal, Expression (Massoc));
9046
9047 -- Set entity on identifier for proper tree
9048 -- structure.
9049
9050 Set_Entity (Choice, Formal);
9051
9052 exit;
9053 end if;
9054
9055 Next_Formal (Formal);
9056 end loop;
9057
9058 Next (Massoc);
9059 end loop;
9060 end if;
9061 end if;
9062 end;
9063 end if;
9064 end Process_Extended_Import_Export_Subprogram_Pragma;
9065
9066 --------------------------
9067 -- Process_Generic_List --
9068 --------------------------
9069
9070 procedure Process_Generic_List is
9071 Arg : Node_Id;
9072 Exp : Node_Id;
9073
9074 begin
9075 Check_No_Identifiers;
9076 Check_At_Least_N_Arguments (1);
9077
9078 -- Check all arguments are names of generic units or instances
9079
9080 Arg := Arg1;
9081 while Present (Arg) loop
9082 Exp := Get_Pragma_Arg (Arg);
9083 Analyze (Exp);
9084
9085 if not Is_Entity_Name (Exp)
9086 or else
9087 (not Is_Generic_Instance (Entity (Exp))
9088 and then
9089 not Is_Generic_Unit (Entity (Exp)))
9090 then
9091 Error_Pragma_Arg
9092 ("pragma% argument must be name of generic unit/instance",
9093 Arg);
9094 end if;
9095
9096 Next (Arg);
9097 end loop;
9098 end Process_Generic_List;
9099
9100 ------------------------------------
9101 -- Process_Import_Predefined_Type --
9102 ------------------------------------
9103
9104 procedure Process_Import_Predefined_Type is
9105 Loc : constant Source_Ptr := Sloc (N);
9106 Elmt : Elmt_Id;
9107 Ftyp : Node_Id := Empty;
9108 Decl : Node_Id;
9109 Def : Node_Id;
9110 Nam : Name_Id;
9111
9112 begin
9113 Nam := String_To_Name (Strval (Expression (Arg3)));
9114
9115 Elmt := First_Elmt (Predefined_Float_Types);
9116 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
9117 Next_Elmt (Elmt);
9118 end loop;
9119
9120 Ftyp := Node (Elmt);
9121
9122 if Present (Ftyp) then
9123
9124 -- Don't build a derived type declaration, because predefined C
9125 -- types have no declaration anywhere, so cannot really be named.
9126 -- Instead build a full type declaration, starting with an
9127 -- appropriate type definition is built
9128
9129 if Is_Floating_Point_Type (Ftyp) then
9130 Def := Make_Floating_Point_Definition (Loc,
9131 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
9132 Make_Real_Range_Specification (Loc,
9133 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
9134 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
9135
9136 -- Should never have a predefined type we cannot handle
9137
9138 else
9139 raise Program_Error;
9140 end if;
9141
9142 -- Build and insert a Full_Type_Declaration, which will be
9143 -- analyzed as soon as this list entry has been analyzed.
9144
9145 Decl := Make_Full_Type_Declaration (Loc,
9146 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
9147 Type_Definition => Def);
9148
9149 Insert_After (N, Decl);
9150 Mark_Rewrite_Insertion (Decl);
9151
9152 else
9153 Error_Pragma_Arg ("no matching type found for pragma%", Arg2);
9154 end if;
9155 end Process_Import_Predefined_Type;
9156
9157 ---------------------------------
9158 -- Process_Import_Or_Interface --
9159 ---------------------------------
9160
9161 procedure Process_Import_Or_Interface is
9162 C : Convention_Id;
9163 Def_Id : Entity_Id;
9164 Hom_Id : Entity_Id;
9165
9166 begin
9167 -- In Relaxed_RM_Semantics, support old Ada 83 style:
9168 -- pragma Import (Entity, "external name");
9169
9170 if Relaxed_RM_Semantics
9171 and then Arg_Count = 2
9172 and then Prag_Id = Pragma_Import
9173 and then Nkind (Expression (Arg2)) = N_String_Literal
9174 then
9175 C := Convention_C;
9176 Def_Id := Get_Pragma_Arg (Arg1);
9177 Analyze (Def_Id);
9178
9179 if not Is_Entity_Name (Def_Id) then
9180 Error_Pragma_Arg ("entity name required", Arg1);
9181 end if;
9182
9183 Def_Id := Entity (Def_Id);
9184 Kill_Size_Check_Code (Def_Id);
9185 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
9186
9187 else
9188 Process_Convention (C, Def_Id);
9189
9190 -- A pragma that applies to a Ghost entity becomes Ghost for the
9191 -- purposes of legality checks and removal of ignored Ghost code.
9192
9193 Mark_Ghost_Pragma (N, Def_Id);
9194 Kill_Size_Check_Code (Def_Id);
9195 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
9196 end if;
9197
9198 -- Various error checks
9199
9200 if Ekind_In (Def_Id, E_Variable, E_Constant) then
9201
9202 -- We do not permit Import to apply to a renaming declaration
9203
9204 if Present (Renamed_Object (Def_Id)) then
9205 Error_Pragma_Arg
9206 ("pragma% not allowed for object renaming", Arg2);
9207
9208 -- User initialization is not allowed for imported object, but
9209 -- the object declaration may contain a default initialization,
9210 -- that will be discarded. Note that an explicit initialization
9211 -- only counts if it comes from source, otherwise it is simply
9212 -- the code generator making an implicit initialization explicit.
9213
9214 elsif Present (Expression (Parent (Def_Id)))
9215 and then Comes_From_Source
9216 (Original_Node (Expression (Parent (Def_Id))))
9217 then
9218 -- Set imported flag to prevent cascaded errors
9219
9220 Set_Is_Imported (Def_Id);
9221
9222 Error_Msg_Sloc := Sloc (Def_Id);
9223 Error_Pragma_Arg
9224 ("no initialization allowed for declaration of& #",
9225 "\imported entities cannot be initialized (RM B.1(24))",
9226 Arg2);
9227
9228 else
9229 -- If the pragma comes from an aspect specification the
9230 -- Is_Imported flag has already been set.
9231
9232 if not From_Aspect_Specification (N) then
9233 Set_Imported (Def_Id);
9234 end if;
9235
9236 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9237
9238 -- Note that we do not set Is_Public here. That's because we
9239 -- only want to set it if there is no address clause, and we
9240 -- don't know that yet, so we delay that processing till
9241 -- freeze time.
9242
9243 -- pragma Import completes deferred constants
9244
9245 if Ekind (Def_Id) = E_Constant then
9246 Set_Has_Completion (Def_Id);
9247 end if;
9248
9249 -- It is not possible to import a constant of an unconstrained
9250 -- array type (e.g. string) because there is no simple way to
9251 -- write a meaningful subtype for it.
9252
9253 if Is_Array_Type (Etype (Def_Id))
9254 and then not Is_Constrained (Etype (Def_Id))
9255 then
9256 Error_Msg_NE
9257 ("imported constant& must have a constrained subtype",
9258 N, Def_Id);
9259 end if;
9260 end if;
9261
9262 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9263
9264 -- If the name is overloaded, pragma applies to all of the denoted
9265 -- entities in the same declarative part, unless the pragma comes
9266 -- from an aspect specification or was generated by the compiler
9267 -- (such as for pragma Provide_Shift_Operators).
9268
9269 Hom_Id := Def_Id;
9270 while Present (Hom_Id) loop
9271
9272 Def_Id := Get_Base_Subprogram (Hom_Id);
9273
9274 -- Ignore inherited subprograms because the pragma will apply
9275 -- to the parent operation, which is the one called.
9276
9277 if Is_Overloadable (Def_Id)
9278 and then Present (Alias (Def_Id))
9279 then
9280 null;
9281
9282 -- If it is not a subprogram, it must be in an outer scope and
9283 -- pragma does not apply.
9284
9285 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9286 null;
9287
9288 -- The pragma does not apply to primitives of interfaces
9289
9290 elsif Is_Dispatching_Operation (Def_Id)
9291 and then Present (Find_Dispatching_Type (Def_Id))
9292 and then Is_Interface (Find_Dispatching_Type (Def_Id))
9293 then
9294 null;
9295
9296 -- Verify that the homonym is in the same declarative part (not
9297 -- just the same scope). If the pragma comes from an aspect
9298 -- specification we know that it is part of the declaration.
9299
9300 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
9301 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9302 and then not From_Aspect_Specification (N)
9303 then
9304 exit;
9305
9306 else
9307 -- If the pragma comes from an aspect specification the
9308 -- Is_Imported flag has already been set.
9309
9310 if not From_Aspect_Specification (N) then
9311 Set_Imported (Def_Id);
9312 end if;
9313
9314 -- Reject an Import applied to an abstract subprogram
9315
9316 if Is_Subprogram (Def_Id)
9317 and then Is_Abstract_Subprogram (Def_Id)
9318 then
9319 Error_Msg_Sloc := Sloc (Def_Id);
9320 Error_Msg_NE
9321 ("cannot import abstract subprogram& declared#",
9322 Arg2, Def_Id);
9323 end if;
9324
9325 -- Special processing for Convention_Intrinsic
9326
9327 if C = Convention_Intrinsic then
9328
9329 -- Link_Name argument not allowed for intrinsic
9330
9331 Check_No_Link_Name;
9332
9333 Set_Is_Intrinsic_Subprogram (Def_Id);
9334
9335 -- If no external name is present, then check that this
9336 -- is a valid intrinsic subprogram. If an external name
9337 -- is present, then this is handled by the back end.
9338
9339 if No (Arg3) then
9340 Check_Intrinsic_Subprogram
9341 (Def_Id, Get_Pragma_Arg (Arg2));
9342 end if;
9343 end if;
9344
9345 -- Verify that the subprogram does not have a completion
9346 -- through a renaming declaration. For other completions the
9347 -- pragma appears as a too late representation.
9348
9349 declare
9350 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
9351
9352 begin
9353 if Present (Decl)
9354 and then Nkind (Decl) = N_Subprogram_Declaration
9355 and then Present (Corresponding_Body (Decl))
9356 and then Nkind (Unit_Declaration_Node
9357 (Corresponding_Body (Decl))) =
9358 N_Subprogram_Renaming_Declaration
9359 then
9360 Error_Msg_Sloc := Sloc (Def_Id);
9361 Error_Msg_NE
9362 ("cannot import&, renaming already provided for "
9363 & "declaration #", N, Def_Id);
9364 end if;
9365 end;
9366
9367 -- If the pragma comes from an aspect specification, there
9368 -- must be an Import aspect specified as well. In the rare
9369 -- case where Import is set to False, the suprogram needs to
9370 -- have a local completion.
9371
9372 declare
9373 Imp_Aspect : constant Node_Id :=
9374 Find_Aspect (Def_Id, Aspect_Import);
9375 Expr : Node_Id;
9376
9377 begin
9378 if Present (Imp_Aspect)
9379 and then Present (Expression (Imp_Aspect))
9380 then
9381 Expr := Expression (Imp_Aspect);
9382 Analyze_And_Resolve (Expr, Standard_Boolean);
9383
9384 if Is_Entity_Name (Expr)
9385 and then Entity (Expr) = Standard_True
9386 then
9387 Set_Has_Completion (Def_Id);
9388 end if;
9389
9390 -- If there is no expression, the default is True, as for
9391 -- all boolean aspects. Same for the older pragma.
9392
9393 else
9394 Set_Has_Completion (Def_Id);
9395 end if;
9396 end;
9397
9398 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9399 end if;
9400
9401 if Is_Compilation_Unit (Hom_Id) then
9402
9403 -- Its possible homonyms are not affected by the pragma.
9404 -- Such homonyms might be present in the context of other
9405 -- units being compiled.
9406
9407 exit;
9408
9409 elsif From_Aspect_Specification (N) then
9410 exit;
9411
9412 -- If the pragma was created by the compiler, then we don't
9413 -- want it to apply to other homonyms. This kind of case can
9414 -- occur when using pragma Provide_Shift_Operators, which
9415 -- generates implicit shift and rotate operators with Import
9416 -- pragmas that might apply to earlier explicit or implicit
9417 -- declarations marked with Import (for example, coming from
9418 -- an earlier pragma Provide_Shift_Operators for another type),
9419 -- and we don't generally want other homonyms being treated
9420 -- as imported or the pragma flagged as an illegal duplicate.
9421
9422 elsif not Comes_From_Source (N) then
9423 exit;
9424
9425 else
9426 Hom_Id := Homonym (Hom_Id);
9427 end if;
9428 end loop;
9429
9430 -- Import a CPP class
9431
9432 elsif C = Convention_CPP
9433 and then (Is_Record_Type (Def_Id)
9434 or else Ekind (Def_Id) = E_Incomplete_Type)
9435 then
9436 if Ekind (Def_Id) = E_Incomplete_Type then
9437 if Present (Full_View (Def_Id)) then
9438 Def_Id := Full_View (Def_Id);
9439
9440 else
9441 Error_Msg_N
9442 ("cannot import 'C'P'P type before full declaration seen",
9443 Get_Pragma_Arg (Arg2));
9444
9445 -- Although we have reported the error we decorate it as
9446 -- CPP_Class to avoid reporting spurious errors
9447
9448 Set_Is_CPP_Class (Def_Id);
9449 return;
9450 end if;
9451 end if;
9452
9453 -- Types treated as CPP classes must be declared limited (note:
9454 -- this used to be a warning but there is no real benefit to it
9455 -- since we did effectively intend to treat the type as limited
9456 -- anyway).
9457
9458 if not Is_Limited_Type (Def_Id) then
9459 Error_Msg_N
9460 ("imported 'C'P'P type must be limited",
9461 Get_Pragma_Arg (Arg2));
9462 end if;
9463
9464 if Etype (Def_Id) /= Def_Id
9465 and then not Is_CPP_Class (Root_Type (Def_Id))
9466 then
9467 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
9468 end if;
9469
9470 Set_Is_CPP_Class (Def_Id);
9471
9472 -- Imported CPP types must not have discriminants (because C++
9473 -- classes do not have discriminants).
9474
9475 if Has_Discriminants (Def_Id) then
9476 Error_Msg_N
9477 ("imported 'C'P'P type cannot have discriminants",
9478 First (Discriminant_Specifications
9479 (Declaration_Node (Def_Id))));
9480 end if;
9481
9482 -- Check that components of imported CPP types do not have default
9483 -- expressions. For private types this check is performed when the
9484 -- full view is analyzed (see Process_Full_View).
9485
9486 if not Is_Private_Type (Def_Id) then
9487 Check_CPP_Type_Has_No_Defaults (Def_Id);
9488 end if;
9489
9490 -- Import a CPP exception
9491
9492 elsif C = Convention_CPP
9493 and then Ekind (Def_Id) = E_Exception
9494 then
9495 if No (Arg3) then
9496 Error_Pragma_Arg
9497 ("'External_'Name arguments is required for 'Cpp exception",
9498 Arg3);
9499 else
9500 -- As only a string is allowed, Check_Arg_Is_External_Name
9501 -- isn't called.
9502
9503 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9504 end if;
9505
9506 if Present (Arg4) then
9507 Error_Pragma_Arg
9508 ("Link_Name argument not allowed for imported Cpp exception",
9509 Arg4);
9510 end if;
9511
9512 -- Do not call Set_Interface_Name as the name of the exception
9513 -- shouldn't be modified (and in particular it shouldn't be
9514 -- the External_Name). For exceptions, the External_Name is the
9515 -- name of the RTTI structure.
9516
9517 -- ??? Emit an error if pragma Import/Export_Exception is present
9518
9519 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
9520 Check_No_Link_Name;
9521 Check_Arg_Count (3);
9522 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9523
9524 Process_Import_Predefined_Type;
9525
9526 else
9527 Error_Pragma_Arg
9528 ("second argument of pragma% must be object, subprogram "
9529 & "or incomplete type",
9530 Arg2);
9531 end if;
9532
9533 -- If this pragma applies to a compilation unit, then the unit, which
9534 -- is a subprogram, does not require (or allow) a body. We also do
9535 -- not need to elaborate imported procedures.
9536
9537 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9538 declare
9539 Cunit : constant Node_Id := Parent (Parent (N));
9540 begin
9541 Set_Body_Required (Cunit, False);
9542 end;
9543 end if;
9544 end Process_Import_Or_Interface;
9545
9546 --------------------
9547 -- Process_Inline --
9548 --------------------
9549
9550 procedure Process_Inline (Status : Inline_Status) is
9551 Applies : Boolean;
9552 Assoc : Node_Id;
9553 Decl : Node_Id;
9554 Subp : Entity_Id;
9555 Subp_Id : Node_Id;
9556
9557 Ghost_Error_Posted : Boolean := False;
9558 -- Flag set when an error concerning the illegal mix of Ghost and
9559 -- non-Ghost subprograms is emitted.
9560
9561 Ghost_Id : Entity_Id := Empty;
9562 -- The entity of the first Ghost subprogram encountered while
9563 -- processing the arguments of the pragma.
9564
9565 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id);
9566 -- Verify the placement of pragma Inline_Always with respect to the
9567 -- initial declaration of subprogram Spec_Id.
9568
9569 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
9570 -- Returns True if it can be determined at this stage that inlining
9571 -- is not possible, for example if the body is available and contains
9572 -- exception handlers, we prevent inlining, since otherwise we can
9573 -- get undefined symbols at link time. This function also emits a
9574 -- warning if the pragma appears too late.
9575 --
9576 -- ??? is business with link symbols still valid, or does it relate
9577 -- to front end ZCX which is being phased out ???
9578
9579 procedure Make_Inline (Subp : Entity_Id);
9580 -- Subp is the defining unit name of the subprogram declaration. If
9581 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
9582 -- the corresponding body, if there is one present.
9583
9584 procedure Set_Inline_Flags (Subp : Entity_Id);
9585 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
9586 -- Also set or clear Is_Inlined flag on Subp depending on Status.
9587
9588 -----------------------------------
9589 -- Check_Inline_Always_Placement --
9590 -----------------------------------
9591
9592 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id) is
9593 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id);
9594
9595 function Compilation_Unit_OK return Boolean;
9596 pragma Inline (Compilation_Unit_OK);
9597 -- Determine whether pragma Inline_Always applies to a compatible
9598 -- compilation unit denoted by Spec_Id.
9599
9600 function Declarative_List_OK return Boolean;
9601 pragma Inline (Declarative_List_OK);
9602 -- Determine whether the initial declaration of subprogram Spec_Id
9603 -- and the pragma appear in compatible declarative lists.
9604
9605 function Subprogram_Body_OK return Boolean;
9606 pragma Inline (Subprogram_Body_OK);
9607 -- Determine whether pragma Inline_Always applies to a compatible
9608 -- subprogram body denoted by Spec_Id.
9609
9610 -------------------------
9611 -- Compilation_Unit_OK --
9612 -------------------------
9613
9614 function Compilation_Unit_OK return Boolean is
9615 Comp_Unit : constant Node_Id := Parent (Spec_Decl);
9616
9617 begin
9618 -- The pragma appears after the initial declaration of a
9619 -- compilation unit.
9620
9621 -- procedure Comp_Unit;
9622 -- pragma Inline_Always (Comp_Unit);
9623
9624 -- Note that for compatibility reasons, the following case is
9625 -- also accepted.
9626
9627 -- procedure Stand_Alone_Body_Comp_Unit is
9628 -- ...
9629 -- end Stand_Alone_Body_Comp_Unit;
9630 -- pragma Inline_Always (Stand_Alone_Body_Comp_Unit);
9631
9632 return
9633 Nkind (Comp_Unit) = N_Compilation_Unit
9634 and then Present (Aux_Decls_Node (Comp_Unit))
9635 and then Is_List_Member (N)
9636 and then List_Containing (N) =
9637 Pragmas_After (Aux_Decls_Node (Comp_Unit));
9638 end Compilation_Unit_OK;
9639
9640 -------------------------
9641 -- Declarative_List_OK --
9642 -------------------------
9643
9644 function Declarative_List_OK return Boolean is
9645 Context : constant Node_Id := Parent (Spec_Decl);
9646
9647 Init_Decl : Node_Id;
9648 Init_List : List_Id;
9649 Prag_List : List_Id;
9650
9651 begin
9652 -- Determine the proper initial declaration. In general this is
9653 -- the declaration node of the subprogram except when the input
9654 -- denotes a generic instantiation.
9655
9656 -- procedure Inst is new Gen;
9657 -- pragma Inline_Always (Inst);
9658
9659 -- In this case the original subprogram is moved inside an
9660 -- anonymous package while pragma Inline_Always remains at the
9661 -- level of the anonymous package. Use the declaration of the
9662 -- package because it reflects the placement of the original
9663 -- instantiation.
9664
9665 -- package Anon_Pack is
9666 -- procedure Inst is ... end Inst; -- original
9667 -- end Anon_Pack;
9668
9669 -- procedure Inst renames Anon_Pack.Inst;
9670 -- pragma Inline_Always (Inst);
9671
9672 if Is_Generic_Instance (Spec_Id) then
9673 Init_Decl := Parent (Parent (Spec_Decl));
9674 pragma Assert (Nkind (Init_Decl) = N_Package_Declaration);
9675 else
9676 Init_Decl := Spec_Decl;
9677 end if;
9678
9679 if Is_List_Member (Init_Decl) and then Is_List_Member (N) then
9680 Init_List := List_Containing (Init_Decl);
9681 Prag_List := List_Containing (N);
9682
9683 -- The pragma and then initial declaration appear within the
9684 -- same declarative list.
9685
9686 if Init_List = Prag_List then
9687 return True;
9688
9689 -- A special case of the above is when both the pragma and
9690 -- the initial declaration appear in different lists of a
9691 -- package spec, protected definition, or a task definition.
9692
9693 -- package Pack is
9694 -- procedure Proc;
9695 -- private
9696 -- pragma Inline_Always (Proc);
9697 -- end Pack;
9698
9699 elsif Nkind_In (Context, N_Package_Specification,
9700 N_Protected_Definition,
9701 N_Task_Definition)
9702 and then Init_List = Visible_Declarations (Context)
9703 and then Prag_List = Private_Declarations (Context)
9704 then
9705 return True;
9706 end if;
9707 end if;
9708
9709 return False;
9710 end Declarative_List_OK;
9711
9712 ------------------------
9713 -- Subprogram_Body_OK --
9714 ------------------------
9715
9716 function Subprogram_Body_OK return Boolean is
9717 Body_Decl : Node_Id;
9718
9719 begin
9720 -- The pragma appears within the declarative list of a stand-
9721 -- alone subprogram body.
9722
9723 -- procedure Stand_Alone_Body is
9724 -- pragma Inline_Always (Stand_Alone_Body);
9725 -- begin
9726 -- ...
9727 -- end Stand_Alone_Body;
9728
9729 -- The compiler creates a dummy spec in this case, however the
9730 -- pragma remains within the declarative list of the body.
9731
9732 if Nkind (Spec_Decl) = N_Subprogram_Declaration
9733 and then not Comes_From_Source (Spec_Decl)
9734 and then Present (Corresponding_Body (Spec_Decl))
9735 then
9736 Body_Decl :=
9737 Unit_Declaration_Node (Corresponding_Body (Spec_Decl));
9738
9739 if Present (Declarations (Body_Decl))
9740 and then Is_List_Member (N)
9741 and then List_Containing (N) = Declarations (Body_Decl)
9742 then
9743 return True;
9744 end if;
9745 end if;
9746
9747 return False;
9748 end Subprogram_Body_OK;
9749
9750 -- Start of processing for Check_Inline_Always_Placement
9751
9752 begin
9753 -- This check is relevant only for pragma Inline_Always
9754
9755 if Pname /= Name_Inline_Always then
9756 return;
9757
9758 -- Nothing to do when the pragma is internally generated on the
9759 -- assumption that it is properly placed.
9760
9761 elsif not Comes_From_Source (N) then
9762 return;
9763
9764 -- Nothing to do for internally generated subprograms that act
9765 -- as accidental homonyms of a source subprogram being inlined.
9766
9767 elsif not Comes_From_Source (Spec_Id) then
9768 return;
9769
9770 -- Nothing to do for generic formal subprograms that act as
9771 -- homonyms of another source subprogram being inlined.
9772
9773 elsif Is_Formal_Subprogram (Spec_Id) then
9774 return;
9775
9776 elsif Compilation_Unit_OK
9777 or else Declarative_List_OK
9778 or else Subprogram_Body_OK
9779 then
9780 return;
9781 end if;
9782
9783 -- At this point it is known that the pragma applies to or appears
9784 -- within a completing body, a completing stub, or a subunit.
9785
9786 Error_Msg_Name_1 := Pname;
9787 Error_Msg_Name_2 := Chars (Spec_Id);
9788 Error_Msg_Sloc := Sloc (Spec_Id);
9789
9790 Error_Msg_N
9791 ("pragma % must appear on initial declaration of subprogram "
9792 & "% defined #", N);
9793 end Check_Inline_Always_Placement;
9794
9795 ---------------------------
9796 -- Inlining_Not_Possible --
9797 ---------------------------
9798
9799 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
9800 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
9801 Stats : Node_Id;
9802
9803 begin
9804 if Nkind (Decl) = N_Subprogram_Body then
9805 Stats := Handled_Statement_Sequence (Decl);
9806 return Present (Exception_Handlers (Stats))
9807 or else Present (At_End_Proc (Stats));
9808
9809 elsif Nkind (Decl) = N_Subprogram_Declaration
9810 and then Present (Corresponding_Body (Decl))
9811 then
9812 if Analyzed (Corresponding_Body (Decl)) then
9813 Error_Msg_N ("pragma appears too late, ignored??", N);
9814 return True;
9815
9816 -- If the subprogram is a renaming as body, the body is just a
9817 -- call to the renamed subprogram, and inlining is trivially
9818 -- possible.
9819
9820 elsif
9821 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
9822 N_Subprogram_Renaming_Declaration
9823 then
9824 return False;
9825
9826 else
9827 Stats :=
9828 Handled_Statement_Sequence
9829 (Unit_Declaration_Node (Corresponding_Body (Decl)));
9830
9831 return
9832 Present (Exception_Handlers (Stats))
9833 or else Present (At_End_Proc (Stats));
9834 end if;
9835
9836 else
9837 -- If body is not available, assume the best, the check is
9838 -- performed again when compiling enclosing package bodies.
9839
9840 return False;
9841 end if;
9842 end Inlining_Not_Possible;
9843
9844 -----------------
9845 -- Make_Inline --
9846 -----------------
9847
9848 procedure Make_Inline (Subp : Entity_Id) is
9849 Kind : constant Entity_Kind := Ekind (Subp);
9850 Inner_Subp : Entity_Id := Subp;
9851
9852 begin
9853 -- Ignore if bad type, avoid cascaded error
9854
9855 if Etype (Subp) = Any_Type then
9856 Applies := True;
9857 return;
9858
9859 -- If inlining is not possible, for now do not treat as an error
9860
9861 elsif Status /= Suppressed
9862 and then Front_End_Inlining
9863 and then Inlining_Not_Possible (Subp)
9864 then
9865 Applies := True;
9866 return;
9867
9868 -- Here we have a candidate for inlining, but we must exclude
9869 -- derived operations. Otherwise we would end up trying to inline
9870 -- a phantom declaration, and the result would be to drag in a
9871 -- body which has no direct inlining associated with it. That
9872 -- would not only be inefficient but would also result in the
9873 -- backend doing cross-unit inlining in cases where it was
9874 -- definitely inappropriate to do so.
9875
9876 -- However, a simple Comes_From_Source test is insufficient, since
9877 -- we do want to allow inlining of generic instances which also do
9878 -- not come from source. We also need to recognize specs generated
9879 -- by the front-end for bodies that carry the pragma. Finally,
9880 -- predefined operators do not come from source but are not
9881 -- inlineable either.
9882
9883 elsif Is_Generic_Instance (Subp)
9884 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
9885 then
9886 null;
9887
9888 elsif not Comes_From_Source (Subp)
9889 and then Scope (Subp) /= Standard_Standard
9890 then
9891 Applies := True;
9892 return;
9893 end if;
9894
9895 -- The referenced entity must either be the enclosing entity, or
9896 -- an entity declared within the current open scope.
9897
9898 if Present (Scope (Subp))
9899 and then Scope (Subp) /= Current_Scope
9900 and then Subp /= Current_Scope
9901 then
9902 Error_Pragma_Arg
9903 ("argument of% must be entity in current scope", Assoc);
9904 return;
9905 end if;
9906
9907 -- Processing for procedure, operator or function. If subprogram
9908 -- is aliased (as for an instance) indicate that the renamed
9909 -- entity (if declared in the same unit) is inlined.
9910 -- If this is the anonymous subprogram created for a subprogram
9911 -- instance, the inlining applies to it directly. Otherwise we
9912 -- retrieve it as the alias of the visible subprogram instance.
9913
9914 if Is_Subprogram (Subp) then
9915
9916 -- Ensure that pragma Inline_Always is associated with the
9917 -- initial declaration of the subprogram.
9918
9919 Check_Inline_Always_Placement (Subp);
9920
9921 if Is_Wrapper_Package (Scope (Subp)) then
9922 Inner_Subp := Subp;
9923 else
9924 Inner_Subp := Ultimate_Alias (Inner_Subp);
9925 end if;
9926
9927 if In_Same_Source_Unit (Subp, Inner_Subp) then
9928 Set_Inline_Flags (Inner_Subp);
9929
9930 Decl := Parent (Parent (Inner_Subp));
9931
9932 if Nkind (Decl) = N_Subprogram_Declaration
9933 and then Present (Corresponding_Body (Decl))
9934 then
9935 Set_Inline_Flags (Corresponding_Body (Decl));
9936
9937 elsif Is_Generic_Instance (Subp)
9938 and then Comes_From_Source (Subp)
9939 then
9940 -- Indicate that the body needs to be created for
9941 -- inlining subsequent calls. The instantiation node
9942 -- follows the declaration of the wrapper package
9943 -- created for it. The subprogram that requires the
9944 -- body is the anonymous one in the wrapper package.
9945
9946 if Scope (Subp) /= Standard_Standard
9947 and then
9948 Need_Subprogram_Instance_Body
9949 (Next (Unit_Declaration_Node
9950 (Scope (Alias (Subp)))), Subp)
9951 then
9952 null;
9953 end if;
9954
9955 -- Inline is a program unit pragma (RM 10.1.5) and cannot
9956 -- appear in a formal part to apply to a formal subprogram.
9957 -- Do not apply check within an instance or a formal package
9958 -- the test will have been applied to the original generic.
9959
9960 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
9961 and then List_Containing (Decl) = List_Containing (N)
9962 and then not In_Instance
9963 then
9964 Error_Msg_N
9965 ("Inline cannot apply to a formal subprogram", N);
9966 end if;
9967 end if;
9968
9969 Applies := True;
9970
9971 -- For a generic subprogram set flag as well, for use at the point
9972 -- of instantiation, to determine whether the body should be
9973 -- generated.
9974
9975 elsif Is_Generic_Subprogram (Subp) then
9976 Set_Inline_Flags (Subp);
9977 Applies := True;
9978
9979 -- Literals are by definition inlined
9980
9981 elsif Kind = E_Enumeration_Literal then
9982 null;
9983
9984 -- Anything else is an error
9985
9986 else
9987 Error_Pragma_Arg
9988 ("expect subprogram name for pragma%", Assoc);
9989 end if;
9990 end Make_Inline;
9991
9992 ----------------------
9993 -- Set_Inline_Flags --
9994 ----------------------
9995
9996 procedure Set_Inline_Flags (Subp : Entity_Id) is
9997 begin
9998 -- First set the Has_Pragma_XXX flags and issue the appropriate
9999 -- errors and warnings for suspicious combinations.
10000
10001 if Prag_Id = Pragma_No_Inline then
10002 if Has_Pragma_Inline_Always (Subp) then
10003 Error_Msg_N
10004 ("Inline_Always and No_Inline are mutually exclusive", N);
10005 elsif Has_Pragma_Inline (Subp) then
10006 Error_Msg_NE
10007 ("Inline and No_Inline both specified for& ??",
10008 N, Entity (Subp_Id));
10009 end if;
10010
10011 Set_Has_Pragma_No_Inline (Subp);
10012 else
10013 if Prag_Id = Pragma_Inline_Always then
10014 if Has_Pragma_No_Inline (Subp) then
10015 Error_Msg_N
10016 ("Inline_Always and No_Inline are mutually exclusive",
10017 N);
10018 end if;
10019
10020 Set_Has_Pragma_Inline_Always (Subp);
10021 else
10022 if Has_Pragma_No_Inline (Subp) then
10023 Error_Msg_NE
10024 ("Inline and No_Inline both specified for& ??",
10025 N, Entity (Subp_Id));
10026 end if;
10027 end if;
10028
10029 Set_Has_Pragma_Inline (Subp);
10030 end if;
10031
10032 -- Then adjust the Is_Inlined flag. It can never be set if the
10033 -- subprogram is subject to pragma No_Inline.
10034
10035 case Status is
10036 when Suppressed =>
10037 Set_Is_Inlined (Subp, False);
10038
10039 when Disabled =>
10040 null;
10041
10042 when Enabled =>
10043 if not Has_Pragma_No_Inline (Subp) then
10044 Set_Is_Inlined (Subp, True);
10045 end if;
10046 end case;
10047
10048 -- A pragma that applies to a Ghost entity becomes Ghost for the
10049 -- purposes of legality checks and removal of ignored Ghost code.
10050
10051 Mark_Ghost_Pragma (N, Subp);
10052
10053 -- Capture the entity of the first Ghost subprogram being
10054 -- processed for error detection purposes.
10055
10056 if Is_Ghost_Entity (Subp) then
10057 if No (Ghost_Id) then
10058 Ghost_Id := Subp;
10059 end if;
10060
10061 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
10062 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
10063
10064 elsif Present (Ghost_Id) and then not Ghost_Error_Posted then
10065 Ghost_Error_Posted := True;
10066
10067 Error_Msg_Name_1 := Pname;
10068 Error_Msg_N
10069 ("pragma % cannot mention ghost and non-ghost subprograms",
10070 N);
10071
10072 Error_Msg_Sloc := Sloc (Ghost_Id);
10073 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
10074
10075 Error_Msg_Sloc := Sloc (Subp);
10076 Error_Msg_NE ("\& # declared as non-ghost", N, Subp);
10077 end if;
10078 end Set_Inline_Flags;
10079
10080 -- Start of processing for Process_Inline
10081
10082 begin
10083 -- An inlined subprogram may grant access to its private enclosing
10084 -- context depending on the placement of its body. From elaboration
10085 -- point of view, the flow of execution may enter this private
10086 -- context, and then reach an external unit, thus producing a
10087 -- dependency on that external unit. For such a path to be properly
10088 -- discovered and encoded in the ALI file of the main unit, let the
10089 -- ABE mechanism process the body of the main unit, and encode all
10090 -- relevant invocation constructs and the relations between them.
10091
10092 Mark_Save_Invocation_Graph_Of_Body;
10093
10094 Check_No_Identifiers;
10095 Check_At_Least_N_Arguments (1);
10096
10097 if Status = Enabled then
10098 Inline_Processing_Required := True;
10099 end if;
10100
10101 Assoc := Arg1;
10102 while Present (Assoc) loop
10103 Subp_Id := Get_Pragma_Arg (Assoc);
10104 Analyze (Subp_Id);
10105 Applies := False;
10106
10107 if Is_Entity_Name (Subp_Id) then
10108 Subp := Entity (Subp_Id);
10109
10110 if Subp = Any_Id then
10111
10112 -- If previous error, avoid cascaded errors
10113
10114 Check_Error_Detected;
10115 Applies := True;
10116
10117 else
10118 Make_Inline (Subp);
10119
10120 -- For the pragma case, climb homonym chain. This is
10121 -- what implements allowing the pragma in the renaming
10122 -- case, with the result applying to the ancestors, and
10123 -- also allows Inline to apply to all previous homonyms.
10124
10125 if not From_Aspect_Specification (N) then
10126 while Present (Homonym (Subp))
10127 and then Scope (Homonym (Subp)) = Current_Scope
10128 loop
10129 Make_Inline (Homonym (Subp));
10130 Subp := Homonym (Subp);
10131 end loop;
10132 end if;
10133 end if;
10134 end if;
10135
10136 if not Applies then
10137 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
10138 end if;
10139
10140 Next (Assoc);
10141 end loop;
10142
10143 -- If the context is a package declaration, the pragma indicates
10144 -- that inlining will require the presence of the corresponding
10145 -- body. (this may be further refined).
10146
10147 if not In_Instance
10148 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
10149 N_Package_Declaration
10150 then
10151 Set_Body_Needed_For_Inlining (Cunit_Entity (Current_Sem_Unit));
10152 end if;
10153 end Process_Inline;
10154
10155 ----------------------------
10156 -- Process_Interface_Name --
10157 ----------------------------
10158
10159 procedure Process_Interface_Name
10160 (Subprogram_Def : Entity_Id;
10161 Ext_Arg : Node_Id;
10162 Link_Arg : Node_Id;
10163 Prag : Node_Id)
10164 is
10165 Ext_Nam : Node_Id;
10166 Link_Nam : Node_Id;
10167 String_Val : String_Id;
10168
10169 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
10170 -- SN is a string literal node for an interface name. This routine
10171 -- performs some minimal checks that the name is reasonable. In
10172 -- particular that no spaces or other obviously incorrect characters
10173 -- appear. This is only a warning, since any characters are allowed.
10174
10175 ----------------------------------
10176 -- Check_Form_Of_Interface_Name --
10177 ----------------------------------
10178
10179 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
10180 S : constant String_Id := Strval (Expr_Value_S (SN));
10181 SL : constant Nat := String_Length (S);
10182 C : Char_Code;
10183
10184 begin
10185 if SL = 0 then
10186 Error_Msg_N ("interface name cannot be null string", SN);
10187 end if;
10188
10189 for J in 1 .. SL loop
10190 C := Get_String_Char (S, J);
10191
10192 -- Look for dubious character and issue unconditional warning.
10193 -- Definitely dubious if not in character range.
10194
10195 if not In_Character_Range (C)
10196
10197 -- Commas, spaces and (back)slashes are dubious
10198
10199 or else Get_Character (C) = ','
10200 or else Get_Character (C) = '\'
10201 or else Get_Character (C) = ' '
10202 or else Get_Character (C) = '/'
10203 then
10204 Error_Msg
10205 ("??interface name contains illegal character",
10206 Sloc (SN) + Source_Ptr (J));
10207 end if;
10208 end loop;
10209 end Check_Form_Of_Interface_Name;
10210
10211 -- Start of processing for Process_Interface_Name
10212
10213 begin
10214 -- If we are looking at a pragma that comes from an aspect then it
10215 -- needs to have its corresponding aspect argument expressions
10216 -- analyzed in addition to the generated pragma so that aspects
10217 -- within generic units get properly resolved.
10218
10219 if Present (Prag) and then From_Aspect_Specification (Prag) then
10220 declare
10221 Asp : constant Node_Id := Corresponding_Aspect (Prag);
10222 Dummy_1 : Node_Id;
10223 Dummy_2 : Node_Id;
10224 Dummy_3 : Node_Id;
10225 EN : Node_Id;
10226 LN : Node_Id;
10227
10228 begin
10229 -- Obtain all interfacing aspects used to construct the pragma
10230
10231 Get_Interfacing_Aspects
10232 (Asp, Dummy_1, EN, Dummy_2, Dummy_3, LN);
10233
10234 -- Analyze the expression of aspect External_Name
10235
10236 if Present (EN) then
10237 Analyze (Expression (EN));
10238 end if;
10239
10240 -- Analyze the expressio of aspect Link_Name
10241
10242 if Present (LN) then
10243 Analyze (Expression (LN));
10244 end if;
10245 end;
10246 end if;
10247
10248 if No (Link_Arg) then
10249 if No (Ext_Arg) then
10250 return;
10251
10252 elsif Chars (Ext_Arg) = Name_Link_Name then
10253 Ext_Nam := Empty;
10254 Link_Nam := Expression (Ext_Arg);
10255
10256 else
10257 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10258 Ext_Nam := Expression (Ext_Arg);
10259 Link_Nam := Empty;
10260 end if;
10261
10262 else
10263 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10264 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
10265 Ext_Nam := Expression (Ext_Arg);
10266 Link_Nam := Expression (Link_Arg);
10267 end if;
10268
10269 -- Check expressions for external name and link name are static
10270
10271 if Present (Ext_Nam) then
10272 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
10273 Check_Form_Of_Interface_Name (Ext_Nam);
10274
10275 -- Verify that external name is not the name of a local entity,
10276 -- which would hide the imported one and could lead to run-time
10277 -- surprises. The problem can only arise for entities declared in
10278 -- a package body (otherwise the external name is fully qualified
10279 -- and will not conflict).
10280
10281 declare
10282 Nam : Name_Id;
10283 E : Entity_Id;
10284 Par : Node_Id;
10285
10286 begin
10287 if Prag_Id = Pragma_Import then
10288 Nam := String_To_Name (Strval (Expr_Value_S (Ext_Nam)));
10289 E := Entity_Id (Get_Name_Table_Int (Nam));
10290
10291 if Nam /= Chars (Subprogram_Def)
10292 and then Present (E)
10293 and then not Is_Overloadable (E)
10294 and then Is_Immediately_Visible (E)
10295 and then not Is_Imported (E)
10296 and then Ekind (Scope (E)) = E_Package
10297 then
10298 Par := Parent (E);
10299 while Present (Par) loop
10300 if Nkind (Par) = N_Package_Body then
10301 Error_Msg_Sloc := Sloc (E);
10302 Error_Msg_NE
10303 ("imported entity is hidden by & declared#",
10304 Ext_Arg, E);
10305 exit;
10306 end if;
10307
10308 Par := Parent (Par);
10309 end loop;
10310 end if;
10311 end if;
10312 end;
10313 end if;
10314
10315 if Present (Link_Nam) then
10316 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
10317 Check_Form_Of_Interface_Name (Link_Nam);
10318 end if;
10319
10320 -- If there is no link name, just set the external name
10321
10322 if No (Link_Nam) then
10323 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
10324
10325 -- For the Link_Name case, the given literal is preceded by an
10326 -- asterisk, which indicates to GCC that the given name should be
10327 -- taken literally, and in particular that no prepending of
10328 -- underlines should occur, even in systems where this is the
10329 -- normal default.
10330
10331 else
10332 Start_String;
10333 Store_String_Char (Get_Char_Code ('*'));
10334 String_Val := Strval (Expr_Value_S (Link_Nam));
10335 Store_String_Chars (String_Val);
10336 Link_Nam :=
10337 Make_String_Literal (Sloc (Link_Nam),
10338 Strval => End_String);
10339 end if;
10340
10341 -- Set the interface name. If the entity is a generic instance, use
10342 -- its alias, which is the callable entity.
10343
10344 if Is_Generic_Instance (Subprogram_Def) then
10345 Set_Encoded_Interface_Name
10346 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
10347 else
10348 Set_Encoded_Interface_Name
10349 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
10350 end if;
10351
10352 Check_Duplicated_Export_Name (Link_Nam);
10353 end Process_Interface_Name;
10354
10355 -----------------------------------------
10356 -- Process_Interrupt_Or_Attach_Handler --
10357 -----------------------------------------
10358
10359 procedure Process_Interrupt_Or_Attach_Handler is
10360 Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
10361 Prot_Typ : constant Entity_Id := Scope (Handler);
10362
10363 begin
10364 -- A pragma that applies to a Ghost entity becomes Ghost for the
10365 -- purposes of legality checks and removal of ignored Ghost code.
10366
10367 Mark_Ghost_Pragma (N, Handler);
10368 Set_Is_Interrupt_Handler (Handler);
10369
10370 pragma Assert (Ekind (Prot_Typ) = E_Protected_Type);
10371
10372 Record_Rep_Item (Prot_Typ, N);
10373
10374 -- Chain the pragma on the contract for completeness
10375
10376 Add_Contract_Item (N, Handler);
10377 end Process_Interrupt_Or_Attach_Handler;
10378
10379 --------------------------------------------------
10380 -- Process_Restrictions_Or_Restriction_Warnings --
10381 --------------------------------------------------
10382
10383 -- Note: some of the simple identifier cases were handled in par-prag,
10384 -- but it is harmless (and more straightforward) to simply handle all
10385 -- cases here, even if it means we repeat a bit of work in some cases.
10386
10387 procedure Process_Restrictions_Or_Restriction_Warnings
10388 (Warn : Boolean)
10389 is
10390 Arg : Node_Id;
10391 R_Id : Restriction_Id;
10392 Id : Name_Id;
10393 Expr : Node_Id;
10394 Val : Uint;
10395
10396 begin
10397 -- Ignore all Restrictions pragmas in CodePeer mode
10398
10399 if CodePeer_Mode then
10400 return;
10401 end if;
10402
10403 Check_Ada_83_Warning;
10404 Check_At_Least_N_Arguments (1);
10405 Check_Valid_Configuration_Pragma;
10406
10407 Arg := Arg1;
10408 while Present (Arg) loop
10409 Id := Chars (Arg);
10410 Expr := Get_Pragma_Arg (Arg);
10411
10412 -- Case of no restriction identifier present
10413
10414 if Id = No_Name then
10415 if Nkind (Expr) /= N_Identifier then
10416 Error_Pragma_Arg
10417 ("invalid form for restriction", Arg);
10418 end if;
10419
10420 R_Id :=
10421 Get_Restriction_Id
10422 (Process_Restriction_Synonyms (Expr));
10423
10424 if R_Id not in All_Boolean_Restrictions then
10425 Error_Msg_Name_1 := Pname;
10426 Error_Msg_N
10427 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
10428
10429 -- Check for possible misspelling
10430
10431 for J in Restriction_Id loop
10432 declare
10433 Rnm : constant String := Restriction_Id'Image (J);
10434
10435 begin
10436 Name_Buffer (1 .. Rnm'Length) := Rnm;
10437 Name_Len := Rnm'Length;
10438 Set_Casing (All_Lower_Case);
10439
10440 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
10441 Set_Casing
10442 (Identifier_Casing
10443 (Source_Index (Current_Sem_Unit)));
10444 Error_Msg_String (1 .. Rnm'Length) :=
10445 Name_Buffer (1 .. Name_Len);
10446 Error_Msg_Strlen := Rnm'Length;
10447 Error_Msg_N -- CODEFIX
10448 ("\possible misspelling of ""~""",
10449 Get_Pragma_Arg (Arg));
10450 exit;
10451 end if;
10452 end;
10453 end loop;
10454
10455 raise Pragma_Exit;
10456 end if;
10457
10458 if Implementation_Restriction (R_Id) then
10459 Check_Restriction (No_Implementation_Restrictions, Arg);
10460 end if;
10461
10462 -- Special processing for No_Elaboration_Code restriction
10463
10464 if R_Id = No_Elaboration_Code then
10465
10466 -- Restriction is only recognized within a configuration
10467 -- pragma file, or within a unit of the main extended
10468 -- program. Note: the test for Main_Unit is needed to
10469 -- properly include the case of configuration pragma files.
10470
10471 if not (Current_Sem_Unit = Main_Unit
10472 or else In_Extended_Main_Source_Unit (N))
10473 then
10474 return;
10475
10476 -- Don't allow in a subunit unless already specified in
10477 -- body or spec.
10478
10479 elsif Nkind (Parent (N)) = N_Compilation_Unit
10480 and then Nkind (Unit (Parent (N))) = N_Subunit
10481 and then not Restriction_Active (No_Elaboration_Code)
10482 then
10483 Error_Msg_N
10484 ("invalid specification of ""No_Elaboration_Code""",
10485 N);
10486 Error_Msg_N
10487 ("\restriction cannot be specified in a subunit", N);
10488 Error_Msg_N
10489 ("\unless also specified in body or spec", N);
10490 return;
10491
10492 -- If we accept a No_Elaboration_Code restriction, then it
10493 -- needs to be added to the configuration restriction set so
10494 -- that we get proper application to other units in the main
10495 -- extended source as required.
10496
10497 else
10498 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
10499 end if;
10500 end if;
10501
10502 -- If this is a warning, then set the warning unless we already
10503 -- have a real restriction active (we never want a warning to
10504 -- override a real restriction).
10505
10506 if Warn then
10507 if not Restriction_Active (R_Id) then
10508 Set_Restriction (R_Id, N);
10509 Restriction_Warnings (R_Id) := True;
10510 end if;
10511
10512 -- If real restriction case, then set it and make sure that the
10513 -- restriction warning flag is off, since a real restriction
10514 -- always overrides a warning.
10515
10516 else
10517 Set_Restriction (R_Id, N);
10518 Restriction_Warnings (R_Id) := False;
10519 end if;
10520
10521 -- Check for obsolescent restrictions in Ada 2005 mode
10522
10523 if not Warn
10524 and then Ada_Version >= Ada_2005
10525 and then (R_Id = No_Asynchronous_Control
10526 or else
10527 R_Id = No_Unchecked_Deallocation
10528 or else
10529 R_Id = No_Unchecked_Conversion)
10530 then
10531 Check_Restriction (No_Obsolescent_Features, N);
10532 end if;
10533
10534 -- A very special case that must be processed here: pragma
10535 -- Restrictions (No_Exceptions) turns off all run-time
10536 -- checking. This is a bit dubious in terms of the formal
10537 -- language definition, but it is what is intended by RM
10538 -- H.4(12). Restriction_Warnings never affects generated code
10539 -- so this is done only in the real restriction case.
10540
10541 -- Atomic_Synchronization is not a real check, so it is not
10542 -- affected by this processing).
10543
10544 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
10545 -- run-time checks in CodePeer and GNATprove modes: we want to
10546 -- generate checks for analysis purposes, as set respectively
10547 -- by -gnatC and -gnatd.F
10548
10549 if not Warn
10550 and then not (CodePeer_Mode or GNATprove_Mode)
10551 and then R_Id = No_Exceptions
10552 then
10553 for J in Scope_Suppress.Suppress'Range loop
10554 if J /= Atomic_Synchronization then
10555 Scope_Suppress.Suppress (J) := True;
10556 end if;
10557 end loop;
10558 end if;
10559
10560 -- Case of No_Dependence => unit-name. Note that the parser
10561 -- already made the necessary entry in the No_Dependence table.
10562
10563 elsif Id = Name_No_Dependence then
10564 if not OK_No_Dependence_Unit_Name (Expr) then
10565 raise Pragma_Exit;
10566 end if;
10567
10568 -- Case of No_Specification_Of_Aspect => aspect-identifier
10569
10570 elsif Id = Name_No_Specification_Of_Aspect then
10571 declare
10572 A_Id : Aspect_Id;
10573
10574 begin
10575 if Nkind (Expr) /= N_Identifier then
10576 A_Id := No_Aspect;
10577 else
10578 A_Id := Get_Aspect_Id (Chars (Expr));
10579 end if;
10580
10581 if A_Id = No_Aspect then
10582 Error_Pragma_Arg ("invalid restriction name", Arg);
10583 else
10584 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
10585 end if;
10586 end;
10587
10588 -- Case of No_Use_Of_Attribute => attribute-identifier
10589
10590 elsif Id = Name_No_Use_Of_Attribute then
10591 if Nkind (Expr) /= N_Identifier
10592 or else not Is_Attribute_Name (Chars (Expr))
10593 then
10594 Error_Msg_N ("unknown attribute name??", Expr);
10595
10596 else
10597 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
10598 end if;
10599
10600 -- Case of No_Use_Of_Entity => fully-qualified-name
10601
10602 elsif Id = Name_No_Use_Of_Entity then
10603
10604 -- Restriction is only recognized within a configuration
10605 -- pragma file, or within a unit of the main extended
10606 -- program. Note: the test for Main_Unit is needed to
10607 -- properly include the case of configuration pragma files.
10608
10609 if Current_Sem_Unit = Main_Unit
10610 or else In_Extended_Main_Source_Unit (N)
10611 then
10612 if not OK_No_Dependence_Unit_Name (Expr) then
10613 Error_Msg_N ("wrong form for entity name", Expr);
10614 else
10615 Set_Restriction_No_Use_Of_Entity
10616 (Expr, Warn, No_Profile);
10617 end if;
10618 end if;
10619
10620 -- Case of No_Use_Of_Pragma => pragma-identifier
10621
10622 elsif Id = Name_No_Use_Of_Pragma then
10623 if Nkind (Expr) /= N_Identifier
10624 or else not Is_Pragma_Name (Chars (Expr))
10625 then
10626 Error_Msg_N ("unknown pragma name??", Expr);
10627 else
10628 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
10629 end if;
10630
10631 -- All other cases of restriction identifier present
10632
10633 else
10634 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
10635 Analyze_And_Resolve (Expr, Any_Integer);
10636
10637 if R_Id not in All_Parameter_Restrictions then
10638 Error_Pragma_Arg
10639 ("invalid restriction parameter identifier", Arg);
10640
10641 elsif not Is_OK_Static_Expression (Expr) then
10642 Flag_Non_Static_Expr
10643 ("value must be static expression!", Expr);
10644 raise Pragma_Exit;
10645
10646 elsif not Is_Integer_Type (Etype (Expr))
10647 or else Expr_Value (Expr) < 0
10648 then
10649 Error_Pragma_Arg
10650 ("value must be non-negative integer", Arg);
10651 end if;
10652
10653 -- Restriction pragma is active
10654
10655 Val := Expr_Value (Expr);
10656
10657 if not UI_Is_In_Int_Range (Val) then
10658 Error_Pragma_Arg
10659 ("pragma ignored, value too large??", Arg);
10660 end if;
10661
10662 -- Warning case. If the real restriction is active, then we
10663 -- ignore the request, since warning never overrides a real
10664 -- restriction. Otherwise we set the proper warning. Note that
10665 -- this circuit sets the warning again if it is already set,
10666 -- which is what we want, since the constant may have changed.
10667
10668 if Warn then
10669 if not Restriction_Active (R_Id) then
10670 Set_Restriction
10671 (R_Id, N, Integer (UI_To_Int (Val)));
10672 Restriction_Warnings (R_Id) := True;
10673 end if;
10674
10675 -- Real restriction case, set restriction and make sure warning
10676 -- flag is off since real restriction always overrides warning.
10677
10678 else
10679 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
10680 Restriction_Warnings (R_Id) := False;
10681 end if;
10682 end if;
10683
10684 Next (Arg);
10685 end loop;
10686 end Process_Restrictions_Or_Restriction_Warnings;
10687
10688 ---------------------------------
10689 -- Process_Suppress_Unsuppress --
10690 ---------------------------------
10691
10692 -- Note: this procedure makes entries in the check suppress data
10693 -- structures managed by Sem. See spec of package Sem for full
10694 -- details on how we handle recording of check suppression.
10695
10696 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
10697 C : Check_Id;
10698 E : Entity_Id;
10699 E_Id : Node_Id;
10700
10701 In_Package_Spec : constant Boolean :=
10702 Is_Package_Or_Generic_Package (Current_Scope)
10703 and then not In_Package_Body (Current_Scope);
10704
10705 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
10706 -- Used to suppress a single check on the given entity
10707
10708 --------------------------------
10709 -- Suppress_Unsuppress_Echeck --
10710 --------------------------------
10711
10712 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
10713 begin
10714 -- Check for error of trying to set atomic synchronization for
10715 -- a non-atomic variable.
10716
10717 if C = Atomic_Synchronization
10718 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
10719 then
10720 Error_Msg_N
10721 ("pragma & requires atomic type or variable",
10722 Pragma_Identifier (Original_Node (N)));
10723 end if;
10724
10725 Set_Checks_May_Be_Suppressed (E);
10726
10727 if In_Package_Spec then
10728 Push_Global_Suppress_Stack_Entry
10729 (Entity => E,
10730 Check => C,
10731 Suppress => Suppress_Case);
10732 else
10733 Push_Local_Suppress_Stack_Entry
10734 (Entity => E,
10735 Check => C,
10736 Suppress => Suppress_Case);
10737 end if;
10738
10739 -- If this is a first subtype, and the base type is distinct,
10740 -- then also set the suppress flags on the base type.
10741
10742 if Is_First_Subtype (E) and then Etype (E) /= E then
10743 Suppress_Unsuppress_Echeck (Etype (E), C);
10744 end if;
10745 end Suppress_Unsuppress_Echeck;
10746
10747 -- Start of processing for Process_Suppress_Unsuppress
10748
10749 begin
10750 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
10751 -- on user code: we want to generate checks for analysis purposes, as
10752 -- set respectively by -gnatC and -gnatd.F
10753
10754 if Comes_From_Source (N)
10755 and then (CodePeer_Mode or GNATprove_Mode)
10756 then
10757 return;
10758 end if;
10759
10760 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
10761 -- declarative part or a package spec (RM 11.5(5)).
10762
10763 if not Is_Configuration_Pragma then
10764 Check_Is_In_Decl_Part_Or_Package_Spec;
10765 end if;
10766
10767 Check_At_Least_N_Arguments (1);
10768 Check_At_Most_N_Arguments (2);
10769 Check_No_Identifier (Arg1);
10770 Check_Arg_Is_Identifier (Arg1);
10771
10772 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
10773
10774 if C = No_Check_Id then
10775 Error_Pragma_Arg
10776 ("argument of pragma% is not valid check name", Arg1);
10777 end if;
10778
10779 -- Warn that suppress of Elaboration_Check has no effect in SPARK
10780
10781 if C = Elaboration_Check and then SPARK_Mode = On then
10782 Error_Pragma_Arg
10783 ("Suppress of Elaboration_Check ignored in SPARK??",
10784 "\elaboration checking rules are statically enforced "
10785 & "(SPARK RM 7.7)", Arg1);
10786 end if;
10787
10788 -- One-argument case
10789
10790 if Arg_Count = 1 then
10791
10792 -- Make an entry in the local scope suppress table. This is the
10793 -- table that directly shows the current value of the scope
10794 -- suppress check for any check id value.
10795
10796 if C = All_Checks then
10797
10798 -- For All_Checks, we set all specific predefined checks with
10799 -- the exception of Elaboration_Check, which is handled
10800 -- specially because of not wanting All_Checks to have the
10801 -- effect of deactivating static elaboration order processing.
10802 -- Atomic_Synchronization is also not affected, since this is
10803 -- not a real check.
10804
10805 for J in Scope_Suppress.Suppress'Range loop
10806 if J /= Elaboration_Check
10807 and then
10808 J /= Atomic_Synchronization
10809 then
10810 Scope_Suppress.Suppress (J) := Suppress_Case;
10811 end if;
10812 end loop;
10813
10814 -- If not All_Checks, and predefined check, then set appropriate
10815 -- scope entry. Note that we will set Elaboration_Check if this
10816 -- is explicitly specified. Atomic_Synchronization is allowed
10817 -- only if internally generated and entity is atomic.
10818
10819 elsif C in Predefined_Check_Id
10820 and then (not Comes_From_Source (N)
10821 or else C /= Atomic_Synchronization)
10822 then
10823 Scope_Suppress.Suppress (C) := Suppress_Case;
10824 end if;
10825
10826 -- Also make an entry in the Local_Entity_Suppress table
10827
10828 Push_Local_Suppress_Stack_Entry
10829 (Entity => Empty,
10830 Check => C,
10831 Suppress => Suppress_Case);
10832
10833 -- Case of two arguments present, where the check is suppressed for
10834 -- a specified entity (given as the second argument of the pragma)
10835
10836 else
10837 -- This is obsolescent in Ada 2005 mode
10838
10839 if Ada_Version >= Ada_2005 then
10840 Check_Restriction (No_Obsolescent_Features, Arg2);
10841 end if;
10842
10843 Check_Optional_Identifier (Arg2, Name_On);
10844 E_Id := Get_Pragma_Arg (Arg2);
10845 Analyze (E_Id);
10846
10847 if not Is_Entity_Name (E_Id) then
10848 Error_Pragma_Arg
10849 ("second argument of pragma% must be entity name", Arg2);
10850 end if;
10851
10852 E := Entity (E_Id);
10853
10854 if E = Any_Id then
10855 return;
10856 end if;
10857
10858 -- A pragma that applies to a Ghost entity becomes Ghost for the
10859 -- purposes of legality checks and removal of ignored Ghost code.
10860
10861 Mark_Ghost_Pragma (N, E);
10862
10863 -- Enforce RM 11.5(7) which requires that for a pragma that
10864 -- appears within a package spec, the named entity must be
10865 -- within the package spec. We allow the package name itself
10866 -- to be mentioned since that makes sense, although it is not
10867 -- strictly allowed by 11.5(7).
10868
10869 if In_Package_Spec
10870 and then E /= Current_Scope
10871 and then Scope (E) /= Current_Scope
10872 then
10873 Error_Pragma_Arg
10874 ("entity in pragma% is not in package spec (RM 11.5(7))",
10875 Arg2);
10876 end if;
10877
10878 -- Loop through homonyms. As noted below, in the case of a package
10879 -- spec, only homonyms within the package spec are considered.
10880
10881 loop
10882 Suppress_Unsuppress_Echeck (E, C);
10883
10884 if Is_Generic_Instance (E)
10885 and then Is_Subprogram (E)
10886 and then Present (Alias (E))
10887 then
10888 Suppress_Unsuppress_Echeck (Alias (E), C);
10889 end if;
10890
10891 -- Move to next homonym if not aspect spec case
10892
10893 exit when From_Aspect_Specification (N);
10894 E := Homonym (E);
10895 exit when No (E);
10896
10897 -- If we are within a package specification, the pragma only
10898 -- applies to homonyms in the same scope.
10899
10900 exit when In_Package_Spec
10901 and then Scope (E) /= Current_Scope;
10902 end loop;
10903 end if;
10904 end Process_Suppress_Unsuppress;
10905
10906 -------------------------------
10907 -- Record_Independence_Check --
10908 -------------------------------
10909
10910 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
10911 pragma Unreferenced (N, E);
10912 begin
10913 -- For GCC back ends the validation is done a priori
10914 -- ??? This code is dead, might be useful in the future
10915
10916 -- if not AAMP_On_Target then
10917 -- return;
10918 -- end if;
10919
10920 -- Independence_Checks.Append ((N, E));
10921
10922 return;
10923 end Record_Independence_Check;
10924
10925 ------------------
10926 -- Set_Exported --
10927 ------------------
10928
10929 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
10930 begin
10931 if Is_Imported (E) then
10932 Error_Pragma_Arg
10933 ("cannot export entity& that was previously imported", Arg);
10934
10935 elsif Present (Address_Clause (E))
10936 and then not Relaxed_RM_Semantics
10937 then
10938 Error_Pragma_Arg
10939 ("cannot export entity& that has an address clause", Arg);
10940 end if;
10941
10942 Set_Is_Exported (E);
10943
10944 -- Generate a reference for entity explicitly, because the
10945 -- identifier may be overloaded and name resolution will not
10946 -- generate one.
10947
10948 Generate_Reference (E, Arg);
10949
10950 -- Deal with exporting non-library level entity
10951
10952 if not Is_Library_Level_Entity (E) then
10953
10954 -- Not allowed at all for subprograms
10955
10956 if Is_Subprogram (E) then
10957 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
10958
10959 -- Otherwise set public and statically allocated
10960
10961 else
10962 Set_Is_Public (E);
10963 Set_Is_Statically_Allocated (E);
10964
10965 -- Warn if the corresponding W flag is set
10966
10967 if Warn_On_Export_Import
10968
10969 -- Only do this for something that was in the source. Not
10970 -- clear if this can be False now (there used for sure to be
10971 -- cases on some systems where it was False), but anyway the
10972 -- test is harmless if not needed, so it is retained.
10973
10974 and then Comes_From_Source (Arg)
10975 then
10976 Error_Msg_NE
10977 ("?x?& has been made static as a result of Export",
10978 Arg, E);
10979 Error_Msg_N
10980 ("\?x?this usage is non-standard and non-portable",
10981 Arg);
10982 end if;
10983 end if;
10984 end if;
10985
10986 if Warn_On_Export_Import and then Is_Type (E) then
10987 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
10988 end if;
10989
10990 if Warn_On_Export_Import and Inside_A_Generic then
10991 Error_Msg_NE
10992 ("all instances of& will have the same external name?x?",
10993 Arg, E);
10994 end if;
10995 end Set_Exported;
10996
10997 ----------------------------------------------
10998 -- Set_Extended_Import_Export_External_Name --
10999 ----------------------------------------------
11000
11001 procedure Set_Extended_Import_Export_External_Name
11002 (Internal_Ent : Entity_Id;
11003 Arg_External : Node_Id)
11004 is
11005 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
11006 New_Name : Node_Id;
11007
11008 begin
11009 if No (Arg_External) then
11010 return;
11011 end if;
11012
11013 Check_Arg_Is_External_Name (Arg_External);
11014
11015 if Nkind (Arg_External) = N_String_Literal then
11016 if String_Length (Strval (Arg_External)) = 0 then
11017 return;
11018 else
11019 New_Name := Adjust_External_Name_Case (Arg_External);
11020 end if;
11021
11022 elsif Nkind (Arg_External) = N_Identifier then
11023 New_Name := Get_Default_External_Name (Arg_External);
11024
11025 -- Check_Arg_Is_External_Name should let through only identifiers and
11026 -- string literals or static string expressions (which are folded to
11027 -- string literals).
11028
11029 else
11030 raise Program_Error;
11031 end if;
11032
11033 -- If we already have an external name set (by a prior normal Import
11034 -- or Export pragma), then the external names must match
11035
11036 if Present (Interface_Name (Internal_Ent)) then
11037
11038 -- Ignore mismatching names in CodePeer mode, to support some
11039 -- old compilers which would export the same procedure under
11040 -- different names, e.g:
11041 -- procedure P;
11042 -- pragma Export_Procedure (P, "a");
11043 -- pragma Export_Procedure (P, "b");
11044
11045 if CodePeer_Mode then
11046 return;
11047 end if;
11048
11049 Check_Matching_Internal_Names : declare
11050 S1 : constant String_Id := Strval (Old_Name);
11051 S2 : constant String_Id := Strval (New_Name);
11052
11053 procedure Mismatch;
11054 pragma No_Return (Mismatch);
11055 -- Called if names do not match
11056
11057 --------------
11058 -- Mismatch --
11059 --------------
11060
11061 procedure Mismatch is
11062 begin
11063 Error_Msg_Sloc := Sloc (Old_Name);
11064 Error_Pragma_Arg
11065 ("external name does not match that given #",
11066 Arg_External);
11067 end Mismatch;
11068
11069 -- Start of processing for Check_Matching_Internal_Names
11070
11071 begin
11072 if String_Length (S1) /= String_Length (S2) then
11073 Mismatch;
11074
11075 else
11076 for J in 1 .. String_Length (S1) loop
11077 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
11078 Mismatch;
11079 end if;
11080 end loop;
11081 end if;
11082 end Check_Matching_Internal_Names;
11083
11084 -- Otherwise set the given name
11085
11086 else
11087 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
11088 Check_Duplicated_Export_Name (New_Name);
11089 end if;
11090 end Set_Extended_Import_Export_External_Name;
11091
11092 ------------------
11093 -- Set_Imported --
11094 ------------------
11095
11096 procedure Set_Imported (E : Entity_Id) is
11097 begin
11098 -- Error message if already imported or exported
11099
11100 if Is_Exported (E) or else Is_Imported (E) then
11101
11102 -- Error if being set Exported twice
11103
11104 if Is_Exported (E) then
11105 Error_Msg_NE ("entity& was previously exported", N, E);
11106
11107 -- Ignore error in CodePeer mode where we treat all imported
11108 -- subprograms as unknown.
11109
11110 elsif CodePeer_Mode then
11111 goto OK;
11112
11113 -- OK if Import/Interface case
11114
11115 elsif Import_Interface_Present (N) then
11116 goto OK;
11117
11118 -- Error if being set Imported twice
11119
11120 else
11121 Error_Msg_NE ("entity& was previously imported", N, E);
11122 end if;
11123
11124 Error_Msg_Name_1 := Pname;
11125 Error_Msg_N
11126 ("\(pragma% applies to all previous entities)", N);
11127
11128 Error_Msg_Sloc := Sloc (E);
11129 Error_Msg_NE ("\import not allowed for& declared#", N, E);
11130
11131 -- Here if not previously imported or exported, OK to import
11132
11133 else
11134 Set_Is_Imported (E);
11135
11136 -- For subprogram, set Import_Pragma field
11137
11138 if Is_Subprogram (E) then
11139 Set_Import_Pragma (E, N);
11140 end if;
11141
11142 -- If the entity is an object that is not at the library level,
11143 -- then it is statically allocated. We do not worry about objects
11144 -- with address clauses in this context since they are not really
11145 -- imported in the linker sense.
11146
11147 if Is_Object (E)
11148 and then not Is_Library_Level_Entity (E)
11149 and then No (Address_Clause (E))
11150 then
11151 Set_Is_Statically_Allocated (E);
11152 end if;
11153 end if;
11154
11155 <<OK>> null;
11156 end Set_Imported;
11157
11158 -------------------------
11159 -- Set_Mechanism_Value --
11160 -------------------------
11161
11162 -- Note: the mechanism name has not been analyzed (and cannot indeed be
11163 -- analyzed, since it is semantic nonsense), so we get it in the exact
11164 -- form created by the parser.
11165
11166 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
11167 procedure Bad_Mechanism;
11168 pragma No_Return (Bad_Mechanism);
11169 -- Signal bad mechanism name
11170
11171 -------------------
11172 -- Bad_Mechanism --
11173 -------------------
11174
11175 procedure Bad_Mechanism is
11176 begin
11177 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
11178 end Bad_Mechanism;
11179
11180 -- Start of processing for Set_Mechanism_Value
11181
11182 begin
11183 if Mechanism (Ent) /= Default_Mechanism then
11184 Error_Msg_NE
11185 ("mechanism for & has already been set", Mech_Name, Ent);
11186 end if;
11187
11188 -- MECHANISM_NAME ::= value | reference
11189
11190 if Nkind (Mech_Name) = N_Identifier then
11191 if Chars (Mech_Name) = Name_Value then
11192 Set_Mechanism (Ent, By_Copy);
11193 return;
11194
11195 elsif Chars (Mech_Name) = Name_Reference then
11196 Set_Mechanism (Ent, By_Reference);
11197 return;
11198
11199 elsif Chars (Mech_Name) = Name_Copy then
11200 Error_Pragma_Arg
11201 ("bad mechanism name, Value assumed", Mech_Name);
11202
11203 else
11204 Bad_Mechanism;
11205 end if;
11206
11207 else
11208 Bad_Mechanism;
11209 end if;
11210 end Set_Mechanism_Value;
11211
11212 --------------------------
11213 -- Set_Rational_Profile --
11214 --------------------------
11215
11216 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
11217 -- extension to the semantics of renaming declarations.
11218
11219 procedure Set_Rational_Profile is
11220 begin
11221 Implicit_Packing := True;
11222 Overriding_Renamings := True;
11223 Use_VADS_Size := True;
11224 end Set_Rational_Profile;
11225
11226 ---------------------------
11227 -- Set_Ravenscar_Profile --
11228 ---------------------------
11229
11230 -- The tasks to be done here are
11231
11232 -- Set required policies
11233
11234 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11235 -- (For Ravenscar and GNAT_Extended_Ravenscar profiles)
11236 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11237 -- (For GNAT_Ravenscar_EDF profile)
11238 -- pragma Locking_Policy (Ceiling_Locking)
11239
11240 -- Set Detect_Blocking mode
11241
11242 -- Set required restrictions (see System.Rident for detailed list)
11243
11244 -- Set the No_Dependence rules
11245 -- No_Dependence => Ada.Asynchronous_Task_Control
11246 -- No_Dependence => Ada.Calendar
11247 -- No_Dependence => Ada.Execution_Time.Group_Budget
11248 -- No_Dependence => Ada.Execution_Time.Timers
11249 -- No_Dependence => Ada.Task_Attributes
11250 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11251
11252 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is
11253 procedure Set_Error_Msg_To_Profile_Name;
11254 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
11255 -- profile.
11256
11257 -----------------------------------
11258 -- Set_Error_Msg_To_Profile_Name --
11259 -----------------------------------
11260
11261 procedure Set_Error_Msg_To_Profile_Name is
11262 Prof_Nam : constant Node_Id :=
11263 Get_Pragma_Arg
11264 (First (Pragma_Argument_Associations (N)));
11265
11266 begin
11267 Get_Name_String (Chars (Prof_Nam));
11268 Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam));
11269 Error_Msg_Strlen := Name_Len;
11270 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
11271 end Set_Error_Msg_To_Profile_Name;
11272
11273 -- Local variables
11274
11275 Nod : Node_Id;
11276 Pref : Node_Id;
11277 Pref_Id : Node_Id;
11278 Sel_Id : Node_Id;
11279
11280 Profile_Dispatching_Policy : Character;
11281
11282 -- Start of processing for Set_Ravenscar_Profile
11283
11284 begin
11285 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11286
11287 if Profile = GNAT_Ravenscar_EDF then
11288 Profile_Dispatching_Policy := 'E';
11289
11290 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11291
11292 else
11293 Profile_Dispatching_Policy := 'F';
11294 end if;
11295
11296 if Task_Dispatching_Policy /= ' '
11297 and then Task_Dispatching_Policy /= Profile_Dispatching_Policy
11298 then
11299 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11300 Set_Error_Msg_To_Profile_Name;
11301 Error_Pragma ("Profile (~) incompatible with policy#");
11302
11303 -- Set the FIFO_Within_Priorities policy, but always preserve
11304 -- System_Location since we like the error message with the run time
11305 -- name.
11306
11307 else
11308 Task_Dispatching_Policy := Profile_Dispatching_Policy;
11309
11310 if Task_Dispatching_Policy_Sloc /= System_Location then
11311 Task_Dispatching_Policy_Sloc := Loc;
11312 end if;
11313 end if;
11314
11315 -- pragma Locking_Policy (Ceiling_Locking)
11316
11317 if Locking_Policy /= ' '
11318 and then Locking_Policy /= 'C'
11319 then
11320 Error_Msg_Sloc := Locking_Policy_Sloc;
11321 Set_Error_Msg_To_Profile_Name;
11322 Error_Pragma ("Profile (~) incompatible with policy#");
11323
11324 -- Set the Ceiling_Locking policy, but preserve System_Location since
11325 -- we like the error message with the run time name.
11326
11327 else
11328 Locking_Policy := 'C';
11329
11330 if Locking_Policy_Sloc /= System_Location then
11331 Locking_Policy_Sloc := Loc;
11332 end if;
11333 end if;
11334
11335 -- pragma Detect_Blocking
11336
11337 Detect_Blocking := True;
11338
11339 -- Set the corresponding restrictions
11340
11341 Set_Profile_Restrictions
11342 (Profile, N, Warn => Treat_Restrictions_As_Warnings);
11343
11344 -- Set the No_Dependence restrictions
11345
11346 -- The following No_Dependence restrictions:
11347 -- No_Dependence => Ada.Asynchronous_Task_Control
11348 -- No_Dependence => Ada.Calendar
11349 -- No_Dependence => Ada.Task_Attributes
11350 -- are already set by previous call to Set_Profile_Restrictions.
11351
11352 -- Set the following restrictions which were added to Ada 2005:
11353 -- No_Dependence => Ada.Execution_Time.Group_Budget
11354 -- No_Dependence => Ada.Execution_Time.Timers
11355
11356 if Ada_Version >= Ada_2005 then
11357 Pref_Id := Make_Identifier (Loc, Name_Find ("ada"));
11358 Sel_Id := Make_Identifier (Loc, Name_Find ("execution_time"));
11359
11360 Pref :=
11361 Make_Selected_Component
11362 (Sloc => Loc,
11363 Prefix => Pref_Id,
11364 Selector_Name => Sel_Id);
11365
11366 Sel_Id := Make_Identifier (Loc, Name_Find ("group_budgets"));
11367
11368 Nod :=
11369 Make_Selected_Component
11370 (Sloc => Loc,
11371 Prefix => Pref,
11372 Selector_Name => Sel_Id);
11373
11374 Set_Restriction_No_Dependence
11375 (Unit => Nod,
11376 Warn => Treat_Restrictions_As_Warnings,
11377 Profile => Ravenscar);
11378
11379 Sel_Id := Make_Identifier (Loc, Name_Find ("timers"));
11380
11381 Nod :=
11382 Make_Selected_Component
11383 (Sloc => Loc,
11384 Prefix => Pref,
11385 Selector_Name => Sel_Id);
11386
11387 Set_Restriction_No_Dependence
11388 (Unit => Nod,
11389 Warn => Treat_Restrictions_As_Warnings,
11390 Profile => Ravenscar);
11391 end if;
11392
11393 -- Set the following restriction which was added to Ada 2012 (see
11394 -- AI-0171):
11395 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11396
11397 if Ada_Version >= Ada_2012 then
11398 Pref_Id := Make_Identifier (Loc, Name_Find ("system"));
11399 Sel_Id := Make_Identifier (Loc, Name_Find ("multiprocessors"));
11400
11401 Pref :=
11402 Make_Selected_Component
11403 (Sloc => Loc,
11404 Prefix => Pref_Id,
11405 Selector_Name => Sel_Id);
11406
11407 Sel_Id := Make_Identifier (Loc, Name_Find ("dispatching_domains"));
11408
11409 Nod :=
11410 Make_Selected_Component
11411 (Sloc => Loc,
11412 Prefix => Pref,
11413 Selector_Name => Sel_Id);
11414
11415 Set_Restriction_No_Dependence
11416 (Unit => Nod,
11417 Warn => Treat_Restrictions_As_Warnings,
11418 Profile => Ravenscar);
11419 end if;
11420 end Set_Ravenscar_Profile;
11421
11422 -----------------------------------
11423 -- Validate_Acc_Condition_Clause --
11424 -----------------------------------
11425
11426 procedure Validate_Acc_Condition_Clause (Clause : Node_Id) is
11427 begin
11428 Analyze_And_Resolve (Clause);
11429
11430 if not Is_Boolean_Type (Etype (Clause)) then
11431 Error_Pragma ("expected a boolean");
11432 end if;
11433 end Validate_Acc_Condition_Clause;
11434
11435 ------------------------------
11436 -- Validate_Acc_Data_Clause --
11437 ------------------------------
11438
11439 procedure Validate_Acc_Data_Clause (Clause : Node_Id) is
11440 Expr : Node_Id;
11441
11442 begin
11443 Expr := Acc_First (Clause);
11444 while Present (Expr) loop
11445 if Nkind (Expr) /= N_Identifier then
11446 Error_Pragma ("expected an identifer");
11447 end if;
11448
11449 Analyze_And_Resolve (Expr);
11450
11451 Expr := Acc_Next (Expr);
11452 end loop;
11453 end Validate_Acc_Data_Clause;
11454
11455 ----------------------------------
11456 -- Validate_Acc_Int_Expr_Clause --
11457 ----------------------------------
11458
11459 procedure Validate_Acc_Int_Expr_Clause (Clause : Node_Id) is
11460 begin
11461 Analyze_And_Resolve (Clause);
11462
11463 if not Is_Integer_Type (Etype (Clause)) then
11464 Error_Pragma_Arg ("expected an integer", Clause);
11465 end if;
11466 end Validate_Acc_Int_Expr_Clause;
11467
11468 ---------------------------------------
11469 -- Validate_Acc_Int_Expr_List_Clause --
11470 ---------------------------------------
11471
11472 procedure Validate_Acc_Int_Expr_List_Clause (Clause : Node_Id) is
11473 Expr : Node_Id;
11474
11475 begin
11476 Expr := Acc_First (Clause);
11477 while Present (Expr) loop
11478 Analyze_And_Resolve (Expr);
11479
11480 if not Is_Integer_Type (Etype (Expr)) then
11481 Error_Pragma ("expected an integer");
11482 end if;
11483
11484 Expr := Acc_Next (Expr);
11485 end loop;
11486 end Validate_Acc_Int_Expr_List_Clause;
11487
11488 --------------------------------
11489 -- Validate_Acc_Loop_Collapse --
11490 --------------------------------
11491
11492 procedure Validate_Acc_Loop_Collapse (Clause : Node_Id) is
11493 Count : Uint;
11494 Par_Loop : Node_Id;
11495 Stmt : Node_Id;
11496
11497 begin
11498 -- Make sure the argument is a positive integer
11499
11500 Analyze_And_Resolve (Clause);
11501
11502 Count := Static_Integer (Clause);
11503 if Count = No_Uint or else Count < 1 then
11504 Error_Pragma_Arg ("expected a positive integer", Clause);
11505 end if;
11506
11507 -- Then, make sure we have at least Count-1 tightly-nested loops
11508 -- (i.e. loops with no statements in between).
11509
11510 Par_Loop := Parent (Parent (Parent (Clause)));
11511 Stmt := First (Statements (Par_Loop));
11512
11513 -- Skip first pragmas in the parent loop
11514
11515 while Present (Stmt) and then Nkind (Stmt) = N_Pragma loop
11516 Next (Stmt);
11517 end loop;
11518
11519 if not Present (Next (Stmt)) then
11520 while Nkind (Stmt) = N_Loop_Statement and Count > 1 loop
11521 Stmt := First (Statements (Stmt));
11522 exit when Present (Next (Stmt));
11523
11524 Count := Count - 1;
11525 end loop;
11526 end if;
11527
11528 if Count > 1 then
11529 Error_Pragma_Arg
11530 ("Collapse argument too high or loops not tightly nested",
11531 Clause);
11532 end if;
11533 end Validate_Acc_Loop_Collapse;
11534
11535 ----------------------------
11536 -- Validate_Acc_Loop_Gang --
11537 ----------------------------
11538
11539 procedure Validate_Acc_Loop_Gang (Clause : Node_Id) is
11540 begin
11541 Error_Pragma_Arg ("Loop_Gang not implemented", Clause);
11542 end Validate_Acc_Loop_Gang;
11543
11544 ------------------------------
11545 -- Validate_Acc_Loop_Vector --
11546 ------------------------------
11547
11548 procedure Validate_Acc_Loop_Vector (Clause : Node_Id) is
11549 begin
11550 Error_Pragma_Arg ("Loop_Vector not implemented", Clause);
11551 end Validate_Acc_Loop_Vector;
11552
11553 -------------------------------
11554 -- Validate_Acc_Loop_Worker --
11555 -------------------------------
11556
11557 procedure Validate_Acc_Loop_Worker (Clause : Node_Id) is
11558 begin
11559 Error_Pragma_Arg ("Loop_Worker not implemented", Clause);
11560 end Validate_Acc_Loop_Worker;
11561
11562 ---------------------------------
11563 -- Validate_Acc_Name_Reduction --
11564 ---------------------------------
11565
11566 procedure Validate_Acc_Name_Reduction (Clause : Node_Id) is
11567
11568 -- ??? On top of the following operations, the OpenAcc spec adds the
11569 -- "bitwise and", "bitwise or" and modulo for C and ".eqv" and
11570 -- ".neqv" for Fortran. Can we, should we and how do we support them
11571 -- in Ada?
11572
11573 type Reduction_Op is (Add_Op, Mul_Op, Max_Op, Min_Op, And_Op, Or_Op);
11574
11575 function To_Reduction_Op (Op : String) return Reduction_Op;
11576 -- Convert operator Op described by a String into its corresponding
11577 -- enumeration value.
11578
11579 ---------------------
11580 -- To_Reduction_Op --
11581 ---------------------
11582
11583 function To_Reduction_Op (Op : String) return Reduction_Op is
11584 begin
11585 if Op = "+" then
11586 return Add_Op;
11587
11588 elsif Op = "*" then
11589 return Mul_Op;
11590
11591 elsif Op = "max" then
11592 return Max_Op;
11593
11594 elsif Op = "min" then
11595 return Min_Op;
11596
11597 elsif Op = "and" then
11598 return And_Op;
11599
11600 elsif Op = "or" then
11601 return Or_Op;
11602
11603 else
11604 Error_Pragma ("unsuported reduction operation");
11605 end if;
11606 end To_Reduction_Op;
11607
11608 -- Local variables
11609
11610 Seen : constant Elist_Id := New_Elmt_List;
11611
11612 Expr : Node_Id;
11613 Reduc_Op : Node_Id;
11614 Reduc_Var : Node_Id;
11615
11616 -- Start of processing for Validate_Acc_Name_Reduction
11617
11618 begin
11619 -- Reduction operations appear in the following form:
11620 -- ("+" => (a, b), "*" => c)
11621
11622 Expr := First (Component_Associations (Clause));
11623 while Present (Expr) loop
11624 Reduc_Op := First (Choices (Expr));
11625 String_To_Name_Buffer (Strval (Reduc_Op));
11626
11627 case To_Reduction_Op (Name_Buffer (1 .. Name_Len)) is
11628 when Add_Op
11629 | Mul_Op
11630 | Max_Op
11631 | Min_Op
11632 =>
11633 Reduc_Var := Acc_First (Expression (Expr));
11634 while Present (Reduc_Var) loop
11635 Analyze_And_Resolve (Reduc_Var);
11636
11637 if Contains (Seen, Entity (Reduc_Var)) then
11638 Error_Pragma ("variable used in multiple reductions");
11639
11640 else
11641 if Nkind (Reduc_Var) /= N_Identifier
11642 or not Is_Numeric_Type (Etype (Reduc_Var))
11643 then
11644 Error_Pragma
11645 ("expected an identifier for a Numeric");
11646 end if;
11647
11648 Append_Elmt (Entity (Reduc_Var), Seen);
11649 end if;
11650
11651 Reduc_Var := Acc_Next (Reduc_Var);
11652 end loop;
11653
11654 when And_Op
11655 | Or_Op
11656 =>
11657 Reduc_Var := Acc_First (Expression (Expr));
11658 while Present (Reduc_Var) loop
11659 Analyze_And_Resolve (Reduc_Var);
11660
11661 if Contains (Seen, Entity (Reduc_Var)) then
11662 Error_Pragma ("variable used in multiple reductions");
11663
11664 else
11665 if Nkind (Reduc_Var) /= N_Identifier
11666 or not Is_Boolean_Type (Etype (Reduc_Var))
11667 then
11668 Error_Pragma
11669 ("expected a variable of type boolean");
11670 end if;
11671
11672 Append_Elmt (Entity (Reduc_Var), Seen);
11673 end if;
11674
11675 Reduc_Var := Acc_Next (Reduc_Var);
11676 end loop;
11677 end case;
11678
11679 Next (Expr);
11680 end loop;
11681 end Validate_Acc_Name_Reduction;
11682
11683 -----------------------------------
11684 -- Validate_Acc_Size_Expressions --
11685 -----------------------------------
11686
11687 procedure Validate_Acc_Size_Expressions (Clause : Node_Id) is
11688 function Validate_Size_Expr (Expr : Node_Id) return Boolean;
11689 -- A size expr is either an integer expression or "*"
11690
11691 ------------------------
11692 -- Validate_Size_Expr --
11693 ------------------------
11694
11695 function Validate_Size_Expr (Expr : Node_Id) return Boolean is
11696 begin
11697 if Nkind (Expr) = N_Operator_Symbol then
11698 return Get_String_Char (Strval (Expr), 1) = Get_Char_Code ('*');
11699 end if;
11700
11701 Analyze_And_Resolve (Expr);
11702
11703 return Is_Integer_Type (Etype (Expr));
11704 end Validate_Size_Expr;
11705
11706 -- Local variables
11707
11708 Expr : Node_Id;
11709
11710 -- Start of processing for Validate_Acc_Size_Expressions
11711
11712 begin
11713 Expr := Acc_First (Clause);
11714 while Present (Expr) loop
11715 if not Validate_Size_Expr (Expr) then
11716 Error_Pragma
11717 ("Size expressions should be either integers or '*'");
11718 end if;
11719
11720 Expr := Acc_Next (Expr);
11721 end loop;
11722 end Validate_Acc_Size_Expressions;
11723
11724 -- Start of processing for Analyze_Pragma
11725
11726 begin
11727 -- The following code is a defense against recursion. Not clear that
11728 -- this can happen legitimately, but perhaps some error situations can
11729 -- cause it, and we did see this recursion during testing.
11730
11731 if Analyzed (N) then
11732 return;
11733 else
11734 Set_Analyzed (N);
11735 end if;
11736
11737 Check_Restriction_No_Use_Of_Pragma (N);
11738
11739 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
11740 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
11741
11742 if Should_Ignore_Pragma_Sem (N)
11743 or else (Prag_Id = Pragma_Default_Scalar_Storage_Order
11744 and then Ignore_Rep_Clauses)
11745 then
11746 return;
11747 end if;
11748
11749 -- Deal with unrecognized pragma
11750
11751 if not Is_Pragma_Name (Pname) then
11752 if Warn_On_Unrecognized_Pragma then
11753 Error_Msg_Name_1 := Pname;
11754 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
11755
11756 for PN in First_Pragma_Name .. Last_Pragma_Name loop
11757 if Is_Bad_Spelling_Of (Pname, PN) then
11758 Error_Msg_Name_1 := PN;
11759 Error_Msg_N -- CODEFIX
11760 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
11761 exit;
11762 end if;
11763 end loop;
11764 end if;
11765
11766 return;
11767 end if;
11768
11769 -- Here to start processing for recognized pragma
11770
11771 Pname := Original_Aspect_Pragma_Name (N);
11772
11773 -- Capture setting of Opt.Uneval_Old
11774
11775 case Opt.Uneval_Old is
11776 when 'A' =>
11777 Set_Uneval_Old_Accept (N);
11778
11779 when 'E' =>
11780 null;
11781
11782 when 'W' =>
11783 Set_Uneval_Old_Warn (N);
11784
11785 when others =>
11786 raise Program_Error;
11787 end case;
11788
11789 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
11790 -- is already set, indicating that we have already checked the policy
11791 -- at the right point. This happens for example in the case of a pragma
11792 -- that is derived from an Aspect.
11793
11794 if Is_Ignored (N) or else Is_Checked (N) then
11795 null;
11796
11797 -- For a pragma that is a rewriting of another pragma, copy the
11798 -- Is_Checked/Is_Ignored status from the rewritten pragma.
11799
11800 elsif Is_Rewrite_Substitution (N)
11801 and then Nkind (Original_Node (N)) = N_Pragma
11802 then
11803 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
11804 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
11805
11806 -- Otherwise query the applicable policy at this point
11807
11808 else
11809 Check_Applicable_Policy (N);
11810
11811 -- If pragma is disabled, rewrite as NULL and skip analysis
11812
11813 if Is_Disabled (N) then
11814 Rewrite (N, Make_Null_Statement (Loc));
11815 Analyze (N);
11816 raise Pragma_Exit;
11817 end if;
11818 end if;
11819
11820 -- Preset arguments
11821
11822 Arg_Count := 0;
11823 Arg1 := Empty;
11824 Arg2 := Empty;
11825 Arg3 := Empty;
11826 Arg4 := Empty;
11827
11828 if Present (Pragma_Argument_Associations (N)) then
11829 Arg_Count := List_Length (Pragma_Argument_Associations (N));
11830 Arg1 := First (Pragma_Argument_Associations (N));
11831
11832 if Present (Arg1) then
11833 Arg2 := Next (Arg1);
11834
11835 if Present (Arg2) then
11836 Arg3 := Next (Arg2);
11837
11838 if Present (Arg3) then
11839 Arg4 := Next (Arg3);
11840 end if;
11841 end if;
11842 end if;
11843 end if;
11844
11845 -- An enumeration type defines the pragmas that are supported by the
11846 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
11847 -- into the corresponding enumeration value for the following case.
11848
11849 case Prag_Id is
11850
11851 -----------------
11852 -- Abort_Defer --
11853 -----------------
11854
11855 -- pragma Abort_Defer;
11856
11857 when Pragma_Abort_Defer =>
11858 GNAT_Pragma;
11859 Check_Arg_Count (0);
11860
11861 -- The only required semantic processing is to check the
11862 -- placement. This pragma must appear at the start of the
11863 -- statement sequence of a handled sequence of statements.
11864
11865 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
11866 or else N /= First (Statements (Parent (N)))
11867 then
11868 Pragma_Misplaced;
11869 end if;
11870
11871 --------------------
11872 -- Abstract_State --
11873 --------------------
11874
11875 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
11876
11877 -- ABSTRACT_STATE_LIST ::=
11878 -- null
11879 -- | STATE_NAME_WITH_OPTIONS
11880 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
11881
11882 -- STATE_NAME_WITH_OPTIONS ::=
11883 -- STATE_NAME
11884 -- | (STATE_NAME with OPTION_LIST)
11885
11886 -- OPTION_LIST ::= OPTION {, OPTION}
11887
11888 -- OPTION ::=
11889 -- SIMPLE_OPTION
11890 -- | NAME_VALUE_OPTION
11891
11892 -- SIMPLE_OPTION ::= Ghost | Synchronous
11893
11894 -- NAME_VALUE_OPTION ::=
11895 -- Part_Of => ABSTRACT_STATE
11896 -- | External [=> EXTERNAL_PROPERTY_LIST]
11897
11898 -- EXTERNAL_PROPERTY_LIST ::=
11899 -- EXTERNAL_PROPERTY
11900 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
11901
11902 -- EXTERNAL_PROPERTY ::=
11903 -- Async_Readers [=> boolean_EXPRESSION]
11904 -- | Async_Writers [=> boolean_EXPRESSION]
11905 -- | Effective_Reads [=> boolean_EXPRESSION]
11906 -- | Effective_Writes [=> boolean_EXPRESSION]
11907 -- others => boolean_EXPRESSION
11908
11909 -- STATE_NAME ::= defining_identifier
11910
11911 -- ABSTRACT_STATE ::= name
11912
11913 -- Characteristics:
11914
11915 -- * Analysis - The annotation is fully analyzed immediately upon
11916 -- elaboration as it cannot forward reference entities.
11917
11918 -- * Expansion - None.
11919
11920 -- * Template - The annotation utilizes the generic template of the
11921 -- related package declaration.
11922
11923 -- * Globals - The annotation cannot reference global entities.
11924
11925 -- * Instance - The annotation is instantiated automatically when
11926 -- the related generic package is instantiated.
11927
11928 when Pragma_Abstract_State => Abstract_State : declare
11929 Missing_Parentheses : Boolean := False;
11930 -- Flag set when a state declaration with options is not properly
11931 -- parenthesized.
11932
11933 -- Flags used to verify the consistency of states
11934
11935 Non_Null_Seen : Boolean := False;
11936 Null_Seen : Boolean := False;
11937
11938 procedure Analyze_Abstract_State
11939 (State : Node_Id;
11940 Pack_Id : Entity_Id);
11941 -- Verify the legality of a single state declaration. Create and
11942 -- decorate a state abstraction entity and introduce it into the
11943 -- visibility chain. Pack_Id denotes the entity or the related
11944 -- package where pragma Abstract_State appears.
11945
11946 procedure Malformed_State_Error (State : Node_Id);
11947 -- Emit an error concerning the illegal declaration of abstract
11948 -- state State. This routine diagnoses syntax errors that lead to
11949 -- a different parse tree. The error is issued regardless of the
11950 -- SPARK mode in effect.
11951
11952 ----------------------------
11953 -- Analyze_Abstract_State --
11954 ----------------------------
11955
11956 procedure Analyze_Abstract_State
11957 (State : Node_Id;
11958 Pack_Id : Entity_Id)
11959 is
11960 -- Flags used to verify the consistency of options
11961
11962 AR_Seen : Boolean := False;
11963 AW_Seen : Boolean := False;
11964 ER_Seen : Boolean := False;
11965 EW_Seen : Boolean := False;
11966 External_Seen : Boolean := False;
11967 Ghost_Seen : Boolean := False;
11968 Others_Seen : Boolean := False;
11969 Part_Of_Seen : Boolean := False;
11970 Synchronous_Seen : Boolean := False;
11971
11972 -- Flags used to store the static value of all external states'
11973 -- expressions.
11974
11975 AR_Val : Boolean := False;
11976 AW_Val : Boolean := False;
11977 ER_Val : Boolean := False;
11978 EW_Val : Boolean := False;
11979
11980 State_Id : Entity_Id := Empty;
11981 -- The entity to be generated for the current state declaration
11982
11983 procedure Analyze_External_Option (Opt : Node_Id);
11984 -- Verify the legality of option External
11985
11986 procedure Analyze_External_Property
11987 (Prop : Node_Id;
11988 Expr : Node_Id := Empty);
11989 -- Verify the legailty of a single external property. Prop
11990 -- denotes the external property. Expr is the expression used
11991 -- to set the property.
11992
11993 procedure Analyze_Part_Of_Option (Opt : Node_Id);
11994 -- Verify the legality of option Part_Of
11995
11996 procedure Check_Duplicate_Option
11997 (Opt : Node_Id;
11998 Status : in out Boolean);
11999 -- Flag Status denotes whether a particular option has been
12000 -- seen while processing a state. This routine verifies that
12001 -- Opt is not a duplicate option and sets the flag Status
12002 -- (SPARK RM 7.1.4(1)).
12003
12004 procedure Check_Duplicate_Property
12005 (Prop : Node_Id;
12006 Status : in out Boolean);
12007 -- Flag Status denotes whether a particular property has been
12008 -- seen while processing option External. This routine verifies
12009 -- that Prop is not a duplicate property and sets flag Status.
12010 -- Opt is not a duplicate property and sets the flag Status.
12011 -- (SPARK RM 7.1.4(2))
12012
12013 procedure Check_Ghost_Synchronous;
12014 -- Ensure that the abstract state is not subject to both Ghost
12015 -- and Synchronous simple options. Emit an error if this is the
12016 -- case.
12017
12018 procedure Create_Abstract_State
12019 (Nam : Name_Id;
12020 Decl : Node_Id;
12021 Loc : Source_Ptr;
12022 Is_Null : Boolean);
12023 -- Generate an abstract state entity with name Nam and enter it
12024 -- into visibility. Decl is the "declaration" of the state as
12025 -- it appears in pragma Abstract_State. Loc is the location of
12026 -- the related state "declaration". Flag Is_Null should be set
12027 -- when the associated Abstract_State pragma defines a null
12028 -- state.
12029
12030 -----------------------------
12031 -- Analyze_External_Option --
12032 -----------------------------
12033
12034 procedure Analyze_External_Option (Opt : Node_Id) is
12035 Errors : constant Nat := Serious_Errors_Detected;
12036 Prop : Node_Id;
12037 Props : Node_Id := Empty;
12038
12039 begin
12040 if Nkind (Opt) = N_Component_Association then
12041 Props := Expression (Opt);
12042 end if;
12043
12044 -- External state with properties
12045
12046 if Present (Props) then
12047
12048 -- Multiple properties appear as an aggregate
12049
12050 if Nkind (Props) = N_Aggregate then
12051
12052 -- Simple property form
12053
12054 Prop := First (Expressions (Props));
12055 while Present (Prop) loop
12056 Analyze_External_Property (Prop);
12057 Next (Prop);
12058 end loop;
12059
12060 -- Property with expression form
12061
12062 Prop := First (Component_Associations (Props));
12063 while Present (Prop) loop
12064 Analyze_External_Property
12065 (Prop => First (Choices (Prop)),
12066 Expr => Expression (Prop));
12067
12068 Next (Prop);
12069 end loop;
12070
12071 -- Single property
12072
12073 else
12074 Analyze_External_Property (Props);
12075 end if;
12076
12077 -- An external state defined without any properties defaults
12078 -- all properties to True.
12079
12080 else
12081 AR_Val := True;
12082 AW_Val := True;
12083 ER_Val := True;
12084 EW_Val := True;
12085 end if;
12086
12087 -- Once all external properties have been processed, verify
12088 -- their mutual interaction. Do not perform the check when
12089 -- at least one of the properties is illegal as this will
12090 -- produce a bogus error.
12091
12092 if Errors = Serious_Errors_Detected then
12093 Check_External_Properties
12094 (State, AR_Val, AW_Val, ER_Val, EW_Val);
12095 end if;
12096 end Analyze_External_Option;
12097
12098 -------------------------------
12099 -- Analyze_External_Property --
12100 -------------------------------
12101
12102 procedure Analyze_External_Property
12103 (Prop : Node_Id;
12104 Expr : Node_Id := Empty)
12105 is
12106 Expr_Val : Boolean;
12107
12108 begin
12109 -- Check the placement of "others" (if available)
12110
12111 if Nkind (Prop) = N_Others_Choice then
12112 if Others_Seen then
12113 SPARK_Msg_N
12114 ("only one others choice allowed in option External",
12115 Prop);
12116 else
12117 Others_Seen := True;
12118 end if;
12119
12120 elsif Others_Seen then
12121 SPARK_Msg_N
12122 ("others must be the last property in option External",
12123 Prop);
12124
12125 -- The only remaining legal options are the four predefined
12126 -- external properties.
12127
12128 elsif Nkind (Prop) = N_Identifier
12129 and then Nam_In (Chars (Prop), Name_Async_Readers,
12130 Name_Async_Writers,
12131 Name_Effective_Reads,
12132 Name_Effective_Writes)
12133 then
12134 null;
12135
12136 -- Otherwise the construct is not a valid property
12137
12138 else
12139 SPARK_Msg_N ("invalid external state property", Prop);
12140 return;
12141 end if;
12142
12143 -- Ensure that the expression of the external state property
12144 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
12145
12146 if Present (Expr) then
12147 Analyze_And_Resolve (Expr, Standard_Boolean);
12148
12149 if Is_OK_Static_Expression (Expr) then
12150 Expr_Val := Is_True (Expr_Value (Expr));
12151 else
12152 SPARK_Msg_N
12153 ("expression of external state property must be "
12154 & "static", Expr);
12155 return;
12156 end if;
12157
12158 -- The lack of expression defaults the property to True
12159
12160 else
12161 Expr_Val := True;
12162 end if;
12163
12164 -- Named properties
12165
12166 if Nkind (Prop) = N_Identifier then
12167 if Chars (Prop) = Name_Async_Readers then
12168 Check_Duplicate_Property (Prop, AR_Seen);
12169 AR_Val := Expr_Val;
12170
12171 elsif Chars (Prop) = Name_Async_Writers then
12172 Check_Duplicate_Property (Prop, AW_Seen);
12173 AW_Val := Expr_Val;
12174
12175 elsif Chars (Prop) = Name_Effective_Reads then
12176 Check_Duplicate_Property (Prop, ER_Seen);
12177 ER_Val := Expr_Val;
12178
12179 else
12180 Check_Duplicate_Property (Prop, EW_Seen);
12181 EW_Val := Expr_Val;
12182 end if;
12183
12184 -- The handling of property "others" must take into account
12185 -- all other named properties that have been encountered so
12186 -- far. Only those that have not been seen are affected by
12187 -- "others".
12188
12189 else
12190 if not AR_Seen then
12191 AR_Val := Expr_Val;
12192 end if;
12193
12194 if not AW_Seen then
12195 AW_Val := Expr_Val;
12196 end if;
12197
12198 if not ER_Seen then
12199 ER_Val := Expr_Val;
12200 end if;
12201
12202 if not EW_Seen then
12203 EW_Val := Expr_Val;
12204 end if;
12205 end if;
12206 end Analyze_External_Property;
12207
12208 ----------------------------
12209 -- Analyze_Part_Of_Option --
12210 ----------------------------
12211
12212 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
12213 Encap : constant Node_Id := Expression (Opt);
12214 Constits : Elist_Id;
12215 Encap_Id : Entity_Id;
12216 Legal : Boolean;
12217
12218 begin
12219 Check_Duplicate_Option (Opt, Part_Of_Seen);
12220
12221 Analyze_Part_Of
12222 (Indic => First (Choices (Opt)),
12223 Item_Id => State_Id,
12224 Encap => Encap,
12225 Encap_Id => Encap_Id,
12226 Legal => Legal);
12227
12228 -- The Part_Of indicator transforms the abstract state into
12229 -- a constituent of the encapsulating state or single
12230 -- concurrent type.
12231
12232 if Legal then
12233 pragma Assert (Present (Encap_Id));
12234 Constits := Part_Of_Constituents (Encap_Id);
12235
12236 if No (Constits) then
12237 Constits := New_Elmt_List;
12238 Set_Part_Of_Constituents (Encap_Id, Constits);
12239 end if;
12240
12241 Append_Elmt (State_Id, Constits);
12242 Set_Encapsulating_State (State_Id, Encap_Id);
12243 end if;
12244 end Analyze_Part_Of_Option;
12245
12246 ----------------------------
12247 -- Check_Duplicate_Option --
12248 ----------------------------
12249
12250 procedure Check_Duplicate_Option
12251 (Opt : Node_Id;
12252 Status : in out Boolean)
12253 is
12254 begin
12255 if Status then
12256 SPARK_Msg_N ("duplicate state option", Opt);
12257 end if;
12258
12259 Status := True;
12260 end Check_Duplicate_Option;
12261
12262 ------------------------------
12263 -- Check_Duplicate_Property --
12264 ------------------------------
12265
12266 procedure Check_Duplicate_Property
12267 (Prop : Node_Id;
12268 Status : in out Boolean)
12269 is
12270 begin
12271 if Status then
12272 SPARK_Msg_N ("duplicate external property", Prop);
12273 end if;
12274
12275 Status := True;
12276 end Check_Duplicate_Property;
12277
12278 -----------------------------
12279 -- Check_Ghost_Synchronous --
12280 -----------------------------
12281
12282 procedure Check_Ghost_Synchronous is
12283 begin
12284 -- A synchronized abstract state cannot be Ghost and vice
12285 -- versa (SPARK RM 6.9(19)).
12286
12287 if Ghost_Seen and Synchronous_Seen then
12288 SPARK_Msg_N ("synchronized state cannot be ghost", State);
12289 end if;
12290 end Check_Ghost_Synchronous;
12291
12292 ---------------------------
12293 -- Create_Abstract_State --
12294 ---------------------------
12295
12296 procedure Create_Abstract_State
12297 (Nam : Name_Id;
12298 Decl : Node_Id;
12299 Loc : Source_Ptr;
12300 Is_Null : Boolean)
12301 is
12302 begin
12303 -- The abstract state may be semi-declared when the related
12304 -- package was withed through a limited with clause. In that
12305 -- case reuse the entity to fully declare the state.
12306
12307 if Present (Decl) and then Present (Entity (Decl)) then
12308 State_Id := Entity (Decl);
12309
12310 -- Otherwise the elaboration of pragma Abstract_State
12311 -- declares the state.
12312
12313 else
12314 State_Id := Make_Defining_Identifier (Loc, Nam);
12315
12316 if Present (Decl) then
12317 Set_Entity (Decl, State_Id);
12318 end if;
12319 end if;
12320
12321 -- Null states never come from source
12322
12323 Set_Comes_From_Source (State_Id, not Is_Null);
12324 Set_Parent (State_Id, State);
12325 Set_Ekind (State_Id, E_Abstract_State);
12326 Set_Etype (State_Id, Standard_Void_Type);
12327 Set_Encapsulating_State (State_Id, Empty);
12328
12329 -- Set the SPARK mode from the current context
12330
12331 Set_SPARK_Pragma (State_Id, SPARK_Mode_Pragma);
12332 Set_SPARK_Pragma_Inherited (State_Id);
12333
12334 -- An abstract state declared within a Ghost region becomes
12335 -- Ghost (SPARK RM 6.9(2)).
12336
12337 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then
12338 Set_Is_Ghost_Entity (State_Id);
12339 end if;
12340
12341 -- Establish a link between the state declaration and the
12342 -- abstract state entity. Note that a null state remains as
12343 -- N_Null and does not carry any linkages.
12344
12345 if not Is_Null then
12346 if Present (Decl) then
12347 Set_Entity (Decl, State_Id);
12348 Set_Etype (Decl, Standard_Void_Type);
12349 end if;
12350
12351 -- Every non-null state must be defined, nameable and
12352 -- resolvable.
12353
12354 Push_Scope (Pack_Id);
12355 Generate_Definition (State_Id);
12356 Enter_Name (State_Id);
12357 Pop_Scope;
12358 end if;
12359 end Create_Abstract_State;
12360
12361 -- Local variables
12362
12363 Opt : Node_Id;
12364 Opt_Nam : Node_Id;
12365
12366 -- Start of processing for Analyze_Abstract_State
12367
12368 begin
12369 -- A package with a null abstract state is not allowed to
12370 -- declare additional states.
12371
12372 if Null_Seen then
12373 SPARK_Msg_NE
12374 ("package & has null abstract state", State, Pack_Id);
12375
12376 -- Null states appear as internally generated entities
12377
12378 elsif Nkind (State) = N_Null then
12379 Create_Abstract_State
12380 (Nam => New_Internal_Name ('S'),
12381 Decl => Empty,
12382 Loc => Sloc (State),
12383 Is_Null => True);
12384 Null_Seen := True;
12385
12386 -- Catch a case where a null state appears in a list of
12387 -- non-null states.
12388
12389 if Non_Null_Seen then
12390 SPARK_Msg_NE
12391 ("package & has non-null abstract state",
12392 State, Pack_Id);
12393 end if;
12394
12395 -- Simple state declaration
12396
12397 elsif Nkind (State) = N_Identifier then
12398 Create_Abstract_State
12399 (Nam => Chars (State),
12400 Decl => State,
12401 Loc => Sloc (State),
12402 Is_Null => False);
12403 Non_Null_Seen := True;
12404
12405 -- State declaration with various options. This construct
12406 -- appears as an extension aggregate in the tree.
12407
12408 elsif Nkind (State) = N_Extension_Aggregate then
12409 if Nkind (Ancestor_Part (State)) = N_Identifier then
12410 Create_Abstract_State
12411 (Nam => Chars (Ancestor_Part (State)),
12412 Decl => Ancestor_Part (State),
12413 Loc => Sloc (Ancestor_Part (State)),
12414 Is_Null => False);
12415 Non_Null_Seen := True;
12416 else
12417 SPARK_Msg_N
12418 ("state name must be an identifier",
12419 Ancestor_Part (State));
12420 end if;
12421
12422 -- Options External, Ghost and Synchronous appear as
12423 -- expressions.
12424
12425 Opt := First (Expressions (State));
12426 while Present (Opt) loop
12427 if Nkind (Opt) = N_Identifier then
12428
12429 -- External
12430
12431 if Chars (Opt) = Name_External then
12432 Check_Duplicate_Option (Opt, External_Seen);
12433 Analyze_External_Option (Opt);
12434
12435 -- Ghost
12436
12437 elsif Chars (Opt) = Name_Ghost then
12438 Check_Duplicate_Option (Opt, Ghost_Seen);
12439 Check_Ghost_Synchronous;
12440
12441 if Present (State_Id) then
12442 Set_Is_Ghost_Entity (State_Id);
12443 end if;
12444
12445 -- Synchronous
12446
12447 elsif Chars (Opt) = Name_Synchronous then
12448 Check_Duplicate_Option (Opt, Synchronous_Seen);
12449 Check_Ghost_Synchronous;
12450
12451 -- Option Part_Of without an encapsulating state is
12452 -- illegal (SPARK RM 7.1.4(8)).
12453
12454 elsif Chars (Opt) = Name_Part_Of then
12455 SPARK_Msg_N
12456 ("indicator Part_Of must denote abstract state, "
12457 & "single protected type or single task type",
12458 Opt);
12459
12460 -- Do not emit an error message when a previous state
12461 -- declaration with options was not parenthesized as
12462 -- the option is actually another state declaration.
12463 --
12464 -- with Abstract_State
12465 -- (State_1 with ..., -- missing parentheses
12466 -- (State_2 with ...),
12467 -- State_3) -- ok state declaration
12468
12469 elsif Missing_Parentheses then
12470 null;
12471
12472 -- Otherwise the option is not allowed. Note that it
12473 -- is not possible to distinguish between an option
12474 -- and a state declaration when a previous state with
12475 -- options not properly parentheses.
12476 --
12477 -- with Abstract_State
12478 -- (State_1 with ..., -- missing parentheses
12479 -- State_2); -- could be an option
12480
12481 else
12482 SPARK_Msg_N
12483 ("simple option not allowed in state declaration",
12484 Opt);
12485 end if;
12486
12487 -- Catch a case where missing parentheses around a state
12488 -- declaration with options cause a subsequent state
12489 -- declaration with options to be treated as an option.
12490 --
12491 -- with Abstract_State
12492 -- (State_1 with ..., -- missing parentheses
12493 -- (State_2 with ...))
12494
12495 elsif Nkind (Opt) = N_Extension_Aggregate then
12496 Missing_Parentheses := True;
12497 SPARK_Msg_N
12498 ("state declaration must be parenthesized",
12499 Ancestor_Part (State));
12500
12501 -- Otherwise the option is malformed
12502
12503 else
12504 SPARK_Msg_N ("malformed option", Opt);
12505 end if;
12506
12507 Next (Opt);
12508 end loop;
12509
12510 -- Options External and Part_Of appear as component
12511 -- associations.
12512
12513 Opt := First (Component_Associations (State));
12514 while Present (Opt) loop
12515 Opt_Nam := First (Choices (Opt));
12516
12517 if Nkind (Opt_Nam) = N_Identifier then
12518 if Chars (Opt_Nam) = Name_External then
12519 Analyze_External_Option (Opt);
12520
12521 elsif Chars (Opt_Nam) = Name_Part_Of then
12522 Analyze_Part_Of_Option (Opt);
12523
12524 else
12525 SPARK_Msg_N ("invalid state option", Opt);
12526 end if;
12527 else
12528 SPARK_Msg_N ("invalid state option", Opt);
12529 end if;
12530
12531 Next (Opt);
12532 end loop;
12533
12534 -- Any other attempt to declare a state is illegal
12535
12536 else
12537 Malformed_State_Error (State);
12538 return;
12539 end if;
12540
12541 -- Guard against a junk state. In such cases no entity is
12542 -- generated and the subsequent checks cannot be applied.
12543
12544 if Present (State_Id) then
12545
12546 -- Verify whether the state does not introduce an illegal
12547 -- hidden state within a package subject to a null abstract
12548 -- state.
12549
12550 Check_No_Hidden_State (State_Id);
12551
12552 -- Check whether the lack of option Part_Of agrees with the
12553 -- placement of the abstract state with respect to the state
12554 -- space.
12555
12556 if not Part_Of_Seen then
12557 Check_Missing_Part_Of (State_Id);
12558 end if;
12559
12560 -- Associate the state with its related package
12561
12562 if No (Abstract_States (Pack_Id)) then
12563 Set_Abstract_States (Pack_Id, New_Elmt_List);
12564 end if;
12565
12566 Append_Elmt (State_Id, Abstract_States (Pack_Id));
12567 end if;
12568 end Analyze_Abstract_State;
12569
12570 ---------------------------
12571 -- Malformed_State_Error --
12572 ---------------------------
12573
12574 procedure Malformed_State_Error (State : Node_Id) is
12575 begin
12576 Error_Msg_N ("malformed abstract state declaration", State);
12577
12578 -- An abstract state with a simple option is being declared
12579 -- with "=>" rather than the legal "with". The state appears
12580 -- as a component association.
12581
12582 if Nkind (State) = N_Component_Association then
12583 Error_Msg_N ("\use WITH to specify simple option", State);
12584 end if;
12585 end Malformed_State_Error;
12586
12587 -- Local variables
12588
12589 Pack_Decl : Node_Id;
12590 Pack_Id : Entity_Id;
12591 State : Node_Id;
12592 States : Node_Id;
12593
12594 -- Start of processing for Abstract_State
12595
12596 begin
12597 GNAT_Pragma;
12598 Check_No_Identifiers;
12599 Check_Arg_Count (1);
12600
12601 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
12602
12603 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
12604 N_Package_Declaration)
12605 then
12606 Pragma_Misplaced;
12607 return;
12608 end if;
12609
12610 Pack_Id := Defining_Entity (Pack_Decl);
12611
12612 -- A pragma that applies to a Ghost entity becomes Ghost for the
12613 -- purposes of legality checks and removal of ignored Ghost code.
12614
12615 Mark_Ghost_Pragma (N, Pack_Id);
12616 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
12617
12618 -- Chain the pragma on the contract for completeness
12619
12620 Add_Contract_Item (N, Pack_Id);
12621
12622 -- The legality checks of pragmas Abstract_State, Initializes, and
12623 -- Initial_Condition are affected by the SPARK mode in effect. In
12624 -- addition, these three pragmas are subject to an inherent order:
12625
12626 -- 1) Abstract_State
12627 -- 2) Initializes
12628 -- 3) Initial_Condition
12629
12630 -- Analyze all these pragmas in the order outlined above
12631
12632 Analyze_If_Present (Pragma_SPARK_Mode);
12633 States := Expression (Get_Argument (N, Pack_Id));
12634
12635 -- Multiple non-null abstract states appear as an aggregate
12636
12637 if Nkind (States) = N_Aggregate then
12638 State := First (Expressions (States));
12639 while Present (State) loop
12640 Analyze_Abstract_State (State, Pack_Id);
12641 Next (State);
12642 end loop;
12643
12644 -- An abstract state with a simple option is being illegaly
12645 -- declared with "=>" rather than "with". In this case the
12646 -- state declaration appears as a component association.
12647
12648 if Present (Component_Associations (States)) then
12649 State := First (Component_Associations (States));
12650 while Present (State) loop
12651 Malformed_State_Error (State);
12652 Next (State);
12653 end loop;
12654 end if;
12655
12656 -- Various forms of a single abstract state. Note that these may
12657 -- include malformed state declarations.
12658
12659 else
12660 Analyze_Abstract_State (States, Pack_Id);
12661 end if;
12662
12663 Analyze_If_Present (Pragma_Initializes);
12664 Analyze_If_Present (Pragma_Initial_Condition);
12665 end Abstract_State;
12666
12667 --------------
12668 -- Acc_Data --
12669 --------------
12670
12671 when Pragma_Acc_Data => Acc_Data : declare
12672 Clause_Names : constant Name_List :=
12673 (Name_Attach,
12674 Name_Copy,
12675 Name_Copy_In,
12676 Name_Copy_Out,
12677 Name_Create,
12678 Name_Delete,
12679 Name_Detach,
12680 Name_Device_Ptr,
12681 Name_No_Create,
12682 Name_Present);
12683
12684 Clause : Node_Id;
12685 Clauses : Args_List (Clause_Names'Range);
12686
12687 begin
12688 if not OpenAcc_Enabled then
12689 return;
12690 end if;
12691
12692 GNAT_Pragma;
12693
12694 if Nkind (Parent (N)) /= N_Loop_Statement then
12695 Error_Pragma
12696 ("Acc_Data pragma should be placed in loop or block "
12697 & "statements");
12698 end if;
12699
12700 Gather_Associations (Clause_Names, Clauses);
12701
12702 for Id in Clause_Names'First .. Clause_Names'Last loop
12703 Clause := Clauses (Id);
12704
12705 if Present (Clause) then
12706 case Clause_Names (Id) is
12707 when Name_Copy
12708 | Name_Copy_In
12709 | Name_Copy_Out
12710 | Name_Create
12711 | Name_Device_Ptr
12712 | Name_Present
12713 =>
12714 Validate_Acc_Data_Clause (Clause);
12715
12716 when Name_Attach
12717 | Name_Detach
12718 | Name_Delete
12719 | Name_No_Create
12720 =>
12721 Error_Pragma ("unsupported pragma clause");
12722
12723 when others =>
12724 raise Program_Error;
12725 end case;
12726 end if;
12727 end loop;
12728
12729 Set_Is_OpenAcc_Environment (Parent (N));
12730 end Acc_Data;
12731
12732 --------------
12733 -- Acc_Loop --
12734 --------------
12735
12736 when Pragma_Acc_Loop => Acc_Loop : declare
12737 Clause_Names : constant Name_List :=
12738 (Name_Auto,
12739 Name_Collapse,
12740 Name_Gang,
12741 Name_Independent,
12742 Name_Acc_Private,
12743 Name_Reduction,
12744 Name_Seq,
12745 Name_Tile,
12746 Name_Vector,
12747 Name_Worker);
12748
12749 Clause : Node_Id;
12750 Clauses : Args_List (Clause_Names'Range);
12751 Par : Node_Id;
12752
12753 begin
12754 if not OpenAcc_Enabled then
12755 return;
12756 end if;
12757
12758 GNAT_Pragma;
12759
12760 -- Make sure the pragma is in an openacc construct
12761
12762 Check_Loop_Pragma_Placement;
12763
12764 Par := Parent (N);
12765 while Present (Par)
12766 and then (Nkind (Par) /= N_Loop_Statement
12767 or else not Is_OpenAcc_Environment (Par))
12768 loop
12769 Par := Parent (Par);
12770 end loop;
12771
12772 if not Is_OpenAcc_Environment (Par) then
12773 Error_Pragma
12774 ("Acc_Loop directive must be associated with an OpenAcc "
12775 & "construct region");
12776 end if;
12777
12778 Gather_Associations (Clause_Names, Clauses);
12779
12780 for Id in Clause_Names'First .. Clause_Names'Last loop
12781 Clause := Clauses (Id);
12782
12783 if Present (Clause) then
12784 case Clause_Names (Id) is
12785 when Name_Auto
12786 | Name_Independent
12787 | Name_Seq
12788 =>
12789 null;
12790
12791 when Name_Collapse =>
12792 Validate_Acc_Loop_Collapse (Clause);
12793
12794 when Name_Gang =>
12795 Validate_Acc_Loop_Gang (Clause);
12796
12797 when Name_Acc_Private =>
12798 Validate_Acc_Data_Clause (Clause);
12799
12800 when Name_Reduction =>
12801 Validate_Acc_Name_Reduction (Clause);
12802
12803 when Name_Tile =>
12804 Validate_Acc_Size_Expressions (Clause);
12805
12806 when Name_Vector =>
12807 Validate_Acc_Loop_Vector (Clause);
12808
12809 when Name_Worker =>
12810 Validate_Acc_Loop_Worker (Clause);
12811
12812 when others =>
12813 raise Program_Error;
12814 end case;
12815 end if;
12816 end loop;
12817
12818 Set_Is_OpenAcc_Loop (Parent (N));
12819 end Acc_Loop;
12820
12821 ----------------------------------
12822 -- Acc_Parallel and Acc_Kernels --
12823 ----------------------------------
12824
12825 when Pragma_Acc_Parallel
12826 | Pragma_Acc_Kernels
12827 =>
12828 Acc_Kernels_Or_Parallel : declare
12829 Clause_Names : constant Name_List :=
12830 (Name_Acc_If,
12831 Name_Async,
12832 Name_Copy,
12833 Name_Copy_In,
12834 Name_Copy_Out,
12835 Name_Create,
12836 Name_Default,
12837 Name_Device_Ptr,
12838 Name_Device_Type,
12839 Name_Num_Gangs,
12840 Name_Num_Workers,
12841 Name_Present,
12842 Name_Vector_Length,
12843 Name_Wait,
12844
12845 -- Parallel only
12846
12847 Name_Acc_Private,
12848 Name_First_Private,
12849 Name_Reduction,
12850
12851 -- Kernels only
12852
12853 Name_Attach,
12854 Name_No_Create);
12855
12856 Clause : Node_Id;
12857 Clauses : Args_List (Clause_Names'Range);
12858
12859 begin
12860 if not OpenAcc_Enabled then
12861 return;
12862 end if;
12863
12864 GNAT_Pragma;
12865 Check_Loop_Pragma_Placement;
12866
12867 if Nkind (Parent (N)) /= N_Loop_Statement then
12868 Error_Pragma
12869 ("pragma should be placed in loop or block statements");
12870 end if;
12871
12872 Gather_Associations (Clause_Names, Clauses);
12873
12874 for Id in Clause_Names'First .. Clause_Names'Last loop
12875 Clause := Clauses (Id);
12876
12877 if Present (Clause) then
12878 if Chars (Parent (Clause)) = No_Name then
12879 Error_Pragma ("all arguments should be associations");
12880 else
12881 case Clause_Names (Id) is
12882
12883 -- Note: According to the OpenAcc Standard v2.6,
12884 -- Async's argument should be optional. Because this
12885 -- complicates parsing the clause, the argument is
12886 -- made mandatory. The standard defines two negative
12887 -- values, acc_async_noval and acc_async_sync. When
12888 -- given acc_async_noval as value, the clause should
12889 -- behave as if no argument was given. According to
12890 -- the standard, acc_async_noval is defined in header
12891 -- files for C and Fortran, thus this value should
12892 -- probably be defined in the OpenAcc Ada library once
12893 -- it is implemented.
12894
12895 when Name_Async
12896 | Name_Num_Gangs
12897 | Name_Num_Workers
12898 | Name_Vector_Length
12899 =>
12900 Validate_Acc_Int_Expr_Clause (Clause);
12901
12902 when Name_Acc_If =>
12903 Validate_Acc_Condition_Clause (Clause);
12904
12905 -- Unsupported by GCC
12906
12907 when Name_Attach
12908 | Name_No_Create
12909 =>
12910 Error_Pragma ("unsupported clause");
12911
12912 when Name_Acc_Private
12913 | Name_First_Private
12914 =>
12915 if Prag_Id /= Pragma_Acc_Parallel then
12916 Error_Pragma
12917 ("argument is only available for 'Parallel' "
12918 & "construct");
12919 else
12920 Validate_Acc_Data_Clause (Clause);
12921 end if;
12922
12923 when Name_Copy
12924 | Name_Copy_In
12925 | Name_Copy_Out
12926 | Name_Create
12927 | Name_Device_Ptr
12928 | Name_Present
12929 =>
12930 Validate_Acc_Data_Clause (Clause);
12931
12932 when Name_Reduction =>
12933 if Prag_Id /= Pragma_Acc_Parallel then
12934 Error_Pragma
12935 ("argument is only available for 'Parallel' "
12936 & "construct");
12937 else
12938 Validate_Acc_Name_Reduction (Clause);
12939 end if;
12940
12941 when Name_Default =>
12942 if Chars (Clause) /= Name_None then
12943 Error_Pragma ("expected none");
12944 end if;
12945
12946 when Name_Device_Type =>
12947 Error_Pragma ("unsupported pragma clause");
12948
12949 -- Similar to Name_Async, Name_Wait's arguments should
12950 -- be optional. However, this can be simulated using
12951 -- acc_async_noval, hence, we do not bother making the
12952 -- argument optional for now.
12953
12954 when Name_Wait =>
12955 Validate_Acc_Int_Expr_List_Clause (Clause);
12956
12957 when others =>
12958 raise Program_Error;
12959 end case;
12960 end if;
12961 end if;
12962 end loop;
12963
12964 Set_Is_OpenAcc_Environment (Parent (N));
12965 end Acc_Kernels_Or_Parallel;
12966
12967 ------------
12968 -- Ada_83 --
12969 ------------
12970
12971 -- pragma Ada_83;
12972
12973 -- Note: this pragma also has some specific processing in Par.Prag
12974 -- because we want to set the Ada version mode during parsing.
12975
12976 when Pragma_Ada_83 =>
12977 GNAT_Pragma;
12978 Check_Arg_Count (0);
12979
12980 -- We really should check unconditionally for proper configuration
12981 -- pragma placement, since we really don't want mixed Ada modes
12982 -- within a single unit, and the GNAT reference manual has always
12983 -- said this was a configuration pragma, but we did not check and
12984 -- are hesitant to add the check now.
12985
12986 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
12987 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
12988 -- or Ada 2012 mode.
12989
12990 if Ada_Version >= Ada_2005 then
12991 Check_Valid_Configuration_Pragma;
12992 end if;
12993
12994 -- Now set Ada 83 mode
12995
12996 if Latest_Ada_Only then
12997 Error_Pragma ("??pragma% ignored");
12998 else
12999 Ada_Version := Ada_83;
13000 Ada_Version_Explicit := Ada_83;
13001 Ada_Version_Pragma := N;
13002 end if;
13003
13004 ------------
13005 -- Ada_95 --
13006 ------------
13007
13008 -- pragma Ada_95;
13009
13010 -- Note: this pragma also has some specific processing in Par.Prag
13011 -- because we want to set the Ada 83 version mode during parsing.
13012
13013 when Pragma_Ada_95 =>
13014 GNAT_Pragma;
13015 Check_Arg_Count (0);
13016
13017 -- We really should check unconditionally for proper configuration
13018 -- pragma placement, since we really don't want mixed Ada modes
13019 -- within a single unit, and the GNAT reference manual has always
13020 -- said this was a configuration pragma, but we did not check and
13021 -- are hesitant to add the check now.
13022
13023 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
13024 -- or Ada 95, so we must check if we are in Ada 2005 mode.
13025
13026 if Ada_Version >= Ada_2005 then
13027 Check_Valid_Configuration_Pragma;
13028 end if;
13029
13030 -- Now set Ada 95 mode
13031
13032 if Latest_Ada_Only then
13033 Error_Pragma ("??pragma% ignored");
13034 else
13035 Ada_Version := Ada_95;
13036 Ada_Version_Explicit := Ada_95;
13037 Ada_Version_Pragma := N;
13038 end if;
13039
13040 ---------------------
13041 -- Ada_05/Ada_2005 --
13042 ---------------------
13043
13044 -- pragma Ada_05;
13045 -- pragma Ada_05 (LOCAL_NAME);
13046
13047 -- pragma Ada_2005;
13048 -- pragma Ada_2005 (LOCAL_NAME):
13049
13050 -- Note: these pragmas also have some specific processing in Par.Prag
13051 -- because we want to set the Ada 2005 version mode during parsing.
13052
13053 -- The one argument form is used for managing the transition from
13054 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
13055 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
13056 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
13057 -- mode, a preference rule is established which does not choose
13058 -- such an entity unless it is unambiguously specified. This avoids
13059 -- extra subprograms marked this way from generating ambiguities in
13060 -- otherwise legal pre-Ada_2005 programs. The one argument form is
13061 -- intended for exclusive use in the GNAT run-time library.
13062
13063 when Pragma_Ada_05
13064 | Pragma_Ada_2005
13065 =>
13066 declare
13067 E_Id : Node_Id;
13068
13069 begin
13070 GNAT_Pragma;
13071
13072 if Arg_Count = 1 then
13073 Check_Arg_Is_Local_Name (Arg1);
13074 E_Id := Get_Pragma_Arg (Arg1);
13075
13076 if Etype (E_Id) = Any_Type then
13077 return;
13078 end if;
13079
13080 Set_Is_Ada_2005_Only (Entity (E_Id));
13081 Record_Rep_Item (Entity (E_Id), N);
13082
13083 else
13084 Check_Arg_Count (0);
13085
13086 -- For Ada_2005 we unconditionally enforce the documented
13087 -- configuration pragma placement, since we do not want to
13088 -- tolerate mixed modes in a unit involving Ada 2005. That
13089 -- would cause real difficulties for those cases where there
13090 -- are incompatibilities between Ada 95 and Ada 2005.
13091
13092 Check_Valid_Configuration_Pragma;
13093
13094 -- Now set appropriate Ada mode
13095
13096 if Latest_Ada_Only then
13097 Error_Pragma ("??pragma% ignored");
13098 else
13099 Ada_Version := Ada_2005;
13100 Ada_Version_Explicit := Ada_2005;
13101 Ada_Version_Pragma := N;
13102 end if;
13103 end if;
13104 end;
13105
13106 ---------------------
13107 -- Ada_12/Ada_2012 --
13108 ---------------------
13109
13110 -- pragma Ada_12;
13111 -- pragma Ada_12 (LOCAL_NAME);
13112
13113 -- pragma Ada_2012;
13114 -- pragma Ada_2012 (LOCAL_NAME):
13115
13116 -- Note: these pragmas also have some specific processing in Par.Prag
13117 -- because we want to set the Ada 2012 version mode during parsing.
13118
13119 -- The one argument form is used for managing the transition from Ada
13120 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
13121 -- as Ada_2012 only, then referencing the entity in any pre-Ada_2012
13122 -- mode will generate a warning. In addition, in any pre-Ada_2012
13123 -- mode, a preference rule is established which does not choose
13124 -- such an entity unless it is unambiguously specified. This avoids
13125 -- extra subprograms marked this way from generating ambiguities in
13126 -- otherwise legal pre-Ada_2012 programs. The one argument form is
13127 -- intended for exclusive use in the GNAT run-time library.
13128
13129 when Pragma_Ada_12
13130 | Pragma_Ada_2012
13131 =>
13132 declare
13133 E_Id : Node_Id;
13134
13135 begin
13136 GNAT_Pragma;
13137
13138 if Arg_Count = 1 then
13139 Check_Arg_Is_Local_Name (Arg1);
13140 E_Id := Get_Pragma_Arg (Arg1);
13141
13142 if Etype (E_Id) = Any_Type then
13143 return;
13144 end if;
13145
13146 Set_Is_Ada_2012_Only (Entity (E_Id));
13147 Record_Rep_Item (Entity (E_Id), N);
13148
13149 else
13150 Check_Arg_Count (0);
13151
13152 -- For Ada_2012 we unconditionally enforce the documented
13153 -- configuration pragma placement, since we do not want to
13154 -- tolerate mixed modes in a unit involving Ada 2012. That
13155 -- would cause real difficulties for those cases where there
13156 -- are incompatibilities between Ada 95 and Ada 2012. We could
13157 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
13158
13159 Check_Valid_Configuration_Pragma;
13160
13161 -- Now set appropriate Ada mode
13162
13163 Ada_Version := Ada_2012;
13164 Ada_Version_Explicit := Ada_2012;
13165 Ada_Version_Pragma := N;
13166 end if;
13167 end;
13168
13169 --------------
13170 -- Ada_2020 --
13171 --------------
13172
13173 -- pragma Ada_2020;
13174
13175 -- Note: this pragma also has some specific processing in Par.Prag
13176 -- because we want to set the Ada 2020 version mode during parsing.
13177
13178 when Pragma_Ada_2020 =>
13179 GNAT_Pragma;
13180
13181 Check_Arg_Count (0);
13182
13183 Check_Valid_Configuration_Pragma;
13184
13185 -- Now set appropriate Ada mode
13186
13187 Ada_Version := Ada_2020;
13188 Ada_Version_Explicit := Ada_2020;
13189 Ada_Version_Pragma := N;
13190
13191 -------------------------------------
13192 -- Aggregate_Individually_Assign --
13193 -------------------------------------
13194
13195 -- pragma Aggregate_Individually_Assign;
13196
13197 when Pragma_Aggregate_Individually_Assign =>
13198 GNAT_Pragma;
13199 Check_Arg_Count (0);
13200 Check_Valid_Configuration_Pragma;
13201 Aggregate_Individually_Assign := True;
13202
13203 ----------------------
13204 -- All_Calls_Remote --
13205 ----------------------
13206
13207 -- pragma All_Calls_Remote [(library_package_NAME)];
13208
13209 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
13210 Lib_Entity : Entity_Id;
13211
13212 begin
13213 Check_Ada_83_Warning;
13214 Check_Valid_Library_Unit_Pragma;
13215
13216 if Nkind (N) = N_Null_Statement then
13217 return;
13218 end if;
13219
13220 Lib_Entity := Find_Lib_Unit_Name;
13221
13222 -- A pragma that applies to a Ghost entity becomes Ghost for the
13223 -- purposes of legality checks and removal of ignored Ghost code.
13224
13225 Mark_Ghost_Pragma (N, Lib_Entity);
13226
13227 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
13228
13229 if Present (Lib_Entity) and then not Debug_Flag_U then
13230 if not Is_Remote_Call_Interface (Lib_Entity) then
13231 Error_Pragma ("pragma% only apply to rci unit");
13232
13233 -- Set flag for entity of the library unit
13234
13235 else
13236 Set_Has_All_Calls_Remote (Lib_Entity);
13237 end if;
13238 end if;
13239 end All_Calls_Remote;
13240
13241 ---------------------------
13242 -- Allow_Integer_Address --
13243 ---------------------------
13244
13245 -- pragma Allow_Integer_Address;
13246
13247 when Pragma_Allow_Integer_Address =>
13248 GNAT_Pragma;
13249 Check_Valid_Configuration_Pragma;
13250 Check_Arg_Count (0);
13251
13252 -- If Address is a private type, then set the flag to allow
13253 -- integer address values. If Address is not private, then this
13254 -- pragma has no purpose, so it is simply ignored. Not clear if
13255 -- there are any such targets now.
13256
13257 if Opt.Address_Is_Private then
13258 Opt.Allow_Integer_Address := True;
13259 end if;
13260
13261 --------------
13262 -- Annotate --
13263 --------------
13264
13265 -- pragma Annotate
13266 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
13267 -- ARG ::= NAME | EXPRESSION
13268
13269 -- The first two arguments are by convention intended to refer to an
13270 -- external tool and a tool-specific function. These arguments are
13271 -- not analyzed.
13272
13273 when Pragma_Annotate => Annotate : declare
13274 Arg : Node_Id;
13275 Expr : Node_Id;
13276 Nam_Arg : Node_Id;
13277
13278 --------------------------
13279 -- Inferred_String_Type --
13280 --------------------------
13281
13282 function Preferred_String_Type (Expr : Node_Id) return Entity_Id;
13283 -- Infer the type to use for a string literal or a concatentation
13284 -- of operands whose types can be inferred. For such expressions,
13285 -- returns the "narrowest" of the three predefined string types
13286 -- that can represent the characters occurring in the expression.
13287 -- For other expressions, returns Empty.
13288
13289 function Preferred_String_Type (Expr : Node_Id) return Entity_Id is
13290 begin
13291 case Nkind (Expr) is
13292 when N_String_Literal =>
13293 if Has_Wide_Wide_Character (Expr) then
13294 return Standard_Wide_Wide_String;
13295 elsif Has_Wide_Character (Expr) then
13296 return Standard_Wide_String;
13297 else
13298 return Standard_String;
13299 end if;
13300
13301 when N_Op_Concat =>
13302 declare
13303 L_Type : constant Entity_Id
13304 := Preferred_String_Type (Left_Opnd (Expr));
13305 R_Type : constant Entity_Id
13306 := Preferred_String_Type (Right_Opnd (Expr));
13307
13308 Type_Table : constant array (1 .. 4) of Entity_Id
13309 := (Empty,
13310 Standard_Wide_Wide_String,
13311 Standard_Wide_String,
13312 Standard_String);
13313 begin
13314 for Idx in Type_Table'Range loop
13315 if (L_Type = Type_Table (Idx)) or
13316 (R_Type = Type_Table (Idx))
13317 then
13318 return Type_Table (Idx);
13319 end if;
13320 end loop;
13321 raise Program_Error;
13322 end;
13323
13324 when others =>
13325 return Empty;
13326 end case;
13327 end Preferred_String_Type;
13328 begin
13329 GNAT_Pragma;
13330 Check_At_Least_N_Arguments (1);
13331
13332 Nam_Arg := Last (Pragma_Argument_Associations (N));
13333
13334 -- Determine whether the last argument is "Entity => local_NAME"
13335 -- and if it is, perform the required semantic checks. Remove the
13336 -- argument from further processing.
13337
13338 if Nkind (Nam_Arg) = N_Pragma_Argument_Association
13339 and then Chars (Nam_Arg) = Name_Entity
13340 then
13341 Check_Arg_Is_Local_Name (Nam_Arg);
13342 Arg_Count := Arg_Count - 1;
13343
13344 -- A pragma that applies to a Ghost entity becomes Ghost for
13345 -- the purposes of legality checks and removal of ignored Ghost
13346 -- code.
13347
13348 if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg))
13349 and then Present (Entity (Get_Pragma_Arg (Nam_Arg)))
13350 then
13351 Mark_Ghost_Pragma (N, Entity (Get_Pragma_Arg (Nam_Arg)));
13352 end if;
13353
13354 -- Not allowed in compiler units (bootstrap issues)
13355
13356 Check_Compiler_Unit ("Entity for pragma Annotate", N);
13357 end if;
13358
13359 -- Continue the processing with last argument removed for now
13360
13361 Check_Arg_Is_Identifier (Arg1);
13362 Check_No_Identifiers;
13363 Store_Note (N);
13364
13365 -- The second parameter is optional, it is never analyzed
13366
13367 if No (Arg2) then
13368 null;
13369
13370 -- Otherwise there is a second parameter
13371
13372 else
13373 -- The second parameter must be an identifier
13374
13375 Check_Arg_Is_Identifier (Arg2);
13376
13377 -- Process the remaining parameters (if any)
13378
13379 Arg := Next (Arg2);
13380 while Present (Arg) loop
13381 Expr := Get_Pragma_Arg (Arg);
13382 Analyze (Expr);
13383
13384 if Is_Entity_Name (Expr) then
13385 null;
13386
13387 -- For string literals and concatenations of string literals
13388 -- we assume Standard_String as the type, unless the string
13389 -- contains wide or wide_wide characters.
13390
13391 elsif Present (Preferred_String_Type (Expr)) then
13392 Resolve (Expr, Preferred_String_Type (Expr));
13393
13394 elsif Is_Overloaded (Expr) then
13395 Error_Pragma_Arg ("ambiguous argument for pragma%", Expr);
13396
13397 else
13398 Resolve (Expr);
13399 end if;
13400
13401 Next (Arg);
13402 end loop;
13403 end if;
13404 end Annotate;
13405
13406 -------------------------------------------------
13407 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
13408 -------------------------------------------------
13409
13410 -- pragma Assert
13411 -- ( [Check => ] Boolean_EXPRESSION
13412 -- [, [Message =>] Static_String_EXPRESSION]);
13413
13414 -- pragma Assert_And_Cut
13415 -- ( [Check => ] Boolean_EXPRESSION
13416 -- [, [Message =>] Static_String_EXPRESSION]);
13417
13418 -- pragma Assume
13419 -- ( [Check => ] Boolean_EXPRESSION
13420 -- [, [Message =>] Static_String_EXPRESSION]);
13421
13422 -- pragma Loop_Invariant
13423 -- ( [Check => ] Boolean_EXPRESSION
13424 -- [, [Message =>] Static_String_EXPRESSION]);
13425
13426 when Pragma_Assert
13427 | Pragma_Assert_And_Cut
13428 | Pragma_Assume
13429 | Pragma_Loop_Invariant
13430 =>
13431 Assert : declare
13432 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
13433 -- Determine whether expression Expr contains a Loop_Entry
13434 -- attribute reference.
13435
13436 -------------------------
13437 -- Contains_Loop_Entry --
13438 -------------------------
13439
13440 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
13441 Has_Loop_Entry : Boolean := False;
13442
13443 function Process (N : Node_Id) return Traverse_Result;
13444 -- Process function for traversal to look for Loop_Entry
13445
13446 -------------
13447 -- Process --
13448 -------------
13449
13450 function Process (N : Node_Id) return Traverse_Result is
13451 begin
13452 if Nkind (N) = N_Attribute_Reference
13453 and then Attribute_Name (N) = Name_Loop_Entry
13454 then
13455 Has_Loop_Entry := True;
13456 return Abandon;
13457 else
13458 return OK;
13459 end if;
13460 end Process;
13461
13462 procedure Traverse is new Traverse_Proc (Process);
13463
13464 -- Start of processing for Contains_Loop_Entry
13465
13466 begin
13467 Traverse (Expr);
13468 return Has_Loop_Entry;
13469 end Contains_Loop_Entry;
13470
13471 -- Local variables
13472
13473 Expr : Node_Id;
13474 New_Args : List_Id;
13475
13476 -- Start of processing for Assert
13477
13478 begin
13479 -- Assert is an Ada 2005 RM-defined pragma
13480
13481 if Prag_Id = Pragma_Assert then
13482 Ada_2005_Pragma;
13483
13484 -- The remaining ones are GNAT pragmas
13485
13486 else
13487 GNAT_Pragma;
13488 end if;
13489
13490 Check_At_Least_N_Arguments (1);
13491 Check_At_Most_N_Arguments (2);
13492 Check_Arg_Order ((Name_Check, Name_Message));
13493 Check_Optional_Identifier (Arg1, Name_Check);
13494 Expr := Get_Pragma_Arg (Arg1);
13495
13496 -- Special processing for Loop_Invariant, Loop_Variant or for
13497 -- other cases where a Loop_Entry attribute is present. If the
13498 -- assertion pragma contains attribute Loop_Entry, ensure that
13499 -- the related pragma is within a loop.
13500
13501 if Prag_Id = Pragma_Loop_Invariant
13502 or else Prag_Id = Pragma_Loop_Variant
13503 or else Contains_Loop_Entry (Expr)
13504 then
13505 Check_Loop_Pragma_Placement;
13506
13507 -- Perform preanalysis to deal with embedded Loop_Entry
13508 -- attributes.
13509
13510 Preanalyze_Assert_Expression (Expr, Any_Boolean);
13511 end if;
13512
13513 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
13514 -- a corresponding Check pragma:
13515
13516 -- pragma Check (name, condition [, msg]);
13517
13518 -- Where name is the identifier matching the pragma name. So
13519 -- rewrite pragma in this manner, transfer the message argument
13520 -- if present, and analyze the result
13521
13522 -- Note: When dealing with a semantically analyzed tree, the
13523 -- information that a Check node N corresponds to a source Assert,
13524 -- Assume, or Assert_And_Cut pragma can be retrieved from the
13525 -- pragma kind of Original_Node(N).
13526
13527 New_Args := New_List (
13528 Make_Pragma_Argument_Association (Loc,
13529 Expression => Make_Identifier (Loc, Pname)),
13530 Make_Pragma_Argument_Association (Sloc (Expr),
13531 Expression => Expr));
13532
13533 if Arg_Count > 1 then
13534 Check_Optional_Identifier (Arg2, Name_Message);
13535
13536 -- Provide semantic annotations for optional argument, for
13537 -- ASIS use, before rewriting.
13538 -- Is this still needed???
13539
13540 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
13541 Append_To (New_Args, New_Copy_Tree (Arg2));
13542 end if;
13543
13544 -- Rewrite as Check pragma
13545
13546 Rewrite (N,
13547 Make_Pragma (Loc,
13548 Chars => Name_Check,
13549 Pragma_Argument_Associations => New_Args));
13550
13551 Analyze (N);
13552 end Assert;
13553
13554 ----------------------
13555 -- Assertion_Policy --
13556 ----------------------
13557
13558 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
13559
13560 -- The following form is Ada 2012 only, but we allow it in all modes
13561
13562 -- Pragma Assertion_Policy (
13563 -- ASSERTION_KIND => POLICY_IDENTIFIER
13564 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
13565
13566 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
13567
13568 -- RM_ASSERTION_KIND ::= Assert |
13569 -- Static_Predicate |
13570 -- Dynamic_Predicate |
13571 -- Pre |
13572 -- Pre'Class |
13573 -- Post |
13574 -- Post'Class |
13575 -- Type_Invariant |
13576 -- Type_Invariant'Class
13577
13578 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
13579 -- Assume |
13580 -- Contract_Cases |
13581 -- Debug |
13582 -- Default_Initial_Condition |
13583 -- Ghost |
13584 -- Initial_Condition |
13585 -- Loop_Invariant |
13586 -- Loop_Variant |
13587 -- Postcondition |
13588 -- Precondition |
13589 -- Predicate |
13590 -- Refined_Post |
13591 -- Statement_Assertions
13592
13593 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
13594 -- ID_ASSERTION_KIND list contains implementation-defined additions
13595 -- recognized by GNAT. The effect is to control the behavior of
13596 -- identically named aspects and pragmas, depending on the specified
13597 -- policy identifier:
13598
13599 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
13600
13601 -- Note: Check and Ignore are language-defined. Disable is a GNAT
13602 -- implementation-defined addition that results in totally ignoring
13603 -- the corresponding assertion. If Disable is specified, then the
13604 -- argument of the assertion is not even analyzed. This is useful
13605 -- when the aspect/pragma argument references entities in a with'ed
13606 -- package that is replaced by a dummy package in the final build.
13607
13608 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
13609 -- and Type_Invariant'Class were recognized by the parser and
13610 -- transformed into references to the special internal identifiers
13611 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
13612 -- processing is required here.
13613
13614 when Pragma_Assertion_Policy => Assertion_Policy : declare
13615 procedure Resolve_Suppressible (Policy : Node_Id);
13616 -- Converts the assertion policy 'Suppressible' to either Check or
13617 -- Ignore based on whether checks are suppressed via -gnatp.
13618
13619 --------------------------
13620 -- Resolve_Suppressible --
13621 --------------------------
13622
13623 procedure Resolve_Suppressible (Policy : Node_Id) is
13624 Arg : constant Node_Id := Get_Pragma_Arg (Policy);
13625 Nam : Name_Id;
13626
13627 begin
13628 -- Transform policy argument Suppressible into either Ignore or
13629 -- Check depending on whether checks are enabled or suppressed.
13630
13631 if Chars (Arg) = Name_Suppressible then
13632 if Suppress_Checks then
13633 Nam := Name_Ignore;
13634 else
13635 Nam := Name_Check;
13636 end if;
13637
13638 Rewrite (Arg, Make_Identifier (Sloc (Arg), Nam));
13639 end if;
13640 end Resolve_Suppressible;
13641
13642 -- Local variables
13643
13644 Arg : Node_Id;
13645 Kind : Name_Id;
13646 LocP : Source_Ptr;
13647 Policy : Node_Id;
13648
13649 begin
13650 Ada_2005_Pragma;
13651
13652 -- This can always appear as a configuration pragma
13653
13654 if Is_Configuration_Pragma then
13655 null;
13656
13657 -- It can also appear in a declarative part or package spec in Ada
13658 -- 2012 mode. We allow this in other modes, but in that case we
13659 -- consider that we have an Ada 2012 pragma on our hands.
13660
13661 else
13662 Check_Is_In_Decl_Part_Or_Package_Spec;
13663 Ada_2012_Pragma;
13664 end if;
13665
13666 -- One argument case with no identifier (first form above)
13667
13668 if Arg_Count = 1
13669 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
13670 or else Chars (Arg1) = No_Name)
13671 then
13672 Check_Arg_Is_One_Of (Arg1,
13673 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13674
13675 Resolve_Suppressible (Arg1);
13676
13677 -- Treat one argument Assertion_Policy as equivalent to:
13678
13679 -- pragma Check_Policy (Assertion, policy)
13680
13681 -- So rewrite pragma in that manner and link on to the chain
13682 -- of Check_Policy pragmas, marking the pragma as analyzed.
13683
13684 Policy := Get_Pragma_Arg (Arg1);
13685
13686 Rewrite (N,
13687 Make_Pragma (Loc,
13688 Chars => Name_Check_Policy,
13689 Pragma_Argument_Associations => New_List (
13690 Make_Pragma_Argument_Association (Loc,
13691 Expression => Make_Identifier (Loc, Name_Assertion)),
13692
13693 Make_Pragma_Argument_Association (Loc,
13694 Expression =>
13695 Make_Identifier (Sloc (Policy), Chars (Policy))))));
13696 Analyze (N);
13697
13698 -- Here if we have two or more arguments
13699
13700 else
13701 Check_At_Least_N_Arguments (1);
13702 Ada_2012_Pragma;
13703
13704 -- Loop through arguments
13705
13706 Arg := Arg1;
13707 while Present (Arg) loop
13708 LocP := Sloc (Arg);
13709
13710 -- Kind must be specified
13711
13712 if Nkind (Arg) /= N_Pragma_Argument_Association
13713 or else Chars (Arg) = No_Name
13714 then
13715 Error_Pragma_Arg
13716 ("missing assertion kind for pragma%", Arg);
13717 end if;
13718
13719 -- Check Kind and Policy have allowed forms
13720
13721 Kind := Chars (Arg);
13722 Policy := Get_Pragma_Arg (Arg);
13723
13724 if not Is_Valid_Assertion_Kind (Kind) then
13725 Error_Pragma_Arg
13726 ("invalid assertion kind for pragma%", Arg);
13727 end if;
13728
13729 Check_Arg_Is_One_Of (Arg,
13730 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13731
13732 Resolve_Suppressible (Arg);
13733
13734 if Kind = Name_Ghost then
13735
13736 -- The Ghost policy must be either Check or Ignore
13737 -- (SPARK RM 6.9(6)).
13738
13739 if not Nam_In (Chars (Policy), Name_Check,
13740 Name_Ignore)
13741 then
13742 Error_Pragma_Arg
13743 ("argument of pragma % Ghost must be Check or "
13744 & "Ignore", Policy);
13745 end if;
13746
13747 -- Pragma Assertion_Policy specifying a Ghost policy
13748 -- cannot occur within a Ghost subprogram or package
13749 -- (SPARK RM 6.9(14)).
13750
13751 if Ghost_Mode > None then
13752 Error_Pragma
13753 ("pragma % cannot appear within ghost subprogram or "
13754 & "package");
13755 end if;
13756 end if;
13757
13758 -- Rewrite the Assertion_Policy pragma as a series of
13759 -- Check_Policy pragmas of the form:
13760
13761 -- Check_Policy (Kind, Policy);
13762
13763 -- Note: the insertion of the pragmas cannot be done with
13764 -- Insert_Action because in the configuration case, there
13765 -- are no scopes on the scope stack and the mechanism will
13766 -- fail.
13767
13768 Insert_Before_And_Analyze (N,
13769 Make_Pragma (LocP,
13770 Chars => Name_Check_Policy,
13771 Pragma_Argument_Associations => New_List (
13772 Make_Pragma_Argument_Association (LocP,
13773 Expression => Make_Identifier (LocP, Kind)),
13774 Make_Pragma_Argument_Association (LocP,
13775 Expression => Policy))));
13776
13777 Arg := Next (Arg);
13778 end loop;
13779
13780 -- Rewrite the Assertion_Policy pragma as null since we have
13781 -- now inserted all the equivalent Check pragmas.
13782
13783 Rewrite (N, Make_Null_Statement (Loc));
13784 Analyze (N);
13785 end if;
13786 end Assertion_Policy;
13787
13788 ------------------------------
13789 -- Assume_No_Invalid_Values --
13790 ------------------------------
13791
13792 -- pragma Assume_No_Invalid_Values (On | Off);
13793
13794 when Pragma_Assume_No_Invalid_Values =>
13795 GNAT_Pragma;
13796 Check_Valid_Configuration_Pragma;
13797 Check_Arg_Count (1);
13798 Check_No_Identifiers;
13799 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13800
13801 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
13802 Assume_No_Invalid_Values := True;
13803 else
13804 Assume_No_Invalid_Values := False;
13805 end if;
13806
13807 --------------------------
13808 -- Attribute_Definition --
13809 --------------------------
13810
13811 -- pragma Attribute_Definition
13812 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
13813 -- [Entity =>] LOCAL_NAME,
13814 -- [Expression =>] EXPRESSION | NAME);
13815
13816 when Pragma_Attribute_Definition => Attribute_Definition : declare
13817 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
13818 Aname : Name_Id;
13819
13820 begin
13821 GNAT_Pragma;
13822 Check_Arg_Count (3);
13823 Check_Optional_Identifier (Arg1, "attribute");
13824 Check_Optional_Identifier (Arg2, "entity");
13825 Check_Optional_Identifier (Arg3, "expression");
13826
13827 if Nkind (Attribute_Designator) /= N_Identifier then
13828 Error_Msg_N ("attribute name expected", Attribute_Designator);
13829 return;
13830 end if;
13831
13832 Check_Arg_Is_Local_Name (Arg2);
13833
13834 -- If the attribute is not recognized, then issue a warning (not
13835 -- an error), and ignore the pragma.
13836
13837 Aname := Chars (Attribute_Designator);
13838
13839 if not Is_Attribute_Name (Aname) then
13840 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
13841 return;
13842 end if;
13843
13844 -- Otherwise, rewrite the pragma as an attribute definition clause
13845
13846 Rewrite (N,
13847 Make_Attribute_Definition_Clause (Loc,
13848 Name => Get_Pragma_Arg (Arg2),
13849 Chars => Aname,
13850 Expression => Get_Pragma_Arg (Arg3)));
13851 Analyze (N);
13852 end Attribute_Definition;
13853
13854 ------------------------------------------------------------------
13855 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
13856 -- No_Caching --
13857 ------------------------------------------------------------------
13858
13859 -- pragma Async_Readers [ (boolean_EXPRESSION) ];
13860 -- pragma Async_Writers [ (boolean_EXPRESSION) ];
13861 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
13862 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
13863 -- pragma No_Caching [ (boolean_EXPRESSION) ];
13864
13865 when Pragma_Async_Readers
13866 | Pragma_Async_Writers
13867 | Pragma_Effective_Reads
13868 | Pragma_Effective_Writes
13869 | Pragma_No_Caching
13870 =>
13871 Async_Effective : declare
13872 Obj_Decl : Node_Id;
13873 Obj_Id : Entity_Id;
13874
13875 begin
13876 GNAT_Pragma;
13877 Check_No_Identifiers;
13878 Check_At_Most_N_Arguments (1);
13879
13880 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
13881
13882 -- Object declaration
13883
13884 if Nkind (Obj_Decl) /= N_Object_Declaration then
13885 Pragma_Misplaced;
13886 return;
13887 end if;
13888
13889 Obj_Id := Defining_Entity (Obj_Decl);
13890
13891 -- Perform minimal verification to ensure that the argument is at
13892 -- least a variable. Subsequent finer grained checks will be done
13893 -- at the end of the declarative region the contains the pragma.
13894
13895 if Ekind (Obj_Id) = E_Variable then
13896
13897 -- A pragma that applies to a Ghost entity becomes Ghost for
13898 -- the purposes of legality checks and removal of ignored Ghost
13899 -- code.
13900
13901 Mark_Ghost_Pragma (N, Obj_Id);
13902
13903 -- Chain the pragma on the contract for further processing by
13904 -- Analyze_External_Property_In_Decl_Part.
13905
13906 Add_Contract_Item (N, Obj_Id);
13907
13908 -- Analyze the Boolean expression (if any)
13909
13910 if Present (Arg1) then
13911 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
13912 end if;
13913
13914 -- Otherwise the external property applies to a constant
13915
13916 else
13917 Error_Pragma ("pragma % must apply to a volatile object");
13918 end if;
13919 end Async_Effective;
13920
13921 ------------------
13922 -- Asynchronous --
13923 ------------------
13924
13925 -- pragma Asynchronous (LOCAL_NAME);
13926
13927 when Pragma_Asynchronous => Asynchronous : declare
13928 C_Ent : Entity_Id;
13929 Decl : Node_Id;
13930 Formal : Entity_Id;
13931 L : List_Id;
13932 Nm : Entity_Id;
13933 S : Node_Id;
13934
13935 procedure Process_Async_Pragma;
13936 -- Common processing for procedure and access-to-procedure case
13937
13938 --------------------------
13939 -- Process_Async_Pragma --
13940 --------------------------
13941
13942 procedure Process_Async_Pragma is
13943 begin
13944 if No (L) then
13945 Set_Is_Asynchronous (Nm);
13946 return;
13947 end if;
13948
13949 -- The formals should be of mode IN (RM E.4.1(6))
13950
13951 S := First (L);
13952 while Present (S) loop
13953 Formal := Defining_Identifier (S);
13954
13955 if Nkind (Formal) = N_Defining_Identifier
13956 and then Ekind (Formal) /= E_In_Parameter
13957 then
13958 Error_Pragma_Arg
13959 ("pragma% procedure can only have IN parameter",
13960 Arg1);
13961 end if;
13962
13963 Next (S);
13964 end loop;
13965
13966 Set_Is_Asynchronous (Nm);
13967 end Process_Async_Pragma;
13968
13969 -- Start of processing for pragma Asynchronous
13970
13971 begin
13972 Check_Ada_83_Warning;
13973 Check_No_Identifiers;
13974 Check_Arg_Count (1);
13975 Check_Arg_Is_Local_Name (Arg1);
13976
13977 if Debug_Flag_U then
13978 return;
13979 end if;
13980
13981 C_Ent := Cunit_Entity (Current_Sem_Unit);
13982 Analyze (Get_Pragma_Arg (Arg1));
13983 Nm := Entity (Get_Pragma_Arg (Arg1));
13984
13985 -- A pragma that applies to a Ghost entity becomes Ghost for the
13986 -- purposes of legality checks and removal of ignored Ghost code.
13987
13988 Mark_Ghost_Pragma (N, Nm);
13989
13990 if not Is_Remote_Call_Interface (C_Ent)
13991 and then not Is_Remote_Types (C_Ent)
13992 then
13993 -- This pragma should only appear in an RCI or Remote Types
13994 -- unit (RM E.4.1(4)).
13995
13996 Error_Pragma
13997 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
13998 end if;
13999
14000 if Ekind (Nm) = E_Procedure
14001 and then Nkind (Parent (Nm)) = N_Procedure_Specification
14002 then
14003 if not Is_Remote_Call_Interface (Nm) then
14004 Error_Pragma_Arg
14005 ("pragma% cannot be applied on non-remote procedure",
14006 Arg1);
14007 end if;
14008
14009 L := Parameter_Specifications (Parent (Nm));
14010 Process_Async_Pragma;
14011 return;
14012
14013 elsif Ekind (Nm) = E_Function then
14014 Error_Pragma_Arg
14015 ("pragma% cannot be applied to function", Arg1);
14016
14017 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
14018 if Is_Record_Type (Nm) then
14019
14020 -- A record type that is the Equivalent_Type for a remote
14021 -- access-to-subprogram type.
14022
14023 Decl := Declaration_Node (Corresponding_Remote_Type (Nm));
14024
14025 else
14026 -- A non-expanded RAS type (distribution is not enabled)
14027
14028 Decl := Declaration_Node (Nm);
14029 end if;
14030
14031 if Nkind (Decl) = N_Full_Type_Declaration
14032 and then Nkind (Type_Definition (Decl)) =
14033 N_Access_Procedure_Definition
14034 then
14035 L := Parameter_Specifications (Type_Definition (Decl));
14036 Process_Async_Pragma;
14037
14038 if Is_Asynchronous (Nm)
14039 and then Expander_Active
14040 and then Get_PCS_Name /= Name_No_DSA
14041 then
14042 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
14043 end if;
14044
14045 else
14046 Error_Pragma_Arg
14047 ("pragma% cannot reference access-to-function type",
14048 Arg1);
14049 end if;
14050
14051 -- Only other possibility is Access-to-class-wide type
14052
14053 elsif Is_Access_Type (Nm)
14054 and then Is_Class_Wide_Type (Designated_Type (Nm))
14055 then
14056 Check_First_Subtype (Arg1);
14057 Set_Is_Asynchronous (Nm);
14058 if Expander_Active then
14059 RACW_Type_Is_Asynchronous (Nm);
14060 end if;
14061
14062 else
14063 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
14064 end if;
14065 end Asynchronous;
14066
14067 ------------
14068 -- Atomic --
14069 ------------
14070
14071 -- pragma Atomic (LOCAL_NAME);
14072
14073 when Pragma_Atomic =>
14074 Process_Atomic_Independent_Shared_Volatile;
14075
14076 -----------------------
14077 -- Atomic_Components --
14078 -----------------------
14079
14080 -- pragma Atomic_Components (array_LOCAL_NAME);
14081
14082 -- This processing is shared by Volatile_Components
14083
14084 when Pragma_Atomic_Components
14085 | Pragma_Volatile_Components
14086 =>
14087 Atomic_Components : declare
14088 D : Node_Id;
14089 E : Entity_Id;
14090 E_Id : Node_Id;
14091
14092 begin
14093 Check_Ada_83_Warning;
14094 Check_No_Identifiers;
14095 Check_Arg_Count (1);
14096 Check_Arg_Is_Local_Name (Arg1);
14097 E_Id := Get_Pragma_Arg (Arg1);
14098
14099 if Etype (E_Id) = Any_Type then
14100 return;
14101 end if;
14102
14103 E := Entity (E_Id);
14104
14105 -- A pragma that applies to a Ghost entity becomes Ghost for the
14106 -- purposes of legality checks and removal of ignored Ghost code.
14107
14108 Mark_Ghost_Pragma (N, E);
14109 Check_Duplicate_Pragma (E);
14110
14111 if Rep_Item_Too_Early (E, N)
14112 or else
14113 Rep_Item_Too_Late (E, N)
14114 then
14115 return;
14116 end if;
14117
14118 D := Declaration_Node (E);
14119
14120 if (Nkind (D) = N_Full_Type_Declaration and then Is_Array_Type (E))
14121 or else
14122 (Nkind (D) = N_Object_Declaration
14123 and then (Ekind (E) = E_Constant
14124 or else
14125 Ekind (E) = E_Variable)
14126 and then Nkind (Object_Definition (D)) =
14127 N_Constrained_Array_Definition)
14128 or else
14129 (Ada_Version >= Ada_2020
14130 and then Nkind (D) = N_Formal_Type_Declaration)
14131 then
14132 -- The flag is set on the base type, or on the object
14133
14134 if Nkind (D) = N_Full_Type_Declaration then
14135 E := Base_Type (E);
14136 end if;
14137
14138 -- Atomic implies both Independent and Volatile
14139
14140 if Prag_Id = Pragma_Atomic_Components then
14141 if Ada_Version >= Ada_2020 then
14142 Check_Atomic_VFA
14143 (Component_Type (Etype (E)), VFA => False);
14144 end if;
14145
14146 Set_Has_Atomic_Components (E);
14147 Set_Has_Independent_Components (E);
14148 end if;
14149
14150 Set_Has_Volatile_Components (E);
14151
14152 else
14153 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
14154 end if;
14155 end Atomic_Components;
14156
14157 --------------------
14158 -- Attach_Handler --
14159 --------------------
14160
14161 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
14162
14163 when Pragma_Attach_Handler =>
14164 Check_Ada_83_Warning;
14165 Check_No_Identifiers;
14166 Check_Arg_Count (2);
14167
14168 if No_Run_Time_Mode then
14169 Error_Msg_CRT ("Attach_Handler pragma", N);
14170 else
14171 Check_Interrupt_Or_Attach_Handler;
14172
14173 -- The expression that designates the attribute may depend on a
14174 -- discriminant, and is therefore a per-object expression, to
14175 -- be expanded in the init proc. If expansion is enabled, then
14176 -- perform semantic checks on a copy only.
14177
14178 declare
14179 Temp : Node_Id;
14180 Typ : Node_Id;
14181 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
14182
14183 begin
14184 -- In Relaxed_RM_Semantics mode, we allow any static
14185 -- integer value, for compatibility with other compilers.
14186
14187 if Relaxed_RM_Semantics
14188 and then Nkind (Parg2) = N_Integer_Literal
14189 then
14190 Typ := Standard_Integer;
14191 else
14192 Typ := RTE (RE_Interrupt_ID);
14193 end if;
14194
14195 if Expander_Active then
14196 Temp := New_Copy_Tree (Parg2);
14197 Set_Parent (Temp, N);
14198 Preanalyze_And_Resolve (Temp, Typ);
14199 else
14200 Analyze (Parg2);
14201 Resolve (Parg2, Typ);
14202 end if;
14203 end;
14204
14205 Process_Interrupt_Or_Attach_Handler;
14206 end if;
14207
14208 --------------------
14209 -- C_Pass_By_Copy --
14210 --------------------
14211
14212 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
14213
14214 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
14215 Arg : Node_Id;
14216 Val : Uint;
14217
14218 begin
14219 GNAT_Pragma;
14220 Check_Valid_Configuration_Pragma;
14221 Check_Arg_Count (1);
14222 Check_Optional_Identifier (Arg1, "max_size");
14223
14224 Arg := Get_Pragma_Arg (Arg1);
14225 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
14226
14227 Val := Expr_Value (Arg);
14228
14229 if Val <= 0 then
14230 Error_Pragma_Arg
14231 ("maximum size for pragma% must be positive", Arg1);
14232
14233 elsif UI_Is_In_Int_Range (Val) then
14234 Default_C_Record_Mechanism := UI_To_Int (Val);
14235
14236 -- If a giant value is given, Int'Last will do well enough.
14237 -- If sometime someone complains that a record larger than
14238 -- two gigabytes is not copied, we will worry about it then.
14239
14240 else
14241 Default_C_Record_Mechanism := Mechanism_Type'Last;
14242 end if;
14243 end C_Pass_By_Copy;
14244
14245 -----------
14246 -- Check --
14247 -----------
14248
14249 -- pragma Check ([Name =>] CHECK_KIND,
14250 -- [Check =>] Boolean_EXPRESSION
14251 -- [,[Message =>] String_EXPRESSION]);
14252
14253 -- CHECK_KIND ::= IDENTIFIER |
14254 -- Pre'Class |
14255 -- Post'Class |
14256 -- Invariant'Class |
14257 -- Type_Invariant'Class
14258
14259 -- The identifiers Assertions and Statement_Assertions are not
14260 -- allowed, since they have special meaning for Check_Policy.
14261
14262 -- WARNING: The code below manages Ghost regions. Return statements
14263 -- must be replaced by gotos which jump to the end of the code and
14264 -- restore the Ghost mode.
14265
14266 when Pragma_Check => Check : declare
14267 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
14268 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
14269 -- Save the Ghost-related attributes to restore on exit
14270
14271 Cname : Name_Id;
14272 Eloc : Source_Ptr;
14273 Expr : Node_Id;
14274 Str : Node_Id;
14275 pragma Warnings (Off, Str);
14276
14277 begin
14278 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
14279 -- the mode now to ensure that any nodes generated during analysis
14280 -- and expansion are marked as Ghost.
14281
14282 Set_Ghost_Mode (N);
14283
14284 GNAT_Pragma;
14285 Check_At_Least_N_Arguments (2);
14286 Check_At_Most_N_Arguments (3);
14287 Check_Optional_Identifier (Arg1, Name_Name);
14288 Check_Optional_Identifier (Arg2, Name_Check);
14289
14290 if Arg_Count = 3 then
14291 Check_Optional_Identifier (Arg3, Name_Message);
14292 Str := Get_Pragma_Arg (Arg3);
14293 end if;
14294
14295 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
14296 Check_Arg_Is_Identifier (Arg1);
14297 Cname := Chars (Get_Pragma_Arg (Arg1));
14298
14299 -- Check forbidden name Assertions or Statement_Assertions
14300
14301 case Cname is
14302 when Name_Assertions =>
14303 Error_Pragma_Arg
14304 ("""Assertions"" is not allowed as a check kind for "
14305 & "pragma%", Arg1);
14306
14307 when Name_Statement_Assertions =>
14308 Error_Pragma_Arg
14309 ("""Statement_Assertions"" is not allowed as a check kind "
14310 & "for pragma%", Arg1);
14311
14312 when others =>
14313 null;
14314 end case;
14315
14316 -- Check applicable policy. We skip this if Checked/Ignored status
14317 -- is already set (e.g. in the case of a pragma from an aspect).
14318
14319 if Is_Checked (N) or else Is_Ignored (N) then
14320 null;
14321
14322 -- For a non-source pragma that is a rewriting of another pragma,
14323 -- copy the Is_Checked/Ignored status from the rewritten pragma.
14324
14325 elsif Is_Rewrite_Substitution (N)
14326 and then Nkind (Original_Node (N)) = N_Pragma
14327 then
14328 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
14329 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
14330
14331 -- Otherwise query the applicable policy at this point
14332
14333 else
14334 case Check_Kind (Cname) is
14335 when Name_Ignore =>
14336 Set_Is_Ignored (N, True);
14337 Set_Is_Checked (N, False);
14338
14339 when Name_Check =>
14340 Set_Is_Ignored (N, False);
14341 Set_Is_Checked (N, True);
14342
14343 -- For disable, rewrite pragma as null statement and skip
14344 -- rest of the analysis of the pragma.
14345
14346 when Name_Disable =>
14347 Rewrite (N, Make_Null_Statement (Loc));
14348 Analyze (N);
14349 raise Pragma_Exit;
14350
14351 -- No other possibilities
14352
14353 when others =>
14354 raise Program_Error;
14355 end case;
14356 end if;
14357
14358 -- If check kind was not Disable, then continue pragma analysis
14359
14360 Expr := Get_Pragma_Arg (Arg2);
14361
14362 -- Mark the pragma (or, if rewritten from an aspect, the original
14363 -- aspect) as enabled. Nothing to do for an internally generated
14364 -- check for a dynamic predicate.
14365
14366 if Is_Checked (N)
14367 and then not Split_PPC (N)
14368 and then Cname /= Name_Dynamic_Predicate
14369 then
14370 Set_SCO_Pragma_Enabled (Loc);
14371 end if;
14372
14373 -- Deal with analyzing the string argument. If checks are not
14374 -- on we don't want any expansion (since such expansion would
14375 -- not get properly deleted) but we do want to analyze (to get
14376 -- proper references). The Preanalyze_And_Resolve routine does
14377 -- just what we want. Ditto if pragma is active, because it will
14378 -- be rewritten as an if-statement whose analysis will complete
14379 -- analysis and expansion of the string message. This makes a
14380 -- difference in the unusual case where the expression for the
14381 -- string may have a side effect, such as raising an exception.
14382 -- This is mandated by RM 11.4.2, which specifies that the string
14383 -- expression is only evaluated if the check fails and
14384 -- Assertion_Error is to be raised.
14385
14386 if Arg_Count = 3 then
14387 Preanalyze_And_Resolve (Str, Standard_String);
14388 end if;
14389
14390 -- Now you might think we could just do the same with the Boolean
14391 -- expression if checks are off (and expansion is on) and then
14392 -- rewrite the check as a null statement. This would work but we
14393 -- would lose the useful warnings about an assertion being bound
14394 -- to fail even if assertions are turned off.
14395
14396 -- So instead we wrap the boolean expression in an if statement
14397 -- that looks like:
14398
14399 -- if False and then condition then
14400 -- null;
14401 -- end if;
14402
14403 -- The reason we do this rewriting during semantic analysis rather
14404 -- than as part of normal expansion is that we cannot analyze and
14405 -- expand the code for the boolean expression directly, or it may
14406 -- cause insertion of actions that would escape the attempt to
14407 -- suppress the check code.
14408
14409 -- Note that the Sloc for the if statement corresponds to the
14410 -- argument condition, not the pragma itself. The reason for
14411 -- this is that we may generate a warning if the condition is
14412 -- False at compile time, and we do not want to delete this
14413 -- warning when we delete the if statement.
14414
14415 if Expander_Active and Is_Ignored (N) then
14416 Eloc := Sloc (Expr);
14417
14418 Rewrite (N,
14419 Make_If_Statement (Eloc,
14420 Condition =>
14421 Make_And_Then (Eloc,
14422 Left_Opnd => Make_Identifier (Eloc, Name_False),
14423 Right_Opnd => Expr),
14424 Then_Statements => New_List (
14425 Make_Null_Statement (Eloc))));
14426
14427 -- Now go ahead and analyze the if statement
14428
14429 In_Assertion_Expr := In_Assertion_Expr + 1;
14430
14431 -- One rather special treatment. If we are now in Eliminated
14432 -- overflow mode, then suppress overflow checking since we do
14433 -- not want to drag in the bignum stuff if we are in Ignore
14434 -- mode anyway. This is particularly important if we are using
14435 -- a configurable run time that does not support bignum ops.
14436
14437 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
14438 declare
14439 Svo : constant Boolean :=
14440 Scope_Suppress.Suppress (Overflow_Check);
14441 begin
14442 Scope_Suppress.Overflow_Mode_Assertions := Strict;
14443 Scope_Suppress.Suppress (Overflow_Check) := True;
14444 Analyze (N);
14445 Scope_Suppress.Suppress (Overflow_Check) := Svo;
14446 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
14447 end;
14448
14449 -- Not that special case
14450
14451 else
14452 Analyze (N);
14453 end if;
14454
14455 -- All done with this check
14456
14457 In_Assertion_Expr := In_Assertion_Expr - 1;
14458
14459 -- Check is active or expansion not active. In these cases we can
14460 -- just go ahead and analyze the boolean with no worries.
14461
14462 else
14463 In_Assertion_Expr := In_Assertion_Expr + 1;
14464 Analyze_And_Resolve (Expr, Any_Boolean);
14465 In_Assertion_Expr := In_Assertion_Expr - 1;
14466 end if;
14467
14468 Restore_Ghost_Region (Saved_GM, Saved_IGR);
14469 end Check;
14470
14471 --------------------------
14472 -- Check_Float_Overflow --
14473 --------------------------
14474
14475 -- pragma Check_Float_Overflow;
14476
14477 when Pragma_Check_Float_Overflow =>
14478 GNAT_Pragma;
14479 Check_Valid_Configuration_Pragma;
14480 Check_Arg_Count (0);
14481 Check_Float_Overflow := not Machine_Overflows_On_Target;
14482
14483 ----------------
14484 -- Check_Name --
14485 ----------------
14486
14487 -- pragma Check_Name (check_IDENTIFIER);
14488
14489 when Pragma_Check_Name =>
14490 GNAT_Pragma;
14491 Check_No_Identifiers;
14492 Check_Valid_Configuration_Pragma;
14493 Check_Arg_Count (1);
14494 Check_Arg_Is_Identifier (Arg1);
14495
14496 declare
14497 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
14498
14499 begin
14500 for J in Check_Names.First .. Check_Names.Last loop
14501 if Check_Names.Table (J) = Nam then
14502 return;
14503 end if;
14504 end loop;
14505
14506 Check_Names.Append (Nam);
14507 end;
14508
14509 ------------------
14510 -- Check_Policy --
14511 ------------------
14512
14513 -- This is the old style syntax, which is still allowed in all modes:
14514
14515 -- pragma Check_Policy ([Name =>] CHECK_KIND
14516 -- [Policy =>] POLICY_IDENTIFIER);
14517
14518 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
14519
14520 -- CHECK_KIND ::= IDENTIFIER |
14521 -- Pre'Class |
14522 -- Post'Class |
14523 -- Type_Invariant'Class |
14524 -- Invariant'Class
14525
14526 -- This is the new style syntax, compatible with Assertion_Policy
14527 -- and also allowed in all modes.
14528
14529 -- Pragma Check_Policy (
14530 -- CHECK_KIND => POLICY_IDENTIFIER
14531 -- {, CHECK_KIND => POLICY_IDENTIFIER});
14532
14533 -- Note: the identifiers Name and Policy are not allowed as
14534 -- Check_Kind values. This avoids ambiguities between the old and
14535 -- new form syntax.
14536
14537 when Pragma_Check_Policy => Check_Policy : declare
14538 Kind : Node_Id;
14539
14540 begin
14541 GNAT_Pragma;
14542 Check_At_Least_N_Arguments (1);
14543
14544 -- A Check_Policy pragma can appear either as a configuration
14545 -- pragma, or in a declarative part or a package spec (see RM
14546 -- 11.5(5) for rules for Suppress/Unsuppress which are also
14547 -- followed for Check_Policy).
14548
14549 if not Is_Configuration_Pragma then
14550 Check_Is_In_Decl_Part_Or_Package_Spec;
14551 end if;
14552
14553 -- Figure out if we have the old or new syntax. We have the
14554 -- old syntax if the first argument has no identifier, or the
14555 -- identifier is Name.
14556
14557 if Nkind (Arg1) /= N_Pragma_Argument_Association
14558 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
14559 then
14560 -- Old syntax
14561
14562 Check_Arg_Count (2);
14563 Check_Optional_Identifier (Arg1, Name_Name);
14564 Kind := Get_Pragma_Arg (Arg1);
14565 Rewrite_Assertion_Kind (Kind,
14566 From_Policy => Comes_From_Source (N));
14567 Check_Arg_Is_Identifier (Arg1);
14568
14569 -- Check forbidden check kind
14570
14571 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
14572 Error_Msg_Name_2 := Chars (Kind);
14573 Error_Pragma_Arg
14574 ("pragma% does not allow% as check name", Arg1);
14575 end if;
14576
14577 -- Check policy
14578
14579 Check_Optional_Identifier (Arg2, Name_Policy);
14580 Check_Arg_Is_One_Of
14581 (Arg2,
14582 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
14583
14584 -- And chain pragma on the Check_Policy_List for search
14585
14586 Set_Next_Pragma (N, Opt.Check_Policy_List);
14587 Opt.Check_Policy_List := N;
14588
14589 -- For the new syntax, what we do is to convert each argument to
14590 -- an old syntax equivalent. We do that because we want to chain
14591 -- old style Check_Policy pragmas for the search (we don't want
14592 -- to have to deal with multiple arguments in the search).
14593
14594 else
14595 declare
14596 Arg : Node_Id;
14597 Argx : Node_Id;
14598 LocP : Source_Ptr;
14599 New_P : Node_Id;
14600
14601 begin
14602 Arg := Arg1;
14603 while Present (Arg) loop
14604 LocP := Sloc (Arg);
14605 Argx := Get_Pragma_Arg (Arg);
14606
14607 -- Kind must be specified
14608
14609 if Nkind (Arg) /= N_Pragma_Argument_Association
14610 or else Chars (Arg) = No_Name
14611 then
14612 Error_Pragma_Arg
14613 ("missing assertion kind for pragma%", Arg);
14614 end if;
14615
14616 -- Construct equivalent old form syntax Check_Policy
14617 -- pragma and insert it to get remaining checks.
14618
14619 New_P :=
14620 Make_Pragma (LocP,
14621 Chars => Name_Check_Policy,
14622 Pragma_Argument_Associations => New_List (
14623 Make_Pragma_Argument_Association (LocP,
14624 Expression =>
14625 Make_Identifier (LocP, Chars (Arg))),
14626 Make_Pragma_Argument_Association (Sloc (Argx),
14627 Expression => Argx)));
14628
14629 Arg := Next (Arg);
14630
14631 -- For a configuration pragma, insert old form in
14632 -- the corresponding file.
14633
14634 if Is_Configuration_Pragma then
14635 Insert_After (N, New_P);
14636 Analyze (New_P);
14637
14638 else
14639 Insert_Action (N, New_P);
14640 end if;
14641 end loop;
14642
14643 -- Rewrite original Check_Policy pragma to null, since we
14644 -- have converted it into a series of old syntax pragmas.
14645
14646 Rewrite (N, Make_Null_Statement (Loc));
14647 Analyze (N);
14648 end;
14649 end if;
14650 end Check_Policy;
14651
14652 -------------
14653 -- Comment --
14654 -------------
14655
14656 -- pragma Comment (static_string_EXPRESSION)
14657
14658 -- Processing for pragma Comment shares the circuitry for pragma
14659 -- Ident. The only differences are that Ident enforces a limit of 31
14660 -- characters on its argument, and also enforces limitations on
14661 -- placement for DEC compatibility. Pragma Comment shares neither of
14662 -- these restrictions.
14663
14664 -------------------
14665 -- Common_Object --
14666 -------------------
14667
14668 -- pragma Common_Object (
14669 -- [Internal =>] LOCAL_NAME
14670 -- [, [External =>] EXTERNAL_SYMBOL]
14671 -- [, [Size =>] EXTERNAL_SYMBOL]);
14672
14673 -- Processing for this pragma is shared with Psect_Object
14674
14675 ----------------------------------------------
14676 -- Compile_Time_Error, Compile_Time_Warning --
14677 ----------------------------------------------
14678
14679 -- pragma Compile_Time_Error
14680 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14681
14682 -- pragma Compile_Time_Warning
14683 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14684
14685 when Pragma_Compile_Time_Error | Pragma_Compile_Time_Warning =>
14686 GNAT_Pragma;
14687 Process_Compile_Time_Warning_Or_Error;
14688
14689 ---------------------------
14690 -- Compiler_Unit_Warning --
14691 ---------------------------
14692
14693 -- pragma Compiler_Unit_Warning;
14694
14695 -- Historical note
14696
14697 -- Originally, we had only pragma Compiler_Unit, and it resulted in
14698 -- errors not warnings. This means that we had introduced a big extra
14699 -- inertia to compiler changes, since even if we implemented a new
14700 -- feature, and even if all versions to be used for bootstrapping
14701 -- implemented this new feature, we could not use it, since old
14702 -- compilers would give errors for using this feature in units
14703 -- having Compiler_Unit pragmas.
14704
14705 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
14706 -- problem. We no longer have any units mentioning Compiler_Unit,
14707 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
14708 -- and thus generates a warning which can be ignored. So that deals
14709 -- with the problem of old compilers not implementing the newer form
14710 -- of the pragma.
14711
14712 -- Newer compilers recognize the new pragma, but generate warning
14713 -- messages instead of errors, which again can be ignored in the
14714 -- case of an old compiler which implements a wanted new feature
14715 -- but at the time felt like warning about it for older compilers.
14716
14717 -- We retain Compiler_Unit so that new compilers can be used to build
14718 -- older run-times that use this pragma. That's an unusual case, but
14719 -- it's easy enough to handle, so why not?
14720
14721 when Pragma_Compiler_Unit
14722 | Pragma_Compiler_Unit_Warning
14723 =>
14724 GNAT_Pragma;
14725 Check_Arg_Count (0);
14726
14727 -- Only recognized in main unit
14728
14729 if Current_Sem_Unit = Main_Unit then
14730 Compiler_Unit := True;
14731 end if;
14732
14733 -----------------------------
14734 -- Complete_Representation --
14735 -----------------------------
14736
14737 -- pragma Complete_Representation;
14738
14739 when Pragma_Complete_Representation =>
14740 GNAT_Pragma;
14741 Check_Arg_Count (0);
14742
14743 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
14744 Error_Pragma
14745 ("pragma & must appear within record representation clause");
14746 end if;
14747
14748 ----------------------------
14749 -- Complex_Representation --
14750 ----------------------------
14751
14752 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
14753
14754 when Pragma_Complex_Representation => Complex_Representation : declare
14755 E_Id : Entity_Id;
14756 E : Entity_Id;
14757 Ent : Entity_Id;
14758
14759 begin
14760 GNAT_Pragma;
14761 Check_Arg_Count (1);
14762 Check_Optional_Identifier (Arg1, Name_Entity);
14763 Check_Arg_Is_Local_Name (Arg1);
14764 E_Id := Get_Pragma_Arg (Arg1);
14765
14766 if Etype (E_Id) = Any_Type then
14767 return;
14768 end if;
14769
14770 E := Entity (E_Id);
14771
14772 if not Is_Record_Type (E) then
14773 Error_Pragma_Arg
14774 ("argument for pragma% must be record type", Arg1);
14775 end if;
14776
14777 Ent := First_Entity (E);
14778
14779 if No (Ent)
14780 or else No (Next_Entity (Ent))
14781 or else Present (Next_Entity (Next_Entity (Ent)))
14782 or else not Is_Floating_Point_Type (Etype (Ent))
14783 or else Etype (Ent) /= Etype (Next_Entity (Ent))
14784 then
14785 Error_Pragma_Arg
14786 ("record for pragma% must have two fields of the same "
14787 & "floating-point type", Arg1);
14788
14789 else
14790 Set_Has_Complex_Representation (Base_Type (E));
14791
14792 -- We need to treat the type has having a non-standard
14793 -- representation, for back-end purposes, even though in
14794 -- general a complex will have the default representation
14795 -- of a record with two real components.
14796
14797 Set_Has_Non_Standard_Rep (Base_Type (E));
14798 end if;
14799 end Complex_Representation;
14800
14801 -------------------------
14802 -- Component_Alignment --
14803 -------------------------
14804
14805 -- pragma Component_Alignment (
14806 -- [Form =>] ALIGNMENT_CHOICE
14807 -- [, [Name =>] type_LOCAL_NAME]);
14808 --
14809 -- ALIGNMENT_CHOICE ::=
14810 -- Component_Size
14811 -- | Component_Size_4
14812 -- | Storage_Unit
14813 -- | Default
14814
14815 when Pragma_Component_Alignment => Component_AlignmentP : declare
14816 Args : Args_List (1 .. 2);
14817 Names : constant Name_List (1 .. 2) := (
14818 Name_Form,
14819 Name_Name);
14820
14821 Form : Node_Id renames Args (1);
14822 Name : Node_Id renames Args (2);
14823
14824 Atype : Component_Alignment_Kind;
14825 Typ : Entity_Id;
14826
14827 begin
14828 GNAT_Pragma;
14829 Gather_Associations (Names, Args);
14830
14831 if No (Form) then
14832 Error_Pragma ("missing Form argument for pragma%");
14833 end if;
14834
14835 Check_Arg_Is_Identifier (Form);
14836
14837 -- Get proper alignment, note that Default = Component_Size on all
14838 -- machines we have so far, and we want to set this value rather
14839 -- than the default value to indicate that it has been explicitly
14840 -- set (and thus will not get overridden by the default component
14841 -- alignment for the current scope)
14842
14843 if Chars (Form) = Name_Component_Size then
14844 Atype := Calign_Component_Size;
14845
14846 elsif Chars (Form) = Name_Component_Size_4 then
14847 Atype := Calign_Component_Size_4;
14848
14849 elsif Chars (Form) = Name_Default then
14850 Atype := Calign_Component_Size;
14851
14852 elsif Chars (Form) = Name_Storage_Unit then
14853 Atype := Calign_Storage_Unit;
14854
14855 else
14856 Error_Pragma_Arg
14857 ("invalid Form parameter for pragma%", Form);
14858 end if;
14859
14860 -- The pragma appears in a configuration file
14861
14862 if No (Parent (N)) then
14863 Check_Valid_Configuration_Pragma;
14864
14865 -- Capture the component alignment in a global variable when
14866 -- the pragma appears in a configuration file. Note that the
14867 -- scope stack is empty at this point and cannot be used to
14868 -- store the alignment value.
14869
14870 Configuration_Component_Alignment := Atype;
14871
14872 -- Case with no name, supplied, affects scope table entry
14873
14874 elsif No (Name) then
14875 Scope_Stack.Table
14876 (Scope_Stack.Last).Component_Alignment_Default := Atype;
14877
14878 -- Case of name supplied
14879
14880 else
14881 Check_Arg_Is_Local_Name (Name);
14882 Find_Type (Name);
14883 Typ := Entity (Name);
14884
14885 if Typ = Any_Type
14886 or else Rep_Item_Too_Early (Typ, N)
14887 then
14888 return;
14889 else
14890 Typ := Underlying_Type (Typ);
14891 end if;
14892
14893 if not Is_Record_Type (Typ)
14894 and then not Is_Array_Type (Typ)
14895 then
14896 Error_Pragma_Arg
14897 ("Name parameter of pragma% must identify record or "
14898 & "array type", Name);
14899 end if;
14900
14901 -- An explicit Component_Alignment pragma overrides an
14902 -- implicit pragma Pack, but not an explicit one.
14903
14904 if not Has_Pragma_Pack (Base_Type (Typ)) then
14905 Set_Is_Packed (Base_Type (Typ), False);
14906 Set_Component_Alignment (Base_Type (Typ), Atype);
14907 end if;
14908 end if;
14909 end Component_AlignmentP;
14910
14911 --------------------------------
14912 -- Constant_After_Elaboration --
14913 --------------------------------
14914
14915 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
14916
14917 when Pragma_Constant_After_Elaboration => Constant_After_Elaboration :
14918 declare
14919 Obj_Decl : Node_Id;
14920 Obj_Id : Entity_Id;
14921
14922 begin
14923 GNAT_Pragma;
14924 Check_No_Identifiers;
14925 Check_At_Most_N_Arguments (1);
14926
14927 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
14928
14929 if Nkind (Obj_Decl) /= N_Object_Declaration then
14930 Pragma_Misplaced;
14931 return;
14932 end if;
14933
14934 Obj_Id := Defining_Entity (Obj_Decl);
14935
14936 -- The object declaration must be a library-level variable which
14937 -- is either explicitly initialized or obtains a value during the
14938 -- elaboration of a package body (SPARK RM 3.3.1).
14939
14940 if Ekind (Obj_Id) = E_Variable then
14941 if not Is_Library_Level_Entity (Obj_Id) then
14942 Error_Pragma
14943 ("pragma % must apply to a library level variable");
14944 return;
14945 end if;
14946
14947 -- Otherwise the pragma applies to a constant, which is illegal
14948
14949 else
14950 Error_Pragma ("pragma % must apply to a variable declaration");
14951 return;
14952 end if;
14953
14954 -- A pragma that applies to a Ghost entity becomes Ghost for the
14955 -- purposes of legality checks and removal of ignored Ghost code.
14956
14957 Mark_Ghost_Pragma (N, Obj_Id);
14958
14959 -- Chain the pragma on the contract for completeness
14960
14961 Add_Contract_Item (N, Obj_Id);
14962
14963 -- Analyze the Boolean expression (if any)
14964
14965 if Present (Arg1) then
14966 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
14967 end if;
14968 end Constant_After_Elaboration;
14969
14970 --------------------
14971 -- Contract_Cases --
14972 --------------------
14973
14974 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
14975
14976 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
14977
14978 -- CASE_GUARD ::= boolean_EXPRESSION | others
14979
14980 -- CONSEQUENCE ::= boolean_EXPRESSION
14981
14982 -- Characteristics:
14983
14984 -- * Analysis - The annotation undergoes initial checks to verify
14985 -- the legal placement and context. Secondary checks preanalyze the
14986 -- expressions in:
14987
14988 -- Analyze_Contract_Cases_In_Decl_Part
14989
14990 -- * Expansion - The annotation is expanded during the expansion of
14991 -- the related subprogram [body] contract as performed in:
14992
14993 -- Expand_Subprogram_Contract
14994
14995 -- * Template - The annotation utilizes the generic template of the
14996 -- related subprogram [body] when it is:
14997
14998 -- aspect on subprogram declaration
14999 -- aspect on stand-alone subprogram body
15000 -- pragma on stand-alone subprogram body
15001
15002 -- The annotation must prepare its own template when it is:
15003
15004 -- pragma on subprogram declaration
15005
15006 -- * Globals - Capture of global references must occur after full
15007 -- analysis.
15008
15009 -- * Instance - The annotation is instantiated automatically when
15010 -- the related generic subprogram [body] is instantiated except for
15011 -- the "pragma on subprogram declaration" case. In that scenario
15012 -- the annotation must instantiate itself.
15013
15014 when Pragma_Contract_Cases => Contract_Cases : declare
15015 Spec_Id : Entity_Id;
15016 Subp_Decl : Node_Id;
15017 Subp_Spec : Node_Id;
15018
15019 begin
15020 GNAT_Pragma;
15021 Check_No_Identifiers;
15022 Check_Arg_Count (1);
15023
15024 -- Ensure the proper placement of the pragma. Contract_Cases must
15025 -- be associated with a subprogram declaration or a body that acts
15026 -- as a spec.
15027
15028 Subp_Decl :=
15029 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
15030
15031 -- Entry
15032
15033 if Nkind (Subp_Decl) = N_Entry_Declaration then
15034 null;
15035
15036 -- Generic subprogram
15037
15038 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
15039 null;
15040
15041 -- Body acts as spec
15042
15043 elsif Nkind (Subp_Decl) = N_Subprogram_Body
15044 and then No (Corresponding_Spec (Subp_Decl))
15045 then
15046 null;
15047
15048 -- Body stub acts as spec
15049
15050 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
15051 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
15052 then
15053 null;
15054
15055 -- Subprogram
15056
15057 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
15058 Subp_Spec := Specification (Subp_Decl);
15059
15060 -- Pragma Contract_Cases is forbidden on null procedures, as
15061 -- this may lead to potential ambiguities in behavior when
15062 -- interface null procedures are involved.
15063
15064 if Nkind (Subp_Spec) = N_Procedure_Specification
15065 and then Null_Present (Subp_Spec)
15066 then
15067 Error_Msg_N (Fix_Error
15068 ("pragma % cannot apply to null procedure"), N);
15069 return;
15070 end if;
15071
15072 else
15073 Pragma_Misplaced;
15074 return;
15075 end if;
15076
15077 Spec_Id := Unique_Defining_Entity (Subp_Decl);
15078
15079 -- A pragma that applies to a Ghost entity becomes Ghost for the
15080 -- purposes of legality checks and removal of ignored Ghost code.
15081
15082 Mark_Ghost_Pragma (N, Spec_Id);
15083 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
15084
15085 -- Chain the pragma on the contract for further processing by
15086 -- Analyze_Contract_Cases_In_Decl_Part.
15087
15088 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
15089
15090 -- Fully analyze the pragma when it appears inside an entry
15091 -- or subprogram body because it cannot benefit from forward
15092 -- references.
15093
15094 if Nkind_In (Subp_Decl, N_Entry_Body,
15095 N_Subprogram_Body,
15096 N_Subprogram_Body_Stub)
15097 then
15098 -- The legality checks of pragma Contract_Cases are affected by
15099 -- the SPARK mode in effect and the volatility of the context.
15100 -- Analyze all pragmas in a specific order.
15101
15102 Analyze_If_Present (Pragma_SPARK_Mode);
15103 Analyze_If_Present (Pragma_Volatile_Function);
15104 Analyze_Contract_Cases_In_Decl_Part (N);
15105 end if;
15106 end Contract_Cases;
15107
15108 ----------------
15109 -- Controlled --
15110 ----------------
15111
15112 -- pragma Controlled (first_subtype_LOCAL_NAME);
15113
15114 when Pragma_Controlled => Controlled : declare
15115 Arg : Node_Id;
15116
15117 begin
15118 Check_No_Identifiers;
15119 Check_Arg_Count (1);
15120 Check_Arg_Is_Local_Name (Arg1);
15121 Arg := Get_Pragma_Arg (Arg1);
15122
15123 if not Is_Entity_Name (Arg)
15124 or else not Is_Access_Type (Entity (Arg))
15125 then
15126 Error_Pragma_Arg ("pragma% requires access type", Arg1);
15127 else
15128 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
15129 end if;
15130 end Controlled;
15131
15132 ----------------
15133 -- Convention --
15134 ----------------
15135
15136 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
15137 -- [Entity =>] LOCAL_NAME);
15138
15139 when Pragma_Convention => Convention : declare
15140 C : Convention_Id;
15141 E : Entity_Id;
15142 pragma Warnings (Off, C);
15143 pragma Warnings (Off, E);
15144
15145 begin
15146 Check_Arg_Order ((Name_Convention, Name_Entity));
15147 Check_Ada_83_Warning;
15148 Check_Arg_Count (2);
15149 Process_Convention (C, E);
15150
15151 -- A pragma that applies to a Ghost entity becomes Ghost for the
15152 -- purposes of legality checks and removal of ignored Ghost code.
15153
15154 Mark_Ghost_Pragma (N, E);
15155 end Convention;
15156
15157 ---------------------------
15158 -- Convention_Identifier --
15159 ---------------------------
15160
15161 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
15162 -- [Convention =>] convention_IDENTIFIER);
15163
15164 when Pragma_Convention_Identifier => Convention_Identifier : declare
15165 Idnam : Name_Id;
15166 Cname : Name_Id;
15167
15168 begin
15169 GNAT_Pragma;
15170 Check_Arg_Order ((Name_Name, Name_Convention));
15171 Check_Arg_Count (2);
15172 Check_Optional_Identifier (Arg1, Name_Name);
15173 Check_Optional_Identifier (Arg2, Name_Convention);
15174 Check_Arg_Is_Identifier (Arg1);
15175 Check_Arg_Is_Identifier (Arg2);
15176 Idnam := Chars (Get_Pragma_Arg (Arg1));
15177 Cname := Chars (Get_Pragma_Arg (Arg2));
15178
15179 if Is_Convention_Name (Cname) then
15180 Record_Convention_Identifier
15181 (Idnam, Get_Convention_Id (Cname));
15182 else
15183 Error_Pragma_Arg
15184 ("second arg for % pragma must be convention", Arg2);
15185 end if;
15186 end Convention_Identifier;
15187
15188 ---------------
15189 -- CPP_Class --
15190 ---------------
15191
15192 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
15193
15194 when Pragma_CPP_Class =>
15195 GNAT_Pragma;
15196
15197 if Warn_On_Obsolescent_Feature then
15198 Error_Msg_N
15199 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
15200 & "effect; replace it by pragma import?j?", N);
15201 end if;
15202
15203 Check_Arg_Count (1);
15204
15205 Rewrite (N,
15206 Make_Pragma (Loc,
15207 Chars => Name_Import,
15208 Pragma_Argument_Associations => New_List (
15209 Make_Pragma_Argument_Association (Loc,
15210 Expression => Make_Identifier (Loc, Name_CPP)),
15211 New_Copy (First (Pragma_Argument_Associations (N))))));
15212 Analyze (N);
15213
15214 ---------------------
15215 -- CPP_Constructor --
15216 ---------------------
15217
15218 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
15219 -- [, [External_Name =>] static_string_EXPRESSION ]
15220 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15221
15222 when Pragma_CPP_Constructor => CPP_Constructor : declare
15223 Elmt : Elmt_Id;
15224 Id : Entity_Id;
15225 Def_Id : Entity_Id;
15226 Tag_Typ : Entity_Id;
15227
15228 begin
15229 GNAT_Pragma;
15230 Check_At_Least_N_Arguments (1);
15231 Check_At_Most_N_Arguments (3);
15232 Check_Optional_Identifier (Arg1, Name_Entity);
15233 Check_Arg_Is_Local_Name (Arg1);
15234
15235 Id := Get_Pragma_Arg (Arg1);
15236 Find_Program_Unit_Name (Id);
15237
15238 -- If we did not find the name, we are done
15239
15240 if Etype (Id) = Any_Type then
15241 return;
15242 end if;
15243
15244 Def_Id := Entity (Id);
15245
15246 -- Check if already defined as constructor
15247
15248 if Is_Constructor (Def_Id) then
15249 Error_Msg_N
15250 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
15251 return;
15252 end if;
15253
15254 if Ekind (Def_Id) = E_Function
15255 and then (Is_CPP_Class (Etype (Def_Id))
15256 or else (Is_Class_Wide_Type (Etype (Def_Id))
15257 and then
15258 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
15259 then
15260 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
15261 Error_Msg_N
15262 ("'C'P'P constructor must be defined in the scope of "
15263 & "its returned type", Arg1);
15264 end if;
15265
15266 if Arg_Count >= 2 then
15267 Set_Imported (Def_Id);
15268 Set_Is_Public (Def_Id);
15269 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
15270 end if;
15271
15272 Set_Has_Completion (Def_Id);
15273 Set_Is_Constructor (Def_Id);
15274 Set_Convention (Def_Id, Convention_CPP);
15275
15276 -- Imported C++ constructors are not dispatching primitives
15277 -- because in C++ they don't have a dispatch table slot.
15278 -- However, in Ada the constructor has the profile of a
15279 -- function that returns a tagged type and therefore it has
15280 -- been treated as a primitive operation during semantic
15281 -- analysis. We now remove it from the list of primitive
15282 -- operations of the type.
15283
15284 if Is_Tagged_Type (Etype (Def_Id))
15285 and then not Is_Class_Wide_Type (Etype (Def_Id))
15286 and then Is_Dispatching_Operation (Def_Id)
15287 then
15288 Tag_Typ := Etype (Def_Id);
15289
15290 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
15291 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
15292 Next_Elmt (Elmt);
15293 end loop;
15294
15295 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
15296 Set_Is_Dispatching_Operation (Def_Id, False);
15297 end if;
15298
15299 -- For backward compatibility, if the constructor returns a
15300 -- class wide type, and we internally change the return type to
15301 -- the corresponding root type.
15302
15303 if Is_Class_Wide_Type (Etype (Def_Id)) then
15304 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
15305 end if;
15306 else
15307 Error_Pragma_Arg
15308 ("pragma% requires function returning a 'C'P'P_Class type",
15309 Arg1);
15310 end if;
15311 end CPP_Constructor;
15312
15313 -----------------
15314 -- CPP_Virtual --
15315 -----------------
15316
15317 when Pragma_CPP_Virtual =>
15318 GNAT_Pragma;
15319
15320 if Warn_On_Obsolescent_Feature then
15321 Error_Msg_N
15322 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
15323 & "effect?j?", N);
15324 end if;
15325
15326 ----------------
15327 -- CPP_Vtable --
15328 ----------------
15329
15330 when Pragma_CPP_Vtable =>
15331 GNAT_Pragma;
15332
15333 if Warn_On_Obsolescent_Feature then
15334 Error_Msg_N
15335 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
15336 & "effect?j?", N);
15337 end if;
15338
15339 ---------
15340 -- CPU --
15341 ---------
15342
15343 -- pragma CPU (EXPRESSION);
15344
15345 when Pragma_CPU => CPU : declare
15346 P : constant Node_Id := Parent (N);
15347 Arg : Node_Id;
15348 Ent : Entity_Id;
15349
15350 begin
15351 Ada_2012_Pragma;
15352 Check_No_Identifiers;
15353 Check_Arg_Count (1);
15354
15355 -- Subprogram case
15356
15357 if Nkind (P) = N_Subprogram_Body then
15358 Check_In_Main_Program;
15359
15360 Arg := Get_Pragma_Arg (Arg1);
15361 Analyze_And_Resolve (Arg, Any_Integer);
15362
15363 Ent := Defining_Unit_Name (Specification (P));
15364
15365 if Nkind (Ent) = N_Defining_Program_Unit_Name then
15366 Ent := Defining_Identifier (Ent);
15367 end if;
15368
15369 -- Must be static
15370
15371 if not Is_OK_Static_Expression (Arg) then
15372 Flag_Non_Static_Expr
15373 ("main subprogram affinity is not static!", Arg);
15374 raise Pragma_Exit;
15375
15376 -- If constraint error, then we already signalled an error
15377
15378 elsif Raises_Constraint_Error (Arg) then
15379 null;
15380
15381 -- Otherwise check in range
15382
15383 else
15384 declare
15385 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
15386 -- This is the entity System.Multiprocessors.CPU_Range;
15387
15388 Val : constant Uint := Expr_Value (Arg);
15389
15390 begin
15391 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
15392 or else
15393 Val > Expr_Value (Type_High_Bound (CPU_Id))
15394 then
15395 Error_Pragma_Arg
15396 ("main subprogram CPU is out of range", Arg1);
15397 end if;
15398 end;
15399 end if;
15400
15401 Set_Main_CPU
15402 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
15403
15404 -- Task case
15405
15406 elsif Nkind (P) = N_Task_Definition then
15407 Arg := Get_Pragma_Arg (Arg1);
15408 Ent := Defining_Identifier (Parent (P));
15409
15410 -- The expression must be analyzed in the special manner
15411 -- described in "Handling of Default and Per-Object
15412 -- Expressions" in sem.ads.
15413
15414 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
15415
15416 -- Anything else is incorrect
15417
15418 else
15419 Pragma_Misplaced;
15420 end if;
15421
15422 -- Check duplicate pragma before we chain the pragma in the Rep
15423 -- Item chain of Ent.
15424
15425 Check_Duplicate_Pragma (Ent);
15426 Record_Rep_Item (Ent, N);
15427 end CPU;
15428
15429 --------------------
15430 -- Deadline_Floor --
15431 --------------------
15432
15433 -- pragma Deadline_Floor (time_span_EXPRESSION);
15434
15435 when Pragma_Deadline_Floor => Deadline_Floor : declare
15436 P : constant Node_Id := Parent (N);
15437 Arg : Node_Id;
15438 Ent : Entity_Id;
15439
15440 begin
15441 GNAT_Pragma;
15442 Check_No_Identifiers;
15443 Check_Arg_Count (1);
15444
15445 Arg := Get_Pragma_Arg (Arg1);
15446
15447 -- The expression must be analyzed in the special manner described
15448 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
15449
15450 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
15451
15452 -- Only protected types allowed
15453
15454 if Nkind (P) /= N_Protected_Definition then
15455 Pragma_Misplaced;
15456
15457 else
15458 Ent := Defining_Identifier (Parent (P));
15459
15460 -- Check duplicate pragma before we chain the pragma in the Rep
15461 -- Item chain of Ent.
15462
15463 Check_Duplicate_Pragma (Ent);
15464 Record_Rep_Item (Ent, N);
15465 end if;
15466 end Deadline_Floor;
15467
15468 -----------
15469 -- Debug --
15470 -----------
15471
15472 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
15473
15474 when Pragma_Debug => Debug : declare
15475 Cond : Node_Id;
15476 Call : Node_Id;
15477
15478 begin
15479 GNAT_Pragma;
15480
15481 -- The condition for executing the call is that the expander
15482 -- is active and that we are not ignoring this debug pragma.
15483
15484 Cond :=
15485 New_Occurrence_Of
15486 (Boolean_Literals
15487 (Expander_Active and then not Is_Ignored (N)),
15488 Loc);
15489
15490 if not Is_Ignored (N) then
15491 Set_SCO_Pragma_Enabled (Loc);
15492 end if;
15493
15494 if Arg_Count = 2 then
15495 Cond :=
15496 Make_And_Then (Loc,
15497 Left_Opnd => Relocate_Node (Cond),
15498 Right_Opnd => Get_Pragma_Arg (Arg1));
15499 Call := Get_Pragma_Arg (Arg2);
15500 else
15501 Call := Get_Pragma_Arg (Arg1);
15502 end if;
15503
15504 if Nkind_In (Call, N_Expanded_Name,
15505 N_Function_Call,
15506 N_Identifier,
15507 N_Indexed_Component,
15508 N_Selected_Component)
15509 then
15510 -- If this pragma Debug comes from source, its argument was
15511 -- parsed as a name form (which is syntactically identical).
15512 -- In a generic context a parameterless call will be left as
15513 -- an expanded name (if global) or selected_component if local.
15514 -- Change it to a procedure call statement now.
15515
15516 Change_Name_To_Procedure_Call_Statement (Call);
15517
15518 elsif Nkind (Call) = N_Procedure_Call_Statement then
15519
15520 -- Already in the form of a procedure call statement: nothing
15521 -- to do (could happen in case of an internally generated
15522 -- pragma Debug).
15523
15524 null;
15525
15526 else
15527 -- All other cases: diagnose error
15528
15529 Error_Msg
15530 ("argument of pragma ""Debug"" is not procedure call",
15531 Sloc (Call));
15532 return;
15533 end if;
15534
15535 -- Rewrite into a conditional with an appropriate condition. We
15536 -- wrap the procedure call in a block so that overhead from e.g.
15537 -- use of the secondary stack does not generate execution overhead
15538 -- for suppressed conditions.
15539
15540 -- Normally the analysis that follows will freeze the subprogram
15541 -- being called. However, if the call is to a null procedure,
15542 -- we want to freeze it before creating the block, because the
15543 -- analysis that follows may be done with expansion disabled, in
15544 -- which case the body will not be generated, leading to spurious
15545 -- errors.
15546
15547 if Nkind (Call) = N_Procedure_Call_Statement
15548 and then Is_Entity_Name (Name (Call))
15549 then
15550 Analyze (Name (Call));
15551 Freeze_Before (N, Entity (Name (Call)));
15552 end if;
15553
15554 Rewrite (N,
15555 Make_Implicit_If_Statement (N,
15556 Condition => Cond,
15557 Then_Statements => New_List (
15558 Make_Block_Statement (Loc,
15559 Handled_Statement_Sequence =>
15560 Make_Handled_Sequence_Of_Statements (Loc,
15561 Statements => New_List (Relocate_Node (Call)))))));
15562 Analyze (N);
15563
15564 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
15565 -- after analysis of the normally rewritten node, to capture all
15566 -- references to entities, which avoids issuing wrong warnings
15567 -- about unused entities.
15568
15569 if GNATprove_Mode then
15570 Rewrite (N, Make_Null_Statement (Loc));
15571 end if;
15572 end Debug;
15573
15574 ------------------
15575 -- Debug_Policy --
15576 ------------------
15577
15578 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
15579
15580 when Pragma_Debug_Policy =>
15581 GNAT_Pragma;
15582 Check_Arg_Count (1);
15583 Check_No_Identifiers;
15584 Check_Arg_Is_Identifier (Arg1);
15585
15586 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
15587 -- rewrite it that way, and let the rest of the checking come
15588 -- from analyzing the rewritten pragma.
15589
15590 Rewrite (N,
15591 Make_Pragma (Loc,
15592 Chars => Name_Check_Policy,
15593 Pragma_Argument_Associations => New_List (
15594 Make_Pragma_Argument_Association (Loc,
15595 Expression => Make_Identifier (Loc, Name_Debug)),
15596
15597 Make_Pragma_Argument_Association (Loc,
15598 Expression => Get_Pragma_Arg (Arg1)))));
15599 Analyze (N);
15600
15601 -------------------------------
15602 -- Default_Initial_Condition --
15603 -------------------------------
15604
15605 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
15606
15607 when Pragma_Default_Initial_Condition => DIC : declare
15608 Discard : Boolean;
15609 Stmt : Node_Id;
15610 Typ : Entity_Id;
15611
15612 begin
15613 GNAT_Pragma;
15614 Check_No_Identifiers;
15615 Check_At_Most_N_Arguments (1);
15616
15617 Typ := Empty;
15618 Stmt := Prev (N);
15619 while Present (Stmt) loop
15620
15621 -- Skip prior pragmas, but check for duplicates
15622
15623 if Nkind (Stmt) = N_Pragma then
15624 if Pragma_Name (Stmt) = Pname then
15625 Duplication_Error
15626 (Prag => N,
15627 Prev => Stmt);
15628 raise Pragma_Exit;
15629 end if;
15630
15631 -- Skip internally generated code. Note that derived type
15632 -- declarations of untagged types with discriminants are
15633 -- rewritten as private type declarations.
15634
15635 elsif not Comes_From_Source (Stmt)
15636 and then Nkind (Stmt) /= N_Private_Type_Declaration
15637 then
15638 null;
15639
15640 -- The associated private type [extension] has been found, stop
15641 -- the search.
15642
15643 elsif Nkind_In (Stmt, N_Private_Extension_Declaration,
15644 N_Private_Type_Declaration)
15645 then
15646 Typ := Defining_Entity (Stmt);
15647 exit;
15648
15649 -- The pragma does not apply to a legal construct, issue an
15650 -- error and stop the analysis.
15651
15652 else
15653 Pragma_Misplaced;
15654 return;
15655 end if;
15656
15657 Stmt := Prev (Stmt);
15658 end loop;
15659
15660 -- The pragma does not apply to a legal construct, issue an error
15661 -- and stop the analysis.
15662
15663 if No (Typ) then
15664 Pragma_Misplaced;
15665 return;
15666 end if;
15667
15668 -- A pragma that applies to a Ghost entity becomes Ghost for the
15669 -- purposes of legality checks and removal of ignored Ghost code.
15670
15671 Mark_Ghost_Pragma (N, Typ);
15672
15673 -- The pragma signals that the type defines its own DIC assertion
15674 -- expression.
15675
15676 Set_Has_Own_DIC (Typ);
15677
15678 -- Chain the pragma on the rep item chain for further processing
15679
15680 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15681
15682 -- Create the declaration of the procedure which verifies the
15683 -- assertion expression of pragma DIC at runtime.
15684
15685 Build_DIC_Procedure_Declaration (Typ);
15686 end DIC;
15687
15688 ----------------------------------
15689 -- Default_Scalar_Storage_Order --
15690 ----------------------------------
15691
15692 -- pragma Default_Scalar_Storage_Order
15693 -- (High_Order_First | Low_Order_First);
15694
15695 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
15696 Default : Character;
15697
15698 begin
15699 GNAT_Pragma;
15700 Check_Arg_Count (1);
15701
15702 -- Default_Scalar_Storage_Order can appear as a configuration
15703 -- pragma, or in a declarative part of a package spec.
15704
15705 if not Is_Configuration_Pragma then
15706 Check_Is_In_Decl_Part_Or_Package_Spec;
15707 end if;
15708
15709 Check_No_Identifiers;
15710 Check_Arg_Is_One_Of
15711 (Arg1, Name_High_Order_First, Name_Low_Order_First);
15712 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15713 Default := Fold_Upper (Name_Buffer (1));
15714
15715 if not Support_Nondefault_SSO_On_Target
15716 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
15717 then
15718 if Warn_On_Unrecognized_Pragma then
15719 Error_Msg_N
15720 ("non-default Scalar_Storage_Order not supported "
15721 & "on target?g?", N);
15722 Error_Msg_N
15723 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
15724 end if;
15725
15726 -- Here set the specified default
15727
15728 else
15729 Opt.Default_SSO := Default;
15730 end if;
15731 end DSSO;
15732
15733 --------------------------
15734 -- Default_Storage_Pool --
15735 --------------------------
15736
15737 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
15738
15739 when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
15740 Pool : Node_Id;
15741
15742 begin
15743 Ada_2012_Pragma;
15744 Check_Arg_Count (1);
15745
15746 -- Default_Storage_Pool can appear as a configuration pragma, or
15747 -- in a declarative part of a package spec.
15748
15749 if not Is_Configuration_Pragma then
15750 Check_Is_In_Decl_Part_Or_Package_Spec;
15751 end if;
15752
15753 if From_Aspect_Specification (N) then
15754 declare
15755 E : constant Entity_Id := Entity (Corresponding_Aspect (N));
15756 begin
15757 if not In_Open_Scopes (E) then
15758 Error_Msg_N
15759 ("aspect must apply to package or subprogram", N);
15760 end if;
15761 end;
15762 end if;
15763
15764 if Present (Arg1) then
15765 Pool := Get_Pragma_Arg (Arg1);
15766
15767 -- Case of Default_Storage_Pool (null);
15768
15769 if Nkind (Pool) = N_Null then
15770 Analyze (Pool);
15771
15772 -- This is an odd case, this is not really an expression,
15773 -- so we don't have a type for it. So just set the type to
15774 -- Empty.
15775
15776 Set_Etype (Pool, Empty);
15777
15778 -- Case of Default_Storage_Pool (storage_pool_NAME);
15779
15780 else
15781 -- If it's a configuration pragma, then the only allowed
15782 -- argument is "null".
15783
15784 if Is_Configuration_Pragma then
15785 Error_Pragma_Arg ("NULL expected", Arg1);
15786 end if;
15787
15788 -- The expected type for a non-"null" argument is
15789 -- Root_Storage_Pool'Class, and the pool must be a variable.
15790
15791 Analyze_And_Resolve
15792 (Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
15793
15794 if Is_Variable (Pool) then
15795
15796 -- A pragma that applies to a Ghost entity becomes Ghost
15797 -- for the purposes of legality checks and removal of
15798 -- ignored Ghost code.
15799
15800 Mark_Ghost_Pragma (N, Entity (Pool));
15801
15802 else
15803 Error_Pragma_Arg
15804 ("default storage pool must be a variable", Arg1);
15805 end if;
15806 end if;
15807
15808 -- Record the pool name (or null). Freeze.Freeze_Entity for an
15809 -- access type will use this information to set the appropriate
15810 -- attributes of the access type. If the pragma appears in a
15811 -- generic unit it is ignored, given that it may refer to a
15812 -- local entity.
15813
15814 if not Inside_A_Generic then
15815 Default_Pool := Pool;
15816 end if;
15817 end if;
15818 end Default_Storage_Pool;
15819
15820 -------------
15821 -- Depends --
15822 -------------
15823
15824 -- pragma Depends (DEPENDENCY_RELATION);
15825
15826 -- DEPENDENCY_RELATION ::=
15827 -- null
15828 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
15829
15830 -- DEPENDENCY_CLAUSE ::=
15831 -- OUTPUT_LIST =>[+] INPUT_LIST
15832 -- | NULL_DEPENDENCY_CLAUSE
15833
15834 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
15835
15836 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
15837
15838 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
15839
15840 -- OUTPUT ::= NAME | FUNCTION_RESULT
15841 -- INPUT ::= NAME
15842
15843 -- where FUNCTION_RESULT is a function Result attribute_reference
15844
15845 -- Characteristics:
15846
15847 -- * Analysis - The annotation undergoes initial checks to verify
15848 -- the legal placement and context. Secondary checks fully analyze
15849 -- the dependency clauses in:
15850
15851 -- Analyze_Depends_In_Decl_Part
15852
15853 -- * Expansion - None.
15854
15855 -- * Template - The annotation utilizes the generic template of the
15856 -- related subprogram [body] when it is:
15857
15858 -- aspect on subprogram declaration
15859 -- aspect on stand-alone subprogram body
15860 -- pragma on stand-alone subprogram body
15861
15862 -- The annotation must prepare its own template when it is:
15863
15864 -- pragma on subprogram declaration
15865
15866 -- * Globals - Capture of global references must occur after full
15867 -- analysis.
15868
15869 -- * Instance - The annotation is instantiated automatically when
15870 -- the related generic subprogram [body] is instantiated except for
15871 -- the "pragma on subprogram declaration" case. In that scenario
15872 -- the annotation must instantiate itself.
15873
15874 when Pragma_Depends => Depends : declare
15875 Legal : Boolean;
15876 Spec_Id : Entity_Id;
15877 Subp_Decl : Node_Id;
15878
15879 begin
15880 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
15881
15882 if Legal then
15883
15884 -- Chain the pragma on the contract for further processing by
15885 -- Analyze_Depends_In_Decl_Part.
15886
15887 Add_Contract_Item (N, Spec_Id);
15888
15889 -- Fully analyze the pragma when it appears inside an entry
15890 -- or subprogram body because it cannot benefit from forward
15891 -- references.
15892
15893 if Nkind_In (Subp_Decl, N_Entry_Body,
15894 N_Subprogram_Body,
15895 N_Subprogram_Body_Stub)
15896 then
15897 -- The legality checks of pragmas Depends and Global are
15898 -- affected by the SPARK mode in effect and the volatility
15899 -- of the context. In addition these two pragmas are subject
15900 -- to an inherent order:
15901
15902 -- 1) Global
15903 -- 2) Depends
15904
15905 -- Analyze all these pragmas in the order outlined above
15906
15907 Analyze_If_Present (Pragma_SPARK_Mode);
15908 Analyze_If_Present (Pragma_Volatile_Function);
15909 Analyze_If_Present (Pragma_Global);
15910 Analyze_Depends_In_Decl_Part (N);
15911 end if;
15912 end if;
15913 end Depends;
15914
15915 ---------------------
15916 -- Detect_Blocking --
15917 ---------------------
15918
15919 -- pragma Detect_Blocking;
15920
15921 when Pragma_Detect_Blocking =>
15922 Ada_2005_Pragma;
15923 Check_Arg_Count (0);
15924 Check_Valid_Configuration_Pragma;
15925 Detect_Blocking := True;
15926
15927 ------------------------------------
15928 -- Disable_Atomic_Synchronization --
15929 ------------------------------------
15930
15931 -- pragma Disable_Atomic_Synchronization [(Entity)];
15932
15933 when Pragma_Disable_Atomic_Synchronization =>
15934 GNAT_Pragma;
15935 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
15936
15937 -------------------
15938 -- Discard_Names --
15939 -------------------
15940
15941 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
15942
15943 when Pragma_Discard_Names => Discard_Names : declare
15944 E : Entity_Id;
15945 E_Id : Node_Id;
15946
15947 begin
15948 Check_Ada_83_Warning;
15949
15950 -- Deal with configuration pragma case
15951
15952 if Arg_Count = 0 and then Is_Configuration_Pragma then
15953 Global_Discard_Names := True;
15954 return;
15955
15956 -- Otherwise, check correct appropriate context
15957
15958 else
15959 Check_Is_In_Decl_Part_Or_Package_Spec;
15960
15961 if Arg_Count = 0 then
15962
15963 -- If there is no parameter, then from now on this pragma
15964 -- applies to any enumeration, exception or tagged type
15965 -- defined in the current declarative part, and recursively
15966 -- to any nested scope.
15967
15968 Set_Discard_Names (Current_Scope);
15969 return;
15970
15971 else
15972 Check_Arg_Count (1);
15973 Check_Optional_Identifier (Arg1, Name_On);
15974 Check_Arg_Is_Local_Name (Arg1);
15975
15976 E_Id := Get_Pragma_Arg (Arg1);
15977
15978 if Etype (E_Id) = Any_Type then
15979 return;
15980 end if;
15981
15982 E := Entity (E_Id);
15983
15984 -- A pragma that applies to a Ghost entity becomes Ghost for
15985 -- the purposes of legality checks and removal of ignored
15986 -- Ghost code.
15987
15988 Mark_Ghost_Pragma (N, E);
15989
15990 if (Is_First_Subtype (E)
15991 and then
15992 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
15993 or else Ekind (E) = E_Exception
15994 then
15995 Set_Discard_Names (E);
15996 Record_Rep_Item (E, N);
15997
15998 else
15999 Error_Pragma_Arg
16000 ("inappropriate entity for pragma%", Arg1);
16001 end if;
16002 end if;
16003 end if;
16004 end Discard_Names;
16005
16006 ------------------------
16007 -- Dispatching_Domain --
16008 ------------------------
16009
16010 -- pragma Dispatching_Domain (EXPRESSION);
16011
16012 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
16013 P : constant Node_Id := Parent (N);
16014 Arg : Node_Id;
16015 Ent : Entity_Id;
16016
16017 begin
16018 Ada_2012_Pragma;
16019 Check_No_Identifiers;
16020 Check_Arg_Count (1);
16021
16022 -- This pragma is born obsolete, but not the aspect
16023
16024 if not From_Aspect_Specification (N) then
16025 Check_Restriction
16026 (No_Obsolescent_Features, Pragma_Identifier (N));
16027 end if;
16028
16029 if Nkind (P) = N_Task_Definition then
16030 Arg := Get_Pragma_Arg (Arg1);
16031 Ent := Defining_Identifier (Parent (P));
16032
16033 -- A pragma that applies to a Ghost entity becomes Ghost for
16034 -- the purposes of legality checks and removal of ignored Ghost
16035 -- code.
16036
16037 Mark_Ghost_Pragma (N, Ent);
16038
16039 -- The expression must be analyzed in the special manner
16040 -- described in "Handling of Default and Per-Object
16041 -- Expressions" in sem.ads.
16042
16043 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
16044
16045 -- Check duplicate pragma before we chain the pragma in the Rep
16046 -- Item chain of Ent.
16047
16048 Check_Duplicate_Pragma (Ent);
16049 Record_Rep_Item (Ent, N);
16050
16051 -- Anything else is incorrect
16052
16053 else
16054 Pragma_Misplaced;
16055 end if;
16056 end Dispatching_Domain;
16057
16058 ---------------
16059 -- Elaborate --
16060 ---------------
16061
16062 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
16063
16064 when Pragma_Elaborate => Elaborate : declare
16065 Arg : Node_Id;
16066 Citem : Node_Id;
16067
16068 begin
16069 -- Pragma must be in context items list of a compilation unit
16070
16071 if not Is_In_Context_Clause then
16072 Pragma_Misplaced;
16073 end if;
16074
16075 -- Must be at least one argument
16076
16077 if Arg_Count = 0 then
16078 Error_Pragma ("pragma% requires at least one argument");
16079 end if;
16080
16081 -- In Ada 83 mode, there can be no items following it in the
16082 -- context list except other pragmas and implicit with clauses
16083 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
16084 -- placement rule does not apply.
16085
16086 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
16087 Citem := Next (N);
16088 while Present (Citem) loop
16089 if Nkind (Citem) = N_Pragma
16090 or else (Nkind (Citem) = N_With_Clause
16091 and then Implicit_With (Citem))
16092 then
16093 null;
16094 else
16095 Error_Pragma
16096 ("(Ada 83) pragma% must be at end of context clause");
16097 end if;
16098
16099 Next (Citem);
16100 end loop;
16101 end if;
16102
16103 -- Finally, the arguments must all be units mentioned in a with
16104 -- clause in the same context clause. Note we already checked (in
16105 -- Par.Prag) that the arguments are all identifiers or selected
16106 -- components.
16107
16108 Arg := Arg1;
16109 Outer : while Present (Arg) loop
16110 Citem := First (List_Containing (N));
16111 Inner : while Citem /= N loop
16112 if Nkind (Citem) = N_With_Clause
16113 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
16114 then
16115 Set_Elaborate_Present (Citem, True);
16116 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
16117
16118 -- With the pragma present, elaboration calls on
16119 -- subprograms from the named unit need no further
16120 -- checks, as long as the pragma appears in the current
16121 -- compilation unit. If the pragma appears in some unit
16122 -- in the context, there might still be a need for an
16123 -- Elaborate_All_Desirable from the current compilation
16124 -- to the named unit, so we keep the check enabled. This
16125 -- does not apply in SPARK mode, where we allow pragma
16126 -- Elaborate, but we don't trust it to be right so we
16127 -- will still insist on the Elaborate_All.
16128
16129 if Legacy_Elaboration_Checks
16130 and then In_Extended_Main_Source_Unit (N)
16131 and then SPARK_Mode /= On
16132 then
16133 Set_Suppress_Elaboration_Warnings
16134 (Entity (Name (Citem)));
16135 end if;
16136
16137 exit Inner;
16138 end if;
16139
16140 Next (Citem);
16141 end loop Inner;
16142
16143 if Citem = N then
16144 Error_Pragma_Arg
16145 ("argument of pragma% is not withed unit", Arg);
16146 end if;
16147
16148 Next (Arg);
16149 end loop Outer;
16150 end Elaborate;
16151
16152 -------------------
16153 -- Elaborate_All --
16154 -------------------
16155
16156 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
16157
16158 when Pragma_Elaborate_All => Elaborate_All : declare
16159 Arg : Node_Id;
16160 Citem : Node_Id;
16161
16162 begin
16163 Check_Ada_83_Warning;
16164
16165 -- Pragma must be in context items list of a compilation unit
16166
16167 if not Is_In_Context_Clause then
16168 Pragma_Misplaced;
16169 end if;
16170
16171 -- Must be at least one argument
16172
16173 if Arg_Count = 0 then
16174 Error_Pragma ("pragma% requires at least one argument");
16175 end if;
16176
16177 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
16178 -- have to appear at the end of the context clause, but may
16179 -- appear mixed in with other items, even in Ada 83 mode.
16180
16181 -- Final check: the arguments must all be units mentioned in
16182 -- a with clause in the same context clause. Note that we
16183 -- already checked (in Par.Prag) that all the arguments are
16184 -- either identifiers or selected components.
16185
16186 Arg := Arg1;
16187 Outr : while Present (Arg) loop
16188 Citem := First (List_Containing (N));
16189 Innr : while Citem /= N loop
16190 if Nkind (Citem) = N_With_Clause
16191 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
16192 then
16193 Set_Elaborate_All_Present (Citem, True);
16194 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
16195
16196 -- Suppress warnings and elaboration checks on the named
16197 -- unit if the pragma is in the current compilation, as
16198 -- for pragma Elaborate.
16199
16200 if Legacy_Elaboration_Checks
16201 and then In_Extended_Main_Source_Unit (N)
16202 then
16203 Set_Suppress_Elaboration_Warnings
16204 (Entity (Name (Citem)));
16205 end if;
16206
16207 exit Innr;
16208 end if;
16209
16210 Next (Citem);
16211 end loop Innr;
16212
16213 if Citem = N then
16214 Set_Error_Posted (N);
16215 Error_Pragma_Arg
16216 ("argument of pragma% is not withed unit", Arg);
16217 end if;
16218
16219 Next (Arg);
16220 end loop Outr;
16221 end Elaborate_All;
16222
16223 --------------------
16224 -- Elaborate_Body --
16225 --------------------
16226
16227 -- pragma Elaborate_Body [( library_unit_NAME )];
16228
16229 when Pragma_Elaborate_Body => Elaborate_Body : declare
16230 Cunit_Node : Node_Id;
16231 Cunit_Ent : Entity_Id;
16232
16233 begin
16234 Check_Ada_83_Warning;
16235 Check_Valid_Library_Unit_Pragma;
16236
16237 if Nkind (N) = N_Null_Statement then
16238 return;
16239 end if;
16240
16241 Cunit_Node := Cunit (Current_Sem_Unit);
16242 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
16243
16244 -- A pragma that applies to a Ghost entity becomes Ghost for the
16245 -- purposes of legality checks and removal of ignored Ghost code.
16246
16247 Mark_Ghost_Pragma (N, Cunit_Ent);
16248
16249 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
16250 N_Subprogram_Body)
16251 then
16252 Error_Pragma ("pragma% must refer to a spec, not a body");
16253 else
16254 Set_Body_Required (Cunit_Node);
16255 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
16256
16257 -- If we are in dynamic elaboration mode, then we suppress
16258 -- elaboration warnings for the unit, since it is definitely
16259 -- fine NOT to do dynamic checks at the first level (and such
16260 -- checks will be suppressed because no elaboration boolean
16261 -- is created for Elaborate_Body packages).
16262 --
16263 -- But in the static model of elaboration, Elaborate_Body is
16264 -- definitely NOT good enough to ensure elaboration safety on
16265 -- its own, since the body may WITH other units that are not
16266 -- safe from an elaboration point of view, so a client must
16267 -- still do an Elaborate_All on such units.
16268 --
16269 -- Debug flag -gnatdD restores the old behavior of 3.13, where
16270 -- Elaborate_Body always suppressed elab warnings.
16271
16272 if Legacy_Elaboration_Checks
16273 and then (Dynamic_Elaboration_Checks or Debug_Flag_DD)
16274 then
16275 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
16276 end if;
16277 end if;
16278 end Elaborate_Body;
16279
16280 ------------------------
16281 -- Elaboration_Checks --
16282 ------------------------
16283
16284 -- pragma Elaboration_Checks (Static | Dynamic);
16285
16286 when Pragma_Elaboration_Checks => Elaboration_Checks : declare
16287 procedure Check_Duplicate_Elaboration_Checks_Pragma;
16288 -- Emit an error if the current context list already contains
16289 -- a previous Elaboration_Checks pragma. This routine raises
16290 -- Pragma_Exit if a duplicate is found.
16291
16292 procedure Ignore_Elaboration_Checks_Pragma;
16293 -- Warn that the effects of the pragma are ignored. This routine
16294 -- raises Pragma_Exit.
16295
16296 -----------------------------------------------
16297 -- Check_Duplicate_Elaboration_Checks_Pragma --
16298 -----------------------------------------------
16299
16300 procedure Check_Duplicate_Elaboration_Checks_Pragma is
16301 Item : Node_Id;
16302
16303 begin
16304 Item := Prev (N);
16305 while Present (Item) loop
16306 if Nkind (Item) = N_Pragma
16307 and then Pragma_Name (Item) = Name_Elaboration_Checks
16308 then
16309 Duplication_Error
16310 (Prag => N,
16311 Prev => Item);
16312 raise Pragma_Exit;
16313 end if;
16314
16315 Prev (Item);
16316 end loop;
16317 end Check_Duplicate_Elaboration_Checks_Pragma;
16318
16319 --------------------------------------
16320 -- Ignore_Elaboration_Checks_Pragma --
16321 --------------------------------------
16322
16323 procedure Ignore_Elaboration_Checks_Pragma is
16324 begin
16325 Error_Msg_Name_1 := Pname;
16326 Error_Msg_N ("??effects of pragma % are ignored", N);
16327 Error_Msg_N
16328 ("\place pragma on initial declaration of library unit", N);
16329
16330 raise Pragma_Exit;
16331 end Ignore_Elaboration_Checks_Pragma;
16332
16333 -- Local variables
16334
16335 Context : constant Node_Id := Parent (N);
16336 Unt : Node_Id;
16337
16338 -- Start of processing for Elaboration_Checks
16339
16340 begin
16341 GNAT_Pragma;
16342 Check_Arg_Count (1);
16343 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
16344
16345 -- The pragma appears in a configuration file
16346
16347 if No (Context) then
16348 Check_Valid_Configuration_Pragma;
16349 Check_Duplicate_Elaboration_Checks_Pragma;
16350
16351 -- The pragma acts as a configuration pragma in a compilation unit
16352
16353 -- pragma Elaboration_Checks (...);
16354 -- package Pack is ...;
16355
16356 elsif Nkind (Context) = N_Compilation_Unit
16357 and then List_Containing (N) = Context_Items (Context)
16358 then
16359 Check_Valid_Configuration_Pragma;
16360 Check_Duplicate_Elaboration_Checks_Pragma;
16361
16362 Unt := Unit (Context);
16363
16364 -- The pragma must appear on the initial declaration of a unit.
16365 -- If this is not the case, warn that the effects of the pragma
16366 -- are ignored.
16367
16368 if Nkind (Unt) = N_Package_Body then
16369 Ignore_Elaboration_Checks_Pragma;
16370
16371 -- Check the Acts_As_Spec flag of the compilation units itself
16372 -- to determine whether the subprogram body completes since it
16373 -- has not been analyzed yet. This is safe because compilation
16374 -- units are not overloadable.
16375
16376 elsif Nkind (Unt) = N_Subprogram_Body
16377 and then not Acts_As_Spec (Context)
16378 then
16379 Ignore_Elaboration_Checks_Pragma;
16380
16381 elsif Nkind (Unt) = N_Subunit then
16382 Ignore_Elaboration_Checks_Pragma;
16383 end if;
16384
16385 -- Otherwise the pragma does not appear at the configuration level
16386 -- and is illegal.
16387
16388 else
16389 Pragma_Misplaced;
16390 end if;
16391
16392 -- At this point the pragma is not a duplicate, and appears in the
16393 -- proper context. Set the elaboration model in effect.
16394
16395 Dynamic_Elaboration_Checks :=
16396 Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic;
16397 end Elaboration_Checks;
16398
16399 ---------------
16400 -- Eliminate --
16401 ---------------
16402
16403 -- pragma Eliminate (
16404 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
16405 -- [Entity =>] IDENTIFIER |
16406 -- SELECTED_COMPONENT |
16407 -- STRING_LITERAL]
16408 -- [, Source_Location => SOURCE_TRACE]);
16409
16410 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
16411 -- SOURCE_TRACE ::= STRING_LITERAL
16412
16413 when Pragma_Eliminate => Eliminate : declare
16414 Args : Args_List (1 .. 5);
16415 Names : constant Name_List (1 .. 5) := (
16416 Name_Unit_Name,
16417 Name_Entity,
16418 Name_Parameter_Types,
16419 Name_Result_Type,
16420 Name_Source_Location);
16421
16422 -- Note : Parameter_Types and Result_Type are leftovers from
16423 -- prior implementations of the pragma. They are not generated
16424 -- by the gnatelim tool, and play no role in selecting which
16425 -- of a set of overloaded names is chosen for elimination.
16426
16427 Unit_Name : Node_Id renames Args (1);
16428 Entity : Node_Id renames Args (2);
16429 Parameter_Types : Node_Id renames Args (3);
16430 Result_Type : Node_Id renames Args (4);
16431 Source_Location : Node_Id renames Args (5);
16432
16433 begin
16434 GNAT_Pragma;
16435 Check_Valid_Configuration_Pragma;
16436 Gather_Associations (Names, Args);
16437
16438 if No (Unit_Name) then
16439 Error_Pragma ("missing Unit_Name argument for pragma%");
16440 end if;
16441
16442 if No (Entity)
16443 and then (Present (Parameter_Types)
16444 or else
16445 Present (Result_Type)
16446 or else
16447 Present (Source_Location))
16448 then
16449 Error_Pragma ("missing Entity argument for pragma%");
16450 end if;
16451
16452 if (Present (Parameter_Types)
16453 or else
16454 Present (Result_Type))
16455 and then
16456 Present (Source_Location)
16457 then
16458 Error_Pragma
16459 ("parameter profile and source location cannot be used "
16460 & "together in pragma%");
16461 end if;
16462
16463 Process_Eliminate_Pragma
16464 (N,
16465 Unit_Name,
16466 Entity,
16467 Parameter_Types,
16468 Result_Type,
16469 Source_Location);
16470 end Eliminate;
16471
16472 -----------------------------------
16473 -- Enable_Atomic_Synchronization --
16474 -----------------------------------
16475
16476 -- pragma Enable_Atomic_Synchronization [(Entity)];
16477
16478 when Pragma_Enable_Atomic_Synchronization =>
16479 GNAT_Pragma;
16480 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
16481
16482 ------------
16483 -- Export --
16484 ------------
16485
16486 -- pragma Export (
16487 -- [ Convention =>] convention_IDENTIFIER,
16488 -- [ Entity =>] LOCAL_NAME
16489 -- [, [External_Name =>] static_string_EXPRESSION ]
16490 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16491
16492 when Pragma_Export => Export : declare
16493 C : Convention_Id;
16494 Def_Id : Entity_Id;
16495
16496 pragma Warnings (Off, C);
16497
16498 begin
16499 Check_Ada_83_Warning;
16500 Check_Arg_Order
16501 ((Name_Convention,
16502 Name_Entity,
16503 Name_External_Name,
16504 Name_Link_Name));
16505
16506 Check_At_Least_N_Arguments (2);
16507 Check_At_Most_N_Arguments (4);
16508
16509 -- In Relaxed_RM_Semantics, support old Ada 83 style:
16510 -- pragma Export (Entity, "external name");
16511
16512 if Relaxed_RM_Semantics
16513 and then Arg_Count = 2
16514 and then Nkind (Expression (Arg2)) = N_String_Literal
16515 then
16516 C := Convention_C;
16517 Def_Id := Get_Pragma_Arg (Arg1);
16518 Analyze (Def_Id);
16519
16520 if not Is_Entity_Name (Def_Id) then
16521 Error_Pragma_Arg ("entity name required", Arg1);
16522 end if;
16523
16524 Def_Id := Entity (Def_Id);
16525 Set_Exported (Def_Id, Arg1);
16526
16527 else
16528 Process_Convention (C, Def_Id);
16529
16530 -- A pragma that applies to a Ghost entity becomes Ghost for
16531 -- the purposes of legality checks and removal of ignored Ghost
16532 -- code.
16533
16534 Mark_Ghost_Pragma (N, Def_Id);
16535
16536 if Ekind (Def_Id) /= E_Constant then
16537 Note_Possible_Modification
16538 (Get_Pragma_Arg (Arg2), Sure => False);
16539 end if;
16540
16541 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
16542 Set_Exported (Def_Id, Arg2);
16543 end if;
16544
16545 -- If the entity is a deferred constant, propagate the information
16546 -- to the full view, because gigi elaborates the full view only.
16547
16548 if Ekind (Def_Id) = E_Constant
16549 and then Present (Full_View (Def_Id))
16550 then
16551 declare
16552 Id2 : constant Entity_Id := Full_View (Def_Id);
16553 begin
16554 Set_Is_Exported (Id2, Is_Exported (Def_Id));
16555 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
16556 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
16557 end;
16558 end if;
16559 end Export;
16560
16561 ---------------------
16562 -- Export_Function --
16563 ---------------------
16564
16565 -- pragma Export_Function (
16566 -- [Internal =>] LOCAL_NAME
16567 -- [, [External =>] EXTERNAL_SYMBOL]
16568 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16569 -- [, [Result_Type =>] TYPE_DESIGNATOR]
16570 -- [, [Mechanism =>] MECHANISM]
16571 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
16572
16573 -- EXTERNAL_SYMBOL ::=
16574 -- IDENTIFIER
16575 -- | static_string_EXPRESSION
16576
16577 -- PARAMETER_TYPES ::=
16578 -- null
16579 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16580
16581 -- TYPE_DESIGNATOR ::=
16582 -- subtype_NAME
16583 -- | subtype_Name ' Access
16584
16585 -- MECHANISM ::=
16586 -- MECHANISM_NAME
16587 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16588
16589 -- MECHANISM_ASSOCIATION ::=
16590 -- [formal_parameter_NAME =>] MECHANISM_NAME
16591
16592 -- MECHANISM_NAME ::=
16593 -- Value
16594 -- | Reference
16595
16596 when Pragma_Export_Function => Export_Function : declare
16597 Args : Args_List (1 .. 6);
16598 Names : constant Name_List (1 .. 6) := (
16599 Name_Internal,
16600 Name_External,
16601 Name_Parameter_Types,
16602 Name_Result_Type,
16603 Name_Mechanism,
16604 Name_Result_Mechanism);
16605
16606 Internal : Node_Id renames Args (1);
16607 External : Node_Id renames Args (2);
16608 Parameter_Types : Node_Id renames Args (3);
16609 Result_Type : Node_Id renames Args (4);
16610 Mechanism : Node_Id renames Args (5);
16611 Result_Mechanism : Node_Id renames Args (6);
16612
16613 begin
16614 GNAT_Pragma;
16615 Gather_Associations (Names, Args);
16616 Process_Extended_Import_Export_Subprogram_Pragma (
16617 Arg_Internal => Internal,
16618 Arg_External => External,
16619 Arg_Parameter_Types => Parameter_Types,
16620 Arg_Result_Type => Result_Type,
16621 Arg_Mechanism => Mechanism,
16622 Arg_Result_Mechanism => Result_Mechanism);
16623 end Export_Function;
16624
16625 -------------------
16626 -- Export_Object --
16627 -------------------
16628
16629 -- pragma Export_Object (
16630 -- [Internal =>] LOCAL_NAME
16631 -- [, [External =>] EXTERNAL_SYMBOL]
16632 -- [, [Size =>] EXTERNAL_SYMBOL]);
16633
16634 -- EXTERNAL_SYMBOL ::=
16635 -- IDENTIFIER
16636 -- | static_string_EXPRESSION
16637
16638 -- PARAMETER_TYPES ::=
16639 -- null
16640 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16641
16642 -- TYPE_DESIGNATOR ::=
16643 -- subtype_NAME
16644 -- | subtype_Name ' Access
16645
16646 -- MECHANISM ::=
16647 -- MECHANISM_NAME
16648 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16649
16650 -- MECHANISM_ASSOCIATION ::=
16651 -- [formal_parameter_NAME =>] MECHANISM_NAME
16652
16653 -- MECHANISM_NAME ::=
16654 -- Value
16655 -- | Reference
16656
16657 when Pragma_Export_Object => Export_Object : declare
16658 Args : Args_List (1 .. 3);
16659 Names : constant Name_List (1 .. 3) := (
16660 Name_Internal,
16661 Name_External,
16662 Name_Size);
16663
16664 Internal : Node_Id renames Args (1);
16665 External : Node_Id renames Args (2);
16666 Size : Node_Id renames Args (3);
16667
16668 begin
16669 GNAT_Pragma;
16670 Gather_Associations (Names, Args);
16671 Process_Extended_Import_Export_Object_Pragma (
16672 Arg_Internal => Internal,
16673 Arg_External => External,
16674 Arg_Size => Size);
16675 end Export_Object;
16676
16677 ----------------------
16678 -- Export_Procedure --
16679 ----------------------
16680
16681 -- pragma Export_Procedure (
16682 -- [Internal =>] LOCAL_NAME
16683 -- [, [External =>] EXTERNAL_SYMBOL]
16684 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16685 -- [, [Mechanism =>] MECHANISM]);
16686
16687 -- EXTERNAL_SYMBOL ::=
16688 -- IDENTIFIER
16689 -- | static_string_EXPRESSION
16690
16691 -- PARAMETER_TYPES ::=
16692 -- null
16693 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16694
16695 -- TYPE_DESIGNATOR ::=
16696 -- subtype_NAME
16697 -- | subtype_Name ' Access
16698
16699 -- MECHANISM ::=
16700 -- MECHANISM_NAME
16701 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16702
16703 -- MECHANISM_ASSOCIATION ::=
16704 -- [formal_parameter_NAME =>] MECHANISM_NAME
16705
16706 -- MECHANISM_NAME ::=
16707 -- Value
16708 -- | Reference
16709
16710 when Pragma_Export_Procedure => Export_Procedure : declare
16711 Args : Args_List (1 .. 4);
16712 Names : constant Name_List (1 .. 4) := (
16713 Name_Internal,
16714 Name_External,
16715 Name_Parameter_Types,
16716 Name_Mechanism);
16717
16718 Internal : Node_Id renames Args (1);
16719 External : Node_Id renames Args (2);
16720 Parameter_Types : Node_Id renames Args (3);
16721 Mechanism : Node_Id renames Args (4);
16722
16723 begin
16724 GNAT_Pragma;
16725 Gather_Associations (Names, Args);
16726 Process_Extended_Import_Export_Subprogram_Pragma (
16727 Arg_Internal => Internal,
16728 Arg_External => External,
16729 Arg_Parameter_Types => Parameter_Types,
16730 Arg_Mechanism => Mechanism);
16731 end Export_Procedure;
16732
16733 ------------------
16734 -- Export_Value --
16735 ------------------
16736
16737 -- pragma Export_Value (
16738 -- [Value =>] static_integer_EXPRESSION,
16739 -- [Link_Name =>] static_string_EXPRESSION);
16740
16741 when Pragma_Export_Value =>
16742 GNAT_Pragma;
16743 Check_Arg_Order ((Name_Value, Name_Link_Name));
16744 Check_Arg_Count (2);
16745
16746 Check_Optional_Identifier (Arg1, Name_Value);
16747 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
16748
16749 Check_Optional_Identifier (Arg2, Name_Link_Name);
16750 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16751
16752 -----------------------------
16753 -- Export_Valued_Procedure --
16754 -----------------------------
16755
16756 -- pragma Export_Valued_Procedure (
16757 -- [Internal =>] LOCAL_NAME
16758 -- [, [External =>] EXTERNAL_SYMBOL,]
16759 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16760 -- [, [Mechanism =>] MECHANISM]);
16761
16762 -- EXTERNAL_SYMBOL ::=
16763 -- IDENTIFIER
16764 -- | static_string_EXPRESSION
16765
16766 -- PARAMETER_TYPES ::=
16767 -- null
16768 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16769
16770 -- TYPE_DESIGNATOR ::=
16771 -- subtype_NAME
16772 -- | subtype_Name ' Access
16773
16774 -- MECHANISM ::=
16775 -- MECHANISM_NAME
16776 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16777
16778 -- MECHANISM_ASSOCIATION ::=
16779 -- [formal_parameter_NAME =>] MECHANISM_NAME
16780
16781 -- MECHANISM_NAME ::=
16782 -- Value
16783 -- | Reference
16784
16785 when Pragma_Export_Valued_Procedure =>
16786 Export_Valued_Procedure : declare
16787 Args : Args_List (1 .. 4);
16788 Names : constant Name_List (1 .. 4) := (
16789 Name_Internal,
16790 Name_External,
16791 Name_Parameter_Types,
16792 Name_Mechanism);
16793
16794 Internal : Node_Id renames Args (1);
16795 External : Node_Id renames Args (2);
16796 Parameter_Types : Node_Id renames Args (3);
16797 Mechanism : Node_Id renames Args (4);
16798
16799 begin
16800 GNAT_Pragma;
16801 Gather_Associations (Names, Args);
16802 Process_Extended_Import_Export_Subprogram_Pragma (
16803 Arg_Internal => Internal,
16804 Arg_External => External,
16805 Arg_Parameter_Types => Parameter_Types,
16806 Arg_Mechanism => Mechanism);
16807 end Export_Valued_Procedure;
16808
16809 -------------------
16810 -- Extend_System --
16811 -------------------
16812
16813 -- pragma Extend_System ([Name =>] Identifier);
16814
16815 when Pragma_Extend_System =>
16816 GNAT_Pragma;
16817 Check_Valid_Configuration_Pragma;
16818 Check_Arg_Count (1);
16819 Check_Optional_Identifier (Arg1, Name_Name);
16820 Check_Arg_Is_Identifier (Arg1);
16821
16822 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16823
16824 if Name_Len > 4
16825 and then Name_Buffer (1 .. 4) = "aux_"
16826 then
16827 if Present (System_Extend_Pragma_Arg) then
16828 if Chars (Get_Pragma_Arg (Arg1)) =
16829 Chars (Expression (System_Extend_Pragma_Arg))
16830 then
16831 null;
16832 else
16833 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
16834 Error_Pragma ("pragma% conflicts with that #");
16835 end if;
16836
16837 else
16838 System_Extend_Pragma_Arg := Arg1;
16839
16840 if not GNAT_Mode then
16841 System_Extend_Unit := Arg1;
16842 end if;
16843 end if;
16844 else
16845 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
16846 end if;
16847
16848 ------------------------
16849 -- Extensions_Allowed --
16850 ------------------------
16851
16852 -- pragma Extensions_Allowed (ON | OFF);
16853
16854 when Pragma_Extensions_Allowed =>
16855 GNAT_Pragma;
16856 Check_Arg_Count (1);
16857 Check_No_Identifiers;
16858 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16859
16860 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
16861 Extensions_Allowed := True;
16862 Ada_Version := Ada_Version_Type'Last;
16863
16864 else
16865 Extensions_Allowed := False;
16866 Ada_Version := Ada_Version_Explicit;
16867 Ada_Version_Pragma := Empty;
16868 end if;
16869
16870 ------------------------
16871 -- Extensions_Visible --
16872 ------------------------
16873
16874 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
16875
16876 -- Characteristics:
16877
16878 -- * Analysis - The annotation is fully analyzed immediately upon
16879 -- elaboration as its expression must be static.
16880
16881 -- * Expansion - None.
16882
16883 -- * Template - The annotation utilizes the generic template of the
16884 -- related subprogram [body] when it is:
16885
16886 -- aspect on subprogram declaration
16887 -- aspect on stand-alone subprogram body
16888 -- pragma on stand-alone subprogram body
16889
16890 -- The annotation must prepare its own template when it is:
16891
16892 -- pragma on subprogram declaration
16893
16894 -- * Globals - Capture of global references must occur after full
16895 -- analysis.
16896
16897 -- * Instance - The annotation is instantiated automatically when
16898 -- the related generic subprogram [body] is instantiated except for
16899 -- the "pragma on subprogram declaration" case. In that scenario
16900 -- the annotation must instantiate itself.
16901
16902 when Pragma_Extensions_Visible => Extensions_Visible : declare
16903 Formal : Entity_Id;
16904 Has_OK_Formal : Boolean := False;
16905 Spec_Id : Entity_Id;
16906 Subp_Decl : Node_Id;
16907
16908 begin
16909 GNAT_Pragma;
16910 Check_No_Identifiers;
16911 Check_At_Most_N_Arguments (1);
16912
16913 Subp_Decl :=
16914 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
16915
16916 -- Abstract subprogram declaration
16917
16918 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
16919 null;
16920
16921 -- Generic subprogram declaration
16922
16923 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
16924 null;
16925
16926 -- Body acts as spec
16927
16928 elsif Nkind (Subp_Decl) = N_Subprogram_Body
16929 and then No (Corresponding_Spec (Subp_Decl))
16930 then
16931 null;
16932
16933 -- Body stub acts as spec
16934
16935 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
16936 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
16937 then
16938 null;
16939
16940 -- Subprogram declaration
16941
16942 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
16943 null;
16944
16945 -- Otherwise the pragma is associated with an illegal construct
16946
16947 else
16948 Error_Pragma ("pragma % must apply to a subprogram");
16949 return;
16950 end if;
16951
16952 -- Mark the pragma as Ghost if the related subprogram is also
16953 -- Ghost. This also ensures that any expansion performed further
16954 -- below will produce Ghost nodes.
16955
16956 Spec_Id := Unique_Defining_Entity (Subp_Decl);
16957 Mark_Ghost_Pragma (N, Spec_Id);
16958
16959 -- Chain the pragma on the contract for completeness
16960
16961 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
16962
16963 -- The legality checks of pragma Extension_Visible are affected
16964 -- by the SPARK mode in effect. Analyze all pragmas in specific
16965 -- order.
16966
16967 Analyze_If_Present (Pragma_SPARK_Mode);
16968
16969 -- Examine the formals of the related subprogram
16970
16971 Formal := First_Formal (Spec_Id);
16972 while Present (Formal) loop
16973
16974 -- At least one of the formals is of a specific tagged type,
16975 -- the pragma is legal.
16976
16977 if Is_Specific_Tagged_Type (Etype (Formal)) then
16978 Has_OK_Formal := True;
16979 exit;
16980
16981 -- A generic subprogram with at least one formal of a private
16982 -- type ensures the legality of the pragma because the actual
16983 -- may be specifically tagged. Note that this is verified by
16984 -- the check above at instantiation time.
16985
16986 elsif Is_Private_Type (Etype (Formal))
16987 and then Is_Generic_Type (Etype (Formal))
16988 then
16989 Has_OK_Formal := True;
16990 exit;
16991 end if;
16992
16993 Next_Formal (Formal);
16994 end loop;
16995
16996 if not Has_OK_Formal then
16997 Error_Msg_Name_1 := Pname;
16998 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
16999 Error_Msg_NE
17000 ("\subprogram & lacks parameter of specific tagged or "
17001 & "generic private type", N, Spec_Id);
17002
17003 return;
17004 end if;
17005
17006 -- Analyze the Boolean expression (if any)
17007
17008 if Present (Arg1) then
17009 Check_Static_Boolean_Expression
17010 (Expression (Get_Argument (N, Spec_Id)));
17011 end if;
17012 end Extensions_Visible;
17013
17014 --------------
17015 -- External --
17016 --------------
17017
17018 -- pragma External (
17019 -- [ Convention =>] convention_IDENTIFIER,
17020 -- [ Entity =>] LOCAL_NAME
17021 -- [, [External_Name =>] static_string_EXPRESSION ]
17022 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17023
17024 when Pragma_External => External : declare
17025 C : Convention_Id;
17026 E : Entity_Id;
17027 pragma Warnings (Off, C);
17028
17029 begin
17030 GNAT_Pragma;
17031 Check_Arg_Order
17032 ((Name_Convention,
17033 Name_Entity,
17034 Name_External_Name,
17035 Name_Link_Name));
17036 Check_At_Least_N_Arguments (2);
17037 Check_At_Most_N_Arguments (4);
17038 Process_Convention (C, E);
17039
17040 -- A pragma that applies to a Ghost entity becomes Ghost for the
17041 -- purposes of legality checks and removal of ignored Ghost code.
17042
17043 Mark_Ghost_Pragma (N, E);
17044
17045 Note_Possible_Modification
17046 (Get_Pragma_Arg (Arg2), Sure => False);
17047 Process_Interface_Name (E, Arg3, Arg4, N);
17048 Set_Exported (E, Arg2);
17049 end External;
17050
17051 --------------------------
17052 -- External_Name_Casing --
17053 --------------------------
17054
17055 -- pragma External_Name_Casing (
17056 -- UPPERCASE | LOWERCASE
17057 -- [, AS_IS | UPPERCASE | LOWERCASE]);
17058
17059 when Pragma_External_Name_Casing =>
17060 GNAT_Pragma;
17061 Check_No_Identifiers;
17062
17063 if Arg_Count = 2 then
17064 Check_Arg_Is_One_Of
17065 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
17066
17067 case Chars (Get_Pragma_Arg (Arg2)) is
17068 when Name_As_Is =>
17069 Opt.External_Name_Exp_Casing := As_Is;
17070
17071 when Name_Uppercase =>
17072 Opt.External_Name_Exp_Casing := Uppercase;
17073
17074 when Name_Lowercase =>
17075 Opt.External_Name_Exp_Casing := Lowercase;
17076
17077 when others =>
17078 null;
17079 end case;
17080
17081 else
17082 Check_Arg_Count (1);
17083 end if;
17084
17085 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
17086
17087 case Chars (Get_Pragma_Arg (Arg1)) is
17088 when Name_Uppercase =>
17089 Opt.External_Name_Imp_Casing := Uppercase;
17090
17091 when Name_Lowercase =>
17092 Opt.External_Name_Imp_Casing := Lowercase;
17093
17094 when others =>
17095 null;
17096 end case;
17097
17098 ---------------
17099 -- Fast_Math --
17100 ---------------
17101
17102 -- pragma Fast_Math;
17103
17104 when Pragma_Fast_Math =>
17105 GNAT_Pragma;
17106 Check_No_Identifiers;
17107 Check_Valid_Configuration_Pragma;
17108 Fast_Math := True;
17109
17110 --------------------------
17111 -- Favor_Top_Level --
17112 --------------------------
17113
17114 -- pragma Favor_Top_Level (type_NAME);
17115
17116 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
17117 Typ : Entity_Id;
17118
17119 begin
17120 GNAT_Pragma;
17121 Check_No_Identifiers;
17122 Check_Arg_Count (1);
17123 Check_Arg_Is_Local_Name (Arg1);
17124 Typ := Entity (Get_Pragma_Arg (Arg1));
17125
17126 -- A pragma that applies to a Ghost entity becomes Ghost for the
17127 -- purposes of legality checks and removal of ignored Ghost code.
17128
17129 Mark_Ghost_Pragma (N, Typ);
17130
17131 -- If it's an access-to-subprogram type (in particular, not a
17132 -- subtype), set the flag on that type.
17133
17134 if Is_Access_Subprogram_Type (Typ) then
17135 Set_Can_Use_Internal_Rep (Typ, False);
17136
17137 -- Otherwise it's an error (name denotes the wrong sort of entity)
17138
17139 else
17140 Error_Pragma_Arg
17141 ("access-to-subprogram type expected",
17142 Get_Pragma_Arg (Arg1));
17143 end if;
17144 end Favor_Top_Level;
17145
17146 ---------------------------
17147 -- Finalize_Storage_Only --
17148 ---------------------------
17149
17150 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
17151
17152 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
17153 Assoc : constant Node_Id := Arg1;
17154 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
17155 Typ : Entity_Id;
17156
17157 begin
17158 GNAT_Pragma;
17159 Check_No_Identifiers;
17160 Check_Arg_Count (1);
17161 Check_Arg_Is_Local_Name (Arg1);
17162
17163 Find_Type (Type_Id);
17164 Typ := Entity (Type_Id);
17165
17166 if Typ = Any_Type
17167 or else Rep_Item_Too_Early (Typ, N)
17168 then
17169 return;
17170 else
17171 Typ := Underlying_Type (Typ);
17172 end if;
17173
17174 if not Is_Controlled (Typ) then
17175 Error_Pragma ("pragma% must specify controlled type");
17176 end if;
17177
17178 Check_First_Subtype (Arg1);
17179
17180 if Finalize_Storage_Only (Typ) then
17181 Error_Pragma ("duplicate pragma%, only one allowed");
17182
17183 elsif not Rep_Item_Too_Late (Typ, N) then
17184 Set_Finalize_Storage_Only (Base_Type (Typ), True);
17185 end if;
17186 end Finalize_Storage;
17187
17188 -----------
17189 -- Ghost --
17190 -----------
17191
17192 -- pragma Ghost [ (boolean_EXPRESSION) ];
17193
17194 when Pragma_Ghost => Ghost : declare
17195 Context : Node_Id;
17196 Expr : Node_Id;
17197 Id : Entity_Id;
17198 Orig_Stmt : Node_Id;
17199 Prev_Id : Entity_Id;
17200 Stmt : Node_Id;
17201
17202 begin
17203 GNAT_Pragma;
17204 Check_No_Identifiers;
17205 Check_At_Most_N_Arguments (1);
17206
17207 Id := Empty;
17208 Stmt := Prev (N);
17209 while Present (Stmt) loop
17210
17211 -- Skip prior pragmas, but check for duplicates
17212
17213 if Nkind (Stmt) = N_Pragma then
17214 if Pragma_Name (Stmt) = Pname then
17215 Duplication_Error
17216 (Prag => N,
17217 Prev => Stmt);
17218 raise Pragma_Exit;
17219 end if;
17220
17221 -- Task unit declared without a definition cannot be subject to
17222 -- pragma Ghost (SPARK RM 6.9(19)).
17223
17224 elsif Nkind_In (Stmt, N_Single_Task_Declaration,
17225 N_Task_Type_Declaration)
17226 then
17227 Error_Pragma ("pragma % cannot apply to a task type");
17228 return;
17229
17230 -- Skip internally generated code
17231
17232 elsif not Comes_From_Source (Stmt) then
17233 Orig_Stmt := Original_Node (Stmt);
17234
17235 -- When pragma Ghost applies to an untagged derivation, the
17236 -- derivation is transformed into a [sub]type declaration.
17237
17238 if Nkind_In (Stmt, N_Full_Type_Declaration,
17239 N_Subtype_Declaration)
17240 and then Comes_From_Source (Orig_Stmt)
17241 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
17242 and then Nkind (Type_Definition (Orig_Stmt)) =
17243 N_Derived_Type_Definition
17244 then
17245 Id := Defining_Entity (Stmt);
17246 exit;
17247
17248 -- When pragma Ghost applies to an object declaration which
17249 -- is initialized by means of a function call that returns
17250 -- on the secondary stack, the object declaration becomes a
17251 -- renaming.
17252
17253 elsif Nkind (Stmt) = N_Object_Renaming_Declaration
17254 and then Comes_From_Source (Orig_Stmt)
17255 and then Nkind (Orig_Stmt) = N_Object_Declaration
17256 then
17257 Id := Defining_Entity (Stmt);
17258 exit;
17259
17260 -- When pragma Ghost applies to an expression function, the
17261 -- expression function is transformed into a subprogram.
17262
17263 elsif Nkind (Stmt) = N_Subprogram_Declaration
17264 and then Comes_From_Source (Orig_Stmt)
17265 and then Nkind (Orig_Stmt) = N_Expression_Function
17266 then
17267 Id := Defining_Entity (Stmt);
17268 exit;
17269 end if;
17270
17271 -- The pragma applies to a legal construct, stop the traversal
17272
17273 elsif Nkind_In (Stmt, N_Abstract_Subprogram_Declaration,
17274 N_Full_Type_Declaration,
17275 N_Generic_Subprogram_Declaration,
17276 N_Object_Declaration,
17277 N_Private_Extension_Declaration,
17278 N_Private_Type_Declaration,
17279 N_Subprogram_Declaration,
17280 N_Subtype_Declaration)
17281 then
17282 Id := Defining_Entity (Stmt);
17283 exit;
17284
17285 -- The pragma does not apply to a legal construct, issue an
17286 -- error and stop the analysis.
17287
17288 else
17289 Error_Pragma
17290 ("pragma % must apply to an object, package, subprogram "
17291 & "or type");
17292 return;
17293 end if;
17294
17295 Stmt := Prev (Stmt);
17296 end loop;
17297
17298 Context := Parent (N);
17299
17300 -- Handle compilation units
17301
17302 if Nkind (Context) = N_Compilation_Unit_Aux then
17303 Context := Unit (Parent (Context));
17304 end if;
17305
17306 -- Protected and task types cannot be subject to pragma Ghost
17307 -- (SPARK RM 6.9(19)).
17308
17309 if Nkind_In (Context, N_Protected_Body, N_Protected_Definition)
17310 then
17311 Error_Pragma ("pragma % cannot apply to a protected type");
17312 return;
17313
17314 elsif Nkind_In (Context, N_Task_Body, N_Task_Definition) then
17315 Error_Pragma ("pragma % cannot apply to a task type");
17316 return;
17317 end if;
17318
17319 if No (Id) then
17320
17321 -- When pragma Ghost is associated with a [generic] package, it
17322 -- appears in the visible declarations.
17323
17324 if Nkind (Context) = N_Package_Specification
17325 and then Present (Visible_Declarations (Context))
17326 and then List_Containing (N) = Visible_Declarations (Context)
17327 then
17328 Id := Defining_Entity (Context);
17329
17330 -- Pragma Ghost applies to a stand-alone subprogram body
17331
17332 elsif Nkind (Context) = N_Subprogram_Body
17333 and then No (Corresponding_Spec (Context))
17334 then
17335 Id := Defining_Entity (Context);
17336
17337 -- Pragma Ghost applies to a subprogram declaration that acts
17338 -- as a compilation unit.
17339
17340 elsif Nkind (Context) = N_Subprogram_Declaration then
17341 Id := Defining_Entity (Context);
17342
17343 -- Pragma Ghost applies to a generic subprogram
17344
17345 elsif Nkind (Context) = N_Generic_Subprogram_Declaration then
17346 Id := Defining_Entity (Specification (Context));
17347 end if;
17348 end if;
17349
17350 if No (Id) then
17351 Error_Pragma
17352 ("pragma % must apply to an object, package, subprogram or "
17353 & "type");
17354 return;
17355 end if;
17356
17357 -- Handle completions of types and constants that are subject to
17358 -- pragma Ghost.
17359
17360 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
17361 Prev_Id := Incomplete_Or_Partial_View (Id);
17362
17363 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
17364 Error_Msg_Name_1 := Pname;
17365
17366 -- The full declaration of a deferred constant cannot be
17367 -- subject to pragma Ghost unless the deferred declaration
17368 -- is also Ghost (SPARK RM 6.9(9)).
17369
17370 if Ekind (Prev_Id) = E_Constant then
17371 Error_Msg_Name_1 := Pname;
17372 Error_Msg_NE (Fix_Error
17373 ("pragma % must apply to declaration of deferred "
17374 & "constant &"), N, Id);
17375 return;
17376
17377 -- Pragma Ghost may appear on the full view of an incomplete
17378 -- type because the incomplete declaration lacks aspects and
17379 -- cannot be subject to pragma Ghost.
17380
17381 elsif Ekind (Prev_Id) = E_Incomplete_Type then
17382 null;
17383
17384 -- The full declaration of a type cannot be subject to
17385 -- pragma Ghost unless the partial view is also Ghost
17386 -- (SPARK RM 6.9(9)).
17387
17388 else
17389 Error_Msg_NE (Fix_Error
17390 ("pragma % must apply to partial view of type &"),
17391 N, Id);
17392 return;
17393 end if;
17394 end if;
17395
17396 -- A synchronized object cannot be subject to pragma Ghost
17397 -- (SPARK RM 6.9(19)).
17398
17399 elsif Ekind (Id) = E_Variable then
17400 if Is_Protected_Type (Etype (Id)) then
17401 Error_Pragma ("pragma % cannot apply to a protected object");
17402 return;
17403
17404 elsif Is_Task_Type (Etype (Id)) then
17405 Error_Pragma ("pragma % cannot apply to a task object");
17406 return;
17407 end if;
17408 end if;
17409
17410 -- Analyze the Boolean expression (if any)
17411
17412 if Present (Arg1) then
17413 Expr := Get_Pragma_Arg (Arg1);
17414
17415 Analyze_And_Resolve (Expr, Standard_Boolean);
17416
17417 if Is_OK_Static_Expression (Expr) then
17418
17419 -- "Ghostness" cannot be turned off once enabled within a
17420 -- region (SPARK RM 6.9(6)).
17421
17422 if Is_False (Expr_Value (Expr))
17423 and then Ghost_Mode > None
17424 then
17425 Error_Pragma
17426 ("pragma % with value False cannot appear in enabled "
17427 & "ghost region");
17428 return;
17429 end if;
17430
17431 -- Otherwie the expression is not static
17432
17433 else
17434 Error_Pragma_Arg
17435 ("expression of pragma % must be static", Expr);
17436 return;
17437 end if;
17438 end if;
17439
17440 Set_Is_Ghost_Entity (Id);
17441 end Ghost;
17442
17443 ------------
17444 -- Global --
17445 ------------
17446
17447 -- pragma Global (GLOBAL_SPECIFICATION);
17448
17449 -- GLOBAL_SPECIFICATION ::=
17450 -- null
17451 -- | (GLOBAL_LIST)
17452 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
17453
17454 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
17455
17456 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
17457 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
17458 -- GLOBAL_ITEM ::= NAME
17459
17460 -- Characteristics:
17461
17462 -- * Analysis - The annotation undergoes initial checks to verify
17463 -- the legal placement and context. Secondary checks fully analyze
17464 -- the dependency clauses in:
17465
17466 -- Analyze_Global_In_Decl_Part
17467
17468 -- * Expansion - None.
17469
17470 -- * Template - The annotation utilizes the generic template of the
17471 -- related subprogram [body] when it is:
17472
17473 -- aspect on subprogram declaration
17474 -- aspect on stand-alone subprogram body
17475 -- pragma on stand-alone subprogram body
17476
17477 -- The annotation must prepare its own template when it is:
17478
17479 -- pragma on subprogram declaration
17480
17481 -- * Globals - Capture of global references must occur after full
17482 -- analysis.
17483
17484 -- * Instance - The annotation is instantiated automatically when
17485 -- the related generic subprogram [body] is instantiated except for
17486 -- the "pragma on subprogram declaration" case. In that scenario
17487 -- the annotation must instantiate itself.
17488
17489 when Pragma_Global => Global : declare
17490 Legal : Boolean;
17491 Spec_Id : Entity_Id;
17492 Subp_Decl : Node_Id;
17493
17494 begin
17495 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
17496
17497 if Legal then
17498
17499 -- Chain the pragma on the contract for further processing by
17500 -- Analyze_Global_In_Decl_Part.
17501
17502 Add_Contract_Item (N, Spec_Id);
17503
17504 -- Fully analyze the pragma when it appears inside an entry
17505 -- or subprogram body because it cannot benefit from forward
17506 -- references.
17507
17508 if Nkind_In (Subp_Decl, N_Entry_Body,
17509 N_Subprogram_Body,
17510 N_Subprogram_Body_Stub)
17511 then
17512 -- The legality checks of pragmas Depends and Global are
17513 -- affected by the SPARK mode in effect and the volatility
17514 -- of the context. In addition these two pragmas are subject
17515 -- to an inherent order:
17516
17517 -- 1) Global
17518 -- 2) Depends
17519
17520 -- Analyze all these pragmas in the order outlined above
17521
17522 Analyze_If_Present (Pragma_SPARK_Mode);
17523 Analyze_If_Present (Pragma_Volatile_Function);
17524 Analyze_Global_In_Decl_Part (N);
17525 Analyze_If_Present (Pragma_Depends);
17526 end if;
17527 end if;
17528 end Global;
17529
17530 -----------
17531 -- Ident --
17532 -----------
17533
17534 -- pragma Ident (static_string_EXPRESSION)
17535
17536 -- Note: pragma Comment shares this processing. Pragma Ident is
17537 -- identical in effect to pragma Commment.
17538
17539 when Pragma_Comment
17540 | Pragma_Ident
17541 =>
17542 Ident : declare
17543 Str : Node_Id;
17544
17545 begin
17546 GNAT_Pragma;
17547 Check_Arg_Count (1);
17548 Check_No_Identifiers;
17549 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17550 Store_Note (N);
17551
17552 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
17553
17554 declare
17555 CS : Node_Id;
17556 GP : Node_Id;
17557
17558 begin
17559 GP := Parent (Parent (N));
17560
17561 if Nkind_In (GP, N_Package_Declaration,
17562 N_Generic_Package_Declaration)
17563 then
17564 GP := Parent (GP);
17565 end if;
17566
17567 -- If we have a compilation unit, then record the ident value,
17568 -- checking for improper duplication.
17569
17570 if Nkind (GP) = N_Compilation_Unit then
17571 CS := Ident_String (Current_Sem_Unit);
17572
17573 if Present (CS) then
17574
17575 -- If we have multiple instances, concatenate them.
17576
17577 Start_String (Strval (CS));
17578 Store_String_Char (' ');
17579 Store_String_Chars (Strval (Str));
17580 Set_Strval (CS, End_String);
17581
17582 else
17583 Set_Ident_String (Current_Sem_Unit, Str);
17584 end if;
17585
17586 -- For subunits, we just ignore the Ident, since in GNAT these
17587 -- are not separate object files, and hence not separate units
17588 -- in the unit table.
17589
17590 elsif Nkind (GP) = N_Subunit then
17591 null;
17592 end if;
17593 end;
17594 end Ident;
17595
17596 -------------------
17597 -- Ignore_Pragma --
17598 -------------------
17599
17600 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
17601
17602 -- Entirely handled in the parser, nothing to do here
17603
17604 when Pragma_Ignore_Pragma =>
17605 null;
17606
17607 ----------------------------
17608 -- Implementation_Defined --
17609 ----------------------------
17610
17611 -- pragma Implementation_Defined (LOCAL_NAME);
17612
17613 -- Marks previously declared entity as implementation defined. For
17614 -- an overloaded entity, applies to the most recent homonym.
17615
17616 -- pragma Implementation_Defined;
17617
17618 -- The form with no arguments appears anywhere within a scope, most
17619 -- typically a package spec, and indicates that all entities that are
17620 -- defined within the package spec are Implementation_Defined.
17621
17622 when Pragma_Implementation_Defined => Implementation_Defined : declare
17623 Ent : Entity_Id;
17624
17625 begin
17626 GNAT_Pragma;
17627 Check_No_Identifiers;
17628
17629 -- Form with no arguments
17630
17631 if Arg_Count = 0 then
17632 Set_Is_Implementation_Defined (Current_Scope);
17633
17634 -- Form with one argument
17635
17636 else
17637 Check_Arg_Count (1);
17638 Check_Arg_Is_Local_Name (Arg1);
17639 Ent := Entity (Get_Pragma_Arg (Arg1));
17640 Set_Is_Implementation_Defined (Ent);
17641 end if;
17642 end Implementation_Defined;
17643
17644 -----------------
17645 -- Implemented --
17646 -----------------
17647
17648 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
17649
17650 -- IMPLEMENTATION_KIND ::=
17651 -- By_Entry | By_Protected_Procedure | By_Any | Optional
17652
17653 -- "By_Any" and "Optional" are treated as synonyms in order to
17654 -- support Ada 2012 aspect Synchronization.
17655
17656 when Pragma_Implemented => Implemented : declare
17657 Proc_Id : Entity_Id;
17658 Typ : Entity_Id;
17659
17660 begin
17661 Ada_2012_Pragma;
17662 Check_Arg_Count (2);
17663 Check_No_Identifiers;
17664 Check_Arg_Is_Identifier (Arg1);
17665 Check_Arg_Is_Local_Name (Arg1);
17666 Check_Arg_Is_One_Of (Arg2,
17667 Name_By_Any,
17668 Name_By_Entry,
17669 Name_By_Protected_Procedure,
17670 Name_Optional);
17671
17672 -- Extract the name of the local procedure
17673
17674 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
17675
17676 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
17677 -- primitive procedure of a synchronized tagged type.
17678
17679 if Ekind (Proc_Id) = E_Procedure
17680 and then Is_Primitive (Proc_Id)
17681 and then Present (First_Formal (Proc_Id))
17682 then
17683 Typ := Etype (First_Formal (Proc_Id));
17684
17685 if Is_Tagged_Type (Typ)
17686 and then
17687
17688 -- Check for a protected, a synchronized or a task interface
17689
17690 ((Is_Interface (Typ)
17691 and then Is_Synchronized_Interface (Typ))
17692
17693 -- Check for a protected type or a task type that implements
17694 -- an interface.
17695
17696 or else
17697 (Is_Concurrent_Record_Type (Typ)
17698 and then Present (Interfaces (Typ)))
17699
17700 -- In analysis-only mode, examine original protected type
17701
17702 or else
17703 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
17704 and then Present (Interface_List (Parent (Typ))))
17705
17706 -- Check for a private record extension with keyword
17707 -- "synchronized".
17708
17709 or else
17710 (Ekind_In (Typ, E_Record_Type_With_Private,
17711 E_Record_Subtype_With_Private)
17712 and then Synchronized_Present (Parent (Typ))))
17713 then
17714 null;
17715 else
17716 Error_Pragma_Arg
17717 ("controlling formal must be of synchronized tagged type",
17718 Arg1);
17719 return;
17720 end if;
17721
17722 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
17723 -- By_Protected_Procedure to the primitive procedure of a task
17724 -- interface.
17725
17726 if Chars (Arg2) = Name_By_Protected_Procedure
17727 and then Is_Interface (Typ)
17728 and then Is_Task_Interface (Typ)
17729 then
17730 Error_Pragma_Arg
17731 ("implementation kind By_Protected_Procedure cannot be "
17732 & "applied to a task interface primitive", Arg2);
17733 return;
17734 end if;
17735
17736 -- Procedures declared inside a protected type must be accepted
17737
17738 elsif Ekind (Proc_Id) = E_Procedure
17739 and then Is_Protected_Type (Scope (Proc_Id))
17740 then
17741 null;
17742
17743 -- The first argument is not a primitive procedure
17744
17745 else
17746 Error_Pragma_Arg
17747 ("pragma % must be applied to a primitive procedure", Arg1);
17748 return;
17749 end if;
17750
17751 Record_Rep_Item (Proc_Id, N);
17752 end Implemented;
17753
17754 ----------------------
17755 -- Implicit_Packing --
17756 ----------------------
17757
17758 -- pragma Implicit_Packing;
17759
17760 when Pragma_Implicit_Packing =>
17761 GNAT_Pragma;
17762 Check_Arg_Count (0);
17763 Implicit_Packing := True;
17764
17765 ------------
17766 -- Import --
17767 ------------
17768
17769 -- pragma Import (
17770 -- [Convention =>] convention_IDENTIFIER,
17771 -- [Entity =>] LOCAL_NAME
17772 -- [, [External_Name =>] static_string_EXPRESSION ]
17773 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17774
17775 when Pragma_Import =>
17776 Check_Ada_83_Warning;
17777 Check_Arg_Order
17778 ((Name_Convention,
17779 Name_Entity,
17780 Name_External_Name,
17781 Name_Link_Name));
17782
17783 Check_At_Least_N_Arguments (2);
17784 Check_At_Most_N_Arguments (4);
17785 Process_Import_Or_Interface;
17786
17787 ---------------------
17788 -- Import_Function --
17789 ---------------------
17790
17791 -- pragma Import_Function (
17792 -- [Internal =>] LOCAL_NAME,
17793 -- [, [External =>] EXTERNAL_SYMBOL]
17794 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17795 -- [, [Result_Type =>] SUBTYPE_MARK]
17796 -- [, [Mechanism =>] MECHANISM]
17797 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
17798
17799 -- EXTERNAL_SYMBOL ::=
17800 -- IDENTIFIER
17801 -- | static_string_EXPRESSION
17802
17803 -- PARAMETER_TYPES ::=
17804 -- null
17805 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17806
17807 -- TYPE_DESIGNATOR ::=
17808 -- subtype_NAME
17809 -- | subtype_Name ' Access
17810
17811 -- MECHANISM ::=
17812 -- MECHANISM_NAME
17813 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17814
17815 -- MECHANISM_ASSOCIATION ::=
17816 -- [formal_parameter_NAME =>] MECHANISM_NAME
17817
17818 -- MECHANISM_NAME ::=
17819 -- Value
17820 -- | Reference
17821
17822 when Pragma_Import_Function => Import_Function : declare
17823 Args : Args_List (1 .. 6);
17824 Names : constant Name_List (1 .. 6) := (
17825 Name_Internal,
17826 Name_External,
17827 Name_Parameter_Types,
17828 Name_Result_Type,
17829 Name_Mechanism,
17830 Name_Result_Mechanism);
17831
17832 Internal : Node_Id renames Args (1);
17833 External : Node_Id renames Args (2);
17834 Parameter_Types : Node_Id renames Args (3);
17835 Result_Type : Node_Id renames Args (4);
17836 Mechanism : Node_Id renames Args (5);
17837 Result_Mechanism : Node_Id renames Args (6);
17838
17839 begin
17840 GNAT_Pragma;
17841 Gather_Associations (Names, Args);
17842 Process_Extended_Import_Export_Subprogram_Pragma (
17843 Arg_Internal => Internal,
17844 Arg_External => External,
17845 Arg_Parameter_Types => Parameter_Types,
17846 Arg_Result_Type => Result_Type,
17847 Arg_Mechanism => Mechanism,
17848 Arg_Result_Mechanism => Result_Mechanism);
17849 end Import_Function;
17850
17851 -------------------
17852 -- Import_Object --
17853 -------------------
17854
17855 -- pragma Import_Object (
17856 -- [Internal =>] LOCAL_NAME
17857 -- [, [External =>] EXTERNAL_SYMBOL]
17858 -- [, [Size =>] EXTERNAL_SYMBOL]);
17859
17860 -- EXTERNAL_SYMBOL ::=
17861 -- IDENTIFIER
17862 -- | static_string_EXPRESSION
17863
17864 when Pragma_Import_Object => Import_Object : declare
17865 Args : Args_List (1 .. 3);
17866 Names : constant Name_List (1 .. 3) := (
17867 Name_Internal,
17868 Name_External,
17869 Name_Size);
17870
17871 Internal : Node_Id renames Args (1);
17872 External : Node_Id renames Args (2);
17873 Size : Node_Id renames Args (3);
17874
17875 begin
17876 GNAT_Pragma;
17877 Gather_Associations (Names, Args);
17878 Process_Extended_Import_Export_Object_Pragma (
17879 Arg_Internal => Internal,
17880 Arg_External => External,
17881 Arg_Size => Size);
17882 end Import_Object;
17883
17884 ----------------------
17885 -- Import_Procedure --
17886 ----------------------
17887
17888 -- pragma Import_Procedure (
17889 -- [Internal =>] LOCAL_NAME
17890 -- [, [External =>] EXTERNAL_SYMBOL]
17891 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17892 -- [, [Mechanism =>] MECHANISM]);
17893
17894 -- EXTERNAL_SYMBOL ::=
17895 -- IDENTIFIER
17896 -- | static_string_EXPRESSION
17897
17898 -- PARAMETER_TYPES ::=
17899 -- null
17900 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17901
17902 -- TYPE_DESIGNATOR ::=
17903 -- subtype_NAME
17904 -- | subtype_Name ' Access
17905
17906 -- MECHANISM ::=
17907 -- MECHANISM_NAME
17908 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17909
17910 -- MECHANISM_ASSOCIATION ::=
17911 -- [formal_parameter_NAME =>] MECHANISM_NAME
17912
17913 -- MECHANISM_NAME ::=
17914 -- Value
17915 -- | Reference
17916
17917 when Pragma_Import_Procedure => Import_Procedure : declare
17918 Args : Args_List (1 .. 4);
17919 Names : constant Name_List (1 .. 4) := (
17920 Name_Internal,
17921 Name_External,
17922 Name_Parameter_Types,
17923 Name_Mechanism);
17924
17925 Internal : Node_Id renames Args (1);
17926 External : Node_Id renames Args (2);
17927 Parameter_Types : Node_Id renames Args (3);
17928 Mechanism : Node_Id renames Args (4);
17929
17930 begin
17931 GNAT_Pragma;
17932 Gather_Associations (Names, Args);
17933 Process_Extended_Import_Export_Subprogram_Pragma (
17934 Arg_Internal => Internal,
17935 Arg_External => External,
17936 Arg_Parameter_Types => Parameter_Types,
17937 Arg_Mechanism => Mechanism);
17938 end Import_Procedure;
17939
17940 -----------------------------
17941 -- Import_Valued_Procedure --
17942 -----------------------------
17943
17944 -- pragma Import_Valued_Procedure (
17945 -- [Internal =>] LOCAL_NAME
17946 -- [, [External =>] EXTERNAL_SYMBOL]
17947 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17948 -- [, [Mechanism =>] MECHANISM]);
17949
17950 -- EXTERNAL_SYMBOL ::=
17951 -- IDENTIFIER
17952 -- | static_string_EXPRESSION
17953
17954 -- PARAMETER_TYPES ::=
17955 -- null
17956 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17957
17958 -- TYPE_DESIGNATOR ::=
17959 -- subtype_NAME
17960 -- | subtype_Name ' Access
17961
17962 -- MECHANISM ::=
17963 -- MECHANISM_NAME
17964 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17965
17966 -- MECHANISM_ASSOCIATION ::=
17967 -- [formal_parameter_NAME =>] MECHANISM_NAME
17968
17969 -- MECHANISM_NAME ::=
17970 -- Value
17971 -- | Reference
17972
17973 when Pragma_Import_Valued_Procedure =>
17974 Import_Valued_Procedure : declare
17975 Args : Args_List (1 .. 4);
17976 Names : constant Name_List (1 .. 4) := (
17977 Name_Internal,
17978 Name_External,
17979 Name_Parameter_Types,
17980 Name_Mechanism);
17981
17982 Internal : Node_Id renames Args (1);
17983 External : Node_Id renames Args (2);
17984 Parameter_Types : Node_Id renames Args (3);
17985 Mechanism : Node_Id renames Args (4);
17986
17987 begin
17988 GNAT_Pragma;
17989 Gather_Associations (Names, Args);
17990 Process_Extended_Import_Export_Subprogram_Pragma (
17991 Arg_Internal => Internal,
17992 Arg_External => External,
17993 Arg_Parameter_Types => Parameter_Types,
17994 Arg_Mechanism => Mechanism);
17995 end Import_Valued_Procedure;
17996
17997 -----------------
17998 -- Independent --
17999 -----------------
18000
18001 -- pragma Independent (LOCAL_NAME);
18002
18003 when Pragma_Independent =>
18004 Process_Atomic_Independent_Shared_Volatile;
18005
18006 ----------------------------
18007 -- Independent_Components --
18008 ----------------------------
18009
18010 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
18011
18012 when Pragma_Independent_Components => Independent_Components : declare
18013 C : Node_Id;
18014 D : Node_Id;
18015 E_Id : Node_Id;
18016 E : Entity_Id;
18017
18018 begin
18019 Check_Ada_83_Warning;
18020 Ada_2012_Pragma;
18021 Check_No_Identifiers;
18022 Check_Arg_Count (1);
18023 Check_Arg_Is_Local_Name (Arg1);
18024 E_Id := Get_Pragma_Arg (Arg1);
18025
18026 if Etype (E_Id) = Any_Type then
18027 return;
18028 end if;
18029
18030 E := Entity (E_Id);
18031
18032 -- A record type with a self-referential component of anonymous
18033 -- access type is given an incomplete view in order to handle the
18034 -- self reference:
18035 --
18036 -- type Rec is record
18037 -- Self : access Rec;
18038 -- end record;
18039 --
18040 -- becomes
18041 --
18042 -- type Rec;
18043 -- type Ptr is access Rec;
18044 -- type Rec is record
18045 -- Self : Ptr;
18046 -- end record;
18047 --
18048 -- Since the incomplete view is now the initial view of the type,
18049 -- the argument of the pragma will reference the incomplete view,
18050 -- but this view is illegal according to the semantics of the
18051 -- pragma.
18052 --
18053 -- Obtain the full view of an internally-generated incomplete type
18054 -- only. This way an attempt to associate the pragma with a source
18055 -- incomplete type is still caught.
18056
18057 if Ekind (E) = E_Incomplete_Type
18058 and then not Comes_From_Source (E)
18059 and then Present (Full_View (E))
18060 then
18061 E := Full_View (E);
18062 end if;
18063
18064 -- A pragma that applies to a Ghost entity becomes Ghost for the
18065 -- purposes of legality checks and removal of ignored Ghost code.
18066
18067 Mark_Ghost_Pragma (N, E);
18068
18069 -- Check duplicate before we chain ourselves
18070
18071 Check_Duplicate_Pragma (E);
18072
18073 -- Check appropriate entity
18074
18075 if Rep_Item_Too_Early (E, N)
18076 or else
18077 Rep_Item_Too_Late (E, N)
18078 then
18079 return;
18080 end if;
18081
18082 D := Declaration_Node (E);
18083
18084 -- The flag is set on the base type, or on the object
18085
18086 if Nkind (D) = N_Full_Type_Declaration
18087 and then (Is_Array_Type (E) or else Is_Record_Type (E))
18088 then
18089 Set_Has_Independent_Components (Base_Type (E));
18090 Record_Independence_Check (N, Base_Type (E));
18091
18092 -- For record type, set all components independent
18093
18094 if Is_Record_Type (E) then
18095 C := First_Component (E);
18096 while Present (C) loop
18097 Set_Is_Independent (C);
18098 Next_Component (C);
18099 end loop;
18100 end if;
18101
18102 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
18103 and then Nkind (D) = N_Object_Declaration
18104 and then Nkind (Object_Definition (D)) =
18105 N_Constrained_Array_Definition
18106 then
18107 Set_Has_Independent_Components (E);
18108 Record_Independence_Check (N, E);
18109
18110 else
18111 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
18112 end if;
18113 end Independent_Components;
18114
18115 -----------------------
18116 -- Initial_Condition --
18117 -----------------------
18118
18119 -- pragma Initial_Condition (boolean_EXPRESSION);
18120
18121 -- Characteristics:
18122
18123 -- * Analysis - The annotation undergoes initial checks to verify
18124 -- the legal placement and context. Secondary checks preanalyze the
18125 -- expression in:
18126
18127 -- Analyze_Initial_Condition_In_Decl_Part
18128
18129 -- * Expansion - The annotation is expanded during the expansion of
18130 -- the package body whose declaration is subject to the annotation
18131 -- as done in:
18132
18133 -- Expand_Pragma_Initial_Condition
18134
18135 -- * Template - The annotation utilizes the generic template of the
18136 -- related package declaration.
18137
18138 -- * Globals - Capture of global references must occur after full
18139 -- analysis.
18140
18141 -- * Instance - The annotation is instantiated automatically when
18142 -- the related generic package is instantiated.
18143
18144 when Pragma_Initial_Condition => Initial_Condition : declare
18145 Pack_Decl : Node_Id;
18146 Pack_Id : Entity_Id;
18147
18148 begin
18149 GNAT_Pragma;
18150 Check_No_Identifiers;
18151 Check_Arg_Count (1);
18152
18153 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
18154
18155 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
18156 N_Package_Declaration)
18157 then
18158 Pragma_Misplaced;
18159 return;
18160 end if;
18161
18162 Pack_Id := Defining_Entity (Pack_Decl);
18163
18164 -- A pragma that applies to a Ghost entity becomes Ghost for the
18165 -- purposes of legality checks and removal of ignored Ghost code.
18166
18167 Mark_Ghost_Pragma (N, Pack_Id);
18168
18169 -- Chain the pragma on the contract for further processing by
18170 -- Analyze_Initial_Condition_In_Decl_Part.
18171
18172 Add_Contract_Item (N, Pack_Id);
18173
18174 -- The legality checks of pragmas Abstract_State, Initializes, and
18175 -- Initial_Condition are affected by the SPARK mode in effect. In
18176 -- addition, these three pragmas are subject to an inherent order:
18177
18178 -- 1) Abstract_State
18179 -- 2) Initializes
18180 -- 3) Initial_Condition
18181
18182 -- Analyze all these pragmas in the order outlined above
18183
18184 Analyze_If_Present (Pragma_SPARK_Mode);
18185 Analyze_If_Present (Pragma_Abstract_State);
18186 Analyze_If_Present (Pragma_Initializes);
18187 end Initial_Condition;
18188
18189 ------------------------
18190 -- Initialize_Scalars --
18191 ------------------------
18192
18193 -- pragma Initialize_Scalars
18194 -- [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ];
18195
18196 -- TYPE_VALUE_PAIR ::=
18197 -- SCALAR_TYPE => static_EXPRESSION
18198
18199 -- SCALAR_TYPE :=
18200 -- Short_Float
18201 -- | Float
18202 -- | Long_Float
18203 -- | Long_Long_Flat
18204 -- | Signed_8
18205 -- | Signed_16
18206 -- | Signed_32
18207 -- | Signed_64
18208 -- | Unsigned_8
18209 -- | Unsigned_16
18210 -- | Unsigned_32
18211 -- | Unsigned_64
18212
18213 when Pragma_Initialize_Scalars => Do_Initialize_Scalars : declare
18214 Seen : array (Scalar_Id) of Node_Id := (others => Empty);
18215 -- This collection holds the individual pairs which specify the
18216 -- invalid values of their respective scalar types.
18217
18218 procedure Analyze_Float_Value
18219 (Scal_Typ : Float_Scalar_Id;
18220 Val_Expr : Node_Id);
18221 -- Analyze a type value pair associated with float type Scal_Typ
18222 -- and expression Val_Expr.
18223
18224 procedure Analyze_Integer_Value
18225 (Scal_Typ : Integer_Scalar_Id;
18226 Val_Expr : Node_Id);
18227 -- Analyze a type value pair associated with integer type Scal_Typ
18228 -- and expression Val_Expr.
18229
18230 procedure Analyze_Type_Value_Pair (Pair : Node_Id);
18231 -- Analyze type value pair Pair
18232
18233 -------------------------
18234 -- Analyze_Float_Value --
18235 -------------------------
18236
18237 procedure Analyze_Float_Value
18238 (Scal_Typ : Float_Scalar_Id;
18239 Val_Expr : Node_Id)
18240 is
18241 begin
18242 Analyze_And_Resolve (Val_Expr, Any_Real);
18243
18244 if Is_OK_Static_Expression (Val_Expr) then
18245 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value_R (Val_Expr));
18246
18247 else
18248 Error_Msg_Name_1 := Scal_Typ;
18249 Error_Msg_N ("value for type % must be static", Val_Expr);
18250 end if;
18251 end Analyze_Float_Value;
18252
18253 ---------------------------
18254 -- Analyze_Integer_Value --
18255 ---------------------------
18256
18257 procedure Analyze_Integer_Value
18258 (Scal_Typ : Integer_Scalar_Id;
18259 Val_Expr : Node_Id)
18260 is
18261 begin
18262 Analyze_And_Resolve (Val_Expr, Any_Integer);
18263
18264 if Is_OK_Static_Expression (Val_Expr) then
18265 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value (Val_Expr));
18266
18267 else
18268 Error_Msg_Name_1 := Scal_Typ;
18269 Error_Msg_N ("value for type % must be static", Val_Expr);
18270 end if;
18271 end Analyze_Integer_Value;
18272
18273 -----------------------------
18274 -- Analyze_Type_Value_Pair --
18275 -----------------------------
18276
18277 procedure Analyze_Type_Value_Pair (Pair : Node_Id) is
18278 Scal_Typ : constant Name_Id := Chars (Pair);
18279 Val_Expr : constant Node_Id := Expression (Pair);
18280 Prev_Pair : Node_Id;
18281
18282 begin
18283 if Scal_Typ in Scalar_Id then
18284 Prev_Pair := Seen (Scal_Typ);
18285
18286 -- Prevent multiple attempts to set a value for a scalar
18287 -- type.
18288
18289 if Present (Prev_Pair) then
18290 Error_Msg_Name_1 := Scal_Typ;
18291 Error_Msg_N
18292 ("cannot specify multiple invalid values for type %",
18293 Pair);
18294
18295 Error_Msg_Sloc := Sloc (Prev_Pair);
18296 Error_Msg_N ("previous value set #", Pair);
18297
18298 -- Ignore the effects of the pair, but do not halt the
18299 -- analysis of the pragma altogether.
18300
18301 return;
18302
18303 -- Otherwise capture the first pair for this scalar type
18304
18305 else
18306 Seen (Scal_Typ) := Pair;
18307 end if;
18308
18309 if Scal_Typ in Float_Scalar_Id then
18310 Analyze_Float_Value (Scal_Typ, Val_Expr);
18311
18312 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
18313 Analyze_Integer_Value (Scal_Typ, Val_Expr);
18314 end if;
18315
18316 -- Otherwise the scalar family is illegal
18317
18318 else
18319 Error_Msg_Name_1 := Pname;
18320 Error_Msg_N
18321 ("argument of pragma % must denote valid scalar family",
18322 Pair);
18323 end if;
18324 end Analyze_Type_Value_Pair;
18325
18326 -- Local variables
18327
18328 Pairs : constant List_Id := Pragma_Argument_Associations (N);
18329 Pair : Node_Id;
18330
18331 -- Start of processing for Do_Initialize_Scalars
18332
18333 begin
18334 GNAT_Pragma;
18335 Check_Valid_Configuration_Pragma;
18336 Check_Restriction (No_Initialize_Scalars, N);
18337
18338 -- Ignore the effects of the pragma when No_Initialize_Scalars is
18339 -- in effect.
18340
18341 if Restriction_Active (No_Initialize_Scalars) then
18342 null;
18343
18344 -- Initialize_Scalars creates false positives in CodePeer, and
18345 -- incorrect negative results in GNATprove mode, so ignore this
18346 -- pragma in these modes.
18347
18348 elsif CodePeer_Mode or GNATprove_Mode then
18349 null;
18350
18351 -- Otherwise analyze the pragma
18352
18353 else
18354 if Present (Pairs) then
18355
18356 -- Install Standard in order to provide access to primitive
18357 -- types in case the expressions contain attributes such as
18358 -- Integer'Last.
18359
18360 Push_Scope (Standard_Standard);
18361
18362 Pair := First (Pairs);
18363 while Present (Pair) loop
18364 Analyze_Type_Value_Pair (Pair);
18365 Next (Pair);
18366 end loop;
18367
18368 -- Remove Standard
18369
18370 Pop_Scope;
18371 end if;
18372
18373 Init_Or_Norm_Scalars := True;
18374 Initialize_Scalars := True;
18375 end if;
18376 end Do_Initialize_Scalars;
18377
18378 -----------------
18379 -- Initializes --
18380 -----------------
18381
18382 -- pragma Initializes (INITIALIZATION_LIST);
18383
18384 -- INITIALIZATION_LIST ::=
18385 -- null
18386 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
18387
18388 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
18389
18390 -- INPUT_LIST ::=
18391 -- null
18392 -- | INPUT
18393 -- | (INPUT {, INPUT})
18394
18395 -- INPUT ::= name
18396
18397 -- Characteristics:
18398
18399 -- * Analysis - The annotation undergoes initial checks to verify
18400 -- the legal placement and context. Secondary checks preanalyze the
18401 -- expression in:
18402
18403 -- Analyze_Initializes_In_Decl_Part
18404
18405 -- * Expansion - None.
18406
18407 -- * Template - The annotation utilizes the generic template of the
18408 -- related package declaration.
18409
18410 -- * Globals - Capture of global references must occur after full
18411 -- analysis.
18412
18413 -- * Instance - The annotation is instantiated automatically when
18414 -- the related generic package is instantiated.
18415
18416 when Pragma_Initializes => Initializes : declare
18417 Pack_Decl : Node_Id;
18418 Pack_Id : Entity_Id;
18419
18420 begin
18421 GNAT_Pragma;
18422 Check_No_Identifiers;
18423 Check_Arg_Count (1);
18424
18425 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
18426
18427 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
18428 N_Package_Declaration)
18429 then
18430 Pragma_Misplaced;
18431 return;
18432 end if;
18433
18434 Pack_Id := Defining_Entity (Pack_Decl);
18435
18436 -- A pragma that applies to a Ghost entity becomes Ghost for the
18437 -- purposes of legality checks and removal of ignored Ghost code.
18438
18439 Mark_Ghost_Pragma (N, Pack_Id);
18440 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
18441
18442 -- Chain the pragma on the contract for further processing by
18443 -- Analyze_Initializes_In_Decl_Part.
18444
18445 Add_Contract_Item (N, Pack_Id);
18446
18447 -- The legality checks of pragmas Abstract_State, Initializes, and
18448 -- Initial_Condition are affected by the SPARK mode in effect. In
18449 -- addition, these three pragmas are subject to an inherent order:
18450
18451 -- 1) Abstract_State
18452 -- 2) Initializes
18453 -- 3) Initial_Condition
18454
18455 -- Analyze all these pragmas in the order outlined above
18456
18457 Analyze_If_Present (Pragma_SPARK_Mode);
18458 Analyze_If_Present (Pragma_Abstract_State);
18459 Analyze_If_Present (Pragma_Initial_Condition);
18460 end Initializes;
18461
18462 ------------
18463 -- Inline --
18464 ------------
18465
18466 -- pragma Inline ( NAME {, NAME} );
18467
18468 when Pragma_Inline =>
18469
18470 -- Pragma always active unless in GNATprove mode. It is disabled
18471 -- in GNATprove mode because frontend inlining is applied
18472 -- independently of pragmas Inline and Inline_Always for
18473 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
18474 -- in inline.ads.
18475
18476 if not GNATprove_Mode then
18477
18478 -- Inline status is Enabled if option -gnatn is specified.
18479 -- However this status determines only the value of the
18480 -- Is_Inlined flag on the subprogram and does not prevent
18481 -- the pragma itself from being recorded for later use,
18482 -- in particular for a later modification of Is_Inlined
18483 -- independently of the -gnatn option.
18484
18485 -- In other words, if -gnatn is specified for a unit, then
18486 -- all Inline pragmas processed for the compilation of this
18487 -- unit, including those in the spec of other units, are
18488 -- activated, so subprograms will be inlined across units.
18489
18490 -- If -gnatn is not specified, no Inline pragma is activated
18491 -- here, which means that subprograms will not be inlined
18492 -- across units. The Is_Inlined flag will nevertheless be
18493 -- set later when bodies are analyzed, so subprograms will
18494 -- be inlined within the unit.
18495
18496 if Inline_Active then
18497 Process_Inline (Enabled);
18498 else
18499 Process_Inline (Disabled);
18500 end if;
18501 end if;
18502
18503 -------------------
18504 -- Inline_Always --
18505 -------------------
18506
18507 -- pragma Inline_Always ( NAME {, NAME} );
18508
18509 when Pragma_Inline_Always =>
18510 GNAT_Pragma;
18511
18512 -- Pragma always active unless in CodePeer mode or GNATprove
18513 -- mode. It is disabled in CodePeer mode because inlining is
18514 -- not helpful, and enabling it caused walk order issues. It
18515 -- is disabled in GNATprove mode because frontend inlining is
18516 -- applied independently of pragmas Inline and Inline_Always for
18517 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
18518 -- inline.ads.
18519
18520 if not CodePeer_Mode and not GNATprove_Mode then
18521 Process_Inline (Enabled);
18522 end if;
18523
18524 --------------------
18525 -- Inline_Generic --
18526 --------------------
18527
18528 -- pragma Inline_Generic (NAME {, NAME});
18529
18530 when Pragma_Inline_Generic =>
18531 GNAT_Pragma;
18532 Process_Generic_List;
18533
18534 ----------------------
18535 -- Inspection_Point --
18536 ----------------------
18537
18538 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
18539
18540 when Pragma_Inspection_Point => Inspection_Point : declare
18541 Arg : Node_Id;
18542 Exp : Node_Id;
18543
18544 begin
18545 ip;
18546
18547 if Arg_Count > 0 then
18548 Arg := Arg1;
18549 loop
18550 Exp := Get_Pragma_Arg (Arg);
18551 Analyze (Exp);
18552
18553 if not Is_Entity_Name (Exp)
18554 or else not Is_Object (Entity (Exp))
18555 then
18556 Error_Pragma_Arg ("object name required", Arg);
18557 end if;
18558
18559 Next (Arg);
18560 exit when No (Arg);
18561 end loop;
18562 end if;
18563 end Inspection_Point;
18564
18565 ---------------
18566 -- Interface --
18567 ---------------
18568
18569 -- pragma Interface (
18570 -- [ Convention =>] convention_IDENTIFIER,
18571 -- [ Entity =>] LOCAL_NAME
18572 -- [, [External_Name =>] static_string_EXPRESSION ]
18573 -- [, [Link_Name =>] static_string_EXPRESSION ]);
18574
18575 when Pragma_Interface =>
18576 GNAT_Pragma;
18577 Check_Arg_Order
18578 ((Name_Convention,
18579 Name_Entity,
18580 Name_External_Name,
18581 Name_Link_Name));
18582 Check_At_Least_N_Arguments (2);
18583 Check_At_Most_N_Arguments (4);
18584 Process_Import_Or_Interface;
18585
18586 -- In Ada 2005, the permission to use Interface (a reserved word)
18587 -- as a pragma name is considered an obsolescent feature, and this
18588 -- pragma was already obsolescent in Ada 95.
18589
18590 if Ada_Version >= Ada_95 then
18591 Check_Restriction
18592 (No_Obsolescent_Features, Pragma_Identifier (N));
18593
18594 if Warn_On_Obsolescent_Feature then
18595 Error_Msg_N
18596 ("pragma Interface is an obsolescent feature?j?", N);
18597 Error_Msg_N
18598 ("|use pragma Import instead?j?", N);
18599 end if;
18600 end if;
18601
18602 --------------------
18603 -- Interface_Name --
18604 --------------------
18605
18606 -- pragma Interface_Name (
18607 -- [ Entity =>] LOCAL_NAME
18608 -- [,[External_Name =>] static_string_EXPRESSION ]
18609 -- [,[Link_Name =>] static_string_EXPRESSION ]);
18610
18611 when Pragma_Interface_Name => Interface_Name : declare
18612 Id : Node_Id;
18613 Def_Id : Entity_Id;
18614 Hom_Id : Entity_Id;
18615 Found : Boolean;
18616
18617 begin
18618 GNAT_Pragma;
18619 Check_Arg_Order
18620 ((Name_Entity, Name_External_Name, Name_Link_Name));
18621 Check_At_Least_N_Arguments (2);
18622 Check_At_Most_N_Arguments (3);
18623 Id := Get_Pragma_Arg (Arg1);
18624 Analyze (Id);
18625
18626 -- This is obsolete from Ada 95 on, but it is an implementation
18627 -- defined pragma, so we do not consider that it violates the
18628 -- restriction (No_Obsolescent_Features).
18629
18630 if Ada_Version >= Ada_95 then
18631 if Warn_On_Obsolescent_Feature then
18632 Error_Msg_N
18633 ("pragma Interface_Name is an obsolescent feature?j?", N);
18634 Error_Msg_N
18635 ("|use pragma Import instead?j?", N);
18636 end if;
18637 end if;
18638
18639 if not Is_Entity_Name (Id) then
18640 Error_Pragma_Arg
18641 ("first argument for pragma% must be entity name", Arg1);
18642 elsif Etype (Id) = Any_Type then
18643 return;
18644 else
18645 Def_Id := Entity (Id);
18646 end if;
18647
18648 -- Special DEC-compatible processing for the object case, forces
18649 -- object to be imported.
18650
18651 if Ekind (Def_Id) = E_Variable then
18652 Kill_Size_Check_Code (Def_Id);
18653 Note_Possible_Modification (Id, Sure => False);
18654
18655 -- Initialization is not allowed for imported variable
18656
18657 if Present (Expression (Parent (Def_Id)))
18658 and then Comes_From_Source (Expression (Parent (Def_Id)))
18659 then
18660 Error_Msg_Sloc := Sloc (Def_Id);
18661 Error_Pragma_Arg
18662 ("no initialization allowed for declaration of& #",
18663 Arg2);
18664
18665 else
18666 -- For compatibility, support VADS usage of providing both
18667 -- pragmas Interface and Interface_Name to obtain the effect
18668 -- of a single Import pragma.
18669
18670 if Is_Imported (Def_Id)
18671 and then Present (First_Rep_Item (Def_Id))
18672 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
18673 and then Pragma_Name (First_Rep_Item (Def_Id)) =
18674 Name_Interface
18675 then
18676 null;
18677 else
18678 Set_Imported (Def_Id);
18679 end if;
18680
18681 Set_Is_Public (Def_Id);
18682 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
18683 end if;
18684
18685 -- Otherwise must be subprogram
18686
18687 elsif not Is_Subprogram (Def_Id) then
18688 Error_Pragma_Arg
18689 ("argument of pragma% is not subprogram", Arg1);
18690
18691 else
18692 Check_At_Most_N_Arguments (3);
18693 Hom_Id := Def_Id;
18694 Found := False;
18695
18696 -- Loop through homonyms
18697
18698 loop
18699 Def_Id := Get_Base_Subprogram (Hom_Id);
18700
18701 if Is_Imported (Def_Id) then
18702 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
18703 Found := True;
18704 end if;
18705
18706 exit when From_Aspect_Specification (N);
18707 Hom_Id := Homonym (Hom_Id);
18708
18709 exit when No (Hom_Id)
18710 or else Scope (Hom_Id) /= Current_Scope;
18711 end loop;
18712
18713 if not Found then
18714 Error_Pragma_Arg
18715 ("argument of pragma% is not imported subprogram",
18716 Arg1);
18717 end if;
18718 end if;
18719 end Interface_Name;
18720
18721 -----------------------
18722 -- Interrupt_Handler --
18723 -----------------------
18724
18725 -- pragma Interrupt_Handler (handler_NAME);
18726
18727 when Pragma_Interrupt_Handler =>
18728 Check_Ada_83_Warning;
18729 Check_Arg_Count (1);
18730 Check_No_Identifiers;
18731
18732 if No_Run_Time_Mode then
18733 Error_Msg_CRT ("Interrupt_Handler pragma", N);
18734 else
18735 Check_Interrupt_Or_Attach_Handler;
18736 Process_Interrupt_Or_Attach_Handler;
18737 end if;
18738
18739 ------------------------
18740 -- Interrupt_Priority --
18741 ------------------------
18742
18743 -- pragma Interrupt_Priority [(EXPRESSION)];
18744
18745 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
18746 P : constant Node_Id := Parent (N);
18747 Arg : Node_Id;
18748 Ent : Entity_Id;
18749
18750 begin
18751 Check_Ada_83_Warning;
18752
18753 if Arg_Count /= 0 then
18754 Arg := Get_Pragma_Arg (Arg1);
18755 Check_Arg_Count (1);
18756 Check_No_Identifiers;
18757
18758 -- The expression must be analyzed in the special manner
18759 -- described in "Handling of Default and Per-Object
18760 -- Expressions" in sem.ads.
18761
18762 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
18763 end if;
18764
18765 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
18766 Pragma_Misplaced;
18767 return;
18768
18769 else
18770 Ent := Defining_Identifier (Parent (P));
18771
18772 -- Check duplicate pragma before we chain the pragma in the Rep
18773 -- Item chain of Ent.
18774
18775 Check_Duplicate_Pragma (Ent);
18776 Record_Rep_Item (Ent, N);
18777
18778 -- Check the No_Task_At_Interrupt_Priority restriction
18779
18780 if Nkind (P) = N_Task_Definition then
18781 Check_Restriction (No_Task_At_Interrupt_Priority, N);
18782 end if;
18783 end if;
18784 end Interrupt_Priority;
18785
18786 ---------------------
18787 -- Interrupt_State --
18788 ---------------------
18789
18790 -- pragma Interrupt_State (
18791 -- [Name =>] INTERRUPT_ID,
18792 -- [State =>] INTERRUPT_STATE);
18793
18794 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
18795 -- INTERRUPT_STATE => System | Runtime | User
18796
18797 -- Note: if the interrupt id is given as an identifier, then it must
18798 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
18799 -- given as a static integer expression which must be in the range of
18800 -- Ada.Interrupts.Interrupt_ID.
18801
18802 when Pragma_Interrupt_State => Interrupt_State : declare
18803 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
18804 -- This is the entity Ada.Interrupts.Interrupt_ID;
18805
18806 State_Type : Character;
18807 -- Set to 's'/'r'/'u' for System/Runtime/User
18808
18809 IST_Num : Pos;
18810 -- Index to entry in Interrupt_States table
18811
18812 Int_Val : Uint;
18813 -- Value of interrupt
18814
18815 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
18816 -- The first argument to the pragma
18817
18818 Int_Ent : Entity_Id;
18819 -- Interrupt entity in Ada.Interrupts.Names
18820
18821 begin
18822 GNAT_Pragma;
18823 Check_Arg_Order ((Name_Name, Name_State));
18824 Check_Arg_Count (2);
18825
18826 Check_Optional_Identifier (Arg1, Name_Name);
18827 Check_Optional_Identifier (Arg2, Name_State);
18828 Check_Arg_Is_Identifier (Arg2);
18829
18830 -- First argument is identifier
18831
18832 if Nkind (Arg1X) = N_Identifier then
18833
18834 -- Search list of names in Ada.Interrupts.Names
18835
18836 Int_Ent := First_Entity (RTE (RE_Names));
18837 loop
18838 if No (Int_Ent) then
18839 Error_Pragma_Arg ("invalid interrupt name", Arg1);
18840
18841 elsif Chars (Int_Ent) = Chars (Arg1X) then
18842 Int_Val := Expr_Value (Constant_Value (Int_Ent));
18843 exit;
18844 end if;
18845
18846 Next_Entity (Int_Ent);
18847 end loop;
18848
18849 -- First argument is not an identifier, so it must be a static
18850 -- expression of type Ada.Interrupts.Interrupt_ID.
18851
18852 else
18853 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
18854 Int_Val := Expr_Value (Arg1X);
18855
18856 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
18857 or else
18858 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
18859 then
18860 Error_Pragma_Arg
18861 ("value not in range of type "
18862 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
18863 end if;
18864 end if;
18865
18866 -- Check OK state
18867
18868 case Chars (Get_Pragma_Arg (Arg2)) is
18869 when Name_Runtime => State_Type := 'r';
18870 when Name_System => State_Type := 's';
18871 when Name_User => State_Type := 'u';
18872
18873 when others =>
18874 Error_Pragma_Arg ("invalid interrupt state", Arg2);
18875 end case;
18876
18877 -- Check if entry is already stored
18878
18879 IST_Num := Interrupt_States.First;
18880 loop
18881 -- If entry not found, add it
18882
18883 if IST_Num > Interrupt_States.Last then
18884 Interrupt_States.Append
18885 ((Interrupt_Number => UI_To_Int (Int_Val),
18886 Interrupt_State => State_Type,
18887 Pragma_Loc => Loc));
18888 exit;
18889
18890 -- Case of entry for the same entry
18891
18892 elsif Int_Val = Interrupt_States.Table (IST_Num).
18893 Interrupt_Number
18894 then
18895 -- If state matches, done, no need to make redundant entry
18896
18897 exit when
18898 State_Type = Interrupt_States.Table (IST_Num).
18899 Interrupt_State;
18900
18901 -- Otherwise if state does not match, error
18902
18903 Error_Msg_Sloc :=
18904 Interrupt_States.Table (IST_Num).Pragma_Loc;
18905 Error_Pragma_Arg
18906 ("state conflicts with that given #", Arg2);
18907 exit;
18908 end if;
18909
18910 IST_Num := IST_Num + 1;
18911 end loop;
18912 end Interrupt_State;
18913
18914 ---------------
18915 -- Invariant --
18916 ---------------
18917
18918 -- pragma Invariant
18919 -- ([Entity =>] type_LOCAL_NAME,
18920 -- [Check =>] EXPRESSION
18921 -- [,[Message =>] String_Expression]);
18922
18923 when Pragma_Invariant => Invariant : declare
18924 Discard : Boolean;
18925 Typ : Entity_Id;
18926 Typ_Arg : Node_Id;
18927
18928 begin
18929 GNAT_Pragma;
18930 Check_At_Least_N_Arguments (2);
18931 Check_At_Most_N_Arguments (3);
18932 Check_Optional_Identifier (Arg1, Name_Entity);
18933 Check_Optional_Identifier (Arg2, Name_Check);
18934
18935 if Arg_Count = 3 then
18936 Check_Optional_Identifier (Arg3, Name_Message);
18937 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
18938 end if;
18939
18940 Check_Arg_Is_Local_Name (Arg1);
18941
18942 Typ_Arg := Get_Pragma_Arg (Arg1);
18943 Find_Type (Typ_Arg);
18944 Typ := Entity (Typ_Arg);
18945
18946 -- Nothing to do of the related type is erroneous in some way
18947
18948 if Typ = Any_Type then
18949 return;
18950
18951 -- AI12-0041: Invariants are allowed in interface types
18952
18953 elsif Is_Interface (Typ) then
18954 null;
18955
18956 -- An invariant must apply to a private type, or appear in the
18957 -- private part of a package spec and apply to a completion.
18958 -- a class-wide invariant can only appear on a private declaration
18959 -- or private extension, not a completion.
18960
18961 -- A [class-wide] invariant may be associated a [limited] private
18962 -- type or a private extension.
18963
18964 elsif Ekind_In (Typ, E_Limited_Private_Type,
18965 E_Private_Type,
18966 E_Record_Type_With_Private)
18967 then
18968 null;
18969
18970 -- A non-class-wide invariant may be associated with the full view
18971 -- of a [limited] private type or a private extension.
18972
18973 elsif Has_Private_Declaration (Typ)
18974 and then not Class_Present (N)
18975 then
18976 null;
18977
18978 -- A class-wide invariant may appear on the partial view only
18979
18980 elsif Class_Present (N) then
18981 Error_Pragma_Arg
18982 ("pragma % only allowed for private type", Arg1);
18983 return;
18984
18985 -- A regular invariant may appear on both views
18986
18987 else
18988 Error_Pragma_Arg
18989 ("pragma % only allowed for private type or corresponding "
18990 & "full view", Arg1);
18991 return;
18992 end if;
18993
18994 -- An invariant associated with an abstract type (this includes
18995 -- interfaces) must be class-wide.
18996
18997 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
18998 Error_Pragma_Arg
18999 ("pragma % not allowed for abstract type", Arg1);
19000 return;
19001 end if;
19002
19003 -- A pragma that applies to a Ghost entity becomes Ghost for the
19004 -- purposes of legality checks and removal of ignored Ghost code.
19005
19006 Mark_Ghost_Pragma (N, Typ);
19007
19008 -- The pragma defines a type-specific invariant, the type is said
19009 -- to have invariants of its "own".
19010
19011 Set_Has_Own_Invariants (Typ);
19012
19013 -- Set the Invariants_Ignored flag if that policy is in effect
19014
19015 Set_Invariants_Ignored (Typ,
19016 Present (Check_Policy_List)
19017 and then
19018 (Policy_In_Effect (Name_Invariant) = Name_Ignore
19019 and then
19020 Policy_In_Effect (Name_Type_Invariant) = Name_Ignore));
19021
19022 -- If the invariant is class-wide, then it can be inherited by
19023 -- derived or interface implementing types. The type is said to
19024 -- have "inheritable" invariants.
19025
19026 if Class_Present (N) then
19027 Set_Has_Inheritable_Invariants (Typ);
19028 end if;
19029
19030 -- Chain the pragma on to the rep item chain, for processing when
19031 -- the type is frozen.
19032
19033 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
19034
19035 -- Create the declaration of the invariant procedure that will
19036 -- verify the invariant at run time. Interfaces are treated as the
19037 -- partial view of a private type in order to achieve uniformity
19038 -- with the general case. As a result, an interface receives only
19039 -- a "partial" invariant procedure, which is never called.
19040
19041 Build_Invariant_Procedure_Declaration
19042 (Typ => Typ,
19043 Partial_Invariant => Is_Interface (Typ));
19044 end Invariant;
19045
19046 ----------------
19047 -- Keep_Names --
19048 ----------------
19049
19050 -- pragma Keep_Names ([On => ] LOCAL_NAME);
19051
19052 when Pragma_Keep_Names => Keep_Names : declare
19053 Arg : Node_Id;
19054
19055 begin
19056 GNAT_Pragma;
19057 Check_Arg_Count (1);
19058 Check_Optional_Identifier (Arg1, Name_On);
19059 Check_Arg_Is_Local_Name (Arg1);
19060
19061 Arg := Get_Pragma_Arg (Arg1);
19062 Analyze (Arg);
19063
19064 if Etype (Arg) = Any_Type then
19065 return;
19066 end if;
19067
19068 if not Is_Entity_Name (Arg)
19069 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
19070 then
19071 Error_Pragma_Arg
19072 ("pragma% requires a local enumeration type", Arg1);
19073 end if;
19074
19075 Set_Discard_Names (Entity (Arg), False);
19076 end Keep_Names;
19077
19078 -------------
19079 -- License --
19080 -------------
19081
19082 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
19083
19084 when Pragma_License =>
19085 GNAT_Pragma;
19086
19087 -- Do not analyze pragma any further in CodePeer mode, to avoid
19088 -- extraneous errors in this implementation-dependent pragma,
19089 -- which has a different profile on other compilers.
19090
19091 if CodePeer_Mode then
19092 return;
19093 end if;
19094
19095 Check_Arg_Count (1);
19096 Check_No_Identifiers;
19097 Check_Valid_Configuration_Pragma;
19098 Check_Arg_Is_Identifier (Arg1);
19099
19100 declare
19101 Sind : constant Source_File_Index :=
19102 Source_Index (Current_Sem_Unit);
19103
19104 begin
19105 case Chars (Get_Pragma_Arg (Arg1)) is
19106 when Name_GPL =>
19107 Set_License (Sind, GPL);
19108
19109 when Name_Modified_GPL =>
19110 Set_License (Sind, Modified_GPL);
19111
19112 when Name_Restricted =>
19113 Set_License (Sind, Restricted);
19114
19115 when Name_Unrestricted =>
19116 Set_License (Sind, Unrestricted);
19117
19118 when others =>
19119 Error_Pragma_Arg ("invalid license name", Arg1);
19120 end case;
19121 end;
19122
19123 ---------------
19124 -- Link_With --
19125 ---------------
19126
19127 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
19128
19129 when Pragma_Link_With => Link_With : declare
19130 Arg : Node_Id;
19131
19132 begin
19133 GNAT_Pragma;
19134
19135 if Operating_Mode = Generate_Code
19136 and then In_Extended_Main_Source_Unit (N)
19137 then
19138 Check_At_Least_N_Arguments (1);
19139 Check_No_Identifiers;
19140 Check_Is_In_Decl_Part_Or_Package_Spec;
19141 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
19142 Start_String;
19143
19144 Arg := Arg1;
19145 while Present (Arg) loop
19146 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
19147
19148 -- Store argument, converting sequences of spaces to a
19149 -- single null character (this is one of the differences
19150 -- in processing between Link_With and Linker_Options).
19151
19152 Arg_Store : declare
19153 C : constant Char_Code := Get_Char_Code (' ');
19154 S : constant String_Id :=
19155 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
19156 L : constant Nat := String_Length (S);
19157 F : Nat := 1;
19158
19159 procedure Skip_Spaces;
19160 -- Advance F past any spaces
19161
19162 -----------------
19163 -- Skip_Spaces --
19164 -----------------
19165
19166 procedure Skip_Spaces is
19167 begin
19168 while F <= L and then Get_String_Char (S, F) = C loop
19169 F := F + 1;
19170 end loop;
19171 end Skip_Spaces;
19172
19173 -- Start of processing for Arg_Store
19174
19175 begin
19176 Skip_Spaces; -- skip leading spaces
19177
19178 -- Loop through characters, changing any embedded
19179 -- sequence of spaces to a single null character (this
19180 -- is how Link_With/Linker_Options differ)
19181
19182 while F <= L loop
19183 if Get_String_Char (S, F) = C then
19184 Skip_Spaces;
19185 exit when F > L;
19186 Store_String_Char (ASCII.NUL);
19187
19188 else
19189 Store_String_Char (Get_String_Char (S, F));
19190 F := F + 1;
19191 end if;
19192 end loop;
19193 end Arg_Store;
19194
19195 Arg := Next (Arg);
19196
19197 if Present (Arg) then
19198 Store_String_Char (ASCII.NUL);
19199 end if;
19200 end loop;
19201
19202 Store_Linker_Option_String (End_String);
19203 end if;
19204 end Link_With;
19205
19206 ------------------
19207 -- Linker_Alias --
19208 ------------------
19209
19210 -- pragma Linker_Alias (
19211 -- [Entity =>] LOCAL_NAME
19212 -- [Target =>] static_string_EXPRESSION);
19213
19214 when Pragma_Linker_Alias =>
19215 GNAT_Pragma;
19216 Check_Arg_Order ((Name_Entity, Name_Target));
19217 Check_Arg_Count (2);
19218 Check_Optional_Identifier (Arg1, Name_Entity);
19219 Check_Optional_Identifier (Arg2, Name_Target);
19220 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19221 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19222
19223 -- The only processing required is to link this item on to the
19224 -- list of rep items for the given entity. This is accomplished
19225 -- by the call to Rep_Item_Too_Late (when no error is detected
19226 -- and False is returned).
19227
19228 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
19229 return;
19230 else
19231 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
19232 end if;
19233
19234 ------------------------
19235 -- Linker_Constructor --
19236 ------------------------
19237
19238 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
19239
19240 -- Code is shared with Linker_Destructor
19241
19242 -----------------------
19243 -- Linker_Destructor --
19244 -----------------------
19245
19246 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
19247
19248 when Pragma_Linker_Constructor
19249 | Pragma_Linker_Destructor
19250 =>
19251 Linker_Constructor : declare
19252 Arg1_X : Node_Id;
19253 Proc : Entity_Id;
19254
19255 begin
19256 GNAT_Pragma;
19257 Check_Arg_Count (1);
19258 Check_No_Identifiers;
19259 Check_Arg_Is_Local_Name (Arg1);
19260 Arg1_X := Get_Pragma_Arg (Arg1);
19261 Analyze (Arg1_X);
19262 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
19263
19264 if not Is_Library_Level_Entity (Proc) then
19265 Error_Pragma_Arg
19266 ("argument for pragma% must be library level entity", Arg1);
19267 end if;
19268
19269 -- The only processing required is to link this item on to the
19270 -- list of rep items for the given entity. This is accomplished
19271 -- by the call to Rep_Item_Too_Late (when no error is detected
19272 -- and False is returned).
19273
19274 if Rep_Item_Too_Late (Proc, N) then
19275 return;
19276 else
19277 Set_Has_Gigi_Rep_Item (Proc);
19278 end if;
19279 end Linker_Constructor;
19280
19281 --------------------
19282 -- Linker_Options --
19283 --------------------
19284
19285 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
19286
19287 when Pragma_Linker_Options => Linker_Options : declare
19288 Arg : Node_Id;
19289
19290 begin
19291 Check_Ada_83_Warning;
19292 Check_No_Identifiers;
19293 Check_Arg_Count (1);
19294 Check_Is_In_Decl_Part_Or_Package_Spec;
19295 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
19296 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
19297
19298 Arg := Arg2;
19299 while Present (Arg) loop
19300 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
19301 Store_String_Char (ASCII.NUL);
19302 Store_String_Chars
19303 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
19304 Arg := Next (Arg);
19305 end loop;
19306
19307 if Operating_Mode = Generate_Code
19308 and then In_Extended_Main_Source_Unit (N)
19309 then
19310 Store_Linker_Option_String (End_String);
19311 end if;
19312 end Linker_Options;
19313
19314 --------------------
19315 -- Linker_Section --
19316 --------------------
19317
19318 -- pragma Linker_Section (
19319 -- [Entity =>] LOCAL_NAME
19320 -- [Section =>] static_string_EXPRESSION);
19321
19322 when Pragma_Linker_Section => Linker_Section : declare
19323 Arg : Node_Id;
19324 Ent : Entity_Id;
19325 LPE : Node_Id;
19326
19327 Ghost_Error_Posted : Boolean := False;
19328 -- Flag set when an error concerning the illegal mix of Ghost and
19329 -- non-Ghost subprograms is emitted.
19330
19331 Ghost_Id : Entity_Id := Empty;
19332 -- The entity of the first Ghost subprogram encountered while
19333 -- processing the arguments of the pragma.
19334
19335 begin
19336 GNAT_Pragma;
19337 Check_Arg_Order ((Name_Entity, Name_Section));
19338 Check_Arg_Count (2);
19339 Check_Optional_Identifier (Arg1, Name_Entity);
19340 Check_Optional_Identifier (Arg2, Name_Section);
19341 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19342 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19343
19344 -- Check kind of entity
19345
19346 Arg := Get_Pragma_Arg (Arg1);
19347 Ent := Entity (Arg);
19348
19349 case Ekind (Ent) is
19350
19351 -- Objects (constants and variables) and types. For these cases
19352 -- all we need to do is to set the Linker_Section_pragma field,
19353 -- checking that we do not have a duplicate.
19354
19355 when Type_Kind
19356 | E_Constant
19357 | E_Variable
19358 =>
19359 LPE := Linker_Section_Pragma (Ent);
19360
19361 if Present (LPE) then
19362 Error_Msg_Sloc := Sloc (LPE);
19363 Error_Msg_NE
19364 ("Linker_Section already specified for &#", Arg1, Ent);
19365 end if;
19366
19367 Set_Linker_Section_Pragma (Ent, N);
19368
19369 -- A pragma that applies to a Ghost entity becomes Ghost for
19370 -- the purposes of legality checks and removal of ignored
19371 -- Ghost code.
19372
19373 Mark_Ghost_Pragma (N, Ent);
19374
19375 -- Subprograms
19376
19377 when Subprogram_Kind =>
19378
19379 -- Aspect case, entity already set
19380
19381 if From_Aspect_Specification (N) then
19382 Set_Linker_Section_Pragma
19383 (Entity (Corresponding_Aspect (N)), N);
19384
19385 -- Propagate it to its ultimate aliased entity to
19386 -- facilitate the backend processing this attribute
19387 -- in instantiations of generic subprograms.
19388
19389 if Present (Alias (Entity (Corresponding_Aspect (N))))
19390 then
19391 Set_Linker_Section_Pragma
19392 (Ultimate_Alias
19393 (Entity (Corresponding_Aspect (N))), N);
19394 end if;
19395
19396 -- Pragma case, we must climb the homonym chain, but skip
19397 -- any for which the linker section is already set.
19398
19399 else
19400 loop
19401 if No (Linker_Section_Pragma (Ent)) then
19402 Set_Linker_Section_Pragma (Ent, N);
19403
19404 -- Propagate it to its ultimate aliased entity to
19405 -- facilitate the backend processing this attribute
19406 -- in instantiations of generic subprograms.
19407
19408 if Present (Alias (Ent)) then
19409 Set_Linker_Section_Pragma
19410 (Ultimate_Alias (Ent), N);
19411 end if;
19412
19413 -- A pragma that applies to a Ghost entity becomes
19414 -- Ghost for the purposes of legality checks and
19415 -- removal of ignored Ghost code.
19416
19417 Mark_Ghost_Pragma (N, Ent);
19418
19419 -- Capture the entity of the first Ghost subprogram
19420 -- being processed for error detection purposes.
19421
19422 if Is_Ghost_Entity (Ent) then
19423 if No (Ghost_Id) then
19424 Ghost_Id := Ent;
19425 end if;
19426
19427 -- Otherwise the subprogram is non-Ghost. It is
19428 -- illegal to mix references to Ghost and non-Ghost
19429 -- entities (SPARK RM 6.9).
19430
19431 elsif Present (Ghost_Id)
19432 and then not Ghost_Error_Posted
19433 then
19434 Ghost_Error_Posted := True;
19435
19436 Error_Msg_Name_1 := Pname;
19437 Error_Msg_N
19438 ("pragma % cannot mention ghost and "
19439 & "non-ghost subprograms", N);
19440
19441 Error_Msg_Sloc := Sloc (Ghost_Id);
19442 Error_Msg_NE
19443 ("\& # declared as ghost", N, Ghost_Id);
19444
19445 Error_Msg_Sloc := Sloc (Ent);
19446 Error_Msg_NE
19447 ("\& # declared as non-ghost", N, Ent);
19448 end if;
19449 end if;
19450
19451 Ent := Homonym (Ent);
19452 exit when No (Ent)
19453 or else Scope (Ent) /= Current_Scope;
19454 end loop;
19455 end if;
19456
19457 -- All other cases are illegal
19458
19459 when others =>
19460 Error_Pragma_Arg
19461 ("pragma% applies only to objects, subprograms, and types",
19462 Arg1);
19463 end case;
19464 end Linker_Section;
19465
19466 ----------
19467 -- List --
19468 ----------
19469
19470 -- pragma List (On | Off)
19471
19472 -- There is nothing to do here, since we did all the processing for
19473 -- this pragma in Par.Prag (so that it works properly even in syntax
19474 -- only mode).
19475
19476 when Pragma_List =>
19477 null;
19478
19479 ---------------
19480 -- Lock_Free --
19481 ---------------
19482
19483 -- pragma Lock_Free [(Boolean_EXPRESSION)];
19484
19485 when Pragma_Lock_Free => Lock_Free : declare
19486 P : constant Node_Id := Parent (N);
19487 Arg : Node_Id;
19488 Ent : Entity_Id;
19489 Val : Boolean;
19490
19491 begin
19492 Check_No_Identifiers;
19493 Check_At_Most_N_Arguments (1);
19494
19495 -- Protected definition case
19496
19497 if Nkind (P) = N_Protected_Definition then
19498 Ent := Defining_Identifier (Parent (P));
19499
19500 -- One argument
19501
19502 if Arg_Count = 1 then
19503 Arg := Get_Pragma_Arg (Arg1);
19504 Val := Is_True (Static_Boolean (Arg));
19505
19506 -- No arguments (expression is considered to be True)
19507
19508 else
19509 Val := True;
19510 end if;
19511
19512 -- Check duplicate pragma before we chain the pragma in the Rep
19513 -- Item chain of Ent.
19514
19515 Check_Duplicate_Pragma (Ent);
19516 Record_Rep_Item (Ent, N);
19517 Set_Uses_Lock_Free (Ent, Val);
19518
19519 -- Anything else is incorrect placement
19520
19521 else
19522 Pragma_Misplaced;
19523 end if;
19524 end Lock_Free;
19525
19526 --------------------
19527 -- Locking_Policy --
19528 --------------------
19529
19530 -- pragma Locking_Policy (policy_IDENTIFIER);
19531
19532 when Pragma_Locking_Policy => declare
19533 subtype LP_Range is Name_Id
19534 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
19535 LP_Val : LP_Range;
19536 LP : Character;
19537
19538 begin
19539 Check_Ada_83_Warning;
19540 Check_Arg_Count (1);
19541 Check_No_Identifiers;
19542 Check_Arg_Is_Locking_Policy (Arg1);
19543 Check_Valid_Configuration_Pragma;
19544 LP_Val := Chars (Get_Pragma_Arg (Arg1));
19545
19546 case LP_Val is
19547 when Name_Ceiling_Locking => LP := 'C';
19548 when Name_Concurrent_Readers_Locking => LP := 'R';
19549 when Name_Inheritance_Locking => LP := 'I';
19550 end case;
19551
19552 if Locking_Policy /= ' '
19553 and then Locking_Policy /= LP
19554 then
19555 Error_Msg_Sloc := Locking_Policy_Sloc;
19556 Error_Pragma ("locking policy incompatible with policy#");
19557
19558 -- Set new policy, but always preserve System_Location since we
19559 -- like the error message with the run time name.
19560
19561 else
19562 Locking_Policy := LP;
19563
19564 if Locking_Policy_Sloc /= System_Location then
19565 Locking_Policy_Sloc := Loc;
19566 end if;
19567 end if;
19568 end;
19569
19570 -------------------
19571 -- Loop_Optimize --
19572 -------------------
19573
19574 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
19575
19576 -- OPTIMIZATION_HINT ::=
19577 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
19578
19579 when Pragma_Loop_Optimize => Loop_Optimize : declare
19580 Hint : Node_Id;
19581
19582 begin
19583 GNAT_Pragma;
19584 Check_At_Least_N_Arguments (1);
19585 Check_No_Identifiers;
19586
19587 Hint := First (Pragma_Argument_Associations (N));
19588 while Present (Hint) loop
19589 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
19590 Name_No_Unroll,
19591 Name_Unroll,
19592 Name_No_Vector,
19593 Name_Vector);
19594 Next (Hint);
19595 end loop;
19596
19597 Check_Loop_Pragma_Placement;
19598 end Loop_Optimize;
19599
19600 ------------------
19601 -- Loop_Variant --
19602 ------------------
19603
19604 -- pragma Loop_Variant
19605 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
19606
19607 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
19608
19609 -- CHANGE_DIRECTION ::= Increases | Decreases
19610
19611 when Pragma_Loop_Variant => Loop_Variant : declare
19612 Variant : Node_Id;
19613
19614 begin
19615 GNAT_Pragma;
19616 Check_At_Least_N_Arguments (1);
19617 Check_Loop_Pragma_Placement;
19618
19619 -- Process all increasing / decreasing expressions
19620
19621 Variant := First (Pragma_Argument_Associations (N));
19622 while Present (Variant) loop
19623 if Chars (Variant) = No_Name then
19624 Error_Pragma_Arg_Ident ("expect name `Increases`", Variant);
19625
19626 elsif not Nam_In (Chars (Variant), Name_Decreases,
19627 Name_Increases)
19628 then
19629 declare
19630 Name : String := Get_Name_String (Chars (Variant));
19631
19632 begin
19633 -- It is a common mistake to write "Increasing" for
19634 -- "Increases" or "Decreasing" for "Decreases". Recognize
19635 -- specially names starting with "incr" or "decr" to
19636 -- suggest the corresponding name.
19637
19638 System.Case_Util.To_Lower (Name);
19639
19640 if Name'Length >= 4
19641 and then Name (1 .. 4) = "incr"
19642 then
19643 Error_Pragma_Arg_Ident
19644 ("expect name `Increases`", Variant);
19645
19646 elsif Name'Length >= 4
19647 and then Name (1 .. 4) = "decr"
19648 then
19649 Error_Pragma_Arg_Ident
19650 ("expect name `Decreases`", Variant);
19651
19652 else
19653 Error_Pragma_Arg_Ident
19654 ("expect name `Increases` or `Decreases`", Variant);
19655 end if;
19656 end;
19657 end if;
19658
19659 Preanalyze_Assert_Expression
19660 (Expression (Variant), Any_Discrete);
19661
19662 Next (Variant);
19663 end loop;
19664 end Loop_Variant;
19665
19666 -----------------------
19667 -- Machine_Attribute --
19668 -----------------------
19669
19670 -- pragma Machine_Attribute (
19671 -- [Entity =>] LOCAL_NAME,
19672 -- [Attribute_Name =>] static_string_EXPRESSION
19673 -- [, [Info =>] static_EXPRESSION {, static_EXPRESSION}] );
19674
19675 when Pragma_Machine_Attribute => Machine_Attribute : declare
19676 Arg : Node_Id;
19677 Def_Id : Entity_Id;
19678
19679 begin
19680 GNAT_Pragma;
19681 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
19682
19683 if Arg_Count >= 3 then
19684 Check_Optional_Identifier (Arg3, Name_Info);
19685 Arg := Arg3;
19686 while Present (Arg) loop
19687 Check_Arg_Is_OK_Static_Expression (Arg);
19688 Arg := Next (Arg);
19689 end loop;
19690 else
19691 Check_Arg_Count (2);
19692 end if;
19693
19694 Check_Optional_Identifier (Arg1, Name_Entity);
19695 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
19696 Check_Arg_Is_Local_Name (Arg1);
19697 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19698 Def_Id := Entity (Get_Pragma_Arg (Arg1));
19699
19700 if Is_Access_Type (Def_Id) then
19701 Def_Id := Designated_Type (Def_Id);
19702 end if;
19703
19704 if Rep_Item_Too_Early (Def_Id, N) then
19705 return;
19706 end if;
19707
19708 Def_Id := Underlying_Type (Def_Id);
19709
19710 -- The only processing required is to link this item on to the
19711 -- list of rep items for the given entity. This is accomplished
19712 -- by the call to Rep_Item_Too_Late (when no error is detected
19713 -- and False is returned).
19714
19715 if Rep_Item_Too_Late (Def_Id, N) then
19716 return;
19717 else
19718 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
19719 end if;
19720 end Machine_Attribute;
19721
19722 ----------
19723 -- Main --
19724 ----------
19725
19726 -- pragma Main
19727 -- (MAIN_OPTION [, MAIN_OPTION]);
19728
19729 -- MAIN_OPTION ::=
19730 -- [STACK_SIZE =>] static_integer_EXPRESSION
19731 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
19732 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
19733
19734 when Pragma_Main => Main : declare
19735 Args : Args_List (1 .. 3);
19736 Names : constant Name_List (1 .. 3) := (
19737 Name_Stack_Size,
19738 Name_Task_Stack_Size_Default,
19739 Name_Time_Slicing_Enabled);
19740
19741 Nod : Node_Id;
19742
19743 begin
19744 GNAT_Pragma;
19745 Gather_Associations (Names, Args);
19746
19747 for J in 1 .. 2 loop
19748 if Present (Args (J)) then
19749 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19750 end if;
19751 end loop;
19752
19753 if Present (Args (3)) then
19754 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
19755 end if;
19756
19757 Nod := Next (N);
19758 while Present (Nod) loop
19759 if Nkind (Nod) = N_Pragma
19760 and then Pragma_Name (Nod) = Name_Main
19761 then
19762 Error_Msg_Name_1 := Pname;
19763 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19764 end if;
19765
19766 Next (Nod);
19767 end loop;
19768 end Main;
19769
19770 ------------------
19771 -- Main_Storage --
19772 ------------------
19773
19774 -- pragma Main_Storage
19775 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
19776
19777 -- MAIN_STORAGE_OPTION ::=
19778 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
19779 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
19780
19781 when Pragma_Main_Storage => Main_Storage : declare
19782 Args : Args_List (1 .. 2);
19783 Names : constant Name_List (1 .. 2) := (
19784 Name_Working_Storage,
19785 Name_Top_Guard);
19786
19787 Nod : Node_Id;
19788
19789 begin
19790 GNAT_Pragma;
19791 Gather_Associations (Names, Args);
19792
19793 for J in 1 .. 2 loop
19794 if Present (Args (J)) then
19795 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19796 end if;
19797 end loop;
19798
19799 Check_In_Main_Program;
19800
19801 Nod := Next (N);
19802 while Present (Nod) loop
19803 if Nkind (Nod) = N_Pragma
19804 and then Pragma_Name (Nod) = Name_Main_Storage
19805 then
19806 Error_Msg_Name_1 := Pname;
19807 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19808 end if;
19809
19810 Next (Nod);
19811 end loop;
19812 end Main_Storage;
19813
19814 ----------------------------
19815 -- Max_Entry_Queue_Length --
19816 ----------------------------
19817
19818 -- pragma Max_Entry_Queue_Length (static_integer_EXPRESSION);
19819
19820 -- This processing is shared by Pragma_Max_Entry_Queue_Depth and
19821 -- Pragma_Max_Queue_Length.
19822
19823 when Pragma_Max_Entry_Queue_Length
19824 | Pragma_Max_Entry_Queue_Depth
19825 | Pragma_Max_Queue_Length
19826 =>
19827 Max_Entry_Queue_Length : declare
19828 Arg : Node_Id;
19829 Entry_Decl : Node_Id;
19830 Entry_Id : Entity_Id;
19831 Val : Uint;
19832
19833 begin
19834 if Prag_Id = Pragma_Max_Entry_Queue_Depth
19835 or else Prag_Id = Pragma_Max_Queue_Length
19836 then
19837 GNAT_Pragma;
19838 end if;
19839
19840 Check_Arg_Count (1);
19841
19842 Entry_Decl :=
19843 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
19844
19845 -- Entry declaration
19846
19847 if Nkind (Entry_Decl) = N_Entry_Declaration then
19848
19849 -- Entry illegally within a task
19850
19851 if Nkind (Parent (N)) = N_Task_Definition then
19852 Error_Pragma ("pragma % cannot apply to task entries");
19853 return;
19854 end if;
19855
19856 Entry_Id := Defining_Entity (Entry_Decl);
19857
19858 -- Otherwise the pragma is associated with an illegal construct
19859
19860 else
19861 Error_Pragma ("pragma % must apply to a protected entry");
19862 return;
19863 end if;
19864
19865 -- Mark the pragma as Ghost if the related subprogram is also
19866 -- Ghost. This also ensures that any expansion performed further
19867 -- below will produce Ghost nodes.
19868
19869 Mark_Ghost_Pragma (N, Entry_Id);
19870
19871 -- Analyze the Integer expression
19872
19873 Arg := Get_Pragma_Arg (Arg1);
19874 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
19875
19876 Val := Expr_Value (Arg);
19877
19878 if Val < -1 then
19879 Error_Pragma_Arg
19880 ("argument for pragma% cannot be less than -1", Arg1);
19881
19882 elsif not UI_Is_In_Int_Range (Val) then
19883 Error_Pragma_Arg
19884 ("argument for pragma% out of range of Integer", Arg1);
19885
19886 end if;
19887
19888 Record_Rep_Item (Entry_Id, N);
19889 end Max_Entry_Queue_Length;
19890
19891 -----------------
19892 -- Memory_Size --
19893 -----------------
19894
19895 -- pragma Memory_Size (NUMERIC_LITERAL)
19896
19897 when Pragma_Memory_Size =>
19898 GNAT_Pragma;
19899
19900 -- Memory size is simply ignored
19901
19902 Check_No_Identifiers;
19903 Check_Arg_Count (1);
19904 Check_Arg_Is_Integer_Literal (Arg1);
19905
19906 -------------
19907 -- No_Body --
19908 -------------
19909
19910 -- pragma No_Body;
19911
19912 -- The only correct use of this pragma is on its own in a file, in
19913 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
19914 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
19915 -- check for a file containing nothing but a No_Body pragma). If we
19916 -- attempt to process it during normal semantics processing, it means
19917 -- it was misplaced.
19918
19919 when Pragma_No_Body =>
19920 GNAT_Pragma;
19921 Pragma_Misplaced;
19922
19923 -----------------------------
19924 -- No_Elaboration_Code_All --
19925 -----------------------------
19926
19927 -- pragma No_Elaboration_Code_All;
19928
19929 when Pragma_No_Elaboration_Code_All =>
19930 GNAT_Pragma;
19931 Check_Valid_Library_Unit_Pragma;
19932
19933 if Nkind (N) = N_Null_Statement then
19934 return;
19935 end if;
19936
19937 -- Must appear for a spec or generic spec
19938
19939 if not Nkind_In (Unit (Cunit (Current_Sem_Unit)),
19940 N_Generic_Package_Declaration,
19941 N_Generic_Subprogram_Declaration,
19942 N_Package_Declaration,
19943 N_Subprogram_Declaration)
19944 then
19945 Error_Pragma
19946 (Fix_Error
19947 ("pragma% can only occur for package "
19948 & "or subprogram spec"));
19949 end if;
19950
19951 -- Set flag in unit table
19952
19953 Set_No_Elab_Code_All (Current_Sem_Unit);
19954
19955 -- Set restriction No_Elaboration_Code if this is the main unit
19956
19957 if Current_Sem_Unit = Main_Unit then
19958 Set_Restriction (No_Elaboration_Code, N);
19959 end if;
19960
19961 -- If we are in the main unit or in an extended main source unit,
19962 -- then we also add it to the configuration restrictions so that
19963 -- it will apply to all units in the extended main source.
19964
19965 if Current_Sem_Unit = Main_Unit
19966 or else In_Extended_Main_Source_Unit (N)
19967 then
19968 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
19969 end if;
19970
19971 -- If in main extended unit, activate transitive with test
19972
19973 if In_Extended_Main_Source_Unit (N) then
19974 Opt.No_Elab_Code_All_Pragma := N;
19975 end if;
19976
19977 -----------------------------
19978 -- No_Component_Reordering --
19979 -----------------------------
19980
19981 -- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
19982
19983 when Pragma_No_Component_Reordering => No_Comp_Reordering : declare
19984 E : Entity_Id;
19985 E_Id : Node_Id;
19986
19987 begin
19988 GNAT_Pragma;
19989 Check_At_Most_N_Arguments (1);
19990
19991 if Arg_Count = 0 then
19992 Check_Valid_Configuration_Pragma;
19993 Opt.No_Component_Reordering := True;
19994
19995 else
19996 Check_Optional_Identifier (Arg2, Name_Entity);
19997 Check_Arg_Is_Local_Name (Arg1);
19998 E_Id := Get_Pragma_Arg (Arg1);
19999
20000 if Etype (E_Id) = Any_Type then
20001 return;
20002 end if;
20003
20004 E := Entity (E_Id);
20005
20006 if not Is_Record_Type (E) then
20007 Error_Pragma_Arg ("pragma% requires record type", Arg1);
20008 end if;
20009
20010 Set_No_Reordering (Base_Type (E));
20011 end if;
20012 end No_Comp_Reordering;
20013
20014 --------------------------
20015 -- No_Heap_Finalization --
20016 --------------------------
20017
20018 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
20019
20020 when Pragma_No_Heap_Finalization => No_Heap_Finalization : declare
20021 Context : constant Node_Id := Parent (N);
20022 Typ_Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
20023 Prev : Node_Id;
20024 Typ : Entity_Id;
20025
20026 begin
20027 GNAT_Pragma;
20028 Check_No_Identifiers;
20029
20030 -- The pragma appears in a configuration file
20031
20032 if No (Context) then
20033 Check_Arg_Count (0);
20034 Check_Valid_Configuration_Pragma;
20035
20036 -- Detect a duplicate pragma
20037
20038 if Present (No_Heap_Finalization_Pragma) then
20039 Duplication_Error
20040 (Prag => N,
20041 Prev => No_Heap_Finalization_Pragma);
20042 raise Pragma_Exit;
20043 end if;
20044
20045 No_Heap_Finalization_Pragma := N;
20046
20047 -- Otherwise the pragma should be associated with a library-level
20048 -- named access-to-object type.
20049
20050 else
20051 Check_Arg_Count (1);
20052 Check_Arg_Is_Local_Name (Arg1);
20053
20054 Find_Type (Typ_Arg);
20055 Typ := Entity (Typ_Arg);
20056
20057 -- The type being subjected to the pragma is erroneous
20058
20059 if Typ = Any_Type then
20060 Error_Pragma ("cannot find type referenced by pragma %");
20061
20062 -- The pragma is applied to an incomplete or generic formal
20063 -- type way too early.
20064
20065 elsif Rep_Item_Too_Early (Typ, N) then
20066 return;
20067
20068 else
20069 Typ := Underlying_Type (Typ);
20070 end if;
20071
20072 -- The pragma must apply to an access-to-object type
20073
20074 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type) then
20075 null;
20076
20077 -- Give a detailed error message on all other access type kinds
20078
20079 elsif Ekind (Typ) = E_Access_Protected_Subprogram_Type then
20080 Error_Pragma
20081 ("pragma % cannot apply to access protected subprogram "
20082 & "type");
20083
20084 elsif Ekind (Typ) = E_Access_Subprogram_Type then
20085 Error_Pragma
20086 ("pragma % cannot apply to access subprogram type");
20087
20088 elsif Is_Anonymous_Access_Type (Typ) then
20089 Error_Pragma
20090 ("pragma % cannot apply to anonymous access type");
20091
20092 -- Give a general error message in case the pragma applies to a
20093 -- non-access type.
20094
20095 else
20096 Error_Pragma
20097 ("pragma % must apply to library level access type");
20098 end if;
20099
20100 -- At this point the argument denotes an access-to-object type.
20101 -- Ensure that the type is declared at the library level.
20102
20103 if Is_Library_Level_Entity (Typ) then
20104 null;
20105
20106 -- Quietly ignore an access-to-object type originally declared
20107 -- at the library level within a generic, but instantiated at
20108 -- a non-library level. As a result the access-to-object type
20109 -- "loses" its No_Heap_Finalization property.
20110
20111 elsif In_Instance then
20112 raise Pragma_Exit;
20113
20114 else
20115 Error_Pragma
20116 ("pragma % must apply to library level access type");
20117 end if;
20118
20119 -- Detect a duplicate pragma
20120
20121 if Present (No_Heap_Finalization_Pragma) then
20122 Duplication_Error
20123 (Prag => N,
20124 Prev => No_Heap_Finalization_Pragma);
20125 raise Pragma_Exit;
20126
20127 else
20128 Prev := Get_Pragma (Typ, Pragma_No_Heap_Finalization);
20129
20130 if Present (Prev) then
20131 Duplication_Error
20132 (Prag => N,
20133 Prev => Prev);
20134 raise Pragma_Exit;
20135 end if;
20136 end if;
20137
20138 Record_Rep_Item (Typ, N);
20139 end if;
20140 end No_Heap_Finalization;
20141
20142 ---------------
20143 -- No_Inline --
20144 ---------------
20145
20146 -- pragma No_Inline ( NAME {, NAME} );
20147
20148 when Pragma_No_Inline =>
20149 GNAT_Pragma;
20150 Process_Inline (Suppressed);
20151
20152 ---------------
20153 -- No_Return --
20154 ---------------
20155
20156 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
20157
20158 when Pragma_No_Return => No_Return : declare
20159 Arg : Node_Id;
20160 E : Entity_Id;
20161 Found : Boolean;
20162 Id : Node_Id;
20163
20164 Ghost_Error_Posted : Boolean := False;
20165 -- Flag set when an error concerning the illegal mix of Ghost and
20166 -- non-Ghost subprograms is emitted.
20167
20168 Ghost_Id : Entity_Id := Empty;
20169 -- The entity of the first Ghost procedure encountered while
20170 -- processing the arguments of the pragma.
20171
20172 begin
20173 Ada_2005_Pragma;
20174 Check_At_Least_N_Arguments (1);
20175
20176 -- Loop through arguments of pragma
20177
20178 Arg := Arg1;
20179 while Present (Arg) loop
20180 Check_Arg_Is_Local_Name (Arg);
20181 Id := Get_Pragma_Arg (Arg);
20182 Analyze (Id);
20183
20184 if not Is_Entity_Name (Id) then
20185 Error_Pragma_Arg ("entity name required", Arg);
20186 end if;
20187
20188 if Etype (Id) = Any_Type then
20189 raise Pragma_Exit;
20190 end if;
20191
20192 -- Loop to find matching procedures
20193
20194 E := Entity (Id);
20195
20196 Found := False;
20197 while Present (E)
20198 and then Scope (E) = Current_Scope
20199 loop
20200 if Ekind_In (E, E_Generic_Procedure, E_Procedure) then
20201
20202 -- Check that the pragma is not applied to a body.
20203 -- First check the specless body case, to give a
20204 -- different error message. These checks do not apply
20205 -- if Relaxed_RM_Semantics, to accommodate other Ada
20206 -- compilers. Disable these checks under -gnatd.J.
20207
20208 if not Debug_Flag_Dot_JJ then
20209 if Nkind (Parent (Declaration_Node (E))) =
20210 N_Subprogram_Body
20211 and then not Relaxed_RM_Semantics
20212 then
20213 Error_Pragma
20214 ("pragma% requires separate spec and must come "
20215 & "before body");
20216 end if;
20217
20218 -- Now the "specful" body case
20219
20220 if Rep_Item_Too_Late (E, N) then
20221 raise Pragma_Exit;
20222 end if;
20223 end if;
20224
20225 Set_No_Return (E);
20226
20227 -- A pragma that applies to a Ghost entity becomes Ghost
20228 -- for the purposes of legality checks and removal of
20229 -- ignored Ghost code.
20230
20231 Mark_Ghost_Pragma (N, E);
20232
20233 -- Capture the entity of the first Ghost procedure being
20234 -- processed for error detection purposes.
20235
20236 if Is_Ghost_Entity (E) then
20237 if No (Ghost_Id) then
20238 Ghost_Id := E;
20239 end if;
20240
20241 -- Otherwise the subprogram is non-Ghost. It is illegal
20242 -- to mix references to Ghost and non-Ghost entities
20243 -- (SPARK RM 6.9).
20244
20245 elsif Present (Ghost_Id)
20246 and then not Ghost_Error_Posted
20247 then
20248 Ghost_Error_Posted := True;
20249
20250 Error_Msg_Name_1 := Pname;
20251 Error_Msg_N
20252 ("pragma % cannot mention ghost and non-ghost "
20253 & "procedures", N);
20254
20255 Error_Msg_Sloc := Sloc (Ghost_Id);
20256 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
20257
20258 Error_Msg_Sloc := Sloc (E);
20259 Error_Msg_NE ("\& # declared as non-ghost", N, E);
20260 end if;
20261
20262 -- Set flag on any alias as well
20263
20264 if Is_Overloadable (E) and then Present (Alias (E)) then
20265 Set_No_Return (Alias (E));
20266 end if;
20267
20268 Found := True;
20269 end if;
20270
20271 exit when From_Aspect_Specification (N);
20272 E := Homonym (E);
20273 end loop;
20274
20275 -- If entity in not in current scope it may be the enclosing
20276 -- suprogram body to which the aspect applies.
20277
20278 if not Found then
20279 if Entity (Id) = Current_Scope
20280 and then From_Aspect_Specification (N)
20281 then
20282 Set_No_Return (Entity (Id));
20283 else
20284 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
20285 end if;
20286 end if;
20287
20288 Next (Arg);
20289 end loop;
20290 end No_Return;
20291
20292 -----------------
20293 -- No_Run_Time --
20294 -----------------
20295
20296 -- pragma No_Run_Time;
20297
20298 -- Note: this pragma is retained for backwards compatibility. See
20299 -- body of Rtsfind for full details on its handling.
20300
20301 when Pragma_No_Run_Time =>
20302 GNAT_Pragma;
20303 Check_Valid_Configuration_Pragma;
20304 Check_Arg_Count (0);
20305
20306 -- Remove backward compatibility if Build_Type is FSF or GPL and
20307 -- generate a warning.
20308
20309 declare
20310 Ignore : constant Boolean := Build_Type in FSF .. GPL;
20311 begin
20312 if Ignore then
20313 Error_Pragma ("pragma% is ignored, has no effect??");
20314 else
20315 No_Run_Time_Mode := True;
20316 Configurable_Run_Time_Mode := True;
20317
20318 -- Set Duration to 32 bits if word size is 32
20319
20320 if Ttypes.System_Word_Size = 32 then
20321 Duration_32_Bits_On_Target := True;
20322 end if;
20323
20324 -- Set appropriate restrictions
20325
20326 Set_Restriction (No_Finalization, N);
20327 Set_Restriction (No_Exception_Handlers, N);
20328 Set_Restriction (Max_Tasks, N, 0);
20329 Set_Restriction (No_Tasking, N);
20330 end if;
20331 end;
20332
20333 -----------------------
20334 -- No_Tagged_Streams --
20335 -----------------------
20336
20337 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
20338
20339 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
20340 E : Entity_Id;
20341 E_Id : Node_Id;
20342
20343 begin
20344 GNAT_Pragma;
20345 Check_At_Most_N_Arguments (1);
20346
20347 -- One argument case
20348
20349 if Arg_Count = 1 then
20350 Check_Optional_Identifier (Arg1, Name_Entity);
20351 Check_Arg_Is_Local_Name (Arg1);
20352 E_Id := Get_Pragma_Arg (Arg1);
20353
20354 if Etype (E_Id) = Any_Type then
20355 return;
20356 end if;
20357
20358 E := Entity (E_Id);
20359
20360 Check_Duplicate_Pragma (E);
20361
20362 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
20363 Error_Pragma_Arg
20364 ("argument for pragma% must be root tagged type", Arg1);
20365 end if;
20366
20367 if Rep_Item_Too_Early (E, N)
20368 or else
20369 Rep_Item_Too_Late (E, N)
20370 then
20371 return;
20372 else
20373 Set_No_Tagged_Streams_Pragma (E, N);
20374 end if;
20375
20376 -- Zero argument case
20377
20378 else
20379 Check_Is_In_Decl_Part_Or_Package_Spec;
20380 No_Tagged_Streams := N;
20381 end if;
20382 end No_Tagged_Strms;
20383
20384 ------------------------
20385 -- No_Strict_Aliasing --
20386 ------------------------
20387
20388 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
20389
20390 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
20391 E : Entity_Id;
20392 E_Id : Node_Id;
20393
20394 begin
20395 GNAT_Pragma;
20396 Check_At_Most_N_Arguments (1);
20397
20398 if Arg_Count = 0 then
20399 Check_Valid_Configuration_Pragma;
20400 Opt.No_Strict_Aliasing := True;
20401
20402 else
20403 Check_Optional_Identifier (Arg2, Name_Entity);
20404 Check_Arg_Is_Local_Name (Arg1);
20405 E_Id := Get_Pragma_Arg (Arg1);
20406
20407 if Etype (E_Id) = Any_Type then
20408 return;
20409 end if;
20410
20411 E := Entity (E_Id);
20412
20413 if not Is_Access_Type (E) then
20414 Error_Pragma_Arg ("pragma% requires access type", Arg1);
20415 end if;
20416
20417 Set_No_Strict_Aliasing (Base_Type (E));
20418 end if;
20419 end No_Strict_Aliasing;
20420
20421 -----------------------
20422 -- Normalize_Scalars --
20423 -----------------------
20424
20425 -- pragma Normalize_Scalars;
20426
20427 when Pragma_Normalize_Scalars =>
20428 Check_Ada_83_Warning;
20429 Check_Arg_Count (0);
20430 Check_Valid_Configuration_Pragma;
20431
20432 -- Normalize_Scalars creates false positives in CodePeer, and
20433 -- incorrect negative results in GNATprove mode, so ignore this
20434 -- pragma in these modes.
20435
20436 if not (CodePeer_Mode or GNATprove_Mode) then
20437 Normalize_Scalars := True;
20438 Init_Or_Norm_Scalars := True;
20439 end if;
20440
20441 -----------------
20442 -- Obsolescent --
20443 -----------------
20444
20445 -- pragma Obsolescent;
20446
20447 -- pragma Obsolescent (
20448 -- [Message =>] static_string_EXPRESSION
20449 -- [,[Version =>] Ada_05]]);
20450
20451 -- pragma Obsolescent (
20452 -- [Entity =>] NAME
20453 -- [,[Message =>] static_string_EXPRESSION
20454 -- [,[Version =>] Ada_05]] );
20455
20456 when Pragma_Obsolescent => Obsolescent : declare
20457 Decl : Node_Id;
20458 Ename : Node_Id;
20459
20460 procedure Set_Obsolescent (E : Entity_Id);
20461 -- Given an entity Ent, mark it as obsolescent if appropriate
20462
20463 ---------------------
20464 -- Set_Obsolescent --
20465 ---------------------
20466
20467 procedure Set_Obsolescent (E : Entity_Id) is
20468 Active : Boolean;
20469 Ent : Entity_Id;
20470 S : String_Id;
20471
20472 begin
20473 Active := True;
20474 Ent := E;
20475
20476 -- A pragma that applies to a Ghost entity becomes Ghost for
20477 -- the purposes of legality checks and removal of ignored Ghost
20478 -- code.
20479
20480 Mark_Ghost_Pragma (N, E);
20481
20482 -- Entity name was given
20483
20484 if Present (Ename) then
20485
20486 -- If entity name matches, we are fine.
20487
20488 if Chars (Ename) = Chars (Ent) then
20489 Set_Entity (Ename, Ent);
20490 Generate_Reference (Ent, Ename);
20491
20492 -- If entity name does not match, only possibility is an
20493 -- enumeration literal from an enumeration type declaration.
20494
20495 elsif Ekind (Ent) /= E_Enumeration_Type then
20496 Error_Pragma
20497 ("pragma % entity name does not match declaration");
20498
20499 else
20500 Ent := First_Literal (E);
20501 loop
20502 if No (Ent) then
20503 Error_Pragma
20504 ("pragma % entity name does not match any "
20505 & "enumeration literal");
20506
20507 elsif Chars (Ent) = Chars (Ename) then
20508 Set_Entity (Ename, Ent);
20509 Generate_Reference (Ent, Ename);
20510 exit;
20511
20512 else
20513 Next_Literal (Ent);
20514 end if;
20515 end loop;
20516 end if;
20517 end if;
20518
20519 -- Ent points to entity to be marked
20520
20521 if Arg_Count >= 1 then
20522
20523 -- Deal with static string argument
20524
20525 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
20526 S := Strval (Get_Pragma_Arg (Arg1));
20527
20528 for J in 1 .. String_Length (S) loop
20529 if not In_Character_Range (Get_String_Char (S, J)) then
20530 Error_Pragma_Arg
20531 ("pragma% argument does not allow wide characters",
20532 Arg1);
20533 end if;
20534 end loop;
20535
20536 Obsolescent_Warnings.Append
20537 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
20538
20539 -- Check for Ada_05 parameter
20540
20541 if Arg_Count /= 1 then
20542 Check_Arg_Count (2);
20543
20544 declare
20545 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
20546
20547 begin
20548 Check_Arg_Is_Identifier (Argx);
20549
20550 if Chars (Argx) /= Name_Ada_05 then
20551 Error_Msg_Name_2 := Name_Ada_05;
20552 Error_Pragma_Arg
20553 ("only allowed argument for pragma% is %", Argx);
20554 end if;
20555
20556 if Ada_Version_Explicit < Ada_2005
20557 or else not Warn_On_Ada_2005_Compatibility
20558 then
20559 Active := False;
20560 end if;
20561 end;
20562 end if;
20563 end if;
20564
20565 -- Set flag if pragma active
20566
20567 if Active then
20568 Set_Is_Obsolescent (Ent);
20569 end if;
20570
20571 return;
20572 end Set_Obsolescent;
20573
20574 -- Start of processing for pragma Obsolescent
20575
20576 begin
20577 GNAT_Pragma;
20578
20579 Check_At_Most_N_Arguments (3);
20580
20581 -- See if first argument specifies an entity name
20582
20583 if Arg_Count >= 1
20584 and then
20585 (Chars (Arg1) = Name_Entity
20586 or else
20587 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
20588 N_Identifier,
20589 N_Operator_Symbol))
20590 then
20591 Ename := Get_Pragma_Arg (Arg1);
20592
20593 -- Eliminate first argument, so we can share processing
20594
20595 Arg1 := Arg2;
20596 Arg2 := Arg3;
20597 Arg_Count := Arg_Count - 1;
20598
20599 -- No Entity name argument given
20600
20601 else
20602 Ename := Empty;
20603 end if;
20604
20605 if Arg_Count >= 1 then
20606 Check_Optional_Identifier (Arg1, Name_Message);
20607
20608 if Arg_Count = 2 then
20609 Check_Optional_Identifier (Arg2, Name_Version);
20610 end if;
20611 end if;
20612
20613 -- Get immediately preceding declaration
20614
20615 Decl := Prev (N);
20616 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
20617 Prev (Decl);
20618 end loop;
20619
20620 -- Cases where we do not follow anything other than another pragma
20621
20622 if No (Decl) then
20623
20624 -- First case: library level compilation unit declaration with
20625 -- the pragma immediately following the declaration.
20626
20627 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
20628 Set_Obsolescent
20629 (Defining_Entity (Unit (Parent (Parent (N)))));
20630 return;
20631
20632 -- Case 2: library unit placement for package
20633
20634 else
20635 declare
20636 Ent : constant Entity_Id := Find_Lib_Unit_Name;
20637 begin
20638 if Is_Package_Or_Generic_Package (Ent) then
20639 Set_Obsolescent (Ent);
20640 return;
20641 end if;
20642 end;
20643 end if;
20644
20645 -- Cases where we must follow a declaration, including an
20646 -- abstract subprogram declaration, which is not in the
20647 -- other node subtypes.
20648
20649 else
20650 if Nkind (Decl) not in N_Declaration
20651 and then Nkind (Decl) not in N_Later_Decl_Item
20652 and then Nkind (Decl) not in N_Generic_Declaration
20653 and then Nkind (Decl) not in N_Renaming_Declaration
20654 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
20655 then
20656 Error_Pragma
20657 ("pragma% misplaced, "
20658 & "must immediately follow a declaration");
20659
20660 else
20661 Set_Obsolescent (Defining_Entity (Decl));
20662 return;
20663 end if;
20664 end if;
20665 end Obsolescent;
20666
20667 --------------
20668 -- Optimize --
20669 --------------
20670
20671 -- pragma Optimize (Time | Space | Off);
20672
20673 -- The actual check for optimize is done in Gigi. Note that this
20674 -- pragma does not actually change the optimization setting, it
20675 -- simply checks that it is consistent with the pragma.
20676
20677 when Pragma_Optimize =>
20678 Check_No_Identifiers;
20679 Check_Arg_Count (1);
20680 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
20681
20682 ------------------------
20683 -- Optimize_Alignment --
20684 ------------------------
20685
20686 -- pragma Optimize_Alignment (Time | Space | Off);
20687
20688 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
20689 GNAT_Pragma;
20690 Check_No_Identifiers;
20691 Check_Arg_Count (1);
20692 Check_Valid_Configuration_Pragma;
20693
20694 declare
20695 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
20696 begin
20697 case Nam is
20698 when Name_Off => Opt.Optimize_Alignment := 'O';
20699 when Name_Space => Opt.Optimize_Alignment := 'S';
20700 when Name_Time => Opt.Optimize_Alignment := 'T';
20701
20702 when others =>
20703 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
20704 end case;
20705 end;
20706
20707 -- Set indication that mode is set locally. If we are in fact in a
20708 -- configuration pragma file, this setting is harmless since the
20709 -- switch will get reset anyway at the start of each unit.
20710
20711 Optimize_Alignment_Local := True;
20712 end Optimize_Alignment;
20713
20714 -------------
20715 -- Ordered --
20716 -------------
20717
20718 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
20719
20720 when Pragma_Ordered => Ordered : declare
20721 Assoc : constant Node_Id := Arg1;
20722 Type_Id : Node_Id;
20723 Typ : Entity_Id;
20724
20725 begin
20726 GNAT_Pragma;
20727 Check_No_Identifiers;
20728 Check_Arg_Count (1);
20729 Check_Arg_Is_Local_Name (Arg1);
20730
20731 Type_Id := Get_Pragma_Arg (Assoc);
20732 Find_Type (Type_Id);
20733 Typ := Entity (Type_Id);
20734
20735 if Typ = Any_Type then
20736 return;
20737 else
20738 Typ := Underlying_Type (Typ);
20739 end if;
20740
20741 if not Is_Enumeration_Type (Typ) then
20742 Error_Pragma ("pragma% must specify enumeration type");
20743 end if;
20744
20745 Check_First_Subtype (Arg1);
20746 Set_Has_Pragma_Ordered (Base_Type (Typ));
20747 end Ordered;
20748
20749 -------------------
20750 -- Overflow_Mode --
20751 -------------------
20752
20753 -- pragma Overflow_Mode
20754 -- ([General => ] MODE [, [Assertions => ] MODE]);
20755
20756 -- MODE := STRICT | MINIMIZED | ELIMINATED
20757
20758 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
20759 -- since System.Bignums makes this assumption. This is true of nearly
20760 -- all (all?) targets.
20761
20762 when Pragma_Overflow_Mode => Overflow_Mode : declare
20763 function Get_Overflow_Mode
20764 (Name : Name_Id;
20765 Arg : Node_Id) return Overflow_Mode_Type;
20766 -- Function to process one pragma argument, Arg. If an identifier
20767 -- is present, it must be Name. Mode type is returned if a valid
20768 -- argument exists, otherwise an error is signalled.
20769
20770 -----------------------
20771 -- Get_Overflow_Mode --
20772 -----------------------
20773
20774 function Get_Overflow_Mode
20775 (Name : Name_Id;
20776 Arg : Node_Id) return Overflow_Mode_Type
20777 is
20778 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
20779
20780 begin
20781 Check_Optional_Identifier (Arg, Name);
20782 Check_Arg_Is_Identifier (Argx);
20783
20784 if Chars (Argx) = Name_Strict then
20785 return Strict;
20786
20787 elsif Chars (Argx) = Name_Minimized then
20788 return Minimized;
20789
20790 elsif Chars (Argx) = Name_Eliminated then
20791 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
20792 Error_Pragma_Arg
20793 ("Eliminated not implemented on this target", Argx);
20794 else
20795 return Eliminated;
20796 end if;
20797
20798 else
20799 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
20800 end if;
20801 end Get_Overflow_Mode;
20802
20803 -- Start of processing for Overflow_Mode
20804
20805 begin
20806 GNAT_Pragma;
20807 Check_At_Least_N_Arguments (1);
20808 Check_At_Most_N_Arguments (2);
20809
20810 -- Process first argument
20811
20812 Scope_Suppress.Overflow_Mode_General :=
20813 Get_Overflow_Mode (Name_General, Arg1);
20814
20815 -- Case of only one argument
20816
20817 if Arg_Count = 1 then
20818 Scope_Suppress.Overflow_Mode_Assertions :=
20819 Scope_Suppress.Overflow_Mode_General;
20820
20821 -- Case of two arguments present
20822
20823 else
20824 Scope_Suppress.Overflow_Mode_Assertions :=
20825 Get_Overflow_Mode (Name_Assertions, Arg2);
20826 end if;
20827 end Overflow_Mode;
20828
20829 --------------------------
20830 -- Overriding Renamings --
20831 --------------------------
20832
20833 -- pragma Overriding_Renamings;
20834
20835 when Pragma_Overriding_Renamings =>
20836 GNAT_Pragma;
20837 Check_Arg_Count (0);
20838 Check_Valid_Configuration_Pragma;
20839 Overriding_Renamings := True;
20840
20841 ----------
20842 -- Pack --
20843 ----------
20844
20845 -- pragma Pack (first_subtype_LOCAL_NAME);
20846
20847 when Pragma_Pack => Pack : declare
20848 Assoc : constant Node_Id := Arg1;
20849 Ctyp : Entity_Id;
20850 Ignore : Boolean := False;
20851 Typ : Entity_Id;
20852 Type_Id : Node_Id;
20853
20854 begin
20855 Check_No_Identifiers;
20856 Check_Arg_Count (1);
20857 Check_Arg_Is_Local_Name (Arg1);
20858 Type_Id := Get_Pragma_Arg (Assoc);
20859
20860 if not Is_Entity_Name (Type_Id)
20861 or else not Is_Type (Entity (Type_Id))
20862 then
20863 Error_Pragma_Arg
20864 ("argument for pragma% must be type or subtype", Arg1);
20865 end if;
20866
20867 Find_Type (Type_Id);
20868 Typ := Entity (Type_Id);
20869
20870 if Typ = Any_Type
20871 or else Rep_Item_Too_Early (Typ, N)
20872 then
20873 return;
20874 else
20875 Typ := Underlying_Type (Typ);
20876 end if;
20877
20878 -- A pragma that applies to a Ghost entity becomes Ghost for the
20879 -- purposes of legality checks and removal of ignored Ghost code.
20880
20881 Mark_Ghost_Pragma (N, Typ);
20882
20883 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
20884 Error_Pragma ("pragma% must specify array or record type");
20885 end if;
20886
20887 Check_First_Subtype (Arg1);
20888 Check_Duplicate_Pragma (Typ);
20889
20890 -- Array type
20891
20892 if Is_Array_Type (Typ) then
20893 Ctyp := Component_Type (Typ);
20894
20895 -- Ignore pack that does nothing
20896
20897 if Known_Static_Esize (Ctyp)
20898 and then Known_Static_RM_Size (Ctyp)
20899 and then Esize (Ctyp) = RM_Size (Ctyp)
20900 and then Addressable (Esize (Ctyp))
20901 then
20902 Ignore := True;
20903 end if;
20904
20905 -- Process OK pragma Pack. Note that if there is a separate
20906 -- component clause present, the Pack will be cancelled. This
20907 -- processing is in Freeze.
20908
20909 if not Rep_Item_Too_Late (Typ, N) then
20910
20911 -- In CodePeer mode, we do not need complex front-end
20912 -- expansions related to pragma Pack, so disable handling
20913 -- of pragma Pack.
20914
20915 if CodePeer_Mode then
20916 null;
20917
20918 -- Normal case where we do the pack action
20919
20920 else
20921 if not Ignore then
20922 Set_Is_Packed (Base_Type (Typ));
20923 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20924 end if;
20925
20926 Set_Has_Pragma_Pack (Base_Type (Typ));
20927 end if;
20928 end if;
20929
20930 -- For record types, the pack is always effective
20931
20932 else pragma Assert (Is_Record_Type (Typ));
20933 if not Rep_Item_Too_Late (Typ, N) then
20934 Set_Is_Packed (Base_Type (Typ));
20935 Set_Has_Pragma_Pack (Base_Type (Typ));
20936 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20937 end if;
20938 end if;
20939 end Pack;
20940
20941 ----------
20942 -- Page --
20943 ----------
20944
20945 -- pragma Page;
20946
20947 -- There is nothing to do here, since we did all the processing for
20948 -- this pragma in Par.Prag (so that it works properly even in syntax
20949 -- only mode).
20950
20951 when Pragma_Page =>
20952 null;
20953
20954 -------------
20955 -- Part_Of --
20956 -------------
20957
20958 -- pragma Part_Of (ABSTRACT_STATE);
20959
20960 -- ABSTRACT_STATE ::= NAME
20961
20962 when Pragma_Part_Of => Part_Of : declare
20963 procedure Propagate_Part_Of
20964 (Pack_Id : Entity_Id;
20965 State_Id : Entity_Id;
20966 Instance : Node_Id);
20967 -- Propagate the Part_Of indicator to all abstract states and
20968 -- objects declared in the visible state space of a package
20969 -- denoted by Pack_Id. State_Id is the encapsulating state.
20970 -- Instance is the package instantiation node.
20971
20972 -----------------------
20973 -- Propagate_Part_Of --
20974 -----------------------
20975
20976 procedure Propagate_Part_Of
20977 (Pack_Id : Entity_Id;
20978 State_Id : Entity_Id;
20979 Instance : Node_Id)
20980 is
20981 Has_Item : Boolean := False;
20982 -- Flag set when the visible state space contains at least one
20983 -- abstract state or variable.
20984
20985 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
20986 -- Propagate the Part_Of indicator to all abstract states and
20987 -- objects declared in the visible state space of a package
20988 -- denoted by Pack_Id.
20989
20990 -----------------------
20991 -- Propagate_Part_Of --
20992 -----------------------
20993
20994 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
20995 Constits : Elist_Id;
20996 Item_Id : Entity_Id;
20997
20998 begin
20999 -- Traverse the entity chain of the package and set relevant
21000 -- attributes of abstract states and objects declared in the
21001 -- visible state space of the package.
21002
21003 Item_Id := First_Entity (Pack_Id);
21004 while Present (Item_Id)
21005 and then not In_Private_Part (Item_Id)
21006 loop
21007 -- Do not consider internally generated items
21008
21009 if not Comes_From_Source (Item_Id) then
21010 null;
21011
21012 -- Do not consider generic formals or their corresponding
21013 -- actuals because they are not part of a visible state.
21014 -- Note that both entities are marked as hidden.
21015
21016 elsif Is_Hidden (Item_Id) then
21017 null;
21018
21019 -- The Part_Of indicator turns an abstract state or an
21020 -- object into a constituent of the encapsulating state.
21021 -- Note that constants are considered here even though
21022 -- they may not depend on variable input. This check is
21023 -- left to the SPARK prover.
21024
21025 elsif Ekind_In (Item_Id, E_Abstract_State,
21026 E_Constant,
21027 E_Variable)
21028 then
21029 Has_Item := True;
21030 Constits := Part_Of_Constituents (State_Id);
21031
21032 if No (Constits) then
21033 Constits := New_Elmt_List;
21034 Set_Part_Of_Constituents (State_Id, Constits);
21035 end if;
21036
21037 Append_Elmt (Item_Id, Constits);
21038 Set_Encapsulating_State (Item_Id, State_Id);
21039
21040 -- Recursively handle nested packages and instantiations
21041
21042 elsif Ekind (Item_Id) = E_Package then
21043 Propagate_Part_Of (Item_Id);
21044 end if;
21045
21046 Next_Entity (Item_Id);
21047 end loop;
21048 end Propagate_Part_Of;
21049
21050 -- Start of processing for Propagate_Part_Of
21051
21052 begin
21053 Propagate_Part_Of (Pack_Id);
21054
21055 -- Detect a package instantiation that is subject to a Part_Of
21056 -- indicator, but has no visible state.
21057
21058 if not Has_Item then
21059 SPARK_Msg_NE
21060 ("package instantiation & has Part_Of indicator but "
21061 & "lacks visible state", Instance, Pack_Id);
21062 end if;
21063 end Propagate_Part_Of;
21064
21065 -- Local variables
21066
21067 Constits : Elist_Id;
21068 Encap : Node_Id;
21069 Encap_Id : Entity_Id;
21070 Item_Id : Entity_Id;
21071 Legal : Boolean;
21072 Stmt : Node_Id;
21073
21074 -- Start of processing for Part_Of
21075
21076 begin
21077 GNAT_Pragma;
21078 Check_No_Identifiers;
21079 Check_Arg_Count (1);
21080
21081 Stmt := Find_Related_Context (N, Do_Checks => True);
21082
21083 -- Object declaration
21084
21085 if Nkind (Stmt) = N_Object_Declaration then
21086 null;
21087
21088 -- Package instantiation
21089
21090 elsif Nkind (Stmt) = N_Package_Instantiation then
21091 null;
21092
21093 -- Single concurrent type declaration
21094
21095 elsif Is_Single_Concurrent_Type_Declaration (Stmt) then
21096 null;
21097
21098 -- Otherwise the pragma is associated with an illegal construct
21099
21100 else
21101 Pragma_Misplaced;
21102 return;
21103 end if;
21104
21105 -- Extract the entity of the related object declaration or package
21106 -- instantiation. In the case of the instantiation, use the entity
21107 -- of the instance spec.
21108
21109 if Nkind (Stmt) = N_Package_Instantiation then
21110 Stmt := Instance_Spec (Stmt);
21111 end if;
21112
21113 Item_Id := Defining_Entity (Stmt);
21114
21115 -- A pragma that applies to a Ghost entity becomes Ghost for the
21116 -- purposes of legality checks and removal of ignored Ghost code.
21117
21118 Mark_Ghost_Pragma (N, Item_Id);
21119
21120 -- Chain the pragma on the contract for further processing by
21121 -- Analyze_Part_Of_In_Decl_Part or for completeness.
21122
21123 Add_Contract_Item (N, Item_Id);
21124
21125 -- A variable may act as constituent of a single concurrent type
21126 -- which in turn could be declared after the variable. Due to this
21127 -- discrepancy, the full analysis of indicator Part_Of is delayed
21128 -- until the end of the enclosing declarative region (see routine
21129 -- Analyze_Part_Of_In_Decl_Part).
21130
21131 if Ekind (Item_Id) = E_Variable then
21132 null;
21133
21134 -- Otherwise indicator Part_Of applies to a constant or a package
21135 -- instantiation.
21136
21137 else
21138 Encap := Get_Pragma_Arg (Arg1);
21139
21140 -- Detect any discrepancies between the placement of the
21141 -- constant or package instantiation with respect to state
21142 -- space and the encapsulating state.
21143
21144 Analyze_Part_Of
21145 (Indic => N,
21146 Item_Id => Item_Id,
21147 Encap => Encap,
21148 Encap_Id => Encap_Id,
21149 Legal => Legal);
21150
21151 if Legal then
21152 pragma Assert (Present (Encap_Id));
21153
21154 if Ekind (Item_Id) = E_Constant then
21155 Constits := Part_Of_Constituents (Encap_Id);
21156
21157 if No (Constits) then
21158 Constits := New_Elmt_List;
21159 Set_Part_Of_Constituents (Encap_Id, Constits);
21160 end if;
21161
21162 Append_Elmt (Item_Id, Constits);
21163 Set_Encapsulating_State (Item_Id, Encap_Id);
21164
21165 -- Propagate the Part_Of indicator to the visible state
21166 -- space of the package instantiation.
21167
21168 else
21169 Propagate_Part_Of
21170 (Pack_Id => Item_Id,
21171 State_Id => Encap_Id,
21172 Instance => Stmt);
21173 end if;
21174 end if;
21175 end if;
21176 end Part_Of;
21177
21178 ----------------------------------
21179 -- Partition_Elaboration_Policy --
21180 ----------------------------------
21181
21182 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
21183
21184 when Pragma_Partition_Elaboration_Policy => PEP : declare
21185 subtype PEP_Range is Name_Id
21186 range First_Partition_Elaboration_Policy_Name
21187 .. Last_Partition_Elaboration_Policy_Name;
21188 PEP_Val : PEP_Range;
21189 PEP : Character;
21190
21191 begin
21192 Ada_2005_Pragma;
21193 Check_Arg_Count (1);
21194 Check_No_Identifiers;
21195 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
21196 Check_Valid_Configuration_Pragma;
21197 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
21198
21199 case PEP_Val is
21200 when Name_Concurrent => PEP := 'C';
21201 when Name_Sequential => PEP := 'S';
21202 end case;
21203
21204 if Partition_Elaboration_Policy /= ' '
21205 and then Partition_Elaboration_Policy /= PEP
21206 then
21207 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
21208 Error_Pragma
21209 ("partition elaboration policy incompatible with policy#");
21210
21211 -- Set new policy, but always preserve System_Location since we
21212 -- like the error message with the run time name.
21213
21214 else
21215 Partition_Elaboration_Policy := PEP;
21216
21217 if Partition_Elaboration_Policy_Sloc /= System_Location then
21218 Partition_Elaboration_Policy_Sloc := Loc;
21219 end if;
21220 end if;
21221 end PEP;
21222
21223 -------------
21224 -- Passive --
21225 -------------
21226
21227 -- pragma Passive [(PASSIVE_FORM)];
21228
21229 -- PASSIVE_FORM ::= Semaphore | No
21230
21231 when Pragma_Passive =>
21232 GNAT_Pragma;
21233
21234 if Nkind (Parent (N)) /= N_Task_Definition then
21235 Error_Pragma ("pragma% must be within task definition");
21236 end if;
21237
21238 if Arg_Count /= 0 then
21239 Check_Arg_Count (1);
21240 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
21241 end if;
21242
21243 ----------------------------------
21244 -- Preelaborable_Initialization --
21245 ----------------------------------
21246
21247 -- pragma Preelaborable_Initialization (DIRECT_NAME);
21248
21249 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
21250 Ent : Entity_Id;
21251
21252 begin
21253 Ada_2005_Pragma;
21254 Check_Arg_Count (1);
21255 Check_No_Identifiers;
21256 Check_Arg_Is_Identifier (Arg1);
21257 Check_Arg_Is_Local_Name (Arg1);
21258 Check_First_Subtype (Arg1);
21259 Ent := Entity (Get_Pragma_Arg (Arg1));
21260
21261 -- A pragma that applies to a Ghost entity becomes Ghost for the
21262 -- purposes of legality checks and removal of ignored Ghost code.
21263
21264 Mark_Ghost_Pragma (N, Ent);
21265
21266 -- The pragma may come from an aspect on a private declaration,
21267 -- even if the freeze point at which this is analyzed in the
21268 -- private part after the full view.
21269
21270 if Has_Private_Declaration (Ent)
21271 and then From_Aspect_Specification (N)
21272 then
21273 null;
21274
21275 -- Check appropriate type argument
21276
21277 elsif Is_Private_Type (Ent)
21278 or else Is_Protected_Type (Ent)
21279 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
21280
21281 -- AI05-0028: The pragma applies to all composite types. Note
21282 -- that we apply this binding interpretation to earlier versions
21283 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
21284 -- choice since there are other compilers that do the same.
21285
21286 or else Is_Composite_Type (Ent)
21287 then
21288 null;
21289
21290 else
21291 Error_Pragma_Arg
21292 ("pragma % can only be applied to private, formal derived, "
21293 & "protected, or composite type", Arg1);
21294 end if;
21295
21296 -- Give an error if the pragma is applied to a protected type that
21297 -- does not qualify (due to having entries, or due to components
21298 -- that do not qualify).
21299
21300 if Is_Protected_Type (Ent)
21301 and then not Has_Preelaborable_Initialization (Ent)
21302 then
21303 Error_Msg_N
21304 ("protected type & does not have preelaborable "
21305 & "initialization", Ent);
21306
21307 -- Otherwise mark the type as definitely having preelaborable
21308 -- initialization.
21309
21310 else
21311 Set_Known_To_Have_Preelab_Init (Ent);
21312 end if;
21313
21314 if Has_Pragma_Preelab_Init (Ent)
21315 and then Warn_On_Redundant_Constructs
21316 then
21317 Error_Pragma ("?r?duplicate pragma%!");
21318 else
21319 Set_Has_Pragma_Preelab_Init (Ent);
21320 end if;
21321 end Preelab_Init;
21322
21323 --------------------
21324 -- Persistent_BSS --
21325 --------------------
21326
21327 -- pragma Persistent_BSS [(object_NAME)];
21328
21329 when Pragma_Persistent_BSS => Persistent_BSS : declare
21330 Decl : Node_Id;
21331 Ent : Entity_Id;
21332 Prag : Node_Id;
21333
21334 begin
21335 GNAT_Pragma;
21336 Check_At_Most_N_Arguments (1);
21337
21338 -- Case of application to specific object (one argument)
21339
21340 if Arg_Count = 1 then
21341 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21342
21343 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
21344 or else not
21345 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
21346 E_Constant)
21347 then
21348 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
21349 end if;
21350
21351 Ent := Entity (Get_Pragma_Arg (Arg1));
21352
21353 -- A pragma that applies to a Ghost entity becomes Ghost for
21354 -- the purposes of legality checks and removal of ignored Ghost
21355 -- code.
21356
21357 Mark_Ghost_Pragma (N, Ent);
21358
21359 -- Check for duplication before inserting in list of
21360 -- representation items.
21361
21362 Check_Duplicate_Pragma (Ent);
21363
21364 if Rep_Item_Too_Late (Ent, N) then
21365 return;
21366 end if;
21367
21368 Decl := Parent (Ent);
21369
21370 if Present (Expression (Decl)) then
21371 -- Variables in Persistent_BSS cannot be initialized, so
21372 -- turn off any initialization that might be caused by
21373 -- pragmas Initialize_Scalars or Normalize_Scalars.
21374
21375 if Kill_Range_Check (Expression (Decl)) then
21376 Prag :=
21377 Make_Pragma (Loc,
21378 Name_Suppress_Initialization,
21379 Pragma_Argument_Associations => New_List (
21380 Make_Pragma_Argument_Association (Loc,
21381 Expression => New_Occurrence_Of (Ent, Loc))));
21382 Insert_Before (N, Prag);
21383 Analyze (Prag);
21384
21385 else
21386 Error_Pragma_Arg
21387 ("object for pragma% cannot have initialization", Arg1);
21388 end if;
21389 end if;
21390
21391 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
21392 Error_Pragma_Arg
21393 ("object type for pragma% is not potentially persistent",
21394 Arg1);
21395 end if;
21396
21397 Prag :=
21398 Make_Linker_Section_Pragma
21399 (Ent, Loc, ".persistent.bss");
21400 Insert_After (N, Prag);
21401 Analyze (Prag);
21402
21403 -- Case of use as configuration pragma with no arguments
21404
21405 else
21406 Check_Valid_Configuration_Pragma;
21407 Persistent_BSS_Mode := True;
21408 end if;
21409 end Persistent_BSS;
21410
21411 --------------------
21412 -- Rename_Pragma --
21413 --------------------
21414
21415 -- pragma Rename_Pragma (
21416 -- [New_Name =>] IDENTIFIER,
21417 -- [Renamed =>] pragma_IDENTIFIER);
21418
21419 when Pragma_Rename_Pragma => Rename_Pragma : declare
21420 New_Name : constant Node_Id := Get_Pragma_Arg (Arg1);
21421 Old_Name : constant Node_Id := Get_Pragma_Arg (Arg2);
21422
21423 begin
21424 GNAT_Pragma;
21425 Check_Valid_Configuration_Pragma;
21426 Check_Arg_Count (2);
21427 Check_Optional_Identifier (Arg1, Name_New_Name);
21428 Check_Optional_Identifier (Arg2, Name_Renamed);
21429
21430 if Nkind (New_Name) /= N_Identifier then
21431 Error_Pragma_Arg ("identifier expected", Arg1);
21432 end if;
21433
21434 if Nkind (Old_Name) /= N_Identifier then
21435 Error_Pragma_Arg ("identifier expected", Arg2);
21436 end if;
21437
21438 -- The New_Name arg should not be an existing pragma (but we allow
21439 -- it; it's just a warning). The Old_Name arg must be an existing
21440 -- pragma.
21441
21442 if Is_Pragma_Name (Chars (New_Name)) then
21443 Error_Pragma_Arg ("??pragma is already defined", Arg1);
21444 end if;
21445
21446 if not Is_Pragma_Name (Chars (Old_Name)) then
21447 Error_Pragma_Arg ("existing pragma name expected", Arg1);
21448 end if;
21449
21450 Map_Pragma_Name (From => Chars (New_Name), To => Chars (Old_Name));
21451 end Rename_Pragma;
21452
21453 -------------
21454 -- Polling --
21455 -------------
21456
21457 -- pragma Polling (ON | OFF);
21458
21459 when Pragma_Polling =>
21460 GNAT_Pragma;
21461 Check_Arg_Count (1);
21462 Check_No_Identifiers;
21463 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
21464 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
21465
21466 -----------------------------------
21467 -- Post/Post_Class/Postcondition --
21468 -----------------------------------
21469
21470 -- pragma Post (Boolean_EXPRESSION);
21471 -- pragma Post_Class (Boolean_EXPRESSION);
21472 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
21473 -- [,[Message =>] String_EXPRESSION]);
21474
21475 -- Characteristics:
21476
21477 -- * Analysis - The annotation undergoes initial checks to verify
21478 -- the legal placement and context. Secondary checks preanalyze the
21479 -- expression in:
21480
21481 -- Analyze_Pre_Post_Condition_In_Decl_Part
21482
21483 -- * Expansion - The annotation is expanded during the expansion of
21484 -- the related subprogram [body] contract as performed in:
21485
21486 -- Expand_Subprogram_Contract
21487
21488 -- * Template - The annotation utilizes the generic template of the
21489 -- related subprogram [body] when it is:
21490
21491 -- aspect on subprogram declaration
21492 -- aspect on stand-alone subprogram body
21493 -- pragma on stand-alone subprogram body
21494
21495 -- The annotation must prepare its own template when it is:
21496
21497 -- pragma on subprogram declaration
21498
21499 -- * Globals - Capture of global references must occur after full
21500 -- analysis.
21501
21502 -- * Instance - The annotation is instantiated automatically when
21503 -- the related generic subprogram [body] is instantiated except for
21504 -- the "pragma on subprogram declaration" case. In that scenario
21505 -- the annotation must instantiate itself.
21506
21507 when Pragma_Post
21508 | Pragma_Post_Class
21509 | Pragma_Postcondition
21510 =>
21511 Analyze_Pre_Post_Condition;
21512
21513 --------------------------------
21514 -- Pre/Pre_Class/Precondition --
21515 --------------------------------
21516
21517 -- pragma Pre (Boolean_EXPRESSION);
21518 -- pragma Pre_Class (Boolean_EXPRESSION);
21519 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
21520 -- [,[Message =>] String_EXPRESSION]);
21521
21522 -- Characteristics:
21523
21524 -- * Analysis - The annotation undergoes initial checks to verify
21525 -- the legal placement and context. Secondary checks preanalyze the
21526 -- expression in:
21527
21528 -- Analyze_Pre_Post_Condition_In_Decl_Part
21529
21530 -- * Expansion - The annotation is expanded during the expansion of
21531 -- the related subprogram [body] contract as performed in:
21532
21533 -- Expand_Subprogram_Contract
21534
21535 -- * Template - The annotation utilizes the generic template of the
21536 -- related subprogram [body] when it is:
21537
21538 -- aspect on subprogram declaration
21539 -- aspect on stand-alone subprogram body
21540 -- pragma on stand-alone subprogram body
21541
21542 -- The annotation must prepare its own template when it is:
21543
21544 -- pragma on subprogram declaration
21545
21546 -- * Globals - Capture of global references must occur after full
21547 -- analysis.
21548
21549 -- * Instance - The annotation is instantiated automatically when
21550 -- the related generic subprogram [body] is instantiated except for
21551 -- the "pragma on subprogram declaration" case. In that scenario
21552 -- the annotation must instantiate itself.
21553
21554 when Pragma_Pre
21555 | Pragma_Pre_Class
21556 | Pragma_Precondition
21557 =>
21558 Analyze_Pre_Post_Condition;
21559
21560 ---------------
21561 -- Predicate --
21562 ---------------
21563
21564 -- pragma Predicate
21565 -- ([Entity =>] type_LOCAL_NAME,
21566 -- [Check =>] boolean_EXPRESSION);
21567
21568 when Pragma_Predicate => Predicate : declare
21569 Discard : Boolean;
21570 Typ : Entity_Id;
21571 Type_Id : Node_Id;
21572
21573 begin
21574 GNAT_Pragma;
21575 Check_Arg_Count (2);
21576 Check_Optional_Identifier (Arg1, Name_Entity);
21577 Check_Optional_Identifier (Arg2, Name_Check);
21578
21579 Check_Arg_Is_Local_Name (Arg1);
21580
21581 Type_Id := Get_Pragma_Arg (Arg1);
21582 Find_Type (Type_Id);
21583 Typ := Entity (Type_Id);
21584
21585 if Typ = Any_Type then
21586 return;
21587 end if;
21588
21589 -- A pragma that applies to a Ghost entity becomes Ghost for the
21590 -- purposes of legality checks and removal of ignored Ghost code.
21591
21592 Mark_Ghost_Pragma (N, Typ);
21593
21594 -- The remaining processing is simply to link the pragma on to
21595 -- the rep item chain, for processing when the type is frozen.
21596 -- This is accomplished by a call to Rep_Item_Too_Late. We also
21597 -- mark the type as having predicates.
21598
21599 -- If the current policy for predicate checking is Ignore mark the
21600 -- subtype accordingly. In the case of predicates we consider them
21601 -- enabled unless Ignore is specified (either directly or with a
21602 -- general Assertion_Policy pragma) to preserve existing warnings.
21603
21604 Set_Has_Predicates (Typ);
21605
21606 -- Indicate that the pragma must be processed at the point the
21607 -- type is frozen, as is done for the corresponding aspect.
21608
21609 Set_Has_Delayed_Aspects (Typ);
21610 Set_Has_Delayed_Freeze (Typ);
21611
21612 Set_Predicates_Ignored (Typ,
21613 Present (Check_Policy_List)
21614 and then
21615 Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore);
21616 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
21617 end Predicate;
21618
21619 -----------------------
21620 -- Predicate_Failure --
21621 -----------------------
21622
21623 -- pragma Predicate_Failure
21624 -- ([Entity =>] type_LOCAL_NAME,
21625 -- [Message =>] string_EXPRESSION);
21626
21627 when Pragma_Predicate_Failure => Predicate_Failure : declare
21628 Discard : Boolean;
21629 Typ : Entity_Id;
21630 Type_Id : Node_Id;
21631
21632 begin
21633 GNAT_Pragma;
21634 Check_Arg_Count (2);
21635 Check_Optional_Identifier (Arg1, Name_Entity);
21636 Check_Optional_Identifier (Arg2, Name_Message);
21637
21638 Check_Arg_Is_Local_Name (Arg1);
21639
21640 Type_Id := Get_Pragma_Arg (Arg1);
21641 Find_Type (Type_Id);
21642 Typ := Entity (Type_Id);
21643
21644 if Typ = Any_Type then
21645 return;
21646 end if;
21647
21648 -- A pragma that applies to a Ghost entity becomes Ghost for the
21649 -- purposes of legality checks and removal of ignored Ghost code.
21650
21651 Mark_Ghost_Pragma (N, Typ);
21652
21653 -- The remaining processing is simply to link the pragma on to
21654 -- the rep item chain, for processing when the type is frozen.
21655 -- This is accomplished by a call to Rep_Item_Too_Late.
21656
21657 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
21658 end Predicate_Failure;
21659
21660 ------------------
21661 -- Preelaborate --
21662 ------------------
21663
21664 -- pragma Preelaborate [(library_unit_NAME)];
21665
21666 -- Set the flag Is_Preelaborated of program unit name entity
21667
21668 when Pragma_Preelaborate => Preelaborate : declare
21669 Pa : constant Node_Id := Parent (N);
21670 Pk : constant Node_Kind := Nkind (Pa);
21671 Ent : Entity_Id;
21672
21673 begin
21674 Check_Ada_83_Warning;
21675 Check_Valid_Library_Unit_Pragma;
21676
21677 if Nkind (N) = N_Null_Statement then
21678 return;
21679 end if;
21680
21681 Ent := Find_Lib_Unit_Name;
21682
21683 -- A pragma that applies to a Ghost entity becomes Ghost for the
21684 -- purposes of legality checks and removal of ignored Ghost code.
21685
21686 Mark_Ghost_Pragma (N, Ent);
21687 Check_Duplicate_Pragma (Ent);
21688
21689 -- This filters out pragmas inside generic parents that show up
21690 -- inside instantiations. Pragmas that come from aspects in the
21691 -- unit are not ignored.
21692
21693 if Present (Ent) then
21694 if Pk = N_Package_Specification
21695 and then Present (Generic_Parent (Pa))
21696 and then not From_Aspect_Specification (N)
21697 then
21698 null;
21699
21700 else
21701 if not Debug_Flag_U then
21702 Set_Is_Preelaborated (Ent);
21703
21704 if Legacy_Elaboration_Checks then
21705 Set_Suppress_Elaboration_Warnings (Ent);
21706 end if;
21707 end if;
21708 end if;
21709 end if;
21710 end Preelaborate;
21711
21712 -------------------------------
21713 -- Prefix_Exception_Messages --
21714 -------------------------------
21715
21716 -- pragma Prefix_Exception_Messages;
21717
21718 when Pragma_Prefix_Exception_Messages =>
21719 GNAT_Pragma;
21720 Check_Valid_Configuration_Pragma;
21721 Check_Arg_Count (0);
21722 Prefix_Exception_Messages := True;
21723
21724 --------------
21725 -- Priority --
21726 --------------
21727
21728 -- pragma Priority (EXPRESSION);
21729
21730 when Pragma_Priority => Priority : declare
21731 P : constant Node_Id := Parent (N);
21732 Arg : Node_Id;
21733 Ent : Entity_Id;
21734
21735 begin
21736 Check_No_Identifiers;
21737 Check_Arg_Count (1);
21738
21739 -- Subprogram case
21740
21741 if Nkind (P) = N_Subprogram_Body then
21742 Check_In_Main_Program;
21743
21744 Ent := Defining_Unit_Name (Specification (P));
21745
21746 if Nkind (Ent) = N_Defining_Program_Unit_Name then
21747 Ent := Defining_Identifier (Ent);
21748 end if;
21749
21750 Arg := Get_Pragma_Arg (Arg1);
21751 Analyze_And_Resolve (Arg, Standard_Integer);
21752
21753 -- Must be static
21754
21755 if not Is_OK_Static_Expression (Arg) then
21756 Flag_Non_Static_Expr
21757 ("main subprogram priority is not static!", Arg);
21758 raise Pragma_Exit;
21759
21760 -- If constraint error, then we already signalled an error
21761
21762 elsif Raises_Constraint_Error (Arg) then
21763 null;
21764
21765 -- Otherwise check in range except if Relaxed_RM_Semantics
21766 -- where we ignore the value if out of range.
21767
21768 else
21769 if not Relaxed_RM_Semantics
21770 and then not Is_In_Range (Arg, RTE (RE_Priority))
21771 then
21772 Error_Pragma_Arg
21773 ("main subprogram priority is out of range", Arg1);
21774 else
21775 Set_Main_Priority
21776 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
21777 end if;
21778 end if;
21779
21780 -- Load an arbitrary entity from System.Tasking.Stages or
21781 -- System.Tasking.Restricted.Stages (depending on the
21782 -- supported profile) to make sure that one of these packages
21783 -- is implicitly with'ed, since we need to have the tasking
21784 -- run time active for the pragma Priority to have any effect.
21785 -- Previously we with'ed the package System.Tasking, but this
21786 -- package does not trigger the required initialization of the
21787 -- run-time library.
21788
21789 declare
21790 Discard : Entity_Id;
21791 pragma Warnings (Off, Discard);
21792 begin
21793 if Restricted_Profile then
21794 Discard := RTE (RE_Activate_Restricted_Tasks);
21795 else
21796 Discard := RTE (RE_Activate_Tasks);
21797 end if;
21798 end;
21799
21800 -- Task or Protected, must be of type Integer
21801
21802 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
21803 Arg := Get_Pragma_Arg (Arg1);
21804 Ent := Defining_Identifier (Parent (P));
21805
21806 -- The expression must be analyzed in the special manner
21807 -- described in "Handling of Default and Per-Object
21808 -- Expressions" in sem.ads.
21809
21810 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
21811
21812 if not Is_OK_Static_Expression (Arg) then
21813 Check_Restriction (Static_Priorities, Arg);
21814 end if;
21815
21816 -- Anything else is incorrect
21817
21818 else
21819 Pragma_Misplaced;
21820 end if;
21821
21822 -- Check duplicate pragma before we chain the pragma in the Rep
21823 -- Item chain of Ent.
21824
21825 Check_Duplicate_Pragma (Ent);
21826 Record_Rep_Item (Ent, N);
21827 end Priority;
21828
21829 -----------------------------------
21830 -- Priority_Specific_Dispatching --
21831 -----------------------------------
21832
21833 -- pragma Priority_Specific_Dispatching (
21834 -- policy_IDENTIFIER,
21835 -- first_priority_EXPRESSION,
21836 -- last_priority_EXPRESSION);
21837
21838 when Pragma_Priority_Specific_Dispatching =>
21839 Priority_Specific_Dispatching : declare
21840 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
21841 -- This is the entity System.Any_Priority;
21842
21843 DP : Character;
21844 Lower_Bound : Node_Id;
21845 Upper_Bound : Node_Id;
21846 Lower_Val : Uint;
21847 Upper_Val : Uint;
21848
21849 begin
21850 Ada_2005_Pragma;
21851 Check_Arg_Count (3);
21852 Check_No_Identifiers;
21853 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
21854 Check_Valid_Configuration_Pragma;
21855 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21856 DP := Fold_Upper (Name_Buffer (1));
21857
21858 Lower_Bound := Get_Pragma_Arg (Arg2);
21859 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
21860 Lower_Val := Expr_Value (Lower_Bound);
21861
21862 Upper_Bound := Get_Pragma_Arg (Arg3);
21863 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
21864 Upper_Val := Expr_Value (Upper_Bound);
21865
21866 -- It is not allowed to use Task_Dispatching_Policy and
21867 -- Priority_Specific_Dispatching in the same partition.
21868
21869 if Task_Dispatching_Policy /= ' ' then
21870 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21871 Error_Pragma
21872 ("pragma% incompatible with Task_Dispatching_Policy#");
21873
21874 -- Check lower bound in range
21875
21876 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21877 or else
21878 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
21879 then
21880 Error_Pragma_Arg
21881 ("first_priority is out of range", Arg2);
21882
21883 -- Check upper bound in range
21884
21885 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21886 or else
21887 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
21888 then
21889 Error_Pragma_Arg
21890 ("last_priority is out of range", Arg3);
21891
21892 -- Check that the priority range is valid
21893
21894 elsif Lower_Val > Upper_Val then
21895 Error_Pragma
21896 ("last_priority_expression must be greater than or equal to "
21897 & "first_priority_expression");
21898
21899 -- Store the new policy, but always preserve System_Location since
21900 -- we like the error message with the run-time name.
21901
21902 else
21903 -- Check overlapping in the priority ranges specified in other
21904 -- Priority_Specific_Dispatching pragmas within the same
21905 -- partition. We can only check those we know about.
21906
21907 for J in
21908 Specific_Dispatching.First .. Specific_Dispatching.Last
21909 loop
21910 if Specific_Dispatching.Table (J).First_Priority in
21911 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21912 or else Specific_Dispatching.Table (J).Last_Priority in
21913 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21914 then
21915 Error_Msg_Sloc :=
21916 Specific_Dispatching.Table (J).Pragma_Loc;
21917 Error_Pragma
21918 ("priority range overlaps with "
21919 & "Priority_Specific_Dispatching#");
21920 end if;
21921 end loop;
21922
21923 -- The use of Priority_Specific_Dispatching is incompatible
21924 -- with Task_Dispatching_Policy.
21925
21926 if Task_Dispatching_Policy /= ' ' then
21927 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21928 Error_Pragma
21929 ("Priority_Specific_Dispatching incompatible "
21930 & "with Task_Dispatching_Policy#");
21931 end if;
21932
21933 -- The use of Priority_Specific_Dispatching forces ceiling
21934 -- locking policy.
21935
21936 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
21937 Error_Msg_Sloc := Locking_Policy_Sloc;
21938 Error_Pragma
21939 ("Priority_Specific_Dispatching incompatible "
21940 & "with Locking_Policy#");
21941
21942 -- Set the Ceiling_Locking policy, but preserve System_Location
21943 -- since we like the error message with the run time name.
21944
21945 else
21946 Locking_Policy := 'C';
21947
21948 if Locking_Policy_Sloc /= System_Location then
21949 Locking_Policy_Sloc := Loc;
21950 end if;
21951 end if;
21952
21953 -- Add entry in the table
21954
21955 Specific_Dispatching.Append
21956 ((Dispatching_Policy => DP,
21957 First_Priority => UI_To_Int (Lower_Val),
21958 Last_Priority => UI_To_Int (Upper_Val),
21959 Pragma_Loc => Loc));
21960 end if;
21961 end Priority_Specific_Dispatching;
21962
21963 -------------
21964 -- Profile --
21965 -------------
21966
21967 -- pragma Profile (profile_IDENTIFIER);
21968
21969 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
21970
21971 when Pragma_Profile =>
21972 Ada_2005_Pragma;
21973 Check_Arg_Count (1);
21974 Check_Valid_Configuration_Pragma;
21975 Check_No_Identifiers;
21976
21977 declare
21978 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21979
21980 begin
21981 if Chars (Argx) = Name_Ravenscar then
21982 Set_Ravenscar_Profile (Ravenscar, N);
21983
21984 elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then
21985 Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N);
21986
21987 elsif Chars (Argx) = Name_Gnat_Ravenscar_EDF then
21988 Set_Ravenscar_Profile (GNAT_Ravenscar_EDF, N);
21989
21990 elsif Chars (Argx) = Name_Restricted then
21991 Set_Profile_Restrictions
21992 (Restricted,
21993 N, Warn => Treat_Restrictions_As_Warnings);
21994
21995 elsif Chars (Argx) = Name_Rational then
21996 Set_Rational_Profile;
21997
21998 elsif Chars (Argx) = Name_No_Implementation_Extensions then
21999 Set_Profile_Restrictions
22000 (No_Implementation_Extensions,
22001 N, Warn => Treat_Restrictions_As_Warnings);
22002
22003 else
22004 Error_Pragma_Arg ("& is not a valid profile", Argx);
22005 end if;
22006 end;
22007
22008 ----------------------
22009 -- Profile_Warnings --
22010 ----------------------
22011
22012 -- pragma Profile_Warnings (profile_IDENTIFIER);
22013
22014 -- profile_IDENTIFIER => Restricted | Ravenscar
22015
22016 when Pragma_Profile_Warnings =>
22017 GNAT_Pragma;
22018 Check_Arg_Count (1);
22019 Check_Valid_Configuration_Pragma;
22020 Check_No_Identifiers;
22021
22022 declare
22023 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
22024
22025 begin
22026 if Chars (Argx) = Name_Ravenscar then
22027 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
22028
22029 elsif Chars (Argx) = Name_Restricted then
22030 Set_Profile_Restrictions (Restricted, N, Warn => True);
22031
22032 elsif Chars (Argx) = Name_No_Implementation_Extensions then
22033 Set_Profile_Restrictions
22034 (No_Implementation_Extensions, N, Warn => True);
22035
22036 else
22037 Error_Pragma_Arg ("& is not a valid profile", Argx);
22038 end if;
22039 end;
22040
22041 --------------------------
22042 -- Propagate_Exceptions --
22043 --------------------------
22044
22045 -- pragma Propagate_Exceptions;
22046
22047 -- Note: this pragma is obsolete and has no effect
22048
22049 when Pragma_Propagate_Exceptions =>
22050 GNAT_Pragma;
22051 Check_Arg_Count (0);
22052
22053 if Warn_On_Obsolescent_Feature then
22054 Error_Msg_N
22055 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
22056 "and has no effect?j?", N);
22057 end if;
22058
22059 -----------------------------
22060 -- Provide_Shift_Operators --
22061 -----------------------------
22062
22063 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
22064
22065 when Pragma_Provide_Shift_Operators =>
22066 Provide_Shift_Operators : declare
22067 Ent : Entity_Id;
22068
22069 procedure Declare_Shift_Operator (Nam : Name_Id);
22070 -- Insert declaration and pragma Instrinsic for named shift op
22071
22072 ----------------------------
22073 -- Declare_Shift_Operator --
22074 ----------------------------
22075
22076 procedure Declare_Shift_Operator (Nam : Name_Id) is
22077 Func : Node_Id;
22078 Import : Node_Id;
22079
22080 begin
22081 Func :=
22082 Make_Subprogram_Declaration (Loc,
22083 Make_Function_Specification (Loc,
22084 Defining_Unit_Name =>
22085 Make_Defining_Identifier (Loc, Chars => Nam),
22086
22087 Result_Definition =>
22088 Make_Identifier (Loc, Chars => Chars (Ent)),
22089
22090 Parameter_Specifications => New_List (
22091 Make_Parameter_Specification (Loc,
22092 Defining_Identifier =>
22093 Make_Defining_Identifier (Loc, Name_Value),
22094 Parameter_Type =>
22095 Make_Identifier (Loc, Chars => Chars (Ent))),
22096
22097 Make_Parameter_Specification (Loc,
22098 Defining_Identifier =>
22099 Make_Defining_Identifier (Loc, Name_Amount),
22100 Parameter_Type =>
22101 New_Occurrence_Of (Standard_Natural, Loc)))));
22102
22103 Import :=
22104 Make_Pragma (Loc,
22105 Chars => Name_Import,
22106 Pragma_Argument_Associations => New_List (
22107 Make_Pragma_Argument_Association (Loc,
22108 Expression => Make_Identifier (Loc, Name_Intrinsic)),
22109 Make_Pragma_Argument_Association (Loc,
22110 Expression => Make_Identifier (Loc, Nam))));
22111
22112 Insert_After (N, Import);
22113 Insert_After (N, Func);
22114 end Declare_Shift_Operator;
22115
22116 -- Start of processing for Provide_Shift_Operators
22117
22118 begin
22119 GNAT_Pragma;
22120 Check_Arg_Count (1);
22121 Check_Arg_Is_Local_Name (Arg1);
22122
22123 Arg1 := Get_Pragma_Arg (Arg1);
22124
22125 -- We must have an entity name
22126
22127 if not Is_Entity_Name (Arg1) then
22128 Error_Pragma_Arg
22129 ("pragma % must apply to integer first subtype", Arg1);
22130 end if;
22131
22132 -- If no Entity, means there was a prior error so ignore
22133
22134 if Present (Entity (Arg1)) then
22135 Ent := Entity (Arg1);
22136
22137 -- Apply error checks
22138
22139 if not Is_First_Subtype (Ent) then
22140 Error_Pragma_Arg
22141 ("cannot apply pragma %",
22142 "\& is not a first subtype",
22143 Arg1);
22144
22145 elsif not Is_Integer_Type (Ent) then
22146 Error_Pragma_Arg
22147 ("cannot apply pragma %",
22148 "\& is not an integer type",
22149 Arg1);
22150
22151 elsif Has_Shift_Operator (Ent) then
22152 Error_Pragma_Arg
22153 ("cannot apply pragma %",
22154 "\& already has declared shift operators",
22155 Arg1);
22156
22157 elsif Is_Frozen (Ent) then
22158 Error_Pragma_Arg
22159 ("pragma % appears too late",
22160 "\& is already frozen",
22161 Arg1);
22162 end if;
22163
22164 -- Now declare the operators. We do this during analysis rather
22165 -- than expansion, since we want the operators available if we
22166 -- are operating in -gnatc mode.
22167
22168 Declare_Shift_Operator (Name_Rotate_Left);
22169 Declare_Shift_Operator (Name_Rotate_Right);
22170 Declare_Shift_Operator (Name_Shift_Left);
22171 Declare_Shift_Operator (Name_Shift_Right);
22172 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
22173 end if;
22174 end Provide_Shift_Operators;
22175
22176 ------------------
22177 -- Psect_Object --
22178 ------------------
22179
22180 -- pragma Psect_Object (
22181 -- [Internal =>] LOCAL_NAME,
22182 -- [, [External =>] EXTERNAL_SYMBOL]
22183 -- [, [Size =>] EXTERNAL_SYMBOL]);
22184
22185 when Pragma_Common_Object
22186 | Pragma_Psect_Object
22187 =>
22188 Psect_Object : declare
22189 Args : Args_List (1 .. 3);
22190 Names : constant Name_List (1 .. 3) := (
22191 Name_Internal,
22192 Name_External,
22193 Name_Size);
22194
22195 Internal : Node_Id renames Args (1);
22196 External : Node_Id renames Args (2);
22197 Size : Node_Id renames Args (3);
22198
22199 Def_Id : Entity_Id;
22200
22201 procedure Check_Arg (Arg : Node_Id);
22202 -- Checks that argument is either a string literal or an
22203 -- identifier, and posts error message if not.
22204
22205 ---------------
22206 -- Check_Arg --
22207 ---------------
22208
22209 procedure Check_Arg (Arg : Node_Id) is
22210 begin
22211 if not Nkind_In (Original_Node (Arg),
22212 N_String_Literal,
22213 N_Identifier)
22214 then
22215 Error_Pragma_Arg
22216 ("inappropriate argument for pragma %", Arg);
22217 end if;
22218 end Check_Arg;
22219
22220 -- Start of processing for Common_Object/Psect_Object
22221
22222 begin
22223 GNAT_Pragma;
22224 Gather_Associations (Names, Args);
22225 Process_Extended_Import_Export_Internal_Arg (Internal);
22226
22227 Def_Id := Entity (Internal);
22228
22229 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
22230 Error_Pragma_Arg
22231 ("pragma% must designate an object", Internal);
22232 end if;
22233
22234 Check_Arg (Internal);
22235
22236 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
22237 Error_Pragma_Arg
22238 ("cannot use pragma% for imported/exported object",
22239 Internal);
22240 end if;
22241
22242 if Is_Concurrent_Type (Etype (Internal)) then
22243 Error_Pragma_Arg
22244 ("cannot specify pragma % for task/protected object",
22245 Internal);
22246 end if;
22247
22248 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
22249 or else
22250 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
22251 then
22252 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
22253 end if;
22254
22255 if Ekind (Def_Id) = E_Constant then
22256 Error_Pragma_Arg
22257 ("cannot specify pragma % for a constant", Internal);
22258 end if;
22259
22260 if Is_Record_Type (Etype (Internal)) then
22261 declare
22262 Ent : Entity_Id;
22263 Decl : Entity_Id;
22264
22265 begin
22266 Ent := First_Entity (Etype (Internal));
22267 while Present (Ent) loop
22268 Decl := Declaration_Node (Ent);
22269
22270 if Ekind (Ent) = E_Component
22271 and then Nkind (Decl) = N_Component_Declaration
22272 and then Present (Expression (Decl))
22273 and then Warn_On_Export_Import
22274 then
22275 Error_Msg_N
22276 ("?x?object for pragma % has defaults", Internal);
22277 exit;
22278
22279 else
22280 Next_Entity (Ent);
22281 end if;
22282 end loop;
22283 end;
22284 end if;
22285
22286 if Present (Size) then
22287 Check_Arg (Size);
22288 end if;
22289
22290 if Present (External) then
22291 Check_Arg_Is_External_Name (External);
22292 end if;
22293
22294 -- If all error tests pass, link pragma on to the rep item chain
22295
22296 Record_Rep_Item (Def_Id, N);
22297 end Psect_Object;
22298
22299 ----------
22300 -- Pure --
22301 ----------
22302
22303 -- pragma Pure [(library_unit_NAME)];
22304
22305 when Pragma_Pure => Pure : declare
22306 Ent : Entity_Id;
22307
22308 begin
22309 Check_Ada_83_Warning;
22310
22311 -- If the pragma comes from a subprogram instantiation, nothing to
22312 -- check, this can happen at any level of nesting.
22313
22314 if Is_Wrapper_Package (Current_Scope) then
22315 return;
22316 else
22317 Check_Valid_Library_Unit_Pragma;
22318 end if;
22319
22320 if Nkind (N) = N_Null_Statement then
22321 return;
22322 end if;
22323
22324 Ent := Find_Lib_Unit_Name;
22325
22326 -- A pragma that applies to a Ghost entity becomes Ghost for the
22327 -- purposes of legality checks and removal of ignored Ghost code.
22328
22329 Mark_Ghost_Pragma (N, Ent);
22330
22331 if not Debug_Flag_U then
22332 Set_Is_Pure (Ent);
22333 Set_Has_Pragma_Pure (Ent);
22334
22335 if Legacy_Elaboration_Checks then
22336 Set_Suppress_Elaboration_Warnings (Ent);
22337 end if;
22338 end if;
22339 end Pure;
22340
22341 -------------------
22342 -- Pure_Function --
22343 -------------------
22344
22345 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
22346
22347 when Pragma_Pure_Function => Pure_Function : declare
22348 Def_Id : Entity_Id;
22349 E : Entity_Id;
22350 E_Id : Node_Id;
22351 Effective : Boolean := False;
22352 Orig_Def : Entity_Id;
22353 Same_Decl : Boolean := False;
22354
22355 begin
22356 GNAT_Pragma;
22357 Check_Arg_Count (1);
22358 Check_Optional_Identifier (Arg1, Name_Entity);
22359 Check_Arg_Is_Local_Name (Arg1);
22360 E_Id := Get_Pragma_Arg (Arg1);
22361
22362 if Etype (E_Id) = Any_Type then
22363 return;
22364 end if;
22365
22366 -- Loop through homonyms (overloadings) of referenced entity
22367
22368 E := Entity (E_Id);
22369
22370 -- A pragma that applies to a Ghost entity becomes Ghost for the
22371 -- purposes of legality checks and removal of ignored Ghost code.
22372
22373 Mark_Ghost_Pragma (N, E);
22374
22375 if Present (E) then
22376 loop
22377 Def_Id := Get_Base_Subprogram (E);
22378
22379 if not Ekind_In (Def_Id, E_Function,
22380 E_Generic_Function,
22381 E_Operator)
22382 then
22383 Error_Pragma_Arg
22384 ("pragma% requires a function name", Arg1);
22385 end if;
22386
22387 -- When we have a generic function we must jump up a level
22388 -- to the declaration of the wrapper package itself.
22389
22390 Orig_Def := Def_Id;
22391
22392 if Is_Generic_Instance (Def_Id) then
22393 while Nkind (Orig_Def) /= N_Package_Declaration loop
22394 Orig_Def := Parent (Orig_Def);
22395 end loop;
22396 end if;
22397
22398 if In_Same_Declarative_Part (Parent (N), Orig_Def) then
22399 Same_Decl := True;
22400 Set_Is_Pure (Def_Id);
22401
22402 if not Has_Pragma_Pure_Function (Def_Id) then
22403 Set_Has_Pragma_Pure_Function (Def_Id);
22404 Effective := True;
22405 end if;
22406 end if;
22407
22408 exit when From_Aspect_Specification (N);
22409 E := Homonym (E);
22410 exit when No (E) or else Scope (E) /= Current_Scope;
22411 end loop;
22412
22413 if not Effective
22414 and then Warn_On_Redundant_Constructs
22415 then
22416 Error_Msg_NE
22417 ("pragma Pure_Function on& is redundant?r?",
22418 N, Entity (E_Id));
22419
22420 elsif not Same_Decl then
22421 Error_Pragma_Arg
22422 ("pragma% argument must be in same declarative part",
22423 Arg1);
22424 end if;
22425 end if;
22426 end Pure_Function;
22427
22428 --------------------
22429 -- Queuing_Policy --
22430 --------------------
22431
22432 -- pragma Queuing_Policy (policy_IDENTIFIER);
22433
22434 when Pragma_Queuing_Policy => declare
22435 QP : Character;
22436
22437 begin
22438 Check_Ada_83_Warning;
22439 Check_Arg_Count (1);
22440 Check_No_Identifiers;
22441 Check_Arg_Is_Queuing_Policy (Arg1);
22442 Check_Valid_Configuration_Pragma;
22443 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
22444 QP := Fold_Upper (Name_Buffer (1));
22445
22446 if Queuing_Policy /= ' '
22447 and then Queuing_Policy /= QP
22448 then
22449 Error_Msg_Sloc := Queuing_Policy_Sloc;
22450 Error_Pragma ("queuing policy incompatible with policy#");
22451
22452 -- Set new policy, but always preserve System_Location since we
22453 -- like the error message with the run time name.
22454
22455 else
22456 Queuing_Policy := QP;
22457
22458 if Queuing_Policy_Sloc /= System_Location then
22459 Queuing_Policy_Sloc := Loc;
22460 end if;
22461 end if;
22462 end;
22463
22464 --------------
22465 -- Rational --
22466 --------------
22467
22468 -- pragma Rational, for compatibility with foreign compiler
22469
22470 when Pragma_Rational =>
22471 Set_Rational_Profile;
22472
22473 ---------------------
22474 -- Refined_Depends --
22475 ---------------------
22476
22477 -- pragma Refined_Depends (DEPENDENCY_RELATION);
22478
22479 -- DEPENDENCY_RELATION ::=
22480 -- null
22481 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
22482
22483 -- DEPENDENCY_CLAUSE ::=
22484 -- OUTPUT_LIST =>[+] INPUT_LIST
22485 -- | NULL_DEPENDENCY_CLAUSE
22486
22487 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
22488
22489 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
22490
22491 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
22492
22493 -- OUTPUT ::= NAME | FUNCTION_RESULT
22494 -- INPUT ::= NAME
22495
22496 -- where FUNCTION_RESULT is a function Result attribute_reference
22497
22498 -- Characteristics:
22499
22500 -- * Analysis - The annotation undergoes initial checks to verify
22501 -- the legal placement and context. Secondary checks fully analyze
22502 -- the dependency clauses/global list in:
22503
22504 -- Analyze_Refined_Depends_In_Decl_Part
22505
22506 -- * Expansion - None.
22507
22508 -- * Template - The annotation utilizes the generic template of the
22509 -- related subprogram body.
22510
22511 -- * Globals - Capture of global references must occur after full
22512 -- analysis.
22513
22514 -- * Instance - The annotation is instantiated automatically when
22515 -- the related generic subprogram body is instantiated.
22516
22517 when Pragma_Refined_Depends => Refined_Depends : declare
22518 Body_Id : Entity_Id;
22519 Legal : Boolean;
22520 Spec_Id : Entity_Id;
22521
22522 begin
22523 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22524
22525 if Legal then
22526
22527 -- Chain the pragma on the contract for further processing by
22528 -- Analyze_Refined_Depends_In_Decl_Part.
22529
22530 Add_Contract_Item (N, Body_Id);
22531
22532 -- The legality checks of pragmas Refined_Depends and
22533 -- Refined_Global are affected by the SPARK mode in effect and
22534 -- the volatility of the context. In addition these two pragmas
22535 -- are subject to an inherent order:
22536
22537 -- 1) Refined_Global
22538 -- 2) Refined_Depends
22539
22540 -- Analyze all these pragmas in the order outlined above
22541
22542 Analyze_If_Present (Pragma_SPARK_Mode);
22543 Analyze_If_Present (Pragma_Volatile_Function);
22544 Analyze_If_Present (Pragma_Refined_Global);
22545 Analyze_Refined_Depends_In_Decl_Part (N);
22546 end if;
22547 end Refined_Depends;
22548
22549 --------------------
22550 -- Refined_Global --
22551 --------------------
22552
22553 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
22554
22555 -- GLOBAL_SPECIFICATION ::=
22556 -- null
22557 -- | (GLOBAL_LIST)
22558 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
22559
22560 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
22561
22562 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
22563 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
22564 -- GLOBAL_ITEM ::= NAME
22565
22566 -- Characteristics:
22567
22568 -- * Analysis - The annotation undergoes initial checks to verify
22569 -- the legal placement and context. Secondary checks fully analyze
22570 -- the dependency clauses/global list in:
22571
22572 -- Analyze_Refined_Global_In_Decl_Part
22573
22574 -- * Expansion - None.
22575
22576 -- * Template - The annotation utilizes the generic template of the
22577 -- related subprogram body.
22578
22579 -- * Globals - Capture of global references must occur after full
22580 -- analysis.
22581
22582 -- * Instance - The annotation is instantiated automatically when
22583 -- the related generic subprogram body is instantiated.
22584
22585 when Pragma_Refined_Global => Refined_Global : declare
22586 Body_Id : Entity_Id;
22587 Legal : Boolean;
22588 Spec_Id : Entity_Id;
22589
22590 begin
22591 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22592
22593 if Legal then
22594
22595 -- Chain the pragma on the contract for further processing by
22596 -- Analyze_Refined_Global_In_Decl_Part.
22597
22598 Add_Contract_Item (N, Body_Id);
22599
22600 -- The legality checks of pragmas Refined_Depends and
22601 -- Refined_Global are affected by the SPARK mode in effect and
22602 -- the volatility of the context. In addition these two pragmas
22603 -- are subject to an inherent order:
22604
22605 -- 1) Refined_Global
22606 -- 2) Refined_Depends
22607
22608 -- Analyze all these pragmas in the order outlined above
22609
22610 Analyze_If_Present (Pragma_SPARK_Mode);
22611 Analyze_If_Present (Pragma_Volatile_Function);
22612 Analyze_Refined_Global_In_Decl_Part (N);
22613 Analyze_If_Present (Pragma_Refined_Depends);
22614 end if;
22615 end Refined_Global;
22616
22617 ------------------
22618 -- Refined_Post --
22619 ------------------
22620
22621 -- pragma Refined_Post (boolean_EXPRESSION);
22622
22623 -- Characteristics:
22624
22625 -- * Analysis - The annotation is fully analyzed immediately upon
22626 -- elaboration as it cannot forward reference entities.
22627
22628 -- * Expansion - The annotation is expanded during the expansion of
22629 -- the related subprogram body contract as performed in:
22630
22631 -- Expand_Subprogram_Contract
22632
22633 -- * Template - The annotation utilizes the generic template of the
22634 -- related subprogram body.
22635
22636 -- * Globals - Capture of global references must occur after full
22637 -- analysis.
22638
22639 -- * Instance - The annotation is instantiated automatically when
22640 -- the related generic subprogram body is instantiated.
22641
22642 when Pragma_Refined_Post => Refined_Post : declare
22643 Body_Id : Entity_Id;
22644 Legal : Boolean;
22645 Spec_Id : Entity_Id;
22646
22647 begin
22648 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22649
22650 -- Fully analyze the pragma when it appears inside a subprogram
22651 -- body because it cannot benefit from forward references.
22652
22653 if Legal then
22654
22655 -- Chain the pragma on the contract for completeness
22656
22657 Add_Contract_Item (N, Body_Id);
22658
22659 -- The legality checks of pragma Refined_Post are affected by
22660 -- the SPARK mode in effect and the volatility of the context.
22661 -- Analyze all pragmas in a specific order.
22662
22663 Analyze_If_Present (Pragma_SPARK_Mode);
22664 Analyze_If_Present (Pragma_Volatile_Function);
22665 Analyze_Pre_Post_Condition_In_Decl_Part (N);
22666
22667 -- Currently it is not possible to inline pre/postconditions on
22668 -- a subprogram subject to pragma Inline_Always.
22669
22670 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
22671 end if;
22672 end Refined_Post;
22673
22674 -------------------
22675 -- Refined_State --
22676 -------------------
22677
22678 -- pragma Refined_State (REFINEMENT_LIST);
22679
22680 -- REFINEMENT_LIST ::=
22681 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
22682
22683 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
22684
22685 -- CONSTITUENT_LIST ::=
22686 -- null
22687 -- | CONSTITUENT
22688 -- | (CONSTITUENT {, CONSTITUENT})
22689
22690 -- CONSTITUENT ::= object_NAME | state_NAME
22691
22692 -- Characteristics:
22693
22694 -- * Analysis - The annotation undergoes initial checks to verify
22695 -- the legal placement and context. Secondary checks preanalyze the
22696 -- refinement clauses in:
22697
22698 -- Analyze_Refined_State_In_Decl_Part
22699
22700 -- * Expansion - None.
22701
22702 -- * Template - The annotation utilizes the template of the related
22703 -- package body.
22704
22705 -- * Globals - Capture of global references must occur after full
22706 -- analysis.
22707
22708 -- * Instance - The annotation is instantiated automatically when
22709 -- the related generic package body is instantiated.
22710
22711 when Pragma_Refined_State => Refined_State : declare
22712 Pack_Decl : Node_Id;
22713 Spec_Id : Entity_Id;
22714
22715 begin
22716 GNAT_Pragma;
22717 Check_No_Identifiers;
22718 Check_Arg_Count (1);
22719
22720 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
22721
22722 if Nkind (Pack_Decl) /= N_Package_Body then
22723 Pragma_Misplaced;
22724 return;
22725 end if;
22726
22727 Spec_Id := Corresponding_Spec (Pack_Decl);
22728
22729 -- A pragma that applies to a Ghost entity becomes Ghost for the
22730 -- purposes of legality checks and removal of ignored Ghost code.
22731
22732 Mark_Ghost_Pragma (N, Spec_Id);
22733
22734 -- Chain the pragma on the contract for further processing by
22735 -- Analyze_Refined_State_In_Decl_Part.
22736
22737 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
22738
22739 -- The legality checks of pragma Refined_State are affected by the
22740 -- SPARK mode in effect. Analyze all pragmas in a specific order.
22741
22742 Analyze_If_Present (Pragma_SPARK_Mode);
22743
22744 -- State refinement is allowed only when the corresponding package
22745 -- declaration has non-null pragma Abstract_State. Refinement not
22746 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
22747
22748 if SPARK_Mode /= Off
22749 and then
22750 (No (Abstract_States (Spec_Id))
22751 or else Has_Null_Abstract_State (Spec_Id))
22752 then
22753 Error_Msg_NE
22754 ("useless refinement, package & does not define abstract "
22755 & "states", N, Spec_Id);
22756 return;
22757 end if;
22758 end Refined_State;
22759
22760 -----------------------
22761 -- Relative_Deadline --
22762 -----------------------
22763
22764 -- pragma Relative_Deadline (time_span_EXPRESSION);
22765
22766 when Pragma_Relative_Deadline => Relative_Deadline : declare
22767 P : constant Node_Id := Parent (N);
22768 Arg : Node_Id;
22769
22770 begin
22771 Ada_2005_Pragma;
22772 Check_No_Identifiers;
22773 Check_Arg_Count (1);
22774
22775 Arg := Get_Pragma_Arg (Arg1);
22776
22777 -- The expression must be analyzed in the special manner described
22778 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
22779
22780 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
22781
22782 -- Subprogram case
22783
22784 if Nkind (P) = N_Subprogram_Body then
22785 Check_In_Main_Program;
22786
22787 -- Only Task and subprogram cases allowed
22788
22789 elsif Nkind (P) /= N_Task_Definition then
22790 Pragma_Misplaced;
22791 end if;
22792
22793 -- Check duplicate pragma before we set the corresponding flag
22794
22795 if Has_Relative_Deadline_Pragma (P) then
22796 Error_Pragma ("duplicate pragma% not allowed");
22797 end if;
22798
22799 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
22800 -- Relative_Deadline pragma node cannot be inserted in the Rep
22801 -- Item chain of Ent since it is rewritten by the expander as a
22802 -- procedure call statement that will break the chain.
22803
22804 Set_Has_Relative_Deadline_Pragma (P);
22805 end Relative_Deadline;
22806
22807 ------------------------
22808 -- Remote_Access_Type --
22809 ------------------------
22810
22811 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
22812
22813 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
22814 E : Entity_Id;
22815
22816 begin
22817 GNAT_Pragma;
22818 Check_Arg_Count (1);
22819 Check_Optional_Identifier (Arg1, Name_Entity);
22820 Check_Arg_Is_Local_Name (Arg1);
22821
22822 E := Entity (Get_Pragma_Arg (Arg1));
22823
22824 -- A pragma that applies to a Ghost entity becomes Ghost for the
22825 -- purposes of legality checks and removal of ignored Ghost code.
22826
22827 Mark_Ghost_Pragma (N, E);
22828
22829 if Nkind (Parent (E)) = N_Formal_Type_Declaration
22830 and then Ekind (E) = E_General_Access_Type
22831 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
22832 and then Scope (Root_Type (Directly_Designated_Type (E)))
22833 = Scope (E)
22834 and then Is_Valid_Remote_Object_Type
22835 (Root_Type (Directly_Designated_Type (E)))
22836 then
22837 Set_Is_Remote_Types (E);
22838
22839 else
22840 Error_Pragma_Arg
22841 ("pragma% applies only to formal access-to-class-wide types",
22842 Arg1);
22843 end if;
22844 end Remote_Access_Type;
22845
22846 ---------------------------
22847 -- Remote_Call_Interface --
22848 ---------------------------
22849
22850 -- pragma Remote_Call_Interface [(library_unit_NAME)];
22851
22852 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
22853 Cunit_Node : Node_Id;
22854 Cunit_Ent : Entity_Id;
22855 K : Node_Kind;
22856
22857 begin
22858 Check_Ada_83_Warning;
22859 Check_Valid_Library_Unit_Pragma;
22860
22861 if Nkind (N) = N_Null_Statement then
22862 return;
22863 end if;
22864
22865 Cunit_Node := Cunit (Current_Sem_Unit);
22866 K := Nkind (Unit (Cunit_Node));
22867 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22868
22869 -- A pragma that applies to a Ghost entity becomes Ghost for the
22870 -- purposes of legality checks and removal of ignored Ghost code.
22871
22872 Mark_Ghost_Pragma (N, Cunit_Ent);
22873
22874 if K = N_Package_Declaration
22875 or else K = N_Generic_Package_Declaration
22876 or else K = N_Subprogram_Declaration
22877 or else K = N_Generic_Subprogram_Declaration
22878 or else (K = N_Subprogram_Body
22879 and then Acts_As_Spec (Unit (Cunit_Node)))
22880 then
22881 null;
22882 else
22883 Error_Pragma (
22884 "pragma% must apply to package or subprogram declaration");
22885 end if;
22886
22887 Set_Is_Remote_Call_Interface (Cunit_Ent);
22888 end Remote_Call_Interface;
22889
22890 ------------------
22891 -- Remote_Types --
22892 ------------------
22893
22894 -- pragma Remote_Types [(library_unit_NAME)];
22895
22896 when Pragma_Remote_Types => Remote_Types : declare
22897 Cunit_Node : Node_Id;
22898 Cunit_Ent : Entity_Id;
22899
22900 begin
22901 Check_Ada_83_Warning;
22902 Check_Valid_Library_Unit_Pragma;
22903
22904 if Nkind (N) = N_Null_Statement then
22905 return;
22906 end if;
22907
22908 Cunit_Node := Cunit (Current_Sem_Unit);
22909 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22910
22911 -- A pragma that applies to a Ghost entity becomes Ghost for the
22912 -- purposes of legality checks and removal of ignored Ghost code.
22913
22914 Mark_Ghost_Pragma (N, Cunit_Ent);
22915
22916 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
22917 N_Generic_Package_Declaration)
22918 then
22919 Error_Pragma
22920 ("pragma% can only apply to a package declaration");
22921 end if;
22922
22923 Set_Is_Remote_Types (Cunit_Ent);
22924 end Remote_Types;
22925
22926 ---------------
22927 -- Ravenscar --
22928 ---------------
22929
22930 -- pragma Ravenscar;
22931
22932 when Pragma_Ravenscar =>
22933 GNAT_Pragma;
22934 Check_Arg_Count (0);
22935 Check_Valid_Configuration_Pragma;
22936 Set_Ravenscar_Profile (Ravenscar, N);
22937
22938 if Warn_On_Obsolescent_Feature then
22939 Error_Msg_N
22940 ("pragma Ravenscar is an obsolescent feature?j?", N);
22941 Error_Msg_N
22942 ("|use pragma Profile (Ravenscar) instead?j?", N);
22943 end if;
22944
22945 -------------------------
22946 -- Restricted_Run_Time --
22947 -------------------------
22948
22949 -- pragma Restricted_Run_Time;
22950
22951 when Pragma_Restricted_Run_Time =>
22952 GNAT_Pragma;
22953 Check_Arg_Count (0);
22954 Check_Valid_Configuration_Pragma;
22955 Set_Profile_Restrictions
22956 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
22957
22958 if Warn_On_Obsolescent_Feature then
22959 Error_Msg_N
22960 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
22961 N);
22962 Error_Msg_N
22963 ("|use pragma Profile (Restricted) instead?j?", N);
22964 end if;
22965
22966 ------------------
22967 -- Restrictions --
22968 ------------------
22969
22970 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
22971
22972 -- RESTRICTION ::=
22973 -- restriction_IDENTIFIER
22974 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22975
22976 when Pragma_Restrictions =>
22977 Process_Restrictions_Or_Restriction_Warnings
22978 (Warn => Treat_Restrictions_As_Warnings);
22979
22980 --------------------------
22981 -- Restriction_Warnings --
22982 --------------------------
22983
22984 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
22985
22986 -- RESTRICTION ::=
22987 -- restriction_IDENTIFIER
22988 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22989
22990 when Pragma_Restriction_Warnings =>
22991 GNAT_Pragma;
22992 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
22993
22994 ----------------
22995 -- Reviewable --
22996 ----------------
22997
22998 -- pragma Reviewable;
22999
23000 when Pragma_Reviewable =>
23001 Check_Ada_83_Warning;
23002 Check_Arg_Count (0);
23003
23004 -- Call dummy debugging function rv. This is done to assist front
23005 -- end debugging. By placing a Reviewable pragma in the source
23006 -- program, a breakpoint on rv catches this place in the source,
23007 -- allowing convenient stepping to the point of interest.
23008
23009 rv;
23010
23011 --------------------------
23012 -- Secondary_Stack_Size --
23013 --------------------------
23014
23015 -- pragma Secondary_Stack_Size (EXPRESSION);
23016
23017 when Pragma_Secondary_Stack_Size => Secondary_Stack_Size : declare
23018 P : constant Node_Id := Parent (N);
23019 Arg : Node_Id;
23020 Ent : Entity_Id;
23021
23022 begin
23023 GNAT_Pragma;
23024 Check_No_Identifiers;
23025 Check_Arg_Count (1);
23026
23027 if Nkind (P) = N_Task_Definition then
23028 Arg := Get_Pragma_Arg (Arg1);
23029 Ent := Defining_Identifier (Parent (P));
23030
23031 -- The expression must be analyzed in the special manner
23032 -- described in "Handling of Default Expressions" in sem.ads.
23033
23034 Preanalyze_Spec_Expression (Arg, Any_Integer);
23035
23036 -- The pragma cannot appear if the No_Secondary_Stack
23037 -- restriction is in effect.
23038
23039 Check_Restriction (No_Secondary_Stack, Arg);
23040
23041 -- Anything else is incorrect
23042
23043 else
23044 Pragma_Misplaced;
23045 end if;
23046
23047 -- Check duplicate pragma before we chain the pragma in the Rep
23048 -- Item chain of Ent.
23049
23050 Check_Duplicate_Pragma (Ent);
23051 Record_Rep_Item (Ent, N);
23052 end Secondary_Stack_Size;
23053
23054 --------------------------
23055 -- Short_Circuit_And_Or --
23056 --------------------------
23057
23058 -- pragma Short_Circuit_And_Or;
23059
23060 when Pragma_Short_Circuit_And_Or =>
23061 GNAT_Pragma;
23062 Check_Arg_Count (0);
23063 Check_Valid_Configuration_Pragma;
23064 Short_Circuit_And_Or := True;
23065
23066 -------------------
23067 -- Share_Generic --
23068 -------------------
23069
23070 -- pragma Share_Generic (GNAME {, GNAME});
23071
23072 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
23073
23074 when Pragma_Share_Generic =>
23075 GNAT_Pragma;
23076 Process_Generic_List;
23077
23078 ------------
23079 -- Shared --
23080 ------------
23081
23082 -- pragma Shared (LOCAL_NAME);
23083
23084 when Pragma_Shared =>
23085 GNAT_Pragma;
23086 Process_Atomic_Independent_Shared_Volatile;
23087
23088 --------------------
23089 -- Shared_Passive --
23090 --------------------
23091
23092 -- pragma Shared_Passive [(library_unit_NAME)];
23093
23094 -- Set the flag Is_Shared_Passive of program unit name entity
23095
23096 when Pragma_Shared_Passive => Shared_Passive : declare
23097 Cunit_Node : Node_Id;
23098 Cunit_Ent : Entity_Id;
23099
23100 begin
23101 Check_Ada_83_Warning;
23102 Check_Valid_Library_Unit_Pragma;
23103
23104 if Nkind (N) = N_Null_Statement then
23105 return;
23106 end if;
23107
23108 Cunit_Node := Cunit (Current_Sem_Unit);
23109 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
23110
23111 -- A pragma that applies to a Ghost entity becomes Ghost for the
23112 -- purposes of legality checks and removal of ignored Ghost code.
23113
23114 Mark_Ghost_Pragma (N, Cunit_Ent);
23115
23116 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
23117 N_Generic_Package_Declaration)
23118 then
23119 Error_Pragma
23120 ("pragma% can only apply to a package declaration");
23121 end if;
23122
23123 Set_Is_Shared_Passive (Cunit_Ent);
23124 end Shared_Passive;
23125
23126 -----------------------
23127 -- Short_Descriptors --
23128 -----------------------
23129
23130 -- pragma Short_Descriptors;
23131
23132 -- Recognize and validate, but otherwise ignore
23133
23134 when Pragma_Short_Descriptors =>
23135 GNAT_Pragma;
23136 Check_Arg_Count (0);
23137 Check_Valid_Configuration_Pragma;
23138
23139 ------------------------------
23140 -- Simple_Storage_Pool_Type --
23141 ------------------------------
23142
23143 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
23144
23145 when Pragma_Simple_Storage_Pool_Type =>
23146 Simple_Storage_Pool_Type : declare
23147 Typ : Entity_Id;
23148 Type_Id : Node_Id;
23149
23150 begin
23151 GNAT_Pragma;
23152 Check_Arg_Count (1);
23153 Check_Arg_Is_Library_Level_Local_Name (Arg1);
23154
23155 Type_Id := Get_Pragma_Arg (Arg1);
23156 Find_Type (Type_Id);
23157 Typ := Entity (Type_Id);
23158
23159 if Typ = Any_Type then
23160 return;
23161 end if;
23162
23163 -- A pragma that applies to a Ghost entity becomes Ghost for the
23164 -- purposes of legality checks and removal of ignored Ghost code.
23165
23166 Mark_Ghost_Pragma (N, Typ);
23167
23168 -- We require the pragma to apply to a type declared in a package
23169 -- declaration, but not (immediately) within a package body.
23170
23171 if Ekind (Current_Scope) /= E_Package
23172 or else In_Package_Body (Current_Scope)
23173 then
23174 Error_Pragma
23175 ("pragma% can only apply to type declared immediately "
23176 & "within a package declaration");
23177 end if;
23178
23179 -- A simple storage pool type must be an immutably limited record
23180 -- or private type. If the pragma is given for a private type,
23181 -- the full type is similarly restricted (which is checked later
23182 -- in Freeze_Entity).
23183
23184 if Is_Record_Type (Typ)
23185 and then not Is_Limited_View (Typ)
23186 then
23187 Error_Pragma
23188 ("pragma% can only apply to explicitly limited record type");
23189
23190 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
23191 Error_Pragma
23192 ("pragma% can only apply to a private type that is limited");
23193
23194 elsif not Is_Record_Type (Typ)
23195 and then not Is_Private_Type (Typ)
23196 then
23197 Error_Pragma
23198 ("pragma% can only apply to limited record or private type");
23199 end if;
23200
23201 Record_Rep_Item (Typ, N);
23202 end Simple_Storage_Pool_Type;
23203
23204 ----------------------
23205 -- Source_File_Name --
23206 ----------------------
23207
23208 -- There are five forms for this pragma:
23209
23210 -- pragma Source_File_Name (
23211 -- [UNIT_NAME =>] unit_NAME,
23212 -- BODY_FILE_NAME => STRING_LITERAL
23213 -- [, [INDEX =>] INTEGER_LITERAL]);
23214
23215 -- pragma Source_File_Name (
23216 -- [UNIT_NAME =>] unit_NAME,
23217 -- SPEC_FILE_NAME => STRING_LITERAL
23218 -- [, [INDEX =>] INTEGER_LITERAL]);
23219
23220 -- pragma Source_File_Name (
23221 -- BODY_FILE_NAME => STRING_LITERAL
23222 -- [, DOT_REPLACEMENT => STRING_LITERAL]
23223 -- [, CASING => CASING_SPEC]);
23224
23225 -- pragma Source_File_Name (
23226 -- SPEC_FILE_NAME => STRING_LITERAL
23227 -- [, DOT_REPLACEMENT => STRING_LITERAL]
23228 -- [, CASING => CASING_SPEC]);
23229
23230 -- pragma Source_File_Name (
23231 -- SUBUNIT_FILE_NAME => STRING_LITERAL
23232 -- [, DOT_REPLACEMENT => STRING_LITERAL]
23233 -- [, CASING => CASING_SPEC]);
23234
23235 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
23236
23237 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
23238 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
23239 -- only be used when no project file is used, while SFNP can only be
23240 -- used when a project file is used.
23241
23242 -- No processing here. Processing was completed during parsing, since
23243 -- we need to have file names set as early as possible. Units are
23244 -- loaded well before semantic processing starts.
23245
23246 -- The only processing we defer to this point is the check for
23247 -- correct placement.
23248
23249 when Pragma_Source_File_Name =>
23250 GNAT_Pragma;
23251 Check_Valid_Configuration_Pragma;
23252
23253 ------------------------------
23254 -- Source_File_Name_Project --
23255 ------------------------------
23256
23257 -- See Source_File_Name for syntax
23258
23259 -- No processing here. Processing was completed during parsing, since
23260 -- we need to have file names set as early as possible. Units are
23261 -- loaded well before semantic processing starts.
23262
23263 -- The only processing we defer to this point is the check for
23264 -- correct placement.
23265
23266 when Pragma_Source_File_Name_Project =>
23267 GNAT_Pragma;
23268 Check_Valid_Configuration_Pragma;
23269
23270 -- Check that a pragma Source_File_Name_Project is used only in a
23271 -- configuration pragmas file.
23272
23273 -- Pragmas Source_File_Name_Project should only be generated by
23274 -- the Project Manager in configuration pragmas files.
23275
23276 -- This is really an ugly test. It seems to depend on some
23277 -- accidental and undocumented property. At the very least it
23278 -- needs to be documented, but it would be better to have a
23279 -- clean way of testing if we are in a configuration file???
23280
23281 if Present (Parent (N)) then
23282 Error_Pragma
23283 ("pragma% can only appear in a configuration pragmas file");
23284 end if;
23285
23286 ----------------------
23287 -- Source_Reference --
23288 ----------------------
23289
23290 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
23291
23292 -- Nothing to do, all processing completed in Par.Prag, since we need
23293 -- the information for possible parser messages that are output.
23294
23295 when Pragma_Source_Reference =>
23296 GNAT_Pragma;
23297
23298 ----------------
23299 -- SPARK_Mode --
23300 ----------------
23301
23302 -- pragma SPARK_Mode [(On | Off)];
23303
23304 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
23305 Mode_Id : SPARK_Mode_Type;
23306
23307 procedure Check_Pragma_Conformance
23308 (Context_Pragma : Node_Id;
23309 Entity : Entity_Id;
23310 Entity_Pragma : Node_Id);
23311 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
23312 -- conformance of pragma N depending the following scenarios:
23313 --
23314 -- If pragma Context_Pragma is not Empty, verify that pragma N is
23315 -- compatible with the pragma Context_Pragma that was inherited
23316 -- from the context:
23317 -- * If the mode of Context_Pragma is ON, then the new mode can
23318 -- be anything.
23319 -- * If the mode of Context_Pragma is OFF, then the only allowed
23320 -- new mode is also OFF. Emit error if this is not the case.
23321 --
23322 -- If Entity is not Empty, verify that pragma N is compatible with
23323 -- pragma Entity_Pragma that belongs to Entity.
23324 -- * If Entity_Pragma is Empty, always issue an error as this
23325 -- corresponds to the case where a previous section of Entity
23326 -- has no SPARK_Mode set.
23327 -- * If the mode of Entity_Pragma is ON, then the new mode can
23328 -- be anything.
23329 -- * If the mode of Entity_Pragma is OFF, then the only allowed
23330 -- new mode is also OFF. Emit error if this is not the case.
23331
23332 procedure Check_Library_Level_Entity (E : Entity_Id);
23333 -- Subsidiary to routines Process_xxx. Verify that the related
23334 -- entity E subject to pragma SPARK_Mode is library-level.
23335
23336 procedure Process_Body (Decl : Node_Id);
23337 -- Verify the legality of pragma SPARK_Mode when it appears as the
23338 -- top of the body declarations of entry, package, protected unit,
23339 -- subprogram or task unit body denoted by Decl.
23340
23341 procedure Process_Overloadable (Decl : Node_Id);
23342 -- Verify the legality of pragma SPARK_Mode when it applies to an
23343 -- entry or [generic] subprogram declaration denoted by Decl.
23344
23345 procedure Process_Private_Part (Decl : Node_Id);
23346 -- Verify the legality of pragma SPARK_Mode when it appears at the
23347 -- top of the private declarations of a package spec, protected or
23348 -- task unit declaration denoted by Decl.
23349
23350 procedure Process_Statement_Part (Decl : Node_Id);
23351 -- Verify the legality of pragma SPARK_Mode when it appears at the
23352 -- top of the statement sequence of a package body denoted by node
23353 -- Decl.
23354
23355 procedure Process_Visible_Part (Decl : Node_Id);
23356 -- Verify the legality of pragma SPARK_Mode when it appears at the
23357 -- top of the visible declarations of a package spec, protected or
23358 -- task unit declaration denoted by Decl. The routine is also used
23359 -- on protected or task units declared without a definition.
23360
23361 procedure Set_SPARK_Context;
23362 -- Subsidiary to routines Process_xxx. Set the global variables
23363 -- which represent the mode of the context from pragma N. Ensure
23364 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
23365
23366 ------------------------------
23367 -- Check_Pragma_Conformance --
23368 ------------------------------
23369
23370 procedure Check_Pragma_Conformance
23371 (Context_Pragma : Node_Id;
23372 Entity : Entity_Id;
23373 Entity_Pragma : Node_Id)
23374 is
23375 Err_Id : Entity_Id;
23376 Err_N : Node_Id;
23377
23378 begin
23379 -- The current pragma may appear without an argument. If this
23380 -- is the case, associate all error messages with the pragma
23381 -- itself.
23382
23383 if Present (Arg1) then
23384 Err_N := Arg1;
23385 else
23386 Err_N := N;
23387 end if;
23388
23389 -- The mode of the current pragma is compared against that of
23390 -- an enclosing context.
23391
23392 if Present (Context_Pragma) then
23393 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
23394
23395 -- Issue an error if the new mode is less restrictive than
23396 -- that of the context.
23397
23398 if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off
23399 and then Get_SPARK_Mode_From_Annotation (N) = On
23400 then
23401 Error_Msg_N
23402 ("cannot change SPARK_Mode from Off to On", Err_N);
23403 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
23404 Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N);
23405 raise Pragma_Exit;
23406 end if;
23407 end if;
23408
23409 -- The mode of the current pragma is compared against that of
23410 -- an initial package, protected type, subprogram or task type
23411 -- declaration.
23412
23413 if Present (Entity) then
23414
23415 -- A simple protected or task type is transformed into an
23416 -- anonymous type whose name cannot be used to issue error
23417 -- messages. Recover the original entity of the type.
23418
23419 if Ekind_In (Entity, E_Protected_Type, E_Task_Type) then
23420 Err_Id :=
23421 Defining_Entity
23422 (Original_Node (Unit_Declaration_Node (Entity)));
23423 else
23424 Err_Id := Entity;
23425 end if;
23426
23427 -- Both the initial declaration and the completion carry
23428 -- SPARK_Mode pragmas.
23429
23430 if Present (Entity_Pragma) then
23431 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
23432
23433 -- Issue an error if the new mode is less restrictive
23434 -- than that of the initial declaration.
23435
23436 if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off
23437 and then Get_SPARK_Mode_From_Annotation (N) = On
23438 then
23439 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
23440 Error_Msg_Sloc := Sloc (Entity_Pragma);
23441 Error_Msg_NE
23442 ("\value Off was set for SPARK_Mode on&#",
23443 Err_N, Err_Id);
23444 raise Pragma_Exit;
23445 end if;
23446
23447 -- Otherwise the initial declaration lacks a SPARK_Mode
23448 -- pragma in which case the current pragma is illegal as
23449 -- it cannot "complete".
23450
23451 else
23452 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
23453 Error_Msg_Sloc := Sloc (Err_Id);
23454 Error_Msg_NE
23455 ("\no value was set for SPARK_Mode on&#",
23456 Err_N, Err_Id);
23457 raise Pragma_Exit;
23458 end if;
23459 end if;
23460 end Check_Pragma_Conformance;
23461
23462 --------------------------------
23463 -- Check_Library_Level_Entity --
23464 --------------------------------
23465
23466 procedure Check_Library_Level_Entity (E : Entity_Id) is
23467 procedure Add_Entity_To_Name_Buffer;
23468 -- Add the E_Kind of entity E to the name buffer
23469
23470 -------------------------------
23471 -- Add_Entity_To_Name_Buffer --
23472 -------------------------------
23473
23474 procedure Add_Entity_To_Name_Buffer is
23475 begin
23476 if Ekind_In (E, E_Entry, E_Entry_Family) then
23477 Add_Str_To_Name_Buffer ("entry");
23478
23479 elsif Ekind_In (E, E_Generic_Package,
23480 E_Package,
23481 E_Package_Body)
23482 then
23483 Add_Str_To_Name_Buffer ("package");
23484
23485 elsif Ekind_In (E, E_Protected_Body, E_Protected_Type) then
23486 Add_Str_To_Name_Buffer ("protected type");
23487
23488 elsif Ekind_In (E, E_Function,
23489 E_Generic_Function,
23490 E_Generic_Procedure,
23491 E_Procedure,
23492 E_Subprogram_Body)
23493 then
23494 Add_Str_To_Name_Buffer ("subprogram");
23495
23496 else
23497 pragma Assert (Ekind_In (E, E_Task_Body, E_Task_Type));
23498 Add_Str_To_Name_Buffer ("task type");
23499 end if;
23500 end Add_Entity_To_Name_Buffer;
23501
23502 -- Local variables
23503
23504 Msg_1 : constant String := "incorrect placement of pragma%";
23505 Msg_2 : Name_Id;
23506
23507 -- Start of processing for Check_Library_Level_Entity
23508
23509 begin
23510 -- A SPARK_Mode of On shall only apply to library-level
23511 -- entities, except for those in generic instances, which are
23512 -- ignored (even if the entity gets SPARK_Mode pragma attached
23513 -- in the AST, its effect is not taken into account unless the
23514 -- context already provides SPARK_Mode of On in GNATprove).
23515
23516 if Get_SPARK_Mode_From_Annotation (N) = On
23517 and then not Is_Library_Level_Entity (E)
23518 and then Instantiation_Location (Sloc (N)) = No_Location
23519 then
23520 Error_Msg_Name_1 := Pname;
23521 Error_Msg_N (Fix_Error (Msg_1), N);
23522
23523 Name_Len := 0;
23524 Add_Str_To_Name_Buffer ("\& is not a library-level ");
23525 Add_Entity_To_Name_Buffer;
23526
23527 Msg_2 := Name_Find;
23528 Error_Msg_NE (Get_Name_String (Msg_2), N, E);
23529
23530 raise Pragma_Exit;
23531 end if;
23532 end Check_Library_Level_Entity;
23533
23534 ------------------
23535 -- Process_Body --
23536 ------------------
23537
23538 procedure Process_Body (Decl : Node_Id) is
23539 Body_Id : constant Entity_Id := Defining_Entity (Decl);
23540 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
23541
23542 begin
23543 -- Ignore pragma when applied to the special body created for
23544 -- inlining, recognized by its internal name _Parent.
23545
23546 if Chars (Body_Id) = Name_uParent then
23547 return;
23548 end if;
23549
23550 Check_Library_Level_Entity (Body_Id);
23551
23552 -- For entry bodies, verify the legality against:
23553 -- * The mode of the context
23554 -- * The mode of the spec (if any)
23555
23556 if Nkind_In (Decl, N_Entry_Body, N_Subprogram_Body) then
23557
23558 -- A stand-alone subprogram body
23559
23560 if Body_Id = Spec_Id then
23561 Check_Pragma_Conformance
23562 (Context_Pragma => SPARK_Pragma (Body_Id),
23563 Entity => Empty,
23564 Entity_Pragma => Empty);
23565
23566 -- An entry or subprogram body that completes a previous
23567 -- declaration.
23568
23569 else
23570 Check_Pragma_Conformance
23571 (Context_Pragma => SPARK_Pragma (Body_Id),
23572 Entity => Spec_Id,
23573 Entity_Pragma => SPARK_Pragma (Spec_Id));
23574 end if;
23575
23576 Set_SPARK_Context;
23577 Set_SPARK_Pragma (Body_Id, N);
23578 Set_SPARK_Pragma_Inherited (Body_Id, False);
23579
23580 -- For package bodies, verify the legality against:
23581 -- * The mode of the context
23582 -- * The mode of the private part
23583
23584 -- This case is separated from protected and task bodies
23585 -- because the statement part of the package body inherits
23586 -- the mode of the body declarations.
23587
23588 elsif Nkind (Decl) = N_Package_Body then
23589 Check_Pragma_Conformance
23590 (Context_Pragma => SPARK_Pragma (Body_Id),
23591 Entity => Spec_Id,
23592 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
23593
23594 Set_SPARK_Context;
23595 Set_SPARK_Pragma (Body_Id, N);
23596 Set_SPARK_Pragma_Inherited (Body_Id, False);
23597 Set_SPARK_Aux_Pragma (Body_Id, N);
23598 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
23599
23600 -- For protected and task bodies, verify the legality against:
23601 -- * The mode of the context
23602 -- * The mode of the private part
23603
23604 else
23605 pragma Assert
23606 (Nkind_In (Decl, N_Protected_Body, N_Task_Body));
23607
23608 Check_Pragma_Conformance
23609 (Context_Pragma => SPARK_Pragma (Body_Id),
23610 Entity => Spec_Id,
23611 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
23612
23613 Set_SPARK_Context;
23614 Set_SPARK_Pragma (Body_Id, N);
23615 Set_SPARK_Pragma_Inherited (Body_Id, False);
23616 end if;
23617 end Process_Body;
23618
23619 --------------------------
23620 -- Process_Overloadable --
23621 --------------------------
23622
23623 procedure Process_Overloadable (Decl : Node_Id) is
23624 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23625 Spec_Typ : constant Entity_Id := Etype (Spec_Id);
23626
23627 begin
23628 Check_Library_Level_Entity (Spec_Id);
23629
23630 -- Verify the legality against:
23631 -- * The mode of the context
23632
23633 Check_Pragma_Conformance
23634 (Context_Pragma => SPARK_Pragma (Spec_Id),
23635 Entity => Empty,
23636 Entity_Pragma => Empty);
23637
23638 Set_SPARK_Pragma (Spec_Id, N);
23639 Set_SPARK_Pragma_Inherited (Spec_Id, False);
23640
23641 -- When the pragma applies to the anonymous object created for
23642 -- a single task type, decorate the type as well. This scenario
23643 -- arises when the single task type lacks a task definition,
23644 -- therefore there is no issue with respect to a potential
23645 -- pragma SPARK_Mode in the private part.
23646
23647 -- task type Anon_Task_Typ;
23648 -- Obj : Anon_Task_Typ;
23649 -- pragma SPARK_Mode ...;
23650
23651 if Is_Single_Task_Object (Spec_Id) then
23652 Set_SPARK_Pragma (Spec_Typ, N);
23653 Set_SPARK_Pragma_Inherited (Spec_Typ, False);
23654 Set_SPARK_Aux_Pragma (Spec_Typ, N);
23655 Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True);
23656 end if;
23657 end Process_Overloadable;
23658
23659 --------------------------
23660 -- Process_Private_Part --
23661 --------------------------
23662
23663 procedure Process_Private_Part (Decl : Node_Id) is
23664 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23665
23666 begin
23667 Check_Library_Level_Entity (Spec_Id);
23668
23669 -- Verify the legality against:
23670 -- * The mode of the visible declarations
23671
23672 Check_Pragma_Conformance
23673 (Context_Pragma => Empty,
23674 Entity => Spec_Id,
23675 Entity_Pragma => SPARK_Pragma (Spec_Id));
23676
23677 Set_SPARK_Context;
23678 Set_SPARK_Aux_Pragma (Spec_Id, N);
23679 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
23680 end Process_Private_Part;
23681
23682 ----------------------------
23683 -- Process_Statement_Part --
23684 ----------------------------
23685
23686 procedure Process_Statement_Part (Decl : Node_Id) is
23687 Body_Id : constant Entity_Id := Defining_Entity (Decl);
23688
23689 begin
23690 Check_Library_Level_Entity (Body_Id);
23691
23692 -- Verify the legality against:
23693 -- * The mode of the body declarations
23694
23695 Check_Pragma_Conformance
23696 (Context_Pragma => Empty,
23697 Entity => Body_Id,
23698 Entity_Pragma => SPARK_Pragma (Body_Id));
23699
23700 Set_SPARK_Context;
23701 Set_SPARK_Aux_Pragma (Body_Id, N);
23702 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
23703 end Process_Statement_Part;
23704
23705 --------------------------
23706 -- Process_Visible_Part --
23707 --------------------------
23708
23709 procedure Process_Visible_Part (Decl : Node_Id) is
23710 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23711 Obj_Id : Entity_Id;
23712
23713 begin
23714 Check_Library_Level_Entity (Spec_Id);
23715
23716 -- Verify the legality against:
23717 -- * The mode of the context
23718
23719 Check_Pragma_Conformance
23720 (Context_Pragma => SPARK_Pragma (Spec_Id),
23721 Entity => Empty,
23722 Entity_Pragma => Empty);
23723
23724 -- A task unit declared without a definition does not set the
23725 -- SPARK_Mode of the context because the task does not have any
23726 -- entries that could inherit the mode.
23727
23728 if not Nkind_In (Decl, N_Single_Task_Declaration,
23729 N_Task_Type_Declaration)
23730 then
23731 Set_SPARK_Context;
23732 end if;
23733
23734 Set_SPARK_Pragma (Spec_Id, N);
23735 Set_SPARK_Pragma_Inherited (Spec_Id, False);
23736 Set_SPARK_Aux_Pragma (Spec_Id, N);
23737 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
23738
23739 -- When the pragma applies to a single protected or task type,
23740 -- decorate the corresponding anonymous object as well.
23741
23742 -- protected Anon_Prot_Typ is
23743 -- pragma SPARK_Mode ...;
23744 -- ...
23745 -- end Anon_Prot_Typ;
23746
23747 -- Obj : Anon_Prot_Typ;
23748
23749 if Is_Single_Concurrent_Type (Spec_Id) then
23750 Obj_Id := Anonymous_Object (Spec_Id);
23751
23752 Set_SPARK_Pragma (Obj_Id, N);
23753 Set_SPARK_Pragma_Inherited (Obj_Id, False);
23754 end if;
23755 end Process_Visible_Part;
23756
23757 -----------------------
23758 -- Set_SPARK_Context --
23759 -----------------------
23760
23761 procedure Set_SPARK_Context is
23762 begin
23763 SPARK_Mode := Mode_Id;
23764 SPARK_Mode_Pragma := N;
23765 end Set_SPARK_Context;
23766
23767 -- Local variables
23768
23769 Context : Node_Id;
23770 Mode : Name_Id;
23771 Stmt : Node_Id;
23772
23773 -- Start of processing for Do_SPARK_Mode
23774
23775 begin
23776 -- When a SPARK_Mode pragma appears inside an instantiation whose
23777 -- enclosing context has SPARK_Mode set to "off", the pragma has
23778 -- no semantic effect.
23779
23780 if Ignore_SPARK_Mode_Pragmas_In_Instance then
23781 Rewrite (N, Make_Null_Statement (Loc));
23782 Analyze (N);
23783 return;
23784 end if;
23785
23786 GNAT_Pragma;
23787 Check_No_Identifiers;
23788 Check_At_Most_N_Arguments (1);
23789
23790 -- Check the legality of the mode (no argument = ON)
23791
23792 if Arg_Count = 1 then
23793 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23794 Mode := Chars (Get_Pragma_Arg (Arg1));
23795 else
23796 Mode := Name_On;
23797 end if;
23798
23799 Mode_Id := Get_SPARK_Mode_Type (Mode);
23800 Context := Parent (N);
23801
23802 -- The pragma appears in a configuration file
23803
23804 if No (Context) then
23805 Check_Valid_Configuration_Pragma;
23806
23807 if Present (SPARK_Mode_Pragma) then
23808 Duplication_Error
23809 (Prag => N,
23810 Prev => SPARK_Mode_Pragma);
23811 raise Pragma_Exit;
23812 end if;
23813
23814 Set_SPARK_Context;
23815
23816 -- The pragma acts as a configuration pragma in a compilation unit
23817
23818 -- pragma SPARK_Mode ...;
23819 -- package Pack is ...;
23820
23821 elsif Nkind (Context) = N_Compilation_Unit
23822 and then List_Containing (N) = Context_Items (Context)
23823 then
23824 Check_Valid_Configuration_Pragma;
23825 Set_SPARK_Context;
23826
23827 -- Otherwise the placement of the pragma within the tree dictates
23828 -- its associated construct. Inspect the declarative list where
23829 -- the pragma resides to find a potential construct.
23830
23831 else
23832 Stmt := Prev (N);
23833 while Present (Stmt) loop
23834
23835 -- Skip prior pragmas, but check for duplicates. Note that
23836 -- this also takes care of pragmas generated for aspects.
23837
23838 if Nkind (Stmt) = N_Pragma then
23839 if Pragma_Name (Stmt) = Pname then
23840 Duplication_Error
23841 (Prag => N,
23842 Prev => Stmt);
23843 raise Pragma_Exit;
23844 end if;
23845
23846 -- The pragma applies to an expression function that has
23847 -- already been rewritten into a subprogram declaration.
23848
23849 -- function Expr_Func return ... is (...);
23850 -- pragma SPARK_Mode ...;
23851
23852 elsif Nkind (Stmt) = N_Subprogram_Declaration
23853 and then Nkind (Original_Node (Stmt)) =
23854 N_Expression_Function
23855 then
23856 Process_Overloadable (Stmt);
23857 return;
23858
23859 -- The pragma applies to the anonymous object created for a
23860 -- single concurrent type.
23861
23862 -- protected type Anon_Prot_Typ ...;
23863 -- Obj : Anon_Prot_Typ;
23864 -- pragma SPARK_Mode ...;
23865
23866 elsif Nkind (Stmt) = N_Object_Declaration
23867 and then Is_Single_Concurrent_Object
23868 (Defining_Entity (Stmt))
23869 then
23870 Process_Overloadable (Stmt);
23871 return;
23872
23873 -- Skip internally generated code
23874
23875 elsif not Comes_From_Source (Stmt) then
23876 null;
23877
23878 -- The pragma applies to an entry or [generic] subprogram
23879 -- declaration.
23880
23881 -- entry Ent ...;
23882 -- pragma SPARK_Mode ...;
23883
23884 -- [generic]
23885 -- procedure Proc ...;
23886 -- pragma SPARK_Mode ...;
23887
23888 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
23889 N_Subprogram_Declaration)
23890 or else (Nkind (Stmt) = N_Entry_Declaration
23891 and then Is_Protected_Type
23892 (Scope (Defining_Entity (Stmt))))
23893 then
23894 Process_Overloadable (Stmt);
23895 return;
23896
23897 -- Otherwise the pragma does not apply to a legal construct
23898 -- or it does not appear at the top of a declarative or a
23899 -- statement list. Issue an error and stop the analysis.
23900
23901 else
23902 Pragma_Misplaced;
23903 exit;
23904 end if;
23905
23906 Prev (Stmt);
23907 end loop;
23908
23909 -- The pragma applies to a package or a subprogram that acts as
23910 -- a compilation unit.
23911
23912 -- procedure Proc ...;
23913 -- pragma SPARK_Mode ...;
23914
23915 if Nkind (Context) = N_Compilation_Unit_Aux then
23916 Context := Unit (Parent (Context));
23917 end if;
23918
23919 -- The pragma appears at the top of entry, package, protected
23920 -- unit, subprogram or task unit body declarations.
23921
23922 -- entry Ent when ... is
23923 -- pragma SPARK_Mode ...;
23924
23925 -- package body Pack is
23926 -- pragma SPARK_Mode ...;
23927
23928 -- procedure Proc ... is
23929 -- pragma SPARK_Mode;
23930
23931 -- protected body Prot is
23932 -- pragma SPARK_Mode ...;
23933
23934 if Nkind_In (Context, N_Entry_Body,
23935 N_Package_Body,
23936 N_Protected_Body,
23937 N_Subprogram_Body,
23938 N_Task_Body)
23939 then
23940 Process_Body (Context);
23941
23942 -- The pragma appears at the top of the visible or private
23943 -- declaration of a package spec, protected or task unit.
23944
23945 -- package Pack is
23946 -- pragma SPARK_Mode ...;
23947 -- private
23948 -- pragma SPARK_Mode ...;
23949
23950 -- protected [type] Prot is
23951 -- pragma SPARK_Mode ...;
23952 -- private
23953 -- pragma SPARK_Mode ...;
23954
23955 elsif Nkind_In (Context, N_Package_Specification,
23956 N_Protected_Definition,
23957 N_Task_Definition)
23958 then
23959 if List_Containing (N) = Visible_Declarations (Context) then
23960 Process_Visible_Part (Parent (Context));
23961 else
23962 Process_Private_Part (Parent (Context));
23963 end if;
23964
23965 -- The pragma appears at the top of package body statements
23966
23967 -- package body Pack is
23968 -- begin
23969 -- pragma SPARK_Mode;
23970
23971 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
23972 and then Nkind (Parent (Context)) = N_Package_Body
23973 then
23974 Process_Statement_Part (Parent (Context));
23975
23976 -- The pragma appeared as an aspect of a [generic] subprogram
23977 -- declaration that acts as a compilation unit.
23978
23979 -- [generic]
23980 -- procedure Proc ...;
23981 -- pragma SPARK_Mode ...;
23982
23983 elsif Nkind_In (Context, N_Generic_Subprogram_Declaration,
23984 N_Subprogram_Declaration)
23985 then
23986 Process_Overloadable (Context);
23987
23988 -- The pragma does not apply to a legal construct, issue error
23989
23990 else
23991 Pragma_Misplaced;
23992 end if;
23993 end if;
23994 end Do_SPARK_Mode;
23995
23996 --------------------------------
23997 -- Static_Elaboration_Desired --
23998 --------------------------------
23999
24000 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
24001
24002 when Pragma_Static_Elaboration_Desired =>
24003 GNAT_Pragma;
24004 Check_At_Most_N_Arguments (1);
24005
24006 if Is_Compilation_Unit (Current_Scope)
24007 and then Ekind (Current_Scope) = E_Package
24008 then
24009 Set_Static_Elaboration_Desired (Current_Scope, True);
24010 else
24011 Error_Pragma ("pragma% must apply to a library-level package");
24012 end if;
24013
24014 ------------------
24015 -- Storage_Size --
24016 ------------------
24017
24018 -- pragma Storage_Size (EXPRESSION);
24019
24020 when Pragma_Storage_Size => Storage_Size : declare
24021 P : constant Node_Id := Parent (N);
24022 Arg : Node_Id;
24023
24024 begin
24025 Check_No_Identifiers;
24026 Check_Arg_Count (1);
24027
24028 -- The expression must be analyzed in the special manner described
24029 -- in "Handling of Default Expressions" in sem.ads.
24030
24031 Arg := Get_Pragma_Arg (Arg1);
24032 Preanalyze_Spec_Expression (Arg, Any_Integer);
24033
24034 if not Is_OK_Static_Expression (Arg) then
24035 Check_Restriction (Static_Storage_Size, Arg);
24036 end if;
24037
24038 if Nkind (P) /= N_Task_Definition then
24039 Pragma_Misplaced;
24040 return;
24041
24042 else
24043 if Has_Storage_Size_Pragma (P) then
24044 Error_Pragma ("duplicate pragma% not allowed");
24045 else
24046 Set_Has_Storage_Size_Pragma (P, True);
24047 end if;
24048
24049 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
24050 end if;
24051 end Storage_Size;
24052
24053 ------------------
24054 -- Storage_Unit --
24055 ------------------
24056
24057 -- pragma Storage_Unit (NUMERIC_LITERAL);
24058
24059 -- Only permitted argument is System'Storage_Unit value
24060
24061 when Pragma_Storage_Unit =>
24062 Check_No_Identifiers;
24063 Check_Arg_Count (1);
24064 Check_Arg_Is_Integer_Literal (Arg1);
24065
24066 if Intval (Get_Pragma_Arg (Arg1)) /=
24067 UI_From_Int (Ttypes.System_Storage_Unit)
24068 then
24069 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
24070 Error_Pragma_Arg
24071 ("the only allowed argument for pragma% is ^", Arg1);
24072 end if;
24073
24074 --------------------
24075 -- Stream_Convert --
24076 --------------------
24077
24078 -- pragma Stream_Convert (
24079 -- [Entity =>] type_LOCAL_NAME,
24080 -- [Read =>] function_NAME,
24081 -- [Write =>] function NAME);
24082
24083 when Pragma_Stream_Convert => Stream_Convert : declare
24084 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
24085 -- Check that the given argument is the name of a local function
24086 -- of one argument that is not overloaded earlier in the current
24087 -- local scope. A check is also made that the argument is a
24088 -- function with one parameter.
24089
24090 --------------------------------------
24091 -- Check_OK_Stream_Convert_Function --
24092 --------------------------------------
24093
24094 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
24095 Ent : Entity_Id;
24096
24097 begin
24098 Check_Arg_Is_Local_Name (Arg);
24099 Ent := Entity (Get_Pragma_Arg (Arg));
24100
24101 if Has_Homonym (Ent) then
24102 Error_Pragma_Arg
24103 ("argument for pragma% may not be overloaded", Arg);
24104 end if;
24105
24106 if Ekind (Ent) /= E_Function
24107 or else No (First_Formal (Ent))
24108 or else Present (Next_Formal (First_Formal (Ent)))
24109 then
24110 Error_Pragma_Arg
24111 ("argument for pragma% must be function of one argument",
24112 Arg);
24113 end if;
24114 end Check_OK_Stream_Convert_Function;
24115
24116 -- Start of processing for Stream_Convert
24117
24118 begin
24119 GNAT_Pragma;
24120 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
24121 Check_Arg_Count (3);
24122 Check_Optional_Identifier (Arg1, Name_Entity);
24123 Check_Optional_Identifier (Arg2, Name_Read);
24124 Check_Optional_Identifier (Arg3, Name_Write);
24125 Check_Arg_Is_Local_Name (Arg1);
24126 Check_OK_Stream_Convert_Function (Arg2);
24127 Check_OK_Stream_Convert_Function (Arg3);
24128
24129 declare
24130 Typ : constant Entity_Id :=
24131 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
24132 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
24133 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
24134
24135 begin
24136 Check_First_Subtype (Arg1);
24137
24138 -- Check for too early or too late. Note that we don't enforce
24139 -- the rule about primitive operations in this case, since, as
24140 -- is the case for explicit stream attributes themselves, these
24141 -- restrictions are not appropriate. Note that the chaining of
24142 -- the pragma by Rep_Item_Too_Late is actually the critical
24143 -- processing done for this pragma.
24144
24145 if Rep_Item_Too_Early (Typ, N)
24146 or else
24147 Rep_Item_Too_Late (Typ, N, FOnly => True)
24148 then
24149 return;
24150 end if;
24151
24152 -- Return if previous error
24153
24154 if Etype (Typ) = Any_Type
24155 or else
24156 Etype (Read) = Any_Type
24157 or else
24158 Etype (Write) = Any_Type
24159 then
24160 return;
24161 end if;
24162
24163 -- Error checks
24164
24165 if Underlying_Type (Etype (Read)) /= Typ then
24166 Error_Pragma_Arg
24167 ("incorrect return type for function&", Arg2);
24168 end if;
24169
24170 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
24171 Error_Pragma_Arg
24172 ("incorrect parameter type for function&", Arg3);
24173 end if;
24174
24175 if Underlying_Type (Etype (First_Formal (Read))) /=
24176 Underlying_Type (Etype (Write))
24177 then
24178 Error_Pragma_Arg
24179 ("result type of & does not match Read parameter type",
24180 Arg3);
24181 end if;
24182 end;
24183 end Stream_Convert;
24184
24185 ------------------
24186 -- Style_Checks --
24187 ------------------
24188
24189 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
24190
24191 -- This is processed by the parser since some of the style checks
24192 -- take place during source scanning and parsing. This means that
24193 -- we don't need to issue error messages here.
24194
24195 when Pragma_Style_Checks => Style_Checks : declare
24196 A : constant Node_Id := Get_Pragma_Arg (Arg1);
24197 S : String_Id;
24198 C : Char_Code;
24199
24200 begin
24201 GNAT_Pragma;
24202 Check_No_Identifiers;
24203
24204 -- Two argument form
24205
24206 if Arg_Count = 2 then
24207 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
24208
24209 declare
24210 E_Id : Node_Id;
24211 E : Entity_Id;
24212
24213 begin
24214 E_Id := Get_Pragma_Arg (Arg2);
24215 Analyze (E_Id);
24216
24217 if not Is_Entity_Name (E_Id) then
24218 Error_Pragma_Arg
24219 ("second argument of pragma% must be entity name",
24220 Arg2);
24221 end if;
24222
24223 E := Entity (E_Id);
24224
24225 if not Ignore_Style_Checks_Pragmas then
24226 if E = Any_Id then
24227 return;
24228 else
24229 loop
24230 Set_Suppress_Style_Checks
24231 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
24232 exit when No (Homonym (E));
24233 E := Homonym (E);
24234 end loop;
24235 end if;
24236 end if;
24237 end;
24238
24239 -- One argument form
24240
24241 else
24242 Check_Arg_Count (1);
24243
24244 if Nkind (A) = N_String_Literal then
24245 S := Strval (A);
24246
24247 declare
24248 Slen : constant Natural := Natural (String_Length (S));
24249 Options : String (1 .. Slen);
24250 J : Positive;
24251
24252 begin
24253 J := 1;
24254 loop
24255 C := Get_String_Char (S, Pos (J));
24256 exit when not In_Character_Range (C);
24257 Options (J) := Get_Character (C);
24258
24259 -- If at end of string, set options. As per discussion
24260 -- above, no need to check for errors, since we issued
24261 -- them in the parser.
24262
24263 if J = Slen then
24264 if not Ignore_Style_Checks_Pragmas then
24265 Set_Style_Check_Options (Options);
24266 end if;
24267
24268 exit;
24269 end if;
24270
24271 J := J + 1;
24272 end loop;
24273 end;
24274
24275 elsif Nkind (A) = N_Identifier then
24276 if Chars (A) = Name_All_Checks then
24277 if not Ignore_Style_Checks_Pragmas then
24278 if GNAT_Mode then
24279 Set_GNAT_Style_Check_Options;
24280 else
24281 Set_Default_Style_Check_Options;
24282 end if;
24283 end if;
24284
24285 elsif Chars (A) = Name_On then
24286 if not Ignore_Style_Checks_Pragmas then
24287 Style_Check := True;
24288 end if;
24289
24290 elsif Chars (A) = Name_Off then
24291 if not Ignore_Style_Checks_Pragmas then
24292 Style_Check := False;
24293 end if;
24294 end if;
24295 end if;
24296 end if;
24297 end Style_Checks;
24298
24299 --------------
24300 -- Subtitle --
24301 --------------
24302
24303 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
24304
24305 when Pragma_Subtitle =>
24306 GNAT_Pragma;
24307 Check_Arg_Count (1);
24308 Check_Optional_Identifier (Arg1, Name_Subtitle);
24309 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
24310 Store_Note (N);
24311
24312 --------------
24313 -- Suppress --
24314 --------------
24315
24316 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
24317
24318 when Pragma_Suppress =>
24319 Process_Suppress_Unsuppress (Suppress_Case => True);
24320
24321 ------------------
24322 -- Suppress_All --
24323 ------------------
24324
24325 -- pragma Suppress_All;
24326
24327 -- The only check made here is that the pragma has no arguments.
24328 -- There are no placement rules, and the processing required (setting
24329 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
24330 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
24331 -- then creates and inserts a pragma Suppress (All_Checks).
24332
24333 when Pragma_Suppress_All =>
24334 GNAT_Pragma;
24335 Check_Arg_Count (0);
24336
24337 -------------------------
24338 -- Suppress_Debug_Info --
24339 -------------------------
24340
24341 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
24342
24343 when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare
24344 Nam_Id : Entity_Id;
24345
24346 begin
24347 GNAT_Pragma;
24348 Check_Arg_Count (1);
24349 Check_Optional_Identifier (Arg1, Name_Entity);
24350 Check_Arg_Is_Local_Name (Arg1);
24351
24352 Nam_Id := Entity (Get_Pragma_Arg (Arg1));
24353
24354 -- A pragma that applies to a Ghost entity becomes Ghost for the
24355 -- purposes of legality checks and removal of ignored Ghost code.
24356
24357 Mark_Ghost_Pragma (N, Nam_Id);
24358 Set_Debug_Info_Off (Nam_Id);
24359 end Suppress_Debug_Info;
24360
24361 ----------------------------------
24362 -- Suppress_Exception_Locations --
24363 ----------------------------------
24364
24365 -- pragma Suppress_Exception_Locations;
24366
24367 when Pragma_Suppress_Exception_Locations =>
24368 GNAT_Pragma;
24369 Check_Arg_Count (0);
24370 Check_Valid_Configuration_Pragma;
24371 Exception_Locations_Suppressed := True;
24372
24373 -----------------------------
24374 -- Suppress_Initialization --
24375 -----------------------------
24376
24377 -- pragma Suppress_Initialization ([Entity =>] type_Name);
24378
24379 when Pragma_Suppress_Initialization => Suppress_Init : declare
24380 E : Entity_Id;
24381 E_Id : Node_Id;
24382
24383 begin
24384 GNAT_Pragma;
24385 Check_Arg_Count (1);
24386 Check_Optional_Identifier (Arg1, Name_Entity);
24387 Check_Arg_Is_Local_Name (Arg1);
24388
24389 E_Id := Get_Pragma_Arg (Arg1);
24390
24391 if Etype (E_Id) = Any_Type then
24392 return;
24393 end if;
24394
24395 E := Entity (E_Id);
24396
24397 -- A pragma that applies to a Ghost entity becomes Ghost for the
24398 -- purposes of legality checks and removal of ignored Ghost code.
24399
24400 Mark_Ghost_Pragma (N, E);
24401
24402 if not Is_Type (E) and then Ekind (E) /= E_Variable then
24403 Error_Pragma_Arg
24404 ("pragma% requires variable, type or subtype", Arg1);
24405 end if;
24406
24407 if Rep_Item_Too_Early (E, N)
24408 or else
24409 Rep_Item_Too_Late (E, N, FOnly => True)
24410 then
24411 return;
24412 end if;
24413
24414 -- For incomplete/private type, set flag on full view
24415
24416 if Is_Incomplete_Or_Private_Type (E) then
24417 if No (Full_View (Base_Type (E))) then
24418 Error_Pragma_Arg
24419 ("argument of pragma% cannot be an incomplete type", Arg1);
24420 else
24421 Set_Suppress_Initialization (Full_View (E));
24422 end if;
24423
24424 -- For first subtype, set flag on base type
24425
24426 elsif Is_First_Subtype (E) then
24427 Set_Suppress_Initialization (Base_Type (E));
24428
24429 -- For other than first subtype, set flag on subtype or variable
24430
24431 else
24432 Set_Suppress_Initialization (E);
24433 end if;
24434 end Suppress_Init;
24435
24436 -----------------
24437 -- System_Name --
24438 -----------------
24439
24440 -- pragma System_Name (DIRECT_NAME);
24441
24442 -- Syntax check: one argument, which must be the identifier GNAT or
24443 -- the identifier GCC, no other identifiers are acceptable.
24444
24445 when Pragma_System_Name =>
24446 GNAT_Pragma;
24447 Check_No_Identifiers;
24448 Check_Arg_Count (1);
24449 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
24450
24451 -----------------------------
24452 -- Task_Dispatching_Policy --
24453 -----------------------------
24454
24455 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
24456
24457 when Pragma_Task_Dispatching_Policy => declare
24458 DP : Character;
24459
24460 begin
24461 Check_Ada_83_Warning;
24462 Check_Arg_Count (1);
24463 Check_No_Identifiers;
24464 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
24465 Check_Valid_Configuration_Pragma;
24466 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
24467 DP := Fold_Upper (Name_Buffer (1));
24468
24469 if Task_Dispatching_Policy /= ' '
24470 and then Task_Dispatching_Policy /= DP
24471 then
24472 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
24473 Error_Pragma
24474 ("task dispatching policy incompatible with policy#");
24475
24476 -- Set new policy, but always preserve System_Location since we
24477 -- like the error message with the run time name.
24478
24479 else
24480 Task_Dispatching_Policy := DP;
24481
24482 if Task_Dispatching_Policy_Sloc /= System_Location then
24483 Task_Dispatching_Policy_Sloc := Loc;
24484 end if;
24485 end if;
24486 end;
24487
24488 ---------------
24489 -- Task_Info --
24490 ---------------
24491
24492 -- pragma Task_Info (EXPRESSION);
24493
24494 when Pragma_Task_Info => Task_Info : declare
24495 P : constant Node_Id := Parent (N);
24496 Ent : Entity_Id;
24497
24498 begin
24499 GNAT_Pragma;
24500
24501 if Warn_On_Obsolescent_Feature then
24502 Error_Msg_N
24503 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
24504 & "instead?j?", N);
24505 end if;
24506
24507 if Nkind (P) /= N_Task_Definition then
24508 Error_Pragma ("pragma% must appear in task definition");
24509 end if;
24510
24511 Check_No_Identifiers;
24512 Check_Arg_Count (1);
24513
24514 Analyze_And_Resolve
24515 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
24516
24517 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
24518 return;
24519 end if;
24520
24521 Ent := Defining_Identifier (Parent (P));
24522
24523 -- Check duplicate pragma before we chain the pragma in the Rep
24524 -- Item chain of Ent.
24525
24526 if Has_Rep_Pragma
24527 (Ent, Name_Task_Info, Check_Parents => False)
24528 then
24529 Error_Pragma ("duplicate pragma% not allowed");
24530 end if;
24531
24532 Record_Rep_Item (Ent, N);
24533 end Task_Info;
24534
24535 ---------------
24536 -- Task_Name --
24537 ---------------
24538
24539 -- pragma Task_Name (string_EXPRESSION);
24540
24541 when Pragma_Task_Name => Task_Name : declare
24542 P : constant Node_Id := Parent (N);
24543 Arg : Node_Id;
24544 Ent : Entity_Id;
24545
24546 begin
24547 Check_No_Identifiers;
24548 Check_Arg_Count (1);
24549
24550 Arg := Get_Pragma_Arg (Arg1);
24551
24552 -- The expression is used in the call to Create_Task, and must be
24553 -- expanded there, not in the context of the current spec. It must
24554 -- however be analyzed to capture global references, in case it
24555 -- appears in a generic context.
24556
24557 Preanalyze_And_Resolve (Arg, Standard_String);
24558
24559 if Nkind (P) /= N_Task_Definition then
24560 Pragma_Misplaced;
24561 end if;
24562
24563 Ent := Defining_Identifier (Parent (P));
24564
24565 -- Check duplicate pragma before we chain the pragma in the Rep
24566 -- Item chain of Ent.
24567
24568 if Has_Rep_Pragma
24569 (Ent, Name_Task_Name, Check_Parents => False)
24570 then
24571 Error_Pragma ("duplicate pragma% not allowed");
24572 end if;
24573
24574 Record_Rep_Item (Ent, N);
24575 end Task_Name;
24576
24577 ------------------
24578 -- Task_Storage --
24579 ------------------
24580
24581 -- pragma Task_Storage (
24582 -- [Task_Type =>] LOCAL_NAME,
24583 -- [Top_Guard =>] static_integer_EXPRESSION);
24584
24585 when Pragma_Task_Storage => Task_Storage : declare
24586 Args : Args_List (1 .. 2);
24587 Names : constant Name_List (1 .. 2) := (
24588 Name_Task_Type,
24589 Name_Top_Guard);
24590
24591 Task_Type : Node_Id renames Args (1);
24592 Top_Guard : Node_Id renames Args (2);
24593
24594 Ent : Entity_Id;
24595
24596 begin
24597 GNAT_Pragma;
24598 Gather_Associations (Names, Args);
24599
24600 if No (Task_Type) then
24601 Error_Pragma
24602 ("missing task_type argument for pragma%");
24603 end if;
24604
24605 Check_Arg_Is_Local_Name (Task_Type);
24606
24607 Ent := Entity (Task_Type);
24608
24609 if not Is_Task_Type (Ent) then
24610 Error_Pragma_Arg
24611 ("argument for pragma% must be task type", Task_Type);
24612 end if;
24613
24614 if No (Top_Guard) then
24615 Error_Pragma_Arg
24616 ("pragma% takes two arguments", Task_Type);
24617 else
24618 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
24619 end if;
24620
24621 Check_First_Subtype (Task_Type);
24622
24623 if Rep_Item_Too_Late (Ent, N) then
24624 raise Pragma_Exit;
24625 end if;
24626 end Task_Storage;
24627
24628 ---------------
24629 -- Test_Case --
24630 ---------------
24631
24632 -- pragma Test_Case
24633 -- ([Name =>] Static_String_EXPRESSION
24634 -- ,[Mode =>] MODE_TYPE
24635 -- [, Requires => Boolean_EXPRESSION]
24636 -- [, Ensures => Boolean_EXPRESSION]);
24637
24638 -- MODE_TYPE ::= Nominal | Robustness
24639
24640 -- Characteristics:
24641
24642 -- * Analysis - The annotation undergoes initial checks to verify
24643 -- the legal placement and context. Secondary checks preanalyze the
24644 -- expressions in:
24645
24646 -- Analyze_Test_Case_In_Decl_Part
24647
24648 -- * Expansion - None.
24649
24650 -- * Template - The annotation utilizes the generic template of the
24651 -- related subprogram when it is:
24652
24653 -- aspect on subprogram declaration
24654
24655 -- The annotation must prepare its own template when it is:
24656
24657 -- pragma on subprogram declaration
24658
24659 -- * Globals - Capture of global references must occur after full
24660 -- analysis.
24661
24662 -- * Instance - The annotation is instantiated automatically when
24663 -- the related generic subprogram is instantiated except for the
24664 -- "pragma on subprogram declaration" case. In that scenario the
24665 -- annotation must instantiate itself.
24666
24667 when Pragma_Test_Case => Test_Case : declare
24668 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
24669 -- Ensure that the contract of subprogram Subp_Id does not contain
24670 -- another Test_Case pragma with the same Name as the current one.
24671
24672 -------------------------
24673 -- Check_Distinct_Name --
24674 -------------------------
24675
24676 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
24677 Items : constant Node_Id := Contract (Subp_Id);
24678 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
24679 Prag : Node_Id;
24680
24681 begin
24682 -- Inspect all Test_Case pragma of the related subprogram
24683 -- looking for one with a duplicate "Name" argument.
24684
24685 if Present (Items) then
24686 Prag := Contract_Test_Cases (Items);
24687 while Present (Prag) loop
24688 if Pragma_Name (Prag) = Name_Test_Case
24689 and then Prag /= N
24690 and then String_Equal
24691 (Name, Get_Name_From_CTC_Pragma (Prag))
24692 then
24693 Error_Msg_Sloc := Sloc (Prag);
24694 Error_Pragma ("name for pragma % is already used #");
24695 end if;
24696
24697 Prag := Next_Pragma (Prag);
24698 end loop;
24699 end if;
24700 end Check_Distinct_Name;
24701
24702 -- Local variables
24703
24704 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
24705 Asp_Arg : Node_Id;
24706 Context : Node_Id;
24707 Subp_Decl : Node_Id;
24708 Subp_Id : Entity_Id;
24709
24710 -- Start of processing for Test_Case
24711
24712 begin
24713 GNAT_Pragma;
24714 Check_At_Least_N_Arguments (2);
24715 Check_At_Most_N_Arguments (4);
24716 Check_Arg_Order
24717 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
24718
24719 -- Argument "Name"
24720
24721 Check_Optional_Identifier (Arg1, Name_Name);
24722 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
24723
24724 -- Argument "Mode"
24725
24726 Check_Optional_Identifier (Arg2, Name_Mode);
24727 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
24728
24729 -- Arguments "Requires" and "Ensures"
24730
24731 if Present (Arg3) then
24732 if Present (Arg4) then
24733 Check_Identifier (Arg3, Name_Requires);
24734 Check_Identifier (Arg4, Name_Ensures);
24735 else
24736 Check_Identifier_Is_One_Of
24737 (Arg3, Name_Requires, Name_Ensures);
24738 end if;
24739 end if;
24740
24741 -- Pragma Test_Case must be associated with a subprogram declared
24742 -- in a library-level package. First determine whether the current
24743 -- compilation unit is a legal context.
24744
24745 if Nkind_In (Pack_Decl, N_Package_Declaration,
24746 N_Generic_Package_Declaration)
24747 then
24748 null;
24749
24750 -- Otherwise the placement is illegal
24751
24752 else
24753 Error_Pragma
24754 ("pragma % must be specified within a package declaration");
24755 return;
24756 end if;
24757
24758 Subp_Decl := Find_Related_Declaration_Or_Body (N);
24759
24760 -- Find the enclosing context
24761
24762 Context := Parent (Subp_Decl);
24763
24764 if Present (Context) then
24765 Context := Parent (Context);
24766 end if;
24767
24768 -- Verify the placement of the pragma
24769
24770 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
24771 Error_Pragma
24772 ("pragma % cannot be applied to abstract subprogram");
24773 return;
24774
24775 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
24776 Error_Pragma ("pragma % cannot be applied to entry");
24777 return;
24778
24779 -- The context is a [generic] subprogram declared at the top level
24780 -- of the [generic] package unit.
24781
24782 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
24783 N_Subprogram_Declaration)
24784 and then Present (Context)
24785 and then Nkind_In (Context, N_Generic_Package_Declaration,
24786 N_Package_Declaration)
24787 then
24788 null;
24789
24790 -- Otherwise the placement is illegal
24791
24792 else
24793 Error_Pragma
24794 ("pragma % must be applied to a library-level subprogram "
24795 & "declaration");
24796 return;
24797 end if;
24798
24799 Subp_Id := Defining_Entity (Subp_Decl);
24800
24801 -- A pragma that applies to a Ghost entity becomes Ghost for the
24802 -- purposes of legality checks and removal of ignored Ghost code.
24803
24804 Mark_Ghost_Pragma (N, Subp_Id);
24805
24806 -- Chain the pragma on the contract for further processing by
24807 -- Analyze_Test_Case_In_Decl_Part.
24808
24809 Add_Contract_Item (N, Subp_Id);
24810
24811 -- Preanalyze the original aspect argument "Name" for a generic
24812 -- subprogram to properly capture global references.
24813
24814 if Is_Generic_Subprogram (Subp_Id) then
24815 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
24816
24817 if Present (Asp_Arg) then
24818
24819 -- The argument appears with an identifier in association
24820 -- form.
24821
24822 if Nkind (Asp_Arg) = N_Component_Association then
24823 Asp_Arg := Expression (Asp_Arg);
24824 end if;
24825
24826 Check_Expr_Is_OK_Static_Expression
24827 (Asp_Arg, Standard_String);
24828 end if;
24829 end if;
24830
24831 -- Ensure that the all Test_Case pragmas of the related subprogram
24832 -- have distinct names.
24833
24834 Check_Distinct_Name (Subp_Id);
24835
24836 -- Fully analyze the pragma when it appears inside an entry
24837 -- or subprogram body because it cannot benefit from forward
24838 -- references.
24839
24840 if Nkind_In (Subp_Decl, N_Entry_Body,
24841 N_Subprogram_Body,
24842 N_Subprogram_Body_Stub)
24843 then
24844 -- The legality checks of pragma Test_Case are affected by the
24845 -- SPARK mode in effect and the volatility of the context.
24846 -- Analyze all pragmas in a specific order.
24847
24848 Analyze_If_Present (Pragma_SPARK_Mode);
24849 Analyze_If_Present (Pragma_Volatile_Function);
24850 Analyze_Test_Case_In_Decl_Part (N);
24851 end if;
24852 end Test_Case;
24853
24854 --------------------------
24855 -- Thread_Local_Storage --
24856 --------------------------
24857
24858 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
24859
24860 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
24861 E : Entity_Id;
24862 Id : Node_Id;
24863
24864 begin
24865 GNAT_Pragma;
24866 Check_Arg_Count (1);
24867 Check_Optional_Identifier (Arg1, Name_Entity);
24868 Check_Arg_Is_Library_Level_Local_Name (Arg1);
24869
24870 Id := Get_Pragma_Arg (Arg1);
24871 Analyze (Id);
24872
24873 if not Is_Entity_Name (Id)
24874 or else Ekind (Entity (Id)) /= E_Variable
24875 then
24876 Error_Pragma_Arg ("local variable name required", Arg1);
24877 end if;
24878
24879 E := Entity (Id);
24880
24881 -- A pragma that applies to a Ghost entity becomes Ghost for the
24882 -- purposes of legality checks and removal of ignored Ghost code.
24883
24884 Mark_Ghost_Pragma (N, E);
24885
24886 if Rep_Item_Too_Early (E, N)
24887 or else
24888 Rep_Item_Too_Late (E, N)
24889 then
24890 raise Pragma_Exit;
24891 end if;
24892
24893 Set_Has_Pragma_Thread_Local_Storage (E);
24894 Set_Has_Gigi_Rep_Item (E);
24895 end Thread_Local_Storage;
24896
24897 ----------------
24898 -- Time_Slice --
24899 ----------------
24900
24901 -- pragma Time_Slice (static_duration_EXPRESSION);
24902
24903 when Pragma_Time_Slice => Time_Slice : declare
24904 Val : Ureal;
24905 Nod : Node_Id;
24906
24907 begin
24908 GNAT_Pragma;
24909 Check_Arg_Count (1);
24910 Check_No_Identifiers;
24911 Check_In_Main_Program;
24912 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
24913
24914 if not Error_Posted (Arg1) then
24915 Nod := Next (N);
24916 while Present (Nod) loop
24917 if Nkind (Nod) = N_Pragma
24918 and then Pragma_Name (Nod) = Name_Time_Slice
24919 then
24920 Error_Msg_Name_1 := Pname;
24921 Error_Msg_N ("duplicate pragma% not permitted", Nod);
24922 end if;
24923
24924 Next (Nod);
24925 end loop;
24926 end if;
24927
24928 -- Process only if in main unit
24929
24930 if Get_Source_Unit (Loc) = Main_Unit then
24931 Opt.Time_Slice_Set := True;
24932 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
24933
24934 if Val <= Ureal_0 then
24935 Opt.Time_Slice_Value := 0;
24936
24937 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
24938 Opt.Time_Slice_Value := 1_000_000_000;
24939
24940 else
24941 Opt.Time_Slice_Value :=
24942 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
24943 end if;
24944 end if;
24945 end Time_Slice;
24946
24947 -----------
24948 -- Title --
24949 -----------
24950
24951 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
24952
24953 -- TITLING_OPTION ::=
24954 -- [Title =>] STRING_LITERAL
24955 -- | [Subtitle =>] STRING_LITERAL
24956
24957 when Pragma_Title => Title : declare
24958 Args : Args_List (1 .. 2);
24959 Names : constant Name_List (1 .. 2) := (
24960 Name_Title,
24961 Name_Subtitle);
24962
24963 begin
24964 GNAT_Pragma;
24965 Gather_Associations (Names, Args);
24966 Store_Note (N);
24967
24968 for J in 1 .. 2 loop
24969 if Present (Args (J)) then
24970 Check_Arg_Is_OK_Static_Expression
24971 (Args (J), Standard_String);
24972 end if;
24973 end loop;
24974 end Title;
24975
24976 ----------------------------
24977 -- Type_Invariant[_Class] --
24978 ----------------------------
24979
24980 -- pragma Type_Invariant[_Class]
24981 -- ([Entity =>] type_LOCAL_NAME,
24982 -- [Check =>] EXPRESSION);
24983
24984 when Pragma_Type_Invariant
24985 | Pragma_Type_Invariant_Class
24986 =>
24987 Type_Invariant : declare
24988 I_Pragma : Node_Id;
24989
24990 begin
24991 Check_Arg_Count (2);
24992
24993 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
24994 -- setting Class_Present for the Type_Invariant_Class case.
24995
24996 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
24997 I_Pragma := New_Copy (N);
24998 Set_Pragma_Identifier
24999 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
25000 Rewrite (N, I_Pragma);
25001 Set_Analyzed (N, False);
25002 Analyze (N);
25003 end Type_Invariant;
25004
25005 ---------------------
25006 -- Unchecked_Union --
25007 ---------------------
25008
25009 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
25010
25011 when Pragma_Unchecked_Union => Unchecked_Union : declare
25012 Assoc : constant Node_Id := Arg1;
25013 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
25014 Clist : Node_Id;
25015 Comp : Node_Id;
25016 Tdef : Node_Id;
25017 Typ : Entity_Id;
25018 Variant : Node_Id;
25019 Vpart : Node_Id;
25020
25021 begin
25022 Ada_2005_Pragma;
25023 Check_No_Identifiers;
25024 Check_Arg_Count (1);
25025 Check_Arg_Is_Local_Name (Arg1);
25026
25027 Find_Type (Type_Id);
25028
25029 Typ := Entity (Type_Id);
25030
25031 -- A pragma that applies to a Ghost entity becomes Ghost for the
25032 -- purposes of legality checks and removal of ignored Ghost code.
25033
25034 Mark_Ghost_Pragma (N, Typ);
25035
25036 if Typ = Any_Type
25037 or else Rep_Item_Too_Early (Typ, N)
25038 then
25039 return;
25040 else
25041 Typ := Underlying_Type (Typ);
25042 end if;
25043
25044 if Rep_Item_Too_Late (Typ, N) then
25045 return;
25046 end if;
25047
25048 Check_First_Subtype (Arg1);
25049
25050 -- Note remaining cases are references to a type in the current
25051 -- declarative part. If we find an error, we post the error on
25052 -- the relevant type declaration at an appropriate point.
25053
25054 if not Is_Record_Type (Typ) then
25055 Error_Msg_N ("unchecked union must be record type", Typ);
25056 return;
25057
25058 elsif Is_Tagged_Type (Typ) then
25059 Error_Msg_N ("unchecked union must not be tagged", Typ);
25060 return;
25061
25062 elsif not Has_Discriminants (Typ) then
25063 Error_Msg_N
25064 ("unchecked union must have one discriminant", Typ);
25065 return;
25066
25067 -- Note: in previous versions of GNAT we used to check for limited
25068 -- types and give an error, but in fact the standard does allow
25069 -- Unchecked_Union on limited types, so this check was removed.
25070
25071 -- Similarly, GNAT used to require that all discriminants have
25072 -- default values, but this is not mandated by the RM.
25073
25074 -- Proceed with basic error checks completed
25075
25076 else
25077 Tdef := Type_Definition (Declaration_Node (Typ));
25078 Clist := Component_List (Tdef);
25079
25080 -- Check presence of component list and variant part
25081
25082 if No (Clist) or else No (Variant_Part (Clist)) then
25083 Error_Msg_N
25084 ("unchecked union must have variant part", Tdef);
25085 return;
25086 end if;
25087
25088 -- Check components
25089
25090 Comp := First_Non_Pragma (Component_Items (Clist));
25091 while Present (Comp) loop
25092 Check_Component (Comp, Typ);
25093 Next_Non_Pragma (Comp);
25094 end loop;
25095
25096 -- Check variant part
25097
25098 Vpart := Variant_Part (Clist);
25099
25100 Variant := First_Non_Pragma (Variants (Vpart));
25101 while Present (Variant) loop
25102 Check_Variant (Variant, Typ);
25103 Next_Non_Pragma (Variant);
25104 end loop;
25105 end if;
25106
25107 Set_Is_Unchecked_Union (Typ);
25108 Set_Convention (Typ, Convention_C);
25109 Set_Has_Unchecked_Union (Base_Type (Typ));
25110 Set_Is_Unchecked_Union (Base_Type (Typ));
25111 end Unchecked_Union;
25112
25113 ----------------------------
25114 -- Unevaluated_Use_Of_Old --
25115 ----------------------------
25116
25117 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
25118
25119 when Pragma_Unevaluated_Use_Of_Old =>
25120 GNAT_Pragma;
25121 Check_Arg_Count (1);
25122 Check_No_Identifiers;
25123 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
25124
25125 -- Suppress/Unsuppress can appear as a configuration pragma, or in
25126 -- a declarative part or a package spec.
25127
25128 if not Is_Configuration_Pragma then
25129 Check_Is_In_Decl_Part_Or_Package_Spec;
25130 end if;
25131
25132 -- Store proper setting of Uneval_Old
25133
25134 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
25135 Uneval_Old := Fold_Upper (Name_Buffer (1));
25136
25137 ------------------------
25138 -- Unimplemented_Unit --
25139 ------------------------
25140
25141 -- pragma Unimplemented_Unit;
25142
25143 -- Note: this only gives an error if we are generating code, or if
25144 -- we are in a generic library unit (where the pragma appears in the
25145 -- body, not in the spec).
25146
25147 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
25148 Cunitent : constant Entity_Id :=
25149 Cunit_Entity (Get_Source_Unit (Loc));
25150 Ent_Kind : constant Entity_Kind := Ekind (Cunitent);
25151
25152 begin
25153 GNAT_Pragma;
25154 Check_Arg_Count (0);
25155
25156 if Operating_Mode = Generate_Code
25157 or else Ent_Kind = E_Generic_Function
25158 or else Ent_Kind = E_Generic_Procedure
25159 or else Ent_Kind = E_Generic_Package
25160 then
25161 Get_Name_String (Chars (Cunitent));
25162 Set_Casing (Mixed_Case);
25163 Write_Str (Name_Buffer (1 .. Name_Len));
25164 Write_Str (" is not supported in this configuration");
25165 Write_Eol;
25166 raise Unrecoverable_Error;
25167 end if;
25168 end Unimplemented_Unit;
25169
25170 ------------------------
25171 -- Universal_Aliasing --
25172 ------------------------
25173
25174 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
25175
25176 when Pragma_Universal_Aliasing => Universal_Alias : declare
25177 E : Entity_Id;
25178 E_Id : Node_Id;
25179
25180 begin
25181 GNAT_Pragma;
25182 Check_Arg_Count (1);
25183 Check_Optional_Identifier (Arg2, Name_Entity);
25184 Check_Arg_Is_Local_Name (Arg1);
25185 E_Id := Get_Pragma_Arg (Arg1);
25186
25187 if Etype (E_Id) = Any_Type then
25188 return;
25189 end if;
25190
25191 E := Entity (E_Id);
25192
25193 if not Is_Type (E) then
25194 Error_Pragma_Arg ("pragma% requires type", Arg1);
25195 end if;
25196
25197 -- A pragma that applies to a Ghost entity becomes Ghost for the
25198 -- purposes of legality checks and removal of ignored Ghost code.
25199
25200 Mark_Ghost_Pragma (N, E);
25201 Set_Universal_Aliasing (Base_Type (E));
25202 Record_Rep_Item (E, N);
25203 end Universal_Alias;
25204
25205 --------------------
25206 -- Universal_Data --
25207 --------------------
25208
25209 -- pragma Universal_Data [(library_unit_NAME)];
25210
25211 when Pragma_Universal_Data =>
25212 GNAT_Pragma;
25213 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
25214
25215 ----------------
25216 -- Unmodified --
25217 ----------------
25218
25219 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
25220
25221 when Pragma_Unmodified =>
25222 Analyze_Unmodified_Or_Unused;
25223
25224 ------------------
25225 -- Unreferenced --
25226 ------------------
25227
25228 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
25229
25230 -- or when used in a context clause:
25231
25232 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
25233
25234 when Pragma_Unreferenced =>
25235 Analyze_Unreferenced_Or_Unused;
25236
25237 --------------------------
25238 -- Unreferenced_Objects --
25239 --------------------------
25240
25241 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
25242
25243 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
25244 Arg : Node_Id;
25245 Arg_Expr : Node_Id;
25246 Arg_Id : Entity_Id;
25247
25248 Ghost_Error_Posted : Boolean := False;
25249 -- Flag set when an error concerning the illegal mix of Ghost and
25250 -- non-Ghost types is emitted.
25251
25252 Ghost_Id : Entity_Id := Empty;
25253 -- The entity of the first Ghost type encountered while processing
25254 -- the arguments of the pragma.
25255
25256 begin
25257 GNAT_Pragma;
25258 Check_At_Least_N_Arguments (1);
25259
25260 Arg := Arg1;
25261 while Present (Arg) loop
25262 Check_No_Identifier (Arg);
25263 Check_Arg_Is_Local_Name (Arg);
25264 Arg_Expr := Get_Pragma_Arg (Arg);
25265
25266 if Is_Entity_Name (Arg_Expr) then
25267 Arg_Id := Entity (Arg_Expr);
25268
25269 if Is_Type (Arg_Id) then
25270 Set_Has_Pragma_Unreferenced_Objects (Arg_Id);
25271
25272 -- A pragma that applies to a Ghost entity becomes Ghost
25273 -- for the purposes of legality checks and removal of
25274 -- ignored Ghost code.
25275
25276 Mark_Ghost_Pragma (N, Arg_Id);
25277
25278 -- Capture the entity of the first Ghost type being
25279 -- processed for error detection purposes.
25280
25281 if Is_Ghost_Entity (Arg_Id) then
25282 if No (Ghost_Id) then
25283 Ghost_Id := Arg_Id;
25284 end if;
25285
25286 -- Otherwise the type is non-Ghost. It is illegal to mix
25287 -- references to Ghost and non-Ghost entities
25288 -- (SPARK RM 6.9).
25289
25290 elsif Present (Ghost_Id)
25291 and then not Ghost_Error_Posted
25292 then
25293 Ghost_Error_Posted := True;
25294
25295 Error_Msg_Name_1 := Pname;
25296 Error_Msg_N
25297 ("pragma % cannot mention ghost and non-ghost types",
25298 N);
25299
25300 Error_Msg_Sloc := Sloc (Ghost_Id);
25301 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
25302
25303 Error_Msg_Sloc := Sloc (Arg_Id);
25304 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
25305 end if;
25306 else
25307 Error_Pragma_Arg
25308 ("argument for pragma% must be type or subtype", Arg);
25309 end if;
25310 else
25311 Error_Pragma_Arg
25312 ("argument for pragma% must be type or subtype", Arg);
25313 end if;
25314
25315 Next (Arg);
25316 end loop;
25317 end Unreferenced_Objects;
25318
25319 ------------------------------
25320 -- Unreserve_All_Interrupts --
25321 ------------------------------
25322
25323 -- pragma Unreserve_All_Interrupts;
25324
25325 when Pragma_Unreserve_All_Interrupts =>
25326 GNAT_Pragma;
25327 Check_Arg_Count (0);
25328
25329 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
25330 Unreserve_All_Interrupts := True;
25331 end if;
25332
25333 ----------------
25334 -- Unsuppress --
25335 ----------------
25336
25337 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
25338
25339 when Pragma_Unsuppress =>
25340 Ada_2005_Pragma;
25341 Process_Suppress_Unsuppress (Suppress_Case => False);
25342
25343 ------------
25344 -- Unused --
25345 ------------
25346
25347 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
25348
25349 when Pragma_Unused =>
25350 Analyze_Unmodified_Or_Unused (Is_Unused => True);
25351 Analyze_Unreferenced_Or_Unused (Is_Unused => True);
25352
25353 -------------------
25354 -- Use_VADS_Size --
25355 -------------------
25356
25357 -- pragma Use_VADS_Size;
25358
25359 when Pragma_Use_VADS_Size =>
25360 GNAT_Pragma;
25361 Check_Arg_Count (0);
25362 Check_Valid_Configuration_Pragma;
25363 Use_VADS_Size := True;
25364
25365 ---------------------
25366 -- Validity_Checks --
25367 ---------------------
25368
25369 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
25370
25371 when Pragma_Validity_Checks => Validity_Checks : declare
25372 A : constant Node_Id := Get_Pragma_Arg (Arg1);
25373 S : String_Id;
25374 C : Char_Code;
25375
25376 begin
25377 GNAT_Pragma;
25378 Check_Arg_Count (1);
25379 Check_No_Identifiers;
25380
25381 -- Pragma always active unless in CodePeer or GNATprove modes,
25382 -- which use a fixed configuration of validity checks.
25383
25384 if not (CodePeer_Mode or GNATprove_Mode) then
25385 if Nkind (A) = N_String_Literal then
25386 S := Strval (A);
25387
25388 declare
25389 Slen : constant Natural := Natural (String_Length (S));
25390 Options : String (1 .. Slen);
25391 J : Positive;
25392
25393 begin
25394 -- Couldn't we use a for loop here over Options'Range???
25395
25396 J := 1;
25397 loop
25398 C := Get_String_Char (S, Pos (J));
25399
25400 -- This is a weird test, it skips setting validity
25401 -- checks entirely if any element of S is out of
25402 -- range of Character, what is that about ???
25403
25404 exit when not In_Character_Range (C);
25405 Options (J) := Get_Character (C);
25406
25407 if J = Slen then
25408 Set_Validity_Check_Options (Options);
25409 exit;
25410 else
25411 J := J + 1;
25412 end if;
25413 end loop;
25414 end;
25415
25416 elsif Nkind (A) = N_Identifier then
25417 if Chars (A) = Name_All_Checks then
25418 Set_Validity_Check_Options ("a");
25419 elsif Chars (A) = Name_On then
25420 Validity_Checks_On := True;
25421 elsif Chars (A) = Name_Off then
25422 Validity_Checks_On := False;
25423 end if;
25424 end if;
25425 end if;
25426 end Validity_Checks;
25427
25428 --------------
25429 -- Volatile --
25430 --------------
25431
25432 -- pragma Volatile (LOCAL_NAME);
25433
25434 when Pragma_Volatile =>
25435 Process_Atomic_Independent_Shared_Volatile;
25436
25437 -------------------------
25438 -- Volatile_Components --
25439 -------------------------
25440
25441 -- pragma Volatile_Components (array_LOCAL_NAME);
25442
25443 -- Volatile is handled by the same circuit as Atomic_Components
25444
25445 --------------------------
25446 -- Volatile_Full_Access --
25447 --------------------------
25448
25449 -- pragma Volatile_Full_Access (LOCAL_NAME);
25450
25451 when Pragma_Volatile_Full_Access =>
25452 GNAT_Pragma;
25453 Process_Atomic_Independent_Shared_Volatile;
25454
25455 -----------------------
25456 -- Volatile_Function --
25457 -----------------------
25458
25459 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
25460
25461 when Pragma_Volatile_Function => Volatile_Function : declare
25462 Over_Id : Entity_Id;
25463 Spec_Id : Entity_Id;
25464 Subp_Decl : Node_Id;
25465
25466 begin
25467 GNAT_Pragma;
25468 Check_No_Identifiers;
25469 Check_At_Most_N_Arguments (1);
25470
25471 Subp_Decl :=
25472 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
25473
25474 -- Generic subprogram
25475
25476 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
25477 null;
25478
25479 -- Body acts as spec
25480
25481 elsif Nkind (Subp_Decl) = N_Subprogram_Body
25482 and then No (Corresponding_Spec (Subp_Decl))
25483 then
25484 null;
25485
25486 -- Body stub acts as spec
25487
25488 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
25489 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
25490 then
25491 null;
25492
25493 -- Subprogram
25494
25495 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
25496 null;
25497
25498 else
25499 Pragma_Misplaced;
25500 return;
25501 end if;
25502
25503 Spec_Id := Unique_Defining_Entity (Subp_Decl);
25504
25505 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
25506 Pragma_Misplaced;
25507 return;
25508 end if;
25509
25510 -- A pragma that applies to a Ghost entity becomes Ghost for the
25511 -- purposes of legality checks and removal of ignored Ghost code.
25512
25513 Mark_Ghost_Pragma (N, Spec_Id);
25514
25515 -- Chain the pragma on the contract for completeness
25516
25517 Add_Contract_Item (N, Spec_Id);
25518
25519 -- The legality checks of pragma Volatile_Function are affected by
25520 -- the SPARK mode in effect. Analyze all pragmas in a specific
25521 -- order.
25522
25523 Analyze_If_Present (Pragma_SPARK_Mode);
25524
25525 -- A volatile function cannot override a non-volatile function
25526 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
25527 -- in New_Overloaded_Entity, however at that point the pragma has
25528 -- not been processed yet.
25529
25530 Over_Id := Overridden_Operation (Spec_Id);
25531
25532 if Present (Over_Id)
25533 and then not Is_Volatile_Function (Over_Id)
25534 then
25535 Error_Msg_N
25536 ("incompatible volatile function values in effect", Spec_Id);
25537
25538 Error_Msg_Sloc := Sloc (Over_Id);
25539 Error_Msg_N
25540 ("\& declared # with Volatile_Function value False",
25541 Spec_Id);
25542
25543 Error_Msg_Sloc := Sloc (Spec_Id);
25544 Error_Msg_N
25545 ("\overridden # with Volatile_Function value True",
25546 Spec_Id);
25547 end if;
25548
25549 -- Analyze the Boolean expression (if any)
25550
25551 if Present (Arg1) then
25552 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
25553 end if;
25554 end Volatile_Function;
25555
25556 ----------------------
25557 -- Warning_As_Error --
25558 ----------------------
25559
25560 -- pragma Warning_As_Error (static_string_EXPRESSION);
25561
25562 when Pragma_Warning_As_Error =>
25563 GNAT_Pragma;
25564 Check_Arg_Count (1);
25565 Check_No_Identifiers;
25566 Check_Valid_Configuration_Pragma;
25567
25568 if not Is_Static_String_Expression (Arg1) then
25569 Error_Pragma_Arg
25570 ("argument of pragma% must be static string expression",
25571 Arg1);
25572
25573 -- OK static string expression
25574
25575 else
25576 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
25577 Warnings_As_Errors (Warnings_As_Errors_Count) :=
25578 new String'(Acquire_Warning_Match_String
25579 (Expr_Value_S (Get_Pragma_Arg (Arg1))));
25580 end if;
25581
25582 --------------
25583 -- Warnings --
25584 --------------
25585
25586 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
25587
25588 -- DETAILS ::= On | Off
25589 -- DETAILS ::= On | Off, local_NAME
25590 -- DETAILS ::= static_string_EXPRESSION
25591 -- DETAILS ::= On | Off, static_string_EXPRESSION
25592
25593 -- TOOL_NAME ::= GNAT | GNATProve
25594
25595 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
25596
25597 -- Note: If the first argument matches an allowed tool name, it is
25598 -- always considered to be a tool name, even if there is a string
25599 -- variable of that name.
25600
25601 -- Note if the second argument of DETAILS is a local_NAME then the
25602 -- second form is always understood. If the intention is to use
25603 -- the fourth form, then you can write NAME & "" to force the
25604 -- intepretation as a static_string_EXPRESSION.
25605
25606 when Pragma_Warnings => Warnings : declare
25607 Reason : String_Id;
25608
25609 begin
25610 GNAT_Pragma;
25611 Check_At_Least_N_Arguments (1);
25612
25613 -- See if last argument is labeled Reason. If so, make sure we
25614 -- have a string literal or a concatenation of string literals,
25615 -- and acquire the REASON string. Then remove the REASON argument
25616 -- by decreasing Num_Args by one; Remaining processing looks only
25617 -- at first Num_Args arguments).
25618
25619 declare
25620 Last_Arg : constant Node_Id :=
25621 Last (Pragma_Argument_Associations (N));
25622
25623 begin
25624 if Nkind (Last_Arg) = N_Pragma_Argument_Association
25625 and then Chars (Last_Arg) = Name_Reason
25626 then
25627 Start_String;
25628 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
25629 Reason := End_String;
25630 Arg_Count := Arg_Count - 1;
25631
25632 -- Not allowed in compiler units (bootstrap issues)
25633
25634 Check_Compiler_Unit ("Reason for pragma Warnings", N);
25635
25636 -- No REASON string, set null string as reason
25637
25638 else
25639 Reason := Null_String_Id;
25640 end if;
25641 end;
25642
25643 -- Now proceed with REASON taken care of and eliminated
25644
25645 Check_No_Identifiers;
25646
25647 -- If debug flag -gnatd.i is set, pragma is ignored
25648
25649 if Debug_Flag_Dot_I then
25650 return;
25651 end if;
25652
25653 -- Process various forms of the pragma
25654
25655 declare
25656 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
25657 Shifted_Args : List_Id;
25658
25659 begin
25660 -- See if first argument is a tool name, currently either
25661 -- GNAT or GNATprove. If so, either ignore the pragma if the
25662 -- tool used does not match, or continue as if no tool name
25663 -- was given otherwise, by shifting the arguments.
25664
25665 if Nkind (Argx) = N_Identifier
25666 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
25667 then
25668 if Chars (Argx) = Name_Gnat then
25669 if CodePeer_Mode or GNATprove_Mode then
25670 Rewrite (N, Make_Null_Statement (Loc));
25671 Analyze (N);
25672 raise Pragma_Exit;
25673 end if;
25674
25675 elsif Chars (Argx) = Name_Gnatprove then
25676 if not GNATprove_Mode then
25677 Rewrite (N, Make_Null_Statement (Loc));
25678 Analyze (N);
25679 raise Pragma_Exit;
25680 end if;
25681
25682 else
25683 raise Program_Error;
25684 end if;
25685
25686 -- At this point, the pragma Warnings applies to the tool,
25687 -- so continue with shifted arguments.
25688
25689 Arg_Count := Arg_Count - 1;
25690
25691 if Arg_Count = 1 then
25692 Shifted_Args := New_List (New_Copy (Arg2));
25693 elsif Arg_Count = 2 then
25694 Shifted_Args := New_List (New_Copy (Arg2),
25695 New_Copy (Arg3));
25696 elsif Arg_Count = 3 then
25697 Shifted_Args := New_List (New_Copy (Arg2),
25698 New_Copy (Arg3),
25699 New_Copy (Arg4));
25700 else
25701 raise Program_Error;
25702 end if;
25703
25704 Rewrite (N,
25705 Make_Pragma (Loc,
25706 Chars => Name_Warnings,
25707 Pragma_Argument_Associations => Shifted_Args));
25708 Analyze (N);
25709 raise Pragma_Exit;
25710 end if;
25711
25712 -- One argument case
25713
25714 if Arg_Count = 1 then
25715
25716 -- On/Off one argument case was processed by parser
25717
25718 if Nkind (Argx) = N_Identifier
25719 and then Nam_In (Chars (Argx), Name_On, Name_Off)
25720 then
25721 null;
25722
25723 -- One argument case must be ON/OFF or static string expr
25724
25725 elsif not Is_Static_String_Expression (Arg1) then
25726 Error_Pragma_Arg
25727 ("argument of pragma% must be On/Off or static string "
25728 & "expression", Arg1);
25729
25730 -- One argument string expression case
25731
25732 else
25733 declare
25734 Lit : constant Node_Id := Expr_Value_S (Argx);
25735 Str : constant String_Id := Strval (Lit);
25736 Len : constant Nat := String_Length (Str);
25737 C : Char_Code;
25738 J : Nat;
25739 OK : Boolean;
25740 Chr : Character;
25741
25742 begin
25743 J := 1;
25744 while J <= Len loop
25745 C := Get_String_Char (Str, J);
25746 OK := In_Character_Range (C);
25747
25748 if OK then
25749 Chr := Get_Character (C);
25750
25751 -- Dash case: only -Wxxx is accepted
25752
25753 if J = 1
25754 and then J < Len
25755 and then Chr = '-'
25756 then
25757 J := J + 1;
25758 C := Get_String_Char (Str, J);
25759 Chr := Get_Character (C);
25760 exit when Chr = 'W';
25761 OK := False;
25762
25763 -- Dot case
25764
25765 elsif J < Len and then Chr = '.' then
25766 J := J + 1;
25767 C := Get_String_Char (Str, J);
25768 Chr := Get_Character (C);
25769
25770 if not Set_Dot_Warning_Switch (Chr) then
25771 Error_Pragma_Arg
25772 ("invalid warning switch character "
25773 & '.' & Chr, Arg1);
25774 end if;
25775
25776 -- Non-Dot case
25777
25778 else
25779 OK := Set_Warning_Switch (Chr);
25780 end if;
25781
25782 if not OK then
25783 Error_Pragma_Arg
25784 ("invalid warning switch character " & Chr,
25785 Arg1);
25786 end if;
25787
25788 else
25789 Error_Pragma_Arg
25790 ("invalid wide character in warning switch ",
25791 Arg1);
25792 end if;
25793
25794 J := J + 1;
25795 end loop;
25796 end;
25797 end if;
25798
25799 -- Two or more arguments (must be two)
25800
25801 else
25802 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
25803 Check_Arg_Count (2);
25804
25805 declare
25806 E_Id : Node_Id;
25807 E : Entity_Id;
25808 Err : Boolean;
25809
25810 begin
25811 E_Id := Get_Pragma_Arg (Arg2);
25812 Analyze (E_Id);
25813
25814 -- In the expansion of an inlined body, a reference to
25815 -- the formal may be wrapped in a conversion if the
25816 -- actual is a conversion. Retrieve the real entity name.
25817
25818 if (In_Instance_Body or In_Inlined_Body)
25819 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
25820 then
25821 E_Id := Expression (E_Id);
25822 end if;
25823
25824 -- Entity name case
25825
25826 if Is_Entity_Name (E_Id) then
25827 E := Entity (E_Id);
25828
25829 if E = Any_Id then
25830 return;
25831 else
25832 loop
25833 Set_Warnings_Off
25834 (E, (Chars (Get_Pragma_Arg (Arg1)) =
25835 Name_Off));
25836
25837 -- Suppress elaboration warnings if the entity
25838 -- denotes an elaboration target.
25839
25840 if Is_Elaboration_Target (E) then
25841 Set_Is_Elaboration_Warnings_OK_Id (E, False);
25842 end if;
25843
25844 -- For OFF case, make entry in warnings off
25845 -- pragma table for later processing. But we do
25846 -- not do that within an instance, since these
25847 -- warnings are about what is needed in the
25848 -- template, not an instance of it.
25849
25850 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
25851 and then Warn_On_Warnings_Off
25852 and then not In_Instance
25853 then
25854 Warnings_Off_Pragmas.Append ((N, E, Reason));
25855 end if;
25856
25857 if Is_Enumeration_Type (E) then
25858 declare
25859 Lit : Entity_Id;
25860 begin
25861 Lit := First_Literal (E);
25862 while Present (Lit) loop
25863 Set_Warnings_Off (Lit);
25864 Next_Literal (Lit);
25865 end loop;
25866 end;
25867 end if;
25868
25869 exit when No (Homonym (E));
25870 E := Homonym (E);
25871 end loop;
25872 end if;
25873
25874 -- Error if not entity or static string expression case
25875
25876 elsif not Is_Static_String_Expression (Arg2) then
25877 Error_Pragma_Arg
25878 ("second argument of pragma% must be entity name "
25879 & "or static string expression", Arg2);
25880
25881 -- Static string expression case
25882
25883 else
25884 -- Note on configuration pragma case: If this is a
25885 -- configuration pragma, then for an OFF pragma, we
25886 -- just set Config True in the call, which is all
25887 -- that needs to be done. For the case of ON, this
25888 -- is normally an error, unless it is canceling the
25889 -- effect of a previous OFF pragma in the same file.
25890 -- In any other case, an error will be signalled (ON
25891 -- with no matching OFF).
25892
25893 -- Note: We set Used if we are inside a generic to
25894 -- disable the test that the non-config case actually
25895 -- cancels a warning. That's because we can't be sure
25896 -- there isn't an instantiation in some other unit
25897 -- where a warning is suppressed.
25898
25899 -- We could do a little better here by checking if the
25900 -- generic unit we are inside is public, but for now
25901 -- we don't bother with that refinement.
25902
25903 declare
25904 Message : constant String :=
25905 Acquire_Warning_Match_String
25906 (Expr_Value_S (Get_Pragma_Arg (Arg2)));
25907 begin
25908 if Chars (Argx) = Name_Off then
25909 Set_Specific_Warning_Off
25910 (Loc, Message, Reason,
25911 Config => Is_Configuration_Pragma,
25912 Used => Inside_A_Generic or else In_Instance);
25913
25914 elsif Chars (Argx) = Name_On then
25915 Set_Specific_Warning_On (Loc, Message, Err);
25916
25917 if Err then
25918 Error_Msg
25919 ("??pragma Warnings On with no matching "
25920 & "Warnings Off", Loc);
25921 end if;
25922 end if;
25923 end;
25924 end if;
25925 end;
25926 end if;
25927 end;
25928 end Warnings;
25929
25930 -------------------
25931 -- Weak_External --
25932 -------------------
25933
25934 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
25935
25936 when Pragma_Weak_External => Weak_External : declare
25937 Ent : Entity_Id;
25938
25939 begin
25940 GNAT_Pragma;
25941 Check_Arg_Count (1);
25942 Check_Optional_Identifier (Arg1, Name_Entity);
25943 Check_Arg_Is_Library_Level_Local_Name (Arg1);
25944 Ent := Entity (Get_Pragma_Arg (Arg1));
25945
25946 if Rep_Item_Too_Early (Ent, N) then
25947 return;
25948 else
25949 Ent := Underlying_Type (Ent);
25950 end if;
25951
25952 -- The pragma applies to entities with addresses
25953
25954 if Is_Type (Ent) then
25955 Error_Pragma ("pragma applies to objects and subprograms");
25956 end if;
25957
25958 -- The only processing required is to link this item on to the
25959 -- list of rep items for the given entity. This is accomplished
25960 -- by the call to Rep_Item_Too_Late (when no error is detected
25961 -- and False is returned).
25962
25963 if Rep_Item_Too_Late (Ent, N) then
25964 return;
25965 else
25966 Set_Has_Gigi_Rep_Item (Ent);
25967 end if;
25968 end Weak_External;
25969
25970 -----------------------------
25971 -- Wide_Character_Encoding --
25972 -----------------------------
25973
25974 -- pragma Wide_Character_Encoding (IDENTIFIER);
25975
25976 when Pragma_Wide_Character_Encoding =>
25977 GNAT_Pragma;
25978
25979 -- Nothing to do, handled in parser. Note that we do not enforce
25980 -- configuration pragma placement, this pragma can appear at any
25981 -- place in the source, allowing mixed encodings within a single
25982 -- source program.
25983
25984 null;
25985
25986 --------------------
25987 -- Unknown_Pragma --
25988 --------------------
25989
25990 -- Should be impossible, since the case of an unknown pragma is
25991 -- separately processed before the case statement is entered.
25992
25993 when Unknown_Pragma =>
25994 raise Program_Error;
25995 end case;
25996
25997 -- AI05-0144: detect dangerous order dependence. Disabled for now,
25998 -- until AI is formally approved.
25999
26000 -- Check_Order_Dependence;
26001
26002 exception
26003 when Pragma_Exit => null;
26004 end Analyze_Pragma;
26005
26006 ---------------------------------------------
26007 -- Analyze_Pre_Post_Condition_In_Decl_Part --
26008 ---------------------------------------------
26009
26010 -- WARNING: This routine manages Ghost regions. Return statements must be
26011 -- replaced by gotos which jump to the end of the routine and restore the
26012 -- Ghost mode.
26013
26014 procedure Analyze_Pre_Post_Condition_In_Decl_Part
26015 (N : Node_Id;
26016 Freeze_Id : Entity_Id := Empty)
26017 is
26018 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
26019 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
26020
26021 Disp_Typ : Entity_Id;
26022 -- The dispatching type of the subprogram subject to the pre- or
26023 -- postcondition.
26024
26025 function Check_References (Nod : Node_Id) return Traverse_Result;
26026 -- Check that expression Nod does not mention non-primitives of the
26027 -- type, global objects of the type, or other illegalities described
26028 -- and implied by AI12-0113.
26029
26030 ----------------------
26031 -- Check_References --
26032 ----------------------
26033
26034 function Check_References (Nod : Node_Id) return Traverse_Result is
26035 begin
26036 if Nkind (Nod) = N_Function_Call
26037 and then Is_Entity_Name (Name (Nod))
26038 then
26039 declare
26040 Func : constant Entity_Id := Entity (Name (Nod));
26041 Form : Entity_Id;
26042
26043 begin
26044 -- An operation of the type must be a primitive
26045
26046 if No (Find_Dispatching_Type (Func)) then
26047 Form := First_Formal (Func);
26048 while Present (Form) loop
26049 if Etype (Form) = Disp_Typ then
26050 Error_Msg_NE
26051 ("operation in class-wide condition must be "
26052 & "primitive of &", Nod, Disp_Typ);
26053 end if;
26054
26055 Next_Formal (Form);
26056 end loop;
26057
26058 -- A return object of the type is illegal as well
26059
26060 if Etype (Func) = Disp_Typ
26061 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
26062 then
26063 Error_Msg_NE
26064 ("operation in class-wide condition must be primitive "
26065 & "of &", Nod, Disp_Typ);
26066 end if;
26067
26068 -- Otherwise we have a call to an overridden primitive, and we
26069 -- will create a common class-wide clone for the body of
26070 -- original operation and its eventual inherited versions. If
26071 -- the original operation dispatches on result it is never
26072 -- inherited and there is no need for a clone. There is not
26073 -- need for a clone either in GNATprove mode, as cases that
26074 -- would require it are rejected (when an inherited primitive
26075 -- calls an overridden operation in a class-wide contract), and
26076 -- the clone would make proof impossible in some cases.
26077
26078 elsif not Is_Abstract_Subprogram (Spec_Id)
26079 and then No (Class_Wide_Clone (Spec_Id))
26080 and then not Has_Controlling_Result (Spec_Id)
26081 and then not GNATprove_Mode
26082 then
26083 Build_Class_Wide_Clone_Decl (Spec_Id);
26084 end if;
26085 end;
26086
26087 elsif Is_Entity_Name (Nod)
26088 and then
26089 (Etype (Nod) = Disp_Typ
26090 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
26091 and then Ekind_In (Entity (Nod), E_Constant, E_Variable)
26092 then
26093 Error_Msg_NE
26094 ("object in class-wide condition must be formal of type &",
26095 Nod, Disp_Typ);
26096
26097 elsif Nkind (Nod) = N_Explicit_Dereference
26098 and then (Etype (Nod) = Disp_Typ
26099 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
26100 and then (not Is_Entity_Name (Prefix (Nod))
26101 or else not Is_Formal (Entity (Prefix (Nod))))
26102 then
26103 Error_Msg_NE
26104 ("operation in class-wide condition must be primitive of &",
26105 Nod, Disp_Typ);
26106 end if;
26107
26108 return OK;
26109 end Check_References;
26110
26111 procedure Check_Class_Wide_Condition is
26112 new Traverse_Proc (Check_References);
26113
26114 -- Local variables
26115
26116 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
26117
26118 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
26119 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
26120 -- Save the Ghost-related attributes to restore on exit
26121
26122 Errors : Nat;
26123 Restore_Scope : Boolean := False;
26124
26125 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
26126
26127 begin
26128 -- Do not analyze the pragma multiple times
26129
26130 if Is_Analyzed_Pragma (N) then
26131 return;
26132 end if;
26133
26134 -- Set the Ghost mode in effect from the pragma. Due to the delayed
26135 -- analysis of the pragma, the Ghost mode at point of declaration and
26136 -- point of analysis may not necessarily be the same. Use the mode in
26137 -- effect at the point of declaration.
26138
26139 Set_Ghost_Mode (N);
26140
26141 -- Ensure that the subprogram and its formals are visible when analyzing
26142 -- the expression of the pragma.
26143
26144 if not In_Open_Scopes (Spec_Id) then
26145 Restore_Scope := True;
26146 Push_Scope (Spec_Id);
26147
26148 if Is_Generic_Subprogram (Spec_Id) then
26149 Install_Generic_Formals (Spec_Id);
26150 else
26151 Install_Formals (Spec_Id);
26152 end if;
26153 end if;
26154
26155 Errors := Serious_Errors_Detected;
26156 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
26157
26158 -- Emit a clarification message when the expression contains at least
26159 -- one undefined reference, possibly due to contract freezing.
26160
26161 if Errors /= Serious_Errors_Detected
26162 and then Present (Freeze_Id)
26163 and then Has_Undefined_Reference (Expr)
26164 then
26165 Contract_Freeze_Error (Spec_Id, Freeze_Id);
26166 end if;
26167
26168 if Class_Present (N) then
26169
26170 -- Verify that a class-wide condition is legal, i.e. the operation is
26171 -- a primitive of a tagged type. Note that a generic subprogram is
26172 -- not a primitive operation.
26173
26174 Disp_Typ := Find_Dispatching_Type (Spec_Id);
26175
26176 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
26177 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
26178
26179 if From_Aspect_Specification (N) then
26180 Error_Msg_N
26181 ("aspect % can only be specified for a primitive operation "
26182 & "of a tagged type", Corresponding_Aspect (N));
26183
26184 -- The pragma is a source construct
26185
26186 else
26187 Error_Msg_N
26188 ("pragma % can only be specified for a primitive operation "
26189 & "of a tagged type", N);
26190 end if;
26191
26192 -- Remaining semantic checks require a full tree traversal
26193
26194 else
26195 Check_Class_Wide_Condition (Expr);
26196 end if;
26197
26198 end if;
26199
26200 if Restore_Scope then
26201 End_Scope;
26202 end if;
26203
26204 -- If analysis of the condition indicates that a class-wide clone
26205 -- has been created, build and analyze its declaration.
26206
26207 if Is_Subprogram (Spec_Id)
26208 and then Present (Class_Wide_Clone (Spec_Id))
26209 then
26210 Analyze (Unit_Declaration_Node (Class_Wide_Clone (Spec_Id)));
26211 end if;
26212
26213 -- Currently it is not possible to inline pre/postconditions on a
26214 -- subprogram subject to pragma Inline_Always.
26215
26216 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
26217 Set_Is_Analyzed_Pragma (N);
26218
26219 Restore_Ghost_Region (Saved_GM, Saved_IGR);
26220 end Analyze_Pre_Post_Condition_In_Decl_Part;
26221
26222 ------------------------------------------
26223 -- Analyze_Refined_Depends_In_Decl_Part --
26224 ------------------------------------------
26225
26226 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
26227 procedure Check_Dependency_Clause
26228 (Spec_Id : Entity_Id;
26229 Dep_Clause : Node_Id;
26230 Dep_States : Elist_Id;
26231 Refinements : List_Id;
26232 Matched_Items : in out Elist_Id);
26233 -- Try to match a single dependency clause Dep_Clause against one or
26234 -- more refinement clauses found in list Refinements. Each successful
26235 -- match eliminates at least one refinement clause from Refinements.
26236 -- Spec_Id denotes the entity of the related subprogram. Dep_States
26237 -- denotes the entities of all abstract states which appear in pragma
26238 -- Depends. Matched_Items contains the entities of all successfully
26239 -- matched items found in pragma Depends.
26240
26241 procedure Check_Output_States
26242 (Spec_Inputs : Elist_Id;
26243 Spec_Outputs : Elist_Id;
26244 Body_Inputs : Elist_Id;
26245 Body_Outputs : Elist_Id);
26246 -- Determine whether pragma Depends contains an output state with a
26247 -- visible refinement and if so, ensure that pragma Refined_Depends
26248 -- mentions all its constituents as outputs. Spec_Inputs and
26249 -- Spec_Outputs denote the inputs and outputs of the subprogram spec
26250 -- synthesized from pragma Depends. Body_Inputs and Body_Outputs denote
26251 -- the inputs and outputs of the subprogram body synthesized from pragma
26252 -- Refined_Depends.
26253
26254 function Collect_States (Clauses : List_Id) return Elist_Id;
26255 -- Given a normalized list of dependencies obtained from calling
26256 -- Normalize_Clauses, return a list containing the entities of all
26257 -- states appearing in dependencies. It helps in checking refinements
26258 -- involving a state and a corresponding constituent which is not a
26259 -- direct constituent of the state.
26260
26261 procedure Normalize_Clauses (Clauses : List_Id);
26262 -- Given a list of dependence or refinement clauses Clauses, normalize
26263 -- each clause by creating multiple dependencies with exactly one input
26264 -- and one output.
26265
26266 procedure Remove_Extra_Clauses
26267 (Clauses : List_Id;
26268 Matched_Items : Elist_Id);
26269 -- Given a list of refinement clauses Clauses, remove all clauses whose
26270 -- inputs and/or outputs have been previously matched. See the body for
26271 -- all special cases. Matched_Items contains the entities of all matched
26272 -- items found in pragma Depends.
26273
26274 procedure Report_Extra_Clauses (Clauses : List_Id);
26275 -- Emit an error for each extra clause found in list Clauses
26276
26277 -----------------------------
26278 -- Check_Dependency_Clause --
26279 -----------------------------
26280
26281 procedure Check_Dependency_Clause
26282 (Spec_Id : Entity_Id;
26283 Dep_Clause : Node_Id;
26284 Dep_States : Elist_Id;
26285 Refinements : List_Id;
26286 Matched_Items : in out Elist_Id)
26287 is
26288 Dep_Input : constant Node_Id := Expression (Dep_Clause);
26289 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
26290
26291 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
26292 -- Determine whether dependency item Dep_Item has been matched in a
26293 -- previous clause.
26294
26295 function Is_In_Out_State_Clause return Boolean;
26296 -- Determine whether dependence clause Dep_Clause denotes an abstract
26297 -- state that depends on itself (State => State).
26298
26299 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
26300 -- Determine whether item Item denotes an abstract state with visible
26301 -- null refinement.
26302
26303 procedure Match_Items
26304 (Dep_Item : Node_Id;
26305 Ref_Item : Node_Id;
26306 Matched : out Boolean);
26307 -- Try to match dependence item Dep_Item against refinement item
26308 -- Ref_Item. To match against a possible null refinement (see 2, 9),
26309 -- set Ref_Item to Empty. Flag Matched is set to True when one of
26310 -- the following conformance scenarios is in effect:
26311 -- 1) Both items denote null
26312 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
26313 -- 3) Both items denote attribute 'Result
26314 -- 4) Both items denote the same object
26315 -- 5) Both items denote the same formal parameter
26316 -- 6) Both items denote the same current instance of a type
26317 -- 7) Both items denote the same discriminant
26318 -- 8) Dep_Item is an abstract state with visible null refinement
26319 -- and Ref_Item denotes null.
26320 -- 9) Dep_Item is an abstract state with visible null refinement
26321 -- and Ref_Item is Empty (special case).
26322 -- 10) Dep_Item is an abstract state with full or partial visible
26323 -- non-null refinement and Ref_Item denotes one of its
26324 -- constituents.
26325 -- 11) Dep_Item is an abstract state without a full visible
26326 -- refinement and Ref_Item denotes the same state.
26327 -- When scenario 10 is in effect, the entity of the abstract state
26328 -- denoted by Dep_Item is added to list Refined_States.
26329
26330 procedure Record_Item (Item_Id : Entity_Id);
26331 -- Store the entity of an item denoted by Item_Id in Matched_Items
26332
26333 ------------------------
26334 -- Is_Already_Matched --
26335 ------------------------
26336
26337 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean is
26338 Item_Id : Entity_Id := Empty;
26339
26340 begin
26341 -- When the dependency item denotes attribute 'Result, check for
26342 -- the entity of the related subprogram.
26343
26344 if Is_Attribute_Result (Dep_Item) then
26345 Item_Id := Spec_Id;
26346
26347 elsif Is_Entity_Name (Dep_Item) then
26348 Item_Id := Available_View (Entity_Of (Dep_Item));
26349 end if;
26350
26351 return
26352 Present (Item_Id) and then Contains (Matched_Items, Item_Id);
26353 end Is_Already_Matched;
26354
26355 ----------------------------
26356 -- Is_In_Out_State_Clause --
26357 ----------------------------
26358
26359 function Is_In_Out_State_Clause return Boolean is
26360 Dep_Input_Id : Entity_Id;
26361 Dep_Output_Id : Entity_Id;
26362
26363 begin
26364 -- Detect the following clause:
26365 -- State => State
26366
26367 if Is_Entity_Name (Dep_Input)
26368 and then Is_Entity_Name (Dep_Output)
26369 then
26370 -- Handle abstract views generated for limited with clauses
26371
26372 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
26373 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
26374
26375 return
26376 Ekind (Dep_Input_Id) = E_Abstract_State
26377 and then Dep_Input_Id = Dep_Output_Id;
26378 else
26379 return False;
26380 end if;
26381 end Is_In_Out_State_Clause;
26382
26383 ---------------------------
26384 -- Is_Null_Refined_State --
26385 ---------------------------
26386
26387 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
26388 Item_Id : Entity_Id;
26389
26390 begin
26391 if Is_Entity_Name (Item) then
26392
26393 -- Handle abstract views generated for limited with clauses
26394
26395 Item_Id := Available_View (Entity_Of (Item));
26396
26397 return
26398 Ekind (Item_Id) = E_Abstract_State
26399 and then Has_Null_Visible_Refinement (Item_Id);
26400 else
26401 return False;
26402 end if;
26403 end Is_Null_Refined_State;
26404
26405 -----------------
26406 -- Match_Items --
26407 -----------------
26408
26409 procedure Match_Items
26410 (Dep_Item : Node_Id;
26411 Ref_Item : Node_Id;
26412 Matched : out Boolean)
26413 is
26414 Dep_Item_Id : Entity_Id;
26415 Ref_Item_Id : Entity_Id;
26416
26417 begin
26418 -- Assume that the two items do not match
26419
26420 Matched := False;
26421
26422 -- A null matches null or Empty (special case)
26423
26424 if Nkind (Dep_Item) = N_Null
26425 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
26426 then
26427 Matched := True;
26428
26429 -- Attribute 'Result matches attribute 'Result
26430
26431 elsif Is_Attribute_Result (Dep_Item)
26432 and then Is_Attribute_Result (Ref_Item)
26433 then
26434 -- Put the entity of the related function on the list of
26435 -- matched items because attribute 'Result does not carry
26436 -- an entity similar to states and constituents.
26437
26438 Record_Item (Spec_Id);
26439 Matched := True;
26440
26441 -- Abstract states, current instances of concurrent types,
26442 -- discriminants, formal parameters and objects.
26443
26444 elsif Is_Entity_Name (Dep_Item) then
26445
26446 -- Handle abstract views generated for limited with clauses
26447
26448 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
26449
26450 if Ekind (Dep_Item_Id) = E_Abstract_State then
26451
26452 -- An abstract state with visible null refinement matches
26453 -- null or Empty (special case).
26454
26455 if Has_Null_Visible_Refinement (Dep_Item_Id)
26456 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
26457 then
26458 Record_Item (Dep_Item_Id);
26459 Matched := True;
26460
26461 -- An abstract state with visible non-null refinement
26462 -- matches one of its constituents, or itself for an
26463 -- abstract state with partial visible refinement.
26464
26465 elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then
26466 if Is_Entity_Name (Ref_Item) then
26467 Ref_Item_Id := Entity_Of (Ref_Item);
26468
26469 if Ekind_In (Ref_Item_Id, E_Abstract_State,
26470 E_Constant,
26471 E_Variable)
26472 and then Present (Encapsulating_State (Ref_Item_Id))
26473 and then Find_Encapsulating_State
26474 (Dep_States, Ref_Item_Id) = Dep_Item_Id
26475 then
26476 Record_Item (Dep_Item_Id);
26477 Matched := True;
26478
26479 elsif not Has_Visible_Refinement (Dep_Item_Id)
26480 and then Ref_Item_Id = Dep_Item_Id
26481 then
26482 Record_Item (Dep_Item_Id);
26483 Matched := True;
26484 end if;
26485 end if;
26486
26487 -- An abstract state without a visible refinement matches
26488 -- itself.
26489
26490 elsif Is_Entity_Name (Ref_Item)
26491 and then Entity_Of (Ref_Item) = Dep_Item_Id
26492 then
26493 Record_Item (Dep_Item_Id);
26494 Matched := True;
26495 end if;
26496
26497 -- A current instance of a concurrent type, discriminant,
26498 -- formal parameter or an object matches itself.
26499
26500 elsif Is_Entity_Name (Ref_Item)
26501 and then Entity_Of (Ref_Item) = Dep_Item_Id
26502 then
26503 Record_Item (Dep_Item_Id);
26504 Matched := True;
26505 end if;
26506 end if;
26507 end Match_Items;
26508
26509 -----------------
26510 -- Record_Item --
26511 -----------------
26512
26513 procedure Record_Item (Item_Id : Entity_Id) is
26514 begin
26515 if No (Matched_Items) then
26516 Matched_Items := New_Elmt_List;
26517 end if;
26518
26519 Append_Unique_Elmt (Item_Id, Matched_Items);
26520 end Record_Item;
26521
26522 -- Local variables
26523
26524 Clause_Matched : Boolean := False;
26525 Dummy : Boolean := False;
26526 Inputs_Match : Boolean;
26527 Next_Ref_Clause : Node_Id;
26528 Outputs_Match : Boolean;
26529 Ref_Clause : Node_Id;
26530 Ref_Input : Node_Id;
26531 Ref_Output : Node_Id;
26532
26533 -- Start of processing for Check_Dependency_Clause
26534
26535 begin
26536 -- Do not perform this check in an instance because it was already
26537 -- performed successfully in the generic template.
26538
26539 if In_Instance then
26540 return;
26541 end if;
26542
26543 -- Examine all refinement clauses and compare them against the
26544 -- dependence clause.
26545
26546 Ref_Clause := First (Refinements);
26547 while Present (Ref_Clause) loop
26548 Next_Ref_Clause := Next (Ref_Clause);
26549
26550 -- Obtain the attributes of the current refinement clause
26551
26552 Ref_Input := Expression (Ref_Clause);
26553 Ref_Output := First (Choices (Ref_Clause));
26554
26555 -- The current refinement clause matches the dependence clause
26556 -- when both outputs match and both inputs match. See routine
26557 -- Match_Items for all possible conformance scenarios.
26558
26559 -- Depends Dep_Output => Dep_Input
26560 -- ^ ^
26561 -- match ? match ?
26562 -- v v
26563 -- Refined_Depends Ref_Output => Ref_Input
26564
26565 Match_Items
26566 (Dep_Item => Dep_Input,
26567 Ref_Item => Ref_Input,
26568 Matched => Inputs_Match);
26569
26570 Match_Items
26571 (Dep_Item => Dep_Output,
26572 Ref_Item => Ref_Output,
26573 Matched => Outputs_Match);
26574
26575 -- An In_Out state clause may be matched against a refinement with
26576 -- a null input or null output as long as the non-null side of the
26577 -- relation contains a valid constituent of the In_Out_State.
26578
26579 if Is_In_Out_State_Clause then
26580
26581 -- Depends => (State => State)
26582 -- Refined_Depends => (null => Constit) -- OK
26583
26584 if Inputs_Match
26585 and then not Outputs_Match
26586 and then Nkind (Ref_Output) = N_Null
26587 then
26588 Outputs_Match := True;
26589 end if;
26590
26591 -- Depends => (State => State)
26592 -- Refined_Depends => (Constit => null) -- OK
26593
26594 if not Inputs_Match
26595 and then Outputs_Match
26596 and then Nkind (Ref_Input) = N_Null
26597 then
26598 Inputs_Match := True;
26599 end if;
26600 end if;
26601
26602 -- The current refinement clause is legally constructed following
26603 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
26604 -- the pool of candidates. The seach continues because a single
26605 -- dependence clause may have multiple matching refinements.
26606
26607 if Inputs_Match and Outputs_Match then
26608 Clause_Matched := True;
26609 Remove (Ref_Clause);
26610 end if;
26611
26612 Ref_Clause := Next_Ref_Clause;
26613 end loop;
26614
26615 -- Depending on the order or composition of refinement clauses, an
26616 -- In_Out state clause may not be directly refinable.
26617
26618 -- Refined_State => (State => (Constit_1, Constit_2))
26619 -- Depends => ((Output, State) => (Input, State))
26620 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
26621
26622 -- Matching normalized clause (State => State) fails because there is
26623 -- no direct refinement capable of satisfying this relation. Another
26624 -- similar case arises when clauses (Constit_1 => Input) and (Output
26625 -- => Constit_2) are matched first, leaving no candidates for clause
26626 -- (State => State). Both scenarios are legal as long as one of the
26627 -- previous clauses mentioned a valid constituent of State.
26628
26629 if not Clause_Matched
26630 and then Is_In_Out_State_Clause
26631 and then Is_Already_Matched (Dep_Input)
26632 then
26633 Clause_Matched := True;
26634 end if;
26635
26636 -- A clause where the input is an abstract state with visible null
26637 -- refinement or a 'Result attribute is implicitly matched when the
26638 -- output has already been matched in a previous clause.
26639
26640 -- Refined_State => (State => null)
26641 -- Depends => (Output => State) -- implicitly OK
26642 -- Refined_Depends => (Output => ...)
26643 -- Depends => (...'Result => State) -- implicitly OK
26644 -- Refined_Depends => (...'Result => ...)
26645
26646 if not Clause_Matched
26647 and then Is_Null_Refined_State (Dep_Input)
26648 and then Is_Already_Matched (Dep_Output)
26649 then
26650 Clause_Matched := True;
26651 end if;
26652
26653 -- A clause where the output is an abstract state with visible null
26654 -- refinement is implicitly matched when the input has already been
26655 -- matched in a previous clause.
26656
26657 -- Refined_State => (State => null)
26658 -- Depends => (State => Input) -- implicitly OK
26659 -- Refined_Depends => (... => Input)
26660
26661 if not Clause_Matched
26662 and then Is_Null_Refined_State (Dep_Output)
26663 and then Is_Already_Matched (Dep_Input)
26664 then
26665 Clause_Matched := True;
26666 end if;
26667
26668 -- At this point either all refinement clauses have been examined or
26669 -- pragma Refined_Depends contains a solitary null. Only an abstract
26670 -- state with null refinement can possibly match these cases.
26671
26672 -- Refined_State => (State => null)
26673 -- Depends => (State => null)
26674 -- Refined_Depends => null -- OK
26675
26676 if not Clause_Matched then
26677 Match_Items
26678 (Dep_Item => Dep_Input,
26679 Ref_Item => Empty,
26680 Matched => Inputs_Match);
26681
26682 Match_Items
26683 (Dep_Item => Dep_Output,
26684 Ref_Item => Empty,
26685 Matched => Outputs_Match);
26686
26687 Clause_Matched := Inputs_Match and Outputs_Match;
26688 end if;
26689
26690 -- If the contents of Refined_Depends are legal, then the current
26691 -- dependence clause should be satisfied either by an explicit match
26692 -- or by one of the special cases.
26693
26694 if not Clause_Matched then
26695 SPARK_Msg_NE
26696 (Fix_Msg (Spec_Id, "dependence clause of subprogram & has no "
26697 & "matching refinement in body"), Dep_Clause, Spec_Id);
26698 end if;
26699 end Check_Dependency_Clause;
26700
26701 -------------------------
26702 -- Check_Output_States --
26703 -------------------------
26704
26705 procedure Check_Output_States
26706 (Spec_Inputs : Elist_Id;
26707 Spec_Outputs : Elist_Id;
26708 Body_Inputs : Elist_Id;
26709 Body_Outputs : Elist_Id)
26710 is
26711 procedure Check_Constituent_Usage (State_Id : Entity_Id);
26712 -- Determine whether all constituents of state State_Id with full
26713 -- visible refinement are used as outputs in pragma Refined_Depends.
26714 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
26715
26716 -----------------------------
26717 -- Check_Constituent_Usage --
26718 -----------------------------
26719
26720 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
26721 Constits : constant Elist_Id :=
26722 Partial_Refinement_Constituents (State_Id);
26723 Constit_Elmt : Elmt_Id;
26724 Constit_Id : Entity_Id;
26725 Only_Partial : constant Boolean :=
26726 not Has_Visible_Refinement (State_Id);
26727 Posted : Boolean := False;
26728
26729 begin
26730 if Present (Constits) then
26731 Constit_Elmt := First_Elmt (Constits);
26732 while Present (Constit_Elmt) loop
26733 Constit_Id := Node (Constit_Elmt);
26734
26735 -- Issue an error when a constituent of State_Id is used,
26736 -- and State_Id has only partial visible refinement
26737 -- (SPARK RM 7.2.4(3d)).
26738
26739 if Only_Partial then
26740 if (Present (Body_Inputs)
26741 and then Appears_In (Body_Inputs, Constit_Id))
26742 or else
26743 (Present (Body_Outputs)
26744 and then Appears_In (Body_Outputs, Constit_Id))
26745 then
26746 Error_Msg_Name_1 := Chars (State_Id);
26747 SPARK_Msg_NE
26748 ("constituent & of state % cannot be used in "
26749 & "dependence refinement", N, Constit_Id);
26750 Error_Msg_Name_1 := Chars (State_Id);
26751 SPARK_Msg_N ("\use state % instead", N);
26752 end if;
26753
26754 -- The constituent acts as an input (SPARK RM 7.2.5(3))
26755
26756 elsif Present (Body_Inputs)
26757 and then Appears_In (Body_Inputs, Constit_Id)
26758 then
26759 Error_Msg_Name_1 := Chars (State_Id);
26760 SPARK_Msg_NE
26761 ("constituent & of state % must act as output in "
26762 & "dependence refinement", N, Constit_Id);
26763
26764 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
26765
26766 elsif No (Body_Outputs)
26767 or else not Appears_In (Body_Outputs, Constit_Id)
26768 then
26769 if not Posted then
26770 Posted := True;
26771 SPARK_Msg_NE
26772 ("output state & must be replaced by all its "
26773 & "constituents in dependence refinement",
26774 N, State_Id);
26775 end if;
26776
26777 SPARK_Msg_NE
26778 ("\constituent & is missing in output list",
26779 N, Constit_Id);
26780 end if;
26781
26782 Next_Elmt (Constit_Elmt);
26783 end loop;
26784 end if;
26785 end Check_Constituent_Usage;
26786
26787 -- Local variables
26788
26789 Item : Node_Id;
26790 Item_Elmt : Elmt_Id;
26791 Item_Id : Entity_Id;
26792
26793 -- Start of processing for Check_Output_States
26794
26795 begin
26796 -- Do not perform this check in an instance because it was already
26797 -- performed successfully in the generic template.
26798
26799 if In_Instance then
26800 null;
26801
26802 -- Inspect the outputs of pragma Depends looking for a state with a
26803 -- visible refinement.
26804
26805 elsif Present (Spec_Outputs) then
26806 Item_Elmt := First_Elmt (Spec_Outputs);
26807 while Present (Item_Elmt) loop
26808 Item := Node (Item_Elmt);
26809
26810 -- Deal with the mixed nature of the input and output lists
26811
26812 if Nkind (Item) = N_Defining_Identifier then
26813 Item_Id := Item;
26814 else
26815 Item_Id := Available_View (Entity_Of (Item));
26816 end if;
26817
26818 if Ekind (Item_Id) = E_Abstract_State then
26819
26820 -- The state acts as an input-output, skip it
26821
26822 if Present (Spec_Inputs)
26823 and then Appears_In (Spec_Inputs, Item_Id)
26824 then
26825 null;
26826
26827 -- Ensure that all of the constituents are utilized as
26828 -- outputs in pragma Refined_Depends.
26829
26830 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
26831 Check_Constituent_Usage (Item_Id);
26832 end if;
26833 end if;
26834
26835 Next_Elmt (Item_Elmt);
26836 end loop;
26837 end if;
26838 end Check_Output_States;
26839
26840 --------------------
26841 -- Collect_States --
26842 --------------------
26843
26844 function Collect_States (Clauses : List_Id) return Elist_Id is
26845 procedure Collect_State
26846 (Item : Node_Id;
26847 States : in out Elist_Id);
26848 -- Add the entity of Item to list States when it denotes to a state
26849
26850 -------------------
26851 -- Collect_State --
26852 -------------------
26853
26854 procedure Collect_State
26855 (Item : Node_Id;
26856 States : in out Elist_Id)
26857 is
26858 Id : Entity_Id;
26859
26860 begin
26861 if Is_Entity_Name (Item) then
26862 Id := Entity_Of (Item);
26863
26864 if Ekind (Id) = E_Abstract_State then
26865 if No (States) then
26866 States := New_Elmt_List;
26867 end if;
26868
26869 Append_Unique_Elmt (Id, States);
26870 end if;
26871 end if;
26872 end Collect_State;
26873
26874 -- Local variables
26875
26876 Clause : Node_Id;
26877 Input : Node_Id;
26878 Output : Node_Id;
26879 States : Elist_Id := No_Elist;
26880
26881 -- Start of processing for Collect_States
26882
26883 begin
26884 Clause := First (Clauses);
26885 while Present (Clause) loop
26886 Input := Expression (Clause);
26887 Output := First (Choices (Clause));
26888
26889 Collect_State (Input, States);
26890 Collect_State (Output, States);
26891
26892 Next (Clause);
26893 end loop;
26894
26895 return States;
26896 end Collect_States;
26897
26898 -----------------------
26899 -- Normalize_Clauses --
26900 -----------------------
26901
26902 procedure Normalize_Clauses (Clauses : List_Id) is
26903 procedure Normalize_Inputs (Clause : Node_Id);
26904 -- Normalize clause Clause by creating multiple clauses for each
26905 -- input item of Clause. It is assumed that Clause has exactly one
26906 -- output. The transformation is as follows:
26907 --
26908 -- Output => (Input_1, Input_2) -- original
26909 --
26910 -- Output => Input_1 -- normalizations
26911 -- Output => Input_2
26912
26913 procedure Normalize_Outputs (Clause : Node_Id);
26914 -- Normalize clause Clause by creating multiple clause for each
26915 -- output item of Clause. The transformation is as follows:
26916 --
26917 -- (Output_1, Output_2) => Input -- original
26918 --
26919 -- Output_1 => Input -- normalization
26920 -- Output_2 => Input
26921
26922 ----------------------
26923 -- Normalize_Inputs --
26924 ----------------------
26925
26926 procedure Normalize_Inputs (Clause : Node_Id) is
26927 Inputs : constant Node_Id := Expression (Clause);
26928 Loc : constant Source_Ptr := Sloc (Clause);
26929 Output : constant List_Id := Choices (Clause);
26930 Last_Input : Node_Id;
26931 Input : Node_Id;
26932 New_Clause : Node_Id;
26933 Next_Input : Node_Id;
26934
26935 begin
26936 -- Normalization is performed only when the original clause has
26937 -- more than one input. Multiple inputs appear as an aggregate.
26938
26939 if Nkind (Inputs) = N_Aggregate then
26940 Last_Input := Last (Expressions (Inputs));
26941
26942 -- Create a new clause for each input
26943
26944 Input := First (Expressions (Inputs));
26945 while Present (Input) loop
26946 Next_Input := Next (Input);
26947
26948 -- Unhook the current input from the original input list
26949 -- because it will be relocated to a new clause.
26950
26951 Remove (Input);
26952
26953 -- Special processing for the last input. At this point the
26954 -- original aggregate has been stripped down to one element.
26955 -- Replace the aggregate by the element itself.
26956
26957 if Input = Last_Input then
26958 Rewrite (Inputs, Input);
26959
26960 -- Generate a clause of the form:
26961 -- Output => Input
26962
26963 else
26964 New_Clause :=
26965 Make_Component_Association (Loc,
26966 Choices => New_Copy_List_Tree (Output),
26967 Expression => Input);
26968
26969 -- The new clause contains replicated content that has
26970 -- already been analyzed, mark the clause as analyzed.
26971
26972 Set_Analyzed (New_Clause);
26973 Insert_After (Clause, New_Clause);
26974 end if;
26975
26976 Input := Next_Input;
26977 end loop;
26978 end if;
26979 end Normalize_Inputs;
26980
26981 -----------------------
26982 -- Normalize_Outputs --
26983 -----------------------
26984
26985 procedure Normalize_Outputs (Clause : Node_Id) is
26986 Inputs : constant Node_Id := Expression (Clause);
26987 Loc : constant Source_Ptr := Sloc (Clause);
26988 Outputs : constant Node_Id := First (Choices (Clause));
26989 Last_Output : Node_Id;
26990 New_Clause : Node_Id;
26991 Next_Output : Node_Id;
26992 Output : Node_Id;
26993
26994 begin
26995 -- Multiple outputs appear as an aggregate. Nothing to do when
26996 -- the clause has exactly one output.
26997
26998 if Nkind (Outputs) = N_Aggregate then
26999 Last_Output := Last (Expressions (Outputs));
27000
27001 -- Create a clause for each output. Note that each time a new
27002 -- clause is created, the original output list slowly shrinks
27003 -- until there is one item left.
27004
27005 Output := First (Expressions (Outputs));
27006 while Present (Output) loop
27007 Next_Output := Next (Output);
27008
27009 -- Unhook the output from the original output list as it
27010 -- will be relocated to a new clause.
27011
27012 Remove (Output);
27013
27014 -- Special processing for the last output. At this point
27015 -- the original aggregate has been stripped down to one
27016 -- element. Replace the aggregate by the element itself.
27017
27018 if Output = Last_Output then
27019 Rewrite (Outputs, Output);
27020
27021 else
27022 -- Generate a clause of the form:
27023 -- (Output => Inputs)
27024
27025 New_Clause :=
27026 Make_Component_Association (Loc,
27027 Choices => New_List (Output),
27028 Expression => New_Copy_Tree (Inputs));
27029
27030 -- The new clause contains replicated content that has
27031 -- already been analyzed. There is not need to reanalyze
27032 -- them.
27033
27034 Set_Analyzed (New_Clause);
27035 Insert_After (Clause, New_Clause);
27036 end if;
27037
27038 Output := Next_Output;
27039 end loop;
27040 end if;
27041 end Normalize_Outputs;
27042
27043 -- Local variables
27044
27045 Clause : Node_Id;
27046
27047 -- Start of processing for Normalize_Clauses
27048
27049 begin
27050 Clause := First (Clauses);
27051 while Present (Clause) loop
27052 Normalize_Outputs (Clause);
27053 Next (Clause);
27054 end loop;
27055
27056 Clause := First (Clauses);
27057 while Present (Clause) loop
27058 Normalize_Inputs (Clause);
27059 Next (Clause);
27060 end loop;
27061 end Normalize_Clauses;
27062
27063 --------------------------
27064 -- Remove_Extra_Clauses --
27065 --------------------------
27066
27067 procedure Remove_Extra_Clauses
27068 (Clauses : List_Id;
27069 Matched_Items : Elist_Id)
27070 is
27071 Clause : Node_Id;
27072 Input : Node_Id;
27073 Input_Id : Entity_Id;
27074 Next_Clause : Node_Id;
27075 Output : Node_Id;
27076 State_Id : Entity_Id;
27077
27078 begin
27079 Clause := First (Clauses);
27080 while Present (Clause) loop
27081 Next_Clause := Next (Clause);
27082
27083 Input := Expression (Clause);
27084 Output := First (Choices (Clause));
27085
27086 -- Recognize a clause of the form
27087
27088 -- null => Input
27089
27090 -- where Input is a constituent of a state which was already
27091 -- successfully matched. This clause must be removed because it
27092 -- simply indicates that some of the constituents of the state
27093 -- are not used.
27094
27095 -- Refined_State => (State => (Constit_1, Constit_2))
27096 -- Depends => (Output => State)
27097 -- Refined_Depends => ((Output => Constit_1), -- State matched
27098 -- (null => Constit_2)) -- OK
27099
27100 if Nkind (Output) = N_Null and then Is_Entity_Name (Input) then
27101
27102 -- Handle abstract views generated for limited with clauses
27103
27104 Input_Id := Available_View (Entity_Of (Input));
27105
27106 -- The input must be a constituent of a state
27107
27108 if Ekind_In (Input_Id, E_Abstract_State,
27109 E_Constant,
27110 E_Variable)
27111 and then Present (Encapsulating_State (Input_Id))
27112 then
27113 State_Id := Encapsulating_State (Input_Id);
27114
27115 -- The state must have a non-null visible refinement and be
27116 -- matched in a previous clause.
27117
27118 if Has_Non_Null_Visible_Refinement (State_Id)
27119 and then Contains (Matched_Items, State_Id)
27120 then
27121 Remove (Clause);
27122 end if;
27123 end if;
27124
27125 -- Recognize a clause of the form
27126
27127 -- Output => null
27128
27129 -- where Output is an arbitrary item. This clause must be removed
27130 -- because a null input legitimately matches anything.
27131
27132 elsif Nkind (Input) = N_Null then
27133 Remove (Clause);
27134 end if;
27135
27136 Clause := Next_Clause;
27137 end loop;
27138 end Remove_Extra_Clauses;
27139
27140 --------------------------
27141 -- Report_Extra_Clauses --
27142 --------------------------
27143
27144 procedure Report_Extra_Clauses (Clauses : List_Id) is
27145 Clause : Node_Id;
27146
27147 begin
27148 -- Do not perform this check in an instance because it was already
27149 -- performed successfully in the generic template.
27150
27151 if In_Instance then
27152 null;
27153
27154 elsif Present (Clauses) then
27155 Clause := First (Clauses);
27156 while Present (Clause) loop
27157 SPARK_Msg_N
27158 ("unmatched or extra clause in dependence refinement",
27159 Clause);
27160
27161 Next (Clause);
27162 end loop;
27163 end if;
27164 end Report_Extra_Clauses;
27165
27166 -- Local variables
27167
27168 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
27169 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
27170 Errors : constant Nat := Serious_Errors_Detected;
27171
27172 Clause : Node_Id;
27173 Deps : Node_Id;
27174 Dummy : Boolean;
27175 Refs : Node_Id;
27176
27177 Body_Inputs : Elist_Id := No_Elist;
27178 Body_Outputs : Elist_Id := No_Elist;
27179 -- The inputs and outputs of the subprogram body synthesized from pragma
27180 -- Refined_Depends.
27181
27182 Dependencies : List_Id := No_List;
27183 Depends : Node_Id;
27184 -- The corresponding Depends pragma along with its clauses
27185
27186 Matched_Items : Elist_Id := No_Elist;
27187 -- A list containing the entities of all successfully matched items
27188 -- found in pragma Depends.
27189
27190 Refinements : List_Id := No_List;
27191 -- The clauses of pragma Refined_Depends
27192
27193 Spec_Id : Entity_Id;
27194 -- The entity of the subprogram subject to pragma Refined_Depends
27195
27196 Spec_Inputs : Elist_Id := No_Elist;
27197 Spec_Outputs : Elist_Id := No_Elist;
27198 -- The inputs and outputs of the subprogram spec synthesized from pragma
27199 -- Depends.
27200
27201 States : Elist_Id := No_Elist;
27202 -- A list containing the entities of all states whose constituents
27203 -- appear in pragma Depends.
27204
27205 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
27206
27207 begin
27208 -- Do not analyze the pragma multiple times
27209
27210 if Is_Analyzed_Pragma (N) then
27211 return;
27212 end if;
27213
27214 Spec_Id := Unique_Defining_Entity (Body_Decl);
27215
27216 -- Use the anonymous object as the proper spec when Refined_Depends
27217 -- applies to the body of a single task type. The object carries the
27218 -- proper Chars as well as all non-refined versions of pragmas.
27219
27220 if Is_Single_Concurrent_Type (Spec_Id) then
27221 Spec_Id := Anonymous_Object (Spec_Id);
27222 end if;
27223
27224 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
27225
27226 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
27227 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
27228
27229 if No (Depends) then
27230 SPARK_Msg_NE
27231 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
27232 & "& lacks aspect or pragma Depends"), N, Spec_Id);
27233 goto Leave;
27234 end if;
27235
27236 Deps := Expression (Get_Argument (Depends, Spec_Id));
27237
27238 -- A null dependency relation renders the refinement useless because it
27239 -- cannot possibly mention abstract states with visible refinement. Note
27240 -- that the inverse is not true as states may be refined to null
27241 -- (SPARK RM 7.2.5(2)).
27242
27243 if Nkind (Deps) = N_Null then
27244 SPARK_Msg_NE
27245 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
27246 & "depend on abstract state with visible refinement"), N, Spec_Id);
27247 goto Leave;
27248 end if;
27249
27250 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
27251 -- This ensures that the categorization of all refined dependency items
27252 -- is consistent with their role.
27253
27254 Analyze_Depends_In_Decl_Part (N);
27255
27256 -- Do not match dependencies against refinements if Refined_Depends is
27257 -- illegal to avoid emitting misleading error.
27258
27259 if Serious_Errors_Detected = Errors then
27260
27261 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
27262 -- the inputs and outputs of the subprogram spec and body to verify
27263 -- the use of states with visible refinement and their constituents.
27264
27265 if No (Get_Pragma (Spec_Id, Pragma_Global))
27266 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
27267 then
27268 Collect_Subprogram_Inputs_Outputs
27269 (Subp_Id => Spec_Id,
27270 Synthesize => True,
27271 Subp_Inputs => Spec_Inputs,
27272 Subp_Outputs => Spec_Outputs,
27273 Global_Seen => Dummy);
27274
27275 Collect_Subprogram_Inputs_Outputs
27276 (Subp_Id => Body_Id,
27277 Synthesize => True,
27278 Subp_Inputs => Body_Inputs,
27279 Subp_Outputs => Body_Outputs,
27280 Global_Seen => Dummy);
27281
27282 -- For an output state with a visible refinement, ensure that all
27283 -- constituents appear as outputs in the dependency refinement.
27284
27285 Check_Output_States
27286 (Spec_Inputs => Spec_Inputs,
27287 Spec_Outputs => Spec_Outputs,
27288 Body_Inputs => Body_Inputs,
27289 Body_Outputs => Body_Outputs);
27290 end if;
27291
27292 -- Multiple dependency clauses appear as component associations of an
27293 -- aggregate. Note that the clauses are copied because the algorithm
27294 -- modifies them and this should not be visible in Depends.
27295
27296 pragma Assert (Nkind (Deps) = N_Aggregate);
27297 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
27298 Normalize_Clauses (Dependencies);
27299
27300 -- Gather all states which appear in Depends
27301
27302 States := Collect_States (Dependencies);
27303
27304 Refs := Expression (Get_Argument (N, Spec_Id));
27305
27306 if Nkind (Refs) = N_Null then
27307 Refinements := No_List;
27308
27309 -- Multiple dependency clauses appear as component associations of an
27310 -- aggregate. Note that the clauses are copied because the algorithm
27311 -- modifies them and this should not be visible in Refined_Depends.
27312
27313 else pragma Assert (Nkind (Refs) = N_Aggregate);
27314 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
27315 Normalize_Clauses (Refinements);
27316 end if;
27317
27318 -- At this point the clauses of pragmas Depends and Refined_Depends
27319 -- have been normalized into simple dependencies between one output
27320 -- and one input. Examine all clauses of pragma Depends looking for
27321 -- matching clauses in pragma Refined_Depends.
27322
27323 Clause := First (Dependencies);
27324 while Present (Clause) loop
27325 Check_Dependency_Clause
27326 (Spec_Id => Spec_Id,
27327 Dep_Clause => Clause,
27328 Dep_States => States,
27329 Refinements => Refinements,
27330 Matched_Items => Matched_Items);
27331
27332 Next (Clause);
27333 end loop;
27334
27335 -- Pragma Refined_Depends may contain multiple clarification clauses
27336 -- which indicate that certain constituents do not influence the data
27337 -- flow in any way. Such clauses must be removed as long as the state
27338 -- has been matched, otherwise they will be incorrectly flagged as
27339 -- unmatched.
27340
27341 -- Refined_State => (State => (Constit_1, Constit_2))
27342 -- Depends => (Output => State)
27343 -- Refined_Depends => ((Output => Constit_1), -- State matched
27344 -- (null => Constit_2)) -- must be removed
27345
27346 Remove_Extra_Clauses (Refinements, Matched_Items);
27347
27348 if Serious_Errors_Detected = Errors then
27349 Report_Extra_Clauses (Refinements);
27350 end if;
27351 end if;
27352
27353 <<Leave>>
27354 Set_Is_Analyzed_Pragma (N);
27355 end Analyze_Refined_Depends_In_Decl_Part;
27356
27357 -----------------------------------------
27358 -- Analyze_Refined_Global_In_Decl_Part --
27359 -----------------------------------------
27360
27361 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
27362 Global : Node_Id;
27363 -- The corresponding Global pragma
27364
27365 Has_In_State : Boolean := False;
27366 Has_In_Out_State : Boolean := False;
27367 Has_Out_State : Boolean := False;
27368 Has_Proof_In_State : Boolean := False;
27369 -- These flags are set when the corresponding Global pragma has a state
27370 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
27371 -- refinement.
27372
27373 Has_Null_State : Boolean := False;
27374 -- This flag is set when the corresponding Global pragma has at least
27375 -- one state with a null refinement.
27376
27377 In_Constits : Elist_Id := No_Elist;
27378 In_Out_Constits : Elist_Id := No_Elist;
27379 Out_Constits : Elist_Id := No_Elist;
27380 Proof_In_Constits : Elist_Id := No_Elist;
27381 -- These lists contain the entities of all Input, In_Out, Output and
27382 -- Proof_In constituents that appear in Refined_Global and participate
27383 -- in state refinement.
27384
27385 In_Items : Elist_Id := No_Elist;
27386 In_Out_Items : Elist_Id := No_Elist;
27387 Out_Items : Elist_Id := No_Elist;
27388 Proof_In_Items : Elist_Id := No_Elist;
27389 -- These lists contain the entities of all Input, In_Out, Output and
27390 -- Proof_In items defined in the corresponding Global pragma.
27391
27392 Repeat_Items : Elist_Id := No_Elist;
27393 -- A list of all global items without full visible refinement found
27394 -- in pragma Global. These states should be repeated in the global
27395 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
27396 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
27397
27398 Spec_Id : Entity_Id;
27399 -- The entity of the subprogram subject to pragma Refined_Global
27400
27401 States : Elist_Id := No_Elist;
27402 -- A list of all states with full or partial visible refinement found in
27403 -- pragma Global.
27404
27405 procedure Check_In_Out_States;
27406 -- Determine whether the corresponding Global pragma mentions In_Out
27407 -- states with visible refinement and if so, ensure that one of the
27408 -- following completions apply to the constituents of the state:
27409 -- 1) there is at least one constituent of mode In_Out
27410 -- 2) there is at least one Input and one Output constituent
27411 -- 3) not all constituents are present and one of them is of mode
27412 -- Output.
27413 -- This routine may remove elements from In_Constits, In_Out_Constits,
27414 -- Out_Constits and Proof_In_Constits.
27415
27416 procedure Check_Input_States;
27417 -- Determine whether the corresponding Global pragma mentions Input
27418 -- states with visible refinement and if so, ensure that at least one of
27419 -- its constituents appears as an Input item in Refined_Global.
27420 -- This routine may remove elements from In_Constits, In_Out_Constits,
27421 -- Out_Constits and Proof_In_Constits.
27422
27423 procedure Check_Output_States;
27424 -- Determine whether the corresponding Global pragma mentions Output
27425 -- states with visible refinement and if so, ensure that all of its
27426 -- constituents appear as Output items in Refined_Global.
27427 -- This routine may remove elements from In_Constits, In_Out_Constits,
27428 -- Out_Constits and Proof_In_Constits.
27429
27430 procedure Check_Proof_In_States;
27431 -- Determine whether the corresponding Global pragma mentions Proof_In
27432 -- states with visible refinement and if so, ensure that at least one of
27433 -- its constituents appears as a Proof_In item in Refined_Global.
27434 -- This routine may remove elements from In_Constits, In_Out_Constits,
27435 -- Out_Constits and Proof_In_Constits.
27436
27437 procedure Check_Refined_Global_List
27438 (List : Node_Id;
27439 Global_Mode : Name_Id := Name_Input);
27440 -- Verify the legality of a single global list declaration. Global_Mode
27441 -- denotes the current mode in effect.
27442
27443 procedure Collect_Global_Items
27444 (List : Node_Id;
27445 Mode : Name_Id := Name_Input);
27446 -- Gather all Input, In_Out, Output and Proof_In items from node List
27447 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
27448 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
27449 -- and Has_Proof_In_State are set when there is at least one abstract
27450 -- state with full or partial visible refinement available in the
27451 -- corresponding mode. Flag Has_Null_State is set when at least state
27452 -- has a null refinement. Mode denotes the current global mode in
27453 -- effect.
27454
27455 function Present_Then_Remove
27456 (List : Elist_Id;
27457 Item : Entity_Id) return Boolean;
27458 -- Search List for a particular entity Item. If Item has been found,
27459 -- remove it from List. This routine is used to strip lists In_Constits,
27460 -- In_Out_Constits and Out_Constits of valid constituents.
27461
27462 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id);
27463 -- Same as function Present_Then_Remove, but do not report the presence
27464 -- of Item in List.
27465
27466 procedure Report_Extra_Constituents;
27467 -- Emit an error for each constituent found in lists In_Constits,
27468 -- In_Out_Constits and Out_Constits.
27469
27470 procedure Report_Missing_Items;
27471 -- Emit an error for each global item not repeated found in list
27472 -- Repeat_Items.
27473
27474 -------------------------
27475 -- Check_In_Out_States --
27476 -------------------------
27477
27478 procedure Check_In_Out_States is
27479 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27480 -- Determine whether one of the following coverage scenarios is in
27481 -- effect:
27482 -- 1) there is at least one constituent of mode In_Out or Output
27483 -- 2) there is at least one pair of constituents with modes Input
27484 -- and Output, or Proof_In and Output.
27485 -- 3) there is at least one constituent of mode Output and not all
27486 -- constituents are present.
27487 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
27488
27489 -----------------------------
27490 -- Check_Constituent_Usage --
27491 -----------------------------
27492
27493 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27494 Constits : constant Elist_Id :=
27495 Partial_Refinement_Constituents (State_Id);
27496 Constit_Elmt : Elmt_Id;
27497 Constit_Id : Entity_Id;
27498 Has_Missing : Boolean := False;
27499 In_Out_Seen : Boolean := False;
27500 Input_Seen : Boolean := False;
27501 Output_Seen : Boolean := False;
27502 Proof_In_Seen : Boolean := False;
27503
27504 begin
27505 -- Process all the constituents of the state and note their modes
27506 -- within the global refinement.
27507
27508 if Present (Constits) then
27509 Constit_Elmt := First_Elmt (Constits);
27510 while Present (Constit_Elmt) loop
27511 Constit_Id := Node (Constit_Elmt);
27512
27513 if Present_Then_Remove (In_Constits, Constit_Id) then
27514 Input_Seen := True;
27515
27516 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
27517 In_Out_Seen := True;
27518
27519 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
27520 Output_Seen := True;
27521
27522 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
27523 then
27524 Proof_In_Seen := True;
27525
27526 else
27527 Has_Missing := True;
27528 end if;
27529
27530 Next_Elmt (Constit_Elmt);
27531 end loop;
27532 end if;
27533
27534 -- An In_Out constituent is a valid completion
27535
27536 if In_Out_Seen then
27537 null;
27538
27539 -- A pair of one Input/Proof_In and one Output constituent is a
27540 -- valid completion.
27541
27542 elsif (Input_Seen or Proof_In_Seen) and Output_Seen then
27543 null;
27544
27545 elsif Output_Seen then
27546
27547 -- A single Output constituent is a valid completion only when
27548 -- some of the other constituents are missing.
27549
27550 if Has_Missing then
27551 null;
27552
27553 -- Otherwise all constituents are of mode Output
27554
27555 else
27556 SPARK_Msg_NE
27557 ("global refinement of state & must include at least one "
27558 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
27559 N, State_Id);
27560 end if;
27561
27562 -- The state lacks a completion. When full refinement is visible,
27563 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
27564 -- refinement is visible, emit an error if the abstract state
27565 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
27566 -- both are utilized, Check_State_And_Constituent_Use. will issue
27567 -- the error.
27568
27569 elsif not Input_Seen
27570 and then not In_Out_Seen
27571 and then not Output_Seen
27572 and then not Proof_In_Seen
27573 then
27574 if Has_Visible_Refinement (State_Id)
27575 or else Contains (Repeat_Items, State_Id)
27576 then
27577 SPARK_Msg_NE
27578 ("missing global refinement of state &", N, State_Id);
27579 end if;
27580
27581 -- Otherwise the state has a malformed completion where at least
27582 -- one of the constituents has a different mode.
27583
27584 else
27585 SPARK_Msg_NE
27586 ("global refinement of state & redefines the mode of its "
27587 & "constituents", N, State_Id);
27588 end if;
27589 end Check_Constituent_Usage;
27590
27591 -- Local variables
27592
27593 Item_Elmt : Elmt_Id;
27594 Item_Id : Entity_Id;
27595
27596 -- Start of processing for Check_In_Out_States
27597
27598 begin
27599 -- Do not perform this check in an instance because it was already
27600 -- performed successfully in the generic template.
27601
27602 if In_Instance then
27603 null;
27604
27605 -- Inspect the In_Out items of the corresponding Global pragma
27606 -- looking for a state with a visible refinement.
27607
27608 elsif Has_In_Out_State and then Present (In_Out_Items) then
27609 Item_Elmt := First_Elmt (In_Out_Items);
27610 while Present (Item_Elmt) loop
27611 Item_Id := Node (Item_Elmt);
27612
27613 -- Ensure that one of the three coverage variants is satisfied
27614
27615 if Ekind (Item_Id) = E_Abstract_State
27616 and then Has_Non_Null_Visible_Refinement (Item_Id)
27617 then
27618 Check_Constituent_Usage (Item_Id);
27619 end if;
27620
27621 Next_Elmt (Item_Elmt);
27622 end loop;
27623 end if;
27624 end Check_In_Out_States;
27625
27626 ------------------------
27627 -- Check_Input_States --
27628 ------------------------
27629
27630 procedure Check_Input_States is
27631 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27632 -- Determine whether at least one constituent of state State_Id with
27633 -- full or partial visible refinement is used and has mode Input.
27634 -- Ensure that the remaining constituents do not have In_Out or
27635 -- Output modes. Emit an error if this is not the case
27636 -- (SPARK RM 7.2.4(5)).
27637
27638 -----------------------------
27639 -- Check_Constituent_Usage --
27640 -----------------------------
27641
27642 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27643 Constits : constant Elist_Id :=
27644 Partial_Refinement_Constituents (State_Id);
27645 Constit_Elmt : Elmt_Id;
27646 Constit_Id : Entity_Id;
27647 In_Seen : Boolean := False;
27648
27649 begin
27650 if Present (Constits) then
27651 Constit_Elmt := First_Elmt (Constits);
27652 while Present (Constit_Elmt) loop
27653 Constit_Id := Node (Constit_Elmt);
27654
27655 -- At least one of the constituents appears as an Input
27656
27657 if Present_Then_Remove (In_Constits, Constit_Id) then
27658 In_Seen := True;
27659
27660 -- A Proof_In constituent can refine an Input state as long
27661 -- as there is at least one Input constituent present.
27662
27663 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
27664 then
27665 null;
27666
27667 -- The constituent appears in the global refinement, but has
27668 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
27669
27670 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
27671 or else Present_Then_Remove (Out_Constits, Constit_Id)
27672 then
27673 Error_Msg_Name_1 := Chars (State_Id);
27674 SPARK_Msg_NE
27675 ("constituent & of state % must have mode `Input` in "
27676 & "global refinement", N, Constit_Id);
27677 end if;
27678
27679 Next_Elmt (Constit_Elmt);
27680 end loop;
27681 end if;
27682
27683 -- Not one of the constituents appeared as Input. Always emit an
27684 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
27685 -- When only partial refinement is visible, emit an error if the
27686 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27687 -- the case where both are utilized, an error will be issued in
27688 -- Check_State_And_Constituent_Use.
27689
27690 if not In_Seen
27691 and then (Has_Visible_Refinement (State_Id)
27692 or else Contains (Repeat_Items, State_Id))
27693 then
27694 SPARK_Msg_NE
27695 ("global refinement of state & must include at least one "
27696 & "constituent of mode `Input`", N, State_Id);
27697 end if;
27698 end Check_Constituent_Usage;
27699
27700 -- Local variables
27701
27702 Item_Elmt : Elmt_Id;
27703 Item_Id : Entity_Id;
27704
27705 -- Start of processing for Check_Input_States
27706
27707 begin
27708 -- Do not perform this check in an instance because it was already
27709 -- performed successfully in the generic template.
27710
27711 if In_Instance then
27712 null;
27713
27714 -- Inspect the Input items of the corresponding Global pragma looking
27715 -- for a state with a visible refinement.
27716
27717 elsif Has_In_State and then Present (In_Items) then
27718 Item_Elmt := First_Elmt (In_Items);
27719 while Present (Item_Elmt) loop
27720 Item_Id := Node (Item_Elmt);
27721
27722 -- When full refinement is visible, ensure that at least one of
27723 -- the constituents is utilized and is of mode Input. When only
27724 -- partial refinement is visible, ensure that either one of
27725 -- the constituents is utilized and is of mode Input, or the
27726 -- abstract state is repeated and no constituent is utilized.
27727
27728 if Ekind (Item_Id) = E_Abstract_State
27729 and then Has_Non_Null_Visible_Refinement (Item_Id)
27730 then
27731 Check_Constituent_Usage (Item_Id);
27732 end if;
27733
27734 Next_Elmt (Item_Elmt);
27735 end loop;
27736 end if;
27737 end Check_Input_States;
27738
27739 -------------------------
27740 -- Check_Output_States --
27741 -------------------------
27742
27743 procedure Check_Output_States is
27744 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27745 -- Determine whether all constituents of state State_Id with full
27746 -- visible refinement are used and have mode Output. Emit an error
27747 -- if this is not the case (SPARK RM 7.2.4(5)).
27748
27749 -----------------------------
27750 -- Check_Constituent_Usage --
27751 -----------------------------
27752
27753 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27754 Constits : constant Elist_Id :=
27755 Partial_Refinement_Constituents (State_Id);
27756 Only_Partial : constant Boolean :=
27757 not Has_Visible_Refinement (State_Id);
27758 Constit_Elmt : Elmt_Id;
27759 Constit_Id : Entity_Id;
27760 Posted : Boolean := False;
27761
27762 begin
27763 if Present (Constits) then
27764 Constit_Elmt := First_Elmt (Constits);
27765 while Present (Constit_Elmt) loop
27766 Constit_Id := Node (Constit_Elmt);
27767
27768 -- Issue an error when a constituent of State_Id is utilized
27769 -- and State_Id has only partial visible refinement
27770 -- (SPARK RM 7.2.4(3d)).
27771
27772 if Only_Partial then
27773 if Present_Then_Remove (Out_Constits, Constit_Id)
27774 or else Present_Then_Remove (In_Constits, Constit_Id)
27775 or else
27776 Present_Then_Remove (In_Out_Constits, Constit_Id)
27777 or else
27778 Present_Then_Remove (Proof_In_Constits, Constit_Id)
27779 then
27780 Error_Msg_Name_1 := Chars (State_Id);
27781 SPARK_Msg_NE
27782 ("constituent & of state % cannot be used in global "
27783 & "refinement", N, Constit_Id);
27784 Error_Msg_Name_1 := Chars (State_Id);
27785 SPARK_Msg_N ("\use state % instead", N);
27786 end if;
27787
27788 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
27789 null;
27790
27791 -- The constituent appears in the global refinement, but has
27792 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
27793
27794 elsif Present_Then_Remove (In_Constits, Constit_Id)
27795 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27796 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
27797 then
27798 Error_Msg_Name_1 := Chars (State_Id);
27799 SPARK_Msg_NE
27800 ("constituent & of state % must have mode `Output` in "
27801 & "global refinement", N, Constit_Id);
27802
27803 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
27804
27805 else
27806 if not Posted then
27807 Posted := True;
27808 SPARK_Msg_NE
27809 ("`Output` state & must be replaced by all its "
27810 & "constituents in global refinement", N, State_Id);
27811 end if;
27812
27813 SPARK_Msg_NE
27814 ("\constituent & is missing in output list",
27815 N, Constit_Id);
27816 end if;
27817
27818 Next_Elmt (Constit_Elmt);
27819 end loop;
27820 end if;
27821 end Check_Constituent_Usage;
27822
27823 -- Local variables
27824
27825 Item_Elmt : Elmt_Id;
27826 Item_Id : Entity_Id;
27827
27828 -- Start of processing for Check_Output_States
27829
27830 begin
27831 -- Do not perform this check in an instance because it was already
27832 -- performed successfully in the generic template.
27833
27834 if In_Instance then
27835 null;
27836
27837 -- Inspect the Output items of the corresponding Global pragma
27838 -- looking for a state with a visible refinement.
27839
27840 elsif Has_Out_State and then Present (Out_Items) then
27841 Item_Elmt := First_Elmt (Out_Items);
27842 while Present (Item_Elmt) loop
27843 Item_Id := Node (Item_Elmt);
27844
27845 -- When full refinement is visible, ensure that all of the
27846 -- constituents are utilized and they have mode Output. When
27847 -- only partial refinement is visible, ensure that no
27848 -- constituent is utilized.
27849
27850 if Ekind (Item_Id) = E_Abstract_State
27851 and then Has_Non_Null_Visible_Refinement (Item_Id)
27852 then
27853 Check_Constituent_Usage (Item_Id);
27854 end if;
27855
27856 Next_Elmt (Item_Elmt);
27857 end loop;
27858 end if;
27859 end Check_Output_States;
27860
27861 ---------------------------
27862 -- Check_Proof_In_States --
27863 ---------------------------
27864
27865 procedure Check_Proof_In_States is
27866 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27867 -- Determine whether at least one constituent of state State_Id with
27868 -- full or partial visible refinement is used and has mode Proof_In.
27869 -- Ensure that the remaining constituents do not have Input, In_Out,
27870 -- or Output modes. Emit an error if this is not the case
27871 -- (SPARK RM 7.2.4(5)).
27872
27873 -----------------------------
27874 -- Check_Constituent_Usage --
27875 -----------------------------
27876
27877 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27878 Constits : constant Elist_Id :=
27879 Partial_Refinement_Constituents (State_Id);
27880 Constit_Elmt : Elmt_Id;
27881 Constit_Id : Entity_Id;
27882 Proof_In_Seen : Boolean := False;
27883
27884 begin
27885 if Present (Constits) then
27886 Constit_Elmt := First_Elmt (Constits);
27887 while Present (Constit_Elmt) loop
27888 Constit_Id := Node (Constit_Elmt);
27889
27890 -- At least one of the constituents appears as Proof_In
27891
27892 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
27893 Proof_In_Seen := True;
27894
27895 -- The constituent appears in the global refinement, but has
27896 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
27897
27898 elsif Present_Then_Remove (In_Constits, Constit_Id)
27899 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27900 or else Present_Then_Remove (Out_Constits, Constit_Id)
27901 then
27902 Error_Msg_Name_1 := Chars (State_Id);
27903 SPARK_Msg_NE
27904 ("constituent & of state % must have mode `Proof_In` "
27905 & "in global refinement", N, Constit_Id);
27906 end if;
27907
27908 Next_Elmt (Constit_Elmt);
27909 end loop;
27910 end if;
27911
27912 -- Not one of the constituents appeared as Proof_In. Always emit
27913 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
27914 -- When only partial refinement is visible, emit an error if the
27915 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27916 -- the case where both are utilized, an error will be issued by
27917 -- Check_State_And_Constituent_Use.
27918
27919 if not Proof_In_Seen
27920 and then (Has_Visible_Refinement (State_Id)
27921 or else Contains (Repeat_Items, State_Id))
27922 then
27923 SPARK_Msg_NE
27924 ("global refinement of state & must include at least one "
27925 & "constituent of mode `Proof_In`", N, State_Id);
27926 end if;
27927 end Check_Constituent_Usage;
27928
27929 -- Local variables
27930
27931 Item_Elmt : Elmt_Id;
27932 Item_Id : Entity_Id;
27933
27934 -- Start of processing for Check_Proof_In_States
27935
27936 begin
27937 -- Do not perform this check in an instance because it was already
27938 -- performed successfully in the generic template.
27939
27940 if In_Instance then
27941 null;
27942
27943 -- Inspect the Proof_In items of the corresponding Global pragma
27944 -- looking for a state with a visible refinement.
27945
27946 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
27947 Item_Elmt := First_Elmt (Proof_In_Items);
27948 while Present (Item_Elmt) loop
27949 Item_Id := Node (Item_Elmt);
27950
27951 -- Ensure that at least one of the constituents is utilized
27952 -- and is of mode Proof_In. When only partial refinement is
27953 -- visible, ensure that either one of the constituents is
27954 -- utilized and is of mode Proof_In, or the abstract state
27955 -- is repeated and no constituent is utilized.
27956
27957 if Ekind (Item_Id) = E_Abstract_State
27958 and then Has_Non_Null_Visible_Refinement (Item_Id)
27959 then
27960 Check_Constituent_Usage (Item_Id);
27961 end if;
27962
27963 Next_Elmt (Item_Elmt);
27964 end loop;
27965 end if;
27966 end Check_Proof_In_States;
27967
27968 -------------------------------
27969 -- Check_Refined_Global_List --
27970 -------------------------------
27971
27972 procedure Check_Refined_Global_List
27973 (List : Node_Id;
27974 Global_Mode : Name_Id := Name_Input)
27975 is
27976 procedure Check_Refined_Global_Item
27977 (Item : Node_Id;
27978 Global_Mode : Name_Id);
27979 -- Verify the legality of a single global item declaration. Parameter
27980 -- Global_Mode denotes the current mode in effect.
27981
27982 -------------------------------
27983 -- Check_Refined_Global_Item --
27984 -------------------------------
27985
27986 procedure Check_Refined_Global_Item
27987 (Item : Node_Id;
27988 Global_Mode : Name_Id)
27989 is
27990 Item_Id : constant Entity_Id := Entity_Of (Item);
27991
27992 procedure Inconsistent_Mode_Error (Expect : Name_Id);
27993 -- Issue a common error message for all mode mismatches. Expect
27994 -- denotes the expected mode.
27995
27996 -----------------------------
27997 -- Inconsistent_Mode_Error --
27998 -----------------------------
27999
28000 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
28001 begin
28002 SPARK_Msg_NE
28003 ("global item & has inconsistent modes", Item, Item_Id);
28004
28005 Error_Msg_Name_1 := Global_Mode;
28006 Error_Msg_Name_2 := Expect;
28007 SPARK_Msg_N ("\expected mode %, found mode %", Item);
28008 end Inconsistent_Mode_Error;
28009
28010 -- Local variables
28011
28012 Enc_State : Entity_Id := Empty;
28013 -- Encapsulating state for constituent, Empty otherwise
28014
28015 -- Start of processing for Check_Refined_Global_Item
28016
28017 begin
28018 if Ekind_In (Item_Id, E_Abstract_State,
28019 E_Constant,
28020 E_Variable)
28021 then
28022 Enc_State := Find_Encapsulating_State (States, Item_Id);
28023 end if;
28024
28025 -- When the state or object acts as a constituent of another
28026 -- state with a visible refinement, collect it for the state
28027 -- completeness checks performed later on. Note that the item
28028 -- acts as a constituent only when the encapsulating state is
28029 -- present in pragma Global.
28030
28031 if Present (Enc_State)
28032 and then (Has_Visible_Refinement (Enc_State)
28033 or else Has_Partial_Visible_Refinement (Enc_State))
28034 and then Contains (States, Enc_State)
28035 then
28036 -- If the state has only partial visible refinement, remove it
28037 -- from the list of items that should be repeated from pragma
28038 -- Global.
28039
28040 if not Has_Visible_Refinement (Enc_State) then
28041 Present_Then_Remove (Repeat_Items, Enc_State);
28042 end if;
28043
28044 if Global_Mode = Name_Input then
28045 Append_New_Elmt (Item_Id, In_Constits);
28046
28047 elsif Global_Mode = Name_In_Out then
28048 Append_New_Elmt (Item_Id, In_Out_Constits);
28049
28050 elsif Global_Mode = Name_Output then
28051 Append_New_Elmt (Item_Id, Out_Constits);
28052
28053 elsif Global_Mode = Name_Proof_In then
28054 Append_New_Elmt (Item_Id, Proof_In_Constits);
28055 end if;
28056
28057 -- When not a constituent, ensure that both occurrences of the
28058 -- item in pragmas Global and Refined_Global match. Also remove
28059 -- it when present from the list of items that should be repeated
28060 -- from pragma Global.
28061
28062 else
28063 Present_Then_Remove (Repeat_Items, Item_Id);
28064
28065 if Contains (In_Items, Item_Id) then
28066 if Global_Mode /= Name_Input then
28067 Inconsistent_Mode_Error (Name_Input);
28068 end if;
28069
28070 elsif Contains (In_Out_Items, Item_Id) then
28071 if Global_Mode /= Name_In_Out then
28072 Inconsistent_Mode_Error (Name_In_Out);
28073 end if;
28074
28075 elsif Contains (Out_Items, Item_Id) then
28076 if Global_Mode /= Name_Output then
28077 Inconsistent_Mode_Error (Name_Output);
28078 end if;
28079
28080 elsif Contains (Proof_In_Items, Item_Id) then
28081 null;
28082
28083 -- The item does not appear in the corresponding Global pragma,
28084 -- it must be an extra (SPARK RM 7.2.4(3)).
28085
28086 else
28087 pragma Assert (Present (Global));
28088 Error_Msg_Sloc := Sloc (Global);
28089 SPARK_Msg_NE
28090 ("extra global item & does not refine or repeat any "
28091 & "global item #", Item, Item_Id);
28092 end if;
28093 end if;
28094 end Check_Refined_Global_Item;
28095
28096 -- Local variables
28097
28098 Item : Node_Id;
28099
28100 -- Start of processing for Check_Refined_Global_List
28101
28102 begin
28103 -- Do not perform this check in an instance because it was already
28104 -- performed successfully in the generic template.
28105
28106 if In_Instance then
28107 null;
28108
28109 elsif Nkind (List) = N_Null then
28110 null;
28111
28112 -- Single global item declaration
28113
28114 elsif Nkind_In (List, N_Expanded_Name,
28115 N_Identifier,
28116 N_Selected_Component)
28117 then
28118 Check_Refined_Global_Item (List, Global_Mode);
28119
28120 -- Simple global list or moded global list declaration
28121
28122 elsif Nkind (List) = N_Aggregate then
28123
28124 -- The declaration of a simple global list appear as a collection
28125 -- of expressions.
28126
28127 if Present (Expressions (List)) then
28128 Item := First (Expressions (List));
28129 while Present (Item) loop
28130 Check_Refined_Global_Item (Item, Global_Mode);
28131 Next (Item);
28132 end loop;
28133
28134 -- The declaration of a moded global list appears as a collection
28135 -- of component associations where individual choices denote
28136 -- modes.
28137
28138 elsif Present (Component_Associations (List)) then
28139 Item := First (Component_Associations (List));
28140 while Present (Item) loop
28141 Check_Refined_Global_List
28142 (List => Expression (Item),
28143 Global_Mode => Chars (First (Choices (Item))));
28144
28145 Next (Item);
28146 end loop;
28147
28148 -- Invalid tree
28149
28150 else
28151 raise Program_Error;
28152 end if;
28153
28154 -- Invalid list
28155
28156 else
28157 raise Program_Error;
28158 end if;
28159 end Check_Refined_Global_List;
28160
28161 --------------------------
28162 -- Collect_Global_Items --
28163 --------------------------
28164
28165 procedure Collect_Global_Items
28166 (List : Node_Id;
28167 Mode : Name_Id := Name_Input)
28168 is
28169 procedure Collect_Global_Item
28170 (Item : Node_Id;
28171 Item_Mode : Name_Id);
28172 -- Add a single item to the appropriate list. Item_Mode denotes the
28173 -- current mode in effect.
28174
28175 -------------------------
28176 -- Collect_Global_Item --
28177 -------------------------
28178
28179 procedure Collect_Global_Item
28180 (Item : Node_Id;
28181 Item_Mode : Name_Id)
28182 is
28183 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
28184 -- The above handles abstract views of variables and states built
28185 -- for limited with clauses.
28186
28187 begin
28188 -- Signal that the global list contains at least one abstract
28189 -- state with a visible refinement. Note that the refinement may
28190 -- be null in which case there are no constituents.
28191
28192 if Ekind (Item_Id) = E_Abstract_State then
28193 if Has_Null_Visible_Refinement (Item_Id) then
28194 Has_Null_State := True;
28195
28196 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
28197 Append_New_Elmt (Item_Id, States);
28198
28199 if Item_Mode = Name_Input then
28200 Has_In_State := True;
28201 elsif Item_Mode = Name_In_Out then
28202 Has_In_Out_State := True;
28203 elsif Item_Mode = Name_Output then
28204 Has_Out_State := True;
28205 elsif Item_Mode = Name_Proof_In then
28206 Has_Proof_In_State := True;
28207 end if;
28208 end if;
28209 end if;
28210
28211 -- Record global items without full visible refinement found in
28212 -- pragma Global which should be repeated in the global refinement
28213 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
28214
28215 if Ekind (Item_Id) /= E_Abstract_State
28216 or else not Has_Visible_Refinement (Item_Id)
28217 then
28218 Append_New_Elmt (Item_Id, Repeat_Items);
28219 end if;
28220
28221 -- Add the item to the proper list
28222
28223 if Item_Mode = Name_Input then
28224 Append_New_Elmt (Item_Id, In_Items);
28225 elsif Item_Mode = Name_In_Out then
28226 Append_New_Elmt (Item_Id, In_Out_Items);
28227 elsif Item_Mode = Name_Output then
28228 Append_New_Elmt (Item_Id, Out_Items);
28229 elsif Item_Mode = Name_Proof_In then
28230 Append_New_Elmt (Item_Id, Proof_In_Items);
28231 end if;
28232 end Collect_Global_Item;
28233
28234 -- Local variables
28235
28236 Item : Node_Id;
28237
28238 -- Start of processing for Collect_Global_Items
28239
28240 begin
28241 if Nkind (List) = N_Null then
28242 null;
28243
28244 -- Single global item declaration
28245
28246 elsif Nkind_In (List, N_Expanded_Name,
28247 N_Identifier,
28248 N_Selected_Component)
28249 then
28250 Collect_Global_Item (List, Mode);
28251
28252 -- Single global list or moded global list declaration
28253
28254 elsif Nkind (List) = N_Aggregate then
28255
28256 -- The declaration of a simple global list appear as a collection
28257 -- of expressions.
28258
28259 if Present (Expressions (List)) then
28260 Item := First (Expressions (List));
28261 while Present (Item) loop
28262 Collect_Global_Item (Item, Mode);
28263 Next (Item);
28264 end loop;
28265
28266 -- The declaration of a moded global list appears as a collection
28267 -- of component associations where individual choices denote mode.
28268
28269 elsif Present (Component_Associations (List)) then
28270 Item := First (Component_Associations (List));
28271 while Present (Item) loop
28272 Collect_Global_Items
28273 (List => Expression (Item),
28274 Mode => Chars (First (Choices (Item))));
28275
28276 Next (Item);
28277 end loop;
28278
28279 -- Invalid tree
28280
28281 else
28282 raise Program_Error;
28283 end if;
28284
28285 -- To accommodate partial decoration of disabled SPARK features, this
28286 -- routine may be called with illegal input. If this is the case, do
28287 -- not raise Program_Error.
28288
28289 else
28290 null;
28291 end if;
28292 end Collect_Global_Items;
28293
28294 -------------------------
28295 -- Present_Then_Remove --
28296 -------------------------
28297
28298 function Present_Then_Remove
28299 (List : Elist_Id;
28300 Item : Entity_Id) return Boolean
28301 is
28302 Elmt : Elmt_Id;
28303
28304 begin
28305 if Present (List) then
28306 Elmt := First_Elmt (List);
28307 while Present (Elmt) loop
28308 if Node (Elmt) = Item then
28309 Remove_Elmt (List, Elmt);
28310 return True;
28311 end if;
28312
28313 Next_Elmt (Elmt);
28314 end loop;
28315 end if;
28316
28317 return False;
28318 end Present_Then_Remove;
28319
28320 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id) is
28321 Ignore : Boolean;
28322 begin
28323 Ignore := Present_Then_Remove (List, Item);
28324 end Present_Then_Remove;
28325
28326 -------------------------------
28327 -- Report_Extra_Constituents --
28328 -------------------------------
28329
28330 procedure Report_Extra_Constituents is
28331 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
28332 -- Emit an error for every element of List
28333
28334 ---------------------------------------
28335 -- Report_Extra_Constituents_In_List --
28336 ---------------------------------------
28337
28338 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
28339 Constit_Elmt : Elmt_Id;
28340
28341 begin
28342 if Present (List) then
28343 Constit_Elmt := First_Elmt (List);
28344 while Present (Constit_Elmt) loop
28345 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
28346 Next_Elmt (Constit_Elmt);
28347 end loop;
28348 end if;
28349 end Report_Extra_Constituents_In_List;
28350
28351 -- Start of processing for Report_Extra_Constituents
28352
28353 begin
28354 -- Do not perform this check in an instance because it was already
28355 -- performed successfully in the generic template.
28356
28357 if In_Instance then
28358 null;
28359
28360 else
28361 Report_Extra_Constituents_In_List (In_Constits);
28362 Report_Extra_Constituents_In_List (In_Out_Constits);
28363 Report_Extra_Constituents_In_List (Out_Constits);
28364 Report_Extra_Constituents_In_List (Proof_In_Constits);
28365 end if;
28366 end Report_Extra_Constituents;
28367
28368 --------------------------
28369 -- Report_Missing_Items --
28370 --------------------------
28371
28372 procedure Report_Missing_Items is
28373 Item_Elmt : Elmt_Id;
28374 Item_Id : Entity_Id;
28375
28376 begin
28377 -- Do not perform this check in an instance because it was already
28378 -- performed successfully in the generic template.
28379
28380 if In_Instance then
28381 null;
28382
28383 else
28384 if Present (Repeat_Items) then
28385 Item_Elmt := First_Elmt (Repeat_Items);
28386 while Present (Item_Elmt) loop
28387 Item_Id := Node (Item_Elmt);
28388 SPARK_Msg_NE ("missing global item &", N, Item_Id);
28389 Next_Elmt (Item_Elmt);
28390 end loop;
28391 end if;
28392 end if;
28393 end Report_Missing_Items;
28394
28395 -- Local variables
28396
28397 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
28398 Errors : constant Nat := Serious_Errors_Detected;
28399 Items : Node_Id;
28400 No_Constit : Boolean;
28401
28402 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
28403
28404 begin
28405 -- Do not analyze the pragma multiple times
28406
28407 if Is_Analyzed_Pragma (N) then
28408 return;
28409 end if;
28410
28411 Spec_Id := Unique_Defining_Entity (Body_Decl);
28412
28413 -- Use the anonymous object as the proper spec when Refined_Global
28414 -- applies to the body of a single task type. The object carries the
28415 -- proper Chars as well as all non-refined versions of pragmas.
28416
28417 if Is_Single_Concurrent_Type (Spec_Id) then
28418 Spec_Id := Anonymous_Object (Spec_Id);
28419 end if;
28420
28421 Global := Get_Pragma (Spec_Id, Pragma_Global);
28422 Items := Expression (Get_Argument (N, Spec_Id));
28423
28424 -- The subprogram declaration lacks pragma Global. This renders
28425 -- Refined_Global useless as there is nothing to refine.
28426
28427 if No (Global) then
28428 SPARK_Msg_NE
28429 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
28430 & "& lacks aspect or pragma Global"), N, Spec_Id);
28431 goto Leave;
28432 end if;
28433
28434 -- Extract all relevant items from the corresponding Global pragma
28435
28436 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
28437
28438 -- Package and subprogram bodies are instantiated individually in
28439 -- a separate compiler pass. Due to this mode of instantiation, the
28440 -- refinement of a state may no longer be visible when a subprogram
28441 -- body contract is instantiated. Since the generic template is legal,
28442 -- do not perform this check in the instance to circumvent this oddity.
28443
28444 if In_Instance then
28445 null;
28446
28447 -- Non-instance case
28448
28449 else
28450 -- The corresponding Global pragma must mention at least one
28451 -- state with a visible refinement at the point Refined_Global
28452 -- is processed. States with null refinements need Refined_Global
28453 -- pragma (SPARK RM 7.2.4(2)).
28454
28455 if not Has_In_State
28456 and then not Has_In_Out_State
28457 and then not Has_Out_State
28458 and then not Has_Proof_In_State
28459 and then not Has_Null_State
28460 then
28461 SPARK_Msg_NE
28462 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
28463 & "depend on abstract state with visible refinement"),
28464 N, Spec_Id);
28465 goto Leave;
28466
28467 -- The global refinement of inputs and outputs cannot be null when
28468 -- the corresponding Global pragma contains at least one item except
28469 -- in the case where we have states with null refinements.
28470
28471 elsif Nkind (Items) = N_Null
28472 and then
28473 (Present (In_Items)
28474 or else Present (In_Out_Items)
28475 or else Present (Out_Items)
28476 or else Present (Proof_In_Items))
28477 and then not Has_Null_State
28478 then
28479 SPARK_Msg_NE
28480 (Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has "
28481 & "global items"), N, Spec_Id);
28482 goto Leave;
28483 end if;
28484 end if;
28485
28486 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
28487 -- This ensures that the categorization of all refined global items is
28488 -- consistent with their role.
28489
28490 Analyze_Global_In_Decl_Part (N);
28491
28492 -- Perform all refinement checks with respect to completeness and mode
28493 -- matching.
28494
28495 if Serious_Errors_Detected = Errors then
28496 Check_Refined_Global_List (Items);
28497 end if;
28498
28499 -- Store the information that no constituent is used in the global
28500 -- refinement, prior to calling checking procedures which remove items
28501 -- from the list of constituents.
28502
28503 No_Constit :=
28504 No (In_Constits)
28505 and then No (In_Out_Constits)
28506 and then No (Out_Constits)
28507 and then No (Proof_In_Constits);
28508
28509 -- For Input states with visible refinement, at least one constituent
28510 -- must be used as an Input in the global refinement.
28511
28512 if Serious_Errors_Detected = Errors then
28513 Check_Input_States;
28514 end if;
28515
28516 -- Verify all possible completion variants for In_Out states with
28517 -- visible refinement.
28518
28519 if Serious_Errors_Detected = Errors then
28520 Check_In_Out_States;
28521 end if;
28522
28523 -- For Output states with visible refinement, all constituents must be
28524 -- used as Outputs in the global refinement.
28525
28526 if Serious_Errors_Detected = Errors then
28527 Check_Output_States;
28528 end if;
28529
28530 -- For Proof_In states with visible refinement, at least one constituent
28531 -- must be used as Proof_In in the global refinement.
28532
28533 if Serious_Errors_Detected = Errors then
28534 Check_Proof_In_States;
28535 end if;
28536
28537 -- Emit errors for all constituents that belong to other states with
28538 -- visible refinement that do not appear in Global.
28539
28540 if Serious_Errors_Detected = Errors then
28541 Report_Extra_Constituents;
28542 end if;
28543
28544 -- Emit errors for all items in Global that are not repeated in the
28545 -- global refinement and for which there is no full visible refinement
28546 -- and, in the case of states with partial visible refinement, no
28547 -- constituent is mentioned in the global refinement.
28548
28549 if Serious_Errors_Detected = Errors then
28550 Report_Missing_Items;
28551 end if;
28552
28553 -- Emit an error if no constituent is used in the global refinement
28554 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
28555 -- one may be issued by the checking procedures. Do not perform this
28556 -- check in an instance because it was already performed successfully
28557 -- in the generic template.
28558
28559 if Serious_Errors_Detected = Errors
28560 and then not In_Instance
28561 and then not Has_Null_State
28562 and then No_Constit
28563 then
28564 SPARK_Msg_N ("missing refinement", N);
28565 end if;
28566
28567 <<Leave>>
28568 Set_Is_Analyzed_Pragma (N);
28569 end Analyze_Refined_Global_In_Decl_Part;
28570
28571 ----------------------------------------
28572 -- Analyze_Refined_State_In_Decl_Part --
28573 ----------------------------------------
28574
28575 procedure Analyze_Refined_State_In_Decl_Part
28576 (N : Node_Id;
28577 Freeze_Id : Entity_Id := Empty)
28578 is
28579 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
28580 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
28581 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
28582
28583 Available_States : Elist_Id := No_Elist;
28584 -- A list of all abstract states defined in the package declaration that
28585 -- are available for refinement. The list is used to report unrefined
28586 -- states.
28587
28588 Body_States : Elist_Id := No_Elist;
28589 -- A list of all hidden states that appear in the body of the related
28590 -- package. The list is used to report unused hidden states.
28591
28592 Constituents_Seen : Elist_Id := No_Elist;
28593 -- A list that contains all constituents processed so far. The list is
28594 -- used to detect multiple uses of the same constituent.
28595
28596 Freeze_Posted : Boolean := False;
28597 -- A flag that controls the output of a freezing-related error (see use
28598 -- below).
28599
28600 Refined_States_Seen : Elist_Id := No_Elist;
28601 -- A list that contains all refined states processed so far. The list is
28602 -- used to detect duplicate refinements.
28603
28604 procedure Analyze_Refinement_Clause (Clause : Node_Id);
28605 -- Perform full analysis of a single refinement clause
28606
28607 procedure Report_Unrefined_States (States : Elist_Id);
28608 -- Emit errors for all unrefined abstract states found in list States
28609
28610 -------------------------------
28611 -- Analyze_Refinement_Clause --
28612 -------------------------------
28613
28614 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
28615 AR_Constit : Entity_Id := Empty;
28616 AW_Constit : Entity_Id := Empty;
28617 ER_Constit : Entity_Id := Empty;
28618 EW_Constit : Entity_Id := Empty;
28619 -- The entities of external constituents that contain one of the
28620 -- following enabled properties: Async_Readers, Async_Writers,
28621 -- Effective_Reads and Effective_Writes.
28622
28623 External_Constit_Seen : Boolean := False;
28624 -- Flag used to mark when at least one external constituent is part
28625 -- of the state refinement.
28626
28627 Non_Null_Seen : Boolean := False;
28628 Null_Seen : Boolean := False;
28629 -- Flags used to detect multiple uses of null in a single clause or a
28630 -- mixture of null and non-null constituents.
28631
28632 Part_Of_Constits : Elist_Id := No_Elist;
28633 -- A list of all candidate constituents subject to indicator Part_Of
28634 -- where the encapsulating state is the current state.
28635
28636 State : Node_Id;
28637 State_Id : Entity_Id;
28638 -- The current state being refined
28639
28640 procedure Analyze_Constituent (Constit : Node_Id);
28641 -- Perform full analysis of a single constituent
28642
28643 procedure Check_External_Property
28644 (Prop_Nam : Name_Id;
28645 Enabled : Boolean;
28646 Constit : Entity_Id);
28647 -- Determine whether a property denoted by name Prop_Nam is present
28648 -- in the refined state. Emit an error if this is not the case. Flag
28649 -- Enabled should be set when the property applies to the refined
28650 -- state. Constit denotes the constituent (if any) which introduces
28651 -- the property in the refinement.
28652
28653 procedure Match_State;
28654 -- Determine whether the state being refined appears in list
28655 -- Available_States. Emit an error when attempting to re-refine the
28656 -- state or when the state is not defined in the package declaration,
28657 -- otherwise remove the state from Available_States.
28658
28659 procedure Report_Unused_Constituents (Constits : Elist_Id);
28660 -- Emit errors for all unused Part_Of constituents in list Constits
28661
28662 -------------------------
28663 -- Analyze_Constituent --
28664 -------------------------
28665
28666 procedure Analyze_Constituent (Constit : Node_Id) is
28667 procedure Match_Constituent (Constit_Id : Entity_Id);
28668 -- Determine whether constituent Constit denoted by its entity
28669 -- Constit_Id appears in Body_States. Emit an error when the
28670 -- constituent is not a valid hidden state of the related package
28671 -- or when it is used more than once. Otherwise remove the
28672 -- constituent from Body_States.
28673
28674 -----------------------
28675 -- Match_Constituent --
28676 -----------------------
28677
28678 procedure Match_Constituent (Constit_Id : Entity_Id) is
28679 procedure Collect_Constituent;
28680 -- Verify the legality of constituent Constit_Id and add it to
28681 -- the refinements of State_Id.
28682
28683 -------------------------
28684 -- Collect_Constituent --
28685 -------------------------
28686
28687 procedure Collect_Constituent is
28688 Constits : Elist_Id;
28689
28690 begin
28691 -- The Ghost policy in effect at the point of abstract state
28692 -- declaration and constituent must match (SPARK RM 6.9(15))
28693
28694 Check_Ghost_Refinement
28695 (State, State_Id, Constit, Constit_Id);
28696
28697 -- A synchronized state must be refined by a synchronized
28698 -- object or another synchronized state (SPARK RM 9.6).
28699
28700 if Is_Synchronized_State (State_Id)
28701 and then not Is_Synchronized_Object (Constit_Id)
28702 and then not Is_Synchronized_State (Constit_Id)
28703 then
28704 SPARK_Msg_NE
28705 ("constituent of synchronized state & must be "
28706 & "synchronized", Constit, State_Id);
28707 end if;
28708
28709 -- Add the constituent to the list of processed items to aid
28710 -- with the detection of duplicates.
28711
28712 Append_New_Elmt (Constit_Id, Constituents_Seen);
28713
28714 -- Collect the constituent in the list of refinement items
28715 -- and establish a relation between the refined state and
28716 -- the item.
28717
28718 Constits := Refinement_Constituents (State_Id);
28719
28720 if No (Constits) then
28721 Constits := New_Elmt_List;
28722 Set_Refinement_Constituents (State_Id, Constits);
28723 end if;
28724
28725 Append_Elmt (Constit_Id, Constits);
28726 Set_Encapsulating_State (Constit_Id, State_Id);
28727
28728 -- The state has at least one legal constituent, mark the
28729 -- start of the refinement region. The region ends when the
28730 -- body declarations end (see routine Analyze_Declarations).
28731
28732 Set_Has_Visible_Refinement (State_Id);
28733
28734 -- When the constituent is external, save its relevant
28735 -- property for further checks.
28736
28737 if Async_Readers_Enabled (Constit_Id) then
28738 AR_Constit := Constit_Id;
28739 External_Constit_Seen := True;
28740 end if;
28741
28742 if Async_Writers_Enabled (Constit_Id) then
28743 AW_Constit := Constit_Id;
28744 External_Constit_Seen := True;
28745 end if;
28746
28747 if Effective_Reads_Enabled (Constit_Id) then
28748 ER_Constit := Constit_Id;
28749 External_Constit_Seen := True;
28750 end if;
28751
28752 if Effective_Writes_Enabled (Constit_Id) then
28753 EW_Constit := Constit_Id;
28754 External_Constit_Seen := True;
28755 end if;
28756 end Collect_Constituent;
28757
28758 -- Local variables
28759
28760 State_Elmt : Elmt_Id;
28761
28762 -- Start of processing for Match_Constituent
28763
28764 begin
28765 -- Detect a duplicate use of a constituent
28766
28767 if Contains (Constituents_Seen, Constit_Id) then
28768 SPARK_Msg_NE
28769 ("duplicate use of constituent &", Constit, Constit_Id);
28770 return;
28771 end if;
28772
28773 -- The constituent is subject to a Part_Of indicator
28774
28775 if Present (Encapsulating_State (Constit_Id)) then
28776 if Encapsulating_State (Constit_Id) = State_Id then
28777 Remove (Part_Of_Constits, Constit_Id);
28778 Collect_Constituent;
28779
28780 -- The constituent is part of another state and is used
28781 -- incorrectly in the refinement of the current state.
28782
28783 else
28784 Error_Msg_Name_1 := Chars (State_Id);
28785 SPARK_Msg_NE
28786 ("& cannot act as constituent of state %",
28787 Constit, Constit_Id);
28788 SPARK_Msg_NE
28789 ("\Part_Of indicator specifies encapsulator &",
28790 Constit, Encapsulating_State (Constit_Id));
28791 end if;
28792
28793 -- The only other source of legal constituents is the body
28794 -- state space of the related package.
28795
28796 else
28797 if Present (Body_States) then
28798 State_Elmt := First_Elmt (Body_States);
28799 while Present (State_Elmt) loop
28800
28801 -- Consume a valid constituent to signal that it has
28802 -- been encountered.
28803
28804 if Node (State_Elmt) = Constit_Id then
28805 Remove_Elmt (Body_States, State_Elmt);
28806 Collect_Constituent;
28807 return;
28808 end if;
28809
28810 Next_Elmt (State_Elmt);
28811 end loop;
28812 end if;
28813
28814 -- At this point it is known that the constituent is not
28815 -- part of the package hidden state and cannot be used in
28816 -- a refinement (SPARK RM 7.2.2(9)).
28817
28818 Error_Msg_Name_1 := Chars (Spec_Id);
28819 SPARK_Msg_NE
28820 ("cannot use & in refinement, constituent is not a hidden "
28821 & "state of package %", Constit, Constit_Id);
28822 end if;
28823 end Match_Constituent;
28824
28825 -- Local variables
28826
28827 Constit_Id : Entity_Id;
28828 Constits : Elist_Id;
28829
28830 -- Start of processing for Analyze_Constituent
28831
28832 begin
28833 -- Detect multiple uses of null in a single refinement clause or a
28834 -- mixture of null and non-null constituents.
28835
28836 if Nkind (Constit) = N_Null then
28837 if Null_Seen then
28838 SPARK_Msg_N
28839 ("multiple null constituents not allowed", Constit);
28840
28841 elsif Non_Null_Seen then
28842 SPARK_Msg_N
28843 ("cannot mix null and non-null constituents", Constit);
28844
28845 else
28846 Null_Seen := True;
28847
28848 -- Collect the constituent in the list of refinement items
28849
28850 Constits := Refinement_Constituents (State_Id);
28851
28852 if No (Constits) then
28853 Constits := New_Elmt_List;
28854 Set_Refinement_Constituents (State_Id, Constits);
28855 end if;
28856
28857 Append_Elmt (Constit, Constits);
28858
28859 -- The state has at least one legal constituent, mark the
28860 -- start of the refinement region. The region ends when the
28861 -- body declarations end (see Analyze_Declarations).
28862
28863 Set_Has_Visible_Refinement (State_Id);
28864 end if;
28865
28866 -- Non-null constituents
28867
28868 else
28869 Non_Null_Seen := True;
28870
28871 if Null_Seen then
28872 SPARK_Msg_N
28873 ("cannot mix null and non-null constituents", Constit);
28874 end if;
28875
28876 Analyze (Constit);
28877 Resolve_State (Constit);
28878
28879 -- Ensure that the constituent denotes a valid state or a
28880 -- whole object (SPARK RM 7.2.2(5)).
28881
28882 if Is_Entity_Name (Constit) then
28883 Constit_Id := Entity_Of (Constit);
28884
28885 -- When a constituent is declared after a subprogram body
28886 -- that caused freezing of the related contract where
28887 -- pragma Refined_State resides, the constituent appears
28888 -- undefined and carries Any_Id as its entity.
28889
28890 -- package body Pack
28891 -- with Refined_State => (State => Constit)
28892 -- is
28893 -- procedure Proc
28894 -- with Refined_Global => (Input => Constit)
28895 -- is
28896 -- ...
28897 -- end Proc;
28898
28899 -- Constit : ...;
28900 -- end Pack;
28901
28902 if Constit_Id = Any_Id then
28903 SPARK_Msg_NE ("& is undefined", Constit, Constit_Id);
28904
28905 -- Emit a specialized info message when the contract of
28906 -- the related package body was "frozen" by another body.
28907 -- Note that it is not possible to precisely identify why
28908 -- the constituent is undefined because it is not visible
28909 -- when pragma Refined_State is analyzed. This message is
28910 -- a reasonable approximation.
28911
28912 if Present (Freeze_Id) and then not Freeze_Posted then
28913 Freeze_Posted := True;
28914
28915 Error_Msg_Name_1 := Chars (Body_Id);
28916 Error_Msg_Sloc := Sloc (Freeze_Id);
28917 SPARK_Msg_NE
28918 ("body & declared # freezes the contract of %",
28919 N, Freeze_Id);
28920 SPARK_Msg_N
28921 ("\all constituents must be declared before body #",
28922 N);
28923
28924 -- A misplaced constituent is a critical error because
28925 -- pragma Refined_Depends or Refined_Global depends on
28926 -- the proper link between a state and a constituent.
28927 -- Stop the compilation, as this leads to a multitude
28928 -- of misleading cascaded errors.
28929
28930 raise Unrecoverable_Error;
28931 end if;
28932
28933 -- The constituent is a valid state or object
28934
28935 elsif Ekind_In (Constit_Id, E_Abstract_State,
28936 E_Constant,
28937 E_Variable)
28938 then
28939 Match_Constituent (Constit_Id);
28940
28941 -- The variable may eventually become a constituent of a
28942 -- single protected/task type. Record the reference now
28943 -- and verify its legality when analyzing the contract of
28944 -- the variable (SPARK RM 9.3).
28945
28946 if Ekind (Constit_Id) = E_Variable then
28947 Record_Possible_Part_Of_Reference
28948 (Var_Id => Constit_Id,
28949 Ref => Constit);
28950 end if;
28951
28952 -- Otherwise the constituent is illegal
28953
28954 else
28955 SPARK_Msg_NE
28956 ("constituent & must denote object or state",
28957 Constit, Constit_Id);
28958 end if;
28959
28960 -- The constituent is illegal
28961
28962 else
28963 SPARK_Msg_N ("malformed constituent", Constit);
28964 end if;
28965 end if;
28966 end Analyze_Constituent;
28967
28968 -----------------------------
28969 -- Check_External_Property --
28970 -----------------------------
28971
28972 procedure Check_External_Property
28973 (Prop_Nam : Name_Id;
28974 Enabled : Boolean;
28975 Constit : Entity_Id)
28976 is
28977 begin
28978 -- The property is missing in the declaration of the state, but
28979 -- a constituent is introducing it in the state refinement
28980 -- (SPARK RM 7.2.8(2)).
28981
28982 if not Enabled and then Present (Constit) then
28983 Error_Msg_Name_1 := Prop_Nam;
28984 Error_Msg_Name_2 := Chars (State_Id);
28985 SPARK_Msg_NE
28986 ("constituent & introduces external property % in refinement "
28987 & "of state %", State, Constit);
28988
28989 Error_Msg_Sloc := Sloc (State_Id);
28990 SPARK_Msg_N
28991 ("\property is missing in abstract state declaration #",
28992 State);
28993 end if;
28994 end Check_External_Property;
28995
28996 -----------------
28997 -- Match_State --
28998 -----------------
28999
29000 procedure Match_State is
29001 State_Elmt : Elmt_Id;
29002
29003 begin
29004 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
29005
29006 if Contains (Refined_States_Seen, State_Id) then
29007 SPARK_Msg_NE
29008 ("duplicate refinement of state &", State, State_Id);
29009 return;
29010 end if;
29011
29012 -- Inspect the abstract states defined in the package declaration
29013 -- looking for a match.
29014
29015 State_Elmt := First_Elmt (Available_States);
29016 while Present (State_Elmt) loop
29017
29018 -- A valid abstract state is being refined in the body. Add
29019 -- the state to the list of processed refined states to aid
29020 -- with the detection of duplicate refinements. Remove the
29021 -- state from Available_States to signal that it has already
29022 -- been refined.
29023
29024 if Node (State_Elmt) = State_Id then
29025 Append_New_Elmt (State_Id, Refined_States_Seen);
29026 Remove_Elmt (Available_States, State_Elmt);
29027 return;
29028 end if;
29029
29030 Next_Elmt (State_Elmt);
29031 end loop;
29032
29033 -- If we get here, we are refining a state that is not defined in
29034 -- the package declaration.
29035
29036 Error_Msg_Name_1 := Chars (Spec_Id);
29037 SPARK_Msg_NE
29038 ("cannot refine state, & is not defined in package %",
29039 State, State_Id);
29040 end Match_State;
29041
29042 --------------------------------
29043 -- Report_Unused_Constituents --
29044 --------------------------------
29045
29046 procedure Report_Unused_Constituents (Constits : Elist_Id) is
29047 Constit_Elmt : Elmt_Id;
29048 Constit_Id : Entity_Id;
29049 Posted : Boolean := False;
29050
29051 begin
29052 if Present (Constits) then
29053 Constit_Elmt := First_Elmt (Constits);
29054 while Present (Constit_Elmt) loop
29055 Constit_Id := Node (Constit_Elmt);
29056
29057 -- Generate an error message of the form:
29058
29059 -- state ... has unused Part_Of constituents
29060 -- abstract state ... defined at ...
29061 -- constant ... defined at ...
29062 -- variable ... defined at ...
29063
29064 if not Posted then
29065 Posted := True;
29066 SPARK_Msg_NE
29067 ("state & has unused Part_Of constituents",
29068 State, State_Id);
29069 end if;
29070
29071 Error_Msg_Sloc := Sloc (Constit_Id);
29072
29073 if Ekind (Constit_Id) = E_Abstract_State then
29074 SPARK_Msg_NE
29075 ("\abstract state & defined #", State, Constit_Id);
29076
29077 elsif Ekind (Constit_Id) = E_Constant then
29078 SPARK_Msg_NE
29079 ("\constant & defined #", State, Constit_Id);
29080
29081 else
29082 pragma Assert (Ekind (Constit_Id) = E_Variable);
29083 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
29084 end if;
29085
29086 Next_Elmt (Constit_Elmt);
29087 end loop;
29088 end if;
29089 end Report_Unused_Constituents;
29090
29091 -- Local declarations
29092
29093 Body_Ref : Node_Id;
29094 Body_Ref_Elmt : Elmt_Id;
29095 Constit : Node_Id;
29096 Extra_State : Node_Id;
29097
29098 -- Start of processing for Analyze_Refinement_Clause
29099
29100 begin
29101 -- A refinement clause appears as a component association where the
29102 -- sole choice is the state and the expressions are the constituents.
29103 -- This is a syntax error, always report.
29104
29105 if Nkind (Clause) /= N_Component_Association then
29106 Error_Msg_N ("malformed state refinement clause", Clause);
29107 return;
29108 end if;
29109
29110 -- Analyze the state name of a refinement clause
29111
29112 State := First (Choices (Clause));
29113
29114 Analyze (State);
29115 Resolve_State (State);
29116
29117 -- Ensure that the state name denotes a valid abstract state that is
29118 -- defined in the spec of the related package.
29119
29120 if Is_Entity_Name (State) then
29121 State_Id := Entity_Of (State);
29122
29123 -- When the abstract state is undefined, it appears as Any_Id. Do
29124 -- not continue with the analysis of the clause.
29125
29126 if State_Id = Any_Id then
29127 return;
29128
29129 -- Catch any attempts to re-refine a state or refine a state that
29130 -- is not defined in the package declaration.
29131
29132 elsif Ekind (State_Id) = E_Abstract_State then
29133 Match_State;
29134
29135 else
29136 SPARK_Msg_NE ("& must denote abstract state", State, State_Id);
29137 return;
29138 end if;
29139
29140 -- References to a state with visible refinement are illegal.
29141 -- When nested packages are involved, detecting such references is
29142 -- tricky because pragma Refined_State is analyzed later than the
29143 -- offending pragma Depends or Global. References that occur in
29144 -- such nested context are stored in a list. Emit errors for all
29145 -- references found in Body_References (SPARK RM 6.1.4(8)).
29146
29147 if Present (Body_References (State_Id)) then
29148 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
29149 while Present (Body_Ref_Elmt) loop
29150 Body_Ref := Node (Body_Ref_Elmt);
29151
29152 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
29153 Error_Msg_Sloc := Sloc (State);
29154 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
29155
29156 Next_Elmt (Body_Ref_Elmt);
29157 end loop;
29158 end if;
29159
29160 -- The state name is illegal. This is a syntax error, always report.
29161
29162 else
29163 Error_Msg_N ("malformed state name in refinement clause", State);
29164 return;
29165 end if;
29166
29167 -- A refinement clause may only refine one state at a time
29168
29169 Extra_State := Next (State);
29170
29171 if Present (Extra_State) then
29172 SPARK_Msg_N
29173 ("refinement clause cannot cover multiple states", Extra_State);
29174 end if;
29175
29176 -- Replicate the Part_Of constituents of the refined state because
29177 -- the algorithm will consume items.
29178
29179 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
29180
29181 -- Analyze all constituents of the refinement. Multiple constituents
29182 -- appear as an aggregate.
29183
29184 Constit := Expression (Clause);
29185
29186 if Nkind (Constit) = N_Aggregate then
29187 if Present (Component_Associations (Constit)) then
29188 SPARK_Msg_N
29189 ("constituents of refinement clause must appear in "
29190 & "positional form", Constit);
29191
29192 else pragma Assert (Present (Expressions (Constit)));
29193 Constit := First (Expressions (Constit));
29194 while Present (Constit) loop
29195 Analyze_Constituent (Constit);
29196 Next (Constit);
29197 end loop;
29198 end if;
29199
29200 -- Various forms of a single constituent. Note that these may include
29201 -- malformed constituents.
29202
29203 else
29204 Analyze_Constituent (Constit);
29205 end if;
29206
29207 -- Verify that external constituents do not introduce new external
29208 -- property in the state refinement (SPARK RM 7.2.8(2)).
29209
29210 if Is_External_State (State_Id) then
29211 Check_External_Property
29212 (Prop_Nam => Name_Async_Readers,
29213 Enabled => Async_Readers_Enabled (State_Id),
29214 Constit => AR_Constit);
29215
29216 Check_External_Property
29217 (Prop_Nam => Name_Async_Writers,
29218 Enabled => Async_Writers_Enabled (State_Id),
29219 Constit => AW_Constit);
29220
29221 Check_External_Property
29222 (Prop_Nam => Name_Effective_Reads,
29223 Enabled => Effective_Reads_Enabled (State_Id),
29224 Constit => ER_Constit);
29225
29226 Check_External_Property
29227 (Prop_Nam => Name_Effective_Writes,
29228 Enabled => Effective_Writes_Enabled (State_Id),
29229 Constit => EW_Constit);
29230
29231 -- When a refined state is not external, it should not have external
29232 -- constituents (SPARK RM 7.2.8(1)).
29233
29234 elsif External_Constit_Seen then
29235 SPARK_Msg_NE
29236 ("non-external state & cannot contain external constituents in "
29237 & "refinement", State, State_Id);
29238 end if;
29239
29240 -- Ensure that all Part_Of candidate constituents have been mentioned
29241 -- in the refinement clause.
29242
29243 Report_Unused_Constituents (Part_Of_Constits);
29244 end Analyze_Refinement_Clause;
29245
29246 -----------------------------
29247 -- Report_Unrefined_States --
29248 -----------------------------
29249
29250 procedure Report_Unrefined_States (States : Elist_Id) is
29251 State_Elmt : Elmt_Id;
29252
29253 begin
29254 if Present (States) then
29255 State_Elmt := First_Elmt (States);
29256 while Present (State_Elmt) loop
29257 SPARK_Msg_N
29258 ("abstract state & must be refined", Node (State_Elmt));
29259
29260 Next_Elmt (State_Elmt);
29261 end loop;
29262 end if;
29263 end Report_Unrefined_States;
29264
29265 -- Local declarations
29266
29267 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
29268 Clause : Node_Id;
29269
29270 -- Start of processing for Analyze_Refined_State_In_Decl_Part
29271
29272 begin
29273 -- Do not analyze the pragma multiple times
29274
29275 if Is_Analyzed_Pragma (N) then
29276 return;
29277 end if;
29278
29279 -- Save the scenario for examination by the ABE Processing phase
29280
29281 Record_Elaboration_Scenario (N);
29282
29283 -- Replicate the abstract states declared by the package because the
29284 -- matching algorithm will consume states.
29285
29286 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
29287
29288 -- Gather all abstract states and objects declared in the visible
29289 -- state space of the package body. These items must be utilized as
29290 -- constituents in a state refinement.
29291
29292 Body_States := Collect_Body_States (Body_Id);
29293
29294 -- Multiple non-null state refinements appear as an aggregate
29295
29296 if Nkind (Clauses) = N_Aggregate then
29297 if Present (Expressions (Clauses)) then
29298 SPARK_Msg_N
29299 ("state refinements must appear as component associations",
29300 Clauses);
29301
29302 else pragma Assert (Present (Component_Associations (Clauses)));
29303 Clause := First (Component_Associations (Clauses));
29304 while Present (Clause) loop
29305 Analyze_Refinement_Clause (Clause);
29306 Next (Clause);
29307 end loop;
29308 end if;
29309
29310 -- Various forms of a single state refinement. Note that these may
29311 -- include malformed refinements.
29312
29313 else
29314 Analyze_Refinement_Clause (Clauses);
29315 end if;
29316
29317 -- List all abstract states that were left unrefined
29318
29319 Report_Unrefined_States (Available_States);
29320
29321 Set_Is_Analyzed_Pragma (N);
29322 end Analyze_Refined_State_In_Decl_Part;
29323
29324 ------------------------------------
29325 -- Analyze_Test_Case_In_Decl_Part --
29326 ------------------------------------
29327
29328 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
29329 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
29330 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
29331
29332 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
29333 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
29334 -- denoted by Arg_Nam.
29335
29336 ------------------------------
29337 -- Preanalyze_Test_Case_Arg --
29338 ------------------------------
29339
29340 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
29341 Arg : Node_Id;
29342
29343 begin
29344 -- Preanalyze the original aspect argument for a generic subprogram
29345 -- to properly capture global references.
29346
29347 if Is_Generic_Subprogram (Spec_Id) then
29348 Arg :=
29349 Test_Case_Arg
29350 (Prag => N,
29351 Arg_Nam => Arg_Nam,
29352 From_Aspect => True);
29353
29354 if Present (Arg) then
29355 Preanalyze_Assert_Expression
29356 (Expression (Arg), Standard_Boolean);
29357 end if;
29358 end if;
29359
29360 Arg := Test_Case_Arg (N, Arg_Nam);
29361
29362 if Present (Arg) then
29363 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
29364 end if;
29365 end Preanalyze_Test_Case_Arg;
29366
29367 -- Local variables
29368
29369 Restore_Scope : Boolean := False;
29370
29371 -- Start of processing for Analyze_Test_Case_In_Decl_Part
29372
29373 begin
29374 -- Do not analyze the pragma multiple times
29375
29376 if Is_Analyzed_Pragma (N) then
29377 return;
29378 end if;
29379
29380 -- Ensure that the formal parameters are visible when analyzing all
29381 -- clauses. This falls out of the general rule of aspects pertaining
29382 -- to subprogram declarations.
29383
29384 if not In_Open_Scopes (Spec_Id) then
29385 Restore_Scope := True;
29386 Push_Scope (Spec_Id);
29387
29388 if Is_Generic_Subprogram (Spec_Id) then
29389 Install_Generic_Formals (Spec_Id);
29390 else
29391 Install_Formals (Spec_Id);
29392 end if;
29393 end if;
29394
29395 Preanalyze_Test_Case_Arg (Name_Requires);
29396 Preanalyze_Test_Case_Arg (Name_Ensures);
29397
29398 if Restore_Scope then
29399 End_Scope;
29400 end if;
29401
29402 -- Currently it is not possible to inline pre/postconditions on a
29403 -- subprogram subject to pragma Inline_Always.
29404
29405 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
29406
29407 Set_Is_Analyzed_Pragma (N);
29408 end Analyze_Test_Case_In_Decl_Part;
29409
29410 ----------------
29411 -- Appears_In --
29412 ----------------
29413
29414 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
29415 Elmt : Elmt_Id;
29416 Id : Entity_Id;
29417
29418 begin
29419 if Present (List) then
29420 Elmt := First_Elmt (List);
29421 while Present (Elmt) loop
29422 if Nkind (Node (Elmt)) = N_Defining_Identifier then
29423 Id := Node (Elmt);
29424 else
29425 Id := Entity_Of (Node (Elmt));
29426 end if;
29427
29428 if Id = Item_Id then
29429 return True;
29430 end if;
29431
29432 Next_Elmt (Elmt);
29433 end loop;
29434 end if;
29435
29436 return False;
29437 end Appears_In;
29438
29439 -----------------------------------
29440 -- Build_Pragma_Check_Equivalent --
29441 -----------------------------------
29442
29443 function Build_Pragma_Check_Equivalent
29444 (Prag : Node_Id;
29445 Subp_Id : Entity_Id := Empty;
29446 Inher_Id : Entity_Id := Empty;
29447 Keep_Pragma_Id : Boolean := False) return Node_Id
29448 is
29449 function Suppress_Reference (N : Node_Id) return Traverse_Result;
29450 -- Detect whether node N references a formal parameter subject to
29451 -- pragma Unreferenced. If this is the case, set Comes_From_Source
29452 -- to False to suppress the generation of a reference when analyzing
29453 -- N later on.
29454
29455 ------------------------
29456 -- Suppress_Reference --
29457 ------------------------
29458
29459 function Suppress_Reference (N : Node_Id) return Traverse_Result is
29460 Formal : Entity_Id;
29461
29462 begin
29463 if Is_Entity_Name (N) and then Present (Entity (N)) then
29464 Formal := Entity (N);
29465
29466 -- The formal parameter is subject to pragma Unreferenced. Prevent
29467 -- the generation of references by resetting the Comes_From_Source
29468 -- flag.
29469
29470 if Is_Formal (Formal)
29471 and then Has_Pragma_Unreferenced (Formal)
29472 then
29473 Set_Comes_From_Source (N, False);
29474 end if;
29475 end if;
29476
29477 return OK;
29478 end Suppress_Reference;
29479
29480 procedure Suppress_References is
29481 new Traverse_Proc (Suppress_Reference);
29482
29483 -- Local variables
29484
29485 Loc : constant Source_Ptr := Sloc (Prag);
29486 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
29487 Check_Prag : Node_Id;
29488 Msg_Arg : Node_Id;
29489 Nam : Name_Id;
29490
29491 Needs_Wrapper : Boolean;
29492 pragma Unreferenced (Needs_Wrapper);
29493
29494 -- Start of processing for Build_Pragma_Check_Equivalent
29495
29496 begin
29497 -- When the pre- or postcondition is inherited, map the formals of the
29498 -- inherited subprogram to those of the current subprogram. In addition,
29499 -- map primitive operations of the parent type into the corresponding
29500 -- primitive operations of the descendant.
29501
29502 if Present (Inher_Id) then
29503 pragma Assert (Present (Subp_Id));
29504
29505 Update_Primitives_Mapping (Inher_Id, Subp_Id);
29506
29507 -- Use generic machinery to copy inherited pragma, as if it were an
29508 -- instantiation, resetting source locations appropriately, so that
29509 -- expressions inside the inherited pragma use chained locations.
29510 -- This is used in particular in GNATprove to locate precisely
29511 -- messages on a given inherited pragma.
29512
29513 Set_Copied_Sloc_For_Inherited_Pragma
29514 (Unit_Declaration_Node (Subp_Id), Inher_Id);
29515 Check_Prag := New_Copy_Tree (Source => Prag);
29516
29517 -- Build the inherited class-wide condition
29518
29519 Build_Class_Wide_Expression
29520 (Prag => Check_Prag,
29521 Subp => Subp_Id,
29522 Par_Subp => Inher_Id,
29523 Adjust_Sloc => True,
29524 Needs_Wrapper => Needs_Wrapper);
29525
29526 -- If not an inherited condition simply copy the original pragma
29527
29528 else
29529 Check_Prag := New_Copy_Tree (Source => Prag);
29530 end if;
29531
29532 -- Mark the pragma as being internally generated and reset the Analyzed
29533 -- flag.
29534
29535 Set_Analyzed (Check_Prag, False);
29536 Set_Comes_From_Source (Check_Prag, False);
29537
29538 -- The tree of the original pragma may contain references to the
29539 -- formal parameters of the related subprogram. At the same time
29540 -- the corresponding body may mark the formals as unreferenced:
29541
29542 -- procedure Proc (Formal : ...)
29543 -- with Pre => Formal ...;
29544
29545 -- procedure Proc (Formal : ...) is
29546 -- pragma Unreferenced (Formal);
29547 -- ...
29548
29549 -- This creates problems because all pragma Check equivalents are
29550 -- analyzed at the end of the body declarations. Since all source
29551 -- references have already been accounted for, reset any references
29552 -- to such formals in the generated pragma Check equivalent.
29553
29554 Suppress_References (Check_Prag);
29555
29556 if Present (Corresponding_Aspect (Prag)) then
29557 Nam := Chars (Identifier (Corresponding_Aspect (Prag)));
29558 else
29559 Nam := Prag_Nam;
29560 end if;
29561
29562 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
29563 -- the copied pragma in the newly created pragma, convert the copy into
29564 -- pragma Check by correcting the name and adding a check_kind argument.
29565
29566 if not Keep_Pragma_Id then
29567 Set_Class_Present (Check_Prag, False);
29568
29569 Set_Pragma_Identifier
29570 (Check_Prag, Make_Identifier (Loc, Name_Check));
29571
29572 Prepend_To (Pragma_Argument_Associations (Check_Prag),
29573 Make_Pragma_Argument_Association (Loc,
29574 Expression => Make_Identifier (Loc, Nam)));
29575 end if;
29576
29577 -- Update the error message when the pragma is inherited
29578
29579 if Present (Inher_Id) then
29580 Msg_Arg := Last (Pragma_Argument_Associations (Check_Prag));
29581
29582 if Chars (Msg_Arg) = Name_Message then
29583 String_To_Name_Buffer (Strval (Expression (Msg_Arg)));
29584
29585 -- Insert "inherited" to improve the error message
29586
29587 if Name_Buffer (1 .. 8) = "failed p" then
29588 Insert_Str_In_Name_Buffer ("inherited ", 8);
29589 Set_Strval (Expression (Msg_Arg), String_From_Name_Buffer);
29590 end if;
29591 end if;
29592 end if;
29593
29594 return Check_Prag;
29595 end Build_Pragma_Check_Equivalent;
29596
29597 -----------------------------
29598 -- Check_Applicable_Policy --
29599 -----------------------------
29600
29601 procedure Check_Applicable_Policy (N : Node_Id) is
29602 PP : Node_Id;
29603 Policy : Name_Id;
29604
29605 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
29606
29607 begin
29608 -- No effect if not valid assertion kind name
29609
29610 if not Is_Valid_Assertion_Kind (Ename) then
29611 return;
29612 end if;
29613
29614 -- Loop through entries in check policy list
29615
29616 PP := Opt.Check_Policy_List;
29617 while Present (PP) loop
29618 declare
29619 PPA : constant List_Id := Pragma_Argument_Associations (PP);
29620 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
29621
29622 begin
29623 if Ename = Pnm
29624 or else Pnm = Name_Assertion
29625 or else (Pnm = Name_Statement_Assertions
29626 and then Nam_In (Ename, Name_Assert,
29627 Name_Assert_And_Cut,
29628 Name_Assume,
29629 Name_Loop_Invariant,
29630 Name_Loop_Variant))
29631 then
29632 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
29633
29634 case Policy is
29635 when Name_Ignore
29636 | Name_Off
29637 =>
29638 -- In CodePeer mode and GNATprove mode, we need to
29639 -- consider all assertions, unless they are disabled.
29640 -- Force Is_Checked on ignored assertions, in particular
29641 -- because transformations of the AST may depend on
29642 -- assertions being checked (e.g. the translation of
29643 -- attribute 'Loop_Entry).
29644
29645 if CodePeer_Mode or GNATprove_Mode then
29646 Set_Is_Checked (N, True);
29647 Set_Is_Ignored (N, False);
29648 else
29649 Set_Is_Checked (N, False);
29650 Set_Is_Ignored (N, True);
29651 end if;
29652
29653 when Name_Check
29654 | Name_On
29655 =>
29656 Set_Is_Checked (N, True);
29657 Set_Is_Ignored (N, False);
29658
29659 when Name_Disable =>
29660 Set_Is_Ignored (N, True);
29661 Set_Is_Checked (N, False);
29662 Set_Is_Disabled (N, True);
29663
29664 -- That should be exhaustive, the null here is a defence
29665 -- against a malformed tree from previous errors.
29666
29667 when others =>
29668 null;
29669 end case;
29670
29671 return;
29672 end if;
29673
29674 PP := Next_Pragma (PP);
29675 end;
29676 end loop;
29677
29678 -- If there are no specific entries that matched, then we let the
29679 -- setting of assertions govern. Note that this provides the needed
29680 -- compatibility with the RM for the cases of assertion, invariant,
29681 -- precondition, predicate, and postcondition. Note also that
29682 -- Assertions_Enabled is forced in CodePeer mode and GNATprove mode.
29683
29684 if Assertions_Enabled then
29685 Set_Is_Checked (N, True);
29686 Set_Is_Ignored (N, False);
29687 else
29688 Set_Is_Checked (N, False);
29689 Set_Is_Ignored (N, True);
29690 end if;
29691 end Check_Applicable_Policy;
29692
29693 -------------------------------
29694 -- Check_External_Properties --
29695 -------------------------------
29696
29697 procedure Check_External_Properties
29698 (Item : Node_Id;
29699 AR : Boolean;
29700 AW : Boolean;
29701 ER : Boolean;
29702 EW : Boolean)
29703 is
29704 begin
29705 -- All properties enabled
29706
29707 if AR and AW and ER and EW then
29708 null;
29709
29710 -- Async_Readers + Effective_Writes
29711 -- Async_Readers + Async_Writers + Effective_Writes
29712
29713 elsif AR and EW and not ER then
29714 null;
29715
29716 -- Async_Writers + Effective_Reads
29717 -- Async_Readers + Async_Writers + Effective_Reads
29718
29719 elsif AW and ER and not EW then
29720 null;
29721
29722 -- Async_Readers + Async_Writers
29723
29724 elsif AR and AW and not ER and not EW then
29725 null;
29726
29727 -- Async_Readers
29728
29729 elsif AR and not AW and not ER and not EW then
29730 null;
29731
29732 -- Async_Writers
29733
29734 elsif AW and not AR and not ER and not EW then
29735 null;
29736
29737 else
29738 SPARK_Msg_N
29739 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
29740 Item);
29741 end if;
29742 end Check_External_Properties;
29743
29744 ----------------
29745 -- Check_Kind --
29746 ----------------
29747
29748 function Check_Kind (Nam : Name_Id) return Name_Id is
29749 PP : Node_Id;
29750
29751 begin
29752 -- Loop through entries in check policy list
29753
29754 PP := Opt.Check_Policy_List;
29755 while Present (PP) loop
29756 declare
29757 PPA : constant List_Id := Pragma_Argument_Associations (PP);
29758 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
29759
29760 begin
29761 if Nam = Pnm
29762 or else (Pnm = Name_Assertion
29763 and then Is_Valid_Assertion_Kind (Nam))
29764 or else (Pnm = Name_Statement_Assertions
29765 and then Nam_In (Nam, Name_Assert,
29766 Name_Assert_And_Cut,
29767 Name_Assume,
29768 Name_Loop_Invariant,
29769 Name_Loop_Variant))
29770 then
29771 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
29772 when Name_Check
29773 | Name_On
29774 =>
29775 return Name_Check;
29776
29777 when Name_Ignore
29778 | Name_Off
29779 =>
29780 return Name_Ignore;
29781
29782 when Name_Disable =>
29783 return Name_Disable;
29784
29785 when others =>
29786 raise Program_Error;
29787 end case;
29788
29789 else
29790 PP := Next_Pragma (PP);
29791 end if;
29792 end;
29793 end loop;
29794
29795 -- If there are no specific entries that matched, then we let the
29796 -- setting of assertions govern. Note that this provides the needed
29797 -- compatibility with the RM for the cases of assertion, invariant,
29798 -- precondition, predicate, and postcondition.
29799
29800 if Assertions_Enabled then
29801 return Name_Check;
29802 else
29803 return Name_Ignore;
29804 end if;
29805 end Check_Kind;
29806
29807 ---------------------------
29808 -- Check_Missing_Part_Of --
29809 ---------------------------
29810
29811 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
29812 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
29813 -- Determine whether a package denoted by Pack_Id declares at least one
29814 -- visible state.
29815
29816 -----------------------
29817 -- Has_Visible_State --
29818 -----------------------
29819
29820 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
29821 Item_Id : Entity_Id;
29822
29823 begin
29824 -- Traverse the entity chain of the package trying to find at least
29825 -- one visible abstract state, variable or a package [instantiation]
29826 -- that declares a visible state.
29827
29828 Item_Id := First_Entity (Pack_Id);
29829 while Present (Item_Id)
29830 and then not In_Private_Part (Item_Id)
29831 loop
29832 -- Do not consider internally generated items
29833
29834 if not Comes_From_Source (Item_Id) then
29835 null;
29836
29837 -- Do not consider generic formals or their corresponding actuals
29838 -- because they are not part of a visible state. Note that both
29839 -- entities are marked as hidden.
29840
29841 elsif Is_Hidden (Item_Id) then
29842 null;
29843
29844 -- A visible state has been found. Note that constants are not
29845 -- considered here because it is not possible to determine whether
29846 -- they depend on variable input. This check is left to the SPARK
29847 -- prover.
29848
29849 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
29850 return True;
29851
29852 -- Recursively peek into nested packages and instantiations
29853
29854 elsif Ekind (Item_Id) = E_Package
29855 and then Has_Visible_State (Item_Id)
29856 then
29857 return True;
29858 end if;
29859
29860 Next_Entity (Item_Id);
29861 end loop;
29862
29863 return False;
29864 end Has_Visible_State;
29865
29866 -- Local variables
29867
29868 Pack_Id : Entity_Id;
29869 Placement : State_Space_Kind;
29870
29871 -- Start of processing for Check_Missing_Part_Of
29872
29873 begin
29874 -- Do not consider abstract states, variables or package instantiations
29875 -- coming from an instance as those always inherit the Part_Of indicator
29876 -- of the instance itself.
29877
29878 if In_Instance then
29879 return;
29880
29881 -- Do not consider internally generated entities as these can never
29882 -- have a Part_Of indicator.
29883
29884 elsif not Comes_From_Source (Item_Id) then
29885 return;
29886
29887 -- Perform these checks only when SPARK_Mode is enabled as they will
29888 -- interfere with standard Ada rules and produce false positives.
29889
29890 elsif SPARK_Mode /= On then
29891 return;
29892
29893 -- Do not consider constants, because the compiler cannot accurately
29894 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
29895 -- act as a hidden state of a package.
29896
29897 elsif Ekind (Item_Id) = E_Constant then
29898 return;
29899 end if;
29900
29901 -- Find where the abstract state, variable or package instantiation
29902 -- lives with respect to the state space.
29903
29904 Find_Placement_In_State_Space
29905 (Item_Id => Item_Id,
29906 Placement => Placement,
29907 Pack_Id => Pack_Id);
29908
29909 -- Items that appear in a non-package construct (subprogram, block, etc)
29910 -- do not require a Part_Of indicator because they can never act as a
29911 -- hidden state.
29912
29913 if Placement = Not_In_Package then
29914 null;
29915
29916 -- An item declared in the body state space of a package always act as a
29917 -- constituent and does not need explicit Part_Of indicator.
29918
29919 elsif Placement = Body_State_Space then
29920 null;
29921
29922 -- In general an item declared in the visible state space of a package
29923 -- does not require a Part_Of indicator. The only exception is when the
29924 -- related package is a nongeneric private child unit, in which case
29925 -- Part_Of must denote a state in the parent unit or in one of its
29926 -- descendants.
29927
29928 elsif Placement = Visible_State_Space then
29929 if Is_Child_Unit (Pack_Id)
29930 and then not Is_Generic_Unit (Pack_Id)
29931 and then Is_Private_Descendant (Pack_Id)
29932 then
29933 -- A package instantiation does not need a Part_Of indicator when
29934 -- the related generic template has no visible state.
29935
29936 if Ekind (Item_Id) = E_Package
29937 and then Is_Generic_Instance (Item_Id)
29938 and then not Has_Visible_State (Item_Id)
29939 then
29940 null;
29941
29942 -- All other cases require Part_Of
29943
29944 else
29945 Error_Msg_N
29946 ("indicator Part_Of is required in this context "
29947 & "(SPARK RM 7.2.6(3))", Item_Id);
29948 Error_Msg_Name_1 := Chars (Pack_Id);
29949 Error_Msg_N
29950 ("\& is declared in the visible part of private child "
29951 & "unit %", Item_Id);
29952 end if;
29953 end if;
29954
29955 -- When the item appears in the private state space of a package, it
29956 -- must be a part of some state declared by the said package.
29957
29958 else pragma Assert (Placement = Private_State_Space);
29959
29960 -- The related package does not declare a state, the item cannot act
29961 -- as a Part_Of constituent.
29962
29963 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
29964 null;
29965
29966 -- A package instantiation does not need a Part_Of indicator when the
29967 -- related generic template has no visible state.
29968
29969 elsif Ekind (Item_Id) = E_Package
29970 and then Is_Generic_Instance (Item_Id)
29971 and then not Has_Visible_State (Item_Id)
29972 then
29973 null;
29974
29975 -- All other cases require Part_Of
29976
29977 else
29978 Error_Msg_N
29979 ("indicator Part_Of is required in this context "
29980 & "(SPARK RM 7.2.6(2))", Item_Id);
29981 Error_Msg_Name_1 := Chars (Pack_Id);
29982 Error_Msg_N
29983 ("\& is declared in the private part of package %", Item_Id);
29984 end if;
29985 end if;
29986 end Check_Missing_Part_Of;
29987
29988 ---------------------------------------------------
29989 -- Check_Postcondition_Use_In_Inlined_Subprogram --
29990 ---------------------------------------------------
29991
29992 procedure Check_Postcondition_Use_In_Inlined_Subprogram
29993 (Prag : Node_Id;
29994 Spec_Id : Entity_Id)
29995 is
29996 begin
29997 if Warn_On_Redundant_Constructs
29998 and then Has_Pragma_Inline_Always (Spec_Id)
29999 and then Assertions_Enabled
30000 then
30001 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
30002
30003 if From_Aspect_Specification (Prag) then
30004 Error_Msg_NE
30005 ("aspect % not enforced on inlined subprogram &?r?",
30006 Corresponding_Aspect (Prag), Spec_Id);
30007 else
30008 Error_Msg_NE
30009 ("pragma % not enforced on inlined subprogram &?r?",
30010 Prag, Spec_Id);
30011 end if;
30012 end if;
30013 end Check_Postcondition_Use_In_Inlined_Subprogram;
30014
30015 -------------------------------------
30016 -- Check_State_And_Constituent_Use --
30017 -------------------------------------
30018
30019 procedure Check_State_And_Constituent_Use
30020 (States : Elist_Id;
30021 Constits : Elist_Id;
30022 Context : Node_Id)
30023 is
30024 Constit_Elmt : Elmt_Id;
30025 Constit_Id : Entity_Id;
30026 State_Id : Entity_Id;
30027
30028 begin
30029 -- Nothing to do if there are no states or constituents
30030
30031 if No (States) or else No (Constits) then
30032 return;
30033 end if;
30034
30035 -- Inspect the list of constituents and try to determine whether its
30036 -- encapsulating state is in list States.
30037
30038 Constit_Elmt := First_Elmt (Constits);
30039 while Present (Constit_Elmt) loop
30040 Constit_Id := Node (Constit_Elmt);
30041
30042 -- Determine whether the constituent is part of an encapsulating
30043 -- state that appears in the same context and if this is the case,
30044 -- emit an error (SPARK RM 7.2.6(7)).
30045
30046 State_Id := Find_Encapsulating_State (States, Constit_Id);
30047
30048 if Present (State_Id) then
30049 Error_Msg_Name_1 := Chars (Constit_Id);
30050 SPARK_Msg_NE
30051 ("cannot mention state & and its constituent % in the same "
30052 & "context", Context, State_Id);
30053 exit;
30054 end if;
30055
30056 Next_Elmt (Constit_Elmt);
30057 end loop;
30058 end Check_State_And_Constituent_Use;
30059
30060 ---------------------------------------------
30061 -- Collect_Inherited_Class_Wide_Conditions --
30062 ---------------------------------------------
30063
30064 procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is
30065 Parent_Subp : constant Entity_Id :=
30066 Ultimate_Alias (Overridden_Operation (Subp));
30067 -- The Overridden_Operation may itself be inherited and as such have no
30068 -- explicit contract.
30069
30070 Prags : constant Node_Id := Contract (Parent_Subp);
30071 In_Spec_Expr : Boolean := In_Spec_Expression;
30072 Installed : Boolean;
30073 Prag : Node_Id;
30074 New_Prag : Node_Id;
30075
30076 begin
30077 Installed := False;
30078
30079 -- Iterate over the contract of the overridden subprogram to find all
30080 -- inherited class-wide pre- and postconditions.
30081
30082 if Present (Prags) then
30083 Prag := Pre_Post_Conditions (Prags);
30084
30085 while Present (Prag) loop
30086 if Nam_In (Pragma_Name_Unmapped (Prag),
30087 Name_Precondition, Name_Postcondition)
30088 and then Class_Present (Prag)
30089 then
30090 -- The generated pragma must be analyzed in the context of
30091 -- the subprogram, to make its formals visible. In addition,
30092 -- we must inhibit freezing and full analysis because the
30093 -- controlling type of the subprogram is not frozen yet, and
30094 -- may have further primitives.
30095
30096 if not Installed then
30097 Installed := True;
30098 Push_Scope (Subp);
30099 Install_Formals (Subp);
30100 In_Spec_Expr := In_Spec_Expression;
30101 In_Spec_Expression := True;
30102 end if;
30103
30104 New_Prag :=
30105 Build_Pragma_Check_Equivalent
30106 (Prag, Subp, Parent_Subp, Keep_Pragma_Id => True);
30107
30108 Insert_After (Unit_Declaration_Node (Subp), New_Prag);
30109 Preanalyze (New_Prag);
30110
30111 -- Prevent further analysis in subsequent processing of the
30112 -- current list of declarations
30113
30114 Set_Analyzed (New_Prag);
30115 end if;
30116
30117 Prag := Next_Pragma (Prag);
30118 end loop;
30119
30120 if Installed then
30121 In_Spec_Expression := In_Spec_Expr;
30122 End_Scope;
30123 end if;
30124 end if;
30125 end Collect_Inherited_Class_Wide_Conditions;
30126
30127 ---------------------------------------
30128 -- Collect_Subprogram_Inputs_Outputs --
30129 ---------------------------------------
30130
30131 procedure Collect_Subprogram_Inputs_Outputs
30132 (Subp_Id : Entity_Id;
30133 Synthesize : Boolean := False;
30134 Subp_Inputs : in out Elist_Id;
30135 Subp_Outputs : in out Elist_Id;
30136 Global_Seen : out Boolean)
30137 is
30138 procedure Collect_Dependency_Clause (Clause : Node_Id);
30139 -- Collect all relevant items from a dependency clause
30140
30141 procedure Collect_Global_List
30142 (List : Node_Id;
30143 Mode : Name_Id := Name_Input);
30144 -- Collect all relevant items from a global list
30145
30146 -------------------------------
30147 -- Collect_Dependency_Clause --
30148 -------------------------------
30149
30150 procedure Collect_Dependency_Clause (Clause : Node_Id) is
30151 procedure Collect_Dependency_Item
30152 (Item : Node_Id;
30153 Is_Input : Boolean);
30154 -- Add an item to the proper subprogram input or output collection
30155
30156 -----------------------------
30157 -- Collect_Dependency_Item --
30158 -----------------------------
30159
30160 procedure Collect_Dependency_Item
30161 (Item : Node_Id;
30162 Is_Input : Boolean)
30163 is
30164 Extra : Node_Id;
30165
30166 begin
30167 -- Nothing to collect when the item is null
30168
30169 if Nkind (Item) = N_Null then
30170 null;
30171
30172 -- Ditto for attribute 'Result
30173
30174 elsif Is_Attribute_Result (Item) then
30175 null;
30176
30177 -- Multiple items appear as an aggregate
30178
30179 elsif Nkind (Item) = N_Aggregate then
30180 Extra := First (Expressions (Item));
30181 while Present (Extra) loop
30182 Collect_Dependency_Item (Extra, Is_Input);
30183 Next (Extra);
30184 end loop;
30185
30186 -- Otherwise this is a solitary item
30187
30188 else
30189 if Is_Input then
30190 Append_New_Elmt (Item, Subp_Inputs);
30191 else
30192 Append_New_Elmt (Item, Subp_Outputs);
30193 end if;
30194 end if;
30195 end Collect_Dependency_Item;
30196
30197 -- Start of processing for Collect_Dependency_Clause
30198
30199 begin
30200 if Nkind (Clause) = N_Null then
30201 null;
30202
30203 -- A dependency clause appears as component association
30204
30205 elsif Nkind (Clause) = N_Component_Association then
30206 Collect_Dependency_Item
30207 (Item => Expression (Clause),
30208 Is_Input => True);
30209
30210 Collect_Dependency_Item
30211 (Item => First (Choices (Clause)),
30212 Is_Input => False);
30213
30214 -- To accommodate partial decoration of disabled SPARK features, this
30215 -- routine may be called with illegal input. If this is the case, do
30216 -- not raise Program_Error.
30217
30218 else
30219 null;
30220 end if;
30221 end Collect_Dependency_Clause;
30222
30223 -------------------------
30224 -- Collect_Global_List --
30225 -------------------------
30226
30227 procedure Collect_Global_List
30228 (List : Node_Id;
30229 Mode : Name_Id := Name_Input)
30230 is
30231 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
30232 -- Add an item to the proper subprogram input or output collection
30233
30234 -------------------------
30235 -- Collect_Global_Item --
30236 -------------------------
30237
30238 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
30239 begin
30240 if Nam_In (Mode, Name_In_Out, Name_Input) then
30241 Append_New_Elmt (Item, Subp_Inputs);
30242 end if;
30243
30244 if Nam_In (Mode, Name_In_Out, Name_Output) then
30245 Append_New_Elmt (Item, Subp_Outputs);
30246 end if;
30247 end Collect_Global_Item;
30248
30249 -- Local variables
30250
30251 Assoc : Node_Id;
30252 Item : Node_Id;
30253
30254 -- Start of processing for Collect_Global_List
30255
30256 begin
30257 if Nkind (List) = N_Null then
30258 null;
30259
30260 -- Single global item declaration
30261
30262 elsif Nkind_In (List, N_Expanded_Name,
30263 N_Identifier,
30264 N_Selected_Component)
30265 then
30266 Collect_Global_Item (List, Mode);
30267
30268 -- Simple global list or moded global list declaration
30269
30270 elsif Nkind (List) = N_Aggregate then
30271 if Present (Expressions (List)) then
30272 Item := First (Expressions (List));
30273 while Present (Item) loop
30274 Collect_Global_Item (Item, Mode);
30275 Next (Item);
30276 end loop;
30277
30278 else
30279 Assoc := First (Component_Associations (List));
30280 while Present (Assoc) loop
30281 Collect_Global_List
30282 (List => Expression (Assoc),
30283 Mode => Chars (First (Choices (Assoc))));
30284 Next (Assoc);
30285 end loop;
30286 end if;
30287
30288 -- To accommodate partial decoration of disabled SPARK features, this
30289 -- routine may be called with illegal input. If this is the case, do
30290 -- not raise Program_Error.
30291
30292 else
30293 null;
30294 end if;
30295 end Collect_Global_List;
30296
30297 -- Local variables
30298
30299 Clause : Node_Id;
30300 Clauses : Node_Id;
30301 Depends : Node_Id;
30302 Formal : Entity_Id;
30303 Global : Node_Id;
30304 Spec_Id : Entity_Id := Empty;
30305 Subp_Decl : Node_Id;
30306 Typ : Entity_Id;
30307
30308 -- Start of processing for Collect_Subprogram_Inputs_Outputs
30309
30310 begin
30311 Global_Seen := False;
30312
30313 -- Process all formal parameters of entries, [generic] subprograms, and
30314 -- their bodies.
30315
30316 if Ekind_In (Subp_Id, E_Entry,
30317 E_Entry_Family,
30318 E_Function,
30319 E_Generic_Function,
30320 E_Generic_Procedure,
30321 E_Procedure,
30322 E_Subprogram_Body)
30323 then
30324 Subp_Decl := Unit_Declaration_Node (Subp_Id);
30325 Spec_Id := Unique_Defining_Entity (Subp_Decl);
30326
30327 -- Process all formal parameters
30328
30329 Formal := First_Entity (Spec_Id);
30330 while Present (Formal) loop
30331 if Ekind_In (Formal, E_In_Out_Parameter, E_In_Parameter) then
30332 Append_New_Elmt (Formal, Subp_Inputs);
30333 end if;
30334
30335 if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
30336 Append_New_Elmt (Formal, Subp_Outputs);
30337
30338 -- Out parameters can act as inputs when the related type is
30339 -- tagged, unconstrained array, unconstrained record, or record
30340 -- with unconstrained components.
30341
30342 if Ekind (Formal) = E_Out_Parameter
30343 and then Is_Unconstrained_Or_Tagged_Item (Formal)
30344 then
30345 Append_New_Elmt (Formal, Subp_Inputs);
30346 end if;
30347 end if;
30348
30349 Next_Entity (Formal);
30350 end loop;
30351
30352 -- Otherwise the input denotes a task type, a task body, or the
30353 -- anonymous object created for a single task type.
30354
30355 elsif Ekind_In (Subp_Id, E_Task_Type, E_Task_Body)
30356 or else Is_Single_Task_Object (Subp_Id)
30357 then
30358 Subp_Decl := Declaration_Node (Subp_Id);
30359 Spec_Id := Unique_Defining_Entity (Subp_Decl);
30360 end if;
30361
30362 -- When processing an entry, subprogram or task body, look for pragmas
30363 -- Refined_Depends and Refined_Global as they specify the inputs and
30364 -- outputs.
30365
30366 if Is_Entry_Body (Subp_Id)
30367 or else Ekind_In (Subp_Id, E_Subprogram_Body, E_Task_Body)
30368 then
30369 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
30370 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
30371
30372 -- Subprogram declaration or stand-alone body case, look for pragmas
30373 -- Depends and Global
30374
30375 else
30376 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
30377 Global := Get_Pragma (Spec_Id, Pragma_Global);
30378 end if;
30379
30380 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
30381 -- because it provides finer granularity of inputs and outputs.
30382
30383 if Present (Global) then
30384 Global_Seen := True;
30385 Collect_Global_List (Expression (Get_Argument (Global, Spec_Id)));
30386
30387 -- When the related subprogram lacks pragma [Refined_]Global, fall back
30388 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
30389 -- the inputs and outputs from [Refined_]Depends.
30390
30391 elsif Synthesize and then Present (Depends) then
30392 Clauses := Expression (Get_Argument (Depends, Spec_Id));
30393
30394 -- Multiple dependency clauses appear as an aggregate
30395
30396 if Nkind (Clauses) = N_Aggregate then
30397 Clause := First (Component_Associations (Clauses));
30398 while Present (Clause) loop
30399 Collect_Dependency_Clause (Clause);
30400 Next (Clause);
30401 end loop;
30402
30403 -- Otherwise this is a single dependency clause
30404
30405 else
30406 Collect_Dependency_Clause (Clauses);
30407 end if;
30408 end if;
30409
30410 -- The current instance of a protected type acts as a formal parameter
30411 -- of mode IN for functions and IN OUT for entries and procedures
30412 -- (SPARK RM 6.1.4).
30413
30414 if Ekind (Scope (Spec_Id)) = E_Protected_Type then
30415 Typ := Scope (Spec_Id);
30416
30417 -- Use the anonymous object when the type is single protected
30418
30419 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
30420 Typ := Anonymous_Object (Typ);
30421 end if;
30422
30423 Append_New_Elmt (Typ, Subp_Inputs);
30424
30425 if Ekind_In (Spec_Id, E_Entry, E_Entry_Family, E_Procedure) then
30426 Append_New_Elmt (Typ, Subp_Outputs);
30427 end if;
30428
30429 -- The current instance of a task type acts as a formal parameter of
30430 -- mode IN OUT (SPARK RM 6.1.4).
30431
30432 elsif Ekind (Spec_Id) = E_Task_Type then
30433 Typ := Spec_Id;
30434
30435 -- Use the anonymous object when the type is single task
30436
30437 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
30438 Typ := Anonymous_Object (Typ);
30439 end if;
30440
30441 Append_New_Elmt (Typ, Subp_Inputs);
30442 Append_New_Elmt (Typ, Subp_Outputs);
30443
30444 elsif Is_Single_Task_Object (Spec_Id) then
30445 Append_New_Elmt (Spec_Id, Subp_Inputs);
30446 Append_New_Elmt (Spec_Id, Subp_Outputs);
30447 end if;
30448 end Collect_Subprogram_Inputs_Outputs;
30449
30450 ---------------------------
30451 -- Contract_Freeze_Error --
30452 ---------------------------
30453
30454 procedure Contract_Freeze_Error
30455 (Contract_Id : Entity_Id;
30456 Freeze_Id : Entity_Id)
30457 is
30458 begin
30459 Error_Msg_Name_1 := Chars (Contract_Id);
30460 Error_Msg_Sloc := Sloc (Freeze_Id);
30461
30462 SPARK_Msg_NE
30463 ("body & declared # freezes the contract of%", Contract_Id, Freeze_Id);
30464 SPARK_Msg_N
30465 ("\all contractual items must be declared before body #", Contract_Id);
30466 end Contract_Freeze_Error;
30467
30468 ---------------------------------
30469 -- Delay_Config_Pragma_Analyze --
30470 ---------------------------------
30471
30472 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
30473 begin
30474 return Nam_In (Pragma_Name_Unmapped (N),
30475 Name_Interrupt_State, Name_Priority_Specific_Dispatching);
30476 end Delay_Config_Pragma_Analyze;
30477
30478 -----------------------
30479 -- Duplication_Error --
30480 -----------------------
30481
30482 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
30483 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
30484 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
30485
30486 begin
30487 Error_Msg_Sloc := Sloc (Prev);
30488 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
30489
30490 -- Emit a precise message to distinguish between source pragmas and
30491 -- pragmas generated from aspects. The ordering of the two pragmas is
30492 -- the following:
30493
30494 -- Prev -- ok
30495 -- Prag -- duplicate
30496
30497 -- No error is emitted when both pragmas come from aspects because this
30498 -- is already detected by the general aspect analysis mechanism.
30499
30500 if Prag_From_Asp and Prev_From_Asp then
30501 null;
30502 elsif Prag_From_Asp then
30503 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
30504 elsif Prev_From_Asp then
30505 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
30506 else
30507 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
30508 end if;
30509 end Duplication_Error;
30510
30511 ------------------------------
30512 -- Find_Encapsulating_State --
30513 ------------------------------
30514
30515 function Find_Encapsulating_State
30516 (States : Elist_Id;
30517 Constit_Id : Entity_Id) return Entity_Id
30518 is
30519 State_Id : Entity_Id;
30520
30521 begin
30522 -- Since a constituent may be part of a larger constituent set, climb
30523 -- the encapsulating state chain looking for a state that appears in
30524 -- States.
30525
30526 State_Id := Encapsulating_State (Constit_Id);
30527 while Present (State_Id) loop
30528 if Contains (States, State_Id) then
30529 return State_Id;
30530 end if;
30531
30532 State_Id := Encapsulating_State (State_Id);
30533 end loop;
30534
30535 return Empty;
30536 end Find_Encapsulating_State;
30537
30538 --------------------------
30539 -- Find_Related_Context --
30540 --------------------------
30541
30542 function Find_Related_Context
30543 (Prag : Node_Id;
30544 Do_Checks : Boolean := False) return Node_Id
30545 is
30546 Stmt : Node_Id;
30547
30548 begin
30549 Stmt := Prev (Prag);
30550 while Present (Stmt) loop
30551
30552 -- Skip prior pragmas, but check for duplicates
30553
30554 if Nkind (Stmt) = N_Pragma then
30555 if Do_Checks
30556 and then Pragma_Name (Stmt) = Pragma_Name (Prag)
30557 then
30558 Duplication_Error
30559 (Prag => Prag,
30560 Prev => Stmt);
30561 end if;
30562
30563 -- Skip internally generated code
30564
30565 elsif not Comes_From_Source (Stmt) then
30566
30567 -- The anonymous object created for a single concurrent type is a
30568 -- suitable context.
30569
30570 if Nkind (Stmt) = N_Object_Declaration
30571 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
30572 then
30573 return Stmt;
30574 end if;
30575
30576 -- Return the current source construct
30577
30578 else
30579 return Stmt;
30580 end if;
30581
30582 Prev (Stmt);
30583 end loop;
30584
30585 return Empty;
30586 end Find_Related_Context;
30587
30588 --------------------------------------
30589 -- Find_Related_Declaration_Or_Body --
30590 --------------------------------------
30591
30592 function Find_Related_Declaration_Or_Body
30593 (Prag : Node_Id;
30594 Do_Checks : Boolean := False) return Node_Id
30595 is
30596 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
30597
30598 procedure Expression_Function_Error;
30599 -- Emit an error concerning pragma Prag that illegaly applies to an
30600 -- expression function.
30601
30602 -------------------------------
30603 -- Expression_Function_Error --
30604 -------------------------------
30605
30606 procedure Expression_Function_Error is
30607 begin
30608 Error_Msg_Name_1 := Prag_Nam;
30609
30610 -- Emit a precise message to distinguish between source pragmas and
30611 -- pragmas generated from aspects.
30612
30613 if From_Aspect_Specification (Prag) then
30614 Error_Msg_N
30615 ("aspect % cannot apply to a stand alone expression function",
30616 Prag);
30617 else
30618 Error_Msg_N
30619 ("pragma % cannot apply to a stand alone expression function",
30620 Prag);
30621 end if;
30622 end Expression_Function_Error;
30623
30624 -- Local variables
30625
30626 Context : constant Node_Id := Parent (Prag);
30627 Stmt : Node_Id;
30628
30629 Look_For_Body : constant Boolean :=
30630 Nam_In (Prag_Nam, Name_Refined_Depends,
30631 Name_Refined_Global,
30632 Name_Refined_Post,
30633 Name_Refined_State);
30634 -- Refinement pragmas must be associated with a subprogram body [stub]
30635
30636 -- Start of processing for Find_Related_Declaration_Or_Body
30637
30638 begin
30639 Stmt := Prev (Prag);
30640 while Present (Stmt) loop
30641
30642 -- Skip prior pragmas, but check for duplicates. Pragmas produced
30643 -- by splitting a complex pre/postcondition are not considered to
30644 -- be duplicates.
30645
30646 if Nkind (Stmt) = N_Pragma then
30647 if Do_Checks
30648 and then not Split_PPC (Stmt)
30649 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
30650 then
30651 Duplication_Error
30652 (Prag => Prag,
30653 Prev => Stmt);
30654 end if;
30655
30656 -- Emit an error when a refinement pragma appears on an expression
30657 -- function without a completion.
30658
30659 elsif Do_Checks
30660 and then Look_For_Body
30661 and then Nkind (Stmt) = N_Subprogram_Declaration
30662 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
30663 and then not Has_Completion (Defining_Entity (Stmt))
30664 then
30665 Expression_Function_Error;
30666 return Empty;
30667
30668 -- The refinement pragma applies to a subprogram body stub
30669
30670 elsif Look_For_Body
30671 and then Nkind (Stmt) = N_Subprogram_Body_Stub
30672 then
30673 return Stmt;
30674
30675 -- Skip internally generated code
30676
30677 elsif not Comes_From_Source (Stmt) then
30678
30679 -- The anonymous object created for a single concurrent type is a
30680 -- suitable context.
30681
30682 if Nkind (Stmt) = N_Object_Declaration
30683 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
30684 then
30685 return Stmt;
30686
30687 elsif Nkind (Stmt) = N_Subprogram_Declaration then
30688
30689 -- The subprogram declaration is an internally generated spec
30690 -- for an expression function.
30691
30692 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
30693 return Stmt;
30694
30695 -- The subprogram declaration is an internally generated spec
30696 -- for a stand-alone subrogram body declared inside a protected
30697 -- body.
30698
30699 elsif Present (Corresponding_Body (Stmt))
30700 and then Comes_From_Source (Corresponding_Body (Stmt))
30701 and then Is_Protected_Type (Current_Scope)
30702 then
30703 return Stmt;
30704
30705 -- The subprogram is actually an instance housed within an
30706 -- anonymous wrapper package.
30707
30708 elsif Present (Generic_Parent (Specification (Stmt))) then
30709 return Stmt;
30710 end if;
30711 end if;
30712
30713 -- Return the current construct which is either a subprogram body,
30714 -- a subprogram declaration or is illegal.
30715
30716 else
30717 return Stmt;
30718 end if;
30719
30720 Prev (Stmt);
30721 end loop;
30722
30723 -- If we fall through, then the pragma was either the first declaration
30724 -- or it was preceded by other pragmas and no source constructs.
30725
30726 -- The pragma is associated with a library-level subprogram
30727
30728 if Nkind (Context) = N_Compilation_Unit_Aux then
30729 return Unit (Parent (Context));
30730
30731 -- The pragma appears inside the declarations of an entry body
30732
30733 elsif Nkind (Context) = N_Entry_Body then
30734 return Context;
30735
30736 -- The pragma appears inside the statements of a subprogram body. This
30737 -- placement is the result of subprogram contract expansion.
30738
30739 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
30740 return Parent (Context);
30741
30742 -- The pragma appears inside the declarative part of a package body
30743
30744 elsif Nkind (Context) = N_Package_Body then
30745 return Context;
30746
30747 -- The pragma appears inside the declarative part of a subprogram body
30748
30749 elsif Nkind (Context) = N_Subprogram_Body then
30750 return Context;
30751
30752 -- The pragma appears inside the declarative part of a task body
30753
30754 elsif Nkind (Context) = N_Task_Body then
30755 return Context;
30756
30757 -- The pragma appears inside the visible part of a package specification
30758
30759 elsif Nkind (Context) = N_Package_Specification then
30760 return Parent (Context);
30761
30762 -- The pragma is a byproduct of aspect expansion, return the related
30763 -- context of the original aspect. This case has a lower priority as
30764 -- the above circuitry pinpoints precisely the related context.
30765
30766 elsif Present (Corresponding_Aspect (Prag)) then
30767 return Parent (Corresponding_Aspect (Prag));
30768
30769 -- No candidate subprogram [body] found
30770
30771 else
30772 return Empty;
30773 end if;
30774 end Find_Related_Declaration_Or_Body;
30775
30776 ----------------------------------
30777 -- Find_Related_Package_Or_Body --
30778 ----------------------------------
30779
30780 function Find_Related_Package_Or_Body
30781 (Prag : Node_Id;
30782 Do_Checks : Boolean := False) return Node_Id
30783 is
30784 Context : constant Node_Id := Parent (Prag);
30785 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
30786 Stmt : Node_Id;
30787
30788 begin
30789 Stmt := Prev (Prag);
30790 while Present (Stmt) loop
30791
30792 -- Skip prior pragmas, but check for duplicates
30793
30794 if Nkind (Stmt) = N_Pragma then
30795 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
30796 Duplication_Error
30797 (Prag => Prag,
30798 Prev => Stmt);
30799 end if;
30800
30801 -- Skip internally generated code
30802
30803 elsif not Comes_From_Source (Stmt) then
30804 if Nkind (Stmt) = N_Subprogram_Declaration then
30805
30806 -- The subprogram declaration is an internally generated spec
30807 -- for an expression function.
30808
30809 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
30810 return Stmt;
30811
30812 -- The subprogram is actually an instance housed within an
30813 -- anonymous wrapper package.
30814
30815 elsif Present (Generic_Parent (Specification (Stmt))) then
30816 return Stmt;
30817 end if;
30818 end if;
30819
30820 -- Return the current source construct which is illegal
30821
30822 else
30823 return Stmt;
30824 end if;
30825
30826 Prev (Stmt);
30827 end loop;
30828
30829 -- If we fall through, then the pragma was either the first declaration
30830 -- or it was preceded by other pragmas and no source constructs.
30831
30832 -- The pragma is associated with a package. The immediate context in
30833 -- this case is the specification of the package.
30834
30835 if Nkind (Context) = N_Package_Specification then
30836 return Parent (Context);
30837
30838 -- The pragma appears in the declarations of a package body
30839
30840 elsif Nkind (Context) = N_Package_Body then
30841 return Context;
30842
30843 -- The pragma appears in the statements of a package body
30844
30845 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
30846 and then Nkind (Parent (Context)) = N_Package_Body
30847 then
30848 return Parent (Context);
30849
30850 -- The pragma is a byproduct of aspect expansion, return the related
30851 -- context of the original aspect. This case has a lower priority as
30852 -- the above circuitry pinpoints precisely the related context.
30853
30854 elsif Present (Corresponding_Aspect (Prag)) then
30855 return Parent (Corresponding_Aspect (Prag));
30856
30857 -- No candidate package [body] found
30858
30859 else
30860 return Empty;
30861 end if;
30862 end Find_Related_Package_Or_Body;
30863
30864 ------------------
30865 -- Get_Argument --
30866 ------------------
30867
30868 function Get_Argument
30869 (Prag : Node_Id;
30870 Context_Id : Entity_Id := Empty) return Node_Id
30871 is
30872 Args : constant List_Id := Pragma_Argument_Associations (Prag);
30873
30874 begin
30875 -- Use the expression of the original aspect when analyzing the template
30876 -- of a generic unit. In both cases the aspect's tree must be decorated
30877 -- to allow for ASIS queries or to save the global references in the
30878 -- generic context.
30879
30880 if From_Aspect_Specification (Prag)
30881 and then (Present (Context_Id) and then Is_Generic_Unit (Context_Id))
30882 then
30883 return Corresponding_Aspect (Prag);
30884
30885 -- Otherwise use the expression of the pragma
30886
30887 elsif Present (Args) then
30888 return First (Args);
30889
30890 else
30891 return Empty;
30892 end if;
30893 end Get_Argument;
30894
30895 -------------------------
30896 -- Get_Base_Subprogram --
30897 -------------------------
30898
30899 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
30900 begin
30901 -- Follow subprogram renaming chain
30902
30903 if Is_Subprogram (Def_Id)
30904 and then Nkind (Parent (Declaration_Node (Def_Id))) =
30905 N_Subprogram_Renaming_Declaration
30906 and then Present (Alias (Def_Id))
30907 then
30908 return Alias (Def_Id);
30909 else
30910 return Def_Id;
30911 end if;
30912 end Get_Base_Subprogram;
30913
30914 -----------------------
30915 -- Get_SPARK_Mode_Type --
30916 -----------------------
30917
30918 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
30919 begin
30920 if N = Name_On then
30921 return On;
30922 elsif N = Name_Off then
30923 return Off;
30924
30925 -- Any other argument is illegal. Assume that no SPARK mode applies to
30926 -- avoid potential cascaded errors.
30927
30928 else
30929 return None;
30930 end if;
30931 end Get_SPARK_Mode_Type;
30932
30933 ------------------------------------
30934 -- Get_SPARK_Mode_From_Annotation --
30935 ------------------------------------
30936
30937 function Get_SPARK_Mode_From_Annotation
30938 (N : Node_Id) return SPARK_Mode_Type
30939 is
30940 Mode : Node_Id;
30941
30942 begin
30943 if Nkind (N) = N_Aspect_Specification then
30944 Mode := Expression (N);
30945
30946 else pragma Assert (Nkind (N) = N_Pragma);
30947 Mode := First (Pragma_Argument_Associations (N));
30948
30949 if Present (Mode) then
30950 Mode := Get_Pragma_Arg (Mode);
30951 end if;
30952 end if;
30953
30954 -- Aspect or pragma SPARK_Mode specifies an explicit mode
30955
30956 if Present (Mode) then
30957 if Nkind (Mode) = N_Identifier then
30958 return Get_SPARK_Mode_Type (Chars (Mode));
30959
30960 -- In case of a malformed aspect or pragma, return the default None
30961
30962 else
30963 return None;
30964 end if;
30965
30966 -- Otherwise the lack of an expression defaults SPARK_Mode to On
30967
30968 else
30969 return On;
30970 end if;
30971 end Get_SPARK_Mode_From_Annotation;
30972
30973 ---------------------------
30974 -- Has_Extra_Parentheses --
30975 ---------------------------
30976
30977 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
30978 Expr : Node_Id;
30979
30980 begin
30981 -- The aggregate should not have an expression list because a clause
30982 -- is always interpreted as a component association. The only way an
30983 -- expression list can sneak in is by adding extra parentheses around
30984 -- the individual clauses:
30985
30986 -- Depends (Output => Input) -- proper form
30987 -- Depends ((Output => Input)) -- extra parentheses
30988
30989 -- Since the extra parentheses are not allowed by the syntax of the
30990 -- pragma, flag them now to avoid emitting misleading errors down the
30991 -- line.
30992
30993 if Nkind (Clause) = N_Aggregate
30994 and then Present (Expressions (Clause))
30995 then
30996 Expr := First (Expressions (Clause));
30997 while Present (Expr) loop
30998
30999 -- A dependency clause surrounded by extra parentheses appears
31000 -- as an aggregate of component associations with an optional
31001 -- Paren_Count set.
31002
31003 if Nkind (Expr) = N_Aggregate
31004 and then Present (Component_Associations (Expr))
31005 then
31006 SPARK_Msg_N
31007 ("dependency clause contains extra parentheses", Expr);
31008
31009 -- Otherwise the expression is a malformed construct
31010
31011 else
31012 SPARK_Msg_N ("malformed dependency clause", Expr);
31013 end if;
31014
31015 Next (Expr);
31016 end loop;
31017
31018 return True;
31019 end if;
31020
31021 return False;
31022 end Has_Extra_Parentheses;
31023
31024 ----------------
31025 -- Initialize --
31026 ----------------
31027
31028 procedure Initialize is
31029 begin
31030 Externals.Init;
31031 Compile_Time_Warnings_Errors.Init;
31032 end Initialize;
31033
31034 --------
31035 -- ip --
31036 --------
31037
31038 procedure ip is
31039 begin
31040 Dummy := Dummy + 1;
31041 end ip;
31042
31043 -----------------------------
31044 -- Is_Config_Static_String --
31045 -----------------------------
31046
31047 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
31048
31049 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
31050 -- This is an internal recursive function that is just like the outer
31051 -- function except that it adds the string to the name buffer rather
31052 -- than placing the string in the name buffer.
31053
31054 ------------------------------
31055 -- Add_Config_Static_String --
31056 ------------------------------
31057
31058 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
31059 N : Node_Id;
31060 C : Char_Code;
31061
31062 begin
31063 N := Arg;
31064
31065 if Nkind (N) = N_Op_Concat then
31066 if Add_Config_Static_String (Left_Opnd (N)) then
31067 N := Right_Opnd (N);
31068 else
31069 return False;
31070 end if;
31071 end if;
31072
31073 if Nkind (N) /= N_String_Literal then
31074 Error_Msg_N ("string literal expected for pragma argument", N);
31075 return False;
31076
31077 else
31078 for J in 1 .. String_Length (Strval (N)) loop
31079 C := Get_String_Char (Strval (N), J);
31080
31081 if not In_Character_Range (C) then
31082 Error_Msg
31083 ("string literal contains invalid wide character",
31084 Sloc (N) + 1 + Source_Ptr (J));
31085 return False;
31086 end if;
31087
31088 Add_Char_To_Name_Buffer (Get_Character (C));
31089 end loop;
31090 end if;
31091
31092 return True;
31093 end Add_Config_Static_String;
31094
31095 -- Start of processing for Is_Config_Static_String
31096
31097 begin
31098 Name_Len := 0;
31099
31100 return Add_Config_Static_String (Arg);
31101 end Is_Config_Static_String;
31102
31103 -------------------------------
31104 -- Is_Elaboration_SPARK_Mode --
31105 -------------------------------
31106
31107 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
31108 begin
31109 pragma Assert
31110 (Nkind (N) = N_Pragma
31111 and then Pragma_Name (N) = Name_SPARK_Mode
31112 and then Is_List_Member (N));
31113
31114 -- Pragma SPARK_Mode affects the elaboration of a package body when it
31115 -- appears in the statement part of the body.
31116
31117 return
31118 Present (Parent (N))
31119 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
31120 and then List_Containing (N) = Statements (Parent (N))
31121 and then Present (Parent (Parent (N)))
31122 and then Nkind (Parent (Parent (N))) = N_Package_Body;
31123 end Is_Elaboration_SPARK_Mode;
31124
31125 -----------------------
31126 -- Is_Enabled_Pragma --
31127 -----------------------
31128
31129 function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is
31130 Arg : Node_Id;
31131
31132 begin
31133 if Present (Prag) then
31134 Arg := First (Pragma_Argument_Associations (Prag));
31135
31136 if Present (Arg) then
31137 return Is_True (Expr_Value (Get_Pragma_Arg (Arg)));
31138
31139 -- The lack of a Boolean argument automatically enables the pragma
31140
31141 else
31142 return True;
31143 end if;
31144
31145 -- The pragma is missing, therefore it is not enabled
31146
31147 else
31148 return False;
31149 end if;
31150 end Is_Enabled_Pragma;
31151
31152 -----------------------------------------
31153 -- Is_Non_Significant_Pragma_Reference --
31154 -----------------------------------------
31155
31156 -- This function makes use of the following static table which indicates
31157 -- whether appearance of some name in a given pragma is to be considered
31158 -- as a reference for the purposes of warnings about unreferenced objects.
31159
31160 -- -1 indicates that appearence in any argument is significant
31161 -- 0 indicates that appearance in any argument is not significant
31162 -- +n indicates that appearance as argument n is significant, but all
31163 -- other arguments are not significant
31164 -- 9n arguments from n on are significant, before n insignificant
31165
31166 Sig_Flags : constant array (Pragma_Id) of Int :=
31167 (Pragma_Abort_Defer => -1,
31168 Pragma_Abstract_State => -1,
31169 Pragma_Acc_Data => 0,
31170 Pragma_Acc_Kernels => 0,
31171 Pragma_Acc_Loop => 0,
31172 Pragma_Acc_Parallel => 0,
31173 Pragma_Ada_83 => -1,
31174 Pragma_Ada_95 => -1,
31175 Pragma_Ada_05 => -1,
31176 Pragma_Ada_2005 => -1,
31177 Pragma_Ada_12 => -1,
31178 Pragma_Ada_2012 => -1,
31179 Pragma_Ada_2020 => -1,
31180 Pragma_Aggregate_Individually_Assign => 0,
31181 Pragma_All_Calls_Remote => -1,
31182 Pragma_Allow_Integer_Address => -1,
31183 Pragma_Annotate => 93,
31184 Pragma_Assert => -1,
31185 Pragma_Assert_And_Cut => -1,
31186 Pragma_Assertion_Policy => 0,
31187 Pragma_Assume => -1,
31188 Pragma_Assume_No_Invalid_Values => 0,
31189 Pragma_Async_Readers => 0,
31190 Pragma_Async_Writers => 0,
31191 Pragma_Asynchronous => 0,
31192 Pragma_Atomic => 0,
31193 Pragma_Atomic_Components => 0,
31194 Pragma_Attach_Handler => -1,
31195 Pragma_Attribute_Definition => 92,
31196 Pragma_Check => -1,
31197 Pragma_Check_Float_Overflow => 0,
31198 Pragma_Check_Name => 0,
31199 Pragma_Check_Policy => 0,
31200 Pragma_CPP_Class => 0,
31201 Pragma_CPP_Constructor => 0,
31202 Pragma_CPP_Virtual => 0,
31203 Pragma_CPP_Vtable => 0,
31204 Pragma_CPU => -1,
31205 Pragma_C_Pass_By_Copy => 0,
31206 Pragma_Comment => -1,
31207 Pragma_Common_Object => 0,
31208 Pragma_Compile_Time_Error => -1,
31209 Pragma_Compile_Time_Warning => -1,
31210 Pragma_Compiler_Unit => -1,
31211 Pragma_Compiler_Unit_Warning => -1,
31212 Pragma_Complete_Representation => 0,
31213 Pragma_Complex_Representation => 0,
31214 Pragma_Component_Alignment => 0,
31215 Pragma_Constant_After_Elaboration => 0,
31216 Pragma_Contract_Cases => -1,
31217 Pragma_Controlled => 0,
31218 Pragma_Convention => 0,
31219 Pragma_Convention_Identifier => 0,
31220 Pragma_Deadline_Floor => -1,
31221 Pragma_Debug => -1,
31222 Pragma_Debug_Policy => 0,
31223 Pragma_Detect_Blocking => 0,
31224 Pragma_Default_Initial_Condition => -1,
31225 Pragma_Default_Scalar_Storage_Order => 0,
31226 Pragma_Default_Storage_Pool => 0,
31227 Pragma_Depends => -1,
31228 Pragma_Disable_Atomic_Synchronization => 0,
31229 Pragma_Discard_Names => 0,
31230 Pragma_Dispatching_Domain => -1,
31231 Pragma_Effective_Reads => 0,
31232 Pragma_Effective_Writes => 0,
31233 Pragma_Elaborate => 0,
31234 Pragma_Elaborate_All => 0,
31235 Pragma_Elaborate_Body => 0,
31236 Pragma_Elaboration_Checks => 0,
31237 Pragma_Eliminate => 0,
31238 Pragma_Enable_Atomic_Synchronization => 0,
31239 Pragma_Export => -1,
31240 Pragma_Export_Function => -1,
31241 Pragma_Export_Object => -1,
31242 Pragma_Export_Procedure => -1,
31243 Pragma_Export_Value => -1,
31244 Pragma_Export_Valued_Procedure => -1,
31245 Pragma_Extend_System => -1,
31246 Pragma_Extensions_Allowed => 0,
31247 Pragma_Extensions_Visible => 0,
31248 Pragma_External => -1,
31249 Pragma_Favor_Top_Level => 0,
31250 Pragma_External_Name_Casing => 0,
31251 Pragma_Fast_Math => 0,
31252 Pragma_Finalize_Storage_Only => 0,
31253 Pragma_Ghost => 0,
31254 Pragma_Global => -1,
31255 Pragma_Ident => -1,
31256 Pragma_Ignore_Pragma => 0,
31257 Pragma_Implementation_Defined => -1,
31258 Pragma_Implemented => -1,
31259 Pragma_Implicit_Packing => 0,
31260 Pragma_Import => 93,
31261 Pragma_Import_Function => 0,
31262 Pragma_Import_Object => 0,
31263 Pragma_Import_Procedure => 0,
31264 Pragma_Import_Valued_Procedure => 0,
31265 Pragma_Independent => 0,
31266 Pragma_Independent_Components => 0,
31267 Pragma_Initial_Condition => -1,
31268 Pragma_Initialize_Scalars => 0,
31269 Pragma_Initializes => -1,
31270 Pragma_Inline => 0,
31271 Pragma_Inline_Always => 0,
31272 Pragma_Inline_Generic => 0,
31273 Pragma_Inspection_Point => -1,
31274 Pragma_Interface => 92,
31275 Pragma_Interface_Name => 0,
31276 Pragma_Interrupt_Handler => -1,
31277 Pragma_Interrupt_Priority => -1,
31278 Pragma_Interrupt_State => -1,
31279 Pragma_Invariant => -1,
31280 Pragma_Keep_Names => 0,
31281 Pragma_License => 0,
31282 Pragma_Link_With => -1,
31283 Pragma_Linker_Alias => -1,
31284 Pragma_Linker_Constructor => -1,
31285 Pragma_Linker_Destructor => -1,
31286 Pragma_Linker_Options => -1,
31287 Pragma_Linker_Section => -1,
31288 Pragma_List => 0,
31289 Pragma_Lock_Free => 0,
31290 Pragma_Locking_Policy => 0,
31291 Pragma_Loop_Invariant => -1,
31292 Pragma_Loop_Optimize => 0,
31293 Pragma_Loop_Variant => -1,
31294 Pragma_Machine_Attribute => -1,
31295 Pragma_Main => -1,
31296 Pragma_Main_Storage => -1,
31297 Pragma_Max_Entry_Queue_Depth => 0,
31298 Pragma_Max_Entry_Queue_Length => 0,
31299 Pragma_Max_Queue_Length => 0,
31300 Pragma_Memory_Size => 0,
31301 Pragma_No_Body => 0,
31302 Pragma_No_Caching => 0,
31303 Pragma_No_Component_Reordering => -1,
31304 Pragma_No_Elaboration_Code_All => 0,
31305 Pragma_No_Heap_Finalization => 0,
31306 Pragma_No_Inline => 0,
31307 Pragma_No_Return => 0,
31308 Pragma_No_Run_Time => -1,
31309 Pragma_No_Strict_Aliasing => -1,
31310 Pragma_No_Tagged_Streams => 0,
31311 Pragma_Normalize_Scalars => 0,
31312 Pragma_Obsolescent => 0,
31313 Pragma_Optimize => 0,
31314 Pragma_Optimize_Alignment => 0,
31315 Pragma_Overflow_Mode => 0,
31316 Pragma_Overriding_Renamings => 0,
31317 Pragma_Ordered => 0,
31318 Pragma_Pack => 0,
31319 Pragma_Page => 0,
31320 Pragma_Part_Of => 0,
31321 Pragma_Partition_Elaboration_Policy => 0,
31322 Pragma_Passive => 0,
31323 Pragma_Persistent_BSS => 0,
31324 Pragma_Polling => 0,
31325 Pragma_Prefix_Exception_Messages => 0,
31326 Pragma_Post => -1,
31327 Pragma_Postcondition => -1,
31328 Pragma_Post_Class => -1,
31329 Pragma_Pre => -1,
31330 Pragma_Precondition => -1,
31331 Pragma_Predicate => -1,
31332 Pragma_Predicate_Failure => -1,
31333 Pragma_Preelaborable_Initialization => -1,
31334 Pragma_Preelaborate => 0,
31335 Pragma_Pre_Class => -1,
31336 Pragma_Priority => -1,
31337 Pragma_Priority_Specific_Dispatching => 0,
31338 Pragma_Profile => 0,
31339 Pragma_Profile_Warnings => 0,
31340 Pragma_Propagate_Exceptions => 0,
31341 Pragma_Provide_Shift_Operators => 0,
31342 Pragma_Psect_Object => 0,
31343 Pragma_Pure => 0,
31344 Pragma_Pure_Function => 0,
31345 Pragma_Queuing_Policy => 0,
31346 Pragma_Rational => 0,
31347 Pragma_Ravenscar => 0,
31348 Pragma_Refined_Depends => -1,
31349 Pragma_Refined_Global => -1,
31350 Pragma_Refined_Post => -1,
31351 Pragma_Refined_State => -1,
31352 Pragma_Relative_Deadline => 0,
31353 Pragma_Rename_Pragma => 0,
31354 Pragma_Remote_Access_Type => -1,
31355 Pragma_Remote_Call_Interface => -1,
31356 Pragma_Remote_Types => -1,
31357 Pragma_Restricted_Run_Time => 0,
31358 Pragma_Restriction_Warnings => 0,
31359 Pragma_Restrictions => 0,
31360 Pragma_Reviewable => -1,
31361 Pragma_Secondary_Stack_Size => -1,
31362 Pragma_Short_Circuit_And_Or => 0,
31363 Pragma_Share_Generic => 0,
31364 Pragma_Shared => 0,
31365 Pragma_Shared_Passive => 0,
31366 Pragma_Short_Descriptors => 0,
31367 Pragma_Simple_Storage_Pool_Type => 0,
31368 Pragma_Source_File_Name => 0,
31369 Pragma_Source_File_Name_Project => 0,
31370 Pragma_Source_Reference => 0,
31371 Pragma_SPARK_Mode => 0,
31372 Pragma_Storage_Size => -1,
31373 Pragma_Storage_Unit => 0,
31374 Pragma_Static_Elaboration_Desired => 0,
31375 Pragma_Stream_Convert => 0,
31376 Pragma_Style_Checks => 0,
31377 Pragma_Subtitle => 0,
31378 Pragma_Suppress => 0,
31379 Pragma_Suppress_Exception_Locations => 0,
31380 Pragma_Suppress_All => 0,
31381 Pragma_Suppress_Debug_Info => 0,
31382 Pragma_Suppress_Initialization => 0,
31383 Pragma_System_Name => 0,
31384 Pragma_Task_Dispatching_Policy => 0,
31385 Pragma_Task_Info => -1,
31386 Pragma_Task_Name => -1,
31387 Pragma_Task_Storage => -1,
31388 Pragma_Test_Case => -1,
31389 Pragma_Thread_Local_Storage => -1,
31390 Pragma_Time_Slice => -1,
31391 Pragma_Title => 0,
31392 Pragma_Type_Invariant => -1,
31393 Pragma_Type_Invariant_Class => -1,
31394 Pragma_Unchecked_Union => 0,
31395 Pragma_Unevaluated_Use_Of_Old => 0,
31396 Pragma_Unimplemented_Unit => 0,
31397 Pragma_Universal_Aliasing => 0,
31398 Pragma_Universal_Data => 0,
31399 Pragma_Unmodified => 0,
31400 Pragma_Unreferenced => 0,
31401 Pragma_Unreferenced_Objects => 0,
31402 Pragma_Unreserve_All_Interrupts => 0,
31403 Pragma_Unsuppress => 0,
31404 Pragma_Unused => 0,
31405 Pragma_Use_VADS_Size => 0,
31406 Pragma_Validity_Checks => 0,
31407 Pragma_Volatile => 0,
31408 Pragma_Volatile_Components => 0,
31409 Pragma_Volatile_Full_Access => 0,
31410 Pragma_Volatile_Function => 0,
31411 Pragma_Warning_As_Error => 0,
31412 Pragma_Warnings => 0,
31413 Pragma_Weak_External => 0,
31414 Pragma_Wide_Character_Encoding => 0,
31415 Unknown_Pragma => 0);
31416
31417 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
31418 Id : Pragma_Id;
31419 P : Node_Id;
31420 C : Int;
31421 AN : Nat;
31422
31423 function Arg_No return Nat;
31424 -- Returns an integer showing what argument we are in. A value of
31425 -- zero means we are not in any of the arguments.
31426
31427 ------------
31428 -- Arg_No --
31429 ------------
31430
31431 function Arg_No return Nat is
31432 A : Node_Id;
31433 N : Nat;
31434
31435 begin
31436 A := First (Pragma_Argument_Associations (Parent (P)));
31437 N := 1;
31438 loop
31439 if No (A) then
31440 return 0;
31441 elsif A = P then
31442 return N;
31443 end if;
31444
31445 Next (A);
31446 N := N + 1;
31447 end loop;
31448 end Arg_No;
31449
31450 -- Start of processing for Non_Significant_Pragma_Reference
31451
31452 begin
31453 P := Parent (N);
31454
31455 if Nkind (P) /= N_Pragma_Argument_Association then
31456 return False;
31457
31458 else
31459 Id := Get_Pragma_Id (Parent (P));
31460 C := Sig_Flags (Id);
31461 AN := Arg_No;
31462
31463 if AN = 0 then
31464 return False;
31465 end if;
31466
31467 case C is
31468 when -1 =>
31469 return False;
31470
31471 when 0 =>
31472 return True;
31473
31474 when 92 .. 99 =>
31475 return AN < (C - 90);
31476
31477 when others =>
31478 return AN /= C;
31479 end case;
31480 end if;
31481 end Is_Non_Significant_Pragma_Reference;
31482
31483 ------------------------------
31484 -- Is_Pragma_String_Literal --
31485 ------------------------------
31486
31487 -- This function returns true if the corresponding pragma argument is a
31488 -- static string expression. These are the only cases in which string
31489 -- literals can appear as pragma arguments. We also allow a string literal
31490 -- as the first argument to pragma Assert (although it will of course
31491 -- always generate a type error).
31492
31493 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
31494 Pragn : constant Node_Id := Parent (Par);
31495 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
31496 Pname : constant Name_Id := Pragma_Name (Pragn);
31497 Argn : Natural;
31498 N : Node_Id;
31499
31500 begin
31501 Argn := 1;
31502 N := First (Assoc);
31503 loop
31504 exit when N = Par;
31505 Argn := Argn + 1;
31506 Next (N);
31507 end loop;
31508
31509 if Pname = Name_Assert then
31510 return True;
31511
31512 elsif Pname = Name_Export then
31513 return Argn > 2;
31514
31515 elsif Pname = Name_Ident then
31516 return Argn = 1;
31517
31518 elsif Pname = Name_Import then
31519 return Argn > 2;
31520
31521 elsif Pname = Name_Interface_Name then
31522 return Argn > 1;
31523
31524 elsif Pname = Name_Linker_Alias then
31525 return Argn = 2;
31526
31527 elsif Pname = Name_Linker_Section then
31528 return Argn = 2;
31529
31530 elsif Pname = Name_Machine_Attribute then
31531 return Argn = 2;
31532
31533 elsif Pname = Name_Source_File_Name then
31534 return True;
31535
31536 elsif Pname = Name_Source_Reference then
31537 return Argn = 2;
31538
31539 elsif Pname = Name_Title then
31540 return True;
31541
31542 elsif Pname = Name_Subtitle then
31543 return True;
31544
31545 else
31546 return False;
31547 end if;
31548 end Is_Pragma_String_Literal;
31549
31550 ---------------------------
31551 -- Is_Private_SPARK_Mode --
31552 ---------------------------
31553
31554 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
31555 begin
31556 pragma Assert
31557 (Nkind (N) = N_Pragma
31558 and then Pragma_Name (N) = Name_SPARK_Mode
31559 and then Is_List_Member (N));
31560
31561 -- For pragma SPARK_Mode to be private, it has to appear in the private
31562 -- declarations of a package.
31563
31564 return
31565 Present (Parent (N))
31566 and then Nkind (Parent (N)) = N_Package_Specification
31567 and then List_Containing (N) = Private_Declarations (Parent (N));
31568 end Is_Private_SPARK_Mode;
31569
31570 -------------------------------------
31571 -- Is_Unconstrained_Or_Tagged_Item --
31572 -------------------------------------
31573
31574 function Is_Unconstrained_Or_Tagged_Item
31575 (Item : Entity_Id) return Boolean
31576 is
31577 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
31578 -- Determine whether record type Typ has at least one unconstrained
31579 -- component.
31580
31581 ---------------------------------
31582 -- Has_Unconstrained_Component --
31583 ---------------------------------
31584
31585 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
31586 Comp : Entity_Id;
31587
31588 begin
31589 Comp := First_Component (Typ);
31590 while Present (Comp) loop
31591 if Is_Unconstrained_Or_Tagged_Item (Comp) then
31592 return True;
31593 end if;
31594
31595 Next_Component (Comp);
31596 end loop;
31597
31598 return False;
31599 end Has_Unconstrained_Component;
31600
31601 -- Local variables
31602
31603 Typ : constant Entity_Id := Etype (Item);
31604
31605 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
31606
31607 begin
31608 if Is_Tagged_Type (Typ) then
31609 return True;
31610
31611 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
31612 return True;
31613
31614 elsif Is_Record_Type (Typ) then
31615 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
31616 return True;
31617 else
31618 return Has_Unconstrained_Component (Typ);
31619 end if;
31620
31621 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
31622 return True;
31623
31624 else
31625 return False;
31626 end if;
31627 end Is_Unconstrained_Or_Tagged_Item;
31628
31629 -----------------------------
31630 -- Is_Valid_Assertion_Kind --
31631 -----------------------------
31632
31633 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
31634 begin
31635 case Nam is
31636 when
31637 -- RM defined
31638
31639 Name_Assert
31640 | Name_Assertion_Policy
31641 | Name_Static_Predicate
31642 | Name_Dynamic_Predicate
31643 | Name_Pre
31644 | Name_uPre
31645 | Name_Post
31646 | Name_uPost
31647 | Name_Type_Invariant
31648 | Name_uType_Invariant
31649
31650 -- Impl defined
31651
31652 | Name_Assert_And_Cut
31653 | Name_Assume
31654 | Name_Contract_Cases
31655 | Name_Debug
31656 | Name_Default_Initial_Condition
31657 | Name_Ghost
31658 | Name_Initial_Condition
31659 | Name_Invariant
31660 | Name_uInvariant
31661 | Name_Loop_Invariant
31662 | Name_Loop_Variant
31663 | Name_Postcondition
31664 | Name_Precondition
31665 | Name_Predicate
31666 | Name_Refined_Post
31667 | Name_Statement_Assertions
31668 =>
31669 return True;
31670
31671 when others =>
31672 return False;
31673 end case;
31674 end Is_Valid_Assertion_Kind;
31675
31676 --------------------------------------
31677 -- Process_Compilation_Unit_Pragmas --
31678 --------------------------------------
31679
31680 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
31681 begin
31682 -- A special check for pragma Suppress_All, a very strange DEC pragma,
31683 -- strange because it comes at the end of the unit. Rational has the
31684 -- same name for a pragma, but treats it as a program unit pragma, In
31685 -- GNAT we just decide to allow it anywhere at all. If it appeared then
31686 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
31687 -- node, and we insert a pragma Suppress (All_Checks) at the start of
31688 -- the context clause to ensure the correct processing.
31689
31690 if Has_Pragma_Suppress_All (N) then
31691 Prepend_To (Context_Items (N),
31692 Make_Pragma (Sloc (N),
31693 Chars => Name_Suppress,
31694 Pragma_Argument_Associations => New_List (
31695 Make_Pragma_Argument_Association (Sloc (N),
31696 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
31697 end if;
31698
31699 -- Nothing else to do at the current time
31700
31701 end Process_Compilation_Unit_Pragmas;
31702
31703 --------------------------------------------
31704 -- Validate_Compile_Time_Warning_Or_Error --
31705 --------------------------------------------
31706
31707 procedure Validate_Compile_Time_Warning_Or_Error
31708 (N : Node_Id;
31709 Eloc : Source_Ptr)
31710 is
31711 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
31712 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
31713 Arg2 : constant Node_Id := Next (Arg1);
31714
31715 Pname : constant Name_Id := Pragma_Name_Unmapped (N);
31716 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
31717
31718 begin
31719 Analyze_And_Resolve (Arg1x, Standard_Boolean);
31720
31721 if Compile_Time_Known_Value (Arg1x) then
31722 if Is_True (Expr_Value (Arg1x)) then
31723
31724 -- We have already verified that the second argument is a static
31725 -- string expression. Its string value must be retrieved
31726 -- explicitly if it is a declared constant, otherwise it has
31727 -- been constant-folded previously.
31728
31729 declare
31730 Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
31731 Str : constant String_Id :=
31732 Strval (Expr_Value_S (Get_Pragma_Arg (Arg2)));
31733 Str_Len : constant Nat := String_Length (Str);
31734
31735 Force : constant Boolean :=
31736 Prag_Id = Pragma_Compile_Time_Warning
31737 and then Is_Spec_Name (Unit_Name (Current_Sem_Unit))
31738 and then (Ekind (Cent) /= E_Package
31739 or else not In_Private_Part (Cent));
31740 -- Set True if this is the warning case, and we are in the
31741 -- visible part of a package spec, or in a subprogram spec,
31742 -- in which case we want to force the client to see the
31743 -- warning, even though it is not in the main unit.
31744
31745 C : Character;
31746 CC : Char_Code;
31747 Cont : Boolean;
31748 Ptr : Nat;
31749
31750 begin
31751 -- Loop through segments of message separated by line feeds.
31752 -- We output these segments as separate messages with
31753 -- continuation marks for all but the first.
31754
31755 Cont := False;
31756 Ptr := 1;
31757 loop
31758 Error_Msg_Strlen := 0;
31759
31760 -- Loop to copy characters from argument to error message
31761 -- string buffer.
31762
31763 loop
31764 exit when Ptr > Str_Len;
31765 CC := Get_String_Char (Str, Ptr);
31766 Ptr := Ptr + 1;
31767
31768 -- Ignore wide chars ??? else store character
31769
31770 if In_Character_Range (CC) then
31771 C := Get_Character (CC);
31772 exit when C = ASCII.LF;
31773 Error_Msg_Strlen := Error_Msg_Strlen + 1;
31774 Error_Msg_String (Error_Msg_Strlen) := C;
31775 end if;
31776 end loop;
31777
31778 -- Here with one line ready to go
31779
31780 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
31781
31782 -- If this is a warning in a spec, then we want clients
31783 -- to see the warning, so mark the message with the
31784 -- special sequence !! to force the warning. In the case
31785 -- of a package spec, we do not force this if we are in
31786 -- the private part of the spec.
31787
31788 if Force then
31789 if Cont = False then
31790 Error_Msg ("<<~!!", Eloc);
31791 Cont := True;
31792 else
31793 Error_Msg ("\<<~!!", Eloc);
31794 end if;
31795
31796 -- Error, rather than warning, or in a body, so we do not
31797 -- need to force visibility for client (error will be
31798 -- output in any case, and this is the situation in which
31799 -- we do not want a client to get a warning, since the
31800 -- warning is in the body or the spec private part).
31801
31802 else
31803 if Cont = False then
31804 Error_Msg ("<<~", Eloc);
31805 Cont := True;
31806 else
31807 Error_Msg ("\<<~", Eloc);
31808 end if;
31809 end if;
31810
31811 exit when Ptr > Str_Len;
31812 end loop;
31813 end;
31814 end if;
31815
31816 -- Arg1x is not known at compile time, so possibly issue an error
31817 -- or warning. This can happen only if the pragma's processing
31818 -- was deferred until after the back end is run (see
31819 -- Process_Compile_Time_Warning_Or_Error). Note that the warning
31820 -- control switch applies to only the warning case.
31821
31822 elsif Prag_Id = Pragma_Compile_Time_Error then
31823 Error_Msg_N ("condition is not known at compile time", Arg1x);
31824
31825 elsif Warn_On_Unknown_Compile_Time_Warning then
31826 Error_Msg_N ("?condition is not known at compile time", Arg1x);
31827 end if;
31828 end Validate_Compile_Time_Warning_Or_Error;
31829
31830 ------------------------------------
31831 -- Record_Possible_Body_Reference --
31832 ------------------------------------
31833
31834 procedure Record_Possible_Body_Reference
31835 (State_Id : Entity_Id;
31836 Ref : Node_Id)
31837 is
31838 Context : Node_Id;
31839 Spec_Id : Entity_Id;
31840
31841 begin
31842 -- Ensure that we are dealing with a reference to a state
31843
31844 pragma Assert (Ekind (State_Id) = E_Abstract_State);
31845
31846 -- Climb the tree starting from the reference looking for a package body
31847 -- whose spec declares the referenced state. This criteria automatically
31848 -- excludes references in package specs which are legal. Note that it is
31849 -- not wise to emit an error now as the package body may lack pragma
31850 -- Refined_State or the referenced state may not be mentioned in the
31851 -- refinement. This approach avoids the generation of misleading errors.
31852
31853 Context := Ref;
31854 while Present (Context) loop
31855 if Nkind (Context) = N_Package_Body then
31856 Spec_Id := Corresponding_Spec (Context);
31857
31858 if Present (Abstract_States (Spec_Id))
31859 and then Contains (Abstract_States (Spec_Id), State_Id)
31860 then
31861 if No (Body_References (State_Id)) then
31862 Set_Body_References (State_Id, New_Elmt_List);
31863 end if;
31864
31865 Append_Elmt (Ref, To => Body_References (State_Id));
31866 exit;
31867 end if;
31868 end if;
31869
31870 Context := Parent (Context);
31871 end loop;
31872 end Record_Possible_Body_Reference;
31873
31874 ------------------------------------------
31875 -- Relocate_Pragmas_To_Anonymous_Object --
31876 ------------------------------------------
31877
31878 procedure Relocate_Pragmas_To_Anonymous_Object
31879 (Typ_Decl : Node_Id;
31880 Obj_Decl : Node_Id)
31881 is
31882 Decl : Node_Id;
31883 Def : Node_Id;
31884 Next_Decl : Node_Id;
31885
31886 begin
31887 if Nkind (Typ_Decl) = N_Protected_Type_Declaration then
31888 Def := Protected_Definition (Typ_Decl);
31889 else
31890 pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration);
31891 Def := Task_Definition (Typ_Decl);
31892 end if;
31893
31894 -- The concurrent definition has a visible declaration list. Inspect it
31895 -- and relocate all canidate pragmas.
31896
31897 if Present (Def) and then Present (Visible_Declarations (Def)) then
31898 Decl := First (Visible_Declarations (Def));
31899 while Present (Decl) loop
31900
31901 -- Preserve the following declaration for iteration purposes due
31902 -- to possible relocation of a pragma.
31903
31904 Next_Decl := Next (Decl);
31905
31906 if Nkind (Decl) = N_Pragma
31907 and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl))
31908 then
31909 Remove (Decl);
31910 Insert_After (Obj_Decl, Decl);
31911
31912 -- Skip internally generated code
31913
31914 elsif not Comes_From_Source (Decl) then
31915 null;
31916
31917 -- No candidate pragmas are available for relocation
31918
31919 else
31920 exit;
31921 end if;
31922
31923 Decl := Next_Decl;
31924 end loop;
31925 end if;
31926 end Relocate_Pragmas_To_Anonymous_Object;
31927
31928 ------------------------------
31929 -- Relocate_Pragmas_To_Body --
31930 ------------------------------
31931
31932 procedure Relocate_Pragmas_To_Body
31933 (Subp_Body : Node_Id;
31934 Target_Body : Node_Id := Empty)
31935 is
31936 procedure Relocate_Pragma (Prag : Node_Id);
31937 -- Remove a single pragma from its current list and add it to the
31938 -- declarations of the proper body (either Subp_Body or Target_Body).
31939
31940 ---------------------
31941 -- Relocate_Pragma --
31942 ---------------------
31943
31944 procedure Relocate_Pragma (Prag : Node_Id) is
31945 Decls : List_Id;
31946 Target : Node_Id;
31947
31948 begin
31949 -- When subprogram stubs or expression functions are involves, the
31950 -- destination declaration list belongs to the proper body.
31951
31952 if Present (Target_Body) then
31953 Target := Target_Body;
31954 else
31955 Target := Subp_Body;
31956 end if;
31957
31958 Decls := Declarations (Target);
31959
31960 if No (Decls) then
31961 Decls := New_List;
31962 Set_Declarations (Target, Decls);
31963 end if;
31964
31965 -- Unhook the pragma from its current list
31966
31967 Remove (Prag);
31968 Prepend (Prag, Decls);
31969 end Relocate_Pragma;
31970
31971 -- Local variables
31972
31973 Body_Id : constant Entity_Id :=
31974 Defining_Unit_Name (Specification (Subp_Body));
31975 Next_Stmt : Node_Id;
31976 Stmt : Node_Id;
31977
31978 -- Start of processing for Relocate_Pragmas_To_Body
31979
31980 begin
31981 -- Do not process a body that comes from a separate unit as no construct
31982 -- can possibly follow it.
31983
31984 if not Is_List_Member (Subp_Body) then
31985 return;
31986
31987 -- Do not relocate pragmas that follow a stub if the stub does not have
31988 -- a proper body.
31989
31990 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
31991 and then No (Target_Body)
31992 then
31993 return;
31994
31995 -- Do not process internally generated routine _Postconditions
31996
31997 elsif Ekind (Body_Id) = E_Procedure
31998 and then Chars (Body_Id) = Name_uPostconditions
31999 then
32000 return;
32001 end if;
32002
32003 -- Look at what is following the body. We are interested in certain kind
32004 -- of pragmas (either from source or byproducts of expansion) that can
32005 -- apply to a body [stub].
32006
32007 Stmt := Next (Subp_Body);
32008 while Present (Stmt) loop
32009
32010 -- Preserve the following statement for iteration purposes due to a
32011 -- possible relocation of a pragma.
32012
32013 Next_Stmt := Next (Stmt);
32014
32015 -- Move a candidate pragma following the body to the declarations of
32016 -- the body.
32017
32018 if Nkind (Stmt) = N_Pragma
32019 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
32020 then
32021
32022 -- If a source pragma Warnings follows the body, it applies to
32023 -- following statements and does not belong in the body.
32024
32025 if Get_Pragma_Id (Stmt) = Pragma_Warnings
32026 and then Comes_From_Source (Stmt)
32027 then
32028 null;
32029 else
32030 Relocate_Pragma (Stmt);
32031 end if;
32032
32033 -- Skip internally generated code
32034
32035 elsif not Comes_From_Source (Stmt) then
32036 null;
32037
32038 -- No candidate pragmas are available for relocation
32039
32040 else
32041 exit;
32042 end if;
32043
32044 Stmt := Next_Stmt;
32045 end loop;
32046 end Relocate_Pragmas_To_Body;
32047
32048 -------------------
32049 -- Resolve_State --
32050 -------------------
32051
32052 procedure Resolve_State (N : Node_Id) is
32053 Func : Entity_Id;
32054 State : Entity_Id;
32055
32056 begin
32057 if Is_Entity_Name (N) and then Present (Entity (N)) then
32058 Func := Entity (N);
32059
32060 -- Handle overloading of state names by functions. Traverse the
32061 -- homonym chain looking for an abstract state.
32062
32063 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
32064 pragma Assert (Is_Overloaded (N));
32065
32066 State := Homonym (Func);
32067 while Present (State) loop
32068 if Ekind (State) = E_Abstract_State then
32069
32070 -- Resolve the overloading by setting the proper entity of
32071 -- the reference to that of the state.
32072
32073 Set_Etype (N, Standard_Void_Type);
32074 Set_Entity (N, State);
32075 Set_Is_Overloaded (N, False);
32076
32077 Generate_Reference (State, N);
32078 return;
32079 end if;
32080
32081 State := Homonym (State);
32082 end loop;
32083
32084 -- A function can never act as a state. If the homonym chain does
32085 -- not contain a corresponding state, then something went wrong in
32086 -- the overloading mechanism.
32087
32088 raise Program_Error;
32089 end if;
32090 end if;
32091 end Resolve_State;
32092
32093 ----------------------------
32094 -- Rewrite_Assertion_Kind --
32095 ----------------------------
32096
32097 procedure Rewrite_Assertion_Kind
32098 (N : Node_Id;
32099 From_Policy : Boolean := False)
32100 is
32101 Nam : Name_Id;
32102
32103 begin
32104 Nam := No_Name;
32105 if Nkind (N) = N_Attribute_Reference
32106 and then Attribute_Name (N) = Name_Class
32107 and then Nkind (Prefix (N)) = N_Identifier
32108 then
32109 case Chars (Prefix (N)) is
32110 when Name_Pre =>
32111 Nam := Name_uPre;
32112
32113 when Name_Post =>
32114 Nam := Name_uPost;
32115
32116 when Name_Type_Invariant =>
32117 Nam := Name_uType_Invariant;
32118
32119 when Name_Invariant =>
32120 Nam := Name_uInvariant;
32121
32122 when others =>
32123 return;
32124 end case;
32125
32126 -- Recommend standard use of aspect names Pre/Post
32127
32128 elsif Nkind (N) = N_Identifier
32129 and then From_Policy
32130 and then Serious_Errors_Detected = 0
32131 then
32132 if Chars (N) = Name_Precondition
32133 or else Chars (N) = Name_Postcondition
32134 then
32135 Error_Msg_N ("Check_Policy is a non-standard pragma??", N);
32136 Error_Msg_N
32137 ("\use Assertion_Policy and aspect names Pre/Post for "
32138 & "Ada2012 conformance?", N);
32139 end if;
32140
32141 return;
32142 end if;
32143
32144 if Nam /= No_Name then
32145 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
32146 end if;
32147 end Rewrite_Assertion_Kind;
32148
32149 --------
32150 -- rv --
32151 --------
32152
32153 procedure rv is
32154 begin
32155 Dummy := Dummy + 1;
32156 end rv;
32157
32158 --------------------------------
32159 -- Set_Encoded_Interface_Name --
32160 --------------------------------
32161
32162 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
32163 Str : constant String_Id := Strval (S);
32164 Len : constant Nat := String_Length (Str);
32165 CC : Char_Code;
32166 C : Character;
32167 J : Pos;
32168
32169 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
32170
32171 procedure Encode;
32172 -- Stores encoded value of character code CC. The encoding we use an
32173 -- underscore followed by four lower case hex digits.
32174
32175 ------------
32176 -- Encode --
32177 ------------
32178
32179 procedure Encode is
32180 begin
32181 Store_String_Char (Get_Char_Code ('_'));
32182 Store_String_Char
32183 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
32184 Store_String_Char
32185 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
32186 Store_String_Char
32187 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
32188 Store_String_Char
32189 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
32190 end Encode;
32191
32192 -- Start of processing for Set_Encoded_Interface_Name
32193
32194 begin
32195 -- If first character is asterisk, this is a link name, and we leave it
32196 -- completely unmodified. We also ignore null strings (the latter case
32197 -- happens only in error cases).
32198
32199 if Len = 0
32200 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
32201 then
32202 Set_Interface_Name (E, S);
32203
32204 else
32205 J := 1;
32206 loop
32207 CC := Get_String_Char (Str, J);
32208
32209 exit when not In_Character_Range (CC);
32210
32211 C := Get_Character (CC);
32212
32213 exit when C /= '_' and then C /= '$'
32214 and then C not in '0' .. '9'
32215 and then C not in 'a' .. 'z'
32216 and then C not in 'A' .. 'Z';
32217
32218 if J = Len then
32219 Set_Interface_Name (E, S);
32220 return;
32221
32222 else
32223 J := J + 1;
32224 end if;
32225 end loop;
32226
32227 -- Here we need to encode. The encoding we use as follows:
32228 -- three underscores + four hex digits (lower case)
32229
32230 Start_String;
32231
32232 for J in 1 .. String_Length (Str) loop
32233 CC := Get_String_Char (Str, J);
32234
32235 if not In_Character_Range (CC) then
32236 Encode;
32237 else
32238 C := Get_Character (CC);
32239
32240 if C = '_' or else C = '$'
32241 or else C in '0' .. '9'
32242 or else C in 'a' .. 'z'
32243 or else C in 'A' .. 'Z'
32244 then
32245 Store_String_Char (CC);
32246 else
32247 Encode;
32248 end if;
32249 end if;
32250 end loop;
32251
32252 Set_Interface_Name (E,
32253 Make_String_Literal (Sloc (S),
32254 Strval => End_String));
32255 end if;
32256 end Set_Encoded_Interface_Name;
32257
32258 ------------------------
32259 -- Set_Elab_Unit_Name --
32260 ------------------------
32261
32262 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
32263 Pref : Node_Id;
32264 Scop : Entity_Id;
32265
32266 begin
32267 if Nkind (N) = N_Identifier
32268 and then Nkind (With_Item) = N_Identifier
32269 then
32270 Set_Entity (N, Entity (With_Item));
32271
32272 elsif Nkind (N) = N_Selected_Component then
32273 Change_Selected_Component_To_Expanded_Name (N);
32274 Set_Entity (N, Entity (With_Item));
32275 Set_Entity (Selector_Name (N), Entity (N));
32276
32277 Pref := Prefix (N);
32278 Scop := Scope (Entity (N));
32279 while Nkind (Pref) = N_Selected_Component loop
32280 Change_Selected_Component_To_Expanded_Name (Pref);
32281 Set_Entity (Selector_Name (Pref), Scop);
32282 Set_Entity (Pref, Scop);
32283 Pref := Prefix (Pref);
32284 Scop := Scope (Scop);
32285 end loop;
32286
32287 Set_Entity (Pref, Scop);
32288 end if;
32289
32290 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
32291 end Set_Elab_Unit_Name;
32292
32293 -----------------------
32294 -- Set_Overflow_Mode --
32295 -----------------------
32296
32297 procedure Set_Overflow_Mode (N : Node_Id) is
32298
32299 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type;
32300 -- Function to process one pragma argument, Arg
32301
32302 -----------------------
32303 -- Get_Overflow_Mode --
32304 -----------------------
32305
32306 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type is
32307 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
32308
32309 begin
32310 if Chars (Argx) = Name_Strict then
32311 return Strict;
32312
32313 elsif Chars (Argx) = Name_Minimized then
32314 return Minimized;
32315
32316 elsif Chars (Argx) = Name_Eliminated then
32317 return Eliminated;
32318
32319 else
32320 raise Program_Error;
32321 end if;
32322 end Get_Overflow_Mode;
32323
32324 -- Local variables
32325
32326 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
32327 Arg2 : constant Node_Id := Next (Arg1);
32328
32329 -- Start of processing for Set_Overflow_Mode
32330
32331 begin
32332 -- Process first argument
32333
32334 Scope_Suppress.Overflow_Mode_General :=
32335 Get_Overflow_Mode (Arg1);
32336
32337 -- Case of only one argument
32338
32339 if No (Arg2) then
32340 Scope_Suppress.Overflow_Mode_Assertions :=
32341 Scope_Suppress.Overflow_Mode_General;
32342
32343 -- Case of two arguments present
32344
32345 else
32346 Scope_Suppress.Overflow_Mode_Assertions :=
32347 Get_Overflow_Mode (Arg2);
32348 end if;
32349 end Set_Overflow_Mode;
32350
32351 -------------------
32352 -- Test_Case_Arg --
32353 -------------------
32354
32355 function Test_Case_Arg
32356 (Prag : Node_Id;
32357 Arg_Nam : Name_Id;
32358 From_Aspect : Boolean := False) return Node_Id
32359 is
32360 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
32361 Arg : Node_Id;
32362 Args : Node_Id;
32363
32364 begin
32365 pragma Assert (Nam_In (Arg_Nam, Name_Ensures,
32366 Name_Mode,
32367 Name_Name,
32368 Name_Requires));
32369
32370 -- The caller requests the aspect argument
32371
32372 if From_Aspect then
32373 if Present (Aspect)
32374 and then Nkind (Expression (Aspect)) = N_Aggregate
32375 then
32376 Args := Expression (Aspect);
32377
32378 -- "Name" and "Mode" may appear without an identifier as a
32379 -- positional association.
32380
32381 if Present (Expressions (Args)) then
32382 Arg := First (Expressions (Args));
32383
32384 if Present (Arg) and then Arg_Nam = Name_Name then
32385 return Arg;
32386 end if;
32387
32388 -- Skip "Name"
32389
32390 Arg := Next (Arg);
32391
32392 if Present (Arg) and then Arg_Nam = Name_Mode then
32393 return Arg;
32394 end if;
32395 end if;
32396
32397 -- Some or all arguments may appear as component associatons
32398
32399 if Present (Component_Associations (Args)) then
32400 Arg := First (Component_Associations (Args));
32401 while Present (Arg) loop
32402 if Chars (First (Choices (Arg))) = Arg_Nam then
32403 return Arg;
32404 end if;
32405
32406 Next (Arg);
32407 end loop;
32408 end if;
32409 end if;
32410
32411 -- Otherwise retrieve the argument directly from the pragma
32412
32413 else
32414 Arg := First (Pragma_Argument_Associations (Prag));
32415
32416 if Present (Arg) and then Arg_Nam = Name_Name then
32417 return Arg;
32418 end if;
32419
32420 -- Skip argument "Name"
32421
32422 Arg := Next (Arg);
32423
32424 if Present (Arg) and then Arg_Nam = Name_Mode then
32425 return Arg;
32426 end if;
32427
32428 -- Skip argument "Mode"
32429
32430 Arg := Next (Arg);
32431
32432 -- Arguments "Requires" and "Ensures" are optional and may not be
32433 -- present at all.
32434
32435 while Present (Arg) loop
32436 if Chars (Arg) = Arg_Nam then
32437 return Arg;
32438 end if;
32439
32440 Next (Arg);
32441 end loop;
32442 end if;
32443
32444 return Empty;
32445 end Test_Case_Arg;
32446
32447 --------------------------------------------
32448 -- Defer_Compile_Time_Warning_Error_To_BE --
32449 --------------------------------------------
32450
32451 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id) is
32452 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
32453 begin
32454 Compile_Time_Warnings_Errors.Append
32455 (New_Val => CTWE_Entry'(Eloc => Sloc (Arg1),
32456 Scope => Current_Scope,
32457 Prag => N));
32458
32459 -- If the Boolean expression contains T'Size, and we're not in the main
32460 -- unit being compiled, then we need to copy the pragma into the main
32461 -- unit, because otherwise T'Size might never be computed, leaving it
32462 -- as 0.
32463
32464 if not In_Extended_Main_Code_Unit (N) then
32465 Insert_Library_Level_Action (New_Copy_Tree (N));
32466 end if;
32467 end Defer_Compile_Time_Warning_Error_To_BE;
32468
32469 ------------------------------------------
32470 -- Validate_Compile_Time_Warning_Errors --
32471 ------------------------------------------
32472
32473 procedure Validate_Compile_Time_Warning_Errors is
32474 procedure Set_Scope (S : Entity_Id);
32475 -- Install all enclosing scopes of S along with S itself
32476
32477 procedure Unset_Scope (S : Entity_Id);
32478 -- Uninstall all enclosing scopes of S along with S itself
32479
32480 ---------------
32481 -- Set_Scope --
32482 ---------------
32483
32484 procedure Set_Scope (S : Entity_Id) is
32485 begin
32486 if S /= Standard_Standard then
32487 Set_Scope (Scope (S));
32488 end if;
32489
32490 Push_Scope (S);
32491 end Set_Scope;
32492
32493 -----------------
32494 -- Unset_Scope --
32495 -----------------
32496
32497 procedure Unset_Scope (S : Entity_Id) is
32498 begin
32499 if S /= Standard_Standard then
32500 Unset_Scope (Scope (S));
32501 end if;
32502
32503 Pop_Scope;
32504 end Unset_Scope;
32505
32506 -- Start of processing for Validate_Compile_Time_Warning_Errors
32507
32508 begin
32509 Expander_Mode_Save_And_Set (False);
32510 In_Compile_Time_Warning_Or_Error := True;
32511
32512 for N in Compile_Time_Warnings_Errors.First ..
32513 Compile_Time_Warnings_Errors.Last
32514 loop
32515 declare
32516 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
32517
32518 begin
32519 Set_Scope (T.Scope);
32520 Reset_Analyzed_Flags (T.Prag);
32521 Validate_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
32522 Unset_Scope (T.Scope);
32523 end;
32524 end loop;
32525
32526 In_Compile_Time_Warning_Or_Error := False;
32527 Expander_Mode_Restore;
32528 end Validate_Compile_Time_Warning_Errors;
32529
32530 end Sem_Prag;