]> gcc.gnu.org Git - gcc.git/blob - gcc/ada/sem_prag.adb
ada: Implement change to SPARK RM rule on state refinement
[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-2022, 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_Part_Of
190 (Indic : Node_Id;
191 Item_Id : Entity_Id;
192 Encap : Node_Id;
193 Encap_Id : out Entity_Id;
194 Legal : out Boolean);
195 -- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and
196 -- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the
197 -- Part_Of indicator. Item_Id is the entity of an abstract state, object or
198 -- package instantiation. Encap denotes the encapsulating state or single
199 -- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when
200 -- the indicator is legal.
201
202 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
203 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
204 -- Query whether a particular item appears in a mixed list of nodes and
205 -- entities. It is assumed that all nodes in the list have entities.
206
207 procedure Check_Postcondition_Use_In_Inlined_Subprogram
208 (Prag : Node_Id;
209 Spec_Id : Entity_Id);
210 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
211 -- Precondition, Refined_Post, and Test_Case. Emit a warning when pragma
212 -- Prag is associated with subprogram Spec_Id subject to Inline_Always,
213 -- and assertions are enabled.
214
215 procedure Check_State_And_Constituent_Use
216 (States : Elist_Id;
217 Constits : Elist_Id;
218 Context : Node_Id);
219 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
220 -- Global and Initializes. Determine whether a state from list States and a
221 -- corresponding constituent from list Constits (if any) appear in the same
222 -- context denoted by Context. If this is the case, emit an error.
223
224 procedure Contract_Freeze_Error
225 (Contract_Id : Entity_Id;
226 Freeze_Id : Entity_Id);
227 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and
228 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity
229 -- of a body which caused contract freezing and Contract_Id denotes the
230 -- entity of the affected contstruct.
231
232 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id);
233 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma
234 -- Prag that duplicates previous pragma Prev.
235
236 function Find_Encapsulating_State
237 (States : Elist_Id;
238 Constit_Id : Entity_Id) return Entity_Id;
239 -- Given the entity of a constituent Constit_Id, find the corresponding
240 -- encapsulating state which appears in States. The routine returns Empty
241 -- if no such state is found.
242
243 function Find_Related_Context
244 (Prag : Node_Id;
245 Do_Checks : Boolean := False) return Node_Id;
246 -- Subsidiary to the analysis of pragmas
247 -- Async_Readers
248 -- Async_Writers
249 -- Constant_After_Elaboration
250 -- Effective_Reads
251 -- Effective_Writers
252 -- No_Caching
253 -- Part_Of
254 -- Find the first source declaration or statement found while traversing
255 -- the previous node chain starting from pragma Prag. If flag Do_Checks is
256 -- set, the routine reports duplicate pragmas. The routine returns Empty
257 -- when reaching the start of the node chain.
258
259 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
260 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
261 -- original one, following the renaming chain) is returned. Otherwise the
262 -- entity is returned unchanged. Should be in Einfo???
263
264 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
265 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
266 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
267 -- value of type SPARK_Mode_Type.
268
269 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
270 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
271 -- Determine whether dependency clause Clause is surrounded by extra
272 -- parentheses. If this is the case, issue an error message.
273
274 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
275 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
276 -- pragma Depends. Determine whether the type of dependency item Item is
277 -- tagged, unconstrained array, unconstrained record or a record with at
278 -- least one unconstrained component.
279
280 procedure Record_Possible_Body_Reference
281 (State_Id : Entity_Id;
282 Ref : Node_Id);
283 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
284 -- Global. Given an abstract state denoted by State_Id and a reference Ref
285 -- to it, determine whether the reference appears in a package body that
286 -- will eventually refine the state. If this is the case, record the
287 -- reference for future checks (see Analyze_Refined_State_In_Decls).
288
289 procedure Resolve_State (N : Node_Id);
290 -- Handle the overloading of state names by functions. When N denotes a
291 -- function, this routine finds the corresponding state and sets the entity
292 -- of N to that of the state.
293
294 procedure Rewrite_Assertion_Kind
295 (N : Node_Id;
296 From_Policy : Boolean := False);
297 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
298 -- then it is rewritten as an identifier with the corresponding special
299 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
300 -- and Check_Policy. If the names are Precondition or Postcondition, this
301 -- combination is deprecated in favor of Assertion_Policy and Ada2012
302 -- Aspect names. The parameter From_Policy indicates that the pragma
303 -- is the old non-standard Check_Policy and not a rewritten pragma.
304
305 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
306 -- Place semantic information on the argument of an Elaborate/Elaborate_All
307 -- pragma. Entity name for unit and its parents is taken from item in
308 -- previous with_clause that mentions the unit.
309
310 procedure Validate_Compile_Time_Warning_Or_Error
311 (N : Node_Id;
312 Eloc : Source_Ptr);
313 -- Common processing for Compile_Time_Error and Compile_Time_Warning of
314 -- pragma N. Called when the pragma is processed as part of its regular
315 -- analysis but also called after calling the back end to validate these
316 -- pragmas for size and alignment appropriateness.
317
318 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id);
319 -- N is a pragma Compile_Time_Error or Compile_Warning_Error whose boolean
320 -- expression is not known at compile time during the front end. This
321 -- procedure makes an entry in a table. The actual checking is performed by
322 -- Validate_Compile_Time_Warning_Errors, which is invoked after calling the
323 -- back end.
324
325 Dummy : Integer := 0;
326 pragma Volatile (Dummy);
327 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
328
329 procedure ip;
330 pragma No_Inline (ip);
331 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
332 -- is just to help debugging the front end. If a pragma Inspection_Point
333 -- is added to a source program, then breaking on ip will get you to that
334 -- point in the program.
335
336 procedure rv;
337 pragma No_Inline (rv);
338 -- This is a dummy function called by the processing for pragma Reviewable.
339 -- It is there for assisting front end debugging. By placing a Reviewable
340 -- pragma in the source program, a breakpoint on rv catches this place in
341 -- the source, allowing convenient stepping to the point of interest.
342
343 ------------------------------------------------------
344 -- Table for Defer_Compile_Time_Warning_Error_To_BE --
345 ------------------------------------------------------
346
347 -- The following table collects pragmas Compile_Time_Error and Compile_
348 -- Time_Warning for validation. Entries are made by calls to subprogram
349 -- Defer_Compile_Time_Warning_Error_To_BE, and the call to the procedure
350 -- Validate_Compile_Time_Warning_Errors does the actual error checking
351 -- and posting of warning and error messages. The reason for this delayed
352 -- processing is to take advantage of back-annotations of attributes size
353 -- and alignment values performed by the back end.
354
355 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
356 -- that by the time Validate_Compile_Time_Warning_Errors is called, Sprint
357 -- will already have modified all Sloc values if the -gnatD option is set.
358
359 type CTWE_Entry is record
360 Eloc : Source_Ptr;
361 -- Source location used in warnings and error messages
362
363 Prag : Node_Id;
364 -- Pragma Compile_Time_Error or Compile_Time_Warning
365
366 Scope : Node_Id;
367 -- The scope which encloses the pragma
368 end record;
369
370 package Compile_Time_Warnings_Errors is new Table.Table (
371 Table_Component_Type => CTWE_Entry,
372 Table_Index_Type => Int,
373 Table_Low_Bound => 1,
374 Table_Initial => 50,
375 Table_Increment => 200,
376 Table_Name => "Compile_Time_Warnings_Errors");
377
378 -------------------------------
379 -- Adjust_External_Name_Case --
380 -------------------------------
381
382 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
383 CC : Char_Code;
384
385 begin
386 -- Adjust case of literal if required
387
388 if Opt.External_Name_Exp_Casing = As_Is then
389 return N;
390
391 else
392 -- Copy existing string
393
394 Start_String;
395
396 -- Set proper casing
397
398 for J in 1 .. String_Length (Strval (N)) loop
399 CC := Get_String_Char (Strval (N), J);
400
401 if Opt.External_Name_Exp_Casing = Uppercase
402 and then CC in Get_Char_Code ('a') .. Get_Char_Code ('z')
403 then
404 Store_String_Char (CC - 32);
405
406 elsif Opt.External_Name_Exp_Casing = Lowercase
407 and then CC in Get_Char_Code ('A') .. Get_Char_Code ('Z')
408 then
409 Store_String_Char (CC + 32);
410
411 else
412 Store_String_Char (CC);
413 end if;
414 end loop;
415
416 return
417 Make_String_Literal (Sloc (N),
418 Strval => End_String);
419 end if;
420 end Adjust_External_Name_Case;
421
422 -----------------------------------------
423 -- Analyze_Contract_Cases_In_Decl_Part --
424 -----------------------------------------
425
426 -- WARNING: This routine manages Ghost regions. Return statements must be
427 -- replaced by gotos which jump to the end of the routine and restore the
428 -- Ghost mode.
429
430 procedure Analyze_Contract_Cases_In_Decl_Part
431 (N : Node_Id;
432 Freeze_Id : Entity_Id := Empty)
433 is
434 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
435 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
436
437 Others_Seen : Boolean := False;
438 -- This flag is set when an "others" choice is encountered. It is used
439 -- to detect multiple illegal occurrences of "others".
440
441 procedure Analyze_Contract_Case (CCase : Node_Id);
442 -- Verify the legality of a single contract case
443
444 ---------------------------
445 -- Analyze_Contract_Case --
446 ---------------------------
447
448 procedure Analyze_Contract_Case (CCase : Node_Id) is
449 Case_Guard : Node_Id;
450 Conseq : Node_Id;
451 Errors : Nat;
452 Extra_Guard : Node_Id;
453
454 begin
455 if Nkind (CCase) = N_Component_Association then
456 Case_Guard := First (Choices (CCase));
457 Conseq := Expression (CCase);
458
459 -- Each contract case must have exactly one case guard
460
461 Extra_Guard := Next (Case_Guard);
462
463 if Present (Extra_Guard) then
464 Error_Msg_N
465 ("contract case must have exactly one case guard",
466 Extra_Guard);
467 end if;
468
469 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
470
471 if Nkind (Case_Guard) = N_Others_Choice then
472 if Others_Seen then
473 Error_Msg_N
474 ("only one OTHERS choice allowed in contract cases",
475 Case_Guard);
476 else
477 Others_Seen := True;
478 end if;
479
480 elsif Others_Seen then
481 Error_Msg_N
482 ("OTHERS must be the last choice in contract cases", N);
483 end if;
484
485 -- Preanalyze the case guard and consequence
486
487 if Nkind (Case_Guard) /= N_Others_Choice then
488 Errors := Serious_Errors_Detected;
489 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
490
491 -- Emit a clarification message when the case guard contains
492 -- at least one undefined reference, possibly due to contract
493 -- freezing.
494
495 if Errors /= Serious_Errors_Detected
496 and then Present (Freeze_Id)
497 and then Has_Undefined_Reference (Case_Guard)
498 then
499 Contract_Freeze_Error (Spec_Id, Freeze_Id);
500 end if;
501 end if;
502
503 Errors := Serious_Errors_Detected;
504 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
505
506 -- Emit a clarification message when the consequence contains
507 -- at least one undefined reference, possibly due to contract
508 -- freezing.
509
510 if Errors /= Serious_Errors_Detected
511 and then Present (Freeze_Id)
512 and then Has_Undefined_Reference (Conseq)
513 then
514 Contract_Freeze_Error (Spec_Id, Freeze_Id);
515 end if;
516
517 -- The contract case is malformed
518
519 else
520 Error_Msg_N ("wrong syntax in contract case", CCase);
521 end if;
522 end Analyze_Contract_Case;
523
524 -- Local variables
525
526 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
527
528 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
529 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
530 -- Save the Ghost-related attributes to restore on exit
531
532 CCase : Node_Id;
533 Restore_Scope : Boolean := False;
534
535 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
536
537 begin
538 -- Do not analyze the pragma multiple times
539
540 if Is_Analyzed_Pragma (N) then
541 return;
542 end if;
543
544 -- Set the Ghost mode in effect from the pragma. Due to the delayed
545 -- analysis of the pragma, the Ghost mode at point of declaration and
546 -- point of analysis may not necessarily be the same. Use the mode in
547 -- effect at the point of declaration.
548
549 Set_Ghost_Mode (N);
550
551 -- Single and multiple contract cases must appear in aggregate form. If
552 -- this is not the case, then either the parser or the analysis of the
553 -- pragma failed to produce an aggregate, e.g. when the contract is
554 -- "null" or a "(null record)".
555
556 pragma Assert
557 (if Nkind (CCases) = N_Aggregate
558 then Null_Record_Present (CCases)
559 xor (Present (Component_Associations (CCases))
560 or
561 Present (Expressions (CCases)))
562 else Nkind (CCases) = N_Null);
563
564 -- Only CASE_GUARD => CONSEQUENCE clauses are allowed
565
566 if Nkind (CCases) = N_Aggregate
567 and then Present (Component_Associations (CCases))
568 and then No (Expressions (CCases))
569 then
570
571 -- Check that the expression is a proper aggregate (no parentheses)
572
573 if Paren_Count (CCases) /= 0 then
574 Error_Msg_F -- CODEFIX
575 ("redundant parentheses", CCases);
576 end if;
577
578 -- Ensure that the formal parameters are visible when analyzing all
579 -- clauses. This falls out of the general rule of aspects pertaining
580 -- to subprogram declarations.
581
582 if not In_Open_Scopes (Spec_Id) then
583 Restore_Scope := True;
584 Push_Scope (Spec_Id);
585
586 if Is_Generic_Subprogram (Spec_Id) then
587 Install_Generic_Formals (Spec_Id);
588 else
589 Install_Formals (Spec_Id);
590 end if;
591 end if;
592
593 CCase := First (Component_Associations (CCases));
594 while Present (CCase) loop
595 Analyze_Contract_Case (CCase);
596 Next (CCase);
597 end loop;
598
599 if Restore_Scope then
600 End_Scope;
601 end if;
602
603 -- Currently it is not possible to inline pre/postconditions on a
604 -- subprogram subject to pragma Inline_Always.
605
606 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
607
608 -- Otherwise the pragma is illegal
609
610 else
611 Error_Msg_N ("wrong syntax for contract cases", N);
612 end if;
613
614 Set_Is_Analyzed_Pragma (N);
615
616 Restore_Ghost_Region (Saved_GM, Saved_IGR);
617 end Analyze_Contract_Cases_In_Decl_Part;
618
619 ----------------------------------
620 -- Analyze_Depends_In_Decl_Part --
621 ----------------------------------
622
623 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
624 Loc : constant Source_Ptr := Sloc (N);
625 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
626 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
627
628 All_Inputs_Seen : Elist_Id := No_Elist;
629 -- A list containing the entities of all the inputs processed so far.
630 -- The list is populated with unique entities because the same input
631 -- may appear in multiple input lists.
632
633 All_Outputs_Seen : Elist_Id := No_Elist;
634 -- A list containing the entities of all the outputs processed so far.
635 -- The list is populated with unique entities because output items are
636 -- unique in a dependence relation.
637
638 Constits_Seen : Elist_Id := No_Elist;
639 -- A list containing the entities of all constituents processed so far.
640 -- It aids in detecting illegal usage of a state and a corresponding
641 -- constituent in pragma [Refinde_]Depends.
642
643 Global_Seen : Boolean := False;
644 -- A flag set when pragma Global has been processed
645
646 Null_Output_Seen : Boolean := False;
647 -- A flag used to track the legality of a null output
648
649 Result_Seen : Boolean := False;
650 -- A flag set when Spec_Id'Result is processed
651
652 States_Seen : Elist_Id := No_Elist;
653 -- A list containing the entities of all states processed so far. It
654 -- helps in detecting illegal usage of a state and a corresponding
655 -- constituent in pragma [Refined_]Depends.
656
657 Subp_Inputs : Elist_Id := No_Elist;
658 Subp_Outputs : Elist_Id := No_Elist;
659 -- Two lists containing the full set of inputs and output of the related
660 -- subprograms. Note that these lists contain both nodes and entities.
661
662 Task_Input_Seen : Boolean := False;
663 Task_Output_Seen : Boolean := False;
664 -- Flags used to track the implicit dependence of a task unit on itself
665
666 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
667 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
668 -- to the name buffer. The individual kinds are as follows:
669 -- E_Abstract_State - "state"
670 -- E_Constant - "constant"
671 -- E_Generic_In_Out_Parameter - "generic parameter"
672 -- E_Generic_In_Parameter - "generic parameter"
673 -- E_In_Parameter - "parameter"
674 -- E_In_Out_Parameter - "parameter"
675 -- E_Loop_Parameter - "loop parameter"
676 -- E_Out_Parameter - "parameter"
677 -- E_Protected_Type - "current instance of protected type"
678 -- E_Task_Type - "current instance of task type"
679 -- E_Variable - "global"
680
681 procedure Analyze_Dependency_Clause
682 (Clause : Node_Id;
683 Is_Last : Boolean);
684 -- Verify the legality of a single dependency clause. Flag Is_Last
685 -- denotes whether Clause is the last clause in the relation.
686
687 procedure Check_Function_Return;
688 -- Verify that Funtion'Result appears as one of the outputs
689 -- (SPARK RM 6.1.5(10)).
690
691 procedure Check_Role
692 (Item : Node_Id;
693 Item_Id : Entity_Id;
694 Is_Input : Boolean;
695 Self_Ref : Boolean);
696 -- Ensure that an item fulfills its designated input and/or output role
697 -- as specified by pragma Global (if any) or the enclosing context. If
698 -- this is not the case, emit an error. Item and Item_Id denote the
699 -- attributes of an item. Flag Is_Input should be set when item comes
700 -- from an input list. Flag Self_Ref should be set when the item is an
701 -- output and the dependency clause has operator "+".
702
703 procedure Check_Usage
704 (Subp_Items : Elist_Id;
705 Used_Items : Elist_Id;
706 Is_Input : Boolean);
707 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
708 -- error if this is not the case.
709
710 procedure Normalize_Clause (Clause : Node_Id);
711 -- Remove a self-dependency "+" from the input list of a clause
712
713 -----------------------------
714 -- Add_Item_To_Name_Buffer --
715 -----------------------------
716
717 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
718 begin
719 if Ekind (Item_Id) = E_Abstract_State then
720 Add_Str_To_Name_Buffer ("state");
721
722 elsif Ekind (Item_Id) = E_Constant then
723 Add_Str_To_Name_Buffer ("constant");
724
725 elsif Is_Formal_Object (Item_Id) then
726 Add_Str_To_Name_Buffer ("generic parameter");
727
728 elsif Is_Formal (Item_Id) then
729 Add_Str_To_Name_Buffer ("parameter");
730
731 elsif Ekind (Item_Id) = E_Loop_Parameter then
732 Add_Str_To_Name_Buffer ("loop parameter");
733
734 elsif Ekind (Item_Id) = E_Protected_Type
735 or else Is_Single_Protected_Object (Item_Id)
736 then
737 Add_Str_To_Name_Buffer ("current instance of protected type");
738
739 elsif Ekind (Item_Id) = E_Task_Type
740 or else Is_Single_Task_Object (Item_Id)
741 then
742 Add_Str_To_Name_Buffer ("current instance of task type");
743
744 elsif Ekind (Item_Id) = E_Variable then
745 Add_Str_To_Name_Buffer ("global");
746
747 -- The routine should not be called with non-SPARK items
748
749 else
750 raise Program_Error;
751 end if;
752 end Add_Item_To_Name_Buffer;
753
754 -------------------------------
755 -- Analyze_Dependency_Clause --
756 -------------------------------
757
758 procedure Analyze_Dependency_Clause
759 (Clause : Node_Id;
760 Is_Last : Boolean)
761 is
762 procedure Analyze_Input_List (Inputs : Node_Id);
763 -- Verify the legality of a single input list
764
765 procedure Analyze_Input_Output
766 (Item : Node_Id;
767 Is_Input : Boolean;
768 Self_Ref : Boolean;
769 Top_Level : Boolean;
770 Seen : in out Elist_Id;
771 Null_Seen : in out Boolean;
772 Non_Null_Seen : in out Boolean);
773 -- Verify the legality of a single input or output item. Flag
774 -- Is_Input should be set whenever Item is an input, False when it
775 -- denotes an output. Flag Self_Ref should be set when the item is an
776 -- output and the dependency clause has a "+". Flag Top_Level should
777 -- be set whenever Item appears immediately within an input or output
778 -- list. Seen is a collection of all abstract states, objects and
779 -- formals processed so far. Flag Null_Seen denotes whether a null
780 -- input or output has been encountered. Flag Non_Null_Seen denotes
781 -- whether a non-null input or output has been encountered.
782
783 ------------------------
784 -- Analyze_Input_List --
785 ------------------------
786
787 procedure Analyze_Input_List (Inputs : Node_Id) is
788 Inputs_Seen : Elist_Id := No_Elist;
789 -- A list containing the entities of all inputs that appear in the
790 -- current input list.
791
792 Non_Null_Input_Seen : Boolean := False;
793 Null_Input_Seen : Boolean := False;
794 -- Flags used to check the legality of an input list
795
796 Input : Node_Id;
797
798 begin
799 -- Multiple inputs appear as an aggregate
800
801 if Nkind (Inputs) = N_Aggregate then
802 if Present (Component_Associations (Inputs)) then
803 SPARK_Msg_N
804 ("nested dependency relations not allowed", Inputs);
805
806 elsif Present (Expressions (Inputs)) then
807 Input := First (Expressions (Inputs));
808 while Present (Input) loop
809 Analyze_Input_Output
810 (Item => Input,
811 Is_Input => True,
812 Self_Ref => False,
813 Top_Level => False,
814 Seen => Inputs_Seen,
815 Null_Seen => Null_Input_Seen,
816 Non_Null_Seen => Non_Null_Input_Seen);
817
818 Next (Input);
819 end loop;
820
821 -- Syntax error, always report
822
823 else
824 Error_Msg_N ("malformed input dependency list", Inputs);
825 end if;
826
827 -- Process a solitary input
828
829 else
830 Analyze_Input_Output
831 (Item => Inputs,
832 Is_Input => True,
833 Self_Ref => False,
834 Top_Level => False,
835 Seen => Inputs_Seen,
836 Null_Seen => Null_Input_Seen,
837 Non_Null_Seen => Non_Null_Input_Seen);
838 end if;
839
840 -- Detect an illegal dependency clause of the form
841
842 -- (null =>[+] null)
843
844 if Null_Output_Seen and then Null_Input_Seen then
845 SPARK_Msg_N
846 ("null dependency clause cannot have a null input list",
847 Inputs);
848 end if;
849 end Analyze_Input_List;
850
851 --------------------------
852 -- Analyze_Input_Output --
853 --------------------------
854
855 procedure Analyze_Input_Output
856 (Item : Node_Id;
857 Is_Input : Boolean;
858 Self_Ref : Boolean;
859 Top_Level : Boolean;
860 Seen : in out Elist_Id;
861 Null_Seen : in out Boolean;
862 Non_Null_Seen : in out Boolean)
863 is
864 procedure Current_Task_Instance_Seen;
865 -- Set the appropriate global flag when the current instance of a
866 -- task unit is encountered.
867
868 --------------------------------
869 -- Current_Task_Instance_Seen --
870 --------------------------------
871
872 procedure Current_Task_Instance_Seen is
873 begin
874 if Is_Input then
875 Task_Input_Seen := True;
876 else
877 Task_Output_Seen := True;
878 end if;
879 end Current_Task_Instance_Seen;
880
881 -- Local variables
882
883 Is_Output : constant Boolean := not Is_Input;
884 Grouped : Node_Id;
885 Item_Id : Entity_Id;
886
887 -- Start of processing for Analyze_Input_Output
888
889 begin
890 -- Multiple input or output items appear as an aggregate
891
892 if Nkind (Item) = N_Aggregate then
893 if not Top_Level then
894 SPARK_Msg_N ("nested grouping of items not allowed", Item);
895
896 elsif Present (Component_Associations (Item)) then
897 SPARK_Msg_N
898 ("nested dependency relations not allowed", Item);
899
900 -- Recursively analyze the grouped items
901
902 elsif Present (Expressions (Item)) then
903 Grouped := First (Expressions (Item));
904 while Present (Grouped) loop
905 Analyze_Input_Output
906 (Item => Grouped,
907 Is_Input => Is_Input,
908 Self_Ref => Self_Ref,
909 Top_Level => False,
910 Seen => Seen,
911 Null_Seen => Null_Seen,
912 Non_Null_Seen => Non_Null_Seen);
913
914 Next (Grouped);
915 end loop;
916
917 -- Syntax error, always report
918
919 else
920 Error_Msg_N ("malformed dependency list", Item);
921 end if;
922
923 -- Process attribute 'Result in the context of a dependency clause
924
925 elsif Is_Attribute_Result (Item) then
926 Non_Null_Seen := True;
927
928 Analyze (Item);
929
930 -- Attribute 'Result is allowed to appear on the output side of
931 -- a dependency clause (SPARK RM 6.1.5(6)).
932
933 if Is_Input then
934 SPARK_Msg_N ("function result cannot act as input", Item);
935
936 elsif Null_Seen then
937 SPARK_Msg_N
938 ("cannot mix null and non-null dependency items", Item);
939
940 else
941 Result_Seen := True;
942 end if;
943
944 -- Detect multiple uses of null in a single dependency list or
945 -- throughout the whole relation. Verify the placement of a null
946 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
947
948 elsif Nkind (Item) = N_Null then
949 if Null_Seen then
950 SPARK_Msg_N
951 ("multiple null dependency relations not allowed", Item);
952
953 elsif Non_Null_Seen then
954 SPARK_Msg_N
955 ("cannot mix null and non-null dependency items", Item);
956
957 else
958 Null_Seen := True;
959
960 if Is_Output then
961 if not Is_Last then
962 SPARK_Msg_N
963 ("null output list must be the last clause in a "
964 & "dependency relation", Item);
965
966 -- Catch a useless dependence of the form:
967 -- null =>+ ...
968
969 elsif Self_Ref then
970 SPARK_Msg_N
971 ("useless dependence, null depends on itself", Item);
972 end if;
973 end if;
974 end if;
975
976 -- Default case
977
978 else
979 Non_Null_Seen := True;
980
981 if Null_Seen then
982 SPARK_Msg_N ("cannot mix null and non-null items", Item);
983 end if;
984
985 Analyze (Item);
986 Resolve_State (Item);
987
988 -- Find the entity of the item. If this is a renaming, climb
989 -- the renaming chain to reach the root object. Renamings of
990 -- non-entire objects do not yield an entity (Empty).
991
992 Item_Id := Entity_Of (Item);
993
994 if Present (Item_Id) then
995
996 -- Constants
997
998 if Ekind (Item_Id) in E_Constant | E_Loop_Parameter
999 or else
1000
1001 -- Current instances of concurrent types
1002
1003 Ekind (Item_Id) in E_Protected_Type | E_Task_Type
1004 or else
1005
1006 -- Formal parameters
1007
1008 Ekind (Item_Id) in E_Generic_In_Out_Parameter
1009 | E_Generic_In_Parameter
1010 | E_In_Parameter
1011 | E_In_Out_Parameter
1012 | E_Out_Parameter
1013 or else
1014
1015 -- States, variables
1016
1017 Ekind (Item_Id) in E_Abstract_State | E_Variable
1018 then
1019 -- A [generic] function is not allowed to have Output
1020 -- items in its dependency relations. Note that "null"
1021 -- and attribute 'Result are still valid items.
1022
1023 if Ekind (Spec_Id) in E_Function | E_Generic_Function
1024 and then not Is_Input
1025 then
1026 SPARK_Msg_N
1027 ("output item is not applicable to function", Item);
1028 end if;
1029
1030 -- The item denotes a concurrent type. Note that single
1031 -- protected/task types are not considered here because
1032 -- they behave as objects in the context of pragma
1033 -- [Refined_]Depends.
1034
1035 if Ekind (Item_Id) in E_Protected_Type | E_Task_Type then
1036
1037 -- This use is legal as long as the concurrent type is
1038 -- the current instance of an enclosing type.
1039
1040 if Is_CCT_Instance (Item_Id, Spec_Id) then
1041
1042 -- The dependence of a task unit on itself is
1043 -- implicit and may or may not be explicitly
1044 -- specified (SPARK RM 6.1.4).
1045
1046 if Ekind (Item_Id) = E_Task_Type then
1047 Current_Task_Instance_Seen;
1048 end if;
1049
1050 -- Otherwise this is not the current instance
1051
1052 else
1053 SPARK_Msg_N
1054 ("invalid use of subtype mark in dependency "
1055 & "relation", Item);
1056 end if;
1057
1058 -- The dependency of a task unit on itself is implicit
1059 -- and may or may not be explicitly specified
1060 -- (SPARK RM 6.1.4).
1061
1062 elsif Is_Single_Task_Object (Item_Id)
1063 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
1064 then
1065 Current_Task_Instance_Seen;
1066 end if;
1067
1068 -- Ensure that the item fulfills its role as input and/or
1069 -- output as specified by pragma Global or the enclosing
1070 -- context.
1071
1072 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
1073
1074 -- Detect multiple uses of the same state, variable or
1075 -- formal parameter. If this is not the case, add the
1076 -- item to the list of processed relations.
1077
1078 if Contains (Seen, Item_Id) then
1079 SPARK_Msg_NE
1080 ("duplicate use of item &", Item, Item_Id);
1081 else
1082 Append_New_Elmt (Item_Id, Seen);
1083 end if;
1084
1085 -- Detect illegal use of an input related to a null
1086 -- output. Such input items cannot appear in other
1087 -- input lists (SPARK RM 6.1.5(13)).
1088
1089 if Is_Input
1090 and then Null_Output_Seen
1091 and then Contains (All_Inputs_Seen, Item_Id)
1092 then
1093 SPARK_Msg_N
1094 ("input of a null output list cannot appear in "
1095 & "multiple input lists", Item);
1096 end if;
1097
1098 -- Add an input or a self-referential output to the list
1099 -- of all processed inputs.
1100
1101 if Is_Input or else Self_Ref then
1102 Append_New_Elmt (Item_Id, All_Inputs_Seen);
1103 end if;
1104
1105 -- State related checks (SPARK RM 6.1.5(3))
1106
1107 if Ekind (Item_Id) = E_Abstract_State then
1108
1109 -- Package and subprogram bodies are instantiated
1110 -- individually in a separate compiler pass. Due to
1111 -- this mode of instantiation, the refinement of a
1112 -- state may no longer be visible when a subprogram
1113 -- body contract is instantiated. Since the generic
1114 -- template is legal, do not perform this check in
1115 -- the instance to circumvent this oddity.
1116
1117 if In_Instance then
1118 null;
1119
1120 -- An abstract state with visible refinement cannot
1121 -- appear in pragma [Refined_]Depends as its place
1122 -- must be taken by some of its constituents
1123 -- (SPARK RM 6.1.4(7)).
1124
1125 elsif Has_Visible_Refinement (Item_Id) then
1126 SPARK_Msg_NE
1127 ("cannot mention state & in dependence relation",
1128 Item, Item_Id);
1129 SPARK_Msg_N ("\use its constituents instead", Item);
1130 return;
1131
1132 -- If the reference to the abstract state appears in
1133 -- an enclosing package body that will eventually
1134 -- refine the state, record the reference for future
1135 -- checks.
1136
1137 else
1138 Record_Possible_Body_Reference
1139 (State_Id => Item_Id,
1140 Ref => Item);
1141 end if;
1142
1143 elsif Ekind (Item_Id) in E_Constant | E_Variable
1144 and then Present (Ultimate_Overlaid_Entity (Item_Id))
1145 then
1146 SPARK_Msg_NE
1147 ("overlaying object & cannot appear in Depends",
1148 Item, Item_Id);
1149 SPARK_Msg_NE
1150 ("\use the overlaid object & instead",
1151 Item, Ultimate_Overlaid_Entity (Item_Id));
1152 return;
1153 end if;
1154
1155 -- When the item renames an entire object, replace the
1156 -- item with a reference to the object.
1157
1158 if Entity (Item) /= Item_Id then
1159 Rewrite (Item,
1160 New_Occurrence_Of (Item_Id, Sloc (Item)));
1161 Analyze (Item);
1162 end if;
1163
1164 -- Add the entity of the current item to the list of
1165 -- processed items.
1166
1167 if Ekind (Item_Id) = E_Abstract_State then
1168 Append_New_Elmt (Item_Id, States_Seen);
1169
1170 -- The variable may eventually become a constituent of a
1171 -- single protected/task type. Record the reference now
1172 -- and verify its legality when analyzing the contract of
1173 -- the variable (SPARK RM 9.3).
1174
1175 elsif Ekind (Item_Id) = E_Variable then
1176 Record_Possible_Part_Of_Reference
1177 (Var_Id => Item_Id,
1178 Ref => Item);
1179 end if;
1180
1181 if Ekind (Item_Id) in E_Abstract_State
1182 | E_Constant
1183 | E_Variable
1184 and then Present (Encapsulating_State (Item_Id))
1185 then
1186 Append_New_Elmt (Item_Id, Constits_Seen);
1187 end if;
1188
1189 -- All other input/output items are illegal
1190 -- (SPARK RM 6.1.5(1)).
1191
1192 else
1193 SPARK_Msg_N
1194 ("item must denote parameter, variable, state or "
1195 & "current instance of concurrent type", Item);
1196 end if;
1197
1198 -- All other input/output items are illegal
1199 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1200
1201 else
1202 Error_Msg_N
1203 ("item must denote parameter, variable, state or current "
1204 & "instance of concurrent type", Item);
1205 end if;
1206 end if;
1207 end Analyze_Input_Output;
1208
1209 -- Local variables
1210
1211 Inputs : Node_Id;
1212 Output : Node_Id;
1213 Self_Ref : Boolean;
1214
1215 Non_Null_Output_Seen : Boolean := False;
1216 -- Flag used to check the legality of an output list
1217
1218 -- Start of processing for Analyze_Dependency_Clause
1219
1220 begin
1221 Inputs := Expression (Clause);
1222 Self_Ref := False;
1223
1224 -- An input list with a self-dependency appears as operator "+" where
1225 -- the actuals inputs are the right operand.
1226
1227 if Nkind (Inputs) = N_Op_Plus then
1228 Inputs := Right_Opnd (Inputs);
1229 Self_Ref := True;
1230 end if;
1231
1232 -- Process the output_list of a dependency_clause
1233
1234 Output := First (Choices (Clause));
1235 while Present (Output) loop
1236 Analyze_Input_Output
1237 (Item => Output,
1238 Is_Input => False,
1239 Self_Ref => Self_Ref,
1240 Top_Level => True,
1241 Seen => All_Outputs_Seen,
1242 Null_Seen => Null_Output_Seen,
1243 Non_Null_Seen => Non_Null_Output_Seen);
1244
1245 Next (Output);
1246 end loop;
1247
1248 -- Process the input_list of a dependency_clause
1249
1250 Analyze_Input_List (Inputs);
1251 end Analyze_Dependency_Clause;
1252
1253 ---------------------------
1254 -- Check_Function_Return --
1255 ---------------------------
1256
1257 procedure Check_Function_Return is
1258 begin
1259 if Ekind (Spec_Id) in E_Function | E_Generic_Function
1260 and then not Result_Seen
1261 then
1262 SPARK_Msg_NE
1263 ("result of & must appear in exactly one output list",
1264 N, Spec_Id);
1265 end if;
1266 end Check_Function_Return;
1267
1268 ----------------
1269 -- Check_Role --
1270 ----------------
1271
1272 procedure Check_Role
1273 (Item : Node_Id;
1274 Item_Id : Entity_Id;
1275 Is_Input : Boolean;
1276 Self_Ref : Boolean)
1277 is
1278 procedure Find_Role
1279 (Item_Is_Input : out Boolean;
1280 Item_Is_Output : out Boolean);
1281 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1282 -- Item_Is_Output are set depending on the role.
1283
1284 procedure Role_Error
1285 (Item_Is_Input : Boolean;
1286 Item_Is_Output : Boolean);
1287 -- Emit an error message concerning the incorrect use of Item in
1288 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1289 -- denote whether the item is an input and/or an output.
1290
1291 ---------------
1292 -- Find_Role --
1293 ---------------
1294
1295 procedure Find_Role
1296 (Item_Is_Input : out Boolean;
1297 Item_Is_Output : out Boolean)
1298 is
1299 -- A constant or an IN parameter of a procedure or a protected
1300 -- entry, if it is of an access-to-variable type, should be
1301 -- handled like a variable, as the underlying memory pointed-to
1302 -- can be modified. Use Adjusted_Kind to do this adjustment.
1303
1304 Adjusted_Kind : Entity_Kind := Ekind (Item_Id);
1305
1306 begin
1307 if (Ekind (Item_Id) in E_Constant | E_Generic_In_Parameter
1308 or else
1309 (Ekind (Item_Id) = E_In_Parameter
1310 and then Ekind (Scope (Item_Id))
1311 not in E_Function | E_Generic_Function))
1312 and then Is_Access_Variable (Etype (Item_Id))
1313 and then Ekind (Spec_Id) not in E_Function
1314 | E_Generic_Function
1315 then
1316 Adjusted_Kind := E_Variable;
1317 end if;
1318
1319 case Adjusted_Kind is
1320
1321 -- Abstract states
1322
1323 when E_Abstract_State =>
1324
1325 -- When pragma Global is present it determines the mode of
1326 -- the abstract state.
1327
1328 if Global_Seen then
1329 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1330 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1331
1332 -- Otherwise the state has a default IN OUT mode, because it
1333 -- behaves as a variable.
1334
1335 else
1336 Item_Is_Input := True;
1337 Item_Is_Output := True;
1338 end if;
1339
1340 -- Constants and IN parameters
1341
1342 when E_Constant
1343 | E_Generic_In_Parameter
1344 | E_In_Parameter
1345 | E_Loop_Parameter
1346 =>
1347 -- When pragma Global is present it determines the mode
1348 -- of constant objects as inputs (and such objects cannot
1349 -- appear as outputs in the Global contract).
1350
1351 if Global_Seen then
1352 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1353 else
1354 Item_Is_Input := True;
1355 end if;
1356
1357 Item_Is_Output := False;
1358
1359 -- Variables and IN OUT parameters, as well as constants and
1360 -- IN parameters of access type which are handled like
1361 -- variables.
1362
1363 when E_Generic_In_Out_Parameter
1364 | E_In_Out_Parameter
1365 | E_Out_Parameter
1366 | E_Variable
1367 =>
1368 -- An OUT parameter of the related subprogram; it cannot
1369 -- appear in Global.
1370
1371 if Adjusted_Kind = E_Out_Parameter
1372 and then Scope (Item_Id) = Spec_Id
1373 then
1374
1375 -- The parameter has mode IN if its type is unconstrained
1376 -- or tagged because array bounds, discriminants or tags
1377 -- can be read.
1378
1379 Item_Is_Input :=
1380 Is_Unconstrained_Or_Tagged_Item (Item_Id);
1381
1382 Item_Is_Output := True;
1383
1384 -- A parameter of an enclosing subprogram; it can appear
1385 -- in Global and behaves as a read-write variable.
1386
1387 else
1388 -- When pragma Global is present it determines the mode
1389 -- of the object.
1390
1391 if Global_Seen then
1392
1393 -- A variable has mode IN when its type is
1394 -- unconstrained or tagged because array bounds,
1395 -- discriminants, or tags can be read.
1396
1397 Item_Is_Input :=
1398 Appears_In (Subp_Inputs, Item_Id)
1399 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1400
1401 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1402
1403 -- Otherwise the variable has a default IN OUT mode
1404
1405 else
1406 Item_Is_Input := True;
1407 Item_Is_Output := True;
1408 end if;
1409 end if;
1410
1411 -- Protected types
1412
1413 when E_Protected_Type =>
1414 if Global_Seen then
1415
1416 -- A variable has mode IN when its type is unconstrained
1417 -- or tagged because array bounds, discriminants or tags
1418 -- can be read.
1419
1420 Item_Is_Input :=
1421 Appears_In (Subp_Inputs, Item_Id)
1422 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1423
1424 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1425
1426 else
1427 -- A protected type acts as a formal parameter of mode IN
1428 -- when it applies to a protected function.
1429
1430 if Ekind (Spec_Id) = E_Function then
1431 Item_Is_Input := True;
1432 Item_Is_Output := False;
1433
1434 -- Otherwise the protected type acts as a formal of mode
1435 -- IN OUT.
1436
1437 else
1438 Item_Is_Input := True;
1439 Item_Is_Output := True;
1440 end if;
1441 end if;
1442
1443 -- Task types
1444
1445 when E_Task_Type =>
1446
1447 -- When pragma Global is present it determines the mode of
1448 -- the object.
1449
1450 if Global_Seen then
1451 Item_Is_Input :=
1452 Appears_In (Subp_Inputs, Item_Id)
1453 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1454
1455 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1456
1457 -- Otherwise task types act as IN OUT parameters
1458
1459 else
1460 Item_Is_Input := True;
1461 Item_Is_Output := True;
1462 end if;
1463
1464 when others =>
1465 raise Program_Error;
1466 end case;
1467 end Find_Role;
1468
1469 ----------------
1470 -- Role_Error --
1471 ----------------
1472
1473 procedure Role_Error
1474 (Item_Is_Input : Boolean;
1475 Item_Is_Output : Boolean)
1476 is
1477 begin
1478 Name_Len := 0;
1479
1480 -- When the item is not part of the input and the output set of
1481 -- the related subprogram, then it appears as extra in pragma
1482 -- [Refined_]Depends.
1483
1484 if not Item_Is_Input and then not Item_Is_Output then
1485 Add_Item_To_Name_Buffer (Item_Id);
1486 Add_Str_To_Name_Buffer
1487 (" & cannot appear in dependence relation");
1488
1489 SPARK_Msg_NE (To_String (Global_Name_Buffer), Item, Item_Id);
1490
1491 Error_Msg_Name_1 := Chars (Spec_Id);
1492 SPARK_Msg_NE
1493 (Fix_Msg (Spec_Id, "\& is not part of the input or output "
1494 & "set of subprogram %"), Item, Item_Id);
1495
1496 -- The mode of the item and its role in pragma [Refined_]Depends
1497 -- are in conflict. Construct a detailed message explaining the
1498 -- illegality (SPARK RM 6.1.5(5-6)).
1499
1500 else
1501 if Item_Is_Input then
1502 Add_Str_To_Name_Buffer ("read-only");
1503 else
1504 Add_Str_To_Name_Buffer ("write-only");
1505 end if;
1506
1507 Add_Char_To_Name_Buffer (' ');
1508 Add_Item_To_Name_Buffer (Item_Id);
1509 Add_Str_To_Name_Buffer (" & cannot appear as ");
1510
1511 if Item_Is_Input then
1512 Add_Str_To_Name_Buffer ("output");
1513 else
1514 Add_Str_To_Name_Buffer ("input");
1515 end if;
1516
1517 Add_Str_To_Name_Buffer (" in dependence relation");
1518
1519 SPARK_Msg_NE (To_String (Global_Name_Buffer), Item, Item_Id);
1520 end if;
1521 end Role_Error;
1522
1523 -- Local variables
1524
1525 Item_Is_Input : Boolean;
1526 Item_Is_Output : Boolean;
1527
1528 -- Start of processing for Check_Role
1529
1530 begin
1531 Find_Role (Item_Is_Input, Item_Is_Output);
1532
1533 -- Input item
1534
1535 if Is_Input then
1536 if not Item_Is_Input then
1537 Role_Error (Item_Is_Input, Item_Is_Output);
1538 end if;
1539
1540 -- Self-referential item
1541
1542 elsif Self_Ref then
1543 if not Item_Is_Input or else not Item_Is_Output then
1544 Role_Error (Item_Is_Input, Item_Is_Output);
1545 end if;
1546
1547 -- Output item
1548
1549 elsif not Item_Is_Output then
1550 Role_Error (Item_Is_Input, Item_Is_Output);
1551 end if;
1552 end Check_Role;
1553
1554 -----------------
1555 -- Check_Usage --
1556 -----------------
1557
1558 procedure Check_Usage
1559 (Subp_Items : Elist_Id;
1560 Used_Items : Elist_Id;
1561 Is_Input : Boolean)
1562 is
1563 procedure Usage_Error (Item_Id : Entity_Id);
1564 -- Emit an error concerning the illegal usage of an item
1565
1566 -----------------
1567 -- Usage_Error --
1568 -----------------
1569
1570 procedure Usage_Error (Item_Id : Entity_Id) is
1571 begin
1572 -- Input case
1573
1574 if Is_Input then
1575
1576 -- Unconstrained and tagged items are not part of the explicit
1577 -- input set of the related subprogram, they do not have to be
1578 -- present in a dependence relation and should not be flagged
1579 -- (SPARK RM 6.1.5(5)).
1580
1581 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1582 Name_Len := 0;
1583
1584 Add_Item_To_Name_Buffer (Item_Id);
1585 Add_Str_To_Name_Buffer
1586 (" & is missing from input dependence list");
1587
1588 SPARK_Msg_NE (To_String (Global_Name_Buffer), N, Item_Id);
1589 SPARK_Msg_NE
1590 ("\add `null ='> &` dependency to ignore this input",
1591 N, Item_Id);
1592 end if;
1593
1594 -- Output case (SPARK RM 6.1.5(10))
1595
1596 else
1597 Name_Len := 0;
1598
1599 Add_Item_To_Name_Buffer (Item_Id);
1600 Add_Str_To_Name_Buffer
1601 (" & is missing from output dependence list");
1602
1603 SPARK_Msg_NE (To_String (Global_Name_Buffer), N, Item_Id);
1604 end if;
1605 end Usage_Error;
1606
1607 -- Local variables
1608
1609 Elmt : Elmt_Id;
1610 Item : Node_Id;
1611 Item_Id : Entity_Id;
1612
1613 -- Start of processing for Check_Usage
1614
1615 begin
1616 if No (Subp_Items) then
1617 return;
1618 end if;
1619
1620 -- Each input or output of the subprogram must appear in a dependency
1621 -- relation.
1622
1623 Elmt := First_Elmt (Subp_Items);
1624 while Present (Elmt) loop
1625 Item := Node (Elmt);
1626
1627 if Nkind (Item) = N_Defining_Identifier then
1628 Item_Id := Item;
1629 else
1630 Item_Id := Entity_Of (Item);
1631 end if;
1632
1633 -- The item does not appear in a dependency
1634
1635 if Present (Item_Id)
1636 and then not Contains (Used_Items, Item_Id)
1637 then
1638 if Is_Formal (Item_Id) then
1639 Usage_Error (Item_Id);
1640
1641 -- The current instance of a protected type behaves as a formal
1642 -- parameter (SPARK RM 6.1.4).
1643
1644 elsif Ekind (Item_Id) = E_Protected_Type
1645 or else Is_Single_Protected_Object (Item_Id)
1646 then
1647 Usage_Error (Item_Id);
1648
1649 -- The current instance of a task type behaves as a formal
1650 -- parameter (SPARK RM 6.1.4).
1651
1652 elsif Ekind (Item_Id) = E_Task_Type
1653 or else Is_Single_Task_Object (Item_Id)
1654 then
1655 -- The dependence of a task unit on itself is implicit and
1656 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1657 -- Emit an error if only one input/output is present.
1658
1659 if Task_Input_Seen /= Task_Output_Seen then
1660 Usage_Error (Item_Id);
1661 end if;
1662
1663 -- States and global objects are not used properly only when
1664 -- the subprogram is subject to pragma Global.
1665
1666 elsif Global_Seen
1667 and then Ekind (Item_Id) in E_Abstract_State
1668 | E_Constant
1669 | E_Loop_Parameter
1670 | E_Protected_Type
1671 | E_Task_Type
1672 | E_Variable
1673 | Formal_Kind
1674 then
1675 Usage_Error (Item_Id);
1676 end if;
1677 end if;
1678
1679 Next_Elmt (Elmt);
1680 end loop;
1681 end Check_Usage;
1682
1683 ----------------------
1684 -- Normalize_Clause --
1685 ----------------------
1686
1687 procedure Normalize_Clause (Clause : Node_Id) is
1688 procedure Create_Or_Modify_Clause
1689 (Output : Node_Id;
1690 Outputs : Node_Id;
1691 Inputs : Node_Id;
1692 After : Node_Id;
1693 In_Place : Boolean;
1694 Multiple : Boolean);
1695 -- Create a brand new clause to represent the self-reference or
1696 -- modify the input and/or output lists of an existing clause. Output
1697 -- denotes a self-referencial output. Outputs is the output list of a
1698 -- clause. Inputs is the input list of a clause. After denotes the
1699 -- clause after which the new clause is to be inserted. Flag In_Place
1700 -- should be set when normalizing the last output of an output list.
1701 -- Flag Multiple should be set when Output comes from a list with
1702 -- multiple items.
1703
1704 -----------------------------
1705 -- Create_Or_Modify_Clause --
1706 -----------------------------
1707
1708 procedure Create_Or_Modify_Clause
1709 (Output : Node_Id;
1710 Outputs : Node_Id;
1711 Inputs : Node_Id;
1712 After : Node_Id;
1713 In_Place : Boolean;
1714 Multiple : Boolean)
1715 is
1716 procedure Propagate_Output
1717 (Output : Node_Id;
1718 Inputs : Node_Id);
1719 -- Handle the various cases of output propagation to the input
1720 -- list. Output denotes a self-referencial output item. Inputs
1721 -- is the input list of a clause.
1722
1723 ----------------------
1724 -- Propagate_Output --
1725 ----------------------
1726
1727 procedure Propagate_Output
1728 (Output : Node_Id;
1729 Inputs : Node_Id)
1730 is
1731 function In_Input_List
1732 (Item : Entity_Id;
1733 Inputs : List_Id) return Boolean;
1734 -- Determine whether a particulat item appears in the input
1735 -- list of a clause.
1736
1737 -------------------
1738 -- In_Input_List --
1739 -------------------
1740
1741 function In_Input_List
1742 (Item : Entity_Id;
1743 Inputs : List_Id) return Boolean
1744 is
1745 Elmt : Node_Id;
1746
1747 begin
1748 Elmt := First (Inputs);
1749 while Present (Elmt) loop
1750 if Entity_Of (Elmt) = Item then
1751 return True;
1752 end if;
1753
1754 Next (Elmt);
1755 end loop;
1756
1757 return False;
1758 end In_Input_List;
1759
1760 -- Local variables
1761
1762 Output_Id : constant Entity_Id := Entity_Of (Output);
1763 Grouped : List_Id;
1764
1765 -- Start of processing for Propagate_Output
1766
1767 begin
1768 -- The clause is of the form:
1769
1770 -- (Output =>+ null)
1771
1772 -- Remove null input and replace it with a copy of the output:
1773
1774 -- (Output => Output)
1775
1776 if Nkind (Inputs) = N_Null then
1777 Rewrite (Inputs, New_Copy_Tree (Output));
1778
1779 -- The clause is of the form:
1780
1781 -- (Output =>+ (Input1, ..., InputN))
1782
1783 -- Determine whether the output is not already mentioned in the
1784 -- input list and if not, add it to the list of inputs:
1785
1786 -- (Output => (Output, Input1, ..., InputN))
1787
1788 elsif Nkind (Inputs) = N_Aggregate then
1789 Grouped := Expressions (Inputs);
1790
1791 if not In_Input_List
1792 (Item => Output_Id,
1793 Inputs => Grouped)
1794 then
1795 Prepend_To (Grouped, New_Copy_Tree (Output));
1796 end if;
1797
1798 -- The clause is of the form:
1799
1800 -- (Output =>+ Input)
1801
1802 -- If the input does not mention the output, group the two
1803 -- together:
1804
1805 -- (Output => (Output, Input))
1806
1807 elsif Entity_Of (Inputs) /= Output_Id then
1808 Rewrite (Inputs,
1809 Make_Aggregate (Loc,
1810 Expressions => New_List (
1811 New_Copy_Tree (Output),
1812 New_Copy_Tree (Inputs))));
1813 end if;
1814 end Propagate_Output;
1815
1816 -- Local variables
1817
1818 Loc : constant Source_Ptr := Sloc (Clause);
1819 New_Clause : Node_Id;
1820
1821 -- Start of processing for Create_Or_Modify_Clause
1822
1823 begin
1824 -- A null output depending on itself does not require any
1825 -- normalization.
1826
1827 if Nkind (Output) = N_Null then
1828 return;
1829
1830 -- A function result cannot depend on itself because it cannot
1831 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1832
1833 elsif Is_Attribute_Result (Output) then
1834 SPARK_Msg_N ("function result cannot depend on itself", Output);
1835 return;
1836 end if;
1837
1838 -- When performing the transformation in place, simply add the
1839 -- output to the list of inputs (if not already there). This
1840 -- case arises when dealing with the last output of an output
1841 -- list. Perform the normalization in place to avoid generating
1842 -- a malformed tree.
1843
1844 if In_Place then
1845 Propagate_Output (Output, Inputs);
1846
1847 -- A list with multiple outputs is slowly trimmed until only
1848 -- one element remains. When this happens, replace aggregate
1849 -- with the element itself.
1850
1851 if Multiple then
1852 Remove (Output);
1853 Rewrite (Outputs, Output);
1854 end if;
1855
1856 -- Default case
1857
1858 else
1859 -- Unchain the output from its output list as it will appear in
1860 -- a new clause. Note that we cannot simply rewrite the output
1861 -- as null because this will violate the semantics of pragma
1862 -- Depends.
1863
1864 Remove (Output);
1865
1866 -- Generate a new clause of the form:
1867 -- (Output => Inputs)
1868
1869 New_Clause :=
1870 Make_Component_Association (Loc,
1871 Choices => New_List (Output),
1872 Expression => New_Copy_Tree (Inputs));
1873
1874 -- The new clause contains replicated content that has already
1875 -- been analyzed. There is not need to reanalyze or renormalize
1876 -- it again.
1877
1878 Set_Analyzed (New_Clause);
1879
1880 Propagate_Output
1881 (Output => First (Choices (New_Clause)),
1882 Inputs => Expression (New_Clause));
1883
1884 Insert_After (After, New_Clause);
1885 end if;
1886 end Create_Or_Modify_Clause;
1887
1888 -- Local variables
1889
1890 Outputs : constant Node_Id := First (Choices (Clause));
1891 Inputs : Node_Id;
1892 Last_Output : Node_Id;
1893 Next_Output : Node_Id;
1894 Output : Node_Id;
1895
1896 -- Start of processing for Normalize_Clause
1897
1898 begin
1899 -- A self-dependency appears as operator "+". Remove the "+" from the
1900 -- tree by moving the real inputs to their proper place.
1901
1902 if Nkind (Expression (Clause)) = N_Op_Plus then
1903 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1904 Inputs := Expression (Clause);
1905
1906 -- Multiple outputs appear as an aggregate
1907
1908 if Nkind (Outputs) = N_Aggregate then
1909 Last_Output := Last (Expressions (Outputs));
1910
1911 Output := First (Expressions (Outputs));
1912 while Present (Output) loop
1913
1914 -- Normalization may remove an output from its list,
1915 -- preserve the subsequent output now.
1916
1917 Next_Output := Next (Output);
1918
1919 Create_Or_Modify_Clause
1920 (Output => Output,
1921 Outputs => Outputs,
1922 Inputs => Inputs,
1923 After => Clause,
1924 In_Place => Output = Last_Output,
1925 Multiple => True);
1926
1927 Output := Next_Output;
1928 end loop;
1929
1930 -- Solitary output
1931
1932 else
1933 Create_Or_Modify_Clause
1934 (Output => Outputs,
1935 Outputs => Empty,
1936 Inputs => Inputs,
1937 After => Empty,
1938 In_Place => True,
1939 Multiple => False);
1940 end if;
1941 end if;
1942 end Normalize_Clause;
1943
1944 -- Local variables
1945
1946 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
1947 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1948
1949 Clause : Node_Id;
1950 Errors : Nat;
1951 Last_Clause : Node_Id;
1952 Restore_Scope : Boolean := False;
1953
1954 -- Start of processing for Analyze_Depends_In_Decl_Part
1955
1956 begin
1957 -- Do not analyze the pragma multiple times
1958
1959 if Is_Analyzed_Pragma (N) then
1960 return;
1961 end if;
1962
1963 -- Empty dependency list
1964
1965 if Nkind (Deps) = N_Null then
1966
1967 -- Gather all states, objects and formal parameters that the
1968 -- subprogram may depend on. These items are obtained from the
1969 -- parameter profile or pragma [Refined_]Global (if available).
1970
1971 Collect_Subprogram_Inputs_Outputs
1972 (Subp_Id => Subp_Id,
1973 Subp_Inputs => Subp_Inputs,
1974 Subp_Outputs => Subp_Outputs,
1975 Global_Seen => Global_Seen);
1976
1977 -- Verify that every input or output of the subprogram appear in a
1978 -- dependency.
1979
1980 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1981 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1982 Check_Function_Return;
1983
1984 -- Dependency clauses appear as component associations of an aggregate
1985
1986 elsif Nkind (Deps) = N_Aggregate then
1987
1988 -- Do not attempt to perform analysis of a syntactically illegal
1989 -- clause as this will lead to misleading errors.
1990
1991 if Has_Extra_Parentheses (Deps) then
1992 goto Leave;
1993 end if;
1994
1995 if Present (Component_Associations (Deps)) then
1996 Last_Clause := Last (Component_Associations (Deps));
1997
1998 -- Gather all states, objects and formal parameters that the
1999 -- subprogram may depend on. These items are obtained from the
2000 -- parameter profile or pragma [Refined_]Global (if available).
2001
2002 Collect_Subprogram_Inputs_Outputs
2003 (Subp_Id => Subp_Id,
2004 Subp_Inputs => Subp_Inputs,
2005 Subp_Outputs => Subp_Outputs,
2006 Global_Seen => Global_Seen);
2007
2008 -- When pragma [Refined_]Depends appears on a single concurrent
2009 -- type, it is relocated to the anonymous object.
2010
2011 if Is_Single_Concurrent_Object (Spec_Id) then
2012 null;
2013
2014 -- Ensure that the formal parameters are visible when analyzing
2015 -- all clauses. This falls out of the general rule of aspects
2016 -- pertaining to subprogram declarations.
2017
2018 elsif not In_Open_Scopes (Spec_Id) then
2019 Restore_Scope := True;
2020 Push_Scope (Spec_Id);
2021
2022 if Ekind (Spec_Id) = E_Task_Type then
2023
2024 -- Task discriminants cannot appear in the [Refined_]Depends
2025 -- contract, but must be present for the analysis so that we
2026 -- can reject them with an informative error message.
2027
2028 if Has_Discriminants (Spec_Id) then
2029 Install_Discriminants (Spec_Id);
2030 end if;
2031
2032 elsif Is_Generic_Subprogram (Spec_Id) then
2033 Install_Generic_Formals (Spec_Id);
2034
2035 else
2036 Install_Formals (Spec_Id);
2037 end if;
2038 end if;
2039
2040 Clause := First (Component_Associations (Deps));
2041 while Present (Clause) loop
2042 Errors := Serious_Errors_Detected;
2043
2044 -- The normalization mechanism may create extra clauses that
2045 -- contain replicated input and output names. There is no need
2046 -- to reanalyze them.
2047
2048 if not Analyzed (Clause) then
2049 Set_Analyzed (Clause);
2050
2051 Analyze_Dependency_Clause
2052 (Clause => Clause,
2053 Is_Last => Clause = Last_Clause);
2054 end if;
2055
2056 -- Do not normalize a clause if errors were detected (count
2057 -- of Serious_Errors has increased) because the inputs and/or
2058 -- outputs may denote illegal items.
2059
2060 if Serious_Errors_Detected = Errors then
2061 Normalize_Clause (Clause);
2062 end if;
2063
2064 Next (Clause);
2065 end loop;
2066
2067 if Restore_Scope then
2068 End_Scope;
2069 end if;
2070
2071 -- Verify that every input or output of the subprogram appear in a
2072 -- dependency.
2073
2074 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
2075 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
2076 Check_Function_Return;
2077
2078 -- The dependency list is malformed. This is a syntax error, always
2079 -- report.
2080
2081 else
2082 Error_Msg_N ("malformed dependency relation", Deps);
2083 goto Leave;
2084 end if;
2085
2086 -- The top level dependency relation is malformed. This is a syntax
2087 -- error, always report.
2088
2089 else
2090 Error_Msg_N ("malformed dependency relation", Deps);
2091 goto Leave;
2092 end if;
2093
2094 -- Ensure that a state and a corresponding constituent do not appear
2095 -- together in pragma [Refined_]Depends.
2096
2097 Check_State_And_Constituent_Use
2098 (States => States_Seen,
2099 Constits => Constits_Seen,
2100 Context => N);
2101
2102 <<Leave>>
2103 Set_Is_Analyzed_Pragma (N);
2104 end Analyze_Depends_In_Decl_Part;
2105
2106 --------------------------------------------
2107 -- Analyze_External_Property_In_Decl_Part --
2108 --------------------------------------------
2109
2110 procedure Analyze_External_Property_In_Decl_Part
2111 (N : Node_Id;
2112 Expr_Val : out Boolean)
2113 is
2114 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pragma_Name (N));
2115 Arg1 : constant Node_Id :=
2116 First (Pragma_Argument_Associations (N));
2117 Obj_Decl : constant Node_Id := Find_Related_Context (N);
2118 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
2119 Expr : Node_Id;
2120
2121 begin
2122 -- Ensure that the Boolean expression (if present) is static. A missing
2123 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2124
2125 Expr_Val := True;
2126
2127 if Present (Arg1) then
2128 Expr := Get_Pragma_Arg (Arg1);
2129
2130 if Is_OK_Static_Expression (Expr) then
2131 Expr_Val := Is_True (Expr_Value (Expr));
2132 end if;
2133 end if;
2134
2135 -- The output parameter was set to the argument specified by the pragma.
2136 -- Do not analyze the pragma multiple times.
2137
2138 if Is_Analyzed_Pragma (N) then
2139 return;
2140 end if;
2141
2142 Error_Msg_Name_1 := Pragma_Name (N);
2143
2144 -- An external property pragma must apply to an effectively volatile
2145 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
2146 -- The check is performed at the end of the declarative region due to a
2147 -- possible out-of-order arrangement of pragmas:
2148
2149 -- Obj : ...;
2150 -- pragma Async_Readers (Obj);
2151 -- pragma Volatile (Obj);
2152
2153 if Prag_Id /= Pragma_No_Caching
2154 and then not Is_Effectively_Volatile (Obj_Id)
2155 then
2156 if Ekind (Obj_Id) = E_Variable
2157 and then No_Caching_Enabled (Obj_Id)
2158 then
2159 if Expr_Val then -- Confirming value of False is allowed
2160 SPARK_Msg_N
2161 ("illegal combination of external property % and property "
2162 & """No_Caching"" (SPARK RM 7.1.2(6))", N);
2163 end if;
2164 else
2165 SPARK_Msg_N
2166 ("external property % must apply to a volatile type or object",
2167 N);
2168 end if;
2169
2170 -- Pragma No_Caching should only apply to volatile variables of
2171 -- a non-effectively volatile type (SPARK RM 7.1.2).
2172
2173 elsif Prag_Id = Pragma_No_Caching then
2174 if Is_Effectively_Volatile (Etype (Obj_Id)) then
2175 SPARK_Msg_N ("property % must not apply to an object of "
2176 & "an effectively volatile type", N);
2177 elsif not Is_Volatile (Obj_Id) then
2178 SPARK_Msg_N ("property % must apply to a volatile object", N);
2179 end if;
2180 end if;
2181
2182 Set_Is_Analyzed_Pragma (N);
2183 end Analyze_External_Property_In_Decl_Part;
2184
2185 ---------------------------------
2186 -- Analyze_Global_In_Decl_Part --
2187 ---------------------------------
2188
2189 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
2190 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2191 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2192 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2193
2194 Constits_Seen : Elist_Id := No_Elist;
2195 -- A list containing the entities of all constituents processed so far.
2196 -- It aids in detecting illegal usage of a state and a corresponding
2197 -- constituent in pragma [Refinde_]Global.
2198
2199 Seen : Elist_Id := No_Elist;
2200 -- A list containing the entities of all the items processed so far. It
2201 -- plays a role in detecting distinct entities.
2202
2203 States_Seen : Elist_Id := No_Elist;
2204 -- A list containing the entities of all states processed so far. It
2205 -- helps in detecting illegal usage of a state and a corresponding
2206 -- constituent in pragma [Refined_]Global.
2207
2208 In_Out_Seen : Boolean := False;
2209 Input_Seen : Boolean := False;
2210 Output_Seen : Boolean := False;
2211 Proof_Seen : Boolean := False;
2212 -- Flags used to verify the consistency of modes
2213
2214 procedure Analyze_Global_List
2215 (List : Node_Id;
2216 Global_Mode : Name_Id := Name_Input);
2217 -- Verify the legality of a single global list declaration. Global_Mode
2218 -- denotes the current mode in effect.
2219
2220 -------------------------
2221 -- Analyze_Global_List --
2222 -------------------------
2223
2224 procedure Analyze_Global_List
2225 (List : Node_Id;
2226 Global_Mode : Name_Id := Name_Input)
2227 is
2228 procedure Analyze_Global_Item
2229 (Item : Node_Id;
2230 Global_Mode : Name_Id);
2231 -- Verify the legality of a single global item declaration denoted by
2232 -- Item. Global_Mode denotes the current mode in effect.
2233
2234 procedure Check_Duplicate_Mode
2235 (Mode : Node_Id;
2236 Status : in out Boolean);
2237 -- Flag Status denotes whether a particular mode has been seen while
2238 -- processing a global list. This routine verifies that Mode is not a
2239 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2240
2241 procedure Check_Mode_Restriction_In_Enclosing_Context
2242 (Item : Node_Id;
2243 Item_Id : Entity_Id);
2244 -- Verify that an item of mode In_Out or Output does not appear as
2245 -- an input in the Global aspect of an enclosing subprogram or task
2246 -- unit. If this is the case, emit an error. Item and Item_Id are
2247 -- respectively the item and its entity.
2248
2249 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
2250 -- Mode denotes either In_Out or Output. Depending on the kind of the
2251 -- related subprogram, emit an error if those two modes apply to a
2252 -- function (SPARK RM 6.1.4(10)).
2253
2254 -------------------------
2255 -- Analyze_Global_Item --
2256 -------------------------
2257
2258 procedure Analyze_Global_Item
2259 (Item : Node_Id;
2260 Global_Mode : Name_Id)
2261 is
2262 Item_Id : Entity_Id;
2263
2264 begin
2265 -- Detect one of the following cases
2266
2267 -- with Global => (null, Name)
2268 -- with Global => (Name_1, null, Name_2)
2269 -- with Global => (Name, null)
2270
2271 if Nkind (Item) = N_Null then
2272 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
2273 return;
2274 end if;
2275
2276 Analyze (Item);
2277 Resolve_State (Item);
2278
2279 -- Find the entity of the item. If this is a renaming, climb the
2280 -- renaming chain to reach the root object. Renamings of non-
2281 -- entire objects do not yield an entity (Empty).
2282
2283 Item_Id := Entity_Of (Item);
2284
2285 if Present (Item_Id) then
2286
2287 -- A global item may denote a formal parameter of an enclosing
2288 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2289 -- provide a better error diagnostic.
2290
2291 if Is_Formal (Item_Id) then
2292 if Scope (Item_Id) = Spec_Id then
2293 SPARK_Msg_NE
2294 (Fix_Msg (Spec_Id, "global item cannot reference "
2295 & "parameter of subprogram &"), Item, Spec_Id);
2296 return;
2297 end if;
2298
2299 -- A global item may denote a concurrent type as long as it is
2300 -- the current instance of an enclosing protected or task type
2301 -- (SPARK RM 6.1.4).
2302
2303 elsif Ekind (Item_Id) in E_Protected_Type | E_Task_Type then
2304 if Is_CCT_Instance (Item_Id, Spec_Id) then
2305
2306 -- Pragma [Refined_]Global associated with a protected
2307 -- subprogram cannot mention the current instance of a
2308 -- protected type because the instance behaves as a
2309 -- formal parameter.
2310
2311 if Ekind (Item_Id) = E_Protected_Type then
2312 if Scope (Spec_Id) = Item_Id then
2313 Error_Msg_Name_1 := Chars (Item_Id);
2314 SPARK_Msg_NE
2315 (Fix_Msg (Spec_Id, "global item of subprogram & "
2316 & "cannot reference current instance of "
2317 & "protected type %"), Item, Spec_Id);
2318 return;
2319 end if;
2320
2321 -- Pragma [Refined_]Global associated with a task type
2322 -- cannot mention the current instance of a task type
2323 -- because the instance behaves as a formal parameter.
2324
2325 else pragma Assert (Ekind (Item_Id) = E_Task_Type);
2326 if Spec_Id = Item_Id then
2327 Error_Msg_Name_1 := Chars (Item_Id);
2328 SPARK_Msg_NE
2329 (Fix_Msg (Spec_Id, "global item of subprogram & "
2330 & "cannot reference current instance of task "
2331 & "type %"), Item, Spec_Id);
2332 return;
2333 end if;
2334 end if;
2335
2336 -- Otherwise the global item denotes a subtype mark that is
2337 -- not a current instance.
2338
2339 else
2340 SPARK_Msg_N
2341 ("invalid use of subtype mark in global list", Item);
2342 return;
2343 end if;
2344
2345 -- A global item may denote the anonymous object created for a
2346 -- single protected/task type as long as the current instance
2347 -- is the same single type (SPARK RM 6.1.4).
2348
2349 elsif Is_Single_Concurrent_Object (Item_Id)
2350 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
2351 then
2352 -- Pragma [Refined_]Global associated with a protected
2353 -- subprogram cannot mention the current instance of a
2354 -- protected type because the instance behaves as a formal
2355 -- parameter.
2356
2357 if Is_Single_Protected_Object (Item_Id) then
2358 if Scope (Spec_Id) = Etype (Item_Id) then
2359 Error_Msg_Name_1 := Chars (Item_Id);
2360 SPARK_Msg_NE
2361 (Fix_Msg (Spec_Id, "global item of subprogram & "
2362 & "cannot reference current instance of protected "
2363 & "type %"), Item, Spec_Id);
2364 return;
2365 end if;
2366
2367 -- Pragma [Refined_]Global associated with a task type
2368 -- cannot mention the current instance of a task type
2369 -- because the instance behaves as a formal parameter.
2370
2371 else pragma Assert (Is_Single_Task_Object (Item_Id));
2372 if Spec_Id = Item_Id then
2373 Error_Msg_Name_1 := Chars (Item_Id);
2374 SPARK_Msg_NE
2375 (Fix_Msg (Spec_Id, "global item of subprogram & "
2376 & "cannot reference current instance of task "
2377 & "type %"), Item, Spec_Id);
2378 return;
2379 end if;
2380 end if;
2381
2382 -- A formal object may act as a global item inside a generic
2383
2384 elsif Is_Formal_Object (Item_Id) then
2385 null;
2386
2387 elsif Ekind (Item_Id) in E_Constant | E_Variable
2388 and then Present (Ultimate_Overlaid_Entity (Item_Id))
2389 then
2390 SPARK_Msg_NE
2391 ("overlaying object & cannot appear in Global",
2392 Item, Item_Id);
2393 SPARK_Msg_NE
2394 ("\use the overlaid object & instead",
2395 Item, Ultimate_Overlaid_Entity (Item_Id));
2396 return;
2397
2398 -- The only legal references are those to abstract states,
2399 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2400
2401 elsif Ekind (Item_Id) not in E_Abstract_State
2402 | E_Constant
2403 | E_Loop_Parameter
2404 | E_Variable
2405 then
2406 SPARK_Msg_N
2407 ("global item must denote object, state or current "
2408 & "instance of concurrent type", Item);
2409
2410 if Is_Named_Number (Item_Id) then
2411 SPARK_Msg_NE
2412 ("\named number & is not an object", Item, Item_Id);
2413 end if;
2414
2415 return;
2416 end if;
2417
2418 -- State related checks
2419
2420 if Ekind (Item_Id) = E_Abstract_State then
2421
2422 -- Package and subprogram bodies are instantiated
2423 -- individually in a separate compiler pass. Due to this
2424 -- mode of instantiation, the refinement of a state may
2425 -- no longer be visible when a subprogram body contract
2426 -- is instantiated. Since the generic template is legal,
2427 -- do not perform this check in the instance to circumvent
2428 -- this oddity.
2429
2430 if In_Instance then
2431 null;
2432
2433 -- An abstract state with visible refinement cannot appear
2434 -- in pragma [Refined_]Global as its place must be taken by
2435 -- some of its constituents (SPARK RM 6.1.4(7)).
2436
2437 elsif Has_Visible_Refinement (Item_Id) then
2438 SPARK_Msg_NE
2439 ("cannot mention state & in global refinement",
2440 Item, Item_Id);
2441 SPARK_Msg_N ("\use its constituents instead", Item);
2442 return;
2443
2444 -- An external state which has Async_Writers or
2445 -- Effective_Reads enabled cannot appear as a global item
2446 -- of a nonvolatile function (SPARK RM 7.1.3(8)).
2447
2448 elsif Is_External_State (Item_Id)
2449 and then (Async_Writers_Enabled (Item_Id)
2450 or else Effective_Reads_Enabled (Item_Id))
2451 and then Ekind (Spec_Id) in E_Function | E_Generic_Function
2452 and then not Is_Volatile_Function (Spec_Id)
2453 then
2454 SPARK_Msg_NE
2455 ("external state & cannot act as global item of "
2456 & "nonvolatile function", Item, Item_Id);
2457 return;
2458
2459 -- If the reference to the abstract state appears in an
2460 -- enclosing package body that will eventually refine the
2461 -- state, record the reference for future checks.
2462
2463 else
2464 Record_Possible_Body_Reference
2465 (State_Id => Item_Id,
2466 Ref => Item);
2467 end if;
2468
2469 -- Constant related checks
2470
2471 elsif Ekind (Item_Id) = E_Constant then
2472
2473 -- Constant is a read-only item, therefore it cannot act as
2474 -- an output.
2475
2476 if Global_Mode in Name_In_Out | Name_Output then
2477
2478 -- Constant of an access-to-variable type is a read-write
2479 -- item in procedures, generic procedures, protected
2480 -- entries and tasks.
2481
2482 if Is_Access_Variable (Etype (Item_Id))
2483 and then (Ekind (Spec_Id) in E_Entry
2484 | E_Entry_Family
2485 | E_Procedure
2486 | E_Generic_Procedure
2487 | E_Task_Type
2488 or else Is_Single_Task_Object (Spec_Id))
2489 then
2490 null;
2491 else
2492 SPARK_Msg_NE
2493 ("constant & cannot act as output", Item, Item_Id);
2494 return;
2495 end if;
2496 end if;
2497
2498 -- Loop parameter related checks
2499
2500 elsif Ekind (Item_Id) = E_Loop_Parameter then
2501
2502 -- A loop parameter is a read-only item, therefore it cannot
2503 -- act as an output.
2504
2505 if Global_Mode in Name_In_Out | Name_Output then
2506 SPARK_Msg_NE
2507 ("loop parameter & cannot act as output",
2508 Item, Item_Id);
2509 return;
2510 end if;
2511
2512 -- Variable related checks. These are only relevant when
2513 -- SPARK_Mode is on as they are not standard Ada legality
2514 -- rules.
2515
2516 elsif SPARK_Mode = On
2517 and then Ekind (Item_Id) = E_Variable
2518 and then Is_Effectively_Volatile_For_Reading (Item_Id)
2519 then
2520 -- The current instance of a protected unit is not an
2521 -- effectively volatile object, unless the protected unit
2522 -- is already volatile for another reason (SPARK RM 7.1.2).
2523
2524 if Is_Single_Protected_Object (Item_Id)
2525 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
2526 and then not Is_Effectively_Volatile_For_Reading
2527 (Item_Id, Ignore_Protected => True)
2528 then
2529 null;
2530
2531 -- An effectively volatile object for reading cannot appear
2532 -- as a global item of a nonvolatile function (SPARK RM
2533 -- 7.1.3(8)).
2534
2535 elsif Ekind (Spec_Id) in E_Function | E_Generic_Function
2536 and then not Is_Volatile_Function (Spec_Id)
2537 then
2538 Error_Msg_NE
2539 ("volatile object & cannot act as global item of a "
2540 & "function", Item, Item_Id);
2541 return;
2542
2543 -- An effectively volatile object with external property
2544 -- Effective_Reads set to True must have mode Output or
2545 -- In_Out (SPARK RM 7.1.3(10)).
2546
2547 elsif Effective_Reads_Enabled (Item_Id)
2548 and then Global_Mode = Name_Input
2549 then
2550 Error_Msg_NE
2551 ("volatile object & with property Effective_Reads must "
2552 & "have mode In_Out or Output", Item, Item_Id);
2553 return;
2554 end if;
2555 end if;
2556
2557 -- When the item renames an entire object, replace the item
2558 -- with a reference to the object.
2559
2560 if Entity (Item) /= Item_Id then
2561 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2562 Analyze (Item);
2563 end if;
2564
2565 -- Some form of illegal construct masquerading as a name
2566 -- (SPARK RM 6.1.4(4)).
2567
2568 else
2569 Error_Msg_N
2570 ("global item must denote object, state or current instance "
2571 & "of concurrent type", Item);
2572 return;
2573 end if;
2574
2575 -- Verify that an output does not appear as an input in an
2576 -- enclosing subprogram.
2577
2578 if Global_Mode in Name_In_Out | Name_Output then
2579 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2580 end if;
2581
2582 -- The same entity might be referenced through various way.
2583 -- Check the entity of the item rather than the item itself
2584 -- (SPARK RM 6.1.4(10)).
2585
2586 if Contains (Seen, Item_Id) then
2587 SPARK_Msg_N ("duplicate global item", Item);
2588
2589 -- Add the entity of the current item to the list of processed
2590 -- items.
2591
2592 else
2593 Append_New_Elmt (Item_Id, Seen);
2594
2595 if Ekind (Item_Id) = E_Abstract_State then
2596 Append_New_Elmt (Item_Id, States_Seen);
2597
2598 -- The variable may eventually become a constituent of a single
2599 -- protected/task type. Record the reference now and verify its
2600 -- legality when analyzing the contract of the variable
2601 -- (SPARK RM 9.3).
2602
2603 elsif Ekind (Item_Id) = E_Variable then
2604 Record_Possible_Part_Of_Reference
2605 (Var_Id => Item_Id,
2606 Ref => Item);
2607 end if;
2608
2609 if Ekind (Item_Id) in E_Abstract_State | E_Constant | E_Variable
2610 and then Present (Encapsulating_State (Item_Id))
2611 then
2612 Append_New_Elmt (Item_Id, Constits_Seen);
2613 end if;
2614 end if;
2615 end Analyze_Global_Item;
2616
2617 --------------------------
2618 -- Check_Duplicate_Mode --
2619 --------------------------
2620
2621 procedure Check_Duplicate_Mode
2622 (Mode : Node_Id;
2623 Status : in out Boolean)
2624 is
2625 begin
2626 if Status then
2627 SPARK_Msg_N ("duplicate global mode", Mode);
2628 end if;
2629
2630 Status := True;
2631 end Check_Duplicate_Mode;
2632
2633 -------------------------------------------------
2634 -- Check_Mode_Restriction_In_Enclosing_Context --
2635 -------------------------------------------------
2636
2637 procedure Check_Mode_Restriction_In_Enclosing_Context
2638 (Item : Node_Id;
2639 Item_Id : Entity_Id)
2640 is
2641 Context : Entity_Id;
2642 Dummy : Boolean;
2643 Inputs : Elist_Id := No_Elist;
2644 Outputs : Elist_Id := No_Elist;
2645
2646 begin
2647 -- Traverse the scope stack looking for enclosing subprograms or
2648 -- tasks subject to pragma [Refined_]Global.
2649
2650 Context := Scope (Subp_Id);
2651 while Present (Context) and then Context /= Standard_Standard loop
2652
2653 -- For a single task type, retrieve the corresponding object to
2654 -- which pragma [Refined_]Global is attached.
2655
2656 if Ekind (Context) = E_Task_Type
2657 and then Is_Single_Concurrent_Type (Context)
2658 then
2659 Context := Anonymous_Object (Context);
2660 end if;
2661
2662 if Is_Subprogram_Or_Entry (Context)
2663 or else Ekind (Context) = E_Task_Type
2664 or else Is_Single_Task_Object (Context)
2665 then
2666 Collect_Subprogram_Inputs_Outputs
2667 (Subp_Id => Context,
2668 Subp_Inputs => Inputs,
2669 Subp_Outputs => Outputs,
2670 Global_Seen => Dummy);
2671
2672 -- The item is classified as In_Out or Output but appears as
2673 -- an Input or a formal parameter of mode IN in an enclosing
2674 -- subprogram or task unit (SPARK RM 6.1.4(13)).
2675
2676 if Appears_In (Inputs, Item_Id)
2677 and then not Appears_In (Outputs, Item_Id)
2678 then
2679 SPARK_Msg_NE
2680 ("global item & cannot have mode In_Out or Output",
2681 Item, Item_Id);
2682
2683 if Is_Subprogram_Or_Entry (Context) then
2684 SPARK_Msg_NE
2685 (Fix_Msg (Subp_Id, "\item already appears as input "
2686 & "of subprogram &"), Item, Context);
2687 else
2688 SPARK_Msg_NE
2689 (Fix_Msg (Subp_Id, "\item already appears as input "
2690 & "of task &"), Item, Context);
2691 end if;
2692
2693 -- Stop the traversal once an error has been detected
2694
2695 exit;
2696 end if;
2697 end if;
2698
2699 Context := Scope (Context);
2700 end loop;
2701 end Check_Mode_Restriction_In_Enclosing_Context;
2702
2703 ----------------------------------------
2704 -- Check_Mode_Restriction_In_Function --
2705 ----------------------------------------
2706
2707 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2708 begin
2709 if Ekind (Spec_Id) in E_Function | E_Generic_Function then
2710 SPARK_Msg_N
2711 ("global mode & is not applicable to functions", Mode);
2712 end if;
2713 end Check_Mode_Restriction_In_Function;
2714
2715 -- Local variables
2716
2717 Assoc : Node_Id;
2718 Item : Node_Id;
2719 Mode : Node_Id;
2720
2721 -- Start of processing for Analyze_Global_List
2722
2723 begin
2724 if Nkind (List) = N_Null then
2725 Set_Analyzed (List);
2726
2727 -- Single global item declaration
2728
2729 elsif Nkind (List) in N_Expanded_Name
2730 | N_Identifier
2731 | N_Selected_Component
2732 then
2733 Analyze_Global_Item (List, Global_Mode);
2734
2735 -- Simple global list or moded global list declaration
2736
2737 elsif Nkind (List) = N_Aggregate then
2738 Set_Analyzed (List);
2739
2740 -- The declaration of a simple global list appear as a collection
2741 -- of expressions.
2742
2743 if Present (Expressions (List)) then
2744 if Present (Component_Associations (List)) then
2745 SPARK_Msg_N
2746 ("cannot mix moded and non-moded global lists", List);
2747 end if;
2748
2749 Item := First (Expressions (List));
2750 while Present (Item) loop
2751 Analyze_Global_Item (Item, Global_Mode);
2752 Next (Item);
2753 end loop;
2754
2755 -- The declaration of a moded global list appears as a collection
2756 -- of component associations where individual choices denote
2757 -- modes.
2758
2759 elsif Present (Component_Associations (List)) then
2760 if Present (Expressions (List)) then
2761 SPARK_Msg_N
2762 ("cannot mix moded and non-moded global lists", List);
2763 end if;
2764
2765 Assoc := First (Component_Associations (List));
2766 while Present (Assoc) loop
2767 Mode := First (Choices (Assoc));
2768
2769 if Nkind (Mode) = N_Identifier then
2770 if Chars (Mode) = Name_In_Out then
2771 Check_Duplicate_Mode (Mode, In_Out_Seen);
2772 Check_Mode_Restriction_In_Function (Mode);
2773
2774 elsif Chars (Mode) = Name_Input then
2775 Check_Duplicate_Mode (Mode, Input_Seen);
2776
2777 elsif Chars (Mode) = Name_Output then
2778 Check_Duplicate_Mode (Mode, Output_Seen);
2779 Check_Mode_Restriction_In_Function (Mode);
2780
2781 elsif Chars (Mode) = Name_Proof_In then
2782 Check_Duplicate_Mode (Mode, Proof_Seen);
2783
2784 else
2785 SPARK_Msg_N ("invalid mode selector", Mode);
2786 end if;
2787
2788 else
2789 SPARK_Msg_N ("invalid mode selector", Mode);
2790 end if;
2791
2792 -- Items in a moded list appear as a collection of
2793 -- expressions. Reuse the existing machinery to analyze
2794 -- them.
2795
2796 Analyze_Global_List
2797 (List => Expression (Assoc),
2798 Global_Mode => Chars (Mode));
2799
2800 Next (Assoc);
2801 end loop;
2802
2803 -- Invalid tree
2804
2805 else
2806 raise Program_Error;
2807 end if;
2808
2809 -- Any other attempt to declare a global item is illegal. This is a
2810 -- syntax error, always report.
2811
2812 else
2813 Error_Msg_N ("malformed global list", List);
2814 end if;
2815 end Analyze_Global_List;
2816
2817 -- Local variables
2818
2819 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2820
2821 Restore_Scope : Boolean := False;
2822
2823 -- Start of processing for Analyze_Global_In_Decl_Part
2824
2825 begin
2826 -- Do not analyze the pragma multiple times
2827
2828 if Is_Analyzed_Pragma (N) then
2829 return;
2830 end if;
2831
2832 -- There is nothing to be done for a null global list
2833
2834 if Nkind (Items) = N_Null then
2835 Set_Analyzed (Items);
2836
2837 -- Analyze the various forms of global lists and items. Note that some
2838 -- of these may be malformed in which case the analysis emits error
2839 -- messages.
2840
2841 else
2842 -- When pragma [Refined_]Global appears on a single concurrent type,
2843 -- it is relocated to the anonymous object.
2844
2845 if Is_Single_Concurrent_Object (Spec_Id) then
2846 null;
2847
2848 -- Ensure that the formal parameters are visible when processing an
2849 -- item. This falls out of the general rule of aspects pertaining to
2850 -- subprogram declarations.
2851
2852 elsif not In_Open_Scopes (Spec_Id) then
2853 Restore_Scope := True;
2854 Push_Scope (Spec_Id);
2855
2856 if Ekind (Spec_Id) = E_Task_Type then
2857
2858 -- Task discriminants cannot appear in the [Refined_]Global
2859 -- contract, but must be present for the analysis so that we
2860 -- can reject them with an informative error message.
2861
2862 if Has_Discriminants (Spec_Id) then
2863 Install_Discriminants (Spec_Id);
2864 end if;
2865
2866 elsif Is_Generic_Subprogram (Spec_Id) then
2867 Install_Generic_Formals (Spec_Id);
2868
2869 else
2870 Install_Formals (Spec_Id);
2871 end if;
2872 end if;
2873
2874 Analyze_Global_List (Items);
2875
2876 if Restore_Scope then
2877 End_Scope;
2878 end if;
2879 end if;
2880
2881 -- Ensure that a state and a corresponding constituent do not appear
2882 -- together in pragma [Refined_]Global.
2883
2884 Check_State_And_Constituent_Use
2885 (States => States_Seen,
2886 Constits => Constits_Seen,
2887 Context => N);
2888
2889 Set_Is_Analyzed_Pragma (N);
2890 end Analyze_Global_In_Decl_Part;
2891
2892 --------------------------------------------
2893 -- Analyze_Initial_Condition_In_Decl_Part --
2894 --------------------------------------------
2895
2896 -- WARNING: This routine manages Ghost regions. Return statements must be
2897 -- replaced by gotos which jump to the end of the routine and restore the
2898 -- Ghost mode.
2899
2900 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2901 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2902 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2903 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2904
2905 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
2906 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
2907 -- Save the Ghost-related attributes to restore on exit
2908
2909 begin
2910 -- Do not analyze the pragma multiple times
2911
2912 if Is_Analyzed_Pragma (N) then
2913 return;
2914 end if;
2915
2916 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2917 -- analysis of the pragma, the Ghost mode at point of declaration and
2918 -- point of analysis may not necessarily be the same. Use the mode in
2919 -- effect at the point of declaration.
2920
2921 Set_Ghost_Mode (N);
2922
2923 -- The expression is preanalyzed because it has not been moved to its
2924 -- final place yet. A direct analysis may generate side effects and this
2925 -- is not desired at this point.
2926
2927 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2928 Set_Is_Analyzed_Pragma (N);
2929
2930 Restore_Ghost_Region (Saved_GM, Saved_IGR);
2931 end Analyze_Initial_Condition_In_Decl_Part;
2932
2933 --------------------------------------
2934 -- Analyze_Initializes_In_Decl_Part --
2935 --------------------------------------
2936
2937 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2938 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2939 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2940
2941 Constits_Seen : Elist_Id := No_Elist;
2942 -- A list containing the entities of all constituents processed so far.
2943 -- It aids in detecting illegal usage of a state and a corresponding
2944 -- constituent in pragma Initializes.
2945
2946 Items_Seen : Elist_Id := No_Elist;
2947 -- A list of all initialization items processed so far. This list is
2948 -- used to detect duplicate items.
2949
2950 States_And_Objs : Elist_Id := No_Elist;
2951 -- A list of all abstract states and objects declared in the visible
2952 -- declarations of the related package. This list is used to detect the
2953 -- legality of initialization items.
2954
2955 States_Seen : Elist_Id := No_Elist;
2956 -- A list containing the entities of all states processed so far. It
2957 -- helps in detecting illegal usage of a state and a corresponding
2958 -- constituent in pragma Initializes.
2959
2960 procedure Analyze_Initialization_Item (Item : Node_Id);
2961 -- Verify the legality of a single initialization item
2962
2963 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2964 -- Verify the legality of a single initialization item followed by a
2965 -- list of input items.
2966
2967 procedure Collect_States_And_Objects (Pack_Decl : Node_Id);
2968 -- Inspect the visible declarations of the related package and gather
2969 -- the entities of all abstract states and objects in States_And_Objs.
2970
2971 ---------------------------------
2972 -- Analyze_Initialization_Item --
2973 ---------------------------------
2974
2975 procedure Analyze_Initialization_Item (Item : Node_Id) is
2976 Item_Id : Entity_Id;
2977
2978 begin
2979 Analyze (Item);
2980 Resolve_State (Item);
2981
2982 if Is_Entity_Name (Item) then
2983 Item_Id := Entity_Of (Item);
2984
2985 if Present (Item_Id)
2986 and then Ekind (Item_Id) in
2987 E_Abstract_State | E_Constant | E_Variable
2988 then
2989 -- When the initialization item is undefined, it appears as
2990 -- Any_Id. Do not continue with the analysis of the item.
2991
2992 if Item_Id = Any_Id then
2993 null;
2994
2995 elsif Ekind (Item_Id) in E_Constant | E_Variable
2996 and then Present (Ultimate_Overlaid_Entity (Item_Id))
2997 then
2998 SPARK_Msg_NE
2999 ("overlaying object & cannot appear in Initializes",
3000 Item, Item_Id);
3001 SPARK_Msg_NE
3002 ("\use the overlaid object & instead",
3003 Item, Ultimate_Overlaid_Entity (Item_Id));
3004
3005 -- The state or variable must be declared in the visible
3006 -- declarations of the package (SPARK RM 7.1.5(7)).
3007
3008 elsif not Contains (States_And_Objs, Item_Id) then
3009 Error_Msg_Name_1 := Chars (Pack_Id);
3010 SPARK_Msg_NE
3011 ("initialization item & must appear in the visible "
3012 & "declarations of package %", Item, Item_Id);
3013
3014 -- Detect a duplicate use of the same initialization item
3015 -- (SPARK RM 7.1.5(5)).
3016
3017 elsif Contains (Items_Seen, Item_Id) then
3018 SPARK_Msg_N ("duplicate initialization item", Item);
3019
3020 -- The item is legal, add it to the list of processed states
3021 -- and variables.
3022
3023 else
3024 Append_New_Elmt (Item_Id, Items_Seen);
3025
3026 if Ekind (Item_Id) = E_Abstract_State then
3027 Append_New_Elmt (Item_Id, States_Seen);
3028 end if;
3029
3030 if Present (Encapsulating_State (Item_Id)) then
3031 Append_New_Elmt (Item_Id, Constits_Seen);
3032 end if;
3033 end if;
3034
3035 -- The item references something that is not a state or object
3036 -- (SPARK RM 7.1.5(3)).
3037
3038 else
3039 SPARK_Msg_N
3040 ("initialization item must denote object or state", Item);
3041 end if;
3042
3043 -- Some form of illegal construct masquerading as a name
3044 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
3045
3046 else
3047 Error_Msg_N
3048 ("initialization item must denote object or state", Item);
3049 end if;
3050 end Analyze_Initialization_Item;
3051
3052 ---------------------------------------------
3053 -- Analyze_Initialization_Item_With_Inputs --
3054 ---------------------------------------------
3055
3056 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
3057 Inputs_Seen : Elist_Id := No_Elist;
3058 -- A list of all inputs processed so far. This list is used to detect
3059 -- duplicate uses of an input.
3060
3061 Non_Null_Seen : Boolean := False;
3062 Null_Seen : Boolean := False;
3063 -- Flags used to check the legality of an input list
3064
3065 procedure Analyze_Input_Item (Input : Node_Id);
3066 -- Verify the legality of a single input item
3067
3068 ------------------------
3069 -- Analyze_Input_Item --
3070 ------------------------
3071
3072 procedure Analyze_Input_Item (Input : Node_Id) is
3073 Input_Id : Entity_Id;
3074
3075 begin
3076 -- Null input list
3077
3078 if Nkind (Input) = N_Null then
3079 if Null_Seen then
3080 SPARK_Msg_N
3081 ("multiple null initializations not allowed", Item);
3082
3083 elsif Non_Null_Seen then
3084 SPARK_Msg_N
3085 ("cannot mix null and non-null initialization item", Item);
3086 else
3087 Null_Seen := True;
3088 end if;
3089
3090 -- Input item
3091
3092 else
3093 Non_Null_Seen := True;
3094
3095 if Null_Seen then
3096 SPARK_Msg_N
3097 ("cannot mix null and non-null initialization item", Item);
3098 end if;
3099
3100 Analyze (Input);
3101 Resolve_State (Input);
3102
3103 if Is_Entity_Name (Input) then
3104 Input_Id := Entity_Of (Input);
3105
3106 if Present (Input_Id)
3107 and then Ekind (Input_Id) in E_Abstract_State
3108 | E_Constant
3109 | E_Generic_In_Out_Parameter
3110 | E_Generic_In_Parameter
3111 | E_In_Parameter
3112 | E_In_Out_Parameter
3113 | E_Out_Parameter
3114 | E_Protected_Type
3115 | E_Task_Type
3116 | E_Variable
3117 then
3118 -- The input cannot denote states or objects declared
3119 -- within the related package (SPARK RM 7.1.5(4)).
3120
3121 if Within_Scope (Input_Id, Current_Scope) then
3122
3123 -- Do not consider generic formal parameters or their
3124 -- respective mappings to generic formals. Even though
3125 -- the formals appear within the scope of the package,
3126 -- it is allowed for an initialization item to depend
3127 -- on an input item.
3128
3129 if Is_Formal_Object (Input_Id) then
3130 null;
3131
3132 elsif Ekind (Input_Id) in E_Constant | E_Variable
3133 and then Present (Corresponding_Generic_Association
3134 (Declaration_Node (Input_Id)))
3135 then
3136 null;
3137
3138 else
3139 Error_Msg_Name_1 := Chars (Pack_Id);
3140 SPARK_Msg_NE
3141 ("input item & cannot denote a visible object or "
3142 & "state of package %", Input, Input_Id);
3143 return;
3144 end if;
3145 end if;
3146
3147 if Ekind (Input_Id) in E_Constant | E_Variable
3148 and then Present (Ultimate_Overlaid_Entity (Input_Id))
3149 then
3150 SPARK_Msg_NE
3151 ("overlaying object & cannot appear in Initializes",
3152 Input, Input_Id);
3153 SPARK_Msg_NE
3154 ("\use the overlaid object & instead",
3155 Input, Ultimate_Overlaid_Entity (Input_Id));
3156 return;
3157 end if;
3158
3159 -- Detect a duplicate use of the same input item
3160 -- (SPARK RM 7.1.5(5)).
3161
3162 if Contains (Inputs_Seen, Input_Id) then
3163 SPARK_Msg_N ("duplicate input item", Input);
3164 return;
3165 end if;
3166
3167 -- At this point it is known that the input is legal. Add
3168 -- it to the list of processed inputs.
3169
3170 Append_New_Elmt (Input_Id, Inputs_Seen);
3171
3172 if Ekind (Input_Id) = E_Abstract_State then
3173 Append_New_Elmt (Input_Id, States_Seen);
3174 end if;
3175
3176 if Ekind (Input_Id) in E_Abstract_State
3177 | E_Constant
3178 | E_Variable
3179 and then Present (Encapsulating_State (Input_Id))
3180 then
3181 Append_New_Elmt (Input_Id, Constits_Seen);
3182 end if;
3183
3184 -- The input references something that is not a state or an
3185 -- object (SPARK RM 7.1.5(3)).
3186
3187 else
3188 SPARK_Msg_N
3189 ("input item must denote object or state", Input);
3190 end if;
3191
3192 -- Some form of illegal construct masquerading as a name
3193 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
3194
3195 else
3196 Error_Msg_N
3197 ("input item must denote object or state", Input);
3198 end if;
3199 end if;
3200 end Analyze_Input_Item;
3201
3202 -- Local variables
3203
3204 Inputs : constant Node_Id := Expression (Item);
3205 Elmt : Node_Id;
3206 Input : Node_Id;
3207
3208 Name_Seen : Boolean := False;
3209 -- A flag used to detect multiple item names
3210
3211 -- Start of processing for Analyze_Initialization_Item_With_Inputs
3212
3213 begin
3214 -- Inspect the name of an item with inputs
3215
3216 Elmt := First (Choices (Item));
3217 while Present (Elmt) loop
3218 if Name_Seen then
3219 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
3220 else
3221 Name_Seen := True;
3222 Analyze_Initialization_Item (Elmt);
3223 end if;
3224
3225 Next (Elmt);
3226 end loop;
3227
3228 -- Multiple input items appear as an aggregate
3229
3230 if Nkind (Inputs) = N_Aggregate then
3231 if Present (Expressions (Inputs)) then
3232 Input := First (Expressions (Inputs));
3233 while Present (Input) loop
3234 Analyze_Input_Item (Input);
3235 Next (Input);
3236 end loop;
3237 end if;
3238
3239 if Present (Component_Associations (Inputs)) then
3240 SPARK_Msg_N
3241 ("inputs must appear in named association form", Inputs);
3242 end if;
3243
3244 -- Single input item
3245
3246 else
3247 Analyze_Input_Item (Inputs);
3248 end if;
3249 end Analyze_Initialization_Item_With_Inputs;
3250
3251 --------------------------------
3252 -- Collect_States_And_Objects --
3253 --------------------------------
3254
3255 procedure Collect_States_And_Objects (Pack_Decl : Node_Id) is
3256 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
3257 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
3258 Decl : Node_Id;
3259 State_Elmt : Elmt_Id;
3260
3261 begin
3262 -- Collect the abstract states defined in the package (if any)
3263
3264 if Has_Non_Null_Abstract_State (Pack_Id) then
3265 State_Elmt := First_Elmt (Abstract_States (Pack_Id));
3266 while Present (State_Elmt) loop
3267 Append_New_Elmt (Node (State_Elmt), States_And_Objs);
3268 Next_Elmt (State_Elmt);
3269 end loop;
3270 end if;
3271
3272 -- Collect all objects that appear in the visible declarations of the
3273 -- related package.
3274
3275 Decl := First (Visible_Declarations (Pack_Spec));
3276 while Present (Decl) loop
3277 if Comes_From_Source (Decl)
3278 and then Nkind (Decl) in N_Object_Declaration
3279 | N_Object_Renaming_Declaration
3280 then
3281 Append_New_Elmt (Defining_Entity (Decl), States_And_Objs);
3282
3283 elsif Nkind (Decl) = N_Package_Declaration then
3284 Collect_States_And_Objects (Decl);
3285
3286 elsif Is_Single_Concurrent_Type_Declaration (Decl) then
3287 Append_New_Elmt
3288 (Anonymous_Object (Defining_Entity (Decl)),
3289 States_And_Objs);
3290 end if;
3291
3292 Next (Decl);
3293 end loop;
3294 end Collect_States_And_Objects;
3295
3296 -- Local variables
3297
3298 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3299 Init : Node_Id;
3300
3301 -- Start of processing for Analyze_Initializes_In_Decl_Part
3302
3303 begin
3304 -- Do not analyze the pragma multiple times
3305
3306 if Is_Analyzed_Pragma (N) then
3307 return;
3308 end if;
3309
3310 -- Nothing to do when the initialization list is empty
3311
3312 if Nkind (Inits) = N_Null then
3313 return;
3314 end if;
3315
3316 -- Single and multiple initialization clauses appear as an aggregate. If
3317 -- this is not the case, then either the parser or the analysis of the
3318 -- pragma failed to produce an aggregate.
3319
3320 pragma Assert (Nkind (Inits) = N_Aggregate);
3321
3322 -- Initialize the various lists used during analysis
3323
3324 Collect_States_And_Objects (Pack_Decl);
3325
3326 if Present (Expressions (Inits)) then
3327 Init := First (Expressions (Inits));
3328 while Present (Init) loop
3329 Analyze_Initialization_Item (Init);
3330 Next (Init);
3331 end loop;
3332 end if;
3333
3334 if Present (Component_Associations (Inits)) then
3335 Init := First (Component_Associations (Inits));
3336 while Present (Init) loop
3337 Analyze_Initialization_Item_With_Inputs (Init);
3338 Next (Init);
3339 end loop;
3340 end if;
3341
3342 -- Ensure that a state and a corresponding constituent do not appear
3343 -- together in pragma Initializes.
3344
3345 Check_State_And_Constituent_Use
3346 (States => States_Seen,
3347 Constits => Constits_Seen,
3348 Context => N);
3349
3350 Set_Is_Analyzed_Pragma (N);
3351 end Analyze_Initializes_In_Decl_Part;
3352
3353 ---------------------
3354 -- Analyze_Part_Of --
3355 ---------------------
3356
3357 procedure Analyze_Part_Of
3358 (Indic : Node_Id;
3359 Item_Id : Entity_Id;
3360 Encap : Node_Id;
3361 Encap_Id : out Entity_Id;
3362 Legal : out Boolean)
3363 is
3364 procedure Check_Part_Of_Abstract_State;
3365 pragma Inline (Check_Part_Of_Abstract_State);
3366 -- Verify the legality of indicator Part_Of when the encapsulator is an
3367 -- abstract state.
3368
3369 procedure Check_Part_Of_Concurrent_Type;
3370 pragma Inline (Check_Part_Of_Concurrent_Type);
3371 -- Verify the legality of indicator Part_Of when the encapsulator is a
3372 -- single concurrent type.
3373
3374 ----------------------------------
3375 -- Check_Part_Of_Abstract_State --
3376 ----------------------------------
3377
3378 procedure Check_Part_Of_Abstract_State is
3379 Pack_Id : Entity_Id;
3380 Placement : State_Space_Kind;
3381 Parent_Unit : Entity_Id;
3382
3383 begin
3384 -- Determine where the object, package instantiation or state lives
3385 -- with respect to the enclosing packages or package bodies.
3386
3387 Find_Placement_In_State_Space
3388 (Item_Id => Item_Id,
3389 Placement => Placement,
3390 Pack_Id => Pack_Id);
3391
3392 -- The item appears in a non-package construct with a declarative
3393 -- part (subprogram, block, etc). As such, the item is not allowed
3394 -- to be a part of an encapsulating state because the item is not
3395 -- visible.
3396
3397 if Placement = Not_In_Package then
3398 SPARK_Msg_N
3399 ("indicator Part_Of cannot appear in this context "
3400 & "(SPARK RM 7.2.6(5))", Indic);
3401
3402 Error_Msg_Name_1 := Chars (Scope (Encap_Id));
3403 SPARK_Msg_NE
3404 ("\& is not part of the hidden state of package %",
3405 Indic, Item_Id);
3406 return;
3407
3408 -- The item appears in the visible state space of some package. In
3409 -- general this scenario does not warrant Part_Of except when the
3410 -- package is a nongeneric private child unit and the encapsulating
3411 -- state is declared in a parent unit or a public descendant of that
3412 -- parent unit.
3413
3414 elsif Placement = Visible_State_Space then
3415 if Is_Child_Unit (Pack_Id)
3416 and then not Is_Generic_Unit (Pack_Id)
3417 and then Is_Private_Descendant (Pack_Id)
3418 then
3419 -- A variable or state abstraction which is part of the visible
3420 -- state of a nongeneric private child unit or its public
3421 -- descendants must have its Part_Of indicator specified. The
3422 -- Part_Of indicator must denote a state declared by either the
3423 -- parent unit of the private unit or by a public descendant of
3424 -- that parent unit.
3425
3426 -- Find the nearest private ancestor (which can be the current
3427 -- unit itself).
3428
3429 Parent_Unit := Pack_Id;
3430 while Present (Parent_Unit) loop
3431 exit when Is_Private_Library_Unit (Parent_Unit);
3432 Parent_Unit := Scope (Parent_Unit);
3433 end loop;
3434
3435 Parent_Unit := Scope (Parent_Unit);
3436
3437 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
3438 SPARK_Msg_NE
3439 ("indicator Part_Of must denote abstract state of & or of "
3440 & "its public descendant (SPARK RM 7.2.6(3))",
3441 Indic, Parent_Unit);
3442 return;
3443
3444 elsif Scope (Encap_Id) = Parent_Unit
3445 or else
3446 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id))
3447 and then not Is_Private_Descendant (Scope (Encap_Id)))
3448 then
3449 null;
3450
3451 else
3452 SPARK_Msg_NE
3453 ("indicator Part_Of must denote abstract state of & or of "
3454 & "its public descendant (SPARK RM 7.2.6(3))",
3455 Indic, Parent_Unit);
3456 return;
3457 end if;
3458
3459 -- Indicator Part_Of is not needed when the related package is
3460 -- not a nongeneric private child unit or a public descendant
3461 -- thereof.
3462
3463 else
3464 SPARK_Msg_N
3465 ("indicator Part_Of cannot appear in this context "
3466 & "(SPARK RM 7.2.6(5))", Indic);
3467
3468 Error_Msg_Name_1 := Chars (Pack_Id);
3469 SPARK_Msg_NE
3470 ("\& is declared in the visible part of package %",
3471 Indic, Item_Id);
3472 return;
3473 end if;
3474
3475 -- When the item appears in the private state space of a package, the
3476 -- encapsulating state must be declared in the same package.
3477
3478 elsif Placement = Private_State_Space then
3479
3480 -- In the case of the abstract state of a nongeneric private
3481 -- child package, it may be encapsulated in the state of a
3482 -- public descendant of its parent package.
3483
3484 declare
3485 function Is_Public_Descendant
3486 (Child, Ancestor : Entity_Id)
3487 return Boolean;
3488 -- Return True if Child is a public descendant of Pack
3489
3490 --------------------------
3491 -- Is_Public_Descendant --
3492 --------------------------
3493
3494 function Is_Public_Descendant
3495 (Child, Ancestor : Entity_Id)
3496 return Boolean
3497 is
3498 P : Entity_Id := Child;
3499 begin
3500 while Is_Child_Unit (P)
3501 and then not Is_Private_Library_Unit (P)
3502 loop
3503 if Scope (P) = Ancestor then
3504 return True;
3505 end if;
3506
3507 P := Scope (P);
3508 end loop;
3509
3510 return False;
3511 end Is_Public_Descendant;
3512
3513 -- Local variables
3514
3515 Immediate_Pack_Id : constant Entity_Id := Scope (Item_Id);
3516
3517 Is_State_Of_Private_Child : constant Boolean :=
3518 Is_Child_Unit (Immediate_Pack_Id)
3519 and then not Is_Generic_Unit (Immediate_Pack_Id)
3520 and then Is_Private_Descendant (Immediate_Pack_Id);
3521
3522 Is_OK_Through_Sibling : Boolean := False;
3523
3524 begin
3525 if Ekind (Item_Id) = E_Abstract_State
3526 and then Is_State_Of_Private_Child
3527 and then Is_Public_Descendant (Scope (Encap_Id), Pack_Id)
3528 then
3529 Is_OK_Through_Sibling := True;
3530 end if;
3531
3532 if Scope (Encap_Id) /= Pack_Id
3533 and then not Is_OK_Through_Sibling
3534 then
3535 if Is_State_Of_Private_Child then
3536 SPARK_Msg_NE
3537 ("indicator Part_Of must denote abstract state of & "
3538 & "or of its public descendant "
3539 & "(SPARK RM 7.2.6(3))", Indic, Pack_Id);
3540 else
3541 SPARK_Msg_NE
3542 ("indicator Part_Of must denote an abstract state of "
3543 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3544 end if;
3545
3546 Error_Msg_Name_1 := Chars (Pack_Id);
3547 SPARK_Msg_NE
3548 ("\& is declared in the private part of package %",
3549 Indic, Item_Id);
3550 return;
3551 end if;
3552 end;
3553
3554 -- Items declared in the body state space of a package do not need
3555 -- Part_Of indicators as the refinement has already been seen.
3556
3557 else
3558 SPARK_Msg_N
3559 ("indicator Part_Of cannot appear in this context "
3560 & "(SPARK RM 7.2.6(5))", Indic);
3561
3562 if Scope (Encap_Id) = Pack_Id then
3563 Error_Msg_Name_1 := Chars (Pack_Id);
3564 SPARK_Msg_NE
3565 ("\& is declared in the body of package %", Indic, Item_Id);
3566 end if;
3567
3568 return;
3569 end if;
3570
3571 -- In the case of state in a (descendant of a private) child which
3572 -- is Part_Of the state of another package, the package defining the
3573 -- encapsulating abstract state should have a body, to ensure that it
3574 -- has a state refinement (SPARK RM 7.1.4(4)).
3575
3576 if Enclosing_Comp_Unit_Node (Encap_Id) /=
3577 Enclosing_Comp_Unit_Node (Item_Id)
3578 and then not Unit_Requires_Body (Scope (Encap_Id))
3579 then
3580 SPARK_Msg_N
3581 ("indicator Part_Of must denote abstract state of package "
3582 & "with a body (SPARK RM 7.1.4(4))", Indic);
3583 return;
3584 end if;
3585
3586 -- At this point it is known that the Part_Of indicator is legal
3587
3588 Legal := True;
3589 end Check_Part_Of_Abstract_State;
3590
3591 -----------------------------------
3592 -- Check_Part_Of_Concurrent_Type --
3593 -----------------------------------
3594
3595 procedure Check_Part_Of_Concurrent_Type is
3596 function In_Proper_Order
3597 (First : Node_Id;
3598 Second : Node_Id) return Boolean;
3599 pragma Inline (In_Proper_Order);
3600 -- Determine whether node First precedes node Second
3601
3602 procedure Placement_Error;
3603 pragma Inline (Placement_Error);
3604 -- Emit an error concerning the illegal placement of the item with
3605 -- respect to the single concurrent type.
3606
3607 ---------------------
3608 -- In_Proper_Order --
3609 ---------------------
3610
3611 function In_Proper_Order
3612 (First : Node_Id;
3613 Second : Node_Id) return Boolean
3614 is
3615 N : Node_Id;
3616
3617 begin
3618 if List_Containing (First) = List_Containing (Second) then
3619 N := First;
3620 while Present (N) loop
3621 if N = Second then
3622 return True;
3623 end if;
3624
3625 Next (N);
3626 end loop;
3627 end if;
3628
3629 return False;
3630 end In_Proper_Order;
3631
3632 ---------------------
3633 -- Placement_Error --
3634 ---------------------
3635
3636 procedure Placement_Error is
3637 begin
3638 SPARK_Msg_N
3639 ("indicator Part_Of must denote a previously declared single "
3640 & "protected type or single task type", Encap);
3641 end Placement_Error;
3642
3643 -- Local variables
3644
3645 Conc_Typ : constant Entity_Id := Etype (Encap_Id);
3646 Encap_Decl : constant Node_Id := Declaration_Node (Encap_Id);
3647 Encap_Context : constant Node_Id := Parent (Encap_Decl);
3648
3649 Item_Context : Node_Id;
3650 Item_Decl : Node_Id;
3651 Prv_Decls : List_Id;
3652 Vis_Decls : List_Id;
3653
3654 -- Start of processing for Check_Part_Of_Concurrent_Type
3655
3656 begin
3657 -- Only abstract states and variables can act as constituents of an
3658 -- encapsulating single concurrent type.
3659
3660 if Ekind (Item_Id) in E_Abstract_State | E_Variable then
3661 null;
3662
3663 -- The constituent is a constant
3664
3665 elsif Ekind (Item_Id) = E_Constant then
3666 Error_Msg_Name_1 := Chars (Encap_Id);
3667 SPARK_Msg_NE
3668 (Fix_Msg (Conc_Typ, "constant & cannot act as constituent of "
3669 & "single protected type %"), Indic, Item_Id);
3670 return;
3671
3672 -- The constituent is a package instantiation
3673
3674 else
3675 Error_Msg_Name_1 := Chars (Encap_Id);
3676 SPARK_Msg_NE
3677 (Fix_Msg (Conc_Typ, "package instantiation & cannot act as "
3678 & "constituent of single protected type %"), Indic, Item_Id);
3679 return;
3680 end if;
3681
3682 -- When the item denotes an abstract state of a nested package, use
3683 -- the declaration of the package to detect proper placement.
3684
3685 -- package Pack is
3686 -- task T;
3687 -- package Nested
3688 -- with Abstract_State => (State with Part_Of => T)
3689
3690 if Ekind (Item_Id) = E_Abstract_State then
3691 Item_Decl := Unit_Declaration_Node (Scope (Item_Id));
3692 else
3693 Item_Decl := Declaration_Node (Item_Id);
3694 end if;
3695
3696 Item_Context := Parent (Item_Decl);
3697
3698 -- The item and the single concurrent type must appear in the same
3699 -- declarative region, with the item following the declaration of
3700 -- the single concurrent type (SPARK RM 9(3)).
3701
3702 if Item_Context = Encap_Context then
3703 if Nkind (Item_Context) in N_Package_Specification
3704 | N_Protected_Definition
3705 | N_Task_Definition
3706 then
3707 Prv_Decls := Private_Declarations (Item_Context);
3708 Vis_Decls := Visible_Declarations (Item_Context);
3709
3710 -- The placement is OK when the single concurrent type appears
3711 -- within the visible declarations and the item in the private
3712 -- declarations.
3713 --
3714 -- package Pack is
3715 -- protected PO ...
3716 -- private
3717 -- Constit : ... with Part_Of => PO;
3718 -- end Pack;
3719
3720 if List_Containing (Encap_Decl) = Vis_Decls
3721 and then List_Containing (Item_Decl) = Prv_Decls
3722 then
3723 null;
3724
3725 -- The placement is illegal when the item appears within the
3726 -- visible declarations and the single concurrent type is in
3727 -- the private declarations.
3728 --
3729 -- package Pack is
3730 -- Constit : ... with Part_Of => PO;
3731 -- private
3732 -- protected PO ...
3733 -- end Pack;
3734
3735 elsif List_Containing (Item_Decl) = Vis_Decls
3736 and then List_Containing (Encap_Decl) = Prv_Decls
3737 then
3738 Placement_Error;
3739 return;
3740
3741 -- Otherwise both the item and the single concurrent type are
3742 -- in the same list. Ensure that the declaration of the single
3743 -- concurrent type precedes that of the item.
3744
3745 elsif not In_Proper_Order
3746 (First => Encap_Decl,
3747 Second => Item_Decl)
3748 then
3749 Placement_Error;
3750 return;
3751 end if;
3752
3753 -- Otherwise both the item and the single concurrent type are
3754 -- in the same list. Ensure that the declaration of the single
3755 -- concurrent type precedes that of the item.
3756
3757 elsif not In_Proper_Order
3758 (First => Encap_Decl,
3759 Second => Item_Decl)
3760 then
3761 Placement_Error;
3762 return;
3763 end if;
3764
3765 -- Otherwise the item and the single concurrent type reside within
3766 -- unrelated regions.
3767
3768 else
3769 Error_Msg_Name_1 := Chars (Encap_Id);
3770 SPARK_Msg_NE
3771 (Fix_Msg (Conc_Typ, "constituent & must be declared "
3772 & "immediately within the same region as single protected "
3773 & "type %"), Indic, Item_Id);
3774 return;
3775 end if;
3776
3777 -- At this point it is known that the Part_Of indicator is legal
3778
3779 Legal := True;
3780 end Check_Part_Of_Concurrent_Type;
3781
3782 -- Start of processing for Analyze_Part_Of
3783
3784 begin
3785 -- Assume that the indicator is illegal
3786
3787 Encap_Id := Empty;
3788 Legal := False;
3789
3790 if Nkind (Encap) in
3791 N_Expanded_Name | N_Identifier | N_Selected_Component
3792 then
3793 Analyze (Encap);
3794 Resolve_State (Encap);
3795
3796 Encap_Id := Entity (Encap);
3797
3798 -- The encapsulator is an abstract state
3799
3800 if Ekind (Encap_Id) = E_Abstract_State then
3801 null;
3802
3803 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3804
3805 elsif Is_Single_Concurrent_Object (Encap_Id) then
3806 null;
3807
3808 -- Otherwise the encapsulator is not a legal choice
3809
3810 else
3811 SPARK_Msg_N
3812 ("indicator Part_Of must denote abstract state, single "
3813 & "protected type or single task type", Encap);
3814 return;
3815 end if;
3816
3817 -- This is a syntax error, always report
3818
3819 else
3820 Error_Msg_N
3821 ("indicator Part_Of must denote abstract state, single protected "
3822 & "type or single task type", Encap);
3823 return;
3824 end if;
3825
3826 -- Catch a case where indicator Part_Of denotes the abstract view of a
3827 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3828
3829 if From_Limited_With (Encap_Id)
3830 and then Present (Non_Limited_View (Encap_Id))
3831 and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable
3832 then
3833 SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap);
3834 SPARK_Msg_N ("\& denotes abstract view of object", Encap);
3835 return;
3836 end if;
3837
3838 -- The encapsulator is an abstract state
3839
3840 if Ekind (Encap_Id) = E_Abstract_State then
3841 Check_Part_Of_Abstract_State;
3842
3843 -- The encapsulator is a single concurrent type
3844
3845 else
3846 Check_Part_Of_Concurrent_Type;
3847 end if;
3848 end Analyze_Part_Of;
3849
3850 ----------------------------------
3851 -- Analyze_Part_Of_In_Decl_Part --
3852 ----------------------------------
3853
3854 procedure Analyze_Part_Of_In_Decl_Part
3855 (N : Node_Id;
3856 Freeze_Id : Entity_Id := Empty)
3857 is
3858 Encap : constant Node_Id :=
3859 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
3860 Errors : constant Nat := Serious_Errors_Detected;
3861 Var_Decl : constant Node_Id := Find_Related_Context (N);
3862 Var_Id : constant Entity_Id := Defining_Entity (Var_Decl);
3863 Constits : Elist_Id;
3864 Encap_Id : Entity_Id;
3865 Legal : Boolean;
3866
3867 begin
3868 -- Detect any discrepancies between the placement of the variable with
3869 -- respect to general state space and the encapsulating state or single
3870 -- concurrent type.
3871
3872 Analyze_Part_Of
3873 (Indic => N,
3874 Item_Id => Var_Id,
3875 Encap => Encap,
3876 Encap_Id => Encap_Id,
3877 Legal => Legal);
3878
3879 -- The Part_Of indicator turns the variable into a constituent of the
3880 -- encapsulating state or single concurrent type.
3881
3882 if Legal then
3883 pragma Assert (Present (Encap_Id));
3884 Constits := Part_Of_Constituents (Encap_Id);
3885
3886 if No (Constits) then
3887 Constits := New_Elmt_List;
3888 Set_Part_Of_Constituents (Encap_Id, Constits);
3889 end if;
3890
3891 Append_Elmt (Var_Id, Constits);
3892 Set_Encapsulating_State (Var_Id, Encap_Id);
3893
3894 -- A Part_Of constituent partially refines an abstract state. This
3895 -- property does not apply to protected or task units.
3896
3897 if Ekind (Encap_Id) = E_Abstract_State then
3898 Set_Has_Partial_Visible_Refinement (Encap_Id);
3899 end if;
3900 end if;
3901
3902 -- Emit a clarification message when the encapsulator is undefined,
3903 -- possibly due to contract freezing.
3904
3905 if Errors /= Serious_Errors_Detected
3906 and then Present (Freeze_Id)
3907 and then Has_Undefined_Reference (Encap)
3908 then
3909 Contract_Freeze_Error (Var_Id, Freeze_Id);
3910 end if;
3911 end Analyze_Part_Of_In_Decl_Part;
3912
3913 --------------------
3914 -- Analyze_Pragma --
3915 --------------------
3916
3917 procedure Analyze_Pragma (N : Node_Id) is
3918 Loc : constant Source_Ptr := Sloc (N);
3919
3920 Pname : Name_Id := Pragma_Name (N);
3921 -- Name of the source pragma, or name of the corresponding aspect for
3922 -- pragmas which originate in a source aspect. In the latter case, the
3923 -- name may be different from the pragma name.
3924
3925 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
3926
3927 Pragma_Exit : exception;
3928 -- This exception is used to exit pragma processing completely. It
3929 -- is used when an error is detected, and no further processing is
3930 -- required. It is also used if an earlier error has left the tree in
3931 -- a state where the pragma should not be processed.
3932
3933 Arg_Count : Nat;
3934 -- Number of pragma argument associations
3935
3936 Arg1 : Node_Id;
3937 Arg2 : Node_Id;
3938 Arg3 : Node_Id;
3939 Arg4 : Node_Id;
3940 Arg5 : Node_Id;
3941 -- First five pragma arguments (pragma argument association nodes, or
3942 -- Empty if the corresponding argument does not exist).
3943
3944 type Name_List is array (Natural range <>) of Name_Id;
3945 type Args_List is array (Natural range <>) of Node_Id;
3946 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3947
3948 -----------------------
3949 -- Local Subprograms --
3950 -----------------------
3951
3952 procedure Ada_2005_Pragma;
3953 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3954 -- Ada 95 mode, these are implementation defined pragmas, so should be
3955 -- caught by the No_Implementation_Pragmas restriction.
3956
3957 procedure Ada_2012_Pragma;
3958 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3959 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3960 -- should be caught by the No_Implementation_Pragmas restriction.
3961
3962 procedure Analyze_Depends_Global
3963 (Spec_Id : out Entity_Id;
3964 Subp_Decl : out Node_Id;
3965 Legal : out Boolean);
3966 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3967 -- legality of the placement and related context of the pragma. Spec_Id
3968 -- is the entity of the related subprogram. Subp_Decl is the declaration
3969 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3970
3971 procedure Analyze_If_Present (Id : Pragma_Id);
3972 -- Inspect the remainder of the list containing pragma N and look for
3973 -- a pragma that matches Id. If found, analyze the pragma.
3974
3975 procedure Analyze_Pre_Post_Condition;
3976 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3977
3978 procedure Analyze_Refined_Depends_Global_Post
3979 (Spec_Id : out Entity_Id;
3980 Body_Id : out Entity_Id;
3981 Legal : out Boolean);
3982 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3983 -- Refined_Global and Refined_Post. Verify the legality of the placement
3984 -- and related context of the pragma. Spec_Id is the entity of the
3985 -- related subprogram. Body_Id is the entity of the subprogram body.
3986 -- Flag Legal is set when the pragma is legal.
3987
3988 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False);
3989 -- Perform full analysis of pragma Unmodified and the write aspect of
3990 -- pragma Unused. Flag Is_Unused should be set when verifying the
3991 -- semantics of pragma Unused.
3992
3993 procedure Analyze_Unreferenced_Or_Unused (Is_Unused : Boolean := False);
3994 -- Perform full analysis of pragma Unreferenced and the read aspect of
3995 -- pragma Unused. Flag Is_Unused should be set when verifying the
3996 -- semantics of pragma Unused.
3997
3998 procedure Check_Ada_83_Warning;
3999 -- Issues a warning message for the current pragma if operating in Ada
4000 -- 83 mode (used for language pragmas that are not a standard part of
4001 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
4002 -- of 95 pragma.
4003
4004 procedure Check_Arg_Count (Required : Nat);
4005 -- Check argument count for pragma is equal to given parameter. If not,
4006 -- then issue an error message and raise Pragma_Exit.
4007
4008 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
4009 -- Arg which can either be a pragma argument association, in which case
4010 -- the check is applied to the expression of the association or an
4011 -- expression directly.
4012
4013 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
4014 -- Check that an argument has the right form for an EXTERNAL_NAME
4015 -- parameter of an extended import/export pragma. The rule is that the
4016 -- name must be an identifier or string literal (in Ada 83 mode) or a
4017 -- static string expression (in Ada 95 mode).
4018
4019 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
4020 -- Check the specified argument Arg to make sure that it is an
4021 -- identifier. If not give error and raise Pragma_Exit.
4022
4023 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
4024 -- Check the specified argument Arg to make sure that it is an integer
4025 -- literal. If not give error and raise Pragma_Exit.
4026
4027 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
4028 -- Check the specified argument Arg to make sure that it has the proper
4029 -- syntactic form for a local name and meets the semantic requirements
4030 -- for a local name. The local name is analyzed as part of the
4031 -- processing for this call. In addition, the local name is required
4032 -- to represent an entity at the library level.
4033
4034 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
4035 -- Check the specified argument Arg to make sure that it has the proper
4036 -- syntactic form for a local name and meets the semantic requirements
4037 -- for a local name. The local name is analyzed as part of the
4038 -- processing for this call.
4039
4040 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
4041 -- Check the specified argument Arg to make sure that it is a valid
4042 -- locking policy name. If not give error and raise Pragma_Exit.
4043
4044 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
4045 -- Check the specified argument Arg to make sure that it is a valid
4046 -- elaboration policy name. If not give error and raise Pragma_Exit.
4047
4048 procedure Check_Arg_Is_One_Of
4049 (Arg : Node_Id;
4050 N1, N2 : Name_Id);
4051 procedure Check_Arg_Is_One_Of
4052 (Arg : Node_Id;
4053 N1, N2, N3 : Name_Id);
4054 procedure Check_Arg_Is_One_Of
4055 (Arg : Node_Id;
4056 N1, N2, N3, N4 : Name_Id);
4057 procedure Check_Arg_Is_One_Of
4058 (Arg : Node_Id;
4059 N1, N2, N3, N4, N5 : Name_Id);
4060 -- Check the specified argument Arg to make sure that it is an
4061 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
4062 -- present). If not then give error and raise Pragma_Exit.
4063
4064 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
4065 -- Check the specified argument Arg to make sure that it is a valid
4066 -- queuing policy name. If not give error and raise Pragma_Exit.
4067
4068 procedure Check_Arg_Is_OK_Static_Expression
4069 (Arg : Node_Id;
4070 Typ : Entity_Id := Empty);
4071 -- Check the specified argument Arg to make sure that it is a static
4072 -- expression of the given type (i.e. it will be analyzed and resolved
4073 -- using this type, which can be any valid argument to Resolve, e.g.
4074 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
4075 -- Typ is left Empty, then any static expression is allowed. Includes
4076 -- checking that the argument does not raise Constraint_Error.
4077
4078 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
4079 -- Check the specified argument Arg to make sure that it is a valid task
4080 -- dispatching policy name. If not give error and raise Pragma_Exit.
4081
4082 procedure Check_Arg_Order (Names : Name_List);
4083 -- Checks for an instance of two arguments with identifiers for the
4084 -- current pragma which are not in the sequence indicated by Names,
4085 -- and if so, generates a fatal message about bad order of arguments.
4086
4087 procedure Check_At_Least_N_Arguments (N : Nat);
4088 -- Check there are at least N arguments present
4089
4090 procedure Check_At_Most_N_Arguments (N : Nat);
4091 -- Check there are no more than N arguments present
4092
4093 procedure Check_Component
4094 (Comp : Node_Id;
4095 UU_Typ : Entity_Id;
4096 In_Variant_Part : Boolean := False);
4097 -- Examine an Unchecked_Union component for correct use of per-object
4098 -- constrained subtypes, and for restrictions on finalizable components.
4099 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
4100 -- should be set when Comp comes from a record variant.
4101
4102 procedure Check_Duplicate_Pragma (E : Entity_Id);
4103 -- Check if a rep item of the same name as the current pragma is already
4104 -- chained as a rep pragma to the given entity. If so give a message
4105 -- about the duplicate, and then raise Pragma_Exit so does not return.
4106 -- Note that if E is a type, then this routine avoids flagging a pragma
4107 -- which applies to a parent type from which E is derived.
4108
4109 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
4110 -- Nam is an N_String_Literal node containing the external name set by
4111 -- an Import or Export pragma (or extended Import or Export pragma).
4112 -- This procedure checks for possible duplications if this is the export
4113 -- case, and if found, issues an appropriate error message.
4114
4115 procedure Check_Expr_Is_OK_Static_Expression
4116 (Expr : Node_Id;
4117 Typ : Entity_Id := Empty);
4118 -- Check the specified expression Expr to make sure that it is a static
4119 -- expression of the given type (i.e. it will be analyzed and resolved
4120 -- using this type, which can be any valid argument to Resolve, e.g.
4121 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
4122 -- Typ is left Empty, then any static expression is allowed. Includes
4123 -- checking that the expression does not raise Constraint_Error.
4124
4125 procedure Check_First_Subtype (Arg : Node_Id);
4126 -- Checks that Arg, whose expression is an entity name, references a
4127 -- first subtype.
4128
4129 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
4130 -- Checks that the given argument has an identifier, and if so, requires
4131 -- it to match the given identifier name. If there is no identifier, or
4132 -- a non-matching identifier, then an error message is given and
4133 -- Pragma_Exit is raised.
4134
4135 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
4136 -- Checks that the given argument has an identifier, and if so, requires
4137 -- it to match one of the given identifier names. If there is no
4138 -- identifier, or a non-matching identifier, then an error message is
4139 -- given and Pragma_Exit is raised.
4140
4141 procedure Check_In_Main_Program;
4142 -- Common checks for pragmas that appear within a main program
4143 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
4144
4145 procedure Check_Interrupt_Or_Attach_Handler;
4146 -- Common processing for first argument of pragma Interrupt_Handler or
4147 -- pragma Attach_Handler.
4148
4149 procedure Check_Loop_Pragma_Placement;
4150 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
4151 -- appear immediately within a construct restricted to loops, and that
4152 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
4153
4154 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
4155 -- Check that pragma appears in a declarative part, or in a package
4156 -- specification, i.e. that it does not occur in a statement sequence
4157 -- in a body.
4158
4159 procedure Check_No_Identifier (Arg : Node_Id);
4160 -- Checks that the given argument does not have an identifier. If
4161 -- an identifier is present, then an error message is issued, and
4162 -- Pragma_Exit is raised.
4163
4164 procedure Check_No_Identifiers;
4165 -- Checks that none of the arguments to the pragma has an identifier.
4166 -- If any argument has an identifier, then an error message is issued,
4167 -- and Pragma_Exit is raised.
4168
4169 procedure Check_No_Link_Name;
4170 -- Checks that no link name is specified
4171
4172 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
4173 -- Checks if the given argument has an identifier, and if so, requires
4174 -- it to match the given identifier name. If there is a non-matching
4175 -- identifier, then an error message is given and Pragma_Exit is raised.
4176
4177 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
4178 -- Checks if the given argument has an identifier, and if so, requires
4179 -- it to match the given identifier name. If there is a non-matching
4180 -- identifier, then an error message is given and Pragma_Exit is raised.
4181 -- In this version of the procedure, the identifier name is given as
4182 -- a string with lower case letters.
4183
4184 procedure Check_Static_Boolean_Expression (Expr : Node_Id);
4185 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
4186 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
4187 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
4188 -- is an OK static boolean expression. Emit an error if this is not the
4189 -- case.
4190
4191 procedure Check_Static_Constraint (Constr : Node_Id);
4192 -- Constr is a constraint from an N_Subtype_Indication node from a
4193 -- component constraint in an Unchecked_Union type, a range, or a
4194 -- discriminant association. This routine checks that the constraint
4195 -- is static as required by the restrictions for Unchecked_Union.
4196
4197 procedure Check_Valid_Configuration_Pragma;
4198 -- Legality checks for placement of a configuration pragma
4199
4200 procedure Check_Valid_Library_Unit_Pragma;
4201 -- Legality checks for library unit pragmas. A special case arises for
4202 -- pragmas in generic instances that come from copies of the original
4203 -- library unit pragmas in the generic templates. In the case of other
4204 -- than library level instantiations these can appear in contexts which
4205 -- would normally be invalid (they only apply to the original template
4206 -- and to library level instantiations), and they are simply ignored,
4207 -- which is implemented by rewriting them as null statements and
4208 -- optionally raising Pragma_Exit to terminate analysis. An exception
4209 -- is not always raised to avoid exception propagation during the
4210 -- bootstrap, so all callers should check whether N has been rewritten.
4211
4212 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
4213 -- Check an Unchecked_Union variant for lack of nested variants and
4214 -- presence of at least one component. UU_Typ is the related Unchecked_
4215 -- Union type.
4216
4217 procedure Ensure_Aggregate_Form (Arg : Node_Id);
4218 -- Subsidiary routine to the processing of pragmas Abstract_State,
4219 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
4220 -- Refined_Global, Refined_State and Subprogram_Variant. Transform
4221 -- argument Arg into an aggregate if not one already. N_Null is never
4222 -- transformed. Arg may denote an aspect specification or a pragma
4223 -- argument association.
4224
4225 procedure Error_Pragma (Msg : String);
4226 pragma No_Return (Error_Pragma);
4227 -- Outputs error message for current pragma. The message contains a %
4228 -- that will be replaced with the pragma name, and the flag is placed
4229 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
4230 -- calls Fix_Error (see spec of that procedure for details).
4231
4232 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
4233 pragma No_Return (Error_Pragma_Arg);
4234 -- Outputs error message for current pragma. The message may contain
4235 -- a % that will be replaced with the pragma name. The parameter Arg
4236 -- may either be a pragma argument association, in which case the flag
4237 -- is placed on the expression of this association, or an expression,
4238 -- in which case the flag is placed directly on the expression. The
4239 -- message is placed using Error_Msg_N, so the message may also contain
4240 -- an & insertion character which will reference the given Arg value.
4241 -- After placing the message, Pragma_Exit is raised. Note: this routine
4242 -- calls Fix_Error (see spec of that procedure for details).
4243
4244 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
4245 pragma No_Return (Error_Pragma_Arg);
4246 -- Similar to above form of Error_Pragma_Arg except that two messages
4247 -- are provided, the second is a continuation comment starting with \.
4248
4249 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
4250 pragma No_Return (Error_Pragma_Arg_Ident);
4251 -- Outputs error message for current pragma. The message may contain a %
4252 -- that will be replaced with the pragma name. The parameter Arg must be
4253 -- a pragma argument association with a non-empty identifier (i.e. its
4254 -- Chars field must be set), and the error message is placed on the
4255 -- identifier. The message is placed using Error_Msg_N so the message
4256 -- may also contain an & insertion character which will reference
4257 -- the identifier. After placing the message, Pragma_Exit is raised.
4258 -- Note: this routine calls Fix_Error (see spec of that procedure for
4259 -- details).
4260
4261 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
4262 pragma No_Return (Error_Pragma_Ref);
4263 -- Outputs error message for current pragma. The message may contain
4264 -- a % that will be replaced with the pragma name. The parameter Ref
4265 -- must be an entity whose name can be referenced by & and sloc by #.
4266 -- After placing the message, Pragma_Exit is raised. Note: this routine
4267 -- calls Fix_Error (see spec of that procedure for details).
4268
4269 function Find_Lib_Unit_Name return Entity_Id;
4270 -- Used for a library unit pragma to find the entity to which the
4271 -- library unit pragma applies, returns the entity found.
4272
4273 procedure Find_Program_Unit_Name (Id : Node_Id);
4274 -- If the pragma is a compilation unit pragma, the id must denote the
4275 -- compilation unit in the same compilation, and the pragma must appear
4276 -- in the list of preceding or trailing pragmas. If it is a program
4277 -- unit pragma that is not a compilation unit pragma, then the
4278 -- identifier must be visible.
4279
4280 function Find_Unique_Parameterless_Procedure
4281 (Name : Entity_Id;
4282 Arg : Node_Id) return Entity_Id;
4283 -- Used for a procedure pragma to find the unique parameterless
4284 -- procedure identified by Name, returns it if it exists, otherwise
4285 -- errors out and uses Arg as the pragma argument for the message.
4286
4287 function Fix_Error (Msg : String) return String;
4288 -- This is called prior to issuing an error message. Msg is the normal
4289 -- error message issued in the pragma case. This routine checks for the
4290 -- case of a pragma coming from an aspect in the source, and returns a
4291 -- message suitable for the aspect case as follows:
4292 --
4293 -- Each substring "pragma" is replaced by "aspect"
4294 --
4295 -- If "argument of" is at the start of the error message text, it is
4296 -- replaced by "entity for".
4297 --
4298 -- If "argument" is at the start of the error message text, it is
4299 -- replaced by "entity".
4300 --
4301 -- So for example, "argument of pragma X must be discrete type"
4302 -- returns "entity for aspect X must be a discrete type".
4303
4304 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
4305 -- be different from the pragma name). If the current pragma results
4306 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
4307 -- original pragma name.
4308
4309 procedure Gather_Associations
4310 (Names : Name_List;
4311 Args : out Args_List);
4312 -- This procedure is used to gather the arguments for a pragma that
4313 -- permits arbitrary ordering of parameters using the normal rules
4314 -- for named and positional parameters. The Names argument is a list
4315 -- of Name_Id values that corresponds to the allowed pragma argument
4316 -- association identifiers in order. The result returned in Args is
4317 -- a list of corresponding expressions that are the pragma arguments.
4318 -- Note that this is a list of expressions, not of pragma argument
4319 -- associations (Gather_Associations has completely checked all the
4320 -- optional identifiers when it returns). An entry in Args is Empty
4321 -- on return if the corresponding argument is not present.
4322
4323 procedure GNAT_Pragma;
4324 -- Called for all GNAT defined pragmas to check the relevant restriction
4325 -- (No_Implementation_Pragmas).
4326
4327 function Is_Before_First_Decl
4328 (Pragma_Node : Node_Id;
4329 Decls : List_Id) return Boolean;
4330 -- Return True if Pragma_Node is before the first declarative item in
4331 -- Decls where Decls is the list of declarative items.
4332
4333 function Is_Configuration_Pragma return Boolean;
4334 -- Determines if the placement of the current pragma is appropriate
4335 -- for a configuration pragma.
4336
4337 function Is_In_Context_Clause return Boolean;
4338 -- Returns True if pragma appears within the context clause of a unit,
4339 -- and False for any other placement (does not generate any messages).
4340
4341 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
4342 -- Analyzes the argument, and determines if it is a static string
4343 -- expression, returns True if so, False if non-static or not String.
4344 -- A special case is that a string literal returns True in Ada 83 mode
4345 -- (which has no such thing as static string expressions). Note that
4346 -- the call analyzes its argument, so this cannot be used for the case
4347 -- where an identifier might not be declared.
4348
4349 procedure Pragma_Misplaced;
4350 pragma No_Return (Pragma_Misplaced);
4351 -- Issue fatal error message for misplaced pragma
4352
4353 procedure Process_Atomic_Independent_Shared_Volatile;
4354 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
4355 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
4356 -- and treated as being identical in effect to pragma Atomic.
4357
4358 procedure Process_Compile_Time_Warning_Or_Error;
4359 -- Common processing for Compile_Time_Error and Compile_Time_Warning
4360
4361 procedure Process_Convention
4362 (C : out Convention_Id;
4363 Ent : out Entity_Id);
4364 -- Common processing for Convention, Interface, Import and Export.
4365 -- Checks first two arguments of pragma, and sets the appropriate
4366 -- convention value in the specified entity or entities. On return
4367 -- C is the convention, Ent is the referenced entity.
4368
4369 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
4370 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
4371 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
4372
4373 procedure Process_Extended_Import_Export_Object_Pragma
4374 (Arg_Internal : Node_Id;
4375 Arg_External : Node_Id;
4376 Arg_Size : Node_Id);
4377 -- Common processing for the pragmas Import/Export_Object. The three
4378 -- arguments correspond to the three named parameters of the pragmas. An
4379 -- argument is empty if the corresponding parameter is not present in
4380 -- the pragma.
4381
4382 procedure Process_Extended_Import_Export_Internal_Arg
4383 (Arg_Internal : Node_Id := Empty);
4384 -- Common processing for all extended Import and Export pragmas. The
4385 -- argument is the pragma parameter for the Internal argument. If
4386 -- Arg_Internal is empty or inappropriate, an error message is posted.
4387 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
4388 -- set to identify the referenced entity.
4389
4390 procedure Process_Extended_Import_Export_Subprogram_Pragma
4391 (Arg_Internal : Node_Id;
4392 Arg_External : Node_Id;
4393 Arg_Parameter_Types : Node_Id;
4394 Arg_Result_Type : Node_Id := Empty;
4395 Arg_Mechanism : Node_Id;
4396 Arg_Result_Mechanism : Node_Id := Empty);
4397 -- Common processing for all extended Import and Export pragmas applying
4398 -- to subprograms. The caller omits any arguments that do not apply to
4399 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
4400 -- only in the Import_Function and Export_Function cases). The argument
4401 -- names correspond to the allowed pragma association identifiers.
4402
4403 procedure Process_Generic_List;
4404 -- Common processing for Share_Generic and Inline_Generic
4405
4406 procedure Process_Import_Or_Interface;
4407 -- Common processing for Import or Interface
4408
4409 procedure Process_Import_Predefined_Type;
4410 -- Processing for completing a type with pragma Import. This is used
4411 -- to declare types that match predefined C types, especially for cases
4412 -- without corresponding Ada predefined type.
4413
4414 type Inline_Status is (Suppressed, Disabled, Enabled);
4415 -- Inline status of a subprogram, indicated as follows:
4416 -- Suppressed: inlining is suppressed for the subprogram
4417 -- Disabled: no inlining is requested for the subprogram
4418 -- Enabled: inlining is requested/required for the subprogram
4419
4420 procedure Process_Inline (Status : Inline_Status);
4421 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
4422 -- indicates the inline status specified by the pragma.
4423
4424 procedure Process_Interface_Name
4425 (Subprogram_Def : Entity_Id;
4426 Ext_Arg : Node_Id;
4427 Link_Arg : Node_Id;
4428 Prag : Node_Id);
4429 -- Given the last two arguments of pragma Import, pragma Export, or
4430 -- pragma Interface_Name, performs validity checks and sets the
4431 -- Interface_Name field of the given subprogram entity to the
4432 -- appropriate external or link name, depending on the arguments given.
4433 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
4434 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
4435 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
4436 -- nor Link_Arg is present, the interface name is set to the default
4437 -- from the subprogram name. In addition, the pragma itself is passed
4438 -- to analyze any expressions in the case the pragma came from an aspect
4439 -- specification.
4440
4441 procedure Process_Interrupt_Or_Attach_Handler;
4442 -- Common processing for Interrupt and Attach_Handler pragmas
4443
4444 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
4445 -- Common processing for Restrictions and Restriction_Warnings pragmas.
4446 -- Warn is True for Restriction_Warnings, or for Restrictions if the
4447 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
4448 -- is not set in the Restrictions case.
4449
4450 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
4451 -- Common processing for Suppress and Unsuppress. The boolean parameter
4452 -- Suppress_Case is True for the Suppress case, and False for the
4453 -- Unsuppress case.
4454
4455 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
4456 -- Subsidiary to the analysis of pragmas Independent[_Components].
4457 -- Record such a pragma N applied to entity E for future checks.
4458
4459 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
4460 -- This procedure sets the Is_Exported flag for the given entity,
4461 -- checking that the entity was not previously imported. Arg is
4462 -- the argument that specified the entity. A check is also made
4463 -- for exporting inappropriate entities.
4464
4465 procedure Set_Extended_Import_Export_External_Name
4466 (Internal_Ent : Entity_Id;
4467 Arg_External : Node_Id);
4468 -- Common processing for all extended import export pragmas. The first
4469 -- argument, Internal_Ent, is the internal entity, which has already
4470 -- been checked for validity by the caller. Arg_External is from the
4471 -- Import or Export pragma, and may be null if no External parameter
4472 -- was present. If Arg_External is present and is a non-null string
4473 -- (a null string is treated as the default), then the Interface_Name
4474 -- field of Internal_Ent is set appropriately.
4475
4476 procedure Set_Imported (E : Entity_Id);
4477 -- This procedure sets the Is_Imported flag for the given entity,
4478 -- checking that it is not previously exported or imported.
4479
4480 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
4481 -- Mech is a parameter passing mechanism (see Import_Function syntax
4482 -- for MECHANISM_NAME). This routine checks that the mechanism argument
4483 -- has the right form, and if not issues an error message. If the
4484 -- argument has the right form then the Mechanism field of Ent is
4485 -- set appropriately.
4486
4487 procedure Set_Rational_Profile;
4488 -- Activate the set of configuration pragmas and permissions that make
4489 -- up the Rational profile.
4490
4491 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id);
4492 -- Activate the set of configuration pragmas and restrictions that make
4493 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
4494 -- GNAT_Ravenscar_EDF, Jorvik, or Ravenscar. N is the corresponding
4495 -- pragma node, which is used for error messages on any constructs
4496 -- violating the profile.
4497
4498 ---------------------
4499 -- Ada_2005_Pragma --
4500 ---------------------
4501
4502 procedure Ada_2005_Pragma is
4503 begin
4504 if Ada_Version <= Ada_95 then
4505 Check_Restriction (No_Implementation_Pragmas, N);
4506 end if;
4507 end Ada_2005_Pragma;
4508
4509 ---------------------
4510 -- Ada_2012_Pragma --
4511 ---------------------
4512
4513 procedure Ada_2012_Pragma is
4514 begin
4515 if Ada_Version <= Ada_2005 then
4516 Check_Restriction (No_Implementation_Pragmas, N);
4517 end if;
4518 end Ada_2012_Pragma;
4519
4520 ----------------------------
4521 -- Analyze_Depends_Global --
4522 ----------------------------
4523
4524 procedure Analyze_Depends_Global
4525 (Spec_Id : out Entity_Id;
4526 Subp_Decl : out Node_Id;
4527 Legal : out Boolean)
4528 is
4529 begin
4530 -- Assume that the pragma is illegal
4531
4532 Spec_Id := Empty;
4533 Subp_Decl := Empty;
4534 Legal := False;
4535
4536 GNAT_Pragma;
4537 Check_Arg_Count (1);
4538
4539 -- Ensure the proper placement of the pragma. Depends/Global must be
4540 -- associated with a subprogram declaration or a body that acts as a
4541 -- spec.
4542
4543 Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4544
4545 -- Entry
4546
4547 if Nkind (Subp_Decl) = N_Entry_Declaration then
4548 null;
4549
4550 -- Generic subprogram
4551
4552 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4553 null;
4554
4555 -- Object declaration of a single concurrent type
4556
4557 elsif Nkind (Subp_Decl) = N_Object_Declaration
4558 and then Is_Single_Concurrent_Object
4559 (Unique_Defining_Entity (Subp_Decl))
4560 then
4561 null;
4562
4563 -- Single task type
4564
4565 elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then
4566 null;
4567
4568 -- Abstract subprogram declaration
4569
4570 elsif Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4571 null;
4572
4573 -- Subprogram body acts as spec
4574
4575 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4576 and then No (Corresponding_Spec (Subp_Decl))
4577 then
4578 null;
4579
4580 -- Subprogram body stub acts as spec
4581
4582 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4583 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
4584 then
4585 null;
4586
4587 -- Subprogram declaration
4588
4589 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4590
4591 -- Pragmas Global and Depends are forbidden on null procedures
4592 -- (SPARK RM 6.1.2(2)).
4593
4594 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4595 and then Null_Present (Specification (Subp_Decl))
4596 then
4597 Error_Msg_N (Fix_Error
4598 ("pragma % cannot apply to null procedure"), N);
4599 return;
4600 end if;
4601
4602 -- Task type
4603
4604 elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then
4605 null;
4606
4607 else
4608 Pragma_Misplaced;
4609 end if;
4610
4611 -- If we get here, then the pragma is legal
4612
4613 Legal := True;
4614 Spec_Id := Unique_Defining_Entity (Subp_Decl);
4615
4616 -- When the related context is an entry, the entry must belong to a
4617 -- protected unit (SPARK RM 6.1.4(6)).
4618
4619 if Is_Entry_Declaration (Spec_Id)
4620 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
4621 then
4622 Pragma_Misplaced;
4623
4624 -- When the related context is an anonymous object created for a
4625 -- simple concurrent type, the type must be a task
4626 -- (SPARK RM 6.1.4(6)).
4627
4628 elsif Is_Single_Concurrent_Object (Spec_Id)
4629 and then Ekind (Etype (Spec_Id)) /= E_Task_Type
4630 then
4631 Pragma_Misplaced;
4632 end if;
4633
4634 -- A pragma that applies to a Ghost entity becomes Ghost for the
4635 -- purposes of legality checks and removal of ignored Ghost code.
4636
4637 Mark_Ghost_Pragma (N, Spec_Id);
4638 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4639 end Analyze_Depends_Global;
4640
4641 ------------------------
4642 -- Analyze_If_Present --
4643 ------------------------
4644
4645 procedure Analyze_If_Present (Id : Pragma_Id) is
4646 Stmt : Node_Id;
4647
4648 begin
4649 pragma Assert (Is_List_Member (N));
4650
4651 -- Inspect the declarations or statements following pragma N looking
4652 -- for another pragma whose Id matches the caller's request. If it is
4653 -- available, analyze it.
4654
4655 Stmt := Next (N);
4656 while Present (Stmt) loop
4657 if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then
4658 Analyze_Pragma (Stmt);
4659 exit;
4660
4661 -- The first source declaration or statement immediately following
4662 -- N ends the region where a pragma may appear.
4663
4664 elsif Comes_From_Source (Stmt) then
4665 exit;
4666 end if;
4667
4668 Next (Stmt);
4669 end loop;
4670 end Analyze_If_Present;
4671
4672 --------------------------------
4673 -- Analyze_Pre_Post_Condition --
4674 --------------------------------
4675
4676 procedure Analyze_Pre_Post_Condition is
4677 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
4678 Subp_Decl : Node_Id;
4679 Subp_Id : Entity_Id;
4680
4681 Duplicates_OK : Boolean := False;
4682 -- Flag set when a pre/postcondition allows multiple pragmas of the
4683 -- same kind.
4684
4685 In_Body_OK : Boolean := False;
4686 -- Flag set when a pre/postcondition is allowed to appear on a body
4687 -- even though the subprogram may have a spec.
4688
4689 Is_Pre_Post : Boolean := False;
4690 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4691 -- Post_Class.
4692
4693 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean;
4694 -- Implement rules in AI12-0131: an overriding operation can have
4695 -- a class-wide precondition only if one of its ancestors has an
4696 -- explicit class-wide precondition.
4697
4698 -----------------------------
4699 -- Inherits_Class_Wide_Pre --
4700 -----------------------------
4701
4702 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean is
4703 Typ : constant Entity_Id := Find_Dispatching_Type (E);
4704 Cont : Node_Id;
4705 Prag : Node_Id;
4706 Prev : Entity_Id := Overridden_Operation (E);
4707
4708 begin
4709 -- Check ancestors on the overriding operation to examine the
4710 -- preconditions that may apply to them.
4711
4712 while Present (Prev) loop
4713 Cont := Contract (Prev);
4714 if Present (Cont) then
4715 Prag := Pre_Post_Conditions (Cont);
4716 while Present (Prag) loop
4717 if Pragma_Name (Prag) = Name_Precondition
4718 and then Class_Present (Prag)
4719 then
4720 return True;
4721 end if;
4722
4723 Prag := Next_Pragma (Prag);
4724 end loop;
4725 end if;
4726
4727 -- For a type derived from a generic formal type, the operation
4728 -- inheriting the condition is a renaming, not an overriding of
4729 -- the operation of the formal. Ditto for an inherited
4730 -- operation which has no explicit contracts.
4731
4732 if Is_Generic_Type (Find_Dispatching_Type (Prev))
4733 or else not Comes_From_Source (Prev)
4734 then
4735 Prev := Alias (Prev);
4736 else
4737 Prev := Overridden_Operation (Prev);
4738 end if;
4739 end loop;
4740
4741 -- If the controlling type of the subprogram has progenitors, an
4742 -- interface operation implemented by the current operation may
4743 -- have a class-wide precondition.
4744
4745 if Has_Interfaces (Typ) then
4746 declare
4747 Elmt : Elmt_Id;
4748 Ints : Elist_Id;
4749 Prim : Entity_Id;
4750 Prim_Elmt : Elmt_Id;
4751 Prim_List : Elist_Id;
4752
4753 begin
4754 Collect_Interfaces (Typ, Ints);
4755 Elmt := First_Elmt (Ints);
4756
4757 -- Iterate over the primitive operations of each interface
4758
4759 while Present (Elmt) loop
4760 Prim_List := Direct_Primitive_Operations (Node (Elmt));
4761 Prim_Elmt := First_Elmt (Prim_List);
4762 while Present (Prim_Elmt) loop
4763 Prim := Node (Prim_Elmt);
4764 if Chars (Prim) = Chars (E)
4765 and then Present (Contract (Prim))
4766 and then Class_Present
4767 (Pre_Post_Conditions (Contract (Prim)))
4768 then
4769 return True;
4770 end if;
4771
4772 Next_Elmt (Prim_Elmt);
4773 end loop;
4774
4775 Next_Elmt (Elmt);
4776 end loop;
4777 end;
4778 end if;
4779
4780 return False;
4781 end Inherits_Class_Wide_Pre;
4782
4783 -- Start of processing for Analyze_Pre_Post_Condition
4784
4785 begin
4786 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4787 -- offer uniformity among the various kinds of pre/postconditions by
4788 -- rewriting the pragma identifier. This allows the retrieval of the
4789 -- original pragma name by routine Original_Aspect_Pragma_Name.
4790
4791 if Comes_From_Source (N) then
4792 if Pname in Name_Pre | Name_Pre_Class then
4793 Is_Pre_Post := True;
4794 Set_Class_Present (N, Pname = Name_Pre_Class);
4795 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
4796
4797 elsif Pname in Name_Post | Name_Post_Class then
4798 Is_Pre_Post := True;
4799 Set_Class_Present (N, Pname = Name_Post_Class);
4800 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
4801 end if;
4802 end if;
4803
4804 -- Determine the semantics with respect to duplicates and placement
4805 -- in a body. Pragmas Precondition and Postcondition were introduced
4806 -- before aspects and are not subject to the same aspect-like rules.
4807
4808 if Pname in Name_Precondition | Name_Postcondition then
4809 Duplicates_OK := True;
4810 In_Body_OK := True;
4811 end if;
4812
4813 GNAT_Pragma;
4814
4815 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4816 -- argument without an identifier.
4817
4818 if Is_Pre_Post then
4819 Check_Arg_Count (1);
4820 Check_No_Identifiers;
4821
4822 -- Pragmas Precondition and Postcondition have complex argument
4823 -- profile.
4824
4825 else
4826 Check_At_Least_N_Arguments (1);
4827 Check_At_Most_N_Arguments (2);
4828 Check_Optional_Identifier (Arg1, Name_Check);
4829
4830 if Present (Arg2) then
4831 Check_Optional_Identifier (Arg2, Name_Message);
4832 Preanalyze_Spec_Expression
4833 (Get_Pragma_Arg (Arg2), Standard_String);
4834 end if;
4835 end if;
4836
4837 -- For a pragma PPC in the extended main source unit, record enabled
4838 -- status in SCO.
4839 -- ??? nothing checks that the pragma is in the main source unit
4840
4841 if Is_Checked (N) and then not Split_PPC (N) then
4842 Set_SCO_Pragma_Enabled (Loc);
4843 end if;
4844
4845 -- Ensure the proper placement of the pragma
4846
4847 Subp_Decl :=
4848 Find_Related_Declaration_Or_Body
4849 (N, Do_Checks => not Duplicates_OK);
4850
4851 -- When a pre/postcondition pragma applies to an abstract subprogram,
4852 -- its original form must be an aspect with 'Class.
4853
4854 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4855 if not From_Aspect_Specification (N) then
4856 Error_Pragma
4857 ("pragma % cannot be applied to abstract subprogram");
4858
4859 elsif not Class_Present (N) then
4860 Error_Pragma
4861 ("aspect % requires ''Class for abstract subprogram");
4862 end if;
4863
4864 -- Entry declaration
4865
4866 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
4867 null;
4868
4869 -- Generic subprogram declaration
4870
4871 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4872 null;
4873
4874 -- Subprogram body
4875
4876 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4877 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
4878 then
4879 null;
4880
4881 -- Subprogram body stub
4882
4883 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4884 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
4885 then
4886 null;
4887
4888 -- Subprogram declaration
4889
4890 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4891
4892 -- AI05-0230: When a pre/postcondition pragma applies to a null
4893 -- procedure, its original form must be an aspect with 'Class.
4894
4895 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4896 and then Null_Present (Specification (Subp_Decl))
4897 and then From_Aspect_Specification (N)
4898 and then not Class_Present (N)
4899 then
4900 Error_Pragma ("aspect % requires ''Class for null procedure");
4901 end if;
4902
4903 -- Implement the legality checks mandated by AI12-0131:
4904 -- Pre'Class shall not be specified for an overriding primitive
4905 -- subprogram of a tagged type T unless the Pre'Class aspect is
4906 -- specified for the corresponding primitive subprogram of some
4907 -- ancestor of T.
4908
4909 declare
4910 E : constant Entity_Id := Defining_Entity (Subp_Decl);
4911
4912 begin
4913 if Class_Present (N)
4914 and then Pragma_Name (N) = Name_Precondition
4915 and then Present (Overridden_Operation (E))
4916 and then not Inherits_Class_Wide_Pre (E)
4917 then
4918 Error_Msg_N
4919 ("illegal class-wide precondition on overriding operation",
4920 Corresponding_Aspect (N));
4921 end if;
4922 end;
4923
4924 -- A renaming declaration may inherit a generated pragma, its
4925 -- placement comes from expansion, not from source.
4926
4927 elsif Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
4928 and then not Comes_From_Source (N)
4929 then
4930 null;
4931
4932 -- For Ada 2022, pre/postconditions can appear on formal subprograms
4933
4934 elsif Nkind (Subp_Decl) = N_Formal_Concrete_Subprogram_Declaration
4935 and then Ada_Version >= Ada_2022
4936 then
4937 null;
4938
4939 -- An access-to-subprogram type can have pre/postconditions, but
4940 -- these are transferred to the generated subprogram wrapper and
4941 -- analyzed there.
4942
4943 -- Otherwise the placement of the pragma is illegal
4944
4945 else
4946 Pragma_Misplaced;
4947 end if;
4948
4949 Subp_Id := Defining_Entity (Subp_Decl);
4950
4951 -- A pragma that applies to a Ghost entity becomes Ghost for the
4952 -- purposes of legality checks and removal of ignored Ghost code.
4953
4954 Mark_Ghost_Pragma (N, Subp_Id);
4955
4956 -- Chain the pragma on the contract for further processing by
4957 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4958
4959 Add_Contract_Item (N, Subp_Id);
4960
4961 -- Fully analyze the pragma when it appears inside an entry or
4962 -- subprogram body because it cannot benefit from forward references.
4963
4964 if Nkind (Subp_Decl) in N_Entry_Body
4965 | N_Subprogram_Body
4966 | N_Subprogram_Body_Stub
4967 then
4968 -- The legality checks of pragmas Precondition and Postcondition
4969 -- are affected by the SPARK mode in effect and the volatility of
4970 -- the context. Analyze all pragmas in a specific order.
4971
4972 Analyze_If_Present (Pragma_SPARK_Mode);
4973 Analyze_If_Present (Pragma_Volatile_Function);
4974 Analyze_Pre_Post_Condition_In_Decl_Part (N);
4975 end if;
4976 end Analyze_Pre_Post_Condition;
4977
4978 -----------------------------------------
4979 -- Analyze_Refined_Depends_Global_Post --
4980 -----------------------------------------
4981
4982 procedure Analyze_Refined_Depends_Global_Post
4983 (Spec_Id : out Entity_Id;
4984 Body_Id : out Entity_Id;
4985 Legal : out Boolean)
4986 is
4987 Body_Decl : Node_Id;
4988 Spec_Decl : Node_Id;
4989
4990 begin
4991 -- Assume that the pragma is illegal
4992
4993 Spec_Id := Empty;
4994 Body_Id := Empty;
4995 Legal := False;
4996
4997 GNAT_Pragma;
4998 Check_Arg_Count (1);
4999 Check_No_Identifiers;
5000
5001 -- Verify the placement of the pragma and check for duplicates. The
5002 -- pragma must apply to a subprogram body [stub].
5003
5004 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
5005
5006 if Nkind (Body_Decl) not in
5007 N_Entry_Body | N_Subprogram_Body | N_Subprogram_Body_Stub |
5008 N_Task_Body | N_Task_Body_Stub
5009 then
5010 Pragma_Misplaced;
5011 end if;
5012
5013 Body_Id := Defining_Entity (Body_Decl);
5014 Spec_Id := Unique_Defining_Entity (Body_Decl);
5015
5016 -- The pragma must apply to the second declaration of a subprogram.
5017 -- In other words, the body [stub] cannot acts as a spec.
5018
5019 if No (Spec_Id) then
5020 Error_Pragma ("pragma % cannot apply to a stand alone body");
5021
5022 -- Catch the case where the subprogram body is a subunit and acts as
5023 -- the third declaration of the subprogram.
5024
5025 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
5026 Error_Pragma ("pragma % cannot apply to a subunit");
5027 end if;
5028
5029 -- A refined pragma can only apply to the body [stub] of a subprogram
5030 -- declared in the visible part of a package. Retrieve the context of
5031 -- the subprogram declaration.
5032
5033 Spec_Decl := Unit_Declaration_Node (Spec_Id);
5034
5035 -- When dealing with protected entries or protected subprograms, use
5036 -- the enclosing protected type as the proper context.
5037
5038 if Ekind (Spec_Id) in E_Entry
5039 | E_Entry_Family
5040 | E_Function
5041 | E_Procedure
5042 and then Ekind (Scope (Spec_Id)) = E_Protected_Type
5043 then
5044 Spec_Decl := Declaration_Node (Scope (Spec_Id));
5045 end if;
5046
5047 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
5048 Error_Pragma
5049 (Fix_Msg (Spec_Id, "pragma % must apply to the body of "
5050 & "subprogram declared in a package specification"));
5051 end if;
5052
5053 -- If we get here, then the pragma is legal
5054
5055 Legal := True;
5056
5057 -- A pragma that applies to a Ghost entity becomes Ghost for the
5058 -- purposes of legality checks and removal of ignored Ghost code.
5059
5060 Mark_Ghost_Pragma (N, Spec_Id);
5061
5062 if Pname in Name_Refined_Depends | Name_Refined_Global then
5063 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
5064 end if;
5065 end Analyze_Refined_Depends_Global_Post;
5066
5067 ----------------------------------
5068 -- Analyze_Unmodified_Or_Unused --
5069 ----------------------------------
5070
5071 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False) is
5072 Arg : Node_Id;
5073 Arg_Expr : Node_Id;
5074 Arg_Id : Entity_Id;
5075
5076 Ghost_Error_Posted : Boolean := False;
5077 -- Flag set when an error concerning the illegal mix of Ghost and
5078 -- non-Ghost variables is emitted.
5079
5080 Ghost_Id : Entity_Id := Empty;
5081 -- The entity of the first Ghost variable encountered while
5082 -- processing the arguments of the pragma.
5083
5084 begin
5085 GNAT_Pragma;
5086 Check_At_Least_N_Arguments (1);
5087
5088 -- Loop through arguments
5089
5090 Arg := Arg1;
5091 while Present (Arg) loop
5092 Check_No_Identifier (Arg);
5093
5094 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
5095 -- in fact generate reference, so that the entity will have a
5096 -- reference, which will inhibit any warnings about it not
5097 -- being referenced, and also properly show up in the ali file
5098 -- as a reference. But this reference is recorded before the
5099 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5100 -- generated for this reference.
5101
5102 Check_Arg_Is_Local_Name (Arg);
5103 Arg_Expr := Get_Pragma_Arg (Arg);
5104
5105 if Is_Entity_Name (Arg_Expr) then
5106 Arg_Id := Entity (Arg_Expr);
5107
5108 -- Skip processing the argument if already flagged
5109
5110 if Is_Assignable (Arg_Id)
5111 and then not Has_Pragma_Unmodified (Arg_Id)
5112 and then not Has_Pragma_Unused (Arg_Id)
5113 then
5114 Set_Has_Pragma_Unmodified (Arg_Id);
5115
5116 if Is_Unused then
5117 Set_Has_Pragma_Unused (Arg_Id);
5118 end if;
5119
5120 -- A pragma that applies to a Ghost entity becomes Ghost for
5121 -- the purposes of legality checks and removal of ignored
5122 -- Ghost code.
5123
5124 Mark_Ghost_Pragma (N, Arg_Id);
5125
5126 -- Capture the entity of the first Ghost variable being
5127 -- processed for error detection purposes.
5128
5129 if Is_Ghost_Entity (Arg_Id) then
5130 if No (Ghost_Id) then
5131 Ghost_Id := Arg_Id;
5132 end if;
5133
5134 -- Otherwise the variable is non-Ghost. It is illegal to mix
5135 -- references to Ghost and non-Ghost entities
5136 -- (SPARK RM 6.9).
5137
5138 elsif Present (Ghost_Id)
5139 and then not Ghost_Error_Posted
5140 then
5141 Ghost_Error_Posted := True;
5142
5143 Error_Msg_Name_1 := Pname;
5144 Error_Msg_N
5145 ("pragma % cannot mention ghost and non-ghost "
5146 & "variables", N);
5147
5148 Error_Msg_Sloc := Sloc (Ghost_Id);
5149 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
5150
5151 Error_Msg_Sloc := Sloc (Arg_Id);
5152 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
5153 end if;
5154
5155 -- Warn if already flagged as Unused or Unmodified
5156
5157 elsif Has_Pragma_Unmodified (Arg_Id) then
5158 if Has_Pragma_Unused (Arg_Id) then
5159 Error_Msg_NE
5160 (Fix_Error ("??pragma Unused already given for &!"),
5161 Arg_Expr, Arg_Id);
5162 else
5163 Error_Msg_NE
5164 (Fix_Error ("??pragma Unmodified already given for &!"),
5165 Arg_Expr, Arg_Id);
5166 end if;
5167
5168 -- Otherwise the pragma referenced an illegal entity
5169
5170 else
5171 Error_Pragma_Arg
5172 ("pragma% can only be applied to a variable", Arg_Expr);
5173 end if;
5174 end if;
5175
5176 Next (Arg);
5177 end loop;
5178 end Analyze_Unmodified_Or_Unused;
5179
5180 ------------------------------------
5181 -- Analyze_Unreferenced_Or_Unused --
5182 ------------------------------------
5183
5184 procedure Analyze_Unreferenced_Or_Unused
5185 (Is_Unused : Boolean := False)
5186 is
5187 Arg : Node_Id;
5188 Arg_Expr : Node_Id;
5189 Arg_Id : Entity_Id;
5190 Citem : Node_Id;
5191
5192 Ghost_Error_Posted : Boolean := False;
5193 -- Flag set when an error concerning the illegal mix of Ghost and
5194 -- non-Ghost names is emitted.
5195
5196 Ghost_Id : Entity_Id := Empty;
5197 -- The entity of the first Ghost name encountered while processing
5198 -- the arguments of the pragma.
5199
5200 begin
5201 GNAT_Pragma;
5202 Check_At_Least_N_Arguments (1);
5203
5204 -- Check case of appearing within context clause
5205
5206 if not Is_Unused and then Is_In_Context_Clause then
5207
5208 -- The arguments must all be units mentioned in a with clause in
5209 -- the same context clause. Note that Par.Prag already checked
5210 -- that the arguments are either identifiers or selected
5211 -- components.
5212
5213 Arg := Arg1;
5214 while Present (Arg) loop
5215 Citem := First (List_Containing (N));
5216 while Citem /= N loop
5217 Arg_Expr := Get_Pragma_Arg (Arg);
5218
5219 if Nkind (Citem) = N_With_Clause
5220 and then Same_Name (Name (Citem), Arg_Expr)
5221 then
5222 Set_Has_Pragma_Unreferenced
5223 (Cunit_Entity
5224 (Get_Source_Unit
5225 (Library_Unit (Citem))));
5226 Set_Elab_Unit_Name (Arg_Expr, Name (Citem));
5227 exit;
5228 end if;
5229
5230 Next (Citem);
5231 end loop;
5232
5233 if Citem = N then
5234 Error_Pragma_Arg
5235 ("argument of pragma% is not withed unit", Arg);
5236 end if;
5237
5238 Next (Arg);
5239 end loop;
5240
5241 -- Case of not in list of context items
5242
5243 else
5244 Arg := Arg1;
5245 while Present (Arg) loop
5246 Check_No_Identifier (Arg);
5247
5248 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
5249 -- in fact generate reference, so that the entity will have a
5250 -- reference, which will inhibit any warnings about it not
5251 -- being referenced, and also properly show up in the ali file
5252 -- as a reference. But this reference is recorded before the
5253 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5254 -- generated for this reference.
5255
5256 Check_Arg_Is_Local_Name (Arg);
5257 Arg_Expr := Get_Pragma_Arg (Arg);
5258
5259 if Is_Entity_Name (Arg_Expr) then
5260 Arg_Id := Entity (Arg_Expr);
5261
5262 -- Warn if already flagged as Unused or Unreferenced and
5263 -- skip processing the argument.
5264
5265 if Has_Pragma_Unreferenced (Arg_Id) then
5266 if Has_Pragma_Unused (Arg_Id) then
5267 Error_Msg_NE
5268 (Fix_Error ("??pragma Unused already given for &!"),
5269 Arg_Expr, Arg_Id);
5270 else
5271 Error_Msg_NE
5272 (Fix_Error
5273 ("??pragma Unreferenced already given for &!"),
5274 Arg_Expr, Arg_Id);
5275 end if;
5276
5277 -- Apply Unreferenced to the entity
5278
5279 else
5280 -- If the entity is overloaded, the pragma applies to the
5281 -- most recent overloading, as documented. In this case,
5282 -- name resolution does not generate a reference, so it
5283 -- must be done here explicitly.
5284
5285 if Is_Overloaded (Arg_Expr) then
5286 Generate_Reference (Arg_Id, N);
5287 end if;
5288
5289 Set_Has_Pragma_Unreferenced (Arg_Id);
5290
5291 if Is_Unused then
5292 Set_Has_Pragma_Unused (Arg_Id);
5293 end if;
5294
5295 -- A pragma that applies to a Ghost entity becomes Ghost
5296 -- for the purposes of legality checks and removal of
5297 -- ignored Ghost code.
5298
5299 Mark_Ghost_Pragma (N, Arg_Id);
5300
5301 -- Capture the entity of the first Ghost name being
5302 -- processed for error detection purposes.
5303
5304 if Is_Ghost_Entity (Arg_Id) then
5305 if No (Ghost_Id) then
5306 Ghost_Id := Arg_Id;
5307 end if;
5308
5309 -- Otherwise the name is non-Ghost. It is illegal to mix
5310 -- references to Ghost and non-Ghost entities
5311 -- (SPARK RM 6.9).
5312
5313 elsif Present (Ghost_Id)
5314 and then not Ghost_Error_Posted
5315 then
5316 Ghost_Error_Posted := True;
5317
5318 Error_Msg_Name_1 := Pname;
5319 Error_Msg_N
5320 ("pragma % cannot mention ghost and non-ghost "
5321 & "names", N);
5322
5323 Error_Msg_Sloc := Sloc (Ghost_Id);
5324 Error_Msg_NE
5325 ("\& # declared as ghost", N, Ghost_Id);
5326
5327 Error_Msg_Sloc := Sloc (Arg_Id);
5328 Error_Msg_NE
5329 ("\& # declared as non-ghost", N, Arg_Id);
5330 end if;
5331 end if;
5332 end if;
5333
5334 Next (Arg);
5335 end loop;
5336 end if;
5337 end Analyze_Unreferenced_Or_Unused;
5338
5339 --------------------------
5340 -- Check_Ada_83_Warning --
5341 --------------------------
5342
5343 procedure Check_Ada_83_Warning is
5344 begin
5345 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5346 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
5347 end if;
5348 end Check_Ada_83_Warning;
5349
5350 ---------------------
5351 -- Check_Arg_Count --
5352 ---------------------
5353
5354 procedure Check_Arg_Count (Required : Nat) is
5355 begin
5356 if Arg_Count /= Required then
5357 Error_Pragma ("wrong number of arguments for pragma%");
5358 end if;
5359 end Check_Arg_Count;
5360
5361 --------------------------------
5362 -- Check_Arg_Is_External_Name --
5363 --------------------------------
5364
5365 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
5366 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5367
5368 begin
5369 if Nkind (Argx) = N_Identifier then
5370 return;
5371
5372 else
5373 Analyze_And_Resolve (Argx, Standard_String);
5374
5375 if Is_OK_Static_Expression (Argx) then
5376 return;
5377
5378 elsif Etype (Argx) = Any_Type then
5379 raise Pragma_Exit;
5380
5381 -- An interesting special case, if we have a string literal and
5382 -- we are in Ada 83 mode, then we allow it even though it will
5383 -- not be flagged as static. This allows expected Ada 83 mode
5384 -- use of external names which are string literals, even though
5385 -- technically these are not static in Ada 83.
5386
5387 elsif Ada_Version = Ada_83
5388 and then Nkind (Argx) = N_String_Literal
5389 then
5390 return;
5391
5392 -- Here we have a real error (non-static expression)
5393
5394 else
5395 Error_Msg_Name_1 := Pname;
5396 Flag_Non_Static_Expr
5397 (Fix_Error ("argument for pragma% must be a identifier or "
5398 & "static string expression!"), Argx);
5399
5400 raise Pragma_Exit;
5401 end if;
5402 end if;
5403 end Check_Arg_Is_External_Name;
5404
5405 -----------------------------
5406 -- Check_Arg_Is_Identifier --
5407 -----------------------------
5408
5409 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
5410 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5411 begin
5412 if Nkind (Argx) /= N_Identifier then
5413 Error_Pragma_Arg ("argument for pragma% must be identifier", Argx);
5414 end if;
5415 end Check_Arg_Is_Identifier;
5416
5417 ----------------------------------
5418 -- Check_Arg_Is_Integer_Literal --
5419 ----------------------------------
5420
5421 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
5422 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5423 begin
5424 if Nkind (Argx) /= N_Integer_Literal then
5425 Error_Pragma_Arg
5426 ("argument for pragma% must be integer literal", Argx);
5427 end if;
5428 end Check_Arg_Is_Integer_Literal;
5429
5430 -------------------------------------------
5431 -- Check_Arg_Is_Library_Level_Local_Name --
5432 -------------------------------------------
5433
5434 -- LOCAL_NAME ::=
5435 -- DIRECT_NAME
5436 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5437 -- | library_unit_NAME
5438
5439 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
5440 begin
5441 Check_Arg_Is_Local_Name (Arg);
5442
5443 -- If it came from an aspect, we want to give the error just as if it
5444 -- came from source.
5445
5446 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
5447 and then (Comes_From_Source (N)
5448 or else Present (Corresponding_Aspect (Parent (Arg))))
5449 then
5450 Error_Pragma_Arg
5451 ("argument for pragma% must be library level entity", Arg);
5452 end if;
5453 end Check_Arg_Is_Library_Level_Local_Name;
5454
5455 -----------------------------
5456 -- Check_Arg_Is_Local_Name --
5457 -----------------------------
5458
5459 -- LOCAL_NAME ::=
5460 -- DIRECT_NAME
5461 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5462 -- | library_unit_NAME
5463
5464 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
5465 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5466
5467 begin
5468 -- If this pragma came from an aspect specification, we don't want to
5469 -- check for this error, because that would cause spurious errors, in
5470 -- case a type is frozen in a scope more nested than the type. The
5471 -- aspect itself of course can't be anywhere but on the declaration
5472 -- itself.
5473
5474 if Nkind (Arg) = N_Pragma_Argument_Association then
5475 if From_Aspect_Specification (Parent (Arg)) then
5476 return;
5477 end if;
5478
5479 -- Arg is the Expression of an N_Pragma_Argument_Association
5480
5481 else
5482 if From_Aspect_Specification (Parent (Parent (Arg))) then
5483 return;
5484 end if;
5485 end if;
5486
5487 Analyze (Argx);
5488
5489 if Nkind (Argx) not in N_Direct_Name
5490 and then (Nkind (Argx) /= N_Attribute_Reference
5491 or else Present (Expressions (Argx))
5492 or else Nkind (Prefix (Argx)) /= N_Identifier)
5493 and then (not Is_Entity_Name (Argx)
5494 or else not Is_Compilation_Unit (Entity (Argx)))
5495 then
5496 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
5497 end if;
5498
5499 -- No further check required if not an entity name
5500
5501 if not Is_Entity_Name (Argx) then
5502 null;
5503
5504 else
5505 declare
5506 OK : Boolean;
5507 Ent : constant Entity_Id := Entity (Argx);
5508 Scop : constant Entity_Id := Scope (Ent);
5509
5510 begin
5511 -- Case of a pragma applied to a compilation unit: pragma must
5512 -- occur immediately after the program unit in the compilation.
5513
5514 if Is_Compilation_Unit (Ent) then
5515 declare
5516 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
5517
5518 begin
5519 -- Case of pragma placed immediately after spec
5520
5521 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
5522 OK := True;
5523
5524 -- Case of pragma placed immediately after body
5525
5526 elsif Nkind (Decl) = N_Subprogram_Declaration
5527 and then Present (Corresponding_Body (Decl))
5528 then
5529 OK := Parent (N) =
5530 Aux_Decls_Node
5531 (Parent (Unit_Declaration_Node
5532 (Corresponding_Body (Decl))));
5533
5534 -- All other cases are illegal
5535
5536 else
5537 OK := False;
5538 end if;
5539 end;
5540
5541 -- Special restricted placement rule from 10.2.1(11.8/2)
5542
5543 elsif Is_Generic_Formal (Ent)
5544 and then Prag_Id = Pragma_Preelaborable_Initialization
5545 then
5546 OK := List_Containing (N) =
5547 Generic_Formal_Declarations
5548 (Unit_Declaration_Node (Scop));
5549
5550 -- If this is an aspect applied to a subprogram body, the
5551 -- pragma is inserted in its declarative part.
5552
5553 elsif From_Aspect_Specification (N)
5554 and then Ent = Current_Scope
5555 and then
5556 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
5557 then
5558 OK := True;
5559
5560 -- If the aspect is a predicate (possibly others ???) and the
5561 -- context is a record type, this is a discriminant expression
5562 -- within a type declaration, that freezes the predicated
5563 -- subtype.
5564
5565 elsif From_Aspect_Specification (N)
5566 and then Prag_Id = Pragma_Predicate
5567 and then Ekind (Current_Scope) = E_Record_Type
5568 and then Scop = Scope (Current_Scope)
5569 then
5570 OK := True;
5571
5572 -- Special case for postconditions wrappers
5573
5574 elsif Ekind (Scop) in Subprogram_Kind
5575 and then Present (Wrapped_Statements (Scop))
5576 and then Wrapped_Statements (Scop) = Current_Scope
5577 then
5578 OK := True;
5579
5580 -- Default case, just check that the pragma occurs in the scope
5581 -- of the entity denoted by the name.
5582
5583 else
5584 OK := Current_Scope = Scop;
5585 end if;
5586
5587 if not OK then
5588 Error_Pragma_Arg
5589 ("pragma% argument must be in same declarative part", Arg);
5590 end if;
5591 end;
5592 end if;
5593 end Check_Arg_Is_Local_Name;
5594
5595 ---------------------------------
5596 -- Check_Arg_Is_Locking_Policy --
5597 ---------------------------------
5598
5599 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
5600 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5601
5602 begin
5603 Check_Arg_Is_Identifier (Argx);
5604
5605 if not Is_Locking_Policy_Name (Chars (Argx)) then
5606 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
5607 end if;
5608 end Check_Arg_Is_Locking_Policy;
5609
5610 -----------------------------------------------
5611 -- Check_Arg_Is_Partition_Elaboration_Policy --
5612 -----------------------------------------------
5613
5614 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
5615 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5616
5617 begin
5618 Check_Arg_Is_Identifier (Argx);
5619
5620 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
5621 Error_Pragma_Arg
5622 ("& is not a valid partition elaboration policy name", Argx);
5623 end if;
5624 end Check_Arg_Is_Partition_Elaboration_Policy;
5625
5626 -------------------------
5627 -- Check_Arg_Is_One_Of --
5628 -------------------------
5629
5630 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5631 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5632
5633 begin
5634 Check_Arg_Is_Identifier (Argx);
5635
5636 if Chars (Argx) not in N1 | N2 then
5637 Error_Msg_Name_2 := N1;
5638 Error_Msg_Name_3 := N2;
5639 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
5640 end if;
5641 end Check_Arg_Is_One_Of;
5642
5643 procedure Check_Arg_Is_One_Of
5644 (Arg : Node_Id;
5645 N1, N2, N3 : Name_Id)
5646 is
5647 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5648
5649 begin
5650 Check_Arg_Is_Identifier (Argx);
5651
5652 if Chars (Argx) not in N1 | N2 | N3 then
5653 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5654 end if;
5655 end Check_Arg_Is_One_Of;
5656
5657 procedure Check_Arg_Is_One_Of
5658 (Arg : Node_Id;
5659 N1, N2, N3, N4 : Name_Id)
5660 is
5661 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5662
5663 begin
5664 Check_Arg_Is_Identifier (Argx);
5665
5666 if Chars (Argx) not in N1 | N2 | N3 | N4 then
5667 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5668 end if;
5669 end Check_Arg_Is_One_Of;
5670
5671 procedure Check_Arg_Is_One_Of
5672 (Arg : Node_Id;
5673 N1, N2, N3, N4, N5 : Name_Id)
5674 is
5675 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5676
5677 begin
5678 Check_Arg_Is_Identifier (Argx);
5679
5680 if Chars (Argx) not in N1 | N2 | N3 | N4 | N5 then
5681 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5682 end if;
5683 end Check_Arg_Is_One_Of;
5684
5685 ---------------------------------
5686 -- Check_Arg_Is_Queuing_Policy --
5687 ---------------------------------
5688
5689 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
5690 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5691
5692 begin
5693 Check_Arg_Is_Identifier (Argx);
5694
5695 if not Is_Queuing_Policy_Name (Chars (Argx)) then
5696 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
5697 end if;
5698 end Check_Arg_Is_Queuing_Policy;
5699
5700 ---------------------------------------
5701 -- Check_Arg_Is_OK_Static_Expression --
5702 ---------------------------------------
5703
5704 procedure Check_Arg_Is_OK_Static_Expression
5705 (Arg : Node_Id;
5706 Typ : Entity_Id := Empty)
5707 is
5708 begin
5709 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
5710 end Check_Arg_Is_OK_Static_Expression;
5711
5712 ------------------------------------------
5713 -- Check_Arg_Is_Task_Dispatching_Policy --
5714 ------------------------------------------
5715
5716 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
5717 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5718
5719 begin
5720 Check_Arg_Is_Identifier (Argx);
5721
5722 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
5723 Error_Pragma_Arg
5724 ("& is not an allowed task dispatching policy name", Argx);
5725 end if;
5726 end Check_Arg_Is_Task_Dispatching_Policy;
5727
5728 ---------------------
5729 -- Check_Arg_Order --
5730 ---------------------
5731
5732 procedure Check_Arg_Order (Names : Name_List) is
5733 Arg : Node_Id;
5734
5735 Highest_So_Far : Natural := 0;
5736 -- Highest index in Names seen do far
5737
5738 begin
5739 Arg := Arg1;
5740 for J in 1 .. Arg_Count loop
5741 if Chars (Arg) /= No_Name then
5742 for K in Names'Range loop
5743 if Chars (Arg) = Names (K) then
5744 if K < Highest_So_Far then
5745 Error_Msg_Name_1 := Pname;
5746 Error_Msg_N
5747 ("parameters out of order for pragma%", Arg);
5748 Error_Msg_Name_1 := Names (K);
5749 Error_Msg_Name_2 := Names (Highest_So_Far);
5750 Error_Msg_N ("\% must appear before %", Arg);
5751 raise Pragma_Exit;
5752
5753 else
5754 Highest_So_Far := K;
5755 end if;
5756 end if;
5757 end loop;
5758 end if;
5759
5760 Arg := Next (Arg);
5761 end loop;
5762 end Check_Arg_Order;
5763
5764 --------------------------------
5765 -- Check_At_Least_N_Arguments --
5766 --------------------------------
5767
5768 procedure Check_At_Least_N_Arguments (N : Nat) is
5769 begin
5770 if Arg_Count < N then
5771 Error_Pragma ("too few arguments for pragma%");
5772 end if;
5773 end Check_At_Least_N_Arguments;
5774
5775 -------------------------------
5776 -- Check_At_Most_N_Arguments --
5777 -------------------------------
5778
5779 procedure Check_At_Most_N_Arguments (N : Nat) is
5780 Arg : Node_Id;
5781 begin
5782 if Arg_Count > N then
5783 Arg := Arg1;
5784 for J in 1 .. N loop
5785 Next (Arg);
5786 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
5787 end loop;
5788 end if;
5789 end Check_At_Most_N_Arguments;
5790
5791 ---------------------
5792 -- Check_Component --
5793 ---------------------
5794
5795 procedure Check_Component
5796 (Comp : Node_Id;
5797 UU_Typ : Entity_Id;
5798 In_Variant_Part : Boolean := False)
5799 is
5800 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
5801 Sindic : constant Node_Id :=
5802 Subtype_Indication (Component_Definition (Comp));
5803 Typ : constant Entity_Id := Etype (Comp_Id);
5804
5805 begin
5806 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
5807 -- object constraint, then the component type shall be an Unchecked_
5808 -- Union.
5809
5810 if Nkind (Sindic) = N_Subtype_Indication
5811 and then Has_Per_Object_Constraint (Comp_Id)
5812 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
5813 then
5814 Error_Msg_N
5815 ("component subtype subject to per-object constraint "
5816 & "must be an Unchecked_Union", Comp);
5817
5818 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
5819 -- the body of a generic unit, or within the body of any of its
5820 -- descendant library units, no part of the type of a component
5821 -- declared in a variant_part of the unchecked union type shall be of
5822 -- a formal private type or formal private extension declared within
5823 -- the formal part of the generic unit.
5824
5825 elsif Ada_Version >= Ada_2012
5826 and then In_Generic_Body (UU_Typ)
5827 and then In_Variant_Part
5828 and then Is_Private_Type (Typ)
5829 and then Is_Generic_Type (Typ)
5830 then
5831 Error_Msg_N
5832 ("component of unchecked union cannot be of generic type", Comp);
5833
5834 elsif Needs_Finalization (Typ) then
5835 Error_Msg_N
5836 ("component of unchecked union cannot be controlled", Comp);
5837
5838 elsif Has_Task (Typ) then
5839 Error_Msg_N
5840 ("component of unchecked union cannot have tasks", Comp);
5841 end if;
5842 end Check_Component;
5843
5844 ----------------------------
5845 -- Check_Duplicate_Pragma --
5846 ----------------------------
5847
5848 procedure Check_Duplicate_Pragma (E : Entity_Id) is
5849 Id : Entity_Id := E;
5850 P : Node_Id;
5851
5852 begin
5853 -- Nothing to do if this pragma comes from an aspect specification,
5854 -- since we could not be duplicating a pragma, and we dealt with the
5855 -- case of duplicated aspects in Analyze_Aspect_Specifications.
5856
5857 if From_Aspect_Specification (N) then
5858 return;
5859 end if;
5860
5861 -- Otherwise current pragma may duplicate previous pragma or a
5862 -- previously given aspect specification or attribute definition
5863 -- clause for the same pragma.
5864
5865 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
5866
5867 if Present (P) then
5868
5869 -- If the entity is a type, then we have to make sure that the
5870 -- ostensible duplicate is not for a parent type from which this
5871 -- type is derived.
5872
5873 if Is_Type (E) then
5874 if Nkind (P) = N_Pragma then
5875 declare
5876 Args : constant List_Id :=
5877 Pragma_Argument_Associations (P);
5878 begin
5879 if Present (Args)
5880 and then Is_Entity_Name (Expression (First (Args)))
5881 and then Is_Type (Entity (Expression (First (Args))))
5882 and then Entity (Expression (First (Args))) /= E
5883 then
5884 return;
5885 end if;
5886 end;
5887
5888 elsif Nkind (P) = N_Aspect_Specification
5889 and then Is_Type (Entity (P))
5890 and then Entity (P) /= E
5891 then
5892 return;
5893 end if;
5894 end if;
5895
5896 -- Here we have a definite duplicate
5897
5898 Error_Msg_Name_1 := Pragma_Name (N);
5899 Error_Msg_Sloc := Sloc (P);
5900
5901 -- For a single protected or a single task object, the error is
5902 -- issued on the original entity.
5903
5904 if Ekind (Id) in E_Task_Type | E_Protected_Type then
5905 Id := Defining_Identifier (Original_Node (Parent (Id)));
5906 end if;
5907
5908 if Nkind (P) = N_Aspect_Specification
5909 or else From_Aspect_Specification (P)
5910 then
5911 Error_Msg_NE ("aspect% for & previously given#", N, Id);
5912 else
5913 -- If -gnatwr is set, warn in case of a duplicate pragma
5914 -- [No_]Inline which is suspicious but not an error, generate
5915 -- an error for other pragmas.
5916
5917 if Pragma_Name (N) in Name_Inline | Name_No_Inline then
5918 if Warn_On_Redundant_Constructs then
5919 Error_Msg_NE
5920 ("?r?pragma% for & duplicates pragma#", N, Id);
5921 end if;
5922 else
5923 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
5924 end if;
5925 end if;
5926
5927 raise Pragma_Exit;
5928 end if;
5929 end Check_Duplicate_Pragma;
5930
5931 ----------------------------------
5932 -- Check_Duplicated_Export_Name --
5933 ----------------------------------
5934
5935 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
5936 String_Val : constant String_Id := Strval (Nam);
5937
5938 begin
5939 -- We are only interested in the export case, and in the case of
5940 -- generics, it is the instance, not the template, that is the
5941 -- problem (the template will generate a warning in any case).
5942
5943 if not Inside_A_Generic
5944 and then (Prag_Id = Pragma_Export
5945 or else
5946 Prag_Id = Pragma_Export_Procedure
5947 or else
5948 Prag_Id = Pragma_Export_Valued_Procedure
5949 or else
5950 Prag_Id = Pragma_Export_Function)
5951 then
5952 for J in Externals.First .. Externals.Last loop
5953 if String_Equal (String_Val, Strval (Externals.Table (J))) then
5954 Error_Msg_Sloc := Sloc (Externals.Table (J));
5955 Error_Msg_N ("external name duplicates name given#", Nam);
5956 exit;
5957 end if;
5958 end loop;
5959
5960 Externals.Append (Nam);
5961 end if;
5962 end Check_Duplicated_Export_Name;
5963
5964 ----------------------------------------
5965 -- Check_Expr_Is_OK_Static_Expression --
5966 ----------------------------------------
5967
5968 procedure Check_Expr_Is_OK_Static_Expression
5969 (Expr : Node_Id;
5970 Typ : Entity_Id := Empty)
5971 is
5972 begin
5973 if Present (Typ) then
5974 Analyze_And_Resolve (Expr, Typ);
5975 else
5976 Analyze_And_Resolve (Expr);
5977 end if;
5978
5979 -- An expression cannot be considered static if its resolution failed
5980 -- or if it's erroneous. Stop the analysis of the related pragma.
5981
5982 if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
5983 raise Pragma_Exit;
5984
5985 elsif Is_OK_Static_Expression (Expr) then
5986 return;
5987
5988 -- An interesting special case, if we have a string literal and we
5989 -- are in Ada 83 mode, then we allow it even though it will not be
5990 -- flagged as static. This allows the use of Ada 95 pragmas like
5991 -- Import in Ada 83 mode. They will of course be flagged with
5992 -- warnings as usual, but will not cause errors.
5993
5994 elsif Ada_Version = Ada_83
5995 and then Nkind (Expr) = N_String_Literal
5996 then
5997 return;
5998
5999 -- Finally, we have a real error
6000
6001 else
6002 Error_Msg_Name_1 := Pname;
6003 Flag_Non_Static_Expr
6004 (Fix_Error ("argument for pragma% must be a static expression!"),
6005 Expr);
6006 raise Pragma_Exit;
6007 end if;
6008 end Check_Expr_Is_OK_Static_Expression;
6009
6010 -------------------------
6011 -- Check_First_Subtype --
6012 -------------------------
6013
6014 procedure Check_First_Subtype (Arg : Node_Id) is
6015 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6016 Ent : constant Entity_Id := Entity (Argx);
6017
6018 begin
6019 if Is_First_Subtype (Ent) then
6020 null;
6021
6022 elsif Is_Type (Ent) then
6023 Error_Pragma_Arg
6024 ("pragma% cannot apply to subtype", Argx);
6025
6026 elsif Is_Object (Ent) then
6027 Error_Pragma_Arg
6028 ("pragma% cannot apply to object, requires a type", Argx);
6029
6030 else
6031 Error_Pragma_Arg
6032 ("pragma% cannot apply to&, requires a type", Argx);
6033 end if;
6034 end Check_First_Subtype;
6035
6036 ----------------------
6037 -- Check_Identifier --
6038 ----------------------
6039
6040 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
6041 begin
6042 if Present (Arg)
6043 and then Nkind (Arg) = N_Pragma_Argument_Association
6044 then
6045 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
6046 Error_Msg_Name_1 := Pname;
6047 Error_Msg_Name_2 := Id;
6048 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6049 raise Pragma_Exit;
6050 end if;
6051 end if;
6052 end Check_Identifier;
6053
6054 --------------------------------
6055 -- Check_Identifier_Is_One_Of --
6056 --------------------------------
6057
6058 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
6059 begin
6060 if Present (Arg)
6061 and then Nkind (Arg) = N_Pragma_Argument_Association
6062 then
6063 if Chars (Arg) = No_Name then
6064 Error_Msg_Name_1 := Pname;
6065 Error_Msg_N ("pragma% argument expects an identifier", Arg);
6066 raise Pragma_Exit;
6067
6068 elsif Chars (Arg) /= N1
6069 and then Chars (Arg) /= N2
6070 then
6071 Error_Msg_Name_1 := Pname;
6072 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
6073 raise Pragma_Exit;
6074 end if;
6075 end if;
6076 end Check_Identifier_Is_One_Of;
6077
6078 ---------------------------
6079 -- Check_In_Main_Program --
6080 ---------------------------
6081
6082 procedure Check_In_Main_Program is
6083 P : constant Node_Id := Parent (N);
6084
6085 begin
6086 -- Must be in subprogram body
6087
6088 if Nkind (P) /= N_Subprogram_Body then
6089 Error_Pragma ("% pragma allowed only in subprogram");
6090
6091 -- Otherwise warn if obviously not main program
6092
6093 elsif Present (Parameter_Specifications (Specification (P)))
6094 or else not Is_Compilation_Unit (Defining_Entity (P))
6095 then
6096 Error_Msg_Name_1 := Pname;
6097 Error_Msg_N
6098 ("??pragma% is only effective in main program", N);
6099 end if;
6100 end Check_In_Main_Program;
6101
6102 ---------------------------------------
6103 -- Check_Interrupt_Or_Attach_Handler --
6104 ---------------------------------------
6105
6106 procedure Check_Interrupt_Or_Attach_Handler is
6107 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
6108 Handler_Proc, Proc_Scope : Entity_Id;
6109
6110 begin
6111 Analyze (Arg1_X);
6112
6113 if Prag_Id = Pragma_Interrupt_Handler then
6114 Check_Restriction (No_Dynamic_Attachment, N);
6115 end if;
6116
6117 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
6118 Proc_Scope := Scope (Handler_Proc);
6119
6120 if Ekind (Proc_Scope) /= E_Protected_Type then
6121 Error_Pragma_Arg
6122 ("argument of pragma% must be protected procedure", Arg1);
6123 end if;
6124
6125 -- For pragma case (as opposed to access case), check placement.
6126 -- We don't need to do that for aspects, because we have the
6127 -- check that they aspect applies an appropriate procedure.
6128
6129 if not From_Aspect_Specification (N)
6130 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
6131 then
6132 Error_Pragma ("pragma% must be in protected definition");
6133 end if;
6134
6135 if not Is_Library_Level_Entity (Proc_Scope) then
6136 Error_Pragma_Arg
6137 ("argument for pragma% must be library level entity", Arg1);
6138 end if;
6139
6140 -- AI05-0033: A pragma cannot appear within a generic body, because
6141 -- instance can be in a nested scope. The check that protected type
6142 -- is itself a library-level declaration is done elsewhere.
6143
6144 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
6145 -- handle code prior to AI-0033. Analysis tools typically are not
6146 -- interested in this pragma in any case, so no need to worry too
6147 -- much about its placement.
6148
6149 if Inside_A_Generic then
6150 if Ekind (Scope (Current_Scope)) = E_Generic_Package
6151 and then In_Package_Body (Scope (Current_Scope))
6152 and then not Relaxed_RM_Semantics
6153 then
6154 Error_Pragma ("pragma% cannot be used inside a generic");
6155 end if;
6156 end if;
6157 end Check_Interrupt_Or_Attach_Handler;
6158
6159 ---------------------------------
6160 -- Check_Loop_Pragma_Placement --
6161 ---------------------------------
6162
6163 procedure Check_Loop_Pragma_Placement is
6164 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
6165 -- Verify whether the current pragma is properly grouped with other
6166 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
6167 -- related loop where the pragma appears.
6168
6169 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
6170 -- Determine whether an arbitrary statement Stmt denotes pragma
6171 -- Loop_Invariant or Loop_Variant.
6172
6173 procedure Placement_Error (Constr : Node_Id);
6174 pragma No_Return (Placement_Error);
6175 -- Node Constr denotes the last loop restricted construct before we
6176 -- encountered an illegal relation between enclosing constructs. Emit
6177 -- an error depending on what Constr was.
6178
6179 --------------------------------
6180 -- Check_Loop_Pragma_Grouping --
6181 --------------------------------
6182
6183 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
6184 function Check_Grouping (L : List_Id) return Boolean;
6185 -- Find the first group of pragmas in list L and if successful,
6186 -- ensure that the current pragma is part of that group. The
6187 -- routine returns True once such a check is performed to
6188 -- stop the analysis.
6189
6190 procedure Grouping_Error (Prag : Node_Id);
6191 pragma No_Return (Grouping_Error);
6192 -- Emit an error concerning the current pragma indicating that it
6193 -- should be placed after pragma Prag.
6194
6195 --------------------
6196 -- Check_Grouping --
6197 --------------------
6198
6199 function Check_Grouping (L : List_Id) return Boolean is
6200 HSS : Node_Id;
6201 Stmt : Node_Id;
6202 Prag : Node_Id := Empty; -- init to avoid warning
6203
6204 begin
6205 -- Inspect the list of declarations or statements looking for
6206 -- the first grouping of pragmas:
6207
6208 -- loop
6209 -- pragma Loop_Invariant ...;
6210 -- pragma Loop_Variant ...;
6211 -- . . . -- (1)
6212 -- pragma Loop_Variant ...; -- current pragma
6213
6214 -- If the current pragma is not in the grouping, then it must
6215 -- either appear in a different declarative or statement list
6216 -- or the construct at (1) is separating the pragma from the
6217 -- grouping.
6218
6219 Stmt := First (L);
6220 while Present (Stmt) loop
6221
6222 -- First pragma of the first topmost grouping has been found
6223
6224 if Is_Loop_Pragma (Stmt) then
6225
6226 -- The group and the current pragma are not in the same
6227 -- declarative or statement list.
6228
6229 if not In_Same_List (Stmt, N) then
6230 Grouping_Error (Stmt);
6231
6232 -- Try to reach the current pragma from the first pragma
6233 -- of the grouping while skipping other members:
6234
6235 -- pragma Loop_Invariant ...; -- first pragma
6236 -- pragma Loop_Variant ...; -- member
6237 -- . . .
6238 -- pragma Loop_Variant ...; -- current pragma
6239
6240 else
6241 while Present (Stmt) loop
6242 -- The current pragma is either the first pragma
6243 -- of the group or is a member of the group.
6244 -- Stop the search as the placement is legal.
6245
6246 if Stmt = N then
6247 return True;
6248
6249 -- Skip group members, but keep track of the
6250 -- last pragma in the group.
6251
6252 elsif Is_Loop_Pragma (Stmt) then
6253 Prag := Stmt;
6254
6255 -- Skip declarations and statements generated by
6256 -- the compiler during expansion. Note that some
6257 -- source statements (e.g. pragma Assert) may have
6258 -- been transformed so that they do not appear as
6259 -- coming from source anymore, so we instead look
6260 -- at their Original_Node.
6261
6262 elsif not Comes_From_Source (Original_Node (Stmt))
6263 then
6264 null;
6265
6266 -- A non-pragma is separating the group from the
6267 -- current pragma, the placement is illegal.
6268
6269 else
6270 Grouping_Error (Prag);
6271 end if;
6272
6273 Next (Stmt);
6274 end loop;
6275
6276 -- If the traversal did not reach the current pragma,
6277 -- then the list must be malformed.
6278
6279 raise Program_Error;
6280 end if;
6281
6282 -- Pragmas Loop_Invariant and Loop_Variant may only appear
6283 -- inside a loop or a block housed inside a loop. Inspect
6284 -- the declarations and statements of the block as they may
6285 -- contain the first grouping. This case follows the one for
6286 -- loop pragmas, as block statements which originate in a
6287 -- loop pragma (and so Is_Loop_Pragma will return True on
6288 -- that block statement) should be treated in the previous
6289 -- case.
6290
6291 elsif Nkind (Stmt) = N_Block_Statement then
6292 HSS := Handled_Statement_Sequence (Stmt);
6293
6294 if Check_Grouping (Declarations (Stmt)) then
6295 return True;
6296 end if;
6297
6298 if Present (HSS) then
6299 if Check_Grouping (Statements (HSS)) then
6300 return True;
6301 end if;
6302 end if;
6303 end if;
6304
6305 Next (Stmt);
6306 end loop;
6307
6308 return False;
6309 end Check_Grouping;
6310
6311 --------------------
6312 -- Grouping_Error --
6313 --------------------
6314
6315 procedure Grouping_Error (Prag : Node_Id) is
6316 begin
6317 Error_Msg_Sloc := Sloc (Prag);
6318 Error_Pragma ("pragma% must appear next to pragma#");
6319 end Grouping_Error;
6320
6321 Ignore : Boolean;
6322
6323 -- Start of processing for Check_Loop_Pragma_Grouping
6324
6325 begin
6326 -- Inspect the statements of the loop or nested blocks housed
6327 -- within to determine whether the current pragma is part of the
6328 -- first topmost grouping of Loop_Invariant and Loop_Variant.
6329
6330 Ignore := Check_Grouping (Statements (Loop_Stmt));
6331 end Check_Loop_Pragma_Grouping;
6332
6333 --------------------
6334 -- Is_Loop_Pragma --
6335 --------------------
6336
6337 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
6338 Original_Stmt : constant Node_Id := Original_Node (Stmt);
6339
6340 begin
6341 -- Inspect the original node as Loop_Invariant and Loop_Variant
6342 -- pragmas are rewritten to null when assertions are disabled.
6343
6344 return Nkind (Original_Stmt) = N_Pragma
6345 and then Pragma_Name_Unmapped (Original_Stmt)
6346 in Name_Loop_Invariant | Name_Loop_Variant;
6347 end Is_Loop_Pragma;
6348
6349 ---------------------
6350 -- Placement_Error --
6351 ---------------------
6352
6353 procedure Placement_Error (Constr : Node_Id) is
6354 LA : constant String := " with Loop_Entry";
6355
6356 begin
6357 if Prag_Id = Pragma_Assert then
6358 Error_Msg_String (1 .. LA'Length) := LA;
6359 Error_Msg_Strlen := LA'Length;
6360 else
6361 Error_Msg_Strlen := 0;
6362 end if;
6363
6364 if Nkind (Constr) = N_Pragma then
6365 Error_Pragma
6366 ("pragma %~ must appear immediately within the statements "
6367 & "of a loop");
6368 else
6369 Error_Pragma_Arg
6370 ("block containing pragma %~ must appear immediately within "
6371 & "the statements of a loop", Constr);
6372 end if;
6373 end Placement_Error;
6374
6375 -- Local declarations
6376
6377 Prev : Node_Id;
6378 Stmt : Node_Id;
6379
6380 -- Start of processing for Check_Loop_Pragma_Placement
6381
6382 begin
6383 -- Check that pragma appears immediately within a loop statement,
6384 -- ignoring intervening block statements.
6385
6386 Prev := N;
6387 Stmt := Parent (N);
6388 while Present (Stmt) loop
6389
6390 -- The pragma or previous block must appear immediately within the
6391 -- current block's declarative or statement part.
6392
6393 if Nkind (Stmt) = N_Block_Statement then
6394 if (No (Declarations (Stmt))
6395 or else List_Containing (Prev) /= Declarations (Stmt))
6396 and then
6397 List_Containing (Prev) /=
6398 Statements (Handled_Statement_Sequence (Stmt))
6399 then
6400 Placement_Error (Prev);
6401
6402 -- Keep inspecting the parents because we are now within a
6403 -- chain of nested blocks.
6404
6405 else
6406 Prev := Stmt;
6407 Stmt := Parent (Stmt);
6408 end if;
6409
6410 -- The pragma or previous block must appear immediately within the
6411 -- statements of the loop.
6412
6413 elsif Nkind (Stmt) = N_Loop_Statement then
6414 if List_Containing (Prev) /= Statements (Stmt) then
6415 Placement_Error (Prev);
6416 end if;
6417
6418 -- Stop the traversal because we reached the innermost loop
6419 -- regardless of whether we encountered an error or not.
6420
6421 exit;
6422
6423 -- Ignore a handled statement sequence. Note that this node may
6424 -- be related to a subprogram body in which case we will emit an
6425 -- error on the next iteration of the search.
6426
6427 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
6428 Stmt := Parent (Stmt);
6429
6430 -- Any other statement breaks the chain from the pragma to the
6431 -- loop.
6432
6433 else
6434 Placement_Error (Prev);
6435 end if;
6436 end loop;
6437
6438 -- Check that the current pragma Loop_Invariant or Loop_Variant is
6439 -- grouped together with other such pragmas.
6440
6441 if Is_Loop_Pragma (N) then
6442
6443 -- The previous check should have located the related loop
6444
6445 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
6446 Check_Loop_Pragma_Grouping (Stmt);
6447 end if;
6448 end Check_Loop_Pragma_Placement;
6449
6450 -------------------------------------------
6451 -- Check_Is_In_Decl_Part_Or_Package_Spec --
6452 -------------------------------------------
6453
6454 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
6455 P : Node_Id;
6456
6457 begin
6458 P := Parent (N);
6459 loop
6460 if No (P) then
6461 exit;
6462
6463 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
6464 exit;
6465
6466 elsif Nkind (P) in N_Package_Specification | N_Block_Statement then
6467 return;
6468
6469 -- Note: the following tests seem a little peculiar, because
6470 -- they test for bodies, but if we were in the statement part
6471 -- of the body, we would already have hit the handled statement
6472 -- sequence, so the only way we get here is by being in the
6473 -- declarative part of the body.
6474
6475 elsif Nkind (P) in
6476 N_Subprogram_Body | N_Package_Body | N_Task_Body | N_Entry_Body
6477 then
6478 return;
6479 end if;
6480
6481 P := Parent (P);
6482 end loop;
6483
6484 Error_Pragma ("pragma% is not in declarative part or package spec");
6485 end Check_Is_In_Decl_Part_Or_Package_Spec;
6486
6487 -------------------------
6488 -- Check_No_Identifier --
6489 -------------------------
6490
6491 procedure Check_No_Identifier (Arg : Node_Id) is
6492 begin
6493 if Nkind (Arg) = N_Pragma_Argument_Association
6494 and then Chars (Arg) /= No_Name
6495 then
6496 Error_Pragma_Arg_Ident
6497 ("pragma% does not permit identifier& here", Arg);
6498 end if;
6499 end Check_No_Identifier;
6500
6501 --------------------------
6502 -- Check_No_Identifiers --
6503 --------------------------
6504
6505 procedure Check_No_Identifiers is
6506 Arg_Node : Node_Id;
6507 begin
6508 Arg_Node := Arg1;
6509 for J in 1 .. Arg_Count loop
6510 Check_No_Identifier (Arg_Node);
6511 Next (Arg_Node);
6512 end loop;
6513 end Check_No_Identifiers;
6514
6515 ------------------------
6516 -- Check_No_Link_Name --
6517 ------------------------
6518
6519 procedure Check_No_Link_Name is
6520 begin
6521 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
6522 Arg4 := Arg3;
6523 end if;
6524
6525 if Present (Arg4) then
6526 Error_Pragma_Arg
6527 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
6528 end if;
6529 end Check_No_Link_Name;
6530
6531 -------------------------------
6532 -- Check_Optional_Identifier --
6533 -------------------------------
6534
6535 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
6536 begin
6537 if Present (Arg)
6538 and then Nkind (Arg) = N_Pragma_Argument_Association
6539 and then Chars (Arg) /= No_Name
6540 then
6541 if Chars (Arg) /= Id then
6542 Error_Msg_Name_1 := Pname;
6543 Error_Msg_Name_2 := Id;
6544 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6545 raise Pragma_Exit;
6546 end if;
6547 end if;
6548 end Check_Optional_Identifier;
6549
6550 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
6551 begin
6552 Check_Optional_Identifier (Arg, Name_Find (Id));
6553 end Check_Optional_Identifier;
6554
6555 -------------------------------------
6556 -- Check_Static_Boolean_Expression --
6557 -------------------------------------
6558
6559 procedure Check_Static_Boolean_Expression (Expr : Node_Id) is
6560 begin
6561 if Present (Expr) then
6562 Analyze_And_Resolve (Expr, Standard_Boolean);
6563
6564 if not Is_OK_Static_Expression (Expr) then
6565 Error_Pragma_Arg
6566 ("expression of pragma % must be static", Expr);
6567 end if;
6568 end if;
6569 end Check_Static_Boolean_Expression;
6570
6571 -----------------------------
6572 -- Check_Static_Constraint --
6573 -----------------------------
6574
6575 procedure Check_Static_Constraint (Constr : Node_Id) is
6576
6577 procedure Require_Static (E : Node_Id);
6578 -- Require given expression to be static expression
6579
6580 --------------------
6581 -- Require_Static --
6582 --------------------
6583
6584 procedure Require_Static (E : Node_Id) is
6585 begin
6586 if not Is_OK_Static_Expression (E) then
6587 Flag_Non_Static_Expr
6588 ("non-static constraint not allowed in Unchecked_Union!", E);
6589 raise Pragma_Exit;
6590 end if;
6591 end Require_Static;
6592
6593 -- Start of processing for Check_Static_Constraint
6594
6595 begin
6596 case Nkind (Constr) is
6597 when N_Discriminant_Association =>
6598 Require_Static (Expression (Constr));
6599
6600 when N_Range =>
6601 Require_Static (Low_Bound (Constr));
6602 Require_Static (High_Bound (Constr));
6603
6604 when N_Attribute_Reference =>
6605 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
6606 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
6607
6608 when N_Range_Constraint =>
6609 Check_Static_Constraint (Range_Expression (Constr));
6610
6611 when N_Index_Or_Discriminant_Constraint =>
6612 declare
6613 IDC : Entity_Id;
6614 begin
6615 IDC := First (Constraints (Constr));
6616 while Present (IDC) loop
6617 Check_Static_Constraint (IDC);
6618 Next (IDC);
6619 end loop;
6620 end;
6621
6622 when others =>
6623 null;
6624 end case;
6625 end Check_Static_Constraint;
6626
6627 --------------------------------------
6628 -- Check_Valid_Configuration_Pragma --
6629 --------------------------------------
6630
6631 -- A configuration pragma must appear in the context clause of a
6632 -- compilation unit, and only other pragmas may precede it. Note that
6633 -- the test also allows use in a configuration pragma file.
6634
6635 procedure Check_Valid_Configuration_Pragma is
6636 begin
6637 if not Is_Configuration_Pragma then
6638 Error_Pragma ("incorrect placement for configuration pragma%");
6639 end if;
6640 end Check_Valid_Configuration_Pragma;
6641
6642 -------------------------------------
6643 -- Check_Valid_Library_Unit_Pragma --
6644 -------------------------------------
6645
6646 procedure Check_Valid_Library_Unit_Pragma is
6647 Plist : List_Id;
6648 Parent_Node : Node_Id;
6649 Unit_Name : Entity_Id;
6650 Unit_Kind : Node_Kind;
6651 Unit_Node : Node_Id;
6652 Sindex : Source_File_Index;
6653
6654 begin
6655 if not Is_List_Member (N) then
6656 Pragma_Misplaced;
6657
6658 else
6659 Plist := List_Containing (N);
6660 Parent_Node := Parent (Plist);
6661
6662 if Parent_Node = Empty then
6663 Pragma_Misplaced;
6664
6665 -- Case of pragma appearing after a compilation unit. In this case
6666 -- it must have an argument with the corresponding name and must
6667 -- be part of the following pragmas of its parent.
6668
6669 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
6670 if Plist /= Pragmas_After (Parent_Node) then
6671 Error_Pragma
6672 ("pragma% misplaced, must be inside or after the "
6673 & "compilation unit");
6674
6675 elsif Arg_Count = 0 then
6676 Error_Pragma
6677 ("argument required if outside compilation unit");
6678
6679 else
6680 Check_No_Identifiers;
6681 Check_Arg_Count (1);
6682 Unit_Node := Unit (Parent (Parent_Node));
6683 Unit_Kind := Nkind (Unit_Node);
6684
6685 Analyze (Get_Pragma_Arg (Arg1));
6686
6687 if Unit_Kind = N_Generic_Subprogram_Declaration
6688 or else Unit_Kind = N_Subprogram_Declaration
6689 then
6690 Unit_Name := Defining_Entity (Unit_Node);
6691
6692 elsif Unit_Kind in N_Generic_Instantiation then
6693 Unit_Name := Defining_Entity (Unit_Node);
6694
6695 else
6696 Unit_Name := Cunit_Entity (Current_Sem_Unit);
6697 end if;
6698
6699 if Chars (Unit_Name) /=
6700 Chars (Entity (Get_Pragma_Arg (Arg1)))
6701 then
6702 Error_Pragma_Arg
6703 ("pragma% argument is not current unit name", Arg1);
6704 end if;
6705
6706 if Ekind (Unit_Name) = E_Package
6707 and then Present (Renamed_Entity (Unit_Name))
6708 then
6709 Error_Pragma ("pragma% not allowed for renamed package");
6710 end if;
6711 end if;
6712
6713 -- Pragma appears other than after a compilation unit
6714
6715 else
6716 -- Here we check for the generic instantiation case and also
6717 -- for the case of processing a generic formal package. We
6718 -- detect these cases by noting that the Sloc on the node
6719 -- does not belong to the current compilation unit.
6720
6721 Sindex := Source_Index (Current_Sem_Unit);
6722
6723 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
6724 -- We do not want to raise an exception here since this code
6725 -- is part of the bootstrap path where we cannot rely on
6726 -- exception propagation working.
6727 -- Instead the caller should check for N being rewritten as
6728 -- a null statement.
6729 -- This code triggers when compiling a-except.adb.
6730
6731 Rewrite (N, Make_Null_Statement (Loc));
6732
6733 -- If before first declaration, the pragma applies to the
6734 -- enclosing unit, and the name if present must be this name.
6735
6736 elsif Is_Before_First_Decl (N, Plist) then
6737 Unit_Node := Unit_Declaration_Node (Current_Scope);
6738 Unit_Kind := Nkind (Unit_Node);
6739
6740 if Unit_Node = Standard_Package_Node then
6741 Error_Pragma
6742 ("pragma% misplaced, must be inside or after the "
6743 & "compilation unit");
6744
6745 elsif Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
6746 Error_Pragma
6747 ("pragma% misplaced, must be on library unit");
6748
6749 elsif Unit_Kind = N_Subprogram_Body
6750 and then not Acts_As_Spec (Unit_Node)
6751 then
6752 Error_Pragma
6753 ("pragma% misplaced, must be on the subprogram spec");
6754
6755 elsif Nkind (Parent_Node) = N_Package_Body then
6756 Error_Pragma
6757 ("pragma% misplaced, must be on the package spec");
6758
6759 elsif Nkind (Parent_Node) = N_Package_Specification
6760 and then Plist = Private_Declarations (Parent_Node)
6761 then
6762 Error_Pragma
6763 ("pragma% misplaced, must be in the public part");
6764
6765 elsif Nkind (Parent_Node) in N_Generic_Declaration
6766 and then Plist = Generic_Formal_Declarations (Parent_Node)
6767 then
6768 Error_Pragma
6769 ("pragma% misplaced, must not be in formal part");
6770
6771 elsif Arg_Count > 0 then
6772 Analyze (Get_Pragma_Arg (Arg1));
6773
6774 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
6775 Error_Pragma_Arg
6776 ("name in pragma% must be enclosing unit", Arg1);
6777 end if;
6778
6779 -- It is legal to have no argument in this context
6780
6781 else
6782 return;
6783 end if;
6784
6785 -- Error if not before first declaration. This is because a
6786 -- library unit pragma argument must be the name of a library
6787 -- unit (RM 10.1.5(7)), but the only names permitted in this
6788 -- context are (RM 10.1.5(6)) names of subprogram declarations,
6789 -- generic subprogram declarations or generic instantiations.
6790
6791 else
6792 Error_Pragma
6793 ("pragma% misplaced, must be before first declaration");
6794 end if;
6795 end if;
6796 end if;
6797 end Check_Valid_Library_Unit_Pragma;
6798
6799 -------------------
6800 -- Check_Variant --
6801 -------------------
6802
6803 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
6804 Clist : constant Node_Id := Component_List (Variant);
6805 Comp : Node_Id;
6806
6807 begin
6808 Comp := First_Non_Pragma (Component_Items (Clist));
6809 while Present (Comp) loop
6810 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
6811 Next_Non_Pragma (Comp);
6812 end loop;
6813 end Check_Variant;
6814
6815 ---------------------------
6816 -- Ensure_Aggregate_Form --
6817 ---------------------------
6818
6819 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
6820 CFSD : constant Boolean := Get_Comes_From_Source_Default;
6821 Expr : constant Node_Id := Expression (Arg);
6822 Loc : constant Source_Ptr := Sloc (Expr);
6823 Comps : List_Id := No_List;
6824 Exprs : List_Id := No_List;
6825 Nam : Name_Id := No_Name;
6826 Nam_Loc : Source_Ptr;
6827
6828 begin
6829 -- The pragma argument is in positional form:
6830
6831 -- pragma Depends (Nam => ...)
6832 -- ^
6833 -- Chars field
6834
6835 -- Note that the Sloc of the Chars field is the Sloc of the pragma
6836 -- argument association.
6837
6838 if Nkind (Arg) = N_Pragma_Argument_Association then
6839 Nam := Chars (Arg);
6840 Nam_Loc := Sloc (Arg);
6841
6842 -- Remove the pragma argument name as this will be captured in the
6843 -- aggregate.
6844
6845 Set_Chars (Arg, No_Name);
6846 end if;
6847
6848 -- The argument is already in aggregate form, but the presence of a
6849 -- name causes this to be interpreted as named association which in
6850 -- turn must be converted into an aggregate.
6851
6852 -- pragma Global (In_Out => (A, B, C))
6853 -- ^ ^
6854 -- name aggregate
6855
6856 -- pragma Global ((In_Out => (A, B, C)))
6857 -- ^ ^
6858 -- aggregate aggregate
6859
6860 if Nkind (Expr) = N_Aggregate then
6861 if Nam = No_Name then
6862 return;
6863 end if;
6864
6865 -- Do not transform a null argument into an aggregate as N_Null has
6866 -- special meaning in formal verification pragmas.
6867
6868 elsif Nkind (Expr) = N_Null then
6869 return;
6870 end if;
6871
6872 -- Everything comes from source if the original comes from source
6873
6874 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
6875
6876 -- Positional argument is transformed into an aggregate with an
6877 -- Expressions list.
6878
6879 if Nam = No_Name then
6880 Exprs := New_List (Relocate_Node (Expr));
6881
6882 -- An associative argument is transformed into an aggregate with
6883 -- Component_Associations.
6884
6885 else
6886 Comps := New_List (
6887 Make_Component_Association (Loc,
6888 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
6889 Expression => Relocate_Node (Expr)));
6890 end if;
6891
6892 Set_Expression (Arg,
6893 Make_Aggregate (Loc,
6894 Component_Associations => Comps,
6895 Expressions => Exprs));
6896
6897 -- Restore Comes_From_Source default
6898
6899 Set_Comes_From_Source_Default (CFSD);
6900 end Ensure_Aggregate_Form;
6901
6902 ------------------
6903 -- Error_Pragma --
6904 ------------------
6905
6906 procedure Error_Pragma (Msg : String) is
6907 begin
6908 Error_Msg_Name_1 := Pname;
6909 Error_Msg_N (Fix_Error (Msg), N);
6910 raise Pragma_Exit;
6911 end Error_Pragma;
6912
6913 ----------------------
6914 -- Error_Pragma_Arg --
6915 ----------------------
6916
6917 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
6918 begin
6919 Error_Msg_Name_1 := Pname;
6920 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
6921 raise Pragma_Exit;
6922 end Error_Pragma_Arg;
6923
6924 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
6925 begin
6926 Error_Msg_Name_1 := Pname;
6927 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
6928 Error_Pragma_Arg (Msg2, Arg);
6929 end Error_Pragma_Arg;
6930
6931 ----------------------------
6932 -- Error_Pragma_Arg_Ident --
6933 ----------------------------
6934
6935 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
6936 begin
6937 Error_Msg_Name_1 := Pname;
6938 Error_Msg_N (Fix_Error (Msg), Arg);
6939 raise Pragma_Exit;
6940 end Error_Pragma_Arg_Ident;
6941
6942 ----------------------
6943 -- Error_Pragma_Ref --
6944 ----------------------
6945
6946 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
6947 begin
6948 Error_Msg_Name_1 := Pname;
6949 Error_Msg_Sloc := Sloc (Ref);
6950 Error_Msg_NE (Fix_Error (Msg), N, Ref);
6951 raise Pragma_Exit;
6952 end Error_Pragma_Ref;
6953
6954 ------------------------
6955 -- Find_Lib_Unit_Name --
6956 ------------------------
6957
6958 function Find_Lib_Unit_Name return Entity_Id is
6959 begin
6960 -- Return inner compilation unit entity, for case of nested
6961 -- categorization pragmas. This happens in generic unit.
6962
6963 if Nkind (Parent (N)) = N_Package_Specification
6964 and then Defining_Entity (Parent (N)) /= Current_Scope
6965 then
6966 return Defining_Entity (Parent (N));
6967 else
6968 return Current_Scope;
6969 end if;
6970 end Find_Lib_Unit_Name;
6971
6972 ----------------------------
6973 -- Find_Program_Unit_Name --
6974 ----------------------------
6975
6976 procedure Find_Program_Unit_Name (Id : Node_Id) is
6977 Unit_Name : Entity_Id;
6978 Unit_Kind : Node_Kind;
6979 P : constant Node_Id := Parent (N);
6980
6981 begin
6982 if Nkind (P) = N_Compilation_Unit then
6983 Unit_Kind := Nkind (Unit (P));
6984
6985 if Unit_Kind in N_Subprogram_Declaration
6986 | N_Package_Declaration
6987 | N_Generic_Declaration
6988 then
6989 Unit_Name := Defining_Entity (Unit (P));
6990
6991 if Chars (Id) = Chars (Unit_Name) then
6992 Set_Entity (Id, Unit_Name);
6993 Set_Etype (Id, Etype (Unit_Name));
6994 else
6995 Set_Etype (Id, Any_Type);
6996 Error_Pragma
6997 ("cannot find program unit referenced by pragma%");
6998 end if;
6999
7000 else
7001 Set_Etype (Id, Any_Type);
7002 Error_Pragma ("pragma% inapplicable to this unit");
7003 end if;
7004
7005 else
7006 Analyze (Id);
7007 end if;
7008 end Find_Program_Unit_Name;
7009
7010 -----------------------------------------
7011 -- Find_Unique_Parameterless_Procedure --
7012 -----------------------------------------
7013
7014 function Find_Unique_Parameterless_Procedure
7015 (Name : Entity_Id;
7016 Arg : Node_Id) return Entity_Id
7017 is
7018 Proc : Entity_Id := Empty;
7019
7020 begin
7021 -- Perform sanity checks on Name
7022
7023 if not Is_Entity_Name (Name) then
7024 Error_Pragma_Arg
7025 ("argument of pragma% must be entity name", Arg);
7026
7027 elsif not Is_Overloaded (Name) then
7028 Proc := Entity (Name);
7029
7030 if Ekind (Proc) /= E_Procedure
7031 or else Present (First_Formal (Proc))
7032 then
7033 Error_Pragma_Arg
7034 ("argument of pragma% must be parameterless procedure", Arg);
7035 end if;
7036
7037 -- Otherwise, search through interpretations looking for one which
7038 -- has no parameters.
7039
7040 else
7041 declare
7042 Found : Boolean := False;
7043 It : Interp;
7044 Index : Interp_Index;
7045
7046 begin
7047 Get_First_Interp (Name, Index, It);
7048 while Present (It.Nam) loop
7049 Proc := It.Nam;
7050
7051 if Ekind (Proc) = E_Procedure
7052 and then No (First_Formal (Proc))
7053 then
7054 -- We found an interpretation, note it and continue
7055 -- looking looking to verify it is unique.
7056
7057 if not Found then
7058 Found := True;
7059 Set_Entity (Name, Proc);
7060 Set_Is_Overloaded (Name, False);
7061
7062 -- Two procedures with the same name, log an error
7063 -- since the name is ambiguous.
7064
7065 else
7066 Error_Pragma_Arg
7067 ("ambiguous handler name for pragma%", Arg);
7068 end if;
7069 end if;
7070
7071 Get_Next_Interp (Index, It);
7072 end loop;
7073
7074 if not Found then
7075 -- Issue an error if we haven't found a suitable match for
7076 -- Name.
7077
7078 Error_Pragma_Arg
7079 ("argument of pragma% must be parameterless procedure",
7080 Arg);
7081
7082 else
7083 Proc := Entity (Name);
7084 end if;
7085 end;
7086 end if;
7087
7088 return Proc;
7089 end Find_Unique_Parameterless_Procedure;
7090
7091 ---------------
7092 -- Fix_Error --
7093 ---------------
7094
7095 function Fix_Error (Msg : String) return String is
7096 Res : String (Msg'Range) := Msg;
7097 Res_Last : Natural := Msg'Last;
7098 J : Natural;
7099
7100 begin
7101 -- If we have a rewriting of another pragma, go to that pragma
7102
7103 if Is_Rewrite_Substitution (N)
7104 and then Nkind (Original_Node (N)) = N_Pragma
7105 then
7106 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
7107 end if;
7108
7109 -- Case where pragma comes from an aspect specification
7110
7111 if From_Aspect_Specification (N) then
7112
7113 -- Change appearance of "pragma" in message to "aspect"
7114
7115 J := Res'First;
7116 while J <= Res_Last - 5 loop
7117 if Res (J .. J + 5) = "pragma" then
7118 Res (J .. J + 5) := "aspect";
7119 J := J + 6;
7120
7121 else
7122 J := J + 1;
7123 end if;
7124 end loop;
7125
7126 -- Change "argument of" at start of message to "entity for"
7127
7128 if Res'Length > 11
7129 and then Res (Res'First .. Res'First + 10) = "argument of"
7130 then
7131 Res (Res'First .. Res'First + 9) := "entity for";
7132 Res (Res'First + 10 .. Res_Last - 1) :=
7133 Res (Res'First + 11 .. Res_Last);
7134 Res_Last := Res_Last - 1;
7135 end if;
7136
7137 -- Change "argument" at start of message to "entity"
7138
7139 if Res'Length > 8
7140 and then Res (Res'First .. Res'First + 7) = "argument"
7141 then
7142 Res (Res'First .. Res'First + 5) := "entity";
7143 Res (Res'First + 6 .. Res_Last - 2) :=
7144 Res (Res'First + 8 .. Res_Last);
7145 Res_Last := Res_Last - 2;
7146 end if;
7147
7148 -- Get name from corresponding aspect
7149
7150 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
7151 end if;
7152
7153 -- Return possibly modified message
7154
7155 return Res (Res'First .. Res_Last);
7156 end Fix_Error;
7157
7158 -------------------------
7159 -- Gather_Associations --
7160 -------------------------
7161
7162 procedure Gather_Associations
7163 (Names : Name_List;
7164 Args : out Args_List)
7165 is
7166 Arg : Node_Id;
7167
7168 begin
7169 -- Initialize all parameters to Empty
7170
7171 for J in Args'Range loop
7172 Args (J) := Empty;
7173 end loop;
7174
7175 -- That's all we have to do if there are no argument associations
7176
7177 if No (Pragma_Argument_Associations (N)) then
7178 return;
7179 end if;
7180
7181 -- Otherwise first deal with any positional parameters present
7182
7183 Arg := First (Pragma_Argument_Associations (N));
7184 for Index in Args'Range loop
7185 exit when No (Arg) or else Chars (Arg) /= No_Name;
7186 Args (Index) := Get_Pragma_Arg (Arg);
7187 Next (Arg);
7188 end loop;
7189
7190 -- Positional parameters all processed, if any left, then we
7191 -- have too many positional parameters.
7192
7193 if Present (Arg) and then Chars (Arg) = No_Name then
7194 Error_Pragma_Arg
7195 ("too many positional associations for pragma%", Arg);
7196 end if;
7197
7198 -- Process named parameters if any are present
7199
7200 while Present (Arg) loop
7201 if Chars (Arg) = No_Name then
7202 Error_Pragma_Arg
7203 ("positional association cannot follow named association",
7204 Arg);
7205
7206 else
7207 for Index in Names'Range loop
7208 if Names (Index) = Chars (Arg) then
7209 if Present (Args (Index)) then
7210 Error_Pragma_Arg
7211 ("duplicate argument association for pragma%", Arg);
7212 else
7213 Args (Index) := Get_Pragma_Arg (Arg);
7214 exit;
7215 end if;
7216 end if;
7217
7218 if Index = Names'Last then
7219 Error_Msg_Name_1 := Pname;
7220 Error_Msg_N ("pragma% does not allow & argument", Arg);
7221
7222 -- Check for possible misspelling
7223
7224 for Index1 in Names'Range loop
7225 if Is_Bad_Spelling_Of
7226 (Chars (Arg), Names (Index1))
7227 then
7228 Error_Msg_Name_1 := Names (Index1);
7229 Error_Msg_N -- CODEFIX
7230 ("\possible misspelling of%", Arg);
7231 exit;
7232 end if;
7233 end loop;
7234
7235 raise Pragma_Exit;
7236 end if;
7237 end loop;
7238 end if;
7239
7240 Next (Arg);
7241 end loop;
7242 end Gather_Associations;
7243
7244 -----------------
7245 -- GNAT_Pragma --
7246 -----------------
7247
7248 procedure GNAT_Pragma is
7249 begin
7250 -- We need to check the No_Implementation_Pragmas restriction for
7251 -- the case of a pragma from source. Note that the case of aspects
7252 -- generating corresponding pragmas marks these pragmas as not being
7253 -- from source, so this test also catches that case.
7254
7255 if Comes_From_Source (N) then
7256 Check_Restriction (No_Implementation_Pragmas, N);
7257 end if;
7258 end GNAT_Pragma;
7259
7260 --------------------------
7261 -- Is_Before_First_Decl --
7262 --------------------------
7263
7264 function Is_Before_First_Decl
7265 (Pragma_Node : Node_Id;
7266 Decls : List_Id) return Boolean
7267 is
7268 Item : Node_Id := First (Decls);
7269
7270 begin
7271 -- Only other pragmas can come before this pragma, but they might
7272 -- have been rewritten so check the original node.
7273
7274 loop
7275 if No (Item) or else Nkind (Original_Node (Item)) /= N_Pragma then
7276 return False;
7277
7278 elsif Item = Pragma_Node then
7279 return True;
7280 end if;
7281
7282 Next (Item);
7283 end loop;
7284 end Is_Before_First_Decl;
7285
7286 -----------------------------
7287 -- Is_Configuration_Pragma --
7288 -----------------------------
7289
7290 -- A configuration pragma must appear in the context clause of a
7291 -- compilation unit, and only other pragmas may precede it. Note that
7292 -- the test below also permits use in a configuration pragma file.
7293
7294 function Is_Configuration_Pragma return Boolean is
7295 Lis : constant List_Id := List_Containing (N);
7296 Par : constant Node_Id := Parent (N);
7297 Prg : Node_Id;
7298
7299 begin
7300 -- If no parent, then we are in the configuration pragma file,
7301 -- so the placement is definitely appropriate.
7302
7303 if No (Par) then
7304 return True;
7305
7306 -- Otherwise we must be in the context clause of a compilation unit
7307 -- and the only thing allowed before us in the context list is more
7308 -- configuration pragmas.
7309
7310 elsif Nkind (Par) = N_Compilation_Unit
7311 and then Context_Items (Par) = Lis
7312 then
7313 Prg := First (Lis);
7314
7315 loop
7316 if Prg = N then
7317 return True;
7318 elsif Nkind (Prg) /= N_Pragma then
7319 return False;
7320 end if;
7321
7322 Next (Prg);
7323 end loop;
7324
7325 else
7326 return False;
7327 end if;
7328 end Is_Configuration_Pragma;
7329
7330 --------------------------
7331 -- Is_In_Context_Clause --
7332 --------------------------
7333
7334 function Is_In_Context_Clause return Boolean is
7335 Plist : List_Id;
7336 Parent_Node : Node_Id;
7337
7338 begin
7339 if Is_List_Member (N) then
7340 Plist := List_Containing (N);
7341 Parent_Node := Parent (Plist);
7342
7343 return Present (Parent_Node)
7344 and then Nkind (Parent_Node) = N_Compilation_Unit
7345 and then Context_Items (Parent_Node) = Plist;
7346 end if;
7347
7348 return False;
7349 end Is_In_Context_Clause;
7350
7351 ---------------------------------
7352 -- Is_Static_String_Expression --
7353 ---------------------------------
7354
7355 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
7356 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
7357 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
7358
7359 begin
7360 Analyze_And_Resolve (Argx);
7361
7362 -- Special case Ada 83, where the expression will never be static,
7363 -- but we will return true if we had a string literal to start with.
7364
7365 if Ada_Version = Ada_83 then
7366 return Lit;
7367
7368 -- Normal case, true only if we end up with a string literal that
7369 -- is marked as being the result of evaluating a static expression.
7370
7371 else
7372 return Is_OK_Static_Expression (Argx)
7373 and then Nkind (Argx) = N_String_Literal;
7374 end if;
7375
7376 end Is_Static_String_Expression;
7377
7378 ----------------------
7379 -- Pragma_Misplaced --
7380 ----------------------
7381
7382 procedure Pragma_Misplaced is
7383 begin
7384 Error_Pragma ("incorrect placement of pragma%");
7385 end Pragma_Misplaced;
7386
7387 ------------------------------------------------
7388 -- Process_Atomic_Independent_Shared_Volatile --
7389 ------------------------------------------------
7390
7391 procedure Process_Atomic_Independent_Shared_Volatile is
7392 procedure Check_Full_Access_Only (Ent : Entity_Id);
7393 -- Apply legality checks to type or object Ent subject to the
7394 -- Full_Access_Only aspect in Ada 2022 (RM C.6(8.2)).
7395
7396 procedure Mark_Component_Or_Object (Ent : Entity_Id);
7397 -- Appropriately set flags on the given entity, either an array or
7398 -- record component, or an object declaration) according to the
7399 -- current pragma.
7400
7401 procedure Mark_Type (Ent : Entity_Id);
7402 -- Appropriately set flags on the given entity, a type
7403
7404 procedure Set_Atomic_VFA (Ent : Entity_Id);
7405 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
7406 -- no explicit alignment was given, set alignment to unknown, since
7407 -- back end knows what the alignment requirements are for atomic and
7408 -- full access arrays. Note: this is necessary for derived types.
7409
7410 -------------------------
7411 -- Check_Full_Access_Only --
7412 -------------------------
7413
7414 procedure Check_Full_Access_Only (Ent : Entity_Id) is
7415 Typ : Entity_Id;
7416
7417 Full_Access_Subcomponent : exception;
7418 -- Exception raised if a full access subcomponent is found
7419
7420 Generic_Type_Subcomponent : exception;
7421 -- Exception raised if a subcomponent with generic type is found
7422
7423 procedure Check_Subcomponents (Typ : Entity_Id);
7424 -- Apply checks to subcomponents recursively
7425
7426 -------------------------
7427 -- Check_Subcomponents --
7428 -------------------------
7429
7430 procedure Check_Subcomponents (Typ : Entity_Id) is
7431 Comp : Entity_Id;
7432
7433 begin
7434 if Is_Array_Type (Typ) then
7435 Comp := Component_Type (Typ);
7436
7437 if Has_Atomic_Components (Typ)
7438 or else Is_Full_Access (Comp)
7439 then
7440 raise Full_Access_Subcomponent;
7441
7442 elsif Is_Generic_Type (Comp) then
7443 raise Generic_Type_Subcomponent;
7444 end if;
7445
7446 -- Recurse on the component type
7447
7448 Check_Subcomponents (Comp);
7449
7450 elsif Is_Record_Type (Typ) then
7451 Comp := First_Component_Or_Discriminant (Typ);
7452 while Present (Comp) loop
7453
7454 if Is_Full_Access (Comp)
7455 or else Is_Full_Access (Etype (Comp))
7456 then
7457 raise Full_Access_Subcomponent;
7458
7459 elsif Is_Generic_Type (Etype (Comp)) then
7460 raise Generic_Type_Subcomponent;
7461 end if;
7462
7463 -- Recurse on the component type
7464
7465 Check_Subcomponents (Etype (Comp));
7466
7467 Next_Component_Or_Discriminant (Comp);
7468 end loop;
7469 end if;
7470 end Check_Subcomponents;
7471
7472 -- Start of processing for Check_Full_Access_Only
7473
7474 begin
7475 -- Fetch the type in case we are dealing with an object or
7476 -- component.
7477
7478 if Is_Type (Ent) then
7479 Typ := Ent;
7480 else
7481 pragma Assert (Is_Object (Ent)
7482 or else
7483 Nkind (Declaration_Node (Ent)) = N_Component_Declaration);
7484
7485 Typ := Etype (Ent);
7486 end if;
7487
7488 if not Is_Volatile (Ent) and then not Is_Volatile (Typ) then
7489 Error_Pragma
7490 ("cannot have Full_Access_Only without Volatile/Atomic "
7491 & "(RM C.6(8.2))");
7492 end if;
7493
7494 -- Check all the subcomponents of the type recursively, if any
7495
7496 Check_Subcomponents (Typ);
7497
7498 exception
7499 when Full_Access_Subcomponent =>
7500 Error_Pragma
7501 ("cannot have Full_Access_Only with full access subcomponent "
7502 & "(RM C.6(8.2))");
7503
7504 when Generic_Type_Subcomponent =>
7505 Error_Pragma
7506 ("cannot have Full_Access_Only with subcomponent of generic "
7507 & "type (RM C.6(8.2))");
7508
7509 end Check_Full_Access_Only;
7510
7511 ------------------------------
7512 -- Mark_Component_Or_Object --
7513 ------------------------------
7514
7515 procedure Mark_Component_Or_Object (Ent : Entity_Id) is
7516 begin
7517 if Prag_Id = Pragma_Atomic
7518 or else Prag_Id = Pragma_Shared
7519 or else Prag_Id = Pragma_Volatile_Full_Access
7520 then
7521 if Prag_Id = Pragma_Volatile_Full_Access then
7522 Set_Is_Volatile_Full_Access (Ent);
7523 else
7524 Set_Is_Atomic (Ent);
7525 end if;
7526
7527 -- If the object declaration has an explicit initialization, a
7528 -- temporary may have to be created to hold the expression, to
7529 -- ensure that access to the object remains atomic.
7530
7531 if Nkind (Parent (Ent)) = N_Object_Declaration
7532 and then Present (Expression (Parent (Ent)))
7533 then
7534 Set_Has_Delayed_Freeze (Ent);
7535 end if;
7536 end if;
7537
7538 -- Atomic/Shared/Volatile_Full_Access imply Independent
7539
7540 if Prag_Id /= Pragma_Volatile then
7541 Set_Is_Independent (Ent);
7542
7543 if Prag_Id = Pragma_Independent then
7544 Record_Independence_Check (N, Ent);
7545 end if;
7546 end if;
7547
7548 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7549
7550 if Prag_Id /= Pragma_Independent then
7551 Set_Is_Volatile (Ent);
7552 Set_Treat_As_Volatile (Ent);
7553 end if;
7554 end Mark_Component_Or_Object;
7555
7556 ---------------
7557 -- Mark_Type --
7558 ---------------
7559
7560 procedure Mark_Type (Ent : Entity_Id) is
7561 begin
7562 -- Attribute belongs on the base type. If the view of the type is
7563 -- currently private, it also belongs on the underlying type.
7564
7565 -- In Ada 2022, the pragma can apply to a formal type, for which
7566 -- there may be no underlying type.
7567
7568 if Prag_Id = Pragma_Atomic
7569 or else Prag_Id = Pragma_Shared
7570 or else Prag_Id = Pragma_Volatile_Full_Access
7571 then
7572 Set_Atomic_VFA (Ent);
7573 Set_Atomic_VFA (Base_Type (Ent));
7574
7575 if not Is_Generic_Type (Ent) then
7576 Set_Atomic_VFA (Underlying_Type (Ent));
7577 end if;
7578 end if;
7579
7580 -- Atomic/Shared/Volatile_Full_Access imply Independent
7581
7582 if Prag_Id /= Pragma_Volatile then
7583 Set_Is_Independent (Ent);
7584 Set_Is_Independent (Base_Type (Ent));
7585
7586 if not Is_Generic_Type (Ent) then
7587 Set_Is_Independent (Underlying_Type (Ent));
7588
7589 if Prag_Id = Pragma_Independent then
7590 Record_Independence_Check (N, Base_Type (Ent));
7591 end if;
7592 end if;
7593 end if;
7594
7595 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7596
7597 if Prag_Id /= Pragma_Independent then
7598 Set_Is_Volatile (Ent);
7599 Set_Is_Volatile (Base_Type (Ent));
7600
7601 if not Is_Generic_Type (Ent) then
7602 Set_Is_Volatile (Underlying_Type (Ent));
7603 Set_Treat_As_Volatile (Underlying_Type (Ent));
7604 end if;
7605
7606 Set_Treat_As_Volatile (Ent);
7607 end if;
7608
7609 -- Apply Volatile to the composite type's individual components,
7610 -- (RM C.6(8/3)).
7611
7612 if Prag_Id = Pragma_Volatile
7613 and then Is_Record_Type (Etype (Ent))
7614 then
7615 declare
7616 Comp : Entity_Id;
7617 begin
7618 Comp := First_Component (Ent);
7619 while Present (Comp) loop
7620 Mark_Component_Or_Object (Comp);
7621
7622 Next_Component (Comp);
7623 end loop;
7624 end;
7625 end if;
7626 end Mark_Type;
7627
7628 --------------------
7629 -- Set_Atomic_VFA --
7630 --------------------
7631
7632 procedure Set_Atomic_VFA (Ent : Entity_Id) is
7633 begin
7634 if Prag_Id = Pragma_Volatile_Full_Access then
7635 Set_Is_Volatile_Full_Access (Ent);
7636 else
7637 Set_Is_Atomic (Ent);
7638 end if;
7639
7640 if not Has_Alignment_Clause (Ent) then
7641 Reinit_Alignment (Ent);
7642 end if;
7643 end Set_Atomic_VFA;
7644
7645 -- Local variables
7646
7647 Decl : Node_Id;
7648 E : Entity_Id;
7649 E_Arg : Node_Id;
7650
7651 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
7652
7653 begin
7654 Check_Ada_83_Warning;
7655 Check_No_Identifiers;
7656 Check_Arg_Count (1);
7657 Check_Arg_Is_Local_Name (Arg1);
7658 E_Arg := Get_Pragma_Arg (Arg1);
7659
7660 if Etype (E_Arg) = Any_Type then
7661 return;
7662 end if;
7663
7664 E := Entity (E_Arg);
7665 Decl := Declaration_Node (E);
7666
7667 -- A pragma that applies to a Ghost entity becomes Ghost for the
7668 -- purposes of legality checks and removal of ignored Ghost code.
7669
7670 Mark_Ghost_Pragma (N, E);
7671
7672 -- Check duplicate before we chain ourselves
7673
7674 Check_Duplicate_Pragma (E);
7675
7676 -- Check the constraints of Full_Access_Only in Ada 2022. Note that
7677 -- they do not apply to GNAT's Volatile_Full_Access because 1) this
7678 -- aspect subsumes the Volatile aspect and 2) nesting is supported
7679 -- for this aspect and the outermost enclosing VFA object prevails.
7680
7681 -- Note also that we used to forbid specifying both Atomic and VFA on
7682 -- the same type or object, but the restriction has been lifted in
7683 -- light of the semantics of Full_Access_Only and Atomic in Ada 2022.
7684
7685 if Prag_Id = Pragma_Volatile_Full_Access
7686 and then From_Aspect_Specification (N)
7687 and then
7688 Get_Aspect_Id (Corresponding_Aspect (N)) = Aspect_Full_Access_Only
7689 then
7690 Check_Full_Access_Only (E);
7691 end if;
7692
7693 -- The following check is only relevant when SPARK_Mode is on as
7694 -- this is not a standard Ada legality rule. Pragma Volatile can
7695 -- only apply to a full type declaration or an object declaration
7696 -- (SPARK RM 7.1.3(2)). Original_Node is necessary to account for
7697 -- untagged derived types that are rewritten as subtypes of their
7698 -- respective root types.
7699
7700 if SPARK_Mode = On
7701 and then Prag_Id = Pragma_Volatile
7702 and then Nkind (Original_Node (Decl)) not in
7703 N_Full_Type_Declaration |
7704 N_Formal_Type_Declaration |
7705 N_Object_Declaration |
7706 N_Single_Protected_Declaration |
7707 N_Single_Task_Declaration
7708 then
7709 Error_Pragma_Arg
7710 ("argument of pragma % must denote a full type or object "
7711 & "declaration", Arg1);
7712 end if;
7713
7714 -- Deal with the case where the pragma/attribute is applied to a type
7715
7716 if Is_Type (E) then
7717 if Rep_Item_Too_Early (E, N)
7718 or else Rep_Item_Too_Late (E, N)
7719 then
7720 return;
7721 else
7722 Check_First_Subtype (Arg1);
7723 end if;
7724
7725 Mark_Type (E);
7726
7727 -- Deal with the case where the pragma/attribute applies to a
7728 -- component or object declaration.
7729
7730 elsif Nkind (Decl) = N_Object_Declaration
7731 or else (Nkind (Decl) = N_Component_Declaration
7732 and then Original_Record_Component (E) = E)
7733 then
7734 if Rep_Item_Too_Late (E, N) then
7735 return;
7736 end if;
7737
7738 Mark_Component_Or_Object (E);
7739
7740 -- In other cases give an error
7741
7742 else
7743 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7744 end if;
7745 end Process_Atomic_Independent_Shared_Volatile;
7746
7747 -------------------------------------------
7748 -- Process_Compile_Time_Warning_Or_Error --
7749 -------------------------------------------
7750
7751 procedure Process_Compile_Time_Warning_Or_Error is
7752 P : Node_Id := Parent (N);
7753 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
7754
7755 begin
7756 Check_Arg_Count (2);
7757 Check_No_Identifiers;
7758 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
7759 Analyze_And_Resolve (Arg1x, Standard_Boolean);
7760
7761 -- In GNATprove mode, pragma Compile_Time_Error is translated as
7762 -- a Check pragma in GNATprove mode, handled as an assumption in
7763 -- GNATprove. This is correct as the compiler will issue an error
7764 -- if the condition cannot be statically evaluated to False.
7765 -- Compile_Time_Warning are ignored, as the analyzer may not have the
7766 -- same information as the compiler (in particular regarding size of
7767 -- objects decided in gigi) so it makes no sense to issue a warning
7768 -- in GNATprove.
7769
7770 if GNATprove_Mode then
7771 if Prag_Id = Pragma_Compile_Time_Error then
7772 declare
7773 New_Args : List_Id;
7774 begin
7775 -- Implement Compile_Time_Error by generating
7776 -- a corresponding Check pragma:
7777
7778 -- pragma Check (name, condition);
7779
7780 -- where name is the identifier matching the pragma name. So
7781 -- rewrite pragma in this manner and analyze the result.
7782
7783 New_Args := New_List
7784 (Make_Pragma_Argument_Association
7785 (Loc,
7786 Expression => Make_Identifier (Loc, Pname)),
7787 Make_Pragma_Argument_Association
7788 (Sloc (Arg1x),
7789 Expression => Arg1x));
7790
7791 -- Rewrite as Check pragma
7792
7793 Rewrite (N,
7794 Make_Pragma (Loc,
7795 Chars => Name_Check,
7796 Pragma_Argument_Associations => New_Args));
7797
7798 Analyze (N);
7799 end;
7800
7801 else
7802 Rewrite (N, Make_Null_Statement (Loc));
7803 end if;
7804
7805 return;
7806 end if;
7807
7808 -- If the condition is known at compile time (now), validate it now.
7809 -- Otherwise, register the expression for validation after the back
7810 -- end has been called, because it might be known at compile time
7811 -- then. For example, if the expression is "Record_Type'Size /= 32"
7812 -- it might be known after the back end has determined the size of
7813 -- Record_Type. We do not defer validation if we're inside a generic
7814 -- unit, because we will have more information in the instances.
7815
7816 if Compile_Time_Known_Value (Arg1x) then
7817 Validate_Compile_Time_Warning_Or_Error (N, Sloc (Arg1));
7818
7819 else
7820 while Present (P) and then Nkind (P) not in N_Generic_Declaration
7821 loop
7822 if (Nkind (P) = N_Subprogram_Body and then not Acts_As_Spec (P))
7823 or else Nkind (P) = N_Package_Body
7824 then
7825 P := Parent (Corresponding_Spec (P));
7826
7827 else
7828 P := Parent (P);
7829 end if;
7830 end loop;
7831
7832 if No (P) then
7833 Defer_Compile_Time_Warning_Error_To_BE (N);
7834 end if;
7835 end if;
7836 end Process_Compile_Time_Warning_Or_Error;
7837
7838 ------------------------
7839 -- Process_Convention --
7840 ------------------------
7841
7842 procedure Process_Convention
7843 (C : out Convention_Id;
7844 Ent : out Entity_Id)
7845 is
7846 Cname : Name_Id;
7847
7848 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
7849 -- Called if we have more than one Export/Import/Convention pragma.
7850 -- This is generally illegal, but we have a special case of allowing
7851 -- Import and Interface to coexist if they specify the convention in
7852 -- a consistent manner. We are allowed to do this, since Interface is
7853 -- an implementation defined pragma, and we choose to do it since we
7854 -- know Rational allows this combination. S is the entity id of the
7855 -- subprogram in question. This procedure also sets the special flag
7856 -- Import_Interface_Present in both pragmas in the case where we do
7857 -- have matching Import and Interface pragmas.
7858
7859 procedure Set_Convention_From_Pragma (E : Entity_Id);
7860 -- Set convention in entity E, and also flag that the entity has a
7861 -- convention pragma. If entity is for a private or incomplete type,
7862 -- also set convention and flag on underlying type. This procedure
7863 -- also deals with the special case of C_Pass_By_Copy convention,
7864 -- and error checks for inappropriate convention specification.
7865
7866 -------------------------------
7867 -- Diagnose_Multiple_Pragmas --
7868 -------------------------------
7869
7870 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
7871 Pdec : constant Node_Id := Declaration_Node (S);
7872 Decl : Node_Id;
7873 Err : Boolean;
7874
7875 function Same_Convention (Decl : Node_Id) return Boolean;
7876 -- Decl is a pragma node. This function returns True if this
7877 -- pragma has a first argument that is an identifier with a
7878 -- Chars field corresponding to the Convention_Id C.
7879
7880 function Same_Name (Decl : Node_Id) return Boolean;
7881 -- Decl is a pragma node. This function returns True if this
7882 -- pragma has a second argument that is an identifier with a
7883 -- Chars field that matches the Chars of the current subprogram.
7884
7885 ---------------------
7886 -- Same_Convention --
7887 ---------------------
7888
7889 function Same_Convention (Decl : Node_Id) return Boolean is
7890 Arg1 : constant Node_Id :=
7891 First (Pragma_Argument_Associations (Decl));
7892
7893 begin
7894 if Present (Arg1) then
7895 declare
7896 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
7897 begin
7898 if Nkind (Arg) = N_Identifier
7899 and then Is_Convention_Name (Chars (Arg))
7900 and then Get_Convention_Id (Chars (Arg)) = C
7901 then
7902 return True;
7903 end if;
7904 end;
7905 end if;
7906
7907 return False;
7908 end Same_Convention;
7909
7910 ---------------
7911 -- Same_Name --
7912 ---------------
7913
7914 function Same_Name (Decl : Node_Id) return Boolean is
7915 Arg1 : constant Node_Id :=
7916 First (Pragma_Argument_Associations (Decl));
7917 Arg2 : Node_Id;
7918
7919 begin
7920 if No (Arg1) then
7921 return False;
7922 end if;
7923
7924 Arg2 := Next (Arg1);
7925
7926 if No (Arg2) then
7927 return False;
7928 end if;
7929
7930 declare
7931 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
7932 begin
7933 if Nkind (Arg) = N_Identifier
7934 and then Chars (Arg) = Chars (S)
7935 then
7936 return True;
7937 end if;
7938 end;
7939
7940 return False;
7941 end Same_Name;
7942
7943 -- Start of processing for Diagnose_Multiple_Pragmas
7944
7945 begin
7946 Err := True;
7947
7948 -- Definitely give message if we have Convention/Export here
7949
7950 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
7951 null;
7952
7953 -- If we have an Import or Export, scan back from pragma to
7954 -- find any previous pragma applying to the same procedure.
7955 -- The scan will be terminated by the start of the list, or
7956 -- hitting the subprogram declaration. This won't allow one
7957 -- pragma to appear in the public part and one in the private
7958 -- part, but that seems very unlikely in practice.
7959
7960 else
7961 Decl := Prev (N);
7962 while Present (Decl) and then Decl /= Pdec loop
7963
7964 -- Look for pragma with same name as us
7965
7966 if Nkind (Decl) = N_Pragma
7967 and then Same_Name (Decl)
7968 then
7969 -- Give error if same as our pragma or Export/Convention
7970
7971 if Pragma_Name_Unmapped (Decl)
7972 in Name_Export
7973 | Name_Convention
7974 | Pragma_Name_Unmapped (N)
7975 then
7976 exit;
7977
7978 -- Case of Import/Interface or the other way round
7979
7980 elsif Pragma_Name_Unmapped (Decl)
7981 in Name_Interface | Name_Import
7982 then
7983 -- Here we know that we have Import and Interface. It
7984 -- doesn't matter which way round they are. See if
7985 -- they specify the same convention. If so, all OK,
7986 -- and set special flags to stop other messages
7987
7988 if Same_Convention (Decl) then
7989 Set_Import_Interface_Present (N);
7990 Set_Import_Interface_Present (Decl);
7991 Err := False;
7992
7993 -- If different conventions, special message
7994
7995 else
7996 Error_Msg_Sloc := Sloc (Decl);
7997 Error_Pragma_Arg
7998 ("convention differs from that given#", Arg1);
7999 end if;
8000 end if;
8001 end if;
8002
8003 Next (Decl);
8004 end loop;
8005 end if;
8006
8007 -- Give message if needed if we fall through those tests
8008 -- except on Relaxed_RM_Semantics where we let go: either this
8009 -- is a case accepted/ignored by other Ada compilers (e.g.
8010 -- a mix of Convention and Import), or another error will be
8011 -- generated later (e.g. using both Import and Export).
8012
8013 if Err and not Relaxed_RM_Semantics then
8014 Error_Pragma_Arg
8015 ("at most one Convention/Export/Import pragma is allowed",
8016 Arg2);
8017 end if;
8018 end Diagnose_Multiple_Pragmas;
8019
8020 --------------------------------
8021 -- Set_Convention_From_Pragma --
8022 --------------------------------
8023
8024 procedure Set_Convention_From_Pragma (E : Entity_Id) is
8025 begin
8026 -- Ada 2005 (AI-430): Check invalid attempt to change convention
8027 -- for an overridden dispatching operation. Technically this is
8028 -- an amendment and should only be done in Ada 2005 mode. However,
8029 -- this is clearly a mistake, since the problem that is addressed
8030 -- by this AI is that there is a clear gap in the RM.
8031
8032 if Is_Dispatching_Operation (E)
8033 and then Present (Overridden_Operation (E))
8034 and then C /= Convention (Overridden_Operation (E))
8035 then
8036 Error_Pragma_Arg
8037 ("cannot change convention for overridden dispatching "
8038 & "operation", Arg1);
8039
8040 -- Special check for convention Stdcall: a dispatching call is not
8041 -- allowed. A dispatching subprogram cannot be used to interface
8042 -- to the Win32 API, so this check actually does not impose any
8043 -- effective restriction.
8044
8045 elsif Is_Dispatching_Operation (E)
8046 and then C = Convention_Stdcall
8047 then
8048 -- Note: make this unconditional so that if there is more
8049 -- than one call to which the pragma applies, we get a
8050 -- message for each call. Also don't use Error_Pragma,
8051 -- so that we get multiple messages.
8052
8053 Error_Msg_Sloc := Sloc (E);
8054 Error_Msg_N
8055 ("dispatching subprogram# cannot use Stdcall convention!",
8056 Get_Pragma_Arg (Arg1));
8057 end if;
8058
8059 -- Set the convention
8060
8061 Set_Convention (E, C);
8062 Set_Has_Convention_Pragma (E);
8063
8064 -- For the case of a record base type, also set the convention of
8065 -- any anonymous access types declared in the record which do not
8066 -- currently have a specified convention.
8067 -- Similarly for an array base type and anonymous access types
8068 -- components.
8069
8070 if Is_Base_Type (E) then
8071 if Is_Record_Type (E) then
8072 declare
8073 Comp : Node_Id;
8074
8075 begin
8076 Comp := First_Component (E);
8077 while Present (Comp) loop
8078 if Present (Etype (Comp))
8079 and then
8080 Ekind (Etype (Comp)) in
8081 E_Anonymous_Access_Type |
8082 E_Anonymous_Access_Subprogram_Type
8083 and then not Has_Convention_Pragma (Comp)
8084 then
8085 Set_Convention (Comp, C);
8086 end if;
8087
8088 Next_Component (Comp);
8089 end loop;
8090 end;
8091
8092 elsif Is_Array_Type (E)
8093 and then Ekind (Component_Type (E)) in
8094 E_Anonymous_Access_Type |
8095 E_Anonymous_Access_Subprogram_Type
8096 then
8097 Set_Convention (Designated_Type (Component_Type (E)), C);
8098 end if;
8099 end if;
8100
8101 -- Deal with incomplete/private type case, where underlying type
8102 -- is available, so set convention of that underlying type.
8103
8104 if Is_Incomplete_Or_Private_Type (E)
8105 and then Present (Underlying_Type (E))
8106 then
8107 Set_Convention (Underlying_Type (E), C);
8108 Set_Has_Convention_Pragma (Underlying_Type (E), True);
8109 end if;
8110
8111 -- A class-wide type should inherit the convention of the specific
8112 -- root type (although this isn't specified clearly by the RM).
8113
8114 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
8115 Set_Convention (Class_Wide_Type (E), C);
8116 end if;
8117
8118 -- If the entity is a record type, then check for special case of
8119 -- C_Pass_By_Copy, which is treated the same as C except that the
8120 -- special record flag is set. This convention is only permitted
8121 -- on record types (see AI95-00131).
8122
8123 if Cname = Name_C_Pass_By_Copy then
8124 if Is_Record_Type (E) then
8125 Set_C_Pass_By_Copy (Base_Type (E));
8126 elsif Is_Incomplete_Or_Private_Type (E)
8127 and then Is_Record_Type (Underlying_Type (E))
8128 then
8129 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
8130 else
8131 Error_Pragma_Arg
8132 ("C_Pass_By_Copy convention allowed only for record type",
8133 Arg2);
8134 end if;
8135 end if;
8136
8137 -- If the entity is a derived boolean type, check for the special
8138 -- case of convention C, C++, or Fortran, where we consider any
8139 -- nonzero value to represent true.
8140
8141 if Is_Discrete_Type (E)
8142 and then Root_Type (Etype (E)) = Standard_Boolean
8143 and then
8144 (C = Convention_C
8145 or else
8146 C = Convention_CPP
8147 or else
8148 C = Convention_Fortran)
8149 then
8150 Set_Nonzero_Is_True (Base_Type (E));
8151 end if;
8152 end Set_Convention_From_Pragma;
8153
8154 -- Local variables
8155
8156 Comp_Unit : Unit_Number_Type;
8157 E : Entity_Id;
8158 E1 : Entity_Id;
8159 Id : Node_Id;
8160 Subp : Entity_Id;
8161
8162 -- Start of processing for Process_Convention
8163
8164 begin
8165 Check_At_Least_N_Arguments (2);
8166 Check_Optional_Identifier (Arg1, Name_Convention);
8167 Check_Arg_Is_Identifier (Arg1);
8168 Cname := Chars (Get_Pragma_Arg (Arg1));
8169
8170 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
8171 -- tested again below to set the critical flag).
8172
8173 if Cname = Name_C_Pass_By_Copy then
8174 C := Convention_C;
8175
8176 -- Otherwise we must have something in the standard convention list
8177
8178 elsif Is_Convention_Name (Cname) then
8179 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
8180
8181 -- Otherwise warn on unrecognized convention
8182
8183 else
8184 if Warn_On_Export_Import then
8185 Error_Msg_N
8186 ("??unrecognized convention name, C assumed",
8187 Get_Pragma_Arg (Arg1));
8188 end if;
8189
8190 C := Convention_C;
8191 end if;
8192
8193 Check_Optional_Identifier (Arg2, Name_Entity);
8194 Check_Arg_Is_Local_Name (Arg2);
8195
8196 Id := Get_Pragma_Arg (Arg2);
8197 Analyze (Id);
8198
8199 if not Is_Entity_Name (Id) then
8200 Error_Pragma_Arg ("entity name required", Arg2);
8201 end if;
8202
8203 E := Entity (Id);
8204
8205 -- Set entity to return
8206
8207 Ent := E;
8208
8209 -- Ada_Pass_By_Copy special checking
8210
8211 if C = Convention_Ada_Pass_By_Copy then
8212 if not Is_First_Subtype (E) then
8213 Error_Pragma_Arg
8214 ("convention `Ada_Pass_By_Copy` only allowed for types",
8215 Arg2);
8216 end if;
8217
8218 if Is_By_Reference_Type (E) then
8219 Error_Pragma_Arg
8220 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
8221 & "type", Arg1);
8222 end if;
8223
8224 -- Ada_Pass_By_Reference special checking
8225
8226 elsif C = Convention_Ada_Pass_By_Reference then
8227 if not Is_First_Subtype (E) then
8228 Error_Pragma_Arg
8229 ("convention `Ada_Pass_By_Reference` only allowed for types",
8230 Arg2);
8231 end if;
8232
8233 if Is_By_Copy_Type (E) then
8234 Error_Pragma_Arg
8235 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
8236 & "type", Arg1);
8237 end if;
8238 end if;
8239
8240 -- Go to renamed subprogram if present, since convention applies to
8241 -- the actual renamed entity, not to the renaming entity. If the
8242 -- subprogram is inherited, go to parent subprogram.
8243
8244 if Is_Subprogram (E)
8245 and then Present (Alias (E))
8246 then
8247 if Nkind (Parent (Declaration_Node (E))) =
8248 N_Subprogram_Renaming_Declaration
8249 then
8250 if Scope (E) /= Scope (Alias (E)) then
8251 Error_Pragma_Ref
8252 ("cannot apply pragma% to non-local entity&#", E);
8253 end if;
8254
8255 E := Alias (E);
8256
8257 elsif Nkind (Parent (E)) in
8258 N_Full_Type_Declaration | N_Private_Extension_Declaration
8259 and then Scope (E) = Scope (Alias (E))
8260 then
8261 E := Alias (E);
8262
8263 -- Return the parent subprogram the entity was inherited from
8264
8265 Ent := E;
8266 end if;
8267 end if;
8268
8269 -- Check that we are not applying this to a specless body. Relax this
8270 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
8271
8272 if Is_Subprogram (E)
8273 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
8274 and then not Relaxed_RM_Semantics
8275 then
8276 Error_Pragma
8277 ("pragma% requires separate spec and must come before body");
8278 end if;
8279
8280 -- Check that we are not applying this to a named constant
8281
8282 if Is_Named_Number (E) then
8283 Error_Msg_Name_1 := Pname;
8284 Error_Msg_N
8285 ("cannot apply pragma% to named constant!",
8286 Get_Pragma_Arg (Arg2));
8287 Error_Pragma_Arg
8288 ("\supply appropriate type for&!", Arg2);
8289 end if;
8290
8291 if Ekind (E) = E_Enumeration_Literal then
8292 Error_Pragma ("enumeration literal not allowed for pragma%");
8293 end if;
8294
8295 -- Check for rep item appearing too early or too late
8296
8297 if Etype (E) = Any_Type
8298 or else Rep_Item_Too_Early (E, N)
8299 then
8300 raise Pragma_Exit;
8301
8302 elsif Present (Underlying_Type (E)) then
8303 E := Underlying_Type (E);
8304 end if;
8305
8306 if Rep_Item_Too_Late (E, N) then
8307 raise Pragma_Exit;
8308 end if;
8309
8310 if Has_Convention_Pragma (E) then
8311 Diagnose_Multiple_Pragmas (E);
8312
8313 elsif Convention (E) = Convention_Protected
8314 or else Ekind (Scope (E)) = E_Protected_Type
8315 then
8316 Error_Pragma_Arg
8317 ("a protected operation cannot be given a different convention",
8318 Arg2);
8319 end if;
8320
8321 -- For Intrinsic, a subprogram is required
8322
8323 if C = Convention_Intrinsic
8324 and then not Is_Subprogram_Or_Generic_Subprogram (E)
8325 then
8326 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
8327
8328 if not (Is_Type (E) and then Relaxed_RM_Semantics) then
8329 if From_Aspect_Specification (N) then
8330 Error_Pragma_Arg
8331 ("entity for aspect% must be a subprogram", Arg2);
8332 else
8333 Error_Pragma_Arg
8334 ("second argument of pragma% must be a subprogram", Arg2);
8335 end if;
8336 end if;
8337
8338 -- Special checks for C_Variadic_n
8339
8340 elsif C in Convention_C_Variadic then
8341
8342 -- Several allowed cases
8343
8344 if Is_Subprogram_Or_Generic_Subprogram (E) then
8345 Subp := E;
8346
8347 -- An access to subprogram is also allowed
8348
8349 elsif Is_Access_Type (E)
8350 and then Ekind (Designated_Type (E)) = E_Subprogram_Type
8351 then
8352 Subp := Designated_Type (E);
8353
8354 -- Allow internal call to set convention of subprogram type
8355
8356 elsif Ekind (E) = E_Subprogram_Type then
8357 Subp := E;
8358
8359 else
8360 Error_Pragma_Arg
8361 ("argument of pragma% must be subprogram or access type",
8362 Arg2);
8363 end if;
8364
8365 -- ISO C requires a named parameter before the ellipsis, so a
8366 -- variadic C function taking 0 fixed parameter cannot exist.
8367
8368 if C = Convention_C_Variadic_0 then
8369
8370 Error_Msg_N
8371 ("??C_Variadic_0 cannot be used for an 'I'S'O C function",
8372 Get_Pragma_Arg (Arg2));
8373
8374 -- Now check the number of parameters of the subprogram and give
8375 -- an error if it is lower than n.
8376
8377 elsif Present (Subp) then
8378 declare
8379 Minimum : constant Nat :=
8380 Convention_Id'Pos (C) -
8381 Convention_Id'Pos (Convention_C_Variadic_0);
8382
8383 Count : Nat;
8384 Formal : Entity_Id;
8385
8386 begin
8387 Count := 0;
8388 Formal := First_Formal (Subp);
8389 while Present (Formal) loop
8390 Count := Count + 1;
8391 Next_Formal (Formal);
8392 end loop;
8393
8394 if Count < Minimum then
8395 Error_Msg_Uint_1 := UI_From_Int (Minimum);
8396 Error_Pragma_Arg
8397 ("argument of pragma% must have at least"
8398 & "^ parameters", Arg2);
8399 end if;
8400 end;
8401 end if;
8402
8403 -- Special checks for Stdcall
8404
8405 elsif C = Convention_Stdcall then
8406
8407 -- Several allowed cases
8408
8409 if Is_Subprogram_Or_Generic_Subprogram (E)
8410
8411 -- A variable is OK
8412
8413 or else Ekind (E) = E_Variable
8414
8415 -- A component as well. The entity does not have its Ekind
8416 -- set until the enclosing record declaration is fully
8417 -- analyzed.
8418
8419 or else Nkind (Parent (E)) = N_Component_Declaration
8420
8421 -- An access to subprogram is also allowed
8422
8423 or else
8424 (Is_Access_Type (E)
8425 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
8426
8427 -- Allow internal call to set convention of subprogram type
8428
8429 or else Ekind (E) = E_Subprogram_Type
8430 then
8431 null;
8432
8433 else
8434 Error_Pragma_Arg
8435 ("argument of pragma% must be subprogram or access type",
8436 Arg2);
8437 end if;
8438 end if;
8439
8440 Set_Convention_From_Pragma (E);
8441
8442 -- Deal with non-subprogram cases
8443
8444 if not Is_Subprogram_Or_Generic_Subprogram (E) then
8445 if Is_Type (E) then
8446
8447 -- The pragma must apply to a first subtype, but it can also
8448 -- apply to a generic type in a generic formal part, in which
8449 -- case it will also appear in the corresponding instance.
8450
8451 if Is_Generic_Type (E) or else In_Instance then
8452 null;
8453 else
8454 Check_First_Subtype (Arg2);
8455 end if;
8456
8457 Set_Convention_From_Pragma (Base_Type (E));
8458
8459 -- For access subprograms, we must set the convention on the
8460 -- internally generated directly designated type as well.
8461
8462 if Ekind (E) = E_Access_Subprogram_Type then
8463 Set_Convention_From_Pragma (Directly_Designated_Type (E));
8464 end if;
8465 end if;
8466
8467 -- For the subprogram case, set proper convention for all homonyms
8468 -- in same scope and the same declarative part, i.e. the same
8469 -- compilation unit.
8470
8471 else
8472 -- Treat a pragma Import as an implicit body, and pragma import
8473 -- as implicit reference (for navigation in GNAT Studio).
8474
8475 if Prag_Id = Pragma_Import then
8476 Generate_Reference (E, Id, 'b');
8477
8478 -- For exported entities we restrict the generation of references
8479 -- to entities exported to foreign languages since entities
8480 -- exported to Ada do not provide further information to
8481 -- GNAT Studio and add undesired references to the output of the
8482 -- gnatxref tool.
8483
8484 elsif Prag_Id = Pragma_Export
8485 and then Convention (E) /= Convention_Ada
8486 then
8487 Generate_Reference (E, Id, 'i');
8488 end if;
8489
8490 -- If the pragma comes from an aspect, it only applies to the
8491 -- given entity, not its homonyms.
8492
8493 if From_Aspect_Specification (N) then
8494 if C = Convention_Intrinsic
8495 and then Nkind (Ent) = N_Defining_Operator_Symbol
8496 then
8497 if Is_Fixed_Point_Type (Etype (Ent))
8498 or else Is_Fixed_Point_Type (Etype (First_Entity (Ent)))
8499 or else Is_Fixed_Point_Type (Etype (Last_Entity (Ent)))
8500 then
8501 Error_Msg_N
8502 ("no intrinsic operator available for this fixed-point "
8503 & "operation", N);
8504 Error_Msg_N
8505 ("\use expression functions with the desired "
8506 & "conversions made explicit", N);
8507 end if;
8508 end if;
8509
8510 return;
8511 end if;
8512
8513 -- Otherwise Loop through the homonyms of the pragma argument's
8514 -- entity, an apply convention to those in the current scope.
8515
8516 Comp_Unit := Get_Source_Unit (E);
8517 E1 := Ent;
8518
8519 loop
8520 E1 := Homonym (E1);
8521 exit when No (E1) or else Scope (E1) /= Current_Scope;
8522
8523 -- Ignore entry for which convention is already set
8524
8525 if Has_Convention_Pragma (E1) then
8526 goto Continue;
8527 end if;
8528
8529 if Is_Subprogram (E1)
8530 and then Nkind (Parent (Declaration_Node (E1))) =
8531 N_Subprogram_Body
8532 and then not Relaxed_RM_Semantics
8533 then
8534 Set_Has_Completion (E); -- to prevent cascaded error
8535 Error_Pragma_Ref
8536 ("pragma% requires separate spec and must come before "
8537 & "body#", E1);
8538 end if;
8539
8540 -- Do not set the pragma on inherited operations or on formal
8541 -- subprograms.
8542
8543 if Comes_From_Source (E1)
8544 and then Comp_Unit = Get_Source_Unit (E1)
8545 and then not Is_Formal_Subprogram (E1)
8546 and then Nkind (Original_Node (Parent (E1))) /=
8547 N_Full_Type_Declaration
8548 then
8549 if Present (Alias (E1))
8550 and then Scope (E1) /= Scope (Alias (E1))
8551 then
8552 Error_Pragma_Ref
8553 ("cannot apply pragma% to non-local entity& declared#",
8554 E1);
8555 end if;
8556
8557 Set_Convention_From_Pragma (E1);
8558
8559 if Prag_Id = Pragma_Import then
8560 Generate_Reference (E1, Id, 'b');
8561 end if;
8562 end if;
8563
8564 <<Continue>>
8565 null;
8566 end loop;
8567 end if;
8568 end Process_Convention;
8569
8570 ----------------------------------------
8571 -- Process_Disable_Enable_Atomic_Sync --
8572 ----------------------------------------
8573
8574 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
8575 begin
8576 Check_No_Identifiers;
8577 Check_At_Most_N_Arguments (1);
8578
8579 -- Modeled internally as
8580 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
8581
8582 Rewrite (N,
8583 Make_Pragma (Loc,
8584 Chars => Nam,
8585 Pragma_Argument_Associations => New_List (
8586 Make_Pragma_Argument_Association (Loc,
8587 Expression =>
8588 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
8589
8590 if Present (Arg1) then
8591 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
8592 end if;
8593
8594 Analyze (N);
8595 end Process_Disable_Enable_Atomic_Sync;
8596
8597 -------------------------------------------------
8598 -- Process_Extended_Import_Export_Internal_Arg --
8599 -------------------------------------------------
8600
8601 procedure Process_Extended_Import_Export_Internal_Arg
8602 (Arg_Internal : Node_Id := Empty)
8603 is
8604 begin
8605 if No (Arg_Internal) then
8606 Error_Pragma ("Internal parameter required for pragma%");
8607 end if;
8608
8609 if Nkind (Arg_Internal) = N_Identifier then
8610 null;
8611
8612 elsif Nkind (Arg_Internal) = N_Operator_Symbol
8613 and then (Prag_Id = Pragma_Import_Function
8614 or else
8615 Prag_Id = Pragma_Export_Function)
8616 then
8617 null;
8618
8619 else
8620 Error_Pragma_Arg
8621 ("wrong form for Internal parameter for pragma%", Arg_Internal);
8622 end if;
8623
8624 Check_Arg_Is_Local_Name (Arg_Internal);
8625 end Process_Extended_Import_Export_Internal_Arg;
8626
8627 --------------------------------------------------
8628 -- Process_Extended_Import_Export_Object_Pragma --
8629 --------------------------------------------------
8630
8631 procedure Process_Extended_Import_Export_Object_Pragma
8632 (Arg_Internal : Node_Id;
8633 Arg_External : Node_Id;
8634 Arg_Size : Node_Id)
8635 is
8636 Def_Id : Entity_Id;
8637
8638 begin
8639 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8640 Def_Id := Entity (Arg_Internal);
8641
8642 if Ekind (Def_Id) not in E_Constant | E_Variable then
8643 Error_Pragma_Arg
8644 ("pragma% must designate an object", Arg_Internal);
8645 end if;
8646
8647 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
8648 or else
8649 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
8650 then
8651 Error_Pragma_Arg
8652 ("previous Common/Psect_Object applies, pragma % not permitted",
8653 Arg_Internal);
8654 end if;
8655
8656 if Rep_Item_Too_Late (Def_Id, N) then
8657 raise Pragma_Exit;
8658 end if;
8659
8660 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
8661
8662 if Present (Arg_Size) then
8663 Check_Arg_Is_External_Name (Arg_Size);
8664 end if;
8665
8666 -- Export_Object case
8667
8668 if Prag_Id = Pragma_Export_Object then
8669 if not Is_Library_Level_Entity (Def_Id) then
8670 Error_Pragma_Arg
8671 ("argument for pragma% must be library level entity",
8672 Arg_Internal);
8673 end if;
8674
8675 if Ekind (Current_Scope) = E_Generic_Package then
8676 Error_Pragma ("pragma& cannot appear in a generic unit");
8677 end if;
8678
8679 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
8680 Error_Pragma_Arg
8681 ("exported object must have compile time known size",
8682 Arg_Internal);
8683 end if;
8684
8685 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
8686 Error_Msg_N ("??duplicate Export_Object pragma", N);
8687 else
8688 Set_Exported (Def_Id, Arg_Internal);
8689 end if;
8690
8691 -- Import_Object case
8692
8693 else
8694 if Is_Concurrent_Type (Etype (Def_Id)) then
8695 Error_Pragma_Arg
8696 ("cannot use pragma% for task/protected object",
8697 Arg_Internal);
8698 end if;
8699
8700 if Ekind (Def_Id) = E_Constant then
8701 Error_Pragma_Arg
8702 ("cannot import a constant", Arg_Internal);
8703 end if;
8704
8705 if Warn_On_Export_Import
8706 and then Has_Discriminants (Etype (Def_Id))
8707 then
8708 Error_Msg_N
8709 ("imported value must be initialized??", Arg_Internal);
8710 end if;
8711
8712 if Warn_On_Export_Import
8713 and then Is_Access_Type (Etype (Def_Id))
8714 then
8715 Error_Pragma_Arg
8716 ("cannot import object of an access type??", Arg_Internal);
8717 end if;
8718
8719 if Warn_On_Export_Import
8720 and then Is_Imported (Def_Id)
8721 then
8722 Error_Msg_N ("??duplicate Import_Object pragma", N);
8723
8724 -- Check for explicit initialization present. Note that an
8725 -- initialization generated by the code generator, e.g. for an
8726 -- access type, does not count here.
8727
8728 elsif Present (Expression (Parent (Def_Id)))
8729 and then
8730 Comes_From_Source
8731 (Original_Node (Expression (Parent (Def_Id))))
8732 then
8733 Error_Msg_Sloc := Sloc (Def_Id);
8734 Error_Pragma_Arg
8735 ("imported entities cannot be initialized (RM B.1(24))",
8736 "\no initialization allowed for & declared#", Arg1);
8737 else
8738 Set_Imported (Def_Id);
8739 Note_Possible_Modification (Arg_Internal, Sure => False);
8740 end if;
8741 end if;
8742 end Process_Extended_Import_Export_Object_Pragma;
8743
8744 ------------------------------------------------------
8745 -- Process_Extended_Import_Export_Subprogram_Pragma --
8746 ------------------------------------------------------
8747
8748 procedure Process_Extended_Import_Export_Subprogram_Pragma
8749 (Arg_Internal : Node_Id;
8750 Arg_External : Node_Id;
8751 Arg_Parameter_Types : Node_Id;
8752 Arg_Result_Type : Node_Id := Empty;
8753 Arg_Mechanism : Node_Id;
8754 Arg_Result_Mechanism : Node_Id := Empty)
8755 is
8756 Ent : Entity_Id;
8757 Def_Id : Entity_Id;
8758 Hom_Id : Entity_Id;
8759 Formal : Entity_Id;
8760 Ambiguous : Boolean;
8761 Match : Boolean;
8762
8763 function Same_Base_Type
8764 (Ptype : Node_Id;
8765 Formal : Entity_Id) return Boolean;
8766 -- Determines if Ptype references the type of Formal. Note that only
8767 -- the base types need to match according to the spec. Ptype here is
8768 -- the argument from the pragma, which is either a type name, or an
8769 -- access attribute.
8770
8771 --------------------
8772 -- Same_Base_Type --
8773 --------------------
8774
8775 function Same_Base_Type
8776 (Ptype : Node_Id;
8777 Formal : Entity_Id) return Boolean
8778 is
8779 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
8780 Pref : Node_Id;
8781
8782 begin
8783 -- Case where pragma argument is typ'Access
8784
8785 if Nkind (Ptype) = N_Attribute_Reference
8786 and then Attribute_Name (Ptype) = Name_Access
8787 then
8788 Pref := Prefix (Ptype);
8789 Find_Type (Pref);
8790
8791 if not Is_Entity_Name (Pref)
8792 or else Entity (Pref) = Any_Type
8793 then
8794 raise Pragma_Exit;
8795 end if;
8796
8797 -- We have a match if the corresponding argument is of an
8798 -- anonymous access type, and its designated type matches the
8799 -- type of the prefix of the access attribute
8800
8801 return Ekind (Ftyp) = E_Anonymous_Access_Type
8802 and then Base_Type (Entity (Pref)) =
8803 Base_Type (Etype (Designated_Type (Ftyp)));
8804
8805 -- Case where pragma argument is a type name
8806
8807 else
8808 Find_Type (Ptype);
8809
8810 if not Is_Entity_Name (Ptype)
8811 or else Entity (Ptype) = Any_Type
8812 then
8813 raise Pragma_Exit;
8814 end if;
8815
8816 -- We have a match if the corresponding argument is of the type
8817 -- given in the pragma (comparing base types)
8818
8819 return Base_Type (Entity (Ptype)) = Ftyp;
8820 end if;
8821 end Same_Base_Type;
8822
8823 -- Start of processing for
8824 -- Process_Extended_Import_Export_Subprogram_Pragma
8825
8826 begin
8827 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8828 Ent := Empty;
8829 Ambiguous := False;
8830
8831 -- Loop through homonyms (overloadings) of the entity
8832
8833 Hom_Id := Entity (Arg_Internal);
8834 while Present (Hom_Id) loop
8835 Def_Id := Get_Base_Subprogram (Hom_Id);
8836
8837 -- We need a subprogram in the current scope
8838
8839 if not Is_Subprogram (Def_Id)
8840 or else Scope (Def_Id) /= Current_Scope
8841 then
8842 null;
8843
8844 else
8845 Match := True;
8846
8847 -- Pragma cannot apply to subprogram body
8848
8849 if Is_Subprogram (Def_Id)
8850 and then Nkind (Parent (Declaration_Node (Def_Id))) =
8851 N_Subprogram_Body
8852 then
8853 Error_Pragma
8854 ("pragma% requires separate spec and must come before "
8855 & "body");
8856 end if;
8857
8858 -- Test result type if given, note that the result type
8859 -- parameter can only be present for the function cases.
8860
8861 if Present (Arg_Result_Type)
8862 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
8863 then
8864 Match := False;
8865
8866 elsif Etype (Def_Id) /= Standard_Void_Type
8867 and then
8868 Pname in Name_Export_Procedure | Name_Import_Procedure
8869 then
8870 Match := False;
8871
8872 -- Test parameter types if given. Note that this parameter has
8873 -- not been analyzed (and must not be, since it is semantic
8874 -- nonsense), so we get it as the parser left it.
8875
8876 elsif Present (Arg_Parameter_Types) then
8877 Check_Matching_Types : declare
8878 Formal : Entity_Id;
8879 Ptype : Node_Id;
8880
8881 begin
8882 Formal := First_Formal (Def_Id);
8883
8884 if Nkind (Arg_Parameter_Types) = N_Null then
8885 if Present (Formal) then
8886 Match := False;
8887 end if;
8888
8889 -- A list of one type, e.g. (List) is parsed as a
8890 -- parenthesized expression.
8891
8892 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
8893 and then Paren_Count (Arg_Parameter_Types) = 1
8894 then
8895 if No (Formal)
8896 or else Present (Next_Formal (Formal))
8897 then
8898 Match := False;
8899 else
8900 Match :=
8901 Same_Base_Type (Arg_Parameter_Types, Formal);
8902 end if;
8903
8904 -- A list of more than one type is parsed as a aggregate
8905
8906 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
8907 and then Paren_Count (Arg_Parameter_Types) = 0
8908 then
8909 Ptype := First (Expressions (Arg_Parameter_Types));
8910 while Present (Ptype) or else Present (Formal) loop
8911 if No (Ptype)
8912 or else No (Formal)
8913 or else not Same_Base_Type (Ptype, Formal)
8914 then
8915 Match := False;
8916 exit;
8917 else
8918 Next_Formal (Formal);
8919 Next (Ptype);
8920 end if;
8921 end loop;
8922
8923 -- Anything else is of the wrong form
8924
8925 else
8926 Error_Pragma_Arg
8927 ("wrong form for Parameter_Types parameter",
8928 Arg_Parameter_Types);
8929 end if;
8930 end Check_Matching_Types;
8931 end if;
8932
8933 -- Match is now False if the entry we found did not match
8934 -- either a supplied Parameter_Types or Result_Types argument
8935
8936 if Match then
8937 if No (Ent) then
8938 Ent := Def_Id;
8939
8940 -- Ambiguous case, the flag Ambiguous shows if we already
8941 -- detected this and output the initial messages.
8942
8943 else
8944 if not Ambiguous then
8945 Ambiguous := True;
8946 Error_Msg_Name_1 := Pname;
8947 Error_Msg_N
8948 ("pragma% does not uniquely identify subprogram!",
8949 N);
8950 Error_Msg_Sloc := Sloc (Ent);
8951 Error_Msg_N ("matching subprogram #!", N);
8952 Ent := Empty;
8953 end if;
8954
8955 Error_Msg_Sloc := Sloc (Def_Id);
8956 Error_Msg_N ("matching subprogram #!", N);
8957 end if;
8958 end if;
8959 end if;
8960
8961 Hom_Id := Homonym (Hom_Id);
8962 end loop;
8963
8964 -- See if we found an entry
8965
8966 if No (Ent) then
8967 if not Ambiguous then
8968 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
8969 Error_Pragma
8970 ("pragma% cannot be given for generic subprogram");
8971 else
8972 Error_Pragma
8973 ("pragma% does not identify local subprogram");
8974 end if;
8975 end if;
8976
8977 return;
8978 end if;
8979
8980 -- Import pragmas must be for imported entities
8981
8982 if Prag_Id = Pragma_Import_Function
8983 or else
8984 Prag_Id = Pragma_Import_Procedure
8985 or else
8986 Prag_Id = Pragma_Import_Valued_Procedure
8987 then
8988 if not Is_Imported (Ent) then
8989 Error_Pragma
8990 ("pragma Import or Interface must precede pragma%");
8991 end if;
8992
8993 -- Here we have the Export case which can set the entity as exported
8994
8995 -- But does not do so if the specified external name is null, since
8996 -- that is taken as a signal in DEC Ada 83 (with which we want to be
8997 -- compatible) to request no external name.
8998
8999 elsif Nkind (Arg_External) = N_String_Literal
9000 and then String_Length (Strval (Arg_External)) = 0
9001 then
9002 null;
9003
9004 -- In all other cases, set entity as exported
9005
9006 else
9007 Set_Exported (Ent, Arg_Internal);
9008 end if;
9009
9010 -- Special processing for Valued_Procedure cases
9011
9012 if Prag_Id = Pragma_Import_Valued_Procedure
9013 or else
9014 Prag_Id = Pragma_Export_Valued_Procedure
9015 then
9016 Formal := First_Formal (Ent);
9017
9018 if No (Formal) then
9019 Error_Pragma ("at least one parameter required for pragma%");
9020
9021 elsif Ekind (Formal) /= E_Out_Parameter then
9022 Error_Pragma ("first parameter must have mode OUT for pragma%");
9023
9024 else
9025 Set_Is_Valued_Procedure (Ent);
9026 end if;
9027 end if;
9028
9029 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
9030
9031 -- Process Result_Mechanism argument if present. We have already
9032 -- checked that this is only allowed for the function case.
9033
9034 if Present (Arg_Result_Mechanism) then
9035 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
9036 end if;
9037
9038 -- Process Mechanism parameter if present. Note that this parameter
9039 -- is not analyzed, and must not be analyzed since it is semantic
9040 -- nonsense, so we get it in exactly as the parser left it.
9041
9042 if Present (Arg_Mechanism) then
9043 declare
9044 Formal : Entity_Id;
9045 Massoc : Node_Id;
9046 Mname : Node_Id;
9047 Choice : Node_Id;
9048
9049 begin
9050 -- A single mechanism association without a formal parameter
9051 -- name is parsed as a parenthesized expression. All other
9052 -- cases are parsed as aggregates, so we rewrite the single
9053 -- parameter case as an aggregate for consistency.
9054
9055 if Nkind (Arg_Mechanism) /= N_Aggregate
9056 and then Paren_Count (Arg_Mechanism) = 1
9057 then
9058 Rewrite (Arg_Mechanism,
9059 Make_Aggregate (Sloc (Arg_Mechanism),
9060 Expressions => New_List (
9061 Relocate_Node (Arg_Mechanism))));
9062 end if;
9063
9064 -- Case of only mechanism name given, applies to all formals
9065
9066 if Nkind (Arg_Mechanism) /= N_Aggregate then
9067 Formal := First_Formal (Ent);
9068 while Present (Formal) loop
9069 Set_Mechanism_Value (Formal, Arg_Mechanism);
9070 Next_Formal (Formal);
9071 end loop;
9072
9073 -- Case of list of mechanism associations given
9074
9075 else
9076 if Null_Record_Present (Arg_Mechanism) then
9077 Error_Pragma_Arg
9078 ("inappropriate form for Mechanism parameter",
9079 Arg_Mechanism);
9080 end if;
9081
9082 -- Deal with positional ones first
9083
9084 Formal := First_Formal (Ent);
9085
9086 if Present (Expressions (Arg_Mechanism)) then
9087 Mname := First (Expressions (Arg_Mechanism));
9088 while Present (Mname) loop
9089 if No (Formal) then
9090 Error_Pragma_Arg
9091 ("too many mechanism associations", Mname);
9092 end if;
9093
9094 Set_Mechanism_Value (Formal, Mname);
9095 Next_Formal (Formal);
9096 Next (Mname);
9097 end loop;
9098 end if;
9099
9100 -- Deal with named entries
9101
9102 if Present (Component_Associations (Arg_Mechanism)) then
9103 Massoc := First (Component_Associations (Arg_Mechanism));
9104 while Present (Massoc) loop
9105 Choice := First (Choices (Massoc));
9106
9107 if Nkind (Choice) /= N_Identifier
9108 or else Present (Next (Choice))
9109 then
9110 Error_Pragma_Arg
9111 ("incorrect form for mechanism association",
9112 Massoc);
9113 end if;
9114
9115 Formal := First_Formal (Ent);
9116 loop
9117 if No (Formal) then
9118 Error_Pragma_Arg
9119 ("parameter name & not present", Choice);
9120 end if;
9121
9122 if Chars (Choice) = Chars (Formal) then
9123 Set_Mechanism_Value
9124 (Formal, Expression (Massoc));
9125
9126 -- Set entity on identifier for proper tree
9127 -- structure.
9128
9129 Set_Entity (Choice, Formal);
9130
9131 exit;
9132 end if;
9133
9134 Next_Formal (Formal);
9135 end loop;
9136
9137 Next (Massoc);
9138 end loop;
9139 end if;
9140 end if;
9141 end;
9142 end if;
9143 end Process_Extended_Import_Export_Subprogram_Pragma;
9144
9145 --------------------------
9146 -- Process_Generic_List --
9147 --------------------------
9148
9149 procedure Process_Generic_List is
9150 Arg : Node_Id;
9151 Exp : Node_Id;
9152
9153 begin
9154 Check_No_Identifiers;
9155 Check_At_Least_N_Arguments (1);
9156
9157 -- Check all arguments are names of generic units or instances
9158
9159 Arg := Arg1;
9160 while Present (Arg) loop
9161 Exp := Get_Pragma_Arg (Arg);
9162 Analyze (Exp);
9163
9164 if not Is_Entity_Name (Exp)
9165 or else
9166 (not Is_Generic_Instance (Entity (Exp))
9167 and then
9168 not Is_Generic_Unit (Entity (Exp)))
9169 then
9170 Error_Pragma_Arg
9171 ("pragma% argument must be name of generic unit/instance",
9172 Arg);
9173 end if;
9174
9175 Next (Arg);
9176 end loop;
9177 end Process_Generic_List;
9178
9179 ------------------------------------
9180 -- Process_Import_Predefined_Type --
9181 ------------------------------------
9182
9183 procedure Process_Import_Predefined_Type is
9184 Loc : constant Source_Ptr := Sloc (N);
9185 Elmt : Elmt_Id;
9186 Ftyp : Node_Id := Empty;
9187 Decl : Node_Id;
9188 Def : Node_Id;
9189 Nam : Name_Id;
9190
9191 begin
9192 Nam := String_To_Name (Strval (Expression (Arg3)));
9193
9194 Elmt := First_Elmt (Predefined_Float_Types);
9195 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
9196 Next_Elmt (Elmt);
9197 end loop;
9198
9199 Ftyp := Node (Elmt);
9200
9201 if Present (Ftyp) then
9202
9203 -- Don't build a derived type declaration, because predefined C
9204 -- types have no declaration anywhere, so cannot really be named.
9205 -- Instead build a full type declaration, starting with an
9206 -- appropriate type definition is built
9207
9208 if Is_Floating_Point_Type (Ftyp) then
9209 Def := Make_Floating_Point_Definition (Loc,
9210 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
9211 Make_Real_Range_Specification (Loc,
9212 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
9213 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
9214
9215 -- Should never have a predefined type we cannot handle
9216
9217 else
9218 raise Program_Error;
9219 end if;
9220
9221 -- Build and insert a Full_Type_Declaration, which will be
9222 -- analyzed as soon as this list entry has been analyzed.
9223
9224 Decl := Make_Full_Type_Declaration (Loc,
9225 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
9226 Type_Definition => Def);
9227
9228 Insert_After (N, Decl);
9229 Mark_Rewrite_Insertion (Decl);
9230
9231 else
9232 Error_Pragma_Arg ("no matching type found for pragma%", Arg2);
9233 end if;
9234 end Process_Import_Predefined_Type;
9235
9236 ---------------------------------
9237 -- Process_Import_Or_Interface --
9238 ---------------------------------
9239
9240 procedure Process_Import_Or_Interface is
9241 C : Convention_Id;
9242 Def_Id : Entity_Id;
9243 Hom_Id : Entity_Id;
9244
9245 begin
9246 -- In Relaxed_RM_Semantics, support old Ada 83 style:
9247 -- pragma Import (Entity, "external name");
9248
9249 if Relaxed_RM_Semantics
9250 and then Arg_Count = 2
9251 and then Prag_Id = Pragma_Import
9252 and then Nkind (Expression (Arg2)) = N_String_Literal
9253 then
9254 C := Convention_C;
9255 Def_Id := Get_Pragma_Arg (Arg1);
9256 Analyze (Def_Id);
9257
9258 if not Is_Entity_Name (Def_Id) then
9259 Error_Pragma_Arg ("entity name required", Arg1);
9260 end if;
9261
9262 Def_Id := Entity (Def_Id);
9263 Kill_Size_Check_Code (Def_Id);
9264 if Ekind (Def_Id) /= E_Constant then
9265 Note_Possible_Modification
9266 (Get_Pragma_Arg (Arg1), Sure => False);
9267 end if;
9268
9269 else
9270 Process_Convention (C, Def_Id);
9271
9272 -- A pragma that applies to a Ghost entity becomes Ghost for the
9273 -- purposes of legality checks and removal of ignored Ghost code.
9274
9275 Mark_Ghost_Pragma (N, Def_Id);
9276 Kill_Size_Check_Code (Def_Id);
9277 if Ekind (Def_Id) /= E_Constant then
9278 Note_Possible_Modification
9279 (Get_Pragma_Arg (Arg2), Sure => False);
9280 end if;
9281 end if;
9282
9283 -- Various error checks
9284
9285 if Ekind (Def_Id) in E_Variable | E_Constant then
9286
9287 -- We do not permit Import to apply to a renaming declaration
9288
9289 if Present (Renamed_Object (Def_Id)) then
9290 Error_Pragma_Arg
9291 ("pragma% not allowed for object renaming", Arg2);
9292
9293 -- User initialization is not allowed for imported object, but
9294 -- the object declaration may contain a default initialization,
9295 -- that will be discarded. Note that an explicit initialization
9296 -- only counts if it comes from source, otherwise it is simply
9297 -- the code generator making an implicit initialization explicit.
9298
9299 elsif Present (Expression (Parent (Def_Id)))
9300 and then Comes_From_Source
9301 (Original_Node (Expression (Parent (Def_Id))))
9302 then
9303 -- Set imported flag to prevent cascaded errors
9304
9305 Set_Is_Imported (Def_Id);
9306
9307 Error_Msg_Sloc := Sloc (Def_Id);
9308 Error_Pragma_Arg
9309 ("no initialization allowed for declaration of& #",
9310 "\imported entities cannot be initialized (RM B.1(24))",
9311 Arg2);
9312
9313 else
9314 -- If the pragma comes from an aspect specification the
9315 -- Is_Imported flag has already been set.
9316
9317 if not From_Aspect_Specification (N) then
9318 Set_Imported (Def_Id);
9319 end if;
9320
9321 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9322
9323 -- Note that we do not set Is_Public here. That's because we
9324 -- only want to set it if there is no address clause, and we
9325 -- don't know that yet, so we delay that processing till
9326 -- freeze time.
9327
9328 -- pragma Import completes deferred constants
9329
9330 if Ekind (Def_Id) = E_Constant then
9331 Set_Has_Completion (Def_Id);
9332 end if;
9333
9334 -- It is not possible to import a constant of an unconstrained
9335 -- array type (e.g. string) because there is no simple way to
9336 -- write a meaningful subtype for it.
9337
9338 if Is_Array_Type (Etype (Def_Id))
9339 and then not Is_Constrained (Etype (Def_Id))
9340 then
9341 Error_Msg_NE
9342 ("imported constant& must have a constrained subtype",
9343 N, Def_Id);
9344 end if;
9345 end if;
9346
9347 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9348
9349 -- If the name is overloaded, pragma applies to all of the denoted
9350 -- entities in the same declarative part, unless the pragma comes
9351 -- from an aspect specification or was generated by the compiler
9352 -- (such as for pragma Provide_Shift_Operators).
9353
9354 Hom_Id := Def_Id;
9355 while Present (Hom_Id) loop
9356
9357 Def_Id := Get_Base_Subprogram (Hom_Id);
9358
9359 -- Ignore inherited subprograms because the pragma will apply
9360 -- to the parent operation, which is the one called.
9361
9362 if Is_Overloadable (Def_Id)
9363 and then Present (Alias (Def_Id))
9364 then
9365 null;
9366
9367 -- If it is not a subprogram, it must be in an outer scope and
9368 -- pragma does not apply.
9369
9370 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9371 null;
9372
9373 -- The pragma does not apply to primitives of interfaces
9374
9375 elsif Is_Dispatching_Operation (Def_Id)
9376 and then Present (Find_Dispatching_Type (Def_Id))
9377 and then Is_Interface (Find_Dispatching_Type (Def_Id))
9378 then
9379 null;
9380
9381 -- Verify that the homonym is in the same declarative part (not
9382 -- just the same scope). If the pragma comes from an aspect
9383 -- specification we know that it is part of the declaration.
9384
9385 elsif (No (Unit_Declaration_Node (Def_Id))
9386 or else Parent (Unit_Declaration_Node (Def_Id)) /=
9387 Parent (N))
9388 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9389 and then not From_Aspect_Specification (N)
9390 then
9391 exit;
9392
9393 else
9394 -- If the pragma comes from an aspect specification the
9395 -- Is_Imported flag has already been set.
9396
9397 if not From_Aspect_Specification (N) then
9398 Set_Imported (Def_Id);
9399 end if;
9400
9401 -- Reject an Import applied to an abstract subprogram
9402
9403 if Is_Subprogram (Def_Id)
9404 and then Is_Abstract_Subprogram (Def_Id)
9405 then
9406 Error_Msg_Sloc := Sloc (Def_Id);
9407 Error_Msg_NE
9408 ("cannot import abstract subprogram& declared#",
9409 Arg2, Def_Id);
9410 end if;
9411
9412 -- Special processing for Convention_Intrinsic
9413
9414 if C = Convention_Intrinsic then
9415
9416 -- Link_Name argument not allowed for intrinsic
9417
9418 Check_No_Link_Name;
9419
9420 Set_Is_Intrinsic_Subprogram (Def_Id);
9421
9422 -- If no external name is present, then check that this
9423 -- is a valid intrinsic subprogram. If an external name
9424 -- is present, then this is handled by the back end.
9425
9426 if No (Arg3) then
9427 Check_Intrinsic_Subprogram
9428 (Def_Id, Get_Pragma_Arg (Arg2));
9429 end if;
9430 end if;
9431
9432 -- Verify that the subprogram does not have a completion
9433 -- through a renaming declaration. For other completions the
9434 -- pragma appears as a too late representation.
9435
9436 declare
9437 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
9438
9439 begin
9440 if Present (Decl)
9441 and then Nkind (Decl) = N_Subprogram_Declaration
9442 and then Present (Corresponding_Body (Decl))
9443 and then Nkind (Unit_Declaration_Node
9444 (Corresponding_Body (Decl))) =
9445 N_Subprogram_Renaming_Declaration
9446 then
9447 Error_Msg_Sloc := Sloc (Def_Id);
9448 Error_Msg_NE
9449 ("cannot import&, renaming already provided for "
9450 & "declaration #", N, Def_Id);
9451 end if;
9452 end;
9453
9454 -- If the pragma comes from an aspect specification, there
9455 -- must be an Import aspect specified as well. In the rare
9456 -- case where Import is set to False, the subprogram needs
9457 -- to have a local completion.
9458
9459 declare
9460 Imp_Aspect : constant Node_Id :=
9461 Find_Aspect (Def_Id, Aspect_Import);
9462 Expr : Node_Id;
9463
9464 begin
9465 if Present (Imp_Aspect)
9466 and then Present (Expression (Imp_Aspect))
9467 then
9468 Expr := Expression (Imp_Aspect);
9469 Analyze_And_Resolve (Expr, Standard_Boolean);
9470
9471 if Is_Entity_Name (Expr)
9472 and then Entity (Expr) = Standard_True
9473 then
9474 Set_Has_Completion (Def_Id);
9475 end if;
9476
9477 -- If there is no expression, the default is True, as for
9478 -- all boolean aspects. Same for the older pragma.
9479
9480 else
9481 Set_Has_Completion (Def_Id);
9482 end if;
9483 end;
9484
9485 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9486 end if;
9487
9488 if Is_Compilation_Unit (Hom_Id) then
9489
9490 -- Its possible homonyms are not affected by the pragma.
9491 -- Such homonyms might be present in the context of other
9492 -- units being compiled.
9493
9494 exit;
9495
9496 elsif From_Aspect_Specification (N) then
9497 exit;
9498
9499 -- If the pragma was created by the compiler, then we don't
9500 -- want it to apply to other homonyms. This kind of case can
9501 -- occur when using pragma Provide_Shift_Operators, which
9502 -- generates implicit shift and rotate operators with Import
9503 -- pragmas that might apply to earlier explicit or implicit
9504 -- declarations marked with Import (for example, coming from
9505 -- an earlier pragma Provide_Shift_Operators for another type),
9506 -- and we don't generally want other homonyms being treated
9507 -- as imported or the pragma flagged as an illegal duplicate.
9508
9509 elsif not Comes_From_Source (N) then
9510 exit;
9511
9512 else
9513 Hom_Id := Homonym (Hom_Id);
9514 end if;
9515 end loop;
9516
9517 -- Import a CPP class
9518
9519 elsif C = Convention_CPP
9520 and then (Is_Record_Type (Def_Id)
9521 or else Ekind (Def_Id) = E_Incomplete_Type)
9522 then
9523 if Ekind (Def_Id) = E_Incomplete_Type then
9524 if Present (Full_View (Def_Id)) then
9525 Def_Id := Full_View (Def_Id);
9526
9527 else
9528 Error_Msg_N
9529 ("cannot import 'C'P'P type before full declaration seen",
9530 Get_Pragma_Arg (Arg2));
9531
9532 -- Although we have reported the error we decorate it as
9533 -- CPP_Class to avoid reporting spurious errors
9534
9535 Set_Is_CPP_Class (Def_Id);
9536 return;
9537 end if;
9538 end if;
9539
9540 -- Types treated as CPP classes must be declared limited (note:
9541 -- this used to be a warning but there is no real benefit to it
9542 -- since we did effectively intend to treat the type as limited
9543 -- anyway).
9544
9545 if not Is_Limited_Type (Def_Id) then
9546 Error_Msg_N
9547 ("imported 'C'P'P type must be limited",
9548 Get_Pragma_Arg (Arg2));
9549 end if;
9550
9551 if Etype (Def_Id) /= Def_Id
9552 and then not Is_CPP_Class (Root_Type (Def_Id))
9553 then
9554 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
9555 end if;
9556
9557 Set_Is_CPP_Class (Def_Id);
9558
9559 -- Imported CPP types must not have discriminants (because C++
9560 -- classes do not have discriminants).
9561
9562 if Has_Discriminants (Def_Id) then
9563 Error_Msg_N
9564 ("imported 'C'P'P type cannot have discriminants",
9565 First (Discriminant_Specifications
9566 (Declaration_Node (Def_Id))));
9567 end if;
9568
9569 -- Check that components of imported CPP types do not have default
9570 -- expressions. For private types this check is performed when the
9571 -- full view is analyzed (see Process_Full_View).
9572
9573 if not Is_Private_Type (Def_Id) then
9574 Check_CPP_Type_Has_No_Defaults (Def_Id);
9575 end if;
9576
9577 -- Import a CPP exception
9578
9579 elsif C = Convention_CPP
9580 and then Ekind (Def_Id) = E_Exception
9581 then
9582 if No (Arg3) then
9583 Error_Pragma_Arg
9584 ("'External_'Name arguments is required for 'Cpp exception",
9585 Arg3);
9586 else
9587 -- As only a string is allowed, Check_Arg_Is_External_Name
9588 -- isn't called.
9589
9590 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9591 end if;
9592
9593 if Present (Arg4) then
9594 Error_Pragma_Arg
9595 ("Link_Name argument not allowed for imported Cpp exception",
9596 Arg4);
9597 end if;
9598
9599 -- Do not call Set_Interface_Name as the name of the exception
9600 -- shouldn't be modified (and in particular it shouldn't be
9601 -- the External_Name). For exceptions, the External_Name is the
9602 -- name of the RTTI structure.
9603
9604 -- ??? Emit an error if pragma Import/Export_Exception is present
9605
9606 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
9607 Check_No_Link_Name;
9608 Check_Arg_Count (3);
9609 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9610
9611 Process_Import_Predefined_Type;
9612
9613 -- Emit an error unless Relaxed_RM_Semantics since some legacy Ada
9614 -- compilers may accept more cases, e.g. JGNAT allowed importing
9615 -- a Java package.
9616
9617 elsif not Relaxed_RM_Semantics then
9618 if From_Aspect_Specification (N) then
9619 Error_Pragma_Arg
9620 ("entity for aspect% must be object, subprogram "
9621 & "or incomplete type",
9622 Arg2);
9623 else
9624 Error_Pragma_Arg
9625 ("second argument of pragma% must be object, subprogram "
9626 & "or incomplete type",
9627 Arg2);
9628 end if;
9629 end if;
9630
9631 -- If this pragma applies to a compilation unit, then the unit, which
9632 -- is a subprogram, does not require (or allow) a body. We also do
9633 -- not need to elaborate imported procedures.
9634
9635 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9636 declare
9637 Cunit : constant Node_Id := Parent (Parent (N));
9638 begin
9639 Set_Body_Required (Cunit, False);
9640 end;
9641 end if;
9642 end Process_Import_Or_Interface;
9643
9644 --------------------
9645 -- Process_Inline --
9646 --------------------
9647
9648 procedure Process_Inline (Status : Inline_Status) is
9649 Applies : Boolean;
9650 Assoc : Node_Id;
9651 Decl : Node_Id;
9652 Subp : Entity_Id;
9653 Subp_Id : Node_Id;
9654
9655 Ghost_Error_Posted : Boolean := False;
9656 -- Flag set when an error concerning the illegal mix of Ghost and
9657 -- non-Ghost subprograms is emitted.
9658
9659 Ghost_Id : Entity_Id := Empty;
9660 -- The entity of the first Ghost subprogram encountered while
9661 -- processing the arguments of the pragma.
9662
9663 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id);
9664 -- Verify the placement of pragma Inline_Always with respect to the
9665 -- initial declaration of subprogram Spec_Id.
9666
9667 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
9668 -- Returns True if it can be determined at this stage that inlining
9669 -- is not possible, for example if the body is available and contains
9670 -- exception handlers, we prevent inlining, since otherwise we can
9671 -- get undefined symbols at link time. This function also emits a
9672 -- warning if the pragma appears too late.
9673 --
9674 -- ??? is business with link symbols still valid, or does it relate
9675 -- to front end ZCX which is being phased out ???
9676
9677 procedure Make_Inline (Subp : Entity_Id);
9678 -- Subp is the defining unit name of the subprogram declaration. If
9679 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
9680 -- the corresponding body, if there is one present.
9681
9682 procedure Set_Inline_Flags (Subp : Entity_Id);
9683 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
9684 -- Also set or clear Is_Inlined flag on Subp depending on Status.
9685
9686 -----------------------------------
9687 -- Check_Inline_Always_Placement --
9688 -----------------------------------
9689
9690 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id) is
9691 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id);
9692
9693 function Compilation_Unit_OK return Boolean;
9694 pragma Inline (Compilation_Unit_OK);
9695 -- Determine whether pragma Inline_Always applies to a compatible
9696 -- compilation unit denoted by Spec_Id.
9697
9698 function Declarative_List_OK return Boolean;
9699 pragma Inline (Declarative_List_OK);
9700 -- Determine whether the initial declaration of subprogram Spec_Id
9701 -- and the pragma appear in compatible declarative lists.
9702
9703 function Subprogram_Body_OK return Boolean;
9704 pragma Inline (Subprogram_Body_OK);
9705 -- Determine whether pragma Inline_Always applies to a compatible
9706 -- subprogram body denoted by Spec_Id.
9707
9708 -------------------------
9709 -- Compilation_Unit_OK --
9710 -------------------------
9711
9712 function Compilation_Unit_OK return Boolean is
9713 Comp_Unit : constant Node_Id := Parent (Spec_Decl);
9714
9715 begin
9716 -- The pragma appears after the initial declaration of a
9717 -- compilation unit.
9718
9719 -- procedure Comp_Unit;
9720 -- pragma Inline_Always (Comp_Unit);
9721
9722 -- Note that for compatibility reasons, the following case is
9723 -- also accepted.
9724
9725 -- procedure Stand_Alone_Body_Comp_Unit is
9726 -- ...
9727 -- end Stand_Alone_Body_Comp_Unit;
9728 -- pragma Inline_Always (Stand_Alone_Body_Comp_Unit);
9729
9730 return
9731 Nkind (Comp_Unit) = N_Compilation_Unit
9732 and then Present (Aux_Decls_Node (Comp_Unit))
9733 and then Is_List_Member (N)
9734 and then List_Containing (N) =
9735 Pragmas_After (Aux_Decls_Node (Comp_Unit));
9736 end Compilation_Unit_OK;
9737
9738 -------------------------
9739 -- Declarative_List_OK --
9740 -------------------------
9741
9742 function Declarative_List_OK return Boolean is
9743 Context : constant Node_Id := Parent (Spec_Decl);
9744
9745 Init_Decl : Node_Id;
9746 Init_List : List_Id;
9747 Prag_List : List_Id;
9748
9749 begin
9750 -- Determine the proper initial declaration. In general this is
9751 -- the declaration node of the subprogram except when the input
9752 -- denotes a generic instantiation.
9753
9754 -- procedure Inst is new Gen;
9755 -- pragma Inline_Always (Inst);
9756
9757 -- In this case the original subprogram is moved inside an
9758 -- anonymous package while pragma Inline_Always remains at the
9759 -- level of the anonymous package. Use the declaration of the
9760 -- package because it reflects the placement of the original
9761 -- instantiation.
9762
9763 -- package Anon_Pack is
9764 -- procedure Inst is ... end Inst; -- original
9765 -- end Anon_Pack;
9766
9767 -- procedure Inst renames Anon_Pack.Inst;
9768 -- pragma Inline_Always (Inst);
9769
9770 if Is_Generic_Instance (Spec_Id) then
9771 Init_Decl := Parent (Parent (Spec_Decl));
9772 pragma Assert (Nkind (Init_Decl) = N_Package_Declaration);
9773 else
9774 Init_Decl := Spec_Decl;
9775 end if;
9776
9777 if Is_List_Member (Init_Decl) and then Is_List_Member (N) then
9778 Init_List := List_Containing (Init_Decl);
9779 Prag_List := List_Containing (N);
9780
9781 -- The pragma and then initial declaration appear within the
9782 -- same declarative list.
9783
9784 if Init_List = Prag_List then
9785 return True;
9786
9787 -- A special case of the above is when both the pragma and
9788 -- the initial declaration appear in different lists of a
9789 -- package spec, protected definition, or a task definition.
9790
9791 -- package Pack is
9792 -- procedure Proc;
9793 -- private
9794 -- pragma Inline_Always (Proc);
9795 -- end Pack;
9796
9797 elsif Nkind (Context) in N_Package_Specification
9798 | N_Protected_Definition
9799 | N_Task_Definition
9800 and then Init_List = Visible_Declarations (Context)
9801 and then Prag_List = Private_Declarations (Context)
9802 then
9803 return True;
9804 end if;
9805 end if;
9806
9807 return False;
9808 end Declarative_List_OK;
9809
9810 ------------------------
9811 -- Subprogram_Body_OK --
9812 ------------------------
9813
9814 function Subprogram_Body_OK return Boolean is
9815 Body_Decl : Node_Id;
9816
9817 begin
9818 -- The pragma appears within the declarative list of a stand-
9819 -- alone subprogram body.
9820
9821 -- procedure Stand_Alone_Body is
9822 -- pragma Inline_Always (Stand_Alone_Body);
9823 -- begin
9824 -- ...
9825 -- end Stand_Alone_Body;
9826
9827 -- The compiler creates a dummy spec in this case, however the
9828 -- pragma remains within the declarative list of the body.
9829
9830 if Nkind (Spec_Decl) = N_Subprogram_Declaration
9831 and then not Comes_From_Source (Spec_Decl)
9832 and then Present (Corresponding_Body (Spec_Decl))
9833 then
9834 Body_Decl :=
9835 Unit_Declaration_Node (Corresponding_Body (Spec_Decl));
9836
9837 if Present (Declarations (Body_Decl))
9838 and then Is_List_Member (N)
9839 and then List_Containing (N) = Declarations (Body_Decl)
9840 then
9841 return True;
9842 end if;
9843 end if;
9844
9845 return False;
9846 end Subprogram_Body_OK;
9847
9848 -- Start of processing for Check_Inline_Always_Placement
9849
9850 begin
9851 -- This check is relevant only for pragma Inline_Always
9852
9853 if Pname /= Name_Inline_Always then
9854 return;
9855
9856 -- Nothing to do when the pragma is internally generated on the
9857 -- assumption that it is properly placed.
9858
9859 elsif not Comes_From_Source (N) then
9860 return;
9861
9862 -- Nothing to do for internally generated subprograms that act
9863 -- as accidental homonyms of a source subprogram being inlined.
9864
9865 elsif not Comes_From_Source (Spec_Id) then
9866 return;
9867
9868 -- Nothing to do for generic formal subprograms that act as
9869 -- homonyms of another source subprogram being inlined.
9870
9871 elsif Is_Formal_Subprogram (Spec_Id) then
9872 return;
9873
9874 elsif Compilation_Unit_OK
9875 or else Declarative_List_OK
9876 or else Subprogram_Body_OK
9877 then
9878 return;
9879 end if;
9880
9881 -- At this point it is known that the pragma applies to or appears
9882 -- within a completing body, a completing stub, or a subunit.
9883
9884 Error_Msg_Name_1 := Pname;
9885 Error_Msg_Name_2 := Chars (Spec_Id);
9886 Error_Msg_Sloc := Sloc (Spec_Id);
9887
9888 Error_Msg_N
9889 ("pragma % must appear on initial declaration of subprogram "
9890 & "% defined #", N);
9891 end Check_Inline_Always_Placement;
9892
9893 ---------------------------
9894 -- Inlining_Not_Possible --
9895 ---------------------------
9896
9897 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
9898 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
9899 Stats : Node_Id;
9900
9901 begin
9902 if Nkind (Decl) = N_Subprogram_Body then
9903 Stats := Handled_Statement_Sequence (Decl);
9904 return Present (Exception_Handlers (Stats))
9905 or else Present (At_End_Proc (Stats));
9906
9907 elsif Nkind (Decl) = N_Subprogram_Declaration
9908 and then Present (Corresponding_Body (Decl))
9909 then
9910 if Analyzed (Corresponding_Body (Decl)) then
9911 Error_Msg_N ("pragma appears too late, ignored??", N);
9912 return True;
9913
9914 -- If the subprogram is a renaming as body, the body is just a
9915 -- call to the renamed subprogram, and inlining is trivially
9916 -- possible.
9917
9918 elsif
9919 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
9920 N_Subprogram_Renaming_Declaration
9921 then
9922 return False;
9923
9924 else
9925 Stats :=
9926 Handled_Statement_Sequence
9927 (Unit_Declaration_Node (Corresponding_Body (Decl)));
9928
9929 return
9930 Present (Exception_Handlers (Stats))
9931 or else Present (At_End_Proc (Stats));
9932 end if;
9933
9934 else
9935 -- If body is not available, assume the best, the check is
9936 -- performed again when compiling enclosing package bodies.
9937
9938 return False;
9939 end if;
9940 end Inlining_Not_Possible;
9941
9942 -----------------
9943 -- Make_Inline --
9944 -----------------
9945
9946 procedure Make_Inline (Subp : Entity_Id) is
9947 Kind : constant Entity_Kind := Ekind (Subp);
9948 Inner_Subp : Entity_Id := Subp;
9949
9950 begin
9951 -- Ignore if bad type, avoid cascaded error
9952
9953 if Etype (Subp) = Any_Type then
9954 Applies := True;
9955 return;
9956
9957 -- If inlining is not possible, for now do not treat as an error
9958
9959 elsif Status /= Suppressed
9960 and then Front_End_Inlining
9961 and then Inlining_Not_Possible (Subp)
9962 then
9963 Applies := True;
9964 return;
9965
9966 -- Here we have a candidate for inlining, but we must exclude
9967 -- derived operations. Otherwise we would end up trying to inline
9968 -- a phantom declaration, and the result would be to drag in a
9969 -- body which has no direct inlining associated with it. That
9970 -- would not only be inefficient but would also result in the
9971 -- backend doing cross-unit inlining in cases where it was
9972 -- definitely inappropriate to do so.
9973
9974 -- However, a simple Comes_From_Source test is insufficient, since
9975 -- we do want to allow inlining of generic instances which also do
9976 -- not come from source. We also need to recognize specs generated
9977 -- by the front-end for bodies that carry the pragma. Finally,
9978 -- predefined operators do not come from source but are not
9979 -- inlineable either.
9980
9981 elsif Is_Generic_Instance (Subp)
9982 or else Parent_Kind (Parent (Subp)) = N_Subprogram_Declaration
9983 then
9984 null;
9985
9986 elsif not Comes_From_Source (Subp)
9987 and then Scope (Subp) /= Standard_Standard
9988 then
9989 Applies := True;
9990 return;
9991 end if;
9992
9993 -- The referenced entity must either be the enclosing entity, or
9994 -- an entity declared within the current open scope.
9995
9996 if Present (Scope (Subp))
9997 and then Scope (Subp) /= Current_Scope
9998 and then Subp /= Current_Scope
9999 then
10000 Error_Pragma_Arg
10001 ("argument of% must be entity in current scope", Assoc);
10002 end if;
10003
10004 -- Processing for procedure, operator or function. If subprogram
10005 -- is aliased (as for an instance) indicate that the renamed
10006 -- entity (if declared in the same unit) is inlined.
10007 -- If this is the anonymous subprogram created for a subprogram
10008 -- instance, the inlining applies to it directly. Otherwise we
10009 -- retrieve it as the alias of the visible subprogram instance.
10010
10011 if Is_Subprogram (Subp) then
10012
10013 -- Ensure that pragma Inline_Always is associated with the
10014 -- initial declaration of the subprogram.
10015
10016 Check_Inline_Always_Placement (Subp);
10017
10018 if Is_Wrapper_Package (Scope (Subp)) then
10019 Inner_Subp := Subp;
10020 else
10021 Inner_Subp := Ultimate_Alias (Inner_Subp);
10022 end if;
10023
10024 if In_Same_Source_Unit (Subp, Inner_Subp) then
10025 Set_Inline_Flags (Inner_Subp);
10026
10027 if Present (Parent (Inner_Subp)) then
10028 Decl := Parent (Parent (Inner_Subp));
10029 else
10030 Decl := Empty;
10031 end if;
10032
10033 if Nkind (Decl) = N_Subprogram_Declaration
10034 and then Present (Corresponding_Body (Decl))
10035 then
10036 Set_Inline_Flags (Corresponding_Body (Decl));
10037
10038 elsif Is_Generic_Instance (Subp)
10039 and then Comes_From_Source (Subp)
10040 then
10041 -- Indicate that the body needs to be created for
10042 -- inlining subsequent calls. The instantiation node
10043 -- follows the declaration of the wrapper package
10044 -- created for it. The subprogram that requires the
10045 -- body is the anonymous one in the wrapper package.
10046
10047 if Scope (Subp) /= Standard_Standard
10048 and then
10049 Need_Subprogram_Instance_Body
10050 (Next (Unit_Declaration_Node
10051 (Scope (Alias (Subp)))), Subp)
10052 then
10053 null;
10054 end if;
10055
10056 -- Inline is a program unit pragma (RM 10.1.5) and cannot
10057 -- appear in a formal part to apply to a formal subprogram.
10058 -- Do not apply check within an instance or a formal package
10059 -- the test will have been applied to the original generic.
10060
10061 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
10062 and then In_Same_List (Decl, N)
10063 and then not In_Instance
10064 then
10065 Error_Msg_N
10066 ("Inline cannot apply to a formal subprogram", N);
10067 end if;
10068 end if;
10069
10070 Applies := True;
10071
10072 -- For a generic subprogram set flag as well, for use at the point
10073 -- of instantiation, to determine whether the body should be
10074 -- generated.
10075
10076 elsif Is_Generic_Subprogram (Subp) then
10077 Set_Inline_Flags (Subp);
10078 Applies := True;
10079
10080 -- Literals are by definition inlined
10081
10082 elsif Kind = E_Enumeration_Literal then
10083 null;
10084
10085 -- Anything else is an error
10086
10087 else
10088 Error_Pragma_Arg
10089 ("expect subprogram name for pragma%", Assoc);
10090 end if;
10091 end Make_Inline;
10092
10093 ----------------------
10094 -- Set_Inline_Flags --
10095 ----------------------
10096
10097 procedure Set_Inline_Flags (Subp : Entity_Id) is
10098 begin
10099 -- First set the Has_Pragma_XXX flags and issue the appropriate
10100 -- errors and warnings for suspicious combinations.
10101
10102 if Prag_Id = Pragma_No_Inline then
10103 if Has_Pragma_Inline_Always (Subp) then
10104 Error_Msg_N
10105 ("Inline_Always and No_Inline are mutually exclusive", N);
10106 elsif Has_Pragma_Inline (Subp) then
10107 Error_Msg_NE
10108 ("Inline and No_Inline both specified for& ??",
10109 N, Entity (Subp_Id));
10110 end if;
10111
10112 Set_Has_Pragma_No_Inline (Subp);
10113 else
10114 if Prag_Id = Pragma_Inline_Always then
10115 if Has_Pragma_No_Inline (Subp) then
10116 Error_Msg_N
10117 ("Inline_Always and No_Inline are mutually exclusive",
10118 N);
10119 end if;
10120
10121 Set_Has_Pragma_Inline_Always (Subp);
10122 else
10123 if Has_Pragma_No_Inline (Subp) then
10124 Error_Msg_NE
10125 ("Inline and No_Inline both specified for& ??",
10126 N, Entity (Subp_Id));
10127 end if;
10128 end if;
10129
10130 Set_Has_Pragma_Inline (Subp);
10131 end if;
10132
10133 -- Then adjust the Is_Inlined flag. It can never be set if the
10134 -- subprogram is subject to pragma No_Inline.
10135
10136 case Status is
10137 when Suppressed =>
10138 Set_Is_Inlined (Subp, False);
10139
10140 when Disabled =>
10141 null;
10142
10143 when Enabled =>
10144 if not Has_Pragma_No_Inline (Subp) then
10145 Set_Is_Inlined (Subp, True);
10146 end if;
10147 end case;
10148
10149 -- A pragma that applies to a Ghost entity becomes Ghost for the
10150 -- purposes of legality checks and removal of ignored Ghost code.
10151
10152 Mark_Ghost_Pragma (N, Subp);
10153
10154 -- Capture the entity of the first Ghost subprogram being
10155 -- processed for error detection purposes.
10156
10157 if Is_Ghost_Entity (Subp) then
10158 if No (Ghost_Id) then
10159 Ghost_Id := Subp;
10160 end if;
10161
10162 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
10163 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
10164
10165 elsif Present (Ghost_Id) and then not Ghost_Error_Posted then
10166 Ghost_Error_Posted := True;
10167
10168 Error_Msg_Name_1 := Pname;
10169 Error_Msg_N
10170 ("pragma % cannot mention ghost and non-ghost subprograms",
10171 N);
10172
10173 Error_Msg_Sloc := Sloc (Ghost_Id);
10174 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
10175
10176 Error_Msg_Sloc := Sloc (Subp);
10177 Error_Msg_NE ("\& # declared as non-ghost", N, Subp);
10178 end if;
10179 end Set_Inline_Flags;
10180
10181 -- Start of processing for Process_Inline
10182
10183 begin
10184 -- An inlined subprogram may grant access to its private enclosing
10185 -- context depending on the placement of its body. From elaboration
10186 -- point of view, the flow of execution may enter this private
10187 -- context, and then reach an external unit, thus producing a
10188 -- dependency on that external unit. For such a path to be properly
10189 -- discovered and encoded in the ALI file of the main unit, let the
10190 -- ABE mechanism process the body of the main unit, and encode all
10191 -- relevant invocation constructs and the relations between them.
10192
10193 Mark_Save_Invocation_Graph_Of_Body;
10194
10195 Check_No_Identifiers;
10196 Check_At_Least_N_Arguments (1);
10197
10198 if Status = Enabled then
10199 Inline_Processing_Required := True;
10200 end if;
10201
10202 Assoc := Arg1;
10203 while Present (Assoc) loop
10204 Subp_Id := Get_Pragma_Arg (Assoc);
10205 Analyze (Subp_Id);
10206 Applies := False;
10207
10208 if Is_Entity_Name (Subp_Id) then
10209 Subp := Entity (Subp_Id);
10210
10211 if Subp = Any_Id then
10212
10213 -- If previous error, avoid cascaded errors
10214
10215 Check_Error_Detected;
10216 Applies := True;
10217
10218 else
10219 -- Check for RM 13.1(9.2/4): If a [...] aspect_specification
10220 -- is given that directly specifies an aspect of an entity,
10221 -- then it is illegal to give another [...]
10222 -- aspect_specification that directly specifies the same
10223 -- aspect of the entity.
10224 -- We only check Subp directly as per "directly specifies"
10225 -- above and because the case of pragma Inline is really
10226 -- special given its pre aspect usage.
10227
10228 Check_Duplicate_Pragma (Subp);
10229 Record_Rep_Item (Subp, N);
10230
10231 Make_Inline (Subp);
10232
10233 -- For the pragma case, climb homonym chain. This is
10234 -- what implements allowing the pragma in the renaming
10235 -- case, with the result applying to the ancestors, and
10236 -- also allows Inline to apply to all previous homonyms.
10237
10238 if not From_Aspect_Specification (N) then
10239 while Present (Homonym (Subp))
10240 and then Scope (Homonym (Subp)) = Current_Scope
10241 loop
10242 Subp := Homonym (Subp);
10243 Make_Inline (Subp);
10244 end loop;
10245 end if;
10246 end if;
10247 end if;
10248
10249 if not Applies then
10250 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
10251 end if;
10252
10253 Next (Assoc);
10254 end loop;
10255
10256 -- If the context is a package declaration, the pragma indicates
10257 -- that inlining will require the presence of the corresponding
10258 -- body. (this may be further refined).
10259
10260 if not In_Instance
10261 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
10262 N_Package_Declaration
10263 then
10264 Set_Body_Needed_For_Inlining (Cunit_Entity (Current_Sem_Unit));
10265 end if;
10266 end Process_Inline;
10267
10268 ----------------------------
10269 -- Process_Interface_Name --
10270 ----------------------------
10271
10272 procedure Process_Interface_Name
10273 (Subprogram_Def : Entity_Id;
10274 Ext_Arg : Node_Id;
10275 Link_Arg : Node_Id;
10276 Prag : Node_Id)
10277 is
10278 Ext_Nam : Node_Id;
10279 Link_Nam : Node_Id;
10280 String_Val : String_Id;
10281
10282 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
10283 -- SN is a string literal node for an interface name. This routine
10284 -- performs some minimal checks that the name is reasonable. In
10285 -- particular that no spaces or other obviously incorrect characters
10286 -- appear. This is only a warning, since any characters are allowed.
10287
10288 ----------------------------------
10289 -- Check_Form_Of_Interface_Name --
10290 ----------------------------------
10291
10292 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
10293 S : constant String_Id := Strval (Expr_Value_S (SN));
10294 SL : constant Nat := String_Length (S);
10295 C : Char_Code;
10296
10297 begin
10298 if SL = 0 then
10299 Error_Msg_N ("interface name cannot be null string", SN);
10300 end if;
10301
10302 for J in 1 .. SL loop
10303 C := Get_String_Char (S, J);
10304
10305 -- Look for dubious character and issue unconditional warning.
10306 -- Definitely dubious if not in character range.
10307
10308 if not In_Character_Range (C)
10309
10310 -- Commas, spaces and (back)slashes are dubious
10311
10312 or else Get_Character (C) = ','
10313 or else Get_Character (C) = '\'
10314 or else Get_Character (C) = ' '
10315 or else Get_Character (C) = '/'
10316 then
10317 Error_Msg
10318 ("??interface name contains illegal character",
10319 Sloc (SN) + Source_Ptr (J));
10320 end if;
10321 end loop;
10322 end Check_Form_Of_Interface_Name;
10323
10324 -- Start of processing for Process_Interface_Name
10325
10326 begin
10327 -- If we are looking at a pragma that comes from an aspect then it
10328 -- needs to have its corresponding aspect argument expressions
10329 -- analyzed in addition to the generated pragma so that aspects
10330 -- within generic units get properly resolved.
10331
10332 if Present (Prag) and then From_Aspect_Specification (Prag) then
10333 declare
10334 Asp : constant Node_Id := Corresponding_Aspect (Prag);
10335 Dummy_1 : Node_Id;
10336 Dummy_2 : Node_Id;
10337 Dummy_3 : Node_Id;
10338 EN : Node_Id;
10339 LN : Node_Id;
10340
10341 begin
10342 -- Obtain all interfacing aspects used to construct the pragma
10343
10344 Get_Interfacing_Aspects
10345 (Asp, Dummy_1, EN, Dummy_2, Dummy_3, LN);
10346
10347 -- Analyze the expression of aspect External_Name
10348
10349 if Present (EN) then
10350 Analyze (Expression (EN));
10351 end if;
10352
10353 -- Analyze the expressio of aspect Link_Name
10354
10355 if Present (LN) then
10356 Analyze (Expression (LN));
10357 end if;
10358 end;
10359 end if;
10360
10361 if No (Link_Arg) then
10362 if No (Ext_Arg) then
10363 return;
10364
10365 elsif Chars (Ext_Arg) = Name_Link_Name then
10366 Ext_Nam := Empty;
10367 Link_Nam := Expression (Ext_Arg);
10368
10369 else
10370 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10371 Ext_Nam := Expression (Ext_Arg);
10372 Link_Nam := Empty;
10373 end if;
10374
10375 else
10376 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10377 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
10378 Ext_Nam := Expression (Ext_Arg);
10379 Link_Nam := Expression (Link_Arg);
10380 end if;
10381
10382 -- Check expressions for external name and link name are static
10383
10384 if Present (Ext_Nam) then
10385 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
10386 Check_Form_Of_Interface_Name (Ext_Nam);
10387
10388 -- Verify that external name is not the name of a local entity,
10389 -- which would hide the imported one and could lead to run-time
10390 -- surprises. The problem can only arise for entities declared in
10391 -- a package body (otherwise the external name is fully qualified
10392 -- and will not conflict).
10393
10394 declare
10395 Nam : Name_Id;
10396 E : Entity_Id;
10397 Par : Node_Id;
10398
10399 begin
10400 if Prag_Id = Pragma_Import then
10401 Nam := String_To_Name (Strval (Expr_Value_S (Ext_Nam)));
10402 E := Entity_Id (Get_Name_Table_Int (Nam));
10403
10404 if Nam /= Chars (Subprogram_Def)
10405 and then Present (E)
10406 and then not Is_Overloadable (E)
10407 and then Is_Immediately_Visible (E)
10408 and then not Is_Imported (E)
10409 and then Ekind (Scope (E)) = E_Package
10410 then
10411 Par := Parent (E);
10412 while Present (Par) loop
10413 if Nkind (Par) = N_Package_Body then
10414 Error_Msg_Sloc := Sloc (E);
10415 Error_Msg_NE
10416 ("imported entity is hidden by & declared#",
10417 Ext_Arg, E);
10418 exit;
10419 end if;
10420
10421 Par := Parent (Par);
10422 end loop;
10423 end if;
10424 end if;
10425 end;
10426 end if;
10427
10428 if Present (Link_Nam) then
10429 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
10430 Check_Form_Of_Interface_Name (Link_Nam);
10431 end if;
10432
10433 -- If there is no link name, just set the external name
10434
10435 if No (Link_Nam) then
10436 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
10437
10438 -- For the Link_Name case, the given literal is preceded by an
10439 -- asterisk, which indicates to GCC that the given name should be
10440 -- taken literally, and in particular that no prepending of
10441 -- underlines should occur, even in systems where this is the
10442 -- normal default.
10443
10444 else
10445 Start_String;
10446 Store_String_Char (Get_Char_Code ('*'));
10447 String_Val := Strval (Expr_Value_S (Link_Nam));
10448 Store_String_Chars (String_Val);
10449 Link_Nam :=
10450 Make_String_Literal (Sloc (Link_Nam),
10451 Strval => End_String);
10452 end if;
10453
10454 -- Set the interface name. If the entity is a generic instance, use
10455 -- its alias, which is the callable entity.
10456
10457 if Is_Generic_Instance (Subprogram_Def) then
10458 Set_Encoded_Interface_Name
10459 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
10460 else
10461 Set_Encoded_Interface_Name
10462 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
10463 end if;
10464
10465 Check_Duplicated_Export_Name (Link_Nam);
10466 end Process_Interface_Name;
10467
10468 -----------------------------------------
10469 -- Process_Interrupt_Or_Attach_Handler --
10470 -----------------------------------------
10471
10472 procedure Process_Interrupt_Or_Attach_Handler is
10473 Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
10474 Prot_Typ : constant Entity_Id := Scope (Handler);
10475
10476 begin
10477 -- A pragma that applies to a Ghost entity becomes Ghost for the
10478 -- purposes of legality checks and removal of ignored Ghost code.
10479
10480 Mark_Ghost_Pragma (N, Handler);
10481 Set_Is_Interrupt_Handler (Handler);
10482
10483 pragma Assert (Ekind (Prot_Typ) = E_Protected_Type);
10484
10485 Record_Rep_Item (Prot_Typ, N);
10486
10487 -- Chain the pragma on the contract for completeness
10488
10489 Add_Contract_Item (N, Handler);
10490 end Process_Interrupt_Or_Attach_Handler;
10491
10492 --------------------------------------------------
10493 -- Process_Restrictions_Or_Restriction_Warnings --
10494 --------------------------------------------------
10495
10496 -- Note: some of the simple identifier cases were handled in par-prag,
10497 -- but it is harmless (and more straightforward) to simply handle all
10498 -- cases here, even if it means we repeat a bit of work in some cases.
10499
10500 procedure Process_Restrictions_Or_Restriction_Warnings
10501 (Warn : Boolean)
10502 is
10503 Arg : Node_Id;
10504 R_Id : Restriction_Id;
10505 Id : Name_Id;
10506 Expr : Node_Id;
10507 Val : Uint;
10508
10509 procedure Process_No_Specification_of_Aspect;
10510 -- Process the No_Specification_of_Aspect restriction
10511
10512 procedure Process_No_Use_Of_Attribute;
10513 -- Process the No_Use_Of_Attribute restriction
10514
10515 ----------------------------------------
10516 -- Process_No_Specification_of_Aspect --
10517 ----------------------------------------
10518
10519 procedure Process_No_Specification_of_Aspect is
10520 Name : constant Name_Id := Chars (Expr);
10521 begin
10522 if Nkind (Expr) = N_Identifier
10523 and then Is_Aspect_Id (Name)
10524 then
10525 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
10526 else
10527 Bad_Aspect (Expr, Name, Warn => True);
10528
10529 raise Pragma_Exit;
10530 end if;
10531 end Process_No_Specification_of_Aspect;
10532
10533 ---------------------------------
10534 -- Process_No_Use_Of_Attribute --
10535 ---------------------------------
10536
10537 procedure Process_No_Use_Of_Attribute is
10538 Name : constant Name_Id := Chars (Expr);
10539 begin
10540 if Nkind (Expr) = N_Identifier
10541 and then Is_Attribute_Name (Name)
10542 then
10543 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
10544 else
10545 Bad_Attribute (Expr, Name, Warn => True);
10546 end if;
10547
10548 end Process_No_Use_Of_Attribute;
10549
10550 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
10551
10552 begin
10553 -- Ignore all Restrictions pragmas in CodePeer mode
10554
10555 if CodePeer_Mode then
10556 return;
10557 end if;
10558
10559 Check_Ada_83_Warning;
10560 Check_At_Least_N_Arguments (1);
10561 Check_Valid_Configuration_Pragma;
10562
10563 Arg := Arg1;
10564 while Present (Arg) loop
10565 Id := Chars (Arg);
10566 Expr := Get_Pragma_Arg (Arg);
10567
10568 -- Case of no restriction identifier present
10569
10570 if Id = No_Name then
10571 if Nkind (Expr) /= N_Identifier then
10572 Error_Pragma_Arg
10573 ("invalid form for restriction", Arg);
10574 end if;
10575
10576 R_Id :=
10577 Get_Restriction_Id
10578 (Process_Restriction_Synonyms (Expr));
10579
10580 if R_Id not in All_Boolean_Restrictions then
10581 Error_Msg_Name_1 := Pname;
10582 Error_Msg_N
10583 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
10584
10585 -- Check for possible misspelling
10586
10587 for J in All_Restrictions loop
10588 declare
10589 Rnm : constant String := Restriction_Id'Image (J);
10590
10591 begin
10592 Name_Buffer (1 .. Rnm'Length) := Rnm;
10593 Name_Len := Rnm'Length;
10594 Set_Casing (All_Lower_Case);
10595
10596 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
10597 Set_Casing
10598 (Identifier_Casing
10599 (Source_Index (Current_Sem_Unit)));
10600 Error_Msg_String (1 .. Rnm'Length) :=
10601 Name_Buffer (1 .. Name_Len);
10602 Error_Msg_Strlen := Rnm'Length;
10603 Error_Msg_N -- CODEFIX
10604 ("\possible misspelling of ""~""",
10605 Get_Pragma_Arg (Arg));
10606 exit;
10607 end if;
10608 end;
10609 end loop;
10610
10611 raise Pragma_Exit;
10612 end if;
10613
10614 if Implementation_Restriction (R_Id) then
10615 Check_Restriction (No_Implementation_Restrictions, Arg);
10616 end if;
10617
10618 -- Special processing for No_Elaboration_Code restriction
10619
10620 if R_Id = No_Elaboration_Code then
10621
10622 -- Restriction is only recognized within a configuration
10623 -- pragma file, or within a unit of the main extended
10624 -- program. Note: the test for Main_Unit is needed to
10625 -- properly include the case of configuration pragma files.
10626
10627 if not (Current_Sem_Unit = Main_Unit
10628 or else In_Extended_Main_Source_Unit (N))
10629 then
10630 return;
10631
10632 -- Don't allow in a subunit unless already specified in
10633 -- body or spec.
10634
10635 elsif Nkind (Parent (N)) = N_Compilation_Unit
10636 and then Nkind (Unit (Parent (N))) = N_Subunit
10637 and then not Restriction_Active (No_Elaboration_Code)
10638 then
10639 Error_Msg_N
10640 ("invalid specification of ""No_Elaboration_Code""",
10641 N);
10642 Error_Msg_N
10643 ("\restriction cannot be specified in a subunit", N);
10644 Error_Msg_N
10645 ("\unless also specified in body or spec", N);
10646 return;
10647
10648 -- If we accept a No_Elaboration_Code restriction, then it
10649 -- needs to be added to the configuration restriction set so
10650 -- that we get proper application to other units in the main
10651 -- extended source as required.
10652
10653 else
10654 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
10655 end if;
10656
10657 -- Special processing for No_Dynamic_Accessibility_Checks to
10658 -- disallow exclusive specification in a body or subunit.
10659
10660 elsif R_Id = No_Dynamic_Accessibility_Checks
10661 -- Check if the restriction is within configuration pragma
10662 -- in a similar way to No_Elaboration_Code.
10663
10664 and then not (Current_Sem_Unit = Main_Unit
10665 or else In_Extended_Main_Source_Unit (N))
10666
10667 and then Nkind (Unit (Parent (N))) = N_Compilation_Unit
10668
10669 and then (Nkind (Unit (Parent (N))) = N_Package_Body
10670 or else Nkind (Unit (Parent (N))) = N_Subunit)
10671
10672 and then not Restriction_Active
10673 (No_Dynamic_Accessibility_Checks)
10674 then
10675 Error_Msg_N
10676 ("invalid specification of " &
10677 """No_Dynamic_Accessibility_Checks""", N);
10678
10679 if Nkind (Unit (Parent (N))) = N_Package_Body then
10680 Error_Msg_N
10681 ("\restriction cannot be specified in a package " &
10682 "body", N);
10683
10684 elsif Nkind (Unit (Parent (N))) = N_Subunit then
10685 Error_Msg_N
10686 ("\restriction cannot be specified in a subunit", N);
10687 end if;
10688
10689 Error_Msg_N
10690 ("\unless also specified in spec", N);
10691
10692 -- Special processing for No_Tasking restriction (not just a
10693 -- warning) when it appears as a configuration pragma.
10694
10695 elsif R_Id = No_Tasking
10696 and then No (Cunit (Main_Unit))
10697 and then not Warn
10698 then
10699 Set_Global_No_Tasking;
10700 end if;
10701
10702 Set_Restriction (R_Id, N, Warn);
10703
10704 if R_Id = No_Dynamic_CPU_Assignment
10705 or else R_Id = No_Tasks_Unassigned_To_CPU
10706 then
10707 -- These imply No_Dependence =>
10708 -- "System.Multiprocessors.Dispatching_Domains".
10709 -- This is not strictly what the AI says, but it eliminates
10710 -- the need for run-time checks, which are undesirable in
10711 -- this context.
10712
10713 Set_Restriction_No_Dependence
10714 (Sel_Comp
10715 (Sel_Comp ("system", "multiprocessors", Loc),
10716 "dispatching_domains"),
10717 Warn);
10718 end if;
10719
10720 if R_Id = No_Tasks_Unassigned_To_CPU then
10721 -- Likewise, imply No_Dynamic_CPU_Assignment
10722
10723 Set_Restriction (No_Dynamic_CPU_Assignment, N, Warn);
10724 end if;
10725
10726 -- Check for obsolescent restrictions in Ada 2005 mode
10727
10728 if not Warn
10729 and then Ada_Version >= Ada_2005
10730 and then (R_Id = No_Asynchronous_Control
10731 or else
10732 R_Id = No_Unchecked_Deallocation
10733 or else
10734 R_Id = No_Unchecked_Conversion)
10735 then
10736 Check_Restriction (No_Obsolescent_Features, N);
10737 end if;
10738
10739 -- A very special case that must be processed here: pragma
10740 -- Restrictions (No_Exceptions) turns off all run-time
10741 -- checking. This is a bit dubious in terms of the formal
10742 -- language definition, but it is what is intended by RM
10743 -- H.4(12). Restriction_Warnings never affects generated code
10744 -- so this is done only in the real restriction case.
10745
10746 -- Atomic_Synchronization is not a real check, so it is not
10747 -- affected by this processing).
10748
10749 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
10750 -- run-time checks in CodePeer and GNATprove modes: we want to
10751 -- generate checks for analysis purposes, as set respectively
10752 -- by -gnatC and -gnatd.F
10753
10754 if not Warn
10755 and then not (CodePeer_Mode or GNATprove_Mode)
10756 and then R_Id = No_Exceptions
10757 then
10758 for J in Scope_Suppress.Suppress'Range loop
10759 if J /= Atomic_Synchronization then
10760 Scope_Suppress.Suppress (J) := True;
10761 end if;
10762 end loop;
10763 end if;
10764
10765 -- Case of No_Dependence => unit-name. Note that the parser
10766 -- already made the necessary entry in the No_Dependence table.
10767
10768 elsif Id = Name_No_Dependence then
10769 if not OK_No_Dependence_Unit_Name (Expr) then
10770 raise Pragma_Exit;
10771 end if;
10772
10773 -- Case of No_Specification_Of_Aspect => aspect-identifier
10774
10775 elsif Id = Name_No_Specification_Of_Aspect then
10776 Process_No_Specification_of_Aspect;
10777
10778 -- Case of No_Use_Of_Attribute => attribute-identifier
10779
10780 elsif Id = Name_No_Use_Of_Attribute then
10781 Process_No_Use_Of_Attribute;
10782
10783 -- Case of No_Use_Of_Entity => fully-qualified-name
10784
10785 elsif Id = Name_No_Use_Of_Entity then
10786
10787 -- Restriction is only recognized within a configuration
10788 -- pragma file, or within a unit of the main extended
10789 -- program. Note: the test for Main_Unit is needed to
10790 -- properly include the case of configuration pragma files.
10791
10792 if Current_Sem_Unit = Main_Unit
10793 or else In_Extended_Main_Source_Unit (N)
10794 then
10795 if not OK_No_Dependence_Unit_Name (Expr) then
10796 Error_Msg_N ("wrong form for entity name", Expr);
10797 else
10798 Set_Restriction_No_Use_Of_Entity
10799 (Expr, Warn, No_Profile);
10800 end if;
10801 end if;
10802
10803 -- Case of No_Use_Of_Pragma => pragma-identifier
10804
10805 elsif Id = Name_No_Use_Of_Pragma then
10806 if Nkind (Expr) /= N_Identifier
10807 or else not Is_Pragma_Name (Chars (Expr))
10808 then
10809 Error_Msg_N ("unknown pragma name??", Expr);
10810 else
10811 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
10812 end if;
10813
10814 -- All other cases of restriction identifier present
10815
10816 else
10817 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
10818
10819 if R_Id not in All_Parameter_Restrictions then
10820 Error_Pragma_Arg
10821 ("invalid restriction parameter identifier", Arg);
10822 end if;
10823
10824 Analyze_And_Resolve (Expr, Any_Integer);
10825
10826 if not Is_OK_Static_Expression (Expr) then
10827 Flag_Non_Static_Expr
10828 ("value must be static expression!", Expr);
10829 raise Pragma_Exit;
10830
10831 elsif not Is_Integer_Type (Etype (Expr))
10832 or else Expr_Value (Expr) < 0
10833 then
10834 Error_Pragma_Arg
10835 ("value must be non-negative integer", Arg);
10836 end if;
10837
10838 -- Restriction pragma is active
10839
10840 Val := Expr_Value (Expr);
10841
10842 if not UI_Is_In_Int_Range (Val) then
10843 Error_Pragma_Arg
10844 ("pragma ignored, value too large??", Arg);
10845 end if;
10846
10847 Set_Restriction (R_Id, N, Warn, Integer (UI_To_Int (Val)));
10848 end if;
10849
10850 Next (Arg);
10851 end loop;
10852 end Process_Restrictions_Or_Restriction_Warnings;
10853
10854 ---------------------------------
10855 -- Process_Suppress_Unsuppress --
10856 ---------------------------------
10857
10858 -- Note: this procedure makes entries in the check suppress data
10859 -- structures managed by Sem. See spec of package Sem for full
10860 -- details on how we handle recording of check suppression.
10861
10862 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
10863 C : Check_Id;
10864 E : Entity_Id;
10865 E_Id : Node_Id;
10866
10867 In_Package_Spec : constant Boolean :=
10868 Is_Package_Or_Generic_Package (Current_Scope)
10869 and then not In_Package_Body (Current_Scope);
10870
10871 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
10872 -- Used to suppress a single check on the given entity
10873
10874 --------------------------------
10875 -- Suppress_Unsuppress_Echeck --
10876 --------------------------------
10877
10878 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
10879 begin
10880 -- Check for error of trying to set atomic synchronization for
10881 -- a non-atomic variable.
10882
10883 if C = Atomic_Synchronization
10884 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
10885 then
10886 Error_Msg_N
10887 ("pragma & requires atomic type or variable",
10888 Pragma_Identifier (Original_Node (N)));
10889 end if;
10890
10891 Set_Checks_May_Be_Suppressed (E);
10892
10893 if In_Package_Spec then
10894 Push_Global_Suppress_Stack_Entry
10895 (Entity => E,
10896 Check => C,
10897 Suppress => Suppress_Case);
10898 else
10899 Push_Local_Suppress_Stack_Entry
10900 (Entity => E,
10901 Check => C,
10902 Suppress => Suppress_Case);
10903 end if;
10904
10905 -- If this is a first subtype, and the base type is distinct,
10906 -- then also set the suppress flags on the base type.
10907
10908 if Is_First_Subtype (E) and then Etype (E) /= E then
10909 Suppress_Unsuppress_Echeck (Etype (E), C);
10910 end if;
10911 end Suppress_Unsuppress_Echeck;
10912
10913 -- Start of processing for Process_Suppress_Unsuppress
10914
10915 begin
10916 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
10917 -- on user code: we want to generate checks for analysis purposes, as
10918 -- set respectively by -gnatC and -gnatd.F
10919
10920 if Comes_From_Source (N)
10921 and then (CodePeer_Mode or GNATprove_Mode)
10922 then
10923 return;
10924 end if;
10925
10926 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
10927 -- declarative part or a package spec (RM 11.5(5)).
10928
10929 if not Is_Configuration_Pragma then
10930 Check_Is_In_Decl_Part_Or_Package_Spec;
10931 end if;
10932
10933 Check_At_Least_N_Arguments (1);
10934 Check_At_Most_N_Arguments (2);
10935 Check_No_Identifier (Arg1);
10936 Check_Arg_Is_Identifier (Arg1);
10937
10938 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
10939
10940 if C = No_Check_Id then
10941 Error_Pragma_Arg
10942 ("argument of pragma% is not valid check name", Arg1);
10943 end if;
10944
10945 -- Warn that suppress of Elaboration_Check has no effect in SPARK
10946
10947 if C = Elaboration_Check and then SPARK_Mode = On then
10948 Error_Pragma_Arg
10949 ("Suppress of Elaboration_Check ignored in SPARK??",
10950 "\elaboration checking rules are statically enforced "
10951 & "(SPARK RM 7.7)", Arg1);
10952 end if;
10953
10954 -- One-argument case
10955
10956 if Arg_Count = 1 then
10957
10958 -- Make an entry in the local scope suppress table. This is the
10959 -- table that directly shows the current value of the scope
10960 -- suppress check for any check id value.
10961
10962 if C = All_Checks then
10963
10964 -- For All_Checks, we set all specific predefined checks with
10965 -- the exception of Elaboration_Check, which is handled
10966 -- specially because of not wanting All_Checks to have the
10967 -- effect of deactivating static elaboration order processing.
10968 -- Atomic_Synchronization is also not affected, since this is
10969 -- not a real check.
10970
10971 for J in Scope_Suppress.Suppress'Range loop
10972 if J /= Elaboration_Check
10973 and then
10974 J /= Atomic_Synchronization
10975 then
10976 Scope_Suppress.Suppress (J) := Suppress_Case;
10977 end if;
10978 end loop;
10979
10980 -- If not All_Checks, and predefined check, then set appropriate
10981 -- scope entry. Note that we will set Elaboration_Check if this
10982 -- is explicitly specified. Atomic_Synchronization is allowed
10983 -- only if internally generated and entity is atomic.
10984
10985 elsif C in Predefined_Check_Id
10986 and then (not Comes_From_Source (N)
10987 or else C /= Atomic_Synchronization)
10988 then
10989 Scope_Suppress.Suppress (C) := Suppress_Case;
10990 end if;
10991
10992 -- Also push an entry in the local suppress stack
10993
10994 Push_Local_Suppress_Stack_Entry
10995 (Entity => Empty,
10996 Check => C,
10997 Suppress => Suppress_Case);
10998
10999 -- Case of two arguments present, where the check is suppressed for
11000 -- a specified entity (given as the second argument of the pragma)
11001
11002 else
11003 -- This is obsolescent in Ada 2005 mode
11004
11005 if Ada_Version >= Ada_2005 then
11006 Check_Restriction (No_Obsolescent_Features, Arg2);
11007 end if;
11008
11009 Check_Optional_Identifier (Arg2, Name_On);
11010 E_Id := Get_Pragma_Arg (Arg2);
11011 Analyze (E_Id);
11012
11013 if not Is_Entity_Name (E_Id) then
11014 Error_Pragma_Arg
11015 ("second argument of pragma% must be entity name", Arg2);
11016 end if;
11017
11018 E := Entity (E_Id);
11019
11020 if E = Any_Id then
11021 return;
11022 end if;
11023
11024 -- A pragma that applies to a Ghost entity becomes Ghost for the
11025 -- purposes of legality checks and removal of ignored Ghost code.
11026
11027 Mark_Ghost_Pragma (N, E);
11028
11029 -- Enforce RM 11.5(7) which requires that for a pragma that
11030 -- appears within a package spec, the named entity must be
11031 -- within the package spec. We allow the package name itself
11032 -- to be mentioned since that makes sense, although it is not
11033 -- strictly allowed by 11.5(7).
11034
11035 if In_Package_Spec
11036 and then E /= Current_Scope
11037 and then Scope (E) /= Current_Scope
11038 then
11039 Error_Pragma_Arg
11040 ("entity in pragma% is not in package spec (RM 11.5(7))",
11041 Arg2);
11042 end if;
11043
11044 -- Loop through homonyms. As noted below, in the case of a package
11045 -- spec, only homonyms within the package spec are considered.
11046
11047 loop
11048 Suppress_Unsuppress_Echeck (E, C);
11049
11050 if Is_Generic_Instance (E)
11051 and then Is_Subprogram (E)
11052 and then Present (Alias (E))
11053 then
11054 Suppress_Unsuppress_Echeck (Alias (E), C);
11055 end if;
11056
11057 -- Move to next homonym if not aspect spec case
11058
11059 exit when From_Aspect_Specification (N);
11060 E := Homonym (E);
11061 exit when No (E);
11062
11063 -- If we are within a package specification, the pragma only
11064 -- applies to homonyms in the same scope.
11065
11066 exit when In_Package_Spec
11067 and then Scope (E) /= Current_Scope;
11068 end loop;
11069 end if;
11070 end Process_Suppress_Unsuppress;
11071
11072 -------------------------------
11073 -- Record_Independence_Check --
11074 -------------------------------
11075
11076 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
11077 pragma Unreferenced (N, E);
11078 begin
11079 -- For GCC back ends the validation is done a priori. This code is
11080 -- dead, but might be useful in the future.
11081
11082 -- if not AAMP_On_Target then
11083 -- return;
11084 -- end if;
11085
11086 -- Independence_Checks.Append ((N, E));
11087
11088 return;
11089 end Record_Independence_Check;
11090
11091 ------------------
11092 -- Set_Exported --
11093 ------------------
11094
11095 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
11096 begin
11097 if Is_Imported (E) then
11098 Error_Pragma_Arg
11099 ("cannot export entity& that was previously imported", Arg);
11100
11101 elsif Present (Address_Clause (E))
11102 and then not Relaxed_RM_Semantics
11103 then
11104 Error_Pragma_Arg
11105 ("cannot export entity& that has an address clause", Arg);
11106 end if;
11107
11108 Set_Is_Exported (E);
11109
11110 -- Generate a reference for entity explicitly, because the
11111 -- identifier may be overloaded and name resolution will not
11112 -- generate one.
11113
11114 Generate_Reference (E, Arg);
11115
11116 -- Deal with exporting non-library level entity
11117
11118 if not Is_Library_Level_Entity (E) then
11119
11120 -- Not allowed at all for subprograms
11121
11122 if Is_Subprogram (E) then
11123 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
11124
11125 -- Otherwise set public and statically allocated
11126
11127 else
11128 Set_Is_Public (E);
11129 Set_Is_Statically_Allocated (E);
11130
11131 -- Warn if the corresponding W flag is set
11132
11133 if Warn_On_Export_Import
11134
11135 -- Only do this for something that was in the source. Not
11136 -- clear if this can be False now (there used for sure to be
11137 -- cases on some systems where it was False), but anyway the
11138 -- test is harmless if not needed, so it is retained.
11139
11140 and then Comes_From_Source (Arg)
11141 then
11142 Error_Msg_NE
11143 ("?x?& has been made static as a result of Export",
11144 Arg, E);
11145 Error_Msg_N
11146 ("\?x?this usage is non-standard and non-portable",
11147 Arg);
11148 end if;
11149 end if;
11150 end if;
11151
11152 if Warn_On_Export_Import and Inside_A_Generic then
11153 Error_Msg_NE
11154 ("all instances of& will have the same external name?x?",
11155 Arg, E);
11156 end if;
11157 end Set_Exported;
11158
11159 ----------------------------------------------
11160 -- Set_Extended_Import_Export_External_Name --
11161 ----------------------------------------------
11162
11163 procedure Set_Extended_Import_Export_External_Name
11164 (Internal_Ent : Entity_Id;
11165 Arg_External : Node_Id)
11166 is
11167 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
11168 New_Name : Node_Id;
11169
11170 begin
11171 if No (Arg_External) then
11172 return;
11173 end if;
11174
11175 Check_Arg_Is_External_Name (Arg_External);
11176
11177 if Nkind (Arg_External) = N_String_Literal then
11178 if String_Length (Strval (Arg_External)) = 0 then
11179 return;
11180 else
11181 New_Name := Adjust_External_Name_Case (Arg_External);
11182 end if;
11183
11184 elsif Nkind (Arg_External) = N_Identifier then
11185 New_Name := Get_Default_External_Name (Arg_External);
11186
11187 -- Check_Arg_Is_External_Name should let through only identifiers and
11188 -- string literals or static string expressions (which are folded to
11189 -- string literals).
11190
11191 else
11192 raise Program_Error;
11193 end if;
11194
11195 -- If we already have an external name set (by a prior normal Import
11196 -- or Export pragma), then the external names must match
11197
11198 if Present (Interface_Name (Internal_Ent)) then
11199
11200 -- Ignore mismatching names in CodePeer mode, to support some
11201 -- old compilers which would export the same procedure under
11202 -- different names, e.g:
11203 -- procedure P;
11204 -- pragma Export_Procedure (P, "a");
11205 -- pragma Export_Procedure (P, "b");
11206
11207 if CodePeer_Mode then
11208 return;
11209 end if;
11210
11211 Check_Matching_Internal_Names : declare
11212 S1 : constant String_Id := Strval (Old_Name);
11213 S2 : constant String_Id := Strval (New_Name);
11214
11215 procedure Mismatch;
11216 pragma No_Return (Mismatch);
11217 -- Called if names do not match
11218
11219 --------------
11220 -- Mismatch --
11221 --------------
11222
11223 procedure Mismatch is
11224 begin
11225 Error_Msg_Sloc := Sloc (Old_Name);
11226 Error_Pragma_Arg
11227 ("external name does not match that given #",
11228 Arg_External);
11229 end Mismatch;
11230
11231 -- Start of processing for Check_Matching_Internal_Names
11232
11233 begin
11234 if String_Length (S1) /= String_Length (S2) then
11235 Mismatch;
11236
11237 else
11238 for J in 1 .. String_Length (S1) loop
11239 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
11240 Mismatch;
11241 end if;
11242 end loop;
11243 end if;
11244 end Check_Matching_Internal_Names;
11245
11246 -- Otherwise set the given name
11247
11248 else
11249 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
11250 Check_Duplicated_Export_Name (New_Name);
11251 end if;
11252 end Set_Extended_Import_Export_External_Name;
11253
11254 ------------------
11255 -- Set_Imported --
11256 ------------------
11257
11258 procedure Set_Imported (E : Entity_Id) is
11259 begin
11260 -- Error message if already imported or exported
11261
11262 if Is_Exported (E) or else Is_Imported (E) then
11263
11264 -- Error if being set Exported twice
11265
11266 if Is_Exported (E) then
11267 Error_Msg_NE ("entity& was previously exported", N, E);
11268
11269 -- Ignore error in CodePeer mode where we treat all imported
11270 -- subprograms as unknown.
11271
11272 elsif CodePeer_Mode then
11273 goto OK;
11274
11275 -- OK if Import/Interface case
11276
11277 elsif Import_Interface_Present (N) then
11278 goto OK;
11279
11280 -- Error if being set Imported twice
11281
11282 else
11283 Error_Msg_NE ("entity& was previously imported", N, E);
11284 end if;
11285
11286 Error_Msg_Name_1 := Pname;
11287 Error_Msg_N
11288 ("\(pragma% applies to all previous entities)", N);
11289
11290 Error_Msg_Sloc := Sloc (E);
11291 Error_Msg_NE ("\import not allowed for& declared#", N, E);
11292
11293 -- Here if not previously imported or exported, OK to import
11294
11295 else
11296 Set_Is_Imported (E);
11297
11298 -- For subprogram, set Import_Pragma field
11299
11300 if Is_Subprogram (E) then
11301 Set_Import_Pragma (E, N);
11302 end if;
11303
11304 -- If the entity is an object that is not at the library level,
11305 -- then it is statically allocated. We do not worry about objects
11306 -- with address clauses in this context since they are not really
11307 -- imported in the linker sense.
11308
11309 if Is_Object (E)
11310 and then not Is_Library_Level_Entity (E)
11311 and then No (Address_Clause (E))
11312 then
11313 Set_Is_Statically_Allocated (E);
11314 end if;
11315 end if;
11316
11317 <<OK>> null;
11318 end Set_Imported;
11319
11320 -------------------------
11321 -- Set_Mechanism_Value --
11322 -------------------------
11323
11324 -- Note: the mechanism name has not been analyzed (and cannot indeed be
11325 -- analyzed, since it is semantic nonsense), so we get it in the exact
11326 -- form created by the parser.
11327
11328 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
11329 procedure Bad_Mechanism;
11330 pragma No_Return (Bad_Mechanism);
11331 -- Signal bad mechanism name
11332
11333 -------------------
11334 -- Bad_Mechanism --
11335 -------------------
11336
11337 procedure Bad_Mechanism is
11338 begin
11339 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
11340 end Bad_Mechanism;
11341
11342 -- Start of processing for Set_Mechanism_Value
11343
11344 begin
11345 if Mechanism (Ent) /= Default_Mechanism then
11346 Error_Msg_NE
11347 ("mechanism for & has already been set", Mech_Name, Ent);
11348 end if;
11349
11350 -- MECHANISM_NAME ::= value | reference
11351
11352 if Nkind (Mech_Name) = N_Identifier then
11353 if Chars (Mech_Name) = Name_Value then
11354 Set_Mechanism (Ent, By_Copy);
11355 return;
11356
11357 elsif Chars (Mech_Name) = Name_Reference then
11358 Set_Mechanism (Ent, By_Reference);
11359 return;
11360
11361 elsif Chars (Mech_Name) = Name_Copy then
11362 Error_Pragma_Arg
11363 ("bad mechanism name, Value assumed", Mech_Name);
11364
11365 else
11366 Bad_Mechanism;
11367 end if;
11368
11369 else
11370 Bad_Mechanism;
11371 end if;
11372 end Set_Mechanism_Value;
11373
11374 --------------------------
11375 -- Set_Rational_Profile --
11376 --------------------------
11377
11378 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
11379 -- extension to the semantics of renaming declarations.
11380
11381 procedure Set_Rational_Profile is
11382 begin
11383 Implicit_Packing := True;
11384 Overriding_Renamings := True;
11385 Use_VADS_Size := True;
11386 end Set_Rational_Profile;
11387
11388 ---------------------------
11389 -- Set_Ravenscar_Profile --
11390 ---------------------------
11391
11392 -- The tasks to be done here are
11393
11394 -- Set required policies
11395
11396 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11397 -- (For Ravenscar, Jorvik, and GNAT_Extended_Ravenscar profiles)
11398 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11399 -- (For GNAT_Ravenscar_EDF profile)
11400 -- pragma Locking_Policy (Ceiling_Locking)
11401
11402 -- Set Detect_Blocking mode
11403
11404 -- Set required restrictions (see System.Rident for detailed list)
11405
11406 -- Set the No_Dependence rules
11407 -- No_Dependence => Ada.Asynchronous_Task_Control
11408 -- No_Dependence => Ada.Calendar
11409 -- No_Dependence => Ada.Execution_Time.Group_Budget
11410 -- No_Dependence => Ada.Execution_Time.Timers
11411 -- No_Dependence => Ada.Task_Attributes
11412 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11413
11414 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is
11415 procedure Set_Error_Msg_To_Profile_Name;
11416 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
11417 -- profile.
11418
11419 -----------------------------------
11420 -- Set_Error_Msg_To_Profile_Name --
11421 -----------------------------------
11422
11423 procedure Set_Error_Msg_To_Profile_Name is
11424 Prof_Nam : constant Node_Id :=
11425 Get_Pragma_Arg
11426 (First (Pragma_Argument_Associations (N)));
11427
11428 begin
11429 Get_Name_String (Chars (Prof_Nam));
11430 Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam));
11431 Error_Msg_Strlen := Name_Len;
11432 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
11433 end Set_Error_Msg_To_Profile_Name;
11434
11435 Profile_Dispatching_Policy : Character;
11436
11437 -- Start of processing for Set_Ravenscar_Profile
11438
11439 begin
11440 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11441
11442 if Profile = GNAT_Ravenscar_EDF then
11443 Profile_Dispatching_Policy := 'E';
11444
11445 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11446
11447 else
11448 Profile_Dispatching_Policy := 'F';
11449 end if;
11450
11451 if Task_Dispatching_Policy /= ' '
11452 and then Task_Dispatching_Policy /= Profile_Dispatching_Policy
11453 then
11454 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11455 Set_Error_Msg_To_Profile_Name;
11456 Error_Pragma ("Profile (~) incompatible with policy#");
11457
11458 -- Set the FIFO_Within_Priorities policy, but always preserve
11459 -- System_Location since we like the error message with the run time
11460 -- name.
11461
11462 else
11463 Task_Dispatching_Policy := Profile_Dispatching_Policy;
11464
11465 if Task_Dispatching_Policy_Sloc /= System_Location then
11466 Task_Dispatching_Policy_Sloc := Loc;
11467 end if;
11468 end if;
11469
11470 -- pragma Locking_Policy (Ceiling_Locking)
11471
11472 if Locking_Policy /= ' '
11473 and then Locking_Policy /= 'C'
11474 then
11475 Error_Msg_Sloc := Locking_Policy_Sloc;
11476 Set_Error_Msg_To_Profile_Name;
11477 Error_Pragma ("Profile (~) incompatible with policy#");
11478
11479 -- Set the Ceiling_Locking policy, but preserve System_Location since
11480 -- we like the error message with the run time name.
11481
11482 else
11483 Locking_Policy := 'C';
11484
11485 if Locking_Policy_Sloc /= System_Location then
11486 Locking_Policy_Sloc := Loc;
11487 end if;
11488 end if;
11489
11490 -- pragma Detect_Blocking
11491
11492 Detect_Blocking := True;
11493
11494 -- Set the corresponding restrictions
11495
11496 Set_Profile_Restrictions
11497 (Profile, N, Warn => Treat_Restrictions_As_Warnings);
11498
11499 -- Set the No_Dependence restrictions
11500
11501 -- The following No_Dependence restrictions:
11502 -- No_Dependence => Ada.Asynchronous_Task_Control
11503 -- No_Dependence => Ada.Calendar
11504 -- No_Dependence => Ada.Task_Attributes
11505 -- are already set by previous call to Set_Profile_Restrictions.
11506 -- Really???
11507
11508 -- Set the following restrictions which were added to Ada 2005:
11509 -- No_Dependence => Ada.Execution_Time.Group_Budget
11510 -- No_Dependence => Ada.Execution_Time.Timers
11511
11512 if Ada_Version >= Ada_2005 then
11513 declare
11514 Execution_Time : constant Node_Id :=
11515 Sel_Comp ("ada", "execution_time", Loc);
11516 Group_Budgets : constant Node_Id :=
11517 Sel_Comp (Execution_Time, "group_budgets");
11518 Timers : constant Node_Id :=
11519 Sel_Comp (Execution_Time, "timers");
11520 begin
11521 Set_Restriction_No_Dependence
11522 (Unit => Group_Budgets,
11523 Warn => Treat_Restrictions_As_Warnings,
11524 Profile => Ravenscar);
11525 Set_Restriction_No_Dependence
11526 (Unit => Timers,
11527 Warn => Treat_Restrictions_As_Warnings,
11528 Profile => Ravenscar);
11529 end;
11530 end if;
11531
11532 -- Set the following restriction which was added to Ada 2012 (see
11533 -- AI05-0171):
11534 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11535
11536 if Ada_Version >= Ada_2012 then
11537 Set_Restriction_No_Dependence
11538 (Sel_Comp
11539 (Sel_Comp ("system", "multiprocessors", Loc),
11540 "dispatching_domains"),
11541 Warn => Treat_Restrictions_As_Warnings,
11542 Profile => Ravenscar);
11543
11544 -- Set the following restriction which was added to Ada 2022,
11545 -- but as a binding interpretation:
11546 -- No_Dependence => Ada.Synchronous_Barriers
11547 -- for Ravenscar (and therefore for Ravenscar variants) but not
11548 -- for Jorvik. The unit Ada.Synchronous_Barriers was introduced
11549 -- in Ada2012 (AI05-0174).
11550
11551 if Profile /= Jorvik then
11552 Set_Restriction_No_Dependence
11553 (Sel_Comp ("ada", "synchronous_barriers", Loc),
11554 Warn => Treat_Restrictions_As_Warnings,
11555 Profile => Ravenscar);
11556 end if;
11557 end if;
11558
11559 end Set_Ravenscar_Profile;
11560
11561 -- Start of processing for Analyze_Pragma
11562
11563 begin
11564 -- The following code is a defense against recursion. Not clear that
11565 -- this can happen legitimately, but perhaps some error situations can
11566 -- cause it, and we did see this recursion during testing.
11567
11568 if Analyzed (N) then
11569 return;
11570 else
11571 Set_Analyzed (N);
11572 end if;
11573
11574 Check_Restriction_No_Use_Of_Pragma (N);
11575
11576 if Is_Aspect_Id (Chars (Pragma_Identifier (N))) then
11577 -- 6.1/3 No_Specification_of_Aspect: Identifies an aspect for which
11578 -- no aspect_specification, attribute_definition_clause, or pragma
11579 -- is given.
11580 Check_Restriction_No_Specification_Of_Aspect (N);
11581 end if;
11582
11583 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
11584 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
11585
11586 if Should_Ignore_Pragma_Sem (N)
11587 or else (Prag_Id = Pragma_Default_Scalar_Storage_Order
11588 and then Ignore_Rep_Clauses)
11589 then
11590 return;
11591 end if;
11592
11593 -- Deal with unrecognized pragma
11594
11595 if not Is_Pragma_Name (Pname) then
11596 declare
11597 Msg_Issued : Boolean := False;
11598 begin
11599 Check_Restriction
11600 (Msg_Issued, No_Unrecognized_Pragmas, Pragma_Identifier (N));
11601 if not Msg_Issued and then Warn_On_Unrecognized_Pragma then
11602 Error_Msg_Name_1 := Pname;
11603 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
11604
11605 for PN in First_Pragma_Name .. Last_Pragma_Name loop
11606 if Is_Bad_Spelling_Of (Pname, PN) then
11607 Error_Msg_Name_1 := PN;
11608 Error_Msg_N -- CODEFIX
11609 ("\?g?possible misspelling of %!",
11610 Pragma_Identifier (N));
11611 exit;
11612 end if;
11613 end loop;
11614 end if;
11615 end;
11616
11617 return;
11618 end if;
11619
11620 -- Here to start processing for recognized pragma
11621
11622 Pname := Original_Aspect_Pragma_Name (N);
11623
11624 -- Capture setting of Opt.Uneval_Old
11625
11626 case Opt.Uneval_Old is
11627 when 'A' =>
11628 Set_Uneval_Old_Accept (N);
11629
11630 when 'E' =>
11631 null;
11632
11633 when 'W' =>
11634 Set_Uneval_Old_Warn (N);
11635
11636 when others =>
11637 raise Program_Error;
11638 end case;
11639
11640 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
11641 -- is already set, indicating that we have already checked the policy
11642 -- at the right point. This happens for example in the case of a pragma
11643 -- that is derived from an Aspect.
11644
11645 if Is_Ignored (N) or else Is_Checked (N) then
11646 null;
11647
11648 -- For a pragma that is a rewriting of another pragma, copy the
11649 -- Is_Checked/Is_Ignored status from the rewritten pragma.
11650
11651 elsif Is_Rewrite_Substitution (N)
11652 and then Nkind (Original_Node (N)) = N_Pragma
11653 then
11654 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
11655 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
11656
11657 -- Otherwise query the applicable policy at this point
11658
11659 else
11660 Check_Applicable_Policy (N);
11661
11662 -- If pragma is disabled, rewrite as NULL and skip analysis
11663
11664 if Is_Disabled (N) then
11665 Rewrite (N, Make_Null_Statement (Loc));
11666 Analyze (N);
11667 raise Pragma_Exit;
11668 end if;
11669 end if;
11670
11671 -- Mark assertion pragmas as Ghost depending on their enclosing context
11672
11673 if Assertion_Expression_Pragma (Prag_Id) then
11674 Mark_Ghost_Pragma (N, Current_Scope);
11675 end if;
11676
11677 -- Preset arguments
11678
11679 Arg_Count := 0;
11680 Arg1 := Empty;
11681 Arg2 := Empty;
11682 Arg3 := Empty;
11683 Arg4 := Empty;
11684 Arg5 := Empty;
11685
11686 if Present (Pragma_Argument_Associations (N)) then
11687 Arg_Count := List_Length (Pragma_Argument_Associations (N));
11688 Arg1 := First (Pragma_Argument_Associations (N));
11689
11690 if Present (Arg1) then
11691 Arg2 := Next (Arg1);
11692
11693 if Present (Arg2) then
11694 Arg3 := Next (Arg2);
11695
11696 if Present (Arg3) then
11697 Arg4 := Next (Arg3);
11698
11699 if Present (Arg4) then
11700 Arg5 := Next (Arg4);
11701 end if;
11702 end if;
11703 end if;
11704 end if;
11705 end if;
11706
11707 -- An enumeration type defines the pragmas that are supported by the
11708 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
11709 -- into the corresponding enumeration value for the following case.
11710
11711 case Prag_Id is
11712
11713 -----------------
11714 -- Abort_Defer --
11715 -----------------
11716
11717 -- pragma Abort_Defer;
11718
11719 when Pragma_Abort_Defer =>
11720 GNAT_Pragma;
11721 Check_Arg_Count (0);
11722
11723 -- The only required semantic processing is to check the
11724 -- placement. This pragma must appear at the start of the
11725 -- statement sequence of a handled sequence of statements.
11726
11727 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
11728 or else N /= First (Statements (Parent (N)))
11729 then
11730 Pragma_Misplaced;
11731 end if;
11732
11733 --------------------
11734 -- Abstract_State --
11735 --------------------
11736
11737 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
11738
11739 -- ABSTRACT_STATE_LIST ::=
11740 -- null
11741 -- | STATE_NAME_WITH_OPTIONS
11742 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
11743
11744 -- STATE_NAME_WITH_OPTIONS ::=
11745 -- STATE_NAME
11746 -- | (STATE_NAME with OPTION_LIST)
11747
11748 -- OPTION_LIST ::= OPTION {, OPTION}
11749
11750 -- OPTION ::=
11751 -- SIMPLE_OPTION
11752 -- | NAME_VALUE_OPTION
11753
11754 -- SIMPLE_OPTION ::= Ghost | Relaxed_Initialization | Synchronous
11755
11756 -- NAME_VALUE_OPTION ::=
11757 -- Part_Of => ABSTRACT_STATE
11758 -- | External [=> EXTERNAL_PROPERTY_LIST]
11759
11760 -- EXTERNAL_PROPERTY_LIST ::=
11761 -- EXTERNAL_PROPERTY
11762 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
11763
11764 -- EXTERNAL_PROPERTY ::=
11765 -- Async_Readers [=> boolean_EXPRESSION]
11766 -- | Async_Writers [=> boolean_EXPRESSION]
11767 -- | Effective_Reads [=> boolean_EXPRESSION]
11768 -- | Effective_Writes [=> boolean_EXPRESSION]
11769 -- others => boolean_EXPRESSION
11770
11771 -- STATE_NAME ::= defining_identifier
11772
11773 -- ABSTRACT_STATE ::= name
11774
11775 -- Characteristics:
11776
11777 -- * Analysis - The annotation is fully analyzed immediately upon
11778 -- elaboration as it cannot forward reference entities.
11779
11780 -- * Expansion - None.
11781
11782 -- * Template - The annotation utilizes the generic template of the
11783 -- related package declaration.
11784
11785 -- * Globals - The annotation cannot reference global entities.
11786
11787 -- * Instance - The annotation is instantiated automatically when
11788 -- the related generic package is instantiated.
11789
11790 when Pragma_Abstract_State => Abstract_State : declare
11791 Missing_Parentheses : Boolean := False;
11792 -- Flag set when a state declaration with options is not properly
11793 -- parenthesized.
11794
11795 -- Flags used to verify the consistency of states
11796
11797 Non_Null_Seen : Boolean := False;
11798 Null_Seen : Boolean := False;
11799
11800 procedure Analyze_Abstract_State
11801 (State : Node_Id;
11802 Pack_Id : Entity_Id);
11803 -- Verify the legality of a single state declaration. Create and
11804 -- decorate a state abstraction entity and introduce it into the
11805 -- visibility chain. Pack_Id denotes the entity or the related
11806 -- package where pragma Abstract_State appears.
11807
11808 procedure Malformed_State_Error (State : Node_Id);
11809 -- Emit an error concerning the illegal declaration of abstract
11810 -- state State. This routine diagnoses syntax errors that lead to
11811 -- a different parse tree. The error is issued regardless of the
11812 -- SPARK mode in effect.
11813
11814 ----------------------------
11815 -- Analyze_Abstract_State --
11816 ----------------------------
11817
11818 procedure Analyze_Abstract_State
11819 (State : Node_Id;
11820 Pack_Id : Entity_Id)
11821 is
11822 -- Flags used to verify the consistency of options
11823
11824 AR_Seen : Boolean := False;
11825 AW_Seen : Boolean := False;
11826 ER_Seen : Boolean := False;
11827 EW_Seen : Boolean := False;
11828 External_Seen : Boolean := False;
11829 Ghost_Seen : Boolean := False;
11830 Others_Seen : Boolean := False;
11831 Part_Of_Seen : Boolean := False;
11832 Relaxed_Initialization_Seen : Boolean := False;
11833 Synchronous_Seen : Boolean := False;
11834
11835 -- Flags used to store the static value of all external states'
11836 -- expressions.
11837
11838 AR_Val : Boolean := False;
11839 AW_Val : Boolean := False;
11840 ER_Val : Boolean := False;
11841 EW_Val : Boolean := False;
11842
11843 State_Id : Entity_Id := Empty;
11844 -- The entity to be generated for the current state declaration
11845
11846 procedure Analyze_External_Option (Opt : Node_Id);
11847 -- Verify the legality of option External
11848
11849 procedure Analyze_External_Property
11850 (Prop : Node_Id;
11851 Expr : Node_Id := Empty);
11852 -- Verify the legailty of a single external property. Prop
11853 -- denotes the external property. Expr is the expression used
11854 -- to set the property.
11855
11856 procedure Analyze_Part_Of_Option (Opt : Node_Id);
11857 -- Verify the legality of option Part_Of
11858
11859 procedure Check_Duplicate_Option
11860 (Opt : Node_Id;
11861 Status : in out Boolean);
11862 -- Flag Status denotes whether a particular option has been
11863 -- seen while processing a state. This routine verifies that
11864 -- Opt is not a duplicate option and sets the flag Status
11865 -- (SPARK RM 7.1.4(1)).
11866
11867 procedure Check_Duplicate_Property
11868 (Prop : Node_Id;
11869 Status : in out Boolean);
11870 -- Flag Status denotes whether a particular property has been
11871 -- seen while processing option External. This routine verifies
11872 -- that Prop is not a duplicate property and sets flag Status.
11873 -- Opt is not a duplicate property and sets the flag Status.
11874 -- (SPARK RM 7.1.4(2))
11875
11876 procedure Check_Ghost_Synchronous;
11877 -- Ensure that the abstract state is not subject to both Ghost
11878 -- and Synchronous simple options. Emit an error if this is the
11879 -- case.
11880
11881 procedure Create_Abstract_State
11882 (Nam : Name_Id;
11883 Decl : Node_Id;
11884 Loc : Source_Ptr;
11885 Is_Null : Boolean);
11886 -- Generate an abstract state entity with name Nam and enter it
11887 -- into visibility. Decl is the "declaration" of the state as
11888 -- it appears in pragma Abstract_State. Loc is the location of
11889 -- the related state "declaration". Flag Is_Null should be set
11890 -- when the associated Abstract_State pragma defines a null
11891 -- state.
11892
11893 -----------------------------
11894 -- Analyze_External_Option --
11895 -----------------------------
11896
11897 procedure Analyze_External_Option (Opt : Node_Id) is
11898 Errors : constant Nat := Serious_Errors_Detected;
11899 Prop : Node_Id;
11900 Props : Node_Id := Empty;
11901
11902 begin
11903 if Nkind (Opt) = N_Component_Association then
11904 Props := Expression (Opt);
11905 end if;
11906
11907 -- External state with properties
11908
11909 if Present (Props) then
11910
11911 -- Multiple properties appear as an aggregate
11912
11913 if Nkind (Props) = N_Aggregate then
11914
11915 -- Simple property form
11916
11917 Prop := First (Expressions (Props));
11918 while Present (Prop) loop
11919 Analyze_External_Property (Prop);
11920 Next (Prop);
11921 end loop;
11922
11923 -- Property with expression form
11924
11925 Prop := First (Component_Associations (Props));
11926 while Present (Prop) loop
11927 Analyze_External_Property
11928 (Prop => First (Choices (Prop)),
11929 Expr => Expression (Prop));
11930
11931 Next (Prop);
11932 end loop;
11933
11934 -- Single property
11935
11936 else
11937 Analyze_External_Property (Props);
11938 end if;
11939
11940 -- An external state defined without any properties defaults
11941 -- all properties to True.
11942
11943 else
11944 AR_Val := True;
11945 AW_Val := True;
11946 ER_Val := True;
11947 EW_Val := True;
11948 end if;
11949
11950 -- Once all external properties have been processed, verify
11951 -- their mutual interaction. Do not perform the check when
11952 -- at least one of the properties is illegal as this will
11953 -- produce a bogus error.
11954
11955 if Errors = Serious_Errors_Detected then
11956 Check_External_Properties
11957 (State, AR_Val, AW_Val, ER_Val, EW_Val);
11958 end if;
11959 end Analyze_External_Option;
11960
11961 -------------------------------
11962 -- Analyze_External_Property --
11963 -------------------------------
11964
11965 procedure Analyze_External_Property
11966 (Prop : Node_Id;
11967 Expr : Node_Id := Empty)
11968 is
11969 Expr_Val : Boolean;
11970
11971 begin
11972 -- Check the placement of "others" (if available)
11973
11974 if Nkind (Prop) = N_Others_Choice then
11975 if Others_Seen then
11976 SPARK_Msg_N
11977 ("only one OTHERS choice allowed in option External",
11978 Prop);
11979 else
11980 Others_Seen := True;
11981 end if;
11982
11983 elsif Others_Seen then
11984 SPARK_Msg_N
11985 ("OTHERS must be the last property in option External",
11986 Prop);
11987
11988 -- The only remaining legal options are the four predefined
11989 -- external properties.
11990
11991 elsif Nkind (Prop) = N_Identifier
11992 and then Chars (Prop) in Name_Async_Readers
11993 | Name_Async_Writers
11994 | Name_Effective_Reads
11995 | Name_Effective_Writes
11996 then
11997 null;
11998
11999 -- Otherwise the construct is not a valid property
12000
12001 else
12002 SPARK_Msg_N ("invalid external state property", Prop);
12003 return;
12004 end if;
12005
12006 -- Ensure that the expression of the external state property
12007 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
12008
12009 if Present (Expr) then
12010 Analyze_And_Resolve (Expr, Standard_Boolean);
12011
12012 if Is_OK_Static_Expression (Expr) then
12013 Expr_Val := Is_True (Expr_Value (Expr));
12014 else
12015 SPARK_Msg_N
12016 ("expression of external state property must be "
12017 & "static", Expr);
12018 return;
12019 end if;
12020
12021 -- The lack of expression defaults the property to True
12022
12023 else
12024 Expr_Val := True;
12025 end if;
12026
12027 -- Named properties
12028
12029 if Nkind (Prop) = N_Identifier then
12030 if Chars (Prop) = Name_Async_Readers then
12031 Check_Duplicate_Property (Prop, AR_Seen);
12032 AR_Val := Expr_Val;
12033
12034 elsif Chars (Prop) = Name_Async_Writers then
12035 Check_Duplicate_Property (Prop, AW_Seen);
12036 AW_Val := Expr_Val;
12037
12038 elsif Chars (Prop) = Name_Effective_Reads then
12039 Check_Duplicate_Property (Prop, ER_Seen);
12040 ER_Val := Expr_Val;
12041
12042 else
12043 Check_Duplicate_Property (Prop, EW_Seen);
12044 EW_Val := Expr_Val;
12045 end if;
12046
12047 -- The handling of property "others" must take into account
12048 -- all other named properties that have been encountered so
12049 -- far. Only those that have not been seen are affected by
12050 -- "others".
12051
12052 else
12053 if not AR_Seen then
12054 AR_Val := Expr_Val;
12055 end if;
12056
12057 if not AW_Seen then
12058 AW_Val := Expr_Val;
12059 end if;
12060
12061 if not ER_Seen then
12062 ER_Val := Expr_Val;
12063 end if;
12064
12065 if not EW_Seen then
12066 EW_Val := Expr_Val;
12067 end if;
12068 end if;
12069 end Analyze_External_Property;
12070
12071 ----------------------------
12072 -- Analyze_Part_Of_Option --
12073 ----------------------------
12074
12075 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
12076 Encap : constant Node_Id := Expression (Opt);
12077 Constits : Elist_Id;
12078 Encap_Id : Entity_Id;
12079 Legal : Boolean;
12080
12081 begin
12082 Check_Duplicate_Option (Opt, Part_Of_Seen);
12083
12084 Analyze_Part_Of
12085 (Indic => First (Choices (Opt)),
12086 Item_Id => State_Id,
12087 Encap => Encap,
12088 Encap_Id => Encap_Id,
12089 Legal => Legal);
12090
12091 -- The Part_Of indicator transforms the abstract state into
12092 -- a constituent of the encapsulating state or single
12093 -- concurrent type.
12094
12095 if Legal then
12096 pragma Assert (Present (Encap_Id));
12097 Constits := Part_Of_Constituents (Encap_Id);
12098
12099 if No (Constits) then
12100 Constits := New_Elmt_List;
12101 Set_Part_Of_Constituents (Encap_Id, Constits);
12102 end if;
12103
12104 Append_Elmt (State_Id, Constits);
12105 Set_Encapsulating_State (State_Id, Encap_Id);
12106 end if;
12107 end Analyze_Part_Of_Option;
12108
12109 ----------------------------
12110 -- Check_Duplicate_Option --
12111 ----------------------------
12112
12113 procedure Check_Duplicate_Option
12114 (Opt : Node_Id;
12115 Status : in out Boolean)
12116 is
12117 begin
12118 if Status then
12119 SPARK_Msg_N ("duplicate state option", Opt);
12120 end if;
12121
12122 Status := True;
12123 end Check_Duplicate_Option;
12124
12125 ------------------------------
12126 -- Check_Duplicate_Property --
12127 ------------------------------
12128
12129 procedure Check_Duplicate_Property
12130 (Prop : Node_Id;
12131 Status : in out Boolean)
12132 is
12133 begin
12134 if Status then
12135 SPARK_Msg_N ("duplicate external property", Prop);
12136 end if;
12137
12138 Status := True;
12139 end Check_Duplicate_Property;
12140
12141 -----------------------------
12142 -- Check_Ghost_Synchronous --
12143 -----------------------------
12144
12145 procedure Check_Ghost_Synchronous is
12146 begin
12147 -- A synchronized abstract state cannot be Ghost and vice
12148 -- versa (SPARK RM 6.9(19)).
12149
12150 if Ghost_Seen and Synchronous_Seen then
12151 SPARK_Msg_N ("synchronized state cannot be ghost", State);
12152 end if;
12153 end Check_Ghost_Synchronous;
12154
12155 ---------------------------
12156 -- Create_Abstract_State --
12157 ---------------------------
12158
12159 procedure Create_Abstract_State
12160 (Nam : Name_Id;
12161 Decl : Node_Id;
12162 Loc : Source_Ptr;
12163 Is_Null : Boolean)
12164 is
12165 begin
12166 -- The abstract state may be semi-declared when the related
12167 -- package was withed through a limited with clause. In that
12168 -- case reuse the entity to fully declare the state.
12169
12170 if Present (Decl) and then Present (Entity (Decl)) then
12171 State_Id := Entity (Decl);
12172
12173 -- Otherwise the elaboration of pragma Abstract_State
12174 -- declares the state.
12175
12176 else
12177 State_Id := Make_Defining_Identifier (Loc, Nam);
12178
12179 if Present (Decl) then
12180 Set_Entity (Decl, State_Id);
12181 end if;
12182 end if;
12183
12184 -- Null states never come from source
12185
12186 Set_Comes_From_Source (State_Id, not Is_Null);
12187 Set_Parent (State_Id, State);
12188 Mutate_Ekind (State_Id, E_Abstract_State);
12189 Set_Etype (State_Id, Standard_Void_Type);
12190 Set_Encapsulating_State (State_Id, Empty);
12191
12192 -- Set the SPARK mode from the current context
12193
12194 Set_SPARK_Pragma (State_Id, SPARK_Mode_Pragma);
12195 Set_SPARK_Pragma_Inherited (State_Id);
12196
12197 -- An abstract state declared within a Ghost region becomes
12198 -- Ghost (SPARK RM 6.9(2)).
12199
12200 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then
12201 Set_Is_Ghost_Entity (State_Id);
12202 end if;
12203
12204 -- Establish a link between the state declaration and the
12205 -- abstract state entity. Note that a null state remains as
12206 -- N_Null and does not carry any linkages.
12207
12208 if not Is_Null then
12209 if Present (Decl) then
12210 Set_Entity (Decl, State_Id);
12211 Set_Etype (Decl, Standard_Void_Type);
12212 end if;
12213
12214 -- Every non-null state must be defined, nameable and
12215 -- resolvable.
12216
12217 Push_Scope (Pack_Id);
12218 Generate_Definition (State_Id);
12219 Enter_Name (State_Id);
12220 Pop_Scope;
12221 end if;
12222 end Create_Abstract_State;
12223
12224 -- Local variables
12225
12226 Opt : Node_Id;
12227 Opt_Nam : Node_Id;
12228
12229 -- Start of processing for Analyze_Abstract_State
12230
12231 begin
12232 -- A package with a null abstract state is not allowed to
12233 -- declare additional states.
12234
12235 if Null_Seen then
12236 SPARK_Msg_NE
12237 ("package & has null abstract state", State, Pack_Id);
12238
12239 -- Null states appear as internally generated entities
12240
12241 elsif Nkind (State) = N_Null then
12242 Create_Abstract_State
12243 (Nam => New_Internal_Name ('S'),
12244 Decl => Empty,
12245 Loc => Sloc (State),
12246 Is_Null => True);
12247 Null_Seen := True;
12248
12249 -- Catch a case where a null state appears in a list of
12250 -- non-null states.
12251
12252 if Non_Null_Seen then
12253 SPARK_Msg_NE
12254 ("package & has non-null abstract state",
12255 State, Pack_Id);
12256 end if;
12257
12258 -- Simple state declaration
12259
12260 elsif Nkind (State) = N_Identifier then
12261 Create_Abstract_State
12262 (Nam => Chars (State),
12263 Decl => State,
12264 Loc => Sloc (State),
12265 Is_Null => False);
12266 Non_Null_Seen := True;
12267
12268 -- State declaration with various options. This construct
12269 -- appears as an extension aggregate in the tree.
12270
12271 elsif Nkind (State) = N_Extension_Aggregate then
12272 if Nkind (Ancestor_Part (State)) = N_Identifier then
12273 Create_Abstract_State
12274 (Nam => Chars (Ancestor_Part (State)),
12275 Decl => Ancestor_Part (State),
12276 Loc => Sloc (Ancestor_Part (State)),
12277 Is_Null => False);
12278 Non_Null_Seen := True;
12279 else
12280 SPARK_Msg_N
12281 ("state name must be an identifier",
12282 Ancestor_Part (State));
12283 end if;
12284
12285 -- Options External, Ghost and Synchronous appear as
12286 -- expressions.
12287
12288 Opt := First (Expressions (State));
12289 while Present (Opt) loop
12290 if Nkind (Opt) = N_Identifier then
12291
12292 -- External
12293
12294 if Chars (Opt) = Name_External then
12295 Check_Duplicate_Option (Opt, External_Seen);
12296 Analyze_External_Option (Opt);
12297
12298 -- Ghost
12299
12300 elsif Chars (Opt) = Name_Ghost then
12301 Check_Duplicate_Option (Opt, Ghost_Seen);
12302 Check_Ghost_Synchronous;
12303
12304 if Present (State_Id) then
12305 Set_Is_Ghost_Entity (State_Id);
12306 end if;
12307
12308 -- Synchronous
12309
12310 elsif Chars (Opt) = Name_Synchronous then
12311 Check_Duplicate_Option (Opt, Synchronous_Seen);
12312 Check_Ghost_Synchronous;
12313
12314 -- Relaxed_Initialization
12315
12316 elsif Chars (Opt) = Name_Relaxed_Initialization then
12317 Check_Duplicate_Option
12318 (Opt, Relaxed_Initialization_Seen);
12319
12320 -- Option Part_Of without an encapsulating state is
12321 -- illegal (SPARK RM 7.1.4(8)).
12322
12323 elsif Chars (Opt) = Name_Part_Of then
12324 SPARK_Msg_N
12325 ("indicator Part_Of must denote abstract state, "
12326 & "single protected type or single task type",
12327 Opt);
12328
12329 -- Do not emit an error message when a previous state
12330 -- declaration with options was not parenthesized as
12331 -- the option is actually another state declaration.
12332 --
12333 -- with Abstract_State
12334 -- (State_1 with ..., -- missing parentheses
12335 -- (State_2 with ...),
12336 -- State_3) -- ok state declaration
12337
12338 elsif Missing_Parentheses then
12339 null;
12340
12341 -- Otherwise the option is not allowed. Note that it
12342 -- is not possible to distinguish between an option
12343 -- and a state declaration when a previous state with
12344 -- options not properly parentheses.
12345 --
12346 -- with Abstract_State
12347 -- (State_1 with ..., -- missing parentheses
12348 -- State_2); -- could be an option
12349
12350 else
12351 SPARK_Msg_N
12352 ("simple option not allowed in state declaration",
12353 Opt);
12354 end if;
12355
12356 -- Catch a case where missing parentheses around a state
12357 -- declaration with options cause a subsequent state
12358 -- declaration with options to be treated as an option.
12359 --
12360 -- with Abstract_State
12361 -- (State_1 with ..., -- missing parentheses
12362 -- (State_2 with ...))
12363
12364 elsif Nkind (Opt) = N_Extension_Aggregate then
12365 Missing_Parentheses := True;
12366 SPARK_Msg_N
12367 ("state declaration must be parenthesized",
12368 Ancestor_Part (State));
12369
12370 -- Otherwise the option is malformed
12371
12372 else
12373 SPARK_Msg_N ("malformed option", Opt);
12374 end if;
12375
12376 Next (Opt);
12377 end loop;
12378
12379 -- Options External and Part_Of appear as component
12380 -- associations.
12381
12382 Opt := First (Component_Associations (State));
12383 while Present (Opt) loop
12384 Opt_Nam := First (Choices (Opt));
12385
12386 if Nkind (Opt_Nam) = N_Identifier then
12387 if Chars (Opt_Nam) = Name_External then
12388 Analyze_External_Option (Opt);
12389
12390 elsif Chars (Opt_Nam) = Name_Part_Of then
12391 Analyze_Part_Of_Option (Opt);
12392
12393 else
12394 SPARK_Msg_N ("invalid state option", Opt);
12395 end if;
12396 else
12397 SPARK_Msg_N ("invalid state option", Opt);
12398 end if;
12399
12400 Next (Opt);
12401 end loop;
12402
12403 -- Any other attempt to declare a state is illegal
12404
12405 else
12406 Malformed_State_Error (State);
12407 return;
12408 end if;
12409
12410 -- Guard against a junk state. In such cases no entity is
12411 -- generated and the subsequent checks cannot be applied.
12412
12413 if Present (State_Id) then
12414
12415 -- Verify whether the state does not introduce an illegal
12416 -- hidden state within a package subject to a null abstract
12417 -- state.
12418
12419 Check_No_Hidden_State (State_Id);
12420
12421 -- Check whether the lack of option Part_Of agrees with the
12422 -- placement of the abstract state with respect to the state
12423 -- space.
12424
12425 if not Part_Of_Seen then
12426 Check_Missing_Part_Of (State_Id);
12427 end if;
12428
12429 -- Associate the state with its related package
12430
12431 if No (Abstract_States (Pack_Id)) then
12432 Set_Abstract_States (Pack_Id, New_Elmt_List);
12433 end if;
12434
12435 Append_Elmt (State_Id, Abstract_States (Pack_Id));
12436 end if;
12437 end Analyze_Abstract_State;
12438
12439 ---------------------------
12440 -- Malformed_State_Error --
12441 ---------------------------
12442
12443 procedure Malformed_State_Error (State : Node_Id) is
12444 begin
12445 Error_Msg_N ("malformed abstract state declaration", State);
12446
12447 -- An abstract state with a simple option is being declared
12448 -- with "=>" rather than the legal "with". The state appears
12449 -- as a component association.
12450
12451 if Nkind (State) = N_Component_Association then
12452 Error_Msg_N ("\use WITH to specify simple option", State);
12453 end if;
12454 end Malformed_State_Error;
12455
12456 -- Local variables
12457
12458 Pack_Decl : Node_Id;
12459 Pack_Id : Entity_Id;
12460 State : Node_Id;
12461 States : Node_Id;
12462
12463 -- Start of processing for Abstract_State
12464
12465 begin
12466 GNAT_Pragma;
12467 Check_No_Identifiers;
12468 Check_Arg_Count (1);
12469
12470 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
12471
12472 if Nkind (Pack_Decl) not in
12473 N_Generic_Package_Declaration | N_Package_Declaration
12474 then
12475 Pragma_Misplaced;
12476 end if;
12477
12478 Pack_Id := Defining_Entity (Pack_Decl);
12479
12480 -- A pragma that applies to a Ghost entity becomes Ghost for the
12481 -- purposes of legality checks and removal of ignored Ghost code.
12482
12483 Mark_Ghost_Pragma (N, Pack_Id);
12484 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
12485
12486 -- Chain the pragma on the contract for completeness
12487
12488 Add_Contract_Item (N, Pack_Id);
12489
12490 -- The legality checks of pragmas Abstract_State, Initializes, and
12491 -- Initial_Condition are affected by the SPARK mode in effect. In
12492 -- addition, these three pragmas are subject to an inherent order:
12493
12494 -- 1) Abstract_State
12495 -- 2) Initializes
12496 -- 3) Initial_Condition
12497
12498 -- Analyze all these pragmas in the order outlined above
12499
12500 Analyze_If_Present (Pragma_SPARK_Mode);
12501 States := Expression (Get_Argument (N, Pack_Id));
12502
12503 -- Multiple non-null abstract states appear as an aggregate
12504
12505 if Nkind (States) = N_Aggregate then
12506 State := First (Expressions (States));
12507 while Present (State) loop
12508 Analyze_Abstract_State (State, Pack_Id);
12509 Next (State);
12510 end loop;
12511
12512 -- An abstract state with a simple option is being illegaly
12513 -- declared with "=>" rather than "with". In this case the
12514 -- state declaration appears as a component association.
12515
12516 if Present (Component_Associations (States)) then
12517 State := First (Component_Associations (States));
12518 while Present (State) loop
12519 Malformed_State_Error (State);
12520 Next (State);
12521 end loop;
12522 end if;
12523
12524 -- Various forms of a single abstract state. Note that these may
12525 -- include malformed state declarations.
12526
12527 else
12528 Analyze_Abstract_State (States, Pack_Id);
12529 end if;
12530
12531 Analyze_If_Present (Pragma_Initializes);
12532 Analyze_If_Present (Pragma_Initial_Condition);
12533 end Abstract_State;
12534
12535 ------------
12536 -- Ada_83 --
12537 ------------
12538
12539 -- pragma Ada_83;
12540
12541 -- Note: this pragma also has some specific processing in Par.Prag
12542 -- because we want to set the Ada version mode during parsing.
12543
12544 when Pragma_Ada_83 =>
12545 GNAT_Pragma;
12546 Check_Arg_Count (0);
12547
12548 -- We really should check unconditionally for proper configuration
12549 -- pragma placement, since we really don't want mixed Ada modes
12550 -- within a single unit, and the GNAT reference manual has always
12551 -- said this was a configuration pragma, but we did not check and
12552 -- are hesitant to add the check now.
12553
12554 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
12555 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
12556 -- or Ada 2012 mode.
12557
12558 if Ada_Version >= Ada_2005 then
12559 Check_Valid_Configuration_Pragma;
12560 end if;
12561
12562 -- Now set Ada 83 mode
12563
12564 if Latest_Ada_Only then
12565 Error_Pragma ("??pragma% ignored");
12566 else
12567 Ada_Version := Ada_83;
12568 Ada_Version_Explicit := Ada_83;
12569 Ada_Version_Pragma := N;
12570 end if;
12571
12572 ------------
12573 -- Ada_95 --
12574 ------------
12575
12576 -- pragma Ada_95;
12577
12578 -- Note: this pragma also has some specific processing in Par.Prag
12579 -- because we want to set the Ada 83 version mode during parsing.
12580
12581 when Pragma_Ada_95 =>
12582 GNAT_Pragma;
12583 Check_Arg_Count (0);
12584
12585 -- We really should check unconditionally for proper configuration
12586 -- pragma placement, since we really don't want mixed Ada modes
12587 -- within a single unit, and the GNAT reference manual has always
12588 -- said this was a configuration pragma, but we did not check and
12589 -- are hesitant to add the check now.
12590
12591 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
12592 -- or Ada 95, so we must check if we are in Ada 2005 mode.
12593
12594 if Ada_Version >= Ada_2005 then
12595 Check_Valid_Configuration_Pragma;
12596 end if;
12597
12598 -- Now set Ada 95 mode
12599
12600 if Latest_Ada_Only then
12601 Error_Pragma ("??pragma% ignored");
12602 else
12603 Ada_Version := Ada_95;
12604 Ada_Version_Explicit := Ada_95;
12605 Ada_Version_Pragma := N;
12606 end if;
12607
12608 ---------------------
12609 -- Ada_05/Ada_2005 --
12610 ---------------------
12611
12612 -- pragma Ada_05;
12613 -- pragma Ada_05 (LOCAL_NAME);
12614
12615 -- pragma Ada_2005;
12616 -- pragma Ada_2005 (LOCAL_NAME):
12617
12618 -- Note: these pragmas also have some specific processing in Par.Prag
12619 -- because we want to set the Ada 2005 version mode during parsing.
12620
12621 -- The one argument form is used for managing the transition from
12622 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
12623 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
12624 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
12625 -- mode, a preference rule is established which does not choose
12626 -- such an entity unless it is unambiguously specified. This avoids
12627 -- extra subprograms marked this way from generating ambiguities in
12628 -- otherwise legal pre-Ada_2005 programs. The one argument form is
12629 -- intended for exclusive use in the GNAT run-time library.
12630
12631 when Pragma_Ada_05
12632 | Pragma_Ada_2005
12633 =>
12634 declare
12635 E_Id : Node_Id;
12636
12637 begin
12638 GNAT_Pragma;
12639
12640 if Arg_Count = 1 then
12641 Check_Arg_Is_Local_Name (Arg1);
12642 E_Id := Get_Pragma_Arg (Arg1);
12643
12644 if Etype (E_Id) = Any_Type then
12645 return;
12646 end if;
12647
12648 Set_Is_Ada_2005_Only (Entity (E_Id));
12649 Record_Rep_Item (Entity (E_Id), N);
12650
12651 else
12652 Check_Arg_Count (0);
12653
12654 -- For Ada_2005 we unconditionally enforce the documented
12655 -- configuration pragma placement, since we do not want to
12656 -- tolerate mixed modes in a unit involving Ada 2005. That
12657 -- would cause real difficulties for those cases where there
12658 -- are incompatibilities between Ada 95 and Ada 2005.
12659
12660 Check_Valid_Configuration_Pragma;
12661
12662 -- Now set appropriate Ada mode
12663
12664 if Latest_Ada_Only then
12665 Error_Pragma ("??pragma% ignored");
12666 else
12667 Ada_Version := Ada_2005;
12668 Ada_Version_Explicit := Ada_2005;
12669 Ada_Version_Pragma := N;
12670 end if;
12671 end if;
12672 end;
12673
12674 ---------------------
12675 -- Ada_12/Ada_2012 --
12676 ---------------------
12677
12678 -- pragma Ada_12;
12679 -- pragma Ada_12 (LOCAL_NAME);
12680
12681 -- pragma Ada_2012;
12682 -- pragma Ada_2012 (LOCAL_NAME):
12683
12684 -- Note: these pragmas also have some specific processing in Par.Prag
12685 -- because we want to set the Ada 2012 version mode during parsing.
12686
12687 -- The one argument form is used for managing the transition from Ada
12688 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
12689 -- as Ada_2012 only, then referencing the entity in any pre-Ada_2012
12690 -- mode will generate a warning. In addition, in any pre-Ada_2012
12691 -- mode, a preference rule is established which does not choose
12692 -- such an entity unless it is unambiguously specified. This avoids
12693 -- extra subprograms marked this way from generating ambiguities in
12694 -- otherwise legal pre-Ada_2012 programs. The one argument form is
12695 -- intended for exclusive use in the GNAT run-time library.
12696
12697 when Pragma_Ada_12
12698 | Pragma_Ada_2012
12699 =>
12700 declare
12701 E_Id : Node_Id;
12702
12703 begin
12704 GNAT_Pragma;
12705
12706 if Arg_Count = 1 then
12707 Check_Arg_Is_Local_Name (Arg1);
12708 E_Id := Get_Pragma_Arg (Arg1);
12709
12710 if Etype (E_Id) = Any_Type then
12711 return;
12712 end if;
12713
12714 Set_Is_Ada_2012_Only (Entity (E_Id));
12715 Record_Rep_Item (Entity (E_Id), N);
12716
12717 else
12718 Check_Arg_Count (0);
12719
12720 -- For Ada_2012 we unconditionally enforce the documented
12721 -- configuration pragma placement, since we do not want to
12722 -- tolerate mixed modes in a unit involving Ada 2012. That
12723 -- would cause real difficulties for those cases where there
12724 -- are incompatibilities between Ada 95 and Ada 2012. We could
12725 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
12726
12727 Check_Valid_Configuration_Pragma;
12728
12729 -- Now set appropriate Ada mode
12730
12731 Ada_Version := Ada_2012;
12732 Ada_Version_Explicit := Ada_2012;
12733 Ada_Version_Pragma := N;
12734 end if;
12735 end;
12736
12737 --------------
12738 -- Ada_2022 --
12739 --------------
12740
12741 -- pragma Ada_2022;
12742 -- pragma Ada_2022 (LOCAL_NAME):
12743
12744 -- Note: this pragma also has some specific processing in Par.Prag
12745 -- because we want to set the Ada 2022 version mode during parsing.
12746
12747 -- The one argument form is used for managing the transition from Ada
12748 -- 2012 to Ada 2022 in the run-time library. If an entity is marked
12749 -- as Ada_2022 only, then referencing the entity in any pre-Ada_2022
12750 -- mode will generate a warning;for calls to Ada_2022 only primitives
12751 -- that require overriding an error will be reported. In addition, in
12752 -- any pre-Ada_2022 mode, a preference rule is established which does
12753 -- not choose such an entity unless it is unambiguously specified.
12754 -- This avoids extra subprograms marked this way from generating
12755 -- ambiguities in otherwise legal pre-Ada 2022 programs. The one
12756 -- argument form is intended for exclusive use in the GNAT run-time
12757 -- library.
12758
12759 when Pragma_Ada_2022 =>
12760 declare
12761 E_Id : Node_Id;
12762
12763 begin
12764 GNAT_Pragma;
12765
12766 if Arg_Count = 1 then
12767 Check_Arg_Is_Local_Name (Arg1);
12768 E_Id := Get_Pragma_Arg (Arg1);
12769
12770 if Etype (E_Id) = Any_Type then
12771 return;
12772 end if;
12773
12774 Set_Is_Ada_2022_Only (Entity (E_Id));
12775 Record_Rep_Item (Entity (E_Id), N);
12776
12777 else
12778 Check_Arg_Count (0);
12779
12780 -- For Ada_2022 we unconditionally enforce the documented
12781 -- configuration pragma placement, since we do not want to
12782 -- tolerate mixed modes in a unit involving Ada 2022. That
12783 -- would cause real difficulties for those cases where there
12784 -- are incompatibilities between Ada 2012 and Ada 2022. We
12785 -- could allow mixing of Ada 2012 and Ada 2022 but it's not
12786 -- worth it.
12787
12788 Check_Valid_Configuration_Pragma;
12789
12790 -- Now set appropriate Ada mode
12791
12792 Ada_Version := Ada_2022;
12793 Ada_Version_Explicit := Ada_2022;
12794 Ada_Version_Pragma := N;
12795 end if;
12796 end;
12797
12798 -------------------------------------
12799 -- Aggregate_Individually_Assign --
12800 -------------------------------------
12801
12802 -- pragma Aggregate_Individually_Assign;
12803
12804 when Pragma_Aggregate_Individually_Assign =>
12805 GNAT_Pragma;
12806 Check_Arg_Count (0);
12807 Check_Valid_Configuration_Pragma;
12808 Aggregate_Individually_Assign := True;
12809
12810 ----------------------
12811 -- All_Calls_Remote --
12812 ----------------------
12813
12814 -- pragma All_Calls_Remote [(library_package_NAME)];
12815
12816 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
12817 Lib_Entity : Entity_Id;
12818
12819 begin
12820 Check_Ada_83_Warning;
12821 Check_Valid_Library_Unit_Pragma;
12822
12823 -- If N was rewritten as a null statement there is nothing more
12824 -- to do.
12825
12826 if Nkind (N) = N_Null_Statement then
12827 return;
12828 end if;
12829
12830 Lib_Entity := Find_Lib_Unit_Name;
12831
12832 -- A pragma that applies to a Ghost entity becomes Ghost for the
12833 -- purposes of legality checks and removal of ignored Ghost code.
12834
12835 Mark_Ghost_Pragma (N, Lib_Entity);
12836
12837 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
12838
12839 if Present (Lib_Entity) and then not Debug_Flag_U then
12840 if not Is_Remote_Call_Interface (Lib_Entity) then
12841 Error_Pragma ("pragma% only apply to rci unit");
12842
12843 -- Set flag for entity of the library unit
12844
12845 else
12846 Set_Has_All_Calls_Remote (Lib_Entity);
12847 end if;
12848 end if;
12849 end All_Calls_Remote;
12850
12851 ---------------------------
12852 -- Allow_Integer_Address --
12853 ---------------------------
12854
12855 -- pragma Allow_Integer_Address;
12856
12857 when Pragma_Allow_Integer_Address =>
12858 GNAT_Pragma;
12859 Check_Valid_Configuration_Pragma;
12860 Check_Arg_Count (0);
12861
12862 -- If Address is a private type, then set the flag to allow
12863 -- integer address values. If Address is not private, then this
12864 -- pragma has no purpose, so it is simply ignored. Not clear if
12865 -- there are any such targets now.
12866
12867 if Opt.Address_Is_Private then
12868 Opt.Allow_Integer_Address := True;
12869 end if;
12870
12871 --------------
12872 -- Annotate --
12873 --------------
12874
12875 -- pragma Annotate
12876 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
12877 -- ARG ::= NAME | EXPRESSION
12878
12879 -- The first two arguments are by convention intended to refer to an
12880 -- external tool and a tool-specific function. These arguments are
12881 -- not analyzed.
12882
12883 when Pragma_Annotate | Pragma_GNAT_Annotate => Annotate : declare
12884 Arg : Node_Id;
12885 Expr : Node_Id;
12886 Nam_Arg : Node_Id;
12887
12888 --------------------------
12889 -- Inferred_String_Type --
12890 --------------------------
12891
12892 function Preferred_String_Type (Expr : Node_Id) return Entity_Id;
12893 -- Infer the type to use for a string literal or a concatentation
12894 -- of operands whose types can be inferred. For such expressions,
12895 -- returns the "narrowest" of the three predefined string types
12896 -- that can represent the characters occurring in the expression.
12897 -- For other expressions, returns Empty.
12898
12899 function Preferred_String_Type (Expr : Node_Id) return Entity_Id is
12900 begin
12901 case Nkind (Expr) is
12902 when N_String_Literal =>
12903 if Has_Wide_Wide_Character (Expr) then
12904 return Standard_Wide_Wide_String;
12905 elsif Has_Wide_Character (Expr) then
12906 return Standard_Wide_String;
12907 else
12908 return Standard_String;
12909 end if;
12910
12911 when N_Op_Concat =>
12912 declare
12913 L_Type : constant Entity_Id
12914 := Preferred_String_Type (Left_Opnd (Expr));
12915 R_Type : constant Entity_Id
12916 := Preferred_String_Type (Right_Opnd (Expr));
12917
12918 Type_Table : constant array (1 .. 4) of Entity_Id
12919 := (Empty,
12920 Standard_Wide_Wide_String,
12921 Standard_Wide_String,
12922 Standard_String);
12923 begin
12924 for Idx in Type_Table'Range loop
12925 if (L_Type = Type_Table (Idx)) or
12926 (R_Type = Type_Table (Idx))
12927 then
12928 return Type_Table (Idx);
12929 end if;
12930 end loop;
12931 raise Program_Error;
12932 end;
12933
12934 when others =>
12935 return Empty;
12936 end case;
12937 end Preferred_String_Type;
12938 begin
12939 GNAT_Pragma;
12940 Check_At_Least_N_Arguments (1);
12941
12942 Nam_Arg := Last (Pragma_Argument_Associations (N));
12943
12944 -- Determine whether the last argument is "Entity => local_NAME"
12945 -- and if it is, perform the required semantic checks. Remove the
12946 -- argument from further processing.
12947
12948 if Nkind (Nam_Arg) = N_Pragma_Argument_Association
12949 and then Chars (Nam_Arg) = Name_Entity
12950 then
12951 Check_Arg_Is_Local_Name (Nam_Arg);
12952 Arg_Count := Arg_Count - 1;
12953
12954 -- A pragma that applies to a Ghost entity becomes Ghost for
12955 -- the purposes of legality checks and removal of ignored Ghost
12956 -- code.
12957
12958 if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg))
12959 and then Present (Entity (Get_Pragma_Arg (Nam_Arg)))
12960 then
12961 Mark_Ghost_Pragma (N, Entity (Get_Pragma_Arg (Nam_Arg)));
12962 end if;
12963 end if;
12964
12965 -- Continue the processing with last argument removed for now
12966
12967 Check_Arg_Is_Identifier (Arg1);
12968 Check_No_Identifiers;
12969 Store_Note (N);
12970
12971 -- The second parameter is optional, it is never analyzed
12972
12973 if No (Arg2) then
12974 null;
12975
12976 -- Otherwise there is a second parameter
12977
12978 else
12979 -- The second parameter must be an identifier
12980
12981 Check_Arg_Is_Identifier (Arg2);
12982
12983 -- Process the remaining parameters (if any)
12984
12985 Arg := Next (Arg2);
12986 while Present (Arg) loop
12987 Expr := Get_Pragma_Arg (Arg);
12988 Analyze (Expr);
12989
12990 if Is_Entity_Name (Expr) then
12991 null;
12992
12993 -- For string literals and concatenations of string literals
12994 -- we assume Standard_String as the type, unless the string
12995 -- contains wide or wide_wide characters.
12996
12997 elsif Present (Preferred_String_Type (Expr)) then
12998 Resolve (Expr, Preferred_String_Type (Expr));
12999
13000 elsif Is_Overloaded (Expr) then
13001 Error_Pragma_Arg ("ambiguous argument for pragma%", Expr);
13002
13003 else
13004 Resolve (Expr);
13005 end if;
13006
13007 Next (Arg);
13008 end loop;
13009 end if;
13010 end Annotate;
13011
13012 -------------------------------------------------
13013 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
13014 -------------------------------------------------
13015
13016 -- pragma Assert
13017 -- ( [Check => ] Boolean_EXPRESSION
13018 -- [, [Message =>] Static_String_EXPRESSION]);
13019
13020 -- pragma Assert_And_Cut
13021 -- ( [Check => ] Boolean_EXPRESSION
13022 -- [, [Message =>] Static_String_EXPRESSION]);
13023
13024 -- pragma Assume
13025 -- ( [Check => ] Boolean_EXPRESSION
13026 -- [, [Message =>] Static_String_EXPRESSION]);
13027
13028 -- pragma Loop_Invariant
13029 -- ( [Check => ] Boolean_EXPRESSION
13030 -- [, [Message =>] Static_String_EXPRESSION]);
13031
13032 when Pragma_Assert
13033 | Pragma_Assert_And_Cut
13034 | Pragma_Assume
13035 | Pragma_Loop_Invariant
13036 =>
13037 Assert : declare
13038 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
13039 -- Determine whether expression Expr contains a Loop_Entry
13040 -- attribute reference.
13041
13042 -------------------------
13043 -- Contains_Loop_Entry --
13044 -------------------------
13045
13046 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
13047 Has_Loop_Entry : Boolean := False;
13048
13049 function Process (N : Node_Id) return Traverse_Result;
13050 -- Process function for traversal to look for Loop_Entry
13051
13052 -------------
13053 -- Process --
13054 -------------
13055
13056 function Process (N : Node_Id) return Traverse_Result is
13057 begin
13058 if Nkind (N) = N_Attribute_Reference
13059 and then Attribute_Name (N) = Name_Loop_Entry
13060 then
13061 Has_Loop_Entry := True;
13062 return Abandon;
13063 else
13064 return OK;
13065 end if;
13066 end Process;
13067
13068 procedure Traverse is new Traverse_Proc (Process);
13069
13070 -- Start of processing for Contains_Loop_Entry
13071
13072 begin
13073 Traverse (Expr);
13074 return Has_Loop_Entry;
13075 end Contains_Loop_Entry;
13076
13077 -- Local variables
13078
13079 Expr : Node_Id;
13080 New_Args : List_Id;
13081
13082 -- Start of processing for Assert
13083
13084 begin
13085 -- Assert is an Ada 2005 RM-defined pragma
13086
13087 if Prag_Id = Pragma_Assert then
13088 Ada_2005_Pragma;
13089
13090 -- The remaining ones are GNAT pragmas
13091
13092 else
13093 GNAT_Pragma;
13094 end if;
13095
13096 Check_At_Least_N_Arguments (1);
13097 Check_At_Most_N_Arguments (2);
13098 Check_Arg_Order ((Name_Check, Name_Message));
13099 Check_Optional_Identifier (Arg1, Name_Check);
13100 Expr := Get_Pragma_Arg (Arg1);
13101
13102 -- Special processing for Loop_Invariant, Loop_Variant or for
13103 -- other cases where a Loop_Entry attribute is present. If the
13104 -- assertion pragma contains attribute Loop_Entry, ensure that
13105 -- the related pragma is within a loop.
13106
13107 if Prag_Id = Pragma_Loop_Invariant
13108 or else Prag_Id = Pragma_Loop_Variant
13109 or else Contains_Loop_Entry (Expr)
13110 then
13111 Check_Loop_Pragma_Placement;
13112
13113 -- Perform preanalysis to deal with embedded Loop_Entry
13114 -- attributes.
13115
13116 Preanalyze_Assert_Expression (Expr, Any_Boolean);
13117 end if;
13118
13119 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
13120 -- a corresponding Check pragma:
13121
13122 -- pragma Check (name, condition [, msg]);
13123
13124 -- Where name is the identifier matching the pragma name. So
13125 -- rewrite pragma in this manner, transfer the message argument
13126 -- if present, and analyze the result
13127
13128 -- Note: When dealing with a semantically analyzed tree, the
13129 -- information that a Check node N corresponds to a source Assert,
13130 -- Assume, or Assert_And_Cut pragma can be retrieved from the
13131 -- pragma kind of Original_Node(N).
13132
13133 New_Args := New_List (
13134 Make_Pragma_Argument_Association (Loc,
13135 Expression => Make_Identifier (Loc, Pname)),
13136 Make_Pragma_Argument_Association (Sloc (Expr),
13137 Expression => Expr));
13138
13139 if Arg_Count > 1 then
13140 Check_Optional_Identifier (Arg2, Name_Message);
13141
13142 -- Provide semantic annotations for optional argument, for
13143 -- ASIS use, before rewriting.
13144 -- Is this still needed???
13145
13146 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
13147 Append_To (New_Args, New_Copy_Tree (Arg2));
13148 end if;
13149
13150 -- Rewrite as Check pragma
13151
13152 Rewrite (N,
13153 Make_Pragma (Loc,
13154 Chars => Name_Check,
13155 Pragma_Argument_Associations => New_Args));
13156
13157 Analyze (N);
13158 end Assert;
13159
13160 ----------------------
13161 -- Assertion_Policy --
13162 ----------------------
13163
13164 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
13165
13166 -- The following form is Ada 2012 only, but we allow it in all modes
13167
13168 -- Pragma Assertion_Policy (
13169 -- ASSERTION_KIND => POLICY_IDENTIFIER
13170 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
13171
13172 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
13173
13174 -- RM_ASSERTION_KIND ::= Assert |
13175 -- Static_Predicate |
13176 -- Dynamic_Predicate |
13177 -- Pre |
13178 -- Pre'Class |
13179 -- Post |
13180 -- Post'Class |
13181 -- Type_Invariant |
13182 -- Type_Invariant'Class |
13183 -- Default_Initial_Condition
13184
13185 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
13186 -- Assume |
13187 -- Contract_Cases |
13188 -- Debug |
13189 -- Ghost |
13190 -- Initial_Condition |
13191 -- Loop_Invariant |
13192 -- Loop_Variant |
13193 -- Postcondition |
13194 -- Precondition |
13195 -- Predicate |
13196 -- Refined_Post |
13197 -- Statement_Assertions |
13198 -- Subprogram_Variant
13199
13200 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
13201 -- ID_ASSERTION_KIND list contains implementation-defined additions
13202 -- recognized by GNAT. The effect is to control the behavior of
13203 -- identically named aspects and pragmas, depending on the specified
13204 -- policy identifier:
13205
13206 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
13207
13208 -- Note: Check and Ignore are language-defined. Disable is a GNAT
13209 -- implementation-defined addition that results in totally ignoring
13210 -- the corresponding assertion. If Disable is specified, then the
13211 -- argument of the assertion is not even analyzed. This is useful
13212 -- when the aspect/pragma argument references entities in a with'ed
13213 -- package that is replaced by a dummy package in the final build.
13214
13215 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
13216 -- and Type_Invariant'Class were recognized by the parser and
13217 -- transformed into references to the special internal identifiers
13218 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
13219 -- processing is required here.
13220
13221 when Pragma_Assertion_Policy => Assertion_Policy : declare
13222 procedure Resolve_Suppressible (Policy : Node_Id);
13223 -- Converts the assertion policy 'Suppressible' to either Check or
13224 -- Ignore based on whether checks are suppressed via -gnatp.
13225
13226 --------------------------
13227 -- Resolve_Suppressible --
13228 --------------------------
13229
13230 procedure Resolve_Suppressible (Policy : Node_Id) is
13231 Arg : constant Node_Id := Get_Pragma_Arg (Policy);
13232 Nam : Name_Id;
13233
13234 begin
13235 -- Transform policy argument Suppressible into either Ignore or
13236 -- Check depending on whether checks are enabled or suppressed.
13237
13238 if Chars (Arg) = Name_Suppressible then
13239 if Suppress_Checks then
13240 Nam := Name_Ignore;
13241 else
13242 Nam := Name_Check;
13243 end if;
13244
13245 Rewrite (Arg, Make_Identifier (Sloc (Arg), Nam));
13246 end if;
13247 end Resolve_Suppressible;
13248
13249 -- Local variables
13250
13251 Arg : Node_Id;
13252 Kind : Name_Id;
13253 LocP : Source_Ptr;
13254 Policy : Node_Id;
13255
13256 begin
13257 Ada_2005_Pragma;
13258
13259 -- This can always appear as a configuration pragma
13260
13261 if Is_Configuration_Pragma then
13262 null;
13263
13264 -- It can also appear in a declarative part or package spec in Ada
13265 -- 2012 mode. We allow this in other modes, but in that case we
13266 -- consider that we have an Ada 2012 pragma on our hands.
13267
13268 else
13269 Check_Is_In_Decl_Part_Or_Package_Spec;
13270 Ada_2012_Pragma;
13271 end if;
13272
13273 -- One argument case with no identifier (first form above)
13274
13275 if Arg_Count = 1
13276 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
13277 or else Chars (Arg1) = No_Name)
13278 then
13279 Check_Arg_Is_One_Of (Arg1,
13280 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13281
13282 Resolve_Suppressible (Arg1);
13283
13284 -- Treat one argument Assertion_Policy as equivalent to:
13285
13286 -- pragma Check_Policy (Assertion, policy)
13287
13288 -- So rewrite pragma in that manner and link on to the chain
13289 -- of Check_Policy pragmas, marking the pragma as analyzed.
13290
13291 Policy := Get_Pragma_Arg (Arg1);
13292
13293 Rewrite (N,
13294 Make_Pragma (Loc,
13295 Chars => Name_Check_Policy,
13296 Pragma_Argument_Associations => New_List (
13297 Make_Pragma_Argument_Association (Loc,
13298 Expression => Make_Identifier (Loc, Name_Assertion)),
13299
13300 Make_Pragma_Argument_Association (Loc,
13301 Expression =>
13302 Make_Identifier (Sloc (Policy), Chars (Policy))))));
13303 Analyze (N);
13304
13305 -- Here if we have two or more arguments
13306
13307 else
13308 Check_At_Least_N_Arguments (1);
13309 Ada_2012_Pragma;
13310
13311 -- Loop through arguments
13312
13313 Arg := Arg1;
13314 while Present (Arg) loop
13315 LocP := Sloc (Arg);
13316
13317 -- Kind must be specified
13318
13319 if Nkind (Arg) /= N_Pragma_Argument_Association
13320 or else Chars (Arg) = No_Name
13321 then
13322 Error_Pragma_Arg
13323 ("missing assertion kind for pragma%", Arg);
13324 end if;
13325
13326 -- Check Kind and Policy have allowed forms
13327
13328 Kind := Chars (Arg);
13329 Policy := Get_Pragma_Arg (Arg);
13330
13331 if not Is_Valid_Assertion_Kind (Kind) then
13332 Error_Pragma_Arg
13333 ("invalid assertion kind for pragma%", Arg);
13334 end if;
13335
13336 Check_Arg_Is_One_Of (Arg,
13337 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13338
13339 Resolve_Suppressible (Arg);
13340
13341 if Kind = Name_Ghost then
13342
13343 -- The Ghost policy must be either Check or Ignore
13344 -- (SPARK RM 6.9(6)).
13345
13346 if Chars (Policy) not in Name_Check | Name_Ignore then
13347 Error_Pragma_Arg
13348 ("argument of pragma % Ghost must be Check or "
13349 & "Ignore", Policy);
13350 end if;
13351
13352 -- Pragma Assertion_Policy specifying a Ghost policy
13353 -- cannot occur within a Ghost subprogram or package
13354 -- (SPARK RM 6.9(14)).
13355
13356 if Ghost_Mode > None then
13357 Error_Pragma
13358 ("pragma % cannot appear within ghost subprogram or "
13359 & "package");
13360 end if;
13361 end if;
13362
13363 -- Rewrite the Assertion_Policy pragma as a series of
13364 -- Check_Policy pragmas of the form:
13365
13366 -- Check_Policy (Kind, Policy);
13367
13368 -- Note: the insertion of the pragmas cannot be done with
13369 -- Insert_Action because in the configuration case, there
13370 -- are no scopes on the scope stack and the mechanism will
13371 -- fail.
13372
13373 Insert_Before_And_Analyze (N,
13374 Make_Pragma (LocP,
13375 Chars => Name_Check_Policy,
13376 Pragma_Argument_Associations => New_List (
13377 Make_Pragma_Argument_Association (LocP,
13378 Expression => Make_Identifier (LocP, Kind)),
13379 Make_Pragma_Argument_Association (LocP,
13380 Expression => Policy))));
13381
13382 Arg := Next (Arg);
13383 end loop;
13384
13385 -- Rewrite the Assertion_Policy pragma as null since we have
13386 -- now inserted all the equivalent Check pragmas.
13387
13388 Rewrite (N, Make_Null_Statement (Loc));
13389 Analyze (N);
13390 end if;
13391 end Assertion_Policy;
13392
13393 ------------------------------
13394 -- Assume_No_Invalid_Values --
13395 ------------------------------
13396
13397 -- pragma Assume_No_Invalid_Values (On | Off);
13398
13399 when Pragma_Assume_No_Invalid_Values =>
13400 GNAT_Pragma;
13401 Check_Valid_Configuration_Pragma;
13402 Check_Arg_Count (1);
13403 Check_No_Identifiers;
13404 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13405
13406 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
13407 Assume_No_Invalid_Values := True;
13408 else
13409 Assume_No_Invalid_Values := False;
13410 end if;
13411
13412 --------------------------
13413 -- Attribute_Definition --
13414 --------------------------
13415
13416 -- pragma Attribute_Definition
13417 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
13418 -- [Entity =>] LOCAL_NAME,
13419 -- [Expression =>] EXPRESSION | NAME);
13420
13421 when Pragma_Attribute_Definition => Attribute_Definition : declare
13422 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
13423 Aname : Name_Id;
13424
13425 begin
13426 GNAT_Pragma;
13427 Check_Arg_Count (3);
13428 Check_Optional_Identifier (Arg1, "attribute");
13429 Check_Optional_Identifier (Arg2, "entity");
13430 Check_Optional_Identifier (Arg3, "expression");
13431
13432 if Nkind (Attribute_Designator) /= N_Identifier then
13433 Error_Msg_N ("attribute name expected", Attribute_Designator);
13434 return;
13435 end if;
13436
13437 Check_Arg_Is_Local_Name (Arg2);
13438
13439 -- If the attribute is not recognized, then issue a warning (not
13440 -- an error), and ignore the pragma.
13441
13442 Aname := Chars (Attribute_Designator);
13443
13444 if not Is_Attribute_Name (Aname) then
13445 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
13446 return;
13447 end if;
13448
13449 -- Otherwise, rewrite the pragma as an attribute definition clause
13450
13451 Rewrite (N,
13452 Make_Attribute_Definition_Clause (Loc,
13453 Name => Get_Pragma_Arg (Arg2),
13454 Chars => Aname,
13455 Expression => Get_Pragma_Arg (Arg3)));
13456 Analyze (N);
13457 end Attribute_Definition;
13458
13459 ------------------------------------------------------------------
13460 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
13461 -- No_Caching --
13462 ------------------------------------------------------------------
13463
13464 -- pragma Async_Readers [ (boolean_EXPRESSION) ];
13465 -- pragma Async_Writers [ (boolean_EXPRESSION) ];
13466 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
13467 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
13468 -- pragma No_Caching [ (boolean_EXPRESSION) ];
13469
13470 when Pragma_Async_Readers
13471 | Pragma_Async_Writers
13472 | Pragma_Effective_Reads
13473 | Pragma_Effective_Writes
13474 | Pragma_No_Caching
13475 =>
13476 Async_Effective : declare
13477 Obj_Or_Type_Decl : Node_Id;
13478 Obj_Or_Type_Id : Entity_Id;
13479 begin
13480 GNAT_Pragma;
13481 Check_No_Identifiers;
13482 Check_At_Most_N_Arguments (1);
13483
13484 Obj_Or_Type_Decl := Find_Related_Context (N, Do_Checks => True);
13485
13486 -- Pragma must apply to a object declaration or to a type
13487 -- declaration (only the former in the No_Caching case).
13488 -- Original_Node is necessary to account for untagged derived
13489 -- types that are rewritten as subtypes of their
13490 -- respective root types.
13491
13492 if Nkind (Obj_Or_Type_Decl) /= N_Object_Declaration then
13493 if Prag_Id = Pragma_No_Caching
13494 or else Nkind (Original_Node (Obj_Or_Type_Decl)) not in
13495 N_Full_Type_Declaration |
13496 N_Private_Type_Declaration |
13497 N_Formal_Type_Declaration |
13498 N_Task_Type_Declaration |
13499 N_Protected_Type_Declaration
13500 then
13501 Pragma_Misplaced;
13502 end if;
13503 end if;
13504
13505 Obj_Or_Type_Id := Defining_Entity (Obj_Or_Type_Decl);
13506
13507 -- Perform minimal verification to ensure that the argument is at
13508 -- least an object or a type. Subsequent finer grained checks will
13509 -- be done at the end of the declarative region that contains the
13510 -- pragma.
13511
13512 if Ekind (Obj_Or_Type_Id) in E_Constant | E_Variable
13513 or else Is_Type (Obj_Or_Type_Id)
13514 then
13515
13516 -- In the case of a type, pragma is a type-related
13517 -- representation item and so requires checks common to
13518 -- all type-related representation items.
13519
13520 if Is_Type (Obj_Or_Type_Id)
13521 and then Rep_Item_Too_Late (Obj_Or_Type_Id, N)
13522 then
13523 return;
13524 end if;
13525
13526 -- A pragma that applies to a Ghost entity becomes Ghost for
13527 -- the purposes of legality checks and removal of ignored Ghost
13528 -- code.
13529
13530 Mark_Ghost_Pragma (N, Obj_Or_Type_Id);
13531
13532 -- Chain the pragma on the contract for further processing by
13533 -- Analyze_External_Property_In_Decl_Part.
13534
13535 Add_Contract_Item (N, Obj_Or_Type_Id);
13536
13537 -- Analyze the Boolean expression (if any)
13538
13539 if Present (Arg1) then
13540 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
13541 end if;
13542
13543 -- Otherwise the external property applies to a constant
13544
13545 else
13546 Error_Pragma
13547 ("pragma % must apply to a volatile type or object");
13548 end if;
13549 end Async_Effective;
13550
13551 ------------------
13552 -- Asynchronous --
13553 ------------------
13554
13555 -- pragma Asynchronous (LOCAL_NAME);
13556
13557 when Pragma_Asynchronous => Asynchronous : declare
13558 C_Ent : Entity_Id;
13559 Decl : Node_Id;
13560 Formal : Entity_Id;
13561 L : List_Id;
13562 Nm : Entity_Id;
13563 S : Node_Id;
13564
13565 procedure Process_Async_Pragma;
13566 -- Common processing for procedure and access-to-procedure case
13567
13568 --------------------------
13569 -- Process_Async_Pragma --
13570 --------------------------
13571
13572 procedure Process_Async_Pragma is
13573 begin
13574 if No (L) then
13575 Set_Is_Asynchronous (Nm);
13576 return;
13577 end if;
13578
13579 -- The formals should be of mode IN (RM E.4.1(6))
13580
13581 S := First (L);
13582 while Present (S) loop
13583 Formal := Defining_Identifier (S);
13584
13585 if Nkind (Formal) = N_Defining_Identifier
13586 and then Ekind (Formal) /= E_In_Parameter
13587 then
13588 Error_Pragma_Arg
13589 ("pragma% procedure can only have IN parameter",
13590 Arg1);
13591 end if;
13592
13593 Next (S);
13594 end loop;
13595
13596 Set_Is_Asynchronous (Nm);
13597 end Process_Async_Pragma;
13598
13599 -- Start of processing for pragma Asynchronous
13600
13601 begin
13602 Check_Ada_83_Warning;
13603 Check_No_Identifiers;
13604 Check_Arg_Count (1);
13605 Check_Arg_Is_Local_Name (Arg1);
13606
13607 if Debug_Flag_U then
13608 return;
13609 end if;
13610
13611 C_Ent := Cunit_Entity (Current_Sem_Unit);
13612 Analyze (Get_Pragma_Arg (Arg1));
13613 Nm := Entity (Get_Pragma_Arg (Arg1));
13614
13615 -- A pragma that applies to a Ghost entity becomes Ghost for the
13616 -- purposes of legality checks and removal of ignored Ghost code.
13617
13618 Mark_Ghost_Pragma (N, Nm);
13619
13620 if not Is_Remote_Call_Interface (C_Ent)
13621 and then not Is_Remote_Types (C_Ent)
13622 then
13623 -- This pragma should only appear in an RCI or Remote Types
13624 -- unit (RM E.4.1(4)).
13625
13626 Error_Pragma
13627 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
13628 end if;
13629
13630 if Ekind (Nm) = E_Procedure
13631 and then Nkind (Parent (Nm)) = N_Procedure_Specification
13632 then
13633 if not Is_Remote_Call_Interface (Nm) then
13634 Error_Pragma_Arg
13635 ("pragma% cannot be applied on non-remote procedure",
13636 Arg1);
13637 end if;
13638
13639 L := Parameter_Specifications (Parent (Nm));
13640 Process_Async_Pragma;
13641 return;
13642
13643 elsif Ekind (Nm) = E_Function then
13644 Error_Pragma_Arg
13645 ("pragma% cannot be applied to function", Arg1);
13646
13647 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
13648 if Is_Record_Type (Nm) then
13649
13650 -- A record type that is the Equivalent_Type for a remote
13651 -- access-to-subprogram type.
13652
13653 Decl := Declaration_Node (Corresponding_Remote_Type (Nm));
13654
13655 else
13656 -- A non-expanded RAS type (distribution is not enabled)
13657
13658 Decl := Declaration_Node (Nm);
13659 end if;
13660
13661 if Nkind (Decl) = N_Full_Type_Declaration
13662 and then Nkind (Type_Definition (Decl)) =
13663 N_Access_Procedure_Definition
13664 then
13665 L := Parameter_Specifications (Type_Definition (Decl));
13666 Process_Async_Pragma;
13667
13668 if Is_Asynchronous (Nm)
13669 and then Expander_Active
13670 and then Get_PCS_Name /= Name_No_DSA
13671 then
13672 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
13673 end if;
13674
13675 else
13676 Error_Pragma_Arg
13677 ("pragma% cannot reference access-to-function type",
13678 Arg1);
13679 end if;
13680
13681 -- Only other possibility is access-to-class-wide type
13682
13683 elsif Is_Access_Type (Nm)
13684 and then Is_Class_Wide_Type (Designated_Type (Nm))
13685 then
13686 Check_First_Subtype (Arg1);
13687 Set_Is_Asynchronous (Nm);
13688 if Expander_Active then
13689 RACW_Type_Is_Asynchronous (Nm);
13690 end if;
13691
13692 else
13693 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
13694 end if;
13695 end Asynchronous;
13696
13697 ------------
13698 -- Atomic --
13699 ------------
13700
13701 -- pragma Atomic (LOCAL_NAME);
13702
13703 when Pragma_Atomic =>
13704 Process_Atomic_Independent_Shared_Volatile;
13705
13706 -----------------------
13707 -- Atomic_Components --
13708 -----------------------
13709
13710 -- pragma Atomic_Components (array_LOCAL_NAME);
13711
13712 -- This processing is shared by Volatile_Components
13713
13714 when Pragma_Atomic_Components
13715 | Pragma_Volatile_Components
13716 =>
13717 Atomic_Components : declare
13718 D : Node_Id;
13719 E : Entity_Id;
13720 E_Id : Node_Id;
13721
13722 begin
13723 Check_Ada_83_Warning;
13724 Check_No_Identifiers;
13725 Check_Arg_Count (1);
13726 Check_Arg_Is_Local_Name (Arg1);
13727 E_Id := Get_Pragma_Arg (Arg1);
13728
13729 if Etype (E_Id) = Any_Type then
13730 return;
13731 end if;
13732
13733 E := Entity (E_Id);
13734
13735 -- A pragma that applies to a Ghost entity becomes Ghost for the
13736 -- purposes of legality checks and removal of ignored Ghost code.
13737
13738 Mark_Ghost_Pragma (N, E);
13739 Check_Duplicate_Pragma (E);
13740
13741 if Rep_Item_Too_Early (E, N)
13742 or else
13743 Rep_Item_Too_Late (E, N)
13744 then
13745 return;
13746 end if;
13747
13748 D := Declaration_Node (E);
13749
13750 if (Nkind (D) = N_Full_Type_Declaration and then Is_Array_Type (E))
13751 or else
13752 (Nkind (D) = N_Object_Declaration
13753 and then Ekind (E) in E_Constant | E_Variable
13754 and then Nkind (Object_Definition (D)) =
13755 N_Constrained_Array_Definition)
13756 or else
13757 (Ada_Version >= Ada_2022
13758 and then Nkind (D) = N_Formal_Type_Declaration)
13759 then
13760 -- The flag is set on the base type, or on the object
13761
13762 if Nkind (D) = N_Full_Type_Declaration then
13763 E := Base_Type (E);
13764 end if;
13765
13766 -- Atomic implies both Independent and Volatile
13767
13768 if Prag_Id = Pragma_Atomic_Components then
13769 Set_Has_Atomic_Components (E);
13770 Set_Has_Independent_Components (E);
13771 end if;
13772
13773 Set_Has_Volatile_Components (E);
13774
13775 else
13776 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
13777 end if;
13778 end Atomic_Components;
13779
13780 --------------------
13781 -- Attach_Handler --
13782 --------------------
13783
13784 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
13785
13786 when Pragma_Attach_Handler =>
13787 Check_Ada_83_Warning;
13788 Check_No_Identifiers;
13789 Check_Arg_Count (2);
13790
13791 if No_Run_Time_Mode then
13792 Error_Msg_CRT ("Attach_Handler pragma", N);
13793 else
13794 Check_Interrupt_Or_Attach_Handler;
13795
13796 -- The expression that designates the attribute may depend on a
13797 -- discriminant, and is therefore a per-object expression, to
13798 -- be expanded in the init proc. If expansion is enabled, then
13799 -- perform semantic checks on a copy only.
13800
13801 declare
13802 Temp : Node_Id;
13803 Typ : Node_Id;
13804 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
13805
13806 begin
13807 -- In Relaxed_RM_Semantics mode, we allow any static
13808 -- integer value, for compatibility with other compilers.
13809
13810 if Relaxed_RM_Semantics
13811 and then Nkind (Parg2) = N_Integer_Literal
13812 then
13813 Typ := Standard_Integer;
13814 else
13815 Typ := RTE (RE_Interrupt_ID);
13816 end if;
13817
13818 if Expander_Active then
13819 Temp := New_Copy_Tree (Parg2);
13820 Set_Parent (Temp, N);
13821 Preanalyze_And_Resolve (Temp, Typ);
13822 else
13823 Analyze (Parg2);
13824 Resolve (Parg2, Typ);
13825 end if;
13826 end;
13827
13828 Process_Interrupt_Or_Attach_Handler;
13829 end if;
13830
13831 --------------------
13832 -- C_Pass_By_Copy --
13833 --------------------
13834
13835 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
13836
13837 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
13838 Arg : Node_Id;
13839 Val : Uint;
13840
13841 begin
13842 GNAT_Pragma;
13843 Check_Valid_Configuration_Pragma;
13844 Check_Arg_Count (1);
13845 Check_Optional_Identifier (Arg1, "max_size");
13846
13847 Arg := Get_Pragma_Arg (Arg1);
13848 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
13849
13850 Val := Expr_Value (Arg);
13851
13852 if Val <= 0 then
13853 Error_Pragma_Arg
13854 ("maximum size for pragma% must be positive", Arg1);
13855
13856 elsif UI_Is_In_Int_Range (Val) then
13857 Default_C_Record_Mechanism := UI_To_Int (Val);
13858
13859 -- If a giant value is given, Int'Last will do well enough.
13860 -- If sometime someone complains that a record larger than
13861 -- two gigabytes is not copied, we will worry about it then.
13862
13863 else
13864 Default_C_Record_Mechanism := Mechanism_Type'Last;
13865 end if;
13866 end C_Pass_By_Copy;
13867
13868 -----------
13869 -- Check --
13870 -----------
13871
13872 -- pragma Check ([Name =>] CHECK_KIND,
13873 -- [Check =>] Boolean_EXPRESSION
13874 -- [,[Message =>] String_EXPRESSION]);
13875
13876 -- CHECK_KIND ::= IDENTIFIER |
13877 -- Pre'Class |
13878 -- Post'Class |
13879 -- Invariant'Class |
13880 -- Type_Invariant'Class
13881
13882 -- The identifiers Assertions and Statement_Assertions are not
13883 -- allowed, since they have special meaning for Check_Policy.
13884
13885 -- WARNING: The code below manages Ghost regions. Return statements
13886 -- must be replaced by gotos which jump to the end of the code and
13887 -- restore the Ghost mode.
13888
13889 when Pragma_Check => Check : declare
13890 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
13891 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
13892 -- Save the Ghost-related attributes to restore on exit
13893
13894 Cname : Name_Id;
13895 Eloc : Source_Ptr;
13896 Expr : Node_Id;
13897 Str : Node_Id;
13898 pragma Warnings (Off, Str);
13899
13900 begin
13901 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
13902 -- the mode now to ensure that any nodes generated during analysis
13903 -- and expansion are marked as Ghost.
13904
13905 Set_Ghost_Mode (N);
13906
13907 GNAT_Pragma;
13908 Check_At_Least_N_Arguments (2);
13909 Check_At_Most_N_Arguments (3);
13910 Check_Optional_Identifier (Arg1, Name_Name);
13911 Check_Optional_Identifier (Arg2, Name_Check);
13912
13913 if Arg_Count = 3 then
13914 Check_Optional_Identifier (Arg3, Name_Message);
13915 Str := Get_Pragma_Arg (Arg3);
13916 end if;
13917
13918 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
13919 Check_Arg_Is_Identifier (Arg1);
13920 Cname := Chars (Get_Pragma_Arg (Arg1));
13921
13922 -- Check forbidden name Assertions or Statement_Assertions
13923
13924 case Cname is
13925 when Name_Assertions =>
13926 Error_Pragma_Arg
13927 ("""Assertions"" is not allowed as a check kind for "
13928 & "pragma%", Arg1);
13929
13930 when Name_Statement_Assertions =>
13931 Error_Pragma_Arg
13932 ("""Statement_Assertions"" is not allowed as a check kind "
13933 & "for pragma%", Arg1);
13934
13935 when others =>
13936 null;
13937 end case;
13938
13939 -- Check applicable policy. We skip this if Checked/Ignored status
13940 -- is already set (e.g. in the case of a pragma from an aspect).
13941
13942 if Is_Checked (N) or else Is_Ignored (N) then
13943 null;
13944
13945 -- For a non-source pragma that is a rewriting of another pragma,
13946 -- copy the Is_Checked/Ignored status from the rewritten pragma.
13947
13948 elsif Is_Rewrite_Substitution (N)
13949 and then Nkind (Original_Node (N)) = N_Pragma
13950 then
13951 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
13952 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
13953
13954 -- Otherwise query the applicable policy at this point
13955
13956 else
13957 case Check_Kind (Cname) is
13958 when Name_Ignore =>
13959 Set_Is_Ignored (N, True);
13960 Set_Is_Checked (N, False);
13961
13962 when Name_Check =>
13963 Set_Is_Ignored (N, False);
13964 Set_Is_Checked (N, True);
13965
13966 -- For disable, rewrite pragma as null statement and skip
13967 -- rest of the analysis of the pragma.
13968
13969 when Name_Disable =>
13970 Rewrite (N, Make_Null_Statement (Loc));
13971 Analyze (N);
13972 raise Pragma_Exit;
13973
13974 -- No other possibilities
13975
13976 when others =>
13977 raise Program_Error;
13978 end case;
13979 end if;
13980
13981 -- If check kind was not Disable, then continue pragma analysis
13982
13983 Expr := Get_Pragma_Arg (Arg2);
13984
13985 -- Mark the pragma (or, if rewritten from an aspect, the original
13986 -- aspect) as enabled. Nothing to do for an internally generated
13987 -- check for a dynamic predicate.
13988
13989 if Is_Checked (N)
13990 and then not Split_PPC (N)
13991 and then Cname /= Name_Dynamic_Predicate
13992 then
13993 Set_SCO_Pragma_Enabled (Loc);
13994 end if;
13995
13996 -- Deal with analyzing the string argument. If checks are not
13997 -- on we don't want any expansion (since such expansion would
13998 -- not get properly deleted) but we do want to analyze (to get
13999 -- proper references). The Preanalyze_And_Resolve routine does
14000 -- just what we want. Ditto if pragma is active, because it will
14001 -- be rewritten as an if-statement whose analysis will complete
14002 -- analysis and expansion of the string message. This makes a
14003 -- difference in the unusual case where the expression for the
14004 -- string may have a side effect, such as raising an exception.
14005 -- This is mandated by RM 11.4.2, which specifies that the string
14006 -- expression is only evaluated if the check fails and
14007 -- Assertion_Error is to be raised.
14008
14009 if Arg_Count = 3 then
14010 Preanalyze_And_Resolve (Str, Standard_String);
14011 end if;
14012
14013 -- Now you might think we could just do the same with the Boolean
14014 -- expression if checks are off (and expansion is on) and then
14015 -- rewrite the check as a null statement. This would work but we
14016 -- would lose the useful warnings about an assertion being bound
14017 -- to fail even if assertions are turned off.
14018
14019 -- So instead we wrap the boolean expression in an if statement
14020 -- that looks like:
14021
14022 -- if False and then condition then
14023 -- null;
14024 -- end if;
14025
14026 -- The reason we do this rewriting during semantic analysis rather
14027 -- than as part of normal expansion is that we cannot analyze and
14028 -- expand the code for the boolean expression directly, or it may
14029 -- cause insertion of actions that would escape the attempt to
14030 -- suppress the check code.
14031
14032 -- Note that the Sloc for the if statement corresponds to the
14033 -- argument condition, not the pragma itself. The reason for
14034 -- this is that we may generate a warning if the condition is
14035 -- False at compile time, and we do not want to delete this
14036 -- warning when we delete the if statement.
14037
14038 if Expander_Active and Is_Ignored (N) then
14039 Eloc := Sloc (Expr);
14040
14041 Rewrite (N,
14042 Make_If_Statement (Eloc,
14043 Condition =>
14044 Make_And_Then (Eloc,
14045 Left_Opnd => Make_Identifier (Eloc, Name_False),
14046 Right_Opnd => Expr),
14047 Then_Statements => New_List (
14048 Make_Null_Statement (Eloc))));
14049
14050 -- Now go ahead and analyze the if statement
14051
14052 In_Assertion_Expr := In_Assertion_Expr + 1;
14053
14054 -- One rather special treatment. If we are now in Eliminated
14055 -- overflow mode, then suppress overflow checking since we do
14056 -- not want to drag in the bignum stuff if we are in Ignore
14057 -- mode anyway. This is particularly important if we are using
14058 -- a configurable run time that does not support bignum ops.
14059
14060 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
14061 declare
14062 Svo : constant Boolean :=
14063 Scope_Suppress.Suppress (Overflow_Check);
14064 begin
14065 Scope_Suppress.Overflow_Mode_Assertions := Strict;
14066 Scope_Suppress.Suppress (Overflow_Check) := True;
14067 Analyze (N);
14068 Scope_Suppress.Suppress (Overflow_Check) := Svo;
14069 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
14070 end;
14071
14072 -- Not that special case
14073
14074 else
14075 Analyze (N);
14076 end if;
14077
14078 -- All done with this check
14079
14080 In_Assertion_Expr := In_Assertion_Expr - 1;
14081
14082 -- Check is active or expansion not active. In these cases we can
14083 -- just go ahead and analyze the boolean with no worries.
14084
14085 else
14086 In_Assertion_Expr := In_Assertion_Expr + 1;
14087 Analyze_And_Resolve (Expr, Any_Boolean);
14088 In_Assertion_Expr := In_Assertion_Expr - 1;
14089 end if;
14090
14091 Restore_Ghost_Region (Saved_GM, Saved_IGR);
14092 end Check;
14093
14094 --------------------------
14095 -- Check_Float_Overflow --
14096 --------------------------
14097
14098 -- pragma Check_Float_Overflow;
14099
14100 when Pragma_Check_Float_Overflow =>
14101 GNAT_Pragma;
14102 Check_Valid_Configuration_Pragma;
14103 Check_Arg_Count (0);
14104 Check_Float_Overflow := not Machine_Overflows_On_Target;
14105
14106 ----------------
14107 -- Check_Name --
14108 ----------------
14109
14110 -- pragma Check_Name (check_IDENTIFIER);
14111
14112 when Pragma_Check_Name =>
14113 GNAT_Pragma;
14114 Check_No_Identifiers;
14115 Check_Valid_Configuration_Pragma;
14116 Check_Arg_Count (1);
14117 Check_Arg_Is_Identifier (Arg1);
14118
14119 declare
14120 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
14121
14122 begin
14123 for J in Check_Names.First .. Check_Names.Last loop
14124 if Check_Names.Table (J) = Nam then
14125 return;
14126 end if;
14127 end loop;
14128
14129 Check_Names.Append (Nam);
14130 end;
14131
14132 ------------------
14133 -- Check_Policy --
14134 ------------------
14135
14136 -- This is the old style syntax, which is still allowed in all modes:
14137
14138 -- pragma Check_Policy ([Name =>] CHECK_KIND
14139 -- [Policy =>] POLICY_IDENTIFIER);
14140
14141 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
14142
14143 -- CHECK_KIND ::= IDENTIFIER |
14144 -- Pre'Class |
14145 -- Post'Class |
14146 -- Type_Invariant'Class |
14147 -- Invariant'Class
14148
14149 -- This is the new style syntax, compatible with Assertion_Policy
14150 -- and also allowed in all modes.
14151
14152 -- Pragma Check_Policy (
14153 -- CHECK_KIND => POLICY_IDENTIFIER
14154 -- {, CHECK_KIND => POLICY_IDENTIFIER});
14155
14156 -- Note: the identifiers Name and Policy are not allowed as
14157 -- Check_Kind values. This avoids ambiguities between the old and
14158 -- new form syntax.
14159
14160 when Pragma_Check_Policy => Check_Policy : declare
14161 Kind : Node_Id;
14162
14163 begin
14164 GNAT_Pragma;
14165 Check_At_Least_N_Arguments (1);
14166
14167 -- A Check_Policy pragma can appear either as a configuration
14168 -- pragma, or in a declarative part or a package spec (see RM
14169 -- 11.5(5) for rules for Suppress/Unsuppress which are also
14170 -- followed for Check_Policy).
14171
14172 if not Is_Configuration_Pragma then
14173 Check_Is_In_Decl_Part_Or_Package_Spec;
14174 end if;
14175
14176 -- Figure out if we have the old or new syntax. We have the
14177 -- old syntax if the first argument has no identifier, or the
14178 -- identifier is Name.
14179
14180 if Nkind (Arg1) /= N_Pragma_Argument_Association
14181 or else Chars (Arg1) in No_Name | Name_Name
14182 then
14183 -- Old syntax
14184
14185 Check_Arg_Count (2);
14186 Check_Optional_Identifier (Arg1, Name_Name);
14187 Kind := Get_Pragma_Arg (Arg1);
14188 Rewrite_Assertion_Kind (Kind,
14189 From_Policy => Comes_From_Source (N));
14190 Check_Arg_Is_Identifier (Arg1);
14191
14192 -- Check forbidden check kind
14193
14194 if Chars (Kind) in Name_Name | Name_Policy then
14195 Error_Msg_Name_2 := Chars (Kind);
14196 Error_Pragma_Arg
14197 ("pragma% does not allow% as check name", Arg1);
14198 end if;
14199
14200 -- Check policy
14201
14202 Check_Optional_Identifier (Arg2, Name_Policy);
14203 Check_Arg_Is_One_Of
14204 (Arg2,
14205 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
14206
14207 -- And chain pragma on the Check_Policy_List for search
14208
14209 Set_Next_Pragma (N, Opt.Check_Policy_List);
14210 Opt.Check_Policy_List := N;
14211
14212 -- For the new syntax, what we do is to convert each argument to
14213 -- an old syntax equivalent. We do that because we want to chain
14214 -- old style Check_Policy pragmas for the search (we don't want
14215 -- to have to deal with multiple arguments in the search).
14216
14217 else
14218 declare
14219 Arg : Node_Id;
14220 Argx : Node_Id;
14221 LocP : Source_Ptr;
14222 New_P : Node_Id;
14223
14224 begin
14225 Arg := Arg1;
14226 while Present (Arg) loop
14227 LocP := Sloc (Arg);
14228 Argx := Get_Pragma_Arg (Arg);
14229
14230 -- Kind must be specified
14231
14232 if Nkind (Arg) /= N_Pragma_Argument_Association
14233 or else Chars (Arg) = No_Name
14234 then
14235 Error_Pragma_Arg
14236 ("missing assertion kind for pragma%", Arg);
14237 end if;
14238
14239 -- Construct equivalent old form syntax Check_Policy
14240 -- pragma and insert it to get remaining checks.
14241
14242 New_P :=
14243 Make_Pragma (LocP,
14244 Chars => Name_Check_Policy,
14245 Pragma_Argument_Associations => New_List (
14246 Make_Pragma_Argument_Association (LocP,
14247 Expression =>
14248 Make_Identifier (LocP, Chars (Arg))),
14249 Make_Pragma_Argument_Association (Sloc (Argx),
14250 Expression => Argx)));
14251
14252 Arg := Next (Arg);
14253
14254 -- For a configuration pragma, insert old form in
14255 -- the corresponding file.
14256
14257 if Is_Configuration_Pragma then
14258 Insert_After (N, New_P);
14259 Analyze (New_P);
14260
14261 else
14262 Insert_Action (N, New_P);
14263 end if;
14264 end loop;
14265
14266 -- Rewrite original Check_Policy pragma to null, since we
14267 -- have converted it into a series of old syntax pragmas.
14268
14269 Rewrite (N, Make_Null_Statement (Loc));
14270 Analyze (N);
14271 end;
14272 end if;
14273 end Check_Policy;
14274
14275 -------------
14276 -- Comment --
14277 -------------
14278
14279 -- pragma Comment (static_string_EXPRESSION)
14280
14281 -- Processing for pragma Comment shares the circuitry for pragma
14282 -- Ident. The only differences are that Ident enforces a limit of 31
14283 -- characters on its argument, and also enforces limitations on
14284 -- placement for DEC compatibility. Pragma Comment shares neither of
14285 -- these restrictions.
14286
14287 -------------------
14288 -- Common_Object --
14289 -------------------
14290
14291 -- pragma Common_Object (
14292 -- [Internal =>] LOCAL_NAME
14293 -- [, [External =>] EXTERNAL_SYMBOL]
14294 -- [, [Size =>] EXTERNAL_SYMBOL]);
14295
14296 -- Processing for this pragma is shared with Psect_Object
14297
14298 ----------------------------------------------
14299 -- Compile_Time_Error, Compile_Time_Warning --
14300 ----------------------------------------------
14301
14302 -- pragma Compile_Time_Error
14303 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14304
14305 -- pragma Compile_Time_Warning
14306 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14307
14308 when Pragma_Compile_Time_Error | Pragma_Compile_Time_Warning =>
14309 GNAT_Pragma;
14310
14311 Process_Compile_Time_Warning_Or_Error;
14312
14313 -----------------------------
14314 -- Complete_Representation --
14315 -----------------------------
14316
14317 -- pragma Complete_Representation;
14318
14319 when Pragma_Complete_Representation =>
14320 GNAT_Pragma;
14321 Check_Arg_Count (0);
14322
14323 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
14324 Error_Pragma
14325 ("pragma & must appear within record representation clause");
14326 end if;
14327
14328 ----------------------------
14329 -- Complex_Representation --
14330 ----------------------------
14331
14332 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
14333
14334 when Pragma_Complex_Representation => Complex_Representation : declare
14335 E_Id : Node_Id;
14336 E : Entity_Id;
14337 Ent : Entity_Id;
14338
14339 begin
14340 GNAT_Pragma;
14341 Check_Arg_Count (1);
14342 Check_Optional_Identifier (Arg1, Name_Entity);
14343 Check_Arg_Is_Local_Name (Arg1);
14344 E_Id := Get_Pragma_Arg (Arg1);
14345
14346 if Etype (E_Id) = Any_Type then
14347 return;
14348 end if;
14349
14350 E := Entity (E_Id);
14351
14352 if not Is_Record_Type (E) then
14353 Error_Pragma_Arg
14354 ("argument for pragma% must be record type", Arg1);
14355 end if;
14356
14357 Ent := First_Entity (E);
14358
14359 if No (Ent)
14360 or else No (Next_Entity (Ent))
14361 or else Present (Next_Entity (Next_Entity (Ent)))
14362 or else not Is_Floating_Point_Type (Etype (Ent))
14363 or else Etype (Ent) /= Etype (Next_Entity (Ent))
14364 then
14365 Error_Pragma_Arg
14366 ("record for pragma% must have two fields of the same "
14367 & "floating-point type", Arg1);
14368
14369 else
14370 Set_Has_Complex_Representation (Base_Type (E));
14371
14372 -- We need to treat the type has having a non-standard
14373 -- representation, for back-end purposes, even though in
14374 -- general a complex will have the default representation
14375 -- of a record with two real components.
14376
14377 Set_Has_Non_Standard_Rep (Base_Type (E));
14378 end if;
14379 end Complex_Representation;
14380
14381 -------------------------
14382 -- Component_Alignment --
14383 -------------------------
14384
14385 -- pragma Component_Alignment (
14386 -- [Form =>] ALIGNMENT_CHOICE
14387 -- [, [Name =>] type_LOCAL_NAME]);
14388 --
14389 -- ALIGNMENT_CHOICE ::=
14390 -- Component_Size
14391 -- | Component_Size_4
14392 -- | Storage_Unit
14393 -- | Default
14394
14395 when Pragma_Component_Alignment => Component_AlignmentP : declare
14396 Args : Args_List (1 .. 2);
14397 Names : constant Name_List (1 .. 2) := (
14398 Name_Form,
14399 Name_Name);
14400
14401 Form : Node_Id renames Args (1);
14402 Name : Node_Id renames Args (2);
14403
14404 Atype : Component_Alignment_Kind;
14405 Typ : Entity_Id;
14406
14407 begin
14408 GNAT_Pragma;
14409 Gather_Associations (Names, Args);
14410
14411 if No (Form) then
14412 Error_Pragma ("missing Form argument for pragma%");
14413 end if;
14414
14415 Check_Arg_Is_Identifier (Form);
14416
14417 -- Get proper alignment, note that Default = Component_Size on all
14418 -- machines we have so far, and we want to set this value rather
14419 -- than the default value to indicate that it has been explicitly
14420 -- set (and thus will not get overridden by the default component
14421 -- alignment for the current scope)
14422
14423 if Chars (Form) = Name_Component_Size then
14424 Atype := Calign_Component_Size;
14425
14426 elsif Chars (Form) = Name_Component_Size_4 then
14427 Atype := Calign_Component_Size_4;
14428
14429 elsif Chars (Form) = Name_Default then
14430 Atype := Calign_Component_Size;
14431
14432 elsif Chars (Form) = Name_Storage_Unit then
14433 Atype := Calign_Storage_Unit;
14434
14435 else
14436 Error_Pragma_Arg
14437 ("invalid Form parameter for pragma%", Form);
14438 end if;
14439
14440 -- The pragma appears in a configuration file
14441
14442 if No (Parent (N)) then
14443 Check_Valid_Configuration_Pragma;
14444
14445 -- Capture the component alignment in a global variable when
14446 -- the pragma appears in a configuration file. Note that the
14447 -- scope stack is empty at this point and cannot be used to
14448 -- store the alignment value.
14449
14450 Configuration_Component_Alignment := Atype;
14451
14452 -- Case with no name, supplied, affects scope table entry
14453
14454 elsif No (Name) then
14455 Scope_Stack.Table
14456 (Scope_Stack.Last).Component_Alignment_Default := Atype;
14457
14458 -- Case of name supplied
14459
14460 else
14461 Check_Arg_Is_Local_Name (Name);
14462 Find_Type (Name);
14463 Typ := Entity (Name);
14464
14465 if Typ = Any_Type
14466 or else Rep_Item_Too_Early (Typ, N)
14467 then
14468 return;
14469 else
14470 Typ := Underlying_Type (Typ);
14471 end if;
14472
14473 if not Is_Record_Type (Typ)
14474 and then not Is_Array_Type (Typ)
14475 then
14476 Error_Pragma_Arg
14477 ("Name parameter of pragma% must identify record or "
14478 & "array type", Name);
14479 end if;
14480
14481 -- An explicit Component_Alignment pragma overrides an
14482 -- implicit pragma Pack, but not an explicit one.
14483
14484 if not Has_Pragma_Pack (Base_Type (Typ)) then
14485 Set_Is_Packed (Base_Type (Typ), False);
14486 Set_Component_Alignment (Base_Type (Typ), Atype);
14487 end if;
14488 end if;
14489 end Component_AlignmentP;
14490
14491 --------------------------------
14492 -- Constant_After_Elaboration --
14493 --------------------------------
14494
14495 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
14496
14497 when Pragma_Constant_After_Elaboration => Constant_After_Elaboration :
14498 declare
14499 Obj_Decl : Node_Id;
14500 Obj_Id : Entity_Id;
14501
14502 begin
14503 GNAT_Pragma;
14504 Check_No_Identifiers;
14505 Check_At_Most_N_Arguments (1);
14506
14507 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
14508
14509 if Nkind (Obj_Decl) /= N_Object_Declaration then
14510 Pragma_Misplaced;
14511 end if;
14512
14513 Obj_Id := Defining_Entity (Obj_Decl);
14514
14515 -- The object declaration must be a library-level variable which
14516 -- is either explicitly initialized or obtains a value during the
14517 -- elaboration of a package body (SPARK RM 3.3.1).
14518
14519 if Ekind (Obj_Id) = E_Variable then
14520 if not Is_Library_Level_Entity (Obj_Id) then
14521 Error_Pragma
14522 ("pragma % must apply to a library level variable");
14523 end if;
14524
14525 -- Otherwise the pragma applies to a constant, which is illegal
14526
14527 else
14528 Error_Pragma ("pragma % must apply to a variable declaration");
14529 end if;
14530
14531 -- A pragma that applies to a Ghost entity becomes Ghost for the
14532 -- purposes of legality checks and removal of ignored Ghost code.
14533
14534 Mark_Ghost_Pragma (N, Obj_Id);
14535
14536 -- Chain the pragma on the contract for completeness
14537
14538 Add_Contract_Item (N, Obj_Id);
14539
14540 -- Analyze the Boolean expression (if any)
14541
14542 if Present (Arg1) then
14543 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
14544 end if;
14545 end Constant_After_Elaboration;
14546
14547 --------------------
14548 -- Contract_Cases --
14549 --------------------
14550
14551 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
14552
14553 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
14554
14555 -- CASE_GUARD ::= boolean_EXPRESSION | others
14556
14557 -- CONSEQUENCE ::= boolean_EXPRESSION
14558
14559 -- Characteristics:
14560
14561 -- * Analysis - The annotation undergoes initial checks to verify
14562 -- the legal placement and context. Secondary checks preanalyze the
14563 -- expressions in:
14564
14565 -- Analyze_Contract_Cases_In_Decl_Part
14566
14567 -- * Expansion - The annotation is expanded during the expansion of
14568 -- the related subprogram [body] contract as performed in:
14569
14570 -- Expand_Subprogram_Contract
14571
14572 -- * Template - The annotation utilizes the generic template of the
14573 -- related subprogram [body] when it is:
14574
14575 -- aspect on subprogram declaration
14576 -- aspect on stand-alone subprogram body
14577 -- pragma on stand-alone subprogram body
14578
14579 -- The annotation must prepare its own template when it is:
14580
14581 -- pragma on subprogram declaration
14582
14583 -- * Globals - Capture of global references must occur after full
14584 -- analysis.
14585
14586 -- * Instance - The annotation is instantiated automatically when
14587 -- the related generic subprogram [body] is instantiated except for
14588 -- the "pragma on subprogram declaration" case. In that scenario
14589 -- the annotation must instantiate itself.
14590
14591 when Pragma_Contract_Cases => Contract_Cases : declare
14592 Spec_Id : Entity_Id;
14593 Subp_Decl : Node_Id;
14594 Subp_Spec : Node_Id;
14595
14596 begin
14597 GNAT_Pragma;
14598 Check_No_Identifiers;
14599 Check_Arg_Count (1);
14600
14601 -- Ensure the proper placement of the pragma. Contract_Cases must
14602 -- be associated with a subprogram declaration or a body that acts
14603 -- as a spec.
14604
14605 Subp_Decl :=
14606 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
14607
14608 -- Entry
14609
14610 if Nkind (Subp_Decl) = N_Entry_Declaration then
14611 null;
14612
14613 -- Generic subprogram
14614
14615 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
14616 null;
14617
14618 -- Body acts as spec
14619
14620 elsif Nkind (Subp_Decl) = N_Subprogram_Body
14621 and then No (Corresponding_Spec (Subp_Decl))
14622 then
14623 null;
14624
14625 -- Body stub acts as spec
14626
14627 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
14628 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
14629 then
14630 null;
14631
14632 -- Subprogram
14633
14634 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
14635 Subp_Spec := Specification (Subp_Decl);
14636
14637 -- Pragma Contract_Cases is forbidden on null procedures, as
14638 -- this may lead to potential ambiguities in behavior when
14639 -- interface null procedures are involved.
14640
14641 if Nkind (Subp_Spec) = N_Procedure_Specification
14642 and then Null_Present (Subp_Spec)
14643 then
14644 Error_Msg_N (Fix_Error
14645 ("pragma % cannot apply to null procedure"), N);
14646 return;
14647 end if;
14648
14649 else
14650 Pragma_Misplaced;
14651 end if;
14652
14653 Spec_Id := Unique_Defining_Entity (Subp_Decl);
14654
14655 -- A pragma that applies to a Ghost entity becomes Ghost for the
14656 -- purposes of legality checks and removal of ignored Ghost code.
14657
14658 Mark_Ghost_Pragma (N, Spec_Id);
14659 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
14660
14661 -- Chain the pragma on the contract for further processing by
14662 -- Analyze_Contract_Cases_In_Decl_Part.
14663
14664 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
14665
14666 -- Fully analyze the pragma when it appears inside an entry
14667 -- or subprogram body because it cannot benefit from forward
14668 -- references.
14669
14670 if Nkind (Subp_Decl) in N_Entry_Body
14671 | N_Subprogram_Body
14672 | N_Subprogram_Body_Stub
14673 then
14674 -- The legality checks of pragma Contract_Cases are affected by
14675 -- the SPARK mode in effect and the volatility of the context.
14676 -- Analyze all pragmas in a specific order.
14677
14678 Analyze_If_Present (Pragma_SPARK_Mode);
14679 Analyze_If_Present (Pragma_Volatile_Function);
14680 Analyze_Contract_Cases_In_Decl_Part (N);
14681 end if;
14682 end Contract_Cases;
14683
14684 ----------------
14685 -- Controlled --
14686 ----------------
14687
14688 -- pragma Controlled (first_subtype_LOCAL_NAME);
14689
14690 when Pragma_Controlled => Controlled : declare
14691 Arg : Node_Id;
14692
14693 begin
14694 Check_No_Identifiers;
14695 Check_Arg_Count (1);
14696 Check_Arg_Is_Local_Name (Arg1);
14697 Arg := Get_Pragma_Arg (Arg1);
14698
14699 if not Is_Entity_Name (Arg)
14700 or else not Is_Access_Type (Entity (Arg))
14701 then
14702 Error_Pragma_Arg ("pragma% requires access type", Arg1);
14703 else
14704 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
14705 end if;
14706 end Controlled;
14707
14708 ----------------
14709 -- Convention --
14710 ----------------
14711
14712 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
14713 -- [Entity =>] LOCAL_NAME);
14714
14715 when Pragma_Convention => Convention : declare
14716 C : Convention_Id;
14717 E : Entity_Id;
14718 pragma Warnings (Off, C);
14719 pragma Warnings (Off, E);
14720
14721 begin
14722 Check_Arg_Order ((Name_Convention, Name_Entity));
14723 Check_Ada_83_Warning;
14724 Check_Arg_Count (2);
14725 Process_Convention (C, E);
14726
14727 -- A pragma that applies to a Ghost entity becomes Ghost for the
14728 -- purposes of legality checks and removal of ignored Ghost code.
14729
14730 Mark_Ghost_Pragma (N, E);
14731 end Convention;
14732
14733 ---------------------------
14734 -- Convention_Identifier --
14735 ---------------------------
14736
14737 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
14738 -- [Convention =>] convention_IDENTIFIER);
14739
14740 when Pragma_Convention_Identifier => Convention_Identifier : declare
14741 Idnam : Name_Id;
14742 Cname : Name_Id;
14743
14744 begin
14745 GNAT_Pragma;
14746 Check_Arg_Order ((Name_Name, Name_Convention));
14747 Check_Arg_Count (2);
14748 Check_Optional_Identifier (Arg1, Name_Name);
14749 Check_Optional_Identifier (Arg2, Name_Convention);
14750 Check_Arg_Is_Identifier (Arg1);
14751 Check_Arg_Is_Identifier (Arg2);
14752 Idnam := Chars (Get_Pragma_Arg (Arg1));
14753 Cname := Chars (Get_Pragma_Arg (Arg2));
14754
14755 if Is_Convention_Name (Cname) then
14756 Record_Convention_Identifier
14757 (Idnam, Get_Convention_Id (Cname));
14758 else
14759 Error_Pragma_Arg
14760 ("second arg for % pragma must be convention", Arg2);
14761 end if;
14762 end Convention_Identifier;
14763
14764 ---------------
14765 -- CPP_Class --
14766 ---------------
14767
14768 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
14769
14770 when Pragma_CPP_Class =>
14771 GNAT_Pragma;
14772
14773 if Warn_On_Obsolescent_Feature then
14774 Error_Msg_N
14775 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
14776 & "effect; replace it by pragma import?j?", N);
14777 end if;
14778
14779 Check_Arg_Count (1);
14780
14781 Rewrite (N,
14782 Make_Pragma (Loc,
14783 Chars => Name_Import,
14784 Pragma_Argument_Associations => New_List (
14785 Make_Pragma_Argument_Association (Loc,
14786 Expression => Make_Identifier (Loc, Name_CPP)),
14787 New_Copy (First (Pragma_Argument_Associations (N))))));
14788 Analyze (N);
14789
14790 ---------------------
14791 -- CPP_Constructor --
14792 ---------------------
14793
14794 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
14795 -- [, [External_Name =>] static_string_EXPRESSION ]
14796 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14797
14798 when Pragma_CPP_Constructor => CPP_Constructor : declare
14799 Id : Entity_Id;
14800 Def_Id : Entity_Id;
14801 Tag_Typ : Entity_Id;
14802
14803 begin
14804 GNAT_Pragma;
14805 Check_At_Least_N_Arguments (1);
14806 Check_At_Most_N_Arguments (3);
14807 Check_Optional_Identifier (Arg1, Name_Entity);
14808 Check_Arg_Is_Local_Name (Arg1);
14809
14810 Id := Get_Pragma_Arg (Arg1);
14811 Find_Program_Unit_Name (Id);
14812
14813 -- If we did not find the name, we are done
14814
14815 if Etype (Id) = Any_Type then
14816 return;
14817 end if;
14818
14819 Def_Id := Entity (Id);
14820
14821 -- Check if already defined as constructor
14822
14823 if Is_Constructor (Def_Id) then
14824 Error_Msg_N
14825 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
14826 return;
14827 end if;
14828
14829 if Ekind (Def_Id) = E_Function
14830 and then (Is_CPP_Class (Etype (Def_Id))
14831 or else (Is_Class_Wide_Type (Etype (Def_Id))
14832 and then
14833 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
14834 then
14835 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
14836 Error_Msg_N
14837 ("'C'P'P constructor must be defined in the scope of "
14838 & "its returned type", Arg1);
14839 end if;
14840
14841 if Arg_Count >= 2 then
14842 Set_Imported (Def_Id);
14843 Set_Is_Public (Def_Id);
14844 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
14845 end if;
14846
14847 Set_Has_Completion (Def_Id);
14848 Set_Is_Constructor (Def_Id);
14849 Set_Convention (Def_Id, Convention_CPP);
14850
14851 -- Imported C++ constructors are not dispatching primitives
14852 -- because in C++ they don't have a dispatch table slot.
14853 -- However, in Ada the constructor has the profile of a
14854 -- function that returns a tagged type and therefore it has
14855 -- been treated as a primitive operation during semantic
14856 -- analysis. We now remove it from the list of primitive
14857 -- operations of the type.
14858
14859 if Is_Tagged_Type (Etype (Def_Id))
14860 and then not Is_Class_Wide_Type (Etype (Def_Id))
14861 and then Is_Dispatching_Operation (Def_Id)
14862 then
14863 Tag_Typ := Etype (Def_Id);
14864
14865 Remove (Primitive_Operations (Tag_Typ), Def_Id);
14866 Set_Is_Dispatching_Operation (Def_Id, False);
14867 end if;
14868
14869 -- For backward compatibility, if the constructor returns a
14870 -- class wide type, and we internally change the return type to
14871 -- the corresponding root type.
14872
14873 if Is_Class_Wide_Type (Etype (Def_Id)) then
14874 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
14875 end if;
14876 else
14877 Error_Pragma_Arg
14878 ("pragma% requires function returning a 'C'P'P_Class type",
14879 Arg1);
14880 end if;
14881 end CPP_Constructor;
14882
14883 -----------------
14884 -- CPP_Virtual --
14885 -----------------
14886
14887 when Pragma_CPP_Virtual =>
14888 GNAT_Pragma;
14889
14890 if Warn_On_Obsolescent_Feature then
14891 Error_Msg_N
14892 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
14893 & "effect?j?", N);
14894 end if;
14895
14896 -----------------
14897 -- CUDA_Device --
14898 -----------------
14899
14900 when Pragma_CUDA_Device => CUDA_Device : declare
14901 Arg_Node : Node_Id;
14902 Device_Entity : Entity_Id;
14903 begin
14904 GNAT_Pragma;
14905 Check_Arg_Count (1);
14906 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14907
14908 Arg_Node := Get_Pragma_Arg (Arg1);
14909 Device_Entity := Entity (Arg_Node);
14910
14911 if Ekind (Device_Entity) in E_Variable
14912 | E_Constant
14913 | E_Procedure
14914 | E_Function
14915 then
14916 Add_CUDA_Device_Entity
14917 (Package_Specification_Of_Scope (Scope (Device_Entity)),
14918 Device_Entity);
14919
14920 else
14921 Error_Msg_NE ("& must be constant, variable or subprogram",
14922 N,
14923 Device_Entity);
14924 end if;
14925
14926 end CUDA_Device;
14927
14928 ------------------
14929 -- CUDA_Execute --
14930 ------------------
14931
14932 -- pragma CUDA_Execute (PROCEDURE_CALL_STATEMENT,
14933 -- EXPRESSION,
14934 -- EXPRESSION,
14935 -- [, EXPRESSION
14936 -- [, EXPRESSION]]);
14937
14938 when Pragma_CUDA_Execute => CUDA_Execute : declare
14939
14940 function Is_Acceptable_Dim3 (N : Node_Id) return Boolean;
14941 -- Returns True if N is an acceptable argument for CUDA_Execute,
14942 -- False otherwise.
14943
14944 ------------------------
14945 -- Is_Acceptable_Dim3 --
14946 ------------------------
14947
14948 function Is_Acceptable_Dim3 (N : Node_Id) return Boolean is
14949 Expr : Node_Id;
14950 begin
14951 if Is_RTE (Etype (N), RE_Dim3)
14952 or else Is_Integer_Type (Etype (N))
14953 then
14954 return True;
14955 end if;
14956
14957 if Nkind (N) = N_Aggregate
14958 and then not Null_Record_Present (N)
14959 and then No (Component_Associations (N))
14960 and then List_Length (Expressions (N)) = 3
14961 then
14962 Expr := First (Expressions (N));
14963 while Present (Expr) loop
14964 Analyze_And_Resolve (Expr, Any_Integer);
14965 Next (Expr);
14966 end loop;
14967 return True;
14968 end if;
14969
14970 return False;
14971 end Is_Acceptable_Dim3;
14972
14973 -- Local variables
14974
14975 Block_Dimensions : constant Node_Id := Get_Pragma_Arg (Arg3);
14976 Grid_Dimensions : constant Node_Id := Get_Pragma_Arg (Arg2);
14977 Kernel_Call : constant Node_Id := Get_Pragma_Arg (Arg1);
14978 Shared_Memory : Node_Id;
14979 Stream : Node_Id;
14980
14981 -- Start of processing for CUDA_Execute
14982
14983 begin
14984 GNAT_Pragma;
14985 Check_At_Least_N_Arguments (3);
14986 Check_At_Most_N_Arguments (5);
14987
14988 Analyze_And_Resolve (Kernel_Call);
14989 if Nkind (Kernel_Call) /= N_Function_Call
14990 or else Etype (Kernel_Call) /= Standard_Void_Type
14991 then
14992 -- In `pragma CUDA_Execute (Kernel_Call (...), ...)`,
14993 -- GNAT sees Kernel_Call as an N_Function_Call since
14994 -- Kernel_Call "looks" like an expression. However, only
14995 -- procedures can be kernels, so to make things easier for the
14996 -- user the error message complains about Kernel_Call not being
14997 -- a procedure call.
14998
14999 Error_Msg_N ("first argument of & must be a procedure call", N);
15000 end if;
15001
15002 Analyze (Grid_Dimensions);
15003 if not Is_Acceptable_Dim3 (Grid_Dimensions) then
15004 Error_Msg_N
15005 ("second argument of & must be an Integer, Dim3 or aggregate "
15006 & "containing 3 Integers", N);
15007 end if;
15008
15009 Analyze (Block_Dimensions);
15010 if not Is_Acceptable_Dim3 (Block_Dimensions) then
15011 Error_Msg_N
15012 ("third argument of & must be an Integer, Dim3 or aggregate "
15013 & "containing 3 Integers", N);
15014 end if;
15015
15016 if Present (Arg4) then
15017 Shared_Memory := Get_Pragma_Arg (Arg4);
15018 Analyze_And_Resolve (Shared_Memory, Any_Integer);
15019
15020 if Present (Arg5) then
15021 Stream := Get_Pragma_Arg (Arg5);
15022 Analyze_And_Resolve (Stream, RTE (RE_Stream_T));
15023 end if;
15024 end if;
15025 end CUDA_Execute;
15026
15027 -----------------
15028 -- CUDA_Global --
15029 -----------------
15030
15031 -- pragma CUDA_Global ([Entity =>] IDENTIFIER);
15032
15033 when Pragma_CUDA_Global => CUDA_Global : declare
15034 Arg_Node : Node_Id;
15035 Kernel_Proc : Entity_Id;
15036 Pack_Id : Entity_Id;
15037 begin
15038 GNAT_Pragma;
15039 Check_Arg_Count (1);
15040 Check_Optional_Identifier (Arg1, Name_Entity);
15041 Check_Arg_Is_Local_Name (Arg1);
15042
15043 Arg_Node := Get_Pragma_Arg (Arg1);
15044 Analyze (Arg_Node);
15045
15046 Kernel_Proc := Entity (Arg_Node);
15047 Pack_Id := Scope (Kernel_Proc);
15048
15049 if Ekind (Kernel_Proc) /= E_Procedure then
15050 Error_Msg_NE ("& must be a procedure", N, Kernel_Proc);
15051
15052 elsif Ekind (Pack_Id) /= E_Package
15053 or else not Is_Library_Level_Entity (Pack_Id)
15054 then
15055 Error_Msg_NE
15056 ("& must reside in a library-level package", N, Kernel_Proc);
15057
15058 else
15059 Set_Is_CUDA_Kernel (Kernel_Proc);
15060 Add_CUDA_Kernel (Pack_Id, Kernel_Proc);
15061 end if;
15062 end CUDA_Global;
15063
15064 ----------------
15065 -- CPP_Vtable --
15066 ----------------
15067
15068 when Pragma_CPP_Vtable =>
15069 GNAT_Pragma;
15070
15071 if Warn_On_Obsolescent_Feature then
15072 Error_Msg_N
15073 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
15074 & "effect?j?", N);
15075 end if;
15076
15077 ---------
15078 -- CPU --
15079 ---------
15080
15081 -- pragma CPU (EXPRESSION);
15082
15083 when Pragma_CPU => CPU : declare
15084 P : constant Node_Id := Parent (N);
15085 Arg : Node_Id;
15086 Ent : Entity_Id;
15087
15088 begin
15089 Ada_2012_Pragma;
15090 Check_No_Identifiers;
15091 Check_Arg_Count (1);
15092 Arg := Get_Pragma_Arg (Arg1);
15093
15094 -- Subprogram case
15095
15096 if Nkind (P) = N_Subprogram_Body then
15097 Check_In_Main_Program;
15098
15099 Analyze_And_Resolve (Arg, Any_Integer);
15100
15101 Ent := Defining_Unit_Name (Specification (P));
15102
15103 if Nkind (Ent) = N_Defining_Program_Unit_Name then
15104 Ent := Defining_Identifier (Ent);
15105 end if;
15106
15107 -- Must be static
15108
15109 if not Is_OK_Static_Expression (Arg) then
15110 Flag_Non_Static_Expr
15111 ("main subprogram affinity is not static!", Arg);
15112 raise Pragma_Exit;
15113
15114 -- If constraint error, then we already signalled an error
15115
15116 elsif Raises_Constraint_Error (Arg) then
15117 null;
15118
15119 -- Otherwise check in range
15120
15121 else
15122 declare
15123 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
15124 -- This is the entity System.Multiprocessors.CPU_Range;
15125
15126 Val : constant Uint := Expr_Value (Arg);
15127
15128 begin
15129 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
15130 or else
15131 Val > Expr_Value (Type_High_Bound (CPU_Id))
15132 then
15133 Error_Pragma_Arg
15134 ("main subprogram CPU is out of range", Arg1);
15135 end if;
15136 end;
15137 end if;
15138
15139 Set_Main_CPU
15140 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
15141
15142 -- Task case
15143
15144 elsif Nkind (P) = N_Task_Definition then
15145 Ent := Defining_Identifier (Parent (P));
15146
15147 -- The expression must be analyzed in the special manner
15148 -- described in "Handling of Default and Per-Object
15149 -- Expressions" in sem.ads.
15150
15151 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
15152
15153 -- See comment in Sem_Ch13 about the following restrictions
15154
15155 if Is_OK_Static_Expression (Arg) then
15156 if Expr_Value (Arg) = Uint_0 then
15157 Check_Restriction (No_Tasks_Unassigned_To_CPU, N);
15158 end if;
15159 else
15160 Check_Restriction (No_Dynamic_CPU_Assignment, N);
15161 end if;
15162
15163 -- Anything else is incorrect
15164
15165 else
15166 Pragma_Misplaced;
15167 end if;
15168
15169 -- Check duplicate pragma before we chain the pragma in the Rep
15170 -- Item chain of Ent.
15171
15172 Check_Duplicate_Pragma (Ent);
15173 Record_Rep_Item (Ent, N);
15174 end CPU;
15175
15176 --------------------
15177 -- Deadline_Floor --
15178 --------------------
15179
15180 -- pragma Deadline_Floor (time_span_EXPRESSION);
15181
15182 when Pragma_Deadline_Floor => Deadline_Floor : declare
15183 P : constant Node_Id := Parent (N);
15184 Arg : Node_Id;
15185 Ent : Entity_Id;
15186
15187 begin
15188 GNAT_Pragma;
15189 Check_No_Identifiers;
15190 Check_Arg_Count (1);
15191
15192 Arg := Get_Pragma_Arg (Arg1);
15193
15194 -- The expression must be analyzed in the special manner described
15195 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
15196
15197 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
15198
15199 -- Only protected types allowed
15200
15201 if Nkind (P) /= N_Protected_Definition then
15202 Pragma_Misplaced;
15203
15204 else
15205 Ent := Defining_Identifier (Parent (P));
15206
15207 -- Check duplicate pragma before we chain the pragma in the Rep
15208 -- Item chain of Ent.
15209
15210 Check_Duplicate_Pragma (Ent);
15211 Record_Rep_Item (Ent, N);
15212 end if;
15213 end Deadline_Floor;
15214
15215 -----------
15216 -- Debug --
15217 -----------
15218
15219 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
15220
15221 when Pragma_Debug => Debug : declare
15222 Cond : Node_Id;
15223 Call : Node_Id;
15224
15225 begin
15226 GNAT_Pragma;
15227
15228 -- The condition for executing the call is that the expander
15229 -- is active and that we are not ignoring this debug pragma.
15230
15231 Cond :=
15232 New_Occurrence_Of
15233 (Boolean_Literals
15234 (Expander_Active and then not Is_Ignored (N)),
15235 Loc);
15236
15237 if not Is_Ignored (N) then
15238 Set_SCO_Pragma_Enabled (Loc);
15239 end if;
15240
15241 if Arg_Count = 2 then
15242 Cond :=
15243 Make_And_Then (Loc,
15244 Left_Opnd => Relocate_Node (Cond),
15245 Right_Opnd => Get_Pragma_Arg (Arg1));
15246 Call := Get_Pragma_Arg (Arg2);
15247 else
15248 Call := Get_Pragma_Arg (Arg1);
15249 end if;
15250
15251 if Nkind (Call) in N_Expanded_Name
15252 | N_Function_Call
15253 | N_Identifier
15254 | N_Indexed_Component
15255 | N_Selected_Component
15256 then
15257 -- If this pragma Debug comes from source, its argument was
15258 -- parsed as a name form (which is syntactically identical).
15259 -- In a generic context a parameterless call will be left as
15260 -- an expanded name (if global) or selected_component if local.
15261 -- Change it to a procedure call statement now.
15262
15263 Change_Name_To_Procedure_Call_Statement (Call);
15264
15265 elsif Nkind (Call) = N_Procedure_Call_Statement then
15266
15267 -- Already in the form of a procedure call statement: nothing
15268 -- to do (could happen in case of an internally generated
15269 -- pragma Debug).
15270
15271 null;
15272
15273 else
15274 -- All other cases: diagnose error
15275
15276 Error_Msg_N
15277 ("argument of pragma ""Debug"" is not procedure call", Call);
15278 return;
15279 end if;
15280
15281 -- Rewrite into a conditional with an appropriate condition. We
15282 -- wrap the procedure call in a block so that overhead from e.g.
15283 -- use of the secondary stack does not generate execution overhead
15284 -- for suppressed conditions.
15285
15286 -- Normally the analysis that follows will freeze the subprogram
15287 -- being called. However, if the call is to a null procedure,
15288 -- we want to freeze it before creating the block, because the
15289 -- analysis that follows may be done with expansion disabled, in
15290 -- which case the body will not be generated, leading to spurious
15291 -- errors.
15292
15293 if Nkind (Call) = N_Procedure_Call_Statement
15294 and then Is_Entity_Name (Name (Call))
15295 then
15296 Analyze (Name (Call));
15297 Freeze_Before (N, Entity (Name (Call)));
15298 end if;
15299
15300 Rewrite (N,
15301 Make_Implicit_If_Statement (N,
15302 Condition => Cond,
15303 Then_Statements => New_List (
15304 Make_Block_Statement (Loc,
15305 Handled_Statement_Sequence =>
15306 Make_Handled_Sequence_Of_Statements (Loc,
15307 Statements => New_List (Relocate_Node (Call)))))));
15308 Analyze (N);
15309
15310 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
15311 -- after analysis of the normally rewritten node, to capture all
15312 -- references to entities, which avoids issuing wrong warnings
15313 -- about unused entities.
15314
15315 if GNATprove_Mode then
15316 Rewrite (N, Make_Null_Statement (Loc));
15317 end if;
15318 end Debug;
15319
15320 ------------------
15321 -- Debug_Policy --
15322 ------------------
15323
15324 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
15325
15326 when Pragma_Debug_Policy =>
15327 GNAT_Pragma;
15328 Check_Arg_Count (1);
15329 Check_No_Identifiers;
15330 Check_Arg_Is_Identifier (Arg1);
15331
15332 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
15333 -- rewrite it that way, and let the rest of the checking come
15334 -- from analyzing the rewritten pragma.
15335
15336 Rewrite (N,
15337 Make_Pragma (Loc,
15338 Chars => Name_Check_Policy,
15339 Pragma_Argument_Associations => New_List (
15340 Make_Pragma_Argument_Association (Loc,
15341 Expression => Make_Identifier (Loc, Name_Debug)),
15342
15343 Make_Pragma_Argument_Association (Loc,
15344 Expression => Get_Pragma_Arg (Arg1)))));
15345 Analyze (N);
15346
15347 -------------------------------
15348 -- Default_Initial_Condition --
15349 -------------------------------
15350
15351 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
15352
15353 when Pragma_Default_Initial_Condition => DIC : declare
15354 Discard : Boolean;
15355 Stmt : Node_Id;
15356 Typ : Entity_Id;
15357
15358 begin
15359 GNAT_Pragma;
15360 Check_No_Identifiers;
15361 Check_At_Most_N_Arguments (2); -- Accounts for implicit type arg
15362
15363 Typ := Empty;
15364 Stmt := Prev (N);
15365 while Present (Stmt) loop
15366
15367 -- Skip prior pragmas, but check for duplicates
15368
15369 if Nkind (Stmt) = N_Pragma then
15370 if Pragma_Name (Stmt) = Pname then
15371 Duplication_Error
15372 (Prag => N,
15373 Prev => Stmt);
15374 raise Pragma_Exit;
15375 end if;
15376
15377 -- Skip internally generated code. Note that derived type
15378 -- declarations of untagged types with discriminants are
15379 -- rewritten as private type declarations.
15380
15381 elsif not Comes_From_Source (Stmt)
15382 and then Nkind (Stmt) /= N_Private_Type_Declaration
15383 then
15384 null;
15385
15386 -- The associated private type [extension] has been found, stop
15387 -- the search.
15388
15389 elsif Nkind (Stmt) in N_Private_Extension_Declaration
15390 | N_Private_Type_Declaration
15391 then
15392 Typ := Defining_Entity (Stmt);
15393 exit;
15394
15395 -- The pragma does not apply to a legal construct, issue an
15396 -- error and stop the analysis.
15397
15398 else
15399 Pragma_Misplaced;
15400 end if;
15401
15402 Stmt := Prev (Stmt);
15403 end loop;
15404
15405 -- The pragma does not apply to a legal construct, issue an error
15406 -- and stop the analysis.
15407
15408 if No (Typ) then
15409 Pragma_Misplaced;
15410 end if;
15411
15412 -- A pragma that applies to a Ghost entity becomes Ghost for the
15413 -- purposes of legality checks and removal of ignored Ghost code.
15414
15415 Mark_Ghost_Pragma (N, Typ);
15416
15417 -- The pragma signals that the type defines its own DIC assertion
15418 -- expression.
15419
15420 Set_Has_Own_DIC (Typ);
15421
15422 -- A type entity argument is appended to facilitate inheriting the
15423 -- aspect/pragma from parent types (see Build_DIC_Procedure_Body),
15424 -- though that extra argument isn't documented for the pragma.
15425
15426 if No (Arg2) then
15427 -- When the pragma has no arguments, create an argument with
15428 -- the value Empty, so the type name argument can be appended
15429 -- following it (since it's expected as the second argument).
15430
15431 if No (Arg1) then
15432 Set_Pragma_Argument_Associations (N, New_List (
15433 Make_Pragma_Argument_Association (Sloc (Typ),
15434 Expression => Empty)));
15435 end if;
15436
15437 Append_To
15438 (Pragma_Argument_Associations (N),
15439 Make_Pragma_Argument_Association (Sloc (Typ),
15440 Expression => New_Occurrence_Of (Typ, Sloc (Typ))));
15441 end if;
15442
15443 -- Chain the pragma on the rep item chain for further processing
15444
15445 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15446
15447 -- Create the declaration of the procedure which verifies the
15448 -- assertion expression of pragma DIC at runtime.
15449
15450 Build_DIC_Procedure_Declaration (Typ);
15451 end DIC;
15452
15453 ----------------------------------
15454 -- Default_Scalar_Storage_Order --
15455 ----------------------------------
15456
15457 -- pragma Default_Scalar_Storage_Order
15458 -- (High_Order_First | Low_Order_First);
15459
15460 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
15461 Default : Character;
15462
15463 begin
15464 GNAT_Pragma;
15465 Check_Arg_Count (1);
15466
15467 -- Default_Scalar_Storage_Order can appear as a configuration
15468 -- pragma, or in a declarative part of a package spec.
15469
15470 if not Is_Configuration_Pragma then
15471 Check_Is_In_Decl_Part_Or_Package_Spec;
15472 end if;
15473
15474 Check_No_Identifiers;
15475 Check_Arg_Is_One_Of
15476 (Arg1, Name_High_Order_First, Name_Low_Order_First);
15477 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15478 Default := Fold_Upper (Name_Buffer (1));
15479
15480 if not Support_Nondefault_SSO_On_Target
15481 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
15482 then
15483 if Warn_On_Unrecognized_Pragma then
15484 Error_Msg_N
15485 ("non-default Scalar_Storage_Order not supported "
15486 & "on target?g?", N);
15487 Error_Msg_N
15488 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
15489 end if;
15490
15491 -- Here set the specified default
15492
15493 else
15494 Opt.Default_SSO := Default;
15495 end if;
15496 end DSSO;
15497
15498 --------------------------
15499 -- Default_Storage_Pool --
15500 --------------------------
15501
15502 -- pragma Default_Storage_Pool (storage_pool_NAME | null | Standard);
15503
15504 when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
15505 Pool : Node_Id;
15506
15507 begin
15508 Ada_2012_Pragma;
15509 Check_Arg_Count (1);
15510
15511 -- Default_Storage_Pool can appear as a configuration pragma, or
15512 -- in a declarative part of a package spec.
15513
15514 if not Is_Configuration_Pragma then
15515 Check_Is_In_Decl_Part_Or_Package_Spec;
15516 end if;
15517
15518 if From_Aspect_Specification (N) then
15519 declare
15520 E : constant Entity_Id := Entity (Corresponding_Aspect (N));
15521 begin
15522 if not In_Open_Scopes (E) then
15523 Error_Msg_N
15524 ("aspect must apply to package or subprogram", N);
15525 end if;
15526 end;
15527 end if;
15528
15529 if Present (Arg1) then
15530 Pool := Get_Pragma_Arg (Arg1);
15531
15532 -- Case of Default_Storage_Pool (null);
15533
15534 if Nkind (Pool) = N_Null then
15535 Analyze (Pool);
15536
15537 -- This is an odd case, this is not really an expression,
15538 -- so we don't have a type for it. So just set the type to
15539 -- Empty.
15540
15541 Set_Etype (Pool, Empty);
15542
15543 -- Case of Default_Storage_Pool (Standard);
15544
15545 elsif Nkind (Pool) = N_Identifier
15546 and then Chars (Pool) = Name_Standard
15547 then
15548 Analyze (Pool);
15549
15550 if Entity (Pool) /= Standard_Standard then
15551 Error_Pragma_Arg
15552 ("package Standard is not directly visible", Arg1);
15553 end if;
15554
15555 -- Case of Default_Storage_Pool (storage_pool_NAME);
15556
15557 else
15558 -- If it's a configuration pragma, then the only allowed
15559 -- argument is "null".
15560
15561 if Is_Configuration_Pragma then
15562 Error_Pragma_Arg ("NULL or Standard expected", Arg1);
15563 end if;
15564
15565 -- The expected type for a non-"null" argument is
15566 -- Root_Storage_Pool'Class, and the pool must be a variable.
15567
15568 Analyze_And_Resolve
15569 (Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
15570
15571 if Is_Variable (Pool) then
15572
15573 -- A pragma that applies to a Ghost entity becomes Ghost
15574 -- for the purposes of legality checks and removal of
15575 -- ignored Ghost code.
15576
15577 Mark_Ghost_Pragma (N, Entity (Pool));
15578
15579 else
15580 Error_Pragma_Arg
15581 ("default storage pool must be a variable", Arg1);
15582 end if;
15583 end if;
15584
15585 -- Record the pool name (or null). Freeze.Freeze_Entity for an
15586 -- access type will use this information to set the appropriate
15587 -- attributes of the access type. If the pragma appears in a
15588 -- generic unit it is ignored, given that it may refer to a
15589 -- local entity.
15590
15591 if not Inside_A_Generic then
15592 Default_Pool := Pool;
15593 end if;
15594 end if;
15595 end Default_Storage_Pool;
15596
15597 -------------
15598 -- Depends --
15599 -------------
15600
15601 -- pragma Depends (DEPENDENCY_RELATION);
15602
15603 -- DEPENDENCY_RELATION ::=
15604 -- null
15605 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
15606
15607 -- DEPENDENCY_CLAUSE ::=
15608 -- OUTPUT_LIST =>[+] INPUT_LIST
15609 -- | NULL_DEPENDENCY_CLAUSE
15610
15611 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
15612
15613 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
15614
15615 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
15616
15617 -- OUTPUT ::= NAME | FUNCTION_RESULT
15618 -- INPUT ::= NAME
15619
15620 -- where FUNCTION_RESULT is a function Result attribute_reference
15621
15622 -- Characteristics:
15623
15624 -- * Analysis - The annotation undergoes initial checks to verify
15625 -- the legal placement and context. Secondary checks fully analyze
15626 -- the dependency clauses in:
15627
15628 -- Analyze_Depends_In_Decl_Part
15629
15630 -- * Expansion - None.
15631
15632 -- * Template - The annotation utilizes the generic template of the
15633 -- related subprogram [body] when it is:
15634
15635 -- aspect on subprogram declaration
15636 -- aspect on stand-alone subprogram body
15637 -- pragma on stand-alone subprogram body
15638
15639 -- The annotation must prepare its own template when it is:
15640
15641 -- pragma on subprogram declaration
15642
15643 -- * Globals - Capture of global references must occur after full
15644 -- analysis.
15645
15646 -- * Instance - The annotation is instantiated automatically when
15647 -- the related generic subprogram [body] is instantiated except for
15648 -- the "pragma on subprogram declaration" case. In that scenario
15649 -- the annotation must instantiate itself.
15650
15651 when Pragma_Depends => Depends : declare
15652 Legal : Boolean;
15653 Spec_Id : Entity_Id;
15654 Subp_Decl : Node_Id;
15655
15656 begin
15657 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
15658
15659 if Legal then
15660
15661 -- Chain the pragma on the contract for further processing by
15662 -- Analyze_Depends_In_Decl_Part.
15663
15664 Add_Contract_Item (N, Spec_Id);
15665
15666 -- Fully analyze the pragma when it appears inside an entry
15667 -- or subprogram body because it cannot benefit from forward
15668 -- references.
15669
15670 if Nkind (Subp_Decl) in N_Entry_Body
15671 | N_Subprogram_Body
15672 | N_Subprogram_Body_Stub
15673 then
15674 -- The legality checks of pragmas Depends and Global are
15675 -- affected by the SPARK mode in effect and the volatility
15676 -- of the context. In addition these two pragmas are subject
15677 -- to an inherent order:
15678
15679 -- 1) Global
15680 -- 2) Depends
15681
15682 -- Analyze all these pragmas in the order outlined above
15683
15684 Analyze_If_Present (Pragma_SPARK_Mode);
15685 Analyze_If_Present (Pragma_Volatile_Function);
15686 Analyze_If_Present (Pragma_Global);
15687 Analyze_Depends_In_Decl_Part (N);
15688 end if;
15689 end if;
15690 end Depends;
15691
15692 ---------------------
15693 -- Detect_Blocking --
15694 ---------------------
15695
15696 -- pragma Detect_Blocking;
15697
15698 when Pragma_Detect_Blocking =>
15699 Ada_2005_Pragma;
15700 Check_Arg_Count (0);
15701 Check_Valid_Configuration_Pragma;
15702 Detect_Blocking := True;
15703
15704 ------------------------------------
15705 -- Disable_Atomic_Synchronization --
15706 ------------------------------------
15707
15708 -- pragma Disable_Atomic_Synchronization [(Entity)];
15709
15710 when Pragma_Disable_Atomic_Synchronization =>
15711 GNAT_Pragma;
15712 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
15713
15714 -------------------
15715 -- Discard_Names --
15716 -------------------
15717
15718 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
15719
15720 when Pragma_Discard_Names => Discard_Names : declare
15721 E : Entity_Id;
15722 E_Id : Node_Id;
15723
15724 begin
15725 Check_Ada_83_Warning;
15726
15727 -- Deal with configuration pragma case
15728
15729 if Arg_Count = 0 and then Is_Configuration_Pragma then
15730 Global_Discard_Names := True;
15731 return;
15732
15733 -- Otherwise, check correct appropriate context
15734
15735 else
15736 Check_Is_In_Decl_Part_Or_Package_Spec;
15737
15738 if Arg_Count = 0 then
15739
15740 -- If there is no parameter, then from now on this pragma
15741 -- applies to any enumeration, exception or tagged type
15742 -- defined in the current declarative part, and recursively
15743 -- to any nested scope.
15744
15745 Set_Discard_Names (Current_Scope);
15746 return;
15747
15748 else
15749 Check_Arg_Count (1);
15750 Check_Optional_Identifier (Arg1, Name_On);
15751 Check_Arg_Is_Local_Name (Arg1);
15752
15753 E_Id := Get_Pragma_Arg (Arg1);
15754
15755 if Etype (E_Id) = Any_Type then
15756 return;
15757 end if;
15758
15759 E := Entity (E_Id);
15760
15761 -- A pragma that applies to a Ghost entity becomes Ghost for
15762 -- the purposes of legality checks and removal of ignored
15763 -- Ghost code.
15764
15765 Mark_Ghost_Pragma (N, E);
15766
15767 if (Is_First_Subtype (E)
15768 and then
15769 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
15770 or else Ekind (E) = E_Exception
15771 then
15772 Set_Discard_Names (E);
15773 Record_Rep_Item (E, N);
15774
15775 else
15776 Error_Pragma_Arg
15777 ("inappropriate entity for pragma%", Arg1);
15778 end if;
15779 end if;
15780 end if;
15781 end Discard_Names;
15782
15783 ------------------------
15784 -- Dispatching_Domain --
15785 ------------------------
15786
15787 -- pragma Dispatching_Domain (EXPRESSION);
15788
15789 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
15790 P : constant Node_Id := Parent (N);
15791 Arg : Node_Id;
15792 Ent : Entity_Id;
15793
15794 begin
15795 Ada_2012_Pragma;
15796 Check_No_Identifiers;
15797 Check_Arg_Count (1);
15798
15799 -- This pragma is born obsolete, but not the aspect
15800
15801 if not From_Aspect_Specification (N) then
15802 Check_Restriction
15803 (No_Obsolescent_Features, Pragma_Identifier (N));
15804 end if;
15805
15806 if Nkind (P) = N_Task_Definition then
15807 Arg := Get_Pragma_Arg (Arg1);
15808 Ent := Defining_Identifier (Parent (P));
15809
15810 -- A pragma that applies to a Ghost entity becomes Ghost for
15811 -- the purposes of legality checks and removal of ignored Ghost
15812 -- code.
15813
15814 Mark_Ghost_Pragma (N, Ent);
15815
15816 -- The expression must be analyzed in the special manner
15817 -- described in "Handling of Default and Per-Object
15818 -- Expressions" in sem.ads.
15819
15820 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
15821
15822 -- Check duplicate pragma before we chain the pragma in the Rep
15823 -- Item chain of Ent.
15824
15825 Check_Duplicate_Pragma (Ent);
15826 Record_Rep_Item (Ent, N);
15827
15828 -- Anything else is incorrect
15829
15830 else
15831 Pragma_Misplaced;
15832 end if;
15833 end Dispatching_Domain;
15834
15835 ---------------
15836 -- Elaborate --
15837 ---------------
15838
15839 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
15840
15841 when Pragma_Elaborate => Elaborate : declare
15842 Arg : Node_Id;
15843 Citem : Node_Id;
15844
15845 begin
15846 -- Pragma must be in context items list of a compilation unit
15847
15848 if not Is_In_Context_Clause then
15849 Pragma_Misplaced;
15850 end if;
15851
15852 -- Must be at least one argument
15853
15854 if Arg_Count = 0 then
15855 Error_Pragma ("pragma% requires at least one argument");
15856 end if;
15857
15858 -- In Ada 83 mode, there can be no items following it in the
15859 -- context list except other pragmas and implicit with clauses
15860 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
15861 -- placement rule does not apply.
15862
15863 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
15864 Citem := Next (N);
15865 while Present (Citem) loop
15866 if Nkind (Citem) = N_Pragma
15867 or else (Nkind (Citem) = N_With_Clause
15868 and then Implicit_With (Citem))
15869 then
15870 null;
15871 else
15872 Error_Pragma
15873 ("(Ada 83) pragma% must be at end of context clause");
15874 end if;
15875
15876 Next (Citem);
15877 end loop;
15878 end if;
15879
15880 -- Finally, the arguments must all be units mentioned in a with
15881 -- clause in the same context clause. Note we already checked (in
15882 -- Par.Prag) that the arguments are all identifiers or selected
15883 -- components.
15884
15885 Arg := Arg1;
15886 Outer : while Present (Arg) loop
15887 Citem := First (List_Containing (N));
15888 Inner : while Citem /= N loop
15889 if Nkind (Citem) = N_With_Clause
15890 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
15891 then
15892 Set_Elaborate_Present (Citem, True);
15893 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
15894
15895 -- With the pragma present, elaboration calls on
15896 -- subprograms from the named unit need no further
15897 -- checks, as long as the pragma appears in the current
15898 -- compilation unit. If the pragma appears in some unit
15899 -- in the context, there might still be a need for an
15900 -- Elaborate_All_Desirable from the current compilation
15901 -- to the named unit, so we keep the check enabled. This
15902 -- does not apply in SPARK mode, where we allow pragma
15903 -- Elaborate, but we don't trust it to be right so we
15904 -- will still insist on the Elaborate_All.
15905
15906 if Legacy_Elaboration_Checks
15907 and then In_Extended_Main_Source_Unit (N)
15908 and then SPARK_Mode /= On
15909 then
15910 Set_Suppress_Elaboration_Warnings
15911 (Entity (Name (Citem)));
15912 end if;
15913
15914 exit Inner;
15915 end if;
15916
15917 Next (Citem);
15918 end loop Inner;
15919
15920 if Citem = N then
15921 Error_Pragma_Arg
15922 ("argument of pragma% is not withed unit", Arg);
15923 end if;
15924
15925 Next (Arg);
15926 end loop Outer;
15927 end Elaborate;
15928
15929 -------------------
15930 -- Elaborate_All --
15931 -------------------
15932
15933 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
15934
15935 when Pragma_Elaborate_All => Elaborate_All : declare
15936 Arg : Node_Id;
15937 Citem : Node_Id;
15938
15939 begin
15940 Check_Ada_83_Warning;
15941
15942 -- Pragma must be in context items list of a compilation unit
15943
15944 if not Is_In_Context_Clause then
15945 Pragma_Misplaced;
15946 end if;
15947
15948 -- Must be at least one argument
15949
15950 if Arg_Count = 0 then
15951 Error_Pragma ("pragma% requires at least one argument");
15952 end if;
15953
15954 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
15955 -- have to appear at the end of the context clause, but may
15956 -- appear mixed in with other items, even in Ada 83 mode.
15957
15958 -- Final check: the arguments must all be units mentioned in
15959 -- a with clause in the same context clause. Note that we
15960 -- already checked (in Par.Prag) that all the arguments are
15961 -- either identifiers or selected components.
15962
15963 Arg := Arg1;
15964 Outr : while Present (Arg) loop
15965 Citem := First (List_Containing (N));
15966 Innr : while Citem /= N loop
15967 if Nkind (Citem) = N_With_Clause
15968 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
15969 then
15970 Set_Elaborate_All_Present (Citem, True);
15971 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
15972
15973 -- Suppress warnings and elaboration checks on the named
15974 -- unit if the pragma is in the current compilation, as
15975 -- for pragma Elaborate.
15976
15977 if Legacy_Elaboration_Checks
15978 and then In_Extended_Main_Source_Unit (N)
15979 then
15980 Set_Suppress_Elaboration_Warnings
15981 (Entity (Name (Citem)));
15982 end if;
15983
15984 exit Innr;
15985 end if;
15986
15987 Next (Citem);
15988 end loop Innr;
15989
15990 if Citem = N then
15991 Error_Pragma_Arg
15992 ("argument of pragma% is not withed unit", Arg);
15993 end if;
15994
15995 Next (Arg);
15996 end loop Outr;
15997 end Elaborate_All;
15998
15999 --------------------
16000 -- Elaborate_Body --
16001 --------------------
16002
16003 -- pragma Elaborate_Body [( library_unit_NAME )];
16004
16005 when Pragma_Elaborate_Body => Elaborate_Body : declare
16006 Cunit_Node : Node_Id;
16007 Cunit_Ent : Entity_Id;
16008
16009 begin
16010 Check_Ada_83_Warning;
16011 Check_Valid_Library_Unit_Pragma;
16012
16013 -- If N was rewritten as a null statement there is nothing more
16014 -- to do.
16015
16016 if Nkind (N) = N_Null_Statement then
16017 return;
16018 end if;
16019
16020 Cunit_Node := Cunit (Current_Sem_Unit);
16021 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
16022
16023 -- A pragma that applies to a Ghost entity becomes Ghost for the
16024 -- purposes of legality checks and removal of ignored Ghost code.
16025
16026 Mark_Ghost_Pragma (N, Cunit_Ent);
16027
16028 if Nkind (Unit (Cunit_Node)) in
16029 N_Package_Body | N_Subprogram_Body
16030 then
16031 Error_Pragma ("pragma% must refer to a spec, not a body");
16032 else
16033 Set_Body_Required (Cunit_Node);
16034 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
16035
16036 -- If we are in dynamic elaboration mode, then we suppress
16037 -- elaboration warnings for the unit, since it is definitely
16038 -- fine NOT to do dynamic checks at the first level (and such
16039 -- checks will be suppressed because no elaboration boolean
16040 -- is created for Elaborate_Body packages).
16041 --
16042 -- But in the static model of elaboration, Elaborate_Body is
16043 -- definitely NOT good enough to ensure elaboration safety on
16044 -- its own, since the body may WITH other units that are not
16045 -- safe from an elaboration point of view, so a client must
16046 -- still do an Elaborate_All on such units.
16047 --
16048 -- Debug flag -gnatdD restores the old behavior of 3.13, where
16049 -- Elaborate_Body always suppressed elab warnings.
16050
16051 if Legacy_Elaboration_Checks
16052 and then (Dynamic_Elaboration_Checks or Debug_Flag_DD)
16053 then
16054 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
16055 end if;
16056 end if;
16057 end Elaborate_Body;
16058
16059 ------------------------
16060 -- Elaboration_Checks --
16061 ------------------------
16062
16063 -- pragma Elaboration_Checks (Static | Dynamic);
16064
16065 when Pragma_Elaboration_Checks => Elaboration_Checks : declare
16066 procedure Check_Duplicate_Elaboration_Checks_Pragma;
16067 -- Emit an error if the current context list already contains
16068 -- a previous Elaboration_Checks pragma. This routine raises
16069 -- Pragma_Exit if a duplicate is found.
16070
16071 procedure Ignore_Elaboration_Checks_Pragma;
16072 -- Warn that the effects of the pragma are ignored. This routine
16073 -- raises Pragma_Exit.
16074
16075 -----------------------------------------------
16076 -- Check_Duplicate_Elaboration_Checks_Pragma --
16077 -----------------------------------------------
16078
16079 procedure Check_Duplicate_Elaboration_Checks_Pragma is
16080 Item : Node_Id;
16081
16082 begin
16083 Item := Prev (N);
16084 while Present (Item) loop
16085 if Nkind (Item) = N_Pragma
16086 and then Pragma_Name (Item) = Name_Elaboration_Checks
16087 then
16088 Duplication_Error
16089 (Prag => N,
16090 Prev => Item);
16091 raise Pragma_Exit;
16092 end if;
16093
16094 Prev (Item);
16095 end loop;
16096 end Check_Duplicate_Elaboration_Checks_Pragma;
16097
16098 --------------------------------------
16099 -- Ignore_Elaboration_Checks_Pragma --
16100 --------------------------------------
16101
16102 procedure Ignore_Elaboration_Checks_Pragma is
16103 begin
16104 Error_Msg_Name_1 := Pname;
16105 Error_Msg_N ("??effects of pragma % are ignored", N);
16106 Error_Msg_N
16107 ("\place pragma on initial declaration of library unit", N);
16108
16109 raise Pragma_Exit;
16110 end Ignore_Elaboration_Checks_Pragma;
16111
16112 -- Local variables
16113
16114 Context : constant Node_Id := Parent (N);
16115 Unt : Node_Id;
16116
16117 -- Start of processing for Elaboration_Checks
16118
16119 begin
16120 GNAT_Pragma;
16121 Check_Arg_Count (1);
16122 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
16123
16124 -- The pragma appears in a configuration file
16125
16126 if No (Context) then
16127 Check_Valid_Configuration_Pragma;
16128 Check_Duplicate_Elaboration_Checks_Pragma;
16129
16130 -- The pragma acts as a configuration pragma in a compilation unit
16131
16132 -- pragma Elaboration_Checks (...);
16133 -- package Pack is ...;
16134
16135 elsif Nkind (Context) = N_Compilation_Unit
16136 and then List_Containing (N) = Context_Items (Context)
16137 then
16138 Check_Valid_Configuration_Pragma;
16139 Check_Duplicate_Elaboration_Checks_Pragma;
16140
16141 Unt := Unit (Context);
16142
16143 -- The pragma must appear on the initial declaration of a unit.
16144 -- If this is not the case, warn that the effects of the pragma
16145 -- are ignored.
16146
16147 if Nkind (Unt) = N_Package_Body then
16148 Ignore_Elaboration_Checks_Pragma;
16149
16150 -- Check the Acts_As_Spec flag of the compilation units itself
16151 -- to determine whether the subprogram body completes since it
16152 -- has not been analyzed yet. This is safe because compilation
16153 -- units are not overloadable.
16154
16155 elsif Nkind (Unt) = N_Subprogram_Body
16156 and then not Acts_As_Spec (Context)
16157 then
16158 Ignore_Elaboration_Checks_Pragma;
16159
16160 elsif Nkind (Unt) = N_Subunit then
16161 Ignore_Elaboration_Checks_Pragma;
16162 end if;
16163
16164 -- Otherwise the pragma does not appear at the configuration level
16165 -- and is illegal.
16166
16167 else
16168 Pragma_Misplaced;
16169 end if;
16170
16171 -- At this point the pragma is not a duplicate, and appears in the
16172 -- proper context. Set the elaboration model in effect.
16173
16174 Dynamic_Elaboration_Checks :=
16175 Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic;
16176 end Elaboration_Checks;
16177
16178 ---------------
16179 -- Eliminate --
16180 ---------------
16181
16182 -- pragma Eliminate (
16183 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
16184 -- [Entity =>] IDENTIFIER |
16185 -- SELECTED_COMPONENT |
16186 -- STRING_LITERAL]
16187 -- [, Source_Location => SOURCE_TRACE]);
16188
16189 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
16190 -- SOURCE_TRACE ::= STRING_LITERAL
16191
16192 when Pragma_Eliminate => Eliminate : declare
16193 Args : Args_List (1 .. 5);
16194 Names : constant Name_List (1 .. 5) := (
16195 Name_Unit_Name,
16196 Name_Entity,
16197 Name_Parameter_Types,
16198 Name_Result_Type,
16199 Name_Source_Location);
16200
16201 -- Note : Parameter_Types and Result_Type are leftovers from
16202 -- prior implementations of the pragma. They are not generated
16203 -- by the gnatelim tool, and play no role in selecting which
16204 -- of a set of overloaded names is chosen for elimination.
16205
16206 Unit_Name : Node_Id renames Args (1);
16207 Entity : Node_Id renames Args (2);
16208 Parameter_Types : Node_Id renames Args (3);
16209 Result_Type : Node_Id renames Args (4);
16210 Source_Location : Node_Id renames Args (5);
16211
16212 begin
16213 GNAT_Pragma;
16214 Check_Valid_Configuration_Pragma;
16215 Gather_Associations (Names, Args);
16216
16217 if No (Unit_Name) then
16218 Error_Pragma ("missing Unit_Name argument for pragma%");
16219 end if;
16220
16221 if No (Entity)
16222 and then (Present (Parameter_Types)
16223 or else
16224 Present (Result_Type)
16225 or else
16226 Present (Source_Location))
16227 then
16228 Error_Pragma ("missing Entity argument for pragma%");
16229 end if;
16230
16231 if (Present (Parameter_Types)
16232 or else
16233 Present (Result_Type))
16234 and then
16235 Present (Source_Location)
16236 then
16237 Error_Pragma
16238 ("parameter profile and source location cannot be used "
16239 & "together in pragma%");
16240 end if;
16241
16242 Process_Eliminate_Pragma
16243 (N,
16244 Unit_Name,
16245 Entity,
16246 Parameter_Types,
16247 Result_Type,
16248 Source_Location);
16249 end Eliminate;
16250
16251 -----------------------------------
16252 -- Enable_Atomic_Synchronization --
16253 -----------------------------------
16254
16255 -- pragma Enable_Atomic_Synchronization [(Entity)];
16256
16257 when Pragma_Enable_Atomic_Synchronization =>
16258 GNAT_Pragma;
16259 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
16260
16261 ------------
16262 -- Export --
16263 ------------
16264
16265 -- pragma Export (
16266 -- [ Convention =>] convention_IDENTIFIER,
16267 -- [ Entity =>] LOCAL_NAME
16268 -- [, [External_Name =>] static_string_EXPRESSION ]
16269 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16270
16271 when Pragma_Export => Export : declare
16272 C : Convention_Id;
16273 Def_Id : Entity_Id;
16274
16275 pragma Warnings (Off, C);
16276
16277 begin
16278 Check_Ada_83_Warning;
16279 Check_Arg_Order
16280 ((Name_Convention,
16281 Name_Entity,
16282 Name_External_Name,
16283 Name_Link_Name));
16284
16285 Check_At_Least_N_Arguments (2);
16286 Check_At_Most_N_Arguments (4);
16287
16288 -- In Relaxed_RM_Semantics, support old Ada 83 style:
16289 -- pragma Export (Entity, "external name");
16290
16291 if Relaxed_RM_Semantics
16292 and then Arg_Count = 2
16293 and then Nkind (Expression (Arg2)) = N_String_Literal
16294 then
16295 C := Convention_C;
16296 Def_Id := Get_Pragma_Arg (Arg1);
16297 Analyze (Def_Id);
16298
16299 if not Is_Entity_Name (Def_Id) then
16300 Error_Pragma_Arg ("entity name required", Arg1);
16301 end if;
16302
16303 Def_Id := Entity (Def_Id);
16304 Set_Exported (Def_Id, Arg1);
16305
16306 else
16307 Process_Convention (C, Def_Id);
16308
16309 -- A pragma that applies to a Ghost entity becomes Ghost for
16310 -- the purposes of legality checks and removal of ignored Ghost
16311 -- code.
16312
16313 Mark_Ghost_Pragma (N, Def_Id);
16314
16315 if Ekind (Def_Id) /= E_Constant then
16316 Note_Possible_Modification
16317 (Get_Pragma_Arg (Arg2), Sure => False);
16318 end if;
16319
16320 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
16321 Set_Exported (Def_Id, Arg2);
16322 end if;
16323
16324 -- If the entity is a deferred constant, propagate the information
16325 -- to the full view, because gigi elaborates the full view only.
16326
16327 if Ekind (Def_Id) = E_Constant
16328 and then Present (Full_View (Def_Id))
16329 then
16330 declare
16331 Id2 : constant Entity_Id := Full_View (Def_Id);
16332 begin
16333 Set_Is_Exported (Id2, Is_Exported (Def_Id));
16334 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
16335 Set_Interface_Name
16336 (Id2, Einfo.Entities.Interface_Name (Def_Id));
16337 end;
16338 end if;
16339 end Export;
16340
16341 ---------------------
16342 -- Export_Function --
16343 ---------------------
16344
16345 -- pragma Export_Function (
16346 -- [Internal =>] LOCAL_NAME
16347 -- [, [External =>] EXTERNAL_SYMBOL]
16348 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16349 -- [, [Result_Type =>] TYPE_DESIGNATOR]
16350 -- [, [Mechanism =>] MECHANISM]
16351 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
16352
16353 -- EXTERNAL_SYMBOL ::=
16354 -- IDENTIFIER
16355 -- | static_string_EXPRESSION
16356
16357 -- PARAMETER_TYPES ::=
16358 -- null
16359 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16360
16361 -- TYPE_DESIGNATOR ::=
16362 -- subtype_NAME
16363 -- | subtype_Name ' Access
16364
16365 -- MECHANISM ::=
16366 -- MECHANISM_NAME
16367 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16368
16369 -- MECHANISM_ASSOCIATION ::=
16370 -- [formal_parameter_NAME =>] MECHANISM_NAME
16371
16372 -- MECHANISM_NAME ::=
16373 -- Value
16374 -- | Reference
16375
16376 when Pragma_Export_Function => Export_Function : declare
16377 Args : Args_List (1 .. 6);
16378 Names : constant Name_List (1 .. 6) := (
16379 Name_Internal,
16380 Name_External,
16381 Name_Parameter_Types,
16382 Name_Result_Type,
16383 Name_Mechanism,
16384 Name_Result_Mechanism);
16385
16386 Internal : Node_Id renames Args (1);
16387 External : Node_Id renames Args (2);
16388 Parameter_Types : Node_Id renames Args (3);
16389 Result_Type : Node_Id renames Args (4);
16390 Mechanism : Node_Id renames Args (5);
16391 Result_Mechanism : Node_Id renames Args (6);
16392
16393 begin
16394 GNAT_Pragma;
16395 Gather_Associations (Names, Args);
16396 Process_Extended_Import_Export_Subprogram_Pragma (
16397 Arg_Internal => Internal,
16398 Arg_External => External,
16399 Arg_Parameter_Types => Parameter_Types,
16400 Arg_Result_Type => Result_Type,
16401 Arg_Mechanism => Mechanism,
16402 Arg_Result_Mechanism => Result_Mechanism);
16403 end Export_Function;
16404
16405 -------------------
16406 -- Export_Object --
16407 -------------------
16408
16409 -- pragma Export_Object (
16410 -- [Internal =>] LOCAL_NAME
16411 -- [, [External =>] EXTERNAL_SYMBOL]
16412 -- [, [Size =>] EXTERNAL_SYMBOL]);
16413
16414 -- EXTERNAL_SYMBOL ::=
16415 -- IDENTIFIER
16416 -- | static_string_EXPRESSION
16417
16418 -- PARAMETER_TYPES ::=
16419 -- null
16420 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16421
16422 -- TYPE_DESIGNATOR ::=
16423 -- subtype_NAME
16424 -- | subtype_Name ' Access
16425
16426 -- MECHANISM ::=
16427 -- MECHANISM_NAME
16428 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16429
16430 -- MECHANISM_ASSOCIATION ::=
16431 -- [formal_parameter_NAME =>] MECHANISM_NAME
16432
16433 -- MECHANISM_NAME ::=
16434 -- Value
16435 -- | Reference
16436
16437 when Pragma_Export_Object => Export_Object : declare
16438 Args : Args_List (1 .. 3);
16439 Names : constant Name_List (1 .. 3) := (
16440 Name_Internal,
16441 Name_External,
16442 Name_Size);
16443
16444 Internal : Node_Id renames Args (1);
16445 External : Node_Id renames Args (2);
16446 Size : Node_Id renames Args (3);
16447
16448 begin
16449 GNAT_Pragma;
16450 Gather_Associations (Names, Args);
16451 Process_Extended_Import_Export_Object_Pragma (
16452 Arg_Internal => Internal,
16453 Arg_External => External,
16454 Arg_Size => Size);
16455 end Export_Object;
16456
16457 ----------------------
16458 -- Export_Procedure --
16459 ----------------------
16460
16461 -- pragma Export_Procedure (
16462 -- [Internal =>] LOCAL_NAME
16463 -- [, [External =>] EXTERNAL_SYMBOL]
16464 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16465 -- [, [Mechanism =>] MECHANISM]);
16466
16467 -- EXTERNAL_SYMBOL ::=
16468 -- IDENTIFIER
16469 -- | static_string_EXPRESSION
16470
16471 -- PARAMETER_TYPES ::=
16472 -- null
16473 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16474
16475 -- TYPE_DESIGNATOR ::=
16476 -- subtype_NAME
16477 -- | subtype_Name ' Access
16478
16479 -- MECHANISM ::=
16480 -- MECHANISM_NAME
16481 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16482
16483 -- MECHANISM_ASSOCIATION ::=
16484 -- [formal_parameter_NAME =>] MECHANISM_NAME
16485
16486 -- MECHANISM_NAME ::=
16487 -- Value
16488 -- | Reference
16489
16490 when Pragma_Export_Procedure => Export_Procedure : declare
16491 Args : Args_List (1 .. 4);
16492 Names : constant Name_List (1 .. 4) := (
16493 Name_Internal,
16494 Name_External,
16495 Name_Parameter_Types,
16496 Name_Mechanism);
16497
16498 Internal : Node_Id renames Args (1);
16499 External : Node_Id renames Args (2);
16500 Parameter_Types : Node_Id renames Args (3);
16501 Mechanism : Node_Id renames Args (4);
16502
16503 begin
16504 GNAT_Pragma;
16505 Gather_Associations (Names, Args);
16506 Process_Extended_Import_Export_Subprogram_Pragma (
16507 Arg_Internal => Internal,
16508 Arg_External => External,
16509 Arg_Parameter_Types => Parameter_Types,
16510 Arg_Mechanism => Mechanism);
16511 end Export_Procedure;
16512
16513 -----------------------------
16514 -- Export_Valued_Procedure --
16515 -----------------------------
16516
16517 -- pragma Export_Valued_Procedure (
16518 -- [Internal =>] LOCAL_NAME
16519 -- [, [External =>] EXTERNAL_SYMBOL,]
16520 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16521 -- [, [Mechanism =>] MECHANISM]);
16522
16523 -- EXTERNAL_SYMBOL ::=
16524 -- IDENTIFIER
16525 -- | static_string_EXPRESSION
16526
16527 -- PARAMETER_TYPES ::=
16528 -- null
16529 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16530
16531 -- TYPE_DESIGNATOR ::=
16532 -- subtype_NAME
16533 -- | subtype_Name ' Access
16534
16535 -- MECHANISM ::=
16536 -- MECHANISM_NAME
16537 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16538
16539 -- MECHANISM_ASSOCIATION ::=
16540 -- [formal_parameter_NAME =>] MECHANISM_NAME
16541
16542 -- MECHANISM_NAME ::=
16543 -- Value
16544 -- | Reference
16545
16546 when Pragma_Export_Valued_Procedure =>
16547 Export_Valued_Procedure : declare
16548 Args : Args_List (1 .. 4);
16549 Names : constant Name_List (1 .. 4) := (
16550 Name_Internal,
16551 Name_External,
16552 Name_Parameter_Types,
16553 Name_Mechanism);
16554
16555 Internal : Node_Id renames Args (1);
16556 External : Node_Id renames Args (2);
16557 Parameter_Types : Node_Id renames Args (3);
16558 Mechanism : Node_Id renames Args (4);
16559
16560 begin
16561 GNAT_Pragma;
16562 Gather_Associations (Names, Args);
16563 Process_Extended_Import_Export_Subprogram_Pragma (
16564 Arg_Internal => Internal,
16565 Arg_External => External,
16566 Arg_Parameter_Types => Parameter_Types,
16567 Arg_Mechanism => Mechanism);
16568 end Export_Valued_Procedure;
16569
16570 -------------------
16571 -- Extend_System --
16572 -------------------
16573
16574 -- pragma Extend_System ([Name =>] Identifier);
16575
16576 when Pragma_Extend_System =>
16577 GNAT_Pragma;
16578 Check_Valid_Configuration_Pragma;
16579 Check_Arg_Count (1);
16580 Check_Optional_Identifier (Arg1, Name_Name);
16581 Check_Arg_Is_Identifier (Arg1);
16582
16583 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16584
16585 if Name_Len > 4
16586 and then Name_Buffer (1 .. 4) = "aux_"
16587 then
16588 if Present (System_Extend_Pragma_Arg) then
16589 if Chars (Get_Pragma_Arg (Arg1)) =
16590 Chars (Expression (System_Extend_Pragma_Arg))
16591 then
16592 null;
16593 else
16594 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
16595 Error_Pragma ("pragma% conflicts with that #");
16596 end if;
16597
16598 else
16599 System_Extend_Pragma_Arg := Arg1;
16600
16601 if not GNAT_Mode then
16602 System_Extend_Unit := Arg1;
16603 end if;
16604 end if;
16605 else
16606 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
16607 end if;
16608
16609 ------------------------
16610 -- Extensions_Allowed --
16611 ------------------------
16612
16613 -- pragma Extensions_Allowed (ON | OFF | ALL);
16614
16615 when Pragma_Extensions_Allowed =>
16616 GNAT_Pragma;
16617 Check_Arg_Count (1);
16618 Check_No_Identifiers;
16619 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off, Name_All);
16620
16621 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
16622 Ada_Version := Ada_With_Core_Extensions;
16623 elsif Chars (Get_Pragma_Arg (Arg1)) = Name_All then
16624 Ada_Version := Ada_With_All_Extensions;
16625 else
16626 Ada_Version := Ada_Version_Explicit;
16627 Ada_Version_Pragma := Empty;
16628 end if;
16629
16630 ------------------------
16631 -- Extensions_Visible --
16632 ------------------------
16633
16634 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
16635
16636 -- Characteristics:
16637
16638 -- * Analysis - The annotation is fully analyzed immediately upon
16639 -- elaboration as its expression must be static.
16640
16641 -- * Expansion - None.
16642
16643 -- * Template - The annotation utilizes the generic template of the
16644 -- related subprogram [body] when it is:
16645
16646 -- aspect on subprogram declaration
16647 -- aspect on stand-alone subprogram body
16648 -- pragma on stand-alone subprogram body
16649
16650 -- The annotation must prepare its own template when it is:
16651
16652 -- pragma on subprogram declaration
16653
16654 -- * Globals - Capture of global references must occur after full
16655 -- analysis.
16656
16657 -- * Instance - The annotation is instantiated automatically when
16658 -- the related generic subprogram [body] is instantiated except for
16659 -- the "pragma on subprogram declaration" case. In that scenario
16660 -- the annotation must instantiate itself.
16661
16662 when Pragma_Extensions_Visible => Extensions_Visible : declare
16663 Formal : Entity_Id;
16664 Has_OK_Formal : Boolean := False;
16665 Spec_Id : Entity_Id;
16666 Subp_Decl : Node_Id;
16667
16668 begin
16669 GNAT_Pragma;
16670 Check_No_Identifiers;
16671 Check_At_Most_N_Arguments (1);
16672
16673 Subp_Decl :=
16674 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
16675
16676 -- Abstract subprogram declaration
16677
16678 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
16679 null;
16680
16681 -- Generic subprogram declaration
16682
16683 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
16684 null;
16685
16686 -- Body acts as spec
16687
16688 elsif Nkind (Subp_Decl) = N_Subprogram_Body
16689 and then No (Corresponding_Spec (Subp_Decl))
16690 then
16691 null;
16692
16693 -- Body stub acts as spec
16694
16695 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
16696 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
16697 then
16698 null;
16699
16700 -- Subprogram declaration
16701
16702 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
16703 null;
16704
16705 -- Otherwise the pragma is associated with an illegal construct
16706
16707 else
16708 Error_Pragma ("pragma % must apply to a subprogram");
16709 end if;
16710
16711 -- Mark the pragma as Ghost if the related subprogram is also
16712 -- Ghost. This also ensures that any expansion performed further
16713 -- below will produce Ghost nodes.
16714
16715 Spec_Id := Unique_Defining_Entity (Subp_Decl);
16716 Mark_Ghost_Pragma (N, Spec_Id);
16717
16718 -- Chain the pragma on the contract for completeness
16719
16720 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
16721
16722 -- The legality checks of pragma Extension_Visible are affected
16723 -- by the SPARK mode in effect. Analyze all pragmas in specific
16724 -- order.
16725
16726 Analyze_If_Present (Pragma_SPARK_Mode);
16727
16728 -- Examine the formals of the related subprogram
16729
16730 Formal := First_Formal (Spec_Id);
16731 while Present (Formal) loop
16732
16733 -- At least one of the formals is of a specific tagged type,
16734 -- the pragma is legal.
16735
16736 if Is_Specific_Tagged_Type (Etype (Formal)) then
16737 Has_OK_Formal := True;
16738 exit;
16739
16740 -- A generic subprogram with at least one formal of a private
16741 -- type ensures the legality of the pragma because the actual
16742 -- may be specifically tagged. Note that this is verified by
16743 -- the check above at instantiation time.
16744
16745 elsif Is_Private_Type (Etype (Formal))
16746 and then Is_Generic_Type (Etype (Formal))
16747 then
16748 Has_OK_Formal := True;
16749 exit;
16750 end if;
16751
16752 Next_Formal (Formal);
16753 end loop;
16754
16755 if not Has_OK_Formal then
16756 Error_Msg_Name_1 := Pname;
16757 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
16758 Error_Msg_NE
16759 ("\subprogram & lacks parameter of specific tagged or "
16760 & "generic private type", N, Spec_Id);
16761
16762 return;
16763 end if;
16764
16765 -- Analyze the Boolean expression (if any)
16766
16767 if Present (Arg1) then
16768 Check_Static_Boolean_Expression
16769 (Expression (Get_Argument (N, Spec_Id)));
16770 end if;
16771 end Extensions_Visible;
16772
16773 --------------
16774 -- External --
16775 --------------
16776
16777 -- pragma External (
16778 -- [ Convention =>] convention_IDENTIFIER,
16779 -- [ Entity =>] LOCAL_NAME
16780 -- [, [External_Name =>] static_string_EXPRESSION ]
16781 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16782
16783 when Pragma_External => External : declare
16784 C : Convention_Id;
16785 E : Entity_Id;
16786 pragma Warnings (Off, C);
16787
16788 begin
16789 GNAT_Pragma;
16790 Check_Arg_Order
16791 ((Name_Convention,
16792 Name_Entity,
16793 Name_External_Name,
16794 Name_Link_Name));
16795 Check_At_Least_N_Arguments (2);
16796 Check_At_Most_N_Arguments (4);
16797 Process_Convention (C, E);
16798
16799 -- A pragma that applies to a Ghost entity becomes Ghost for the
16800 -- purposes of legality checks and removal of ignored Ghost code.
16801
16802 Mark_Ghost_Pragma (N, E);
16803
16804 Note_Possible_Modification
16805 (Get_Pragma_Arg (Arg2), Sure => False);
16806 Process_Interface_Name (E, Arg3, Arg4, N);
16807 Set_Exported (E, Arg2);
16808 end External;
16809
16810 --------------------------
16811 -- External_Name_Casing --
16812 --------------------------
16813
16814 -- pragma External_Name_Casing (
16815 -- UPPERCASE | LOWERCASE
16816 -- [, AS_IS | UPPERCASE | LOWERCASE]);
16817
16818 when Pragma_External_Name_Casing =>
16819 GNAT_Pragma;
16820 Check_No_Identifiers;
16821
16822 if Arg_Count = 2 then
16823 Check_Arg_Is_One_Of
16824 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
16825
16826 case Chars (Get_Pragma_Arg (Arg2)) is
16827 when Name_As_Is =>
16828 Opt.External_Name_Exp_Casing := As_Is;
16829
16830 when Name_Uppercase =>
16831 Opt.External_Name_Exp_Casing := Uppercase;
16832
16833 when Name_Lowercase =>
16834 Opt.External_Name_Exp_Casing := Lowercase;
16835
16836 when others =>
16837 null;
16838 end case;
16839
16840 else
16841 Check_Arg_Count (1);
16842 end if;
16843
16844 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
16845
16846 case Chars (Get_Pragma_Arg (Arg1)) is
16847 when Name_Uppercase =>
16848 Opt.External_Name_Imp_Casing := Uppercase;
16849
16850 when Name_Lowercase =>
16851 Opt.External_Name_Imp_Casing := Lowercase;
16852
16853 when others =>
16854 null;
16855 end case;
16856
16857 ---------------
16858 -- Fast_Math --
16859 ---------------
16860
16861 -- pragma Fast_Math;
16862
16863 when Pragma_Fast_Math =>
16864 GNAT_Pragma;
16865 Check_No_Identifiers;
16866 Check_Valid_Configuration_Pragma;
16867 Fast_Math := True;
16868
16869 --------------------------
16870 -- Favor_Top_Level --
16871 --------------------------
16872
16873 -- pragma Favor_Top_Level (type_NAME);
16874
16875 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
16876 Typ : Entity_Id;
16877
16878 begin
16879 GNAT_Pragma;
16880 Check_No_Identifiers;
16881 Check_Arg_Count (1);
16882 Check_Arg_Is_Local_Name (Arg1);
16883 Typ := Entity (Get_Pragma_Arg (Arg1));
16884
16885 -- A pragma that applies to a Ghost entity becomes Ghost for the
16886 -- purposes of legality checks and removal of ignored Ghost code.
16887
16888 Mark_Ghost_Pragma (N, Typ);
16889
16890 -- If it's an access-to-subprogram type (in particular, not a
16891 -- subtype), set the flag on that type.
16892
16893 if Is_Access_Subprogram_Type (Typ) then
16894 Set_Can_Use_Internal_Rep (Typ, False);
16895
16896 -- Otherwise it's an error (name denotes the wrong sort of entity)
16897
16898 else
16899 Error_Pragma_Arg
16900 ("access-to-subprogram type expected",
16901 Get_Pragma_Arg (Arg1));
16902 end if;
16903 end Favor_Top_Level;
16904
16905 ---------------------------
16906 -- Finalize_Storage_Only --
16907 ---------------------------
16908
16909 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
16910
16911 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
16912 Assoc : constant Node_Id := Arg1;
16913 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
16914 Typ : Entity_Id;
16915
16916 begin
16917 GNAT_Pragma;
16918 Check_No_Identifiers;
16919 Check_Arg_Count (1);
16920 Check_Arg_Is_Local_Name (Arg1);
16921
16922 Find_Type (Type_Id);
16923 Typ := Entity (Type_Id);
16924
16925 if Typ = Any_Type
16926 or else Rep_Item_Too_Early (Typ, N)
16927 then
16928 return;
16929 else
16930 Typ := Underlying_Type (Typ);
16931 end if;
16932
16933 if not Is_Controlled (Typ) then
16934 Error_Pragma ("pragma% must specify controlled type");
16935 end if;
16936
16937 Check_First_Subtype (Arg1);
16938
16939 if Finalize_Storage_Only (Typ) then
16940 Error_Pragma ("duplicate pragma%, only one allowed");
16941
16942 elsif not Rep_Item_Too_Late (Typ, N) then
16943 Set_Finalize_Storage_Only (Base_Type (Typ), True);
16944 end if;
16945 end Finalize_Storage;
16946
16947 -----------
16948 -- Ghost --
16949 -----------
16950
16951 -- pragma Ghost [ (boolean_EXPRESSION) ];
16952
16953 when Pragma_Ghost => Ghost : declare
16954 Context : Node_Id;
16955 Expr : Node_Id;
16956 Id : Entity_Id;
16957 Orig_Stmt : Node_Id;
16958 Prev_Id : Entity_Id;
16959 Stmt : Node_Id;
16960
16961 begin
16962 GNAT_Pragma;
16963 Check_No_Identifiers;
16964 Check_At_Most_N_Arguments (1);
16965
16966 Id := Empty;
16967 Stmt := Prev (N);
16968 while Present (Stmt) loop
16969
16970 -- Skip prior pragmas, but check for duplicates
16971
16972 if Nkind (Stmt) = N_Pragma then
16973 if Pragma_Name (Stmt) = Pname then
16974 Duplication_Error
16975 (Prag => N,
16976 Prev => Stmt);
16977 raise Pragma_Exit;
16978 end if;
16979
16980 -- Task unit declared without a definition cannot be subject to
16981 -- pragma Ghost (SPARK RM 6.9(19)).
16982
16983 elsif Nkind (Stmt) in
16984 N_Single_Task_Declaration | N_Task_Type_Declaration
16985 then
16986 Error_Pragma ("pragma % cannot apply to a task type");
16987
16988 -- Skip internally generated code
16989
16990 elsif not Comes_From_Source (Stmt) then
16991 Orig_Stmt := Original_Node (Stmt);
16992
16993 -- When pragma Ghost applies to an untagged derivation, the
16994 -- derivation is transformed into a [sub]type declaration.
16995
16996 if Nkind (Stmt) in
16997 N_Full_Type_Declaration | N_Subtype_Declaration
16998 and then Comes_From_Source (Orig_Stmt)
16999 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
17000 and then Nkind (Type_Definition (Orig_Stmt)) =
17001 N_Derived_Type_Definition
17002 then
17003 Id := Defining_Entity (Stmt);
17004 exit;
17005
17006 -- When pragma Ghost applies to an object declaration which
17007 -- is initialized by means of a function call that returns
17008 -- on the secondary stack, the object declaration becomes a
17009 -- renaming.
17010
17011 elsif Nkind (Stmt) = N_Object_Renaming_Declaration
17012 and then Comes_From_Source (Orig_Stmt)
17013 and then Nkind (Orig_Stmt) = N_Object_Declaration
17014 then
17015 Id := Defining_Entity (Stmt);
17016 exit;
17017
17018 -- When pragma Ghost applies to an expression function, the
17019 -- expression function is transformed into a subprogram.
17020
17021 elsif Nkind (Stmt) = N_Subprogram_Declaration
17022 and then Comes_From_Source (Orig_Stmt)
17023 and then Nkind (Orig_Stmt) = N_Expression_Function
17024 then
17025 Id := Defining_Entity (Stmt);
17026 exit;
17027
17028 -- When pragma Ghost applies to a generic formal type, the
17029 -- type declaration in the instantiation is a generated
17030 -- subtype declaration.
17031
17032 elsif Nkind (Stmt) = N_Subtype_Declaration
17033 and then Present (Generic_Parent_Type (Stmt))
17034 then
17035 Id := Defining_Entity (Stmt);
17036 exit;
17037 end if;
17038
17039 -- The pragma applies to a legal construct, stop the traversal
17040
17041 elsif Nkind (Stmt) in N_Abstract_Subprogram_Declaration
17042 | N_Formal_Object_Declaration
17043 | N_Formal_Subprogram_Declaration
17044 | N_Formal_Type_Declaration
17045 | N_Full_Type_Declaration
17046 | N_Generic_Subprogram_Declaration
17047 | N_Object_Declaration
17048 | N_Private_Extension_Declaration
17049 | N_Private_Type_Declaration
17050 | N_Subprogram_Declaration
17051 | N_Subtype_Declaration
17052 then
17053 Id := Defining_Entity (Stmt);
17054 exit;
17055
17056 -- The pragma does not apply to a legal construct, issue an
17057 -- error and stop the analysis.
17058
17059 else
17060 Error_Pragma
17061 ("pragma % must apply to an object, package, subprogram "
17062 & "or type");
17063 end if;
17064
17065 Stmt := Prev (Stmt);
17066 end loop;
17067
17068 Context := Parent (N);
17069
17070 -- Handle compilation units
17071
17072 if Nkind (Context) = N_Compilation_Unit_Aux then
17073 Context := Unit (Parent (Context));
17074 end if;
17075
17076 -- Protected and task types cannot be subject to pragma Ghost
17077 -- (SPARK RM 6.9(19)).
17078
17079 if Nkind (Context) in N_Protected_Body | N_Protected_Definition
17080 then
17081 Error_Pragma ("pragma % cannot apply to a protected type");
17082
17083 elsif Nkind (Context) in N_Task_Body | N_Task_Definition then
17084 Error_Pragma ("pragma % cannot apply to a task type");
17085 end if;
17086
17087 if No (Id) then
17088
17089 -- When pragma Ghost is associated with a [generic] package, it
17090 -- appears in the visible declarations.
17091
17092 if Nkind (Context) = N_Package_Specification
17093 and then Present (Visible_Declarations (Context))
17094 and then List_Containing (N) = Visible_Declarations (Context)
17095 then
17096 Id := Defining_Entity (Context);
17097
17098 -- Pragma Ghost applies to a stand-alone subprogram body
17099
17100 elsif Nkind (Context) = N_Subprogram_Body
17101 and then No (Corresponding_Spec (Context))
17102 then
17103 Id := Defining_Entity (Context);
17104
17105 -- Pragma Ghost applies to a subprogram declaration that acts
17106 -- as a compilation unit.
17107
17108 elsif Nkind (Context) = N_Subprogram_Declaration then
17109 Id := Defining_Entity (Context);
17110
17111 -- Pragma Ghost applies to a generic subprogram
17112
17113 elsif Nkind (Context) = N_Generic_Subprogram_Declaration then
17114 Id := Defining_Entity (Specification (Context));
17115 end if;
17116 end if;
17117
17118 if No (Id) then
17119 Error_Pragma
17120 ("pragma % must apply to an object, package, subprogram or "
17121 & "type");
17122 end if;
17123
17124 -- Handle completions of types and constants that are subject to
17125 -- pragma Ghost.
17126
17127 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
17128 Prev_Id := Incomplete_Or_Partial_View (Id);
17129
17130 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
17131 Error_Msg_Name_1 := Pname;
17132
17133 -- The full declaration of a deferred constant cannot be
17134 -- subject to pragma Ghost unless the deferred declaration
17135 -- is also Ghost (SPARK RM 6.9(9)).
17136
17137 if Ekind (Prev_Id) = E_Constant then
17138 Error_Msg_Name_1 := Pname;
17139 Error_Msg_NE (Fix_Error
17140 ("pragma % must apply to declaration of deferred "
17141 & "constant &"), N, Id);
17142 return;
17143
17144 -- Pragma Ghost may appear on the full view of an incomplete
17145 -- type because the incomplete declaration lacks aspects and
17146 -- cannot be subject to pragma Ghost.
17147
17148 elsif Ekind (Prev_Id) = E_Incomplete_Type then
17149 null;
17150
17151 -- The full declaration of a type cannot be subject to
17152 -- pragma Ghost unless the partial view is also Ghost
17153 -- (SPARK RM 6.9(9)).
17154
17155 else
17156 Error_Msg_NE (Fix_Error
17157 ("pragma % must apply to partial view of type &"),
17158 N, Id);
17159 return;
17160 end if;
17161 end if;
17162
17163 -- A synchronized object cannot be subject to pragma Ghost
17164 -- (SPARK RM 6.9(19)).
17165
17166 elsif Ekind (Id) = E_Variable then
17167 if Is_Protected_Type (Etype (Id)) then
17168 Error_Pragma ("pragma % cannot apply to a protected object");
17169
17170 elsif Is_Task_Type (Etype (Id)) then
17171 Error_Pragma ("pragma % cannot apply to a task object");
17172 end if;
17173 end if;
17174
17175 -- Analyze the Boolean expression (if any)
17176
17177 if Present (Arg1) then
17178 Expr := Get_Pragma_Arg (Arg1);
17179
17180 Analyze_And_Resolve (Expr, Standard_Boolean);
17181
17182 if Is_OK_Static_Expression (Expr) then
17183
17184 -- "Ghostness" cannot be turned off once enabled within a
17185 -- region (SPARK RM 6.9(6)).
17186
17187 if Is_False (Expr_Value (Expr))
17188 and then Ghost_Mode > None
17189 then
17190 Error_Pragma
17191 ("pragma % with value False cannot appear in enabled "
17192 & "ghost region");
17193 end if;
17194
17195 -- Otherwise the expression is not static
17196
17197 else
17198 Error_Pragma_Arg
17199 ("expression of pragma % must be static", Expr);
17200 end if;
17201 end if;
17202
17203 Set_Is_Ghost_Entity (Id);
17204 end Ghost;
17205
17206 ------------
17207 -- Global --
17208 ------------
17209
17210 -- pragma Global (GLOBAL_SPECIFICATION);
17211
17212 -- GLOBAL_SPECIFICATION ::=
17213 -- null
17214 -- | (GLOBAL_LIST)
17215 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
17216
17217 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
17218
17219 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
17220 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
17221 -- GLOBAL_ITEM ::= NAME
17222
17223 -- Characteristics:
17224
17225 -- * Analysis - The annotation undergoes initial checks to verify
17226 -- the legal placement and context. Secondary checks fully analyze
17227 -- the dependency clauses in:
17228
17229 -- Analyze_Global_In_Decl_Part
17230
17231 -- * Expansion - None.
17232
17233 -- * Template - The annotation utilizes the generic template of the
17234 -- related subprogram [body] when it is:
17235
17236 -- aspect on subprogram declaration
17237 -- aspect on stand-alone subprogram body
17238 -- pragma on stand-alone subprogram body
17239
17240 -- The annotation must prepare its own template when it is:
17241
17242 -- pragma on subprogram declaration
17243
17244 -- * Globals - Capture of global references must occur after full
17245 -- analysis.
17246
17247 -- * Instance - The annotation is instantiated automatically when
17248 -- the related generic subprogram [body] is instantiated except for
17249 -- the "pragma on subprogram declaration" case. In that scenario
17250 -- the annotation must instantiate itself.
17251
17252 when Pragma_Global => Global : declare
17253 Legal : Boolean;
17254 Spec_Id : Entity_Id;
17255 Subp_Decl : Node_Id;
17256
17257 begin
17258 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
17259
17260 if Legal then
17261
17262 -- Chain the pragma on the contract for further processing by
17263 -- Analyze_Global_In_Decl_Part.
17264
17265 Add_Contract_Item (N, Spec_Id);
17266
17267 -- Fully analyze the pragma when it appears inside an entry
17268 -- or subprogram body because it cannot benefit from forward
17269 -- references.
17270
17271 if Nkind (Subp_Decl) in N_Entry_Body
17272 | N_Subprogram_Body
17273 | N_Subprogram_Body_Stub
17274 then
17275 -- The legality checks of pragmas Depends and Global are
17276 -- affected by the SPARK mode in effect and the volatility
17277 -- of the context. In addition these two pragmas are subject
17278 -- to an inherent order:
17279
17280 -- 1) Global
17281 -- 2) Depends
17282
17283 -- Analyze all these pragmas in the order outlined above
17284
17285 Analyze_If_Present (Pragma_SPARK_Mode);
17286 Analyze_If_Present (Pragma_Volatile_Function);
17287 Analyze_Global_In_Decl_Part (N);
17288 Analyze_If_Present (Pragma_Depends);
17289 end if;
17290 end if;
17291 end Global;
17292
17293 -----------
17294 -- Ident --
17295 -----------
17296
17297 -- pragma Ident (static_string_EXPRESSION)
17298
17299 -- Note: pragma Comment shares this processing. Pragma Ident is
17300 -- identical in effect to pragma Commment.
17301
17302 when Pragma_Comment
17303 | Pragma_Ident
17304 =>
17305 Ident : declare
17306 Str : Node_Id;
17307
17308 begin
17309 GNAT_Pragma;
17310 Check_Arg_Count (1);
17311 Check_No_Identifiers;
17312 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17313 Store_Note (N);
17314
17315 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
17316
17317 declare
17318 CS : Node_Id;
17319 GP : Node_Id;
17320
17321 begin
17322 GP := Parent (Parent (N));
17323
17324 if Nkind (GP) in
17325 N_Package_Declaration | N_Generic_Package_Declaration
17326 then
17327 GP := Parent (GP);
17328 end if;
17329
17330 -- If we have a compilation unit, then record the ident value,
17331 -- checking for improper duplication.
17332
17333 if Nkind (GP) = N_Compilation_Unit then
17334 CS := Ident_String (Current_Sem_Unit);
17335
17336 if Present (CS) then
17337
17338 -- If we have multiple instances, concatenate them.
17339
17340 Start_String (Strval (CS));
17341 Store_String_Char (' ');
17342 Store_String_Chars (Strval (Str));
17343 Set_Strval (CS, End_String);
17344
17345 else
17346 Set_Ident_String (Current_Sem_Unit, Str);
17347 end if;
17348
17349 -- For subunits, we just ignore the Ident, since in GNAT these
17350 -- are not separate object files, and hence not separate units
17351 -- in the unit table.
17352
17353 elsif Nkind (GP) = N_Subunit then
17354 null;
17355 end if;
17356 end;
17357 end Ident;
17358
17359 -------------------
17360 -- Ignore_Pragma --
17361 -------------------
17362
17363 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
17364
17365 -- Entirely handled in the parser, nothing to do here
17366
17367 when Pragma_Ignore_Pragma =>
17368 null;
17369
17370 ----------------------------
17371 -- Implementation_Defined --
17372 ----------------------------
17373
17374 -- pragma Implementation_Defined (LOCAL_NAME);
17375
17376 -- Marks previously declared entity as implementation defined. For
17377 -- an overloaded entity, applies to the most recent homonym.
17378
17379 -- pragma Implementation_Defined;
17380
17381 -- The form with no arguments appears anywhere within a scope, most
17382 -- typically a package spec, and indicates that all entities that are
17383 -- defined within the package spec are Implementation_Defined.
17384
17385 when Pragma_Implementation_Defined => Implementation_Defined : declare
17386 Ent : Entity_Id;
17387
17388 begin
17389 GNAT_Pragma;
17390 Check_No_Identifiers;
17391
17392 -- Form with no arguments
17393
17394 if Arg_Count = 0 then
17395 Set_Is_Implementation_Defined (Current_Scope);
17396
17397 -- Form with one argument
17398
17399 else
17400 Check_Arg_Count (1);
17401 Check_Arg_Is_Local_Name (Arg1);
17402 Ent := Entity (Get_Pragma_Arg (Arg1));
17403 Set_Is_Implementation_Defined (Ent);
17404 end if;
17405 end Implementation_Defined;
17406
17407 -----------------
17408 -- Implemented --
17409 -----------------
17410
17411 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
17412
17413 -- IMPLEMENTATION_KIND ::=
17414 -- By_Entry | By_Protected_Procedure | By_Any | Optional
17415
17416 -- "By_Any" and "Optional" are treated as synonyms in order to
17417 -- support Ada 2012 aspect Synchronization.
17418
17419 when Pragma_Implemented => Implemented : declare
17420 Proc_Id : Entity_Id;
17421 Typ : Entity_Id;
17422
17423 begin
17424 Ada_2012_Pragma;
17425 Check_Arg_Count (2);
17426 Check_No_Identifiers;
17427 Check_Arg_Is_Identifier (Arg1);
17428 Check_Arg_Is_Local_Name (Arg1);
17429 Check_Arg_Is_One_Of (Arg2,
17430 Name_By_Any,
17431 Name_By_Entry,
17432 Name_By_Protected_Procedure,
17433 Name_Optional);
17434
17435 -- Extract the name of the local procedure
17436
17437 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
17438
17439 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
17440 -- primitive procedure of a synchronized tagged type.
17441
17442 if Ekind (Proc_Id) = E_Procedure
17443 and then Is_Primitive (Proc_Id)
17444 and then Present (First_Formal (Proc_Id))
17445 then
17446 Typ := Etype (First_Formal (Proc_Id));
17447
17448 if Is_Tagged_Type (Typ)
17449 and then
17450
17451 -- Check for a protected, a synchronized or a task interface
17452
17453 ((Is_Interface (Typ)
17454 and then Is_Synchronized_Interface (Typ))
17455
17456 -- Check for a protected type or a task type that implements
17457 -- an interface.
17458
17459 or else
17460 (Is_Concurrent_Record_Type (Typ)
17461 and then Present (Interfaces (Typ)))
17462
17463 -- In analysis-only mode, examine original protected type
17464
17465 or else
17466 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
17467 and then Present (Interface_List (Parent (Typ))))
17468
17469 -- Check for a private record extension with keyword
17470 -- "synchronized".
17471
17472 or else
17473 (Ekind (Typ) in E_Record_Type_With_Private
17474 | E_Record_Subtype_With_Private
17475 and then Synchronized_Present (Parent (Typ))))
17476 then
17477 null;
17478 else
17479 Error_Pragma_Arg
17480 ("controlling formal must be of synchronized tagged type",
17481 Arg1);
17482 end if;
17483
17484 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
17485 -- By_Protected_Procedure to the primitive procedure of a task
17486 -- interface.
17487
17488 if Chars (Get_Pragma_Arg (Arg2)) = Name_By_Protected_Procedure
17489 and then Is_Interface (Typ)
17490 and then Is_Task_Interface (Typ)
17491 then
17492 Error_Pragma_Arg
17493 ("implementation kind By_Protected_Procedure cannot be "
17494 & "applied to a task interface primitive", Arg2);
17495 end if;
17496
17497 -- Procedures declared inside a protected type must be accepted
17498
17499 elsif Ekind (Proc_Id) = E_Procedure
17500 and then Is_Protected_Type (Scope (Proc_Id))
17501 then
17502 null;
17503
17504 -- The first argument is not a primitive procedure
17505
17506 else
17507 Error_Pragma_Arg
17508 ("pragma % must be applied to a primitive procedure", Arg1);
17509 end if;
17510
17511 -- Ada 2012 (AI12-0279): Cannot apply the implementation_kind
17512 -- By_Protected_Procedure to a procedure that has aspect Yield
17513
17514 if Chars (Get_Pragma_Arg (Arg2)) = Name_By_Protected_Procedure
17515 and then Has_Yield_Aspect (Proc_Id)
17516 then
17517 Error_Pragma_Arg
17518 ("implementation kind By_Protected_Procedure cannot be "
17519 & "applied to entities with aspect 'Yield", Arg2);
17520 end if;
17521
17522 Record_Rep_Item (Proc_Id, N);
17523 end Implemented;
17524
17525 ----------------------
17526 -- Implicit_Packing --
17527 ----------------------
17528
17529 -- pragma Implicit_Packing;
17530
17531 when Pragma_Implicit_Packing =>
17532 GNAT_Pragma;
17533 Check_Arg_Count (0);
17534 Implicit_Packing := True;
17535
17536 ------------
17537 -- Import --
17538 ------------
17539
17540 -- pragma Import (
17541 -- [Convention =>] convention_IDENTIFIER,
17542 -- [Entity =>] LOCAL_NAME
17543 -- [, [External_Name =>] static_string_EXPRESSION ]
17544 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17545
17546 when Pragma_Import =>
17547 Check_Ada_83_Warning;
17548 Check_Arg_Order
17549 ((Name_Convention,
17550 Name_Entity,
17551 Name_External_Name,
17552 Name_Link_Name));
17553
17554 Check_At_Least_N_Arguments (2);
17555 Check_At_Most_N_Arguments (4);
17556 Process_Import_Or_Interface;
17557
17558 ---------------------
17559 -- Import_Function --
17560 ---------------------
17561
17562 -- pragma Import_Function (
17563 -- [Internal =>] LOCAL_NAME,
17564 -- [, [External =>] EXTERNAL_SYMBOL]
17565 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17566 -- [, [Result_Type =>] SUBTYPE_MARK]
17567 -- [, [Mechanism =>] MECHANISM]
17568 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
17569
17570 -- EXTERNAL_SYMBOL ::=
17571 -- IDENTIFIER
17572 -- | static_string_EXPRESSION
17573
17574 -- PARAMETER_TYPES ::=
17575 -- null
17576 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17577
17578 -- TYPE_DESIGNATOR ::=
17579 -- subtype_NAME
17580 -- | subtype_Name ' Access
17581
17582 -- MECHANISM ::=
17583 -- MECHANISM_NAME
17584 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17585
17586 -- MECHANISM_ASSOCIATION ::=
17587 -- [formal_parameter_NAME =>] MECHANISM_NAME
17588
17589 -- MECHANISM_NAME ::=
17590 -- Value
17591 -- | Reference
17592
17593 when Pragma_Import_Function => Import_Function : declare
17594 Args : Args_List (1 .. 6);
17595 Names : constant Name_List (1 .. 6) := (
17596 Name_Internal,
17597 Name_External,
17598 Name_Parameter_Types,
17599 Name_Result_Type,
17600 Name_Mechanism,
17601 Name_Result_Mechanism);
17602
17603 Internal : Node_Id renames Args (1);
17604 External : Node_Id renames Args (2);
17605 Parameter_Types : Node_Id renames Args (3);
17606 Result_Type : Node_Id renames Args (4);
17607 Mechanism : Node_Id renames Args (5);
17608 Result_Mechanism : Node_Id renames Args (6);
17609
17610 begin
17611 GNAT_Pragma;
17612 Gather_Associations (Names, Args);
17613 Process_Extended_Import_Export_Subprogram_Pragma (
17614 Arg_Internal => Internal,
17615 Arg_External => External,
17616 Arg_Parameter_Types => Parameter_Types,
17617 Arg_Result_Type => Result_Type,
17618 Arg_Mechanism => Mechanism,
17619 Arg_Result_Mechanism => Result_Mechanism);
17620 end Import_Function;
17621
17622 -------------------
17623 -- Import_Object --
17624 -------------------
17625
17626 -- pragma Import_Object (
17627 -- [Internal =>] LOCAL_NAME
17628 -- [, [External =>] EXTERNAL_SYMBOL]
17629 -- [, [Size =>] EXTERNAL_SYMBOL]);
17630
17631 -- EXTERNAL_SYMBOL ::=
17632 -- IDENTIFIER
17633 -- | static_string_EXPRESSION
17634
17635 when Pragma_Import_Object => Import_Object : declare
17636 Args : Args_List (1 .. 3);
17637 Names : constant Name_List (1 .. 3) := (
17638 Name_Internal,
17639 Name_External,
17640 Name_Size);
17641
17642 Internal : Node_Id renames Args (1);
17643 External : Node_Id renames Args (2);
17644 Size : Node_Id renames Args (3);
17645
17646 begin
17647 GNAT_Pragma;
17648 Gather_Associations (Names, Args);
17649 Process_Extended_Import_Export_Object_Pragma (
17650 Arg_Internal => Internal,
17651 Arg_External => External,
17652 Arg_Size => Size);
17653 end Import_Object;
17654
17655 ----------------------
17656 -- Import_Procedure --
17657 ----------------------
17658
17659 -- pragma Import_Procedure (
17660 -- [Internal =>] LOCAL_NAME
17661 -- [, [External =>] EXTERNAL_SYMBOL]
17662 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17663 -- [, [Mechanism =>] MECHANISM]);
17664
17665 -- EXTERNAL_SYMBOL ::=
17666 -- IDENTIFIER
17667 -- | static_string_EXPRESSION
17668
17669 -- PARAMETER_TYPES ::=
17670 -- null
17671 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17672
17673 -- TYPE_DESIGNATOR ::=
17674 -- subtype_NAME
17675 -- | subtype_Name ' Access
17676
17677 -- MECHANISM ::=
17678 -- MECHANISM_NAME
17679 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17680
17681 -- MECHANISM_ASSOCIATION ::=
17682 -- [formal_parameter_NAME =>] MECHANISM_NAME
17683
17684 -- MECHANISM_NAME ::=
17685 -- Value
17686 -- | Reference
17687
17688 when Pragma_Import_Procedure => Import_Procedure : declare
17689 Args : Args_List (1 .. 4);
17690 Names : constant Name_List (1 .. 4) := (
17691 Name_Internal,
17692 Name_External,
17693 Name_Parameter_Types,
17694 Name_Mechanism);
17695
17696 Internal : Node_Id renames Args (1);
17697 External : Node_Id renames Args (2);
17698 Parameter_Types : Node_Id renames Args (3);
17699 Mechanism : Node_Id renames Args (4);
17700
17701 begin
17702 GNAT_Pragma;
17703 Gather_Associations (Names, Args);
17704 Process_Extended_Import_Export_Subprogram_Pragma (
17705 Arg_Internal => Internal,
17706 Arg_External => External,
17707 Arg_Parameter_Types => Parameter_Types,
17708 Arg_Mechanism => Mechanism);
17709 end Import_Procedure;
17710
17711 -----------------------------
17712 -- Import_Valued_Procedure --
17713 -----------------------------
17714
17715 -- pragma Import_Valued_Procedure (
17716 -- [Internal =>] LOCAL_NAME
17717 -- [, [External =>] EXTERNAL_SYMBOL]
17718 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17719 -- [, [Mechanism =>] MECHANISM]);
17720
17721 -- EXTERNAL_SYMBOL ::=
17722 -- IDENTIFIER
17723 -- | static_string_EXPRESSION
17724
17725 -- PARAMETER_TYPES ::=
17726 -- null
17727 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17728
17729 -- TYPE_DESIGNATOR ::=
17730 -- subtype_NAME
17731 -- | subtype_Name ' Access
17732
17733 -- MECHANISM ::=
17734 -- MECHANISM_NAME
17735 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17736
17737 -- MECHANISM_ASSOCIATION ::=
17738 -- [formal_parameter_NAME =>] MECHANISM_NAME
17739
17740 -- MECHANISM_NAME ::=
17741 -- Value
17742 -- | Reference
17743
17744 when Pragma_Import_Valued_Procedure =>
17745 Import_Valued_Procedure : declare
17746 Args : Args_List (1 .. 4);
17747 Names : constant Name_List (1 .. 4) := (
17748 Name_Internal,
17749 Name_External,
17750 Name_Parameter_Types,
17751 Name_Mechanism);
17752
17753 Internal : Node_Id renames Args (1);
17754 External : Node_Id renames Args (2);
17755 Parameter_Types : Node_Id renames Args (3);
17756 Mechanism : Node_Id renames Args (4);
17757
17758 begin
17759 GNAT_Pragma;
17760 Gather_Associations (Names, Args);
17761 Process_Extended_Import_Export_Subprogram_Pragma (
17762 Arg_Internal => Internal,
17763 Arg_External => External,
17764 Arg_Parameter_Types => Parameter_Types,
17765 Arg_Mechanism => Mechanism);
17766 end Import_Valued_Procedure;
17767
17768 -----------------
17769 -- Independent --
17770 -----------------
17771
17772 -- pragma Independent (LOCAL_NAME);
17773
17774 when Pragma_Independent =>
17775 Process_Atomic_Independent_Shared_Volatile;
17776
17777 ----------------------------
17778 -- Independent_Components --
17779 ----------------------------
17780
17781 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
17782
17783 when Pragma_Independent_Components => Independent_Components : declare
17784 C : Node_Id;
17785 D : Node_Id;
17786 E_Id : Node_Id;
17787 E : Entity_Id;
17788
17789 begin
17790 Check_Ada_83_Warning;
17791 Ada_2012_Pragma;
17792 Check_No_Identifiers;
17793 Check_Arg_Count (1);
17794 Check_Arg_Is_Local_Name (Arg1);
17795 E_Id := Get_Pragma_Arg (Arg1);
17796
17797 if Etype (E_Id) = Any_Type then
17798 return;
17799 end if;
17800
17801 E := Entity (E_Id);
17802
17803 -- A record type with a self-referential component of anonymous
17804 -- access type is given an incomplete view in order to handle the
17805 -- self reference:
17806 --
17807 -- type Rec is record
17808 -- Self : access Rec;
17809 -- end record;
17810 --
17811 -- becomes
17812 --
17813 -- type Rec;
17814 -- type Ptr is access Rec;
17815 -- type Rec is record
17816 -- Self : Ptr;
17817 -- end record;
17818 --
17819 -- Since the incomplete view is now the initial view of the type,
17820 -- the argument of the pragma will reference the incomplete view,
17821 -- but this view is illegal according to the semantics of the
17822 -- pragma.
17823 --
17824 -- Obtain the full view of an internally-generated incomplete type
17825 -- only. This way an attempt to associate the pragma with a source
17826 -- incomplete type is still caught.
17827
17828 if Ekind (E) = E_Incomplete_Type
17829 and then not Comes_From_Source (E)
17830 and then Present (Full_View (E))
17831 then
17832 E := Full_View (E);
17833 end if;
17834
17835 -- A pragma that applies to a Ghost entity becomes Ghost for the
17836 -- purposes of legality checks and removal of ignored Ghost code.
17837
17838 Mark_Ghost_Pragma (N, E);
17839
17840 -- Check duplicate before we chain ourselves
17841
17842 Check_Duplicate_Pragma (E);
17843
17844 -- Check appropriate entity
17845
17846 if Rep_Item_Too_Early (E, N)
17847 or else
17848 Rep_Item_Too_Late (E, N)
17849 then
17850 return;
17851 end if;
17852
17853 D := Declaration_Node (E);
17854
17855 -- The flag is set on the base type, or on the object
17856
17857 if Nkind (D) = N_Full_Type_Declaration
17858 and then (Is_Array_Type (E) or else Is_Record_Type (E))
17859 then
17860 Set_Has_Independent_Components (Base_Type (E));
17861 Record_Independence_Check (N, Base_Type (E));
17862
17863 -- For record type, set all components independent
17864
17865 if Is_Record_Type (E) then
17866 C := First_Component (E);
17867 while Present (C) loop
17868 Set_Is_Independent (C);
17869 Next_Component (C);
17870 end loop;
17871 end if;
17872
17873 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
17874 and then Nkind (D) = N_Object_Declaration
17875 and then Nkind (Object_Definition (D)) =
17876 N_Constrained_Array_Definition
17877 then
17878 Set_Has_Independent_Components (E);
17879 Record_Independence_Check (N, E);
17880
17881 else
17882 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
17883 end if;
17884 end Independent_Components;
17885
17886 -----------------------
17887 -- Initial_Condition --
17888 -----------------------
17889
17890 -- pragma Initial_Condition (boolean_EXPRESSION);
17891
17892 -- Characteristics:
17893
17894 -- * Analysis - The annotation undergoes initial checks to verify
17895 -- the legal placement and context. Secondary checks preanalyze the
17896 -- expression in:
17897
17898 -- Analyze_Initial_Condition_In_Decl_Part
17899
17900 -- * Expansion - The annotation is expanded during the expansion of
17901 -- the package body whose declaration is subject to the annotation
17902 -- as done in:
17903
17904 -- Expand_Pragma_Initial_Condition
17905
17906 -- * Template - The annotation utilizes the generic template of the
17907 -- related package declaration.
17908
17909 -- * Globals - Capture of global references must occur after full
17910 -- analysis.
17911
17912 -- * Instance - The annotation is instantiated automatically when
17913 -- the related generic package is instantiated.
17914
17915 when Pragma_Initial_Condition => Initial_Condition : declare
17916 Pack_Decl : Node_Id;
17917 Pack_Id : Entity_Id;
17918
17919 begin
17920 GNAT_Pragma;
17921 Check_No_Identifiers;
17922 Check_Arg_Count (1);
17923
17924 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
17925
17926 if Nkind (Pack_Decl) not in
17927 N_Generic_Package_Declaration | N_Package_Declaration
17928 then
17929 Pragma_Misplaced;
17930 end if;
17931
17932 Pack_Id := Defining_Entity (Pack_Decl);
17933
17934 -- A pragma that applies to a Ghost entity becomes Ghost for the
17935 -- purposes of legality checks and removal of ignored Ghost code.
17936
17937 Mark_Ghost_Pragma (N, Pack_Id);
17938
17939 -- Chain the pragma on the contract for further processing by
17940 -- Analyze_Initial_Condition_In_Decl_Part.
17941
17942 Add_Contract_Item (N, Pack_Id);
17943
17944 -- The legality checks of pragmas Abstract_State, Initializes, and
17945 -- Initial_Condition are affected by the SPARK mode in effect. In
17946 -- addition, these three pragmas are subject to an inherent order:
17947
17948 -- 1) Abstract_State
17949 -- 2) Initializes
17950 -- 3) Initial_Condition
17951
17952 -- Analyze all these pragmas in the order outlined above
17953
17954 Analyze_If_Present (Pragma_SPARK_Mode);
17955 Analyze_If_Present (Pragma_Abstract_State);
17956 Analyze_If_Present (Pragma_Initializes);
17957 end Initial_Condition;
17958
17959 ------------------------
17960 -- Initialize_Scalars --
17961 ------------------------
17962
17963 -- pragma Initialize_Scalars
17964 -- [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ];
17965
17966 -- TYPE_VALUE_PAIR ::=
17967 -- SCALAR_TYPE => static_EXPRESSION
17968
17969 -- SCALAR_TYPE :=
17970 -- Short_Float
17971 -- | Float
17972 -- | Long_Float
17973 -- | Long_Long_Float
17974 -- | Signed_8
17975 -- | Signed_16
17976 -- | Signed_32
17977 -- | Signed_64
17978 -- | Signed_128
17979 -- | Unsigned_8
17980 -- | Unsigned_16
17981 -- | Unsigned_32
17982 -- | Unsigned_64
17983 -- | Unsigned_128
17984
17985 when Pragma_Initialize_Scalars => Do_Initialize_Scalars : declare
17986 Seen : array (Scalar_Id) of Node_Id := (others => Empty);
17987 -- This collection holds the individual pairs which specify the
17988 -- invalid values of their respective scalar types.
17989
17990 procedure Analyze_Float_Value
17991 (Scal_Typ : Float_Scalar_Id;
17992 Val_Expr : Node_Id);
17993 -- Analyze a type value pair associated with float type Scal_Typ
17994 -- and expression Val_Expr.
17995
17996 procedure Analyze_Integer_Value
17997 (Scal_Typ : Integer_Scalar_Id;
17998 Val_Expr : Node_Id);
17999 -- Analyze a type value pair associated with integer type Scal_Typ
18000 -- and expression Val_Expr.
18001
18002 procedure Analyze_Type_Value_Pair (Pair : Node_Id);
18003 -- Analyze type value pair Pair
18004
18005 -------------------------
18006 -- Analyze_Float_Value --
18007 -------------------------
18008
18009 procedure Analyze_Float_Value
18010 (Scal_Typ : Float_Scalar_Id;
18011 Val_Expr : Node_Id)
18012 is
18013 begin
18014 Analyze_And_Resolve (Val_Expr, Any_Real);
18015
18016 if Is_OK_Static_Expression (Val_Expr) then
18017 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value_R (Val_Expr));
18018
18019 else
18020 Error_Msg_Name_1 := Scal_Typ;
18021 Error_Msg_N ("value for type % must be static", Val_Expr);
18022 end if;
18023 end Analyze_Float_Value;
18024
18025 ---------------------------
18026 -- Analyze_Integer_Value --
18027 ---------------------------
18028
18029 procedure Analyze_Integer_Value
18030 (Scal_Typ : Integer_Scalar_Id;
18031 Val_Expr : Node_Id)
18032 is
18033 begin
18034 Analyze_And_Resolve (Val_Expr, Any_Integer);
18035
18036 if (Scal_Typ = Name_Signed_128
18037 or else Scal_Typ = Name_Unsigned_128)
18038 and then Ttypes.System_Max_Integer_Size < 128
18039 then
18040 Error_Msg_Name_1 := Scal_Typ;
18041 Error_Msg_N ("value cannot be set for type %", Val_Expr);
18042
18043 elsif Is_OK_Static_Expression (Val_Expr) then
18044 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value (Val_Expr));
18045
18046 else
18047 Error_Msg_Name_1 := Scal_Typ;
18048 Error_Msg_N ("value for type % must be static", Val_Expr);
18049 end if;
18050 end Analyze_Integer_Value;
18051
18052 -----------------------------
18053 -- Analyze_Type_Value_Pair --
18054 -----------------------------
18055
18056 procedure Analyze_Type_Value_Pair (Pair : Node_Id) is
18057 Scal_Typ : constant Name_Id := Chars (Pair);
18058 Val_Expr : constant Node_Id := Expression (Pair);
18059 Prev_Pair : Node_Id;
18060
18061 begin
18062 if Scal_Typ in Scalar_Id then
18063 Prev_Pair := Seen (Scal_Typ);
18064
18065 -- Prevent multiple attempts to set a value for a scalar
18066 -- type.
18067
18068 if Present (Prev_Pair) then
18069 Error_Msg_Name_1 := Scal_Typ;
18070 Error_Msg_N
18071 ("cannot specify multiple invalid values for type %",
18072 Pair);
18073
18074 Error_Msg_Sloc := Sloc (Prev_Pair);
18075 Error_Msg_N ("previous value set #", Pair);
18076
18077 -- Ignore the effects of the pair, but do not halt the
18078 -- analysis of the pragma altogether.
18079
18080 return;
18081
18082 -- Otherwise capture the first pair for this scalar type
18083
18084 else
18085 Seen (Scal_Typ) := Pair;
18086 end if;
18087
18088 if Scal_Typ in Float_Scalar_Id then
18089 Analyze_Float_Value (Scal_Typ, Val_Expr);
18090
18091 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
18092 Analyze_Integer_Value (Scal_Typ, Val_Expr);
18093 end if;
18094
18095 -- Otherwise the scalar family is illegal
18096
18097 else
18098 Error_Msg_Name_1 := Pname;
18099 Error_Msg_N
18100 ("argument of pragma % must denote valid scalar family",
18101 Pair);
18102 end if;
18103 end Analyze_Type_Value_Pair;
18104
18105 -- Local variables
18106
18107 Pairs : constant List_Id := Pragma_Argument_Associations (N);
18108 Pair : Node_Id;
18109
18110 -- Start of processing for Do_Initialize_Scalars
18111
18112 begin
18113 GNAT_Pragma;
18114 Check_Valid_Configuration_Pragma;
18115 Check_Restriction (No_Initialize_Scalars, N);
18116
18117 -- Ignore the effects of the pragma when No_Initialize_Scalars is
18118 -- in effect.
18119
18120 if Restriction_Active (No_Initialize_Scalars) then
18121 null;
18122
18123 -- Initialize_Scalars creates false positives in CodePeer, and
18124 -- incorrect negative results in GNATprove mode, so ignore this
18125 -- pragma in these modes.
18126
18127 elsif CodePeer_Mode or GNATprove_Mode then
18128 null;
18129
18130 -- Otherwise analyze the pragma
18131
18132 else
18133 if Present (Pairs) then
18134
18135 -- Install Standard in order to provide access to primitive
18136 -- types in case the expressions contain attributes such as
18137 -- Integer'Last.
18138
18139 Push_Scope (Standard_Standard);
18140
18141 Pair := First (Pairs);
18142 while Present (Pair) loop
18143 Analyze_Type_Value_Pair (Pair);
18144 Next (Pair);
18145 end loop;
18146
18147 -- Remove Standard
18148
18149 Pop_Scope;
18150 end if;
18151
18152 Init_Or_Norm_Scalars := True;
18153 Initialize_Scalars := True;
18154 end if;
18155 end Do_Initialize_Scalars;
18156
18157 -----------------
18158 -- Initializes --
18159 -----------------
18160
18161 -- pragma Initializes (INITIALIZATION_LIST);
18162
18163 -- INITIALIZATION_LIST ::=
18164 -- null
18165 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
18166
18167 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
18168
18169 -- INPUT_LIST ::=
18170 -- null
18171 -- | INPUT
18172 -- | (INPUT {, INPUT})
18173
18174 -- INPUT ::= name
18175
18176 -- Characteristics:
18177
18178 -- * Analysis - The annotation undergoes initial checks to verify
18179 -- the legal placement and context. Secondary checks preanalyze the
18180 -- expression in:
18181
18182 -- Analyze_Initializes_In_Decl_Part
18183
18184 -- * Expansion - None.
18185
18186 -- * Template - The annotation utilizes the generic template of the
18187 -- related package declaration.
18188
18189 -- * Globals - Capture of global references must occur after full
18190 -- analysis.
18191
18192 -- * Instance - The annotation is instantiated automatically when
18193 -- the related generic package is instantiated.
18194
18195 when Pragma_Initializes => Initializes : declare
18196 Pack_Decl : Node_Id;
18197 Pack_Id : Entity_Id;
18198
18199 begin
18200 GNAT_Pragma;
18201 Check_No_Identifiers;
18202 Check_Arg_Count (1);
18203
18204 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
18205
18206 if Nkind (Pack_Decl) not in
18207 N_Generic_Package_Declaration | N_Package_Declaration
18208 then
18209 Pragma_Misplaced;
18210 end if;
18211
18212 Pack_Id := Defining_Entity (Pack_Decl);
18213
18214 -- A pragma that applies to a Ghost entity becomes Ghost for the
18215 -- purposes of legality checks and removal of ignored Ghost code.
18216
18217 Mark_Ghost_Pragma (N, Pack_Id);
18218 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
18219
18220 -- Chain the pragma on the contract for further processing by
18221 -- Analyze_Initializes_In_Decl_Part.
18222
18223 Add_Contract_Item (N, Pack_Id);
18224
18225 -- The legality checks of pragmas Abstract_State, Initializes, and
18226 -- Initial_Condition are affected by the SPARK mode in effect. In
18227 -- addition, these three pragmas are subject to an inherent order:
18228
18229 -- 1) Abstract_State
18230 -- 2) Initializes
18231 -- 3) Initial_Condition
18232
18233 -- Analyze all these pragmas in the order outlined above
18234
18235 Analyze_If_Present (Pragma_SPARK_Mode);
18236 Analyze_If_Present (Pragma_Abstract_State);
18237 Analyze_If_Present (Pragma_Initial_Condition);
18238 end Initializes;
18239
18240 ------------
18241 -- Inline --
18242 ------------
18243
18244 -- pragma Inline ( NAME {, NAME} );
18245
18246 when Pragma_Inline =>
18247
18248 -- Pragma always active unless in GNATprove mode. It is disabled
18249 -- in GNATprove mode because frontend inlining is applied
18250 -- independently of pragmas Inline and Inline_Always for
18251 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
18252 -- in inline.ads.
18253
18254 if not GNATprove_Mode then
18255
18256 -- Inline status is Enabled if option -gnatn is specified.
18257 -- However this status determines only the value of the
18258 -- Is_Inlined flag on the subprogram and does not prevent
18259 -- the pragma itself from being recorded for later use,
18260 -- in particular for a later modification of Is_Inlined
18261 -- independently of the -gnatn option.
18262
18263 -- In other words, if -gnatn is specified for a unit, then
18264 -- all Inline pragmas processed for the compilation of this
18265 -- unit, including those in the spec of other units, are
18266 -- activated, so subprograms will be inlined across units.
18267
18268 -- If -gnatn is not specified, no Inline pragma is activated
18269 -- here, which means that subprograms will not be inlined
18270 -- across units. The Is_Inlined flag will nevertheless be
18271 -- set later when bodies are analyzed, so subprograms will
18272 -- be inlined within the unit.
18273
18274 if Inline_Active then
18275 Process_Inline (Enabled);
18276 else
18277 Process_Inline (Disabled);
18278 end if;
18279 end if;
18280
18281 -------------------
18282 -- Inline_Always --
18283 -------------------
18284
18285 -- pragma Inline_Always ( NAME {, NAME} );
18286
18287 when Pragma_Inline_Always =>
18288 GNAT_Pragma;
18289
18290 -- Pragma always active unless in CodePeer mode or GNATprove
18291 -- mode. It is disabled in CodePeer mode because inlining is
18292 -- not helpful, and enabling it caused walk order issues. It
18293 -- is disabled in GNATprove mode because frontend inlining is
18294 -- applied independently of pragmas Inline and Inline_Always for
18295 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
18296 -- inline.ads.
18297
18298 if not CodePeer_Mode and not GNATprove_Mode then
18299 Process_Inline (Enabled);
18300 end if;
18301
18302 --------------------
18303 -- Inline_Generic --
18304 --------------------
18305
18306 -- pragma Inline_Generic (NAME {, NAME});
18307
18308 when Pragma_Inline_Generic =>
18309 GNAT_Pragma;
18310 Process_Generic_List;
18311
18312 ----------------------
18313 -- Inspection_Point --
18314 ----------------------
18315
18316 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
18317
18318 when Pragma_Inspection_Point => Inspection_Point : declare
18319 Arg : Node_Id;
18320 Exp : Node_Id;
18321
18322 begin
18323 ip;
18324
18325 if Arg_Count > 0 then
18326 Arg := Arg1;
18327 loop
18328 Exp := Get_Pragma_Arg (Arg);
18329 Analyze (Exp);
18330
18331 if not Is_Entity_Name (Exp)
18332 or else not Is_Object (Entity (Exp))
18333 then
18334 Error_Pragma_Arg ("object name required", Arg);
18335 end if;
18336
18337 Next (Arg);
18338 exit when No (Arg);
18339 end loop;
18340 end if;
18341 end Inspection_Point;
18342
18343 ---------------
18344 -- Interface --
18345 ---------------
18346
18347 -- pragma Interface (
18348 -- [ Convention =>] convention_IDENTIFIER,
18349 -- [ Entity =>] LOCAL_NAME
18350 -- [, [External_Name =>] static_string_EXPRESSION ]
18351 -- [, [Link_Name =>] static_string_EXPRESSION ]);
18352
18353 when Pragma_Interface =>
18354 GNAT_Pragma;
18355 Check_Arg_Order
18356 ((Name_Convention,
18357 Name_Entity,
18358 Name_External_Name,
18359 Name_Link_Name));
18360 Check_At_Least_N_Arguments (2);
18361 Check_At_Most_N_Arguments (4);
18362 Process_Import_Or_Interface;
18363
18364 -- In Ada 2005, the permission to use Interface (a reserved word)
18365 -- as a pragma name is considered an obsolescent feature, and this
18366 -- pragma was already obsolescent in Ada 95.
18367
18368 if Ada_Version >= Ada_95 then
18369 Check_Restriction
18370 (No_Obsolescent_Features, Pragma_Identifier (N));
18371
18372 if Warn_On_Obsolescent_Feature then
18373 Error_Msg_N
18374 ("pragma Interface is an obsolescent feature?j?", N);
18375 Error_Msg_N
18376 ("|use pragma Import instead?j?", N);
18377 end if;
18378 end if;
18379
18380 --------------------
18381 -- Interface_Name --
18382 --------------------
18383
18384 -- pragma Interface_Name (
18385 -- [ Entity =>] LOCAL_NAME
18386 -- [,[External_Name =>] static_string_EXPRESSION ]
18387 -- [,[Link_Name =>] static_string_EXPRESSION ]);
18388
18389 when Pragma_Interface_Name => Interface_Name : declare
18390 Id : Node_Id;
18391 Def_Id : Entity_Id;
18392 Hom_Id : Entity_Id;
18393 Found : Boolean;
18394
18395 begin
18396 GNAT_Pragma;
18397 Check_Arg_Order
18398 ((Name_Entity, Name_External_Name, Name_Link_Name));
18399 Check_At_Least_N_Arguments (2);
18400 Check_At_Most_N_Arguments (3);
18401 Id := Get_Pragma_Arg (Arg1);
18402 Analyze (Id);
18403
18404 -- This is obsolete from Ada 95 on, but it is an implementation
18405 -- defined pragma, so we do not consider that it violates the
18406 -- restriction (No_Obsolescent_Features).
18407
18408 if Ada_Version >= Ada_95 then
18409 if Warn_On_Obsolescent_Feature then
18410 Error_Msg_N
18411 ("pragma Interface_Name is an obsolescent feature?j?", N);
18412 Error_Msg_N
18413 ("|use pragma Import instead?j?", N);
18414 end if;
18415 end if;
18416
18417 if not Is_Entity_Name (Id) then
18418 Error_Pragma_Arg
18419 ("first argument for pragma% must be entity name", Arg1);
18420 elsif Etype (Id) = Any_Type then
18421 return;
18422 else
18423 Def_Id := Entity (Id);
18424 end if;
18425
18426 -- Special DEC-compatible processing for the object case, forces
18427 -- object to be imported.
18428
18429 if Ekind (Def_Id) = E_Variable then
18430 Kill_Size_Check_Code (Def_Id);
18431 Note_Possible_Modification (Id, Sure => False);
18432
18433 -- Initialization is not allowed for imported variable
18434
18435 if Present (Expression (Parent (Def_Id)))
18436 and then Comes_From_Source (Expression (Parent (Def_Id)))
18437 then
18438 Error_Msg_Sloc := Sloc (Def_Id);
18439 Error_Pragma_Arg
18440 ("no initialization allowed for declaration of& #",
18441 Arg2);
18442
18443 else
18444 -- For compatibility, support VADS usage of providing both
18445 -- pragmas Interface and Interface_Name to obtain the effect
18446 -- of a single Import pragma.
18447
18448 if Is_Imported (Def_Id)
18449 and then Present (First_Rep_Item (Def_Id))
18450 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
18451 and then Pragma_Name (First_Rep_Item (Def_Id)) =
18452 Name_Interface
18453 then
18454 null;
18455 else
18456 Set_Imported (Def_Id);
18457 end if;
18458
18459 Set_Is_Public (Def_Id);
18460 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
18461 end if;
18462
18463 -- Otherwise must be subprogram
18464
18465 elsif not Is_Subprogram (Def_Id) then
18466 Error_Pragma_Arg
18467 ("argument of pragma% is not subprogram", Arg1);
18468
18469 else
18470 Check_At_Most_N_Arguments (3);
18471 Hom_Id := Def_Id;
18472 Found := False;
18473
18474 -- Loop through homonyms
18475
18476 loop
18477 Def_Id := Get_Base_Subprogram (Hom_Id);
18478
18479 if Is_Imported (Def_Id) then
18480 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
18481 Found := True;
18482 end if;
18483
18484 exit when From_Aspect_Specification (N);
18485 Hom_Id := Homonym (Hom_Id);
18486
18487 exit when No (Hom_Id)
18488 or else Scope (Hom_Id) /= Current_Scope;
18489 end loop;
18490
18491 if not Found then
18492 Error_Pragma_Arg
18493 ("argument of pragma% is not imported subprogram",
18494 Arg1);
18495 end if;
18496 end if;
18497 end Interface_Name;
18498
18499 -----------------------
18500 -- Interrupt_Handler --
18501 -----------------------
18502
18503 -- pragma Interrupt_Handler (handler_NAME);
18504
18505 when Pragma_Interrupt_Handler =>
18506 Check_Ada_83_Warning;
18507 Check_Arg_Count (1);
18508 Check_No_Identifiers;
18509
18510 if No_Run_Time_Mode then
18511 Error_Msg_CRT ("Interrupt_Handler pragma", N);
18512 else
18513 Check_Interrupt_Or_Attach_Handler;
18514 Process_Interrupt_Or_Attach_Handler;
18515 end if;
18516
18517 ------------------------
18518 -- Interrupt_Priority --
18519 ------------------------
18520
18521 -- pragma Interrupt_Priority [(EXPRESSION)];
18522
18523 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
18524 P : constant Node_Id := Parent (N);
18525 Arg : Node_Id;
18526 Ent : Entity_Id;
18527
18528 begin
18529 Check_Ada_83_Warning;
18530
18531 if Arg_Count /= 0 then
18532 Arg := Get_Pragma_Arg (Arg1);
18533 Check_Arg_Count (1);
18534 Check_No_Identifiers;
18535
18536 -- The expression must be analyzed in the special manner
18537 -- described in "Handling of Default and Per-Object
18538 -- Expressions" in sem.ads.
18539
18540 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
18541 end if;
18542
18543 if Nkind (P) not in N_Task_Definition | N_Protected_Definition then
18544 Pragma_Misplaced;
18545
18546 else
18547 Ent := Defining_Identifier (Parent (P));
18548
18549 -- Check duplicate pragma before we chain the pragma in the Rep
18550 -- Item chain of Ent.
18551
18552 Check_Duplicate_Pragma (Ent);
18553 Record_Rep_Item (Ent, N);
18554
18555 -- Check the No_Task_At_Interrupt_Priority restriction
18556
18557 if Nkind (P) = N_Task_Definition then
18558 Check_Restriction (No_Task_At_Interrupt_Priority, N);
18559 end if;
18560 end if;
18561 end Interrupt_Priority;
18562
18563 ---------------------
18564 -- Interrupt_State --
18565 ---------------------
18566
18567 -- pragma Interrupt_State (
18568 -- [Name =>] INTERRUPT_ID,
18569 -- [State =>] INTERRUPT_STATE);
18570
18571 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
18572 -- INTERRUPT_STATE => System | Runtime | User
18573
18574 -- Note: if the interrupt id is given as an identifier, then it must
18575 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
18576 -- given as a static integer expression which must be in the range of
18577 -- Ada.Interrupts.Interrupt_ID.
18578
18579 when Pragma_Interrupt_State => Interrupt_State : declare
18580 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
18581 -- This is the entity Ada.Interrupts.Interrupt_ID;
18582
18583 State_Type : Character;
18584 -- Set to 's'/'r'/'u' for System/Runtime/User
18585
18586 IST_Num : Pos;
18587 -- Index to entry in Interrupt_States table
18588
18589 Int_Val : Uint;
18590 -- Value of interrupt
18591
18592 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
18593 -- The first argument to the pragma
18594
18595 Int_Ent : Entity_Id;
18596 -- Interrupt entity in Ada.Interrupts.Names
18597
18598 begin
18599 GNAT_Pragma;
18600 Check_Arg_Order ((Name_Name, Name_State));
18601 Check_Arg_Count (2);
18602
18603 Check_Optional_Identifier (Arg1, Name_Name);
18604 Check_Optional_Identifier (Arg2, Name_State);
18605 Check_Arg_Is_Identifier (Arg2);
18606
18607 -- First argument is identifier
18608
18609 if Nkind (Arg1X) = N_Identifier then
18610
18611 -- Search list of names in Ada.Interrupts.Names
18612
18613 Int_Ent := First_Entity (RTE (RE_Names));
18614 loop
18615 if No (Int_Ent) then
18616 Error_Pragma_Arg ("invalid interrupt name", Arg1);
18617
18618 elsif Chars (Int_Ent) = Chars (Arg1X) then
18619 Int_Val := Expr_Value (Constant_Value (Int_Ent));
18620 exit;
18621 end if;
18622
18623 Next_Entity (Int_Ent);
18624 end loop;
18625
18626 -- First argument is not an identifier, so it must be a static
18627 -- expression of type Ada.Interrupts.Interrupt_ID.
18628
18629 else
18630 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
18631 Int_Val := Expr_Value (Arg1X);
18632
18633 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
18634 or else
18635 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
18636 then
18637 Error_Pragma_Arg
18638 ("value not in range of type "
18639 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
18640 end if;
18641 end if;
18642
18643 -- Check OK state
18644
18645 case Chars (Get_Pragma_Arg (Arg2)) is
18646 when Name_Runtime => State_Type := 'r';
18647 when Name_System => State_Type := 's';
18648 when Name_User => State_Type := 'u';
18649
18650 when others =>
18651 Error_Pragma_Arg ("invalid interrupt state", Arg2);
18652 end case;
18653
18654 -- Check if entry is already stored
18655
18656 IST_Num := Interrupt_States.First;
18657 loop
18658 -- If entry not found, add it
18659
18660 if IST_Num > Interrupt_States.Last then
18661 Interrupt_States.Append
18662 ((Interrupt_Number => UI_To_Int (Int_Val),
18663 Interrupt_State => State_Type,
18664 Pragma_Loc => Loc));
18665 exit;
18666
18667 -- Case of entry for the same entry
18668
18669 elsif Int_Val = Interrupt_States.Table (IST_Num).
18670 Interrupt_Number
18671 then
18672 -- If state matches, done, no need to make redundant entry
18673
18674 exit when
18675 State_Type = Interrupt_States.Table (IST_Num).
18676 Interrupt_State;
18677
18678 -- Otherwise if state does not match, error
18679
18680 Error_Msg_Sloc :=
18681 Interrupt_States.Table (IST_Num).Pragma_Loc;
18682 Error_Pragma_Arg
18683 ("state conflicts with that given #", Arg2);
18684 end if;
18685
18686 IST_Num := IST_Num + 1;
18687 end loop;
18688 end Interrupt_State;
18689
18690 ---------------
18691 -- Invariant --
18692 ---------------
18693
18694 -- pragma Invariant
18695 -- ([Entity =>] type_LOCAL_NAME,
18696 -- [Check =>] EXPRESSION
18697 -- [,[Message =>] String_Expression]);
18698
18699 when Pragma_Invariant => Invariant : declare
18700 Discard : Boolean;
18701 Typ : Entity_Id;
18702 Typ_Arg : Node_Id;
18703
18704 begin
18705 GNAT_Pragma;
18706 Check_At_Least_N_Arguments (2);
18707 Check_At_Most_N_Arguments (3);
18708 Check_Optional_Identifier (Arg1, Name_Entity);
18709 Check_Optional_Identifier (Arg2, Name_Check);
18710
18711 if Arg_Count = 3 then
18712 Check_Optional_Identifier (Arg3, Name_Message);
18713 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
18714 end if;
18715
18716 Check_Arg_Is_Local_Name (Arg1);
18717
18718 Typ_Arg := Get_Pragma_Arg (Arg1);
18719 Find_Type (Typ_Arg);
18720 Typ := Entity (Typ_Arg);
18721
18722 -- Nothing to do of the related type is erroneous in some way
18723
18724 if Typ = Any_Type then
18725 return;
18726
18727 -- AI12-0041: Invariants are allowed in interface types
18728
18729 elsif Is_Interface (Typ) then
18730 null;
18731
18732 -- An invariant must apply to a private type, or appear in the
18733 -- private part of a package spec and apply to a completion.
18734 -- a class-wide invariant can only appear on a private declaration
18735 -- or private extension, not a completion.
18736
18737 -- A [class-wide] invariant may be associated a [limited] private
18738 -- type or a private extension.
18739
18740 elsif Ekind (Typ) in E_Limited_Private_Type
18741 | E_Private_Type
18742 | E_Record_Type_With_Private
18743 then
18744 null;
18745
18746 -- A non-class-wide invariant may be associated with the full view
18747 -- of a [limited] private type or a private extension.
18748
18749 elsif Has_Private_Declaration (Typ)
18750 and then not Class_Present (N)
18751 then
18752 null;
18753
18754 -- A class-wide invariant may appear on the partial view only
18755
18756 elsif Class_Present (N) then
18757 Error_Pragma_Arg
18758 ("pragma % only allowed for private type", Arg1);
18759
18760 -- A regular invariant may appear on both views
18761
18762 else
18763 Error_Pragma_Arg
18764 ("pragma % only allowed for private type or corresponding "
18765 & "full view", Arg1);
18766 end if;
18767
18768 -- An invariant associated with an abstract type (this includes
18769 -- interfaces) must be class-wide.
18770
18771 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
18772 Error_Pragma_Arg
18773 ("pragma % not allowed for abstract type", Arg1);
18774 end if;
18775
18776 -- A pragma that applies to a Ghost entity becomes Ghost for the
18777 -- purposes of legality checks and removal of ignored Ghost code.
18778
18779 Mark_Ghost_Pragma (N, Typ);
18780
18781 -- The pragma defines a type-specific invariant, the type is said
18782 -- to have invariants of its "own".
18783
18784 Set_Has_Own_Invariants (Base_Type (Typ));
18785
18786 -- If the invariant is class-wide, then it can be inherited by
18787 -- derived or interface implementing types. The type is said to
18788 -- have "inheritable" invariants.
18789
18790 if Class_Present (N) then
18791 Set_Has_Inheritable_Invariants (Typ);
18792 end if;
18793
18794 -- Chain the pragma on to the rep item chain, for processing when
18795 -- the type is frozen.
18796
18797 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18798
18799 -- Create the declaration of the invariant procedure that will
18800 -- verify the invariant at run time. Interfaces are treated as the
18801 -- partial view of a private type in order to achieve uniformity
18802 -- with the general case. As a result, an interface receives only
18803 -- a "partial" invariant procedure, which is never called.
18804
18805 Build_Invariant_Procedure_Declaration
18806 (Typ => Typ,
18807 Partial_Invariant => Is_Interface (Typ));
18808 end Invariant;
18809
18810 ----------------
18811 -- Keep_Names --
18812 ----------------
18813
18814 -- pragma Keep_Names ([On => ] LOCAL_NAME);
18815
18816 when Pragma_Keep_Names => Keep_Names : declare
18817 Arg : Node_Id;
18818
18819 begin
18820 GNAT_Pragma;
18821 Check_Arg_Count (1);
18822 Check_Optional_Identifier (Arg1, Name_On);
18823 Check_Arg_Is_Local_Name (Arg1);
18824
18825 Arg := Get_Pragma_Arg (Arg1);
18826 Analyze (Arg);
18827
18828 if Etype (Arg) = Any_Type then
18829 return;
18830 end if;
18831
18832 if not Is_Entity_Name (Arg)
18833 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
18834 then
18835 Error_Pragma_Arg
18836 ("pragma% requires a local enumeration type", Arg1);
18837 end if;
18838
18839 Set_Discard_Names (Entity (Arg), False);
18840 end Keep_Names;
18841
18842 -------------
18843 -- License --
18844 -------------
18845
18846 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
18847
18848 when Pragma_License =>
18849 GNAT_Pragma;
18850
18851 -- Do not analyze pragma any further in CodePeer mode, to avoid
18852 -- extraneous errors in this implementation-dependent pragma,
18853 -- which has a different profile on other compilers.
18854
18855 if CodePeer_Mode then
18856 return;
18857 end if;
18858
18859 Check_Arg_Count (1);
18860 Check_No_Identifiers;
18861 Check_Valid_Configuration_Pragma;
18862 Check_Arg_Is_Identifier (Arg1);
18863
18864 declare
18865 Sind : constant Source_File_Index :=
18866 Source_Index (Current_Sem_Unit);
18867
18868 begin
18869 case Chars (Get_Pragma_Arg (Arg1)) is
18870 when Name_GPL =>
18871 Set_License (Sind, GPL);
18872
18873 when Name_Modified_GPL =>
18874 Set_License (Sind, Modified_GPL);
18875
18876 when Name_Restricted =>
18877 Set_License (Sind, Restricted);
18878
18879 when Name_Unrestricted =>
18880 Set_License (Sind, Unrestricted);
18881
18882 when others =>
18883 Error_Pragma_Arg ("invalid license name", Arg1);
18884 end case;
18885 end;
18886
18887 ---------------
18888 -- Link_With --
18889 ---------------
18890
18891 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
18892
18893 when Pragma_Link_With => Link_With : declare
18894 Arg : Node_Id;
18895
18896 begin
18897 GNAT_Pragma;
18898
18899 if Operating_Mode = Generate_Code
18900 and then In_Extended_Main_Source_Unit (N)
18901 then
18902 Check_At_Least_N_Arguments (1);
18903 Check_No_Identifiers;
18904 Check_Is_In_Decl_Part_Or_Package_Spec;
18905 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18906 Start_String;
18907
18908 Arg := Arg1;
18909 while Present (Arg) loop
18910 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
18911
18912 -- Store argument, converting sequences of spaces to a
18913 -- single null character (this is one of the differences
18914 -- in processing between Link_With and Linker_Options).
18915
18916 Arg_Store : declare
18917 C : constant Char_Code := Get_Char_Code (' ');
18918 S : constant String_Id :=
18919 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
18920 L : constant Nat := String_Length (S);
18921 F : Nat := 1;
18922
18923 procedure Skip_Spaces;
18924 -- Advance F past any spaces
18925
18926 -----------------
18927 -- Skip_Spaces --
18928 -----------------
18929
18930 procedure Skip_Spaces is
18931 begin
18932 while F <= L and then Get_String_Char (S, F) = C loop
18933 F := F + 1;
18934 end loop;
18935 end Skip_Spaces;
18936
18937 -- Start of processing for Arg_Store
18938
18939 begin
18940 Skip_Spaces; -- skip leading spaces
18941
18942 -- Loop through characters, changing any embedded
18943 -- sequence of spaces to a single null character (this
18944 -- is how Link_With/Linker_Options differ)
18945
18946 while F <= L loop
18947 if Get_String_Char (S, F) = C then
18948 Skip_Spaces;
18949 exit when F > L;
18950 Store_String_Char (ASCII.NUL);
18951
18952 else
18953 Store_String_Char (Get_String_Char (S, F));
18954 F := F + 1;
18955 end if;
18956 end loop;
18957 end Arg_Store;
18958
18959 Arg := Next (Arg);
18960
18961 if Present (Arg) then
18962 Store_String_Char (ASCII.NUL);
18963 end if;
18964 end loop;
18965
18966 Store_Linker_Option_String (End_String);
18967 end if;
18968 end Link_With;
18969
18970 ------------------
18971 -- Linker_Alias --
18972 ------------------
18973
18974 -- pragma Linker_Alias (
18975 -- [Entity =>] LOCAL_NAME
18976 -- [Target =>] static_string_EXPRESSION);
18977
18978 when Pragma_Linker_Alias =>
18979 GNAT_Pragma;
18980 Check_Arg_Order ((Name_Entity, Name_Target));
18981 Check_Arg_Count (2);
18982 Check_Optional_Identifier (Arg1, Name_Entity);
18983 Check_Optional_Identifier (Arg2, Name_Target);
18984 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18985 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
18986
18987 -- The only processing required is to link this item on to the
18988 -- list of rep items for the given entity. This is accomplished
18989 -- by the call to Rep_Item_Too_Late (when no error is detected
18990 -- and False is returned).
18991
18992 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
18993 return;
18994 else
18995 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
18996 end if;
18997
18998 ------------------------
18999 -- Linker_Constructor --
19000 ------------------------
19001
19002 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
19003
19004 -- Code is shared with Linker_Destructor
19005
19006 -----------------------
19007 -- Linker_Destructor --
19008 -----------------------
19009
19010 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
19011
19012 when Pragma_Linker_Constructor
19013 | Pragma_Linker_Destructor
19014 =>
19015 Linker_Constructor : declare
19016 Arg1_X : Node_Id;
19017 Proc : Entity_Id;
19018
19019 begin
19020 GNAT_Pragma;
19021 Check_Arg_Count (1);
19022 Check_No_Identifiers;
19023 Check_Arg_Is_Local_Name (Arg1);
19024 Arg1_X := Get_Pragma_Arg (Arg1);
19025 Analyze (Arg1_X);
19026 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
19027
19028 if not Is_Library_Level_Entity (Proc) then
19029 Error_Pragma_Arg
19030 ("argument for pragma% must be library level entity", Arg1);
19031 end if;
19032
19033 -- The only processing required is to link this item on to the
19034 -- list of rep items for the given entity. This is accomplished
19035 -- by the call to Rep_Item_Too_Late (when no error is detected
19036 -- and False is returned).
19037
19038 if Rep_Item_Too_Late (Proc, N) then
19039 return;
19040 else
19041 Set_Has_Gigi_Rep_Item (Proc);
19042 end if;
19043 end Linker_Constructor;
19044
19045 --------------------
19046 -- Linker_Options --
19047 --------------------
19048
19049 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
19050
19051 when Pragma_Linker_Options => Linker_Options : declare
19052 Arg : Node_Id;
19053
19054 begin
19055 Check_Ada_83_Warning;
19056 Check_No_Identifiers;
19057 Check_Arg_Count (1);
19058 Check_Is_In_Decl_Part_Or_Package_Spec;
19059 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
19060 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
19061
19062 Arg := Arg2;
19063 while Present (Arg) loop
19064 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
19065 Store_String_Char (ASCII.NUL);
19066 Store_String_Chars
19067 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
19068 Arg := Next (Arg);
19069 end loop;
19070
19071 if Operating_Mode = Generate_Code
19072 and then In_Extended_Main_Source_Unit (N)
19073 then
19074 Store_Linker_Option_String (End_String);
19075 end if;
19076 end Linker_Options;
19077
19078 --------------------
19079 -- Linker_Section --
19080 --------------------
19081
19082 -- pragma Linker_Section (
19083 -- [Entity =>] LOCAL_NAME
19084 -- [Section =>] static_string_EXPRESSION);
19085
19086 when Pragma_Linker_Section => Linker_Section : declare
19087 Arg : Node_Id;
19088 Ent : Entity_Id;
19089 LPE : Node_Id;
19090
19091 Ghost_Error_Posted : Boolean := False;
19092 -- Flag set when an error concerning the illegal mix of Ghost and
19093 -- non-Ghost subprograms is emitted.
19094
19095 Ghost_Id : Entity_Id := Empty;
19096 -- The entity of the first Ghost subprogram encountered while
19097 -- processing the arguments of the pragma.
19098
19099 begin
19100 GNAT_Pragma;
19101 Check_Arg_Order ((Name_Entity, Name_Section));
19102 Check_Arg_Count (2);
19103 Check_Optional_Identifier (Arg1, Name_Entity);
19104 Check_Optional_Identifier (Arg2, Name_Section);
19105 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19106 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19107
19108 -- Check kind of entity
19109
19110 Arg := Get_Pragma_Arg (Arg1);
19111 Ent := Entity (Arg);
19112
19113 case Ekind (Ent) is
19114
19115 -- Objects (constants and variables) and types. For these cases
19116 -- all we need to do is to set the Linker_Section_pragma field,
19117 -- checking that we do not have a duplicate.
19118
19119 when Type_Kind
19120 | E_Constant
19121 | E_Variable
19122 =>
19123 LPE := Linker_Section_Pragma (Ent);
19124
19125 if Present (LPE) then
19126 Error_Msg_Sloc := Sloc (LPE);
19127 Error_Msg_NE
19128 ("Linker_Section already specified for &#", Arg1, Ent);
19129 end if;
19130
19131 Set_Linker_Section_Pragma (Ent, N);
19132
19133 -- A pragma that applies to a Ghost entity becomes Ghost for
19134 -- the purposes of legality checks and removal of ignored
19135 -- Ghost code.
19136
19137 Mark_Ghost_Pragma (N, Ent);
19138
19139 -- Subprograms
19140
19141 when Subprogram_Kind =>
19142
19143 -- Aspect case, entity already set
19144
19145 if From_Aspect_Specification (N) then
19146 Set_Linker_Section_Pragma
19147 (Entity (Corresponding_Aspect (N)), N);
19148
19149 -- Propagate it to its ultimate aliased entity to
19150 -- facilitate the backend processing this attribute
19151 -- in instantiations of generic subprograms.
19152
19153 if Present (Alias (Entity (Corresponding_Aspect (N))))
19154 then
19155 Set_Linker_Section_Pragma
19156 (Ultimate_Alias
19157 (Entity (Corresponding_Aspect (N))), N);
19158 end if;
19159
19160 -- Pragma case, we must climb the homonym chain, but skip
19161 -- any for which the linker section is already set.
19162
19163 else
19164 loop
19165 if No (Linker_Section_Pragma (Ent)) then
19166 Set_Linker_Section_Pragma (Ent, N);
19167
19168 -- Propagate it to its ultimate aliased entity to
19169 -- facilitate the backend processing this attribute
19170 -- in instantiations of generic subprograms.
19171
19172 if Present (Alias (Ent)) then
19173 Set_Linker_Section_Pragma
19174 (Ultimate_Alias (Ent), N);
19175 end if;
19176
19177 -- A pragma that applies to a Ghost entity becomes
19178 -- Ghost for the purposes of legality checks and
19179 -- removal of ignored Ghost code.
19180
19181 Mark_Ghost_Pragma (N, Ent);
19182
19183 -- Capture the entity of the first Ghost subprogram
19184 -- being processed for error detection purposes.
19185
19186 if Is_Ghost_Entity (Ent) then
19187 if No (Ghost_Id) then
19188 Ghost_Id := Ent;
19189 end if;
19190
19191 -- Otherwise the subprogram is non-Ghost. It is
19192 -- illegal to mix references to Ghost and non-Ghost
19193 -- entities (SPARK RM 6.9).
19194
19195 elsif Present (Ghost_Id)
19196 and then not Ghost_Error_Posted
19197 then
19198 Ghost_Error_Posted := True;
19199
19200 Error_Msg_Name_1 := Pname;
19201 Error_Msg_N
19202 ("pragma % cannot mention ghost and "
19203 & "non-ghost subprograms", N);
19204
19205 Error_Msg_Sloc := Sloc (Ghost_Id);
19206 Error_Msg_NE
19207 ("\& # declared as ghost", N, Ghost_Id);
19208
19209 Error_Msg_Sloc := Sloc (Ent);
19210 Error_Msg_NE
19211 ("\& # declared as non-ghost", N, Ent);
19212 end if;
19213 end if;
19214
19215 Ent := Homonym (Ent);
19216 exit when No (Ent)
19217 or else Scope (Ent) /= Current_Scope;
19218 end loop;
19219 end if;
19220
19221 -- All other cases are illegal
19222
19223 when others =>
19224 Error_Pragma_Arg
19225 ("pragma% applies only to objects, subprograms, and types",
19226 Arg1);
19227 end case;
19228 end Linker_Section;
19229
19230 ----------
19231 -- List --
19232 ----------
19233
19234 -- pragma List (On | Off)
19235
19236 -- There is nothing to do here, since we did all the processing for
19237 -- this pragma in Par.Prag (so that it works properly even in syntax
19238 -- only mode).
19239
19240 when Pragma_List =>
19241 null;
19242
19243 ---------------
19244 -- Lock_Free --
19245 ---------------
19246
19247 -- pragma Lock_Free [(Boolean_EXPRESSION)];
19248
19249 when Pragma_Lock_Free => Lock_Free : declare
19250 P : constant Node_Id := Parent (N);
19251 Arg : Node_Id;
19252 Ent : Entity_Id;
19253 Val : Boolean;
19254
19255 begin
19256 Check_No_Identifiers;
19257 Check_At_Most_N_Arguments (1);
19258
19259 -- Protected definition case
19260
19261 if Nkind (P) = N_Protected_Definition then
19262 Ent := Defining_Identifier (Parent (P));
19263
19264 -- One argument
19265
19266 if Arg_Count = 1 then
19267 Arg := Get_Pragma_Arg (Arg1);
19268 Val := Is_True (Static_Boolean (Arg));
19269
19270 -- No arguments (expression is considered to be True)
19271
19272 else
19273 Val := True;
19274 end if;
19275
19276 -- Check duplicate pragma before we chain the pragma in the Rep
19277 -- Item chain of Ent.
19278
19279 Check_Duplicate_Pragma (Ent);
19280 Record_Rep_Item (Ent, N);
19281 Set_Uses_Lock_Free (Ent, Val);
19282
19283 -- Anything else is incorrect placement
19284
19285 else
19286 Pragma_Misplaced;
19287 end if;
19288 end Lock_Free;
19289
19290 --------------------
19291 -- Locking_Policy --
19292 --------------------
19293
19294 -- pragma Locking_Policy (policy_IDENTIFIER);
19295
19296 when Pragma_Locking_Policy => declare
19297 subtype LP_Range is Name_Id
19298 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
19299 LP_Val : LP_Range;
19300 LP : Character;
19301
19302 begin
19303 Check_Ada_83_Warning;
19304 Check_Arg_Count (1);
19305 Check_No_Identifiers;
19306 Check_Arg_Is_Locking_Policy (Arg1);
19307 Check_Valid_Configuration_Pragma;
19308 LP_Val := Chars (Get_Pragma_Arg (Arg1));
19309
19310 case LP_Val is
19311 when Name_Ceiling_Locking => LP := 'C';
19312 when Name_Concurrent_Readers_Locking => LP := 'R';
19313 when Name_Inheritance_Locking => LP := 'I';
19314 end case;
19315
19316 if Locking_Policy /= ' '
19317 and then Locking_Policy /= LP
19318 then
19319 Error_Msg_Sloc := Locking_Policy_Sloc;
19320 Error_Pragma ("locking policy incompatible with policy#");
19321
19322 -- Set new policy, but always preserve System_Location since we
19323 -- like the error message with the run time name.
19324
19325 else
19326 Locking_Policy := LP;
19327
19328 if Locking_Policy_Sloc /= System_Location then
19329 Locking_Policy_Sloc := Loc;
19330 end if;
19331 end if;
19332 end;
19333
19334 -------------------
19335 -- Loop_Optimize --
19336 -------------------
19337
19338 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
19339
19340 -- OPTIMIZATION_HINT ::=
19341 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
19342
19343 when Pragma_Loop_Optimize => Loop_Optimize : declare
19344 Hint : Node_Id;
19345
19346 begin
19347 GNAT_Pragma;
19348 Check_At_Least_N_Arguments (1);
19349 Check_No_Identifiers;
19350
19351 Hint := First (Pragma_Argument_Associations (N));
19352 while Present (Hint) loop
19353 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
19354 Name_No_Unroll,
19355 Name_Unroll,
19356 Name_No_Vector,
19357 Name_Vector);
19358 Next (Hint);
19359 end loop;
19360
19361 Check_Loop_Pragma_Placement;
19362 end Loop_Optimize;
19363
19364 ------------------
19365 -- Loop_Variant --
19366 ------------------
19367
19368 -- pragma Loop_Variant
19369 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
19370
19371 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
19372
19373 -- CHANGE_DIRECTION ::= Increases | Decreases
19374
19375 when Pragma_Loop_Variant => Loop_Variant : declare
19376 Variant : Node_Id;
19377
19378 begin
19379 GNAT_Pragma;
19380 Check_At_Least_N_Arguments (1);
19381 Check_Loop_Pragma_Placement;
19382
19383 -- Process all increasing / decreasing expressions
19384
19385 Variant := First (Pragma_Argument_Associations (N));
19386 while Present (Variant) loop
19387 if Chars (Variant) = No_Name then
19388 Error_Pragma_Arg_Ident ("expect name `Increases`", Variant);
19389
19390 elsif Chars (Variant) not in
19391 Name_Decreases | Name_Increases | Name_Structural
19392 then
19393 declare
19394 Name : String := Get_Name_String (Chars (Variant));
19395
19396 begin
19397 -- It is a common mistake to write "Increasing" for
19398 -- "Increases" or "Decreasing" for "Decreases". Recognize
19399 -- specially names starting with "incr" or "decr" to
19400 -- suggest the corresponding name.
19401
19402 System.Case_Util.To_Lower (Name);
19403
19404 if Name'Length >= 4
19405 and then Name (1 .. 4) = "incr"
19406 then
19407 Error_Pragma_Arg_Ident
19408 ("expect name `Increases`", Variant);
19409
19410 elsif Name'Length >= 4
19411 and then Name (1 .. 4) = "decr"
19412 then
19413 Error_Pragma_Arg_Ident
19414 ("expect name `Decreases`", Variant);
19415
19416 elsif Name'Length >= 4
19417 and then Name (1 .. 4) = "stru"
19418 then
19419 Error_Pragma_Arg_Ident
19420 ("expect name `Structural`", Variant);
19421
19422 else
19423 Error_Pragma_Arg_Ident
19424 ("expect name `Increases`, `Decreases`,"
19425 & " or `Structural`", Variant);
19426 end if;
19427 end;
19428
19429 elsif Chars (Variant) = Name_Structural
19430 and then List_Length (Pragma_Argument_Associations (N)) > 1
19431 then
19432 Error_Pragma_Arg_Ident
19433 ("Structural variant shall be the only variant", Variant);
19434 end if;
19435
19436 -- Preanalyze_Assert_Expression, but without enforcing any of
19437 -- the two acceptable types.
19438
19439 Preanalyze_Assert_Expression (Expression (Variant));
19440
19441 -- Expression of a discrete type is allowed. Nothing to
19442 -- check for structural variants.
19443
19444 if Chars (Variant) = Name_Structural
19445 or else Is_Discrete_Type (Etype (Expression (Variant)))
19446 then
19447 null;
19448
19449 -- Expression of a Big_Integer type (or its ghost variant) is
19450 -- only allowed in Decreases clause.
19451
19452 elsif
19453 Is_RTE (Base_Type (Etype (Expression (Variant))),
19454 RE_Big_Integer)
19455 or else
19456 Is_RTE (Base_Type (Etype (Expression (Variant))),
19457 RO_GH_Big_Integer)
19458 then
19459 if Chars (Variant) = Name_Increases then
19460 Error_Msg_N
19461 ("Loop_Variant with Big_Integer can only decrease",
19462 Expression (Variant));
19463 end if;
19464
19465 -- Expression of other types is not allowed
19466
19467 else
19468 Error_Msg_N
19469 ("expected a discrete or Big_Integer type",
19470 Expression (Variant));
19471 end if;
19472
19473 Next (Variant);
19474 end loop;
19475 end Loop_Variant;
19476
19477 -----------------------
19478 -- Machine_Attribute --
19479 -----------------------
19480
19481 -- pragma Machine_Attribute (
19482 -- [Entity =>] LOCAL_NAME,
19483 -- [Attribute_Name =>] static_string_EXPRESSION
19484 -- [, [Info =>] static_EXPRESSION {, static_EXPRESSION}] );
19485
19486 when Pragma_Machine_Attribute => Machine_Attribute : declare
19487 Arg : Node_Id;
19488 Def_Id : Entity_Id;
19489
19490 begin
19491 GNAT_Pragma;
19492 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
19493
19494 if Arg_Count >= 3 then
19495 Check_Optional_Identifier (Arg3, Name_Info);
19496 Arg := Arg3;
19497 while Present (Arg) loop
19498 Check_Arg_Is_OK_Static_Expression (Arg);
19499 Arg := Next (Arg);
19500 end loop;
19501 else
19502 Check_Arg_Count (2);
19503 end if;
19504
19505 Check_Optional_Identifier (Arg1, Name_Entity);
19506 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
19507 Check_Arg_Is_Local_Name (Arg1);
19508 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19509 Def_Id := Entity (Get_Pragma_Arg (Arg1));
19510
19511 -- Apply the pragma to the designated type, rather than to the
19512 -- access type, unless it's a strub annotation. We wish to enable
19513 -- objects of access type, as well as access types themselves, to
19514 -- be annotated, so that reading the access objects (as oposed to
19515 -- the designated data) automatically enables stack
19516 -- scrubbing. That said, as in the attribute handler that
19517 -- processes the pragma turned into a compiler attribute, a strub
19518 -- annotation that must be associated with a subprogram type (for
19519 -- holding an explicit strub mode), when applied to an
19520 -- access-to-subprogram, gets promoted to the subprogram type. We
19521 -- might be tempted to leave it alone here, since the C attribute
19522 -- handler will adjust it, but then GNAT would convert the
19523 -- annotated subprogram types to naked ones before using them,
19524 -- cancelling out their intended effects.
19525
19526 if Is_Access_Type (Def_Id)
19527 and then (not Strub_Pragma_P (N)
19528 or else
19529 (Present (Arg3)
19530 and then
19531 Ekind (Designated_Type
19532 (Def_Id)) = E_Subprogram_Type))
19533 then
19534 Def_Id := Designated_Type (Def_Id);
19535 end if;
19536
19537 if Rep_Item_Too_Early (Def_Id, N) then
19538 return;
19539 end if;
19540
19541 Def_Id := Underlying_Type (Def_Id);
19542
19543 -- The only processing required is to link this item on to the
19544 -- list of rep items for the given entity. This is accomplished
19545 -- by the call to Rep_Item_Too_Late (when no error is detected
19546 -- and False is returned).
19547
19548 if Rep_Item_Too_Late (Def_Id, N) then
19549 return;
19550 else
19551 Set_Has_Gigi_Rep_Item (Def_Id);
19552 end if;
19553 end Machine_Attribute;
19554
19555 ----------
19556 -- Main --
19557 ----------
19558
19559 -- pragma Main
19560 -- (MAIN_OPTION [, MAIN_OPTION]);
19561
19562 -- MAIN_OPTION ::=
19563 -- [STACK_SIZE =>] static_integer_EXPRESSION
19564 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
19565 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
19566
19567 when Pragma_Main => Main : declare
19568 Args : Args_List (1 .. 3);
19569 Names : constant Name_List (1 .. 3) := (
19570 Name_Stack_Size,
19571 Name_Task_Stack_Size_Default,
19572 Name_Time_Slicing_Enabled);
19573
19574 Nod : Node_Id;
19575
19576 begin
19577 GNAT_Pragma;
19578 Gather_Associations (Names, Args);
19579
19580 for J in 1 .. 2 loop
19581 if Present (Args (J)) then
19582 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19583 end if;
19584 end loop;
19585
19586 if Present (Args (3)) then
19587 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
19588 end if;
19589
19590 Nod := Next (N);
19591 while Present (Nod) loop
19592 if Nkind (Nod) = N_Pragma
19593 and then Pragma_Name (Nod) = Name_Main
19594 then
19595 Error_Msg_Name_1 := Pname;
19596 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19597 end if;
19598
19599 Next (Nod);
19600 end loop;
19601 end Main;
19602
19603 ------------------
19604 -- Main_Storage --
19605 ------------------
19606
19607 -- pragma Main_Storage
19608 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
19609
19610 -- MAIN_STORAGE_OPTION ::=
19611 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
19612 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
19613
19614 when Pragma_Main_Storage => Main_Storage : declare
19615 Args : Args_List (1 .. 2);
19616 Names : constant Name_List (1 .. 2) := (
19617 Name_Working_Storage,
19618 Name_Top_Guard);
19619
19620 Nod : Node_Id;
19621
19622 begin
19623 GNAT_Pragma;
19624 Gather_Associations (Names, Args);
19625
19626 for J in 1 .. 2 loop
19627 if Present (Args (J)) then
19628 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19629 end if;
19630 end loop;
19631
19632 Check_In_Main_Program;
19633
19634 Nod := Next (N);
19635 while Present (Nod) loop
19636 if Nkind (Nod) = N_Pragma
19637 and then Pragma_Name (Nod) = Name_Main_Storage
19638 then
19639 Error_Msg_Name_1 := Pname;
19640 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19641 end if;
19642
19643 Next (Nod);
19644 end loop;
19645 end Main_Storage;
19646
19647 ----------------------------
19648 -- Max_Entry_Queue_Length --
19649 ----------------------------
19650
19651 -- pragma Max_Entry_Queue_Length (static_integer_EXPRESSION);
19652
19653 -- This processing is shared by Pragma_Max_Entry_Queue_Depth and
19654 -- Pragma_Max_Queue_Length.
19655
19656 when Pragma_Max_Entry_Queue_Length
19657 | Pragma_Max_Entry_Queue_Depth
19658 | Pragma_Max_Queue_Length
19659 =>
19660 Max_Entry_Queue_Length : declare
19661 Arg : Node_Id;
19662 Entry_Decl : Node_Id;
19663 Entry_Id : Entity_Id;
19664 Val : Uint;
19665
19666 begin
19667 if Prag_Id = Pragma_Max_Entry_Queue_Depth
19668 or else Prag_Id = Pragma_Max_Queue_Length
19669 then
19670 GNAT_Pragma;
19671 end if;
19672
19673 Check_Arg_Count (1);
19674
19675 Entry_Decl :=
19676 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
19677
19678 -- Entry declaration
19679
19680 if Nkind (Entry_Decl) = N_Entry_Declaration then
19681
19682 -- Entry illegally within a task
19683
19684 if Nkind (Parent (N)) = N_Task_Definition then
19685 Error_Pragma ("pragma % cannot apply to task entries");
19686 end if;
19687
19688 Entry_Id := Defining_Entity (Entry_Decl);
19689
19690 -- Otherwise the pragma is associated with an illegal construct
19691
19692 else
19693 Error_Pragma
19694 ("pragma % must apply to a protected entry declaration");
19695 end if;
19696
19697 -- Mark the pragma as Ghost if the related subprogram is also
19698 -- Ghost. This also ensures that any expansion performed further
19699 -- below will produce Ghost nodes.
19700
19701 Mark_Ghost_Pragma (N, Entry_Id);
19702
19703 -- Analyze the Integer expression
19704
19705 Arg := Get_Pragma_Arg (Arg1);
19706 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
19707
19708 Val := Expr_Value (Arg);
19709
19710 if Val < -1 then
19711 Error_Pragma_Arg
19712 ("argument for pragma% cannot be less than -1", Arg1);
19713
19714 elsif not UI_Is_In_Int_Range (Val) then
19715 Error_Pragma_Arg
19716 ("argument for pragma% out of range of Integer", Arg1);
19717
19718 end if;
19719
19720 Record_Rep_Item (Entry_Id, N);
19721 end Max_Entry_Queue_Length;
19722
19723 -----------------
19724 -- Memory_Size --
19725 -----------------
19726
19727 -- pragma Memory_Size (NUMERIC_LITERAL)
19728
19729 when Pragma_Memory_Size =>
19730 GNAT_Pragma;
19731
19732 -- Memory size is simply ignored
19733
19734 Check_No_Identifiers;
19735 Check_Arg_Count (1);
19736 Check_Arg_Is_Integer_Literal (Arg1);
19737
19738 -------------
19739 -- No_Body --
19740 -------------
19741
19742 -- pragma No_Body;
19743
19744 -- The only correct use of this pragma is on its own in a file, in
19745 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
19746 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
19747 -- check for a file containing nothing but a No_Body pragma). If we
19748 -- attempt to process it during normal semantics processing, it means
19749 -- it was misplaced.
19750
19751 when Pragma_No_Body =>
19752 GNAT_Pragma;
19753 Pragma_Misplaced;
19754
19755 -----------------------------
19756 -- No_Elaboration_Code_All --
19757 -----------------------------
19758
19759 -- pragma No_Elaboration_Code_All;
19760
19761 when Pragma_No_Elaboration_Code_All =>
19762 GNAT_Pragma;
19763 Check_Valid_Library_Unit_Pragma;
19764
19765 -- If N was rewritten as a null statement there is nothing more
19766 -- to do.
19767
19768 if Nkind (N) = N_Null_Statement then
19769 return;
19770 end if;
19771
19772 -- Must appear for a spec or generic spec
19773
19774 if Nkind (Unit (Cunit (Current_Sem_Unit))) not in
19775 N_Generic_Package_Declaration |
19776 N_Generic_Subprogram_Declaration |
19777 N_Package_Declaration |
19778 N_Subprogram_Declaration
19779 then
19780 Error_Pragma
19781 (Fix_Error
19782 ("pragma% can only occur for package "
19783 & "or subprogram spec"));
19784 end if;
19785
19786 -- Set flag in unit table
19787
19788 Set_No_Elab_Code_All (Current_Sem_Unit);
19789
19790 -- Set restriction No_Elaboration_Code if this is the main unit
19791
19792 if Current_Sem_Unit = Main_Unit then
19793 Set_Restriction (No_Elaboration_Code, N);
19794 end if;
19795
19796 -- If we are in the main unit or in an extended main source unit,
19797 -- then we also add it to the configuration restrictions so that
19798 -- it will apply to all units in the extended main source.
19799
19800 if Current_Sem_Unit = Main_Unit
19801 or else In_Extended_Main_Source_Unit (N)
19802 then
19803 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
19804 end if;
19805
19806 -- If in main extended unit, activate transitive with test
19807
19808 if In_Extended_Main_Source_Unit (N) then
19809 Opt.No_Elab_Code_All_Pragma := N;
19810 end if;
19811
19812 -----------------------------
19813 -- No_Component_Reordering --
19814 -----------------------------
19815
19816 -- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
19817
19818 when Pragma_No_Component_Reordering => No_Comp_Reordering : declare
19819 E : Entity_Id;
19820 E_Id : Node_Id;
19821
19822 begin
19823 GNAT_Pragma;
19824 Check_At_Most_N_Arguments (1);
19825
19826 if Arg_Count = 0 then
19827 Check_Valid_Configuration_Pragma;
19828 Opt.No_Component_Reordering := True;
19829
19830 else
19831 Check_Optional_Identifier (Arg2, Name_Entity);
19832 Check_Arg_Is_Local_Name (Arg1);
19833 E_Id := Get_Pragma_Arg (Arg1);
19834
19835 if Etype (E_Id) = Any_Type then
19836 return;
19837 end if;
19838
19839 E := Entity (E_Id);
19840
19841 if not Is_Record_Type (E) then
19842 Error_Pragma_Arg ("pragma% requires record type", Arg1);
19843 end if;
19844
19845 Set_No_Reordering (Base_Type (E));
19846 end if;
19847 end No_Comp_Reordering;
19848
19849 --------------------------
19850 -- No_Heap_Finalization --
19851 --------------------------
19852
19853 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
19854
19855 when Pragma_No_Heap_Finalization => No_Heap_Finalization : declare
19856 Context : constant Node_Id := Parent (N);
19857 Typ_Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
19858 Prev : Node_Id;
19859 Typ : Entity_Id;
19860
19861 begin
19862 GNAT_Pragma;
19863 Check_No_Identifiers;
19864
19865 -- The pragma appears in a configuration file
19866
19867 if No (Context) then
19868 Check_Arg_Count (0);
19869 Check_Valid_Configuration_Pragma;
19870
19871 -- Detect a duplicate pragma
19872
19873 if Present (No_Heap_Finalization_Pragma) then
19874 Duplication_Error
19875 (Prag => N,
19876 Prev => No_Heap_Finalization_Pragma);
19877 raise Pragma_Exit;
19878 end if;
19879
19880 No_Heap_Finalization_Pragma := N;
19881
19882 -- Otherwise the pragma should be associated with a library-level
19883 -- named access-to-object type.
19884
19885 else
19886 Check_Arg_Count (1);
19887 Check_Arg_Is_Local_Name (Arg1);
19888
19889 Find_Type (Typ_Arg);
19890 Typ := Entity (Typ_Arg);
19891
19892 -- The type being subjected to the pragma is erroneous
19893
19894 if Typ = Any_Type then
19895 Error_Pragma ("cannot find type referenced by pragma %");
19896
19897 -- The pragma is applied to an incomplete or generic formal
19898 -- type way too early.
19899
19900 elsif Rep_Item_Too_Early (Typ, N) then
19901 return;
19902
19903 else
19904 Typ := Underlying_Type (Typ);
19905 end if;
19906
19907 -- The pragma must apply to an access-to-object type
19908
19909 if Ekind (Typ) in E_Access_Type | E_General_Access_Type then
19910 null;
19911
19912 -- Give a detailed error message on all other access type kinds
19913
19914 elsif Ekind (Typ) = E_Access_Protected_Subprogram_Type then
19915 Error_Pragma
19916 ("pragma % cannot apply to access protected subprogram "
19917 & "type");
19918
19919 elsif Ekind (Typ) = E_Access_Subprogram_Type then
19920 Error_Pragma
19921 ("pragma % cannot apply to access subprogram type");
19922
19923 elsif Is_Anonymous_Access_Type (Typ) then
19924 Error_Pragma
19925 ("pragma % cannot apply to anonymous access type");
19926
19927 -- Give a general error message in case the pragma applies to a
19928 -- non-access type.
19929
19930 else
19931 Error_Pragma
19932 ("pragma % must apply to library level access type");
19933 end if;
19934
19935 -- At this point the argument denotes an access-to-object type.
19936 -- Ensure that the type is declared at the library level.
19937
19938 if Is_Library_Level_Entity (Typ) then
19939 null;
19940
19941 -- Quietly ignore an access-to-object type originally declared
19942 -- at the library level within a generic, but instantiated at
19943 -- a non-library level. As a result the access-to-object type
19944 -- "loses" its No_Heap_Finalization property.
19945
19946 elsif In_Instance then
19947 raise Pragma_Exit;
19948
19949 else
19950 Error_Pragma
19951 ("pragma % must apply to library level access type");
19952 end if;
19953
19954 -- Detect a duplicate pragma
19955
19956 if Present (No_Heap_Finalization_Pragma) then
19957 Duplication_Error
19958 (Prag => N,
19959 Prev => No_Heap_Finalization_Pragma);
19960 raise Pragma_Exit;
19961
19962 else
19963 Prev := Get_Pragma (Typ, Pragma_No_Heap_Finalization);
19964
19965 if Present (Prev) then
19966 Duplication_Error
19967 (Prag => N,
19968 Prev => Prev);
19969 raise Pragma_Exit;
19970 end if;
19971 end if;
19972
19973 Record_Rep_Item (Typ, N);
19974 end if;
19975 end No_Heap_Finalization;
19976
19977 ---------------
19978 -- No_Inline --
19979 ---------------
19980
19981 -- pragma No_Inline ( NAME {, NAME} );
19982
19983 when Pragma_No_Inline =>
19984 GNAT_Pragma;
19985 Process_Inline (Suppressed);
19986
19987 ---------------
19988 -- No_Return --
19989 ---------------
19990
19991 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
19992
19993 when Pragma_No_Return => Prag_No_Return : declare
19994
19995 function Check_No_Return
19996 (E : Entity_Id;
19997 N : Node_Id) return Boolean;
19998 -- Check rule 6.5.1(4/3) of the Ada RM. If the rule is violated,
19999 -- emit an error message and return False, otherwise return True.
20000 -- 6.5.1 Nonreturning procedures:
20001 -- 4/3 "Aspect No_Return shall not be specified for a null
20002 -- procedure nor an instance of a generic unit."
20003
20004 ---------------------
20005 -- Check_No_Return --
20006 ---------------------
20007
20008 function Check_No_Return
20009 (E : Entity_Id;
20010 N : Node_Id) return Boolean
20011 is
20012 begin
20013 if Ekind (E) = E_Procedure then
20014
20015 -- If E is a generic instance, marking it with No_Return
20016 -- is forbidden, but having it inherit the No_Return of
20017 -- the generic is allowed. We check if E is inheriting its
20018 -- No_Return flag from the generic by checking if No_Return
20019 -- is already set.
20020
20021 if Is_Generic_Instance (E) and then not No_Return (E) then
20022 Error_Msg_NE
20023 ("generic instance & is marked as No_Return", N, E);
20024 Error_Msg_NE
20025 ("\generic procedure & must be marked No_Return",
20026 N,
20027 Generic_Parent (Parent (E)));
20028 return False;
20029
20030 elsif Null_Present (Subprogram_Specification (E)) then
20031 Error_Msg_NE
20032 ("null procedure & cannot be marked No_Return", N, E);
20033 return False;
20034 end if;
20035 end if;
20036
20037 return True;
20038 end Check_No_Return;
20039
20040 Arg : Node_Id;
20041 E : Entity_Id;
20042 Found : Boolean;
20043 Id : Node_Id;
20044
20045 Ghost_Error_Posted : Boolean := False;
20046 -- Flag set when an error concerning the illegal mix of Ghost and
20047 -- non-Ghost subprograms is emitted.
20048
20049 Ghost_Id : Entity_Id := Empty;
20050 -- The entity of the first Ghost procedure encountered while
20051 -- processing the arguments of the pragma.
20052
20053 begin
20054 Ada_2005_Pragma;
20055 Check_At_Least_N_Arguments (1);
20056
20057 -- Loop through arguments of pragma
20058
20059 Arg := Arg1;
20060 while Present (Arg) loop
20061 Check_Arg_Is_Local_Name (Arg);
20062 Id := Get_Pragma_Arg (Arg);
20063 Analyze (Id);
20064
20065 if not Is_Entity_Name (Id) then
20066 Error_Pragma_Arg ("entity name required", Arg);
20067 end if;
20068
20069 if Etype (Id) = Any_Type then
20070 raise Pragma_Exit;
20071 end if;
20072
20073 -- Loop to find matching procedures or functions (Ada 2022)
20074
20075 E := Entity (Id);
20076
20077 Found := False;
20078 while Present (E)
20079 and then Scope (E) = Current_Scope
20080 loop
20081 -- Ada 2022 (AI12-0269): A function can be No_Return
20082
20083 if Ekind (E) in E_Generic_Procedure | E_Procedure
20084 or else (Ada_Version >= Ada_2022
20085 and then
20086 Ekind (E) in E_Generic_Function | E_Function)
20087 then
20088 -- Check that the pragma is not applied to a body.
20089 -- First check the specless body case, to give a
20090 -- different error message. These checks do not apply
20091 -- if Relaxed_RM_Semantics, to accommodate other Ada
20092 -- compilers. Disable these checks under -gnatd.J.
20093
20094 if not Debug_Flag_Dot_JJ then
20095 if Nkind (Parent (Declaration_Node (E))) =
20096 N_Subprogram_Body
20097 and then not Relaxed_RM_Semantics
20098 then
20099 Error_Pragma
20100 ("pragma% requires separate spec and must come "
20101 & "before body");
20102 end if;
20103
20104 -- Now the "specful" body case
20105
20106 if Rep_Item_Too_Late (E, N) then
20107 raise Pragma_Exit;
20108 end if;
20109 end if;
20110
20111 if Check_No_Return (E, N) then
20112 Set_No_Return (E);
20113 end if;
20114
20115 -- A pragma that applies to a Ghost entity becomes Ghost
20116 -- for the purposes of legality checks and removal of
20117 -- ignored Ghost code.
20118
20119 Mark_Ghost_Pragma (N, E);
20120
20121 -- Capture the entity of the first Ghost procedure being
20122 -- processed for error detection purposes.
20123
20124 if Is_Ghost_Entity (E) then
20125 if No (Ghost_Id) then
20126 Ghost_Id := E;
20127 end if;
20128
20129 -- Otherwise the subprogram is non-Ghost. It is illegal
20130 -- to mix references to Ghost and non-Ghost entities
20131 -- (SPARK RM 6.9).
20132
20133 elsif Present (Ghost_Id)
20134 and then not Ghost_Error_Posted
20135 then
20136 Ghost_Error_Posted := True;
20137
20138 Error_Msg_Name_1 := Pname;
20139 Error_Msg_N
20140 ("pragma % cannot mention ghost and non-ghost "
20141 & "procedures", N);
20142
20143 Error_Msg_Sloc := Sloc (Ghost_Id);
20144 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
20145
20146 Error_Msg_Sloc := Sloc (E);
20147 Error_Msg_NE ("\& # declared as non-ghost", N, E);
20148 end if;
20149
20150 -- Set flag on any alias as well
20151
20152 if Is_Overloadable (E)
20153 and then Present (Alias (E))
20154 and then Check_No_Return (Alias (E), N)
20155 then
20156 Set_No_Return (Alias (E));
20157 end if;
20158
20159 Found := True;
20160 end if;
20161
20162 exit when From_Aspect_Specification (N);
20163 E := Homonym (E);
20164 end loop;
20165
20166 -- If entity in not in current scope it may be the enclosing
20167 -- subprogram body to which the aspect applies.
20168
20169 if not Found then
20170 if Entity (Id) = Current_Scope
20171 and then From_Aspect_Specification (N)
20172 and then Check_No_Return (Entity (Id), N)
20173 then
20174 Set_No_Return (Entity (Id));
20175
20176 elsif Ada_Version >= Ada_2022 then
20177 Error_Pragma_Arg
20178 ("no subprogram& found for pragma%", Arg);
20179
20180 else
20181 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
20182 end if;
20183 end if;
20184
20185 Next (Arg);
20186 end loop;
20187 end Prag_No_Return;
20188
20189 -----------------
20190 -- No_Run_Time --
20191 -----------------
20192
20193 -- pragma No_Run_Time;
20194
20195 -- Note: this pragma is retained for backwards compatibility. See
20196 -- body of Rtsfind for full details on its handling.
20197
20198 when Pragma_No_Run_Time =>
20199 GNAT_Pragma;
20200 Check_Valid_Configuration_Pragma;
20201 Check_Arg_Count (0);
20202
20203 -- Remove backward compatibility if Build_Type is FSF or GPL and
20204 -- generate a warning.
20205
20206 declare
20207 Ignore : constant Boolean := Build_Type in FSF .. GPL;
20208 begin
20209 if Ignore then
20210 Error_Pragma ("pragma% is ignored, has no effect??");
20211 else
20212 No_Run_Time_Mode := True;
20213 Configurable_Run_Time_Mode := True;
20214
20215 -- Set Duration to 32 bits if word size is 32
20216
20217 if Ttypes.System_Word_Size = 32 then
20218 Duration_32_Bits_On_Target := True;
20219 end if;
20220
20221 -- Set appropriate restrictions
20222
20223 Set_Restriction (No_Finalization, N);
20224 Set_Restriction (No_Exception_Handlers, N);
20225 Set_Restriction (Max_Tasks, N, 0);
20226 Set_Restriction (No_Tasking, N);
20227 end if;
20228 end;
20229
20230 -----------------------
20231 -- No_Tagged_Streams --
20232 -----------------------
20233
20234 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
20235
20236 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
20237 E : Entity_Id;
20238 E_Id : Node_Id;
20239
20240 begin
20241 GNAT_Pragma;
20242 Check_At_Most_N_Arguments (1);
20243
20244 -- One argument case
20245
20246 if Arg_Count = 1 then
20247 Check_Optional_Identifier (Arg1, Name_Entity);
20248 Check_Arg_Is_Local_Name (Arg1);
20249 E_Id := Get_Pragma_Arg (Arg1);
20250
20251 if Etype (E_Id) = Any_Type then
20252 return;
20253 end if;
20254
20255 E := Entity (E_Id);
20256
20257 Check_Duplicate_Pragma (E);
20258
20259 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
20260 Error_Pragma_Arg
20261 ("argument for pragma% must be root tagged type", Arg1);
20262 end if;
20263
20264 if Rep_Item_Too_Early (E, N)
20265 or else
20266 Rep_Item_Too_Late (E, N)
20267 then
20268 return;
20269 else
20270 Set_No_Tagged_Streams_Pragma (E, N);
20271 end if;
20272
20273 -- Zero argument case
20274
20275 else
20276 Check_Is_In_Decl_Part_Or_Package_Spec;
20277 No_Tagged_Streams := N;
20278 end if;
20279 end No_Tagged_Strms;
20280
20281 ------------------------
20282 -- No_Strict_Aliasing --
20283 ------------------------
20284
20285 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
20286
20287 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
20288 E : Entity_Id;
20289 E_Id : Node_Id;
20290
20291 begin
20292 GNAT_Pragma;
20293 Check_At_Most_N_Arguments (1);
20294
20295 if Arg_Count = 0 then
20296 Check_Valid_Configuration_Pragma;
20297 Opt.No_Strict_Aliasing := True;
20298
20299 else
20300 Check_Optional_Identifier (Arg2, Name_Entity);
20301 Check_Arg_Is_Local_Name (Arg1);
20302 E_Id := Get_Pragma_Arg (Arg1);
20303
20304 if Etype (E_Id) = Any_Type then
20305 return;
20306 end if;
20307
20308 E := Entity (E_Id);
20309
20310 if not Is_Access_Type (E) then
20311 Error_Pragma_Arg ("pragma% requires access type", Arg1);
20312 end if;
20313
20314 Set_No_Strict_Aliasing (Base_Type (E));
20315 end if;
20316 end No_Strict_Aliasing;
20317
20318 -----------------------
20319 -- Normalize_Scalars --
20320 -----------------------
20321
20322 -- pragma Normalize_Scalars;
20323
20324 when Pragma_Normalize_Scalars =>
20325 Check_Ada_83_Warning;
20326 Check_Arg_Count (0);
20327 Check_Valid_Configuration_Pragma;
20328
20329 -- Normalize_Scalars creates false positives in CodePeer, and
20330 -- incorrect negative results in GNATprove mode, so ignore this
20331 -- pragma in these modes.
20332
20333 if not (CodePeer_Mode or GNATprove_Mode) then
20334 Normalize_Scalars := True;
20335 Init_Or_Norm_Scalars := True;
20336 end if;
20337
20338 -----------------
20339 -- Obsolescent --
20340 -----------------
20341
20342 -- pragma Obsolescent;
20343
20344 -- pragma Obsolescent (
20345 -- [Message =>] static_string_EXPRESSION
20346 -- [,[Version =>] Ada_05]);
20347
20348 -- pragma Obsolescent (
20349 -- [Entity =>] NAME
20350 -- [,[Message =>] static_string_EXPRESSION
20351 -- [,[Version =>] Ada_05]]);
20352
20353 when Pragma_Obsolescent => Obsolescent : declare
20354 Decl : Node_Id;
20355 Ename : Node_Id;
20356
20357 procedure Set_Obsolescent (E : Entity_Id);
20358 -- Given an entity Ent, mark it as obsolescent if appropriate
20359
20360 ---------------------
20361 -- Set_Obsolescent --
20362 ---------------------
20363
20364 procedure Set_Obsolescent (E : Entity_Id) is
20365 Active : Boolean;
20366 Ent : Entity_Id;
20367 S : String_Id;
20368
20369 begin
20370 Active := True;
20371 Ent := E;
20372
20373 -- A pragma that applies to a Ghost entity becomes Ghost for
20374 -- the purposes of legality checks and removal of ignored Ghost
20375 -- code.
20376
20377 Mark_Ghost_Pragma (N, E);
20378
20379 -- Entity name was given
20380
20381 if Present (Ename) then
20382
20383 -- If entity name matches, we are fine.
20384
20385 if Chars (Ename) = Chars (Ent) then
20386 Set_Entity (Ename, Ent);
20387 Generate_Reference (Ent, Ename);
20388
20389 -- If entity name does not match, only possibility is an
20390 -- enumeration literal from an enumeration type declaration.
20391
20392 elsif Ekind (Ent) /= E_Enumeration_Type then
20393 Error_Pragma
20394 ("pragma % entity name does not match declaration");
20395
20396 else
20397 Ent := First_Literal (E);
20398 loop
20399 if No (Ent) then
20400 Error_Pragma
20401 ("pragma % entity name does not match any "
20402 & "enumeration literal");
20403
20404 elsif Chars (Ent) = Chars (Ename) then
20405 Set_Entity (Ename, Ent);
20406 Generate_Reference (Ent, Ename);
20407 exit;
20408
20409 else
20410 Next_Literal (Ent);
20411 end if;
20412 end loop;
20413 end if;
20414 end if;
20415
20416 -- Ent points to entity to be marked
20417
20418 if Arg_Count >= 1 then
20419
20420 -- Deal with static string argument
20421
20422 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
20423 S := Strval (Get_Pragma_Arg (Arg1));
20424
20425 for J in 1 .. String_Length (S) loop
20426 if not In_Character_Range (Get_String_Char (S, J)) then
20427 Error_Pragma_Arg
20428 ("pragma% argument does not allow wide characters",
20429 Arg1);
20430 end if;
20431 end loop;
20432
20433 Obsolescent_Warnings.Append
20434 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
20435
20436 -- Check for Ada_05 parameter
20437
20438 if Arg_Count /= 1 then
20439 Check_Arg_Count (2);
20440
20441 declare
20442 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
20443
20444 begin
20445 Check_Arg_Is_Identifier (Argx);
20446
20447 if Chars (Argx) /= Name_Ada_05 then
20448 Error_Msg_Name_2 := Name_Ada_05;
20449 Error_Pragma_Arg
20450 ("only allowed argument for pragma% is %", Argx);
20451 end if;
20452
20453 if Ada_Version_Explicit < Ada_2005
20454 or else not Warn_On_Ada_2005_Compatibility
20455 then
20456 Active := False;
20457 end if;
20458 end;
20459 end if;
20460 end if;
20461
20462 -- Set flag if pragma active
20463
20464 if Active then
20465 Set_Is_Obsolescent (Ent);
20466 end if;
20467
20468 return;
20469 end Set_Obsolescent;
20470
20471 -- Start of processing for pragma Obsolescent
20472
20473 begin
20474 GNAT_Pragma;
20475
20476 Check_At_Most_N_Arguments (3);
20477
20478 -- See if first argument specifies an entity name
20479
20480 if Arg_Count >= 1
20481 and then
20482 (Chars (Arg1) = Name_Entity
20483 or else
20484 Nkind (Get_Pragma_Arg (Arg1)) in
20485 N_Character_Literal | N_Identifier | N_Operator_Symbol)
20486 then
20487 Ename := Get_Pragma_Arg (Arg1);
20488
20489 -- Eliminate first argument, so we can share processing
20490
20491 Arg1 := Arg2;
20492 Arg2 := Arg3;
20493 Arg_Count := Arg_Count - 1;
20494
20495 -- No Entity name argument given
20496
20497 else
20498 Ename := Empty;
20499 end if;
20500
20501 if Arg_Count >= 1 then
20502 Check_Optional_Identifier (Arg1, Name_Message);
20503
20504 if Arg_Count = 2 then
20505 Check_Optional_Identifier (Arg2, Name_Version);
20506 end if;
20507 end if;
20508
20509 -- Get immediately preceding declaration
20510
20511 Decl := Prev (N);
20512 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
20513 Prev (Decl);
20514 end loop;
20515
20516 -- Cases where we do not follow anything other than another pragma
20517
20518 if No (Decl) then
20519
20520 -- Case 0: library level compilation unit declaration with
20521 -- the pragma preceding the declaration.
20522
20523 if Nkind (Parent (N)) = N_Compilation_Unit then
20524 Pragma_Misplaced;
20525
20526 -- Case 1: library level compilation unit declaration with
20527 -- the pragma immediately following the declaration.
20528
20529 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
20530 Set_Obsolescent
20531 (Defining_Entity (Unit (Parent (Parent (N)))));
20532 return;
20533
20534 -- Case 2: library unit placement for package
20535
20536 else
20537 declare
20538 Ent : constant Entity_Id := Find_Lib_Unit_Name;
20539 begin
20540 if Is_Package_Or_Generic_Package (Ent) then
20541 Set_Obsolescent (Ent);
20542 return;
20543 end if;
20544 end;
20545 end if;
20546
20547 -- Cases where we must follow a declaration, including an
20548 -- abstract subprogram declaration, which is not in the
20549 -- other node subtypes.
20550
20551 else
20552 if Nkind (Decl) not in N_Declaration
20553 and then Nkind (Decl) not in N_Later_Decl_Item
20554 and then Nkind (Decl) not in N_Generic_Declaration
20555 and then Nkind (Decl) not in N_Renaming_Declaration
20556 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
20557 then
20558 Error_Pragma
20559 ("pragma% misplaced, "
20560 & "must immediately follow a declaration");
20561
20562 else
20563 Set_Obsolescent (Defining_Entity (Decl));
20564 return;
20565 end if;
20566 end if;
20567 end Obsolescent;
20568
20569 --------------
20570 -- Optimize --
20571 --------------
20572
20573 -- pragma Optimize (Time | Space | Off);
20574
20575 -- The actual check for optimize is done in Gigi. Note that this
20576 -- pragma does not actually change the optimization setting, it
20577 -- simply checks that it is consistent with the pragma.
20578
20579 when Pragma_Optimize =>
20580 Check_No_Identifiers;
20581 Check_Arg_Count (1);
20582 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
20583
20584 ------------------------
20585 -- Optimize_Alignment --
20586 ------------------------
20587
20588 -- pragma Optimize_Alignment (Time | Space | Off);
20589
20590 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
20591 GNAT_Pragma;
20592 Check_No_Identifiers;
20593 Check_Arg_Count (1);
20594 Check_Valid_Configuration_Pragma;
20595
20596 declare
20597 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
20598 begin
20599 case Nam is
20600 when Name_Off => Opt.Optimize_Alignment := 'O';
20601 when Name_Space => Opt.Optimize_Alignment := 'S';
20602 when Name_Time => Opt.Optimize_Alignment := 'T';
20603
20604 when others =>
20605 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
20606 end case;
20607 end;
20608
20609 -- Set indication that mode is set locally. If we are in fact in a
20610 -- configuration pragma file, this setting is harmless since the
20611 -- switch will get reset anyway at the start of each unit.
20612
20613 Optimize_Alignment_Local := True;
20614 end Optimize_Alignment;
20615
20616 -------------
20617 -- Ordered --
20618 -------------
20619
20620 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
20621
20622 when Pragma_Ordered => Ordered : declare
20623 Assoc : constant Node_Id := Arg1;
20624 Type_Id : Node_Id;
20625 Typ : Entity_Id;
20626
20627 begin
20628 GNAT_Pragma;
20629 Check_No_Identifiers;
20630 Check_Arg_Count (1);
20631 Check_Arg_Is_Local_Name (Arg1);
20632
20633 Type_Id := Get_Pragma_Arg (Assoc);
20634 Find_Type (Type_Id);
20635 Typ := Entity (Type_Id);
20636
20637 if Typ = Any_Type then
20638 return;
20639 else
20640 Typ := Underlying_Type (Typ);
20641 end if;
20642
20643 if not Is_Enumeration_Type (Typ) then
20644 Error_Pragma ("pragma% must specify enumeration type");
20645 end if;
20646
20647 Check_First_Subtype (Arg1);
20648 Set_Has_Pragma_Ordered (Base_Type (Typ));
20649 end Ordered;
20650
20651 -------------------
20652 -- Overflow_Mode --
20653 -------------------
20654
20655 -- pragma Overflow_Mode
20656 -- ([General => ] MODE [, [Assertions => ] MODE]);
20657
20658 -- MODE := STRICT | MINIMIZED | ELIMINATED
20659
20660 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
20661 -- since System.Bignums makes this assumption. This is true of nearly
20662 -- all (all?) targets.
20663
20664 when Pragma_Overflow_Mode => Overflow_Mode : declare
20665 function Get_Overflow_Mode
20666 (Name : Name_Id;
20667 Arg : Node_Id) return Overflow_Mode_Type;
20668 -- Function to process one pragma argument, Arg. If an identifier
20669 -- is present, it must be Name. Mode type is returned if a valid
20670 -- argument exists, otherwise an error is signalled.
20671
20672 -----------------------
20673 -- Get_Overflow_Mode --
20674 -----------------------
20675
20676 function Get_Overflow_Mode
20677 (Name : Name_Id;
20678 Arg : Node_Id) return Overflow_Mode_Type
20679 is
20680 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
20681
20682 begin
20683 Check_Optional_Identifier (Arg, Name);
20684 Check_Arg_Is_Identifier (Argx);
20685
20686 if Chars (Argx) = Name_Strict then
20687 return Strict;
20688
20689 elsif Chars (Argx) = Name_Minimized then
20690 return Minimized;
20691
20692 elsif Chars (Argx) = Name_Eliminated then
20693 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
20694 Error_Pragma_Arg
20695 ("Eliminated requires Long_Long_Integer'Size = 64",
20696 Argx);
20697 else
20698 return Eliminated;
20699 end if;
20700
20701 else
20702 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
20703 end if;
20704 end Get_Overflow_Mode;
20705
20706 -- Start of processing for Overflow_Mode
20707
20708 begin
20709 GNAT_Pragma;
20710 Check_At_Least_N_Arguments (1);
20711 Check_At_Most_N_Arguments (2);
20712
20713 -- Process first argument
20714
20715 Scope_Suppress.Overflow_Mode_General :=
20716 Get_Overflow_Mode (Name_General, Arg1);
20717
20718 -- Case of only one argument
20719
20720 if Arg_Count = 1 then
20721 Scope_Suppress.Overflow_Mode_Assertions :=
20722 Scope_Suppress.Overflow_Mode_General;
20723
20724 -- Case of two arguments present
20725
20726 else
20727 Scope_Suppress.Overflow_Mode_Assertions :=
20728 Get_Overflow_Mode (Name_Assertions, Arg2);
20729 end if;
20730 end Overflow_Mode;
20731
20732 --------------------------
20733 -- Overriding Renamings --
20734 --------------------------
20735
20736 -- pragma Overriding_Renamings;
20737
20738 when Pragma_Overriding_Renamings =>
20739 GNAT_Pragma;
20740 Check_Arg_Count (0);
20741 Check_Valid_Configuration_Pragma;
20742 Overriding_Renamings := True;
20743
20744 ----------
20745 -- Pack --
20746 ----------
20747
20748 -- pragma Pack (first_subtype_LOCAL_NAME);
20749
20750 when Pragma_Pack => Pack : declare
20751 Assoc : constant Node_Id := Arg1;
20752 Ctyp : Entity_Id;
20753 Ignore : Boolean := False;
20754 Typ : Entity_Id;
20755 Type_Id : Node_Id;
20756
20757 begin
20758 Check_No_Identifiers;
20759 Check_Arg_Count (1);
20760 Check_Arg_Is_Local_Name (Arg1);
20761 Type_Id := Get_Pragma_Arg (Assoc);
20762
20763 if not Is_Entity_Name (Type_Id)
20764 or else not Is_Type (Entity (Type_Id))
20765 then
20766 Error_Pragma_Arg
20767 ("argument for pragma% must be type or subtype", Arg1);
20768 end if;
20769
20770 Find_Type (Type_Id);
20771 Typ := Entity (Type_Id);
20772
20773 if Typ = Any_Type
20774 or else Rep_Item_Too_Early (Typ, N)
20775 then
20776 return;
20777 else
20778 Typ := Underlying_Type (Typ);
20779 end if;
20780
20781 -- A pragma that applies to a Ghost entity becomes Ghost for the
20782 -- purposes of legality checks and removal of ignored Ghost code.
20783
20784 Mark_Ghost_Pragma (N, Typ);
20785
20786 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
20787 Error_Pragma ("pragma% must specify array or record type");
20788 end if;
20789
20790 Check_First_Subtype (Arg1);
20791 Check_Duplicate_Pragma (Typ);
20792
20793 -- Array type
20794
20795 if Is_Array_Type (Typ) then
20796 Ctyp := Component_Type (Typ);
20797
20798 -- Ignore pack that does nothing
20799
20800 if Known_Static_Esize (Ctyp)
20801 and then Known_Static_RM_Size (Ctyp)
20802 and then Esize (Ctyp) = RM_Size (Ctyp)
20803 and then Addressable (Esize (Ctyp))
20804 then
20805 Ignore := True;
20806 end if;
20807
20808 -- Process OK pragma Pack. Note that if there is a separate
20809 -- component clause present, the Pack will be cancelled. This
20810 -- processing is in Freeze.
20811
20812 if not Rep_Item_Too_Late (Typ, N) then
20813
20814 -- In CodePeer mode, we do not need complex front-end
20815 -- expansions related to pragma Pack, so disable handling
20816 -- of pragma Pack.
20817
20818 if CodePeer_Mode then
20819 null;
20820
20821 -- Normal case where we do the pack action
20822
20823 else
20824 if not Ignore then
20825 Set_Is_Packed (Base_Type (Typ));
20826 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20827 end if;
20828
20829 Set_Has_Pragma_Pack (Base_Type (Typ));
20830 end if;
20831 end if;
20832
20833 -- For record types, the pack is always effective
20834
20835 else pragma Assert (Is_Record_Type (Typ));
20836 if not Rep_Item_Too_Late (Typ, N) then
20837 Set_Is_Packed (Base_Type (Typ));
20838 Set_Has_Pragma_Pack (Base_Type (Typ));
20839 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20840 end if;
20841 end if;
20842 end Pack;
20843
20844 ----------
20845 -- Page --
20846 ----------
20847
20848 -- pragma Page;
20849
20850 -- There is nothing to do here, since we did all the processing for
20851 -- this pragma in Par.Prag (so that it works properly even in syntax
20852 -- only mode).
20853
20854 when Pragma_Page =>
20855 null;
20856
20857 -------------
20858 -- Part_Of --
20859 -------------
20860
20861 -- pragma Part_Of (ABSTRACT_STATE);
20862
20863 -- ABSTRACT_STATE ::= NAME
20864
20865 when Pragma_Part_Of => Part_Of : declare
20866 procedure Propagate_Part_Of
20867 (Pack_Id : Entity_Id;
20868 State_Id : Entity_Id;
20869 Instance : Node_Id);
20870 -- Propagate the Part_Of indicator to all abstract states and
20871 -- objects declared in the visible state space of a package
20872 -- denoted by Pack_Id. State_Id is the encapsulating state.
20873 -- Instance is the package instantiation node.
20874
20875 -----------------------
20876 -- Propagate_Part_Of --
20877 -----------------------
20878
20879 procedure Propagate_Part_Of
20880 (Pack_Id : Entity_Id;
20881 State_Id : Entity_Id;
20882 Instance : Node_Id)
20883 is
20884 Has_Item : Boolean := False;
20885 -- Flag set when the visible state space contains at least one
20886 -- abstract state or variable.
20887
20888 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
20889 -- Propagate the Part_Of indicator to all abstract states and
20890 -- objects declared in the visible state space of a package
20891 -- denoted by Pack_Id.
20892
20893 -----------------------
20894 -- Propagate_Part_Of --
20895 -----------------------
20896
20897 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
20898 Constits : Elist_Id;
20899 Item_Id : Entity_Id;
20900
20901 begin
20902 -- Traverse the entity chain of the package and set relevant
20903 -- attributes of abstract states and objects declared in the
20904 -- visible state space of the package.
20905
20906 Item_Id := First_Entity (Pack_Id);
20907 while Present (Item_Id)
20908 and then not In_Private_Part (Item_Id)
20909 loop
20910 -- Do not consider internally generated items
20911
20912 if not Comes_From_Source (Item_Id) then
20913 null;
20914
20915 -- Do not consider generic formals or their corresponding
20916 -- actuals because they are not part of a visible state.
20917 -- Note that both entities are marked as hidden.
20918
20919 elsif Is_Hidden (Item_Id) then
20920 null;
20921
20922 -- The Part_Of indicator turns an abstract state or an
20923 -- object into a constituent of the encapsulating state.
20924 -- Note that constants are considered here even though
20925 -- they may not depend on variable input. This check is
20926 -- left to the SPARK prover.
20927
20928 elsif Ekind (Item_Id) in
20929 E_Abstract_State | E_Constant | E_Variable
20930 then
20931 Has_Item := True;
20932 Constits := Part_Of_Constituents (State_Id);
20933
20934 if No (Constits) then
20935 Constits := New_Elmt_List;
20936 Set_Part_Of_Constituents (State_Id, Constits);
20937 end if;
20938
20939 Append_Elmt (Item_Id, Constits);
20940 Set_Encapsulating_State (Item_Id, State_Id);
20941
20942 -- Recursively handle nested packages and instantiations
20943
20944 elsif Ekind (Item_Id) = E_Package then
20945 Propagate_Part_Of (Item_Id);
20946 end if;
20947
20948 Next_Entity (Item_Id);
20949 end loop;
20950 end Propagate_Part_Of;
20951
20952 -- Start of processing for Propagate_Part_Of
20953
20954 begin
20955 Propagate_Part_Of (Pack_Id);
20956
20957 -- Detect a package instantiation that is subject to a Part_Of
20958 -- indicator, but has no visible state.
20959
20960 if not Has_Item then
20961 SPARK_Msg_NE
20962 ("package instantiation & has Part_Of indicator but "
20963 & "lacks visible state", Instance, Pack_Id);
20964 end if;
20965 end Propagate_Part_Of;
20966
20967 -- Local variables
20968
20969 Constits : Elist_Id;
20970 Encap : Node_Id;
20971 Encap_Id : Entity_Id;
20972 Item_Id : Entity_Id;
20973 Legal : Boolean;
20974 Stmt : Node_Id;
20975
20976 -- Start of processing for Part_Of
20977
20978 begin
20979 GNAT_Pragma;
20980 Check_No_Identifiers;
20981 Check_Arg_Count (1);
20982
20983 Stmt := Find_Related_Context (N, Do_Checks => True);
20984
20985 -- Object declaration
20986
20987 if Nkind (Stmt) = N_Object_Declaration then
20988 null;
20989
20990 -- Package instantiation
20991
20992 elsif Nkind (Stmt) = N_Package_Instantiation then
20993 null;
20994
20995 -- Single concurrent type declaration
20996
20997 elsif Is_Single_Concurrent_Type_Declaration (Stmt) then
20998 null;
20999
21000 -- Otherwise the pragma is associated with an illegal construct
21001
21002 else
21003 Pragma_Misplaced;
21004 end if;
21005
21006 -- Extract the entity of the related object declaration or package
21007 -- instantiation. In the case of the instantiation, use the entity
21008 -- of the instance spec.
21009
21010 if Nkind (Stmt) = N_Package_Instantiation then
21011 Stmt := Instance_Spec (Stmt);
21012 end if;
21013
21014 Item_Id := Defining_Entity (Stmt);
21015
21016 -- A pragma that applies to a Ghost entity becomes Ghost for the
21017 -- purposes of legality checks and removal of ignored Ghost code.
21018
21019 Mark_Ghost_Pragma (N, Item_Id);
21020
21021 -- Chain the pragma on the contract for further processing by
21022 -- Analyze_Part_Of_In_Decl_Part or for completeness.
21023
21024 Add_Contract_Item (N, Item_Id);
21025
21026 -- A variable may act as constituent of a single concurrent type
21027 -- which in turn could be declared after the variable. Due to this
21028 -- discrepancy, the full analysis of indicator Part_Of is delayed
21029 -- until the end of the enclosing declarative region (see routine
21030 -- Analyze_Part_Of_In_Decl_Part).
21031
21032 if Ekind (Item_Id) = E_Variable then
21033 null;
21034
21035 -- Otherwise indicator Part_Of applies to a constant or a package
21036 -- instantiation.
21037
21038 else
21039 Encap := Get_Pragma_Arg (Arg1);
21040
21041 -- Detect any discrepancies between the placement of the
21042 -- constant or package instantiation with respect to state
21043 -- space and the encapsulating state.
21044
21045 Analyze_Part_Of
21046 (Indic => N,
21047 Item_Id => Item_Id,
21048 Encap => Encap,
21049 Encap_Id => Encap_Id,
21050 Legal => Legal);
21051
21052 if Legal then
21053 pragma Assert (Present (Encap_Id));
21054
21055 if Ekind (Item_Id) = E_Constant then
21056 Constits := Part_Of_Constituents (Encap_Id);
21057
21058 if No (Constits) then
21059 Constits := New_Elmt_List;
21060 Set_Part_Of_Constituents (Encap_Id, Constits);
21061 end if;
21062
21063 Append_Elmt (Item_Id, Constits);
21064 Set_Encapsulating_State (Item_Id, Encap_Id);
21065
21066 -- Propagate the Part_Of indicator to the visible state
21067 -- space of the package instantiation.
21068
21069 else
21070 Propagate_Part_Of
21071 (Pack_Id => Item_Id,
21072 State_Id => Encap_Id,
21073 Instance => Stmt);
21074 end if;
21075 end if;
21076 end if;
21077 end Part_Of;
21078
21079 ----------------------------------
21080 -- Partition_Elaboration_Policy --
21081 ----------------------------------
21082
21083 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
21084
21085 when Pragma_Partition_Elaboration_Policy => PEP : declare
21086 subtype PEP_Range is Name_Id
21087 range First_Partition_Elaboration_Policy_Name
21088 .. Last_Partition_Elaboration_Policy_Name;
21089 PEP_Val : PEP_Range;
21090 PEP : Character;
21091
21092 begin
21093 Ada_2005_Pragma;
21094 Check_Arg_Count (1);
21095 Check_No_Identifiers;
21096 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
21097 Check_Valid_Configuration_Pragma;
21098 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
21099
21100 case PEP_Val is
21101 when Name_Concurrent => PEP := 'C';
21102 when Name_Sequential => PEP := 'S';
21103 end case;
21104
21105 if Partition_Elaboration_Policy /= ' '
21106 and then Partition_Elaboration_Policy /= PEP
21107 then
21108 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
21109 Error_Pragma
21110 ("partition elaboration policy incompatible with policy#");
21111
21112 -- Set new policy, but always preserve System_Location since we
21113 -- like the error message with the run time name.
21114
21115 else
21116 Partition_Elaboration_Policy := PEP;
21117
21118 if Partition_Elaboration_Policy_Sloc /= System_Location then
21119 Partition_Elaboration_Policy_Sloc := Loc;
21120 end if;
21121
21122 if PEP_Val = Name_Sequential
21123 and then not Restriction_Active (No_Task_Hierarchy)
21124 then
21125 -- RM H.6(6) guarantees that No_Task_Hierarchy will be
21126 -- set eventually, so take advantage of that knowledge now.
21127 -- But we have to do this in a tricky way. If we simply
21128 -- set the No_Task_Hierarchy restriction here, then the
21129 -- assumption that the restriction will be set eventually
21130 -- becomes a self-fulfilling prophecy; the binder can
21131 -- then mistakenly conclude that the H.6(6) rule is
21132 -- satisified in cases where the post-compilation check
21133 -- should fail. So we invent a new restriction,
21134 -- No_Task_Hierarchy_Implicit, which is treated specially
21135 -- in the function Restriction_Active.
21136
21137 Set_Restriction (No_Task_Hierarchy_Implicit, N);
21138 pragma Assert (Restriction_Active (No_Task_Hierarchy));
21139 end if;
21140 end if;
21141 end PEP;
21142
21143 -------------
21144 -- Passive --
21145 -------------
21146
21147 -- pragma Passive [(PASSIVE_FORM)];
21148
21149 -- PASSIVE_FORM ::= Semaphore | No
21150
21151 when Pragma_Passive =>
21152 GNAT_Pragma;
21153
21154 if Nkind (Parent (N)) /= N_Task_Definition then
21155 Error_Pragma ("pragma% must be within task definition");
21156 end if;
21157
21158 if Arg_Count /= 0 then
21159 Check_Arg_Count (1);
21160 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
21161 end if;
21162
21163 ----------------------------------
21164 -- Preelaborable_Initialization --
21165 ----------------------------------
21166
21167 -- pragma Preelaborable_Initialization (DIRECT_NAME);
21168
21169 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
21170 Ent : Entity_Id;
21171
21172 begin
21173 Ada_2005_Pragma;
21174 Check_Arg_Count (1);
21175 Check_No_Identifiers;
21176 Check_Arg_Is_Identifier (Arg1);
21177 Check_Arg_Is_Local_Name (Arg1);
21178 Check_First_Subtype (Arg1);
21179 Ent := Entity (Get_Pragma_Arg (Arg1));
21180
21181 -- A pragma that applies to a Ghost entity becomes Ghost for the
21182 -- purposes of legality checks and removal of ignored Ghost code.
21183
21184 Mark_Ghost_Pragma (N, Ent);
21185
21186 -- The pragma may come from an aspect on a private declaration,
21187 -- even if the freeze point at which this is analyzed in the
21188 -- private part after the full view.
21189
21190 if Has_Private_Declaration (Ent)
21191 and then From_Aspect_Specification (N)
21192 then
21193 null;
21194
21195 -- Check appropriate type argument
21196
21197 elsif Is_Private_Type (Ent)
21198 or else Is_Protected_Type (Ent)
21199 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
21200
21201 -- AI05-0028: The pragma applies to all composite types. Note
21202 -- that we apply this binding interpretation to earlier versions
21203 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
21204 -- choice since there are other compilers that do the same.
21205
21206 or else Is_Composite_Type (Ent)
21207 then
21208 null;
21209
21210 else
21211 Error_Pragma_Arg
21212 ("pragma % can only be applied to private, formal derived, "
21213 & "protected, or composite type", Arg1);
21214 end if;
21215
21216 -- Give an error if the pragma is applied to a protected type that
21217 -- does not qualify (due to having entries, or due to components
21218 -- that do not qualify).
21219
21220 if Is_Protected_Type (Ent)
21221 and then not Has_Preelaborable_Initialization (Ent)
21222 then
21223 Error_Msg_N
21224 ("protected type & does not have preelaborable "
21225 & "initialization", Ent);
21226
21227 -- Otherwise mark the type as definitely having preelaborable
21228 -- initialization.
21229
21230 else
21231 Set_Known_To_Have_Preelab_Init (Ent);
21232 end if;
21233
21234 if Has_Pragma_Preelab_Init (Ent)
21235 and then Warn_On_Redundant_Constructs
21236 then
21237 Error_Pragma ("?r?duplicate pragma%!");
21238 else
21239 Set_Has_Pragma_Preelab_Init (Ent);
21240 end if;
21241 end Preelab_Init;
21242
21243 --------------------
21244 -- Persistent_BSS --
21245 --------------------
21246
21247 -- pragma Persistent_BSS [(object_NAME)];
21248
21249 when Pragma_Persistent_BSS => Persistent_BSS : declare
21250 Decl : Node_Id;
21251 Ent : Entity_Id;
21252 Prag : Node_Id;
21253
21254 begin
21255 GNAT_Pragma;
21256 Check_At_Most_N_Arguments (1);
21257
21258 -- Case of application to specific object (one argument)
21259
21260 if Arg_Count = 1 then
21261 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21262
21263 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
21264 or else
21265 Ekind (Entity (Get_Pragma_Arg (Arg1))) not in
21266 E_Variable | E_Constant
21267 then
21268 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
21269 end if;
21270
21271 Ent := Entity (Get_Pragma_Arg (Arg1));
21272
21273 -- A pragma that applies to a Ghost entity becomes Ghost for
21274 -- the purposes of legality checks and removal of ignored Ghost
21275 -- code.
21276
21277 Mark_Ghost_Pragma (N, Ent);
21278
21279 -- Check for duplication before inserting in list of
21280 -- representation items.
21281
21282 Check_Duplicate_Pragma (Ent);
21283
21284 if Rep_Item_Too_Late (Ent, N) then
21285 return;
21286 end if;
21287
21288 Decl := Parent (Ent);
21289
21290 if Present (Expression (Decl)) then
21291 -- Variables in Persistent_BSS cannot be initialized, so
21292 -- turn off any initialization that might be caused by
21293 -- pragmas Initialize_Scalars or Normalize_Scalars.
21294
21295 if Kill_Range_Check (Expression (Decl)) then
21296 Prag :=
21297 Make_Pragma (Loc,
21298 Name_Suppress_Initialization,
21299 Pragma_Argument_Associations => New_List (
21300 Make_Pragma_Argument_Association (Loc,
21301 Expression => New_Occurrence_Of (Ent, Loc))));
21302 Insert_Before (N, Prag);
21303 Analyze (Prag);
21304
21305 else
21306 Error_Pragma_Arg
21307 ("object for pragma% cannot have initialization", Arg1);
21308 end if;
21309 end if;
21310
21311 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
21312 Error_Pragma_Arg
21313 ("object type for pragma% is not potentially persistent",
21314 Arg1);
21315 end if;
21316
21317 Prag :=
21318 Make_Linker_Section_Pragma
21319 (Ent, Loc, ".persistent.bss");
21320 Insert_After (N, Prag);
21321 Analyze (Prag);
21322
21323 -- Case of use as configuration pragma with no arguments
21324
21325 else
21326 Check_Valid_Configuration_Pragma;
21327 Persistent_BSS_Mode := True;
21328 end if;
21329 end Persistent_BSS;
21330
21331 --------------------
21332 -- Rename_Pragma --
21333 --------------------
21334
21335 -- pragma Rename_Pragma (
21336 -- [New_Name =>] IDENTIFIER,
21337 -- [Renamed =>] pragma_IDENTIFIER);
21338
21339 when Pragma_Rename_Pragma => Rename_Pragma : declare
21340 New_Name : constant Node_Id := Get_Pragma_Arg (Arg1);
21341 Old_Name : constant Node_Id := Get_Pragma_Arg (Arg2);
21342
21343 begin
21344 GNAT_Pragma;
21345 Check_Valid_Configuration_Pragma;
21346 Check_Arg_Count (2);
21347 Check_Optional_Identifier (Arg1, Name_New_Name);
21348 Check_Optional_Identifier (Arg2, Name_Renamed);
21349
21350 if Nkind (New_Name) /= N_Identifier then
21351 Error_Pragma_Arg ("identifier expected", Arg1);
21352 end if;
21353
21354 if Nkind (Old_Name) /= N_Identifier then
21355 Error_Pragma_Arg ("identifier expected", Arg2);
21356 end if;
21357
21358 -- The New_Name arg should not be an existing pragma (but we allow
21359 -- it; it's just a warning). The Old_Name arg must be an existing
21360 -- pragma.
21361
21362 if Is_Pragma_Name (Chars (New_Name)) then
21363 Error_Pragma_Arg ("??pragma is already defined", Arg1);
21364 end if;
21365
21366 if not Is_Pragma_Name (Chars (Old_Name)) then
21367 Error_Pragma_Arg ("existing pragma name expected", Arg1);
21368 end if;
21369
21370 Map_Pragma_Name (From => Chars (New_Name), To => Chars (Old_Name));
21371 end Rename_Pragma;
21372
21373 -----------------------------------
21374 -- Post/Post_Class/Postcondition --
21375 -----------------------------------
21376
21377 -- pragma Post (Boolean_EXPRESSION);
21378 -- pragma Post_Class (Boolean_EXPRESSION);
21379 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
21380 -- [,[Message =>] String_EXPRESSION]);
21381
21382 -- Characteristics:
21383
21384 -- * Analysis - The annotation undergoes initial checks to verify
21385 -- the legal placement and context. Secondary checks preanalyze the
21386 -- expression in:
21387
21388 -- Analyze_Pre_Post_Condition_In_Decl_Part
21389
21390 -- * Expansion - The annotation is expanded during the expansion of
21391 -- the related subprogram [body] contract as performed in:
21392
21393 -- Expand_Subprogram_Contract
21394
21395 -- * Template - The annotation utilizes the generic template of the
21396 -- related subprogram [body] when it is:
21397
21398 -- aspect on subprogram declaration
21399 -- aspect on stand-alone subprogram body
21400 -- pragma on stand-alone subprogram body
21401
21402 -- The annotation must prepare its own template when it is:
21403
21404 -- pragma on subprogram declaration
21405
21406 -- * Globals - Capture of global references must occur after full
21407 -- analysis.
21408
21409 -- * Instance - The annotation is instantiated automatically when
21410 -- the related generic subprogram [body] is instantiated except for
21411 -- the "pragma on subprogram declaration" case. In that scenario
21412 -- the annotation must instantiate itself.
21413
21414 when Pragma_Post
21415 | Pragma_Post_Class
21416 | Pragma_Postcondition
21417 =>
21418 Analyze_Pre_Post_Condition;
21419
21420 --------------------------------
21421 -- Pre/Pre_Class/Precondition --
21422 --------------------------------
21423
21424 -- pragma Pre (Boolean_EXPRESSION);
21425 -- pragma Pre_Class (Boolean_EXPRESSION);
21426 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
21427 -- [,[Message =>] String_EXPRESSION]);
21428
21429 -- Characteristics:
21430
21431 -- * Analysis - The annotation undergoes initial checks to verify
21432 -- the legal placement and context. Secondary checks preanalyze the
21433 -- expression in:
21434
21435 -- Analyze_Pre_Post_Condition_In_Decl_Part
21436
21437 -- * Expansion - The annotation is expanded during the expansion of
21438 -- the related subprogram [body] contract as performed in:
21439
21440 -- Expand_Subprogram_Contract
21441
21442 -- * Template - The annotation utilizes the generic template of the
21443 -- related subprogram [body] when it is:
21444
21445 -- aspect on subprogram declaration
21446 -- aspect on stand-alone subprogram body
21447 -- pragma on stand-alone subprogram body
21448
21449 -- The annotation must prepare its own template when it is:
21450
21451 -- pragma on subprogram declaration
21452
21453 -- * Globals - Capture of global references must occur after full
21454 -- analysis.
21455
21456 -- * Instance - The annotation is instantiated automatically when
21457 -- the related generic subprogram [body] is instantiated except for
21458 -- the "pragma on subprogram declaration" case. In that scenario
21459 -- the annotation must instantiate itself.
21460
21461 when Pragma_Pre
21462 | Pragma_Pre_Class
21463 | Pragma_Precondition
21464 =>
21465 Analyze_Pre_Post_Condition;
21466
21467 ---------------
21468 -- Predicate --
21469 ---------------
21470
21471 -- pragma Predicate
21472 -- ([Entity =>] type_LOCAL_NAME,
21473 -- [Check =>] boolean_EXPRESSION);
21474
21475 when Pragma_Predicate => Predicate : declare
21476 Discard : Boolean;
21477 Typ : Entity_Id;
21478 Type_Id : Node_Id;
21479
21480 begin
21481 GNAT_Pragma;
21482 Check_Arg_Count (2);
21483 Check_Optional_Identifier (Arg1, Name_Entity);
21484 Check_Optional_Identifier (Arg2, Name_Check);
21485
21486 Check_Arg_Is_Local_Name (Arg1);
21487
21488 Type_Id := Get_Pragma_Arg (Arg1);
21489 Find_Type (Type_Id);
21490 Typ := Entity (Type_Id);
21491
21492 if Typ = Any_Type then
21493 return;
21494 end if;
21495
21496 -- A pragma that applies to a Ghost entity becomes Ghost for the
21497 -- purposes of legality checks and removal of ignored Ghost code.
21498
21499 Mark_Ghost_Pragma (N, Typ);
21500
21501 -- The remaining processing is simply to link the pragma on to
21502 -- the rep item chain, for processing when the type is frozen.
21503 -- This is accomplished by a call to Rep_Item_Too_Late. We also
21504 -- mark the type as having predicates.
21505
21506 -- If the current policy for predicate checking is Ignore mark the
21507 -- subtype accordingly. In the case of predicates we consider them
21508 -- enabled unless Ignore is specified (either directly or with a
21509 -- general Assertion_Policy pragma) to preserve existing warnings.
21510
21511 Set_Has_Predicates (Typ);
21512
21513 -- Indicate that the pragma must be processed at the point the
21514 -- type is frozen, as is done for the corresponding aspect.
21515
21516 Set_Has_Delayed_Aspects (Typ);
21517 Set_Has_Delayed_Freeze (Typ);
21518
21519 Set_Predicates_Ignored (Typ,
21520 Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore);
21521 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
21522 end Predicate;
21523
21524 -----------------------
21525 -- Predicate_Failure --
21526 -----------------------
21527
21528 -- pragma Predicate_Failure
21529 -- ([Entity =>] type_LOCAL_NAME,
21530 -- [Message =>] string_EXPRESSION);
21531
21532 when Pragma_Predicate_Failure => Predicate_Failure : declare
21533 Discard : Boolean;
21534 Typ : Entity_Id;
21535 Type_Id : Node_Id;
21536
21537 begin
21538 GNAT_Pragma;
21539 Check_Arg_Count (2);
21540 Check_Optional_Identifier (Arg1, Name_Entity);
21541 Check_Optional_Identifier (Arg2, Name_Message);
21542
21543 Check_Arg_Is_Local_Name (Arg1);
21544
21545 Type_Id := Get_Pragma_Arg (Arg1);
21546 Find_Type (Type_Id);
21547 Typ := Entity (Type_Id);
21548
21549 if Typ = Any_Type then
21550 return;
21551 end if;
21552
21553 -- A pragma that applies to a Ghost entity becomes Ghost for the
21554 -- purposes of legality checks and removal of ignored Ghost code.
21555
21556 Mark_Ghost_Pragma (N, Typ);
21557
21558 -- The remaining processing is simply to link the pragma on to
21559 -- the rep item chain, for processing when the type is frozen.
21560 -- This is accomplished by a call to Rep_Item_Too_Late.
21561
21562 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
21563 end Predicate_Failure;
21564
21565 ------------------
21566 -- Preelaborate --
21567 ------------------
21568
21569 -- pragma Preelaborate [(library_unit_NAME)];
21570
21571 -- Set the flag Is_Preelaborated of program unit name entity
21572
21573 when Pragma_Preelaborate => Preelaborate : declare
21574 Pa : constant Node_Id := Parent (N);
21575 Pk : constant Node_Kind := Nkind (Pa);
21576 Ent : Entity_Id;
21577
21578 begin
21579 Check_Ada_83_Warning;
21580 Check_Valid_Library_Unit_Pragma;
21581
21582 -- If N was rewritten as a null statement there is nothing more
21583 -- to do.
21584
21585 if Nkind (N) = N_Null_Statement then
21586 return;
21587 end if;
21588
21589 Ent := Find_Lib_Unit_Name;
21590
21591 -- A pragma that applies to a Ghost entity becomes Ghost for the
21592 -- purposes of legality checks and removal of ignored Ghost code.
21593
21594 Mark_Ghost_Pragma (N, Ent);
21595 Check_Duplicate_Pragma (Ent);
21596
21597 -- This filters out pragmas inside generic parents that show up
21598 -- inside instantiations. Pragmas that come from aspects in the
21599 -- unit are not ignored.
21600
21601 if Present (Ent) then
21602 if Pk = N_Package_Specification
21603 and then Present (Generic_Parent (Pa))
21604 and then not From_Aspect_Specification (N)
21605 then
21606 null;
21607
21608 else
21609 if not Debug_Flag_U then
21610 Set_Is_Preelaborated (Ent);
21611
21612 if Legacy_Elaboration_Checks then
21613 Set_Suppress_Elaboration_Warnings (Ent);
21614 end if;
21615 end if;
21616 end if;
21617 end if;
21618 end Preelaborate;
21619
21620 -------------------------------
21621 -- Prefix_Exception_Messages --
21622 -------------------------------
21623
21624 -- pragma Prefix_Exception_Messages;
21625
21626 when Pragma_Prefix_Exception_Messages =>
21627 GNAT_Pragma;
21628 Check_Valid_Configuration_Pragma;
21629 Check_Arg_Count (0);
21630 Prefix_Exception_Messages := True;
21631
21632 --------------
21633 -- Priority --
21634 --------------
21635
21636 -- pragma Priority (EXPRESSION);
21637
21638 when Pragma_Priority => Priority : declare
21639 P : constant Node_Id := Parent (N);
21640 Arg : Node_Id;
21641 Ent : Entity_Id;
21642
21643 begin
21644 Check_No_Identifiers;
21645 Check_Arg_Count (1);
21646
21647 -- Subprogram case
21648
21649 if Nkind (P) = N_Subprogram_Body then
21650 Check_In_Main_Program;
21651
21652 Ent := Defining_Unit_Name (Specification (P));
21653
21654 if Nkind (Ent) = N_Defining_Program_Unit_Name then
21655 Ent := Defining_Identifier (Ent);
21656 end if;
21657
21658 Arg := Get_Pragma_Arg (Arg1);
21659 Analyze_And_Resolve (Arg, Standard_Integer);
21660
21661 -- Must be static
21662
21663 if not Is_OK_Static_Expression (Arg) then
21664 Flag_Non_Static_Expr
21665 ("main subprogram priority is not static!", Arg);
21666 raise Pragma_Exit;
21667
21668 -- If constraint error, then we already signalled an error
21669
21670 elsif Raises_Constraint_Error (Arg) then
21671 null;
21672
21673 -- Otherwise check in range except if Relaxed_RM_Semantics
21674 -- where we ignore the value if out of range.
21675
21676 else
21677 if not Relaxed_RM_Semantics
21678 and then not Is_In_Range (Arg, RTE (RE_Priority))
21679 then
21680 Error_Pragma_Arg
21681 ("main subprogram priority is out of range", Arg1);
21682 else
21683 Set_Main_Priority
21684 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
21685 end if;
21686 end if;
21687
21688 -- Load an arbitrary entity from System.Tasking.Stages or
21689 -- System.Tasking.Restricted.Stages (depending on the
21690 -- supported profile) to make sure that one of these packages
21691 -- is implicitly with'ed, since we need to have the tasking
21692 -- run time active for the pragma Priority to have any effect.
21693 -- Previously we with'ed the package System.Tasking, but this
21694 -- package does not trigger the required initialization of the
21695 -- run-time library.
21696
21697 if Restricted_Profile then
21698 Discard_Node (RTE (RE_Activate_Restricted_Tasks));
21699 else
21700 Discard_Node (RTE (RE_Activate_Tasks));
21701 end if;
21702
21703 -- Task or Protected, must be of type Integer
21704
21705 elsif Nkind (P) in N_Protected_Definition | N_Task_Definition then
21706 Arg := Get_Pragma_Arg (Arg1);
21707 Ent := Defining_Identifier (Parent (P));
21708
21709 -- The expression must be analyzed in the special manner
21710 -- described in "Handling of Default and Per-Object
21711 -- Expressions" in sem.ads.
21712
21713 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
21714
21715 if not Is_OK_Static_Expression (Arg) then
21716 Check_Restriction (Static_Priorities, Arg);
21717 end if;
21718
21719 -- Anything else is incorrect
21720
21721 else
21722 Pragma_Misplaced;
21723 end if;
21724
21725 -- Check duplicate pragma before we chain the pragma in the Rep
21726 -- Item chain of Ent.
21727
21728 Check_Duplicate_Pragma (Ent);
21729 Record_Rep_Item (Ent, N);
21730 end Priority;
21731
21732 -----------------------------------
21733 -- Priority_Specific_Dispatching --
21734 -----------------------------------
21735
21736 -- pragma Priority_Specific_Dispatching (
21737 -- policy_IDENTIFIER,
21738 -- first_priority_EXPRESSION,
21739 -- last_priority_EXPRESSION);
21740
21741 when Pragma_Priority_Specific_Dispatching =>
21742 Priority_Specific_Dispatching : declare
21743 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
21744 -- This is the entity System.Any_Priority;
21745
21746 DP : Character;
21747 Lower_Bound : Node_Id;
21748 Upper_Bound : Node_Id;
21749 Lower_Val : Uint;
21750 Upper_Val : Uint;
21751
21752 begin
21753 Ada_2005_Pragma;
21754 Check_Arg_Count (3);
21755 Check_No_Identifiers;
21756 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
21757 Check_Valid_Configuration_Pragma;
21758 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21759 DP := Fold_Upper (Name_Buffer (1));
21760
21761 Lower_Bound := Get_Pragma_Arg (Arg2);
21762 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
21763 Lower_Val := Expr_Value (Lower_Bound);
21764
21765 Upper_Bound := Get_Pragma_Arg (Arg3);
21766 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
21767 Upper_Val := Expr_Value (Upper_Bound);
21768
21769 -- It is not allowed to use Task_Dispatching_Policy and
21770 -- Priority_Specific_Dispatching in the same partition.
21771
21772 if Task_Dispatching_Policy /= ' ' then
21773 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21774 Error_Pragma
21775 ("pragma% incompatible with Task_Dispatching_Policy#");
21776
21777 -- Check lower bound in range
21778
21779 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21780 or else
21781 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
21782 then
21783 Error_Pragma_Arg
21784 ("first_priority is out of range", Arg2);
21785
21786 -- Check upper bound in range
21787
21788 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21789 or else
21790 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
21791 then
21792 Error_Pragma_Arg
21793 ("last_priority is out of range", Arg3);
21794
21795 -- Check that the priority range is valid
21796
21797 elsif Lower_Val > Upper_Val then
21798 Error_Pragma
21799 ("last_priority_expression must be greater than or equal to "
21800 & "first_priority_expression");
21801
21802 -- Store the new policy, but always preserve System_Location since
21803 -- we like the error message with the run-time name.
21804
21805 else
21806 -- Check overlapping in the priority ranges specified in other
21807 -- Priority_Specific_Dispatching pragmas within the same
21808 -- partition. We can only check those we know about.
21809
21810 for J in
21811 Specific_Dispatching.First .. Specific_Dispatching.Last
21812 loop
21813 if Specific_Dispatching.Table (J).First_Priority in
21814 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21815 or else Specific_Dispatching.Table (J).Last_Priority in
21816 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21817 then
21818 Error_Msg_Sloc :=
21819 Specific_Dispatching.Table (J).Pragma_Loc;
21820 Error_Pragma
21821 ("priority range overlaps with "
21822 & "Priority_Specific_Dispatching#");
21823 end if;
21824 end loop;
21825
21826 -- The use of Priority_Specific_Dispatching is incompatible
21827 -- with Task_Dispatching_Policy.
21828
21829 if Task_Dispatching_Policy /= ' ' then
21830 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21831 Error_Pragma
21832 ("Priority_Specific_Dispatching incompatible "
21833 & "with Task_Dispatching_Policy#");
21834 end if;
21835
21836 -- The use of Priority_Specific_Dispatching forces ceiling
21837 -- locking policy.
21838
21839 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
21840 Error_Msg_Sloc := Locking_Policy_Sloc;
21841 Error_Pragma
21842 ("Priority_Specific_Dispatching incompatible "
21843 & "with Locking_Policy#");
21844
21845 -- Set the Ceiling_Locking policy, but preserve System_Location
21846 -- since we like the error message with the run time name.
21847
21848 else
21849 Locking_Policy := 'C';
21850
21851 if Locking_Policy_Sloc /= System_Location then
21852 Locking_Policy_Sloc := Loc;
21853 end if;
21854 end if;
21855
21856 -- Add entry in the table
21857
21858 Specific_Dispatching.Append
21859 ((Dispatching_Policy => DP,
21860 First_Priority => UI_To_Int (Lower_Val),
21861 Last_Priority => UI_To_Int (Upper_Val),
21862 Pragma_Loc => Loc));
21863 end if;
21864 end Priority_Specific_Dispatching;
21865
21866 -------------
21867 -- Profile --
21868 -------------
21869
21870 -- pragma Profile (profile_IDENTIFIER);
21871
21872 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
21873
21874 when Pragma_Profile =>
21875 Ada_2005_Pragma;
21876 Check_Arg_Count (1);
21877 Check_Valid_Configuration_Pragma;
21878 Check_No_Identifiers;
21879
21880 declare
21881 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21882
21883 begin
21884 if Nkind (Argx) /= N_Identifier then
21885 Error_Msg_N
21886 ("argument of pragma Profile must be an identifier", N);
21887
21888 elsif Chars (Argx) = Name_Ravenscar then
21889 Set_Ravenscar_Profile (Ravenscar, N);
21890
21891 elsif Chars (Argx) = Name_Jorvik then
21892 Set_Ravenscar_Profile (Jorvik, N);
21893
21894 elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then
21895 Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N);
21896
21897 elsif Chars (Argx) = Name_Gnat_Ravenscar_EDF then
21898 Set_Ravenscar_Profile (GNAT_Ravenscar_EDF, N);
21899
21900 elsif Chars (Argx) = Name_Restricted then
21901 Set_Profile_Restrictions
21902 (Restricted,
21903 N, Warn => Treat_Restrictions_As_Warnings);
21904
21905 elsif Chars (Argx) = Name_Rational then
21906 Set_Rational_Profile;
21907
21908 elsif Chars (Argx) = Name_No_Implementation_Extensions then
21909 Set_Profile_Restrictions
21910 (No_Implementation_Extensions,
21911 N, Warn => Treat_Restrictions_As_Warnings);
21912
21913 else
21914 Error_Pragma_Arg ("& is not a valid profile", Argx);
21915 end if;
21916 end;
21917
21918 ----------------------
21919 -- Profile_Warnings --
21920 ----------------------
21921
21922 -- pragma Profile_Warnings (profile_IDENTIFIER);
21923
21924 -- profile_IDENTIFIER => Restricted | Ravenscar
21925
21926 when Pragma_Profile_Warnings =>
21927 GNAT_Pragma;
21928 Check_Arg_Count (1);
21929 Check_Valid_Configuration_Pragma;
21930 Check_No_Identifiers;
21931
21932 declare
21933 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21934
21935 begin
21936 if Chars (Argx) = Name_Ravenscar then
21937 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
21938
21939 elsif Chars (Argx) = Name_Restricted then
21940 Set_Profile_Restrictions (Restricted, N, Warn => True);
21941
21942 elsif Chars (Argx) = Name_No_Implementation_Extensions then
21943 Set_Profile_Restrictions
21944 (No_Implementation_Extensions, N, Warn => True);
21945
21946 else
21947 Error_Pragma_Arg ("& is not a valid profile", Argx);
21948 end if;
21949 end;
21950
21951 --------------------------
21952 -- Propagate_Exceptions --
21953 --------------------------
21954
21955 -- pragma Propagate_Exceptions;
21956
21957 -- Note: this pragma is obsolete and has no effect
21958
21959 when Pragma_Propagate_Exceptions =>
21960 GNAT_Pragma;
21961 Check_Arg_Count (0);
21962
21963 if Warn_On_Obsolescent_Feature then
21964 Error_Msg_N
21965 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
21966 "and has no effect?j?", N);
21967 end if;
21968
21969 -----------------------------
21970 -- Provide_Shift_Operators --
21971 -----------------------------
21972
21973 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
21974
21975 when Pragma_Provide_Shift_Operators =>
21976 Provide_Shift_Operators : declare
21977 Ent : Entity_Id;
21978
21979 procedure Declare_Shift_Operator (Nam : Name_Id);
21980 -- Insert declaration and pragma Instrinsic for named shift op
21981
21982 ----------------------------
21983 -- Declare_Shift_Operator --
21984 ----------------------------
21985
21986 procedure Declare_Shift_Operator (Nam : Name_Id) is
21987 Func : Node_Id;
21988 Import : Node_Id;
21989
21990 begin
21991 Func :=
21992 Make_Subprogram_Declaration (Loc,
21993 Make_Function_Specification (Loc,
21994 Defining_Unit_Name =>
21995 Make_Defining_Identifier (Loc, Chars => Nam),
21996
21997 Result_Definition =>
21998 Make_Identifier (Loc, Chars => Chars (Ent)),
21999
22000 Parameter_Specifications => New_List (
22001 Make_Parameter_Specification (Loc,
22002 Defining_Identifier =>
22003 Make_Defining_Identifier (Loc, Name_Value),
22004 Parameter_Type =>
22005 Make_Identifier (Loc, Chars => Chars (Ent))),
22006
22007 Make_Parameter_Specification (Loc,
22008 Defining_Identifier =>
22009 Make_Defining_Identifier (Loc, Name_Amount),
22010 Parameter_Type =>
22011 New_Occurrence_Of (Standard_Natural, Loc)))));
22012
22013 Import :=
22014 Make_Pragma (Loc,
22015 Chars => Name_Import,
22016 Pragma_Argument_Associations => New_List (
22017 Make_Pragma_Argument_Association (Loc,
22018 Expression => Make_Identifier (Loc, Name_Intrinsic)),
22019 Make_Pragma_Argument_Association (Loc,
22020 Expression => Make_Identifier (Loc, Nam))));
22021
22022 Insert_After (N, Import);
22023 Insert_After (N, Func);
22024 end Declare_Shift_Operator;
22025
22026 -- Start of processing for Provide_Shift_Operators
22027
22028 begin
22029 GNAT_Pragma;
22030 Check_Arg_Count (1);
22031 Check_Arg_Is_Local_Name (Arg1);
22032
22033 Arg1 := Get_Pragma_Arg (Arg1);
22034
22035 -- We must have an entity name
22036
22037 if not Is_Entity_Name (Arg1) then
22038 Error_Pragma_Arg
22039 ("pragma % must apply to integer first subtype", Arg1);
22040 end if;
22041
22042 -- If no Entity, means there was a prior error so ignore
22043
22044 if Present (Entity (Arg1)) then
22045 Ent := Entity (Arg1);
22046
22047 -- Apply error checks
22048
22049 if not Is_First_Subtype (Ent) then
22050 Error_Pragma_Arg
22051 ("cannot apply pragma %",
22052 "\& is not a first subtype",
22053 Arg1);
22054
22055 elsif not Is_Integer_Type (Ent) then
22056 Error_Pragma_Arg
22057 ("cannot apply pragma %",
22058 "\& is not an integer type",
22059 Arg1);
22060
22061 elsif Has_Shift_Operator (Ent) then
22062 Error_Pragma_Arg
22063 ("cannot apply pragma %",
22064 "\& already has declared shift operators",
22065 Arg1);
22066
22067 elsif Is_Frozen (Ent) then
22068 Error_Pragma_Arg
22069 ("pragma % appears too late",
22070 "\& is already frozen",
22071 Arg1);
22072 end if;
22073
22074 -- Now declare the operators. We do this during analysis rather
22075 -- than expansion, since we want the operators available if we
22076 -- are operating in -gnatc mode.
22077
22078 Declare_Shift_Operator (Name_Rotate_Left);
22079 Declare_Shift_Operator (Name_Rotate_Right);
22080 Declare_Shift_Operator (Name_Shift_Left);
22081 Declare_Shift_Operator (Name_Shift_Right);
22082 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
22083 end if;
22084 end Provide_Shift_Operators;
22085
22086 ------------------
22087 -- Psect_Object --
22088 ------------------
22089
22090 -- pragma Psect_Object (
22091 -- [Internal =>] LOCAL_NAME,
22092 -- [, [External =>] EXTERNAL_SYMBOL]
22093 -- [, [Size =>] EXTERNAL_SYMBOL]);
22094
22095 when Pragma_Common_Object
22096 | Pragma_Psect_Object
22097 =>
22098 Psect_Object : declare
22099 Args : Args_List (1 .. 3);
22100 Names : constant Name_List (1 .. 3) := (
22101 Name_Internal,
22102 Name_External,
22103 Name_Size);
22104
22105 Internal : Node_Id renames Args (1);
22106 External : Node_Id renames Args (2);
22107 Size : Node_Id renames Args (3);
22108
22109 Def_Id : Entity_Id;
22110
22111 procedure Check_Arg (Arg : Node_Id);
22112 -- Checks that argument is either a string literal or an
22113 -- identifier, and posts error message if not.
22114
22115 ---------------
22116 -- Check_Arg --
22117 ---------------
22118
22119 procedure Check_Arg (Arg : Node_Id) is
22120 begin
22121 if Nkind (Original_Node (Arg)) not in
22122 N_String_Literal | N_Identifier
22123 then
22124 Error_Pragma_Arg
22125 ("inappropriate argument for pragma %", Arg);
22126 end if;
22127 end Check_Arg;
22128
22129 -- Start of processing for Common_Object/Psect_Object
22130
22131 begin
22132 GNAT_Pragma;
22133 Gather_Associations (Names, Args);
22134 Process_Extended_Import_Export_Internal_Arg (Internal);
22135
22136 Def_Id := Entity (Internal);
22137
22138 if Ekind (Def_Id) not in E_Constant | E_Variable then
22139 Error_Pragma_Arg
22140 ("pragma% must designate an object", Internal);
22141 end if;
22142
22143 Check_Arg (Internal);
22144
22145 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
22146 Error_Pragma_Arg
22147 ("cannot use pragma% for imported/exported object",
22148 Internal);
22149 end if;
22150
22151 if Is_Concurrent_Type (Etype (Internal)) then
22152 Error_Pragma_Arg
22153 ("cannot specify pragma % for task/protected object",
22154 Internal);
22155 end if;
22156
22157 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
22158 or else
22159 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
22160 then
22161 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
22162 end if;
22163
22164 if Ekind (Def_Id) = E_Constant then
22165 Error_Pragma_Arg
22166 ("cannot specify pragma % for a constant", Internal);
22167 end if;
22168
22169 if Is_Record_Type (Etype (Internal)) then
22170 declare
22171 Ent : Entity_Id;
22172 Decl : Entity_Id;
22173
22174 begin
22175 Ent := First_Entity (Etype (Internal));
22176 while Present (Ent) loop
22177 Decl := Declaration_Node (Ent);
22178
22179 if Ekind (Ent) = E_Component
22180 and then Nkind (Decl) = N_Component_Declaration
22181 and then Present (Expression (Decl))
22182 and then Warn_On_Export_Import
22183 then
22184 Error_Msg_N
22185 ("?x?object for pragma % has defaults", Internal);
22186 exit;
22187
22188 else
22189 Next_Entity (Ent);
22190 end if;
22191 end loop;
22192 end;
22193 end if;
22194
22195 if Present (Size) then
22196 Check_Arg (Size);
22197 end if;
22198
22199 if Present (External) then
22200 Check_Arg_Is_External_Name (External);
22201 end if;
22202
22203 -- If all error tests pass, link pragma on to the rep item chain
22204
22205 Record_Rep_Item (Def_Id, N);
22206 end Psect_Object;
22207
22208 ----------
22209 -- Pure --
22210 ----------
22211
22212 -- pragma Pure [(library_unit_NAME)];
22213
22214 when Pragma_Pure => Pure : declare
22215 Ent : Entity_Id;
22216
22217 begin
22218 Check_Ada_83_Warning;
22219
22220 -- If the pragma comes from a subprogram instantiation, nothing to
22221 -- check, this can happen at any level of nesting.
22222
22223 if Is_Wrapper_Package (Current_Scope) then
22224 return;
22225 end if;
22226
22227 Check_Valid_Library_Unit_Pragma;
22228
22229 -- If N was rewritten as a null statement there is nothing more
22230 -- to do.
22231
22232 if Nkind (N) = N_Null_Statement then
22233 return;
22234 end if;
22235
22236 Ent := Find_Lib_Unit_Name;
22237
22238 -- A pragma that applies to a Ghost entity becomes Ghost for the
22239 -- purposes of legality checks and removal of ignored Ghost code.
22240
22241 Mark_Ghost_Pragma (N, Ent);
22242
22243 if not Debug_Flag_U then
22244 Set_Is_Pure (Ent);
22245 Set_Has_Pragma_Pure (Ent);
22246
22247 if Legacy_Elaboration_Checks then
22248 Set_Suppress_Elaboration_Warnings (Ent);
22249 end if;
22250 end if;
22251 end Pure;
22252
22253 -------------------
22254 -- Pure_Function --
22255 -------------------
22256
22257 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
22258
22259 when Pragma_Pure_Function => Pure_Function : declare
22260 Def_Id : Entity_Id;
22261 E : Entity_Id;
22262 E_Id : Node_Id;
22263 Effective : Boolean := False;
22264 Orig_Def : Entity_Id;
22265 Same_Decl : Boolean := False;
22266
22267 begin
22268 GNAT_Pragma;
22269 Check_Arg_Count (1);
22270 Check_Optional_Identifier (Arg1, Name_Entity);
22271 Check_Arg_Is_Local_Name (Arg1);
22272 E_Id := Get_Pragma_Arg (Arg1);
22273
22274 if Etype (E_Id) = Any_Type then
22275 return;
22276 end if;
22277
22278 -- Loop through homonyms (overloadings) of referenced entity
22279
22280 E := Entity (E_Id);
22281
22282 -- A pragma that applies to a Ghost entity becomes Ghost for the
22283 -- purposes of legality checks and removal of ignored Ghost code.
22284
22285 Mark_Ghost_Pragma (N, E);
22286
22287 if Present (E) then
22288 loop
22289 Def_Id := Get_Base_Subprogram (E);
22290
22291 if Ekind (Def_Id) not in
22292 E_Function | E_Generic_Function | E_Operator
22293 then
22294 Error_Pragma_Arg
22295 ("pragma% requires a function name", Arg1);
22296 end if;
22297
22298 -- When we have a generic function we must jump up a level
22299 -- to the declaration of the wrapper package itself.
22300
22301 Orig_Def := Def_Id;
22302
22303 if Is_Generic_Instance (Def_Id) then
22304 while Nkind (Orig_Def) /= N_Package_Declaration loop
22305 Orig_Def := Parent (Orig_Def);
22306 end loop;
22307 end if;
22308
22309 if In_Same_Declarative_Part (Parent (N), Orig_Def) then
22310 Same_Decl := True;
22311 Set_Is_Pure (Def_Id);
22312
22313 if not Has_Pragma_Pure_Function (Def_Id) then
22314 Set_Has_Pragma_Pure_Function (Def_Id);
22315 Effective := True;
22316 end if;
22317 end if;
22318
22319 exit when From_Aspect_Specification (N);
22320 E := Homonym (E);
22321 exit when No (E) or else Scope (E) /= Current_Scope;
22322 end loop;
22323
22324 if not Effective
22325 and then Warn_On_Redundant_Constructs
22326 then
22327 Error_Msg_NE
22328 ("pragma Pure_Function on& is redundant?r?",
22329 N, Entity (E_Id));
22330
22331 elsif not Same_Decl then
22332 Error_Pragma_Arg
22333 ("pragma% argument must be in same declarative part",
22334 Arg1);
22335 end if;
22336 end if;
22337 end Pure_Function;
22338
22339 --------------------
22340 -- Queuing_Policy --
22341 --------------------
22342
22343 -- pragma Queuing_Policy (policy_IDENTIFIER);
22344
22345 when Pragma_Queuing_Policy => declare
22346 QP : Character;
22347
22348 begin
22349 Check_Ada_83_Warning;
22350 Check_Arg_Count (1);
22351 Check_No_Identifiers;
22352 Check_Arg_Is_Queuing_Policy (Arg1);
22353 Check_Valid_Configuration_Pragma;
22354 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
22355 QP := Fold_Upper (Name_Buffer (1));
22356
22357 if Queuing_Policy /= ' '
22358 and then Queuing_Policy /= QP
22359 then
22360 Error_Msg_Sloc := Queuing_Policy_Sloc;
22361 Error_Pragma ("queuing policy incompatible with policy#");
22362
22363 -- Set new policy, but always preserve System_Location since we
22364 -- like the error message with the run time name.
22365
22366 else
22367 Queuing_Policy := QP;
22368
22369 if Queuing_Policy_Sloc /= System_Location then
22370 Queuing_Policy_Sloc := Loc;
22371 end if;
22372 end if;
22373 end;
22374
22375 --------------
22376 -- Rational --
22377 --------------
22378
22379 -- pragma Rational, for compatibility with foreign compiler
22380
22381 when Pragma_Rational =>
22382 Set_Rational_Profile;
22383
22384 ---------------------
22385 -- Refined_Depends --
22386 ---------------------
22387
22388 -- pragma Refined_Depends (DEPENDENCY_RELATION);
22389
22390 -- DEPENDENCY_RELATION ::=
22391 -- null
22392 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
22393
22394 -- DEPENDENCY_CLAUSE ::=
22395 -- OUTPUT_LIST =>[+] INPUT_LIST
22396 -- | NULL_DEPENDENCY_CLAUSE
22397
22398 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
22399
22400 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
22401
22402 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
22403
22404 -- OUTPUT ::= NAME | FUNCTION_RESULT
22405 -- INPUT ::= NAME
22406
22407 -- where FUNCTION_RESULT is a function Result attribute_reference
22408
22409 -- Characteristics:
22410
22411 -- * Analysis - The annotation undergoes initial checks to verify
22412 -- the legal placement and context. Secondary checks fully analyze
22413 -- the dependency clauses/global list in:
22414
22415 -- Analyze_Refined_Depends_In_Decl_Part
22416
22417 -- * Expansion - None.
22418
22419 -- * Template - The annotation utilizes the generic template of the
22420 -- related subprogram body.
22421
22422 -- * Globals - Capture of global references must occur after full
22423 -- analysis.
22424
22425 -- * Instance - The annotation is instantiated automatically when
22426 -- the related generic subprogram body is instantiated.
22427
22428 when Pragma_Refined_Depends => Refined_Depends : declare
22429 Body_Id : Entity_Id;
22430 Legal : Boolean;
22431 Spec_Id : Entity_Id;
22432
22433 begin
22434 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22435
22436 if Legal then
22437
22438 -- Chain the pragma on the contract for further processing by
22439 -- Analyze_Refined_Depends_In_Decl_Part.
22440
22441 Add_Contract_Item (N, Body_Id);
22442
22443 -- The legality checks of pragmas Refined_Depends and
22444 -- Refined_Global are affected by the SPARK mode in effect and
22445 -- the volatility of the context. In addition these two pragmas
22446 -- are subject to an inherent order:
22447
22448 -- 1) Refined_Global
22449 -- 2) Refined_Depends
22450
22451 -- Analyze all these pragmas in the order outlined above
22452
22453 Analyze_If_Present (Pragma_SPARK_Mode);
22454 Analyze_If_Present (Pragma_Volatile_Function);
22455 Analyze_If_Present (Pragma_Refined_Global);
22456 Analyze_Refined_Depends_In_Decl_Part (N);
22457 end if;
22458 end Refined_Depends;
22459
22460 --------------------
22461 -- Refined_Global --
22462 --------------------
22463
22464 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
22465
22466 -- GLOBAL_SPECIFICATION ::=
22467 -- null
22468 -- | (GLOBAL_LIST)
22469 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
22470
22471 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
22472
22473 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
22474 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
22475 -- GLOBAL_ITEM ::= NAME
22476
22477 -- Characteristics:
22478
22479 -- * Analysis - The annotation undergoes initial checks to verify
22480 -- the legal placement and context. Secondary checks fully analyze
22481 -- the dependency clauses/global list in:
22482
22483 -- Analyze_Refined_Global_In_Decl_Part
22484
22485 -- * Expansion - None.
22486
22487 -- * Template - The annotation utilizes the generic template of the
22488 -- related subprogram body.
22489
22490 -- * Globals - Capture of global references must occur after full
22491 -- analysis.
22492
22493 -- * Instance - The annotation is instantiated automatically when
22494 -- the related generic subprogram body is instantiated.
22495
22496 when Pragma_Refined_Global => Refined_Global : declare
22497 Body_Id : Entity_Id;
22498 Legal : Boolean;
22499 Spec_Id : Entity_Id;
22500
22501 begin
22502 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22503
22504 if Legal then
22505
22506 -- Chain the pragma on the contract for further processing by
22507 -- Analyze_Refined_Global_In_Decl_Part.
22508
22509 Add_Contract_Item (N, Body_Id);
22510
22511 -- The legality checks of pragmas Refined_Depends and
22512 -- Refined_Global are affected by the SPARK mode in effect and
22513 -- the volatility of the context. In addition these two pragmas
22514 -- are subject to an inherent order:
22515
22516 -- 1) Refined_Global
22517 -- 2) Refined_Depends
22518
22519 -- Analyze all these pragmas in the order outlined above
22520
22521 Analyze_If_Present (Pragma_SPARK_Mode);
22522 Analyze_If_Present (Pragma_Volatile_Function);
22523 Analyze_Refined_Global_In_Decl_Part (N);
22524 Analyze_If_Present (Pragma_Refined_Depends);
22525 end if;
22526 end Refined_Global;
22527
22528 ------------------
22529 -- Refined_Post --
22530 ------------------
22531
22532 -- pragma Refined_Post (boolean_EXPRESSION);
22533
22534 -- Characteristics:
22535
22536 -- * Analysis - The annotation is fully analyzed immediately upon
22537 -- elaboration as it cannot forward reference entities.
22538
22539 -- * Expansion - The annotation is expanded during the expansion of
22540 -- the related subprogram body contract as performed in:
22541
22542 -- Expand_Subprogram_Contract
22543
22544 -- * Template - The annotation utilizes the generic template of the
22545 -- related subprogram body.
22546
22547 -- * Globals - Capture of global references must occur after full
22548 -- analysis.
22549
22550 -- * Instance - The annotation is instantiated automatically when
22551 -- the related generic subprogram body is instantiated.
22552
22553 when Pragma_Refined_Post => Refined_Post : declare
22554 Body_Id : Entity_Id;
22555 Legal : Boolean;
22556 Spec_Id : Entity_Id;
22557
22558 begin
22559 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22560
22561 -- Fully analyze the pragma when it appears inside a subprogram
22562 -- body because it cannot benefit from forward references.
22563
22564 if Legal then
22565
22566 -- Chain the pragma on the contract for completeness
22567
22568 Add_Contract_Item (N, Body_Id);
22569
22570 -- The legality checks of pragma Refined_Post are affected by
22571 -- the SPARK mode in effect and the volatility of the context.
22572 -- Analyze all pragmas in a specific order.
22573
22574 Analyze_If_Present (Pragma_SPARK_Mode);
22575 Analyze_If_Present (Pragma_Volatile_Function);
22576 Analyze_Pre_Post_Condition_In_Decl_Part (N);
22577
22578 -- Currently it is not possible to inline pre/postconditions on
22579 -- a subprogram subject to pragma Inline_Always.
22580
22581 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
22582 end if;
22583 end Refined_Post;
22584
22585 -------------------
22586 -- Refined_State --
22587 -------------------
22588
22589 -- pragma Refined_State (REFINEMENT_LIST);
22590
22591 -- REFINEMENT_LIST ::=
22592 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
22593
22594 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
22595
22596 -- CONSTITUENT_LIST ::=
22597 -- null
22598 -- | CONSTITUENT
22599 -- | (CONSTITUENT {, CONSTITUENT})
22600
22601 -- CONSTITUENT ::= object_NAME | state_NAME
22602
22603 -- Characteristics:
22604
22605 -- * Analysis - The annotation undergoes initial checks to verify
22606 -- the legal placement and context. Secondary checks preanalyze the
22607 -- refinement clauses in:
22608
22609 -- Analyze_Refined_State_In_Decl_Part
22610
22611 -- * Expansion - None.
22612
22613 -- * Template - The annotation utilizes the template of the related
22614 -- package body.
22615
22616 -- * Globals - Capture of global references must occur after full
22617 -- analysis.
22618
22619 -- * Instance - The annotation is instantiated automatically when
22620 -- the related generic package body is instantiated.
22621
22622 when Pragma_Refined_State => Refined_State : declare
22623 Pack_Decl : Node_Id;
22624 Spec_Id : Entity_Id;
22625
22626 begin
22627 GNAT_Pragma;
22628 Check_No_Identifiers;
22629 Check_Arg_Count (1);
22630
22631 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
22632
22633 if Nkind (Pack_Decl) /= N_Package_Body then
22634 Pragma_Misplaced;
22635 end if;
22636
22637 Spec_Id := Corresponding_Spec (Pack_Decl);
22638
22639 -- A pragma that applies to a Ghost entity becomes Ghost for the
22640 -- purposes of legality checks and removal of ignored Ghost code.
22641
22642 Mark_Ghost_Pragma (N, Spec_Id);
22643
22644 -- Chain the pragma on the contract for further processing by
22645 -- Analyze_Refined_State_In_Decl_Part.
22646
22647 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
22648
22649 -- The legality checks of pragma Refined_State are affected by the
22650 -- SPARK mode in effect. Analyze all pragmas in a specific order.
22651
22652 Analyze_If_Present (Pragma_SPARK_Mode);
22653
22654 -- State refinement is allowed only when the corresponding package
22655 -- declaration has non-null pragma Abstract_State. Refinement not
22656 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
22657
22658 if SPARK_Mode /= Off
22659 and then
22660 (No (Abstract_States (Spec_Id))
22661 or else Has_Null_Abstract_State (Spec_Id))
22662 then
22663 Error_Msg_NE
22664 ("useless refinement, package & does not define abstract "
22665 & "states", N, Spec_Id);
22666 return;
22667 end if;
22668 end Refined_State;
22669
22670 -----------------------
22671 -- Relative_Deadline --
22672 -----------------------
22673
22674 -- pragma Relative_Deadline (time_span_EXPRESSION);
22675
22676 when Pragma_Relative_Deadline => Relative_Deadline : declare
22677 P : constant Node_Id := Parent (N);
22678 Arg : Node_Id;
22679
22680 begin
22681 Ada_2005_Pragma;
22682 Check_No_Identifiers;
22683 Check_Arg_Count (1);
22684
22685 Arg := Get_Pragma_Arg (Arg1);
22686
22687 -- The expression must be analyzed in the special manner described
22688 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
22689
22690 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
22691
22692 -- Subprogram case
22693
22694 if Nkind (P) = N_Subprogram_Body then
22695 Check_In_Main_Program;
22696
22697 -- Only Task and subprogram cases allowed
22698
22699 elsif Nkind (P) /= N_Task_Definition then
22700 Pragma_Misplaced;
22701 end if;
22702
22703 -- Check duplicate pragma before we set the corresponding flag
22704
22705 if Has_Relative_Deadline_Pragma (P) then
22706 Error_Pragma ("duplicate pragma% not allowed");
22707 end if;
22708
22709 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
22710 -- Relative_Deadline pragma node cannot be inserted in the Rep
22711 -- Item chain of Ent since it is rewritten by the expander as a
22712 -- procedure call statement that will break the chain.
22713
22714 Set_Has_Relative_Deadline_Pragma (P);
22715 end Relative_Deadline;
22716
22717 ------------------------
22718 -- Remote_Access_Type --
22719 ------------------------
22720
22721 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
22722
22723 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
22724 E : Entity_Id;
22725
22726 begin
22727 GNAT_Pragma;
22728 Check_Arg_Count (1);
22729 Check_Optional_Identifier (Arg1, Name_Entity);
22730 Check_Arg_Is_Local_Name (Arg1);
22731
22732 E := Entity (Get_Pragma_Arg (Arg1));
22733
22734 -- A pragma that applies to a Ghost entity becomes Ghost for the
22735 -- purposes of legality checks and removal of ignored Ghost code.
22736
22737 Mark_Ghost_Pragma (N, E);
22738
22739 if Nkind (Parent (E)) = N_Formal_Type_Declaration
22740 and then Ekind (E) = E_General_Access_Type
22741 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
22742 and then Scope (Root_Type (Directly_Designated_Type (E)))
22743 = Scope (E)
22744 and then Is_Valid_Remote_Object_Type
22745 (Root_Type (Directly_Designated_Type (E)))
22746 then
22747 Set_Is_Remote_Types (E);
22748
22749 else
22750 Error_Pragma_Arg
22751 ("pragma% applies only to formal access-to-class-wide types",
22752 Arg1);
22753 end if;
22754 end Remote_Access_Type;
22755
22756 ---------------------------
22757 -- Remote_Call_Interface --
22758 ---------------------------
22759
22760 -- pragma Remote_Call_Interface [(library_unit_NAME)];
22761
22762 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
22763 Cunit_Node : Node_Id;
22764 Cunit_Ent : Entity_Id;
22765 K : Node_Kind;
22766
22767 begin
22768 Check_Ada_83_Warning;
22769 Check_Valid_Library_Unit_Pragma;
22770
22771 -- If N was rewritten as a null statement there is nothing more
22772 -- to do.
22773
22774 if Nkind (N) = N_Null_Statement then
22775 return;
22776 end if;
22777
22778 Cunit_Node := Cunit (Current_Sem_Unit);
22779 K := Nkind (Unit (Cunit_Node));
22780 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22781
22782 -- A pragma that applies to a Ghost entity becomes Ghost for the
22783 -- purposes of legality checks and removal of ignored Ghost code.
22784
22785 Mark_Ghost_Pragma (N, Cunit_Ent);
22786
22787 if K = N_Package_Declaration
22788 or else K = N_Generic_Package_Declaration
22789 or else K = N_Subprogram_Declaration
22790 or else K = N_Generic_Subprogram_Declaration
22791 or else (K = N_Subprogram_Body
22792 and then Acts_As_Spec (Unit (Cunit_Node)))
22793 then
22794 null;
22795 else
22796 Error_Pragma (
22797 "pragma% must apply to package or subprogram declaration");
22798 end if;
22799
22800 Set_Is_Remote_Call_Interface (Cunit_Ent);
22801 end Remote_Call_Interface;
22802
22803 ------------------
22804 -- Remote_Types --
22805 ------------------
22806
22807 -- pragma Remote_Types [(library_unit_NAME)];
22808
22809 when Pragma_Remote_Types => Remote_Types : declare
22810 Cunit_Node : Node_Id;
22811 Cunit_Ent : Entity_Id;
22812
22813 begin
22814 Check_Ada_83_Warning;
22815 Check_Valid_Library_Unit_Pragma;
22816
22817 -- If N was rewritten as a null statement there is nothing more
22818 -- to do.
22819
22820 if Nkind (N) = N_Null_Statement then
22821 return;
22822 end if;
22823
22824 Cunit_Node := Cunit (Current_Sem_Unit);
22825 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22826
22827 -- A pragma that applies to a Ghost entity becomes Ghost for the
22828 -- purposes of legality checks and removal of ignored Ghost code.
22829
22830 Mark_Ghost_Pragma (N, Cunit_Ent);
22831
22832 if Nkind (Unit (Cunit_Node)) not in
22833 N_Package_Declaration | N_Generic_Package_Declaration
22834 then
22835 Error_Pragma
22836 ("pragma% can only apply to a package declaration");
22837 end if;
22838
22839 Set_Is_Remote_Types (Cunit_Ent);
22840 end Remote_Types;
22841
22842 ---------------
22843 -- Ravenscar --
22844 ---------------
22845
22846 -- pragma Ravenscar;
22847
22848 when Pragma_Ravenscar =>
22849 GNAT_Pragma;
22850 Check_Arg_Count (0);
22851 Check_Valid_Configuration_Pragma;
22852 Set_Ravenscar_Profile (Ravenscar, N);
22853
22854 if Warn_On_Obsolescent_Feature then
22855 Error_Msg_N
22856 ("pragma Ravenscar is an obsolescent feature?j?", N);
22857 Error_Msg_N
22858 ("|use pragma Profile (Ravenscar) instead?j?", N);
22859 end if;
22860
22861 -------------------------
22862 -- Restricted_Run_Time --
22863 -------------------------
22864
22865 -- pragma Restricted_Run_Time;
22866
22867 when Pragma_Restricted_Run_Time =>
22868 GNAT_Pragma;
22869 Check_Arg_Count (0);
22870 Check_Valid_Configuration_Pragma;
22871 Set_Profile_Restrictions
22872 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
22873
22874 if Warn_On_Obsolescent_Feature then
22875 Error_Msg_N
22876 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
22877 N);
22878 Error_Msg_N
22879 ("|use pragma Profile (Restricted) instead?j?", N);
22880 end if;
22881
22882 ------------------
22883 -- Restrictions --
22884 ------------------
22885
22886 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
22887
22888 -- RESTRICTION ::=
22889 -- restriction_IDENTIFIER
22890 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22891
22892 when Pragma_Restrictions =>
22893 Process_Restrictions_Or_Restriction_Warnings
22894 (Warn => Treat_Restrictions_As_Warnings);
22895
22896 --------------------------
22897 -- Restriction_Warnings --
22898 --------------------------
22899
22900 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
22901
22902 -- RESTRICTION ::=
22903 -- restriction_IDENTIFIER
22904 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22905
22906 when Pragma_Restriction_Warnings =>
22907 GNAT_Pragma;
22908 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
22909
22910 ----------------
22911 -- Reviewable --
22912 ----------------
22913
22914 -- pragma Reviewable;
22915
22916 when Pragma_Reviewable =>
22917 Check_Ada_83_Warning;
22918 Check_Arg_Count (0);
22919
22920 -- Call dummy debugging function rv. This is done to assist front
22921 -- end debugging. By placing a Reviewable pragma in the source
22922 -- program, a breakpoint on rv catches this place in the source,
22923 -- allowing convenient stepping to the point of interest.
22924
22925 rv;
22926
22927 --------------------------
22928 -- Secondary_Stack_Size --
22929 --------------------------
22930
22931 -- pragma Secondary_Stack_Size (EXPRESSION);
22932
22933 when Pragma_Secondary_Stack_Size => Secondary_Stack_Size : declare
22934 P : constant Node_Id := Parent (N);
22935 Arg : Node_Id;
22936 Ent : Entity_Id;
22937
22938 begin
22939 GNAT_Pragma;
22940 Check_No_Identifiers;
22941 Check_Arg_Count (1);
22942
22943 if Nkind (P) = N_Task_Definition then
22944 Arg := Get_Pragma_Arg (Arg1);
22945 Ent := Defining_Identifier (Parent (P));
22946
22947 -- The expression must be analyzed in the special manner
22948 -- described in "Handling of Default Expressions" in sem.ads.
22949
22950 Preanalyze_Spec_Expression (Arg, Any_Integer);
22951
22952 -- The pragma cannot appear if the No_Secondary_Stack
22953 -- restriction is in effect.
22954
22955 Check_Restriction (No_Secondary_Stack, Arg);
22956
22957 -- Anything else is incorrect
22958
22959 else
22960 Pragma_Misplaced;
22961 end if;
22962
22963 -- Check duplicate pragma before we chain the pragma in the Rep
22964 -- Item chain of Ent.
22965
22966 Check_Duplicate_Pragma (Ent);
22967 Record_Rep_Item (Ent, N);
22968 end Secondary_Stack_Size;
22969
22970 --------------------------
22971 -- Short_Circuit_And_Or --
22972 --------------------------
22973
22974 -- pragma Short_Circuit_And_Or;
22975
22976 when Pragma_Short_Circuit_And_Or =>
22977 GNAT_Pragma;
22978 Check_Arg_Count (0);
22979 Check_Valid_Configuration_Pragma;
22980 Short_Circuit_And_Or := True;
22981
22982 -------------------
22983 -- Share_Generic --
22984 -------------------
22985
22986 -- pragma Share_Generic (GNAME {, GNAME});
22987
22988 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
22989
22990 when Pragma_Share_Generic =>
22991 GNAT_Pragma;
22992 Process_Generic_List;
22993
22994 ------------
22995 -- Shared --
22996 ------------
22997
22998 -- pragma Shared (LOCAL_NAME);
22999
23000 when Pragma_Shared =>
23001 GNAT_Pragma;
23002 Process_Atomic_Independent_Shared_Volatile;
23003
23004 --------------------
23005 -- Shared_Passive --
23006 --------------------
23007
23008 -- pragma Shared_Passive [(library_unit_NAME)];
23009
23010 -- Set the flag Is_Shared_Passive of program unit name entity
23011
23012 when Pragma_Shared_Passive => Shared_Passive : declare
23013 Cunit_Node : Node_Id;
23014 Cunit_Ent : Entity_Id;
23015
23016 begin
23017 Check_Ada_83_Warning;
23018 Check_Valid_Library_Unit_Pragma;
23019
23020 -- If N was rewritten as a null statement there is nothing more
23021 -- to do.
23022
23023 if Nkind (N) = N_Null_Statement then
23024 return;
23025 end if;
23026
23027 Cunit_Node := Cunit (Current_Sem_Unit);
23028 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
23029
23030 -- A pragma that applies to a Ghost entity becomes Ghost for the
23031 -- purposes of legality checks and removal of ignored Ghost code.
23032
23033 Mark_Ghost_Pragma (N, Cunit_Ent);
23034
23035 if Nkind (Unit (Cunit_Node)) not in
23036 N_Package_Declaration | N_Generic_Package_Declaration
23037 then
23038 Error_Pragma
23039 ("pragma% can only apply to a package declaration");
23040 end if;
23041
23042 Set_Is_Shared_Passive (Cunit_Ent);
23043 end Shared_Passive;
23044
23045 -----------------------
23046 -- Short_Descriptors --
23047 -----------------------
23048
23049 -- pragma Short_Descriptors;
23050
23051 -- Recognize and validate, but otherwise ignore
23052
23053 when Pragma_Short_Descriptors =>
23054 GNAT_Pragma;
23055 Check_Arg_Count (0);
23056 Check_Valid_Configuration_Pragma;
23057
23058 ------------------------------
23059 -- Simple_Storage_Pool_Type --
23060 ------------------------------
23061
23062 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
23063
23064 when Pragma_Simple_Storage_Pool_Type =>
23065 Simple_Storage_Pool_Type : declare
23066 Typ : Entity_Id;
23067 Type_Id : Node_Id;
23068
23069 begin
23070 GNAT_Pragma;
23071 Check_Arg_Count (1);
23072 Check_Arg_Is_Library_Level_Local_Name (Arg1);
23073
23074 Type_Id := Get_Pragma_Arg (Arg1);
23075 Find_Type (Type_Id);
23076 Typ := Entity (Type_Id);
23077
23078 if Typ = Any_Type then
23079 return;
23080 end if;
23081
23082 -- A pragma that applies to a Ghost entity becomes Ghost for the
23083 -- purposes of legality checks and removal of ignored Ghost code.
23084
23085 Mark_Ghost_Pragma (N, Typ);
23086
23087 -- We require the pragma to apply to a type declared in a package
23088 -- declaration, but not (immediately) within a package body.
23089
23090 if Ekind (Current_Scope) /= E_Package
23091 or else In_Package_Body (Current_Scope)
23092 then
23093 Error_Pragma
23094 ("pragma% can only apply to type declared immediately "
23095 & "within a package declaration");
23096 end if;
23097
23098 -- A simple storage pool type must be an immutably limited record
23099 -- or private type. If the pragma is given for a private type,
23100 -- the full type is similarly restricted (which is checked later
23101 -- in Freeze_Entity).
23102
23103 if Is_Record_Type (Typ)
23104 and then not Is_Limited_View (Typ)
23105 then
23106 Error_Pragma
23107 ("pragma% can only apply to explicitly limited record type");
23108
23109 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
23110 Error_Pragma
23111 ("pragma% can only apply to a private type that is limited");
23112
23113 elsif not Is_Record_Type (Typ)
23114 and then not Is_Private_Type (Typ)
23115 then
23116 Error_Pragma
23117 ("pragma% can only apply to limited record or private type");
23118 end if;
23119
23120 Record_Rep_Item (Typ, N);
23121 end Simple_Storage_Pool_Type;
23122
23123 ----------------------
23124 -- Source_File_Name --
23125 ----------------------
23126
23127 -- There are five forms for this pragma:
23128
23129 -- pragma Source_File_Name (
23130 -- [UNIT_NAME =>] unit_NAME,
23131 -- BODY_FILE_NAME => STRING_LITERAL
23132 -- [, [INDEX =>] INTEGER_LITERAL]);
23133
23134 -- pragma Source_File_Name (
23135 -- [UNIT_NAME =>] unit_NAME,
23136 -- SPEC_FILE_NAME => STRING_LITERAL
23137 -- [, [INDEX =>] INTEGER_LITERAL]);
23138
23139 -- pragma Source_File_Name (
23140 -- BODY_FILE_NAME => STRING_LITERAL
23141 -- [, DOT_REPLACEMENT => STRING_LITERAL]
23142 -- [, CASING => CASING_SPEC]);
23143
23144 -- pragma Source_File_Name (
23145 -- SPEC_FILE_NAME => STRING_LITERAL
23146 -- [, DOT_REPLACEMENT => STRING_LITERAL]
23147 -- [, CASING => CASING_SPEC]);
23148
23149 -- pragma Source_File_Name (
23150 -- SUBUNIT_FILE_NAME => STRING_LITERAL
23151 -- [, DOT_REPLACEMENT => STRING_LITERAL]
23152 -- [, CASING => CASING_SPEC]);
23153
23154 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
23155
23156 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
23157 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
23158 -- only be used when no project file is used, while SFNP can only be
23159 -- used when a project file is used.
23160
23161 -- No processing here. Processing was completed during parsing, since
23162 -- we need to have file names set as early as possible. Units are
23163 -- loaded well before semantic processing starts.
23164
23165 -- The only processing we defer to this point is the check for
23166 -- correct placement.
23167
23168 when Pragma_Source_File_Name =>
23169 GNAT_Pragma;
23170 Check_Valid_Configuration_Pragma;
23171
23172 ------------------------------
23173 -- Source_File_Name_Project --
23174 ------------------------------
23175
23176 -- See Source_File_Name for syntax
23177
23178 -- No processing here. Processing was completed during parsing, since
23179 -- we need to have file names set as early as possible. Units are
23180 -- loaded well before semantic processing starts.
23181
23182 -- The only processing we defer to this point is the check for
23183 -- correct placement.
23184
23185 when Pragma_Source_File_Name_Project =>
23186 GNAT_Pragma;
23187 Check_Valid_Configuration_Pragma;
23188
23189 -- Check that a pragma Source_File_Name_Project is used only in a
23190 -- configuration pragmas file.
23191
23192 -- Pragmas Source_File_Name_Project should only be generated by
23193 -- the Project Manager in configuration pragmas files.
23194
23195 -- This is really an ugly test. It seems to depend on some
23196 -- accidental and undocumented property. At the very least it
23197 -- needs to be documented, but it would be better to have a
23198 -- clean way of testing if we are in a configuration file???
23199
23200 if Present (Parent (N)) then
23201 Error_Pragma
23202 ("pragma% can only appear in a configuration pragmas file");
23203 end if;
23204
23205 ----------------------
23206 -- Source_Reference --
23207 ----------------------
23208
23209 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
23210
23211 -- Nothing to do, all processing completed in Par.Prag, since we need
23212 -- the information for possible parser messages that are output.
23213
23214 when Pragma_Source_Reference =>
23215 GNAT_Pragma;
23216
23217 ----------------
23218 -- SPARK_Mode --
23219 ----------------
23220
23221 -- pragma SPARK_Mode [(Auto | On | Off)];
23222
23223 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
23224 Mode_Id : SPARK_Mode_Type;
23225
23226 procedure Check_Pragma_Conformance
23227 (Context_Pragma : Node_Id;
23228 Entity : Entity_Id;
23229 Entity_Pragma : Node_Id);
23230 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
23231 -- conformance of pragma N depending the following scenarios:
23232 --
23233 -- If pragma Context_Pragma is not Empty, verify that pragma N is
23234 -- compatible with the pragma Context_Pragma that was inherited
23235 -- from the context:
23236 -- * If the mode of Context_Pragma is ON, then the new mode can
23237 -- be anything.
23238 -- * If the mode of Context_Pragma is OFF, then the only allowed
23239 -- new mode is also OFF. Emit error if this is not the case.
23240 --
23241 -- If Entity is not Empty, verify that pragma N is compatible with
23242 -- pragma Entity_Pragma that belongs to Entity.
23243 -- * If Entity_Pragma is Empty, always issue an error as this
23244 -- corresponds to the case where a previous section of Entity
23245 -- has no SPARK_Mode set.
23246 -- * If the mode of Entity_Pragma is ON, then the new mode can
23247 -- be anything.
23248 -- * If the mode of Entity_Pragma is OFF, then the only allowed
23249 -- new mode is also OFF. Emit error if this is not the case.
23250
23251 procedure Check_Library_Level_Entity (E : Entity_Id);
23252 -- Subsidiary to routines Process_xxx. Verify that the related
23253 -- entity E subject to pragma SPARK_Mode is library-level.
23254
23255 procedure Process_Body (Decl : Node_Id);
23256 -- Verify the legality of pragma SPARK_Mode when it appears as the
23257 -- top of the body declarations of entry, package, protected unit,
23258 -- subprogram or task unit body denoted by Decl.
23259
23260 procedure Process_Overloadable (Decl : Node_Id);
23261 -- Verify the legality of pragma SPARK_Mode when it applies to an
23262 -- entry or [generic] subprogram declaration denoted by Decl.
23263
23264 procedure Process_Private_Part (Decl : Node_Id);
23265 -- Verify the legality of pragma SPARK_Mode when it appears at the
23266 -- top of the private declarations of a package spec, protected or
23267 -- task unit declaration denoted by Decl.
23268
23269 procedure Process_Statement_Part (Decl : Node_Id);
23270 -- Verify the legality of pragma SPARK_Mode when it appears at the
23271 -- top of the statement sequence of a package body denoted by node
23272 -- Decl.
23273
23274 procedure Process_Visible_Part (Decl : Node_Id);
23275 -- Verify the legality of pragma SPARK_Mode when it appears at the
23276 -- top of the visible declarations of a package spec, protected or
23277 -- task unit declaration denoted by Decl. The routine is also used
23278 -- on protected or task units declared without a definition.
23279
23280 procedure Set_SPARK_Context;
23281 -- Subsidiary to routines Process_xxx. Set the global variables
23282 -- which represent the mode of the context from pragma N. Ensure
23283 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
23284
23285 ------------------------------
23286 -- Check_Pragma_Conformance --
23287 ------------------------------
23288
23289 procedure Check_Pragma_Conformance
23290 (Context_Pragma : Node_Id;
23291 Entity : Entity_Id;
23292 Entity_Pragma : Node_Id)
23293 is
23294 Err_Id : Entity_Id;
23295 Err_N : Node_Id;
23296
23297 begin
23298 -- The current pragma may appear without an argument. If this
23299 -- is the case, associate all error messages with the pragma
23300 -- itself.
23301
23302 if Present (Arg1) then
23303 Err_N := Arg1;
23304 else
23305 Err_N := N;
23306 end if;
23307
23308 -- The mode of the current pragma is compared against that of
23309 -- an enclosing context.
23310
23311 if Present (Context_Pragma) then
23312 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
23313
23314 -- Issue an error if the new mode is less restrictive than
23315 -- that of the context.
23316
23317 if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off
23318 and then Get_SPARK_Mode_From_Annotation (N) = On
23319 then
23320 Error_Msg_N
23321 ("cannot change SPARK_Mode from Off to On", Err_N);
23322 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
23323 Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N);
23324 raise Pragma_Exit;
23325 end if;
23326 end if;
23327
23328 -- The mode of the current pragma is compared against that of
23329 -- an initial package, protected type, subprogram or task type
23330 -- declaration.
23331
23332 if Present (Entity) then
23333
23334 -- A simple protected or task type is transformed into an
23335 -- anonymous type whose name cannot be used to issue error
23336 -- messages. Recover the original entity of the type.
23337
23338 if Ekind (Entity) in E_Protected_Type | E_Task_Type then
23339 Err_Id :=
23340 Defining_Entity
23341 (Original_Node (Unit_Declaration_Node (Entity)));
23342 else
23343 Err_Id := Entity;
23344 end if;
23345
23346 -- Both the initial declaration and the completion carry
23347 -- SPARK_Mode pragmas.
23348
23349 if Present (Entity_Pragma) then
23350 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
23351
23352 -- Issue an error if the new mode is less restrictive
23353 -- than that of the initial declaration.
23354
23355 if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off
23356 and then Get_SPARK_Mode_From_Annotation (N) = On
23357 then
23358 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
23359 Error_Msg_Sloc := Sloc (Entity_Pragma);
23360 Error_Msg_NE
23361 ("\value Off was set for SPARK_Mode on&#",
23362 Err_N, Err_Id);
23363 raise Pragma_Exit;
23364 end if;
23365
23366 -- Otherwise the initial declaration lacks a SPARK_Mode
23367 -- pragma in which case the current pragma is illegal as
23368 -- it cannot "complete".
23369
23370 elsif Get_SPARK_Mode_From_Annotation (N) = Off
23371 and then (Is_Generic_Unit (Entity) or else In_Instance)
23372 then
23373 null;
23374
23375 else
23376 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
23377 Error_Msg_Sloc := Sloc (Err_Id);
23378 Error_Msg_NE
23379 ("\no value was set for SPARK_Mode on&#",
23380 Err_N, Err_Id);
23381 raise Pragma_Exit;
23382 end if;
23383 end if;
23384 end Check_Pragma_Conformance;
23385
23386 --------------------------------
23387 -- Check_Library_Level_Entity --
23388 --------------------------------
23389
23390 procedure Check_Library_Level_Entity (E : Entity_Id) is
23391 procedure Add_Entity_To_Name_Buffer;
23392 -- Add the E_Kind of entity E to the name buffer
23393
23394 -------------------------------
23395 -- Add_Entity_To_Name_Buffer --
23396 -------------------------------
23397
23398 procedure Add_Entity_To_Name_Buffer is
23399 begin
23400 if Ekind (E) in E_Entry | E_Entry_Family then
23401 Add_Str_To_Name_Buffer ("entry");
23402
23403 elsif Ekind (E) in E_Generic_Package
23404 | E_Package
23405 | E_Package_Body
23406 then
23407 Add_Str_To_Name_Buffer ("package");
23408
23409 elsif Ekind (E) in E_Protected_Body | E_Protected_Type then
23410 Add_Str_To_Name_Buffer ("protected type");
23411
23412 elsif Ekind (E) in E_Function
23413 | E_Generic_Function
23414 | E_Generic_Procedure
23415 | E_Procedure
23416 | E_Subprogram_Body
23417 then
23418 Add_Str_To_Name_Buffer ("subprogram");
23419
23420 else
23421 pragma Assert (Ekind (E) in E_Task_Body | E_Task_Type);
23422 Add_Str_To_Name_Buffer ("task type");
23423 end if;
23424 end Add_Entity_To_Name_Buffer;
23425
23426 -- Local variables
23427
23428 Msg_1 : constant String := "incorrect placement of pragma%";
23429 Msg_2 : Name_Id;
23430
23431 -- Start of processing for Check_Library_Level_Entity
23432
23433 begin
23434 -- A SPARK_Mode of On shall only apply to library-level
23435 -- entities, except for those in generic instances, which are
23436 -- ignored (even if the entity gets SPARK_Mode pragma attached
23437 -- in the AST, its effect is not taken into account unless the
23438 -- context already provides SPARK_Mode of On in GNATprove).
23439
23440 if Get_SPARK_Mode_From_Annotation (N) = On
23441 and then not Is_Library_Level_Entity (E)
23442 and then Instantiation_Location (Sloc (N)) = No_Location
23443 then
23444 Error_Msg_Name_1 := Pname;
23445 Error_Msg_N (Fix_Error (Msg_1), N);
23446
23447 Name_Len := 0;
23448 Add_Str_To_Name_Buffer ("\& is not a library-level ");
23449 Add_Entity_To_Name_Buffer;
23450
23451 Msg_2 := Name_Find;
23452 Error_Msg_NE (Get_Name_String (Msg_2), N, E);
23453
23454 raise Pragma_Exit;
23455 end if;
23456 end Check_Library_Level_Entity;
23457
23458 ------------------
23459 -- Process_Body --
23460 ------------------
23461
23462 procedure Process_Body (Decl : Node_Id) is
23463 Body_Id : constant Entity_Id := Defining_Entity (Decl);
23464 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
23465
23466 begin
23467 -- Ignore pragma when applied to the special body created
23468 -- for inlining, recognized by its internal name _Parent; or
23469 -- when applied to the special body created for contracts,
23470 -- recognized by its internal name _Wrapped_Statements.
23471
23472 if Chars (Body_Id) in Name_uParent
23473 | Name_uWrapped_Statements
23474 then
23475 return;
23476 end if;
23477
23478 Check_Library_Level_Entity (Body_Id);
23479
23480 -- For entry bodies, verify the legality against:
23481 -- * The mode of the context
23482 -- * The mode of the spec (if any)
23483
23484 if Nkind (Decl) in N_Entry_Body | N_Subprogram_Body then
23485
23486 -- A stand-alone subprogram body
23487
23488 if Body_Id = Spec_Id then
23489 Check_Pragma_Conformance
23490 (Context_Pragma => SPARK_Pragma (Body_Id),
23491 Entity => Empty,
23492 Entity_Pragma => Empty);
23493
23494 -- An entry or subprogram body that completes a previous
23495 -- declaration.
23496
23497 else
23498 Check_Pragma_Conformance
23499 (Context_Pragma => SPARK_Pragma (Body_Id),
23500 Entity => Spec_Id,
23501 Entity_Pragma => SPARK_Pragma (Spec_Id));
23502 end if;
23503
23504 Set_SPARK_Context;
23505 Set_SPARK_Pragma (Body_Id, N);
23506 Set_SPARK_Pragma_Inherited (Body_Id, False);
23507
23508 -- For package bodies, verify the legality against:
23509 -- * The mode of the context
23510 -- * The mode of the private part
23511
23512 -- This case is separated from protected and task bodies
23513 -- because the statement part of the package body inherits
23514 -- the mode of the body declarations.
23515
23516 elsif Nkind (Decl) = N_Package_Body then
23517 Check_Pragma_Conformance
23518 (Context_Pragma => SPARK_Pragma (Body_Id),
23519 Entity => Spec_Id,
23520 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
23521
23522 Set_SPARK_Context;
23523 Set_SPARK_Pragma (Body_Id, N);
23524 Set_SPARK_Pragma_Inherited (Body_Id, False);
23525 Set_SPARK_Aux_Pragma (Body_Id, N);
23526 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
23527
23528 -- For protected and task bodies, verify the legality against:
23529 -- * The mode of the context
23530 -- * The mode of the private part
23531
23532 else
23533 pragma Assert
23534 (Nkind (Decl) in N_Protected_Body | N_Task_Body);
23535
23536 Check_Pragma_Conformance
23537 (Context_Pragma => SPARK_Pragma (Body_Id),
23538 Entity => Spec_Id,
23539 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
23540
23541 Set_SPARK_Context;
23542 Set_SPARK_Pragma (Body_Id, N);
23543 Set_SPARK_Pragma_Inherited (Body_Id, False);
23544 end if;
23545 end Process_Body;
23546
23547 --------------------------
23548 -- Process_Overloadable --
23549 --------------------------
23550
23551 procedure Process_Overloadable (Decl : Node_Id) is
23552 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23553 Spec_Typ : constant Entity_Id := Etype (Spec_Id);
23554
23555 begin
23556 Check_Library_Level_Entity (Spec_Id);
23557
23558 -- Verify the legality against:
23559 -- * The mode of the context
23560
23561 Check_Pragma_Conformance
23562 (Context_Pragma => SPARK_Pragma (Spec_Id),
23563 Entity => Empty,
23564 Entity_Pragma => Empty);
23565
23566 Set_SPARK_Pragma (Spec_Id, N);
23567 Set_SPARK_Pragma_Inherited (Spec_Id, False);
23568
23569 -- When the pragma applies to the anonymous object created for
23570 -- a single task type, decorate the type as well. This scenario
23571 -- arises when the single task type lacks a task definition,
23572 -- therefore there is no issue with respect to a potential
23573 -- pragma SPARK_Mode in the private part.
23574
23575 -- task type Anon_Task_Typ;
23576 -- Obj : Anon_Task_Typ;
23577 -- pragma SPARK_Mode ...;
23578
23579 if Is_Single_Task_Object (Spec_Id) then
23580 Set_SPARK_Pragma (Spec_Typ, N);
23581 Set_SPARK_Pragma_Inherited (Spec_Typ, False);
23582 Set_SPARK_Aux_Pragma (Spec_Typ, N);
23583 Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True);
23584 end if;
23585 end Process_Overloadable;
23586
23587 --------------------------
23588 -- Process_Private_Part --
23589 --------------------------
23590
23591 procedure Process_Private_Part (Decl : Node_Id) is
23592 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23593
23594 begin
23595 Check_Library_Level_Entity (Spec_Id);
23596
23597 -- Verify the legality against:
23598 -- * The mode of the visible declarations
23599
23600 Check_Pragma_Conformance
23601 (Context_Pragma => Empty,
23602 Entity => Spec_Id,
23603 Entity_Pragma => SPARK_Pragma (Spec_Id));
23604
23605 Set_SPARK_Context;
23606 Set_SPARK_Aux_Pragma (Spec_Id, N);
23607 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
23608 end Process_Private_Part;
23609
23610 ----------------------------
23611 -- Process_Statement_Part --
23612 ----------------------------
23613
23614 procedure Process_Statement_Part (Decl : Node_Id) is
23615 Body_Id : constant Entity_Id := Defining_Entity (Decl);
23616
23617 begin
23618 Check_Library_Level_Entity (Body_Id);
23619
23620 -- Verify the legality against:
23621 -- * The mode of the body declarations
23622
23623 Check_Pragma_Conformance
23624 (Context_Pragma => Empty,
23625 Entity => Body_Id,
23626 Entity_Pragma => SPARK_Pragma (Body_Id));
23627
23628 Set_SPARK_Context;
23629 Set_SPARK_Aux_Pragma (Body_Id, N);
23630 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
23631 end Process_Statement_Part;
23632
23633 --------------------------
23634 -- Process_Visible_Part --
23635 --------------------------
23636
23637 procedure Process_Visible_Part (Decl : Node_Id) is
23638 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23639 Obj_Id : Entity_Id;
23640
23641 begin
23642 Check_Library_Level_Entity (Spec_Id);
23643
23644 -- Verify the legality against:
23645 -- * The mode of the context
23646
23647 Check_Pragma_Conformance
23648 (Context_Pragma => SPARK_Pragma (Spec_Id),
23649 Entity => Empty,
23650 Entity_Pragma => Empty);
23651
23652 -- A task unit declared without a definition does not set the
23653 -- SPARK_Mode of the context because the task does not have any
23654 -- entries that could inherit the mode.
23655
23656 if Nkind (Decl) not in
23657 N_Single_Task_Declaration | N_Task_Type_Declaration
23658 then
23659 Set_SPARK_Context;
23660 end if;
23661
23662 Set_SPARK_Pragma (Spec_Id, N);
23663 Set_SPARK_Pragma_Inherited (Spec_Id, False);
23664 Set_SPARK_Aux_Pragma (Spec_Id, N);
23665 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
23666
23667 -- When the pragma applies to a single protected or task type,
23668 -- decorate the corresponding anonymous object as well.
23669
23670 -- protected Anon_Prot_Typ is
23671 -- pragma SPARK_Mode ...;
23672 -- ...
23673 -- end Anon_Prot_Typ;
23674
23675 -- Obj : Anon_Prot_Typ;
23676
23677 if Is_Single_Concurrent_Type (Spec_Id) then
23678 Obj_Id := Anonymous_Object (Spec_Id);
23679
23680 Set_SPARK_Pragma (Obj_Id, N);
23681 Set_SPARK_Pragma_Inherited (Obj_Id, False);
23682 end if;
23683 end Process_Visible_Part;
23684
23685 -----------------------
23686 -- Set_SPARK_Context --
23687 -----------------------
23688
23689 procedure Set_SPARK_Context is
23690 begin
23691 SPARK_Mode := Mode_Id;
23692 SPARK_Mode_Pragma := N;
23693 end Set_SPARK_Context;
23694
23695 -- Local variables
23696
23697 Context : Node_Id;
23698 Mode : Name_Id;
23699 Stmt : Node_Id;
23700
23701 -- Start of processing for Do_SPARK_Mode
23702
23703 begin
23704 GNAT_Pragma;
23705 Check_No_Identifiers;
23706 Check_At_Most_N_Arguments (1);
23707
23708 -- Check the legality of the mode (no argument = ON)
23709
23710 if Arg_Count = 1 then
23711 Check_Arg_Is_One_Of (Arg1, Name_Auto, Name_On, Name_Off);
23712 Mode := Chars (Get_Pragma_Arg (Arg1));
23713 else
23714 Mode := Name_On;
23715 end if;
23716
23717 Mode_Id := Get_SPARK_Mode_Type (Mode);
23718 Context := Parent (N);
23719
23720 -- When a SPARK_Mode pragma appears inside an instantiation whose
23721 -- enclosing context has SPARK_Mode set to "off", the pragma has
23722 -- no semantic effect.
23723
23724 if Ignore_SPARK_Mode_Pragmas_In_Instance
23725 and then Mode_Id /= Off
23726 then
23727 Rewrite (N, Make_Null_Statement (Loc));
23728 Analyze (N);
23729 return;
23730 end if;
23731
23732 -- The pragma appears in a configuration file
23733
23734 if No (Context) then
23735 Check_Valid_Configuration_Pragma;
23736
23737 if Present (SPARK_Mode_Pragma) then
23738 Duplication_Error
23739 (Prag => N,
23740 Prev => SPARK_Mode_Pragma);
23741 raise Pragma_Exit;
23742 end if;
23743
23744 Set_SPARK_Context;
23745
23746 -- The pragma acts as a configuration pragma in a compilation unit
23747
23748 -- pragma SPARK_Mode ...;
23749 -- package Pack is ...;
23750
23751 elsif Nkind (Context) = N_Compilation_Unit
23752 and then List_Containing (N) = Context_Items (Context)
23753 then
23754 Check_Valid_Configuration_Pragma;
23755 Set_SPARK_Context;
23756
23757 -- Otherwise the placement of the pragma within the tree dictates
23758 -- its associated construct. Inspect the declarative list where
23759 -- the pragma resides to find a potential construct.
23760
23761 else
23762 -- An explicit mode of Auto is only allowed as a configuration
23763 -- pragma. Escape "pragma" to avoid replacement with "aspect".
23764
23765 if Mode_Id = None then
23766 Error_Pragma_Arg
23767 ("only configuration 'p'r'a'g'm'a% can have value &",
23768 Arg1);
23769 end if;
23770
23771 Stmt := Prev (N);
23772 while Present (Stmt) loop
23773
23774 -- Skip prior pragmas, but check for duplicates. Note that
23775 -- this also takes care of pragmas generated for aspects.
23776
23777 if Nkind (Stmt) = N_Pragma then
23778 if Pragma_Name (Stmt) = Pname then
23779 Duplication_Error
23780 (Prag => N,
23781 Prev => Stmt);
23782 raise Pragma_Exit;
23783 end if;
23784
23785 -- The pragma applies to an expression function that has
23786 -- already been rewritten into a subprogram declaration.
23787
23788 -- function Expr_Func return ... is (...);
23789 -- pragma SPARK_Mode ...;
23790
23791 elsif Nkind (Stmt) = N_Subprogram_Declaration
23792 and then Nkind (Original_Node (Stmt)) =
23793 N_Expression_Function
23794 then
23795 Process_Overloadable (Stmt);
23796 return;
23797
23798 -- The pragma applies to the anonymous object created for a
23799 -- single concurrent type.
23800
23801 -- protected type Anon_Prot_Typ ...;
23802 -- Obj : Anon_Prot_Typ;
23803 -- pragma SPARK_Mode ...;
23804
23805 elsif Nkind (Stmt) = N_Object_Declaration
23806 and then Is_Single_Concurrent_Object
23807 (Defining_Entity (Stmt))
23808 then
23809 Process_Overloadable (Stmt);
23810 return;
23811
23812 -- Skip internally generated code
23813
23814 elsif not Comes_From_Source (Stmt) then
23815 null;
23816
23817 -- The pragma applies to an entry or [generic] subprogram
23818 -- declaration.
23819
23820 -- entry Ent ...;
23821 -- pragma SPARK_Mode ...;
23822
23823 -- [generic]
23824 -- procedure Proc ...;
23825 -- pragma SPARK_Mode ...;
23826
23827 elsif Nkind (Stmt) in N_Generic_Subprogram_Declaration
23828 | N_Subprogram_Declaration
23829 or else (Nkind (Stmt) = N_Entry_Declaration
23830 and then Is_Protected_Type
23831 (Scope (Defining_Entity (Stmt))))
23832 then
23833 Process_Overloadable (Stmt);
23834 return;
23835
23836 -- Otherwise the pragma does not apply to a legal construct
23837 -- or it does not appear at the top of a declarative or a
23838 -- statement list. Issue an error and stop the analysis.
23839
23840 else
23841 Pragma_Misplaced;
23842 end if;
23843
23844 Prev (Stmt);
23845 end loop;
23846
23847 -- The pragma applies to a package or a subprogram that acts as
23848 -- a compilation unit.
23849
23850 -- procedure Proc ...;
23851 -- pragma SPARK_Mode ...;
23852
23853 if Nkind (Context) = N_Compilation_Unit_Aux then
23854 Context := Unit (Parent (Context));
23855 end if;
23856
23857 -- The pragma appears at the top of entry, package, protected
23858 -- unit, subprogram or task unit body declarations.
23859
23860 -- entry Ent when ... is
23861 -- pragma SPARK_Mode ...;
23862
23863 -- package body Pack is
23864 -- pragma SPARK_Mode ...;
23865
23866 -- procedure Proc ... is
23867 -- pragma SPARK_Mode;
23868
23869 -- protected body Prot is
23870 -- pragma SPARK_Mode ...;
23871
23872 if Nkind (Context) in N_Entry_Body
23873 | N_Package_Body
23874 | N_Protected_Body
23875 | N_Subprogram_Body
23876 | N_Task_Body
23877 then
23878 Process_Body (Context);
23879
23880 -- The pragma appears at the top of the visible or private
23881 -- declaration of a package spec, protected or task unit.
23882
23883 -- package Pack is
23884 -- pragma SPARK_Mode ...;
23885 -- private
23886 -- pragma SPARK_Mode ...;
23887
23888 -- protected [type] Prot is
23889 -- pragma SPARK_Mode ...;
23890 -- private
23891 -- pragma SPARK_Mode ...;
23892
23893 elsif Nkind (Context) in N_Package_Specification
23894 | N_Protected_Definition
23895 | N_Task_Definition
23896 then
23897 if List_Containing (N) = Visible_Declarations (Context) then
23898 Process_Visible_Part (Parent (Context));
23899 else
23900 Process_Private_Part (Parent (Context));
23901 end if;
23902
23903 -- The pragma appears at the top of package body statements
23904
23905 -- package body Pack is
23906 -- begin
23907 -- pragma SPARK_Mode;
23908
23909 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
23910 and then Nkind (Parent (Context)) = N_Package_Body
23911 then
23912 Process_Statement_Part (Parent (Context));
23913
23914 -- The pragma appeared as an aspect of a [generic] subprogram
23915 -- declaration that acts as a compilation unit.
23916
23917 -- [generic]
23918 -- procedure Proc ...;
23919 -- pragma SPARK_Mode ...;
23920
23921 elsif Nkind (Context) in N_Generic_Subprogram_Declaration
23922 | N_Subprogram_Declaration
23923 then
23924 Process_Overloadable (Context);
23925
23926 -- The pragma does not apply to a legal construct, issue error
23927
23928 else
23929 Pragma_Misplaced;
23930 end if;
23931 end if;
23932 end Do_SPARK_Mode;
23933
23934 --------------------------------
23935 -- Static_Elaboration_Desired --
23936 --------------------------------
23937
23938 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
23939
23940 when Pragma_Static_Elaboration_Desired =>
23941 GNAT_Pragma;
23942 Check_At_Most_N_Arguments (1);
23943
23944 if Is_Compilation_Unit (Current_Scope)
23945 and then Ekind (Current_Scope) = E_Package
23946 then
23947 Set_Static_Elaboration_Desired (Current_Scope, True);
23948 else
23949 Error_Pragma ("pragma% must apply to a library-level package");
23950 end if;
23951
23952 ------------------
23953 -- Storage_Size --
23954 ------------------
23955
23956 -- pragma Storage_Size (EXPRESSION);
23957
23958 when Pragma_Storage_Size => Storage_Size : declare
23959 P : constant Node_Id := Parent (N);
23960 Arg : Node_Id;
23961
23962 begin
23963 Check_No_Identifiers;
23964 Check_Arg_Count (1);
23965
23966 -- The expression must be analyzed in the special manner described
23967 -- in "Handling of Default Expressions" in sem.ads.
23968
23969 Arg := Get_Pragma_Arg (Arg1);
23970 Preanalyze_Spec_Expression (Arg, Any_Integer);
23971
23972 if not Is_OK_Static_Expression (Arg) then
23973 Check_Restriction (Static_Storage_Size, Arg);
23974 end if;
23975
23976 if Nkind (P) /= N_Task_Definition then
23977 Pragma_Misplaced;
23978
23979 else
23980 if Has_Storage_Size_Pragma (P) then
23981 Error_Pragma ("duplicate pragma% not allowed");
23982 else
23983 Set_Has_Storage_Size_Pragma (P, True);
23984 end if;
23985
23986 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
23987 end if;
23988 end Storage_Size;
23989
23990 ------------------
23991 -- Storage_Unit --
23992 ------------------
23993
23994 -- pragma Storage_Unit (NUMERIC_LITERAL);
23995
23996 -- Only permitted argument is System'Storage_Unit value
23997
23998 when Pragma_Storage_Unit =>
23999 Check_No_Identifiers;
24000 Check_Arg_Count (1);
24001 Check_Arg_Is_Integer_Literal (Arg1);
24002
24003 if Intval (Get_Pragma_Arg (Arg1)) /=
24004 UI_From_Int (Ttypes.System_Storage_Unit)
24005 then
24006 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
24007 Error_Pragma_Arg
24008 ("the only allowed argument for pragma% is ^", Arg1);
24009 end if;
24010
24011 --------------------
24012 -- Stream_Convert --
24013 --------------------
24014
24015 -- pragma Stream_Convert (
24016 -- [Entity =>] type_LOCAL_NAME,
24017 -- [Read =>] function_NAME,
24018 -- [Write =>] function NAME);
24019
24020 when Pragma_Stream_Convert => Stream_Convert : declare
24021 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
24022 -- Check that the given argument is the name of a local function
24023 -- of one argument that is not overloaded earlier in the current
24024 -- local scope. A check is also made that the argument is a
24025 -- function with one parameter.
24026
24027 --------------------------------------
24028 -- Check_OK_Stream_Convert_Function --
24029 --------------------------------------
24030
24031 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
24032 Ent : Entity_Id;
24033
24034 begin
24035 Check_Arg_Is_Local_Name (Arg);
24036 Ent := Entity (Get_Pragma_Arg (Arg));
24037
24038 if Has_Homonym (Ent) then
24039 Error_Pragma_Arg
24040 ("argument for pragma% may not be overloaded", Arg);
24041 end if;
24042
24043 if Ekind (Ent) /= E_Function
24044 or else No (First_Formal (Ent))
24045 or else Present (Next_Formal (First_Formal (Ent)))
24046 then
24047 Error_Pragma_Arg
24048 ("argument for pragma% must be function of one argument",
24049 Arg);
24050 elsif Is_Abstract_Subprogram (Ent) then
24051 Error_Pragma_Arg
24052 ("argument for pragma% cannot be abstract", Arg);
24053 end if;
24054 end Check_OK_Stream_Convert_Function;
24055
24056 -- Start of processing for Stream_Convert
24057
24058 begin
24059 GNAT_Pragma;
24060 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
24061 Check_Arg_Count (3);
24062 Check_Optional_Identifier (Arg1, Name_Entity);
24063 Check_Optional_Identifier (Arg2, Name_Read);
24064 Check_Optional_Identifier (Arg3, Name_Write);
24065 Check_Arg_Is_Local_Name (Arg1);
24066 Check_OK_Stream_Convert_Function (Arg2);
24067 Check_OK_Stream_Convert_Function (Arg3);
24068
24069 declare
24070 Typ : constant Entity_Id :=
24071 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
24072 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
24073 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
24074
24075 begin
24076 Check_First_Subtype (Arg1);
24077
24078 -- Check for too early or too late. Note that we don't enforce
24079 -- the rule about primitive operations in this case, since, as
24080 -- is the case for explicit stream attributes themselves, these
24081 -- restrictions are not appropriate. Note that the chaining of
24082 -- the pragma by Rep_Item_Too_Late is actually the critical
24083 -- processing done for this pragma.
24084
24085 if Rep_Item_Too_Early (Typ, N)
24086 or else
24087 Rep_Item_Too_Late (Typ, N, FOnly => True)
24088 then
24089 return;
24090 end if;
24091
24092 -- Return if previous error
24093
24094 if Etype (Typ) = Any_Type
24095 or else
24096 Etype (Read) = Any_Type
24097 or else
24098 Etype (Write) = Any_Type
24099 then
24100 return;
24101 end if;
24102
24103 -- Error checks
24104
24105 if Underlying_Type (Etype (Read)) /= Typ then
24106 Error_Pragma_Arg
24107 ("incorrect return type for function&", Arg2);
24108 end if;
24109
24110 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
24111 Error_Pragma_Arg
24112 ("incorrect parameter type for function&", Arg3);
24113 end if;
24114
24115 if Underlying_Type (Etype (First_Formal (Read))) /=
24116 Underlying_Type (Etype (Write))
24117 then
24118 Error_Pragma_Arg
24119 ("result type of & does not match Read parameter type",
24120 Arg3);
24121 end if;
24122 end;
24123 end Stream_Convert;
24124
24125 ------------------
24126 -- Style_Checks --
24127 ------------------
24128
24129 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
24130
24131 -- This is processed by the parser since some of the style checks
24132 -- take place during source scanning and parsing. This means that
24133 -- we don't need to issue error messages here.
24134
24135 when Pragma_Style_Checks => Style_Checks : declare
24136 A : constant Node_Id := Get_Pragma_Arg (Arg1);
24137 S : String_Id;
24138 C : Char_Code;
24139
24140 begin
24141 GNAT_Pragma;
24142 Check_No_Identifiers;
24143
24144 -- Two argument form
24145
24146 if Arg_Count = 2 then
24147 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
24148
24149 declare
24150 E_Id : Node_Id;
24151 E : Entity_Id;
24152
24153 begin
24154 E_Id := Get_Pragma_Arg (Arg2);
24155 Analyze (E_Id);
24156
24157 if not Is_Entity_Name (E_Id) then
24158 Error_Pragma_Arg
24159 ("second argument of pragma% must be entity name",
24160 Arg2);
24161 end if;
24162
24163 E := Entity (E_Id);
24164
24165 if not Ignore_Style_Checks_Pragmas then
24166 if E = Any_Id then
24167 return;
24168 else
24169 loop
24170 Set_Suppress_Style_Checks
24171 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
24172 exit when No (Homonym (E));
24173 E := Homonym (E);
24174 end loop;
24175 end if;
24176 end if;
24177 end;
24178
24179 -- One argument form
24180
24181 else
24182 Check_Arg_Count (1);
24183
24184 if Nkind (A) = N_String_Literal then
24185 S := Strval (A);
24186
24187 declare
24188 Slen : constant Natural := Natural (String_Length (S));
24189 Options : String (1 .. Slen);
24190 J : Positive;
24191
24192 begin
24193 J := 1;
24194 loop
24195 C := Get_String_Char (S, Pos (J));
24196 exit when not In_Character_Range (C);
24197 Options (J) := Get_Character (C);
24198
24199 -- If at end of string, set options. As per discussion
24200 -- above, no need to check for errors, since we issued
24201 -- them in the parser.
24202
24203 if J = Slen then
24204 if not Ignore_Style_Checks_Pragmas then
24205 Set_Style_Check_Options (Options);
24206 end if;
24207
24208 exit;
24209 end if;
24210
24211 J := J + 1;
24212 end loop;
24213 end;
24214
24215 elsif Nkind (A) = N_Identifier then
24216 if Chars (A) = Name_All_Checks then
24217 if not Ignore_Style_Checks_Pragmas then
24218 if GNAT_Mode then
24219 Set_GNAT_Style_Check_Options;
24220 else
24221 Set_Default_Style_Check_Options;
24222 end if;
24223 end if;
24224
24225 elsif Chars (A) = Name_On then
24226 if not Ignore_Style_Checks_Pragmas then
24227 Style_Check := True;
24228 end if;
24229
24230 elsif Chars (A) = Name_Off then
24231 if not Ignore_Style_Checks_Pragmas then
24232 Style_Check := False;
24233 end if;
24234 end if;
24235 end if;
24236 end if;
24237 end Style_Checks;
24238
24239 ------------------------
24240 -- Subprogram_Variant --
24241 ------------------------
24242
24243 -- pragma Subprogram_Variant ( SUBPROGRAM_VARIANT_LIST );
24244
24245 -- SUBPROGRAM_VARIANT_LIST ::= STRUCTURAL_SUBPROGRAM_VARIANT_ITEM
24246 -- | NUMERIC_SUBPROGRAM_VARIANT_ITEMS
24247 -- NUMERIC_SUBPROGRAM_VARIANT_ITEMS ::=
24248 -- NUMERIC_SUBPROGRAM_VARIANT_ITEM
24249 -- {, NUMERIC_SUBPROGRAM_VARIANT_ITEM}
24250 -- NUMERIC_SUBPROGRAM_VARIANT_ITEM ::= CHANGE_DIRECTION => EXPRESSION
24251 -- STRUCTURAL_SUBPROGRAM_VARIANT_ITEM ::= Structural => EXPRESSION
24252 -- CHANGE_DIRECTION ::= Increases | Decreases
24253
24254 -- Characteristics:
24255
24256 -- * Analysis - The annotation undergoes initial checks to verify
24257 -- the legal placement and context. Secondary checks preanalyze the
24258 -- expressions in:
24259
24260 -- Analyze_Subprogram_Variant_In_Decl_Part
24261
24262 -- * Expansion - The annotation is expanded during the expansion of
24263 -- the related subprogram [body] contract as performed in:
24264
24265 -- Expand_Subprogram_Contract
24266
24267 -- * Template - The annotation utilizes the generic template of the
24268 -- related subprogram [body] when it is:
24269
24270 -- aspect on subprogram declaration
24271 -- aspect on stand-alone subprogram body
24272 -- pragma on stand-alone subprogram body
24273
24274 -- The annotation must prepare its own template when it is:
24275
24276 -- pragma on subprogram declaration
24277
24278 -- * Globals - Capture of global references must occur after full
24279 -- analysis.
24280
24281 -- * Instance - The annotation is instantiated automatically when
24282 -- the related generic subprogram [body] is instantiated except for
24283 -- the "pragma on subprogram declaration" case. In that scenario
24284 -- the annotation must instantiate itself.
24285
24286 when Pragma_Subprogram_Variant => Subprogram_Variant : declare
24287 Spec_Id : Entity_Id;
24288 Subp_Decl : Node_Id;
24289 Subp_Spec : Node_Id;
24290
24291 begin
24292 GNAT_Pragma;
24293 Check_No_Identifiers;
24294 Check_Arg_Count (1);
24295
24296 -- Ensure the proper placement of the pragma. Subprogram_Variant
24297 -- must be associated with a subprogram declaration or a body that
24298 -- acts as a spec.
24299
24300 Subp_Decl :=
24301 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
24302
24303 -- Generic subprogram
24304
24305 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
24306 null;
24307
24308 -- Body acts as spec
24309
24310 elsif Nkind (Subp_Decl) = N_Subprogram_Body
24311 and then No (Corresponding_Spec (Subp_Decl))
24312 then
24313 null;
24314
24315 -- Body stub acts as spec
24316
24317 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
24318 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
24319 then
24320 null;
24321
24322 -- Subprogram
24323
24324 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
24325 Subp_Spec := Specification (Subp_Decl);
24326
24327 -- Pragma Subprogram_Variant is forbidden on null procedures,
24328 -- as this may lead to potential ambiguities in behavior when
24329 -- interface null procedures are involved. Also, it just
24330 -- wouldn't make sense, because null procedure is not
24331 -- recursive.
24332
24333 if Nkind (Subp_Spec) = N_Procedure_Specification
24334 and then Null_Present (Subp_Spec)
24335 then
24336 Error_Msg_N (Fix_Error
24337 ("pragma % cannot apply to null procedure"), N);
24338 return;
24339 end if;
24340
24341 else
24342 Pragma_Misplaced;
24343 end if;
24344
24345 Spec_Id := Unique_Defining_Entity (Subp_Decl);
24346
24347 -- A pragma that applies to a Ghost entity becomes Ghost for the
24348 -- purposes of legality checks and removal of ignored Ghost code.
24349
24350 Mark_Ghost_Pragma (N, Spec_Id);
24351 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
24352
24353 -- Chain the pragma on the contract for further processing by
24354 -- Analyze_Subprogram_Variant_In_Decl_Part.
24355
24356 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
24357
24358 -- Fully analyze the pragma when it appears inside a subprogram
24359 -- body because it cannot benefit from forward references.
24360
24361 if Nkind (Subp_Decl) in N_Subprogram_Body
24362 | N_Subprogram_Body_Stub
24363 then
24364 -- The legality checks of pragma Subprogram_Variant are
24365 -- affected by the SPARK mode in effect and the volatility
24366 -- of the context. Analyze all pragmas in a specific order.
24367
24368 Analyze_If_Present (Pragma_SPARK_Mode);
24369 Analyze_If_Present (Pragma_Volatile_Function);
24370 Analyze_Subprogram_Variant_In_Decl_Part (N);
24371 end if;
24372 end Subprogram_Variant;
24373
24374 --------------
24375 -- Subtitle --
24376 --------------
24377
24378 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
24379
24380 when Pragma_Subtitle =>
24381 GNAT_Pragma;
24382 Check_Arg_Count (1);
24383 Check_Optional_Identifier (Arg1, Name_Subtitle);
24384 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
24385 Store_Note (N);
24386
24387 --------------
24388 -- Suppress --
24389 --------------
24390
24391 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
24392
24393 when Pragma_Suppress =>
24394 Process_Suppress_Unsuppress (Suppress_Case => True);
24395
24396 ------------------
24397 -- Suppress_All --
24398 ------------------
24399
24400 -- pragma Suppress_All;
24401
24402 -- The only check made here is that the pragma has no arguments.
24403 -- There are no placement rules, and the processing required (setting
24404 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
24405 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
24406 -- then creates and inserts a pragma Suppress (All_Checks).
24407
24408 when Pragma_Suppress_All =>
24409 GNAT_Pragma;
24410 Check_Arg_Count (0);
24411
24412 -------------------------
24413 -- Suppress_Debug_Info --
24414 -------------------------
24415
24416 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
24417
24418 when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare
24419 Nam_Id : Entity_Id;
24420
24421 begin
24422 GNAT_Pragma;
24423 Check_Arg_Count (1);
24424 Check_Optional_Identifier (Arg1, Name_Entity);
24425 Check_Arg_Is_Local_Name (Arg1);
24426
24427 Nam_Id := Entity (Get_Pragma_Arg (Arg1));
24428
24429 -- A pragma that applies to a Ghost entity becomes Ghost for the
24430 -- purposes of legality checks and removal of ignored Ghost code.
24431
24432 Mark_Ghost_Pragma (N, Nam_Id);
24433 Set_Debug_Info_Off (Nam_Id);
24434 end Suppress_Debug_Info;
24435
24436 ----------------------------------
24437 -- Suppress_Exception_Locations --
24438 ----------------------------------
24439
24440 -- pragma Suppress_Exception_Locations;
24441
24442 when Pragma_Suppress_Exception_Locations =>
24443 GNAT_Pragma;
24444 Check_Arg_Count (0);
24445 Check_Valid_Configuration_Pragma;
24446 Exception_Locations_Suppressed := True;
24447
24448 -----------------------------
24449 -- Suppress_Initialization --
24450 -----------------------------
24451
24452 -- pragma Suppress_Initialization ([Entity =>] type_Name);
24453
24454 when Pragma_Suppress_Initialization => Suppress_Init : declare
24455 E : Entity_Id;
24456 E_Id : Node_Id;
24457
24458 begin
24459 GNAT_Pragma;
24460 Check_Arg_Count (1);
24461 Check_Optional_Identifier (Arg1, Name_Entity);
24462 Check_Arg_Is_Local_Name (Arg1);
24463
24464 E_Id := Get_Pragma_Arg (Arg1);
24465
24466 if Etype (E_Id) = Any_Type then
24467 return;
24468 end if;
24469
24470 E := Entity (E_Id);
24471
24472 -- A pragma that applies to a Ghost entity becomes Ghost for the
24473 -- purposes of legality checks and removal of ignored Ghost code.
24474
24475 Mark_Ghost_Pragma (N, E);
24476
24477 if not Is_Type (E) and then Ekind (E) /= E_Variable then
24478 Error_Pragma_Arg
24479 ("pragma% requires variable, type or subtype", Arg1);
24480 end if;
24481
24482 if Rep_Item_Too_Early (E, N)
24483 or else
24484 Rep_Item_Too_Late (E, N, FOnly => True)
24485 then
24486 return;
24487 end if;
24488
24489 -- For incomplete/private type, set flag on full view
24490
24491 if Is_Incomplete_Or_Private_Type (E) then
24492 if No (Full_View (Base_Type (E))) then
24493 Error_Pragma_Arg
24494 ("argument of pragma% cannot be an incomplete type", Arg1);
24495 else
24496 Set_Suppress_Initialization (Full_View (E));
24497 end if;
24498
24499 -- For first subtype, set flag on base type
24500
24501 elsif Is_First_Subtype (E) then
24502 Set_Suppress_Initialization (Base_Type (E));
24503
24504 -- For other than first subtype, set flag on subtype or variable
24505
24506 else
24507 Set_Suppress_Initialization (E);
24508 end if;
24509 end Suppress_Init;
24510
24511 -----------------
24512 -- System_Name --
24513 -----------------
24514
24515 -- pragma System_Name (DIRECT_NAME);
24516
24517 -- Syntax check: one argument, which must be the identifier GNAT or
24518 -- the identifier GCC, no other identifiers are acceptable.
24519
24520 when Pragma_System_Name =>
24521 GNAT_Pragma;
24522 Check_No_Identifiers;
24523 Check_Arg_Count (1);
24524 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
24525
24526 -----------------------------
24527 -- Task_Dispatching_Policy --
24528 -----------------------------
24529
24530 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
24531
24532 when Pragma_Task_Dispatching_Policy => declare
24533 DP : Character;
24534
24535 begin
24536 Check_Ada_83_Warning;
24537 Check_Arg_Count (1);
24538 Check_No_Identifiers;
24539 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
24540 Check_Valid_Configuration_Pragma;
24541 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
24542 DP := Fold_Upper (Name_Buffer (1));
24543
24544 if Task_Dispatching_Policy /= ' '
24545 and then Task_Dispatching_Policy /= DP
24546 then
24547 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
24548 Error_Pragma
24549 ("task dispatching policy incompatible with policy#");
24550
24551 -- Set new policy, but always preserve System_Location since we
24552 -- like the error message with the run time name.
24553
24554 else
24555 Task_Dispatching_Policy := DP;
24556
24557 if Task_Dispatching_Policy_Sloc /= System_Location then
24558 Task_Dispatching_Policy_Sloc := Loc;
24559 end if;
24560 end if;
24561 end;
24562
24563 ---------------
24564 -- Task_Info --
24565 ---------------
24566
24567 -- pragma Task_Info (EXPRESSION);
24568
24569 when Pragma_Task_Info => Task_Info : declare
24570 P : constant Node_Id := Parent (N);
24571 Ent : Entity_Id;
24572
24573 begin
24574 GNAT_Pragma;
24575
24576 if Warn_On_Obsolescent_Feature then
24577 Error_Msg_N
24578 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
24579 & "instead?j?", N);
24580 end if;
24581
24582 if Nkind (P) /= N_Task_Definition then
24583 Error_Pragma ("pragma% must appear in task definition");
24584 end if;
24585
24586 Check_No_Identifiers;
24587 Check_Arg_Count (1);
24588
24589 Analyze_And_Resolve
24590 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
24591
24592 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
24593 return;
24594 end if;
24595
24596 Ent := Defining_Identifier (Parent (P));
24597
24598 -- Check duplicate pragma before we chain the pragma in the Rep
24599 -- Item chain of Ent.
24600
24601 if Has_Rep_Pragma
24602 (Ent, Name_Task_Info, Check_Parents => False)
24603 then
24604 Error_Pragma ("duplicate pragma% not allowed");
24605 end if;
24606
24607 Record_Rep_Item (Ent, N);
24608 end Task_Info;
24609
24610 ---------------
24611 -- Task_Name --
24612 ---------------
24613
24614 -- pragma Task_Name (string_EXPRESSION);
24615
24616 when Pragma_Task_Name => Task_Name : declare
24617 P : constant Node_Id := Parent (N);
24618 Arg : Node_Id;
24619 Ent : Entity_Id;
24620
24621 begin
24622 Check_No_Identifiers;
24623 Check_Arg_Count (1);
24624
24625 Arg := Get_Pragma_Arg (Arg1);
24626
24627 -- The expression is used in the call to Create_Task, and must be
24628 -- expanded there, not in the context of the current spec. It must
24629 -- however be analyzed to capture global references, in case it
24630 -- appears in a generic context.
24631
24632 Preanalyze_And_Resolve (Arg, Standard_String);
24633
24634 if Nkind (P) /= N_Task_Definition then
24635 Pragma_Misplaced;
24636 end if;
24637
24638 Ent := Defining_Identifier (Parent (P));
24639
24640 -- Check duplicate pragma before we chain the pragma in the Rep
24641 -- Item chain of Ent.
24642
24643 if Has_Rep_Pragma
24644 (Ent, Name_Task_Name, Check_Parents => False)
24645 then
24646 Error_Pragma ("duplicate pragma% not allowed");
24647 end if;
24648
24649 Record_Rep_Item (Ent, N);
24650 end Task_Name;
24651
24652 ------------------
24653 -- Task_Storage --
24654 ------------------
24655
24656 -- pragma Task_Storage (
24657 -- [Task_Type =>] LOCAL_NAME,
24658 -- [Top_Guard =>] static_integer_EXPRESSION);
24659
24660 when Pragma_Task_Storage => Task_Storage : declare
24661 Args : Args_List (1 .. 2);
24662 Names : constant Name_List (1 .. 2) := (
24663 Name_Task_Type,
24664 Name_Top_Guard);
24665
24666 Task_Type : Node_Id renames Args (1);
24667 Top_Guard : Node_Id renames Args (2);
24668
24669 Ent : Entity_Id;
24670
24671 begin
24672 GNAT_Pragma;
24673 Gather_Associations (Names, Args);
24674
24675 if No (Task_Type) then
24676 Error_Pragma
24677 ("missing task_type argument for pragma%");
24678 end if;
24679
24680 Check_Arg_Is_Local_Name (Task_Type);
24681
24682 Ent := Entity (Task_Type);
24683
24684 if not Is_Task_Type (Ent) then
24685 Error_Pragma_Arg
24686 ("argument for pragma% must be task type", Task_Type);
24687 end if;
24688
24689 if No (Top_Guard) then
24690 Error_Pragma_Arg
24691 ("pragma% takes two arguments", Task_Type);
24692 else
24693 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
24694 end if;
24695
24696 Check_First_Subtype (Task_Type);
24697
24698 if Rep_Item_Too_Late (Ent, N) then
24699 return;
24700 end if;
24701 end Task_Storage;
24702
24703 ---------------
24704 -- Test_Case --
24705 ---------------
24706
24707 -- pragma Test_Case
24708 -- ([Name =>] Static_String_EXPRESSION
24709 -- ,[Mode =>] MODE_TYPE
24710 -- [, Requires => Boolean_EXPRESSION]
24711 -- [, Ensures => Boolean_EXPRESSION]);
24712
24713 -- MODE_TYPE ::= Nominal | Robustness
24714
24715 -- Characteristics:
24716
24717 -- * Analysis - The annotation undergoes initial checks to verify
24718 -- the legal placement and context. Secondary checks preanalyze the
24719 -- expressions in:
24720
24721 -- Analyze_Test_Case_In_Decl_Part
24722
24723 -- * Expansion - None.
24724
24725 -- * Template - The annotation utilizes the generic template of the
24726 -- related subprogram when it is:
24727
24728 -- aspect on subprogram declaration
24729
24730 -- The annotation must prepare its own template when it is:
24731
24732 -- pragma on subprogram declaration
24733
24734 -- * Globals - Capture of global references must occur after full
24735 -- analysis.
24736
24737 -- * Instance - The annotation is instantiated automatically when
24738 -- the related generic subprogram is instantiated except for the
24739 -- "pragma on subprogram declaration" case. In that scenario the
24740 -- annotation must instantiate itself.
24741
24742 when Pragma_Test_Case => Test_Case : declare
24743 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
24744 -- Ensure that the contract of subprogram Subp_Id does not contain
24745 -- another Test_Case pragma with the same Name as the current one.
24746
24747 -------------------------
24748 -- Check_Distinct_Name --
24749 -------------------------
24750
24751 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
24752 Items : constant Node_Id := Contract (Subp_Id);
24753 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
24754 Prag : Node_Id;
24755
24756 begin
24757 -- Inspect all Test_Case pragma of the related subprogram
24758 -- looking for one with a duplicate "Name" argument.
24759
24760 if Present (Items) then
24761 Prag := Contract_Test_Cases (Items);
24762 while Present (Prag) loop
24763 if Pragma_Name (Prag) = Name_Test_Case
24764 and then Prag /= N
24765 and then String_Equal
24766 (Name, Get_Name_From_CTC_Pragma (Prag))
24767 then
24768 Error_Msg_Sloc := Sloc (Prag);
24769 Error_Pragma ("name for pragma % is already used #");
24770 end if;
24771
24772 Prag := Next_Pragma (Prag);
24773 end loop;
24774 end if;
24775 end Check_Distinct_Name;
24776
24777 -- Local variables
24778
24779 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
24780 Asp_Arg : Node_Id;
24781 Context : Node_Id;
24782 Subp_Decl : Node_Id;
24783 Subp_Id : Entity_Id;
24784
24785 -- Start of processing for Test_Case
24786
24787 begin
24788 GNAT_Pragma;
24789 Check_At_Least_N_Arguments (2);
24790 Check_At_Most_N_Arguments (4);
24791 Check_Arg_Order
24792 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
24793
24794 -- Argument "Name"
24795
24796 Check_Optional_Identifier (Arg1, Name_Name);
24797 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
24798
24799 -- Argument "Mode"
24800
24801 Check_Optional_Identifier (Arg2, Name_Mode);
24802 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
24803
24804 -- Arguments "Requires" and "Ensures"
24805
24806 if Present (Arg3) then
24807 if Present (Arg4) then
24808 Check_Identifier (Arg3, Name_Requires);
24809 Check_Identifier (Arg4, Name_Ensures);
24810 else
24811 Check_Identifier_Is_One_Of
24812 (Arg3, Name_Requires, Name_Ensures);
24813 end if;
24814 end if;
24815
24816 -- Pragma Test_Case must be associated with a subprogram declared
24817 -- in a library-level package. First determine whether the current
24818 -- compilation unit is a legal context.
24819
24820 if Nkind (Pack_Decl) in N_Package_Declaration
24821 | N_Generic_Package_Declaration
24822 then
24823 null;
24824
24825 -- Otherwise the placement is illegal
24826
24827 else
24828 Error_Pragma
24829 ("pragma % must be specified within a package declaration");
24830 end if;
24831
24832 Subp_Decl := Find_Related_Declaration_Or_Body (N);
24833
24834 -- Find the enclosing context
24835
24836 Context := Parent (Subp_Decl);
24837
24838 if Present (Context) then
24839 Context := Parent (Context);
24840 end if;
24841
24842 -- Verify the placement of the pragma
24843
24844 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
24845 Error_Pragma
24846 ("pragma % cannot be applied to abstract subprogram");
24847
24848 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
24849 Error_Pragma ("pragma % cannot be applied to entry");
24850
24851 -- The context is a [generic] subprogram declared at the top level
24852 -- of the [generic] package unit.
24853
24854 elsif Nkind (Subp_Decl) in N_Generic_Subprogram_Declaration
24855 | N_Subprogram_Declaration
24856 and then Present (Context)
24857 and then Nkind (Context) in N_Generic_Package_Declaration
24858 | N_Package_Declaration
24859 then
24860 null;
24861
24862 -- Otherwise the placement is illegal
24863
24864 else
24865 Error_Pragma
24866 ("pragma % must be applied to a library-level subprogram "
24867 & "declaration");
24868 end if;
24869
24870 Subp_Id := Defining_Entity (Subp_Decl);
24871
24872 -- A pragma that applies to a Ghost entity becomes Ghost for the
24873 -- purposes of legality checks and removal of ignored Ghost code.
24874
24875 Mark_Ghost_Pragma (N, Subp_Id);
24876
24877 -- Chain the pragma on the contract for further processing by
24878 -- Analyze_Test_Case_In_Decl_Part.
24879
24880 Add_Contract_Item (N, Subp_Id);
24881
24882 -- Preanalyze the original aspect argument "Name" for a generic
24883 -- subprogram to properly capture global references.
24884
24885 if Is_Generic_Subprogram (Subp_Id) then
24886 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
24887
24888 if Present (Asp_Arg) then
24889
24890 -- The argument appears with an identifier in association
24891 -- form.
24892
24893 if Nkind (Asp_Arg) = N_Component_Association then
24894 Asp_Arg := Expression (Asp_Arg);
24895 end if;
24896
24897 Check_Expr_Is_OK_Static_Expression
24898 (Asp_Arg, Standard_String);
24899 end if;
24900 end if;
24901
24902 -- Ensure that the all Test_Case pragmas of the related subprogram
24903 -- have distinct names.
24904
24905 Check_Distinct_Name (Subp_Id);
24906
24907 -- Fully analyze the pragma when it appears inside an entry
24908 -- or subprogram body because it cannot benefit from forward
24909 -- references.
24910
24911 if Nkind (Subp_Decl) in N_Entry_Body
24912 | N_Subprogram_Body
24913 | N_Subprogram_Body_Stub
24914 then
24915 -- The legality checks of pragma Test_Case are affected by the
24916 -- SPARK mode in effect and the volatility of the context.
24917 -- Analyze all pragmas in a specific order.
24918
24919 Analyze_If_Present (Pragma_SPARK_Mode);
24920 Analyze_If_Present (Pragma_Volatile_Function);
24921 Analyze_Test_Case_In_Decl_Part (N);
24922 end if;
24923 end Test_Case;
24924
24925 --------------------------
24926 -- Thread_Local_Storage --
24927 --------------------------
24928
24929 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
24930
24931 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
24932 E : Entity_Id;
24933 Id : Node_Id;
24934
24935 begin
24936 GNAT_Pragma;
24937 Check_Arg_Count (1);
24938 Check_Optional_Identifier (Arg1, Name_Entity);
24939 Check_Arg_Is_Library_Level_Local_Name (Arg1);
24940
24941 Id := Get_Pragma_Arg (Arg1);
24942
24943 if not Is_Entity_Name (Id)
24944 or else Ekind (Entity (Id)) /= E_Variable
24945 then
24946 Error_Pragma_Arg ("local variable name required", Arg1);
24947 end if;
24948
24949 E := Entity (Id);
24950
24951 -- A pragma that applies to a Ghost entity becomes Ghost for the
24952 -- purposes of legality checks and removal of ignored Ghost code.
24953
24954 Mark_Ghost_Pragma (N, E);
24955
24956 if Rep_Item_Too_Early (E, N)
24957 or else
24958 Rep_Item_Too_Late (E, N)
24959 then
24960 return;
24961 end if;
24962
24963 Set_Has_Pragma_Thread_Local_Storage (E);
24964 Set_Has_Gigi_Rep_Item (E);
24965 end Thread_Local_Storage;
24966
24967 ----------------
24968 -- Time_Slice --
24969 ----------------
24970
24971 -- pragma Time_Slice (static_duration_EXPRESSION);
24972
24973 when Pragma_Time_Slice => Time_Slice : declare
24974 Val : Ureal;
24975 Nod : Node_Id;
24976
24977 begin
24978 GNAT_Pragma;
24979 Check_Arg_Count (1);
24980 Check_No_Identifiers;
24981 Check_In_Main_Program;
24982 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
24983
24984 if not Error_Posted (Arg1) then
24985 Nod := Next (N);
24986 while Present (Nod) loop
24987 if Nkind (Nod) = N_Pragma
24988 and then Pragma_Name (Nod) = Name_Time_Slice
24989 then
24990 Error_Msg_Name_1 := Pname;
24991 Error_Msg_N ("duplicate pragma% not permitted", Nod);
24992 end if;
24993
24994 Next (Nod);
24995 end loop;
24996 end if;
24997
24998 -- Process only if in main unit
24999
25000 if Get_Source_Unit (Loc) = Main_Unit then
25001 Opt.Time_Slice_Set := True;
25002 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
25003
25004 if Val <= Ureal_0 then
25005 Opt.Time_Slice_Value := 0;
25006
25007 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
25008 Opt.Time_Slice_Value := 1_000_000_000;
25009
25010 else
25011 Opt.Time_Slice_Value :=
25012 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
25013 end if;
25014 end if;
25015 end Time_Slice;
25016
25017 -----------
25018 -- Title --
25019 -----------
25020
25021 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
25022
25023 -- TITLING_OPTION ::=
25024 -- [Title =>] STRING_LITERAL
25025 -- | [Subtitle =>] STRING_LITERAL
25026
25027 when Pragma_Title => Title : declare
25028 Args : Args_List (1 .. 2);
25029 Names : constant Name_List (1 .. 2) := (
25030 Name_Title,
25031 Name_Subtitle);
25032
25033 begin
25034 GNAT_Pragma;
25035 Gather_Associations (Names, Args);
25036 Store_Note (N);
25037
25038 for J in 1 .. 2 loop
25039 if Present (Args (J)) then
25040 Check_Arg_Is_OK_Static_Expression
25041 (Args (J), Standard_String);
25042 end if;
25043 end loop;
25044 end Title;
25045
25046 ----------------------------
25047 -- Type_Invariant[_Class] --
25048 ----------------------------
25049
25050 -- pragma Type_Invariant[_Class]
25051 -- ([Entity =>] type_LOCAL_NAME,
25052 -- [Check =>] EXPRESSION);
25053
25054 when Pragma_Type_Invariant
25055 | Pragma_Type_Invariant_Class
25056 =>
25057 Type_Invariant : declare
25058 I_Pragma : Node_Id;
25059
25060 begin
25061 Check_Arg_Count (2);
25062
25063 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
25064 -- setting Class_Present for the Type_Invariant_Class case.
25065
25066 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
25067 I_Pragma := New_Copy (N);
25068 Set_Pragma_Identifier
25069 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
25070 Rewrite (N, I_Pragma);
25071 Set_Analyzed (N, False);
25072 Analyze (N);
25073 end Type_Invariant;
25074
25075 ---------------------
25076 -- Unchecked_Union --
25077 ---------------------
25078
25079 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
25080
25081 when Pragma_Unchecked_Union => Unchecked_Union : declare
25082 Assoc : constant Node_Id := Arg1;
25083 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
25084 Clist : Node_Id;
25085 Comp : Node_Id;
25086 Tdef : Node_Id;
25087 Typ : Entity_Id;
25088 Variant : Node_Id;
25089 Vpart : Node_Id;
25090
25091 begin
25092 Ada_2005_Pragma;
25093 Check_No_Identifiers;
25094 Check_Arg_Count (1);
25095 Check_Arg_Is_Local_Name (Arg1);
25096
25097 Find_Type (Type_Id);
25098
25099 Typ := Entity (Type_Id);
25100
25101 -- A pragma that applies to a Ghost entity becomes Ghost for the
25102 -- purposes of legality checks and removal of ignored Ghost code.
25103
25104 Mark_Ghost_Pragma (N, Typ);
25105
25106 if Typ = Any_Type
25107 or else Rep_Item_Too_Early (Typ, N)
25108 then
25109 return;
25110 else
25111 Typ := Underlying_Type (Typ);
25112 end if;
25113
25114 if Rep_Item_Too_Late (Typ, N) then
25115 return;
25116 end if;
25117
25118 Check_First_Subtype (Arg1);
25119
25120 -- Note remaining cases are references to a type in the current
25121 -- declarative part. If we find an error, we post the error on
25122 -- the relevant type declaration at an appropriate point.
25123
25124 if not Is_Record_Type (Typ) then
25125 Error_Msg_N ("unchecked union must be record type", Typ);
25126 return;
25127
25128 elsif Is_Tagged_Type (Typ) then
25129 Error_Msg_N ("unchecked union must not be tagged", Typ);
25130 return;
25131
25132 elsif not Has_Discriminants (Typ) then
25133 Error_Msg_N
25134 ("unchecked union must have one discriminant", Typ);
25135 return;
25136
25137 -- Note: in previous versions of GNAT we used to check for limited
25138 -- types and give an error, but in fact the standard does allow
25139 -- Unchecked_Union on limited types, so this check was removed.
25140
25141 -- Similarly, GNAT used to require that all discriminants have
25142 -- default values, but this is not mandated by the RM.
25143
25144 -- Proceed with basic error checks completed
25145
25146 else
25147 Tdef := Type_Definition (Declaration_Node (Typ));
25148 Clist := Component_List (Tdef);
25149
25150 -- Check presence of component list and variant part
25151
25152 if No (Clist) or else No (Variant_Part (Clist)) then
25153 Error_Msg_N
25154 ("unchecked union must have variant part", Tdef);
25155 return;
25156 end if;
25157
25158 -- Check components
25159
25160 Comp := First_Non_Pragma (Component_Items (Clist));
25161 while Present (Comp) loop
25162 Check_Component (Comp, Typ);
25163 Next_Non_Pragma (Comp);
25164 end loop;
25165
25166 -- Check variant part
25167
25168 Vpart := Variant_Part (Clist);
25169
25170 Variant := First_Non_Pragma (Variants (Vpart));
25171 while Present (Variant) loop
25172 Check_Variant (Variant, Typ);
25173 Next_Non_Pragma (Variant);
25174 end loop;
25175 end if;
25176
25177 Set_Is_Unchecked_Union (Typ);
25178 Set_Convention (Typ, Convention_C);
25179 Set_Has_Unchecked_Union (Base_Type (Typ));
25180 Set_Is_Unchecked_Union (Base_Type (Typ));
25181 end Unchecked_Union;
25182
25183 ----------------------------
25184 -- Unevaluated_Use_Of_Old --
25185 ----------------------------
25186
25187 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
25188
25189 when Pragma_Unevaluated_Use_Of_Old =>
25190 GNAT_Pragma;
25191 Check_Arg_Count (1);
25192 Check_No_Identifiers;
25193 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
25194
25195 -- Suppress/Unsuppress can appear as a configuration pragma, or in
25196 -- a declarative part or a package spec.
25197
25198 if not Is_Configuration_Pragma then
25199 Check_Is_In_Decl_Part_Or_Package_Spec;
25200 end if;
25201
25202 -- Store proper setting of Uneval_Old
25203
25204 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
25205 Uneval_Old := Fold_Upper (Name_Buffer (1));
25206
25207 ------------------------
25208 -- Unimplemented_Unit --
25209 ------------------------
25210
25211 -- pragma Unimplemented_Unit;
25212
25213 -- Note: this only gives an error if we are generating code, or if
25214 -- we are in a generic library unit (where the pragma appears in the
25215 -- body, not in the spec).
25216
25217 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
25218 Cunitent : constant Entity_Id :=
25219 Cunit_Entity (Get_Source_Unit (Loc));
25220
25221 begin
25222 GNAT_Pragma;
25223 Check_Arg_Count (0);
25224
25225 if Operating_Mode = Generate_Code
25226 or else Is_Generic_Unit (Cunitent)
25227 then
25228 Get_Name_String (Chars (Cunitent));
25229 Set_Casing (Mixed_Case);
25230 Write_Str (Name_Buffer (1 .. Name_Len));
25231 Write_Str (" is not supported in this configuration");
25232 Write_Eol;
25233 raise Unrecoverable_Error;
25234 end if;
25235 end Unimplemented_Unit;
25236
25237 ------------------------
25238 -- Universal_Aliasing --
25239 ------------------------
25240
25241 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
25242
25243 when Pragma_Universal_Aliasing => Universal_Alias : declare
25244 E : Entity_Id;
25245 E_Id : Node_Id;
25246
25247 begin
25248 GNAT_Pragma;
25249 Check_Arg_Count (1);
25250 Check_Optional_Identifier (Arg2, Name_Entity);
25251 Check_Arg_Is_Local_Name (Arg1);
25252 E_Id := Get_Pragma_Arg (Arg1);
25253
25254 if Etype (E_Id) = Any_Type then
25255 return;
25256 end if;
25257
25258 E := Entity (E_Id);
25259
25260 if not Is_Type (E) then
25261 Error_Pragma_Arg ("pragma% requires type", Arg1);
25262 end if;
25263
25264 -- A pragma that applies to a Ghost entity becomes Ghost for the
25265 -- purposes of legality checks and removal of ignored Ghost code.
25266
25267 Mark_Ghost_Pragma (N, E);
25268 Set_Universal_Aliasing (Base_Type (E));
25269 Record_Rep_Item (E, N);
25270 end Universal_Alias;
25271
25272 ----------------
25273 -- Unmodified --
25274 ----------------
25275
25276 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
25277
25278 when Pragma_Unmodified =>
25279 Analyze_Unmodified_Or_Unused;
25280
25281 ------------------
25282 -- Unreferenced --
25283 ------------------
25284
25285 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
25286
25287 -- or when used in a context clause:
25288
25289 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
25290
25291 when Pragma_Unreferenced =>
25292 Analyze_Unreferenced_Or_Unused;
25293
25294 --------------------------
25295 -- Unreferenced_Objects --
25296 --------------------------
25297
25298 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
25299
25300 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
25301 Arg : Node_Id;
25302 Arg_Expr : Node_Id;
25303 Arg_Id : Entity_Id;
25304
25305 Ghost_Error_Posted : Boolean := False;
25306 -- Flag set when an error concerning the illegal mix of Ghost and
25307 -- non-Ghost types is emitted.
25308
25309 Ghost_Id : Entity_Id := Empty;
25310 -- The entity of the first Ghost type encountered while processing
25311 -- the arguments of the pragma.
25312
25313 begin
25314 GNAT_Pragma;
25315 Check_At_Least_N_Arguments (1);
25316
25317 Arg := Arg1;
25318 while Present (Arg) loop
25319 Check_No_Identifier (Arg);
25320 Check_Arg_Is_Local_Name (Arg);
25321 Arg_Expr := Get_Pragma_Arg (Arg);
25322
25323 if Is_Entity_Name (Arg_Expr) then
25324 Arg_Id := Entity (Arg_Expr);
25325
25326 if Is_Type (Arg_Id) then
25327 Set_Has_Pragma_Unreferenced_Objects (Arg_Id);
25328
25329 -- A pragma that applies to a Ghost entity becomes Ghost
25330 -- for the purposes of legality checks and removal of
25331 -- ignored Ghost code.
25332
25333 Mark_Ghost_Pragma (N, Arg_Id);
25334
25335 -- Capture the entity of the first Ghost type being
25336 -- processed for error detection purposes.
25337
25338 if Is_Ghost_Entity (Arg_Id) then
25339 if No (Ghost_Id) then
25340 Ghost_Id := Arg_Id;
25341 end if;
25342
25343 -- Otherwise the type is non-Ghost. It is illegal to mix
25344 -- references to Ghost and non-Ghost entities
25345 -- (SPARK RM 6.9).
25346
25347 elsif Present (Ghost_Id)
25348 and then not Ghost_Error_Posted
25349 then
25350 Ghost_Error_Posted := True;
25351
25352 Error_Msg_Name_1 := Pname;
25353 Error_Msg_N
25354 ("pragma % cannot mention ghost and non-ghost types",
25355 N);
25356
25357 Error_Msg_Sloc := Sloc (Ghost_Id);
25358 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
25359
25360 Error_Msg_Sloc := Sloc (Arg_Id);
25361 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
25362 end if;
25363 else
25364 Error_Pragma_Arg
25365 ("argument for pragma% must be type or subtype", Arg);
25366 end if;
25367 else
25368 Error_Pragma_Arg
25369 ("argument for pragma% must be type or subtype", Arg);
25370 end if;
25371
25372 Next (Arg);
25373 end loop;
25374 end Unreferenced_Objects;
25375
25376 ------------------------------
25377 -- Unreserve_All_Interrupts --
25378 ------------------------------
25379
25380 -- pragma Unreserve_All_Interrupts;
25381
25382 when Pragma_Unreserve_All_Interrupts =>
25383 GNAT_Pragma;
25384 Check_Arg_Count (0);
25385
25386 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
25387 Unreserve_All_Interrupts := True;
25388 end if;
25389
25390 ----------------
25391 -- Unsuppress --
25392 ----------------
25393
25394 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
25395
25396 when Pragma_Unsuppress =>
25397 Ada_2005_Pragma;
25398 Process_Suppress_Unsuppress (Suppress_Case => False);
25399
25400 ------------
25401 -- Unused --
25402 ------------
25403
25404 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
25405
25406 when Pragma_Unused =>
25407 Analyze_Unmodified_Or_Unused (Is_Unused => True);
25408 Analyze_Unreferenced_Or_Unused (Is_Unused => True);
25409
25410 -------------------
25411 -- Use_VADS_Size --
25412 -------------------
25413
25414 -- pragma Use_VADS_Size;
25415
25416 when Pragma_Use_VADS_Size =>
25417 GNAT_Pragma;
25418 Check_Arg_Count (0);
25419 Check_Valid_Configuration_Pragma;
25420 Use_VADS_Size := True;
25421
25422 ---------------------
25423 -- Validity_Checks --
25424 ---------------------
25425
25426 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
25427
25428 when Pragma_Validity_Checks => Validity_Checks : declare
25429 A : constant Node_Id := Get_Pragma_Arg (Arg1);
25430 S : String_Id;
25431 C : Char_Code;
25432
25433 begin
25434 GNAT_Pragma;
25435 Check_Arg_Count (1);
25436 Check_No_Identifiers;
25437
25438 -- Pragma always active unless in CodePeer or GNATprove modes,
25439 -- which use a fixed configuration of validity checks.
25440
25441 if not (CodePeer_Mode or GNATprove_Mode) then
25442 if Nkind (A) = N_String_Literal then
25443 S := Strval (A);
25444
25445 declare
25446 Slen : constant Natural := Natural (String_Length (S));
25447 Options : String (1 .. Slen);
25448 J : Positive;
25449
25450 begin
25451 -- Couldn't we use a for loop here over Options'Range???
25452
25453 J := 1;
25454 loop
25455 C := Get_String_Char (S, Pos (J));
25456
25457 -- This is a weird test, it skips setting validity
25458 -- checks entirely if any element of S is out of
25459 -- range of Character, what is that about ???
25460
25461 exit when not In_Character_Range (C);
25462 Options (J) := Get_Character (C);
25463
25464 if J = Slen then
25465 Set_Validity_Check_Options (Options);
25466 exit;
25467 else
25468 J := J + 1;
25469 end if;
25470 end loop;
25471 end;
25472
25473 elsif Nkind (A) = N_Identifier then
25474 if Chars (A) = Name_All_Checks then
25475 Set_Validity_Check_Options ("a");
25476 elsif Chars (A) = Name_On then
25477 Validity_Checks_On := True;
25478 elsif Chars (A) = Name_Off then
25479 Validity_Checks_On := False;
25480 end if;
25481 end if;
25482 end if;
25483 end Validity_Checks;
25484
25485 --------------
25486 -- Volatile --
25487 --------------
25488
25489 -- pragma Volatile (LOCAL_NAME);
25490
25491 when Pragma_Volatile =>
25492 Process_Atomic_Independent_Shared_Volatile;
25493
25494 -------------------------
25495 -- Volatile_Components --
25496 -------------------------
25497
25498 -- pragma Volatile_Components (array_LOCAL_NAME);
25499
25500 -- Volatile is handled by the same circuit as Atomic_Components
25501
25502 --------------------------
25503 -- Volatile_Full_Access --
25504 --------------------------
25505
25506 -- pragma Volatile_Full_Access (LOCAL_NAME);
25507
25508 when Pragma_Volatile_Full_Access =>
25509 GNAT_Pragma;
25510 Process_Atomic_Independent_Shared_Volatile;
25511
25512 -----------------------
25513 -- Volatile_Function --
25514 -----------------------
25515
25516 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
25517
25518 when Pragma_Volatile_Function => Volatile_Function : declare
25519 Over_Id : Entity_Id;
25520 Spec_Id : Entity_Id;
25521 Subp_Decl : Node_Id;
25522
25523 begin
25524 GNAT_Pragma;
25525 Check_No_Identifiers;
25526 Check_At_Most_N_Arguments (1);
25527
25528 Subp_Decl :=
25529 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
25530
25531 -- Generic subprogram
25532
25533 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
25534 null;
25535
25536 -- Body acts as spec
25537
25538 elsif Nkind (Subp_Decl) = N_Subprogram_Body
25539 and then No (Corresponding_Spec (Subp_Decl))
25540 then
25541 null;
25542
25543 -- Body stub acts as spec
25544
25545 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
25546 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
25547 then
25548 null;
25549
25550 -- Subprogram
25551
25552 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
25553 null;
25554
25555 else
25556 Pragma_Misplaced;
25557 end if;
25558
25559 Spec_Id := Unique_Defining_Entity (Subp_Decl);
25560
25561 if Ekind (Spec_Id) not in E_Function | E_Generic_Function then
25562 Pragma_Misplaced;
25563 end if;
25564
25565 -- A pragma that applies to a Ghost entity becomes Ghost for the
25566 -- purposes of legality checks and removal of ignored Ghost code.
25567
25568 Mark_Ghost_Pragma (N, Spec_Id);
25569
25570 -- Chain the pragma on the contract for completeness
25571
25572 Add_Contract_Item (N, Spec_Id);
25573
25574 -- The legality checks of pragma Volatile_Function are affected by
25575 -- the SPARK mode in effect. Analyze all pragmas in a specific
25576 -- order.
25577
25578 Analyze_If_Present (Pragma_SPARK_Mode);
25579
25580 -- A volatile function cannot override a non-volatile function
25581 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
25582 -- in New_Overloaded_Entity, however at that point the pragma has
25583 -- not been processed yet.
25584
25585 Over_Id := Overridden_Operation (Spec_Id);
25586
25587 if Present (Over_Id)
25588 and then not Is_Volatile_Function (Over_Id)
25589 then
25590 Error_Msg_N
25591 ("incompatible volatile function values in effect", Spec_Id);
25592
25593 Error_Msg_Sloc := Sloc (Over_Id);
25594 Error_Msg_N
25595 ("\& declared # with Volatile_Function value False",
25596 Spec_Id);
25597
25598 Error_Msg_Sloc := Sloc (Spec_Id);
25599 Error_Msg_N
25600 ("\overridden # with Volatile_Function value True",
25601 Spec_Id);
25602 end if;
25603
25604 -- Analyze the Boolean expression (if any)
25605
25606 if Present (Arg1) then
25607 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
25608 end if;
25609 end Volatile_Function;
25610
25611 ----------------------
25612 -- Warning_As_Error --
25613 ----------------------
25614
25615 -- pragma Warning_As_Error (static_string_EXPRESSION);
25616
25617 when Pragma_Warning_As_Error =>
25618 GNAT_Pragma;
25619 Check_Arg_Count (1);
25620 Check_No_Identifiers;
25621 Check_Valid_Configuration_Pragma;
25622
25623 if not Is_Static_String_Expression (Arg1) then
25624 Error_Pragma_Arg
25625 ("argument of pragma% must be static string expression",
25626 Arg1);
25627
25628 -- OK static string expression
25629
25630 else
25631 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
25632 Warnings_As_Errors (Warnings_As_Errors_Count) :=
25633 new String'(Acquire_Warning_Match_String
25634 (Expr_Value_S (Get_Pragma_Arg (Arg1))));
25635 end if;
25636
25637 --------------
25638 -- Warnings --
25639 --------------
25640
25641 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
25642
25643 -- DETAILS ::= On | Off
25644 -- DETAILS ::= On | Off, local_NAME
25645 -- DETAILS ::= static_string_EXPRESSION
25646 -- DETAILS ::= On | Off, static_string_EXPRESSION
25647
25648 -- TOOL_NAME ::= GNAT | GNATprove
25649
25650 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
25651
25652 -- Note: If the first argument matches an allowed tool name, it is
25653 -- always considered to be a tool name, even if there is a string
25654 -- variable of that name.
25655
25656 -- Note if the second argument of DETAILS is a local_NAME then the
25657 -- second form is always understood. If the intention is to use
25658 -- the fourth form, then you can write NAME & "" to force the
25659 -- intepretation as a static_string_EXPRESSION.
25660
25661 when Pragma_Warnings => Warnings : declare
25662 Reason : String_Id;
25663
25664 begin
25665 GNAT_Pragma;
25666 Check_At_Least_N_Arguments (1);
25667
25668 -- See if last argument is labeled Reason. If so, make sure we
25669 -- have a string literal or a concatenation of string literals,
25670 -- and acquire the REASON string. Then remove the REASON argument
25671 -- by decreasing Num_Args by one; Remaining processing looks only
25672 -- at first Num_Args arguments).
25673
25674 declare
25675 Last_Arg : constant Node_Id :=
25676 Last (Pragma_Argument_Associations (N));
25677
25678 begin
25679 if Nkind (Last_Arg) = N_Pragma_Argument_Association
25680 and then Chars (Last_Arg) = Name_Reason
25681 then
25682 Start_String;
25683 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
25684 Reason := End_String;
25685 Arg_Count := Arg_Count - 1;
25686
25687 -- No REASON string, set null string as reason
25688
25689 else
25690 Reason := Null_String_Id;
25691 end if;
25692 end;
25693
25694 -- Now proceed with REASON taken care of and eliminated
25695
25696 Check_No_Identifiers;
25697
25698 -- If debug flag -gnatd.i is set, pragma is ignored
25699
25700 if Debug_Flag_Dot_I then
25701 return;
25702 end if;
25703
25704 -- Process various forms of the pragma
25705
25706 declare
25707 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
25708 Shifted_Args : List_Id;
25709
25710 begin
25711 -- See if first argument is a tool name, currently either
25712 -- GNAT or GNATprove. If so, either ignore the pragma if the
25713 -- tool used does not match, or continue as if no tool name
25714 -- was given otherwise, by shifting the arguments.
25715
25716 if Nkind (Argx) = N_Identifier
25717 and then Chars (Argx) in Name_Gnat | Name_Gnatprove
25718 then
25719 if Chars (Argx) = Name_Gnat then
25720 if CodePeer_Mode or GNATprove_Mode then
25721 Rewrite (N, Make_Null_Statement (Loc));
25722 Analyze (N);
25723 return;
25724 end if;
25725
25726 elsif Chars (Argx) = Name_Gnatprove then
25727 if not GNATprove_Mode then
25728 Rewrite (N, Make_Null_Statement (Loc));
25729 Analyze (N);
25730 return;
25731 end if;
25732 else
25733 raise Program_Error;
25734 end if;
25735
25736 -- At this point, the pragma Warnings applies to the tool,
25737 -- so continue with shifted arguments.
25738
25739 Arg_Count := Arg_Count - 1;
25740
25741 if Arg_Count = 1 then
25742 Shifted_Args := New_List (New_Copy (Arg2));
25743 elsif Arg_Count = 2 then
25744 Shifted_Args := New_List (New_Copy (Arg2),
25745 New_Copy (Arg3));
25746 elsif Arg_Count = 3 then
25747 Shifted_Args := New_List (New_Copy (Arg2),
25748 New_Copy (Arg3),
25749 New_Copy (Arg4));
25750 else
25751 raise Program_Error;
25752 end if;
25753
25754 Rewrite (N,
25755 Make_Pragma (Loc,
25756 Chars => Name_Warnings,
25757 Pragma_Argument_Associations => Shifted_Args));
25758 Analyze (N);
25759 return;
25760 end if;
25761
25762 -- One argument case
25763
25764 if Arg_Count = 1 then
25765
25766 -- On/Off one argument case was processed by parser
25767
25768 if Nkind (Argx) = N_Identifier
25769 and then Chars (Argx) in Name_On | Name_Off
25770 then
25771 null;
25772
25773 -- One argument case must be ON/OFF or static string expr
25774
25775 elsif not Is_Static_String_Expression (Arg1) then
25776 Error_Pragma_Arg
25777 ("argument of pragma% must be On/Off or static string "
25778 & "expression", Arg1);
25779
25780 -- Use of pragma Warnings to set warning switches is
25781 -- ignored in GNATprove mode, as these switches apply to
25782 -- the compiler only.
25783
25784 elsif GNATprove_Mode then
25785 null;
25786
25787 -- One argument string expression case
25788
25789 else
25790 declare
25791 Lit : constant Node_Id := Expr_Value_S (Argx);
25792 Str : constant String_Id := Strval (Lit);
25793 Len : constant Nat := String_Length (Str);
25794 C : Char_Code;
25795 J : Nat;
25796 OK : Boolean;
25797 Chr : Character;
25798
25799 begin
25800 J := 1;
25801 while J <= Len loop
25802 C := Get_String_Char (Str, J);
25803 OK := In_Character_Range (C);
25804
25805 if OK then
25806 Chr := Get_Character (C);
25807
25808 -- Dash case: only -Wxxx is accepted
25809
25810 if J = 1
25811 and then J < Len
25812 and then Chr = '-'
25813 then
25814 J := J + 1;
25815 C := Get_String_Char (Str, J);
25816 Chr := Get_Character (C);
25817 exit when Chr = 'W';
25818 OK := False;
25819
25820 -- Dot case
25821
25822 elsif J < Len and then Chr = '.' then
25823 J := J + 1;
25824 C := Get_String_Char (Str, J);
25825 Chr := Get_Character (C);
25826
25827 if not Set_Warning_Switch ('.', Chr) then
25828 Error_Pragma_Arg
25829 ("invalid warning switch character "
25830 & '.' & Chr, Arg1);
25831 end if;
25832
25833 -- Non-Dot case
25834
25835 else
25836 OK := Set_Warning_Switch (Plain, Chr);
25837 end if;
25838
25839 if not OK then
25840 Error_Pragma_Arg
25841 ("invalid warning switch character " & Chr,
25842 Arg1);
25843 end if;
25844
25845 else
25846 Error_Pragma_Arg
25847 ("invalid wide character in warning switch ",
25848 Arg1);
25849 end if;
25850
25851 J := J + 1;
25852 end loop;
25853 end;
25854 end if;
25855
25856 -- Two or more arguments (must be two)
25857
25858 else
25859 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
25860 Check_Arg_Count (2);
25861
25862 declare
25863 E_Id : Node_Id;
25864 E : Entity_Id;
25865 Err : Boolean;
25866
25867 begin
25868 E_Id := Get_Pragma_Arg (Arg2);
25869 Analyze (E_Id);
25870
25871 -- In the expansion of an inlined body, a reference to
25872 -- the formal may be wrapped in a conversion if the
25873 -- actual is a conversion. Retrieve the real entity name.
25874
25875 if (In_Instance_Body or In_Inlined_Body)
25876 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
25877 then
25878 E_Id := Expression (E_Id);
25879 end if;
25880
25881 -- Entity name case
25882
25883 if Is_Entity_Name (E_Id) then
25884 E := Entity (E_Id);
25885
25886 if E = Any_Id then
25887 return;
25888 else
25889 loop
25890 Set_Warnings_Off
25891 (E, (Chars (Get_Pragma_Arg (Arg1)) =
25892 Name_Off));
25893
25894 -- Suppress elaboration warnings if the entity
25895 -- denotes an elaboration target.
25896
25897 if Is_Elaboration_Target (E) then
25898 Set_Is_Elaboration_Warnings_OK_Id (E, False);
25899 end if;
25900
25901 -- For OFF case, make entry in warnings off
25902 -- pragma table for later processing. But we do
25903 -- not do that within an instance, since these
25904 -- warnings are about what is needed in the
25905 -- template, not an instance of it.
25906
25907 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
25908 and then Warn_On_Warnings_Off
25909 and then not In_Instance
25910 then
25911 Warnings_Off_Pragmas.Append ((N, E, Reason));
25912 end if;
25913
25914 if Is_Enumeration_Type (E) then
25915 declare
25916 Lit : Entity_Id;
25917 begin
25918 Lit := First_Literal (E);
25919 while Present (Lit) loop
25920 Set_Warnings_Off (Lit);
25921 Next_Literal (Lit);
25922 end loop;
25923 end;
25924 end if;
25925
25926 exit when No (Homonym (E));
25927 E := Homonym (E);
25928 end loop;
25929 end if;
25930
25931 -- Error if not entity or static string expression case
25932
25933 elsif not Is_Static_String_Expression (Arg2) then
25934 Error_Pragma_Arg
25935 ("second argument of pragma% must be entity name "
25936 & "or static string expression", Arg2);
25937
25938 -- Static string expression case
25939
25940 else
25941 -- Note on configuration pragma case: If this is a
25942 -- configuration pragma, then for an OFF pragma, we
25943 -- just set Config True in the call, which is all
25944 -- that needs to be done. For the case of ON, this
25945 -- is normally an error, unless it is canceling the
25946 -- effect of a previous OFF pragma in the same file.
25947 -- In any other case, an error will be signalled (ON
25948 -- with no matching OFF).
25949
25950 -- Note: We set Used if we are inside a generic to
25951 -- disable the test that the non-config case actually
25952 -- cancels a warning. That's because we can't be sure
25953 -- there isn't an instantiation in some other unit
25954 -- where a warning is suppressed.
25955
25956 -- We could do a little better here by checking if the
25957 -- generic unit we are inside is public, but for now
25958 -- we don't bother with that refinement.
25959
25960 declare
25961 Message : constant String :=
25962 Acquire_Warning_Match_String
25963 (Expr_Value_S (Get_Pragma_Arg (Arg2)));
25964 begin
25965 if Chars (Argx) = Name_Off then
25966 Set_Specific_Warning_Off
25967 (Loc, Message, Reason,
25968 Config => Is_Configuration_Pragma,
25969 Used => Inside_A_Generic or else In_Instance);
25970
25971 elsif Chars (Argx) = Name_On then
25972 Set_Specific_Warning_On (Loc, Message, Err);
25973
25974 if Err then
25975 Error_Msg_N
25976 ("??pragma Warnings On with no matching "
25977 & "Warnings Off", N);
25978 end if;
25979 end if;
25980 end;
25981 end if;
25982 end;
25983 end if;
25984 end;
25985 end Warnings;
25986
25987 -------------------
25988 -- Weak_External --
25989 -------------------
25990
25991 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
25992
25993 when Pragma_Weak_External => Weak_External : declare
25994 Ent : Entity_Id;
25995
25996 begin
25997 GNAT_Pragma;
25998 Check_Arg_Count (1);
25999 Check_Optional_Identifier (Arg1, Name_Entity);
26000 Check_Arg_Is_Library_Level_Local_Name (Arg1);
26001 Ent := Entity (Get_Pragma_Arg (Arg1));
26002
26003 if Rep_Item_Too_Early (Ent, N) then
26004 return;
26005 else
26006 Ent := Underlying_Type (Ent);
26007 end if;
26008
26009 -- The pragma applies to entities with addresses
26010
26011 if Is_Type (Ent) then
26012 Error_Pragma ("pragma applies to objects and subprograms");
26013 end if;
26014
26015 -- The only processing required is to link this item on to the
26016 -- list of rep items for the given entity. This is accomplished
26017 -- by the call to Rep_Item_Too_Late (when no error is detected
26018 -- and False is returned).
26019
26020 if Rep_Item_Too_Late (Ent, N) then
26021 return;
26022 else
26023 Set_Has_Gigi_Rep_Item (Ent);
26024 end if;
26025 end Weak_External;
26026
26027 -----------------------------
26028 -- Wide_Character_Encoding --
26029 -----------------------------
26030
26031 -- pragma Wide_Character_Encoding (IDENTIFIER);
26032
26033 when Pragma_Wide_Character_Encoding =>
26034 GNAT_Pragma;
26035
26036 -- Nothing to do, handled in parser. Note that we do not enforce
26037 -- configuration pragma placement, this pragma can appear at any
26038 -- place in the source, allowing mixed encodings within a single
26039 -- source program.
26040
26041 null;
26042
26043 --------------------
26044 -- Unknown_Pragma --
26045 --------------------
26046
26047 -- Should be impossible, since the case of an unknown pragma is
26048 -- separately processed before the case statement is entered.
26049
26050 when Unknown_Pragma =>
26051 raise Program_Error;
26052 end case;
26053
26054 -- AI05-0144: detect dangerous order dependence. Disabled for now,
26055 -- until AI is formally approved.
26056
26057 -- Check_Order_Dependence;
26058
26059 exception
26060 when Pragma_Exit => null;
26061 end Analyze_Pragma;
26062
26063 ---------------------------------------------
26064 -- Analyze_Pre_Post_Condition_In_Decl_Part --
26065 ---------------------------------------------
26066
26067 -- WARNING: This routine manages Ghost regions. Return statements must be
26068 -- replaced by gotos which jump to the end of the routine and restore the
26069 -- Ghost mode.
26070
26071 procedure Analyze_Pre_Post_Condition_In_Decl_Part
26072 (N : Node_Id;
26073 Freeze_Id : Entity_Id := Empty)
26074 is
26075 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
26076 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
26077
26078 Disp_Typ : Entity_Id;
26079 -- The dispatching type of the subprogram subject to the pre- or
26080 -- postcondition.
26081
26082 function Check_References (Nod : Node_Id) return Traverse_Result;
26083 -- Check that expression Nod does not mention non-primitives of the
26084 -- type, global objects of the type, or other illegalities described
26085 -- and implied by AI12-0113.
26086
26087 ----------------------
26088 -- Check_References --
26089 ----------------------
26090
26091 function Check_References (Nod : Node_Id) return Traverse_Result is
26092 begin
26093 if Nkind (Nod) = N_Function_Call
26094 and then Is_Entity_Name (Name (Nod))
26095 then
26096 declare
26097 Func : constant Entity_Id := Entity (Name (Nod));
26098 Form : Entity_Id;
26099
26100 begin
26101 -- An operation of the type must be a primitive
26102
26103 if No (Find_Dispatching_Type (Func)) then
26104 Form := First_Formal (Func);
26105 while Present (Form) loop
26106 if Etype (Form) = Disp_Typ then
26107 Error_Msg_NE
26108 ("operation in class-wide condition must be "
26109 & "primitive of &", Nod, Disp_Typ);
26110 end if;
26111
26112 Next_Formal (Form);
26113 end loop;
26114
26115 -- A return object of the type is illegal as well
26116
26117 if Etype (Func) = Disp_Typ
26118 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
26119 then
26120 Error_Msg_NE
26121 ("operation in class-wide condition must be primitive "
26122 & "of &", Nod, Disp_Typ);
26123 end if;
26124 end if;
26125 end;
26126
26127 elsif Is_Entity_Name (Nod)
26128 and then
26129 (Etype (Nod) = Disp_Typ
26130 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
26131 and then Ekind (Entity (Nod)) in E_Constant | E_Variable
26132 then
26133 Error_Msg_NE
26134 ("object in class-wide condition must be formal of type &",
26135 Nod, Disp_Typ);
26136
26137 elsif Nkind (Nod) = N_Explicit_Dereference
26138 and then (Etype (Nod) = Disp_Typ
26139 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
26140 and then (not Is_Entity_Name (Prefix (Nod))
26141 or else not Is_Formal (Entity (Prefix (Nod))))
26142 then
26143 Error_Msg_NE
26144 ("operation in class-wide condition must be primitive of &",
26145 Nod, Disp_Typ);
26146 end if;
26147
26148 return OK;
26149 end Check_References;
26150
26151 procedure Check_Class_Wide_Condition is
26152 new Traverse_Proc (Check_References);
26153
26154 -- Local variables
26155
26156 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
26157
26158 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
26159 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
26160 -- Save the Ghost-related attributes to restore on exit
26161
26162 Errors : Nat;
26163 Restore_Scope : Boolean := False;
26164
26165 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
26166
26167 begin
26168 -- Do not analyze the pragma multiple times
26169
26170 if Is_Analyzed_Pragma (N) then
26171 return;
26172 end if;
26173
26174 -- Set the Ghost mode in effect from the pragma. Due to the delayed
26175 -- analysis of the pragma, the Ghost mode at point of declaration and
26176 -- point of analysis may not necessarily be the same. Use the mode in
26177 -- effect at the point of declaration.
26178
26179 Set_Ghost_Mode (N);
26180
26181 -- Ensure that the subprogram and its formals are visible when analyzing
26182 -- the expression of the pragma.
26183
26184 if not In_Open_Scopes (Spec_Id) then
26185 Restore_Scope := True;
26186 Push_Scope (Spec_Id);
26187
26188 if Is_Generic_Subprogram (Spec_Id) then
26189 Install_Generic_Formals (Spec_Id);
26190 else
26191 Install_Formals (Spec_Id);
26192 end if;
26193 end if;
26194
26195 Errors := Serious_Errors_Detected;
26196 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
26197
26198 -- Emit a clarification message when the expression contains at least
26199 -- one undefined reference, possibly due to contract freezing.
26200
26201 if Errors /= Serious_Errors_Detected
26202 and then Present (Freeze_Id)
26203 and then Has_Undefined_Reference (Expr)
26204 then
26205 Contract_Freeze_Error (Spec_Id, Freeze_Id);
26206 end if;
26207
26208 if Class_Present (N) then
26209
26210 -- Verify that a class-wide condition is legal, i.e. the operation is
26211 -- a primitive of a tagged type.
26212
26213 if not Is_Dispatching_Operation (Spec_Id) then
26214 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
26215
26216 if From_Aspect_Specification (N) then
26217 Error_Msg_N
26218 ("aspect % can only be specified for a primitive operation "
26219 & "of a tagged type", Corresponding_Aspect (N));
26220
26221 -- The pragma is a source construct
26222
26223 else
26224 Error_Msg_N
26225 ("pragma % can only be specified for a primitive operation "
26226 & "of a tagged type", N);
26227 end if;
26228
26229 -- Remaining semantic checks require a full tree traversal
26230
26231 else
26232 Disp_Typ := Find_Dispatching_Type (Spec_Id);
26233 Check_Class_Wide_Condition (Expr);
26234 end if;
26235
26236 end if;
26237
26238 if Restore_Scope then
26239 End_Scope;
26240 end if;
26241
26242 -- Currently it is not possible to inline pre/postconditions on a
26243 -- subprogram subject to pragma Inline_Always.
26244
26245 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
26246 Set_Is_Analyzed_Pragma (N);
26247
26248 -- If the subprogram is frozen then its class-wide pre- and post-
26249 -- conditions have been preanalyzed (see Merge_Class_Conditions);
26250 -- otherwise they must be preanalyzed now to ensure the correct
26251 -- visibility of their referenced entities. This scenario occurs
26252 -- when the subprogram is defined in a nested package (since the
26253 -- end of the package does not cause freezing).
26254
26255 if Class_Present (N)
26256 and then Is_Dispatching_Operation (Spec_Id)
26257 and then not Is_Frozen (Spec_Id)
26258 then
26259 Preanalyze_Class_Conditions (Spec_Id);
26260 end if;
26261
26262 Restore_Ghost_Region (Saved_GM, Saved_IGR);
26263 end Analyze_Pre_Post_Condition_In_Decl_Part;
26264
26265 ------------------------------------------
26266 -- Analyze_Refined_Depends_In_Decl_Part --
26267 ------------------------------------------
26268
26269 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
26270 procedure Check_Dependency_Clause
26271 (Spec_Id : Entity_Id;
26272 Dep_Clause : Node_Id;
26273 Dep_States : Elist_Id;
26274 Refinements : List_Id;
26275 Matched_Items : in out Elist_Id);
26276 -- Try to match a single dependency clause Dep_Clause against one or
26277 -- more refinement clauses found in list Refinements. Each successful
26278 -- match eliminates at least one refinement clause from Refinements.
26279 -- Spec_Id denotes the entity of the related subprogram. Dep_States
26280 -- denotes the entities of all abstract states which appear in pragma
26281 -- Depends. Matched_Items contains the entities of all successfully
26282 -- matched items found in pragma Depends.
26283
26284 procedure Check_Output_States
26285 (Spec_Inputs : Elist_Id;
26286 Spec_Outputs : Elist_Id;
26287 Body_Inputs : Elist_Id;
26288 Body_Outputs : Elist_Id);
26289 -- Determine whether pragma Depends contains an output state with a
26290 -- visible refinement and if so, ensure that pragma Refined_Depends
26291 -- mentions all its constituents as outputs. Spec_Inputs and
26292 -- Spec_Outputs denote the inputs and outputs of the subprogram spec
26293 -- synthesized from pragma Depends. Body_Inputs and Body_Outputs denote
26294 -- the inputs and outputs of the subprogram body synthesized from pragma
26295 -- Refined_Depends.
26296
26297 function Collect_States (Clauses : List_Id) return Elist_Id;
26298 -- Given a normalized list of dependencies obtained from calling
26299 -- Normalize_Clauses, return a list containing the entities of all
26300 -- states appearing in dependencies. It helps in checking refinements
26301 -- involving a state and a corresponding constituent which is not a
26302 -- direct constituent of the state.
26303
26304 procedure Normalize_Clauses (Clauses : List_Id);
26305 -- Given a list of dependence or refinement clauses Clauses, normalize
26306 -- each clause by creating multiple dependencies with exactly one input
26307 -- and one output.
26308
26309 procedure Remove_Extra_Clauses
26310 (Clauses : List_Id;
26311 Matched_Items : Elist_Id);
26312 -- Given a list of refinement clauses Clauses, remove all clauses whose
26313 -- inputs and/or outputs have been previously matched. See the body for
26314 -- all special cases. Matched_Items contains the entities of all matched
26315 -- items found in pragma Depends.
26316
26317 procedure Report_Extra_Clauses (Clauses : List_Id);
26318 -- Emit an error for each extra clause found in list Clauses
26319
26320 -----------------------------
26321 -- Check_Dependency_Clause --
26322 -----------------------------
26323
26324 procedure Check_Dependency_Clause
26325 (Spec_Id : Entity_Id;
26326 Dep_Clause : Node_Id;
26327 Dep_States : Elist_Id;
26328 Refinements : List_Id;
26329 Matched_Items : in out Elist_Id)
26330 is
26331 Dep_Input : constant Node_Id := Expression (Dep_Clause);
26332 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
26333
26334 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
26335 -- Determine whether dependency item Dep_Item has been matched in a
26336 -- previous clause.
26337
26338 function Is_In_Out_State_Clause return Boolean;
26339 -- Determine whether dependence clause Dep_Clause denotes an abstract
26340 -- state that depends on itself (State => State).
26341
26342 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
26343 -- Determine whether item Item denotes an abstract state with visible
26344 -- null refinement.
26345
26346 procedure Match_Items
26347 (Dep_Item : Node_Id;
26348 Ref_Item : Node_Id;
26349 Matched : out Boolean);
26350 -- Try to match dependence item Dep_Item against refinement item
26351 -- Ref_Item. To match against a possible null refinement (see 2, 9),
26352 -- set Ref_Item to Empty. Flag Matched is set to True when one of
26353 -- the following conformance scenarios is in effect:
26354 -- 1) Both items denote null
26355 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
26356 -- 3) Both items denote attribute 'Result
26357 -- 4) Both items denote the same object
26358 -- 5) Both items denote the same formal parameter
26359 -- 6) Both items denote the same current instance of a type
26360 -- 7) Both items denote the same discriminant
26361 -- 8) Dep_Item is an abstract state with visible null refinement
26362 -- and Ref_Item denotes null.
26363 -- 9) Dep_Item is an abstract state with visible null refinement
26364 -- and Ref_Item is Empty (special case).
26365 -- 10) Dep_Item is an abstract state with full or partial visible
26366 -- non-null refinement and Ref_Item denotes one of its
26367 -- constituents.
26368 -- 11) Dep_Item is an abstract state without a full visible
26369 -- refinement and Ref_Item denotes the same state.
26370 -- When scenario 10 is in effect, the entity of the abstract state
26371 -- denoted by Dep_Item is added to list Refined_States.
26372
26373 procedure Record_Item (Item_Id : Entity_Id);
26374 -- Store the entity of an item denoted by Item_Id in Matched_Items
26375
26376 ------------------------
26377 -- Is_Already_Matched --
26378 ------------------------
26379
26380 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean is
26381 Item_Id : Entity_Id := Empty;
26382
26383 begin
26384 -- When the dependency item denotes attribute 'Result, check for
26385 -- the entity of the related subprogram.
26386
26387 if Is_Attribute_Result (Dep_Item) then
26388 Item_Id := Spec_Id;
26389
26390 elsif Is_Entity_Name (Dep_Item) then
26391 Item_Id := Available_View (Entity_Of (Dep_Item));
26392 end if;
26393
26394 return
26395 Present (Item_Id) and then Contains (Matched_Items, Item_Id);
26396 end Is_Already_Matched;
26397
26398 ----------------------------
26399 -- Is_In_Out_State_Clause --
26400 ----------------------------
26401
26402 function Is_In_Out_State_Clause return Boolean is
26403 Dep_Input_Id : Entity_Id;
26404 Dep_Output_Id : Entity_Id;
26405
26406 begin
26407 -- Detect the following clause:
26408 -- State => State
26409
26410 if Is_Entity_Name (Dep_Input)
26411 and then Is_Entity_Name (Dep_Output)
26412 then
26413 -- Handle abstract views generated for limited with clauses
26414
26415 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
26416 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
26417
26418 return
26419 Ekind (Dep_Input_Id) = E_Abstract_State
26420 and then Dep_Input_Id = Dep_Output_Id;
26421 else
26422 return False;
26423 end if;
26424 end Is_In_Out_State_Clause;
26425
26426 ---------------------------
26427 -- Is_Null_Refined_State --
26428 ---------------------------
26429
26430 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
26431 Item_Id : Entity_Id;
26432
26433 begin
26434 if Is_Entity_Name (Item) then
26435
26436 -- Handle abstract views generated for limited with clauses
26437
26438 Item_Id := Available_View (Entity_Of (Item));
26439
26440 return
26441 Ekind (Item_Id) = E_Abstract_State
26442 and then Has_Null_Visible_Refinement (Item_Id);
26443 else
26444 return False;
26445 end if;
26446 end Is_Null_Refined_State;
26447
26448 -----------------
26449 -- Match_Items --
26450 -----------------
26451
26452 procedure Match_Items
26453 (Dep_Item : Node_Id;
26454 Ref_Item : Node_Id;
26455 Matched : out Boolean)
26456 is
26457 Dep_Item_Id : Entity_Id;
26458 Ref_Item_Id : Entity_Id;
26459
26460 begin
26461 -- Assume that the two items do not match
26462
26463 Matched := False;
26464
26465 -- A null matches null or Empty (special case)
26466
26467 if Nkind (Dep_Item) = N_Null
26468 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
26469 then
26470 Matched := True;
26471
26472 -- Attribute 'Result matches attribute 'Result
26473
26474 elsif Is_Attribute_Result (Dep_Item)
26475 and then Is_Attribute_Result (Ref_Item)
26476 then
26477 -- Put the entity of the related function on the list of
26478 -- matched items because attribute 'Result does not carry
26479 -- an entity similar to states and constituents.
26480
26481 Record_Item (Spec_Id);
26482 Matched := True;
26483
26484 -- Abstract states, current instances of concurrent types,
26485 -- discriminants, formal parameters and objects.
26486
26487 elsif Is_Entity_Name (Dep_Item) then
26488
26489 -- Handle abstract views generated for limited with clauses
26490
26491 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
26492
26493 if Ekind (Dep_Item_Id) = E_Abstract_State then
26494
26495 -- An abstract state with visible null refinement matches
26496 -- null or Empty (special case).
26497
26498 if Has_Null_Visible_Refinement (Dep_Item_Id)
26499 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
26500 then
26501 Record_Item (Dep_Item_Id);
26502 Matched := True;
26503
26504 -- An abstract state with visible non-null refinement
26505 -- matches one of its constituents, or itself for an
26506 -- abstract state with partial visible refinement.
26507
26508 elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then
26509 if Is_Entity_Name (Ref_Item) then
26510 Ref_Item_Id := Entity_Of (Ref_Item);
26511
26512 if Ekind (Ref_Item_Id) in
26513 E_Abstract_State | E_Constant | E_Variable
26514 and then Present (Encapsulating_State (Ref_Item_Id))
26515 and then Find_Encapsulating_State
26516 (Dep_States, Ref_Item_Id) = Dep_Item_Id
26517 then
26518 Record_Item (Dep_Item_Id);
26519 Matched := True;
26520
26521 elsif not Has_Visible_Refinement (Dep_Item_Id)
26522 and then Ref_Item_Id = Dep_Item_Id
26523 then
26524 Record_Item (Dep_Item_Id);
26525 Matched := True;
26526 end if;
26527 end if;
26528
26529 -- An abstract state without a visible refinement matches
26530 -- itself.
26531
26532 elsif Is_Entity_Name (Ref_Item)
26533 and then Entity_Of (Ref_Item) = Dep_Item_Id
26534 then
26535 Record_Item (Dep_Item_Id);
26536 Matched := True;
26537 end if;
26538
26539 -- A current instance of a concurrent type, discriminant,
26540 -- formal parameter or an object matches itself.
26541
26542 elsif Is_Entity_Name (Ref_Item)
26543 and then Entity_Of (Ref_Item) = Dep_Item_Id
26544 then
26545 Record_Item (Dep_Item_Id);
26546 Matched := True;
26547 end if;
26548 end if;
26549 end Match_Items;
26550
26551 -----------------
26552 -- Record_Item --
26553 -----------------
26554
26555 procedure Record_Item (Item_Id : Entity_Id) is
26556 begin
26557 if No (Matched_Items) then
26558 Matched_Items := New_Elmt_List;
26559 end if;
26560
26561 Append_Unique_Elmt (Item_Id, Matched_Items);
26562 end Record_Item;
26563
26564 -- Local variables
26565
26566 Clause_Matched : Boolean := False;
26567 Dummy : Boolean := False;
26568 Inputs_Match : Boolean;
26569 Next_Ref_Clause : Node_Id;
26570 Outputs_Match : Boolean;
26571 Ref_Clause : Node_Id;
26572 Ref_Input : Node_Id;
26573 Ref_Output : Node_Id;
26574
26575 -- Start of processing for Check_Dependency_Clause
26576
26577 begin
26578 -- Do not perform this check in an instance because it was already
26579 -- performed successfully in the generic template.
26580
26581 if In_Instance then
26582 return;
26583 end if;
26584
26585 -- Examine all refinement clauses and compare them against the
26586 -- dependence clause.
26587
26588 Ref_Clause := First (Refinements);
26589 while Present (Ref_Clause) loop
26590 Next_Ref_Clause := Next (Ref_Clause);
26591
26592 -- Obtain the attributes of the current refinement clause
26593
26594 Ref_Input := Expression (Ref_Clause);
26595 Ref_Output := First (Choices (Ref_Clause));
26596
26597 -- The current refinement clause matches the dependence clause
26598 -- when both outputs match and both inputs match. See routine
26599 -- Match_Items for all possible conformance scenarios.
26600
26601 -- Depends Dep_Output => Dep_Input
26602 -- ^ ^
26603 -- match ? match ?
26604 -- v v
26605 -- Refined_Depends Ref_Output => Ref_Input
26606
26607 Match_Items
26608 (Dep_Item => Dep_Input,
26609 Ref_Item => Ref_Input,
26610 Matched => Inputs_Match);
26611
26612 Match_Items
26613 (Dep_Item => Dep_Output,
26614 Ref_Item => Ref_Output,
26615 Matched => Outputs_Match);
26616
26617 -- An In_Out state clause may be matched against a refinement with
26618 -- a null input or null output as long as the non-null side of the
26619 -- relation contains a valid constituent of the In_Out_State.
26620
26621 if Is_In_Out_State_Clause then
26622
26623 -- Depends => (State => State)
26624 -- Refined_Depends => (null => Constit) -- OK
26625
26626 if Inputs_Match
26627 and then not Outputs_Match
26628 and then Nkind (Ref_Output) = N_Null
26629 then
26630 Outputs_Match := True;
26631 end if;
26632
26633 -- Depends => (State => State)
26634 -- Refined_Depends => (Constit => null) -- OK
26635
26636 if not Inputs_Match
26637 and then Outputs_Match
26638 and then Nkind (Ref_Input) = N_Null
26639 then
26640 Inputs_Match := True;
26641 end if;
26642 end if;
26643
26644 -- The current refinement clause is legally constructed following
26645 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
26646 -- the pool of candidates. The search continues because a single
26647 -- dependence clause may have multiple matching refinements.
26648
26649 if Inputs_Match and Outputs_Match then
26650 Clause_Matched := True;
26651 Remove (Ref_Clause);
26652 end if;
26653
26654 Ref_Clause := Next_Ref_Clause;
26655 end loop;
26656
26657 -- Depending on the order or composition of refinement clauses, an
26658 -- In_Out state clause may not be directly refinable.
26659
26660 -- Refined_State => (State => (Constit_1, Constit_2))
26661 -- Depends => ((Output, State) => (Input, State))
26662 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
26663
26664 -- Matching normalized clause (State => State) fails because there is
26665 -- no direct refinement capable of satisfying this relation. Another
26666 -- similar case arises when clauses (Constit_1 => Input) and (Output
26667 -- => Constit_2) are matched first, leaving no candidates for clause
26668 -- (State => State). Both scenarios are legal as long as one of the
26669 -- previous clauses mentioned a valid constituent of State.
26670
26671 if not Clause_Matched
26672 and then Is_In_Out_State_Clause
26673 and then Is_Already_Matched (Dep_Input)
26674 then
26675 Clause_Matched := True;
26676 end if;
26677
26678 -- A clause where the input is an abstract state with visible null
26679 -- refinement or a 'Result attribute is implicitly matched when the
26680 -- output has already been matched in a previous clause.
26681
26682 -- Refined_State => (State => null)
26683 -- Depends => (Output => State) -- implicitly OK
26684 -- Refined_Depends => (Output => ...)
26685 -- Depends => (...'Result => State) -- implicitly OK
26686 -- Refined_Depends => (...'Result => ...)
26687
26688 if not Clause_Matched
26689 and then Is_Null_Refined_State (Dep_Input)
26690 and then Is_Already_Matched (Dep_Output)
26691 then
26692 Clause_Matched := True;
26693 end if;
26694
26695 -- A clause where the output is an abstract state with visible null
26696 -- refinement is implicitly matched when the input has already been
26697 -- matched in a previous clause.
26698
26699 -- Refined_State => (State => null)
26700 -- Depends => (State => Input) -- implicitly OK
26701 -- Refined_Depends => (... => Input)
26702
26703 if not Clause_Matched
26704 and then Is_Null_Refined_State (Dep_Output)
26705 and then Is_Already_Matched (Dep_Input)
26706 then
26707 Clause_Matched := True;
26708 end if;
26709
26710 -- At this point either all refinement clauses have been examined or
26711 -- pragma Refined_Depends contains a solitary null. Only an abstract
26712 -- state with null refinement can possibly match these cases.
26713
26714 -- Refined_State => (State => null)
26715 -- Depends => (State => null)
26716 -- Refined_Depends => null -- OK
26717
26718 if not Clause_Matched then
26719 Match_Items
26720 (Dep_Item => Dep_Input,
26721 Ref_Item => Empty,
26722 Matched => Inputs_Match);
26723
26724 Match_Items
26725 (Dep_Item => Dep_Output,
26726 Ref_Item => Empty,
26727 Matched => Outputs_Match);
26728
26729 Clause_Matched := Inputs_Match and Outputs_Match;
26730 end if;
26731
26732 -- If the contents of Refined_Depends are legal, then the current
26733 -- dependence clause should be satisfied either by an explicit match
26734 -- or by one of the special cases.
26735
26736 if not Clause_Matched then
26737 SPARK_Msg_NE
26738 (Fix_Msg (Spec_Id, "dependence clause of subprogram & has no "
26739 & "matching refinement in body"), Dep_Clause, Spec_Id);
26740 end if;
26741 end Check_Dependency_Clause;
26742
26743 -------------------------
26744 -- Check_Output_States --
26745 -------------------------
26746
26747 procedure Check_Output_States
26748 (Spec_Inputs : Elist_Id;
26749 Spec_Outputs : Elist_Id;
26750 Body_Inputs : Elist_Id;
26751 Body_Outputs : Elist_Id)
26752 is
26753 procedure Check_Constituent_Usage (State_Id : Entity_Id);
26754 -- Determine whether all constituents of state State_Id with full
26755 -- visible refinement are used as outputs in pragma Refined_Depends.
26756 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
26757
26758 -----------------------------
26759 -- Check_Constituent_Usage --
26760 -----------------------------
26761
26762 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
26763 Constits : constant Elist_Id :=
26764 Partial_Refinement_Constituents (State_Id);
26765 Constit_Elmt : Elmt_Id;
26766 Constit_Id : Entity_Id;
26767 Only_Partial : constant Boolean :=
26768 not Has_Visible_Refinement (State_Id);
26769 Posted : Boolean := False;
26770
26771 begin
26772 if Present (Constits) then
26773 Constit_Elmt := First_Elmt (Constits);
26774 while Present (Constit_Elmt) loop
26775 Constit_Id := Node (Constit_Elmt);
26776
26777 -- Issue an error when a constituent of State_Id is used,
26778 -- and State_Id has only partial visible refinement
26779 -- (SPARK RM 7.2.4(3d)).
26780
26781 if Only_Partial then
26782 if (Present (Body_Inputs)
26783 and then Appears_In (Body_Inputs, Constit_Id))
26784 or else
26785 (Present (Body_Outputs)
26786 and then Appears_In (Body_Outputs, Constit_Id))
26787 then
26788 Error_Msg_Name_1 := Chars (State_Id);
26789 SPARK_Msg_NE
26790 ("constituent & of state % cannot be used in "
26791 & "dependence refinement", N, Constit_Id);
26792 Error_Msg_Name_1 := Chars (State_Id);
26793 SPARK_Msg_N ("\use state % instead", N);
26794 end if;
26795
26796 -- The constituent acts as an input (SPARK RM 7.2.5(3))
26797
26798 elsif Present (Body_Inputs)
26799 and then Appears_In (Body_Inputs, Constit_Id)
26800 then
26801 Error_Msg_Name_1 := Chars (State_Id);
26802 SPARK_Msg_NE
26803 ("constituent & of state % must act as output in "
26804 & "dependence refinement", N, Constit_Id);
26805
26806 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
26807
26808 elsif No (Body_Outputs)
26809 or else not Appears_In (Body_Outputs, Constit_Id)
26810 then
26811 if not Posted then
26812 Posted := True;
26813 SPARK_Msg_NE
26814 ("output state & must be replaced by all its "
26815 & "constituents in dependence refinement",
26816 N, State_Id);
26817 end if;
26818
26819 SPARK_Msg_NE
26820 ("\constituent & is missing in output list",
26821 N, Constit_Id);
26822 end if;
26823
26824 Next_Elmt (Constit_Elmt);
26825 end loop;
26826 end if;
26827 end Check_Constituent_Usage;
26828
26829 -- Local variables
26830
26831 Item : Node_Id;
26832 Item_Elmt : Elmt_Id;
26833 Item_Id : Entity_Id;
26834
26835 -- Start of processing for Check_Output_States
26836
26837 begin
26838 -- Do not perform this check in an instance because it was already
26839 -- performed successfully in the generic template.
26840
26841 if In_Instance then
26842 null;
26843
26844 -- Inspect the outputs of pragma Depends looking for a state with a
26845 -- visible refinement.
26846
26847 elsif Present (Spec_Outputs) then
26848 Item_Elmt := First_Elmt (Spec_Outputs);
26849 while Present (Item_Elmt) loop
26850 Item := Node (Item_Elmt);
26851
26852 -- Deal with the mixed nature of the input and output lists
26853
26854 if Nkind (Item) = N_Defining_Identifier then
26855 Item_Id := Item;
26856 else
26857 Item_Id := Available_View (Entity_Of (Item));
26858 end if;
26859
26860 if Ekind (Item_Id) = E_Abstract_State then
26861
26862 -- The state acts as an input-output, skip it
26863
26864 if Present (Spec_Inputs)
26865 and then Appears_In (Spec_Inputs, Item_Id)
26866 then
26867 null;
26868
26869 -- Ensure that all of the constituents are utilized as
26870 -- outputs in pragma Refined_Depends.
26871
26872 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
26873 Check_Constituent_Usage (Item_Id);
26874 end if;
26875 end if;
26876
26877 Next_Elmt (Item_Elmt);
26878 end loop;
26879 end if;
26880 end Check_Output_States;
26881
26882 --------------------
26883 -- Collect_States --
26884 --------------------
26885
26886 function Collect_States (Clauses : List_Id) return Elist_Id is
26887 procedure Collect_State
26888 (Item : Node_Id;
26889 States : in out Elist_Id);
26890 -- Add the entity of Item to list States when it denotes to a state
26891
26892 -------------------
26893 -- Collect_State --
26894 -------------------
26895
26896 procedure Collect_State
26897 (Item : Node_Id;
26898 States : in out Elist_Id)
26899 is
26900 Id : Entity_Id;
26901
26902 begin
26903 if Is_Entity_Name (Item) then
26904 Id := Entity_Of (Item);
26905
26906 if Ekind (Id) = E_Abstract_State then
26907 if No (States) then
26908 States := New_Elmt_List;
26909 end if;
26910
26911 Append_Unique_Elmt (Id, States);
26912 end if;
26913 end if;
26914 end Collect_State;
26915
26916 -- Local variables
26917
26918 Clause : Node_Id;
26919 Input : Node_Id;
26920 Output : Node_Id;
26921 States : Elist_Id := No_Elist;
26922
26923 -- Start of processing for Collect_States
26924
26925 begin
26926 Clause := First (Clauses);
26927 while Present (Clause) loop
26928 Input := Expression (Clause);
26929 Output := First (Choices (Clause));
26930
26931 Collect_State (Input, States);
26932 Collect_State (Output, States);
26933
26934 Next (Clause);
26935 end loop;
26936
26937 return States;
26938 end Collect_States;
26939
26940 -----------------------
26941 -- Normalize_Clauses --
26942 -----------------------
26943
26944 procedure Normalize_Clauses (Clauses : List_Id) is
26945 procedure Normalize_Inputs (Clause : Node_Id);
26946 -- Normalize clause Clause by creating multiple clauses for each
26947 -- input item of Clause. It is assumed that Clause has exactly one
26948 -- output. The transformation is as follows:
26949 --
26950 -- Output => (Input_1, Input_2) -- original
26951 --
26952 -- Output => Input_1 -- normalizations
26953 -- Output => Input_2
26954
26955 procedure Normalize_Outputs (Clause : Node_Id);
26956 -- Normalize clause Clause by creating multiple clause for each
26957 -- output item of Clause. The transformation is as follows:
26958 --
26959 -- (Output_1, Output_2) => Input -- original
26960 --
26961 -- Output_1 => Input -- normalization
26962 -- Output_2 => Input
26963
26964 ----------------------
26965 -- Normalize_Inputs --
26966 ----------------------
26967
26968 procedure Normalize_Inputs (Clause : Node_Id) is
26969 Inputs : constant Node_Id := Expression (Clause);
26970 Loc : constant Source_Ptr := Sloc (Clause);
26971 Output : constant List_Id := Choices (Clause);
26972 Last_Input : Node_Id;
26973 Input : Node_Id;
26974 New_Clause : Node_Id;
26975 Next_Input : Node_Id;
26976
26977 begin
26978 -- Normalization is performed only when the original clause has
26979 -- more than one input. Multiple inputs appear as an aggregate.
26980
26981 if Nkind (Inputs) = N_Aggregate then
26982 Last_Input := Last (Expressions (Inputs));
26983
26984 -- Create a new clause for each input
26985
26986 Input := First (Expressions (Inputs));
26987 while Present (Input) loop
26988 Next_Input := Next (Input);
26989
26990 -- Unhook the current input from the original input list
26991 -- because it will be relocated to a new clause.
26992
26993 Remove (Input);
26994
26995 -- Special processing for the last input. At this point the
26996 -- original aggregate has been stripped down to one element.
26997 -- Replace the aggregate by the element itself.
26998
26999 if Input = Last_Input then
27000 Rewrite (Inputs, Input);
27001
27002 -- Generate a clause of the form:
27003 -- Output => Input
27004
27005 else
27006 New_Clause :=
27007 Make_Component_Association (Loc,
27008 Choices => New_Copy_List_Tree (Output),
27009 Expression => Input);
27010
27011 -- The new clause contains replicated content that has
27012 -- already been analyzed, mark the clause as analyzed.
27013
27014 Set_Analyzed (New_Clause);
27015 Insert_After (Clause, New_Clause);
27016 end if;
27017
27018 Input := Next_Input;
27019 end loop;
27020 end if;
27021 end Normalize_Inputs;
27022
27023 -----------------------
27024 -- Normalize_Outputs --
27025 -----------------------
27026
27027 procedure Normalize_Outputs (Clause : Node_Id) is
27028 Inputs : constant Node_Id := Expression (Clause);
27029 Loc : constant Source_Ptr := Sloc (Clause);
27030 Outputs : constant Node_Id := First (Choices (Clause));
27031 Last_Output : Node_Id;
27032 New_Clause : Node_Id;
27033 Next_Output : Node_Id;
27034 Output : Node_Id;
27035
27036 begin
27037 -- Multiple outputs appear as an aggregate. Nothing to do when
27038 -- the clause has exactly one output.
27039
27040 if Nkind (Outputs) = N_Aggregate then
27041 Last_Output := Last (Expressions (Outputs));
27042
27043 -- Create a clause for each output. Note that each time a new
27044 -- clause is created, the original output list slowly shrinks
27045 -- until there is one item left.
27046
27047 Output := First (Expressions (Outputs));
27048 while Present (Output) loop
27049 Next_Output := Next (Output);
27050
27051 -- Unhook the output from the original output list as it
27052 -- will be relocated to a new clause.
27053
27054 Remove (Output);
27055
27056 -- Special processing for the last output. At this point
27057 -- the original aggregate has been stripped down to one
27058 -- element. Replace the aggregate by the element itself.
27059
27060 if Output = Last_Output then
27061 Rewrite (Outputs, Output);
27062
27063 else
27064 -- Generate a clause of the form:
27065 -- (Output => Inputs)
27066
27067 New_Clause :=
27068 Make_Component_Association (Loc,
27069 Choices => New_List (Output),
27070 Expression => New_Copy_Tree (Inputs));
27071
27072 -- The new clause contains replicated content that has
27073 -- already been analyzed. There is not need to reanalyze
27074 -- them.
27075
27076 Set_Analyzed (New_Clause);
27077 Insert_After (Clause, New_Clause);
27078 end if;
27079
27080 Output := Next_Output;
27081 end loop;
27082 end if;
27083 end Normalize_Outputs;
27084
27085 -- Local variables
27086
27087 Clause : Node_Id;
27088
27089 -- Start of processing for Normalize_Clauses
27090
27091 begin
27092 Clause := First (Clauses);
27093 while Present (Clause) loop
27094 Normalize_Outputs (Clause);
27095 Next (Clause);
27096 end loop;
27097
27098 Clause := First (Clauses);
27099 while Present (Clause) loop
27100 Normalize_Inputs (Clause);
27101 Next (Clause);
27102 end loop;
27103 end Normalize_Clauses;
27104
27105 --------------------------
27106 -- Remove_Extra_Clauses --
27107 --------------------------
27108
27109 procedure Remove_Extra_Clauses
27110 (Clauses : List_Id;
27111 Matched_Items : Elist_Id)
27112 is
27113 Clause : Node_Id;
27114 Input : Node_Id;
27115 Input_Id : Entity_Id;
27116 Next_Clause : Node_Id;
27117 Output : Node_Id;
27118 State_Id : Entity_Id;
27119
27120 begin
27121 Clause := First (Clauses);
27122 while Present (Clause) loop
27123 Next_Clause := Next (Clause);
27124
27125 Input := Expression (Clause);
27126 Output := First (Choices (Clause));
27127
27128 -- Recognize a clause of the form
27129
27130 -- null => Input
27131
27132 -- where Input is a constituent of a state which was already
27133 -- successfully matched. This clause must be removed because it
27134 -- simply indicates that some of the constituents of the state
27135 -- are not used.
27136
27137 -- Refined_State => (State => (Constit_1, Constit_2))
27138 -- Depends => (Output => State)
27139 -- Refined_Depends => ((Output => Constit_1), -- State matched
27140 -- (null => Constit_2)) -- OK
27141
27142 if Nkind (Output) = N_Null and then Is_Entity_Name (Input) then
27143
27144 -- Handle abstract views generated for limited with clauses
27145
27146 Input_Id := Available_View (Entity_Of (Input));
27147
27148 -- The input must be a constituent of a state
27149
27150 if Ekind (Input_Id) in
27151 E_Abstract_State | E_Constant | E_Variable
27152 and then Present (Encapsulating_State (Input_Id))
27153 then
27154 State_Id := Encapsulating_State (Input_Id);
27155
27156 -- The state must have a non-null visible refinement and be
27157 -- matched in a previous clause.
27158
27159 if Has_Non_Null_Visible_Refinement (State_Id)
27160 and then Contains (Matched_Items, State_Id)
27161 then
27162 Remove (Clause);
27163 end if;
27164 end if;
27165
27166 -- Recognize a clause of the form
27167
27168 -- Output => null
27169
27170 -- where Output is an arbitrary item. This clause must be removed
27171 -- because a null input legitimately matches anything.
27172
27173 elsif Nkind (Input) = N_Null then
27174 Remove (Clause);
27175 end if;
27176
27177 Clause := Next_Clause;
27178 end loop;
27179 end Remove_Extra_Clauses;
27180
27181 --------------------------
27182 -- Report_Extra_Clauses --
27183 --------------------------
27184
27185 procedure Report_Extra_Clauses (Clauses : List_Id) is
27186 Clause : Node_Id;
27187
27188 begin
27189 -- Do not perform this check in an instance because it was already
27190 -- performed successfully in the generic template.
27191
27192 if In_Instance then
27193 null;
27194
27195 elsif Present (Clauses) then
27196 Clause := First (Clauses);
27197 while Present (Clause) loop
27198 SPARK_Msg_N
27199 ("unmatched or extra clause in dependence refinement",
27200 Clause);
27201
27202 Next (Clause);
27203 end loop;
27204 end if;
27205 end Report_Extra_Clauses;
27206
27207 -- Local variables
27208
27209 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
27210 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
27211 Errors : constant Nat := Serious_Errors_Detected;
27212
27213 Clause : Node_Id;
27214 Deps : Node_Id;
27215 Dummy : Boolean;
27216 Refs : Node_Id;
27217
27218 Body_Inputs : Elist_Id := No_Elist;
27219 Body_Outputs : Elist_Id := No_Elist;
27220 -- The inputs and outputs of the subprogram body synthesized from pragma
27221 -- Refined_Depends.
27222
27223 Dependencies : List_Id := No_List;
27224 Depends : Node_Id;
27225 -- The corresponding Depends pragma along with its clauses
27226
27227 Matched_Items : Elist_Id := No_Elist;
27228 -- A list containing the entities of all successfully matched items
27229 -- found in pragma Depends.
27230
27231 Refinements : List_Id := No_List;
27232 -- The clauses of pragma Refined_Depends
27233
27234 Spec_Id : Entity_Id;
27235 -- The entity of the subprogram subject to pragma Refined_Depends
27236
27237 Spec_Inputs : Elist_Id := No_Elist;
27238 Spec_Outputs : Elist_Id := No_Elist;
27239 -- The inputs and outputs of the subprogram spec synthesized from pragma
27240 -- Depends.
27241
27242 States : Elist_Id := No_Elist;
27243 -- A list containing the entities of all states whose constituents
27244 -- appear in pragma Depends.
27245
27246 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
27247
27248 begin
27249 -- Do not analyze the pragma multiple times
27250
27251 if Is_Analyzed_Pragma (N) then
27252 return;
27253 end if;
27254
27255 Spec_Id := Unique_Defining_Entity (Body_Decl);
27256
27257 -- Use the anonymous object as the proper spec when Refined_Depends
27258 -- applies to the body of a single task type. The object carries the
27259 -- proper Chars as well as all non-refined versions of pragmas.
27260
27261 if Is_Single_Concurrent_Type (Spec_Id) then
27262 Spec_Id := Anonymous_Object (Spec_Id);
27263 end if;
27264
27265 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
27266
27267 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
27268 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
27269
27270 if No (Depends) then
27271 SPARK_Msg_NE
27272 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
27273 & "& lacks aspect or pragma Depends"), N, Spec_Id);
27274 goto Leave;
27275 end if;
27276
27277 Deps := Expression (Get_Argument (Depends, Spec_Id));
27278
27279 -- A null dependency relation renders the refinement useless because it
27280 -- cannot possibly mention abstract states with visible refinement. Note
27281 -- that the inverse is not true as states may be refined to null
27282 -- (SPARK RM 7.2.5(2)).
27283
27284 if Nkind (Deps) = N_Null then
27285 SPARK_Msg_NE
27286 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
27287 & "depend on abstract state with visible refinement"), N, Spec_Id);
27288 goto Leave;
27289 end if;
27290
27291 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
27292 -- This ensures that the categorization of all refined dependency items
27293 -- is consistent with their role.
27294
27295 Analyze_Depends_In_Decl_Part (N);
27296
27297 -- Do not match dependencies against refinements if Refined_Depends is
27298 -- illegal to avoid emitting misleading error.
27299
27300 if Serious_Errors_Detected = Errors then
27301
27302 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
27303 -- the inputs and outputs of the subprogram spec and body to verify
27304 -- the use of states with visible refinement and their constituents.
27305
27306 if No (Get_Pragma (Spec_Id, Pragma_Global))
27307 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
27308 then
27309 Collect_Subprogram_Inputs_Outputs
27310 (Subp_Id => Spec_Id,
27311 Synthesize => True,
27312 Subp_Inputs => Spec_Inputs,
27313 Subp_Outputs => Spec_Outputs,
27314 Global_Seen => Dummy);
27315
27316 Collect_Subprogram_Inputs_Outputs
27317 (Subp_Id => Body_Id,
27318 Synthesize => True,
27319 Subp_Inputs => Body_Inputs,
27320 Subp_Outputs => Body_Outputs,
27321 Global_Seen => Dummy);
27322
27323 -- For an output state with a visible refinement, ensure that all
27324 -- constituents appear as outputs in the dependency refinement.
27325
27326 Check_Output_States
27327 (Spec_Inputs => Spec_Inputs,
27328 Spec_Outputs => Spec_Outputs,
27329 Body_Inputs => Body_Inputs,
27330 Body_Outputs => Body_Outputs);
27331 end if;
27332
27333 -- Multiple dependency clauses appear as component associations of an
27334 -- aggregate. Note that the clauses are copied because the algorithm
27335 -- modifies them and this should not be visible in Depends.
27336
27337 pragma Assert (Nkind (Deps) = N_Aggregate);
27338 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
27339 Normalize_Clauses (Dependencies);
27340
27341 -- Gather all states which appear in Depends
27342
27343 States := Collect_States (Dependencies);
27344
27345 Refs := Expression (Get_Argument (N, Spec_Id));
27346
27347 if Nkind (Refs) = N_Null then
27348 Refinements := No_List;
27349
27350 -- Multiple dependency clauses appear as component associations of an
27351 -- aggregate. Note that the clauses are copied because the algorithm
27352 -- modifies them and this should not be visible in Refined_Depends.
27353
27354 else pragma Assert (Nkind (Refs) = N_Aggregate);
27355 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
27356 Normalize_Clauses (Refinements);
27357 end if;
27358
27359 -- At this point the clauses of pragmas Depends and Refined_Depends
27360 -- have been normalized into simple dependencies between one output
27361 -- and one input. Examine all clauses of pragma Depends looking for
27362 -- matching clauses in pragma Refined_Depends.
27363
27364 Clause := First (Dependencies);
27365 while Present (Clause) loop
27366 Check_Dependency_Clause
27367 (Spec_Id => Spec_Id,
27368 Dep_Clause => Clause,
27369 Dep_States => States,
27370 Refinements => Refinements,
27371 Matched_Items => Matched_Items);
27372
27373 Next (Clause);
27374 end loop;
27375
27376 -- Pragma Refined_Depends may contain multiple clarification clauses
27377 -- which indicate that certain constituents do not influence the data
27378 -- flow in any way. Such clauses must be removed as long as the state
27379 -- has been matched, otherwise they will be incorrectly flagged as
27380 -- unmatched.
27381
27382 -- Refined_State => (State => (Constit_1, Constit_2))
27383 -- Depends => (Output => State)
27384 -- Refined_Depends => ((Output => Constit_1), -- State matched
27385 -- (null => Constit_2)) -- must be removed
27386
27387 Remove_Extra_Clauses (Refinements, Matched_Items);
27388
27389 if Serious_Errors_Detected = Errors then
27390 Report_Extra_Clauses (Refinements);
27391 end if;
27392 end if;
27393
27394 <<Leave>>
27395 Set_Is_Analyzed_Pragma (N);
27396 end Analyze_Refined_Depends_In_Decl_Part;
27397
27398 -----------------------------------------
27399 -- Analyze_Refined_Global_In_Decl_Part --
27400 -----------------------------------------
27401
27402 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
27403 Global : Node_Id;
27404 -- The corresponding Global pragma
27405
27406 Has_In_State : Boolean := False;
27407 Has_In_Out_State : Boolean := False;
27408 Has_Out_State : Boolean := False;
27409 Has_Proof_In_State : Boolean := False;
27410 -- These flags are set when the corresponding Global pragma has a state
27411 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
27412 -- refinement.
27413
27414 Has_Null_State : Boolean := False;
27415 -- This flag is set when the corresponding Global pragma has at least
27416 -- one state with a null refinement.
27417
27418 In_Constits : Elist_Id := No_Elist;
27419 In_Out_Constits : Elist_Id := No_Elist;
27420 Out_Constits : Elist_Id := No_Elist;
27421 Proof_In_Constits : Elist_Id := No_Elist;
27422 -- These lists contain the entities of all Input, In_Out, Output and
27423 -- Proof_In constituents that appear in Refined_Global and participate
27424 -- in state refinement.
27425
27426 In_Items : Elist_Id := No_Elist;
27427 In_Out_Items : Elist_Id := No_Elist;
27428 Out_Items : Elist_Id := No_Elist;
27429 Proof_In_Items : Elist_Id := No_Elist;
27430 -- These lists contain the entities of all Input, In_Out, Output and
27431 -- Proof_In items defined in the corresponding Global pragma.
27432
27433 Repeat_Items : Elist_Id := No_Elist;
27434 -- A list of all global items without full visible refinement found
27435 -- in pragma Global. These states should be repeated in the global
27436 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
27437 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
27438
27439 Spec_Id : Entity_Id;
27440 -- The entity of the subprogram subject to pragma Refined_Global
27441
27442 States : Elist_Id := No_Elist;
27443 -- A list of all states with full or partial visible refinement found in
27444 -- pragma Global.
27445
27446 procedure Check_In_Out_States;
27447 -- Determine whether the corresponding Global pragma mentions In_Out
27448 -- states with visible refinement and if so, ensure that one of the
27449 -- following completions apply to the constituents of the state:
27450 -- 1) there is at least one constituent of mode In_Out
27451 -- 2) there is at least one Input and one Output constituent
27452 -- 3) not all constituents are present and one of them is of mode
27453 -- Output.
27454 -- This routine may remove elements from In_Constits, In_Out_Constits,
27455 -- Out_Constits and Proof_In_Constits.
27456
27457 procedure Check_Input_States;
27458 -- Determine whether the corresponding Global pragma mentions Input
27459 -- states with visible refinement and if so, ensure that at least one of
27460 -- its constituents appears as an Input item in Refined_Global.
27461 -- This routine may remove elements from In_Constits, In_Out_Constits,
27462 -- Out_Constits and Proof_In_Constits.
27463
27464 procedure Check_Output_States;
27465 -- Determine whether the corresponding Global pragma mentions Output
27466 -- states with visible refinement and if so, ensure that all of its
27467 -- constituents appear as Output items in Refined_Global.
27468 -- This routine may remove elements from In_Constits, In_Out_Constits,
27469 -- Out_Constits and Proof_In_Constits.
27470
27471 procedure Check_Proof_In_States;
27472 -- Determine whether the corresponding Global pragma mentions Proof_In
27473 -- states with visible refinement and if so, ensure that at least one of
27474 -- its constituents appears as a Proof_In item in Refined_Global.
27475 -- This routine may remove elements from In_Constits, In_Out_Constits,
27476 -- Out_Constits and Proof_In_Constits.
27477
27478 procedure Check_Refined_Global_List
27479 (List : Node_Id;
27480 Global_Mode : Name_Id := Name_Input);
27481 -- Verify the legality of a single global list declaration. Global_Mode
27482 -- denotes the current mode in effect.
27483
27484 procedure Collect_Global_Items
27485 (List : Node_Id;
27486 Mode : Name_Id := Name_Input);
27487 -- Gather all Input, In_Out, Output and Proof_In items from node List
27488 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
27489 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
27490 -- and Has_Proof_In_State are set when there is at least one abstract
27491 -- state with full or partial visible refinement available in the
27492 -- corresponding mode. Flag Has_Null_State is set when at least state
27493 -- has a null refinement. Mode denotes the current global mode in
27494 -- effect.
27495
27496 function Present_Then_Remove
27497 (List : Elist_Id;
27498 Item : Entity_Id) return Boolean;
27499 -- Search List for a particular entity Item. If Item has been found,
27500 -- remove it from List. This routine is used to strip lists In_Constits,
27501 -- In_Out_Constits and Out_Constits of valid constituents.
27502
27503 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id);
27504 -- Same as function Present_Then_Remove, but do not report the presence
27505 -- of Item in List.
27506
27507 procedure Report_Extra_Constituents;
27508 -- Emit an error for each constituent found in lists In_Constits,
27509 -- In_Out_Constits and Out_Constits.
27510
27511 procedure Report_Missing_Items;
27512 -- Emit an error for each global item not repeated found in list
27513 -- Repeat_Items.
27514
27515 -------------------------
27516 -- Check_In_Out_States --
27517 -------------------------
27518
27519 procedure Check_In_Out_States is
27520 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27521 -- Determine whether one of the following coverage scenarios is in
27522 -- effect:
27523 -- 1) there is at least one constituent of mode In_Out or Output
27524 -- 2) there is at least one pair of constituents with modes Input
27525 -- and Output, or Proof_In and Output.
27526 -- 3) there is at least one constituent of mode Output and not all
27527 -- constituents are present.
27528 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
27529
27530 -----------------------------
27531 -- Check_Constituent_Usage --
27532 -----------------------------
27533
27534 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27535 Constits : constant Elist_Id :=
27536 Partial_Refinement_Constituents (State_Id);
27537 Constit_Elmt : Elmt_Id;
27538 Constit_Id : Entity_Id;
27539 Has_Missing : Boolean := False;
27540 In_Out_Seen : Boolean := False;
27541 Input_Seen : Boolean := False;
27542 Output_Seen : Boolean := False;
27543 Proof_In_Seen : Boolean := False;
27544
27545 begin
27546 -- Process all the constituents of the state and note their modes
27547 -- within the global refinement.
27548
27549 if Present (Constits) then
27550 Constit_Elmt := First_Elmt (Constits);
27551 while Present (Constit_Elmt) loop
27552 Constit_Id := Node (Constit_Elmt);
27553
27554 if Present_Then_Remove (In_Constits, Constit_Id) then
27555 Input_Seen := True;
27556
27557 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
27558 In_Out_Seen := True;
27559
27560 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
27561 Output_Seen := True;
27562
27563 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
27564 then
27565 Proof_In_Seen := True;
27566
27567 else
27568 Has_Missing := True;
27569 end if;
27570
27571 Next_Elmt (Constit_Elmt);
27572 end loop;
27573 end if;
27574
27575 -- An In_Out constituent is a valid completion
27576
27577 if In_Out_Seen then
27578 null;
27579
27580 -- A pair of one Input/Proof_In and one Output constituent is a
27581 -- valid completion.
27582
27583 elsif (Input_Seen or Proof_In_Seen) and Output_Seen then
27584 null;
27585
27586 elsif Output_Seen then
27587
27588 -- A single Output constituent is a valid completion only when
27589 -- some of the other constituents are missing.
27590
27591 if Has_Missing then
27592 null;
27593
27594 -- Otherwise all constituents are of mode Output
27595
27596 else
27597 SPARK_Msg_NE
27598 ("global refinement of state & must include at least one "
27599 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
27600 N, State_Id);
27601 end if;
27602
27603 -- The state lacks a completion. When full refinement is visible,
27604 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
27605 -- refinement is visible, emit an error if the abstract state
27606 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
27607 -- both are utilized, Check_State_And_Constituent_Use. will issue
27608 -- the error.
27609
27610 elsif not Input_Seen
27611 and then not In_Out_Seen
27612 and then not Output_Seen
27613 and then not Proof_In_Seen
27614 then
27615 if Has_Visible_Refinement (State_Id)
27616 or else Contains (Repeat_Items, State_Id)
27617 then
27618 SPARK_Msg_NE
27619 ("missing global refinement of state &", N, State_Id);
27620 end if;
27621
27622 -- Otherwise the state has a malformed completion where at least
27623 -- one of the constituents has a different mode.
27624
27625 else
27626 SPARK_Msg_NE
27627 ("global refinement of state & redefines the mode of its "
27628 & "constituents", N, State_Id);
27629 end if;
27630 end Check_Constituent_Usage;
27631
27632 -- Local variables
27633
27634 Item_Elmt : Elmt_Id;
27635 Item_Id : Entity_Id;
27636
27637 -- Start of processing for Check_In_Out_States
27638
27639 begin
27640 -- Do not perform this check in an instance because it was already
27641 -- performed successfully in the generic template.
27642
27643 if In_Instance then
27644 null;
27645
27646 -- Inspect the In_Out items of the corresponding Global pragma
27647 -- looking for a state with a visible refinement.
27648
27649 elsif Has_In_Out_State and then Present (In_Out_Items) then
27650 Item_Elmt := First_Elmt (In_Out_Items);
27651 while Present (Item_Elmt) loop
27652 Item_Id := Node (Item_Elmt);
27653
27654 -- Ensure that one of the three coverage variants is satisfied
27655
27656 if Ekind (Item_Id) = E_Abstract_State
27657 and then Has_Non_Null_Visible_Refinement (Item_Id)
27658 then
27659 Check_Constituent_Usage (Item_Id);
27660 end if;
27661
27662 Next_Elmt (Item_Elmt);
27663 end loop;
27664 end if;
27665 end Check_In_Out_States;
27666
27667 ------------------------
27668 -- Check_Input_States --
27669 ------------------------
27670
27671 procedure Check_Input_States is
27672 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27673 -- Determine whether at least one constituent of state State_Id with
27674 -- full or partial visible refinement is used and has mode Input.
27675 -- Ensure that the remaining constituents do not have In_Out or
27676 -- Output modes. Emit an error if this is not the case
27677 -- (SPARK RM 7.2.4(5)).
27678
27679 -----------------------------
27680 -- Check_Constituent_Usage --
27681 -----------------------------
27682
27683 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27684 Constits : constant Elist_Id :=
27685 Partial_Refinement_Constituents (State_Id);
27686 Constit_Elmt : Elmt_Id;
27687 Constit_Id : Entity_Id;
27688 In_Seen : Boolean := False;
27689
27690 begin
27691 if Present (Constits) then
27692 Constit_Elmt := First_Elmt (Constits);
27693 while Present (Constit_Elmt) loop
27694 Constit_Id := Node (Constit_Elmt);
27695
27696 -- At least one of the constituents appears as an Input
27697
27698 if Present_Then_Remove (In_Constits, Constit_Id) then
27699 In_Seen := True;
27700
27701 -- A Proof_In constituent can refine an Input state as long
27702 -- as there is at least one Input constituent present.
27703
27704 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
27705 then
27706 null;
27707
27708 -- The constituent appears in the global refinement, but has
27709 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
27710
27711 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
27712 or else Present_Then_Remove (Out_Constits, Constit_Id)
27713 then
27714 Error_Msg_Name_1 := Chars (State_Id);
27715 SPARK_Msg_NE
27716 ("constituent & of state % must have mode `Input` in "
27717 & "global refinement", N, Constit_Id);
27718 end if;
27719
27720 Next_Elmt (Constit_Elmt);
27721 end loop;
27722 end if;
27723
27724 -- Not one of the constituents appeared as Input. Always emit an
27725 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
27726 -- When only partial refinement is visible, emit an error if the
27727 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27728 -- the case where both are utilized, an error will be issued in
27729 -- Check_State_And_Constituent_Use.
27730
27731 if not In_Seen
27732 and then (Has_Visible_Refinement (State_Id)
27733 or else Contains (Repeat_Items, State_Id))
27734 then
27735 SPARK_Msg_NE
27736 ("global refinement of state & must include at least one "
27737 & "constituent of mode `Input`", N, State_Id);
27738 end if;
27739 end Check_Constituent_Usage;
27740
27741 -- Local variables
27742
27743 Item_Elmt : Elmt_Id;
27744 Item_Id : Entity_Id;
27745
27746 -- Start of processing for Check_Input_States
27747
27748 begin
27749 -- Do not perform this check in an instance because it was already
27750 -- performed successfully in the generic template.
27751
27752 if In_Instance then
27753 null;
27754
27755 -- Inspect the Input items of the corresponding Global pragma looking
27756 -- for a state with a visible refinement.
27757
27758 elsif Has_In_State and then Present (In_Items) then
27759 Item_Elmt := First_Elmt (In_Items);
27760 while Present (Item_Elmt) loop
27761 Item_Id := Node (Item_Elmt);
27762
27763 -- When full refinement is visible, ensure that at least one of
27764 -- the constituents is utilized and is of mode Input. When only
27765 -- partial refinement is visible, ensure that either one of
27766 -- the constituents is utilized and is of mode Input, or the
27767 -- abstract state is repeated and no constituent is utilized.
27768
27769 if Ekind (Item_Id) = E_Abstract_State
27770 and then Has_Non_Null_Visible_Refinement (Item_Id)
27771 then
27772 Check_Constituent_Usage (Item_Id);
27773 end if;
27774
27775 Next_Elmt (Item_Elmt);
27776 end loop;
27777 end if;
27778 end Check_Input_States;
27779
27780 -------------------------
27781 -- Check_Output_States --
27782 -------------------------
27783
27784 procedure Check_Output_States is
27785 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27786 -- Determine whether all constituents of state State_Id with full
27787 -- visible refinement are used and have mode Output. Emit an error
27788 -- if this is not the case (SPARK RM 7.2.4(5)).
27789
27790 -----------------------------
27791 -- Check_Constituent_Usage --
27792 -----------------------------
27793
27794 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27795 Constits : constant Elist_Id :=
27796 Partial_Refinement_Constituents (State_Id);
27797 Only_Partial : constant Boolean :=
27798 not Has_Visible_Refinement (State_Id);
27799 Constit_Elmt : Elmt_Id;
27800 Constit_Id : Entity_Id;
27801 Posted : Boolean := False;
27802
27803 begin
27804 if Present (Constits) then
27805 Constit_Elmt := First_Elmt (Constits);
27806 while Present (Constit_Elmt) loop
27807 Constit_Id := Node (Constit_Elmt);
27808
27809 -- Issue an error when a constituent of State_Id is utilized
27810 -- and State_Id has only partial visible refinement
27811 -- (SPARK RM 7.2.4(3d)).
27812
27813 if Only_Partial then
27814 if Present_Then_Remove (Out_Constits, Constit_Id)
27815 or else Present_Then_Remove (In_Constits, Constit_Id)
27816 or else
27817 Present_Then_Remove (In_Out_Constits, Constit_Id)
27818 or else
27819 Present_Then_Remove (Proof_In_Constits, Constit_Id)
27820 then
27821 Error_Msg_Name_1 := Chars (State_Id);
27822 SPARK_Msg_NE
27823 ("constituent & of state % cannot be used in global "
27824 & "refinement", N, Constit_Id);
27825 Error_Msg_Name_1 := Chars (State_Id);
27826 SPARK_Msg_N ("\use state % instead", N);
27827 end if;
27828
27829 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
27830 null;
27831
27832 -- The constituent appears in the global refinement, but has
27833 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
27834
27835 elsif Present_Then_Remove (In_Constits, Constit_Id)
27836 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27837 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
27838 then
27839 Error_Msg_Name_1 := Chars (State_Id);
27840 SPARK_Msg_NE
27841 ("constituent & of state % must have mode `Output` in "
27842 & "global refinement", N, Constit_Id);
27843
27844 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
27845
27846 else
27847 if not Posted then
27848 Posted := True;
27849 SPARK_Msg_NE
27850 ("`Output` state & must be replaced by all its "
27851 & "constituents in global refinement", N, State_Id);
27852 end if;
27853
27854 SPARK_Msg_NE
27855 ("\constituent & is missing in output list",
27856 N, Constit_Id);
27857 end if;
27858
27859 Next_Elmt (Constit_Elmt);
27860 end loop;
27861 end if;
27862 end Check_Constituent_Usage;
27863
27864 -- Local variables
27865
27866 Item_Elmt : Elmt_Id;
27867 Item_Id : Entity_Id;
27868
27869 -- Start of processing for Check_Output_States
27870
27871 begin
27872 -- Do not perform this check in an instance because it was already
27873 -- performed successfully in the generic template.
27874
27875 if In_Instance then
27876 null;
27877
27878 -- Inspect the Output items of the corresponding Global pragma
27879 -- looking for a state with a visible refinement.
27880
27881 elsif Has_Out_State and then Present (Out_Items) then
27882 Item_Elmt := First_Elmt (Out_Items);
27883 while Present (Item_Elmt) loop
27884 Item_Id := Node (Item_Elmt);
27885
27886 -- When full refinement is visible, ensure that all of the
27887 -- constituents are utilized and they have mode Output. When
27888 -- only partial refinement is visible, ensure that no
27889 -- constituent is utilized.
27890
27891 if Ekind (Item_Id) = E_Abstract_State
27892 and then Has_Non_Null_Visible_Refinement (Item_Id)
27893 then
27894 Check_Constituent_Usage (Item_Id);
27895 end if;
27896
27897 Next_Elmt (Item_Elmt);
27898 end loop;
27899 end if;
27900 end Check_Output_States;
27901
27902 ---------------------------
27903 -- Check_Proof_In_States --
27904 ---------------------------
27905
27906 procedure Check_Proof_In_States is
27907 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27908 -- Determine whether at least one constituent of state State_Id with
27909 -- full or partial visible refinement is used and has mode Proof_In.
27910 -- Ensure that the remaining constituents do not have Input, In_Out,
27911 -- or Output modes. Emit an error if this is not the case
27912 -- (SPARK RM 7.2.4(5)).
27913
27914 -----------------------------
27915 -- Check_Constituent_Usage --
27916 -----------------------------
27917
27918 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27919 Constits : constant Elist_Id :=
27920 Partial_Refinement_Constituents (State_Id);
27921 Constit_Elmt : Elmt_Id;
27922 Constit_Id : Entity_Id;
27923 Proof_In_Seen : Boolean := False;
27924
27925 begin
27926 if Present (Constits) then
27927 Constit_Elmt := First_Elmt (Constits);
27928 while Present (Constit_Elmt) loop
27929 Constit_Id := Node (Constit_Elmt);
27930
27931 -- At least one of the constituents appears as Proof_In
27932
27933 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
27934 Proof_In_Seen := True;
27935
27936 -- The constituent appears in the global refinement, but has
27937 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
27938
27939 elsif Present_Then_Remove (In_Constits, Constit_Id)
27940 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27941 or else Present_Then_Remove (Out_Constits, Constit_Id)
27942 then
27943 Error_Msg_Name_1 := Chars (State_Id);
27944 SPARK_Msg_NE
27945 ("constituent & of state % must have mode `Proof_In` "
27946 & "in global refinement", N, Constit_Id);
27947 end if;
27948
27949 Next_Elmt (Constit_Elmt);
27950 end loop;
27951 end if;
27952
27953 -- Not one of the constituents appeared as Proof_In. Always emit
27954 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
27955 -- When only partial refinement is visible, emit an error if the
27956 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27957 -- the case where both are utilized, an error will be issued by
27958 -- Check_State_And_Constituent_Use.
27959
27960 if not Proof_In_Seen
27961 and then (Has_Visible_Refinement (State_Id)
27962 or else Contains (Repeat_Items, State_Id))
27963 then
27964 SPARK_Msg_NE
27965 ("global refinement of state & must include at least one "
27966 & "constituent of mode `Proof_In`", N, State_Id);
27967 end if;
27968 end Check_Constituent_Usage;
27969
27970 -- Local variables
27971
27972 Item_Elmt : Elmt_Id;
27973 Item_Id : Entity_Id;
27974
27975 -- Start of processing for Check_Proof_In_States
27976
27977 begin
27978 -- Do not perform this check in an instance because it was already
27979 -- performed successfully in the generic template.
27980
27981 if In_Instance then
27982 null;
27983
27984 -- Inspect the Proof_In items of the corresponding Global pragma
27985 -- looking for a state with a visible refinement.
27986
27987 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
27988 Item_Elmt := First_Elmt (Proof_In_Items);
27989 while Present (Item_Elmt) loop
27990 Item_Id := Node (Item_Elmt);
27991
27992 -- Ensure that at least one of the constituents is utilized
27993 -- and is of mode Proof_In. When only partial refinement is
27994 -- visible, ensure that either one of the constituents is
27995 -- utilized and is of mode Proof_In, or the abstract state
27996 -- is repeated and no constituent is utilized.
27997
27998 if Ekind (Item_Id) = E_Abstract_State
27999 and then Has_Non_Null_Visible_Refinement (Item_Id)
28000 then
28001 Check_Constituent_Usage (Item_Id);
28002 end if;
28003
28004 Next_Elmt (Item_Elmt);
28005 end loop;
28006 end if;
28007 end Check_Proof_In_States;
28008
28009 -------------------------------
28010 -- Check_Refined_Global_List --
28011 -------------------------------
28012
28013 procedure Check_Refined_Global_List
28014 (List : Node_Id;
28015 Global_Mode : Name_Id := Name_Input)
28016 is
28017 procedure Check_Refined_Global_Item
28018 (Item : Node_Id;
28019 Global_Mode : Name_Id);
28020 -- Verify the legality of a single global item declaration. Parameter
28021 -- Global_Mode denotes the current mode in effect.
28022
28023 -------------------------------
28024 -- Check_Refined_Global_Item --
28025 -------------------------------
28026
28027 procedure Check_Refined_Global_Item
28028 (Item : Node_Id;
28029 Global_Mode : Name_Id)
28030 is
28031 Item_Id : constant Entity_Id := Entity_Of (Item);
28032
28033 procedure Inconsistent_Mode_Error (Expect : Name_Id);
28034 -- Issue a common error message for all mode mismatches. Expect
28035 -- denotes the expected mode.
28036
28037 -----------------------------
28038 -- Inconsistent_Mode_Error --
28039 -----------------------------
28040
28041 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
28042 begin
28043 SPARK_Msg_NE
28044 ("global item & has inconsistent modes", Item, Item_Id);
28045
28046 Error_Msg_Name_1 := Global_Mode;
28047 Error_Msg_Name_2 := Expect;
28048 SPARK_Msg_N ("\expected mode %, found mode %", Item);
28049 end Inconsistent_Mode_Error;
28050
28051 -- Local variables
28052
28053 Enc_State : Entity_Id := Empty;
28054 -- Encapsulating state for constituent, Empty otherwise
28055
28056 -- Start of processing for Check_Refined_Global_Item
28057
28058 begin
28059 if Ekind (Item_Id) in E_Abstract_State | E_Constant | E_Variable
28060 then
28061 Enc_State := Find_Encapsulating_State (States, Item_Id);
28062 end if;
28063
28064 -- When the state or object acts as a constituent of another
28065 -- state with a visible refinement, collect it for the state
28066 -- completeness checks performed later on. Note that the item
28067 -- acts as a constituent only when the encapsulating state is
28068 -- present in pragma Global.
28069
28070 if Present (Enc_State)
28071 and then (Has_Visible_Refinement (Enc_State)
28072 or else Has_Partial_Visible_Refinement (Enc_State))
28073 and then Contains (States, Enc_State)
28074 then
28075 -- If the state has only partial visible refinement, remove it
28076 -- from the list of items that should be repeated from pragma
28077 -- Global.
28078
28079 if not Has_Visible_Refinement (Enc_State) then
28080 Present_Then_Remove (Repeat_Items, Enc_State);
28081 end if;
28082
28083 if Global_Mode = Name_Input then
28084 Append_New_Elmt (Item_Id, In_Constits);
28085
28086 elsif Global_Mode = Name_In_Out then
28087 Append_New_Elmt (Item_Id, In_Out_Constits);
28088
28089 elsif Global_Mode = Name_Output then
28090 Append_New_Elmt (Item_Id, Out_Constits);
28091
28092 elsif Global_Mode = Name_Proof_In then
28093 Append_New_Elmt (Item_Id, Proof_In_Constits);
28094 end if;
28095
28096 -- When not a constituent, ensure that both occurrences of the
28097 -- item in pragmas Global and Refined_Global match. Also remove
28098 -- it when present from the list of items that should be repeated
28099 -- from pragma Global.
28100
28101 else
28102 Present_Then_Remove (Repeat_Items, Item_Id);
28103
28104 if Contains (In_Items, Item_Id) then
28105 if Global_Mode /= Name_Input then
28106 Inconsistent_Mode_Error (Name_Input);
28107 end if;
28108
28109 elsif Contains (In_Out_Items, Item_Id) then
28110 if Global_Mode /= Name_In_Out then
28111 Inconsistent_Mode_Error (Name_In_Out);
28112 end if;
28113
28114 elsif Contains (Out_Items, Item_Id) then
28115 if Global_Mode /= Name_Output then
28116 Inconsistent_Mode_Error (Name_Output);
28117 end if;
28118
28119 elsif Contains (Proof_In_Items, Item_Id) then
28120 null;
28121
28122 -- The item does not appear in the corresponding Global pragma,
28123 -- it must be an extra (SPARK RM 7.2.4(3)).
28124
28125 else
28126 pragma Assert (Present (Global));
28127 Error_Msg_Sloc := Sloc (Global);
28128 SPARK_Msg_NE
28129 ("extra global item & does not refine or repeat any "
28130 & "global item #", Item, Item_Id);
28131 end if;
28132 end if;
28133 end Check_Refined_Global_Item;
28134
28135 -- Local variables
28136
28137 Item : Node_Id;
28138
28139 -- Start of processing for Check_Refined_Global_List
28140
28141 begin
28142 -- Do not perform this check in an instance because it was already
28143 -- performed successfully in the generic template.
28144
28145 if In_Instance then
28146 null;
28147
28148 elsif Nkind (List) = N_Null then
28149 null;
28150
28151 -- Single global item declaration
28152
28153 elsif Nkind (List) in N_Expanded_Name
28154 | N_Identifier
28155 | N_Selected_Component
28156 then
28157 Check_Refined_Global_Item (List, Global_Mode);
28158
28159 -- Simple global list or moded global list declaration
28160
28161 elsif Nkind (List) = N_Aggregate then
28162
28163 -- The declaration of a simple global list appear as a collection
28164 -- of expressions.
28165
28166 if Present (Expressions (List)) then
28167 Item := First (Expressions (List));
28168 while Present (Item) loop
28169 Check_Refined_Global_Item (Item, Global_Mode);
28170 Next (Item);
28171 end loop;
28172
28173 -- The declaration of a moded global list appears as a collection
28174 -- of component associations where individual choices denote
28175 -- modes.
28176
28177 elsif Present (Component_Associations (List)) then
28178 Item := First (Component_Associations (List));
28179 while Present (Item) loop
28180 Check_Refined_Global_List
28181 (List => Expression (Item),
28182 Global_Mode => Chars (First (Choices (Item))));
28183
28184 Next (Item);
28185 end loop;
28186
28187 -- Invalid tree
28188
28189 else
28190 raise Program_Error;
28191 end if;
28192
28193 -- Invalid list
28194
28195 else
28196 raise Program_Error;
28197 end if;
28198 end Check_Refined_Global_List;
28199
28200 --------------------------
28201 -- Collect_Global_Items --
28202 --------------------------
28203
28204 procedure Collect_Global_Items
28205 (List : Node_Id;
28206 Mode : Name_Id := Name_Input)
28207 is
28208 procedure Collect_Global_Item
28209 (Item : Node_Id;
28210 Item_Mode : Name_Id);
28211 -- Add a single item to the appropriate list. Item_Mode denotes the
28212 -- current mode in effect.
28213
28214 -------------------------
28215 -- Collect_Global_Item --
28216 -------------------------
28217
28218 procedure Collect_Global_Item
28219 (Item : Node_Id;
28220 Item_Mode : Name_Id)
28221 is
28222 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
28223 -- The above handles abstract views of variables and states built
28224 -- for limited with clauses.
28225
28226 begin
28227 -- Signal that the global list contains at least one abstract
28228 -- state with a visible refinement. Note that the refinement may
28229 -- be null in which case there are no constituents.
28230
28231 if Ekind (Item_Id) = E_Abstract_State then
28232 if Has_Null_Visible_Refinement (Item_Id) then
28233 Has_Null_State := True;
28234
28235 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
28236 Append_New_Elmt (Item_Id, States);
28237
28238 if Item_Mode = Name_Input then
28239 Has_In_State := True;
28240 elsif Item_Mode = Name_In_Out then
28241 Has_In_Out_State := True;
28242 elsif Item_Mode = Name_Output then
28243 Has_Out_State := True;
28244 elsif Item_Mode = Name_Proof_In then
28245 Has_Proof_In_State := True;
28246 end if;
28247 end if;
28248 end if;
28249
28250 -- Record global items without full visible refinement found in
28251 -- pragma Global which should be repeated in the global refinement
28252 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
28253
28254 if Ekind (Item_Id) /= E_Abstract_State
28255 or else not Has_Visible_Refinement (Item_Id)
28256 then
28257 Append_New_Elmt (Item_Id, Repeat_Items);
28258 end if;
28259
28260 -- Add the item to the proper list
28261
28262 if Item_Mode = Name_Input then
28263 Append_New_Elmt (Item_Id, In_Items);
28264 elsif Item_Mode = Name_In_Out then
28265 Append_New_Elmt (Item_Id, In_Out_Items);
28266 elsif Item_Mode = Name_Output then
28267 Append_New_Elmt (Item_Id, Out_Items);
28268 elsif Item_Mode = Name_Proof_In then
28269 Append_New_Elmt (Item_Id, Proof_In_Items);
28270 end if;
28271 end Collect_Global_Item;
28272
28273 -- Local variables
28274
28275 Item : Node_Id;
28276
28277 -- Start of processing for Collect_Global_Items
28278
28279 begin
28280 if Nkind (List) = N_Null then
28281 null;
28282
28283 -- Single global item declaration
28284
28285 elsif Nkind (List) in N_Expanded_Name
28286 | N_Identifier
28287 | N_Selected_Component
28288 then
28289 Collect_Global_Item (List, Mode);
28290
28291 -- Single global list or moded global list declaration
28292
28293 elsif Nkind (List) = N_Aggregate then
28294
28295 -- The declaration of a simple global list appear as a collection
28296 -- of expressions.
28297
28298 if Present (Expressions (List)) then
28299 Item := First (Expressions (List));
28300 while Present (Item) loop
28301 Collect_Global_Item (Item, Mode);
28302 Next (Item);
28303 end loop;
28304
28305 -- The declaration of a moded global list appears as a collection
28306 -- of component associations where individual choices denote mode.
28307
28308 elsif Present (Component_Associations (List)) then
28309 Item := First (Component_Associations (List));
28310 while Present (Item) loop
28311 Collect_Global_Items
28312 (List => Expression (Item),
28313 Mode => Chars (First (Choices (Item))));
28314
28315 Next (Item);
28316 end loop;
28317
28318 -- Invalid tree
28319
28320 else
28321 raise Program_Error;
28322 end if;
28323
28324 -- To accommodate partial decoration of disabled SPARK features, this
28325 -- routine may be called with illegal input. If this is the case, do
28326 -- not raise Program_Error.
28327
28328 else
28329 null;
28330 end if;
28331 end Collect_Global_Items;
28332
28333 -------------------------
28334 -- Present_Then_Remove --
28335 -------------------------
28336
28337 function Present_Then_Remove
28338 (List : Elist_Id;
28339 Item : Entity_Id) return Boolean
28340 is
28341 Elmt : Elmt_Id;
28342
28343 begin
28344 if Present (List) then
28345 Elmt := First_Elmt (List);
28346 while Present (Elmt) loop
28347 if Node (Elmt) = Item then
28348 Remove_Elmt (List, Elmt);
28349 return True;
28350 end if;
28351
28352 Next_Elmt (Elmt);
28353 end loop;
28354 end if;
28355
28356 return False;
28357 end Present_Then_Remove;
28358
28359 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id) is
28360 Ignore : Boolean;
28361 begin
28362 Ignore := Present_Then_Remove (List, Item);
28363 end Present_Then_Remove;
28364
28365 -------------------------------
28366 -- Report_Extra_Constituents --
28367 -------------------------------
28368
28369 procedure Report_Extra_Constituents is
28370 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
28371 -- Emit an error for every element of List
28372
28373 ---------------------------------------
28374 -- Report_Extra_Constituents_In_List --
28375 ---------------------------------------
28376
28377 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
28378 Constit_Elmt : Elmt_Id;
28379
28380 begin
28381 if Present (List) then
28382 Constit_Elmt := First_Elmt (List);
28383 while Present (Constit_Elmt) loop
28384 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
28385 Next_Elmt (Constit_Elmt);
28386 end loop;
28387 end if;
28388 end Report_Extra_Constituents_In_List;
28389
28390 -- Start of processing for Report_Extra_Constituents
28391
28392 begin
28393 -- Do not perform this check in an instance because it was already
28394 -- performed successfully in the generic template.
28395
28396 if In_Instance then
28397 null;
28398
28399 else
28400 Report_Extra_Constituents_In_List (In_Constits);
28401 Report_Extra_Constituents_In_List (In_Out_Constits);
28402 Report_Extra_Constituents_In_List (Out_Constits);
28403 Report_Extra_Constituents_In_List (Proof_In_Constits);
28404 end if;
28405 end Report_Extra_Constituents;
28406
28407 --------------------------
28408 -- Report_Missing_Items --
28409 --------------------------
28410
28411 procedure Report_Missing_Items is
28412 Item_Elmt : Elmt_Id;
28413 Item_Id : Entity_Id;
28414
28415 begin
28416 -- Do not perform this check in an instance because it was already
28417 -- performed successfully in the generic template.
28418
28419 if In_Instance then
28420 null;
28421
28422 else
28423 if Present (Repeat_Items) then
28424 Item_Elmt := First_Elmt (Repeat_Items);
28425 while Present (Item_Elmt) loop
28426 Item_Id := Node (Item_Elmt);
28427 SPARK_Msg_NE ("missing global item &", N, Item_Id);
28428 Next_Elmt (Item_Elmt);
28429 end loop;
28430 end if;
28431 end if;
28432 end Report_Missing_Items;
28433
28434 -- Local variables
28435
28436 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
28437 Errors : constant Nat := Serious_Errors_Detected;
28438 Items : Node_Id;
28439 No_Constit : Boolean;
28440
28441 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
28442
28443 begin
28444 -- Do not analyze the pragma multiple times
28445
28446 if Is_Analyzed_Pragma (N) then
28447 return;
28448 end if;
28449
28450 Spec_Id := Unique_Defining_Entity (Body_Decl);
28451
28452 -- Use the anonymous object as the proper spec when Refined_Global
28453 -- applies to the body of a single task type. The object carries the
28454 -- proper Chars as well as all non-refined versions of pragmas.
28455
28456 if Is_Single_Concurrent_Type (Spec_Id) then
28457 Spec_Id := Anonymous_Object (Spec_Id);
28458 end if;
28459
28460 Global := Get_Pragma (Spec_Id, Pragma_Global);
28461 Items := Expression (Get_Argument (N, Spec_Id));
28462
28463 -- The subprogram declaration lacks pragma Global. This renders
28464 -- Refined_Global useless as there is nothing to refine.
28465
28466 if No (Global) then
28467 SPARK_Msg_NE
28468 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
28469 & "& lacks aspect or pragma Global"), N, Spec_Id);
28470 goto Leave;
28471 end if;
28472
28473 -- Extract all relevant items from the corresponding Global pragma
28474
28475 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
28476
28477 -- Package and subprogram bodies are instantiated individually in
28478 -- a separate compiler pass. Due to this mode of instantiation, the
28479 -- refinement of a state may no longer be visible when a subprogram
28480 -- body contract is instantiated. Since the generic template is legal,
28481 -- do not perform this check in the instance to circumvent this oddity.
28482
28483 if In_Instance then
28484 null;
28485
28486 -- Non-instance case
28487
28488 else
28489 -- The corresponding Global pragma must mention at least one
28490 -- state with a visible refinement at the point Refined_Global
28491 -- is processed. States with null refinements need Refined_Global
28492 -- pragma (SPARK RM 7.2.4(2)).
28493
28494 if not Has_In_State
28495 and then not Has_In_Out_State
28496 and then not Has_Out_State
28497 and then not Has_Proof_In_State
28498 and then not Has_Null_State
28499 then
28500 SPARK_Msg_NE
28501 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
28502 & "depend on abstract state with visible refinement"),
28503 N, Spec_Id);
28504 goto Leave;
28505
28506 -- The global refinement of inputs and outputs cannot be null when
28507 -- the corresponding Global pragma contains at least one item except
28508 -- in the case where we have states with null refinements.
28509
28510 elsif Nkind (Items) = N_Null
28511 and then
28512 (Present (In_Items)
28513 or else Present (In_Out_Items)
28514 or else Present (Out_Items)
28515 or else Present (Proof_In_Items))
28516 and then not Has_Null_State
28517 then
28518 SPARK_Msg_NE
28519 (Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has "
28520 & "global items"), N, Spec_Id);
28521 goto Leave;
28522 end if;
28523 end if;
28524
28525 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
28526 -- This ensures that the categorization of all refined global items is
28527 -- consistent with their role.
28528
28529 Analyze_Global_In_Decl_Part (N);
28530
28531 -- Perform all refinement checks with respect to completeness and mode
28532 -- matching.
28533
28534 if Serious_Errors_Detected = Errors then
28535 Check_Refined_Global_List (Items);
28536 end if;
28537
28538 -- Store the information that no constituent is used in the global
28539 -- refinement, prior to calling checking procedures which remove items
28540 -- from the list of constituents.
28541
28542 No_Constit :=
28543 No (In_Constits)
28544 and then No (In_Out_Constits)
28545 and then No (Out_Constits)
28546 and then No (Proof_In_Constits);
28547
28548 -- For Input states with visible refinement, at least one constituent
28549 -- must be used as an Input in the global refinement.
28550
28551 if Serious_Errors_Detected = Errors then
28552 Check_Input_States;
28553 end if;
28554
28555 -- Verify all possible completion variants for In_Out states with
28556 -- visible refinement.
28557
28558 if Serious_Errors_Detected = Errors then
28559 Check_In_Out_States;
28560 end if;
28561
28562 -- For Output states with visible refinement, all constituents must be
28563 -- used as Outputs in the global refinement.
28564
28565 if Serious_Errors_Detected = Errors then
28566 Check_Output_States;
28567 end if;
28568
28569 -- For Proof_In states with visible refinement, at least one constituent
28570 -- must be used as Proof_In in the global refinement.
28571
28572 if Serious_Errors_Detected = Errors then
28573 Check_Proof_In_States;
28574 end if;
28575
28576 -- Emit errors for all constituents that belong to other states with
28577 -- visible refinement that do not appear in Global.
28578
28579 if Serious_Errors_Detected = Errors then
28580 Report_Extra_Constituents;
28581 end if;
28582
28583 -- Emit errors for all items in Global that are not repeated in the
28584 -- global refinement and for which there is no full visible refinement
28585 -- and, in the case of states with partial visible refinement, no
28586 -- constituent is mentioned in the global refinement.
28587
28588 if Serious_Errors_Detected = Errors then
28589 Report_Missing_Items;
28590 end if;
28591
28592 -- Emit an error if no constituent is used in the global refinement
28593 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
28594 -- one may be issued by the checking procedures. Do not perform this
28595 -- check in an instance because it was already performed successfully
28596 -- in the generic template.
28597
28598 if Serious_Errors_Detected = Errors
28599 and then not In_Instance
28600 and then not Has_Null_State
28601 and then No_Constit
28602 then
28603 SPARK_Msg_N ("missing refinement", N);
28604 end if;
28605
28606 <<Leave>>
28607 Set_Is_Analyzed_Pragma (N);
28608 end Analyze_Refined_Global_In_Decl_Part;
28609
28610 ----------------------------------------
28611 -- Analyze_Refined_State_In_Decl_Part --
28612 ----------------------------------------
28613
28614 procedure Analyze_Refined_State_In_Decl_Part
28615 (N : Node_Id;
28616 Freeze_Id : Entity_Id := Empty)
28617 is
28618 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
28619 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
28620 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
28621
28622 Available_States : Elist_Id := No_Elist;
28623 -- A list of all abstract states defined in the package declaration that
28624 -- are available for refinement. The list is used to report unrefined
28625 -- states.
28626
28627 Body_States : Elist_Id := No_Elist;
28628 -- A list of all hidden states that appear in the body of the related
28629 -- package. The list is used to report unused hidden states.
28630
28631 Constituents_Seen : Elist_Id := No_Elist;
28632 -- A list that contains all constituents processed so far. The list is
28633 -- used to detect multiple uses of the same constituent.
28634
28635 Freeze_Posted : Boolean := False;
28636 -- A flag that controls the output of a freezing-related error (see use
28637 -- below).
28638
28639 Refined_States_Seen : Elist_Id := No_Elist;
28640 -- A list that contains all refined states processed so far. The list is
28641 -- used to detect duplicate refinements.
28642
28643 procedure Analyze_Refinement_Clause (Clause : Node_Id);
28644 -- Perform full analysis of a single refinement clause
28645
28646 procedure Report_Unrefined_States (States : Elist_Id);
28647 -- Emit errors for all unrefined abstract states found in list States
28648
28649 -------------------------------
28650 -- Analyze_Refinement_Clause --
28651 -------------------------------
28652
28653 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
28654 AR_Constit : Entity_Id := Empty;
28655 AW_Constit : Entity_Id := Empty;
28656 ER_Constit : Entity_Id := Empty;
28657 EW_Constit : Entity_Id := Empty;
28658 -- The entities of external constituents that contain one of the
28659 -- following enabled properties: Async_Readers, Async_Writers,
28660 -- Effective_Reads and Effective_Writes.
28661
28662 External_Constit_Seen : Boolean := False;
28663 -- Flag used to mark when at least one external constituent is part
28664 -- of the state refinement.
28665
28666 Non_Null_Seen : Boolean := False;
28667 Null_Seen : Boolean := False;
28668 -- Flags used to detect multiple uses of null in a single clause or a
28669 -- mixture of null and non-null constituents.
28670
28671 Part_Of_Constits : Elist_Id := No_Elist;
28672 -- A list of all candidate constituents subject to indicator Part_Of
28673 -- where the encapsulating state is the current state.
28674
28675 State : Node_Id;
28676 State_Id : Entity_Id;
28677 -- The current state being refined
28678
28679 procedure Analyze_Constituent (Constit : Node_Id);
28680 -- Perform full analysis of a single constituent
28681
28682 procedure Check_External_Property
28683 (Prop_Nam : Name_Id;
28684 Enabled : Boolean;
28685 Constit : Entity_Id);
28686 -- Determine whether a property denoted by name Prop_Nam is present
28687 -- in the refined state. Emit an error if this is not the case. Flag
28688 -- Enabled should be set when the property applies to the refined
28689 -- state. Constit denotes the constituent (if any) which introduces
28690 -- the property in the refinement.
28691
28692 procedure Match_State;
28693 -- Determine whether the state being refined appears in list
28694 -- Available_States. Emit an error when attempting to re-refine the
28695 -- state or when the state is not defined in the package declaration,
28696 -- otherwise remove the state from Available_States.
28697
28698 procedure Report_Unused_Constituents (Constits : Elist_Id);
28699 -- Emit errors for all unused Part_Of constituents in list Constits
28700
28701 -------------------------
28702 -- Analyze_Constituent --
28703 -------------------------
28704
28705 procedure Analyze_Constituent (Constit : Node_Id) is
28706 procedure Match_Constituent (Constit_Id : Entity_Id);
28707 -- Determine whether constituent Constit denoted by its entity
28708 -- Constit_Id appears in Body_States. Emit an error when the
28709 -- constituent is not a valid hidden state of the related package
28710 -- or when it is used more than once. Otherwise remove the
28711 -- constituent from Body_States.
28712
28713 -----------------------
28714 -- Match_Constituent --
28715 -----------------------
28716
28717 procedure Match_Constituent (Constit_Id : Entity_Id) is
28718 procedure Collect_Constituent;
28719 -- Verify the legality of constituent Constit_Id and add it to
28720 -- the refinements of State_Id.
28721
28722 -------------------------
28723 -- Collect_Constituent --
28724 -------------------------
28725
28726 procedure Collect_Constituent is
28727 Constits : Elist_Id;
28728
28729 begin
28730 -- The Ghost policy in effect at the point of abstract state
28731 -- declaration and constituent must match (SPARK RM 6.9(15))
28732
28733 Check_Ghost_Refinement
28734 (State, State_Id, Constit, Constit_Id);
28735
28736 -- A synchronized state must be refined by a synchronized
28737 -- object or another synchronized state (SPARK RM 9.6).
28738
28739 if Is_Synchronized_State (State_Id)
28740 and then not Is_Synchronized_Object (Constit_Id)
28741 and then not Is_Synchronized_State (Constit_Id)
28742 then
28743 SPARK_Msg_NE
28744 ("constituent of synchronized state & must be "
28745 & "synchronized", Constit, State_Id);
28746 end if;
28747
28748 -- Add the constituent to the list of processed items to aid
28749 -- with the detection of duplicates.
28750
28751 Append_New_Elmt (Constit_Id, Constituents_Seen);
28752
28753 -- Collect the constituent in the list of refinement items
28754 -- and establish a relation between the refined state and
28755 -- the item.
28756
28757 Constits := Refinement_Constituents (State_Id);
28758
28759 if No (Constits) then
28760 Constits := New_Elmt_List;
28761 Set_Refinement_Constituents (State_Id, Constits);
28762 end if;
28763
28764 Append_Elmt (Constit_Id, Constits);
28765 Set_Encapsulating_State (Constit_Id, State_Id);
28766
28767 -- The state has at least one legal constituent, mark the
28768 -- start of the refinement region. The region ends when the
28769 -- body declarations end (see routine Analyze_Declarations).
28770
28771 Set_Has_Visible_Refinement (State_Id);
28772
28773 -- When the constituent is external, save its relevant
28774 -- property for further checks.
28775
28776 if Async_Readers_Enabled (Constit_Id) then
28777 AR_Constit := Constit_Id;
28778 External_Constit_Seen := True;
28779 end if;
28780
28781 if Async_Writers_Enabled (Constit_Id) then
28782 AW_Constit := Constit_Id;
28783 External_Constit_Seen := True;
28784 end if;
28785
28786 if Effective_Reads_Enabled (Constit_Id) then
28787 ER_Constit := Constit_Id;
28788 External_Constit_Seen := True;
28789 end if;
28790
28791 if Effective_Writes_Enabled (Constit_Id) then
28792 EW_Constit := Constit_Id;
28793 External_Constit_Seen := True;
28794 end if;
28795 end Collect_Constituent;
28796
28797 -- Local variables
28798
28799 State_Elmt : Elmt_Id;
28800
28801 -- Start of processing for Match_Constituent
28802
28803 begin
28804 -- Detect a duplicate use of a constituent
28805
28806 if Contains (Constituents_Seen, Constit_Id) then
28807 SPARK_Msg_NE
28808 ("duplicate use of constituent &", Constit, Constit_Id);
28809 return;
28810 end if;
28811
28812 -- The constituent is subject to a Part_Of indicator
28813
28814 if Present (Encapsulating_State (Constit_Id)) then
28815 if Encapsulating_State (Constit_Id) = State_Id then
28816 Remove (Part_Of_Constits, Constit_Id);
28817 Collect_Constituent;
28818
28819 -- The constituent is part of another state and is used
28820 -- incorrectly in the refinement of the current state.
28821
28822 else
28823 Error_Msg_Name_1 := Chars (State_Id);
28824 SPARK_Msg_NE
28825 ("& cannot act as constituent of state %",
28826 Constit, Constit_Id);
28827 SPARK_Msg_NE
28828 ("\Part_Of indicator specifies encapsulator &",
28829 Constit, Encapsulating_State (Constit_Id));
28830 end if;
28831
28832 else
28833 declare
28834 Pack_Id : Entity_Id;
28835 Placement : State_Space_Kind;
28836 begin
28837 -- Find where the constituent lives with respect to the
28838 -- state space.
28839
28840 Find_Placement_In_State_Space
28841 (Item_Id => Constit_Id,
28842 Placement => Placement,
28843 Pack_Id => Pack_Id);
28844
28845 -- The constituent is either part of the hidden state of
28846 -- the package or part of the visible state of a private
28847 -- child package, but lacks a Part_Of indicator.
28848
28849 if (Placement = Private_State_Space
28850 and then Pack_Id = Spec_Id)
28851 or else
28852 (Placement = Visible_State_Space
28853 and then Is_Child_Unit (Pack_Id)
28854 and then not Is_Generic_Unit (Pack_Id)
28855 and then Is_Private_Descendant (Pack_Id))
28856 then
28857 Error_Msg_Name_1 := Chars (State_Id);
28858 SPARK_Msg_NE
28859 ("& cannot act as constituent of state %",
28860 Constit, Constit_Id);
28861 Error_Msg_Sloc :=
28862 Sloc (Enclosing_Declaration (Constit_Id));
28863 SPARK_Msg_NE
28864 ("\missing Part_Of indicator # should specify "
28865 & "encapsulator &",
28866 Constit, State_Id);
28867
28868 -- The only other source of legal constituents is the
28869 -- body state space of the related package.
28870
28871 else
28872 if Present (Body_States) then
28873 State_Elmt := First_Elmt (Body_States);
28874 while Present (State_Elmt) loop
28875
28876 -- Consume a valid constituent to signal that it
28877 -- has been encountered.
28878
28879 if Node (State_Elmt) = Constit_Id then
28880 Remove_Elmt (Body_States, State_Elmt);
28881 Collect_Constituent;
28882 return;
28883 end if;
28884
28885 Next_Elmt (State_Elmt);
28886 end loop;
28887 end if;
28888
28889 -- At this point it is known that the constituent is
28890 -- not part of the package hidden state and cannot be
28891 -- used in a refinement (SPARK RM 7.2.2(9)).
28892
28893 Error_Msg_Name_1 := Chars (Spec_Id);
28894 SPARK_Msg_NE
28895 ("cannot use & in refinement, constituent is not a "
28896 & "hidden state of package %", Constit, Constit_Id);
28897 end if;
28898 end;
28899 end if;
28900 end Match_Constituent;
28901
28902 -- Local variables
28903
28904 Constit_Id : Entity_Id;
28905 Constits : Elist_Id;
28906
28907 -- Start of processing for Analyze_Constituent
28908
28909 begin
28910 -- Detect multiple uses of null in a single refinement clause or a
28911 -- mixture of null and non-null constituents.
28912
28913 if Nkind (Constit) = N_Null then
28914 if Null_Seen then
28915 SPARK_Msg_N
28916 ("multiple null constituents not allowed", Constit);
28917
28918 elsif Non_Null_Seen then
28919 SPARK_Msg_N
28920 ("cannot mix null and non-null constituents", Constit);
28921
28922 else
28923 Null_Seen := True;
28924
28925 -- Collect the constituent in the list of refinement items
28926
28927 Constits := Refinement_Constituents (State_Id);
28928
28929 if No (Constits) then
28930 Constits := New_Elmt_List;
28931 Set_Refinement_Constituents (State_Id, Constits);
28932 end if;
28933
28934 Append_Elmt (Constit, Constits);
28935
28936 -- The state has at least one legal constituent, mark the
28937 -- start of the refinement region. The region ends when the
28938 -- body declarations end (see Analyze_Declarations).
28939
28940 Set_Has_Visible_Refinement (State_Id);
28941 end if;
28942
28943 -- Non-null constituents
28944
28945 else
28946 Non_Null_Seen := True;
28947
28948 if Null_Seen then
28949 SPARK_Msg_N
28950 ("cannot mix null and non-null constituents", Constit);
28951 end if;
28952
28953 Analyze (Constit);
28954 Resolve_State (Constit);
28955
28956 -- Ensure that the constituent denotes a valid state or a
28957 -- whole object (SPARK RM 7.2.2(5)).
28958
28959 if Is_Entity_Name (Constit) then
28960 Constit_Id := Entity_Of (Constit);
28961
28962 -- When a constituent is declared after a subprogram body
28963 -- that caused freezing of the related contract where
28964 -- pragma Refined_State resides, the constituent appears
28965 -- undefined and carries Any_Id as its entity.
28966
28967 -- package body Pack
28968 -- with Refined_State => (State => Constit)
28969 -- is
28970 -- procedure Proc
28971 -- with Refined_Global => (Input => Constit)
28972 -- is
28973 -- ...
28974 -- end Proc;
28975
28976 -- Constit : ...;
28977 -- end Pack;
28978
28979 if Constit_Id = Any_Id then
28980 SPARK_Msg_NE ("& is undefined", Constit, Constit_Id);
28981
28982 -- Emit a specialized info message when the contract of
28983 -- the related package body was "frozen" by another body.
28984 -- Note that it is not possible to precisely identify why
28985 -- the constituent is undefined because it is not visible
28986 -- when pragma Refined_State is analyzed. This message is
28987 -- a reasonable approximation.
28988
28989 if Present (Freeze_Id) and then not Freeze_Posted then
28990 Freeze_Posted := True;
28991
28992 Error_Msg_Name_1 := Chars (Body_Id);
28993 Error_Msg_Sloc := Sloc (Freeze_Id);
28994 SPARK_Msg_NE
28995 ("body & declared # freezes the contract of %",
28996 N, Freeze_Id);
28997 SPARK_Msg_N
28998 ("\all constituents must be declared before body #",
28999 N);
29000
29001 -- A misplaced constituent is a critical error because
29002 -- pragma Refined_Depends or Refined_Global depends on
29003 -- the proper link between a state and a constituent.
29004 -- Stop the compilation, as this leads to a multitude
29005 -- of misleading cascaded errors.
29006
29007 raise Unrecoverable_Error;
29008 end if;
29009
29010 -- The constituent is a valid state or object
29011
29012 elsif Ekind (Constit_Id) in
29013 E_Abstract_State | E_Constant | E_Variable
29014 then
29015 Match_Constituent (Constit_Id);
29016
29017 -- The variable may eventually become a constituent of a
29018 -- single protected/task type. Record the reference now
29019 -- and verify its legality when analyzing the contract of
29020 -- the variable (SPARK RM 9.3).
29021
29022 if Ekind (Constit_Id) = E_Variable then
29023 Record_Possible_Part_Of_Reference
29024 (Var_Id => Constit_Id,
29025 Ref => Constit);
29026 end if;
29027
29028 -- Otherwise the constituent is illegal
29029
29030 else
29031 SPARK_Msg_NE
29032 ("constituent & must denote object or state",
29033 Constit, Constit_Id);
29034 end if;
29035
29036 -- The constituent is illegal
29037
29038 else
29039 SPARK_Msg_N ("malformed constituent", Constit);
29040 end if;
29041 end if;
29042 end Analyze_Constituent;
29043
29044 -----------------------------
29045 -- Check_External_Property --
29046 -----------------------------
29047
29048 procedure Check_External_Property
29049 (Prop_Nam : Name_Id;
29050 Enabled : Boolean;
29051 Constit : Entity_Id)
29052 is
29053 begin
29054 -- The property is missing in the declaration of the state, but
29055 -- a constituent is introducing it in the state refinement
29056 -- (SPARK RM 7.2.8(2)).
29057
29058 if not Enabled and then Present (Constit) then
29059 Error_Msg_Name_1 := Prop_Nam;
29060 Error_Msg_Name_2 := Chars (State_Id);
29061 SPARK_Msg_NE
29062 ("constituent & introduces external property % in refinement "
29063 & "of state %", State, Constit);
29064
29065 Error_Msg_Sloc := Sloc (State_Id);
29066 SPARK_Msg_N
29067 ("\property is missing in abstract state declaration #",
29068 State);
29069 end if;
29070 end Check_External_Property;
29071
29072 -----------------
29073 -- Match_State --
29074 -----------------
29075
29076 procedure Match_State is
29077 State_Elmt : Elmt_Id;
29078
29079 begin
29080 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
29081
29082 if Contains (Refined_States_Seen, State_Id) then
29083 SPARK_Msg_NE
29084 ("duplicate refinement of state &", State, State_Id);
29085 return;
29086 end if;
29087
29088 -- Inspect the abstract states defined in the package declaration
29089 -- looking for a match.
29090
29091 State_Elmt := First_Elmt (Available_States);
29092 while Present (State_Elmt) loop
29093
29094 -- A valid abstract state is being refined in the body. Add
29095 -- the state to the list of processed refined states to aid
29096 -- with the detection of duplicate refinements. Remove the
29097 -- state from Available_States to signal that it has already
29098 -- been refined.
29099
29100 if Node (State_Elmt) = State_Id then
29101 Append_New_Elmt (State_Id, Refined_States_Seen);
29102 Remove_Elmt (Available_States, State_Elmt);
29103 return;
29104 end if;
29105
29106 Next_Elmt (State_Elmt);
29107 end loop;
29108
29109 -- If we get here, we are refining a state that is not defined in
29110 -- the package declaration.
29111
29112 Error_Msg_Name_1 := Chars (Spec_Id);
29113 SPARK_Msg_NE
29114 ("cannot refine state, & is not defined in package %",
29115 State, State_Id);
29116 end Match_State;
29117
29118 --------------------------------
29119 -- Report_Unused_Constituents --
29120 --------------------------------
29121
29122 procedure Report_Unused_Constituents (Constits : Elist_Id) is
29123 Constit_Elmt : Elmt_Id;
29124 Constit_Id : Entity_Id;
29125 Posted : Boolean := False;
29126
29127 begin
29128 if Present (Constits) then
29129 Constit_Elmt := First_Elmt (Constits);
29130 while Present (Constit_Elmt) loop
29131 Constit_Id := Node (Constit_Elmt);
29132
29133 -- Generate an error message of the form:
29134
29135 -- state ... has unused Part_Of constituents
29136 -- abstract state ... defined at ...
29137 -- constant ... defined at ...
29138 -- variable ... defined at ...
29139
29140 if not Posted then
29141 Posted := True;
29142 SPARK_Msg_NE
29143 ("state & has unused Part_Of constituents",
29144 State, State_Id);
29145 end if;
29146
29147 Error_Msg_Sloc := Sloc (Constit_Id);
29148
29149 if Ekind (Constit_Id) = E_Abstract_State then
29150 SPARK_Msg_NE
29151 ("\abstract state & defined #", State, Constit_Id);
29152
29153 elsif Ekind (Constit_Id) = E_Constant then
29154 SPARK_Msg_NE
29155 ("\constant & defined #", State, Constit_Id);
29156
29157 else
29158 pragma Assert (Ekind (Constit_Id) = E_Variable);
29159 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
29160 end if;
29161
29162 Next_Elmt (Constit_Elmt);
29163 end loop;
29164 end if;
29165 end Report_Unused_Constituents;
29166
29167 -- Local declarations
29168
29169 Body_Ref : Node_Id;
29170 Body_Ref_Elmt : Elmt_Id;
29171 Constit : Node_Id;
29172 Extra_State : Node_Id;
29173
29174 -- Start of processing for Analyze_Refinement_Clause
29175
29176 begin
29177 -- A refinement clause appears as a component association where the
29178 -- sole choice is the state and the expressions are the constituents.
29179 -- This is a syntax error, always report.
29180
29181 if Nkind (Clause) /= N_Component_Association then
29182 Error_Msg_N ("malformed state refinement clause", Clause);
29183 return;
29184 end if;
29185
29186 -- Analyze the state name of a refinement clause
29187
29188 State := First (Choices (Clause));
29189
29190 Analyze (State);
29191 Resolve_State (State);
29192
29193 -- Ensure that the state name denotes a valid abstract state that is
29194 -- defined in the spec of the related package.
29195
29196 if Is_Entity_Name (State) then
29197 State_Id := Entity_Of (State);
29198
29199 -- When the abstract state is undefined, it appears as Any_Id. Do
29200 -- not continue with the analysis of the clause.
29201
29202 if State_Id = Any_Id then
29203 return;
29204
29205 -- Catch any attempts to re-refine a state or refine a state that
29206 -- is not defined in the package declaration.
29207
29208 elsif Ekind (State_Id) = E_Abstract_State then
29209 Match_State;
29210
29211 else
29212 SPARK_Msg_NE ("& must denote abstract state", State, State_Id);
29213 return;
29214 end if;
29215
29216 -- References to a state with visible refinement are illegal.
29217 -- When nested packages are involved, detecting such references is
29218 -- tricky because pragma Refined_State is analyzed later than the
29219 -- offending pragma Depends or Global. References that occur in
29220 -- such nested context are stored in a list. Emit errors for all
29221 -- references found in Body_References (SPARK RM 6.1.4(8)).
29222
29223 if Present (Body_References (State_Id)) then
29224 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
29225 while Present (Body_Ref_Elmt) loop
29226 Body_Ref := Node (Body_Ref_Elmt);
29227
29228 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
29229 Error_Msg_Sloc := Sloc (State);
29230 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
29231
29232 Next_Elmt (Body_Ref_Elmt);
29233 end loop;
29234 end if;
29235
29236 -- The state name is illegal. This is a syntax error, always report.
29237
29238 else
29239 Error_Msg_N ("malformed state name in refinement clause", State);
29240 return;
29241 end if;
29242
29243 -- A refinement clause may only refine one state at a time
29244
29245 Extra_State := Next (State);
29246
29247 if Present (Extra_State) then
29248 SPARK_Msg_N
29249 ("refinement clause cannot cover multiple states", Extra_State);
29250 end if;
29251
29252 -- Replicate the Part_Of constituents of the refined state because
29253 -- the algorithm will consume items.
29254
29255 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
29256
29257 -- Analyze all constituents of the refinement. Multiple constituents
29258 -- appear as an aggregate.
29259
29260 Constit := Expression (Clause);
29261
29262 if Nkind (Constit) = N_Aggregate then
29263 if Present (Component_Associations (Constit)) then
29264 SPARK_Msg_N
29265 ("constituents of refinement clause must appear in "
29266 & "positional form", Constit);
29267
29268 else pragma Assert (Present (Expressions (Constit)));
29269 Constit := First (Expressions (Constit));
29270 while Present (Constit) loop
29271 Analyze_Constituent (Constit);
29272 Next (Constit);
29273 end loop;
29274 end if;
29275
29276 -- Various forms of a single constituent. Note that these may include
29277 -- malformed constituents.
29278
29279 else
29280 Analyze_Constituent (Constit);
29281 end if;
29282
29283 -- Verify that external constituents do not introduce new external
29284 -- property in the state refinement (SPARK RM 7.2.8(2)).
29285
29286 if Is_External_State (State_Id) then
29287 Check_External_Property
29288 (Prop_Nam => Name_Async_Readers,
29289 Enabled => Async_Readers_Enabled (State_Id),
29290 Constit => AR_Constit);
29291
29292 Check_External_Property
29293 (Prop_Nam => Name_Async_Writers,
29294 Enabled => Async_Writers_Enabled (State_Id),
29295 Constit => AW_Constit);
29296
29297 Check_External_Property
29298 (Prop_Nam => Name_Effective_Reads,
29299 Enabled => Effective_Reads_Enabled (State_Id),
29300 Constit => ER_Constit);
29301
29302 Check_External_Property
29303 (Prop_Nam => Name_Effective_Writes,
29304 Enabled => Effective_Writes_Enabled (State_Id),
29305 Constit => EW_Constit);
29306
29307 -- When a refined state is not external, it should not have external
29308 -- constituents (SPARK RM 7.2.8(1)).
29309
29310 elsif External_Constit_Seen then
29311 SPARK_Msg_NE
29312 ("non-external state & cannot contain external constituents in "
29313 & "refinement", State, State_Id);
29314 end if;
29315
29316 -- Ensure that all Part_Of candidate constituents have been mentioned
29317 -- in the refinement clause.
29318
29319 Report_Unused_Constituents (Part_Of_Constits);
29320
29321 -- Avoid a cascading error reporting a missing refinement by adding a
29322 -- dummy constituent.
29323
29324 if No (Refinement_Constituents (State_Id)) then
29325 Set_Refinement_Constituents (State_Id, New_Elmt_List (Any_Id));
29326 end if;
29327
29328 -- At this point the refinement might be dummy, but must be
29329 -- well-formed, to prevent cascaded errors.
29330
29331 pragma Assert (Has_Null_Refinement (State_Id)
29332 xor
29333 Has_Non_Null_Refinement (State_Id));
29334 end Analyze_Refinement_Clause;
29335
29336 -----------------------------
29337 -- Report_Unrefined_States --
29338 -----------------------------
29339
29340 procedure Report_Unrefined_States (States : Elist_Id) is
29341 State_Elmt : Elmt_Id;
29342
29343 begin
29344 if Present (States) then
29345 State_Elmt := First_Elmt (States);
29346 while Present (State_Elmt) loop
29347 SPARK_Msg_N
29348 ("abstract state & must be refined", Node (State_Elmt));
29349
29350 Next_Elmt (State_Elmt);
29351 end loop;
29352 end if;
29353 end Report_Unrefined_States;
29354
29355 -- Local declarations
29356
29357 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
29358 Clause : Node_Id;
29359
29360 -- Start of processing for Analyze_Refined_State_In_Decl_Part
29361
29362 begin
29363 -- Do not analyze the pragma multiple times
29364
29365 if Is_Analyzed_Pragma (N) then
29366 return;
29367 end if;
29368
29369 -- Save the scenario for examination by the ABE Processing phase
29370
29371 Record_Elaboration_Scenario (N);
29372
29373 -- Replicate the abstract states declared by the package because the
29374 -- matching algorithm will consume states.
29375
29376 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
29377
29378 -- Gather all abstract states and objects declared in the visible
29379 -- state space of the package body. These items must be utilized as
29380 -- constituents in a state refinement.
29381
29382 Body_States := Collect_Body_States (Body_Id);
29383
29384 -- Multiple non-null state refinements appear as an aggregate
29385
29386 if Nkind (Clauses) = N_Aggregate then
29387 if Present (Expressions (Clauses)) then
29388 SPARK_Msg_N
29389 ("state refinements must appear as component associations",
29390 Clauses);
29391
29392 else pragma Assert (Present (Component_Associations (Clauses)));
29393 Clause := First (Component_Associations (Clauses));
29394 while Present (Clause) loop
29395 Analyze_Refinement_Clause (Clause);
29396 Next (Clause);
29397 end loop;
29398 end if;
29399
29400 -- Various forms of a single state refinement. Note that these may
29401 -- include malformed refinements.
29402
29403 else
29404 Analyze_Refinement_Clause (Clauses);
29405 end if;
29406
29407 -- List all abstract states that were left unrefined
29408
29409 Report_Unrefined_States (Available_States);
29410
29411 Set_Is_Analyzed_Pragma (N);
29412 end Analyze_Refined_State_In_Decl_Part;
29413
29414 ---------------------------------------------
29415 -- Analyze_Subprogram_Variant_In_Decl_Part --
29416 ---------------------------------------------
29417
29418 -- WARNING: This routine manages Ghost regions. Return statements must be
29419 -- replaced by gotos which jump to the end of the routine and restore the
29420 -- Ghost mode.
29421
29422 procedure Analyze_Subprogram_Variant_In_Decl_Part
29423 (N : Node_Id;
29424 Freeze_Id : Entity_Id := Empty)
29425 is
29426 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
29427 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
29428
29429 procedure Analyze_Variant (Variant : Node_Id);
29430 -- Verify the legality of a single contract case
29431
29432 ---------------------
29433 -- Analyze_Variant --
29434 ---------------------
29435
29436 procedure Analyze_Variant (Variant : Node_Id) is
29437 Direction : Node_Id;
29438 Expr : Node_Id;
29439 Errors : Nat;
29440 Extra_Direction : Node_Id;
29441
29442 begin
29443 if Nkind (Variant) /= N_Component_Association then
29444 Error_Msg_N ("wrong syntax in subprogram variant", Variant);
29445 return;
29446 end if;
29447
29448 Direction := First (Choices (Variant));
29449 Expr := Expression (Variant);
29450
29451 -- Each variant must have exactly one direction
29452
29453 Extra_Direction := Next (Direction);
29454
29455 if Present (Extra_Direction) then
29456 Error_Msg_N
29457 ("subprogram variant case must have exactly one direction",
29458 Extra_Direction);
29459 end if;
29460
29461 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
29462
29463 if Nkind (Direction) = N_Identifier then
29464 if Chars (Direction) not in Name_Decreases
29465 | Name_Increases
29466 | Name_Structural
29467 then
29468 Error_Msg_N ("wrong direction", Direction);
29469 end if;
29470 else
29471 Error_Msg_N ("wrong syntax", Direction);
29472 end if;
29473
29474 Errors := Serious_Errors_Detected;
29475
29476 -- Preanalyze_Assert_Expression, but without enforcing any of the two
29477 -- acceptable types.
29478
29479 Preanalyze_Assert_Expression (Expr);
29480
29481 -- Expression of a discrete type is allowed. Nothing more to check
29482 -- for structural variants.
29483
29484 if Is_Discrete_Type (Etype (Expr))
29485 or else Chars (Direction) = Name_Structural
29486 then
29487 null;
29488
29489 -- Expression of a Big_Integer type (or its ghost variant) is only
29490 -- allowed in Decreases clause.
29491
29492 elsif
29493 Is_RTE (Base_Type (Etype (Expr)), RE_Big_Integer)
29494 or else
29495 Is_RTE (Base_Type (Etype (Expr)), RO_GH_Big_Integer)
29496 then
29497 if Chars (Direction) = Name_Increases then
29498 Error_Msg_N
29499 ("Subprogram_Variant with Big_Integer can only decrease",
29500 Expr);
29501 end if;
29502
29503 -- Expression of other types is not allowed
29504
29505 else
29506 Error_Msg_N ("expected a discrete or Big_Integer type", Expr);
29507 end if;
29508
29509 -- Emit a clarification message when the variant expression
29510 -- contains at least one undefined reference, possibly due
29511 -- to contract freezing.
29512
29513 if Errors /= Serious_Errors_Detected
29514 and then Present (Freeze_Id)
29515 and then Has_Undefined_Reference (Expr)
29516 then
29517 Contract_Freeze_Error (Spec_Id, Freeze_Id);
29518 end if;
29519 end Analyze_Variant;
29520
29521 -- Local variables
29522
29523 Variants : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
29524
29525 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
29526 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
29527 -- Save the Ghost-related attributes to restore on exit
29528
29529 Variant : Node_Id;
29530 Restore_Scope : Boolean := False;
29531
29532 -- Start of processing for Analyze_Subprogram_Variant_In_Decl_Part
29533
29534 begin
29535 -- Do not analyze the pragma multiple times
29536
29537 if Is_Analyzed_Pragma (N) then
29538 return;
29539 end if;
29540
29541 -- Set the Ghost mode in effect from the pragma. Due to the delayed
29542 -- analysis of the pragma, the Ghost mode at point of declaration and
29543 -- point of analysis may not necessarily be the same. Use the mode in
29544 -- effect at the point of declaration.
29545
29546 Set_Ghost_Mode (N);
29547
29548 -- Single and multiple contract cases must appear in aggregate form. If
29549 -- this is not the case, then either the parser of the analysis of the
29550 -- pragma failed to produce an aggregate, e.g. when the contract is
29551 -- "null" or a "(null record)".
29552
29553 pragma Assert
29554 (if Nkind (Variants) = N_Aggregate
29555 then Null_Record_Present (Variants)
29556 xor (Present (Component_Associations (Variants))
29557 or
29558 Present (Expressions (Variants)))
29559 else Nkind (Variants) = N_Null);
29560
29561 -- Only "change_direction => discrete_expression" clauses are allowed
29562
29563 if Nkind (Variants) = N_Aggregate
29564 and then Present (Component_Associations (Variants))
29565 and then No (Expressions (Variants))
29566 then
29567
29568 -- Check that the expression is a proper aggregate (no parentheses)
29569
29570 if Paren_Count (Variants) /= 0 then
29571 Error_Msg_F -- CODEFIX
29572 ("redundant parentheses", Variants);
29573 end if;
29574
29575 -- Ensure that the formal parameters are visible when analyzing all
29576 -- clauses. This falls out of the general rule of aspects pertaining
29577 -- to subprogram declarations.
29578
29579 if not In_Open_Scopes (Spec_Id) then
29580 Restore_Scope := True;
29581 Push_Scope (Spec_Id);
29582
29583 if Is_Generic_Subprogram (Spec_Id) then
29584 Install_Generic_Formals (Spec_Id);
29585 else
29586 Install_Formals (Spec_Id);
29587 end if;
29588 end if;
29589
29590 Variant := First (Component_Associations (Variants));
29591 while Present (Variant) loop
29592 Analyze_Variant (Variant);
29593
29594 if Chars (First (Choices (Variant))) = Name_Structural
29595 and then List_Length (Component_Associations (Variants)) > 1
29596 then
29597 Error_Msg_N
29598 ("Structural variant shall be the only variant", Variant);
29599 end if;
29600
29601 Next (Variant);
29602 end loop;
29603
29604 if Restore_Scope then
29605 End_Scope;
29606 end if;
29607
29608 -- Otherwise the pragma is illegal
29609
29610 else
29611 Error_Msg_N ("wrong syntax for subprogram variant", N);
29612 end if;
29613
29614 Set_Is_Analyzed_Pragma (N);
29615
29616 Restore_Ghost_Region (Saved_GM, Saved_IGR);
29617 end Analyze_Subprogram_Variant_In_Decl_Part;
29618
29619 ------------------------------------
29620 -- Analyze_Test_Case_In_Decl_Part --
29621 ------------------------------------
29622
29623 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
29624 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
29625 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
29626
29627 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
29628 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
29629 -- denoted by Arg_Nam.
29630
29631 ------------------------------
29632 -- Preanalyze_Test_Case_Arg --
29633 ------------------------------
29634
29635 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
29636 Arg : Node_Id;
29637
29638 begin
29639 -- Preanalyze the original aspect argument for a generic subprogram
29640 -- to properly capture global references.
29641
29642 if Is_Generic_Subprogram (Spec_Id) then
29643 Arg :=
29644 Test_Case_Arg
29645 (Prag => N,
29646 Arg_Nam => Arg_Nam,
29647 From_Aspect => True);
29648
29649 if Present (Arg) then
29650 Preanalyze_Assert_Expression
29651 (Expression (Arg), Standard_Boolean);
29652 end if;
29653 end if;
29654
29655 Arg := Test_Case_Arg (N, Arg_Nam);
29656
29657 if Present (Arg) then
29658 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
29659 end if;
29660 end Preanalyze_Test_Case_Arg;
29661
29662 -- Local variables
29663
29664 Restore_Scope : Boolean := False;
29665
29666 -- Start of processing for Analyze_Test_Case_In_Decl_Part
29667
29668 begin
29669 -- Do not analyze the pragma multiple times
29670
29671 if Is_Analyzed_Pragma (N) then
29672 return;
29673 end if;
29674
29675 -- Ensure that the formal parameters are visible when analyzing all
29676 -- clauses. This falls out of the general rule of aspects pertaining
29677 -- to subprogram declarations.
29678
29679 if not In_Open_Scopes (Spec_Id) then
29680 Restore_Scope := True;
29681 Push_Scope (Spec_Id);
29682
29683 if Is_Generic_Subprogram (Spec_Id) then
29684 Install_Generic_Formals (Spec_Id);
29685 else
29686 Install_Formals (Spec_Id);
29687 end if;
29688 end if;
29689
29690 Preanalyze_Test_Case_Arg (Name_Requires);
29691 Preanalyze_Test_Case_Arg (Name_Ensures);
29692
29693 if Restore_Scope then
29694 End_Scope;
29695 end if;
29696
29697 -- Currently it is not possible to inline pre/postconditions on a
29698 -- subprogram subject to pragma Inline_Always.
29699
29700 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
29701
29702 Set_Is_Analyzed_Pragma (N);
29703 end Analyze_Test_Case_In_Decl_Part;
29704
29705 ----------------
29706 -- Appears_In --
29707 ----------------
29708
29709 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
29710 Elmt : Elmt_Id;
29711 Id : Entity_Id;
29712
29713 begin
29714 if Present (List) then
29715 Elmt := First_Elmt (List);
29716 while Present (Elmt) loop
29717 if Nkind (Node (Elmt)) = N_Defining_Identifier then
29718 Id := Node (Elmt);
29719 else
29720 Id := Entity_Of (Node (Elmt));
29721 end if;
29722
29723 if Id = Item_Id then
29724 return True;
29725 end if;
29726
29727 Next_Elmt (Elmt);
29728 end loop;
29729 end if;
29730
29731 return False;
29732 end Appears_In;
29733
29734 -----------------------------------
29735 -- Build_Pragma_Check_Equivalent --
29736 -----------------------------------
29737
29738 function Build_Pragma_Check_Equivalent
29739 (Prag : Node_Id;
29740 Subp_Id : Entity_Id := Empty;
29741 Inher_Id : Entity_Id := Empty;
29742 Keep_Pragma_Id : Boolean := False) return Node_Id
29743 is
29744 function Suppress_Reference (N : Node_Id) return Traverse_Result;
29745 -- Detect whether node N references a formal parameter subject to
29746 -- pragma Unreferenced. If this is the case, set Comes_From_Source
29747 -- to False to suppress the generation of a reference when analyzing
29748 -- N later on.
29749
29750 ------------------------
29751 -- Suppress_Reference --
29752 ------------------------
29753
29754 function Suppress_Reference (N : Node_Id) return Traverse_Result is
29755 Formal : Entity_Id;
29756
29757 begin
29758 if Is_Entity_Name (N) and then Present (Entity (N)) then
29759 Formal := Entity (N);
29760
29761 -- The formal parameter is subject to pragma Unreferenced. Prevent
29762 -- the generation of references by resetting the Comes_From_Source
29763 -- flag.
29764
29765 if Is_Formal (Formal)
29766 and then Has_Pragma_Unreferenced (Formal)
29767 then
29768 Set_Comes_From_Source (N, False);
29769 end if;
29770 end if;
29771
29772 return OK;
29773 end Suppress_Reference;
29774
29775 procedure Suppress_References is
29776 new Traverse_Proc (Suppress_Reference);
29777
29778 -- Local variables
29779
29780 Loc : constant Source_Ptr := Sloc (Prag);
29781 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
29782 Check_Prag : Node_Id;
29783 Msg_Arg : Node_Id;
29784 Nam : Name_Id;
29785
29786 -- Start of processing for Build_Pragma_Check_Equivalent
29787
29788 begin
29789 -- When the pre- or postcondition is inherited, map the formals of the
29790 -- inherited subprogram to those of the current subprogram. In addition,
29791 -- map primitive operations of the parent type into the corresponding
29792 -- primitive operations of the descendant.
29793
29794 if Present (Inher_Id) then
29795 pragma Assert (Present (Subp_Id));
29796
29797 Update_Primitives_Mapping (Inher_Id, Subp_Id);
29798
29799 -- Use generic machinery to copy inherited pragma, as if it were an
29800 -- instantiation, resetting source locations appropriately, so that
29801 -- expressions inside the inherited pragma use chained locations.
29802 -- This is used in particular in GNATprove to locate precisely
29803 -- messages on a given inherited pragma.
29804
29805 Set_Copied_Sloc_For_Inherited_Pragma
29806 (Unit_Declaration_Node (Subp_Id), Inher_Id);
29807 Check_Prag := New_Copy_Tree (Source => Prag);
29808
29809 -- Build the inherited class-wide condition
29810
29811 Build_Class_Wide_Expression
29812 (Pragma_Or_Expr => Check_Prag,
29813 Subp => Subp_Id,
29814 Par_Subp => Inher_Id,
29815 Adjust_Sloc => True);
29816
29817 -- If not an inherited condition simply copy the original pragma
29818
29819 else
29820 Check_Prag := New_Copy_Tree (Source => Prag);
29821 end if;
29822
29823 -- Mark the pragma as being internally generated and reset the Analyzed
29824 -- flag.
29825
29826 Set_Analyzed (Check_Prag, False);
29827 Set_Comes_From_Source (Check_Prag, False);
29828
29829 -- The tree of the original pragma may contain references to the
29830 -- formal parameters of the related subprogram. At the same time
29831 -- the corresponding body may mark the formals as unreferenced:
29832
29833 -- procedure Proc (Formal : ...)
29834 -- with Pre => Formal ...;
29835
29836 -- procedure Proc (Formal : ...) is
29837 -- pragma Unreferenced (Formal);
29838 -- ...
29839
29840 -- This creates problems because all pragma Check equivalents are
29841 -- analyzed at the end of the body declarations. Since all source
29842 -- references have already been accounted for, reset any references
29843 -- to such formals in the generated pragma Check equivalent.
29844
29845 Suppress_References (Check_Prag);
29846
29847 if Present (Corresponding_Aspect (Prag)) then
29848 Nam := Chars (Identifier (Corresponding_Aspect (Prag)));
29849 else
29850 Nam := Prag_Nam;
29851 end if;
29852
29853 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
29854 -- the copied pragma in the newly created pragma, convert the copy into
29855 -- pragma Check by correcting the name and adding a check_kind argument.
29856
29857 if not Keep_Pragma_Id then
29858 Set_Class_Present (Check_Prag, False);
29859
29860 Set_Pragma_Identifier
29861 (Check_Prag, Make_Identifier (Loc, Name_Check));
29862
29863 Prepend_To (Pragma_Argument_Associations (Check_Prag),
29864 Make_Pragma_Argument_Association (Loc,
29865 Expression => Make_Identifier (Loc, Nam)));
29866 end if;
29867
29868 -- Update the error message when the pragma is inherited
29869
29870 if Present (Inher_Id) then
29871 Msg_Arg := Last (Pragma_Argument_Associations (Check_Prag));
29872
29873 if Chars (Msg_Arg) = Name_Message then
29874 String_To_Name_Buffer (Strval (Expression (Msg_Arg)));
29875
29876 -- Insert "inherited" to improve the error message
29877
29878 if Name_Buffer (1 .. 8) = "failed p" then
29879 Insert_Str_In_Name_Buffer ("inherited ", 8);
29880 Set_Strval (Expression (Msg_Arg), String_From_Name_Buffer);
29881 end if;
29882 end if;
29883 end if;
29884
29885 return Check_Prag;
29886 end Build_Pragma_Check_Equivalent;
29887
29888 -----------------------------
29889 -- Check_Applicable_Policy --
29890 -----------------------------
29891
29892 procedure Check_Applicable_Policy (N : Node_Id) is
29893 PP : Node_Id;
29894 Policy : Name_Id;
29895
29896 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
29897
29898 begin
29899 -- No effect if not valid assertion kind name
29900
29901 if not Is_Valid_Assertion_Kind (Ename) then
29902 return;
29903 end if;
29904
29905 -- Loop through entries in check policy list
29906
29907 PP := Opt.Check_Policy_List;
29908 while Present (PP) loop
29909 declare
29910 PPA : constant List_Id := Pragma_Argument_Associations (PP);
29911 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
29912
29913 begin
29914 if Ename = Pnm
29915 or else Pnm = Name_Assertion
29916 or else (Pnm = Name_Statement_Assertions
29917 and then Ename in Name_Assert
29918 | Name_Assert_And_Cut
29919 | Name_Assume
29920 | Name_Loop_Invariant
29921 | Name_Loop_Variant)
29922 then
29923 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
29924
29925 case Policy is
29926 when Name_Ignore
29927 | Name_Off
29928 =>
29929 -- In CodePeer mode and GNATprove mode, we need to
29930 -- consider all assertions, unless they are disabled.
29931 -- Force Is_Checked on ignored assertions, in particular
29932 -- because transformations of the AST may depend on
29933 -- assertions being checked (e.g. the translation of
29934 -- attribute 'Loop_Entry).
29935
29936 if CodePeer_Mode or GNATprove_Mode then
29937 Set_Is_Checked (N, True);
29938 Set_Is_Ignored (N, False);
29939 else
29940 Set_Is_Checked (N, False);
29941 Set_Is_Ignored (N, True);
29942 end if;
29943
29944 when Name_Check
29945 | Name_On
29946 =>
29947 Set_Is_Checked (N, True);
29948 Set_Is_Ignored (N, False);
29949
29950 when Name_Disable =>
29951 Set_Is_Ignored (N, True);
29952 Set_Is_Checked (N, False);
29953 Set_Is_Disabled (N, True);
29954
29955 -- That should be exhaustive, the null here is a defence
29956 -- against a malformed tree from previous errors.
29957
29958 when others =>
29959 null;
29960 end case;
29961
29962 return;
29963 end if;
29964
29965 PP := Next_Pragma (PP);
29966 end;
29967 end loop;
29968
29969 -- If there are no specific entries that matched, then we let the
29970 -- setting of assertions govern. Note that this provides the needed
29971 -- compatibility with the RM for the cases of assertion, invariant,
29972 -- precondition, predicate, and postcondition. Note also that
29973 -- Assertions_Enabled is forced in CodePeer mode and GNATprove mode.
29974
29975 if Assertions_Enabled then
29976 Set_Is_Checked (N, True);
29977 Set_Is_Ignored (N, False);
29978 else
29979 Set_Is_Checked (N, False);
29980 Set_Is_Ignored (N, True);
29981 end if;
29982 end Check_Applicable_Policy;
29983
29984 -------------------------------
29985 -- Check_External_Properties --
29986 -------------------------------
29987
29988 procedure Check_External_Properties
29989 (Item : Node_Id;
29990 AR : Boolean;
29991 AW : Boolean;
29992 ER : Boolean;
29993 EW : Boolean)
29994 is
29995 type Properties is array (Positive range 1 .. 4) of Boolean;
29996 type Combinations is array (Positive range <>) of Properties;
29997 -- Arrays of Async_Readers, Async_Writers, Effective_Writes and
29998 -- Effective_Reads properties and their combinations, respectively.
29999
30000 Specified : constant Properties := (AR, AW, EW, ER);
30001 -- External properties, as given by the Item pragma
30002
30003 Allowed : constant Combinations :=
30004 (1 => (True, False, True, False),
30005 2 => (False, True, False, True),
30006 3 => (True, False, False, False),
30007 4 => (False, True, False, False),
30008 5 => (True, True, True, False),
30009 6 => (True, True, False, True),
30010 7 => (True, True, False, False),
30011 8 => (True, True, True, True));
30012 -- Allowed combinations, as listed in the SPARK RM 7.1.2(6) table
30013
30014 begin
30015 -- Check if the specified properties match any of the allowed
30016 -- combination; if not, then emit an error.
30017
30018 for J in Allowed'Range loop
30019 if Specified = Allowed (J) then
30020 return;
30021 end if;
30022 end loop;
30023
30024 SPARK_Msg_N
30025 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
30026 Item);
30027 end Check_External_Properties;
30028
30029 ----------------
30030 -- Check_Kind --
30031 ----------------
30032
30033 function Check_Kind (Nam : Name_Id) return Name_Id is
30034 PP : Node_Id;
30035
30036 begin
30037 -- Loop through entries in check policy list
30038
30039 PP := Opt.Check_Policy_List;
30040 while Present (PP) loop
30041 declare
30042 PPA : constant List_Id := Pragma_Argument_Associations (PP);
30043 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
30044
30045 begin
30046 if Nam = Pnm
30047 or else (Pnm = Name_Assertion
30048 and then Is_Valid_Assertion_Kind (Nam))
30049 or else (Pnm = Name_Statement_Assertions
30050 and then Nam in Name_Assert
30051 | Name_Assert_And_Cut
30052 | Name_Assume
30053 | Name_Loop_Invariant
30054 | Name_Loop_Variant)
30055 then
30056 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
30057 when Name_Check
30058 | Name_On
30059 =>
30060 return Name_Check;
30061
30062 when Name_Ignore
30063 | Name_Off
30064 =>
30065 return Name_Ignore;
30066
30067 when Name_Disable =>
30068 return Name_Disable;
30069
30070 when others =>
30071 raise Program_Error;
30072 end case;
30073
30074 else
30075 PP := Next_Pragma (PP);
30076 end if;
30077 end;
30078 end loop;
30079
30080 -- If there are no specific entries that matched, then we let the
30081 -- setting of assertions govern. Note that this provides the needed
30082 -- compatibility with the RM for the cases of assertion, invariant,
30083 -- precondition, predicate, and postcondition.
30084
30085 if Assertions_Enabled then
30086 return Name_Check;
30087 else
30088 return Name_Ignore;
30089 end if;
30090 end Check_Kind;
30091
30092 ---------------------------
30093 -- Check_Missing_Part_Of --
30094 ---------------------------
30095
30096 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
30097 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
30098 -- Determine whether a package denoted by Pack_Id declares at least one
30099 -- visible state.
30100
30101 -----------------------
30102 -- Has_Visible_State --
30103 -----------------------
30104
30105 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
30106 Item_Id : Entity_Id;
30107
30108 begin
30109 -- Traverse the entity chain of the package trying to find at least
30110 -- one visible abstract state, variable or a package [instantiation]
30111 -- that declares a visible state.
30112
30113 Item_Id := First_Entity (Pack_Id);
30114 while Present (Item_Id)
30115 and then not In_Private_Part (Item_Id)
30116 loop
30117 -- Do not consider internally generated items
30118
30119 if not Comes_From_Source (Item_Id) then
30120 null;
30121
30122 -- Do not consider generic formals or their corresponding actuals
30123 -- because they are not part of a visible state. Note that both
30124 -- entities are marked as hidden.
30125
30126 elsif Is_Hidden (Item_Id) then
30127 null;
30128
30129 -- A visible state has been found. Note that constants are not
30130 -- considered here because it is not possible to determine whether
30131 -- they depend on variable input. This check is left to the SPARK
30132 -- prover.
30133
30134 elsif Ekind (Item_Id) in E_Abstract_State | E_Variable then
30135 return True;
30136
30137 -- Recursively peek into nested packages and instantiations
30138
30139 elsif Ekind (Item_Id) = E_Package
30140 and then Has_Visible_State (Item_Id)
30141 then
30142 return True;
30143 end if;
30144
30145 Next_Entity (Item_Id);
30146 end loop;
30147
30148 return False;
30149 end Has_Visible_State;
30150
30151 -- Local variables
30152
30153 Pack_Id : Entity_Id;
30154 Placement : State_Space_Kind;
30155
30156 -- Start of processing for Check_Missing_Part_Of
30157
30158 begin
30159 -- Do not consider abstract states, variables or package instantiations
30160 -- coming from an instance as those always inherit the Part_Of indicator
30161 -- of the instance itself.
30162
30163 if In_Instance then
30164 return;
30165
30166 -- Do not consider internally generated entities as these can never
30167 -- have a Part_Of indicator.
30168
30169 elsif not Comes_From_Source (Item_Id) then
30170 return;
30171
30172 -- Perform these checks only when SPARK_Mode is enabled as they will
30173 -- interfere with standard Ada rules and produce false positives.
30174
30175 elsif SPARK_Mode /= On then
30176 return;
30177
30178 -- Do not consider constants, because the compiler cannot accurately
30179 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
30180 -- act as a hidden state of a package.
30181
30182 elsif Ekind (Item_Id) = E_Constant then
30183 return;
30184 end if;
30185
30186 -- Find where the abstract state, variable or package instantiation
30187 -- lives with respect to the state space.
30188
30189 Find_Placement_In_State_Space
30190 (Item_Id => Item_Id,
30191 Placement => Placement,
30192 Pack_Id => Pack_Id);
30193
30194 -- Items that appear in a non-package construct (subprogram, block, etc)
30195 -- do not require a Part_Of indicator because they can never act as a
30196 -- hidden state.
30197
30198 if Placement = Not_In_Package then
30199 null;
30200
30201 -- An item declared in the body state space of a package always act as a
30202 -- constituent and does not need explicit Part_Of indicator.
30203
30204 elsif Placement = Body_State_Space then
30205 null;
30206
30207 -- In general an item declared in the visible state space of a package
30208 -- does not require a Part_Of indicator. The only exception is when the
30209 -- related package is a nongeneric private child unit, in which case
30210 -- Part_Of must denote a state in the parent unit or in one of its
30211 -- descendants.
30212
30213 elsif Placement = Visible_State_Space then
30214 if Is_Child_Unit (Pack_Id)
30215 and then not Is_Generic_Unit (Pack_Id)
30216 and then Is_Private_Descendant (Pack_Id)
30217 then
30218 -- A package instantiation does not need a Part_Of indicator when
30219 -- the related generic template has no visible state.
30220
30221 if Ekind (Item_Id) = E_Package
30222 and then Is_Generic_Instance (Item_Id)
30223 and then not Has_Visible_State (Item_Id)
30224 then
30225 null;
30226
30227 -- All other cases require Part_Of
30228
30229 else
30230 Error_Msg_N
30231 ("indicator Part_Of is required in this context "
30232 & "(SPARK RM 7.2.6(3))", Item_Id);
30233 Error_Msg_Name_1 := Chars (Pack_Id);
30234 Error_Msg_N
30235 ("\& is declared in the visible part of private child "
30236 & "unit %", Item_Id);
30237 end if;
30238 end if;
30239
30240 -- When the item appears in the private state space of a package, it
30241 -- must be a part of some state declared by the said package.
30242
30243 else pragma Assert (Placement = Private_State_Space);
30244
30245 -- The related package does not declare a state, the item cannot act
30246 -- as a Part_Of constituent.
30247
30248 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
30249 null;
30250
30251 -- A package instantiation does not need a Part_Of indicator when the
30252 -- related generic template has no visible state.
30253
30254 elsif Ekind (Item_Id) = E_Package
30255 and then Is_Generic_Instance (Item_Id)
30256 and then not Has_Visible_State (Item_Id)
30257 then
30258 null;
30259
30260 -- All other cases require Part_Of
30261
30262 else
30263 Error_Msg_N
30264 ("indicator Part_Of is required in this context "
30265 & "(SPARK RM 7.2.6(2))", Item_Id);
30266 Error_Msg_Name_1 := Chars (Pack_Id);
30267 Error_Msg_N
30268 ("\& is declared in the private part of package %", Item_Id);
30269 end if;
30270 end if;
30271 end Check_Missing_Part_Of;
30272
30273 ---------------------------------------------------
30274 -- Check_Postcondition_Use_In_Inlined_Subprogram --
30275 ---------------------------------------------------
30276
30277 procedure Check_Postcondition_Use_In_Inlined_Subprogram
30278 (Prag : Node_Id;
30279 Spec_Id : Entity_Id)
30280 is
30281 begin
30282 if Warn_On_Redundant_Constructs
30283 and then Has_Pragma_Inline_Always (Spec_Id)
30284 and then Assertions_Enabled
30285 then
30286 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
30287
30288 if From_Aspect_Specification (Prag) then
30289 Error_Msg_NE
30290 ("aspect % not enforced on inlined subprogram &?r?",
30291 Corresponding_Aspect (Prag), Spec_Id);
30292 else
30293 Error_Msg_NE
30294 ("pragma % not enforced on inlined subprogram &?r?",
30295 Prag, Spec_Id);
30296 end if;
30297 end if;
30298 end Check_Postcondition_Use_In_Inlined_Subprogram;
30299
30300 -------------------------------------
30301 -- Check_State_And_Constituent_Use --
30302 -------------------------------------
30303
30304 procedure Check_State_And_Constituent_Use
30305 (States : Elist_Id;
30306 Constits : Elist_Id;
30307 Context : Node_Id)
30308 is
30309 Constit_Elmt : Elmt_Id;
30310 Constit_Id : Entity_Id;
30311 State_Id : Entity_Id;
30312
30313 begin
30314 -- Nothing to do if there are no states or constituents
30315
30316 if No (States) or else No (Constits) then
30317 return;
30318 end if;
30319
30320 -- Inspect the list of constituents and try to determine whether its
30321 -- encapsulating state is in list States.
30322
30323 Constit_Elmt := First_Elmt (Constits);
30324 while Present (Constit_Elmt) loop
30325 Constit_Id := Node (Constit_Elmt);
30326
30327 -- Determine whether the constituent is part of an encapsulating
30328 -- state that appears in the same context and if this is the case,
30329 -- emit an error (SPARK RM 7.2.6(7)).
30330
30331 State_Id := Find_Encapsulating_State (States, Constit_Id);
30332
30333 if Present (State_Id) then
30334 Error_Msg_Name_1 := Chars (Constit_Id);
30335 SPARK_Msg_NE
30336 ("cannot mention state & and its constituent % in the same "
30337 & "context", Context, State_Id);
30338 exit;
30339 end if;
30340
30341 Next_Elmt (Constit_Elmt);
30342 end loop;
30343 end Check_State_And_Constituent_Use;
30344
30345 ---------------------------------------------
30346 -- Collect_Inherited_Class_Wide_Conditions --
30347 ---------------------------------------------
30348
30349 procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is
30350 Parent_Subp : constant Entity_Id :=
30351 Ultimate_Alias (Overridden_Operation (Subp));
30352 -- The Overridden_Operation may itself be inherited and as such have no
30353 -- explicit contract.
30354
30355 Prags : constant Node_Id := Contract (Parent_Subp);
30356 In_Spec_Expr : Boolean := In_Spec_Expression;
30357 Installed : Boolean;
30358 Prag : Node_Id;
30359 New_Prag : Node_Id;
30360
30361 begin
30362 Installed := False;
30363
30364 -- Iterate over the contract of the overridden subprogram to find all
30365 -- inherited class-wide pre- and postconditions.
30366
30367 if Present (Prags) then
30368 Prag := Pre_Post_Conditions (Prags);
30369
30370 while Present (Prag) loop
30371 if Pragma_Name_Unmapped (Prag)
30372 in Name_Precondition | Name_Postcondition
30373 and then Class_Present (Prag)
30374 then
30375 -- The generated pragma must be analyzed in the context of
30376 -- the subprogram, to make its formals visible. In addition,
30377 -- we must inhibit freezing and full analysis because the
30378 -- controlling type of the subprogram is not frozen yet, and
30379 -- may have further primitives.
30380
30381 if not Installed then
30382 Installed := True;
30383 Push_Scope (Subp);
30384 Install_Formals (Subp);
30385 In_Spec_Expr := In_Spec_Expression;
30386 In_Spec_Expression := True;
30387 end if;
30388
30389 New_Prag :=
30390 Build_Pragma_Check_Equivalent
30391 (Prag, Subp, Parent_Subp, Keep_Pragma_Id => True);
30392
30393 Insert_After (Unit_Declaration_Node (Subp), New_Prag);
30394 Preanalyze (New_Prag);
30395
30396 -- Prevent further analysis in subsequent processing of the
30397 -- current list of declarations
30398
30399 Set_Analyzed (New_Prag);
30400 end if;
30401
30402 Prag := Next_Pragma (Prag);
30403 end loop;
30404
30405 if Installed then
30406 In_Spec_Expression := In_Spec_Expr;
30407 End_Scope;
30408 end if;
30409 end if;
30410 end Collect_Inherited_Class_Wide_Conditions;
30411
30412 ---------------------------------------
30413 -- Collect_Subprogram_Inputs_Outputs --
30414 ---------------------------------------
30415
30416 procedure Collect_Subprogram_Inputs_Outputs
30417 (Subp_Id : Entity_Id;
30418 Synthesize : Boolean := False;
30419 Subp_Inputs : in out Elist_Id;
30420 Subp_Outputs : in out Elist_Id;
30421 Global_Seen : out Boolean)
30422 is
30423 procedure Collect_Dependency_Clause (Clause : Node_Id);
30424 -- Collect all relevant items from a dependency clause
30425
30426 procedure Collect_Global_List
30427 (List : Node_Id;
30428 Mode : Name_Id := Name_Input);
30429 -- Collect all relevant items from a global list
30430
30431 -------------------------------
30432 -- Collect_Dependency_Clause --
30433 -------------------------------
30434
30435 procedure Collect_Dependency_Clause (Clause : Node_Id) is
30436 procedure Collect_Dependency_Item
30437 (Item : Node_Id;
30438 Is_Input : Boolean);
30439 -- Add an item to the proper subprogram input or output collection
30440
30441 -----------------------------
30442 -- Collect_Dependency_Item --
30443 -----------------------------
30444
30445 procedure Collect_Dependency_Item
30446 (Item : Node_Id;
30447 Is_Input : Boolean)
30448 is
30449 Extra : Node_Id;
30450
30451 begin
30452 -- Nothing to collect when the item is null
30453
30454 if Nkind (Item) = N_Null then
30455 null;
30456
30457 -- Ditto for attribute 'Result
30458
30459 elsif Is_Attribute_Result (Item) then
30460 null;
30461
30462 -- Multiple items appear as an aggregate
30463
30464 elsif Nkind (Item) = N_Aggregate then
30465 Extra := First (Expressions (Item));
30466 while Present (Extra) loop
30467 Collect_Dependency_Item (Extra, Is_Input);
30468 Next (Extra);
30469 end loop;
30470
30471 -- Otherwise this is a solitary item
30472
30473 else
30474 if Is_Input then
30475 Append_New_Elmt (Item, Subp_Inputs);
30476 else
30477 Append_New_Elmt (Item, Subp_Outputs);
30478 end if;
30479 end if;
30480 end Collect_Dependency_Item;
30481
30482 -- Start of processing for Collect_Dependency_Clause
30483
30484 begin
30485 if Nkind (Clause) = N_Null then
30486 null;
30487
30488 -- A dependency clause appears as component association
30489
30490 elsif Nkind (Clause) = N_Component_Association then
30491 Collect_Dependency_Item
30492 (Item => Expression (Clause),
30493 Is_Input => True);
30494
30495 Collect_Dependency_Item
30496 (Item => First (Choices (Clause)),
30497 Is_Input => False);
30498
30499 -- To accommodate partial decoration of disabled SPARK features, this
30500 -- routine may be called with illegal input. If this is the case, do
30501 -- not raise Program_Error.
30502
30503 else
30504 null;
30505 end if;
30506 end Collect_Dependency_Clause;
30507
30508 -------------------------
30509 -- Collect_Global_List --
30510 -------------------------
30511
30512 procedure Collect_Global_List
30513 (List : Node_Id;
30514 Mode : Name_Id := Name_Input)
30515 is
30516 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
30517 -- Add an item to the proper subprogram input or output collection
30518
30519 -------------------------
30520 -- Collect_Global_Item --
30521 -------------------------
30522
30523 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
30524 begin
30525 if Mode in Name_In_Out | Name_Input then
30526 Append_New_Elmt (Item, Subp_Inputs);
30527 end if;
30528
30529 if Mode in Name_In_Out | Name_Output then
30530 Append_New_Elmt (Item, Subp_Outputs);
30531 end if;
30532 end Collect_Global_Item;
30533
30534 -- Local variables
30535
30536 Assoc : Node_Id;
30537 Item : Node_Id;
30538
30539 -- Start of processing for Collect_Global_List
30540
30541 begin
30542 if Nkind (List) = N_Null then
30543 null;
30544
30545 -- Single global item declaration
30546
30547 elsif Nkind (List) in N_Expanded_Name
30548 | N_Identifier
30549 | N_Selected_Component
30550 then
30551 Collect_Global_Item (List, Mode);
30552
30553 -- Simple global list or moded global list declaration
30554
30555 elsif Nkind (List) = N_Aggregate then
30556 if Present (Expressions (List)) then
30557 Item := First (Expressions (List));
30558 while Present (Item) loop
30559 Collect_Global_Item (Item, Mode);
30560 Next (Item);
30561 end loop;
30562
30563 else
30564 Assoc := First (Component_Associations (List));
30565 while Present (Assoc) loop
30566 Collect_Global_List
30567 (List => Expression (Assoc),
30568 Mode => Chars (First (Choices (Assoc))));
30569 Next (Assoc);
30570 end loop;
30571 end if;
30572
30573 -- To accommodate partial decoration of disabled SPARK features, this
30574 -- routine may be called with illegal input. If this is the case, do
30575 -- not raise Program_Error.
30576
30577 else
30578 null;
30579 end if;
30580 end Collect_Global_List;
30581
30582 -- Local variables
30583
30584 Clause : Node_Id;
30585 Clauses : Node_Id;
30586 Depends : Node_Id;
30587 Formal : Entity_Id;
30588 Global : Node_Id;
30589 Spec_Id : Entity_Id := Empty;
30590 Subp_Decl : Node_Id;
30591 Typ : Entity_Id;
30592
30593 -- Start of processing for Collect_Subprogram_Inputs_Outputs
30594
30595 begin
30596 Global_Seen := False;
30597
30598 -- Process all formal parameters of entries, [generic] subprograms, and
30599 -- their bodies.
30600
30601 if Ekind (Subp_Id) in E_Entry
30602 | E_Entry_Family
30603 | E_Function
30604 | E_Generic_Function
30605 | E_Generic_Procedure
30606 | E_Procedure
30607 | E_Subprogram_Body
30608 then
30609 Subp_Decl := Unit_Declaration_Node (Subp_Id);
30610 Spec_Id := Unique_Defining_Entity (Subp_Decl);
30611
30612 -- Process all formal parameters
30613
30614 Formal := First_Formal (Spec_Id);
30615 while Present (Formal) loop
30616 if Ekind (Formal) in E_In_Out_Parameter | E_In_Parameter then
30617 Append_New_Elmt (Formal, Subp_Inputs);
30618 end if;
30619
30620 if Ekind (Formal) in E_In_Out_Parameter | E_Out_Parameter then
30621 Append_New_Elmt (Formal, Subp_Outputs);
30622
30623 -- OUT parameters can act as inputs when the related type is
30624 -- tagged, unconstrained array, unconstrained record, or record
30625 -- with unconstrained components.
30626
30627 if Ekind (Formal) = E_Out_Parameter
30628 and then Is_Unconstrained_Or_Tagged_Item (Formal)
30629 then
30630 Append_New_Elmt (Formal, Subp_Inputs);
30631 end if;
30632 end if;
30633
30634 -- IN parameters of procedures and protected entries can act as
30635 -- outputs when the related type is access-to-variable.
30636
30637 if Ekind (Formal) = E_In_Parameter
30638 and then Ekind (Spec_Id) not in E_Function
30639 | E_Generic_Function
30640 and then Is_Access_Variable (Etype (Formal))
30641 then
30642 Append_New_Elmt (Formal, Subp_Outputs);
30643 end if;
30644
30645 Next_Formal (Formal);
30646 end loop;
30647
30648 -- Otherwise the input denotes a task type, a task body, or the
30649 -- anonymous object created for a single task type.
30650
30651 elsif Ekind (Subp_Id) in E_Task_Type | E_Task_Body
30652 or else Is_Single_Task_Object (Subp_Id)
30653 then
30654 Subp_Decl := Declaration_Node (Subp_Id);
30655 Spec_Id := Unique_Defining_Entity (Subp_Decl);
30656 end if;
30657
30658 -- When processing an entry, subprogram or task body, look for pragmas
30659 -- Refined_Depends and Refined_Global as they specify the inputs and
30660 -- outputs.
30661
30662 if Is_Entry_Body (Subp_Id)
30663 or else Ekind (Subp_Id) in E_Subprogram_Body | E_Task_Body
30664 then
30665 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
30666 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
30667
30668 -- Subprogram declaration or stand-alone body case, look for pragmas
30669 -- Depends and Global.
30670
30671 else
30672 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
30673 Global := Get_Pragma (Spec_Id, Pragma_Global);
30674 end if;
30675
30676 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
30677 -- because it provides finer granularity of inputs and outputs.
30678
30679 if Present (Global) then
30680 Global_Seen := True;
30681 Collect_Global_List (Expression (Get_Argument (Global, Spec_Id)));
30682
30683 -- When the related subprogram lacks pragma [Refined_]Global, fall back
30684 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
30685 -- the inputs and outputs from [Refined_]Depends.
30686
30687 elsif Synthesize and then Present (Depends) then
30688 Clauses := Expression (Get_Argument (Depends, Spec_Id));
30689
30690 -- Multiple dependency clauses appear as an aggregate
30691
30692 if Nkind (Clauses) = N_Aggregate then
30693 Clause := First (Component_Associations (Clauses));
30694 while Present (Clause) loop
30695 Collect_Dependency_Clause (Clause);
30696 Next (Clause);
30697 end loop;
30698
30699 -- Otherwise this is a single dependency clause
30700
30701 else
30702 Collect_Dependency_Clause (Clauses);
30703 end if;
30704 end if;
30705
30706 -- The current instance of a protected type acts as a formal parameter
30707 -- of mode IN for functions and IN OUT for entries and procedures
30708 -- (SPARK RM 6.1.4).
30709
30710 if Ekind (Scope (Spec_Id)) = E_Protected_Type then
30711 Typ := Scope (Spec_Id);
30712
30713 -- Use the anonymous object when the type is single protected
30714
30715 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
30716 Typ := Anonymous_Object (Typ);
30717 end if;
30718
30719 Append_New_Elmt (Typ, Subp_Inputs);
30720
30721 if Ekind (Spec_Id) in E_Entry | E_Entry_Family | E_Procedure then
30722 Append_New_Elmt (Typ, Subp_Outputs);
30723 end if;
30724
30725 -- The current instance of a task type acts as a formal parameter of
30726 -- mode IN OUT (SPARK RM 6.1.4).
30727
30728 elsif Ekind (Spec_Id) = E_Task_Type then
30729 Typ := Spec_Id;
30730
30731 -- Use the anonymous object when the type is single task
30732
30733 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
30734 Typ := Anonymous_Object (Typ);
30735 end if;
30736
30737 Append_New_Elmt (Typ, Subp_Inputs);
30738 Append_New_Elmt (Typ, Subp_Outputs);
30739
30740 elsif Is_Single_Task_Object (Spec_Id) then
30741 Append_New_Elmt (Spec_Id, Subp_Inputs);
30742 Append_New_Elmt (Spec_Id, Subp_Outputs);
30743 end if;
30744 end Collect_Subprogram_Inputs_Outputs;
30745
30746 ---------------------------
30747 -- Contract_Freeze_Error --
30748 ---------------------------
30749
30750 procedure Contract_Freeze_Error
30751 (Contract_Id : Entity_Id;
30752 Freeze_Id : Entity_Id)
30753 is
30754 begin
30755 Error_Msg_Name_1 := Chars (Contract_Id);
30756 Error_Msg_Sloc := Sloc (Freeze_Id);
30757
30758 SPARK_Msg_NE
30759 ("body & declared # freezes the contract of%", Contract_Id, Freeze_Id);
30760 SPARK_Msg_N
30761 ("\all contractual items must be declared before body #", Contract_Id);
30762 end Contract_Freeze_Error;
30763
30764 ---------------------------------
30765 -- Delay_Config_Pragma_Analyze --
30766 ---------------------------------
30767
30768 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
30769 begin
30770 return Pragma_Name_Unmapped (N)
30771 in Name_Interrupt_State | Name_Priority_Specific_Dispatching;
30772 end Delay_Config_Pragma_Analyze;
30773
30774 -----------------------
30775 -- Duplication_Error --
30776 -----------------------
30777
30778 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
30779 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
30780 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
30781
30782 begin
30783 Error_Msg_Sloc := Sloc (Prev);
30784 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
30785
30786 -- Emit a precise message to distinguish between source pragmas and
30787 -- pragmas generated from aspects. The ordering of the two pragmas is
30788 -- the following:
30789
30790 -- Prev -- ok
30791 -- Prag -- duplicate
30792
30793 -- No error is emitted when both pragmas come from aspects because this
30794 -- is already detected by the general aspect analysis mechanism.
30795
30796 if Prag_From_Asp and Prev_From_Asp then
30797 null;
30798 elsif Prag_From_Asp then
30799 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
30800 elsif Prev_From_Asp then
30801 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
30802 else
30803 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
30804 end if;
30805 end Duplication_Error;
30806
30807 ------------------------------
30808 -- Find_Encapsulating_State --
30809 ------------------------------
30810
30811 function Find_Encapsulating_State
30812 (States : Elist_Id;
30813 Constit_Id : Entity_Id) return Entity_Id
30814 is
30815 State_Id : Entity_Id;
30816
30817 begin
30818 -- Since a constituent may be part of a larger constituent set, climb
30819 -- the encapsulating state chain looking for a state that appears in
30820 -- States.
30821
30822 State_Id := Encapsulating_State (Constit_Id);
30823 while Present (State_Id) loop
30824 if Contains (States, State_Id) then
30825 return State_Id;
30826 end if;
30827
30828 State_Id := Encapsulating_State (State_Id);
30829 end loop;
30830
30831 return Empty;
30832 end Find_Encapsulating_State;
30833
30834 --------------------------
30835 -- Find_Related_Context --
30836 --------------------------
30837
30838 function Find_Related_Context
30839 (Prag : Node_Id;
30840 Do_Checks : Boolean := False) return Node_Id
30841 is
30842 Stmt : Node_Id;
30843
30844 begin
30845 -- If the pragma comes from an aspect on a compilation unit that is a
30846 -- package instance, then return the original package instantiation
30847 -- node.
30848
30849 if Nkind (Parent (Prag)) = N_Compilation_Unit_Aux then
30850 return
30851 Get_Unit_Instantiation_Node
30852 (Defining_Entity (Unit (Enclosing_Comp_Unit_Node (Prag))));
30853 end if;
30854
30855 Stmt := Prev (Prag);
30856 while Present (Stmt) loop
30857
30858 -- Skip prior pragmas, but check for duplicates
30859
30860 if Nkind (Stmt) = N_Pragma then
30861 if Do_Checks
30862 and then Pragma_Name (Stmt) = Pragma_Name (Prag)
30863 then
30864 Duplication_Error
30865 (Prag => Prag,
30866 Prev => Stmt);
30867 end if;
30868
30869 -- Skip internally generated code
30870
30871 elsif not Comes_From_Source (Stmt)
30872 and then not Comes_From_Source (Original_Node (Stmt))
30873 then
30874
30875 -- The anonymous object created for a single concurrent type is a
30876 -- suitable context.
30877
30878 if Nkind (Stmt) = N_Object_Declaration
30879 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
30880 then
30881 return Stmt;
30882 end if;
30883
30884 -- Return the current source construct
30885
30886 else
30887 return Stmt;
30888 end if;
30889
30890 Prev (Stmt);
30891 end loop;
30892
30893 return Empty;
30894 end Find_Related_Context;
30895
30896 --------------------------------------
30897 -- Find_Related_Declaration_Or_Body --
30898 --------------------------------------
30899
30900 function Find_Related_Declaration_Or_Body
30901 (Prag : Node_Id;
30902 Do_Checks : Boolean := False) return Node_Id
30903 is
30904 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
30905
30906 procedure Expression_Function_Error;
30907 -- Emit an error concerning pragma Prag that illegaly applies to an
30908 -- expression function.
30909
30910 -------------------------------
30911 -- Expression_Function_Error --
30912 -------------------------------
30913
30914 procedure Expression_Function_Error is
30915 begin
30916 Error_Msg_Name_1 := Prag_Nam;
30917
30918 -- Emit a precise message to distinguish between source pragmas and
30919 -- pragmas generated from aspects.
30920
30921 if From_Aspect_Specification (Prag) then
30922 Error_Msg_N
30923 ("aspect % cannot apply to a standalone expression function",
30924 Prag);
30925 else
30926 Error_Msg_N
30927 ("pragma % cannot apply to a standalone expression function",
30928 Prag);
30929 end if;
30930 end Expression_Function_Error;
30931
30932 -- Local variables
30933
30934 Context : constant Node_Id := Parent (Prag);
30935 Stmt : Node_Id;
30936
30937 Look_For_Body : constant Boolean :=
30938 Prag_Nam in Name_Refined_Depends
30939 | Name_Refined_Global
30940 | Name_Refined_Post
30941 | Name_Refined_State;
30942 -- Refinement pragmas must be associated with a subprogram body [stub]
30943
30944 -- Start of processing for Find_Related_Declaration_Or_Body
30945
30946 begin
30947 Stmt := Prev (Prag);
30948 while Present (Stmt) loop
30949
30950 -- Skip prior pragmas, but check for duplicates. Pragmas produced
30951 -- by splitting a complex pre/postcondition are not considered to
30952 -- be duplicates.
30953
30954 if Nkind (Stmt) = N_Pragma then
30955 if Do_Checks
30956 and then not Split_PPC (Stmt)
30957 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
30958 then
30959 Duplication_Error
30960 (Prag => Prag,
30961 Prev => Stmt);
30962 end if;
30963
30964 -- Emit an error when a refinement pragma appears on an expression
30965 -- function without a completion.
30966
30967 elsif Do_Checks
30968 and then Look_For_Body
30969 and then Nkind (Stmt) = N_Subprogram_Declaration
30970 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
30971 and then not Has_Completion (Defining_Entity (Stmt))
30972 then
30973 Expression_Function_Error;
30974 return Empty;
30975
30976 -- The refinement pragma applies to a subprogram body stub
30977
30978 elsif Look_For_Body
30979 and then Nkind (Stmt) = N_Subprogram_Body_Stub
30980 then
30981 return Stmt;
30982
30983 -- Skip internally generated code
30984
30985 elsif not Comes_From_Source (Stmt) then
30986
30987 -- The anonymous object created for a single concurrent type is a
30988 -- suitable context.
30989
30990 if Nkind (Stmt) = N_Object_Declaration
30991 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
30992 then
30993 return Stmt;
30994
30995 elsif Nkind (Stmt) = N_Subprogram_Declaration then
30996
30997 -- The subprogram declaration is an internally generated spec
30998 -- for an expression function.
30999
31000 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
31001 return Stmt;
31002
31003 -- The subprogram declaration is an internally generated spec
31004 -- for a stand-alone subprogram body declared inside a
31005 -- protected body.
31006
31007 elsif Present (Corresponding_Body (Stmt))
31008 and then Comes_From_Source (Corresponding_Body (Stmt))
31009 and then Is_Protected_Type (Current_Scope)
31010 then
31011 return Stmt;
31012
31013 -- The subprogram is actually an instance housed within an
31014 -- anonymous wrapper package.
31015
31016 elsif Present (Generic_Parent (Specification (Stmt))) then
31017 return Stmt;
31018
31019 -- Ada 2022: contract on formal subprogram or on generated
31020 -- Access_Subprogram_Wrapper, which appears after the related
31021 -- Access_Subprogram declaration.
31022
31023 elsif Is_Generic_Actual_Subprogram (Defining_Entity (Stmt))
31024 and then Ada_Version >= Ada_2022
31025 then
31026 return Stmt;
31027
31028 elsif Is_Access_Subprogram_Wrapper (Defining_Entity (Stmt))
31029 and then Ada_Version >= Ada_2022
31030 then
31031 return Stmt;
31032 end if;
31033 end if;
31034
31035 -- Return the current construct which is either a subprogram body,
31036 -- a subprogram declaration or is illegal.
31037
31038 else
31039 return Stmt;
31040 end if;
31041
31042 Prev (Stmt);
31043 end loop;
31044
31045 -- If we fall through, then the pragma was either the first declaration
31046 -- or it was preceded by other pragmas and no source constructs.
31047
31048 -- The pragma is associated with a library-level subprogram
31049
31050 if Nkind (Context) = N_Compilation_Unit_Aux then
31051 return Unit (Parent (Context));
31052
31053 -- The pragma appears inside the declarations of an entry body
31054
31055 elsif Nkind (Context) = N_Entry_Body then
31056 return Context;
31057
31058 -- The pragma appears inside the statements of a subprogram body at
31059 -- some nested level.
31060
31061 elsif Is_Statement (Context)
31062 and then Present (Enclosing_HSS (Context))
31063 then
31064 return Parent (Enclosing_HSS (Context));
31065
31066 -- The pragma appears directly in the statements of a subprogram body
31067
31068 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
31069 return Parent (Context);
31070
31071 -- The pragma appears inside the declarative part of a package body
31072
31073 elsif Nkind (Context) = N_Package_Body then
31074 return Context;
31075
31076 -- The pragma appears inside the declarative part of a subprogram body
31077
31078 elsif Nkind (Context) = N_Subprogram_Body then
31079 return Context;
31080
31081 -- The pragma appears inside the declarative part of a task body
31082
31083 elsif Nkind (Context) = N_Task_Body then
31084 return Context;
31085
31086 -- The pragma appears inside the visible part of a package specification
31087
31088 elsif Nkind (Context) = N_Package_Specification then
31089 return Parent (Context);
31090
31091 -- The pragma is a byproduct of aspect expansion, return the related
31092 -- context of the original aspect. This case has a lower priority as
31093 -- the above circuitry pinpoints precisely the related context.
31094
31095 elsif Present (Corresponding_Aspect (Prag)) then
31096 return Parent (Corresponding_Aspect (Prag));
31097
31098 -- No candidate subprogram [body] found
31099
31100 else
31101 return Empty;
31102 end if;
31103 end Find_Related_Declaration_Or_Body;
31104
31105 ----------------------------------
31106 -- Find_Related_Package_Or_Body --
31107 ----------------------------------
31108
31109 function Find_Related_Package_Or_Body
31110 (Prag : Node_Id;
31111 Do_Checks : Boolean := False) return Node_Id
31112 is
31113 Context : constant Node_Id := Parent (Prag);
31114 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
31115 Stmt : Node_Id;
31116
31117 begin
31118 Stmt := Prev (Prag);
31119 while Present (Stmt) loop
31120
31121 -- Skip prior pragmas, but check for duplicates
31122
31123 if Nkind (Stmt) = N_Pragma then
31124 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
31125 Duplication_Error
31126 (Prag => Prag,
31127 Prev => Stmt);
31128 end if;
31129
31130 -- Skip internally generated code
31131
31132 elsif not Comes_From_Source (Stmt) then
31133 if Nkind (Stmt) = N_Subprogram_Declaration then
31134
31135 -- The subprogram declaration is an internally generated spec
31136 -- for an expression function.
31137
31138 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
31139 return Stmt;
31140
31141 -- The subprogram is actually an instance housed within an
31142 -- anonymous wrapper package.
31143
31144 elsif Present (Generic_Parent (Specification (Stmt))) then
31145 return Stmt;
31146 end if;
31147 end if;
31148
31149 -- Return the current source construct which is illegal
31150
31151 else
31152 return Stmt;
31153 end if;
31154
31155 Prev (Stmt);
31156 end loop;
31157
31158 -- If we fall through, then the pragma was either the first declaration
31159 -- or it was preceded by other pragmas and no source constructs.
31160
31161 -- The pragma is associated with a package. The immediate context in
31162 -- this case is the specification of the package.
31163
31164 if Nkind (Context) = N_Package_Specification then
31165 return Parent (Context);
31166
31167 -- The pragma appears in the declarations of a package body
31168
31169 elsif Nkind (Context) = N_Package_Body then
31170 return Context;
31171
31172 -- The pragma appears in the statements of a package body
31173
31174 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
31175 and then Nkind (Parent (Context)) = N_Package_Body
31176 then
31177 return Parent (Context);
31178
31179 -- The pragma is a byproduct of aspect expansion, return the related
31180 -- context of the original aspect. This case has a lower priority as
31181 -- the above circuitry pinpoints precisely the related context.
31182
31183 elsif Present (Corresponding_Aspect (Prag)) then
31184 return Parent (Corresponding_Aspect (Prag));
31185
31186 -- No candidate package [body] found
31187
31188 else
31189 return Empty;
31190 end if;
31191 end Find_Related_Package_Or_Body;
31192
31193 ------------------
31194 -- Get_Argument --
31195 ------------------
31196
31197 function Get_Argument
31198 (Prag : Node_Id;
31199 Context_Id : Entity_Id := Empty) return Node_Id
31200 is
31201 Args : constant List_Id := Pragma_Argument_Associations (Prag);
31202
31203 begin
31204 -- Use the expression of the original aspect when analyzing the template
31205 -- of a generic unit. In both cases the aspect's tree must be decorated
31206 -- to save the global references in the generic context.
31207
31208 if From_Aspect_Specification (Prag)
31209 and then (Present (Context_Id) and then Is_Generic_Unit (Context_Id))
31210 then
31211 return Corresponding_Aspect (Prag);
31212
31213 -- Otherwise use the expression of the pragma
31214
31215 elsif Present (Args) then
31216 return First (Args);
31217
31218 else
31219 return Empty;
31220 end if;
31221 end Get_Argument;
31222
31223 -------------------------
31224 -- Get_Base_Subprogram --
31225 -------------------------
31226
31227 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
31228 begin
31229 -- Follow subprogram renaming chain
31230
31231 if Is_Subprogram (Def_Id)
31232 and then Parent_Kind (Declaration_Node (Def_Id)) =
31233 N_Subprogram_Renaming_Declaration
31234 and then Present (Alias (Def_Id))
31235 then
31236 return Alias (Def_Id);
31237 else
31238 return Def_Id;
31239 end if;
31240 end Get_Base_Subprogram;
31241
31242 -------------------------
31243 -- Get_SPARK_Mode_Type --
31244 -------------------------
31245
31246 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
31247 begin
31248 case N is
31249 when Name_Auto =>
31250 return None;
31251 when Name_On =>
31252 return On;
31253 when Name_Off =>
31254 return Off;
31255
31256 -- Any other argument is illegal. Assume that no SPARK mode applies
31257 -- to avoid potential cascaded errors.
31258
31259 when others =>
31260 return None;
31261 end case;
31262 end Get_SPARK_Mode_Type;
31263
31264 ------------------------------------
31265 -- Get_SPARK_Mode_From_Annotation --
31266 ------------------------------------
31267
31268 function Get_SPARK_Mode_From_Annotation
31269 (N : Node_Id) return SPARK_Mode_Type
31270 is
31271 Mode : Node_Id;
31272
31273 begin
31274 if Nkind (N) = N_Aspect_Specification then
31275 Mode := Expression (N);
31276
31277 else pragma Assert (Nkind (N) = N_Pragma);
31278 Mode := First (Pragma_Argument_Associations (N));
31279
31280 if Present (Mode) then
31281 Mode := Get_Pragma_Arg (Mode);
31282 end if;
31283 end if;
31284
31285 -- Aspect or pragma SPARK_Mode specifies an explicit mode
31286
31287 if Present (Mode) then
31288 if Nkind (Mode) = N_Identifier then
31289 return Get_SPARK_Mode_Type (Chars (Mode));
31290
31291 -- In case of a malformed aspect or pragma, return the default None
31292
31293 else
31294 return None;
31295 end if;
31296
31297 -- Otherwise the lack of an expression defaults SPARK_Mode to On
31298
31299 else
31300 return On;
31301 end if;
31302 end Get_SPARK_Mode_From_Annotation;
31303
31304 ---------------------------
31305 -- Has_Extra_Parentheses --
31306 ---------------------------
31307
31308 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
31309 Expr : Node_Id;
31310
31311 begin
31312 -- The aggregate should not have an expression list because a clause
31313 -- is always interpreted as a component association. The only way an
31314 -- expression list can sneak in is by adding extra parentheses around
31315 -- the individual clauses:
31316
31317 -- Depends (Output => Input) -- proper form
31318 -- Depends ((Output => Input)) -- extra parentheses
31319
31320 -- Since the extra parentheses are not allowed by the syntax of the
31321 -- pragma, flag them now to avoid emitting misleading errors down the
31322 -- line.
31323
31324 if Nkind (Clause) = N_Aggregate
31325 and then Present (Expressions (Clause))
31326 then
31327 Expr := First (Expressions (Clause));
31328 while Present (Expr) loop
31329
31330 -- A dependency clause surrounded by extra parentheses appears
31331 -- as an aggregate of component associations with an optional
31332 -- Paren_Count set.
31333
31334 if Nkind (Expr) = N_Aggregate
31335 and then Present (Component_Associations (Expr))
31336 then
31337 SPARK_Msg_N
31338 ("dependency clause contains extra parentheses", Expr);
31339
31340 -- Otherwise the expression is a malformed construct
31341
31342 else
31343 SPARK_Msg_N ("malformed dependency clause", Expr);
31344 end if;
31345
31346 Next (Expr);
31347 end loop;
31348
31349 return True;
31350 end if;
31351
31352 return False;
31353 end Has_Extra_Parentheses;
31354
31355 ----------------
31356 -- Initialize --
31357 ----------------
31358
31359 procedure Initialize is
31360 begin
31361 Externals.Init;
31362 Compile_Time_Warnings_Errors.Init;
31363 end Initialize;
31364
31365 --------
31366 -- ip --
31367 --------
31368
31369 procedure ip is
31370 begin
31371 Dummy := Dummy + 1;
31372 end ip;
31373
31374 -----------------------------
31375 -- Is_Config_Static_String --
31376 -----------------------------
31377
31378 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
31379
31380 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
31381 -- This is an internal recursive function that is just like the outer
31382 -- function except that it adds the string to the name buffer rather
31383 -- than placing the string in the name buffer.
31384
31385 ------------------------------
31386 -- Add_Config_Static_String --
31387 ------------------------------
31388
31389 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
31390 N : Node_Id;
31391 C : Char_Code;
31392
31393 begin
31394 N := Arg;
31395
31396 if Nkind (N) = N_Op_Concat then
31397 if Add_Config_Static_String (Left_Opnd (N)) then
31398 N := Right_Opnd (N);
31399 else
31400 return False;
31401 end if;
31402 end if;
31403
31404 if Nkind (N) /= N_String_Literal then
31405 Error_Msg_N ("string literal expected for pragma argument", N);
31406 return False;
31407
31408 else
31409 for J in 1 .. String_Length (Strval (N)) loop
31410 C := Get_String_Char (Strval (N), J);
31411
31412 if not In_Character_Range (C) then
31413 Error_Msg
31414 ("string literal contains invalid wide character",
31415 Sloc (N) + 1 + Source_Ptr (J));
31416 return False;
31417 end if;
31418
31419 Add_Char_To_Name_Buffer (Get_Character (C));
31420 end loop;
31421 end if;
31422
31423 return True;
31424 end Add_Config_Static_String;
31425
31426 -- Start of processing for Is_Config_Static_String
31427
31428 begin
31429 Name_Len := 0;
31430
31431 return Add_Config_Static_String (Arg);
31432 end Is_Config_Static_String;
31433
31434 -------------------------------
31435 -- Is_Elaboration_SPARK_Mode --
31436 -------------------------------
31437
31438 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
31439 begin
31440 pragma Assert
31441 (Nkind (N) = N_Pragma
31442 and then Pragma_Name (N) = Name_SPARK_Mode
31443 and then Is_List_Member (N));
31444
31445 -- Pragma SPARK_Mode affects the elaboration of a package body when it
31446 -- appears in the statement part of the body.
31447
31448 return
31449 Present (Parent (N))
31450 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
31451 and then List_Containing (N) = Statements (Parent (N))
31452 and then Present (Parent (Parent (N)))
31453 and then Nkind (Parent (Parent (N))) = N_Package_Body;
31454 end Is_Elaboration_SPARK_Mode;
31455
31456 -----------------------
31457 -- Is_Enabled_Pragma --
31458 -----------------------
31459
31460 function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is
31461 Arg : Node_Id;
31462
31463 begin
31464 if Present (Prag) then
31465 Arg := First (Pragma_Argument_Associations (Prag));
31466
31467 if Present (Arg) then
31468 return Is_True (Expr_Value (Get_Pragma_Arg (Arg)));
31469
31470 -- The lack of a Boolean argument automatically enables the pragma
31471
31472 else
31473 return True;
31474 end if;
31475
31476 -- The pragma is missing, therefore it is not enabled
31477
31478 else
31479 return False;
31480 end if;
31481 end Is_Enabled_Pragma;
31482
31483 -----------------------------------------
31484 -- Is_Non_Significant_Pragma_Reference --
31485 -----------------------------------------
31486
31487 -- This function makes use of the following static table which indicates
31488 -- whether appearance of some name in a given pragma is to be considered
31489 -- as a reference for the purposes of warnings about unreferenced objects.
31490
31491 -- -1 indicates that appearance in any argument is significant
31492 -- 0 indicates that appearance in any argument is not significant
31493 -- +n indicates that appearance as argument n is significant, but all
31494 -- other arguments are not significant
31495 -- 9n arguments from n on are significant, before n insignificant
31496
31497 Sig_Flags : constant array (Pragma_Id) of Int :=
31498 (Pragma_Abort_Defer => -1,
31499 Pragma_Abstract_State => -1,
31500 Pragma_Ada_83 => -1,
31501 Pragma_Ada_95 => -1,
31502 Pragma_Ada_05 => -1,
31503 Pragma_Ada_2005 => -1,
31504 Pragma_Ada_12 => -1,
31505 Pragma_Ada_2012 => -1,
31506 Pragma_Ada_2022 => -1,
31507 Pragma_Aggregate_Individually_Assign => 0,
31508 Pragma_All_Calls_Remote => -1,
31509 Pragma_Allow_Integer_Address => -1,
31510 Pragma_Annotate => 93,
31511 Pragma_Assert => -1,
31512 Pragma_Assert_And_Cut => -1,
31513 Pragma_Assertion_Policy => 0,
31514 Pragma_Assume => -1,
31515 Pragma_Assume_No_Invalid_Values => 0,
31516 Pragma_Async_Readers => 0,
31517 Pragma_Async_Writers => 0,
31518 Pragma_Asynchronous => 0,
31519 Pragma_Atomic => 0,
31520 Pragma_Atomic_Components => 0,
31521 Pragma_Attach_Handler => -1,
31522 Pragma_Attribute_Definition => 92,
31523 Pragma_Check => -1,
31524 Pragma_Check_Float_Overflow => 0,
31525 Pragma_Check_Name => 0,
31526 Pragma_Check_Policy => 0,
31527 Pragma_CPP_Class => 0,
31528 Pragma_CPP_Constructor => 0,
31529 Pragma_CPP_Virtual => 0,
31530 Pragma_CPP_Vtable => 0,
31531 Pragma_CPU => -1,
31532 Pragma_C_Pass_By_Copy => 0,
31533 Pragma_Comment => -1,
31534 Pragma_Common_Object => 0,
31535 Pragma_CUDA_Device => -1,
31536 Pragma_CUDA_Execute => -1,
31537 Pragma_CUDA_Global => -1,
31538 Pragma_Compile_Time_Error => -1,
31539 Pragma_Compile_Time_Warning => -1,
31540 Pragma_Complete_Representation => 0,
31541 Pragma_Complex_Representation => 0,
31542 Pragma_Component_Alignment => 0,
31543 Pragma_Constant_After_Elaboration => 0,
31544 Pragma_Contract_Cases => -1,
31545 Pragma_Controlled => 0,
31546 Pragma_Convention => 0,
31547 Pragma_Convention_Identifier => 0,
31548 Pragma_Deadline_Floor => -1,
31549 Pragma_Debug => -1,
31550 Pragma_Debug_Policy => 0,
31551 Pragma_Default_Initial_Condition => -1,
31552 Pragma_Default_Scalar_Storage_Order => 0,
31553 Pragma_Default_Storage_Pool => 0,
31554 Pragma_Depends => -1,
31555 Pragma_Detect_Blocking => 0,
31556 Pragma_Disable_Atomic_Synchronization => 0,
31557 Pragma_Discard_Names => 0,
31558 Pragma_Dispatching_Domain => -1,
31559 Pragma_Effective_Reads => 0,
31560 Pragma_Effective_Writes => 0,
31561 Pragma_Elaborate => 0,
31562 Pragma_Elaborate_All => 0,
31563 Pragma_Elaborate_Body => 0,
31564 Pragma_Elaboration_Checks => 0,
31565 Pragma_Eliminate => 0,
31566 Pragma_Enable_Atomic_Synchronization => 0,
31567 Pragma_Export => -1,
31568 Pragma_Export_Function => -1,
31569 Pragma_Export_Object => -1,
31570 Pragma_Export_Procedure => -1,
31571 Pragma_Export_Valued_Procedure => -1,
31572 Pragma_Extend_System => -1,
31573 Pragma_Extensions_Allowed => 0,
31574 Pragma_Extensions_Visible => 0,
31575 Pragma_External => -1,
31576 Pragma_External_Name_Casing => 0,
31577 Pragma_Fast_Math => 0,
31578 Pragma_Favor_Top_Level => 0,
31579 Pragma_Finalize_Storage_Only => 0,
31580 Pragma_Ghost => 0,
31581 Pragma_Global => -1,
31582 Pragma_GNAT_Annotate => 93,
31583 Pragma_Ident => -1,
31584 Pragma_Ignore_Pragma => 0,
31585 Pragma_Implementation_Defined => -1,
31586 Pragma_Implemented => -1,
31587 Pragma_Implicit_Packing => 0,
31588 Pragma_Import => 93,
31589 Pragma_Import_Function => 0,
31590 Pragma_Import_Object => 0,
31591 Pragma_Import_Procedure => 0,
31592 Pragma_Import_Valued_Procedure => 0,
31593 Pragma_Independent => 0,
31594 Pragma_Independent_Components => 0,
31595 Pragma_Initial_Condition => -1,
31596 Pragma_Initialize_Scalars => 0,
31597 Pragma_Initializes => -1,
31598 Pragma_Inline => 0,
31599 Pragma_Inline_Always => 0,
31600 Pragma_Inline_Generic => 0,
31601 Pragma_Inspection_Point => -1,
31602 Pragma_Interface => 92,
31603 Pragma_Interface_Name => 0,
31604 Pragma_Interrupt_Handler => -1,
31605 Pragma_Interrupt_Priority => -1,
31606 Pragma_Interrupt_State => -1,
31607 Pragma_Invariant => -1,
31608 Pragma_Keep_Names => 0,
31609 Pragma_License => 0,
31610 Pragma_Link_With => -1,
31611 Pragma_Linker_Alias => -1,
31612 Pragma_Linker_Constructor => -1,
31613 Pragma_Linker_Destructor => -1,
31614 Pragma_Linker_Options => -1,
31615 Pragma_Linker_Section => -1,
31616 Pragma_List => 0,
31617 Pragma_Lock_Free => 0,
31618 Pragma_Locking_Policy => 0,
31619 Pragma_Loop_Invariant => -1,
31620 Pragma_Loop_Optimize => 0,
31621 Pragma_Loop_Variant => -1,
31622 Pragma_Machine_Attribute => -1,
31623 Pragma_Main => -1,
31624 Pragma_Main_Storage => -1,
31625 Pragma_Max_Entry_Queue_Depth => 0,
31626 Pragma_Max_Entry_Queue_Length => 0,
31627 Pragma_Max_Queue_Length => 0,
31628 Pragma_Memory_Size => 0,
31629 Pragma_No_Body => 0,
31630 Pragma_No_Caching => 0,
31631 Pragma_No_Component_Reordering => -1,
31632 Pragma_No_Elaboration_Code_All => 0,
31633 Pragma_No_Heap_Finalization => 0,
31634 Pragma_No_Inline => 0,
31635 Pragma_No_Return => 0,
31636 Pragma_No_Run_Time => -1,
31637 Pragma_No_Strict_Aliasing => -1,
31638 Pragma_No_Tagged_Streams => 0,
31639 Pragma_Normalize_Scalars => 0,
31640 Pragma_Obsolescent => 0,
31641 Pragma_Optimize => 0,
31642 Pragma_Optimize_Alignment => 0,
31643 Pragma_Ordered => 0,
31644 Pragma_Overflow_Mode => 0,
31645 Pragma_Overriding_Renamings => 0,
31646 Pragma_Pack => 0,
31647 Pragma_Page => 0,
31648 Pragma_Part_Of => 0,
31649 Pragma_Partition_Elaboration_Policy => 0,
31650 Pragma_Passive => 0,
31651 Pragma_Persistent_BSS => 0,
31652 Pragma_Post => -1,
31653 Pragma_Postcondition => -1,
31654 Pragma_Post_Class => -1,
31655 Pragma_Pre => -1,
31656 Pragma_Precondition => -1,
31657 Pragma_Predicate => -1,
31658 Pragma_Predicate_Failure => -1,
31659 Pragma_Preelaborable_Initialization => -1,
31660 Pragma_Preelaborate => 0,
31661 Pragma_Prefix_Exception_Messages => 0,
31662 Pragma_Pre_Class => -1,
31663 Pragma_Priority => -1,
31664 Pragma_Priority_Specific_Dispatching => 0,
31665 Pragma_Profile => 0,
31666 Pragma_Profile_Warnings => 0,
31667 Pragma_Propagate_Exceptions => 0,
31668 Pragma_Provide_Shift_Operators => 0,
31669 Pragma_Psect_Object => 0,
31670 Pragma_Pure => 0,
31671 Pragma_Pure_Function => 0,
31672 Pragma_Queuing_Policy => 0,
31673 Pragma_Rational => 0,
31674 Pragma_Ravenscar => 0,
31675 Pragma_Refined_Depends => -1,
31676 Pragma_Refined_Global => -1,
31677 Pragma_Refined_Post => -1,
31678 Pragma_Refined_State => 0,
31679 Pragma_Relative_Deadline => 0,
31680 Pragma_Remote_Access_Type => -1,
31681 Pragma_Remote_Call_Interface => -1,
31682 Pragma_Remote_Types => -1,
31683 Pragma_Rename_Pragma => 0,
31684 Pragma_Restricted_Run_Time => 0,
31685 Pragma_Restriction_Warnings => 0,
31686 Pragma_Restrictions => 0,
31687 Pragma_Reviewable => -1,
31688 Pragma_Secondary_Stack_Size => -1,
31689 Pragma_Share_Generic => 0,
31690 Pragma_Shared => 0,
31691 Pragma_Shared_Passive => 0,
31692 Pragma_Short_Circuit_And_Or => 0,
31693 Pragma_Short_Descriptors => 0,
31694 Pragma_Simple_Storage_Pool_Type => 0,
31695 Pragma_Source_File_Name => 0,
31696 Pragma_Source_File_Name_Project => 0,
31697 Pragma_Source_Reference => 0,
31698 Pragma_SPARK_Mode => 0,
31699 Pragma_Static_Elaboration_Desired => 0,
31700 Pragma_Storage_Size => -1,
31701 Pragma_Storage_Unit => 0,
31702 Pragma_Stream_Convert => 0,
31703 Pragma_Style_Checks => 0,
31704 Pragma_Subprogram_Variant => -1,
31705 Pragma_Subtitle => 0,
31706 Pragma_Suppress => 0,
31707 Pragma_Suppress_All => 0,
31708 Pragma_Suppress_Debug_Info => 0,
31709 Pragma_Suppress_Exception_Locations => 0,
31710 Pragma_Suppress_Initialization => 0,
31711 Pragma_System_Name => 0,
31712 Pragma_Task_Dispatching_Policy => 0,
31713 Pragma_Task_Info => -1,
31714 Pragma_Task_Name => -1,
31715 Pragma_Task_Storage => -1,
31716 Pragma_Test_Case => -1,
31717 Pragma_Thread_Local_Storage => -1,
31718 Pragma_Time_Slice => -1,
31719 Pragma_Title => 0,
31720 Pragma_Type_Invariant => -1,
31721 Pragma_Type_Invariant_Class => -1,
31722 Pragma_Unchecked_Union => 0,
31723 Pragma_Unevaluated_Use_Of_Old => 0,
31724 Pragma_Unimplemented_Unit => 0,
31725 Pragma_Universal_Aliasing => 0,
31726 Pragma_Unmodified => 0,
31727 Pragma_Unreferenced => 0,
31728 Pragma_Unreferenced_Objects => 0,
31729 Pragma_Unreserve_All_Interrupts => 0,
31730 Pragma_Unsuppress => 0,
31731 Pragma_Unused => 0,
31732 Pragma_Use_VADS_Size => 0,
31733 Pragma_Validity_Checks => 0,
31734 Pragma_Volatile => 0,
31735 Pragma_Volatile_Components => 0,
31736 Pragma_Volatile_Full_Access => 0,
31737 Pragma_Volatile_Function => 0,
31738 Pragma_Warning_As_Error => 0,
31739 Pragma_Warnings => 0,
31740 Pragma_Weak_External => 0,
31741 Pragma_Wide_Character_Encoding => 0,
31742 Unknown_Pragma => 0);
31743
31744 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
31745 Id : Pragma_Id;
31746 P : Node_Id;
31747 C : Int;
31748 AN : Nat;
31749
31750 function Arg_No return Nat;
31751 -- Returns an integer showing what argument we are in. A value of
31752 -- zero means we are not in any of the arguments.
31753
31754 ------------
31755 -- Arg_No --
31756 ------------
31757
31758 function Arg_No return Nat is
31759 A : Node_Id;
31760 N : Nat;
31761
31762 begin
31763 A := First (Pragma_Argument_Associations (Parent (P)));
31764 N := 1;
31765 loop
31766 if No (A) then
31767 return 0;
31768 elsif A = P then
31769 return N;
31770 end if;
31771
31772 Next (A);
31773 N := N + 1;
31774 end loop;
31775 end Arg_No;
31776
31777 -- Start of processing for Non_Significant_Pragma_Reference
31778
31779 begin
31780 -- Reference might appear either directly as expression of a pragma
31781 -- argument association, e.g. pragma Export (...), or within an
31782 -- aggregate with component associations, e.g. pragma Refined_State
31783 -- ((... => ...)).
31784
31785 P := Parent (N);
31786 loop
31787 case Nkind (P) is
31788 when N_Pragma_Argument_Association =>
31789 exit;
31790 when N_Aggregate | N_Component_Association =>
31791 P := Parent (P);
31792 when others =>
31793 return False;
31794 end case;
31795 end loop;
31796
31797 AN := Arg_No;
31798
31799 if AN = 0 then
31800 return False;
31801 end if;
31802
31803 Id := Get_Pragma_Id (Parent (P));
31804 C := Sig_Flags (Id);
31805
31806 case C is
31807 when -1 =>
31808 return False;
31809
31810 when 0 =>
31811 return True;
31812
31813 when 92 .. 99 =>
31814 return AN < (C - 90);
31815
31816 when others =>
31817 return AN /= C;
31818 end case;
31819 end Is_Non_Significant_Pragma_Reference;
31820
31821 ------------------------------
31822 -- Is_Pragma_String_Literal --
31823 ------------------------------
31824
31825 -- This function returns true if the corresponding pragma argument is a
31826 -- static string expression. These are the only cases in which string
31827 -- literals can appear as pragma arguments. We also allow a string literal
31828 -- as the first argument to pragma Assert (although it will of course
31829 -- always generate a type error).
31830
31831 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
31832 Pragn : constant Node_Id := Parent (Par);
31833 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
31834 Pname : constant Name_Id := Pragma_Name (Pragn);
31835 Argn : Natural;
31836 N : Node_Id;
31837
31838 begin
31839 Argn := 1;
31840 N := First (Assoc);
31841 loop
31842 exit when N = Par;
31843 Argn := Argn + 1;
31844 Next (N);
31845 end loop;
31846
31847 if Pname = Name_Assert then
31848 return True;
31849
31850 elsif Pname = Name_Export then
31851 return Argn > 2;
31852
31853 elsif Pname = Name_Ident then
31854 return Argn = 1;
31855
31856 elsif Pname = Name_Import then
31857 return Argn > 2;
31858
31859 elsif Pname = Name_Interface_Name then
31860 return Argn > 1;
31861
31862 elsif Pname = Name_Linker_Alias then
31863 return Argn = 2;
31864
31865 elsif Pname = Name_Linker_Section then
31866 return Argn = 2;
31867
31868 elsif Pname = Name_Machine_Attribute then
31869 return Argn = 2;
31870
31871 elsif Pname = Name_Source_File_Name then
31872 return True;
31873
31874 elsif Pname = Name_Source_Reference then
31875 return Argn = 2;
31876
31877 elsif Pname = Name_Title then
31878 return True;
31879
31880 elsif Pname = Name_Subtitle then
31881 return True;
31882
31883 else
31884 return False;
31885 end if;
31886 end Is_Pragma_String_Literal;
31887
31888 ---------------------------
31889 -- Is_Private_SPARK_Mode --
31890 ---------------------------
31891
31892 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
31893 begin
31894 pragma Assert
31895 (Nkind (N) = N_Pragma
31896 and then Pragma_Name (N) = Name_SPARK_Mode
31897 and then Is_List_Member (N));
31898
31899 -- For pragma SPARK_Mode to be private, it has to appear in the private
31900 -- declarations of a package.
31901
31902 return
31903 Present (Parent (N))
31904 and then Nkind (Parent (N)) = N_Package_Specification
31905 and then List_Containing (N) = Private_Declarations (Parent (N));
31906 end Is_Private_SPARK_Mode;
31907
31908 -------------------------------------
31909 -- Is_Unconstrained_Or_Tagged_Item --
31910 -------------------------------------
31911
31912 function Is_Unconstrained_Or_Tagged_Item
31913 (Item : Entity_Id) return Boolean
31914 is
31915 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
31916 -- Determine whether record type Typ has at least one unconstrained
31917 -- component.
31918
31919 ---------------------------------
31920 -- Has_Unconstrained_Component --
31921 ---------------------------------
31922
31923 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
31924 Comp : Entity_Id;
31925
31926 begin
31927 Comp := First_Component (Typ);
31928 while Present (Comp) loop
31929 if Is_Unconstrained_Or_Tagged_Item (Comp) then
31930 return True;
31931 end if;
31932
31933 Next_Component (Comp);
31934 end loop;
31935
31936 return False;
31937 end Has_Unconstrained_Component;
31938
31939 -- Local variables
31940
31941 Typ : constant Entity_Id := Etype (Item);
31942
31943 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
31944
31945 begin
31946 if Is_Tagged_Type (Typ) then
31947 return True;
31948
31949 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
31950 return True;
31951
31952 elsif Is_Record_Type (Typ) then
31953 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
31954 return True;
31955 else
31956 return Has_Unconstrained_Component (Typ);
31957 end if;
31958
31959 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
31960 return True;
31961
31962 else
31963 return False;
31964 end if;
31965 end Is_Unconstrained_Or_Tagged_Item;
31966
31967 -----------------------------
31968 -- Is_Valid_Assertion_Kind --
31969 -----------------------------
31970
31971 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
31972 begin
31973 case Nam is
31974 when
31975 -- RM defined
31976
31977 Name_Assert
31978 | Name_Static_Predicate
31979 | Name_Dynamic_Predicate
31980 | Name_Pre
31981 | Name_uPre
31982 | Name_Post
31983 | Name_uPost
31984 | Name_Type_Invariant
31985 | Name_uType_Invariant
31986
31987 -- Impl defined
31988
31989 | Name_Assert_And_Cut
31990 | Name_Assume
31991 | Name_Contract_Cases
31992 | Name_Debug
31993 | Name_Default_Initial_Condition
31994 | Name_Ghost
31995 | Name_Initial_Condition
31996 | Name_Invariant
31997 | Name_uInvariant
31998 | Name_Loop_Invariant
31999 | Name_Loop_Variant
32000 | Name_Postcondition
32001 | Name_Precondition
32002 | Name_Predicate
32003 | Name_Refined_Post
32004 | Name_Statement_Assertions
32005 | Name_Subprogram_Variant
32006 =>
32007 return True;
32008
32009 when others =>
32010 return False;
32011 end case;
32012 end Is_Valid_Assertion_Kind;
32013
32014 --------------------------------------
32015 -- Process_Compilation_Unit_Pragmas --
32016 --------------------------------------
32017
32018 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
32019 begin
32020 -- A special check for pragma Suppress_All, a very strange DEC pragma,
32021 -- strange because it comes at the end of the unit. Rational has the
32022 -- same name for a pragma, but treats it as a program unit pragma, In
32023 -- GNAT we just decide to allow it anywhere at all. If it appeared then
32024 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
32025 -- node, and we insert a pragma Suppress (All_Checks) at the start of
32026 -- the context clause to ensure the correct processing.
32027
32028 if Has_Pragma_Suppress_All (N) then
32029 Prepend_To (Context_Items (N),
32030 Make_Pragma (Sloc (N),
32031 Chars => Name_Suppress,
32032 Pragma_Argument_Associations => New_List (
32033 Make_Pragma_Argument_Association (Sloc (N),
32034 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
32035 end if;
32036
32037 -- Nothing else to do at the current time
32038
32039 end Process_Compilation_Unit_Pragmas;
32040
32041 --------------------------------------------
32042 -- Validate_Compile_Time_Warning_Or_Error --
32043 --------------------------------------------
32044
32045 procedure Validate_Compile_Time_Warning_Or_Error
32046 (N : Node_Id;
32047 Eloc : Source_Ptr)
32048 is
32049 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
32050 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
32051 Arg2 : constant Node_Id := Next (Arg1);
32052
32053 Pname : constant Name_Id := Pragma_Name_Unmapped (N);
32054 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
32055
32056 begin
32057 Analyze_And_Resolve (Arg1x, Standard_Boolean);
32058
32059 if Compile_Time_Known_Value (Arg1x) then
32060 if Is_True (Expr_Value (Arg1x)) then
32061
32062 -- We have already verified that the second argument is a static
32063 -- string expression. Its string value must be retrieved
32064 -- explicitly if it is a declared constant, otherwise it has
32065 -- been constant-folded previously.
32066
32067 declare
32068 Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
32069 Str : constant String_Id :=
32070 Strval (Expr_Value_S (Get_Pragma_Arg (Arg2)));
32071 Str_Len : constant Nat := String_Length (Str);
32072
32073 Force : constant Boolean :=
32074 Prag_Id = Pragma_Compile_Time_Warning
32075 and then Is_Spec_Name (Unit_Name (Current_Sem_Unit))
32076 and then (Ekind (Cent) /= E_Package
32077 or else not In_Private_Part (Cent));
32078 -- Set True if this is the warning case, and we are in the
32079 -- visible part of a package spec, or in a subprogram spec,
32080 -- in which case we want to force the client to see the
32081 -- warning, even though it is not in the main unit.
32082
32083 C : Character;
32084 CC : Char_Code;
32085 Cont : Boolean;
32086 Ptr : Nat;
32087
32088 begin
32089 -- Loop through segments of message separated by line feeds.
32090 -- We output these segments as separate messages with
32091 -- continuation marks for all but the first.
32092
32093 Cont := False;
32094 Ptr := 1;
32095 loop
32096 Error_Msg_Strlen := 0;
32097
32098 -- Loop to copy characters from argument to error message
32099 -- string buffer.
32100
32101 loop
32102 exit when Ptr > Str_Len;
32103 CC := Get_String_Char (Str, Ptr);
32104 Ptr := Ptr + 1;
32105
32106 -- Ignore wide chars ??? else store character
32107
32108 if In_Character_Range (CC) then
32109 C := Get_Character (CC);
32110 exit when C = ASCII.LF;
32111 Error_Msg_Strlen := Error_Msg_Strlen + 1;
32112 Error_Msg_String (Error_Msg_Strlen) := C;
32113 end if;
32114 end loop;
32115
32116 -- Here with one line ready to go
32117
32118 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
32119
32120 -- If this is a warning in a spec, then we want clients
32121 -- to see the warning, so mark the message with the
32122 -- special sequence !! to force the warning. In the case
32123 -- of a package spec, we do not force this if we are in
32124 -- the private part of the spec.
32125
32126 if Force then
32127 if Cont = False then
32128 Error_Msg
32129 ("<<~!!", Eloc, Is_Compile_Time_Pragma => True);
32130 Cont := True;
32131 else
32132 Error_Msg
32133 ("\<<~!!", Eloc, Is_Compile_Time_Pragma => True);
32134 end if;
32135
32136 -- Error, rather than warning, or in a body, so we do not
32137 -- need to force visibility for client (error will be
32138 -- output in any case, and this is the situation in which
32139 -- we do not want a client to get a warning, since the
32140 -- warning is in the body or the spec private part).
32141
32142 else
32143 if Cont = False then
32144 Error_Msg
32145 ("<<~", Eloc, Is_Compile_Time_Pragma => True);
32146 Cont := True;
32147 else
32148 Error_Msg
32149 ("\<<~", Eloc, Is_Compile_Time_Pragma => True);
32150 end if;
32151 end if;
32152
32153 exit when Ptr > Str_Len;
32154 end loop;
32155 end;
32156 end if;
32157
32158 -- Arg1x is not known at compile time, so possibly issue an error
32159 -- or warning. This can happen only if the pragma's processing
32160 -- was deferred until after the back end is run (see
32161 -- Process_Compile_Time_Warning_Or_Error). Note that the warning
32162 -- control switch applies to only the warning case.
32163
32164 elsif Prag_Id = Pragma_Compile_Time_Error then
32165 Error_Msg_N ("condition is not known at compile time", Arg1x);
32166
32167 elsif Warn_On_Unknown_Compile_Time_Warning then
32168 Error_Msg_N ("?_c?condition is not known at compile time", Arg1x);
32169 end if;
32170 end Validate_Compile_Time_Warning_Or_Error;
32171
32172 ------------------------------------
32173 -- Record_Possible_Body_Reference --
32174 ------------------------------------
32175
32176 procedure Record_Possible_Body_Reference
32177 (State_Id : Entity_Id;
32178 Ref : Node_Id)
32179 is
32180 Context : Node_Id;
32181 Spec_Id : Entity_Id;
32182
32183 begin
32184 -- Ensure that we are dealing with a reference to a state
32185
32186 pragma Assert (Ekind (State_Id) = E_Abstract_State);
32187
32188 -- Climb the tree starting from the reference looking for a package body
32189 -- whose spec declares the referenced state. This criteria automatically
32190 -- excludes references in package specs which are legal. Note that it is
32191 -- not wise to emit an error now as the package body may lack pragma
32192 -- Refined_State or the referenced state may not be mentioned in the
32193 -- refinement. This approach avoids the generation of misleading errors.
32194
32195 Context := Ref;
32196 while Present (Context) loop
32197 if Nkind (Context) = N_Package_Body then
32198 Spec_Id := Corresponding_Spec (Context);
32199
32200 if Present (Abstract_States (Spec_Id))
32201 and then Contains (Abstract_States (Spec_Id), State_Id)
32202 then
32203 if No (Body_References (State_Id)) then
32204 Set_Body_References (State_Id, New_Elmt_List);
32205 end if;
32206
32207 Append_Elmt (Ref, To => Body_References (State_Id));
32208 exit;
32209 end if;
32210 end if;
32211
32212 Context := Parent (Context);
32213 end loop;
32214 end Record_Possible_Body_Reference;
32215
32216 ------------------------------------------
32217 -- Relocate_Pragmas_To_Anonymous_Object --
32218 ------------------------------------------
32219
32220 procedure Relocate_Pragmas_To_Anonymous_Object
32221 (Typ_Decl : Node_Id;
32222 Obj_Decl : Node_Id)
32223 is
32224 Decl : Node_Id;
32225 Def : Node_Id;
32226 Next_Decl : Node_Id;
32227
32228 begin
32229 if Nkind (Typ_Decl) = N_Protected_Type_Declaration then
32230 Def := Protected_Definition (Typ_Decl);
32231 else
32232 pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration);
32233 Def := Task_Definition (Typ_Decl);
32234 end if;
32235
32236 -- The concurrent definition has a visible declaration list. Inspect it
32237 -- and relocate all canidate pragmas.
32238
32239 if Present (Def) and then Present (Visible_Declarations (Def)) then
32240 Decl := First (Visible_Declarations (Def));
32241 while Present (Decl) loop
32242
32243 -- Preserve the following declaration for iteration purposes due
32244 -- to possible relocation of a pragma.
32245
32246 Next_Decl := Next (Decl);
32247
32248 if Nkind (Decl) = N_Pragma
32249 and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl))
32250 then
32251 Remove (Decl);
32252 Insert_After (Obj_Decl, Decl);
32253
32254 -- Skip internally generated code
32255
32256 elsif not Comes_From_Source (Decl) then
32257 null;
32258
32259 -- No candidate pragmas are available for relocation
32260
32261 else
32262 exit;
32263 end if;
32264
32265 Decl := Next_Decl;
32266 end loop;
32267 end if;
32268 end Relocate_Pragmas_To_Anonymous_Object;
32269
32270 ------------------------------
32271 -- Relocate_Pragmas_To_Body --
32272 ------------------------------
32273
32274 procedure Relocate_Pragmas_To_Body
32275 (Subp_Body : Node_Id;
32276 Target_Body : Node_Id := Empty)
32277 is
32278 procedure Relocate_Pragma (Prag : Node_Id);
32279 -- Remove a single pragma from its current list and add it to the
32280 -- declarations of the proper body (either Subp_Body or Target_Body).
32281
32282 ---------------------
32283 -- Relocate_Pragma --
32284 ---------------------
32285
32286 procedure Relocate_Pragma (Prag : Node_Id) is
32287 Decls : List_Id;
32288 Target : Node_Id;
32289
32290 begin
32291 -- When subprogram stubs or expression functions are involves, the
32292 -- destination declaration list belongs to the proper body.
32293
32294 if Present (Target_Body) then
32295 Target := Target_Body;
32296 else
32297 Target := Subp_Body;
32298 end if;
32299
32300 Decls := Declarations (Target);
32301
32302 if No (Decls) then
32303 Decls := New_List;
32304 Set_Declarations (Target, Decls);
32305 end if;
32306
32307 -- Unhook the pragma from its current list
32308
32309 Remove (Prag);
32310 Prepend (Prag, Decls);
32311 end Relocate_Pragma;
32312
32313 -- Local variables
32314
32315 Body_Id : constant Entity_Id :=
32316 Defining_Unit_Name (Specification (Subp_Body));
32317 Next_Stmt : Node_Id;
32318 Stmt : Node_Id;
32319
32320 -- Start of processing for Relocate_Pragmas_To_Body
32321
32322 begin
32323 -- Do not process a body that comes from a separate unit as no construct
32324 -- can possibly follow it.
32325
32326 if not Is_List_Member (Subp_Body) then
32327 return;
32328
32329 -- Do not relocate pragmas that follow a stub if the stub does not have
32330 -- a proper body.
32331
32332 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
32333 and then No (Target_Body)
32334 then
32335 return;
32336
32337 -- Do not process internally generated routine _Wrapped_Statements
32338
32339 elsif Ekind (Body_Id) = E_Procedure
32340 and then Chars (Body_Id) = Name_uWrapped_Statements
32341 then
32342 return;
32343 end if;
32344
32345 -- Look at what is following the body. We are interested in certain kind
32346 -- of pragmas (either from source or byproducts of expansion) that can
32347 -- apply to a body [stub].
32348
32349 Stmt := Next (Subp_Body);
32350 while Present (Stmt) loop
32351
32352 -- Preserve the following statement for iteration purposes due to a
32353 -- possible relocation of a pragma.
32354
32355 Next_Stmt := Next (Stmt);
32356
32357 -- Move a candidate pragma following the body to the declarations of
32358 -- the body.
32359
32360 if Nkind (Stmt) = N_Pragma
32361 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
32362 then
32363
32364 -- If a source pragma Warnings follows the body, it applies to
32365 -- following statements and does not belong in the body.
32366
32367 if Get_Pragma_Id (Stmt) = Pragma_Warnings
32368 and then Comes_From_Source (Stmt)
32369 then
32370 null;
32371 else
32372 Relocate_Pragma (Stmt);
32373 end if;
32374
32375 -- Skip internally generated code
32376
32377 elsif not Comes_From_Source (Stmt) then
32378 null;
32379
32380 -- No candidate pragmas are available for relocation
32381
32382 else
32383 exit;
32384 end if;
32385
32386 Stmt := Next_Stmt;
32387 end loop;
32388 end Relocate_Pragmas_To_Body;
32389
32390 -------------------
32391 -- Resolve_State --
32392 -------------------
32393
32394 procedure Resolve_State (N : Node_Id) is
32395 Func : Entity_Id;
32396 State : Entity_Id;
32397
32398 begin
32399 if Is_Entity_Name (N) and then Present (Entity (N)) then
32400 Func := Entity (N);
32401
32402 -- Handle overloading of state names by functions. Traverse the
32403 -- homonym chain looking for an abstract state.
32404
32405 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
32406 pragma Assert (Is_Overloaded (N));
32407
32408 State := Homonym (Func);
32409 while Present (State) loop
32410 if Ekind (State) = E_Abstract_State then
32411
32412 -- Resolve the overloading by setting the proper entity of
32413 -- the reference to that of the state.
32414
32415 Set_Etype (N, Standard_Void_Type);
32416 Set_Entity (N, State);
32417 Set_Is_Overloaded (N, False);
32418
32419 Generate_Reference (State, N);
32420 return;
32421 end if;
32422
32423 State := Homonym (State);
32424 end loop;
32425
32426 -- A function can never act as a state. If the homonym chain does
32427 -- not contain a corresponding state, then something went wrong in
32428 -- the overloading mechanism.
32429
32430 raise Program_Error;
32431 end if;
32432 end if;
32433 end Resolve_State;
32434
32435 ----------------------------
32436 -- Rewrite_Assertion_Kind --
32437 ----------------------------
32438
32439 procedure Rewrite_Assertion_Kind
32440 (N : Node_Id;
32441 From_Policy : Boolean := False)
32442 is
32443 Nam : Name_Id;
32444
32445 begin
32446 Nam := No_Name;
32447 if Nkind (N) = N_Attribute_Reference
32448 and then Attribute_Name (N) = Name_Class
32449 and then Nkind (Prefix (N)) = N_Identifier
32450 then
32451 case Chars (Prefix (N)) is
32452 when Name_Pre =>
32453 Nam := Name_uPre;
32454
32455 when Name_Post =>
32456 Nam := Name_uPost;
32457
32458 when Name_Type_Invariant =>
32459 Nam := Name_uType_Invariant;
32460
32461 when Name_Invariant =>
32462 Nam := Name_uInvariant;
32463
32464 when others =>
32465 return;
32466 end case;
32467
32468 -- Recommend standard use of aspect names Pre/Post
32469
32470 elsif Nkind (N) = N_Identifier
32471 and then From_Policy
32472 and then Serious_Errors_Detected = 0
32473 then
32474 if Chars (N) = Name_Precondition
32475 or else Chars (N) = Name_Postcondition
32476 then
32477 Error_Msg_N ("Check_Policy is a non-standard pragma??", N);
32478 Error_Msg_N
32479 ("\use Assertion_Policy and aspect names Pre/Post for "
32480 & "Ada2012 conformance?", N);
32481 end if;
32482
32483 return;
32484 end if;
32485
32486 if Nam /= No_Name then
32487 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
32488 end if;
32489 end Rewrite_Assertion_Kind;
32490
32491 --------
32492 -- rv --
32493 --------
32494
32495 procedure rv is
32496 begin
32497 Dummy := Dummy + 1;
32498 end rv;
32499
32500 --------------------------------
32501 -- Set_Encoded_Interface_Name --
32502 --------------------------------
32503
32504 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
32505 Str : constant String_Id := Strval (S);
32506 Len : constant Nat := String_Length (Str);
32507 CC : Char_Code;
32508 C : Character;
32509 J : Pos;
32510
32511 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
32512
32513 procedure Encode;
32514 -- Stores encoded value of character code CC. The encoding we use an
32515 -- underscore followed by four lower case hex digits.
32516
32517 ------------
32518 -- Encode --
32519 ------------
32520
32521 procedure Encode is
32522 begin
32523 Store_String_Char (Get_Char_Code ('_'));
32524 Store_String_Char
32525 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
32526 Store_String_Char
32527 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
32528 Store_String_Char
32529 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
32530 Store_String_Char
32531 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
32532 end Encode;
32533
32534 -- Start of processing for Set_Encoded_Interface_Name
32535
32536 begin
32537 -- If first character is asterisk, this is a link name, and we leave it
32538 -- completely unmodified. We also ignore null strings (the latter case
32539 -- happens only in error cases).
32540
32541 if Len = 0
32542 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
32543 then
32544 Set_Interface_Name (E, S);
32545
32546 else
32547 J := 1;
32548 loop
32549 CC := Get_String_Char (Str, J);
32550
32551 exit when not In_Character_Range (CC);
32552
32553 C := Get_Character (CC);
32554
32555 exit when C /= '_' and then C /= '$'
32556 and then C not in '0' .. '9'
32557 and then C not in 'a' .. 'z'
32558 and then C not in 'A' .. 'Z';
32559
32560 if J = Len then
32561 Set_Interface_Name (E, S);
32562 return;
32563
32564 else
32565 J := J + 1;
32566 end if;
32567 end loop;
32568
32569 -- Here we need to encode. The encoding we use as follows:
32570 -- three underscores + four hex digits (lower case)
32571
32572 Start_String;
32573
32574 for J in 1 .. String_Length (Str) loop
32575 CC := Get_String_Char (Str, J);
32576
32577 if not In_Character_Range (CC) then
32578 Encode;
32579 else
32580 C := Get_Character (CC);
32581
32582 if C = '_' or else C = '$'
32583 or else C in '0' .. '9'
32584 or else C in 'a' .. 'z'
32585 or else C in 'A' .. 'Z'
32586 then
32587 Store_String_Char (CC);
32588 else
32589 Encode;
32590 end if;
32591 end if;
32592 end loop;
32593
32594 Set_Interface_Name (E,
32595 Make_String_Literal (Sloc (S),
32596 Strval => End_String));
32597 end if;
32598 end Set_Encoded_Interface_Name;
32599
32600 ------------------------
32601 -- Set_Elab_Unit_Name --
32602 ------------------------
32603
32604 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
32605 Pref : Node_Id;
32606 Scop : Entity_Id;
32607
32608 begin
32609 if Nkind (N) = N_Identifier
32610 and then Nkind (With_Item) = N_Identifier
32611 then
32612 Set_Entity (N, Entity (With_Item));
32613
32614 elsif Nkind (N) = N_Selected_Component then
32615 Change_Selected_Component_To_Expanded_Name (N);
32616 Set_Entity (N, Entity (With_Item));
32617 Set_Entity (Selector_Name (N), Entity (N));
32618
32619 Pref := Prefix (N);
32620 Scop := Scope (Entity (N));
32621 while Nkind (Pref) = N_Selected_Component loop
32622 Change_Selected_Component_To_Expanded_Name (Pref);
32623 Set_Entity (Selector_Name (Pref), Scop);
32624 Set_Entity (Pref, Scop);
32625 Pref := Prefix (Pref);
32626 Scop := Scope (Scop);
32627 end loop;
32628
32629 Set_Entity (Pref, Scop);
32630 end if;
32631
32632 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
32633 end Set_Elab_Unit_Name;
32634
32635 -----------------------
32636 -- Set_Overflow_Mode --
32637 -----------------------
32638
32639 procedure Set_Overflow_Mode (N : Node_Id) is
32640
32641 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type;
32642 -- Function to process one pragma argument, Arg
32643
32644 -----------------------
32645 -- Get_Overflow_Mode --
32646 -----------------------
32647
32648 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type is
32649 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
32650
32651 begin
32652 if Chars (Argx) = Name_Strict then
32653 return Strict;
32654
32655 elsif Chars (Argx) = Name_Minimized then
32656 return Minimized;
32657
32658 elsif Chars (Argx) = Name_Eliminated then
32659 return Eliminated;
32660
32661 else
32662 raise Program_Error;
32663 end if;
32664 end Get_Overflow_Mode;
32665
32666 -- Local variables
32667
32668 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
32669 Arg2 : constant Node_Id := Next (Arg1);
32670
32671 -- Start of processing for Set_Overflow_Mode
32672
32673 begin
32674 -- Process first argument
32675
32676 Scope_Suppress.Overflow_Mode_General :=
32677 Get_Overflow_Mode (Arg1);
32678
32679 -- Case of only one argument
32680
32681 if No (Arg2) then
32682 Scope_Suppress.Overflow_Mode_Assertions :=
32683 Scope_Suppress.Overflow_Mode_General;
32684
32685 -- Case of two arguments present
32686
32687 else
32688 Scope_Suppress.Overflow_Mode_Assertions :=
32689 Get_Overflow_Mode (Arg2);
32690 end if;
32691 end Set_Overflow_Mode;
32692
32693 -------------------
32694 -- Test_Case_Arg --
32695 -------------------
32696
32697 function Test_Case_Arg
32698 (Prag : Node_Id;
32699 Arg_Nam : Name_Id;
32700 From_Aspect : Boolean := False) return Node_Id
32701 is
32702 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
32703 Arg : Node_Id;
32704 Args : Node_Id;
32705
32706 begin
32707 pragma Assert
32708 (Arg_Nam in Name_Ensures | Name_Mode | Name_Name | Name_Requires);
32709
32710 -- The caller requests the aspect argument
32711
32712 if From_Aspect then
32713 if Present (Aspect)
32714 and then Nkind (Expression (Aspect)) = N_Aggregate
32715 then
32716 Args := Expression (Aspect);
32717
32718 -- "Name" and "Mode" may appear without an identifier as a
32719 -- positional association.
32720
32721 if Present (Expressions (Args)) then
32722 Arg := First (Expressions (Args));
32723
32724 if Present (Arg) and then Arg_Nam = Name_Name then
32725 return Arg;
32726 end if;
32727
32728 -- Skip "Name"
32729
32730 Arg := Next (Arg);
32731
32732 if Present (Arg) and then Arg_Nam = Name_Mode then
32733 return Arg;
32734 end if;
32735 end if;
32736
32737 -- Some or all arguments may appear as component associatons
32738
32739 if Present (Component_Associations (Args)) then
32740 Arg := First (Component_Associations (Args));
32741 while Present (Arg) loop
32742 if Chars (First (Choices (Arg))) = Arg_Nam then
32743 return Arg;
32744 end if;
32745
32746 Next (Arg);
32747 end loop;
32748 end if;
32749 end if;
32750
32751 -- Otherwise retrieve the argument directly from the pragma
32752
32753 else
32754 Arg := First (Pragma_Argument_Associations (Prag));
32755
32756 if Present (Arg) and then Arg_Nam = Name_Name then
32757 return Arg;
32758 end if;
32759
32760 -- Skip argument "Name"
32761
32762 Arg := Next (Arg);
32763
32764 if Present (Arg) and then Arg_Nam = Name_Mode then
32765 return Arg;
32766 end if;
32767
32768 -- Skip argument "Mode"
32769
32770 Arg := Next (Arg);
32771
32772 -- Arguments "Requires" and "Ensures" are optional and may not be
32773 -- present at all.
32774
32775 while Present (Arg) loop
32776 if Chars (Arg) = Arg_Nam then
32777 return Arg;
32778 end if;
32779
32780 Next (Arg);
32781 end loop;
32782 end if;
32783
32784 return Empty;
32785 end Test_Case_Arg;
32786
32787 --------------------------------------------
32788 -- Defer_Compile_Time_Warning_Error_To_BE --
32789 --------------------------------------------
32790
32791 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id) is
32792 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
32793 begin
32794 Compile_Time_Warnings_Errors.Append
32795 (New_Val => CTWE_Entry'(Eloc => Sloc (Arg1),
32796 Scope => Current_Scope,
32797 Prag => N));
32798
32799 -- If the Boolean expression contains T'Size, and we're not in the main
32800 -- unit being compiled, then we need to copy the pragma into the main
32801 -- unit, because otherwise T'Size might never be computed, leaving it
32802 -- as 0.
32803
32804 if not In_Extended_Main_Code_Unit (N) then
32805 Insert_Library_Level_Action (New_Copy_Tree (N));
32806 end if;
32807 end Defer_Compile_Time_Warning_Error_To_BE;
32808
32809 ------------------------------------------
32810 -- Validate_Compile_Time_Warning_Errors --
32811 ------------------------------------------
32812
32813 procedure Validate_Compile_Time_Warning_Errors is
32814 procedure Set_Scope (S : Entity_Id);
32815 -- Install all enclosing scopes of S along with S itself
32816
32817 procedure Unset_Scope (S : Entity_Id);
32818 -- Uninstall all enclosing scopes of S along with S itself
32819
32820 ---------------
32821 -- Set_Scope --
32822 ---------------
32823
32824 procedure Set_Scope (S : Entity_Id) is
32825 begin
32826 if S /= Standard_Standard then
32827 Set_Scope (Scope (S));
32828 end if;
32829
32830 Push_Scope (S);
32831 end Set_Scope;
32832
32833 -----------------
32834 -- Unset_Scope --
32835 -----------------
32836
32837 procedure Unset_Scope (S : Entity_Id) is
32838 begin
32839 if S /= Standard_Standard then
32840 Unset_Scope (Scope (S));
32841 end if;
32842
32843 Pop_Scope;
32844 end Unset_Scope;
32845
32846 -- Start of processing for Validate_Compile_Time_Warning_Errors
32847
32848 begin
32849 Expander_Mode_Save_And_Set (False);
32850 In_Compile_Time_Warning_Or_Error := True;
32851
32852 for N in Compile_Time_Warnings_Errors.First ..
32853 Compile_Time_Warnings_Errors.Last
32854 loop
32855 declare
32856 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
32857
32858 begin
32859 Set_Scope (T.Scope);
32860 Reset_Analyzed_Flags (T.Prag);
32861 Validate_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
32862 Unset_Scope (T.Scope);
32863 end;
32864 end loop;
32865
32866 In_Compile_Time_Warning_Or_Error := False;
32867 Expander_Mode_Restore;
32868 end Validate_Compile_Time_Warning_Errors;
32869
32870 end Sem_Prag;
This page took 1.421739 seconds and 5 git commands to generate.