]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/sem_prag.adb
ada: Accept constants of access types as globals of side-effect function
[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-2024, 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 Einfo.Entities; use Einfo.Entities;
41 with Einfo.Utils; use Einfo.Utils;
42 with Elists; use Elists;
43 with Errout; use Errout;
44 with Exp_Dist; use Exp_Dist;
45 with Exp_Util; use Exp_Util;
46 with Expander; use Expander;
47 with Freeze; use Freeze;
48 with Ghost; use Ghost;
49 with GNAT_CUDA; use GNAT_CUDA;
50 with Gnatvsn; use Gnatvsn;
51 with Lib; use Lib;
52 with Lib.Writ; use Lib.Writ;
53 with Lib.Xref; use Lib.Xref;
54 with Namet.Sp; use Namet.Sp;
55 with Nlists; use Nlists;
56 with Nmake; use Nmake;
57 with Output; use Output;
58 with Par_SCO; use Par_SCO;
59 with Restrict; use Restrict;
60 with Rident; use Rident;
61 with Rtsfind; use Rtsfind;
62 with Sem; use Sem;
63 with Sem_Aux; use Sem_Aux;
64 with Sem_Ch3; use Sem_Ch3;
65 with Sem_Ch6; use Sem_Ch6;
66 with Sem_Ch7; use Sem_Ch7;
67 with Sem_Ch8; use Sem_Ch8;
68 with Sem_Ch12; use Sem_Ch12;
69 with Sem_Ch13; use Sem_Ch13;
70 with Sem_Disp; use Sem_Disp;
71 with Sem_Dist; use Sem_Dist;
72 with Sem_Elab; use Sem_Elab;
73 with Sem_Elim; use Sem_Elim;
74 with Sem_Eval; use Sem_Eval;
75 with Sem_Intr; use Sem_Intr;
76 with Sem_Mech; use Sem_Mech;
77 with Sem_Res; use Sem_Res;
78 with Sem_Type; use Sem_Type;
79 with Sem_Util; use Sem_Util;
80 with Sem_Warn; use Sem_Warn;
81 with Stand; use Stand;
82 with Sinfo; use Sinfo;
83 with Sinfo.Nodes; use Sinfo.Nodes;
84 with Sinfo.Utils; use Sinfo.Utils;
85 with Sinfo.CN; use Sinfo.CN;
86 with Sinput; use Sinput;
87 with Stringt; use Stringt;
88 with Strub; use Strub;
89 with Stylesw; use Stylesw;
90 with Table;
91 with Targparm; use Targparm;
92 with Tbuild; use Tbuild;
93 with Ttypes;
94 with Uintp; use Uintp;
95 with Uname; use Uname;
96 with Urealp; use Urealp;
97 with Validsw; use Validsw;
98 with Warnsw; use Warnsw;
99
100 with System.Case_Util;
101
102 package body Sem_Prag is
103
104 ----------------------------------------------
105 -- Common Handling of Import-Export Pragmas --
106 ----------------------------------------------
107
108 -- In the following section, a number of Import_xxx and Export_xxx pragmas
109 -- are defined by GNAT. These are compatible with the DEC pragmas of the
110 -- same name, and all have the following common form and processing:
111
112 -- pragma Export_xxx
113 -- [Internal =>] LOCAL_NAME
114 -- [, [External =>] EXTERNAL_SYMBOL]
115 -- [, other optional parameters ]);
116
117 -- pragma Import_xxx
118 -- [Internal =>] LOCAL_NAME
119 -- [, [External =>] EXTERNAL_SYMBOL]
120 -- [, other optional parameters ]);
121
122 -- EXTERNAL_SYMBOL ::=
123 -- IDENTIFIER
124 -- | static_string_EXPRESSION
125
126 -- The internal LOCAL_NAME designates the entity that is imported or
127 -- exported, and must refer to an entity in the current declarative
128 -- part (as required by the rules for LOCAL_NAME).
129
130 -- The external linker name is designated by the External parameter if
131 -- given, or the Internal parameter if not (if there is no External
132 -- parameter, the External parameter is a copy of the Internal name).
133
134 -- If the External parameter is given as a string, then this string is
135 -- treated as an external name (exactly as though it had been given as an
136 -- External_Name parameter for a normal Import pragma).
137
138 -- If the External parameter is given as an identifier (or there is no
139 -- External parameter, so that the Internal identifier is used), then
140 -- the external name is the characters of the identifier, translated
141 -- to all lower case letters.
142
143 -- Note: the external name specified or implied by any of these special
144 -- Import_xxx or Export_xxx pragmas override an external or link name
145 -- specified in a previous Import or Export pragma.
146
147 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
148 -- named notation, following the standard rules for subprogram calls, i.e.
149 -- parameters can be given in any order if named notation is used, and
150 -- positional and named notation can be mixed, subject to the rule that all
151 -- positional parameters must appear first.
152
153 -- Note: All these pragmas are implemented exactly following the DEC design
154 -- and implementation and are intended to be fully compatible with the use
155 -- of these pragmas in the DEC Ada compiler.
156
157 --------------------------------------------
158 -- Checking for Duplicated External Names --
159 --------------------------------------------
160
161 -- It is suspicious if two separate Export pragmas use the same external
162 -- name. The following table is used to diagnose this situation so that
163 -- an appropriate warning can be issued.
164
165 -- The Node_Id stored is for the N_String_Literal node created to hold
166 -- the value of the external name. The Sloc of this node is used to
167 -- cross-reference the location of the duplication.
168
169 package Externals is new Table.Table (
170 Table_Component_Type => Node_Id,
171 Table_Index_Type => Int,
172 Table_Low_Bound => 0,
173 Table_Initial => 100,
174 Table_Increment => 100,
175 Table_Name => "Name_Externals");
176
177 -------------------------------------
178 -- Local Subprograms and Variables --
179 -------------------------------------
180
181 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
182 -- This routine is used for possible casing adjustment of an explicit
183 -- external name supplied as a string literal (the node N), according to
184 -- the casing requirement of Opt.External_Name_Casing. If this is set to
185 -- As_Is, then the string literal is returned unchanged, but if it is set
186 -- to Uppercase or Lowercase, then a new string literal with appropriate
187 -- casing is constructed.
188
189 procedure Analyze_If_Present_Internal
190 (N : Node_Id;
191 Id : Pragma_Id;
192 Included : Boolean);
193 -- Inspect the remainder of the list containing pragma N and look for a
194 -- pragma that matches Id. If found, analyze the pragma. If Included is
195 -- True, N is included in the search.
196
197 procedure Analyze_Part_Of
198 (Indic : Node_Id;
199 Item_Id : Entity_Id;
200 Encap : Node_Id;
201 Encap_Id : out Entity_Id;
202 Legal : out Boolean);
203 -- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and
204 -- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the
205 -- Part_Of indicator. Item_Id is the entity of an abstract state, object or
206 -- package instantiation. Encap denotes the encapsulating state or single
207 -- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when
208 -- the indicator is legal.
209
210 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
211 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
212 -- Query whether a particular item appears in a mixed list of nodes and
213 -- entities. It is assumed that all nodes in the list have entities.
214
215 procedure Check_Postcondition_Use_In_Inlined_Subprogram
216 (Prag : Node_Id;
217 Spec_Id : Entity_Id);
218 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
219 -- Precondition, Refined_Post, Subprogram_Variant, and Test_Case. Emit a
220 -- warning when pragma Prag is associated with subprogram Spec_Id subject
221 -- to Inline_Always, assertions are enabled and inling is done in the
222 -- frontend.
223
224 procedure Check_State_And_Constituent_Use
225 (States : Elist_Id;
226 Constits : Elist_Id;
227 Context : Node_Id);
228 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
229 -- Global and Initializes. Determine whether a state from list States and a
230 -- corresponding constituent from list Constits (if any) appear in the same
231 -- context denoted by Context. If this is the case, emit an error.
232
233 procedure Contract_Freeze_Error
234 (Contract_Id : Entity_Id;
235 Freeze_Id : Entity_Id);
236 -- Subsidiary to the analysis of pragmas Contract_Cases, Exceptional_Cases,
237 -- Part_Of, Post, Pre and Subprogram_Variant. Emit a freezing-related error
238 -- message where Freeze_Id is the entity of a body which caused contract
239 -- freezing and Contract_Id denotes the entity of the affected contstruct.
240
241 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id);
242 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma
243 -- Prag that duplicates previous pragma Prev.
244
245 function Find_Encapsulating_State
246 (States : Elist_Id;
247 Constit_Id : Entity_Id) return Entity_Id;
248 -- Given the entity of a constituent Constit_Id, find the corresponding
249 -- encapsulating state which appears in States. The routine returns Empty
250 -- if no such state is found.
251
252 function Find_Related_Context
253 (Prag : Node_Id;
254 Do_Checks : Boolean := False) return Node_Id;
255 -- Subsidiary to the analysis of pragmas
256 -- Async_Readers
257 -- Async_Writers
258 -- Constant_After_Elaboration
259 -- Effective_Reads
260 -- Effective_Writers
261 -- No_Caching
262 -- Part_Of
263 -- Find the first source declaration or statement found while traversing
264 -- the previous node chain starting from pragma Prag. If flag Do_Checks is
265 -- set, the routine reports duplicate pragmas. The routine returns Empty
266 -- when reaching the start of the node chain.
267
268 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
269 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
270 -- original one, following the renaming chain) is returned. Otherwise the
271 -- entity is returned unchanged. Should be in Einfo???
272
273 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
274 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
275 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
276 -- value of type SPARK_Mode_Type.
277
278 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
279 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
280 -- Determine whether dependency clause Clause is surrounded by extra
281 -- parentheses. If this is the case, issue an error message.
282
283 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
284 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
285 -- pragma Depends. Determine whether the type of dependency item Item is
286 -- tagged, unconstrained array or unconstrained record.
287
288 procedure Record_Possible_Body_Reference
289 (State_Id : Entity_Id;
290 Ref : Node_Id);
291 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
292 -- Global. Given an abstract state denoted by State_Id and a reference Ref
293 -- to it, determine whether the reference appears in a package body that
294 -- will eventually refine the state. If this is the case, record the
295 -- reference for future checks (see Analyze_Refined_State_In_Decls).
296
297 procedure Resolve_State (N : Node_Id);
298 -- Handle the overloading of state names by functions. When N denotes a
299 -- function, this routine finds the corresponding state and sets the entity
300 -- of N to that of the state.
301
302 procedure Rewrite_Assertion_Kind
303 (N : Node_Id;
304 From_Policy : Boolean := False);
305 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
306 -- then it is rewritten as an identifier with the corresponding special
307 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
308 -- and Check_Policy. If the names are Precondition or Postcondition, this
309 -- combination is deprecated in favor of Assertion_Policy and Ada2012
310 -- Aspect names. The parameter From_Policy indicates that the pragma
311 -- is the old non-standard Check_Policy and not a rewritten pragma.
312
313 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
314 -- Place semantic information on the argument of an Elaborate/Elaborate_All
315 -- pragma. Entity name for unit and its parents is taken from item in
316 -- previous with_clause that mentions the unit.
317
318 procedure Validate_Compile_Time_Warning_Or_Error
319 (N : Node_Id;
320 Eloc : Source_Ptr);
321 -- Common processing for Compile_Time_Error and Compile_Time_Warning of
322 -- pragma N. Called when the pragma is processed as part of its regular
323 -- analysis but also called after calling the back end to validate these
324 -- pragmas for size and alignment appropriateness.
325
326 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id);
327 -- N is a pragma Compile_Time_Error or Compile_Warning_Error whose boolean
328 -- expression is not known at compile time during the front end. This
329 -- procedure makes an entry in a table. The actual checking is performed by
330 -- Validate_Compile_Time_Warning_Errors, which is invoked after calling the
331 -- back end.
332
333 Dummy : Integer := 0;
334 pragma Volatile (Dummy);
335 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
336
337 procedure ip;
338 pragma No_Inline (ip);
339 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
340 -- is just to help debugging the front end. If a pragma Inspection_Point
341 -- is added to a source program, then breaking on ip will get you to that
342 -- point in the program.
343
344 procedure rv;
345 pragma No_Inline (rv);
346 -- This is a dummy function called by the processing for pragma Reviewable.
347 -- It is there for assisting front end debugging. By placing a Reviewable
348 -- pragma in the source program, a breakpoint on rv catches this place in
349 -- the source, allowing convenient stepping to the point of interest.
350
351 ------------------------------------------------------
352 -- Table for Defer_Compile_Time_Warning_Error_To_BE --
353 ------------------------------------------------------
354
355 -- The following table collects pragmas Compile_Time_Error and Compile_
356 -- Time_Warning for validation. Entries are made by calls to subprogram
357 -- Defer_Compile_Time_Warning_Error_To_BE, and the call to the procedure
358 -- Validate_Compile_Time_Warning_Errors does the actual error checking
359 -- and posting of warning and error messages. The reason for this delayed
360 -- processing is to take advantage of back-annotations of attributes size
361 -- and alignment values performed by the back end.
362
363 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
364 -- that by the time Validate_Compile_Time_Warning_Errors is called, Sprint
365 -- will already have modified all Sloc values if the -gnatD option is set.
366
367 type CTWE_Entry is record
368 Eloc : Source_Ptr;
369 -- Source location used in warnings and error messages
370
371 Prag : Node_Id;
372 -- Pragma Compile_Time_Error or Compile_Time_Warning
373
374 Scope : Node_Id;
375 -- The scope which encloses the pragma
376 end record;
377
378 package Compile_Time_Warnings_Errors is new Table.Table (
379 Table_Component_Type => CTWE_Entry,
380 Table_Index_Type => Int,
381 Table_Low_Bound => 1,
382 Table_Initial => 50,
383 Table_Increment => 200,
384 Table_Name => "Compile_Time_Warnings_Errors");
385
386 -------------------------------
387 -- Adjust_External_Name_Case --
388 -------------------------------
389
390 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
391 CC : Char_Code;
392
393 begin
394 -- Adjust case of literal if required
395
396 if Opt.External_Name_Exp_Casing = As_Is then
397 return N;
398
399 else
400 -- Copy existing string
401
402 Start_String;
403
404 -- Set proper casing
405
406 for J in 1 .. String_Length (Strval (N)) loop
407 CC := Get_String_Char (Strval (N), J);
408
409 if Opt.External_Name_Exp_Casing = Uppercase
410 and then CC in Get_Char_Code ('a') .. Get_Char_Code ('z')
411 then
412 Store_String_Char (CC - 32);
413
414 elsif Opt.External_Name_Exp_Casing = Lowercase
415 and then CC in Get_Char_Code ('A') .. Get_Char_Code ('Z')
416 then
417 Store_String_Char (CC + 32);
418
419 else
420 Store_String_Char (CC);
421 end if;
422 end loop;
423
424 return
425 Make_String_Literal (Sloc (N),
426 Strval => End_String);
427 end if;
428 end Adjust_External_Name_Case;
429
430 --------------------------------------------
431 -- Analyze_Always_Terminates_In_Decl_Part --
432 --------------------------------------------
433
434 procedure Analyze_Always_Terminates_In_Decl_Part
435 (N : Node_Id;
436 Freeze_Id : Entity_Id := Empty)
437 is
438 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
439 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
440 Arg1 : constant Node_Id :=
441 First (Pragma_Argument_Associations (N));
442
443 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
444 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
445 -- Save the Ghost-related attributes to restore on exit
446
447 Errors : Nat;
448 Restore_Scope : Boolean := False;
449
450 begin
451 -- Do not analyze the pragma multiple times
452
453 if Is_Analyzed_Pragma (N) then
454 return;
455 end if;
456
457 if Present (Arg1) then
458
459 -- Set the Ghost mode in effect from the pragma. Due to the delayed
460 -- analysis of the pragma, the Ghost mode at point of declaration and
461 -- point of analysis may not necessarily be the same. Use the mode in
462 -- effect at the point of declaration.
463
464 Set_Ghost_Mode (N);
465
466 -- Ensure that the subprogram and its formals are visible when
467 -- analyzing the expression of the pragma.
468
469 if not In_Open_Scopes (Spec_Id) then
470 Restore_Scope := True;
471
472 if Is_Generic_Subprogram (Spec_Id) then
473 Push_Scope (Spec_Id);
474 Install_Generic_Formals (Spec_Id);
475 else
476 Push_Scope (Spec_Id);
477 Install_Formals (Spec_Id);
478 end if;
479 end if;
480
481 Errors := Serious_Errors_Detected;
482 Preanalyze_Assert_Expression (Expression (Arg1), Standard_Boolean);
483
484 -- Emit a clarification message when the expression contains at least
485 -- one undefined reference, possibly due to contract freezing.
486
487 if Errors /= Serious_Errors_Detected
488 and then Present (Freeze_Id)
489 and then Has_Undefined_Reference (Expression (Arg1))
490 then
491 Contract_Freeze_Error (Spec_Id, Freeze_Id);
492 end if;
493
494 if Restore_Scope then
495 End_Scope;
496 end if;
497
498 Restore_Ghost_Region (Saved_GM, Saved_IGR);
499 end if;
500
501 Set_Is_Analyzed_Pragma (N);
502
503 end Analyze_Always_Terminates_In_Decl_Part;
504
505 -----------------------------------------
506 -- Analyze_Contract_Cases_In_Decl_Part --
507 -----------------------------------------
508
509 -- WARNING: This routine manages Ghost regions. Return statements must be
510 -- replaced by gotos which jump to the end of the routine and restore the
511 -- Ghost mode.
512
513 procedure Analyze_Contract_Cases_In_Decl_Part
514 (N : Node_Id;
515 Freeze_Id : Entity_Id := Empty)
516 is
517 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
518 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
519
520 Others_Seen : Boolean := False;
521 -- This flag is set when an "others" choice is encountered. It is used
522 -- to detect multiple illegal occurrences of "others".
523
524 procedure Analyze_Contract_Case (CCase : Node_Id);
525 -- Verify the legality of a single contract case
526
527 ---------------------------
528 -- Analyze_Contract_Case --
529 ---------------------------
530
531 procedure Analyze_Contract_Case (CCase : Node_Id) is
532 Case_Guard : Node_Id;
533 Conseq : Node_Id;
534 Errors : Nat;
535 Extra_Guard : Node_Id;
536
537 begin
538 if Nkind (CCase) = N_Component_Association then
539 Case_Guard := First (Choices (CCase));
540 Conseq := Expression (CCase);
541
542 -- Each contract case must have exactly one case guard
543
544 Extra_Guard := Next (Case_Guard);
545
546 if Present (Extra_Guard) then
547 Error_Msg_N
548 ("contract case must have exactly one case guard",
549 Extra_Guard);
550 end if;
551
552 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
553
554 if Nkind (Case_Guard) = N_Others_Choice then
555 if Others_Seen then
556 Error_Msg_N
557 ("only one OTHERS choice allowed in contract cases",
558 Case_Guard);
559 else
560 Others_Seen := True;
561 end if;
562
563 elsif Others_Seen then
564 Error_Msg_N
565 ("OTHERS must be the last choice in contract cases", N);
566 end if;
567
568 -- Preanalyze the case guard and consequence
569
570 if Nkind (Case_Guard) /= N_Others_Choice then
571 Errors := Serious_Errors_Detected;
572 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
573
574 -- Emit a clarification message when the case guard contains
575 -- at least one undefined reference, possibly due to contract
576 -- freezing.
577
578 if Errors /= Serious_Errors_Detected
579 and then Present (Freeze_Id)
580 and then Has_Undefined_Reference (Case_Guard)
581 then
582 Contract_Freeze_Error (Spec_Id, Freeze_Id);
583 end if;
584 end if;
585
586 Errors := Serious_Errors_Detected;
587 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
588
589 -- Emit a clarification message when the consequence contains
590 -- at least one undefined reference, possibly due to contract
591 -- freezing.
592
593 if Errors /= Serious_Errors_Detected
594 and then Present (Freeze_Id)
595 and then Has_Undefined_Reference (Conseq)
596 then
597 Contract_Freeze_Error (Spec_Id, Freeze_Id);
598 end if;
599
600 -- The contract case is malformed
601
602 else
603 Error_Msg_N ("wrong syntax in contract case", CCase);
604 end if;
605 end Analyze_Contract_Case;
606
607 -- Local variables
608
609 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
610
611 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
612 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
613 -- Save the Ghost-related attributes to restore on exit
614
615 CCase : Node_Id;
616 Restore_Scope : Boolean := False;
617
618 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
619
620 begin
621 -- Do not analyze the pragma multiple times
622
623 if Is_Analyzed_Pragma (N) then
624 return;
625 end if;
626
627 -- Set the Ghost mode in effect from the pragma. Due to the delayed
628 -- analysis of the pragma, the Ghost mode at point of declaration and
629 -- point of analysis may not necessarily be the same. Use the mode in
630 -- effect at the point of declaration.
631
632 Set_Ghost_Mode (N);
633
634 -- Single and multiple contract cases must appear in aggregate form. If
635 -- this is not the case, then either the parser or the analysis of the
636 -- pragma failed to produce an aggregate, e.g. when the contract is
637 -- "null" or a "(null record)".
638
639 pragma Assert
640 (if Nkind (CCases) = N_Aggregate
641 then Null_Record_Present (CCases)
642 xor (Present (Component_Associations (CCases))
643 or
644 Present (Expressions (CCases)))
645 else Nkind (CCases) = N_Null);
646
647 -- Only CASE_GUARD => CONSEQUENCE clauses are allowed
648
649 if Nkind (CCases) = N_Aggregate
650 and then Present (Component_Associations (CCases))
651 and then No (Expressions (CCases))
652 then
653
654 -- Check that the expression is a proper aggregate (no parentheses)
655
656 if Paren_Count (CCases) /= 0 then
657 Error_Msg_F -- CODEFIX
658 ("redundant parentheses", CCases);
659 end if;
660
661 -- Ensure that the formal parameters are visible when analyzing all
662 -- clauses. This falls out of the general rule of aspects pertaining
663 -- to subprogram declarations.
664
665 if not In_Open_Scopes (Spec_Id) then
666 Restore_Scope := True;
667 Push_Scope (Spec_Id);
668
669 if Is_Generic_Subprogram (Spec_Id) then
670 Install_Generic_Formals (Spec_Id);
671 else
672 Install_Formals (Spec_Id);
673 end if;
674 end if;
675
676 CCase := First (Component_Associations (CCases));
677 while Present (CCase) loop
678 Analyze_Contract_Case (CCase);
679 Next (CCase);
680 end loop;
681
682 if Restore_Scope then
683 End_Scope;
684 end if;
685
686 -- Currently it is not possible to inline pre/postconditions on a
687 -- subprogram subject to pragma Inline_Always.
688
689 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
690
691 -- Otherwise the pragma is illegal
692
693 else
694 Error_Msg_N ("wrong syntax for contract cases", N);
695 end if;
696
697 Set_Is_Analyzed_Pragma (N);
698
699 Restore_Ghost_Region (Saved_GM, Saved_IGR);
700 end Analyze_Contract_Cases_In_Decl_Part;
701
702 ----------------------------------
703 -- Analyze_Depends_In_Decl_Part --
704 ----------------------------------
705
706 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
707 Loc : constant Source_Ptr := Sloc (N);
708 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
709 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
710
711 All_Inputs_Seen : Elist_Id := No_Elist;
712 -- A list containing the entities of all the inputs processed so far.
713 -- The list is populated with unique entities because the same input
714 -- may appear in multiple input lists.
715
716 All_Outputs_Seen : Elist_Id := No_Elist;
717 -- A list containing the entities of all the outputs processed so far.
718 -- The list is populated with unique entities because output items are
719 -- unique in a dependence relation.
720
721 Constits_Seen : Elist_Id := No_Elist;
722 -- A list containing the entities of all constituents processed so far.
723 -- It aids in detecting illegal usage of a state and a corresponding
724 -- constituent in pragma [Refinde_]Depends.
725
726 Global_Seen : Boolean := False;
727 -- A flag set when pragma Global has been processed
728
729 Null_Output_Seen : Boolean := False;
730 -- A flag used to track the legality of a null output
731
732 Result_Seen : Boolean := False;
733 -- A flag set when Spec_Id'Result is processed
734
735 States_Seen : Elist_Id := No_Elist;
736 -- A list containing the entities of all states processed so far. It
737 -- helps in detecting illegal usage of a state and a corresponding
738 -- constituent in pragma [Refined_]Depends.
739
740 Subp_Inputs : Elist_Id := No_Elist;
741 Subp_Outputs : Elist_Id := No_Elist;
742 -- Two lists containing the full set of inputs and output of the related
743 -- subprograms. Note that these lists contain both nodes and entities.
744
745 Task_Input_Seen : Boolean := False;
746 Task_Output_Seen : Boolean := False;
747 -- Flags used to track the implicit dependence of a task unit on itself
748
749 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
750 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
751 -- to the name buffer. The individual kinds are as follows:
752 -- E_Abstract_State - "state"
753 -- E_Constant - "constant"
754 -- E_Generic_In_Out_Parameter - "generic parameter"
755 -- E_Generic_In_Parameter - "generic parameter"
756 -- E_In_Parameter - "parameter"
757 -- E_In_Out_Parameter - "parameter"
758 -- E_Loop_Parameter - "loop parameter"
759 -- E_Out_Parameter - "parameter"
760 -- E_Protected_Type - "current instance of protected type"
761 -- E_Task_Type - "current instance of task type"
762 -- E_Variable - "global"
763
764 procedure Analyze_Dependency_Clause
765 (Clause : Node_Id;
766 Is_Last : Boolean);
767 -- Verify the legality of a single dependency clause. Flag Is_Last
768 -- denotes whether Clause is the last clause in the relation.
769
770 procedure Check_Function_Return;
771 -- Verify that Funtion'Result appears as one of the outputs
772 -- (SPARK RM 6.1.5(10)).
773
774 procedure Check_Role
775 (Item : Node_Id;
776 Item_Id : Entity_Id;
777 Is_Input : Boolean;
778 Self_Ref : Boolean);
779 -- Ensure that an item fulfills its designated input and/or output role
780 -- as specified by pragma Global (if any) or the enclosing context. If
781 -- this is not the case, emit an error. Item and Item_Id denote the
782 -- attributes of an item. Flag Is_Input should be set when item comes
783 -- from an input list. Flag Self_Ref should be set when the item is an
784 -- output and the dependency clause has operator "+".
785
786 procedure Check_Usage
787 (Subp_Items : Elist_Id;
788 Used_Items : Elist_Id;
789 Is_Input : Boolean);
790 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
791 -- error if this is not the case.
792
793 procedure Normalize_Clause (Clause : Node_Id);
794 -- Remove a self-dependency "+" from the input list of a clause
795
796 -----------------------------
797 -- Add_Item_To_Name_Buffer --
798 -----------------------------
799
800 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
801 begin
802 if Ekind (Item_Id) = E_Abstract_State then
803 Add_Str_To_Name_Buffer ("state");
804
805 elsif Ekind (Item_Id) = E_Constant then
806 Add_Str_To_Name_Buffer ("constant");
807
808 elsif Is_Formal_Object (Item_Id) then
809 Add_Str_To_Name_Buffer ("generic parameter");
810
811 elsif Is_Formal (Item_Id) then
812 Add_Str_To_Name_Buffer ("parameter");
813
814 elsif Ekind (Item_Id) = E_Loop_Parameter then
815 Add_Str_To_Name_Buffer ("loop parameter");
816
817 elsif Ekind (Item_Id) = E_Protected_Type
818 or else Is_Single_Protected_Object (Item_Id)
819 then
820 Add_Str_To_Name_Buffer ("current instance of protected type");
821
822 elsif Ekind (Item_Id) = E_Task_Type
823 or else Is_Single_Task_Object (Item_Id)
824 then
825 Add_Str_To_Name_Buffer ("current instance of task type");
826
827 elsif Ekind (Item_Id) = E_Variable then
828 Add_Str_To_Name_Buffer ("global");
829
830 -- The routine should not be called with non-SPARK items
831
832 else
833 raise Program_Error;
834 end if;
835 end Add_Item_To_Name_Buffer;
836
837 -------------------------------
838 -- Analyze_Dependency_Clause --
839 -------------------------------
840
841 procedure Analyze_Dependency_Clause
842 (Clause : Node_Id;
843 Is_Last : Boolean)
844 is
845 procedure Analyze_Input_List (Inputs : Node_Id);
846 -- Verify the legality of a single input list
847
848 procedure Analyze_Input_Output
849 (Item : Node_Id;
850 Is_Input : Boolean;
851 Self_Ref : Boolean;
852 Top_Level : Boolean;
853 Seen : in out Elist_Id;
854 Null_Seen : in out Boolean;
855 Non_Null_Seen : in out Boolean);
856 -- Verify the legality of a single input or output item. Flag
857 -- Is_Input should be set whenever Item is an input, False when it
858 -- denotes an output. Flag Self_Ref should be set when the item is an
859 -- output and the dependency clause has a "+". Flag Top_Level should
860 -- be set whenever Item appears immediately within an input or output
861 -- list. Seen is a collection of all abstract states, objects and
862 -- formals processed so far. Flag Null_Seen denotes whether a null
863 -- input or output has been encountered. Flag Non_Null_Seen denotes
864 -- whether a non-null input or output has been encountered.
865
866 ------------------------
867 -- Analyze_Input_List --
868 ------------------------
869
870 procedure Analyze_Input_List (Inputs : Node_Id) is
871 Inputs_Seen : Elist_Id := No_Elist;
872 -- A list containing the entities of all inputs that appear in the
873 -- current input list.
874
875 Non_Null_Input_Seen : Boolean := False;
876 Null_Input_Seen : Boolean := False;
877 -- Flags used to check the legality of an input list
878
879 Input : Node_Id;
880
881 begin
882 -- Multiple inputs appear as an aggregate
883
884 if Nkind (Inputs) = N_Aggregate then
885 if Present (Component_Associations (Inputs)) then
886 SPARK_Msg_N
887 ("nested dependency relations not allowed", Inputs);
888
889 elsif Present (Expressions (Inputs)) then
890 Input := First (Expressions (Inputs));
891 while Present (Input) loop
892 Analyze_Input_Output
893 (Item => Input,
894 Is_Input => True,
895 Self_Ref => False,
896 Top_Level => False,
897 Seen => Inputs_Seen,
898 Null_Seen => Null_Input_Seen,
899 Non_Null_Seen => Non_Null_Input_Seen);
900
901 Next (Input);
902 end loop;
903
904 -- Syntax error, always report
905
906 else
907 Error_Msg_N ("malformed input dependency list", Inputs);
908 end if;
909
910 -- Process a solitary input
911
912 else
913 Analyze_Input_Output
914 (Item => Inputs,
915 Is_Input => True,
916 Self_Ref => False,
917 Top_Level => False,
918 Seen => Inputs_Seen,
919 Null_Seen => Null_Input_Seen,
920 Non_Null_Seen => Non_Null_Input_Seen);
921 end if;
922
923 -- Detect an illegal dependency clause of the form
924
925 -- (null =>[+] null)
926
927 if Null_Output_Seen and then Null_Input_Seen then
928 SPARK_Msg_N
929 ("null dependency clause cannot have a null input list",
930 Inputs);
931 end if;
932 end Analyze_Input_List;
933
934 --------------------------
935 -- Analyze_Input_Output --
936 --------------------------
937
938 procedure Analyze_Input_Output
939 (Item : Node_Id;
940 Is_Input : Boolean;
941 Self_Ref : Boolean;
942 Top_Level : Boolean;
943 Seen : in out Elist_Id;
944 Null_Seen : in out Boolean;
945 Non_Null_Seen : in out Boolean)
946 is
947 procedure Current_Task_Instance_Seen;
948 -- Set the appropriate global flag when the current instance of a
949 -- task unit is encountered.
950
951 --------------------------------
952 -- Current_Task_Instance_Seen --
953 --------------------------------
954
955 procedure Current_Task_Instance_Seen is
956 begin
957 if Is_Input then
958 Task_Input_Seen := True;
959 else
960 Task_Output_Seen := True;
961 end if;
962 end Current_Task_Instance_Seen;
963
964 -- Local variables
965
966 Is_Output : constant Boolean := not Is_Input;
967 Grouped : Node_Id;
968 Item_Id : Entity_Id;
969
970 -- Start of processing for Analyze_Input_Output
971
972 begin
973 -- Multiple input or output items appear as an aggregate
974
975 if Nkind (Item) = N_Aggregate then
976 if not Top_Level then
977 SPARK_Msg_N ("nested grouping of items not allowed", Item);
978
979 elsif Present (Component_Associations (Item)) then
980 SPARK_Msg_N
981 ("nested dependency relations not allowed", Item);
982
983 -- Recursively analyze the grouped items
984
985 elsif Present (Expressions (Item)) then
986 Grouped := First (Expressions (Item));
987 while Present (Grouped) loop
988 Analyze_Input_Output
989 (Item => Grouped,
990 Is_Input => Is_Input,
991 Self_Ref => Self_Ref,
992 Top_Level => False,
993 Seen => Seen,
994 Null_Seen => Null_Seen,
995 Non_Null_Seen => Non_Null_Seen);
996
997 Next (Grouped);
998 end loop;
999
1000 -- Syntax error, always report
1001
1002 else
1003 Error_Msg_N ("malformed dependency list", Item);
1004 end if;
1005
1006 -- Process attribute 'Result in the context of a dependency clause
1007
1008 elsif Is_Attribute_Result (Item) then
1009 Non_Null_Seen := True;
1010
1011 Analyze (Item);
1012
1013 -- Attribute 'Result is allowed to appear on the output side of
1014 -- a dependency clause (SPARK RM 6.1.5(6)).
1015
1016 if Is_Input then
1017 SPARK_Msg_N ("function result cannot act as input", Item);
1018
1019 elsif Null_Seen then
1020 SPARK_Msg_N
1021 ("cannot mix null and non-null dependency items", Item);
1022
1023 else
1024 Result_Seen := True;
1025 end if;
1026
1027 -- Detect multiple uses of null in a single dependency list or
1028 -- throughout the whole relation. Verify the placement of a null
1029 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
1030
1031 elsif Nkind (Item) = N_Null then
1032 if Null_Seen then
1033 SPARK_Msg_N
1034 ("multiple null dependency relations not allowed", Item);
1035
1036 elsif Non_Null_Seen then
1037 SPARK_Msg_N
1038 ("cannot mix null and non-null dependency items", Item);
1039
1040 else
1041 Null_Seen := True;
1042
1043 if Is_Output then
1044 if not Is_Last then
1045 SPARK_Msg_N
1046 ("null output list must be the last clause in a "
1047 & "dependency relation", Item);
1048
1049 -- Catch a useless dependence of the form:
1050 -- null =>+ ...
1051
1052 elsif Self_Ref then
1053 SPARK_Msg_N
1054 ("useless dependence, null depends on itself", Item);
1055 end if;
1056 end if;
1057 end if;
1058
1059 -- Default case
1060
1061 else
1062 Non_Null_Seen := True;
1063
1064 if Null_Seen then
1065 SPARK_Msg_N ("cannot mix null and non-null items", Item);
1066 end if;
1067
1068 Analyze (Item);
1069 Resolve_State (Item);
1070
1071 -- Find the entity of the item. If this is a renaming, climb
1072 -- the renaming chain to reach the root object. Renamings of
1073 -- non-entire objects do not yield an entity (Empty).
1074
1075 Item_Id := Entity_Of (Item);
1076
1077 if Present (Item_Id) then
1078
1079 -- Constants
1080
1081 if Ekind (Item_Id) in E_Constant | E_Loop_Parameter
1082 or else
1083
1084 -- Current instances of concurrent types
1085
1086 Ekind (Item_Id) in E_Protected_Type | E_Task_Type
1087 or else
1088
1089 -- Formal parameters
1090
1091 Ekind (Item_Id) in E_Generic_In_Out_Parameter
1092 | E_Generic_In_Parameter
1093 | E_In_Parameter
1094 | E_In_Out_Parameter
1095 | E_Out_Parameter
1096 or else
1097
1098 -- States, variables
1099
1100 Ekind (Item_Id) in E_Abstract_State | E_Variable
1101 then
1102 -- A [generic] function is not allowed to have Output
1103 -- items in its dependency relations. Note that "null"
1104 -- and attribute 'Result are still valid items.
1105
1106 if Ekind (Spec_Id) in E_Function | E_Generic_Function
1107 and then not Is_Function_With_Side_Effects (Spec_Id)
1108 and then not Is_Input
1109 then
1110 Error_Msg_Code :=
1111 GEC_Output_In_Function_Global_Or_Depends;
1112 SPARK_Msg_N
1113 ("output item is not applicable to function '[[]']",
1114 Item);
1115 end if;
1116
1117 -- The item denotes a concurrent type. Note that single
1118 -- protected/task types are not considered here because
1119 -- they behave as objects in the context of pragma
1120 -- [Refined_]Depends.
1121
1122 if Ekind (Item_Id) in E_Protected_Type | E_Task_Type then
1123
1124 -- This use is legal as long as the concurrent type is
1125 -- the current instance of an enclosing type.
1126
1127 if Is_CCT_Instance (Item_Id, Spec_Id) then
1128
1129 -- The dependence of a task unit on itself is
1130 -- implicit and may or may not be explicitly
1131 -- specified (SPARK RM 6.1.4).
1132
1133 if Ekind (Item_Id) = E_Task_Type then
1134 Current_Task_Instance_Seen;
1135 end if;
1136
1137 -- Otherwise this is not the current instance
1138
1139 else
1140 SPARK_Msg_N
1141 ("invalid use of subtype mark in dependency "
1142 & "relation", Item);
1143 end if;
1144
1145 -- The dependency of a task unit on itself is implicit
1146 -- and may or may not be explicitly specified
1147 -- (SPARK RM 6.1.4).
1148
1149 elsif Is_Single_Task_Object (Item_Id)
1150 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
1151 then
1152 Current_Task_Instance_Seen;
1153 end if;
1154
1155 -- Ensure that the item fulfills its role as input and/or
1156 -- output as specified by pragma Global or the enclosing
1157 -- context.
1158
1159 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
1160
1161 -- Detect multiple uses of the same state, variable or
1162 -- formal parameter. If this is not the case, add the
1163 -- item to the list of processed relations.
1164
1165 if Contains (Seen, Item_Id) then
1166 SPARK_Msg_NE
1167 ("duplicate use of item &", Item, Item_Id);
1168 else
1169 Append_New_Elmt (Item_Id, Seen);
1170 end if;
1171
1172 -- Detect illegal use of an input related to a null
1173 -- output. Such input items cannot appear in other
1174 -- input lists (SPARK RM 6.1.5(13)).
1175
1176 if Is_Input
1177 and then Null_Output_Seen
1178 and then Contains (All_Inputs_Seen, Item_Id)
1179 then
1180 SPARK_Msg_N
1181 ("input of a null output list cannot appear in "
1182 & "multiple input lists", Item);
1183 end if;
1184
1185 -- Add an input or a self-referential output to the list
1186 -- of all processed inputs.
1187
1188 if Is_Input or else Self_Ref then
1189 Append_New_Elmt (Item_Id, All_Inputs_Seen);
1190 end if;
1191
1192 -- State related checks (SPARK RM 6.1.5(3))
1193
1194 if Ekind (Item_Id) = E_Abstract_State then
1195
1196 -- Package and subprogram bodies are instantiated
1197 -- individually in a separate compiler pass. Due to
1198 -- this mode of instantiation, the refinement of a
1199 -- state may no longer be visible when a subprogram
1200 -- body contract is instantiated. Since the generic
1201 -- template is legal, do not perform this check in
1202 -- the instance to circumvent this oddity.
1203
1204 if In_Instance then
1205 null;
1206
1207 -- An abstract state with visible refinement cannot
1208 -- appear in pragma [Refined_]Depends as its place
1209 -- must be taken by some of its constituents
1210 -- (SPARK RM 6.1.4(7)).
1211
1212 elsif Has_Visible_Refinement (Item_Id) then
1213 SPARK_Msg_NE
1214 ("cannot mention state & in dependence relation",
1215 Item, Item_Id);
1216 SPARK_Msg_N ("\use its constituents instead", Item);
1217 return;
1218
1219 -- If the reference to the abstract state appears in
1220 -- an enclosing package body that will eventually
1221 -- refine the state, record the reference for future
1222 -- checks.
1223
1224 else
1225 Record_Possible_Body_Reference
1226 (State_Id => Item_Id,
1227 Ref => Item);
1228 end if;
1229
1230 elsif Ekind (Item_Id) in E_Constant | E_Variable
1231 and then Present (Ultimate_Overlaid_Entity (Item_Id))
1232 then
1233 SPARK_Msg_NE
1234 ("overlaying object & cannot appear in Depends",
1235 Item, Item_Id);
1236 SPARK_Msg_NE
1237 ("\use the overlaid object & instead",
1238 Item, Ultimate_Overlaid_Entity (Item_Id));
1239 return;
1240 end if;
1241
1242 -- When the item renames an entire object, replace the
1243 -- item with a reference to the object.
1244
1245 if Entity (Item) /= Item_Id then
1246 Rewrite (Item,
1247 New_Occurrence_Of (Item_Id, Sloc (Item)));
1248 Analyze (Item);
1249 end if;
1250
1251 -- Add the entity of the current item to the list of
1252 -- processed items.
1253
1254 if Ekind (Item_Id) = E_Abstract_State then
1255 Append_New_Elmt (Item_Id, States_Seen);
1256
1257 -- The variable may eventually become a constituent of a
1258 -- single protected/task type. Record the reference now
1259 -- and verify its legality when analyzing the contract of
1260 -- the variable (SPARK RM 9.3).
1261
1262 elsif Ekind (Item_Id) = E_Variable then
1263 Record_Possible_Part_Of_Reference
1264 (Var_Id => Item_Id,
1265 Ref => Item);
1266 end if;
1267
1268 if Ekind (Item_Id) in E_Abstract_State
1269 | E_Constant
1270 | E_Variable
1271 and then Present (Encapsulating_State (Item_Id))
1272 then
1273 Append_New_Elmt (Item_Id, Constits_Seen);
1274 end if;
1275
1276 -- All other input/output items are illegal
1277 -- (SPARK RM 6.1.5(1)).
1278
1279 else
1280 SPARK_Msg_N
1281 ("item must denote parameter, variable, state or "
1282 & "current instance of concurrent type", Item);
1283 end if;
1284
1285 -- All other input/output items are illegal
1286 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1287
1288 else
1289 Error_Msg_N
1290 ("item must denote parameter, variable, state or current "
1291 & "instance of concurrent type", Item);
1292 end if;
1293 end if;
1294 end Analyze_Input_Output;
1295
1296 -- Local variables
1297
1298 Inputs : Node_Id;
1299 Output : Node_Id;
1300 Self_Ref : Boolean;
1301
1302 Non_Null_Output_Seen : Boolean := False;
1303 -- Flag used to check the legality of an output list
1304
1305 -- Start of processing for Analyze_Dependency_Clause
1306
1307 begin
1308 Inputs := Expression (Clause);
1309 Self_Ref := False;
1310
1311 -- An input list with a self-dependency appears as operator "+" where
1312 -- the actuals inputs are the right operand.
1313
1314 if Nkind (Inputs) = N_Op_Plus then
1315 Inputs := Right_Opnd (Inputs);
1316 Self_Ref := True;
1317 end if;
1318
1319 -- Process the output_list of a dependency_clause
1320
1321 Output := First (Choices (Clause));
1322 while Present (Output) loop
1323 Analyze_Input_Output
1324 (Item => Output,
1325 Is_Input => False,
1326 Self_Ref => Self_Ref,
1327 Top_Level => True,
1328 Seen => All_Outputs_Seen,
1329 Null_Seen => Null_Output_Seen,
1330 Non_Null_Seen => Non_Null_Output_Seen);
1331
1332 Next (Output);
1333 end loop;
1334
1335 -- Process the input_list of a dependency_clause
1336
1337 Analyze_Input_List (Inputs);
1338 end Analyze_Dependency_Clause;
1339
1340 ---------------------------
1341 -- Check_Function_Return --
1342 ---------------------------
1343
1344 procedure Check_Function_Return is
1345 begin
1346 if Ekind (Spec_Id) in E_Function | E_Generic_Function
1347 and then not Result_Seen
1348 then
1349 SPARK_Msg_NE
1350 ("result of & must appear in exactly one output list",
1351 N, Spec_Id);
1352 end if;
1353 end Check_Function_Return;
1354
1355 ----------------
1356 -- Check_Role --
1357 ----------------
1358
1359 procedure Check_Role
1360 (Item : Node_Id;
1361 Item_Id : Entity_Id;
1362 Is_Input : Boolean;
1363 Self_Ref : Boolean)
1364 is
1365 procedure Find_Role
1366 (Item_Is_Input : out Boolean;
1367 Item_Is_Output : out Boolean);
1368 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1369 -- Item_Is_Output are set depending on the role.
1370
1371 procedure Role_Error
1372 (Item_Is_Input : Boolean;
1373 Item_Is_Output : Boolean);
1374 -- Emit an error message concerning the incorrect use of Item in
1375 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1376 -- denote whether the item is an input and/or an output.
1377
1378 ---------------
1379 -- Find_Role --
1380 ---------------
1381
1382 procedure Find_Role
1383 (Item_Is_Input : out Boolean;
1384 Item_Is_Output : out Boolean)
1385 is
1386 -- A constant or an IN parameter of a protected entry, procedure,
1387 -- or function with side-effects, if it is of an
1388 -- access-to-variable type, should be handled like a variable, as
1389 -- the underlying memory pointed-to can be modified. Use
1390 -- Adjusted_Kind to do this adjustment.
1391
1392 Adjusted_Kind : Entity_Kind := Ekind (Item_Id);
1393
1394 begin
1395 if (Ekind (Item_Id) in E_Constant | E_Generic_In_Parameter
1396 or else
1397 (Ekind (Item_Id) = E_In_Parameter
1398 and then
1399 (Ekind (Scope (Item_Id)) not in E_Function
1400 | E_Generic_Function
1401 or else
1402 Is_Function_With_Side_Effects (Scope (Item_Id)))))
1403 and then Is_Access_Variable (Etype (Item_Id))
1404 and then (Ekind (Spec_Id) not in E_Function
1405 | E_Generic_Function
1406 or else Is_Function_With_Side_Effects (Spec_Id))
1407 then
1408 Adjusted_Kind := E_Variable;
1409 end if;
1410
1411 case Adjusted_Kind is
1412
1413 -- Abstract states
1414
1415 when E_Abstract_State =>
1416
1417 -- When pragma Global is present it determines the mode of
1418 -- the abstract state.
1419
1420 if Global_Seen then
1421 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1422 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1423
1424 -- Otherwise the state has a default IN OUT mode, because it
1425 -- behaves as a variable.
1426
1427 else
1428 Item_Is_Input := True;
1429 Item_Is_Output := True;
1430 end if;
1431
1432 -- Constants and IN parameters
1433
1434 when E_Constant
1435 | E_Generic_In_Parameter
1436 | E_In_Parameter
1437 | E_Loop_Parameter
1438 =>
1439 -- When pragma Global is present it determines the mode
1440 -- of constant objects as inputs (and such objects cannot
1441 -- appear as outputs in the Global contract).
1442
1443 if Global_Seen then
1444 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1445 else
1446 Item_Is_Input := True;
1447 end if;
1448
1449 Item_Is_Output := False;
1450
1451 -- Variables and IN OUT parameters, as well as constants and
1452 -- IN parameters of access type which are handled like
1453 -- variables.
1454
1455 when E_Generic_In_Out_Parameter
1456 | E_In_Out_Parameter
1457 | E_Out_Parameter
1458 | E_Variable
1459 =>
1460 -- An OUT parameter of the related subprogram; it cannot
1461 -- appear in Global.
1462
1463 if Adjusted_Kind = E_Out_Parameter
1464 and then Scope (Item_Id) = Spec_Id
1465 then
1466
1467 -- The parameter has mode IN if its type is unconstrained
1468 -- or tagged because array bounds, discriminants or tags
1469 -- can be read.
1470
1471 Item_Is_Input :=
1472 Is_Unconstrained_Or_Tagged_Item (Item_Id);
1473
1474 Item_Is_Output := True;
1475
1476 -- A parameter of an enclosing subprogram; it can appear
1477 -- in Global and behaves as a read-write variable.
1478
1479 else
1480 -- When pragma Global is present it determines the mode
1481 -- of the object.
1482
1483 if Global_Seen then
1484
1485 -- A variable has mode IN when its type is
1486 -- unconstrained or tagged because array bounds,
1487 -- discriminants, or tags can be read.
1488
1489 Item_Is_Input :=
1490 Appears_In (Subp_Inputs, Item_Id)
1491 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1492
1493 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1494
1495 -- Otherwise the variable has a default IN OUT mode
1496
1497 else
1498 Item_Is_Input := True;
1499 Item_Is_Output := True;
1500 end if;
1501 end if;
1502
1503 -- Protected types
1504
1505 when E_Protected_Type =>
1506 if Global_Seen then
1507
1508 -- A variable has mode IN when its type is unconstrained
1509 -- or tagged because array bounds, discriminants or tags
1510 -- can be read.
1511
1512 Item_Is_Input :=
1513 Appears_In (Subp_Inputs, Item_Id)
1514 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1515
1516 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1517
1518 else
1519 -- A protected type acts as a formal parameter of mode IN
1520 -- when it applies to a protected function.
1521
1522 if Ekind (Spec_Id) = E_Function then
1523 Item_Is_Input := True;
1524 Item_Is_Output := False;
1525
1526 -- Otherwise the protected type acts as a formal of mode
1527 -- IN OUT.
1528
1529 else
1530 Item_Is_Input := True;
1531 Item_Is_Output := True;
1532 end if;
1533 end if;
1534
1535 -- Task types
1536
1537 when E_Task_Type =>
1538
1539 -- When pragma Global is present it determines the mode of
1540 -- the object.
1541
1542 if Global_Seen then
1543 Item_Is_Input :=
1544 Appears_In (Subp_Inputs, Item_Id)
1545 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1546
1547 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1548
1549 -- Otherwise task types act as IN OUT parameters
1550
1551 else
1552 Item_Is_Input := True;
1553 Item_Is_Output := True;
1554 end if;
1555
1556 when others =>
1557 raise Program_Error;
1558 end case;
1559 end Find_Role;
1560
1561 ----------------
1562 -- Role_Error --
1563 ----------------
1564
1565 procedure Role_Error
1566 (Item_Is_Input : Boolean;
1567 Item_Is_Output : Boolean)
1568 is
1569 begin
1570 Name_Len := 0;
1571
1572 -- When the item is not part of the input and the output set of
1573 -- the related subprogram, then it appears as extra in pragma
1574 -- [Refined_]Depends.
1575
1576 if not Item_Is_Input and then not Item_Is_Output then
1577 Add_Item_To_Name_Buffer (Item_Id);
1578 Add_Str_To_Name_Buffer
1579 (" & cannot appear in dependence relation");
1580
1581 SPARK_Msg_NE (To_String (Global_Name_Buffer), Item, Item_Id);
1582
1583 Error_Msg_Name_1 := Chars (Spec_Id);
1584 SPARK_Msg_NE
1585 (Fix_Msg (Spec_Id, "\& is not part of the input or output "
1586 & "set of subprogram %"), Item, Item_Id);
1587
1588 -- The mode of the item and its role in pragma [Refined_]Depends
1589 -- are in conflict. Construct a detailed message explaining the
1590 -- illegality (SPARK RM 6.1.5(5-6)).
1591
1592 else
1593 if Item_Is_Input then
1594 Add_Str_To_Name_Buffer ("read-only");
1595 else
1596 Add_Str_To_Name_Buffer ("write-only");
1597 end if;
1598
1599 Add_Char_To_Name_Buffer (' ');
1600 Add_Item_To_Name_Buffer (Item_Id);
1601 Add_Str_To_Name_Buffer (" & cannot appear as ");
1602
1603 if Item_Is_Input then
1604 Add_Str_To_Name_Buffer ("output");
1605 else
1606 Add_Str_To_Name_Buffer ("input");
1607 end if;
1608
1609 Add_Str_To_Name_Buffer (" in dependence relation");
1610
1611 SPARK_Msg_NE (To_String (Global_Name_Buffer), Item, Item_Id);
1612 end if;
1613 end Role_Error;
1614
1615 -- Local variables
1616
1617 Item_Is_Input : Boolean;
1618 Item_Is_Output : Boolean;
1619
1620 -- Start of processing for Check_Role
1621
1622 begin
1623 Find_Role (Item_Is_Input, Item_Is_Output);
1624
1625 -- Input item
1626
1627 if Is_Input then
1628 if not Item_Is_Input then
1629 Role_Error (Item_Is_Input, Item_Is_Output);
1630 end if;
1631
1632 -- Self-referential item
1633
1634 elsif Self_Ref then
1635 if not Item_Is_Input or else not Item_Is_Output then
1636 Role_Error (Item_Is_Input, Item_Is_Output);
1637 end if;
1638
1639 -- Output item
1640
1641 elsif not Item_Is_Output then
1642 Role_Error (Item_Is_Input, Item_Is_Output);
1643 end if;
1644 end Check_Role;
1645
1646 -----------------
1647 -- Check_Usage --
1648 -----------------
1649
1650 procedure Check_Usage
1651 (Subp_Items : Elist_Id;
1652 Used_Items : Elist_Id;
1653 Is_Input : Boolean)
1654 is
1655 procedure Usage_Error (Item_Id : Entity_Id);
1656 -- Emit an error concerning the illegal usage of an item
1657
1658 -----------------
1659 -- Usage_Error --
1660 -----------------
1661
1662 procedure Usage_Error (Item_Id : Entity_Id) is
1663 begin
1664 -- Input case
1665
1666 if Is_Input then
1667
1668 -- Unconstrained and tagged items are not part of the explicit
1669 -- input set of the related subprogram, they do not have to be
1670 -- present in a dependence relation and should not be flagged
1671 -- (SPARK RM 6.1.5(5)).
1672
1673 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1674 Name_Len := 0;
1675
1676 Add_Item_To_Name_Buffer (Item_Id);
1677 Add_Str_To_Name_Buffer
1678 (" & is missing from input dependence list");
1679
1680 SPARK_Msg_NE (To_String (Global_Name_Buffer), N, Item_Id);
1681 SPARK_Msg_NE
1682 ("\add `null ='> &` dependency to ignore this input",
1683 N, Item_Id);
1684 end if;
1685
1686 -- Output case (SPARK RM 6.1.5(10))
1687
1688 else
1689 Name_Len := 0;
1690
1691 Add_Item_To_Name_Buffer (Item_Id);
1692 Add_Str_To_Name_Buffer
1693 (" & is missing from output dependence list");
1694
1695 SPARK_Msg_NE (To_String (Global_Name_Buffer), N, Item_Id);
1696 end if;
1697 end Usage_Error;
1698
1699 -- Local variables
1700
1701 Elmt : Elmt_Id;
1702 Item : Node_Id;
1703 Item_Id : Entity_Id;
1704
1705 -- Start of processing for Check_Usage
1706
1707 begin
1708 if No (Subp_Items) then
1709 return;
1710 end if;
1711
1712 -- Each input or output of the subprogram must appear in a dependency
1713 -- relation.
1714
1715 Elmt := First_Elmt (Subp_Items);
1716 while Present (Elmt) loop
1717 Item := Node (Elmt);
1718
1719 if Nkind (Item) = N_Defining_Identifier then
1720 Item_Id := Item;
1721 else
1722 Item_Id := Entity_Of (Item);
1723 end if;
1724
1725 -- The item does not appear in a dependency
1726
1727 if Present (Item_Id)
1728 and then not Contains (Used_Items, Item_Id)
1729 then
1730 if Is_Formal (Item_Id) then
1731 Usage_Error (Item_Id);
1732
1733 -- The current instance of a protected type behaves as a formal
1734 -- parameter (SPARK RM 6.1.4).
1735
1736 elsif Ekind (Item_Id) = E_Protected_Type
1737 or else Is_Single_Protected_Object (Item_Id)
1738 then
1739 Usage_Error (Item_Id);
1740
1741 -- The current instance of a task type behaves as a formal
1742 -- parameter (SPARK RM 6.1.4).
1743
1744 elsif Ekind (Item_Id) = E_Task_Type
1745 or else Is_Single_Task_Object (Item_Id)
1746 then
1747 -- The dependence of a task unit on itself is implicit and
1748 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1749 -- Emit an error if only one input/output is present.
1750
1751 if Task_Input_Seen /= Task_Output_Seen then
1752 Usage_Error (Item_Id);
1753 end if;
1754
1755 -- States and global objects are not used properly only when
1756 -- the subprogram is subject to pragma Global.
1757
1758 elsif Global_Seen
1759 and then Ekind (Item_Id) in E_Abstract_State
1760 | E_Constant
1761 | E_Loop_Parameter
1762 | E_Protected_Type
1763 | E_Task_Type
1764 | E_Variable
1765 | Formal_Kind
1766 then
1767 Usage_Error (Item_Id);
1768 end if;
1769 end if;
1770
1771 Next_Elmt (Elmt);
1772 end loop;
1773 end Check_Usage;
1774
1775 ----------------------
1776 -- Normalize_Clause --
1777 ----------------------
1778
1779 procedure Normalize_Clause (Clause : Node_Id) is
1780 procedure Create_Or_Modify_Clause
1781 (Output : Node_Id;
1782 Outputs : Node_Id;
1783 Inputs : Node_Id;
1784 After : Node_Id;
1785 In_Place : Boolean;
1786 Multiple : Boolean);
1787 -- Create a brand new clause to represent the self-reference or
1788 -- modify the input and/or output lists of an existing clause. Output
1789 -- denotes a self-referencial output. Outputs is the output list of a
1790 -- clause. Inputs is the input list of a clause. After denotes the
1791 -- clause after which the new clause is to be inserted. Flag In_Place
1792 -- should be set when normalizing the last output of an output list.
1793 -- Flag Multiple should be set when Output comes from a list with
1794 -- multiple items.
1795
1796 -----------------------------
1797 -- Create_Or_Modify_Clause --
1798 -----------------------------
1799
1800 procedure Create_Or_Modify_Clause
1801 (Output : Node_Id;
1802 Outputs : Node_Id;
1803 Inputs : Node_Id;
1804 After : Node_Id;
1805 In_Place : Boolean;
1806 Multiple : Boolean)
1807 is
1808 procedure Propagate_Output
1809 (Output : Node_Id;
1810 Inputs : Node_Id);
1811 -- Handle the various cases of output propagation to the input
1812 -- list. Output denotes a self-referencial output item. Inputs
1813 -- is the input list of a clause.
1814
1815 ----------------------
1816 -- Propagate_Output --
1817 ----------------------
1818
1819 procedure Propagate_Output
1820 (Output : Node_Id;
1821 Inputs : Node_Id)
1822 is
1823 function In_Input_List
1824 (Item : Entity_Id;
1825 Inputs : List_Id) return Boolean;
1826 -- Determine whether a particulat item appears in the input
1827 -- list of a clause.
1828
1829 -------------------
1830 -- In_Input_List --
1831 -------------------
1832
1833 function In_Input_List
1834 (Item : Entity_Id;
1835 Inputs : List_Id) return Boolean
1836 is
1837 Elmt : Node_Id;
1838
1839 begin
1840 Elmt := First (Inputs);
1841 while Present (Elmt) loop
1842 if Entity_Of (Elmt) = Item then
1843 return True;
1844 end if;
1845
1846 Next (Elmt);
1847 end loop;
1848
1849 return False;
1850 end In_Input_List;
1851
1852 -- Local variables
1853
1854 Output_Id : constant Entity_Id := Entity_Of (Output);
1855 Grouped : List_Id;
1856
1857 -- Start of processing for Propagate_Output
1858
1859 begin
1860 -- The clause is of the form:
1861
1862 -- (Output =>+ null)
1863
1864 -- Remove null input and replace it with a copy of the output:
1865
1866 -- (Output => Output)
1867
1868 if Nkind (Inputs) = N_Null then
1869 Rewrite (Inputs, New_Copy_Tree (Output));
1870
1871 -- The clause is of the form:
1872
1873 -- (Output =>+ (Input1, ..., InputN))
1874
1875 -- Determine whether the output is not already mentioned in the
1876 -- input list and if not, add it to the list of inputs:
1877
1878 -- (Output => (Output, Input1, ..., InputN))
1879
1880 elsif Nkind (Inputs) = N_Aggregate then
1881 Grouped := Expressions (Inputs);
1882
1883 if not In_Input_List
1884 (Item => Output_Id,
1885 Inputs => Grouped)
1886 then
1887 Prepend_To (Grouped, New_Copy_Tree (Output));
1888 end if;
1889
1890 -- The clause is of the form:
1891
1892 -- (Output =>+ Input)
1893
1894 -- If the input does not mention the output, group the two
1895 -- together:
1896
1897 -- (Output => (Output, Input))
1898
1899 elsif Entity_Of (Inputs) /= Output_Id then
1900 Rewrite (Inputs,
1901 Make_Aggregate (Loc,
1902 Expressions => New_List (
1903 New_Copy_Tree (Output),
1904 New_Copy_Tree (Inputs))));
1905 end if;
1906 end Propagate_Output;
1907
1908 -- Local variables
1909
1910 Loc : constant Source_Ptr := Sloc (Clause);
1911 New_Clause : Node_Id;
1912
1913 -- Start of processing for Create_Or_Modify_Clause
1914
1915 begin
1916 -- A null output depending on itself does not require any
1917 -- normalization.
1918
1919 if Nkind (Output) = N_Null then
1920 return;
1921
1922 -- A function result cannot depend on itself because it cannot
1923 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1924
1925 elsif Is_Attribute_Result (Output) then
1926 SPARK_Msg_N ("function result cannot depend on itself", Output);
1927 return;
1928 end if;
1929
1930 -- When performing the transformation in place, simply add the
1931 -- output to the list of inputs (if not already there). This
1932 -- case arises when dealing with the last output of an output
1933 -- list. Perform the normalization in place to avoid generating
1934 -- a malformed tree.
1935
1936 if In_Place then
1937 Propagate_Output (Output, Inputs);
1938
1939 -- A list with multiple outputs is slowly trimmed until only
1940 -- one element remains. When this happens, replace aggregate
1941 -- with the element itself.
1942
1943 if Multiple then
1944 Remove (Output);
1945 Rewrite (Outputs, Output);
1946 end if;
1947
1948 -- Default case
1949
1950 else
1951 -- Unchain the output from its output list as it will appear in
1952 -- a new clause. Note that we cannot simply rewrite the output
1953 -- as null because this will violate the semantics of pragma
1954 -- Depends.
1955
1956 Remove (Output);
1957
1958 -- Generate a new clause of the form:
1959 -- (Output => Inputs)
1960
1961 New_Clause :=
1962 Make_Component_Association (Loc,
1963 Choices => New_List (Output),
1964 Expression => New_Copy_Tree (Inputs));
1965
1966 -- The new clause contains replicated content that has already
1967 -- been analyzed. There is not need to reanalyze or renormalize
1968 -- it again.
1969
1970 Set_Analyzed (New_Clause);
1971
1972 Propagate_Output
1973 (Output => First (Choices (New_Clause)),
1974 Inputs => Expression (New_Clause));
1975
1976 Insert_After (After, New_Clause);
1977 end if;
1978 end Create_Or_Modify_Clause;
1979
1980 -- Local variables
1981
1982 Outputs : constant Node_Id := First (Choices (Clause));
1983 Inputs : Node_Id;
1984 Last_Output : Node_Id;
1985 Next_Output : Node_Id;
1986 Output : Node_Id;
1987
1988 -- Start of processing for Normalize_Clause
1989
1990 begin
1991 -- A self-dependency appears as operator "+". Remove the "+" from the
1992 -- tree by moving the real inputs to their proper place.
1993
1994 if Nkind (Expression (Clause)) = N_Op_Plus then
1995 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1996 Inputs := Expression (Clause);
1997
1998 -- Multiple outputs appear as an aggregate
1999
2000 if Nkind (Outputs) = N_Aggregate then
2001 Last_Output := Last (Expressions (Outputs));
2002
2003 Output := First (Expressions (Outputs));
2004 while Present (Output) loop
2005
2006 -- Normalization may remove an output from its list,
2007 -- preserve the subsequent output now.
2008
2009 Next_Output := Next (Output);
2010
2011 Create_Or_Modify_Clause
2012 (Output => Output,
2013 Outputs => Outputs,
2014 Inputs => Inputs,
2015 After => Clause,
2016 In_Place => Output = Last_Output,
2017 Multiple => True);
2018
2019 Output := Next_Output;
2020 end loop;
2021
2022 -- Solitary output
2023
2024 else
2025 Create_Or_Modify_Clause
2026 (Output => Outputs,
2027 Outputs => Empty,
2028 Inputs => Inputs,
2029 After => Empty,
2030 In_Place => True,
2031 Multiple => False);
2032 end if;
2033 end if;
2034 end Normalize_Clause;
2035
2036 -- Local variables
2037
2038 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2039 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2040
2041 Clause : Node_Id;
2042 Errors : Nat;
2043 Last_Clause : Node_Id;
2044 Restore_Scope : Boolean := False;
2045
2046 -- Start of processing for Analyze_Depends_In_Decl_Part
2047
2048 begin
2049 -- Do not analyze the pragma multiple times
2050
2051 if Is_Analyzed_Pragma (N) then
2052 return;
2053 end if;
2054
2055 -- Empty dependency list
2056
2057 if Nkind (Deps) = N_Null then
2058
2059 -- Gather all states, objects and formal parameters that the
2060 -- subprogram may depend on. These items are obtained from the
2061 -- parameter profile or pragma [Refined_]Global (if available).
2062
2063 Collect_Subprogram_Inputs_Outputs
2064 (Subp_Id => Subp_Id,
2065 Subp_Inputs => Subp_Inputs,
2066 Subp_Outputs => Subp_Outputs,
2067 Global_Seen => Global_Seen);
2068
2069 -- Verify that every input or output of the subprogram appear in a
2070 -- dependency.
2071
2072 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
2073 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
2074 Check_Function_Return;
2075
2076 -- Dependency clauses appear as component associations of an aggregate
2077
2078 elsif Nkind (Deps) = N_Aggregate then
2079
2080 -- Do not attempt to perform analysis of a syntactically illegal
2081 -- clause as this will lead to misleading errors.
2082
2083 if Has_Extra_Parentheses (Deps) then
2084 goto Leave;
2085 end if;
2086
2087 if Present (Component_Associations (Deps)) then
2088 Last_Clause := Last (Component_Associations (Deps));
2089
2090 -- Gather all states, objects and formal parameters that the
2091 -- subprogram may depend on. These items are obtained from the
2092 -- parameter profile or pragma [Refined_]Global (if available).
2093
2094 Collect_Subprogram_Inputs_Outputs
2095 (Subp_Id => Subp_Id,
2096 Subp_Inputs => Subp_Inputs,
2097 Subp_Outputs => Subp_Outputs,
2098 Global_Seen => Global_Seen);
2099
2100 -- When pragma [Refined_]Depends appears on a single concurrent
2101 -- type, it is relocated to the anonymous object.
2102
2103 if Is_Single_Concurrent_Object (Spec_Id) then
2104 null;
2105
2106 -- Ensure that the formal parameters are visible when analyzing
2107 -- all clauses. This falls out of the general rule of aspects
2108 -- pertaining to subprogram declarations.
2109
2110 elsif not In_Open_Scopes (Spec_Id) then
2111 Restore_Scope := True;
2112 Push_Scope (Spec_Id);
2113
2114 if Ekind (Spec_Id) = E_Task_Type then
2115
2116 -- Task discriminants cannot appear in the [Refined_]Depends
2117 -- contract, but must be present for the analysis so that we
2118 -- can reject them with an informative error message.
2119
2120 if Has_Discriminants (Spec_Id) then
2121 Install_Discriminants (Spec_Id);
2122 end if;
2123
2124 elsif Is_Generic_Subprogram (Spec_Id) then
2125 Install_Generic_Formals (Spec_Id);
2126
2127 else
2128 Install_Formals (Spec_Id);
2129 end if;
2130 end if;
2131
2132 Clause := First (Component_Associations (Deps));
2133 while Present (Clause) loop
2134 Errors := Serious_Errors_Detected;
2135
2136 -- The normalization mechanism may create extra clauses that
2137 -- contain replicated input and output names. There is no need
2138 -- to reanalyze them.
2139
2140 if not Analyzed (Clause) then
2141 Set_Analyzed (Clause);
2142
2143 Analyze_Dependency_Clause
2144 (Clause => Clause,
2145 Is_Last => Clause = Last_Clause);
2146 end if;
2147
2148 -- Do not normalize a clause if errors were detected (count
2149 -- of Serious_Errors has increased) because the inputs and/or
2150 -- outputs may denote illegal items.
2151
2152 if Serious_Errors_Detected = Errors then
2153 Normalize_Clause (Clause);
2154 end if;
2155
2156 Next (Clause);
2157 end loop;
2158
2159 if Restore_Scope then
2160 End_Scope;
2161 end if;
2162
2163 -- Verify that every input or output of the subprogram appear in a
2164 -- dependency.
2165
2166 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
2167 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
2168 Check_Function_Return;
2169
2170 -- The dependency list is malformed. This is a syntax error, always
2171 -- report.
2172
2173 else
2174 Error_Msg_N ("malformed dependency relation", Deps);
2175 goto Leave;
2176 end if;
2177
2178 -- The top level dependency relation is malformed. This is a syntax
2179 -- error, always report.
2180
2181 else
2182 Error_Msg_N ("malformed dependency relation", Deps);
2183 goto Leave;
2184 end if;
2185
2186 -- Ensure that a state and a corresponding constituent do not appear
2187 -- together in pragma [Refined_]Depends.
2188
2189 Check_State_And_Constituent_Use
2190 (States => States_Seen,
2191 Constits => Constits_Seen,
2192 Context => N);
2193
2194 <<Leave>>
2195 Set_Is_Analyzed_Pragma (N);
2196 end Analyze_Depends_In_Decl_Part;
2197
2198 --------------------------------------------
2199 -- Analyze_Exceptional_Cases_In_Decl_Part --
2200 --------------------------------------------
2201
2202 -- WARNING: This routine manages Ghost regions. Return statements must be
2203 -- replaced by gotos which jump to the end of the routine and restore the
2204 -- Ghost mode.
2205
2206 procedure Analyze_Exceptional_Cases_In_Decl_Part
2207 (N : Node_Id;
2208 Freeze_Id : Entity_Id := Empty)
2209 is
2210 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2211 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2212
2213 procedure Analyze_Exceptional_Contract (Exceptional_Contract : Node_Id);
2214 -- Verify the legality of a single exceptional contract
2215
2216 procedure Check_Duplication (Id : Node_Id; Contracts : List_Id);
2217 -- Iterate through the identifiers in each contract to find duplicates
2218
2219 ----------------------------------
2220 -- Analyze_Exceptional_Contract --
2221 ----------------------------------
2222
2223 procedure Analyze_Exceptional_Contract (Exceptional_Contract : Node_Id)
2224 is
2225 Exception_Choice : Node_Id;
2226 Consequence : Node_Id;
2227 Errors : Nat;
2228
2229 begin
2230 if Nkind (Exceptional_Contract) /= N_Component_Association then
2231 Error_Msg_N
2232 ("wrong syntax in exceptional contract", Exceptional_Contract);
2233 return;
2234 end if;
2235
2236 Exception_Choice := First (Choices (Exceptional_Contract));
2237 Consequence := Expression (Exceptional_Contract);
2238
2239 while Present (Exception_Choice) loop
2240 if Nkind (Exception_Choice) = N_Others_Choice then
2241 if Present (Next (Exception_Choice))
2242 or else Present (Next (Exceptional_Contract))
2243 or else Present (Prev (Exception_Choice))
2244 then
2245 Error_Msg_N
2246 ("OTHERS must appear alone and last", Exception_Choice);
2247 end if;
2248
2249 else
2250 Analyze (Exception_Choice);
2251
2252 if Is_Entity_Name (Exception_Choice)
2253 and then Ekind (Entity (Exception_Choice)) = E_Exception
2254 then
2255 if Present (Renamed_Entity (Entity (Exception_Choice)))
2256 and then Entity (Exception_Choice) = Standard_Numeric_Error
2257 then
2258 Check_Restriction
2259 (No_Obsolescent_Features, Exception_Choice);
2260
2261 if Warn_On_Obsolescent_Feature then
2262 Error_Msg_N
2263 ("Numeric_Error is an obsolescent feature " &
2264 "(RM J.6(1))?j?",
2265 Exception_Choice);
2266 Error_Msg_N
2267 ("\use Constraint_Error instead?j?",
2268 Exception_Choice);
2269 end if;
2270 end if;
2271
2272 Check_Duplication
2273 (Exception_Choice, List_Containing (Exceptional_Contract));
2274
2275 -- Check for exception declared within generic formal
2276 -- package (which is illegal, see RM 11.2(8)).
2277
2278 declare
2279 Ent : Entity_Id := Entity (Exception_Choice);
2280 Scop : Entity_Id;
2281
2282 begin
2283 if Present (Renamed_Entity (Ent)) then
2284 Ent := Renamed_Entity (Ent);
2285 end if;
2286
2287 Scop := Scope (Ent);
2288 while Scop /= Standard_Standard
2289 and then Ekind (Scop) = E_Package
2290 loop
2291 if Nkind (Declaration_Node (Scop)) =
2292 N_Package_Specification
2293 and then
2294 Nkind (Original_Node (Parent
2295 (Declaration_Node (Scop)))) =
2296 N_Formal_Package_Declaration
2297 then
2298 Error_Msg_NE
2299 ("exception& is declared in generic formal "
2300 & "package", Exception_Choice, Ent);
2301 Error_Msg_N
2302 ("\and therefore cannot appear in contract "
2303 & "(RM 11.2(8))", Exception_Choice);
2304 exit;
2305
2306 -- If the exception is declared in an inner instance,
2307 -- nothing else to check.
2308
2309 elsif Is_Generic_Instance (Scop) then
2310 exit;
2311 end if;
2312
2313 Scop := Scope (Scop);
2314 end loop;
2315 end;
2316 else
2317 Error_Msg_N ("exception name expected", Exception_Choice);
2318 end if;
2319 end if;
2320
2321 Next (Exception_Choice);
2322 end loop;
2323
2324 -- Now analyze the expressions of this contract
2325
2326 Errors := Serious_Errors_Detected;
2327
2328 -- Preanalyze_Assert_Expression, but without enforcing any of the two
2329 -- acceptable types.
2330
2331 Preanalyze_Assert_Expression (Consequence, Any_Boolean);
2332
2333 -- Emit a clarification message when the consequence contains at
2334 -- least one undefined reference, possibly due to contract freezing.
2335
2336 if Errors /= Serious_Errors_Detected
2337 and then Present (Freeze_Id)
2338 and then Has_Undefined_Reference (Consequence)
2339 then
2340 Contract_Freeze_Error (Spec_Id, Freeze_Id);
2341 end if;
2342 end Analyze_Exceptional_Contract;
2343
2344 -----------------------
2345 -- Check_Duplication --
2346 -----------------------
2347
2348 procedure Check_Duplication (Id : Node_Id; Contracts : List_Id) is
2349 Contract : Node_Id;
2350 Id1 : Node_Id;
2351 Id_Entity : Entity_Id := Entity (Id);
2352
2353 begin
2354 if Present (Renamed_Entity (Id_Entity)) then
2355 Id_Entity := Renamed_Entity (Id_Entity);
2356 end if;
2357
2358 Contract := First (Contracts);
2359 while Present (Contract) loop
2360 Id1 := First (Choices (Contract));
2361 while Present (Id1) loop
2362
2363 -- Only check against the exception choices which precede
2364 -- Id in the contract, since the ones that follow Id have not
2365 -- been analyzed yet and will be checked in a subsequent call.
2366
2367 if Id = Id1 then
2368 return;
2369
2370 -- Duplication both simple and via a renaming across different
2371 -- exceptional contracts is illegal.
2372
2373 elsif Nkind (Id1) /= N_Others_Choice
2374 and then
2375 (Id_Entity = Entity (Id1)
2376 or else Id_Entity = Renamed_Entity (Entity (Id1)))
2377 and then Contract /= Parent (Id)
2378 then
2379 Error_Msg_Sloc := Sloc (Id1);
2380 Error_Msg_NE ("exception choice duplicates &#", Id, Id1);
2381 end if;
2382
2383 Next (Id1);
2384 end loop;
2385
2386 Next (Contract);
2387 end loop;
2388 end Check_Duplication;
2389
2390 -- Local variables
2391
2392 Exceptional_Contracts : constant Node_Id :=
2393 Expression (Get_Argument (N, Spec_Id));
2394
2395 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
2396 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
2397 -- Save the Ghost-related attributes to restore on exit
2398
2399 Exceptional_Contract : Node_Id;
2400 Restore_Scope : Boolean := False;
2401
2402 -- Start of processing for Analyze_Subprogram_Variant_In_Decl_Part
2403
2404 begin
2405 -- Do not analyze the pragma multiple times
2406
2407 if Is_Analyzed_Pragma (N) then
2408 return;
2409 end if;
2410
2411 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2412 -- analysis of the pragma, the Ghost mode at point of declaration and
2413 -- point of analysis may not necessarily be the same. Use the mode in
2414 -- effect at the point of declaration.
2415
2416 Set_Ghost_Mode (N);
2417
2418 -- Single and multiple contracts must appear in aggregate form. If this
2419 -- is not the case, then either the parser of the analysis of the pragma
2420 -- failed to produce an aggregate, e.g. when the contract is "null" or a
2421 -- "(null record)".
2422
2423 pragma Assert
2424 (if Nkind (Exceptional_Contracts) = N_Aggregate
2425 then Null_Record_Present (Exceptional_Contracts)
2426 xor (Present (Component_Associations (Exceptional_Contracts))
2427 or
2428 Present (Expressions (Exceptional_Contracts)))
2429 else Nkind (Exceptional_Contracts) = N_Null);
2430
2431 -- Only clauses of the following form are allowed:
2432 --
2433 -- exceptional_contract ::=
2434 -- [choice_parameter_specification:]
2435 -- exception_choice {'|' exception_choice} => consequence
2436 --
2437 -- where
2438 --
2439 -- consequence ::= Boolean_expression
2440
2441 if Nkind (Exceptional_Contracts) = N_Aggregate
2442 and then Present (Component_Associations (Exceptional_Contracts))
2443 and then No (Expressions (Exceptional_Contracts))
2444 then
2445
2446 -- Check that the expression is a proper aggregate (no parentheses)
2447
2448 if Paren_Count (Exceptional_Contracts) /= 0 then
2449 Error_Msg_F -- CODEFIX
2450 ("redundant parentheses", Exceptional_Contracts);
2451 end if;
2452
2453 -- Ensure that the formal parameters are visible when analyzing all
2454 -- clauses. This falls out of the general rule of aspects pertaining
2455 -- to subprogram declarations.
2456
2457 if not In_Open_Scopes (Spec_Id) then
2458 Restore_Scope := True;
2459 Push_Scope (Spec_Id);
2460
2461 if Is_Generic_Subprogram (Spec_Id) then
2462 Install_Generic_Formals (Spec_Id);
2463 else
2464 Install_Formals (Spec_Id);
2465 end if;
2466 end if;
2467
2468 Exceptional_Contract :=
2469 First (Component_Associations (Exceptional_Contracts));
2470 while Present (Exceptional_Contract) loop
2471 Analyze_Exceptional_Contract (Exceptional_Contract);
2472 Next (Exceptional_Contract);
2473 end loop;
2474
2475 if Restore_Scope then
2476 End_Scope;
2477 end if;
2478
2479 -- Otherwise the pragma is illegal
2480
2481 else
2482 Error_Msg_N ("wrong syntax for exceptional cases", N);
2483 end if;
2484
2485 Set_Is_Analyzed_Pragma (N);
2486
2487 Restore_Ghost_Region (Saved_GM, Saved_IGR);
2488 end Analyze_Exceptional_Cases_In_Decl_Part;
2489
2490 --------------------------------------------
2491 -- Analyze_External_Property_In_Decl_Part --
2492 --------------------------------------------
2493
2494 procedure Analyze_External_Property_In_Decl_Part
2495 (N : Node_Id;
2496 Expr_Val : out Boolean)
2497 is
2498 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pragma_Name (N));
2499 Arg1 : constant Node_Id :=
2500 First (Pragma_Argument_Associations (N));
2501 Obj_Decl : constant Node_Id := Find_Related_Context (N);
2502 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
2503 Obj_Typ : Entity_Id;
2504 Expr : Node_Id;
2505
2506 begin
2507 if Is_Type (Obj_Id) then
2508 Obj_Typ := Obj_Id;
2509 else
2510 Obj_Typ := Etype (Obj_Id);
2511 end if;
2512
2513 -- Ensure that the Boolean expression (if present) is static. A missing
2514 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2515
2516 Expr_Val := True;
2517
2518 if Present (Arg1) then
2519 Expr := Get_Pragma_Arg (Arg1);
2520
2521 if Is_OK_Static_Expression (Expr) then
2522 Expr_Val := Is_True (Expr_Value (Expr));
2523 end if;
2524 end if;
2525
2526 -- The output parameter was set to the argument specified by the pragma.
2527 -- Do not analyze the pragma multiple times.
2528
2529 if Is_Analyzed_Pragma (N) then
2530 return;
2531 end if;
2532
2533 Error_Msg_Name_1 := Pragma_Name (N);
2534
2535 -- An external property pragma must apply to an effectively volatile
2536 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
2537 -- The check is performed at the end of the declarative region due to a
2538 -- possible out-of-order arrangement of pragmas:
2539
2540 -- Obj : ...;
2541 -- pragma Async_Readers (Obj);
2542 -- pragma Volatile (Obj);
2543
2544 if Prag_Id /= Pragma_No_Caching
2545 and then not Is_Effectively_Volatile (Obj_Id)
2546 then
2547 if No_Caching_Enabled (Obj_Id) then
2548 if Expr_Val then -- Confirming value of False is allowed
2549 SPARK_Msg_N
2550 ("illegal combination of external property % and property "
2551 & """No_Caching"" (SPARK RM 7.1.2(6))", N);
2552 end if;
2553 else
2554 SPARK_Msg_N
2555 ("external property % must apply to a volatile type or object",
2556 N);
2557 end if;
2558
2559 -- Pragma No_Caching should only apply to volatile types or variables of
2560 -- a non-effectively volatile type (SPARK RM 7.1.2).
2561
2562 elsif Prag_Id = Pragma_No_Caching then
2563 if Is_Effectively_Volatile (Obj_Typ) then
2564 SPARK_Msg_N ("property % must not apply to a type or object of "
2565 & "an effectively volatile type", N);
2566 elsif not Is_Volatile (Obj_Id) then
2567 SPARK_Msg_N
2568 ("property % must apply to a volatile type or object", N);
2569 end if;
2570 end if;
2571
2572 Set_Is_Analyzed_Pragma (N);
2573 end Analyze_External_Property_In_Decl_Part;
2574
2575 ---------------------------------
2576 -- Analyze_Global_In_Decl_Part --
2577 ---------------------------------
2578
2579 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
2580 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2581 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2582 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2583
2584 Constits_Seen : Elist_Id := No_Elist;
2585 -- A list containing the entities of all constituents processed so far.
2586 -- It aids in detecting illegal usage of a state and a corresponding
2587 -- constituent in pragma [Refinde_]Global.
2588
2589 Seen : Elist_Id := No_Elist;
2590 -- A list containing the entities of all the items processed so far. It
2591 -- plays a role in detecting distinct entities.
2592
2593 States_Seen : Elist_Id := No_Elist;
2594 -- A list containing the entities of all states processed so far. It
2595 -- helps in detecting illegal usage of a state and a corresponding
2596 -- constituent in pragma [Refined_]Global.
2597
2598 In_Out_Seen : Boolean := False;
2599 Input_Seen : Boolean := False;
2600 Output_Seen : Boolean := False;
2601 Proof_Seen : Boolean := False;
2602 -- Flags used to verify the consistency of modes
2603
2604 procedure Analyze_Global_List
2605 (List : Node_Id;
2606 Global_Mode : Name_Id := Name_Input);
2607 -- Verify the legality of a single global list declaration. Global_Mode
2608 -- denotes the current mode in effect.
2609
2610 -------------------------
2611 -- Analyze_Global_List --
2612 -------------------------
2613
2614 procedure Analyze_Global_List
2615 (List : Node_Id;
2616 Global_Mode : Name_Id := Name_Input)
2617 is
2618 procedure Analyze_Global_Item
2619 (Item : Node_Id;
2620 Global_Mode : Name_Id);
2621 -- Verify the legality of a single global item declaration denoted by
2622 -- Item. Global_Mode denotes the current mode in effect.
2623
2624 procedure Check_Duplicate_Mode
2625 (Mode : Node_Id;
2626 Status : in out Boolean);
2627 -- Flag Status denotes whether a particular mode has been seen while
2628 -- processing a global list. This routine verifies that Mode is not a
2629 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2630
2631 procedure Check_Mode_Restriction_In_Enclosing_Context
2632 (Item : Node_Id;
2633 Item_Id : Entity_Id);
2634 -- Verify that an item of mode In_Out or Output does not appear as
2635 -- an input in the Global aspect of an enclosing subprogram or task
2636 -- unit. If this is the case, emit an error. Item and Item_Id are
2637 -- respectively the item and its entity.
2638
2639 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
2640 -- Mode denotes either In_Out or Output. Depending on the kind of the
2641 -- related subprogram, emit an error if those two modes apply to a
2642 -- function (SPARK RM 6.1.4(10)).
2643
2644 -------------------------
2645 -- Analyze_Global_Item --
2646 -------------------------
2647
2648 procedure Analyze_Global_Item
2649 (Item : Node_Id;
2650 Global_Mode : Name_Id)
2651 is
2652 Item_Id : Entity_Id;
2653
2654 begin
2655 -- Detect one of the following cases
2656
2657 -- with Global => (null, Name)
2658 -- with Global => (Name_1, null, Name_2)
2659 -- with Global => (Name, null)
2660
2661 if Nkind (Item) = N_Null then
2662 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
2663 return;
2664 end if;
2665
2666 Analyze (Item);
2667 Resolve_State (Item);
2668
2669 -- Find the entity of the item. If this is a renaming, climb the
2670 -- renaming chain to reach the root object. Renamings of non-
2671 -- entire objects do not yield an entity (Empty).
2672
2673 Item_Id := Entity_Of (Item);
2674
2675 if Present (Item_Id) then
2676
2677 -- A global item may denote a formal parameter of an enclosing
2678 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2679 -- provide a better error diagnostic.
2680
2681 if Is_Formal (Item_Id) then
2682 if Scope (Item_Id) = Spec_Id then
2683 SPARK_Msg_NE
2684 (Fix_Msg (Spec_Id, "global item cannot reference "
2685 & "parameter of subprogram &"), Item, Spec_Id);
2686 return;
2687 end if;
2688
2689 -- A global item may denote a concurrent type as long as it is
2690 -- the current instance of an enclosing protected or task type
2691 -- (SPARK RM 6.1.4).
2692
2693 elsif Ekind (Item_Id) in E_Protected_Type | E_Task_Type then
2694 if Is_CCT_Instance (Item_Id, Spec_Id) then
2695
2696 -- Pragma [Refined_]Global associated with a protected
2697 -- subprogram cannot mention the current instance of a
2698 -- protected type because the instance behaves as a
2699 -- formal parameter.
2700
2701 if Ekind (Item_Id) = E_Protected_Type then
2702 if Scope (Spec_Id) = Item_Id then
2703 Error_Msg_Name_1 := Chars (Item_Id);
2704 SPARK_Msg_NE
2705 (Fix_Msg (Spec_Id, "global item of subprogram & "
2706 & "cannot reference current instance of "
2707 & "protected type %"), Item, Spec_Id);
2708 return;
2709 end if;
2710
2711 -- Pragma [Refined_]Global associated with a task type
2712 -- cannot mention the current instance of a task type
2713 -- because the instance behaves as a formal parameter.
2714
2715 else pragma Assert (Ekind (Item_Id) = E_Task_Type);
2716 if Spec_Id = Item_Id then
2717 Error_Msg_Name_1 := Chars (Item_Id);
2718 SPARK_Msg_NE
2719 (Fix_Msg (Spec_Id, "global item of subprogram & "
2720 & "cannot reference current instance of task "
2721 & "type %"), Item, Spec_Id);
2722 return;
2723 end if;
2724 end if;
2725
2726 -- Otherwise the global item denotes a subtype mark that is
2727 -- not a current instance.
2728
2729 else
2730 SPARK_Msg_N
2731 ("invalid use of subtype mark in global list", Item);
2732 return;
2733 end if;
2734
2735 -- A global item may denote the anonymous object created for a
2736 -- single protected/task type as long as the current instance
2737 -- is the same single type (SPARK RM 6.1.4).
2738
2739 elsif Is_Single_Concurrent_Object (Item_Id)
2740 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
2741 then
2742 -- Pragma [Refined_]Global associated with a protected
2743 -- subprogram cannot mention the current instance of a
2744 -- protected type because the instance behaves as a formal
2745 -- parameter.
2746
2747 if Is_Single_Protected_Object (Item_Id) then
2748 if Scope (Spec_Id) = Etype (Item_Id) then
2749 Error_Msg_Name_1 := Chars (Item_Id);
2750 SPARK_Msg_NE
2751 (Fix_Msg (Spec_Id, "global item of subprogram & "
2752 & "cannot reference current instance of protected "
2753 & "type %"), Item, Spec_Id);
2754 return;
2755 end if;
2756
2757 -- Pragma [Refined_]Global associated with a task type
2758 -- cannot mention the current instance of a task type
2759 -- because the instance behaves as a formal parameter.
2760
2761 else pragma Assert (Is_Single_Task_Object (Item_Id));
2762 if Spec_Id = Item_Id then
2763 Error_Msg_Name_1 := Chars (Item_Id);
2764 SPARK_Msg_NE
2765 (Fix_Msg (Spec_Id, "global item of subprogram & "
2766 & "cannot reference current instance of task "
2767 & "type %"), Item, Spec_Id);
2768 return;
2769 end if;
2770 end if;
2771
2772 -- A formal object may act as a global item inside a generic
2773
2774 elsif Is_Formal_Object (Item_Id) then
2775 null;
2776
2777 elsif Ekind (Item_Id) in E_Constant | E_Variable
2778 and then Present (Ultimate_Overlaid_Entity (Item_Id))
2779 then
2780 SPARK_Msg_NE
2781 ("overlaying object & cannot appear in Global",
2782 Item, Item_Id);
2783 SPARK_Msg_NE
2784 ("\use the overlaid object & instead",
2785 Item, Ultimate_Overlaid_Entity (Item_Id));
2786 return;
2787
2788 -- The only legal references are those to abstract states,
2789 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2790
2791 elsif Ekind (Item_Id) not in E_Abstract_State
2792 | E_Constant
2793 | E_Loop_Parameter
2794 | E_Variable
2795 then
2796 SPARK_Msg_N
2797 ("global item must denote object, state or current "
2798 & "instance of concurrent type", Item);
2799
2800 if Is_Named_Number (Item_Id) then
2801 SPARK_Msg_NE
2802 ("\named number & is not an object", Item, Item_Id);
2803 end if;
2804
2805 return;
2806 end if;
2807
2808 -- State related checks
2809
2810 if Ekind (Item_Id) = E_Abstract_State then
2811
2812 -- Package and subprogram bodies are instantiated
2813 -- individually in a separate compiler pass. Due to this
2814 -- mode of instantiation, the refinement of a state may
2815 -- no longer be visible when a subprogram body contract
2816 -- is instantiated. Since the generic template is legal,
2817 -- do not perform this check in the instance to circumvent
2818 -- this oddity.
2819
2820 if In_Instance then
2821 null;
2822
2823 -- An abstract state with visible refinement cannot appear
2824 -- in pragma [Refined_]Global as its place must be taken by
2825 -- some of its constituents (SPARK RM 6.1.4(7)).
2826
2827 elsif Has_Visible_Refinement (Item_Id) then
2828 SPARK_Msg_NE
2829 ("cannot mention state & in global refinement",
2830 Item, Item_Id);
2831 SPARK_Msg_N ("\use its constituents instead", Item);
2832 return;
2833
2834 -- If the reference to the abstract state appears in an
2835 -- enclosing package body that will eventually refine the
2836 -- state, record the reference for future checks.
2837
2838 else
2839 Record_Possible_Body_Reference
2840 (State_Id => Item_Id,
2841 Ref => Item);
2842 end if;
2843
2844 -- Constant related checks
2845
2846 elsif Ekind (Item_Id) = E_Constant then
2847
2848 -- Constant is a read-only item, therefore it cannot act as
2849 -- an output.
2850
2851 if Global_Mode in Name_In_Out | Name_Output then
2852
2853 -- Constant of an access-to-variable type is a read-write
2854 -- item in procedures, generic procedures, protected
2855 -- entries and tasks.
2856
2857 if Is_Access_Variable (Etype (Item_Id))
2858 and then (Ekind (Spec_Id) in E_Entry
2859 | E_Entry_Family
2860 | E_Procedure
2861 | E_Generic_Procedure
2862 | E_Task_Type
2863 or else Is_Single_Task_Object (Spec_Id)
2864 or else
2865 Is_Function_With_Side_Effects (Spec_Id))
2866 then
2867 null;
2868 else
2869 SPARK_Msg_NE
2870 ("constant & cannot act as output", Item, Item_Id);
2871 return;
2872 end if;
2873 end if;
2874
2875 -- Loop parameter related checks
2876
2877 elsif Ekind (Item_Id) = E_Loop_Parameter then
2878
2879 -- A loop parameter is a read-only item, therefore it cannot
2880 -- act as an output.
2881
2882 if Global_Mode in Name_In_Out | Name_Output then
2883 SPARK_Msg_NE
2884 ("loop parameter & cannot act as output",
2885 Item, Item_Id);
2886 return;
2887 end if;
2888 end if;
2889
2890 -- When the item renames an entire object, replace the item
2891 -- with a reference to the object.
2892
2893 if Entity (Item) /= Item_Id then
2894 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2895 Analyze (Item);
2896 end if;
2897
2898 -- Some form of illegal construct masquerading as a name
2899 -- (SPARK RM 6.1.4(4)).
2900
2901 else
2902 Error_Msg_N
2903 ("global item must denote object, state or current instance "
2904 & "of concurrent type", Item);
2905 return;
2906 end if;
2907
2908 -- Verify that an output does not appear as an input in an
2909 -- enclosing subprogram.
2910
2911 if Global_Mode in Name_In_Out | Name_Output then
2912 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2913 end if;
2914
2915 -- The same entity might be referenced through various way.
2916 -- Check the entity of the item rather than the item itself
2917 -- (SPARK RM 6.1.4(10)).
2918
2919 if Contains (Seen, Item_Id) then
2920 SPARK_Msg_N ("duplicate global item", Item);
2921
2922 -- Add the entity of the current item to the list of processed
2923 -- items.
2924
2925 else
2926 Append_New_Elmt (Item_Id, Seen);
2927
2928 if Ekind (Item_Id) = E_Abstract_State then
2929 Append_New_Elmt (Item_Id, States_Seen);
2930
2931 -- The variable may eventually become a constituent of a single
2932 -- protected/task type. Record the reference now and verify its
2933 -- legality when analyzing the contract of the variable
2934 -- (SPARK RM 9.3).
2935
2936 elsif Ekind (Item_Id) = E_Variable then
2937 Record_Possible_Part_Of_Reference
2938 (Var_Id => Item_Id,
2939 Ref => Item);
2940 end if;
2941
2942 if Ekind (Item_Id) in E_Abstract_State | E_Constant | E_Variable
2943 and then Present (Encapsulating_State (Item_Id))
2944 then
2945 Append_New_Elmt (Item_Id, Constits_Seen);
2946 end if;
2947 end if;
2948 end Analyze_Global_Item;
2949
2950 --------------------------
2951 -- Check_Duplicate_Mode --
2952 --------------------------
2953
2954 procedure Check_Duplicate_Mode
2955 (Mode : Node_Id;
2956 Status : in out Boolean)
2957 is
2958 begin
2959 if Status then
2960 SPARK_Msg_N ("duplicate global mode", Mode);
2961 end if;
2962
2963 Status := True;
2964 end Check_Duplicate_Mode;
2965
2966 -------------------------------------------------
2967 -- Check_Mode_Restriction_In_Enclosing_Context --
2968 -------------------------------------------------
2969
2970 procedure Check_Mode_Restriction_In_Enclosing_Context
2971 (Item : Node_Id;
2972 Item_Id : Entity_Id)
2973 is
2974 Context : Entity_Id;
2975 Dummy : Boolean;
2976 Inputs : Elist_Id := No_Elist;
2977 Outputs : Elist_Id := No_Elist;
2978
2979 begin
2980 -- Traverse the scope stack looking for enclosing subprograms or
2981 -- tasks subject to pragma [Refined_]Global.
2982
2983 Context := Scope (Subp_Id);
2984 while Present (Context) and then Context /= Standard_Standard loop
2985
2986 -- For a single task type, retrieve the corresponding object to
2987 -- which pragma [Refined_]Global is attached.
2988
2989 if Ekind (Context) = E_Task_Type
2990 and then Is_Single_Concurrent_Type (Context)
2991 then
2992 Context := Anonymous_Object (Context);
2993 end if;
2994
2995 if Is_Subprogram_Or_Entry (Context)
2996 or else Ekind (Context) = E_Task_Type
2997 or else Is_Single_Task_Object (Context)
2998 then
2999 Collect_Subprogram_Inputs_Outputs
3000 (Subp_Id => Context,
3001 Subp_Inputs => Inputs,
3002 Subp_Outputs => Outputs,
3003 Global_Seen => Dummy);
3004
3005 -- The item is classified as In_Out or Output but appears as
3006 -- an Input or a formal parameter of mode IN in an enclosing
3007 -- subprogram or task unit (SPARK RM 6.1.4(13)).
3008
3009 if Appears_In (Inputs, Item_Id)
3010 and then not Appears_In (Outputs, Item_Id)
3011 then
3012 SPARK_Msg_NE
3013 ("global item & cannot have mode In_Out or Output",
3014 Item, Item_Id);
3015
3016 if Is_Subprogram_Or_Entry (Context) then
3017 SPARK_Msg_NE
3018 (Fix_Msg (Subp_Id, "\item already appears as input "
3019 & "of subprogram &"), Item, Context);
3020 else
3021 SPARK_Msg_NE
3022 (Fix_Msg (Subp_Id, "\item already appears as input "
3023 & "of task &"), Item, Context);
3024 end if;
3025
3026 -- Stop the traversal once an error has been detected
3027
3028 exit;
3029 end if;
3030 end if;
3031
3032 Context := Scope (Context);
3033 end loop;
3034 end Check_Mode_Restriction_In_Enclosing_Context;
3035
3036 ----------------------------------------
3037 -- Check_Mode_Restriction_In_Function --
3038 ----------------------------------------
3039
3040 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
3041 begin
3042 if Ekind (Spec_Id) in E_Function | E_Generic_Function
3043 and then not Is_Function_With_Side_Effects (Spec_Id)
3044 then
3045 Error_Msg_Code := GEC_Output_In_Function_Global_Or_Depends;
3046 SPARK_Msg_N
3047 ("global mode & is not applicable to function '[[]']", Mode);
3048 end if;
3049 end Check_Mode_Restriction_In_Function;
3050
3051 -- Local variables
3052
3053 Assoc : Node_Id;
3054 Item : Node_Id;
3055 Mode : Node_Id;
3056
3057 -- Start of processing for Analyze_Global_List
3058
3059 begin
3060 if Nkind (List) = N_Null then
3061 Set_Analyzed (List);
3062
3063 -- Single global item declaration
3064
3065 elsif Nkind (List) in N_Expanded_Name
3066 | N_Identifier
3067 | N_Selected_Component
3068 then
3069 Analyze_Global_Item (List, Global_Mode);
3070
3071 -- Simple global list or moded global list declaration
3072
3073 elsif Nkind (List) = N_Aggregate then
3074 Set_Analyzed (List);
3075
3076 -- The declaration of a simple global list appear as a collection
3077 -- of expressions.
3078
3079 if Present (Expressions (List)) then
3080 if Present (Component_Associations (List)) then
3081 SPARK_Msg_N
3082 ("cannot mix moded and non-moded global lists", List);
3083 end if;
3084
3085 Item := First (Expressions (List));
3086 while Present (Item) loop
3087 Analyze_Global_Item (Item, Global_Mode);
3088 Next (Item);
3089 end loop;
3090
3091 -- The declaration of a moded global list appears as a collection
3092 -- of component associations where individual choices denote
3093 -- modes.
3094
3095 elsif Present (Component_Associations (List)) then
3096 if Present (Expressions (List)) then
3097 SPARK_Msg_N
3098 ("cannot mix moded and non-moded global lists", List);
3099 end if;
3100
3101 Assoc := First (Component_Associations (List));
3102 while Present (Assoc) loop
3103 Mode := First (Choices (Assoc));
3104
3105 if Nkind (Mode) = N_Identifier then
3106 if Chars (Mode) = Name_In_Out then
3107 Check_Duplicate_Mode (Mode, In_Out_Seen);
3108 Check_Mode_Restriction_In_Function (Mode);
3109
3110 elsif Chars (Mode) = Name_Input then
3111 Check_Duplicate_Mode (Mode, Input_Seen);
3112
3113 elsif Chars (Mode) = Name_Output then
3114 Check_Duplicate_Mode (Mode, Output_Seen);
3115 Check_Mode_Restriction_In_Function (Mode);
3116
3117 elsif Chars (Mode) = Name_Proof_In then
3118 Check_Duplicate_Mode (Mode, Proof_Seen);
3119
3120 else
3121 SPARK_Msg_N ("invalid mode selector", Mode);
3122 end if;
3123
3124 else
3125 SPARK_Msg_N ("invalid mode selector", Mode);
3126 end if;
3127
3128 -- Items in a moded list appear as a collection of
3129 -- expressions. Reuse the existing machinery to analyze
3130 -- them.
3131
3132 Analyze_Global_List
3133 (List => Expression (Assoc),
3134 Global_Mode => Chars (Mode));
3135
3136 Next (Assoc);
3137 end loop;
3138
3139 -- Invalid tree
3140
3141 else
3142 raise Program_Error;
3143 end if;
3144
3145 -- Any other attempt to declare a global item is illegal. This is a
3146 -- syntax error, always report.
3147
3148 else
3149 Error_Msg_N ("malformed global list", List);
3150 end if;
3151 end Analyze_Global_List;
3152
3153 -- Local variables
3154
3155 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
3156
3157 Restore_Scope : Boolean := False;
3158
3159 -- Start of processing for Analyze_Global_In_Decl_Part
3160
3161 begin
3162 -- Do not analyze the pragma multiple times
3163
3164 if Is_Analyzed_Pragma (N) then
3165 return;
3166 end if;
3167
3168 -- There is nothing to be done for a null global list
3169
3170 if Nkind (Items) = N_Null then
3171 Set_Analyzed (Items);
3172
3173 -- Analyze the various forms of global lists and items. Note that some
3174 -- of these may be malformed in which case the analysis emits error
3175 -- messages.
3176
3177 else
3178 -- When pragma [Refined_]Global appears on a single concurrent type,
3179 -- it is relocated to the anonymous object.
3180
3181 if Is_Single_Concurrent_Object (Spec_Id) then
3182 null;
3183
3184 -- Ensure that the formal parameters are visible when processing an
3185 -- item. This falls out of the general rule of aspects pertaining to
3186 -- subprogram declarations.
3187
3188 elsif not In_Open_Scopes (Spec_Id) then
3189 Restore_Scope := True;
3190 Push_Scope (Spec_Id);
3191
3192 if Ekind (Spec_Id) = E_Task_Type then
3193
3194 -- Task discriminants cannot appear in the [Refined_]Global
3195 -- contract, but must be present for the analysis so that we
3196 -- can reject them with an informative error message.
3197
3198 if Has_Discriminants (Spec_Id) then
3199 Install_Discriminants (Spec_Id);
3200 end if;
3201
3202 elsif Is_Generic_Subprogram (Spec_Id) then
3203 Install_Generic_Formals (Spec_Id);
3204
3205 else
3206 Install_Formals (Spec_Id);
3207 end if;
3208 end if;
3209
3210 Analyze_Global_List (Items);
3211
3212 if Restore_Scope then
3213 End_Scope;
3214 end if;
3215 end if;
3216
3217 -- Ensure that a state and a corresponding constituent do not appear
3218 -- together in pragma [Refined_]Global.
3219
3220 Check_State_And_Constituent_Use
3221 (States => States_Seen,
3222 Constits => Constits_Seen,
3223 Context => N);
3224
3225 Set_Is_Analyzed_Pragma (N);
3226 end Analyze_Global_In_Decl_Part;
3227
3228 ---------------------------------
3229 -- Analyze_If_Present_Internal --
3230 ---------------------------------
3231
3232 procedure Analyze_If_Present_Internal
3233 (N : Node_Id;
3234 Id : Pragma_Id;
3235 Included : Boolean)
3236 is
3237 Stmt : Node_Id;
3238
3239 begin
3240 pragma Assert (Is_List_Member (N));
3241
3242 -- Inspect the declarations or statements following pragma N looking
3243 -- for another pragma whose Id matches the caller's request. If it is
3244 -- available, analyze it.
3245
3246 if Included then
3247 Stmt := N;
3248 else
3249 Stmt := Next (N);
3250 end if;
3251
3252 while Present (Stmt) loop
3253 if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then
3254 Analyze_Pragma (Stmt);
3255 exit;
3256
3257 -- The first source declaration or statement immediately following
3258 -- N ends the region where a pragma may appear.
3259
3260 elsif Comes_From_Source (Stmt) then
3261 exit;
3262 end if;
3263
3264 Next (Stmt);
3265 end loop;
3266 end Analyze_If_Present_Internal;
3267
3268 --------------------------------------------
3269 -- Analyze_Initial_Condition_In_Decl_Part --
3270 --------------------------------------------
3271
3272 -- WARNING: This routine manages Ghost regions. Return statements must be
3273 -- replaced by gotos which jump to the end of the routine and restore the
3274 -- Ghost mode.
3275
3276 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
3277 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
3278 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
3279 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3280
3281 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
3282 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
3283 -- Save the Ghost-related attributes to restore on exit
3284
3285 begin
3286 -- Do not analyze the pragma multiple times
3287
3288 if Is_Analyzed_Pragma (N) then
3289 return;
3290 end if;
3291
3292 -- Set the Ghost mode in effect from the pragma. Due to the delayed
3293 -- analysis of the pragma, the Ghost mode at point of declaration and
3294 -- point of analysis may not necessarily be the same. Use the mode in
3295 -- effect at the point of declaration.
3296
3297 Set_Ghost_Mode (N);
3298
3299 -- The expression is preanalyzed because it has not been moved to its
3300 -- final place yet. A direct analysis may generate side effects and this
3301 -- is not desired at this point.
3302
3303 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
3304 Set_Is_Analyzed_Pragma (N);
3305
3306 Restore_Ghost_Region (Saved_GM, Saved_IGR);
3307 end Analyze_Initial_Condition_In_Decl_Part;
3308
3309 --------------------------------------
3310 -- Analyze_Initializes_In_Decl_Part --
3311 --------------------------------------
3312
3313 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
3314 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
3315 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
3316
3317 Constits_Seen : Elist_Id := No_Elist;
3318 -- A list containing the entities of all constituents processed so far.
3319 -- It aids in detecting illegal usage of a state and a corresponding
3320 -- constituent in pragma Initializes.
3321
3322 Items_Seen : Elist_Id := No_Elist;
3323 -- A list of all initialization items processed so far. This list is
3324 -- used to detect duplicate items.
3325
3326 States_And_Objs : Elist_Id := No_Elist;
3327 -- A list of all abstract states and objects declared in the visible
3328 -- declarations of the related package. This list is used to detect the
3329 -- legality of initialization items.
3330
3331 States_Seen : Elist_Id := No_Elist;
3332 -- A list containing the entities of all states processed so far. It
3333 -- helps in detecting illegal usage of a state and a corresponding
3334 -- constituent in pragma Initializes.
3335
3336 procedure Analyze_Initialization_Item (Item : Node_Id);
3337 -- Verify the legality of a single initialization item
3338
3339 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
3340 -- Verify the legality of a single initialization item followed by a
3341 -- list of input items.
3342
3343 procedure Collect_States_And_Objects (Pack_Decl : Node_Id);
3344 -- Inspect the visible declarations of the related package and gather
3345 -- the entities of all abstract states and objects in States_And_Objs.
3346
3347 ---------------------------------
3348 -- Analyze_Initialization_Item --
3349 ---------------------------------
3350
3351 procedure Analyze_Initialization_Item (Item : Node_Id) is
3352 Item_Id : Entity_Id;
3353
3354 begin
3355 Analyze (Item);
3356 Resolve_State (Item);
3357
3358 if Is_Entity_Name (Item) then
3359 Item_Id := Entity_Of (Item);
3360
3361 if Present (Item_Id)
3362 and then Ekind (Item_Id) in
3363 E_Abstract_State | E_Constant | E_Variable
3364 then
3365 -- When the initialization item is undefined, it appears as
3366 -- Any_Id. Do not continue with the analysis of the item.
3367
3368 if Item_Id = Any_Id then
3369 null;
3370
3371 elsif Ekind (Item_Id) in E_Constant | E_Variable
3372 and then Present (Ultimate_Overlaid_Entity (Item_Id))
3373 then
3374 SPARK_Msg_NE
3375 ("overlaying object & cannot appear in Initializes",
3376 Item, Item_Id);
3377 SPARK_Msg_NE
3378 ("\use the overlaid object & instead",
3379 Item, Ultimate_Overlaid_Entity (Item_Id));
3380
3381 -- The state or variable must be declared in the visible
3382 -- declarations of the package (SPARK RM 7.1.5(7)).
3383
3384 elsif not Contains (States_And_Objs, Item_Id) then
3385 Error_Msg_Name_1 := Chars (Pack_Id);
3386 SPARK_Msg_NE
3387 ("initialization item & must appear in the visible "
3388 & "declarations of package %", Item, Item_Id);
3389
3390 -- Detect a duplicate use of the same initialization item
3391 -- (SPARK RM 7.1.5(5)).
3392
3393 elsif Contains (Items_Seen, Item_Id) then
3394 SPARK_Msg_N ("duplicate initialization item", Item);
3395
3396 -- The item is legal, add it to the list of processed states
3397 -- and variables.
3398
3399 else
3400 Append_New_Elmt (Item_Id, Items_Seen);
3401
3402 if Ekind (Item_Id) = E_Abstract_State then
3403 Append_New_Elmt (Item_Id, States_Seen);
3404 end if;
3405
3406 if Present (Encapsulating_State (Item_Id)) then
3407 Append_New_Elmt (Item_Id, Constits_Seen);
3408 end if;
3409 end if;
3410
3411 -- The item references something that is not a state or object
3412 -- (SPARK RM 7.1.5(3)).
3413
3414 else
3415 SPARK_Msg_N
3416 ("initialization item must denote object or state", Item);
3417 end if;
3418
3419 -- Some form of illegal construct masquerading as a name
3420 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
3421
3422 else
3423 Error_Msg_N
3424 ("initialization item must denote object or state", Item);
3425 end if;
3426 end Analyze_Initialization_Item;
3427
3428 ---------------------------------------------
3429 -- Analyze_Initialization_Item_With_Inputs --
3430 ---------------------------------------------
3431
3432 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
3433 Inputs_Seen : Elist_Id := No_Elist;
3434 -- A list of all inputs processed so far. This list is used to detect
3435 -- duplicate uses of an input.
3436
3437 Non_Null_Seen : Boolean := False;
3438 Null_Seen : Boolean := False;
3439 -- Flags used to check the legality of an input list
3440
3441 procedure Analyze_Input_Item (Input : Node_Id);
3442 -- Verify the legality of a single input item
3443
3444 ------------------------
3445 -- Analyze_Input_Item --
3446 ------------------------
3447
3448 procedure Analyze_Input_Item (Input : Node_Id) is
3449 Input_Id : Entity_Id;
3450
3451 begin
3452 -- Null input list
3453
3454 if Nkind (Input) = N_Null then
3455 if Null_Seen then
3456 SPARK_Msg_N
3457 ("multiple null initializations not allowed", Item);
3458
3459 elsif Non_Null_Seen then
3460 SPARK_Msg_N
3461 ("cannot mix null and non-null initialization item", Item);
3462 else
3463 Null_Seen := True;
3464 end if;
3465
3466 -- Input item
3467
3468 else
3469 Non_Null_Seen := True;
3470
3471 if Null_Seen then
3472 SPARK_Msg_N
3473 ("cannot mix null and non-null initialization item", Item);
3474 end if;
3475
3476 Analyze (Input);
3477 Resolve_State (Input);
3478
3479 if Is_Entity_Name (Input) then
3480 Input_Id := Entity_Of (Input);
3481
3482 if Present (Input_Id)
3483 and then Ekind (Input_Id) in E_Abstract_State
3484 | E_Constant
3485 | E_Generic_In_Out_Parameter
3486 | E_Generic_In_Parameter
3487 | E_In_Parameter
3488 | E_In_Out_Parameter
3489 | E_Out_Parameter
3490 | E_Protected_Type
3491 | E_Task_Type
3492 | E_Variable
3493 then
3494 -- The input cannot denote states or objects declared
3495 -- within the related package (SPARK RM 7.1.5(4)).
3496
3497 if Within_Scope (Input_Id, Current_Scope) then
3498
3499 -- Do not consider generic formal parameters or their
3500 -- respective mappings to generic formals. Even though
3501 -- the formals appear within the scope of the package,
3502 -- it is allowed for an initialization item to depend
3503 -- on an input item.
3504
3505 if Is_Formal_Object (Input_Id) then
3506 null;
3507
3508 elsif Ekind (Input_Id) in E_Constant | E_Variable
3509 and then Present (Corresponding_Generic_Association
3510 (Declaration_Node (Input_Id)))
3511 then
3512 null;
3513
3514 else
3515 Error_Msg_Name_1 := Chars (Pack_Id);
3516 SPARK_Msg_NE
3517 ("input item & cannot denote a visible object or "
3518 & "state of package %", Input, Input_Id);
3519 return;
3520 end if;
3521 end if;
3522
3523 if Ekind (Input_Id) in E_Constant | E_Variable
3524 and then Present (Ultimate_Overlaid_Entity (Input_Id))
3525 then
3526 SPARK_Msg_NE
3527 ("overlaying object & cannot appear in Initializes",
3528 Input, Input_Id);
3529 SPARK_Msg_NE
3530 ("\use the overlaid object & instead",
3531 Input, Ultimate_Overlaid_Entity (Input_Id));
3532 return;
3533 end if;
3534
3535 -- Detect a duplicate use of the same input item
3536 -- (SPARK RM 7.1.5(5)).
3537
3538 if Contains (Inputs_Seen, Input_Id) then
3539 SPARK_Msg_N ("duplicate input item", Input);
3540 return;
3541 end if;
3542
3543 -- At this point it is known that the input is legal. Add
3544 -- it to the list of processed inputs.
3545
3546 Append_New_Elmt (Input_Id, Inputs_Seen);
3547
3548 if Ekind (Input_Id) = E_Abstract_State then
3549 Append_New_Elmt (Input_Id, States_Seen);
3550 end if;
3551
3552 if Ekind (Input_Id) in E_Abstract_State
3553 | E_Constant
3554 | E_Variable
3555 and then Present (Encapsulating_State (Input_Id))
3556 then
3557 Append_New_Elmt (Input_Id, Constits_Seen);
3558 end if;
3559
3560 -- The input references something that is not a state or an
3561 -- object (SPARK RM 7.1.5(3)).
3562
3563 else
3564 SPARK_Msg_N
3565 ("input item must denote object or state", Input);
3566 end if;
3567
3568 -- Some form of illegal construct masquerading as a name
3569 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
3570
3571 else
3572 Error_Msg_N
3573 ("input item must denote object or state", Input);
3574 end if;
3575 end if;
3576 end Analyze_Input_Item;
3577
3578 -- Local variables
3579
3580 Inputs : constant Node_Id := Expression (Item);
3581 Elmt : Node_Id;
3582 Input : Node_Id;
3583
3584 Name_Seen : Boolean := False;
3585 -- A flag used to detect multiple item names
3586
3587 -- Start of processing for Analyze_Initialization_Item_With_Inputs
3588
3589 begin
3590 -- Inspect the name of an item with inputs
3591
3592 Elmt := First (Choices (Item));
3593 while Present (Elmt) loop
3594 if Name_Seen then
3595 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
3596 else
3597 Name_Seen := True;
3598 Analyze_Initialization_Item (Elmt);
3599 end if;
3600
3601 Next (Elmt);
3602 end loop;
3603
3604 -- Multiple input items appear as an aggregate
3605
3606 if Nkind (Inputs) = N_Aggregate then
3607 if Present (Expressions (Inputs)) then
3608 Input := First (Expressions (Inputs));
3609 while Present (Input) loop
3610 Analyze_Input_Item (Input);
3611 Next (Input);
3612 end loop;
3613 end if;
3614
3615 if Present (Component_Associations (Inputs)) then
3616 SPARK_Msg_N
3617 ("inputs must appear in named association form", Inputs);
3618 end if;
3619
3620 -- Single input item
3621
3622 else
3623 Analyze_Input_Item (Inputs);
3624 end if;
3625 end Analyze_Initialization_Item_With_Inputs;
3626
3627 --------------------------------
3628 -- Collect_States_And_Objects --
3629 --------------------------------
3630
3631 procedure Collect_States_And_Objects (Pack_Decl : Node_Id) is
3632 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
3633 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
3634 Decl : Node_Id;
3635 State_Elmt : Elmt_Id;
3636
3637 begin
3638 -- Collect the abstract states defined in the package (if any)
3639
3640 if Has_Non_Null_Abstract_State (Pack_Id) then
3641 State_Elmt := First_Elmt (Abstract_States (Pack_Id));
3642 while Present (State_Elmt) loop
3643 Append_New_Elmt (Node (State_Elmt), States_And_Objs);
3644 Next_Elmt (State_Elmt);
3645 end loop;
3646 end if;
3647
3648 -- Collect all objects that appear in the visible declarations of the
3649 -- related package.
3650
3651 Decl := First (Visible_Declarations (Pack_Spec));
3652 while Present (Decl) loop
3653 if Comes_From_Source (Decl)
3654 and then Nkind (Decl) in N_Object_Declaration
3655 | N_Object_Renaming_Declaration
3656 then
3657 Append_New_Elmt (Defining_Entity (Decl), States_And_Objs);
3658
3659 elsif Nkind (Decl) = N_Package_Declaration then
3660 Collect_States_And_Objects (Decl);
3661
3662 elsif Is_Single_Concurrent_Type_Declaration (Decl) then
3663 Append_New_Elmt
3664 (Anonymous_Object (Defining_Entity (Decl)),
3665 States_And_Objs);
3666 end if;
3667
3668 Next (Decl);
3669 end loop;
3670 end Collect_States_And_Objects;
3671
3672 -- Local variables
3673
3674 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3675 Init : Node_Id;
3676
3677 -- Start of processing for Analyze_Initializes_In_Decl_Part
3678
3679 begin
3680 -- Do not analyze the pragma multiple times
3681
3682 if Is_Analyzed_Pragma (N) then
3683 return;
3684 end if;
3685
3686 -- Nothing to do when the initialization list is empty
3687
3688 if Nkind (Inits) = N_Null then
3689 return;
3690 end if;
3691
3692 -- Single and multiple initialization clauses appear as an aggregate. If
3693 -- this is not the case, then either the parser or the analysis of the
3694 -- pragma failed to produce an aggregate.
3695
3696 pragma Assert (Nkind (Inits) = N_Aggregate);
3697
3698 -- Initialize the various lists used during analysis
3699
3700 Collect_States_And_Objects (Pack_Decl);
3701
3702 if Present (Expressions (Inits)) then
3703 Init := First (Expressions (Inits));
3704 while Present (Init) loop
3705 Analyze_Initialization_Item (Init);
3706 Next (Init);
3707 end loop;
3708 end if;
3709
3710 if Present (Component_Associations (Inits)) then
3711 Init := First (Component_Associations (Inits));
3712 while Present (Init) loop
3713 Analyze_Initialization_Item_With_Inputs (Init);
3714 Next (Init);
3715 end loop;
3716 end if;
3717
3718 -- Ensure that a state and a corresponding constituent do not appear
3719 -- together in pragma Initializes.
3720
3721 Check_State_And_Constituent_Use
3722 (States => States_Seen,
3723 Constits => Constits_Seen,
3724 Context => N);
3725
3726 Set_Is_Analyzed_Pragma (N);
3727 end Analyze_Initializes_In_Decl_Part;
3728
3729 ---------------------
3730 -- Analyze_Part_Of --
3731 ---------------------
3732
3733 procedure Analyze_Part_Of
3734 (Indic : Node_Id;
3735 Item_Id : Entity_Id;
3736 Encap : Node_Id;
3737 Encap_Id : out Entity_Id;
3738 Legal : out Boolean)
3739 is
3740 procedure Check_Part_Of_Abstract_State;
3741 pragma Inline (Check_Part_Of_Abstract_State);
3742 -- Verify the legality of indicator Part_Of when the encapsulator is an
3743 -- abstract state.
3744
3745 procedure Check_Part_Of_Concurrent_Type;
3746 pragma Inline (Check_Part_Of_Concurrent_Type);
3747 -- Verify the legality of indicator Part_Of when the encapsulator is a
3748 -- single concurrent type.
3749
3750 ----------------------------------
3751 -- Check_Part_Of_Abstract_State --
3752 ----------------------------------
3753
3754 procedure Check_Part_Of_Abstract_State is
3755 Pack_Id : Entity_Id;
3756 Placement : State_Space_Kind;
3757 Parent_Unit : Entity_Id;
3758
3759 begin
3760 -- Determine where the object, package instantiation or state lives
3761 -- with respect to the enclosing packages or package bodies.
3762
3763 Find_Placement_In_State_Space
3764 (Item_Id => Item_Id,
3765 Placement => Placement,
3766 Pack_Id => Pack_Id);
3767
3768 -- The item appears in a non-package construct with a declarative
3769 -- part (subprogram, block, etc). As such, the item is not allowed
3770 -- to be a part of an encapsulating state because the item is not
3771 -- visible.
3772
3773 if Placement = Not_In_Package then
3774 SPARK_Msg_N
3775 ("indicator Part_Of cannot appear in this context "
3776 & "(SPARK RM 7.2.6(5))", Indic);
3777
3778 Error_Msg_Name_1 := Chars (Scope (Encap_Id));
3779 SPARK_Msg_NE
3780 ("\& is not part of the hidden state of package %",
3781 Indic, Item_Id);
3782 return;
3783
3784 -- The item appears in the visible state space of some package. In
3785 -- general this scenario does not warrant Part_Of except when the
3786 -- package is a nongeneric private child unit and the encapsulating
3787 -- state is declared in a parent unit or a public descendant of that
3788 -- parent unit.
3789
3790 elsif Placement = Visible_State_Space then
3791 if Is_Child_Unit (Pack_Id)
3792 and then not Is_Generic_Unit (Pack_Id)
3793 and then Is_Private_Descendant (Pack_Id)
3794 then
3795 -- A variable or state abstraction which is part of the visible
3796 -- state of a nongeneric private child unit or its public
3797 -- descendants must have its Part_Of indicator specified. The
3798 -- Part_Of indicator must denote a state declared by either the
3799 -- parent unit of the private unit or by a public descendant of
3800 -- that parent unit.
3801
3802 -- Find the nearest private ancestor (which can be the current
3803 -- unit itself).
3804
3805 Parent_Unit := Pack_Id;
3806 while Present (Parent_Unit) loop
3807 exit when Is_Private_Library_Unit (Parent_Unit);
3808 Parent_Unit := Scope (Parent_Unit);
3809 end loop;
3810
3811 Parent_Unit := Scope (Parent_Unit);
3812
3813 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
3814 SPARK_Msg_NE
3815 ("indicator Part_Of must denote abstract state of & or of "
3816 & "its public descendant (SPARK RM 7.2.6(3))",
3817 Indic, Parent_Unit);
3818 return;
3819
3820 elsif Scope (Encap_Id) = Parent_Unit
3821 or else
3822 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id))
3823 and then not Is_Private_Descendant (Scope (Encap_Id)))
3824 then
3825 null;
3826
3827 else
3828 SPARK_Msg_NE
3829 ("indicator Part_Of must denote abstract state of & or of "
3830 & "its public descendant (SPARK RM 7.2.6(3))",
3831 Indic, Parent_Unit);
3832 return;
3833 end if;
3834
3835 -- Indicator Part_Of is not needed when the related package is
3836 -- not a nongeneric private child unit or a public descendant
3837 -- thereof.
3838
3839 else
3840 SPARK_Msg_N
3841 ("indicator Part_Of cannot appear in this context "
3842 & "(SPARK RM 7.2.6(5))", Indic);
3843
3844 Error_Msg_Name_1 := Chars (Pack_Id);
3845 SPARK_Msg_NE
3846 ("\& is declared in the visible part of package %",
3847 Indic, Item_Id);
3848 return;
3849 end if;
3850
3851 -- When the item appears in the private state space of a package, the
3852 -- encapsulating state must be declared in the same package.
3853
3854 elsif Placement = Private_State_Space then
3855
3856 -- In the case of the abstract state of a nongeneric private
3857 -- child package, it may be encapsulated in the state of a
3858 -- public descendant of its parent package.
3859
3860 declare
3861 function Is_Public_Descendant
3862 (Child, Ancestor : Entity_Id)
3863 return Boolean;
3864 -- Return True if Child is a public descendant of Pack
3865
3866 --------------------------
3867 -- Is_Public_Descendant --
3868 --------------------------
3869
3870 function Is_Public_Descendant
3871 (Child, Ancestor : Entity_Id)
3872 return Boolean
3873 is
3874 P : Entity_Id := Child;
3875 begin
3876 while Is_Child_Unit (P)
3877 and then not Is_Private_Library_Unit (P)
3878 loop
3879 if Scope (P) = Ancestor then
3880 return True;
3881 end if;
3882
3883 P := Scope (P);
3884 end loop;
3885
3886 return False;
3887 end Is_Public_Descendant;
3888
3889 -- Local variables
3890
3891 Immediate_Pack_Id : constant Entity_Id := Scope (Item_Id);
3892
3893 Is_State_Of_Private_Child : constant Boolean :=
3894 Is_Child_Unit (Immediate_Pack_Id)
3895 and then not Is_Generic_Unit (Immediate_Pack_Id)
3896 and then Is_Private_Descendant (Immediate_Pack_Id);
3897
3898 Is_OK_Through_Sibling : Boolean := False;
3899
3900 begin
3901 if Ekind (Item_Id) = E_Abstract_State
3902 and then Is_State_Of_Private_Child
3903 and then Is_Public_Descendant (Scope (Encap_Id), Pack_Id)
3904 then
3905 Is_OK_Through_Sibling := True;
3906 end if;
3907
3908 if Scope (Encap_Id) /= Pack_Id
3909 and then not Is_OK_Through_Sibling
3910 then
3911 if Is_State_Of_Private_Child then
3912 SPARK_Msg_NE
3913 ("indicator Part_Of must denote abstract state of & "
3914 & "or of its public descendant "
3915 & "(SPARK RM 7.2.6(3))", Indic, Pack_Id);
3916 else
3917 SPARK_Msg_NE
3918 ("indicator Part_Of must denote an abstract state of "
3919 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3920 end if;
3921
3922 Error_Msg_Name_1 := Chars (Pack_Id);
3923 SPARK_Msg_NE
3924 ("\& is declared in the private part of package %",
3925 Indic, Item_Id);
3926 return;
3927 end if;
3928 end;
3929
3930 -- Items declared in the body state space of a package do not need
3931 -- Part_Of indicators as the refinement has already been seen.
3932
3933 else
3934 SPARK_Msg_N
3935 ("indicator Part_Of cannot appear in this context "
3936 & "(SPARK RM 7.2.6(5))", Indic);
3937
3938 if Scope (Encap_Id) = Pack_Id then
3939 Error_Msg_Name_1 := Chars (Pack_Id);
3940 SPARK_Msg_NE
3941 ("\& is declared in the body of package %", Indic, Item_Id);
3942 end if;
3943
3944 return;
3945 end if;
3946
3947 -- In the case of state in a (descendant of a private) child which
3948 -- is Part_Of the state of another package, the package defining the
3949 -- encapsulating abstract state should have a body, to ensure that it
3950 -- has a state refinement (SPARK RM 7.1.4(4)).
3951
3952 if Enclosing_Comp_Unit_Node (Encap_Id) /=
3953 Enclosing_Comp_Unit_Node (Item_Id)
3954 and then not Unit_Requires_Body (Scope (Encap_Id))
3955 then
3956 SPARK_Msg_N
3957 ("indicator Part_Of must denote abstract state of package "
3958 & "with a body (SPARK RM 7.1.4(4))", Indic);
3959 return;
3960 end if;
3961
3962 -- At this point it is known that the Part_Of indicator is legal
3963
3964 Legal := True;
3965 end Check_Part_Of_Abstract_State;
3966
3967 -----------------------------------
3968 -- Check_Part_Of_Concurrent_Type --
3969 -----------------------------------
3970
3971 procedure Check_Part_Of_Concurrent_Type is
3972 function In_Proper_Order
3973 (First : Node_Id;
3974 Second : Node_Id) return Boolean;
3975 pragma Inline (In_Proper_Order);
3976 -- Determine whether node First precedes node Second
3977
3978 procedure Placement_Error;
3979 pragma Inline (Placement_Error);
3980 -- Emit an error concerning the illegal placement of the item with
3981 -- respect to the single concurrent type.
3982
3983 ---------------------
3984 -- In_Proper_Order --
3985 ---------------------
3986
3987 function In_Proper_Order
3988 (First : Node_Id;
3989 Second : Node_Id) return Boolean
3990 is
3991 N : Node_Id;
3992
3993 begin
3994 if List_Containing (First) = List_Containing (Second) then
3995 N := First;
3996 while Present (N) loop
3997 if N = Second then
3998 return True;
3999 end if;
4000
4001 Next (N);
4002 end loop;
4003 end if;
4004
4005 return False;
4006 end In_Proper_Order;
4007
4008 ---------------------
4009 -- Placement_Error --
4010 ---------------------
4011
4012 procedure Placement_Error is
4013 begin
4014 SPARK_Msg_N
4015 ("indicator Part_Of must denote a previously declared single "
4016 & "protected type or single task type", Encap);
4017 end Placement_Error;
4018
4019 -- Local variables
4020
4021 Conc_Typ : constant Entity_Id := Etype (Encap_Id);
4022 Encap_Decl : constant Node_Id := Declaration_Node (Encap_Id);
4023 Encap_Context : constant Node_Id := Parent (Encap_Decl);
4024
4025 Item_Context : Node_Id;
4026 Item_Decl : Node_Id;
4027 Prv_Decls : List_Id;
4028 Vis_Decls : List_Id;
4029
4030 -- Start of processing for Check_Part_Of_Concurrent_Type
4031
4032 begin
4033 -- Only abstract states and variables can act as constituents of an
4034 -- encapsulating single concurrent type.
4035
4036 if Ekind (Item_Id) in E_Abstract_State | E_Variable then
4037 null;
4038
4039 -- The constituent is a constant
4040
4041 elsif Ekind (Item_Id) = E_Constant then
4042 Error_Msg_Name_1 := Chars (Encap_Id);
4043 SPARK_Msg_NE
4044 (Fix_Msg (Conc_Typ, "constant & cannot act as constituent of "
4045 & "single protected type %"), Indic, Item_Id);
4046 return;
4047
4048 -- The constituent is a package instantiation
4049
4050 else
4051 Error_Msg_Name_1 := Chars (Encap_Id);
4052 SPARK_Msg_NE
4053 (Fix_Msg (Conc_Typ, "package instantiation & cannot act as "
4054 & "constituent of single protected type %"), Indic, Item_Id);
4055 return;
4056 end if;
4057
4058 -- When the item denotes an abstract state of a nested package, use
4059 -- the declaration of the package to detect proper placement.
4060
4061 -- package Pack is
4062 -- task T;
4063 -- package Nested
4064 -- with Abstract_State => (State with Part_Of => T)
4065
4066 if Ekind (Item_Id) = E_Abstract_State then
4067 Item_Decl := Unit_Declaration_Node (Scope (Item_Id));
4068 else
4069 Item_Decl := Declaration_Node (Item_Id);
4070 end if;
4071
4072 Item_Context := Parent (Item_Decl);
4073
4074 -- The item and the single concurrent type must appear in the same
4075 -- declarative region, with the item following the declaration of
4076 -- the single concurrent type (SPARK RM 9(3)).
4077
4078 if Item_Context = Encap_Context then
4079 if Nkind (Item_Context) in N_Package_Specification
4080 | N_Protected_Definition
4081 | N_Task_Definition
4082 then
4083 Prv_Decls := Private_Declarations (Item_Context);
4084 Vis_Decls := Visible_Declarations (Item_Context);
4085
4086 -- The placement is OK when the single concurrent type appears
4087 -- within the visible declarations and the item in the private
4088 -- declarations.
4089 --
4090 -- package Pack is
4091 -- protected PO ...
4092 -- private
4093 -- Constit : ... with Part_Of => PO;
4094 -- end Pack;
4095
4096 if List_Containing (Encap_Decl) = Vis_Decls
4097 and then List_Containing (Item_Decl) = Prv_Decls
4098 then
4099 null;
4100
4101 -- The placement is illegal when the item appears within the
4102 -- visible declarations and the single concurrent type is in
4103 -- the private declarations.
4104 --
4105 -- package Pack is
4106 -- Constit : ... with Part_Of => PO;
4107 -- private
4108 -- protected PO ...
4109 -- end Pack;
4110
4111 elsif List_Containing (Item_Decl) = Vis_Decls
4112 and then List_Containing (Encap_Decl) = Prv_Decls
4113 then
4114 Placement_Error;
4115 return;
4116
4117 -- Otherwise both the item and the single concurrent type are
4118 -- in the same list. Ensure that the declaration of the single
4119 -- concurrent type precedes that of the item.
4120
4121 elsif not In_Proper_Order
4122 (First => Encap_Decl,
4123 Second => Item_Decl)
4124 then
4125 Placement_Error;
4126 return;
4127 end if;
4128
4129 -- Otherwise both the item and the single concurrent type are
4130 -- in the same list. Ensure that the declaration of the single
4131 -- concurrent type precedes that of the item.
4132
4133 elsif not In_Proper_Order
4134 (First => Encap_Decl,
4135 Second => Item_Decl)
4136 then
4137 Placement_Error;
4138 return;
4139 end if;
4140
4141 -- Otherwise the item and the single concurrent type reside within
4142 -- unrelated regions.
4143
4144 else
4145 Error_Msg_Name_1 := Chars (Encap_Id);
4146 SPARK_Msg_NE
4147 (Fix_Msg (Conc_Typ, "constituent & must be declared "
4148 & "immediately within the same region as single protected "
4149 & "type %"), Indic, Item_Id);
4150 return;
4151 end if;
4152
4153 -- At this point it is known that the Part_Of indicator is legal
4154
4155 Legal := True;
4156 end Check_Part_Of_Concurrent_Type;
4157
4158 -- Start of processing for Analyze_Part_Of
4159
4160 begin
4161 -- Assume that the indicator is illegal
4162
4163 Encap_Id := Empty;
4164 Legal := False;
4165
4166 if Nkind (Encap) in
4167 N_Expanded_Name | N_Identifier | N_Selected_Component
4168 then
4169 Analyze (Encap);
4170 Resolve_State (Encap);
4171
4172 Encap_Id := Entity (Encap);
4173
4174 -- The encapsulator is an abstract state
4175
4176 if Ekind (Encap_Id) = E_Abstract_State then
4177 null;
4178
4179 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
4180
4181 elsif Is_Single_Concurrent_Object (Encap_Id) then
4182 null;
4183
4184 -- Otherwise the encapsulator is not a legal choice
4185
4186 else
4187 SPARK_Msg_N
4188 ("indicator Part_Of must denote abstract state, single "
4189 & "protected type or single task type", Encap);
4190 return;
4191 end if;
4192
4193 -- This is a syntax error, always report
4194
4195 else
4196 Error_Msg_N
4197 ("indicator Part_Of must denote abstract state, single protected "
4198 & "type or single task type", Encap);
4199 return;
4200 end if;
4201
4202 -- Catch a case where indicator Part_Of denotes the abstract view of a
4203 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
4204
4205 if From_Limited_With (Encap_Id)
4206 and then Present (Non_Limited_View (Encap_Id))
4207 and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable
4208 then
4209 SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap);
4210 SPARK_Msg_N ("\& denotes abstract view of object", Encap);
4211 return;
4212 end if;
4213
4214 -- The encapsulator is an abstract state
4215
4216 if Ekind (Encap_Id) = E_Abstract_State then
4217 Check_Part_Of_Abstract_State;
4218
4219 -- The encapsulator is a single concurrent type
4220
4221 else
4222 Check_Part_Of_Concurrent_Type;
4223 end if;
4224 end Analyze_Part_Of;
4225
4226 ----------------------------------
4227 -- Analyze_Part_Of_In_Decl_Part --
4228 ----------------------------------
4229
4230 procedure Analyze_Part_Of_In_Decl_Part
4231 (N : Node_Id;
4232 Freeze_Id : Entity_Id := Empty)
4233 is
4234 Encap : constant Node_Id :=
4235 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
4236 Errors : constant Nat := Serious_Errors_Detected;
4237 Var_Decl : constant Node_Id := Find_Related_Context (N);
4238 Var_Id : constant Entity_Id := Defining_Entity (Var_Decl);
4239 Constits : Elist_Id;
4240 Encap_Id : Entity_Id;
4241 Legal : Boolean;
4242
4243 begin
4244 -- Detect any discrepancies between the placement of the variable with
4245 -- respect to general state space and the encapsulating state or single
4246 -- concurrent type.
4247
4248 Analyze_Part_Of
4249 (Indic => N,
4250 Item_Id => Var_Id,
4251 Encap => Encap,
4252 Encap_Id => Encap_Id,
4253 Legal => Legal);
4254
4255 -- The Part_Of indicator turns the variable into a constituent of the
4256 -- encapsulating state or single concurrent type.
4257
4258 if Legal then
4259 pragma Assert (Present (Encap_Id));
4260 Constits := Part_Of_Constituents (Encap_Id);
4261
4262 if No (Constits) then
4263 Constits := New_Elmt_List;
4264 Set_Part_Of_Constituents (Encap_Id, Constits);
4265 end if;
4266
4267 Append_Elmt (Var_Id, Constits);
4268 Set_Encapsulating_State (Var_Id, Encap_Id);
4269
4270 -- A Part_Of constituent partially refines an abstract state. This
4271 -- property does not apply to protected or task units.
4272
4273 if Ekind (Encap_Id) = E_Abstract_State then
4274 Set_Has_Partial_Visible_Refinement (Encap_Id);
4275 end if;
4276 end if;
4277
4278 -- Emit a clarification message when the encapsulator is undefined,
4279 -- possibly due to contract freezing.
4280
4281 if Errors /= Serious_Errors_Detected
4282 and then Present (Freeze_Id)
4283 and then Has_Undefined_Reference (Encap)
4284 then
4285 Contract_Freeze_Error (Var_Id, Freeze_Id);
4286 end if;
4287 end Analyze_Part_Of_In_Decl_Part;
4288
4289 --------------------
4290 -- Analyze_Pragma --
4291 --------------------
4292
4293 procedure Analyze_Pragma (N : Node_Id) is
4294 Loc : constant Source_Ptr := Sloc (N);
4295
4296 Pname : Name_Id := Pragma_Name (N);
4297 -- Name of the source pragma, or name of the corresponding aspect for
4298 -- pragmas which originate in a source aspect. In the latter case, the
4299 -- name may be different from the pragma name.
4300
4301 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
4302
4303 Pragma_Exit : exception;
4304 -- This exception is used to exit pragma processing completely. It
4305 -- is used when an error is detected, and no further processing is
4306 -- required. It is also used if an earlier error has left the tree in
4307 -- a state where the pragma should not be processed.
4308
4309 Arg_Count : Nat;
4310 -- Number of pragma argument associations
4311
4312 Arg1 : Node_Id;
4313 Arg2 : Node_Id;
4314 Arg3 : Node_Id;
4315 Arg4 : Node_Id;
4316 Arg5 : Node_Id;
4317 -- First five pragma arguments (pragma argument association nodes, or
4318 -- Empty if the corresponding argument does not exist).
4319
4320 type Name_List is array (Natural range <>) of Name_Id;
4321 type Args_List is array (Natural range <>) of Node_Id;
4322 -- Types used for arguments to Check_Arg_Order and Gather_Associations
4323
4324 -----------------------
4325 -- Local Subprograms --
4326 -----------------------
4327
4328 procedure Ada_2005_Pragma;
4329 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
4330 -- Ada 95 mode, these are implementation defined pragmas, so should be
4331 -- caught by the No_Implementation_Pragmas restriction.
4332
4333 procedure Ada_2012_Pragma;
4334 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
4335 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
4336 -- should be caught by the No_Implementation_Pragmas restriction.
4337
4338 procedure Analyze_Depends_Global
4339 (Spec_Id : out Entity_Id;
4340 Subp_Decl : out Node_Id;
4341 Legal : out Boolean);
4342 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
4343 -- legality of the placement and related context of the pragma. Spec_Id
4344 -- is the entity of the related subprogram. Subp_Decl is the declaration
4345 -- of the related subprogram. Sets flag Legal when the pragma is legal.
4346
4347 procedure Analyze_If_Present (Id : Pragma_Id);
4348 -- Inspect the remainder of the list containing pragma N and look for
4349 -- a pragma that matches Id. If found, analyze the pragma.
4350
4351 procedure Analyze_Pre_Post_Condition;
4352 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
4353
4354 procedure Analyze_Refined_Depends_Global_Post
4355 (Spec_Id : out Entity_Id;
4356 Body_Id : out Entity_Id;
4357 Legal : out Boolean);
4358 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
4359 -- Refined_Global and Refined_Post. Verify the legality of the placement
4360 -- and related context of the pragma. Spec_Id is the entity of the
4361 -- related subprogram. Body_Id is the entity of the subprogram body.
4362 -- Flag Legal is set when the pragma is legal.
4363
4364 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False);
4365 -- Perform full analysis of pragma Unmodified and the write aspect of
4366 -- pragma Unused. Flag Is_Unused should be set when verifying the
4367 -- semantics of pragma Unused.
4368
4369 procedure Analyze_Unreferenced_Or_Unused (Is_Unused : Boolean := False);
4370 -- Perform full analysis of pragma Unreferenced and the read aspect of
4371 -- pragma Unused. Flag Is_Unused should be set when verifying the
4372 -- semantics of pragma Unused.
4373
4374 procedure Check_Ada_83_Warning;
4375 -- Issues a warning message for the current pragma if operating in Ada
4376 -- 83 mode (used for language pragmas that are not a standard part of
4377 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
4378 -- of 95 pragma.
4379
4380 procedure Check_Arg_Count (Required : Nat);
4381 -- Check argument count for pragma is equal to given parameter. If not,
4382 -- then issue an error message and raise Pragma_Exit.
4383
4384 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
4385 -- Arg which can either be a pragma argument association, in which case
4386 -- the check is applied to the expression of the association or an
4387 -- expression directly.
4388
4389 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
4390 -- Check that an argument has the right form for an EXTERNAL_NAME
4391 -- parameter of an extended import/export pragma. The rule is that the
4392 -- name must be an identifier or string literal (in Ada 83 mode) or a
4393 -- static string expression (in Ada 95 mode).
4394
4395 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
4396 -- Check the specified argument Arg to make sure that it is an
4397 -- identifier. If not give error and raise Pragma_Exit.
4398
4399 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
4400 -- Check the specified argument Arg to make sure that it is an integer
4401 -- literal. If not give error and raise Pragma_Exit.
4402
4403 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
4404 -- Check the specified argument Arg to make sure that it has the proper
4405 -- syntactic form for a local name and meets the semantic requirements
4406 -- for a local name. The local name is analyzed as part of the
4407 -- processing for this call. In addition, the local name is required
4408 -- to represent an entity at the library level.
4409
4410 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
4411 -- Check the specified argument Arg to make sure that it has the proper
4412 -- syntactic form for a local name and meets the semantic requirements
4413 -- for a local name. The local name is analyzed as part of the
4414 -- processing for this call.
4415
4416 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
4417 -- Check the specified argument Arg to make sure that it is a valid
4418 -- locking policy name. If not give error and raise Pragma_Exit.
4419
4420 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
4421 -- Check the specified argument Arg to make sure that it is a valid
4422 -- elaboration policy name. If not give error and raise Pragma_Exit.
4423
4424 procedure Check_Arg_Is_One_Of
4425 (Arg : Node_Id;
4426 N1, N2 : Name_Id);
4427 procedure Check_Arg_Is_One_Of
4428 (Arg : Node_Id;
4429 N1, N2, N3 : Name_Id);
4430 procedure Check_Arg_Is_One_Of
4431 (Arg : Node_Id;
4432 N1, N2, N3, N4 : Name_Id);
4433 procedure Check_Arg_Is_One_Of
4434 (Arg : Node_Id;
4435 N1, N2, N3, N4, N5 : Name_Id);
4436 -- Check the specified argument Arg to make sure that it is an
4437 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
4438 -- present). If not then give error and raise Pragma_Exit.
4439
4440 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
4441 -- Check the specified argument Arg to make sure that it is a valid
4442 -- queuing policy name. If not give error and raise Pragma_Exit.
4443
4444 procedure Check_Arg_Is_OK_Static_Expression
4445 (Arg : Node_Id;
4446 Typ : Entity_Id := Empty);
4447 -- Check the specified argument Arg to make sure that it is a static
4448 -- expression of the given type (i.e. it will be analyzed and resolved
4449 -- using this type, which can be any valid argument to Resolve, e.g.
4450 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
4451 -- Typ is left Empty, then any static expression is allowed. Includes
4452 -- checking that the argument does not raise Constraint_Error.
4453
4454 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
4455 -- Check the specified argument Arg to make sure that it is a valid task
4456 -- dispatching policy name. If not give error and raise Pragma_Exit.
4457
4458 procedure Check_Arg_Order (Names : Name_List);
4459 -- Checks for an instance of two arguments with identifiers for the
4460 -- current pragma which are not in the sequence indicated by Names,
4461 -- and if so, generates a fatal message about bad order of arguments.
4462
4463 procedure Check_At_Least_N_Arguments (N : Nat);
4464 -- Check there are at least N arguments present
4465
4466 procedure Check_At_Most_N_Arguments (N : Nat);
4467 -- Check there are no more than N arguments present
4468
4469 procedure Check_Component
4470 (Comp : Node_Id;
4471 UU_Typ : Entity_Id;
4472 In_Variant_Part : Boolean := False);
4473 -- Examine an Unchecked_Union component for correct use of per-object
4474 -- constrained subtypes, and for restrictions on finalizable components.
4475 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
4476 -- should be set when Comp comes from a record variant.
4477
4478 procedure Check_Duplicate_Pragma (E : Entity_Id);
4479 -- Check if a rep item of the same name as the current pragma is already
4480 -- chained as a rep pragma to the given entity. If so give a message
4481 -- about the duplicate, and then raise Pragma_Exit so does not return.
4482 -- Note that if E is a type, then this routine avoids flagging a pragma
4483 -- which applies to a parent type from which E is derived.
4484
4485 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
4486 -- Nam is an N_String_Literal node containing the external name set by
4487 -- an Import or Export pragma (or extended Import or Export pragma).
4488 -- This procedure checks for possible duplications if this is the export
4489 -- case, and if found, issues an appropriate error message.
4490
4491 procedure Check_Expr_Is_OK_Static_Expression
4492 (Expr : Node_Id;
4493 Typ : Entity_Id := Empty);
4494 -- Check the specified expression Expr to make sure that it is a static
4495 -- expression of the given type (i.e. it will be analyzed and resolved
4496 -- using this type, which can be any valid argument to Resolve, e.g.
4497 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
4498 -- Typ is left Empty, then any static expression is allowed. Includes
4499 -- checking that the expression does not raise Constraint_Error.
4500
4501 procedure Check_First_Subtype (Arg : Node_Id);
4502 -- Checks that Arg, whose expression is an entity name, references a
4503 -- first subtype.
4504
4505 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
4506 -- Checks that the given argument has an identifier, and if so, requires
4507 -- it to match the given identifier name. If there is no identifier, or
4508 -- a non-matching identifier, then an error message is given and
4509 -- Pragma_Exit is raised.
4510
4511 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
4512 -- Checks that the given argument has an identifier, and if so, requires
4513 -- it to match one of the given identifier names. If there is no
4514 -- identifier, or a non-matching identifier, then an error message is
4515 -- given and Pragma_Exit is raised.
4516
4517 procedure Check_In_Main_Program;
4518 -- Common checks for pragmas that appear within a main program
4519 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
4520
4521 procedure Check_Interrupt_Or_Attach_Handler;
4522 -- Common processing for first argument of pragma Interrupt_Handler or
4523 -- pragma Attach_Handler.
4524
4525 procedure Check_Loop_Pragma_Placement;
4526 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
4527 -- appear immediately within a construct restricted to loops, and that
4528 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
4529
4530 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
4531 -- Check that pragma appears in a declarative part, or in a package
4532 -- specification, i.e. that it does not occur in a statement sequence
4533 -- in a body.
4534
4535 procedure Check_No_Identifier (Arg : Node_Id);
4536 -- Checks that the given argument does not have an identifier. If
4537 -- an identifier is present, then an error message is issued, and
4538 -- Pragma_Exit is raised.
4539
4540 procedure Check_No_Identifiers;
4541 -- Checks that none of the arguments to the pragma has an identifier.
4542 -- If any argument has an identifier, then an error message is issued,
4543 -- and Pragma_Exit is raised.
4544
4545 procedure Check_No_Link_Name;
4546 -- Checks that no link name is specified
4547
4548 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
4549 -- Checks if the given argument has an identifier, and if so, requires
4550 -- it to match the given identifier name. If there is a non-matching
4551 -- identifier, then an error message is given and Pragma_Exit is raised.
4552
4553 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
4554 -- Checks if the given argument has an identifier, and if so, requires
4555 -- it to match the given identifier name. If there is a non-matching
4556 -- identifier, then an error message is given and Pragma_Exit is raised.
4557 -- In this version of the procedure, the identifier name is given as
4558 -- a string with lower case letters.
4559
4560 procedure Check_Static_Boolean_Expression (Expr : Node_Id);
4561 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
4562 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
4563 -- Extensions_Visible, Side_Effects and Volatile_Function. Ensure
4564 -- that expression Expr is an OK static boolean expression. Emit an
4565 -- error if this is not the case.
4566
4567 procedure Check_Static_Constraint (Constr : Node_Id);
4568 -- Constr is a constraint from an N_Subtype_Indication node from a
4569 -- component constraint in an Unchecked_Union type, a range, or a
4570 -- discriminant association. This routine checks that the constraint
4571 -- is static as required by the restrictions for Unchecked_Union.
4572
4573 procedure Check_Valid_Configuration_Pragma;
4574 -- Legality checks for placement of a configuration pragma
4575
4576 procedure Check_Valid_Library_Unit_Pragma;
4577 -- Legality checks for library unit pragmas. A special case arises for
4578 -- pragmas in generic instances that come from copies of the original
4579 -- library unit pragmas in the generic templates. In the case of other
4580 -- than library level instantiations these can appear in contexts which
4581 -- would normally be invalid (they only apply to the original template
4582 -- and to library level instantiations), and they are simply ignored,
4583 -- which is implemented by rewriting them as null statements and
4584 -- optionally raising Pragma_Exit to terminate analysis. An exception
4585 -- is not always raised to avoid exception propagation during the
4586 -- bootstrap, so all callers should check whether N has been rewritten.
4587
4588 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
4589 -- Check an Unchecked_Union variant for lack of nested variants and
4590 -- presence of at least one component. UU_Typ is the related Unchecked_
4591 -- Union type.
4592
4593 procedure Ensure_Aggregate_Form (Arg : Node_Id);
4594 -- Subsidiary routine to the processing of pragmas Abstract_State,
4595 -- Contract_Cases, Depends, Exceptional_Cases, Global, Initializes,
4596 -- Refined_Depends, Refined_Global, Refined_State and
4597 -- Subprogram_Variant. Transform argument Arg into an aggregate if not
4598 -- one already. N_Null is never transformed. Arg may denote an aspect
4599 -- specification or a pragma argument association.
4600
4601 procedure Error_Pragma (Msg : String);
4602 pragma No_Return (Error_Pragma);
4603 -- Outputs error message for current pragma. The message contains a %
4604 -- that will be replaced with the pragma name, and the flag is placed
4605 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
4606 -- calls Fix_Error (see spec of that procedure for details).
4607
4608 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
4609 pragma No_Return (Error_Pragma_Arg);
4610 -- Outputs error message for current pragma. The message may contain
4611 -- a % that will be replaced with the pragma name. The parameter Arg
4612 -- may either be a pragma argument association, in which case the flag
4613 -- is placed on the expression of this association, or an expression,
4614 -- in which case the flag is placed directly on the expression. The
4615 -- message is placed using Error_Msg_N, so the message may also contain
4616 -- an & insertion character which will reference the given Arg value.
4617 -- After placing the message, Pragma_Exit is raised. Note: this routine
4618 -- calls Fix_Error (see spec of that procedure for details).
4619
4620 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
4621 pragma No_Return (Error_Pragma_Arg);
4622 -- Similar to above form of Error_Pragma_Arg except that two messages
4623 -- are provided, the second is a continuation comment starting with \.
4624
4625 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
4626 pragma No_Return (Error_Pragma_Arg_Ident);
4627 -- Outputs error message for current pragma. The message may contain a %
4628 -- that will be replaced with the pragma name. The parameter Arg must be
4629 -- a pragma argument association with a non-empty identifier (i.e. its
4630 -- Chars field must be set), and the error message is placed on the
4631 -- identifier. The message is placed using Error_Msg_N so the message
4632 -- may also contain an & insertion character which will reference
4633 -- the identifier. After placing the message, Pragma_Exit is raised.
4634 -- Note: this routine calls Fix_Error (see spec of that procedure for
4635 -- details).
4636
4637 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
4638 pragma No_Return (Error_Pragma_Ref);
4639 -- Outputs error message for current pragma. The message may contain
4640 -- a % that will be replaced with the pragma name. The parameter Ref
4641 -- must be an entity whose name can be referenced by & and sloc by #.
4642 -- After placing the message, Pragma_Exit is raised. Note: this routine
4643 -- calls Fix_Error (see spec of that procedure for details).
4644
4645 function Find_Lib_Unit_Name return Entity_Id;
4646 -- Used for a library unit pragma to find the entity to which the
4647 -- library unit pragma applies, returns the entity found.
4648
4649 procedure Find_Program_Unit_Name (Id : Node_Id);
4650 -- If the pragma is a compilation unit pragma, the id must denote the
4651 -- compilation unit in the same compilation, and the pragma must appear
4652 -- in the list of preceding or trailing pragmas. If it is a program
4653 -- unit pragma that is not a compilation unit pragma, then the
4654 -- identifier must be visible.
4655
4656 function Find_Unique_Parameterless_Procedure
4657 (Name : Entity_Id;
4658 Arg : Node_Id) return Entity_Id;
4659 -- Used for a procedure pragma to find the unique parameterless
4660 -- procedure identified by Name, returns it if it exists, otherwise
4661 -- errors out and uses Arg as the pragma argument for the message.
4662
4663 function Fix_Error (Msg : String) return String;
4664 -- This is called prior to issuing an error message. Msg is the normal
4665 -- error message issued in the pragma case. This routine checks for the
4666 -- case of a pragma coming from an aspect in the source, and returns a
4667 -- message suitable for the aspect case as follows:
4668 --
4669 -- Each substring "pragma" is replaced by "aspect"
4670 --
4671 -- If "argument of" is at the start of the error message text, it is
4672 -- replaced by "entity for".
4673 --
4674 -- If "argument" is at the start of the error message text, it is
4675 -- replaced by "entity".
4676 --
4677 -- So for example, "argument of pragma X must be discrete type"
4678 -- returns "entity for aspect X must be a discrete type".
4679
4680 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
4681 -- be different from the pragma name). If the current pragma results
4682 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
4683 -- original pragma name.
4684
4685 procedure Gather_Associations
4686 (Names : Name_List;
4687 Args : out Args_List);
4688 -- This procedure is used to gather the arguments for a pragma that
4689 -- permits arbitrary ordering of parameters using the normal rules
4690 -- for named and positional parameters. The Names argument is a list
4691 -- of Name_Id values that corresponds to the allowed pragma argument
4692 -- association identifiers in order. The result returned in Args is
4693 -- a list of corresponding expressions that are the pragma arguments.
4694 -- Note that this is a list of expressions, not of pragma argument
4695 -- associations (Gather_Associations has completely checked all the
4696 -- optional identifiers when it returns). An entry in Args is Empty
4697 -- on return if the corresponding argument is not present.
4698
4699 procedure GNAT_Pragma;
4700 -- Called for all GNAT defined pragmas to check the relevant restriction
4701 -- (No_Implementation_Pragmas).
4702
4703 function Is_Before_First_Decl
4704 (Pragma_Node : Node_Id;
4705 Decls : List_Id) return Boolean;
4706 -- Return True if Pragma_Node is before the first declarative item in
4707 -- Decls where Decls is the list of declarative items.
4708
4709 function Is_Configuration_Pragma return Boolean;
4710 -- Determines if the placement of the current pragma is appropriate
4711 -- for a configuration pragma.
4712
4713 function Is_In_Context_Clause return Boolean;
4714 -- Returns True if pragma appears within the context clause of a unit,
4715 -- and False for any other placement (does not generate any messages).
4716
4717 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
4718 -- Analyzes the argument, and determines if it is a static string
4719 -- expression, returns True if so, False if non-static or not String.
4720 -- A special case is that a string literal returns True in Ada 83 mode
4721 -- (which has no such thing as static string expressions). Note that
4722 -- the call analyzes its argument, so this cannot be used for the case
4723 -- where an identifier might not be declared.
4724
4725 procedure Pragma_Misplaced;
4726 pragma No_Return (Pragma_Misplaced);
4727 -- Issue fatal error message for misplaced pragma
4728
4729 procedure Process_Atomic_Independent_Shared_Volatile;
4730 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
4731 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
4732 -- and treated as being identical in effect to pragma Atomic.
4733
4734 procedure Process_Compile_Time_Warning_Or_Error;
4735 -- Common processing for Compile_Time_Error and Compile_Time_Warning
4736
4737 procedure Process_Convention
4738 (C : out Convention_Id;
4739 Ent : out Entity_Id);
4740 -- Common processing for Convention, Interface, Import and Export.
4741 -- Checks first two arguments of pragma, and sets the appropriate
4742 -- convention value in the specified entity or entities. On return
4743 -- C is the convention, Ent is the referenced entity.
4744
4745 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
4746 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
4747 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
4748
4749 procedure Process_Extended_Import_Export_Object_Pragma
4750 (Arg_Internal : Node_Id;
4751 Arg_External : Node_Id;
4752 Arg_Size : Node_Id);
4753 -- Common processing for the pragmas Import/Export_Object. The three
4754 -- arguments correspond to the three named parameters of the pragmas. An
4755 -- argument is empty if the corresponding parameter is not present in
4756 -- the pragma.
4757
4758 procedure Process_Extended_Import_Export_Internal_Arg
4759 (Arg_Internal : Node_Id := Empty);
4760 -- Common processing for all extended Import and Export pragmas. The
4761 -- argument is the pragma parameter for the Internal argument. If
4762 -- Arg_Internal is empty or inappropriate, an error message is posted.
4763 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
4764 -- set to identify the referenced entity.
4765
4766 procedure Process_Extended_Import_Export_Subprogram_Pragma
4767 (Arg_Internal : Node_Id;
4768 Arg_External : Node_Id;
4769 Arg_Parameter_Types : Node_Id;
4770 Arg_Result_Type : Node_Id := Empty;
4771 Arg_Mechanism : Node_Id;
4772 Arg_Result_Mechanism : Node_Id := Empty);
4773 -- Common processing for all extended Import and Export pragmas applying
4774 -- to subprograms. The caller omits any arguments that do not apply to
4775 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
4776 -- only in the Import_Function and Export_Function cases). The argument
4777 -- names correspond to the allowed pragma association identifiers.
4778
4779 procedure Process_Generic_List;
4780 -- Common processing for Share_Generic and Inline_Generic
4781
4782 procedure Process_Import_Or_Interface;
4783 -- Common processing for Import or Interface
4784
4785 procedure Process_Import_Predefined_Type;
4786 -- Processing for completing a type with pragma Import. This is used
4787 -- to declare types that match predefined C types, especially for cases
4788 -- without corresponding Ada predefined type.
4789
4790 type Inline_Status is (Suppressed, Disabled, Enabled);
4791 -- Inline status of a subprogram, indicated as follows:
4792 -- Suppressed: inlining is suppressed for the subprogram
4793 -- Disabled: no inlining is requested for the subprogram
4794 -- Enabled: inlining is requested/required for the subprogram
4795
4796 procedure Process_Inline (Status : Inline_Status);
4797 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
4798 -- indicates the inline status specified by the pragma.
4799
4800 procedure Process_Interface_Name
4801 (Subprogram_Def : Entity_Id;
4802 Ext_Arg : Node_Id;
4803 Link_Arg : Node_Id;
4804 Prag : Node_Id);
4805 -- Given the last two arguments of pragma Import, pragma Export, or
4806 -- pragma Interface_Name, performs validity checks and sets the
4807 -- Interface_Name field of the given subprogram entity to the
4808 -- appropriate external or link name, depending on the arguments given.
4809 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
4810 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
4811 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
4812 -- nor Link_Arg is present, the interface name is set to the default
4813 -- from the subprogram name. In addition, the pragma itself is passed
4814 -- to analyze any expressions in the case the pragma came from an aspect
4815 -- specification.
4816
4817 procedure Process_Interrupt_Or_Attach_Handler;
4818 -- Common processing for Interrupt and Attach_Handler pragmas
4819
4820 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
4821 -- Common processing for Restrictions and Restriction_Warnings pragmas.
4822 -- Warn is True for Restriction_Warnings, or for Restrictions if the
4823 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
4824 -- is not set in the Restrictions case.
4825
4826 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
4827 -- Common processing for Suppress and Unsuppress. The boolean parameter
4828 -- Suppress_Case is True for the Suppress case, and False for the
4829 -- Unsuppress case.
4830
4831 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
4832 -- Subsidiary to the analysis of pragmas Independent[_Components].
4833 -- Record such a pragma N applied to entity E for future checks.
4834
4835 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
4836 -- This procedure sets the Is_Exported flag for the given entity,
4837 -- checking that the entity was not previously imported. Arg is
4838 -- the argument that specified the entity. A check is also made
4839 -- for exporting inappropriate entities.
4840
4841 procedure Set_Extended_Import_Export_External_Name
4842 (Internal_Ent : Entity_Id;
4843 Arg_External : Node_Id);
4844 -- Common processing for all extended import export pragmas. The first
4845 -- argument, Internal_Ent, is the internal entity, which has already
4846 -- been checked for validity by the caller. Arg_External is from the
4847 -- Import or Export pragma, and may be null if no External parameter
4848 -- was present. If Arg_External is present and is a non-null string
4849 -- (a null string is treated as the default), then the Interface_Name
4850 -- field of Internal_Ent is set appropriately.
4851
4852 procedure Set_Imported (E : Entity_Id);
4853 -- This procedure sets the Is_Imported flag for the given entity,
4854 -- checking that it is not previously exported or imported.
4855
4856 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
4857 -- Mech is a parameter passing mechanism (see Import_Function syntax
4858 -- for MECHANISM_NAME). This routine checks that the mechanism argument
4859 -- has the right form, and if not issues an error message. If the
4860 -- argument has the right form then the Mechanism field of Ent is
4861 -- set appropriately.
4862
4863 procedure Set_Rational_Profile;
4864 -- Activate the set of configuration pragmas and permissions that make
4865 -- up the Rational profile.
4866
4867 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id);
4868 -- Activate the set of configuration pragmas and restrictions that make
4869 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
4870 -- GNAT_Ravenscar_EDF, Jorvik, or Ravenscar. N is the corresponding
4871 -- pragma node, which is used for error messages on any constructs
4872 -- violating the profile.
4873
4874 ---------------------
4875 -- Ada_2005_Pragma --
4876 ---------------------
4877
4878 procedure Ada_2005_Pragma is
4879 begin
4880 if Ada_Version <= Ada_95 then
4881 Check_Restriction (No_Implementation_Pragmas, N);
4882 end if;
4883 end Ada_2005_Pragma;
4884
4885 ---------------------
4886 -- Ada_2012_Pragma --
4887 ---------------------
4888
4889 procedure Ada_2012_Pragma is
4890 begin
4891 if Ada_Version <= Ada_2005 then
4892 Check_Restriction (No_Implementation_Pragmas, N);
4893 end if;
4894 end Ada_2012_Pragma;
4895
4896 ----------------------------
4897 -- Analyze_Depends_Global --
4898 ----------------------------
4899
4900 procedure Analyze_Depends_Global
4901 (Spec_Id : out Entity_Id;
4902 Subp_Decl : out Node_Id;
4903 Legal : out Boolean)
4904 is
4905 begin
4906 -- Assume that the pragma is illegal
4907
4908 Spec_Id := Empty;
4909 Subp_Decl := Empty;
4910 Legal := False;
4911
4912 GNAT_Pragma;
4913 Check_Arg_Count (1);
4914
4915 -- Ensure the proper placement of the pragma. Depends/Global must be
4916 -- associated with a subprogram declaration or a body that acts as a
4917 -- spec.
4918
4919 Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4920
4921 -- Entry
4922
4923 if Nkind (Subp_Decl) = N_Entry_Declaration then
4924 null;
4925
4926 -- Generic subprogram
4927
4928 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4929 null;
4930
4931 -- Object declaration of a single concurrent type
4932
4933 elsif Nkind (Subp_Decl) = N_Object_Declaration
4934 and then Is_Single_Concurrent_Object
4935 (Unique_Defining_Entity (Subp_Decl))
4936 then
4937 null;
4938
4939 -- Single task type
4940
4941 elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then
4942 null;
4943
4944 -- Abstract subprogram declaration
4945
4946 elsif Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4947 null;
4948
4949 -- Subprogram body acts as spec
4950
4951 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4952 and then No (Corresponding_Spec (Subp_Decl))
4953 then
4954 null;
4955
4956 -- Subprogram body stub acts as spec
4957
4958 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4959 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
4960 then
4961 null;
4962
4963 -- Subprogram declaration
4964
4965 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4966
4967 -- Pragmas Global and Depends are forbidden on null procedures
4968 -- (SPARK RM 6.1.2(2)).
4969
4970 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4971 and then Null_Present (Specification (Subp_Decl))
4972 then
4973 Error_Msg_N (Fix_Error
4974 ("pragma % cannot apply to null procedure"), N);
4975 return;
4976 end if;
4977
4978 -- Task type
4979
4980 elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then
4981 null;
4982
4983 else
4984 Pragma_Misplaced;
4985 end if;
4986
4987 -- If we get here, then the pragma is legal
4988
4989 Legal := True;
4990 Spec_Id := Unique_Defining_Entity (Subp_Decl);
4991
4992 -- When the related context is an entry, the entry must belong to a
4993 -- protected unit (SPARK RM 6.1.4(6)).
4994
4995 if Is_Entry_Declaration (Spec_Id)
4996 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
4997 then
4998 Pragma_Misplaced;
4999
5000 -- When the related context is an anonymous object created for a
5001 -- simple concurrent type, the type must be a task
5002 -- (SPARK RM 6.1.4(6)).
5003
5004 elsif Is_Single_Concurrent_Object (Spec_Id)
5005 and then Ekind (Etype (Spec_Id)) /= E_Task_Type
5006 then
5007 Pragma_Misplaced;
5008 end if;
5009
5010 -- A pragma that applies to a Ghost entity becomes Ghost for the
5011 -- purposes of legality checks and removal of ignored Ghost code.
5012
5013 Mark_Ghost_Pragma (N, Spec_Id);
5014 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
5015 end Analyze_Depends_Global;
5016
5017 ------------------------
5018 -- Analyze_If_Present --
5019 ------------------------
5020
5021 procedure Analyze_If_Present (Id : Pragma_Id) is
5022 begin
5023 Analyze_If_Present_Internal (N, Id, Included => False);
5024 end Analyze_If_Present;
5025
5026 --------------------------------
5027 -- Analyze_Pre_Post_Condition --
5028 --------------------------------
5029
5030 procedure Analyze_Pre_Post_Condition is
5031 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
5032 Subp_Decl : Node_Id;
5033 Subp_Id : Entity_Id;
5034
5035 Duplicates_OK : Boolean := False;
5036 -- Flag set when a pre/postcondition allows multiple pragmas of the
5037 -- same kind.
5038
5039 In_Body_OK : Boolean := False;
5040 -- Flag set when a pre/postcondition is allowed to appear on a body
5041 -- even though the subprogram may have a spec.
5042
5043 Is_Pre_Post : Boolean := False;
5044 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
5045 -- Post_Class.
5046
5047 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean;
5048 -- Implement rules in AI12-0131: an overriding operation can have
5049 -- a class-wide precondition only if one of its ancestors has an
5050 -- explicit class-wide precondition.
5051
5052 -----------------------------
5053 -- Inherits_Class_Wide_Pre --
5054 -----------------------------
5055
5056 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean is
5057 Typ : constant Entity_Id := Find_Dispatching_Type (E);
5058 Cont : Node_Id;
5059 Prag : Node_Id;
5060 Prev : Entity_Id := Overridden_Operation (E);
5061
5062 begin
5063 -- Check ancestors on the overriding operation to examine the
5064 -- preconditions that may apply to them.
5065
5066 while Present (Prev) loop
5067 Cont := Contract (Prev);
5068 if Present (Cont) then
5069 Prag := Pre_Post_Conditions (Cont);
5070 while Present (Prag) loop
5071 if Pragma_Name (Prag) = Name_Precondition
5072 and then Class_Present (Prag)
5073 then
5074 return True;
5075 end if;
5076
5077 Prag := Next_Pragma (Prag);
5078 end loop;
5079 end if;
5080
5081 -- For a type derived from a generic formal type, the operation
5082 -- inheriting the condition is a renaming, not an overriding of
5083 -- the operation of the formal. Ditto for an inherited
5084 -- operation which has no explicit contracts.
5085
5086 if Is_Generic_Type (Find_Dispatching_Type (Prev))
5087 or else not Comes_From_Source (Prev)
5088 then
5089 Prev := Alias (Prev);
5090 else
5091 Prev := Overridden_Operation (Prev);
5092 end if;
5093 end loop;
5094
5095 -- If the controlling type of the subprogram has progenitors, an
5096 -- interface operation implemented by the current operation may
5097 -- have a class-wide precondition.
5098
5099 if Has_Interfaces (Typ) then
5100 declare
5101 Elmt : Elmt_Id;
5102 Ints : Elist_Id;
5103 Prim : Entity_Id;
5104 Prim_Elmt : Elmt_Id;
5105 Prim_List : Elist_Id;
5106
5107 begin
5108 Collect_Interfaces (Typ, Ints);
5109 Elmt := First_Elmt (Ints);
5110
5111 -- Iterate over the primitive operations of each interface
5112
5113 while Present (Elmt) loop
5114 Prim_List := Direct_Primitive_Operations (Node (Elmt));
5115 Prim_Elmt := First_Elmt (Prim_List);
5116 while Present (Prim_Elmt) loop
5117 Prim := Node (Prim_Elmt);
5118 if Chars (Prim) = Chars (E)
5119 and then Present (Contract (Prim))
5120 and then Class_Present
5121 (Pre_Post_Conditions (Contract (Prim)))
5122 then
5123 return True;
5124 end if;
5125
5126 Next_Elmt (Prim_Elmt);
5127 end loop;
5128
5129 Next_Elmt (Elmt);
5130 end loop;
5131 end;
5132 end if;
5133
5134 return False;
5135 end Inherits_Class_Wide_Pre;
5136
5137 -- Start of processing for Analyze_Pre_Post_Condition
5138
5139 begin
5140 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
5141 -- offer uniformity among the various kinds of pre/postconditions by
5142 -- rewriting the pragma identifier. This allows the retrieval of the
5143 -- original pragma name by routine Original_Aspect_Pragma_Name.
5144
5145 if Comes_From_Source (N) then
5146 if Pname in Name_Pre | Name_Pre_Class then
5147 Is_Pre_Post := True;
5148 Set_Class_Present (N, Pname = Name_Pre_Class);
5149 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
5150
5151 elsif Pname in Name_Post | Name_Post_Class then
5152 Is_Pre_Post := True;
5153 Set_Class_Present (N, Pname = Name_Post_Class);
5154 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
5155 end if;
5156 end if;
5157
5158 -- Determine the semantics with respect to duplicates and placement
5159 -- in a body. Pragmas Precondition and Postcondition were introduced
5160 -- before aspects and are not subject to the same aspect-like rules.
5161
5162 if Pname in Name_Precondition | Name_Postcondition then
5163 Duplicates_OK := True;
5164 In_Body_OK := True;
5165 end if;
5166
5167 GNAT_Pragma;
5168
5169 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
5170 -- argument without an identifier.
5171
5172 if Is_Pre_Post then
5173 Check_Arg_Count (1);
5174 Check_No_Identifiers;
5175
5176 -- Pragmas Precondition and Postcondition have complex argument
5177 -- profile.
5178
5179 else
5180 Check_At_Least_N_Arguments (1);
5181 Check_At_Most_N_Arguments (2);
5182 Check_Optional_Identifier (Arg1, Name_Check);
5183
5184 if Present (Arg2) then
5185 Check_Optional_Identifier (Arg2, Name_Message);
5186 Preanalyze_Spec_Expression
5187 (Get_Pragma_Arg (Arg2), Standard_String);
5188 end if;
5189 end if;
5190
5191 -- For a pragma PPC in the extended main source unit, record enabled
5192 -- status in SCO.
5193 -- ??? nothing checks that the pragma is in the main source unit
5194
5195 if Is_Checked (N) and then not Split_PPC (N) then
5196 Set_SCO_Pragma_Enabled (Loc);
5197 end if;
5198
5199 -- Ensure the proper placement of the pragma
5200
5201 Subp_Decl :=
5202 Find_Related_Declaration_Or_Body
5203 (N, Do_Checks => not Duplicates_OK);
5204
5205 -- When a pre/postcondition pragma applies to an abstract subprogram,
5206 -- its original form must be an aspect with 'Class.
5207
5208 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
5209 if not From_Aspect_Specification (N) then
5210 Error_Pragma
5211 ("pragma % cannot be applied to abstract subprogram");
5212
5213 elsif not Class_Present (N) then
5214 Error_Pragma
5215 ("aspect % requires ''Class for abstract subprogram");
5216 end if;
5217
5218 -- Entry declaration
5219
5220 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
5221 null;
5222
5223 -- Generic subprogram declaration
5224
5225 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
5226 null;
5227
5228 -- Subprogram body
5229
5230 elsif Nkind (Subp_Decl) = N_Subprogram_Body
5231 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
5232 then
5233 null;
5234
5235 -- Subprogram body stub
5236
5237 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
5238 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
5239 then
5240 null;
5241
5242 -- Subprogram declaration
5243
5244 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
5245
5246 -- AI05-0230: When a pre/postcondition pragma applies to a null
5247 -- procedure, its original form must be an aspect with 'Class.
5248
5249 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
5250 and then Null_Present (Specification (Subp_Decl))
5251 and then From_Aspect_Specification (N)
5252 and then not Class_Present (N)
5253 then
5254 Error_Pragma ("aspect % requires ''Class for null procedure");
5255 end if;
5256
5257 -- Implement the legality checks mandated by AI12-0131:
5258 -- Pre'Class shall not be specified for an overriding primitive
5259 -- subprogram of a tagged type T unless the Pre'Class aspect is
5260 -- specified for the corresponding primitive subprogram of some
5261 -- ancestor of T.
5262
5263 declare
5264 E : constant Entity_Id := Defining_Entity (Subp_Decl);
5265
5266 begin
5267 if Class_Present (N)
5268 and then Pragma_Name (N) = Name_Precondition
5269 and then Present (Overridden_Operation (E))
5270 and then not Inherits_Class_Wide_Pre (E)
5271 then
5272 Error_Msg_N
5273 ("illegal class-wide precondition on overriding operation",
5274 Corresponding_Aspect (N));
5275 end if;
5276 end;
5277
5278 -- A renaming declaration may inherit a generated pragma, its
5279 -- placement comes from expansion, not from source.
5280
5281 elsif Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
5282 and then not Comes_From_Source (N)
5283 then
5284 null;
5285
5286 -- For Ada 2022, pre/postconditions can appear on formal subprograms
5287
5288 elsif Nkind (Subp_Decl) = N_Formal_Concrete_Subprogram_Declaration
5289 and then Ada_Version >= Ada_2022
5290 then
5291 null;
5292
5293 -- An access-to-subprogram type can have pre/postconditions, which
5294 -- are both analyzed when attached to the type and copied to the
5295 -- generated subprogram wrapper and analyzed there.
5296
5297 elsif Nkind (Subp_Decl) = N_Full_Type_Declaration
5298 and then Nkind (Type_Definition (Subp_Decl)) in
5299 N_Access_To_Subprogram_Definition
5300 then
5301 if Ada_Version < Ada_2022 then
5302 Error_Msg_Ada_2022_Feature
5303 ("pre/postcondition on access-to-subprogram", Loc);
5304 raise Pragma_Exit;
5305 end if;
5306
5307 -- Otherwise the placement of the pragma is illegal
5308
5309 else
5310 Pragma_Misplaced;
5311 end if;
5312
5313 Subp_Id := Defining_Entity (Subp_Decl);
5314
5315 -- A pragma that applies to a Ghost entity becomes Ghost for the
5316 -- purposes of legality checks and removal of ignored Ghost code.
5317
5318 Mark_Ghost_Pragma (N, Subp_Id);
5319
5320 -- Chain the pragma on the contract for further processing by
5321 -- Analyze_Pre_Post_Condition_In_Decl_Part.
5322
5323 if Ekind (Subp_Id) in Access_Subprogram_Kind then
5324 Add_Contract_Item (N, Directly_Designated_Type (Subp_Id));
5325 else
5326 Add_Contract_Item (N, Subp_Id);
5327 end if;
5328
5329 -- Fully analyze the pragma when it appears inside an entry or
5330 -- subprogram body because it cannot benefit from forward references.
5331
5332 if Nkind (Subp_Decl) in N_Entry_Body
5333 | N_Subprogram_Body
5334 | N_Subprogram_Body_Stub
5335 then
5336 -- The legality checks of pragmas Precondition and Postcondition
5337 -- are affected by the SPARK mode in effect and the volatility of
5338 -- the context. Analyze all pragmas in a specific order.
5339
5340 Analyze_If_Present (Pragma_SPARK_Mode);
5341 Analyze_If_Present (Pragma_Volatile_Function);
5342 Analyze_Pre_Post_Condition_In_Decl_Part (N);
5343 end if;
5344 end Analyze_Pre_Post_Condition;
5345
5346 -----------------------------------------
5347 -- Analyze_Refined_Depends_Global_Post --
5348 -----------------------------------------
5349
5350 procedure Analyze_Refined_Depends_Global_Post
5351 (Spec_Id : out Entity_Id;
5352 Body_Id : out Entity_Id;
5353 Legal : out Boolean)
5354 is
5355 Body_Decl : Node_Id;
5356 Spec_Decl : Node_Id;
5357
5358 begin
5359 -- Assume that the pragma is illegal
5360
5361 Spec_Id := Empty;
5362 Body_Id := Empty;
5363 Legal := False;
5364
5365 GNAT_Pragma;
5366 Check_Arg_Count (1);
5367 Check_No_Identifiers;
5368
5369 -- Verify the placement of the pragma and check for duplicates. The
5370 -- pragma must apply to a subprogram body [stub].
5371
5372 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
5373
5374 if Nkind (Body_Decl) not in
5375 N_Entry_Body | N_Subprogram_Body | N_Subprogram_Body_Stub |
5376 N_Task_Body | N_Task_Body_Stub
5377 then
5378 Pragma_Misplaced;
5379 end if;
5380
5381 Body_Id := Defining_Entity (Body_Decl);
5382 Spec_Id := Unique_Defining_Entity (Body_Decl);
5383
5384 -- The pragma must apply to the second declaration of a subprogram.
5385 -- In other words, the body [stub] cannot acts as a spec.
5386
5387 if No (Spec_Id) then
5388 Error_Pragma ("pragma % cannot apply to a stand alone body");
5389
5390 -- Catch the case where the subprogram body is a subunit and acts as
5391 -- the third declaration of the subprogram.
5392
5393 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
5394 Error_Pragma ("pragma % cannot apply to a subunit");
5395 end if;
5396
5397 -- A refined pragma can only apply to the body [stub] of a subprogram
5398 -- declared in the visible part of a package. Retrieve the context of
5399 -- the subprogram declaration.
5400
5401 Spec_Decl := Unit_Declaration_Node (Spec_Id);
5402
5403 -- When dealing with protected entries or protected subprograms, use
5404 -- the enclosing protected type as the proper context.
5405
5406 if Ekind (Spec_Id) in E_Entry
5407 | E_Entry_Family
5408 | E_Function
5409 | E_Procedure
5410 and then Ekind (Scope (Spec_Id)) = E_Protected_Type
5411 then
5412 Spec_Decl := Declaration_Node (Scope (Spec_Id));
5413 end if;
5414
5415 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
5416 Error_Pragma
5417 (Fix_Msg (Spec_Id, "pragma % must apply to the body of "
5418 & "subprogram declared in a package specification"));
5419 end if;
5420
5421 -- If we get here, then the pragma is legal
5422
5423 Legal := True;
5424
5425 -- A pragma that applies to a Ghost entity becomes Ghost for the
5426 -- purposes of legality checks and removal of ignored Ghost code.
5427
5428 Mark_Ghost_Pragma (N, Spec_Id);
5429
5430 if Pname in Name_Refined_Depends | Name_Refined_Global then
5431 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
5432 end if;
5433 end Analyze_Refined_Depends_Global_Post;
5434
5435 ----------------------------------
5436 -- Analyze_Unmodified_Or_Unused --
5437 ----------------------------------
5438
5439 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False) is
5440 Arg : Node_Id;
5441 Arg_Expr : Node_Id;
5442 Arg_Id : Entity_Id;
5443
5444 Ghost_Error_Posted : Boolean := False;
5445 -- Flag set when an error concerning the illegal mix of Ghost and
5446 -- non-Ghost variables is emitted.
5447
5448 Ghost_Id : Entity_Id := Empty;
5449 -- The entity of the first Ghost variable encountered while
5450 -- processing the arguments of the pragma.
5451
5452 begin
5453 GNAT_Pragma;
5454 Check_At_Least_N_Arguments (1);
5455
5456 -- Loop through arguments
5457
5458 Arg := Arg1;
5459 while Present (Arg) loop
5460 Check_No_Identifier (Arg);
5461
5462 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
5463 -- in fact generate reference, so that the entity will have a
5464 -- reference, which will inhibit any warnings about it not
5465 -- being referenced, and also properly show up in the ali file
5466 -- as a reference. But this reference is recorded before the
5467 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5468 -- generated for this reference.
5469
5470 Check_Arg_Is_Local_Name (Arg);
5471 Arg_Expr := Get_Pragma_Arg (Arg);
5472
5473 if Is_Entity_Name (Arg_Expr) then
5474 Arg_Id := Entity (Arg_Expr);
5475
5476 -- Skip processing the argument if already flagged
5477
5478 if Is_Assignable (Arg_Id)
5479 and then not Has_Pragma_Unmodified (Arg_Id)
5480 and then not Has_Pragma_Unused (Arg_Id)
5481 then
5482 Set_Has_Pragma_Unmodified (Arg_Id);
5483
5484 if Is_Unused then
5485 Set_Has_Pragma_Unused (Arg_Id);
5486 end if;
5487
5488 -- A pragma that applies to a Ghost entity becomes Ghost for
5489 -- the purposes of legality checks and removal of ignored
5490 -- Ghost code.
5491
5492 Mark_Ghost_Pragma (N, Arg_Id);
5493
5494 -- Capture the entity of the first Ghost variable being
5495 -- processed for error detection purposes.
5496
5497 if Is_Ghost_Entity (Arg_Id) then
5498 if No (Ghost_Id) then
5499 Ghost_Id := Arg_Id;
5500 end if;
5501
5502 -- Otherwise the variable is non-Ghost. It is illegal to mix
5503 -- references to Ghost and non-Ghost entities
5504 -- (SPARK RM 6.9).
5505
5506 elsif Present (Ghost_Id)
5507 and then not Ghost_Error_Posted
5508 then
5509 Ghost_Error_Posted := True;
5510
5511 Error_Msg_Name_1 := Pname;
5512 Error_Msg_N
5513 ("pragma % cannot mention ghost and non-ghost "
5514 & "variables", N);
5515
5516 Error_Msg_Sloc := Sloc (Ghost_Id);
5517 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
5518
5519 Error_Msg_Sloc := Sloc (Arg_Id);
5520 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
5521 end if;
5522
5523 -- Warn if already flagged as Unused or Unmodified
5524
5525 elsif Has_Pragma_Unmodified (Arg_Id) then
5526 if Has_Pragma_Unused (Arg_Id) then
5527 Error_Msg_NE
5528 (Fix_Error ("??pragma Unused already given for &!"),
5529 Arg_Expr, Arg_Id);
5530 else
5531 Error_Msg_NE
5532 (Fix_Error ("??pragma Unmodified already given for &!"),
5533 Arg_Expr, Arg_Id);
5534 end if;
5535
5536 -- Otherwise the pragma referenced an illegal entity
5537
5538 else
5539 Error_Pragma_Arg
5540 ("pragma% can only be applied to a variable", Arg_Expr);
5541 end if;
5542 end if;
5543
5544 Next (Arg);
5545 end loop;
5546 end Analyze_Unmodified_Or_Unused;
5547
5548 ------------------------------------
5549 -- Analyze_Unreferenced_Or_Unused --
5550 ------------------------------------
5551
5552 procedure Analyze_Unreferenced_Or_Unused
5553 (Is_Unused : Boolean := False)
5554 is
5555 Arg : Node_Id;
5556 Arg_Expr : Node_Id;
5557 Arg_Id : Entity_Id;
5558 Citem : Node_Id;
5559
5560 Ghost_Error_Posted : Boolean := False;
5561 -- Flag set when an error concerning the illegal mix of Ghost and
5562 -- non-Ghost names is emitted.
5563
5564 Ghost_Id : Entity_Id := Empty;
5565 -- The entity of the first Ghost name encountered while processing
5566 -- the arguments of the pragma.
5567
5568 begin
5569 GNAT_Pragma;
5570 Check_At_Least_N_Arguments (1);
5571
5572 -- Check case of appearing within context clause
5573
5574 if not Is_Unused and then Is_In_Context_Clause then
5575
5576 -- The arguments must all be units mentioned in a with clause in
5577 -- the same context clause. Note that Par.Prag already checked
5578 -- that the arguments are either identifiers or selected
5579 -- components.
5580
5581 Arg := Arg1;
5582 while Present (Arg) loop
5583 Citem := First (List_Containing (N));
5584 while Citem /= N loop
5585 Arg_Expr := Get_Pragma_Arg (Arg);
5586
5587 if Nkind (Citem) = N_With_Clause
5588 and then Same_Name (Name (Citem), Arg_Expr)
5589 then
5590 Set_Has_Pragma_Unreferenced
5591 (Cunit_Entity
5592 (Get_Source_Unit
5593 (Library_Unit (Citem))));
5594 Set_Elab_Unit_Name (Arg_Expr, Name (Citem));
5595 exit;
5596 end if;
5597
5598 Next (Citem);
5599 end loop;
5600
5601 if Citem = N then
5602 Error_Pragma_Arg
5603 ("argument of pragma% is not withed unit", Arg);
5604 end if;
5605
5606 Next (Arg);
5607 end loop;
5608
5609 -- Case of not in list of context items
5610
5611 else
5612 Arg := Arg1;
5613 while Present (Arg) loop
5614 Check_No_Identifier (Arg);
5615
5616 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
5617 -- in fact generate reference, so that the entity will have a
5618 -- reference, which will inhibit any warnings about it not
5619 -- being referenced, and also properly show up in the ali file
5620 -- as a reference. But this reference is recorded before the
5621 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5622 -- generated for this reference.
5623
5624 Check_Arg_Is_Local_Name (Arg);
5625 Arg_Expr := Get_Pragma_Arg (Arg);
5626
5627 if Is_Entity_Name (Arg_Expr) then
5628 Arg_Id := Entity (Arg_Expr);
5629
5630 -- Warn if already flagged as Unused or Unreferenced and
5631 -- skip processing the argument.
5632
5633 if Has_Pragma_Unreferenced (Arg_Id) then
5634 if Has_Pragma_Unused (Arg_Id) then
5635 Error_Msg_NE
5636 (Fix_Error ("??pragma Unused already given for &!"),
5637 Arg_Expr, Arg_Id);
5638 else
5639 Error_Msg_NE
5640 (Fix_Error
5641 ("??pragma Unreferenced already given for &!"),
5642 Arg_Expr, Arg_Id);
5643 end if;
5644
5645 -- Apply Unreferenced to the entity
5646
5647 else
5648 -- If the entity is overloaded, the pragma applies to the
5649 -- most recent overloading, as documented. In this case,
5650 -- name resolution does not generate a reference, so it
5651 -- must be done here explicitly.
5652
5653 if Is_Overloaded (Arg_Expr) then
5654 Generate_Reference (Arg_Id, N);
5655 end if;
5656
5657 Set_Has_Pragma_Unreferenced (Arg_Id);
5658
5659 if Is_Unused then
5660 Set_Has_Pragma_Unused (Arg_Id);
5661 end if;
5662
5663 -- A pragma that applies to a Ghost entity becomes Ghost
5664 -- for the purposes of legality checks and removal of
5665 -- ignored Ghost code.
5666
5667 Mark_Ghost_Pragma (N, Arg_Id);
5668
5669 -- Capture the entity of the first Ghost name being
5670 -- processed for error detection purposes.
5671
5672 if Is_Ghost_Entity (Arg_Id) then
5673 if No (Ghost_Id) then
5674 Ghost_Id := Arg_Id;
5675 end if;
5676
5677 -- Otherwise the name is non-Ghost. It is illegal to mix
5678 -- references to Ghost and non-Ghost entities
5679 -- (SPARK RM 6.9).
5680
5681 elsif Present (Ghost_Id)
5682 and then not Ghost_Error_Posted
5683 then
5684 Ghost_Error_Posted := True;
5685
5686 Error_Msg_Name_1 := Pname;
5687 Error_Msg_N
5688 ("pragma % cannot mention ghost and non-ghost "
5689 & "names", N);
5690
5691 Error_Msg_Sloc := Sloc (Ghost_Id);
5692 Error_Msg_NE
5693 ("\& # declared as ghost", N, Ghost_Id);
5694
5695 Error_Msg_Sloc := Sloc (Arg_Id);
5696 Error_Msg_NE
5697 ("\& # declared as non-ghost", N, Arg_Id);
5698 end if;
5699 end if;
5700 end if;
5701
5702 Next (Arg);
5703 end loop;
5704 end if;
5705 end Analyze_Unreferenced_Or_Unused;
5706
5707 --------------------------
5708 -- Check_Ada_83_Warning --
5709 --------------------------
5710
5711 procedure Check_Ada_83_Warning is
5712 begin
5713 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5714 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
5715 end if;
5716 end Check_Ada_83_Warning;
5717
5718 ---------------------
5719 -- Check_Arg_Count --
5720 ---------------------
5721
5722 procedure Check_Arg_Count (Required : Nat) is
5723 begin
5724 if Arg_Count /= Required then
5725 Error_Pragma ("wrong number of arguments for pragma%");
5726 end if;
5727 end Check_Arg_Count;
5728
5729 --------------------------------
5730 -- Check_Arg_Is_External_Name --
5731 --------------------------------
5732
5733 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
5734 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5735
5736 begin
5737 if Nkind (Argx) = N_Identifier then
5738 return;
5739
5740 else
5741 Analyze_And_Resolve (Argx, Standard_String);
5742
5743 if Is_OK_Static_Expression (Argx) then
5744 return;
5745
5746 elsif Etype (Argx) = Any_Type then
5747 raise Pragma_Exit;
5748
5749 -- An interesting special case, if we have a string literal and
5750 -- we are in Ada 83 mode, then we allow it even though it will
5751 -- not be flagged as static. This allows expected Ada 83 mode
5752 -- use of external names which are string literals, even though
5753 -- technically these are not static in Ada 83.
5754
5755 elsif Ada_Version = Ada_83
5756 and then Nkind (Argx) = N_String_Literal
5757 then
5758 return;
5759
5760 -- Here we have a real error (non-static expression)
5761
5762 else
5763 Error_Msg_Name_1 := Pname;
5764 Flag_Non_Static_Expr
5765 (Fix_Error ("argument for pragma% must be a identifier or "
5766 & "static string expression!"), Argx);
5767
5768 raise Pragma_Exit;
5769 end if;
5770 end if;
5771 end Check_Arg_Is_External_Name;
5772
5773 -----------------------------
5774 -- Check_Arg_Is_Identifier --
5775 -----------------------------
5776
5777 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
5778 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5779 begin
5780 if Nkind (Argx) /= N_Identifier then
5781 Error_Pragma_Arg ("argument for pragma% must be identifier", Argx);
5782 end if;
5783 end Check_Arg_Is_Identifier;
5784
5785 ----------------------------------
5786 -- Check_Arg_Is_Integer_Literal --
5787 ----------------------------------
5788
5789 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
5790 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5791 begin
5792 if Nkind (Argx) /= N_Integer_Literal then
5793 Error_Pragma_Arg
5794 ("argument for pragma% must be integer literal", Argx);
5795 end if;
5796 end Check_Arg_Is_Integer_Literal;
5797
5798 -------------------------------------------
5799 -- Check_Arg_Is_Library_Level_Local_Name --
5800 -------------------------------------------
5801
5802 -- LOCAL_NAME ::=
5803 -- DIRECT_NAME
5804 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5805 -- | library_unit_NAME
5806
5807 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
5808 begin
5809 Check_Arg_Is_Local_Name (Arg);
5810
5811 -- If it came from an aspect, we want to give the error just as if it
5812 -- came from source.
5813
5814 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
5815 and then (Comes_From_Source (N)
5816 or else Present (Corresponding_Aspect (Parent (Arg))))
5817 then
5818 Error_Pragma_Arg
5819 ("argument for pragma% must be library level entity", Arg);
5820 end if;
5821 end Check_Arg_Is_Library_Level_Local_Name;
5822
5823 -----------------------------
5824 -- Check_Arg_Is_Local_Name --
5825 -----------------------------
5826
5827 -- LOCAL_NAME ::=
5828 -- DIRECT_NAME
5829 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5830 -- | library_unit_NAME
5831
5832 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
5833 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5834
5835 begin
5836 -- If this pragma came from an aspect specification, we don't want to
5837 -- check for this error, because that would cause spurious errors, in
5838 -- case a type is frozen in a scope more nested than the type. The
5839 -- aspect itself of course can't be anywhere but on the declaration
5840 -- itself.
5841
5842 if Nkind (Arg) = N_Pragma_Argument_Association then
5843 if From_Aspect_Specification (Parent (Arg)) then
5844 return;
5845 end if;
5846
5847 -- Arg is the Expression of an N_Pragma_Argument_Association
5848
5849 else
5850 if From_Aspect_Specification (Parent (Parent (Arg))) then
5851 return;
5852 end if;
5853 end if;
5854
5855 Analyze (Argx);
5856
5857 if Nkind (Argx) not in N_Direct_Name
5858 and then (Nkind (Argx) /= N_Attribute_Reference
5859 or else Present (Expressions (Argx))
5860 or else Nkind (Prefix (Argx)) /= N_Identifier)
5861 and then (not Is_Entity_Name (Argx)
5862 or else not Is_Compilation_Unit (Entity (Argx)))
5863 then
5864 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
5865 end if;
5866
5867 -- No further check required if not an entity name
5868
5869 if not Is_Entity_Name (Argx) then
5870 null;
5871
5872 else
5873 declare
5874 OK : Boolean;
5875 Ent : constant Entity_Id := Entity (Argx);
5876 Scop : constant Entity_Id := Scope (Ent);
5877
5878 begin
5879 -- Case of a pragma applied to a compilation unit: pragma must
5880 -- occur immediately after the program unit in the compilation.
5881
5882 if Is_Compilation_Unit (Ent) then
5883 declare
5884 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
5885
5886 begin
5887 -- Case of pragma placed immediately after spec
5888
5889 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
5890 OK := True;
5891
5892 -- Case of pragma placed immediately after body
5893
5894 elsif Nkind (Decl) = N_Subprogram_Declaration
5895 and then Present (Corresponding_Body (Decl))
5896 then
5897 OK := Parent (N) =
5898 Aux_Decls_Node
5899 (Parent (Unit_Declaration_Node
5900 (Corresponding_Body (Decl))));
5901
5902 -- All other cases are illegal
5903
5904 else
5905 OK := False;
5906 end if;
5907 end;
5908
5909 -- Special restricted placement rule from 10.2.1(11.8/2)
5910
5911 elsif Is_Generic_Formal (Ent)
5912 and then Prag_Id = Pragma_Preelaborable_Initialization
5913 then
5914 OK := List_Containing (N) =
5915 Generic_Formal_Declarations
5916 (Unit_Declaration_Node (Scop));
5917
5918 -- If this is an aspect applied to a subprogram body, the
5919 -- pragma is inserted in its declarative part.
5920
5921 elsif From_Aspect_Specification (N)
5922 and then Ent = Current_Scope
5923 and then
5924 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
5925 then
5926 OK := True;
5927
5928 -- If the aspect is a predicate (possibly others ???) and the
5929 -- context is a record type, this is a discriminant expression
5930 -- within a type declaration, that freezes the predicated
5931 -- subtype.
5932
5933 elsif From_Aspect_Specification (N)
5934 and then Prag_Id = Pragma_Predicate
5935 and then Ekind (Current_Scope) = E_Record_Type
5936 and then Scop = Scope (Current_Scope)
5937 then
5938 OK := True;
5939
5940 -- Special case for postconditions wrappers
5941
5942 elsif Ekind (Scop) in Subprogram_Kind
5943 and then Present (Wrapped_Statements (Scop))
5944 and then Wrapped_Statements (Scop) = Current_Scope
5945 then
5946 OK := True;
5947
5948 -- Default case, just check that the pragma occurs in the scope
5949 -- of the entity denoted by the name.
5950
5951 else
5952 OK := Current_Scope = Scop;
5953 end if;
5954
5955 if not OK then
5956 Error_Pragma_Arg
5957 ("pragma% argument must be in same declarative part", Arg);
5958 end if;
5959 end;
5960 end if;
5961 end Check_Arg_Is_Local_Name;
5962
5963 ---------------------------------
5964 -- Check_Arg_Is_Locking_Policy --
5965 ---------------------------------
5966
5967 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
5968 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5969
5970 begin
5971 Check_Arg_Is_Identifier (Argx);
5972
5973 if not Is_Locking_Policy_Name (Chars (Argx)) then
5974 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
5975 end if;
5976 end Check_Arg_Is_Locking_Policy;
5977
5978 -----------------------------------------------
5979 -- Check_Arg_Is_Partition_Elaboration_Policy --
5980 -----------------------------------------------
5981
5982 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
5983 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5984
5985 begin
5986 Check_Arg_Is_Identifier (Argx);
5987
5988 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
5989 Error_Pragma_Arg
5990 ("& is not a valid partition elaboration policy name", Argx);
5991 end if;
5992 end Check_Arg_Is_Partition_Elaboration_Policy;
5993
5994 -------------------------
5995 -- Check_Arg_Is_One_Of --
5996 -------------------------
5997
5998 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5999 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6000
6001 begin
6002 Check_Arg_Is_Identifier (Argx);
6003
6004 if Chars (Argx) not in N1 | N2 then
6005 Error_Msg_Name_2 := N1;
6006 Error_Msg_Name_3 := N2;
6007 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
6008 end if;
6009 end Check_Arg_Is_One_Of;
6010
6011 procedure Check_Arg_Is_One_Of
6012 (Arg : Node_Id;
6013 N1, N2, N3 : Name_Id)
6014 is
6015 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6016
6017 begin
6018 Check_Arg_Is_Identifier (Argx);
6019
6020 if Chars (Argx) not in N1 | N2 | N3 then
6021 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
6022 end if;
6023 end Check_Arg_Is_One_Of;
6024
6025 procedure Check_Arg_Is_One_Of
6026 (Arg : Node_Id;
6027 N1, N2, N3, N4 : Name_Id)
6028 is
6029 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6030
6031 begin
6032 Check_Arg_Is_Identifier (Argx);
6033
6034 if Chars (Argx) not in N1 | N2 | N3 | N4 then
6035 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
6036 end if;
6037 end Check_Arg_Is_One_Of;
6038
6039 procedure Check_Arg_Is_One_Of
6040 (Arg : Node_Id;
6041 N1, N2, N3, N4, N5 : Name_Id)
6042 is
6043 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6044
6045 begin
6046 Check_Arg_Is_Identifier (Argx);
6047
6048 if Chars (Argx) not in N1 | N2 | N3 | N4 | N5 then
6049 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
6050 end if;
6051 end Check_Arg_Is_One_Of;
6052
6053 ---------------------------------
6054 -- Check_Arg_Is_Queuing_Policy --
6055 ---------------------------------
6056
6057 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
6058 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6059
6060 begin
6061 Check_Arg_Is_Identifier (Argx);
6062
6063 if not Is_Queuing_Policy_Name (Chars (Argx)) then
6064 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
6065 end if;
6066 end Check_Arg_Is_Queuing_Policy;
6067
6068 ---------------------------------------
6069 -- Check_Arg_Is_OK_Static_Expression --
6070 ---------------------------------------
6071
6072 procedure Check_Arg_Is_OK_Static_Expression
6073 (Arg : Node_Id;
6074 Typ : Entity_Id := Empty)
6075 is
6076 begin
6077 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
6078 end Check_Arg_Is_OK_Static_Expression;
6079
6080 ------------------------------------------
6081 -- Check_Arg_Is_Task_Dispatching_Policy --
6082 ------------------------------------------
6083
6084 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
6085 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6086
6087 begin
6088 Check_Arg_Is_Identifier (Argx);
6089
6090 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
6091 Error_Pragma_Arg
6092 ("& is not an allowed task dispatching policy name", Argx);
6093 end if;
6094 end Check_Arg_Is_Task_Dispatching_Policy;
6095
6096 ---------------------
6097 -- Check_Arg_Order --
6098 ---------------------
6099
6100 procedure Check_Arg_Order (Names : Name_List) is
6101 Arg : Node_Id;
6102
6103 Highest_So_Far : Natural := 0;
6104 -- Highest index in Names seen do far
6105
6106 begin
6107 Arg := Arg1;
6108 for J in 1 .. Arg_Count loop
6109 if Chars (Arg) /= No_Name then
6110 for K in Names'Range loop
6111 if Chars (Arg) = Names (K) then
6112 if K < Highest_So_Far then
6113 Error_Msg_Name_1 := Pname;
6114 Error_Msg_N
6115 ("parameters out of order for pragma%", Arg);
6116 Error_Msg_Name_1 := Names (K);
6117 Error_Msg_Name_2 := Names (Highest_So_Far);
6118 Error_Msg_N ("\% must appear before %", Arg);
6119 raise Pragma_Exit;
6120
6121 else
6122 Highest_So_Far := K;
6123 end if;
6124 end if;
6125 end loop;
6126 end if;
6127
6128 Arg := Next (Arg);
6129 end loop;
6130 end Check_Arg_Order;
6131
6132 --------------------------------
6133 -- Check_At_Least_N_Arguments --
6134 --------------------------------
6135
6136 procedure Check_At_Least_N_Arguments (N : Nat) is
6137 begin
6138 if Arg_Count < N then
6139 Error_Pragma ("too few arguments for pragma%");
6140 end if;
6141 end Check_At_Least_N_Arguments;
6142
6143 -------------------------------
6144 -- Check_At_Most_N_Arguments --
6145 -------------------------------
6146
6147 procedure Check_At_Most_N_Arguments (N : Nat) is
6148 Arg : Node_Id;
6149 begin
6150 if Arg_Count > N then
6151 Arg := Arg1;
6152 for J in 1 .. N loop
6153 Next (Arg);
6154 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
6155 end loop;
6156 end if;
6157 end Check_At_Most_N_Arguments;
6158
6159 ---------------------
6160 -- Check_Component --
6161 ---------------------
6162
6163 procedure Check_Component
6164 (Comp : Node_Id;
6165 UU_Typ : Entity_Id;
6166 In_Variant_Part : Boolean := False)
6167 is
6168 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
6169 Sindic : constant Node_Id :=
6170 Subtype_Indication (Component_Definition (Comp));
6171 Typ : constant Entity_Id := Etype (Comp_Id);
6172
6173 begin
6174 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
6175 -- object constraint, then the component type shall be an Unchecked_
6176 -- Union.
6177
6178 if Nkind (Sindic) = N_Subtype_Indication
6179 and then Has_Per_Object_Constraint (Comp_Id)
6180 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
6181 then
6182 Error_Msg_N
6183 ("component subtype subject to per-object constraint "
6184 & "must be an Unchecked_Union", Comp);
6185
6186 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
6187 -- the body of a generic unit, or within the body of any of its
6188 -- descendant library units, no part of the type of a component
6189 -- declared in a variant_part of the unchecked union type shall be of
6190 -- a formal private type or formal private extension declared within
6191 -- the formal part of the generic unit.
6192
6193 elsif Ada_Version >= Ada_2012
6194 and then In_Generic_Body (UU_Typ)
6195 and then In_Variant_Part
6196 and then Is_Private_Type (Typ)
6197 and then Is_Generic_Type (Typ)
6198 then
6199 Error_Msg_N
6200 ("component of unchecked union cannot be of generic type", Comp);
6201
6202 elsif Needs_Finalization (Typ) then
6203 Error_Msg_N
6204 ("component of unchecked union cannot be controlled", Comp);
6205
6206 elsif Has_Task (Typ) then
6207 Error_Msg_N
6208 ("component of unchecked union cannot have tasks", Comp);
6209 end if;
6210 end Check_Component;
6211
6212 ----------------------------
6213 -- Check_Duplicate_Pragma --
6214 ----------------------------
6215
6216 procedure Check_Duplicate_Pragma (E : Entity_Id) is
6217 Id : Entity_Id := E;
6218 P : Node_Id;
6219
6220 begin
6221 -- Nothing to do if this pragma comes from an aspect specification,
6222 -- since we could not be duplicating a pragma, and we dealt with the
6223 -- case of duplicated aspects in Analyze_Aspect_Specifications.
6224
6225 if From_Aspect_Specification (N) then
6226 return;
6227 end if;
6228
6229 -- Otherwise current pragma may duplicate previous pragma or a
6230 -- previously given aspect specification or attribute definition
6231 -- clause for the same pragma.
6232
6233 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
6234
6235 if Present (P) then
6236
6237 -- If the entity is a type, then we have to make sure that the
6238 -- ostensible duplicate is not for a parent type from which this
6239 -- type is derived.
6240
6241 if Is_Type (E) then
6242 if Nkind (P) = N_Pragma then
6243 declare
6244 Args : constant List_Id :=
6245 Pragma_Argument_Associations (P);
6246 begin
6247 if Present (Args)
6248 and then Is_Entity_Name (Expression (First (Args)))
6249 and then Is_Type (Entity (Expression (First (Args))))
6250 and then Entity (Expression (First (Args))) /= E
6251 then
6252 return;
6253 end if;
6254 end;
6255
6256 elsif Nkind (P) = N_Aspect_Specification
6257 and then Is_Type (Entity (P))
6258 and then Entity (P) /= E
6259 then
6260 return;
6261 end if;
6262 end if;
6263
6264 -- Here we have a definite duplicate
6265
6266 Error_Msg_Name_1 := Pragma_Name (N);
6267 Error_Msg_Sloc := Sloc (P);
6268
6269 -- For a single protected or a single task object, the error is
6270 -- issued on the original entity.
6271
6272 if Ekind (Id) in E_Task_Type | E_Protected_Type then
6273 Id := Defining_Identifier (Original_Node (Parent (Id)));
6274 end if;
6275
6276 if Nkind (P) = N_Aspect_Specification
6277 or else From_Aspect_Specification (P)
6278 then
6279 Error_Msg_NE ("aspect% for & previously given#", N, Id);
6280 else
6281 -- If -gnatwr is set, warn in case of a duplicate pragma
6282 -- [No_]Inline which is suspicious but not an error, generate
6283 -- an error for other pragmas.
6284
6285 if Pragma_Name (N) in Name_Inline | Name_No_Inline then
6286 if Warn_On_Redundant_Constructs then
6287 Error_Msg_NE
6288 ("?r?pragma% for & duplicates pragma#", N, Id);
6289 end if;
6290 else
6291 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
6292 end if;
6293 end if;
6294
6295 raise Pragma_Exit;
6296 end if;
6297 end Check_Duplicate_Pragma;
6298
6299 ----------------------------------
6300 -- Check_Duplicated_Export_Name --
6301 ----------------------------------
6302
6303 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
6304 String_Val : constant String_Id := Strval (Nam);
6305
6306 begin
6307 -- We are only interested in the export case, and in the case of
6308 -- generics, it is the instance, not the template, that is the
6309 -- problem (the template will generate a warning in any case).
6310
6311 if not Inside_A_Generic
6312 and then (Prag_Id = Pragma_Export
6313 or else
6314 Prag_Id = Pragma_Export_Procedure
6315 or else
6316 Prag_Id = Pragma_Export_Valued_Procedure
6317 or else
6318 Prag_Id = Pragma_Export_Function)
6319 then
6320 for J in Externals.First .. Externals.Last loop
6321 if String_Equal (String_Val, Strval (Externals.Table (J))) then
6322 Error_Msg_Sloc := Sloc (Externals.Table (J));
6323 Error_Msg_N ("external name duplicates name given#", Nam);
6324 exit;
6325 end if;
6326 end loop;
6327
6328 Externals.Append (Nam);
6329 end if;
6330 end Check_Duplicated_Export_Name;
6331
6332 ----------------------------------------
6333 -- Check_Expr_Is_OK_Static_Expression --
6334 ----------------------------------------
6335
6336 procedure Check_Expr_Is_OK_Static_Expression
6337 (Expr : Node_Id;
6338 Typ : Entity_Id := Empty)
6339 is
6340 begin
6341 if Present (Typ) then
6342 Analyze_And_Resolve (Expr, Typ);
6343 else
6344 Analyze_And_Resolve (Expr);
6345 end if;
6346
6347 -- An expression cannot be considered static if its resolution failed
6348 -- or if it's erroneous. Stop the analysis of the related pragma.
6349
6350 if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
6351 raise Pragma_Exit;
6352
6353 elsif Is_OK_Static_Expression (Expr) then
6354 return;
6355
6356 -- An interesting special case, if we have a string literal and we
6357 -- are in Ada 83 mode, then we allow it even though it will not be
6358 -- flagged as static. This allows the use of Ada 95 pragmas like
6359 -- Import in Ada 83 mode. They will of course be flagged with
6360 -- warnings as usual, but will not cause errors.
6361
6362 elsif Ada_Version = Ada_83
6363 and then Nkind (Expr) = N_String_Literal
6364 then
6365 return;
6366
6367 -- Finally, we have a real error
6368
6369 else
6370 Error_Msg_Name_1 := Pname;
6371 Flag_Non_Static_Expr
6372 (Fix_Error ("argument for pragma% must be a static expression!"),
6373 Expr);
6374 raise Pragma_Exit;
6375 end if;
6376 end Check_Expr_Is_OK_Static_Expression;
6377
6378 -------------------------
6379 -- Check_First_Subtype --
6380 -------------------------
6381
6382 procedure Check_First_Subtype (Arg : Node_Id) is
6383 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6384 Ent : constant Entity_Id := Entity (Argx);
6385
6386 begin
6387 if Is_First_Subtype (Ent) then
6388 null;
6389
6390 elsif Is_Type (Ent) then
6391 Error_Pragma_Arg
6392 ("pragma% cannot apply to subtype", Argx);
6393
6394 elsif Is_Object (Ent) then
6395 Error_Pragma_Arg
6396 ("pragma% cannot apply to object, requires a type", Argx);
6397
6398 else
6399 Error_Pragma_Arg
6400 ("pragma% cannot apply to&, requires a type", Argx);
6401 end if;
6402 end Check_First_Subtype;
6403
6404 ----------------------
6405 -- Check_Identifier --
6406 ----------------------
6407
6408 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
6409 begin
6410 if Present (Arg)
6411 and then Nkind (Arg) = N_Pragma_Argument_Association
6412 then
6413 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
6414 Error_Msg_Name_1 := Pname;
6415 Error_Msg_Name_2 := Id;
6416 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6417 raise Pragma_Exit;
6418 end if;
6419 end if;
6420 end Check_Identifier;
6421
6422 --------------------------------
6423 -- Check_Identifier_Is_One_Of --
6424 --------------------------------
6425
6426 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
6427 begin
6428 if Present (Arg)
6429 and then Nkind (Arg) = N_Pragma_Argument_Association
6430 then
6431 if Chars (Arg) = No_Name then
6432 Error_Msg_Name_1 := Pname;
6433 Error_Msg_N ("pragma% argument expects an identifier", Arg);
6434 raise Pragma_Exit;
6435
6436 elsif Chars (Arg) /= N1
6437 and then Chars (Arg) /= N2
6438 then
6439 Error_Msg_Name_1 := Pname;
6440 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
6441 raise Pragma_Exit;
6442 end if;
6443 end if;
6444 end Check_Identifier_Is_One_Of;
6445
6446 ---------------------------
6447 -- Check_In_Main_Program --
6448 ---------------------------
6449
6450 procedure Check_In_Main_Program is
6451 P : constant Node_Id := Parent (N);
6452
6453 begin
6454 -- Must be in subprogram body
6455
6456 if Nkind (P) /= N_Subprogram_Body then
6457 Error_Pragma ("% pragma allowed only in subprogram");
6458
6459 -- Otherwise warn if obviously not main program
6460
6461 elsif Present (Parameter_Specifications (Specification (P)))
6462 or else not Is_Compilation_Unit (Defining_Entity (P))
6463 then
6464 Error_Msg_Name_1 := Pname;
6465 Error_Msg_N
6466 ("??pragma% is only effective in main program", N);
6467 end if;
6468 end Check_In_Main_Program;
6469
6470 ---------------------------------------
6471 -- Check_Interrupt_Or_Attach_Handler --
6472 ---------------------------------------
6473
6474 procedure Check_Interrupt_Or_Attach_Handler is
6475 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
6476 Handler_Proc, Proc_Scope : Entity_Id;
6477
6478 begin
6479 Analyze (Arg1_X);
6480
6481 if Prag_Id = Pragma_Interrupt_Handler then
6482 Check_Restriction (No_Dynamic_Attachment, N);
6483 end if;
6484
6485 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
6486 Proc_Scope := Scope (Handler_Proc);
6487
6488 if Ekind (Proc_Scope) /= E_Protected_Type then
6489 Error_Pragma_Arg
6490 ("argument of pragma% must be protected procedure", Arg1);
6491 end if;
6492
6493 -- For pragma case (as opposed to access case), check placement.
6494 -- We don't need to do that for aspects, because we have the
6495 -- check that they aspect applies an appropriate procedure.
6496
6497 if not From_Aspect_Specification (N)
6498 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
6499 then
6500 Error_Pragma ("pragma% must be in protected definition");
6501 end if;
6502
6503 if not Is_Library_Level_Entity (Proc_Scope) then
6504 Error_Pragma_Arg
6505 ("argument for pragma% must be library level entity", Arg1);
6506 end if;
6507
6508 -- AI05-0033: A pragma cannot appear within a generic body, because
6509 -- instance can be in a nested scope. The check that protected type
6510 -- is itself a library-level declaration is done elsewhere.
6511
6512 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
6513 -- handle code prior to AI-0033. Analysis tools typically are not
6514 -- interested in this pragma in any case, so no need to worry too
6515 -- much about its placement.
6516
6517 if Inside_A_Generic then
6518 if Ekind (Scope (Current_Scope)) = E_Generic_Package
6519 and then In_Package_Body (Scope (Current_Scope))
6520 and then not Relaxed_RM_Semantics
6521 then
6522 Error_Pragma ("pragma% cannot be used inside a generic");
6523 end if;
6524 end if;
6525 end Check_Interrupt_Or_Attach_Handler;
6526
6527 ---------------------------------
6528 -- Check_Loop_Pragma_Placement --
6529 ---------------------------------
6530
6531 procedure Check_Loop_Pragma_Placement is
6532 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
6533 -- Verify whether the current pragma is properly grouped with other
6534 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
6535 -- related loop where the pragma appears.
6536
6537 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
6538 -- Determine whether an arbitrary statement Stmt denotes pragma
6539 -- Loop_Invariant or Loop_Variant.
6540
6541 procedure Placement_Error (Constr : Node_Id);
6542 pragma No_Return (Placement_Error);
6543 -- Node Constr denotes the last loop restricted construct before we
6544 -- encountered an illegal relation between enclosing constructs. Emit
6545 -- an error depending on what Constr was.
6546
6547 --------------------------------
6548 -- Check_Loop_Pragma_Grouping --
6549 --------------------------------
6550
6551 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
6552 function Check_Grouping (L : List_Id) return Boolean;
6553 -- Find the first group of pragmas in list L and if successful,
6554 -- ensure that the current pragma is part of that group. The
6555 -- routine returns True once such a check is performed to
6556 -- stop the analysis.
6557
6558 procedure Grouping_Error (Prag : Node_Id);
6559 pragma No_Return (Grouping_Error);
6560 -- Emit an error concerning the current pragma indicating that it
6561 -- should be placed after pragma Prag.
6562
6563 --------------------
6564 -- Check_Grouping --
6565 --------------------
6566
6567 function Check_Grouping (L : List_Id) return Boolean is
6568 HSS : Node_Id;
6569 Stmt : Node_Id;
6570 Prag : Node_Id := Empty; -- init to avoid warning
6571
6572 begin
6573 -- Inspect the list of declarations or statements looking for
6574 -- the first grouping of pragmas:
6575
6576 -- loop
6577 -- pragma Loop_Invariant ...;
6578 -- pragma Loop_Variant ...;
6579 -- . . . -- (1)
6580 -- pragma Loop_Variant ...; -- current pragma
6581
6582 -- If the current pragma is not in the grouping, then it must
6583 -- either appear in a different declarative or statement list
6584 -- or the construct at (1) is separating the pragma from the
6585 -- grouping.
6586
6587 Stmt := First (L);
6588 while Present (Stmt) loop
6589
6590 -- First pragma of the first topmost grouping has been found
6591
6592 if Is_Loop_Pragma (Stmt) then
6593
6594 -- The group and the current pragma are not in the same
6595 -- declarative or statement list.
6596
6597 if not In_Same_List (Stmt, N) then
6598 Grouping_Error (Stmt);
6599
6600 -- Try to reach the current pragma from the first pragma
6601 -- of the grouping while skipping other members:
6602
6603 -- pragma Loop_Invariant ...; -- first pragma
6604 -- pragma Loop_Variant ...; -- member
6605 -- . . .
6606 -- pragma Loop_Variant ...; -- current pragma
6607
6608 else
6609 while Present (Stmt) loop
6610 -- The current pragma is either the first pragma
6611 -- of the group or is a member of the group.
6612 -- Stop the search as the placement is legal.
6613
6614 if Stmt = N then
6615 return True;
6616
6617 -- Skip group members, but keep track of the
6618 -- last pragma in the group.
6619
6620 elsif Is_Loop_Pragma (Stmt) then
6621 Prag := Stmt;
6622
6623 -- Skip Annotate pragmas, typically used to justify
6624 -- unproved loop pragmas in GNATprove.
6625
6626 elsif Nkind (Stmt) = N_Pragma
6627 and then Pragma_Name (Stmt) = Name_Annotate
6628 then
6629 null;
6630
6631 -- Skip declarations and statements generated by
6632 -- the compiler during expansion. Note that some
6633 -- source statements (e.g. pragma Assert) may have
6634 -- been transformed so that they do not appear as
6635 -- coming from source anymore, so we instead look
6636 -- at their Original_Node.
6637
6638 elsif not Comes_From_Source (Original_Node (Stmt))
6639 then
6640 null;
6641
6642 -- A non-pragma is separating the group from the
6643 -- current pragma, the placement is illegal.
6644
6645 else
6646 Grouping_Error (Prag);
6647 end if;
6648
6649 Next (Stmt);
6650 end loop;
6651
6652 -- If the traversal did not reach the current pragma,
6653 -- then the list must be malformed.
6654
6655 raise Program_Error;
6656 end if;
6657
6658 -- Pragmas Loop_Invariant and Loop_Variant may only appear
6659 -- inside a loop or a block housed inside a loop. Inspect
6660 -- the declarations and statements of the block as they may
6661 -- contain the first grouping. This case follows the one for
6662 -- loop pragmas, as block statements which originate in a
6663 -- loop pragma (and so Is_Loop_Pragma will return True on
6664 -- that block statement) should be treated in the previous
6665 -- case.
6666
6667 elsif Nkind (Stmt) = N_Block_Statement then
6668 HSS := Handled_Statement_Sequence (Stmt);
6669
6670 if Check_Grouping (Declarations (Stmt)) then
6671 return True;
6672 end if;
6673
6674 if Present (HSS) then
6675 if Check_Grouping (Statements (HSS)) then
6676 return True;
6677 end if;
6678 end if;
6679 end if;
6680
6681 Next (Stmt);
6682 end loop;
6683
6684 return False;
6685 end Check_Grouping;
6686
6687 --------------------
6688 -- Grouping_Error --
6689 --------------------
6690
6691 procedure Grouping_Error (Prag : Node_Id) is
6692 begin
6693 Error_Msg_Sloc := Sloc (Prag);
6694 Error_Pragma ("pragma% must appear next to pragma#");
6695 end Grouping_Error;
6696
6697 Ignore : Boolean;
6698
6699 -- Start of processing for Check_Loop_Pragma_Grouping
6700
6701 begin
6702 -- Inspect the statements of the loop or nested blocks housed
6703 -- within to determine whether the current pragma is part of the
6704 -- first topmost grouping of Loop_Invariant and Loop_Variant.
6705
6706 Ignore := Check_Grouping (Statements (Loop_Stmt));
6707 end Check_Loop_Pragma_Grouping;
6708
6709 --------------------
6710 -- Is_Loop_Pragma --
6711 --------------------
6712
6713 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
6714 Original_Stmt : constant Node_Id := Original_Node (Stmt);
6715
6716 begin
6717 -- Inspect the original node as Loop_Invariant and Loop_Variant
6718 -- pragmas are rewritten to null when assertions are disabled.
6719
6720 return Nkind (Original_Stmt) = N_Pragma
6721 and then Pragma_Name_Unmapped (Original_Stmt)
6722 in Name_Loop_Invariant | Name_Loop_Variant;
6723 end Is_Loop_Pragma;
6724
6725 ---------------------
6726 -- Placement_Error --
6727 ---------------------
6728
6729 procedure Placement_Error (Constr : Node_Id) is
6730 LA : constant String := " with Loop_Entry";
6731
6732 begin
6733 if Prag_Id = Pragma_Assert then
6734 Error_Msg_String (1 .. LA'Length) := LA;
6735 Error_Msg_Strlen := LA'Length;
6736 else
6737 Error_Msg_Strlen := 0;
6738 end if;
6739
6740 if Nkind (Constr) = N_Pragma then
6741 Error_Pragma
6742 ("pragma %~ must appear immediately within the statements "
6743 & "of a loop");
6744 else
6745 Error_Pragma_Arg
6746 ("block containing pragma %~ must appear immediately within "
6747 & "the statements of a loop", Constr);
6748 end if;
6749 end Placement_Error;
6750
6751 -- Local declarations
6752
6753 Prev : Node_Id;
6754 Stmt : Node_Id;
6755
6756 -- Start of processing for Check_Loop_Pragma_Placement
6757
6758 begin
6759 -- Check that pragma appears immediately within a loop statement,
6760 -- ignoring intervening block statements.
6761
6762 Prev := N;
6763 Stmt := Parent (N);
6764 while Present (Stmt) loop
6765
6766 -- The pragma or previous block must appear immediately within the
6767 -- current block's declarative or statement part.
6768
6769 if Nkind (Stmt) = N_Block_Statement then
6770 if (No (Declarations (Stmt))
6771 or else List_Containing (Prev) /= Declarations (Stmt))
6772 and then
6773 List_Containing (Prev) /=
6774 Statements (Handled_Statement_Sequence (Stmt))
6775 then
6776 Placement_Error (Prev);
6777
6778 -- Keep inspecting the parents because we are now within a
6779 -- chain of nested blocks.
6780
6781 else
6782 Prev := Stmt;
6783 Stmt := Parent (Stmt);
6784 end if;
6785
6786 -- The pragma or previous block must appear immediately within the
6787 -- statements of the loop.
6788
6789 elsif Nkind (Stmt) = N_Loop_Statement then
6790 if List_Containing (Prev) /= Statements (Stmt) then
6791 Placement_Error (Prev);
6792 end if;
6793
6794 -- Stop the traversal because we reached the innermost loop
6795 -- regardless of whether we encountered an error or not.
6796
6797 exit;
6798
6799 -- Ignore a handled statement sequence. Note that this node may
6800 -- be related to a subprogram body in which case we will emit an
6801 -- error on the next iteration of the search.
6802
6803 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
6804 Stmt := Parent (Stmt);
6805
6806 -- Any other statement breaks the chain from the pragma to the
6807 -- loop.
6808
6809 else
6810 Placement_Error (Prev);
6811 end if;
6812 end loop;
6813
6814 -- Check that the current pragma Loop_Invariant or Loop_Variant is
6815 -- grouped together with other such pragmas.
6816
6817 if Is_Loop_Pragma (N) then
6818
6819 -- The previous check should have located the related loop
6820
6821 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
6822 Check_Loop_Pragma_Grouping (Stmt);
6823 end if;
6824 end Check_Loop_Pragma_Placement;
6825
6826 -------------------------------------------
6827 -- Check_Is_In_Decl_Part_Or_Package_Spec --
6828 -------------------------------------------
6829
6830 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
6831 P : Node_Id;
6832
6833 begin
6834 P := Parent (N);
6835 loop
6836 if No (P) then
6837 exit;
6838
6839 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
6840 exit;
6841
6842 elsif Nkind (P) in N_Package_Specification | N_Block_Statement then
6843 return;
6844
6845 -- Note: the following tests seem a little peculiar, because
6846 -- they test for bodies, but if we were in the statement part
6847 -- of the body, we would already have hit the handled statement
6848 -- sequence, so the only way we get here is by being in the
6849 -- declarative part of the body.
6850
6851 elsif Nkind (P) in
6852 N_Subprogram_Body | N_Package_Body | N_Task_Body | N_Entry_Body
6853 then
6854 return;
6855 end if;
6856
6857 P := Parent (P);
6858 end loop;
6859
6860 Error_Pragma ("pragma% is not in declarative part or package spec");
6861 end Check_Is_In_Decl_Part_Or_Package_Spec;
6862
6863 -------------------------
6864 -- Check_No_Identifier --
6865 -------------------------
6866
6867 procedure Check_No_Identifier (Arg : Node_Id) is
6868 begin
6869 if Nkind (Arg) = N_Pragma_Argument_Association
6870 and then Chars (Arg) /= No_Name
6871 then
6872 Error_Pragma_Arg_Ident
6873 ("pragma% does not permit identifier& here", Arg);
6874 end if;
6875 end Check_No_Identifier;
6876
6877 --------------------------
6878 -- Check_No_Identifiers --
6879 --------------------------
6880
6881 procedure Check_No_Identifiers is
6882 Arg_Node : Node_Id;
6883 begin
6884 Arg_Node := Arg1;
6885 for J in 1 .. Arg_Count loop
6886 Check_No_Identifier (Arg_Node);
6887 Next (Arg_Node);
6888 end loop;
6889 end Check_No_Identifiers;
6890
6891 ------------------------
6892 -- Check_No_Link_Name --
6893 ------------------------
6894
6895 procedure Check_No_Link_Name is
6896 begin
6897 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
6898 Arg4 := Arg3;
6899 end if;
6900
6901 if Present (Arg4) then
6902 Error_Pragma_Arg
6903 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
6904 end if;
6905 end Check_No_Link_Name;
6906
6907 -------------------------------
6908 -- Check_Optional_Identifier --
6909 -------------------------------
6910
6911 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
6912 begin
6913 if Present (Arg)
6914 and then Nkind (Arg) = N_Pragma_Argument_Association
6915 and then Chars (Arg) /= No_Name
6916 then
6917 if Chars (Arg) /= Id then
6918 Error_Msg_Name_1 := Pname;
6919 Error_Msg_Name_2 := Id;
6920 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6921 raise Pragma_Exit;
6922 end if;
6923 end if;
6924 end Check_Optional_Identifier;
6925
6926 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
6927 begin
6928 Check_Optional_Identifier (Arg, Name_Find (Id));
6929 end Check_Optional_Identifier;
6930
6931 -------------------------------------
6932 -- Check_Static_Boolean_Expression --
6933 -------------------------------------
6934
6935 procedure Check_Static_Boolean_Expression (Expr : Node_Id) is
6936 begin
6937 if Present (Expr) then
6938 Analyze_And_Resolve (Expr, Standard_Boolean);
6939
6940 if not Is_OK_Static_Expression (Expr) then
6941 Error_Pragma_Arg
6942 ("expression of pragma % must be static", Expr);
6943 end if;
6944 end if;
6945 end Check_Static_Boolean_Expression;
6946
6947 -----------------------------
6948 -- Check_Static_Constraint --
6949 -----------------------------
6950
6951 procedure Check_Static_Constraint (Constr : Node_Id) is
6952
6953 procedure Require_Static (E : Node_Id);
6954 -- Require given expression to be static expression
6955
6956 --------------------
6957 -- Require_Static --
6958 --------------------
6959
6960 procedure Require_Static (E : Node_Id) is
6961 begin
6962 if not Is_OK_Static_Expression (E) then
6963 Flag_Non_Static_Expr
6964 ("non-static constraint not allowed in Unchecked_Union!", E);
6965 raise Pragma_Exit;
6966 end if;
6967 end Require_Static;
6968
6969 -- Start of processing for Check_Static_Constraint
6970
6971 begin
6972 case Nkind (Constr) is
6973 when N_Discriminant_Association =>
6974 Require_Static (Expression (Constr));
6975
6976 when N_Range =>
6977 Require_Static (Low_Bound (Constr));
6978 Require_Static (High_Bound (Constr));
6979
6980 when N_Attribute_Reference =>
6981 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
6982 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
6983
6984 when N_Range_Constraint =>
6985 Check_Static_Constraint (Range_Expression (Constr));
6986
6987 when N_Index_Or_Discriminant_Constraint =>
6988 declare
6989 IDC : Entity_Id;
6990 begin
6991 IDC := First (Constraints (Constr));
6992 while Present (IDC) loop
6993 Check_Static_Constraint (IDC);
6994 Next (IDC);
6995 end loop;
6996 end;
6997
6998 when others =>
6999 null;
7000 end case;
7001 end Check_Static_Constraint;
7002
7003 --------------------------------------
7004 -- Check_Valid_Configuration_Pragma --
7005 --------------------------------------
7006
7007 -- A configuration pragma must appear in the context clause of a
7008 -- compilation unit, and only other pragmas may precede it. Note that
7009 -- the test also allows use in a configuration pragma file.
7010
7011 procedure Check_Valid_Configuration_Pragma is
7012 begin
7013 if not Is_Configuration_Pragma then
7014 Error_Pragma ("incorrect placement for configuration pragma%");
7015 end if;
7016 end Check_Valid_Configuration_Pragma;
7017
7018 -------------------------------------
7019 -- Check_Valid_Library_Unit_Pragma --
7020 -------------------------------------
7021
7022 procedure Check_Valid_Library_Unit_Pragma is
7023 Plist : List_Id;
7024 Parent_Node : Node_Id;
7025 Unit_Name : Entity_Id;
7026 Unit_Kind : Node_Kind;
7027 Unit_Node : Node_Id;
7028 Sindex : Source_File_Index;
7029
7030 begin
7031 if not Is_List_Member (N) then
7032 Pragma_Misplaced;
7033
7034 else
7035 Plist := List_Containing (N);
7036 Parent_Node := Parent (Plist);
7037
7038 if Parent_Node = Empty then
7039 Pragma_Misplaced;
7040
7041 -- Case of pragma appearing after a compilation unit. In this case
7042 -- it must have an argument with the corresponding name and must
7043 -- be part of the following pragmas of its parent.
7044
7045 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
7046 if Plist /= Pragmas_After (Parent_Node) then
7047 Error_Pragma
7048 ("pragma% misplaced, must be inside or after the "
7049 & "compilation unit");
7050
7051 elsif Arg_Count = 0 then
7052 Error_Pragma
7053 ("argument required if outside compilation unit");
7054
7055 else
7056 Check_No_Identifiers;
7057 Check_Arg_Count (1);
7058 Unit_Node := Unit (Parent (Parent_Node));
7059 Unit_Kind := Nkind (Unit_Node);
7060
7061 Analyze (Get_Pragma_Arg (Arg1));
7062
7063 if Unit_Kind = N_Generic_Subprogram_Declaration
7064 or else Unit_Kind = N_Subprogram_Declaration
7065 then
7066 Unit_Name := Defining_Entity (Unit_Node);
7067
7068 elsif Unit_Kind in N_Generic_Instantiation then
7069 Unit_Name := Defining_Entity (Unit_Node);
7070
7071 else
7072 Unit_Name := Cunit_Entity (Current_Sem_Unit);
7073 end if;
7074
7075 if Chars (Unit_Name) /=
7076 Chars (Entity (Get_Pragma_Arg (Arg1)))
7077 then
7078 Error_Pragma_Arg
7079 ("pragma% argument is not current unit name", Arg1);
7080 end if;
7081
7082 if Ekind (Unit_Name) = E_Package
7083 and then Present (Renamed_Entity (Unit_Name))
7084 then
7085 Error_Pragma ("pragma% not allowed for renamed package");
7086 end if;
7087 end if;
7088
7089 -- Pragma appears other than after a compilation unit
7090
7091 else
7092 -- Here we check for the generic instantiation case and also
7093 -- for the case of processing a generic formal package. We
7094 -- detect these cases by noting that the Sloc on the node
7095 -- does not belong to the current compilation unit.
7096
7097 Sindex := Source_Index (Current_Sem_Unit);
7098
7099 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
7100 -- We do not want to raise an exception here since this code
7101 -- is part of the bootstrap path where we cannot rely on
7102 -- exception propagation working.
7103 -- Instead the caller should check for N being rewritten as
7104 -- a null statement.
7105 -- This code triggers when compiling a-except.adb.
7106
7107 Rewrite (N, Make_Null_Statement (Loc));
7108
7109 -- If before first declaration, the pragma applies to the
7110 -- enclosing unit, and the name if present must be this name.
7111
7112 elsif Is_Before_First_Decl (N, Plist) then
7113 Unit_Node := Unit_Declaration_Node (Current_Scope);
7114 Unit_Kind := Nkind (Unit_Node);
7115
7116 if Unit_Node = Standard_Package_Node then
7117 Error_Pragma
7118 ("pragma% misplaced, must be inside or after the "
7119 & "compilation unit");
7120
7121 elsif Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
7122 Error_Pragma
7123 ("pragma% misplaced, must be on library unit");
7124
7125 elsif Unit_Kind = N_Subprogram_Body
7126 and then not Acts_As_Spec (Unit_Node)
7127 then
7128 Error_Pragma
7129 ("pragma% misplaced, must be on the subprogram spec");
7130
7131 elsif Nkind (Parent_Node) = N_Package_Body then
7132 Error_Pragma
7133 ("pragma% misplaced, must be on the package spec");
7134
7135 elsif Nkind (Parent_Node) = N_Package_Specification
7136 and then Plist = Private_Declarations (Parent_Node)
7137 then
7138 Error_Pragma
7139 ("pragma% misplaced, must be in the public part");
7140
7141 elsif Nkind (Parent_Node) in N_Generic_Declaration
7142 and then Plist = Generic_Formal_Declarations (Parent_Node)
7143 then
7144 Error_Pragma
7145 ("pragma% misplaced, must not be in formal part");
7146
7147 elsif Arg_Count > 0 then
7148 Analyze (Get_Pragma_Arg (Arg1));
7149
7150 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
7151 Error_Pragma_Arg
7152 ("name in pragma% must be enclosing unit", Arg1);
7153 end if;
7154
7155 -- It is legal to have no argument in this context
7156
7157 else
7158 return;
7159 end if;
7160
7161 -- Error if not before first declaration. This is because a
7162 -- library unit pragma argument must be the name of a library
7163 -- unit (RM 10.1.5(7)), but the only names permitted in this
7164 -- context are (RM 10.1.5(6)) names of subprogram declarations,
7165 -- generic subprogram declarations or generic instantiations.
7166
7167 else
7168 Error_Pragma
7169 ("pragma% misplaced, must be before first declaration");
7170 end if;
7171 end if;
7172 end if;
7173 end Check_Valid_Library_Unit_Pragma;
7174
7175 -------------------
7176 -- Check_Variant --
7177 -------------------
7178
7179 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
7180 Clist : constant Node_Id := Component_List (Variant);
7181 Comp : Node_Id;
7182
7183 begin
7184 Comp := First_Non_Pragma (Component_Items (Clist));
7185 while Present (Comp) loop
7186 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
7187 Next_Non_Pragma (Comp);
7188 end loop;
7189 end Check_Variant;
7190
7191 ---------------------------
7192 -- Ensure_Aggregate_Form --
7193 ---------------------------
7194
7195 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
7196 CFSD : constant Boolean := Get_Comes_From_Source_Default;
7197 Expr : constant Node_Id := Expression (Arg);
7198 Loc : constant Source_Ptr := Sloc (Expr);
7199 Comps : List_Id := No_List;
7200 Exprs : List_Id := No_List;
7201 Nam : Name_Id := No_Name;
7202 Nam_Loc : Source_Ptr;
7203
7204 begin
7205 -- The pragma argument is in positional form:
7206
7207 -- pragma Depends (Nam => ...)
7208 -- ^
7209 -- Chars field
7210
7211 -- Note that the Sloc of the Chars field is the Sloc of the pragma
7212 -- argument association.
7213
7214 if Nkind (Arg) = N_Pragma_Argument_Association then
7215 Nam := Chars (Arg);
7216 Nam_Loc := Sloc (Arg);
7217
7218 -- Remove the pragma argument name as this will be captured in the
7219 -- aggregate.
7220
7221 Set_Chars (Arg, No_Name);
7222 end if;
7223
7224 -- The argument is already in aggregate form, but the presence of a
7225 -- name causes this to be interpreted as named association which in
7226 -- turn must be converted into an aggregate.
7227
7228 -- pragma Global (In_Out => (A, B, C))
7229 -- ^ ^
7230 -- name aggregate
7231
7232 -- pragma Global ((In_Out => (A, B, C)))
7233 -- ^ ^
7234 -- aggregate aggregate
7235
7236 if Nkind (Expr) = N_Aggregate then
7237 if Nam = No_Name then
7238 return;
7239 end if;
7240
7241 -- Do not transform a null argument into an aggregate as N_Null has
7242 -- special meaning in formal verification pragmas.
7243
7244 elsif Nkind (Expr) = N_Null then
7245 return;
7246 end if;
7247
7248 -- Everything comes from source if the original comes from source
7249
7250 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
7251
7252 -- Positional argument is transformed into an aggregate with an
7253 -- Expressions list.
7254
7255 if Nam = No_Name then
7256 Exprs := New_List (Relocate_Node (Expr));
7257
7258 -- An associative argument is transformed into an aggregate with
7259 -- Component_Associations.
7260
7261 else
7262 Comps := New_List (
7263 Make_Component_Association (Loc,
7264 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
7265 Expression => Relocate_Node (Expr)));
7266 end if;
7267
7268 Set_Expression (Arg,
7269 Make_Aggregate (Loc,
7270 Component_Associations => Comps,
7271 Expressions => Exprs));
7272
7273 -- Restore Comes_From_Source default
7274
7275 Set_Comes_From_Source_Default (CFSD);
7276 end Ensure_Aggregate_Form;
7277
7278 ------------------
7279 -- Error_Pragma --
7280 ------------------
7281
7282 procedure Error_Pragma (Msg : String) is
7283 begin
7284 Error_Msg_Name_1 := Pname;
7285 Error_Msg_N (Fix_Error (Msg), N);
7286 raise Pragma_Exit;
7287 end Error_Pragma;
7288
7289 ----------------------
7290 -- Error_Pragma_Arg --
7291 ----------------------
7292
7293 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
7294 begin
7295 Error_Msg_Name_1 := Pname;
7296 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
7297 raise Pragma_Exit;
7298 end Error_Pragma_Arg;
7299
7300 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
7301 begin
7302 Error_Msg_Name_1 := Pname;
7303 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
7304 Error_Pragma_Arg (Msg2, Arg);
7305 end Error_Pragma_Arg;
7306
7307 ----------------------------
7308 -- Error_Pragma_Arg_Ident --
7309 ----------------------------
7310
7311 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
7312 begin
7313 Error_Msg_Name_1 := Pname;
7314 Error_Msg_N (Fix_Error (Msg), Arg);
7315 raise Pragma_Exit;
7316 end Error_Pragma_Arg_Ident;
7317
7318 ----------------------
7319 -- Error_Pragma_Ref --
7320 ----------------------
7321
7322 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
7323 begin
7324 Error_Msg_Name_1 := Pname;
7325 Error_Msg_Sloc := Sloc (Ref);
7326 Error_Msg_NE (Fix_Error (Msg), N, Ref);
7327 raise Pragma_Exit;
7328 end Error_Pragma_Ref;
7329
7330 ------------------------
7331 -- Find_Lib_Unit_Name --
7332 ------------------------
7333
7334 function Find_Lib_Unit_Name return Entity_Id is
7335 begin
7336 -- Return inner compilation unit entity, for case of nested
7337 -- categorization pragmas. This happens in generic unit.
7338
7339 if Nkind (Parent (N)) = N_Package_Specification
7340 and then Defining_Entity (Parent (N)) /= Current_Scope
7341 then
7342 return Defining_Entity (Parent (N));
7343 else
7344 return Current_Scope;
7345 end if;
7346 end Find_Lib_Unit_Name;
7347
7348 ----------------------------
7349 -- Find_Program_Unit_Name --
7350 ----------------------------
7351
7352 procedure Find_Program_Unit_Name (Id : Node_Id) is
7353 Unit_Name : Entity_Id;
7354 Unit_Kind : Node_Kind;
7355 P : constant Node_Id := Parent (N);
7356
7357 begin
7358 if Nkind (P) = N_Compilation_Unit then
7359 Unit_Kind := Nkind (Unit (P));
7360
7361 if Unit_Kind in N_Subprogram_Declaration
7362 | N_Package_Declaration
7363 | N_Generic_Declaration
7364 then
7365 Unit_Name := Defining_Entity (Unit (P));
7366
7367 if Chars (Id) = Chars (Unit_Name) then
7368 Set_Entity (Id, Unit_Name);
7369 Set_Etype (Id, Etype (Unit_Name));
7370 else
7371 Set_Etype (Id, Any_Type);
7372 Error_Pragma
7373 ("cannot find program unit referenced by pragma%");
7374 end if;
7375
7376 else
7377 Set_Etype (Id, Any_Type);
7378 Error_Pragma ("pragma% inapplicable to this unit");
7379 end if;
7380
7381 else
7382 Analyze (Id);
7383 end if;
7384 end Find_Program_Unit_Name;
7385
7386 -----------------------------------------
7387 -- Find_Unique_Parameterless_Procedure --
7388 -----------------------------------------
7389
7390 function Find_Unique_Parameterless_Procedure
7391 (Name : Entity_Id;
7392 Arg : Node_Id) return Entity_Id
7393 is
7394 Proc : Entity_Id := Empty;
7395
7396 begin
7397 -- Perform sanity checks on Name
7398
7399 if not Is_Entity_Name (Name) then
7400 Error_Pragma_Arg
7401 ("argument of pragma% must be entity name", Arg);
7402
7403 elsif not Is_Overloaded (Name) then
7404 Proc := Entity (Name);
7405
7406 if Ekind (Proc) /= E_Procedure
7407 or else Present (First_Formal (Proc))
7408 then
7409 Error_Pragma_Arg
7410 ("argument of pragma% must be parameterless procedure", Arg);
7411 end if;
7412
7413 -- Otherwise, search through interpretations looking for one which
7414 -- has no parameters.
7415
7416 else
7417 declare
7418 Found : Boolean := False;
7419 It : Interp;
7420 Index : Interp_Index;
7421
7422 begin
7423 Get_First_Interp (Name, Index, It);
7424 while Present (It.Nam) loop
7425 Proc := It.Nam;
7426
7427 if Ekind (Proc) = E_Procedure
7428 and then No (First_Formal (Proc))
7429 then
7430 -- We found an interpretation, note it and continue
7431 -- looking looking to verify it is unique.
7432
7433 if not Found then
7434 Found := True;
7435 Set_Entity (Name, Proc);
7436 Set_Is_Overloaded (Name, False);
7437
7438 -- Two procedures with the same name, log an error
7439 -- since the name is ambiguous.
7440
7441 else
7442 Error_Pragma_Arg
7443 ("ambiguous handler name for pragma%", Arg);
7444 end if;
7445 end if;
7446
7447 Get_Next_Interp (Index, It);
7448 end loop;
7449
7450 if not Found then
7451 -- Issue an error if we haven't found a suitable match for
7452 -- Name.
7453
7454 Error_Pragma_Arg
7455 ("argument of pragma% must be parameterless procedure",
7456 Arg);
7457
7458 else
7459 Proc := Entity (Name);
7460 end if;
7461 end;
7462 end if;
7463
7464 return Proc;
7465 end Find_Unique_Parameterless_Procedure;
7466
7467 ---------------
7468 -- Fix_Error --
7469 ---------------
7470
7471 function Fix_Error (Msg : String) return String is
7472 Res : String (Msg'Range) := Msg;
7473 Res_Last : Natural := Msg'Last;
7474 J : Natural;
7475
7476 begin
7477 -- If we have a rewriting of another pragma, go to that pragma
7478
7479 if Is_Rewrite_Substitution (N)
7480 and then Nkind (Original_Node (N)) = N_Pragma
7481 then
7482 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
7483 end if;
7484
7485 -- Case where pragma comes from an aspect specification
7486
7487 if From_Aspect_Specification (N) then
7488
7489 -- Change appearance of "pragma" in message to "aspect"
7490
7491 J := Res'First;
7492 while J <= Res_Last - 5 loop
7493 if Res (J .. J + 5) = "pragma" then
7494 Res (J .. J + 5) := "aspect";
7495 J := J + 6;
7496
7497 else
7498 J := J + 1;
7499 end if;
7500 end loop;
7501
7502 -- Change "argument of" at start of message to "entity for"
7503
7504 if Res'Length > 11
7505 and then Res (Res'First .. Res'First + 10) = "argument of"
7506 then
7507 Res (Res'First .. Res'First + 9) := "entity for";
7508 Res (Res'First + 10 .. Res_Last - 1) :=
7509 Res (Res'First + 11 .. Res_Last);
7510 Res_Last := Res_Last - 1;
7511 end if;
7512
7513 -- Change "argument" at start of message to "entity"
7514
7515 if Res'Length > 8
7516 and then Res (Res'First .. Res'First + 7) = "argument"
7517 then
7518 Res (Res'First .. Res'First + 5) := "entity";
7519 Res (Res'First + 6 .. Res_Last - 2) :=
7520 Res (Res'First + 8 .. Res_Last);
7521 Res_Last := Res_Last - 2;
7522 end if;
7523
7524 -- Get name from corresponding aspect
7525
7526 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
7527 end if;
7528
7529 -- Return possibly modified message
7530
7531 return Res (Res'First .. Res_Last);
7532 end Fix_Error;
7533
7534 -------------------------
7535 -- Gather_Associations --
7536 -------------------------
7537
7538 procedure Gather_Associations
7539 (Names : Name_List;
7540 Args : out Args_List)
7541 is
7542 Arg : Node_Id;
7543
7544 begin
7545 -- Initialize all parameters to Empty
7546
7547 for J in Args'Range loop
7548 Args (J) := Empty;
7549 end loop;
7550
7551 -- That's all we have to do if there are no argument associations
7552
7553 if No (Pragma_Argument_Associations (N)) then
7554 return;
7555 end if;
7556
7557 -- Otherwise first deal with any positional parameters present
7558
7559 Arg := First (Pragma_Argument_Associations (N));
7560 for Index in Args'Range loop
7561 exit when No (Arg) or else Chars (Arg) /= No_Name;
7562 Args (Index) := Get_Pragma_Arg (Arg);
7563 Next (Arg);
7564 end loop;
7565
7566 -- Positional parameters all processed, if any left, then we
7567 -- have too many positional parameters.
7568
7569 if Present (Arg) and then Chars (Arg) = No_Name then
7570 Error_Pragma_Arg
7571 ("too many positional associations for pragma%", Arg);
7572 end if;
7573
7574 -- Process named parameters if any are present
7575
7576 while Present (Arg) loop
7577 if Chars (Arg) = No_Name then
7578 Error_Pragma_Arg
7579 ("positional association cannot follow named association",
7580 Arg);
7581
7582 else
7583 for Index in Names'Range loop
7584 if Names (Index) = Chars (Arg) then
7585 if Present (Args (Index)) then
7586 Error_Pragma_Arg
7587 ("duplicate argument association for pragma%", Arg);
7588 else
7589 Args (Index) := Get_Pragma_Arg (Arg);
7590 exit;
7591 end if;
7592 end if;
7593
7594 if Index = Names'Last then
7595 Error_Msg_Name_1 := Pname;
7596 Error_Msg_N ("pragma% does not allow & argument", Arg);
7597
7598 -- Check for possible misspelling
7599
7600 for Index1 in Names'Range loop
7601 if Is_Bad_Spelling_Of
7602 (Chars (Arg), Names (Index1))
7603 then
7604 Error_Msg_Name_1 := Names (Index1);
7605 Error_Msg_N -- CODEFIX
7606 ("\possible misspelling of%", Arg);
7607 exit;
7608 end if;
7609 end loop;
7610
7611 raise Pragma_Exit;
7612 end if;
7613 end loop;
7614 end if;
7615
7616 Next (Arg);
7617 end loop;
7618 end Gather_Associations;
7619
7620 -----------------
7621 -- GNAT_Pragma --
7622 -----------------
7623
7624 procedure GNAT_Pragma is
7625 begin
7626 -- We need to check the No_Implementation_Pragmas restriction for
7627 -- the case of a pragma from source. Note that the case of aspects
7628 -- generating corresponding pragmas marks these pragmas as not being
7629 -- from source, so this test also catches that case.
7630
7631 if Comes_From_Source (N) then
7632 Check_Restriction (No_Implementation_Pragmas, N);
7633 end if;
7634 end GNAT_Pragma;
7635
7636 --------------------------
7637 -- Is_Before_First_Decl --
7638 --------------------------
7639
7640 function Is_Before_First_Decl
7641 (Pragma_Node : Node_Id;
7642 Decls : List_Id) return Boolean
7643 is
7644 Item : Node_Id := First (Decls);
7645
7646 begin
7647 -- Only other pragmas can come before this pragma, but they might
7648 -- have been rewritten so check the original node.
7649
7650 loop
7651 if No (Item) or else Nkind (Original_Node (Item)) /= N_Pragma then
7652 return False;
7653
7654 elsif Item = Pragma_Node then
7655 return True;
7656 end if;
7657
7658 Next (Item);
7659 end loop;
7660 end Is_Before_First_Decl;
7661
7662 -----------------------------
7663 -- Is_Configuration_Pragma --
7664 -----------------------------
7665
7666 -- A configuration pragma must appear in the context clause of a
7667 -- compilation unit, and only other pragmas may precede it. Note that
7668 -- the test below also permits use in a configuration pragma file.
7669
7670 function Is_Configuration_Pragma return Boolean is
7671 Lis : List_Id;
7672 Par : constant Node_Id := Parent (N);
7673 Prg : Node_Id;
7674
7675 begin
7676 -- Don't evaluate List_Containing (N) if Parent (N) could be
7677 -- an N_Aspect_Specification node.
7678
7679 if not Is_List_Member (N) then
7680 return False;
7681 end if;
7682
7683 Lis := List_Containing (N);
7684
7685 -- If no parent, then we are in the configuration pragma file,
7686 -- so the placement is definitely appropriate.
7687
7688 if No (Par) then
7689 return True;
7690
7691 -- Otherwise we must be in the context clause of a compilation unit
7692 -- and the only thing allowed before us in the context list is more
7693 -- configuration pragmas.
7694
7695 elsif Nkind (Par) = N_Compilation_Unit
7696 and then Context_Items (Par) = Lis
7697 then
7698 Prg := First (Lis);
7699
7700 loop
7701 if Prg = N then
7702 return True;
7703 elsif Nkind (Prg) /= N_Pragma then
7704 return False;
7705 end if;
7706
7707 Next (Prg);
7708 end loop;
7709
7710 else
7711 return False;
7712 end if;
7713 end Is_Configuration_Pragma;
7714
7715 --------------------------
7716 -- Is_In_Context_Clause --
7717 --------------------------
7718
7719 function Is_In_Context_Clause return Boolean is
7720 Plist : List_Id;
7721 Parent_Node : Node_Id;
7722
7723 begin
7724 if Is_List_Member (N) then
7725 Plist := List_Containing (N);
7726 Parent_Node := Parent (Plist);
7727
7728 return Present (Parent_Node)
7729 and then Nkind (Parent_Node) = N_Compilation_Unit
7730 and then Context_Items (Parent_Node) = Plist;
7731 end if;
7732
7733 return False;
7734 end Is_In_Context_Clause;
7735
7736 ---------------------------------
7737 -- Is_Static_String_Expression --
7738 ---------------------------------
7739
7740 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
7741 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
7742 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
7743
7744 begin
7745 Analyze_And_Resolve (Argx);
7746
7747 -- Special case Ada 83, where the expression will never be static,
7748 -- but we will return true if we had a string literal to start with.
7749
7750 if Ada_Version = Ada_83 then
7751 return Lit;
7752
7753 -- Normal case, true only if we end up with a string literal that
7754 -- is marked as being the result of evaluating a static expression.
7755
7756 else
7757 return Is_OK_Static_Expression (Argx)
7758 and then Nkind (Argx) = N_String_Literal;
7759 end if;
7760
7761 end Is_Static_String_Expression;
7762
7763 ----------------------
7764 -- Pragma_Misplaced --
7765 ----------------------
7766
7767 procedure Pragma_Misplaced is
7768 begin
7769 Error_Pragma ("incorrect placement of pragma%");
7770 end Pragma_Misplaced;
7771
7772 ------------------------------------------------
7773 -- Process_Atomic_Independent_Shared_Volatile --
7774 ------------------------------------------------
7775
7776 procedure Process_Atomic_Independent_Shared_Volatile is
7777 procedure Check_Full_Access_Only (Ent : Entity_Id);
7778 -- Apply legality checks to type or object Ent subject to the
7779 -- Full_Access_Only aspect in Ada 2022 (RM C.6(8.2)).
7780
7781 procedure Mark_Component_Or_Object (Ent : Entity_Id);
7782 -- Appropriately set flags on the given entity, either an array or
7783 -- record component, or an object declaration) according to the
7784 -- current pragma.
7785
7786 procedure Mark_Type (Ent : Entity_Id);
7787 -- Appropriately set flags on the given entity, a type
7788
7789 procedure Set_Atomic_VFA (Ent : Entity_Id);
7790 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
7791 -- no explicit alignment was given, set alignment to unknown, since
7792 -- back end knows what the alignment requirements are for atomic and
7793 -- full access arrays. Note: this is necessary for derived types.
7794
7795 -------------------------
7796 -- Check_Full_Access_Only --
7797 -------------------------
7798
7799 procedure Check_Full_Access_Only (Ent : Entity_Id) is
7800 Typ : Entity_Id;
7801
7802 Full_Access_Subcomponent : exception;
7803 -- Exception raised if a full access subcomponent is found
7804
7805 Generic_Type_Subcomponent : exception;
7806 -- Exception raised if a subcomponent with generic type is found
7807
7808 procedure Check_Subcomponents (Typ : Entity_Id);
7809 -- Apply checks to subcomponents recursively
7810
7811 -------------------------
7812 -- Check_Subcomponents --
7813 -------------------------
7814
7815 procedure Check_Subcomponents (Typ : Entity_Id) is
7816 Comp : Entity_Id;
7817
7818 begin
7819 if Is_Array_Type (Typ) then
7820 Comp := Component_Type (Typ);
7821
7822 if Has_Atomic_Components (Typ)
7823 or else Is_Full_Access (Comp)
7824 then
7825 raise Full_Access_Subcomponent;
7826
7827 elsif Is_Generic_Type (Comp) then
7828 raise Generic_Type_Subcomponent;
7829 end if;
7830
7831 -- Recurse on the component type
7832
7833 Check_Subcomponents (Comp);
7834
7835 elsif Is_Record_Type (Typ) then
7836 Comp := First_Component_Or_Discriminant (Typ);
7837 while Present (Comp) loop
7838
7839 if Is_Full_Access (Comp)
7840 or else Is_Full_Access (Etype (Comp))
7841 then
7842 raise Full_Access_Subcomponent;
7843
7844 elsif Is_Generic_Type (Etype (Comp)) then
7845 raise Generic_Type_Subcomponent;
7846 end if;
7847
7848 -- Recurse on the component type
7849
7850 Check_Subcomponents (Etype (Comp));
7851
7852 Next_Component_Or_Discriminant (Comp);
7853 end loop;
7854 end if;
7855 end Check_Subcomponents;
7856
7857 -- Start of processing for Check_Full_Access_Only
7858
7859 begin
7860 -- Fetch the type in case we are dealing with an object or
7861 -- component.
7862
7863 if Is_Type (Ent) then
7864 Typ := Ent;
7865 else
7866 pragma Assert (Is_Object (Ent)
7867 or else
7868 Nkind (Declaration_Node (Ent)) = N_Component_Declaration);
7869
7870 Typ := Etype (Ent);
7871 end if;
7872
7873 if not Is_Volatile (Ent) and then not Is_Volatile (Typ) then
7874 Error_Pragma
7875 ("cannot have Full_Access_Only without Volatile/Atomic "
7876 & "(RM C.6(8.2))");
7877 end if;
7878
7879 -- Check all the subcomponents of the type recursively, if any
7880
7881 Check_Subcomponents (Typ);
7882
7883 exception
7884 when Full_Access_Subcomponent =>
7885 Error_Pragma
7886 ("cannot have Full_Access_Only with full access subcomponent "
7887 & "(RM C.6(8.2))");
7888
7889 when Generic_Type_Subcomponent =>
7890 Error_Pragma
7891 ("cannot have Full_Access_Only with subcomponent of generic "
7892 & "type (RM C.6(8.2))");
7893
7894 end Check_Full_Access_Only;
7895
7896 ------------------------------
7897 -- Mark_Component_Or_Object --
7898 ------------------------------
7899
7900 procedure Mark_Component_Or_Object (Ent : Entity_Id) is
7901 begin
7902 if Prag_Id = Pragma_Atomic
7903 or else Prag_Id = Pragma_Shared
7904 or else Prag_Id = Pragma_Volatile_Full_Access
7905 then
7906 if Prag_Id = Pragma_Volatile_Full_Access then
7907 Set_Is_Volatile_Full_Access (Ent);
7908 else
7909 Set_Is_Atomic (Ent);
7910 end if;
7911
7912 -- If the object declaration has an explicit initialization, a
7913 -- temporary may have to be created to hold the expression, to
7914 -- ensure that access to the object remains atomic.
7915
7916 if Nkind (Parent (Ent)) = N_Object_Declaration
7917 and then Present (Expression (Parent (Ent)))
7918 then
7919 Set_Has_Delayed_Freeze (Ent);
7920 end if;
7921 end if;
7922
7923 -- Atomic/Shared/Volatile_Full_Access imply Independent
7924
7925 if Prag_Id /= Pragma_Volatile then
7926 Set_Is_Independent (Ent);
7927
7928 if Prag_Id = Pragma_Independent then
7929 Record_Independence_Check (N, Ent);
7930 end if;
7931 end if;
7932
7933 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7934
7935 if Prag_Id /= Pragma_Independent then
7936 Set_Is_Volatile (Ent);
7937 Set_Treat_As_Volatile (Ent);
7938 end if;
7939 end Mark_Component_Or_Object;
7940
7941 ---------------
7942 -- Mark_Type --
7943 ---------------
7944
7945 procedure Mark_Type (Ent : Entity_Id) is
7946 begin
7947 -- Attribute belongs on the base type. If the view of the type is
7948 -- currently private, it also belongs on the underlying type.
7949
7950 -- In Ada 2022, the pragma can apply to a formal type, for which
7951 -- there may be no underlying type.
7952
7953 if Prag_Id = Pragma_Atomic
7954 or else Prag_Id = Pragma_Shared
7955 or else Prag_Id = Pragma_Volatile_Full_Access
7956 then
7957 Set_Atomic_VFA (Ent);
7958 Set_Atomic_VFA (Base_Type (Ent));
7959
7960 if not Is_Generic_Type (Ent) then
7961 Set_Atomic_VFA (Underlying_Type (Ent));
7962 end if;
7963 end if;
7964
7965 -- Atomic/Shared/Volatile_Full_Access imply Independent
7966
7967 if Prag_Id /= Pragma_Volatile then
7968 Set_Is_Independent (Ent);
7969 Set_Is_Independent (Base_Type (Ent));
7970
7971 if not Is_Generic_Type (Ent) then
7972 Set_Is_Independent (Underlying_Type (Ent));
7973
7974 if Prag_Id = Pragma_Independent then
7975 Record_Independence_Check (N, Base_Type (Ent));
7976 end if;
7977 end if;
7978 end if;
7979
7980 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7981
7982 if Prag_Id /= Pragma_Independent then
7983 Set_Is_Volatile (Ent);
7984 Set_Is_Volatile (Base_Type (Ent));
7985
7986 if not Is_Generic_Type (Ent) then
7987 Set_Is_Volatile (Underlying_Type (Ent));
7988 Set_Treat_As_Volatile (Underlying_Type (Ent));
7989 end if;
7990
7991 Set_Treat_As_Volatile (Ent);
7992 end if;
7993
7994 -- Apply Volatile to the composite type's individual components,
7995 -- (RM C.6(8/3)).
7996
7997 if Prag_Id = Pragma_Volatile
7998 and then Is_Record_Type (Etype (Ent))
7999 then
8000 declare
8001 Comp : Entity_Id;
8002 begin
8003 Comp := First_Component (Ent);
8004 while Present (Comp) loop
8005 Mark_Component_Or_Object (Comp);
8006
8007 Next_Component (Comp);
8008 end loop;
8009 end;
8010 end if;
8011 end Mark_Type;
8012
8013 --------------------
8014 -- Set_Atomic_VFA --
8015 --------------------
8016
8017 procedure Set_Atomic_VFA (Ent : Entity_Id) is
8018 begin
8019 if Prag_Id = Pragma_Volatile_Full_Access then
8020 Set_Is_Volatile_Full_Access (Ent);
8021 else
8022 Set_Is_Atomic (Ent);
8023 end if;
8024
8025 if not Has_Alignment_Clause (Ent) then
8026 Reinit_Alignment (Ent);
8027 end if;
8028 end Set_Atomic_VFA;
8029
8030 -- Local variables
8031
8032 Decl : Node_Id;
8033 E : Entity_Id;
8034 E_Arg : Node_Id;
8035
8036 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
8037
8038 begin
8039 Check_Ada_83_Warning;
8040 Check_No_Identifiers;
8041 Check_Arg_Count (1);
8042 Check_Arg_Is_Local_Name (Arg1);
8043 E_Arg := Get_Pragma_Arg (Arg1);
8044
8045 if Etype (E_Arg) = Any_Type then
8046 return;
8047 end if;
8048
8049 E := Entity (E_Arg);
8050 Decl := Declaration_Node (E);
8051
8052 -- A pragma that applies to a Ghost entity becomes Ghost for the
8053 -- purposes of legality checks and removal of ignored Ghost code.
8054
8055 Mark_Ghost_Pragma (N, E);
8056
8057 -- Check duplicate before we chain ourselves
8058
8059 Check_Duplicate_Pragma (E);
8060
8061 -- Check the constraints of Full_Access_Only in Ada 2022. Note that
8062 -- they do not apply to GNAT's Volatile_Full_Access because 1) this
8063 -- aspect subsumes the Volatile aspect and 2) nesting is supported
8064 -- for this aspect and the outermost enclosing VFA object prevails.
8065
8066 -- Note also that we used to forbid specifying both Atomic and VFA on
8067 -- the same type or object, but the restriction has been lifted in
8068 -- light of the semantics of Full_Access_Only and Atomic in Ada 2022.
8069
8070 if Prag_Id = Pragma_Volatile_Full_Access
8071 and then From_Aspect_Specification (N)
8072 and then
8073 Get_Aspect_Id (Corresponding_Aspect (N)) = Aspect_Full_Access_Only
8074 then
8075 Check_Full_Access_Only (E);
8076 end if;
8077
8078 -- Deal with the case where the pragma/attribute is applied to a type
8079
8080 if Is_Type (E) then
8081 if Rep_Item_Too_Early (E, N)
8082 or else Rep_Item_Too_Late (E, N)
8083 then
8084 return;
8085 else
8086 Check_First_Subtype (Arg1);
8087 end if;
8088
8089 Mark_Type (E);
8090
8091 -- Deal with the case where the pragma/attribute applies to a
8092 -- component or object declaration.
8093
8094 elsif Nkind (Decl) = N_Object_Declaration
8095 or else (Nkind (Decl) = N_Component_Declaration
8096 and then Original_Record_Component (E) = E)
8097 then
8098 if Rep_Item_Too_Late (E, N) then
8099 return;
8100 end if;
8101
8102 Mark_Component_Or_Object (E);
8103
8104 -- In other cases give an error
8105
8106 else
8107 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
8108 end if;
8109 end Process_Atomic_Independent_Shared_Volatile;
8110
8111 -------------------------------------------
8112 -- Process_Compile_Time_Warning_Or_Error --
8113 -------------------------------------------
8114
8115 procedure Process_Compile_Time_Warning_Or_Error is
8116 P : Node_Id := Parent (N);
8117 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
8118
8119 begin
8120 Check_Arg_Count (2);
8121 Check_No_Identifiers;
8122 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
8123 Analyze_And_Resolve (Arg1x, Standard_Boolean);
8124
8125 -- In GNATprove mode, pragma Compile_Time_Error is translated as
8126 -- a Check pragma in GNATprove mode, handled as an assumption in
8127 -- GNATprove. This is correct as the compiler will issue an error
8128 -- if the condition cannot be statically evaluated to False.
8129 -- Compile_Time_Warning are ignored, as the analyzer may not have the
8130 -- same information as the compiler (in particular regarding size of
8131 -- objects decided in gigi) so it makes no sense to issue a warning
8132 -- in GNATprove.
8133
8134 if GNATprove_Mode then
8135 if Prag_Id = Pragma_Compile_Time_Error then
8136 declare
8137 New_Args : List_Id;
8138 begin
8139 -- Implement Compile_Time_Error by generating
8140 -- a corresponding Check pragma:
8141
8142 -- pragma Check (name, condition);
8143
8144 -- where name is the identifier matching the pragma name. So
8145 -- rewrite pragma in this manner and analyze the result.
8146
8147 New_Args := New_List
8148 (Make_Pragma_Argument_Association
8149 (Loc,
8150 Expression => Make_Identifier (Loc, Pname)),
8151 Make_Pragma_Argument_Association
8152 (Sloc (Arg1x),
8153 Expression => Arg1x));
8154
8155 -- Rewrite as Check pragma
8156
8157 Rewrite (N,
8158 Make_Pragma (Loc,
8159 Chars => Name_Check,
8160 Pragma_Argument_Associations => New_Args));
8161
8162 Analyze (N);
8163 end;
8164
8165 else
8166 Rewrite (N, Make_Null_Statement (Loc));
8167 end if;
8168
8169 return;
8170 end if;
8171
8172 -- If the condition is known at compile time (now), validate it now.
8173 -- Otherwise, register the expression for validation after the back
8174 -- end has been called, because it might be known at compile time
8175 -- then. For example, if the expression is "Record_Type'Size /= 32"
8176 -- it might be known after the back end has determined the size of
8177 -- Record_Type. We do not defer validation if we're inside a generic
8178 -- unit, because we will have more information in the instances, and
8179 -- this ultimately applies to the main unit itself, because it is not
8180 -- compiled by the back end when it is generic.
8181
8182 if Compile_Time_Known_Value (Arg1x) then
8183 Validate_Compile_Time_Warning_Or_Error (N, Sloc (Arg1));
8184
8185 else
8186 while Present (P) and then Nkind (P) not in N_Generic_Declaration
8187 loop
8188 if (Nkind (P) = N_Subprogram_Body and then not Acts_As_Spec (P))
8189 or else Nkind (P) = N_Package_Body
8190 then
8191 P := Parent (Corresponding_Spec (P));
8192
8193 else
8194 P := Parent (P);
8195 end if;
8196 end loop;
8197
8198 if No (P)
8199 and then
8200 Nkind (Unit (Cunit (Main_Unit))) not in N_Generic_Declaration
8201 then
8202 Defer_Compile_Time_Warning_Error_To_BE (N);
8203 end if;
8204 end if;
8205 end Process_Compile_Time_Warning_Or_Error;
8206
8207 ------------------------
8208 -- Process_Convention --
8209 ------------------------
8210
8211 procedure Process_Convention
8212 (C : out Convention_Id;
8213 Ent : out Entity_Id)
8214 is
8215 Cname : Name_Id;
8216
8217 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
8218 -- Called if we have more than one Export/Import/Convention pragma.
8219 -- This is generally illegal, but we have a special case of allowing
8220 -- Import and Interface to coexist if they specify the convention in
8221 -- a consistent manner. We are allowed to do this, since Interface is
8222 -- an implementation defined pragma, and we choose to do it since we
8223 -- know Rational allows this combination. S is the entity id of the
8224 -- subprogram in question. This procedure also sets the special flag
8225 -- Import_Interface_Present in both pragmas in the case where we do
8226 -- have matching Import and Interface pragmas.
8227
8228 procedure Set_Convention_From_Pragma (E : Entity_Id);
8229 -- Set convention in entity E, and also flag that the entity has a
8230 -- convention pragma. If entity is for a private or incomplete type,
8231 -- also set convention and flag on underlying type. This procedure
8232 -- also deals with the special case of C_Pass_By_Copy convention,
8233 -- and error checks for inappropriate convention specification.
8234
8235 -------------------------------
8236 -- Diagnose_Multiple_Pragmas --
8237 -------------------------------
8238
8239 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
8240 Pdec : constant Node_Id := Declaration_Node (S);
8241 Decl : Node_Id;
8242 Err : Boolean;
8243
8244 function Same_Convention (Decl : Node_Id) return Boolean;
8245 -- Decl is a pragma node. This function returns True if this
8246 -- pragma has a first argument that is an identifier with a
8247 -- Chars field corresponding to the Convention_Id C.
8248
8249 function Same_Name (Decl : Node_Id) return Boolean;
8250 -- Decl is a pragma node. This function returns True if this
8251 -- pragma has a second argument that is an identifier with a
8252 -- Chars field that matches the Chars of the current subprogram.
8253
8254 ---------------------
8255 -- Same_Convention --
8256 ---------------------
8257
8258 function Same_Convention (Decl : Node_Id) return Boolean is
8259 Arg1 : constant Node_Id :=
8260 First (Pragma_Argument_Associations (Decl));
8261
8262 begin
8263 if Present (Arg1) then
8264 declare
8265 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
8266 begin
8267 if Nkind (Arg) = N_Identifier
8268 and then Is_Convention_Name (Chars (Arg))
8269 and then Get_Convention_Id (Chars (Arg)) = C
8270 then
8271 return True;
8272 end if;
8273 end;
8274 end if;
8275
8276 return False;
8277 end Same_Convention;
8278
8279 ---------------
8280 -- Same_Name --
8281 ---------------
8282
8283 function Same_Name (Decl : Node_Id) return Boolean is
8284 Arg1 : constant Node_Id :=
8285 First (Pragma_Argument_Associations (Decl));
8286 Arg2 : Node_Id;
8287
8288 begin
8289 if No (Arg1) then
8290 return False;
8291 end if;
8292
8293 Arg2 := Next (Arg1);
8294
8295 if No (Arg2) then
8296 return False;
8297 end if;
8298
8299 declare
8300 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
8301 begin
8302 if Nkind (Arg) = N_Identifier
8303 and then Chars (Arg) = Chars (S)
8304 then
8305 return True;
8306 end if;
8307 end;
8308
8309 return False;
8310 end Same_Name;
8311
8312 -- Start of processing for Diagnose_Multiple_Pragmas
8313
8314 begin
8315 Err := True;
8316
8317 -- Definitely give message if we have Convention/Export here
8318
8319 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
8320 null;
8321
8322 -- If we have an Import or Export, scan back from pragma to
8323 -- find any previous pragma applying to the same procedure.
8324 -- The scan will be terminated by the start of the list, or
8325 -- hitting the subprogram declaration. This won't allow one
8326 -- pragma to appear in the public part and one in the private
8327 -- part, but that seems very unlikely in practice.
8328
8329 else
8330 Decl := Prev (N);
8331 while Present (Decl) and then Decl /= Pdec loop
8332
8333 -- Look for pragma with same name as us
8334
8335 if Nkind (Decl) = N_Pragma
8336 and then Same_Name (Decl)
8337 then
8338 -- Give error if same as our pragma or Export/Convention
8339
8340 if Pragma_Name_Unmapped (Decl)
8341 in Name_Export
8342 | Name_Convention
8343 | Pragma_Name_Unmapped (N)
8344 then
8345 exit;
8346
8347 -- Case of Import/Interface or the other way round
8348
8349 elsif Pragma_Name_Unmapped (Decl)
8350 in Name_Interface | Name_Import
8351 then
8352 -- Here we know that we have Import and Interface. It
8353 -- doesn't matter which way round they are. See if
8354 -- they specify the same convention. If so, all OK,
8355 -- and set special flags to stop other messages
8356
8357 if Same_Convention (Decl) then
8358 Set_Import_Interface_Present (N);
8359 Set_Import_Interface_Present (Decl);
8360 Err := False;
8361
8362 -- If different conventions, special message
8363
8364 else
8365 Error_Msg_Sloc := Sloc (Decl);
8366 Error_Pragma_Arg
8367 ("convention differs from that given#", Arg1);
8368 end if;
8369 end if;
8370 end if;
8371
8372 Next (Decl);
8373 end loop;
8374 end if;
8375
8376 -- Give message if needed if we fall through those tests
8377 -- except on Relaxed_RM_Semantics where we let go: either this
8378 -- is a case accepted/ignored by other Ada compilers (e.g.
8379 -- a mix of Convention and Import), or another error will be
8380 -- generated later (e.g. using both Import and Export).
8381
8382 if Err and not Relaxed_RM_Semantics then
8383 Error_Pragma_Arg
8384 ("at most one Convention/Export/Import pragma is allowed",
8385 Arg2);
8386 end if;
8387 end Diagnose_Multiple_Pragmas;
8388
8389 --------------------------------
8390 -- Set_Convention_From_Pragma --
8391 --------------------------------
8392
8393 procedure Set_Convention_From_Pragma (E : Entity_Id) is
8394 begin
8395 -- Ada 2005 (AI-430): Check invalid attempt to change convention
8396 -- for an overridden dispatching operation. Technically this is
8397 -- an amendment and should only be done in Ada 2005 mode. However,
8398 -- this is clearly a mistake, since the problem that is addressed
8399 -- by this AI is that there is a clear gap in the RM.
8400
8401 if Is_Dispatching_Operation (E)
8402 and then Present (Overridden_Operation (E))
8403 and then C /= Convention (Overridden_Operation (E))
8404 then
8405 Error_Pragma_Arg
8406 ("cannot change convention for overridden dispatching "
8407 & "operation", Arg1);
8408
8409 -- Special check for convention Stdcall: a dispatching call is not
8410 -- allowed. A dispatching subprogram cannot be used to interface
8411 -- to the Win32 API, so this check actually does not impose any
8412 -- effective restriction.
8413
8414 elsif Is_Dispatching_Operation (E)
8415 and then C = Convention_Stdcall
8416 then
8417 -- Note: make this unconditional so that if there is more
8418 -- than one call to which the pragma applies, we get a
8419 -- message for each call. Also don't use Error_Pragma,
8420 -- so that we get multiple messages.
8421
8422 Error_Msg_Sloc := Sloc (E);
8423 Error_Msg_N
8424 ("dispatching subprogram# cannot use Stdcall convention!",
8425 Get_Pragma_Arg (Arg1));
8426 end if;
8427
8428 -- Set the convention
8429
8430 Set_Convention (E, C);
8431 Set_Has_Convention_Pragma (E);
8432
8433 -- For the case of a record base type, also set the convention of
8434 -- any anonymous access types declared in the record which do not
8435 -- currently have a specified convention.
8436 -- Similarly for an array base type and anonymous access types
8437 -- components.
8438
8439 if Is_Base_Type (E) then
8440 if Is_Record_Type (E) then
8441 declare
8442 Comp : Node_Id;
8443
8444 begin
8445 Comp := First_Component (E);
8446 while Present (Comp) loop
8447 if Present (Etype (Comp))
8448 and then
8449 Ekind (Etype (Comp)) in
8450 E_Anonymous_Access_Type |
8451 E_Anonymous_Access_Subprogram_Type
8452 and then not Has_Convention_Pragma (Comp)
8453 then
8454 Set_Convention (Comp, C);
8455 end if;
8456
8457 Next_Component (Comp);
8458 end loop;
8459 end;
8460
8461 elsif Is_Array_Type (E)
8462 and then Ekind (Component_Type (E)) in
8463 E_Anonymous_Access_Type |
8464 E_Anonymous_Access_Subprogram_Type
8465 then
8466 Set_Convention (Designated_Type (Component_Type (E)), C);
8467 end if;
8468 end if;
8469
8470 -- Deal with incomplete/private type case, where underlying type
8471 -- is available, so set convention of that underlying type.
8472
8473 if Is_Incomplete_Or_Private_Type (E)
8474 and then Present (Underlying_Type (E))
8475 then
8476 Set_Convention (Underlying_Type (E), C);
8477 Set_Has_Convention_Pragma (Underlying_Type (E), True);
8478 end if;
8479
8480 -- A class-wide type should inherit the convention of the specific
8481 -- root type (although this isn't specified clearly by the RM).
8482
8483 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
8484 Set_Convention (Class_Wide_Type (E), C);
8485 end if;
8486
8487 -- If the entity is a record type, then check for special case of
8488 -- C_Pass_By_Copy, which is treated the same as C except that the
8489 -- special record flag is set. This convention is only permitted
8490 -- on record types (see AI95-00131).
8491
8492 if Cname = Name_C_Pass_By_Copy then
8493 if Is_Record_Type (E) then
8494 Set_C_Pass_By_Copy (Base_Type (E));
8495 elsif Is_Incomplete_Or_Private_Type (E)
8496 and then Is_Record_Type (Underlying_Type (E))
8497 then
8498 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
8499 else
8500 Error_Pragma_Arg
8501 ("C_Pass_By_Copy convention allowed only for record type",
8502 Arg2);
8503 end if;
8504 end if;
8505
8506 -- If the entity is a derived boolean type, check for the special
8507 -- case of convention C, C++, or Fortran, where we consider any
8508 -- nonzero value to represent true.
8509
8510 if Is_Discrete_Type (E)
8511 and then Root_Type (Etype (E)) = Standard_Boolean
8512 and then
8513 (C = Convention_C
8514 or else
8515 C = Convention_CPP
8516 or else
8517 C = Convention_Fortran)
8518 then
8519 Set_Nonzero_Is_True (Base_Type (E));
8520 end if;
8521 end Set_Convention_From_Pragma;
8522
8523 -- Local variables
8524
8525 Comp_Unit : Unit_Number_Type;
8526 E : Entity_Id;
8527 E1 : Entity_Id;
8528 Id : Node_Id;
8529 Subp : Entity_Id;
8530
8531 -- Start of processing for Process_Convention
8532
8533 begin
8534 Check_At_Least_N_Arguments (2);
8535 Check_Optional_Identifier (Arg1, Name_Convention);
8536 Check_Arg_Is_Identifier (Arg1);
8537 Cname := Chars (Get_Pragma_Arg (Arg1));
8538
8539 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
8540 -- tested again below to set the critical flag).
8541
8542 if Cname = Name_C_Pass_By_Copy then
8543 C := Convention_C;
8544
8545 -- Otherwise we must have something in the standard convention list
8546
8547 elsif Is_Convention_Name (Cname) then
8548 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
8549
8550 -- Otherwise warn on unrecognized convention
8551
8552 else
8553 if Warn_On_Export_Import then
8554 Error_Msg_N
8555 ("??unrecognized convention name, C assumed",
8556 Get_Pragma_Arg (Arg1));
8557 end if;
8558
8559 C := Convention_C;
8560 end if;
8561
8562 Check_Optional_Identifier (Arg2, Name_Entity);
8563 Check_Arg_Is_Local_Name (Arg2);
8564
8565 Id := Get_Pragma_Arg (Arg2);
8566 Analyze (Id);
8567
8568 if not Is_Entity_Name (Id) then
8569 Error_Pragma_Arg ("entity name required", Arg2);
8570 end if;
8571
8572 E := Entity (Id);
8573
8574 -- Set entity to return
8575
8576 Ent := E;
8577
8578 -- Ada_Pass_By_Copy special checking
8579
8580 if C = Convention_Ada_Pass_By_Copy then
8581 if not Is_First_Subtype (E) then
8582 Error_Pragma_Arg
8583 ("convention `Ada_Pass_By_Copy` only allowed for types",
8584 Arg2);
8585 end if;
8586
8587 if Is_By_Reference_Type (E) then
8588 Error_Pragma_Arg
8589 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
8590 & "type", Arg1);
8591 end if;
8592
8593 -- Ada_Pass_By_Reference special checking
8594
8595 elsif C = Convention_Ada_Pass_By_Reference then
8596 if not Is_First_Subtype (E) then
8597 Error_Pragma_Arg
8598 ("convention `Ada_Pass_By_Reference` only allowed for types",
8599 Arg2);
8600 end if;
8601
8602 if Is_By_Copy_Type (E) then
8603 Error_Pragma_Arg
8604 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
8605 & "type", Arg1);
8606 end if;
8607 end if;
8608
8609 -- Go to renamed subprogram if present, since convention applies to
8610 -- the actual renamed entity, not to the renaming entity. If the
8611 -- subprogram is inherited, go to parent subprogram.
8612
8613 if Is_Subprogram (E)
8614 and then Present (Alias (E))
8615 then
8616 if Nkind (Parent (Declaration_Node (E))) =
8617 N_Subprogram_Renaming_Declaration
8618 then
8619 if Scope (E) /= Scope (Alias (E)) then
8620 Error_Pragma_Ref
8621 ("cannot apply pragma% to non-local entity&#", E);
8622 end if;
8623
8624 E := Alias (E);
8625
8626 elsif Nkind (Parent (E)) in
8627 N_Full_Type_Declaration | N_Private_Extension_Declaration
8628 and then Scope (E) = Scope (Alias (E))
8629 then
8630 E := Alias (E);
8631
8632 -- Return the parent subprogram the entity was inherited from
8633
8634 Ent := E;
8635 end if;
8636 end if;
8637
8638 -- Check that we are not applying this to a specless body. Relax this
8639 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
8640
8641 if Is_Subprogram (E)
8642 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
8643 and then not Relaxed_RM_Semantics
8644 then
8645 Error_Pragma
8646 ("pragma% requires separate spec and must come before body");
8647 end if;
8648
8649 -- Check that we are not applying this to a named constant
8650
8651 if Is_Named_Number (E) then
8652 Error_Msg_Name_1 := Pname;
8653 Error_Msg_N
8654 ("cannot apply pragma% to named constant!",
8655 Get_Pragma_Arg (Arg2));
8656 Error_Pragma_Arg
8657 ("\supply appropriate type for&!", Arg2);
8658 end if;
8659
8660 if Ekind (E) = E_Enumeration_Literal then
8661 Error_Pragma ("enumeration literal not allowed for pragma%");
8662 end if;
8663
8664 -- Check for rep item appearing too early or too late
8665
8666 if Etype (E) = Any_Type
8667 or else Rep_Item_Too_Early (E, N)
8668 then
8669 raise Pragma_Exit;
8670
8671 elsif Present (Underlying_Type (E)) then
8672 E := Underlying_Type (E);
8673 end if;
8674
8675 if Rep_Item_Too_Late (E, N) then
8676 raise Pragma_Exit;
8677 end if;
8678
8679 if Has_Convention_Pragma (E) then
8680 Diagnose_Multiple_Pragmas (E);
8681
8682 elsif Convention (E) = Convention_Protected
8683 or else Ekind (Scope (E)) = E_Protected_Type
8684 then
8685 Error_Pragma_Arg
8686 ("a protected operation cannot be given a different convention",
8687 Arg2);
8688 end if;
8689
8690 -- For Intrinsic, a subprogram is required
8691
8692 if C = Convention_Intrinsic
8693 and then not Is_Subprogram_Or_Generic_Subprogram (E)
8694 then
8695 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
8696
8697 if not (Is_Type (E) and then Relaxed_RM_Semantics) then
8698 if From_Aspect_Specification (N) then
8699 Error_Pragma_Arg
8700 ("entity for aspect% must be a subprogram", Arg2);
8701 else
8702 Error_Pragma_Arg
8703 ("second argument of pragma% must be a subprogram", Arg2);
8704 end if;
8705 end if;
8706
8707 -- Special checks for C_Variadic_n
8708
8709 elsif C in Convention_C_Variadic then
8710
8711 -- Several allowed cases
8712
8713 if Is_Subprogram_Or_Generic_Subprogram (E) then
8714 Subp := E;
8715
8716 -- An access to subprogram is also allowed
8717
8718 elsif Is_Access_Type (E)
8719 and then Ekind (Designated_Type (E)) = E_Subprogram_Type
8720 then
8721 Subp := Designated_Type (E);
8722
8723 -- Allow internal call to set convention of subprogram type
8724
8725 elsif Ekind (E) = E_Subprogram_Type then
8726 Subp := E;
8727
8728 else
8729 Error_Pragma_Arg
8730 ("argument of pragma% must be subprogram or access type",
8731 Arg2);
8732 end if;
8733
8734 -- ISO C requires a named parameter before the ellipsis, so a
8735 -- variadic C function taking 0 fixed parameter cannot exist.
8736
8737 if C = Convention_C_Variadic_0 then
8738
8739 Error_Msg_N
8740 ("??C_Variadic_0 cannot be used for an 'I'S'O C function",
8741 Get_Pragma_Arg (Arg2));
8742
8743 -- Now check the number of parameters of the subprogram and give
8744 -- an error if it is lower than n.
8745
8746 elsif Present (Subp) then
8747 declare
8748 Minimum : constant Nat :=
8749 Convention_Id'Pos (C) -
8750 Convention_Id'Pos (Convention_C_Variadic_0);
8751
8752 Count : Nat;
8753 Formal : Entity_Id;
8754
8755 begin
8756 Count := 0;
8757 Formal := First_Formal (Subp);
8758 while Present (Formal) loop
8759 Count := Count + 1;
8760 Next_Formal (Formal);
8761 end loop;
8762
8763 if Count < Minimum then
8764 Error_Msg_Uint_1 := UI_From_Int (Minimum);
8765 Error_Pragma_Arg
8766 ("argument of pragma% must have at least"
8767 & "^ parameters", Arg2);
8768 end if;
8769 end;
8770 end if;
8771
8772 -- Special checks for Stdcall
8773
8774 elsif C = Convention_Stdcall then
8775
8776 -- Several allowed cases
8777
8778 if Is_Subprogram_Or_Generic_Subprogram (E)
8779
8780 -- A variable is OK
8781
8782 or else Ekind (E) = E_Variable
8783
8784 -- A component as well. The entity does not have its Ekind
8785 -- set until the enclosing record declaration is fully
8786 -- analyzed.
8787
8788 or else Nkind (Parent (E)) = N_Component_Declaration
8789
8790 -- An access to subprogram is also allowed
8791
8792 or else
8793 (Is_Access_Type (E)
8794 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
8795
8796 -- Allow internal call to set convention of subprogram type
8797
8798 or else Ekind (E) = E_Subprogram_Type
8799 then
8800 null;
8801
8802 else
8803 Error_Pragma_Arg
8804 ("argument of pragma% must be subprogram or access type",
8805 Arg2);
8806 end if;
8807 end if;
8808
8809 Set_Convention_From_Pragma (E);
8810
8811 -- Deal with non-subprogram cases
8812
8813 if not Is_Subprogram_Or_Generic_Subprogram (E) then
8814 if Is_Type (E) then
8815
8816 -- The pragma must apply to a first subtype, but it can also
8817 -- apply to a generic type in a generic formal part, in which
8818 -- case it will also appear in the corresponding instance.
8819
8820 if Is_Generic_Type (E) or else In_Instance then
8821 null;
8822 else
8823 Check_First_Subtype (Arg2);
8824 end if;
8825
8826 Set_Convention_From_Pragma (Base_Type (E));
8827
8828 -- For access subprograms, we must set the convention on the
8829 -- internally generated directly designated type as well.
8830
8831 if Ekind (E) = E_Access_Subprogram_Type then
8832 Set_Convention_From_Pragma (Directly_Designated_Type (E));
8833 end if;
8834 end if;
8835
8836 -- For the subprogram case, set proper convention for all homonyms
8837 -- in same scope and the same declarative part, i.e. the same
8838 -- compilation unit.
8839
8840 else
8841 -- Treat a pragma Import as an implicit body, and pragma import
8842 -- as implicit reference (for navigation in GNAT Studio).
8843
8844 if Prag_Id = Pragma_Import then
8845 Generate_Reference (E, Id, 'b');
8846
8847 -- For exported entities we restrict the generation of references
8848 -- to entities exported to foreign languages since entities
8849 -- exported to Ada do not provide further information to
8850 -- GNAT Studio and add undesired references to the output of the
8851 -- gnatxref tool.
8852
8853 elsif Prag_Id = Pragma_Export
8854 and then Convention (E) /= Convention_Ada
8855 then
8856 Generate_Reference (E, Id, 'i');
8857 end if;
8858
8859 -- If the pragma comes from an aspect, it only applies to the
8860 -- given entity, not its homonyms.
8861
8862 if From_Aspect_Specification (N) then
8863 if C = Convention_Intrinsic
8864 and then Nkind (Ent) = N_Defining_Operator_Symbol
8865 then
8866 if Is_Fixed_Point_Type (Etype (Ent))
8867 or else Is_Fixed_Point_Type (Etype (First_Entity (Ent)))
8868 or else Is_Fixed_Point_Type (Etype (Last_Entity (Ent)))
8869 then
8870 Error_Msg_N
8871 ("no intrinsic operator available for this fixed-point "
8872 & "operation", N);
8873 Error_Msg_N
8874 ("\use expression functions with the desired "
8875 & "conversions made explicit", N);
8876 end if;
8877 end if;
8878
8879 return;
8880 end if;
8881
8882 -- Otherwise Loop through the homonyms of the pragma argument's
8883 -- entity, an apply convention to those in the current scope.
8884
8885 Comp_Unit := Get_Source_Unit (E);
8886 E1 := Ent;
8887
8888 loop
8889 E1 := Homonym (E1);
8890 exit when No (E1) or else Scope (E1) /= Current_Scope;
8891
8892 -- Ignore entry for which convention is already set
8893
8894 if Has_Convention_Pragma (E1) then
8895 goto Continue;
8896 end if;
8897
8898 if Is_Subprogram (E1)
8899 and then Nkind (Parent (Declaration_Node (E1))) =
8900 N_Subprogram_Body
8901 and then not Relaxed_RM_Semantics
8902 then
8903 Set_Has_Completion (E); -- to prevent cascaded error
8904 Error_Pragma_Ref
8905 ("pragma% requires separate spec and must come before "
8906 & "body#", E1);
8907 end if;
8908
8909 -- Do not set the pragma on inherited operations or on formal
8910 -- subprograms.
8911
8912 if Comes_From_Source (E1)
8913 and then Comp_Unit = Get_Source_Unit (E1)
8914 and then not Is_Formal_Subprogram (E1)
8915 and then Nkind (Original_Node (Parent (E1))) /=
8916 N_Full_Type_Declaration
8917 then
8918 if Present (Alias (E1))
8919 and then Scope (E1) /= Scope (Alias (E1))
8920 then
8921 Error_Pragma_Ref
8922 ("cannot apply pragma% to non-local entity& declared#",
8923 E1);
8924 end if;
8925
8926 Set_Convention_From_Pragma (E1);
8927
8928 if Prag_Id = Pragma_Import then
8929 Generate_Reference (E1, Id, 'b');
8930 end if;
8931 end if;
8932
8933 <<Continue>>
8934 null;
8935 end loop;
8936 end if;
8937 end Process_Convention;
8938
8939 ----------------------------------------
8940 -- Process_Disable_Enable_Atomic_Sync --
8941 ----------------------------------------
8942
8943 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
8944 begin
8945 Check_No_Identifiers;
8946 Check_At_Most_N_Arguments (1);
8947
8948 -- Modeled internally as
8949 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
8950
8951 Rewrite (N,
8952 Make_Pragma (Loc,
8953 Chars => Nam,
8954 Pragma_Argument_Associations => New_List (
8955 Make_Pragma_Argument_Association (Loc,
8956 Expression =>
8957 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
8958
8959 if Present (Arg1) then
8960 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
8961 end if;
8962
8963 Analyze (N);
8964 end Process_Disable_Enable_Atomic_Sync;
8965
8966 -------------------------------------------------
8967 -- Process_Extended_Import_Export_Internal_Arg --
8968 -------------------------------------------------
8969
8970 procedure Process_Extended_Import_Export_Internal_Arg
8971 (Arg_Internal : Node_Id := Empty)
8972 is
8973 begin
8974 if No (Arg_Internal) then
8975 Error_Pragma ("Internal parameter required for pragma%");
8976 end if;
8977
8978 if Nkind (Arg_Internal) = N_Identifier then
8979 null;
8980
8981 elsif Nkind (Arg_Internal) = N_Operator_Symbol
8982 and then (Prag_Id = Pragma_Import_Function
8983 or else
8984 Prag_Id = Pragma_Export_Function)
8985 then
8986 null;
8987
8988 else
8989 Error_Pragma_Arg
8990 ("wrong form for Internal parameter for pragma%", Arg_Internal);
8991 end if;
8992
8993 Check_Arg_Is_Local_Name (Arg_Internal);
8994 end Process_Extended_Import_Export_Internal_Arg;
8995
8996 --------------------------------------------------
8997 -- Process_Extended_Import_Export_Object_Pragma --
8998 --------------------------------------------------
8999
9000 procedure Process_Extended_Import_Export_Object_Pragma
9001 (Arg_Internal : Node_Id;
9002 Arg_External : Node_Id;
9003 Arg_Size : Node_Id)
9004 is
9005 Def_Id : Entity_Id;
9006
9007 begin
9008 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
9009 Def_Id := Entity (Arg_Internal);
9010
9011 if Ekind (Def_Id) not in E_Constant | E_Variable then
9012 Error_Pragma_Arg
9013 ("pragma% must designate an object", Arg_Internal);
9014 end if;
9015
9016 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
9017 or else
9018 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
9019 then
9020 Error_Pragma_Arg
9021 ("previous Common/Psect_Object applies, pragma % not permitted",
9022 Arg_Internal);
9023 end if;
9024
9025 if Rep_Item_Too_Late (Def_Id, N) then
9026 raise Pragma_Exit;
9027 end if;
9028
9029 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
9030
9031 if Present (Arg_Size) then
9032 Check_Arg_Is_External_Name (Arg_Size);
9033 end if;
9034
9035 -- Export_Object case
9036
9037 if Prag_Id = Pragma_Export_Object then
9038 if not Is_Library_Level_Entity (Def_Id) then
9039 Error_Pragma_Arg
9040 ("argument for pragma% must be library level entity",
9041 Arg_Internal);
9042 end if;
9043
9044 if Ekind (Current_Scope) = E_Generic_Package then
9045 Error_Pragma ("pragma& cannot appear in a generic unit");
9046 end if;
9047
9048 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
9049 Error_Pragma_Arg
9050 ("exported object must have compile time known size",
9051 Arg_Internal);
9052 end if;
9053
9054 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
9055 Error_Msg_N ("??duplicate Export_Object pragma", N);
9056 else
9057 Set_Exported (Def_Id, Arg_Internal);
9058 end if;
9059
9060 -- Import_Object case
9061
9062 else
9063 if Is_Concurrent_Type (Etype (Def_Id)) then
9064 Error_Pragma_Arg
9065 ("cannot use pragma% for task/protected object",
9066 Arg_Internal);
9067 end if;
9068
9069 if Ekind (Def_Id) = E_Constant then
9070 Error_Pragma_Arg
9071 ("cannot import a constant", Arg_Internal);
9072 end if;
9073
9074 if Warn_On_Export_Import
9075 and then Has_Discriminants (Etype (Def_Id))
9076 then
9077 Error_Msg_N
9078 ("imported value must be initialized??", Arg_Internal);
9079 end if;
9080
9081 if Warn_On_Export_Import
9082 and then Is_Access_Type (Etype (Def_Id))
9083 then
9084 Error_Pragma_Arg
9085 ("cannot import object of an access type??", Arg_Internal);
9086 end if;
9087
9088 if Warn_On_Export_Import
9089 and then Is_Imported (Def_Id)
9090 then
9091 Error_Msg_N ("??duplicate Import_Object pragma", N);
9092
9093 -- Check for explicit initialization present. Note that an
9094 -- initialization generated by the code generator, e.g. for an
9095 -- access type, does not count here.
9096
9097 elsif Present (Expression (Parent (Def_Id)))
9098 and then
9099 Comes_From_Source
9100 (Original_Node (Expression (Parent (Def_Id))))
9101 then
9102 Error_Msg_Sloc := Sloc (Def_Id);
9103 Error_Pragma_Arg
9104 ("imported entities cannot be initialized (RM B.1(24))",
9105 "\no initialization allowed for & declared#", Arg1);
9106 else
9107 Set_Imported (Def_Id);
9108 Note_Possible_Modification (Arg_Internal, Sure => False);
9109 end if;
9110 end if;
9111 end Process_Extended_Import_Export_Object_Pragma;
9112
9113 ------------------------------------------------------
9114 -- Process_Extended_Import_Export_Subprogram_Pragma --
9115 ------------------------------------------------------
9116
9117 procedure Process_Extended_Import_Export_Subprogram_Pragma
9118 (Arg_Internal : Node_Id;
9119 Arg_External : Node_Id;
9120 Arg_Parameter_Types : Node_Id;
9121 Arg_Result_Type : Node_Id := Empty;
9122 Arg_Mechanism : Node_Id;
9123 Arg_Result_Mechanism : Node_Id := Empty)
9124 is
9125 Ent : Entity_Id;
9126 Def_Id : Entity_Id;
9127 Hom_Id : Entity_Id;
9128 Formal : Entity_Id;
9129 Ambiguous : Boolean;
9130 Match : Boolean;
9131
9132 function Same_Base_Type
9133 (Ptype : Node_Id;
9134 Formal : Entity_Id) return Boolean;
9135 -- Determines if Ptype references the type of Formal. Note that only
9136 -- the base types need to match according to the spec. Ptype here is
9137 -- the argument from the pragma, which is either a type name, or an
9138 -- access attribute.
9139
9140 --------------------
9141 -- Same_Base_Type --
9142 --------------------
9143
9144 function Same_Base_Type
9145 (Ptype : Node_Id;
9146 Formal : Entity_Id) return Boolean
9147 is
9148 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
9149 Pref : Node_Id;
9150
9151 begin
9152 -- Case where pragma argument is typ'Access
9153
9154 if Nkind (Ptype) = N_Attribute_Reference
9155 and then Attribute_Name (Ptype) = Name_Access
9156 then
9157 Pref := Prefix (Ptype);
9158 Find_Type (Pref);
9159
9160 if not Is_Entity_Name (Pref)
9161 or else Entity (Pref) = Any_Type
9162 then
9163 raise Pragma_Exit;
9164 end if;
9165
9166 -- We have a match if the corresponding argument is of an
9167 -- anonymous access type, and its designated type matches the
9168 -- type of the prefix of the access attribute
9169
9170 return Ekind (Ftyp) = E_Anonymous_Access_Type
9171 and then Base_Type (Entity (Pref)) =
9172 Base_Type (Etype (Designated_Type (Ftyp)));
9173
9174 -- Case where pragma argument is a type name
9175
9176 else
9177 Find_Type (Ptype);
9178
9179 if not Is_Entity_Name (Ptype)
9180 or else Entity (Ptype) = Any_Type
9181 then
9182 raise Pragma_Exit;
9183 end if;
9184
9185 -- We have a match if the corresponding argument is of the type
9186 -- given in the pragma (comparing base types)
9187
9188 return Base_Type (Entity (Ptype)) = Ftyp;
9189 end if;
9190 end Same_Base_Type;
9191
9192 -- Start of processing for
9193 -- Process_Extended_Import_Export_Subprogram_Pragma
9194
9195 begin
9196 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
9197 Ent := Empty;
9198 Ambiguous := False;
9199
9200 -- Loop through homonyms (overloadings) of the entity
9201
9202 Hom_Id := Entity (Arg_Internal);
9203 while Present (Hom_Id) loop
9204 Def_Id := Get_Base_Subprogram (Hom_Id);
9205
9206 -- We need a subprogram in the current scope
9207
9208 if not Is_Subprogram (Def_Id)
9209 or else Scope (Def_Id) /= Current_Scope
9210 then
9211 null;
9212
9213 else
9214 Match := True;
9215
9216 -- Pragma cannot apply to subprogram body
9217
9218 if Is_Subprogram (Def_Id)
9219 and then Nkind (Parent (Declaration_Node (Def_Id))) =
9220 N_Subprogram_Body
9221 then
9222 Error_Pragma
9223 ("pragma% requires separate spec and must come before "
9224 & "body");
9225 end if;
9226
9227 -- Test result type if given, note that the result type
9228 -- parameter can only be present for the function cases.
9229
9230 if Present (Arg_Result_Type)
9231 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
9232 then
9233 Match := False;
9234
9235 elsif Etype (Def_Id) /= Standard_Void_Type
9236 and then
9237 Pname in Name_Export_Procedure | Name_Import_Procedure
9238 then
9239 Match := False;
9240
9241 -- Test parameter types if given. Note that this parameter has
9242 -- not been analyzed (and must not be, since it is semantic
9243 -- nonsense), so we get it as the parser left it.
9244
9245 elsif Present (Arg_Parameter_Types) then
9246 Check_Matching_Types : declare
9247 Formal : Entity_Id;
9248 Ptype : Node_Id;
9249
9250 begin
9251 Formal := First_Formal (Def_Id);
9252
9253 if Nkind (Arg_Parameter_Types) = N_Null then
9254 if Present (Formal) then
9255 Match := False;
9256 end if;
9257
9258 -- A list of one type, e.g. (List) is parsed as a
9259 -- parenthesized expression.
9260
9261 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
9262 and then Paren_Count (Arg_Parameter_Types) = 1
9263 then
9264 if No (Formal)
9265 or else Present (Next_Formal (Formal))
9266 then
9267 Match := False;
9268 else
9269 Match :=
9270 Same_Base_Type (Arg_Parameter_Types, Formal);
9271 end if;
9272
9273 -- A list of more than one type is parsed as a aggregate
9274
9275 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
9276 and then Paren_Count (Arg_Parameter_Types) = 0
9277 then
9278 Ptype := First (Expressions (Arg_Parameter_Types));
9279 while Present (Ptype) or else Present (Formal) loop
9280 if No (Ptype)
9281 or else No (Formal)
9282 or else not Same_Base_Type (Ptype, Formal)
9283 then
9284 Match := False;
9285 exit;
9286 else
9287 Next_Formal (Formal);
9288 Next (Ptype);
9289 end if;
9290 end loop;
9291
9292 -- Anything else is of the wrong form
9293
9294 else
9295 Error_Pragma_Arg
9296 ("wrong form for Parameter_Types parameter",
9297 Arg_Parameter_Types);
9298 end if;
9299 end Check_Matching_Types;
9300 end if;
9301
9302 -- Match is now False if the entry we found did not match
9303 -- either a supplied Parameter_Types or Result_Types argument
9304
9305 if Match then
9306 if No (Ent) then
9307 Ent := Def_Id;
9308
9309 -- Ambiguous case, the flag Ambiguous shows if we already
9310 -- detected this and output the initial messages.
9311
9312 else
9313 if not Ambiguous then
9314 Ambiguous := True;
9315 Error_Msg_Name_1 := Pname;
9316 Error_Msg_N
9317 ("pragma% does not uniquely identify subprogram!",
9318 N);
9319 Error_Msg_Sloc := Sloc (Ent);
9320 Error_Msg_N ("matching subprogram #!", N);
9321 Ent := Empty;
9322 end if;
9323
9324 Error_Msg_Sloc := Sloc (Def_Id);
9325 Error_Msg_N ("matching subprogram #!", N);
9326 end if;
9327 end if;
9328 end if;
9329
9330 Hom_Id := Homonym (Hom_Id);
9331 end loop;
9332
9333 -- See if we found an entry
9334
9335 if No (Ent) then
9336 if not Ambiguous then
9337 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
9338 Error_Pragma
9339 ("pragma% cannot be given for generic subprogram");
9340 else
9341 Error_Pragma
9342 ("pragma% does not identify local subprogram");
9343 end if;
9344 end if;
9345
9346 return;
9347 end if;
9348
9349 -- Import pragmas must be for imported entities
9350
9351 if Prag_Id = Pragma_Import_Function
9352 or else
9353 Prag_Id = Pragma_Import_Procedure
9354 or else
9355 Prag_Id = Pragma_Import_Valued_Procedure
9356 then
9357 if not Is_Imported (Ent) then
9358 Error_Pragma
9359 ("pragma Import or Interface must precede pragma%");
9360 end if;
9361
9362 -- Here we have the Export case which can set the entity as exported
9363
9364 -- But does not do so if the specified external name is null, since
9365 -- that is taken as a signal in DEC Ada 83 (with which we want to be
9366 -- compatible) to request no external name.
9367
9368 elsif Nkind (Arg_External) = N_String_Literal
9369 and then String_Length (Strval (Arg_External)) = 0
9370 then
9371 null;
9372
9373 -- In all other cases, set entity as exported
9374
9375 else
9376 Set_Exported (Ent, Arg_Internal);
9377 end if;
9378
9379 -- Special processing for Valued_Procedure cases
9380
9381 if Prag_Id = Pragma_Import_Valued_Procedure
9382 or else
9383 Prag_Id = Pragma_Export_Valued_Procedure
9384 then
9385 Formal := First_Formal (Ent);
9386
9387 if No (Formal) then
9388 Error_Pragma ("at least one parameter required for pragma%");
9389
9390 elsif Ekind (Formal) /= E_Out_Parameter then
9391 Error_Pragma ("first parameter must have mode OUT for pragma%");
9392
9393 else
9394 Set_Is_Valued_Procedure (Ent);
9395 end if;
9396 end if;
9397
9398 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
9399
9400 -- Process Result_Mechanism argument if present. We have already
9401 -- checked that this is only allowed for the function case.
9402
9403 if Present (Arg_Result_Mechanism) then
9404 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
9405 end if;
9406
9407 -- Process Mechanism parameter if present. Note that this parameter
9408 -- is not analyzed, and must not be analyzed since it is semantic
9409 -- nonsense, so we get it in exactly as the parser left it.
9410
9411 if Present (Arg_Mechanism) then
9412 declare
9413 Formal : Entity_Id;
9414 Massoc : Node_Id;
9415 Mname : Node_Id;
9416 Choice : Node_Id;
9417
9418 begin
9419 -- A single mechanism association without a formal parameter
9420 -- name is parsed as a parenthesized expression. All other
9421 -- cases are parsed as aggregates, so we rewrite the single
9422 -- parameter case as an aggregate for consistency.
9423
9424 if Nkind (Arg_Mechanism) /= N_Aggregate
9425 and then Paren_Count (Arg_Mechanism) = 1
9426 then
9427 Rewrite (Arg_Mechanism,
9428 Make_Aggregate (Sloc (Arg_Mechanism),
9429 Expressions => New_List (
9430 Relocate_Node (Arg_Mechanism))));
9431 end if;
9432
9433 -- Case of only mechanism name given, applies to all formals
9434
9435 if Nkind (Arg_Mechanism) /= N_Aggregate then
9436 Formal := First_Formal (Ent);
9437 while Present (Formal) loop
9438 Set_Mechanism_Value (Formal, Arg_Mechanism);
9439 Next_Formal (Formal);
9440 end loop;
9441
9442 -- Case of list of mechanism associations given
9443
9444 else
9445 if Null_Record_Present (Arg_Mechanism) then
9446 Error_Pragma_Arg
9447 ("inappropriate form for Mechanism parameter",
9448 Arg_Mechanism);
9449 end if;
9450
9451 -- Deal with positional ones first
9452
9453 Formal := First_Formal (Ent);
9454
9455 if Present (Expressions (Arg_Mechanism)) then
9456 Mname := First (Expressions (Arg_Mechanism));
9457 while Present (Mname) loop
9458 if No (Formal) then
9459 Error_Pragma_Arg
9460 ("too many mechanism associations", Mname);
9461 end if;
9462
9463 Set_Mechanism_Value (Formal, Mname);
9464 Next_Formal (Formal);
9465 Next (Mname);
9466 end loop;
9467 end if;
9468
9469 -- Deal with named entries
9470
9471 if Present (Component_Associations (Arg_Mechanism)) then
9472 Massoc := First (Component_Associations (Arg_Mechanism));
9473 while Present (Massoc) loop
9474 Choice := First (Choices (Massoc));
9475
9476 if Nkind (Choice) /= N_Identifier
9477 or else Present (Next (Choice))
9478 then
9479 Error_Pragma_Arg
9480 ("incorrect form for mechanism association",
9481 Massoc);
9482 end if;
9483
9484 Formal := First_Formal (Ent);
9485 loop
9486 if No (Formal) then
9487 Error_Pragma_Arg
9488 ("parameter name & not present", Choice);
9489 end if;
9490
9491 if Chars (Choice) = Chars (Formal) then
9492 Set_Mechanism_Value
9493 (Formal, Expression (Massoc));
9494
9495 -- Set entity on identifier for proper tree
9496 -- structure.
9497
9498 Set_Entity (Choice, Formal);
9499
9500 exit;
9501 end if;
9502
9503 Next_Formal (Formal);
9504 end loop;
9505
9506 Next (Massoc);
9507 end loop;
9508 end if;
9509 end if;
9510 end;
9511 end if;
9512 end Process_Extended_Import_Export_Subprogram_Pragma;
9513
9514 --------------------------
9515 -- Process_Generic_List --
9516 --------------------------
9517
9518 procedure Process_Generic_List is
9519 Arg : Node_Id;
9520 Exp : Node_Id;
9521
9522 begin
9523 Check_No_Identifiers;
9524 Check_At_Least_N_Arguments (1);
9525
9526 -- Check all arguments are names of generic units or instances
9527
9528 Arg := Arg1;
9529 while Present (Arg) loop
9530 Exp := Get_Pragma_Arg (Arg);
9531 Analyze (Exp);
9532
9533 if not Is_Entity_Name (Exp)
9534 or else
9535 (not Is_Generic_Instance (Entity (Exp))
9536 and then
9537 not Is_Generic_Unit (Entity (Exp)))
9538 then
9539 Error_Pragma_Arg
9540 ("pragma% argument must be name of generic unit/instance",
9541 Arg);
9542 end if;
9543
9544 Next (Arg);
9545 end loop;
9546 end Process_Generic_List;
9547
9548 ------------------------------------
9549 -- Process_Import_Predefined_Type --
9550 ------------------------------------
9551
9552 procedure Process_Import_Predefined_Type is
9553 Loc : constant Source_Ptr := Sloc (N);
9554 Elmt : Elmt_Id;
9555 Ftyp : Node_Id := Empty;
9556 Decl : Node_Id;
9557 Def : Node_Id;
9558 Nam : Name_Id;
9559
9560 begin
9561 Nam := String_To_Name (Strval (Expression (Arg3)));
9562
9563 Elmt := First_Elmt (Predefined_Float_Types);
9564 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
9565 Next_Elmt (Elmt);
9566 end loop;
9567
9568 Ftyp := Node (Elmt);
9569
9570 if Present (Ftyp) then
9571
9572 -- Don't build a derived type declaration, because predefined C
9573 -- types have no declaration anywhere, so cannot really be named.
9574 -- Instead build a full type declaration, starting with an
9575 -- appropriate type definition is built
9576
9577 if Is_Floating_Point_Type (Ftyp) then
9578 Def := Make_Floating_Point_Definition (Loc,
9579 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
9580 Make_Real_Range_Specification (Loc,
9581 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
9582 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
9583
9584 -- Should never have a predefined type we cannot handle
9585
9586 else
9587 raise Program_Error;
9588 end if;
9589
9590 -- Build and insert a Full_Type_Declaration, which will be
9591 -- analyzed as soon as this list entry has been analyzed.
9592
9593 Decl := Make_Full_Type_Declaration (Loc,
9594 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
9595 Type_Definition => Def);
9596
9597 Insert_After (N, Decl);
9598 Mark_Rewrite_Insertion (Decl);
9599
9600 else
9601 Error_Pragma_Arg ("no matching type found for pragma%", Arg2);
9602 end if;
9603 end Process_Import_Predefined_Type;
9604
9605 ---------------------------------
9606 -- Process_Import_Or_Interface --
9607 ---------------------------------
9608
9609 procedure Process_Import_Or_Interface is
9610 C : Convention_Id;
9611 Def_Id : Entity_Id;
9612 Hom_Id : Entity_Id;
9613
9614 begin
9615 -- In Relaxed_RM_Semantics, support old Ada 83 style:
9616 -- pragma Import (Entity, "external name");
9617
9618 if Relaxed_RM_Semantics
9619 and then Arg_Count = 2
9620 and then Prag_Id = Pragma_Import
9621 and then Nkind (Expression (Arg2)) = N_String_Literal
9622 then
9623 C := Convention_C;
9624 Def_Id := Get_Pragma_Arg (Arg1);
9625 Analyze (Def_Id);
9626
9627 if not Is_Entity_Name (Def_Id) then
9628 Error_Pragma_Arg ("entity name required", Arg1);
9629 end if;
9630
9631 Def_Id := Entity (Def_Id);
9632 Kill_Size_Check_Code (Def_Id);
9633 if Ekind (Def_Id) /= E_Constant then
9634 Note_Possible_Modification
9635 (Get_Pragma_Arg (Arg1), Sure => False);
9636 end if;
9637
9638 else
9639 Process_Convention (C, Def_Id);
9640
9641 -- A pragma that applies to a Ghost entity becomes Ghost for the
9642 -- purposes of legality checks and removal of ignored Ghost code.
9643
9644 Mark_Ghost_Pragma (N, Def_Id);
9645 Kill_Size_Check_Code (Def_Id);
9646 if Ekind (Def_Id) /= E_Constant then
9647 Note_Possible_Modification
9648 (Get_Pragma_Arg (Arg2), Sure => False);
9649 end if;
9650 end if;
9651
9652 -- Various error checks
9653
9654 if Ekind (Def_Id) in E_Variable | E_Constant then
9655
9656 -- We do not permit Import to apply to a renaming declaration
9657
9658 if Present (Renamed_Object (Def_Id)) then
9659 Error_Pragma_Arg
9660 ("pragma% not allowed for object renaming", Arg2);
9661
9662 -- User initialization is not allowed for imported object, but
9663 -- the object declaration may contain a default initialization,
9664 -- that will be discarded. Note that an explicit initialization
9665 -- only counts if it comes from source, otherwise it is simply
9666 -- the code generator making an implicit initialization explicit.
9667
9668 elsif Present (Expression (Parent (Def_Id)))
9669 and then Comes_From_Source
9670 (Original_Node (Expression (Parent (Def_Id))))
9671 then
9672 -- Set imported flag to prevent cascaded errors
9673
9674 Set_Is_Imported (Def_Id);
9675
9676 Error_Msg_Sloc := Sloc (Def_Id);
9677 Error_Pragma_Arg
9678 ("no initialization allowed for declaration of& #",
9679 "\imported entities cannot be initialized (RM B.1(24))",
9680 Arg2);
9681
9682 else
9683 -- If the pragma comes from an aspect specification the
9684 -- Is_Imported flag has already been set.
9685
9686 if not From_Aspect_Specification (N) then
9687 Set_Imported (Def_Id);
9688 end if;
9689
9690 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9691
9692 -- Note that we do not set Is_Public here. That's because we
9693 -- only want to set it if there is no address clause, and we
9694 -- don't know that yet, so we delay that processing till
9695 -- freeze time.
9696
9697 -- pragma Import completes deferred constants
9698
9699 if Ekind (Def_Id) = E_Constant then
9700 Set_Has_Completion (Def_Id);
9701 end if;
9702
9703 -- It is not possible to import a constant of an unconstrained
9704 -- array type (e.g. string) because there is no simple way to
9705 -- write a meaningful subtype for it.
9706
9707 if Is_Array_Type (Etype (Def_Id))
9708 and then not Is_Constrained (Etype (Def_Id))
9709 then
9710 Error_Msg_NE
9711 ("imported constant& must have a constrained subtype",
9712 N, Def_Id);
9713 end if;
9714 end if;
9715
9716 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9717
9718 -- If the name is overloaded, pragma applies to all of the denoted
9719 -- entities in the same declarative part, unless the pragma comes
9720 -- from an aspect specification or was generated by the compiler
9721 -- (such as for pragma Provide_Shift_Operators).
9722
9723 Hom_Id := Def_Id;
9724 while Present (Hom_Id) loop
9725
9726 Def_Id := Get_Base_Subprogram (Hom_Id);
9727
9728 -- Ignore inherited subprograms because the pragma will apply
9729 -- to the parent operation, which is the one called.
9730
9731 if Is_Overloadable (Def_Id)
9732 and then Present (Alias (Def_Id))
9733 then
9734 null;
9735
9736 -- If it is not a subprogram, it must be in an outer scope and
9737 -- pragma does not apply.
9738
9739 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9740 null;
9741
9742 -- The pragma does not apply to primitives of interfaces
9743
9744 elsif Is_Dispatching_Operation (Def_Id)
9745 and then Present (Find_Dispatching_Type (Def_Id))
9746 and then Is_Interface (Find_Dispatching_Type (Def_Id))
9747 then
9748 null;
9749
9750 -- Verify that the homonym is in the same declarative part (not
9751 -- just the same scope). If the pragma comes from an aspect
9752 -- specification we know that it is part of the declaration.
9753
9754 elsif (No (Unit_Declaration_Node (Def_Id))
9755 or else Parent (Unit_Declaration_Node (Def_Id)) /=
9756 Parent (N))
9757 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9758 and then not From_Aspect_Specification (N)
9759 then
9760 exit;
9761
9762 else
9763 -- If the pragma comes from an aspect specification the
9764 -- Is_Imported flag has already been set.
9765
9766 if not From_Aspect_Specification (N) then
9767 Set_Imported (Def_Id);
9768 end if;
9769
9770 -- Reject an Import applied to an abstract subprogram
9771
9772 if Is_Subprogram (Def_Id)
9773 and then Is_Abstract_Subprogram (Def_Id)
9774 then
9775 Error_Msg_Sloc := Sloc (Def_Id);
9776 Error_Msg_NE
9777 ("cannot import abstract subprogram& declared#",
9778 Arg2, Def_Id);
9779 end if;
9780
9781 -- Special processing for Convention_Intrinsic
9782
9783 if C = Convention_Intrinsic then
9784
9785 -- Link_Name argument not allowed for intrinsic
9786
9787 Check_No_Link_Name;
9788
9789 Set_Is_Intrinsic_Subprogram (Def_Id);
9790
9791 -- If no external name is present, then check that this
9792 -- is a valid intrinsic subprogram. If an external name
9793 -- is present, then this is handled by the back end.
9794
9795 if No (Arg3) then
9796 Check_Intrinsic_Subprogram
9797 (Def_Id, Get_Pragma_Arg (Arg2));
9798 end if;
9799 end if;
9800
9801 -- Verify that the subprogram does not have a completion
9802 -- through a renaming declaration. For other completions the
9803 -- pragma appears as a too late representation.
9804
9805 declare
9806 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
9807
9808 begin
9809 if Present (Decl)
9810 and then Nkind (Decl) = N_Subprogram_Declaration
9811 and then Present (Corresponding_Body (Decl))
9812 and then Nkind (Unit_Declaration_Node
9813 (Corresponding_Body (Decl))) =
9814 N_Subprogram_Renaming_Declaration
9815 then
9816 Error_Msg_Sloc := Sloc (Def_Id);
9817 Error_Msg_NE
9818 ("cannot import&, renaming already provided for "
9819 & "declaration #", N, Def_Id);
9820 end if;
9821 end;
9822
9823 -- If the pragma comes from an aspect specification, there
9824 -- must be an Import aspect specified as well. In the rare
9825 -- case where Import is set to False, the subprogram needs
9826 -- to have a local completion.
9827
9828 declare
9829 Imp_Aspect : constant Node_Id :=
9830 Find_Aspect (Def_Id, Aspect_Import);
9831 Expr : Node_Id;
9832
9833 begin
9834 if Present (Imp_Aspect)
9835 and then Present (Expression (Imp_Aspect))
9836 then
9837 Expr := Expression (Imp_Aspect);
9838 Analyze_And_Resolve (Expr, Standard_Boolean);
9839
9840 if Is_Entity_Name (Expr)
9841 and then Entity (Expr) = Standard_True
9842 then
9843 Set_Has_Completion (Def_Id);
9844 end if;
9845
9846 -- If there is no expression, the default is True, as for
9847 -- all boolean aspects. Same for the older pragma.
9848
9849 else
9850 Set_Has_Completion (Def_Id);
9851 end if;
9852 end;
9853
9854 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9855 end if;
9856
9857 if Is_Compilation_Unit (Hom_Id) then
9858
9859 -- Its possible homonyms are not affected by the pragma.
9860 -- Such homonyms might be present in the context of other
9861 -- units being compiled.
9862
9863 exit;
9864
9865 elsif From_Aspect_Specification (N) then
9866 exit;
9867
9868 -- If the pragma was created by the compiler, then we don't
9869 -- want it to apply to other homonyms. This kind of case can
9870 -- occur when using pragma Provide_Shift_Operators, which
9871 -- generates implicit shift and rotate operators with Import
9872 -- pragmas that might apply to earlier explicit or implicit
9873 -- declarations marked with Import (for example, coming from
9874 -- an earlier pragma Provide_Shift_Operators for another type),
9875 -- and we don't generally want other homonyms being treated
9876 -- as imported or the pragma flagged as an illegal duplicate.
9877
9878 elsif not Comes_From_Source (N) then
9879 exit;
9880
9881 else
9882 Hom_Id := Homonym (Hom_Id);
9883 end if;
9884 end loop;
9885
9886 -- Import a CPP class
9887
9888 elsif C = Convention_CPP
9889 and then (Is_Record_Type (Def_Id)
9890 or else Ekind (Def_Id) = E_Incomplete_Type)
9891 then
9892 if Ekind (Def_Id) = E_Incomplete_Type then
9893 if Present (Full_View (Def_Id)) then
9894 Def_Id := Full_View (Def_Id);
9895
9896 else
9897 Error_Msg_N
9898 ("cannot import 'C'P'P type before full declaration seen",
9899 Get_Pragma_Arg (Arg2));
9900
9901 -- Although we have reported the error we decorate it as
9902 -- CPP_Class to avoid reporting spurious errors
9903
9904 Set_Is_CPP_Class (Def_Id);
9905 return;
9906 end if;
9907 end if;
9908
9909 -- Types treated as CPP classes must be declared limited (note:
9910 -- this used to be a warning but there is no real benefit to it
9911 -- since we did effectively intend to treat the type as limited
9912 -- anyway).
9913
9914 if not Is_Limited_Type (Def_Id) then
9915 Error_Msg_N
9916 ("imported 'C'P'P type must be limited",
9917 Get_Pragma_Arg (Arg2));
9918 end if;
9919
9920 if Etype (Def_Id) /= Def_Id
9921 and then not Is_CPP_Class (Root_Type (Def_Id))
9922 then
9923 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
9924 end if;
9925
9926 Set_Is_CPP_Class (Def_Id);
9927
9928 -- Imported CPP types must not have discriminants (because C++
9929 -- classes do not have discriminants).
9930
9931 if Has_Discriminants (Def_Id) then
9932 Error_Msg_N
9933 ("imported 'C'P'P type cannot have discriminants",
9934 First (Discriminant_Specifications
9935 (Declaration_Node (Def_Id))));
9936 end if;
9937
9938 -- Check that components of imported CPP types do not have default
9939 -- expressions. For private types this check is performed when the
9940 -- full view is analyzed (see Process_Full_View).
9941
9942 if not Is_Private_Type (Def_Id) then
9943 Check_CPP_Type_Has_No_Defaults (Def_Id);
9944 end if;
9945
9946 -- Import a CPP exception
9947
9948 elsif C = Convention_CPP
9949 and then Ekind (Def_Id) = E_Exception
9950 then
9951 if No (Arg3) then
9952 Error_Pragma_Arg
9953 ("'External_'Name arguments is required for 'Cpp exception",
9954 Arg3);
9955 else
9956 -- As only a string is allowed, Check_Arg_Is_External_Name
9957 -- isn't called.
9958
9959 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9960 end if;
9961
9962 if Present (Arg4) then
9963 Error_Pragma_Arg
9964 ("Link_Name argument not allowed for imported Cpp exception",
9965 Arg4);
9966 end if;
9967
9968 -- Do not call Set_Interface_Name as the name of the exception
9969 -- shouldn't be modified (and in particular it shouldn't be
9970 -- the External_Name). For exceptions, the External_Name is the
9971 -- name of the RTTI structure.
9972
9973 -- ??? Emit an error if pragma Import/Export_Exception is present
9974
9975 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
9976 Check_No_Link_Name;
9977 Check_Arg_Count (3);
9978 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9979
9980 Process_Import_Predefined_Type;
9981
9982 -- Emit an error unless Relaxed_RM_Semantics since some legacy Ada
9983 -- compilers may accept more cases, e.g. JGNAT allowed importing
9984 -- a Java package.
9985
9986 elsif not Relaxed_RM_Semantics then
9987 if From_Aspect_Specification (N) then
9988 Error_Pragma_Arg
9989 ("entity for aspect% must be object, subprogram "
9990 & "or incomplete type",
9991 Arg2);
9992 else
9993 Error_Pragma_Arg
9994 ("second argument of pragma% must be object, subprogram "
9995 & "or incomplete type",
9996 Arg2);
9997 end if;
9998 end if;
9999
10000 -- If this pragma applies to a compilation unit, then the unit, which
10001 -- is a subprogram, does not require (or allow) a body. We also do
10002 -- not need to elaborate imported procedures.
10003
10004 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10005 declare
10006 Cunit : constant Node_Id := Parent (Parent (N));
10007 begin
10008 Set_Body_Required (Cunit, False);
10009 end;
10010 end if;
10011 end Process_Import_Or_Interface;
10012
10013 --------------------
10014 -- Process_Inline --
10015 --------------------
10016
10017 procedure Process_Inline (Status : Inline_Status) is
10018 Applies : Boolean;
10019 Assoc : Node_Id;
10020 Decl : Node_Id;
10021 Subp : Entity_Id;
10022 Subp_Id : Node_Id;
10023
10024 Ghost_Error_Posted : Boolean := False;
10025 -- Flag set when an error concerning the illegal mix of Ghost and
10026 -- non-Ghost subprograms is emitted.
10027
10028 Ghost_Id : Entity_Id := Empty;
10029 -- The entity of the first Ghost subprogram encountered while
10030 -- processing the arguments of the pragma.
10031
10032 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id);
10033 -- Verify the placement of pragma Inline_Always with respect to the
10034 -- initial declaration of subprogram Spec_Id.
10035
10036 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
10037 -- Returns True if it can be determined at this stage that inlining
10038 -- is not possible, for example if the body is available and contains
10039 -- exception handlers, we prevent inlining, since otherwise we can
10040 -- get undefined symbols at link time. This function also emits a
10041 -- warning if the pragma appears too late.
10042 --
10043 -- ??? is business with link symbols still valid, or does it relate
10044 -- to front end ZCX which is being phased out ???
10045
10046 procedure Make_Inline (Subp : Entity_Id);
10047 -- Subp is the defining unit name of the subprogram declaration. If
10048 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
10049 -- the corresponding body, if there is one present.
10050
10051 procedure Set_Inline_Flags (Subp : Entity_Id);
10052 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
10053 -- Also set or clear Is_Inlined flag on Subp depending on Status.
10054
10055 -----------------------------------
10056 -- Check_Inline_Always_Placement --
10057 -----------------------------------
10058
10059 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id) is
10060 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id);
10061
10062 function Compilation_Unit_OK return Boolean;
10063 pragma Inline (Compilation_Unit_OK);
10064 -- Determine whether pragma Inline_Always applies to a compatible
10065 -- compilation unit denoted by Spec_Id.
10066
10067 function Declarative_List_OK return Boolean;
10068 pragma Inline (Declarative_List_OK);
10069 -- Determine whether the initial declaration of subprogram Spec_Id
10070 -- and the pragma appear in compatible declarative lists.
10071
10072 function Subprogram_Body_OK return Boolean;
10073 pragma Inline (Subprogram_Body_OK);
10074 -- Determine whether pragma Inline_Always applies to a compatible
10075 -- subprogram body denoted by Spec_Id.
10076
10077 -------------------------
10078 -- Compilation_Unit_OK --
10079 -------------------------
10080
10081 function Compilation_Unit_OK return Boolean is
10082 Comp_Unit : constant Node_Id := Parent (Spec_Decl);
10083
10084 begin
10085 -- The pragma appears after the initial declaration of a
10086 -- compilation unit.
10087
10088 -- procedure Comp_Unit;
10089 -- pragma Inline_Always (Comp_Unit);
10090
10091 -- Note that for compatibility reasons, the following case is
10092 -- also accepted.
10093
10094 -- procedure Stand_Alone_Body_Comp_Unit is
10095 -- ...
10096 -- end Stand_Alone_Body_Comp_Unit;
10097 -- pragma Inline_Always (Stand_Alone_Body_Comp_Unit);
10098
10099 return
10100 Nkind (Comp_Unit) = N_Compilation_Unit
10101 and then Present (Aux_Decls_Node (Comp_Unit))
10102 and then Is_List_Member (N)
10103 and then List_Containing (N) =
10104 Pragmas_After (Aux_Decls_Node (Comp_Unit));
10105 end Compilation_Unit_OK;
10106
10107 -------------------------
10108 -- Declarative_List_OK --
10109 -------------------------
10110
10111 function Declarative_List_OK return Boolean is
10112 Context : constant Node_Id := Parent (Spec_Decl);
10113
10114 Init_Decl : Node_Id;
10115 Init_List : List_Id;
10116 Prag_List : List_Id;
10117
10118 begin
10119 -- Determine the proper initial declaration. In general this is
10120 -- the declaration node of the subprogram except when the input
10121 -- denotes a generic instantiation.
10122
10123 -- procedure Inst is new Gen;
10124 -- pragma Inline_Always (Inst);
10125
10126 -- In this case the original subprogram is moved inside an
10127 -- anonymous package while pragma Inline_Always remains at the
10128 -- level of the anonymous package. Use the declaration of the
10129 -- package because it reflects the placement of the original
10130 -- instantiation.
10131
10132 -- package Anon_Pack is
10133 -- procedure Inst is ... end Inst; -- original
10134 -- end Anon_Pack;
10135
10136 -- procedure Inst renames Anon_Pack.Inst;
10137 -- pragma Inline_Always (Inst);
10138
10139 if Is_Generic_Instance (Spec_Id) then
10140 Init_Decl := Parent (Parent (Spec_Decl));
10141 pragma Assert (Nkind (Init_Decl) = N_Package_Declaration);
10142 else
10143 Init_Decl := Spec_Decl;
10144 end if;
10145
10146 if Is_List_Member (Init_Decl) and then Is_List_Member (N) then
10147 Init_List := List_Containing (Init_Decl);
10148 Prag_List := List_Containing (N);
10149
10150 -- The pragma and then initial declaration appear within the
10151 -- same declarative list.
10152
10153 if Init_List = Prag_List then
10154 return True;
10155
10156 -- A special case of the above is when both the pragma and
10157 -- the initial declaration appear in different lists of a
10158 -- package spec, protected definition, or a task definition.
10159
10160 -- package Pack is
10161 -- procedure Proc;
10162 -- private
10163 -- pragma Inline_Always (Proc);
10164 -- end Pack;
10165
10166 elsif Nkind (Context) in N_Package_Specification
10167 | N_Protected_Definition
10168 | N_Task_Definition
10169 and then Init_List = Visible_Declarations (Context)
10170 and then Prag_List = Private_Declarations (Context)
10171 then
10172 return True;
10173 end if;
10174 end if;
10175
10176 return False;
10177 end Declarative_List_OK;
10178
10179 ------------------------
10180 -- Subprogram_Body_OK --
10181 ------------------------
10182
10183 function Subprogram_Body_OK return Boolean is
10184 Body_Decl : Node_Id;
10185
10186 begin
10187 -- The pragma appears within the declarative list of a stand-
10188 -- alone subprogram body.
10189
10190 -- procedure Stand_Alone_Body is
10191 -- pragma Inline_Always (Stand_Alone_Body);
10192 -- begin
10193 -- ...
10194 -- end Stand_Alone_Body;
10195
10196 -- The compiler creates a dummy spec in this case, however the
10197 -- pragma remains within the declarative list of the body.
10198
10199 if Nkind (Spec_Decl) = N_Subprogram_Declaration
10200 and then not Comes_From_Source (Spec_Decl)
10201 and then Present (Corresponding_Body (Spec_Decl))
10202 then
10203 Body_Decl :=
10204 Unit_Declaration_Node (Corresponding_Body (Spec_Decl));
10205
10206 if Present (Declarations (Body_Decl))
10207 and then Is_List_Member (N)
10208 and then List_Containing (N) = Declarations (Body_Decl)
10209 then
10210 return True;
10211 end if;
10212 end if;
10213
10214 return False;
10215 end Subprogram_Body_OK;
10216
10217 -- Start of processing for Check_Inline_Always_Placement
10218
10219 begin
10220 -- This check is relevant only for pragma Inline_Always
10221
10222 if Pname /= Name_Inline_Always then
10223 return;
10224
10225 -- Nothing to do when the pragma is internally generated on the
10226 -- assumption that it is properly placed.
10227
10228 elsif not Comes_From_Source (N) then
10229 return;
10230
10231 -- Nothing to do for internally generated subprograms that act
10232 -- as accidental homonyms of a source subprogram being inlined.
10233
10234 elsif not Comes_From_Source (Spec_Id) then
10235 return;
10236
10237 -- Nothing to do for generic formal subprograms that act as
10238 -- homonyms of another source subprogram being inlined.
10239
10240 elsif Is_Formal_Subprogram (Spec_Id) then
10241 return;
10242
10243 elsif Compilation_Unit_OK
10244 or else Declarative_List_OK
10245 or else Subprogram_Body_OK
10246 then
10247 return;
10248 end if;
10249
10250 -- At this point it is known that the pragma applies to or appears
10251 -- within a completing body, a completing stub, or a subunit.
10252
10253 Error_Msg_Name_1 := Pname;
10254 Error_Msg_Name_2 := Chars (Spec_Id);
10255 Error_Msg_Sloc := Sloc (Spec_Id);
10256
10257 Error_Msg_N
10258 ("pragma % must appear on initial declaration of subprogram "
10259 & "% defined #", N);
10260 end Check_Inline_Always_Placement;
10261
10262 ---------------------------
10263 -- Inlining_Not_Possible --
10264 ---------------------------
10265
10266 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
10267 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
10268 Stats : Node_Id;
10269
10270 begin
10271 if Nkind (Decl) = N_Subprogram_Body then
10272 Stats := Handled_Statement_Sequence (Decl);
10273 return Present (Exception_Handlers (Stats))
10274 or else Present (At_End_Proc (Stats));
10275
10276 elsif Nkind (Decl) = N_Subprogram_Declaration
10277 and then Present (Corresponding_Body (Decl))
10278 then
10279 if Analyzed (Corresponding_Body (Decl)) then
10280 Error_Msg_N ("pragma appears too late, ignored??", N);
10281 return True;
10282
10283 -- If the subprogram is a renaming as body, the body is just a
10284 -- call to the renamed subprogram, and inlining is trivially
10285 -- possible.
10286
10287 elsif
10288 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
10289 N_Subprogram_Renaming_Declaration
10290 then
10291 return False;
10292
10293 else
10294 Stats :=
10295 Handled_Statement_Sequence
10296 (Unit_Declaration_Node (Corresponding_Body (Decl)));
10297
10298 return
10299 Present (Exception_Handlers (Stats))
10300 or else Present (At_End_Proc (Stats));
10301 end if;
10302
10303 else
10304 -- If body is not available, assume the best, the check is
10305 -- performed again when compiling enclosing package bodies.
10306
10307 return False;
10308 end if;
10309 end Inlining_Not_Possible;
10310
10311 -----------------
10312 -- Make_Inline --
10313 -----------------
10314
10315 procedure Make_Inline (Subp : Entity_Id) is
10316 Kind : constant Entity_Kind := Ekind (Subp);
10317 Inner_Subp : Entity_Id := Subp;
10318
10319 begin
10320 -- Ignore if bad type, avoid cascaded error
10321
10322 if Etype (Subp) = Any_Type then
10323 Applies := True;
10324 return;
10325
10326 -- If inlining is not possible, for now do not treat as an error
10327
10328 elsif Status /= Suppressed
10329 and then Front_End_Inlining
10330 and then Inlining_Not_Possible (Subp)
10331 then
10332 Applies := True;
10333 return;
10334
10335 -- Here we have a candidate for inlining, but we must exclude
10336 -- derived operations. Otherwise we would end up trying to inline
10337 -- a phantom declaration, and the result would be to drag in a
10338 -- body which has no direct inlining associated with it. That
10339 -- would not only be inefficient but would also result in the
10340 -- backend doing cross-unit inlining in cases where it was
10341 -- definitely inappropriate to do so.
10342
10343 -- However, a simple Comes_From_Source test is insufficient, since
10344 -- we do want to allow inlining of generic instances which also do
10345 -- not come from source. We also need to recognize specs generated
10346 -- by the front-end for bodies that carry the pragma. Finally,
10347 -- predefined operators do not come from source but are not
10348 -- inlineable either.
10349
10350 elsif Is_Generic_Instance (Subp)
10351 or else Parent_Kind (Parent (Subp)) = N_Subprogram_Declaration
10352 then
10353 null;
10354
10355 elsif not Comes_From_Source (Subp)
10356 and then Scope (Subp) /= Standard_Standard
10357 then
10358 Applies := True;
10359 return;
10360 end if;
10361
10362 -- The referenced entity must either be the enclosing entity, or
10363 -- an entity declared within the current open scope.
10364
10365 if Present (Scope (Subp))
10366 and then Scope (Subp) /= Current_Scope
10367 and then Subp /= Current_Scope
10368 then
10369 Error_Pragma_Arg
10370 ("argument of% must be entity in current scope", Assoc);
10371 end if;
10372
10373 -- Processing for procedure, operator or function. If subprogram
10374 -- is aliased (as for an instance) indicate that the renamed
10375 -- entity (if declared in the same unit) is inlined.
10376 -- If this is the anonymous subprogram created for a subprogram
10377 -- instance, the inlining applies to it directly. Otherwise we
10378 -- retrieve it as the alias of the visible subprogram instance.
10379
10380 if Is_Subprogram (Subp) then
10381
10382 -- Ensure that pragma Inline_Always is associated with the
10383 -- initial declaration of the subprogram.
10384
10385 Check_Inline_Always_Placement (Subp);
10386
10387 if Is_Wrapper_Package (Scope (Subp)) then
10388 Inner_Subp := Subp;
10389 else
10390 Inner_Subp := Ultimate_Alias (Inner_Subp);
10391 end if;
10392
10393 if In_Same_Source_Unit (Subp, Inner_Subp) then
10394 Set_Inline_Flags (Inner_Subp);
10395
10396 if Present (Parent (Inner_Subp)) then
10397 Decl := Parent (Parent (Inner_Subp));
10398 else
10399 Decl := Empty;
10400 end if;
10401
10402 if Nkind (Decl) = N_Subprogram_Declaration
10403 and then Present (Corresponding_Body (Decl))
10404 then
10405 Set_Inline_Flags (Corresponding_Body (Decl));
10406
10407 elsif Is_Generic_Instance (Subp)
10408 and then Comes_From_Source (Subp)
10409 then
10410 -- Indicate that the body needs to be created for
10411 -- inlining subsequent calls. The instantiation node
10412 -- follows the declaration of the wrapper package
10413 -- created for it. The subprogram that requires the
10414 -- body is the anonymous one in the wrapper package.
10415
10416 if Scope (Subp) /= Standard_Standard
10417 and then
10418 Need_Subprogram_Instance_Body
10419 (Next (Unit_Declaration_Node
10420 (Scope (Alias (Subp)))), Subp)
10421 then
10422 null;
10423 end if;
10424
10425 -- Inline is a program unit pragma (RM 10.1.5) and cannot
10426 -- appear in a formal part to apply to a formal subprogram.
10427 -- Do not apply check within an instance or a formal package
10428 -- the test will have been applied to the original generic.
10429
10430 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
10431 and then In_Same_List (Decl, N)
10432 and then not In_Instance
10433 then
10434 Error_Msg_N
10435 ("Inline cannot apply to a formal subprogram", N);
10436 end if;
10437 end if;
10438
10439 Applies := True;
10440
10441 -- For a generic subprogram set flag as well, for use at the point
10442 -- of instantiation, to determine whether the body should be
10443 -- generated.
10444
10445 elsif Is_Generic_Subprogram (Subp) then
10446 Set_Inline_Flags (Subp);
10447 Applies := True;
10448
10449 -- Literals are by definition inlined
10450
10451 elsif Kind = E_Enumeration_Literal then
10452 null;
10453
10454 -- Anything else is an error
10455
10456 else
10457 Error_Pragma_Arg
10458 ("expect subprogram name for pragma%", Assoc);
10459 end if;
10460 end Make_Inline;
10461
10462 ----------------------
10463 -- Set_Inline_Flags --
10464 ----------------------
10465
10466 procedure Set_Inline_Flags (Subp : Entity_Id) is
10467 begin
10468 -- First set the Has_Pragma_XXX flags and issue the appropriate
10469 -- errors and warnings for suspicious combinations.
10470
10471 if Prag_Id = Pragma_No_Inline then
10472 if Has_Pragma_Inline_Always (Subp) then
10473 Error_Msg_N
10474 ("Inline_Always and No_Inline are mutually exclusive", N);
10475 elsif Has_Pragma_Inline (Subp) then
10476 Error_Msg_NE
10477 ("Inline and No_Inline both specified for& ??",
10478 N, Entity (Subp_Id));
10479 end if;
10480
10481 Set_Has_Pragma_No_Inline (Subp);
10482 else
10483 if Prag_Id = Pragma_Inline_Always then
10484 if Has_Pragma_No_Inline (Subp) then
10485 Error_Msg_N
10486 ("Inline_Always and No_Inline are mutually exclusive",
10487 N);
10488 end if;
10489
10490 Set_Has_Pragma_Inline_Always (Subp);
10491 else
10492 if Has_Pragma_No_Inline (Subp) then
10493 Error_Msg_NE
10494 ("Inline and No_Inline both specified for& ??",
10495 N, Entity (Subp_Id));
10496 end if;
10497 end if;
10498
10499 Set_Has_Pragma_Inline (Subp);
10500 end if;
10501
10502 -- Then adjust the Is_Inlined flag. It can never be set if the
10503 -- subprogram is subject to pragma No_Inline.
10504
10505 case Status is
10506 when Suppressed =>
10507 Set_Is_Inlined (Subp, False);
10508
10509 when Disabled =>
10510 null;
10511
10512 when Enabled =>
10513 if not Has_Pragma_No_Inline (Subp) then
10514 Set_Is_Inlined (Subp, True);
10515 end if;
10516 end case;
10517
10518 -- A pragma that applies to a Ghost entity becomes Ghost for the
10519 -- purposes of legality checks and removal of ignored Ghost code.
10520
10521 Mark_Ghost_Pragma (N, Subp);
10522
10523 -- Capture the entity of the first Ghost subprogram being
10524 -- processed for error detection purposes.
10525
10526 if Is_Ghost_Entity (Subp) then
10527 if No (Ghost_Id) then
10528 Ghost_Id := Subp;
10529 end if;
10530
10531 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
10532 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
10533
10534 elsif Present (Ghost_Id) and then not Ghost_Error_Posted then
10535 Ghost_Error_Posted := True;
10536
10537 Error_Msg_Name_1 := Pname;
10538 Error_Msg_N
10539 ("pragma % cannot mention ghost and non-ghost subprograms",
10540 N);
10541
10542 Error_Msg_Sloc := Sloc (Ghost_Id);
10543 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
10544
10545 Error_Msg_Sloc := Sloc (Subp);
10546 Error_Msg_NE ("\& # declared as non-ghost", N, Subp);
10547 end if;
10548 end Set_Inline_Flags;
10549
10550 -- Start of processing for Process_Inline
10551
10552 begin
10553 -- An inlined subprogram may grant access to its private enclosing
10554 -- context depending on the placement of its body. From elaboration
10555 -- point of view, the flow of execution may enter this private
10556 -- context, and then reach an external unit, thus producing a
10557 -- dependency on that external unit. For such a path to be properly
10558 -- discovered and encoded in the ALI file of the main unit, let the
10559 -- ABE mechanism process the body of the main unit, and encode all
10560 -- relevant invocation constructs and the relations between them.
10561
10562 Mark_Save_Invocation_Graph_Of_Body;
10563
10564 Check_No_Identifiers;
10565 Check_At_Least_N_Arguments (1);
10566
10567 if Status = Enabled then
10568 Inline_Processing_Required := True;
10569 end if;
10570
10571 Assoc := Arg1;
10572 while Present (Assoc) loop
10573 Subp_Id := Get_Pragma_Arg (Assoc);
10574 Analyze (Subp_Id);
10575 Applies := False;
10576
10577 if Is_Entity_Name (Subp_Id) then
10578 Subp := Entity (Subp_Id);
10579
10580 if Subp = Any_Id then
10581
10582 -- If previous error, avoid cascaded errors
10583
10584 Check_Error_Detected;
10585 Applies := True;
10586
10587 else
10588 -- Check for RM 13.1(9.2/4): If a [...] aspect_specification
10589 -- is given that directly specifies an aspect of an entity,
10590 -- then it is illegal to give another [...]
10591 -- aspect_specification that directly specifies the same
10592 -- aspect of the entity.
10593 -- We only check Subp directly as per "directly specifies"
10594 -- above and because the case of pragma Inline is really
10595 -- special given its pre aspect usage.
10596
10597 Check_Duplicate_Pragma (Subp);
10598 Record_Rep_Item (Subp, N);
10599
10600 Make_Inline (Subp);
10601
10602 -- For the pragma case, climb homonym chain. This is
10603 -- what implements allowing the pragma in the renaming
10604 -- case, with the result applying to the ancestors, and
10605 -- also allows Inline to apply to all previous homonyms.
10606
10607 if not From_Aspect_Specification (N) then
10608 while Present (Homonym (Subp))
10609 and then Scope (Homonym (Subp)) = Current_Scope
10610 loop
10611 Subp := Homonym (Subp);
10612 Make_Inline (Subp);
10613 end loop;
10614 end if;
10615 end if;
10616 end if;
10617
10618 if not Applies then
10619 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
10620 end if;
10621
10622 Next (Assoc);
10623 end loop;
10624
10625 -- If the context is a package declaration, the pragma indicates
10626 -- that inlining will require the presence of the corresponding
10627 -- body. (this may be further refined).
10628
10629 if not In_Instance
10630 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
10631 N_Package_Declaration
10632 then
10633 Set_Body_Needed_For_Inlining (Cunit_Entity (Current_Sem_Unit));
10634 end if;
10635 end Process_Inline;
10636
10637 ----------------------------
10638 -- Process_Interface_Name --
10639 ----------------------------
10640
10641 procedure Process_Interface_Name
10642 (Subprogram_Def : Entity_Id;
10643 Ext_Arg : Node_Id;
10644 Link_Arg : Node_Id;
10645 Prag : Node_Id)
10646 is
10647 Ext_Nam : Node_Id;
10648 Link_Nam : Node_Id;
10649 String_Val : String_Id;
10650
10651 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
10652 -- SN is a string literal node for an interface name. This routine
10653 -- performs some minimal checks that the name is reasonable. In
10654 -- particular that no spaces or other obviously incorrect characters
10655 -- appear. This is only a warning, since any characters are allowed.
10656
10657 ----------------------------------
10658 -- Check_Form_Of_Interface_Name --
10659 ----------------------------------
10660
10661 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
10662 S : constant String_Id := Strval (Expr_Value_S (SN));
10663 SL : constant Nat := String_Length (S);
10664 C : Char_Code;
10665
10666 begin
10667 if SL = 0 then
10668 Error_Msg_N ("interface name cannot be null string", SN);
10669 end if;
10670
10671 for J in 1 .. SL loop
10672 C := Get_String_Char (S, J);
10673
10674 -- Look for dubious character and issue unconditional warning.
10675 -- Definitely dubious if not in character range.
10676
10677 if not In_Character_Range (C)
10678
10679 -- Commas, spaces and (back)slashes are dubious
10680
10681 or else Get_Character (C) = ','
10682 or else Get_Character (C) = '\'
10683 or else Get_Character (C) = ' '
10684 or else Get_Character (C) = '/'
10685 then
10686 Error_Msg
10687 ("??interface name contains illegal character",
10688 Sloc (SN) + Source_Ptr (J));
10689 end if;
10690 end loop;
10691 end Check_Form_Of_Interface_Name;
10692
10693 -- Start of processing for Process_Interface_Name
10694
10695 begin
10696 -- If we are looking at a pragma that comes from an aspect then it
10697 -- needs to have its corresponding aspect argument expressions
10698 -- analyzed in addition to the generated pragma so that aspects
10699 -- within generic units get properly resolved.
10700
10701 if Present (Prag) and then From_Aspect_Specification (Prag) then
10702 declare
10703 Asp : constant Node_Id := Corresponding_Aspect (Prag);
10704 Dummy_1 : Node_Id;
10705 Dummy_2 : Node_Id;
10706 Dummy_3 : Node_Id;
10707 EN : Node_Id;
10708 LN : Node_Id;
10709
10710 begin
10711 -- Obtain all interfacing aspects used to construct the pragma
10712
10713 Get_Interfacing_Aspects
10714 (Asp, Dummy_1, EN, Dummy_2, Dummy_3, LN);
10715
10716 -- Analyze the expression of aspect External_Name
10717
10718 if Present (EN) then
10719 Analyze (Expression (EN));
10720 end if;
10721
10722 -- Analyze the expressio of aspect Link_Name
10723
10724 if Present (LN) then
10725 Analyze (Expression (LN));
10726 end if;
10727 end;
10728 end if;
10729
10730 if No (Link_Arg) then
10731 if No (Ext_Arg) then
10732 return;
10733
10734 elsif Chars (Ext_Arg) = Name_Link_Name then
10735 Ext_Nam := Empty;
10736 Link_Nam := Expression (Ext_Arg);
10737
10738 else
10739 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10740 Ext_Nam := Expression (Ext_Arg);
10741 Link_Nam := Empty;
10742 end if;
10743
10744 else
10745 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10746 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
10747 Ext_Nam := Expression (Ext_Arg);
10748 Link_Nam := Expression (Link_Arg);
10749 end if;
10750
10751 -- Check expressions for external name and link name are static
10752
10753 if Present (Ext_Nam) then
10754 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
10755 Check_Form_Of_Interface_Name (Ext_Nam);
10756
10757 -- Verify that external name is not the name of a local entity,
10758 -- which would hide the imported one and could lead to run-time
10759 -- surprises. The problem can only arise for entities declared in
10760 -- a package body (otherwise the external name is fully qualified
10761 -- and will not conflict).
10762
10763 declare
10764 Nam : Name_Id;
10765 E : Entity_Id;
10766 Par : Node_Id;
10767
10768 begin
10769 if Prag_Id = Pragma_Import then
10770 Nam := String_To_Name (Strval (Expr_Value_S (Ext_Nam)));
10771 E := Entity_Id (Get_Name_Table_Int (Nam));
10772
10773 if Nam /= Chars (Subprogram_Def)
10774 and then Present (E)
10775 and then not Is_Overloadable (E)
10776 and then Is_Immediately_Visible (E)
10777 and then not Is_Imported (E)
10778 and then Ekind (Scope (E)) = E_Package
10779 then
10780 Par := Parent (E);
10781 while Present (Par) loop
10782 if Nkind (Par) = N_Package_Body then
10783 Error_Msg_Sloc := Sloc (E);
10784 Error_Msg_NE
10785 ("imported entity is hidden by & declared#",
10786 Ext_Arg, E);
10787 exit;
10788 end if;
10789
10790 Par := Parent (Par);
10791 end loop;
10792 end if;
10793 end if;
10794 end;
10795 end if;
10796
10797 if Present (Link_Nam) then
10798 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
10799 Check_Form_Of_Interface_Name (Link_Nam);
10800 end if;
10801
10802 -- If there is no link name, just set the external name
10803
10804 if No (Link_Nam) then
10805 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
10806
10807 -- For the Link_Name case, the given literal is preceded by an
10808 -- asterisk, which indicates to GCC that the given name should be
10809 -- taken literally, and in particular that no prepending of
10810 -- underlines should occur, even in systems where this is the
10811 -- normal default.
10812
10813 else
10814 Start_String;
10815 Store_String_Char (Get_Char_Code ('*'));
10816 String_Val := Strval (Expr_Value_S (Link_Nam));
10817 Store_String_Chars (String_Val);
10818 Link_Nam :=
10819 Make_String_Literal (Sloc (Link_Nam),
10820 Strval => End_String);
10821 end if;
10822
10823 -- Set the interface name. If the entity is a generic instance, use
10824 -- its alias, which is the callable entity.
10825
10826 if Is_Generic_Instance (Subprogram_Def) then
10827 Set_Encoded_Interface_Name
10828 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
10829 else
10830 Set_Encoded_Interface_Name
10831 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
10832 end if;
10833
10834 Check_Duplicated_Export_Name (Link_Nam);
10835 end Process_Interface_Name;
10836
10837 -----------------------------------------
10838 -- Process_Interrupt_Or_Attach_Handler --
10839 -----------------------------------------
10840
10841 procedure Process_Interrupt_Or_Attach_Handler is
10842 Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
10843 Prot_Typ : constant Entity_Id := Scope (Handler);
10844
10845 begin
10846 -- A pragma that applies to a Ghost entity becomes Ghost for the
10847 -- purposes of legality checks and removal of ignored Ghost code.
10848
10849 Mark_Ghost_Pragma (N, Handler);
10850 Set_Is_Interrupt_Handler (Handler);
10851
10852 pragma Assert (Ekind (Prot_Typ) = E_Protected_Type);
10853
10854 Record_Rep_Item (Prot_Typ, N);
10855
10856 -- Chain the pragma on the contract for completeness
10857
10858 Add_Contract_Item (N, Handler);
10859 end Process_Interrupt_Or_Attach_Handler;
10860
10861 --------------------------------------------------
10862 -- Process_Restrictions_Or_Restriction_Warnings --
10863 --------------------------------------------------
10864
10865 -- Note: some of the simple identifier cases were handled in par-prag,
10866 -- but it is harmless (and more straightforward) to simply handle all
10867 -- cases here, even if it means we repeat a bit of work in some cases.
10868
10869 procedure Process_Restrictions_Or_Restriction_Warnings
10870 (Warn : Boolean)
10871 is
10872 Arg : Node_Id;
10873 R_Id : Restriction_Id;
10874 Id : Name_Id;
10875 Expr : Node_Id;
10876 Val : Uint;
10877
10878 procedure Process_No_Specification_of_Aspect;
10879 -- Process the No_Specification_of_Aspect restriction
10880
10881 procedure Process_No_Use_Of_Attribute;
10882 -- Process the No_Use_Of_Attribute restriction
10883
10884 ----------------------------------------
10885 -- Process_No_Specification_of_Aspect --
10886 ----------------------------------------
10887
10888 procedure Process_No_Specification_of_Aspect is
10889 Name : constant Name_Id := Chars (Expr);
10890 begin
10891 if Nkind (Expr) = N_Identifier
10892 and then Is_Aspect_Id (Name)
10893 then
10894 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
10895 else
10896 Bad_Aspect (Expr, Name, Warn => True);
10897
10898 raise Pragma_Exit;
10899 end if;
10900 end Process_No_Specification_of_Aspect;
10901
10902 ---------------------------------
10903 -- Process_No_Use_Of_Attribute --
10904 ---------------------------------
10905
10906 procedure Process_No_Use_Of_Attribute is
10907 Name : constant Name_Id := Chars (Expr);
10908 begin
10909 if Nkind (Expr) = N_Identifier
10910 and then Is_Attribute_Name (Name)
10911 then
10912 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
10913 else
10914 Bad_Attribute (Expr, Name, Warn => True);
10915 end if;
10916
10917 end Process_No_Use_Of_Attribute;
10918
10919 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
10920
10921 begin
10922 -- Ignore all Restrictions pragmas in CodePeer mode
10923
10924 if CodePeer_Mode then
10925 return;
10926 end if;
10927
10928 Check_Ada_83_Warning;
10929 Check_At_Least_N_Arguments (1);
10930 Check_Valid_Configuration_Pragma;
10931
10932 Arg := Arg1;
10933 while Present (Arg) loop
10934 Id := Chars (Arg);
10935 Expr := Get_Pragma_Arg (Arg);
10936
10937 -- Case of no restriction identifier present
10938
10939 if Id = No_Name then
10940 if Nkind (Expr) /= N_Identifier then
10941 Error_Pragma_Arg
10942 ("invalid form for restriction", Arg);
10943 end if;
10944
10945 R_Id :=
10946 Get_Restriction_Id
10947 (Process_Restriction_Synonyms (Expr));
10948
10949 if R_Id not in All_Boolean_Restrictions then
10950 Error_Msg_Name_1 := Pname;
10951 Error_Msg_N
10952 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
10953
10954 -- Check for possible misspelling
10955
10956 for J in All_Restrictions loop
10957 declare
10958 Rnm : constant String := Restriction_Id'Image (J);
10959
10960 begin
10961 Name_Buffer (1 .. Rnm'Length) := Rnm;
10962 Name_Len := Rnm'Length;
10963 Set_Casing (All_Lower_Case);
10964
10965 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
10966 Set_Casing
10967 (Identifier_Casing
10968 (Source_Index (Current_Sem_Unit)));
10969 Error_Msg_String (1 .. Rnm'Length) :=
10970 Name_Buffer (1 .. Name_Len);
10971 Error_Msg_Strlen := Rnm'Length;
10972 Error_Msg_N -- CODEFIX
10973 ("\possible misspelling of ""~""",
10974 Get_Pragma_Arg (Arg));
10975 exit;
10976 end if;
10977 end;
10978 end loop;
10979
10980 raise Pragma_Exit;
10981 end if;
10982
10983 if Implementation_Restriction (R_Id) then
10984 Check_Restriction (No_Implementation_Restrictions, Arg);
10985 end if;
10986
10987 -- Special processing for No_Elaboration_Code restriction
10988
10989 if R_Id = No_Elaboration_Code then
10990
10991 -- Restriction is only recognized within a configuration
10992 -- pragma file, or within a unit of the main extended
10993 -- program. Note: the test for Main_Unit is needed to
10994 -- properly include the case of configuration pragma files.
10995
10996 if not (Current_Sem_Unit = Main_Unit
10997 or else In_Extended_Main_Source_Unit (N))
10998 then
10999 return;
11000
11001 -- Don't allow in a subunit unless already specified in
11002 -- body or spec.
11003
11004 elsif Nkind (Parent (N)) = N_Compilation_Unit
11005 and then Nkind (Unit (Parent (N))) = N_Subunit
11006 and then not Restriction_Active (No_Elaboration_Code)
11007 then
11008 Error_Msg_N
11009 ("invalid specification of ""No_Elaboration_Code""",
11010 N);
11011 Error_Msg_N
11012 ("\restriction cannot be specified in a subunit", N);
11013 Error_Msg_N
11014 ("\unless also specified in body or spec", N);
11015 return;
11016
11017 -- If we accept a No_Elaboration_Code restriction, then it
11018 -- needs to be added to the configuration restriction set so
11019 -- that we get proper application to other units in the main
11020 -- extended source as required.
11021
11022 else
11023 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
11024 end if;
11025
11026 -- Special processing for No_Dynamic_Accessibility_Checks to
11027 -- disallow exclusive specification in a body or subunit.
11028
11029 elsif R_Id = No_Dynamic_Accessibility_Checks
11030 -- Check if the restriction is within configuration pragma
11031 -- in a similar way to No_Elaboration_Code.
11032
11033 and then not (Current_Sem_Unit = Main_Unit
11034 or else In_Extended_Main_Source_Unit (N))
11035
11036 and then Nkind (Unit (Parent (N))) = N_Compilation_Unit
11037
11038 and then (Nkind (Unit (Parent (N))) = N_Package_Body
11039 or else Nkind (Unit (Parent (N))) = N_Subunit)
11040
11041 and then not Restriction_Active
11042 (No_Dynamic_Accessibility_Checks)
11043 then
11044 Error_Msg_N
11045 ("invalid specification of " &
11046 """No_Dynamic_Accessibility_Checks""", N);
11047
11048 if Nkind (Unit (Parent (N))) = N_Package_Body then
11049 Error_Msg_N
11050 ("\restriction cannot be specified in a package " &
11051 "body", N);
11052
11053 elsif Nkind (Unit (Parent (N))) = N_Subunit then
11054 Error_Msg_N
11055 ("\restriction cannot be specified in a subunit", N);
11056 end if;
11057
11058 Error_Msg_N
11059 ("\unless also specified in spec", N);
11060
11061 -- Special processing for No_Tasking restriction (not just a
11062 -- warning) when it appears as a configuration pragma.
11063
11064 elsif R_Id = No_Tasking
11065 and then No (Cunit (Main_Unit))
11066 and then not Warn
11067 then
11068 Set_Global_No_Tasking;
11069 end if;
11070
11071 Set_Restriction (R_Id, N, Warn);
11072
11073 if R_Id = No_Dynamic_CPU_Assignment
11074 or else R_Id = No_Tasks_Unassigned_To_CPU
11075 then
11076 -- These imply No_Dependence =>
11077 -- "System.Multiprocessors.Dispatching_Domains".
11078 -- This is not strictly what the AI says, but it eliminates
11079 -- the need for run-time checks, which are undesirable in
11080 -- this context.
11081
11082 Set_Restriction_No_Dependence
11083 (Sel_Comp
11084 (Sel_Comp ("system", "multiprocessors", Loc),
11085 "dispatching_domains"),
11086 Warn);
11087 end if;
11088
11089 if R_Id = No_Tasks_Unassigned_To_CPU then
11090 -- Likewise, imply No_Dynamic_CPU_Assignment
11091
11092 Set_Restriction (No_Dynamic_CPU_Assignment, N, Warn);
11093 end if;
11094
11095 -- Check for obsolescent restrictions in Ada 2005 mode
11096
11097 if not Warn
11098 and then Ada_Version >= Ada_2005
11099 and then (R_Id = No_Asynchronous_Control
11100 or else
11101 R_Id = No_Unchecked_Deallocation
11102 or else
11103 R_Id = No_Unchecked_Conversion)
11104 then
11105 Check_Restriction (No_Obsolescent_Features, N);
11106 end if;
11107
11108 -- A very special case that must be processed here: pragma
11109 -- Restrictions (No_Exceptions) turns off all run-time
11110 -- checking. This is a bit dubious in terms of the formal
11111 -- language definition, but it is what is intended by RM
11112 -- H.4(12). Restriction_Warnings never affects generated code
11113 -- so this is done only in the real restriction case.
11114
11115 -- Atomic_Synchronization is not a real check, so it is not
11116 -- affected by this processing).
11117
11118 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
11119 -- run-time checks in CodePeer and GNATprove modes: we want to
11120 -- generate checks for analysis purposes, as set respectively
11121 -- by -gnatC and -gnatd.F
11122
11123 if not Warn
11124 and then not (CodePeer_Mode or GNATprove_Mode)
11125 and then R_Id = No_Exceptions
11126 then
11127 for J in Scope_Suppress.Suppress'Range loop
11128 if J /= Atomic_Synchronization then
11129 Scope_Suppress.Suppress (J) := True;
11130 end if;
11131 end loop;
11132 end if;
11133
11134 -- Case of No_Dependence => unit-name. Note that the parser
11135 -- already made the necessary entry in the No_Dependence table.
11136
11137 elsif Id = Name_No_Dependence then
11138 if not OK_No_Dependence_Unit_Name (Expr) then
11139 raise Pragma_Exit;
11140 end if;
11141
11142 -- Case of No_Specification_Of_Aspect => aspect-identifier
11143
11144 elsif Id = Name_No_Specification_Of_Aspect then
11145 Process_No_Specification_of_Aspect;
11146
11147 -- Case of No_Use_Of_Attribute => attribute-identifier
11148
11149 elsif Id = Name_No_Use_Of_Attribute then
11150 Process_No_Use_Of_Attribute;
11151
11152 -- Case of No_Use_Of_Entity => fully-qualified-name
11153
11154 elsif Id = Name_No_Use_Of_Entity then
11155
11156 -- Restriction is only recognized within a configuration
11157 -- pragma file, or within a unit of the main extended
11158 -- program. Note: the test for Main_Unit is needed to
11159 -- properly include the case of configuration pragma files.
11160
11161 if Current_Sem_Unit = Main_Unit
11162 or else In_Extended_Main_Source_Unit (N)
11163 then
11164 if not OK_No_Dependence_Unit_Name (Expr) then
11165 Error_Msg_N ("wrong form for entity name", Expr);
11166 else
11167 Set_Restriction_No_Use_Of_Entity
11168 (Expr, Warn, No_Profile);
11169 end if;
11170 end if;
11171
11172 -- Case of No_Use_Of_Pragma => pragma-identifier
11173
11174 elsif Id = Name_No_Use_Of_Pragma then
11175 if Nkind (Expr) /= N_Identifier
11176 or else not Is_Pragma_Name (Chars (Expr))
11177 then
11178 Error_Msg_N ("unknown pragma name??", Expr);
11179 else
11180 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
11181 end if;
11182
11183 -- All other cases of restriction identifier present
11184
11185 else
11186 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
11187
11188 if R_Id not in All_Parameter_Restrictions then
11189 Error_Pragma_Arg
11190 ("invalid restriction parameter identifier", Arg);
11191 end if;
11192
11193 Analyze_And_Resolve (Expr, Any_Integer);
11194
11195 if not Is_OK_Static_Expression (Expr) then
11196 Flag_Non_Static_Expr
11197 ("value must be static expression!", Expr);
11198 raise Pragma_Exit;
11199
11200 elsif not Is_Integer_Type (Etype (Expr))
11201 or else Expr_Value (Expr) < 0
11202 then
11203 Error_Pragma_Arg
11204 ("value must be non-negative integer", Arg);
11205 end if;
11206
11207 -- Restriction pragma is active
11208
11209 Val := Expr_Value (Expr);
11210
11211 if not UI_Is_In_Int_Range (Val) then
11212 Error_Pragma_Arg
11213 ("pragma ignored, value too large??", Arg);
11214 end if;
11215
11216 Set_Restriction (R_Id, N, Warn, Integer (UI_To_Int (Val)));
11217 end if;
11218
11219 Next (Arg);
11220 end loop;
11221 end Process_Restrictions_Or_Restriction_Warnings;
11222
11223 ---------------------------------
11224 -- Process_Suppress_Unsuppress --
11225 ---------------------------------
11226
11227 -- Note: this procedure makes entries in the check suppress data
11228 -- structures managed by Sem. See spec of package Sem for full
11229 -- details on how we handle recording of check suppression.
11230
11231 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
11232 C : Check_Id;
11233 E : Entity_Id;
11234 E_Id : Node_Id;
11235
11236 In_Package_Spec : constant Boolean :=
11237 Is_Package_Or_Generic_Package (Current_Scope)
11238 and then not In_Package_Body (Current_Scope);
11239
11240 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
11241 -- Used to suppress a single check on the given entity
11242
11243 --------------------------------
11244 -- Suppress_Unsuppress_Echeck --
11245 --------------------------------
11246
11247 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
11248 begin
11249 -- Check for error of trying to set atomic synchronization for
11250 -- a non-atomic variable.
11251
11252 if C = Atomic_Synchronization
11253 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
11254 then
11255 Error_Msg_N
11256 ("pragma & requires atomic type or variable",
11257 Pragma_Identifier (Original_Node (N)));
11258 end if;
11259
11260 Set_Checks_May_Be_Suppressed (E);
11261
11262 if In_Package_Spec then
11263 Push_Global_Suppress_Stack_Entry
11264 (Entity => E,
11265 Check => C,
11266 Suppress => Suppress_Case);
11267 else
11268 Push_Local_Suppress_Stack_Entry
11269 (Entity => E,
11270 Check => C,
11271 Suppress => Suppress_Case);
11272 end if;
11273
11274 -- If this is a first subtype, and the base type is distinct,
11275 -- then also set the suppress flags on the base type.
11276
11277 if Is_First_Subtype (E) and then Etype (E) /= E then
11278 Suppress_Unsuppress_Echeck (Etype (E), C);
11279 end if;
11280 end Suppress_Unsuppress_Echeck;
11281
11282 -- Start of processing for Process_Suppress_Unsuppress
11283
11284 begin
11285 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
11286 -- on user code: we want to generate checks for analysis purposes, as
11287 -- set respectively by -gnatC and -gnatd.F
11288
11289 if Comes_From_Source (N)
11290 and then (CodePeer_Mode or GNATprove_Mode)
11291 then
11292 return;
11293 end if;
11294
11295 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
11296 -- declarative part or a package spec (RM 11.5(5)).
11297
11298 if not Is_Configuration_Pragma then
11299 Check_Is_In_Decl_Part_Or_Package_Spec;
11300 end if;
11301
11302 Check_At_Least_N_Arguments (1);
11303 Check_At_Most_N_Arguments (2);
11304 Check_No_Identifier (Arg1);
11305 Check_Arg_Is_Identifier (Arg1);
11306
11307 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
11308
11309 if C = No_Check_Id then
11310 Error_Pragma_Arg
11311 ("argument of pragma% is not valid check name", Arg1);
11312 end if;
11313
11314 -- Warn that suppress of Elaboration_Check has no effect in SPARK
11315
11316 if C = Elaboration_Check
11317 and then Suppress_Case
11318 and then SPARK_Mode = On
11319 then
11320 Error_Pragma_Arg
11321 ("Suppress of Elaboration_Check ignored in SPARK??",
11322 "\elaboration checking rules are statically enforced "
11323 & "(SPARK RM 7.7)", Arg1);
11324 end if;
11325
11326 -- One-argument case
11327
11328 if Arg_Count = 1 then
11329
11330 -- Make an entry in the local scope suppress table. This is the
11331 -- table that directly shows the current value of the scope
11332 -- suppress check for any check id value.
11333
11334 if C = All_Checks then
11335
11336 -- For All_Checks, we set all specific predefined checks with
11337 -- the exception of Elaboration_Check, which is handled
11338 -- specially because of not wanting All_Checks to have the
11339 -- effect of deactivating static elaboration order processing.
11340 -- Atomic_Synchronization is also not affected, since this is
11341 -- not a real check.
11342
11343 for J in Scope_Suppress.Suppress'Range loop
11344 if J /= Elaboration_Check
11345 and then
11346 J /= Atomic_Synchronization
11347 then
11348 Scope_Suppress.Suppress (J) := Suppress_Case;
11349 end if;
11350 end loop;
11351
11352 -- If not All_Checks, and predefined check, then set appropriate
11353 -- scope entry. Note that we will set Elaboration_Check if this
11354 -- is explicitly specified. Atomic_Synchronization is allowed
11355 -- only if internally generated and entity is atomic.
11356
11357 elsif C in Predefined_Check_Id
11358 and then (not Comes_From_Source (N)
11359 or else C /= Atomic_Synchronization)
11360 then
11361 Scope_Suppress.Suppress (C) := Suppress_Case;
11362 end if;
11363
11364 -- Also push an entry in the local suppress stack
11365
11366 Push_Local_Suppress_Stack_Entry
11367 (Entity => Empty,
11368 Check => C,
11369 Suppress => Suppress_Case);
11370
11371 -- Case of two arguments present, where the check is suppressed for
11372 -- a specified entity (given as the second argument of the pragma)
11373
11374 else
11375 -- This is obsolescent in Ada 2005 mode
11376
11377 if Ada_Version >= Ada_2005 then
11378 Check_Restriction (No_Obsolescent_Features, Arg2);
11379 end if;
11380
11381 Check_Optional_Identifier (Arg2, Name_On);
11382 E_Id := Get_Pragma_Arg (Arg2);
11383 Analyze (E_Id);
11384
11385 if not Is_Entity_Name (E_Id) then
11386 Error_Pragma_Arg
11387 ("second argument of pragma% must be entity name", Arg2);
11388 end if;
11389
11390 E := Entity (E_Id);
11391
11392 if E = Any_Id then
11393 return;
11394 end if;
11395
11396 -- A pragma that applies to a Ghost entity becomes Ghost for the
11397 -- purposes of legality checks and removal of ignored Ghost code.
11398
11399 Mark_Ghost_Pragma (N, E);
11400
11401 -- Enforce RM 11.5(7) which requires that for a pragma that
11402 -- appears within a package spec, the named entity must be
11403 -- within the package spec. We allow the package name itself
11404 -- to be mentioned since that makes sense, although it is not
11405 -- strictly allowed by 11.5(7).
11406
11407 if In_Package_Spec
11408 and then E /= Current_Scope
11409 and then Scope (E) /= Current_Scope
11410 then
11411 Error_Pragma_Arg
11412 ("entity in pragma% is not in package spec (RM 11.5(7))",
11413 Arg2);
11414 end if;
11415
11416 -- Loop through homonyms. As noted below, in the case of a package
11417 -- spec, only homonyms within the package spec are considered.
11418
11419 loop
11420 Suppress_Unsuppress_Echeck (E, C);
11421
11422 if Is_Generic_Instance (E)
11423 and then Is_Subprogram (E)
11424 and then Present (Alias (E))
11425 then
11426 Suppress_Unsuppress_Echeck (Alias (E), C);
11427 end if;
11428
11429 -- Move to next homonym if not aspect spec case
11430
11431 exit when From_Aspect_Specification (N);
11432 E := Homonym (E);
11433 exit when No (E);
11434
11435 -- If we are within a package specification, the pragma only
11436 -- applies to homonyms in the same scope.
11437
11438 exit when In_Package_Spec
11439 and then Scope (E) /= Current_Scope;
11440 end loop;
11441 end if;
11442 end Process_Suppress_Unsuppress;
11443
11444 -------------------------------
11445 -- Record_Independence_Check --
11446 -------------------------------
11447
11448 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
11449 pragma Unreferenced (N, E);
11450 begin
11451 -- For GCC back ends the validation is done a priori. This code is
11452 -- dead, but might be useful in the future.
11453
11454 -- if not AAMP_On_Target then
11455 -- return;
11456 -- end if;
11457
11458 -- Independence_Checks.Append ((N, E));
11459
11460 return;
11461 end Record_Independence_Check;
11462
11463 ------------------
11464 -- Set_Exported --
11465 ------------------
11466
11467 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
11468 begin
11469 if Is_Imported (E) then
11470 Error_Pragma_Arg
11471 ("cannot export entity& that was previously imported", Arg);
11472
11473 elsif Present (Address_Clause (E))
11474 and then not Relaxed_RM_Semantics
11475 then
11476 Error_Pragma_Arg
11477 ("cannot export entity& that has an address clause", Arg);
11478 end if;
11479
11480 Set_Is_Exported (E);
11481
11482 -- Generate a reference for entity explicitly, because the
11483 -- identifier may be overloaded and name resolution will not
11484 -- generate one.
11485
11486 Generate_Reference (E, Arg);
11487
11488 -- Deal with exporting non-library level entity
11489
11490 if not Is_Library_Level_Entity (E) then
11491
11492 -- Not allowed at all for subprograms
11493
11494 if Is_Subprogram (E) then
11495 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
11496
11497 -- Otherwise set public and statically allocated
11498
11499 else
11500 Set_Is_Public (E);
11501 Set_Is_Statically_Allocated (E);
11502
11503 -- Warn if the corresponding W flag is set
11504
11505 if Warn_On_Export_Import
11506
11507 -- Only do this for something that was in the source. Not
11508 -- clear if this can be False now (there used for sure to be
11509 -- cases on some systems where it was False), but anyway the
11510 -- test is harmless if not needed, so it is retained.
11511
11512 and then Comes_From_Source (Arg)
11513 then
11514 Error_Msg_NE
11515 ("?x?& has been made static as a result of Export",
11516 Arg, E);
11517 Error_Msg_N
11518 ("\?x?this usage is non-standard and non-portable",
11519 Arg);
11520 end if;
11521 end if;
11522 end if;
11523
11524 if Warn_On_Export_Import and Inside_A_Generic then
11525 Error_Msg_NE
11526 ("all instances of& will have the same external name?x?",
11527 Arg, E);
11528 end if;
11529 end Set_Exported;
11530
11531 ----------------------------------------------
11532 -- Set_Extended_Import_Export_External_Name --
11533 ----------------------------------------------
11534
11535 procedure Set_Extended_Import_Export_External_Name
11536 (Internal_Ent : Entity_Id;
11537 Arg_External : Node_Id)
11538 is
11539 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
11540 New_Name : Node_Id;
11541
11542 begin
11543 if No (Arg_External) then
11544 return;
11545 end if;
11546
11547 Check_Arg_Is_External_Name (Arg_External);
11548
11549 if Nkind (Arg_External) = N_String_Literal then
11550 if String_Length (Strval (Arg_External)) = 0 then
11551 return;
11552 else
11553 New_Name := Adjust_External_Name_Case (Arg_External);
11554 end if;
11555
11556 elsif Nkind (Arg_External) = N_Identifier then
11557 New_Name := Get_Default_External_Name (Arg_External);
11558
11559 -- Check_Arg_Is_External_Name should let through only identifiers and
11560 -- string literals or static string expressions (which are folded to
11561 -- string literals).
11562
11563 else
11564 raise Program_Error;
11565 end if;
11566
11567 -- If we already have an external name set (by a prior normal Import
11568 -- or Export pragma), then the external names must match
11569
11570 if Present (Interface_Name (Internal_Ent)) then
11571
11572 -- Ignore mismatching names in CodePeer mode, to support some
11573 -- old compilers which would export the same procedure under
11574 -- different names, e.g:
11575 -- procedure P;
11576 -- pragma Export_Procedure (P, "a");
11577 -- pragma Export_Procedure (P, "b");
11578
11579 if CodePeer_Mode then
11580 return;
11581 end if;
11582
11583 Check_Matching_Internal_Names : declare
11584 S1 : constant String_Id := Strval (Old_Name);
11585 S2 : constant String_Id := Strval (New_Name);
11586
11587 procedure Mismatch;
11588 pragma No_Return (Mismatch);
11589 -- Called if names do not match
11590
11591 --------------
11592 -- Mismatch --
11593 --------------
11594
11595 procedure Mismatch is
11596 begin
11597 Error_Msg_Sloc := Sloc (Old_Name);
11598 Error_Pragma_Arg
11599 ("external name does not match that given #",
11600 Arg_External);
11601 end Mismatch;
11602
11603 -- Start of processing for Check_Matching_Internal_Names
11604
11605 begin
11606 if String_Length (S1) /= String_Length (S2) then
11607 Mismatch;
11608
11609 else
11610 for J in 1 .. String_Length (S1) loop
11611 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
11612 Mismatch;
11613 end if;
11614 end loop;
11615 end if;
11616 end Check_Matching_Internal_Names;
11617
11618 -- Otherwise set the given name
11619
11620 else
11621 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
11622 Check_Duplicated_Export_Name (New_Name);
11623 end if;
11624 end Set_Extended_Import_Export_External_Name;
11625
11626 ------------------
11627 -- Set_Imported --
11628 ------------------
11629
11630 procedure Set_Imported (E : Entity_Id) is
11631 begin
11632 -- Error message if already imported or exported
11633
11634 if Is_Exported (E) or else Is_Imported (E) then
11635
11636 -- Error if being set Exported twice
11637
11638 if Is_Exported (E) then
11639 Error_Msg_NE ("entity& was previously exported", N, E);
11640
11641 -- Ignore error in CodePeer mode where we treat all imported
11642 -- subprograms as unknown.
11643
11644 elsif CodePeer_Mode then
11645 goto OK;
11646
11647 -- OK if Import/Interface case
11648
11649 elsif Import_Interface_Present (N) then
11650 goto OK;
11651
11652 -- Error if being set Imported twice
11653
11654 else
11655 Error_Msg_NE ("entity& was previously imported", N, E);
11656 end if;
11657
11658 Error_Msg_Name_1 := Pname;
11659 Error_Msg_N
11660 ("\(pragma% applies to all previous entities)", N);
11661
11662 Error_Msg_Sloc := Sloc (E);
11663 Error_Msg_NE ("\import not allowed for& declared#", N, E);
11664
11665 -- Here if not previously imported or exported, OK to import
11666
11667 else
11668 Set_Is_Imported (E);
11669
11670 -- For subprogram, set Import_Pragma field
11671
11672 if Is_Subprogram (E) then
11673 Set_Import_Pragma (E, N);
11674 end if;
11675
11676 -- If the entity is an object that is not at the library level,
11677 -- then it is statically allocated. We do not worry about objects
11678 -- with address clauses in this context since they are not really
11679 -- imported in the linker sense.
11680
11681 if Is_Object (E)
11682 and then not Is_Library_Level_Entity (E)
11683 and then No (Address_Clause (E))
11684 then
11685 Set_Is_Statically_Allocated (E);
11686 end if;
11687 end if;
11688
11689 <<OK>> null;
11690 end Set_Imported;
11691
11692 -------------------------
11693 -- Set_Mechanism_Value --
11694 -------------------------
11695
11696 -- Note: the mechanism name has not been analyzed (and cannot indeed be
11697 -- analyzed, since it is semantic nonsense), so we get it in the exact
11698 -- form created by the parser.
11699
11700 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
11701 procedure Bad_Mechanism;
11702 pragma No_Return (Bad_Mechanism);
11703 -- Signal bad mechanism name
11704
11705 -------------------
11706 -- Bad_Mechanism --
11707 -------------------
11708
11709 procedure Bad_Mechanism is
11710 begin
11711 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
11712 end Bad_Mechanism;
11713
11714 -- Start of processing for Set_Mechanism_Value
11715
11716 begin
11717 if Mechanism (Ent) /= Default_Mechanism then
11718 Error_Msg_NE
11719 ("mechanism for & has already been set", Mech_Name, Ent);
11720 end if;
11721
11722 -- MECHANISM_NAME ::= value | reference
11723
11724 if Nkind (Mech_Name) = N_Identifier then
11725 if Chars (Mech_Name) = Name_Value then
11726 Set_Mechanism (Ent, By_Copy);
11727 return;
11728
11729 elsif Chars (Mech_Name) = Name_Reference then
11730 Set_Mechanism (Ent, By_Reference);
11731 return;
11732
11733 elsif Chars (Mech_Name) = Name_Copy then
11734 Error_Pragma_Arg
11735 ("bad mechanism name, Value assumed", Mech_Name);
11736
11737 else
11738 Bad_Mechanism;
11739 end if;
11740
11741 else
11742 Bad_Mechanism;
11743 end if;
11744 end Set_Mechanism_Value;
11745
11746 --------------------------
11747 -- Set_Rational_Profile --
11748 --------------------------
11749
11750 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
11751 -- extension to the semantics of renaming declarations.
11752
11753 procedure Set_Rational_Profile is
11754 begin
11755 Implicit_Packing := True;
11756 Overriding_Renamings := True;
11757 Use_VADS_Size := True;
11758 end Set_Rational_Profile;
11759
11760 ---------------------------
11761 -- Set_Ravenscar_Profile --
11762 ---------------------------
11763
11764 -- The tasks to be done here are
11765
11766 -- Set required policies
11767
11768 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11769 -- (For Ravenscar, Jorvik, and GNAT_Extended_Ravenscar profiles)
11770 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11771 -- (For GNAT_Ravenscar_EDF profile)
11772 -- pragma Locking_Policy (Ceiling_Locking)
11773
11774 -- Set Detect_Blocking mode
11775
11776 -- Set required restrictions (see System.Rident for detailed list)
11777
11778 -- Set the No_Dependence rules
11779 -- No_Dependence => Ada.Asynchronous_Task_Control
11780 -- No_Dependence => Ada.Calendar
11781 -- No_Dependence => Ada.Execution_Time.Group_Budget
11782 -- No_Dependence => Ada.Execution_Time.Timers
11783 -- No_Dependence => Ada.Task_Attributes
11784 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11785
11786 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is
11787 procedure Set_Error_Msg_To_Profile_Name;
11788 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
11789 -- profile.
11790
11791 -----------------------------------
11792 -- Set_Error_Msg_To_Profile_Name --
11793 -----------------------------------
11794
11795 procedure Set_Error_Msg_To_Profile_Name is
11796 Prof_Nam : constant Node_Id :=
11797 Get_Pragma_Arg
11798 (First (Pragma_Argument_Associations (N)));
11799
11800 begin
11801 Get_Name_String (Chars (Prof_Nam));
11802 Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam));
11803 Error_Msg_Strlen := Name_Len;
11804 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
11805 end Set_Error_Msg_To_Profile_Name;
11806
11807 Profile_Dispatching_Policy : Character;
11808
11809 -- Start of processing for Set_Ravenscar_Profile
11810
11811 begin
11812 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11813
11814 if Profile = GNAT_Ravenscar_EDF then
11815 Profile_Dispatching_Policy := 'E';
11816
11817 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11818
11819 else
11820 Profile_Dispatching_Policy := 'F';
11821 end if;
11822
11823 if Task_Dispatching_Policy /= ' '
11824 and then Task_Dispatching_Policy /= Profile_Dispatching_Policy
11825 then
11826 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11827 Set_Error_Msg_To_Profile_Name;
11828 Error_Pragma ("Profile (~) incompatible with policy#");
11829
11830 -- Set the FIFO_Within_Priorities policy, but always preserve
11831 -- System_Location since we like the error message with the run time
11832 -- name.
11833
11834 else
11835 Task_Dispatching_Policy := Profile_Dispatching_Policy;
11836
11837 if Task_Dispatching_Policy_Sloc /= System_Location then
11838 Task_Dispatching_Policy_Sloc := Loc;
11839 end if;
11840 end if;
11841
11842 -- pragma Locking_Policy (Ceiling_Locking)
11843
11844 if Locking_Policy /= ' '
11845 and then Locking_Policy /= 'C'
11846 then
11847 Error_Msg_Sloc := Locking_Policy_Sloc;
11848 Set_Error_Msg_To_Profile_Name;
11849 Error_Pragma ("Profile (~) incompatible with policy#");
11850
11851 -- Set the Ceiling_Locking policy, but preserve System_Location since
11852 -- we like the error message with the run time name.
11853
11854 else
11855 Locking_Policy := 'C';
11856
11857 if Locking_Policy_Sloc /= System_Location then
11858 Locking_Policy_Sloc := Loc;
11859 end if;
11860 end if;
11861
11862 -- pragma Detect_Blocking
11863
11864 Detect_Blocking := True;
11865
11866 -- Set the corresponding restrictions
11867
11868 Set_Profile_Restrictions
11869 (Profile, N, Warn => Treat_Restrictions_As_Warnings);
11870
11871 -- Set the No_Dependence restrictions
11872
11873 -- The following No_Dependence restrictions:
11874 -- No_Dependence => Ada.Asynchronous_Task_Control
11875 -- No_Dependence => Ada.Calendar
11876 -- No_Dependence => Ada.Task_Attributes
11877 -- are already set by previous call to Set_Profile_Restrictions.
11878 -- Really???
11879
11880 -- Set the following restrictions which were added to Ada 2005:
11881 -- No_Dependence => Ada.Execution_Time.Group_Budget
11882 -- No_Dependence => Ada.Execution_Time.Timers
11883
11884 if Ada_Version >= Ada_2005 then
11885 declare
11886 Execution_Time : constant Node_Id :=
11887 Sel_Comp ("ada", "execution_time", Loc);
11888 Group_Budgets : constant Node_Id :=
11889 Sel_Comp (Execution_Time, "group_budgets");
11890 Timers : constant Node_Id :=
11891 Sel_Comp (Execution_Time, "timers");
11892 begin
11893 Set_Restriction_No_Dependence
11894 (Unit => Group_Budgets,
11895 Warn => Treat_Restrictions_As_Warnings,
11896 Profile => Ravenscar);
11897 Set_Restriction_No_Dependence
11898 (Unit => Timers,
11899 Warn => Treat_Restrictions_As_Warnings,
11900 Profile => Ravenscar);
11901 end;
11902 end if;
11903
11904 -- Set the following restriction which was added to Ada 2012 (see
11905 -- AI05-0171):
11906 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11907
11908 if Ada_Version >= Ada_2012 then
11909 Set_Restriction_No_Dependence
11910 (Sel_Comp
11911 (Sel_Comp ("system", "multiprocessors", Loc),
11912 "dispatching_domains"),
11913 Warn => Treat_Restrictions_As_Warnings,
11914 Profile => Ravenscar);
11915
11916 -- Set the following restriction which was added to Ada 2022,
11917 -- but as a binding interpretation:
11918 -- No_Dependence => Ada.Synchronous_Barriers
11919 -- for Ravenscar (and therefore for Ravenscar variants) but not
11920 -- for Jorvik. The unit Ada.Synchronous_Barriers was introduced
11921 -- in Ada2012 (AI05-0174).
11922
11923 if Profile /= Jorvik then
11924 Set_Restriction_No_Dependence
11925 (Sel_Comp ("ada", "synchronous_barriers", Loc),
11926 Warn => Treat_Restrictions_As_Warnings,
11927 Profile => Ravenscar);
11928 end if;
11929 end if;
11930
11931 end Set_Ravenscar_Profile;
11932
11933 -- Start of processing for Analyze_Pragma
11934
11935 begin
11936 -- The following code is a defense against recursion. Not clear that
11937 -- this can happen legitimately, but perhaps some error situations can
11938 -- cause it, and we did see this recursion during testing.
11939
11940 if Analyzed (N) then
11941 return;
11942 else
11943 Set_Analyzed (N);
11944 end if;
11945
11946 Check_Restriction_No_Use_Of_Pragma (N);
11947
11948 if Is_Aspect_Id (Chars (Pragma_Identifier (N))) then
11949 -- 6.1/3 No_Specification_of_Aspect: Identifies an aspect for which
11950 -- no aspect_specification, attribute_definition_clause, or pragma
11951 -- is given.
11952 Check_Restriction_No_Specification_Of_Aspect (N);
11953 end if;
11954
11955 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
11956 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
11957
11958 if Should_Ignore_Pragma_Sem (N)
11959 or else (Prag_Id = Pragma_Default_Scalar_Storage_Order
11960 and then Ignore_Rep_Clauses)
11961 then
11962 return;
11963 end if;
11964
11965 -- Deal with unrecognized pragma
11966
11967 if not Is_Pragma_Name (Pname) then
11968 declare
11969 Msg_Issued : Boolean := False;
11970 begin
11971 Check_Restriction
11972 (Msg_Issued, No_Unrecognized_Pragmas, Pragma_Identifier (N));
11973 if not Msg_Issued and then Warn_On_Unrecognized_Pragma then
11974 Error_Msg_Name_1 := Pname;
11975 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
11976
11977 for PN in First_Pragma_Name .. Last_Pragma_Name loop
11978 if Is_Bad_Spelling_Of (Pname, PN) then
11979 Error_Msg_Name_1 := PN;
11980 Error_Msg_N -- CODEFIX
11981 ("\?g?possible misspelling of %!",
11982 Pragma_Identifier (N));
11983 exit;
11984 end if;
11985 end loop;
11986 end if;
11987 end;
11988
11989 return;
11990 end if;
11991
11992 -- Here to start processing for recognized pragma
11993
11994 Pname := Original_Aspect_Pragma_Name (N);
11995
11996 -- Capture setting of Opt.Uneval_Old
11997
11998 case Opt.Uneval_Old is
11999 when 'A' =>
12000 Set_Uneval_Old_Accept (N);
12001
12002 when 'E' =>
12003 null;
12004
12005 when 'W' =>
12006 Set_Uneval_Old_Warn (N);
12007
12008 when others =>
12009 raise Program_Error;
12010 end case;
12011
12012 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
12013 -- is already set, indicating that we have already checked the policy
12014 -- at the right point. This happens for example in the case of a pragma
12015 -- that is derived from an Aspect.
12016
12017 if Is_Ignored (N) or else Is_Checked (N) then
12018 null;
12019
12020 -- For a pragma that is a rewriting of another pragma, copy the
12021 -- Is_Checked/Is_Ignored status from the rewritten pragma.
12022
12023 elsif Is_Rewrite_Substitution (N)
12024 and then Nkind (Original_Node (N)) = N_Pragma
12025 then
12026 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
12027 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
12028
12029 -- Otherwise query the applicable policy at this point
12030
12031 else
12032 Check_Applicable_Policy (N);
12033
12034 -- If pragma is disabled, rewrite as NULL and skip analysis
12035
12036 if Is_Disabled (N) then
12037 Rewrite (N, Make_Null_Statement (Loc));
12038 Analyze (N);
12039 raise Pragma_Exit;
12040 end if;
12041 end if;
12042
12043 -- Mark assertion pragmas as Ghost depending on their enclosing context
12044
12045 if Assertion_Expression_Pragma (Prag_Id) then
12046 Mark_Ghost_Pragma (N, Current_Scope);
12047 end if;
12048
12049 -- Preset arguments
12050
12051 Arg_Count := List_Length (Pragma_Argument_Associations (N));
12052 Arg1 := First (Pragma_Argument_Associations (N));
12053 Arg2 := Empty;
12054 Arg3 := Empty;
12055 Arg4 := Empty;
12056 Arg5 := Empty;
12057
12058 if Present (Arg1) then
12059 Arg2 := Next (Arg1);
12060
12061 if Present (Arg2) then
12062 Arg3 := Next (Arg2);
12063
12064 if Present (Arg3) then
12065 Arg4 := Next (Arg3);
12066
12067 if Present (Arg4) then
12068 Arg5 := Next (Arg4);
12069 end if;
12070 end if;
12071 end if;
12072 end if;
12073
12074 -- An enumeration type defines the pragmas that are supported by the
12075 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
12076 -- into the corresponding enumeration value for the following case.
12077
12078 case Prag_Id is
12079
12080 -----------------
12081 -- Abort_Defer --
12082 -----------------
12083
12084 -- pragma Abort_Defer;
12085
12086 when Pragma_Abort_Defer =>
12087 GNAT_Pragma;
12088 Check_Arg_Count (0);
12089
12090 -- The only required semantic processing is to check the
12091 -- placement. This pragma must appear at the start of the
12092 -- statement sequence of a handled sequence of statements.
12093
12094 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
12095 or else N /= First (Statements (Parent (N)))
12096 then
12097 Pragma_Misplaced;
12098 end if;
12099
12100 --------------------
12101 -- Abstract_State --
12102 --------------------
12103
12104 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
12105
12106 -- ABSTRACT_STATE_LIST ::=
12107 -- null
12108 -- | STATE_NAME_WITH_OPTIONS
12109 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
12110
12111 -- STATE_NAME_WITH_OPTIONS ::=
12112 -- STATE_NAME
12113 -- | (STATE_NAME with OPTION_LIST)
12114
12115 -- OPTION_LIST ::= OPTION {, OPTION}
12116
12117 -- OPTION ::=
12118 -- SIMPLE_OPTION
12119 -- | NAME_VALUE_OPTION
12120
12121 -- SIMPLE_OPTION ::= Ghost | Relaxed_Initialization | Synchronous
12122
12123 -- NAME_VALUE_OPTION ::=
12124 -- Part_Of => ABSTRACT_STATE
12125 -- | External [=> EXTERNAL_PROPERTY_LIST]
12126
12127 -- EXTERNAL_PROPERTY_LIST ::=
12128 -- EXTERNAL_PROPERTY
12129 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
12130
12131 -- EXTERNAL_PROPERTY ::=
12132 -- Async_Readers [=> boolean_EXPRESSION]
12133 -- | Async_Writers [=> boolean_EXPRESSION]
12134 -- | Effective_Reads [=> boolean_EXPRESSION]
12135 -- | Effective_Writes [=> boolean_EXPRESSION]
12136 -- others => boolean_EXPRESSION
12137
12138 -- STATE_NAME ::= defining_identifier
12139
12140 -- ABSTRACT_STATE ::= name
12141
12142 -- Characteristics:
12143
12144 -- * Analysis - The annotation is fully analyzed immediately upon
12145 -- elaboration as it cannot forward reference entities.
12146
12147 -- * Expansion - None.
12148
12149 -- * Template - The annotation utilizes the generic template of the
12150 -- related package declaration.
12151
12152 -- * Globals - The annotation cannot reference global entities.
12153
12154 -- * Instance - The annotation is instantiated automatically when
12155 -- the related generic package is instantiated.
12156
12157 when Pragma_Abstract_State => Abstract_State : declare
12158 Missing_Parentheses : Boolean := False;
12159 -- Flag set when a state declaration with options is not properly
12160 -- parenthesized.
12161
12162 -- Flags used to verify the consistency of states
12163
12164 Non_Null_Seen : Boolean := False;
12165 Null_Seen : Boolean := False;
12166
12167 procedure Analyze_Abstract_State
12168 (State : Node_Id;
12169 Pack_Id : Entity_Id);
12170 -- Verify the legality of a single state declaration. Create and
12171 -- decorate a state abstraction entity and introduce it into the
12172 -- visibility chain. Pack_Id denotes the entity or the related
12173 -- package where pragma Abstract_State appears.
12174
12175 procedure Malformed_State_Error (State : Node_Id);
12176 -- Emit an error concerning the illegal declaration of abstract
12177 -- state State. This routine diagnoses syntax errors that lead to
12178 -- a different parse tree. The error is issued regardless of the
12179 -- SPARK mode in effect.
12180
12181 ----------------------------
12182 -- Analyze_Abstract_State --
12183 ----------------------------
12184
12185 procedure Analyze_Abstract_State
12186 (State : Node_Id;
12187 Pack_Id : Entity_Id)
12188 is
12189 -- Flags used to verify the consistency of options
12190
12191 AR_Seen : Boolean := False;
12192 AW_Seen : Boolean := False;
12193 ER_Seen : Boolean := False;
12194 EW_Seen : Boolean := False;
12195 External_Seen : Boolean := False;
12196 Ghost_Seen : Boolean := False;
12197 Others_Seen : Boolean := False;
12198 Part_Of_Seen : Boolean := False;
12199 Synchronous_Seen : Boolean := False;
12200
12201 -- Flags used to store the static value of all external states'
12202 -- expressions.
12203
12204 AR_Val : Boolean := False;
12205 AW_Val : Boolean := False;
12206 ER_Val : Boolean := False;
12207 EW_Val : Boolean := False;
12208
12209 State_Id : Entity_Id := Empty;
12210 -- The entity to be generated for the current state declaration
12211
12212 procedure Analyze_External_Option (Opt : Node_Id);
12213 -- Verify the legality of option External
12214
12215 procedure Analyze_External_Property
12216 (Prop : Node_Id;
12217 Expr : Node_Id := Empty);
12218 -- Verify the legailty of a single external property. Prop
12219 -- denotes the external property. Expr is the expression used
12220 -- to set the property.
12221
12222 procedure Analyze_Part_Of_Option (Opt : Node_Id);
12223 -- Verify the legality of option Part_Of
12224
12225 procedure Check_Duplicate_Option
12226 (Opt : Node_Id;
12227 Status : in out Boolean);
12228 -- Flag Status denotes whether a particular option has been
12229 -- seen while processing a state. This routine verifies that
12230 -- Opt is not a duplicate option and sets the flag Status
12231 -- (SPARK RM 7.1.4(1)).
12232
12233 procedure Check_Duplicate_Property
12234 (Prop : Node_Id;
12235 Status : in out Boolean);
12236 -- Flag Status denotes whether a particular property has been
12237 -- seen while processing option External. This routine verifies
12238 -- that Prop is not a duplicate property and sets flag Status.
12239 -- Opt is not a duplicate property and sets the flag Status.
12240 -- (SPARK RM 7.1.4(2))
12241
12242 procedure Check_Ghost_Synchronous;
12243 -- Ensure that the abstract state is not subject to both Ghost
12244 -- and Synchronous simple options. Emit an error if this is the
12245 -- case.
12246
12247 procedure Create_Abstract_State
12248 (Nam : Name_Id;
12249 Decl : Node_Id;
12250 Loc : Source_Ptr;
12251 Is_Null : Boolean);
12252 -- Generate an abstract state entity with name Nam and enter it
12253 -- into visibility. Decl is the "declaration" of the state as
12254 -- it appears in pragma Abstract_State. Loc is the location of
12255 -- the related state "declaration". Flag Is_Null should be set
12256 -- when the associated Abstract_State pragma defines a null
12257 -- state.
12258
12259 -----------------------------
12260 -- Analyze_External_Option --
12261 -----------------------------
12262
12263 procedure Analyze_External_Option (Opt : Node_Id) is
12264 Errors : constant Nat := Serious_Errors_Detected;
12265 Prop : Node_Id;
12266 Props : Node_Id := Empty;
12267
12268 begin
12269 if Nkind (Opt) = N_Component_Association then
12270 Props := Expression (Opt);
12271 end if;
12272
12273 -- External state with properties
12274
12275 if Present (Props) then
12276
12277 -- Multiple properties appear as an aggregate
12278
12279 if Nkind (Props) = N_Aggregate then
12280
12281 -- Simple property form
12282
12283 Prop := First (Expressions (Props));
12284 while Present (Prop) loop
12285 Analyze_External_Property (Prop);
12286 Next (Prop);
12287 end loop;
12288
12289 -- Property with expression form
12290
12291 Prop := First (Component_Associations (Props));
12292 while Present (Prop) loop
12293 Analyze_External_Property
12294 (Prop => First (Choices (Prop)),
12295 Expr => Expression (Prop));
12296
12297 Next (Prop);
12298 end loop;
12299
12300 -- Single property
12301
12302 else
12303 Analyze_External_Property (Props);
12304 end if;
12305
12306 -- An external state defined without any properties defaults
12307 -- all properties to True.
12308
12309 else
12310 AR_Val := True;
12311 AW_Val := True;
12312 ER_Val := True;
12313 EW_Val := True;
12314 end if;
12315
12316 -- Once all external properties have been processed, verify
12317 -- their mutual interaction. Do not perform the check when
12318 -- at least one of the properties is illegal as this will
12319 -- produce a bogus error.
12320
12321 if Errors = Serious_Errors_Detected then
12322 Check_External_Properties
12323 (State, AR_Val, AW_Val, ER_Val, EW_Val);
12324 end if;
12325 end Analyze_External_Option;
12326
12327 -------------------------------
12328 -- Analyze_External_Property --
12329 -------------------------------
12330
12331 procedure Analyze_External_Property
12332 (Prop : Node_Id;
12333 Expr : Node_Id := Empty)
12334 is
12335 Expr_Val : Boolean;
12336
12337 begin
12338 -- Check the placement of "others" (if available)
12339
12340 if Nkind (Prop) = N_Others_Choice then
12341 if Others_Seen then
12342 SPARK_Msg_N
12343 ("only one OTHERS choice allowed in option External",
12344 Prop);
12345 else
12346 Others_Seen := True;
12347 end if;
12348
12349 elsif Others_Seen then
12350 SPARK_Msg_N
12351 ("OTHERS must be the last property in option External",
12352 Prop);
12353
12354 -- The only remaining legal options are the four predefined
12355 -- external properties.
12356
12357 elsif Nkind (Prop) = N_Identifier
12358 and then Chars (Prop) in Name_Async_Readers
12359 | Name_Async_Writers
12360 | Name_Effective_Reads
12361 | Name_Effective_Writes
12362 then
12363 null;
12364
12365 -- Otherwise the construct is not a valid property
12366
12367 else
12368 SPARK_Msg_N ("invalid external state property", Prop);
12369 return;
12370 end if;
12371
12372 -- Ensure that the expression of the external state property
12373 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
12374
12375 if Present (Expr) then
12376 Analyze_And_Resolve (Expr, Standard_Boolean);
12377
12378 if Is_OK_Static_Expression (Expr) then
12379 Expr_Val := Is_True (Expr_Value (Expr));
12380 else
12381 SPARK_Msg_N
12382 ("expression of external state property must be "
12383 & "static", Expr);
12384 return;
12385 end if;
12386
12387 -- The lack of expression defaults the property to True
12388
12389 else
12390 Expr_Val := True;
12391 end if;
12392
12393 -- Named properties
12394
12395 if Nkind (Prop) = N_Identifier then
12396 if Chars (Prop) = Name_Async_Readers then
12397 Check_Duplicate_Property (Prop, AR_Seen);
12398 AR_Val := Expr_Val;
12399
12400 elsif Chars (Prop) = Name_Async_Writers then
12401 Check_Duplicate_Property (Prop, AW_Seen);
12402 AW_Val := Expr_Val;
12403
12404 elsif Chars (Prop) = Name_Effective_Reads then
12405 Check_Duplicate_Property (Prop, ER_Seen);
12406 ER_Val := Expr_Val;
12407
12408 else
12409 Check_Duplicate_Property (Prop, EW_Seen);
12410 EW_Val := Expr_Val;
12411 end if;
12412
12413 -- The handling of property "others" must take into account
12414 -- all other named properties that have been encountered so
12415 -- far. Only those that have not been seen are affected by
12416 -- "others".
12417
12418 else
12419 if not AR_Seen then
12420 AR_Val := Expr_Val;
12421 end if;
12422
12423 if not AW_Seen then
12424 AW_Val := Expr_Val;
12425 end if;
12426
12427 if not ER_Seen then
12428 ER_Val := Expr_Val;
12429 end if;
12430
12431 if not EW_Seen then
12432 EW_Val := Expr_Val;
12433 end if;
12434 end if;
12435 end Analyze_External_Property;
12436
12437 ----------------------------
12438 -- Analyze_Part_Of_Option --
12439 ----------------------------
12440
12441 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
12442 Encap : constant Node_Id := Expression (Opt);
12443 Constits : Elist_Id;
12444 Encap_Id : Entity_Id;
12445 Legal : Boolean;
12446
12447 begin
12448 Check_Duplicate_Option (Opt, Part_Of_Seen);
12449
12450 Analyze_Part_Of
12451 (Indic => First (Choices (Opt)),
12452 Item_Id => State_Id,
12453 Encap => Encap,
12454 Encap_Id => Encap_Id,
12455 Legal => Legal);
12456
12457 -- The Part_Of indicator transforms the abstract state into
12458 -- a constituent of the encapsulating state or single
12459 -- concurrent type.
12460
12461 if Legal then
12462 pragma Assert (Present (Encap_Id));
12463 Constits := Part_Of_Constituents (Encap_Id);
12464
12465 if No (Constits) then
12466 Constits := New_Elmt_List;
12467 Set_Part_Of_Constituents (Encap_Id, Constits);
12468 end if;
12469
12470 Append_Elmt (State_Id, Constits);
12471 Set_Encapsulating_State (State_Id, Encap_Id);
12472 end if;
12473 end Analyze_Part_Of_Option;
12474
12475 ----------------------------
12476 -- Check_Duplicate_Option --
12477 ----------------------------
12478
12479 procedure Check_Duplicate_Option
12480 (Opt : Node_Id;
12481 Status : in out Boolean)
12482 is
12483 begin
12484 if Status then
12485 SPARK_Msg_N ("duplicate state option", Opt);
12486 end if;
12487
12488 Status := True;
12489 end Check_Duplicate_Option;
12490
12491 ------------------------------
12492 -- Check_Duplicate_Property --
12493 ------------------------------
12494
12495 procedure Check_Duplicate_Property
12496 (Prop : Node_Id;
12497 Status : in out Boolean)
12498 is
12499 begin
12500 if Status then
12501 SPARK_Msg_N ("duplicate external property", Prop);
12502 end if;
12503
12504 Status := True;
12505 end Check_Duplicate_Property;
12506
12507 -----------------------------
12508 -- Check_Ghost_Synchronous --
12509 -----------------------------
12510
12511 procedure Check_Ghost_Synchronous is
12512 begin
12513 -- A synchronized abstract state cannot be Ghost and vice
12514 -- versa (SPARK RM 6.9(19)).
12515
12516 if Ghost_Seen and Synchronous_Seen then
12517 SPARK_Msg_N ("synchronized state cannot be ghost", State);
12518 end if;
12519 end Check_Ghost_Synchronous;
12520
12521 ---------------------------
12522 -- Create_Abstract_State --
12523 ---------------------------
12524
12525 procedure Create_Abstract_State
12526 (Nam : Name_Id;
12527 Decl : Node_Id;
12528 Loc : Source_Ptr;
12529 Is_Null : Boolean)
12530 is
12531 begin
12532 -- The abstract state may be semi-declared when the related
12533 -- package was withed through a limited with clause. In that
12534 -- case reuse the entity to fully declare the state.
12535
12536 if Present (Decl) and then Present (Entity (Decl)) then
12537 State_Id := Entity (Decl);
12538
12539 -- Otherwise the elaboration of pragma Abstract_State
12540 -- declares the state.
12541
12542 else
12543 State_Id := Make_Defining_Identifier (Loc, Nam);
12544
12545 if Present (Decl) then
12546 Set_Entity (Decl, State_Id);
12547 end if;
12548 end if;
12549
12550 -- Null states never come from source
12551
12552 Set_Comes_From_Source (State_Id, not Is_Null);
12553 Set_Parent (State_Id, State);
12554 Mutate_Ekind (State_Id, E_Abstract_State);
12555 Set_Is_Not_Self_Hidden (State_Id);
12556 Set_Etype (State_Id, Standard_Void_Type);
12557 Set_Encapsulating_State (State_Id, Empty);
12558
12559 -- Set the SPARK mode from the current context
12560
12561 Set_SPARK_Pragma (State_Id, SPARK_Mode_Pragma);
12562 Set_SPARK_Pragma_Inherited (State_Id);
12563
12564 -- An abstract state declared within a Ghost region becomes
12565 -- Ghost (SPARK RM 6.9(2)).
12566
12567 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then
12568 Set_Is_Ghost_Entity (State_Id);
12569 end if;
12570
12571 -- Establish a link between the state declaration and the
12572 -- abstract state entity. Note that a null state remains as
12573 -- N_Null and does not carry any linkages.
12574
12575 if not Is_Null then
12576 if Present (Decl) then
12577 Set_Entity (Decl, State_Id);
12578 Set_Etype (Decl, Standard_Void_Type);
12579 end if;
12580
12581 -- Every non-null state must be defined, nameable and
12582 -- resolvable.
12583
12584 Push_Scope (Pack_Id);
12585 Generate_Definition (State_Id);
12586 Enter_Name (State_Id);
12587 Pop_Scope;
12588 end if;
12589 end Create_Abstract_State;
12590
12591 -- Local variables
12592
12593 Opt : Node_Id;
12594 Opt_Nam : Node_Id;
12595
12596 -- Start of processing for Analyze_Abstract_State
12597
12598 begin
12599 -- A package with a null abstract state is not allowed to
12600 -- declare additional states.
12601
12602 if Null_Seen then
12603 SPARK_Msg_NE
12604 ("package & has null abstract state", State, Pack_Id);
12605
12606 -- Null states appear as internally generated entities
12607
12608 elsif Nkind (State) = N_Null then
12609 Create_Abstract_State
12610 (Nam => New_Internal_Name ('S'),
12611 Decl => Empty,
12612 Loc => Sloc (State),
12613 Is_Null => True);
12614 Null_Seen := True;
12615
12616 -- Catch a case where a null state appears in a list of
12617 -- non-null states.
12618
12619 if Non_Null_Seen then
12620 SPARK_Msg_NE
12621 ("package & has non-null abstract state",
12622 State, Pack_Id);
12623 end if;
12624
12625 -- Simple state declaration
12626
12627 elsif Nkind (State) = N_Identifier then
12628 Create_Abstract_State
12629 (Nam => Chars (State),
12630 Decl => State,
12631 Loc => Sloc (State),
12632 Is_Null => False);
12633 Non_Null_Seen := True;
12634
12635 -- State declaration with various options. This construct
12636 -- appears as an extension aggregate in the tree.
12637
12638 elsif Nkind (State) = N_Extension_Aggregate then
12639 if Nkind (Ancestor_Part (State)) = N_Identifier then
12640 Create_Abstract_State
12641 (Nam => Chars (Ancestor_Part (State)),
12642 Decl => Ancestor_Part (State),
12643 Loc => Sloc (Ancestor_Part (State)),
12644 Is_Null => False);
12645 Non_Null_Seen := True;
12646 else
12647 SPARK_Msg_N
12648 ("state name must be an identifier",
12649 Ancestor_Part (State));
12650 end if;
12651
12652 -- Options External, Ghost and Synchronous appear as
12653 -- expressions.
12654
12655 Opt := First (Expressions (State));
12656 while Present (Opt) loop
12657 if Nkind (Opt) = N_Identifier then
12658
12659 -- External
12660
12661 if Chars (Opt) = Name_External then
12662 Check_Duplicate_Option (Opt, External_Seen);
12663 Analyze_External_Option (Opt);
12664
12665 -- Ghost
12666
12667 elsif Chars (Opt) = Name_Ghost then
12668 Check_Duplicate_Option (Opt, Ghost_Seen);
12669 Check_Ghost_Synchronous;
12670
12671 if Present (State_Id) then
12672 Set_Is_Ghost_Entity (State_Id);
12673 end if;
12674
12675 -- Synchronous
12676
12677 elsif Chars (Opt) = Name_Synchronous then
12678 Check_Duplicate_Option (Opt, Synchronous_Seen);
12679 Check_Ghost_Synchronous;
12680
12681 -- Option Part_Of without an encapsulating state is
12682 -- illegal (SPARK RM 7.1.4(8)).
12683
12684 elsif Chars (Opt) = Name_Part_Of then
12685 SPARK_Msg_N
12686 ("indicator Part_Of must denote abstract state, "
12687 & "single protected type or single task type",
12688 Opt);
12689
12690 -- Do not emit an error message when a previous state
12691 -- declaration with options was not parenthesized as
12692 -- the option is actually another state declaration.
12693 --
12694 -- with Abstract_State
12695 -- (State_1 with ..., -- missing parentheses
12696 -- (State_2 with ...),
12697 -- State_3) -- ok state declaration
12698
12699 elsif Missing_Parentheses then
12700 null;
12701
12702 -- Otherwise the option is not allowed. Note that it
12703 -- is not possible to distinguish between an option
12704 -- and a state declaration when a previous state with
12705 -- options not properly parentheses.
12706 --
12707 -- with Abstract_State
12708 -- (State_1 with ..., -- missing parentheses
12709 -- State_2); -- could be an option
12710
12711 else
12712 SPARK_Msg_N
12713 ("simple option not allowed in state declaration",
12714 Opt);
12715 end if;
12716
12717 -- Catch a case where missing parentheses around a state
12718 -- declaration with options cause a subsequent state
12719 -- declaration with options to be treated as an option.
12720 --
12721 -- with Abstract_State
12722 -- (State_1 with ..., -- missing parentheses
12723 -- (State_2 with ...))
12724
12725 elsif Nkind (Opt) = N_Extension_Aggregate then
12726 Missing_Parentheses := True;
12727 SPARK_Msg_N
12728 ("state declaration must be parenthesized",
12729 Ancestor_Part (State));
12730
12731 -- Otherwise the option is malformed
12732
12733 else
12734 SPARK_Msg_N ("malformed option", Opt);
12735 end if;
12736
12737 Next (Opt);
12738 end loop;
12739
12740 -- Options External and Part_Of appear as component
12741 -- associations.
12742
12743 Opt := First (Component_Associations (State));
12744 while Present (Opt) loop
12745 Opt_Nam := First (Choices (Opt));
12746
12747 if Nkind (Opt_Nam) = N_Identifier then
12748 if Chars (Opt_Nam) = Name_External then
12749 Analyze_External_Option (Opt);
12750
12751 elsif Chars (Opt_Nam) = Name_Part_Of then
12752 Analyze_Part_Of_Option (Opt);
12753
12754 else
12755 SPARK_Msg_N ("invalid state option", Opt);
12756 end if;
12757 else
12758 SPARK_Msg_N ("invalid state option", Opt);
12759 end if;
12760
12761 Next (Opt);
12762 end loop;
12763
12764 -- Any other attempt to declare a state is illegal
12765
12766 else
12767 Malformed_State_Error (State);
12768 return;
12769 end if;
12770
12771 -- Guard against a junk state. In such cases no entity is
12772 -- generated and the subsequent checks cannot be applied.
12773
12774 if Present (State_Id) then
12775
12776 -- Verify whether the state does not introduce an illegal
12777 -- hidden state within a package subject to a null abstract
12778 -- state.
12779
12780 Check_No_Hidden_State (State_Id);
12781
12782 -- Check whether the lack of option Part_Of agrees with the
12783 -- placement of the abstract state with respect to the state
12784 -- space.
12785
12786 if not Part_Of_Seen then
12787 Check_Missing_Part_Of (State_Id);
12788 end if;
12789
12790 -- Associate the state with its related package
12791
12792 if No (Abstract_States (Pack_Id)) then
12793 Set_Abstract_States (Pack_Id, New_Elmt_List);
12794 end if;
12795
12796 Append_Elmt (State_Id, Abstract_States (Pack_Id));
12797 end if;
12798 end Analyze_Abstract_State;
12799
12800 ---------------------------
12801 -- Malformed_State_Error --
12802 ---------------------------
12803
12804 procedure Malformed_State_Error (State : Node_Id) is
12805 begin
12806 Error_Msg_N ("malformed abstract state declaration", State);
12807
12808 -- An abstract state with a simple option is being declared
12809 -- with "=>" rather than the legal "with". The state appears
12810 -- as a component association.
12811
12812 if Nkind (State) = N_Component_Association then
12813 Error_Msg_N ("\use WITH to specify simple option", State);
12814 end if;
12815 end Malformed_State_Error;
12816
12817 -- Local variables
12818
12819 Pack_Decl : Node_Id;
12820 Pack_Id : Entity_Id;
12821 State : Node_Id;
12822 States : Node_Id;
12823
12824 -- Start of processing for Abstract_State
12825
12826 begin
12827 GNAT_Pragma;
12828 Check_No_Identifiers;
12829 Check_Arg_Count (1);
12830
12831 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
12832
12833 if Nkind (Pack_Decl) not in
12834 N_Generic_Package_Declaration | N_Package_Declaration
12835 then
12836 Pragma_Misplaced;
12837 end if;
12838
12839 Pack_Id := Defining_Entity (Pack_Decl);
12840
12841 -- A pragma that applies to a Ghost entity becomes Ghost for the
12842 -- purposes of legality checks and removal of ignored Ghost code.
12843
12844 Mark_Ghost_Pragma (N, Pack_Id);
12845 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
12846
12847 -- Chain the pragma on the contract for completeness
12848
12849 Add_Contract_Item (N, Pack_Id);
12850
12851 -- The legality checks of pragmas Abstract_State, Initializes, and
12852 -- Initial_Condition are affected by the SPARK mode in effect. In
12853 -- addition, these three pragmas are subject to an inherent order:
12854
12855 -- 1) Abstract_State
12856 -- 2) Initializes
12857 -- 3) Initial_Condition
12858
12859 -- Analyze all these pragmas in the order outlined above
12860
12861 Analyze_If_Present (Pragma_SPARK_Mode);
12862 States := Expression (Get_Argument (N, Pack_Id));
12863
12864 -- Multiple non-null abstract states appear as an aggregate
12865
12866 if Nkind (States) = N_Aggregate then
12867 State := First (Expressions (States));
12868 while Present (State) loop
12869 Analyze_Abstract_State (State, Pack_Id);
12870 Next (State);
12871 end loop;
12872
12873 -- An abstract state with a simple option is being illegaly
12874 -- declared with "=>" rather than "with". In this case the
12875 -- state declaration appears as a component association.
12876
12877 if Present (Component_Associations (States)) then
12878 State := First (Component_Associations (States));
12879 while Present (State) loop
12880 Malformed_State_Error (State);
12881 Next (State);
12882 end loop;
12883 end if;
12884
12885 -- Various forms of a single abstract state. Note that these may
12886 -- include malformed state declarations.
12887
12888 else
12889 Analyze_Abstract_State (States, Pack_Id);
12890 end if;
12891
12892 Analyze_If_Present (Pragma_Initializes);
12893 Analyze_If_Present (Pragma_Initial_Condition);
12894 end Abstract_State;
12895
12896 ------------
12897 -- Ada_83 --
12898 ------------
12899
12900 -- pragma Ada_83;
12901
12902 -- Note: this pragma also has some specific processing in Par.Prag
12903 -- because we want to set the Ada version mode during parsing.
12904
12905 when Pragma_Ada_83 =>
12906 GNAT_Pragma;
12907 Check_Arg_Count (0);
12908
12909 -- We really should check unconditionally for proper configuration
12910 -- pragma placement, since we really don't want mixed Ada modes
12911 -- within a single unit, and the GNAT reference manual has always
12912 -- said this was a configuration pragma, but we did not check and
12913 -- are hesitant to add the check now.
12914
12915 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
12916 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
12917 -- or Ada 2012 mode.
12918
12919 if Ada_Version >= Ada_2005 then
12920 Check_Valid_Configuration_Pragma;
12921 end if;
12922
12923 -- Now set Ada 83 mode
12924
12925 if Latest_Ada_Only then
12926 Error_Pragma ("??pragma% ignored");
12927 else
12928 Ada_Version := Ada_83;
12929 Ada_Version_Explicit := Ada_83;
12930 Ada_Version_Pragma := N;
12931 end if;
12932
12933 ------------
12934 -- Ada_95 --
12935 ------------
12936
12937 -- pragma Ada_95;
12938
12939 -- Note: this pragma also has some specific processing in Par.Prag
12940 -- because we want to set the Ada 83 version mode during parsing.
12941
12942 when Pragma_Ada_95 =>
12943 GNAT_Pragma;
12944 Check_Arg_Count (0);
12945
12946 -- We really should check unconditionally for proper configuration
12947 -- pragma placement, since we really don't want mixed Ada modes
12948 -- within a single unit, and the GNAT reference manual has always
12949 -- said this was a configuration pragma, but we did not check and
12950 -- are hesitant to add the check now.
12951
12952 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
12953 -- or Ada 95, so we must check if we are in Ada 2005 mode.
12954
12955 if Ada_Version >= Ada_2005 then
12956 Check_Valid_Configuration_Pragma;
12957 end if;
12958
12959 -- Now set Ada 95 mode
12960
12961 if Latest_Ada_Only then
12962 Error_Pragma ("??pragma% ignored");
12963 else
12964 Ada_Version := Ada_95;
12965 Ada_Version_Explicit := Ada_95;
12966 Ada_Version_Pragma := N;
12967 end if;
12968
12969 ---------------------
12970 -- Ada_05/Ada_2005 --
12971 ---------------------
12972
12973 -- pragma Ada_05;
12974 -- pragma Ada_05 (LOCAL_NAME);
12975
12976 -- pragma Ada_2005;
12977 -- pragma Ada_2005 (LOCAL_NAME):
12978
12979 -- Note: these pragmas also have some specific processing in Par.Prag
12980 -- because we want to set the Ada 2005 version mode during parsing.
12981
12982 -- The one argument form is used for managing the transition from
12983 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
12984 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
12985 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
12986 -- mode, a preference rule is established which does not choose
12987 -- such an entity unless it is unambiguously specified. This avoids
12988 -- extra subprograms marked this way from generating ambiguities in
12989 -- otherwise legal pre-Ada_2005 programs. The one argument form is
12990 -- intended for exclusive use in the GNAT run-time library.
12991
12992 when Pragma_Ada_05
12993 | Pragma_Ada_2005
12994 =>
12995 declare
12996 E_Id : Node_Id;
12997
12998 begin
12999 GNAT_Pragma;
13000
13001 if Arg_Count = 1 then
13002 Check_Arg_Is_Local_Name (Arg1);
13003 E_Id := Get_Pragma_Arg (Arg1);
13004
13005 if Etype (E_Id) = Any_Type then
13006 return;
13007 end if;
13008
13009 Set_Is_Ada_2005_Only (Entity (E_Id));
13010 Record_Rep_Item (Entity (E_Id), N);
13011
13012 else
13013 Check_Arg_Count (0);
13014
13015 -- For Ada_2005 we unconditionally enforce the documented
13016 -- configuration pragma placement, since we do not want to
13017 -- tolerate mixed modes in a unit involving Ada 2005. That
13018 -- would cause real difficulties for those cases where there
13019 -- are incompatibilities between Ada 95 and Ada 2005.
13020
13021 Check_Valid_Configuration_Pragma;
13022
13023 -- Now set appropriate Ada mode
13024
13025 if Latest_Ada_Only then
13026 Error_Pragma ("??pragma% ignored");
13027 else
13028 Ada_Version := Ada_2005;
13029 Ada_Version_Explicit := Ada_2005;
13030 Ada_Version_Pragma := N;
13031 end if;
13032 end if;
13033 end;
13034
13035 ---------------------
13036 -- Ada_12/Ada_2012 --
13037 ---------------------
13038
13039 -- pragma Ada_12;
13040 -- pragma Ada_12 (LOCAL_NAME);
13041
13042 -- pragma Ada_2012;
13043 -- pragma Ada_2012 (LOCAL_NAME):
13044
13045 -- Note: these pragmas also have some specific processing in Par.Prag
13046 -- because we want to set the Ada 2012 version mode during parsing.
13047
13048 -- The one argument form is used for managing the transition from Ada
13049 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
13050 -- as Ada_2012 only, then referencing the entity in any pre-Ada_2012
13051 -- mode will generate a warning. In addition, in any pre-Ada_2012
13052 -- mode, a preference rule is established which does not choose
13053 -- such an entity unless it is unambiguously specified. This avoids
13054 -- extra subprograms marked this way from generating ambiguities in
13055 -- otherwise legal pre-Ada_2012 programs. The one argument form is
13056 -- intended for exclusive use in the GNAT run-time library.
13057
13058 when Pragma_Ada_12
13059 | Pragma_Ada_2012
13060 =>
13061 declare
13062 E_Id : Node_Id;
13063
13064 begin
13065 GNAT_Pragma;
13066
13067 if Arg_Count = 1 then
13068 Check_Arg_Is_Local_Name (Arg1);
13069 E_Id := Get_Pragma_Arg (Arg1);
13070
13071 if Etype (E_Id) = Any_Type then
13072 return;
13073 end if;
13074
13075 Set_Is_Ada_2012_Only (Entity (E_Id));
13076 Record_Rep_Item (Entity (E_Id), N);
13077
13078 else
13079 Check_Arg_Count (0);
13080
13081 -- For Ada_2012 we unconditionally enforce the documented
13082 -- configuration pragma placement, since we do not want to
13083 -- tolerate mixed modes in a unit involving Ada 2012. That
13084 -- would cause real difficulties for those cases where there
13085 -- are incompatibilities between Ada 95 and Ada 2012. We could
13086 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
13087
13088 Check_Valid_Configuration_Pragma;
13089
13090 -- Now set appropriate Ada mode
13091
13092 Ada_Version := Ada_2012;
13093 Ada_Version_Explicit := Ada_2012;
13094 Ada_Version_Pragma := N;
13095 end if;
13096 end;
13097
13098 --------------
13099 -- Ada_2022 --
13100 --------------
13101
13102 -- pragma Ada_2022;
13103 -- pragma Ada_2022 (LOCAL_NAME):
13104
13105 -- Note: this pragma also has some specific processing in Par.Prag
13106 -- because we want to set the Ada 2022 version mode during parsing.
13107
13108 -- The one argument form is used for managing the transition from Ada
13109 -- 2012 to Ada 2022 in the run-time library. If an entity is marked
13110 -- as Ada_2022 only, then referencing the entity in any pre-Ada_2022
13111 -- mode will generate a warning;for calls to Ada_2022 only primitives
13112 -- that require overriding an error will be reported. In addition, in
13113 -- any pre-Ada_2022 mode, a preference rule is established which does
13114 -- not choose such an entity unless it is unambiguously specified.
13115 -- This avoids extra subprograms marked this way from generating
13116 -- ambiguities in otherwise legal pre-Ada 2022 programs. The one
13117 -- argument form is intended for exclusive use in the GNAT run-time
13118 -- library.
13119
13120 when Pragma_Ada_2022 =>
13121 declare
13122 E_Id : Node_Id;
13123
13124 begin
13125 GNAT_Pragma;
13126
13127 if Arg_Count = 1 then
13128 Check_Arg_Is_Local_Name (Arg1);
13129 E_Id := Get_Pragma_Arg (Arg1);
13130
13131 if Etype (E_Id) = Any_Type then
13132 return;
13133 end if;
13134
13135 Set_Is_Ada_2022_Only (Entity (E_Id));
13136 Record_Rep_Item (Entity (E_Id), N);
13137
13138 else
13139 Check_Arg_Count (0);
13140
13141 -- For Ada_2022 we unconditionally enforce the documented
13142 -- configuration pragma placement, since we do not want to
13143 -- tolerate mixed modes in a unit involving Ada 2022. That
13144 -- would cause real difficulties for those cases where there
13145 -- are incompatibilities between Ada 2012 and Ada 2022. We
13146 -- could allow mixing of Ada 2012 and Ada 2022 but it's not
13147 -- worth it.
13148
13149 Check_Valid_Configuration_Pragma;
13150
13151 -- Now set appropriate Ada mode
13152
13153 Ada_Version := Ada_2022;
13154 Ada_Version_Explicit := Ada_2022;
13155 Ada_Version_Pragma := N;
13156 end if;
13157 end;
13158
13159 -------------------------------------
13160 -- Aggregate_Individually_Assign --
13161 -------------------------------------
13162
13163 -- pragma Aggregate_Individually_Assign;
13164
13165 when Pragma_Aggregate_Individually_Assign =>
13166 GNAT_Pragma;
13167 Check_Arg_Count (0);
13168 Check_Valid_Configuration_Pragma;
13169 Aggregate_Individually_Assign := True;
13170
13171 ----------------------
13172 -- All_Calls_Remote --
13173 ----------------------
13174
13175 -- pragma All_Calls_Remote [(library_package_NAME)];
13176
13177 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
13178 Lib_Entity : Entity_Id;
13179
13180 begin
13181 Check_Ada_83_Warning;
13182 Check_Valid_Library_Unit_Pragma;
13183
13184 -- If N was rewritten as a null statement there is nothing more
13185 -- to do.
13186
13187 if Nkind (N) = N_Null_Statement then
13188 return;
13189 end if;
13190
13191 Lib_Entity := Find_Lib_Unit_Name;
13192
13193 -- A pragma that applies to a Ghost entity becomes Ghost for the
13194 -- purposes of legality checks and removal of ignored Ghost code.
13195
13196 Mark_Ghost_Pragma (N, Lib_Entity);
13197
13198 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
13199
13200 if Present (Lib_Entity) and then not Debug_Flag_U then
13201 if not Is_Remote_Call_Interface (Lib_Entity) then
13202 Error_Pragma ("pragma% only apply to rci unit");
13203
13204 -- Set flag for entity of the library unit
13205
13206 else
13207 Set_Has_All_Calls_Remote (Lib_Entity);
13208 end if;
13209 end if;
13210 end All_Calls_Remote;
13211
13212 ---------------------------
13213 -- Allow_Integer_Address --
13214 ---------------------------
13215
13216 -- pragma Allow_Integer_Address;
13217
13218 when Pragma_Allow_Integer_Address =>
13219 GNAT_Pragma;
13220 Check_Valid_Configuration_Pragma;
13221 Check_Arg_Count (0);
13222
13223 -- If Address is a private type, then set the flag to allow
13224 -- integer address values. If Address is not private, then this
13225 -- pragma has no purpose, so it is simply ignored. Not clear if
13226 -- there are any such targets now.
13227
13228 if Opt.Address_Is_Private then
13229 Opt.Allow_Integer_Address := True;
13230 end if;
13231
13232 -----------------------
13233 -- Always_Terminates --
13234 -----------------------
13235
13236 -- pragma Always_Terminates [ (boolean_EXPRESSION) ];
13237
13238 -- Characteristics:
13239
13240 -- * Analysis - The annotation undergoes initial checks to verify
13241 -- the legal placement and context. Secondary checks preanalyze the
13242 -- expressions in:
13243
13244 -- Analyze_Always_Terminates_Cases_In_Decl_Part
13245
13246 -- * Expansion - The annotation is expanded during the expansion of
13247 -- the related subprogram [body] contract as performed in:
13248
13249 -- Expand_Subprogram_Contract
13250
13251 -- * Template - The annotation utilizes the generic template of the
13252 -- related subprogram [body] when it is:
13253
13254 -- aspect on subprogram declaration
13255 -- aspect on stand-alone subprogram body
13256 -- pragma on stand-alone subprogram body
13257
13258 -- The annotation must prepare its own template when it is:
13259
13260 -- pragma on subprogram declaration
13261
13262 -- * Globals - Capture of global references must occur after full
13263 -- analysis.
13264
13265 -- * Instance - The annotation is instantiated automatically when
13266 -- the related generic subprogram [body] is instantiated except for
13267 -- the "pragma on subprogram declaration" case. In that scenario
13268 -- the annotation must instantiate itself.
13269
13270 when Pragma_Always_Terminates => Always_Terminates : declare
13271 Spec_Id : Entity_Id;
13272 Subp_Decl : Node_Id;
13273 Subp_Spec : Node_Id;
13274
13275 begin
13276 GNAT_Pragma;
13277 Check_No_Identifiers;
13278 Check_At_Most_N_Arguments (1);
13279
13280 -- Ensure the proper placement of the pragma. Always_Terminates
13281 -- must be associated with a subprogram declaration or a body that
13282 -- acts as a spec.
13283
13284 Subp_Decl :=
13285 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
13286
13287 -- Generic subprogram and package declaration
13288
13289 if Nkind (Subp_Decl) in N_Generic_Declaration then
13290 null;
13291
13292 -- Package declaration
13293
13294 elsif Nkind (Subp_Decl) = N_Package_Declaration then
13295 null;
13296
13297 -- Body acts as spec
13298
13299 elsif Nkind (Subp_Decl) = N_Subprogram_Body
13300 and then No (Corresponding_Spec (Subp_Decl))
13301 then
13302 null;
13303
13304 -- Body stub acts as spec
13305
13306 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
13307 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
13308 then
13309 null;
13310
13311 -- Subprogram
13312
13313 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
13314 Subp_Spec := Specification (Subp_Decl);
13315
13316 -- Pragma Always_Terminates is forbidden on null procedures,
13317 -- as this may lead to potential ambiguities in behavior
13318 -- when interface null procedures are involved. Also, it
13319 -- just wouldn't make sense, because null procedures always
13320 -- terminate anyway.
13321
13322 if Nkind (Subp_Spec) = N_Procedure_Specification
13323 and then Null_Present (Subp_Spec)
13324 then
13325 Error_Msg_N (Fix_Error
13326 ("pragma % cannot apply to null procedure"), N);
13327 return;
13328 end if;
13329
13330 -- Entry
13331
13332 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
13333 null;
13334
13335 else
13336 Pragma_Misplaced;
13337 end if;
13338
13339 Spec_Id := Unique_Defining_Entity (Subp_Decl);
13340
13341 -- In order to call Is_Function_With_Side_Effects, analyze pragma
13342 -- Side_Effects if present.
13343
13344 Analyze_If_Present (Pragma_Side_Effects);
13345
13346 -- Pragma Always_Terminates is not allowed on functions without
13347 -- side effects.
13348
13349 if Ekind (Spec_Id) in E_Function | E_Generic_Function
13350 and then not Is_Function_With_Side_Effects (Spec_Id)
13351 then
13352 Error_Msg_Code := GEC_Always_Terminates_On_Function;
13353
13354 if Ekind (Spec_Id) = E_Function then
13355 Error_Msg_N (Fix_Error
13356 ("pragma % cannot apply to function '[[]']"), N);
13357 return;
13358
13359 elsif Ekind (Spec_Id) = E_Generic_Function then
13360 Error_Msg_N (Fix_Error
13361 ("pragma % cannot apply to generic function '[[]']"), N);
13362 return;
13363 end if;
13364 end if;
13365
13366 -- Pragma Always_Terminates applied to packages doesn't allow any
13367 -- expression.
13368
13369 if Is_Package_Or_Generic_Package (Spec_Id)
13370 and then Arg_Count /= 0
13371 then
13372 Error_Msg_N (Fix_Error
13373 ("pragma % applied to package cannot have arguments"), N);
13374 return;
13375 end if;
13376
13377 -- A pragma that applies to a Ghost entity becomes Ghost for the
13378 -- purposes of legality checks and removal of ignored Ghost code.
13379
13380 Mark_Ghost_Pragma (N, Spec_Id);
13381
13382 -- Chain the pragma on the contract for further processing by
13383 -- Analyze_Always_Terminates_In_Decl_Part.
13384
13385 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
13386
13387 -- Fully analyze the pragma when it appears inside a subprogram
13388 -- body because it cannot benefit from forward references.
13389
13390 if Nkind (Subp_Decl) in N_Subprogram_Body
13391 | N_Subprogram_Body_Stub
13392 then
13393 -- The legality checks of pragma Always_Terminates are affected
13394 -- by the SPARK mode in effect and the volatility of the
13395 -- context. Analyze all pragmas in a specific order.
13396
13397 Analyze_If_Present (Pragma_SPARK_Mode);
13398 Analyze_If_Present (Pragma_Volatile_Function);
13399 Analyze_Always_Terminates_In_Decl_Part (N);
13400 end if;
13401 end Always_Terminates;
13402
13403 --------------
13404 -- Annotate --
13405 --------------
13406
13407 -- pragma Annotate
13408 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
13409 -- ARG ::= NAME | EXPRESSION
13410
13411 -- The first two arguments are by convention intended to refer to an
13412 -- external tool and a tool-specific function. These arguments are
13413 -- not analyzed.
13414
13415 when Pragma_Annotate | Pragma_GNAT_Annotate => Annotate : declare
13416 Arg : Node_Id;
13417 Expr : Node_Id;
13418 Nam_Arg : Node_Id;
13419
13420 --------------------------
13421 -- Inferred_String_Type --
13422 --------------------------
13423
13424 function Preferred_String_Type (Expr : Node_Id) return Entity_Id;
13425 -- Infer the type to use for a string literal or a concatentation
13426 -- of operands whose types can be inferred. For such expressions,
13427 -- returns the "narrowest" of the three predefined string types
13428 -- that can represent the characters occurring in the expression.
13429 -- For other expressions, returns Empty.
13430
13431 function Preferred_String_Type (Expr : Node_Id) return Entity_Id is
13432 begin
13433 case Nkind (Expr) is
13434 when N_String_Literal =>
13435 if Has_Wide_Wide_Character (Expr) then
13436 return Standard_Wide_Wide_String;
13437 elsif Has_Wide_Character (Expr) then
13438 return Standard_Wide_String;
13439 else
13440 return Standard_String;
13441 end if;
13442
13443 when N_Op_Concat =>
13444 declare
13445 L_Type : constant Entity_Id
13446 := Preferred_String_Type (Left_Opnd (Expr));
13447 R_Type : constant Entity_Id
13448 := Preferred_String_Type (Right_Opnd (Expr));
13449
13450 Type_Table : constant array (1 .. 4) of Entity_Id
13451 := (Empty,
13452 Standard_Wide_Wide_String,
13453 Standard_Wide_String,
13454 Standard_String);
13455 begin
13456 for Idx in Type_Table'Range loop
13457 if L_Type = Type_Table (Idx) or
13458 R_Type = Type_Table (Idx)
13459 then
13460 return Type_Table (Idx);
13461 end if;
13462 end loop;
13463 raise Program_Error;
13464 end;
13465
13466 when others =>
13467 return Empty;
13468 end case;
13469 end Preferred_String_Type;
13470 begin
13471 GNAT_Pragma;
13472 Check_At_Least_N_Arguments (1);
13473
13474 Nam_Arg := Last (Pragma_Argument_Associations (N));
13475
13476 -- Determine whether the last argument is "Entity => local_NAME"
13477 -- and if it is, perform the required semantic checks. Remove the
13478 -- argument from further processing.
13479
13480 if Nkind (Nam_Arg) = N_Pragma_Argument_Association
13481 and then Chars (Nam_Arg) = Name_Entity
13482 then
13483 Check_Arg_Is_Local_Name (Nam_Arg);
13484 Arg_Count := Arg_Count - 1;
13485
13486 -- A pragma that applies to a Ghost entity becomes Ghost for
13487 -- the purposes of legality checks and removal of ignored Ghost
13488 -- code.
13489
13490 if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg))
13491 and then Present (Entity (Get_Pragma_Arg (Nam_Arg)))
13492 then
13493 Mark_Ghost_Pragma (N, Entity (Get_Pragma_Arg (Nam_Arg)));
13494 end if;
13495 end if;
13496
13497 -- Continue the processing with last argument removed for now
13498
13499 Check_Arg_Is_Identifier (Arg1);
13500 Check_No_Identifiers;
13501 Store_Note (N);
13502
13503 -- The second parameter is optional, it is never analyzed
13504
13505 if No (Arg2) then
13506 null;
13507
13508 -- Otherwise there is a second parameter
13509
13510 else
13511 -- The second parameter must be an identifier
13512
13513 Check_Arg_Is_Identifier (Arg2);
13514
13515 -- Process the remaining parameters (if any)
13516
13517 Arg := Next (Arg2);
13518 while Present (Arg) loop
13519 Expr := Get_Pragma_Arg (Arg);
13520 Analyze (Expr);
13521
13522 if Is_Entity_Name (Expr) then
13523 null;
13524
13525 -- For string literals and concatenations of string literals
13526 -- we assume Standard_String as the type, unless the string
13527 -- contains wide or wide_wide characters.
13528
13529 elsif Present (Preferred_String_Type (Expr)) then
13530 Resolve (Expr, Preferred_String_Type (Expr));
13531
13532 elsif Is_Overloaded (Expr) then
13533 Error_Pragma_Arg ("ambiguous argument for pragma%", Expr);
13534
13535 else
13536 Resolve (Expr);
13537 end if;
13538
13539 Next (Arg);
13540 end loop;
13541 end if;
13542 end Annotate;
13543
13544 -------------------------------------------------
13545 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
13546 -------------------------------------------------
13547
13548 -- pragma Assert
13549 -- ( [Check => ] Boolean_EXPRESSION
13550 -- [, [Message =>] Static_String_EXPRESSION]);
13551
13552 -- pragma Assert_And_Cut
13553 -- ( [Check => ] Boolean_EXPRESSION
13554 -- [, [Message =>] Static_String_EXPRESSION]);
13555
13556 -- pragma Assume
13557 -- ( [Check => ] Boolean_EXPRESSION
13558 -- [, [Message =>] Static_String_EXPRESSION]);
13559
13560 -- pragma Loop_Invariant
13561 -- ( [Check => ] Boolean_EXPRESSION
13562 -- [, [Message =>] Static_String_EXPRESSION]);
13563
13564 when Pragma_Assert
13565 | Pragma_Assert_And_Cut
13566 | Pragma_Assume
13567 | Pragma_Loop_Invariant
13568 =>
13569 Assert : declare
13570 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
13571 -- Determine whether expression Expr contains a Loop_Entry
13572 -- attribute reference.
13573
13574 -------------------------
13575 -- Contains_Loop_Entry --
13576 -------------------------
13577
13578 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
13579 Has_Loop_Entry : Boolean := False;
13580
13581 function Process (N : Node_Id) return Traverse_Result;
13582 -- Process function for traversal to look for Loop_Entry
13583
13584 -------------
13585 -- Process --
13586 -------------
13587
13588 function Process (N : Node_Id) return Traverse_Result is
13589 begin
13590 if Nkind (N) = N_Attribute_Reference
13591 and then Attribute_Name (N) = Name_Loop_Entry
13592 then
13593 Has_Loop_Entry := True;
13594 return Abandon;
13595 else
13596 return OK;
13597 end if;
13598 end Process;
13599
13600 procedure Traverse is new Traverse_Proc (Process);
13601
13602 -- Start of processing for Contains_Loop_Entry
13603
13604 begin
13605 Traverse (Expr);
13606 return Has_Loop_Entry;
13607 end Contains_Loop_Entry;
13608
13609 -- Local variables
13610
13611 Expr : Node_Id;
13612 New_Args : List_Id;
13613
13614 -- Start of processing for Assert
13615
13616 begin
13617 -- Assert is an Ada 2005 RM-defined pragma
13618
13619 if Prag_Id = Pragma_Assert then
13620 Ada_2005_Pragma;
13621
13622 -- The remaining ones are GNAT pragmas
13623
13624 else
13625 GNAT_Pragma;
13626 end if;
13627
13628 Check_At_Least_N_Arguments (1);
13629 Check_At_Most_N_Arguments (2);
13630 Check_Arg_Order ((Name_Check, Name_Message));
13631 Check_Optional_Identifier (Arg1, Name_Check);
13632 Expr := Get_Pragma_Arg (Arg1);
13633
13634 -- Special processing for Loop_Invariant, Loop_Variant or for
13635 -- other cases where a Loop_Entry attribute is present. If the
13636 -- assertion pragma contains attribute Loop_Entry, ensure that
13637 -- the related pragma is within a loop.
13638
13639 if Prag_Id = Pragma_Loop_Invariant
13640 or else Prag_Id = Pragma_Loop_Variant
13641 or else Contains_Loop_Entry (Expr)
13642 then
13643 Check_Loop_Pragma_Placement;
13644
13645 -- Perform preanalysis to deal with embedded Loop_Entry
13646 -- attributes.
13647
13648 Preanalyze_Assert_Expression (Expr, Any_Boolean);
13649 end if;
13650
13651 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
13652 -- a corresponding Check pragma:
13653
13654 -- pragma Check (name, condition [, msg]);
13655
13656 -- Where name is the identifier matching the pragma name. So
13657 -- rewrite pragma in this manner, transfer the message argument
13658 -- if present, and analyze the result
13659
13660 -- Note: When dealing with a semantically analyzed tree, the
13661 -- information that a Check node N corresponds to a source Assert,
13662 -- Assume, or Assert_And_Cut pragma can be retrieved from the
13663 -- pragma kind of Original_Node(N).
13664
13665 New_Args := New_List (
13666 Make_Pragma_Argument_Association (Loc,
13667 Expression => Make_Identifier (Loc, Pname)),
13668 Make_Pragma_Argument_Association (Sloc (Expr),
13669 Expression => Expr));
13670
13671 if Arg_Count > 1 then
13672 Check_Optional_Identifier (Arg2, Name_Message);
13673
13674 -- Provide semantic annotations for optional argument, for
13675 -- ASIS use, before rewriting.
13676 -- Is this still needed???
13677
13678 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
13679 Append_To (New_Args, New_Copy_Tree (Arg2));
13680 end if;
13681
13682 -- Rewrite as Check pragma
13683
13684 Rewrite (N,
13685 Make_Pragma (Loc,
13686 Chars => Name_Check,
13687 Pragma_Argument_Associations => New_Args));
13688
13689 Analyze (N);
13690 end Assert;
13691
13692 ----------------------
13693 -- Assertion_Policy --
13694 ----------------------
13695
13696 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
13697
13698 -- The following form is Ada 2012 only, but we allow it in all modes
13699
13700 -- Pragma Assertion_Policy (
13701 -- ASSERTION_KIND => POLICY_IDENTIFIER
13702 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
13703
13704 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
13705
13706 -- RM_ASSERTION_KIND ::= Assert |
13707 -- Static_Predicate |
13708 -- Dynamic_Predicate |
13709 -- Pre |
13710 -- Pre'Class |
13711 -- Post |
13712 -- Post'Class |
13713 -- Type_Invariant |
13714 -- Type_Invariant'Class |
13715 -- Default_Initial_Condition
13716
13717 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
13718 -- Assume |
13719 -- Contract_Cases |
13720 -- Debug |
13721 -- Ghost |
13722 -- Initial_Condition |
13723 -- Loop_Invariant |
13724 -- Loop_Variant |
13725 -- Postcondition |
13726 -- Precondition |
13727 -- Predicate |
13728 -- Refined_Post |
13729 -- Statement_Assertions |
13730 -- Subprogram_Variant
13731
13732 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
13733 -- ID_ASSERTION_KIND list contains implementation-defined additions
13734 -- recognized by GNAT. The effect is to control the behavior of
13735 -- identically named aspects and pragmas, depending on the specified
13736 -- policy identifier:
13737
13738 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
13739
13740 -- Note: Check and Ignore are language-defined. Disable is a GNAT
13741 -- implementation-defined addition that results in totally ignoring
13742 -- the corresponding assertion. If Disable is specified, then the
13743 -- argument of the assertion is not even analyzed. This is useful
13744 -- when the aspect/pragma argument references entities in a with'ed
13745 -- package that is replaced by a dummy package in the final build.
13746
13747 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
13748 -- and Type_Invariant'Class were recognized by the parser and
13749 -- transformed into references to the special internal identifiers
13750 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
13751 -- processing is required here.
13752
13753 when Pragma_Assertion_Policy => Assertion_Policy : declare
13754 procedure Resolve_Suppressible (Policy : Node_Id);
13755 -- Converts the assertion policy 'Suppressible' to either Check or
13756 -- Ignore based on whether checks are suppressed via -gnatp.
13757
13758 --------------------------
13759 -- Resolve_Suppressible --
13760 --------------------------
13761
13762 procedure Resolve_Suppressible (Policy : Node_Id) is
13763 Arg : constant Node_Id := Get_Pragma_Arg (Policy);
13764 Nam : Name_Id;
13765
13766 begin
13767 -- Transform policy argument Suppressible into either Ignore or
13768 -- Check depending on whether checks are enabled or suppressed.
13769
13770 if Chars (Arg) = Name_Suppressible then
13771 if Suppress_Checks then
13772 Nam := Name_Ignore;
13773 else
13774 Nam := Name_Check;
13775 end if;
13776
13777 Rewrite (Arg, Make_Identifier (Sloc (Arg), Nam));
13778 end if;
13779 end Resolve_Suppressible;
13780
13781 -- Local variables
13782
13783 Arg : Node_Id;
13784 Kind : Name_Id;
13785 LocP : Source_Ptr;
13786 Policy : Node_Id;
13787
13788 begin
13789 Ada_2005_Pragma;
13790
13791 -- This can always appear as a configuration pragma
13792
13793 if Is_Configuration_Pragma then
13794 null;
13795
13796 -- It can also appear in a declarative part or package spec in Ada
13797 -- 2012 mode. We allow this in other modes, but in that case we
13798 -- consider that we have an Ada 2012 pragma on our hands.
13799
13800 else
13801 Check_Is_In_Decl_Part_Or_Package_Spec;
13802 Ada_2012_Pragma;
13803 end if;
13804
13805 -- One argument case with no identifier (first form above)
13806
13807 if Arg_Count = 1
13808 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
13809 or else Chars (Arg1) = No_Name)
13810 then
13811 Check_Arg_Is_One_Of (Arg1,
13812 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13813
13814 Resolve_Suppressible (Arg1);
13815
13816 -- Treat one argument Assertion_Policy as equivalent to:
13817
13818 -- pragma Check_Policy (Assertion, policy)
13819
13820 -- So rewrite pragma in that manner and link on to the chain
13821 -- of Check_Policy pragmas, marking the pragma as analyzed.
13822
13823 Policy := Get_Pragma_Arg (Arg1);
13824
13825 Rewrite (N,
13826 Make_Pragma (Loc,
13827 Chars => Name_Check_Policy,
13828 Pragma_Argument_Associations => New_List (
13829 Make_Pragma_Argument_Association (Loc,
13830 Expression => Make_Identifier (Loc, Name_Assertion)),
13831
13832 Make_Pragma_Argument_Association (Loc,
13833 Expression =>
13834 Make_Identifier (Sloc (Policy), Chars (Policy))))));
13835 Analyze (N);
13836
13837 -- Here if we have two or more arguments
13838
13839 else
13840 Check_At_Least_N_Arguments (1);
13841 Ada_2012_Pragma;
13842
13843 -- Loop through arguments
13844
13845 Arg := Arg1;
13846 while Present (Arg) loop
13847 LocP := Sloc (Arg);
13848
13849 -- Kind must be specified
13850
13851 if Nkind (Arg) /= N_Pragma_Argument_Association
13852 or else Chars (Arg) = No_Name
13853 then
13854 Error_Pragma_Arg
13855 ("missing assertion kind for pragma%", Arg);
13856 end if;
13857
13858 -- Check Kind and Policy have allowed forms
13859
13860 Kind := Chars (Arg);
13861 Policy := Get_Pragma_Arg (Arg);
13862
13863 if not Is_Valid_Assertion_Kind (Kind) then
13864 Error_Pragma_Arg
13865 ("invalid assertion kind for pragma%", Arg);
13866 end if;
13867
13868 Check_Arg_Is_One_Of (Arg,
13869 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13870
13871 Resolve_Suppressible (Arg);
13872
13873 if Kind = Name_Ghost then
13874
13875 -- The Ghost policy must be either Check or Ignore
13876 -- (SPARK RM 6.9(6)).
13877
13878 if Chars (Policy) not in Name_Check | Name_Ignore then
13879 Error_Pragma_Arg
13880 ("argument of pragma % Ghost must be Check or "
13881 & "Ignore", Policy);
13882 end if;
13883
13884 -- Pragma Assertion_Policy specifying a Ghost policy
13885 -- cannot occur within a Ghost subprogram or package
13886 -- (SPARK RM 6.9(14)).
13887
13888 if Ghost_Mode > None then
13889 Error_Pragma
13890 ("pragma % cannot appear within ghost subprogram or "
13891 & "package");
13892 end if;
13893 end if;
13894
13895 -- Rewrite the Assertion_Policy pragma as a series of
13896 -- Check_Policy pragmas of the form:
13897
13898 -- Check_Policy (Kind, Policy);
13899
13900 -- Note: the insertion of the pragmas cannot be done with
13901 -- Insert_Action because in the configuration case, there
13902 -- are no scopes on the scope stack and the mechanism will
13903 -- fail.
13904
13905 Insert_Before_And_Analyze (N,
13906 Make_Pragma (LocP,
13907 Chars => Name_Check_Policy,
13908 Pragma_Argument_Associations => New_List (
13909 Make_Pragma_Argument_Association (LocP,
13910 Expression => Make_Identifier (LocP, Kind)),
13911 Make_Pragma_Argument_Association (LocP,
13912 Expression => Policy))));
13913
13914 Arg := Next (Arg);
13915 end loop;
13916
13917 -- Rewrite the Assertion_Policy pragma as null since we have
13918 -- now inserted all the equivalent Check pragmas.
13919
13920 Rewrite (N, Make_Null_Statement (Loc));
13921 Analyze (N);
13922 end if;
13923 end Assertion_Policy;
13924
13925 ------------------------------
13926 -- Assume_No_Invalid_Values --
13927 ------------------------------
13928
13929 -- pragma Assume_No_Invalid_Values (On | Off);
13930
13931 when Pragma_Assume_No_Invalid_Values =>
13932 GNAT_Pragma;
13933 Check_Valid_Configuration_Pragma;
13934 Check_Arg_Count (1);
13935 Check_No_Identifiers;
13936 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13937
13938 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
13939 Assume_No_Invalid_Values := True;
13940 else
13941 Assume_No_Invalid_Values := False;
13942 end if;
13943
13944 --------------------------
13945 -- Attribute_Definition --
13946 --------------------------
13947
13948 -- pragma Attribute_Definition
13949 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
13950 -- [Entity =>] LOCAL_NAME,
13951 -- [Expression =>] EXPRESSION | NAME);
13952
13953 when Pragma_Attribute_Definition => Attribute_Definition : declare
13954 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
13955 Aname : Name_Id;
13956
13957 begin
13958 GNAT_Pragma;
13959 Check_Arg_Count (3);
13960 Check_Optional_Identifier (Arg1, "attribute");
13961 Check_Optional_Identifier (Arg2, "entity");
13962 Check_Optional_Identifier (Arg3, "expression");
13963
13964 if Nkind (Attribute_Designator) /= N_Identifier then
13965 Error_Msg_N ("attribute name expected", Attribute_Designator);
13966 return;
13967 end if;
13968
13969 Check_Arg_Is_Local_Name (Arg2);
13970
13971 -- If the attribute is not recognized, then issue a warning (not
13972 -- an error), and ignore the pragma.
13973
13974 Aname := Chars (Attribute_Designator);
13975
13976 if not Is_Attribute_Name (Aname) then
13977 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
13978 return;
13979 end if;
13980
13981 -- Otherwise, rewrite the pragma as an attribute definition clause
13982
13983 Rewrite (N,
13984 Make_Attribute_Definition_Clause (Loc,
13985 Name => Get_Pragma_Arg (Arg2),
13986 Chars => Aname,
13987 Expression => Get_Pragma_Arg (Arg3)));
13988 Analyze (N);
13989 end Attribute_Definition;
13990
13991 ------------------------------------------------------------------
13992 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
13993 -- No_Caching --
13994 ------------------------------------------------------------------
13995
13996 -- pragma Async_Readers [ (boolean_EXPRESSION) ];
13997 -- pragma Async_Writers [ (boolean_EXPRESSION) ];
13998 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
13999 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
14000 -- pragma No_Caching [ (boolean_EXPRESSION) ];
14001
14002 when Pragma_Async_Readers
14003 | Pragma_Async_Writers
14004 | Pragma_Effective_Reads
14005 | Pragma_Effective_Writes
14006 | Pragma_No_Caching
14007 =>
14008 Async_Effective : declare
14009 Obj_Or_Type_Decl : Node_Id;
14010 Obj_Or_Type_Id : Entity_Id;
14011 begin
14012 GNAT_Pragma;
14013 Check_No_Identifiers;
14014 Check_At_Most_N_Arguments (1);
14015
14016 Obj_Or_Type_Decl := Find_Related_Context (N, Do_Checks => True);
14017
14018 -- Pragma must apply to a object declaration or to a type
14019 -- declaration. Original_Node is necessary to account for
14020 -- untagged derived types that are rewritten as subtypes of
14021 -- their respective root types.
14022
14023 if Nkind (Obj_Or_Type_Decl) /= N_Object_Declaration
14024 and then Nkind (Original_Node (Obj_Or_Type_Decl)) not in
14025 N_Full_Type_Declaration |
14026 N_Private_Type_Declaration |
14027 N_Formal_Type_Declaration |
14028 N_Task_Type_Declaration |
14029 N_Protected_Type_Declaration
14030 then
14031 Pragma_Misplaced;
14032 end if;
14033
14034 Obj_Or_Type_Id := Defining_Entity (Obj_Or_Type_Decl);
14035
14036 -- Perform minimal verification to ensure that the argument is at
14037 -- least an object or a type. Subsequent finer grained checks will
14038 -- be done at the end of the declarative region that contains the
14039 -- pragma.
14040
14041 if Ekind (Obj_Or_Type_Id) in E_Constant | E_Variable
14042 or else Is_Type (Obj_Or_Type_Id)
14043 then
14044
14045 -- In the case of a type, pragma is a type-related
14046 -- representation item and so requires checks common to
14047 -- all type-related representation items.
14048
14049 if Is_Type (Obj_Or_Type_Id)
14050 and then Rep_Item_Too_Late (Obj_Or_Type_Id, N)
14051 then
14052 return;
14053 end if;
14054
14055 -- A pragma that applies to a Ghost entity becomes Ghost for
14056 -- the purposes of legality checks and removal of ignored Ghost
14057 -- code.
14058
14059 Mark_Ghost_Pragma (N, Obj_Or_Type_Id);
14060
14061 -- Chain the pragma on the contract for further processing by
14062 -- Analyze_External_Property_In_Decl_Part.
14063
14064 Add_Contract_Item (N, Obj_Or_Type_Id);
14065
14066 -- Analyze the Boolean expression (if any)
14067
14068 if Present (Arg1) then
14069 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
14070 end if;
14071
14072 -- Otherwise the external property applies to a constant
14073
14074 else
14075 Error_Pragma
14076 ("pragma % must apply to a volatile type or object");
14077 end if;
14078 end Async_Effective;
14079
14080 ------------------
14081 -- Asynchronous --
14082 ------------------
14083
14084 -- pragma Asynchronous (LOCAL_NAME);
14085
14086 when Pragma_Asynchronous => Asynchronous : declare
14087 C_Ent : Entity_Id;
14088 Decl : Node_Id;
14089 Formal : Entity_Id;
14090 L : List_Id;
14091 Nm : Entity_Id;
14092 S : Node_Id;
14093
14094 procedure Process_Async_Pragma;
14095 -- Common processing for procedure and access-to-procedure case
14096
14097 --------------------------
14098 -- Process_Async_Pragma --
14099 --------------------------
14100
14101 procedure Process_Async_Pragma is
14102 begin
14103 if No (L) then
14104 Set_Is_Asynchronous (Nm);
14105 return;
14106 end if;
14107
14108 -- The formals should be of mode IN (RM E.4.1(6))
14109
14110 S := First (L);
14111 while Present (S) loop
14112 Formal := Defining_Identifier (S);
14113
14114 if Nkind (Formal) = N_Defining_Identifier
14115 and then Ekind (Formal) /= E_In_Parameter
14116 then
14117 Error_Pragma_Arg
14118 ("pragma% procedure can only have IN parameter",
14119 Arg1);
14120 end if;
14121
14122 Next (S);
14123 end loop;
14124
14125 Set_Is_Asynchronous (Nm);
14126 end Process_Async_Pragma;
14127
14128 -- Start of processing for pragma Asynchronous
14129
14130 begin
14131 Check_Ada_83_Warning;
14132 Check_No_Identifiers;
14133 Check_Arg_Count (1);
14134 Check_Arg_Is_Local_Name (Arg1);
14135
14136 if Debug_Flag_U then
14137 return;
14138 end if;
14139
14140 C_Ent := Cunit_Entity (Current_Sem_Unit);
14141 Analyze (Get_Pragma_Arg (Arg1));
14142 Nm := Entity (Get_Pragma_Arg (Arg1));
14143
14144 -- A pragma that applies to a Ghost entity becomes Ghost for the
14145 -- purposes of legality checks and removal of ignored Ghost code.
14146
14147 Mark_Ghost_Pragma (N, Nm);
14148
14149 if not Is_Remote_Call_Interface (C_Ent)
14150 and then not Is_Remote_Types (C_Ent)
14151 then
14152 -- This pragma should only appear in an RCI or Remote Types
14153 -- unit (RM E.4.1(4)).
14154
14155 Error_Pragma
14156 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
14157 end if;
14158
14159 if Ekind (Nm) = E_Procedure
14160 and then Nkind (Parent (Nm)) = N_Procedure_Specification
14161 then
14162 if not Is_Remote_Call_Interface (Nm) then
14163 Error_Pragma_Arg
14164 ("pragma% cannot be applied on non-remote procedure",
14165 Arg1);
14166 end if;
14167
14168 L := Parameter_Specifications (Parent (Nm));
14169 Process_Async_Pragma;
14170 return;
14171
14172 elsif Ekind (Nm) = E_Function then
14173 Error_Pragma_Arg
14174 ("pragma% cannot be applied to function", Arg1);
14175
14176 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
14177 if Is_Record_Type (Nm) then
14178
14179 -- A record type that is the Equivalent_Type for a remote
14180 -- access-to-subprogram type.
14181
14182 Decl := Declaration_Node (Corresponding_Remote_Type (Nm));
14183
14184 else
14185 -- A non-expanded RAS type (distribution is not enabled)
14186
14187 Decl := Declaration_Node (Nm);
14188 end if;
14189
14190 if Nkind (Decl) = N_Full_Type_Declaration
14191 and then Nkind (Type_Definition (Decl)) =
14192 N_Access_Procedure_Definition
14193 then
14194 L := Parameter_Specifications (Type_Definition (Decl));
14195 Process_Async_Pragma;
14196
14197 if Is_Asynchronous (Nm)
14198 and then Expander_Active
14199 and then Get_PCS_Name /= Name_No_DSA
14200 then
14201 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
14202 end if;
14203
14204 else
14205 Error_Pragma_Arg
14206 ("pragma% cannot reference access-to-function type",
14207 Arg1);
14208 end if;
14209
14210 -- Only other possibility is access-to-class-wide type
14211
14212 elsif Is_Access_Type (Nm)
14213 and then Is_Class_Wide_Type (Designated_Type (Nm))
14214 then
14215 Check_First_Subtype (Arg1);
14216 Set_Is_Asynchronous (Nm);
14217 if Expander_Active then
14218 RACW_Type_Is_Asynchronous (Nm);
14219 end if;
14220
14221 else
14222 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
14223 end if;
14224 end Asynchronous;
14225
14226 ------------
14227 -- Atomic --
14228 ------------
14229
14230 -- pragma Atomic (LOCAL_NAME);
14231
14232 when Pragma_Atomic =>
14233 Process_Atomic_Independent_Shared_Volatile;
14234
14235 -----------------------
14236 -- Atomic_Components --
14237 -----------------------
14238
14239 -- pragma Atomic_Components (array_LOCAL_NAME);
14240
14241 -- This processing is shared by Volatile_Components
14242
14243 when Pragma_Atomic_Components
14244 | Pragma_Volatile_Components
14245 =>
14246 Atomic_Components : declare
14247 D : Node_Id;
14248 E : Entity_Id;
14249 E_Id : Node_Id;
14250
14251 begin
14252 Check_Ada_83_Warning;
14253 Check_No_Identifiers;
14254 Check_Arg_Count (1);
14255 Check_Arg_Is_Local_Name (Arg1);
14256 E_Id := Get_Pragma_Arg (Arg1);
14257
14258 if Etype (E_Id) = Any_Type then
14259 return;
14260 end if;
14261
14262 E := Entity (E_Id);
14263
14264 -- A pragma that applies to a Ghost entity becomes Ghost for the
14265 -- purposes of legality checks and removal of ignored Ghost code.
14266
14267 Mark_Ghost_Pragma (N, E);
14268 Check_Duplicate_Pragma (E);
14269
14270 if Rep_Item_Too_Early (E, N)
14271 or else
14272 Rep_Item_Too_Late (E, N)
14273 then
14274 return;
14275 end if;
14276
14277 D := Declaration_Node (E);
14278
14279 if (Nkind (D) = N_Full_Type_Declaration and then Is_Array_Type (E))
14280 or else
14281 (Nkind (D) = N_Object_Declaration
14282 and then Ekind (E) in E_Constant | E_Variable
14283 and then Nkind (Object_Definition (D)) =
14284 N_Constrained_Array_Definition)
14285 or else
14286 (Ada_Version >= Ada_2022
14287 and then Nkind (D) = N_Formal_Type_Declaration)
14288 then
14289 -- The flag is set on the base type, or on the object
14290
14291 if Nkind (D) = N_Full_Type_Declaration then
14292 E := Base_Type (E);
14293 end if;
14294
14295 -- Atomic implies both Independent and Volatile
14296
14297 if Prag_Id = Pragma_Atomic_Components then
14298 Set_Has_Atomic_Components (E);
14299 Set_Has_Independent_Components (E);
14300 end if;
14301
14302 Set_Has_Volatile_Components (E);
14303
14304 else
14305 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
14306 end if;
14307 end Atomic_Components;
14308
14309 --------------------
14310 -- Attach_Handler --
14311 --------------------
14312
14313 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
14314
14315 when Pragma_Attach_Handler =>
14316 Check_Ada_83_Warning;
14317 Check_No_Identifiers;
14318 Check_Arg_Count (2);
14319
14320 if No_Run_Time_Mode then
14321 Error_Msg_CRT ("Attach_Handler pragma", N);
14322 else
14323 Check_Interrupt_Or_Attach_Handler;
14324
14325 -- The expression that designates the attribute may depend on a
14326 -- discriminant, and is therefore a per-object expression, to
14327 -- be expanded in the init proc. If expansion is enabled, then
14328 -- perform semantic checks on a copy only.
14329
14330 declare
14331 Temp : Node_Id;
14332 Typ : Node_Id;
14333 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
14334
14335 begin
14336 -- In Relaxed_RM_Semantics mode, we allow any static
14337 -- integer value, for compatibility with other compilers.
14338
14339 if Relaxed_RM_Semantics
14340 and then Nkind (Parg2) = N_Integer_Literal
14341 then
14342 Typ := Standard_Integer;
14343 else
14344 Typ := RTE (RE_Interrupt_ID);
14345 end if;
14346
14347 if Expander_Active then
14348 Temp := New_Copy_Tree (Parg2);
14349 Set_Parent (Temp, N);
14350 Preanalyze_And_Resolve (Temp, Typ);
14351 else
14352 Analyze (Parg2);
14353 Resolve (Parg2, Typ);
14354 end if;
14355 end;
14356
14357 Process_Interrupt_Or_Attach_Handler;
14358 end if;
14359
14360 --------------------
14361 -- C_Pass_By_Copy --
14362 --------------------
14363
14364 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
14365
14366 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
14367 Arg : Node_Id;
14368 Val : Uint;
14369
14370 begin
14371 GNAT_Pragma;
14372 Check_Valid_Configuration_Pragma;
14373 Check_Arg_Count (1);
14374 Check_Optional_Identifier (Arg1, "max_size");
14375
14376 Arg := Get_Pragma_Arg (Arg1);
14377 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
14378
14379 Val := Expr_Value (Arg);
14380
14381 if Val <= 0 then
14382 Error_Pragma_Arg
14383 ("maximum size for pragma% must be positive", Arg1);
14384
14385 elsif UI_Is_In_Int_Range (Val) then
14386 Default_C_Record_Mechanism := UI_To_Int (Val);
14387
14388 -- If a giant value is given, Int'Last will do well enough.
14389 -- If sometime someone complains that a record larger than
14390 -- two gigabytes is not copied, we will worry about it then.
14391
14392 else
14393 Default_C_Record_Mechanism := Mechanism_Type'Last;
14394 end if;
14395 end C_Pass_By_Copy;
14396
14397 -----------
14398 -- Check --
14399 -----------
14400
14401 -- pragma Check ([Name =>] CHECK_KIND,
14402 -- [Check =>] Boolean_EXPRESSION
14403 -- [,[Message =>] String_EXPRESSION]);
14404
14405 -- CHECK_KIND ::= IDENTIFIER |
14406 -- Pre'Class |
14407 -- Post'Class |
14408 -- Invariant'Class |
14409 -- Type_Invariant'Class
14410
14411 -- The identifiers Assertions and Statement_Assertions are not
14412 -- allowed, since they have special meaning for Check_Policy.
14413
14414 -- WARNING: The code below manages Ghost regions. Return statements
14415 -- must be replaced by gotos which jump to the end of the code and
14416 -- restore the Ghost mode.
14417
14418 when Pragma_Check => Check : declare
14419 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
14420 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
14421 -- Save the Ghost-related attributes to restore on exit
14422
14423 Cname : Name_Id;
14424 Eloc : Source_Ptr;
14425 Expr : Node_Id;
14426 Str : Node_Id;
14427 pragma Warnings (Off, Str);
14428
14429 begin
14430 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
14431 -- the mode now to ensure that any nodes generated during analysis
14432 -- and expansion are marked as Ghost.
14433
14434 Set_Ghost_Mode (N);
14435
14436 GNAT_Pragma;
14437 Check_At_Least_N_Arguments (2);
14438 Check_At_Most_N_Arguments (3);
14439 Check_Optional_Identifier (Arg1, Name_Name);
14440 Check_Optional_Identifier (Arg2, Name_Check);
14441
14442 if Arg_Count = 3 then
14443 Check_Optional_Identifier (Arg3, Name_Message);
14444 Str := Get_Pragma_Arg (Arg3);
14445 end if;
14446
14447 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
14448 Check_Arg_Is_Identifier (Arg1);
14449 Cname := Chars (Get_Pragma_Arg (Arg1));
14450
14451 -- Check forbidden name Assertions or Statement_Assertions
14452
14453 case Cname is
14454 when Name_Assertions =>
14455 Error_Pragma_Arg
14456 ("""Assertions"" is not allowed as a check kind for "
14457 & "pragma%", Arg1);
14458
14459 when Name_Statement_Assertions =>
14460 Error_Pragma_Arg
14461 ("""Statement_Assertions"" is not allowed as a check kind "
14462 & "for pragma%", Arg1);
14463
14464 when others =>
14465 null;
14466 end case;
14467
14468 -- Check applicable policy. We skip this if Checked/Ignored status
14469 -- is already set (e.g. in the case of a pragma from an aspect).
14470
14471 if Is_Checked (N) or else Is_Ignored (N) then
14472 null;
14473
14474 -- For a non-source pragma that is a rewriting of another pragma,
14475 -- copy the Is_Checked/Ignored status from the rewritten pragma.
14476
14477 elsif Is_Rewrite_Substitution (N)
14478 and then Nkind (Original_Node (N)) = N_Pragma
14479 then
14480 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
14481 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
14482
14483 -- Otherwise query the applicable policy at this point
14484
14485 else
14486 case Check_Kind (Cname) is
14487 when Name_Ignore =>
14488 Set_Is_Ignored (N, True);
14489 Set_Is_Checked (N, False);
14490
14491 when Name_Check =>
14492 Set_Is_Ignored (N, False);
14493 Set_Is_Checked (N, True);
14494
14495 -- For disable, rewrite pragma as null statement and skip
14496 -- rest of the analysis of the pragma.
14497
14498 when Name_Disable =>
14499 Rewrite (N, Make_Null_Statement (Loc));
14500 Analyze (N);
14501 raise Pragma_Exit;
14502
14503 -- No other possibilities
14504
14505 when others =>
14506 raise Program_Error;
14507 end case;
14508 end if;
14509
14510 -- If check kind was not Disable, then continue pragma analysis
14511
14512 Expr := Get_Pragma_Arg (Arg2);
14513
14514 -- Mark the pragma (or, if rewritten from an aspect, the original
14515 -- aspect) as enabled. Nothing to do for an internally generated
14516 -- check for a dynamic predicate.
14517
14518 if Is_Checked (N)
14519 and then not Split_PPC (N)
14520 and then Cname /= Name_Dynamic_Predicate
14521 then
14522 Set_SCO_Pragma_Enabled (Loc);
14523 end if;
14524
14525 -- Deal with analyzing the string argument. If checks are not
14526 -- on we don't want any expansion (since such expansion would
14527 -- not get properly deleted) but we do want to analyze (to get
14528 -- proper references). The Preanalyze_And_Resolve routine does
14529 -- just what we want. Ditto if pragma is active, because it will
14530 -- be rewritten as an if-statement whose analysis will complete
14531 -- analysis and expansion of the string message. This makes a
14532 -- difference in the unusual case where the expression for the
14533 -- string may have a side effect, such as raising an exception.
14534 -- This is mandated by RM 11.4.2, which specifies that the string
14535 -- expression is only evaluated if the check fails and
14536 -- Assertion_Error is to be raised.
14537
14538 if Arg_Count = 3 then
14539 Preanalyze_And_Resolve (Str, Standard_String);
14540 end if;
14541
14542 -- Now you might think we could just do the same with the Boolean
14543 -- expression if checks are off (and expansion is on) and then
14544 -- rewrite the check as a null statement. This would work but we
14545 -- would lose the useful warnings about an assertion being bound
14546 -- to fail even if assertions are turned off.
14547
14548 -- So instead we wrap the boolean expression in an if statement
14549 -- that looks like:
14550
14551 -- if False and then condition then
14552 -- null;
14553 -- end if;
14554
14555 -- The reason we do this rewriting during semantic analysis rather
14556 -- than as part of normal expansion is that we cannot analyze and
14557 -- expand the code for the boolean expression directly, or it may
14558 -- cause insertion of actions that would escape the attempt to
14559 -- suppress the check code.
14560
14561 -- Note that the Sloc for the if statement corresponds to the
14562 -- argument condition, not the pragma itself. The reason for
14563 -- this is that we may generate a warning if the condition is
14564 -- False at compile time, and we do not want to delete this
14565 -- warning when we delete the if statement.
14566
14567 if Expander_Active and Is_Ignored (N) then
14568 Eloc := Sloc (Expr);
14569
14570 Rewrite (N,
14571 Make_If_Statement (Eloc,
14572 Condition =>
14573 Make_And_Then (Eloc,
14574 Left_Opnd => Make_Identifier (Eloc, Name_False),
14575 Right_Opnd => Expr),
14576 Then_Statements => New_List (
14577 Make_Null_Statement (Eloc))));
14578
14579 -- Now go ahead and analyze the if statement
14580
14581 In_Assertion_Expr := In_Assertion_Expr + 1;
14582
14583 -- One rather special treatment. If we are now in Eliminated
14584 -- overflow mode, then suppress overflow checking since we do
14585 -- not want to drag in the bignum stuff if we are in Ignore
14586 -- mode anyway. This is particularly important if we are using
14587 -- a configurable run time that does not support bignum ops.
14588
14589 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
14590 declare
14591 Svo : constant Boolean :=
14592 Scope_Suppress.Suppress (Overflow_Check);
14593 begin
14594 Scope_Suppress.Overflow_Mode_Assertions := Strict;
14595 Scope_Suppress.Suppress (Overflow_Check) := True;
14596 Analyze (N);
14597 Scope_Suppress.Suppress (Overflow_Check) := Svo;
14598 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
14599 end;
14600
14601 -- Not that special case
14602
14603 else
14604 Analyze (N);
14605 end if;
14606
14607 -- All done with this check
14608
14609 In_Assertion_Expr := In_Assertion_Expr - 1;
14610
14611 -- Check is active or expansion not active. In these cases we can
14612 -- just go ahead and analyze the boolean with no worries.
14613
14614 else
14615 In_Assertion_Expr := In_Assertion_Expr + 1;
14616 Analyze_And_Resolve (Expr, Any_Boolean);
14617 In_Assertion_Expr := In_Assertion_Expr - 1;
14618 end if;
14619
14620 Restore_Ghost_Region (Saved_GM, Saved_IGR);
14621 end Check;
14622
14623 --------------------------
14624 -- Check_Float_Overflow --
14625 --------------------------
14626
14627 -- pragma Check_Float_Overflow;
14628
14629 when Pragma_Check_Float_Overflow =>
14630 GNAT_Pragma;
14631 Check_Valid_Configuration_Pragma;
14632 Check_Arg_Count (0);
14633 Check_Float_Overflow := not Machine_Overflows_On_Target;
14634
14635 ----------------
14636 -- Check_Name --
14637 ----------------
14638
14639 -- pragma Check_Name (check_IDENTIFIER);
14640
14641 when Pragma_Check_Name =>
14642 GNAT_Pragma;
14643 Check_No_Identifiers;
14644 Check_Valid_Configuration_Pragma;
14645 Check_Arg_Count (1);
14646 Check_Arg_Is_Identifier (Arg1);
14647
14648 declare
14649 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
14650
14651 begin
14652 for J in Check_Names.First .. Check_Names.Last loop
14653 if Check_Names.Table (J) = Nam then
14654 return;
14655 end if;
14656 end loop;
14657
14658 Check_Names.Append (Nam);
14659 end;
14660
14661 ------------------
14662 -- Check_Policy --
14663 ------------------
14664
14665 -- This is the old style syntax, which is still allowed in all modes:
14666
14667 -- pragma Check_Policy ([Name =>] CHECK_KIND
14668 -- [Policy =>] POLICY_IDENTIFIER);
14669
14670 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
14671
14672 -- CHECK_KIND ::= IDENTIFIER |
14673 -- Pre'Class |
14674 -- Post'Class |
14675 -- Type_Invariant'Class |
14676 -- Invariant'Class
14677
14678 -- This is the new style syntax, compatible with Assertion_Policy
14679 -- and also allowed in all modes.
14680
14681 -- Pragma Check_Policy (
14682 -- CHECK_KIND => POLICY_IDENTIFIER
14683 -- {, CHECK_KIND => POLICY_IDENTIFIER});
14684
14685 -- Note: the identifiers Name and Policy are not allowed as
14686 -- Check_Kind values. This avoids ambiguities between the old and
14687 -- new form syntax.
14688
14689 when Pragma_Check_Policy => Check_Policy : declare
14690 Kind : Node_Id;
14691
14692 begin
14693 GNAT_Pragma;
14694 Check_At_Least_N_Arguments (1);
14695
14696 -- A Check_Policy pragma can appear either as a configuration
14697 -- pragma, or in a declarative part or a package spec (see RM
14698 -- 11.5(5) for rules for Suppress/Unsuppress which are also
14699 -- followed for Check_Policy).
14700
14701 if not Is_Configuration_Pragma then
14702 Check_Is_In_Decl_Part_Or_Package_Spec;
14703 end if;
14704
14705 -- Figure out if we have the old or new syntax. We have the
14706 -- old syntax if the first argument has no identifier, or the
14707 -- identifier is Name.
14708
14709 if Nkind (Arg1) /= N_Pragma_Argument_Association
14710 or else Chars (Arg1) in No_Name | Name_Name
14711 then
14712 -- Old syntax
14713
14714 Check_Arg_Count (2);
14715 Check_Optional_Identifier (Arg1, Name_Name);
14716 Kind := Get_Pragma_Arg (Arg1);
14717 Rewrite_Assertion_Kind (Kind,
14718 From_Policy => Comes_From_Source (N));
14719 Check_Arg_Is_Identifier (Arg1);
14720
14721 -- Check forbidden check kind
14722
14723 if Chars (Kind) in Name_Name | Name_Policy then
14724 Error_Msg_Name_2 := Chars (Kind);
14725 Error_Pragma_Arg
14726 ("pragma% does not allow% as check name", Arg1);
14727 end if;
14728
14729 -- Check policy
14730
14731 Check_Optional_Identifier (Arg2, Name_Policy);
14732 Check_Arg_Is_One_Of
14733 (Arg2,
14734 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
14735
14736 -- And chain pragma on the Check_Policy_List for search
14737
14738 Set_Next_Pragma (N, Opt.Check_Policy_List);
14739 Opt.Check_Policy_List := N;
14740
14741 -- For the new syntax, what we do is to convert each argument to
14742 -- an old syntax equivalent. We do that because we want to chain
14743 -- old style Check_Policy pragmas for the search (we don't want
14744 -- to have to deal with multiple arguments in the search).
14745
14746 else
14747 declare
14748 Arg : Node_Id;
14749 Argx : Node_Id;
14750 LocP : Source_Ptr;
14751 New_P : Node_Id;
14752
14753 begin
14754 Arg := Arg1;
14755 while Present (Arg) loop
14756 LocP := Sloc (Arg);
14757 Argx := Get_Pragma_Arg (Arg);
14758
14759 -- Kind must be specified
14760
14761 if Nkind (Arg) /= N_Pragma_Argument_Association
14762 or else Chars (Arg) = No_Name
14763 then
14764 Error_Pragma_Arg
14765 ("missing assertion kind for pragma%", Arg);
14766 end if;
14767
14768 -- Construct equivalent old form syntax Check_Policy
14769 -- pragma and insert it to get remaining checks.
14770
14771 New_P :=
14772 Make_Pragma (LocP,
14773 Chars => Name_Check_Policy,
14774 Pragma_Argument_Associations => New_List (
14775 Make_Pragma_Argument_Association (LocP,
14776 Expression =>
14777 Make_Identifier (LocP, Chars (Arg))),
14778 Make_Pragma_Argument_Association (Sloc (Argx),
14779 Expression => Argx)));
14780
14781 Arg := Next (Arg);
14782
14783 -- For a configuration pragma, insert old form in
14784 -- the corresponding file.
14785
14786 if Is_Configuration_Pragma then
14787 Insert_After (N, New_P);
14788 Analyze (New_P);
14789
14790 else
14791 Insert_Action (N, New_P);
14792 end if;
14793 end loop;
14794
14795 -- Rewrite original Check_Policy pragma to null, since we
14796 -- have converted it into a series of old syntax pragmas.
14797
14798 Rewrite (N, Make_Null_Statement (Loc));
14799 Analyze (N);
14800 end;
14801 end if;
14802 end Check_Policy;
14803
14804 -------------
14805 -- Comment --
14806 -------------
14807
14808 -- pragma Comment (static_string_EXPRESSION)
14809
14810 -- Processing for pragma Comment shares the circuitry for pragma
14811 -- Ident. The only differences are that Ident enforces a limit of 31
14812 -- characters on its argument, and also enforces limitations on
14813 -- placement for DEC compatibility. Pragma Comment shares neither of
14814 -- these restrictions.
14815
14816 -------------------
14817 -- Common_Object --
14818 -------------------
14819
14820 -- pragma Common_Object (
14821 -- [Internal =>] LOCAL_NAME
14822 -- [, [External =>] EXTERNAL_SYMBOL]
14823 -- [, [Size =>] EXTERNAL_SYMBOL]);
14824
14825 -- Processing for this pragma is shared with Psect_Object
14826
14827 ----------------------------------------------
14828 -- Compile_Time_Error, Compile_Time_Warning --
14829 ----------------------------------------------
14830
14831 -- pragma Compile_Time_Error
14832 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14833
14834 -- pragma Compile_Time_Warning
14835 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14836
14837 when Pragma_Compile_Time_Error | Pragma_Compile_Time_Warning =>
14838 GNAT_Pragma;
14839
14840 Process_Compile_Time_Warning_Or_Error;
14841
14842 -----------------------------
14843 -- Complete_Representation --
14844 -----------------------------
14845
14846 -- pragma Complete_Representation;
14847
14848 when Pragma_Complete_Representation =>
14849 GNAT_Pragma;
14850 Check_Arg_Count (0);
14851
14852 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
14853 Error_Pragma
14854 ("pragma & must appear within record representation clause");
14855 end if;
14856
14857 ----------------------------
14858 -- Complex_Representation --
14859 ----------------------------
14860
14861 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
14862
14863 when Pragma_Complex_Representation => Complex_Representation : declare
14864 E_Id : Node_Id;
14865 E : Entity_Id;
14866 Ent : Entity_Id;
14867
14868 begin
14869 GNAT_Pragma;
14870 Check_Arg_Count (1);
14871 Check_Optional_Identifier (Arg1, Name_Entity);
14872 Check_Arg_Is_Local_Name (Arg1);
14873 E_Id := Get_Pragma_Arg (Arg1);
14874
14875 if Etype (E_Id) = Any_Type then
14876 return;
14877 end if;
14878
14879 E := Entity (E_Id);
14880
14881 if not Is_Record_Type (E) then
14882 Error_Pragma_Arg
14883 ("argument for pragma% must be record type", Arg1);
14884 end if;
14885
14886 Ent := First_Entity (E);
14887
14888 if No (Ent)
14889 or else No (Next_Entity (Ent))
14890 or else Present (Next_Entity (Next_Entity (Ent)))
14891 or else not Is_Floating_Point_Type (Etype (Ent))
14892 or else Etype (Ent) /= Etype (Next_Entity (Ent))
14893 then
14894 Error_Pragma_Arg
14895 ("record for pragma% must have two fields of the same "
14896 & "floating-point type", Arg1);
14897
14898 else
14899 Set_Has_Complex_Representation (Base_Type (E));
14900
14901 -- We need to treat the type has having a non-standard
14902 -- representation, for back-end purposes, even though in
14903 -- general a complex will have the default representation
14904 -- of a record with two real components.
14905
14906 Set_Has_Non_Standard_Rep (Base_Type (E));
14907 end if;
14908 end Complex_Representation;
14909
14910 -------------------------
14911 -- Component_Alignment --
14912 -------------------------
14913
14914 -- pragma Component_Alignment (
14915 -- [Form =>] ALIGNMENT_CHOICE
14916 -- [, [Name =>] type_LOCAL_NAME]);
14917 --
14918 -- ALIGNMENT_CHOICE ::=
14919 -- Component_Size
14920 -- | Component_Size_4
14921 -- | Storage_Unit
14922 -- | Default
14923
14924 when Pragma_Component_Alignment => Component_AlignmentP : declare
14925 Args : Args_List (1 .. 2);
14926 Names : constant Name_List (1 .. 2) := (
14927 Name_Form,
14928 Name_Name);
14929
14930 Form : Node_Id renames Args (1);
14931 Name : Node_Id renames Args (2);
14932
14933 Atype : Component_Alignment_Kind;
14934 Typ : Entity_Id;
14935
14936 begin
14937 GNAT_Pragma;
14938 Gather_Associations (Names, Args);
14939
14940 if No (Form) then
14941 Error_Pragma ("missing Form argument for pragma%");
14942 end if;
14943
14944 Check_Arg_Is_Identifier (Form);
14945
14946 -- Get proper alignment, note that Default = Component_Size on all
14947 -- machines we have so far, and we want to set this value rather
14948 -- than the default value to indicate that it has been explicitly
14949 -- set (and thus will not get overridden by the default component
14950 -- alignment for the current scope)
14951
14952 if Chars (Form) = Name_Component_Size then
14953 Atype := Calign_Component_Size;
14954
14955 elsif Chars (Form) = Name_Component_Size_4 then
14956 Atype := Calign_Component_Size_4;
14957
14958 elsif Chars (Form) = Name_Default then
14959 Atype := Calign_Component_Size;
14960
14961 elsif Chars (Form) = Name_Storage_Unit then
14962 Atype := Calign_Storage_Unit;
14963
14964 else
14965 Error_Pragma_Arg
14966 ("invalid Form parameter for pragma%", Form);
14967 end if;
14968
14969 -- The pragma appears in a configuration file
14970
14971 if No (Parent (N)) then
14972 Check_Valid_Configuration_Pragma;
14973
14974 -- Capture the component alignment in a global variable when
14975 -- the pragma appears in a configuration file. Note that the
14976 -- scope stack is empty at this point and cannot be used to
14977 -- store the alignment value.
14978
14979 Configuration_Component_Alignment := Atype;
14980
14981 -- Case with no name, supplied, affects scope table entry
14982
14983 elsif No (Name) then
14984 Scope_Stack.Table
14985 (Scope_Stack.Last).Component_Alignment_Default := Atype;
14986
14987 -- Case of name supplied
14988
14989 else
14990 Check_Arg_Is_Local_Name (Name);
14991 Find_Type (Name);
14992 Typ := Entity (Name);
14993
14994 if Typ = Any_Type
14995 or else Rep_Item_Too_Early (Typ, N)
14996 then
14997 return;
14998 else
14999 Typ := Underlying_Type (Typ);
15000 end if;
15001
15002 if not Is_Record_Type (Typ)
15003 and then not Is_Array_Type (Typ)
15004 then
15005 Error_Pragma_Arg
15006 ("Name parameter of pragma% must identify record or "
15007 & "array type", Name);
15008 end if;
15009
15010 -- An explicit Component_Alignment pragma overrides an
15011 -- implicit pragma Pack, but not an explicit one.
15012
15013 if not Has_Pragma_Pack (Base_Type (Typ)) then
15014 Set_Is_Packed (Base_Type (Typ), False);
15015 Set_Component_Alignment (Base_Type (Typ), Atype);
15016 end if;
15017 end if;
15018 end Component_AlignmentP;
15019
15020 --------------------------------
15021 -- Constant_After_Elaboration --
15022 --------------------------------
15023
15024 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
15025
15026 when Pragma_Constant_After_Elaboration => Constant_After_Elaboration :
15027 declare
15028 Obj_Decl : Node_Id;
15029 Obj_Id : Entity_Id;
15030
15031 begin
15032 GNAT_Pragma;
15033 Check_No_Identifiers;
15034 Check_At_Most_N_Arguments (1);
15035
15036 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
15037
15038 if Nkind (Obj_Decl) /= N_Object_Declaration then
15039 Pragma_Misplaced;
15040 end if;
15041
15042 Obj_Id := Defining_Entity (Obj_Decl);
15043
15044 -- The object declaration must be a library-level variable which
15045 -- is either explicitly initialized or obtains a value during the
15046 -- elaboration of a package body (SPARK RM 3.3.1).
15047
15048 if Ekind (Obj_Id) = E_Variable then
15049 if not Is_Library_Level_Entity (Obj_Id) then
15050 Error_Pragma
15051 ("pragma % must apply to a library level variable");
15052 end if;
15053
15054 -- Otherwise the pragma applies to a constant, which is illegal
15055
15056 else
15057 Error_Pragma ("pragma % must apply to a variable declaration");
15058 end if;
15059
15060 -- A pragma that applies to a Ghost entity becomes Ghost for the
15061 -- purposes of legality checks and removal of ignored Ghost code.
15062
15063 Mark_Ghost_Pragma (N, Obj_Id);
15064
15065 -- Chain the pragma on the contract for completeness
15066
15067 Add_Contract_Item (N, Obj_Id);
15068
15069 -- Analyze the Boolean expression (if any)
15070
15071 if Present (Arg1) then
15072 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
15073 end if;
15074 end Constant_After_Elaboration;
15075
15076 --------------------
15077 -- Contract_Cases --
15078 --------------------
15079
15080 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
15081
15082 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
15083
15084 -- CASE_GUARD ::= boolean_EXPRESSION | others
15085
15086 -- CONSEQUENCE ::= boolean_EXPRESSION
15087
15088 -- Characteristics:
15089
15090 -- * Analysis - The annotation undergoes initial checks to verify
15091 -- the legal placement and context. Secondary checks preanalyze the
15092 -- expressions in:
15093
15094 -- Analyze_Contract_Cases_In_Decl_Part
15095
15096 -- * Expansion - The annotation is expanded during the expansion of
15097 -- the related subprogram [body] contract as performed in:
15098
15099 -- Expand_Subprogram_Contract
15100
15101 -- * Template - The annotation utilizes the generic template of the
15102 -- related subprogram [body] when it is:
15103
15104 -- aspect on subprogram declaration
15105 -- aspect on stand-alone subprogram body
15106 -- pragma on stand-alone subprogram body
15107
15108 -- The annotation must prepare its own template when it is:
15109
15110 -- pragma on subprogram declaration
15111
15112 -- * Globals - Capture of global references must occur after full
15113 -- analysis.
15114
15115 -- * Instance - The annotation is instantiated automatically when
15116 -- the related generic subprogram [body] is instantiated except for
15117 -- the "pragma on subprogram declaration" case. In that scenario
15118 -- the annotation must instantiate itself.
15119
15120 when Pragma_Contract_Cases => Contract_Cases : declare
15121 Spec_Id : Entity_Id;
15122 Subp_Decl : Node_Id;
15123 Subp_Spec : Node_Id;
15124
15125 begin
15126 GNAT_Pragma;
15127 Check_No_Identifiers;
15128 Check_Arg_Count (1);
15129
15130 -- Ensure the proper placement of the pragma. Contract_Cases must
15131 -- be associated with a subprogram declaration or a body that acts
15132 -- as a spec.
15133
15134 Subp_Decl :=
15135 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
15136
15137 -- Entry
15138
15139 if Nkind (Subp_Decl) = N_Entry_Declaration then
15140 null;
15141
15142 -- Generic subprogram
15143
15144 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
15145 null;
15146
15147 -- Body acts as spec
15148
15149 elsif Nkind (Subp_Decl) = N_Subprogram_Body
15150 and then No (Corresponding_Spec (Subp_Decl))
15151 then
15152 null;
15153
15154 -- Body stub acts as spec
15155
15156 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
15157 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
15158 then
15159 null;
15160
15161 -- Subprogram
15162
15163 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
15164 Subp_Spec := Specification (Subp_Decl);
15165
15166 -- Pragma Contract_Cases is forbidden on null procedures, as
15167 -- this may lead to potential ambiguities in behavior when
15168 -- interface null procedures are involved.
15169
15170 if Nkind (Subp_Spec) = N_Procedure_Specification
15171 and then Null_Present (Subp_Spec)
15172 then
15173 Error_Msg_N (Fix_Error
15174 ("pragma % cannot apply to null procedure"), N);
15175 return;
15176 end if;
15177
15178 else
15179 Pragma_Misplaced;
15180 end if;
15181
15182 Spec_Id := Unique_Defining_Entity (Subp_Decl);
15183
15184 -- A pragma that applies to a Ghost entity becomes Ghost for the
15185 -- purposes of legality checks and removal of ignored Ghost code.
15186
15187 Mark_Ghost_Pragma (N, Spec_Id);
15188 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
15189
15190 -- Chain the pragma on the contract for further processing by
15191 -- Analyze_Contract_Cases_In_Decl_Part.
15192
15193 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
15194
15195 -- Fully analyze the pragma when it appears inside an entry
15196 -- or subprogram body because it cannot benefit from forward
15197 -- references.
15198
15199 if Nkind (Subp_Decl) in N_Entry_Body
15200 | N_Subprogram_Body
15201 | N_Subprogram_Body_Stub
15202 then
15203 -- The legality checks of pragma Contract_Cases are affected by
15204 -- the SPARK mode in effect and the volatility of the context.
15205 -- Analyze all pragmas in a specific order.
15206
15207 Analyze_If_Present (Pragma_SPARK_Mode);
15208 Analyze_If_Present (Pragma_Volatile_Function);
15209 Analyze_Contract_Cases_In_Decl_Part (N);
15210 end if;
15211 end Contract_Cases;
15212
15213 ----------------
15214 -- Controlled --
15215 ----------------
15216
15217 -- pragma Controlled (first_subtype_LOCAL_NAME);
15218
15219 when Pragma_Controlled => Controlled : declare
15220 Arg : Node_Id;
15221
15222 begin
15223 Check_No_Identifiers;
15224 Check_Arg_Count (1);
15225 Check_Arg_Is_Local_Name (Arg1);
15226 Arg := Get_Pragma_Arg (Arg1);
15227
15228 if not Is_Entity_Name (Arg)
15229 or else not Is_Access_Type (Entity (Arg))
15230 then
15231 Error_Pragma_Arg ("pragma% requires access type", Arg1);
15232 else
15233 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
15234 end if;
15235 end Controlled;
15236
15237 ----------------
15238 -- Convention --
15239 ----------------
15240
15241 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
15242 -- [Entity =>] LOCAL_NAME);
15243
15244 when Pragma_Convention => Convention : declare
15245 C : Convention_Id;
15246 E : Entity_Id;
15247 pragma Warnings (Off, C);
15248 pragma Warnings (Off, E);
15249
15250 begin
15251 Check_Arg_Order ((Name_Convention, Name_Entity));
15252 Check_Ada_83_Warning;
15253 Check_Arg_Count (2);
15254 Process_Convention (C, E);
15255
15256 -- A pragma that applies to a Ghost entity becomes Ghost for the
15257 -- purposes of legality checks and removal of ignored Ghost code.
15258
15259 Mark_Ghost_Pragma (N, E);
15260 end Convention;
15261
15262 ---------------------------
15263 -- Convention_Identifier --
15264 ---------------------------
15265
15266 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
15267 -- [Convention =>] convention_IDENTIFIER);
15268
15269 when Pragma_Convention_Identifier => Convention_Identifier : declare
15270 Idnam : Name_Id;
15271 Cname : Name_Id;
15272
15273 begin
15274 GNAT_Pragma;
15275 Check_Arg_Order ((Name_Name, Name_Convention));
15276 Check_Arg_Count (2);
15277 Check_Optional_Identifier (Arg1, Name_Name);
15278 Check_Optional_Identifier (Arg2, Name_Convention);
15279 Check_Arg_Is_Identifier (Arg1);
15280 Check_Arg_Is_Identifier (Arg2);
15281 Idnam := Chars (Get_Pragma_Arg (Arg1));
15282 Cname := Chars (Get_Pragma_Arg (Arg2));
15283
15284 if Is_Convention_Name (Cname) then
15285 Record_Convention_Identifier
15286 (Idnam, Get_Convention_Id (Cname));
15287 else
15288 Error_Pragma_Arg
15289 ("second arg for % pragma must be convention", Arg2);
15290 end if;
15291 end Convention_Identifier;
15292
15293 ---------------
15294 -- CPP_Class --
15295 ---------------
15296
15297 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
15298
15299 when Pragma_CPP_Class =>
15300 GNAT_Pragma;
15301
15302 if Warn_On_Obsolescent_Feature then
15303 Error_Msg_N
15304 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
15305 & "effect; replace it by pragma import?j?", N);
15306 end if;
15307
15308 Check_Arg_Count (1);
15309
15310 Rewrite (N,
15311 Make_Pragma (Loc,
15312 Chars => Name_Import,
15313 Pragma_Argument_Associations => New_List (
15314 Make_Pragma_Argument_Association (Loc,
15315 Expression => Make_Identifier (Loc, Name_CPP)),
15316 New_Copy (First (Pragma_Argument_Associations (N))))));
15317 Analyze (N);
15318
15319 ---------------------
15320 -- CPP_Constructor --
15321 ---------------------
15322
15323 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
15324 -- [, [External_Name =>] static_string_EXPRESSION ]
15325 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15326
15327 when Pragma_CPP_Constructor => CPP_Constructor : declare
15328 Id : Entity_Id;
15329 Def_Id : Entity_Id;
15330 Tag_Typ : Entity_Id;
15331
15332 begin
15333 GNAT_Pragma;
15334 Check_At_Least_N_Arguments (1);
15335 Check_At_Most_N_Arguments (3);
15336 Check_Optional_Identifier (Arg1, Name_Entity);
15337 Check_Arg_Is_Local_Name (Arg1);
15338
15339 Id := Get_Pragma_Arg (Arg1);
15340 Find_Program_Unit_Name (Id);
15341
15342 -- If we did not find the name, we are done
15343
15344 if Etype (Id) = Any_Type then
15345 return;
15346 end if;
15347
15348 Def_Id := Entity (Id);
15349
15350 -- Check if already defined as constructor
15351
15352 if Is_Constructor (Def_Id) then
15353 Error_Msg_N
15354 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
15355 return;
15356 end if;
15357
15358 if Ekind (Def_Id) = E_Function
15359 and then (Is_CPP_Class (Etype (Def_Id))
15360 or else (Is_Class_Wide_Type (Etype (Def_Id))
15361 and then
15362 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
15363 then
15364 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
15365 Error_Msg_N
15366 ("'C'P'P constructor must be defined in the scope of "
15367 & "its returned type", Arg1);
15368 end if;
15369
15370 if Arg_Count >= 2 then
15371 Set_Imported (Def_Id);
15372 Set_Is_Public (Def_Id);
15373 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
15374 end if;
15375
15376 Set_Has_Completion (Def_Id);
15377 Set_Is_Constructor (Def_Id);
15378 Set_Convention (Def_Id, Convention_CPP);
15379
15380 -- Imported C++ constructors are not dispatching primitives
15381 -- because in C++ they don't have a dispatch table slot.
15382 -- However, in Ada the constructor has the profile of a
15383 -- function that returns a tagged type and therefore it has
15384 -- been treated as a primitive operation during semantic
15385 -- analysis. We now remove it from the list of primitive
15386 -- operations of the type.
15387
15388 if Is_Tagged_Type (Etype (Def_Id))
15389 and then not Is_Class_Wide_Type (Etype (Def_Id))
15390 and then Is_Dispatching_Operation (Def_Id)
15391 then
15392 Tag_Typ := Etype (Def_Id);
15393
15394 Remove (Primitive_Operations (Tag_Typ), Def_Id);
15395 Set_Is_Dispatching_Operation (Def_Id, False);
15396 end if;
15397
15398 -- For backward compatibility, if the constructor returns a
15399 -- class wide type, and we internally change the return type to
15400 -- the corresponding root type.
15401
15402 if Is_Class_Wide_Type (Etype (Def_Id)) then
15403 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
15404 end if;
15405 else
15406 Error_Pragma_Arg
15407 ("pragma% requires function returning a 'C'P'P_Class type",
15408 Arg1);
15409 end if;
15410 end CPP_Constructor;
15411
15412 -----------------
15413 -- CPP_Virtual --
15414 -----------------
15415
15416 when Pragma_CPP_Virtual =>
15417 GNAT_Pragma;
15418
15419 if Warn_On_Obsolescent_Feature then
15420 Error_Msg_N
15421 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
15422 & "effect?j?", N);
15423 end if;
15424
15425 -----------------
15426 -- CUDA_Device --
15427 -----------------
15428
15429 when Pragma_CUDA_Device => CUDA_Device : declare
15430 Arg_Node : Node_Id;
15431 Device_Entity : Entity_Id;
15432 begin
15433 GNAT_Pragma;
15434 Check_Arg_Count (1);
15435 Check_Arg_Is_Library_Level_Local_Name (Arg1);
15436
15437 Arg_Node := Get_Pragma_Arg (Arg1);
15438 Device_Entity := Entity (Arg_Node);
15439
15440 if Ekind (Device_Entity) in E_Variable
15441 | E_Constant
15442 | E_Procedure
15443 | E_Function
15444 then
15445 Add_CUDA_Device_Entity
15446 (Package_Specification_Of_Scope (Scope (Device_Entity)),
15447 Device_Entity);
15448
15449 else
15450 Error_Msg_NE ("& must be constant, variable or subprogram",
15451 N,
15452 Device_Entity);
15453 end if;
15454
15455 end CUDA_Device;
15456
15457 ------------------
15458 -- CUDA_Execute --
15459 ------------------
15460
15461 -- pragma CUDA_Execute (PROCEDURE_CALL_STATEMENT,
15462 -- EXPRESSION,
15463 -- EXPRESSION,
15464 -- [, EXPRESSION
15465 -- [, EXPRESSION]]);
15466
15467 when Pragma_CUDA_Execute => CUDA_Execute : declare
15468
15469 function Is_Acceptable_Dim3 (N : Node_Id) return Boolean;
15470 -- Returns True if N is an acceptable argument for CUDA_Execute,
15471 -- False otherwise.
15472
15473 ------------------------
15474 -- Is_Acceptable_Dim3 --
15475 ------------------------
15476
15477 function Is_Acceptable_Dim3 (N : Node_Id) return Boolean is
15478 Expr : Node_Id;
15479 begin
15480 if Is_RTE (Etype (N), RE_Dim3)
15481 or else Is_Integer_Type (Etype (N))
15482 then
15483 return True;
15484 end if;
15485
15486 if Nkind (N) = N_Aggregate
15487 and then not Null_Record_Present (N)
15488 and then No (Component_Associations (N))
15489 and then List_Length (Expressions (N)) = 3
15490 then
15491 Expr := First (Expressions (N));
15492 while Present (Expr) loop
15493 Analyze_And_Resolve (Expr, Any_Integer);
15494 Next (Expr);
15495 end loop;
15496 return True;
15497 end if;
15498
15499 return False;
15500 end Is_Acceptable_Dim3;
15501
15502 -- Local variables
15503
15504 Block_Dimensions : constant Node_Id := Get_Pragma_Arg (Arg3);
15505 Grid_Dimensions : constant Node_Id := Get_Pragma_Arg (Arg2);
15506 Kernel_Call : constant Node_Id := Get_Pragma_Arg (Arg1);
15507 Shared_Memory : Node_Id;
15508 Stream : Node_Id;
15509
15510 -- Start of processing for CUDA_Execute
15511
15512 begin
15513 GNAT_Pragma;
15514 Check_At_Least_N_Arguments (3);
15515 Check_At_Most_N_Arguments (5);
15516
15517 Analyze_And_Resolve (Kernel_Call);
15518 if Nkind (Kernel_Call) /= N_Function_Call
15519 or else Etype (Kernel_Call) /= Standard_Void_Type
15520 then
15521 -- In `pragma CUDA_Execute (Kernel_Call (...), ...)`,
15522 -- GNAT sees Kernel_Call as an N_Function_Call since
15523 -- Kernel_Call "looks" like an expression. However, only
15524 -- procedures can be kernels, so to make things easier for the
15525 -- user the error message complains about Kernel_Call not being
15526 -- a procedure call.
15527
15528 Error_Msg_N ("first argument of & must be a procedure call", N);
15529 end if;
15530
15531 Analyze (Grid_Dimensions);
15532 if not Is_Acceptable_Dim3 (Grid_Dimensions) then
15533 Error_Msg_N
15534 ("second argument of & must be an Integer, Dim3 or aggregate "
15535 & "containing 3 Integers", N);
15536 end if;
15537
15538 Analyze (Block_Dimensions);
15539 if not Is_Acceptable_Dim3 (Block_Dimensions) then
15540 Error_Msg_N
15541 ("third argument of & must be an Integer, Dim3 or aggregate "
15542 & "containing 3 Integers", N);
15543 end if;
15544
15545 if Present (Arg4) then
15546 Shared_Memory := Get_Pragma_Arg (Arg4);
15547 Analyze_And_Resolve (Shared_Memory, Any_Integer);
15548
15549 if Present (Arg5) then
15550 Stream := Get_Pragma_Arg (Arg5);
15551 Analyze_And_Resolve (Stream, RTE (RE_Stream_T));
15552 end if;
15553 end if;
15554 end CUDA_Execute;
15555
15556 -----------------
15557 -- CUDA_Global --
15558 -----------------
15559
15560 -- pragma CUDA_Global ([Entity =>] IDENTIFIER);
15561
15562 when Pragma_CUDA_Global => CUDA_Global : declare
15563 Arg_Node : Node_Id;
15564 Kernel_Proc : Entity_Id;
15565 Pack_Id : Entity_Id;
15566 begin
15567 GNAT_Pragma;
15568 Check_Arg_Count (1);
15569 Check_Optional_Identifier (Arg1, Name_Entity);
15570 Check_Arg_Is_Local_Name (Arg1);
15571
15572 Arg_Node := Get_Pragma_Arg (Arg1);
15573 Analyze (Arg_Node);
15574
15575 Kernel_Proc := Entity (Arg_Node);
15576 Pack_Id := Scope (Kernel_Proc);
15577
15578 if Ekind (Kernel_Proc) /= E_Procedure then
15579 Error_Msg_NE ("& must be a procedure", N, Kernel_Proc);
15580
15581 elsif Ekind (Pack_Id) /= E_Package
15582 or else not Is_Library_Level_Entity (Pack_Id)
15583 then
15584 Error_Msg_NE
15585 ("& must reside in a library-level package", N, Kernel_Proc);
15586
15587 else
15588 Set_Is_CUDA_Kernel (Kernel_Proc);
15589 Add_CUDA_Kernel (Pack_Id, Kernel_Proc);
15590 end if;
15591 end CUDA_Global;
15592
15593 ----------------
15594 -- CPP_Vtable --
15595 ----------------
15596
15597 when Pragma_CPP_Vtable =>
15598 GNAT_Pragma;
15599
15600 if Warn_On_Obsolescent_Feature then
15601 Error_Msg_N
15602 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
15603 & "effect?j?", N);
15604 end if;
15605
15606 ---------
15607 -- CPU --
15608 ---------
15609
15610 -- pragma CPU (EXPRESSION);
15611
15612 when Pragma_CPU => CPU : declare
15613 P : constant Node_Id := Parent (N);
15614 Arg : Node_Id;
15615 Ent : Entity_Id;
15616
15617 begin
15618 Ada_2012_Pragma;
15619 Check_No_Identifiers;
15620 Check_Arg_Count (1);
15621 Arg := Get_Pragma_Arg (Arg1);
15622
15623 -- Subprogram case
15624
15625 if Nkind (P) = N_Subprogram_Body then
15626 Check_In_Main_Program;
15627
15628 Analyze_And_Resolve (Arg, Any_Integer);
15629
15630 Ent := Defining_Unit_Name (Specification (P));
15631
15632 if Nkind (Ent) = N_Defining_Program_Unit_Name then
15633 Ent := Defining_Identifier (Ent);
15634 end if;
15635
15636 -- Must be static
15637
15638 if not Is_OK_Static_Expression (Arg) then
15639 Flag_Non_Static_Expr
15640 ("main subprogram affinity is not static!", Arg);
15641 raise Pragma_Exit;
15642
15643 -- If constraint error, then we already signalled an error
15644
15645 elsif Raises_Constraint_Error (Arg) then
15646 null;
15647
15648 -- Otherwise check in range
15649
15650 else
15651 declare
15652 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
15653 -- This is the entity System.Multiprocessors.CPU_Range;
15654
15655 Val : constant Uint := Expr_Value (Arg);
15656
15657 begin
15658 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
15659 or else
15660 Val > Expr_Value (Type_High_Bound (CPU_Id))
15661 then
15662 Error_Pragma_Arg
15663 ("main subprogram CPU is out of range", Arg1);
15664 end if;
15665 end;
15666 end if;
15667
15668 Set_Main_CPU
15669 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
15670
15671 -- Task case
15672
15673 elsif Nkind (P) = N_Task_Definition then
15674 Ent := Defining_Identifier (Parent (P));
15675
15676 -- The expression must be analyzed in the special manner
15677 -- described in "Handling of Default and Per-Object
15678 -- Expressions" in sem.ads.
15679
15680 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
15681
15682 -- See comment in Sem_Ch13 about the following restrictions
15683
15684 if Is_OK_Static_Expression (Arg) then
15685 if Expr_Value (Arg) = Uint_0 then
15686 Check_Restriction (No_Tasks_Unassigned_To_CPU, N);
15687 end if;
15688 else
15689 Check_Restriction (No_Dynamic_CPU_Assignment, N);
15690 end if;
15691
15692 -- Anything else is incorrect
15693
15694 else
15695 Pragma_Misplaced;
15696 end if;
15697
15698 -- Check duplicate pragma before we chain the pragma in the Rep
15699 -- Item chain of Ent.
15700
15701 Check_Duplicate_Pragma (Ent);
15702 Record_Rep_Item (Ent, N);
15703 end CPU;
15704
15705 --------------------
15706 -- Deadline_Floor --
15707 --------------------
15708
15709 -- pragma Deadline_Floor (time_span_EXPRESSION);
15710
15711 when Pragma_Deadline_Floor => Deadline_Floor : declare
15712 P : constant Node_Id := Parent (N);
15713 Arg : Node_Id;
15714 Ent : Entity_Id;
15715
15716 begin
15717 GNAT_Pragma;
15718 Check_No_Identifiers;
15719 Check_Arg_Count (1);
15720
15721 Arg := Get_Pragma_Arg (Arg1);
15722
15723 -- The expression must be analyzed in the special manner described
15724 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
15725
15726 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
15727
15728 -- Only protected types allowed
15729
15730 if Nkind (P) /= N_Protected_Definition then
15731 Pragma_Misplaced;
15732
15733 else
15734 Ent := Defining_Identifier (Parent (P));
15735
15736 -- Check duplicate pragma before we chain the pragma in the Rep
15737 -- Item chain of Ent.
15738
15739 Check_Duplicate_Pragma (Ent);
15740 Record_Rep_Item (Ent, N);
15741 end if;
15742 end Deadline_Floor;
15743
15744 -----------
15745 -- Debug --
15746 -----------
15747
15748 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
15749
15750 when Pragma_Debug => Debug : declare
15751 Cond : Node_Id;
15752 Call : Node_Id;
15753
15754 begin
15755 GNAT_Pragma;
15756
15757 -- The condition for executing the call is that the expander
15758 -- is active and that we are not ignoring this debug pragma.
15759
15760 Cond :=
15761 New_Occurrence_Of
15762 (Boolean_Literals
15763 (Expander_Active and then not Is_Ignored (N)),
15764 Loc);
15765
15766 if not Is_Ignored (N) then
15767 Set_SCO_Pragma_Enabled (Loc);
15768 end if;
15769
15770 if Arg_Count = 2 then
15771 Cond :=
15772 Make_And_Then (Loc,
15773 Left_Opnd => Relocate_Node (Cond),
15774 Right_Opnd => Get_Pragma_Arg (Arg1));
15775 Call := Get_Pragma_Arg (Arg2);
15776 else
15777 Call := Get_Pragma_Arg (Arg1);
15778 end if;
15779
15780 if Nkind (Call) in N_Expanded_Name
15781 | N_Function_Call
15782 | N_Identifier
15783 | N_Indexed_Component
15784 | N_Selected_Component
15785 then
15786 -- If this pragma Debug comes from source, its argument was
15787 -- parsed as a name form (which is syntactically identical).
15788 -- In a generic context a parameterless call will be left as
15789 -- an expanded name (if global) or selected_component if local.
15790 -- Change it to a procedure call statement now.
15791
15792 Change_Name_To_Procedure_Call_Statement (Call);
15793
15794 elsif Nkind (Call) = N_Procedure_Call_Statement then
15795
15796 -- Already in the form of a procedure call statement: nothing
15797 -- to do (could happen in case of an internally generated
15798 -- pragma Debug).
15799
15800 null;
15801
15802 else
15803 -- All other cases: diagnose error
15804
15805 Error_Msg_N
15806 ("argument of pragma ""Debug"" is not procedure call", Call);
15807 return;
15808 end if;
15809
15810 -- Rewrite into a conditional with an appropriate condition. We
15811 -- wrap the procedure call in a block so that overhead from e.g.
15812 -- use of the secondary stack does not generate execution overhead
15813 -- for suppressed conditions.
15814
15815 -- Normally the analysis that follows will freeze the subprogram
15816 -- being called. However, if the call is to a null procedure,
15817 -- we want to freeze it before creating the block, because the
15818 -- analysis that follows may be done with expansion disabled, in
15819 -- which case the body will not be generated, leading to spurious
15820 -- errors.
15821
15822 if Nkind (Call) = N_Procedure_Call_Statement
15823 and then Is_Entity_Name (Name (Call))
15824 then
15825 Analyze (Name (Call));
15826 Freeze_Before (N, Entity (Name (Call)));
15827 end if;
15828
15829 Rewrite (N,
15830 Make_Implicit_If_Statement (N,
15831 Condition => Cond,
15832 Then_Statements => New_List (
15833 Make_Block_Statement (Loc,
15834 Handled_Statement_Sequence =>
15835 Make_Handled_Sequence_Of_Statements (Loc,
15836 Statements => New_List (Relocate_Node (Call)))))));
15837 Analyze (N);
15838
15839 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
15840 -- after analysis of the normally rewritten node, to capture all
15841 -- references to entities, which avoids issuing wrong warnings
15842 -- about unused entities.
15843
15844 if GNATprove_Mode then
15845 Rewrite (N, Make_Null_Statement (Loc));
15846 end if;
15847 end Debug;
15848
15849 ------------------
15850 -- Debug_Policy --
15851 ------------------
15852
15853 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
15854
15855 when Pragma_Debug_Policy =>
15856 GNAT_Pragma;
15857 Check_Arg_Count (1);
15858 Check_No_Identifiers;
15859 Check_Arg_Is_Identifier (Arg1);
15860
15861 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
15862 -- rewrite it that way, and let the rest of the checking come
15863 -- from analyzing the rewritten pragma.
15864
15865 Rewrite (N,
15866 Make_Pragma (Loc,
15867 Chars => Name_Check_Policy,
15868 Pragma_Argument_Associations => New_List (
15869 Make_Pragma_Argument_Association (Loc,
15870 Expression => Make_Identifier (Loc, Name_Debug)),
15871
15872 Make_Pragma_Argument_Association (Loc,
15873 Expression => Get_Pragma_Arg (Arg1)))));
15874 Analyze (N);
15875
15876 -------------------------------
15877 -- Default_Initial_Condition --
15878 -------------------------------
15879
15880 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
15881
15882 when Pragma_Default_Initial_Condition => DIC : declare
15883 Discard : Boolean;
15884 Stmt : Node_Id;
15885 Typ : Entity_Id;
15886
15887 begin
15888 GNAT_Pragma;
15889 Check_No_Identifiers;
15890 Check_At_Most_N_Arguments (2); -- Accounts for implicit type arg
15891
15892 Typ := Empty;
15893 Stmt := Prev (N);
15894 while Present (Stmt) loop
15895
15896 -- Skip prior pragmas, but check for duplicates
15897
15898 if Nkind (Stmt) = N_Pragma then
15899 if Pragma_Name (Stmt) = Pname then
15900 Duplication_Error
15901 (Prag => N,
15902 Prev => Stmt);
15903 raise Pragma_Exit;
15904 end if;
15905
15906 -- Skip internally generated code. Note that derived type
15907 -- declarations of untagged types with discriminants are
15908 -- rewritten as private type declarations.
15909
15910 elsif not Comes_From_Source (Stmt)
15911 and then Nkind (Stmt) /= N_Private_Type_Declaration
15912 then
15913 null;
15914
15915 -- The associated private type [extension] has been found, stop
15916 -- the search.
15917
15918 elsif Nkind (Stmt) in N_Private_Extension_Declaration
15919 | N_Private_Type_Declaration
15920 then
15921 Typ := Defining_Entity (Stmt);
15922 exit;
15923
15924 -- The pragma does not apply to a legal construct, issue an
15925 -- error and stop the analysis.
15926
15927 else
15928 Pragma_Misplaced;
15929 end if;
15930
15931 Stmt := Prev (Stmt);
15932 end loop;
15933
15934 -- The pragma does not apply to a legal construct, issue an error
15935 -- and stop the analysis.
15936
15937 if No (Typ) then
15938 Pragma_Misplaced;
15939 end if;
15940
15941 -- A pragma that applies to a Ghost entity becomes Ghost for the
15942 -- purposes of legality checks and removal of ignored Ghost code.
15943
15944 Mark_Ghost_Pragma (N, Typ);
15945
15946 -- The pragma signals that the type defines its own DIC assertion
15947 -- expression.
15948
15949 Set_Has_Own_DIC (Typ);
15950
15951 -- A type entity argument is appended to facilitate inheriting the
15952 -- aspect/pragma from parent types (see Build_DIC_Procedure_Body),
15953 -- though that extra argument isn't documented for the pragma.
15954
15955 if No (Arg2) then
15956 -- When the pragma has no arguments, create an argument with
15957 -- the value Empty, so the type name argument can be appended
15958 -- following it (since it's expected as the second argument).
15959
15960 if No (Arg1) then
15961 Set_Pragma_Argument_Associations (N, New_List (
15962 Make_Pragma_Argument_Association (Sloc (Typ),
15963 Expression => Empty)));
15964 end if;
15965
15966 Append_To
15967 (Pragma_Argument_Associations (N),
15968 Make_Pragma_Argument_Association (Sloc (Typ),
15969 Expression => New_Occurrence_Of (Typ, Sloc (Typ))));
15970 end if;
15971
15972 -- Chain the pragma on the rep item chain for further processing
15973
15974 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15975
15976 -- Create the declaration of the procedure which verifies the
15977 -- assertion expression of pragma DIC at runtime.
15978
15979 Build_DIC_Procedure_Declaration (Typ);
15980 end DIC;
15981
15982 ----------------------------------
15983 -- Default_Scalar_Storage_Order --
15984 ----------------------------------
15985
15986 -- pragma Default_Scalar_Storage_Order
15987 -- (High_Order_First | Low_Order_First);
15988
15989 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
15990 Default : Character;
15991
15992 begin
15993 GNAT_Pragma;
15994 Check_Arg_Count (1);
15995
15996 -- Default_Scalar_Storage_Order can appear as a configuration
15997 -- pragma, or in a declarative part of a package spec.
15998
15999 if not Is_Configuration_Pragma then
16000 Check_Is_In_Decl_Part_Or_Package_Spec;
16001 end if;
16002
16003 Check_No_Identifiers;
16004 Check_Arg_Is_One_Of
16005 (Arg1, Name_High_Order_First, Name_Low_Order_First);
16006 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16007 Default := Fold_Upper (Name_Buffer (1));
16008
16009 if not Support_Nondefault_SSO_On_Target
16010 and then Ttypes.Bytes_Big_Endian /= (Default = 'H')
16011 then
16012 if Warn_On_Unrecognized_Pragma then
16013 Error_Msg_N
16014 ("non-default Scalar_Storage_Order not supported "
16015 & "on target?g?", N);
16016 Error_Msg_N
16017 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
16018 end if;
16019
16020 -- Here set the specified default
16021
16022 else
16023 Opt.Default_SSO := Default;
16024 end if;
16025 end DSSO;
16026
16027 --------------------------
16028 -- Default_Storage_Pool --
16029 --------------------------
16030
16031 -- pragma Default_Storage_Pool (storage_pool_NAME | null | Standard);
16032
16033 when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
16034 Pool : Node_Id;
16035
16036 begin
16037 Ada_2012_Pragma;
16038 Check_Arg_Count (1);
16039
16040 -- Default_Storage_Pool can appear as a configuration pragma, or
16041 -- in a declarative part of a package spec.
16042
16043 if not Is_Configuration_Pragma then
16044 Check_Is_In_Decl_Part_Or_Package_Spec;
16045 end if;
16046
16047 if From_Aspect_Specification (N) then
16048 declare
16049 E : constant Entity_Id := Entity (Corresponding_Aspect (N));
16050 begin
16051 if not In_Open_Scopes (E) then
16052 Error_Msg_N
16053 ("aspect must apply to package or subprogram", N);
16054 end if;
16055 end;
16056 end if;
16057
16058 if Present (Arg1) then
16059 Pool := Get_Pragma_Arg (Arg1);
16060
16061 -- Case of Default_Storage_Pool (null);
16062
16063 if Nkind (Pool) = N_Null then
16064 Analyze (Pool);
16065
16066 -- This is an odd case, this is not really an expression,
16067 -- so we don't have a type for it. So just set the type to
16068 -- Empty.
16069
16070 Set_Etype (Pool, Empty);
16071
16072 -- Case of Default_Storage_Pool (Standard);
16073
16074 elsif Nkind (Pool) = N_Identifier
16075 and then Chars (Pool) = Name_Standard
16076 then
16077 Analyze (Pool);
16078
16079 if Entity (Pool) /= Standard_Standard then
16080 Error_Pragma_Arg
16081 ("package Standard is not directly visible", Arg1);
16082 end if;
16083
16084 -- Case of Default_Storage_Pool (storage_pool_NAME);
16085
16086 else
16087 -- If it's a configuration pragma, then the only allowed
16088 -- argument is "null".
16089
16090 if Is_Configuration_Pragma then
16091 Error_Pragma_Arg ("NULL or Standard expected", Arg1);
16092 end if;
16093
16094 -- The expected type for a non-"null" argument is
16095 -- Root_Storage_Pool'Class, and the pool must be a variable.
16096
16097 Analyze_And_Resolve
16098 (Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
16099
16100 if Is_Variable (Pool) then
16101
16102 -- A pragma that applies to a Ghost entity becomes Ghost
16103 -- for the purposes of legality checks and removal of
16104 -- ignored Ghost code.
16105
16106 Mark_Ghost_Pragma (N, Entity (Pool));
16107
16108 else
16109 Error_Pragma_Arg
16110 ("default storage pool must be a variable", Arg1);
16111 end if;
16112 end if;
16113
16114 -- Record the pool name (or null). Freeze.Freeze_Entity for an
16115 -- access type will use this information to set the appropriate
16116 -- attributes of the access type. If the pragma appears in a
16117 -- generic unit it is ignored, given that it may refer to a
16118 -- local entity.
16119
16120 if not Inside_A_Generic then
16121 Default_Pool := Pool;
16122 end if;
16123 end if;
16124 end Default_Storage_Pool;
16125
16126 -------------
16127 -- Depends --
16128 -------------
16129
16130 -- pragma Depends (DEPENDENCY_RELATION);
16131
16132 -- DEPENDENCY_RELATION ::=
16133 -- null
16134 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
16135
16136 -- DEPENDENCY_CLAUSE ::=
16137 -- OUTPUT_LIST =>[+] INPUT_LIST
16138 -- | NULL_DEPENDENCY_CLAUSE
16139
16140 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
16141
16142 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
16143
16144 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
16145
16146 -- OUTPUT ::= NAME | FUNCTION_RESULT
16147 -- INPUT ::= NAME
16148
16149 -- where FUNCTION_RESULT is a function Result attribute_reference
16150
16151 -- Characteristics:
16152
16153 -- * Analysis - The annotation undergoes initial checks to verify
16154 -- the legal placement and context. Secondary checks fully analyze
16155 -- the dependency clauses in:
16156
16157 -- Analyze_Depends_In_Decl_Part
16158
16159 -- * Expansion - None.
16160
16161 -- * Template - The annotation utilizes the generic template of the
16162 -- related subprogram [body] when it is:
16163
16164 -- aspect on subprogram declaration
16165 -- aspect on stand-alone subprogram body
16166 -- pragma on stand-alone subprogram body
16167
16168 -- The annotation must prepare its own template when it is:
16169
16170 -- pragma on subprogram declaration
16171
16172 -- * Globals - Capture of global references must occur after full
16173 -- analysis.
16174
16175 -- * Instance - The annotation is instantiated automatically when
16176 -- the related generic subprogram [body] is instantiated except for
16177 -- the "pragma on subprogram declaration" case. In that scenario
16178 -- the annotation must instantiate itself.
16179
16180 when Pragma_Depends => Depends : declare
16181 Legal : Boolean;
16182 Spec_Id : Entity_Id;
16183 Subp_Decl : Node_Id;
16184
16185 begin
16186 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
16187
16188 if Legal then
16189
16190 -- Chain the pragma on the contract for further processing by
16191 -- Analyze_Depends_In_Decl_Part.
16192
16193 Add_Contract_Item (N, Spec_Id);
16194
16195 -- Fully analyze the pragma when it appears inside an entry
16196 -- or subprogram body because it cannot benefit from forward
16197 -- references.
16198
16199 if Nkind (Subp_Decl) in N_Entry_Body
16200 | N_Subprogram_Body
16201 | N_Subprogram_Body_Stub
16202 then
16203 -- The legality checks of pragmas Depends and Global are
16204 -- affected by the SPARK mode in effect and the volatility
16205 -- of the context. In addition these two pragmas are subject
16206 -- to an inherent order:
16207
16208 -- 1) Global
16209 -- 2) Depends
16210
16211 -- Analyze all these pragmas in the order outlined above
16212
16213 Analyze_If_Present (Pragma_SPARK_Mode);
16214 Analyze_If_Present (Pragma_Volatile_Function);
16215 Analyze_If_Present (Pragma_Side_Effects);
16216 Analyze_If_Present (Pragma_Global);
16217 Analyze_Depends_In_Decl_Part (N);
16218 end if;
16219 end if;
16220 end Depends;
16221
16222 ---------------------
16223 -- Detect_Blocking --
16224 ---------------------
16225
16226 -- pragma Detect_Blocking;
16227
16228 when Pragma_Detect_Blocking =>
16229 Ada_2005_Pragma;
16230 Check_Arg_Count (0);
16231 Check_Valid_Configuration_Pragma;
16232 Detect_Blocking := True;
16233
16234 ------------------------------------
16235 -- Disable_Atomic_Synchronization --
16236 ------------------------------------
16237
16238 -- pragma Disable_Atomic_Synchronization [(Entity)];
16239
16240 when Pragma_Disable_Atomic_Synchronization =>
16241 GNAT_Pragma;
16242 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
16243
16244 -------------------
16245 -- Discard_Names --
16246 -------------------
16247
16248 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
16249
16250 when Pragma_Discard_Names => Discard_Names : declare
16251 E : Entity_Id;
16252 E_Id : Node_Id;
16253
16254 begin
16255 Check_Ada_83_Warning;
16256
16257 -- Deal with configuration pragma case
16258
16259 if Is_Configuration_Pragma then
16260 if Arg_Count /= 0 then
16261 Error_Pragma
16262 ("nonzero number of arguments for configuration pragma%");
16263 else
16264 Global_Discard_Names := True;
16265 end if;
16266 return;
16267
16268 -- Otherwise, check correct appropriate context
16269
16270 else
16271 Check_Is_In_Decl_Part_Or_Package_Spec;
16272
16273 if Arg_Count = 0 then
16274
16275 -- If there is no parameter, then from now on this pragma
16276 -- applies to any enumeration, exception or tagged type
16277 -- defined in the current declarative part, and recursively
16278 -- to any nested scope.
16279
16280 Set_Discard_Names (Current_Scope);
16281 return;
16282
16283 else
16284 Check_Arg_Count (1);
16285 Check_Optional_Identifier (Arg1, Name_On);
16286 Check_Arg_Is_Local_Name (Arg1);
16287
16288 E_Id := Get_Pragma_Arg (Arg1);
16289
16290 if Etype (E_Id) = Any_Type then
16291 return;
16292 end if;
16293
16294 E := Entity (E_Id);
16295
16296 -- A pragma that applies to a Ghost entity becomes Ghost for
16297 -- the purposes of legality checks and removal of ignored
16298 -- Ghost code.
16299
16300 Mark_Ghost_Pragma (N, E);
16301
16302 if (Is_First_Subtype (E)
16303 and then
16304 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
16305 or else Ekind (E) = E_Exception
16306 then
16307 Set_Discard_Names (E);
16308 Record_Rep_Item (E, N);
16309
16310 else
16311 Error_Pragma_Arg
16312 ("inappropriate entity for pragma%", Arg1);
16313 end if;
16314 end if;
16315 end if;
16316 end Discard_Names;
16317
16318 ------------------------
16319 -- Dispatching_Domain --
16320 ------------------------
16321
16322 -- pragma Dispatching_Domain (EXPRESSION);
16323
16324 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
16325 P : constant Node_Id := Parent (N);
16326 Arg : Node_Id;
16327 Ent : Entity_Id;
16328
16329 begin
16330 Ada_2012_Pragma;
16331 Check_No_Identifiers;
16332 Check_Arg_Count (1);
16333
16334 -- This pragma is born obsolete, but not the aspect
16335
16336 if not From_Aspect_Specification (N) then
16337 Check_Restriction
16338 (No_Obsolescent_Features, Pragma_Identifier (N));
16339 end if;
16340
16341 if Nkind (P) = N_Task_Definition then
16342 Arg := Get_Pragma_Arg (Arg1);
16343 Ent := Defining_Identifier (Parent (P));
16344
16345 -- A pragma that applies to a Ghost entity becomes Ghost for
16346 -- the purposes of legality checks and removal of ignored Ghost
16347 -- code.
16348
16349 Mark_Ghost_Pragma (N, Ent);
16350
16351 -- The expression must be analyzed in the special manner
16352 -- described in "Handling of Default and Per-Object
16353 -- Expressions" in sem.ads.
16354
16355 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
16356
16357 -- Check duplicate pragma before we chain the pragma in the Rep
16358 -- Item chain of Ent.
16359
16360 Check_Duplicate_Pragma (Ent);
16361 Record_Rep_Item (Ent, N);
16362
16363 -- Anything else is incorrect
16364
16365 else
16366 Pragma_Misplaced;
16367 end if;
16368 end Dispatching_Domain;
16369
16370 ---------------
16371 -- Elaborate --
16372 ---------------
16373
16374 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
16375
16376 when Pragma_Elaborate => Elaborate : declare
16377 Arg : Node_Id;
16378 Citem : Node_Id;
16379
16380 begin
16381 -- Pragma must be in context items list of a compilation unit
16382
16383 if not Is_In_Context_Clause then
16384 Pragma_Misplaced;
16385 end if;
16386
16387 -- Must be at least one argument
16388
16389 if Arg_Count = 0 then
16390 Error_Pragma ("pragma% requires at least one argument");
16391 end if;
16392
16393 -- In Ada 83 mode, there can be no items following it in the
16394 -- context list except other pragmas and implicit with clauses
16395 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
16396 -- placement rule does not apply.
16397
16398 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
16399 Citem := Next (N);
16400 while Present (Citem) loop
16401 if Nkind (Citem) = N_Pragma
16402 or else (Nkind (Citem) = N_With_Clause
16403 and then Implicit_With (Citem))
16404 then
16405 null;
16406 else
16407 Error_Pragma
16408 ("(Ada 83) pragma% must be at end of context clause");
16409 end if;
16410
16411 Next (Citem);
16412 end loop;
16413 end if;
16414
16415 -- Finally, the arguments must all be units mentioned in a with
16416 -- clause in the same context clause. Note we already checked (in
16417 -- Par.Prag) that the arguments are all identifiers or selected
16418 -- components.
16419
16420 Arg := Arg1;
16421 Outer : while Present (Arg) loop
16422 Citem := First (List_Containing (N));
16423 Inner : while Citem /= N loop
16424 if Nkind (Citem) = N_With_Clause
16425 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
16426 then
16427 Set_Elaborate_Present (Citem, True);
16428 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
16429
16430 -- With the pragma present, elaboration calls on
16431 -- subprograms from the named unit need no further
16432 -- checks, as long as the pragma appears in the current
16433 -- compilation unit. If the pragma appears in some unit
16434 -- in the context, there might still be a need for an
16435 -- Elaborate_All_Desirable from the current compilation
16436 -- to the named unit, so we keep the check enabled. This
16437 -- does not apply in SPARK mode, where we allow pragma
16438 -- Elaborate, but we don't trust it to be right so we
16439 -- will still insist on the Elaborate_All.
16440
16441 if Legacy_Elaboration_Checks
16442 and then In_Extended_Main_Source_Unit (N)
16443 and then SPARK_Mode /= On
16444 then
16445 Set_Suppress_Elaboration_Warnings
16446 (Entity (Name (Citem)));
16447 end if;
16448
16449 exit Inner;
16450 end if;
16451
16452 Next (Citem);
16453 end loop Inner;
16454
16455 if Citem = N then
16456 Error_Pragma_Arg
16457 ("argument of pragma% is not withed unit", Arg);
16458 end if;
16459
16460 Next (Arg);
16461 end loop Outer;
16462 end Elaborate;
16463
16464 -------------------
16465 -- Elaborate_All --
16466 -------------------
16467
16468 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
16469
16470 when Pragma_Elaborate_All => Elaborate_All : declare
16471 Arg : Node_Id;
16472 Citem : Node_Id;
16473
16474 begin
16475 Check_Ada_83_Warning;
16476
16477 -- Pragma must be in context items list of a compilation unit
16478
16479 if not Is_In_Context_Clause then
16480 Pragma_Misplaced;
16481 end if;
16482
16483 -- Must be at least one argument
16484
16485 if Arg_Count = 0 then
16486 Error_Pragma ("pragma% requires at least one argument");
16487 end if;
16488
16489 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
16490 -- have to appear at the end of the context clause, but may
16491 -- appear mixed in with other items, even in Ada 83 mode.
16492
16493 -- Final check: the arguments must all be units mentioned in
16494 -- a with clause in the same context clause. Note that we
16495 -- already checked (in Par.Prag) that all the arguments are
16496 -- either identifiers or selected components.
16497
16498 Arg := Arg1;
16499 Outr : while Present (Arg) loop
16500 Citem := First (List_Containing (N));
16501 Innr : while Citem /= N loop
16502 if Nkind (Citem) = N_With_Clause
16503 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
16504 then
16505 Set_Elaborate_All_Present (Citem, True);
16506 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
16507
16508 -- Suppress warnings and elaboration checks on the named
16509 -- unit if the pragma is in the current compilation, as
16510 -- for pragma Elaborate.
16511
16512 if Legacy_Elaboration_Checks
16513 and then In_Extended_Main_Source_Unit (N)
16514 then
16515 Set_Suppress_Elaboration_Warnings
16516 (Entity (Name (Citem)));
16517 end if;
16518
16519 exit Innr;
16520 end if;
16521
16522 Next (Citem);
16523 end loop Innr;
16524
16525 if Citem = N then
16526 Error_Pragma_Arg
16527 ("argument of pragma% is not withed unit", Arg);
16528 end if;
16529
16530 Next (Arg);
16531 end loop Outr;
16532 end Elaborate_All;
16533
16534 --------------------
16535 -- Elaborate_Body --
16536 --------------------
16537
16538 -- pragma Elaborate_Body [( library_unit_NAME )];
16539
16540 when Pragma_Elaborate_Body => Elaborate_Body : declare
16541 Cunit_Node : Node_Id;
16542 Cunit_Ent : Entity_Id;
16543
16544 begin
16545 Check_Ada_83_Warning;
16546 Check_Valid_Library_Unit_Pragma;
16547
16548 -- If N was rewritten as a null statement there is nothing more
16549 -- to do.
16550
16551 if Nkind (N) = N_Null_Statement then
16552 return;
16553 end if;
16554
16555 Cunit_Node := Cunit (Current_Sem_Unit);
16556 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
16557
16558 -- A pragma that applies to a Ghost entity becomes Ghost for the
16559 -- purposes of legality checks and removal of ignored Ghost code.
16560
16561 Mark_Ghost_Pragma (N, Cunit_Ent);
16562
16563 if Nkind (Unit (Cunit_Node)) in
16564 N_Package_Body | N_Subprogram_Body
16565 then
16566 Error_Pragma ("pragma% must refer to a spec, not a body");
16567 else
16568 Set_Body_Required (Cunit_Node);
16569 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
16570
16571 -- If we are in dynamic elaboration mode, then we suppress
16572 -- elaboration warnings for the unit, since it is definitely
16573 -- fine NOT to do dynamic checks at the first level (and such
16574 -- checks will be suppressed because no elaboration boolean
16575 -- is created for Elaborate_Body packages).
16576 --
16577 -- But in the static model of elaboration, Elaborate_Body is
16578 -- definitely NOT good enough to ensure elaboration safety on
16579 -- its own, since the body may WITH other units that are not
16580 -- safe from an elaboration point of view, so a client must
16581 -- still do an Elaborate_All on such units.
16582 --
16583 -- Debug flag -gnatdD restores the old behavior of 3.13, where
16584 -- Elaborate_Body always suppressed elab warnings.
16585
16586 if Legacy_Elaboration_Checks
16587 and then (Dynamic_Elaboration_Checks or Debug_Flag_DD)
16588 then
16589 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
16590 end if;
16591 end if;
16592 end Elaborate_Body;
16593
16594 ------------------------
16595 -- Elaboration_Checks --
16596 ------------------------
16597
16598 -- pragma Elaboration_Checks (Static | Dynamic);
16599
16600 when Pragma_Elaboration_Checks => Elaboration_Checks : declare
16601 procedure Check_Duplicate_Elaboration_Checks_Pragma;
16602 -- Emit an error if the current context list already contains
16603 -- a previous Elaboration_Checks pragma. This routine raises
16604 -- Pragma_Exit if a duplicate is found.
16605
16606 procedure Ignore_Elaboration_Checks_Pragma;
16607 -- Warn that the effects of the pragma are ignored. This routine
16608 -- raises Pragma_Exit.
16609
16610 -----------------------------------------------
16611 -- Check_Duplicate_Elaboration_Checks_Pragma --
16612 -----------------------------------------------
16613
16614 procedure Check_Duplicate_Elaboration_Checks_Pragma is
16615 Item : Node_Id;
16616
16617 begin
16618 Item := Prev (N);
16619 while Present (Item) loop
16620 if Nkind (Item) = N_Pragma
16621 and then Pragma_Name (Item) = Name_Elaboration_Checks
16622 then
16623 Duplication_Error
16624 (Prag => N,
16625 Prev => Item);
16626 raise Pragma_Exit;
16627 end if;
16628
16629 Prev (Item);
16630 end loop;
16631 end Check_Duplicate_Elaboration_Checks_Pragma;
16632
16633 --------------------------------------
16634 -- Ignore_Elaboration_Checks_Pragma --
16635 --------------------------------------
16636
16637 procedure Ignore_Elaboration_Checks_Pragma is
16638 begin
16639 Error_Msg_Name_1 := Pname;
16640 Error_Msg_N ("??effects of pragma % are ignored", N);
16641 Error_Msg_N
16642 ("\place pragma on initial declaration of library unit", N);
16643
16644 raise Pragma_Exit;
16645 end Ignore_Elaboration_Checks_Pragma;
16646
16647 -- Local variables
16648
16649 Context : constant Node_Id := Parent (N);
16650 Unt : Node_Id;
16651
16652 -- Start of processing for Elaboration_Checks
16653
16654 begin
16655 GNAT_Pragma;
16656 Check_Arg_Count (1);
16657 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
16658
16659 -- The pragma appears in a configuration file
16660
16661 if No (Context) then
16662 Check_Valid_Configuration_Pragma;
16663 Check_Duplicate_Elaboration_Checks_Pragma;
16664
16665 -- The pragma acts as a configuration pragma in a compilation unit
16666
16667 -- pragma Elaboration_Checks (...);
16668 -- package Pack is ...;
16669
16670 elsif Nkind (Context) = N_Compilation_Unit
16671 and then List_Containing (N) = Context_Items (Context)
16672 then
16673 Check_Valid_Configuration_Pragma;
16674 Check_Duplicate_Elaboration_Checks_Pragma;
16675
16676 Unt := Unit (Context);
16677
16678 -- The pragma must appear on the initial declaration of a unit.
16679 -- If this is not the case, warn that the effects of the pragma
16680 -- are ignored.
16681
16682 if Nkind (Unt) = N_Package_Body then
16683 Ignore_Elaboration_Checks_Pragma;
16684
16685 -- Check the Acts_As_Spec flag of the compilation units itself
16686 -- to determine whether the subprogram body completes since it
16687 -- has not been analyzed yet. This is safe because compilation
16688 -- units are not overloadable.
16689
16690 elsif Nkind (Unt) = N_Subprogram_Body
16691 and then not Acts_As_Spec (Context)
16692 then
16693 Ignore_Elaboration_Checks_Pragma;
16694
16695 elsif Nkind (Unt) = N_Subunit then
16696 Ignore_Elaboration_Checks_Pragma;
16697 end if;
16698
16699 -- Otherwise the pragma does not appear at the configuration level
16700 -- and is illegal.
16701
16702 else
16703 Pragma_Misplaced;
16704 end if;
16705
16706 -- At this point the pragma is not a duplicate, and appears in the
16707 -- proper context. Set the elaboration model in effect.
16708
16709 Dynamic_Elaboration_Checks :=
16710 Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic;
16711 end Elaboration_Checks;
16712
16713 ---------------
16714 -- Eliminate --
16715 ---------------
16716
16717 -- pragma Eliminate (
16718 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
16719 -- [Entity =>] IDENTIFIER |
16720 -- SELECTED_COMPONENT |
16721 -- STRING_LITERAL]
16722 -- [, Source_Location => SOURCE_TRACE]);
16723
16724 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
16725 -- SOURCE_TRACE ::= STRING_LITERAL
16726
16727 when Pragma_Eliminate => Eliminate : declare
16728 Args : Args_List (1 .. 5);
16729 Names : constant Name_List (1 .. 5) := (
16730 Name_Unit_Name,
16731 Name_Entity,
16732 Name_Parameter_Types,
16733 Name_Result_Type,
16734 Name_Source_Location);
16735
16736 -- Note : Parameter_Types and Result_Type are leftovers from
16737 -- prior implementations of the pragma. They are not generated
16738 -- by the gnatelim tool, and play no role in selecting which
16739 -- of a set of overloaded names is chosen for elimination.
16740
16741 Unit_Name : Node_Id renames Args (1);
16742 Entity : Node_Id renames Args (2);
16743 Parameter_Types : Node_Id renames Args (3);
16744 Result_Type : Node_Id renames Args (4);
16745 Source_Location : Node_Id renames Args (5);
16746
16747 begin
16748 GNAT_Pragma;
16749 Check_Valid_Configuration_Pragma;
16750 Gather_Associations (Names, Args);
16751
16752 if No (Unit_Name) then
16753 Error_Pragma ("missing Unit_Name argument for pragma%");
16754 end if;
16755
16756 if No (Entity)
16757 and then (Present (Parameter_Types)
16758 or else
16759 Present (Result_Type)
16760 or else
16761 Present (Source_Location))
16762 then
16763 Error_Pragma ("missing Entity argument for pragma%");
16764 end if;
16765
16766 if (Present (Parameter_Types)
16767 or else
16768 Present (Result_Type))
16769 and then
16770 Present (Source_Location)
16771 then
16772 Error_Pragma
16773 ("parameter profile and source location cannot be used "
16774 & "together in pragma%");
16775 end if;
16776
16777 Process_Eliminate_Pragma
16778 (N,
16779 Unit_Name,
16780 Entity,
16781 Parameter_Types,
16782 Result_Type,
16783 Source_Location);
16784 end Eliminate;
16785
16786 -----------------------------------
16787 -- Enable_Atomic_Synchronization --
16788 -----------------------------------
16789
16790 -- pragma Enable_Atomic_Synchronization [(Entity)];
16791
16792 when Pragma_Enable_Atomic_Synchronization =>
16793 GNAT_Pragma;
16794 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
16795
16796 -----------------------
16797 -- Exceptional_Cases --
16798 -----------------------
16799
16800 -- pragma Exceptional_Cases ( EXCEPTIONAL_CONTRACT_LIST );
16801
16802 -- EXCEPTIONAL_CONTRACT_LIST ::=
16803 -- ( EXCEPTIONAL_CONTRACT {, EXCEPTIONAL_CONTRACT })
16804
16805 -- EXCEPTIONAL_CONTRACT ::=
16806 -- EXCEPTION_CHOICE {'|' EXCEPTION_CHOICE} => CONSEQUENCE
16807 --
16808 -- where
16809 --
16810 -- CONSEQUENCE ::= boolean_EXPRESSION
16811
16812 -- Characteristics:
16813
16814 -- * Analysis - The annotation undergoes initial checks to verify
16815 -- the legal placement and context. Secondary checks preanalyze the
16816 -- expressions in:
16817
16818 -- Analyze_Exceptional_Cases_In_Decl_Part
16819
16820 -- * Expansion - The annotation is expanded during the expansion of
16821 -- the related subprogram [body] contract as performed in:
16822
16823 -- Expand_Subprogram_Contract
16824
16825 -- * Template - The annotation utilizes the generic template of the
16826 -- related subprogram [body] when it is:
16827
16828 -- aspect on subprogram declaration
16829 -- aspect on stand-alone subprogram body
16830 -- pragma on stand-alone subprogram body
16831
16832 -- The annotation must prepare its own template when it is:
16833
16834 -- pragma on subprogram declaration
16835
16836 -- * Globals - Capture of global references must occur after full
16837 -- analysis.
16838
16839 -- * Instance - The annotation is instantiated automatically when
16840 -- the related generic subprogram [body] is instantiated except for
16841 -- the "pragma on subprogram declaration" case. In that scenario
16842 -- the annotation must instantiate itself.
16843
16844 when Pragma_Exceptional_Cases => Exceptional_Cases : declare
16845 Spec_Id : Entity_Id;
16846 Subp_Decl : Node_Id;
16847 Subp_Spec : Node_Id;
16848
16849 begin
16850 GNAT_Pragma;
16851 Check_No_Identifiers;
16852 Check_Arg_Count (1);
16853
16854 -- Ensure the proper placement of the pragma. Exceptional_Cases
16855 -- must be associated with a subprogram declaration or a body that
16856 -- acts as a spec.
16857
16858 Subp_Decl :=
16859 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
16860
16861 -- Generic subprogram
16862
16863 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
16864 null;
16865
16866 -- Body acts as spec
16867
16868 elsif Nkind (Subp_Decl) = N_Subprogram_Body
16869 and then No (Corresponding_Spec (Subp_Decl))
16870 then
16871 null;
16872
16873 -- Body stub acts as spec
16874
16875 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
16876 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
16877 then
16878 null;
16879
16880 -- Subprogram
16881
16882 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
16883 Subp_Spec := Specification (Subp_Decl);
16884
16885 -- Pragma Exceptional_Cases is forbidden on null procedures,
16886 -- as this may lead to potential ambiguities in behavior when
16887 -- interface null procedures are involved. Also, it just
16888 -- wouldn't make sense, because null procedures do not raise
16889 -- exceptions.
16890
16891 if Nkind (Subp_Spec) = N_Procedure_Specification
16892 and then Null_Present (Subp_Spec)
16893 then
16894 Error_Msg_N (Fix_Error
16895 ("pragma % cannot apply to null procedure"), N);
16896 return;
16897 end if;
16898
16899 else
16900 Pragma_Misplaced;
16901 end if;
16902
16903 Spec_Id := Unique_Defining_Entity (Subp_Decl);
16904
16905 -- In order to call Is_Function_With_Side_Effects, analyze pragma
16906 -- Side_Effects if present.
16907
16908 Analyze_If_Present (Pragma_Side_Effects);
16909
16910 -- Pragma Exceptional_Cases is not allowed on functions without
16911 -- side effects.
16912
16913 if Ekind (Spec_Id) in E_Function | E_Generic_Function
16914 and then not Is_Function_With_Side_Effects (Spec_Id)
16915 then
16916 Error_Msg_Sloc := GEC_Exceptional_Cases_On_Function;
16917
16918 if Ekind (Spec_Id) = E_Function then
16919 Error_Msg_N (Fix_Error
16920 ("pragma % cannot apply to function '[[]']"), N);
16921 return;
16922
16923 elsif Ekind (Spec_Id) = E_Generic_Function then
16924 Error_Msg_N (Fix_Error
16925 ("pragma % cannot apply to generic function '[[]']"), N);
16926 return;
16927 end if;
16928 end if;
16929
16930 -- A pragma that applies to a Ghost entity becomes Ghost for the
16931 -- purposes of legality checks and removal of ignored Ghost code.
16932
16933 Mark_Ghost_Pragma (N, Spec_Id);
16934 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
16935
16936 -- Chain the pragma on the contract for further processing by
16937 -- Analyze_Exceptional_Cases_In_Decl_Part.
16938
16939 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
16940
16941 -- Fully analyze the pragma when it appears inside a subprogram
16942 -- body because it cannot benefit from forward references.
16943
16944 if Nkind (Subp_Decl) in N_Subprogram_Body
16945 | N_Subprogram_Body_Stub
16946 then
16947 -- The legality checks of pragma Exceptional_Cases are
16948 -- affected by the SPARK mode in effect and the volatility
16949 -- of the context. Analyze all pragmas in a specific order.
16950
16951 Analyze_If_Present (Pragma_SPARK_Mode);
16952 Analyze_If_Present (Pragma_Volatile_Function);
16953 Analyze_Exceptional_Cases_In_Decl_Part (N);
16954 end if;
16955 end Exceptional_Cases;
16956
16957 ------------
16958 -- Export --
16959 ------------
16960
16961 -- pragma Export (
16962 -- [ Convention =>] convention_IDENTIFIER,
16963 -- [ Entity =>] LOCAL_NAME
16964 -- [, [External_Name =>] static_string_EXPRESSION ]
16965 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16966
16967 when Pragma_Export => Export : declare
16968 C : Convention_Id;
16969 Def_Id : Entity_Id;
16970
16971 pragma Warnings (Off, C);
16972
16973 begin
16974 Check_Ada_83_Warning;
16975 Check_Arg_Order
16976 ((Name_Convention,
16977 Name_Entity,
16978 Name_External_Name,
16979 Name_Link_Name));
16980
16981 Check_At_Least_N_Arguments (2);
16982 Check_At_Most_N_Arguments (4);
16983
16984 -- In Relaxed_RM_Semantics, support old Ada 83 style:
16985 -- pragma Export (Entity, "external name");
16986
16987 if Relaxed_RM_Semantics
16988 and then Arg_Count = 2
16989 and then Nkind (Expression (Arg2)) = N_String_Literal
16990 then
16991 C := Convention_C;
16992 Def_Id := Get_Pragma_Arg (Arg1);
16993 Analyze (Def_Id);
16994
16995 if not Is_Entity_Name (Def_Id) then
16996 Error_Pragma_Arg ("entity name required", Arg1);
16997 end if;
16998
16999 Def_Id := Entity (Def_Id);
17000 Set_Exported (Def_Id, Arg1);
17001
17002 else
17003 Process_Convention (C, Def_Id);
17004
17005 -- A pragma that applies to a Ghost entity becomes Ghost for
17006 -- the purposes of legality checks and removal of ignored Ghost
17007 -- code.
17008
17009 Mark_Ghost_Pragma (N, Def_Id);
17010
17011 if Ekind (Def_Id) /= E_Constant then
17012 Note_Possible_Modification
17013 (Get_Pragma_Arg (Arg2), Sure => False);
17014 end if;
17015
17016 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
17017 Set_Exported (Def_Id, Arg2);
17018 end if;
17019
17020 -- If the entity is a deferred constant, propagate the information
17021 -- to the full view, because gigi elaborates the full view only.
17022
17023 if Ekind (Def_Id) = E_Constant
17024 and then Present (Full_View (Def_Id))
17025 then
17026 declare
17027 Id2 : constant Entity_Id := Full_View (Def_Id);
17028 begin
17029 Set_Is_Exported (Id2, Is_Exported (Def_Id));
17030 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
17031 Set_Interface_Name
17032 (Id2, Einfo.Entities.Interface_Name (Def_Id));
17033 end;
17034 end if;
17035 end Export;
17036
17037 ---------------------
17038 -- Export_Function --
17039 ---------------------
17040
17041 -- pragma Export_Function (
17042 -- [Internal =>] LOCAL_NAME
17043 -- [, [External =>] EXTERNAL_SYMBOL]
17044 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17045 -- [, [Result_Type =>] TYPE_DESIGNATOR]
17046 -- [, [Mechanism =>] MECHANISM]
17047 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
17048
17049 -- EXTERNAL_SYMBOL ::=
17050 -- IDENTIFIER
17051 -- | static_string_EXPRESSION
17052
17053 -- PARAMETER_TYPES ::=
17054 -- null
17055 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17056
17057 -- TYPE_DESIGNATOR ::=
17058 -- subtype_NAME
17059 -- | subtype_Name ' Access
17060
17061 -- MECHANISM ::=
17062 -- MECHANISM_NAME
17063 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17064
17065 -- MECHANISM_ASSOCIATION ::=
17066 -- [formal_parameter_NAME =>] MECHANISM_NAME
17067
17068 -- MECHANISM_NAME ::=
17069 -- Value
17070 -- | Reference
17071
17072 when Pragma_Export_Function => Export_Function : declare
17073 Args : Args_List (1 .. 6);
17074 Names : constant Name_List (1 .. 6) := (
17075 Name_Internal,
17076 Name_External,
17077 Name_Parameter_Types,
17078 Name_Result_Type,
17079 Name_Mechanism,
17080 Name_Result_Mechanism);
17081
17082 Internal : Node_Id renames Args (1);
17083 External : Node_Id renames Args (2);
17084 Parameter_Types : Node_Id renames Args (3);
17085 Result_Type : Node_Id renames Args (4);
17086 Mechanism : Node_Id renames Args (5);
17087 Result_Mechanism : Node_Id renames Args (6);
17088
17089 begin
17090 GNAT_Pragma;
17091 Gather_Associations (Names, Args);
17092 Process_Extended_Import_Export_Subprogram_Pragma (
17093 Arg_Internal => Internal,
17094 Arg_External => External,
17095 Arg_Parameter_Types => Parameter_Types,
17096 Arg_Result_Type => Result_Type,
17097 Arg_Mechanism => Mechanism,
17098 Arg_Result_Mechanism => Result_Mechanism);
17099 end Export_Function;
17100
17101 -------------------
17102 -- Export_Object --
17103 -------------------
17104
17105 -- pragma Export_Object (
17106 -- [Internal =>] LOCAL_NAME
17107 -- [, [External =>] EXTERNAL_SYMBOL]
17108 -- [, [Size =>] EXTERNAL_SYMBOL]);
17109
17110 -- EXTERNAL_SYMBOL ::=
17111 -- IDENTIFIER
17112 -- | static_string_EXPRESSION
17113
17114 -- PARAMETER_TYPES ::=
17115 -- null
17116 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17117
17118 -- TYPE_DESIGNATOR ::=
17119 -- subtype_NAME
17120 -- | subtype_Name ' Access
17121
17122 -- MECHANISM ::=
17123 -- MECHANISM_NAME
17124 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17125
17126 -- MECHANISM_ASSOCIATION ::=
17127 -- [formal_parameter_NAME =>] MECHANISM_NAME
17128
17129 -- MECHANISM_NAME ::=
17130 -- Value
17131 -- | Reference
17132
17133 when Pragma_Export_Object => Export_Object : declare
17134 Args : Args_List (1 .. 3);
17135 Names : constant Name_List (1 .. 3) := (
17136 Name_Internal,
17137 Name_External,
17138 Name_Size);
17139
17140 Internal : Node_Id renames Args (1);
17141 External : Node_Id renames Args (2);
17142 Size : Node_Id renames Args (3);
17143
17144 begin
17145 GNAT_Pragma;
17146 Gather_Associations (Names, Args);
17147 Process_Extended_Import_Export_Object_Pragma (
17148 Arg_Internal => Internal,
17149 Arg_External => External,
17150 Arg_Size => Size);
17151 end Export_Object;
17152
17153 ----------------------
17154 -- Export_Procedure --
17155 ----------------------
17156
17157 -- pragma Export_Procedure (
17158 -- [Internal =>] LOCAL_NAME
17159 -- [, [External =>] EXTERNAL_SYMBOL]
17160 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17161 -- [, [Mechanism =>] MECHANISM]);
17162
17163 -- EXTERNAL_SYMBOL ::=
17164 -- IDENTIFIER
17165 -- | static_string_EXPRESSION
17166
17167 -- PARAMETER_TYPES ::=
17168 -- null
17169 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17170
17171 -- TYPE_DESIGNATOR ::=
17172 -- subtype_NAME
17173 -- | subtype_Name ' Access
17174
17175 -- MECHANISM ::=
17176 -- MECHANISM_NAME
17177 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17178
17179 -- MECHANISM_ASSOCIATION ::=
17180 -- [formal_parameter_NAME =>] MECHANISM_NAME
17181
17182 -- MECHANISM_NAME ::=
17183 -- Value
17184 -- | Reference
17185
17186 when Pragma_Export_Procedure => Export_Procedure : declare
17187 Args : Args_List (1 .. 4);
17188 Names : constant Name_List (1 .. 4) := (
17189 Name_Internal,
17190 Name_External,
17191 Name_Parameter_Types,
17192 Name_Mechanism);
17193
17194 Internal : Node_Id renames Args (1);
17195 External : Node_Id renames Args (2);
17196 Parameter_Types : Node_Id renames Args (3);
17197 Mechanism : Node_Id renames Args (4);
17198
17199 begin
17200 GNAT_Pragma;
17201 Gather_Associations (Names, Args);
17202 Process_Extended_Import_Export_Subprogram_Pragma (
17203 Arg_Internal => Internal,
17204 Arg_External => External,
17205 Arg_Parameter_Types => Parameter_Types,
17206 Arg_Mechanism => Mechanism);
17207 end Export_Procedure;
17208
17209 -----------------------------
17210 -- Export_Valued_Procedure --
17211 -----------------------------
17212
17213 -- pragma Export_Valued_Procedure (
17214 -- [Internal =>] LOCAL_NAME
17215 -- [, [External =>] EXTERNAL_SYMBOL,]
17216 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17217 -- [, [Mechanism =>] MECHANISM]);
17218
17219 -- EXTERNAL_SYMBOL ::=
17220 -- IDENTIFIER
17221 -- | static_string_EXPRESSION
17222
17223 -- PARAMETER_TYPES ::=
17224 -- null
17225 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17226
17227 -- TYPE_DESIGNATOR ::=
17228 -- subtype_NAME
17229 -- | subtype_Name ' Access
17230
17231 -- MECHANISM ::=
17232 -- MECHANISM_NAME
17233 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17234
17235 -- MECHANISM_ASSOCIATION ::=
17236 -- [formal_parameter_NAME =>] MECHANISM_NAME
17237
17238 -- MECHANISM_NAME ::=
17239 -- Value
17240 -- | Reference
17241
17242 when Pragma_Export_Valued_Procedure =>
17243 Export_Valued_Procedure : declare
17244 Args : Args_List (1 .. 4);
17245 Names : constant Name_List (1 .. 4) := (
17246 Name_Internal,
17247 Name_External,
17248 Name_Parameter_Types,
17249 Name_Mechanism);
17250
17251 Internal : Node_Id renames Args (1);
17252 External : Node_Id renames Args (2);
17253 Parameter_Types : Node_Id renames Args (3);
17254 Mechanism : Node_Id renames Args (4);
17255
17256 begin
17257 GNAT_Pragma;
17258 Gather_Associations (Names, Args);
17259 Process_Extended_Import_Export_Subprogram_Pragma (
17260 Arg_Internal => Internal,
17261 Arg_External => External,
17262 Arg_Parameter_Types => Parameter_Types,
17263 Arg_Mechanism => Mechanism);
17264 end Export_Valued_Procedure;
17265
17266 -------------------
17267 -- Extend_System --
17268 -------------------
17269
17270 -- pragma Extend_System ([Name =>] Identifier);
17271
17272 when Pragma_Extend_System =>
17273 GNAT_Pragma;
17274 Check_Valid_Configuration_Pragma;
17275 Check_Arg_Count (1);
17276 Check_Optional_Identifier (Arg1, Name_Name);
17277 Check_Arg_Is_Identifier (Arg1);
17278
17279 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
17280
17281 if Name_Len > 4
17282 and then Name_Buffer (1 .. 4) = "aux_"
17283 then
17284 if Present (System_Extend_Pragma_Arg) then
17285 if Chars (Get_Pragma_Arg (Arg1)) =
17286 Chars (Expression (System_Extend_Pragma_Arg))
17287 then
17288 null;
17289 else
17290 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
17291 Error_Pragma ("pragma% conflicts with that #");
17292 end if;
17293
17294 else
17295 System_Extend_Pragma_Arg := Arg1;
17296
17297 if not GNAT_Mode then
17298 System_Extend_Unit := Arg1;
17299 end if;
17300 end if;
17301 else
17302 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
17303 end if;
17304
17305 ------------------------
17306 -- Extensions_Allowed --
17307 ------------------------
17308
17309 -- pragma Extensions_Allowed (ON | OFF | ALL);
17310
17311 when Pragma_Extensions_Allowed =>
17312 GNAT_Pragma;
17313 Check_Arg_Count (1);
17314 Check_No_Identifiers;
17315 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off, Name_All);
17316
17317 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
17318 Ada_Version := Ada_With_Core_Extensions;
17319 elsif Chars (Get_Pragma_Arg (Arg1)) = Name_All then
17320 Ada_Version := Ada_With_All_Extensions;
17321 else
17322 Ada_Version := Ada_Version_Explicit;
17323 Ada_Version_Pragma := Empty;
17324 end if;
17325
17326 ------------------------
17327 -- Extensions_Visible --
17328 ------------------------
17329
17330 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
17331
17332 -- Characteristics:
17333
17334 -- * Analysis - The annotation is fully analyzed immediately upon
17335 -- elaboration as its expression must be static.
17336
17337 -- * Expansion - None.
17338
17339 -- * Template - The annotation utilizes the generic template of the
17340 -- related subprogram [body] when it is:
17341
17342 -- aspect on subprogram declaration
17343 -- aspect on stand-alone subprogram body
17344 -- pragma on stand-alone subprogram body
17345
17346 -- The annotation must prepare its own template when it is:
17347
17348 -- pragma on subprogram declaration
17349
17350 -- * Globals - Capture of global references must occur after full
17351 -- analysis.
17352
17353 -- * Instance - The annotation is instantiated automatically when
17354 -- the related generic subprogram [body] is instantiated except for
17355 -- the "pragma on subprogram declaration" case. In that scenario
17356 -- the annotation must instantiate itself.
17357
17358 when Pragma_Extensions_Visible => Extensions_Visible : declare
17359 Formal : Entity_Id;
17360 Has_OK_Formal : Boolean := False;
17361 Spec_Id : Entity_Id;
17362 Subp_Decl : Node_Id;
17363
17364 begin
17365 GNAT_Pragma;
17366 Check_No_Identifiers;
17367 Check_At_Most_N_Arguments (1);
17368
17369 Subp_Decl :=
17370 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
17371
17372 -- Abstract subprogram declaration
17373
17374 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
17375 null;
17376
17377 -- Generic subprogram declaration
17378
17379 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
17380 null;
17381
17382 -- Body acts as spec
17383
17384 elsif Nkind (Subp_Decl) = N_Subprogram_Body
17385 and then No (Corresponding_Spec (Subp_Decl))
17386 then
17387 null;
17388
17389 -- Body stub acts as spec
17390
17391 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
17392 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
17393 then
17394 null;
17395
17396 -- Subprogram declaration
17397
17398 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
17399 null;
17400
17401 -- Otherwise the pragma is associated with an illegal construct
17402
17403 else
17404 Error_Pragma ("pragma % must apply to a subprogram");
17405 end if;
17406
17407 -- Mark the pragma as Ghost if the related subprogram is also
17408 -- Ghost. This also ensures that any expansion performed further
17409 -- below will produce Ghost nodes.
17410
17411 Spec_Id := Unique_Defining_Entity (Subp_Decl);
17412 Mark_Ghost_Pragma (N, Spec_Id);
17413
17414 -- Chain the pragma on the contract for completeness
17415
17416 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
17417
17418 -- The legality checks of pragma Extension_Visible are affected
17419 -- by the SPARK mode in effect. Analyze all pragmas in specific
17420 -- order.
17421
17422 Analyze_If_Present (Pragma_SPARK_Mode);
17423
17424 -- Examine the formals of the related subprogram
17425
17426 Formal := First_Formal (Spec_Id);
17427 while Present (Formal) loop
17428
17429 -- At least one of the formals is of a specific tagged type,
17430 -- the pragma is legal.
17431
17432 if Is_Specific_Tagged_Type (Etype (Formal)) then
17433 Has_OK_Formal := True;
17434 exit;
17435
17436 -- A generic subprogram with at least one formal of a private
17437 -- type ensures the legality of the pragma because the actual
17438 -- may be specifically tagged. Note that this is verified by
17439 -- the check above at instantiation time.
17440
17441 elsif Is_Private_Type (Etype (Formal))
17442 and then Is_Generic_Type (Etype (Formal))
17443 then
17444 Has_OK_Formal := True;
17445 exit;
17446 end if;
17447
17448 Next_Formal (Formal);
17449 end loop;
17450
17451 if not Has_OK_Formal then
17452 Error_Msg_Name_1 := Pname;
17453 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
17454 Error_Msg_NE
17455 ("\subprogram & lacks parameter of specific tagged or "
17456 & "generic private type", N, Spec_Id);
17457
17458 return;
17459 end if;
17460
17461 -- Analyze the Boolean expression (if any)
17462
17463 if Present (Arg1) then
17464 Check_Static_Boolean_Expression
17465 (Expression (Get_Argument (N, Spec_Id)));
17466 end if;
17467 end Extensions_Visible;
17468
17469 --------------
17470 -- External --
17471 --------------
17472
17473 -- pragma External (
17474 -- [ Convention =>] convention_IDENTIFIER,
17475 -- [ Entity =>] LOCAL_NAME
17476 -- [, [External_Name =>] static_string_EXPRESSION ]
17477 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17478
17479 when Pragma_External => External : declare
17480 C : Convention_Id;
17481 E : Entity_Id;
17482 pragma Warnings (Off, C);
17483
17484 begin
17485 GNAT_Pragma;
17486 Check_Arg_Order
17487 ((Name_Convention,
17488 Name_Entity,
17489 Name_External_Name,
17490 Name_Link_Name));
17491 Check_At_Least_N_Arguments (2);
17492 Check_At_Most_N_Arguments (4);
17493 Process_Convention (C, E);
17494
17495 -- A pragma that applies to a Ghost entity becomes Ghost for the
17496 -- purposes of legality checks and removal of ignored Ghost code.
17497
17498 Mark_Ghost_Pragma (N, E);
17499
17500 Note_Possible_Modification
17501 (Get_Pragma_Arg (Arg2), Sure => False);
17502 Process_Interface_Name (E, Arg3, Arg4, N);
17503 Set_Exported (E, Arg2);
17504 end External;
17505
17506 --------------------------
17507 -- External_Name_Casing --
17508 --------------------------
17509
17510 -- pragma External_Name_Casing (
17511 -- UPPERCASE | LOWERCASE
17512 -- [, AS_IS | UPPERCASE | LOWERCASE]);
17513
17514 when Pragma_External_Name_Casing =>
17515 GNAT_Pragma;
17516 Check_No_Identifiers;
17517
17518 if Arg_Count = 2 then
17519 Check_Arg_Is_One_Of
17520 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
17521
17522 case Chars (Get_Pragma_Arg (Arg2)) is
17523 when Name_As_Is =>
17524 Opt.External_Name_Exp_Casing := As_Is;
17525
17526 when Name_Uppercase =>
17527 Opt.External_Name_Exp_Casing := Uppercase;
17528
17529 when Name_Lowercase =>
17530 Opt.External_Name_Exp_Casing := Lowercase;
17531
17532 when others =>
17533 null;
17534 end case;
17535
17536 else
17537 Check_Arg_Count (1);
17538 end if;
17539
17540 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
17541
17542 case Chars (Get_Pragma_Arg (Arg1)) is
17543 when Name_Uppercase =>
17544 Opt.External_Name_Imp_Casing := Uppercase;
17545
17546 when Name_Lowercase =>
17547 Opt.External_Name_Imp_Casing := Lowercase;
17548
17549 when others =>
17550 null;
17551 end case;
17552
17553 ---------------
17554 -- Fast_Math --
17555 ---------------
17556
17557 -- pragma Fast_Math;
17558
17559 when Pragma_Fast_Math =>
17560 GNAT_Pragma;
17561 Check_No_Identifiers;
17562 Check_Valid_Configuration_Pragma;
17563 Fast_Math := True;
17564
17565 --------------------------
17566 -- Favor_Top_Level --
17567 --------------------------
17568
17569 -- pragma Favor_Top_Level (type_NAME);
17570
17571 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
17572 Typ : Entity_Id;
17573
17574 begin
17575 GNAT_Pragma;
17576 Check_No_Identifiers;
17577 Check_Arg_Count (1);
17578 Check_Arg_Is_Local_Name (Arg1);
17579 Typ := Entity (Get_Pragma_Arg (Arg1));
17580
17581 -- A pragma that applies to a Ghost entity becomes Ghost for the
17582 -- purposes of legality checks and removal of ignored Ghost code.
17583
17584 Mark_Ghost_Pragma (N, Typ);
17585
17586 -- If it's an access-to-subprogram type (in particular, not a
17587 -- subtype), set the flag on that type.
17588
17589 if Is_Access_Subprogram_Type (Typ) then
17590 Set_Can_Use_Internal_Rep (Typ, False);
17591
17592 -- Otherwise it's an error (name denotes the wrong sort of entity)
17593
17594 else
17595 Error_Pragma_Arg
17596 ("access-to-subprogram type expected",
17597 Get_Pragma_Arg (Arg1));
17598 end if;
17599 end Favor_Top_Level;
17600
17601 ---------------------------
17602 -- Finalize_Storage_Only --
17603 ---------------------------
17604
17605 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
17606
17607 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
17608 Assoc : constant Node_Id := Arg1;
17609 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
17610 Typ : Entity_Id;
17611
17612 begin
17613 GNAT_Pragma;
17614 Check_No_Identifiers;
17615 Check_Arg_Count (1);
17616 Check_Arg_Is_Local_Name (Arg1);
17617
17618 Find_Type (Type_Id);
17619 Typ := Entity (Type_Id);
17620
17621 if Typ = Any_Type
17622 or else Rep_Item_Too_Early (Typ, N)
17623 then
17624 return;
17625 else
17626 Typ := Underlying_Type (Typ);
17627 end if;
17628
17629 if not Is_Controlled (Typ) then
17630 Error_Pragma ("pragma% must specify controlled type");
17631 end if;
17632
17633 Check_First_Subtype (Arg1);
17634
17635 if Finalize_Storage_Only (Typ) then
17636 Error_Pragma ("duplicate pragma%, only one allowed");
17637
17638 elsif not Rep_Item_Too_Late (Typ, N) then
17639 Set_Finalize_Storage_Only (Base_Type (Typ), True);
17640 end if;
17641 end Finalize_Storage;
17642
17643 -----------
17644 -- Ghost --
17645 -----------
17646
17647 -- pragma Ghost [ (boolean_EXPRESSION) ];
17648
17649 when Pragma_Ghost => Ghost : declare
17650 Context : Node_Id;
17651 Expr : Node_Id;
17652 Id : Entity_Id;
17653 Orig_Stmt : Node_Id;
17654 Prev_Id : Entity_Id;
17655 Stmt : Node_Id;
17656
17657 begin
17658 GNAT_Pragma;
17659 Check_No_Identifiers;
17660 Check_At_Most_N_Arguments (1);
17661
17662 Id := Empty;
17663 Stmt := Prev (N);
17664 while Present (Stmt) loop
17665
17666 -- Skip prior pragmas, but check for duplicates
17667
17668 if Nkind (Stmt) = N_Pragma then
17669 if Pragma_Name (Stmt) = Pname then
17670 Duplication_Error
17671 (Prag => N,
17672 Prev => Stmt);
17673 raise Pragma_Exit;
17674 end if;
17675
17676 -- Task unit declared without a definition cannot be subject to
17677 -- pragma Ghost (SPARK RM 6.9(19)).
17678
17679 elsif Nkind (Stmt) in
17680 N_Single_Task_Declaration | N_Task_Type_Declaration
17681 then
17682 Error_Pragma ("pragma % cannot apply to a task type");
17683
17684 -- Skip internally generated code
17685
17686 elsif not Comes_From_Source (Stmt) then
17687 Orig_Stmt := Original_Node (Stmt);
17688
17689 -- When pragma Ghost applies to an untagged derivation, the
17690 -- derivation is transformed into a [sub]type declaration.
17691
17692 if Nkind (Stmt) in
17693 N_Full_Type_Declaration | N_Subtype_Declaration
17694 and then Comes_From_Source (Orig_Stmt)
17695 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
17696 and then Nkind (Type_Definition (Orig_Stmt)) =
17697 N_Derived_Type_Definition
17698 then
17699 Id := Defining_Entity (Stmt);
17700 exit;
17701
17702 -- When pragma Ghost applies to an object declaration which
17703 -- is initialized by means of a function call that returns
17704 -- on the secondary stack, the object declaration becomes a
17705 -- renaming.
17706
17707 elsif Nkind (Stmt) = N_Object_Renaming_Declaration
17708 and then Comes_From_Source (Orig_Stmt)
17709 and then Nkind (Orig_Stmt) = N_Object_Declaration
17710 then
17711 Id := Defining_Entity (Stmt);
17712 exit;
17713
17714 -- When pragma Ghost applies to an expression function, the
17715 -- expression function is transformed into a subprogram.
17716
17717 elsif Nkind (Stmt) = N_Subprogram_Declaration
17718 and then Comes_From_Source (Orig_Stmt)
17719 and then Nkind (Orig_Stmt) = N_Expression_Function
17720 then
17721 Id := Defining_Entity (Stmt);
17722 exit;
17723
17724 -- When pragma Ghost applies to a generic formal type, the
17725 -- type declaration in the instantiation is a generated
17726 -- subtype declaration.
17727
17728 elsif Nkind (Stmt) = N_Subtype_Declaration
17729 and then Present (Generic_Parent_Type (Stmt))
17730 then
17731 Id := Defining_Entity (Stmt);
17732 exit;
17733 end if;
17734
17735 -- The pragma applies to a legal construct, stop the traversal
17736
17737 elsif Nkind (Stmt) in N_Abstract_Subprogram_Declaration
17738 | N_Formal_Object_Declaration
17739 | N_Formal_Subprogram_Declaration
17740 | N_Formal_Type_Declaration
17741 | N_Full_Type_Declaration
17742 | N_Generic_Subprogram_Declaration
17743 | N_Object_Declaration
17744 | N_Private_Extension_Declaration
17745 | N_Private_Type_Declaration
17746 | N_Subprogram_Declaration
17747 | N_Subtype_Declaration
17748 then
17749 Id := Defining_Entity (Stmt);
17750 exit;
17751
17752 -- The pragma does not apply to a legal construct, issue an
17753 -- error and stop the analysis.
17754
17755 else
17756 Error_Pragma
17757 ("pragma % must apply to an object, package, subprogram "
17758 & "or type");
17759 end if;
17760
17761 Stmt := Prev (Stmt);
17762 end loop;
17763
17764 Context := Parent (N);
17765
17766 -- Handle compilation units
17767
17768 if Nkind (Context) = N_Compilation_Unit_Aux then
17769 Context := Unit (Parent (Context));
17770 end if;
17771
17772 -- Protected and task types cannot be subject to pragma Ghost
17773 -- (SPARK RM 6.9(19)).
17774
17775 if Nkind (Context) in N_Protected_Body | N_Protected_Definition
17776 then
17777 Error_Pragma ("pragma % cannot apply to a protected type");
17778
17779 elsif Nkind (Context) in N_Task_Body | N_Task_Definition then
17780 Error_Pragma ("pragma % cannot apply to a task type");
17781 end if;
17782
17783 if No (Id) then
17784
17785 -- When pragma Ghost is associated with a [generic] package, it
17786 -- appears in the visible declarations.
17787
17788 if Nkind (Context) = N_Package_Specification
17789 and then Present (Visible_Declarations (Context))
17790 and then List_Containing (N) = Visible_Declarations (Context)
17791 then
17792 Id := Defining_Entity (Context);
17793
17794 -- Pragma Ghost applies to a stand-alone subprogram body
17795
17796 elsif Nkind (Context) = N_Subprogram_Body
17797 and then No (Corresponding_Spec (Context))
17798 then
17799 Id := Defining_Entity (Context);
17800
17801 -- Pragma Ghost applies to a subprogram declaration that acts
17802 -- as a compilation unit.
17803
17804 elsif Nkind (Context) = N_Subprogram_Declaration then
17805 Id := Defining_Entity (Context);
17806
17807 -- Pragma Ghost applies to a generic subprogram
17808
17809 elsif Nkind (Context) = N_Generic_Subprogram_Declaration then
17810 Id := Defining_Entity (Specification (Context));
17811 end if;
17812 end if;
17813
17814 if No (Id) then
17815 Error_Pragma
17816 ("pragma % must apply to an object, package, subprogram or "
17817 & "type");
17818 end if;
17819
17820 -- Handle completions of types and constants that are subject to
17821 -- pragma Ghost.
17822
17823 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
17824 Prev_Id := Incomplete_Or_Partial_View (Id);
17825
17826 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
17827 Error_Msg_Name_1 := Pname;
17828
17829 -- The full declaration of a deferred constant cannot be
17830 -- subject to pragma Ghost unless the deferred declaration
17831 -- is also Ghost (SPARK RM 6.9(9)).
17832
17833 if Ekind (Prev_Id) = E_Constant then
17834 Error_Msg_Name_1 := Pname;
17835 Error_Msg_NE (Fix_Error
17836 ("pragma % must apply to declaration of deferred "
17837 & "constant &"), N, Id);
17838 return;
17839
17840 -- Pragma Ghost may appear on the full view of an incomplete
17841 -- type because the incomplete declaration lacks aspects and
17842 -- cannot be subject to pragma Ghost.
17843
17844 elsif Ekind (Prev_Id) = E_Incomplete_Type then
17845 null;
17846
17847 -- The full declaration of a type cannot be subject to
17848 -- pragma Ghost unless the partial view is also Ghost
17849 -- (SPARK RM 6.9(9)).
17850
17851 else
17852 Error_Msg_NE (Fix_Error
17853 ("pragma % must apply to partial view of type &"),
17854 N, Id);
17855 return;
17856 end if;
17857 end if;
17858
17859 -- A synchronized object cannot be subject to pragma Ghost
17860 -- (SPARK RM 6.9(19)).
17861
17862 elsif Ekind (Id) = E_Variable then
17863 if Is_Protected_Type (Etype (Id)) then
17864 Error_Pragma ("pragma % cannot apply to a protected object");
17865
17866 elsif Is_Task_Type (Etype (Id)) then
17867 Error_Pragma ("pragma % cannot apply to a task object");
17868 end if;
17869 end if;
17870
17871 -- Analyze the Boolean expression (if any)
17872
17873 if Present (Arg1) then
17874 Expr := Get_Pragma_Arg (Arg1);
17875
17876 Analyze_And_Resolve (Expr, Standard_Boolean);
17877
17878 if Is_OK_Static_Expression (Expr) then
17879
17880 -- "Ghostness" cannot be turned off once enabled within a
17881 -- region (SPARK RM 6.9(6)).
17882
17883 if Is_False (Expr_Value (Expr))
17884 and then Ghost_Mode > None
17885 then
17886 Error_Pragma
17887 ("pragma % with value False cannot appear in enabled "
17888 & "ghost region");
17889 end if;
17890
17891 -- Otherwise the expression is not static
17892
17893 else
17894 Error_Pragma_Arg
17895 ("expression of pragma % must be static", Expr);
17896 end if;
17897 end if;
17898
17899 Set_Is_Ghost_Entity (Id);
17900 end Ghost;
17901
17902 ------------
17903 -- Global --
17904 ------------
17905
17906 -- pragma Global (GLOBAL_SPECIFICATION);
17907
17908 -- GLOBAL_SPECIFICATION ::=
17909 -- null
17910 -- | (GLOBAL_LIST)
17911 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
17912
17913 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
17914
17915 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
17916 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
17917 -- GLOBAL_ITEM ::= NAME
17918
17919 -- Characteristics:
17920
17921 -- * Analysis - The annotation undergoes initial checks to verify
17922 -- the legal placement and context. Secondary checks fully analyze
17923 -- the dependency clauses in:
17924
17925 -- Analyze_Global_In_Decl_Part
17926
17927 -- * Expansion - None.
17928
17929 -- * Template - The annotation utilizes the generic template of the
17930 -- related subprogram [body] when it is:
17931
17932 -- aspect on subprogram declaration
17933 -- aspect on stand-alone subprogram body
17934 -- pragma on stand-alone subprogram body
17935
17936 -- The annotation must prepare its own template when it is:
17937
17938 -- pragma on subprogram declaration
17939
17940 -- * Globals - Capture of global references must occur after full
17941 -- analysis.
17942
17943 -- * Instance - The annotation is instantiated automatically when
17944 -- the related generic subprogram [body] is instantiated except for
17945 -- the "pragma on subprogram declaration" case. In that scenario
17946 -- the annotation must instantiate itself.
17947
17948 when Pragma_Global => Global : declare
17949 Legal : Boolean;
17950 Spec_Id : Entity_Id;
17951 Subp_Decl : Node_Id;
17952
17953 begin
17954 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
17955
17956 if Legal then
17957
17958 -- Chain the pragma on the contract for further processing by
17959 -- Analyze_Global_In_Decl_Part.
17960
17961 Add_Contract_Item (N, Spec_Id);
17962
17963 -- Fully analyze the pragma when it appears inside an entry
17964 -- or subprogram body because it cannot benefit from forward
17965 -- references.
17966
17967 if Nkind (Subp_Decl) in N_Entry_Body
17968 | N_Subprogram_Body
17969 | N_Subprogram_Body_Stub
17970 then
17971 -- The legality checks of pragmas Depends and Global are
17972 -- affected by the SPARK mode in effect and the volatility
17973 -- of the context. In addition these two pragmas are subject
17974 -- to an inherent order:
17975
17976 -- 1) Global
17977 -- 2) Depends
17978
17979 -- Analyze all these pragmas in the order outlined above
17980
17981 Analyze_If_Present (Pragma_SPARK_Mode);
17982 Analyze_If_Present (Pragma_Volatile_Function);
17983 Analyze_If_Present (Pragma_Side_Effects);
17984 Analyze_Global_In_Decl_Part (N);
17985 Analyze_If_Present (Pragma_Depends);
17986 end if;
17987 end if;
17988 end Global;
17989
17990 -----------
17991 -- Ident --
17992 -----------
17993
17994 -- pragma Ident (static_string_EXPRESSION)
17995
17996 -- Note: pragma Comment shares this processing. Pragma Ident is
17997 -- identical in effect to pragma Commment.
17998
17999 when Pragma_Comment
18000 | Pragma_Ident
18001 =>
18002 Ident : declare
18003 Str : Node_Id;
18004
18005 begin
18006 GNAT_Pragma;
18007 Check_Arg_Count (1);
18008 Check_No_Identifiers;
18009 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18010 Store_Note (N);
18011
18012 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
18013
18014 declare
18015 CS : Node_Id;
18016 GP : Node_Id;
18017
18018 begin
18019 GP := Parent (Parent (N));
18020
18021 if Nkind (GP) in
18022 N_Package_Declaration | N_Generic_Package_Declaration
18023 then
18024 GP := Parent (GP);
18025 end if;
18026
18027 -- If we have a compilation unit, then record the ident value,
18028 -- checking for improper duplication.
18029
18030 if Nkind (GP) = N_Compilation_Unit then
18031 CS := Ident_String (Current_Sem_Unit);
18032
18033 if Present (CS) then
18034
18035 -- If we have multiple instances, concatenate them.
18036
18037 Start_String (Strval (CS));
18038 Store_String_Char (' ');
18039 Store_String_Chars (Strval (Str));
18040 Set_Strval (CS, End_String);
18041
18042 else
18043 Set_Ident_String (Current_Sem_Unit, Str);
18044 end if;
18045
18046 -- For subunits, we just ignore the Ident, since in GNAT these
18047 -- are not separate object files, and hence not separate units
18048 -- in the unit table.
18049
18050 elsif Nkind (GP) = N_Subunit then
18051 null;
18052 end if;
18053 end;
18054 end Ident;
18055
18056 -------------------
18057 -- Ignore_Pragma --
18058 -------------------
18059
18060 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
18061
18062 -- Entirely handled in the parser, nothing to do here
18063
18064 when Pragma_Ignore_Pragma =>
18065 null;
18066
18067 ----------------------------
18068 -- Implementation_Defined --
18069 ----------------------------
18070
18071 -- pragma Implementation_Defined (LOCAL_NAME);
18072
18073 -- Marks previously declared entity as implementation defined. For
18074 -- an overloaded entity, applies to the most recent homonym.
18075
18076 -- pragma Implementation_Defined;
18077
18078 -- The form with no arguments appears anywhere within a scope, most
18079 -- typically a package spec, and indicates that all entities that are
18080 -- defined within the package spec are Implementation_Defined.
18081
18082 when Pragma_Implementation_Defined => Implementation_Defined : declare
18083 Ent : Entity_Id;
18084
18085 begin
18086 GNAT_Pragma;
18087 Check_No_Identifiers;
18088
18089 -- Form with no arguments
18090
18091 if Arg_Count = 0 then
18092 Set_Is_Implementation_Defined (Current_Scope);
18093
18094 -- Form with one argument
18095
18096 else
18097 Check_Arg_Count (1);
18098 Check_Arg_Is_Local_Name (Arg1);
18099 Ent := Entity (Get_Pragma_Arg (Arg1));
18100 Set_Is_Implementation_Defined (Ent);
18101 end if;
18102 end Implementation_Defined;
18103
18104 -----------------
18105 -- Implemented --
18106 -----------------
18107
18108 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
18109
18110 -- IMPLEMENTATION_KIND ::=
18111 -- By_Entry | By_Protected_Procedure | By_Any | Optional
18112
18113 -- "By_Any" and "Optional" are treated as synonyms in order to
18114 -- support Ada 2012 aspect Synchronization.
18115
18116 when Pragma_Implemented => Implemented : declare
18117 Proc_Id : Entity_Id;
18118 Typ : Entity_Id;
18119
18120 begin
18121 Ada_2012_Pragma;
18122 Check_Arg_Count (2);
18123 Check_No_Identifiers;
18124 Check_Arg_Is_Identifier (Arg1);
18125 Check_Arg_Is_Local_Name (Arg1);
18126 Check_Arg_Is_One_Of (Arg2,
18127 Name_By_Any,
18128 Name_By_Entry,
18129 Name_By_Protected_Procedure,
18130 Name_Optional);
18131
18132 -- Extract the name of the local procedure
18133
18134 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
18135
18136 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
18137 -- primitive procedure of a synchronized tagged type.
18138
18139 if Ekind (Proc_Id) = E_Procedure
18140 and then Is_Primitive (Proc_Id)
18141 and then Present (First_Formal (Proc_Id))
18142 then
18143 Typ := Etype (First_Formal (Proc_Id));
18144
18145 if Is_Tagged_Type (Typ)
18146 and then
18147
18148 -- Check for a protected, a synchronized or a task interface
18149
18150 ((Is_Interface (Typ)
18151 and then Is_Synchronized_Interface (Typ))
18152
18153 -- Check for a protected type or a task type that implements
18154 -- an interface.
18155
18156 or else
18157 (Is_Concurrent_Record_Type (Typ)
18158 and then Present (Interfaces (Typ)))
18159
18160 -- In analysis-only mode, examine original protected type
18161
18162 or else
18163 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
18164 and then Present (Interface_List (Parent (Typ))))
18165
18166 -- Check for a private record extension with keyword
18167 -- "synchronized".
18168
18169 or else
18170 (Ekind (Typ) in E_Record_Type_With_Private
18171 | E_Record_Subtype_With_Private
18172 and then Synchronized_Present (Parent (Typ))))
18173 then
18174 null;
18175 else
18176 Error_Pragma_Arg
18177 ("controlling formal must be of synchronized tagged type",
18178 Arg1);
18179 end if;
18180
18181 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
18182 -- By_Protected_Procedure to the primitive procedure of a task
18183 -- interface.
18184
18185 if Chars (Get_Pragma_Arg (Arg2)) = Name_By_Protected_Procedure
18186 and then Is_Interface (Typ)
18187 and then Is_Task_Interface (Typ)
18188 then
18189 Error_Pragma_Arg
18190 ("implementation kind By_Protected_Procedure cannot be "
18191 & "applied to a task interface primitive", Arg2);
18192 end if;
18193
18194 -- Procedures declared inside a protected type must be accepted
18195
18196 elsif Ekind (Proc_Id) = E_Procedure
18197 and then Is_Protected_Type (Scope (Proc_Id))
18198 then
18199 null;
18200
18201 -- The first argument is not a primitive procedure
18202
18203 else
18204 Error_Pragma_Arg
18205 ("pragma % must be applied to a primitive procedure", Arg1);
18206 end if;
18207
18208 -- Ada 2012 (AI12-0279): Cannot apply the implementation_kind
18209 -- By_Protected_Procedure to a procedure that has aspect Yield
18210
18211 if Chars (Get_Pragma_Arg (Arg2)) = Name_By_Protected_Procedure
18212 and then Has_Yield_Aspect (Proc_Id)
18213 then
18214 Error_Pragma_Arg
18215 ("implementation kind By_Protected_Procedure cannot be "
18216 & "applied to entities with aspect 'Yield", Arg2);
18217 end if;
18218
18219 Record_Rep_Item (Proc_Id, N);
18220 end Implemented;
18221
18222 ----------------------
18223 -- Implicit_Packing --
18224 ----------------------
18225
18226 -- pragma Implicit_Packing;
18227
18228 when Pragma_Implicit_Packing =>
18229 GNAT_Pragma;
18230 Check_Arg_Count (0);
18231 Implicit_Packing := True;
18232
18233 ------------
18234 -- Import --
18235 ------------
18236
18237 -- pragma Import (
18238 -- [Convention =>] convention_IDENTIFIER,
18239 -- [Entity =>] LOCAL_NAME
18240 -- [, [External_Name =>] static_string_EXPRESSION ]
18241 -- [, [Link_Name =>] static_string_EXPRESSION ]);
18242
18243 when Pragma_Import =>
18244 Check_Ada_83_Warning;
18245 Check_Arg_Order
18246 ((Name_Convention,
18247 Name_Entity,
18248 Name_External_Name,
18249 Name_Link_Name));
18250
18251 Check_At_Least_N_Arguments (2);
18252 Check_At_Most_N_Arguments (4);
18253 Process_Import_Or_Interface;
18254
18255 ---------------------
18256 -- Import_Function --
18257 ---------------------
18258
18259 -- pragma Import_Function (
18260 -- [Internal =>] LOCAL_NAME,
18261 -- [, [External =>] EXTERNAL_SYMBOL]
18262 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
18263 -- [, [Result_Type =>] SUBTYPE_MARK]
18264 -- [, [Mechanism =>] MECHANISM]
18265 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
18266
18267 -- EXTERNAL_SYMBOL ::=
18268 -- IDENTIFIER
18269 -- | static_string_EXPRESSION
18270
18271 -- PARAMETER_TYPES ::=
18272 -- null
18273 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
18274
18275 -- TYPE_DESIGNATOR ::=
18276 -- subtype_NAME
18277 -- | subtype_Name ' Access
18278
18279 -- MECHANISM ::=
18280 -- MECHANISM_NAME
18281 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
18282
18283 -- MECHANISM_ASSOCIATION ::=
18284 -- [formal_parameter_NAME =>] MECHANISM_NAME
18285
18286 -- MECHANISM_NAME ::=
18287 -- Value
18288 -- | Reference
18289
18290 when Pragma_Import_Function => Import_Function : declare
18291 Args : Args_List (1 .. 6);
18292 Names : constant Name_List (1 .. 6) := (
18293 Name_Internal,
18294 Name_External,
18295 Name_Parameter_Types,
18296 Name_Result_Type,
18297 Name_Mechanism,
18298 Name_Result_Mechanism);
18299
18300 Internal : Node_Id renames Args (1);
18301 External : Node_Id renames Args (2);
18302 Parameter_Types : Node_Id renames Args (3);
18303 Result_Type : Node_Id renames Args (4);
18304 Mechanism : Node_Id renames Args (5);
18305 Result_Mechanism : Node_Id renames Args (6);
18306
18307 begin
18308 GNAT_Pragma;
18309 Gather_Associations (Names, Args);
18310 Process_Extended_Import_Export_Subprogram_Pragma (
18311 Arg_Internal => Internal,
18312 Arg_External => External,
18313 Arg_Parameter_Types => Parameter_Types,
18314 Arg_Result_Type => Result_Type,
18315 Arg_Mechanism => Mechanism,
18316 Arg_Result_Mechanism => Result_Mechanism);
18317 end Import_Function;
18318
18319 -------------------
18320 -- Import_Object --
18321 -------------------
18322
18323 -- pragma Import_Object (
18324 -- [Internal =>] LOCAL_NAME
18325 -- [, [External =>] EXTERNAL_SYMBOL]
18326 -- [, [Size =>] EXTERNAL_SYMBOL]);
18327
18328 -- EXTERNAL_SYMBOL ::=
18329 -- IDENTIFIER
18330 -- | static_string_EXPRESSION
18331
18332 when Pragma_Import_Object => Import_Object : declare
18333 Args : Args_List (1 .. 3);
18334 Names : constant Name_List (1 .. 3) := (
18335 Name_Internal,
18336 Name_External,
18337 Name_Size);
18338
18339 Internal : Node_Id renames Args (1);
18340 External : Node_Id renames Args (2);
18341 Size : Node_Id renames Args (3);
18342
18343 begin
18344 GNAT_Pragma;
18345 Gather_Associations (Names, Args);
18346 Process_Extended_Import_Export_Object_Pragma (
18347 Arg_Internal => Internal,
18348 Arg_External => External,
18349 Arg_Size => Size);
18350 end Import_Object;
18351
18352 ----------------------
18353 -- Import_Procedure --
18354 ----------------------
18355
18356 -- pragma Import_Procedure (
18357 -- [Internal =>] LOCAL_NAME
18358 -- [, [External =>] EXTERNAL_SYMBOL]
18359 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
18360 -- [, [Mechanism =>] MECHANISM]);
18361
18362 -- EXTERNAL_SYMBOL ::=
18363 -- IDENTIFIER
18364 -- | static_string_EXPRESSION
18365
18366 -- PARAMETER_TYPES ::=
18367 -- null
18368 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
18369
18370 -- TYPE_DESIGNATOR ::=
18371 -- subtype_NAME
18372 -- | subtype_Name ' Access
18373
18374 -- MECHANISM ::=
18375 -- MECHANISM_NAME
18376 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
18377
18378 -- MECHANISM_ASSOCIATION ::=
18379 -- [formal_parameter_NAME =>] MECHANISM_NAME
18380
18381 -- MECHANISM_NAME ::=
18382 -- Value
18383 -- | Reference
18384
18385 when Pragma_Import_Procedure => Import_Procedure : declare
18386 Args : Args_List (1 .. 4);
18387 Names : constant Name_List (1 .. 4) := (
18388 Name_Internal,
18389 Name_External,
18390 Name_Parameter_Types,
18391 Name_Mechanism);
18392
18393 Internal : Node_Id renames Args (1);
18394 External : Node_Id renames Args (2);
18395 Parameter_Types : Node_Id renames Args (3);
18396 Mechanism : Node_Id renames Args (4);
18397
18398 begin
18399 GNAT_Pragma;
18400 Gather_Associations (Names, Args);
18401 Process_Extended_Import_Export_Subprogram_Pragma (
18402 Arg_Internal => Internal,
18403 Arg_External => External,
18404 Arg_Parameter_Types => Parameter_Types,
18405 Arg_Mechanism => Mechanism);
18406 end Import_Procedure;
18407
18408 -----------------------------
18409 -- Import_Valued_Procedure --
18410 -----------------------------
18411
18412 -- pragma Import_Valued_Procedure (
18413 -- [Internal =>] LOCAL_NAME
18414 -- [, [External =>] EXTERNAL_SYMBOL]
18415 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
18416 -- [, [Mechanism =>] MECHANISM]);
18417
18418 -- EXTERNAL_SYMBOL ::=
18419 -- IDENTIFIER
18420 -- | static_string_EXPRESSION
18421
18422 -- PARAMETER_TYPES ::=
18423 -- null
18424 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
18425
18426 -- TYPE_DESIGNATOR ::=
18427 -- subtype_NAME
18428 -- | subtype_Name ' Access
18429
18430 -- MECHANISM ::=
18431 -- MECHANISM_NAME
18432 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
18433
18434 -- MECHANISM_ASSOCIATION ::=
18435 -- [formal_parameter_NAME =>] MECHANISM_NAME
18436
18437 -- MECHANISM_NAME ::=
18438 -- Value
18439 -- | Reference
18440
18441 when Pragma_Import_Valued_Procedure =>
18442 Import_Valued_Procedure : declare
18443 Args : Args_List (1 .. 4);
18444 Names : constant Name_List (1 .. 4) := (
18445 Name_Internal,
18446 Name_External,
18447 Name_Parameter_Types,
18448 Name_Mechanism);
18449
18450 Internal : Node_Id renames Args (1);
18451 External : Node_Id renames Args (2);
18452 Parameter_Types : Node_Id renames Args (3);
18453 Mechanism : Node_Id renames Args (4);
18454
18455 begin
18456 GNAT_Pragma;
18457 Gather_Associations (Names, Args);
18458 Process_Extended_Import_Export_Subprogram_Pragma (
18459 Arg_Internal => Internal,
18460 Arg_External => External,
18461 Arg_Parameter_Types => Parameter_Types,
18462 Arg_Mechanism => Mechanism);
18463 end Import_Valued_Procedure;
18464
18465 -----------------
18466 -- Independent --
18467 -----------------
18468
18469 -- pragma Independent (LOCAL_NAME);
18470
18471 when Pragma_Independent =>
18472 Process_Atomic_Independent_Shared_Volatile;
18473
18474 ----------------------------
18475 -- Independent_Components --
18476 ----------------------------
18477
18478 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
18479
18480 when Pragma_Independent_Components => Independent_Components : declare
18481 C : Node_Id;
18482 D : Node_Id;
18483 E_Id : Node_Id;
18484 E : Entity_Id;
18485
18486 begin
18487 Check_Ada_83_Warning;
18488 Ada_2012_Pragma;
18489 Check_No_Identifiers;
18490 Check_Arg_Count (1);
18491 Check_Arg_Is_Local_Name (Arg1);
18492 E_Id := Get_Pragma_Arg (Arg1);
18493
18494 if Etype (E_Id) = Any_Type then
18495 return;
18496 end if;
18497
18498 E := Entity (E_Id);
18499
18500 -- A record type with a self-referential component of anonymous
18501 -- access type is given an incomplete view in order to handle the
18502 -- self reference:
18503 --
18504 -- type Rec is record
18505 -- Self : access Rec;
18506 -- end record;
18507 --
18508 -- becomes
18509 --
18510 -- type Rec;
18511 -- type Ptr is access Rec;
18512 -- type Rec is record
18513 -- Self : Ptr;
18514 -- end record;
18515 --
18516 -- Since the incomplete view is now the initial view of the type,
18517 -- the argument of the pragma will reference the incomplete view,
18518 -- but this view is illegal according to the semantics of the
18519 -- pragma.
18520 --
18521 -- Obtain the full view of an internally-generated incomplete type
18522 -- only. This way an attempt to associate the pragma with a source
18523 -- incomplete type is still caught.
18524
18525 if Ekind (E) = E_Incomplete_Type
18526 and then not Comes_From_Source (E)
18527 and then Present (Full_View (E))
18528 then
18529 E := Full_View (E);
18530 end if;
18531
18532 -- A pragma that applies to a Ghost entity becomes Ghost for the
18533 -- purposes of legality checks and removal of ignored Ghost code.
18534
18535 Mark_Ghost_Pragma (N, E);
18536
18537 -- Check duplicate before we chain ourselves
18538
18539 Check_Duplicate_Pragma (E);
18540
18541 -- Check appropriate entity
18542
18543 if Rep_Item_Too_Early (E, N)
18544 or else
18545 Rep_Item_Too_Late (E, N)
18546 then
18547 return;
18548 end if;
18549
18550 D := Declaration_Node (E);
18551
18552 -- The flag is set on the base type, or on the object
18553
18554 if Nkind (D) = N_Full_Type_Declaration
18555 and then (Is_Array_Type (E) or else Is_Record_Type (E))
18556 then
18557 Set_Has_Independent_Components (Base_Type (E));
18558 Record_Independence_Check (N, Base_Type (E));
18559
18560 -- For record type, set all components independent
18561
18562 if Is_Record_Type (E) then
18563 C := First_Component (E);
18564 while Present (C) loop
18565 Set_Is_Independent (C);
18566 Next_Component (C);
18567 end loop;
18568 end if;
18569
18570 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
18571 and then Nkind (D) = N_Object_Declaration
18572 and then Nkind (Object_Definition (D)) =
18573 N_Constrained_Array_Definition
18574 then
18575 Set_Has_Independent_Components (E);
18576 Record_Independence_Check (N, E);
18577
18578 else
18579 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
18580 end if;
18581 end Independent_Components;
18582
18583 -----------------------
18584 -- Initial_Condition --
18585 -----------------------
18586
18587 -- pragma Initial_Condition (boolean_EXPRESSION);
18588
18589 -- Characteristics:
18590
18591 -- * Analysis - The annotation undergoes initial checks to verify
18592 -- the legal placement and context. Secondary checks preanalyze the
18593 -- expression in:
18594
18595 -- Analyze_Initial_Condition_In_Decl_Part
18596
18597 -- * Expansion - The annotation is expanded during the expansion of
18598 -- the package body whose declaration is subject to the annotation
18599 -- as done in:
18600
18601 -- Expand_Pragma_Initial_Condition
18602
18603 -- * Template - The annotation utilizes the generic template of the
18604 -- related package declaration.
18605
18606 -- * Globals - Capture of global references must occur after full
18607 -- analysis.
18608
18609 -- * Instance - The annotation is instantiated automatically when
18610 -- the related generic package is instantiated.
18611
18612 when Pragma_Initial_Condition => Initial_Condition : declare
18613 Pack_Decl : Node_Id;
18614 Pack_Id : Entity_Id;
18615
18616 begin
18617 GNAT_Pragma;
18618 Check_No_Identifiers;
18619 Check_Arg_Count (1);
18620
18621 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
18622
18623 if Nkind (Pack_Decl) not in
18624 N_Generic_Package_Declaration | N_Package_Declaration
18625 then
18626 Pragma_Misplaced;
18627 end if;
18628
18629 Pack_Id := Defining_Entity (Pack_Decl);
18630
18631 -- A pragma that applies to a Ghost entity becomes Ghost for the
18632 -- purposes of legality checks and removal of ignored Ghost code.
18633
18634 Mark_Ghost_Pragma (N, Pack_Id);
18635
18636 -- Chain the pragma on the contract for further processing by
18637 -- Analyze_Initial_Condition_In_Decl_Part.
18638
18639 Add_Contract_Item (N, Pack_Id);
18640
18641 -- The legality checks of pragmas Abstract_State, Initializes, and
18642 -- Initial_Condition are affected by the SPARK mode in effect. In
18643 -- addition, these three pragmas are subject to an inherent order:
18644
18645 -- 1) Abstract_State
18646 -- 2) Initializes
18647 -- 3) Initial_Condition
18648
18649 -- Analyze all these pragmas in the order outlined above
18650
18651 Analyze_If_Present (Pragma_SPARK_Mode);
18652 Analyze_If_Present (Pragma_Abstract_State);
18653 Analyze_If_Present (Pragma_Initializes);
18654 end Initial_Condition;
18655
18656 ------------------------
18657 -- Initialize_Scalars --
18658 ------------------------
18659
18660 -- pragma Initialize_Scalars
18661 -- [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ];
18662
18663 -- TYPE_VALUE_PAIR ::=
18664 -- SCALAR_TYPE => static_EXPRESSION
18665
18666 -- SCALAR_TYPE :=
18667 -- Short_Float
18668 -- | Float
18669 -- | Long_Float
18670 -- | Long_Long_Float
18671 -- | Signed_8
18672 -- | Signed_16
18673 -- | Signed_32
18674 -- | Signed_64
18675 -- | Signed_128
18676 -- | Unsigned_8
18677 -- | Unsigned_16
18678 -- | Unsigned_32
18679 -- | Unsigned_64
18680 -- | Unsigned_128
18681
18682 when Pragma_Initialize_Scalars => Do_Initialize_Scalars : declare
18683 Seen : array (Scalar_Id) of Node_Id := (others => Empty);
18684 -- This collection holds the individual pairs which specify the
18685 -- invalid values of their respective scalar types.
18686
18687 procedure Analyze_Float_Value
18688 (Scal_Typ : Float_Scalar_Id;
18689 Val_Expr : Node_Id);
18690 -- Analyze a type value pair associated with float type Scal_Typ
18691 -- and expression Val_Expr.
18692
18693 procedure Analyze_Integer_Value
18694 (Scal_Typ : Integer_Scalar_Id;
18695 Val_Expr : Node_Id);
18696 -- Analyze a type value pair associated with integer type Scal_Typ
18697 -- and expression Val_Expr.
18698
18699 procedure Analyze_Type_Value_Pair (Pair : Node_Id);
18700 -- Analyze type value pair Pair
18701
18702 -------------------------
18703 -- Analyze_Float_Value --
18704 -------------------------
18705
18706 procedure Analyze_Float_Value
18707 (Scal_Typ : Float_Scalar_Id;
18708 Val_Expr : Node_Id)
18709 is
18710 begin
18711 Analyze_And_Resolve (Val_Expr, Any_Real);
18712
18713 if Is_OK_Static_Expression (Val_Expr) then
18714 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value_R (Val_Expr));
18715
18716 else
18717 Error_Msg_Name_1 := Scal_Typ;
18718 Error_Msg_N ("value for type % must be static", Val_Expr);
18719 end if;
18720 end Analyze_Float_Value;
18721
18722 ---------------------------
18723 -- Analyze_Integer_Value --
18724 ---------------------------
18725
18726 procedure Analyze_Integer_Value
18727 (Scal_Typ : Integer_Scalar_Id;
18728 Val_Expr : Node_Id)
18729 is
18730 begin
18731 Analyze_And_Resolve (Val_Expr, Any_Integer);
18732
18733 if (Scal_Typ = Name_Signed_128
18734 or else Scal_Typ = Name_Unsigned_128)
18735 and then Ttypes.System_Max_Integer_Size < 128
18736 then
18737 Error_Msg_Name_1 := Scal_Typ;
18738 Error_Msg_N ("value cannot be set for type %", Val_Expr);
18739
18740 elsif Is_OK_Static_Expression (Val_Expr) then
18741 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value (Val_Expr));
18742
18743 else
18744 Error_Msg_Name_1 := Scal_Typ;
18745 Error_Msg_N ("value for type % must be static", Val_Expr);
18746 end if;
18747 end Analyze_Integer_Value;
18748
18749 -----------------------------
18750 -- Analyze_Type_Value_Pair --
18751 -----------------------------
18752
18753 procedure Analyze_Type_Value_Pair (Pair : Node_Id) is
18754 Scal_Typ : constant Name_Id := Chars (Pair);
18755 Val_Expr : constant Node_Id := Expression (Pair);
18756 Prev_Pair : Node_Id;
18757
18758 begin
18759 if Scal_Typ in Scalar_Id then
18760 Prev_Pair := Seen (Scal_Typ);
18761
18762 -- Prevent multiple attempts to set a value for a scalar
18763 -- type.
18764
18765 if Present (Prev_Pair) then
18766 Error_Msg_Name_1 := Scal_Typ;
18767 Error_Msg_N
18768 ("cannot specify multiple invalid values for type %",
18769 Pair);
18770
18771 Error_Msg_Sloc := Sloc (Prev_Pair);
18772 Error_Msg_N ("previous value set #", Pair);
18773
18774 -- Ignore the effects of the pair, but do not halt the
18775 -- analysis of the pragma altogether.
18776
18777 return;
18778
18779 -- Otherwise capture the first pair for this scalar type
18780
18781 else
18782 Seen (Scal_Typ) := Pair;
18783 end if;
18784
18785 if Scal_Typ in Float_Scalar_Id then
18786 Analyze_Float_Value (Scal_Typ, Val_Expr);
18787
18788 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
18789 Analyze_Integer_Value (Scal_Typ, Val_Expr);
18790 end if;
18791
18792 -- Otherwise the scalar family is illegal
18793
18794 else
18795 Error_Msg_Name_1 := Pname;
18796 Error_Msg_N
18797 ("argument of pragma % must denote valid scalar family",
18798 Pair);
18799 end if;
18800 end Analyze_Type_Value_Pair;
18801
18802 -- Local variables
18803
18804 Pairs : constant List_Id := Pragma_Argument_Associations (N);
18805 Pair : Node_Id;
18806
18807 -- Start of processing for Do_Initialize_Scalars
18808
18809 begin
18810 GNAT_Pragma;
18811 Check_Valid_Configuration_Pragma;
18812 Check_Restriction (No_Initialize_Scalars, N);
18813
18814 -- Ignore the effects of the pragma when No_Initialize_Scalars is
18815 -- in effect.
18816
18817 if Restriction_Active (No_Initialize_Scalars) then
18818 null;
18819
18820 -- Initialize_Scalars creates false positives in CodePeer, and
18821 -- incorrect negative results in GNATprove mode, so ignore this
18822 -- pragma in these modes.
18823
18824 elsif CodePeer_Mode or GNATprove_Mode then
18825 null;
18826
18827 -- Otherwise analyze the pragma
18828
18829 else
18830 if Present (Pairs) then
18831
18832 -- Install Standard in order to provide access to primitive
18833 -- types in case the expressions contain attributes such as
18834 -- Integer'Last.
18835
18836 Push_Scope (Standard_Standard);
18837
18838 Pair := First (Pairs);
18839 while Present (Pair) loop
18840 Analyze_Type_Value_Pair (Pair);
18841 Next (Pair);
18842 end loop;
18843
18844 -- Remove Standard
18845
18846 Pop_Scope;
18847 end if;
18848
18849 Init_Or_Norm_Scalars := True;
18850 Initialize_Scalars := True;
18851 end if;
18852 end Do_Initialize_Scalars;
18853
18854 -----------------
18855 -- Initializes --
18856 -----------------
18857
18858 -- pragma Initializes (INITIALIZATION_LIST);
18859
18860 -- INITIALIZATION_LIST ::=
18861 -- null
18862 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
18863
18864 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
18865
18866 -- INPUT_LIST ::=
18867 -- null
18868 -- | INPUT
18869 -- | (INPUT {, INPUT})
18870
18871 -- INPUT ::= name
18872
18873 -- Characteristics:
18874
18875 -- * Analysis - The annotation undergoes initial checks to verify
18876 -- the legal placement and context. Secondary checks preanalyze the
18877 -- expression in:
18878
18879 -- Analyze_Initializes_In_Decl_Part
18880
18881 -- * Expansion - None.
18882
18883 -- * Template - The annotation utilizes the generic template of the
18884 -- related package declaration.
18885
18886 -- * Globals - Capture of global references must occur after full
18887 -- analysis.
18888
18889 -- * Instance - The annotation is instantiated automatically when
18890 -- the related generic package is instantiated.
18891
18892 when Pragma_Initializes => Initializes : declare
18893 Pack_Decl : Node_Id;
18894 Pack_Id : Entity_Id;
18895
18896 begin
18897 GNAT_Pragma;
18898 Check_No_Identifiers;
18899 Check_Arg_Count (1);
18900
18901 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
18902
18903 if Nkind (Pack_Decl) not in
18904 N_Generic_Package_Declaration | N_Package_Declaration
18905 then
18906 Pragma_Misplaced;
18907 end if;
18908
18909 Pack_Id := Defining_Entity (Pack_Decl);
18910
18911 -- A pragma that applies to a Ghost entity becomes Ghost for the
18912 -- purposes of legality checks and removal of ignored Ghost code.
18913
18914 Mark_Ghost_Pragma (N, Pack_Id);
18915 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
18916
18917 -- Chain the pragma on the contract for further processing by
18918 -- Analyze_Initializes_In_Decl_Part.
18919
18920 Add_Contract_Item (N, Pack_Id);
18921
18922 -- The legality checks of pragmas Abstract_State, Initializes, and
18923 -- Initial_Condition are affected by the SPARK mode in effect. In
18924 -- addition, these three pragmas are subject to an inherent order:
18925
18926 -- 1) Abstract_State
18927 -- 2) Initializes
18928 -- 3) Initial_Condition
18929
18930 -- Analyze all these pragmas in the order outlined above
18931
18932 Analyze_If_Present (Pragma_SPARK_Mode);
18933 Analyze_If_Present (Pragma_Abstract_State);
18934 Analyze_If_Present (Pragma_Initial_Condition);
18935 end Initializes;
18936
18937 ------------
18938 -- Inline --
18939 ------------
18940
18941 -- pragma Inline ( NAME {, NAME} );
18942
18943 when Pragma_Inline =>
18944
18945 -- Pragma always active unless in GNATprove mode. It is disabled
18946 -- in GNATprove mode because frontend inlining is applied
18947 -- independently of pragmas Inline and Inline_Always for
18948 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
18949 -- in inline.ads.
18950
18951 if not GNATprove_Mode then
18952
18953 -- Inline status is Enabled if option -gnatn is specified.
18954 -- However this status determines only the value of the
18955 -- Is_Inlined flag on the subprogram and does not prevent
18956 -- the pragma itself from being recorded for later use,
18957 -- in particular for a later modification of Is_Inlined
18958 -- independently of the -gnatn option.
18959
18960 -- In other words, if -gnatn is specified for a unit, then
18961 -- all Inline pragmas processed for the compilation of this
18962 -- unit, including those in the spec of other units, are
18963 -- activated, so subprograms will be inlined across units.
18964
18965 -- If -gnatn is not specified, no Inline pragma is activated
18966 -- here, which means that subprograms will not be inlined
18967 -- across units. The Is_Inlined flag will nevertheless be
18968 -- set later when bodies are analyzed, so subprograms will
18969 -- be inlined within the unit.
18970
18971 if Inline_Active then
18972 Process_Inline (Enabled);
18973 else
18974 Process_Inline (Disabled);
18975 end if;
18976 end if;
18977
18978 -------------------
18979 -- Inline_Always --
18980 -------------------
18981
18982 -- pragma Inline_Always ( NAME {, NAME} );
18983
18984 when Pragma_Inline_Always =>
18985 GNAT_Pragma;
18986
18987 -- Pragma always active unless in CodePeer mode or GNATprove
18988 -- mode. It is disabled in CodePeer mode because inlining is
18989 -- not helpful, and enabling it caused walk order issues. It
18990 -- is disabled in GNATprove mode because frontend inlining is
18991 -- applied independently of pragmas Inline and Inline_Always for
18992 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
18993 -- inline.ads.
18994
18995 if not CodePeer_Mode and not GNATprove_Mode then
18996 Process_Inline (Enabled);
18997 end if;
18998
18999 --------------------
19000 -- Inline_Generic --
19001 --------------------
19002
19003 -- pragma Inline_Generic (NAME {, NAME});
19004
19005 when Pragma_Inline_Generic =>
19006 GNAT_Pragma;
19007 Process_Generic_List;
19008
19009 ----------------------
19010 -- Inspection_Point --
19011 ----------------------
19012
19013 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
19014
19015 when Pragma_Inspection_Point => Inspection_Point : declare
19016 Arg : Node_Id;
19017 Exp : Node_Id;
19018
19019 begin
19020 ip;
19021
19022 if Arg_Count > 0 then
19023 Arg := Arg1;
19024 loop
19025 Exp := Get_Pragma_Arg (Arg);
19026 Analyze (Exp);
19027
19028 if not Is_Entity_Name (Exp)
19029 or else not Is_Object (Entity (Exp))
19030 then
19031 Error_Pragma_Arg ("object name required", Arg);
19032 end if;
19033
19034 Next (Arg);
19035 exit when No (Arg);
19036 end loop;
19037 end if;
19038 end Inspection_Point;
19039
19040 ---------------
19041 -- Interface --
19042 ---------------
19043
19044 -- pragma Interface (
19045 -- [ Convention =>] convention_IDENTIFIER,
19046 -- [ Entity =>] LOCAL_NAME
19047 -- [, [External_Name =>] static_string_EXPRESSION ]
19048 -- [, [Link_Name =>] static_string_EXPRESSION ]);
19049
19050 when Pragma_Interface =>
19051 GNAT_Pragma;
19052 Check_Arg_Order
19053 ((Name_Convention,
19054 Name_Entity,
19055 Name_External_Name,
19056 Name_Link_Name));
19057 Check_At_Least_N_Arguments (2);
19058 Check_At_Most_N_Arguments (4);
19059 Process_Import_Or_Interface;
19060
19061 -- In Ada 2005, the permission to use Interface (a reserved word)
19062 -- as a pragma name is considered an obsolescent feature, and this
19063 -- pragma was already obsolescent in Ada 95.
19064
19065 if Ada_Version >= Ada_95 then
19066 Check_Restriction
19067 (No_Obsolescent_Features, Pragma_Identifier (N));
19068
19069 if Warn_On_Obsolescent_Feature then
19070 Error_Msg_N
19071 ("pragma Interface is an obsolescent feature?j?", N);
19072 Error_Msg_N
19073 ("|use pragma Import instead?j?", N);
19074 end if;
19075 end if;
19076
19077 --------------------
19078 -- Interface_Name --
19079 --------------------
19080
19081 -- pragma Interface_Name (
19082 -- [ Entity =>] LOCAL_NAME
19083 -- [,[External_Name =>] static_string_EXPRESSION ]
19084 -- [,[Link_Name =>] static_string_EXPRESSION ]);
19085
19086 when Pragma_Interface_Name => Interface_Name : declare
19087 Id : Node_Id;
19088 Def_Id : Entity_Id;
19089 Hom_Id : Entity_Id;
19090 Found : Boolean;
19091
19092 begin
19093 GNAT_Pragma;
19094 Check_Arg_Order
19095 ((Name_Entity, Name_External_Name, Name_Link_Name));
19096 Check_At_Least_N_Arguments (2);
19097 Check_At_Most_N_Arguments (3);
19098 Id := Get_Pragma_Arg (Arg1);
19099 Analyze (Id);
19100
19101 -- This is obsolete from Ada 95 on, but it is an implementation
19102 -- defined pragma, so we do not consider that it violates the
19103 -- restriction (No_Obsolescent_Features).
19104
19105 if Ada_Version >= Ada_95 then
19106 if Warn_On_Obsolescent_Feature then
19107 Error_Msg_N
19108 ("pragma Interface_Name is an obsolescent feature?j?", N);
19109 Error_Msg_N
19110 ("|use pragma Import instead?j?", N);
19111 end if;
19112 end if;
19113
19114 if not Is_Entity_Name (Id) then
19115 Error_Pragma_Arg
19116 ("first argument for pragma% must be entity name", Arg1);
19117 elsif Etype (Id) = Any_Type then
19118 return;
19119 else
19120 Def_Id := Entity (Id);
19121 end if;
19122
19123 -- Special DEC-compatible processing for the object case, forces
19124 -- object to be imported.
19125
19126 if Ekind (Def_Id) = E_Variable then
19127 Kill_Size_Check_Code (Def_Id);
19128 Note_Possible_Modification (Id, Sure => False);
19129
19130 -- Initialization is not allowed for imported variable
19131
19132 if Present (Expression (Parent (Def_Id)))
19133 and then Comes_From_Source (Expression (Parent (Def_Id)))
19134 then
19135 Error_Msg_Sloc := Sloc (Def_Id);
19136 Error_Pragma_Arg
19137 ("no initialization allowed for declaration of& #",
19138 Arg2);
19139
19140 else
19141 -- For compatibility, support VADS usage of providing both
19142 -- pragmas Interface and Interface_Name to obtain the effect
19143 -- of a single Import pragma.
19144
19145 if Is_Imported (Def_Id)
19146 and then Present (First_Rep_Item (Def_Id))
19147 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
19148 and then Pragma_Name (First_Rep_Item (Def_Id)) =
19149 Name_Interface
19150 then
19151 null;
19152 else
19153 Set_Imported (Def_Id);
19154 end if;
19155
19156 Set_Is_Public (Def_Id);
19157 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
19158 end if;
19159
19160 -- Otherwise must be subprogram
19161
19162 elsif not Is_Subprogram (Def_Id) then
19163 Error_Pragma_Arg
19164 ("argument of pragma% is not subprogram", Arg1);
19165
19166 else
19167 Check_At_Most_N_Arguments (3);
19168 Hom_Id := Def_Id;
19169 Found := False;
19170
19171 -- Loop through homonyms
19172
19173 loop
19174 Def_Id := Get_Base_Subprogram (Hom_Id);
19175
19176 if Is_Imported (Def_Id) then
19177 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
19178 Found := True;
19179 end if;
19180
19181 exit when From_Aspect_Specification (N);
19182 Hom_Id := Homonym (Hom_Id);
19183
19184 exit when No (Hom_Id)
19185 or else Scope (Hom_Id) /= Current_Scope;
19186 end loop;
19187
19188 if not Found then
19189 Error_Pragma_Arg
19190 ("argument of pragma% is not imported subprogram",
19191 Arg1);
19192 end if;
19193 end if;
19194 end Interface_Name;
19195
19196 -----------------------
19197 -- Interrupt_Handler --
19198 -----------------------
19199
19200 -- pragma Interrupt_Handler (handler_NAME);
19201
19202 when Pragma_Interrupt_Handler =>
19203 Check_Ada_83_Warning;
19204 Check_Arg_Count (1);
19205 Check_No_Identifiers;
19206
19207 if No_Run_Time_Mode then
19208 Error_Msg_CRT ("Interrupt_Handler pragma", N);
19209 else
19210 Check_Interrupt_Or_Attach_Handler;
19211 Process_Interrupt_Or_Attach_Handler;
19212 end if;
19213
19214 ------------------------
19215 -- Interrupt_Priority --
19216 ------------------------
19217
19218 -- pragma Interrupt_Priority [(EXPRESSION)];
19219
19220 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
19221 P : constant Node_Id := Parent (N);
19222 Arg : Node_Id;
19223 Ent : Entity_Id;
19224
19225 begin
19226 Check_Ada_83_Warning;
19227
19228 if Arg_Count /= 0 then
19229 Arg := Get_Pragma_Arg (Arg1);
19230 Check_Arg_Count (1);
19231 Check_No_Identifiers;
19232
19233 -- The expression must be analyzed in the special manner
19234 -- described in "Handling of Default and Per-Object
19235 -- Expressions" in sem.ads.
19236
19237 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
19238 end if;
19239
19240 if Nkind (P) not in N_Task_Definition | N_Protected_Definition then
19241 Pragma_Misplaced;
19242
19243 else
19244 Ent := Defining_Identifier (Parent (P));
19245
19246 -- Check duplicate pragma before we chain the pragma in the Rep
19247 -- Item chain of Ent.
19248
19249 Check_Duplicate_Pragma (Ent);
19250 Record_Rep_Item (Ent, N);
19251
19252 -- Check the No_Task_At_Interrupt_Priority restriction
19253
19254 if Nkind (P) = N_Task_Definition then
19255 Check_Restriction (No_Task_At_Interrupt_Priority, N);
19256 end if;
19257 end if;
19258 end Interrupt_Priority;
19259
19260 ---------------------
19261 -- Interrupt_State --
19262 ---------------------
19263
19264 -- pragma Interrupt_State (
19265 -- [Name =>] INTERRUPT_ID,
19266 -- [State =>] INTERRUPT_STATE);
19267
19268 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
19269 -- INTERRUPT_STATE => System | Runtime | User
19270
19271 -- Note: if the interrupt id is given as an identifier, then it must
19272 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
19273 -- given as a static integer expression which must be in the range of
19274 -- Ada.Interrupts.Interrupt_ID.
19275
19276 when Pragma_Interrupt_State => Interrupt_State : declare
19277 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
19278 -- This is the entity Ada.Interrupts.Interrupt_ID;
19279
19280 State_Type : Character;
19281 -- Set to 's'/'r'/'u' for System/Runtime/User
19282
19283 IST_Num : Pos;
19284 -- Index to entry in Interrupt_States table
19285
19286 Int_Val : Uint;
19287 -- Value of interrupt
19288
19289 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
19290 -- The first argument to the pragma
19291
19292 Int_Ent : Entity_Id;
19293 -- Interrupt entity in Ada.Interrupts.Names
19294
19295 begin
19296 GNAT_Pragma;
19297 Check_Arg_Order ((Name_Name, Name_State));
19298 Check_Arg_Count (2);
19299
19300 Check_Optional_Identifier (Arg1, Name_Name);
19301 Check_Optional_Identifier (Arg2, Name_State);
19302 Check_Arg_Is_Identifier (Arg2);
19303
19304 -- First argument is identifier
19305
19306 if Nkind (Arg1X) = N_Identifier then
19307
19308 -- Search list of names in Ada.Interrupts.Names
19309
19310 Int_Ent := First_Entity (RTE (RE_Names));
19311 loop
19312 if No (Int_Ent) then
19313 Error_Pragma_Arg ("invalid interrupt name", Arg1);
19314
19315 elsif Chars (Int_Ent) = Chars (Arg1X) then
19316 Int_Val := Expr_Value (Constant_Value (Int_Ent));
19317 exit;
19318 end if;
19319
19320 Next_Entity (Int_Ent);
19321 end loop;
19322
19323 -- First argument is not an identifier, so it must be a static
19324 -- expression of type Ada.Interrupts.Interrupt_ID.
19325
19326 else
19327 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
19328 Int_Val := Expr_Value (Arg1X);
19329
19330 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
19331 or else
19332 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
19333 then
19334 Error_Pragma_Arg
19335 ("value not in range of type "
19336 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
19337 end if;
19338 end if;
19339
19340 -- Check OK state
19341
19342 case Chars (Get_Pragma_Arg (Arg2)) is
19343 when Name_Runtime => State_Type := 'r';
19344 when Name_System => State_Type := 's';
19345 when Name_User => State_Type := 'u';
19346
19347 when others =>
19348 Error_Pragma_Arg ("invalid interrupt state", Arg2);
19349 end case;
19350
19351 -- Check if entry is already stored
19352
19353 IST_Num := Interrupt_States.First;
19354 loop
19355 -- If entry not found, add it
19356
19357 if IST_Num > Interrupt_States.Last then
19358 Interrupt_States.Append
19359 ((Interrupt_Number => UI_To_Int (Int_Val),
19360 Interrupt_State => State_Type,
19361 Pragma_Loc => Loc));
19362 exit;
19363
19364 -- Case of entry for the same entry
19365
19366 elsif Int_Val = Interrupt_States.Table (IST_Num).
19367 Interrupt_Number
19368 then
19369 -- If state matches, done, no need to make redundant entry
19370
19371 exit when
19372 State_Type = Interrupt_States.Table (IST_Num).
19373 Interrupt_State;
19374
19375 -- Otherwise if state does not match, error
19376
19377 Error_Msg_Sloc :=
19378 Interrupt_States.Table (IST_Num).Pragma_Loc;
19379 Error_Pragma_Arg
19380 ("state conflicts with that given #", Arg2);
19381 end if;
19382
19383 IST_Num := IST_Num + 1;
19384 end loop;
19385 end Interrupt_State;
19386
19387 ---------------
19388 -- Invariant --
19389 ---------------
19390
19391 -- pragma Invariant
19392 -- ([Entity =>] type_LOCAL_NAME,
19393 -- [Check =>] EXPRESSION
19394 -- [,[Message =>] String_Expression]);
19395
19396 when Pragma_Invariant => Invariant : declare
19397 Discard : Boolean;
19398 Typ : Entity_Id;
19399 Typ_Arg : Node_Id;
19400
19401 begin
19402 GNAT_Pragma;
19403 Check_At_Least_N_Arguments (2);
19404 Check_At_Most_N_Arguments (3);
19405 Check_Optional_Identifier (Arg1, Name_Entity);
19406 Check_Optional_Identifier (Arg2, Name_Check);
19407
19408 if Arg_Count = 3 then
19409 Check_Optional_Identifier (Arg3, Name_Message);
19410 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
19411 end if;
19412
19413 Check_Arg_Is_Local_Name (Arg1);
19414
19415 Typ_Arg := Get_Pragma_Arg (Arg1);
19416 Find_Type (Typ_Arg);
19417 Typ := Entity (Typ_Arg);
19418
19419 -- Nothing to do of the related type is erroneous in some way
19420
19421 if Typ = Any_Type then
19422 return;
19423
19424 -- AI12-0041: Invariants are allowed in interface types
19425
19426 elsif Is_Interface (Typ) then
19427 null;
19428
19429 -- An invariant must apply to a private type, or appear in the
19430 -- private part of a package spec and apply to a completion.
19431 -- a class-wide invariant can only appear on a private declaration
19432 -- or private extension, not a completion.
19433
19434 -- A [class-wide] invariant may be associated a [limited] private
19435 -- type or a private extension.
19436
19437 elsif Ekind (Typ) in E_Limited_Private_Type
19438 | E_Private_Type
19439 | E_Record_Type_With_Private
19440 then
19441 null;
19442
19443 -- A non-class-wide invariant may be associated with the full view
19444 -- of a [limited] private type or a private extension.
19445
19446 elsif Has_Private_Declaration (Typ)
19447 and then not Class_Present (N)
19448 then
19449 null;
19450
19451 -- A class-wide invariant may appear on the partial view only
19452
19453 elsif Class_Present (N) then
19454 Error_Pragma_Arg
19455 ("pragma % only allowed for private type", Arg1);
19456
19457 -- A regular invariant may appear on both views
19458
19459 else
19460 Error_Pragma_Arg
19461 ("pragma % only allowed for private type or corresponding "
19462 & "full view", Arg1);
19463 end if;
19464
19465 -- An invariant associated with an abstract type (this includes
19466 -- interfaces) must be class-wide.
19467
19468 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
19469 Error_Pragma_Arg
19470 ("pragma % not allowed for abstract type", Arg1);
19471 end if;
19472
19473 -- A pragma that applies to a Ghost entity becomes Ghost for the
19474 -- purposes of legality checks and removal of ignored Ghost code.
19475
19476 Mark_Ghost_Pragma (N, Typ);
19477
19478 -- The pragma defines a type-specific invariant, the type is said
19479 -- to have invariants of its "own".
19480
19481 Set_Has_Own_Invariants (Base_Type (Typ));
19482
19483 -- If the invariant is class-wide, then it can be inherited by
19484 -- derived or interface implementing types. The type is said to
19485 -- have "inheritable" invariants.
19486
19487 if Class_Present (N) then
19488 Set_Has_Inheritable_Invariants (Typ);
19489 end if;
19490
19491 -- Chain the pragma on to the rep item chain, for processing when
19492 -- the type is frozen.
19493
19494 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
19495
19496 -- Create the declaration of the invariant procedure that will
19497 -- verify the invariant at run time. Interfaces are treated as the
19498 -- partial view of a private type in order to achieve uniformity
19499 -- with the general case. As a result, an interface receives only
19500 -- a "partial" invariant procedure, which is never called.
19501
19502 Build_Invariant_Procedure_Declaration
19503 (Typ => Typ,
19504 Partial_Invariant => Is_Interface (Typ));
19505 end Invariant;
19506
19507 ----------------
19508 -- Keep_Names --
19509 ----------------
19510
19511 -- pragma Keep_Names ([On => ] LOCAL_NAME);
19512
19513 when Pragma_Keep_Names => Keep_Names : declare
19514 Arg : Node_Id;
19515
19516 begin
19517 GNAT_Pragma;
19518 Check_Arg_Count (1);
19519 Check_Optional_Identifier (Arg1, Name_On);
19520 Check_Arg_Is_Local_Name (Arg1);
19521
19522 Arg := Get_Pragma_Arg (Arg1);
19523 Analyze (Arg);
19524
19525 if Etype (Arg) = Any_Type then
19526 return;
19527 end if;
19528
19529 if not Is_Entity_Name (Arg)
19530 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
19531 then
19532 Error_Pragma_Arg
19533 ("pragma% requires a local enumeration type", Arg1);
19534 end if;
19535
19536 Set_Discard_Names (Entity (Arg), False);
19537 end Keep_Names;
19538
19539 -------------
19540 -- License --
19541 -------------
19542
19543 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
19544
19545 when Pragma_License =>
19546 GNAT_Pragma;
19547
19548 -- Do not analyze pragma any further in CodePeer mode, to avoid
19549 -- extraneous errors in this implementation-dependent pragma,
19550 -- which has a different profile on other compilers.
19551
19552 if CodePeer_Mode then
19553 return;
19554 end if;
19555
19556 Check_Arg_Count (1);
19557 Check_No_Identifiers;
19558 Check_Valid_Configuration_Pragma;
19559 Check_Arg_Is_Identifier (Arg1);
19560
19561 declare
19562 Sind : constant Source_File_Index :=
19563 Source_Index (Current_Sem_Unit);
19564
19565 begin
19566 case Chars (Get_Pragma_Arg (Arg1)) is
19567 when Name_GPL =>
19568 Set_License (Sind, GPL);
19569
19570 when Name_Modified_GPL =>
19571 Set_License (Sind, Modified_GPL);
19572
19573 when Name_Restricted =>
19574 Set_License (Sind, Restricted);
19575
19576 when Name_Unrestricted =>
19577 Set_License (Sind, Unrestricted);
19578
19579 when others =>
19580 Error_Pragma_Arg ("invalid license name", Arg1);
19581 end case;
19582 end;
19583
19584 ---------------
19585 -- Link_With --
19586 ---------------
19587
19588 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
19589
19590 when Pragma_Link_With => Link_With : declare
19591 Arg : Node_Id;
19592
19593 begin
19594 GNAT_Pragma;
19595
19596 if Operating_Mode = Generate_Code
19597 and then In_Extended_Main_Source_Unit (N)
19598 then
19599 Check_At_Least_N_Arguments (1);
19600 Check_No_Identifiers;
19601 Check_Is_In_Decl_Part_Or_Package_Spec;
19602 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
19603 Start_String;
19604
19605 Arg := Arg1;
19606 while Present (Arg) loop
19607 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
19608
19609 -- Store argument, converting sequences of spaces to a
19610 -- single null character (this is one of the differences
19611 -- in processing between Link_With and Linker_Options).
19612
19613 Arg_Store : declare
19614 C : constant Char_Code := Get_Char_Code (' ');
19615 S : constant String_Id :=
19616 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
19617 L : constant Nat := String_Length (S);
19618 F : Nat := 1;
19619
19620 procedure Skip_Spaces;
19621 -- Advance F past any spaces
19622
19623 -----------------
19624 -- Skip_Spaces --
19625 -----------------
19626
19627 procedure Skip_Spaces is
19628 begin
19629 while F <= L and then Get_String_Char (S, F) = C loop
19630 F := F + 1;
19631 end loop;
19632 end Skip_Spaces;
19633
19634 -- Start of processing for Arg_Store
19635
19636 begin
19637 Skip_Spaces; -- skip leading spaces
19638
19639 -- Loop through characters, changing any embedded
19640 -- sequence of spaces to a single null character (this
19641 -- is how Link_With/Linker_Options differ)
19642
19643 while F <= L loop
19644 if Get_String_Char (S, F) = C then
19645 Skip_Spaces;
19646 exit when F > L;
19647 Store_String_Char (ASCII.NUL);
19648
19649 else
19650 Store_String_Char (Get_String_Char (S, F));
19651 F := F + 1;
19652 end if;
19653 end loop;
19654 end Arg_Store;
19655
19656 Arg := Next (Arg);
19657
19658 if Present (Arg) then
19659 Store_String_Char (ASCII.NUL);
19660 end if;
19661 end loop;
19662
19663 Store_Linker_Option_String (End_String);
19664 end if;
19665 end Link_With;
19666
19667 ------------------
19668 -- Linker_Alias --
19669 ------------------
19670
19671 -- pragma Linker_Alias (
19672 -- [Entity =>] LOCAL_NAME
19673 -- [Target =>] static_string_EXPRESSION);
19674
19675 when Pragma_Linker_Alias =>
19676 GNAT_Pragma;
19677 Check_Arg_Order ((Name_Entity, Name_Target));
19678 Check_Arg_Count (2);
19679 Check_Optional_Identifier (Arg1, Name_Entity);
19680 Check_Optional_Identifier (Arg2, Name_Target);
19681 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19682 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19683
19684 -- The only processing required is to link this item on to the
19685 -- list of rep items for the given entity. This is accomplished
19686 -- by the call to Rep_Item_Too_Late (when no error is detected
19687 -- and False is returned).
19688
19689 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
19690 return;
19691 else
19692 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
19693 end if;
19694
19695 ------------------------
19696 -- Linker_Constructor --
19697 ------------------------
19698
19699 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
19700
19701 -- Code is shared with Linker_Destructor
19702
19703 -----------------------
19704 -- Linker_Destructor --
19705 -----------------------
19706
19707 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
19708
19709 when Pragma_Linker_Constructor
19710 | Pragma_Linker_Destructor
19711 =>
19712 Linker_Constructor : declare
19713 Arg1_X : Node_Id;
19714 Proc : Entity_Id;
19715
19716 begin
19717 GNAT_Pragma;
19718 Check_Arg_Count (1);
19719 Check_No_Identifiers;
19720 Check_Arg_Is_Local_Name (Arg1);
19721 Arg1_X := Get_Pragma_Arg (Arg1);
19722 Analyze (Arg1_X);
19723 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
19724
19725 if not Is_Library_Level_Entity (Proc) then
19726 Error_Pragma_Arg
19727 ("argument for pragma% must be library level entity", Arg1);
19728 end if;
19729
19730 -- The only processing required is to link this item on to the
19731 -- list of rep items for the given entity. This is accomplished
19732 -- by the call to Rep_Item_Too_Late (when no error is detected
19733 -- and False is returned).
19734
19735 if Rep_Item_Too_Late (Proc, N) then
19736 return;
19737 else
19738 Set_Has_Gigi_Rep_Item (Proc);
19739 end if;
19740 end Linker_Constructor;
19741
19742 --------------------
19743 -- Linker_Options --
19744 --------------------
19745
19746 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
19747
19748 when Pragma_Linker_Options => Linker_Options : declare
19749 Arg : Node_Id;
19750
19751 begin
19752 Check_Ada_83_Warning;
19753 Check_No_Identifiers;
19754 Check_Arg_Count (1);
19755 Check_Is_In_Decl_Part_Or_Package_Spec;
19756 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
19757 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
19758
19759 Arg := Arg2;
19760 while Present (Arg) loop
19761 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
19762 Store_String_Char (ASCII.NUL);
19763 Store_String_Chars
19764 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
19765 Arg := Next (Arg);
19766 end loop;
19767
19768 if Operating_Mode = Generate_Code
19769 and then In_Extended_Main_Source_Unit (N)
19770 then
19771 Store_Linker_Option_String (End_String);
19772 end if;
19773 end Linker_Options;
19774
19775 --------------------
19776 -- Linker_Section --
19777 --------------------
19778
19779 -- pragma Linker_Section (
19780 -- [Entity =>] LOCAL_NAME
19781 -- [Section =>] static_string_EXPRESSION);
19782
19783 when Pragma_Linker_Section => Linker_Section : declare
19784 Arg : Node_Id;
19785 Ent : Entity_Id;
19786 LPE : Node_Id;
19787
19788 Ghost_Error_Posted : Boolean := False;
19789 -- Flag set when an error concerning the illegal mix of Ghost and
19790 -- non-Ghost subprograms is emitted.
19791
19792 Ghost_Id : Entity_Id := Empty;
19793 -- The entity of the first Ghost subprogram encountered while
19794 -- processing the arguments of the pragma.
19795
19796 begin
19797 GNAT_Pragma;
19798 Check_Arg_Order ((Name_Entity, Name_Section));
19799 Check_Arg_Count (2);
19800 Check_Optional_Identifier (Arg1, Name_Entity);
19801 Check_Optional_Identifier (Arg2, Name_Section);
19802 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19803 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19804
19805 -- Check kind of entity
19806
19807 Arg := Get_Pragma_Arg (Arg1);
19808 Ent := Entity (Arg);
19809
19810 case Ekind (Ent) is
19811
19812 -- Objects (constants and variables) and types. For these cases
19813 -- all we need to do is to set the Linker_Section_pragma field,
19814 -- checking that we do not have a duplicate.
19815
19816 when Type_Kind
19817 | E_Constant
19818 | E_Variable
19819 =>
19820 LPE := Linker_Section_Pragma (Ent);
19821
19822 if Present (LPE) then
19823 Error_Msg_Sloc := Sloc (LPE);
19824 Error_Msg_NE
19825 ("Linker_Section already specified for &#", Arg1, Ent);
19826 end if;
19827
19828 Set_Linker_Section_Pragma (Ent, N);
19829
19830 -- A pragma that applies to a Ghost entity becomes Ghost for
19831 -- the purposes of legality checks and removal of ignored
19832 -- Ghost code.
19833
19834 Mark_Ghost_Pragma (N, Ent);
19835
19836 -- Subprograms
19837
19838 when Subprogram_Kind =>
19839
19840 -- Aspect case, entity already set
19841
19842 if From_Aspect_Specification (N) then
19843 Set_Linker_Section_Pragma
19844 (Entity (Corresponding_Aspect (N)), N);
19845
19846 -- Propagate it to its ultimate aliased entity to
19847 -- facilitate the backend processing this attribute
19848 -- in instantiations of generic subprograms.
19849
19850 if Present (Alias (Entity (Corresponding_Aspect (N))))
19851 then
19852 Set_Linker_Section_Pragma
19853 (Ultimate_Alias
19854 (Entity (Corresponding_Aspect (N))), N);
19855 end if;
19856
19857 -- Pragma case, we must climb the homonym chain, but skip
19858 -- any for which the linker section is already set.
19859
19860 else
19861 loop
19862 if No (Linker_Section_Pragma (Ent)) then
19863 Set_Linker_Section_Pragma (Ent, N);
19864
19865 -- Propagate it to its ultimate aliased entity to
19866 -- facilitate the backend processing this attribute
19867 -- in instantiations of generic subprograms.
19868
19869 if Present (Alias (Ent)) then
19870 Set_Linker_Section_Pragma
19871 (Ultimate_Alias (Ent), N);
19872 end if;
19873
19874 -- A pragma that applies to a Ghost entity becomes
19875 -- Ghost for the purposes of legality checks and
19876 -- removal of ignored Ghost code.
19877
19878 Mark_Ghost_Pragma (N, Ent);
19879
19880 -- Capture the entity of the first Ghost subprogram
19881 -- being processed for error detection purposes.
19882
19883 if Is_Ghost_Entity (Ent) then
19884 if No (Ghost_Id) then
19885 Ghost_Id := Ent;
19886 end if;
19887
19888 -- Otherwise the subprogram is non-Ghost. It is
19889 -- illegal to mix references to Ghost and non-Ghost
19890 -- entities (SPARK RM 6.9).
19891
19892 elsif Present (Ghost_Id)
19893 and then not Ghost_Error_Posted
19894 then
19895 Ghost_Error_Posted := True;
19896
19897 Error_Msg_Name_1 := Pname;
19898 Error_Msg_N
19899 ("pragma % cannot mention ghost and "
19900 & "non-ghost subprograms", N);
19901
19902 Error_Msg_Sloc := Sloc (Ghost_Id);
19903 Error_Msg_NE
19904 ("\& # declared as ghost", N, Ghost_Id);
19905
19906 Error_Msg_Sloc := Sloc (Ent);
19907 Error_Msg_NE
19908 ("\& # declared as non-ghost", N, Ent);
19909 end if;
19910 end if;
19911
19912 Ent := Homonym (Ent);
19913 exit when No (Ent)
19914 or else Scope (Ent) /= Current_Scope;
19915 end loop;
19916 end if;
19917
19918 -- All other cases are illegal
19919
19920 when others =>
19921 Error_Pragma_Arg
19922 ("pragma% applies only to objects, subprograms, and types",
19923 Arg1);
19924 end case;
19925 end Linker_Section;
19926
19927 ----------
19928 -- List --
19929 ----------
19930
19931 -- pragma List (On | Off)
19932
19933 -- There is nothing to do here, since we did all the processing for
19934 -- this pragma in Par.Prag (so that it works properly even in syntax
19935 -- only mode).
19936
19937 when Pragma_List =>
19938 null;
19939
19940 ---------------
19941 -- Lock_Free --
19942 ---------------
19943
19944 -- pragma Lock_Free [(Boolean_EXPRESSION)];
19945
19946 when Pragma_Lock_Free => Lock_Free : declare
19947 P : constant Node_Id := Parent (N);
19948 Arg : Node_Id;
19949 Ent : Entity_Id;
19950 Val : Boolean;
19951
19952 begin
19953 Check_No_Identifiers;
19954 Check_At_Most_N_Arguments (1);
19955
19956 -- Protected definition case
19957
19958 if Nkind (P) = N_Protected_Definition then
19959 Ent := Defining_Identifier (Parent (P));
19960
19961 -- One argument
19962
19963 if Arg_Count = 1 then
19964 Arg := Get_Pragma_Arg (Arg1);
19965 Val := Is_True (Static_Boolean (Arg));
19966
19967 -- No arguments (expression is considered to be True)
19968
19969 else
19970 Val := True;
19971 end if;
19972
19973 -- Check duplicate pragma before we chain the pragma in the Rep
19974 -- Item chain of Ent.
19975
19976 Check_Duplicate_Pragma (Ent);
19977 Record_Rep_Item (Ent, N);
19978 Set_Uses_Lock_Free (Ent, Val);
19979
19980 -- Anything else is incorrect placement
19981
19982 else
19983 Pragma_Misplaced;
19984 end if;
19985 end Lock_Free;
19986
19987 --------------------
19988 -- Locking_Policy --
19989 --------------------
19990
19991 -- pragma Locking_Policy (policy_IDENTIFIER);
19992
19993 when Pragma_Locking_Policy => declare
19994 subtype LP_Range is Name_Id
19995 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
19996 LP_Val : LP_Range;
19997 LP : Character;
19998
19999 begin
20000 Check_Ada_83_Warning;
20001 Check_Arg_Count (1);
20002 Check_No_Identifiers;
20003 Check_Arg_Is_Locking_Policy (Arg1);
20004 Check_Valid_Configuration_Pragma;
20005 LP_Val := Chars (Get_Pragma_Arg (Arg1));
20006
20007 case LP_Val is
20008 when Name_Ceiling_Locking => LP := 'C';
20009 when Name_Concurrent_Readers_Locking => LP := 'R';
20010 when Name_Inheritance_Locking => LP := 'I';
20011 end case;
20012
20013 if Locking_Policy /= ' '
20014 and then Locking_Policy /= LP
20015 then
20016 Error_Msg_Sloc := Locking_Policy_Sloc;
20017 Error_Pragma ("locking policy incompatible with policy#");
20018
20019 -- Set new policy, but always preserve System_Location since we
20020 -- like the error message with the run time name.
20021
20022 else
20023 Locking_Policy := LP;
20024
20025 if Locking_Policy_Sloc /= System_Location then
20026 Locking_Policy_Sloc := Loc;
20027 end if;
20028 end if;
20029 end;
20030
20031 -------------------
20032 -- Loop_Optimize --
20033 -------------------
20034
20035 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
20036
20037 -- OPTIMIZATION_HINT ::=
20038 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
20039
20040 when Pragma_Loop_Optimize => Loop_Optimize : declare
20041 Hint : Node_Id;
20042
20043 begin
20044 GNAT_Pragma;
20045 Check_At_Least_N_Arguments (1);
20046 Check_No_Identifiers;
20047
20048 Hint := First (Pragma_Argument_Associations (N));
20049 while Present (Hint) loop
20050 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
20051 Name_No_Unroll,
20052 Name_Unroll,
20053 Name_No_Vector,
20054 Name_Vector);
20055 Next (Hint);
20056 end loop;
20057
20058 Check_Loop_Pragma_Placement;
20059 end Loop_Optimize;
20060
20061 ------------------
20062 -- Loop_Variant --
20063 ------------------
20064
20065 -- pragma Loop_Variant
20066 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
20067
20068 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
20069
20070 -- CHANGE_DIRECTION ::= Increases | Decreases
20071
20072 when Pragma_Loop_Variant => Loop_Variant : declare
20073 Variant : Node_Id;
20074
20075 begin
20076 GNAT_Pragma;
20077 Check_At_Least_N_Arguments (1);
20078 Check_Loop_Pragma_Placement;
20079
20080 -- Process all increasing / decreasing expressions
20081
20082 Variant := First (Pragma_Argument_Associations (N));
20083 while Present (Variant) loop
20084 if Chars (Variant) = No_Name then
20085 Error_Pragma_Arg_Ident ("expect name `Increases`", Variant);
20086
20087 elsif Chars (Variant) not in
20088 Name_Decreases | Name_Increases | Name_Structural
20089 then
20090 declare
20091 Name : String := Get_Name_String (Chars (Variant));
20092
20093 begin
20094 -- It is a common mistake to write "Increasing" for
20095 -- "Increases" or "Decreasing" for "Decreases". Recognize
20096 -- specially names starting with "incr" or "decr" to
20097 -- suggest the corresponding name.
20098
20099 System.Case_Util.To_Lower (Name);
20100
20101 if Name'Length >= 4
20102 and then Name (1 .. 4) = "incr"
20103 then
20104 Error_Pragma_Arg_Ident
20105 ("expect name `Increases`", Variant);
20106
20107 elsif Name'Length >= 4
20108 and then Name (1 .. 4) = "decr"
20109 then
20110 Error_Pragma_Arg_Ident
20111 ("expect name `Decreases`", Variant);
20112
20113 elsif Name'Length >= 4
20114 and then Name (1 .. 4) = "stru"
20115 then
20116 Error_Pragma_Arg_Ident
20117 ("expect name `Structural`", Variant);
20118
20119 else
20120 Error_Pragma_Arg_Ident
20121 ("expect name `Increases`, `Decreases`,"
20122 & " or `Structural`", Variant);
20123 end if;
20124 end;
20125
20126 elsif Chars (Variant) = Name_Structural
20127 and then List_Length (Pragma_Argument_Associations (N)) > 1
20128 then
20129 Error_Pragma_Arg_Ident
20130 ("Structural variant shall be the only variant", Variant);
20131 end if;
20132
20133 -- Preanalyze_Assert_Expression, but without enforcing any of
20134 -- the two acceptable types.
20135
20136 Preanalyze_Assert_Expression (Expression (Variant));
20137
20138 -- Expression of a discrete type is allowed. Nothing to
20139 -- check for structural variants.
20140
20141 if Chars (Variant) = Name_Structural
20142 or else Is_Discrete_Type (Etype (Expression (Variant)))
20143 then
20144 null;
20145
20146 -- Expression of a Big_Integer type (or its ghost variant) is
20147 -- only allowed in Decreases clause.
20148
20149 elsif
20150 Is_RTE (Base_Type (Etype (Expression (Variant))),
20151 RE_Big_Integer)
20152 or else
20153 Is_RTE (Base_Type (Etype (Expression (Variant))),
20154 RO_GH_Big_Integer)
20155 then
20156 if Chars (Variant) = Name_Increases then
20157 Error_Msg_N
20158 ("Loop_Variant with Big_Integer can only decrease",
20159 Expression (Variant));
20160 end if;
20161
20162 -- Expression of other types is not allowed
20163
20164 else
20165 Error_Msg_N
20166 ("expected a discrete or Big_Integer type",
20167 Expression (Variant));
20168 end if;
20169
20170 Next (Variant);
20171 end loop;
20172 end Loop_Variant;
20173
20174 -----------------------
20175 -- Machine_Attribute --
20176 -----------------------
20177
20178 -- pragma Machine_Attribute (
20179 -- [Entity =>] LOCAL_NAME,
20180 -- [Attribute_Name =>] static_string_EXPRESSION
20181 -- [, [Info =>] static_EXPRESSION {, static_EXPRESSION}] );
20182
20183 when Pragma_Machine_Attribute => Machine_Attribute : declare
20184 Arg : Node_Id;
20185 Def_Id : Entity_Id;
20186
20187 begin
20188 GNAT_Pragma;
20189 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
20190
20191 if Arg_Count >= 3 then
20192 Check_Optional_Identifier (Arg3, Name_Info);
20193 Arg := Arg3;
20194 while Present (Arg) loop
20195 Check_Arg_Is_OK_Static_Expression (Arg);
20196 Arg := Next (Arg);
20197 end loop;
20198 else
20199 Check_Arg_Count (2);
20200 end if;
20201
20202 Check_Optional_Identifier (Arg1, Name_Entity);
20203 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
20204 Check_Arg_Is_Local_Name (Arg1);
20205 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
20206 Def_Id := Entity (Get_Pragma_Arg (Arg1));
20207
20208 -- Apply the pragma to the designated type, rather than to the
20209 -- access type, unless it's a strub annotation. We wish to enable
20210 -- objects of access type, as well as access types themselves, to
20211 -- be annotated, so that reading the access objects (as oposed to
20212 -- the designated data) automatically enables stack
20213 -- scrubbing. That said, as in the attribute handler that
20214 -- processes the pragma turned into a compiler attribute, a strub
20215 -- annotation that must be associated with a subprogram type (for
20216 -- holding an explicit strub mode), when applied to an
20217 -- access-to-subprogram, gets promoted to the subprogram type. We
20218 -- might be tempted to leave it alone here, since the C attribute
20219 -- handler will adjust it, but then GNAT would convert the
20220 -- annotated subprogram types to naked ones before using them,
20221 -- cancelling out their intended effects.
20222
20223 if Is_Access_Type (Def_Id)
20224 and then (not Strub_Pragma_P (N)
20225 or else
20226 (Present (Arg3)
20227 and then
20228 Ekind (Designated_Type
20229 (Def_Id)) = E_Subprogram_Type))
20230 then
20231 Def_Id := Designated_Type (Def_Id);
20232 end if;
20233
20234 if Rep_Item_Too_Early (Def_Id, N) then
20235 return;
20236 end if;
20237
20238 Def_Id := Underlying_Type (Def_Id);
20239
20240 -- The only processing required is to link this item on to the
20241 -- list of rep items for the given entity. This is accomplished
20242 -- by the call to Rep_Item_Too_Late (when no error is detected
20243 -- and False is returned).
20244
20245 if Rep_Item_Too_Late (Def_Id, N) then
20246 return;
20247 else
20248 Set_Has_Gigi_Rep_Item (Def_Id);
20249 end if;
20250 end Machine_Attribute;
20251
20252 ----------
20253 -- Main --
20254 ----------
20255
20256 -- pragma Main
20257 -- (MAIN_OPTION [, MAIN_OPTION]);
20258
20259 -- MAIN_OPTION ::=
20260 -- [STACK_SIZE =>] static_integer_EXPRESSION
20261 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
20262 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
20263
20264 when Pragma_Main => Main : declare
20265 Args : Args_List (1 .. 3);
20266 Names : constant Name_List (1 .. 3) := (
20267 Name_Stack_Size,
20268 Name_Task_Stack_Size_Default,
20269 Name_Time_Slicing_Enabled);
20270
20271 Nod : Node_Id;
20272
20273 begin
20274 GNAT_Pragma;
20275 Gather_Associations (Names, Args);
20276
20277 for J in 1 .. 2 loop
20278 if Present (Args (J)) then
20279 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
20280 end if;
20281 end loop;
20282
20283 if Present (Args (3)) then
20284 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
20285 end if;
20286
20287 Nod := Next (N);
20288 while Present (Nod) loop
20289 if Nkind (Nod) = N_Pragma
20290 and then Pragma_Name (Nod) = Name_Main
20291 then
20292 Error_Msg_Name_1 := Pname;
20293 Error_Msg_N ("duplicate pragma% not permitted", Nod);
20294 end if;
20295
20296 Next (Nod);
20297 end loop;
20298 end Main;
20299
20300 ------------------
20301 -- Main_Storage --
20302 ------------------
20303
20304 -- pragma Main_Storage
20305 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
20306
20307 -- MAIN_STORAGE_OPTION ::=
20308 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
20309 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
20310
20311 when Pragma_Main_Storage => Main_Storage : declare
20312 Args : Args_List (1 .. 2);
20313 Names : constant Name_List (1 .. 2) := (
20314 Name_Working_Storage,
20315 Name_Top_Guard);
20316
20317 Nod : Node_Id;
20318
20319 begin
20320 GNAT_Pragma;
20321 Gather_Associations (Names, Args);
20322
20323 for J in 1 .. 2 loop
20324 if Present (Args (J)) then
20325 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
20326 end if;
20327 end loop;
20328
20329 Check_In_Main_Program;
20330
20331 Nod := Next (N);
20332 while Present (Nod) loop
20333 if Nkind (Nod) = N_Pragma
20334 and then Pragma_Name (Nod) = Name_Main_Storage
20335 then
20336 Error_Msg_Name_1 := Pname;
20337 Error_Msg_N ("duplicate pragma% not permitted", Nod);
20338 end if;
20339
20340 Next (Nod);
20341 end loop;
20342 end Main_Storage;
20343
20344 ----------------------------
20345 -- Max_Entry_Queue_Length --
20346 ----------------------------
20347
20348 -- pragma Max_Entry_Queue_Length (static_integer_EXPRESSION);
20349
20350 -- This processing is shared by Pragma_Max_Entry_Queue_Depth and
20351 -- Pragma_Max_Queue_Length.
20352
20353 when Pragma_Max_Entry_Queue_Length
20354 | Pragma_Max_Entry_Queue_Depth
20355 | Pragma_Max_Queue_Length
20356 =>
20357 Max_Entry_Queue_Length : declare
20358 Arg : Node_Id;
20359 Entry_Decl : Node_Id;
20360 Entry_Id : Entity_Id;
20361 Val : Uint;
20362
20363 begin
20364 if Prag_Id = Pragma_Max_Entry_Queue_Depth
20365 or else Prag_Id = Pragma_Max_Queue_Length
20366 then
20367 GNAT_Pragma;
20368 end if;
20369
20370 Check_Arg_Count (1);
20371
20372 Entry_Decl :=
20373 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
20374
20375 -- Entry declaration
20376
20377 if Nkind (Entry_Decl) = N_Entry_Declaration then
20378
20379 -- Entry illegally within a task
20380
20381 if Nkind (Parent (N)) = N_Task_Definition then
20382 Error_Pragma ("pragma % cannot apply to task entries");
20383 end if;
20384
20385 Entry_Id := Defining_Entity (Entry_Decl);
20386
20387 -- Otherwise the pragma is associated with an illegal construct
20388
20389 else
20390 Error_Pragma
20391 ("pragma % must apply to a protected entry declaration");
20392 end if;
20393
20394 -- Mark the pragma as Ghost if the related subprogram is also
20395 -- Ghost. This also ensures that any expansion performed further
20396 -- below will produce Ghost nodes.
20397
20398 Mark_Ghost_Pragma (N, Entry_Id);
20399
20400 -- Analyze the Integer expression
20401
20402 Arg := Get_Pragma_Arg (Arg1);
20403 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
20404
20405 Val := Expr_Value (Arg);
20406
20407 if Val < -1 then
20408 Error_Pragma_Arg
20409 ("argument for pragma% cannot be less than -1", Arg1);
20410
20411 elsif not UI_Is_In_Int_Range (Val) then
20412 Error_Pragma_Arg
20413 ("argument for pragma% out of range of Integer", Arg1);
20414
20415 end if;
20416
20417 Record_Rep_Item (Entry_Id, N);
20418 end Max_Entry_Queue_Length;
20419
20420 -----------------
20421 -- Memory_Size --
20422 -----------------
20423
20424 -- pragma Memory_Size (NUMERIC_LITERAL)
20425
20426 when Pragma_Memory_Size =>
20427 GNAT_Pragma;
20428
20429 -- Memory size is simply ignored
20430
20431 Check_No_Identifiers;
20432 Check_Arg_Count (1);
20433 Check_Arg_Is_Integer_Literal (Arg1);
20434
20435 -------------
20436 -- No_Body --
20437 -------------
20438
20439 -- pragma No_Body;
20440
20441 -- The only correct use of this pragma is on its own in a file, in
20442 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
20443 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
20444 -- check for a file containing nothing but a No_Body pragma). If we
20445 -- attempt to process it during normal semantics processing, it means
20446 -- it was misplaced.
20447
20448 when Pragma_No_Body =>
20449 GNAT_Pragma;
20450 Pragma_Misplaced;
20451
20452 -----------------------------
20453 -- No_Elaboration_Code_All --
20454 -----------------------------
20455
20456 -- pragma No_Elaboration_Code_All;
20457
20458 when Pragma_No_Elaboration_Code_All =>
20459 GNAT_Pragma;
20460 Check_Valid_Library_Unit_Pragma;
20461
20462 -- If N was rewritten as a null statement there is nothing more
20463 -- to do.
20464
20465 if Nkind (N) = N_Null_Statement then
20466 return;
20467 end if;
20468
20469 -- Must appear for a spec or generic spec
20470
20471 if Nkind (Unit (Cunit (Current_Sem_Unit))) not in
20472 N_Generic_Package_Declaration |
20473 N_Generic_Subprogram_Declaration |
20474 N_Package_Declaration |
20475 N_Subprogram_Declaration
20476 then
20477 Error_Pragma
20478 (Fix_Error
20479 ("pragma% can only occur for package "
20480 & "or subprogram spec"));
20481 end if;
20482
20483 -- Set flag in unit table
20484
20485 Set_No_Elab_Code_All (Current_Sem_Unit);
20486
20487 -- Set restriction No_Elaboration_Code if this is the main unit
20488
20489 if Current_Sem_Unit = Main_Unit then
20490 Set_Restriction (No_Elaboration_Code, N);
20491 end if;
20492
20493 -- If we are in the main unit or in an extended main source unit,
20494 -- then we also add it to the configuration restrictions so that
20495 -- it will apply to all units in the extended main source.
20496
20497 if Current_Sem_Unit = Main_Unit
20498 or else In_Extended_Main_Source_Unit (N)
20499 then
20500 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
20501 end if;
20502
20503 -- If in main extended unit, activate transitive with test
20504
20505 if In_Extended_Main_Source_Unit (N) then
20506 Opt.No_Elab_Code_All_Pragma := N;
20507 end if;
20508
20509 -----------------------------
20510 -- No_Component_Reordering --
20511 -----------------------------
20512
20513 -- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
20514
20515 when Pragma_No_Component_Reordering => No_Comp_Reordering : declare
20516 E : Entity_Id;
20517 E_Id : Node_Id;
20518
20519 begin
20520 GNAT_Pragma;
20521 Check_At_Most_N_Arguments (1);
20522
20523 if Arg_Count = 0 then
20524 Check_Valid_Configuration_Pragma;
20525 Opt.No_Component_Reordering := True;
20526
20527 else
20528 Check_Optional_Identifier (Arg2, Name_Entity);
20529 Check_Arg_Is_Local_Name (Arg1);
20530 E_Id := Get_Pragma_Arg (Arg1);
20531
20532 if Etype (E_Id) = Any_Type then
20533 return;
20534 end if;
20535
20536 E := Entity (E_Id);
20537
20538 if not Is_Record_Type (E) then
20539 Error_Pragma_Arg ("pragma% requires record type", Arg1);
20540 end if;
20541
20542 Set_No_Reordering (Base_Type (E));
20543 end if;
20544 end No_Comp_Reordering;
20545
20546 --------------------------
20547 -- No_Heap_Finalization --
20548 --------------------------
20549
20550 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
20551
20552 when Pragma_No_Heap_Finalization => No_Heap_Finalization : declare
20553 Context : constant Node_Id := Parent (N);
20554 Typ_Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
20555 Prev : Node_Id;
20556 Typ : Entity_Id;
20557
20558 begin
20559 GNAT_Pragma;
20560 Check_No_Identifiers;
20561
20562 -- The pragma appears in a configuration file
20563
20564 if No (Context) then
20565 Check_Arg_Count (0);
20566 Check_Valid_Configuration_Pragma;
20567
20568 -- Detect a duplicate pragma
20569
20570 if Present (No_Heap_Finalization_Pragma) then
20571 Duplication_Error
20572 (Prag => N,
20573 Prev => No_Heap_Finalization_Pragma);
20574 raise Pragma_Exit;
20575 end if;
20576
20577 No_Heap_Finalization_Pragma := N;
20578
20579 -- Otherwise the pragma should be associated with a library-level
20580 -- named access-to-object type.
20581
20582 else
20583 Check_Arg_Count (1);
20584 Check_Arg_Is_Local_Name (Arg1);
20585
20586 Find_Type (Typ_Arg);
20587 Typ := Entity (Typ_Arg);
20588
20589 -- The type being subjected to the pragma is erroneous
20590
20591 if Typ = Any_Type then
20592 Error_Pragma ("cannot find type referenced by pragma %");
20593
20594 -- The pragma is applied to an incomplete or generic formal
20595 -- type way too early.
20596
20597 elsif Rep_Item_Too_Early (Typ, N) then
20598 return;
20599
20600 else
20601 Typ := Underlying_Type (Typ);
20602 end if;
20603
20604 -- The pragma must apply to an access-to-object type
20605
20606 if Ekind (Typ) in E_Access_Type | E_General_Access_Type then
20607 null;
20608
20609 -- Give a detailed error message on all other access type kinds
20610
20611 elsif Ekind (Typ) = E_Access_Protected_Subprogram_Type then
20612 Error_Pragma
20613 ("pragma % cannot apply to access protected subprogram "
20614 & "type");
20615
20616 elsif Ekind (Typ) = E_Access_Subprogram_Type then
20617 Error_Pragma
20618 ("pragma % cannot apply to access subprogram type");
20619
20620 elsif Is_Anonymous_Access_Type (Typ) then
20621 Error_Pragma
20622 ("pragma % cannot apply to anonymous access type");
20623
20624 -- Give a general error message in case the pragma applies to a
20625 -- non-access type.
20626
20627 else
20628 Error_Pragma
20629 ("pragma % must apply to library level access type");
20630 end if;
20631
20632 -- At this point the argument denotes an access-to-object type.
20633 -- Ensure that the type is declared at the library level.
20634
20635 if Is_Library_Level_Entity (Typ) then
20636 null;
20637
20638 -- Quietly ignore an access-to-object type originally declared
20639 -- at the library level within a generic, but instantiated at
20640 -- a non-library level. As a result the access-to-object type
20641 -- "loses" its No_Heap_Finalization property.
20642
20643 elsif In_Instance then
20644 raise Pragma_Exit;
20645
20646 else
20647 Error_Pragma
20648 ("pragma % must apply to library level access type");
20649 end if;
20650
20651 -- Detect a duplicate pragma
20652
20653 if Present (No_Heap_Finalization_Pragma) then
20654 Duplication_Error
20655 (Prag => N,
20656 Prev => No_Heap_Finalization_Pragma);
20657 raise Pragma_Exit;
20658
20659 else
20660 Prev := Get_Pragma (Typ, Pragma_No_Heap_Finalization);
20661
20662 if Present (Prev) then
20663 Duplication_Error
20664 (Prag => N,
20665 Prev => Prev);
20666 raise Pragma_Exit;
20667 end if;
20668 end if;
20669
20670 Record_Rep_Item (Typ, N);
20671 end if;
20672 end No_Heap_Finalization;
20673
20674 ---------------
20675 -- No_Inline --
20676 ---------------
20677
20678 -- pragma No_Inline ( NAME {, NAME} );
20679
20680 when Pragma_No_Inline =>
20681 GNAT_Pragma;
20682 Process_Inline (Suppressed);
20683
20684 ---------------
20685 -- No_Return --
20686 ---------------
20687
20688 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
20689
20690 when Pragma_No_Return => Prag_No_Return : declare
20691
20692 function Check_No_Return
20693 (E : Entity_Id;
20694 N : Node_Id) return Boolean;
20695 -- Check rule 6.5.1(4/3) of the Ada RM. If the rule is violated,
20696 -- emit an error message and return False, otherwise return True.
20697 -- 6.5.1 Nonreturning procedures:
20698 -- 4/3 "Aspect No_Return shall not be specified for a null
20699 -- procedure nor an instance of a generic unit."
20700
20701 ---------------------
20702 -- Check_No_Return --
20703 ---------------------
20704
20705 function Check_No_Return
20706 (E : Entity_Id;
20707 N : Node_Id) return Boolean
20708 is
20709 begin
20710 if Ekind (E) in E_Function | E_Generic_Function then
20711 Error_Msg_Ada_2022_Feature ("No_Return function", Sloc (N));
20712 return Ada_Version >= Ada_2022;
20713
20714 elsif Ekind (E) = E_Procedure then
20715
20716 -- If E is a generic instance, marking it with No_Return
20717 -- is forbidden, but having it inherit the No_Return of
20718 -- the generic is allowed. We check if E is inheriting its
20719 -- No_Return flag from the generic by checking if No_Return
20720 -- is already set.
20721
20722 if Is_Generic_Instance (E) and then not No_Return (E) then
20723 Error_Msg_NE
20724 ("generic instance & is marked as No_Return", N, E);
20725 Error_Msg_NE
20726 ("\generic procedure & must be marked No_Return",
20727 N,
20728 Generic_Parent (Parent (E)));
20729 return False;
20730
20731 elsif Null_Present (Subprogram_Specification (E)) then
20732 Error_Msg_NE
20733 ("null procedure & cannot be marked No_Return", N, E);
20734 return False;
20735 end if;
20736 end if;
20737
20738 return True;
20739 end Check_No_Return;
20740
20741 Arg : Node_Id;
20742 E : Entity_Id;
20743 Found : Boolean;
20744 Id : Node_Id;
20745
20746 Ghost_Error_Posted : Boolean := False;
20747 -- Flag set when an error concerning the illegal mix of Ghost and
20748 -- non-Ghost subprograms is emitted.
20749
20750 Ghost_Id : Entity_Id := Empty;
20751 -- The entity of the first Ghost procedure encountered while
20752 -- processing the arguments of the pragma.
20753
20754 begin
20755 Ada_2005_Pragma;
20756 Check_At_Least_N_Arguments (1);
20757
20758 -- Loop through arguments of pragma
20759
20760 Arg := Arg1;
20761 while Present (Arg) loop
20762 Check_Arg_Is_Local_Name (Arg);
20763 Id := Get_Pragma_Arg (Arg);
20764 Analyze (Id);
20765
20766 if not Is_Entity_Name (Id) then
20767 Error_Pragma_Arg ("entity name required", Arg);
20768 end if;
20769
20770 if Etype (Id) = Any_Type then
20771 raise Pragma_Exit;
20772 end if;
20773
20774 -- Loop to find matching procedures or functions (Ada 2022)
20775
20776 E := Entity (Id);
20777
20778 Found := False;
20779 while Present (E)
20780 and then Scope (E) = Current_Scope
20781 loop
20782 -- Ada 2022 (AI12-0269): A function can be No_Return
20783
20784 if Ekind (E) in E_Generic_Procedure | E_Procedure
20785 | E_Generic_Function | E_Function
20786 then
20787 -- Check that the pragma is not applied to a body.
20788 -- First check the specless body case, to give a
20789 -- different error message. These checks do not apply
20790 -- if Relaxed_RM_Semantics, to accommodate other Ada
20791 -- compilers. Disable these checks under -gnatd.J.
20792
20793 if not Debug_Flag_Dot_JJ then
20794 if Nkind (Parent (Declaration_Node (E))) =
20795 N_Subprogram_Body
20796 and then not Relaxed_RM_Semantics
20797 then
20798 Error_Pragma
20799 ("pragma% requires separate spec and must come "
20800 & "before body");
20801 end if;
20802
20803 -- Now the "specful" body case
20804
20805 if Rep_Item_Too_Late (E, N) then
20806 raise Pragma_Exit;
20807 end if;
20808 end if;
20809
20810 if Check_No_Return (E, N) then
20811 Set_No_Return (E);
20812 end if;
20813
20814 -- A pragma that applies to a Ghost entity becomes Ghost
20815 -- for the purposes of legality checks and removal of
20816 -- ignored Ghost code.
20817
20818 Mark_Ghost_Pragma (N, E);
20819
20820 -- Capture the entity of the first Ghost procedure being
20821 -- processed for error detection purposes.
20822
20823 if Is_Ghost_Entity (E) then
20824 if No (Ghost_Id) then
20825 Ghost_Id := E;
20826 end if;
20827
20828 -- Otherwise the subprogram is non-Ghost. It is illegal
20829 -- to mix references to Ghost and non-Ghost entities
20830 -- (SPARK RM 6.9).
20831
20832 elsif Present (Ghost_Id)
20833 and then not Ghost_Error_Posted
20834 then
20835 Ghost_Error_Posted := True;
20836
20837 Error_Msg_Name_1 := Pname;
20838 Error_Msg_N
20839 ("pragma % cannot mention ghost and non-ghost "
20840 & "procedures", N);
20841
20842 Error_Msg_Sloc := Sloc (Ghost_Id);
20843 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
20844
20845 Error_Msg_Sloc := Sloc (E);
20846 Error_Msg_NE ("\& # declared as non-ghost", N, E);
20847 end if;
20848
20849 -- Set flag on any alias as well
20850
20851 if Is_Overloadable (E)
20852 and then Present (Alias (E))
20853 and then Check_No_Return (Alias (E), N)
20854 then
20855 Set_No_Return (Alias (E));
20856 end if;
20857
20858 Found := True;
20859 end if;
20860
20861 exit when From_Aspect_Specification (N);
20862 E := Homonym (E);
20863 end loop;
20864
20865 -- If entity in not in current scope it may be the enclosing
20866 -- subprogram body to which the aspect applies.
20867
20868 if not Found then
20869 if Entity (Id) = Current_Scope
20870 and then From_Aspect_Specification (N)
20871 and then Check_No_Return (Entity (Id), N)
20872 then
20873 Set_No_Return (Entity (Id));
20874
20875 elsif Ada_Version >= Ada_2022 then
20876 Error_Pragma_Arg
20877 ("no subprogram& found for pragma%", Arg);
20878
20879 else
20880 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
20881 end if;
20882 end if;
20883
20884 Next (Arg);
20885 end loop;
20886 end Prag_No_Return;
20887
20888 -----------------
20889 -- No_Run_Time --
20890 -----------------
20891
20892 -- pragma No_Run_Time;
20893
20894 -- Note: this pragma is retained for backwards compatibility. See
20895 -- body of Rtsfind for full details on its handling.
20896
20897 when Pragma_No_Run_Time =>
20898 GNAT_Pragma;
20899 Check_Valid_Configuration_Pragma;
20900 Check_Arg_Count (0);
20901
20902 -- Remove backward compatibility if Build_Type is FSF or GPL and
20903 -- generate a warning.
20904
20905 declare
20906 Ignore : constant Boolean := Build_Type in FSF .. GPL;
20907 begin
20908 if Ignore then
20909 Error_Pragma ("pragma% is ignored, has no effect??");
20910 else
20911 No_Run_Time_Mode := True;
20912 Configurable_Run_Time_Mode := True;
20913
20914 -- Set Duration to 32 bits if word size is 32
20915
20916 if Ttypes.System_Word_Size = 32 then
20917 Duration_32_Bits_On_Target := True;
20918 end if;
20919
20920 -- Set appropriate restrictions
20921
20922 Set_Restriction (No_Finalization, N);
20923 Set_Restriction (No_Exception_Handlers, N);
20924 Set_Restriction (Max_Tasks, N, 0);
20925 Set_Restriction (No_Tasking, N);
20926 end if;
20927 end;
20928
20929 -----------------------
20930 -- No_Tagged_Streams --
20931 -----------------------
20932
20933 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
20934
20935 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
20936 E : Entity_Id;
20937 E_Id : Node_Id;
20938
20939 begin
20940 GNAT_Pragma;
20941 Check_At_Most_N_Arguments (1);
20942
20943 -- One argument case
20944
20945 if Arg_Count = 1 then
20946 Check_Optional_Identifier (Arg1, Name_Entity);
20947 Check_Arg_Is_Local_Name (Arg1);
20948 E_Id := Get_Pragma_Arg (Arg1);
20949
20950 if Etype (E_Id) = Any_Type then
20951 return;
20952 end if;
20953
20954 E := Entity (E_Id);
20955
20956 Check_Duplicate_Pragma (E);
20957
20958 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
20959 Error_Pragma_Arg
20960 ("argument for pragma% must be root tagged type", Arg1);
20961 end if;
20962
20963 if Rep_Item_Too_Early (E, N)
20964 or else
20965 Rep_Item_Too_Late (E, N)
20966 then
20967 return;
20968 else
20969 Set_No_Tagged_Streams_Pragma (E, N);
20970 end if;
20971
20972 -- Zero argument case
20973
20974 else
20975 Check_Is_In_Decl_Part_Or_Package_Spec;
20976 No_Tagged_Streams := N;
20977 end if;
20978 end No_Tagged_Strms;
20979
20980 ------------------------
20981 -- No_Strict_Aliasing --
20982 ------------------------
20983
20984 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
20985
20986 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
20987 E : Entity_Id;
20988 E_Id : Node_Id;
20989
20990 begin
20991 GNAT_Pragma;
20992 Check_At_Most_N_Arguments (1);
20993
20994 if Arg_Count = 0 then
20995 Check_Valid_Configuration_Pragma;
20996 Opt.No_Strict_Aliasing := True;
20997
20998 else
20999 Check_Optional_Identifier (Arg2, Name_Entity);
21000 Check_Arg_Is_Local_Name (Arg1);
21001 E_Id := Get_Pragma_Arg (Arg1);
21002
21003 if Etype (E_Id) = Any_Type then
21004 return;
21005 end if;
21006
21007 E := Entity (E_Id);
21008
21009 if not Is_Access_Type (E) then
21010 Error_Pragma_Arg ("pragma% requires access type", Arg1);
21011 end if;
21012
21013 Set_No_Strict_Aliasing (Base_Type (E));
21014 end if;
21015 end No_Strict_Aliasing;
21016
21017 -----------------------
21018 -- Normalize_Scalars --
21019 -----------------------
21020
21021 -- pragma Normalize_Scalars;
21022
21023 when Pragma_Normalize_Scalars =>
21024 Check_Ada_83_Warning;
21025 Check_Arg_Count (0);
21026 Check_Valid_Configuration_Pragma;
21027
21028 -- Normalize_Scalars creates false positives in CodePeer, and
21029 -- incorrect negative results in GNATprove mode, so ignore this
21030 -- pragma in these modes.
21031
21032 if not (CodePeer_Mode or GNATprove_Mode) then
21033 Normalize_Scalars := True;
21034 Init_Or_Norm_Scalars := True;
21035 end if;
21036
21037 -----------------
21038 -- Obsolescent --
21039 -----------------
21040
21041 -- pragma Obsolescent;
21042
21043 -- pragma Obsolescent (
21044 -- [Message =>] static_string_EXPRESSION
21045 -- [,[Version =>] Ada_05]);
21046
21047 -- pragma Obsolescent (
21048 -- [Entity =>] NAME
21049 -- [,[Message =>] static_string_EXPRESSION
21050 -- [,[Version =>] Ada_05]]);
21051
21052 when Pragma_Obsolescent => Obsolescent : declare
21053 Decl : Node_Id;
21054 Ename : Node_Id;
21055
21056 procedure Set_Obsolescent (E : Entity_Id);
21057 -- Given an entity Ent, mark it as obsolescent if appropriate
21058
21059 ---------------------
21060 -- Set_Obsolescent --
21061 ---------------------
21062
21063 procedure Set_Obsolescent (E : Entity_Id) is
21064 Active : Boolean;
21065 Ent : Entity_Id;
21066 S : String_Id;
21067
21068 begin
21069 Active := True;
21070 Ent := E;
21071
21072 -- A pragma that applies to a Ghost entity becomes Ghost for
21073 -- the purposes of legality checks and removal of ignored Ghost
21074 -- code.
21075
21076 Mark_Ghost_Pragma (N, E);
21077
21078 -- Entity name was given
21079
21080 if Present (Ename) then
21081
21082 -- If entity name matches, we are fine.
21083
21084 if Chars (Ename) = Chars (Ent) then
21085 Set_Entity (Ename, Ent);
21086 Generate_Reference (Ent, Ename);
21087
21088 -- If entity name does not match, only possibility is an
21089 -- enumeration literal from an enumeration type declaration.
21090
21091 elsif Ekind (Ent) /= E_Enumeration_Type then
21092 Error_Pragma
21093 ("pragma % entity name does not match declaration");
21094
21095 else
21096 Ent := First_Literal (E);
21097 loop
21098 if No (Ent) then
21099 Error_Pragma
21100 ("pragma % entity name does not match any "
21101 & "enumeration literal");
21102
21103 elsif Chars (Ent) = Chars (Ename) then
21104 Set_Entity (Ename, Ent);
21105 Generate_Reference (Ent, Ename);
21106 exit;
21107
21108 else
21109 Next_Literal (Ent);
21110 end if;
21111 end loop;
21112 end if;
21113 end if;
21114
21115 -- Ent points to entity to be marked
21116
21117 if Arg_Count >= 1 then
21118
21119 -- Deal with static string argument
21120
21121 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
21122 S := Strval (Get_Pragma_Arg (Arg1));
21123
21124 for J in 1 .. String_Length (S) loop
21125 if not In_Character_Range (Get_String_Char (S, J)) then
21126 Error_Pragma_Arg
21127 ("pragma% argument does not allow wide characters",
21128 Arg1);
21129 end if;
21130 end loop;
21131
21132 Obsolescent_Warnings.Append
21133 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
21134
21135 -- Check for Ada_05 parameter
21136
21137 if Arg_Count /= 1 then
21138 Check_Arg_Count (2);
21139
21140 declare
21141 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
21142
21143 begin
21144 Check_Arg_Is_Identifier (Argx);
21145
21146 if Chars (Argx) /= Name_Ada_05 then
21147 Error_Msg_Name_2 := Name_Ada_05;
21148 Error_Pragma_Arg
21149 ("only allowed argument for pragma% is %", Argx);
21150 end if;
21151
21152 if Ada_Version_Explicit < Ada_2005
21153 or else not Warn_On_Ada_2005_Compatibility
21154 then
21155 Active := False;
21156 end if;
21157 end;
21158 end if;
21159 end if;
21160
21161 -- Set flag if pragma active
21162
21163 if Active then
21164 Set_Is_Obsolescent (Ent);
21165 end if;
21166
21167 return;
21168 end Set_Obsolescent;
21169
21170 -- Start of processing for pragma Obsolescent
21171
21172 begin
21173 GNAT_Pragma;
21174
21175 Check_At_Most_N_Arguments (3);
21176
21177 -- See if first argument specifies an entity name
21178
21179 if Arg_Count >= 1
21180 and then
21181 (Chars (Arg1) = Name_Entity
21182 or else
21183 Nkind (Get_Pragma_Arg (Arg1)) in
21184 N_Character_Literal | N_Identifier | N_Operator_Symbol)
21185 then
21186 Ename := Get_Pragma_Arg (Arg1);
21187
21188 -- Eliminate first argument, so we can share processing
21189
21190 Arg1 := Arg2;
21191 Arg2 := Arg3;
21192 Arg_Count := Arg_Count - 1;
21193
21194 -- No Entity name argument given
21195
21196 else
21197 Ename := Empty;
21198 end if;
21199
21200 if Arg_Count >= 1 then
21201 Check_Optional_Identifier (Arg1, Name_Message);
21202
21203 if Arg_Count = 2 then
21204 Check_Optional_Identifier (Arg2, Name_Version);
21205 end if;
21206 end if;
21207
21208 -- Get immediately preceding declaration
21209
21210 Decl := Prev (N);
21211 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
21212 Prev (Decl);
21213 end loop;
21214
21215 -- Cases where we do not follow anything other than another pragma
21216
21217 if No (Decl) then
21218
21219 -- Case 0: library level compilation unit declaration with
21220 -- the pragma preceding the declaration.
21221
21222 if Nkind (Parent (N)) = N_Compilation_Unit then
21223 Pragma_Misplaced;
21224
21225 -- Case 1: library level compilation unit declaration with
21226 -- the pragma immediately following the declaration.
21227
21228 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
21229 Set_Obsolescent
21230 (Defining_Entity (Unit (Parent (Parent (N)))));
21231 return;
21232
21233 -- Case 2: library unit placement for package
21234
21235 else
21236 declare
21237 Ent : constant Entity_Id := Find_Lib_Unit_Name;
21238 begin
21239 if Is_Package_Or_Generic_Package (Ent) then
21240 Set_Obsolescent (Ent);
21241 return;
21242 end if;
21243 end;
21244 end if;
21245
21246 -- Cases where we must follow a declaration, including an
21247 -- abstract subprogram declaration, which is not in the
21248 -- other node subtypes.
21249
21250 else
21251 if Nkind (Decl) not in N_Declaration
21252 and then Nkind (Decl) not in N_Later_Decl_Item
21253 and then Nkind (Decl) not in N_Generic_Declaration
21254 and then Nkind (Decl) not in N_Renaming_Declaration
21255 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
21256 then
21257 Error_Pragma
21258 ("pragma% misplaced, "
21259 & "must immediately follow a declaration");
21260
21261 else
21262 Set_Obsolescent (Defining_Entity (Decl));
21263 return;
21264 end if;
21265 end if;
21266 end Obsolescent;
21267
21268 --------------
21269 -- Optimize --
21270 --------------
21271
21272 -- pragma Optimize (Time | Space | Off);
21273
21274 -- The actual check for optimize is done in Gigi. Note that this
21275 -- pragma does not actually change the optimization setting, it
21276 -- simply checks that it is consistent with the pragma.
21277
21278 when Pragma_Optimize =>
21279 Check_No_Identifiers;
21280 Check_Arg_Count (1);
21281 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
21282
21283 ------------------------
21284 -- Optimize_Alignment --
21285 ------------------------
21286
21287 -- pragma Optimize_Alignment (Time | Space | Off);
21288
21289 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
21290 GNAT_Pragma;
21291 Check_No_Identifiers;
21292 Check_Arg_Count (1);
21293 Check_Valid_Configuration_Pragma;
21294
21295 declare
21296 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
21297 begin
21298 case Nam is
21299 when Name_Off => Opt.Optimize_Alignment := 'O';
21300 when Name_Space => Opt.Optimize_Alignment := 'S';
21301 when Name_Time => Opt.Optimize_Alignment := 'T';
21302
21303 when others =>
21304 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
21305 end case;
21306 end;
21307
21308 -- Set indication that mode is set locally. If we are in fact in a
21309 -- configuration pragma file, this setting is harmless since the
21310 -- switch will get reset anyway at the start of each unit.
21311
21312 Optimize_Alignment_Local := True;
21313 end Optimize_Alignment;
21314
21315 -------------
21316 -- Ordered --
21317 -------------
21318
21319 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
21320
21321 when Pragma_Ordered => Ordered : declare
21322 Assoc : constant Node_Id := Arg1;
21323 Type_Id : Node_Id;
21324 Typ : Entity_Id;
21325
21326 begin
21327 GNAT_Pragma;
21328 Check_No_Identifiers;
21329 Check_Arg_Count (1);
21330 Check_Arg_Is_Local_Name (Arg1);
21331
21332 Type_Id := Get_Pragma_Arg (Assoc);
21333 Find_Type (Type_Id);
21334 Typ := Entity (Type_Id);
21335
21336 if Typ = Any_Type then
21337 return;
21338 else
21339 Typ := Underlying_Type (Typ);
21340 end if;
21341
21342 if not Is_Enumeration_Type (Typ) then
21343 Error_Pragma ("pragma% must specify enumeration type");
21344 end if;
21345
21346 Check_First_Subtype (Arg1);
21347 Set_Has_Pragma_Ordered (Base_Type (Typ));
21348 end Ordered;
21349
21350 -------------------
21351 -- Overflow_Mode --
21352 -------------------
21353
21354 -- pragma Overflow_Mode
21355 -- ([General => ] MODE [, [Assertions => ] MODE]);
21356
21357 -- MODE := STRICT | MINIMIZED | ELIMINATED
21358
21359 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
21360 -- since System.Bignums makes this assumption. This is true of nearly
21361 -- all (all?) targets.
21362
21363 when Pragma_Overflow_Mode => Overflow_Mode : declare
21364 function Get_Overflow_Mode
21365 (Name : Name_Id;
21366 Arg : Node_Id) return Overflow_Mode_Type;
21367 -- Function to process one pragma argument, Arg. If an identifier
21368 -- is present, it must be Name. Mode type is returned if a valid
21369 -- argument exists, otherwise an error is signalled.
21370
21371 -----------------------
21372 -- Get_Overflow_Mode --
21373 -----------------------
21374
21375 function Get_Overflow_Mode
21376 (Name : Name_Id;
21377 Arg : Node_Id) return Overflow_Mode_Type
21378 is
21379 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
21380
21381 begin
21382 Check_Optional_Identifier (Arg, Name);
21383 Check_Arg_Is_Identifier (Argx);
21384
21385 if Chars (Argx) = Name_Strict then
21386 return Strict;
21387
21388 elsif Chars (Argx) = Name_Minimized then
21389 return Minimized;
21390
21391 elsif Chars (Argx) = Name_Eliminated then
21392 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
21393 Error_Pragma_Arg
21394 ("Eliminated requires Long_Long_Integer'Size = 64",
21395 Argx);
21396 else
21397 return Eliminated;
21398 end if;
21399
21400 else
21401 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
21402 end if;
21403 end Get_Overflow_Mode;
21404
21405 -- Start of processing for Overflow_Mode
21406
21407 begin
21408 GNAT_Pragma;
21409 Check_At_Least_N_Arguments (1);
21410 Check_At_Most_N_Arguments (2);
21411
21412 -- Process first argument
21413
21414 Scope_Suppress.Overflow_Mode_General :=
21415 Get_Overflow_Mode (Name_General, Arg1);
21416
21417 -- Case of only one argument
21418
21419 if Arg_Count = 1 then
21420 Scope_Suppress.Overflow_Mode_Assertions :=
21421 Scope_Suppress.Overflow_Mode_General;
21422
21423 -- Case of two arguments present
21424
21425 else
21426 Scope_Suppress.Overflow_Mode_Assertions :=
21427 Get_Overflow_Mode (Name_Assertions, Arg2);
21428 end if;
21429 end Overflow_Mode;
21430
21431 --------------------------
21432 -- Overriding Renamings --
21433 --------------------------
21434
21435 -- pragma Overriding_Renamings;
21436
21437 when Pragma_Overriding_Renamings =>
21438 GNAT_Pragma;
21439 Check_Arg_Count (0);
21440 Check_Valid_Configuration_Pragma;
21441 Overriding_Renamings := True;
21442
21443 ----------
21444 -- Pack --
21445 ----------
21446
21447 -- pragma Pack (first_subtype_LOCAL_NAME);
21448
21449 when Pragma_Pack => Pack : declare
21450 Assoc : constant Node_Id := Arg1;
21451 Ctyp : Entity_Id;
21452 Ignore : Boolean := False;
21453 Typ : Entity_Id;
21454 Type_Id : Node_Id;
21455
21456 begin
21457 Check_No_Identifiers;
21458 Check_Arg_Count (1);
21459 Check_Arg_Is_Local_Name (Arg1);
21460 Type_Id := Get_Pragma_Arg (Assoc);
21461
21462 if not Is_Entity_Name (Type_Id)
21463 or else not Is_Type (Entity (Type_Id))
21464 then
21465 Error_Pragma_Arg
21466 ("argument for pragma% must be type or subtype", Arg1);
21467 end if;
21468
21469 Find_Type (Type_Id);
21470 Typ := Entity (Type_Id);
21471
21472 if Typ = Any_Type
21473 or else Rep_Item_Too_Early (Typ, N)
21474 then
21475 return;
21476 else
21477 Typ := Underlying_Type (Typ);
21478 end if;
21479
21480 -- A pragma that applies to a Ghost entity becomes Ghost for the
21481 -- purposes of legality checks and removal of ignored Ghost code.
21482
21483 Mark_Ghost_Pragma (N, Typ);
21484
21485 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
21486 Error_Pragma ("pragma% must specify array or record type");
21487 end if;
21488
21489 Check_First_Subtype (Arg1);
21490 Check_Duplicate_Pragma (Typ);
21491
21492 -- Array type
21493
21494 if Is_Array_Type (Typ) then
21495 Ctyp := Component_Type (Typ);
21496
21497 -- Ignore pack that does nothing
21498
21499 if Known_Static_Esize (Ctyp)
21500 and then Known_Static_RM_Size (Ctyp)
21501 and then Esize (Ctyp) = RM_Size (Ctyp)
21502 and then Addressable (Esize (Ctyp))
21503 then
21504 Ignore := True;
21505 end if;
21506
21507 -- Process OK pragma Pack. Note that if there is a separate
21508 -- component clause present, the Pack will be cancelled. This
21509 -- processing is in Freeze.
21510
21511 if not Rep_Item_Too_Late (Typ, N) then
21512
21513 -- In CodePeer mode, we do not need complex front-end
21514 -- expansions related to pragma Pack, so disable handling
21515 -- of pragma Pack.
21516
21517 if CodePeer_Mode then
21518 null;
21519
21520 -- Normal case where we do the pack action
21521
21522 else
21523 if not Ignore then
21524 Set_Is_Packed (Base_Type (Typ));
21525 Set_Has_Non_Standard_Rep (Base_Type (Typ));
21526 end if;
21527
21528 Set_Has_Pragma_Pack (Base_Type (Typ));
21529 end if;
21530 end if;
21531
21532 -- For record types, the pack is always effective
21533
21534 else pragma Assert (Is_Record_Type (Typ));
21535 if not Rep_Item_Too_Late (Typ, N) then
21536 Set_Is_Packed (Base_Type (Typ));
21537 Set_Has_Pragma_Pack (Base_Type (Typ));
21538 Set_Has_Non_Standard_Rep (Base_Type (Typ));
21539 end if;
21540 end if;
21541 end Pack;
21542
21543 ----------
21544 -- Page --
21545 ----------
21546
21547 -- pragma Page;
21548
21549 -- There is nothing to do here, since we did all the processing for
21550 -- this pragma in Par.Prag (so that it works properly even in syntax
21551 -- only mode).
21552
21553 when Pragma_Page =>
21554 null;
21555
21556 -------------
21557 -- Part_Of --
21558 -------------
21559
21560 -- pragma Part_Of (ABSTRACT_STATE);
21561
21562 -- ABSTRACT_STATE ::= NAME
21563
21564 when Pragma_Part_Of => Part_Of : declare
21565 procedure Propagate_Part_Of
21566 (Pack_Id : Entity_Id;
21567 State_Id : Entity_Id;
21568 Instance : Node_Id);
21569 -- Propagate the Part_Of indicator to all abstract states and
21570 -- objects declared in the visible state space of a package
21571 -- denoted by Pack_Id. State_Id is the encapsulating state.
21572 -- Instance is the package instantiation node.
21573
21574 -----------------------
21575 -- Propagate_Part_Of --
21576 -----------------------
21577
21578 procedure Propagate_Part_Of
21579 (Pack_Id : Entity_Id;
21580 State_Id : Entity_Id;
21581 Instance : Node_Id)
21582 is
21583 Has_Item : Boolean := False;
21584 -- Flag set when the visible state space contains at least one
21585 -- abstract state or variable.
21586
21587 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
21588 -- Propagate the Part_Of indicator to all abstract states and
21589 -- objects declared in the visible state space of a package
21590 -- denoted by Pack_Id.
21591
21592 -----------------------
21593 -- Propagate_Part_Of --
21594 -----------------------
21595
21596 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
21597 Constits : Elist_Id;
21598 Item_Id : Entity_Id;
21599
21600 begin
21601 -- Traverse the entity chain of the package and set relevant
21602 -- attributes of abstract states and objects declared in the
21603 -- visible state space of the package.
21604
21605 Item_Id := First_Entity (Pack_Id);
21606 while Present (Item_Id)
21607 and then not In_Private_Part (Item_Id)
21608 loop
21609 -- Do not consider internally generated items
21610
21611 if not Comes_From_Source (Item_Id) then
21612 null;
21613
21614 -- Do not consider generic formals or their corresponding
21615 -- actuals because they are not part of a visible state.
21616 -- Note that both entities are marked as hidden.
21617
21618 elsif Is_Hidden (Item_Id) then
21619 null;
21620
21621 -- The Part_Of indicator turns an abstract state or an
21622 -- object into a constituent of the encapsulating state.
21623 -- Note that constants are considered here even though
21624 -- they may not depend on variable input. This check is
21625 -- left to the SPARK prover.
21626
21627 elsif Ekind (Item_Id) in
21628 E_Abstract_State | E_Constant | E_Variable
21629 then
21630 Has_Item := True;
21631 Constits := Part_Of_Constituents (State_Id);
21632
21633 if No (Constits) then
21634 Constits := New_Elmt_List;
21635 Set_Part_Of_Constituents (State_Id, Constits);
21636 end if;
21637
21638 Append_Elmt (Item_Id, Constits);
21639 Set_Encapsulating_State (Item_Id, State_Id);
21640
21641 -- Recursively handle nested packages and instantiations
21642
21643 elsif Ekind (Item_Id) = E_Package then
21644 Propagate_Part_Of (Item_Id);
21645 end if;
21646
21647 Next_Entity (Item_Id);
21648 end loop;
21649 end Propagate_Part_Of;
21650
21651 -- Start of processing for Propagate_Part_Of
21652
21653 begin
21654 Propagate_Part_Of (Pack_Id);
21655
21656 -- Detect a package instantiation that is subject to a Part_Of
21657 -- indicator, but has no visible state.
21658
21659 if not Has_Item then
21660 SPARK_Msg_NE
21661 ("package instantiation & has Part_Of indicator but "
21662 & "lacks visible state", Instance, Pack_Id);
21663 end if;
21664 end Propagate_Part_Of;
21665
21666 -- Local variables
21667
21668 Constits : Elist_Id;
21669 Encap : Node_Id;
21670 Encap_Id : Entity_Id;
21671 Item_Id : Entity_Id;
21672 Legal : Boolean;
21673 Stmt : Node_Id;
21674
21675 -- Start of processing for Part_Of
21676
21677 begin
21678 GNAT_Pragma;
21679 Check_No_Identifiers;
21680 Check_Arg_Count (1);
21681
21682 Stmt := Find_Related_Context (N, Do_Checks => True);
21683
21684 -- Object declaration
21685
21686 if Nkind (Stmt) = N_Object_Declaration then
21687 null;
21688
21689 -- Package instantiation
21690
21691 elsif Nkind (Stmt) = N_Package_Instantiation then
21692 null;
21693
21694 -- Single concurrent type declaration
21695
21696 elsif Is_Single_Concurrent_Type_Declaration (Stmt) then
21697 null;
21698
21699 -- Otherwise the pragma is associated with an illegal construct
21700
21701 else
21702 Pragma_Misplaced;
21703 end if;
21704
21705 -- Extract the entity of the related object declaration or package
21706 -- instantiation. In the case of the instantiation, use the entity
21707 -- of the instance spec.
21708
21709 if Nkind (Stmt) = N_Package_Instantiation then
21710 Stmt := Instance_Spec (Stmt);
21711 end if;
21712
21713 Item_Id := Defining_Entity (Stmt);
21714
21715 -- A pragma that applies to a Ghost entity becomes Ghost for the
21716 -- purposes of legality checks and removal of ignored Ghost code.
21717
21718 Mark_Ghost_Pragma (N, Item_Id);
21719
21720 -- Chain the pragma on the contract for further processing by
21721 -- Analyze_Part_Of_In_Decl_Part or for completeness.
21722
21723 Add_Contract_Item (N, Item_Id);
21724
21725 -- A variable may act as constituent of a single concurrent type
21726 -- which in turn could be declared after the variable. Due to this
21727 -- discrepancy, the full analysis of indicator Part_Of is delayed
21728 -- until the end of the enclosing declarative region (see routine
21729 -- Analyze_Part_Of_In_Decl_Part).
21730
21731 if Ekind (Item_Id) = E_Variable then
21732 null;
21733
21734 -- Otherwise indicator Part_Of applies to a constant or a package
21735 -- instantiation.
21736
21737 else
21738 Encap := Get_Pragma_Arg (Arg1);
21739
21740 -- Detect any discrepancies between the placement of the
21741 -- constant or package instantiation with respect to state
21742 -- space and the encapsulating state.
21743
21744 Analyze_Part_Of
21745 (Indic => N,
21746 Item_Id => Item_Id,
21747 Encap => Encap,
21748 Encap_Id => Encap_Id,
21749 Legal => Legal);
21750
21751 if Legal then
21752 pragma Assert (Present (Encap_Id));
21753
21754 if Ekind (Item_Id) = E_Constant then
21755 Constits := Part_Of_Constituents (Encap_Id);
21756
21757 if No (Constits) then
21758 Constits := New_Elmt_List;
21759 Set_Part_Of_Constituents (Encap_Id, Constits);
21760 end if;
21761
21762 Append_Elmt (Item_Id, Constits);
21763 Set_Encapsulating_State (Item_Id, Encap_Id);
21764
21765 -- Propagate the Part_Of indicator to the visible state
21766 -- space of the package instantiation.
21767
21768 else
21769 Propagate_Part_Of
21770 (Pack_Id => Item_Id,
21771 State_Id => Encap_Id,
21772 Instance => Stmt);
21773 end if;
21774 end if;
21775 end if;
21776 end Part_Of;
21777
21778 ----------------------------------
21779 -- Partition_Elaboration_Policy --
21780 ----------------------------------
21781
21782 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
21783
21784 when Pragma_Partition_Elaboration_Policy => PEP : declare
21785 subtype PEP_Range is Name_Id
21786 range First_Partition_Elaboration_Policy_Name
21787 .. Last_Partition_Elaboration_Policy_Name;
21788 PEP_Val : PEP_Range;
21789 PEP : Character;
21790
21791 begin
21792 Ada_2005_Pragma;
21793 Check_Arg_Count (1);
21794 Check_No_Identifiers;
21795 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
21796 Check_Valid_Configuration_Pragma;
21797 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
21798
21799 case PEP_Val is
21800 when Name_Concurrent => PEP := 'C';
21801 when Name_Sequential => PEP := 'S';
21802 end case;
21803
21804 if Partition_Elaboration_Policy /= ' '
21805 and then Partition_Elaboration_Policy /= PEP
21806 then
21807 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
21808 Error_Pragma
21809 ("partition elaboration policy incompatible with policy#");
21810
21811 -- Set new policy, but always preserve System_Location since we
21812 -- like the error message with the run time name.
21813
21814 else
21815 Partition_Elaboration_Policy := PEP;
21816
21817 if Partition_Elaboration_Policy_Sloc /= System_Location then
21818 Partition_Elaboration_Policy_Sloc := Loc;
21819 end if;
21820
21821 if PEP_Val = Name_Sequential
21822 and then not Restriction_Active (No_Task_Hierarchy)
21823 then
21824 -- RM H.6(6) guarantees that No_Task_Hierarchy will be
21825 -- set eventually, so take advantage of that knowledge now.
21826 -- But we have to do this in a tricky way. If we simply
21827 -- set the No_Task_Hierarchy restriction here, then the
21828 -- assumption that the restriction will be set eventually
21829 -- becomes a self-fulfilling prophecy; the binder can
21830 -- then mistakenly conclude that the H.6(6) rule is
21831 -- satisified in cases where the post-compilation check
21832 -- should fail. So we invent a new restriction,
21833 -- No_Task_Hierarchy_Implicit, which is treated specially
21834 -- in the function Restriction_Active.
21835
21836 Set_Restriction (No_Task_Hierarchy_Implicit, N);
21837 pragma Assert (Restriction_Active (No_Task_Hierarchy));
21838 end if;
21839 end if;
21840 end PEP;
21841
21842 -------------
21843 -- Passive --
21844 -------------
21845
21846 -- pragma Passive [(PASSIVE_FORM)];
21847
21848 -- PASSIVE_FORM ::= Semaphore | No
21849
21850 when Pragma_Passive =>
21851 GNAT_Pragma;
21852
21853 if Nkind (Parent (N)) /= N_Task_Definition then
21854 Error_Pragma ("pragma% must be within task definition");
21855 end if;
21856
21857 if Arg_Count /= 0 then
21858 Check_Arg_Count (1);
21859 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
21860 end if;
21861
21862 ----------------------------------
21863 -- Preelaborable_Initialization --
21864 ----------------------------------
21865
21866 -- pragma Preelaborable_Initialization (DIRECT_NAME);
21867
21868 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
21869 Ent : Entity_Id;
21870
21871 begin
21872 Ada_2005_Pragma;
21873 Check_Arg_Count (1);
21874 Check_No_Identifiers;
21875 Check_Arg_Is_Identifier (Arg1);
21876 Check_Arg_Is_Local_Name (Arg1);
21877 Check_First_Subtype (Arg1);
21878 Ent := Entity (Get_Pragma_Arg (Arg1));
21879
21880 -- A pragma that applies to a Ghost entity becomes Ghost for the
21881 -- purposes of legality checks and removal of ignored Ghost code.
21882
21883 Mark_Ghost_Pragma (N, Ent);
21884
21885 -- The pragma may come from an aspect on a private declaration,
21886 -- even if the freeze point at which this is analyzed in the
21887 -- private part after the full view.
21888
21889 if Has_Private_Declaration (Ent)
21890 and then From_Aspect_Specification (N)
21891 then
21892 null;
21893
21894 -- Check appropriate type argument
21895
21896 elsif Is_Private_Type (Ent)
21897 or else Is_Protected_Type (Ent)
21898 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
21899
21900 -- AI05-0028: The pragma applies to all composite types. Note
21901 -- that we apply this binding interpretation to earlier versions
21902 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
21903 -- choice since there are other compilers that do the same.
21904
21905 or else Is_Composite_Type (Ent)
21906 then
21907 null;
21908
21909 else
21910 Error_Pragma_Arg
21911 ("pragma % can only be applied to private, formal derived, "
21912 & "protected, or composite type", Arg1);
21913 end if;
21914
21915 -- Give an error if the pragma is applied to a protected type that
21916 -- does not qualify (due to having entries, or due to components
21917 -- that do not qualify).
21918
21919 if Is_Protected_Type (Ent)
21920 and then not Has_Preelaborable_Initialization (Ent)
21921 then
21922 Error_Msg_N
21923 ("protected type & does not have preelaborable "
21924 & "initialization", Ent);
21925
21926 -- Otherwise mark the type as definitely having preelaborable
21927 -- initialization.
21928
21929 else
21930 Set_Known_To_Have_Preelab_Init (Ent);
21931 end if;
21932
21933 if Has_Pragma_Preelab_Init (Ent)
21934 and then Warn_On_Redundant_Constructs
21935 then
21936 Error_Pragma ("?r?duplicate pragma%!");
21937 else
21938 Set_Has_Pragma_Preelab_Init (Ent);
21939 end if;
21940 end Preelab_Init;
21941
21942 --------------------
21943 -- Persistent_BSS --
21944 --------------------
21945
21946 -- pragma Persistent_BSS [(object_NAME)];
21947
21948 when Pragma_Persistent_BSS => Persistent_BSS : declare
21949 Decl : Node_Id;
21950 Ent : Entity_Id;
21951 Prag : Node_Id;
21952
21953 begin
21954 GNAT_Pragma;
21955 Check_At_Most_N_Arguments (1);
21956
21957 -- Case of application to specific object (one argument)
21958
21959 if Arg_Count = 1 then
21960 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21961
21962 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
21963 or else
21964 Ekind (Entity (Get_Pragma_Arg (Arg1))) not in
21965 E_Variable | E_Constant
21966 then
21967 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
21968 end if;
21969
21970 Ent := Entity (Get_Pragma_Arg (Arg1));
21971
21972 -- A pragma that applies to a Ghost entity becomes Ghost for
21973 -- the purposes of legality checks and removal of ignored Ghost
21974 -- code.
21975
21976 Mark_Ghost_Pragma (N, Ent);
21977
21978 -- Check for duplication before inserting in list of
21979 -- representation items.
21980
21981 Check_Duplicate_Pragma (Ent);
21982
21983 if Rep_Item_Too_Late (Ent, N) then
21984 return;
21985 end if;
21986
21987 Decl := Parent (Ent);
21988
21989 if Present (Expression (Decl)) then
21990 -- Variables in Persistent_BSS cannot be initialized, so
21991 -- turn off any initialization that might be caused by
21992 -- pragmas Initialize_Scalars or Normalize_Scalars.
21993
21994 if Kill_Range_Check (Expression (Decl)) then
21995 Prag :=
21996 Make_Pragma (Loc,
21997 Name_Suppress_Initialization,
21998 Pragma_Argument_Associations => New_List (
21999 Make_Pragma_Argument_Association (Loc,
22000 Expression => New_Occurrence_Of (Ent, Loc))));
22001 Insert_Before (N, Prag);
22002 Analyze (Prag);
22003
22004 else
22005 Error_Pragma_Arg
22006 ("object for pragma% cannot have initialization", Arg1);
22007 end if;
22008 end if;
22009
22010 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
22011 Error_Pragma_Arg
22012 ("object type for pragma% is not potentially persistent",
22013 Arg1);
22014 end if;
22015
22016 Prag :=
22017 Make_Linker_Section_Pragma
22018 (Ent, Loc, ".persistent.bss");
22019 Insert_After (N, Prag);
22020 Analyze (Prag);
22021
22022 -- Case of use as configuration pragma with no arguments
22023
22024 else
22025 Check_Valid_Configuration_Pragma;
22026 Persistent_BSS_Mode := True;
22027 end if;
22028 end Persistent_BSS;
22029
22030 --------------------
22031 -- Rename_Pragma --
22032 --------------------
22033
22034 -- pragma Rename_Pragma (
22035 -- [New_Name =>] IDENTIFIER,
22036 -- [Renamed =>] pragma_IDENTIFIER);
22037
22038 when Pragma_Rename_Pragma => Rename_Pragma : declare
22039 New_Name : constant Node_Id := Get_Pragma_Arg (Arg1);
22040 Old_Name : constant Node_Id := Get_Pragma_Arg (Arg2);
22041
22042 begin
22043 GNAT_Pragma;
22044 Check_Valid_Configuration_Pragma;
22045 Check_Arg_Count (2);
22046 Check_Optional_Identifier (Arg1, Name_New_Name);
22047 Check_Optional_Identifier (Arg2, Name_Renamed);
22048
22049 if Nkind (New_Name) /= N_Identifier then
22050 Error_Pragma_Arg ("identifier expected", Arg1);
22051 end if;
22052
22053 if Nkind (Old_Name) /= N_Identifier then
22054 Error_Pragma_Arg ("identifier expected", Arg2);
22055 end if;
22056
22057 -- The New_Name arg should not be an existing pragma (but we allow
22058 -- it; it's just a warning). The Old_Name arg must be an existing
22059 -- pragma.
22060
22061 if Is_Pragma_Name (Chars (New_Name)) then
22062 Error_Pragma_Arg ("??pragma is already defined", Arg1);
22063 end if;
22064
22065 if not Is_Pragma_Name (Chars (Old_Name)) then
22066 Error_Pragma_Arg ("existing pragma name expected", Arg1);
22067 end if;
22068
22069 Map_Pragma_Name (From => Chars (New_Name), To => Chars (Old_Name));
22070 end Rename_Pragma;
22071
22072 -----------------------------------
22073 -- Post/Post_Class/Postcondition --
22074 -----------------------------------
22075
22076 -- pragma Post (Boolean_EXPRESSION);
22077 -- pragma Post_Class (Boolean_EXPRESSION);
22078 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
22079 -- [,[Message =>] String_EXPRESSION]);
22080
22081 -- Characteristics:
22082
22083 -- * Analysis - The annotation undergoes initial checks to verify
22084 -- the legal placement and context. Secondary checks preanalyze the
22085 -- expression in:
22086
22087 -- Analyze_Pre_Post_Condition_In_Decl_Part
22088
22089 -- * Expansion - The annotation is expanded during the expansion of
22090 -- the related subprogram [body] contract as performed in:
22091
22092 -- Expand_Subprogram_Contract
22093
22094 -- * Template - The annotation utilizes the generic template of the
22095 -- related subprogram [body] when it is:
22096
22097 -- aspect on subprogram declaration
22098 -- aspect on stand-alone subprogram body
22099 -- pragma on stand-alone subprogram body
22100
22101 -- The annotation must prepare its own template when it is:
22102
22103 -- pragma on subprogram declaration
22104
22105 -- * Globals - Capture of global references must occur after full
22106 -- analysis.
22107
22108 -- * Instance - The annotation is instantiated automatically when
22109 -- the related generic subprogram [body] is instantiated except for
22110 -- the "pragma on subprogram declaration" case. In that scenario
22111 -- the annotation must instantiate itself.
22112
22113 when Pragma_Post
22114 | Pragma_Post_Class
22115 | Pragma_Postcondition
22116 =>
22117 Analyze_Pre_Post_Condition;
22118
22119 --------------------------------
22120 -- Pre/Pre_Class/Precondition --
22121 --------------------------------
22122
22123 -- pragma Pre (Boolean_EXPRESSION);
22124 -- pragma Pre_Class (Boolean_EXPRESSION);
22125 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
22126 -- [,[Message =>] String_EXPRESSION]);
22127
22128 -- Characteristics:
22129
22130 -- * Analysis - The annotation undergoes initial checks to verify
22131 -- the legal placement and context. Secondary checks preanalyze the
22132 -- expression in:
22133
22134 -- Analyze_Pre_Post_Condition_In_Decl_Part
22135
22136 -- * Expansion - The annotation is expanded during the expansion of
22137 -- the related subprogram [body] contract as performed in:
22138
22139 -- Expand_Subprogram_Contract
22140
22141 -- * Template - The annotation utilizes the generic template of the
22142 -- related subprogram [body] when it is:
22143
22144 -- aspect on subprogram declaration
22145 -- aspect on stand-alone subprogram body
22146 -- pragma on stand-alone subprogram body
22147
22148 -- The annotation must prepare its own template when it is:
22149
22150 -- pragma on subprogram declaration
22151
22152 -- * Globals - Capture of global references must occur after full
22153 -- analysis.
22154
22155 -- * Instance - The annotation is instantiated automatically when
22156 -- the related generic subprogram [body] is instantiated except for
22157 -- the "pragma on subprogram declaration" case. In that scenario
22158 -- the annotation must instantiate itself.
22159
22160 when Pragma_Pre
22161 | Pragma_Pre_Class
22162 | Pragma_Precondition
22163 =>
22164 Analyze_Pre_Post_Condition;
22165
22166 ---------------
22167 -- Predicate --
22168 ---------------
22169
22170 -- pragma Predicate
22171 -- ([Entity =>] type_LOCAL_NAME,
22172 -- [Check =>] boolean_EXPRESSION);
22173
22174 when Pragma_Predicate => Predicate : declare
22175 Discard : Boolean;
22176 Typ : Entity_Id;
22177 Type_Id : Node_Id;
22178
22179 begin
22180 GNAT_Pragma;
22181 Check_Arg_Count (2);
22182 Check_Optional_Identifier (Arg1, Name_Entity);
22183 Check_Optional_Identifier (Arg2, Name_Check);
22184
22185 Check_Arg_Is_Local_Name (Arg1);
22186
22187 Type_Id := Get_Pragma_Arg (Arg1);
22188 Find_Type (Type_Id);
22189 Typ := Entity (Type_Id);
22190
22191 if Typ = Any_Type then
22192 return;
22193 end if;
22194
22195 -- A Ghost_Predicate aspect is always Ghost with a mode inherited
22196 -- from the context. A Predicate pragma that applies to a Ghost
22197 -- entity becomes Ghost for the purposes of legality checks and
22198 -- removal of ignored Ghost code.
22199
22200 if From_Aspect_Specification (N)
22201 and then Get_Aspect_Id
22202 (Chars (Identifier (Corresponding_Aspect (N))))
22203 = Aspect_Ghost_Predicate
22204 then
22205 Mark_Ghost_Pragma
22206 (N, Name_To_Ghost_Mode (Policy_In_Effect (Name_Ghost)));
22207 else
22208 Mark_Ghost_Pragma (N, Typ);
22209 end if;
22210
22211 -- The remaining processing is simply to link the pragma on to
22212 -- the rep item chain, for processing when the type is frozen.
22213 -- This is accomplished by a call to Rep_Item_Too_Late. We also
22214 -- mark the type as having predicates.
22215
22216 -- If the current policy for predicate checking is Ignore mark the
22217 -- subtype accordingly. In the case of predicates we consider them
22218 -- enabled unless Ignore is specified (either directly or with a
22219 -- general Assertion_Policy pragma) to preserve existing warnings.
22220
22221 Set_Has_Predicates (Typ);
22222
22223 -- Indicate that the pragma must be processed at the point the
22224 -- type is frozen, as is done for the corresponding aspect.
22225
22226 Set_Has_Delayed_Aspects (Typ);
22227 Set_Has_Delayed_Freeze (Typ);
22228
22229 Set_Predicates_Ignored (Typ,
22230 Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore);
22231 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
22232 end Predicate;
22233
22234 -----------------------
22235 -- Predicate_Failure --
22236 -----------------------
22237
22238 -- pragma Predicate_Failure
22239 -- ([Entity =>] type_LOCAL_NAME,
22240 -- [Message =>] string_EXPRESSION);
22241
22242 when Pragma_Predicate_Failure => Predicate_Failure : declare
22243 Discard : Boolean;
22244 Typ : Entity_Id;
22245 Type_Id : Node_Id;
22246
22247 begin
22248 GNAT_Pragma;
22249 Check_Arg_Count (2);
22250 Check_Optional_Identifier (Arg1, Name_Entity);
22251 Check_Optional_Identifier (Arg2, Name_Message);
22252
22253 Check_Arg_Is_Local_Name (Arg1);
22254
22255 Type_Id := Get_Pragma_Arg (Arg1);
22256 Find_Type (Type_Id);
22257 Typ := Entity (Type_Id);
22258
22259 if Typ = Any_Type then
22260 return;
22261 end if;
22262
22263 -- A pragma that applies to a Ghost entity becomes Ghost for the
22264 -- purposes of legality checks and removal of ignored Ghost code.
22265
22266 Mark_Ghost_Pragma (N, Typ);
22267
22268 -- The remaining processing is simply to link the pragma on to
22269 -- the rep item chain, for processing when the type is frozen.
22270 -- This is accomplished by a call to Rep_Item_Too_Late.
22271
22272 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
22273 end Predicate_Failure;
22274
22275 ------------------
22276 -- Preelaborate --
22277 ------------------
22278
22279 -- pragma Preelaborate [(library_unit_NAME)];
22280
22281 -- Set the flag Is_Preelaborated of program unit name entity
22282
22283 when Pragma_Preelaborate => Preelaborate : declare
22284 Pa : constant Node_Id := Parent (N);
22285 Pk : constant Node_Kind := Nkind (Pa);
22286 Ent : Entity_Id;
22287
22288 begin
22289 Check_Ada_83_Warning;
22290 Check_Valid_Library_Unit_Pragma;
22291
22292 -- If N was rewritten as a null statement there is nothing more
22293 -- to do.
22294
22295 if Nkind (N) = N_Null_Statement then
22296 return;
22297 end if;
22298
22299 Ent := Find_Lib_Unit_Name;
22300
22301 -- A pragma that applies to a Ghost entity becomes Ghost for the
22302 -- purposes of legality checks and removal of ignored Ghost code.
22303
22304 Mark_Ghost_Pragma (N, Ent);
22305 Check_Duplicate_Pragma (Ent);
22306
22307 -- This filters out pragmas inside generic parents that show up
22308 -- inside instantiations. Pragmas that come from aspects in the
22309 -- unit are not ignored.
22310
22311 if Present (Ent) then
22312 if Pk = N_Package_Specification
22313 and then Present (Generic_Parent (Pa))
22314 and then not From_Aspect_Specification (N)
22315 then
22316 null;
22317
22318 else
22319 if not Debug_Flag_U then
22320 Set_Is_Preelaborated (Ent);
22321
22322 if Legacy_Elaboration_Checks then
22323 Set_Suppress_Elaboration_Warnings (Ent);
22324 end if;
22325 end if;
22326 end if;
22327 end if;
22328 end Preelaborate;
22329
22330 -------------------------------
22331 -- Prefix_Exception_Messages --
22332 -------------------------------
22333
22334 -- pragma Prefix_Exception_Messages;
22335
22336 when Pragma_Prefix_Exception_Messages =>
22337 GNAT_Pragma;
22338 Check_Valid_Configuration_Pragma;
22339 Check_Arg_Count (0);
22340 Prefix_Exception_Messages := True;
22341
22342 --------------
22343 -- Priority --
22344 --------------
22345
22346 -- pragma Priority (EXPRESSION);
22347
22348 when Pragma_Priority => Priority : declare
22349 P : constant Node_Id := Parent (N);
22350 Arg : Node_Id;
22351 Ent : Entity_Id;
22352
22353 begin
22354 Check_No_Identifiers;
22355 Check_Arg_Count (1);
22356
22357 -- Subprogram case
22358
22359 if Nkind (P) = N_Subprogram_Body then
22360 Check_In_Main_Program;
22361
22362 Ent := Defining_Unit_Name (Specification (P));
22363
22364 if Nkind (Ent) = N_Defining_Program_Unit_Name then
22365 Ent := Defining_Identifier (Ent);
22366 end if;
22367
22368 Arg := Get_Pragma_Arg (Arg1);
22369 Analyze_And_Resolve (Arg, Standard_Integer);
22370
22371 -- Must be static
22372
22373 if not Is_OK_Static_Expression (Arg) then
22374 Flag_Non_Static_Expr
22375 ("main subprogram priority is not static!", Arg);
22376 raise Pragma_Exit;
22377
22378 -- If constraint error, then we already signalled an error
22379
22380 elsif Raises_Constraint_Error (Arg) then
22381 null;
22382
22383 -- Otherwise check in range except if Relaxed_RM_Semantics
22384 -- where we ignore the value if out of range.
22385
22386 else
22387 if not Relaxed_RM_Semantics
22388 and then not Is_In_Range (Arg, RTE (RE_Priority))
22389 then
22390 Error_Pragma_Arg
22391 ("main subprogram priority is out of range", Arg1);
22392 else
22393 Set_Main_Priority
22394 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
22395 end if;
22396 end if;
22397
22398 -- Load an arbitrary entity from System.Tasking.Stages or
22399 -- System.Tasking.Restricted.Stages (depending on the
22400 -- supported profile) to make sure that one of these packages
22401 -- is implicitly with'ed, since we need to have the tasking
22402 -- run time active for the pragma Priority to have any effect.
22403 -- Previously we with'ed the package System.Tasking, but this
22404 -- package does not trigger the required initialization of the
22405 -- run-time library.
22406
22407 if Restricted_Profile then
22408 Discard_Node (RTE (RE_Activate_Restricted_Tasks));
22409 else
22410 Discard_Node (RTE (RE_Activate_Tasks));
22411 end if;
22412
22413 -- Task or Protected, must be of type Integer
22414
22415 elsif Nkind (P) in N_Protected_Definition | N_Task_Definition then
22416 Arg := Get_Pragma_Arg (Arg1);
22417 Ent := Defining_Identifier (Parent (P));
22418
22419 -- The expression must be analyzed in the special manner
22420 -- described in "Handling of Default and Per-Object
22421 -- Expressions" in sem.ads.
22422
22423 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
22424
22425 if not Is_OK_Static_Expression (Arg) then
22426 Check_Restriction (Static_Priorities, Arg);
22427 end if;
22428
22429 -- Anything else is incorrect
22430
22431 else
22432 Pragma_Misplaced;
22433 end if;
22434
22435 -- Check duplicate pragma before we chain the pragma in the Rep
22436 -- Item chain of Ent.
22437
22438 Check_Duplicate_Pragma (Ent);
22439 Record_Rep_Item (Ent, N);
22440 end Priority;
22441
22442 -----------------------------------
22443 -- Priority_Specific_Dispatching --
22444 -----------------------------------
22445
22446 -- pragma Priority_Specific_Dispatching (
22447 -- policy_IDENTIFIER,
22448 -- first_priority_EXPRESSION,
22449 -- last_priority_EXPRESSION);
22450
22451 when Pragma_Priority_Specific_Dispatching =>
22452 Priority_Specific_Dispatching : declare
22453 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
22454 -- This is the entity System.Any_Priority;
22455
22456 DP : Character;
22457 Lower_Bound : Node_Id;
22458 Upper_Bound : Node_Id;
22459 Lower_Val : Uint;
22460 Upper_Val : Uint;
22461
22462 begin
22463 Ada_2005_Pragma;
22464 Check_Arg_Count (3);
22465 Check_No_Identifiers;
22466 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
22467 Check_Valid_Configuration_Pragma;
22468 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
22469 DP := Fold_Upper (Name_Buffer (1));
22470
22471 Lower_Bound := Get_Pragma_Arg (Arg2);
22472 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
22473 Lower_Val := Expr_Value (Lower_Bound);
22474
22475 Upper_Bound := Get_Pragma_Arg (Arg3);
22476 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
22477 Upper_Val := Expr_Value (Upper_Bound);
22478
22479 -- It is not allowed to use Task_Dispatching_Policy and
22480 -- Priority_Specific_Dispatching in the same partition.
22481
22482 if Task_Dispatching_Policy /= ' ' then
22483 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
22484 Error_Pragma
22485 ("pragma% incompatible with Task_Dispatching_Policy#");
22486
22487 -- Check lower bound in range
22488
22489 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
22490 or else
22491 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
22492 then
22493 Error_Pragma_Arg
22494 ("first_priority is out of range", Arg2);
22495
22496 -- Check upper bound in range
22497
22498 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
22499 or else
22500 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
22501 then
22502 Error_Pragma_Arg
22503 ("last_priority is out of range", Arg3);
22504
22505 -- Check that the priority range is valid
22506
22507 elsif Lower_Val > Upper_Val then
22508 Error_Pragma
22509 ("last_priority_expression must be greater than or equal to "
22510 & "first_priority_expression");
22511
22512 -- Store the new policy, but always preserve System_Location since
22513 -- we like the error message with the run-time name.
22514
22515 else
22516 -- Check overlapping in the priority ranges specified in other
22517 -- Priority_Specific_Dispatching pragmas within the same
22518 -- partition. We can only check those we know about.
22519
22520 for J in
22521 Specific_Dispatching.First .. Specific_Dispatching.Last
22522 loop
22523 if Specific_Dispatching.Table (J).First_Priority in
22524 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
22525 or else Specific_Dispatching.Table (J).Last_Priority in
22526 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
22527 then
22528 Error_Msg_Sloc :=
22529 Specific_Dispatching.Table (J).Pragma_Loc;
22530 Error_Pragma
22531 ("priority range overlaps with "
22532 & "Priority_Specific_Dispatching#");
22533 end if;
22534 end loop;
22535
22536 -- The use of Priority_Specific_Dispatching is incompatible
22537 -- with Task_Dispatching_Policy.
22538
22539 if Task_Dispatching_Policy /= ' ' then
22540 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
22541 Error_Pragma
22542 ("Priority_Specific_Dispatching incompatible "
22543 & "with Task_Dispatching_Policy#");
22544 end if;
22545
22546 -- The use of Priority_Specific_Dispatching forces ceiling
22547 -- locking policy.
22548
22549 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
22550 Error_Msg_Sloc := Locking_Policy_Sloc;
22551 Error_Pragma
22552 ("Priority_Specific_Dispatching incompatible "
22553 & "with Locking_Policy#");
22554
22555 -- Set the Ceiling_Locking policy, but preserve System_Location
22556 -- since we like the error message with the run time name.
22557
22558 else
22559 Locking_Policy := 'C';
22560
22561 if Locking_Policy_Sloc /= System_Location then
22562 Locking_Policy_Sloc := Loc;
22563 end if;
22564 end if;
22565
22566 -- Add entry in the table
22567
22568 Specific_Dispatching.Append
22569 ((Dispatching_Policy => DP,
22570 First_Priority => UI_To_Int (Lower_Val),
22571 Last_Priority => UI_To_Int (Upper_Val),
22572 Pragma_Loc => Loc));
22573 end if;
22574 end Priority_Specific_Dispatching;
22575
22576 -------------
22577 -- Profile --
22578 -------------
22579
22580 -- pragma Profile (profile_IDENTIFIER);
22581
22582 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
22583
22584 when Pragma_Profile =>
22585 Ada_2005_Pragma;
22586 Check_Arg_Count (1);
22587 Check_Valid_Configuration_Pragma;
22588 Check_No_Identifiers;
22589
22590 declare
22591 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
22592
22593 begin
22594 if Nkind (Argx) /= N_Identifier then
22595 Error_Msg_N
22596 ("argument of pragma Profile must be an identifier", N);
22597
22598 elsif Chars (Argx) = Name_Ravenscar then
22599 Set_Ravenscar_Profile (Ravenscar, N);
22600
22601 elsif Chars (Argx) = Name_Jorvik then
22602 Set_Ravenscar_Profile (Jorvik, N);
22603
22604 elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then
22605 Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N);
22606
22607 elsif Chars (Argx) = Name_Gnat_Ravenscar_EDF then
22608 Set_Ravenscar_Profile (GNAT_Ravenscar_EDF, N);
22609
22610 elsif Chars (Argx) = Name_Restricted then
22611 Set_Profile_Restrictions
22612 (Restricted,
22613 N, Warn => Treat_Restrictions_As_Warnings);
22614
22615 elsif Chars (Argx) = Name_Rational then
22616 Set_Rational_Profile;
22617
22618 elsif Chars (Argx) = Name_No_Implementation_Extensions then
22619 Set_Profile_Restrictions
22620 (No_Implementation_Extensions,
22621 N, Warn => Treat_Restrictions_As_Warnings);
22622
22623 else
22624 Error_Pragma_Arg ("& is not a valid profile", Argx);
22625 end if;
22626 end;
22627
22628 ----------------------
22629 -- Profile_Warnings --
22630 ----------------------
22631
22632 -- pragma Profile_Warnings (profile_IDENTIFIER);
22633
22634 -- profile_IDENTIFIER => Restricted | Ravenscar
22635
22636 when Pragma_Profile_Warnings =>
22637 GNAT_Pragma;
22638 Check_Arg_Count (1);
22639 Check_Valid_Configuration_Pragma;
22640 Check_No_Identifiers;
22641
22642 declare
22643 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
22644
22645 begin
22646 if Chars (Argx) = Name_Ravenscar then
22647 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
22648
22649 elsif Chars (Argx) = Name_Restricted then
22650 Set_Profile_Restrictions (Restricted, N, Warn => True);
22651
22652 elsif Chars (Argx) = Name_No_Implementation_Extensions then
22653 Set_Profile_Restrictions
22654 (No_Implementation_Extensions, N, Warn => True);
22655
22656 else
22657 Error_Pragma_Arg ("& is not a valid profile", Argx);
22658 end if;
22659 end;
22660
22661 --------------------------
22662 -- Propagate_Exceptions --
22663 --------------------------
22664
22665 -- pragma Propagate_Exceptions;
22666
22667 -- Note: this pragma is obsolete and has no effect
22668
22669 when Pragma_Propagate_Exceptions =>
22670 GNAT_Pragma;
22671 Check_Arg_Count (0);
22672
22673 if Warn_On_Obsolescent_Feature then
22674 Error_Msg_N
22675 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
22676 "and has no effect?j?", N);
22677 end if;
22678
22679 -----------------------------
22680 -- Provide_Shift_Operators --
22681 -----------------------------
22682
22683 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
22684
22685 when Pragma_Provide_Shift_Operators =>
22686 Provide_Shift_Operators : declare
22687 Ent : Entity_Id;
22688
22689 procedure Declare_Shift_Operator (Nam : Name_Id);
22690 -- Insert declaration and pragma Instrinsic for named shift op
22691
22692 ----------------------------
22693 -- Declare_Shift_Operator --
22694 ----------------------------
22695
22696 procedure Declare_Shift_Operator (Nam : Name_Id) is
22697 Func : Node_Id;
22698 Import : Node_Id;
22699
22700 begin
22701 Func :=
22702 Make_Subprogram_Declaration (Loc,
22703 Make_Function_Specification (Loc,
22704 Defining_Unit_Name =>
22705 Make_Defining_Identifier (Loc, Chars => Nam),
22706
22707 Result_Definition =>
22708 Make_Identifier (Loc, Chars => Chars (Ent)),
22709
22710 Parameter_Specifications => New_List (
22711 Make_Parameter_Specification (Loc,
22712 Defining_Identifier =>
22713 Make_Defining_Identifier (Loc, Name_Value),
22714 Parameter_Type =>
22715 Make_Identifier (Loc, Chars => Chars (Ent))),
22716
22717 Make_Parameter_Specification (Loc,
22718 Defining_Identifier =>
22719 Make_Defining_Identifier (Loc, Name_Amount),
22720 Parameter_Type =>
22721 New_Occurrence_Of (Standard_Natural, Loc)))));
22722
22723 Import :=
22724 Make_Pragma (Loc,
22725 Chars => Name_Import,
22726 Pragma_Argument_Associations => New_List (
22727 Make_Pragma_Argument_Association (Loc,
22728 Expression => Make_Identifier (Loc, Name_Intrinsic)),
22729 Make_Pragma_Argument_Association (Loc,
22730 Expression => Make_Identifier (Loc, Nam))));
22731
22732 Insert_After (N, Import);
22733 Insert_After (N, Func);
22734 end Declare_Shift_Operator;
22735
22736 -- Start of processing for Provide_Shift_Operators
22737
22738 begin
22739 GNAT_Pragma;
22740 Check_Arg_Count (1);
22741 Check_Arg_Is_Local_Name (Arg1);
22742
22743 Arg1 := Get_Pragma_Arg (Arg1);
22744
22745 -- We must have an entity name
22746
22747 if not Is_Entity_Name (Arg1) then
22748 Error_Pragma_Arg
22749 ("pragma % must apply to integer first subtype", Arg1);
22750 end if;
22751
22752 -- If no Entity, means there was a prior error so ignore
22753
22754 if Present (Entity (Arg1)) then
22755 Ent := Entity (Arg1);
22756
22757 -- Apply error checks
22758
22759 if not Is_First_Subtype (Ent) then
22760 Error_Pragma_Arg
22761 ("cannot apply pragma %",
22762 "\& is not a first subtype",
22763 Arg1);
22764
22765 elsif not Is_Integer_Type (Ent) then
22766 Error_Pragma_Arg
22767 ("cannot apply pragma %",
22768 "\& is not an integer type",
22769 Arg1);
22770
22771 elsif Has_Shift_Operator (Ent) then
22772 Error_Pragma_Arg
22773 ("cannot apply pragma %",
22774 "\& already has declared shift operators",
22775 Arg1);
22776
22777 elsif Is_Frozen (Ent) then
22778 Error_Pragma_Arg
22779 ("pragma % appears too late",
22780 "\& is already frozen",
22781 Arg1);
22782 end if;
22783
22784 -- Now declare the operators. We do this during analysis rather
22785 -- than expansion, since we want the operators available if we
22786 -- are operating in -gnatc mode.
22787
22788 Declare_Shift_Operator (Name_Rotate_Left);
22789 Declare_Shift_Operator (Name_Rotate_Right);
22790 Declare_Shift_Operator (Name_Shift_Left);
22791 Declare_Shift_Operator (Name_Shift_Right);
22792 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
22793 end if;
22794 end Provide_Shift_Operators;
22795
22796 ------------------
22797 -- Psect_Object --
22798 ------------------
22799
22800 -- pragma Psect_Object (
22801 -- [Internal =>] LOCAL_NAME,
22802 -- [, [External =>] EXTERNAL_SYMBOL]
22803 -- [, [Size =>] EXTERNAL_SYMBOL]);
22804
22805 when Pragma_Common_Object
22806 | Pragma_Psect_Object
22807 =>
22808 Psect_Object : declare
22809 Args : Args_List (1 .. 3);
22810 Names : constant Name_List (1 .. 3) := (
22811 Name_Internal,
22812 Name_External,
22813 Name_Size);
22814
22815 Internal : Node_Id renames Args (1);
22816 External : Node_Id renames Args (2);
22817 Size : Node_Id renames Args (3);
22818
22819 Def_Id : Entity_Id;
22820
22821 procedure Check_Arg (Arg : Node_Id);
22822 -- Checks that argument is either a string literal or an
22823 -- identifier, and posts error message if not.
22824
22825 ---------------
22826 -- Check_Arg --
22827 ---------------
22828
22829 procedure Check_Arg (Arg : Node_Id) is
22830 begin
22831 if Nkind (Original_Node (Arg)) not in
22832 N_String_Literal | N_Identifier
22833 then
22834 Error_Pragma_Arg
22835 ("inappropriate argument for pragma %", Arg);
22836 end if;
22837 end Check_Arg;
22838
22839 -- Start of processing for Common_Object/Psect_Object
22840
22841 begin
22842 GNAT_Pragma;
22843 Gather_Associations (Names, Args);
22844 Process_Extended_Import_Export_Internal_Arg (Internal);
22845
22846 Def_Id := Entity (Internal);
22847
22848 if Ekind (Def_Id) not in E_Constant | E_Variable then
22849 Error_Pragma_Arg
22850 ("pragma% must designate an object", Internal);
22851 end if;
22852
22853 Check_Arg (Internal);
22854
22855 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
22856 Error_Pragma_Arg
22857 ("cannot use pragma% for imported/exported object",
22858 Internal);
22859 end if;
22860
22861 if Is_Concurrent_Type (Etype (Internal)) then
22862 Error_Pragma_Arg
22863 ("cannot specify pragma % for task/protected object",
22864 Internal);
22865 end if;
22866
22867 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
22868 or else
22869 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
22870 then
22871 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
22872 end if;
22873
22874 if Ekind (Def_Id) = E_Constant then
22875 Error_Pragma_Arg
22876 ("cannot specify pragma % for a constant", Internal);
22877 end if;
22878
22879 if Is_Record_Type (Etype (Internal)) then
22880 declare
22881 Ent : Entity_Id;
22882 Decl : Entity_Id;
22883
22884 begin
22885 Ent := First_Entity (Etype (Internal));
22886 while Present (Ent) loop
22887 Decl := Declaration_Node (Ent);
22888
22889 if Ekind (Ent) = E_Component
22890 and then Nkind (Decl) = N_Component_Declaration
22891 and then Present (Expression (Decl))
22892 and then Warn_On_Export_Import
22893 then
22894 Error_Msg_N
22895 ("?x?object for pragma % has defaults", Internal);
22896 exit;
22897
22898 else
22899 Next_Entity (Ent);
22900 end if;
22901 end loop;
22902 end;
22903 end if;
22904
22905 if Present (Size) then
22906 Check_Arg (Size);
22907 end if;
22908
22909 if Present (External) then
22910 Check_Arg_Is_External_Name (External);
22911 end if;
22912
22913 -- If all error tests pass, link pragma on to the rep item chain
22914
22915 Record_Rep_Item (Def_Id, N);
22916 end Psect_Object;
22917
22918 ----------
22919 -- Pure --
22920 ----------
22921
22922 -- pragma Pure [(library_unit_NAME)];
22923
22924 when Pragma_Pure => Pure : declare
22925 Ent : Entity_Id;
22926
22927 begin
22928 Check_Ada_83_Warning;
22929
22930 -- If the pragma comes from a subprogram instantiation, nothing to
22931 -- check, this can happen at any level of nesting.
22932
22933 if Is_Wrapper_Package (Current_Scope) then
22934 return;
22935 end if;
22936
22937 Check_Valid_Library_Unit_Pragma;
22938
22939 -- If N was rewritten as a null statement there is nothing more
22940 -- to do.
22941
22942 if Nkind (N) = N_Null_Statement then
22943 return;
22944 end if;
22945
22946 Ent := Find_Lib_Unit_Name;
22947
22948 -- A pragma that applies to a Ghost entity becomes Ghost for the
22949 -- purposes of legality checks and removal of ignored Ghost code.
22950
22951 Mark_Ghost_Pragma (N, Ent);
22952
22953 if not Debug_Flag_U then
22954 Set_Is_Pure (Ent);
22955 Set_Has_Pragma_Pure (Ent);
22956
22957 if Legacy_Elaboration_Checks then
22958 Set_Suppress_Elaboration_Warnings (Ent);
22959 end if;
22960 end if;
22961 end Pure;
22962
22963 -------------------
22964 -- Pure_Function --
22965 -------------------
22966
22967 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
22968
22969 when Pragma_Pure_Function => Pure_Function : declare
22970 Def_Id : Entity_Id;
22971 E : Entity_Id;
22972 E_Id : Node_Id;
22973 Effective : Boolean := False;
22974 Orig_Def : Entity_Id;
22975 Same_Decl : Boolean := False;
22976
22977 begin
22978 GNAT_Pragma;
22979 Check_Arg_Count (1);
22980 Check_Optional_Identifier (Arg1, Name_Entity);
22981 Check_Arg_Is_Local_Name (Arg1);
22982 E_Id := Get_Pragma_Arg (Arg1);
22983
22984 if Etype (E_Id) = Any_Type then
22985 return;
22986 end if;
22987
22988 -- Loop through homonyms (overloadings) of referenced entity
22989
22990 E := Entity (E_Id);
22991
22992 Analyze_If_Present (Pragma_Side_Effects);
22993
22994 -- A function with side effects shall not have a Pure_Function
22995 -- aspect or pragma (SPARK RM 6.1.11(5)).
22996
22997 if Is_Function_With_Side_Effects (E) then
22998 Error_Pragma
22999 ("pragma % incompatible with ""Side_Effects""");
23000 end if;
23001
23002 -- A pragma that applies to a Ghost entity becomes Ghost for the
23003 -- purposes of legality checks and removal of ignored Ghost code.
23004
23005 Mark_Ghost_Pragma (N, E);
23006
23007 if Present (E) then
23008 loop
23009 Def_Id := Get_Base_Subprogram (E);
23010
23011 if Ekind (Def_Id) not in
23012 E_Function | E_Generic_Function | E_Operator
23013 then
23014 Error_Pragma_Arg
23015 ("pragma% requires a function name", Arg1);
23016 end if;
23017
23018 -- When we have a generic function we must jump up a level
23019 -- to the declaration of the wrapper package itself.
23020
23021 Orig_Def := Def_Id;
23022
23023 if Is_Generic_Instance (Def_Id) then
23024 while Nkind (Orig_Def) /= N_Package_Declaration loop
23025 Orig_Def := Parent (Orig_Def);
23026 end loop;
23027 end if;
23028
23029 if In_Same_Declarative_Part (Parent (N), Orig_Def) then
23030 Same_Decl := True;
23031 Set_Is_Pure (Def_Id);
23032
23033 if not Has_Pragma_Pure_Function (Def_Id) then
23034 Set_Has_Pragma_Pure_Function (Def_Id);
23035 Effective := True;
23036 end if;
23037 end if;
23038
23039 exit when From_Aspect_Specification (N);
23040 E := Homonym (E);
23041 exit when No (E) or else Scope (E) /= Current_Scope;
23042 end loop;
23043
23044 if not Effective
23045 and then Warn_On_Redundant_Constructs
23046 then
23047 Error_Msg_NE
23048 ("pragma Pure_Function on& is redundant?r?",
23049 N, Entity (E_Id));
23050
23051 elsif not Same_Decl then
23052 Error_Pragma_Arg
23053 ("pragma% argument must be in same declarative part",
23054 Arg1);
23055 end if;
23056 end if;
23057 end Pure_Function;
23058
23059 --------------------
23060 -- Queuing_Policy --
23061 --------------------
23062
23063 -- pragma Queuing_Policy (policy_IDENTIFIER);
23064
23065 when Pragma_Queuing_Policy => declare
23066 QP : Character;
23067
23068 begin
23069 Check_Ada_83_Warning;
23070 Check_Arg_Count (1);
23071 Check_No_Identifiers;
23072 Check_Arg_Is_Queuing_Policy (Arg1);
23073 Check_Valid_Configuration_Pragma;
23074 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
23075 QP := Fold_Upper (Name_Buffer (1));
23076
23077 if Queuing_Policy /= ' '
23078 and then Queuing_Policy /= QP
23079 then
23080 Error_Msg_Sloc := Queuing_Policy_Sloc;
23081 Error_Pragma ("queuing policy incompatible with policy#");
23082
23083 -- Set new policy, but always preserve System_Location since we
23084 -- like the error message with the run time name.
23085
23086 else
23087 Queuing_Policy := QP;
23088
23089 if Queuing_Policy_Sloc /= System_Location then
23090 Queuing_Policy_Sloc := Loc;
23091 end if;
23092 end if;
23093 end;
23094
23095 --------------
23096 -- Rational --
23097 --------------
23098
23099 -- pragma Rational, for compatibility with foreign compiler
23100
23101 when Pragma_Rational =>
23102 Set_Rational_Profile;
23103
23104 ---------------------
23105 -- Refined_Depends --
23106 ---------------------
23107
23108 -- pragma Refined_Depends (DEPENDENCY_RELATION);
23109
23110 -- DEPENDENCY_RELATION ::=
23111 -- null
23112 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
23113
23114 -- DEPENDENCY_CLAUSE ::=
23115 -- OUTPUT_LIST =>[+] INPUT_LIST
23116 -- | NULL_DEPENDENCY_CLAUSE
23117
23118 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
23119
23120 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
23121
23122 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
23123
23124 -- OUTPUT ::= NAME | FUNCTION_RESULT
23125 -- INPUT ::= NAME
23126
23127 -- where FUNCTION_RESULT is a function Result attribute_reference
23128
23129 -- Characteristics:
23130
23131 -- * Analysis - The annotation undergoes initial checks to verify
23132 -- the legal placement and context. Secondary checks fully analyze
23133 -- the dependency clauses/global list in:
23134
23135 -- Analyze_Refined_Depends_In_Decl_Part
23136
23137 -- * Expansion - None.
23138
23139 -- * Template - The annotation utilizes the generic template of the
23140 -- related subprogram body.
23141
23142 -- * Globals - Capture of global references must occur after full
23143 -- analysis.
23144
23145 -- * Instance - The annotation is instantiated automatically when
23146 -- the related generic subprogram body is instantiated.
23147
23148 when Pragma_Refined_Depends => Refined_Depends : declare
23149 Body_Id : Entity_Id;
23150 Legal : Boolean;
23151 Spec_Id : Entity_Id;
23152
23153 begin
23154 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
23155
23156 if Legal then
23157
23158 -- Chain the pragma on the contract for further processing by
23159 -- Analyze_Refined_Depends_In_Decl_Part.
23160
23161 Add_Contract_Item (N, Body_Id);
23162
23163 -- The legality checks of pragmas Refined_Depends and
23164 -- Refined_Global are affected by the SPARK mode in effect and
23165 -- the volatility of the context. In addition these two pragmas
23166 -- are subject to an inherent order:
23167
23168 -- 1) Refined_Global
23169 -- 2) Refined_Depends
23170
23171 -- Analyze all these pragmas in the order outlined above
23172
23173 Analyze_If_Present (Pragma_SPARK_Mode);
23174 Analyze_If_Present (Pragma_Volatile_Function);
23175 Analyze_If_Present (Pragma_Side_Effects);
23176 Analyze_If_Present (Pragma_Refined_Global);
23177 Analyze_Refined_Depends_In_Decl_Part (N);
23178 end if;
23179 end Refined_Depends;
23180
23181 --------------------
23182 -- Refined_Global --
23183 --------------------
23184
23185 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
23186
23187 -- GLOBAL_SPECIFICATION ::=
23188 -- null
23189 -- | (GLOBAL_LIST)
23190 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
23191
23192 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
23193
23194 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
23195 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
23196 -- GLOBAL_ITEM ::= NAME
23197
23198 -- Characteristics:
23199
23200 -- * Analysis - The annotation undergoes initial checks to verify
23201 -- the legal placement and context. Secondary checks fully analyze
23202 -- the dependency clauses/global list in:
23203
23204 -- Analyze_Refined_Global_In_Decl_Part
23205
23206 -- * Expansion - None.
23207
23208 -- * Template - The annotation utilizes the generic template of the
23209 -- related subprogram body.
23210
23211 -- * Globals - Capture of global references must occur after full
23212 -- analysis.
23213
23214 -- * Instance - The annotation is instantiated automatically when
23215 -- the related generic subprogram body is instantiated.
23216
23217 when Pragma_Refined_Global => Refined_Global : declare
23218 Body_Id : Entity_Id;
23219 Legal : Boolean;
23220 Spec_Id : Entity_Id;
23221
23222 begin
23223 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
23224
23225 if Legal then
23226
23227 -- Chain the pragma on the contract for further processing by
23228 -- Analyze_Refined_Global_In_Decl_Part.
23229
23230 Add_Contract_Item (N, Body_Id);
23231
23232 -- The legality checks of pragmas Refined_Depends and
23233 -- Refined_Global are affected by the SPARK mode in effect and
23234 -- the volatility of the context. In addition these two pragmas
23235 -- are subject to an inherent order:
23236
23237 -- 1) Refined_Global
23238 -- 2) Refined_Depends
23239
23240 -- Analyze all these pragmas in the order outlined above
23241
23242 Analyze_If_Present (Pragma_SPARK_Mode);
23243 Analyze_If_Present (Pragma_Volatile_Function);
23244 Analyze_If_Present (Pragma_Side_Effects);
23245 Analyze_Refined_Global_In_Decl_Part (N);
23246 Analyze_If_Present (Pragma_Refined_Depends);
23247 end if;
23248 end Refined_Global;
23249
23250 ------------------
23251 -- Refined_Post --
23252 ------------------
23253
23254 -- pragma Refined_Post (boolean_EXPRESSION);
23255
23256 -- Characteristics:
23257
23258 -- * Analysis - The annotation is fully analyzed immediately upon
23259 -- elaboration as it cannot forward reference entities.
23260
23261 -- * Expansion - The annotation is expanded during the expansion of
23262 -- the related subprogram body contract as performed in:
23263
23264 -- Expand_Subprogram_Contract
23265
23266 -- * Template - The annotation utilizes the generic template of the
23267 -- related subprogram body.
23268
23269 -- * Globals - Capture of global references must occur after full
23270 -- analysis.
23271
23272 -- * Instance - The annotation is instantiated automatically when
23273 -- the related generic subprogram body is instantiated.
23274
23275 when Pragma_Refined_Post => Refined_Post : declare
23276 Body_Id : Entity_Id;
23277 Legal : Boolean;
23278 Spec_Id : Entity_Id;
23279
23280 begin
23281 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
23282
23283 -- Fully analyze the pragma when it appears inside a subprogram
23284 -- body because it cannot benefit from forward references.
23285
23286 if Legal then
23287
23288 -- Chain the pragma on the contract for completeness
23289
23290 Add_Contract_Item (N, Body_Id);
23291
23292 -- The legality checks of pragma Refined_Post are affected by
23293 -- the SPARK mode in effect and the volatility of the context.
23294 -- Analyze all pragmas in a specific order.
23295
23296 Analyze_If_Present (Pragma_SPARK_Mode);
23297 Analyze_If_Present (Pragma_Volatile_Function);
23298 Analyze_Pre_Post_Condition_In_Decl_Part (N);
23299
23300 -- Currently it is not possible to inline pre/postconditions on
23301 -- a subprogram subject to pragma Inline_Always.
23302
23303 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
23304 end if;
23305 end Refined_Post;
23306
23307 -------------------
23308 -- Refined_State --
23309 -------------------
23310
23311 -- pragma Refined_State (REFINEMENT_LIST);
23312
23313 -- REFINEMENT_LIST ::=
23314 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
23315
23316 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
23317
23318 -- CONSTITUENT_LIST ::=
23319 -- null
23320 -- | CONSTITUENT
23321 -- | (CONSTITUENT {, CONSTITUENT})
23322
23323 -- CONSTITUENT ::= object_NAME | state_NAME
23324
23325 -- Characteristics:
23326
23327 -- * Analysis - The annotation undergoes initial checks to verify
23328 -- the legal placement and context. Secondary checks preanalyze the
23329 -- refinement clauses in:
23330
23331 -- Analyze_Refined_State_In_Decl_Part
23332
23333 -- * Expansion - None.
23334
23335 -- * Template - The annotation utilizes the template of the related
23336 -- package body.
23337
23338 -- * Globals - Capture of global references must occur after full
23339 -- analysis.
23340
23341 -- * Instance - The annotation is instantiated automatically when
23342 -- the related generic package body is instantiated.
23343
23344 when Pragma_Refined_State => Refined_State : declare
23345 Pack_Decl : Node_Id;
23346 Spec_Id : Entity_Id;
23347
23348 begin
23349 GNAT_Pragma;
23350 Check_No_Identifiers;
23351 Check_Arg_Count (1);
23352
23353 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
23354
23355 if Nkind (Pack_Decl) /= N_Package_Body then
23356 Pragma_Misplaced;
23357 end if;
23358
23359 Spec_Id := Corresponding_Spec (Pack_Decl);
23360
23361 -- A pragma that applies to a Ghost entity becomes Ghost for the
23362 -- purposes of legality checks and removal of ignored Ghost code.
23363
23364 Mark_Ghost_Pragma (N, Spec_Id);
23365
23366 -- Chain the pragma on the contract for further processing by
23367 -- Analyze_Refined_State_In_Decl_Part.
23368
23369 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
23370
23371 -- The legality checks of pragma Refined_State are affected by the
23372 -- SPARK mode in effect. Analyze all pragmas in a specific order.
23373
23374 Analyze_If_Present (Pragma_SPARK_Mode);
23375
23376 -- State refinement is allowed only when the corresponding package
23377 -- declaration has non-null pragma Abstract_State (SPARK RM
23378 -- 7.2.2(3)).
23379
23380 if No (Abstract_States (Spec_Id))
23381 or else Has_Null_Abstract_State (Spec_Id)
23382 then
23383 SPARK_Msg_NE
23384 ("useless refinement, package & does not define abstract "
23385 & "states", N, Spec_Id);
23386 return;
23387 end if;
23388 end Refined_State;
23389
23390 -----------------------
23391 -- Relative_Deadline --
23392 -----------------------
23393
23394 -- pragma Relative_Deadline (time_span_EXPRESSION);
23395
23396 when Pragma_Relative_Deadline => Relative_Deadline : declare
23397 P : constant Node_Id := Parent (N);
23398 Arg : Node_Id;
23399
23400 begin
23401 Ada_2005_Pragma;
23402 Check_No_Identifiers;
23403 Check_Arg_Count (1);
23404
23405 Arg := Get_Pragma_Arg (Arg1);
23406
23407 -- The expression must be analyzed in the special manner described
23408 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
23409
23410 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
23411
23412 -- Subprogram case
23413
23414 if Nkind (P) = N_Subprogram_Body then
23415 Check_In_Main_Program;
23416
23417 -- Only Task and subprogram cases allowed
23418
23419 elsif Nkind (P) /= N_Task_Definition then
23420 Pragma_Misplaced;
23421 end if;
23422
23423 -- Check duplicate pragma before we set the corresponding flag
23424
23425 if Has_Relative_Deadline_Pragma (P) then
23426 Error_Pragma ("duplicate pragma% not allowed");
23427 end if;
23428
23429 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
23430 -- Relative_Deadline pragma node cannot be inserted in the Rep
23431 -- Item chain of Ent since it is rewritten by the expander as a
23432 -- procedure call statement that will break the chain.
23433
23434 Set_Has_Relative_Deadline_Pragma (P);
23435 end Relative_Deadline;
23436
23437 ------------------------
23438 -- Remote_Access_Type --
23439 ------------------------
23440
23441 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
23442
23443 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
23444 E : Entity_Id;
23445
23446 begin
23447 GNAT_Pragma;
23448 Check_Arg_Count (1);
23449 Check_Optional_Identifier (Arg1, Name_Entity);
23450 Check_Arg_Is_Local_Name (Arg1);
23451
23452 E := Entity (Get_Pragma_Arg (Arg1));
23453
23454 -- A pragma that applies to a Ghost entity becomes Ghost for the
23455 -- purposes of legality checks and removal of ignored Ghost code.
23456
23457 Mark_Ghost_Pragma (N, E);
23458
23459 if Nkind (Parent (E)) = N_Formal_Type_Declaration
23460 and then Ekind (E) = E_General_Access_Type
23461 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
23462 and then Scope (Root_Type (Directly_Designated_Type (E)))
23463 = Scope (E)
23464 and then Is_Valid_Remote_Object_Type
23465 (Root_Type (Directly_Designated_Type (E)))
23466 then
23467 Set_Is_Remote_Types (E);
23468
23469 else
23470 Error_Pragma_Arg
23471 ("pragma% applies only to formal access-to-class-wide types",
23472 Arg1);
23473 end if;
23474 end Remote_Access_Type;
23475
23476 ---------------------------
23477 -- Remote_Call_Interface --
23478 ---------------------------
23479
23480 -- pragma Remote_Call_Interface [(library_unit_NAME)];
23481
23482 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
23483 Cunit_Node : Node_Id;
23484 Cunit_Ent : Entity_Id;
23485 K : Node_Kind;
23486
23487 begin
23488 Check_Ada_83_Warning;
23489 Check_Valid_Library_Unit_Pragma;
23490
23491 -- If N was rewritten as a null statement there is nothing more
23492 -- to do.
23493
23494 if Nkind (N) = N_Null_Statement then
23495 return;
23496 end if;
23497
23498 Cunit_Node := Cunit (Current_Sem_Unit);
23499 K := Nkind (Unit (Cunit_Node));
23500 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
23501
23502 -- A pragma that applies to a Ghost entity becomes Ghost for the
23503 -- purposes of legality checks and removal of ignored Ghost code.
23504
23505 Mark_Ghost_Pragma (N, Cunit_Ent);
23506
23507 if K = N_Package_Declaration
23508 or else K = N_Generic_Package_Declaration
23509 or else K = N_Subprogram_Declaration
23510 or else K = N_Generic_Subprogram_Declaration
23511 or else (K = N_Subprogram_Body
23512 and then Acts_As_Spec (Unit (Cunit_Node)))
23513 then
23514 null;
23515 else
23516 Error_Pragma (
23517 "pragma% must apply to package or subprogram declaration");
23518 end if;
23519
23520 Set_Is_Remote_Call_Interface (Cunit_Ent);
23521 end Remote_Call_Interface;
23522
23523 ------------------
23524 -- Remote_Types --
23525 ------------------
23526
23527 -- pragma Remote_Types [(library_unit_NAME)];
23528
23529 when Pragma_Remote_Types => Remote_Types : declare
23530 Cunit_Node : Node_Id;
23531 Cunit_Ent : Entity_Id;
23532
23533 begin
23534 Check_Ada_83_Warning;
23535 Check_Valid_Library_Unit_Pragma;
23536
23537 -- If N was rewritten as a null statement there is nothing more
23538 -- to do.
23539
23540 if Nkind (N) = N_Null_Statement then
23541 return;
23542 end if;
23543
23544 Cunit_Node := Cunit (Current_Sem_Unit);
23545 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
23546
23547 -- A pragma that applies to a Ghost entity becomes Ghost for the
23548 -- purposes of legality checks and removal of ignored Ghost code.
23549
23550 Mark_Ghost_Pragma (N, Cunit_Ent);
23551
23552 if Nkind (Unit (Cunit_Node)) not in
23553 N_Package_Declaration | N_Generic_Package_Declaration
23554 then
23555 Error_Pragma
23556 ("pragma% can only apply to a package declaration");
23557 end if;
23558
23559 Set_Is_Remote_Types (Cunit_Ent);
23560 end Remote_Types;
23561
23562 ---------------
23563 -- Ravenscar --
23564 ---------------
23565
23566 -- pragma Ravenscar;
23567
23568 when Pragma_Ravenscar =>
23569 GNAT_Pragma;
23570 Check_Arg_Count (0);
23571 Check_Valid_Configuration_Pragma;
23572 Set_Ravenscar_Profile (Ravenscar, N);
23573
23574 if Warn_On_Obsolescent_Feature then
23575 Error_Msg_N
23576 ("pragma Ravenscar is an obsolescent feature?j?", N);
23577 Error_Msg_N
23578 ("|use pragma Profile (Ravenscar) instead?j?", N);
23579 end if;
23580
23581 -------------------------
23582 -- Restricted_Run_Time --
23583 -------------------------
23584
23585 -- pragma Restricted_Run_Time;
23586
23587 when Pragma_Restricted_Run_Time =>
23588 GNAT_Pragma;
23589 Check_Arg_Count (0);
23590 Check_Valid_Configuration_Pragma;
23591 Set_Profile_Restrictions
23592 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
23593
23594 if Warn_On_Obsolescent_Feature then
23595 Error_Msg_N
23596 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
23597 N);
23598 Error_Msg_N
23599 ("|use pragma Profile (Restricted) instead?j?", N);
23600 end if;
23601
23602 ------------------
23603 -- Restrictions --
23604 ------------------
23605
23606 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
23607
23608 -- RESTRICTION ::=
23609 -- restriction_IDENTIFIER
23610 -- | restriction_parameter_IDENTIFIER => EXPRESSION
23611
23612 when Pragma_Restrictions =>
23613 Process_Restrictions_Or_Restriction_Warnings
23614 (Warn => Treat_Restrictions_As_Warnings);
23615
23616 --------------------------
23617 -- Restriction_Warnings --
23618 --------------------------
23619
23620 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
23621
23622 -- RESTRICTION ::=
23623 -- restriction_IDENTIFIER
23624 -- | restriction_parameter_IDENTIFIER => EXPRESSION
23625
23626 when Pragma_Restriction_Warnings =>
23627 GNAT_Pragma;
23628 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
23629
23630 ----------------
23631 -- Reviewable --
23632 ----------------
23633
23634 -- pragma Reviewable;
23635
23636 when Pragma_Reviewable =>
23637 Check_Ada_83_Warning;
23638 Check_Arg_Count (0);
23639
23640 -- Call dummy debugging function rv. This is done to assist front
23641 -- end debugging. By placing a Reviewable pragma in the source
23642 -- program, a breakpoint on rv catches this place in the source,
23643 -- allowing convenient stepping to the point of interest.
23644
23645 rv;
23646
23647 --------------------------
23648 -- Secondary_Stack_Size --
23649 --------------------------
23650
23651 -- pragma Secondary_Stack_Size (EXPRESSION);
23652
23653 when Pragma_Secondary_Stack_Size => Secondary_Stack_Size : declare
23654 P : constant Node_Id := Parent (N);
23655 Arg : Node_Id;
23656 Ent : Entity_Id;
23657
23658 begin
23659 GNAT_Pragma;
23660 Check_No_Identifiers;
23661 Check_Arg_Count (1);
23662
23663 if Nkind (P) = N_Task_Definition then
23664 Arg := Get_Pragma_Arg (Arg1);
23665 Ent := Defining_Identifier (Parent (P));
23666
23667 -- The expression must be analyzed in the special manner
23668 -- described in "Handling of Default Expressions" in sem.ads.
23669
23670 Preanalyze_Spec_Expression (Arg, Any_Integer);
23671
23672 -- The pragma cannot appear if the No_Secondary_Stack
23673 -- restriction is in effect.
23674
23675 Check_Restriction (No_Secondary_Stack, Arg);
23676
23677 -- Anything else is incorrect
23678
23679 else
23680 Pragma_Misplaced;
23681 end if;
23682
23683 -- Check duplicate pragma before we chain the pragma in the Rep
23684 -- Item chain of Ent.
23685
23686 Check_Duplicate_Pragma (Ent);
23687 Record_Rep_Item (Ent, N);
23688 end Secondary_Stack_Size;
23689
23690 --------------------------
23691 -- Short_Circuit_And_Or --
23692 --------------------------
23693
23694 -- pragma Short_Circuit_And_Or;
23695
23696 when Pragma_Short_Circuit_And_Or =>
23697 GNAT_Pragma;
23698 Check_Arg_Count (0);
23699 Check_Valid_Configuration_Pragma;
23700 Short_Circuit_And_Or := True;
23701
23702 -------------------
23703 -- Share_Generic --
23704 -------------------
23705
23706 -- pragma Share_Generic (GNAME {, GNAME});
23707
23708 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
23709
23710 when Pragma_Share_Generic =>
23711 GNAT_Pragma;
23712 Process_Generic_List;
23713
23714 ------------
23715 -- Shared --
23716 ------------
23717
23718 -- pragma Shared (LOCAL_NAME);
23719
23720 when Pragma_Shared =>
23721 GNAT_Pragma;
23722 Process_Atomic_Independent_Shared_Volatile;
23723
23724 --------------------
23725 -- Shared_Passive --
23726 --------------------
23727
23728 -- pragma Shared_Passive [(library_unit_NAME)];
23729
23730 -- Set the flag Is_Shared_Passive of program unit name entity
23731
23732 when Pragma_Shared_Passive => Shared_Passive : declare
23733 Cunit_Node : Node_Id;
23734 Cunit_Ent : Entity_Id;
23735
23736 begin
23737 Check_Ada_83_Warning;
23738 Check_Valid_Library_Unit_Pragma;
23739
23740 -- If N was rewritten as a null statement there is nothing more
23741 -- to do.
23742
23743 if Nkind (N) = N_Null_Statement then
23744 return;
23745 end if;
23746
23747 Cunit_Node := Cunit (Current_Sem_Unit);
23748 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
23749
23750 -- A pragma that applies to a Ghost entity becomes Ghost for the
23751 -- purposes of legality checks and removal of ignored Ghost code.
23752
23753 Mark_Ghost_Pragma (N, Cunit_Ent);
23754
23755 if Nkind (Unit (Cunit_Node)) not in
23756 N_Package_Declaration | N_Generic_Package_Declaration
23757 then
23758 Error_Pragma
23759 ("pragma% can only apply to a package declaration");
23760 end if;
23761
23762 Set_Is_Shared_Passive (Cunit_Ent);
23763 end Shared_Passive;
23764
23765 -----------------------
23766 -- Short_Descriptors --
23767 -----------------------
23768
23769 -- pragma Short_Descriptors;
23770
23771 -- Recognize and validate, but otherwise ignore
23772
23773 when Pragma_Short_Descriptors =>
23774 GNAT_Pragma;
23775 Check_Arg_Count (0);
23776 Check_Valid_Configuration_Pragma;
23777
23778 ------------------
23779 -- Side_Effects --
23780 ------------------
23781
23782 -- pragma Side_Effects [ (boolean_EXPRESSION) ];
23783
23784 -- Characteristics:
23785
23786 -- * Analysis - The annotation is fully analyzed immediately upon
23787 -- elaboration as its expression must be static.
23788
23789 -- * Expansion - None.
23790
23791 -- * Template - The annotation utilizes the generic template of the
23792 -- related subprogram [body] when it is:
23793
23794 -- aspect on subprogram declaration
23795 -- aspect on stand-alone subprogram body
23796 -- pragma on stand-alone subprogram body
23797
23798 -- The annotation must prepare its own template when it is:
23799
23800 -- pragma on subprogram declaration
23801
23802 -- * Globals - Capture of global references must occur after full
23803 -- analysis.
23804
23805 -- * Instance - The annotation is instantiated automatically when
23806 -- the related generic subprogram [body] is instantiated except for
23807 -- the "pragma on subprogram declaration" case. In that scenario
23808 -- the annotation must instantiate itself.
23809
23810 when Pragma_Side_Effects => Side_Effects : declare
23811 Subp_Decl : Node_Id;
23812 Spec_Id : Entity_Id;
23813 Over_Id : Entity_Id;
23814
23815 begin
23816 GNAT_Pragma;
23817 Check_No_Identifiers;
23818 Check_At_Most_N_Arguments (1);
23819
23820 Subp_Decl :=
23821 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
23822
23823 -- Abstract subprogram declaration
23824
23825 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
23826 null;
23827
23828 -- Generic subprogram declaration
23829
23830 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
23831 null;
23832
23833 -- Body acts as spec
23834
23835 elsif Nkind (Subp_Decl) = N_Subprogram_Body
23836 and then No (Corresponding_Spec (Subp_Decl))
23837 then
23838 null;
23839
23840 -- Body stub acts as spec
23841
23842 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
23843 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
23844 then
23845 null;
23846
23847 -- Subprogram declaration
23848
23849 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
23850 null;
23851
23852 -- Otherwise the pragma is associated with an illegal construct
23853
23854 else
23855 Error_Pragma ("pragma % must apply to a subprogram");
23856 end if;
23857
23858 if Nkind (Specification (Subp_Decl)) /= N_Function_Specification
23859 then
23860 Error_Pragma ("pragma % must apply to a function");
23861 end if;
23862
23863 Spec_Id := Unique_Defining_Entity (Subp_Decl);
23864
23865 -- Chain the pragma on the contract for completeness
23866
23867 Add_Contract_Item (N, Spec_Id);
23868
23869 -- A function with side effects cannot override a function without
23870 -- side effects (SPARK RM 7.1.2(16)). Overriding checks are
23871 -- usually performed in New_Overloaded_Entity, however at
23872 -- that point the pragma has not been processed yet.
23873
23874 Over_Id := Overridden_Operation (Spec_Id);
23875
23876 if Present (Over_Id)
23877 and then not Is_Function_With_Side_Effects (Over_Id)
23878 then
23879 Error_Msg_N
23880 ("incompatible declaration of side effects for function",
23881 Spec_Id);
23882
23883 Error_Msg_Sloc := Sloc (Over_Id);
23884 Error_Msg_N
23885 ("\& declared # with Side_Effects value False",
23886 Spec_Id);
23887
23888 Error_Msg_Sloc := Sloc (Spec_Id);
23889 Error_Msg_N
23890 ("\overridden # with Side_Effects value True",
23891 Spec_Id);
23892 end if;
23893
23894 -- Analyze the Boolean expression (if any)
23895
23896 if Present (Arg1) then
23897 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
23898 end if;
23899 end Side_Effects;
23900
23901 ------------------------------
23902 -- Simple_Storage_Pool_Type --
23903 ------------------------------
23904
23905 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
23906
23907 when Pragma_Simple_Storage_Pool_Type =>
23908 Simple_Storage_Pool_Type : declare
23909 Typ : Entity_Id;
23910 Type_Id : Node_Id;
23911
23912 begin
23913 GNAT_Pragma;
23914 Check_Arg_Count (1);
23915 Check_Arg_Is_Library_Level_Local_Name (Arg1);
23916
23917 Type_Id := Get_Pragma_Arg (Arg1);
23918 Find_Type (Type_Id);
23919 Typ := Entity (Type_Id);
23920
23921 if Typ = Any_Type then
23922 return;
23923 end if;
23924
23925 -- A pragma that applies to a Ghost entity becomes Ghost for the
23926 -- purposes of legality checks and removal of ignored Ghost code.
23927
23928 Mark_Ghost_Pragma (N, Typ);
23929
23930 -- We require the pragma to apply to a type declared in a package
23931 -- declaration, but not (immediately) within a package body.
23932
23933 if Ekind (Current_Scope) /= E_Package
23934 or else In_Package_Body (Current_Scope)
23935 then
23936 Error_Pragma
23937 ("pragma% can only apply to type declared immediately "
23938 & "within a package declaration");
23939 end if;
23940
23941 -- A simple storage pool type must be an immutably limited record
23942 -- or private type. If the pragma is given for a private type,
23943 -- the full type is similarly restricted (which is checked later
23944 -- in Freeze_Entity).
23945
23946 if Is_Record_Type (Typ)
23947 and then not Is_Inherently_Limited_Type (Typ)
23948 then
23949 Error_Pragma
23950 ("pragma% can only apply to explicitly limited record type");
23951
23952 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
23953 Error_Pragma
23954 ("pragma% can only apply to a private type that is limited");
23955
23956 elsif not Is_Record_Type (Typ)
23957 and then not Is_Private_Type (Typ)
23958 then
23959 Error_Pragma
23960 ("pragma% can only apply to limited record or private type");
23961 end if;
23962
23963 Record_Rep_Item (Typ, N);
23964 end Simple_Storage_Pool_Type;
23965
23966 ----------------------
23967 -- Source_File_Name --
23968 ----------------------
23969
23970 -- There are five forms for this pragma:
23971
23972 -- pragma Source_File_Name (
23973 -- [UNIT_NAME =>] unit_NAME,
23974 -- BODY_FILE_NAME => STRING_LITERAL
23975 -- [, [INDEX =>] INTEGER_LITERAL]);
23976
23977 -- pragma Source_File_Name (
23978 -- [UNIT_NAME =>] unit_NAME,
23979 -- SPEC_FILE_NAME => STRING_LITERAL
23980 -- [, [INDEX =>] INTEGER_LITERAL]);
23981
23982 -- pragma Source_File_Name (
23983 -- BODY_FILE_NAME => STRING_LITERAL
23984 -- [, DOT_REPLACEMENT => STRING_LITERAL]
23985 -- [, CASING => CASING_SPEC]);
23986
23987 -- pragma Source_File_Name (
23988 -- SPEC_FILE_NAME => STRING_LITERAL
23989 -- [, DOT_REPLACEMENT => STRING_LITERAL]
23990 -- [, CASING => CASING_SPEC]);
23991
23992 -- pragma Source_File_Name (
23993 -- SUBUNIT_FILE_NAME => STRING_LITERAL
23994 -- [, DOT_REPLACEMENT => STRING_LITERAL]
23995 -- [, CASING => CASING_SPEC]);
23996
23997 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
23998
23999 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
24000 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
24001 -- only be used when no project file is used, while SFNP can only be
24002 -- used when a project file is used.
24003
24004 -- No processing here. Processing was completed during parsing, since
24005 -- we need to have file names set as early as possible. Units are
24006 -- loaded well before semantic processing starts.
24007
24008 -- The only processing we defer to this point is the check for
24009 -- correct placement.
24010
24011 when Pragma_Source_File_Name =>
24012 GNAT_Pragma;
24013 Check_Valid_Configuration_Pragma;
24014
24015 ------------------------------
24016 -- Source_File_Name_Project --
24017 ------------------------------
24018
24019 -- See Source_File_Name for syntax
24020
24021 -- No processing here. Processing was completed during parsing, since
24022 -- we need to have file names set as early as possible. Units are
24023 -- loaded well before semantic processing starts.
24024
24025 -- The only processing we defer to this point is the check for
24026 -- correct placement.
24027
24028 when Pragma_Source_File_Name_Project =>
24029 GNAT_Pragma;
24030 Check_Valid_Configuration_Pragma;
24031
24032 -- Check that a pragma Source_File_Name_Project is used only in a
24033 -- configuration pragmas file.
24034
24035 -- Pragmas Source_File_Name_Project should only be generated by
24036 -- the Project Manager in configuration pragmas files.
24037
24038 -- This is really an ugly test. It seems to depend on some
24039 -- accidental and undocumented property. At the very least it
24040 -- needs to be documented, but it would be better to have a
24041 -- clean way of testing if we are in a configuration file???
24042
24043 if Present (Parent (N)) then
24044 Error_Pragma
24045 ("pragma% can only appear in a configuration pragmas file");
24046 end if;
24047
24048 ----------------------
24049 -- Source_Reference --
24050 ----------------------
24051
24052 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
24053
24054 -- Nothing to do, all processing completed in Par.Prag, since we need
24055 -- the information for possible parser messages that are output.
24056
24057 when Pragma_Source_Reference =>
24058 GNAT_Pragma;
24059
24060 ----------------
24061 -- SPARK_Mode --
24062 ----------------
24063
24064 -- pragma SPARK_Mode [(Auto | On | Off)];
24065
24066 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
24067 Mode_Id : SPARK_Mode_Type;
24068
24069 procedure Check_Pragma_Conformance
24070 (Context_Pragma : Node_Id;
24071 Entity : Entity_Id;
24072 Entity_Pragma : Node_Id);
24073 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
24074 -- conformance of pragma N depending the following scenarios:
24075 --
24076 -- If pragma Context_Pragma is not Empty, verify that pragma N is
24077 -- compatible with the pragma Context_Pragma that was inherited
24078 -- from the context:
24079 -- * If the mode of Context_Pragma is ON, then the new mode can
24080 -- be anything.
24081 -- * If the mode of Context_Pragma is OFF, then the only allowed
24082 -- new mode is also OFF. Emit error if this is not the case.
24083 --
24084 -- If Entity is not Empty, verify that pragma N is compatible with
24085 -- pragma Entity_Pragma that belongs to Entity.
24086 -- * If Entity_Pragma is Empty, always issue an error as this
24087 -- corresponds to the case where a previous section of Entity
24088 -- has no SPARK_Mode set.
24089 -- * If the mode of Entity_Pragma is ON, then the new mode can
24090 -- be anything.
24091 -- * If the mode of Entity_Pragma is OFF, then the only allowed
24092 -- new mode is also OFF. Emit error if this is not the case.
24093
24094 procedure Check_Library_Level_Entity (E : Entity_Id);
24095 -- Subsidiary to routines Process_xxx. Verify that the related
24096 -- entity E subject to pragma SPARK_Mode is library-level.
24097
24098 procedure Process_Body (Decl : Node_Id);
24099 -- Verify the legality of pragma SPARK_Mode when it appears as the
24100 -- top of the body declarations of entry, package, protected unit,
24101 -- subprogram or task unit body denoted by Decl.
24102
24103 procedure Process_Overloadable (Decl : Node_Id);
24104 -- Verify the legality of pragma SPARK_Mode when it applies to an
24105 -- entry or [generic] subprogram declaration denoted by Decl.
24106
24107 procedure Process_Private_Part (Decl : Node_Id);
24108 -- Verify the legality of pragma SPARK_Mode when it appears at the
24109 -- top of the private declarations of a package spec, protected or
24110 -- task unit declaration denoted by Decl.
24111
24112 procedure Process_Statement_Part (Decl : Node_Id);
24113 -- Verify the legality of pragma SPARK_Mode when it appears at the
24114 -- top of the statement sequence of a package body denoted by node
24115 -- Decl.
24116
24117 procedure Process_Visible_Part (Decl : Node_Id);
24118 -- Verify the legality of pragma SPARK_Mode when it appears at the
24119 -- top of the visible declarations of a package spec, protected or
24120 -- task unit declaration denoted by Decl. The routine is also used
24121 -- on protected or task units declared without a definition.
24122
24123 procedure Set_SPARK_Context;
24124 -- Subsidiary to routines Process_xxx. Set the global variables
24125 -- which represent the mode of the context from pragma N. Ensure
24126 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
24127
24128 ------------------------------
24129 -- Check_Pragma_Conformance --
24130 ------------------------------
24131
24132 procedure Check_Pragma_Conformance
24133 (Context_Pragma : Node_Id;
24134 Entity : Entity_Id;
24135 Entity_Pragma : Node_Id)
24136 is
24137 Err_Id : Entity_Id;
24138 Err_N : Node_Id;
24139
24140 begin
24141 -- The current pragma may appear without an argument. If this
24142 -- is the case, associate all error messages with the pragma
24143 -- itself.
24144
24145 if Present (Arg1) then
24146 Err_N := Arg1;
24147 else
24148 Err_N := N;
24149 end if;
24150
24151 -- The mode of the current pragma is compared against that of
24152 -- an enclosing context.
24153
24154 if Present (Context_Pragma) then
24155 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
24156
24157 -- Issue an error if the new mode is less restrictive than
24158 -- that of the context.
24159
24160 if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off
24161 and then Get_SPARK_Mode_From_Annotation (N) = On
24162 then
24163 Error_Msg_N
24164 ("cannot change SPARK_Mode from Off to On", Err_N);
24165 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
24166 Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N);
24167 raise Pragma_Exit;
24168 end if;
24169 end if;
24170
24171 -- The mode of the current pragma is compared against that of
24172 -- an initial package, protected type, subprogram or task type
24173 -- declaration.
24174
24175 if Present (Entity) then
24176
24177 -- A simple protected or task type is transformed into an
24178 -- anonymous type whose name cannot be used to issue error
24179 -- messages. Recover the original entity of the type.
24180
24181 if Ekind (Entity) in E_Protected_Type | E_Task_Type then
24182 Err_Id :=
24183 Defining_Entity
24184 (Original_Node (Unit_Declaration_Node (Entity)));
24185 else
24186 Err_Id := Entity;
24187 end if;
24188
24189 -- Both the initial declaration and the completion carry
24190 -- SPARK_Mode pragmas.
24191
24192 if Present (Entity_Pragma) then
24193 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
24194
24195 -- Issue an error if the new mode is less restrictive
24196 -- than that of the initial declaration.
24197
24198 if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off
24199 and then Get_SPARK_Mode_From_Annotation (N) = On
24200 then
24201 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
24202 Error_Msg_Sloc := Sloc (Entity_Pragma);
24203 Error_Msg_NE
24204 ("\value Off was set for SPARK_Mode on&#",
24205 Err_N, Err_Id);
24206 raise Pragma_Exit;
24207 end if;
24208
24209 -- Otherwise the initial declaration lacks a SPARK_Mode
24210 -- pragma in which case the current pragma is illegal as
24211 -- it cannot "complete".
24212
24213 elsif Get_SPARK_Mode_From_Annotation (N) = Off
24214 and then (Is_Generic_Unit (Entity) or else In_Instance)
24215 then
24216 null;
24217
24218 else
24219 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
24220 Error_Msg_Sloc := Sloc (Err_Id);
24221 Error_Msg_NE
24222 ("\no value was set for SPARK_Mode on&#",
24223 Err_N, Err_Id);
24224 raise Pragma_Exit;
24225 end if;
24226 end if;
24227 end Check_Pragma_Conformance;
24228
24229 --------------------------------
24230 -- Check_Library_Level_Entity --
24231 --------------------------------
24232
24233 procedure Check_Library_Level_Entity (E : Entity_Id) is
24234 procedure Add_Entity_To_Name_Buffer;
24235 -- Add the E_Kind of entity E to the name buffer
24236
24237 -------------------------------
24238 -- Add_Entity_To_Name_Buffer --
24239 -------------------------------
24240
24241 procedure Add_Entity_To_Name_Buffer is
24242 begin
24243 if Ekind (E) in E_Entry | E_Entry_Family then
24244 Add_Str_To_Name_Buffer ("entry");
24245
24246 elsif Ekind (E) in E_Generic_Package
24247 | E_Package
24248 | E_Package_Body
24249 then
24250 Add_Str_To_Name_Buffer ("package");
24251
24252 elsif Ekind (E) in E_Protected_Body | E_Protected_Type then
24253 Add_Str_To_Name_Buffer ("protected type");
24254
24255 elsif Ekind (E) in E_Function
24256 | E_Generic_Function
24257 | E_Generic_Procedure
24258 | E_Procedure
24259 | E_Subprogram_Body
24260 then
24261 Add_Str_To_Name_Buffer ("subprogram");
24262
24263 else
24264 pragma Assert (Ekind (E) in E_Task_Body | E_Task_Type);
24265 Add_Str_To_Name_Buffer ("task type");
24266 end if;
24267 end Add_Entity_To_Name_Buffer;
24268
24269 -- Local variables
24270
24271 Msg_1 : constant String :=
24272 "incorrect placement of pragma% with value ""On"" '[[]']";
24273 Msg_2 : Name_Id;
24274
24275 -- Start of processing for Check_Library_Level_Entity
24276
24277 begin
24278 -- A SPARK_Mode of On shall only apply to library-level
24279 -- entities, except for those in generic instances, which are
24280 -- ignored (even if the entity gets SPARK_Mode pragma attached
24281 -- in the AST, its effect is not taken into account unless the
24282 -- context already provides SPARK_Mode of On in GNATprove).
24283
24284 if Get_SPARK_Mode_From_Annotation (N) = On
24285 and then not Is_Library_Level_Entity (E)
24286 and then Instantiation_Location (Sloc (N)) = No_Location
24287 then
24288 Error_Msg_Name_1 := Pname;
24289 Error_Msg_Code := GEC_SPARK_Mode_On_Not_Library_Level;
24290 Error_Msg_N (Fix_Error (Msg_1), N);
24291
24292 Name_Len := 0;
24293 Add_Str_To_Name_Buffer ("\& is not a library-level ");
24294 Add_Entity_To_Name_Buffer;
24295
24296 Msg_2 := Name_Find;
24297 Error_Msg_NE (Get_Name_String (Msg_2), N, E);
24298
24299 raise Pragma_Exit;
24300 end if;
24301 end Check_Library_Level_Entity;
24302
24303 ------------------
24304 -- Process_Body --
24305 ------------------
24306
24307 procedure Process_Body (Decl : Node_Id) is
24308 Body_Id : constant Entity_Id := Defining_Entity (Decl);
24309 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
24310
24311 begin
24312 -- Ignore pragma when applied to the special body created
24313 -- for inlining, recognized by its internal name _Parent; or
24314 -- when applied to the special body created for contracts,
24315 -- recognized by its internal name _Wrapped_Statements.
24316
24317 if Chars (Body_Id) in Name_uParent
24318 | Name_uWrapped_Statements
24319 then
24320 return;
24321 end if;
24322
24323 Check_Library_Level_Entity (Body_Id);
24324
24325 -- For entry bodies, verify the legality against:
24326 -- * The mode of the context
24327 -- * The mode of the spec (if any)
24328
24329 if Nkind (Decl) in N_Entry_Body | N_Subprogram_Body then
24330
24331 -- A stand-alone subprogram body
24332
24333 if Body_Id = Spec_Id then
24334 Check_Pragma_Conformance
24335 (Context_Pragma => SPARK_Pragma (Body_Id),
24336 Entity => Empty,
24337 Entity_Pragma => Empty);
24338
24339 -- An entry or subprogram body that completes a previous
24340 -- declaration.
24341
24342 else
24343 Check_Pragma_Conformance
24344 (Context_Pragma => SPARK_Pragma (Body_Id),
24345 Entity => Spec_Id,
24346 Entity_Pragma => SPARK_Pragma (Spec_Id));
24347 end if;
24348
24349 Set_SPARK_Context;
24350 Set_SPARK_Pragma (Body_Id, N);
24351 Set_SPARK_Pragma_Inherited (Body_Id, False);
24352
24353 -- For package bodies, verify the legality against:
24354 -- * The mode of the context
24355 -- * The mode of the private part
24356
24357 -- This case is separated from protected and task bodies
24358 -- because the statement part of the package body inherits
24359 -- the mode of the body declarations.
24360
24361 elsif Nkind (Decl) = N_Package_Body then
24362 Check_Pragma_Conformance
24363 (Context_Pragma => SPARK_Pragma (Body_Id),
24364 Entity => Spec_Id,
24365 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
24366
24367 Set_SPARK_Context;
24368 Set_SPARK_Pragma (Body_Id, N);
24369 Set_SPARK_Pragma_Inherited (Body_Id, False);
24370 Set_SPARK_Aux_Pragma (Body_Id, N);
24371 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
24372
24373 -- For protected and task bodies, verify the legality against:
24374 -- * The mode of the context
24375 -- * The mode of the private part
24376
24377 else
24378 pragma Assert
24379 (Nkind (Decl) in N_Protected_Body | N_Task_Body);
24380
24381 Check_Pragma_Conformance
24382 (Context_Pragma => SPARK_Pragma (Body_Id),
24383 Entity => Spec_Id,
24384 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
24385
24386 Set_SPARK_Context;
24387 Set_SPARK_Pragma (Body_Id, N);
24388 Set_SPARK_Pragma_Inherited (Body_Id, False);
24389 end if;
24390 end Process_Body;
24391
24392 --------------------------
24393 -- Process_Overloadable --
24394 --------------------------
24395
24396 procedure Process_Overloadable (Decl : Node_Id) is
24397 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
24398 Spec_Typ : constant Entity_Id := Etype (Spec_Id);
24399
24400 begin
24401 Check_Library_Level_Entity (Spec_Id);
24402
24403 -- Verify the legality against:
24404 -- * The mode of the context
24405
24406 Check_Pragma_Conformance
24407 (Context_Pragma => SPARK_Pragma (Spec_Id),
24408 Entity => Empty,
24409 Entity_Pragma => Empty);
24410
24411 Set_SPARK_Pragma (Spec_Id, N);
24412 Set_SPARK_Pragma_Inherited (Spec_Id, False);
24413
24414 -- When the pragma applies to the anonymous object created for
24415 -- a single task type, decorate the type as well. This scenario
24416 -- arises when the single task type lacks a task definition,
24417 -- therefore there is no issue with respect to a potential
24418 -- pragma SPARK_Mode in the private part.
24419
24420 -- task type Anon_Task_Typ;
24421 -- Obj : Anon_Task_Typ;
24422 -- pragma SPARK_Mode ...;
24423
24424 if Is_Single_Task_Object (Spec_Id) then
24425 Set_SPARK_Pragma (Spec_Typ, N);
24426 Set_SPARK_Pragma_Inherited (Spec_Typ, False);
24427 Set_SPARK_Aux_Pragma (Spec_Typ, N);
24428 Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True);
24429 end if;
24430 end Process_Overloadable;
24431
24432 --------------------------
24433 -- Process_Private_Part --
24434 --------------------------
24435
24436 procedure Process_Private_Part (Decl : Node_Id) is
24437 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
24438
24439 begin
24440 Check_Library_Level_Entity (Spec_Id);
24441
24442 -- Verify the legality against:
24443 -- * The mode of the visible declarations
24444
24445 Check_Pragma_Conformance
24446 (Context_Pragma => Empty,
24447 Entity => Spec_Id,
24448 Entity_Pragma => SPARK_Pragma (Spec_Id));
24449
24450 Set_SPARK_Context;
24451 Set_SPARK_Aux_Pragma (Spec_Id, N);
24452 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
24453 end Process_Private_Part;
24454
24455 ----------------------------
24456 -- Process_Statement_Part --
24457 ----------------------------
24458
24459 procedure Process_Statement_Part (Decl : Node_Id) is
24460 Body_Id : constant Entity_Id := Defining_Entity (Decl);
24461
24462 begin
24463 Check_Library_Level_Entity (Body_Id);
24464
24465 -- Verify the legality against:
24466 -- * The mode of the body declarations
24467
24468 Check_Pragma_Conformance
24469 (Context_Pragma => Empty,
24470 Entity => Body_Id,
24471 Entity_Pragma => SPARK_Pragma (Body_Id));
24472
24473 Set_SPARK_Context;
24474 Set_SPARK_Aux_Pragma (Body_Id, N);
24475 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
24476 end Process_Statement_Part;
24477
24478 --------------------------
24479 -- Process_Visible_Part --
24480 --------------------------
24481
24482 procedure Process_Visible_Part (Decl : Node_Id) is
24483 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
24484 Obj_Id : Entity_Id;
24485
24486 begin
24487 Check_Library_Level_Entity (Spec_Id);
24488
24489 -- Verify the legality against:
24490 -- * The mode of the context
24491
24492 Check_Pragma_Conformance
24493 (Context_Pragma => SPARK_Pragma (Spec_Id),
24494 Entity => Empty,
24495 Entity_Pragma => Empty);
24496
24497 -- A task unit declared without a definition does not set the
24498 -- SPARK_Mode of the context because the task does not have any
24499 -- entries that could inherit the mode.
24500
24501 if Nkind (Decl) not in
24502 N_Single_Task_Declaration | N_Task_Type_Declaration
24503 then
24504 Set_SPARK_Context;
24505 end if;
24506
24507 Set_SPARK_Pragma (Spec_Id, N);
24508 Set_SPARK_Pragma_Inherited (Spec_Id, False);
24509 Set_SPARK_Aux_Pragma (Spec_Id, N);
24510 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
24511
24512 -- When the pragma applies to a single protected or task type,
24513 -- decorate the corresponding anonymous object as well.
24514
24515 -- protected Anon_Prot_Typ is
24516 -- pragma SPARK_Mode ...;
24517 -- ...
24518 -- end Anon_Prot_Typ;
24519
24520 -- Obj : Anon_Prot_Typ;
24521
24522 if Is_Single_Concurrent_Type (Spec_Id) then
24523 Obj_Id := Anonymous_Object (Spec_Id);
24524
24525 Set_SPARK_Pragma (Obj_Id, N);
24526 Set_SPARK_Pragma_Inherited (Obj_Id, False);
24527 end if;
24528 end Process_Visible_Part;
24529
24530 -----------------------
24531 -- Set_SPARK_Context --
24532 -----------------------
24533
24534 procedure Set_SPARK_Context is
24535 begin
24536 SPARK_Mode := Mode_Id;
24537 SPARK_Mode_Pragma := N;
24538 end Set_SPARK_Context;
24539
24540 -- Local variables
24541
24542 Context : Node_Id;
24543 Mode : Name_Id;
24544 Stmt : Node_Id;
24545
24546 -- Start of processing for Do_SPARK_Mode
24547
24548 begin
24549 GNAT_Pragma;
24550 Check_No_Identifiers;
24551 Check_At_Most_N_Arguments (1);
24552
24553 -- Check the legality of the mode (no argument = ON)
24554
24555 if Arg_Count = 1 then
24556 Check_Arg_Is_One_Of (Arg1, Name_Auto, Name_On, Name_Off);
24557 Mode := Chars (Get_Pragma_Arg (Arg1));
24558 else
24559 Mode := Name_On;
24560 end if;
24561
24562 Mode_Id := Get_SPARK_Mode_Type (Mode);
24563 Context := Parent (N);
24564
24565 -- When a SPARK_Mode pragma appears inside an instantiation whose
24566 -- enclosing context has SPARK_Mode set to "off", the pragma has
24567 -- no semantic effect.
24568
24569 if Ignore_SPARK_Mode_Pragmas_In_Instance
24570 and then Mode_Id /= Off
24571 then
24572 Rewrite (N, Make_Null_Statement (Loc));
24573 Analyze (N);
24574 return;
24575 end if;
24576
24577 -- The pragma appears in a configuration file
24578
24579 if No (Context) then
24580 Check_Valid_Configuration_Pragma;
24581
24582 if Present (SPARK_Mode_Pragma) then
24583 Duplication_Error
24584 (Prag => N,
24585 Prev => SPARK_Mode_Pragma);
24586 raise Pragma_Exit;
24587 end if;
24588
24589 Set_SPARK_Context;
24590
24591 -- The pragma acts as a configuration pragma in a compilation unit
24592
24593 -- pragma SPARK_Mode ...;
24594 -- package Pack is ...;
24595
24596 elsif Nkind (Context) = N_Compilation_Unit
24597 and then List_Containing (N) = Context_Items (Context)
24598 then
24599 Check_Valid_Configuration_Pragma;
24600 Set_SPARK_Context;
24601
24602 -- Otherwise the placement of the pragma within the tree dictates
24603 -- its associated construct. Inspect the declarative list where
24604 -- the pragma resides to find a potential construct.
24605
24606 else
24607 -- An explicit mode of Auto is only allowed as a configuration
24608 -- pragma. Escape "pragma" to avoid replacement with "aspect".
24609
24610 if Mode_Id = None then
24611 Error_Pragma_Arg
24612 ("only configuration 'p'r'a'g'm'a% can have value &",
24613 Arg1);
24614 end if;
24615
24616 Stmt := Prev (N);
24617 while Present (Stmt) loop
24618
24619 -- Skip prior pragmas, but check for duplicates. Note that
24620 -- this also takes care of pragmas generated for aspects.
24621
24622 if Nkind (Stmt) = N_Pragma then
24623 if Pragma_Name (Stmt) = Pname then
24624 Duplication_Error
24625 (Prag => N,
24626 Prev => Stmt);
24627 raise Pragma_Exit;
24628 end if;
24629
24630 -- The pragma applies to an expression function that has
24631 -- already been rewritten into a subprogram declaration.
24632
24633 -- function Expr_Func return ... is (...);
24634 -- pragma SPARK_Mode ...;
24635
24636 elsif Nkind (Stmt) = N_Subprogram_Declaration
24637 and then Nkind (Original_Node (Stmt)) =
24638 N_Expression_Function
24639 then
24640 Process_Overloadable (Stmt);
24641 return;
24642
24643 -- The pragma applies to the anonymous object created for a
24644 -- single concurrent type.
24645
24646 -- protected type Anon_Prot_Typ ...;
24647 -- Obj : Anon_Prot_Typ;
24648 -- pragma SPARK_Mode ...;
24649
24650 elsif Nkind (Stmt) = N_Object_Declaration
24651 and then Is_Single_Concurrent_Object
24652 (Defining_Entity (Stmt))
24653 then
24654 Process_Overloadable (Stmt);
24655 return;
24656
24657 -- Skip internally generated code
24658
24659 elsif not Comes_From_Source (Stmt) then
24660 null;
24661
24662 -- The pragma applies to an entry or [generic] subprogram
24663 -- declaration.
24664
24665 -- entry Ent ...;
24666 -- pragma SPARK_Mode ...;
24667
24668 -- [generic]
24669 -- procedure Proc ...;
24670 -- pragma SPARK_Mode ...;
24671
24672 elsif Nkind (Stmt) in N_Generic_Subprogram_Declaration
24673 | N_Subprogram_Declaration
24674 or else (Nkind (Stmt) = N_Entry_Declaration
24675 and then Is_Protected_Type
24676 (Scope (Defining_Entity (Stmt))))
24677 then
24678 Process_Overloadable (Stmt);
24679 return;
24680
24681 -- Otherwise the pragma does not apply to a legal construct
24682 -- or it does not appear at the top of a declarative or a
24683 -- statement list. Issue an error and stop the analysis.
24684
24685 else
24686 Pragma_Misplaced;
24687 end if;
24688
24689 Prev (Stmt);
24690 end loop;
24691
24692 -- The pragma applies to a package or a subprogram that acts as
24693 -- a compilation unit.
24694
24695 -- procedure Proc ...;
24696 -- pragma SPARK_Mode ...;
24697
24698 if Nkind (Context) = N_Compilation_Unit_Aux then
24699 Context := Unit (Parent (Context));
24700 end if;
24701
24702 -- The pragma appears at the top of entry, package, protected
24703 -- unit, subprogram or task unit body declarations.
24704
24705 -- entry Ent when ... is
24706 -- pragma SPARK_Mode ...;
24707
24708 -- package body Pack is
24709 -- pragma SPARK_Mode ...;
24710
24711 -- procedure Proc ... is
24712 -- pragma SPARK_Mode;
24713
24714 -- protected body Prot is
24715 -- pragma SPARK_Mode ...;
24716
24717 if Nkind (Context) in N_Entry_Body
24718 | N_Package_Body
24719 | N_Protected_Body
24720 | N_Subprogram_Body
24721 | N_Task_Body
24722 then
24723 Process_Body (Context);
24724
24725 -- The pragma appears at the top of the visible or private
24726 -- declaration of a package spec, protected or task unit.
24727
24728 -- package Pack is
24729 -- pragma SPARK_Mode ...;
24730 -- private
24731 -- pragma SPARK_Mode ...;
24732
24733 -- protected [type] Prot is
24734 -- pragma SPARK_Mode ...;
24735 -- private
24736 -- pragma SPARK_Mode ...;
24737
24738 elsif Nkind (Context) in N_Package_Specification
24739 | N_Protected_Definition
24740 | N_Task_Definition
24741 then
24742 if List_Containing (N) = Visible_Declarations (Context) then
24743 Process_Visible_Part (Parent (Context));
24744 else
24745 Process_Private_Part (Parent (Context));
24746 end if;
24747
24748 -- The pragma appears at the top of package body statements
24749
24750 -- package body Pack is
24751 -- begin
24752 -- pragma SPARK_Mode;
24753
24754 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
24755 and then Nkind (Parent (Context)) = N_Package_Body
24756 then
24757 Process_Statement_Part (Parent (Context));
24758
24759 -- The pragma appeared as an aspect of a [generic] subprogram
24760 -- declaration that acts as a compilation unit.
24761
24762 -- [generic]
24763 -- procedure Proc ...;
24764 -- pragma SPARK_Mode ...;
24765
24766 elsif Nkind (Context) in N_Generic_Subprogram_Declaration
24767 | N_Subprogram_Declaration
24768 then
24769 Process_Overloadable (Context);
24770
24771 -- The pragma does not apply to a legal construct, issue error
24772
24773 else
24774 Pragma_Misplaced;
24775 end if;
24776 end if;
24777 end Do_SPARK_Mode;
24778
24779 --------------------------------
24780 -- Static_Elaboration_Desired --
24781 --------------------------------
24782
24783 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
24784
24785 when Pragma_Static_Elaboration_Desired =>
24786 GNAT_Pragma;
24787 Check_At_Most_N_Arguments (1);
24788
24789 if Is_Compilation_Unit (Current_Scope)
24790 and then Ekind (Current_Scope) = E_Package
24791 then
24792 Set_Static_Elaboration_Desired (Current_Scope, True);
24793 else
24794 Error_Pragma ("pragma% must apply to a library-level package");
24795 end if;
24796
24797 ------------------
24798 -- Storage_Size --
24799 ------------------
24800
24801 -- pragma Storage_Size (EXPRESSION);
24802
24803 when Pragma_Storage_Size => Storage_Size : declare
24804 P : constant Node_Id := Parent (N);
24805 Arg : Node_Id;
24806
24807 begin
24808 Check_No_Identifiers;
24809 Check_Arg_Count (1);
24810
24811 -- The expression must be analyzed in the special manner described
24812 -- in "Handling of Default Expressions" in sem.ads.
24813
24814 Arg := Get_Pragma_Arg (Arg1);
24815 Preanalyze_Spec_Expression (Arg, Any_Integer);
24816
24817 if not Is_OK_Static_Expression (Arg) then
24818 Check_Restriction (Static_Storage_Size, Arg);
24819 end if;
24820
24821 if Nkind (P) /= N_Task_Definition then
24822 Pragma_Misplaced;
24823
24824 else
24825 if Has_Storage_Size_Pragma (P) then
24826 Error_Pragma ("duplicate pragma% not allowed");
24827 else
24828 Set_Has_Storage_Size_Pragma (P, True);
24829 end if;
24830
24831 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
24832 end if;
24833 end Storage_Size;
24834
24835 ------------------
24836 -- Storage_Unit --
24837 ------------------
24838
24839 -- pragma Storage_Unit (NUMERIC_LITERAL);
24840
24841 -- Only permitted argument is System'Storage_Unit value
24842
24843 when Pragma_Storage_Unit =>
24844 Check_No_Identifiers;
24845 Check_Arg_Count (1);
24846 Check_Arg_Is_Integer_Literal (Arg1);
24847
24848 if Intval (Get_Pragma_Arg (Arg1)) /=
24849 UI_From_Int (Ttypes.System_Storage_Unit)
24850 then
24851 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
24852 Error_Pragma_Arg
24853 ("the only allowed argument for pragma% is ^", Arg1);
24854 end if;
24855
24856 --------------------
24857 -- Stream_Convert --
24858 --------------------
24859
24860 -- pragma Stream_Convert (
24861 -- [Entity =>] type_LOCAL_NAME,
24862 -- [Read =>] function_NAME,
24863 -- [Write =>] function NAME);
24864
24865 when Pragma_Stream_Convert => Stream_Convert : declare
24866 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
24867 -- Check that the given argument is the name of a local function
24868 -- of one argument that is not overloaded earlier in the current
24869 -- local scope. A check is also made that the argument is a
24870 -- function with one parameter.
24871
24872 --------------------------------------
24873 -- Check_OK_Stream_Convert_Function --
24874 --------------------------------------
24875
24876 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
24877 Ent : Entity_Id;
24878
24879 begin
24880 Check_Arg_Is_Local_Name (Arg);
24881 Ent := Entity (Get_Pragma_Arg (Arg));
24882
24883 if Has_Homonym (Ent) then
24884 Error_Pragma_Arg
24885 ("argument for pragma% may not be overloaded", Arg);
24886 end if;
24887
24888 if Ekind (Ent) /= E_Function
24889 or else No (First_Formal (Ent))
24890 or else Present (Next_Formal (First_Formal (Ent)))
24891 then
24892 Error_Pragma_Arg
24893 ("argument for pragma% must be function of one argument",
24894 Arg);
24895 elsif Is_Abstract_Subprogram (Ent) then
24896 Error_Pragma_Arg
24897 ("argument for pragma% cannot be abstract", Arg);
24898 end if;
24899 end Check_OK_Stream_Convert_Function;
24900
24901 -- Start of processing for Stream_Convert
24902
24903 begin
24904 GNAT_Pragma;
24905 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
24906 Check_Arg_Count (3);
24907 Check_Optional_Identifier (Arg1, Name_Entity);
24908 Check_Optional_Identifier (Arg2, Name_Read);
24909 Check_Optional_Identifier (Arg3, Name_Write);
24910 Check_Arg_Is_Local_Name (Arg1);
24911 Check_OK_Stream_Convert_Function (Arg2);
24912 Check_OK_Stream_Convert_Function (Arg3);
24913
24914 declare
24915 Typ : constant Entity_Id :=
24916 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
24917 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
24918 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
24919
24920 begin
24921 Check_First_Subtype (Arg1);
24922
24923 -- Check for too early or too late. Note that we don't enforce
24924 -- the rule about primitive operations in this case, since, as
24925 -- is the case for explicit stream attributes themselves, these
24926 -- restrictions are not appropriate. Note that the chaining of
24927 -- the pragma by Rep_Item_Too_Late is actually the critical
24928 -- processing done for this pragma.
24929
24930 if Rep_Item_Too_Early (Typ, N)
24931 or else
24932 Rep_Item_Too_Late (Typ, N, FOnly => True)
24933 then
24934 return;
24935 end if;
24936
24937 -- Return if previous error
24938
24939 if Etype (Typ) = Any_Type
24940 or else
24941 Etype (Read) = Any_Type
24942 or else
24943 Etype (Write) = Any_Type
24944 then
24945 return;
24946 end if;
24947
24948 -- Error checks
24949
24950 if Underlying_Type (Etype (Read)) /= Typ then
24951 Error_Pragma_Arg
24952 ("incorrect return type for function&", Arg2);
24953 end if;
24954
24955 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
24956 Error_Pragma_Arg
24957 ("incorrect parameter type for function&", Arg3);
24958 end if;
24959
24960 if Underlying_Type (Etype (First_Formal (Read))) /=
24961 Underlying_Type (Etype (Write))
24962 then
24963 Error_Pragma_Arg
24964 ("result type of & does not match Read parameter type",
24965 Arg3);
24966 end if;
24967 end;
24968 end Stream_Convert;
24969
24970 ------------------
24971 -- Style_Checks --
24972 ------------------
24973
24974 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
24975
24976 -- This is processed by the parser since some of the style checks
24977 -- take place during source scanning and parsing. This means that
24978 -- we don't need to issue error messages here.
24979
24980 when Pragma_Style_Checks => Style_Checks : declare
24981 A : constant Node_Id := Get_Pragma_Arg (Arg1);
24982 S : String_Id;
24983 C : Char_Code;
24984
24985 begin
24986 GNAT_Pragma;
24987 Check_No_Identifiers;
24988
24989 -- Two argument form
24990
24991 if Arg_Count = 2 then
24992 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
24993
24994 declare
24995 E_Id : Node_Id;
24996 E : Entity_Id;
24997
24998 begin
24999 E_Id := Get_Pragma_Arg (Arg2);
25000 Analyze (E_Id);
25001
25002 if not Is_Entity_Name (E_Id) then
25003 Error_Pragma_Arg
25004 ("second argument of pragma% must be entity name",
25005 Arg2);
25006 end if;
25007
25008 E := Entity (E_Id);
25009
25010 if not Ignore_Style_Checks_Pragmas then
25011 if E = Any_Id then
25012 return;
25013 else
25014 loop
25015 Set_Suppress_Style_Checks
25016 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
25017 exit when No (Homonym (E));
25018 E := Homonym (E);
25019 end loop;
25020 end if;
25021 end if;
25022 end;
25023
25024 -- One argument form
25025
25026 else
25027 Check_Arg_Count (1);
25028
25029 if Ignore_Style_Checks_Pragmas then
25030 return;
25031 end if;
25032
25033 if Nkind (A) = N_String_Literal then
25034 S := Strval (A);
25035
25036 declare
25037 Slen : constant Natural := Natural (String_Length (S));
25038 Options : String (1 .. Slen);
25039 J : Positive;
25040
25041 begin
25042 J := 1;
25043 loop
25044 C := Get_String_Char (S, Pos (J));
25045 exit when not In_Character_Range (C);
25046 Options (J) := Get_Character (C);
25047
25048 -- If at end of string, set options. As per discussion
25049 -- above, no need to check for errors, since we issued
25050 -- them in the parser.
25051
25052 if J = Slen then
25053 Set_Style_Check_Options (Options);
25054
25055 exit;
25056 end if;
25057
25058 J := J + 1;
25059 end loop;
25060 end;
25061
25062 elsif Nkind (A) = N_Identifier then
25063 if Chars (A) = Name_All_Checks then
25064 if GNAT_Mode then
25065 Set_GNAT_Style_Check_Options;
25066 else
25067 Set_Default_Style_Check_Options;
25068 end if;
25069
25070 elsif Chars (A) = Name_On then
25071 Style_Check := True;
25072
25073 elsif Chars (A) = Name_Off then
25074 Style_Check := False;
25075 end if;
25076 end if;
25077 end if;
25078 end Style_Checks;
25079
25080 ------------------------
25081 -- Subprogram_Variant --
25082 ------------------------
25083
25084 -- pragma Subprogram_Variant ( SUBPROGRAM_VARIANT_LIST );
25085
25086 -- SUBPROGRAM_VARIANT_LIST ::= STRUCTURAL_SUBPROGRAM_VARIANT_ITEM
25087 -- | NUMERIC_SUBPROGRAM_VARIANT_ITEMS
25088 -- NUMERIC_SUBPROGRAM_VARIANT_ITEMS ::=
25089 -- NUMERIC_SUBPROGRAM_VARIANT_ITEM
25090 -- {, NUMERIC_SUBPROGRAM_VARIANT_ITEM}
25091 -- NUMERIC_SUBPROGRAM_VARIANT_ITEM ::= CHANGE_DIRECTION => EXPRESSION
25092 -- STRUCTURAL_SUBPROGRAM_VARIANT_ITEM ::= Structural => EXPRESSION
25093 -- CHANGE_DIRECTION ::= Increases | Decreases
25094
25095 -- Characteristics:
25096
25097 -- * Analysis - The annotation undergoes initial checks to verify
25098 -- the legal placement and context. Secondary checks preanalyze the
25099 -- expressions in:
25100
25101 -- Analyze_Subprogram_Variant_In_Decl_Part
25102
25103 -- * Expansion - The annotation is expanded during the expansion of
25104 -- the related subprogram [body] contract as performed in:
25105
25106 -- Expand_Subprogram_Contract
25107
25108 -- * Template - The annotation utilizes the generic template of the
25109 -- related subprogram [body] when it is:
25110
25111 -- aspect on subprogram declaration
25112 -- aspect on stand-alone subprogram body
25113 -- pragma on stand-alone subprogram body
25114
25115 -- The annotation must prepare its own template when it is:
25116
25117 -- pragma on subprogram declaration
25118
25119 -- * Globals - Capture of global references must occur after full
25120 -- analysis.
25121
25122 -- * Instance - The annotation is instantiated automatically when
25123 -- the related generic subprogram [body] is instantiated except for
25124 -- the "pragma on subprogram declaration" case. In that scenario
25125 -- the annotation must instantiate itself.
25126
25127 when Pragma_Subprogram_Variant => Subprogram_Variant : declare
25128 Spec_Id : Entity_Id;
25129 Subp_Decl : Node_Id;
25130 Subp_Spec : Node_Id;
25131
25132 begin
25133 GNAT_Pragma;
25134 Check_No_Identifiers;
25135 Check_Arg_Count (1);
25136
25137 -- Ensure the proper placement of the pragma. Subprogram_Variant
25138 -- must be associated with a subprogram declaration or a body that
25139 -- acts as a spec.
25140
25141 Subp_Decl :=
25142 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
25143
25144 -- Generic subprogram
25145
25146 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
25147 null;
25148
25149 -- Body acts as spec
25150
25151 elsif Nkind (Subp_Decl) = N_Subprogram_Body
25152 and then No (Corresponding_Spec (Subp_Decl))
25153 then
25154 null;
25155
25156 -- Body stub acts as spec
25157
25158 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
25159 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
25160 then
25161 null;
25162
25163 -- Subprogram
25164
25165 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
25166 Subp_Spec := Specification (Subp_Decl);
25167
25168 -- Pragma Subprogram_Variant is forbidden on null procedures,
25169 -- as this may lead to potential ambiguities in behavior when
25170 -- interface null procedures are involved. Also, it just
25171 -- wouldn't make sense, because null procedure is not
25172 -- recursive.
25173
25174 if Nkind (Subp_Spec) = N_Procedure_Specification
25175 and then Null_Present (Subp_Spec)
25176 then
25177 Error_Msg_N (Fix_Error
25178 ("pragma % cannot apply to null procedure"), N);
25179 return;
25180 end if;
25181
25182 else
25183 Pragma_Misplaced;
25184 end if;
25185
25186 Spec_Id := Unique_Defining_Entity (Subp_Decl);
25187
25188 -- A pragma that applies to a Ghost entity becomes Ghost for the
25189 -- purposes of legality checks and removal of ignored Ghost code.
25190
25191 Mark_Ghost_Pragma (N, Spec_Id);
25192 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
25193
25194 -- Chain the pragma on the contract for further processing by
25195 -- Analyze_Subprogram_Variant_In_Decl_Part.
25196
25197 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
25198
25199 -- Fully analyze the pragma when it appears inside a subprogram
25200 -- body because it cannot benefit from forward references.
25201
25202 if Nkind (Subp_Decl) in N_Subprogram_Body
25203 | N_Subprogram_Body_Stub
25204 then
25205 -- The legality checks of pragma Subprogram_Variant are
25206 -- affected by the SPARK mode in effect and the volatility
25207 -- of the context. Analyze all pragmas in a specific order.
25208
25209 Analyze_If_Present (Pragma_SPARK_Mode);
25210 Analyze_If_Present (Pragma_Volatile_Function);
25211 Analyze_Subprogram_Variant_In_Decl_Part (N);
25212 end if;
25213 end Subprogram_Variant;
25214
25215 --------------
25216 -- Subtitle --
25217 --------------
25218
25219 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
25220
25221 when Pragma_Subtitle =>
25222 GNAT_Pragma;
25223 Check_Arg_Count (1);
25224 Check_Optional_Identifier (Arg1, Name_Subtitle);
25225 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
25226 Store_Note (N);
25227
25228 --------------
25229 -- Suppress --
25230 --------------
25231
25232 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
25233
25234 when Pragma_Suppress =>
25235 Process_Suppress_Unsuppress (Suppress_Case => True);
25236
25237 ------------------
25238 -- Suppress_All --
25239 ------------------
25240
25241 -- pragma Suppress_All;
25242
25243 -- The only check made here is that the pragma has no arguments.
25244 -- There are no placement rules, and the processing required (setting
25245 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
25246 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
25247 -- then creates and inserts a pragma Suppress (All_Checks).
25248
25249 when Pragma_Suppress_All =>
25250 GNAT_Pragma;
25251 Check_Arg_Count (0);
25252
25253 -------------------------
25254 -- Suppress_Debug_Info --
25255 -------------------------
25256
25257 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
25258
25259 when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare
25260 Nam_Id : Entity_Id;
25261
25262 begin
25263 GNAT_Pragma;
25264 Check_Arg_Count (1);
25265 Check_Optional_Identifier (Arg1, Name_Entity);
25266 Check_Arg_Is_Local_Name (Arg1);
25267
25268 Nam_Id := Entity (Get_Pragma_Arg (Arg1));
25269
25270 -- A pragma that applies to a Ghost entity becomes Ghost for the
25271 -- purposes of legality checks and removal of ignored Ghost code.
25272
25273 Mark_Ghost_Pragma (N, Nam_Id);
25274 Set_Debug_Info_Off (Nam_Id);
25275 end Suppress_Debug_Info;
25276
25277 ----------------------------------
25278 -- Suppress_Exception_Locations --
25279 ----------------------------------
25280
25281 -- pragma Suppress_Exception_Locations;
25282
25283 when Pragma_Suppress_Exception_Locations =>
25284 GNAT_Pragma;
25285 Check_Arg_Count (0);
25286 Check_Valid_Configuration_Pragma;
25287 Exception_Locations_Suppressed := True;
25288
25289 -----------------------------
25290 -- Suppress_Initialization --
25291 -----------------------------
25292
25293 -- pragma Suppress_Initialization ([Entity =>] type_Name);
25294
25295 when Pragma_Suppress_Initialization => Suppress_Init : declare
25296 E : Entity_Id;
25297 E_Id : Node_Id;
25298
25299 begin
25300 GNAT_Pragma;
25301 Check_Arg_Count (1);
25302 Check_Optional_Identifier (Arg1, Name_Entity);
25303 Check_Arg_Is_Local_Name (Arg1);
25304
25305 E_Id := Get_Pragma_Arg (Arg1);
25306
25307 if Etype (E_Id) = Any_Type then
25308 return;
25309 end if;
25310
25311 E := Entity (E_Id);
25312
25313 -- A pragma that applies to a Ghost entity becomes Ghost for the
25314 -- purposes of legality checks and removal of ignored Ghost code.
25315
25316 Mark_Ghost_Pragma (N, E);
25317
25318 if not Is_Type (E) and then Ekind (E) /= E_Variable then
25319 Error_Pragma_Arg
25320 ("pragma% requires variable, type or subtype", Arg1);
25321 end if;
25322
25323 if Rep_Item_Too_Early (E, N)
25324 or else
25325 Rep_Item_Too_Late (E, N, FOnly => True)
25326 then
25327 return;
25328 end if;
25329
25330 -- For incomplete/private type, set flag on full view
25331
25332 if Is_Incomplete_Or_Private_Type (E) then
25333 if No (Full_View (Base_Type (E))) then
25334 Error_Pragma_Arg
25335 ("argument of pragma% cannot be an incomplete type", Arg1);
25336 else
25337 Set_Suppress_Initialization (Full_View (E));
25338 end if;
25339
25340 -- For first subtype, set flag on base type
25341
25342 elsif Is_First_Subtype (E) then
25343 Set_Suppress_Initialization (Base_Type (E));
25344
25345 -- For other than first subtype, set flag on subtype or variable
25346
25347 else
25348 Set_Suppress_Initialization (E);
25349 end if;
25350 end Suppress_Init;
25351
25352 -----------------
25353 -- System_Name --
25354 -----------------
25355
25356 -- pragma System_Name (DIRECT_NAME);
25357
25358 -- Syntax check: one argument, which must be the identifier GNAT or
25359 -- the identifier GCC, no other identifiers are acceptable.
25360
25361 when Pragma_System_Name =>
25362 GNAT_Pragma;
25363 Check_No_Identifiers;
25364 Check_Arg_Count (1);
25365 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
25366
25367 -----------------------------
25368 -- Task_Dispatching_Policy --
25369 -----------------------------
25370
25371 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
25372
25373 when Pragma_Task_Dispatching_Policy => declare
25374 DP : Character;
25375
25376 begin
25377 Check_Ada_83_Warning;
25378 Check_Arg_Count (1);
25379 Check_No_Identifiers;
25380 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
25381 Check_Valid_Configuration_Pragma;
25382 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
25383 DP := Fold_Upper (Name_Buffer (1));
25384
25385 if Task_Dispatching_Policy /= ' '
25386 and then Task_Dispatching_Policy /= DP
25387 then
25388 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
25389 Error_Pragma
25390 ("task dispatching policy incompatible with policy#");
25391
25392 -- Set new policy, but always preserve System_Location since we
25393 -- like the error message with the run time name.
25394
25395 else
25396 Task_Dispatching_Policy := DP;
25397
25398 if Task_Dispatching_Policy_Sloc /= System_Location then
25399 Task_Dispatching_Policy_Sloc := Loc;
25400 end if;
25401 end if;
25402 end;
25403
25404 ---------------
25405 -- Task_Info --
25406 ---------------
25407
25408 -- pragma Task_Info (EXPRESSION);
25409
25410 when Pragma_Task_Info => Task_Info : declare
25411 P : constant Node_Id := Parent (N);
25412 Ent : Entity_Id;
25413
25414 begin
25415 GNAT_Pragma;
25416
25417 if Warn_On_Obsolescent_Feature then
25418 Error_Msg_N
25419 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
25420 & "instead?j?", N);
25421 end if;
25422
25423 if Nkind (P) /= N_Task_Definition then
25424 Error_Pragma ("pragma% must appear in task definition");
25425 end if;
25426
25427 Check_No_Identifiers;
25428 Check_Arg_Count (1);
25429
25430 Analyze_And_Resolve
25431 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
25432
25433 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
25434 return;
25435 end if;
25436
25437 Ent := Defining_Identifier (Parent (P));
25438
25439 -- Check duplicate pragma before we chain the pragma in the Rep
25440 -- Item chain of Ent.
25441
25442 if Has_Rep_Pragma
25443 (Ent, Name_Task_Info, Check_Parents => False)
25444 then
25445 Error_Pragma ("duplicate pragma% not allowed");
25446 end if;
25447
25448 Record_Rep_Item (Ent, N);
25449 end Task_Info;
25450
25451 ---------------
25452 -- Task_Name --
25453 ---------------
25454
25455 -- pragma Task_Name (string_EXPRESSION);
25456
25457 when Pragma_Task_Name => Task_Name : declare
25458 P : constant Node_Id := Parent (N);
25459 Arg : Node_Id;
25460 Ent : Entity_Id;
25461
25462 begin
25463 Check_No_Identifiers;
25464 Check_Arg_Count (1);
25465
25466 Arg := Get_Pragma_Arg (Arg1);
25467
25468 -- The expression is used in the call to Create_Task, and must be
25469 -- expanded there, not in the context of the current spec. It must
25470 -- however be analyzed to capture global references, in case it
25471 -- appears in a generic context.
25472
25473 Preanalyze_And_Resolve (Arg, Standard_String);
25474
25475 if Nkind (P) /= N_Task_Definition then
25476 Pragma_Misplaced;
25477 end if;
25478
25479 Ent := Defining_Identifier (Parent (P));
25480
25481 -- Check duplicate pragma before we chain the pragma in the Rep
25482 -- Item chain of Ent.
25483
25484 if Has_Rep_Pragma
25485 (Ent, Name_Task_Name, Check_Parents => False)
25486 then
25487 Error_Pragma ("duplicate pragma% not allowed");
25488 end if;
25489
25490 Record_Rep_Item (Ent, N);
25491 end Task_Name;
25492
25493 ------------------
25494 -- Task_Storage --
25495 ------------------
25496
25497 -- pragma Task_Storage (
25498 -- [Task_Type =>] LOCAL_NAME,
25499 -- [Top_Guard =>] static_integer_EXPRESSION);
25500
25501 when Pragma_Task_Storage => Task_Storage : declare
25502 Args : Args_List (1 .. 2);
25503 Names : constant Name_List (1 .. 2) := (
25504 Name_Task_Type,
25505 Name_Top_Guard);
25506
25507 Task_Type : Node_Id renames Args (1);
25508 Top_Guard : Node_Id renames Args (2);
25509
25510 Ent : Entity_Id;
25511
25512 begin
25513 GNAT_Pragma;
25514 Gather_Associations (Names, Args);
25515
25516 if No (Task_Type) then
25517 Error_Pragma
25518 ("missing task_type argument for pragma%");
25519 end if;
25520
25521 Check_Arg_Is_Local_Name (Task_Type);
25522
25523 Ent := Entity (Task_Type);
25524
25525 if not Is_Task_Type (Ent) then
25526 Error_Pragma_Arg
25527 ("argument for pragma% must be task type", Task_Type);
25528 end if;
25529
25530 if No (Top_Guard) then
25531 Error_Pragma_Arg
25532 ("pragma% takes two arguments", Task_Type);
25533 else
25534 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
25535 end if;
25536
25537 Check_First_Subtype (Task_Type);
25538
25539 if Rep_Item_Too_Late (Ent, N) then
25540 return;
25541 end if;
25542 end Task_Storage;
25543
25544 ---------------
25545 -- Test_Case --
25546 ---------------
25547
25548 -- pragma Test_Case
25549 -- ([Name =>] Static_String_EXPRESSION
25550 -- ,[Mode =>] MODE_TYPE
25551 -- [, Requires => Boolean_EXPRESSION]
25552 -- [, Ensures => Boolean_EXPRESSION]);
25553
25554 -- MODE_TYPE ::= Nominal | Robustness
25555
25556 -- Characteristics:
25557
25558 -- * Analysis - The annotation undergoes initial checks to verify
25559 -- the legal placement and context. Secondary checks preanalyze the
25560 -- expressions in:
25561
25562 -- Analyze_Test_Case_In_Decl_Part
25563
25564 -- * Expansion - None.
25565
25566 -- * Template - The annotation utilizes the generic template of the
25567 -- related subprogram when it is:
25568
25569 -- aspect on subprogram declaration
25570
25571 -- The annotation must prepare its own template when it is:
25572
25573 -- pragma on subprogram declaration
25574
25575 -- * Globals - Capture of global references must occur after full
25576 -- analysis.
25577
25578 -- * Instance - The annotation is instantiated automatically when
25579 -- the related generic subprogram is instantiated except for the
25580 -- "pragma on subprogram declaration" case. In that scenario the
25581 -- annotation must instantiate itself.
25582
25583 when Pragma_Test_Case => Test_Case : declare
25584 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
25585 -- Ensure that the contract of subprogram Subp_Id does not contain
25586 -- another Test_Case pragma with the same Name as the current one.
25587
25588 -------------------------
25589 -- Check_Distinct_Name --
25590 -------------------------
25591
25592 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
25593 Items : constant Node_Id := Contract (Subp_Id);
25594 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
25595 Prag : Node_Id;
25596
25597 begin
25598 -- Inspect all Test_Case pragma of the related subprogram
25599 -- looking for one with a duplicate "Name" argument.
25600
25601 if Present (Items) then
25602 Prag := Contract_Test_Cases (Items);
25603 while Present (Prag) loop
25604 if Pragma_Name (Prag) = Name_Test_Case
25605 and then Prag /= N
25606 and then String_Equal
25607 (Name, Get_Name_From_CTC_Pragma (Prag))
25608 then
25609 Error_Msg_Sloc := Sloc (Prag);
25610 Error_Pragma ("name for pragma % is already used #");
25611 end if;
25612
25613 Prag := Next_Pragma (Prag);
25614 end loop;
25615 end if;
25616 end Check_Distinct_Name;
25617
25618 -- Local variables
25619
25620 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
25621 Asp_Arg : Node_Id;
25622 Context : Node_Id;
25623 Subp_Decl : Node_Id;
25624 Subp_Id : Entity_Id;
25625
25626 -- Start of processing for Test_Case
25627
25628 begin
25629 GNAT_Pragma;
25630 Check_At_Least_N_Arguments (2);
25631 Check_At_Most_N_Arguments (4);
25632 Check_Arg_Order
25633 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
25634
25635 -- Argument "Name"
25636
25637 Check_Optional_Identifier (Arg1, Name_Name);
25638 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
25639
25640 -- Argument "Mode"
25641
25642 Check_Optional_Identifier (Arg2, Name_Mode);
25643 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
25644
25645 -- Arguments "Requires" and "Ensures"
25646
25647 if Present (Arg3) then
25648 if Present (Arg4) then
25649 Check_Identifier (Arg3, Name_Requires);
25650 Check_Identifier (Arg4, Name_Ensures);
25651 else
25652 Check_Identifier_Is_One_Of
25653 (Arg3, Name_Requires, Name_Ensures);
25654 end if;
25655 end if;
25656
25657 -- Pragma Test_Case must be associated with a subprogram declared
25658 -- in a library-level package. First determine whether the current
25659 -- compilation unit is a legal context.
25660
25661 if Nkind (Pack_Decl) in N_Package_Declaration
25662 | N_Generic_Package_Declaration
25663 then
25664 null;
25665
25666 -- Otherwise the placement is illegal
25667
25668 else
25669 Error_Pragma
25670 ("pragma % must be specified within a package declaration");
25671 end if;
25672
25673 Subp_Decl := Find_Related_Declaration_Or_Body (N);
25674
25675 -- Find the enclosing context
25676
25677 Context := Parent (Subp_Decl);
25678
25679 if Present (Context) then
25680 Context := Parent (Context);
25681 end if;
25682
25683 -- Verify the placement of the pragma
25684
25685 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
25686 Error_Pragma
25687 ("pragma % cannot be applied to abstract subprogram");
25688
25689 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
25690 Error_Pragma ("pragma % cannot be applied to entry");
25691
25692 -- The context is a [generic] subprogram declared at the top level
25693 -- of the [generic] package unit.
25694
25695 elsif Nkind (Subp_Decl) in N_Generic_Subprogram_Declaration
25696 | N_Subprogram_Declaration
25697 and then Present (Context)
25698 and then Nkind (Context) in N_Generic_Package_Declaration
25699 | N_Package_Declaration
25700 then
25701 null;
25702
25703 -- Otherwise the placement is illegal
25704
25705 else
25706 Error_Pragma
25707 ("pragma % must be applied to a library-level subprogram "
25708 & "declaration");
25709 end if;
25710
25711 Subp_Id := Defining_Entity (Subp_Decl);
25712
25713 -- A pragma that applies to a Ghost entity becomes Ghost for the
25714 -- purposes of legality checks and removal of ignored Ghost code.
25715
25716 Mark_Ghost_Pragma (N, Subp_Id);
25717
25718 -- Chain the pragma on the contract for further processing by
25719 -- Analyze_Test_Case_In_Decl_Part.
25720
25721 Add_Contract_Item (N, Subp_Id);
25722
25723 -- Preanalyze the original aspect argument "Name" for a generic
25724 -- subprogram to properly capture global references.
25725
25726 if Is_Generic_Subprogram (Subp_Id) then
25727 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
25728
25729 if Present (Asp_Arg) then
25730
25731 -- The argument appears with an identifier in association
25732 -- form.
25733
25734 if Nkind (Asp_Arg) = N_Component_Association then
25735 Asp_Arg := Expression (Asp_Arg);
25736 end if;
25737
25738 Check_Expr_Is_OK_Static_Expression
25739 (Asp_Arg, Standard_String);
25740 end if;
25741 end if;
25742
25743 -- Ensure that the all Test_Case pragmas of the related subprogram
25744 -- have distinct names.
25745
25746 Check_Distinct_Name (Subp_Id);
25747
25748 -- Fully analyze the pragma when it appears inside an entry
25749 -- or subprogram body because it cannot benefit from forward
25750 -- references.
25751
25752 if Nkind (Subp_Decl) in N_Entry_Body
25753 | N_Subprogram_Body
25754 | N_Subprogram_Body_Stub
25755 then
25756 -- The legality checks of pragma Test_Case are affected by the
25757 -- SPARK mode in effect and the volatility of the context.
25758 -- Analyze all pragmas in a specific order.
25759
25760 Analyze_If_Present (Pragma_SPARK_Mode);
25761 Analyze_If_Present (Pragma_Volatile_Function);
25762 Analyze_Test_Case_In_Decl_Part (N);
25763 end if;
25764 end Test_Case;
25765
25766 --------------------------
25767 -- Thread_Local_Storage --
25768 --------------------------
25769
25770 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
25771
25772 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
25773 E : Entity_Id;
25774 Id : Node_Id;
25775
25776 begin
25777 GNAT_Pragma;
25778 Check_Arg_Count (1);
25779 Check_Optional_Identifier (Arg1, Name_Entity);
25780 Check_Arg_Is_Library_Level_Local_Name (Arg1);
25781
25782 Id := Get_Pragma_Arg (Arg1);
25783
25784 if not Is_Entity_Name (Id)
25785 or else Ekind (Entity (Id)) /= E_Variable
25786 then
25787 Error_Pragma_Arg ("local variable name required", Arg1);
25788 end if;
25789
25790 E := Entity (Id);
25791
25792 -- A pragma that applies to a Ghost entity becomes Ghost for the
25793 -- purposes of legality checks and removal of ignored Ghost code.
25794
25795 Mark_Ghost_Pragma (N, E);
25796
25797 if Rep_Item_Too_Early (E, N)
25798 or else
25799 Rep_Item_Too_Late (E, N)
25800 then
25801 return;
25802 end if;
25803
25804 Set_Has_Pragma_Thread_Local_Storage (E);
25805 Set_Has_Gigi_Rep_Item (E);
25806 end Thread_Local_Storage;
25807
25808 ----------------
25809 -- Time_Slice --
25810 ----------------
25811
25812 -- pragma Time_Slice (static_duration_EXPRESSION);
25813
25814 when Pragma_Time_Slice => Time_Slice : declare
25815 Val : Ureal;
25816 Nod : Node_Id;
25817
25818 begin
25819 GNAT_Pragma;
25820 Check_Arg_Count (1);
25821 Check_No_Identifiers;
25822 Check_In_Main_Program;
25823 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
25824
25825 if not Error_Posted (Arg1) then
25826 Nod := Next (N);
25827 while Present (Nod) loop
25828 if Nkind (Nod) = N_Pragma
25829 and then Pragma_Name (Nod) = Name_Time_Slice
25830 then
25831 Error_Msg_Name_1 := Pname;
25832 Error_Msg_N ("duplicate pragma% not permitted", Nod);
25833 end if;
25834
25835 Next (Nod);
25836 end loop;
25837 end if;
25838
25839 -- Process only if in main unit
25840
25841 if Get_Source_Unit (Loc) = Main_Unit then
25842 Opt.Time_Slice_Set := True;
25843 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
25844
25845 if Val <= Ureal_0 then
25846 Opt.Time_Slice_Value := 0;
25847
25848 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
25849 Opt.Time_Slice_Value := 1_000_000_000;
25850
25851 else
25852 Opt.Time_Slice_Value :=
25853 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
25854 end if;
25855 end if;
25856 end Time_Slice;
25857
25858 -----------
25859 -- Title --
25860 -----------
25861
25862 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
25863
25864 -- TITLING_OPTION ::=
25865 -- [Title =>] STRING_LITERAL
25866 -- | [Subtitle =>] STRING_LITERAL
25867
25868 when Pragma_Title => Title : declare
25869 Args : Args_List (1 .. 2);
25870 Names : constant Name_List (1 .. 2) := (
25871 Name_Title,
25872 Name_Subtitle);
25873
25874 begin
25875 GNAT_Pragma;
25876 Gather_Associations (Names, Args);
25877 Store_Note (N);
25878
25879 for J in 1 .. 2 loop
25880 if Present (Args (J)) then
25881 Check_Arg_Is_OK_Static_Expression
25882 (Args (J), Standard_String);
25883 end if;
25884 end loop;
25885 end Title;
25886
25887 ----------------------------
25888 -- Type_Invariant[_Class] --
25889 ----------------------------
25890
25891 -- pragma Type_Invariant[_Class]
25892 -- ([Entity =>] type_LOCAL_NAME,
25893 -- [Check =>] EXPRESSION);
25894
25895 when Pragma_Type_Invariant
25896 | Pragma_Type_Invariant_Class
25897 =>
25898 Type_Invariant : declare
25899 I_Pragma : Node_Id;
25900
25901 begin
25902 Check_Arg_Count (2);
25903
25904 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
25905 -- setting Class_Present for the Type_Invariant_Class case.
25906
25907 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
25908 I_Pragma := New_Copy (N);
25909 Set_Pragma_Identifier
25910 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
25911 Rewrite (N, I_Pragma);
25912 Set_Analyzed (N, False);
25913 Analyze (N);
25914 end Type_Invariant;
25915
25916 ---------------------
25917 -- Unchecked_Union --
25918 ---------------------
25919
25920 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
25921
25922 when Pragma_Unchecked_Union => Unchecked_Union : declare
25923 Assoc : constant Node_Id := Arg1;
25924 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
25925 Clist : Node_Id;
25926 Comp : Node_Id;
25927 Tdef : Node_Id;
25928 Typ : Entity_Id;
25929 Variant : Node_Id;
25930 Vpart : Node_Id;
25931
25932 begin
25933 Ada_2005_Pragma;
25934 Check_No_Identifiers;
25935 Check_Arg_Count (1);
25936 Check_Arg_Is_Local_Name (Arg1);
25937
25938 Find_Type (Type_Id);
25939
25940 Typ := Entity (Type_Id);
25941
25942 -- A pragma that applies to a Ghost entity becomes Ghost for the
25943 -- purposes of legality checks and removal of ignored Ghost code.
25944
25945 Mark_Ghost_Pragma (N, Typ);
25946
25947 if Typ = Any_Type
25948 or else Rep_Item_Too_Early (Typ, N)
25949 then
25950 return;
25951 else
25952 Typ := Underlying_Type (Typ);
25953 end if;
25954
25955 if Rep_Item_Too_Late (Typ, N) then
25956 return;
25957 end if;
25958
25959 Check_First_Subtype (Arg1);
25960
25961 -- Note remaining cases are references to a type in the current
25962 -- declarative part. If we find an error, we post the error on
25963 -- the relevant type declaration at an appropriate point.
25964
25965 if not Is_Record_Type (Typ) then
25966 Error_Msg_N ("unchecked union must be record type", Typ);
25967 return;
25968
25969 elsif Is_Tagged_Type (Typ) then
25970 Error_Msg_N ("unchecked union must not be tagged", Typ);
25971 return;
25972
25973 elsif not Has_Discriminants (Typ) then
25974 Error_Msg_N
25975 ("unchecked union must have one discriminant", Typ);
25976 return;
25977
25978 -- Note: in previous versions of GNAT we used to check for limited
25979 -- types and give an error, but in fact the standard does allow
25980 -- Unchecked_Union on limited types, so this check was removed.
25981
25982 -- Similarly, GNAT used to require that all discriminants have
25983 -- default values, but this is not mandated by the RM.
25984
25985 -- Proceed with basic error checks completed
25986
25987 else
25988 Tdef := Type_Definition (Declaration_Node (Typ));
25989 Clist := Component_List (Tdef);
25990
25991 -- Check presence of component list and variant part
25992
25993 if No (Clist) or else No (Variant_Part (Clist)) then
25994 Error_Msg_N
25995 ("unchecked union must have variant part", Tdef);
25996 return;
25997 end if;
25998
25999 -- Check components
26000
26001 Comp := First_Non_Pragma (Component_Items (Clist));
26002 while Present (Comp) loop
26003 Check_Component (Comp, Typ);
26004 Next_Non_Pragma (Comp);
26005 end loop;
26006
26007 -- Check variant part
26008
26009 Vpart := Variant_Part (Clist);
26010
26011 Variant := First_Non_Pragma (Variants (Vpart));
26012 while Present (Variant) loop
26013 Check_Variant (Variant, Typ);
26014 Next_Non_Pragma (Variant);
26015 end loop;
26016 end if;
26017
26018 Set_Is_Unchecked_Union (Typ);
26019 Set_Convention (Typ, Convention_C);
26020 Set_Has_Unchecked_Union (Base_Type (Typ));
26021 Set_Is_Unchecked_Union (Base_Type (Typ));
26022 end Unchecked_Union;
26023
26024 ----------------------------
26025 -- Unevaluated_Use_Of_Old --
26026 ----------------------------
26027
26028 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
26029
26030 when Pragma_Unevaluated_Use_Of_Old =>
26031 GNAT_Pragma;
26032 Check_Arg_Count (1);
26033 Check_No_Identifiers;
26034 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
26035
26036 -- Suppress/Unsuppress can appear as a configuration pragma, or in
26037 -- a declarative part or a package spec.
26038
26039 if not Is_Configuration_Pragma then
26040 Check_Is_In_Decl_Part_Or_Package_Spec;
26041 end if;
26042
26043 -- Store proper setting of Uneval_Old
26044
26045 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
26046 Uneval_Old := Fold_Upper (Name_Buffer (1));
26047
26048 ------------------------
26049 -- Unimplemented_Unit --
26050 ------------------------
26051
26052 -- pragma Unimplemented_Unit;
26053
26054 -- Note: this only gives an error if we are generating code, or if
26055 -- we are in a generic library unit (where the pragma appears in the
26056 -- body, not in the spec).
26057
26058 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
26059 Cunitent : constant Entity_Id :=
26060 Cunit_Entity (Get_Source_Unit (Loc));
26061
26062 begin
26063 GNAT_Pragma;
26064 Check_Arg_Count (0);
26065
26066 if Operating_Mode = Generate_Code
26067 or else Is_Generic_Unit (Cunitent)
26068 then
26069 Get_Name_String (Chars (Cunitent));
26070 Set_Casing (Mixed_Case);
26071 Write_Str (Name_Buffer (1 .. Name_Len));
26072 Write_Str (" is not supported in this configuration");
26073 Write_Eol;
26074 raise Unrecoverable_Error;
26075 end if;
26076 end Unimplemented_Unit;
26077
26078 ------------------------
26079 -- Universal_Aliasing --
26080 ------------------------
26081
26082 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
26083
26084 when Pragma_Universal_Aliasing => Universal_Alias : declare
26085 E : Entity_Id;
26086 E_Id : Node_Id;
26087
26088 begin
26089 GNAT_Pragma;
26090 Check_Arg_Count (1);
26091 Check_Optional_Identifier (Arg2, Name_Entity);
26092 Check_Arg_Is_Local_Name (Arg1);
26093 E_Id := Get_Pragma_Arg (Arg1);
26094
26095 if Etype (E_Id) = Any_Type then
26096 return;
26097 end if;
26098
26099 E := Entity (E_Id);
26100
26101 if not Is_Type (E) then
26102 Error_Pragma_Arg ("pragma% requires type", Arg1);
26103 end if;
26104
26105 -- A pragma that applies to a Ghost entity becomes Ghost for the
26106 -- purposes of legality checks and removal of ignored Ghost code.
26107
26108 Mark_Ghost_Pragma (N, E);
26109 Set_Universal_Aliasing (Base_Type (E));
26110 Record_Rep_Item (E, N);
26111 end Universal_Alias;
26112
26113 ----------------
26114 -- Unmodified --
26115 ----------------
26116
26117 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
26118
26119 when Pragma_Unmodified =>
26120 Analyze_Unmodified_Or_Unused;
26121
26122 ------------------
26123 -- Unreferenced --
26124 ------------------
26125
26126 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
26127
26128 -- or when used in a context clause:
26129
26130 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
26131
26132 when Pragma_Unreferenced =>
26133 Analyze_Unreferenced_Or_Unused;
26134
26135 --------------------------
26136 -- Unreferenced_Objects --
26137 --------------------------
26138
26139 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
26140
26141 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
26142 Arg : Node_Id;
26143 Arg_Expr : Node_Id;
26144 Arg_Id : Entity_Id;
26145
26146 Ghost_Error_Posted : Boolean := False;
26147 -- Flag set when an error concerning the illegal mix of Ghost and
26148 -- non-Ghost types is emitted.
26149
26150 Ghost_Id : Entity_Id := Empty;
26151 -- The entity of the first Ghost type encountered while processing
26152 -- the arguments of the pragma.
26153
26154 begin
26155 GNAT_Pragma;
26156 Check_At_Least_N_Arguments (1);
26157
26158 Arg := Arg1;
26159 while Present (Arg) loop
26160 Check_No_Identifier (Arg);
26161 Check_Arg_Is_Local_Name (Arg);
26162 Arg_Expr := Get_Pragma_Arg (Arg);
26163
26164 if Is_Entity_Name (Arg_Expr) then
26165 Arg_Id := Entity (Arg_Expr);
26166
26167 if Is_Type (Arg_Id) then
26168 Set_Has_Pragma_Unreferenced_Objects (Arg_Id);
26169
26170 -- A pragma that applies to a Ghost entity becomes Ghost
26171 -- for the purposes of legality checks and removal of
26172 -- ignored Ghost code.
26173
26174 Mark_Ghost_Pragma (N, Arg_Id);
26175
26176 -- Capture the entity of the first Ghost type being
26177 -- processed for error detection purposes.
26178
26179 if Is_Ghost_Entity (Arg_Id) then
26180 if No (Ghost_Id) then
26181 Ghost_Id := Arg_Id;
26182 end if;
26183
26184 -- Otherwise the type is non-Ghost. It is illegal to mix
26185 -- references to Ghost and non-Ghost entities
26186 -- (SPARK RM 6.9).
26187
26188 elsif Present (Ghost_Id)
26189 and then not Ghost_Error_Posted
26190 then
26191 Ghost_Error_Posted := True;
26192
26193 Error_Msg_Name_1 := Pname;
26194 Error_Msg_N
26195 ("pragma % cannot mention ghost and non-ghost types",
26196 N);
26197
26198 Error_Msg_Sloc := Sloc (Ghost_Id);
26199 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
26200
26201 Error_Msg_Sloc := Sloc (Arg_Id);
26202 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
26203 end if;
26204 else
26205 Error_Pragma_Arg
26206 ("argument for pragma% must be type or subtype", Arg);
26207 end if;
26208 else
26209 Error_Pragma_Arg
26210 ("argument for pragma% must be type or subtype", Arg);
26211 end if;
26212
26213 Next (Arg);
26214 end loop;
26215 end Unreferenced_Objects;
26216
26217 ------------------------------
26218 -- Unreserve_All_Interrupts --
26219 ------------------------------
26220
26221 -- pragma Unreserve_All_Interrupts;
26222
26223 when Pragma_Unreserve_All_Interrupts =>
26224 GNAT_Pragma;
26225 Check_Arg_Count (0);
26226
26227 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
26228 Unreserve_All_Interrupts := True;
26229 end if;
26230
26231 ----------------
26232 -- Unsuppress --
26233 ----------------
26234
26235 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
26236
26237 when Pragma_Unsuppress =>
26238 Ada_2005_Pragma;
26239 Process_Suppress_Unsuppress (Suppress_Case => False);
26240
26241 ------------
26242 -- Unused --
26243 ------------
26244
26245 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
26246
26247 when Pragma_Unused =>
26248 Analyze_Unmodified_Or_Unused (Is_Unused => True);
26249 Analyze_Unreferenced_Or_Unused (Is_Unused => True);
26250
26251 -------------------
26252 -- Use_VADS_Size --
26253 -------------------
26254
26255 -- pragma Use_VADS_Size;
26256
26257 when Pragma_Use_VADS_Size =>
26258 GNAT_Pragma;
26259 Check_Arg_Count (0);
26260 Check_Valid_Configuration_Pragma;
26261 Use_VADS_Size := True;
26262
26263 ----------------------------
26264 -- User_Aspect_Definition --
26265 ----------------------------
26266
26267 -- pragma User_Aspect_Definition
26268 -- (Identifier, {, Identifier [(Identifier {, Identifier})]});
26269
26270 when Pragma_User_Aspect_Definition =>
26271 GNAT_Pragma;
26272 Check_Valid_Configuration_Pragma;
26273 declare
26274 Arg : Node_Id :=
26275 First (Pragma_Argument_Associations (N));
26276 User_Aspect_Name : constant Name_Id := Chars (Expression (Arg));
26277 Expr : Node_Id;
26278 Aspect : Aspect_Id;
26279 begin
26280 if Get_Aspect_Id (User_Aspect_Name) /= No_Aspect then
26281 Error_Pragma_Arg
26282 ("User-defined aspect name for pragma% is the name " &
26283 "of an existing aspect", Arg);
26284 end if;
26285
26286 Next (Arg); -- skip first argument, the name of the aspect
26287
26288 while Present (Arg) loop
26289 Expr := Expression (Arg);
26290 case Nkind (Expr) is
26291 when N_Identifier =>
26292 Aspect := Get_Aspect_Id (Chars (Expr));
26293 if Aspect in Boolean_Aspects
26294 and not Is_Representation_Aspect (Aspect)
26295 then
26296 -- If we allowed representation aspects such as
26297 -- Pack here, then User_Aspect itself would need
26298 -- to be a representation aspect.
26299
26300 null;
26301 elsif Aspect = No_Aspect and then
26302 Present (User_Aspect_Support.Registered_UAD_Pragma
26303 (User_Aspect_Name))
26304 then
26305 null;
26306 else
26307 Error_Pragma_Arg
26308 ("unparameterized argument for pragma% must be " &
26309 "either a Boolean-valued non-representation " &
26310 "aspect or user-defined", Arg);
26311 end if;
26312 when N_Indexed_Component =>
26313 Aspect := Get_Aspect_Id (Chars (Prefix (Expr)));
26314
26315 -- Aspect should be an aspect that takes
26316 -- identifier arguments that do not refer to
26317 -- declarations, but rather to undeclared entities
26318 -- such as GNATProve or No_Secondary_Stack for
26319 -- which the notion of visibility does not apply.
26320
26321 case Aspect is
26322 when Aspect_Annotate =>
26323 if List_Length (Expressions (Expr)) /= 2 then
26324 Error_Pragma_Arg
26325 ("Annotate argument for pragma% takes " &
26326 "two parameters", Arg);
26327 end if;
26328
26329 when Aspect_Local_Restrictions =>
26330 null;
26331
26332 when others =>
26333 Error_Pragma_Arg
26334 ("parameterized argument for pragma% must be " &
26335 "Annotate or Local_Restrictions aspect", Arg);
26336 end case;
26337 when others =>
26338 raise Program_Error; -- parsing error
26339 end case;
26340 Next (Arg);
26341 end loop;
26342
26343 declare
26344 Registered : constant Node_Id :=
26345 User_Aspect_Support.Registered_UAD_Pragma
26346 (User_Aspect_Name);
26347
26348 -- Given two User_Aspect_Definition pragmas with
26349 -- matching names for the first argument, check that
26350 -- subsequent arguments also match; complain if they differ.
26351 procedure Check_UAD_Conformance
26352 (New_Pragma, Old_Pragma : Node_Id);
26353
26354 ---------------------------
26355 -- Check_UAD_Conformance --
26356 ---------------------------
26357
26358 procedure Check_UAD_Conformance
26359 (New_Pragma, Old_Pragma : Node_Id)
26360 is
26361 Old_Arg : Node_Id :=
26362 First (Pragma_Argument_Associations (Old_Pragma));
26363 New_Arg : Node_Id :=
26364 First (Pragma_Argument_Associations (New_Pragma));
26365 OK : Boolean := True;
26366
26367 function Same_Chars (Id1, Id2 : Node_Id) return Boolean
26368 is (Chars (Id1) = Chars (Id2));
26369
26370 function Same_Identifier_List (Id1, Id2 : Node_Id)
26371 return Boolean
26372 is (if No (Id1) and No (Id2) then True
26373 elsif No (Id1) or No (Id2) then False
26374 else (Same_Chars (Id1, Id2) and then
26375 Same_Identifier_List (Next (Id1), Next (Id2))));
26376 begin
26377 -- We could skip the first argument pair since those
26378 -- are already known to match (or we wouldn't be
26379 -- calling this procedure).
26380
26381 while Present (Old_Arg) or Present (New_Arg) loop
26382 if Present (Old_Arg) /= Present (New_Arg) then
26383 OK := False;
26384 elsif Nkind (Expression (Old_Arg)) /=
26385 Nkind (Expression (New_Arg))
26386 then
26387 OK := False;
26388 else
26389 case Nkind (Expression (Old_Arg)) is
26390 when N_Identifier =>
26391 OK := Same_Chars (Expression (Old_Arg),
26392 Expression (New_Arg));
26393
26394 when N_Indexed_Component =>
26395 OK := Same_Chars
26396 (Prefix (Expression (Old_Arg)),
26397 Prefix (Expression (New_Arg)))
26398 and then Same_Identifier_List
26399 (First (Expressions
26400 (Expression (Old_Arg))),
26401 First (Expressions
26402 (Expression (New_Arg))));
26403
26404 when others =>
26405 OK := False;
26406 pragma Assert (False);
26407 end case;
26408 end if;
26409
26410 if not OK then
26411 Error_Msg_Sloc := Sloc (Old_Pragma);
26412 Error_Msg_N
26413 ("Nonconforming definitions for user-defined " &
26414 "aspect #", New_Pragma);
26415 return;
26416 end if;
26417
26418 Next (Old_Arg);
26419 Next (New_Arg);
26420 end loop;
26421 end Check_UAD_Conformance;
26422 begin
26423 if Present (Registered) then
26424 -- If we have already seen a UAD pragma with this name,
26425 -- then check that the two pragmas conform (which means
26426 -- that the new pragma is redundant and can be ignored).
26427
26428 -- ??? We could also perform a similar bind-time check,
26429 -- since it is possible that an incompatible pair of
26430 -- UAD pragmas might not be detected by this check.
26431 -- This could arise if no unit's compilation closure
26432 -- includes both of the two. The major downside of
26433 -- failing to detect this case is possible confusion
26434 -- for human readers.
26435
26436 Check_UAD_Conformance (New_Pragma => N,
26437 Old_Pragma => Registered);
26438 else
26439 User_Aspect_Support.Register_UAD_Pragma (N);
26440 end if;
26441 end;
26442 end;
26443
26444 ---------------------
26445 -- Validity_Checks --
26446 ---------------------
26447
26448 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
26449
26450 when Pragma_Validity_Checks => Validity_Checks : declare
26451 A : constant Node_Id := Get_Pragma_Arg (Arg1);
26452 S : String_Id;
26453 C : Char_Code;
26454
26455 begin
26456 GNAT_Pragma;
26457 Check_Arg_Count (1);
26458 Check_No_Identifiers;
26459
26460 -- Pragma always active unless in CodePeer or GNATprove modes,
26461 -- which use a fixed configuration of validity checks.
26462
26463 if not (CodePeer_Mode or GNATprove_Mode) then
26464 if Nkind (A) = N_String_Literal then
26465 S := Strval (A);
26466
26467 declare
26468 Slen : constant Natural := Natural (String_Length (S));
26469 Options : String (1 .. Slen);
26470 J : Positive;
26471
26472 begin
26473 -- Couldn't we use a for loop here over Options'Range???
26474
26475 J := 1;
26476 loop
26477 C := Get_String_Char (S, Pos (J));
26478
26479 -- This is a weird test, it skips setting validity
26480 -- checks entirely if any element of S is out of
26481 -- range of Character, what is that about ???
26482
26483 exit when not In_Character_Range (C);
26484 Options (J) := Get_Character (C);
26485
26486 if J = Slen then
26487 Set_Validity_Check_Options (Options);
26488 exit;
26489 else
26490 J := J + 1;
26491 end if;
26492 end loop;
26493 end;
26494
26495 elsif Nkind (A) = N_Identifier then
26496 if Chars (A) = Name_All_Checks then
26497 Set_Validity_Check_Options ("a");
26498 elsif Chars (A) = Name_On then
26499 Validity_Checks_On := True;
26500 elsif Chars (A) = Name_Off then
26501 Validity_Checks_On := False;
26502 end if;
26503 end if;
26504 end if;
26505 end Validity_Checks;
26506
26507 --------------
26508 -- Volatile --
26509 --------------
26510
26511 -- pragma Volatile (LOCAL_NAME);
26512
26513 when Pragma_Volatile =>
26514 Process_Atomic_Independent_Shared_Volatile;
26515
26516 -------------------------
26517 -- Volatile_Components --
26518 -------------------------
26519
26520 -- pragma Volatile_Components (array_LOCAL_NAME);
26521
26522 -- Volatile is handled by the same circuit as Atomic_Components
26523
26524 --------------------------
26525 -- Volatile_Full_Access --
26526 --------------------------
26527
26528 -- pragma Volatile_Full_Access (LOCAL_NAME);
26529
26530 when Pragma_Volatile_Full_Access =>
26531 GNAT_Pragma;
26532 Process_Atomic_Independent_Shared_Volatile;
26533
26534 -----------------------
26535 -- Volatile_Function --
26536 -----------------------
26537
26538 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
26539
26540 when Pragma_Volatile_Function => Volatile_Function : declare
26541 Over_Id : Entity_Id;
26542 Spec_Id : Entity_Id;
26543 Subp_Decl : Node_Id;
26544
26545 begin
26546 GNAT_Pragma;
26547 Check_No_Identifiers;
26548 Check_At_Most_N_Arguments (1);
26549
26550 Subp_Decl :=
26551 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
26552
26553 -- Generic subprogram
26554
26555 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
26556 null;
26557
26558 -- Body acts as spec
26559
26560 elsif Nkind (Subp_Decl) = N_Subprogram_Body
26561 and then No (Corresponding_Spec (Subp_Decl))
26562 then
26563 null;
26564
26565 -- Body stub acts as spec
26566
26567 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
26568 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
26569 then
26570 null;
26571
26572 -- Subprogram
26573
26574 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
26575 null;
26576
26577 else
26578 Pragma_Misplaced;
26579 end if;
26580
26581 Spec_Id := Unique_Defining_Entity (Subp_Decl);
26582
26583 if Ekind (Spec_Id) not in E_Function | E_Generic_Function then
26584 Pragma_Misplaced;
26585 end if;
26586
26587 -- A pragma that applies to a Ghost entity becomes Ghost for the
26588 -- purposes of legality checks and removal of ignored Ghost code.
26589
26590 Mark_Ghost_Pragma (N, Spec_Id);
26591
26592 -- Chain the pragma on the contract for completeness
26593
26594 Add_Contract_Item (N, Spec_Id);
26595
26596 -- The legality checks of pragma Volatile_Function are affected by
26597 -- the SPARK mode in effect. Analyze all pragmas in a specific
26598 -- order.
26599
26600 Analyze_If_Present (Pragma_SPARK_Mode);
26601
26602 -- A volatile function cannot override a non-volatile function
26603 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
26604 -- in New_Overloaded_Entity, however at that point the pragma has
26605 -- not been processed yet.
26606
26607 Over_Id := Overridden_Operation (Spec_Id);
26608
26609 if Present (Over_Id)
26610 and then not Is_Volatile_Function (Over_Id)
26611 then
26612 Error_Msg_N
26613 ("incompatible volatile function values in effect", Spec_Id);
26614
26615 Error_Msg_Sloc := Sloc (Over_Id);
26616 Error_Msg_N
26617 ("\& declared # with Volatile_Function value False",
26618 Spec_Id);
26619
26620 Error_Msg_Sloc := Sloc (Spec_Id);
26621 Error_Msg_N
26622 ("\overridden # with Volatile_Function value True",
26623 Spec_Id);
26624 end if;
26625
26626 -- Analyze the Boolean expression (if any)
26627
26628 if Present (Arg1) then
26629 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
26630 end if;
26631 end Volatile_Function;
26632
26633 ----------------------
26634 -- Warning_As_Error --
26635 ----------------------
26636
26637 -- pragma Warning_As_Error (static_string_EXPRESSION);
26638
26639 when Pragma_Warning_As_Error =>
26640 GNAT_Pragma;
26641 Check_Arg_Count (1);
26642 Check_No_Identifiers;
26643 Check_Valid_Configuration_Pragma;
26644
26645 if not Is_Static_String_Expression (Arg1) then
26646 Error_Pragma_Arg
26647 ("argument of pragma% must be static string expression",
26648 Arg1);
26649
26650 -- OK static string expression
26651
26652 else
26653 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
26654 Warnings_As_Errors (Warnings_As_Errors_Count) :=
26655 new String'(Acquire_Warning_Match_String
26656 (Expr_Value_S (Get_Pragma_Arg (Arg1))));
26657 end if;
26658
26659 --------------
26660 -- Warnings --
26661 --------------
26662
26663 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
26664
26665 -- DETAILS ::= On | Off
26666 -- DETAILS ::= On | Off, local_NAME
26667 -- DETAILS ::= static_string_EXPRESSION
26668 -- DETAILS ::= On | Off, static_string_EXPRESSION
26669
26670 -- TOOL_NAME ::= GNAT | GNATprove
26671
26672 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
26673
26674 -- Note: If the first argument matches an allowed tool name, it is
26675 -- always considered to be a tool name, even if there is a string
26676 -- variable of that name.
26677
26678 -- Note if the second argument of DETAILS is a local_NAME then the
26679 -- second form is always understood. If the intention is to use
26680 -- the fourth form, then you can write NAME & "" to force the
26681 -- intepretation as a static_string_EXPRESSION.
26682
26683 when Pragma_Warnings => Warnings : declare
26684 Reason : String_Id;
26685
26686 begin
26687 GNAT_Pragma;
26688 Check_At_Least_N_Arguments (1);
26689
26690 -- See if last argument is labeled Reason. If so, make sure we
26691 -- have a string literal or a concatenation of string literals,
26692 -- and acquire the REASON string. Then remove the REASON argument
26693 -- by decreasing Num_Args by one; Remaining processing looks only
26694 -- at first Num_Args arguments).
26695
26696 declare
26697 Last_Arg : constant Node_Id :=
26698 Last (Pragma_Argument_Associations (N));
26699
26700 begin
26701 if Nkind (Last_Arg) = N_Pragma_Argument_Association
26702 and then Chars (Last_Arg) = Name_Reason
26703 then
26704 Start_String;
26705 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
26706 Reason := End_String;
26707 Arg_Count := Arg_Count - 1;
26708
26709 -- No REASON string, set null string as reason
26710
26711 else
26712 Reason := Null_String_Id;
26713 end if;
26714 end;
26715
26716 -- Now proceed with REASON taken care of and eliminated
26717
26718 Check_No_Identifiers;
26719
26720 -- If debug flag -gnatd.i is set, pragma is ignored
26721
26722 if Debug_Flag_Dot_I then
26723 return;
26724 end if;
26725
26726 -- Process various forms of the pragma
26727
26728 declare
26729 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
26730 Shifted_Args : List_Id;
26731
26732 begin
26733 -- See if first argument is a tool name, currently either
26734 -- GNAT or GNATprove. If so, either ignore the pragma if the
26735 -- tool used does not match, or continue as if no tool name
26736 -- was given otherwise, by shifting the arguments.
26737
26738 if Nkind (Argx) = N_Identifier
26739 and then Chars (Argx) in Name_Gnat | Name_Gnatprove
26740 then
26741 if Chars (Argx) = Name_Gnat then
26742 if CodePeer_Mode or GNATprove_Mode then
26743 Rewrite (N, Make_Null_Statement (Loc));
26744 Analyze (N);
26745 return;
26746 end if;
26747
26748 elsif Chars (Argx) = Name_Gnatprove then
26749 if not GNATprove_Mode then
26750 Rewrite (N, Make_Null_Statement (Loc));
26751 Analyze (N);
26752 return;
26753 end if;
26754 else
26755 raise Program_Error;
26756 end if;
26757
26758 -- At this point, the pragma Warnings applies to the tool,
26759 -- so continue with shifted arguments.
26760
26761 Arg_Count := Arg_Count - 1;
26762
26763 if Arg_Count = 1 then
26764 Shifted_Args := New_List (New_Copy (Arg2));
26765 elsif Arg_Count = 2 then
26766 Shifted_Args := New_List (New_Copy (Arg2),
26767 New_Copy (Arg3));
26768 elsif Arg_Count = 3 then
26769 Shifted_Args := New_List (New_Copy (Arg2),
26770 New_Copy (Arg3),
26771 New_Copy (Arg4));
26772 else
26773 raise Program_Error;
26774 end if;
26775
26776 Rewrite (N,
26777 Make_Pragma (Loc,
26778 Chars => Name_Warnings,
26779 Pragma_Argument_Associations => Shifted_Args));
26780 Analyze (N);
26781 return;
26782 end if;
26783
26784 -- One argument case
26785
26786 if Arg_Count = 1 then
26787
26788 -- On/Off one argument case was processed by parser
26789
26790 if Nkind (Argx) = N_Identifier
26791 and then Chars (Argx) in Name_On | Name_Off
26792 then
26793 null;
26794
26795 -- One argument case must be ON/OFF or static string expr
26796
26797 elsif not Is_Static_String_Expression (Arg1) then
26798 Error_Pragma_Arg
26799 ("argument of pragma% must be On/Off or static string "
26800 & "expression", Arg1);
26801
26802 -- Use of pragma Warnings to set warning switches is
26803 -- ignored in GNATprove mode, as these switches apply to
26804 -- the compiler only.
26805
26806 elsif GNATprove_Mode then
26807 null;
26808
26809 -- One argument string expression case
26810
26811 else
26812 declare
26813 Lit : constant Node_Id := Expr_Value_S (Argx);
26814 Str : constant String_Id := Strval (Lit);
26815 Len : constant Nat := String_Length (Str);
26816 C : Char_Code;
26817 J : Nat;
26818 OK : Boolean;
26819 Chr : Character;
26820
26821 begin
26822 J := 1;
26823 while J <= Len loop
26824 C := Get_String_Char (Str, J);
26825 OK := In_Character_Range (C);
26826
26827 if OK then
26828 Chr := Get_Character (C);
26829
26830 -- Dash case: only -Wxxx is accepted
26831
26832 if J = 1
26833 and then J < Len
26834 and then Chr = '-'
26835 then
26836 J := J + 1;
26837 C := Get_String_Char (Str, J);
26838 Chr := Get_Character (C);
26839 exit when Chr = 'W';
26840 OK := False;
26841
26842 -- Dot case
26843
26844 elsif J < Len and then Chr = '.' then
26845 J := J + 1;
26846 C := Get_String_Char (Str, J);
26847 Chr := Get_Character (C);
26848
26849 if not Set_Warning_Switch ('.', Chr) then
26850 Error_Pragma_Arg
26851 ("invalid warning switch character "
26852 & '.' & Chr, Arg1);
26853 end if;
26854
26855 -- Non-Dot case
26856
26857 else
26858 OK := Set_Warning_Switch (Plain, Chr);
26859 end if;
26860
26861 if not OK then
26862 Error_Pragma_Arg
26863 ("invalid warning switch character " & Chr,
26864 Arg1);
26865 end if;
26866
26867 else
26868 Error_Pragma_Arg
26869 ("invalid wide character in warning switch ",
26870 Arg1);
26871 end if;
26872
26873 J := J + 1;
26874 end loop;
26875 end;
26876 end if;
26877
26878 -- Two or more arguments (must be two)
26879
26880 else
26881 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
26882 Check_Arg_Count (2);
26883
26884 declare
26885 E_Id : Node_Id;
26886 E : Entity_Id;
26887 Err : Boolean;
26888
26889 begin
26890 E_Id := Get_Pragma_Arg (Arg2);
26891 Analyze (E_Id);
26892
26893 -- In the expansion of an inlined body, a reference to
26894 -- the formal may be wrapped in a conversion if the
26895 -- actual is a conversion. Retrieve the real entity name.
26896
26897 if (In_Instance_Body or In_Inlined_Body)
26898 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
26899 then
26900 E_Id := Expression (E_Id);
26901 end if;
26902
26903 -- Entity name case
26904
26905 if Is_Entity_Name (E_Id) then
26906 E := Entity (E_Id);
26907
26908 if E = Any_Id then
26909 return;
26910 else
26911 loop
26912 Set_Warnings_Off
26913 (E, (Chars (Get_Pragma_Arg (Arg1)) =
26914 Name_Off));
26915
26916 -- Suppress elaboration warnings if the entity
26917 -- denotes an elaboration target.
26918
26919 if Is_Elaboration_Target (E) then
26920 Set_Is_Elaboration_Warnings_OK_Id (E, False);
26921 end if;
26922
26923 -- For OFF case, make entry in warnings off
26924 -- pragma table for later processing. But we do
26925 -- not do that within an instance, since these
26926 -- warnings are about what is needed in the
26927 -- template, not an instance of it.
26928
26929 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
26930 and then Warn_On_Warnings_Off
26931 and then not In_Instance
26932 then
26933 Warnings_Off_Pragmas.Append ((N, E, Reason));
26934 end if;
26935
26936 if Is_Enumeration_Type (E) then
26937 declare
26938 Lit : Entity_Id;
26939 begin
26940 Lit := First_Literal (E);
26941 while Present (Lit) loop
26942 Set_Warnings_Off (Lit);
26943 Next_Literal (Lit);
26944 end loop;
26945 end;
26946 end if;
26947
26948 exit when No (Homonym (E));
26949 E := Homonym (E);
26950 end loop;
26951 end if;
26952
26953 -- Error if not entity or static string expression case
26954
26955 elsif not Is_Static_String_Expression (Arg2) then
26956 Error_Pragma_Arg
26957 ("second argument of pragma% must be entity name "
26958 & "or static string expression", Arg2);
26959
26960 -- Static string expression case
26961
26962 else
26963 -- Note on configuration pragma case: If this is a
26964 -- configuration pragma, then for an OFF pragma, we
26965 -- just set Config True in the call, which is all
26966 -- that needs to be done. For the case of ON, this
26967 -- is normally an error, unless it is canceling the
26968 -- effect of a previous OFF pragma in the same file.
26969 -- In any other case, an error will be signalled (ON
26970 -- with no matching OFF).
26971
26972 -- Note: We set Used if we are inside a generic to
26973 -- disable the test that the non-config case actually
26974 -- cancels a warning. That's because we can't be sure
26975 -- there isn't an instantiation in some other unit
26976 -- where a warning is suppressed.
26977
26978 -- We could do a little better here by checking if the
26979 -- generic unit we are inside is public, but for now
26980 -- we don't bother with that refinement.
26981
26982 declare
26983 Message : constant String :=
26984 Acquire_Warning_Match_String
26985 (Expr_Value_S (Get_Pragma_Arg (Arg2)));
26986 begin
26987 if Chars (Argx) = Name_Off then
26988 Set_Specific_Warning_Off
26989 (Loc, Message, Reason,
26990 Config => Is_Configuration_Pragma,
26991 Used => Inside_A_Generic or else In_Instance);
26992
26993 elsif Chars (Argx) = Name_On then
26994 Set_Specific_Warning_On (Loc, Message, Err);
26995
26996 if Err then
26997 Error_Msg_N
26998 ("??pragma Warnings On with no matching "
26999 & "Warnings Off", N);
27000 end if;
27001 end if;
27002 end;
27003 end if;
27004 end;
27005 end if;
27006 end;
27007 end Warnings;
27008
27009 -------------------
27010 -- Weak_External --
27011 -------------------
27012
27013 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
27014
27015 when Pragma_Weak_External => Weak_External : declare
27016 Ent : Entity_Id;
27017
27018 begin
27019 GNAT_Pragma;
27020 Check_Arg_Count (1);
27021 Check_Optional_Identifier (Arg1, Name_Entity);
27022 Check_Arg_Is_Library_Level_Local_Name (Arg1);
27023 Ent := Entity (Get_Pragma_Arg (Arg1));
27024
27025 if Rep_Item_Too_Early (Ent, N) then
27026 return;
27027 else
27028 Ent := Underlying_Type (Ent);
27029 end if;
27030
27031 -- The pragma applies to entities with addresses
27032
27033 if Is_Type (Ent) then
27034 Error_Pragma ("pragma applies to objects and subprograms");
27035 end if;
27036
27037 -- The only processing required is to link this item on to the
27038 -- list of rep items for the given entity. This is accomplished
27039 -- by the call to Rep_Item_Too_Late (when no error is detected
27040 -- and False is returned).
27041
27042 if Rep_Item_Too_Late (Ent, N) then
27043 return;
27044 else
27045 Set_Has_Gigi_Rep_Item (Ent);
27046 end if;
27047 end Weak_External;
27048
27049 -----------------------------
27050 -- Wide_Character_Encoding --
27051 -----------------------------
27052
27053 -- pragma Wide_Character_Encoding (IDENTIFIER);
27054
27055 when Pragma_Wide_Character_Encoding =>
27056 GNAT_Pragma;
27057
27058 -- Nothing to do, handled in parser. Note that we do not enforce
27059 -- configuration pragma placement, this pragma can appear at any
27060 -- place in the source, allowing mixed encodings within a single
27061 -- source program.
27062
27063 null;
27064
27065 --------------------
27066 -- Unknown_Pragma --
27067 --------------------
27068
27069 -- Should be impossible, since the case of an unknown pragma is
27070 -- separately processed before the case statement is entered.
27071
27072 when Unknown_Pragma =>
27073 raise Program_Error;
27074 end case;
27075
27076 -- AI05-0144: detect dangerous order dependence. Disabled for now,
27077 -- until AI is formally approved.
27078
27079 -- Check_Order_Dependence;
27080
27081 exception
27082 when Pragma_Exit => null;
27083 end Analyze_Pragma;
27084
27085 --------------------------------
27086 -- Analyze_Pragmas_If_Present --
27087 --------------------------------
27088
27089 procedure Analyze_Pragmas_If_Present (Decl : Node_Id; Id : Pragma_Id) is
27090 Prag : Node_Id;
27091 begin
27092 if Nkind (Parent (Decl)) = N_Compilation_Unit then
27093 Prag := First (Pragmas_After (Aux_Decls_Node (Parent (Decl))));
27094 else
27095 pragma Assert (Is_List_Member (Decl));
27096 Prag := Next (Decl);
27097 end if;
27098
27099 if Present (Prag) then
27100 Analyze_If_Present_Internal (Prag, Id, Included => True);
27101 end if;
27102 end Analyze_Pragmas_If_Present;
27103
27104 ---------------------------------------------
27105 -- Analyze_Pre_Post_Condition_In_Decl_Part --
27106 ---------------------------------------------
27107
27108 -- WARNING: This routine manages Ghost regions. Return statements must be
27109 -- replaced by gotos which jump to the end of the routine and restore the
27110 -- Ghost mode.
27111
27112 procedure Analyze_Pre_Post_Condition_In_Decl_Part
27113 (N : Node_Id;
27114 Freeze_Id : Entity_Id := Empty)
27115 is
27116 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
27117 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
27118
27119 Disp_Typ : Entity_Id;
27120 -- The dispatching type of the subprogram subject to the pre- or
27121 -- postcondition.
27122
27123 function Check_References (Nod : Node_Id) return Traverse_Result;
27124 -- Check that expression Nod does not mention non-primitives of the
27125 -- type, global objects of the type, or other illegalities described
27126 -- and implied by AI12-0113.
27127
27128 ----------------------
27129 -- Check_References --
27130 ----------------------
27131
27132 function Check_References (Nod : Node_Id) return Traverse_Result is
27133 begin
27134 if Nkind (Nod) = N_Function_Call
27135 and then Is_Entity_Name (Name (Nod))
27136 then
27137 declare
27138 Func : constant Entity_Id := Entity (Name (Nod));
27139 Form : Entity_Id;
27140
27141 begin
27142 -- An operation of the type must be a primitive
27143
27144 if No (Find_Dispatching_Type (Func)) then
27145 Form := First_Formal (Func);
27146 while Present (Form) loop
27147 if Etype (Form) = Disp_Typ then
27148 Error_Msg_NE
27149 ("operation in class-wide condition must be "
27150 & "primitive of &", Nod, Disp_Typ);
27151 end if;
27152
27153 Next_Formal (Form);
27154 end loop;
27155
27156 -- A return object of the type is illegal as well
27157
27158 if Etype (Func) = Disp_Typ
27159 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
27160 then
27161 Error_Msg_NE
27162 ("operation in class-wide condition must be primitive "
27163 & "of &", Nod, Disp_Typ);
27164 end if;
27165 end if;
27166 end;
27167
27168 elsif Is_Entity_Name (Nod)
27169 and then
27170 (Etype (Nod) = Disp_Typ
27171 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
27172 and then Ekind (Entity (Nod)) in E_Constant | E_Variable
27173 then
27174 Error_Msg_NE
27175 ("object in class-wide condition must be formal of type &",
27176 Nod, Disp_Typ);
27177
27178 elsif Nkind (Nod) = N_Explicit_Dereference
27179 and then (Etype (Nod) = Disp_Typ
27180 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
27181 and then (not Is_Entity_Name (Prefix (Nod))
27182 or else not Is_Formal (Entity (Prefix (Nod))))
27183 then
27184 Error_Msg_NE
27185 ("operation in class-wide condition must be primitive of &",
27186 Nod, Disp_Typ);
27187 end if;
27188
27189 return OK;
27190 end Check_References;
27191
27192 procedure Check_Class_Wide_Condition is
27193 new Traverse_Proc (Check_References);
27194
27195 -- Local variables
27196
27197 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
27198
27199 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
27200 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
27201 -- Save the Ghost-related attributes to restore on exit
27202
27203 Errors : Nat;
27204 Restore_Scope : Boolean := False;
27205
27206 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
27207
27208 begin
27209 -- Do not analyze the pragma multiple times
27210
27211 if Is_Analyzed_Pragma (N) then
27212 return;
27213 end if;
27214
27215 -- Set the Ghost mode in effect from the pragma. Due to the delayed
27216 -- analysis of the pragma, the Ghost mode at point of declaration and
27217 -- point of analysis may not necessarily be the same. Use the mode in
27218 -- effect at the point of declaration.
27219
27220 Set_Ghost_Mode (N);
27221
27222 -- Ensure that the subprogram and its formals are visible when analyzing
27223 -- the expression of the pragma.
27224
27225 if not In_Open_Scopes (Spec_Id) then
27226 Restore_Scope := True;
27227
27228 if Is_Generic_Subprogram (Spec_Id) then
27229 Push_Scope (Spec_Id);
27230 Install_Generic_Formals (Spec_Id);
27231 elsif Is_Access_Subprogram_Type (Spec_Id) then
27232 Push_Scope (Designated_Type (Spec_Id));
27233 Install_Formals (Designated_Type (Spec_Id));
27234 else
27235 Push_Scope (Spec_Id);
27236 Install_Formals (Spec_Id);
27237 end if;
27238 end if;
27239
27240 Errors := Serious_Errors_Detected;
27241 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
27242
27243 -- Emit a clarification message when the expression contains at least
27244 -- one undefined reference, possibly due to contract freezing.
27245
27246 if Errors /= Serious_Errors_Detected
27247 and then Present (Freeze_Id)
27248 and then Has_Undefined_Reference (Expr)
27249 then
27250 Contract_Freeze_Error (Spec_Id, Freeze_Id);
27251 end if;
27252
27253 if Class_Present (N) then
27254
27255 -- Verify that a class-wide condition is legal, i.e. the operation is
27256 -- a primitive of a tagged type.
27257
27258 if not Is_Dispatching_Operation (Spec_Id) then
27259 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
27260
27261 if From_Aspect_Specification (N) then
27262 Error_Msg_N
27263 ("aspect % can only be specified for a primitive operation "
27264 & "of a tagged type", Corresponding_Aspect (N));
27265
27266 -- The pragma is a source construct
27267
27268 else
27269 Error_Msg_N
27270 ("pragma % can only be specified for a primitive operation "
27271 & "of a tagged type", N);
27272 end if;
27273
27274 -- Remaining semantic checks require a full tree traversal
27275
27276 else
27277 Disp_Typ := Find_Dispatching_Type (Spec_Id);
27278 Check_Class_Wide_Condition (Expr);
27279 end if;
27280
27281 end if;
27282
27283 if Restore_Scope then
27284 End_Scope;
27285 end if;
27286
27287 -- Currently it is not possible to inline pre/postconditions on a
27288 -- subprogram subject to pragma Inline_Always.
27289
27290 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
27291 Set_Is_Analyzed_Pragma (N);
27292
27293 Restore_Ghost_Region (Saved_GM, Saved_IGR);
27294 end Analyze_Pre_Post_Condition_In_Decl_Part;
27295
27296 ------------------------------------------
27297 -- Analyze_Refined_Depends_In_Decl_Part --
27298 ------------------------------------------
27299
27300 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
27301 procedure Check_Dependency_Clause
27302 (Spec_Id : Entity_Id;
27303 Dep_Clause : Node_Id;
27304 Dep_States : Elist_Id;
27305 Refinements : List_Id;
27306 Matched_Items : in out Elist_Id);
27307 -- Try to match a single dependency clause Dep_Clause against one or
27308 -- more refinement clauses found in list Refinements. Each successful
27309 -- match eliminates at least one refinement clause from Refinements.
27310 -- Spec_Id denotes the entity of the related subprogram. Dep_States
27311 -- denotes the entities of all abstract states which appear in pragma
27312 -- Depends. Matched_Items contains the entities of all successfully
27313 -- matched items found in pragma Depends.
27314
27315 procedure Check_Output_States
27316 (Spec_Inputs : Elist_Id;
27317 Spec_Outputs : Elist_Id;
27318 Body_Inputs : Elist_Id;
27319 Body_Outputs : Elist_Id);
27320 -- Determine whether pragma Depends contains an output state with a
27321 -- visible refinement and if so, ensure that pragma Refined_Depends
27322 -- mentions all its constituents as outputs. Spec_Inputs and
27323 -- Spec_Outputs denote the inputs and outputs of the subprogram spec
27324 -- synthesized from pragma Depends. Body_Inputs and Body_Outputs denote
27325 -- the inputs and outputs of the subprogram body synthesized from pragma
27326 -- Refined_Depends.
27327
27328 function Collect_States (Clauses : List_Id) return Elist_Id;
27329 -- Given a normalized list of dependencies obtained from calling
27330 -- Normalize_Clauses, return a list containing the entities of all
27331 -- states appearing in dependencies. It helps in checking refinements
27332 -- involving a state and a corresponding constituent which is not a
27333 -- direct constituent of the state.
27334
27335 procedure Normalize_Clauses (Clauses : List_Id);
27336 -- Given a list of dependence or refinement clauses Clauses, normalize
27337 -- each clause by creating multiple dependencies with exactly one input
27338 -- and one output.
27339
27340 procedure Remove_Extra_Clauses
27341 (Clauses : List_Id;
27342 Matched_Items : Elist_Id);
27343 -- Given a list of refinement clauses Clauses, remove all clauses whose
27344 -- inputs and/or outputs have been previously matched. See the body for
27345 -- all special cases. Matched_Items contains the entities of all matched
27346 -- items found in pragma Depends.
27347
27348 procedure Report_Extra_Clauses (Clauses : List_Id);
27349 -- Emit an error for each extra clause found in list Clauses
27350
27351 -----------------------------
27352 -- Check_Dependency_Clause --
27353 -----------------------------
27354
27355 procedure Check_Dependency_Clause
27356 (Spec_Id : Entity_Id;
27357 Dep_Clause : Node_Id;
27358 Dep_States : Elist_Id;
27359 Refinements : List_Id;
27360 Matched_Items : in out Elist_Id)
27361 is
27362 Dep_Input : constant Node_Id := Expression (Dep_Clause);
27363 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
27364
27365 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
27366 -- Determine whether dependency item Dep_Item has been matched in a
27367 -- previous clause.
27368
27369 function Is_In_Out_State_Clause return Boolean;
27370 -- Determine whether dependence clause Dep_Clause denotes an abstract
27371 -- state that depends on itself (State => State).
27372
27373 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
27374 -- Determine whether item Item denotes an abstract state with visible
27375 -- null refinement.
27376
27377 procedure Match_Items
27378 (Dep_Item : Node_Id;
27379 Ref_Item : Node_Id;
27380 Matched : out Boolean);
27381 -- Try to match dependence item Dep_Item against refinement item
27382 -- Ref_Item. To match against a possible null refinement (see 2, 9),
27383 -- set Ref_Item to Empty. Flag Matched is set to True when one of
27384 -- the following conformance scenarios is in effect:
27385 -- 1) Both items denote null
27386 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
27387 -- 3) Both items denote attribute 'Result
27388 -- 4) Both items denote the same object
27389 -- 5) Both items denote the same formal parameter
27390 -- 6) Both items denote the same current instance of a type
27391 -- 7) Both items denote the same discriminant
27392 -- 8) Dep_Item is an abstract state with visible null refinement
27393 -- and Ref_Item denotes null.
27394 -- 9) Dep_Item is an abstract state with visible null refinement
27395 -- and Ref_Item is Empty (special case).
27396 -- 10) Dep_Item is an abstract state with full or partial visible
27397 -- non-null refinement and Ref_Item denotes one of its
27398 -- constituents.
27399 -- 11) Dep_Item is an abstract state without a full visible
27400 -- refinement and Ref_Item denotes the same state.
27401 -- When scenario 10 is in effect, the entity of the abstract state
27402 -- denoted by Dep_Item is added to list Refined_States.
27403
27404 procedure Record_Item (Item_Id : Entity_Id);
27405 -- Store the entity of an item denoted by Item_Id in Matched_Items
27406
27407 ------------------------
27408 -- Is_Already_Matched --
27409 ------------------------
27410
27411 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean is
27412 Item_Id : Entity_Id := Empty;
27413
27414 begin
27415 -- When the dependency item denotes attribute 'Result, check for
27416 -- the entity of the related subprogram.
27417
27418 if Is_Attribute_Result (Dep_Item) then
27419 Item_Id := Spec_Id;
27420
27421 elsif Is_Entity_Name (Dep_Item) then
27422 Item_Id := Available_View (Entity_Of (Dep_Item));
27423 end if;
27424
27425 return
27426 Present (Item_Id) and then Contains (Matched_Items, Item_Id);
27427 end Is_Already_Matched;
27428
27429 ----------------------------
27430 -- Is_In_Out_State_Clause --
27431 ----------------------------
27432
27433 function Is_In_Out_State_Clause return Boolean is
27434 Dep_Input_Id : Entity_Id;
27435 Dep_Output_Id : Entity_Id;
27436
27437 begin
27438 -- Detect the following clause:
27439 -- State => State
27440
27441 if Is_Entity_Name (Dep_Input)
27442 and then Is_Entity_Name (Dep_Output)
27443 then
27444 -- Handle abstract views generated for limited with clauses
27445
27446 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
27447 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
27448
27449 return
27450 Ekind (Dep_Input_Id) = E_Abstract_State
27451 and then Dep_Input_Id = Dep_Output_Id;
27452 else
27453 return False;
27454 end if;
27455 end Is_In_Out_State_Clause;
27456
27457 ---------------------------
27458 -- Is_Null_Refined_State --
27459 ---------------------------
27460
27461 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
27462 Item_Id : Entity_Id;
27463
27464 begin
27465 if Is_Entity_Name (Item) then
27466
27467 -- Handle abstract views generated for limited with clauses
27468
27469 Item_Id := Available_View (Entity_Of (Item));
27470
27471 return
27472 Ekind (Item_Id) = E_Abstract_State
27473 and then Has_Null_Visible_Refinement (Item_Id);
27474 else
27475 return False;
27476 end if;
27477 end Is_Null_Refined_State;
27478
27479 -----------------
27480 -- Match_Items --
27481 -----------------
27482
27483 procedure Match_Items
27484 (Dep_Item : Node_Id;
27485 Ref_Item : Node_Id;
27486 Matched : out Boolean)
27487 is
27488 Dep_Item_Id : Entity_Id;
27489 Ref_Item_Id : Entity_Id;
27490
27491 begin
27492 -- Assume that the two items do not match
27493
27494 Matched := False;
27495
27496 -- A null matches null or Empty (special case)
27497
27498 if Nkind (Dep_Item) = N_Null
27499 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
27500 then
27501 Matched := True;
27502
27503 -- Attribute 'Result matches attribute 'Result
27504
27505 elsif Is_Attribute_Result (Dep_Item)
27506 and then Is_Attribute_Result (Ref_Item)
27507 then
27508 -- Put the entity of the related function on the list of
27509 -- matched items because attribute 'Result does not carry
27510 -- an entity similar to states and constituents.
27511
27512 Record_Item (Spec_Id);
27513 Matched := True;
27514
27515 -- Abstract states, current instances of concurrent types,
27516 -- discriminants, formal parameters and objects.
27517
27518 elsif Is_Entity_Name (Dep_Item) then
27519
27520 -- Handle abstract views generated for limited with clauses
27521
27522 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
27523
27524 if Ekind (Dep_Item_Id) = E_Abstract_State then
27525
27526 -- An abstract state with visible null refinement matches
27527 -- null or Empty (special case).
27528
27529 if Has_Null_Visible_Refinement (Dep_Item_Id)
27530 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
27531 then
27532 Record_Item (Dep_Item_Id);
27533 Matched := True;
27534
27535 -- An abstract state with visible non-null refinement
27536 -- matches one of its constituents, or itself for an
27537 -- abstract state with partial visible refinement.
27538
27539 elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then
27540 if Is_Entity_Name (Ref_Item) then
27541 Ref_Item_Id := Entity_Of (Ref_Item);
27542
27543 if Ekind (Ref_Item_Id) in
27544 E_Abstract_State | E_Constant | E_Variable
27545 and then Present (Encapsulating_State (Ref_Item_Id))
27546 and then Find_Encapsulating_State
27547 (Dep_States, Ref_Item_Id) = Dep_Item_Id
27548 then
27549 Record_Item (Dep_Item_Id);
27550 Matched := True;
27551
27552 elsif not Has_Visible_Refinement (Dep_Item_Id)
27553 and then Ref_Item_Id = Dep_Item_Id
27554 then
27555 Record_Item (Dep_Item_Id);
27556 Matched := True;
27557 end if;
27558 end if;
27559
27560 -- An abstract state without a visible refinement matches
27561 -- itself.
27562
27563 elsif Is_Entity_Name (Ref_Item)
27564 and then Entity_Of (Ref_Item) = Dep_Item_Id
27565 then
27566 Record_Item (Dep_Item_Id);
27567 Matched := True;
27568 end if;
27569
27570 -- A current instance of a concurrent type, discriminant,
27571 -- formal parameter or an object matches itself.
27572
27573 elsif Is_Entity_Name (Ref_Item)
27574 and then Entity_Of (Ref_Item) = Dep_Item_Id
27575 then
27576 Record_Item (Dep_Item_Id);
27577 Matched := True;
27578 end if;
27579 end if;
27580 end Match_Items;
27581
27582 -----------------
27583 -- Record_Item --
27584 -----------------
27585
27586 procedure Record_Item (Item_Id : Entity_Id) is
27587 begin
27588 if No (Matched_Items) then
27589 Matched_Items := New_Elmt_List;
27590 end if;
27591
27592 Append_Unique_Elmt (Item_Id, Matched_Items);
27593 end Record_Item;
27594
27595 -- Local variables
27596
27597 Clause_Matched : Boolean := False;
27598 Dummy : Boolean := False;
27599 Inputs_Match : Boolean;
27600 Next_Ref_Clause : Node_Id;
27601 Outputs_Match : Boolean;
27602 Ref_Clause : Node_Id;
27603 Ref_Input : Node_Id;
27604 Ref_Output : Node_Id;
27605
27606 -- Start of processing for Check_Dependency_Clause
27607
27608 begin
27609 -- Do not perform this check in an instance because it was already
27610 -- performed successfully in the generic template.
27611
27612 if In_Instance then
27613 return;
27614 end if;
27615
27616 -- Examine all refinement clauses and compare them against the
27617 -- dependence clause.
27618
27619 Ref_Clause := First (Refinements);
27620 while Present (Ref_Clause) loop
27621 Next_Ref_Clause := Next (Ref_Clause);
27622
27623 -- Obtain the attributes of the current refinement clause
27624
27625 Ref_Input := Expression (Ref_Clause);
27626 Ref_Output := First (Choices (Ref_Clause));
27627
27628 -- The current refinement clause matches the dependence clause
27629 -- when both outputs match and both inputs match. See routine
27630 -- Match_Items for all possible conformance scenarios.
27631
27632 -- Depends Dep_Output => Dep_Input
27633 -- ^ ^
27634 -- match ? match ?
27635 -- v v
27636 -- Refined_Depends Ref_Output => Ref_Input
27637
27638 Match_Items
27639 (Dep_Item => Dep_Input,
27640 Ref_Item => Ref_Input,
27641 Matched => Inputs_Match);
27642
27643 Match_Items
27644 (Dep_Item => Dep_Output,
27645 Ref_Item => Ref_Output,
27646 Matched => Outputs_Match);
27647
27648 -- An In_Out state clause may be matched against a refinement with
27649 -- a null input or null output as long as the non-null side of the
27650 -- relation contains a valid constituent of the In_Out_State.
27651
27652 if Is_In_Out_State_Clause then
27653
27654 -- Depends => (State => State)
27655 -- Refined_Depends => (null => Constit) -- OK
27656
27657 if Inputs_Match
27658 and then not Outputs_Match
27659 and then Nkind (Ref_Output) = N_Null
27660 then
27661 Outputs_Match := True;
27662 end if;
27663
27664 -- Depends => (State => State)
27665 -- Refined_Depends => (Constit => null) -- OK
27666
27667 if not Inputs_Match
27668 and then Outputs_Match
27669 and then Nkind (Ref_Input) = N_Null
27670 then
27671 Inputs_Match := True;
27672 end if;
27673 end if;
27674
27675 -- The current refinement clause is legally constructed following
27676 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
27677 -- the pool of candidates. The search continues because a single
27678 -- dependence clause may have multiple matching refinements.
27679
27680 if Inputs_Match and Outputs_Match then
27681 Clause_Matched := True;
27682 Remove (Ref_Clause);
27683 end if;
27684
27685 Ref_Clause := Next_Ref_Clause;
27686 end loop;
27687
27688 -- Depending on the order or composition of refinement clauses, an
27689 -- In_Out state clause may not be directly refinable.
27690
27691 -- Refined_State => (State => (Constit_1, Constit_2))
27692 -- Depends => ((Output, State) => (Input, State))
27693 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
27694
27695 -- Matching normalized clause (State => State) fails because there is
27696 -- no direct refinement capable of satisfying this relation. Another
27697 -- similar case arises when clauses (Constit_1 => Input) and (Output
27698 -- => Constit_2) are matched first, leaving no candidates for clause
27699 -- (State => State). Both scenarios are legal as long as one of the
27700 -- previous clauses mentioned a valid constituent of State.
27701
27702 if not Clause_Matched
27703 and then Is_In_Out_State_Clause
27704 and then Is_Already_Matched (Dep_Input)
27705 then
27706 Clause_Matched := True;
27707 end if;
27708
27709 -- A clause where the input is an abstract state with visible null
27710 -- refinement or a 'Result attribute is implicitly matched when the
27711 -- output has already been matched in a previous clause.
27712
27713 -- Refined_State => (State => null)
27714 -- Depends => (Output => State) -- implicitly OK
27715 -- Refined_Depends => (Output => ...)
27716 -- Depends => (...'Result => State) -- implicitly OK
27717 -- Refined_Depends => (...'Result => ...)
27718
27719 if not Clause_Matched
27720 and then Is_Null_Refined_State (Dep_Input)
27721 and then Is_Already_Matched (Dep_Output)
27722 then
27723 Clause_Matched := True;
27724 end if;
27725
27726 -- A clause where the output is an abstract state with visible null
27727 -- refinement is implicitly matched when the input has already been
27728 -- matched in a previous clause.
27729
27730 -- Refined_State => (State => null)
27731 -- Depends => (State => Input) -- implicitly OK
27732 -- Refined_Depends => (... => Input)
27733
27734 if not Clause_Matched
27735 and then Is_Null_Refined_State (Dep_Output)
27736 and then Is_Already_Matched (Dep_Input)
27737 then
27738 Clause_Matched := True;
27739 end if;
27740
27741 -- At this point either all refinement clauses have been examined or
27742 -- pragma Refined_Depends contains a solitary null. Only an abstract
27743 -- state with null refinement can possibly match these cases.
27744
27745 -- Refined_State => (State => null)
27746 -- Depends => (State => null)
27747 -- Refined_Depends => null -- OK
27748
27749 if not Clause_Matched then
27750 Match_Items
27751 (Dep_Item => Dep_Input,
27752 Ref_Item => Empty,
27753 Matched => Inputs_Match);
27754
27755 Match_Items
27756 (Dep_Item => Dep_Output,
27757 Ref_Item => Empty,
27758 Matched => Outputs_Match);
27759
27760 Clause_Matched := Inputs_Match and Outputs_Match;
27761 end if;
27762
27763 -- If the contents of Refined_Depends are legal, then the current
27764 -- dependence clause should be satisfied either by an explicit match
27765 -- or by one of the special cases.
27766
27767 if not Clause_Matched then
27768 SPARK_Msg_NE
27769 (Fix_Msg (Spec_Id, "dependence clause of subprogram & has no "
27770 & "matching refinement in body"), Dep_Clause, Spec_Id);
27771 end if;
27772 end Check_Dependency_Clause;
27773
27774 -------------------------
27775 -- Check_Output_States --
27776 -------------------------
27777
27778 procedure Check_Output_States
27779 (Spec_Inputs : Elist_Id;
27780 Spec_Outputs : Elist_Id;
27781 Body_Inputs : Elist_Id;
27782 Body_Outputs : Elist_Id)
27783 is
27784 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27785 -- Determine whether all constituents of state State_Id with full
27786 -- visible refinement are used as outputs in pragma Refined_Depends.
27787 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
27788
27789 -----------------------------
27790 -- Check_Constituent_Usage --
27791 -----------------------------
27792
27793 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27794 Constits : constant Elist_Id :=
27795 Partial_Refinement_Constituents (State_Id);
27796 Constit_Elmt : Elmt_Id;
27797 Constit_Id : Entity_Id;
27798 Only_Partial : constant Boolean :=
27799 not Has_Visible_Refinement (State_Id);
27800 Posted : Boolean := False;
27801
27802 begin
27803 if Present (Constits) then
27804 Constit_Elmt := First_Elmt (Constits);
27805 while Present (Constit_Elmt) loop
27806 Constit_Id := Node (Constit_Elmt);
27807
27808 -- Issue an error when a constituent of State_Id is used,
27809 -- and State_Id has only partial visible refinement
27810 -- (SPARK RM 7.2.4(3d)).
27811
27812 if Only_Partial then
27813 if (Present (Body_Inputs)
27814 and then Appears_In (Body_Inputs, Constit_Id))
27815 or else
27816 (Present (Body_Outputs)
27817 and then Appears_In (Body_Outputs, Constit_Id))
27818 then
27819 Error_Msg_Name_1 := Chars (State_Id);
27820 SPARK_Msg_NE
27821 ("constituent & of state % cannot be used in "
27822 & "dependence refinement", N, Constit_Id);
27823 Error_Msg_Name_1 := Chars (State_Id);
27824 SPARK_Msg_N ("\use state % instead", N);
27825 end if;
27826
27827 -- The constituent acts as an input (SPARK RM 7.2.5(3))
27828
27829 elsif Present (Body_Inputs)
27830 and then Appears_In (Body_Inputs, Constit_Id)
27831 then
27832 Error_Msg_Name_1 := Chars (State_Id);
27833 SPARK_Msg_NE
27834 ("constituent & of state % must act as output in "
27835 & "dependence refinement", N, Constit_Id);
27836
27837 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
27838
27839 elsif No (Body_Outputs)
27840 or else not Appears_In (Body_Outputs, Constit_Id)
27841 then
27842 if not Posted then
27843 Posted := True;
27844 SPARK_Msg_NE
27845 ("output state & must be replaced by all its "
27846 & "constituents in dependence refinement",
27847 N, State_Id);
27848 end if;
27849
27850 SPARK_Msg_NE
27851 ("\constituent & is missing in output list",
27852 N, Constit_Id);
27853 end if;
27854
27855 Next_Elmt (Constit_Elmt);
27856 end loop;
27857 end if;
27858 end Check_Constituent_Usage;
27859
27860 -- Local variables
27861
27862 Item : Node_Id;
27863 Item_Elmt : Elmt_Id;
27864 Item_Id : Entity_Id;
27865
27866 -- Start of processing for Check_Output_States
27867
27868 begin
27869 -- Do not perform this check in an instance because it was already
27870 -- performed successfully in the generic template.
27871
27872 if In_Instance then
27873 null;
27874
27875 -- Inspect the outputs of pragma Depends looking for a state with a
27876 -- visible refinement.
27877
27878 elsif Present (Spec_Outputs) then
27879 Item_Elmt := First_Elmt (Spec_Outputs);
27880 while Present (Item_Elmt) loop
27881 Item := Node (Item_Elmt);
27882
27883 -- Deal with the mixed nature of the input and output lists
27884
27885 if Nkind (Item) = N_Defining_Identifier then
27886 Item_Id := Item;
27887 else
27888 Item_Id := Available_View (Entity_Of (Item));
27889 end if;
27890
27891 if Ekind (Item_Id) = E_Abstract_State then
27892
27893 -- The state acts as an input-output, skip it
27894
27895 if Present (Spec_Inputs)
27896 and then Appears_In (Spec_Inputs, Item_Id)
27897 then
27898 null;
27899
27900 -- Ensure that all of the constituents are utilized as
27901 -- outputs in pragma Refined_Depends.
27902
27903 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
27904 Check_Constituent_Usage (Item_Id);
27905 end if;
27906 end if;
27907
27908 Next_Elmt (Item_Elmt);
27909 end loop;
27910 end if;
27911 end Check_Output_States;
27912
27913 --------------------
27914 -- Collect_States --
27915 --------------------
27916
27917 function Collect_States (Clauses : List_Id) return Elist_Id is
27918 procedure Collect_State
27919 (Item : Node_Id;
27920 States : in out Elist_Id);
27921 -- Add the entity of Item to list States when it denotes to a state
27922
27923 -------------------
27924 -- Collect_State --
27925 -------------------
27926
27927 procedure Collect_State
27928 (Item : Node_Id;
27929 States : in out Elist_Id)
27930 is
27931 Id : Entity_Id;
27932
27933 begin
27934 if Is_Entity_Name (Item) then
27935 Id := Entity_Of (Item);
27936
27937 if Ekind (Id) = E_Abstract_State then
27938 if No (States) then
27939 States := New_Elmt_List;
27940 end if;
27941
27942 Append_Unique_Elmt (Id, States);
27943 end if;
27944 end if;
27945 end Collect_State;
27946
27947 -- Local variables
27948
27949 Clause : Node_Id;
27950 Input : Node_Id;
27951 Output : Node_Id;
27952 States : Elist_Id := No_Elist;
27953
27954 -- Start of processing for Collect_States
27955
27956 begin
27957 Clause := First (Clauses);
27958 while Present (Clause) loop
27959 Input := Expression (Clause);
27960 Output := First (Choices (Clause));
27961
27962 Collect_State (Input, States);
27963 Collect_State (Output, States);
27964
27965 Next (Clause);
27966 end loop;
27967
27968 return States;
27969 end Collect_States;
27970
27971 -----------------------
27972 -- Normalize_Clauses --
27973 -----------------------
27974
27975 procedure Normalize_Clauses (Clauses : List_Id) is
27976 procedure Normalize_Inputs (Clause : Node_Id);
27977 -- Normalize clause Clause by creating multiple clauses for each
27978 -- input item of Clause. It is assumed that Clause has exactly one
27979 -- output. The transformation is as follows:
27980 --
27981 -- Output => (Input_1, Input_2) -- original
27982 --
27983 -- Output => Input_1 -- normalizations
27984 -- Output => Input_2
27985
27986 procedure Normalize_Outputs (Clause : Node_Id);
27987 -- Normalize clause Clause by creating multiple clause for each
27988 -- output item of Clause. The transformation is as follows:
27989 --
27990 -- (Output_1, Output_2) => Input -- original
27991 --
27992 -- Output_1 => Input -- normalization
27993 -- Output_2 => Input
27994
27995 ----------------------
27996 -- Normalize_Inputs --
27997 ----------------------
27998
27999 procedure Normalize_Inputs (Clause : Node_Id) is
28000 Inputs : constant Node_Id := Expression (Clause);
28001 Loc : constant Source_Ptr := Sloc (Clause);
28002 Output : constant List_Id := Choices (Clause);
28003 Last_Input : Node_Id;
28004 Input : Node_Id;
28005 New_Clause : Node_Id;
28006 Next_Input : Node_Id;
28007
28008 begin
28009 -- Normalization is performed only when the original clause has
28010 -- more than one input. Multiple inputs appear as an aggregate.
28011
28012 if Nkind (Inputs) = N_Aggregate then
28013 Last_Input := Last (Expressions (Inputs));
28014
28015 -- Create a new clause for each input
28016
28017 Input := First (Expressions (Inputs));
28018 while Present (Input) loop
28019 Next_Input := Next (Input);
28020
28021 -- Unhook the current input from the original input list
28022 -- because it will be relocated to a new clause.
28023
28024 Remove (Input);
28025
28026 -- Special processing for the last input. At this point the
28027 -- original aggregate has been stripped down to one element.
28028 -- Replace the aggregate by the element itself.
28029
28030 if Input = Last_Input then
28031 Rewrite (Inputs, Input);
28032
28033 -- Generate a clause of the form:
28034 -- Output => Input
28035
28036 else
28037 New_Clause :=
28038 Make_Component_Association (Loc,
28039 Choices => New_Copy_List_Tree (Output),
28040 Expression => Input);
28041
28042 -- The new clause contains replicated content that has
28043 -- already been analyzed, mark the clause as analyzed.
28044
28045 Set_Analyzed (New_Clause);
28046 Insert_After (Clause, New_Clause);
28047 end if;
28048
28049 Input := Next_Input;
28050 end loop;
28051 end if;
28052 end Normalize_Inputs;
28053
28054 -----------------------
28055 -- Normalize_Outputs --
28056 -----------------------
28057
28058 procedure Normalize_Outputs (Clause : Node_Id) is
28059 Inputs : constant Node_Id := Expression (Clause);
28060 Loc : constant Source_Ptr := Sloc (Clause);
28061 Outputs : constant Node_Id := First (Choices (Clause));
28062 Last_Output : Node_Id;
28063 New_Clause : Node_Id;
28064 Next_Output : Node_Id;
28065 Output : Node_Id;
28066
28067 begin
28068 -- Multiple outputs appear as an aggregate. Nothing to do when
28069 -- the clause has exactly one output.
28070
28071 if Nkind (Outputs) = N_Aggregate then
28072 Last_Output := Last (Expressions (Outputs));
28073
28074 -- Create a clause for each output. Note that each time a new
28075 -- clause is created, the original output list slowly shrinks
28076 -- until there is one item left.
28077
28078 Output := First (Expressions (Outputs));
28079 while Present (Output) loop
28080 Next_Output := Next (Output);
28081
28082 -- Unhook the output from the original output list as it
28083 -- will be relocated to a new clause.
28084
28085 Remove (Output);
28086
28087 -- Special processing for the last output. At this point
28088 -- the original aggregate has been stripped down to one
28089 -- element. Replace the aggregate by the element itself.
28090
28091 if Output = Last_Output then
28092 Rewrite (Outputs, Output);
28093
28094 else
28095 -- Generate a clause of the form:
28096 -- (Output => Inputs)
28097
28098 New_Clause :=
28099 Make_Component_Association (Loc,
28100 Choices => New_List (Output),
28101 Expression => New_Copy_Tree (Inputs));
28102
28103 -- The new clause contains replicated content that has
28104 -- already been analyzed. There is not need to reanalyze
28105 -- them.
28106
28107 Set_Analyzed (New_Clause);
28108 Insert_After (Clause, New_Clause);
28109 end if;
28110
28111 Output := Next_Output;
28112 end loop;
28113 end if;
28114 end Normalize_Outputs;
28115
28116 -- Local variables
28117
28118 Clause : Node_Id;
28119
28120 -- Start of processing for Normalize_Clauses
28121
28122 begin
28123 Clause := First (Clauses);
28124 while Present (Clause) loop
28125 Normalize_Outputs (Clause);
28126 Next (Clause);
28127 end loop;
28128
28129 Clause := First (Clauses);
28130 while Present (Clause) loop
28131 Normalize_Inputs (Clause);
28132 Next (Clause);
28133 end loop;
28134 end Normalize_Clauses;
28135
28136 --------------------------
28137 -- Remove_Extra_Clauses --
28138 --------------------------
28139
28140 procedure Remove_Extra_Clauses
28141 (Clauses : List_Id;
28142 Matched_Items : Elist_Id)
28143 is
28144 Clause : Node_Id;
28145 Input : Node_Id;
28146 Input_Id : Entity_Id;
28147 Next_Clause : Node_Id;
28148 Output : Node_Id;
28149 State_Id : Entity_Id;
28150
28151 begin
28152 Clause := First (Clauses);
28153 while Present (Clause) loop
28154 Next_Clause := Next (Clause);
28155
28156 Input := Expression (Clause);
28157 Output := First (Choices (Clause));
28158
28159 -- Recognize a clause of the form
28160
28161 -- null => Input
28162
28163 -- where Input is a constituent of a state which was already
28164 -- successfully matched. This clause must be removed because it
28165 -- simply indicates that some of the constituents of the state
28166 -- are not used.
28167
28168 -- Refined_State => (State => (Constit_1, Constit_2))
28169 -- Depends => (Output => State)
28170 -- Refined_Depends => ((Output => Constit_1), -- State matched
28171 -- (null => Constit_2)) -- OK
28172
28173 if Nkind (Output) = N_Null and then Is_Entity_Name (Input) then
28174
28175 -- Handle abstract views generated for limited with clauses
28176
28177 Input_Id := Available_View (Entity_Of (Input));
28178
28179 -- The input must be a constituent of a state
28180
28181 if Ekind (Input_Id) in
28182 E_Abstract_State | E_Constant | E_Variable
28183 and then Present (Encapsulating_State (Input_Id))
28184 then
28185 State_Id := Encapsulating_State (Input_Id);
28186
28187 -- The state must have a non-null visible refinement and be
28188 -- matched in a previous clause.
28189
28190 if Has_Non_Null_Visible_Refinement (State_Id)
28191 and then Contains (Matched_Items, State_Id)
28192 then
28193 Remove (Clause);
28194 end if;
28195 end if;
28196
28197 -- Recognize a clause of the form
28198
28199 -- Output => null
28200
28201 -- where Output is an arbitrary item. This clause must be removed
28202 -- because a null input legitimately matches anything.
28203
28204 elsif Nkind (Input) = N_Null then
28205 Remove (Clause);
28206 end if;
28207
28208 Clause := Next_Clause;
28209 end loop;
28210 end Remove_Extra_Clauses;
28211
28212 --------------------------
28213 -- Report_Extra_Clauses --
28214 --------------------------
28215
28216 procedure Report_Extra_Clauses (Clauses : List_Id) is
28217 Clause : Node_Id;
28218
28219 begin
28220 -- Do not perform this check in an instance because it was already
28221 -- performed successfully in the generic template.
28222
28223 if In_Instance then
28224 null;
28225
28226 elsif Present (Clauses) then
28227 Clause := First (Clauses);
28228 while Present (Clause) loop
28229 SPARK_Msg_N
28230 ("unmatched or extra clause in dependence refinement",
28231 Clause);
28232
28233 Next (Clause);
28234 end loop;
28235 end if;
28236 end Report_Extra_Clauses;
28237
28238 -- Local variables
28239
28240 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
28241 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
28242 Errors : constant Nat := Serious_Errors_Detected;
28243
28244 Clause : Node_Id;
28245 Deps : Node_Id;
28246 Dummy : Boolean;
28247 Refs : Node_Id;
28248
28249 Body_Inputs : Elist_Id := No_Elist;
28250 Body_Outputs : Elist_Id := No_Elist;
28251 -- The inputs and outputs of the subprogram body synthesized from pragma
28252 -- Refined_Depends.
28253
28254 Dependencies : List_Id := No_List;
28255 Depends : Node_Id;
28256 -- The corresponding Depends pragma along with its clauses
28257
28258 Matched_Items : Elist_Id := No_Elist;
28259 -- A list containing the entities of all successfully matched items
28260 -- found in pragma Depends.
28261
28262 Refinements : List_Id := No_List;
28263 -- The clauses of pragma Refined_Depends
28264
28265 Spec_Id : Entity_Id;
28266 -- The entity of the subprogram subject to pragma Refined_Depends
28267
28268 Spec_Inputs : Elist_Id := No_Elist;
28269 Spec_Outputs : Elist_Id := No_Elist;
28270 -- The inputs and outputs of the subprogram spec synthesized from pragma
28271 -- Depends.
28272
28273 States : Elist_Id := No_Elist;
28274 -- A list containing the entities of all states whose constituents
28275 -- appear in pragma Depends.
28276
28277 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
28278
28279 begin
28280 -- Do not analyze the pragma multiple times
28281
28282 if Is_Analyzed_Pragma (N) then
28283 return;
28284 end if;
28285
28286 Spec_Id := Unique_Defining_Entity (Body_Decl);
28287
28288 -- Use the anonymous object as the proper spec when Refined_Depends
28289 -- applies to the body of a single task type. The object carries the
28290 -- proper Chars as well as all non-refined versions of pragmas.
28291
28292 if Is_Single_Concurrent_Type (Spec_Id) then
28293 Spec_Id := Anonymous_Object (Spec_Id);
28294 end if;
28295
28296 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
28297
28298 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
28299 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
28300
28301 if No (Depends) then
28302 SPARK_Msg_NE
28303 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
28304 & "& lacks aspect or pragma Depends"), N, Spec_Id);
28305 goto Leave;
28306 end if;
28307
28308 Deps := Expression (Get_Argument (Depends, Spec_Id));
28309
28310 -- A null dependency relation renders the refinement useless because it
28311 -- cannot possibly mention abstract states with visible refinement. Note
28312 -- that the inverse is not true as states may be refined to null
28313 -- (SPARK RM 7.2.5(2)).
28314
28315 if Nkind (Deps) = N_Null then
28316 SPARK_Msg_NE
28317 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
28318 & "depend on abstract state with visible refinement"), N, Spec_Id);
28319 goto Leave;
28320 end if;
28321
28322 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
28323 -- This ensures that the categorization of all refined dependency items
28324 -- is consistent with their role.
28325
28326 Analyze_Depends_In_Decl_Part (N);
28327
28328 -- Do not match dependencies against refinements if Refined_Depends is
28329 -- illegal to avoid emitting misleading error.
28330
28331 if Serious_Errors_Detected = Errors then
28332
28333 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
28334 -- the inputs and outputs of the subprogram spec and body to verify
28335 -- the use of states with visible refinement and their constituents.
28336
28337 if No (Get_Pragma (Spec_Id, Pragma_Global))
28338 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
28339 then
28340 Collect_Subprogram_Inputs_Outputs
28341 (Subp_Id => Spec_Id,
28342 Synthesize => True,
28343 Subp_Inputs => Spec_Inputs,
28344 Subp_Outputs => Spec_Outputs,
28345 Global_Seen => Dummy);
28346
28347 Collect_Subprogram_Inputs_Outputs
28348 (Subp_Id => Body_Id,
28349 Synthesize => True,
28350 Subp_Inputs => Body_Inputs,
28351 Subp_Outputs => Body_Outputs,
28352 Global_Seen => Dummy);
28353
28354 -- For an output state with a visible refinement, ensure that all
28355 -- constituents appear as outputs in the dependency refinement.
28356
28357 Check_Output_States
28358 (Spec_Inputs => Spec_Inputs,
28359 Spec_Outputs => Spec_Outputs,
28360 Body_Inputs => Body_Inputs,
28361 Body_Outputs => Body_Outputs);
28362 end if;
28363
28364 -- Multiple dependency clauses appear as component associations of an
28365 -- aggregate. Note that the clauses are copied because the algorithm
28366 -- modifies them and this should not be visible in Depends.
28367
28368 pragma Assert (Nkind (Deps) = N_Aggregate);
28369 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
28370 Normalize_Clauses (Dependencies);
28371
28372 -- Gather all states which appear in Depends
28373
28374 States := Collect_States (Dependencies);
28375
28376 Refs := Expression (Get_Argument (N, Spec_Id));
28377
28378 if Nkind (Refs) = N_Null then
28379 Refinements := No_List;
28380
28381 -- Multiple dependency clauses appear as component associations of an
28382 -- aggregate. Note that the clauses are copied because the algorithm
28383 -- modifies them and this should not be visible in Refined_Depends.
28384
28385 else pragma Assert (Nkind (Refs) = N_Aggregate);
28386 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
28387 Normalize_Clauses (Refinements);
28388 end if;
28389
28390 -- At this point the clauses of pragmas Depends and Refined_Depends
28391 -- have been normalized into simple dependencies between one output
28392 -- and one input. Examine all clauses of pragma Depends looking for
28393 -- matching clauses in pragma Refined_Depends.
28394
28395 Clause := First (Dependencies);
28396 while Present (Clause) loop
28397 Check_Dependency_Clause
28398 (Spec_Id => Spec_Id,
28399 Dep_Clause => Clause,
28400 Dep_States => States,
28401 Refinements => Refinements,
28402 Matched_Items => Matched_Items);
28403
28404 Next (Clause);
28405 end loop;
28406
28407 -- Pragma Refined_Depends may contain multiple clarification clauses
28408 -- which indicate that certain constituents do not influence the data
28409 -- flow in any way. Such clauses must be removed as long as the state
28410 -- has been matched, otherwise they will be incorrectly flagged as
28411 -- unmatched.
28412
28413 -- Refined_State => (State => (Constit_1, Constit_2))
28414 -- Depends => (Output => State)
28415 -- Refined_Depends => ((Output => Constit_1), -- State matched
28416 -- (null => Constit_2)) -- must be removed
28417
28418 Remove_Extra_Clauses (Refinements, Matched_Items);
28419
28420 if Serious_Errors_Detected = Errors then
28421 Report_Extra_Clauses (Refinements);
28422 end if;
28423 end if;
28424
28425 <<Leave>>
28426 Set_Is_Analyzed_Pragma (N);
28427 end Analyze_Refined_Depends_In_Decl_Part;
28428
28429 -----------------------------------------
28430 -- Analyze_Refined_Global_In_Decl_Part --
28431 -----------------------------------------
28432
28433 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
28434 Global : Node_Id;
28435 -- The corresponding Global pragma
28436
28437 Has_In_State : Boolean := False;
28438 Has_In_Out_State : Boolean := False;
28439 Has_Out_State : Boolean := False;
28440 Has_Proof_In_State : Boolean := False;
28441 -- These flags are set when the corresponding Global pragma has a state
28442 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
28443 -- refinement.
28444
28445 Has_Null_State : Boolean := False;
28446 -- This flag is set when the corresponding Global pragma has at least
28447 -- one state with a null refinement.
28448
28449 In_Constits : Elist_Id := No_Elist;
28450 In_Out_Constits : Elist_Id := No_Elist;
28451 Out_Constits : Elist_Id := No_Elist;
28452 Proof_In_Constits : Elist_Id := No_Elist;
28453 -- These lists contain the entities of all Input, In_Out, Output and
28454 -- Proof_In constituents that appear in Refined_Global and participate
28455 -- in state refinement.
28456
28457 In_Items : Elist_Id := No_Elist;
28458 In_Out_Items : Elist_Id := No_Elist;
28459 Out_Items : Elist_Id := No_Elist;
28460 Proof_In_Items : Elist_Id := No_Elist;
28461 -- These lists contain the entities of all Input, In_Out, Output and
28462 -- Proof_In items defined in the corresponding Global pragma.
28463
28464 Repeat_Items : Elist_Id := No_Elist;
28465 -- A list of all global items without full visible refinement found
28466 -- in pragma Global. These states should be repeated in the global
28467 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
28468 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
28469
28470 Spec_Id : Entity_Id;
28471 -- The entity of the subprogram subject to pragma Refined_Global
28472
28473 States : Elist_Id := No_Elist;
28474 -- A list of all states with full or partial visible refinement found in
28475 -- pragma Global.
28476
28477 procedure Check_In_Out_States;
28478 -- Determine whether the corresponding Global pragma mentions In_Out
28479 -- states with visible refinement and if so, ensure that one of the
28480 -- following completions apply to the constituents of the state:
28481 -- 1) there is at least one constituent of mode In_Out
28482 -- 2) there is at least one Input and one Output constituent
28483 -- 3) not all constituents are present and one of them is of mode
28484 -- Output.
28485 -- This routine may remove elements from In_Constits, In_Out_Constits,
28486 -- Out_Constits and Proof_In_Constits.
28487
28488 procedure Check_Input_States;
28489 -- Determine whether the corresponding Global pragma mentions Input
28490 -- states with visible refinement and if so, ensure that at least one of
28491 -- its constituents appears as an Input item in Refined_Global.
28492 -- This routine may remove elements from In_Constits, In_Out_Constits,
28493 -- Out_Constits and Proof_In_Constits.
28494
28495 procedure Check_Output_States;
28496 -- Determine whether the corresponding Global pragma mentions Output
28497 -- states with visible refinement and if so, ensure that all of its
28498 -- constituents appear as Output items in Refined_Global.
28499 -- This routine may remove elements from In_Constits, In_Out_Constits,
28500 -- Out_Constits and Proof_In_Constits.
28501
28502 procedure Check_Proof_In_States;
28503 -- Determine whether the corresponding Global pragma mentions Proof_In
28504 -- states with visible refinement and if so, ensure that at least one of
28505 -- its constituents appears as a Proof_In item in Refined_Global.
28506 -- This routine may remove elements from In_Constits, In_Out_Constits,
28507 -- Out_Constits and Proof_In_Constits.
28508
28509 procedure Check_Refined_Global_List
28510 (List : Node_Id;
28511 Global_Mode : Name_Id := Name_Input);
28512 -- Verify the legality of a single global list declaration. Global_Mode
28513 -- denotes the current mode in effect.
28514
28515 procedure Collect_Global_Items
28516 (List : Node_Id;
28517 Mode : Name_Id := Name_Input);
28518 -- Gather all Input, In_Out, Output and Proof_In items from node List
28519 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
28520 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
28521 -- and Has_Proof_In_State are set when there is at least one abstract
28522 -- state with full or partial visible refinement available in the
28523 -- corresponding mode. Flag Has_Null_State is set when at least state
28524 -- has a null refinement. Mode denotes the current global mode in
28525 -- effect.
28526
28527 function Present_Then_Remove
28528 (List : Elist_Id;
28529 Item : Entity_Id) return Boolean;
28530 -- Search List for a particular entity Item. If Item has been found,
28531 -- remove it from List. This routine is used to strip lists In_Constits,
28532 -- In_Out_Constits and Out_Constits of valid constituents.
28533
28534 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id);
28535 -- Same as function Present_Then_Remove, but do not report the presence
28536 -- of Item in List.
28537
28538 procedure Report_Extra_Constituents;
28539 -- Emit an error for each constituent found in lists In_Constits,
28540 -- In_Out_Constits and Out_Constits.
28541
28542 procedure Report_Missing_Items;
28543 -- Emit an error for each global item not repeated found in list
28544 -- Repeat_Items.
28545
28546 -------------------------
28547 -- Check_In_Out_States --
28548 -------------------------
28549
28550 procedure Check_In_Out_States is
28551 procedure Check_Constituent_Usage (State_Id : Entity_Id);
28552 -- Determine whether one of the following coverage scenarios is in
28553 -- effect:
28554 -- 1) there is at least one constituent of mode In_Out or Output
28555 -- 2) there is at least one pair of constituents with modes Input
28556 -- and Output, or Proof_In and Output.
28557 -- 3) there is at least one constituent of mode Output and not all
28558 -- constituents are present.
28559 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
28560
28561 -----------------------------
28562 -- Check_Constituent_Usage --
28563 -----------------------------
28564
28565 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
28566 Constits : constant Elist_Id :=
28567 Partial_Refinement_Constituents (State_Id);
28568 Constit_Elmt : Elmt_Id;
28569 Constit_Id : Entity_Id;
28570 Has_Missing : Boolean := False;
28571 In_Out_Seen : Boolean := False;
28572 Input_Seen : Boolean := False;
28573 Output_Seen : Boolean := False;
28574 Proof_In_Seen : Boolean := False;
28575
28576 begin
28577 -- Process all the constituents of the state and note their modes
28578 -- within the global refinement.
28579
28580 if Present (Constits) then
28581 Constit_Elmt := First_Elmt (Constits);
28582 while Present (Constit_Elmt) loop
28583 Constit_Id := Node (Constit_Elmt);
28584
28585 if Present_Then_Remove (In_Constits, Constit_Id) then
28586 Input_Seen := True;
28587
28588 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
28589 In_Out_Seen := True;
28590
28591 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
28592 Output_Seen := True;
28593
28594 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
28595 then
28596 Proof_In_Seen := True;
28597
28598 else
28599 Has_Missing := True;
28600 end if;
28601
28602 Next_Elmt (Constit_Elmt);
28603 end loop;
28604 end if;
28605
28606 -- An In_Out constituent is a valid completion
28607
28608 if In_Out_Seen then
28609 null;
28610
28611 -- A pair of one Input/Proof_In and one Output constituent is a
28612 -- valid completion.
28613
28614 elsif (Input_Seen or Proof_In_Seen) and Output_Seen then
28615 null;
28616
28617 elsif Output_Seen then
28618
28619 -- A single Output constituent is a valid completion only when
28620 -- some of the other constituents are missing.
28621
28622 if Has_Missing then
28623 null;
28624
28625 -- Otherwise all constituents are of mode Output
28626
28627 else
28628 SPARK_Msg_NE
28629 ("global refinement of state & must include at least one "
28630 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
28631 N, State_Id);
28632 end if;
28633
28634 -- The state lacks a completion. When full refinement is visible,
28635 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
28636 -- refinement is visible, emit an error if the abstract state
28637 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
28638 -- both are utilized, Check_State_And_Constituent_Use. will issue
28639 -- the error.
28640
28641 elsif not Input_Seen
28642 and then not In_Out_Seen
28643 and then not Output_Seen
28644 and then not Proof_In_Seen
28645 then
28646 if Has_Visible_Refinement (State_Id)
28647 or else Contains (Repeat_Items, State_Id)
28648 then
28649 SPARK_Msg_NE
28650 ("missing global refinement of state &", N, State_Id);
28651 end if;
28652
28653 -- Otherwise the state has a malformed completion where at least
28654 -- one of the constituents has a different mode.
28655
28656 else
28657 SPARK_Msg_NE
28658 ("global refinement of state & redefines the mode of its "
28659 & "constituents", N, State_Id);
28660 end if;
28661 end Check_Constituent_Usage;
28662
28663 -- Local variables
28664
28665 Item_Elmt : Elmt_Id;
28666 Item_Id : Entity_Id;
28667
28668 -- Start of processing for Check_In_Out_States
28669
28670 begin
28671 -- Do not perform this check in an instance because it was already
28672 -- performed successfully in the generic template.
28673
28674 if In_Instance then
28675 null;
28676
28677 -- Inspect the In_Out items of the corresponding Global pragma
28678 -- looking for a state with a visible refinement.
28679
28680 elsif Has_In_Out_State and then Present (In_Out_Items) then
28681 Item_Elmt := First_Elmt (In_Out_Items);
28682 while Present (Item_Elmt) loop
28683 Item_Id := Node (Item_Elmt);
28684
28685 -- Ensure that one of the three coverage variants is satisfied
28686
28687 if Ekind (Item_Id) = E_Abstract_State
28688 and then Has_Non_Null_Visible_Refinement (Item_Id)
28689 then
28690 Check_Constituent_Usage (Item_Id);
28691 end if;
28692
28693 Next_Elmt (Item_Elmt);
28694 end loop;
28695 end if;
28696 end Check_In_Out_States;
28697
28698 ------------------------
28699 -- Check_Input_States --
28700 ------------------------
28701
28702 procedure Check_Input_States is
28703 procedure Check_Constituent_Usage (State_Id : Entity_Id);
28704 -- Determine whether at least one constituent of state State_Id with
28705 -- full or partial visible refinement is used and has mode Input.
28706 -- Ensure that the remaining constituents do not have In_Out or
28707 -- Output modes. Emit an error if this is not the case
28708 -- (SPARK RM 7.2.4(5)).
28709
28710 -----------------------------
28711 -- Check_Constituent_Usage --
28712 -----------------------------
28713
28714 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
28715 Constits : constant Elist_Id :=
28716 Partial_Refinement_Constituents (State_Id);
28717 Constit_Elmt : Elmt_Id;
28718 Constit_Id : Entity_Id;
28719 In_Seen : Boolean := False;
28720
28721 begin
28722 if Present (Constits) then
28723 Constit_Elmt := First_Elmt (Constits);
28724 while Present (Constit_Elmt) loop
28725 Constit_Id := Node (Constit_Elmt);
28726
28727 -- At least one of the constituents appears as an Input
28728
28729 if Present_Then_Remove (In_Constits, Constit_Id) then
28730 In_Seen := True;
28731
28732 -- A Proof_In constituent can refine an Input state as long
28733 -- as there is at least one Input constituent present.
28734
28735 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
28736 then
28737 null;
28738
28739 -- The constituent appears in the global refinement, but has
28740 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
28741
28742 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
28743 or else Present_Then_Remove (Out_Constits, Constit_Id)
28744 then
28745 Error_Msg_Name_1 := Chars (State_Id);
28746 SPARK_Msg_NE
28747 ("constituent & of state % must have mode `Input` in "
28748 & "global refinement", N, Constit_Id);
28749 end if;
28750
28751 Next_Elmt (Constit_Elmt);
28752 end loop;
28753 end if;
28754
28755 -- Not one of the constituents appeared as Input. Always emit an
28756 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
28757 -- When only partial refinement is visible, emit an error if the
28758 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
28759 -- the case where both are utilized, an error will be issued in
28760 -- Check_State_And_Constituent_Use.
28761
28762 if not In_Seen
28763 and then (Has_Visible_Refinement (State_Id)
28764 or else Contains (Repeat_Items, State_Id))
28765 then
28766 SPARK_Msg_NE
28767 ("global refinement of state & must include at least one "
28768 & "constituent of mode `Input`", N, State_Id);
28769 end if;
28770 end Check_Constituent_Usage;
28771
28772 -- Local variables
28773
28774 Item_Elmt : Elmt_Id;
28775 Item_Id : Entity_Id;
28776
28777 -- Start of processing for Check_Input_States
28778
28779 begin
28780 -- Do not perform this check in an instance because it was already
28781 -- performed successfully in the generic template.
28782
28783 if In_Instance then
28784 null;
28785
28786 -- Inspect the Input items of the corresponding Global pragma looking
28787 -- for a state with a visible refinement.
28788
28789 elsif Has_In_State and then Present (In_Items) then
28790 Item_Elmt := First_Elmt (In_Items);
28791 while Present (Item_Elmt) loop
28792 Item_Id := Node (Item_Elmt);
28793
28794 -- When full refinement is visible, ensure that at least one of
28795 -- the constituents is utilized and is of mode Input. When only
28796 -- partial refinement is visible, ensure that either one of
28797 -- the constituents is utilized and is of mode Input, or the
28798 -- abstract state is repeated and no constituent is utilized.
28799
28800 if Ekind (Item_Id) = E_Abstract_State
28801 and then Has_Non_Null_Visible_Refinement (Item_Id)
28802 then
28803 Check_Constituent_Usage (Item_Id);
28804 end if;
28805
28806 Next_Elmt (Item_Elmt);
28807 end loop;
28808 end if;
28809 end Check_Input_States;
28810
28811 -------------------------
28812 -- Check_Output_States --
28813 -------------------------
28814
28815 procedure Check_Output_States is
28816 procedure Check_Constituent_Usage (State_Id : Entity_Id);
28817 -- Determine whether all constituents of state State_Id with full
28818 -- visible refinement are used and have mode Output. Emit an error
28819 -- if this is not the case (SPARK RM 7.2.4(5)).
28820
28821 -----------------------------
28822 -- Check_Constituent_Usage --
28823 -----------------------------
28824
28825 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
28826 Constits : constant Elist_Id :=
28827 Partial_Refinement_Constituents (State_Id);
28828 Only_Partial : constant Boolean :=
28829 not Has_Visible_Refinement (State_Id);
28830 Constit_Elmt : Elmt_Id;
28831 Constit_Id : Entity_Id;
28832 Posted : Boolean := False;
28833
28834 begin
28835 if Present (Constits) then
28836 Constit_Elmt := First_Elmt (Constits);
28837 while Present (Constit_Elmt) loop
28838 Constit_Id := Node (Constit_Elmt);
28839
28840 -- Issue an error when a constituent of State_Id is utilized
28841 -- and State_Id has only partial visible refinement
28842 -- (SPARK RM 7.2.4(3d)).
28843
28844 if Only_Partial then
28845 if Present_Then_Remove (Out_Constits, Constit_Id)
28846 or else Present_Then_Remove (In_Constits, Constit_Id)
28847 or else
28848 Present_Then_Remove (In_Out_Constits, Constit_Id)
28849 or else
28850 Present_Then_Remove (Proof_In_Constits, Constit_Id)
28851 then
28852 Error_Msg_Name_1 := Chars (State_Id);
28853 SPARK_Msg_NE
28854 ("constituent & of state % cannot be used in global "
28855 & "refinement", N, Constit_Id);
28856 Error_Msg_Name_1 := Chars (State_Id);
28857 SPARK_Msg_N ("\use state % instead", N);
28858 end if;
28859
28860 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
28861 null;
28862
28863 -- The constituent appears in the global refinement, but has
28864 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
28865
28866 elsif Present_Then_Remove (In_Constits, Constit_Id)
28867 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
28868 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
28869 then
28870 Error_Msg_Name_1 := Chars (State_Id);
28871 SPARK_Msg_NE
28872 ("constituent & of state % must have mode `Output` in "
28873 & "global refinement", N, Constit_Id);
28874
28875 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
28876
28877 else
28878 if not Posted then
28879 Posted := True;
28880 SPARK_Msg_NE
28881 ("`Output` state & must be replaced by all its "
28882 & "constituents in global refinement", N, State_Id);
28883 end if;
28884
28885 SPARK_Msg_NE
28886 ("\constituent & is missing in output list",
28887 N, Constit_Id);
28888 end if;
28889
28890 Next_Elmt (Constit_Elmt);
28891 end loop;
28892 end if;
28893 end Check_Constituent_Usage;
28894
28895 -- Local variables
28896
28897 Item_Elmt : Elmt_Id;
28898 Item_Id : Entity_Id;
28899
28900 -- Start of processing for Check_Output_States
28901
28902 begin
28903 -- Do not perform this check in an instance because it was already
28904 -- performed successfully in the generic template.
28905
28906 if In_Instance then
28907 null;
28908
28909 -- Inspect the Output items of the corresponding Global pragma
28910 -- looking for a state with a visible refinement.
28911
28912 elsif Has_Out_State and then Present (Out_Items) then
28913 Item_Elmt := First_Elmt (Out_Items);
28914 while Present (Item_Elmt) loop
28915 Item_Id := Node (Item_Elmt);
28916
28917 -- When full refinement is visible, ensure that all of the
28918 -- constituents are utilized and they have mode Output. When
28919 -- only partial refinement is visible, ensure that no
28920 -- constituent is utilized.
28921
28922 if Ekind (Item_Id) = E_Abstract_State
28923 and then Has_Non_Null_Visible_Refinement (Item_Id)
28924 then
28925 Check_Constituent_Usage (Item_Id);
28926 end if;
28927
28928 Next_Elmt (Item_Elmt);
28929 end loop;
28930 end if;
28931 end Check_Output_States;
28932
28933 ---------------------------
28934 -- Check_Proof_In_States --
28935 ---------------------------
28936
28937 procedure Check_Proof_In_States is
28938 procedure Check_Constituent_Usage (State_Id : Entity_Id);
28939 -- Determine whether at least one constituent of state State_Id with
28940 -- full or partial visible refinement is used and has mode Proof_In.
28941 -- Ensure that the remaining constituents do not have Input, In_Out,
28942 -- or Output modes. Emit an error if this is not the case
28943 -- (SPARK RM 7.2.4(5)).
28944
28945 -----------------------------
28946 -- Check_Constituent_Usage --
28947 -----------------------------
28948
28949 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
28950 Constits : constant Elist_Id :=
28951 Partial_Refinement_Constituents (State_Id);
28952 Constit_Elmt : Elmt_Id;
28953 Constit_Id : Entity_Id;
28954 Proof_In_Seen : Boolean := False;
28955
28956 begin
28957 if Present (Constits) then
28958 Constit_Elmt := First_Elmt (Constits);
28959 while Present (Constit_Elmt) loop
28960 Constit_Id := Node (Constit_Elmt);
28961
28962 -- At least one of the constituents appears as Proof_In
28963
28964 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
28965 Proof_In_Seen := True;
28966
28967 -- The constituent appears in the global refinement, but has
28968 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
28969
28970 elsif Present_Then_Remove (In_Constits, Constit_Id)
28971 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
28972 or else Present_Then_Remove (Out_Constits, Constit_Id)
28973 then
28974 Error_Msg_Name_1 := Chars (State_Id);
28975 SPARK_Msg_NE
28976 ("constituent & of state % must have mode `Proof_In` "
28977 & "in global refinement", N, Constit_Id);
28978 end if;
28979
28980 Next_Elmt (Constit_Elmt);
28981 end loop;
28982 end if;
28983
28984 -- Not one of the constituents appeared as Proof_In. Always emit
28985 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
28986 -- When only partial refinement is visible, emit an error if the
28987 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
28988 -- the case where both are utilized, an error will be issued by
28989 -- Check_State_And_Constituent_Use.
28990
28991 if not Proof_In_Seen
28992 and then (Has_Visible_Refinement (State_Id)
28993 or else Contains (Repeat_Items, State_Id))
28994 then
28995 SPARK_Msg_NE
28996 ("global refinement of state & must include at least one "
28997 & "constituent of mode `Proof_In`", N, State_Id);
28998 end if;
28999 end Check_Constituent_Usage;
29000
29001 -- Local variables
29002
29003 Item_Elmt : Elmt_Id;
29004 Item_Id : Entity_Id;
29005
29006 -- Start of processing for Check_Proof_In_States
29007
29008 begin
29009 -- Do not perform this check in an instance because it was already
29010 -- performed successfully in the generic template.
29011
29012 if In_Instance then
29013 null;
29014
29015 -- Inspect the Proof_In items of the corresponding Global pragma
29016 -- looking for a state with a visible refinement.
29017
29018 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
29019 Item_Elmt := First_Elmt (Proof_In_Items);
29020 while Present (Item_Elmt) loop
29021 Item_Id := Node (Item_Elmt);
29022
29023 -- Ensure that at least one of the constituents is utilized
29024 -- and is of mode Proof_In. When only partial refinement is
29025 -- visible, ensure that either one of the constituents is
29026 -- utilized and is of mode Proof_In, or the abstract state
29027 -- is repeated and no constituent is utilized.
29028
29029 if Ekind (Item_Id) = E_Abstract_State
29030 and then Has_Non_Null_Visible_Refinement (Item_Id)
29031 then
29032 Check_Constituent_Usage (Item_Id);
29033 end if;
29034
29035 Next_Elmt (Item_Elmt);
29036 end loop;
29037 end if;
29038 end Check_Proof_In_States;
29039
29040 -------------------------------
29041 -- Check_Refined_Global_List --
29042 -------------------------------
29043
29044 procedure Check_Refined_Global_List
29045 (List : Node_Id;
29046 Global_Mode : Name_Id := Name_Input)
29047 is
29048 procedure Check_Refined_Global_Item
29049 (Item : Node_Id;
29050 Global_Mode : Name_Id);
29051 -- Verify the legality of a single global item declaration. Parameter
29052 -- Global_Mode denotes the current mode in effect.
29053
29054 -------------------------------
29055 -- Check_Refined_Global_Item --
29056 -------------------------------
29057
29058 procedure Check_Refined_Global_Item
29059 (Item : Node_Id;
29060 Global_Mode : Name_Id)
29061 is
29062 Item_Id : constant Entity_Id := Entity_Of (Item);
29063
29064 procedure Inconsistent_Mode_Error (Expect : Name_Id);
29065 -- Issue a common error message for all mode mismatches. Expect
29066 -- denotes the expected mode.
29067
29068 -----------------------------
29069 -- Inconsistent_Mode_Error --
29070 -----------------------------
29071
29072 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
29073 begin
29074 SPARK_Msg_NE
29075 ("global item & has inconsistent modes", Item, Item_Id);
29076
29077 Error_Msg_Name_1 := Global_Mode;
29078 Error_Msg_Name_2 := Expect;
29079 SPARK_Msg_N ("\expected mode %, found mode %", Item);
29080 end Inconsistent_Mode_Error;
29081
29082 -- Local variables
29083
29084 Enc_State : Entity_Id := Empty;
29085 -- Encapsulating state for constituent, Empty otherwise
29086
29087 -- Start of processing for Check_Refined_Global_Item
29088
29089 begin
29090 if Ekind (Item_Id) in E_Abstract_State | E_Constant | E_Variable
29091 then
29092 Enc_State := Find_Encapsulating_State (States, Item_Id);
29093 end if;
29094
29095 -- When the state or object acts as a constituent of another
29096 -- state with a visible refinement, collect it for the state
29097 -- completeness checks performed later on. Note that the item
29098 -- acts as a constituent only when the encapsulating state is
29099 -- present in pragma Global.
29100
29101 if Present (Enc_State)
29102 and then (Has_Visible_Refinement (Enc_State)
29103 or else Has_Partial_Visible_Refinement (Enc_State))
29104 and then Contains (States, Enc_State)
29105 then
29106 -- If the state has only partial visible refinement, remove it
29107 -- from the list of items that should be repeated from pragma
29108 -- Global.
29109
29110 if not Has_Visible_Refinement (Enc_State) then
29111 Present_Then_Remove (Repeat_Items, Enc_State);
29112 end if;
29113
29114 if Global_Mode = Name_Input then
29115 Append_New_Elmt (Item_Id, In_Constits);
29116
29117 elsif Global_Mode = Name_In_Out then
29118 Append_New_Elmt (Item_Id, In_Out_Constits);
29119
29120 elsif Global_Mode = Name_Output then
29121 Append_New_Elmt (Item_Id, Out_Constits);
29122
29123 elsif Global_Mode = Name_Proof_In then
29124 Append_New_Elmt (Item_Id, Proof_In_Constits);
29125 end if;
29126
29127 -- When not a constituent, ensure that both occurrences of the
29128 -- item in pragmas Global and Refined_Global match. Also remove
29129 -- it when present from the list of items that should be repeated
29130 -- from pragma Global.
29131
29132 else
29133 Present_Then_Remove (Repeat_Items, Item_Id);
29134
29135 if Contains (In_Items, Item_Id) then
29136 if Global_Mode /= Name_Input then
29137 Inconsistent_Mode_Error (Name_Input);
29138 end if;
29139
29140 elsif Contains (In_Out_Items, Item_Id) then
29141 if Global_Mode /= Name_In_Out then
29142 Inconsistent_Mode_Error (Name_In_Out);
29143 end if;
29144
29145 elsif Contains (Out_Items, Item_Id) then
29146 if Global_Mode /= Name_Output then
29147 Inconsistent_Mode_Error (Name_Output);
29148 end if;
29149
29150 elsif Contains (Proof_In_Items, Item_Id) then
29151 null;
29152
29153 -- The item does not appear in the corresponding Global pragma,
29154 -- it must be an extra (SPARK RM 7.2.4(3)).
29155
29156 else
29157 pragma Assert (Present (Global));
29158 Error_Msg_Sloc := Sloc (Global);
29159 SPARK_Msg_NE
29160 ("extra global item & does not refine or repeat any "
29161 & "global item #", Item, Item_Id);
29162 end if;
29163 end if;
29164 end Check_Refined_Global_Item;
29165
29166 -- Local variables
29167
29168 Item : Node_Id;
29169
29170 -- Start of processing for Check_Refined_Global_List
29171
29172 begin
29173 -- Do not perform this check in an instance because it was already
29174 -- performed successfully in the generic template.
29175
29176 if In_Instance then
29177 null;
29178
29179 elsif Nkind (List) = N_Null then
29180 null;
29181
29182 -- Single global item declaration
29183
29184 elsif Nkind (List) in N_Expanded_Name
29185 | N_Identifier
29186 | N_Selected_Component
29187 then
29188 Check_Refined_Global_Item (List, Global_Mode);
29189
29190 -- Simple global list or moded global list declaration
29191
29192 elsif Nkind (List) = N_Aggregate then
29193
29194 -- The declaration of a simple global list appear as a collection
29195 -- of expressions.
29196
29197 if Present (Expressions (List)) then
29198 Item := First (Expressions (List));
29199 while Present (Item) loop
29200 Check_Refined_Global_Item (Item, Global_Mode);
29201 Next (Item);
29202 end loop;
29203
29204 -- The declaration of a moded global list appears as a collection
29205 -- of component associations where individual choices denote
29206 -- modes.
29207
29208 elsif Present (Component_Associations (List)) then
29209 Item := First (Component_Associations (List));
29210 while Present (Item) loop
29211 Check_Refined_Global_List
29212 (List => Expression (Item),
29213 Global_Mode => Chars (First (Choices (Item))));
29214
29215 Next (Item);
29216 end loop;
29217
29218 -- Invalid tree
29219
29220 else
29221 raise Program_Error;
29222 end if;
29223
29224 -- Invalid list
29225
29226 else
29227 raise Program_Error;
29228 end if;
29229 end Check_Refined_Global_List;
29230
29231 --------------------------
29232 -- Collect_Global_Items --
29233 --------------------------
29234
29235 procedure Collect_Global_Items
29236 (List : Node_Id;
29237 Mode : Name_Id := Name_Input)
29238 is
29239 procedure Collect_Global_Item
29240 (Item : Node_Id;
29241 Item_Mode : Name_Id);
29242 -- Add a single item to the appropriate list. Item_Mode denotes the
29243 -- current mode in effect.
29244
29245 -------------------------
29246 -- Collect_Global_Item --
29247 -------------------------
29248
29249 procedure Collect_Global_Item
29250 (Item : Node_Id;
29251 Item_Mode : Name_Id)
29252 is
29253 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
29254 -- The above handles abstract views of variables and states built
29255 -- for limited with clauses.
29256
29257 begin
29258 -- Signal that the global list contains at least one abstract
29259 -- state with a visible refinement. Note that the refinement may
29260 -- be null in which case there are no constituents.
29261
29262 if Ekind (Item_Id) = E_Abstract_State then
29263 if Has_Null_Visible_Refinement (Item_Id) then
29264 Has_Null_State := True;
29265
29266 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
29267 Append_New_Elmt (Item_Id, States);
29268
29269 if Item_Mode = Name_Input then
29270 Has_In_State := True;
29271 elsif Item_Mode = Name_In_Out then
29272 Has_In_Out_State := True;
29273 elsif Item_Mode = Name_Output then
29274 Has_Out_State := True;
29275 elsif Item_Mode = Name_Proof_In then
29276 Has_Proof_In_State := True;
29277 end if;
29278 end if;
29279 end if;
29280
29281 -- Record global items without full visible refinement found in
29282 -- pragma Global which should be repeated in the global refinement
29283 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
29284
29285 if Ekind (Item_Id) /= E_Abstract_State
29286 or else not Has_Visible_Refinement (Item_Id)
29287 then
29288 Append_New_Elmt (Item_Id, Repeat_Items);
29289 end if;
29290
29291 -- Add the item to the proper list
29292
29293 if Item_Mode = Name_Input then
29294 Append_New_Elmt (Item_Id, In_Items);
29295 elsif Item_Mode = Name_In_Out then
29296 Append_New_Elmt (Item_Id, In_Out_Items);
29297 elsif Item_Mode = Name_Output then
29298 Append_New_Elmt (Item_Id, Out_Items);
29299 elsif Item_Mode = Name_Proof_In then
29300 Append_New_Elmt (Item_Id, Proof_In_Items);
29301 end if;
29302 end Collect_Global_Item;
29303
29304 -- Local variables
29305
29306 Item : Node_Id;
29307
29308 -- Start of processing for Collect_Global_Items
29309
29310 begin
29311 if Nkind (List) = N_Null then
29312 null;
29313
29314 -- Single global item declaration
29315
29316 elsif Nkind (List) in N_Expanded_Name
29317 | N_Identifier
29318 | N_Selected_Component
29319 then
29320 Collect_Global_Item (List, Mode);
29321
29322 -- Single global list or moded global list declaration
29323
29324 elsif Nkind (List) = N_Aggregate then
29325
29326 -- The declaration of a simple global list appear as a collection
29327 -- of expressions.
29328
29329 if Present (Expressions (List)) then
29330 Item := First (Expressions (List));
29331 while Present (Item) loop
29332 Collect_Global_Item (Item, Mode);
29333 Next (Item);
29334 end loop;
29335
29336 -- The declaration of a moded global list appears as a collection
29337 -- of component associations where individual choices denote mode.
29338
29339 elsif Present (Component_Associations (List)) then
29340 Item := First (Component_Associations (List));
29341 while Present (Item) loop
29342 Collect_Global_Items
29343 (List => Expression (Item),
29344 Mode => Chars (First (Choices (Item))));
29345
29346 Next (Item);
29347 end loop;
29348
29349 -- Invalid tree
29350
29351 else
29352 raise Program_Error;
29353 end if;
29354
29355 -- To accommodate partial decoration of disabled SPARK features, this
29356 -- routine may be called with illegal input. If this is the case, do
29357 -- not raise Program_Error.
29358
29359 else
29360 null;
29361 end if;
29362 end Collect_Global_Items;
29363
29364 -------------------------
29365 -- Present_Then_Remove --
29366 -------------------------
29367
29368 function Present_Then_Remove
29369 (List : Elist_Id;
29370 Item : Entity_Id) return Boolean
29371 is
29372 Elmt : Elmt_Id;
29373
29374 begin
29375 if Present (List) then
29376 Elmt := First_Elmt (List);
29377 while Present (Elmt) loop
29378 if Node (Elmt) = Item then
29379 Remove_Elmt (List, Elmt);
29380 return True;
29381 end if;
29382
29383 Next_Elmt (Elmt);
29384 end loop;
29385 end if;
29386
29387 return False;
29388 end Present_Then_Remove;
29389
29390 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id) is
29391 Ignore : Boolean;
29392 begin
29393 Ignore := Present_Then_Remove (List, Item);
29394 end Present_Then_Remove;
29395
29396 -------------------------------
29397 -- Report_Extra_Constituents --
29398 -------------------------------
29399
29400 procedure Report_Extra_Constituents is
29401 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
29402 -- Emit an error for every element of List
29403
29404 ---------------------------------------
29405 -- Report_Extra_Constituents_In_List --
29406 ---------------------------------------
29407
29408 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
29409 Constit_Elmt : Elmt_Id;
29410
29411 begin
29412 if Present (List) then
29413 Constit_Elmt := First_Elmt (List);
29414 while Present (Constit_Elmt) loop
29415 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
29416 Next_Elmt (Constit_Elmt);
29417 end loop;
29418 end if;
29419 end Report_Extra_Constituents_In_List;
29420
29421 -- Start of processing for Report_Extra_Constituents
29422
29423 begin
29424 -- Do not perform this check in an instance because it was already
29425 -- performed successfully in the generic template.
29426
29427 if In_Instance then
29428 null;
29429
29430 else
29431 Report_Extra_Constituents_In_List (In_Constits);
29432 Report_Extra_Constituents_In_List (In_Out_Constits);
29433 Report_Extra_Constituents_In_List (Out_Constits);
29434 Report_Extra_Constituents_In_List (Proof_In_Constits);
29435 end if;
29436 end Report_Extra_Constituents;
29437
29438 --------------------------
29439 -- Report_Missing_Items --
29440 --------------------------
29441
29442 procedure Report_Missing_Items is
29443 Item_Elmt : Elmt_Id;
29444 Item_Id : Entity_Id;
29445
29446 begin
29447 -- Do not perform this check in an instance because it was already
29448 -- performed successfully in the generic template.
29449
29450 if In_Instance then
29451 null;
29452
29453 else
29454 if Present (Repeat_Items) then
29455 Item_Elmt := First_Elmt (Repeat_Items);
29456 while Present (Item_Elmt) loop
29457 Item_Id := Node (Item_Elmt);
29458 SPARK_Msg_NE ("missing global item &", N, Item_Id);
29459 Next_Elmt (Item_Elmt);
29460 end loop;
29461 end if;
29462 end if;
29463 end Report_Missing_Items;
29464
29465 -- Local variables
29466
29467 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
29468 Errors : constant Nat := Serious_Errors_Detected;
29469 Items : Node_Id;
29470 No_Constit : Boolean;
29471
29472 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
29473
29474 begin
29475 -- Do not analyze the pragma multiple times
29476
29477 if Is_Analyzed_Pragma (N) then
29478 return;
29479 end if;
29480
29481 Spec_Id := Unique_Defining_Entity (Body_Decl);
29482
29483 -- Use the anonymous object as the proper spec when Refined_Global
29484 -- applies to the body of a single task type. The object carries the
29485 -- proper Chars as well as all non-refined versions of pragmas.
29486
29487 if Is_Single_Concurrent_Type (Spec_Id) then
29488 Spec_Id := Anonymous_Object (Spec_Id);
29489 end if;
29490
29491 Global := Get_Pragma (Spec_Id, Pragma_Global);
29492 Items := Expression (Get_Argument (N, Spec_Id));
29493
29494 -- The subprogram declaration lacks pragma Global. This renders
29495 -- Refined_Global useless as there is nothing to refine.
29496
29497 if No (Global) then
29498 SPARK_Msg_NE
29499 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
29500 & "& lacks aspect or pragma Global"), N, Spec_Id);
29501 goto Leave;
29502 end if;
29503
29504 -- Extract all relevant items from the corresponding Global pragma
29505
29506 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
29507
29508 -- Package and subprogram bodies are instantiated individually in
29509 -- a separate compiler pass. Due to this mode of instantiation, the
29510 -- refinement of a state may no longer be visible when a subprogram
29511 -- body contract is instantiated. Since the generic template is legal,
29512 -- do not perform this check in the instance to circumvent this oddity.
29513
29514 if In_Instance then
29515 null;
29516
29517 -- Non-instance case
29518
29519 else
29520 -- The corresponding Global pragma must mention at least one
29521 -- state with a visible refinement at the point Refined_Global
29522 -- is processed. States with null refinements need Refined_Global
29523 -- pragma (SPARK RM 7.2.4(2)).
29524
29525 if not Has_In_State
29526 and then not Has_In_Out_State
29527 and then not Has_Out_State
29528 and then not Has_Proof_In_State
29529 and then not Has_Null_State
29530 then
29531 SPARK_Msg_NE
29532 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
29533 & "depend on abstract state with visible refinement"),
29534 N, Spec_Id);
29535 goto Leave;
29536
29537 -- The global refinement of inputs and outputs cannot be null when
29538 -- the corresponding Global pragma contains at least one item except
29539 -- in the case where we have states with null refinements.
29540
29541 elsif Nkind (Items) = N_Null
29542 and then
29543 (Present (In_Items)
29544 or else Present (In_Out_Items)
29545 or else Present (Out_Items)
29546 or else Present (Proof_In_Items))
29547 and then not Has_Null_State
29548 then
29549 SPARK_Msg_NE
29550 (Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has "
29551 & "global items"), N, Spec_Id);
29552 goto Leave;
29553 end if;
29554 end if;
29555
29556 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
29557 -- This ensures that the categorization of all refined global items is
29558 -- consistent with their role.
29559
29560 Analyze_Global_In_Decl_Part (N);
29561
29562 -- Perform all refinement checks with respect to completeness and mode
29563 -- matching.
29564
29565 if Serious_Errors_Detected = Errors then
29566 Check_Refined_Global_List (Items);
29567 end if;
29568
29569 -- Store the information that no constituent is used in the global
29570 -- refinement, prior to calling checking procedures which remove items
29571 -- from the list of constituents.
29572
29573 No_Constit :=
29574 No (In_Constits)
29575 and then No (In_Out_Constits)
29576 and then No (Out_Constits)
29577 and then No (Proof_In_Constits);
29578
29579 -- For Input states with visible refinement, at least one constituent
29580 -- must be used as an Input in the global refinement.
29581
29582 if Serious_Errors_Detected = Errors then
29583 Check_Input_States;
29584 end if;
29585
29586 -- Verify all possible completion variants for In_Out states with
29587 -- visible refinement.
29588
29589 if Serious_Errors_Detected = Errors then
29590 Check_In_Out_States;
29591 end if;
29592
29593 -- For Output states with visible refinement, all constituents must be
29594 -- used as Outputs in the global refinement.
29595
29596 if Serious_Errors_Detected = Errors then
29597 Check_Output_States;
29598 end if;
29599
29600 -- For Proof_In states with visible refinement, at least one constituent
29601 -- must be used as Proof_In in the global refinement.
29602
29603 if Serious_Errors_Detected = Errors then
29604 Check_Proof_In_States;
29605 end if;
29606
29607 -- Emit errors for all constituents that belong to other states with
29608 -- visible refinement that do not appear in Global.
29609
29610 if Serious_Errors_Detected = Errors then
29611 Report_Extra_Constituents;
29612 end if;
29613
29614 -- Emit errors for all items in Global that are not repeated in the
29615 -- global refinement and for which there is no full visible refinement
29616 -- and, in the case of states with partial visible refinement, no
29617 -- constituent is mentioned in the global refinement.
29618
29619 if Serious_Errors_Detected = Errors then
29620 Report_Missing_Items;
29621 end if;
29622
29623 -- Emit an error if no constituent is used in the global refinement
29624 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
29625 -- one may be issued by the checking procedures. Do not perform this
29626 -- check in an instance because it was already performed successfully
29627 -- in the generic template.
29628
29629 if Serious_Errors_Detected = Errors
29630 and then not In_Instance
29631 and then not Has_Null_State
29632 and then No_Constit
29633 then
29634 SPARK_Msg_N ("missing refinement", N);
29635 end if;
29636
29637 <<Leave>>
29638 Set_Is_Analyzed_Pragma (N);
29639 end Analyze_Refined_Global_In_Decl_Part;
29640
29641 ----------------------------------------
29642 -- Analyze_Refined_State_In_Decl_Part --
29643 ----------------------------------------
29644
29645 procedure Analyze_Refined_State_In_Decl_Part
29646 (N : Node_Id;
29647 Freeze_Id : Entity_Id := Empty)
29648 is
29649 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
29650 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
29651 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
29652
29653 Available_States : Elist_Id := No_Elist;
29654 -- A list of all abstract states defined in the package declaration that
29655 -- are available for refinement. The list is used to report unrefined
29656 -- states.
29657
29658 Body_States : Elist_Id := No_Elist;
29659 -- A list of all hidden states that appear in the body of the related
29660 -- package. The list is used to report unused hidden states.
29661
29662 Constituents_Seen : Elist_Id := No_Elist;
29663 -- A list that contains all constituents processed so far. The list is
29664 -- used to detect multiple uses of the same constituent.
29665
29666 Freeze_Posted : Boolean := False;
29667 -- A flag that controls the output of a freezing-related error (see use
29668 -- below).
29669
29670 Refined_States_Seen : Elist_Id := No_Elist;
29671 -- A list that contains all refined states processed so far. The list is
29672 -- used to detect duplicate refinements.
29673
29674 procedure Analyze_Refinement_Clause (Clause : Node_Id);
29675 -- Perform full analysis of a single refinement clause
29676
29677 procedure Report_Unrefined_States (States : Elist_Id);
29678 -- Emit errors for all unrefined abstract states found in list States
29679
29680 -------------------------------
29681 -- Analyze_Refinement_Clause --
29682 -------------------------------
29683
29684 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
29685 AR_Constit : Entity_Id := Empty;
29686 AW_Constit : Entity_Id := Empty;
29687 ER_Constit : Entity_Id := Empty;
29688 EW_Constit : Entity_Id := Empty;
29689 -- The entities of external constituents that contain one of the
29690 -- following enabled properties: Async_Readers, Async_Writers,
29691 -- Effective_Reads and Effective_Writes.
29692
29693 External_Constit_Seen : Boolean := False;
29694 -- Flag used to mark when at least one external constituent is part
29695 -- of the state refinement.
29696
29697 Non_Null_Seen : Boolean := False;
29698 Null_Seen : Boolean := False;
29699 -- Flags used to detect multiple uses of null in a single clause or a
29700 -- mixture of null and non-null constituents.
29701
29702 Part_Of_Constits : Elist_Id := No_Elist;
29703 -- A list of all candidate constituents subject to indicator Part_Of
29704 -- where the encapsulating state is the current state.
29705
29706 State : Node_Id;
29707 State_Id : Entity_Id;
29708 -- The current state being refined
29709
29710 procedure Analyze_Constituent (Constit : Node_Id);
29711 -- Perform full analysis of a single constituent
29712
29713 procedure Check_External_Property
29714 (Prop_Nam : Name_Id;
29715 Enabled : Boolean;
29716 Constit : Entity_Id);
29717 -- Determine whether a property denoted by name Prop_Nam is present
29718 -- in the refined state. Emit an error if this is not the case. Flag
29719 -- Enabled should be set when the property applies to the refined
29720 -- state. Constit denotes the constituent (if any) which introduces
29721 -- the property in the refinement.
29722
29723 procedure Match_State;
29724 -- Determine whether the state being refined appears in list
29725 -- Available_States. Emit an error when attempting to re-refine the
29726 -- state or when the state is not defined in the package declaration,
29727 -- otherwise remove the state from Available_States.
29728
29729 procedure Report_Unused_Constituents (Constits : Elist_Id);
29730 -- Emit errors for all unused Part_Of constituents in list Constits
29731
29732 -------------------------
29733 -- Analyze_Constituent --
29734 -------------------------
29735
29736 procedure Analyze_Constituent (Constit : Node_Id) is
29737 procedure Match_Constituent (Constit_Id : Entity_Id);
29738 -- Determine whether constituent Constit denoted by its entity
29739 -- Constit_Id appears in Body_States. Emit an error when the
29740 -- constituent is not a valid hidden state of the related package
29741 -- or when it is used more than once. Otherwise remove the
29742 -- constituent from Body_States.
29743
29744 -----------------------
29745 -- Match_Constituent --
29746 -----------------------
29747
29748 procedure Match_Constituent (Constit_Id : Entity_Id) is
29749 procedure Collect_Constituent;
29750 -- Verify the legality of constituent Constit_Id and add it to
29751 -- the refinements of State_Id.
29752
29753 -------------------------
29754 -- Collect_Constituent --
29755 -------------------------
29756
29757 procedure Collect_Constituent is
29758 Constits : Elist_Id;
29759
29760 begin
29761 -- The Ghost policy in effect at the point of abstract state
29762 -- declaration and constituent must match (SPARK RM 6.9(15))
29763
29764 Check_Ghost_Refinement
29765 (State, State_Id, Constit, Constit_Id);
29766
29767 -- A synchronized state must be refined by a synchronized
29768 -- object or another synchronized state (SPARK RM 9.6).
29769
29770 if Is_Synchronized_State (State_Id)
29771 and then not Is_Synchronized_Object (Constit_Id)
29772 and then not Is_Synchronized_State (Constit_Id)
29773 then
29774 SPARK_Msg_NE
29775 ("constituent of synchronized state & must be "
29776 & "synchronized", Constit, State_Id);
29777 end if;
29778
29779 -- Add the constituent to the list of processed items to aid
29780 -- with the detection of duplicates.
29781
29782 Append_New_Elmt (Constit_Id, Constituents_Seen);
29783
29784 -- Collect the constituent in the list of refinement items
29785 -- and establish a relation between the refined state and
29786 -- the item.
29787
29788 Constits := Refinement_Constituents (State_Id);
29789
29790 if No (Constits) then
29791 Constits := New_Elmt_List;
29792 Set_Refinement_Constituents (State_Id, Constits);
29793 end if;
29794
29795 Append_Elmt (Constit_Id, Constits);
29796 Set_Encapsulating_State (Constit_Id, State_Id);
29797
29798 -- The state has at least one legal constituent, mark the
29799 -- start of the refinement region. The region ends when the
29800 -- body declarations end (see routine Analyze_Declarations).
29801
29802 Set_Has_Visible_Refinement (State_Id);
29803
29804 -- When the constituent is external, save its relevant
29805 -- property for further checks.
29806
29807 if Async_Readers_Enabled (Constit_Id) then
29808 AR_Constit := Constit_Id;
29809 External_Constit_Seen := True;
29810 end if;
29811
29812 if Async_Writers_Enabled (Constit_Id) then
29813 AW_Constit := Constit_Id;
29814 External_Constit_Seen := True;
29815 end if;
29816
29817 if Effective_Reads_Enabled (Constit_Id) then
29818 ER_Constit := Constit_Id;
29819 External_Constit_Seen := True;
29820 end if;
29821
29822 if Effective_Writes_Enabled (Constit_Id) then
29823 EW_Constit := Constit_Id;
29824 External_Constit_Seen := True;
29825 end if;
29826 end Collect_Constituent;
29827
29828 -- Local variables
29829
29830 State_Elmt : Elmt_Id;
29831
29832 -- Start of processing for Match_Constituent
29833
29834 begin
29835 -- Detect a duplicate use of a constituent
29836
29837 if Contains (Constituents_Seen, Constit_Id) then
29838 SPARK_Msg_NE
29839 ("duplicate use of constituent &", Constit, Constit_Id);
29840 return;
29841 end if;
29842
29843 -- The constituent is subject to a Part_Of indicator
29844
29845 if Present (Encapsulating_State (Constit_Id)) then
29846 if Encapsulating_State (Constit_Id) = State_Id then
29847 Remove (Part_Of_Constits, Constit_Id);
29848 Collect_Constituent;
29849
29850 -- The constituent is part of another state and is used
29851 -- incorrectly in the refinement of the current state.
29852
29853 else
29854 Error_Msg_Name_1 := Chars (State_Id);
29855 SPARK_Msg_NE
29856 ("& cannot act as constituent of state %",
29857 Constit, Constit_Id);
29858 SPARK_Msg_NE
29859 ("\Part_Of indicator specifies encapsulator &",
29860 Constit, Encapsulating_State (Constit_Id));
29861 end if;
29862
29863 else
29864 declare
29865 Pack_Id : Entity_Id;
29866 Placement : State_Space_Kind;
29867 begin
29868 -- Find where the constituent lives with respect to the
29869 -- state space.
29870
29871 Find_Placement_In_State_Space
29872 (Item_Id => Constit_Id,
29873 Placement => Placement,
29874 Pack_Id => Pack_Id);
29875
29876 -- The constituent is either part of the hidden state of
29877 -- the package or part of the visible state of a private
29878 -- child package, but lacks a Part_Of indicator.
29879
29880 if (Placement = Private_State_Space
29881 and then Pack_Id = Spec_Id)
29882 or else
29883 (Placement = Visible_State_Space
29884 and then Is_Child_Unit (Pack_Id)
29885 and then not Is_Generic_Unit (Pack_Id)
29886 and then Is_Private_Descendant (Pack_Id))
29887 then
29888 Error_Msg_Name_1 := Chars (State_Id);
29889 SPARK_Msg_NE
29890 ("& cannot act as constituent of state %",
29891 Constit, Constit_Id);
29892 Error_Msg_Sloc :=
29893 Sloc (Enclosing_Declaration (Constit_Id));
29894 SPARK_Msg_NE
29895 ("\missing Part_Of indicator # should specify "
29896 & "encapsulator &",
29897 Constit, State_Id);
29898
29899 -- The only other source of legal constituents is the
29900 -- body state space of the related package.
29901
29902 else
29903 if Present (Body_States) then
29904 State_Elmt := First_Elmt (Body_States);
29905 while Present (State_Elmt) loop
29906
29907 -- Consume a valid constituent to signal that it
29908 -- has been encountered.
29909
29910 if Node (State_Elmt) = Constit_Id then
29911 Remove_Elmt (Body_States, State_Elmt);
29912 Collect_Constituent;
29913 return;
29914 end if;
29915
29916 Next_Elmt (State_Elmt);
29917 end loop;
29918 end if;
29919
29920 -- At this point it is known that the constituent is
29921 -- not part of the package hidden state and cannot be
29922 -- used in a refinement (SPARK RM 7.2.2(9)).
29923
29924 Error_Msg_Name_1 := Chars (Spec_Id);
29925 SPARK_Msg_NE
29926 ("cannot use & in refinement, constituent is not a "
29927 & "hidden state of package %", Constit, Constit_Id);
29928 end if;
29929 end;
29930 end if;
29931 end Match_Constituent;
29932
29933 -- Local variables
29934
29935 Constit_Id : Entity_Id;
29936 Constits : Elist_Id;
29937
29938 -- Start of processing for Analyze_Constituent
29939
29940 begin
29941 -- Detect multiple uses of null in a single refinement clause or a
29942 -- mixture of null and non-null constituents.
29943
29944 if Nkind (Constit) = N_Null then
29945 if Null_Seen then
29946 SPARK_Msg_N
29947 ("multiple null constituents not allowed", Constit);
29948
29949 elsif Non_Null_Seen then
29950 SPARK_Msg_N
29951 ("cannot mix null and non-null constituents", Constit);
29952
29953 else
29954 Null_Seen := True;
29955
29956 -- Collect the constituent in the list of refinement items
29957
29958 Constits := Refinement_Constituents (State_Id);
29959
29960 if No (Constits) then
29961 Constits := New_Elmt_List;
29962 Set_Refinement_Constituents (State_Id, Constits);
29963 end if;
29964
29965 Append_Elmt (Constit, Constits);
29966
29967 -- The state has at least one legal constituent, mark the
29968 -- start of the refinement region. The region ends when the
29969 -- body declarations end (see Analyze_Declarations).
29970
29971 Set_Has_Visible_Refinement (State_Id);
29972 end if;
29973
29974 -- Non-null constituents
29975
29976 else
29977 Non_Null_Seen := True;
29978
29979 if Null_Seen then
29980 SPARK_Msg_N
29981 ("cannot mix null and non-null constituents", Constit);
29982 end if;
29983
29984 Analyze (Constit);
29985 Resolve_State (Constit);
29986
29987 -- Ensure that the constituent denotes a valid state or a
29988 -- whole object (SPARK RM 7.2.2(5)).
29989
29990 if Is_Entity_Name (Constit) then
29991 Constit_Id := Entity_Of (Constit);
29992
29993 -- When a constituent is declared after a subprogram body
29994 -- that caused freezing of the related contract where
29995 -- pragma Refined_State resides, the constituent appears
29996 -- undefined and carries Any_Id as its entity.
29997
29998 -- package body Pack
29999 -- with Refined_State => (State => Constit)
30000 -- is
30001 -- procedure Proc
30002 -- with Refined_Global => (Input => Constit)
30003 -- is
30004 -- ...
30005 -- end Proc;
30006
30007 -- Constit : ...;
30008 -- end Pack;
30009
30010 if Constit_Id = Any_Id then
30011 SPARK_Msg_NE ("& is undefined", Constit, Constit_Id);
30012
30013 -- Emit a specialized info message when the contract of
30014 -- the related package body was "frozen" by another body.
30015 -- Note that it is not possible to precisely identify why
30016 -- the constituent is undefined because it is not visible
30017 -- when pragma Refined_State is analyzed. This message is
30018 -- a reasonable approximation.
30019
30020 if Present (Freeze_Id) and then not Freeze_Posted then
30021 Freeze_Posted := True;
30022
30023 Error_Msg_Name_1 := Chars (Body_Id);
30024 Error_Msg_Sloc := Sloc (Freeze_Id);
30025 SPARK_Msg_NE
30026 ("body & declared # freezes the contract of %",
30027 N, Freeze_Id);
30028 SPARK_Msg_N
30029 ("\all constituents must be declared before body #",
30030 N);
30031
30032 -- A misplaced constituent is a critical error because
30033 -- pragma Refined_Depends or Refined_Global depends on
30034 -- the proper link between a state and a constituent.
30035 -- Stop the compilation, as this leads to a multitude
30036 -- of misleading cascaded errors.
30037
30038 raise Unrecoverable_Error;
30039 end if;
30040
30041 -- The constituent is a valid state or object
30042
30043 elsif Ekind (Constit_Id) in
30044 E_Abstract_State | E_Constant | E_Variable
30045 then
30046 Match_Constituent (Constit_Id);
30047
30048 -- The variable may eventually become a constituent of a
30049 -- single protected/task type. Record the reference now
30050 -- and verify its legality when analyzing the contract of
30051 -- the variable (SPARK RM 9.3).
30052
30053 if Ekind (Constit_Id) = E_Variable then
30054 Record_Possible_Part_Of_Reference
30055 (Var_Id => Constit_Id,
30056 Ref => Constit);
30057 end if;
30058
30059 -- Otherwise the constituent is illegal
30060
30061 else
30062 SPARK_Msg_NE
30063 ("constituent & must denote object or state",
30064 Constit, Constit_Id);
30065 end if;
30066
30067 -- The constituent is illegal
30068
30069 else
30070 SPARK_Msg_N ("malformed constituent", Constit);
30071 end if;
30072 end if;
30073 end Analyze_Constituent;
30074
30075 -----------------------------
30076 -- Check_External_Property --
30077 -----------------------------
30078
30079 procedure Check_External_Property
30080 (Prop_Nam : Name_Id;
30081 Enabled : Boolean;
30082 Constit : Entity_Id)
30083 is
30084 begin
30085 -- The property is missing in the declaration of the state, but
30086 -- a constituent is introducing it in the state refinement
30087 -- (SPARK RM 7.2.8(2)).
30088
30089 if not Enabled and then Present (Constit) then
30090 Error_Msg_Name_1 := Prop_Nam;
30091 Error_Msg_Name_2 := Chars (State_Id);
30092 SPARK_Msg_NE
30093 ("constituent & introduces external property % in refinement "
30094 & "of state %", State, Constit);
30095
30096 Error_Msg_Sloc := Sloc (State_Id);
30097 SPARK_Msg_N
30098 ("\property is missing in abstract state declaration #",
30099 State);
30100 end if;
30101 end Check_External_Property;
30102
30103 -----------------
30104 -- Match_State --
30105 -----------------
30106
30107 procedure Match_State is
30108 State_Elmt : Elmt_Id;
30109
30110 begin
30111 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
30112
30113 if Contains (Refined_States_Seen, State_Id) then
30114 SPARK_Msg_NE
30115 ("duplicate refinement of state &", State, State_Id);
30116 return;
30117 end if;
30118
30119 -- Inspect the abstract states defined in the package declaration
30120 -- looking for a match.
30121
30122 State_Elmt := First_Elmt (Available_States);
30123 while Present (State_Elmt) loop
30124
30125 -- A valid abstract state is being refined in the body. Add
30126 -- the state to the list of processed refined states to aid
30127 -- with the detection of duplicate refinements. Remove the
30128 -- state from Available_States to signal that it has already
30129 -- been refined.
30130
30131 if Node (State_Elmt) = State_Id then
30132 Append_New_Elmt (State_Id, Refined_States_Seen);
30133 Remove_Elmt (Available_States, State_Elmt);
30134 return;
30135 end if;
30136
30137 Next_Elmt (State_Elmt);
30138 end loop;
30139
30140 -- If we get here, we are refining a state that is not defined in
30141 -- the package declaration.
30142
30143 Error_Msg_Name_1 := Chars (Spec_Id);
30144 SPARK_Msg_NE
30145 ("cannot refine state, & is not defined in package %",
30146 State, State_Id);
30147 end Match_State;
30148
30149 --------------------------------
30150 -- Report_Unused_Constituents --
30151 --------------------------------
30152
30153 procedure Report_Unused_Constituents (Constits : Elist_Id) is
30154 Constit_Elmt : Elmt_Id;
30155 Constit_Id : Entity_Id;
30156 Posted : Boolean := False;
30157
30158 begin
30159 if Present (Constits) then
30160 Constit_Elmt := First_Elmt (Constits);
30161 while Present (Constit_Elmt) loop
30162 Constit_Id := Node (Constit_Elmt);
30163
30164 -- Generate an error message of the form:
30165
30166 -- state ... has unused Part_Of constituents
30167 -- abstract state ... defined at ...
30168 -- constant ... defined at ...
30169 -- variable ... defined at ...
30170
30171 if not Posted then
30172 Posted := True;
30173 SPARK_Msg_NE
30174 ("state & has unused Part_Of constituents",
30175 State, State_Id);
30176 end if;
30177
30178 Error_Msg_Sloc := Sloc (Constit_Id);
30179
30180 if Ekind (Constit_Id) = E_Abstract_State then
30181 SPARK_Msg_NE
30182 ("\abstract state & defined #", State, Constit_Id);
30183
30184 elsif Ekind (Constit_Id) = E_Constant then
30185 SPARK_Msg_NE
30186 ("\constant & defined #", State, Constit_Id);
30187
30188 else
30189 pragma Assert (Ekind (Constit_Id) = E_Variable);
30190 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
30191 end if;
30192
30193 Next_Elmt (Constit_Elmt);
30194 end loop;
30195 end if;
30196 end Report_Unused_Constituents;
30197
30198 -- Local declarations
30199
30200 Body_Ref : Node_Id;
30201 Body_Ref_Elmt : Elmt_Id;
30202 Constit : Node_Id;
30203 Extra_State : Node_Id;
30204
30205 -- Start of processing for Analyze_Refinement_Clause
30206
30207 begin
30208 -- A refinement clause appears as a component association where the
30209 -- sole choice is the state and the expressions are the constituents.
30210 -- This is a syntax error, always report.
30211
30212 if Nkind (Clause) /= N_Component_Association then
30213 Error_Msg_N ("malformed state refinement clause", Clause);
30214 return;
30215 end if;
30216
30217 -- Analyze the state name of a refinement clause
30218
30219 State := First (Choices (Clause));
30220
30221 Analyze (State);
30222 Resolve_State (State);
30223
30224 -- Ensure that the state name denotes a valid abstract state that is
30225 -- defined in the spec of the related package.
30226
30227 if Is_Entity_Name (State) then
30228 State_Id := Entity_Of (State);
30229
30230 -- When the abstract state is undefined, it appears as Any_Id. Do
30231 -- not continue with the analysis of the clause.
30232
30233 if State_Id = Any_Id then
30234 return;
30235
30236 -- Catch any attempts to re-refine a state or refine a state that
30237 -- is not defined in the package declaration.
30238
30239 elsif Ekind (State_Id) = E_Abstract_State then
30240 Match_State;
30241
30242 else
30243 SPARK_Msg_NE ("& must denote abstract state", State, State_Id);
30244 return;
30245 end if;
30246
30247 -- References to a state with visible refinement are illegal.
30248 -- When nested packages are involved, detecting such references is
30249 -- tricky because pragma Refined_State is analyzed later than the
30250 -- offending pragma Depends or Global. References that occur in
30251 -- such nested context are stored in a list. Emit errors for all
30252 -- references found in Body_References (SPARK RM 6.1.4(8)).
30253
30254 if Present (Body_References (State_Id)) then
30255 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
30256 while Present (Body_Ref_Elmt) loop
30257 Body_Ref := Node (Body_Ref_Elmt);
30258
30259 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
30260 Error_Msg_Sloc := Sloc (State);
30261 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
30262
30263 Next_Elmt (Body_Ref_Elmt);
30264 end loop;
30265 end if;
30266
30267 -- The state name is illegal. This is a syntax error, always report.
30268
30269 else
30270 Error_Msg_N ("malformed state name in refinement clause", State);
30271 return;
30272 end if;
30273
30274 -- A refinement clause may only refine one state at a time
30275
30276 Extra_State := Next (State);
30277
30278 if Present (Extra_State) then
30279 SPARK_Msg_N
30280 ("refinement clause cannot cover multiple states", Extra_State);
30281 end if;
30282
30283 -- Replicate the Part_Of constituents of the refined state because
30284 -- the algorithm will consume items.
30285
30286 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
30287
30288 -- Analyze all constituents of the refinement. Multiple constituents
30289 -- appear as an aggregate.
30290
30291 Constit := Expression (Clause);
30292
30293 if Nkind (Constit) = N_Aggregate then
30294 if Present (Component_Associations (Constit)) then
30295 SPARK_Msg_N
30296 ("constituents of refinement clause must appear in "
30297 & "positional form", Constit);
30298
30299 else pragma Assert (Present (Expressions (Constit)));
30300 Constit := First (Expressions (Constit));
30301 while Present (Constit) loop
30302 Analyze_Constituent (Constit);
30303 Next (Constit);
30304 end loop;
30305 end if;
30306
30307 -- Various forms of a single constituent. Note that these may include
30308 -- malformed constituents.
30309
30310 else
30311 Analyze_Constituent (Constit);
30312 end if;
30313
30314 -- Verify that external constituents do not introduce new external
30315 -- property in the state refinement (SPARK RM 7.2.8(2)).
30316
30317 if Is_External_State (State_Id) then
30318 Check_External_Property
30319 (Prop_Nam => Name_Async_Readers,
30320 Enabled => Async_Readers_Enabled (State_Id),
30321 Constit => AR_Constit);
30322
30323 Check_External_Property
30324 (Prop_Nam => Name_Async_Writers,
30325 Enabled => Async_Writers_Enabled (State_Id),
30326 Constit => AW_Constit);
30327
30328 Check_External_Property
30329 (Prop_Nam => Name_Effective_Reads,
30330 Enabled => Effective_Reads_Enabled (State_Id),
30331 Constit => ER_Constit);
30332
30333 Check_External_Property
30334 (Prop_Nam => Name_Effective_Writes,
30335 Enabled => Effective_Writes_Enabled (State_Id),
30336 Constit => EW_Constit);
30337
30338 -- When a refined state is not external, it should not have external
30339 -- constituents (SPARK RM 7.2.8(1)).
30340
30341 elsif External_Constit_Seen then
30342 SPARK_Msg_NE
30343 ("non-external state & cannot contain external constituents in "
30344 & "refinement", State, State_Id);
30345 end if;
30346
30347 -- Ensure that all Part_Of candidate constituents have been mentioned
30348 -- in the refinement clause.
30349
30350 Report_Unused_Constituents (Part_Of_Constits);
30351
30352 -- Avoid a cascading error reporting a missing refinement by adding a
30353 -- dummy constituent.
30354
30355 if No (Refinement_Constituents (State_Id)) then
30356 Set_Refinement_Constituents (State_Id, New_Elmt_List (Any_Id));
30357 end if;
30358
30359 -- At this point the refinement might be dummy, but must be
30360 -- well-formed, to prevent cascaded errors.
30361
30362 pragma Assert (Has_Null_Refinement (State_Id)
30363 xor
30364 Has_Non_Null_Refinement (State_Id));
30365 end Analyze_Refinement_Clause;
30366
30367 -----------------------------
30368 -- Report_Unrefined_States --
30369 -----------------------------
30370
30371 procedure Report_Unrefined_States (States : Elist_Id) is
30372 State_Elmt : Elmt_Id;
30373
30374 begin
30375 if Present (States) then
30376 State_Elmt := First_Elmt (States);
30377 while Present (State_Elmt) loop
30378 SPARK_Msg_N
30379 ("abstract state & must be refined", Node (State_Elmt));
30380
30381 Next_Elmt (State_Elmt);
30382 end loop;
30383 end if;
30384 end Report_Unrefined_States;
30385
30386 -- Local declarations
30387
30388 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
30389 Clause : Node_Id;
30390
30391 -- Start of processing for Analyze_Refined_State_In_Decl_Part
30392
30393 begin
30394 -- Do not analyze the pragma multiple times
30395
30396 if Is_Analyzed_Pragma (N) then
30397 return;
30398 end if;
30399
30400 -- Save the scenario for examination by the ABE Processing phase
30401
30402 Record_Elaboration_Scenario (N);
30403
30404 -- Replicate the abstract states declared by the package because the
30405 -- matching algorithm will consume states.
30406
30407 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
30408
30409 -- Gather all abstract states and objects declared in the visible
30410 -- state space of the package body. These items must be utilized as
30411 -- constituents in a state refinement.
30412
30413 Body_States := Collect_Body_States (Body_Id);
30414
30415 -- Multiple non-null state refinements appear as an aggregate
30416
30417 if Nkind (Clauses) = N_Aggregate then
30418 if Present (Expressions (Clauses)) then
30419 SPARK_Msg_N
30420 ("state refinements must appear as component associations",
30421 Clauses);
30422
30423 else pragma Assert (Present (Component_Associations (Clauses)));
30424 Clause := First (Component_Associations (Clauses));
30425 while Present (Clause) loop
30426 Analyze_Refinement_Clause (Clause);
30427 Next (Clause);
30428 end loop;
30429 end if;
30430
30431 -- Various forms of a single state refinement. Note that these may
30432 -- include malformed refinements.
30433
30434 else
30435 Analyze_Refinement_Clause (Clauses);
30436 end if;
30437
30438 -- List all abstract states that were left unrefined
30439
30440 Report_Unrefined_States (Available_States);
30441
30442 Set_Is_Analyzed_Pragma (N);
30443 end Analyze_Refined_State_In_Decl_Part;
30444
30445 ---------------------------------------------
30446 -- Analyze_Subprogram_Variant_In_Decl_Part --
30447 ---------------------------------------------
30448
30449 -- WARNING: This routine manages Ghost regions. Return statements must be
30450 -- replaced by gotos which jump to the end of the routine and restore the
30451 -- Ghost mode.
30452
30453 procedure Analyze_Subprogram_Variant_In_Decl_Part
30454 (N : Node_Id;
30455 Freeze_Id : Entity_Id := Empty)
30456 is
30457 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
30458 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
30459
30460 procedure Analyze_Variant (Variant : Node_Id);
30461 -- Verify the legality of a single contract case
30462
30463 ---------------------
30464 -- Analyze_Variant --
30465 ---------------------
30466
30467 procedure Analyze_Variant (Variant : Node_Id) is
30468 Direction : Node_Id;
30469 Expr : Node_Id;
30470 Errors : Nat;
30471 Extra_Direction : Node_Id;
30472
30473 begin
30474 if Nkind (Variant) /= N_Component_Association then
30475 Error_Msg_N ("wrong syntax in subprogram variant", Variant);
30476 return;
30477 end if;
30478
30479 Direction := First (Choices (Variant));
30480 Expr := Expression (Variant);
30481
30482 -- Each variant must have exactly one direction
30483
30484 Extra_Direction := Next (Direction);
30485
30486 if Present (Extra_Direction) then
30487 Error_Msg_N
30488 ("subprogram variant case must have exactly one direction",
30489 Extra_Direction);
30490 end if;
30491
30492 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
30493
30494 if Nkind (Direction) = N_Identifier then
30495 if Chars (Direction) not in Name_Decreases
30496 | Name_Increases
30497 | Name_Structural
30498 then
30499 Error_Msg_N ("wrong direction", Direction);
30500 end if;
30501 else
30502 Error_Msg_N ("wrong syntax", Direction);
30503 end if;
30504
30505 Errors := Serious_Errors_Detected;
30506
30507 -- Preanalyze_Assert_Expression, but without enforcing any of the two
30508 -- acceptable types.
30509
30510 Preanalyze_Assert_Expression (Expr);
30511
30512 -- Expression of a discrete type is allowed. Nothing more to check
30513 -- for structural variants.
30514
30515 if Is_Discrete_Type (Etype (Expr))
30516 or else Chars (Direction) = Name_Structural
30517 then
30518 null;
30519
30520 -- Expression of a Big_Integer type (or its ghost variant) is only
30521 -- allowed in Decreases clause.
30522
30523 elsif
30524 Is_RTE (Base_Type (Etype (Expr)), RE_Big_Integer)
30525 or else
30526 Is_RTE (Base_Type (Etype (Expr)), RO_GH_Big_Integer)
30527 then
30528 if Chars (Direction) = Name_Increases then
30529 Error_Msg_N
30530 ("Subprogram_Variant with Big_Integer can only decrease",
30531 Expr);
30532 end if;
30533
30534 -- Expression of other types is not allowed
30535
30536 else
30537 Error_Msg_N ("expected a discrete or Big_Integer type", Expr);
30538 end if;
30539
30540 -- Emit a clarification message when the variant expression
30541 -- contains at least one undefined reference, possibly due
30542 -- to contract freezing.
30543
30544 if Errors /= Serious_Errors_Detected
30545 and then Present (Freeze_Id)
30546 and then Has_Undefined_Reference (Expr)
30547 then
30548 Contract_Freeze_Error (Spec_Id, Freeze_Id);
30549 end if;
30550 end Analyze_Variant;
30551
30552 -- Local variables
30553
30554 Variants : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
30555
30556 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
30557 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
30558 -- Save the Ghost-related attributes to restore on exit
30559
30560 Variant : Node_Id;
30561 Restore_Scope : Boolean := False;
30562
30563 -- Start of processing for Analyze_Subprogram_Variant_In_Decl_Part
30564
30565 begin
30566 -- Do not analyze the pragma multiple times
30567
30568 if Is_Analyzed_Pragma (N) then
30569 return;
30570 end if;
30571
30572 -- Set the Ghost mode in effect from the pragma. Due to the delayed
30573 -- analysis of the pragma, the Ghost mode at point of declaration and
30574 -- point of analysis may not necessarily be the same. Use the mode in
30575 -- effect at the point of declaration.
30576
30577 Set_Ghost_Mode (N);
30578
30579 -- Single and multiple contract cases must appear in aggregate form. If
30580 -- this is not the case, then either the parser of the analysis of the
30581 -- pragma failed to produce an aggregate, e.g. when the contract is
30582 -- "null" or a "(null record)".
30583
30584 pragma Assert
30585 (if Nkind (Variants) = N_Aggregate
30586 then Null_Record_Present (Variants)
30587 xor (Present (Component_Associations (Variants))
30588 or
30589 Present (Expressions (Variants)))
30590 else Nkind (Variants) = N_Null);
30591
30592 -- Only "change_direction => discrete_expression" clauses are allowed
30593
30594 if Nkind (Variants) = N_Aggregate
30595 and then Present (Component_Associations (Variants))
30596 and then No (Expressions (Variants))
30597 then
30598
30599 -- Check that the expression is a proper aggregate (no parentheses)
30600
30601 if Paren_Count (Variants) /= 0 then
30602 Error_Msg_F -- CODEFIX
30603 ("redundant parentheses", Variants);
30604 end if;
30605
30606 -- Ensure that the formal parameters are visible when analyzing all
30607 -- clauses. This falls out of the general rule of aspects pertaining
30608 -- to subprogram declarations.
30609
30610 if not In_Open_Scopes (Spec_Id) then
30611 Restore_Scope := True;
30612 Push_Scope (Spec_Id);
30613
30614 if Is_Generic_Subprogram (Spec_Id) then
30615 Install_Generic_Formals (Spec_Id);
30616 else
30617 Install_Formals (Spec_Id);
30618 end if;
30619 end if;
30620
30621 Variant := First (Component_Associations (Variants));
30622 while Present (Variant) loop
30623 Analyze_Variant (Variant);
30624
30625 if Chars (First (Choices (Variant))) = Name_Structural
30626 and then List_Length (Component_Associations (Variants)) > 1
30627 then
30628 Error_Msg_N
30629 ("Structural variant shall be the only variant", Variant);
30630 end if;
30631
30632 Next (Variant);
30633 end loop;
30634
30635 if Restore_Scope then
30636 End_Scope;
30637 end if;
30638
30639 -- Currently it is not possible to inline Subprogram_Variant on a
30640 -- subprogram subject to pragma Inline_Always.
30641
30642 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
30643
30644 -- Otherwise the pragma is illegal
30645
30646 else
30647 Error_Msg_N ("wrong syntax for subprogram variant", N);
30648 end if;
30649
30650 Set_Is_Analyzed_Pragma (N);
30651
30652 Restore_Ghost_Region (Saved_GM, Saved_IGR);
30653 end Analyze_Subprogram_Variant_In_Decl_Part;
30654
30655 ------------------------------------
30656 -- Analyze_Test_Case_In_Decl_Part --
30657 ------------------------------------
30658
30659 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
30660 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
30661 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
30662
30663 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
30664 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
30665 -- denoted by Arg_Nam.
30666
30667 ------------------------------
30668 -- Preanalyze_Test_Case_Arg --
30669 ------------------------------
30670
30671 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
30672 Arg : Node_Id;
30673
30674 begin
30675 -- Preanalyze the original aspect argument for a generic subprogram
30676 -- to properly capture global references.
30677
30678 if Is_Generic_Subprogram (Spec_Id) then
30679 Arg :=
30680 Test_Case_Arg
30681 (Prag => N,
30682 Arg_Nam => Arg_Nam,
30683 From_Aspect => True);
30684
30685 if Present (Arg) then
30686 Preanalyze_Assert_Expression
30687 (Expression (Arg), Standard_Boolean);
30688 end if;
30689 end if;
30690
30691 Arg := Test_Case_Arg (N, Arg_Nam);
30692
30693 if Present (Arg) then
30694 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
30695 end if;
30696 end Preanalyze_Test_Case_Arg;
30697
30698 -- Local variables
30699
30700 Restore_Scope : Boolean := False;
30701
30702 -- Start of processing for Analyze_Test_Case_In_Decl_Part
30703
30704 begin
30705 -- Do not analyze the pragma multiple times
30706
30707 if Is_Analyzed_Pragma (N) then
30708 return;
30709 end if;
30710
30711 -- Ensure that the formal parameters are visible when analyzing all
30712 -- clauses. This falls out of the general rule of aspects pertaining
30713 -- to subprogram declarations.
30714
30715 if not In_Open_Scopes (Spec_Id) then
30716 Restore_Scope := True;
30717 Push_Scope (Spec_Id);
30718
30719 if Is_Generic_Subprogram (Spec_Id) then
30720 Install_Generic_Formals (Spec_Id);
30721 else
30722 Install_Formals (Spec_Id);
30723 end if;
30724 end if;
30725
30726 Preanalyze_Test_Case_Arg (Name_Requires);
30727 Preanalyze_Test_Case_Arg (Name_Ensures);
30728
30729 if Restore_Scope then
30730 End_Scope;
30731 end if;
30732
30733 -- Currently it is not possible to inline pre/postconditions on a
30734 -- subprogram subject to pragma Inline_Always.
30735
30736 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
30737
30738 Set_Is_Analyzed_Pragma (N);
30739 end Analyze_Test_Case_In_Decl_Part;
30740
30741 ----------------
30742 -- Appears_In --
30743 ----------------
30744
30745 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
30746 Elmt : Elmt_Id;
30747 Id : Entity_Id;
30748
30749 begin
30750 if Present (List) then
30751 Elmt := First_Elmt (List);
30752 while Present (Elmt) loop
30753 if Nkind (Node (Elmt)) = N_Defining_Identifier then
30754 Id := Node (Elmt);
30755 else
30756 Id := Entity_Of (Node (Elmt));
30757 end if;
30758
30759 if Id = Item_Id then
30760 return True;
30761 end if;
30762
30763 Next_Elmt (Elmt);
30764 end loop;
30765 end if;
30766
30767 return False;
30768 end Appears_In;
30769
30770 -----------------------------------
30771 -- Build_Pragma_Check_Equivalent --
30772 -----------------------------------
30773
30774 function Build_Pragma_Check_Equivalent
30775 (Prag : Node_Id;
30776 Subp_Id : Entity_Id := Empty;
30777 Inher_Id : Entity_Id := Empty;
30778 Keep_Pragma_Id : Boolean := False) return Node_Id
30779 is
30780 function Suppress_Reference (N : Node_Id) return Traverse_Result;
30781 -- Detect whether node N references a formal parameter subject to
30782 -- pragma Unreferenced. If this is the case, set Comes_From_Source
30783 -- to False to suppress the generation of a reference when analyzing
30784 -- N later on.
30785
30786 ------------------------
30787 -- Suppress_Reference --
30788 ------------------------
30789
30790 function Suppress_Reference (N : Node_Id) return Traverse_Result is
30791 Formal : Entity_Id;
30792
30793 begin
30794 if Is_Entity_Name (N) and then Present (Entity (N)) then
30795 Formal := Entity (N);
30796
30797 -- The formal parameter is subject to pragma Unreferenced. Prevent
30798 -- the generation of references by resetting the Comes_From_Source
30799 -- flag.
30800
30801 if Is_Formal (Formal)
30802 and then Has_Pragma_Unreferenced (Formal)
30803 then
30804 Set_Comes_From_Source (N, False);
30805 end if;
30806 end if;
30807
30808 return OK;
30809 end Suppress_Reference;
30810
30811 procedure Suppress_References is
30812 new Traverse_Proc (Suppress_Reference);
30813
30814 -- Local variables
30815
30816 Loc : constant Source_Ptr := Sloc (Prag);
30817 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
30818 Check_Prag : Node_Id;
30819 Msg_Arg : Node_Id;
30820 Nam : Name_Id;
30821
30822 -- Start of processing for Build_Pragma_Check_Equivalent
30823
30824 begin
30825 -- When the pre- or postcondition is inherited, map the formals of the
30826 -- inherited subprogram to those of the current subprogram. In addition,
30827 -- map primitive operations of the parent type into the corresponding
30828 -- primitive operations of the descendant.
30829
30830 if Present (Inher_Id) then
30831 pragma Assert (Present (Subp_Id));
30832
30833 Update_Primitives_Mapping (Inher_Id, Subp_Id);
30834
30835 -- Use generic machinery to copy inherited pragma, as if it were an
30836 -- instantiation, resetting source locations appropriately, so that
30837 -- expressions inside the inherited pragma use chained locations.
30838 -- This is used in particular in GNATprove to locate precisely
30839 -- messages on a given inherited pragma.
30840
30841 Set_Copied_Sloc_For_Inherited_Pragma
30842 (Unit_Declaration_Node (Subp_Id), Inher_Id);
30843 Check_Prag := New_Copy_Tree (Source => Prag);
30844
30845 -- Build the inherited class-wide condition
30846
30847 Build_Class_Wide_Expression
30848 (Pragma_Or_Expr => Check_Prag,
30849 Subp => Subp_Id,
30850 Par_Subp => Inher_Id,
30851 Adjust_Sloc => True);
30852
30853 -- If not an inherited condition simply copy the original pragma
30854
30855 else
30856 Check_Prag := New_Copy_Tree (Source => Prag);
30857 end if;
30858
30859 -- Mark the pragma as being internally generated and reset the Analyzed
30860 -- flag.
30861
30862 Set_Analyzed (Check_Prag, False);
30863 Set_Comes_From_Source (Check_Prag, False);
30864
30865 -- The tree of the original pragma may contain references to the
30866 -- formal parameters of the related subprogram. At the same time
30867 -- the corresponding body may mark the formals as unreferenced:
30868
30869 -- procedure Proc (Formal : ...)
30870 -- with Pre => Formal ...;
30871
30872 -- procedure Proc (Formal : ...) is
30873 -- pragma Unreferenced (Formal);
30874 -- ...
30875
30876 -- This creates problems because all pragma Check equivalents are
30877 -- analyzed at the end of the body declarations. Since all source
30878 -- references have already been accounted for, reset any references
30879 -- to such formals in the generated pragma Check equivalent.
30880
30881 Suppress_References (Check_Prag);
30882
30883 if Present (Corresponding_Aspect (Prag)) then
30884 Nam := Chars (Identifier (Corresponding_Aspect (Prag)));
30885 else
30886 Nam := Prag_Nam;
30887 end if;
30888
30889 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
30890 -- the copied pragma in the newly created pragma, convert the copy into
30891 -- pragma Check by correcting the name and adding a check_kind argument.
30892
30893 if not Keep_Pragma_Id then
30894 Set_Class_Present (Check_Prag, False);
30895
30896 Set_Pragma_Identifier
30897 (Check_Prag, Make_Identifier (Loc, Name_Check));
30898
30899 Prepend_To (Pragma_Argument_Associations (Check_Prag),
30900 Make_Pragma_Argument_Association (Loc,
30901 Expression => Make_Identifier (Loc, Nam)));
30902 end if;
30903
30904 -- Update the error message when the pragma is inherited
30905
30906 if Present (Inher_Id) then
30907 Msg_Arg := Last (Pragma_Argument_Associations (Check_Prag));
30908
30909 if Chars (Msg_Arg) = Name_Message then
30910 String_To_Name_Buffer (Strval (Expression (Msg_Arg)));
30911
30912 -- Insert "inherited" to improve the error message
30913
30914 if Name_Buffer (1 .. 8) = "failed p" then
30915 Insert_Str_In_Name_Buffer ("inherited ", 8);
30916 Set_Strval (Expression (Msg_Arg), String_From_Name_Buffer);
30917 end if;
30918 end if;
30919 end if;
30920
30921 return Check_Prag;
30922 end Build_Pragma_Check_Equivalent;
30923
30924 -----------------------------
30925 -- Check_Applicable_Policy --
30926 -----------------------------
30927
30928 procedure Check_Applicable_Policy (N : Node_Id) is
30929 PP : Node_Id;
30930 Policy : Name_Id;
30931
30932 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
30933
30934 begin
30935 -- No effect if not valid assertion kind name
30936
30937 if not Is_Valid_Assertion_Kind (Ename) then
30938 return;
30939 end if;
30940
30941 -- Loop through entries in check policy list
30942
30943 PP := Opt.Check_Policy_List;
30944 while Present (PP) loop
30945 declare
30946 PPA : constant List_Id := Pragma_Argument_Associations (PP);
30947 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
30948
30949 begin
30950 if Ename = Pnm
30951 or else Pnm = Name_Assertion
30952 or else (Pnm = Name_Statement_Assertions
30953 and then Ename in Name_Assert
30954 | Name_Assert_And_Cut
30955 | Name_Assume
30956 | Name_Loop_Invariant
30957 | Name_Loop_Variant)
30958 then
30959 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
30960
30961 case Policy is
30962 when Name_Ignore
30963 | Name_Off
30964 =>
30965 -- In CodePeer mode and GNATprove mode, we need to
30966 -- consider all assertions, unless they are disabled.
30967 -- Force Is_Checked on ignored assertions, in particular
30968 -- because transformations of the AST may depend on
30969 -- assertions being checked (e.g. the translation of
30970 -- attribute 'Loop_Entry).
30971
30972 if CodePeer_Mode or GNATprove_Mode then
30973 Set_Is_Checked (N, True);
30974 Set_Is_Ignored (N, False);
30975 else
30976 Set_Is_Checked (N, False);
30977 Set_Is_Ignored (N, True);
30978 end if;
30979
30980 when Name_Check
30981 | Name_On
30982 =>
30983 Set_Is_Checked (N, True);
30984 Set_Is_Ignored (N, False);
30985
30986 when Name_Disable =>
30987 Set_Is_Ignored (N, True);
30988 Set_Is_Checked (N, False);
30989 Set_Is_Disabled (N, True);
30990
30991 -- That should be exhaustive, the null here is a defence
30992 -- against a malformed tree from previous errors.
30993
30994 when others =>
30995 null;
30996 end case;
30997
30998 return;
30999 end if;
31000
31001 PP := Next_Pragma (PP);
31002 end;
31003 end loop;
31004
31005 -- If there are no specific entries that matched, then we let the
31006 -- setting of assertions govern. Note that this provides the needed
31007 -- compatibility with the RM for the cases of assertion, invariant,
31008 -- precondition, predicate, and postcondition. Note also that
31009 -- Assertions_Enabled is forced in CodePeer mode and GNATprove mode.
31010
31011 if Assertions_Enabled then
31012 Set_Is_Checked (N, True);
31013 Set_Is_Ignored (N, False);
31014 else
31015 Set_Is_Checked (N, False);
31016 Set_Is_Ignored (N, True);
31017 end if;
31018 end Check_Applicable_Policy;
31019
31020 -------------------------------
31021 -- Check_External_Properties --
31022 -------------------------------
31023
31024 procedure Check_External_Properties
31025 (Item : Node_Id;
31026 AR : Boolean;
31027 AW : Boolean;
31028 ER : Boolean;
31029 EW : Boolean)
31030 is
31031 type Properties is array (Positive range 1 .. 4) of Boolean;
31032 type Combinations is array (Positive range <>) of Properties;
31033 -- Arrays of Async_Readers, Async_Writers, Effective_Writes and
31034 -- Effective_Reads properties and their combinations, respectively.
31035
31036 Specified : constant Properties := (AR, AW, EW, ER);
31037 -- External properties, as given by the Item pragma
31038
31039 Allowed : constant Combinations :=
31040 (1 => (True, False, True, False),
31041 2 => (False, True, False, True),
31042 3 => (True, False, False, False),
31043 4 => (False, True, False, False),
31044 5 => (True, True, True, False),
31045 6 => (True, True, False, True),
31046 7 => (True, True, False, False),
31047 8 => (True, True, True, True));
31048 -- Allowed combinations, as listed in the SPARK RM 7.1.2(6) table
31049
31050 begin
31051 -- Check if the specified properties match any of the allowed
31052 -- combination; if not, then emit an error.
31053
31054 for J in Allowed'Range loop
31055 if Specified = Allowed (J) then
31056 return;
31057 end if;
31058 end loop;
31059
31060 SPARK_Msg_N
31061 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
31062 Item);
31063 end Check_External_Properties;
31064
31065 ----------------
31066 -- Check_Kind --
31067 ----------------
31068
31069 function Check_Kind (Nam : Name_Id) return Name_Id is
31070 PP : Node_Id;
31071
31072 begin
31073 -- Loop through entries in check policy list
31074
31075 PP := Opt.Check_Policy_List;
31076 while Present (PP) loop
31077 declare
31078 PPA : constant List_Id := Pragma_Argument_Associations (PP);
31079 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
31080
31081 begin
31082 if Nam = Pnm
31083 or else (Pnm = Name_Assertion
31084 and then Is_Valid_Assertion_Kind (Nam))
31085 or else (Pnm = Name_Statement_Assertions
31086 and then Nam in Name_Assert
31087 | Name_Assert_And_Cut
31088 | Name_Assume
31089 | Name_Loop_Invariant
31090 | Name_Loop_Variant)
31091 then
31092 case Chars (Get_Pragma_Arg (Last (PPA))) is
31093 when Name_Check
31094 | Name_On
31095 =>
31096 return Name_Check;
31097
31098 when Name_Ignore
31099 | Name_Off
31100 =>
31101 return Name_Ignore;
31102
31103 when Name_Disable =>
31104 return Name_Disable;
31105
31106 when others =>
31107 raise Program_Error;
31108 end case;
31109
31110 else
31111 PP := Next_Pragma (PP);
31112 end if;
31113 end;
31114 end loop;
31115
31116 -- If there are no specific entries that matched, then we let the
31117 -- setting of assertions govern. Note that this provides the needed
31118 -- compatibility with the RM for the cases of assertion, invariant,
31119 -- precondition, predicate, and postcondition.
31120
31121 if Assertions_Enabled then
31122 return Name_Check;
31123 else
31124 return Name_Ignore;
31125 end if;
31126 end Check_Kind;
31127
31128 ---------------------------
31129 -- Check_Missing_Part_Of --
31130 ---------------------------
31131
31132 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
31133 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
31134 -- Determine whether a package denoted by Pack_Id declares at least one
31135 -- visible state.
31136
31137 -----------------------
31138 -- Has_Visible_State --
31139 -----------------------
31140
31141 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
31142 Item_Id : Entity_Id;
31143
31144 begin
31145 -- Traverse the entity chain of the package trying to find at least
31146 -- one visible abstract state, variable or a package [instantiation]
31147 -- that declares a visible state.
31148
31149 Item_Id := First_Entity (Pack_Id);
31150 while Present (Item_Id)
31151 and then not In_Private_Part (Item_Id)
31152 loop
31153 -- Do not consider internally generated items
31154
31155 if not Comes_From_Source (Item_Id) then
31156 null;
31157
31158 -- Do not consider generic formals or their corresponding actuals
31159 -- because they are not part of a visible state. Note that both
31160 -- entities are marked as hidden.
31161
31162 elsif Is_Hidden (Item_Id) then
31163 null;
31164
31165 -- A visible state has been found. Note that constants are not
31166 -- considered here because it is not possible to determine whether
31167 -- they depend on variable input. This check is left to the SPARK
31168 -- prover.
31169
31170 elsif Ekind (Item_Id) in E_Abstract_State | E_Variable then
31171 return True;
31172
31173 -- Recursively peek into nested packages and instantiations
31174
31175 elsif Ekind (Item_Id) = E_Package
31176 and then Has_Visible_State (Item_Id)
31177 then
31178 return True;
31179 end if;
31180
31181 Next_Entity (Item_Id);
31182 end loop;
31183
31184 return False;
31185 end Has_Visible_State;
31186
31187 -- Local variables
31188
31189 Pack_Id : Entity_Id;
31190 Placement : State_Space_Kind;
31191
31192 -- Start of processing for Check_Missing_Part_Of
31193
31194 begin
31195 -- Do not consider abstract states, variables or package instantiations
31196 -- coming from an instance as those always inherit the Part_Of indicator
31197 -- of the instance itself.
31198
31199 if In_Instance then
31200 return;
31201
31202 -- Do not consider internally generated entities as these can never
31203 -- have a Part_Of indicator.
31204
31205 elsif not Comes_From_Source (Item_Id) then
31206 return;
31207
31208 -- Perform these checks only when SPARK_Mode is enabled as they will
31209 -- interfere with standard Ada rules and produce false positives.
31210
31211 elsif SPARK_Mode /= On then
31212 return;
31213
31214 -- Do not consider constants, because the compiler cannot accurately
31215 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
31216 -- act as a hidden state of a package.
31217
31218 elsif Ekind (Item_Id) = E_Constant then
31219 return;
31220 end if;
31221
31222 -- Find where the abstract state, variable or package instantiation
31223 -- lives with respect to the state space.
31224
31225 Find_Placement_In_State_Space
31226 (Item_Id => Item_Id,
31227 Placement => Placement,
31228 Pack_Id => Pack_Id);
31229
31230 -- Items that appear in a non-package construct (subprogram, block, etc)
31231 -- do not require a Part_Of indicator because they can never act as a
31232 -- hidden state.
31233
31234 if Placement = Not_In_Package then
31235 null;
31236
31237 -- An item declared in the body state space of a package always act as a
31238 -- constituent and does not need explicit Part_Of indicator.
31239
31240 elsif Placement = Body_State_Space then
31241 null;
31242
31243 -- In general an item declared in the visible state space of a package
31244 -- does not require a Part_Of indicator. The only exception is when the
31245 -- related package is a nongeneric private child unit, in which case
31246 -- Part_Of must denote a state in the parent unit or in one of its
31247 -- descendants.
31248
31249 elsif Placement = Visible_State_Space then
31250 if Is_Child_Unit (Pack_Id)
31251 and then not Is_Generic_Unit (Pack_Id)
31252 and then Is_Private_Descendant (Pack_Id)
31253 then
31254 -- A package instantiation does not need a Part_Of indicator when
31255 -- the related generic template has no visible state.
31256
31257 if Ekind (Item_Id) = E_Package
31258 and then Is_Generic_Instance (Item_Id)
31259 and then not Has_Visible_State (Item_Id)
31260 then
31261 null;
31262
31263 -- All other cases require Part_Of
31264
31265 else
31266 Error_Msg_N
31267 ("indicator Part_Of is required in this context "
31268 & "(SPARK RM 7.2.6(3))", Item_Id);
31269 Error_Msg_Name_1 := Chars (Pack_Id);
31270 Error_Msg_N
31271 ("\& is declared in the visible part of private child "
31272 & "unit %", Item_Id);
31273 end if;
31274 end if;
31275
31276 -- When the item appears in the private state space of a package, it
31277 -- must be a part of some state declared by the said package.
31278
31279 else pragma Assert (Placement = Private_State_Space);
31280
31281 -- The related package does not declare a state, the item cannot act
31282 -- as a Part_Of constituent.
31283
31284 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
31285 null;
31286
31287 -- A package instantiation does not need a Part_Of indicator when the
31288 -- related generic template has no visible state.
31289
31290 elsif Ekind (Item_Id) = E_Package
31291 and then Is_Generic_Instance (Item_Id)
31292 and then not Has_Visible_State (Item_Id)
31293 then
31294 null;
31295
31296 -- All other cases require Part_Of
31297
31298 else
31299 Error_Msg_Code := GEC_Required_Part_Of;
31300 Error_Msg_N
31301 ("indicator Part_Of is required in this context '[[]']",
31302 Item_Id);
31303 Error_Msg_Name_1 := Chars (Pack_Id);
31304 Error_Msg_N
31305 ("\& is declared in the private part of package %", Item_Id);
31306 end if;
31307 end if;
31308 end Check_Missing_Part_Of;
31309
31310 ---------------------------------------------------
31311 -- Check_Postcondition_Use_In_Inlined_Subprogram --
31312 ---------------------------------------------------
31313
31314 procedure Check_Postcondition_Use_In_Inlined_Subprogram
31315 (Prag : Node_Id;
31316 Spec_Id : Entity_Id)
31317 is
31318 begin
31319 if Warn_On_Redundant_Constructs
31320 and then Has_Pragma_Inline_Always (Spec_Id)
31321 and then Assertions_Enabled
31322 and then not Back_End_Inlining
31323 then
31324 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
31325
31326 if From_Aspect_Specification (Prag) then
31327 Error_Msg_NE
31328 ("aspect % not enforced on inlined subprogram &?r?",
31329 Corresponding_Aspect (Prag), Spec_Id);
31330 else
31331 Error_Msg_NE
31332 ("pragma % not enforced on inlined subprogram &?r?",
31333 Prag, Spec_Id);
31334 end if;
31335 end if;
31336 end Check_Postcondition_Use_In_Inlined_Subprogram;
31337
31338 -------------------------------------
31339 -- Check_State_And_Constituent_Use --
31340 -------------------------------------
31341
31342 procedure Check_State_And_Constituent_Use
31343 (States : Elist_Id;
31344 Constits : Elist_Id;
31345 Context : Node_Id)
31346 is
31347 Constit_Elmt : Elmt_Id;
31348 Constit_Id : Entity_Id;
31349 State_Id : Entity_Id;
31350
31351 begin
31352 -- Nothing to do if there are no states or constituents
31353
31354 if No (States) or else No (Constits) then
31355 return;
31356 end if;
31357
31358 -- Inspect the list of constituents and try to determine whether its
31359 -- encapsulating state is in list States.
31360
31361 Constit_Elmt := First_Elmt (Constits);
31362 while Present (Constit_Elmt) loop
31363 Constit_Id := Node (Constit_Elmt);
31364
31365 -- Determine whether the constituent is part of an encapsulating
31366 -- state that appears in the same context and if this is the case,
31367 -- emit an error (SPARK RM 7.2.6(7)).
31368
31369 State_Id := Find_Encapsulating_State (States, Constit_Id);
31370
31371 if Present (State_Id) then
31372 Error_Msg_Name_1 := Chars (Constit_Id);
31373 SPARK_Msg_NE
31374 ("cannot mention state & and its constituent % in the same "
31375 & "context", Context, State_Id);
31376 exit;
31377 end if;
31378
31379 Next_Elmt (Constit_Elmt);
31380 end loop;
31381 end Check_State_And_Constituent_Use;
31382
31383 ---------------------------------------------
31384 -- Collect_Inherited_Class_Wide_Conditions --
31385 ---------------------------------------------
31386
31387 procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is
31388 Parent_Subp : constant Entity_Id :=
31389 Ultimate_Alias (Overridden_Operation (Subp));
31390 -- The Overridden_Operation may itself be inherited and as such have no
31391 -- explicit contract.
31392
31393 Prags : constant Node_Id := Contract (Parent_Subp);
31394 In_Spec_Expr : Boolean := In_Spec_Expression;
31395 Installed : Boolean;
31396 Prag : Node_Id;
31397 New_Prag : Node_Id;
31398
31399 begin
31400 Installed := False;
31401
31402 -- Iterate over the contract of the overridden subprogram to find all
31403 -- inherited class-wide pre- and postconditions.
31404
31405 if Present (Prags) then
31406 Prag := Pre_Post_Conditions (Prags);
31407
31408 while Present (Prag) loop
31409 if Pragma_Name_Unmapped (Prag)
31410 in Name_Precondition | Name_Postcondition
31411 and then Class_Present (Prag)
31412 then
31413 -- The generated pragma must be analyzed in the context of
31414 -- the subprogram, to make its formals visible. In addition,
31415 -- we must inhibit freezing and full analysis because the
31416 -- controlling type of the subprogram is not frozen yet, and
31417 -- may have further primitives.
31418
31419 if not Installed then
31420 Installed := True;
31421 Push_Scope (Subp);
31422 Install_Formals (Subp);
31423 In_Spec_Expr := In_Spec_Expression;
31424 In_Spec_Expression := True;
31425 end if;
31426
31427 New_Prag :=
31428 Build_Pragma_Check_Equivalent
31429 (Prag, Subp, Parent_Subp, Keep_Pragma_Id => True);
31430
31431 Insert_After (Unit_Declaration_Node (Subp), New_Prag);
31432 Preanalyze (New_Prag);
31433
31434 -- Prevent further analysis in subsequent processing of the
31435 -- current list of declarations
31436
31437 Set_Analyzed (New_Prag);
31438 end if;
31439
31440 Prag := Next_Pragma (Prag);
31441 end loop;
31442
31443 if Installed then
31444 In_Spec_Expression := In_Spec_Expr;
31445 End_Scope;
31446 end if;
31447 end if;
31448 end Collect_Inherited_Class_Wide_Conditions;
31449
31450 ---------------------------------------
31451 -- Collect_Subprogram_Inputs_Outputs --
31452 ---------------------------------------
31453
31454 procedure Collect_Subprogram_Inputs_Outputs
31455 (Subp_Id : Entity_Id;
31456 Synthesize : Boolean := False;
31457 Subp_Inputs : in out Elist_Id;
31458 Subp_Outputs : in out Elist_Id;
31459 Global_Seen : out Boolean)
31460 is
31461 procedure Collect_Dependency_Clause (Clause : Node_Id);
31462 -- Collect all relevant items from a dependency clause
31463
31464 procedure Collect_Global_List
31465 (List : Node_Id;
31466 Mode : Name_Id := Name_Input);
31467 -- Collect all relevant items from a global list
31468
31469 -------------------------------
31470 -- Collect_Dependency_Clause --
31471 -------------------------------
31472
31473 procedure Collect_Dependency_Clause (Clause : Node_Id) is
31474 procedure Collect_Dependency_Item
31475 (Item : Node_Id;
31476 Is_Input : Boolean);
31477 -- Add an item to the proper subprogram input or output collection
31478
31479 -----------------------------
31480 -- Collect_Dependency_Item --
31481 -----------------------------
31482
31483 procedure Collect_Dependency_Item
31484 (Item : Node_Id;
31485 Is_Input : Boolean)
31486 is
31487 Extra : Node_Id;
31488
31489 begin
31490 -- Nothing to collect when the item is null
31491
31492 if Nkind (Item) = N_Null then
31493 null;
31494
31495 -- Ditto for attribute 'Result
31496
31497 elsif Is_Attribute_Result (Item) then
31498 null;
31499
31500 -- Multiple items appear as an aggregate
31501
31502 elsif Nkind (Item) = N_Aggregate then
31503 Extra := First (Expressions (Item));
31504 while Present (Extra) loop
31505 Collect_Dependency_Item (Extra, Is_Input);
31506 Next (Extra);
31507 end loop;
31508
31509 -- Otherwise this is a solitary item
31510
31511 else
31512 if Is_Input then
31513 Append_New_Elmt (Item, Subp_Inputs);
31514 else
31515 Append_New_Elmt (Item, Subp_Outputs);
31516 end if;
31517 end if;
31518 end Collect_Dependency_Item;
31519
31520 -- Start of processing for Collect_Dependency_Clause
31521
31522 begin
31523 if Nkind (Clause) = N_Null then
31524 null;
31525
31526 -- A dependency clause appears as component association
31527
31528 elsif Nkind (Clause) = N_Component_Association then
31529 Collect_Dependency_Item
31530 (Item => Expression (Clause),
31531 Is_Input => True);
31532
31533 Collect_Dependency_Item
31534 (Item => First (Choices (Clause)),
31535 Is_Input => False);
31536
31537 -- To accommodate partial decoration of disabled SPARK features, this
31538 -- routine may be called with illegal input. If this is the case, do
31539 -- not raise Program_Error.
31540
31541 else
31542 null;
31543 end if;
31544 end Collect_Dependency_Clause;
31545
31546 -------------------------
31547 -- Collect_Global_List --
31548 -------------------------
31549
31550 procedure Collect_Global_List
31551 (List : Node_Id;
31552 Mode : Name_Id := Name_Input)
31553 is
31554 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
31555 -- Add an item to the proper subprogram input or output collection
31556
31557 -------------------------
31558 -- Collect_Global_Item --
31559 -------------------------
31560
31561 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
31562 begin
31563 if Mode in Name_In_Out | Name_Input then
31564 Append_New_Elmt (Item, Subp_Inputs);
31565 end if;
31566
31567 if Mode in Name_In_Out | Name_Output then
31568 Append_New_Elmt (Item, Subp_Outputs);
31569 end if;
31570 end Collect_Global_Item;
31571
31572 -- Local variables
31573
31574 Assoc : Node_Id;
31575 Item : Node_Id;
31576
31577 -- Start of processing for Collect_Global_List
31578
31579 begin
31580 if Nkind (List) = N_Null then
31581 null;
31582
31583 -- Single global item declaration
31584
31585 elsif Nkind (List) in N_Expanded_Name
31586 | N_Identifier
31587 | N_Selected_Component
31588 then
31589 Collect_Global_Item (List, Mode);
31590
31591 -- Simple global list or moded global list declaration
31592
31593 elsif Nkind (List) = N_Aggregate then
31594 if Present (Expressions (List)) then
31595 Item := First (Expressions (List));
31596 while Present (Item) loop
31597 Collect_Global_Item (Item, Mode);
31598 Next (Item);
31599 end loop;
31600
31601 else
31602 Assoc := First (Component_Associations (List));
31603 while Present (Assoc) loop
31604 Collect_Global_List
31605 (List => Expression (Assoc),
31606 Mode => Chars (First (Choices (Assoc))));
31607 Next (Assoc);
31608 end loop;
31609 end if;
31610
31611 -- To accommodate partial decoration of disabled SPARK features, this
31612 -- routine may be called with illegal input. If this is the case, do
31613 -- not raise Program_Error.
31614
31615 else
31616 null;
31617 end if;
31618 end Collect_Global_List;
31619
31620 -- Local variables
31621
31622 Clause : Node_Id;
31623 Clauses : Node_Id;
31624 Depends : Node_Id;
31625 Formal : Entity_Id;
31626 Global : Node_Id;
31627 Spec_Id : Entity_Id := Empty;
31628 Subp_Decl : Node_Id;
31629 Typ : Entity_Id;
31630
31631 -- Start of processing for Collect_Subprogram_Inputs_Outputs
31632
31633 begin
31634 Global_Seen := False;
31635
31636 -- Process all formal parameters of entries, [generic] subprograms, and
31637 -- their bodies.
31638
31639 if Ekind (Subp_Id) in E_Entry
31640 | E_Entry_Family
31641 | E_Function
31642 | E_Generic_Function
31643 | E_Generic_Procedure
31644 | E_Procedure
31645 | E_Subprogram_Body
31646 then
31647 Subp_Decl := Unit_Declaration_Node (Subp_Id);
31648 Spec_Id := Unique_Defining_Entity (Subp_Decl);
31649
31650 -- Process all formal parameters
31651
31652 Formal := First_Formal (Spec_Id);
31653 while Present (Formal) loop
31654 if Ekind (Formal) in E_In_Out_Parameter | E_In_Parameter then
31655 Append_New_Elmt (Formal, Subp_Inputs);
31656
31657 -- IN parameters of procedures and protected entries can act as
31658 -- outputs when the related type is access-to-variable.
31659
31660 if Ekind (Formal) = E_In_Parameter
31661 and then (Ekind (Spec_Id) not in E_Function
31662 | E_Generic_Function
31663 or else Is_Function_With_Side_Effects (Spec_Id))
31664 and then Is_Access_Variable (Etype (Formal))
31665 then
31666 Append_New_Elmt (Formal, Subp_Outputs);
31667 end if;
31668 end if;
31669
31670 if Ekind (Formal) in E_In_Out_Parameter | E_Out_Parameter then
31671 Append_New_Elmt (Formal, Subp_Outputs);
31672
31673 -- OUT parameters can act as inputs when the related type is
31674 -- tagged, unconstrained array or unconstrained record.
31675
31676 if Ekind (Formal) = E_Out_Parameter
31677 and then Is_Unconstrained_Or_Tagged_Item (Formal)
31678 then
31679 Append_New_Elmt (Formal, Subp_Inputs);
31680 end if;
31681 end if;
31682
31683 Next_Formal (Formal);
31684 end loop;
31685
31686 -- Otherwise the input denotes a task type, a task body, or the
31687 -- anonymous object created for a single task type.
31688
31689 elsif Ekind (Subp_Id) in E_Task_Type | E_Task_Body
31690 or else Is_Single_Task_Object (Subp_Id)
31691 then
31692 Subp_Decl := Declaration_Node (Subp_Id);
31693 Spec_Id := Unique_Defining_Entity (Subp_Decl);
31694 end if;
31695
31696 -- When processing an entry, subprogram or task body, look for pragmas
31697 -- Refined_Depends and Refined_Global as they specify the inputs and
31698 -- outputs.
31699
31700 if Is_Entry_Body (Subp_Id)
31701 or else Ekind (Subp_Id) in E_Subprogram_Body | E_Task_Body
31702 then
31703 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
31704 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
31705
31706 -- Subprogram declaration or stand-alone body case, look for pragmas
31707 -- Depends and Global.
31708
31709 else
31710 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
31711 Global := Get_Pragma (Spec_Id, Pragma_Global);
31712 end if;
31713
31714 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
31715 -- because it provides finer granularity of inputs and outputs.
31716
31717 if Present (Global) then
31718 Global_Seen := True;
31719 Collect_Global_List (Expression (Get_Argument (Global, Spec_Id)));
31720
31721 -- When the related subprogram lacks pragma [Refined_]Global, fall back
31722 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
31723 -- the inputs and outputs from [Refined_]Depends.
31724
31725 elsif Synthesize and then Present (Depends) then
31726 Clauses := Expression (Get_Argument (Depends, Spec_Id));
31727
31728 -- Multiple dependency clauses appear as an aggregate
31729
31730 if Nkind (Clauses) = N_Aggregate then
31731 Clause := First (Component_Associations (Clauses));
31732 while Present (Clause) loop
31733 Collect_Dependency_Clause (Clause);
31734 Next (Clause);
31735 end loop;
31736
31737 -- Otherwise this is a single dependency clause
31738
31739 else
31740 Collect_Dependency_Clause (Clauses);
31741 end if;
31742 end if;
31743
31744 -- The current instance of a protected type acts as a formal parameter
31745 -- of mode IN for functions and IN OUT for entries and procedures
31746 -- (SPARK RM 6.1.4).
31747
31748 if Ekind (Scope (Spec_Id)) = E_Protected_Type then
31749 Typ := Scope (Spec_Id);
31750
31751 -- Use the anonymous object when the type is single protected
31752
31753 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
31754 Typ := Anonymous_Object (Typ);
31755 end if;
31756
31757 Append_New_Elmt (Typ, Subp_Inputs);
31758
31759 if Ekind (Spec_Id) in E_Entry | E_Entry_Family | E_Procedure then
31760 Append_New_Elmt (Typ, Subp_Outputs);
31761 end if;
31762
31763 -- The current instance of a task type acts as a formal parameter of
31764 -- mode IN OUT (SPARK RM 6.1.4).
31765
31766 elsif Ekind (Spec_Id) = E_Task_Type then
31767 Typ := Spec_Id;
31768
31769 -- Use the anonymous object when the type is single task
31770
31771 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
31772 Typ := Anonymous_Object (Typ);
31773 end if;
31774
31775 Append_New_Elmt (Typ, Subp_Inputs);
31776 Append_New_Elmt (Typ, Subp_Outputs);
31777
31778 elsif Is_Single_Task_Object (Spec_Id) then
31779 Append_New_Elmt (Spec_Id, Subp_Inputs);
31780 Append_New_Elmt (Spec_Id, Subp_Outputs);
31781 end if;
31782 end Collect_Subprogram_Inputs_Outputs;
31783
31784 ---------------------------
31785 -- Contract_Freeze_Error --
31786 ---------------------------
31787
31788 procedure Contract_Freeze_Error
31789 (Contract_Id : Entity_Id;
31790 Freeze_Id : Entity_Id)
31791 is
31792 begin
31793 Error_Msg_Name_1 := Chars (Contract_Id);
31794 Error_Msg_Sloc := Sloc (Freeze_Id);
31795
31796 SPARK_Msg_NE
31797 ("body & declared # freezes the contract of%", Contract_Id, Freeze_Id);
31798 SPARK_Msg_N
31799 ("\all contractual items must be declared before body #", Contract_Id);
31800 end Contract_Freeze_Error;
31801
31802 ---------------------------------
31803 -- Delay_Config_Pragma_Analyze --
31804 ---------------------------------
31805
31806 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
31807 begin
31808 return Pragma_Name_Unmapped (N)
31809 in Name_Interrupt_State | Name_Priority_Specific_Dispatching;
31810 end Delay_Config_Pragma_Analyze;
31811
31812 -----------------------
31813 -- Duplication_Error --
31814 -----------------------
31815
31816 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
31817 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
31818 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
31819
31820 begin
31821 Error_Msg_Sloc := Sloc (Prev);
31822 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
31823
31824 -- Emit a precise message to distinguish between source pragmas and
31825 -- pragmas generated from aspects. The ordering of the two pragmas is
31826 -- the following:
31827
31828 -- Prev -- ok
31829 -- Prag -- duplicate
31830
31831 -- No error is emitted when both pragmas come from aspects because this
31832 -- is already detected by the general aspect analysis mechanism.
31833
31834 if Prag_From_Asp and Prev_From_Asp then
31835 null;
31836 elsif Prag_From_Asp then
31837 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
31838 elsif Prev_From_Asp then
31839 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
31840 else
31841 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
31842 end if;
31843 end Duplication_Error;
31844
31845 ------------------------------
31846 -- Find_Encapsulating_State --
31847 ------------------------------
31848
31849 function Find_Encapsulating_State
31850 (States : Elist_Id;
31851 Constit_Id : Entity_Id) return Entity_Id
31852 is
31853 State_Id : Entity_Id;
31854
31855 begin
31856 -- Since a constituent may be part of a larger constituent set, climb
31857 -- the encapsulating state chain looking for a state that appears in
31858 -- States.
31859
31860 State_Id := Encapsulating_State (Constit_Id);
31861 while Present (State_Id) loop
31862 if Contains (States, State_Id) then
31863 return State_Id;
31864 end if;
31865
31866 State_Id := Encapsulating_State (State_Id);
31867 end loop;
31868
31869 return Empty;
31870 end Find_Encapsulating_State;
31871
31872 --------------------------
31873 -- Find_Related_Context --
31874 --------------------------
31875
31876 function Find_Related_Context
31877 (Prag : Node_Id;
31878 Do_Checks : Boolean := False) return Node_Id
31879 is
31880 Stmt : Node_Id;
31881
31882 begin
31883 -- If the pragma comes from an aspect on a compilation unit that is a
31884 -- package instance, then return the original package instantiation
31885 -- node.
31886
31887 if Nkind (Parent (Prag)) = N_Compilation_Unit_Aux then
31888 return
31889 Get_Unit_Instantiation_Node
31890 (Defining_Entity (Unit (Enclosing_Comp_Unit_Node (Prag))));
31891 end if;
31892
31893 Stmt := Prev (Prag);
31894 while Present (Stmt) loop
31895
31896 -- Skip prior pragmas, but check for duplicates
31897
31898 if Nkind (Stmt) = N_Pragma then
31899 if Do_Checks
31900 and then Pragma_Name (Stmt) = Pragma_Name (Prag)
31901 then
31902 Duplication_Error
31903 (Prag => Prag,
31904 Prev => Stmt);
31905 end if;
31906
31907 -- Skip internally generated code
31908
31909 elsif not Comes_From_Source (Stmt)
31910 and then not Comes_From_Source (Original_Node (Stmt))
31911 then
31912
31913 -- The anonymous object created for a single concurrent type is a
31914 -- suitable context.
31915
31916 if Nkind (Stmt) = N_Object_Declaration
31917 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
31918 then
31919 return Stmt;
31920 end if;
31921
31922 -- Return the current source construct
31923
31924 else
31925 return Stmt;
31926 end if;
31927
31928 Prev (Stmt);
31929 end loop;
31930
31931 return Empty;
31932 end Find_Related_Context;
31933
31934 --------------------------------------
31935 -- Find_Related_Declaration_Or_Body --
31936 --------------------------------------
31937
31938 function Find_Related_Declaration_Or_Body
31939 (Prag : Node_Id;
31940 Do_Checks : Boolean := False) return Node_Id
31941 is
31942 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
31943
31944 procedure Expression_Function_Error;
31945 -- Emit an error concerning pragma Prag that illegaly applies to an
31946 -- expression function.
31947
31948 -------------------------------
31949 -- Expression_Function_Error --
31950 -------------------------------
31951
31952 procedure Expression_Function_Error is
31953 begin
31954 Error_Msg_Name_1 := Prag_Nam;
31955
31956 -- Emit a precise message to distinguish between source pragmas and
31957 -- pragmas generated from aspects.
31958
31959 if From_Aspect_Specification (Prag) then
31960 Error_Msg_N
31961 ("aspect % cannot apply to a standalone expression function",
31962 Prag);
31963 else
31964 Error_Msg_N
31965 ("pragma % cannot apply to a standalone expression function",
31966 Prag);
31967 end if;
31968 end Expression_Function_Error;
31969
31970 -- Local variables
31971
31972 Context : constant Node_Id := Parent (Prag);
31973 Stmt : Node_Id;
31974
31975 Look_For_Body : constant Boolean :=
31976 Prag_Nam in Name_Refined_Depends
31977 | Name_Refined_Global
31978 | Name_Refined_Post
31979 | Name_Refined_State;
31980 -- Refinement pragmas must be associated with a subprogram body [stub]
31981
31982 -- Start of processing for Find_Related_Declaration_Or_Body
31983
31984 begin
31985 Stmt := Prev (Prag);
31986 while Present (Stmt) loop
31987
31988 -- Skip prior pragmas, but check for duplicates. Pragmas produced
31989 -- by splitting a complex pre/postcondition are not considered to
31990 -- be duplicates.
31991
31992 if Nkind (Stmt) = N_Pragma then
31993 if Do_Checks
31994 and then not Split_PPC (Stmt)
31995 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
31996 then
31997 Duplication_Error
31998 (Prag => Prag,
31999 Prev => Stmt);
32000 end if;
32001
32002 -- Emit an error when a refinement pragma appears on an expression
32003 -- function without a completion.
32004
32005 elsif Do_Checks
32006 and then Look_For_Body
32007 and then Nkind (Stmt) = N_Subprogram_Declaration
32008 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
32009 and then not Has_Completion (Defining_Entity (Stmt))
32010 then
32011 Expression_Function_Error;
32012 return Empty;
32013
32014 -- The refinement pragma applies to a subprogram body stub
32015
32016 elsif Look_For_Body
32017 and then Nkind (Stmt) = N_Subprogram_Body_Stub
32018 then
32019 return Stmt;
32020
32021 -- Skip internally generated code
32022
32023 elsif not Comes_From_Source (Stmt) then
32024
32025 -- The anonymous object created for a single concurrent type is a
32026 -- suitable context.
32027
32028 if Nkind (Stmt) = N_Object_Declaration
32029 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
32030 then
32031 return Stmt;
32032
32033 elsif Nkind (Stmt) = N_Subprogram_Declaration then
32034
32035 -- The subprogram declaration is an internally generated spec
32036 -- for an expression function.
32037
32038 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
32039 return Stmt;
32040
32041 -- The subprogram declaration is an internally generated spec
32042 -- for a stand-alone subprogram body declared inside a
32043 -- protected body.
32044
32045 elsif Present (Corresponding_Body (Stmt))
32046 and then Comes_From_Source (Corresponding_Body (Stmt))
32047 and then Is_Protected_Type (Current_Scope)
32048 then
32049 return Stmt;
32050
32051 -- The subprogram is actually an instance housed within an
32052 -- anonymous wrapper package.
32053
32054 elsif Present (Generic_Parent (Specification (Stmt))) then
32055 return Stmt;
32056
32057 -- Ada 2022: contract on formal subprogram or on generated
32058 -- Access_Subprogram_Wrapper, which appears after the related
32059 -- Access_Subprogram declaration.
32060
32061 elsif Is_Generic_Actual_Subprogram (Defining_Entity (Stmt))
32062 and then Ada_Version >= Ada_2022
32063 then
32064 return Stmt;
32065
32066 elsif Is_Access_Subprogram_Wrapper (Defining_Entity (Stmt))
32067 and then Ada_Version >= Ada_2022
32068 then
32069 return Stmt;
32070 end if;
32071 end if;
32072
32073 -- Return the current construct which is either a subprogram body,
32074 -- a subprogram declaration or is illegal.
32075
32076 else
32077 return Stmt;
32078 end if;
32079
32080 Prev (Stmt);
32081 end loop;
32082
32083 -- If we fall through, then the pragma was either the first declaration
32084 -- or it was preceded by other pragmas and no source constructs.
32085
32086 -- The pragma is associated with a library-level subprogram
32087
32088 if Nkind (Context) = N_Compilation_Unit_Aux then
32089 return Unit (Parent (Context));
32090
32091 -- The pragma appears inside the declarations of an entry body
32092
32093 elsif Nkind (Context) = N_Entry_Body then
32094 return Context;
32095
32096 -- The pragma appears inside the statements of a subprogram body at
32097 -- some nested level.
32098
32099 elsif Is_Statement (Context)
32100 and then Present (Enclosing_HSS (Context))
32101 then
32102 return Parent (Enclosing_HSS (Context));
32103
32104 -- The pragma appears directly in the statements of a subprogram body
32105
32106 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
32107 return Parent (Context);
32108
32109 -- The pragma appears inside the declarative part of a package body
32110
32111 elsif Nkind (Context) = N_Package_Body then
32112 return Context;
32113
32114 -- The pragma appears inside the declarative part of a subprogram body
32115
32116 elsif Nkind (Context) = N_Subprogram_Body then
32117 return Context;
32118
32119 -- The pragma appears inside the declarative part of a task body
32120
32121 elsif Nkind (Context) = N_Task_Body then
32122 return Context;
32123
32124 -- The pragma appears inside the visible part of a package specification
32125
32126 elsif Nkind (Context) = N_Package_Specification then
32127 return Parent (Context);
32128
32129 -- The pragma is a byproduct of aspect expansion, return the related
32130 -- context of the original aspect. This case has a lower priority as
32131 -- the above circuitry pinpoints precisely the related context.
32132
32133 elsif Present (Corresponding_Aspect (Prag)) then
32134 return Parent (Corresponding_Aspect (Prag));
32135
32136 -- No candidate subprogram [body] found
32137
32138 else
32139 return Empty;
32140 end if;
32141 end Find_Related_Declaration_Or_Body;
32142
32143 ----------------------------------
32144 -- Find_Related_Package_Or_Body --
32145 ----------------------------------
32146
32147 function Find_Related_Package_Or_Body
32148 (Prag : Node_Id;
32149 Do_Checks : Boolean := False) return Node_Id
32150 is
32151 Context : constant Node_Id := Parent (Prag);
32152 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
32153 Stmt : Node_Id;
32154
32155 begin
32156 Stmt := Prev (Prag);
32157 while Present (Stmt) loop
32158
32159 -- Skip prior pragmas, but check for duplicates
32160
32161 if Nkind (Stmt) = N_Pragma then
32162 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
32163 Duplication_Error
32164 (Prag => Prag,
32165 Prev => Stmt);
32166 end if;
32167
32168 -- Skip internally generated code
32169
32170 elsif not Comes_From_Source (Stmt) then
32171 if Nkind (Stmt) = N_Subprogram_Declaration then
32172
32173 -- The subprogram declaration is an internally generated spec
32174 -- for an expression function.
32175
32176 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
32177 return Stmt;
32178
32179 -- The subprogram is actually an instance housed within an
32180 -- anonymous wrapper package.
32181
32182 elsif Present (Generic_Parent (Specification (Stmt))) then
32183 return Stmt;
32184 end if;
32185 end if;
32186
32187 -- Return the current source construct which is illegal
32188
32189 else
32190 return Stmt;
32191 end if;
32192
32193 Prev (Stmt);
32194 end loop;
32195
32196 -- If we fall through, then the pragma was either the first declaration
32197 -- or it was preceded by other pragmas and no source constructs.
32198
32199 -- The pragma is associated with a package. The immediate context in
32200 -- this case is the specification of the package.
32201
32202 if Nkind (Context) = N_Package_Specification then
32203 return Parent (Context);
32204
32205 -- The pragma appears in the declarations of a package body
32206
32207 elsif Nkind (Context) = N_Package_Body then
32208 return Context;
32209
32210 -- The pragma appears in the statements of a package body
32211
32212 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
32213 and then Nkind (Parent (Context)) = N_Package_Body
32214 then
32215 return Parent (Context);
32216
32217 -- The pragma is a byproduct of aspect expansion, return the related
32218 -- context of the original aspect. This case has a lower priority as
32219 -- the above circuitry pinpoints precisely the related context.
32220
32221 elsif Present (Corresponding_Aspect (Prag)) then
32222 return Parent (Corresponding_Aspect (Prag));
32223
32224 -- No candidate package [body] found
32225
32226 else
32227 return Empty;
32228 end if;
32229 end Find_Related_Package_Or_Body;
32230
32231 ------------------
32232 -- Get_Argument --
32233 ------------------
32234
32235 function Get_Argument
32236 (Prag : Node_Id;
32237 Context_Id : Entity_Id := Empty) return Node_Id
32238 is
32239 Args : constant List_Id := Pragma_Argument_Associations (Prag);
32240
32241 begin
32242 -- Use the expression of the original aspect when analyzing the template
32243 -- of a generic unit. In both cases the aspect's tree must be decorated
32244 -- to save the global references in the generic context.
32245
32246 if From_Aspect_Specification (Prag)
32247 and then Present (Context_Id)
32248 and then
32249 Is_Generic_Declaration_Or_Body (Unit_Declaration_Node (Context_Id))
32250 then
32251 return Corresponding_Aspect (Prag);
32252
32253 -- Otherwise use the expression of the pragma
32254
32255 elsif Present (Args) then
32256 return First (Args);
32257
32258 else
32259 return Empty;
32260 end if;
32261 end Get_Argument;
32262
32263 -------------------------
32264 -- Get_Base_Subprogram --
32265 -------------------------
32266
32267 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
32268 begin
32269 -- Follow subprogram renaming chain
32270
32271 if Is_Subprogram (Def_Id)
32272 and then Parent_Kind (Declaration_Node (Def_Id)) =
32273 N_Subprogram_Renaming_Declaration
32274 and then Present (Alias (Def_Id))
32275 then
32276 return Alias (Def_Id);
32277 else
32278 return Def_Id;
32279 end if;
32280 end Get_Base_Subprogram;
32281
32282 -------------------------
32283 -- Get_SPARK_Mode_Type --
32284 -------------------------
32285
32286 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
32287 begin
32288 case N is
32289 when Name_Auto =>
32290 return None;
32291 when Name_On =>
32292 return On;
32293 when Name_Off =>
32294 return Off;
32295
32296 -- Any other argument is illegal. Assume that no SPARK mode applies
32297 -- to avoid potential cascaded errors.
32298
32299 when others =>
32300 return None;
32301 end case;
32302 end Get_SPARK_Mode_Type;
32303
32304 ------------------------------------
32305 -- Get_SPARK_Mode_From_Annotation --
32306 ------------------------------------
32307
32308 function Get_SPARK_Mode_From_Annotation
32309 (N : Node_Id) return SPARK_Mode_Type
32310 is
32311 Mode : Node_Id;
32312
32313 begin
32314 if Nkind (N) = N_Aspect_Specification then
32315 Mode := Expression (N);
32316
32317 else pragma Assert (Nkind (N) = N_Pragma);
32318 Mode := First (Pragma_Argument_Associations (N));
32319
32320 if Present (Mode) then
32321 Mode := Get_Pragma_Arg (Mode);
32322 end if;
32323 end if;
32324
32325 -- Aspect or pragma SPARK_Mode specifies an explicit mode
32326
32327 if Present (Mode) then
32328 if Nkind (Mode) = N_Identifier then
32329 return Get_SPARK_Mode_Type (Chars (Mode));
32330
32331 -- In case of a malformed aspect or pragma, return the default None
32332
32333 else
32334 return None;
32335 end if;
32336
32337 -- Otherwise the lack of an expression defaults SPARK_Mode to On
32338
32339 else
32340 return On;
32341 end if;
32342 end Get_SPARK_Mode_From_Annotation;
32343
32344 ---------------------------
32345 -- Has_Extra_Parentheses --
32346 ---------------------------
32347
32348 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
32349 Expr : Node_Id;
32350
32351 begin
32352 -- The aggregate should not have an expression list because a clause
32353 -- is always interpreted as a component association. The only way an
32354 -- expression list can sneak in is by adding extra parentheses around
32355 -- the individual clauses:
32356
32357 -- Depends (Output => Input) -- proper form
32358 -- Depends ((Output => Input)) -- extra parentheses
32359
32360 -- Since the extra parentheses are not allowed by the syntax of the
32361 -- pragma, flag them now to avoid emitting misleading errors down the
32362 -- line.
32363
32364 if Nkind (Clause) = N_Aggregate
32365 and then Present (Expressions (Clause))
32366 then
32367 Expr := First (Expressions (Clause));
32368 while Present (Expr) loop
32369
32370 -- A dependency clause surrounded by extra parentheses appears
32371 -- as an aggregate of component associations with an optional
32372 -- Paren_Count set.
32373
32374 if Nkind (Expr) = N_Aggregate
32375 and then Present (Component_Associations (Expr))
32376 then
32377 SPARK_Msg_N
32378 ("dependency clause contains extra parentheses", Expr);
32379
32380 -- Otherwise the expression is a malformed construct
32381
32382 else
32383 SPARK_Msg_N ("malformed dependency clause", Expr);
32384 end if;
32385
32386 Next (Expr);
32387 end loop;
32388
32389 return True;
32390 end if;
32391
32392 return False;
32393 end Has_Extra_Parentheses;
32394
32395 ----------------
32396 -- Initialize --
32397 ----------------
32398
32399 procedure Initialize is
32400 begin
32401 Externals.Init;
32402 Compile_Time_Warnings_Errors.Init;
32403 end Initialize;
32404
32405 --------
32406 -- ip --
32407 --------
32408
32409 procedure ip is
32410 begin
32411 Dummy := Dummy + 1;
32412 end ip;
32413
32414 -----------------------------
32415 -- Is_Config_Static_String --
32416 -----------------------------
32417
32418 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
32419
32420 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
32421 -- This is an internal recursive function that is just like the outer
32422 -- function except that it adds the string to the name buffer rather
32423 -- than placing the string in the name buffer.
32424
32425 ------------------------------
32426 -- Add_Config_Static_String --
32427 ------------------------------
32428
32429 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
32430 N : Node_Id;
32431 C : Char_Code;
32432
32433 begin
32434 N := Arg;
32435
32436 if Nkind (N) = N_Op_Concat then
32437 if Add_Config_Static_String (Left_Opnd (N)) then
32438 N := Right_Opnd (N);
32439 else
32440 return False;
32441 end if;
32442 end if;
32443
32444 if Nkind (N) /= N_String_Literal then
32445 Error_Msg_N ("string literal expected for pragma argument", N);
32446 return False;
32447
32448 else
32449 for J in 1 .. String_Length (Strval (N)) loop
32450 C := Get_String_Char (Strval (N), J);
32451
32452 if not In_Character_Range (C) then
32453 Error_Msg
32454 ("string literal contains invalid wide character",
32455 Sloc (N) + 1 + Source_Ptr (J));
32456 return False;
32457 end if;
32458
32459 Add_Char_To_Name_Buffer (Get_Character (C));
32460 end loop;
32461 end if;
32462
32463 return True;
32464 end Add_Config_Static_String;
32465
32466 -- Start of processing for Is_Config_Static_String
32467
32468 begin
32469 Name_Len := 0;
32470
32471 return Add_Config_Static_String (Arg);
32472 end Is_Config_Static_String;
32473
32474 -------------------------------
32475 -- Is_Elaboration_SPARK_Mode --
32476 -------------------------------
32477
32478 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
32479 begin
32480 pragma Assert
32481 (Nkind (N) = N_Pragma
32482 and then Pragma_Name (N) = Name_SPARK_Mode
32483 and then Is_List_Member (N));
32484
32485 -- Pragma SPARK_Mode affects the elaboration of a package body when it
32486 -- appears in the statement part of the body.
32487
32488 return
32489 Present (Parent (N))
32490 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
32491 and then List_Containing (N) = Statements (Parent (N))
32492 and then Present (Parent (Parent (N)))
32493 and then Nkind (Parent (Parent (N))) = N_Package_Body;
32494 end Is_Elaboration_SPARK_Mode;
32495
32496 -----------------------
32497 -- Is_Enabled_Pragma --
32498 -----------------------
32499
32500 function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is
32501 Arg : Node_Id;
32502
32503 begin
32504 if Present (Prag) then
32505 Arg := First (Pragma_Argument_Associations (Prag));
32506
32507 if Present (Arg) then
32508 return Is_True (Expr_Value (Get_Pragma_Arg (Arg)));
32509
32510 -- The lack of a Boolean argument automatically enables the pragma
32511
32512 else
32513 return True;
32514 end if;
32515
32516 -- The pragma is missing, therefore it is not enabled
32517
32518 else
32519 return False;
32520 end if;
32521 end Is_Enabled_Pragma;
32522
32523 -----------------------------------------
32524 -- Is_Non_Significant_Pragma_Reference --
32525 -----------------------------------------
32526
32527 -- This function makes use of the following static table which indicates
32528 -- whether appearance of some name in a given pragma is to be considered
32529 -- as a reference for the purposes of warnings about unreferenced objects.
32530
32531 -- -1 indicates that appearance in any argument is significant
32532 -- 0 indicates that appearance in any argument is not significant
32533 -- +n indicates that appearance as argument n is significant, but all
32534 -- other arguments are not significant
32535 -- 9n arguments from n on are significant, before n insignificant
32536
32537 Sig_Flags : constant array (Pragma_Id) of Int :=
32538 (Pragma_Abort_Defer => -1,
32539 Pragma_Abstract_State => -1,
32540 Pragma_Ada_83 => -1,
32541 Pragma_Ada_95 => -1,
32542 Pragma_Ada_05 => -1,
32543 Pragma_Ada_2005 => -1,
32544 Pragma_Ada_12 => -1,
32545 Pragma_Ada_2012 => -1,
32546 Pragma_Ada_2022 => -1,
32547 Pragma_Aggregate_Individually_Assign => 0,
32548 Pragma_All_Calls_Remote => -1,
32549 Pragma_Allow_Integer_Address => -1,
32550 Pragma_Always_Terminates => -1,
32551 Pragma_Annotate => 93,
32552 Pragma_Assert => -1,
32553 Pragma_Assert_And_Cut => -1,
32554 Pragma_Assertion_Policy => 0,
32555 Pragma_Assume => -1,
32556 Pragma_Assume_No_Invalid_Values => 0,
32557 Pragma_Async_Readers => 0,
32558 Pragma_Async_Writers => 0,
32559 Pragma_Asynchronous => 0,
32560 Pragma_Atomic => 0,
32561 Pragma_Atomic_Components => 0,
32562 Pragma_Attach_Handler => -1,
32563 Pragma_Attribute_Definition => 92,
32564 Pragma_Check => -1,
32565 Pragma_Check_Float_Overflow => 0,
32566 Pragma_Check_Name => 0,
32567 Pragma_Check_Policy => 0,
32568 Pragma_CPP_Class => 0,
32569 Pragma_CPP_Constructor => 0,
32570 Pragma_CPP_Virtual => 0,
32571 Pragma_CPP_Vtable => 0,
32572 Pragma_CPU => -1,
32573 Pragma_C_Pass_By_Copy => 0,
32574 Pragma_Comment => -1,
32575 Pragma_Common_Object => 0,
32576 Pragma_CUDA_Device => -1,
32577 Pragma_CUDA_Execute => -1,
32578 Pragma_CUDA_Global => -1,
32579 Pragma_Compile_Time_Error => -1,
32580 Pragma_Compile_Time_Warning => -1,
32581 Pragma_Complete_Representation => 0,
32582 Pragma_Complex_Representation => 0,
32583 Pragma_Component_Alignment => 0,
32584 Pragma_Constant_After_Elaboration => 0,
32585 Pragma_Contract_Cases => -1,
32586 Pragma_Controlled => 0,
32587 Pragma_Convention => 0,
32588 Pragma_Convention_Identifier => 0,
32589 Pragma_Deadline_Floor => -1,
32590 Pragma_Debug => -1,
32591 Pragma_Debug_Policy => 0,
32592 Pragma_Default_Initial_Condition => -1,
32593 Pragma_Default_Scalar_Storage_Order => 0,
32594 Pragma_Default_Storage_Pool => 0,
32595 Pragma_Depends => -1,
32596 Pragma_Detect_Blocking => 0,
32597 Pragma_Disable_Atomic_Synchronization => 0,
32598 Pragma_Discard_Names => 0,
32599 Pragma_Dispatching_Domain => -1,
32600 Pragma_Effective_Reads => 0,
32601 Pragma_Effective_Writes => 0,
32602 Pragma_Elaborate => 0,
32603 Pragma_Elaborate_All => 0,
32604 Pragma_Elaborate_Body => 0,
32605 Pragma_Elaboration_Checks => 0,
32606 Pragma_Eliminate => 0,
32607 Pragma_Enable_Atomic_Synchronization => 0,
32608 Pragma_Exceptional_Cases => -1,
32609 Pragma_Export => -1,
32610 Pragma_Export_Function => -1,
32611 Pragma_Export_Object => -1,
32612 Pragma_Export_Procedure => -1,
32613 Pragma_Export_Valued_Procedure => -1,
32614 Pragma_Extend_System => -1,
32615 Pragma_Extensions_Allowed => 0,
32616 Pragma_Extensions_Visible => 0,
32617 Pragma_External => -1,
32618 Pragma_External_Name_Casing => 0,
32619 Pragma_Fast_Math => 0,
32620 Pragma_Favor_Top_Level => 0,
32621 Pragma_Finalize_Storage_Only => 0,
32622 Pragma_Ghost => 0,
32623 Pragma_Global => -1,
32624 Pragma_GNAT_Annotate => 93,
32625 Pragma_Ident => -1,
32626 Pragma_Ignore_Pragma => 0,
32627 Pragma_Implementation_Defined => -1,
32628 Pragma_Implemented => -1,
32629 Pragma_Implicit_Packing => 0,
32630 Pragma_Import => 93,
32631 Pragma_Import_Function => 0,
32632 Pragma_Import_Object => 0,
32633 Pragma_Import_Procedure => 0,
32634 Pragma_Import_Valued_Procedure => 0,
32635 Pragma_Independent => 0,
32636 Pragma_Independent_Components => 0,
32637 Pragma_Initial_Condition => -1,
32638 Pragma_Initialize_Scalars => 0,
32639 Pragma_Initializes => -1,
32640 Pragma_Inline => 0,
32641 Pragma_Inline_Always => 0,
32642 Pragma_Inline_Generic => 0,
32643 Pragma_Inspection_Point => -1,
32644 Pragma_Interface => 92,
32645 Pragma_Interface_Name => 0,
32646 Pragma_Interrupt_Handler => -1,
32647 Pragma_Interrupt_Priority => -1,
32648 Pragma_Interrupt_State => -1,
32649 Pragma_Invariant => -1,
32650 Pragma_Keep_Names => 0,
32651 Pragma_License => 0,
32652 Pragma_Link_With => -1,
32653 Pragma_Linker_Alias => -1,
32654 Pragma_Linker_Constructor => -1,
32655 Pragma_Linker_Destructor => -1,
32656 Pragma_Linker_Options => -1,
32657 Pragma_Linker_Section => -1,
32658 Pragma_List => 0,
32659 Pragma_Lock_Free => 0,
32660 Pragma_Locking_Policy => 0,
32661 Pragma_Loop_Invariant => -1,
32662 Pragma_Loop_Optimize => 0,
32663 Pragma_Loop_Variant => -1,
32664 Pragma_Machine_Attribute => -1,
32665 Pragma_Main => -1,
32666 Pragma_Main_Storage => -1,
32667 Pragma_Max_Entry_Queue_Depth => 0,
32668 Pragma_Max_Entry_Queue_Length => 0,
32669 Pragma_Max_Queue_Length => 0,
32670 Pragma_Memory_Size => 0,
32671 Pragma_No_Body => 0,
32672 Pragma_No_Caching => 0,
32673 Pragma_No_Component_Reordering => -1,
32674 Pragma_No_Elaboration_Code_All => 0,
32675 Pragma_No_Heap_Finalization => 0,
32676 Pragma_No_Inline => 0,
32677 Pragma_No_Return => 0,
32678 Pragma_No_Run_Time => -1,
32679 Pragma_No_Strict_Aliasing => -1,
32680 Pragma_No_Tagged_Streams => 0,
32681 Pragma_Normalize_Scalars => 0,
32682 Pragma_Obsolescent => 0,
32683 Pragma_Optimize => 0,
32684 Pragma_Optimize_Alignment => 0,
32685 Pragma_Ordered => 0,
32686 Pragma_Overflow_Mode => 0,
32687 Pragma_Overriding_Renamings => 0,
32688 Pragma_Pack => 0,
32689 Pragma_Page => 0,
32690 Pragma_Part_Of => 0,
32691 Pragma_Partition_Elaboration_Policy => 0,
32692 Pragma_Passive => 0,
32693 Pragma_Persistent_BSS => 0,
32694 Pragma_Post => -1,
32695 Pragma_Postcondition => -1,
32696 Pragma_Post_Class => -1,
32697 Pragma_Pre => -1,
32698 Pragma_Precondition => -1,
32699 Pragma_Predicate => -1,
32700 Pragma_Predicate_Failure => -1,
32701 Pragma_Preelaborable_Initialization => -1,
32702 Pragma_Preelaborate => 0,
32703 Pragma_Prefix_Exception_Messages => 0,
32704 Pragma_Pre_Class => -1,
32705 Pragma_Priority => -1,
32706 Pragma_Priority_Specific_Dispatching => 0,
32707 Pragma_Profile => 0,
32708 Pragma_Profile_Warnings => 0,
32709 Pragma_Propagate_Exceptions => 0,
32710 Pragma_Provide_Shift_Operators => 0,
32711 Pragma_Psect_Object => 0,
32712 Pragma_Pure => 0,
32713 Pragma_Pure_Function => 0,
32714 Pragma_Queuing_Policy => 0,
32715 Pragma_Rational => 0,
32716 Pragma_Ravenscar => 0,
32717 Pragma_Refined_Depends => -1,
32718 Pragma_Refined_Global => -1,
32719 Pragma_Refined_Post => -1,
32720 Pragma_Refined_State => 0,
32721 Pragma_Relative_Deadline => 0,
32722 Pragma_Remote_Access_Type => -1,
32723 Pragma_Remote_Call_Interface => -1,
32724 Pragma_Remote_Types => -1,
32725 Pragma_Rename_Pragma => 0,
32726 Pragma_Restricted_Run_Time => 0,
32727 Pragma_Restriction_Warnings => 0,
32728 Pragma_Restrictions => 0,
32729 Pragma_Reviewable => -1,
32730 Pragma_Side_Effects => 0,
32731 Pragma_Secondary_Stack_Size => -1,
32732 Pragma_Share_Generic => 0,
32733 Pragma_Shared => 0,
32734 Pragma_Shared_Passive => 0,
32735 Pragma_Short_Circuit_And_Or => 0,
32736 Pragma_Short_Descriptors => 0,
32737 Pragma_Simple_Storage_Pool_Type => 0,
32738 Pragma_Source_File_Name => 0,
32739 Pragma_Source_File_Name_Project => 0,
32740 Pragma_Source_Reference => 0,
32741 Pragma_SPARK_Mode => 0,
32742 Pragma_Static_Elaboration_Desired => 0,
32743 Pragma_Storage_Size => -1,
32744 Pragma_Storage_Unit => 0,
32745 Pragma_Stream_Convert => 0,
32746 Pragma_Style_Checks => 0,
32747 Pragma_Subprogram_Variant => -1,
32748 Pragma_Subtitle => 0,
32749 Pragma_Suppress => 0,
32750 Pragma_Suppress_All => 0,
32751 Pragma_Suppress_Debug_Info => 0,
32752 Pragma_Suppress_Exception_Locations => 0,
32753 Pragma_Suppress_Initialization => 0,
32754 Pragma_System_Name => 0,
32755 Pragma_Task_Dispatching_Policy => 0,
32756 Pragma_Task_Info => -1,
32757 Pragma_Task_Name => -1,
32758 Pragma_Task_Storage => -1,
32759 Pragma_Test_Case => -1,
32760 Pragma_Thread_Local_Storage => -1,
32761 Pragma_Time_Slice => -1,
32762 Pragma_Title => 0,
32763 Pragma_Type_Invariant => -1,
32764 Pragma_Type_Invariant_Class => -1,
32765 Pragma_Unchecked_Union => 0,
32766 Pragma_Unevaluated_Use_Of_Old => 0,
32767 Pragma_Unimplemented_Unit => 0,
32768 Pragma_Universal_Aliasing => 0,
32769 Pragma_Unmodified => 0,
32770 Pragma_Unreferenced => 0,
32771 Pragma_Unreferenced_Objects => 0,
32772 Pragma_Unreserve_All_Interrupts => 0,
32773 Pragma_Unsuppress => 0,
32774 Pragma_Unused => 0,
32775 Pragma_Use_VADS_Size => 0,
32776 Pragma_User_Aspect_Definition => 0,
32777 Pragma_Validity_Checks => 0,
32778 Pragma_Volatile => 0,
32779 Pragma_Volatile_Components => 0,
32780 Pragma_Volatile_Full_Access => 0,
32781 Pragma_Volatile_Function => 0,
32782 Pragma_Warning_As_Error => 0,
32783 Pragma_Warnings => 0,
32784 Pragma_Weak_External => 0,
32785 Pragma_Wide_Character_Encoding => 0,
32786 Unknown_Pragma => 0);
32787
32788 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
32789 Id : Pragma_Id;
32790 P : Node_Id;
32791 C : Int;
32792 AN : Nat;
32793
32794 function Arg_No return Nat;
32795 -- Returns an integer showing what argument we are in. A value of
32796 -- zero means we are not in any of the arguments.
32797
32798 ------------
32799 -- Arg_No --
32800 ------------
32801
32802 function Arg_No return Nat is
32803 A : Node_Id;
32804 N : Nat;
32805
32806 begin
32807 A := First (Pragma_Argument_Associations (Parent (P)));
32808 N := 1;
32809 loop
32810 if No (A) then
32811 return 0;
32812 elsif A = P then
32813 return N;
32814 end if;
32815
32816 Next (A);
32817 N := N + 1;
32818 end loop;
32819 end Arg_No;
32820
32821 -- Start of processing for Non_Significant_Pragma_Reference
32822
32823 begin
32824 -- Reference might appear either directly as expression of a pragma
32825 -- argument association, e.g. pragma Export (...), or within an
32826 -- aggregate with component associations, e.g. pragma Refined_State
32827 -- ((... => ...)).
32828
32829 P := Parent (N);
32830 loop
32831 case Nkind (P) is
32832 when N_Pragma_Argument_Association =>
32833 exit;
32834 when N_Aggregate | N_Component_Association =>
32835 P := Parent (P);
32836 when others =>
32837 return False;
32838 end case;
32839 end loop;
32840
32841 AN := Arg_No;
32842
32843 if AN = 0 then
32844 return False;
32845 end if;
32846
32847 Id := Get_Pragma_Id (Parent (P));
32848 C := Sig_Flags (Id);
32849
32850 case C is
32851 when -1 =>
32852 return False;
32853
32854 when 0 =>
32855 return True;
32856
32857 when 92 .. 99 =>
32858 return AN < (C - 90);
32859
32860 when others =>
32861 return AN /= C;
32862 end case;
32863 end Is_Non_Significant_Pragma_Reference;
32864
32865 ------------------------------
32866 -- Is_Pragma_String_Literal --
32867 ------------------------------
32868
32869 -- This function returns true if the corresponding pragma argument is a
32870 -- static string expression. These are the only cases in which string
32871 -- literals can appear as pragma arguments. We also allow a string literal
32872 -- as the first argument to pragma Assert (although it will of course
32873 -- always generate a type error).
32874
32875 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
32876 Pragn : constant Node_Id := Parent (Par);
32877 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
32878 Pname : constant Name_Id := Pragma_Name (Pragn);
32879 Argn : Natural;
32880 N : Node_Id;
32881
32882 begin
32883 Argn := 1;
32884 N := First (Assoc);
32885 loop
32886 exit when N = Par;
32887 Argn := Argn + 1;
32888 Next (N);
32889 end loop;
32890
32891 if Pname = Name_Assert then
32892 return True;
32893
32894 elsif Pname = Name_Export then
32895 return Argn > 2;
32896
32897 elsif Pname = Name_Ident then
32898 return Argn = 1;
32899
32900 elsif Pname = Name_Import then
32901 return Argn > 2;
32902
32903 elsif Pname = Name_Interface_Name then
32904 return Argn > 1;
32905
32906 elsif Pname = Name_Linker_Alias then
32907 return Argn = 2;
32908
32909 elsif Pname = Name_Linker_Section then
32910 return Argn = 2;
32911
32912 elsif Pname = Name_Machine_Attribute then
32913 return Argn = 2;
32914
32915 elsif Pname = Name_Source_File_Name then
32916 return True;
32917
32918 elsif Pname = Name_Source_Reference then
32919 return Argn = 2;
32920
32921 elsif Pname = Name_Title then
32922 return True;
32923
32924 elsif Pname = Name_Subtitle then
32925 return True;
32926
32927 else
32928 return False;
32929 end if;
32930 end Is_Pragma_String_Literal;
32931
32932 ---------------------------
32933 -- Is_Private_SPARK_Mode --
32934 ---------------------------
32935
32936 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
32937 begin
32938 pragma Assert
32939 (Nkind (N) = N_Pragma
32940 and then Pragma_Name (N) = Name_SPARK_Mode
32941 and then Is_List_Member (N));
32942
32943 -- For pragma SPARK_Mode to be private, it has to appear in the private
32944 -- declarations of a package.
32945
32946 return
32947 Present (Parent (N))
32948 and then Nkind (Parent (N)) = N_Package_Specification
32949 and then List_Containing (N) = Private_Declarations (Parent (N));
32950 end Is_Private_SPARK_Mode;
32951
32952 -------------------------------------
32953 -- Is_Unconstrained_Or_Tagged_Item --
32954 -------------------------------------
32955
32956 function Is_Unconstrained_Or_Tagged_Item
32957 (Item : Entity_Id) return Boolean
32958 is
32959 Typ : constant Entity_Id := Etype (Item);
32960 begin
32961 if Is_Tagged_Type (Typ) then
32962 return True;
32963
32964 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
32965 return True;
32966
32967 elsif Is_Record_Type (Typ) then
32968 return Has_Discriminants (Typ) and then not Is_Constrained (Typ);
32969
32970 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
32971 return True;
32972
32973 else
32974 return False;
32975 end if;
32976 end Is_Unconstrained_Or_Tagged_Item;
32977
32978 -----------------------------
32979 -- Is_Valid_Assertion_Kind --
32980 -----------------------------
32981
32982 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
32983 begin
32984 case Nam is
32985 when
32986 -- RM defined
32987
32988 Name_Assert
32989 | Name_Static_Predicate
32990 | Name_Dynamic_Predicate
32991 | Name_Pre
32992 | Name_uPre
32993 | Name_Post
32994 | Name_uPost
32995 | Name_Type_Invariant
32996 | Name_uType_Invariant
32997
32998 -- Impl defined
32999
33000 | Name_Assert_And_Cut
33001 | Name_Assume
33002 | Name_Contract_Cases
33003 | Name_Debug
33004 | Name_Default_Initial_Condition
33005 | Name_Ghost
33006 | Name_Ghost_Predicate
33007 | Name_Initial_Condition
33008 | Name_Invariant
33009 | Name_uInvariant
33010 | Name_Loop_Invariant
33011 | Name_Loop_Variant
33012 | Name_Postcondition
33013 | Name_Precondition
33014 | Name_Predicate
33015 | Name_Refined_Post
33016 | Name_Statement_Assertions
33017 | Name_Subprogram_Variant
33018 =>
33019 return True;
33020
33021 when others =>
33022 return False;
33023 end case;
33024 end Is_Valid_Assertion_Kind;
33025
33026 --------------------------------------
33027 -- Process_Compilation_Unit_Pragmas --
33028 --------------------------------------
33029
33030 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
33031 begin
33032 -- A special check for pragma Suppress_All, a very strange DEC pragma,
33033 -- strange because it comes at the end of the unit. Rational has the
33034 -- same name for a pragma, but treats it as a program unit pragma, In
33035 -- GNAT we just decide to allow it anywhere at all. If it appeared then
33036 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
33037 -- node, and we insert a pragma Suppress (All_Checks) at the start of
33038 -- the context clause to ensure the correct processing.
33039
33040 if Has_Pragma_Suppress_All (N) then
33041 Prepend_To (Context_Items (N),
33042 Make_Pragma (Sloc (N),
33043 Chars => Name_Suppress,
33044 Pragma_Argument_Associations => New_List (
33045 Make_Pragma_Argument_Association (Sloc (N),
33046 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
33047 end if;
33048
33049 -- Nothing else to do at the current time
33050
33051 end Process_Compilation_Unit_Pragmas;
33052
33053 --------------------------------------------
33054 -- Validate_Compile_Time_Warning_Or_Error --
33055 --------------------------------------------
33056
33057 procedure Validate_Compile_Time_Warning_Or_Error
33058 (N : Node_Id;
33059 Eloc : Source_Ptr)
33060 is
33061 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
33062 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
33063 Arg2 : constant Node_Id := Next (Arg1);
33064
33065 Pname : constant Name_Id := Pragma_Name_Unmapped (N);
33066 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
33067
33068 begin
33069 Analyze_And_Resolve (Arg1x, Standard_Boolean);
33070
33071 if Compile_Time_Known_Value (Arg1x) then
33072 if Is_True (Expr_Value (Arg1x)) then
33073
33074 -- We have already verified that the second argument is a static
33075 -- string expression. Its string value must be retrieved
33076 -- explicitly if it is a declared constant, otherwise it has
33077 -- been constant-folded previously.
33078
33079 declare
33080 Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
33081 Str : constant String_Id :=
33082 Strval (Expr_Value_S (Get_Pragma_Arg (Arg2)));
33083 Str_Len : constant Nat := String_Length (Str);
33084
33085 Force : constant Boolean :=
33086 Prag_Id = Pragma_Compile_Time_Warning
33087 and then Is_Spec_Name (Unit_Name (Current_Sem_Unit))
33088 and then (Ekind (Cent) /= E_Package
33089 or else not In_Private_Part (Cent));
33090 -- Set True if this is the warning case, and we are in the
33091 -- visible part of a package spec, or in a subprogram spec,
33092 -- in which case we want to force the client to see the
33093 -- warning, even though it is not in the main unit.
33094
33095 C : Character;
33096 CC : Char_Code;
33097 Cont : Boolean;
33098 Ptr : Nat;
33099
33100 begin
33101 -- Loop through segments of message separated by line feeds.
33102 -- We output these segments as separate messages with
33103 -- continuation marks for all but the first.
33104
33105 Cont := False;
33106 Ptr := 1;
33107 loop
33108 Error_Msg_Strlen := 0;
33109
33110 -- Loop to copy characters from argument to error message
33111 -- string buffer.
33112
33113 loop
33114 exit when Ptr > Str_Len;
33115 CC := Get_String_Char (Str, Ptr);
33116 Ptr := Ptr + 1;
33117
33118 -- Ignore wide chars ??? else store character
33119
33120 if In_Character_Range (CC) then
33121 C := Get_Character (CC);
33122 exit when C = ASCII.LF;
33123 Error_Msg_Strlen := Error_Msg_Strlen + 1;
33124 Error_Msg_String (Error_Msg_Strlen) := C;
33125 end if;
33126 end loop;
33127
33128 -- Here with one line ready to go
33129
33130 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
33131
33132 -- If this is a warning in a spec, then we want clients
33133 -- to see the warning, so mark the message with the
33134 -- special sequence !! to force the warning. In the case
33135 -- of a package spec, we do not force this if we are in
33136 -- the private part of the spec.
33137
33138 if Force then
33139 if Cont = False then
33140 Error_Msg
33141 ("<<~!!", Eloc, Is_Compile_Time_Pragma => True);
33142 Cont := True;
33143 else
33144 Error_Msg
33145 ("\<<~!!", Eloc, Is_Compile_Time_Pragma => True);
33146 end if;
33147
33148 -- Error, rather than warning, or in a body, so we do not
33149 -- need to force visibility for client (error will be
33150 -- output in any case, and this is the situation in which
33151 -- we do not want a client to get a warning, since the
33152 -- warning is in the body or the spec private part).
33153
33154 else
33155 if Cont = False then
33156 Error_Msg
33157 ("<<~", Eloc, Is_Compile_Time_Pragma => True);
33158 Cont := True;
33159 else
33160 Error_Msg
33161 ("\<<~", Eloc, Is_Compile_Time_Pragma => True);
33162 end if;
33163 end if;
33164
33165 exit when Ptr > Str_Len;
33166 end loop;
33167 end;
33168 end if;
33169
33170 -- Arg1x is not known at compile time, so possibly issue an error
33171 -- or warning. This can happen only if the pragma's processing
33172 -- was deferred until after the back end is run (see
33173 -- Process_Compile_Time_Warning_Or_Error). Note that the warning
33174 -- control switch applies to only the warning case.
33175
33176 elsif Prag_Id = Pragma_Compile_Time_Error then
33177 Error_Msg_N ("condition is not known at compile time", Arg1x);
33178
33179 elsif Warn_On_Unknown_Compile_Time_Warning then
33180 Error_Msg_N ("?_c?condition is not known at compile time", Arg1x);
33181 end if;
33182 end Validate_Compile_Time_Warning_Or_Error;
33183
33184 ------------------------------------
33185 -- Record_Possible_Body_Reference --
33186 ------------------------------------
33187
33188 procedure Record_Possible_Body_Reference
33189 (State_Id : Entity_Id;
33190 Ref : Node_Id)
33191 is
33192 Context : Node_Id;
33193 Spec_Id : Entity_Id;
33194
33195 begin
33196 -- Ensure that we are dealing with a reference to a state
33197
33198 pragma Assert (Ekind (State_Id) = E_Abstract_State);
33199
33200 -- Climb the tree starting from the reference looking for a package body
33201 -- whose spec declares the referenced state. This criteria automatically
33202 -- excludes references in package specs which are legal. Note that it is
33203 -- not wise to emit an error now as the package body may lack pragma
33204 -- Refined_State or the referenced state may not be mentioned in the
33205 -- refinement. This approach avoids the generation of misleading errors.
33206
33207 Context := Ref;
33208 while Present (Context) loop
33209 if Nkind (Context) = N_Package_Body then
33210 Spec_Id := Corresponding_Spec (Context);
33211
33212 if Contains (Abstract_States (Spec_Id), State_Id) then
33213 if No (Body_References (State_Id)) then
33214 Set_Body_References (State_Id, New_Elmt_List);
33215 end if;
33216
33217 Append_Elmt (Ref, To => Body_References (State_Id));
33218 exit;
33219 end if;
33220 end if;
33221
33222 Context := Parent (Context);
33223 end loop;
33224 end Record_Possible_Body_Reference;
33225
33226 ------------------------------------------
33227 -- Relocate_Pragmas_To_Anonymous_Object --
33228 ------------------------------------------
33229
33230 procedure Relocate_Pragmas_To_Anonymous_Object
33231 (Typ_Decl : Node_Id;
33232 Obj_Decl : Node_Id)
33233 is
33234 Decl : Node_Id;
33235 Def : Node_Id;
33236 Next_Decl : Node_Id;
33237
33238 begin
33239 if Nkind (Typ_Decl) = N_Protected_Type_Declaration then
33240 Def := Protected_Definition (Typ_Decl);
33241 else
33242 pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration);
33243 Def := Task_Definition (Typ_Decl);
33244 end if;
33245
33246 -- The concurrent definition has a visible declaration list. Inspect it
33247 -- and relocate all canidate pragmas.
33248
33249 if Present (Def) and then Present (Visible_Declarations (Def)) then
33250 Decl := First (Visible_Declarations (Def));
33251 while Present (Decl) loop
33252
33253 -- Preserve the following declaration for iteration purposes due
33254 -- to possible relocation of a pragma.
33255
33256 Next_Decl := Next (Decl);
33257
33258 if Nkind (Decl) = N_Pragma
33259 and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl))
33260 then
33261 Remove (Decl);
33262 Insert_After (Obj_Decl, Decl);
33263
33264 -- Skip internally generated code
33265
33266 elsif not Comes_From_Source (Decl) then
33267 null;
33268
33269 -- No candidate pragmas are available for relocation
33270
33271 else
33272 exit;
33273 end if;
33274
33275 Decl := Next_Decl;
33276 end loop;
33277 end if;
33278 end Relocate_Pragmas_To_Anonymous_Object;
33279
33280 ------------------------------
33281 -- Relocate_Pragmas_To_Body --
33282 ------------------------------
33283
33284 procedure Relocate_Pragmas_To_Body
33285 (Subp_Body : Node_Id;
33286 Target_Body : Node_Id := Empty)
33287 is
33288 procedure Relocate_Pragma (Prag : Node_Id);
33289 -- Remove a single pragma from its current list and add it to the
33290 -- declarations of the proper body (either Subp_Body or Target_Body).
33291
33292 ---------------------
33293 -- Relocate_Pragma --
33294 ---------------------
33295
33296 procedure Relocate_Pragma (Prag : Node_Id) is
33297 Decls : List_Id;
33298 Target : Node_Id;
33299
33300 begin
33301 -- When subprogram stubs or expression functions are involves, the
33302 -- destination declaration list belongs to the proper body.
33303
33304 if Present (Target_Body) then
33305 Target := Target_Body;
33306 else
33307 Target := Subp_Body;
33308 end if;
33309
33310 Decls := Declarations (Target);
33311
33312 if No (Decls) then
33313 Decls := New_List;
33314 Set_Declarations (Target, Decls);
33315 end if;
33316
33317 -- Unhook the pragma from its current list
33318
33319 Remove (Prag);
33320 Prepend (Prag, Decls);
33321 end Relocate_Pragma;
33322
33323 -- Local variables
33324
33325 Body_Id : constant Entity_Id :=
33326 Defining_Unit_Name (Specification (Subp_Body));
33327 Next_Stmt : Node_Id;
33328 Stmt : Node_Id;
33329
33330 -- Start of processing for Relocate_Pragmas_To_Body
33331
33332 begin
33333 -- Do not process a body that comes from a separate unit as no construct
33334 -- can possibly follow it.
33335
33336 if not Is_List_Member (Subp_Body) then
33337 return;
33338
33339 -- Do not relocate pragmas that follow a stub if the stub does not have
33340 -- a proper body.
33341
33342 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
33343 and then No (Target_Body)
33344 then
33345 return;
33346
33347 -- Do not process internally generated routine _Wrapped_Statements
33348
33349 elsif Ekind (Body_Id) = E_Procedure
33350 and then Chars (Body_Id) = Name_uWrapped_Statements
33351 then
33352 return;
33353 end if;
33354
33355 -- Look at what is following the body. We are interested in certain kind
33356 -- of pragmas (either from source or byproducts of expansion) that can
33357 -- apply to a body [stub].
33358
33359 Stmt := Next (Subp_Body);
33360 while Present (Stmt) loop
33361
33362 -- Preserve the following statement for iteration purposes due to a
33363 -- possible relocation of a pragma.
33364
33365 Next_Stmt := Next (Stmt);
33366
33367 -- Move a candidate pragma following the body to the declarations of
33368 -- the body.
33369
33370 if Nkind (Stmt) = N_Pragma
33371 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
33372 then
33373
33374 -- If a source pragma Warnings follows the body, it applies to
33375 -- following statements and does not belong in the body.
33376
33377 if Get_Pragma_Id (Stmt) = Pragma_Warnings
33378 and then Comes_From_Source (Stmt)
33379 then
33380 null;
33381 else
33382 Relocate_Pragma (Stmt);
33383 end if;
33384
33385 -- Skip internally generated code
33386
33387 elsif not Comes_From_Source (Stmt) then
33388 null;
33389
33390 -- No candidate pragmas are available for relocation
33391
33392 else
33393 exit;
33394 end if;
33395
33396 Stmt := Next_Stmt;
33397 end loop;
33398 end Relocate_Pragmas_To_Body;
33399
33400 -------------------
33401 -- Resolve_State --
33402 -------------------
33403
33404 procedure Resolve_State (N : Node_Id) is
33405 Func : Entity_Id;
33406 State : Entity_Id;
33407
33408 begin
33409 if Is_Entity_Name (N) and then Present (Entity (N)) then
33410 Func := Entity (N);
33411
33412 -- Handle overloading of state names by functions. Traverse the
33413 -- homonym chain looking for an abstract state.
33414
33415 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
33416 pragma Assert (Is_Overloaded (N));
33417
33418 State := Homonym (Func);
33419 while Present (State) loop
33420 if Ekind (State) = E_Abstract_State then
33421
33422 -- Resolve the overloading by setting the proper entity of
33423 -- the reference to that of the state.
33424
33425 Set_Etype (N, Standard_Void_Type);
33426 Set_Entity (N, State);
33427 Set_Is_Overloaded (N, False);
33428
33429 Generate_Reference (State, N);
33430 return;
33431 end if;
33432
33433 State := Homonym (State);
33434 end loop;
33435
33436 -- A function can never act as a state. If the homonym chain does
33437 -- not contain a corresponding state, then something went wrong in
33438 -- the overloading mechanism.
33439
33440 raise Program_Error;
33441 end if;
33442 end if;
33443 end Resolve_State;
33444
33445 ----------------------------
33446 -- Rewrite_Assertion_Kind --
33447 ----------------------------
33448
33449 procedure Rewrite_Assertion_Kind
33450 (N : Node_Id;
33451 From_Policy : Boolean := False)
33452 is
33453 Nam : Name_Id;
33454
33455 begin
33456 Nam := No_Name;
33457 if Nkind (N) = N_Attribute_Reference
33458 and then Attribute_Name (N) = Name_Class
33459 and then Nkind (Prefix (N)) = N_Identifier
33460 then
33461 case Chars (Prefix (N)) is
33462 when Name_Pre =>
33463 Nam := Name_uPre;
33464
33465 when Name_Post =>
33466 Nam := Name_uPost;
33467
33468 when Name_Type_Invariant =>
33469 Nam := Name_uType_Invariant;
33470
33471 when Name_Invariant =>
33472 Nam := Name_uInvariant;
33473
33474 when others =>
33475 return;
33476 end case;
33477
33478 -- Recommend standard use of aspect names Pre/Post
33479
33480 elsif Nkind (N) = N_Identifier
33481 and then From_Policy
33482 and then Serious_Errors_Detected = 0
33483 then
33484 if Chars (N) = Name_Precondition
33485 or else Chars (N) = Name_Postcondition
33486 then
33487 Error_Msg_N ("Check_Policy is a non-standard pragma??", N);
33488 Error_Msg_N
33489 ("\use Assertion_Policy and aspect names Pre/Post for "
33490 & "Ada2012 conformance?", N);
33491 end if;
33492
33493 return;
33494 end if;
33495
33496 if Nam /= No_Name then
33497 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
33498 end if;
33499 end Rewrite_Assertion_Kind;
33500
33501 --------
33502 -- rv --
33503 --------
33504
33505 procedure rv is
33506 begin
33507 Dummy := Dummy + 1;
33508 end rv;
33509
33510 --------------------------------
33511 -- Set_Encoded_Interface_Name --
33512 --------------------------------
33513
33514 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
33515 Str : constant String_Id := Strval (S);
33516 Len : constant Nat := String_Length (Str);
33517 CC : Char_Code;
33518 C : Character;
33519 J : Pos;
33520
33521 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
33522
33523 procedure Encode;
33524 -- Stores encoded value of character code CC. The encoding we use an
33525 -- underscore followed by four lower case hex digits.
33526
33527 ------------
33528 -- Encode --
33529 ------------
33530
33531 procedure Encode is
33532 begin
33533 Store_String_Char (Get_Char_Code ('_'));
33534 Store_String_Char
33535 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
33536 Store_String_Char
33537 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
33538 Store_String_Char
33539 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
33540 Store_String_Char
33541 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
33542 end Encode;
33543
33544 -- Start of processing for Set_Encoded_Interface_Name
33545
33546 begin
33547 -- If first character is asterisk, this is a link name, and we leave it
33548 -- completely unmodified. We also ignore null strings (the latter case
33549 -- happens only in error cases).
33550
33551 if Len = 0
33552 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
33553 then
33554 Set_Interface_Name (E, S);
33555
33556 else
33557 J := 1;
33558 loop
33559 CC := Get_String_Char (Str, J);
33560
33561 exit when not In_Character_Range (CC);
33562
33563 C := Get_Character (CC);
33564
33565 exit when C /= '_' and then C /= '$'
33566 and then C not in '0' .. '9'
33567 and then C not in 'a' .. 'z'
33568 and then C not in 'A' .. 'Z';
33569
33570 if J = Len then
33571 Set_Interface_Name (E, S);
33572 return;
33573
33574 else
33575 J := J + 1;
33576 end if;
33577 end loop;
33578
33579 -- Here we need to encode. The encoding we use as follows:
33580 -- three underscores + four hex digits (lower case)
33581
33582 Start_String;
33583
33584 for J in 1 .. String_Length (Str) loop
33585 CC := Get_String_Char (Str, J);
33586
33587 if not In_Character_Range (CC) then
33588 Encode;
33589 else
33590 C := Get_Character (CC);
33591
33592 if C = '_' or else C = '$'
33593 or else C in '0' .. '9'
33594 or else C in 'a' .. 'z'
33595 or else C in 'A' .. 'Z'
33596 then
33597 Store_String_Char (CC);
33598 else
33599 Encode;
33600 end if;
33601 end if;
33602 end loop;
33603
33604 Set_Interface_Name (E,
33605 Make_String_Literal (Sloc (S),
33606 Strval => End_String));
33607 end if;
33608 end Set_Encoded_Interface_Name;
33609
33610 ------------------------
33611 -- Set_Elab_Unit_Name --
33612 ------------------------
33613
33614 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
33615 Pref : Node_Id;
33616 Scop : Entity_Id;
33617
33618 begin
33619 if Nkind (N) = N_Identifier
33620 and then Nkind (With_Item) = N_Identifier
33621 then
33622 Set_Entity (N, Entity (With_Item));
33623
33624 elsif Nkind (N) = N_Selected_Component then
33625 Change_Selected_Component_To_Expanded_Name (N);
33626 Set_Entity (N, Entity (With_Item));
33627 Set_Entity (Selector_Name (N), Entity (N));
33628
33629 Pref := Prefix (N);
33630 Scop := Scope (Entity (N));
33631 while Nkind (Pref) = N_Selected_Component loop
33632 Change_Selected_Component_To_Expanded_Name (Pref);
33633 Set_Entity (Selector_Name (Pref), Scop);
33634 Set_Entity (Pref, Scop);
33635 Pref := Prefix (Pref);
33636 Scop := Scope (Scop);
33637 end loop;
33638
33639 Set_Entity (Pref, Scop);
33640 end if;
33641
33642 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
33643 end Set_Elab_Unit_Name;
33644
33645 -----------------------
33646 -- Set_Overflow_Mode --
33647 -----------------------
33648
33649 procedure Set_Overflow_Mode (N : Node_Id) is
33650
33651 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type;
33652 -- Function to process one pragma argument, Arg
33653
33654 -----------------------
33655 -- Get_Overflow_Mode --
33656 -----------------------
33657
33658 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type is
33659 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
33660
33661 begin
33662 if Chars (Argx) = Name_Strict then
33663 return Strict;
33664
33665 elsif Chars (Argx) = Name_Minimized then
33666 return Minimized;
33667
33668 elsif Chars (Argx) = Name_Eliminated then
33669 return Eliminated;
33670
33671 else
33672 raise Program_Error;
33673 end if;
33674 end Get_Overflow_Mode;
33675
33676 -- Local variables
33677
33678 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
33679 Arg2 : constant Node_Id := Next (Arg1);
33680
33681 -- Start of processing for Set_Overflow_Mode
33682
33683 begin
33684 -- Process first argument
33685
33686 Scope_Suppress.Overflow_Mode_General :=
33687 Get_Overflow_Mode (Arg1);
33688
33689 -- Case of only one argument
33690
33691 if No (Arg2) then
33692 Scope_Suppress.Overflow_Mode_Assertions :=
33693 Scope_Suppress.Overflow_Mode_General;
33694
33695 -- Case of two arguments present
33696
33697 else
33698 Scope_Suppress.Overflow_Mode_Assertions :=
33699 Get_Overflow_Mode (Arg2);
33700 end if;
33701 end Set_Overflow_Mode;
33702
33703 -------------------
33704 -- Test_Case_Arg --
33705 -------------------
33706
33707 function Test_Case_Arg
33708 (Prag : Node_Id;
33709 Arg_Nam : Name_Id;
33710 From_Aspect : Boolean := False) return Node_Id
33711 is
33712 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
33713 Arg : Node_Id;
33714 Args : Node_Id;
33715
33716 begin
33717 pragma Assert
33718 (Arg_Nam in Name_Ensures | Name_Mode | Name_Name | Name_Requires);
33719
33720 -- The caller requests the aspect argument
33721
33722 if From_Aspect then
33723 if Present (Aspect)
33724 and then Nkind (Expression (Aspect)) = N_Aggregate
33725 then
33726 Args := Expression (Aspect);
33727
33728 -- "Name" and "Mode" may appear without an identifier as a
33729 -- positional association.
33730
33731 if Present (Expressions (Args)) then
33732 Arg := First (Expressions (Args));
33733
33734 if Present (Arg) and then Arg_Nam = Name_Name then
33735 return Arg;
33736 end if;
33737
33738 -- Skip "Name"
33739
33740 Arg := Next (Arg);
33741
33742 if Present (Arg) and then Arg_Nam = Name_Mode then
33743 return Arg;
33744 end if;
33745 end if;
33746
33747 -- Some or all arguments may appear as component associatons
33748
33749 if Present (Component_Associations (Args)) then
33750 Arg := First (Component_Associations (Args));
33751 while Present (Arg) loop
33752 if Chars (First (Choices (Arg))) = Arg_Nam then
33753 return Arg;
33754 end if;
33755
33756 Next (Arg);
33757 end loop;
33758 end if;
33759 end if;
33760
33761 -- Otherwise retrieve the argument directly from the pragma
33762
33763 else
33764 Arg := First (Pragma_Argument_Associations (Prag));
33765
33766 if Present (Arg) and then Arg_Nam = Name_Name then
33767 return Arg;
33768 end if;
33769
33770 -- Skip argument "Name"
33771
33772 Arg := Next (Arg);
33773
33774 if Present (Arg) and then Arg_Nam = Name_Mode then
33775 return Arg;
33776 end if;
33777
33778 -- Skip argument "Mode"
33779
33780 Arg := Next (Arg);
33781
33782 -- Arguments "Requires" and "Ensures" are optional and may not be
33783 -- present at all.
33784
33785 while Present (Arg) loop
33786 if Chars (Arg) = Arg_Nam then
33787 return Arg;
33788 end if;
33789
33790 Next (Arg);
33791 end loop;
33792 end if;
33793
33794 return Empty;
33795 end Test_Case_Arg;
33796
33797 --------------------------------------------
33798 -- Defer_Compile_Time_Warning_Error_To_BE --
33799 --------------------------------------------
33800
33801 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id) is
33802 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
33803 begin
33804 Compile_Time_Warnings_Errors.Append
33805 (New_Val => CTWE_Entry'(Eloc => Sloc (Arg1),
33806 Scope => Current_Scope,
33807 Prag => N));
33808
33809 -- If the Boolean expression contains T'Size, and we're not in the main
33810 -- unit being compiled, then we need to copy the pragma into the main
33811 -- unit, because otherwise T'Size might never be computed, leaving it
33812 -- as 0.
33813
33814 if not In_Extended_Main_Code_Unit (N) then
33815 Insert_Library_Level_Action (New_Copy_Tree (N));
33816 end if;
33817 end Defer_Compile_Time_Warning_Error_To_BE;
33818
33819 ------------------------------------------
33820 -- Validate_Compile_Time_Warning_Errors --
33821 ------------------------------------------
33822
33823 procedure Validate_Compile_Time_Warning_Errors is
33824 procedure Set_Scope (S : Entity_Id);
33825 -- Install all enclosing scopes of S along with S itself
33826
33827 procedure Unset_Scope (S : Entity_Id);
33828 -- Uninstall all enclosing scopes of S along with S itself
33829
33830 ---------------
33831 -- Set_Scope --
33832 ---------------
33833
33834 procedure Set_Scope (S : Entity_Id) is
33835 begin
33836 if S /= Standard_Standard then
33837 Set_Scope (Scope (S));
33838 end if;
33839
33840 Push_Scope (S);
33841 end Set_Scope;
33842
33843 -----------------
33844 -- Unset_Scope --
33845 -----------------
33846
33847 procedure Unset_Scope (S : Entity_Id) is
33848 begin
33849 if S /= Standard_Standard then
33850 Unset_Scope (Scope (S));
33851 end if;
33852
33853 Pop_Scope;
33854 end Unset_Scope;
33855
33856 -- Start of processing for Validate_Compile_Time_Warning_Errors
33857
33858 begin
33859
33860 -- These error/warning messages were deferred because they could not be
33861 -- evaluated in the front-end and they needed additional information
33862 -- from the back-end. There is no reason to run these checks again if
33863 -- the back-end was not activated by this point.
33864
33865 if not Generating_Code then
33866 return;
33867 end if;
33868
33869 Expander_Mode_Save_And_Set (False);
33870 In_Compile_Time_Warning_Or_Error := True;
33871
33872 for N in Compile_Time_Warnings_Errors.First ..
33873 Compile_Time_Warnings_Errors.Last
33874 loop
33875 declare
33876 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
33877
33878 begin
33879 Set_Scope (T.Scope);
33880 Reset_Analyzed_Flags (T.Prag);
33881 Validate_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
33882 Unset_Scope (T.Scope);
33883 end;
33884 end loop;
33885
33886 In_Compile_Time_Warning_Or_Error := False;
33887 Expander_Mode_Restore;
33888 end Validate_Compile_Time_Warning_Errors;
33889
33890 end Sem_Prag;