[Ada] Expanded names in ghost assignments
[gcc.git] / gcc / ada / sem_prag.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ P R A G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
31
32 with Aspects; use Aspects;
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Checks; use Checks;
36 with Contracts; use Contracts;
37 with Csets; use Csets;
38 with Debug; use Debug;
39 with Einfo; use Einfo;
40 with Elists; use Elists;
41 with Errout; use Errout;
42 with Exp_Dist; use Exp_Dist;
43 with Exp_Util; use Exp_Util;
44 with Expander; use Expander;
45 with Freeze; use Freeze;
46 with Ghost; use Ghost;
47 with Gnatvsn; use Gnatvsn;
48 with Lib; use Lib;
49 with Lib.Writ; use Lib.Writ;
50 with Lib.Xref; use Lib.Xref;
51 with Namet.Sp; use Namet.Sp;
52 with Nlists; use Nlists;
53 with Nmake; use Nmake;
54 with Output; use Output;
55 with Par_SCO; use Par_SCO;
56 with Restrict; use Restrict;
57 with Rident; use Rident;
58 with Rtsfind; use Rtsfind;
59 with Sem; use Sem;
60 with Sem_Aux; use Sem_Aux;
61 with Sem_Ch3; use Sem_Ch3;
62 with Sem_Ch6; use Sem_Ch6;
63 with Sem_Ch8; use Sem_Ch8;
64 with Sem_Ch12; use Sem_Ch12;
65 with Sem_Ch13; use Sem_Ch13;
66 with Sem_Disp; use Sem_Disp;
67 with Sem_Dist; use Sem_Dist;
68 with Sem_Elab; use Sem_Elab;
69 with Sem_Elim; use Sem_Elim;
70 with Sem_Eval; use Sem_Eval;
71 with Sem_Intr; use Sem_Intr;
72 with Sem_Mech; use Sem_Mech;
73 with Sem_Res; use Sem_Res;
74 with Sem_Type; use Sem_Type;
75 with Sem_Util; use Sem_Util;
76 with Sem_Warn; use Sem_Warn;
77 with Stand; use Stand;
78 with Sinfo; use Sinfo;
79 with Sinfo.CN; use Sinfo.CN;
80 with Sinput; use Sinput;
81 with Stringt; use Stringt;
82 with Stylesw; use Stylesw;
83 with Table;
84 with Targparm; use Targparm;
85 with Tbuild; use Tbuild;
86 with Ttypes;
87 with Uintp; use Uintp;
88 with Uname; use Uname;
89 with Urealp; use Urealp;
90 with Validsw; use Validsw;
91 with Warnsw; use Warnsw;
92
93 with System.Case_Util;
94
95 package body Sem_Prag is
96
97 ----------------------------------------------
98 -- Common Handling of Import-Export Pragmas --
99 ----------------------------------------------
100
101 -- In the following section, a number of Import_xxx and Export_xxx pragmas
102 -- are defined by GNAT. These are compatible with the DEC pragmas of the
103 -- same name, and all have the following common form and processing:
104
105 -- pragma Export_xxx
106 -- [Internal =>] LOCAL_NAME
107 -- [, [External =>] EXTERNAL_SYMBOL]
108 -- [, other optional parameters ]);
109
110 -- pragma Import_xxx
111 -- [Internal =>] LOCAL_NAME
112 -- [, [External =>] EXTERNAL_SYMBOL]
113 -- [, other optional parameters ]);
114
115 -- EXTERNAL_SYMBOL ::=
116 -- IDENTIFIER
117 -- | static_string_EXPRESSION
118
119 -- The internal LOCAL_NAME designates the entity that is imported or
120 -- exported, and must refer to an entity in the current declarative
121 -- part (as required by the rules for LOCAL_NAME).
122
123 -- The external linker name is designated by the External parameter if
124 -- given, or the Internal parameter if not (if there is no External
125 -- parameter, the External parameter is a copy of the Internal name).
126
127 -- If the External parameter is given as a string, then this string is
128 -- treated as an external name (exactly as though it had been given as an
129 -- External_Name parameter for a normal Import pragma).
130
131 -- If the External parameter is given as an identifier (or there is no
132 -- External parameter, so that the Internal identifier is used), then
133 -- the external name is the characters of the identifier, translated
134 -- to all lower case letters.
135
136 -- Note: the external name specified or implied by any of these special
137 -- Import_xxx or Export_xxx pragmas override an external or link name
138 -- specified in a previous Import or Export pragma.
139
140 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
141 -- named notation, following the standard rules for subprogram calls, i.e.
142 -- parameters can be given in any order if named notation is used, and
143 -- positional and named notation can be mixed, subject to the rule that all
144 -- positional parameters must appear first.
145
146 -- Note: All these pragmas are implemented exactly following the DEC design
147 -- and implementation and are intended to be fully compatible with the use
148 -- of these pragmas in the DEC Ada compiler.
149
150 --------------------------------------------
151 -- Checking for Duplicated External Names --
152 --------------------------------------------
153
154 -- It is suspicious if two separate Export pragmas use the same external
155 -- name. The following table is used to diagnose this situation so that
156 -- an appropriate warning can be issued.
157
158 -- The Node_Id stored is for the N_String_Literal node created to hold
159 -- the value of the external name. The Sloc of this node is used to
160 -- cross-reference the location of the duplication.
161
162 package Externals is new Table.Table (
163 Table_Component_Type => Node_Id,
164 Table_Index_Type => Int,
165 Table_Low_Bound => 0,
166 Table_Initial => 100,
167 Table_Increment => 100,
168 Table_Name => "Name_Externals");
169
170 -------------------------------------
171 -- Local Subprograms and Variables --
172 -------------------------------------
173
174 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
175 -- This routine is used for possible casing adjustment of an explicit
176 -- external name supplied as a string literal (the node N), according to
177 -- the casing requirement of Opt.External_Name_Casing. If this is set to
178 -- As_Is, then the string literal is returned unchanged, but if it is set
179 -- to Uppercase or Lowercase, then a new string literal with appropriate
180 -- casing is constructed.
181
182 procedure Analyze_Part_Of
183 (Indic : Node_Id;
184 Item_Id : Entity_Id;
185 Encap : Node_Id;
186 Encap_Id : out Entity_Id;
187 Legal : out Boolean);
188 -- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and
189 -- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the
190 -- Part_Of indicator. Item_Id is the entity of an abstract state, object or
191 -- package instantiation. Encap denotes the encapsulating state or single
192 -- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when
193 -- the indicator is legal.
194
195 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
196 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
197 -- Query whether a particular item appears in a mixed list of nodes and
198 -- entities. It is assumed that all nodes in the list have entities.
199
200 procedure Check_Postcondition_Use_In_Inlined_Subprogram
201 (Prag : Node_Id;
202 Spec_Id : Entity_Id);
203 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
204 -- Precondition, Refined_Post, and Test_Case. Emit a warning when pragma
205 -- Prag is associated with subprogram Spec_Id subject to Inline_Always,
206 -- and assertions are enabled.
207
208 procedure Check_State_And_Constituent_Use
209 (States : Elist_Id;
210 Constits : Elist_Id;
211 Context : Node_Id);
212 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
213 -- Global and Initializes. Determine whether a state from list States and a
214 -- corresponding constituent from list Constits (if any) appear in the same
215 -- context denoted by Context. If this is the case, emit an error.
216
217 procedure Contract_Freeze_Error
218 (Contract_Id : Entity_Id;
219 Freeze_Id : Entity_Id);
220 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and
221 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity
222 -- of a body which caused contract freezing and Contract_Id denotes the
223 -- entity of the affected contstruct.
224
225 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id);
226 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma
227 -- Prag that duplicates previous pragma Prev.
228
229 function Find_Encapsulating_State
230 (States : Elist_Id;
231 Constit_Id : Entity_Id) return Entity_Id;
232 -- Given the entity of a constituent Constit_Id, find the corresponding
233 -- encapsulating state which appears in States. The routine returns Empty
234 -- if no such state is found.
235
236 function Find_Related_Context
237 (Prag : Node_Id;
238 Do_Checks : Boolean := False) return Node_Id;
239 -- Subsidiary to the analysis of pragmas
240 -- Async_Readers
241 -- Async_Writers
242 -- Constant_After_Elaboration
243 -- Effective_Reads
244 -- Effective_Writers
245 -- Part_Of
246 -- Find the first source declaration or statement found while traversing
247 -- the previous node chain starting from pragma Prag. If flag Do_Checks is
248 -- set, the routine reports duplicate pragmas. The routine returns Empty
249 -- when reaching the start of the node chain.
250
251 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
252 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
253 -- original one, following the renaming chain) is returned. Otherwise the
254 -- entity is returned unchanged. Should be in Einfo???
255
256 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
257 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
258 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
259 -- value of type SPARK_Mode_Type.
260
261 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
262 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
263 -- Determine whether dependency clause Clause is surrounded by extra
264 -- parentheses. If this is the case, issue an error message.
265
266 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
267 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
268 -- pragma Depends. Determine whether the type of dependency item Item is
269 -- tagged, unconstrained array, unconstrained record or a record with at
270 -- least one unconstrained component.
271
272 procedure Record_Possible_Body_Reference
273 (State_Id : Entity_Id;
274 Ref : Node_Id);
275 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
276 -- Global. Given an abstract state denoted by State_Id and a reference Ref
277 -- to it, determine whether the reference appears in a package body that
278 -- will eventually refine the state. If this is the case, record the
279 -- reference for future checks (see Analyze_Refined_State_In_Decls).
280
281 procedure Resolve_State (N : Node_Id);
282 -- Handle the overloading of state names by functions. When N denotes a
283 -- function, this routine finds the corresponding state and sets the entity
284 -- of N to that of the state.
285
286 procedure Rewrite_Assertion_Kind
287 (N : Node_Id;
288 From_Policy : Boolean := False);
289 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
290 -- then it is rewritten as an identifier with the corresponding special
291 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
292 -- and Check_Policy. If the names are Precondition or Postcondition, this
293 -- combination is deprecated in favor of Assertion_Policy and Ada2012
294 -- Aspect names. The parameter From_Policy indicates that the pragma
295 -- is the old non-standard Check_Policy and not a rewritten pragma.
296
297 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
298 -- Place semantic information on the argument of an Elaborate/Elaborate_All
299 -- pragma. Entity name for unit and its parents is taken from item in
300 -- previous with_clause that mentions the unit.
301
302 procedure Validate_Compile_Time_Warning_Or_Error
303 (N : Node_Id;
304 Eloc : Source_Ptr);
305 -- Common processing for Compile_Time_Error and Compile_Time_Warning of
306 -- pragma N. Called when the pragma is processed as part of its regular
307 -- analysis but also called after calling the back end to validate these
308 -- pragmas for size and alignment appropriateness.
309
310 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id);
311 -- N is a pragma Compile_Time_Error or Compile_Warning_Error whose boolean
312 -- expression is not known at compile time during the front end. This
313 -- procedure makes an entry in a table. The actual checking is performed by
314 -- Validate_Compile_Time_Warning_Errors, which is invoked after calling the
315 -- back end.
316
317 Dummy : Integer := 0;
318 pragma Volatile (Dummy);
319 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
320
321 procedure ip;
322 pragma No_Inline (ip);
323 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
324 -- is just to help debugging the front end. If a pragma Inspection_Point
325 -- is added to a source program, then breaking on ip will get you to that
326 -- point in the program.
327
328 procedure rv;
329 pragma No_Inline (rv);
330 -- This is a dummy function called by the processing for pragma Reviewable.
331 -- It is there for assisting front end debugging. By placing a Reviewable
332 -- pragma in the source program, a breakpoint on rv catches this place in
333 -- the source, allowing convenient stepping to the point of interest.
334
335 ------------------------------------------------------
336 -- Table for Defer_Compile_Time_Warning_Error_To_BE --
337 ------------------------------------------------------
338
339 -- The following table collects pragmas Compile_Time_Error and Compile_
340 -- Time_Warning for validation. Entries are made by calls to subprogram
341 -- Defer_Compile_Time_Warning_Error_To_BE, and the call to the procedure
342 -- Validate_Compile_Time_Warning_Errors does the actual error checking
343 -- and posting of warning and error messages. The reason for this delayed
344 -- processing is to take advantage of back-annotations of attributes size
345 -- and alignment values performed by the back end.
346
347 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
348 -- that by the time Validate_Compile_Time_Warning_Errors is called, Sprint
349 -- will already have modified all Sloc values if the -gnatD option is set.
350
351 type CTWE_Entry is record
352 Eloc : Source_Ptr;
353 -- Source location used in warnings and error messages
354
355 Prag : Node_Id;
356 -- Pragma Compile_Time_Error or Compile_Time_Warning
357
358 Scope : Node_Id;
359 -- The scope which encloses the pragma
360 end record;
361
362 package Compile_Time_Warnings_Errors is new Table.Table (
363 Table_Component_Type => CTWE_Entry,
364 Table_Index_Type => Int,
365 Table_Low_Bound => 1,
366 Table_Initial => 50,
367 Table_Increment => 200,
368 Table_Name => "Compile_Time_Warnings_Errors");
369
370 -------------------------------
371 -- Adjust_External_Name_Case --
372 -------------------------------
373
374 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
375 CC : Char_Code;
376
377 begin
378 -- Adjust case of literal if required
379
380 if Opt.External_Name_Exp_Casing = As_Is then
381 return N;
382
383 else
384 -- Copy existing string
385
386 Start_String;
387
388 -- Set proper casing
389
390 for J in 1 .. String_Length (Strval (N)) loop
391 CC := Get_String_Char (Strval (N), J);
392
393 if Opt.External_Name_Exp_Casing = Uppercase
394 and then CC >= Get_Char_Code ('a')
395 and then CC <= Get_Char_Code ('z')
396 then
397 Store_String_Char (CC - 32);
398
399 elsif Opt.External_Name_Exp_Casing = Lowercase
400 and then CC >= Get_Char_Code ('A')
401 and then CC <= Get_Char_Code ('Z')
402 then
403 Store_String_Char (CC + 32);
404
405 else
406 Store_String_Char (CC);
407 end if;
408 end loop;
409
410 return
411 Make_String_Literal (Sloc (N),
412 Strval => End_String);
413 end if;
414 end Adjust_External_Name_Case;
415
416 -----------------------------------------
417 -- Analyze_Contract_Cases_In_Decl_Part --
418 -----------------------------------------
419
420 -- WARNING: This routine manages Ghost regions. Return statements must be
421 -- replaced by gotos which jump to the end of the routine and restore the
422 -- Ghost mode.
423
424 procedure Analyze_Contract_Cases_In_Decl_Part
425 (N : Node_Id;
426 Freeze_Id : Entity_Id := Empty)
427 is
428 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
429 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
430
431 Others_Seen : Boolean := False;
432 -- This flag is set when an "others" choice is encountered. It is used
433 -- to detect multiple illegal occurrences of "others".
434
435 procedure Analyze_Contract_Case (CCase : Node_Id);
436 -- Verify the legality of a single contract case
437
438 ---------------------------
439 -- Analyze_Contract_Case --
440 ---------------------------
441
442 procedure Analyze_Contract_Case (CCase : Node_Id) is
443 Case_Guard : Node_Id;
444 Conseq : Node_Id;
445 Errors : Nat;
446 Extra_Guard : Node_Id;
447
448 begin
449 if Nkind (CCase) = N_Component_Association then
450 Case_Guard := First (Choices (CCase));
451 Conseq := Expression (CCase);
452
453 -- Each contract case must have exactly one case guard
454
455 Extra_Guard := Next (Case_Guard);
456
457 if Present (Extra_Guard) then
458 Error_Msg_N
459 ("contract case must have exactly one case guard",
460 Extra_Guard);
461 end if;
462
463 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
464
465 if Nkind (Case_Guard) = N_Others_Choice then
466 if Others_Seen then
467 Error_Msg_N
468 ("only one others choice allowed in contract cases",
469 Case_Guard);
470 else
471 Others_Seen := True;
472 end if;
473
474 elsif Others_Seen then
475 Error_Msg_N
476 ("others must be the last choice in contract cases", N);
477 end if;
478
479 -- Preanalyze the case guard and consequence
480
481 if Nkind (Case_Guard) /= N_Others_Choice then
482 Errors := Serious_Errors_Detected;
483 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
484
485 -- Emit a clarification message when the case guard contains
486 -- at least one undefined reference, possibly due to contract
487 -- freezing.
488
489 if Errors /= Serious_Errors_Detected
490 and then Present (Freeze_Id)
491 and then Has_Undefined_Reference (Case_Guard)
492 then
493 Contract_Freeze_Error (Spec_Id, Freeze_Id);
494 end if;
495 end if;
496
497 Errors := Serious_Errors_Detected;
498 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
499
500 -- Emit a clarification message when the consequence contains
501 -- at least one undefined reference, possibly due to contract
502 -- freezing.
503
504 if Errors /= Serious_Errors_Detected
505 and then Present (Freeze_Id)
506 and then Has_Undefined_Reference (Conseq)
507 then
508 Contract_Freeze_Error (Spec_Id, Freeze_Id);
509 end if;
510
511 -- The contract case is malformed
512
513 else
514 Error_Msg_N ("wrong syntax in contract case", CCase);
515 end if;
516 end Analyze_Contract_Case;
517
518 -- Local variables
519
520 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
521
522 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
523 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
524 -- Save the Ghost-related attributes to restore on exit
525
526 CCase : Node_Id;
527 Restore_Scope : Boolean := False;
528
529 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
530
531 begin
532 -- Do not analyze the pragma multiple times
533
534 if Is_Analyzed_Pragma (N) then
535 return;
536 end if;
537
538 -- Set the Ghost mode in effect from the pragma. Due to the delayed
539 -- analysis of the pragma, the Ghost mode at point of declaration and
540 -- point of analysis may not necessarily be the same. Use the mode in
541 -- effect at the point of declaration.
542
543 Set_Ghost_Mode (N);
544
545 -- Single and multiple contract cases must appear in aggregate form. If
546 -- this is not the case, then either the parser of the analysis of the
547 -- pragma failed to produce an aggregate.
548
549 pragma Assert (Nkind (CCases) = N_Aggregate);
550
551 if Present (Component_Associations (CCases)) then
552
553 -- Ensure that the formal parameters are visible when analyzing all
554 -- clauses. This falls out of the general rule of aspects pertaining
555 -- to subprogram declarations.
556
557 if not In_Open_Scopes (Spec_Id) then
558 Restore_Scope := True;
559 Push_Scope (Spec_Id);
560
561 if Is_Generic_Subprogram (Spec_Id) then
562 Install_Generic_Formals (Spec_Id);
563 else
564 Install_Formals (Spec_Id);
565 end if;
566 end if;
567
568 CCase := First (Component_Associations (CCases));
569 while Present (CCase) loop
570 Analyze_Contract_Case (CCase);
571 Next (CCase);
572 end loop;
573
574 if Restore_Scope then
575 End_Scope;
576 end if;
577
578 -- Currently it is not possible to inline pre/postconditions on a
579 -- subprogram subject to pragma Inline_Always.
580
581 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
582
583 -- Otherwise the pragma is illegal
584
585 else
586 Error_Msg_N ("wrong syntax for contract cases", N);
587 end if;
588
589 Set_Is_Analyzed_Pragma (N);
590
591 Restore_Ghost_Region (Saved_GM, Saved_IGR);
592 end Analyze_Contract_Cases_In_Decl_Part;
593
594 ----------------------------------
595 -- Analyze_Depends_In_Decl_Part --
596 ----------------------------------
597
598 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
599 Loc : constant Source_Ptr := Sloc (N);
600 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
601 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
602
603 All_Inputs_Seen : Elist_Id := No_Elist;
604 -- A list containing the entities of all the inputs processed so far.
605 -- The list is populated with unique entities because the same input
606 -- may appear in multiple input lists.
607
608 All_Outputs_Seen : Elist_Id := No_Elist;
609 -- A list containing the entities of all the outputs processed so far.
610 -- The list is populated with unique entities because output items are
611 -- unique in a dependence relation.
612
613 Constits_Seen : Elist_Id := No_Elist;
614 -- A list containing the entities of all constituents processed so far.
615 -- It aids in detecting illegal usage of a state and a corresponding
616 -- constituent in pragma [Refinde_]Depends.
617
618 Global_Seen : Boolean := False;
619 -- A flag set when pragma Global has been processed
620
621 Null_Output_Seen : Boolean := False;
622 -- A flag used to track the legality of a null output
623
624 Result_Seen : Boolean := False;
625 -- A flag set when Spec_Id'Result is processed
626
627 States_Seen : Elist_Id := No_Elist;
628 -- A list containing the entities of all states processed so far. It
629 -- helps in detecting illegal usage of a state and a corresponding
630 -- constituent in pragma [Refined_]Depends.
631
632 Subp_Inputs : Elist_Id := No_Elist;
633 Subp_Outputs : Elist_Id := No_Elist;
634 -- Two lists containing the full set of inputs and output of the related
635 -- subprograms. Note that these lists contain both nodes and entities.
636
637 Task_Input_Seen : Boolean := False;
638 Task_Output_Seen : Boolean := False;
639 -- Flags used to track the implicit dependence of a task unit on itself
640
641 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
642 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
643 -- to the name buffer. The individual kinds are as follows:
644 -- E_Abstract_State - "state"
645 -- E_Constant - "constant"
646 -- E_Generic_In_Out_Parameter - "generic parameter"
647 -- E_Generic_In_Parameter - "generic parameter"
648 -- E_In_Parameter - "parameter"
649 -- E_In_Out_Parameter - "parameter"
650 -- E_Loop_Parameter - "loop parameter"
651 -- E_Out_Parameter - "parameter"
652 -- E_Protected_Type - "current instance of protected type"
653 -- E_Task_Type - "current instance of task type"
654 -- E_Variable - "global"
655
656 procedure Analyze_Dependency_Clause
657 (Clause : Node_Id;
658 Is_Last : Boolean);
659 -- Verify the legality of a single dependency clause. Flag Is_Last
660 -- denotes whether Clause is the last clause in the relation.
661
662 procedure Check_Function_Return;
663 -- Verify that Funtion'Result appears as one of the outputs
664 -- (SPARK RM 6.1.5(10)).
665
666 procedure Check_Role
667 (Item : Node_Id;
668 Item_Id : Entity_Id;
669 Is_Input : Boolean;
670 Self_Ref : Boolean);
671 -- Ensure that an item fulfills its designated input and/or output role
672 -- as specified by pragma Global (if any) or the enclosing context. If
673 -- this is not the case, emit an error. Item and Item_Id denote the
674 -- attributes of an item. Flag Is_Input should be set when item comes
675 -- from an input list. Flag Self_Ref should be set when the item is an
676 -- output and the dependency clause has operator "+".
677
678 procedure Check_Usage
679 (Subp_Items : Elist_Id;
680 Used_Items : Elist_Id;
681 Is_Input : Boolean);
682 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
683 -- error if this is not the case.
684
685 procedure Normalize_Clause (Clause : Node_Id);
686 -- Remove a self-dependency "+" from the input list of a clause
687
688 -----------------------------
689 -- Add_Item_To_Name_Buffer --
690 -----------------------------
691
692 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
693 begin
694 if Ekind (Item_Id) = E_Abstract_State then
695 Add_Str_To_Name_Buffer ("state");
696
697 elsif Ekind (Item_Id) = E_Constant then
698 Add_Str_To_Name_Buffer ("constant");
699
700 elsif Ekind (Item_Id) in
701 E_Generic_In_Out_Parameter | E_Generic_In_Parameter
702 then
703 Add_Str_To_Name_Buffer ("generic parameter");
704
705 elsif Is_Formal (Item_Id) then
706 Add_Str_To_Name_Buffer ("parameter");
707
708 elsif Ekind (Item_Id) = E_Loop_Parameter then
709 Add_Str_To_Name_Buffer ("loop parameter");
710
711 elsif Ekind (Item_Id) = E_Protected_Type
712 or else Is_Single_Protected_Object (Item_Id)
713 then
714 Add_Str_To_Name_Buffer ("current instance of protected type");
715
716 elsif Ekind (Item_Id) = E_Task_Type
717 or else Is_Single_Task_Object (Item_Id)
718 then
719 Add_Str_To_Name_Buffer ("current instance of task type");
720
721 elsif Ekind (Item_Id) = E_Variable then
722 Add_Str_To_Name_Buffer ("global");
723
724 -- The routine should not be called with non-SPARK items
725
726 else
727 raise Program_Error;
728 end if;
729 end Add_Item_To_Name_Buffer;
730
731 -------------------------------
732 -- Analyze_Dependency_Clause --
733 -------------------------------
734
735 procedure Analyze_Dependency_Clause
736 (Clause : Node_Id;
737 Is_Last : Boolean)
738 is
739 procedure Analyze_Input_List (Inputs : Node_Id);
740 -- Verify the legality of a single input list
741
742 procedure Analyze_Input_Output
743 (Item : Node_Id;
744 Is_Input : Boolean;
745 Self_Ref : Boolean;
746 Top_Level : Boolean;
747 Seen : in out Elist_Id;
748 Null_Seen : in out Boolean;
749 Non_Null_Seen : in out Boolean);
750 -- Verify the legality of a single input or output item. Flag
751 -- Is_Input should be set whenever Item is an input, False when it
752 -- denotes an output. Flag Self_Ref should be set when the item is an
753 -- output and the dependency clause has a "+". Flag Top_Level should
754 -- be set whenever Item appears immediately within an input or output
755 -- list. Seen is a collection of all abstract states, objects and
756 -- formals processed so far. Flag Null_Seen denotes whether a null
757 -- input or output has been encountered. Flag Non_Null_Seen denotes
758 -- whether a non-null input or output has been encountered.
759
760 ------------------------
761 -- Analyze_Input_List --
762 ------------------------
763
764 procedure Analyze_Input_List (Inputs : Node_Id) is
765 Inputs_Seen : Elist_Id := No_Elist;
766 -- A list containing the entities of all inputs that appear in the
767 -- current input list.
768
769 Non_Null_Input_Seen : Boolean := False;
770 Null_Input_Seen : Boolean := False;
771 -- Flags used to check the legality of an input list
772
773 Input : Node_Id;
774
775 begin
776 -- Multiple inputs appear as an aggregate
777
778 if Nkind (Inputs) = N_Aggregate then
779 if Present (Component_Associations (Inputs)) then
780 SPARK_Msg_N
781 ("nested dependency relations not allowed", Inputs);
782
783 elsif Present (Expressions (Inputs)) then
784 Input := First (Expressions (Inputs));
785 while Present (Input) loop
786 Analyze_Input_Output
787 (Item => Input,
788 Is_Input => True,
789 Self_Ref => False,
790 Top_Level => False,
791 Seen => Inputs_Seen,
792 Null_Seen => Null_Input_Seen,
793 Non_Null_Seen => Non_Null_Input_Seen);
794
795 Next (Input);
796 end loop;
797
798 -- Syntax error, always report
799
800 else
801 Error_Msg_N ("malformed input dependency list", Inputs);
802 end if;
803
804 -- Process a solitary input
805
806 else
807 Analyze_Input_Output
808 (Item => Inputs,
809 Is_Input => True,
810 Self_Ref => False,
811 Top_Level => False,
812 Seen => Inputs_Seen,
813 Null_Seen => Null_Input_Seen,
814 Non_Null_Seen => Non_Null_Input_Seen);
815 end if;
816
817 -- Detect an illegal dependency clause of the form
818
819 -- (null =>[+] null)
820
821 if Null_Output_Seen and then Null_Input_Seen then
822 SPARK_Msg_N
823 ("null dependency clause cannot have a null input list",
824 Inputs);
825 end if;
826 end Analyze_Input_List;
827
828 --------------------------
829 -- Analyze_Input_Output --
830 --------------------------
831
832 procedure Analyze_Input_Output
833 (Item : Node_Id;
834 Is_Input : Boolean;
835 Self_Ref : Boolean;
836 Top_Level : Boolean;
837 Seen : in out Elist_Id;
838 Null_Seen : in out Boolean;
839 Non_Null_Seen : in out Boolean)
840 is
841 procedure Current_Task_Instance_Seen;
842 -- Set the appropriate global flag when the current instance of a
843 -- task unit is encountered.
844
845 --------------------------------
846 -- Current_Task_Instance_Seen --
847 --------------------------------
848
849 procedure Current_Task_Instance_Seen is
850 begin
851 if Is_Input then
852 Task_Input_Seen := True;
853 else
854 Task_Output_Seen := True;
855 end if;
856 end Current_Task_Instance_Seen;
857
858 -- Local variables
859
860 Is_Output : constant Boolean := not Is_Input;
861 Grouped : Node_Id;
862 Item_Id : Entity_Id;
863
864 -- Start of processing for Analyze_Input_Output
865
866 begin
867 -- Multiple input or output items appear as an aggregate
868
869 if Nkind (Item) = N_Aggregate then
870 if not Top_Level then
871 SPARK_Msg_N ("nested grouping of items not allowed", Item);
872
873 elsif Present (Component_Associations (Item)) then
874 SPARK_Msg_N
875 ("nested dependency relations not allowed", Item);
876
877 -- Recursively analyze the grouped items
878
879 elsif Present (Expressions (Item)) then
880 Grouped := First (Expressions (Item));
881 while Present (Grouped) loop
882 Analyze_Input_Output
883 (Item => Grouped,
884 Is_Input => Is_Input,
885 Self_Ref => Self_Ref,
886 Top_Level => False,
887 Seen => Seen,
888 Null_Seen => Null_Seen,
889 Non_Null_Seen => Non_Null_Seen);
890
891 Next (Grouped);
892 end loop;
893
894 -- Syntax error, always report
895
896 else
897 Error_Msg_N ("malformed dependency list", Item);
898 end if;
899
900 -- Process attribute 'Result in the context of a dependency clause
901
902 elsif Is_Attribute_Result (Item) then
903 Non_Null_Seen := True;
904
905 Analyze (Item);
906
907 -- Attribute 'Result is allowed to appear on the output side of
908 -- a dependency clause (SPARK RM 6.1.5(6)).
909
910 if Is_Input then
911 SPARK_Msg_N ("function result cannot act as input", Item);
912
913 elsif Null_Seen then
914 SPARK_Msg_N
915 ("cannot mix null and non-null dependency items", Item);
916
917 else
918 Result_Seen := True;
919 end if;
920
921 -- Detect multiple uses of null in a single dependency list or
922 -- throughout the whole relation. Verify the placement of a null
923 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
924
925 elsif Nkind (Item) = N_Null then
926 if Null_Seen then
927 SPARK_Msg_N
928 ("multiple null dependency relations not allowed", Item);
929
930 elsif Non_Null_Seen then
931 SPARK_Msg_N
932 ("cannot mix null and non-null dependency items", Item);
933
934 else
935 Null_Seen := True;
936
937 if Is_Output then
938 if not Is_Last then
939 SPARK_Msg_N
940 ("null output list must be the last clause in a "
941 & "dependency relation", Item);
942
943 -- Catch a useless dependence of the form:
944 -- null =>+ ...
945
946 elsif Self_Ref then
947 SPARK_Msg_N
948 ("useless dependence, null depends on itself", Item);
949 end if;
950 end if;
951 end if;
952
953 -- Default case
954
955 else
956 Non_Null_Seen := True;
957
958 if Null_Seen then
959 SPARK_Msg_N ("cannot mix null and non-null items", Item);
960 end if;
961
962 Analyze (Item);
963 Resolve_State (Item);
964
965 -- Find the entity of the item. If this is a renaming, climb
966 -- the renaming chain to reach the root object. Renamings of
967 -- non-entire objects do not yield an entity (Empty).
968
969 Item_Id := Entity_Of (Item);
970
971 if Present (Item_Id) then
972
973 -- Constants
974
975 if Ekind (Item_Id) in E_Constant | E_Loop_Parameter
976 or else
977
978 -- Current instances of concurrent types
979
980 Ekind (Item_Id) in E_Protected_Type | E_Task_Type
981 or else
982
983 -- Formal parameters
984
985 Ekind (Item_Id) in E_Generic_In_Out_Parameter
986 | E_Generic_In_Parameter
987 | E_In_Parameter
988 | E_In_Out_Parameter
989 | E_Out_Parameter
990 or else
991
992 -- States, variables
993
994 Ekind (Item_Id) in E_Abstract_State | E_Variable
995 then
996 -- A [generic] function is not allowed to have Output
997 -- items in its dependency relations. Note that "null"
998 -- and attribute 'Result are still valid items.
999
1000 if Ekind (Spec_Id) in E_Function | E_Generic_Function
1001 and then not Is_Input
1002 then
1003 SPARK_Msg_N
1004 ("output item is not applicable to function", Item);
1005 end if;
1006
1007 -- The item denotes a concurrent type. Note that single
1008 -- protected/task types are not considered here because
1009 -- they behave as objects in the context of pragma
1010 -- [Refined_]Depends.
1011
1012 if Ekind (Item_Id) in E_Protected_Type | E_Task_Type then
1013
1014 -- This use is legal as long as the concurrent type is
1015 -- the current instance of an enclosing type.
1016
1017 if Is_CCT_Instance (Item_Id, Spec_Id) then
1018
1019 -- The dependence of a task unit on itself is
1020 -- implicit and may or may not be explicitly
1021 -- specified (SPARK RM 6.1.4).
1022
1023 if Ekind (Item_Id) = E_Task_Type then
1024 Current_Task_Instance_Seen;
1025 end if;
1026
1027 -- Otherwise this is not the current instance
1028
1029 else
1030 SPARK_Msg_N
1031 ("invalid use of subtype mark in dependency "
1032 & "relation", Item);
1033 end if;
1034
1035 -- The dependency of a task unit on itself is implicit
1036 -- and may or may not be explicitly specified
1037 -- (SPARK RM 6.1.4).
1038
1039 elsif Is_Single_Task_Object (Item_Id)
1040 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
1041 then
1042 Current_Task_Instance_Seen;
1043 end if;
1044
1045 -- Ensure that the item fulfills its role as input and/or
1046 -- output as specified by pragma Global or the enclosing
1047 -- context.
1048
1049 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
1050
1051 -- Detect multiple uses of the same state, variable or
1052 -- formal parameter. If this is not the case, add the
1053 -- item to the list of processed relations.
1054
1055 if Contains (Seen, Item_Id) then
1056 SPARK_Msg_NE
1057 ("duplicate use of item &", Item, Item_Id);
1058 else
1059 Append_New_Elmt (Item_Id, Seen);
1060 end if;
1061
1062 -- Detect illegal use of an input related to a null
1063 -- output. Such input items cannot appear in other
1064 -- input lists (SPARK RM 6.1.5(13)).
1065
1066 if Is_Input
1067 and then Null_Output_Seen
1068 and then Contains (All_Inputs_Seen, Item_Id)
1069 then
1070 SPARK_Msg_N
1071 ("input of a null output list cannot appear in "
1072 & "multiple input lists", Item);
1073 end if;
1074
1075 -- Add an input or a self-referential output to the list
1076 -- of all processed inputs.
1077
1078 if Is_Input or else Self_Ref then
1079 Append_New_Elmt (Item_Id, All_Inputs_Seen);
1080 end if;
1081
1082 -- State related checks (SPARK RM 6.1.5(3))
1083
1084 if Ekind (Item_Id) = E_Abstract_State then
1085
1086 -- Package and subprogram bodies are instantiated
1087 -- individually in a separate compiler pass. Due to
1088 -- this mode of instantiation, the refinement of a
1089 -- state may no longer be visible when a subprogram
1090 -- body contract is instantiated. Since the generic
1091 -- template is legal, do not perform this check in
1092 -- the instance to circumvent this oddity.
1093
1094 if In_Instance then
1095 null;
1096
1097 -- An abstract state with visible refinement cannot
1098 -- appear in pragma [Refined_]Depends as its place
1099 -- must be taken by some of its constituents
1100 -- (SPARK RM 6.1.4(7)).
1101
1102 elsif Has_Visible_Refinement (Item_Id) then
1103 SPARK_Msg_NE
1104 ("cannot mention state & in dependence relation",
1105 Item, Item_Id);
1106 SPARK_Msg_N ("\use its constituents instead", Item);
1107 return;
1108
1109 -- If the reference to the abstract state appears in
1110 -- an enclosing package body that will eventually
1111 -- refine the state, record the reference for future
1112 -- checks.
1113
1114 else
1115 Record_Possible_Body_Reference
1116 (State_Id => Item_Id,
1117 Ref => Item);
1118 end if;
1119 end if;
1120
1121 -- When the item renames an entire object, replace the
1122 -- item with a reference to the object.
1123
1124 if Entity (Item) /= Item_Id then
1125 Rewrite (Item,
1126 New_Occurrence_Of (Item_Id, Sloc (Item)));
1127 Analyze (Item);
1128 end if;
1129
1130 -- Add the entity of the current item to the list of
1131 -- processed items.
1132
1133 if Ekind (Item_Id) = E_Abstract_State then
1134 Append_New_Elmt (Item_Id, States_Seen);
1135
1136 -- The variable may eventually become a constituent of a
1137 -- single protected/task type. Record the reference now
1138 -- and verify its legality when analyzing the contract of
1139 -- the variable (SPARK RM 9.3).
1140
1141 elsif Ekind (Item_Id) = E_Variable then
1142 Record_Possible_Part_Of_Reference
1143 (Var_Id => Item_Id,
1144 Ref => Item);
1145 end if;
1146
1147 if Ekind (Item_Id) in E_Abstract_State
1148 | E_Constant
1149 | E_Variable
1150 and then Present (Encapsulating_State (Item_Id))
1151 then
1152 Append_New_Elmt (Item_Id, Constits_Seen);
1153 end if;
1154
1155 -- All other input/output items are illegal
1156 -- (SPARK RM 6.1.5(1)).
1157
1158 else
1159 SPARK_Msg_N
1160 ("item must denote parameter, variable, state or "
1161 & "current instance of concurrent type", Item);
1162 end if;
1163
1164 -- All other input/output items are illegal
1165 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1166
1167 else
1168 Error_Msg_N
1169 ("item must denote parameter, variable, state or current "
1170 & "instance of concurrent type", Item);
1171 end if;
1172 end if;
1173 end Analyze_Input_Output;
1174
1175 -- Local variables
1176
1177 Inputs : Node_Id;
1178 Output : Node_Id;
1179 Self_Ref : Boolean;
1180
1181 Non_Null_Output_Seen : Boolean := False;
1182 -- Flag used to check the legality of an output list
1183
1184 -- Start of processing for Analyze_Dependency_Clause
1185
1186 begin
1187 Inputs := Expression (Clause);
1188 Self_Ref := False;
1189
1190 -- An input list with a self-dependency appears as operator "+" where
1191 -- the actuals inputs are the right operand.
1192
1193 if Nkind (Inputs) = N_Op_Plus then
1194 Inputs := Right_Opnd (Inputs);
1195 Self_Ref := True;
1196 end if;
1197
1198 -- Process the output_list of a dependency_clause
1199
1200 Output := First (Choices (Clause));
1201 while Present (Output) loop
1202 Analyze_Input_Output
1203 (Item => Output,
1204 Is_Input => False,
1205 Self_Ref => Self_Ref,
1206 Top_Level => True,
1207 Seen => All_Outputs_Seen,
1208 Null_Seen => Null_Output_Seen,
1209 Non_Null_Seen => Non_Null_Output_Seen);
1210
1211 Next (Output);
1212 end loop;
1213
1214 -- Process the input_list of a dependency_clause
1215
1216 Analyze_Input_List (Inputs);
1217 end Analyze_Dependency_Clause;
1218
1219 ---------------------------
1220 -- Check_Function_Return --
1221 ---------------------------
1222
1223 procedure Check_Function_Return is
1224 begin
1225 if Ekind (Spec_Id) in E_Function | E_Generic_Function
1226 and then not Result_Seen
1227 then
1228 SPARK_Msg_NE
1229 ("result of & must appear in exactly one output list",
1230 N, Spec_Id);
1231 end if;
1232 end Check_Function_Return;
1233
1234 ----------------
1235 -- Check_Role --
1236 ----------------
1237
1238 procedure Check_Role
1239 (Item : Node_Id;
1240 Item_Id : Entity_Id;
1241 Is_Input : Boolean;
1242 Self_Ref : Boolean)
1243 is
1244 procedure Find_Role
1245 (Item_Is_Input : out Boolean;
1246 Item_Is_Output : out Boolean);
1247 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1248 -- Item_Is_Output are set depending on the role.
1249
1250 procedure Role_Error
1251 (Item_Is_Input : Boolean;
1252 Item_Is_Output : Boolean);
1253 -- Emit an error message concerning the incorrect use of Item in
1254 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1255 -- denote whether the item is an input and/or an output.
1256
1257 ---------------
1258 -- Find_Role --
1259 ---------------
1260
1261 procedure Find_Role
1262 (Item_Is_Input : out Boolean;
1263 Item_Is_Output : out Boolean)
1264 is
1265 -- A constant or IN parameter of access type should be handled
1266 -- like a variable, as the underlying memory pointed-to can be
1267 -- modified. Use Adjusted_Kind to do this adjustment.
1268
1269 Adjusted_Kind : Entity_Kind := Ekind (Item_Id);
1270
1271 begin
1272 if Ekind (Item_Id) in E_Constant
1273 | E_Generic_In_Parameter
1274 | E_In_Parameter
1275 and then Is_Access_Type (Etype (Item_Id))
1276 then
1277 Adjusted_Kind := E_Variable;
1278 end if;
1279
1280 case Adjusted_Kind is
1281
1282 -- Abstract states
1283
1284 when E_Abstract_State =>
1285
1286 -- When pragma Global is present it determines the mode of
1287 -- the abstract state.
1288
1289 if Global_Seen then
1290 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1291 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1292
1293 -- Otherwise the state has a default IN OUT mode, because it
1294 -- behaves as a variable.
1295
1296 else
1297 Item_Is_Input := True;
1298 Item_Is_Output := True;
1299 end if;
1300
1301 -- Constants and IN parameters
1302
1303 when E_Constant
1304 | E_Generic_In_Parameter
1305 | E_In_Parameter
1306 | E_Loop_Parameter
1307 =>
1308 -- When pragma Global is present it determines the mode
1309 -- of constant objects as inputs (and such objects cannot
1310 -- appear as outputs in the Global contract).
1311
1312 if Global_Seen then
1313 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1314 else
1315 Item_Is_Input := True;
1316 end if;
1317
1318 Item_Is_Output := False;
1319
1320 -- Variables and IN OUT parameters, as well as constants and
1321 -- IN parameters of access type which are handled like
1322 -- variables.
1323
1324 when E_Generic_In_Out_Parameter
1325 | E_In_Out_Parameter
1326 | E_Variable
1327 =>
1328 -- When pragma Global is present it determines the mode of
1329 -- the object.
1330
1331 if Global_Seen then
1332
1333 -- A variable has mode IN when its type is unconstrained
1334 -- or tagged because array bounds, discriminants or tags
1335 -- can be read.
1336
1337 Item_Is_Input :=
1338 Appears_In (Subp_Inputs, Item_Id)
1339 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1340
1341 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1342
1343 -- Otherwise the variable has a default IN OUT mode
1344
1345 else
1346 Item_Is_Input := True;
1347 Item_Is_Output := True;
1348 end if;
1349
1350 when E_Out_Parameter =>
1351
1352 -- An OUT parameter of the related subprogram; it cannot
1353 -- appear in Global.
1354
1355 if Scope (Item_Id) = Spec_Id then
1356
1357 -- The parameter has mode IN if its type is unconstrained
1358 -- or tagged because array bounds, discriminants or tags
1359 -- can be read.
1360
1361 Item_Is_Input :=
1362 Is_Unconstrained_Or_Tagged_Item (Item_Id);
1363
1364 Item_Is_Output := True;
1365
1366 -- An OUT parameter of an enclosing subprogram; it can
1367 -- appear in Global and behaves as a read-write variable.
1368
1369 else
1370 -- When pragma Global is present it determines the mode
1371 -- of the object.
1372
1373 if Global_Seen then
1374
1375 -- A variable has mode IN when its type is
1376 -- unconstrained or tagged because array
1377 -- bounds, discriminants or tags can be read.
1378
1379 Item_Is_Input :=
1380 Appears_In (Subp_Inputs, Item_Id)
1381 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1382
1383 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1384
1385 -- Otherwise the variable has a default IN OUT mode
1386
1387 else
1388 Item_Is_Input := True;
1389 Item_Is_Output := True;
1390 end if;
1391 end if;
1392
1393 -- Protected types
1394
1395 when E_Protected_Type =>
1396 if Global_Seen then
1397
1398 -- A variable has mode IN when its type is unconstrained
1399 -- or tagged because array bounds, discriminants or tags
1400 -- can be read.
1401
1402 Item_Is_Input :=
1403 Appears_In (Subp_Inputs, Item_Id)
1404 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1405
1406 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1407
1408 else
1409 -- A protected type acts as a formal parameter of mode IN
1410 -- when it applies to a protected function.
1411
1412 if Ekind (Spec_Id) = E_Function then
1413 Item_Is_Input := True;
1414 Item_Is_Output := False;
1415
1416 -- Otherwise the protected type acts as a formal of mode
1417 -- IN OUT.
1418
1419 else
1420 Item_Is_Input := True;
1421 Item_Is_Output := True;
1422 end if;
1423 end if;
1424
1425 -- Task types
1426
1427 when E_Task_Type =>
1428
1429 -- When pragma Global is present it determines the mode of
1430 -- the object.
1431
1432 if Global_Seen then
1433 Item_Is_Input :=
1434 Appears_In (Subp_Inputs, Item_Id)
1435 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1436
1437 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1438
1439 -- Otherwise task types act as IN OUT parameters
1440
1441 else
1442 Item_Is_Input := True;
1443 Item_Is_Output := True;
1444 end if;
1445
1446 when others =>
1447 raise Program_Error;
1448 end case;
1449 end Find_Role;
1450
1451 ----------------
1452 -- Role_Error --
1453 ----------------
1454
1455 procedure Role_Error
1456 (Item_Is_Input : Boolean;
1457 Item_Is_Output : Boolean)
1458 is
1459 Error_Msg : Name_Id;
1460
1461 begin
1462 Name_Len := 0;
1463
1464 -- When the item is not part of the input and the output set of
1465 -- the related subprogram, then it appears as extra in pragma
1466 -- [Refined_]Depends.
1467
1468 if not Item_Is_Input and then not Item_Is_Output then
1469 Add_Item_To_Name_Buffer (Item_Id);
1470 Add_Str_To_Name_Buffer
1471 (" & cannot appear in dependence relation");
1472
1473 Error_Msg := Name_Find;
1474 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1475
1476 Error_Msg_Name_1 := Chars (Spec_Id);
1477 SPARK_Msg_NE
1478 (Fix_Msg (Spec_Id, "\& is not part of the input or output "
1479 & "set of subprogram %"), Item, Item_Id);
1480
1481 -- The mode of the item and its role in pragma [Refined_]Depends
1482 -- are in conflict. Construct a detailed message explaining the
1483 -- illegality (SPARK RM 6.1.5(5-6)).
1484
1485 else
1486 if Item_Is_Input then
1487 Add_Str_To_Name_Buffer ("read-only");
1488 else
1489 Add_Str_To_Name_Buffer ("write-only");
1490 end if;
1491
1492 Add_Char_To_Name_Buffer (' ');
1493 Add_Item_To_Name_Buffer (Item_Id);
1494 Add_Str_To_Name_Buffer (" & cannot appear as ");
1495
1496 if Item_Is_Input then
1497 Add_Str_To_Name_Buffer ("output");
1498 else
1499 Add_Str_To_Name_Buffer ("input");
1500 end if;
1501
1502 Add_Str_To_Name_Buffer (" in dependence relation");
1503 Error_Msg := Name_Find;
1504 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1505 end if;
1506 end Role_Error;
1507
1508 -- Local variables
1509
1510 Item_Is_Input : Boolean;
1511 Item_Is_Output : Boolean;
1512
1513 -- Start of processing for Check_Role
1514
1515 begin
1516 Find_Role (Item_Is_Input, Item_Is_Output);
1517
1518 -- Input item
1519
1520 if Is_Input then
1521 if not Item_Is_Input then
1522 Role_Error (Item_Is_Input, Item_Is_Output);
1523 end if;
1524
1525 -- Self-referential item
1526
1527 elsif Self_Ref then
1528 if not Item_Is_Input or else not Item_Is_Output then
1529 Role_Error (Item_Is_Input, Item_Is_Output);
1530 end if;
1531
1532 -- Output item
1533
1534 elsif not Item_Is_Output then
1535 Role_Error (Item_Is_Input, Item_Is_Output);
1536 end if;
1537 end Check_Role;
1538
1539 -----------------
1540 -- Check_Usage --
1541 -----------------
1542
1543 procedure Check_Usage
1544 (Subp_Items : Elist_Id;
1545 Used_Items : Elist_Id;
1546 Is_Input : Boolean)
1547 is
1548 procedure Usage_Error (Item_Id : Entity_Id);
1549 -- Emit an error concerning the illegal usage of an item
1550
1551 -----------------
1552 -- Usage_Error --
1553 -----------------
1554
1555 procedure Usage_Error (Item_Id : Entity_Id) is
1556 Error_Msg : Name_Id;
1557
1558 begin
1559 -- Input case
1560
1561 if Is_Input then
1562
1563 -- Unconstrained and tagged items are not part of the explicit
1564 -- input set of the related subprogram, they do not have to be
1565 -- present in a dependence relation and should not be flagged
1566 -- (SPARK RM 6.1.5(5)).
1567
1568 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1569 Name_Len := 0;
1570
1571 Add_Item_To_Name_Buffer (Item_Id);
1572 Add_Str_To_Name_Buffer
1573 (" & is missing from input dependence list");
1574
1575 Error_Msg := Name_Find;
1576 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1577 SPARK_Msg_NE
1578 ("\add `null ='> &` dependency to ignore this input",
1579 N, Item_Id);
1580 end if;
1581
1582 -- Output case (SPARK RM 6.1.5(10))
1583
1584 else
1585 Name_Len := 0;
1586
1587 Add_Item_To_Name_Buffer (Item_Id);
1588 Add_Str_To_Name_Buffer
1589 (" & is missing from output dependence list");
1590
1591 Error_Msg := Name_Find;
1592 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1593 end if;
1594 end Usage_Error;
1595
1596 -- Local variables
1597
1598 Elmt : Elmt_Id;
1599 Item : Node_Id;
1600 Item_Id : Entity_Id;
1601
1602 -- Start of processing for Check_Usage
1603
1604 begin
1605 if No (Subp_Items) then
1606 return;
1607 end if;
1608
1609 -- Each input or output of the subprogram must appear in a dependency
1610 -- relation.
1611
1612 Elmt := First_Elmt (Subp_Items);
1613 while Present (Elmt) loop
1614 Item := Node (Elmt);
1615
1616 if Nkind (Item) = N_Defining_Identifier then
1617 Item_Id := Item;
1618 else
1619 Item_Id := Entity_Of (Item);
1620 end if;
1621
1622 -- The item does not appear in a dependency
1623
1624 if Present (Item_Id)
1625 and then not Contains (Used_Items, Item_Id)
1626 then
1627 if Is_Formal (Item_Id) then
1628 Usage_Error (Item_Id);
1629
1630 -- The current instance of a protected type behaves as a formal
1631 -- parameter (SPARK RM 6.1.4).
1632
1633 elsif Ekind (Item_Id) = E_Protected_Type
1634 or else Is_Single_Protected_Object (Item_Id)
1635 then
1636 Usage_Error (Item_Id);
1637
1638 -- The current instance of a task type behaves as a formal
1639 -- parameter (SPARK RM 6.1.4).
1640
1641 elsif Ekind (Item_Id) = E_Task_Type
1642 or else Is_Single_Task_Object (Item_Id)
1643 then
1644 -- The dependence of a task unit on itself is implicit and
1645 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1646 -- Emit an error if only one input/output is present.
1647
1648 if Task_Input_Seen /= Task_Output_Seen then
1649 Usage_Error (Item_Id);
1650 end if;
1651
1652 -- States and global objects are not used properly only when
1653 -- the subprogram is subject to pragma Global.
1654
1655 elsif Global_Seen then
1656 Usage_Error (Item_Id);
1657 end if;
1658 end if;
1659
1660 Next_Elmt (Elmt);
1661 end loop;
1662 end Check_Usage;
1663
1664 ----------------------
1665 -- Normalize_Clause --
1666 ----------------------
1667
1668 procedure Normalize_Clause (Clause : Node_Id) is
1669 procedure Create_Or_Modify_Clause
1670 (Output : Node_Id;
1671 Outputs : Node_Id;
1672 Inputs : Node_Id;
1673 After : Node_Id;
1674 In_Place : Boolean;
1675 Multiple : Boolean);
1676 -- Create a brand new clause to represent the self-reference or
1677 -- modify the input and/or output lists of an existing clause. Output
1678 -- denotes a self-referencial output. Outputs is the output list of a
1679 -- clause. Inputs is the input list of a clause. After denotes the
1680 -- clause after which the new clause is to be inserted. Flag In_Place
1681 -- should be set when normalizing the last output of an output list.
1682 -- Flag Multiple should be set when Output comes from a list with
1683 -- multiple items.
1684
1685 -----------------------------
1686 -- Create_Or_Modify_Clause --
1687 -----------------------------
1688
1689 procedure Create_Or_Modify_Clause
1690 (Output : Node_Id;
1691 Outputs : Node_Id;
1692 Inputs : Node_Id;
1693 After : Node_Id;
1694 In_Place : Boolean;
1695 Multiple : Boolean)
1696 is
1697 procedure Propagate_Output
1698 (Output : Node_Id;
1699 Inputs : Node_Id);
1700 -- Handle the various cases of output propagation to the input
1701 -- list. Output denotes a self-referencial output item. Inputs
1702 -- is the input list of a clause.
1703
1704 ----------------------
1705 -- Propagate_Output --
1706 ----------------------
1707
1708 procedure Propagate_Output
1709 (Output : Node_Id;
1710 Inputs : Node_Id)
1711 is
1712 function In_Input_List
1713 (Item : Entity_Id;
1714 Inputs : List_Id) return Boolean;
1715 -- Determine whether a particulat item appears in the input
1716 -- list of a clause.
1717
1718 -------------------
1719 -- In_Input_List --
1720 -------------------
1721
1722 function In_Input_List
1723 (Item : Entity_Id;
1724 Inputs : List_Id) return Boolean
1725 is
1726 Elmt : Node_Id;
1727
1728 begin
1729 Elmt := First (Inputs);
1730 while Present (Elmt) loop
1731 if Entity_Of (Elmt) = Item then
1732 return True;
1733 end if;
1734
1735 Next (Elmt);
1736 end loop;
1737
1738 return False;
1739 end In_Input_List;
1740
1741 -- Local variables
1742
1743 Output_Id : constant Entity_Id := Entity_Of (Output);
1744 Grouped : List_Id;
1745
1746 -- Start of processing for Propagate_Output
1747
1748 begin
1749 -- The clause is of the form:
1750
1751 -- (Output =>+ null)
1752
1753 -- Remove null input and replace it with a copy of the output:
1754
1755 -- (Output => Output)
1756
1757 if Nkind (Inputs) = N_Null then
1758 Rewrite (Inputs, New_Copy_Tree (Output));
1759
1760 -- The clause is of the form:
1761
1762 -- (Output =>+ (Input1, ..., InputN))
1763
1764 -- Determine whether the output is not already mentioned in the
1765 -- input list and if not, add it to the list of inputs:
1766
1767 -- (Output => (Output, Input1, ..., InputN))
1768
1769 elsif Nkind (Inputs) = N_Aggregate then
1770 Grouped := Expressions (Inputs);
1771
1772 if not In_Input_List
1773 (Item => Output_Id,
1774 Inputs => Grouped)
1775 then
1776 Prepend_To (Grouped, New_Copy_Tree (Output));
1777 end if;
1778
1779 -- The clause is of the form:
1780
1781 -- (Output =>+ Input)
1782
1783 -- If the input does not mention the output, group the two
1784 -- together:
1785
1786 -- (Output => (Output, Input))
1787
1788 elsif Entity_Of (Inputs) /= Output_Id then
1789 Rewrite (Inputs,
1790 Make_Aggregate (Loc,
1791 Expressions => New_List (
1792 New_Copy_Tree (Output),
1793 New_Copy_Tree (Inputs))));
1794 end if;
1795 end Propagate_Output;
1796
1797 -- Local variables
1798
1799 Loc : constant Source_Ptr := Sloc (Clause);
1800 New_Clause : Node_Id;
1801
1802 -- Start of processing for Create_Or_Modify_Clause
1803
1804 begin
1805 -- A null output depending on itself does not require any
1806 -- normalization.
1807
1808 if Nkind (Output) = N_Null then
1809 return;
1810
1811 -- A function result cannot depend on itself because it cannot
1812 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1813
1814 elsif Is_Attribute_Result (Output) then
1815 SPARK_Msg_N ("function result cannot depend on itself", Output);
1816 return;
1817 end if;
1818
1819 -- When performing the transformation in place, simply add the
1820 -- output to the list of inputs (if not already there). This
1821 -- case arises when dealing with the last output of an output
1822 -- list. Perform the normalization in place to avoid generating
1823 -- a malformed tree.
1824
1825 if In_Place then
1826 Propagate_Output (Output, Inputs);
1827
1828 -- A list with multiple outputs is slowly trimmed until only
1829 -- one element remains. When this happens, replace aggregate
1830 -- with the element itself.
1831
1832 if Multiple then
1833 Remove (Output);
1834 Rewrite (Outputs, Output);
1835 end if;
1836
1837 -- Default case
1838
1839 else
1840 -- Unchain the output from its output list as it will appear in
1841 -- a new clause. Note that we cannot simply rewrite the output
1842 -- as null because this will violate the semantics of pragma
1843 -- Depends.
1844
1845 Remove (Output);
1846
1847 -- Generate a new clause of the form:
1848 -- (Output => Inputs)
1849
1850 New_Clause :=
1851 Make_Component_Association (Loc,
1852 Choices => New_List (Output),
1853 Expression => New_Copy_Tree (Inputs));
1854
1855 -- The new clause contains replicated content that has already
1856 -- been analyzed. There is not need to reanalyze or renormalize
1857 -- it again.
1858
1859 Set_Analyzed (New_Clause);
1860
1861 Propagate_Output
1862 (Output => First (Choices (New_Clause)),
1863 Inputs => Expression (New_Clause));
1864
1865 Insert_After (After, New_Clause);
1866 end if;
1867 end Create_Or_Modify_Clause;
1868
1869 -- Local variables
1870
1871 Outputs : constant Node_Id := First (Choices (Clause));
1872 Inputs : Node_Id;
1873 Last_Output : Node_Id;
1874 Next_Output : Node_Id;
1875 Output : Node_Id;
1876
1877 -- Start of processing for Normalize_Clause
1878
1879 begin
1880 -- A self-dependency appears as operator "+". Remove the "+" from the
1881 -- tree by moving the real inputs to their proper place.
1882
1883 if Nkind (Expression (Clause)) = N_Op_Plus then
1884 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1885 Inputs := Expression (Clause);
1886
1887 -- Multiple outputs appear as an aggregate
1888
1889 if Nkind (Outputs) = N_Aggregate then
1890 Last_Output := Last (Expressions (Outputs));
1891
1892 Output := First (Expressions (Outputs));
1893 while Present (Output) loop
1894
1895 -- Normalization may remove an output from its list,
1896 -- preserve the subsequent output now.
1897
1898 Next_Output := Next (Output);
1899
1900 Create_Or_Modify_Clause
1901 (Output => Output,
1902 Outputs => Outputs,
1903 Inputs => Inputs,
1904 After => Clause,
1905 In_Place => Output = Last_Output,
1906 Multiple => True);
1907
1908 Output := Next_Output;
1909 end loop;
1910
1911 -- Solitary output
1912
1913 else
1914 Create_Or_Modify_Clause
1915 (Output => Outputs,
1916 Outputs => Empty,
1917 Inputs => Inputs,
1918 After => Empty,
1919 In_Place => True,
1920 Multiple => False);
1921 end if;
1922 end if;
1923 end Normalize_Clause;
1924
1925 -- Local variables
1926
1927 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
1928 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1929
1930 Clause : Node_Id;
1931 Errors : Nat;
1932 Last_Clause : Node_Id;
1933 Restore_Scope : Boolean := False;
1934
1935 -- Start of processing for Analyze_Depends_In_Decl_Part
1936
1937 begin
1938 -- Do not analyze the pragma multiple times
1939
1940 if Is_Analyzed_Pragma (N) then
1941 return;
1942 end if;
1943
1944 -- Empty dependency list
1945
1946 if Nkind (Deps) = N_Null then
1947
1948 -- Gather all states, objects and formal parameters that the
1949 -- subprogram may depend on. These items are obtained from the
1950 -- parameter profile or pragma [Refined_]Global (if available).
1951
1952 Collect_Subprogram_Inputs_Outputs
1953 (Subp_Id => Subp_Id,
1954 Subp_Inputs => Subp_Inputs,
1955 Subp_Outputs => Subp_Outputs,
1956 Global_Seen => Global_Seen);
1957
1958 -- Verify that every input or output of the subprogram appear in a
1959 -- dependency.
1960
1961 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1962 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1963 Check_Function_Return;
1964
1965 -- Dependency clauses appear as component associations of an aggregate
1966
1967 elsif Nkind (Deps) = N_Aggregate then
1968
1969 -- Do not attempt to perform analysis of a syntactically illegal
1970 -- clause as this will lead to misleading errors.
1971
1972 if Has_Extra_Parentheses (Deps) then
1973 return;
1974 end if;
1975
1976 if Present (Component_Associations (Deps)) then
1977 Last_Clause := Last (Component_Associations (Deps));
1978
1979 -- Gather all states, objects and formal parameters that the
1980 -- subprogram may depend on. These items are obtained from the
1981 -- parameter profile or pragma [Refined_]Global (if available).
1982
1983 Collect_Subprogram_Inputs_Outputs
1984 (Subp_Id => Subp_Id,
1985 Subp_Inputs => Subp_Inputs,
1986 Subp_Outputs => Subp_Outputs,
1987 Global_Seen => Global_Seen);
1988
1989 -- When pragma [Refined_]Depends appears on a single concurrent
1990 -- type, it is relocated to the anonymous object.
1991
1992 if Is_Single_Concurrent_Object (Spec_Id) then
1993 null;
1994
1995 -- Ensure that the formal parameters are visible when analyzing
1996 -- all clauses. This falls out of the general rule of aspects
1997 -- pertaining to subprogram declarations.
1998
1999 elsif not In_Open_Scopes (Spec_Id) then
2000 Restore_Scope := True;
2001 Push_Scope (Spec_Id);
2002
2003 if Ekind (Spec_Id) = E_Task_Type then
2004
2005 -- Task discriminants cannot appear in the [Refined_]Depends
2006 -- contract, but must be present for the analysis so that we
2007 -- can reject them with an informative error message.
2008
2009 if Has_Discriminants (Spec_Id) then
2010 Install_Discriminants (Spec_Id);
2011 end if;
2012
2013 elsif Is_Generic_Subprogram (Spec_Id) then
2014 Install_Generic_Formals (Spec_Id);
2015
2016 else
2017 Install_Formals (Spec_Id);
2018 end if;
2019 end if;
2020
2021 Clause := First (Component_Associations (Deps));
2022 while Present (Clause) loop
2023 Errors := Serious_Errors_Detected;
2024
2025 -- The normalization mechanism may create extra clauses that
2026 -- contain replicated input and output names. There is no need
2027 -- to reanalyze them.
2028
2029 if not Analyzed (Clause) then
2030 Set_Analyzed (Clause);
2031
2032 Analyze_Dependency_Clause
2033 (Clause => Clause,
2034 Is_Last => Clause = Last_Clause);
2035 end if;
2036
2037 -- Do not normalize a clause if errors were detected (count
2038 -- of Serious_Errors has increased) because the inputs and/or
2039 -- outputs may denote illegal items.
2040
2041 if Serious_Errors_Detected = Errors then
2042 Normalize_Clause (Clause);
2043 end if;
2044
2045 Next (Clause);
2046 end loop;
2047
2048 if Restore_Scope then
2049 End_Scope;
2050 end if;
2051
2052 -- Verify that every input or output of the subprogram appear in a
2053 -- dependency.
2054
2055 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
2056 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
2057 Check_Function_Return;
2058
2059 -- The dependency list is malformed. This is a syntax error, always
2060 -- report.
2061
2062 else
2063 Error_Msg_N ("malformed dependency relation", Deps);
2064 return;
2065 end if;
2066
2067 -- The top level dependency relation is malformed. This is a syntax
2068 -- error, always report.
2069
2070 else
2071 Error_Msg_N ("malformed dependency relation", Deps);
2072 goto Leave;
2073 end if;
2074
2075 -- Ensure that a state and a corresponding constituent do not appear
2076 -- together in pragma [Refined_]Depends.
2077
2078 Check_State_And_Constituent_Use
2079 (States => States_Seen,
2080 Constits => Constits_Seen,
2081 Context => N);
2082
2083 <<Leave>>
2084 Set_Is_Analyzed_Pragma (N);
2085 end Analyze_Depends_In_Decl_Part;
2086
2087 --------------------------------------------
2088 -- Analyze_External_Property_In_Decl_Part --
2089 --------------------------------------------
2090
2091 procedure Analyze_External_Property_In_Decl_Part
2092 (N : Node_Id;
2093 Expr_Val : out Boolean)
2094 is
2095 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pragma_Name (N));
2096 Arg1 : constant Node_Id :=
2097 First (Pragma_Argument_Associations (N));
2098 Obj_Decl : constant Node_Id := Find_Related_Context (N);
2099 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
2100 Expr : Node_Id;
2101
2102 begin
2103 Expr_Val := False;
2104
2105 -- Do not analyze the pragma multiple times
2106
2107 if Is_Analyzed_Pragma (N) then
2108 return;
2109 end if;
2110
2111 Error_Msg_Name_1 := Pragma_Name (N);
2112
2113 -- An external property pragma must apply to an effectively volatile
2114 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
2115 -- The check is performed at the end of the declarative region due to a
2116 -- possible out-of-order arrangement of pragmas:
2117
2118 -- Obj : ...;
2119 -- pragma Async_Readers (Obj);
2120 -- pragma Volatile (Obj);
2121
2122 if Prag_Id /= Pragma_No_Caching
2123 and then not Is_Effectively_Volatile (Obj_Id)
2124 then
2125 if Ekind (Obj_Id) = E_Variable
2126 and then No_Caching_Enabled (Obj_Id)
2127 then
2128 SPARK_Msg_N
2129 ("illegal combination of external property % and property "
2130 & """No_Caching"" (SPARK RM 7.1.2(6))", N);
2131 else
2132 SPARK_Msg_N
2133 ("external property % must apply to a volatile type or object",
2134 N);
2135 end if;
2136
2137 -- Pragma No_Caching should only apply to volatile variables of
2138 -- a non-effectively volatile type (SPARK RM 7.1.2).
2139
2140 elsif Prag_Id = Pragma_No_Caching then
2141 if Is_Effectively_Volatile (Etype (Obj_Id)) then
2142 SPARK_Msg_N ("property % must not apply to an object of "
2143 & "an effectively volatile type", N);
2144 elsif not Is_Volatile (Obj_Id) then
2145 SPARK_Msg_N ("property % must apply to a volatile object", N);
2146 end if;
2147 end if;
2148
2149 -- Ensure that the Boolean expression (if present) is static. A missing
2150 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2151
2152 Expr_Val := True;
2153
2154 if Present (Arg1) then
2155 Expr := Get_Pragma_Arg (Arg1);
2156
2157 if Is_OK_Static_Expression (Expr) then
2158 Expr_Val := Is_True (Expr_Value (Expr));
2159 end if;
2160 end if;
2161
2162 Set_Is_Analyzed_Pragma (N);
2163 end Analyze_External_Property_In_Decl_Part;
2164
2165 ---------------------------------
2166 -- Analyze_Global_In_Decl_Part --
2167 ---------------------------------
2168
2169 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
2170 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2171 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2172 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2173
2174 Constits_Seen : Elist_Id := No_Elist;
2175 -- A list containing the entities of all constituents processed so far.
2176 -- It aids in detecting illegal usage of a state and a corresponding
2177 -- constituent in pragma [Refinde_]Global.
2178
2179 Seen : Elist_Id := No_Elist;
2180 -- A list containing the entities of all the items processed so far. It
2181 -- plays a role in detecting distinct entities.
2182
2183 States_Seen : Elist_Id := No_Elist;
2184 -- A list containing the entities of all states processed so far. It
2185 -- helps in detecting illegal usage of a state and a corresponding
2186 -- constituent in pragma [Refined_]Global.
2187
2188 In_Out_Seen : Boolean := False;
2189 Input_Seen : Boolean := False;
2190 Output_Seen : Boolean := False;
2191 Proof_Seen : Boolean := False;
2192 -- Flags used to verify the consistency of modes
2193
2194 procedure Analyze_Global_List
2195 (List : Node_Id;
2196 Global_Mode : Name_Id := Name_Input);
2197 -- Verify the legality of a single global list declaration. Global_Mode
2198 -- denotes the current mode in effect.
2199
2200 -------------------------
2201 -- Analyze_Global_List --
2202 -------------------------
2203
2204 procedure Analyze_Global_List
2205 (List : Node_Id;
2206 Global_Mode : Name_Id := Name_Input)
2207 is
2208 procedure Analyze_Global_Item
2209 (Item : Node_Id;
2210 Global_Mode : Name_Id);
2211 -- Verify the legality of a single global item declaration denoted by
2212 -- Item. Global_Mode denotes the current mode in effect.
2213
2214 procedure Check_Duplicate_Mode
2215 (Mode : Node_Id;
2216 Status : in out Boolean);
2217 -- Flag Status denotes whether a particular mode has been seen while
2218 -- processing a global list. This routine verifies that Mode is not a
2219 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2220
2221 procedure Check_Mode_Restriction_In_Enclosing_Context
2222 (Item : Node_Id;
2223 Item_Id : Entity_Id);
2224 -- Verify that an item of mode In_Out or Output does not appear as
2225 -- an input in the Global aspect of an enclosing subprogram or task
2226 -- unit. If this is the case, emit an error. Item and Item_Id are
2227 -- respectively the item and its entity.
2228
2229 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
2230 -- Mode denotes either In_Out or Output. Depending on the kind of the
2231 -- related subprogram, emit an error if those two modes apply to a
2232 -- function (SPARK RM 6.1.4(10)).
2233
2234 -------------------------
2235 -- Analyze_Global_Item --
2236 -------------------------
2237
2238 procedure Analyze_Global_Item
2239 (Item : Node_Id;
2240 Global_Mode : Name_Id)
2241 is
2242 Item_Id : Entity_Id;
2243
2244 begin
2245 -- Detect one of the following cases
2246
2247 -- with Global => (null, Name)
2248 -- with Global => (Name_1, null, Name_2)
2249 -- with Global => (Name, null)
2250
2251 if Nkind (Item) = N_Null then
2252 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
2253 return;
2254 end if;
2255
2256 Analyze (Item);
2257 Resolve_State (Item);
2258
2259 -- Find the entity of the item. If this is a renaming, climb the
2260 -- renaming chain to reach the root object. Renamings of non-
2261 -- entire objects do not yield an entity (Empty).
2262
2263 Item_Id := Entity_Of (Item);
2264
2265 if Present (Item_Id) then
2266
2267 -- A global item may denote a formal parameter of an enclosing
2268 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2269 -- provide a better error diagnostic.
2270
2271 if Is_Formal (Item_Id) then
2272 if Scope (Item_Id) = Spec_Id then
2273 SPARK_Msg_NE
2274 (Fix_Msg (Spec_Id, "global item cannot reference "
2275 & "parameter of subprogram &"), Item, Spec_Id);
2276 return;
2277 end if;
2278
2279 -- A global item may denote a concurrent type as long as it is
2280 -- the current instance of an enclosing protected or task type
2281 -- (SPARK RM 6.1.4).
2282
2283 elsif Ekind (Item_Id) in E_Protected_Type | E_Task_Type then
2284 if Is_CCT_Instance (Item_Id, Spec_Id) then
2285
2286 -- Pragma [Refined_]Global associated with a protected
2287 -- subprogram cannot mention the current instance of a
2288 -- protected type because the instance behaves as a
2289 -- formal parameter.
2290
2291 if Ekind (Item_Id) = E_Protected_Type then
2292 if Scope (Spec_Id) = Item_Id then
2293 Error_Msg_Name_1 := Chars (Item_Id);
2294 SPARK_Msg_NE
2295 (Fix_Msg (Spec_Id, "global item of subprogram & "
2296 & "cannot reference current instance of "
2297 & "protected type %"), Item, Spec_Id);
2298 return;
2299 end if;
2300
2301 -- Pragma [Refined_]Global associated with a task type
2302 -- cannot mention the current instance of a task type
2303 -- because the instance behaves as a formal parameter.
2304
2305 else pragma Assert (Ekind (Item_Id) = E_Task_Type);
2306 if Spec_Id = Item_Id then
2307 Error_Msg_Name_1 := Chars (Item_Id);
2308 SPARK_Msg_NE
2309 (Fix_Msg (Spec_Id, "global item of subprogram & "
2310 & "cannot reference current instance of task "
2311 & "type %"), Item, Spec_Id);
2312 return;
2313 end if;
2314 end if;
2315
2316 -- Otherwise the global item denotes a subtype mark that is
2317 -- not a current instance.
2318
2319 else
2320 SPARK_Msg_N
2321 ("invalid use of subtype mark in global list", Item);
2322 return;
2323 end if;
2324
2325 -- A global item may denote the anonymous object created for a
2326 -- single protected/task type as long as the current instance
2327 -- is the same single type (SPARK RM 6.1.4).
2328
2329 elsif Is_Single_Concurrent_Object (Item_Id)
2330 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
2331 then
2332 -- Pragma [Refined_]Global associated with a protected
2333 -- subprogram cannot mention the current instance of a
2334 -- protected type because the instance behaves as a formal
2335 -- parameter.
2336
2337 if Is_Single_Protected_Object (Item_Id) then
2338 if Scope (Spec_Id) = Etype (Item_Id) then
2339 Error_Msg_Name_1 := Chars (Item_Id);
2340 SPARK_Msg_NE
2341 (Fix_Msg (Spec_Id, "global item of subprogram & "
2342 & "cannot reference current instance of protected "
2343 & "type %"), Item, Spec_Id);
2344 return;
2345 end if;
2346
2347 -- Pragma [Refined_]Global associated with a task type
2348 -- cannot mention the current instance of a task type
2349 -- because the instance behaves as a formal parameter.
2350
2351 else pragma Assert (Is_Single_Task_Object (Item_Id));
2352 if Spec_Id = Item_Id then
2353 Error_Msg_Name_1 := Chars (Item_Id);
2354 SPARK_Msg_NE
2355 (Fix_Msg (Spec_Id, "global item of subprogram & "
2356 & "cannot reference current instance of task "
2357 & "type %"), Item, Spec_Id);
2358 return;
2359 end if;
2360 end if;
2361
2362 -- A formal object may act as a global item inside a generic
2363
2364 elsif Is_Formal_Object (Item_Id) then
2365 null;
2366
2367 -- The only legal references are those to abstract states,
2368 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2369
2370 elsif Ekind (Item_Id) not in E_Abstract_State
2371 | E_Constant
2372 | E_Loop_Parameter
2373 | E_Variable
2374 then
2375 SPARK_Msg_N
2376 ("global item must denote object, state or current "
2377 & "instance of concurrent type", Item);
2378
2379 if Ekind (Item_Id) in Named_Kind then
2380 SPARK_Msg_NE
2381 ("\named number & is not an object", Item, Item);
2382 end if;
2383
2384 return;
2385 end if;
2386
2387 -- State related checks
2388
2389 if Ekind (Item_Id) = E_Abstract_State then
2390
2391 -- Package and subprogram bodies are instantiated
2392 -- individually in a separate compiler pass. Due to this
2393 -- mode of instantiation, the refinement of a state may
2394 -- no longer be visible when a subprogram body contract
2395 -- is instantiated. Since the generic template is legal,
2396 -- do not perform this check in the instance to circumvent
2397 -- this oddity.
2398
2399 if In_Instance then
2400 null;
2401
2402 -- An abstract state with visible refinement cannot appear
2403 -- in pragma [Refined_]Global as its place must be taken by
2404 -- some of its constituents (SPARK RM 6.1.4(7)).
2405
2406 elsif Has_Visible_Refinement (Item_Id) then
2407 SPARK_Msg_NE
2408 ("cannot mention state & in global refinement",
2409 Item, Item_Id);
2410 SPARK_Msg_N ("\use its constituents instead", Item);
2411 return;
2412
2413 -- An external state cannot appear as a global item of a
2414 -- nonvolatile function (SPARK RM 7.1.3(8)).
2415
2416 elsif Is_External_State (Item_Id)
2417 and then Ekind (Spec_Id) in E_Function | E_Generic_Function
2418 and then not Is_Volatile_Function (Spec_Id)
2419 then
2420 SPARK_Msg_NE
2421 ("external state & cannot act as global item of "
2422 & "nonvolatile function", Item, Item_Id);
2423 return;
2424
2425 -- If the reference to the abstract state appears in an
2426 -- enclosing package body that will eventually refine the
2427 -- state, record the reference for future checks.
2428
2429 else
2430 Record_Possible_Body_Reference
2431 (State_Id => Item_Id,
2432 Ref => Item);
2433 end if;
2434
2435 -- Constant related checks
2436
2437 elsif Ekind (Item_Id) = E_Constant
2438 and then not Is_Access_Type (Etype (Item_Id))
2439 then
2440
2441 -- Unless it is of an access type, a constant is a read-only
2442 -- item, therefore it cannot act as an output.
2443
2444 if Global_Mode in Name_In_Out | Name_Output then
2445 SPARK_Msg_NE
2446 ("constant & cannot act as output", Item, Item_Id);
2447 return;
2448 end if;
2449
2450 -- Loop parameter related checks
2451
2452 elsif Ekind (Item_Id) = E_Loop_Parameter then
2453
2454 -- A loop parameter is a read-only item, therefore it cannot
2455 -- act as an output.
2456
2457 if Global_Mode in Name_In_Out | Name_Output then
2458 SPARK_Msg_NE
2459 ("loop parameter & cannot act as output",
2460 Item, Item_Id);
2461 return;
2462 end if;
2463
2464 -- Variable related checks. These are only relevant when
2465 -- SPARK_Mode is on as they are not standard Ada legality
2466 -- rules.
2467
2468 elsif SPARK_Mode = On
2469 and then Ekind (Item_Id) = E_Variable
2470 and then Is_Effectively_Volatile_For_Reading (Item_Id)
2471 then
2472 -- An effectively volatile object for reading cannot appear
2473 -- as a global item of a nonvolatile function (SPARK RM
2474 -- 7.1.3(8)).
2475
2476 if Ekind (Spec_Id) in E_Function | E_Generic_Function
2477 and then not Is_Volatile_Function (Spec_Id)
2478 then
2479 Error_Msg_NE
2480 ("volatile object & cannot act as global item of a "
2481 & "function", Item, Item_Id);
2482 return;
2483
2484 -- An effectively volatile object with external property
2485 -- Effective_Reads set to True must have mode Output or
2486 -- In_Out (SPARK RM 7.1.3(10)).
2487
2488 elsif Effective_Reads_Enabled (Item_Id)
2489 and then Global_Mode = Name_Input
2490 then
2491 Error_Msg_NE
2492 ("volatile object & with property Effective_Reads must "
2493 & "have mode In_Out or Output", Item, Item_Id);
2494 return;
2495 end if;
2496 end if;
2497
2498 -- When the item renames an entire object, replace the item
2499 -- with a reference to the object.
2500
2501 if Entity (Item) /= Item_Id then
2502 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2503 Analyze (Item);
2504 end if;
2505
2506 -- Some form of illegal construct masquerading as a name
2507 -- (SPARK RM 6.1.4(4)).
2508
2509 else
2510 Error_Msg_N
2511 ("global item must denote object, state or current instance "
2512 & "of concurrent type", Item);
2513 return;
2514 end if;
2515
2516 -- Verify that an output does not appear as an input in an
2517 -- enclosing subprogram.
2518
2519 if Global_Mode in Name_In_Out | Name_Output then
2520 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2521 end if;
2522
2523 -- The same entity might be referenced through various way.
2524 -- Check the entity of the item rather than the item itself
2525 -- (SPARK RM 6.1.4(10)).
2526
2527 if Contains (Seen, Item_Id) then
2528 SPARK_Msg_N ("duplicate global item", Item);
2529
2530 -- Add the entity of the current item to the list of processed
2531 -- items.
2532
2533 else
2534 Append_New_Elmt (Item_Id, Seen);
2535
2536 if Ekind (Item_Id) = E_Abstract_State then
2537 Append_New_Elmt (Item_Id, States_Seen);
2538
2539 -- The variable may eventually become a constituent of a single
2540 -- protected/task type. Record the reference now and verify its
2541 -- legality when analyzing the contract of the variable
2542 -- (SPARK RM 9.3).
2543
2544 elsif Ekind (Item_Id) = E_Variable then
2545 Record_Possible_Part_Of_Reference
2546 (Var_Id => Item_Id,
2547 Ref => Item);
2548 end if;
2549
2550 if Ekind (Item_Id) in E_Abstract_State | E_Constant | E_Variable
2551 and then Present (Encapsulating_State (Item_Id))
2552 then
2553 Append_New_Elmt (Item_Id, Constits_Seen);
2554 end if;
2555 end if;
2556 end Analyze_Global_Item;
2557
2558 --------------------------
2559 -- Check_Duplicate_Mode --
2560 --------------------------
2561
2562 procedure Check_Duplicate_Mode
2563 (Mode : Node_Id;
2564 Status : in out Boolean)
2565 is
2566 begin
2567 if Status then
2568 SPARK_Msg_N ("duplicate global mode", Mode);
2569 end if;
2570
2571 Status := True;
2572 end Check_Duplicate_Mode;
2573
2574 -------------------------------------------------
2575 -- Check_Mode_Restriction_In_Enclosing_Context --
2576 -------------------------------------------------
2577
2578 procedure Check_Mode_Restriction_In_Enclosing_Context
2579 (Item : Node_Id;
2580 Item_Id : Entity_Id)
2581 is
2582 Context : Entity_Id;
2583 Dummy : Boolean;
2584 Inputs : Elist_Id := No_Elist;
2585 Outputs : Elist_Id := No_Elist;
2586
2587 begin
2588 -- Traverse the scope stack looking for enclosing subprograms or
2589 -- tasks subject to pragma [Refined_]Global.
2590
2591 Context := Scope (Subp_Id);
2592 while Present (Context) and then Context /= Standard_Standard loop
2593
2594 -- For a single task type, retrieve the corresponding object to
2595 -- which pragma [Refined_]Global is attached.
2596
2597 if Ekind (Context) = E_Task_Type
2598 and then Is_Single_Concurrent_Type (Context)
2599 then
2600 Context := Anonymous_Object (Context);
2601 end if;
2602
2603 if (Is_Subprogram (Context)
2604 or else Ekind (Context) = E_Task_Type
2605 or else Is_Single_Task_Object (Context))
2606 and then
2607 (Present (Get_Pragma (Context, Pragma_Global))
2608 or else
2609 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2610 then
2611 Collect_Subprogram_Inputs_Outputs
2612 (Subp_Id => Context,
2613 Subp_Inputs => Inputs,
2614 Subp_Outputs => Outputs,
2615 Global_Seen => Dummy);
2616
2617 -- The item is classified as In_Out or Output but appears as
2618 -- an Input in an enclosing subprogram or task unit (SPARK
2619 -- RM 6.1.4(12)).
2620
2621 if Appears_In (Inputs, Item_Id)
2622 and then not Appears_In (Outputs, Item_Id)
2623 then
2624 SPARK_Msg_NE
2625 ("global item & cannot have mode In_Out or Output",
2626 Item, Item_Id);
2627
2628 if Is_Subprogram (Context) then
2629 SPARK_Msg_NE
2630 (Fix_Msg (Subp_Id, "\item already appears as input "
2631 & "of subprogram &"), Item, Context);
2632 else
2633 SPARK_Msg_NE
2634 (Fix_Msg (Subp_Id, "\item already appears as input "
2635 & "of task &"), Item, Context);
2636 end if;
2637
2638 -- Stop the traversal once an error has been detected
2639
2640 exit;
2641 end if;
2642 end if;
2643
2644 Context := Scope (Context);
2645 end loop;
2646 end Check_Mode_Restriction_In_Enclosing_Context;
2647
2648 ----------------------------------------
2649 -- Check_Mode_Restriction_In_Function --
2650 ----------------------------------------
2651
2652 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2653 begin
2654 if Ekind (Spec_Id) in E_Function | E_Generic_Function then
2655 SPARK_Msg_N
2656 ("global mode & is not applicable to functions", Mode);
2657 end if;
2658 end Check_Mode_Restriction_In_Function;
2659
2660 -- Local variables
2661
2662 Assoc : Node_Id;
2663 Item : Node_Id;
2664 Mode : Node_Id;
2665
2666 -- Start of processing for Analyze_Global_List
2667
2668 begin
2669 if Nkind (List) = N_Null then
2670 Set_Analyzed (List);
2671
2672 -- Single global item declaration
2673
2674 elsif Nkind (List) in N_Expanded_Name
2675 | N_Identifier
2676 | N_Selected_Component
2677 then
2678 Analyze_Global_Item (List, Global_Mode);
2679
2680 -- Simple global list or moded global list declaration
2681
2682 elsif Nkind (List) = N_Aggregate then
2683 Set_Analyzed (List);
2684
2685 -- The declaration of a simple global list appear as a collection
2686 -- of expressions.
2687
2688 if Present (Expressions (List)) then
2689 if Present (Component_Associations (List)) then
2690 SPARK_Msg_N
2691 ("cannot mix moded and non-moded global lists", List);
2692 end if;
2693
2694 Item := First (Expressions (List));
2695 while Present (Item) loop
2696 Analyze_Global_Item (Item, Global_Mode);
2697 Next (Item);
2698 end loop;
2699
2700 -- The declaration of a moded global list appears as a collection
2701 -- of component associations where individual choices denote
2702 -- modes.
2703
2704 elsif Present (Component_Associations (List)) then
2705 if Present (Expressions (List)) then
2706 SPARK_Msg_N
2707 ("cannot mix moded and non-moded global lists", List);
2708 end if;
2709
2710 Assoc := First (Component_Associations (List));
2711 while Present (Assoc) loop
2712 Mode := First (Choices (Assoc));
2713
2714 if Nkind (Mode) = N_Identifier then
2715 if Chars (Mode) = Name_In_Out then
2716 Check_Duplicate_Mode (Mode, In_Out_Seen);
2717 Check_Mode_Restriction_In_Function (Mode);
2718
2719 elsif Chars (Mode) = Name_Input then
2720 Check_Duplicate_Mode (Mode, Input_Seen);
2721
2722 elsif Chars (Mode) = Name_Output then
2723 Check_Duplicate_Mode (Mode, Output_Seen);
2724 Check_Mode_Restriction_In_Function (Mode);
2725
2726 elsif Chars (Mode) = Name_Proof_In then
2727 Check_Duplicate_Mode (Mode, Proof_Seen);
2728
2729 else
2730 SPARK_Msg_N ("invalid mode selector", Mode);
2731 end if;
2732
2733 else
2734 SPARK_Msg_N ("invalid mode selector", Mode);
2735 end if;
2736
2737 -- Items in a moded list appear as a collection of
2738 -- expressions. Reuse the existing machinery to analyze
2739 -- them.
2740
2741 Analyze_Global_List
2742 (List => Expression (Assoc),
2743 Global_Mode => Chars (Mode));
2744
2745 Next (Assoc);
2746 end loop;
2747
2748 -- Invalid tree
2749
2750 else
2751 raise Program_Error;
2752 end if;
2753
2754 -- Any other attempt to declare a global item is illegal. This is a
2755 -- syntax error, always report.
2756
2757 else
2758 Error_Msg_N ("malformed global list", List);
2759 end if;
2760 end Analyze_Global_List;
2761
2762 -- Local variables
2763
2764 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2765
2766 Restore_Scope : Boolean := False;
2767
2768 -- Start of processing for Analyze_Global_In_Decl_Part
2769
2770 begin
2771 -- Do not analyze the pragma multiple times
2772
2773 if Is_Analyzed_Pragma (N) then
2774 return;
2775 end if;
2776
2777 -- There is nothing to be done for a null global list
2778
2779 if Nkind (Items) = N_Null then
2780 Set_Analyzed (Items);
2781
2782 -- Analyze the various forms of global lists and items. Note that some
2783 -- of these may be malformed in which case the analysis emits error
2784 -- messages.
2785
2786 else
2787 -- When pragma [Refined_]Global appears on a single concurrent type,
2788 -- it is relocated to the anonymous object.
2789
2790 if Is_Single_Concurrent_Object (Spec_Id) then
2791 null;
2792
2793 -- Ensure that the formal parameters are visible when processing an
2794 -- item. This falls out of the general rule of aspects pertaining to
2795 -- subprogram declarations.
2796
2797 elsif not In_Open_Scopes (Spec_Id) then
2798 Restore_Scope := True;
2799 Push_Scope (Spec_Id);
2800
2801 if Ekind (Spec_Id) = E_Task_Type then
2802
2803 -- Task discriminants cannot appear in the [Refined_]Global
2804 -- contract, but must be present for the analysis so that we
2805 -- can reject them with an informative error message.
2806
2807 if Has_Discriminants (Spec_Id) then
2808 Install_Discriminants (Spec_Id);
2809 end if;
2810
2811 elsif Is_Generic_Subprogram (Spec_Id) then
2812 Install_Generic_Formals (Spec_Id);
2813
2814 else
2815 Install_Formals (Spec_Id);
2816 end if;
2817 end if;
2818
2819 Analyze_Global_List (Items);
2820
2821 if Restore_Scope then
2822 End_Scope;
2823 end if;
2824 end if;
2825
2826 -- Ensure that a state and a corresponding constituent do not appear
2827 -- together in pragma [Refined_]Global.
2828
2829 Check_State_And_Constituent_Use
2830 (States => States_Seen,
2831 Constits => Constits_Seen,
2832 Context => N);
2833
2834 Set_Is_Analyzed_Pragma (N);
2835 end Analyze_Global_In_Decl_Part;
2836
2837 --------------------------------------------
2838 -- Analyze_Initial_Condition_In_Decl_Part --
2839 --------------------------------------------
2840
2841 -- WARNING: This routine manages Ghost regions. Return statements must be
2842 -- replaced by gotos which jump to the end of the routine and restore the
2843 -- Ghost mode.
2844
2845 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2846 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2847 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2848 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2849
2850 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
2851 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
2852 -- Save the Ghost-related attributes to restore on exit
2853
2854 begin
2855 -- Do not analyze the pragma multiple times
2856
2857 if Is_Analyzed_Pragma (N) then
2858 return;
2859 end if;
2860
2861 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2862 -- analysis of the pragma, the Ghost mode at point of declaration and
2863 -- point of analysis may not necessarily be the same. Use the mode in
2864 -- effect at the point of declaration.
2865
2866 Set_Ghost_Mode (N);
2867
2868 -- The expression is preanalyzed because it has not been moved to its
2869 -- final place yet. A direct analysis may generate side effects and this
2870 -- is not desired at this point.
2871
2872 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2873 Set_Is_Analyzed_Pragma (N);
2874
2875 Restore_Ghost_Region (Saved_GM, Saved_IGR);
2876 end Analyze_Initial_Condition_In_Decl_Part;
2877
2878 --------------------------------------
2879 -- Analyze_Initializes_In_Decl_Part --
2880 --------------------------------------
2881
2882 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2883 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2884 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2885
2886 Constits_Seen : Elist_Id := No_Elist;
2887 -- A list containing the entities of all constituents processed so far.
2888 -- It aids in detecting illegal usage of a state and a corresponding
2889 -- constituent in pragma Initializes.
2890
2891 Items_Seen : Elist_Id := No_Elist;
2892 -- A list of all initialization items processed so far. This list is
2893 -- used to detect duplicate items.
2894
2895 States_And_Objs : Elist_Id := No_Elist;
2896 -- A list of all abstract states and objects declared in the visible
2897 -- declarations of the related package. This list is used to detect the
2898 -- legality of initialization items.
2899
2900 States_Seen : Elist_Id := No_Elist;
2901 -- A list containing the entities of all states processed so far. It
2902 -- helps in detecting illegal usage of a state and a corresponding
2903 -- constituent in pragma Initializes.
2904
2905 procedure Analyze_Initialization_Item (Item : Node_Id);
2906 -- Verify the legality of a single initialization item
2907
2908 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2909 -- Verify the legality of a single initialization item followed by a
2910 -- list of input items.
2911
2912 procedure Collect_States_And_Objects (Pack_Decl : Node_Id);
2913 -- Inspect the visible declarations of the related package and gather
2914 -- the entities of all abstract states and objects in States_And_Objs.
2915
2916 ---------------------------------
2917 -- Analyze_Initialization_Item --
2918 ---------------------------------
2919
2920 procedure Analyze_Initialization_Item (Item : Node_Id) is
2921 Item_Id : Entity_Id;
2922
2923 begin
2924 Analyze (Item);
2925 Resolve_State (Item);
2926
2927 if Is_Entity_Name (Item) then
2928 Item_Id := Entity_Of (Item);
2929
2930 if Present (Item_Id)
2931 and then Ekind (Item_Id) in
2932 E_Abstract_State | E_Constant | E_Variable
2933 then
2934 -- When the initialization item is undefined, it appears as
2935 -- Any_Id. Do not continue with the analysis of the item.
2936
2937 if Item_Id = Any_Id then
2938 null;
2939
2940 -- The state or variable must be declared in the visible
2941 -- declarations of the package (SPARK RM 7.1.5(7)).
2942
2943 elsif not Contains (States_And_Objs, Item_Id) then
2944 Error_Msg_Name_1 := Chars (Pack_Id);
2945 SPARK_Msg_NE
2946 ("initialization item & must appear in the visible "
2947 & "declarations of package %", Item, Item_Id);
2948
2949 -- Detect a duplicate use of the same initialization item
2950 -- (SPARK RM 7.1.5(5)).
2951
2952 elsif Contains (Items_Seen, Item_Id) then
2953 SPARK_Msg_N ("duplicate initialization item", Item);
2954
2955 -- The item is legal, add it to the list of processed states
2956 -- and variables.
2957
2958 else
2959 Append_New_Elmt (Item_Id, Items_Seen);
2960
2961 if Ekind (Item_Id) = E_Abstract_State then
2962 Append_New_Elmt (Item_Id, States_Seen);
2963 end if;
2964
2965 if Present (Encapsulating_State (Item_Id)) then
2966 Append_New_Elmt (Item_Id, Constits_Seen);
2967 end if;
2968 end if;
2969
2970 -- The item references something that is not a state or object
2971 -- (SPARK RM 7.1.5(3)).
2972
2973 else
2974 SPARK_Msg_N
2975 ("initialization item must denote object or state", Item);
2976 end if;
2977
2978 -- Some form of illegal construct masquerading as a name
2979 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2980
2981 else
2982 Error_Msg_N
2983 ("initialization item must denote object or state", Item);
2984 end if;
2985 end Analyze_Initialization_Item;
2986
2987 ---------------------------------------------
2988 -- Analyze_Initialization_Item_With_Inputs --
2989 ---------------------------------------------
2990
2991 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2992 Inputs_Seen : Elist_Id := No_Elist;
2993 -- A list of all inputs processed so far. This list is used to detect
2994 -- duplicate uses of an input.
2995
2996 Non_Null_Seen : Boolean := False;
2997 Null_Seen : Boolean := False;
2998 -- Flags used to check the legality of an input list
2999
3000 procedure Analyze_Input_Item (Input : Node_Id);
3001 -- Verify the legality of a single input item
3002
3003 ------------------------
3004 -- Analyze_Input_Item --
3005 ------------------------
3006
3007 procedure Analyze_Input_Item (Input : Node_Id) is
3008 Input_Id : Entity_Id;
3009
3010 begin
3011 -- Null input list
3012
3013 if Nkind (Input) = N_Null then
3014 if Null_Seen then
3015 SPARK_Msg_N
3016 ("multiple null initializations not allowed", Item);
3017
3018 elsif Non_Null_Seen then
3019 SPARK_Msg_N
3020 ("cannot mix null and non-null initialization item", Item);
3021 else
3022 Null_Seen := True;
3023 end if;
3024
3025 -- Input item
3026
3027 else
3028 Non_Null_Seen := True;
3029
3030 if Null_Seen then
3031 SPARK_Msg_N
3032 ("cannot mix null and non-null initialization item", Item);
3033 end if;
3034
3035 Analyze (Input);
3036 Resolve_State (Input);
3037
3038 if Is_Entity_Name (Input) then
3039 Input_Id := Entity_Of (Input);
3040
3041 if Present (Input_Id)
3042 and then Ekind (Input_Id) in E_Abstract_State
3043 | E_Constant
3044 | E_Generic_In_Out_Parameter
3045 | E_Generic_In_Parameter
3046 | E_In_Parameter
3047 | E_In_Out_Parameter
3048 | E_Out_Parameter
3049 | E_Protected_Type
3050 | E_Task_Type
3051 | E_Variable
3052 then
3053 -- The input cannot denote states or objects declared
3054 -- within the related package (SPARK RM 7.1.5(4)).
3055
3056 if Within_Scope (Input_Id, Current_Scope) then
3057
3058 -- Do not consider generic formal parameters or their
3059 -- respective mappings to generic formals. Even though
3060 -- the formals appear within the scope of the package,
3061 -- it is allowed for an initialization item to depend
3062 -- on an input item.
3063
3064 if Ekind (Input_Id) in E_Generic_In_Out_Parameter
3065 | E_Generic_In_Parameter
3066 then
3067 null;
3068
3069 elsif Ekind (Input_Id) in E_Constant | E_Variable
3070 and then Present (Corresponding_Generic_Association
3071 (Declaration_Node (Input_Id)))
3072 then
3073 null;
3074
3075 else
3076 Error_Msg_Name_1 := Chars (Pack_Id);
3077 SPARK_Msg_NE
3078 ("input item & cannot denote a visible object or "
3079 & "state of package %", Input, Input_Id);
3080 return;
3081 end if;
3082 end if;
3083
3084 -- Detect a duplicate use of the same input item
3085 -- (SPARK RM 7.1.5(5)).
3086
3087 if Contains (Inputs_Seen, Input_Id) then
3088 SPARK_Msg_N ("duplicate input item", Input);
3089 return;
3090 end if;
3091
3092 -- At this point it is known that the input is legal. Add
3093 -- it to the list of processed inputs.
3094
3095 Append_New_Elmt (Input_Id, Inputs_Seen);
3096
3097 if Ekind (Input_Id) = E_Abstract_State then
3098 Append_New_Elmt (Input_Id, States_Seen);
3099 end if;
3100
3101 if Ekind (Input_Id) in E_Abstract_State
3102 | E_Constant
3103 | E_Variable
3104 and then Present (Encapsulating_State (Input_Id))
3105 then
3106 Append_New_Elmt (Input_Id, Constits_Seen);
3107 end if;
3108
3109 -- The input references something that is not a state or an
3110 -- object (SPARK RM 7.1.5(3)).
3111
3112 else
3113 SPARK_Msg_N
3114 ("input item must denote object or state", Input);
3115 end if;
3116
3117 -- Some form of illegal construct masquerading as a name
3118 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
3119
3120 else
3121 Error_Msg_N
3122 ("input item must denote object or state", Input);
3123 end if;
3124 end if;
3125 end Analyze_Input_Item;
3126
3127 -- Local variables
3128
3129 Inputs : constant Node_Id := Expression (Item);
3130 Elmt : Node_Id;
3131 Input : Node_Id;
3132
3133 Name_Seen : Boolean := False;
3134 -- A flag used to detect multiple item names
3135
3136 -- Start of processing for Analyze_Initialization_Item_With_Inputs
3137
3138 begin
3139 -- Inspect the name of an item with inputs
3140
3141 Elmt := First (Choices (Item));
3142 while Present (Elmt) loop
3143 if Name_Seen then
3144 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
3145 else
3146 Name_Seen := True;
3147 Analyze_Initialization_Item (Elmt);
3148 end if;
3149
3150 Next (Elmt);
3151 end loop;
3152
3153 -- Multiple input items appear as an aggregate
3154
3155 if Nkind (Inputs) = N_Aggregate then
3156 if Present (Expressions (Inputs)) then
3157 Input := First (Expressions (Inputs));
3158 while Present (Input) loop
3159 Analyze_Input_Item (Input);
3160 Next (Input);
3161 end loop;
3162 end if;
3163
3164 if Present (Component_Associations (Inputs)) then
3165 SPARK_Msg_N
3166 ("inputs must appear in named association form", Inputs);
3167 end if;
3168
3169 -- Single input item
3170
3171 else
3172 Analyze_Input_Item (Inputs);
3173 end if;
3174 end Analyze_Initialization_Item_With_Inputs;
3175
3176 --------------------------------
3177 -- Collect_States_And_Objects --
3178 --------------------------------
3179
3180 procedure Collect_States_And_Objects (Pack_Decl : Node_Id) is
3181 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
3182 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
3183 Decl : Node_Id;
3184 State_Elmt : Elmt_Id;
3185
3186 begin
3187 -- Collect the abstract states defined in the package (if any)
3188
3189 if Has_Non_Null_Abstract_State (Pack_Id) then
3190 State_Elmt := First_Elmt (Abstract_States (Pack_Id));
3191 while Present (State_Elmt) loop
3192 Append_New_Elmt (Node (State_Elmt), States_And_Objs);
3193 Next_Elmt (State_Elmt);
3194 end loop;
3195 end if;
3196
3197 -- Collect all objects that appear in the visible declarations of the
3198 -- related package.
3199
3200 if Present (Visible_Declarations (Pack_Spec)) then
3201 Decl := First (Visible_Declarations (Pack_Spec));
3202 while Present (Decl) loop
3203 if Comes_From_Source (Decl)
3204 and then Nkind (Decl) in N_Object_Declaration
3205 | N_Object_Renaming_Declaration
3206 then
3207 Append_New_Elmt (Defining_Entity (Decl), States_And_Objs);
3208
3209 elsif Nkind (Decl) = N_Package_Declaration then
3210 Collect_States_And_Objects (Decl);
3211
3212 elsif Is_Single_Concurrent_Type_Declaration (Decl) then
3213 Append_New_Elmt
3214 (Anonymous_Object (Defining_Entity (Decl)),
3215 States_And_Objs);
3216 end if;
3217
3218 Next (Decl);
3219 end loop;
3220 end if;
3221 end Collect_States_And_Objects;
3222
3223 -- Local variables
3224
3225 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3226 Init : Node_Id;
3227
3228 -- Start of processing for Analyze_Initializes_In_Decl_Part
3229
3230 begin
3231 -- Do not analyze the pragma multiple times
3232
3233 if Is_Analyzed_Pragma (N) then
3234 return;
3235 end if;
3236
3237 -- Nothing to do when the initialization list is empty
3238
3239 if Nkind (Inits) = N_Null then
3240 return;
3241 end if;
3242
3243 -- Single and multiple initialization clauses appear as an aggregate. If
3244 -- this is not the case, then either the parser or the analysis of the
3245 -- pragma failed to produce an aggregate.
3246
3247 pragma Assert (Nkind (Inits) = N_Aggregate);
3248
3249 -- Initialize the various lists used during analysis
3250
3251 Collect_States_And_Objects (Pack_Decl);
3252
3253 if Present (Expressions (Inits)) then
3254 Init := First (Expressions (Inits));
3255 while Present (Init) loop
3256 Analyze_Initialization_Item (Init);
3257 Next (Init);
3258 end loop;
3259 end if;
3260
3261 if Present (Component_Associations (Inits)) then
3262 Init := First (Component_Associations (Inits));
3263 while Present (Init) loop
3264 Analyze_Initialization_Item_With_Inputs (Init);
3265 Next (Init);
3266 end loop;
3267 end if;
3268
3269 -- Ensure that a state and a corresponding constituent do not appear
3270 -- together in pragma Initializes.
3271
3272 Check_State_And_Constituent_Use
3273 (States => States_Seen,
3274 Constits => Constits_Seen,
3275 Context => N);
3276
3277 Set_Is_Analyzed_Pragma (N);
3278 end Analyze_Initializes_In_Decl_Part;
3279
3280 ---------------------
3281 -- Analyze_Part_Of --
3282 ---------------------
3283
3284 procedure Analyze_Part_Of
3285 (Indic : Node_Id;
3286 Item_Id : Entity_Id;
3287 Encap : Node_Id;
3288 Encap_Id : out Entity_Id;
3289 Legal : out Boolean)
3290 is
3291 procedure Check_Part_Of_Abstract_State;
3292 pragma Inline (Check_Part_Of_Abstract_State);
3293 -- Verify the legality of indicator Part_Of when the encapsulator is an
3294 -- abstract state.
3295
3296 procedure Check_Part_Of_Concurrent_Type;
3297 pragma Inline (Check_Part_Of_Concurrent_Type);
3298 -- Verify the legality of indicator Part_Of when the encapsulator is a
3299 -- single concurrent type.
3300
3301 ----------------------------------
3302 -- Check_Part_Of_Abstract_State --
3303 ----------------------------------
3304
3305 procedure Check_Part_Of_Abstract_State is
3306 Pack_Id : Entity_Id;
3307 Placement : State_Space_Kind;
3308 Parent_Unit : Entity_Id;
3309
3310 begin
3311 -- Determine where the object, package instantiation or state lives
3312 -- with respect to the enclosing packages or package bodies.
3313
3314 Find_Placement_In_State_Space
3315 (Item_Id => Item_Id,
3316 Placement => Placement,
3317 Pack_Id => Pack_Id);
3318
3319 -- The item appears in a non-package construct with a declarative
3320 -- part (subprogram, block, etc). As such, the item is not allowed
3321 -- to be a part of an encapsulating state because the item is not
3322 -- visible.
3323
3324 if Placement = Not_In_Package then
3325 SPARK_Msg_N
3326 ("indicator Part_Of cannot appear in this context "
3327 & "(SPARK RM 7.2.6(5))", Indic);
3328
3329 Error_Msg_Name_1 := Chars (Scope (Encap_Id));
3330 SPARK_Msg_NE
3331 ("\& is not part of the hidden state of package %",
3332 Indic, Item_Id);
3333 return;
3334
3335 -- The item appears in the visible state space of some package. In
3336 -- general this scenario does not warrant Part_Of except when the
3337 -- package is a nongeneric private child unit and the encapsulating
3338 -- state is declared in a parent unit or a public descendant of that
3339 -- parent unit.
3340
3341 elsif Placement = Visible_State_Space then
3342 if Is_Child_Unit (Pack_Id)
3343 and then not Is_Generic_Unit (Pack_Id)
3344 and then Is_Private_Descendant (Pack_Id)
3345 then
3346 -- A variable or state abstraction which is part of the visible
3347 -- state of a nongeneric private child unit or its public
3348 -- descendants must have its Part_Of indicator specified. The
3349 -- Part_Of indicator must denote a state declared by either the
3350 -- parent unit of the private unit or by a public descendant of
3351 -- that parent unit.
3352
3353 -- Find the nearest private ancestor (which can be the current
3354 -- unit itself).
3355
3356 Parent_Unit := Pack_Id;
3357 while Present (Parent_Unit) loop
3358 exit when
3359 Private_Present
3360 (Parent (Unit_Declaration_Node (Parent_Unit)));
3361 Parent_Unit := Scope (Parent_Unit);
3362 end loop;
3363
3364 Parent_Unit := Scope (Parent_Unit);
3365
3366 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
3367 SPARK_Msg_NE
3368 ("indicator Part_Of must denote abstract state of & or of "
3369 & "its public descendant (SPARK RM 7.2.6(3))",
3370 Indic, Parent_Unit);
3371 return;
3372
3373 elsif Scope (Encap_Id) = Parent_Unit
3374 or else
3375 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id))
3376 and then not Is_Private_Descendant (Scope (Encap_Id)))
3377 then
3378 null;
3379
3380 else
3381 SPARK_Msg_NE
3382 ("indicator Part_Of must denote abstract state of & or of "
3383 & "its public descendant (SPARK RM 7.2.6(3))",
3384 Indic, Parent_Unit);
3385 return;
3386 end if;
3387
3388 -- Indicator Part_Of is not needed when the related package is
3389 -- not a nongeneric private child unit or a public descendant
3390 -- thereof.
3391
3392 else
3393 SPARK_Msg_N
3394 ("indicator Part_Of cannot appear in this context "
3395 & "(SPARK RM 7.2.6(5))", Indic);
3396
3397 Error_Msg_Name_1 := Chars (Pack_Id);
3398 SPARK_Msg_NE
3399 ("\& is declared in the visible part of package %",
3400 Indic, Item_Id);
3401 return;
3402 end if;
3403
3404 -- When the item appears in the private state space of a package, the
3405 -- encapsulating state must be declared in the same package.
3406
3407 elsif Placement = Private_State_Space then
3408 if Scope (Encap_Id) /= Pack_Id then
3409 SPARK_Msg_NE
3410 ("indicator Part_Of must denote an abstract state of "
3411 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3412
3413 Error_Msg_Name_1 := Chars (Pack_Id);
3414 SPARK_Msg_NE
3415 ("\& is declared in the private part of package %",
3416 Indic, Item_Id);
3417 return;
3418 end if;
3419
3420 -- Items declared in the body state space of a package do not need
3421 -- Part_Of indicators as the refinement has already been seen.
3422
3423 else
3424 SPARK_Msg_N
3425 ("indicator Part_Of cannot appear in this context "
3426 & "(SPARK RM 7.2.6(5))", Indic);
3427
3428 if Scope (Encap_Id) = Pack_Id then
3429 Error_Msg_Name_1 := Chars (Pack_Id);
3430 SPARK_Msg_NE
3431 ("\& is declared in the body of package %", Indic, Item_Id);
3432 end if;
3433
3434 return;
3435 end if;
3436
3437 -- At this point it is known that the Part_Of indicator is legal
3438
3439 Legal := True;
3440 end Check_Part_Of_Abstract_State;
3441
3442 -----------------------------------
3443 -- Check_Part_Of_Concurrent_Type --
3444 -----------------------------------
3445
3446 procedure Check_Part_Of_Concurrent_Type is
3447 function In_Proper_Order
3448 (First : Node_Id;
3449 Second : Node_Id) return Boolean;
3450 pragma Inline (In_Proper_Order);
3451 -- Determine whether node First precedes node Second
3452
3453 procedure Placement_Error;
3454 pragma Inline (Placement_Error);
3455 -- Emit an error concerning the illegal placement of the item with
3456 -- respect to the single concurrent type.
3457
3458 ---------------------
3459 -- In_Proper_Order --
3460 ---------------------
3461
3462 function In_Proper_Order
3463 (First : Node_Id;
3464 Second : Node_Id) return Boolean
3465 is
3466 N : Node_Id;
3467
3468 begin
3469 if List_Containing (First) = List_Containing (Second) then
3470 N := First;
3471 while Present (N) loop
3472 if N = Second then
3473 return True;
3474 end if;
3475
3476 Next (N);
3477 end loop;
3478 end if;
3479
3480 return False;
3481 end In_Proper_Order;
3482
3483 ---------------------
3484 -- Placement_Error --
3485 ---------------------
3486
3487 procedure Placement_Error is
3488 begin
3489 SPARK_Msg_N
3490 ("indicator Part_Of must denote a previously declared single "
3491 & "protected type or single task type", Encap);
3492 end Placement_Error;
3493
3494 -- Local variables
3495
3496 Conc_Typ : constant Entity_Id := Etype (Encap_Id);
3497 Encap_Decl : constant Node_Id := Declaration_Node (Encap_Id);
3498 Encap_Context : constant Node_Id := Parent (Encap_Decl);
3499
3500 Item_Context : Node_Id;
3501 Item_Decl : Node_Id;
3502 Prv_Decls : List_Id;
3503 Vis_Decls : List_Id;
3504
3505 -- Start of processing for Check_Part_Of_Concurrent_Type
3506
3507 begin
3508 -- Only abstract states and variables can act as constituents of an
3509 -- encapsulating single concurrent type.
3510
3511 if Ekind (Item_Id) in E_Abstract_State | E_Variable then
3512 null;
3513
3514 -- The constituent is a constant
3515
3516 elsif Ekind (Item_Id) = E_Constant then
3517 Error_Msg_Name_1 := Chars (Encap_Id);
3518 SPARK_Msg_NE
3519 (Fix_Msg (Conc_Typ, "constant & cannot act as constituent of "
3520 & "single protected type %"), Indic, Item_Id);
3521 return;
3522
3523 -- The constituent is a package instantiation
3524
3525 else
3526 Error_Msg_Name_1 := Chars (Encap_Id);
3527 SPARK_Msg_NE
3528 (Fix_Msg (Conc_Typ, "package instantiation & cannot act as "
3529 & "constituent of single protected type %"), Indic, Item_Id);
3530 return;
3531 end if;
3532
3533 -- When the item denotes an abstract state of a nested package, use
3534 -- the declaration of the package to detect proper placement.
3535
3536 -- package Pack is
3537 -- task T;
3538 -- package Nested
3539 -- with Abstract_State => (State with Part_Of => T)
3540
3541 if Ekind (Item_Id) = E_Abstract_State then
3542 Item_Decl := Unit_Declaration_Node (Scope (Item_Id));
3543 else
3544 Item_Decl := Declaration_Node (Item_Id);
3545 end if;
3546
3547 Item_Context := Parent (Item_Decl);
3548
3549 -- The item and the single concurrent type must appear in the same
3550 -- declarative region, with the item following the declaration of
3551 -- the single concurrent type (SPARK RM 9(3)).
3552
3553 if Item_Context = Encap_Context then
3554 if Nkind (Item_Context) in N_Package_Specification
3555 | N_Protected_Definition
3556 | N_Task_Definition
3557 then
3558 Prv_Decls := Private_Declarations (Item_Context);
3559 Vis_Decls := Visible_Declarations (Item_Context);
3560
3561 -- The placement is OK when the single concurrent type appears
3562 -- within the visible declarations and the item in the private
3563 -- declarations.
3564 --
3565 -- package Pack is
3566 -- protected PO ...
3567 -- private
3568 -- Constit : ... with Part_Of => PO;
3569 -- end Pack;
3570
3571 if List_Containing (Encap_Decl) = Vis_Decls
3572 and then List_Containing (Item_Decl) = Prv_Decls
3573 then
3574 null;
3575
3576 -- The placement is illegal when the item appears within the
3577 -- visible declarations and the single concurrent type is in
3578 -- the private declarations.
3579 --
3580 -- package Pack is
3581 -- Constit : ... with Part_Of => PO;
3582 -- private
3583 -- protected PO ...
3584 -- end Pack;
3585
3586 elsif List_Containing (Item_Decl) = Vis_Decls
3587 and then List_Containing (Encap_Decl) = Prv_Decls
3588 then
3589 Placement_Error;
3590 return;
3591
3592 -- Otherwise both the item and the single concurrent type are
3593 -- in the same list. Ensure that the declaration of the single
3594 -- concurrent type precedes that of the item.
3595
3596 elsif not In_Proper_Order
3597 (First => Encap_Decl,
3598 Second => Item_Decl)
3599 then
3600 Placement_Error;
3601 return;
3602 end if;
3603
3604 -- Otherwise both the item and the single concurrent type are
3605 -- in the same list. Ensure that the declaration of the single
3606 -- concurrent type precedes that of the item.
3607
3608 elsif not In_Proper_Order
3609 (First => Encap_Decl,
3610 Second => Item_Decl)
3611 then
3612 Placement_Error;
3613 return;
3614 end if;
3615
3616 -- Otherwise the item and the single concurrent type reside within
3617 -- unrelated regions.
3618
3619 else
3620 Error_Msg_Name_1 := Chars (Encap_Id);
3621 SPARK_Msg_NE
3622 (Fix_Msg (Conc_Typ, "constituent & must be declared "
3623 & "immediately within the same region as single protected "
3624 & "type %"), Indic, Item_Id);
3625 return;
3626 end if;
3627
3628 -- At this point it is known that the Part_Of indicator is legal
3629
3630 Legal := True;
3631 end Check_Part_Of_Concurrent_Type;
3632
3633 -- Start of processing for Analyze_Part_Of
3634
3635 begin
3636 -- Assume that the indicator is illegal
3637
3638 Encap_Id := Empty;
3639 Legal := False;
3640
3641 if Nkind (Encap) in
3642 N_Expanded_Name | N_Identifier | N_Selected_Component
3643 then
3644 Analyze (Encap);
3645 Resolve_State (Encap);
3646
3647 Encap_Id := Entity (Encap);
3648
3649 -- The encapsulator is an abstract state
3650
3651 if Ekind (Encap_Id) = E_Abstract_State then
3652 null;
3653
3654 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3655
3656 elsif Is_Single_Concurrent_Object (Encap_Id) then
3657 null;
3658
3659 -- Otherwise the encapsulator is not a legal choice
3660
3661 else
3662 SPARK_Msg_N
3663 ("indicator Part_Of must denote abstract state, single "
3664 & "protected type or single task type", Encap);
3665 return;
3666 end if;
3667
3668 -- This is a syntax error, always report
3669
3670 else
3671 Error_Msg_N
3672 ("indicator Part_Of must denote abstract state, single protected "
3673 & "type or single task type", Encap);
3674 return;
3675 end if;
3676
3677 -- Catch a case where indicator Part_Of denotes the abstract view of a
3678 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3679
3680 if From_Limited_With (Encap_Id)
3681 and then Present (Non_Limited_View (Encap_Id))
3682 and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable
3683 then
3684 SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap);
3685 SPARK_Msg_N ("\& denotes abstract view of object", Encap);
3686 return;
3687 end if;
3688
3689 -- The encapsulator is an abstract state
3690
3691 if Ekind (Encap_Id) = E_Abstract_State then
3692 Check_Part_Of_Abstract_State;
3693
3694 -- The encapsulator is a single concurrent type
3695
3696 else
3697 Check_Part_Of_Concurrent_Type;
3698 end if;
3699 end Analyze_Part_Of;
3700
3701 ----------------------------------
3702 -- Analyze_Part_Of_In_Decl_Part --
3703 ----------------------------------
3704
3705 procedure Analyze_Part_Of_In_Decl_Part
3706 (N : Node_Id;
3707 Freeze_Id : Entity_Id := Empty)
3708 is
3709 Encap : constant Node_Id :=
3710 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
3711 Errors : constant Nat := Serious_Errors_Detected;
3712 Var_Decl : constant Node_Id := Find_Related_Context (N);
3713 Var_Id : constant Entity_Id := Defining_Entity (Var_Decl);
3714 Constits : Elist_Id;
3715 Encap_Id : Entity_Id;
3716 Legal : Boolean;
3717
3718 begin
3719 -- Detect any discrepancies between the placement of the variable with
3720 -- respect to general state space and the encapsulating state or single
3721 -- concurrent type.
3722
3723 Analyze_Part_Of
3724 (Indic => N,
3725 Item_Id => Var_Id,
3726 Encap => Encap,
3727 Encap_Id => Encap_Id,
3728 Legal => Legal);
3729
3730 -- The Part_Of indicator turns the variable into a constituent of the
3731 -- encapsulating state or single concurrent type.
3732
3733 if Legal then
3734 pragma Assert (Present (Encap_Id));
3735 Constits := Part_Of_Constituents (Encap_Id);
3736
3737 if No (Constits) then
3738 Constits := New_Elmt_List;
3739 Set_Part_Of_Constituents (Encap_Id, Constits);
3740 end if;
3741
3742 Append_Elmt (Var_Id, Constits);
3743 Set_Encapsulating_State (Var_Id, Encap_Id);
3744
3745 -- A Part_Of constituent partially refines an abstract state. This
3746 -- property does not apply to protected or task units.
3747
3748 if Ekind (Encap_Id) = E_Abstract_State then
3749 Set_Has_Partial_Visible_Refinement (Encap_Id);
3750 end if;
3751 end if;
3752
3753 -- Emit a clarification message when the encapsulator is undefined,
3754 -- possibly due to contract freezing.
3755
3756 if Errors /= Serious_Errors_Detected
3757 and then Present (Freeze_Id)
3758 and then Has_Undefined_Reference (Encap)
3759 then
3760 Contract_Freeze_Error (Var_Id, Freeze_Id);
3761 end if;
3762 end Analyze_Part_Of_In_Decl_Part;
3763
3764 --------------------
3765 -- Analyze_Pragma --
3766 --------------------
3767
3768 procedure Analyze_Pragma (N : Node_Id) is
3769 Loc : constant Source_Ptr := Sloc (N);
3770
3771 Pname : Name_Id := Pragma_Name (N);
3772 -- Name of the source pragma, or name of the corresponding aspect for
3773 -- pragmas which originate in a source aspect. In the latter case, the
3774 -- name may be different from the pragma name.
3775
3776 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
3777
3778 Pragma_Exit : exception;
3779 -- This exception is used to exit pragma processing completely. It
3780 -- is used when an error is detected, and no further processing is
3781 -- required. It is also used if an earlier error has left the tree in
3782 -- a state where the pragma should not be processed.
3783
3784 Arg_Count : Nat;
3785 -- Number of pragma argument associations
3786
3787 Arg1 : Node_Id;
3788 Arg2 : Node_Id;
3789 Arg3 : Node_Id;
3790 Arg4 : Node_Id;
3791 Arg5 : Node_Id;
3792 -- First five pragma arguments (pragma argument association nodes, or
3793 -- Empty if the corresponding argument does not exist).
3794
3795 type Name_List is array (Natural range <>) of Name_Id;
3796 type Args_List is array (Natural range <>) of Node_Id;
3797 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3798
3799 -----------------------
3800 -- Local Subprograms --
3801 -----------------------
3802
3803 procedure Ada_2005_Pragma;
3804 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3805 -- Ada 95 mode, these are implementation defined pragmas, so should be
3806 -- caught by the No_Implementation_Pragmas restriction.
3807
3808 procedure Ada_2012_Pragma;
3809 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3810 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3811 -- should be caught by the No_Implementation_Pragmas restriction.
3812
3813 procedure Analyze_Depends_Global
3814 (Spec_Id : out Entity_Id;
3815 Subp_Decl : out Node_Id;
3816 Legal : out Boolean);
3817 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3818 -- legality of the placement and related context of the pragma. Spec_Id
3819 -- is the entity of the related subprogram. Subp_Decl is the declaration
3820 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3821
3822 procedure Analyze_If_Present (Id : Pragma_Id);
3823 -- Inspect the remainder of the list containing pragma N and look for
3824 -- a pragma that matches Id. If found, analyze the pragma.
3825
3826 procedure Analyze_Pre_Post_Condition;
3827 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3828
3829 procedure Analyze_Refined_Depends_Global_Post
3830 (Spec_Id : out Entity_Id;
3831 Body_Id : out Entity_Id;
3832 Legal : out Boolean);
3833 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3834 -- Refined_Global and Refined_Post. Verify the legality of the placement
3835 -- and related context of the pragma. Spec_Id is the entity of the
3836 -- related subprogram. Body_Id is the entity of the subprogram body.
3837 -- Flag Legal is set when the pragma is legal.
3838
3839 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False);
3840 -- Perform full analysis of pragma Unmodified and the write aspect of
3841 -- pragma Unused. Flag Is_Unused should be set when verifying the
3842 -- semantics of pragma Unused.
3843
3844 procedure Analyze_Unreferenced_Or_Unused (Is_Unused : Boolean := False);
3845 -- Perform full analysis of pragma Unreferenced and the read aspect of
3846 -- pragma Unused. Flag Is_Unused should be set when verifying the
3847 -- semantics of pragma Unused.
3848
3849 procedure Check_Ada_83_Warning;
3850 -- Issues a warning message for the current pragma if operating in Ada
3851 -- 83 mode (used for language pragmas that are not a standard part of
3852 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3853 -- of 95 pragma.
3854
3855 procedure Check_Arg_Count (Required : Nat);
3856 -- Check argument count for pragma is equal to given parameter. If not,
3857 -- then issue an error message and raise Pragma_Exit.
3858
3859 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3860 -- Arg which can either be a pragma argument association, in which case
3861 -- the check is applied to the expression of the association or an
3862 -- expression directly.
3863
3864 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
3865 -- Check that an argument has the right form for an EXTERNAL_NAME
3866 -- parameter of an extended import/export pragma. The rule is that the
3867 -- name must be an identifier or string literal (in Ada 83 mode) or a
3868 -- static string expression (in Ada 95 mode).
3869
3870 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
3871 -- Check the specified argument Arg to make sure that it is an
3872 -- identifier. If not give error and raise Pragma_Exit.
3873
3874 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
3875 -- Check the specified argument Arg to make sure that it is an integer
3876 -- literal. If not give error and raise Pragma_Exit.
3877
3878 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
3879 -- Check the specified argument Arg to make sure that it has the proper
3880 -- syntactic form for a local name and meets the semantic requirements
3881 -- for a local name. The local name is analyzed as part of the
3882 -- processing for this call. In addition, the local name is required
3883 -- to represent an entity at the library level.
3884
3885 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
3886 -- Check the specified argument Arg to make sure that it has the proper
3887 -- syntactic form for a local name and meets the semantic requirements
3888 -- for a local name. The local name is analyzed as part of the
3889 -- processing for this call.
3890
3891 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
3892 -- Check the specified argument Arg to make sure that it is a valid
3893 -- locking policy name. If not give error and raise Pragma_Exit.
3894
3895 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
3896 -- Check the specified argument Arg to make sure that it is a valid
3897 -- elaboration policy name. If not give error and raise Pragma_Exit.
3898
3899 procedure Check_Arg_Is_One_Of
3900 (Arg : Node_Id;
3901 N1, N2 : Name_Id);
3902 procedure Check_Arg_Is_One_Of
3903 (Arg : Node_Id;
3904 N1, N2, N3 : Name_Id);
3905 procedure Check_Arg_Is_One_Of
3906 (Arg : Node_Id;
3907 N1, N2, N3, N4 : Name_Id);
3908 procedure Check_Arg_Is_One_Of
3909 (Arg : Node_Id;
3910 N1, N2, N3, N4, N5 : Name_Id);
3911 -- Check the specified argument Arg to make sure that it is an
3912 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3913 -- present). If not then give error and raise Pragma_Exit.
3914
3915 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
3916 -- Check the specified argument Arg to make sure that it is a valid
3917 -- queuing policy name. If not give error and raise Pragma_Exit.
3918
3919 procedure Check_Arg_Is_OK_Static_Expression
3920 (Arg : Node_Id;
3921 Typ : Entity_Id := Empty);
3922 -- Check the specified argument Arg to make sure that it is a static
3923 -- expression of the given type (i.e. it will be analyzed and resolved
3924 -- using this type, which can be any valid argument to Resolve, e.g.
3925 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3926 -- Typ is left Empty, then any static expression is allowed. Includes
3927 -- checking that the argument does not raise Constraint_Error.
3928
3929 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
3930 -- Check the specified argument Arg to make sure that it is a valid task
3931 -- dispatching policy name. If not give error and raise Pragma_Exit.
3932
3933 procedure Check_Arg_Order (Names : Name_List);
3934 -- Checks for an instance of two arguments with identifiers for the
3935 -- current pragma which are not in the sequence indicated by Names,
3936 -- and if so, generates a fatal message about bad order of arguments.
3937
3938 procedure Check_At_Least_N_Arguments (N : Nat);
3939 -- Check there are at least N arguments present
3940
3941 procedure Check_At_Most_N_Arguments (N : Nat);
3942 -- Check there are no more than N arguments present
3943
3944 procedure Check_Atomic_VFA (E : Entity_Id; VFA : Boolean);
3945 -- Apply legality checks to type or object E subject to an Atomic aspect
3946 -- in Ada 2020 (RM C.6(13)) or to a Volatile_Full_Access aspect.
3947
3948 procedure Check_Component
3949 (Comp : Node_Id;
3950 UU_Typ : Entity_Id;
3951 In_Variant_Part : Boolean := False);
3952 -- Examine an Unchecked_Union component for correct use of per-object
3953 -- constrained subtypes, and for restrictions on finalizable components.
3954 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3955 -- should be set when Comp comes from a record variant.
3956
3957 procedure Check_Duplicate_Pragma (E : Entity_Id);
3958 -- Check if a rep item of the same name as the current pragma is already
3959 -- chained as a rep pragma to the given entity. If so give a message
3960 -- about the duplicate, and then raise Pragma_Exit so does not return.
3961 -- Note that if E is a type, then this routine avoids flagging a pragma
3962 -- which applies to a parent type from which E is derived.
3963
3964 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
3965 -- Nam is an N_String_Literal node containing the external name set by
3966 -- an Import or Export pragma (or extended Import or Export pragma).
3967 -- This procedure checks for possible duplications if this is the export
3968 -- case, and if found, issues an appropriate error message.
3969
3970 procedure Check_Expr_Is_OK_Static_Expression
3971 (Expr : Node_Id;
3972 Typ : Entity_Id := Empty);
3973 -- Check the specified expression Expr to make sure that it is a static
3974 -- expression of the given type (i.e. it will be analyzed and resolved
3975 -- using this type, which can be any valid argument to Resolve, e.g.
3976 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3977 -- Typ is left Empty, then any static expression is allowed. Includes
3978 -- checking that the expression does not raise Constraint_Error.
3979
3980 procedure Check_First_Subtype (Arg : Node_Id);
3981 -- Checks that Arg, whose expression is an entity name, references a
3982 -- first subtype.
3983
3984 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
3985 -- Checks that the given argument has an identifier, and if so, requires
3986 -- it to match the given identifier name. If there is no identifier, or
3987 -- a non-matching identifier, then an error message is given and
3988 -- Pragma_Exit is raised.
3989
3990 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
3991 -- Checks that the given argument has an identifier, and if so, requires
3992 -- it to match one of the given identifier names. If there is no
3993 -- identifier, or a non-matching identifier, then an error message is
3994 -- given and Pragma_Exit is raised.
3995
3996 procedure Check_In_Main_Program;
3997 -- Common checks for pragmas that appear within a main program
3998 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3999
4000 procedure Check_Interrupt_Or_Attach_Handler;
4001 -- Common processing for first argument of pragma Interrupt_Handler or
4002 -- pragma Attach_Handler.
4003
4004 procedure Check_Loop_Pragma_Placement;
4005 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
4006 -- appear immediately within a construct restricted to loops, and that
4007 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
4008
4009 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
4010 -- Check that pragma appears in a declarative part, or in a package
4011 -- specification, i.e. that it does not occur in a statement sequence
4012 -- in a body.
4013
4014 procedure Check_No_Identifier (Arg : Node_Id);
4015 -- Checks that the given argument does not have an identifier. If
4016 -- an identifier is present, then an error message is issued, and
4017 -- Pragma_Exit is raised.
4018
4019 procedure Check_No_Identifiers;
4020 -- Checks that none of the arguments to the pragma has an identifier.
4021 -- If any argument has an identifier, then an error message is issued,
4022 -- and Pragma_Exit is raised.
4023
4024 procedure Check_No_Link_Name;
4025 -- Checks that no link name is specified
4026
4027 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
4028 -- Checks if the given argument has an identifier, and if so, requires
4029 -- it to match the given identifier name. If there is a non-matching
4030 -- identifier, then an error message is given and Pragma_Exit is raised.
4031
4032 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
4033 -- Checks if the given argument has an identifier, and if so, requires
4034 -- it to match the given identifier name. If there is a non-matching
4035 -- identifier, then an error message is given and Pragma_Exit is raised.
4036 -- In this version of the procedure, the identifier name is given as
4037 -- a string with lower case letters.
4038
4039 procedure Check_Static_Boolean_Expression (Expr : Node_Id);
4040 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
4041 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
4042 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
4043 -- is an OK static boolean expression. Emit an error if this is not the
4044 -- case.
4045
4046 procedure Check_Static_Constraint (Constr : Node_Id);
4047 -- Constr is a constraint from an N_Subtype_Indication node from a
4048 -- component constraint in an Unchecked_Union type. This routine checks
4049 -- that the constraint is static as required by the restrictions for
4050 -- Unchecked_Union.
4051
4052 procedure Check_Valid_Configuration_Pragma;
4053 -- Legality checks for placement of a configuration pragma
4054
4055 procedure Check_Valid_Library_Unit_Pragma;
4056 -- Legality checks for library unit pragmas. A special case arises for
4057 -- pragmas in generic instances that come from copies of the original
4058 -- library unit pragmas in the generic templates. In the case of other
4059 -- than library level instantiations these can appear in contexts which
4060 -- would normally be invalid (they only apply to the original template
4061 -- and to library level instantiations), and they are simply ignored,
4062 -- which is implemented by rewriting them as null statements.
4063
4064 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
4065 -- Check an Unchecked_Union variant for lack of nested variants and
4066 -- presence of at least one component. UU_Typ is the related Unchecked_
4067 -- Union type.
4068
4069 procedure Ensure_Aggregate_Form (Arg : Node_Id);
4070 -- Subsidiary routine to the processing of pragmas Abstract_State,
4071 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
4072 -- Refined_Global and Refined_State. Transform argument Arg into
4073 -- an aggregate if not one already. N_Null is never transformed.
4074 -- Arg may denote an aspect specification or a pragma argument
4075 -- association.
4076
4077 procedure Error_Pragma (Msg : String);
4078 pragma No_Return (Error_Pragma);
4079 -- Outputs error message for current pragma. The message contains a %
4080 -- that will be replaced with the pragma name, and the flag is placed
4081 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
4082 -- calls Fix_Error (see spec of that procedure for details).
4083
4084 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
4085 pragma No_Return (Error_Pragma_Arg);
4086 -- Outputs error message for current pragma. The message may contain
4087 -- a % that will be replaced with the pragma name. The parameter Arg
4088 -- may either be a pragma argument association, in which case the flag
4089 -- is placed on the expression of this association, or an expression,
4090 -- in which case the flag is placed directly on the expression. The
4091 -- message is placed using Error_Msg_N, so the message may also contain
4092 -- an & insertion character which will reference the given Arg value.
4093 -- After placing the message, Pragma_Exit is raised. Note: this routine
4094 -- calls Fix_Error (see spec of that procedure for details).
4095
4096 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
4097 pragma No_Return (Error_Pragma_Arg);
4098 -- Similar to above form of Error_Pragma_Arg except that two messages
4099 -- are provided, the second is a continuation comment starting with \.
4100
4101 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
4102 pragma No_Return (Error_Pragma_Arg_Ident);
4103 -- Outputs error message for current pragma. The message may contain a %
4104 -- that will be replaced with the pragma name. The parameter Arg must be
4105 -- a pragma argument association with a non-empty identifier (i.e. its
4106 -- Chars field must be set), and the error message is placed on the
4107 -- identifier. The message is placed using Error_Msg_N so the message
4108 -- may also contain an & insertion character which will reference
4109 -- the identifier. After placing the message, Pragma_Exit is raised.
4110 -- Note: this routine calls Fix_Error (see spec of that procedure for
4111 -- details).
4112
4113 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
4114 pragma No_Return (Error_Pragma_Ref);
4115 -- Outputs error message for current pragma. The message may contain
4116 -- a % that will be replaced with the pragma name. The parameter Ref
4117 -- must be an entity whose name can be referenced by & and sloc by #.
4118 -- After placing the message, Pragma_Exit is raised. Note: this routine
4119 -- calls Fix_Error (see spec of that procedure for details).
4120
4121 function Find_Lib_Unit_Name return Entity_Id;
4122 -- Used for a library unit pragma to find the entity to which the
4123 -- library unit pragma applies, returns the entity found.
4124
4125 procedure Find_Program_Unit_Name (Id : Node_Id);
4126 -- If the pragma is a compilation unit pragma, the id must denote the
4127 -- compilation unit in the same compilation, and the pragma must appear
4128 -- in the list of preceding or trailing pragmas. If it is a program
4129 -- unit pragma that is not a compilation unit pragma, then the
4130 -- identifier must be visible.
4131
4132 function Find_Unique_Parameterless_Procedure
4133 (Name : Entity_Id;
4134 Arg : Node_Id) return Entity_Id;
4135 -- Used for a procedure pragma to find the unique parameterless
4136 -- procedure identified by Name, returns it if it exists, otherwise
4137 -- errors out and uses Arg as the pragma argument for the message.
4138
4139 function Fix_Error (Msg : String) return String;
4140 -- This is called prior to issuing an error message. Msg is the normal
4141 -- error message issued in the pragma case. This routine checks for the
4142 -- case of a pragma coming from an aspect in the source, and returns a
4143 -- message suitable for the aspect case as follows:
4144 --
4145 -- Each substring "pragma" is replaced by "aspect"
4146 --
4147 -- If "argument of" is at the start of the error message text, it is
4148 -- replaced by "entity for".
4149 --
4150 -- If "argument" is at the start of the error message text, it is
4151 -- replaced by "entity".
4152 --
4153 -- So for example, "argument of pragma X must be discrete type"
4154 -- returns "entity for aspect X must be a discrete type".
4155
4156 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
4157 -- be different from the pragma name). If the current pragma results
4158 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
4159 -- original pragma name.
4160
4161 procedure Gather_Associations
4162 (Names : Name_List;
4163 Args : out Args_List);
4164 -- This procedure is used to gather the arguments for a pragma that
4165 -- permits arbitrary ordering of parameters using the normal rules
4166 -- for named and positional parameters. The Names argument is a list
4167 -- of Name_Id values that corresponds to the allowed pragma argument
4168 -- association identifiers in order. The result returned in Args is
4169 -- a list of corresponding expressions that are the pragma arguments.
4170 -- Note that this is a list of expressions, not of pragma argument
4171 -- associations (Gather_Associations has completely checked all the
4172 -- optional identifiers when it returns). An entry in Args is Empty
4173 -- on return if the corresponding argument is not present.
4174
4175 procedure GNAT_Pragma;
4176 -- Called for all GNAT defined pragmas to check the relevant restriction
4177 -- (No_Implementation_Pragmas).
4178
4179 function Is_Before_First_Decl
4180 (Pragma_Node : Node_Id;
4181 Decls : List_Id) return Boolean;
4182 -- Return True if Pragma_Node is before the first declarative item in
4183 -- Decls where Decls is the list of declarative items.
4184
4185 function Is_Configuration_Pragma return Boolean;
4186 -- Determines if the placement of the current pragma is appropriate
4187 -- for a configuration pragma.
4188
4189 function Is_In_Context_Clause return Boolean;
4190 -- Returns True if pragma appears within the context clause of a unit,
4191 -- and False for any other placement (does not generate any messages).
4192
4193 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
4194 -- Analyzes the argument, and determines if it is a static string
4195 -- expression, returns True if so, False if non-static or not String.
4196 -- A special case is that a string literal returns True in Ada 83 mode
4197 -- (which has no such thing as static string expressions). Note that
4198 -- the call analyzes its argument, so this cannot be used for the case
4199 -- where an identifier might not be declared.
4200
4201 procedure Pragma_Misplaced;
4202 pragma No_Return (Pragma_Misplaced);
4203 -- Issue fatal error message for misplaced pragma
4204
4205 procedure Process_Atomic_Independent_Shared_Volatile;
4206 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
4207 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
4208 -- and treated as being identical in effect to pragma Atomic.
4209
4210 procedure Process_Compile_Time_Warning_Or_Error;
4211 -- Common processing for Compile_Time_Error and Compile_Time_Warning
4212
4213 procedure Process_Convention
4214 (C : out Convention_Id;
4215 Ent : out Entity_Id);
4216 -- Common processing for Convention, Interface, Import and Export.
4217 -- Checks first two arguments of pragma, and sets the appropriate
4218 -- convention value in the specified entity or entities. On return
4219 -- C is the convention, Ent is the referenced entity.
4220
4221 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
4222 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
4223 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
4224
4225 procedure Process_Extended_Import_Export_Object_Pragma
4226 (Arg_Internal : Node_Id;
4227 Arg_External : Node_Id;
4228 Arg_Size : Node_Id);
4229 -- Common processing for the pragmas Import/Export_Object. The three
4230 -- arguments correspond to the three named parameters of the pragmas. An
4231 -- argument is empty if the corresponding parameter is not present in
4232 -- the pragma.
4233
4234 procedure Process_Extended_Import_Export_Internal_Arg
4235 (Arg_Internal : Node_Id := Empty);
4236 -- Common processing for all extended Import and Export pragmas. The
4237 -- argument is the pragma parameter for the Internal argument. If
4238 -- Arg_Internal is empty or inappropriate, an error message is posted.
4239 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
4240 -- set to identify the referenced entity.
4241
4242 procedure Process_Extended_Import_Export_Subprogram_Pragma
4243 (Arg_Internal : Node_Id;
4244 Arg_External : Node_Id;
4245 Arg_Parameter_Types : Node_Id;
4246 Arg_Result_Type : Node_Id := Empty;
4247 Arg_Mechanism : Node_Id;
4248 Arg_Result_Mechanism : Node_Id := Empty);
4249 -- Common processing for all extended Import and Export pragmas applying
4250 -- to subprograms. The caller omits any arguments that do not apply to
4251 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
4252 -- only in the Import_Function and Export_Function cases). The argument
4253 -- names correspond to the allowed pragma association identifiers.
4254
4255 procedure Process_Generic_List;
4256 -- Common processing for Share_Generic and Inline_Generic
4257
4258 procedure Process_Import_Or_Interface;
4259 -- Common processing for Import or Interface
4260
4261 procedure Process_Import_Predefined_Type;
4262 -- Processing for completing a type with pragma Import. This is used
4263 -- to declare types that match predefined C types, especially for cases
4264 -- without corresponding Ada predefined type.
4265
4266 type Inline_Status is (Suppressed, Disabled, Enabled);
4267 -- Inline status of a subprogram, indicated as follows:
4268 -- Suppressed: inlining is suppressed for the subprogram
4269 -- Disabled: no inlining is requested for the subprogram
4270 -- Enabled: inlining is requested/required for the subprogram
4271
4272 procedure Process_Inline (Status : Inline_Status);
4273 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
4274 -- indicates the inline status specified by the pragma.
4275
4276 procedure Process_Interface_Name
4277 (Subprogram_Def : Entity_Id;
4278 Ext_Arg : Node_Id;
4279 Link_Arg : Node_Id;
4280 Prag : Node_Id);
4281 -- Given the last two arguments of pragma Import, pragma Export, or
4282 -- pragma Interface_Name, performs validity checks and sets the
4283 -- Interface_Name field of the given subprogram entity to the
4284 -- appropriate external or link name, depending on the arguments given.
4285 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
4286 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
4287 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
4288 -- nor Link_Arg is present, the interface name is set to the default
4289 -- from the subprogram name. In addition, the pragma itself is passed
4290 -- to analyze any expressions in the case the pragma came from an aspect
4291 -- specification.
4292
4293 procedure Process_Interrupt_Or_Attach_Handler;
4294 -- Common processing for Interrupt and Attach_Handler pragmas
4295
4296 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
4297 -- Common processing for Restrictions and Restriction_Warnings pragmas.
4298 -- Warn is True for Restriction_Warnings, or for Restrictions if the
4299 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
4300 -- is not set in the Restrictions case.
4301
4302 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
4303 -- Common processing for Suppress and Unsuppress. The boolean parameter
4304 -- Suppress_Case is True for the Suppress case, and False for the
4305 -- Unsuppress case.
4306
4307 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
4308 -- Subsidiary to the analysis of pragmas Independent[_Components].
4309 -- Record such a pragma N applied to entity E for future checks.
4310
4311 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
4312 -- This procedure sets the Is_Exported flag for the given entity,
4313 -- checking that the entity was not previously imported. Arg is
4314 -- the argument that specified the entity. A check is also made
4315 -- for exporting inappropriate entities.
4316
4317 procedure Set_Extended_Import_Export_External_Name
4318 (Internal_Ent : Entity_Id;
4319 Arg_External : Node_Id);
4320 -- Common processing for all extended import export pragmas. The first
4321 -- argument, Internal_Ent, is the internal entity, which has already
4322 -- been checked for validity by the caller. Arg_External is from the
4323 -- Import or Export pragma, and may be null if no External parameter
4324 -- was present. If Arg_External is present and is a non-null string
4325 -- (a null string is treated as the default), then the Interface_Name
4326 -- field of Internal_Ent is set appropriately.
4327
4328 procedure Set_Imported (E : Entity_Id);
4329 -- This procedure sets the Is_Imported flag for the given entity,
4330 -- checking that it is not previously exported or imported.
4331
4332 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
4333 -- Mech is a parameter passing mechanism (see Import_Function syntax
4334 -- for MECHANISM_NAME). This routine checks that the mechanism argument
4335 -- has the right form, and if not issues an error message. If the
4336 -- argument has the right form then the Mechanism field of Ent is
4337 -- set appropriately.
4338
4339 procedure Set_Rational_Profile;
4340 -- Activate the set of configuration pragmas and permissions that make
4341 -- up the Rational profile.
4342
4343 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id);
4344 -- Activate the set of configuration pragmas and restrictions that make
4345 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
4346 -- GNAT_Ravenscar_EDF, Jorvik, or Ravenscar. N is the corresponding
4347 -- pragma node, which is used for error messages on any constructs
4348 -- violating the profile.
4349
4350 ---------------------
4351 -- Ada_2005_Pragma --
4352 ---------------------
4353
4354 procedure Ada_2005_Pragma is
4355 begin
4356 if Ada_Version <= Ada_95 then
4357 Check_Restriction (No_Implementation_Pragmas, N);
4358 end if;
4359 end Ada_2005_Pragma;
4360
4361 ---------------------
4362 -- Ada_2012_Pragma --
4363 ---------------------
4364
4365 procedure Ada_2012_Pragma is
4366 begin
4367 if Ada_Version <= Ada_2005 then
4368 Check_Restriction (No_Implementation_Pragmas, N);
4369 end if;
4370 end Ada_2012_Pragma;
4371
4372 ----------------------------
4373 -- Analyze_Depends_Global --
4374 ----------------------------
4375
4376 procedure Analyze_Depends_Global
4377 (Spec_Id : out Entity_Id;
4378 Subp_Decl : out Node_Id;
4379 Legal : out Boolean)
4380 is
4381 begin
4382 -- Assume that the pragma is illegal
4383
4384 Spec_Id := Empty;
4385 Subp_Decl := Empty;
4386 Legal := False;
4387
4388 GNAT_Pragma;
4389 Check_Arg_Count (1);
4390
4391 -- Ensure the proper placement of the pragma. Depends/Global must be
4392 -- associated with a subprogram declaration or a body that acts as a
4393 -- spec.
4394
4395 Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4396
4397 -- Entry
4398
4399 if Nkind (Subp_Decl) = N_Entry_Declaration then
4400 null;
4401
4402 -- Generic subprogram
4403
4404 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4405 null;
4406
4407 -- Object declaration of a single concurrent type
4408
4409 elsif Nkind (Subp_Decl) = N_Object_Declaration
4410 and then Is_Single_Concurrent_Object
4411 (Unique_Defining_Entity (Subp_Decl))
4412 then
4413 null;
4414
4415 -- Single task type
4416
4417 elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then
4418 null;
4419
4420 -- Subprogram body acts as spec
4421
4422 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4423 and then No (Corresponding_Spec (Subp_Decl))
4424 then
4425 null;
4426
4427 -- Subprogram body stub acts as spec
4428
4429 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4430 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
4431 then
4432 null;
4433
4434 -- Subprogram declaration
4435
4436 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4437 null;
4438
4439 -- Task type
4440
4441 elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then
4442 null;
4443
4444 else
4445 Pragma_Misplaced;
4446 return;
4447 end if;
4448
4449 -- If we get here, then the pragma is legal
4450
4451 Legal := True;
4452 Spec_Id := Unique_Defining_Entity (Subp_Decl);
4453
4454 -- When the related context is an entry, the entry must belong to a
4455 -- protected unit (SPARK RM 6.1.4(6)).
4456
4457 if Is_Entry_Declaration (Spec_Id)
4458 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
4459 then
4460 Pragma_Misplaced;
4461 return;
4462
4463 -- When the related context is an anonymous object created for a
4464 -- simple concurrent type, the type must be a task
4465 -- (SPARK RM 6.1.4(6)).
4466
4467 elsif Is_Single_Concurrent_Object (Spec_Id)
4468 and then Ekind (Etype (Spec_Id)) /= E_Task_Type
4469 then
4470 Pragma_Misplaced;
4471 return;
4472 end if;
4473
4474 -- A pragma that applies to a Ghost entity becomes Ghost for the
4475 -- purposes of legality checks and removal of ignored Ghost code.
4476
4477 Mark_Ghost_Pragma (N, Spec_Id);
4478 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4479 end Analyze_Depends_Global;
4480
4481 ------------------------
4482 -- Analyze_If_Present --
4483 ------------------------
4484
4485 procedure Analyze_If_Present (Id : Pragma_Id) is
4486 Stmt : Node_Id;
4487
4488 begin
4489 pragma Assert (Is_List_Member (N));
4490
4491 -- Inspect the declarations or statements following pragma N looking
4492 -- for another pragma whose Id matches the caller's request. If it is
4493 -- available, analyze it.
4494
4495 Stmt := Next (N);
4496 while Present (Stmt) loop
4497 if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then
4498 Analyze_Pragma (Stmt);
4499 exit;
4500
4501 -- The first source declaration or statement immediately following
4502 -- N ends the region where a pragma may appear.
4503
4504 elsif Comes_From_Source (Stmt) then
4505 exit;
4506 end if;
4507
4508 Next (Stmt);
4509 end loop;
4510 end Analyze_If_Present;
4511
4512 --------------------------------
4513 -- Analyze_Pre_Post_Condition --
4514 --------------------------------
4515
4516 procedure Analyze_Pre_Post_Condition is
4517 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
4518 Subp_Decl : Node_Id;
4519 Subp_Id : Entity_Id;
4520
4521 Duplicates_OK : Boolean := False;
4522 -- Flag set when a pre/postcondition allows multiple pragmas of the
4523 -- same kind.
4524
4525 In_Body_OK : Boolean := False;
4526 -- Flag set when a pre/postcondition is allowed to appear on a body
4527 -- even though the subprogram may have a spec.
4528
4529 Is_Pre_Post : Boolean := False;
4530 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4531 -- Post_Class.
4532
4533 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean;
4534 -- Implement rules in AI12-0131: an overriding operation can have
4535 -- a class-wide precondition only if one of its ancestors has an
4536 -- explicit class-wide precondition.
4537
4538 -----------------------------
4539 -- Inherits_Class_Wide_Pre --
4540 -----------------------------
4541
4542 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean is
4543 Typ : constant Entity_Id := Find_Dispatching_Type (E);
4544 Cont : Node_Id;
4545 Prag : Node_Id;
4546 Prev : Entity_Id := Overridden_Operation (E);
4547
4548 begin
4549 -- Check ancestors on the overriding operation to examine the
4550 -- preconditions that may apply to them.
4551
4552 while Present (Prev) loop
4553 Cont := Contract (Prev);
4554 if Present (Cont) then
4555 Prag := Pre_Post_Conditions (Cont);
4556 while Present (Prag) loop
4557 if Pragma_Name (Prag) = Name_Precondition
4558 and then Class_Present (Prag)
4559 then
4560 return True;
4561 end if;
4562
4563 Prag := Next_Pragma (Prag);
4564 end loop;
4565 end if;
4566
4567 -- For a type derived from a generic formal type, the operation
4568 -- inheriting the condition is a renaming, not an overriding of
4569 -- the operation of the formal. Ditto for an inherited
4570 -- operation which has no explicit contracts.
4571
4572 if Is_Generic_Type (Find_Dispatching_Type (Prev))
4573 or else not Comes_From_Source (Prev)
4574 then
4575 Prev := Alias (Prev);
4576 else
4577 Prev := Overridden_Operation (Prev);
4578 end if;
4579 end loop;
4580
4581 -- If the controlling type of the subprogram has progenitors, an
4582 -- interface operation implemented by the current operation may
4583 -- have a class-wide precondition.
4584
4585 if Has_Interfaces (Typ) then
4586 declare
4587 Elmt : Elmt_Id;
4588 Ints : Elist_Id;
4589 Prim : Entity_Id;
4590 Prim_Elmt : Elmt_Id;
4591 Prim_List : Elist_Id;
4592
4593 begin
4594 Collect_Interfaces (Typ, Ints);
4595 Elmt := First_Elmt (Ints);
4596
4597 -- Iterate over the primitive operations of each interface
4598
4599 while Present (Elmt) loop
4600 Prim_List := Direct_Primitive_Operations (Node (Elmt));
4601 Prim_Elmt := First_Elmt (Prim_List);
4602 while Present (Prim_Elmt) loop
4603 Prim := Node (Prim_Elmt);
4604 if Chars (Prim) = Chars (E)
4605 and then Present (Contract (Prim))
4606 and then Class_Present
4607 (Pre_Post_Conditions (Contract (Prim)))
4608 then
4609 return True;
4610 end if;
4611
4612 Next_Elmt (Prim_Elmt);
4613 end loop;
4614
4615 Next_Elmt (Elmt);
4616 end loop;
4617 end;
4618 end if;
4619
4620 return False;
4621 end Inherits_Class_Wide_Pre;
4622
4623 -- Start of processing for Analyze_Pre_Post_Condition
4624
4625 begin
4626 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4627 -- offer uniformity among the various kinds of pre/postconditions by
4628 -- rewriting the pragma identifier. This allows the retrieval of the
4629 -- original pragma name by routine Original_Aspect_Pragma_Name.
4630
4631 if Comes_From_Source (N) then
4632 if Pname in Name_Pre | Name_Pre_Class then
4633 Is_Pre_Post := True;
4634 Set_Class_Present (N, Pname = Name_Pre_Class);
4635 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
4636
4637 elsif Pname in Name_Post | Name_Post_Class then
4638 Is_Pre_Post := True;
4639 Set_Class_Present (N, Pname = Name_Post_Class);
4640 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
4641 end if;
4642 end if;
4643
4644 -- Determine the semantics with respect to duplicates and placement
4645 -- in a body. Pragmas Precondition and Postcondition were introduced
4646 -- before aspects and are not subject to the same aspect-like rules.
4647
4648 if Pname in Name_Precondition | Name_Postcondition then
4649 Duplicates_OK := True;
4650 In_Body_OK := True;
4651 end if;
4652
4653 GNAT_Pragma;
4654
4655 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4656 -- argument without an identifier.
4657
4658 if Is_Pre_Post then
4659 Check_Arg_Count (1);
4660 Check_No_Identifiers;
4661
4662 -- Pragmas Precondition and Postcondition have complex argument
4663 -- profile.
4664
4665 else
4666 Check_At_Least_N_Arguments (1);
4667 Check_At_Most_N_Arguments (2);
4668 Check_Optional_Identifier (Arg1, Name_Check);
4669
4670 if Present (Arg2) then
4671 Check_Optional_Identifier (Arg2, Name_Message);
4672 Preanalyze_Spec_Expression
4673 (Get_Pragma_Arg (Arg2), Standard_String);
4674 end if;
4675 end if;
4676
4677 -- For a pragma PPC in the extended main source unit, record enabled
4678 -- status in SCO.
4679 -- ??? nothing checks that the pragma is in the main source unit
4680
4681 if Is_Checked (N) and then not Split_PPC (N) then
4682 Set_SCO_Pragma_Enabled (Loc);
4683 end if;
4684
4685 -- Ensure the proper placement of the pragma
4686
4687 Subp_Decl :=
4688 Find_Related_Declaration_Or_Body
4689 (N, Do_Checks => not Duplicates_OK);
4690
4691 -- When a pre/postcondition pragma applies to an abstract subprogram,
4692 -- its original form must be an aspect with 'Class.
4693
4694 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4695 if not From_Aspect_Specification (N) then
4696 Error_Pragma
4697 ("pragma % cannot be applied to abstract subprogram");
4698
4699 elsif not Class_Present (N) then
4700 Error_Pragma
4701 ("aspect % requires ''Class for abstract subprogram");
4702 end if;
4703
4704 -- Entry declaration
4705
4706 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
4707 null;
4708
4709 -- Generic subprogram declaration
4710
4711 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4712 null;
4713
4714 -- Subprogram body
4715
4716 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4717 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
4718 then
4719 null;
4720
4721 -- Subprogram body stub
4722
4723 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4724 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
4725 then
4726 null;
4727
4728 -- Subprogram declaration
4729
4730 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4731
4732 -- AI05-0230: When a pre/postcondition pragma applies to a null
4733 -- procedure, its original form must be an aspect with 'Class.
4734
4735 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4736 and then Null_Present (Specification (Subp_Decl))
4737 and then From_Aspect_Specification (N)
4738 and then not Class_Present (N)
4739 then
4740 Error_Pragma ("aspect % requires ''Class for null procedure");
4741 end if;
4742
4743 -- Implement the legality checks mandated by AI12-0131:
4744 -- Pre'Class shall not be specified for an overriding primitive
4745 -- subprogram of a tagged type T unless the Pre'Class aspect is
4746 -- specified for the corresponding primitive subprogram of some
4747 -- ancestor of T.
4748
4749 declare
4750 E : constant Entity_Id := Defining_Entity (Subp_Decl);
4751
4752 begin
4753 if Class_Present (N)
4754 and then Pragma_Name (N) = Name_Precondition
4755 and then Present (Overridden_Operation (E))
4756 and then not Inherits_Class_Wide_Pre (E)
4757 then
4758 Error_Msg_N
4759 ("illegal class-wide precondition on overriding operation",
4760 Corresponding_Aspect (N));
4761 end if;
4762 end;
4763
4764 -- A renaming declaration may inherit a generated pragma, its
4765 -- placement comes from expansion, not from source.
4766
4767 elsif Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
4768 and then not Comes_From_Source (N)
4769 then
4770 null;
4771
4772 -- For Ada 2020, pre/postconditions can appear on formal subprograms
4773
4774 elsif Nkind (Subp_Decl) = N_Formal_Concrete_Subprogram_Declaration
4775 and then Ada_Version >= Ada_2020
4776 then
4777 null;
4778
4779 -- An access-to-subprogram type can have pre/postconditions, but
4780 -- these are transferred to the generated subprogram wrapper and
4781 -- analyzed there.
4782
4783 -- Otherwise the placement of the pragma is illegal
4784
4785 else
4786 Pragma_Misplaced;
4787 return;
4788 end if;
4789
4790 Subp_Id := Defining_Entity (Subp_Decl);
4791
4792 -- A pragma that applies to a Ghost entity becomes Ghost for the
4793 -- purposes of legality checks and removal of ignored Ghost code.
4794
4795 Mark_Ghost_Pragma (N, Subp_Id);
4796
4797 -- Chain the pragma on the contract for further processing by
4798 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4799
4800 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
4801
4802 -- Fully analyze the pragma when it appears inside an entry or
4803 -- subprogram body because it cannot benefit from forward references.
4804
4805 if Nkind (Subp_Decl) in N_Entry_Body
4806 | N_Subprogram_Body
4807 | N_Subprogram_Body_Stub
4808 then
4809 -- The legality checks of pragmas Precondition and Postcondition
4810 -- are affected by the SPARK mode in effect and the volatility of
4811 -- the context. Analyze all pragmas in a specific order.
4812
4813 Analyze_If_Present (Pragma_SPARK_Mode);
4814 Analyze_If_Present (Pragma_Volatile_Function);
4815 Analyze_Pre_Post_Condition_In_Decl_Part (N);
4816 end if;
4817 end Analyze_Pre_Post_Condition;
4818
4819 -----------------------------------------
4820 -- Analyze_Refined_Depends_Global_Post --
4821 -----------------------------------------
4822
4823 procedure Analyze_Refined_Depends_Global_Post
4824 (Spec_Id : out Entity_Id;
4825 Body_Id : out Entity_Id;
4826 Legal : out Boolean)
4827 is
4828 Body_Decl : Node_Id;
4829 Spec_Decl : Node_Id;
4830
4831 begin
4832 -- Assume that the pragma is illegal
4833
4834 Spec_Id := Empty;
4835 Body_Id := Empty;
4836 Legal := False;
4837
4838 GNAT_Pragma;
4839 Check_Arg_Count (1);
4840 Check_No_Identifiers;
4841
4842 -- Verify the placement of the pragma and check for duplicates. The
4843 -- pragma must apply to a subprogram body [stub].
4844
4845 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4846
4847 if Nkind (Body_Decl) not in
4848 N_Entry_Body | N_Subprogram_Body | N_Subprogram_Body_Stub |
4849 N_Task_Body | N_Task_Body_Stub
4850 then
4851 Pragma_Misplaced;
4852 return;
4853 end if;
4854
4855 Body_Id := Defining_Entity (Body_Decl);
4856 Spec_Id := Unique_Defining_Entity (Body_Decl);
4857
4858 -- The pragma must apply to the second declaration of a subprogram.
4859 -- In other words, the body [stub] cannot acts as a spec.
4860
4861 if No (Spec_Id) then
4862 Error_Pragma ("pragma % cannot apply to a stand alone body");
4863 return;
4864
4865 -- Catch the case where the subprogram body is a subunit and acts as
4866 -- the third declaration of the subprogram.
4867
4868 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
4869 Error_Pragma ("pragma % cannot apply to a subunit");
4870 return;
4871 end if;
4872
4873 -- A refined pragma can only apply to the body [stub] of a subprogram
4874 -- declared in the visible part of a package. Retrieve the context of
4875 -- the subprogram declaration.
4876
4877 Spec_Decl := Unit_Declaration_Node (Spec_Id);
4878
4879 -- When dealing with protected entries or protected subprograms, use
4880 -- the enclosing protected type as the proper context.
4881
4882 if Ekind (Spec_Id) in E_Entry
4883 | E_Entry_Family
4884 | E_Function
4885 | E_Procedure
4886 and then Ekind (Scope (Spec_Id)) = E_Protected_Type
4887 then
4888 Spec_Decl := Declaration_Node (Scope (Spec_Id));
4889 end if;
4890
4891 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
4892 Error_Pragma
4893 (Fix_Msg (Spec_Id, "pragma % must apply to the body of "
4894 & "subprogram declared in a package specification"));
4895 return;
4896 end if;
4897
4898 -- If we get here, then the pragma is legal
4899
4900 Legal := True;
4901
4902 -- A pragma that applies to a Ghost entity becomes Ghost for the
4903 -- purposes of legality checks and removal of ignored Ghost code.
4904
4905 Mark_Ghost_Pragma (N, Spec_Id);
4906
4907 if Pname in Name_Refined_Depends | Name_Refined_Global then
4908 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4909 end if;
4910 end Analyze_Refined_Depends_Global_Post;
4911
4912 ----------------------------------
4913 -- Analyze_Unmodified_Or_Unused --
4914 ----------------------------------
4915
4916 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False) is
4917 Arg : Node_Id;
4918 Arg_Expr : Node_Id;
4919 Arg_Id : Entity_Id;
4920
4921 Ghost_Error_Posted : Boolean := False;
4922 -- Flag set when an error concerning the illegal mix of Ghost and
4923 -- non-Ghost variables is emitted.
4924
4925 Ghost_Id : Entity_Id := Empty;
4926 -- The entity of the first Ghost variable encountered while
4927 -- processing the arguments of the pragma.
4928
4929 begin
4930 GNAT_Pragma;
4931 Check_At_Least_N_Arguments (1);
4932
4933 -- Loop through arguments
4934
4935 Arg := Arg1;
4936 while Present (Arg) loop
4937 Check_No_Identifier (Arg);
4938
4939 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4940 -- in fact generate reference, so that the entity will have a
4941 -- reference, which will inhibit any warnings about it not
4942 -- being referenced, and also properly show up in the ali file
4943 -- as a reference. But this reference is recorded before the
4944 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4945 -- generated for this reference.
4946
4947 Check_Arg_Is_Local_Name (Arg);
4948 Arg_Expr := Get_Pragma_Arg (Arg);
4949
4950 if Is_Entity_Name (Arg_Expr) then
4951 Arg_Id := Entity (Arg_Expr);
4952
4953 -- Skip processing the argument if already flagged
4954
4955 if Is_Assignable (Arg_Id)
4956 and then not Has_Pragma_Unmodified (Arg_Id)
4957 and then not Has_Pragma_Unused (Arg_Id)
4958 then
4959 Set_Has_Pragma_Unmodified (Arg_Id);
4960
4961 if Is_Unused then
4962 Set_Has_Pragma_Unused (Arg_Id);
4963 end if;
4964
4965 -- A pragma that applies to a Ghost entity becomes Ghost for
4966 -- the purposes of legality checks and removal of ignored
4967 -- Ghost code.
4968
4969 Mark_Ghost_Pragma (N, Arg_Id);
4970
4971 -- Capture the entity of the first Ghost variable being
4972 -- processed for error detection purposes.
4973
4974 if Is_Ghost_Entity (Arg_Id) then
4975 if No (Ghost_Id) then
4976 Ghost_Id := Arg_Id;
4977 end if;
4978
4979 -- Otherwise the variable is non-Ghost. It is illegal to mix
4980 -- references to Ghost and non-Ghost entities
4981 -- (SPARK RM 6.9).
4982
4983 elsif Present (Ghost_Id)
4984 and then not Ghost_Error_Posted
4985 then
4986 Ghost_Error_Posted := True;
4987
4988 Error_Msg_Name_1 := Pname;
4989 Error_Msg_N
4990 ("pragma % cannot mention ghost and non-ghost "
4991 & "variables", N);
4992
4993 Error_Msg_Sloc := Sloc (Ghost_Id);
4994 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
4995
4996 Error_Msg_Sloc := Sloc (Arg_Id);
4997 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
4998 end if;
4999
5000 -- Warn if already flagged as Unused or Unmodified
5001
5002 elsif Has_Pragma_Unmodified (Arg_Id) then
5003 if Has_Pragma_Unused (Arg_Id) then
5004 Error_Msg_NE
5005 ("??pragma Unused already given for &!", Arg_Expr,
5006 Arg_Id);
5007 else
5008 Error_Msg_NE
5009 ("??pragma Unmodified already given for &!", Arg_Expr,
5010 Arg_Id);
5011 end if;
5012
5013 -- Otherwise the pragma referenced an illegal entity
5014
5015 else
5016 Error_Pragma_Arg
5017 ("pragma% can only be applied to a variable", Arg_Expr);
5018 end if;
5019 end if;
5020
5021 Next (Arg);
5022 end loop;
5023 end Analyze_Unmodified_Or_Unused;
5024
5025 ------------------------------------
5026 -- Analyze_Unreferenced_Or_Unused --
5027 ------------------------------------
5028
5029 procedure Analyze_Unreferenced_Or_Unused
5030 (Is_Unused : Boolean := False)
5031 is
5032 Arg : Node_Id;
5033 Arg_Expr : Node_Id;
5034 Arg_Id : Entity_Id;
5035 Citem : Node_Id;
5036
5037 Ghost_Error_Posted : Boolean := False;
5038 -- Flag set when an error concerning the illegal mix of Ghost and
5039 -- non-Ghost names is emitted.
5040
5041 Ghost_Id : Entity_Id := Empty;
5042 -- The entity of the first Ghost name encountered while processing
5043 -- the arguments of the pragma.
5044
5045 begin
5046 GNAT_Pragma;
5047 Check_At_Least_N_Arguments (1);
5048
5049 -- Check case of appearing within context clause
5050
5051 if not Is_Unused and then Is_In_Context_Clause then
5052
5053 -- The arguments must all be units mentioned in a with clause in
5054 -- the same context clause. Note that Par.Prag already checked
5055 -- that the arguments are either identifiers or selected
5056 -- components.
5057
5058 Arg := Arg1;
5059 while Present (Arg) loop
5060 Citem := First (List_Containing (N));
5061 while Citem /= N loop
5062 Arg_Expr := Get_Pragma_Arg (Arg);
5063
5064 if Nkind (Citem) = N_With_Clause
5065 and then Same_Name (Name (Citem), Arg_Expr)
5066 then
5067 Set_Has_Pragma_Unreferenced
5068 (Cunit_Entity
5069 (Get_Source_Unit
5070 (Library_Unit (Citem))));
5071 Set_Elab_Unit_Name (Arg_Expr, Name (Citem));
5072 exit;
5073 end if;
5074
5075 Next (Citem);
5076 end loop;
5077
5078 if Citem = N then
5079 Error_Pragma_Arg
5080 ("argument of pragma% is not withed unit", Arg);
5081 end if;
5082
5083 Next (Arg);
5084 end loop;
5085
5086 -- Case of not in list of context items
5087
5088 else
5089 Arg := Arg1;
5090 while Present (Arg) loop
5091 Check_No_Identifier (Arg);
5092
5093 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
5094 -- in fact generate reference, so that the entity will have a
5095 -- reference, which will inhibit any warnings about it not
5096 -- being referenced, and also properly show up in the ali file
5097 -- as a reference. But this reference is recorded before the
5098 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5099 -- generated for this reference.
5100
5101 Check_Arg_Is_Local_Name (Arg);
5102 Arg_Expr := Get_Pragma_Arg (Arg);
5103
5104 if Is_Entity_Name (Arg_Expr) then
5105 Arg_Id := Entity (Arg_Expr);
5106
5107 -- Warn if already flagged as Unused or Unreferenced and
5108 -- skip processing the argument.
5109
5110 if Has_Pragma_Unreferenced (Arg_Id) then
5111 if Has_Pragma_Unused (Arg_Id) then
5112 Error_Msg_NE
5113 ("??pragma Unused already given for &!", Arg_Expr,
5114 Arg_Id);
5115 else
5116 Error_Msg_NE
5117 ("??pragma Unreferenced already given for &!",
5118 Arg_Expr, Arg_Id);
5119 end if;
5120
5121 -- Apply Unreferenced to the entity
5122
5123 else
5124 -- If the entity is overloaded, the pragma applies to the
5125 -- most recent overloading, as documented. In this case,
5126 -- name resolution does not generate a reference, so it
5127 -- must be done here explicitly.
5128
5129 if Is_Overloaded (Arg_Expr) then
5130 Generate_Reference (Arg_Id, N);
5131 end if;
5132
5133 Set_Has_Pragma_Unreferenced (Arg_Id);
5134
5135 if Is_Unused then
5136 Set_Has_Pragma_Unused (Arg_Id);
5137 end if;
5138
5139 -- A pragma that applies to a Ghost entity becomes Ghost
5140 -- for the purposes of legality checks and removal of
5141 -- ignored Ghost code.
5142
5143 Mark_Ghost_Pragma (N, Arg_Id);
5144
5145 -- Capture the entity of the first Ghost name being
5146 -- processed for error detection purposes.
5147
5148 if Is_Ghost_Entity (Arg_Id) then
5149 if No (Ghost_Id) then
5150 Ghost_Id := Arg_Id;
5151 end if;
5152
5153 -- Otherwise the name is non-Ghost. It is illegal to mix
5154 -- references to Ghost and non-Ghost entities
5155 -- (SPARK RM 6.9).
5156
5157 elsif Present (Ghost_Id)
5158 and then not Ghost_Error_Posted
5159 then
5160 Ghost_Error_Posted := True;
5161
5162 Error_Msg_Name_1 := Pname;
5163 Error_Msg_N
5164 ("pragma % cannot mention ghost and non-ghost "
5165 & "names", N);
5166
5167 Error_Msg_Sloc := Sloc (Ghost_Id);
5168 Error_Msg_NE
5169 ("\& # declared as ghost", N, Ghost_Id);
5170
5171 Error_Msg_Sloc := Sloc (Arg_Id);
5172 Error_Msg_NE
5173 ("\& # declared as non-ghost", N, Arg_Id);
5174 end if;
5175 end if;
5176 end if;
5177
5178 Next (Arg);
5179 end loop;
5180 end if;
5181 end Analyze_Unreferenced_Or_Unused;
5182
5183 --------------------------
5184 -- Check_Ada_83_Warning --
5185 --------------------------
5186
5187 procedure Check_Ada_83_Warning is
5188 begin
5189 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5190 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
5191 end if;
5192 end Check_Ada_83_Warning;
5193
5194 ---------------------
5195 -- Check_Arg_Count --
5196 ---------------------
5197
5198 procedure Check_Arg_Count (Required : Nat) is
5199 begin
5200 if Arg_Count /= Required then
5201 Error_Pragma ("wrong number of arguments for pragma%");
5202 end if;
5203 end Check_Arg_Count;
5204
5205 --------------------------------
5206 -- Check_Arg_Is_External_Name --
5207 --------------------------------
5208
5209 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
5210 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5211
5212 begin
5213 if Nkind (Argx) = N_Identifier then
5214 return;
5215
5216 else
5217 Analyze_And_Resolve (Argx, Standard_String);
5218
5219 if Is_OK_Static_Expression (Argx) then
5220 return;
5221
5222 elsif Etype (Argx) = Any_Type then
5223 raise Pragma_Exit;
5224
5225 -- An interesting special case, if we have a string literal and
5226 -- we are in Ada 83 mode, then we allow it even though it will
5227 -- not be flagged as static. This allows expected Ada 83 mode
5228 -- use of external names which are string literals, even though
5229 -- technically these are not static in Ada 83.
5230
5231 elsif Ada_Version = Ada_83
5232 and then Nkind (Argx) = N_String_Literal
5233 then
5234 return;
5235
5236 -- Here we have a real error (non-static expression)
5237
5238 else
5239 Error_Msg_Name_1 := Pname;
5240 Flag_Non_Static_Expr
5241 (Fix_Error ("argument for pragma% must be a identifier or "
5242 & "static string expression!"), Argx);
5243
5244 raise Pragma_Exit;
5245 end if;
5246 end if;
5247 end Check_Arg_Is_External_Name;
5248
5249 -----------------------------
5250 -- Check_Arg_Is_Identifier --
5251 -----------------------------
5252
5253 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
5254 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5255 begin
5256 if Nkind (Argx) /= N_Identifier then
5257 Error_Pragma_Arg ("argument for pragma% must be identifier", Argx);
5258 end if;
5259 end Check_Arg_Is_Identifier;
5260
5261 ----------------------------------
5262 -- Check_Arg_Is_Integer_Literal --
5263 ----------------------------------
5264
5265 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
5266 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5267 begin
5268 if Nkind (Argx) /= N_Integer_Literal then
5269 Error_Pragma_Arg
5270 ("argument for pragma% must be integer literal", Argx);
5271 end if;
5272 end Check_Arg_Is_Integer_Literal;
5273
5274 -------------------------------------------
5275 -- Check_Arg_Is_Library_Level_Local_Name --
5276 -------------------------------------------
5277
5278 -- LOCAL_NAME ::=
5279 -- DIRECT_NAME
5280 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5281 -- | library_unit_NAME
5282
5283 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
5284 begin
5285 Check_Arg_Is_Local_Name (Arg);
5286
5287 -- If it came from an aspect, we want to give the error just as if it
5288 -- came from source.
5289
5290 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
5291 and then (Comes_From_Source (N)
5292 or else Present (Corresponding_Aspect (Parent (Arg))))
5293 then
5294 Error_Pragma_Arg
5295 ("argument for pragma% must be library level entity", Arg);
5296 end if;
5297 end Check_Arg_Is_Library_Level_Local_Name;
5298
5299 -----------------------------
5300 -- Check_Arg_Is_Local_Name --
5301 -----------------------------
5302
5303 -- LOCAL_NAME ::=
5304 -- DIRECT_NAME
5305 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5306 -- | library_unit_NAME
5307
5308 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
5309 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5310
5311 begin
5312 -- If this pragma came from an aspect specification, we don't want to
5313 -- check for this error, because that would cause spurious errors, in
5314 -- case a type is frozen in a scope more nested than the type. The
5315 -- aspect itself of course can't be anywhere but on the declaration
5316 -- itself.
5317
5318 if Nkind (Arg) = N_Pragma_Argument_Association then
5319 if From_Aspect_Specification (Parent (Arg)) then
5320 return;
5321 end if;
5322
5323 -- Arg is the Expression of an N_Pragma_Argument_Association
5324
5325 else
5326 if From_Aspect_Specification (Parent (Parent (Arg))) then
5327 return;
5328 end if;
5329 end if;
5330
5331 Analyze (Argx);
5332
5333 if Nkind (Argx) not in N_Direct_Name
5334 and then (Nkind (Argx) /= N_Attribute_Reference
5335 or else Present (Expressions (Argx))
5336 or else Nkind (Prefix (Argx)) /= N_Identifier)
5337 and then (not Is_Entity_Name (Argx)
5338 or else not Is_Compilation_Unit (Entity (Argx)))
5339 then
5340 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
5341 end if;
5342
5343 -- No further check required if not an entity name
5344
5345 if not Is_Entity_Name (Argx) then
5346 null;
5347
5348 else
5349 declare
5350 OK : Boolean;
5351 Ent : constant Entity_Id := Entity (Argx);
5352 Scop : constant Entity_Id := Scope (Ent);
5353
5354 begin
5355 -- Case of a pragma applied to a compilation unit: pragma must
5356 -- occur immediately after the program unit in the compilation.
5357
5358 if Is_Compilation_Unit (Ent) then
5359 declare
5360 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
5361
5362 begin
5363 -- Case of pragma placed immediately after spec
5364
5365 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
5366 OK := True;
5367
5368 -- Case of pragma placed immediately after body
5369
5370 elsif Nkind (Decl) = N_Subprogram_Declaration
5371 and then Present (Corresponding_Body (Decl))
5372 then
5373 OK := Parent (N) =
5374 Aux_Decls_Node
5375 (Parent (Unit_Declaration_Node
5376 (Corresponding_Body (Decl))));
5377
5378 -- All other cases are illegal
5379
5380 else
5381 OK := False;
5382 end if;
5383 end;
5384
5385 -- Special restricted placement rule from 10.2.1(11.8/2)
5386
5387 elsif Is_Generic_Formal (Ent)
5388 and then Prag_Id = Pragma_Preelaborable_Initialization
5389 then
5390 OK := List_Containing (N) =
5391 Generic_Formal_Declarations
5392 (Unit_Declaration_Node (Scop));
5393
5394 -- If this is an aspect applied to a subprogram body, the
5395 -- pragma is inserted in its declarative part.
5396
5397 elsif From_Aspect_Specification (N)
5398 and then Ent = Current_Scope
5399 and then
5400 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
5401 then
5402 OK := True;
5403
5404 -- If the aspect is a predicate (possibly others ???) and the
5405 -- context is a record type, this is a discriminant expression
5406 -- within a type declaration, that freezes the predicated
5407 -- subtype.
5408
5409 elsif From_Aspect_Specification (N)
5410 and then Prag_Id = Pragma_Predicate
5411 and then Ekind (Current_Scope) = E_Record_Type
5412 and then Scop = Scope (Current_Scope)
5413 then
5414 OK := True;
5415
5416 -- Default case, just check that the pragma occurs in the scope
5417 -- of the entity denoted by the name.
5418
5419 else
5420 OK := Current_Scope = Scop;
5421 end if;
5422
5423 if not OK then
5424 Error_Pragma_Arg
5425 ("pragma% argument must be in same declarative part", Arg);
5426 end if;
5427 end;
5428 end if;
5429 end Check_Arg_Is_Local_Name;
5430
5431 ---------------------------------
5432 -- Check_Arg_Is_Locking_Policy --
5433 ---------------------------------
5434
5435 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
5436 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5437
5438 begin
5439 Check_Arg_Is_Identifier (Argx);
5440
5441 if not Is_Locking_Policy_Name (Chars (Argx)) then
5442 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
5443 end if;
5444 end Check_Arg_Is_Locking_Policy;
5445
5446 -----------------------------------------------
5447 -- Check_Arg_Is_Partition_Elaboration_Policy --
5448 -----------------------------------------------
5449
5450 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
5451 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5452
5453 begin
5454 Check_Arg_Is_Identifier (Argx);
5455
5456 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
5457 Error_Pragma_Arg
5458 ("& is not a valid partition elaboration policy name", Argx);
5459 end if;
5460 end Check_Arg_Is_Partition_Elaboration_Policy;
5461
5462 -------------------------
5463 -- Check_Arg_Is_One_Of --
5464 -------------------------
5465
5466 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5467 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5468
5469 begin
5470 Check_Arg_Is_Identifier (Argx);
5471
5472 if Chars (Argx) not in N1 | N2 then
5473 Error_Msg_Name_2 := N1;
5474 Error_Msg_Name_3 := N2;
5475 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
5476 end if;
5477 end Check_Arg_Is_One_Of;
5478
5479 procedure Check_Arg_Is_One_Of
5480 (Arg : Node_Id;
5481 N1, N2, N3 : Name_Id)
5482 is
5483 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5484
5485 begin
5486 Check_Arg_Is_Identifier (Argx);
5487
5488 if Chars (Argx) not in N1 | N2 | N3 then
5489 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5490 end if;
5491 end Check_Arg_Is_One_Of;
5492
5493 procedure Check_Arg_Is_One_Of
5494 (Arg : Node_Id;
5495 N1, N2, N3, N4 : Name_Id)
5496 is
5497 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5498
5499 begin
5500 Check_Arg_Is_Identifier (Argx);
5501
5502 if Chars (Argx) not in N1 | N2 | N3 | N4 then
5503 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5504 end if;
5505 end Check_Arg_Is_One_Of;
5506
5507 procedure Check_Arg_Is_One_Of
5508 (Arg : Node_Id;
5509 N1, N2, N3, N4, N5 : Name_Id)
5510 is
5511 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5512
5513 begin
5514 Check_Arg_Is_Identifier (Argx);
5515
5516 if Chars (Argx) not in N1 | N2 | N3 | N4 | N5 then
5517 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5518 end if;
5519 end Check_Arg_Is_One_Of;
5520
5521 ---------------------------------
5522 -- Check_Arg_Is_Queuing_Policy --
5523 ---------------------------------
5524
5525 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
5526 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5527
5528 begin
5529 Check_Arg_Is_Identifier (Argx);
5530
5531 if not Is_Queuing_Policy_Name (Chars (Argx)) then
5532 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
5533 end if;
5534 end Check_Arg_Is_Queuing_Policy;
5535
5536 ---------------------------------------
5537 -- Check_Arg_Is_OK_Static_Expression --
5538 ---------------------------------------
5539
5540 procedure Check_Arg_Is_OK_Static_Expression
5541 (Arg : Node_Id;
5542 Typ : Entity_Id := Empty)
5543 is
5544 begin
5545 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
5546 end Check_Arg_Is_OK_Static_Expression;
5547
5548 ------------------------------------------
5549 -- Check_Arg_Is_Task_Dispatching_Policy --
5550 ------------------------------------------
5551
5552 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
5553 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5554
5555 begin
5556 Check_Arg_Is_Identifier (Argx);
5557
5558 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
5559 Error_Pragma_Arg
5560 ("& is not an allowed task dispatching policy name", Argx);
5561 end if;
5562 end Check_Arg_Is_Task_Dispatching_Policy;
5563
5564 ---------------------
5565 -- Check_Arg_Order --
5566 ---------------------
5567
5568 procedure Check_Arg_Order (Names : Name_List) is
5569 Arg : Node_Id;
5570
5571 Highest_So_Far : Natural := 0;
5572 -- Highest index in Names seen do far
5573
5574 begin
5575 Arg := Arg1;
5576 for J in 1 .. Arg_Count loop
5577 if Chars (Arg) /= No_Name then
5578 for K in Names'Range loop
5579 if Chars (Arg) = Names (K) then
5580 if K < Highest_So_Far then
5581 Error_Msg_Name_1 := Pname;
5582 Error_Msg_N
5583 ("parameters out of order for pragma%", Arg);
5584 Error_Msg_Name_1 := Names (K);
5585 Error_Msg_Name_2 := Names (Highest_So_Far);
5586 Error_Msg_N ("\% must appear before %", Arg);
5587 raise Pragma_Exit;
5588
5589 else
5590 Highest_So_Far := K;
5591 end if;
5592 end if;
5593 end loop;
5594 end if;
5595
5596 Arg := Next (Arg);
5597 end loop;
5598 end Check_Arg_Order;
5599
5600 --------------------------------
5601 -- Check_At_Least_N_Arguments --
5602 --------------------------------
5603
5604 procedure Check_At_Least_N_Arguments (N : Nat) is
5605 begin
5606 if Arg_Count < N then
5607 Error_Pragma ("too few arguments for pragma%");
5608 end if;
5609 end Check_At_Least_N_Arguments;
5610
5611 -------------------------------
5612 -- Check_At_Most_N_Arguments --
5613 -------------------------------
5614
5615 procedure Check_At_Most_N_Arguments (N : Nat) is
5616 Arg : Node_Id;
5617 begin
5618 if Arg_Count > N then
5619 Arg := Arg1;
5620 for J in 1 .. N loop
5621 Next (Arg);
5622 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
5623 end loop;
5624 end if;
5625 end Check_At_Most_N_Arguments;
5626
5627 ------------------------
5628 -- Check_Atomic_VFA --
5629 ------------------------
5630
5631 procedure Check_Atomic_VFA (E : Entity_Id; VFA : Boolean) is
5632
5633 Aliased_Subcomponent : exception;
5634 -- Exception raised if an aliased subcomponent is found in E
5635
5636 Independent_Subcomponent : exception;
5637 -- Exception raised if an independent subcomponent is found in E
5638
5639 procedure Check_Subcomponents (Typ : Entity_Id);
5640 -- Apply checks to subcomponents for Atomic and Volatile_Full_Access
5641
5642 -------------------------
5643 -- Check_Subcomponents --
5644 -------------------------
5645
5646 procedure Check_Subcomponents (Typ : Entity_Id) is
5647 Comp : Entity_Id;
5648
5649 begin
5650 if Is_Array_Type (Typ) then
5651 Comp := Component_Type (Typ);
5652
5653 -- For Atomic we accept any atomic subcomponents
5654
5655 if not VFA
5656 and then (Has_Atomic_Components (Typ)
5657 or else Is_Atomic (Comp))
5658 then
5659 null;
5660
5661 -- Give an error if the components are aliased
5662
5663 elsif Has_Aliased_Components (Typ)
5664 or else Is_Aliased (Comp)
5665 then
5666 raise Aliased_Subcomponent;
5667
5668 -- For VFA we accept non-aliased VFA subcomponents
5669
5670 elsif VFA
5671 and then Is_Volatile_Full_Access (Comp)
5672 then
5673 null;
5674
5675 -- Give an error if the components are independent
5676
5677 elsif Has_Independent_Components (Typ)
5678 or else Is_Independent (Comp)
5679 then
5680 raise Independent_Subcomponent;
5681 end if;
5682
5683 -- Recurse on the component type
5684
5685 Check_Subcomponents (Comp);
5686
5687 -- Note: Has_Aliased_Components, like Has_Atomic_Components,
5688 -- and Has_Independent_Components, applies only to arrays.
5689 -- However, this flag does not have a corresponding pragma, so
5690 -- perhaps it should be possible to apply it to record types as
5691 -- well. Should this be done ???
5692
5693 elsif Is_Record_Type (Typ) then
5694 -- It is possible to have an aliased discriminant, so they
5695 -- must be checked along with normal components.
5696
5697 Comp := First_Component_Or_Discriminant (Typ);
5698 while Present (Comp) loop
5699
5700 -- For Atomic we accept any atomic subcomponents
5701
5702 if not VFA
5703 and then (Is_Atomic (Comp)
5704 or else Is_Atomic (Etype (Comp)))
5705 then
5706 null;
5707
5708 -- Give an error if the component is aliased
5709
5710 elsif Is_Aliased (Comp)
5711 or else Is_Aliased (Etype (Comp))
5712 then
5713 raise Aliased_Subcomponent;
5714
5715 -- For VFA we accept non-aliased VFA subcomponents
5716
5717 elsif VFA
5718 and then (Is_Volatile_Full_Access (Comp)
5719 or else Is_Volatile_Full_Access (Etype (Comp)))
5720 then
5721 null;
5722
5723 -- Give an error if the component is independent
5724
5725 elsif Is_Independent (Comp)
5726 or else Is_Independent (Etype (Comp))
5727 then
5728 raise Independent_Subcomponent;
5729 end if;
5730
5731 -- Recurse on the component type
5732
5733 Check_Subcomponents (Etype (Comp));
5734
5735 Next_Component_Or_Discriminant (Comp);
5736 end loop;
5737 end if;
5738 end Check_Subcomponents;
5739
5740 Typ : Entity_Id;
5741
5742 begin
5743 -- Fetch the type in case we are dealing with an object or component
5744
5745 if Is_Type (E) then
5746 Typ := E;
5747 else
5748 pragma Assert (Is_Object (E)
5749 or else
5750 Nkind (Declaration_Node (E)) = N_Component_Declaration);
5751
5752 Typ := Etype (E);
5753 end if;
5754
5755 -- Check all the subcomponents of the type recursively, if any
5756
5757 Check_Subcomponents (Typ);
5758
5759 exception
5760 when Aliased_Subcomponent =>
5761 if VFA then
5762 Error_Pragma
5763 ("cannot apply Volatile_Full_Access with aliased "
5764 & "subcomponent ");
5765 else
5766 Error_Pragma
5767 ("cannot apply Atomic with aliased subcomponent "
5768 & "(RM C.6(13))");
5769 end if;
5770
5771 when Independent_Subcomponent =>
5772 if VFA then
5773 Error_Pragma
5774 ("cannot apply Volatile_Full_Access with independent "
5775 & "subcomponent ");
5776 else
5777 Error_Pragma
5778 ("cannot apply Atomic with independent subcomponent "
5779 & "(RM C.6(13))");
5780 end if;
5781
5782 when others =>
5783 raise Program_Error;
5784 end Check_Atomic_VFA;
5785
5786 ---------------------
5787 -- Check_Component --
5788 ---------------------
5789
5790 procedure Check_Component
5791 (Comp : Node_Id;
5792 UU_Typ : Entity_Id;
5793 In_Variant_Part : Boolean := False)
5794 is
5795 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
5796 Sindic : constant Node_Id :=
5797 Subtype_Indication (Component_Definition (Comp));
5798 Typ : constant Entity_Id := Etype (Comp_Id);
5799
5800 begin
5801 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
5802 -- object constraint, then the component type shall be an Unchecked_
5803 -- Union.
5804
5805 if Nkind (Sindic) = N_Subtype_Indication
5806 and then Has_Per_Object_Constraint (Comp_Id)
5807 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
5808 then
5809 Error_Msg_N
5810 ("component subtype subject to per-object constraint "
5811 & "must be an Unchecked_Union", Comp);
5812
5813 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
5814 -- the body of a generic unit, or within the body of any of its
5815 -- descendant library units, no part of the type of a component
5816 -- declared in a variant_part of the unchecked union type shall be of
5817 -- a formal private type or formal private extension declared within
5818 -- the formal part of the generic unit.
5819
5820 elsif Ada_Version >= Ada_2012
5821 and then In_Generic_Body (UU_Typ)
5822 and then In_Variant_Part
5823 and then Is_Private_Type (Typ)
5824 and then Is_Generic_Type (Typ)
5825 then
5826 Error_Msg_N
5827 ("component of unchecked union cannot be of generic type", Comp);
5828
5829 elsif Needs_Finalization (Typ) then
5830 Error_Msg_N
5831 ("component of unchecked union cannot be controlled", Comp);
5832
5833 elsif Has_Task (Typ) then
5834 Error_Msg_N
5835 ("component of unchecked union cannot have tasks", Comp);
5836 end if;
5837 end Check_Component;
5838
5839 ----------------------------
5840 -- Check_Duplicate_Pragma --
5841 ----------------------------
5842
5843 procedure Check_Duplicate_Pragma (E : Entity_Id) is
5844 Id : Entity_Id := E;
5845 P : Node_Id;
5846
5847 begin
5848 -- Nothing to do if this pragma comes from an aspect specification,
5849 -- since we could not be duplicating a pragma, and we dealt with the
5850 -- case of duplicated aspects in Analyze_Aspect_Specifications.
5851
5852 if From_Aspect_Specification (N) then
5853 return;
5854 end if;
5855
5856 -- Otherwise current pragma may duplicate previous pragma or a
5857 -- previously given aspect specification or attribute definition
5858 -- clause for the same pragma.
5859
5860 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
5861
5862 if Present (P) then
5863
5864 -- If the entity is a type, then we have to make sure that the
5865 -- ostensible duplicate is not for a parent type from which this
5866 -- type is derived.
5867
5868 if Is_Type (E) then
5869 if Nkind (P) = N_Pragma then
5870 declare
5871 Args : constant List_Id :=
5872 Pragma_Argument_Associations (P);
5873 begin
5874 if Present (Args)
5875 and then Is_Entity_Name (Expression (First (Args)))
5876 and then Is_Type (Entity (Expression (First (Args))))
5877 and then Entity (Expression (First (Args))) /= E
5878 then
5879 return;
5880 end if;
5881 end;
5882
5883 elsif Nkind (P) = N_Aspect_Specification
5884 and then Is_Type (Entity (P))
5885 and then Entity (P) /= E
5886 then
5887 return;
5888 end if;
5889 end if;
5890
5891 -- Here we have a definite duplicate
5892
5893 Error_Msg_Name_1 := Pragma_Name (N);
5894 Error_Msg_Sloc := Sloc (P);
5895
5896 -- For a single protected or a single task object, the error is
5897 -- issued on the original entity.
5898
5899 if Ekind (Id) in E_Task_Type | E_Protected_Type then
5900 Id := Defining_Identifier (Original_Node (Parent (Id)));
5901 end if;
5902
5903 if Nkind (P) = N_Aspect_Specification
5904 or else From_Aspect_Specification (P)
5905 then
5906 Error_Msg_NE ("aspect% for & previously given#", N, Id);
5907 else
5908 -- If -gnatwr is set, warn in case of a duplicate pragma
5909 -- [No_]Inline which is suspicious but not an error, generate
5910 -- an error for other pragmas.
5911
5912 if Pragma_Name (N) in Name_Inline | Name_No_Inline then
5913 if Warn_On_Redundant_Constructs then
5914 Error_Msg_NE
5915 ("?r?pragma% for & duplicates pragma#", N, Id);
5916 end if;
5917 else
5918 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
5919 end if;
5920 end if;
5921
5922 raise Pragma_Exit;
5923 end if;
5924 end Check_Duplicate_Pragma;
5925
5926 ----------------------------------
5927 -- Check_Duplicated_Export_Name --
5928 ----------------------------------
5929
5930 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
5931 String_Val : constant String_Id := Strval (Nam);
5932
5933 begin
5934 -- We are only interested in the export case, and in the case of
5935 -- generics, it is the instance, not the template, that is the
5936 -- problem (the template will generate a warning in any case).
5937
5938 if not Inside_A_Generic
5939 and then (Prag_Id = Pragma_Export
5940 or else
5941 Prag_Id = Pragma_Export_Procedure
5942 or else
5943 Prag_Id = Pragma_Export_Valued_Procedure
5944 or else
5945 Prag_Id = Pragma_Export_Function)
5946 then
5947 for J in Externals.First .. Externals.Last loop
5948 if String_Equal (String_Val, Strval (Externals.Table (J))) then
5949 Error_Msg_Sloc := Sloc (Externals.Table (J));
5950 Error_Msg_N ("external name duplicates name given#", Nam);
5951 exit;
5952 end if;
5953 end loop;
5954
5955 Externals.Append (Nam);
5956 end if;
5957 end Check_Duplicated_Export_Name;
5958
5959 ----------------------------------------
5960 -- Check_Expr_Is_OK_Static_Expression --
5961 ----------------------------------------
5962
5963 procedure Check_Expr_Is_OK_Static_Expression
5964 (Expr : Node_Id;
5965 Typ : Entity_Id := Empty)
5966 is
5967 begin
5968 if Present (Typ) then
5969 Analyze_And_Resolve (Expr, Typ);
5970 else
5971 Analyze_And_Resolve (Expr);
5972 end if;
5973
5974 -- An expression cannot be considered static if its resolution failed
5975 -- or if it's erroneous. Stop the analysis of the related pragma.
5976
5977 if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
5978 raise Pragma_Exit;
5979
5980 elsif Is_OK_Static_Expression (Expr) then
5981 return;
5982
5983 -- An interesting special case, if we have a string literal and we
5984 -- are in Ada 83 mode, then we allow it even though it will not be
5985 -- flagged as static. This allows the use of Ada 95 pragmas like
5986 -- Import in Ada 83 mode. They will of course be flagged with
5987 -- warnings as usual, but will not cause errors.
5988
5989 elsif Ada_Version = Ada_83
5990 and then Nkind (Expr) = N_String_Literal
5991 then
5992 return;
5993
5994 -- Finally, we have a real error
5995
5996 else
5997 Error_Msg_Name_1 := Pname;
5998 Flag_Non_Static_Expr
5999 (Fix_Error ("argument for pragma% must be a static expression!"),
6000 Expr);
6001 raise Pragma_Exit;
6002 end if;
6003 end Check_Expr_Is_OK_Static_Expression;
6004
6005 -------------------------
6006 -- Check_First_Subtype --
6007 -------------------------
6008
6009 procedure Check_First_Subtype (Arg : Node_Id) is
6010 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6011 Ent : constant Entity_Id := Entity (Argx);
6012
6013 begin
6014 if Is_First_Subtype (Ent) then
6015 null;
6016
6017 elsif Is_Type (Ent) then
6018 Error_Pragma_Arg
6019 ("pragma% cannot apply to subtype", Argx);
6020
6021 elsif Is_Object (Ent) then
6022 Error_Pragma_Arg
6023 ("pragma% cannot apply to object, requires a type", Argx);
6024
6025 else
6026 Error_Pragma_Arg
6027 ("pragma% cannot apply to&, requires a type", Argx);
6028 end if;
6029 end Check_First_Subtype;
6030
6031 ----------------------
6032 -- Check_Identifier --
6033 ----------------------
6034
6035 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
6036 begin
6037 if Present (Arg)
6038 and then Nkind (Arg) = N_Pragma_Argument_Association
6039 then
6040 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
6041 Error_Msg_Name_1 := Pname;
6042 Error_Msg_Name_2 := Id;
6043 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6044 raise Pragma_Exit;
6045 end if;
6046 end if;
6047 end Check_Identifier;
6048
6049 --------------------------------
6050 -- Check_Identifier_Is_One_Of --
6051 --------------------------------
6052
6053 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
6054 begin
6055 if Present (Arg)
6056 and then Nkind (Arg) = N_Pragma_Argument_Association
6057 then
6058 if Chars (Arg) = No_Name then
6059 Error_Msg_Name_1 := Pname;
6060 Error_Msg_N ("pragma% argument expects an identifier", Arg);
6061 raise Pragma_Exit;
6062
6063 elsif Chars (Arg) /= N1
6064 and then Chars (Arg) /= N2
6065 then
6066 Error_Msg_Name_1 := Pname;
6067 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
6068 raise Pragma_Exit;
6069 end if;
6070 end if;
6071 end Check_Identifier_Is_One_Of;
6072
6073 ---------------------------
6074 -- Check_In_Main_Program --
6075 ---------------------------
6076
6077 procedure Check_In_Main_Program is
6078 P : constant Node_Id := Parent (N);
6079
6080 begin
6081 -- Must be in subprogram body
6082
6083 if Nkind (P) /= N_Subprogram_Body then
6084 Error_Pragma ("% pragma allowed only in subprogram");
6085
6086 -- Otherwise warn if obviously not main program
6087
6088 elsif Present (Parameter_Specifications (Specification (P)))
6089 or else not Is_Compilation_Unit (Defining_Entity (P))
6090 then
6091 Error_Msg_Name_1 := Pname;
6092 Error_Msg_N
6093 ("??pragma% is only effective in main program", N);
6094 end if;
6095 end Check_In_Main_Program;
6096
6097 ---------------------------------------
6098 -- Check_Interrupt_Or_Attach_Handler --
6099 ---------------------------------------
6100
6101 procedure Check_Interrupt_Or_Attach_Handler is
6102 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
6103 Handler_Proc, Proc_Scope : Entity_Id;
6104
6105 begin
6106 Analyze (Arg1_X);
6107
6108 if Prag_Id = Pragma_Interrupt_Handler then
6109 Check_Restriction (No_Dynamic_Attachment, N);
6110 end if;
6111
6112 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
6113 Proc_Scope := Scope (Handler_Proc);
6114
6115 if Ekind (Proc_Scope) /= E_Protected_Type then
6116 Error_Pragma_Arg
6117 ("argument of pragma% must be protected procedure", Arg1);
6118 end if;
6119
6120 -- For pragma case (as opposed to access case), check placement.
6121 -- We don't need to do that for aspects, because we have the
6122 -- check that they aspect applies an appropriate procedure.
6123
6124 if not From_Aspect_Specification (N)
6125 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
6126 then
6127 Error_Pragma ("pragma% must be in protected definition");
6128 end if;
6129
6130 if not Is_Library_Level_Entity (Proc_Scope) then
6131 Error_Pragma_Arg
6132 ("argument for pragma% must be library level entity", Arg1);
6133 end if;
6134
6135 -- AI05-0033: A pragma cannot appear within a generic body, because
6136 -- instance can be in a nested scope. The check that protected type
6137 -- is itself a library-level declaration is done elsewhere.
6138
6139 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
6140 -- handle code prior to AI-0033. Analysis tools typically are not
6141 -- interested in this pragma in any case, so no need to worry too
6142 -- much about its placement.
6143
6144 if Inside_A_Generic then
6145 if Ekind (Scope (Current_Scope)) = E_Generic_Package
6146 and then In_Package_Body (Scope (Current_Scope))
6147 and then not Relaxed_RM_Semantics
6148 then
6149 Error_Pragma ("pragma% cannot be used inside a generic");
6150 end if;
6151 end if;
6152 end Check_Interrupt_Or_Attach_Handler;
6153
6154 ---------------------------------
6155 -- Check_Loop_Pragma_Placement --
6156 ---------------------------------
6157
6158 procedure Check_Loop_Pragma_Placement is
6159 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
6160 -- Verify whether the current pragma is properly grouped with other
6161 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
6162 -- related loop where the pragma appears.
6163
6164 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
6165 -- Determine whether an arbitrary statement Stmt denotes pragma
6166 -- Loop_Invariant or Loop_Variant.
6167
6168 procedure Placement_Error (Constr : Node_Id);
6169 pragma No_Return (Placement_Error);
6170 -- Node Constr denotes the last loop restricted construct before we
6171 -- encountered an illegal relation between enclosing constructs. Emit
6172 -- an error depending on what Constr was.
6173
6174 --------------------------------
6175 -- Check_Loop_Pragma_Grouping --
6176 --------------------------------
6177
6178 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
6179 Stop_Search : exception;
6180 -- This exception is used to terminate the recursive descent of
6181 -- routine Check_Grouping.
6182
6183 procedure Check_Grouping (L : List_Id);
6184 -- Find the first group of pragmas in list L and if successful,
6185 -- ensure that the current pragma is part of that group. The
6186 -- routine raises Stop_Search once such a check is performed to
6187 -- halt the recursive descent.
6188
6189 procedure Grouping_Error (Prag : Node_Id);
6190 pragma No_Return (Grouping_Error);
6191 -- Emit an error concerning the current pragma indicating that it
6192 -- should be placed after pragma Prag.
6193
6194 --------------------
6195 -- Check_Grouping --
6196 --------------------
6197
6198 procedure Check_Grouping (L : List_Id) is
6199 HSS : Node_Id;
6200 Stmt : Node_Id;
6201 Prag : Node_Id := Empty; -- init to avoid warning
6202
6203 begin
6204 -- Inspect the list of declarations or statements looking for
6205 -- the first grouping of pragmas:
6206
6207 -- loop
6208 -- pragma Loop_Invariant ...;
6209 -- pragma Loop_Variant ...;
6210 -- . . . -- (1)
6211 -- pragma Loop_Variant ...; -- current pragma
6212
6213 -- If the current pragma is not in the grouping, then it must
6214 -- either appear in a different declarative or statement list
6215 -- or the construct at (1) is separating the pragma from the
6216 -- grouping.
6217
6218 Stmt := First (L);
6219 while Present (Stmt) loop
6220
6221 -- First pragma of the first topmost grouping has been found
6222
6223 if Is_Loop_Pragma (Stmt) then
6224
6225 -- The group and the current pragma are not in the same
6226 -- declarative or statement list.
6227
6228 if List_Containing (Stmt) /= List_Containing (N) then
6229 Grouping_Error (Stmt);
6230
6231 -- Try to reach the current pragma from the first pragma
6232 -- of the grouping while skipping other members:
6233
6234 -- pragma Loop_Invariant ...; -- first pragma
6235 -- pragma Loop_Variant ...; -- member
6236 -- . . .
6237 -- pragma Loop_Variant ...; -- current pragma
6238
6239 else
6240 while Present (Stmt) loop
6241 -- The current pragma is either the first pragma
6242 -- of the group or is a member of the group.
6243 -- Stop the search as the placement is legal.
6244
6245 if Stmt = N then
6246 raise Stop_Search;
6247
6248 -- Skip group members, but keep track of the
6249 -- last pragma in the group.
6250
6251 elsif Is_Loop_Pragma (Stmt) then
6252 Prag := Stmt;
6253
6254 -- Skip declarations and statements generated by
6255 -- the compiler during expansion. Note that some
6256 -- source statements (e.g. pragma Assert) may have
6257 -- been transformed so that they do not appear as
6258 -- coming from source anymore, so we instead look
6259 -- at their Original_Node.
6260
6261 elsif not Comes_From_Source (Original_Node (Stmt))
6262 then
6263 null;
6264
6265 -- A non-pragma is separating the group from the
6266 -- current pragma, the placement is illegal.
6267
6268 else
6269 Grouping_Error (Prag);
6270 end if;
6271
6272 Next (Stmt);
6273 end loop;
6274
6275 -- If the traversal did not reach the current pragma,
6276 -- then the list must be malformed.
6277
6278 raise Program_Error;
6279 end if;
6280
6281 -- Pragmas Loop_Invariant and Loop_Variant may only appear
6282 -- inside a loop or a block housed inside a loop. Inspect
6283 -- the declarations and statements of the block as they may
6284 -- contain the first grouping. This case follows the one for
6285 -- loop pragmas, as block statements which originate in a
6286 -- loop pragma (and so Is_Loop_Pragma will return True on
6287 -- that block statement) should be treated in the previous
6288 -- case.
6289
6290 elsif Nkind (Stmt) = N_Block_Statement then
6291 HSS := Handled_Statement_Sequence (Stmt);
6292
6293 Check_Grouping (Declarations (Stmt));
6294
6295 if Present (HSS) then
6296 Check_Grouping (Statements (HSS));
6297 end if;
6298 end if;
6299
6300 Next (Stmt);
6301 end loop;
6302 end Check_Grouping;
6303
6304 --------------------
6305 -- Grouping_Error --
6306 --------------------
6307
6308 procedure Grouping_Error (Prag : Node_Id) is
6309 begin
6310 Error_Msg_Sloc := Sloc (Prag);
6311 Error_Pragma ("pragma% must appear next to pragma#");
6312 end Grouping_Error;
6313
6314 -- Start of processing for Check_Loop_Pragma_Grouping
6315
6316 begin
6317 -- Inspect the statements of the loop or nested blocks housed
6318 -- within to determine whether the current pragma is part of the
6319 -- first topmost grouping of Loop_Invariant and Loop_Variant.
6320
6321 Check_Grouping (Statements (Loop_Stmt));
6322
6323 exception
6324 when Stop_Search => null;
6325 end Check_Loop_Pragma_Grouping;
6326
6327 --------------------
6328 -- Is_Loop_Pragma --
6329 --------------------
6330
6331 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
6332 begin
6333 -- Inspect the original node as Loop_Invariant and Loop_Variant
6334 -- pragmas are rewritten to null when assertions are disabled.
6335
6336 if Nkind (Original_Node (Stmt)) = N_Pragma then
6337 return
6338 Pragma_Name_Unmapped (Original_Node (Stmt))
6339 in Name_Loop_Invariant | Name_Loop_Variant;
6340 else
6341 return False;
6342 end if;
6343 end Is_Loop_Pragma;
6344
6345 ---------------------
6346 -- Placement_Error --
6347 ---------------------
6348
6349 procedure Placement_Error (Constr : Node_Id) is
6350 LA : constant String := " with Loop_Entry";
6351
6352 begin
6353 if Prag_Id = Pragma_Assert then
6354 Error_Msg_String (1 .. LA'Length) := LA;
6355 Error_Msg_Strlen := LA'Length;
6356 else
6357 Error_Msg_Strlen := 0;
6358 end if;
6359
6360 if Nkind (Constr) = N_Pragma then
6361 Error_Pragma
6362 ("pragma %~ must appear immediately within the statements "
6363 & "of a loop");
6364 else
6365 Error_Pragma_Arg
6366 ("block containing pragma %~ must appear immediately within "
6367 & "the statements of a loop", Constr);
6368 end if;
6369 end Placement_Error;
6370
6371 -- Local declarations
6372
6373 Prev : Node_Id;
6374 Stmt : Node_Id;
6375
6376 -- Start of processing for Check_Loop_Pragma_Placement
6377
6378 begin
6379 -- Check that pragma appears immediately within a loop statement,
6380 -- ignoring intervening block statements.
6381
6382 Prev := N;
6383 Stmt := Parent (N);
6384 while Present (Stmt) loop
6385
6386 -- The pragma or previous block must appear immediately within the
6387 -- current block's declarative or statement part.
6388
6389 if Nkind (Stmt) = N_Block_Statement then
6390 if (No (Declarations (Stmt))
6391 or else List_Containing (Prev) /= Declarations (Stmt))
6392 and then
6393 List_Containing (Prev) /=
6394 Statements (Handled_Statement_Sequence (Stmt))
6395 then
6396 Placement_Error (Prev);
6397 return;
6398
6399 -- Keep inspecting the parents because we are now within a
6400 -- chain of nested blocks.
6401
6402 else
6403 Prev := Stmt;
6404 Stmt := Parent (Stmt);
6405 end if;
6406
6407 -- The pragma or previous block must appear immediately within the
6408 -- statements of the loop.
6409
6410 elsif Nkind (Stmt) = N_Loop_Statement then
6411 if List_Containing (Prev) /= Statements (Stmt) then
6412 Placement_Error (Prev);
6413 end if;
6414
6415 -- Stop the traversal because we reached the innermost loop
6416 -- regardless of whether we encountered an error or not.
6417
6418 exit;
6419
6420 -- Ignore a handled statement sequence. Note that this node may
6421 -- be related to a subprogram body in which case we will emit an
6422 -- error on the next iteration of the search.
6423
6424 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
6425 Stmt := Parent (Stmt);
6426
6427 -- Any other statement breaks the chain from the pragma to the
6428 -- loop.
6429
6430 else
6431 Placement_Error (Prev);
6432 return;
6433 end if;
6434 end loop;
6435
6436 -- Check that the current pragma Loop_Invariant or Loop_Variant is
6437 -- grouped together with other such pragmas.
6438
6439 if Is_Loop_Pragma (N) then
6440
6441 -- The previous check should have located the related loop
6442
6443 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
6444 Check_Loop_Pragma_Grouping (Stmt);
6445 end if;
6446 end Check_Loop_Pragma_Placement;
6447
6448 -------------------------------------------
6449 -- Check_Is_In_Decl_Part_Or_Package_Spec --
6450 -------------------------------------------
6451
6452 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
6453 P : Node_Id;
6454
6455 begin
6456 P := Parent (N);
6457 loop
6458 if No (P) then
6459 exit;
6460
6461 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
6462 exit;
6463
6464 elsif Nkind (P) in N_Package_Specification | N_Block_Statement then
6465 return;
6466
6467 -- Note: the following tests seem a little peculiar, because
6468 -- they test for bodies, but if we were in the statement part
6469 -- of the body, we would already have hit the handled statement
6470 -- sequence, so the only way we get here is by being in the
6471 -- declarative part of the body.
6472
6473 elsif Nkind (P) in
6474 N_Subprogram_Body | N_Package_Body | N_Task_Body | N_Entry_Body
6475 then
6476 return;
6477 end if;
6478
6479 P := Parent (P);
6480 end loop;
6481
6482 Error_Pragma ("pragma% is not in declarative part or package spec");
6483 end Check_Is_In_Decl_Part_Or_Package_Spec;
6484
6485 -------------------------
6486 -- Check_No_Identifier --
6487 -------------------------
6488
6489 procedure Check_No_Identifier (Arg : Node_Id) is
6490 begin
6491 if Nkind (Arg) = N_Pragma_Argument_Association
6492 and then Chars (Arg) /= No_Name
6493 then
6494 Error_Pragma_Arg_Ident
6495 ("pragma% does not permit identifier& here", Arg);
6496 end if;
6497 end Check_No_Identifier;
6498
6499 --------------------------
6500 -- Check_No_Identifiers --
6501 --------------------------
6502
6503 procedure Check_No_Identifiers is
6504 Arg_Node : Node_Id;
6505 begin
6506 Arg_Node := Arg1;
6507 for J in 1 .. Arg_Count loop
6508 Check_No_Identifier (Arg_Node);
6509 Next (Arg_Node);
6510 end loop;
6511 end Check_No_Identifiers;
6512
6513 ------------------------
6514 -- Check_No_Link_Name --
6515 ------------------------
6516
6517 procedure Check_No_Link_Name is
6518 begin
6519 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
6520 Arg4 := Arg3;
6521 end if;
6522
6523 if Present (Arg4) then
6524 Error_Pragma_Arg
6525 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
6526 end if;
6527 end Check_No_Link_Name;
6528
6529 -------------------------------
6530 -- Check_Optional_Identifier --
6531 -------------------------------
6532
6533 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
6534 begin
6535 if Present (Arg)
6536 and then Nkind (Arg) = N_Pragma_Argument_Association
6537 and then Chars (Arg) /= No_Name
6538 then
6539 if Chars (Arg) /= Id then
6540 Error_Msg_Name_1 := Pname;
6541 Error_Msg_Name_2 := Id;
6542 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6543 raise Pragma_Exit;
6544 end if;
6545 end if;
6546 end Check_Optional_Identifier;
6547
6548 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
6549 begin
6550 Check_Optional_Identifier (Arg, Name_Find (Id));
6551 end Check_Optional_Identifier;
6552
6553 -------------------------------------
6554 -- Check_Static_Boolean_Expression --
6555 -------------------------------------
6556
6557 procedure Check_Static_Boolean_Expression (Expr : Node_Id) is
6558 begin
6559 if Present (Expr) then
6560 Analyze_And_Resolve (Expr, Standard_Boolean);
6561
6562 if not Is_OK_Static_Expression (Expr) then
6563 Error_Pragma_Arg
6564 ("expression of pragma % must be static", Expr);
6565 end if;
6566 end if;
6567 end Check_Static_Boolean_Expression;
6568
6569 -----------------------------
6570 -- Check_Static_Constraint --
6571 -----------------------------
6572
6573 -- Note: for convenience in writing this procedure, in addition to
6574 -- the officially (i.e. by spec) allowed argument which is always a
6575 -- constraint, it also allows ranges and discriminant associations.
6576 -- Above is not clear ???
6577
6578 procedure Check_Static_Constraint (Constr : Node_Id) is
6579
6580 procedure Require_Static (E : Node_Id);
6581 -- Require given expression to be static expression
6582
6583 --------------------
6584 -- Require_Static --
6585 --------------------
6586
6587 procedure Require_Static (E : Node_Id) is
6588 begin
6589 if not Is_OK_Static_Expression (E) then
6590 Flag_Non_Static_Expr
6591 ("non-static constraint not allowed in Unchecked_Union!", E);
6592 raise Pragma_Exit;
6593 end if;
6594 end Require_Static;
6595
6596 -- Start of processing for Check_Static_Constraint
6597
6598 begin
6599 case Nkind (Constr) is
6600 when N_Discriminant_Association =>
6601 Require_Static (Expression (Constr));
6602
6603 when N_Range =>
6604 Require_Static (Low_Bound (Constr));
6605 Require_Static (High_Bound (Constr));
6606
6607 when N_Attribute_Reference =>
6608 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
6609 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
6610
6611 when N_Range_Constraint =>
6612 Check_Static_Constraint (Range_Expression (Constr));
6613
6614 when N_Index_Or_Discriminant_Constraint =>
6615 declare
6616 IDC : Entity_Id;
6617 begin
6618 IDC := First (Constraints (Constr));
6619 while Present (IDC) loop
6620 Check_Static_Constraint (IDC);
6621 Next (IDC);
6622 end loop;
6623 end;
6624
6625 when others =>
6626 null;
6627 end case;
6628 end Check_Static_Constraint;
6629
6630 --------------------------------------
6631 -- Check_Valid_Configuration_Pragma --
6632 --------------------------------------
6633
6634 -- A configuration pragma must appear in the context clause of a
6635 -- compilation unit, and only other pragmas may precede it. Note that
6636 -- the test also allows use in a configuration pragma file.
6637
6638 procedure Check_Valid_Configuration_Pragma is
6639 begin
6640 if not Is_Configuration_Pragma then
6641 Error_Pragma ("incorrect placement for configuration pragma%");
6642 end if;
6643 end Check_Valid_Configuration_Pragma;
6644
6645 -------------------------------------
6646 -- Check_Valid_Library_Unit_Pragma --
6647 -------------------------------------
6648
6649 procedure Check_Valid_Library_Unit_Pragma is
6650 Plist : List_Id;
6651 Parent_Node : Node_Id;
6652 Unit_Name : Entity_Id;
6653 Unit_Kind : Node_Kind;
6654 Unit_Node : Node_Id;
6655 Sindex : Source_File_Index;
6656
6657 begin
6658 if not Is_List_Member (N) then
6659 Pragma_Misplaced;
6660
6661 else
6662 Plist := List_Containing (N);
6663 Parent_Node := Parent (Plist);
6664
6665 if Parent_Node = Empty then
6666 Pragma_Misplaced;
6667
6668 -- Case of pragma appearing after a compilation unit. In this case
6669 -- it must have an argument with the corresponding name and must
6670 -- be part of the following pragmas of its parent.
6671
6672 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
6673 if Plist /= Pragmas_After (Parent_Node) then
6674 Pragma_Misplaced;
6675
6676 elsif Arg_Count = 0 then
6677 Error_Pragma
6678 ("argument required if outside compilation unit");
6679
6680 else
6681 Check_No_Identifiers;
6682 Check_Arg_Count (1);
6683 Unit_Node := Unit (Parent (Parent_Node));
6684 Unit_Kind := Nkind (Unit_Node);
6685
6686 Analyze (Get_Pragma_Arg (Arg1));
6687
6688 if Unit_Kind = N_Generic_Subprogram_Declaration
6689 or else Unit_Kind = N_Subprogram_Declaration
6690 then
6691 Unit_Name := Defining_Entity (Unit_Node);
6692
6693 elsif Unit_Kind in N_Generic_Instantiation then
6694 Unit_Name := Defining_Entity (Unit_Node);
6695
6696 else
6697 Unit_Name := Cunit_Entity (Current_Sem_Unit);
6698 end if;
6699
6700 if Chars (Unit_Name) /=
6701 Chars (Entity (Get_Pragma_Arg (Arg1)))
6702 then
6703 Error_Pragma_Arg
6704 ("pragma% argument is not current unit name", Arg1);
6705 end if;
6706
6707 if Ekind (Unit_Name) = E_Package
6708 and then Present (Renamed_Entity (Unit_Name))
6709 then
6710 Error_Pragma ("pragma% not allowed for renamed package");
6711 end if;
6712 end if;
6713
6714 -- Pragma appears other than after a compilation unit
6715
6716 else
6717 -- Here we check for the generic instantiation case and also
6718 -- for the case of processing a generic formal package. We
6719 -- detect these cases by noting that the Sloc on the node
6720 -- does not belong to the current compilation unit.
6721
6722 Sindex := Source_Index (Current_Sem_Unit);
6723
6724 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
6725 Rewrite (N, Make_Null_Statement (Loc));
6726 return;
6727
6728 -- If before first declaration, the pragma applies to the
6729 -- enclosing unit, and the name if present must be this name.
6730
6731 elsif Is_Before_First_Decl (N, Plist) then
6732 Unit_Node := Unit_Declaration_Node (Current_Scope);
6733 Unit_Kind := Nkind (Unit_Node);
6734
6735 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
6736 Pragma_Misplaced;
6737
6738 elsif Unit_Kind = N_Subprogram_Body
6739 and then not Acts_As_Spec (Unit_Node)
6740 then
6741 Pragma_Misplaced;
6742
6743 elsif Nkind (Parent_Node) = N_Package_Body then
6744 Pragma_Misplaced;
6745
6746 elsif Nkind (Parent_Node) = N_Package_Specification
6747 and then Plist = Private_Declarations (Parent_Node)
6748 then
6749 Pragma_Misplaced;
6750
6751 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
6752 or else Nkind (Parent_Node) =
6753 N_Generic_Subprogram_Declaration)
6754 and then Plist = Generic_Formal_Declarations (Parent_Node)
6755 then
6756 Pragma_Misplaced;
6757
6758 elsif Arg_Count > 0 then
6759 Analyze (Get_Pragma_Arg (Arg1));
6760
6761 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
6762 Error_Pragma_Arg
6763 ("name in pragma% must be enclosing unit", Arg1);
6764 end if;
6765
6766 -- It is legal to have no argument in this context
6767
6768 else
6769 return;
6770 end if;
6771
6772 -- Error if not before first declaration. This is because a
6773 -- library unit pragma argument must be the name of a library
6774 -- unit (RM 10.1.5(7)), but the only names permitted in this
6775 -- context are (RM 10.1.5(6)) names of subprogram declarations,
6776 -- generic subprogram declarations or generic instantiations.
6777
6778 else
6779 Error_Pragma
6780 ("pragma% misplaced, must be before first declaration");
6781 end if;
6782 end if;
6783 end if;
6784 end Check_Valid_Library_Unit_Pragma;
6785
6786 -------------------
6787 -- Check_Variant --
6788 -------------------
6789
6790 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
6791 Clist : constant Node_Id := Component_List (Variant);
6792 Comp : Node_Id;
6793
6794 begin
6795 Comp := First_Non_Pragma (Component_Items (Clist));
6796 while Present (Comp) loop
6797 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
6798 Next_Non_Pragma (Comp);
6799 end loop;
6800 end Check_Variant;
6801
6802 ---------------------------
6803 -- Ensure_Aggregate_Form --
6804 ---------------------------
6805
6806 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
6807 CFSD : constant Boolean := Get_Comes_From_Source_Default;
6808 Expr : constant Node_Id := Expression (Arg);
6809 Loc : constant Source_Ptr := Sloc (Expr);
6810 Comps : List_Id := No_List;
6811 Exprs : List_Id := No_List;
6812 Nam : Name_Id := No_Name;
6813 Nam_Loc : Source_Ptr;
6814
6815 begin
6816 -- The pragma argument is in positional form:
6817
6818 -- pragma Depends (Nam => ...)
6819 -- ^
6820 -- Chars field
6821
6822 -- Note that the Sloc of the Chars field is the Sloc of the pragma
6823 -- argument association.
6824
6825 if Nkind (Arg) = N_Pragma_Argument_Association then
6826 Nam := Chars (Arg);
6827 Nam_Loc := Sloc (Arg);
6828
6829 -- Remove the pragma argument name as this will be captured in the
6830 -- aggregate.
6831
6832 Set_Chars (Arg, No_Name);
6833 end if;
6834
6835 -- The argument is already in aggregate form, but the presence of a
6836 -- name causes this to be interpreted as named association which in
6837 -- turn must be converted into an aggregate.
6838
6839 -- pragma Global (In_Out => (A, B, C))
6840 -- ^ ^
6841 -- name aggregate
6842
6843 -- pragma Global ((In_Out => (A, B, C)))
6844 -- ^ ^
6845 -- aggregate aggregate
6846
6847 if Nkind (Expr) = N_Aggregate then
6848 if Nam = No_Name then
6849 return;
6850 end if;
6851
6852 -- Do not transform a null argument into an aggregate as N_Null has
6853 -- special meaning in formal verification pragmas.
6854
6855 elsif Nkind (Expr) = N_Null then
6856 return;
6857 end if;
6858
6859 -- Everything comes from source if the original comes from source
6860
6861 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
6862
6863 -- Positional argument is transformed into an aggregate with an
6864 -- Expressions list.
6865
6866 if Nam = No_Name then
6867 Exprs := New_List (Relocate_Node (Expr));
6868
6869 -- An associative argument is transformed into an aggregate with
6870 -- Component_Associations.
6871
6872 else
6873 Comps := New_List (
6874 Make_Component_Association (Loc,
6875 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
6876 Expression => Relocate_Node (Expr)));
6877 end if;
6878
6879 Set_Expression (Arg,
6880 Make_Aggregate (Loc,
6881 Component_Associations => Comps,
6882 Expressions => Exprs));
6883
6884 -- Restore Comes_From_Source default
6885
6886 Set_Comes_From_Source_Default (CFSD);
6887 end Ensure_Aggregate_Form;
6888
6889 ------------------
6890 -- Error_Pragma --
6891 ------------------
6892
6893 procedure Error_Pragma (Msg : String) is
6894 begin
6895 Error_Msg_Name_1 := Pname;
6896 Error_Msg_N (Fix_Error (Msg), N);
6897 raise Pragma_Exit;
6898 end Error_Pragma;
6899
6900 ----------------------
6901 -- Error_Pragma_Arg --
6902 ----------------------
6903
6904 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
6905 begin
6906 Error_Msg_Name_1 := Pname;
6907 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
6908 raise Pragma_Exit;
6909 end Error_Pragma_Arg;
6910
6911 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
6912 begin
6913 Error_Msg_Name_1 := Pname;
6914 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
6915 Error_Pragma_Arg (Msg2, Arg);
6916 end Error_Pragma_Arg;
6917
6918 ----------------------------
6919 -- Error_Pragma_Arg_Ident --
6920 ----------------------------
6921
6922 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
6923 begin
6924 Error_Msg_Name_1 := Pname;
6925 Error_Msg_N (Fix_Error (Msg), Arg);
6926 raise Pragma_Exit;
6927 end Error_Pragma_Arg_Ident;
6928
6929 ----------------------
6930 -- Error_Pragma_Ref --
6931 ----------------------
6932
6933 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
6934 begin
6935 Error_Msg_Name_1 := Pname;
6936 Error_Msg_Sloc := Sloc (Ref);
6937 Error_Msg_NE (Fix_Error (Msg), N, Ref);
6938 raise Pragma_Exit;
6939 end Error_Pragma_Ref;
6940
6941 ------------------------
6942 -- Find_Lib_Unit_Name --
6943 ------------------------
6944
6945 function Find_Lib_Unit_Name return Entity_Id is
6946 begin
6947 -- Return inner compilation unit entity, for case of nested
6948 -- categorization pragmas. This happens in generic unit.
6949
6950 if Nkind (Parent (N)) = N_Package_Specification
6951 and then Defining_Entity (Parent (N)) /= Current_Scope
6952 then
6953 return Defining_Entity (Parent (N));
6954 else
6955 return Current_Scope;
6956 end if;
6957 end Find_Lib_Unit_Name;
6958
6959 ----------------------------
6960 -- Find_Program_Unit_Name --
6961 ----------------------------
6962
6963 procedure Find_Program_Unit_Name (Id : Node_Id) is
6964 Unit_Name : Entity_Id;
6965 Unit_Kind : Node_Kind;
6966 P : constant Node_Id := Parent (N);
6967
6968 begin
6969 if Nkind (P) = N_Compilation_Unit then
6970 Unit_Kind := Nkind (Unit (P));
6971
6972 if Unit_Kind in N_Subprogram_Declaration
6973 | N_Package_Declaration
6974 | N_Generic_Declaration
6975 then
6976 Unit_Name := Defining_Entity (Unit (P));
6977
6978 if Chars (Id) = Chars (Unit_Name) then
6979 Set_Entity (Id, Unit_Name);
6980 Set_Etype (Id, Etype (Unit_Name));
6981 else
6982 Set_Etype (Id, Any_Type);
6983 Error_Pragma
6984 ("cannot find program unit referenced by pragma%");
6985 end if;
6986
6987 else
6988 Set_Etype (Id, Any_Type);
6989 Error_Pragma ("pragma% inapplicable to this unit");
6990 end if;
6991
6992 else
6993 Analyze (Id);
6994 end if;
6995 end Find_Program_Unit_Name;
6996
6997 -----------------------------------------
6998 -- Find_Unique_Parameterless_Procedure --
6999 -----------------------------------------
7000
7001 function Find_Unique_Parameterless_Procedure
7002 (Name : Entity_Id;
7003 Arg : Node_Id) return Entity_Id
7004 is
7005 Proc : Entity_Id := Empty;
7006
7007 begin
7008 -- The body of this procedure needs some comments ???
7009
7010 if not Is_Entity_Name (Name) then
7011 Error_Pragma_Arg
7012 ("argument of pragma% must be entity name", Arg);
7013
7014 elsif not Is_Overloaded (Name) then
7015 Proc := Entity (Name);
7016
7017 if Ekind (Proc) /= E_Procedure
7018 or else Present (First_Formal (Proc))
7019 then
7020 Error_Pragma_Arg
7021 ("argument of pragma% must be parameterless procedure", Arg);
7022 end if;
7023
7024 else
7025 declare
7026 Found : Boolean := False;
7027 It : Interp;
7028 Index : Interp_Index;
7029
7030 begin
7031 Get_First_Interp (Name, Index, It);
7032 while Present (It.Nam) loop
7033 Proc := It.Nam;
7034
7035 if Ekind (Proc) = E_Procedure
7036 and then No (First_Formal (Proc))
7037 then
7038 if not Found then
7039 Found := True;
7040 Set_Entity (Name, Proc);
7041 Set_Is_Overloaded (Name, False);
7042 else
7043 Error_Pragma_Arg
7044 ("ambiguous handler name for pragma% ", Arg);
7045 end if;
7046 end if;
7047
7048 Get_Next_Interp (Index, It);
7049 end loop;
7050
7051 if not Found then
7052 Error_Pragma_Arg
7053 ("argument of pragma% must be parameterless procedure",
7054 Arg);
7055 else
7056 Proc := Entity (Name);
7057 end if;
7058 end;
7059 end if;
7060
7061 return Proc;
7062 end Find_Unique_Parameterless_Procedure;
7063
7064 ---------------
7065 -- Fix_Error --
7066 ---------------
7067
7068 function Fix_Error (Msg : String) return String is
7069 Res : String (Msg'Range) := Msg;
7070 Res_Last : Natural := Msg'Last;
7071 J : Natural;
7072
7073 begin
7074 -- If we have a rewriting of another pragma, go to that pragma
7075
7076 if Is_Rewrite_Substitution (N)
7077 and then Nkind (Original_Node (N)) = N_Pragma
7078 then
7079 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
7080 end if;
7081
7082 -- Case where pragma comes from an aspect specification
7083
7084 if From_Aspect_Specification (N) then
7085
7086 -- Change appearence of "pragma" in message to "aspect"
7087
7088 J := Res'First;
7089 while J <= Res_Last - 5 loop
7090 if Res (J .. J + 5) = "pragma" then
7091 Res (J .. J + 5) := "aspect";
7092 J := J + 6;
7093
7094 else
7095 J := J + 1;
7096 end if;
7097 end loop;
7098
7099 -- Change "argument of" at start of message to "entity for"
7100
7101 if Res'Length > 11
7102 and then Res (Res'First .. Res'First + 10) = "argument of"
7103 then
7104 Res (Res'First .. Res'First + 9) := "entity for";
7105 Res (Res'First + 10 .. Res_Last - 1) :=
7106 Res (Res'First + 11 .. Res_Last);
7107 Res_Last := Res_Last - 1;
7108 end if;
7109
7110 -- Change "argument" at start of message to "entity"
7111
7112 if Res'Length > 8
7113 and then Res (Res'First .. Res'First + 7) = "argument"
7114 then
7115 Res (Res'First .. Res'First + 5) := "entity";
7116 Res (Res'First + 6 .. Res_Last - 2) :=
7117 Res (Res'First + 8 .. Res_Last);
7118 Res_Last := Res_Last - 2;
7119 end if;
7120
7121 -- Get name from corresponding aspect
7122
7123 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
7124 end if;
7125
7126 -- Return possibly modified message
7127
7128 return Res (Res'First .. Res_Last);
7129 end Fix_Error;
7130
7131 -------------------------
7132 -- Gather_Associations --
7133 -------------------------
7134
7135 procedure Gather_Associations
7136 (Names : Name_List;
7137 Args : out Args_List)
7138 is
7139 Arg : Node_Id;
7140
7141 begin
7142 -- Initialize all parameters to Empty
7143
7144 for J in Args'Range loop
7145 Args (J) := Empty;
7146 end loop;
7147
7148 -- That's all we have to do if there are no argument associations
7149
7150 if No (Pragma_Argument_Associations (N)) then
7151 return;
7152 end if;
7153
7154 -- Otherwise first deal with any positional parameters present
7155
7156 Arg := First (Pragma_Argument_Associations (N));
7157 for Index in Args'Range loop
7158 exit when No (Arg) or else Chars (Arg) /= No_Name;
7159 Args (Index) := Get_Pragma_Arg (Arg);
7160 Next (Arg);
7161 end loop;
7162
7163 -- Positional parameters all processed, if any left, then we
7164 -- have too many positional parameters.
7165
7166 if Present (Arg) and then Chars (Arg) = No_Name then
7167 Error_Pragma_Arg
7168 ("too many positional associations for pragma%", Arg);
7169 end if;
7170
7171 -- Process named parameters if any are present
7172
7173 while Present (Arg) loop
7174 if Chars (Arg) = No_Name then
7175 Error_Pragma_Arg
7176 ("positional association cannot follow named association",
7177 Arg);
7178
7179 else
7180 for Index in Names'Range loop
7181 if Names (Index) = Chars (Arg) then
7182 if Present (Args (Index)) then
7183 Error_Pragma_Arg
7184 ("duplicate argument association for pragma%", Arg);
7185 else
7186 Args (Index) := Get_Pragma_Arg (Arg);
7187 exit;
7188 end if;
7189 end if;
7190
7191 if Index = Names'Last then
7192 Error_Msg_Name_1 := Pname;
7193 Error_Msg_N ("pragma% does not allow & argument", Arg);
7194
7195 -- Check for possible misspelling
7196
7197 for Index1 in Names'Range loop
7198 if Is_Bad_Spelling_Of
7199 (Chars (Arg), Names (Index1))
7200 then
7201 Error_Msg_Name_1 := Names (Index1);
7202 Error_Msg_N -- CODEFIX
7203 ("\possible misspelling of%", Arg);
7204 exit;
7205 end if;
7206 end loop;
7207
7208 raise Pragma_Exit;
7209 end if;
7210 end loop;
7211 end if;
7212
7213 Next (Arg);
7214 end loop;
7215 end Gather_Associations;
7216
7217 -----------------
7218 -- GNAT_Pragma --
7219 -----------------
7220
7221 procedure GNAT_Pragma is
7222 begin
7223 -- We need to check the No_Implementation_Pragmas restriction for
7224 -- the case of a pragma from source. Note that the case of aspects
7225 -- generating corresponding pragmas marks these pragmas as not being
7226 -- from source, so this test also catches that case.
7227
7228 if Comes_From_Source (N) then
7229 Check_Restriction (No_Implementation_Pragmas, N);
7230 end if;
7231 end GNAT_Pragma;
7232
7233 --------------------------
7234 -- Is_Before_First_Decl --
7235 --------------------------
7236
7237 function Is_Before_First_Decl
7238 (Pragma_Node : Node_Id;
7239 Decls : List_Id) return Boolean
7240 is
7241 Item : Node_Id := First (Decls);
7242
7243 begin
7244 -- Only other pragmas can come before this pragma, but they might
7245 -- have been rewritten so check the original node.
7246
7247 loop
7248 if No (Item) or else Nkind (Original_Node (Item)) /= N_Pragma then
7249 return False;
7250
7251 elsif Item = Pragma_Node then
7252 return True;
7253 end if;
7254
7255 Next (Item);
7256 end loop;
7257 end Is_Before_First_Decl;
7258
7259 -----------------------------
7260 -- Is_Configuration_Pragma --
7261 -----------------------------
7262
7263 -- A configuration pragma must appear in the context clause of a
7264 -- compilation unit, and only other pragmas may precede it. Note that
7265 -- the test below also permits use in a configuration pragma file.
7266
7267 function Is_Configuration_Pragma return Boolean is
7268 Lis : constant List_Id := List_Containing (N);
7269 Par : constant Node_Id := Parent (N);
7270 Prg : Node_Id;
7271
7272 begin
7273 -- If no parent, then we are in the configuration pragma file,
7274 -- so the placement is definitely appropriate.
7275
7276 if No (Par) then
7277 return True;
7278
7279 -- Otherwise we must be in the context clause of a compilation unit
7280 -- and the only thing allowed before us in the context list is more
7281 -- configuration pragmas.
7282
7283 elsif Nkind (Par) = N_Compilation_Unit
7284 and then Context_Items (Par) = Lis
7285 then
7286 Prg := First (Lis);
7287
7288 loop
7289 if Prg = N then
7290 return True;
7291 elsif Nkind (Prg) /= N_Pragma then
7292 return False;
7293 end if;
7294
7295 Next (Prg);
7296 end loop;
7297
7298 else
7299 return False;
7300 end if;
7301 end Is_Configuration_Pragma;
7302
7303 --------------------------
7304 -- Is_In_Context_Clause --
7305 --------------------------
7306
7307 function Is_In_Context_Clause return Boolean is
7308 Plist : List_Id;
7309 Parent_Node : Node_Id;
7310
7311 begin
7312 if not Is_List_Member (N) then
7313 return False;
7314
7315 else
7316 Plist := List_Containing (N);
7317 Parent_Node := Parent (Plist);
7318
7319 if Parent_Node = Empty
7320 or else Nkind (Parent_Node) /= N_Compilation_Unit
7321 or else Context_Items (Parent_Node) /= Plist
7322 then
7323 return False;
7324 end if;
7325 end if;
7326
7327 return True;
7328 end Is_In_Context_Clause;
7329
7330 ---------------------------------
7331 -- Is_Static_String_Expression --
7332 ---------------------------------
7333
7334 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
7335 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
7336 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
7337
7338 begin
7339 Analyze_And_Resolve (Argx);
7340
7341 -- Special case Ada 83, where the expression will never be static,
7342 -- but we will return true if we had a string literal to start with.
7343
7344 if Ada_Version = Ada_83 then
7345 return Lit;
7346
7347 -- Normal case, true only if we end up with a string literal that
7348 -- is marked as being the result of evaluating a static expression.
7349
7350 else
7351 return Is_OK_Static_Expression (Argx)
7352 and then Nkind (Argx) = N_String_Literal;
7353 end if;
7354
7355 end Is_Static_String_Expression;
7356
7357 ----------------------
7358 -- Pragma_Misplaced --
7359 ----------------------
7360
7361 procedure Pragma_Misplaced is
7362 begin
7363 Error_Pragma ("incorrect placement of pragma%");
7364 end Pragma_Misplaced;
7365
7366 ------------------------------------------------
7367 -- Process_Atomic_Independent_Shared_Volatile --
7368 ------------------------------------------------
7369
7370 procedure Process_Atomic_Independent_Shared_Volatile is
7371 procedure Check_VFA_Conflicts (Ent : Entity_Id);
7372 -- Check that Volatile_Full_Access and VFA do not conflict
7373
7374 procedure Mark_Component_Or_Object (Ent : Entity_Id);
7375 -- Appropriately set flags on the given entity, either an array or
7376 -- record component, or an object declaration) according to the
7377 -- current pragma.
7378
7379 procedure Mark_Type (Ent : Entity_Id);
7380 -- Appropriately set flags on the given entity, a type
7381
7382 procedure Set_Atomic_VFA (Ent : Entity_Id);
7383 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
7384 -- no explicit alignment was given, set alignment to unknown, since
7385 -- back end knows what the alignment requirements are for atomic and
7386 -- full access arrays. Note: this is necessary for derived types.
7387
7388 -------------------------
7389 -- Check_VFA_Conflicts --
7390 -------------------------
7391
7392 procedure Check_VFA_Conflicts (Ent : Entity_Id) is
7393 Comp : Entity_Id;
7394 Typ : Entity_Id;
7395
7396 VFA_And_Atomic : Boolean := False;
7397 -- Set True if both VFA and Atomic present
7398
7399 begin
7400 -- Fetch the type in case we are dealing with an object or
7401 -- component.
7402
7403 if Is_Type (Ent) then
7404 Typ := Ent;
7405 else
7406 pragma Assert (Is_Object (Ent)
7407 or else
7408 Nkind (Declaration_Node (Ent)) = N_Component_Declaration);
7409
7410 Typ := Etype (Ent);
7411 end if;
7412
7413 -- Check Atomic and VFA used together
7414
7415 if Prag_Id = Pragma_Volatile_Full_Access
7416 or else Is_Volatile_Full_Access (Ent)
7417 then
7418 if Prag_Id = Pragma_Atomic
7419 or else Prag_Id = Pragma_Shared
7420 or else Is_Atomic (Ent)
7421 then
7422 VFA_And_Atomic := True;
7423
7424 elsif Is_Array_Type (Typ) then
7425 VFA_And_Atomic := Has_Atomic_Components (Typ);
7426
7427 -- Note: Has_Atomic_Components is not used below, as this flag
7428 -- represents the pragma of the same name, Atomic_Components,
7429 -- which only applies to arrays.
7430
7431 elsif Is_Record_Type (Typ) then
7432 -- Attributes cannot be applied to discriminants, only
7433 -- regular record components.
7434
7435 Comp := First_Component (Typ);
7436 while Present (Comp) loop
7437 if Is_Atomic (Comp)
7438 or else Is_Atomic (Typ)
7439 then
7440 VFA_And_Atomic := True;
7441
7442 exit;
7443 end if;
7444
7445 Next_Component (Comp);
7446 end loop;
7447 end if;
7448
7449 if VFA_And_Atomic then
7450 Error_Pragma
7451 ("cannot have Volatile_Full_Access and Atomic for same "
7452 & "entity");
7453 end if;
7454 end if;
7455 end Check_VFA_Conflicts;
7456
7457 ------------------------------
7458 -- Mark_Component_Or_Object --
7459 ------------------------------
7460
7461 procedure Mark_Component_Or_Object (Ent : Entity_Id) is
7462 begin
7463 if Prag_Id = Pragma_Atomic
7464 or else Prag_Id = Pragma_Shared
7465 or else Prag_Id = Pragma_Volatile_Full_Access
7466 then
7467 if Prag_Id = Pragma_Volatile_Full_Access then
7468 Set_Is_Volatile_Full_Access (Ent);
7469 else
7470 Set_Is_Atomic (Ent);
7471 end if;
7472
7473 -- If the object declaration has an explicit initialization, a
7474 -- temporary may have to be created to hold the expression, to
7475 -- ensure that access to the object remains atomic.
7476
7477 if Nkind (Parent (Ent)) = N_Object_Declaration
7478 and then Present (Expression (Parent (Ent)))
7479 then
7480 Set_Has_Delayed_Freeze (Ent);
7481 end if;
7482 end if;
7483
7484 -- Atomic/Shared/Volatile_Full_Access imply Independent
7485
7486 if Prag_Id /= Pragma_Volatile then
7487 Set_Is_Independent (Ent);
7488
7489 if Prag_Id = Pragma_Independent then
7490 Record_Independence_Check (N, Ent);
7491 end if;
7492 end if;
7493
7494 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7495
7496 if Prag_Id /= Pragma_Independent then
7497 Set_Is_Volatile (Ent);
7498 Set_Treat_As_Volatile (Ent);
7499 end if;
7500 end Mark_Component_Or_Object;
7501
7502 ---------------
7503 -- Mark_Type --
7504 ---------------
7505
7506 procedure Mark_Type (Ent : Entity_Id) is
7507 begin
7508 -- Attribute belongs on the base type. If the view of the type is
7509 -- currently private, it also belongs on the underlying type.
7510
7511 -- In Ada 2020, the pragma can apply to a formal type, for which
7512 -- there may be no underlying type.
7513
7514 if Prag_Id = Pragma_Atomic
7515 or else Prag_Id = Pragma_Shared
7516 or else Prag_Id = Pragma_Volatile_Full_Access
7517 then
7518 Set_Atomic_VFA (Ent);
7519 Set_Atomic_VFA (Base_Type (Ent));
7520
7521 if not Is_Generic_Type (Ent) then
7522 Set_Atomic_VFA (Underlying_Type (Ent));
7523 end if;
7524 end if;
7525
7526 -- Atomic/Shared/Volatile_Full_Access imply Independent
7527
7528 if Prag_Id /= Pragma_Volatile then
7529 Set_Is_Independent (Ent);
7530 Set_Is_Independent (Base_Type (Ent));
7531
7532 if not Is_Generic_Type (Ent) then
7533 Set_Is_Independent (Underlying_Type (Ent));
7534
7535 if Prag_Id = Pragma_Independent then
7536 Record_Independence_Check (N, Base_Type (Ent));
7537 end if;
7538 end if;
7539 end if;
7540
7541 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7542
7543 if Prag_Id /= Pragma_Independent then
7544 Set_Is_Volatile (Ent);
7545 Set_Is_Volatile (Base_Type (Ent));
7546
7547 if not Is_Generic_Type (Ent) then
7548 Set_Is_Volatile (Underlying_Type (Ent));
7549 Set_Treat_As_Volatile (Underlying_Type (Ent));
7550 end if;
7551
7552 Set_Treat_As_Volatile (Ent);
7553 end if;
7554
7555 -- Apply Volatile to the composite type's individual components,
7556 -- (RM C.6(8/3)).
7557
7558 if Prag_Id = Pragma_Volatile
7559 and then Is_Record_Type (Etype (Ent))
7560 then
7561 declare
7562 Comp : Entity_Id;
7563 begin
7564 Comp := First_Component (Ent);
7565 while Present (Comp) loop
7566 Mark_Component_Or_Object (Comp);
7567
7568 Next_Component (Comp);
7569 end loop;
7570 end;
7571 end if;
7572 end Mark_Type;
7573
7574 --------------------
7575 -- Set_Atomic_VFA --
7576 --------------------
7577
7578 procedure Set_Atomic_VFA (Ent : Entity_Id) is
7579 begin
7580 if Prag_Id = Pragma_Volatile_Full_Access then
7581 Set_Is_Volatile_Full_Access (Ent);
7582 else
7583 Set_Is_Atomic (Ent);
7584 end if;
7585
7586 if not Has_Alignment_Clause (Ent) then
7587 Set_Alignment (Ent, Uint_0);
7588 end if;
7589 end Set_Atomic_VFA;
7590
7591 -- Local variables
7592
7593 Decl : Node_Id;
7594 E : Entity_Id;
7595 E_Arg : Node_Id;
7596
7597 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
7598
7599 begin
7600 Check_Ada_83_Warning;
7601 Check_No_Identifiers;
7602 Check_Arg_Count (1);
7603 Check_Arg_Is_Local_Name (Arg1);
7604 E_Arg := Get_Pragma_Arg (Arg1);
7605
7606 if Etype (E_Arg) = Any_Type then
7607 return;
7608 end if;
7609
7610 E := Entity (E_Arg);
7611
7612 -- A pragma that applies to a Ghost entity becomes Ghost for the
7613 -- purposes of legality checks and removal of ignored Ghost code.
7614
7615 Mark_Ghost_Pragma (N, E);
7616
7617 -- Check duplicate before we chain ourselves
7618
7619 Check_Duplicate_Pragma (E);
7620
7621 -- Check appropriateness of the entity
7622
7623 Decl := Declaration_Node (E);
7624
7625 -- Deal with the case where the pragma/attribute is applied to a type
7626
7627 if Is_Type (E) then
7628 if Rep_Item_Too_Early (E, N)
7629 or else Rep_Item_Too_Late (E, N)
7630 then
7631 return;
7632 else
7633 Check_First_Subtype (Arg1);
7634 end if;
7635
7636 Mark_Type (E);
7637
7638 -- Deal with the case where the pragma/attribute applies to a
7639 -- component or object declaration.
7640
7641 elsif Nkind (Decl) = N_Object_Declaration
7642 or else (Nkind (Decl) = N_Component_Declaration
7643 and then Original_Record_Component (E) = E)
7644 then
7645 if Rep_Item_Too_Late (E, N) then
7646 return;
7647 end if;
7648
7649 Mark_Component_Or_Object (E);
7650
7651 -- In other cases give an error
7652
7653 else
7654 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7655 end if;
7656
7657 -- Check that Volatile_Full_Access and Atomic do not conflict
7658
7659 Check_VFA_Conflicts (E);
7660
7661 -- Check for the application of Atomic or Volatile_Full_Access to
7662 -- an entity that has [nonatomic] aliased, or else specified to be
7663 -- independently addressable, subcomponents.
7664
7665 if (Prag_Id = Pragma_Atomic and then Ada_Version >= Ada_2020)
7666 or else Prag_Id = Pragma_Volatile_Full_Access
7667 then
7668 Check_Atomic_VFA (E, VFA => Prag_Id = Pragma_Volatile_Full_Access);
7669 end if;
7670
7671 -- The following check is only relevant when SPARK_Mode is on as
7672 -- this is not a standard Ada legality rule. Pragma Volatile can
7673 -- only apply to a full type declaration or an object declaration
7674 -- (SPARK RM 7.1.3(2)). Original_Node is necessary to account for
7675 -- untagged derived types that are rewritten as subtypes of their
7676 -- respective root types.
7677
7678 if SPARK_Mode = On
7679 and then Prag_Id = Pragma_Volatile
7680 and then Nkind (Original_Node (Decl)) not in
7681 N_Full_Type_Declaration |
7682 N_Formal_Type_Declaration |
7683 N_Object_Declaration |
7684 N_Single_Protected_Declaration |
7685 N_Single_Task_Declaration
7686 then
7687 Error_Pragma_Arg
7688 ("argument of pragma % must denote a full type or object "
7689 & "declaration", Arg1);
7690 end if;
7691 end Process_Atomic_Independent_Shared_Volatile;
7692
7693 -------------------------------------------
7694 -- Process_Compile_Time_Warning_Or_Error --
7695 -------------------------------------------
7696
7697 procedure Process_Compile_Time_Warning_Or_Error is
7698 P : Node_Id := Parent (N);
7699 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
7700
7701 begin
7702 Check_Arg_Count (2);
7703 Check_No_Identifiers;
7704 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
7705 Analyze_And_Resolve (Arg1x, Standard_Boolean);
7706
7707 -- In GNATprove mode, pragma Compile_Time_Error is translated as
7708 -- a Check pragma in GNATprove mode, handled as an assumption in
7709 -- GNATprove. This is correct as the compiler will issue an error
7710 -- if the condition cannot be statically evaluated to False.
7711 -- Compile_Time_Warning are ignored, as the analyzer may not have the
7712 -- same information as the compiler (in particular regarding size of
7713 -- objects decided in gigi) so it makes no sense to issue a warning
7714 -- in GNATprove.
7715
7716 if GNATprove_Mode then
7717 if Prag_Id = Pragma_Compile_Time_Error then
7718 declare
7719 New_Args : List_Id;
7720 begin
7721 -- Implement Compile_Time_Error by generating
7722 -- a corresponding Check pragma:
7723
7724 -- pragma Check (name, condition);
7725
7726 -- where name is the identifier matching the pragma name. So
7727 -- rewrite pragma in this manner and analyze the result.
7728
7729 New_Args := New_List
7730 (Make_Pragma_Argument_Association
7731 (Loc,
7732 Expression => Make_Identifier (Loc, Pname)),
7733 Make_Pragma_Argument_Association
7734 (Sloc (Arg1x),
7735 Expression => Arg1x));
7736
7737 -- Rewrite as Check pragma
7738
7739 Rewrite (N,
7740 Make_Pragma (Loc,
7741 Chars => Name_Check,
7742 Pragma_Argument_Associations => New_Args));
7743
7744 Analyze (N);
7745 end;
7746
7747 else
7748 Rewrite (N, Make_Null_Statement (Loc));
7749 end if;
7750
7751 return;
7752 end if;
7753
7754 -- If the condition is known at compile time (now), validate it now.
7755 -- Otherwise, register the expression for validation after the back
7756 -- end has been called, because it might be known at compile time
7757 -- then. For example, if the expression is "Record_Type'Size /= 32"
7758 -- it might be known after the back end has determined the size of
7759 -- Record_Type. We do not defer validation if we're inside a generic
7760 -- unit, because we will have more information in the instances.
7761
7762 if Compile_Time_Known_Value (Arg1x) then
7763 Validate_Compile_Time_Warning_Or_Error (N, Sloc (Arg1));
7764 else
7765 while Present (P) and then Nkind (P) not in N_Generic_Declaration
7766 loop
7767 if Nkind (P) in N_Package_Body | N_Subprogram_Body then
7768 P := Corresponding_Spec (P);
7769 else
7770 P := Parent (P);
7771 end if;
7772 end loop;
7773
7774 if No (P) then
7775 Defer_Compile_Time_Warning_Error_To_BE (N);
7776 end if;
7777 end if;
7778 end Process_Compile_Time_Warning_Or_Error;
7779
7780 ------------------------
7781 -- Process_Convention --
7782 ------------------------
7783
7784 procedure Process_Convention
7785 (C : out Convention_Id;
7786 Ent : out Entity_Id)
7787 is
7788 Cname : Name_Id;
7789
7790 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
7791 -- Called if we have more than one Export/Import/Convention pragma.
7792 -- This is generally illegal, but we have a special case of allowing
7793 -- Import and Interface to coexist if they specify the convention in
7794 -- a consistent manner. We are allowed to do this, since Interface is
7795 -- an implementation defined pragma, and we choose to do it since we
7796 -- know Rational allows this combination. S is the entity id of the
7797 -- subprogram in question. This procedure also sets the special flag
7798 -- Import_Interface_Present in both pragmas in the case where we do
7799 -- have matching Import and Interface pragmas.
7800
7801 procedure Set_Convention_From_Pragma (E : Entity_Id);
7802 -- Set convention in entity E, and also flag that the entity has a
7803 -- convention pragma. If entity is for a private or incomplete type,
7804 -- also set convention and flag on underlying type. This procedure
7805 -- also deals with the special case of C_Pass_By_Copy convention,
7806 -- and error checks for inappropriate convention specification.
7807
7808 -------------------------------
7809 -- Diagnose_Multiple_Pragmas --
7810 -------------------------------
7811
7812 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
7813 Pdec : constant Node_Id := Declaration_Node (S);
7814 Decl : Node_Id;
7815 Err : Boolean;
7816
7817 function Same_Convention (Decl : Node_Id) return Boolean;
7818 -- Decl is a pragma node. This function returns True if this
7819 -- pragma has a first argument that is an identifier with a
7820 -- Chars field corresponding to the Convention_Id C.
7821
7822 function Same_Name (Decl : Node_Id) return Boolean;
7823 -- Decl is a pragma node. This function returns True if this
7824 -- pragma has a second argument that is an identifier with a
7825 -- Chars field that matches the Chars of the current subprogram.
7826
7827 ---------------------
7828 -- Same_Convention --
7829 ---------------------
7830
7831 function Same_Convention (Decl : Node_Id) return Boolean is
7832 Arg1 : constant Node_Id :=
7833 First (Pragma_Argument_Associations (Decl));
7834
7835 begin
7836 if Present (Arg1) then
7837 declare
7838 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
7839 begin
7840 if Nkind (Arg) = N_Identifier
7841 and then Is_Convention_Name (Chars (Arg))
7842 and then Get_Convention_Id (Chars (Arg)) = C
7843 then
7844 return True;
7845 end if;
7846 end;
7847 end if;
7848
7849 return False;
7850 end Same_Convention;
7851
7852 ---------------
7853 -- Same_Name --
7854 ---------------
7855
7856 function Same_Name (Decl : Node_Id) return Boolean is
7857 Arg1 : constant Node_Id :=
7858 First (Pragma_Argument_Associations (Decl));
7859 Arg2 : Node_Id;
7860
7861 begin
7862 if No (Arg1) then
7863 return False;
7864 end if;
7865
7866 Arg2 := Next (Arg1);
7867
7868 if No (Arg2) then
7869 return False;
7870 end if;
7871
7872 declare
7873 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
7874 begin
7875 if Nkind (Arg) = N_Identifier
7876 and then Chars (Arg) = Chars (S)
7877 then
7878 return True;
7879 end if;
7880 end;
7881
7882 return False;
7883 end Same_Name;
7884
7885 -- Start of processing for Diagnose_Multiple_Pragmas
7886
7887 begin
7888 Err := True;
7889
7890 -- Definitely give message if we have Convention/Export here
7891
7892 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
7893 null;
7894
7895 -- If we have an Import or Export, scan back from pragma to
7896 -- find any previous pragma applying to the same procedure.
7897 -- The scan will be terminated by the start of the list, or
7898 -- hitting the subprogram declaration. This won't allow one
7899 -- pragma to appear in the public part and one in the private
7900 -- part, but that seems very unlikely in practice.
7901
7902 else
7903 Decl := Prev (N);
7904 while Present (Decl) and then Decl /= Pdec loop
7905
7906 -- Look for pragma with same name as us
7907
7908 if Nkind (Decl) = N_Pragma
7909 and then Same_Name (Decl)
7910 then
7911 -- Give error if same as our pragma or Export/Convention
7912
7913 if Pragma_Name_Unmapped (Decl)
7914 in Name_Export
7915 | Name_Convention
7916 | Pragma_Name_Unmapped (N)
7917 then
7918 exit;
7919
7920 -- Case of Import/Interface or the other way round
7921
7922 elsif Pragma_Name_Unmapped (Decl)
7923 in Name_Interface | Name_Import
7924 then
7925 -- Here we know that we have Import and Interface. It
7926 -- doesn't matter which way round they are. See if
7927 -- they specify the same convention. If so, all OK,
7928 -- and set special flags to stop other messages
7929
7930 if Same_Convention (Decl) then
7931 Set_Import_Interface_Present (N);
7932 Set_Import_Interface_Present (Decl);
7933 Err := False;
7934
7935 -- If different conventions, special message
7936
7937 else
7938 Error_Msg_Sloc := Sloc (Decl);
7939 Error_Pragma_Arg
7940 ("convention differs from that given#", Arg1);
7941 return;
7942 end if;
7943 end if;
7944 end if;
7945
7946 Next (Decl);
7947 end loop;
7948 end if;
7949
7950 -- Give message if needed if we fall through those tests
7951 -- except on Relaxed_RM_Semantics where we let go: either this
7952 -- is a case accepted/ignored by other Ada compilers (e.g.
7953 -- a mix of Convention and Import), or another error will be
7954 -- generated later (e.g. using both Import and Export).
7955
7956 if Err and not Relaxed_RM_Semantics then
7957 Error_Pragma_Arg
7958 ("at most one Convention/Export/Import pragma is allowed",
7959 Arg2);
7960 end if;
7961 end Diagnose_Multiple_Pragmas;
7962
7963 --------------------------------
7964 -- Set_Convention_From_Pragma --
7965 --------------------------------
7966
7967 procedure Set_Convention_From_Pragma (E : Entity_Id) is
7968 begin
7969 -- Ada 2005 (AI-430): Check invalid attempt to change convention
7970 -- for an overridden dispatching operation. Technically this is
7971 -- an amendment and should only be done in Ada 2005 mode. However,
7972 -- this is clearly a mistake, since the problem that is addressed
7973 -- by this AI is that there is a clear gap in the RM.
7974
7975 if Is_Dispatching_Operation (E)
7976 and then Present (Overridden_Operation (E))
7977 and then C /= Convention (Overridden_Operation (E))
7978 then
7979 Error_Pragma_Arg
7980 ("cannot change convention for overridden dispatching "
7981 & "operation", Arg1);
7982
7983 -- Special check for convention Stdcall: a dispatching call is not
7984 -- allowed. A dispatching subprogram cannot be used to interface
7985 -- to the Win32 API, so this check actually does not impose any
7986 -- effective restriction.
7987
7988 elsif Is_Dispatching_Operation (E)
7989 and then C = Convention_Stdcall
7990 then
7991 -- Note: make this unconditional so that if there is more
7992 -- than one call to which the pragma applies, we get a
7993 -- message for each call. Also don't use Error_Pragma,
7994 -- so that we get multiple messages.
7995
7996 Error_Msg_Sloc := Sloc (E);
7997 Error_Msg_N
7998 ("dispatching subprogram# cannot use Stdcall convention!",
7999 Get_Pragma_Arg (Arg1));
8000 end if;
8001
8002 -- Set the convention
8003
8004 Set_Convention (E, C);
8005 Set_Has_Convention_Pragma (E);
8006
8007 -- For the case of a record base type, also set the convention of
8008 -- any anonymous access types declared in the record which do not
8009 -- currently have a specified convention.
8010 -- Similarly for an array base type and anonymous access types
8011 -- components.
8012
8013 if Is_Base_Type (E) then
8014 if Is_Record_Type (E) then
8015 declare
8016 Comp : Node_Id;
8017
8018 begin
8019 Comp := First_Component (E);
8020 while Present (Comp) loop
8021 if Present (Etype (Comp))
8022 and then
8023 Ekind (Etype (Comp)) in
8024 E_Anonymous_Access_Type |
8025 E_Anonymous_Access_Subprogram_Type
8026 and then not Has_Convention_Pragma (Comp)
8027 then
8028 Set_Convention (Comp, C);
8029 end if;
8030
8031 Next_Component (Comp);
8032 end loop;
8033 end;
8034
8035 elsif Is_Array_Type (E)
8036 and then Ekind (Component_Type (E)) in
8037 E_Anonymous_Access_Type |
8038 E_Anonymous_Access_Subprogram_Type
8039 then
8040 Set_Convention (Designated_Type (Component_Type (E)), C);
8041 end if;
8042 end if;
8043
8044 -- Deal with incomplete/private type case, where underlying type
8045 -- is available, so set convention of that underlying type.
8046
8047 if Is_Incomplete_Or_Private_Type (E)
8048 and then Present (Underlying_Type (E))
8049 then
8050 Set_Convention (Underlying_Type (E), C);
8051 Set_Has_Convention_Pragma (Underlying_Type (E), True);
8052 end if;
8053
8054 -- A class-wide type should inherit the convention of the specific
8055 -- root type (although this isn't specified clearly by the RM).
8056
8057 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
8058 Set_Convention (Class_Wide_Type (E), C);
8059 end if;
8060
8061 -- If the entity is a record type, then check for special case of
8062 -- C_Pass_By_Copy, which is treated the same as C except that the
8063 -- special record flag is set. This convention is only permitted
8064 -- on record types (see AI95-00131).
8065
8066 if Cname = Name_C_Pass_By_Copy then
8067 if Is_Record_Type (E) then
8068 Set_C_Pass_By_Copy (Base_Type (E));
8069 elsif Is_Incomplete_Or_Private_Type (E)
8070 and then Is_Record_Type (Underlying_Type (E))
8071 then
8072 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
8073 else
8074 Error_Pragma_Arg
8075 ("C_Pass_By_Copy convention allowed only for record type",
8076 Arg2);
8077 end if;
8078 end if;
8079
8080 -- If the entity is a derived boolean type, check for the special
8081 -- case of convention C, C++, or Fortran, where we consider any
8082 -- nonzero value to represent true.
8083
8084 if Is_Discrete_Type (E)
8085 and then Root_Type (Etype (E)) = Standard_Boolean
8086 and then
8087 (C = Convention_C
8088 or else
8089 C = Convention_CPP
8090 or else
8091 C = Convention_Fortran)
8092 then
8093 Set_Nonzero_Is_True (Base_Type (E));
8094 end if;
8095 end Set_Convention_From_Pragma;
8096
8097 -- Local variables
8098
8099 Comp_Unit : Unit_Number_Type;
8100 E : Entity_Id;
8101 E1 : Entity_Id;
8102 Id : Node_Id;
8103 Subp : Entity_Id;
8104
8105 -- Start of processing for Process_Convention
8106
8107 begin
8108 Check_At_Least_N_Arguments (2);
8109 Check_Optional_Identifier (Arg1, Name_Convention);
8110 Check_Arg_Is_Identifier (Arg1);
8111 Cname := Chars (Get_Pragma_Arg (Arg1));
8112
8113 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
8114 -- tested again below to set the critical flag).
8115
8116 if Cname = Name_C_Pass_By_Copy then
8117 C := Convention_C;
8118
8119 -- Otherwise we must have something in the standard convention list
8120
8121 elsif Is_Convention_Name (Cname) then
8122 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
8123
8124 -- Otherwise warn on unrecognized convention
8125
8126 else
8127 if Warn_On_Export_Import then
8128 Error_Msg_N
8129 ("??unrecognized convention name, C assumed",
8130 Get_Pragma_Arg (Arg1));
8131 end if;
8132
8133 C := Convention_C;
8134 end if;
8135
8136 Check_Optional_Identifier (Arg2, Name_Entity);
8137 Check_Arg_Is_Local_Name (Arg2);
8138
8139 Id := Get_Pragma_Arg (Arg2);
8140 Analyze (Id);
8141
8142 if not Is_Entity_Name (Id) then
8143 Error_Pragma_Arg ("entity name required", Arg2);
8144 end if;
8145
8146 E := Entity (Id);
8147
8148 -- Set entity to return
8149
8150 Ent := E;
8151
8152 -- Ada_Pass_By_Copy special checking
8153
8154 if C = Convention_Ada_Pass_By_Copy then
8155 if not Is_First_Subtype (E) then
8156 Error_Pragma_Arg
8157 ("convention `Ada_Pass_By_Copy` only allowed for types",
8158 Arg2);
8159 end if;
8160
8161 if Is_By_Reference_Type (E) then
8162 Error_Pragma_Arg
8163 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
8164 & "type", Arg1);
8165 end if;
8166
8167 -- Ada_Pass_By_Reference special checking
8168
8169 elsif C = Convention_Ada_Pass_By_Reference then
8170 if not Is_First_Subtype (E) then
8171 Error_Pragma_Arg
8172 ("convention `Ada_Pass_By_Reference` only allowed for types",
8173 Arg2);
8174 end if;
8175
8176 if Is_By_Copy_Type (E) then
8177 Error_Pragma_Arg
8178 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
8179 & "type", Arg1);
8180 end if;
8181 end if;
8182
8183 -- Go to renamed subprogram if present, since convention applies to
8184 -- the actual renamed entity, not to the renaming entity. If the
8185 -- subprogram is inherited, go to parent subprogram.
8186
8187 if Is_Subprogram (E)
8188 and then Present (Alias (E))
8189 then
8190 if Nkind (Parent (Declaration_Node (E))) =
8191 N_Subprogram_Renaming_Declaration
8192 then
8193 if Scope (E) /= Scope (Alias (E)) then
8194 Error_Pragma_Ref
8195 ("cannot apply pragma% to non-local entity&#", E);
8196 end if;
8197
8198 E := Alias (E);
8199
8200 elsif Nkind (Parent (E)) in
8201 N_Full_Type_Declaration | N_Private_Extension_Declaration
8202 and then Scope (E) = Scope (Alias (E))
8203 then
8204 E := Alias (E);
8205
8206 -- Return the parent subprogram the entity was inherited from
8207
8208 Ent := E;
8209 end if;
8210 end if;
8211
8212 -- Check that we are not applying this to a specless body. Relax this
8213 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
8214
8215 if Is_Subprogram (E)
8216 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
8217 and then not Relaxed_RM_Semantics
8218 then
8219 Error_Pragma
8220 ("pragma% requires separate spec and must come before body");
8221 end if;
8222
8223 -- Check that we are not applying this to a named constant
8224
8225 if Ekind (E) in E_Named_Integer | E_Named_Real then
8226 Error_Msg_Name_1 := Pname;
8227 Error_Msg_N
8228 ("cannot apply pragma% to named constant!",
8229 Get_Pragma_Arg (Arg2));
8230 Error_Pragma_Arg
8231 ("\supply appropriate type for&!", Arg2);
8232 end if;
8233
8234 if Ekind (E) = E_Enumeration_Literal then
8235 Error_Pragma ("enumeration literal not allowed for pragma%");
8236 end if;
8237
8238 -- Check for rep item appearing too early or too late
8239
8240 if Etype (E) = Any_Type
8241 or else Rep_Item_Too_Early (E, N)
8242 then
8243 raise Pragma_Exit;
8244
8245 elsif Present (Underlying_Type (E)) then
8246 E := Underlying_Type (E);
8247 end if;
8248
8249 if Rep_Item_Too_Late (E, N) then
8250 raise Pragma_Exit;
8251 end if;
8252
8253 if Has_Convention_Pragma (E) then
8254 Diagnose_Multiple_Pragmas (E);
8255
8256 elsif Convention (E) = Convention_Protected
8257 or else Ekind (Scope (E)) = E_Protected_Type
8258 then
8259 Error_Pragma_Arg
8260 ("a protected operation cannot be given a different convention",
8261 Arg2);
8262 end if;
8263
8264 -- For Intrinsic, a subprogram is required
8265
8266 if C = Convention_Intrinsic
8267 and then not Is_Subprogram_Or_Generic_Subprogram (E)
8268 then
8269 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
8270
8271 if not (Is_Type (E) and then Relaxed_RM_Semantics) then
8272 Error_Pragma_Arg
8273 ("second argument of pragma% must be a subprogram", Arg2);
8274 end if;
8275
8276 -- Special checks for C_Variadic_n
8277
8278 elsif C in Convention_C_Variadic then
8279
8280 -- Several allowed cases
8281
8282 if Is_Subprogram_Or_Generic_Subprogram (E) then
8283 Subp := E;
8284
8285 -- An access to subprogram is also allowed
8286
8287 elsif Is_Access_Type (E)
8288 and then Ekind (Designated_Type (E)) = E_Subprogram_Type
8289 then
8290 Subp := Designated_Type (E);
8291
8292 -- Allow internal call to set convention of subprogram type
8293
8294 elsif Ekind (E) = E_Subprogram_Type then
8295 Subp := E;
8296
8297 else
8298 Error_Pragma_Arg
8299 ("argument of pragma% must be subprogram or access type",
8300 Arg2);
8301 Subp := Empty;
8302 end if;
8303
8304 -- ISO C requires a named parameter before the ellipsis, so a
8305 -- variadic C function taking 0 fixed parameter cannot exist.
8306
8307 if C = Convention_C_Variadic_0 then
8308
8309 Error_Msg_N
8310 ("??C_Variadic_0 cannot be used for an 'I'S'O C function",
8311 Get_Pragma_Arg (Arg2));
8312
8313 -- Now check the number of parameters of the subprogram and give
8314 -- an error if it is lower than n.
8315
8316 elsif Present (Subp) then
8317 declare
8318 Minimum : constant Nat :=
8319 Convention_Id'Pos (C) -
8320 Convention_Id'Pos (Convention_C_Variadic_0);
8321
8322 Count : Nat;
8323 Formal : Entity_Id;
8324
8325 begin
8326 Count := 0;
8327 Formal := First_Formal (Subp);
8328 while Present (Formal) loop
8329 Count := Count + 1;
8330 Next_Formal (Formal);
8331 end loop;
8332
8333 if Count < Minimum then
8334 Error_Msg_Uint_1 := UI_From_Int (Minimum);
8335 Error_Pragma_Arg
8336 ("argument of pragma% must have at least"
8337 & "^ parameters", Arg2);
8338 end if;
8339 end;
8340 end if;
8341
8342 -- Special checks for Stdcall
8343
8344 elsif C = Convention_Stdcall then
8345
8346 -- Several allowed cases
8347
8348 if Is_Subprogram_Or_Generic_Subprogram (E)
8349
8350 -- A variable is OK
8351
8352 or else Ekind (E) = E_Variable
8353
8354 -- A component as well. The entity does not have its Ekind
8355 -- set until the enclosing record declaration is fully
8356 -- analyzed.
8357
8358 or else Nkind (Parent (E)) = N_Component_Declaration
8359
8360 -- An access to subprogram is also allowed
8361
8362 or else
8363 (Is_Access_Type (E)
8364 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
8365
8366 -- Allow internal call to set convention of subprogram type
8367
8368 or else Ekind (E) = E_Subprogram_Type
8369 then
8370 null;
8371
8372 else
8373 Error_Pragma_Arg
8374 ("argument of pragma% must be subprogram or access type",
8375 Arg2);
8376 end if;
8377 end if;
8378
8379 Set_Convention_From_Pragma (E);
8380
8381 -- Deal with non-subprogram cases
8382
8383 if not Is_Subprogram_Or_Generic_Subprogram (E) then
8384 if Is_Type (E) then
8385
8386 -- The pragma must apply to a first subtype, but it can also
8387 -- apply to a generic type in a generic formal part, in which
8388 -- case it will also appear in the corresponding instance.
8389
8390 if Is_Generic_Type (E) or else In_Instance then
8391 null;
8392 else
8393 Check_First_Subtype (Arg2);
8394 end if;
8395
8396 Set_Convention_From_Pragma (Base_Type (E));
8397
8398 -- For access subprograms, we must set the convention on the
8399 -- internally generated directly designated type as well.
8400
8401 if Ekind (E) = E_Access_Subprogram_Type then
8402 Set_Convention_From_Pragma (Directly_Designated_Type (E));
8403 end if;
8404 end if;
8405
8406 -- For the subprogram case, set proper convention for all homonyms
8407 -- in same scope and the same declarative part, i.e. the same
8408 -- compilation unit.
8409
8410 else
8411 -- Treat a pragma Import as an implicit body, and pragma import
8412 -- as implicit reference (for navigation in GNAT Studio).
8413
8414 if Prag_Id = Pragma_Import then
8415 Generate_Reference (E, Id, 'b');
8416
8417 -- For exported entities we restrict the generation of references
8418 -- to entities exported to foreign languages since entities
8419 -- exported to Ada do not provide further information to
8420 -- GNAT Studio and add undesired references to the output of the
8421 -- gnatxref tool.
8422
8423 elsif Prag_Id = Pragma_Export
8424 and then Convention (E) /= Convention_Ada
8425 then
8426 Generate_Reference (E, Id, 'i');
8427 end if;
8428
8429 -- If the pragma comes from an aspect, it only applies to the
8430 -- given entity, not its homonyms.
8431
8432 if From_Aspect_Specification (N) then
8433 if C = Convention_Intrinsic
8434 and then Nkind (Ent) = N_Defining_Operator_Symbol
8435 then
8436 if Is_Fixed_Point_Type (Etype (Ent))
8437 or else Is_Fixed_Point_Type (Etype (First_Entity (Ent)))
8438 or else Is_Fixed_Point_Type (Etype (Last_Entity (Ent)))
8439 then
8440 Error_Msg_N
8441 ("no intrinsic operator available for this fixed-point "
8442 & "operation", N);
8443 Error_Msg_N
8444 ("\use expression functions with the desired "
8445 & "conversions made explicit", N);
8446 end if;
8447 end if;
8448
8449 return;
8450 end if;
8451
8452 -- Otherwise Loop through the homonyms of the pragma argument's
8453 -- entity, an apply convention to those in the current scope.
8454
8455 Comp_Unit := Get_Source_Unit (E);
8456 E1 := Ent;
8457
8458 loop
8459 E1 := Homonym (E1);
8460 exit when No (E1) or else Scope (E1) /= Current_Scope;
8461
8462 -- Ignore entry for which convention is already set
8463
8464 if Has_Convention_Pragma (E1) then
8465 goto Continue;
8466 end if;
8467
8468 if Is_Subprogram (E1)
8469 and then Nkind (Parent (Declaration_Node (E1))) =
8470 N_Subprogram_Body
8471 and then not Relaxed_RM_Semantics
8472 then
8473 Set_Has_Completion (E); -- to prevent cascaded error
8474 Error_Pragma_Ref
8475 ("pragma% requires separate spec and must come before "
8476 & "body#", E1);
8477 end if;
8478
8479 -- Do not set the pragma on inherited operations or on formal
8480 -- subprograms.
8481
8482 if Comes_From_Source (E1)
8483 and then Comp_Unit = Get_Source_Unit (E1)
8484 and then not Is_Formal_Subprogram (E1)
8485 and then Nkind (Original_Node (Parent (E1))) /=
8486 N_Full_Type_Declaration
8487 then
8488 if Present (Alias (E1))
8489 and then Scope (E1) /= Scope (Alias (E1))
8490 then
8491 Error_Pragma_Ref
8492 ("cannot apply pragma% to non-local entity& declared#",
8493 E1);
8494 end if;
8495
8496 Set_Convention_From_Pragma (E1);
8497
8498 if Prag_Id = Pragma_Import then
8499 Generate_Reference (E1, Id, 'b');
8500 end if;
8501 end if;
8502
8503 <<Continue>>
8504 null;
8505 end loop;
8506 end if;
8507 end Process_Convention;
8508
8509 ----------------------------------------
8510 -- Process_Disable_Enable_Atomic_Sync --
8511 ----------------------------------------
8512
8513 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
8514 begin
8515 Check_No_Identifiers;
8516 Check_At_Most_N_Arguments (1);
8517
8518 -- Modeled internally as
8519 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
8520
8521 Rewrite (N,
8522 Make_Pragma (Loc,
8523 Chars => Nam,
8524 Pragma_Argument_Associations => New_List (
8525 Make_Pragma_Argument_Association (Loc,
8526 Expression =>
8527 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
8528
8529 if Present (Arg1) then
8530 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
8531 end if;
8532
8533 Analyze (N);
8534 end Process_Disable_Enable_Atomic_Sync;
8535
8536 -------------------------------------------------
8537 -- Process_Extended_Import_Export_Internal_Arg --
8538 -------------------------------------------------
8539
8540 procedure Process_Extended_Import_Export_Internal_Arg
8541 (Arg_Internal : Node_Id := Empty)
8542 is
8543 begin
8544 if No (Arg_Internal) then
8545 Error_Pragma ("Internal parameter required for pragma%");
8546 end if;
8547
8548 if Nkind (Arg_Internal) = N_Identifier then
8549 null;
8550
8551 elsif Nkind (Arg_Internal) = N_Operator_Symbol
8552 and then (Prag_Id = Pragma_Import_Function
8553 or else
8554 Prag_Id = Pragma_Export_Function)
8555 then
8556 null;
8557
8558 else
8559 Error_Pragma_Arg
8560 ("wrong form for Internal parameter for pragma%", Arg_Internal);
8561 end if;
8562
8563 Check_Arg_Is_Local_Name (Arg_Internal);
8564 end Process_Extended_Import_Export_Internal_Arg;
8565
8566 --------------------------------------------------
8567 -- Process_Extended_Import_Export_Object_Pragma --
8568 --------------------------------------------------
8569
8570 procedure Process_Extended_Import_Export_Object_Pragma
8571 (Arg_Internal : Node_Id;
8572 Arg_External : Node_Id;
8573 Arg_Size : Node_Id)
8574 is
8575 Def_Id : Entity_Id;
8576
8577 begin
8578 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8579 Def_Id := Entity (Arg_Internal);
8580
8581 if Ekind (Def_Id) not in E_Constant | E_Variable then
8582 Error_Pragma_Arg
8583 ("pragma% must designate an object", Arg_Internal);
8584 end if;
8585
8586 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
8587 or else
8588 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
8589 then
8590 Error_Pragma_Arg
8591 ("previous Common/Psect_Object applies, pragma % not permitted",
8592 Arg_Internal);
8593 end if;
8594
8595 if Rep_Item_Too_Late (Def_Id, N) then
8596 raise Pragma_Exit;
8597 end if;
8598
8599 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
8600
8601 if Present (Arg_Size) then
8602 Check_Arg_Is_External_Name (Arg_Size);
8603 end if;
8604
8605 -- Export_Object case
8606
8607 if Prag_Id = Pragma_Export_Object then
8608 if not Is_Library_Level_Entity (Def_Id) then
8609 Error_Pragma_Arg
8610 ("argument for pragma% must be library level entity",
8611 Arg_Internal);
8612 end if;
8613
8614 if Ekind (Current_Scope) = E_Generic_Package then
8615 Error_Pragma ("pragma& cannot appear in a generic unit");
8616 end if;
8617
8618 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
8619 Error_Pragma_Arg
8620 ("exported object must have compile time known size",
8621 Arg_Internal);
8622 end if;
8623
8624 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
8625 Error_Msg_N ("??duplicate Export_Object pragma", N);
8626 else
8627 Set_Exported (Def_Id, Arg_Internal);
8628 end if;
8629
8630 -- Import_Object case
8631
8632 else
8633 if Is_Concurrent_Type (Etype (Def_Id)) then
8634 Error_Pragma_Arg
8635 ("cannot use pragma% for task/protected object",
8636 Arg_Internal);
8637 end if;
8638
8639 if Ekind (Def_Id) = E_Constant then
8640 Error_Pragma_Arg
8641 ("cannot import a constant", Arg_Internal);
8642 end if;
8643
8644 if Warn_On_Export_Import
8645 and then Has_Discriminants (Etype (Def_Id))
8646 then
8647 Error_Msg_N
8648 ("imported value must be initialized??", Arg_Internal);
8649 end if;
8650
8651 if Warn_On_Export_Import
8652 and then Is_Access_Type (Etype (Def_Id))
8653 then
8654 Error_Pragma_Arg
8655 ("cannot import object of an access type??", Arg_Internal);
8656 end if;
8657
8658 if Warn_On_Export_Import
8659 and then Is_Imported (Def_Id)
8660 then
8661 Error_Msg_N ("??duplicate Import_Object pragma", N);
8662
8663 -- Check for explicit initialization present. Note that an
8664 -- initialization generated by the code generator, e.g. for an
8665 -- access type, does not count here.
8666
8667 elsif Present (Expression (Parent (Def_Id)))
8668 and then
8669 Comes_From_Source
8670 (Original_Node (Expression (Parent (Def_Id))))
8671 then
8672 Error_Msg_Sloc := Sloc (Def_Id);
8673 Error_Pragma_Arg
8674 ("imported entities cannot be initialized (RM B.1(24))",
8675 "\no initialization allowed for & declared#", Arg1);
8676 else
8677 Set_Imported (Def_Id);
8678 Note_Possible_Modification (Arg_Internal, Sure => False);
8679 end if;
8680 end if;
8681 end Process_Extended_Import_Export_Object_Pragma;
8682
8683 ------------------------------------------------------
8684 -- Process_Extended_Import_Export_Subprogram_Pragma --
8685 ------------------------------------------------------
8686
8687 procedure Process_Extended_Import_Export_Subprogram_Pragma
8688 (Arg_Internal : Node_Id;
8689 Arg_External : Node_Id;
8690 Arg_Parameter_Types : Node_Id;
8691 Arg_Result_Type : Node_Id := Empty;
8692 Arg_Mechanism : Node_Id;
8693 Arg_Result_Mechanism : Node_Id := Empty)
8694 is
8695 Ent : Entity_Id;
8696 Def_Id : Entity_Id;
8697 Hom_Id : Entity_Id;
8698 Formal : Entity_Id;
8699 Ambiguous : Boolean;
8700 Match : Boolean;
8701
8702 function Same_Base_Type
8703 (Ptype : Node_Id;
8704 Formal : Entity_Id) return Boolean;
8705 -- Determines if Ptype references the type of Formal. Note that only
8706 -- the base types need to match according to the spec. Ptype here is
8707 -- the argument from the pragma, which is either a type name, or an
8708 -- access attribute.
8709
8710 --------------------
8711 -- Same_Base_Type --
8712 --------------------
8713
8714 function Same_Base_Type
8715 (Ptype : Node_Id;
8716 Formal : Entity_Id) return Boolean
8717 is
8718 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
8719 Pref : Node_Id;
8720
8721 begin
8722 -- Case where pragma argument is typ'Access
8723
8724 if Nkind (Ptype) = N_Attribute_Reference
8725 and then Attribute_Name (Ptype) = Name_Access
8726 then
8727 Pref := Prefix (Ptype);
8728 Find_Type (Pref);
8729
8730 if not Is_Entity_Name (Pref)
8731 or else Entity (Pref) = Any_Type
8732 then
8733 raise Pragma_Exit;
8734 end if;
8735
8736 -- We have a match if the corresponding argument is of an
8737 -- anonymous access type, and its designated type matches the
8738 -- type of the prefix of the access attribute
8739
8740 return Ekind (Ftyp) = E_Anonymous_Access_Type
8741 and then Base_Type (Entity (Pref)) =
8742 Base_Type (Etype (Designated_Type (Ftyp)));
8743
8744 -- Case where pragma argument is a type name
8745
8746 else
8747 Find_Type (Ptype);
8748
8749 if not Is_Entity_Name (Ptype)
8750 or else Entity (Ptype) = Any_Type
8751 then
8752 raise Pragma_Exit;
8753 end if;
8754
8755 -- We have a match if the corresponding argument is of the type
8756 -- given in the pragma (comparing base types)
8757
8758 return Base_Type (Entity (Ptype)) = Ftyp;
8759 end if;
8760 end Same_Base_Type;
8761
8762 -- Start of processing for
8763 -- Process_Extended_Import_Export_Subprogram_Pragma
8764
8765 begin
8766 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8767 Ent := Empty;
8768 Ambiguous := False;
8769
8770 -- Loop through homonyms (overloadings) of the entity
8771
8772 Hom_Id := Entity (Arg_Internal);
8773 while Present (Hom_Id) loop
8774 Def_Id := Get_Base_Subprogram (Hom_Id);
8775
8776 -- We need a subprogram in the current scope
8777
8778 if not Is_Subprogram (Def_Id)
8779 or else Scope (Def_Id) /= Current_Scope
8780 then
8781 null;
8782
8783 else
8784 Match := True;
8785
8786 -- Pragma cannot apply to subprogram body
8787
8788 if Is_Subprogram (Def_Id)
8789 and then Nkind (Parent (Declaration_Node (Def_Id))) =
8790 N_Subprogram_Body
8791 then
8792 Error_Pragma
8793 ("pragma% requires separate spec and must come before "
8794 & "body");
8795 end if;
8796
8797 -- Test result type if given, note that the result type
8798 -- parameter can only be present for the function cases.
8799
8800 if Present (Arg_Result_Type)
8801 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
8802 then
8803 Match := False;
8804
8805 elsif Etype (Def_Id) /= Standard_Void_Type
8806 and then
8807 Pname in Name_Export_Procedure | Name_Import_Procedure
8808 then
8809 Match := False;
8810
8811 -- Test parameter types if given. Note that this parameter has
8812 -- not been analyzed (and must not be, since it is semantic
8813 -- nonsense), so we get it as the parser left it.
8814
8815 elsif Present (Arg_Parameter_Types) then
8816 Check_Matching_Types : declare
8817 Formal : Entity_Id;
8818 Ptype : Node_Id;
8819
8820 begin
8821 Formal := First_Formal (Def_Id);
8822
8823 if Nkind (Arg_Parameter_Types) = N_Null then
8824 if Present (Formal) then
8825 Match := False;
8826 end if;
8827
8828 -- A list of one type, e.g. (List) is parsed as a
8829 -- parenthesized expression.
8830
8831 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
8832 and then Paren_Count (Arg_Parameter_Types) = 1
8833 then
8834 if No (Formal)
8835 or else Present (Next_Formal (Formal))
8836 then
8837 Match := False;
8838 else
8839 Match :=
8840 Same_Base_Type (Arg_Parameter_Types, Formal);
8841 end if;
8842
8843 -- A list of more than one type is parsed as a aggregate
8844
8845 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
8846 and then Paren_Count (Arg_Parameter_Types) = 0
8847 then
8848 Ptype := First (Expressions (Arg_Parameter_Types));
8849 while Present (Ptype) or else Present (Formal) loop
8850 if No (Ptype)
8851 or else No (Formal)
8852 or else not Same_Base_Type (Ptype, Formal)
8853 then
8854 Match := False;
8855 exit;
8856 else
8857 Next_Formal (Formal);
8858 Next (Ptype);
8859 end if;
8860 end loop;
8861
8862 -- Anything else is of the wrong form
8863
8864 else
8865 Error_Pragma_Arg
8866 ("wrong form for Parameter_Types parameter",
8867 Arg_Parameter_Types);
8868 end if;
8869 end Check_Matching_Types;
8870 end if;
8871
8872 -- Match is now False if the entry we found did not match
8873 -- either a supplied Parameter_Types or Result_Types argument
8874
8875 if Match then
8876 if No (Ent) then
8877 Ent := Def_Id;
8878
8879 -- Ambiguous case, the flag Ambiguous shows if we already
8880 -- detected this and output the initial messages.
8881
8882 else
8883 if not Ambiguous then
8884 Ambiguous := True;
8885 Error_Msg_Name_1 := Pname;
8886 Error_Msg_N
8887 ("pragma% does not uniquely identify subprogram!",
8888 N);
8889 Error_Msg_Sloc := Sloc (Ent);
8890 Error_Msg_N ("matching subprogram #!", N);
8891 Ent := Empty;
8892 end if;
8893
8894 Error_Msg_Sloc := Sloc (Def_Id);
8895 Error_Msg_N ("matching subprogram #!", N);
8896 end if;
8897 end if;
8898 end if;
8899
8900 Hom_Id := Homonym (Hom_Id);
8901 end loop;
8902
8903 -- See if we found an entry
8904
8905 if No (Ent) then
8906 if not Ambiguous then
8907 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
8908 Error_Pragma
8909 ("pragma% cannot be given for generic subprogram");
8910 else
8911 Error_Pragma
8912 ("pragma% does not identify local subprogram");
8913 end if;
8914 end if;
8915
8916 return;
8917 end if;
8918
8919 -- Import pragmas must be for imported entities
8920
8921 if Prag_Id = Pragma_Import_Function
8922 or else
8923 Prag_Id = Pragma_Import_Procedure
8924 or else
8925 Prag_Id = Pragma_Import_Valued_Procedure
8926 then
8927 if not Is_Imported (Ent) then
8928 Error_Pragma
8929 ("pragma Import or Interface must precede pragma%");
8930 end if;
8931
8932 -- Here we have the Export case which can set the entity as exported
8933
8934 -- But does not do so if the specified external name is null, since
8935 -- that is taken as a signal in DEC Ada 83 (with which we want to be
8936 -- compatible) to request no external name.
8937
8938 elsif Nkind (Arg_External) = N_String_Literal
8939 and then String_Length (Strval (Arg_External)) = 0
8940 then
8941 null;
8942
8943 -- In all other cases, set entity as exported
8944
8945 else
8946 Set_Exported (Ent, Arg_Internal);
8947 end if;
8948
8949 -- Special processing for Valued_Procedure cases
8950
8951 if Prag_Id = Pragma_Import_Valued_Procedure
8952 or else
8953 Prag_Id = Pragma_Export_Valued_Procedure
8954 then
8955 Formal := First_Formal (Ent);
8956
8957 if No (Formal) then
8958 Error_Pragma ("at least one parameter required for pragma%");
8959
8960 elsif Ekind (Formal) /= E_Out_Parameter then
8961 Error_Pragma ("first parameter must have mode out for pragma%");
8962
8963 else
8964 Set_Is_Valued_Procedure (Ent);
8965 end if;
8966 end if;
8967
8968 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
8969
8970 -- Process Result_Mechanism argument if present. We have already
8971 -- checked that this is only allowed for the function case.
8972
8973 if Present (Arg_Result_Mechanism) then
8974 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
8975 end if;
8976
8977 -- Process Mechanism parameter if present. Note that this parameter
8978 -- is not analyzed, and must not be analyzed since it is semantic
8979 -- nonsense, so we get it in exactly as the parser left it.
8980
8981 if Present (Arg_Mechanism) then
8982 declare
8983 Formal : Entity_Id;
8984 Massoc : Node_Id;
8985 Mname : Node_Id;
8986 Choice : Node_Id;
8987
8988 begin
8989 -- A single mechanism association without a formal parameter
8990 -- name is parsed as a parenthesized expression. All other
8991 -- cases are parsed as aggregates, so we rewrite the single
8992 -- parameter case as an aggregate for consistency.
8993
8994 if Nkind (Arg_Mechanism) /= N_Aggregate
8995 and then Paren_Count (Arg_Mechanism) = 1
8996 then
8997 Rewrite (Arg_Mechanism,
8998 Make_Aggregate (Sloc (Arg_Mechanism),
8999 Expressions => New_List (
9000 Relocate_Node (Arg_Mechanism))));
9001 end if;
9002
9003 -- Case of only mechanism name given, applies to all formals
9004
9005 if Nkind (Arg_Mechanism) /= N_Aggregate then
9006 Formal := First_Formal (Ent);
9007 while Present (Formal) loop
9008 Set_Mechanism_Value (Formal, Arg_Mechanism);
9009 Next_Formal (Formal);
9010 end loop;
9011
9012 -- Case of list of mechanism associations given
9013
9014 else
9015 if Null_Record_Present (Arg_Mechanism) then
9016 Error_Pragma_Arg
9017 ("inappropriate form for Mechanism parameter",
9018 Arg_Mechanism);
9019 end if;
9020
9021 -- Deal with positional ones first
9022
9023 Formal := First_Formal (Ent);
9024
9025 if Present (Expressions (Arg_Mechanism)) then
9026 Mname := First (Expressions (Arg_Mechanism));
9027 while Present (Mname) loop
9028 if No (Formal) then
9029 Error_Pragma_Arg
9030 ("too many mechanism associations", Mname);
9031 end if;
9032
9033 Set_Mechanism_Value (Formal, Mname);
9034 Next_Formal (Formal);
9035 Next (Mname);
9036 end loop;
9037 end if;
9038
9039 -- Deal with named entries
9040
9041 if Present (Component_Associations (Arg_Mechanism)) then
9042 Massoc := First (Component_Associations (Arg_Mechanism));
9043 while Present (Massoc) loop
9044 Choice := First (Choices (Massoc));
9045
9046 if Nkind (Choice) /= N_Identifier
9047 or else Present (Next (Choice))
9048 then
9049 Error_Pragma_Arg
9050 ("incorrect form for mechanism association",
9051 Massoc);
9052 end if;
9053
9054 Formal := First_Formal (Ent);
9055 loop
9056 if No (Formal) then
9057 Error_Pragma_Arg
9058 ("parameter name & not present", Choice);
9059 end if;
9060
9061 if Chars (Choice) = Chars (Formal) then
9062 Set_Mechanism_Value
9063 (Formal, Expression (Massoc));
9064
9065 -- Set entity on identifier for proper tree
9066 -- structure.
9067
9068 Set_Entity (Choice, Formal);
9069
9070 exit;
9071 end if;
9072
9073 Next_Formal (Formal);
9074 end loop;
9075
9076 Next (Massoc);
9077 end loop;
9078 end if;
9079 end if;
9080 end;
9081 end if;
9082 end Process_Extended_Import_Export_Subprogram_Pragma;
9083
9084 --------------------------
9085 -- Process_Generic_List --
9086 --------------------------
9087
9088 procedure Process_Generic_List is
9089 Arg : Node_Id;
9090 Exp : Node_Id;
9091
9092 begin
9093 Check_No_Identifiers;
9094 Check_At_Least_N_Arguments (1);
9095
9096 -- Check all arguments are names of generic units or instances
9097
9098 Arg := Arg1;
9099 while Present (Arg) loop
9100 Exp := Get_Pragma_Arg (Arg);
9101 Analyze (Exp);
9102
9103 if not Is_Entity_Name (Exp)
9104 or else
9105 (not Is_Generic_Instance (Entity (Exp))
9106 and then
9107 not Is_Generic_Unit (Entity (Exp)))
9108 then
9109 Error_Pragma_Arg
9110 ("pragma% argument must be name of generic unit/instance",
9111 Arg);
9112 end if;
9113
9114 Next (Arg);
9115 end loop;
9116 end Process_Generic_List;
9117
9118 ------------------------------------
9119 -- Process_Import_Predefined_Type --
9120 ------------------------------------
9121
9122 procedure Process_Import_Predefined_Type is
9123 Loc : constant Source_Ptr := Sloc (N);
9124 Elmt : Elmt_Id;
9125 Ftyp : Node_Id := Empty;
9126 Decl : Node_Id;
9127 Def : Node_Id;
9128 Nam : Name_Id;
9129
9130 begin
9131 Nam := String_To_Name (Strval (Expression (Arg3)));
9132
9133 Elmt := First_Elmt (Predefined_Float_Types);
9134 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
9135 Next_Elmt (Elmt);
9136 end loop;
9137
9138 Ftyp := Node (Elmt);
9139
9140 if Present (Ftyp) then
9141
9142 -- Don't build a derived type declaration, because predefined C
9143 -- types have no declaration anywhere, so cannot really be named.
9144 -- Instead build a full type declaration, starting with an
9145 -- appropriate type definition is built
9146
9147 if Is_Floating_Point_Type (Ftyp) then
9148 Def := Make_Floating_Point_Definition (Loc,
9149 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
9150 Make_Real_Range_Specification (Loc,
9151 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
9152 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
9153
9154 -- Should never have a predefined type we cannot handle
9155
9156 else
9157 raise Program_Error;
9158 end if;
9159
9160 -- Build and insert a Full_Type_Declaration, which will be
9161 -- analyzed as soon as this list entry has been analyzed.
9162
9163 Decl := Make_Full_Type_Declaration (Loc,
9164 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
9165 Type_Definition => Def);
9166
9167 Insert_After (N, Decl);
9168 Mark_Rewrite_Insertion (Decl);
9169
9170 else
9171 Error_Pragma_Arg ("no matching type found for pragma%", Arg2);
9172 end if;
9173 end Process_Import_Predefined_Type;
9174
9175 ---------------------------------
9176 -- Process_Import_Or_Interface --
9177 ---------------------------------
9178
9179 procedure Process_Import_Or_Interface is
9180 C : Convention_Id;
9181 Def_Id : Entity_Id;
9182 Hom_Id : Entity_Id;
9183
9184 begin
9185 -- In Relaxed_RM_Semantics, support old Ada 83 style:
9186 -- pragma Import (Entity, "external name");
9187
9188 if Relaxed_RM_Semantics
9189 and then Arg_Count = 2
9190 and then Prag_Id = Pragma_Import
9191 and then Nkind (Expression (Arg2)) = N_String_Literal
9192 then
9193 C := Convention_C;
9194 Def_Id := Get_Pragma_Arg (Arg1);
9195 Analyze (Def_Id);
9196
9197 if not Is_Entity_Name (Def_Id) then
9198 Error_Pragma_Arg ("entity name required", Arg1);
9199 end if;
9200
9201 Def_Id := Entity (Def_Id);
9202 Kill_Size_Check_Code (Def_Id);
9203 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
9204
9205 else
9206 Process_Convention (C, Def_Id);
9207
9208 -- A pragma that applies to a Ghost entity becomes Ghost for the
9209 -- purposes of legality checks and removal of ignored Ghost code.
9210
9211 Mark_Ghost_Pragma (N, Def_Id);
9212 Kill_Size_Check_Code (Def_Id);
9213 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
9214 end if;
9215
9216 -- Various error checks
9217
9218 if Ekind (Def_Id) in E_Variable | E_Constant then
9219
9220 -- We do not permit Import to apply to a renaming declaration
9221
9222 if Present (Renamed_Object (Def_Id)) then
9223 Error_Pragma_Arg
9224 ("pragma% not allowed for object renaming", Arg2);
9225
9226 -- User initialization is not allowed for imported object, but
9227 -- the object declaration may contain a default initialization,
9228 -- that will be discarded. Note that an explicit initialization
9229 -- only counts if it comes from source, otherwise it is simply
9230 -- the code generator making an implicit initialization explicit.
9231
9232 elsif Present (Expression (Parent (Def_Id)))
9233 and then Comes_From_Source
9234 (Original_Node (Expression (Parent (Def_Id))))
9235 then
9236 -- Set imported flag to prevent cascaded errors
9237
9238 Set_Is_Imported (Def_Id);
9239
9240 Error_Msg_Sloc := Sloc (Def_Id);
9241 Error_Pragma_Arg
9242 ("no initialization allowed for declaration of& #",
9243 "\imported entities cannot be initialized (RM B.1(24))",
9244 Arg2);
9245
9246 else
9247 -- If the pragma comes from an aspect specification the
9248 -- Is_Imported flag has already been set.
9249
9250 if not From_Aspect_Specification (N) then
9251 Set_Imported (Def_Id);
9252 end if;
9253
9254 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9255
9256 -- Note that we do not set Is_Public here. That's because we
9257 -- only want to set it if there is no address clause, and we
9258 -- don't know that yet, so we delay that processing till
9259 -- freeze time.
9260
9261 -- pragma Import completes deferred constants
9262
9263 if Ekind (Def_Id) = E_Constant then
9264 Set_Has_Completion (Def_Id);
9265 end if;
9266
9267 -- It is not possible to import a constant of an unconstrained
9268 -- array type (e.g. string) because there is no simple way to
9269 -- write a meaningful subtype for it.
9270
9271 if Is_Array_Type (Etype (Def_Id))
9272 and then not Is_Constrained (Etype (Def_Id))
9273 then
9274 Error_Msg_NE
9275 ("imported constant& must have a constrained subtype",
9276 N, Def_Id);
9277 end if;
9278 end if;
9279
9280 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9281
9282 -- If the name is overloaded, pragma applies to all of the denoted
9283 -- entities in the same declarative part, unless the pragma comes
9284 -- from an aspect specification or was generated by the compiler
9285 -- (such as for pragma Provide_Shift_Operators).
9286
9287 Hom_Id := Def_Id;
9288 while Present (Hom_Id) loop
9289
9290 Def_Id := Get_Base_Subprogram (Hom_Id);
9291
9292 -- Ignore inherited subprograms because the pragma will apply
9293 -- to the parent operation, which is the one called.
9294
9295 if Is_Overloadable (Def_Id)
9296 and then Present (Alias (Def_Id))
9297 then
9298 null;
9299
9300 -- If it is not a subprogram, it must be in an outer scope and
9301 -- pragma does not apply.
9302
9303 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9304 null;
9305
9306 -- The pragma does not apply to primitives of interfaces
9307
9308 elsif Is_Dispatching_Operation (Def_Id)
9309 and then Present (Find_Dispatching_Type (Def_Id))
9310 and then Is_Interface (Find_Dispatching_Type (Def_Id))
9311 then
9312 null;
9313
9314 -- Verify that the homonym is in the same declarative part (not
9315 -- just the same scope). If the pragma comes from an aspect
9316 -- specification we know that it is part of the declaration.
9317
9318 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
9319 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9320 and then not From_Aspect_Specification (N)
9321 then
9322 exit;
9323
9324 else
9325 -- If the pragma comes from an aspect specification the
9326 -- Is_Imported flag has already been set.
9327
9328 if not From_Aspect_Specification (N) then
9329 Set_Imported (Def_Id);
9330 end if;
9331
9332 -- Reject an Import applied to an abstract subprogram
9333
9334 if Is_Subprogram (Def_Id)
9335 and then Is_Abstract_Subprogram (Def_Id)
9336 then
9337 Error_Msg_Sloc := Sloc (Def_Id);
9338 Error_Msg_NE
9339 ("cannot import abstract subprogram& declared#",
9340 Arg2, Def_Id);
9341 end if;
9342
9343 -- Special processing for Convention_Intrinsic
9344
9345 if C = Convention_Intrinsic then
9346
9347 -- Link_Name argument not allowed for intrinsic
9348
9349 Check_No_Link_Name;
9350
9351 Set_Is_Intrinsic_Subprogram (Def_Id);
9352
9353 -- If no external name is present, then check that this
9354 -- is a valid intrinsic subprogram. If an external name
9355 -- is present, then this is handled by the back end.
9356
9357 if No (Arg3) then
9358 Check_Intrinsic_Subprogram
9359 (Def_Id, Get_Pragma_Arg (Arg2));
9360 end if;
9361 end if;
9362
9363 -- Verify that the subprogram does not have a completion
9364 -- through a renaming declaration. For other completions the
9365 -- pragma appears as a too late representation.
9366
9367 declare
9368 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
9369
9370 begin
9371 if Present (Decl)
9372 and then Nkind (Decl) = N_Subprogram_Declaration
9373 and then Present (Corresponding_Body (Decl))
9374 and then Nkind (Unit_Declaration_Node
9375 (Corresponding_Body (Decl))) =
9376 N_Subprogram_Renaming_Declaration
9377 then
9378 Error_Msg_Sloc := Sloc (Def_Id);
9379 Error_Msg_NE
9380 ("cannot import&, renaming already provided for "
9381 & "declaration #", N, Def_Id);
9382 end if;
9383 end;
9384
9385 -- If the pragma comes from an aspect specification, there
9386 -- must be an Import aspect specified as well. In the rare
9387 -- case where Import is set to False, the suprogram needs to
9388 -- have a local completion.
9389
9390 declare
9391 Imp_Aspect : constant Node_Id :=
9392 Find_Aspect (Def_Id, Aspect_Import);
9393 Expr : Node_Id;
9394
9395 begin
9396 if Present (Imp_Aspect)
9397 and then Present (Expression (Imp_Aspect))
9398 then
9399 Expr := Expression (Imp_Aspect);
9400 Analyze_And_Resolve (Expr, Standard_Boolean);
9401
9402 if Is_Entity_Name (Expr)
9403 and then Entity (Expr) = Standard_True
9404 then
9405 Set_Has_Completion (Def_Id);
9406 end if;
9407
9408 -- If there is no expression, the default is True, as for
9409 -- all boolean aspects. Same for the older pragma.
9410
9411 else
9412 Set_Has_Completion (Def_Id);
9413 end if;
9414 end;
9415
9416 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9417 end if;
9418
9419 if Is_Compilation_Unit (Hom_Id) then
9420
9421 -- Its possible homonyms are not affected by the pragma.
9422 -- Such homonyms might be present in the context of other
9423 -- units being compiled.
9424
9425 exit;
9426
9427 elsif From_Aspect_Specification (N) then
9428 exit;
9429
9430 -- If the pragma was created by the compiler, then we don't
9431 -- want it to apply to other homonyms. This kind of case can
9432 -- occur when using pragma Provide_Shift_Operators, which
9433 -- generates implicit shift and rotate operators with Import
9434 -- pragmas that might apply to earlier explicit or implicit
9435 -- declarations marked with Import (for example, coming from
9436 -- an earlier pragma Provide_Shift_Operators for another type),
9437 -- and we don't generally want other homonyms being treated
9438 -- as imported or the pragma flagged as an illegal duplicate.
9439
9440 elsif not Comes_From_Source (N) then
9441 exit;
9442
9443 else
9444 Hom_Id := Homonym (Hom_Id);
9445 end if;
9446 end loop;
9447
9448 -- Import a CPP class
9449
9450 elsif C = Convention_CPP
9451 and then (Is_Record_Type (Def_Id)
9452 or else Ekind (Def_Id) = E_Incomplete_Type)
9453 then
9454 if Ekind (Def_Id) = E_Incomplete_Type then
9455 if Present (Full_View (Def_Id)) then
9456 Def_Id := Full_View (Def_Id);
9457
9458 else
9459 Error_Msg_N
9460 ("cannot import 'C'P'P type before full declaration seen",
9461 Get_Pragma_Arg (Arg2));
9462
9463 -- Although we have reported the error we decorate it as
9464 -- CPP_Class to avoid reporting spurious errors
9465
9466 Set_Is_CPP_Class (Def_Id);
9467 return;
9468 end if;
9469 end if;
9470
9471 -- Types treated as CPP classes must be declared limited (note:
9472 -- this used to be a warning but there is no real benefit to it
9473 -- since we did effectively intend to treat the type as limited
9474 -- anyway).
9475
9476 if not Is_Limited_Type (Def_Id) then
9477 Error_Msg_N
9478 ("imported 'C'P'P type must be limited",
9479 Get_Pragma_Arg (Arg2));
9480 end if;
9481
9482 if Etype (Def_Id) /= Def_Id
9483 and then not Is_CPP_Class (Root_Type (Def_Id))
9484 then
9485 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
9486 end if;
9487
9488 Set_Is_CPP_Class (Def_Id);
9489
9490 -- Imported CPP types must not have discriminants (because C++
9491 -- classes do not have discriminants).
9492
9493 if Has_Discriminants (Def_Id) then
9494 Error_Msg_N
9495 ("imported 'C'P'P type cannot have discriminants",
9496 First (Discriminant_Specifications
9497 (Declaration_Node (Def_Id))));
9498 end if;
9499
9500 -- Check that components of imported CPP types do not have default
9501 -- expressions. For private types this check is performed when the
9502 -- full view is analyzed (see Process_Full_View).
9503
9504 if not Is_Private_Type (Def_Id) then
9505 Check_CPP_Type_Has_No_Defaults (Def_Id);
9506 end if;
9507
9508 -- Import a CPP exception
9509
9510 elsif C = Convention_CPP
9511 and then Ekind (Def_Id) = E_Exception
9512 then
9513 if No (Arg3) then
9514 Error_Pragma_Arg
9515 ("'External_'Name arguments is required for 'Cpp exception",
9516 Arg3);
9517 else
9518 -- As only a string is allowed, Check_Arg_Is_External_Name
9519 -- isn't called.
9520
9521 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9522 end if;
9523
9524 if Present (Arg4) then
9525 Error_Pragma_Arg
9526 ("Link_Name argument not allowed for imported Cpp exception",
9527 Arg4);
9528 end if;
9529
9530 -- Do not call Set_Interface_Name as the name of the exception
9531 -- shouldn't be modified (and in particular it shouldn't be
9532 -- the External_Name). For exceptions, the External_Name is the
9533 -- name of the RTTI structure.
9534
9535 -- ??? Emit an error if pragma Import/Export_Exception is present
9536
9537 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
9538 Check_No_Link_Name;
9539 Check_Arg_Count (3);
9540 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9541
9542 Process_Import_Predefined_Type;
9543
9544 else
9545 Error_Pragma_Arg
9546 ("second argument of pragma% must be object, subprogram "
9547 & "or incomplete type",
9548 Arg2);
9549 end if;
9550
9551 -- If this pragma applies to a compilation unit, then the unit, which
9552 -- is a subprogram, does not require (or allow) a body. We also do
9553 -- not need to elaborate imported procedures.
9554
9555 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9556 declare
9557 Cunit : constant Node_Id := Parent (Parent (N));
9558 begin
9559 Set_Body_Required (Cunit, False);
9560 end;
9561 end if;
9562 end Process_Import_Or_Interface;
9563
9564 --------------------
9565 -- Process_Inline --
9566 --------------------
9567
9568 procedure Process_Inline (Status : Inline_Status) is
9569 Applies : Boolean;
9570 Assoc : Node_Id;
9571 Decl : Node_Id;
9572 Subp : Entity_Id;
9573 Subp_Id : Node_Id;
9574
9575 Ghost_Error_Posted : Boolean := False;
9576 -- Flag set when an error concerning the illegal mix of Ghost and
9577 -- non-Ghost subprograms is emitted.
9578
9579 Ghost_Id : Entity_Id := Empty;
9580 -- The entity of the first Ghost subprogram encountered while
9581 -- processing the arguments of the pragma.
9582
9583 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id);
9584 -- Verify the placement of pragma Inline_Always with respect to the
9585 -- initial declaration of subprogram Spec_Id.
9586
9587 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
9588 -- Returns True if it can be determined at this stage that inlining
9589 -- is not possible, for example if the body is available and contains
9590 -- exception handlers, we prevent inlining, since otherwise we can
9591 -- get undefined symbols at link time. This function also emits a
9592 -- warning if the pragma appears too late.
9593 --
9594 -- ??? is business with link symbols still valid, or does it relate
9595 -- to front end ZCX which is being phased out ???
9596
9597 procedure Make_Inline (Subp : Entity_Id);
9598 -- Subp is the defining unit name of the subprogram declaration. If
9599 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
9600 -- the corresponding body, if there is one present.
9601
9602 procedure Set_Inline_Flags (Subp : Entity_Id);
9603 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
9604 -- Also set or clear Is_Inlined flag on Subp depending on Status.
9605
9606 -----------------------------------
9607 -- Check_Inline_Always_Placement --
9608 -----------------------------------
9609
9610 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id) is
9611 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id);
9612
9613 function Compilation_Unit_OK return Boolean;
9614 pragma Inline (Compilation_Unit_OK);
9615 -- Determine whether pragma Inline_Always applies to a compatible
9616 -- compilation unit denoted by Spec_Id.
9617
9618 function Declarative_List_OK return Boolean;
9619 pragma Inline (Declarative_List_OK);
9620 -- Determine whether the initial declaration of subprogram Spec_Id
9621 -- and the pragma appear in compatible declarative lists.
9622
9623 function Subprogram_Body_OK return Boolean;
9624 pragma Inline (Subprogram_Body_OK);
9625 -- Determine whether pragma Inline_Always applies to a compatible
9626 -- subprogram body denoted by Spec_Id.
9627
9628 -------------------------
9629 -- Compilation_Unit_OK --
9630 -------------------------
9631
9632 function Compilation_Unit_OK return Boolean is
9633 Comp_Unit : constant Node_Id := Parent (Spec_Decl);
9634
9635 begin
9636 -- The pragma appears after the initial declaration of a
9637 -- compilation unit.
9638
9639 -- procedure Comp_Unit;
9640 -- pragma Inline_Always (Comp_Unit);
9641
9642 -- Note that for compatibility reasons, the following case is
9643 -- also accepted.
9644
9645 -- procedure Stand_Alone_Body_Comp_Unit is
9646 -- ...
9647 -- end Stand_Alone_Body_Comp_Unit;
9648 -- pragma Inline_Always (Stand_Alone_Body_Comp_Unit);
9649
9650 return
9651 Nkind (Comp_Unit) = N_Compilation_Unit
9652 and then Present (Aux_Decls_Node (Comp_Unit))
9653 and then Is_List_Member (N)
9654 and then List_Containing (N) =
9655 Pragmas_After (Aux_Decls_Node (Comp_Unit));
9656 end Compilation_Unit_OK;
9657
9658 -------------------------
9659 -- Declarative_List_OK --
9660 -------------------------
9661
9662 function Declarative_List_OK return Boolean is
9663 Context : constant Node_Id := Parent (Spec_Decl);
9664
9665 Init_Decl : Node_Id;
9666 Init_List : List_Id;
9667 Prag_List : List_Id;
9668
9669 begin
9670 -- Determine the proper initial declaration. In general this is
9671 -- the declaration node of the subprogram except when the input
9672 -- denotes a generic instantiation.
9673
9674 -- procedure Inst is new Gen;
9675 -- pragma Inline_Always (Inst);
9676
9677 -- In this case the original subprogram is moved inside an
9678 -- anonymous package while pragma Inline_Always remains at the
9679 -- level of the anonymous package. Use the declaration of the
9680 -- package because it reflects the placement of the original
9681 -- instantiation.
9682
9683 -- package Anon_Pack is
9684 -- procedure Inst is ... end Inst; -- original
9685 -- end Anon_Pack;
9686
9687 -- procedure Inst renames Anon_Pack.Inst;
9688 -- pragma Inline_Always (Inst);
9689
9690 if Is_Generic_Instance (Spec_Id) then
9691 Init_Decl := Parent (Parent (Spec_Decl));
9692 pragma Assert (Nkind (Init_Decl) = N_Package_Declaration);
9693 else
9694 Init_Decl := Spec_Decl;
9695 end if;
9696
9697 if Is_List_Member (Init_Decl) and then Is_List_Member (N) then
9698 Init_List := List_Containing (Init_Decl);
9699 Prag_List := List_Containing (N);
9700
9701 -- The pragma and then initial declaration appear within the
9702 -- same declarative list.
9703
9704 if Init_List = Prag_List then
9705 return True;
9706
9707 -- A special case of the above is when both the pragma and
9708 -- the initial declaration appear in different lists of a
9709 -- package spec, protected definition, or a task definition.
9710
9711 -- package Pack is
9712 -- procedure Proc;
9713 -- private
9714 -- pragma Inline_Always (Proc);
9715 -- end Pack;
9716
9717 elsif Nkind (Context) in N_Package_Specification
9718 | N_Protected_Definition
9719 | N_Task_Definition
9720 and then Init_List = Visible_Declarations (Context)
9721 and then Prag_List = Private_Declarations (Context)
9722 then
9723 return True;
9724 end if;
9725 end if;
9726
9727 return False;
9728 end Declarative_List_OK;
9729
9730 ------------------------
9731 -- Subprogram_Body_OK --
9732 ------------------------
9733
9734 function Subprogram_Body_OK return Boolean is
9735 Body_Decl : Node_Id;
9736
9737 begin
9738 -- The pragma appears within the declarative list of a stand-
9739 -- alone subprogram body.
9740
9741 -- procedure Stand_Alone_Body is
9742 -- pragma Inline_Always (Stand_Alone_Body);
9743 -- begin
9744 -- ...
9745 -- end Stand_Alone_Body;
9746
9747 -- The compiler creates a dummy spec in this case, however the
9748 -- pragma remains within the declarative list of the body.
9749
9750 if Nkind (Spec_Decl) = N_Subprogram_Declaration
9751 and then not Comes_From_Source (Spec_Decl)
9752 and then Present (Corresponding_Body (Spec_Decl))
9753 then
9754 Body_Decl :=
9755 Unit_Declaration_Node (Corresponding_Body (Spec_Decl));
9756
9757 if Present (Declarations (Body_Decl))
9758 and then Is_List_Member (N)
9759 and then List_Containing (N) = Declarations (Body_Decl)
9760 then
9761 return True;
9762 end if;
9763 end if;
9764
9765 return False;
9766 end Subprogram_Body_OK;
9767
9768 -- Start of processing for Check_Inline_Always_Placement
9769
9770 begin
9771 -- This check is relevant only for pragma Inline_Always
9772
9773 if Pname /= Name_Inline_Always then
9774 return;
9775
9776 -- Nothing to do when the pragma is internally generated on the
9777 -- assumption that it is properly placed.
9778
9779 elsif not Comes_From_Source (N) then
9780 return;
9781
9782 -- Nothing to do for internally generated subprograms that act
9783 -- as accidental homonyms of a source subprogram being inlined.
9784
9785 elsif not Comes_From_Source (Spec_Id) then
9786 return;
9787
9788 -- Nothing to do for generic formal subprograms that act as
9789 -- homonyms of another source subprogram being inlined.
9790
9791 elsif Is_Formal_Subprogram (Spec_Id) then
9792 return;
9793
9794 elsif Compilation_Unit_OK
9795 or else Declarative_List_OK
9796 or else Subprogram_Body_OK
9797 then
9798 return;
9799 end if;
9800
9801 -- At this point it is known that the pragma applies to or appears
9802 -- within a completing body, a completing stub, or a subunit.
9803
9804 Error_Msg_Name_1 := Pname;
9805 Error_Msg_Name_2 := Chars (Spec_Id);
9806 Error_Msg_Sloc := Sloc (Spec_Id);
9807
9808 Error_Msg_N
9809 ("pragma % must appear on initial declaration of subprogram "
9810 & "% defined #", N);
9811 end Check_Inline_Always_Placement;
9812
9813 ---------------------------
9814 -- Inlining_Not_Possible --
9815 ---------------------------
9816
9817 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
9818 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
9819 Stats : Node_Id;
9820
9821 begin
9822 if Nkind (Decl) = N_Subprogram_Body then
9823 Stats := Handled_Statement_Sequence (Decl);
9824 return Present (Exception_Handlers (Stats))
9825 or else Present (At_End_Proc (Stats));
9826
9827 elsif Nkind (Decl) = N_Subprogram_Declaration
9828 and then Present (Corresponding_Body (Decl))
9829 then
9830 if Analyzed (Corresponding_Body (Decl)) then
9831 Error_Msg_N ("pragma appears too late, ignored??", N);
9832 return True;
9833
9834 -- If the subprogram is a renaming as body, the body is just a
9835 -- call to the renamed subprogram, and inlining is trivially
9836 -- possible.
9837
9838 elsif
9839 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
9840 N_Subprogram_Renaming_Declaration
9841 then
9842 return False;
9843
9844 else
9845 Stats :=
9846 Handled_Statement_Sequence
9847 (Unit_Declaration_Node (Corresponding_Body (Decl)));
9848
9849 return
9850 Present (Exception_Handlers (Stats))
9851 or else Present (At_End_Proc (Stats));
9852 end if;
9853
9854 else
9855 -- If body is not available, assume the best, the check is
9856 -- performed again when compiling enclosing package bodies.
9857
9858 return False;
9859 end if;
9860 end Inlining_Not_Possible;
9861
9862 -----------------
9863 -- Make_Inline --
9864 -----------------
9865
9866 procedure Make_Inline (Subp : Entity_Id) is
9867 Kind : constant Entity_Kind := Ekind (Subp);
9868 Inner_Subp : Entity_Id := Subp;
9869
9870 begin
9871 -- Ignore if bad type, avoid cascaded error
9872
9873 if Etype (Subp) = Any_Type then
9874 Applies := True;
9875 return;
9876
9877 -- If inlining is not possible, for now do not treat as an error
9878
9879 elsif Status /= Suppressed
9880 and then Front_End_Inlining
9881 and then Inlining_Not_Possible (Subp)
9882 then
9883 Applies := True;
9884 return;
9885
9886 -- Here we have a candidate for inlining, but we must exclude
9887 -- derived operations. Otherwise we would end up trying to inline
9888 -- a phantom declaration, and the result would be to drag in a
9889 -- body which has no direct inlining associated with it. That
9890 -- would not only be inefficient but would also result in the
9891 -- backend doing cross-unit inlining in cases where it was
9892 -- definitely inappropriate to do so.
9893
9894 -- However, a simple Comes_From_Source test is insufficient, since
9895 -- we do want to allow inlining of generic instances which also do
9896 -- not come from source. We also need to recognize specs generated
9897 -- by the front-end for bodies that carry the pragma. Finally,
9898 -- predefined operators do not come from source but are not
9899 -- inlineable either.
9900
9901 elsif Is_Generic_Instance (Subp)
9902 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
9903 then
9904 null;
9905
9906 elsif not Comes_From_Source (Subp)
9907 and then Scope (Subp) /= Standard_Standard
9908 then
9909 Applies := True;
9910 return;
9911 end if;
9912
9913 -- The referenced entity must either be the enclosing entity, or
9914 -- an entity declared within the current open scope.
9915
9916 if Present (Scope (Subp))
9917 and then Scope (Subp) /= Current_Scope
9918 and then Subp /= Current_Scope
9919 then
9920 Error_Pragma_Arg
9921 ("argument of% must be entity in current scope", Assoc);
9922 return;
9923 end if;
9924
9925 -- Processing for procedure, operator or function. If subprogram
9926 -- is aliased (as for an instance) indicate that the renamed
9927 -- entity (if declared in the same unit) is inlined.
9928 -- If this is the anonymous subprogram created for a subprogram
9929 -- instance, the inlining applies to it directly. Otherwise we
9930 -- retrieve it as the alias of the visible subprogram instance.
9931
9932 if Is_Subprogram (Subp) then
9933
9934 -- Ensure that pragma Inline_Always is associated with the
9935 -- initial declaration of the subprogram.
9936
9937 Check_Inline_Always_Placement (Subp);
9938
9939 if Is_Wrapper_Package (Scope (Subp)) then
9940 Inner_Subp := Subp;
9941 else
9942 Inner_Subp := Ultimate_Alias (Inner_Subp);
9943 end if;
9944
9945 if In_Same_Source_Unit (Subp, Inner_Subp) then
9946 Set_Inline_Flags (Inner_Subp);
9947
9948 Decl := Parent (Parent (Inner_Subp));
9949
9950 if Nkind (Decl) = N_Subprogram_Declaration
9951 and then Present (Corresponding_Body (Decl))
9952 then
9953 Set_Inline_Flags (Corresponding_Body (Decl));
9954
9955 elsif Is_Generic_Instance (Subp)
9956 and then Comes_From_Source (Subp)
9957 then
9958 -- Indicate that the body needs to be created for
9959 -- inlining subsequent calls. The instantiation node
9960 -- follows the declaration of the wrapper package
9961 -- created for it. The subprogram that requires the
9962 -- body is the anonymous one in the wrapper package.
9963
9964 if Scope (Subp) /= Standard_Standard
9965 and then
9966 Need_Subprogram_Instance_Body
9967 (Next (Unit_Declaration_Node
9968 (Scope (Alias (Subp)))), Subp)
9969 then
9970 null;
9971 end if;
9972
9973 -- Inline is a program unit pragma (RM 10.1.5) and cannot
9974 -- appear in a formal part to apply to a formal subprogram.
9975 -- Do not apply check within an instance or a formal package
9976 -- the test will have been applied to the original generic.
9977
9978 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
9979 and then List_Containing (Decl) = List_Containing (N)
9980 and then not In_Instance
9981 then
9982 Error_Msg_N
9983 ("Inline cannot apply to a formal subprogram", N);
9984 end if;
9985 end if;
9986
9987 Applies := True;
9988
9989 -- For a generic subprogram set flag as well, for use at the point
9990 -- of instantiation, to determine whether the body should be
9991 -- generated.
9992
9993 elsif Is_Generic_Subprogram (Subp) then
9994 Set_Inline_Flags (Subp);
9995 Applies := True;
9996
9997 -- Literals are by definition inlined
9998
9999 elsif Kind = E_Enumeration_Literal then
10000 null;
10001
10002 -- Anything else is an error
10003
10004 else
10005 Error_Pragma_Arg
10006 ("expect subprogram name for pragma%", Assoc);
10007 end if;
10008 end Make_Inline;
10009
10010 ----------------------
10011 -- Set_Inline_Flags --
10012 ----------------------
10013
10014 procedure Set_Inline_Flags (Subp : Entity_Id) is
10015 begin
10016 -- First set the Has_Pragma_XXX flags and issue the appropriate
10017 -- errors and warnings for suspicious combinations.
10018
10019 if Prag_Id = Pragma_No_Inline then
10020 if Has_Pragma_Inline_Always (Subp) then
10021 Error_Msg_N
10022 ("Inline_Always and No_Inline are mutually exclusive", N);
10023 elsif Has_Pragma_Inline (Subp) then
10024 Error_Msg_NE
10025 ("Inline and No_Inline both specified for& ??",
10026 N, Entity (Subp_Id));
10027 end if;
10028
10029 Set_Has_Pragma_No_Inline (Subp);
10030 else
10031 if Prag_Id = Pragma_Inline_Always then
10032 if Has_Pragma_No_Inline (Subp) then
10033 Error_Msg_N
10034 ("Inline_Always and No_Inline are mutually exclusive",
10035 N);
10036 end if;
10037
10038 Set_Has_Pragma_Inline_Always (Subp);
10039 else
10040 if Has_Pragma_No_Inline (Subp) then
10041 Error_Msg_NE
10042 ("Inline and No_Inline both specified for& ??",
10043 N, Entity (Subp_Id));
10044 end if;
10045 end if;
10046
10047 Set_Has_Pragma_Inline (Subp);
10048 end if;
10049
10050 -- Then adjust the Is_Inlined flag. It can never be set if the
10051 -- subprogram is subject to pragma No_Inline.
10052
10053 case Status is
10054 when Suppressed =>
10055 Set_Is_Inlined (Subp, False);
10056
10057 when Disabled =>
10058 null;
10059
10060 when Enabled =>
10061 if not Has_Pragma_No_Inline (Subp) then
10062 Set_Is_Inlined (Subp, True);
10063 end if;
10064 end case;
10065
10066 -- A pragma that applies to a Ghost entity becomes Ghost for the
10067 -- purposes of legality checks and removal of ignored Ghost code.
10068
10069 Mark_Ghost_Pragma (N, Subp);
10070
10071 -- Capture the entity of the first Ghost subprogram being
10072 -- processed for error detection purposes.
10073
10074 if Is_Ghost_Entity (Subp) then
10075 if No (Ghost_Id) then
10076 Ghost_Id := Subp;
10077 end if;
10078
10079 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
10080 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
10081
10082 elsif Present (Ghost_Id) and then not Ghost_Error_Posted then
10083 Ghost_Error_Posted := True;
10084
10085 Error_Msg_Name_1 := Pname;
10086 Error_Msg_N
10087 ("pragma % cannot mention ghost and non-ghost subprograms",
10088 N);
10089
10090 Error_Msg_Sloc := Sloc (Ghost_Id);
10091 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
10092
10093 Error_Msg_Sloc := Sloc (Subp);
10094 Error_Msg_NE ("\& # declared as non-ghost", N, Subp);
10095 end if;
10096 end Set_Inline_Flags;
10097
10098 -- Start of processing for Process_Inline
10099
10100 begin
10101 -- An inlined subprogram may grant access to its private enclosing
10102 -- context depending on the placement of its body. From elaboration
10103 -- point of view, the flow of execution may enter this private
10104 -- context, and then reach an external unit, thus producing a
10105 -- dependency on that external unit. For such a path to be properly
10106 -- discovered and encoded in the ALI file of the main unit, let the
10107 -- ABE mechanism process the body of the main unit, and encode all
10108 -- relevant invocation constructs and the relations between them.
10109
10110 Mark_Save_Invocation_Graph_Of_Body;
10111
10112 Check_No_Identifiers;
10113 Check_At_Least_N_Arguments (1);
10114
10115 if Status = Enabled then
10116 Inline_Processing_Required := True;
10117 end if;
10118
10119 Assoc := Arg1;
10120 while Present (Assoc) loop
10121 Subp_Id := Get_Pragma_Arg (Assoc);
10122 Analyze (Subp_Id);
10123 Applies := False;
10124
10125 if Is_Entity_Name (Subp_Id) then
10126 Subp := Entity (Subp_Id);
10127
10128 if Subp = Any_Id then
10129
10130 -- If previous error, avoid cascaded errors
10131
10132 Check_Error_Detected;
10133 Applies := True;
10134
10135 else
10136 -- Check for RM 13.1(9.2/4): If a [...] aspect_specification
10137 -- is given that directly specifies an aspect of an entity,
10138 -- then it is illegal to give another [...]
10139 -- aspect_specification that directly specifies the same
10140 -- aspect of the entity.
10141 -- We only check Subp directly as per "directly specifies"
10142 -- above and because the case of pragma Inline is really
10143 -- special given its pre aspect usage.
10144
10145 Check_Duplicate_Pragma (Subp);
10146 Record_Rep_Item (Subp, N);
10147
10148 Make_Inline (Subp);
10149
10150 -- For the pragma case, climb homonym chain. This is
10151 -- what implements allowing the pragma in the renaming
10152 -- case, with the result applying to the ancestors, and
10153 -- also allows Inline to apply to all previous homonyms.
10154
10155 if not From_Aspect_Specification (N) then
10156 while Present (Homonym (Subp))
10157 and then Scope (Homonym (Subp)) = Current_Scope
10158 loop
10159 Subp := Homonym (Subp);
10160 Make_Inline (Subp);
10161 end loop;
10162 end if;
10163 end if;
10164 end if;
10165
10166 if not Applies then
10167 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
10168 end if;
10169
10170 Next (Assoc);
10171 end loop;
10172
10173 -- If the context is a package declaration, the pragma indicates
10174 -- that inlining will require the presence of the corresponding
10175 -- body. (this may be further refined).
10176
10177 if not In_Instance
10178 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
10179 N_Package_Declaration
10180 then
10181 Set_Body_Needed_For_Inlining (Cunit_Entity (Current_Sem_Unit));
10182 end if;
10183 end Process_Inline;
10184
10185 ----------------------------
10186 -- Process_Interface_Name --
10187 ----------------------------
10188
10189 procedure Process_Interface_Name
10190 (Subprogram_Def : Entity_Id;
10191 Ext_Arg : Node_Id;
10192 Link_Arg : Node_Id;
10193 Prag : Node_Id)
10194 is
10195 Ext_Nam : Node_Id;
10196 Link_Nam : Node_Id;
10197 String_Val : String_Id;
10198
10199 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
10200 -- SN is a string literal node for an interface name. This routine
10201 -- performs some minimal checks that the name is reasonable. In
10202 -- particular that no spaces or other obviously incorrect characters
10203 -- appear. This is only a warning, since any characters are allowed.
10204
10205 ----------------------------------
10206 -- Check_Form_Of_Interface_Name --
10207 ----------------------------------
10208
10209 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
10210 S : constant String_Id := Strval (Expr_Value_S (SN));
10211 SL : constant Nat := String_Length (S);
10212 C : Char_Code;
10213
10214 begin
10215 if SL = 0 then
10216 Error_Msg_N ("interface name cannot be null string", SN);
10217 end if;
10218
10219 for J in 1 .. SL loop
10220 C := Get_String_Char (S, J);
10221
10222 -- Look for dubious character and issue unconditional warning.
10223 -- Definitely dubious if not in character range.
10224
10225 if not In_Character_Range (C)
10226
10227 -- Commas, spaces and (back)slashes are dubious
10228
10229 or else Get_Character (C) = ','
10230 or else Get_Character (C) = '\'
10231 or else Get_Character (C) = ' '
10232 or else Get_Character (C) = '/'
10233 then
10234 Error_Msg
10235 ("??interface name contains illegal character",
10236 Sloc (SN) + Source_Ptr (J));
10237 end if;
10238 end loop;
10239 end Check_Form_Of_Interface_Name;
10240
10241 -- Start of processing for Process_Interface_Name
10242
10243 begin
10244 -- If we are looking at a pragma that comes from an aspect then it
10245 -- needs to have its corresponding aspect argument expressions
10246 -- analyzed in addition to the generated pragma so that aspects
10247 -- within generic units get properly resolved.
10248
10249 if Present (Prag) and then From_Aspect_Specification (Prag) then
10250 declare
10251 Asp : constant Node_Id := Corresponding_Aspect (Prag);
10252 Dummy_1 : Node_Id;
10253 Dummy_2 : Node_Id;
10254 Dummy_3 : Node_Id;
10255 EN : Node_Id;
10256 LN : Node_Id;
10257
10258 begin
10259 -- Obtain all interfacing aspects used to construct the pragma
10260
10261 Get_Interfacing_Aspects
10262 (Asp, Dummy_1, EN, Dummy_2, Dummy_3, LN);
10263
10264 -- Analyze the expression of aspect External_Name
10265
10266 if Present (EN) then
10267 Analyze (Expression (EN));
10268 end if;
10269
10270 -- Analyze the expressio of aspect Link_Name
10271
10272 if Present (LN) then
10273 Analyze (Expression (LN));
10274 end if;
10275 end;
10276 end if;
10277
10278 if No (Link_Arg) then
10279 if No (Ext_Arg) then
10280 return;
10281
10282 elsif Chars (Ext_Arg) = Name_Link_Name then
10283 Ext_Nam := Empty;
10284 Link_Nam := Expression (Ext_Arg);
10285
10286 else
10287 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10288 Ext_Nam := Expression (Ext_Arg);
10289 Link_Nam := Empty;
10290 end if;
10291
10292 else
10293 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10294 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
10295 Ext_Nam := Expression (Ext_Arg);
10296 Link_Nam := Expression (Link_Arg);
10297 end if;
10298
10299 -- Check expressions for external name and link name are static
10300
10301 if Present (Ext_Nam) then
10302 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
10303 Check_Form_Of_Interface_Name (Ext_Nam);
10304
10305 -- Verify that external name is not the name of a local entity,
10306 -- which would hide the imported one and could lead to run-time
10307 -- surprises. The problem can only arise for entities declared in
10308 -- a package body (otherwise the external name is fully qualified
10309 -- and will not conflict).
10310
10311 declare
10312 Nam : Name_Id;
10313 E : Entity_Id;
10314 Par : Node_Id;
10315
10316 begin
10317 if Prag_Id = Pragma_Import then
10318 Nam := String_To_Name (Strval (Expr_Value_S (Ext_Nam)));
10319 E := Entity_Id (Get_Name_Table_Int (Nam));
10320
10321 if Nam /= Chars (Subprogram_Def)
10322 and then Present (E)
10323 and then not Is_Overloadable (E)
10324 and then Is_Immediately_Visible (E)
10325 and then not Is_Imported (E)
10326 and then Ekind (Scope (E)) = E_Package
10327 then
10328 Par := Parent (E);
10329 while Present (Par) loop
10330 if Nkind (Par) = N_Package_Body then
10331 Error_Msg_Sloc := Sloc (E);
10332 Error_Msg_NE
10333 ("imported entity is hidden by & declared#",
10334 Ext_Arg, E);
10335 exit;
10336 end if;
10337
10338 Par := Parent (Par);
10339 end loop;
10340 end if;
10341 end if;
10342 end;
10343 end if;
10344
10345 if Present (Link_Nam) then
10346 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
10347 Check_Form_Of_Interface_Name (Link_Nam);
10348 end if;
10349
10350 -- If there is no link name, just set the external name
10351
10352 if No (Link_Nam) then
10353 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
10354
10355 -- For the Link_Name case, the given literal is preceded by an
10356 -- asterisk, which indicates to GCC that the given name should be
10357 -- taken literally, and in particular that no prepending of
10358 -- underlines should occur, even in systems where this is the
10359 -- normal default.
10360
10361 else
10362 Start_String;
10363 Store_String_Char (Get_Char_Code ('*'));
10364 String_Val := Strval (Expr_Value_S (Link_Nam));
10365 Store_String_Chars (String_Val);
10366 Link_Nam :=
10367 Make_String_Literal (Sloc (Link_Nam),
10368 Strval => End_String);
10369 end if;
10370
10371 -- Set the interface name. If the entity is a generic instance, use
10372 -- its alias, which is the callable entity.
10373
10374 if Is_Generic_Instance (Subprogram_Def) then
10375 Set_Encoded_Interface_Name
10376 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
10377 else
10378 Set_Encoded_Interface_Name
10379 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
10380 end if;
10381
10382 Check_Duplicated_Export_Name (Link_Nam);
10383 end Process_Interface_Name;
10384
10385 -----------------------------------------
10386 -- Process_Interrupt_Or_Attach_Handler --
10387 -----------------------------------------
10388
10389 procedure Process_Interrupt_Or_Attach_Handler is
10390 Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
10391 Prot_Typ : constant Entity_Id := Scope (Handler);
10392
10393 begin
10394 -- A pragma that applies to a Ghost entity becomes Ghost for the
10395 -- purposes of legality checks and removal of ignored Ghost code.
10396
10397 Mark_Ghost_Pragma (N, Handler);
10398 Set_Is_Interrupt_Handler (Handler);
10399
10400 pragma Assert (Ekind (Prot_Typ) = E_Protected_Type);
10401
10402 Record_Rep_Item (Prot_Typ, N);
10403
10404 -- Chain the pragma on the contract for completeness
10405
10406 Add_Contract_Item (N, Handler);
10407 end Process_Interrupt_Or_Attach_Handler;
10408
10409 --------------------------------------------------
10410 -- Process_Restrictions_Or_Restriction_Warnings --
10411 --------------------------------------------------
10412
10413 -- Note: some of the simple identifier cases were handled in par-prag,
10414 -- but it is harmless (and more straightforward) to simply handle all
10415 -- cases here, even if it means we repeat a bit of work in some cases.
10416
10417 procedure Process_Restrictions_Or_Restriction_Warnings
10418 (Warn : Boolean)
10419 is
10420 Arg : Node_Id;
10421 R_Id : Restriction_Id;
10422 Id : Name_Id;
10423 Expr : Node_Id;
10424 Val : Uint;
10425
10426 begin
10427 -- Ignore all Restrictions pragmas in CodePeer mode
10428
10429 if CodePeer_Mode then
10430 return;
10431 end if;
10432
10433 Check_Ada_83_Warning;
10434 Check_At_Least_N_Arguments (1);
10435 Check_Valid_Configuration_Pragma;
10436
10437 Arg := Arg1;
10438 while Present (Arg) loop
10439 Id := Chars (Arg);
10440 Expr := Get_Pragma_Arg (Arg);
10441
10442 -- Case of no restriction identifier present
10443
10444 if Id = No_Name then
10445 if Nkind (Expr) /= N_Identifier then
10446 Error_Pragma_Arg
10447 ("invalid form for restriction", Arg);
10448 end if;
10449
10450 R_Id :=
10451 Get_Restriction_Id
10452 (Process_Restriction_Synonyms (Expr));
10453
10454 if R_Id not in All_Boolean_Restrictions then
10455 Error_Msg_Name_1 := Pname;
10456 Error_Msg_N
10457 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
10458
10459 -- Check for possible misspelling
10460
10461 for J in Restriction_Id loop
10462 declare
10463 Rnm : constant String := Restriction_Id'Image (J);
10464
10465 begin
10466 Name_Buffer (1 .. Rnm'Length) := Rnm;
10467 Name_Len := Rnm'Length;
10468 Set_Casing (All_Lower_Case);
10469
10470 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
10471 Set_Casing
10472 (Identifier_Casing
10473 (Source_Index (Current_Sem_Unit)));
10474 Error_Msg_String (1 .. Rnm'Length) :=
10475 Name_Buffer (1 .. Name_Len);
10476 Error_Msg_Strlen := Rnm'Length;
10477 Error_Msg_N -- CODEFIX
10478 ("\possible misspelling of ""~""",
10479 Get_Pragma_Arg (Arg));
10480 exit;
10481 end if;
10482 end;
10483 end loop;
10484
10485 raise Pragma_Exit;
10486 end if;
10487
10488 if Implementation_Restriction (R_Id) then
10489 Check_Restriction (No_Implementation_Restrictions, Arg);
10490 end if;
10491
10492 -- Special processing for No_Elaboration_Code restriction
10493
10494 if R_Id = No_Elaboration_Code then
10495
10496 -- Restriction is only recognized within a configuration
10497 -- pragma file, or within a unit of the main extended
10498 -- program. Note: the test for Main_Unit is needed to
10499 -- properly include the case of configuration pragma files.
10500
10501 if not (Current_Sem_Unit = Main_Unit
10502 or else In_Extended_Main_Source_Unit (N))
10503 then
10504 return;
10505
10506 -- Don't allow in a subunit unless already specified in
10507 -- body or spec.
10508
10509 elsif Nkind (Parent (N)) = N_Compilation_Unit
10510 and then Nkind (Unit (Parent (N))) = N_Subunit
10511 and then not Restriction_Active (No_Elaboration_Code)
10512 then
10513 Error_Msg_N
10514 ("invalid specification of ""No_Elaboration_Code""",
10515 N);
10516 Error_Msg_N
10517 ("\restriction cannot be specified in a subunit", N);
10518 Error_Msg_N
10519 ("\unless also specified in body or spec", N);
10520 return;
10521
10522 -- If we accept a No_Elaboration_Code restriction, then it
10523 -- needs to be added to the configuration restriction set so
10524 -- that we get proper application to other units in the main
10525 -- extended source as required.
10526
10527 else
10528 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
10529 end if;
10530
10531 -- Special processing for No_Tasking restriction placed in
10532 -- a configuration pragmas file.
10533
10534 elsif R_Id = No_Tasking and then No (Cunit (Main_Unit)) then
10535 Set_Global_No_Tasking;
10536 end if;
10537
10538 Set_Restriction (R_Id, N, Warn);
10539
10540 if R_Id = No_Dynamic_CPU_Assignment
10541 or else R_Id = No_Tasks_Unassigned_To_CPU
10542 then
10543 -- These imply No_Dependence =>
10544 -- "System.Multiprocessors.Dispatching_Domains".
10545 -- This is not strictly what the AI says, but it eliminates
10546 -- the need for run-time checks, which are undesirable in
10547 -- this context.
10548
10549 Set_Restriction_No_Dependence
10550 (Sel_Comp
10551 (Sel_Comp ("system", "multiprocessors", Loc),
10552 "dispatching_domains"),
10553 Warn);
10554 end if;
10555
10556 if R_Id = No_Tasks_Unassigned_To_CPU then
10557 -- Likewise, imply No_Dynamic_CPU_Assignment
10558
10559 Set_Restriction (No_Dynamic_CPU_Assignment, N, Warn);
10560 end if;
10561
10562 -- Check for obsolescent restrictions in Ada 2005 mode
10563
10564 if not Warn
10565 and then Ada_Version >= Ada_2005
10566 and then (R_Id = No_Asynchronous_Control
10567 or else
10568 R_Id = No_Unchecked_Deallocation
10569 or else
10570 R_Id = No_Unchecked_Conversion)
10571 then
10572 Check_Restriction (No_Obsolescent_Features, N);
10573 end if;
10574
10575 -- A very special case that must be processed here: pragma
10576 -- Restrictions (No_Exceptions) turns off all run-time
10577 -- checking. This is a bit dubious in terms of the formal
10578 -- language definition, but it is what is intended by RM
10579 -- H.4(12). Restriction_Warnings never affects generated code
10580 -- so this is done only in the real restriction case.
10581
10582 -- Atomic_Synchronization is not a real check, so it is not
10583 -- affected by this processing).
10584
10585 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
10586 -- run-time checks in CodePeer and GNATprove modes: we want to
10587 -- generate checks for analysis purposes, as set respectively
10588 -- by -gnatC and -gnatd.F
10589
10590 if not Warn
10591 and then not (CodePeer_Mode or GNATprove_Mode)
10592 and then R_Id = No_Exceptions
10593 then
10594 for J in Scope_Suppress.Suppress'Range loop
10595 if J /= Atomic_Synchronization then
10596 Scope_Suppress.Suppress (J) := True;
10597 end if;
10598 end loop;
10599 end if;
10600
10601 -- Case of No_Dependence => unit-name. Note that the parser
10602 -- already made the necessary entry in the No_Dependence table.
10603
10604 elsif Id = Name_No_Dependence then
10605 if not OK_No_Dependence_Unit_Name (Expr) then
10606 raise Pragma_Exit;
10607 end if;
10608
10609 -- Case of No_Specification_Of_Aspect => aspect-identifier
10610
10611 elsif Id = Name_No_Specification_Of_Aspect then
10612 declare
10613 A_Id : Aspect_Id;
10614
10615 begin
10616 if Nkind (Expr) /= N_Identifier then
10617 A_Id := No_Aspect;
10618 else
10619 A_Id := Get_Aspect_Id (Chars (Expr));
10620 end if;
10621
10622 if A_Id = No_Aspect then
10623 Error_Pragma_Arg ("invalid restriction name", Arg);
10624 else
10625 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
10626 end if;
10627 end;
10628
10629 -- Case of No_Use_Of_Attribute => attribute-identifier
10630
10631 elsif Id = Name_No_Use_Of_Attribute then
10632 if Nkind (Expr) /= N_Identifier
10633 or else not Is_Attribute_Name (Chars (Expr))
10634 then
10635 Error_Msg_N ("unknown attribute name??", Expr);
10636
10637 else
10638 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
10639 end if;
10640
10641 -- Case of No_Use_Of_Entity => fully-qualified-name
10642
10643 elsif Id = Name_No_Use_Of_Entity then
10644
10645 -- Restriction is only recognized within a configuration
10646 -- pragma file, or within a unit of the main extended
10647 -- program. Note: the test for Main_Unit is needed to
10648 -- properly include the case of configuration pragma files.
10649
10650 if Current_Sem_Unit = Main_Unit
10651 or else In_Extended_Main_Source_Unit (N)
10652 then
10653 if not OK_No_Dependence_Unit_Name (Expr) then
10654 Error_Msg_N ("wrong form for entity name", Expr);
10655 else
10656 Set_Restriction_No_Use_Of_Entity
10657 (Expr, Warn, No_Profile);
10658 end if;
10659 end if;
10660
10661 -- Case of No_Use_Of_Pragma => pragma-identifier
10662
10663 elsif Id = Name_No_Use_Of_Pragma then
10664 if Nkind (Expr) /= N_Identifier
10665 or else not Is_Pragma_Name (Chars (Expr))
10666 then
10667 Error_Msg_N ("unknown pragma name??", Expr);
10668 else
10669 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
10670 end if;
10671
10672 -- All other cases of restriction identifier present
10673
10674 else
10675 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
10676 Analyze_And_Resolve (Expr, Any_Integer);
10677
10678 if R_Id not in All_Parameter_Restrictions then
10679 Error_Pragma_Arg
10680 ("invalid restriction parameter identifier", Arg);
10681
10682 elsif not Is_OK_Static_Expression (Expr) then
10683 Flag_Non_Static_Expr
10684 ("value must be static expression!", Expr);
10685 raise Pragma_Exit;
10686
10687 elsif not Is_Integer_Type (Etype (Expr))
10688 or else Expr_Value (Expr) < 0
10689 then
10690 Error_Pragma_Arg
10691 ("value must be non-negative integer", Arg);
10692 end if;
10693
10694 -- Restriction pragma is active
10695
10696 Val := Expr_Value (Expr);
10697
10698 if not UI_Is_In_Int_Range (Val) then
10699 Error_Pragma_Arg
10700 ("pragma ignored, value too large??", Arg);
10701 end if;
10702
10703 Set_Restriction (R_Id, N, Warn, Integer (UI_To_Int (Val)));
10704 end if;
10705
10706 Next (Arg);
10707 end loop;
10708 end Process_Restrictions_Or_Restriction_Warnings;
10709
10710 ---------------------------------
10711 -- Process_Suppress_Unsuppress --
10712 ---------------------------------
10713
10714 -- Note: this procedure makes entries in the check suppress data
10715 -- structures managed by Sem. See spec of package Sem for full
10716 -- details on how we handle recording of check suppression.
10717
10718 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
10719 C : Check_Id;
10720 E : Entity_Id;
10721 E_Id : Node_Id;
10722
10723 In_Package_Spec : constant Boolean :=
10724 Is_Package_Or_Generic_Package (Current_Scope)
10725 and then not In_Package_Body (Current_Scope);
10726
10727 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
10728 -- Used to suppress a single check on the given entity
10729
10730 --------------------------------
10731 -- Suppress_Unsuppress_Echeck --
10732 --------------------------------
10733
10734 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
10735 begin
10736 -- Check for error of trying to set atomic synchronization for
10737 -- a non-atomic variable.
10738
10739 if C = Atomic_Synchronization
10740 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
10741 then
10742 Error_Msg_N
10743 ("pragma & requires atomic type or variable",
10744 Pragma_Identifier (Original_Node (N)));
10745 end if;
10746
10747 Set_Checks_May_Be_Suppressed (E);
10748
10749 if In_Package_Spec then
10750 Push_Global_Suppress_Stack_Entry
10751 (Entity => E,
10752 Check => C,
10753 Suppress => Suppress_Case);
10754 else
10755 Push_Local_Suppress_Stack_Entry
10756 (Entity => E,
10757 Check => C,
10758 Suppress => Suppress_Case);
10759 end if;
10760
10761 -- If this is a first subtype, and the base type is distinct,
10762 -- then also set the suppress flags on the base type.
10763
10764 if Is_First_Subtype (E) and then Etype (E) /= E then
10765 Suppress_Unsuppress_Echeck (Etype (E), C);
10766 end if;
10767 end Suppress_Unsuppress_Echeck;
10768
10769 -- Start of processing for Process_Suppress_Unsuppress
10770
10771 begin
10772 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
10773 -- on user code: we want to generate checks for analysis purposes, as
10774 -- set respectively by -gnatC and -gnatd.F
10775
10776 if Comes_From_Source (N)
10777 and then (CodePeer_Mode or GNATprove_Mode)
10778 then
10779 return;
10780 end if;
10781
10782 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
10783 -- declarative part or a package spec (RM 11.5(5)).
10784
10785 if not Is_Configuration_Pragma then
10786 Check_Is_In_Decl_Part_Or_Package_Spec;
10787 end if;
10788
10789 Check_At_Least_N_Arguments (1);
10790 Check_At_Most_N_Arguments (2);
10791 Check_No_Identifier (Arg1);
10792 Check_Arg_Is_Identifier (Arg1);
10793
10794 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
10795
10796 if C = No_Check_Id then
10797 Error_Pragma_Arg
10798 ("argument of pragma% is not valid check name", Arg1);
10799 end if;
10800
10801 -- Warn that suppress of Elaboration_Check has no effect in SPARK
10802
10803 if C = Elaboration_Check and then SPARK_Mode = On then
10804 Error_Pragma_Arg
10805 ("Suppress of Elaboration_Check ignored in SPARK??",
10806 "\elaboration checking rules are statically enforced "
10807 & "(SPARK RM 7.7)", Arg1);
10808 end if;
10809
10810 -- One-argument case
10811
10812 if Arg_Count = 1 then
10813
10814 -- Make an entry in the local scope suppress table. This is the
10815 -- table that directly shows the current value of the scope
10816 -- suppress check for any check id value.
10817
10818 if C = All_Checks then
10819
10820 -- For All_Checks, we set all specific predefined checks with
10821 -- the exception of Elaboration_Check, which is handled
10822 -- specially because of not wanting All_Checks to have the
10823 -- effect of deactivating static elaboration order processing.
10824 -- Atomic_Synchronization is also not affected, since this is
10825 -- not a real check.
10826
10827 for J in Scope_Suppress.Suppress'Range loop
10828 if J /= Elaboration_Check
10829 and then
10830 J /= Atomic_Synchronization
10831 then
10832 Scope_Suppress.Suppress (J) := Suppress_Case;
10833 end if;
10834 end loop;
10835
10836 -- If not All_Checks, and predefined check, then set appropriate
10837 -- scope entry. Note that we will set Elaboration_Check if this
10838 -- is explicitly specified. Atomic_Synchronization is allowed
10839 -- only if internally generated and entity is atomic.
10840
10841 elsif C in Predefined_Check_Id
10842 and then (not Comes_From_Source (N)
10843 or else C /= Atomic_Synchronization)
10844 then
10845 Scope_Suppress.Suppress (C) := Suppress_Case;
10846 end if;
10847
10848 -- Also make an entry in the Local_Entity_Suppress table
10849
10850 Push_Local_Suppress_Stack_Entry
10851 (Entity => Empty,
10852 Check => C,
10853 Suppress => Suppress_Case);
10854
10855 -- Case of two arguments present, where the check is suppressed for
10856 -- a specified entity (given as the second argument of the pragma)
10857
10858 else
10859 -- This is obsolescent in Ada 2005 mode
10860
10861 if Ada_Version >= Ada_2005 then
10862 Check_Restriction (No_Obsolescent_Features, Arg2);
10863 end if;
10864
10865 Check_Optional_Identifier (Arg2, Name_On);
10866 E_Id := Get_Pragma_Arg (Arg2);
10867 Analyze (E_Id);
10868
10869 if not Is_Entity_Name (E_Id) then
10870 Error_Pragma_Arg
10871 ("second argument of pragma% must be entity name", Arg2);
10872 end if;
10873
10874 E := Entity (E_Id);
10875
10876 if E = Any_Id then
10877 return;
10878 end if;
10879
10880 -- A pragma that applies to a Ghost entity becomes Ghost for the
10881 -- purposes of legality checks and removal of ignored Ghost code.
10882
10883 Mark_Ghost_Pragma (N, E);
10884
10885 -- Enforce RM 11.5(7) which requires that for a pragma that
10886 -- appears within a package spec, the named entity must be
10887 -- within the package spec. We allow the package name itself
10888 -- to be mentioned since that makes sense, although it is not
10889 -- strictly allowed by 11.5(7).
10890
10891 if In_Package_Spec
10892 and then E /= Current_Scope
10893 and then Scope (E) /= Current_Scope
10894 then
10895 Error_Pragma_Arg
10896 ("entity in pragma% is not in package spec (RM 11.5(7))",
10897 Arg2);
10898 end if;
10899
10900 -- Loop through homonyms. As noted below, in the case of a package
10901 -- spec, only homonyms within the package spec are considered.
10902
10903 loop
10904 Suppress_Unsuppress_Echeck (E, C);
10905
10906 if Is_Generic_Instance (E)
10907 and then Is_Subprogram (E)
10908 and then Present (Alias (E))
10909 then
10910 Suppress_Unsuppress_Echeck (Alias (E), C);
10911 end if;
10912
10913 -- Move to next homonym if not aspect spec case
10914
10915 exit when From_Aspect_Specification (N);
10916 E := Homonym (E);
10917 exit when No (E);
10918
10919 -- If we are within a package specification, the pragma only
10920 -- applies to homonyms in the same scope.
10921
10922 exit when In_Package_Spec
10923 and then Scope (E) /= Current_Scope;
10924 end loop;
10925 end if;
10926 end Process_Suppress_Unsuppress;
10927
10928 -------------------------------
10929 -- Record_Independence_Check --
10930 -------------------------------
10931
10932 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
10933 pragma Unreferenced (N, E);
10934 begin
10935 -- For GCC back ends the validation is done a priori
10936 -- ??? This code is dead, might be useful in the future
10937
10938 -- if not AAMP_On_Target then
10939 -- return;
10940 -- end if;
10941
10942 -- Independence_Checks.Append ((N, E));
10943
10944 return;
10945 end Record_Independence_Check;
10946
10947 ------------------
10948 -- Set_Exported --
10949 ------------------
10950
10951 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
10952 begin
10953 if Is_Imported (E) then
10954 Error_Pragma_Arg
10955 ("cannot export entity& that was previously imported", Arg);
10956
10957 elsif Present (Address_Clause (E))
10958 and then not Relaxed_RM_Semantics
10959 then
10960 Error_Pragma_Arg
10961 ("cannot export entity& that has an address clause", Arg);
10962 end if;
10963
10964 Set_Is_Exported (E);
10965
10966 -- Generate a reference for entity explicitly, because the
10967 -- identifier may be overloaded and name resolution will not
10968 -- generate one.
10969
10970 Generate_Reference (E, Arg);
10971
10972 -- Deal with exporting non-library level entity
10973
10974 if not Is_Library_Level_Entity (E) then
10975
10976 -- Not allowed at all for subprograms
10977
10978 if Is_Subprogram (E) then
10979 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
10980
10981 -- Otherwise set public and statically allocated
10982
10983 else
10984 Set_Is_Public (E);
10985 Set_Is_Statically_Allocated (E);
10986
10987 -- Warn if the corresponding W flag is set
10988
10989 if Warn_On_Export_Import
10990
10991 -- Only do this for something that was in the source. Not
10992 -- clear if this can be False now (there used for sure to be
10993 -- cases on some systems where it was False), but anyway the
10994 -- test is harmless if not needed, so it is retained.
10995
10996 and then Comes_From_Source (Arg)
10997 then
10998 Error_Msg_NE
10999 ("?x?& has been made static as a result of Export",
11000 Arg, E);
11001 Error_Msg_N
11002 ("\?x?this usage is non-standard and non-portable",
11003 Arg);
11004 end if;
11005 end if;
11006 end if;
11007
11008 if Warn_On_Export_Import and then Is_Type (E) then
11009 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
11010 end if;
11011
11012 if Warn_On_Export_Import and Inside_A_Generic then
11013 Error_Msg_NE
11014 ("all instances of& will have the same external name?x?",
11015 Arg, E);
11016 end if;
11017 end Set_Exported;
11018
11019 ----------------------------------------------
11020 -- Set_Extended_Import_Export_External_Name --
11021 ----------------------------------------------
11022
11023 procedure Set_Extended_Import_Export_External_Name
11024 (Internal_Ent : Entity_Id;
11025 Arg_External : Node_Id)
11026 is
11027 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
11028 New_Name : Node_Id;
11029
11030 begin
11031 if No (Arg_External) then
11032 return;
11033 end if;
11034
11035 Check_Arg_Is_External_Name (Arg_External);
11036
11037 if Nkind (Arg_External) = N_String_Literal then
11038 if String_Length (Strval (Arg_External)) = 0 then
11039 return;
11040 else
11041 New_Name := Adjust_External_Name_Case (Arg_External);
11042 end if;
11043
11044 elsif Nkind (Arg_External) = N_Identifier then
11045 New_Name := Get_Default_External_Name (Arg_External);
11046
11047 -- Check_Arg_Is_External_Name should let through only identifiers and
11048 -- string literals or static string expressions (which are folded to
11049 -- string literals).
11050
11051 else
11052 raise Program_Error;
11053 end if;
11054
11055 -- If we already have an external name set (by a prior normal Import
11056 -- or Export pragma), then the external names must match
11057
11058 if Present (Interface_Name (Internal_Ent)) then
11059
11060 -- Ignore mismatching names in CodePeer mode, to support some
11061 -- old compilers which would export the same procedure under
11062 -- different names, e.g:
11063 -- procedure P;
11064 -- pragma Export_Procedure (P, "a");
11065 -- pragma Export_Procedure (P, "b");
11066
11067 if CodePeer_Mode then
11068 return;
11069 end if;
11070
11071 Check_Matching_Internal_Names : declare
11072 S1 : constant String_Id := Strval (Old_Name);
11073 S2 : constant String_Id := Strval (New_Name);
11074
11075 procedure Mismatch;
11076 pragma No_Return (Mismatch);
11077 -- Called if names do not match
11078
11079 --------------
11080 -- Mismatch --
11081 --------------
11082
11083 procedure Mismatch is
11084 begin
11085 Error_Msg_Sloc := Sloc (Old_Name);
11086 Error_Pragma_Arg
11087 ("external name does not match that given #",
11088 Arg_External);
11089 end Mismatch;
11090
11091 -- Start of processing for Check_Matching_Internal_Names
11092
11093 begin
11094 if String_Length (S1) /= String_Length (S2) then
11095 Mismatch;
11096
11097 else
11098 for J in 1 .. String_Length (S1) loop
11099 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
11100 Mismatch;
11101 end if;
11102 end loop;
11103 end if;
11104 end Check_Matching_Internal_Names;
11105
11106 -- Otherwise set the given name
11107
11108 else
11109 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
11110 Check_Duplicated_Export_Name (New_Name);
11111 end if;
11112 end Set_Extended_Import_Export_External_Name;
11113
11114 ------------------
11115 -- Set_Imported --
11116 ------------------
11117
11118 procedure Set_Imported (E : Entity_Id) is
11119 begin
11120 -- Error message if already imported or exported
11121
11122 if Is_Exported (E) or else Is_Imported (E) then
11123
11124 -- Error if being set Exported twice
11125
11126 if Is_Exported (E) then
11127 Error_Msg_NE ("entity& was previously exported", N, E);
11128
11129 -- Ignore error in CodePeer mode where we treat all imported
11130 -- subprograms as unknown.
11131
11132 elsif CodePeer_Mode then
11133 goto OK;
11134
11135 -- OK if Import/Interface case
11136
11137 elsif Import_Interface_Present (N) then
11138 goto OK;
11139
11140 -- Error if being set Imported twice
11141
11142 else
11143 Error_Msg_NE ("entity& was previously imported", N, E);
11144 end if;
11145
11146 Error_Msg_Name_1 := Pname;
11147 Error_Msg_N
11148 ("\(pragma% applies to all previous entities)", N);
11149
11150 Error_Msg_Sloc := Sloc (E);
11151 Error_Msg_NE ("\import not allowed for& declared#", N, E);
11152
11153 -- Here if not previously imported or exported, OK to import
11154
11155 else
11156 Set_Is_Imported (E);
11157
11158 -- For subprogram, set Import_Pragma field
11159
11160 if Is_Subprogram (E) then
11161 Set_Import_Pragma (E, N);
11162 end if;
11163
11164 -- If the entity is an object that is not at the library level,
11165 -- then it is statically allocated. We do not worry about objects
11166 -- with address clauses in this context since they are not really
11167 -- imported in the linker sense.
11168
11169 if Is_Object (E)
11170 and then not Is_Library_Level_Entity (E)
11171 and then No (Address_Clause (E))
11172 then
11173 Set_Is_Statically_Allocated (E);
11174 end if;
11175 end if;
11176
11177 <<OK>> null;
11178 end Set_Imported;
11179
11180 -------------------------
11181 -- Set_Mechanism_Value --
11182 -------------------------
11183
11184 -- Note: the mechanism name has not been analyzed (and cannot indeed be
11185 -- analyzed, since it is semantic nonsense), so we get it in the exact
11186 -- form created by the parser.
11187
11188 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
11189 procedure Bad_Mechanism;
11190 pragma No_Return (Bad_Mechanism);
11191 -- Signal bad mechanism name
11192
11193 -------------------
11194 -- Bad_Mechanism --
11195 -------------------
11196
11197 procedure Bad_Mechanism is
11198 begin
11199 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
11200 end Bad_Mechanism;
11201
11202 -- Start of processing for Set_Mechanism_Value
11203
11204 begin
11205 if Mechanism (Ent) /= Default_Mechanism then
11206 Error_Msg_NE
11207 ("mechanism for & has already been set", Mech_Name, Ent);
11208 end if;
11209
11210 -- MECHANISM_NAME ::= value | reference
11211
11212 if Nkind (Mech_Name) = N_Identifier then
11213 if Chars (Mech_Name) = Name_Value then
11214 Set_Mechanism (Ent, By_Copy);
11215 return;
11216
11217 elsif Chars (Mech_Name) = Name_Reference then
11218 Set_Mechanism (Ent, By_Reference);
11219 return;
11220
11221 elsif Chars (Mech_Name) = Name_Copy then
11222 Error_Pragma_Arg
11223 ("bad mechanism name, Value assumed", Mech_Name);
11224
11225 else
11226 Bad_Mechanism;
11227 end if;
11228
11229 else
11230 Bad_Mechanism;
11231 end if;
11232 end Set_Mechanism_Value;
11233
11234 --------------------------
11235 -- Set_Rational_Profile --
11236 --------------------------
11237
11238 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
11239 -- extension to the semantics of renaming declarations.
11240
11241 procedure Set_Rational_Profile is
11242 begin
11243 Implicit_Packing := True;
11244 Overriding_Renamings := True;
11245 Use_VADS_Size := True;
11246 end Set_Rational_Profile;
11247
11248 ---------------------------
11249 -- Set_Ravenscar_Profile --
11250 ---------------------------
11251
11252 -- The tasks to be done here are
11253
11254 -- Set required policies
11255
11256 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11257 -- (For Ravenscar, Jorvik, and GNAT_Extended_Ravenscar profiles)
11258 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11259 -- (For GNAT_Ravenscar_EDF profile)
11260 -- pragma Locking_Policy (Ceiling_Locking)
11261
11262 -- Set Detect_Blocking mode
11263
11264 -- Set required restrictions (see System.Rident for detailed list)
11265
11266 -- Set the No_Dependence rules
11267 -- No_Dependence => Ada.Asynchronous_Task_Control
11268 -- No_Dependence => Ada.Calendar
11269 -- No_Dependence => Ada.Execution_Time.Group_Budget
11270 -- No_Dependence => Ada.Execution_Time.Timers
11271 -- No_Dependence => Ada.Task_Attributes
11272 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11273
11274 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is
11275 procedure Set_Error_Msg_To_Profile_Name;
11276 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
11277 -- profile.
11278
11279 -----------------------------------
11280 -- Set_Error_Msg_To_Profile_Name --
11281 -----------------------------------
11282
11283 procedure Set_Error_Msg_To_Profile_Name is
11284 Prof_Nam : constant Node_Id :=
11285 Get_Pragma_Arg
11286 (First (Pragma_Argument_Associations (N)));
11287
11288 begin
11289 Get_Name_String (Chars (Prof_Nam));
11290 Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam));
11291 Error_Msg_Strlen := Name_Len;
11292 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
11293 end Set_Error_Msg_To_Profile_Name;
11294
11295 Profile_Dispatching_Policy : Character;
11296
11297 -- Start of processing for Set_Ravenscar_Profile
11298
11299 begin
11300 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11301
11302 if Profile = GNAT_Ravenscar_EDF then
11303 Profile_Dispatching_Policy := 'E';
11304
11305 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11306
11307 else
11308 Profile_Dispatching_Policy := 'F';
11309 end if;
11310
11311 if Task_Dispatching_Policy /= ' '
11312 and then Task_Dispatching_Policy /= Profile_Dispatching_Policy
11313 then
11314 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11315 Set_Error_Msg_To_Profile_Name;
11316 Error_Pragma ("Profile (~) incompatible with policy#");
11317
11318 -- Set the FIFO_Within_Priorities policy, but always preserve
11319 -- System_Location since we like the error message with the run time
11320 -- name.
11321
11322 else
11323 Task_Dispatching_Policy := Profile_Dispatching_Policy;
11324
11325 if Task_Dispatching_Policy_Sloc /= System_Location then
11326 Task_Dispatching_Policy_Sloc := Loc;
11327 end if;
11328 end if;
11329
11330 -- pragma Locking_Policy (Ceiling_Locking)
11331
11332 if Locking_Policy /= ' '
11333 and then Locking_Policy /= 'C'
11334 then
11335 Error_Msg_Sloc := Locking_Policy_Sloc;
11336 Set_Error_Msg_To_Profile_Name;
11337 Error_Pragma ("Profile (~) incompatible with policy#");
11338
11339 -- Set the Ceiling_Locking policy, but preserve System_Location since
11340 -- we like the error message with the run time name.
11341
11342 else
11343 Locking_Policy := 'C';
11344
11345 if Locking_Policy_Sloc /= System_Location then
11346 Locking_Policy_Sloc := Loc;
11347 end if;
11348 end if;
11349
11350 -- pragma Detect_Blocking
11351
11352 Detect_Blocking := True;
11353
11354 -- Set the corresponding restrictions
11355
11356 Set_Profile_Restrictions
11357 (Profile, N, Warn => Treat_Restrictions_As_Warnings);
11358
11359 -- Set the No_Dependence restrictions
11360
11361 -- The following No_Dependence restrictions:
11362 -- No_Dependence => Ada.Asynchronous_Task_Control
11363 -- No_Dependence => Ada.Calendar
11364 -- No_Dependence => Ada.Task_Attributes
11365 -- are already set by previous call to Set_Profile_Restrictions.
11366 -- Really???
11367
11368 -- Set the following restrictions which were added to Ada 2005:
11369 -- No_Dependence => Ada.Execution_Time.Group_Budget
11370 -- No_Dependence => Ada.Execution_Time.Timers
11371
11372 if Ada_Version >= Ada_2005 then
11373 declare
11374 Execution_Time : constant Node_Id :=
11375 Sel_Comp ("ada", "execution_time", Loc);
11376 Group_Budgets : constant Node_Id :=
11377 Sel_Comp (Execution_Time, "group_budgets");
11378 Timers : constant Node_Id :=
11379 Sel_Comp (Execution_Time, "timers");
11380 begin
11381 Set_Restriction_No_Dependence
11382 (Unit => Group_Budgets,
11383 Warn => Treat_Restrictions_As_Warnings,
11384 Profile => Ravenscar);
11385 Set_Restriction_No_Dependence
11386 (Unit => Timers,
11387 Warn => Treat_Restrictions_As_Warnings,
11388 Profile => Ravenscar);
11389 end;
11390 end if;
11391
11392 -- Set the following restriction which was added to Ada 2012 (see
11393 -- AI05-0171):
11394 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11395
11396 if Ada_Version >= Ada_2012 then
11397 Set_Restriction_No_Dependence
11398 (Sel_Comp
11399 (Sel_Comp ("system", "multiprocessors", Loc),
11400 "dispatching_domains"),
11401 Warn => Treat_Restrictions_As_Warnings,
11402 Profile => Ravenscar);
11403
11404 -- Set the following restriction which was added to Ada 2020,
11405 -- but as a binding interpretation:
11406 -- No_Dependence => Ada.Synchronous_Barriers
11407 -- for Ravenscar (and therefore for Ravenscar variants) but not
11408 -- for Jorvik. The unit Ada.Synchronous_Barriers was introduced
11409 -- in Ada2012 (AI05-0174).
11410
11411 if Profile /= Jorvik then
11412 Set_Restriction_No_Dependence
11413 (Sel_Comp ("ada", "synchronous_barriers", Loc),
11414 Warn => Treat_Restrictions_As_Warnings,
11415 Profile => Ravenscar);
11416 end if;
11417 end if;
11418
11419 end Set_Ravenscar_Profile;
11420
11421 -- Start of processing for Analyze_Pragma
11422
11423 begin
11424 -- The following code is a defense against recursion. Not clear that
11425 -- this can happen legitimately, but perhaps some error situations can
11426 -- cause it, and we did see this recursion during testing.
11427
11428 if Analyzed (N) then
11429 return;
11430 else
11431 Set_Analyzed (N);
11432 end if;
11433
11434 Check_Restriction_No_Use_Of_Pragma (N);
11435
11436 if Get_Aspect_Id (Chars (Pragma_Identifier (N))) /= No_Aspect then
11437 -- 6.1/3 No_Specification_of_Aspect: Identifies an aspect for which
11438 -- no aspect_specification, attribute_definition_clause, or pragma
11439 -- is given.
11440 Check_Restriction_No_Specification_Of_Aspect (N);
11441 end if;
11442
11443 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
11444 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
11445
11446 if Should_Ignore_Pragma_Sem (N)
11447 or else (Prag_Id = Pragma_Default_Scalar_Storage_Order
11448 and then Ignore_Rep_Clauses)
11449 then
11450 return;
11451 end if;
11452
11453 -- Deal with unrecognized pragma
11454
11455 if not Is_Pragma_Name (Pname) then
11456 if Warn_On_Unrecognized_Pragma then
11457 Error_Msg_Name_1 := Pname;
11458 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
11459
11460 for PN in First_Pragma_Name .. Last_Pragma_Name loop
11461 if Is_Bad_Spelling_Of (Pname, PN) then
11462 Error_Msg_Name_1 := PN;
11463 Error_Msg_N -- CODEFIX
11464 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
11465 exit;
11466 end if;
11467 end loop;
11468 end if;
11469
11470 return;
11471 end if;
11472
11473 -- Here to start processing for recognized pragma
11474
11475 Pname := Original_Aspect_Pragma_Name (N);
11476
11477 -- Capture setting of Opt.Uneval_Old
11478
11479 case Opt.Uneval_Old is
11480 when 'A' =>
11481 Set_Uneval_Old_Accept (N);
11482
11483 when 'E' =>
11484 null;
11485
11486 when 'W' =>
11487 Set_Uneval_Old_Warn (N);
11488
11489 when others =>
11490 raise Program_Error;
11491 end case;
11492
11493 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
11494 -- is already set, indicating that we have already checked the policy
11495 -- at the right point. This happens for example in the case of a pragma
11496 -- that is derived from an Aspect.
11497
11498 if Is_Ignored (N) or else Is_Checked (N) then
11499 null;
11500
11501 -- For a pragma that is a rewriting of another pragma, copy the
11502 -- Is_Checked/Is_Ignored status from the rewritten pragma.
11503
11504 elsif Is_Rewrite_Substitution (N)
11505 and then Nkind (Original_Node (N)) = N_Pragma
11506 then
11507 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
11508 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
11509
11510 -- Otherwise query the applicable policy at this point
11511
11512 else
11513 Check_Applicable_Policy (N);
11514
11515 -- If pragma is disabled, rewrite as NULL and skip analysis
11516
11517 if Is_Disabled (N) then
11518 Rewrite (N, Make_Null_Statement (Loc));
11519 Analyze (N);
11520 raise Pragma_Exit;
11521 end if;
11522 end if;
11523
11524 -- Preset arguments
11525
11526 Arg_Count := 0;
11527 Arg1 := Empty;
11528 Arg2 := Empty;
11529 Arg3 := Empty;
11530 Arg4 := Empty;
11531 Arg5 := Empty;
11532
11533 if Present (Pragma_Argument_Associations (N)) then
11534 Arg_Count := List_Length (Pragma_Argument_Associations (N));
11535 Arg1 := First (Pragma_Argument_Associations (N));
11536
11537 if Present (Arg1) then
11538 Arg2 := Next (Arg1);
11539
11540 if Present (Arg2) then
11541 Arg3 := Next (Arg2);
11542
11543 if Present (Arg3) then
11544 Arg4 := Next (Arg3);
11545
11546 if Present (Arg4) then
11547 Arg5 := Next (Arg4);
11548 end if;
11549 end if;
11550 end if;
11551 end if;
11552 end if;
11553
11554 -- An enumeration type defines the pragmas that are supported by the
11555 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
11556 -- into the corresponding enumeration value for the following case.
11557
11558 case Prag_Id is
11559
11560 -----------------
11561 -- Abort_Defer --
11562 -----------------
11563
11564 -- pragma Abort_Defer;
11565
11566 when Pragma_Abort_Defer =>
11567 GNAT_Pragma;
11568 Check_Arg_Count (0);
11569
11570 -- The only required semantic processing is to check the
11571 -- placement. This pragma must appear at the start of the
11572 -- statement sequence of a handled sequence of statements.
11573
11574 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
11575 or else N /= First (Statements (Parent (N)))
11576 then
11577 Pragma_Misplaced;
11578 end if;
11579
11580 --------------------
11581 -- Abstract_State --
11582 --------------------
11583
11584 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
11585
11586 -- ABSTRACT_STATE_LIST ::=
11587 -- null
11588 -- | STATE_NAME_WITH_OPTIONS
11589 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
11590
11591 -- STATE_NAME_WITH_OPTIONS ::=
11592 -- STATE_NAME
11593 -- | (STATE_NAME with OPTION_LIST)
11594
11595 -- OPTION_LIST ::= OPTION {, OPTION}
11596
11597 -- OPTION ::=
11598 -- SIMPLE_OPTION
11599 -- | NAME_VALUE_OPTION
11600
11601 -- SIMPLE_OPTION ::= Ghost | Relaxed_Initialization | Synchronous
11602
11603 -- NAME_VALUE_OPTION ::=
11604 -- Part_Of => ABSTRACT_STATE
11605 -- | External [=> EXTERNAL_PROPERTY_LIST]
11606
11607 -- EXTERNAL_PROPERTY_LIST ::=
11608 -- EXTERNAL_PROPERTY
11609 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
11610
11611 -- EXTERNAL_PROPERTY ::=
11612 -- Async_Readers [=> boolean_EXPRESSION]
11613 -- | Async_Writers [=> boolean_EXPRESSION]
11614 -- | Effective_Reads [=> boolean_EXPRESSION]
11615 -- | Effective_Writes [=> boolean_EXPRESSION]
11616 -- others => boolean_EXPRESSION
11617
11618 -- STATE_NAME ::= defining_identifier
11619
11620 -- ABSTRACT_STATE ::= name
11621
11622 -- Characteristics:
11623
11624 -- * Analysis - The annotation is fully analyzed immediately upon
11625 -- elaboration as it cannot forward reference entities.
11626
11627 -- * Expansion - None.
11628
11629 -- * Template - The annotation utilizes the generic template of the
11630 -- related package declaration.
11631
11632 -- * Globals - The annotation cannot reference global entities.
11633
11634 -- * Instance - The annotation is instantiated automatically when
11635 -- the related generic package is instantiated.
11636
11637 when Pragma_Abstract_State => Abstract_State : declare
11638 Missing_Parentheses : Boolean := False;
11639 -- Flag set when a state declaration with options is not properly
11640 -- parenthesized.
11641
11642 -- Flags used to verify the consistency of states
11643
11644 Non_Null_Seen : Boolean := False;
11645 Null_Seen : Boolean := False;
11646
11647 procedure Analyze_Abstract_State
11648 (State : Node_Id;
11649 Pack_Id : Entity_Id);
11650 -- Verify the legality of a single state declaration. Create and
11651 -- decorate a state abstraction entity and introduce it into the
11652 -- visibility chain. Pack_Id denotes the entity or the related
11653 -- package where pragma Abstract_State appears.
11654
11655 procedure Malformed_State_Error (State : Node_Id);
11656 -- Emit an error concerning the illegal declaration of abstract
11657 -- state State. This routine diagnoses syntax errors that lead to
11658 -- a different parse tree. The error is issued regardless of the
11659 -- SPARK mode in effect.
11660
11661 ----------------------------
11662 -- Analyze_Abstract_State --
11663 ----------------------------
11664
11665 procedure Analyze_Abstract_State
11666 (State : Node_Id;
11667 Pack_Id : Entity_Id)
11668 is
11669 -- Flags used to verify the consistency of options
11670
11671 AR_Seen : Boolean := False;
11672 AW_Seen : Boolean := False;
11673 ER_Seen : Boolean := False;
11674 EW_Seen : Boolean := False;
11675 External_Seen : Boolean := False;
11676 Ghost_Seen : Boolean := False;
11677 Others_Seen : Boolean := False;
11678 Part_Of_Seen : Boolean := False;
11679 Relaxed_Initialization_Seen : Boolean := False;
11680 Synchronous_Seen : Boolean := False;
11681
11682 -- Flags used to store the static value of all external states'
11683 -- expressions.
11684
11685 AR_Val : Boolean := False;
11686 AW_Val : Boolean := False;
11687 ER_Val : Boolean := False;
11688 EW_Val : Boolean := False;
11689
11690 State_Id : Entity_Id := Empty;
11691 -- The entity to be generated for the current state declaration
11692
11693 procedure Analyze_External_Option (Opt : Node_Id);
11694 -- Verify the legality of option External
11695
11696 procedure Analyze_External_Property
11697 (Prop : Node_Id;
11698 Expr : Node_Id := Empty);
11699 -- Verify the legailty of a single external property. Prop
11700 -- denotes the external property. Expr is the expression used
11701 -- to set the property.
11702
11703 procedure Analyze_Part_Of_Option (Opt : Node_Id);
11704 -- Verify the legality of option Part_Of
11705
11706 procedure Check_Duplicate_Option
11707 (Opt : Node_Id;
11708 Status : in out Boolean);
11709 -- Flag Status denotes whether a particular option has been
11710 -- seen while processing a state. This routine verifies that
11711 -- Opt is not a duplicate option and sets the flag Status
11712 -- (SPARK RM 7.1.4(1)).
11713
11714 procedure Check_Duplicate_Property
11715 (Prop : Node_Id;
11716 Status : in out Boolean);
11717 -- Flag Status denotes whether a particular property has been
11718 -- seen while processing option External. This routine verifies
11719 -- that Prop is not a duplicate property and sets flag Status.
11720 -- Opt is not a duplicate property and sets the flag Status.
11721 -- (SPARK RM 7.1.4(2))
11722
11723 procedure Check_Ghost_Synchronous;
11724 -- Ensure that the abstract state is not subject to both Ghost
11725 -- and Synchronous simple options. Emit an error if this is the
11726 -- case.
11727
11728 procedure Create_Abstract_State
11729 (Nam : Name_Id;
11730 Decl : Node_Id;
11731 Loc : Source_Ptr;
11732 Is_Null : Boolean);
11733 -- Generate an abstract state entity with name Nam and enter it
11734 -- into visibility. Decl is the "declaration" of the state as
11735 -- it appears in pragma Abstract_State. Loc is the location of
11736 -- the related state "declaration". Flag Is_Null should be set
11737 -- when the associated Abstract_State pragma defines a null
11738 -- state.
11739
11740 -----------------------------
11741 -- Analyze_External_Option --
11742 -----------------------------
11743
11744 procedure Analyze_External_Option (Opt : Node_Id) is
11745 Errors : constant Nat := Serious_Errors_Detected;
11746 Prop : Node_Id;
11747 Props : Node_Id := Empty;
11748
11749 begin
11750 if Nkind (Opt) = N_Component_Association then
11751 Props := Expression (Opt);
11752 end if;
11753
11754 -- External state with properties
11755
11756 if Present (Props) then
11757
11758 -- Multiple properties appear as an aggregate
11759
11760 if Nkind (Props) = N_Aggregate then
11761
11762 -- Simple property form
11763
11764 Prop := First (Expressions (Props));
11765 while Present (Prop) loop
11766 Analyze_External_Property (Prop);
11767 Next (Prop);
11768 end loop;
11769
11770 -- Property with expression form
11771
11772 Prop := First (Component_Associations (Props));
11773 while Present (Prop) loop
11774 Analyze_External_Property
11775 (Prop => First (Choices (Prop)),
11776 Expr => Expression (Prop));
11777
11778 Next (Prop);
11779 end loop;
11780
11781 -- Single property
11782
11783 else
11784 Analyze_External_Property (Props);
11785 end if;
11786
11787 -- An external state defined without any properties defaults
11788 -- all properties to True.
11789
11790 else
11791 AR_Val := True;
11792 AW_Val := True;
11793 ER_Val := True;
11794 EW_Val := True;
11795 end if;
11796
11797 -- Once all external properties have been processed, verify
11798 -- their mutual interaction. Do not perform the check when
11799 -- at least one of the properties is illegal as this will
11800 -- produce a bogus error.
11801
11802 if Errors = Serious_Errors_Detected then
11803 Check_External_Properties
11804 (State, AR_Val, AW_Val, ER_Val, EW_Val);
11805 end if;
11806 end Analyze_External_Option;
11807
11808 -------------------------------
11809 -- Analyze_External_Property --
11810 -------------------------------
11811
11812 procedure Analyze_External_Property
11813 (Prop : Node_Id;
11814 Expr : Node_Id := Empty)
11815 is
11816 Expr_Val : Boolean;
11817
11818 begin
11819 -- Check the placement of "others" (if available)
11820
11821 if Nkind (Prop) = N_Others_Choice then
11822 if Others_Seen then
11823 SPARK_Msg_N
11824 ("only one others choice allowed in option External",
11825 Prop);
11826 else
11827 Others_Seen := True;
11828 end if;
11829
11830 elsif Others_Seen then
11831 SPARK_Msg_N
11832 ("others must be the last property in option External",
11833 Prop);
11834
11835 -- The only remaining legal options are the four predefined
11836 -- external properties.
11837
11838 elsif Nkind (Prop) = N_Identifier
11839 and then Chars (Prop) in Name_Async_Readers
11840 | Name_Async_Writers
11841 | Name_Effective_Reads
11842 | Name_Effective_Writes
11843 then
11844 null;
11845
11846 -- Otherwise the construct is not a valid property
11847
11848 else
11849 SPARK_Msg_N ("invalid external state property", Prop);
11850 return;
11851 end if;
11852
11853 -- Ensure that the expression of the external state property
11854 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
11855
11856 if Present (Expr) then
11857 Analyze_And_Resolve (Expr, Standard_Boolean);
11858
11859 if Is_OK_Static_Expression (Expr) then
11860 Expr_Val := Is_True (Expr_Value (Expr));
11861 else
11862 SPARK_Msg_N
11863 ("expression of external state property must be "
11864 & "static", Expr);
11865 return;
11866 end if;
11867
11868 -- The lack of expression defaults the property to True
11869
11870 else
11871 Expr_Val := True;
11872 end if;
11873
11874 -- Named properties
11875
11876 if Nkind (Prop) = N_Identifier then
11877 if Chars (Prop) = Name_Async_Readers then
11878 Check_Duplicate_Property (Prop, AR_Seen);
11879 AR_Val := Expr_Val;
11880
11881 elsif Chars (Prop) = Name_Async_Writers then
11882 Check_Duplicate_Property (Prop, AW_Seen);
11883 AW_Val := Expr_Val;
11884
11885 elsif Chars (Prop) = Name_Effective_Reads then
11886 Check_Duplicate_Property (Prop, ER_Seen);
11887 ER_Val := Expr_Val;
11888
11889 else
11890 Check_Duplicate_Property (Prop, EW_Seen);
11891 EW_Val := Expr_Val;
11892 end if;
11893
11894 -- The handling of property "others" must take into account
11895 -- all other named properties that have been encountered so
11896 -- far. Only those that have not been seen are affected by
11897 -- "others".
11898
11899 else
11900 if not AR_Seen then
11901 AR_Val := Expr_Val;
11902 end if;
11903
11904 if not AW_Seen then
11905 AW_Val := Expr_Val;
11906 end if;
11907
11908 if not ER_Seen then
11909 ER_Val := Expr_Val;
11910 end if;
11911
11912 if not EW_Seen then
11913 EW_Val := Expr_Val;
11914 end if;
11915 end if;
11916 end Analyze_External_Property;
11917
11918 ----------------------------
11919 -- Analyze_Part_Of_Option --
11920 ----------------------------
11921
11922 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
11923 Encap : constant Node_Id := Expression (Opt);
11924 Constits : Elist_Id;
11925 Encap_Id : Entity_Id;
11926 Legal : Boolean;
11927
11928 begin
11929 Check_Duplicate_Option (Opt, Part_Of_Seen);
11930
11931 Analyze_Part_Of
11932 (Indic => First (Choices (Opt)),
11933 Item_Id => State_Id,
11934 Encap => Encap,
11935 Encap_Id => Encap_Id,
11936 Legal => Legal);
11937
11938 -- The Part_Of indicator transforms the abstract state into
11939 -- a constituent of the encapsulating state or single
11940 -- concurrent type.
11941
11942 if Legal then
11943 pragma Assert (Present (Encap_Id));
11944 Constits := Part_Of_Constituents (Encap_Id);
11945
11946 if No (Constits) then
11947 Constits := New_Elmt_List;
11948 Set_Part_Of_Constituents (Encap_Id, Constits);
11949 end if;
11950
11951 Append_Elmt (State_Id, Constits);
11952 Set_Encapsulating_State (State_Id, Encap_Id);
11953 end if;
11954 end Analyze_Part_Of_Option;
11955
11956 ----------------------------
11957 -- Check_Duplicate_Option --
11958 ----------------------------
11959
11960 procedure Check_Duplicate_Option
11961 (Opt : Node_Id;
11962 Status : in out Boolean)
11963 is
11964 begin
11965 if Status then
11966 SPARK_Msg_N ("duplicate state option", Opt);
11967 end if;
11968
11969 Status := True;
11970 end Check_Duplicate_Option;
11971
11972 ------------------------------
11973 -- Check_Duplicate_Property --
11974 ------------------------------
11975
11976 procedure Check_Duplicate_Property
11977 (Prop : Node_Id;
11978 Status : in out Boolean)
11979 is
11980 begin
11981 if Status then
11982 SPARK_Msg_N ("duplicate external property", Prop);
11983 end if;
11984
11985 Status := True;
11986 end Check_Duplicate_Property;
11987
11988 -----------------------------
11989 -- Check_Ghost_Synchronous --
11990 -----------------------------
11991
11992 procedure Check_Ghost_Synchronous is
11993 begin
11994 -- A synchronized abstract state cannot be Ghost and vice
11995 -- versa (SPARK RM 6.9(19)).
11996
11997 if Ghost_Seen and Synchronous_Seen then
11998 SPARK_Msg_N ("synchronized state cannot be ghost", State);
11999 end if;
12000 end Check_Ghost_Synchronous;
12001
12002 ---------------------------
12003 -- Create_Abstract_State --
12004 ---------------------------
12005
12006 procedure Create_Abstract_State
12007 (Nam : Name_Id;
12008 Decl : Node_Id;
12009 Loc : Source_Ptr;
12010 Is_Null : Boolean)
12011 is
12012 begin
12013 -- The abstract state may be semi-declared when the related
12014 -- package was withed through a limited with clause. In that
12015 -- case reuse the entity to fully declare the state.
12016
12017 if Present (Decl) and then Present (Entity (Decl)) then
12018 State_Id := Entity (Decl);
12019
12020 -- Otherwise the elaboration of pragma Abstract_State
12021 -- declares the state.
12022
12023 else
12024 State_Id := Make_Defining_Identifier (Loc, Nam);
12025
12026 if Present (Decl) then
12027 Set_Entity (Decl, State_Id);
12028 end if;
12029 end if;
12030
12031 -- Null states never come from source
12032
12033 Set_Comes_From_Source (State_Id, not Is_Null);
12034 Set_Parent (State_Id, State);
12035 Set_Ekind (State_Id, E_Abstract_State);
12036 Set_Etype (State_Id, Standard_Void_Type);
12037 Set_Encapsulating_State (State_Id, Empty);
12038
12039 -- Set the SPARK mode from the current context
12040
12041 Set_SPARK_Pragma (State_Id, SPARK_Mode_Pragma);
12042 Set_SPARK_Pragma_Inherited (State_Id);
12043
12044 -- An abstract state declared within a Ghost region becomes
12045 -- Ghost (SPARK RM 6.9(2)).
12046
12047 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then
12048 Set_Is_Ghost_Entity (State_Id);
12049 end if;
12050
12051 -- Establish a link between the state declaration and the
12052 -- abstract state entity. Note that a null state remains as
12053 -- N_Null and does not carry any linkages.
12054
12055 if not Is_Null then
12056 if Present (Decl) then
12057 Set_Entity (Decl, State_Id);
12058 Set_Etype (Decl, Standard_Void_Type);
12059 end if;
12060
12061 -- Every non-null state must be defined, nameable and
12062 -- resolvable.
12063
12064 Push_Scope (Pack_Id);
12065 Generate_Definition (State_Id);
12066 Enter_Name (State_Id);
12067 Pop_Scope;
12068 end if;
12069 end Create_Abstract_State;
12070
12071 -- Local variables
12072
12073 Opt : Node_Id;
12074 Opt_Nam : Node_Id;
12075
12076 -- Start of processing for Analyze_Abstract_State
12077
12078 begin
12079 -- A package with a null abstract state is not allowed to
12080 -- declare additional states.
12081
12082 if Null_Seen then
12083 SPARK_Msg_NE
12084 ("package & has null abstract state", State, Pack_Id);
12085
12086 -- Null states appear as internally generated entities
12087
12088 elsif Nkind (State) = N_Null then
12089 Create_Abstract_State
12090 (Nam => New_Internal_Name ('S'),
12091 Decl => Empty,
12092 Loc => Sloc (State),
12093 Is_Null => True);
12094 Null_Seen := True;
12095
12096 -- Catch a case where a null state appears in a list of
12097 -- non-null states.
12098
12099 if Non_Null_Seen then
12100 SPARK_Msg_NE
12101 ("package & has non-null abstract state",
12102 State, Pack_Id);
12103 end if;
12104
12105 -- Simple state declaration
12106
12107 elsif Nkind (State) = N_Identifier then
12108 Create_Abstract_State
12109 (Nam => Chars (State),
12110 Decl => State,
12111 Loc => Sloc (State),
12112 Is_Null => False);
12113 Non_Null_Seen := True;
12114
12115 -- State declaration with various options. This construct
12116 -- appears as an extension aggregate in the tree.
12117
12118 elsif Nkind (State) = N_Extension_Aggregate then
12119 if Nkind (Ancestor_Part (State)) = N_Identifier then
12120 Create_Abstract_State
12121 (Nam => Chars (Ancestor_Part (State)),
12122 Decl => Ancestor_Part (State),
12123 Loc => Sloc (Ancestor_Part (State)),
12124 Is_Null => False);
12125 Non_Null_Seen := True;
12126 else
12127 SPARK_Msg_N
12128 ("state name must be an identifier",
12129 Ancestor_Part (State));
12130 end if;
12131
12132 -- Options External, Ghost and Synchronous appear as
12133 -- expressions.
12134
12135 Opt := First (Expressions (State));
12136 while Present (Opt) loop
12137 if Nkind (Opt) = N_Identifier then
12138
12139 -- External
12140
12141 if Chars (Opt) = Name_External then
12142 Check_Duplicate_Option (Opt, External_Seen);
12143 Analyze_External_Option (Opt);
12144
12145 -- Ghost
12146
12147 elsif Chars (Opt) = Name_Ghost then
12148 Check_Duplicate_Option (Opt, Ghost_Seen);
12149 Check_Ghost_Synchronous;
12150
12151 if Present (State_Id) then
12152 Set_Is_Ghost_Entity (State_Id);
12153 end if;
12154
12155 -- Synchronous
12156
12157 elsif Chars (Opt) = Name_Synchronous then
12158 Check_Duplicate_Option (Opt, Synchronous_Seen);
12159 Check_Ghost_Synchronous;
12160
12161 -- Relaxed_Initialization
12162
12163 elsif Chars (Opt) = Name_Relaxed_Initialization then
12164 Check_Duplicate_Option
12165 (Opt, Relaxed_Initialization_Seen);
12166
12167 -- Option Part_Of without an encapsulating state is
12168 -- illegal (SPARK RM 7.1.4(8)).
12169
12170 elsif Chars (Opt) = Name_Part_Of then
12171 SPARK_Msg_N
12172 ("indicator Part_Of must denote abstract state, "
12173 & "single protected type or single task type",
12174 Opt);
12175
12176 -- Do not emit an error message when a previous state
12177 -- declaration with options was not parenthesized as
12178 -- the option is actually another state declaration.
12179 --
12180 -- with Abstract_State
12181 -- (State_1 with ..., -- missing parentheses
12182 -- (State_2 with ...),
12183 -- State_3) -- ok state declaration
12184
12185 elsif Missing_Parentheses then
12186 null;
12187
12188 -- Otherwise the option is not allowed. Note that it
12189 -- is not possible to distinguish between an option
12190 -- and a state declaration when a previous state with
12191 -- options not properly parentheses.
12192 --
12193 -- with Abstract_State
12194 -- (State_1 with ..., -- missing parentheses
12195 -- State_2); -- could be an option
12196
12197 else
12198 SPARK_Msg_N
12199 ("simple option not allowed in state declaration",
12200 Opt);
12201 end if;
12202
12203 -- Catch a case where missing parentheses around a state
12204 -- declaration with options cause a subsequent state
12205 -- declaration with options to be treated as an option.
12206 --
12207 -- with Abstract_State
12208 -- (State_1 with ..., -- missing parentheses
12209 -- (State_2 with ...))
12210
12211 elsif Nkind (Opt) = N_Extension_Aggregate then
12212 Missing_Parentheses := True;
12213 SPARK_Msg_N
12214 ("state declaration must be parenthesized",
12215 Ancestor_Part (State));
12216
12217 -- Otherwise the option is malformed
12218
12219 else
12220 SPARK_Msg_N ("malformed option", Opt);
12221 end if;
12222
12223 Next (Opt);
12224 end loop;
12225
12226 -- Options External and Part_Of appear as component
12227 -- associations.
12228
12229 Opt := First (Component_Associations (State));
12230 while Present (Opt) loop
12231 Opt_Nam := First (Choices (Opt));
12232
12233 if Nkind (Opt_Nam) = N_Identifier then
12234 if Chars (Opt_Nam) = Name_External then
12235 Analyze_External_Option (Opt);
12236
12237 elsif Chars (Opt_Nam) = Name_Part_Of then
12238 Analyze_Part_Of_Option (Opt);
12239
12240 else
12241 SPARK_Msg_N ("invalid state option", Opt);
12242 end if;
12243 else
12244 SPARK_Msg_N ("invalid state option", Opt);
12245 end if;
12246
12247 Next (Opt);
12248 end loop;
12249
12250 -- Any other attempt to declare a state is illegal
12251
12252 else
12253 Malformed_State_Error (State);
12254 return;
12255 end if;
12256
12257 -- Guard against a junk state. In such cases no entity is
12258 -- generated and the subsequent checks cannot be applied.
12259
12260 if Present (State_Id) then
12261
12262 -- Verify whether the state does not introduce an illegal
12263 -- hidden state within a package subject to a null abstract
12264 -- state.
12265
12266 Check_No_Hidden_State (State_Id);
12267
12268 -- Check whether the lack of option Part_Of agrees with the
12269 -- placement of the abstract state with respect to the state
12270 -- space.
12271
12272 if not Part_Of_Seen then
12273 Check_Missing_Part_Of (State_Id);
12274 end if;
12275
12276 -- Associate the state with its related package
12277
12278 if No (Abstract_States (Pack_Id)) then
12279 Set_Abstract_States (Pack_Id, New_Elmt_List);
12280 end if;
12281
12282 Append_Elmt (State_Id, Abstract_States (Pack_Id));
12283 end if;
12284 end Analyze_Abstract_State;
12285
12286 ---------------------------
12287 -- Malformed_State_Error --
12288 ---------------------------
12289
12290 procedure Malformed_State_Error (State : Node_Id) is
12291 begin
12292 Error_Msg_N ("malformed abstract state declaration", State);
12293
12294 -- An abstract state with a simple option is being declared
12295 -- with "=>" rather than the legal "with". The state appears
12296 -- as a component association.
12297
12298 if Nkind (State) = N_Component_Association then
12299 Error_Msg_N ("\use WITH to specify simple option", State);
12300 end if;
12301 end Malformed_State_Error;
12302
12303 -- Local variables
12304
12305 Pack_Decl : Node_Id;
12306 Pack_Id : Entity_Id;
12307 State : Node_Id;
12308 States : Node_Id;
12309
12310 -- Start of processing for Abstract_State
12311
12312 begin
12313 GNAT_Pragma;
12314 Check_No_Identifiers;
12315 Check_Arg_Count (1);
12316
12317 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
12318
12319 if Nkind (Pack_Decl) not in
12320 N_Generic_Package_Declaration | N_Package_Declaration
12321 then
12322 Pragma_Misplaced;
12323 return;
12324 end if;
12325
12326 Pack_Id := Defining_Entity (Pack_Decl);
12327
12328 -- A pragma that applies to a Ghost entity becomes Ghost for the
12329 -- purposes of legality checks and removal of ignored Ghost code.
12330
12331 Mark_Ghost_Pragma (N, Pack_Id);
12332 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
12333
12334 -- Chain the pragma on the contract for completeness
12335
12336 Add_Contract_Item (N, Pack_Id);
12337
12338 -- The legality checks of pragmas Abstract_State, Initializes, and
12339 -- Initial_Condition are affected by the SPARK mode in effect. In
12340 -- addition, these three pragmas are subject to an inherent order:
12341
12342 -- 1) Abstract_State
12343 -- 2) Initializes
12344 -- 3) Initial_Condition
12345
12346 -- Analyze all these pragmas in the order outlined above
12347
12348 Analyze_If_Present (Pragma_SPARK_Mode);
12349 States := Expression (Get_Argument (N, Pack_Id));
12350
12351 -- Multiple non-null abstract states appear as an aggregate
12352
12353 if Nkind (States) = N_Aggregate then
12354 State := First (Expressions (States));
12355 while Present (State) loop
12356 Analyze_Abstract_State (State, Pack_Id);
12357 Next (State);
12358 end loop;
12359
12360 -- An abstract state with a simple option is being illegaly
12361 -- declared with "=>" rather than "with". In this case the
12362 -- state declaration appears as a component association.
12363
12364 if Present (Component_Associations (States)) then
12365 State := First (Component_Associations (States));
12366 while Present (State) loop
12367 Malformed_State_Error (State);
12368 Next (State);
12369 end loop;
12370 end if;
12371
12372 -- Various forms of a single abstract state. Note that these may
12373 -- include malformed state declarations.
12374
12375 else
12376 Analyze_Abstract_State (States, Pack_Id);
12377 end if;
12378
12379 Analyze_If_Present (Pragma_Initializes);
12380 Analyze_If_Present (Pragma_Initial_Condition);
12381 end Abstract_State;
12382
12383 ------------
12384 -- Ada_83 --
12385 ------------
12386
12387 -- pragma Ada_83;
12388
12389 -- Note: this pragma also has some specific processing in Par.Prag
12390 -- because we want to set the Ada version mode during parsing.
12391
12392 when Pragma_Ada_83 =>
12393 GNAT_Pragma;
12394 Check_Arg_Count (0);
12395
12396 -- We really should check unconditionally for proper configuration
12397 -- pragma placement, since we really don't want mixed Ada modes
12398 -- within a single unit, and the GNAT reference manual has always
12399 -- said this was a configuration pragma, but we did not check and
12400 -- are hesitant to add the check now.
12401
12402 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
12403 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
12404 -- or Ada 2012 mode.
12405
12406 if Ada_Version >= Ada_2005 then
12407 Check_Valid_Configuration_Pragma;
12408 end if;
12409
12410 -- Now set Ada 83 mode
12411
12412 if Latest_Ada_Only then
12413 Error_Pragma ("??pragma% ignored");
12414 else
12415 Ada_Version := Ada_83;
12416 Ada_Version_Explicit := Ada_83;
12417 Ada_Version_Pragma := N;
12418 end if;
12419
12420 ------------
12421 -- Ada_95 --
12422 ------------
12423
12424 -- pragma Ada_95;
12425
12426 -- Note: this pragma also has some specific processing in Par.Prag
12427 -- because we want to set the Ada 83 version mode during parsing.
12428
12429 when Pragma_Ada_95 =>
12430 GNAT_Pragma;
12431 Check_Arg_Count (0);
12432
12433 -- We really should check unconditionally for proper configuration
12434 -- pragma placement, since we really don't want mixed Ada modes
12435 -- within a single unit, and the GNAT reference manual has always
12436 -- said this was a configuration pragma, but we did not check and
12437 -- are hesitant to add the check now.
12438
12439 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
12440 -- or Ada 95, so we must check if we are in Ada 2005 mode.
12441
12442 if Ada_Version >= Ada_2005 then
12443 Check_Valid_Configuration_Pragma;
12444 end if;
12445
12446 -- Now set Ada 95 mode
12447
12448 if Latest_Ada_Only then
12449 Error_Pragma ("??pragma% ignored");
12450 else
12451 Ada_Version := Ada_95;
12452 Ada_Version_Explicit := Ada_95;
12453 Ada_Version_Pragma := N;
12454 end if;
12455
12456 ---------------------
12457 -- Ada_05/Ada_2005 --
12458 ---------------------
12459
12460 -- pragma Ada_05;
12461 -- pragma Ada_05 (LOCAL_NAME);
12462
12463 -- pragma Ada_2005;
12464 -- pragma Ada_2005 (LOCAL_NAME):
12465
12466 -- Note: these pragmas also have some specific processing in Par.Prag
12467 -- because we want to set the Ada 2005 version mode during parsing.
12468
12469 -- The one argument form is used for managing the transition from
12470 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
12471 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
12472 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
12473 -- mode, a preference rule is established which does not choose
12474 -- such an entity unless it is unambiguously specified. This avoids
12475 -- extra subprograms marked this way from generating ambiguities in
12476 -- otherwise legal pre-Ada_2005 programs. The one argument form is
12477 -- intended for exclusive use in the GNAT run-time library.
12478
12479 when Pragma_Ada_05
12480 | Pragma_Ada_2005
12481 =>
12482 declare
12483 E_Id : Node_Id;
12484
12485 begin
12486 GNAT_Pragma;
12487
12488 if Arg_Count = 1 then
12489 Check_Arg_Is_Local_Name (Arg1);
12490 E_Id := Get_Pragma_Arg (Arg1);
12491
12492 if Etype (E_Id) = Any_Type then
12493 return;
12494 end if;
12495
12496 Set_Is_Ada_2005_Only (Entity (E_Id));
12497 Record_Rep_Item (Entity (E_Id), N);
12498
12499 else
12500 Check_Arg_Count (0);
12501
12502 -- For Ada_2005 we unconditionally enforce the documented
12503 -- configuration pragma placement, since we do not want to
12504 -- tolerate mixed modes in a unit involving Ada 2005. That
12505 -- would cause real difficulties for those cases where there
12506 -- are incompatibilities between Ada 95 and Ada 2005.
12507
12508 Check_Valid_Configuration_Pragma;
12509
12510 -- Now set appropriate Ada mode
12511
12512 if Latest_Ada_Only then
12513 Error_Pragma ("??pragma% ignored");
12514 else
12515 Ada_Version := Ada_2005;
12516 Ada_Version_Explicit := Ada_2005;
12517 Ada_Version_Pragma := N;
12518 end if;
12519 end if;
12520 end;
12521
12522 ---------------------
12523 -- Ada_12/Ada_2012 --
12524 ---------------------
12525
12526 -- pragma Ada_12;
12527 -- pragma Ada_12 (LOCAL_NAME);
12528
12529 -- pragma Ada_2012;
12530 -- pragma Ada_2012 (LOCAL_NAME):
12531
12532 -- Note: these pragmas also have some specific processing in Par.Prag
12533 -- because we want to set the Ada 2012 version mode during parsing.
12534
12535 -- The one argument form is used for managing the transition from Ada
12536 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
12537 -- as Ada_2012 only, then referencing the entity in any pre-Ada_2012
12538 -- mode will generate a warning. In addition, in any pre-Ada_2012
12539 -- mode, a preference rule is established which does not choose
12540 -- such an entity unless it is unambiguously specified. This avoids
12541 -- extra subprograms marked this way from generating ambiguities in
12542 -- otherwise legal pre-Ada_2012 programs. The one argument form is
12543 -- intended for exclusive use in the GNAT run-time library.
12544
12545 when Pragma_Ada_12
12546 | Pragma_Ada_2012
12547 =>
12548 declare
12549 E_Id : Node_Id;
12550
12551 begin
12552 GNAT_Pragma;
12553
12554 if Arg_Count = 1 then
12555 Check_Arg_Is_Local_Name (Arg1);
12556 E_Id := Get_Pragma_Arg (Arg1);
12557
12558 if Etype (E_Id) = Any_Type then
12559 return;
12560 end if;
12561
12562 Set_Is_Ada_2012_Only (Entity (E_Id));
12563 Record_Rep_Item (Entity (E_Id), N);
12564
12565 else
12566 Check_Arg_Count (0);
12567
12568 -- For Ada_2012 we unconditionally enforce the documented
12569 -- configuration pragma placement, since we do not want to
12570 -- tolerate mixed modes in a unit involving Ada 2012. That
12571 -- would cause real difficulties for those cases where there
12572 -- are incompatibilities between Ada 95 and Ada 2012. We could
12573 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
12574
12575 Check_Valid_Configuration_Pragma;
12576
12577 -- Now set appropriate Ada mode
12578
12579 Ada_Version := Ada_2012;
12580 Ada_Version_Explicit := Ada_2012;
12581 Ada_Version_Pragma := N;
12582 end if;
12583 end;
12584
12585 --------------
12586 -- Ada_2020 --
12587 --------------
12588
12589 -- pragma Ada_2020;
12590
12591 -- Note: this pragma also has some specific processing in Par.Prag
12592 -- because we want to set the Ada 2020 version mode during parsing.
12593
12594 when Pragma_Ada_2020 =>
12595 GNAT_Pragma;
12596
12597 Check_Arg_Count (0);
12598
12599 Check_Valid_Configuration_Pragma;
12600
12601 -- Now set appropriate Ada mode
12602
12603 Ada_Version := Ada_2020;
12604 Ada_Version_Explicit := Ada_2020;
12605 Ada_Version_Pragma := N;
12606
12607 -------------------------------------
12608 -- Aggregate_Individually_Assign --
12609 -------------------------------------
12610
12611 -- pragma Aggregate_Individually_Assign;
12612
12613 when Pragma_Aggregate_Individually_Assign =>
12614 GNAT_Pragma;
12615 Check_Arg_Count (0);
12616 Check_Valid_Configuration_Pragma;
12617 Aggregate_Individually_Assign := True;
12618
12619 ----------------------
12620 -- All_Calls_Remote --
12621 ----------------------
12622
12623 -- pragma All_Calls_Remote [(library_package_NAME)];
12624
12625 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
12626 Lib_Entity : Entity_Id;
12627
12628 begin
12629 Check_Ada_83_Warning;
12630 Check_Valid_Library_Unit_Pragma;
12631
12632 if Nkind (N) = N_Null_Statement then
12633 return;
12634 end if;
12635
12636 Lib_Entity := Find_Lib_Unit_Name;
12637
12638 -- A pragma that applies to a Ghost entity becomes Ghost for the
12639 -- purposes of legality checks and removal of ignored Ghost code.
12640
12641 Mark_Ghost_Pragma (N, Lib_Entity);
12642
12643 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
12644
12645 if Present (Lib_Entity) and then not Debug_Flag_U then
12646 if not Is_Remote_Call_Interface (Lib_Entity) then
12647 Error_Pragma ("pragma% only apply to rci unit");
12648
12649 -- Set flag for entity of the library unit
12650
12651 else
12652 Set_Has_All_Calls_Remote (Lib_Entity);
12653 end if;
12654 end if;
12655 end All_Calls_Remote;
12656
12657 ---------------------------
12658 -- Allow_Integer_Address --
12659 ---------------------------
12660
12661 -- pragma Allow_Integer_Address;
12662
12663 when Pragma_Allow_Integer_Address =>
12664 GNAT_Pragma;
12665 Check_Valid_Configuration_Pragma;
12666 Check_Arg_Count (0);
12667
12668 -- If Address is a private type, then set the flag to allow
12669 -- integer address values. If Address is not private, then this
12670 -- pragma has no purpose, so it is simply ignored. Not clear if
12671 -- there are any such targets now.
12672
12673 if Opt.Address_Is_Private then
12674 Opt.Allow_Integer_Address := True;
12675 end if;
12676
12677 --------------
12678 -- Annotate --
12679 --------------
12680
12681 -- pragma Annotate
12682 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
12683 -- ARG ::= NAME | EXPRESSION
12684
12685 -- The first two arguments are by convention intended to refer to an
12686 -- external tool and a tool-specific function. These arguments are
12687 -- not analyzed.
12688
12689 when Pragma_Annotate => Annotate : declare
12690 Arg : Node_Id;
12691 Expr : Node_Id;
12692 Nam_Arg : Node_Id;
12693
12694 --------------------------
12695 -- Inferred_String_Type --
12696 --------------------------
12697
12698 function Preferred_String_Type (Expr : Node_Id) return Entity_Id;
12699 -- Infer the type to use for a string literal or a concatentation
12700 -- of operands whose types can be inferred. For such expressions,
12701 -- returns the "narrowest" of the three predefined string types
12702 -- that can represent the characters occurring in the expression.
12703 -- For other expressions, returns Empty.
12704
12705 function Preferred_String_Type (Expr : Node_Id) return Entity_Id is
12706 begin
12707 case Nkind (Expr) is
12708 when N_String_Literal =>
12709 if Has_Wide_Wide_Character (Expr) then
12710 return Standard_Wide_Wide_String;
12711 elsif Has_Wide_Character (Expr) then
12712 return Standard_Wide_String;
12713 else
12714 return Standard_String;
12715 end if;
12716
12717 when N_Op_Concat =>
12718 declare
12719 L_Type : constant Entity_Id
12720 := Preferred_String_Type (Left_Opnd (Expr));
12721 R_Type : constant Entity_Id
12722 := Preferred_String_Type (Right_Opnd (Expr));
12723
12724 Type_Table : constant array (1 .. 4) of Entity_Id
12725 := (Empty,
12726 Standard_Wide_Wide_String,
12727 Standard_Wide_String,
12728 Standard_String);
12729 begin
12730 for Idx in Type_Table'Range loop
12731 if (L_Type = Type_Table (Idx)) or
12732 (R_Type = Type_Table (Idx))
12733 then
12734 return Type_Table (Idx);
12735 end if;
12736 end loop;
12737 raise Program_Error;
12738 end;
12739
12740 when others =>
12741 return Empty;
12742 end case;
12743 end Preferred_String_Type;
12744 begin
12745 GNAT_Pragma;
12746 Check_At_Least_N_Arguments (1);
12747
12748 Nam_Arg := Last (Pragma_Argument_Associations (N));
12749
12750 -- Determine whether the last argument is "Entity => local_NAME"
12751 -- and if it is, perform the required semantic checks. Remove the
12752 -- argument from further processing.
12753
12754 if Nkind (Nam_Arg) = N_Pragma_Argument_Association
12755 and then Chars (Nam_Arg) = Name_Entity
12756 then
12757 Check_Arg_Is_Local_Name (Nam_Arg);
12758 Arg_Count := Arg_Count - 1;
12759
12760 -- A pragma that applies to a Ghost entity becomes Ghost for
12761 -- the purposes of legality checks and removal of ignored Ghost
12762 -- code.
12763
12764 if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg))
12765 and then Present (Entity (Get_Pragma_Arg (Nam_Arg)))
12766 then
12767 Mark_Ghost_Pragma (N, Entity (Get_Pragma_Arg (Nam_Arg)));
12768 end if;
12769
12770 -- Not allowed in compiler units (bootstrap issues)
12771
12772 Check_Compiler_Unit ("Entity for pragma Annotate", N);
12773 end if;
12774
12775 -- Continue the processing with last argument removed for now
12776
12777 Check_Arg_Is_Identifier (Arg1);
12778 Check_No_Identifiers;
12779 Store_Note (N);
12780
12781 -- The second parameter is optional, it is never analyzed
12782
12783 if No (Arg2) then
12784 null;
12785
12786 -- Otherwise there is a second parameter
12787
12788 else
12789 -- The second parameter must be an identifier
12790
12791 Check_Arg_Is_Identifier (Arg2);
12792
12793 -- Process the remaining parameters (if any)
12794
12795 Arg := Next (Arg2);
12796 while Present (Arg) loop
12797 Expr := Get_Pragma_Arg (Arg);
12798 Analyze (Expr);
12799
12800 if Is_Entity_Name (Expr) then
12801 null;
12802
12803 -- For string literals and concatenations of string literals
12804 -- we assume Standard_String as the type, unless the string
12805 -- contains wide or wide_wide characters.
12806
12807 elsif Present (Preferred_String_Type (Expr)) then
12808 Resolve (Expr, Preferred_String_Type (Expr));
12809
12810 elsif Is_Overloaded (Expr) then
12811 Error_Pragma_Arg ("ambiguous argument for pragma%", Expr);
12812
12813 else
12814 Resolve (Expr);
12815 end if;
12816
12817 Next (Arg);
12818 end loop;
12819 end if;
12820 end Annotate;
12821
12822 -------------------------------------------------
12823 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
12824 -------------------------------------------------
12825
12826 -- pragma Assert
12827 -- ( [Check => ] Boolean_EXPRESSION
12828 -- [, [Message =>] Static_String_EXPRESSION]);
12829
12830 -- pragma Assert_And_Cut
12831 -- ( [Check => ] Boolean_EXPRESSION
12832 -- [, [Message =>] Static_String_EXPRESSION]);
12833
12834 -- pragma Assume
12835 -- ( [Check => ] Boolean_EXPRESSION
12836 -- [, [Message =>] Static_String_EXPRESSION]);
12837
12838 -- pragma Loop_Invariant
12839 -- ( [Check => ] Boolean_EXPRESSION
12840 -- [, [Message =>] Static_String_EXPRESSION]);
12841
12842 when Pragma_Assert
12843 | Pragma_Assert_And_Cut
12844 | Pragma_Assume
12845 | Pragma_Loop_Invariant
12846 =>
12847 Assert : declare
12848 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
12849 -- Determine whether expression Expr contains a Loop_Entry
12850 -- attribute reference.
12851
12852 -------------------------
12853 -- Contains_Loop_Entry --
12854 -------------------------
12855
12856 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
12857 Has_Loop_Entry : Boolean := False;
12858
12859 function Process (N : Node_Id) return Traverse_Result;
12860 -- Process function for traversal to look for Loop_Entry
12861
12862 -------------
12863 -- Process --
12864 -------------
12865
12866 function Process (N : Node_Id) return Traverse_Result is
12867 begin
12868 if Nkind (N) = N_Attribute_Reference
12869 and then Attribute_Name (N) = Name_Loop_Entry
12870 then
12871 Has_Loop_Entry := True;
12872 return Abandon;
12873 else
12874 return OK;
12875 end if;
12876 end Process;
12877
12878 procedure Traverse is new Traverse_Proc (Process);
12879
12880 -- Start of processing for Contains_Loop_Entry
12881
12882 begin
12883 Traverse (Expr);
12884 return Has_Loop_Entry;
12885 end Contains_Loop_Entry;
12886
12887 -- Local variables
12888
12889 Expr : Node_Id;
12890 New_Args : List_Id;
12891
12892 -- Start of processing for Assert
12893
12894 begin
12895 -- Assert is an Ada 2005 RM-defined pragma
12896
12897 if Prag_Id = Pragma_Assert then
12898 Ada_2005_Pragma;
12899
12900 -- The remaining ones are GNAT pragmas
12901
12902 else
12903 GNAT_Pragma;
12904 end if;
12905
12906 Check_At_Least_N_Arguments (1);
12907 Check_At_Most_N_Arguments (2);
12908 Check_Arg_Order ((Name_Check, Name_Message));
12909 Check_Optional_Identifier (Arg1, Name_Check);
12910 Expr := Get_Pragma_Arg (Arg1);
12911
12912 -- Special processing for Loop_Invariant, Loop_Variant or for
12913 -- other cases where a Loop_Entry attribute is present. If the
12914 -- assertion pragma contains attribute Loop_Entry, ensure that
12915 -- the related pragma is within a loop.
12916
12917 if Prag_Id = Pragma_Loop_Invariant
12918 or else Prag_Id = Pragma_Loop_Variant
12919 or else Contains_Loop_Entry (Expr)
12920 then
12921 Check_Loop_Pragma_Placement;
12922
12923 -- Perform preanalysis to deal with embedded Loop_Entry
12924 -- attributes.
12925
12926 Preanalyze_Assert_Expression (Expr, Any_Boolean);
12927 end if;
12928
12929 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
12930 -- a corresponding Check pragma:
12931
12932 -- pragma Check (name, condition [, msg]);
12933
12934 -- Where name is the identifier matching the pragma name. So
12935 -- rewrite pragma in this manner, transfer the message argument
12936 -- if present, and analyze the result
12937
12938 -- Note: When dealing with a semantically analyzed tree, the
12939 -- information that a Check node N corresponds to a source Assert,
12940 -- Assume, or Assert_And_Cut pragma can be retrieved from the
12941 -- pragma kind of Original_Node(N).
12942
12943 New_Args := New_List (
12944 Make_Pragma_Argument_Association (Loc,
12945 Expression => Make_Identifier (Loc, Pname)),
12946 Make_Pragma_Argument_Association (Sloc (Expr),
12947 Expression => Expr));
12948
12949 if Arg_Count > 1 then
12950 Check_Optional_Identifier (Arg2, Name_Message);
12951
12952 -- Provide semantic annotations for optional argument, for
12953 -- ASIS use, before rewriting.
12954 -- Is this still needed???
12955
12956 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
12957 Append_To (New_Args, New_Copy_Tree (Arg2));
12958 end if;
12959
12960 -- Rewrite as Check pragma
12961
12962 Rewrite (N,
12963 Make_Pragma (Loc,
12964 Chars => Name_Check,
12965 Pragma_Argument_Associations => New_Args));
12966
12967 Analyze (N);
12968 end Assert;
12969
12970 ----------------------
12971 -- Assertion_Policy --
12972 ----------------------
12973
12974 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
12975
12976 -- The following form is Ada 2012 only, but we allow it in all modes
12977
12978 -- Pragma Assertion_Policy (
12979 -- ASSERTION_KIND => POLICY_IDENTIFIER
12980 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
12981
12982 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
12983
12984 -- RM_ASSERTION_KIND ::= Assert |
12985 -- Static_Predicate |
12986 -- Dynamic_Predicate |
12987 -- Pre |
12988 -- Pre'Class |
12989 -- Post |
12990 -- Post'Class |
12991 -- Type_Invariant |
12992 -- Type_Invariant'Class
12993
12994 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
12995 -- Assume |
12996 -- Contract_Cases |
12997 -- Debug |
12998 -- Default_Initial_Condition |
12999 -- Ghost |
13000 -- Initial_Condition |
13001 -- Loop_Invariant |
13002 -- Loop_Variant |
13003 -- Postcondition |
13004 -- Precondition |
13005 -- Predicate |
13006 -- Refined_Post |
13007 -- Statement_Assertions
13008
13009 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
13010 -- ID_ASSERTION_KIND list contains implementation-defined additions
13011 -- recognized by GNAT. The effect is to control the behavior of
13012 -- identically named aspects and pragmas, depending on the specified
13013 -- policy identifier:
13014
13015 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
13016
13017 -- Note: Check and Ignore are language-defined. Disable is a GNAT
13018 -- implementation-defined addition that results in totally ignoring
13019 -- the corresponding assertion. If Disable is specified, then the
13020 -- argument of the assertion is not even analyzed. This is useful
13021 -- when the aspect/pragma argument references entities in a with'ed
13022 -- package that is replaced by a dummy package in the final build.
13023
13024 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
13025 -- and Type_Invariant'Class were recognized by the parser and
13026 -- transformed into references to the special internal identifiers
13027 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
13028 -- processing is required here.
13029
13030 when Pragma_Assertion_Policy => Assertion_Policy : declare
13031 procedure Resolve_Suppressible (Policy : Node_Id);
13032 -- Converts the assertion policy 'Suppressible' to either Check or
13033 -- Ignore based on whether checks are suppressed via -gnatp.
13034
13035 --------------------------
13036 -- Resolve_Suppressible --
13037 --------------------------
13038
13039 procedure Resolve_Suppressible (Policy : Node_Id) is
13040 Arg : constant Node_Id := Get_Pragma_Arg (Policy);
13041 Nam : Name_Id;
13042
13043 begin
13044 -- Transform policy argument Suppressible into either Ignore or
13045 -- Check depending on whether checks are enabled or suppressed.
13046
13047 if Chars (Arg) = Name_Suppressible then
13048 if Suppress_Checks then
13049 Nam := Name_Ignore;
13050 else
13051 Nam := Name_Check;
13052 end if;
13053
13054 Rewrite (Arg, Make_Identifier (Sloc (Arg), Nam));
13055 end if;
13056 end Resolve_Suppressible;
13057
13058 -- Local variables
13059
13060 Arg : Node_Id;
13061 Kind : Name_Id;
13062 LocP : Source_Ptr;
13063 Policy : Node_Id;
13064
13065 begin
13066 Ada_2005_Pragma;
13067
13068 -- This can always appear as a configuration pragma
13069
13070 if Is_Configuration_Pragma then
13071 null;
13072
13073 -- It can also appear in a declarative part or package spec in Ada
13074 -- 2012 mode. We allow this in other modes, but in that case we
13075 -- consider that we have an Ada 2012 pragma on our hands.
13076
13077 else
13078 Check_Is_In_Decl_Part_Or_Package_Spec;
13079 Ada_2012_Pragma;
13080 end if;
13081
13082 -- One argument case with no identifier (first form above)
13083
13084 if Arg_Count = 1
13085 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
13086 or else Chars (Arg1) = No_Name)
13087 then
13088 Check_Arg_Is_One_Of (Arg1,
13089 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13090
13091 Resolve_Suppressible (Arg1);
13092
13093 -- Treat one argument Assertion_Policy as equivalent to:
13094
13095 -- pragma Check_Policy (Assertion, policy)
13096
13097 -- So rewrite pragma in that manner and link on to the chain
13098 -- of Check_Policy pragmas, marking the pragma as analyzed.
13099
13100 Policy := Get_Pragma_Arg (Arg1);
13101
13102 Rewrite (N,
13103 Make_Pragma (Loc,
13104 Chars => Name_Check_Policy,
13105 Pragma_Argument_Associations => New_List (
13106 Make_Pragma_Argument_Association (Loc,
13107 Expression => Make_Identifier (Loc, Name_Assertion)),
13108
13109 Make_Pragma_Argument_Association (Loc,
13110 Expression =>
13111 Make_Identifier (Sloc (Policy), Chars (Policy))))));
13112 Analyze (N);
13113
13114 -- Here if we have two or more arguments
13115
13116 else
13117 Check_At_Least_N_Arguments (1);
13118 Ada_2012_Pragma;
13119
13120 -- Loop through arguments
13121
13122 Arg := Arg1;
13123 while Present (Arg) loop
13124 LocP := Sloc (Arg);
13125
13126 -- Kind must be specified
13127
13128 if Nkind (Arg) /= N_Pragma_Argument_Association
13129 or else Chars (Arg) = No_Name
13130 then
13131 Error_Pragma_Arg
13132 ("missing assertion kind for pragma%", Arg);
13133 end if;
13134
13135 -- Check Kind and Policy have allowed forms
13136
13137 Kind := Chars (Arg);
13138 Policy := Get_Pragma_Arg (Arg);
13139
13140 if not Is_Valid_Assertion_Kind (Kind) then
13141 Error_Pragma_Arg
13142 ("invalid assertion kind for pragma%", Arg);
13143 end if;
13144
13145 Check_Arg_Is_One_Of (Arg,
13146 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13147
13148 Resolve_Suppressible (Arg);
13149
13150 if Kind = Name_Ghost then
13151
13152 -- The Ghost policy must be either Check or Ignore
13153 -- (SPARK RM 6.9(6)).
13154
13155 if Chars (Policy) not in Name_Check | Name_Ignore then
13156 Error_Pragma_Arg
13157 ("argument of pragma % Ghost must be Check or "
13158 & "Ignore", Policy);
13159 end if;
13160
13161 -- Pragma Assertion_Policy specifying a Ghost policy
13162 -- cannot occur within a Ghost subprogram or package
13163 -- (SPARK RM 6.9(14)).
13164
13165 if Ghost_Mode > None then
13166 Error_Pragma
13167 ("pragma % cannot appear within ghost subprogram or "
13168 & "package");
13169 end if;
13170 end if;
13171
13172 -- Rewrite the Assertion_Policy pragma as a series of
13173 -- Check_Policy pragmas of the form:
13174
13175 -- Check_Policy (Kind, Policy);
13176
13177 -- Note: the insertion of the pragmas cannot be done with
13178 -- Insert_Action because in the configuration case, there
13179 -- are no scopes on the scope stack and the mechanism will
13180 -- fail.
13181
13182 Insert_Before_And_Analyze (N,
13183 Make_Pragma (LocP,
13184 Chars => Name_Check_Policy,
13185 Pragma_Argument_Associations => New_List (
13186 Make_Pragma_Argument_Association (LocP,
13187 Expression => Make_Identifier (LocP, Kind)),
13188 Make_Pragma_Argument_Association (LocP,
13189 Expression => Policy))));
13190
13191 Arg := Next (Arg);
13192 end loop;
13193
13194 -- Rewrite the Assertion_Policy pragma as null since we have
13195 -- now inserted all the equivalent Check pragmas.
13196
13197 Rewrite (N, Make_Null_Statement (Loc));
13198 Analyze (N);
13199 end if;
13200 end Assertion_Policy;
13201
13202 ------------------------------
13203 -- Assume_No_Invalid_Values --
13204 ------------------------------
13205
13206 -- pragma Assume_No_Invalid_Values (On | Off);
13207
13208 when Pragma_Assume_No_Invalid_Values =>
13209 GNAT_Pragma;
13210 Check_Valid_Configuration_Pragma;
13211 Check_Arg_Count (1);
13212 Check_No_Identifiers;
13213 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13214
13215 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
13216 Assume_No_Invalid_Values := True;
13217 else
13218 Assume_No_Invalid_Values := False;
13219 end if;
13220
13221 --------------------------
13222 -- Attribute_Definition --
13223 --------------------------
13224
13225 -- pragma Attribute_Definition
13226 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
13227 -- [Entity =>] LOCAL_NAME,
13228 -- [Expression =>] EXPRESSION | NAME);
13229
13230 when Pragma_Attribute_Definition => Attribute_Definition : declare
13231 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
13232 Aname : Name_Id;
13233
13234 begin
13235 GNAT_Pragma;
13236 Check_Arg_Count (3);
13237 Check_Optional_Identifier (Arg1, "attribute");
13238 Check_Optional_Identifier (Arg2, "entity");
13239 Check_Optional_Identifier (Arg3, "expression");
13240
13241 if Nkind (Attribute_Designator) /= N_Identifier then
13242 Error_Msg_N ("attribute name expected", Attribute_Designator);
13243 return;
13244 end if;
13245
13246 Check_Arg_Is_Local_Name (Arg2);
13247
13248 -- If the attribute is not recognized, then issue a warning (not
13249 -- an error), and ignore the pragma.
13250
13251 Aname := Chars (Attribute_Designator);
13252
13253 if not Is_Attribute_Name (Aname) then
13254 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
13255 return;
13256 end if;
13257
13258 -- Otherwise, rewrite the pragma as an attribute definition clause
13259
13260 Rewrite (N,
13261 Make_Attribute_Definition_Clause (Loc,
13262 Name => Get_Pragma_Arg (Arg2),
13263 Chars => Aname,
13264 Expression => Get_Pragma_Arg (Arg3)));
13265 Analyze (N);
13266 end Attribute_Definition;
13267
13268 ------------------------------------------------------------------
13269 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
13270 -- No_Caching --
13271 ------------------------------------------------------------------
13272
13273 -- pragma Async_Readers [ (boolean_EXPRESSION) ];
13274 -- pragma Async_Writers [ (boolean_EXPRESSION) ];
13275 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
13276 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
13277 -- pragma No_Caching [ (boolean_EXPRESSION) ];
13278
13279 when Pragma_Async_Readers
13280 | Pragma_Async_Writers
13281 | Pragma_Effective_Reads
13282 | Pragma_Effective_Writes
13283 | Pragma_No_Caching
13284 =>
13285 Async_Effective : declare
13286 Obj_Or_Type_Decl : Node_Id;
13287 Obj_Or_Type_Id : Entity_Id;
13288 begin
13289 GNAT_Pragma;
13290 Check_No_Identifiers;
13291 Check_At_Most_N_Arguments (1);
13292
13293 Obj_Or_Type_Decl := Find_Related_Context (N, Do_Checks => True);
13294
13295 -- Pragma must apply to a object declaration or to a type
13296 -- declaration (only the former in the No_Caching case).
13297 -- Original_Node is necessary to account for untagged derived
13298 -- types that are rewritten as subtypes of their
13299 -- respective root types.
13300
13301 if Nkind (Obj_Or_Type_Decl) /= N_Object_Declaration then
13302 if Prag_Id = Pragma_No_Caching
13303 or else Nkind (Original_Node (Obj_Or_Type_Decl)) not in
13304 N_Full_Type_Declaration |
13305 N_Private_Type_Declaration |
13306 N_Formal_Type_Declaration |
13307 N_Task_Type_Declaration |
13308 N_Protected_Type_Declaration
13309 then
13310 Pragma_Misplaced;
13311 return;
13312 end if;
13313 end if;
13314
13315 Obj_Or_Type_Id := Defining_Entity (Obj_Or_Type_Decl);
13316
13317 -- Perform minimal verification to ensure that the argument is at
13318 -- least a variable or a type. Subsequent finer grained checks
13319 -- will be done at the end of the declarative region that
13320 -- contains the pragma.
13321
13322 if Ekind (Obj_Or_Type_Id) = E_Variable
13323 or else Is_Type (Obj_Or_Type_Id)
13324 then
13325
13326 -- In the case of a type, pragma is a type-related
13327 -- representation item and so requires checks common to
13328 -- all type-related representation items.
13329
13330 if Is_Type (Obj_Or_Type_Id)
13331 and then Rep_Item_Too_Late (Obj_Or_Type_Id, N)
13332 then
13333 return;
13334 end if;
13335
13336 -- A pragma that applies to a Ghost entity becomes Ghost for
13337 -- the purposes of legality checks and removal of ignored Ghost
13338 -- code.
13339
13340 Mark_Ghost_Pragma (N, Obj_Or_Type_Id);
13341
13342 -- Chain the pragma on the contract for further processing by
13343 -- Analyze_External_Property_In_Decl_Part.
13344
13345 Add_Contract_Item (N, Obj_Or_Type_Id);
13346
13347 -- Analyze the Boolean expression (if any)
13348
13349 if Present (Arg1) then
13350 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
13351 end if;
13352
13353 -- Otherwise the external property applies to a constant
13354
13355 else
13356 Error_Pragma
13357 ("pragma % must apply to a volatile type or object");
13358 end if;
13359 end Async_Effective;
13360
13361 ------------------
13362 -- Asynchronous --
13363 ------------------
13364
13365 -- pragma Asynchronous (LOCAL_NAME);
13366
13367 when Pragma_Asynchronous => Asynchronous : declare
13368 C_Ent : Entity_Id;
13369 Decl : Node_Id;
13370 Formal : Entity_Id;
13371 L : List_Id;
13372 Nm : Entity_Id;
13373 S : Node_Id;
13374
13375 procedure Process_Async_Pragma;
13376 -- Common processing for procedure and access-to-procedure case
13377
13378 --------------------------
13379 -- Process_Async_Pragma --
13380 --------------------------
13381
13382 procedure Process_Async_Pragma is
13383 begin
13384 if No (L) then
13385 Set_Is_Asynchronous (Nm);
13386 return;
13387 end if;
13388
13389 -- The formals should be of mode IN (RM E.4.1(6))
13390
13391 S := First (L);
13392 while Present (S) loop
13393 Formal := Defining_Identifier (S);
13394
13395 if Nkind (Formal) = N_Defining_Identifier
13396 and then Ekind (Formal) /= E_In_Parameter
13397 then
13398 Error_Pragma_Arg
13399 ("pragma% procedure can only have IN parameter",
13400 Arg1);
13401 end if;
13402
13403 Next (S);
13404 end loop;
13405
13406 Set_Is_Asynchronous (Nm);
13407 end Process_Async_Pragma;
13408
13409 -- Start of processing for pragma Asynchronous
13410
13411 begin
13412 Check_Ada_83_Warning;
13413 Check_No_Identifiers;
13414 Check_Arg_Count (1);
13415 Check_Arg_Is_Local_Name (Arg1);
13416
13417 if Debug_Flag_U then
13418 return;
13419 end if;
13420
13421 C_Ent := Cunit_Entity (Current_Sem_Unit);
13422 Analyze (Get_Pragma_Arg (Arg1));
13423 Nm := Entity (Get_Pragma_Arg (Arg1));
13424
13425 -- A pragma that applies to a Ghost entity becomes Ghost for the
13426 -- purposes of legality checks and removal of ignored Ghost code.
13427
13428 Mark_Ghost_Pragma (N, Nm);
13429
13430 if not Is_Remote_Call_Interface (C_Ent)
13431 and then not Is_Remote_Types (C_Ent)
13432 then
13433 -- This pragma should only appear in an RCI or Remote Types
13434 -- unit (RM E.4.1(4)).
13435
13436 Error_Pragma
13437 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
13438 end if;
13439
13440 if Ekind (Nm) = E_Procedure
13441 and then Nkind (Parent (Nm)) = N_Procedure_Specification
13442 then
13443 if not Is_Remote_Call_Interface (Nm) then
13444 Error_Pragma_Arg
13445 ("pragma% cannot be applied on non-remote procedure",
13446 Arg1);
13447 end if;
13448
13449 L := Parameter_Specifications (Parent (Nm));
13450 Process_Async_Pragma;
13451 return;
13452
13453 elsif Ekind (Nm) = E_Function then
13454 Error_Pragma_Arg
13455 ("pragma% cannot be applied to function", Arg1);
13456
13457 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
13458 if Is_Record_Type (Nm) then
13459
13460 -- A record type that is the Equivalent_Type for a remote
13461 -- access-to-subprogram type.
13462
13463 Decl := Declaration_Node (Corresponding_Remote_Type (Nm));
13464
13465 else
13466 -- A non-expanded RAS type (distribution is not enabled)
13467
13468 Decl := Declaration_Node (Nm);
13469 end if;
13470
13471 if Nkind (Decl) = N_Full_Type_Declaration
13472 and then Nkind (Type_Definition (Decl)) =
13473 N_Access_Procedure_Definition
13474 then
13475 L := Parameter_Specifications (Type_Definition (Decl));
13476 Process_Async_Pragma;
13477
13478 if Is_Asynchronous (Nm)
13479 and then Expander_Active
13480 and then Get_PCS_Name /= Name_No_DSA
13481 then
13482 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
13483 end if;
13484
13485 else
13486 Error_Pragma_Arg
13487 ("pragma% cannot reference access-to-function type",
13488 Arg1);
13489 end if;
13490
13491 -- Only other possibility is Access-to-class-wide type
13492
13493 elsif Is_Access_Type (Nm)
13494 and then Is_Class_Wide_Type (Designated_Type (Nm))
13495 then
13496 Check_First_Subtype (Arg1);
13497 Set_Is_Asynchronous (Nm);
13498 if Expander_Active then
13499 RACW_Type_Is_Asynchronous (Nm);
13500 end if;
13501
13502 else
13503 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
13504 end if;
13505 end Asynchronous;
13506
13507 ------------
13508 -- Atomic --
13509 ------------
13510
13511 -- pragma Atomic (LOCAL_NAME);
13512
13513 when Pragma_Atomic =>
13514 Process_Atomic_Independent_Shared_Volatile;
13515
13516 -----------------------
13517 -- Atomic_Components --
13518 -----------------------
13519
13520 -- pragma Atomic_Components (array_LOCAL_NAME);
13521
13522 -- This processing is shared by Volatile_Components
13523
13524 when Pragma_Atomic_Components
13525 | Pragma_Volatile_Components
13526 =>
13527 Atomic_Components : declare
13528 D : Node_Id;
13529 E : Entity_Id;
13530 E_Id : Node_Id;
13531
13532 begin
13533 Check_Ada_83_Warning;
13534 Check_No_Identifiers;
13535 Check_Arg_Count (1);
13536 Check_Arg_Is_Local_Name (Arg1);
13537 E_Id := Get_Pragma_Arg (Arg1);
13538
13539 if Etype (E_Id) = Any_Type then
13540 return;
13541 end if;
13542
13543 E := Entity (E_Id);
13544
13545 -- A pragma that applies to a Ghost entity becomes Ghost for the
13546 -- purposes of legality checks and removal of ignored Ghost code.
13547
13548 Mark_Ghost_Pragma (N, E);
13549 Check_Duplicate_Pragma (E);
13550
13551 if Rep_Item_Too_Early (E, N)
13552 or else
13553 Rep_Item_Too_Late (E, N)
13554 then
13555 return;
13556 end if;
13557
13558 D := Declaration_Node (E);
13559
13560 if (Nkind (D) = N_Full_Type_Declaration and then Is_Array_Type (E))
13561 or else
13562 (Nkind (D) = N_Object_Declaration
13563 and then Ekind (E) in E_Constant | E_Variable
13564 and then Nkind (Object_Definition (D)) =
13565 N_Constrained_Array_Definition)
13566 or else
13567 (Ada_Version >= Ada_2020
13568 and then Nkind (D) = N_Formal_Type_Declaration)
13569 then
13570 -- The flag is set on the base type, or on the object
13571
13572 if Nkind (D) = N_Full_Type_Declaration then
13573 E := Base_Type (E);
13574 end if;
13575
13576 -- Atomic implies both Independent and Volatile
13577
13578 if Prag_Id = Pragma_Atomic_Components then
13579 if Ada_Version >= Ada_2020 then
13580 Check_Atomic_VFA
13581 (Component_Type (Etype (E)), VFA => False);
13582 end if;
13583
13584 Set_Has_Atomic_Components (E);
13585 Set_Has_Independent_Components (E);
13586 end if;
13587
13588 Set_Has_Volatile_Components (E);
13589
13590 else
13591 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
13592 end if;
13593 end Atomic_Components;
13594
13595 --------------------
13596 -- Attach_Handler --
13597 --------------------
13598
13599 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
13600
13601 when Pragma_Attach_Handler =>
13602 Check_Ada_83_Warning;
13603 Check_No_Identifiers;
13604 Check_Arg_Count (2);
13605
13606 if No_Run_Time_Mode then
13607 Error_Msg_CRT ("Attach_Handler pragma", N);
13608 else
13609 Check_Interrupt_Or_Attach_Handler;
13610
13611 -- The expression that designates the attribute may depend on a
13612 -- discriminant, and is therefore a per-object expression, to
13613 -- be expanded in the init proc. If expansion is enabled, then
13614 -- perform semantic checks on a copy only.
13615
13616 declare
13617 Temp : Node_Id;
13618 Typ : Node_Id;
13619 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
13620
13621 begin
13622 -- In Relaxed_RM_Semantics mode, we allow any static
13623 -- integer value, for compatibility with other compilers.
13624
13625 if Relaxed_RM_Semantics
13626 and then Nkind (Parg2) = N_Integer_Literal
13627 then
13628 Typ := Standard_Integer;
13629 else
13630 Typ := RTE (RE_Interrupt_ID);
13631 end if;
13632
13633 if Expander_Active then
13634 Temp := New_Copy_Tree (Parg2);
13635 Set_Parent (Temp, N);
13636 Preanalyze_And_Resolve (Temp, Typ);
13637 else
13638 Analyze (Parg2);
13639 Resolve (Parg2, Typ);
13640 end if;
13641 end;
13642
13643 Process_Interrupt_Or_Attach_Handler;
13644 end if;
13645
13646 --------------------
13647 -- C_Pass_By_Copy --
13648 --------------------
13649
13650 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
13651
13652 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
13653 Arg : Node_Id;
13654 Val : Uint;
13655
13656 begin
13657 GNAT_Pragma;
13658 Check_Valid_Configuration_Pragma;
13659 Check_Arg_Count (1);
13660 Check_Optional_Identifier (Arg1, "max_size");
13661
13662 Arg := Get_Pragma_Arg (Arg1);
13663 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
13664
13665 Val := Expr_Value (Arg);
13666
13667 if Val <= 0 then
13668 Error_Pragma_Arg
13669 ("maximum size for pragma% must be positive", Arg1);
13670
13671 elsif UI_Is_In_Int_Range (Val) then
13672 Default_C_Record_Mechanism := UI_To_Int (Val);
13673
13674 -- If a giant value is given, Int'Last will do well enough.
13675 -- If sometime someone complains that a record larger than
13676 -- two gigabytes is not copied, we will worry about it then.
13677
13678 else
13679 Default_C_Record_Mechanism := Mechanism_Type'Last;
13680 end if;
13681 end C_Pass_By_Copy;
13682
13683 -----------
13684 -- Check --
13685 -----------
13686
13687 -- pragma Check ([Name =>] CHECK_KIND,
13688 -- [Check =>] Boolean_EXPRESSION
13689 -- [,[Message =>] String_EXPRESSION]);
13690
13691 -- CHECK_KIND ::= IDENTIFIER |
13692 -- Pre'Class |
13693 -- Post'Class |
13694 -- Invariant'Class |
13695 -- Type_Invariant'Class
13696
13697 -- The identifiers Assertions and Statement_Assertions are not
13698 -- allowed, since they have special meaning for Check_Policy.
13699
13700 -- WARNING: The code below manages Ghost regions. Return statements
13701 -- must be replaced by gotos which jump to the end of the code and
13702 -- restore the Ghost mode.
13703
13704 when Pragma_Check => Check : declare
13705 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
13706 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
13707 -- Save the Ghost-related attributes to restore on exit
13708
13709 Cname : Name_Id;
13710 Eloc : Source_Ptr;
13711 Expr : Node_Id;
13712 Str : Node_Id;
13713 pragma Warnings (Off, Str);
13714
13715 begin
13716 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
13717 -- the mode now to ensure that any nodes generated during analysis
13718 -- and expansion are marked as Ghost.
13719
13720 Set_Ghost_Mode (N);
13721
13722 GNAT_Pragma;
13723 Check_At_Least_N_Arguments (2);
13724 Check_At_Most_N_Arguments (3);
13725 Check_Optional_Identifier (Arg1, Name_Name);
13726 Check_Optional_Identifier (Arg2, Name_Check);
13727
13728 if Arg_Count = 3 then
13729 Check_Optional_Identifier (Arg3, Name_Message);
13730 Str := Get_Pragma_Arg (Arg3);
13731 end if;
13732
13733 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
13734 Check_Arg_Is_Identifier (Arg1);
13735 Cname := Chars (Get_Pragma_Arg (Arg1));
13736
13737 -- Check forbidden name Assertions or Statement_Assertions
13738
13739 case Cname is
13740 when Name_Assertions =>
13741 Error_Pragma_Arg
13742 ("""Assertions"" is not allowed as a check kind for "
13743 & "pragma%", Arg1);
13744
13745 when Name_Statement_Assertions =>
13746 Error_Pragma_Arg
13747 ("""Statement_Assertions"" is not allowed as a check kind "
13748 & "for pragma%", Arg1);
13749
13750 when others =>
13751 null;
13752 end case;
13753
13754 -- Check applicable policy. We skip this if Checked/Ignored status
13755 -- is already set (e.g. in the case of a pragma from an aspect).
13756
13757 if Is_Checked (N) or else Is_Ignored (N) then
13758 null;
13759
13760 -- For a non-source pragma that is a rewriting of another pragma,
13761 -- copy the Is_Checked/Ignored status from the rewritten pragma.
13762
13763 elsif Is_Rewrite_Substitution (N)
13764 and then Nkind (Original_Node (N)) = N_Pragma
13765 then
13766 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
13767 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
13768
13769 -- Otherwise query the applicable policy at this point
13770
13771 else
13772 case Check_Kind (Cname) is
13773 when Name_Ignore =>
13774 Set_Is_Ignored (N, True);
13775 Set_Is_Checked (N, False);
13776
13777 when Name_Check =>
13778 Set_Is_Ignored (N, False);
13779 Set_Is_Checked (N, True);
13780
13781 -- For disable, rewrite pragma as null statement and skip
13782 -- rest of the analysis of the pragma.
13783
13784 when Name_Disable =>
13785 Rewrite (N, Make_Null_Statement (Loc));
13786 Analyze (N);
13787 raise Pragma_Exit;
13788
13789 -- No other possibilities
13790
13791 when others =>
13792 raise Program_Error;
13793 end case;
13794 end if;
13795
13796 -- If check kind was not Disable, then continue pragma analysis
13797
13798 Expr := Get_Pragma_Arg (Arg2);
13799
13800 -- Mark the pragma (or, if rewritten from an aspect, the original
13801 -- aspect) as enabled. Nothing to do for an internally generated
13802 -- check for a dynamic predicate.
13803
13804 if Is_Checked (N)
13805 and then not Split_PPC (N)
13806 and then Cname /= Name_Dynamic_Predicate
13807 then
13808 Set_SCO_Pragma_Enabled (Loc);
13809 end if;
13810
13811 -- Deal with analyzing the string argument. If checks are not
13812 -- on we don't want any expansion (since such expansion would
13813 -- not get properly deleted) but we do want to analyze (to get
13814 -- proper references). The Preanalyze_And_Resolve routine does
13815 -- just what we want. Ditto if pragma is active, because it will
13816 -- be rewritten as an if-statement whose analysis will complete
13817 -- analysis and expansion of the string message. This makes a
13818 -- difference in the unusual case where the expression for the
13819 -- string may have a side effect, such as raising an exception.
13820 -- This is mandated by RM 11.4.2, which specifies that the string
13821 -- expression is only evaluated if the check fails and
13822 -- Assertion_Error is to be raised.
13823
13824 if Arg_Count = 3 then
13825 Preanalyze_And_Resolve (Str, Standard_String);
13826 end if;
13827
13828 -- Now you might think we could just do the same with the Boolean
13829 -- expression if checks are off (and expansion is on) and then
13830 -- rewrite the check as a null statement. This would work but we
13831 -- would lose the useful warnings about an assertion being bound
13832 -- to fail even if assertions are turned off.
13833
13834 -- So instead we wrap the boolean expression in an if statement
13835 -- that looks like:
13836
13837 -- if False and then condition then
13838 -- null;
13839 -- end if;
13840
13841 -- The reason we do this rewriting during semantic analysis rather
13842 -- than as part of normal expansion is that we cannot analyze and
13843 -- expand the code for the boolean expression directly, or it may
13844 -- cause insertion of actions that would escape the attempt to
13845 -- suppress the check code.
13846
13847 -- Note that the Sloc for the if statement corresponds to the
13848 -- argument condition, not the pragma itself. The reason for
13849 -- this is that we may generate a warning if the condition is
13850 -- False at compile time, and we do not want to delete this
13851 -- warning when we delete the if statement.
13852
13853 if Expander_Active and Is_Ignored (N) then
13854 Eloc := Sloc (Expr);
13855
13856 Rewrite (N,
13857 Make_If_Statement (Eloc,
13858 Condition =>
13859 Make_And_Then (Eloc,
13860 Left_Opnd => Make_Identifier (Eloc, Name_False),
13861 Right_Opnd => Expr),
13862 Then_Statements => New_List (
13863 Make_Null_Statement (Eloc))));
13864
13865 -- Now go ahead and analyze the if statement
13866
13867 In_Assertion_Expr := In_Assertion_Expr + 1;
13868
13869 -- One rather special treatment. If we are now in Eliminated
13870 -- overflow mode, then suppress overflow checking since we do
13871 -- not want to drag in the bignum stuff if we are in Ignore
13872 -- mode anyway. This is particularly important if we are using
13873 -- a configurable run time that does not support bignum ops.
13874
13875 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
13876 declare
13877 Svo : constant Boolean :=
13878 Scope_Suppress.Suppress (Overflow_Check);
13879 begin
13880 Scope_Suppress.Overflow_Mode_Assertions := Strict;
13881 Scope_Suppress.Suppress (Overflow_Check) := True;
13882 Analyze (N);
13883 Scope_Suppress.Suppress (Overflow_Check) := Svo;
13884 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
13885 end;
13886
13887 -- Not that special case
13888
13889 else
13890 Analyze (N);
13891 end if;
13892
13893 -- All done with this check
13894
13895 In_Assertion_Expr := In_Assertion_Expr - 1;
13896
13897 -- Check is active or expansion not active. In these cases we can
13898 -- just go ahead and analyze the boolean with no worries.
13899
13900 else
13901 In_Assertion_Expr := In_Assertion_Expr + 1;
13902 Analyze_And_Resolve (Expr, Any_Boolean);
13903 In_Assertion_Expr := In_Assertion_Expr - 1;
13904 end if;
13905
13906 Restore_Ghost_Region (Saved_GM, Saved_IGR);
13907 end Check;
13908
13909 --------------------------
13910 -- Check_Float_Overflow --
13911 --------------------------
13912
13913 -- pragma Check_Float_Overflow;
13914
13915 when Pragma_Check_Float_Overflow =>
13916 GNAT_Pragma;
13917 Check_Valid_Configuration_Pragma;
13918 Check_Arg_Count (0);
13919 Check_Float_Overflow := not Machine_Overflows_On_Target;
13920
13921 ----------------
13922 -- Check_Name --
13923 ----------------
13924
13925 -- pragma Check_Name (check_IDENTIFIER);
13926
13927 when Pragma_Check_Name =>
13928 GNAT_Pragma;
13929 Check_No_Identifiers;
13930 Check_Valid_Configuration_Pragma;
13931 Check_Arg_Count (1);
13932 Check_Arg_Is_Identifier (Arg1);
13933
13934 declare
13935 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
13936
13937 begin
13938 for J in Check_Names.First .. Check_Names.Last loop
13939 if Check_Names.Table (J) = Nam then
13940 return;
13941 end if;
13942 end loop;
13943
13944 Check_Names.Append (Nam);
13945 end;
13946
13947 ------------------
13948 -- Check_Policy --
13949 ------------------
13950
13951 -- This is the old style syntax, which is still allowed in all modes:
13952
13953 -- pragma Check_Policy ([Name =>] CHECK_KIND
13954 -- [Policy =>] POLICY_IDENTIFIER);
13955
13956 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
13957
13958 -- CHECK_KIND ::= IDENTIFIER |
13959 -- Pre'Class |
13960 -- Post'Class |
13961 -- Type_Invariant'Class |
13962 -- Invariant'Class
13963
13964 -- This is the new style syntax, compatible with Assertion_Policy
13965 -- and also allowed in all modes.
13966
13967 -- Pragma Check_Policy (
13968 -- CHECK_KIND => POLICY_IDENTIFIER
13969 -- {, CHECK_KIND => POLICY_IDENTIFIER});
13970
13971 -- Note: the identifiers Name and Policy are not allowed as
13972 -- Check_Kind values. This avoids ambiguities between the old and
13973 -- new form syntax.
13974
13975 when Pragma_Check_Policy => Check_Policy : declare
13976 Kind : Node_Id;
13977
13978 begin
13979 GNAT_Pragma;
13980 Check_At_Least_N_Arguments (1);
13981
13982 -- A Check_Policy pragma can appear either as a configuration
13983 -- pragma, or in a declarative part or a package spec (see RM
13984 -- 11.5(5) for rules for Suppress/Unsuppress which are also
13985 -- followed for Check_Policy).
13986
13987 if not Is_Configuration_Pragma then
13988 Check_Is_In_Decl_Part_Or_Package_Spec;
13989 end if;
13990
13991 -- Figure out if we have the old or new syntax. We have the
13992 -- old syntax if the first argument has no identifier, or the
13993 -- identifier is Name.
13994
13995 if Nkind (Arg1) /= N_Pragma_Argument_Association
13996 or else Chars (Arg1) in No_Name | Name_Name
13997 then
13998 -- Old syntax
13999
14000 Check_Arg_Count (2);
14001 Check_Optional_Identifier (Arg1, Name_Name);
14002 Kind := Get_Pragma_Arg (Arg1);
14003 Rewrite_Assertion_Kind (Kind,
14004 From_Policy => Comes_From_Source (N));
14005 Check_Arg_Is_Identifier (Arg1);
14006
14007 -- Check forbidden check kind
14008
14009 if Chars (Kind) in Name_Name | Name_Policy then
14010 Error_Msg_Name_2 := Chars (Kind);
14011 Error_Pragma_Arg
14012 ("pragma% does not allow% as check name", Arg1);
14013 end if;
14014
14015 -- Check policy
14016
14017 Check_Optional_Identifier (Arg2, Name_Policy);
14018 Check_Arg_Is_One_Of
14019 (Arg2,
14020 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
14021
14022 -- And chain pragma on the Check_Policy_List for search
14023
14024 Set_Next_Pragma (N, Opt.Check_Policy_List);
14025 Opt.Check_Policy_List := N;
14026
14027 -- For the new syntax, what we do is to convert each argument to
14028 -- an old syntax equivalent. We do that because we want to chain
14029 -- old style Check_Policy pragmas for the search (we don't want
14030 -- to have to deal with multiple arguments in the search).
14031
14032 else
14033 declare
14034 Arg : Node_Id;
14035 Argx : Node_Id;
14036 LocP : Source_Ptr;
14037 New_P : Node_Id;
14038
14039 begin
14040 Arg := Arg1;
14041 while Present (Arg) loop
14042 LocP := Sloc (Arg);
14043 Argx := Get_Pragma_Arg (Arg);
14044
14045 -- Kind must be specified
14046
14047 if Nkind (Arg) /= N_Pragma_Argument_Association
14048 or else Chars (Arg) = No_Name
14049 then
14050 Error_Pragma_Arg
14051 ("missing assertion kind for pragma%", Arg);
14052 end if;
14053
14054 -- Construct equivalent old form syntax Check_Policy
14055 -- pragma and insert it to get remaining checks.
14056
14057 New_P :=
14058 Make_Pragma (LocP,
14059 Chars => Name_Check_Policy,
14060 Pragma_Argument_Associations => New_List (
14061 Make_Pragma_Argument_Association (LocP,
14062 Expression =>
14063 Make_Identifier (LocP, Chars (Arg))),
14064 Make_Pragma_Argument_Association (Sloc (Argx),
14065 Expression => Argx)));
14066
14067 Arg := Next (Arg);
14068
14069 -- For a configuration pragma, insert old form in
14070 -- the corresponding file.
14071
14072 if Is_Configuration_Pragma then
14073 Insert_After (N, New_P);
14074 Analyze (New_P);
14075
14076 else
14077 Insert_Action (N, New_P);
14078 end if;
14079 end loop;
14080
14081 -- Rewrite original Check_Policy pragma to null, since we
14082 -- have converted it into a series of old syntax pragmas.
14083
14084 Rewrite (N, Make_Null_Statement (Loc));
14085 Analyze (N);
14086 end;
14087 end if;
14088 end Check_Policy;
14089
14090 -------------
14091 -- Comment --
14092 -------------
14093
14094 -- pragma Comment (static_string_EXPRESSION)
14095
14096 -- Processing for pragma Comment shares the circuitry for pragma
14097 -- Ident. The only differences are that Ident enforces a limit of 31
14098 -- characters on its argument, and also enforces limitations on
14099 -- placement for DEC compatibility. Pragma Comment shares neither of
14100 -- these restrictions.
14101
14102 -------------------
14103 -- Common_Object --
14104 -------------------
14105
14106 -- pragma Common_Object (
14107 -- [Internal =>] LOCAL_NAME
14108 -- [, [External =>] EXTERNAL_SYMBOL]
14109 -- [, [Size =>] EXTERNAL_SYMBOL]);
14110
14111 -- Processing for this pragma is shared with Psect_Object
14112
14113 ----------------------------------------------
14114 -- Compile_Time_Error, Compile_Time_Warning --
14115 ----------------------------------------------
14116
14117 -- pragma Compile_Time_Error
14118 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14119
14120 -- pragma Compile_Time_Warning
14121 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14122
14123 when Pragma_Compile_Time_Error | Pragma_Compile_Time_Warning =>
14124 GNAT_Pragma;
14125 Process_Compile_Time_Warning_Or_Error;
14126
14127 ---------------------------
14128 -- Compiler_Unit_Warning --
14129 ---------------------------
14130
14131 -- pragma Compiler_Unit_Warning;
14132
14133 -- Historical note
14134
14135 -- Originally, we had only pragma Compiler_Unit, and it resulted in
14136 -- errors not warnings. This means that we had introduced a big extra
14137 -- inertia to compiler changes, since even if we implemented a new
14138 -- feature, and even if all versions to be used for bootstrapping
14139 -- implemented this new feature, we could not use it, since old
14140 -- compilers would give errors for using this feature in units
14141 -- having Compiler_Unit pragmas.
14142
14143 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
14144 -- problem. We no longer have any units mentioning Compiler_Unit,
14145 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
14146 -- and thus generates a warning which can be ignored. So that deals
14147 -- with the problem of old compilers not implementing the newer form
14148 -- of the pragma.
14149
14150 -- Newer compilers recognize the new pragma, but generate warning
14151 -- messages instead of errors, which again can be ignored in the
14152 -- case of an old compiler which implements a wanted new feature
14153 -- but at the time felt like warning about it for older compilers.
14154
14155 -- We retain Compiler_Unit so that new compilers can be used to build
14156 -- older run-times that use this pragma. That's an unusual case, but
14157 -- it's easy enough to handle, so why not?
14158
14159 when Pragma_Compiler_Unit
14160 | Pragma_Compiler_Unit_Warning
14161 =>
14162 GNAT_Pragma;
14163 Check_Arg_Count (0);
14164
14165 -- Only recognized in main unit
14166
14167 if Current_Sem_Unit = Main_Unit then
14168 Compiler_Unit := True;
14169 end if;
14170
14171 -----------------------------
14172 -- Complete_Representation --
14173 -----------------------------
14174
14175 -- pragma Complete_Representation;
14176
14177 when Pragma_Complete_Representation =>
14178 GNAT_Pragma;
14179 Check_Arg_Count (0);
14180
14181 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
14182 Error_Pragma
14183 ("pragma & must appear within record representation clause");
14184 end if;
14185
14186 ----------------------------
14187 -- Complex_Representation --
14188 ----------------------------
14189
14190 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
14191
14192 when Pragma_Complex_Representation => Complex_Representation : declare
14193 E_Id : Node_Id;
14194 E : Entity_Id;
14195 Ent : Entity_Id;
14196
14197 begin
14198 GNAT_Pragma;
14199 Check_Arg_Count (1);
14200 Check_Optional_Identifier (Arg1, Name_Entity);
14201 Check_Arg_Is_Local_Name (Arg1);
14202 E_Id := Get_Pragma_Arg (Arg1);
14203
14204 if Etype (E_Id) = Any_Type then
14205 return;
14206 end if;
14207
14208 E := Entity (E_Id);
14209
14210 if not Is_Record_Type (E) then
14211 Error_Pragma_Arg
14212 ("argument for pragma% must be record type", Arg1);
14213 end if;
14214
14215 Ent := First_Entity (E);
14216
14217 if No (Ent)
14218 or else No (Next_Entity (Ent))
14219 or else Present (Next_Entity (Next_Entity (Ent)))
14220 or else not Is_Floating_Point_Type (Etype (Ent))
14221 or else Etype (Ent) /= Etype (Next_Entity (Ent))
14222 then
14223 Error_Pragma_Arg
14224 ("record for pragma% must have two fields of the same "
14225 & "floating-point type", Arg1);
14226
14227 else
14228 Set_Has_Complex_Representation (Base_Type (E));
14229
14230 -- We need to treat the type has having a non-standard
14231 -- representation, for back-end purposes, even though in
14232 -- general a complex will have the default representation
14233 -- of a record with two real components.
14234
14235 Set_Has_Non_Standard_Rep (Base_Type (E));
14236 end if;
14237 end Complex_Representation;
14238
14239 -------------------------
14240 -- Component_Alignment --
14241 -------------------------
14242
14243 -- pragma Component_Alignment (
14244 -- [Form =>] ALIGNMENT_CHOICE
14245 -- [, [Name =>] type_LOCAL_NAME]);
14246 --
14247 -- ALIGNMENT_CHOICE ::=
14248 -- Component_Size
14249 -- | Component_Size_4
14250 -- | Storage_Unit
14251 -- | Default
14252
14253 when Pragma_Component_Alignment => Component_AlignmentP : declare
14254 Args : Args_List (1 .. 2);
14255 Names : constant Name_List (1 .. 2) := (
14256 Name_Form,
14257 Name_Name);
14258
14259 Form : Node_Id renames Args (1);
14260 Name : Node_Id renames Args (2);
14261
14262 Atype : Component_Alignment_Kind;
14263 Typ : Entity_Id;
14264
14265 begin
14266 GNAT_Pragma;
14267 Gather_Associations (Names, Args);
14268
14269 if No (Form) then
14270 Error_Pragma ("missing Form argument for pragma%");
14271 end if;
14272
14273 Check_Arg_Is_Identifier (Form);
14274
14275 -- Get proper alignment, note that Default = Component_Size on all
14276 -- machines we have so far, and we want to set this value rather
14277 -- than the default value to indicate that it has been explicitly
14278 -- set (and thus will not get overridden by the default component
14279 -- alignment for the current scope)
14280
14281 if Chars (Form) = Name_Component_Size then
14282 Atype := Calign_Component_Size;
14283
14284 elsif Chars (Form) = Name_Component_Size_4 then
14285 Atype := Calign_Component_Size_4;
14286
14287 elsif Chars (Form) = Name_Default then
14288 Atype := Calign_Component_Size;
14289
14290 elsif Chars (Form) = Name_Storage_Unit then
14291 Atype := Calign_Storage_Unit;
14292
14293 else
14294 Error_Pragma_Arg
14295 ("invalid Form parameter for pragma%", Form);
14296 end if;
14297
14298 -- The pragma appears in a configuration file
14299
14300 if No (Parent (N)) then
14301 Check_Valid_Configuration_Pragma;
14302
14303 -- Capture the component alignment in a global variable when
14304 -- the pragma appears in a configuration file. Note that the
14305 -- scope stack is empty at this point and cannot be used to
14306 -- store the alignment value.
14307
14308 Configuration_Component_Alignment := Atype;
14309
14310 -- Case with no name, supplied, affects scope table entry
14311
14312 elsif No (Name) then
14313 Scope_Stack.Table
14314 (Scope_Stack.Last).Component_Alignment_Default := Atype;
14315
14316 -- Case of name supplied
14317
14318 else
14319 Check_Arg_Is_Local_Name (Name);
14320 Find_Type (Name);
14321 Typ := Entity (Name);
14322
14323 if Typ = Any_Type
14324 or else Rep_Item_Too_Early (Typ, N)
14325 then
14326 return;
14327 else
14328 Typ := Underlying_Type (Typ);
14329 end if;
14330
14331 if not Is_Record_Type (Typ)
14332 and then not Is_Array_Type (Typ)
14333 then
14334 Error_Pragma_Arg
14335 ("Name parameter of pragma% must identify record or "
14336 & "array type", Name);
14337 end if;
14338
14339 -- An explicit Component_Alignment pragma overrides an
14340 -- implicit pragma Pack, but not an explicit one.
14341
14342 if not Has_Pragma_Pack (Base_Type (Typ)) then
14343 Set_Is_Packed (Base_Type (Typ), False);
14344 Set_Component_Alignment (Base_Type (Typ), Atype);
14345 end if;
14346 end if;
14347 end Component_AlignmentP;
14348
14349 --------------------------------
14350 -- Constant_After_Elaboration --
14351 --------------------------------
14352
14353 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
14354
14355 when Pragma_Constant_After_Elaboration => Constant_After_Elaboration :
14356 declare
14357 Obj_Decl : Node_Id;
14358 Obj_Id : Entity_Id;
14359
14360 begin
14361 GNAT_Pragma;
14362 Check_No_Identifiers;
14363 Check_At_Most_N_Arguments (1);
14364
14365 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
14366
14367 if Nkind (Obj_Decl) /= N_Object_Declaration then
14368 Pragma_Misplaced;
14369 return;
14370 end if;
14371
14372 Obj_Id := Defining_Entity (Obj_Decl);
14373
14374 -- The object declaration must be a library-level variable which
14375 -- is either explicitly initialized or obtains a value during the
14376 -- elaboration of a package body (SPARK RM 3.3.1).
14377
14378 if Ekind (Obj_Id) = E_Variable then
14379 if not Is_Library_Level_Entity (Obj_Id) then
14380 Error_Pragma
14381 ("pragma % must apply to a library level variable");
14382 return;
14383 end if;
14384
14385 -- Otherwise the pragma applies to a constant, which is illegal
14386
14387 else
14388 Error_Pragma ("pragma % must apply to a variable declaration");
14389 return;
14390 end if;
14391
14392 -- A pragma that applies to a Ghost entity becomes Ghost for the
14393 -- purposes of legality checks and removal of ignored Ghost code.
14394
14395 Mark_Ghost_Pragma (N, Obj_Id);
14396
14397 -- Chain the pragma on the contract for completeness
14398
14399 Add_Contract_Item (N, Obj_Id);
14400
14401 -- Analyze the Boolean expression (if any)
14402
14403 if Present (Arg1) then
14404 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
14405 end if;
14406 end Constant_After_Elaboration;
14407
14408 --------------------
14409 -- Contract_Cases --
14410 --------------------
14411
14412 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
14413
14414 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
14415
14416 -- CASE_GUARD ::= boolean_EXPRESSION | others
14417
14418 -- CONSEQUENCE ::= boolean_EXPRESSION
14419
14420 -- Characteristics:
14421
14422 -- * Analysis - The annotation undergoes initial checks to verify
14423 -- the legal placement and context. Secondary checks preanalyze the
14424 -- expressions in:
14425
14426 -- Analyze_Contract_Cases_In_Decl_Part
14427
14428 -- * Expansion - The annotation is expanded during the expansion of
14429 -- the related subprogram [body] contract as performed in:
14430
14431 -- Expand_Subprogram_Contract
14432
14433 -- * Template - The annotation utilizes the generic template of the
14434 -- related subprogram [body] when it is:
14435
14436 -- aspect on subprogram declaration
14437 -- aspect on stand-alone subprogram body
14438 -- pragma on stand-alone subprogram body
14439
14440 -- The annotation must prepare its own template when it is:
14441
14442 -- pragma on subprogram declaration
14443
14444 -- * Globals - Capture of global references must occur after full
14445 -- analysis.
14446
14447 -- * Instance - The annotation is instantiated automatically when
14448 -- the related generic subprogram [body] is instantiated except for
14449 -- the "pragma on subprogram declaration" case. In that scenario
14450 -- the annotation must instantiate itself.
14451
14452 when Pragma_Contract_Cases => Contract_Cases : declare
14453 Spec_Id : Entity_Id;
14454 Subp_Decl : Node_Id;
14455 Subp_Spec : Node_Id;
14456
14457 begin
14458 GNAT_Pragma;
14459 Check_No_Identifiers;
14460 Check_Arg_Count (1);
14461
14462 -- Ensure the proper placement of the pragma. Contract_Cases must
14463 -- be associated with a subprogram declaration or a body that acts
14464 -- as a spec.
14465
14466 Subp_Decl :=
14467 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
14468
14469 -- Entry
14470
14471 if Nkind (Subp_Decl) = N_Entry_Declaration then
14472 null;
14473
14474 -- Generic subprogram
14475
14476 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
14477 null;
14478
14479 -- Body acts as spec
14480
14481 elsif Nkind (Subp_Decl) = N_Subprogram_Body
14482 and then No (Corresponding_Spec (Subp_Decl))
14483 then
14484 null;
14485
14486 -- Body stub acts as spec
14487
14488 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
14489 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
14490 then
14491 null;
14492
14493 -- Subprogram
14494
14495 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
14496 Subp_Spec := Specification (Subp_Decl);
14497
14498 -- Pragma Contract_Cases is forbidden on null procedures, as
14499 -- this may lead to potential ambiguities in behavior when
14500 -- interface null procedures are involved.
14501
14502 if Nkind (Subp_Spec) = N_Procedure_Specification
14503 and then Null_Present (Subp_Spec)
14504 then
14505 Error_Msg_N (Fix_Error
14506 ("pragma % cannot apply to null procedure"), N);
14507 return;
14508 end if;
14509
14510 else
14511 Pragma_Misplaced;
14512 return;
14513 end if;
14514
14515 Spec_Id := Unique_Defining_Entity (Subp_Decl);
14516
14517 -- A pragma that applies to a Ghost entity becomes Ghost for the
14518 -- purposes of legality checks and removal of ignored Ghost code.
14519
14520 Mark_Ghost_Pragma (N, Spec_Id);
14521 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
14522
14523 -- Chain the pragma on the contract for further processing by
14524 -- Analyze_Contract_Cases_In_Decl_Part.
14525
14526 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
14527
14528 -- Fully analyze the pragma when it appears inside an entry
14529 -- or subprogram body because it cannot benefit from forward
14530 -- references.
14531
14532 if Nkind (Subp_Decl) in N_Entry_Body
14533 | N_Subprogram_Body
14534 | N_Subprogram_Body_Stub
14535 then
14536 -- The legality checks of pragma Contract_Cases are affected by
14537 -- the SPARK mode in effect and the volatility of the context.
14538 -- Analyze all pragmas in a specific order.
14539
14540 Analyze_If_Present (Pragma_SPARK_Mode);
14541 Analyze_If_Present (Pragma_Volatile_Function);
14542 Analyze_Contract_Cases_In_Decl_Part (N);
14543 end if;
14544 end Contract_Cases;
14545
14546 ----------------
14547 -- Controlled --
14548 ----------------
14549
14550 -- pragma Controlled (first_subtype_LOCAL_NAME);
14551
14552 when Pragma_Controlled => Controlled : declare
14553 Arg : Node_Id;
14554
14555 begin
14556 Check_No_Identifiers;
14557 Check_Arg_Count (1);
14558 Check_Arg_Is_Local_Name (Arg1);
14559 Arg := Get_Pragma_Arg (Arg1);
14560
14561 if not Is_Entity_Name (Arg)
14562 or else not Is_Access_Type (Entity (Arg))
14563 then
14564 Error_Pragma_Arg ("pragma% requires access type", Arg1);
14565 else
14566 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
14567 end if;
14568 end Controlled;
14569
14570 ----------------
14571 -- Convention --
14572 ----------------
14573
14574 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
14575 -- [Entity =>] LOCAL_NAME);
14576
14577 when Pragma_Convention => Convention : declare
14578 C : Convention_Id;
14579 E : Entity_Id;
14580 pragma Warnings (Off, C);
14581 pragma Warnings (Off, E);
14582
14583 begin
14584 Check_Arg_Order ((Name_Convention, Name_Entity));
14585 Check_Ada_83_Warning;
14586 Check_Arg_Count (2);
14587 Process_Convention (C, E);
14588
14589 -- A pragma that applies to a Ghost entity becomes Ghost for the
14590 -- purposes of legality checks and removal of ignored Ghost code.
14591
14592 Mark_Ghost_Pragma (N, E);
14593 end Convention;
14594
14595 ---------------------------
14596 -- Convention_Identifier --
14597 ---------------------------
14598
14599 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
14600 -- [Convention =>] convention_IDENTIFIER);
14601
14602 when Pragma_Convention_Identifier => Convention_Identifier : declare
14603 Idnam : Name_Id;
14604 Cname : Name_Id;
14605
14606 begin
14607 GNAT_Pragma;
14608 Check_Arg_Order ((Name_Name, Name_Convention));
14609 Check_Arg_Count (2);
14610 Check_Optional_Identifier (Arg1, Name_Name);
14611 Check_Optional_Identifier (Arg2, Name_Convention);
14612 Check_Arg_Is_Identifier (Arg1);
14613 Check_Arg_Is_Identifier (Arg2);
14614 Idnam := Chars (Get_Pragma_Arg (Arg1));
14615 Cname := Chars (Get_Pragma_Arg (Arg2));
14616
14617 if Is_Convention_Name (Cname) then
14618 Record_Convention_Identifier
14619 (Idnam, Get_Convention_Id (Cname));
14620 else
14621 Error_Pragma_Arg
14622 ("second arg for % pragma must be convention", Arg2);
14623 end if;
14624 end Convention_Identifier;
14625
14626 ---------------
14627 -- CPP_Class --
14628 ---------------
14629
14630 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
14631
14632 when Pragma_CPP_Class =>
14633 GNAT_Pragma;
14634
14635 if Warn_On_Obsolescent_Feature then
14636 Error_Msg_N
14637 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
14638 & "effect; replace it by pragma import?j?", N);
14639 end if;
14640
14641 Check_Arg_Count (1);
14642
14643 Rewrite (N,
14644 Make_Pragma (Loc,
14645 Chars => Name_Import,
14646 Pragma_Argument_Associations => New_List (
14647 Make_Pragma_Argument_Association (Loc,
14648 Expression => Make_Identifier (Loc, Name_CPP)),
14649 New_Copy (First (Pragma_Argument_Associations (N))))));
14650 Analyze (N);
14651
14652 ---------------------
14653 -- CPP_Constructor --
14654 ---------------------
14655
14656 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
14657 -- [, [External_Name =>] static_string_EXPRESSION ]
14658 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14659
14660 when Pragma_CPP_Constructor => CPP_Constructor : declare
14661 Elmt : Elmt_Id;
14662 Id : Entity_Id;
14663 Def_Id : Entity_Id;
14664 Tag_Typ : Entity_Id;
14665
14666 begin
14667 GNAT_Pragma;
14668 Check_At_Least_N_Arguments (1);
14669 Check_At_Most_N_Arguments (3);
14670 Check_Optional_Identifier (Arg1, Name_Entity);
14671 Check_Arg_Is_Local_Name (Arg1);
14672
14673 Id := Get_Pragma_Arg (Arg1);
14674 Find_Program_Unit_Name (Id);
14675
14676 -- If we did not find the name, we are done
14677
14678 if Etype (Id) = Any_Type then
14679 return;
14680 end if;
14681
14682 Def_Id := Entity (Id);
14683
14684 -- Check if already defined as constructor
14685
14686 if Is_Constructor (Def_Id) then
14687 Error_Msg_N
14688 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
14689 return;
14690 end if;
14691
14692 if Ekind (Def_Id) = E_Function
14693 and then (Is_CPP_Class (Etype (Def_Id))
14694 or else (Is_Class_Wide_Type (Etype (Def_Id))
14695 and then
14696 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
14697 then
14698 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
14699 Error_Msg_N
14700 ("'C'P'P constructor must be defined in the scope of "
14701 & "its returned type", Arg1);
14702 end if;
14703
14704 if Arg_Count >= 2 then
14705 Set_Imported (Def_Id);
14706 Set_Is_Public (Def_Id);
14707 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
14708 end if;
14709
14710 Set_Has_Completion (Def_Id);
14711 Set_Is_Constructor (Def_Id);
14712 Set_Convention (Def_Id, Convention_CPP);
14713
14714 -- Imported C++ constructors are not dispatching primitives
14715 -- because in C++ they don't have a dispatch table slot.
14716 -- However, in Ada the constructor has the profile of a
14717 -- function that returns a tagged type and therefore it has
14718 -- been treated as a primitive operation during semantic
14719 -- analysis. We now remove it from the list of primitive
14720 -- operations of the type.
14721
14722 if Is_Tagged_Type (Etype (Def_Id))
14723 and then not Is_Class_Wide_Type (Etype (Def_Id))
14724 and then Is_Dispatching_Operation (Def_Id)
14725 then
14726 Tag_Typ := Etype (Def_Id);
14727
14728 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
14729 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
14730 Next_Elmt (Elmt);
14731 end loop;
14732
14733 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
14734 Set_Is_Dispatching_Operation (Def_Id, False);
14735 end if;
14736
14737 -- For backward compatibility, if the constructor returns a
14738 -- class wide type, and we internally change the return type to
14739 -- the corresponding root type.
14740
14741 if Is_Class_Wide_Type (Etype (Def_Id)) then
14742 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
14743 end if;
14744 else
14745 Error_Pragma_Arg
14746 ("pragma% requires function returning a 'C'P'P_Class type",
14747 Arg1);
14748 end if;
14749 end CPP_Constructor;
14750
14751 -----------------
14752 -- CPP_Virtual --
14753 -----------------
14754
14755 when Pragma_CPP_Virtual =>
14756 GNAT_Pragma;
14757
14758 if Warn_On_Obsolescent_Feature then
14759 Error_Msg_N
14760 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
14761 & "effect?j?", N);
14762 end if;
14763
14764 --------------------
14765 -- CUDA_Execute --
14766 --------------------
14767
14768 -- pragma CUDA_Execute (PROCEDURE_CALL_STATEMENT,
14769 -- EXPRESSION,
14770 -- EXPRESSION,
14771 -- [, EXPRESSION
14772 -- [, EXPRESSION]]);
14773
14774 when Pragma_CUDA_Execute => CUDA_Execute : declare
14775
14776 function Is_Acceptable_Dim3 (N : Node_Id) return Boolean;
14777 -- Returns True if N is an acceptable argument for CUDA_Execute,
14778 -- False otherwise.
14779
14780 ------------------------
14781 -- Is_Acceptable_Dim3 --
14782 ------------------------
14783
14784 function Is_Acceptable_Dim3 (N : Node_Id) return Boolean is
14785 Expr : Node_Id;
14786 begin
14787 if Is_RTE (Etype (N), RE_Dim3)
14788 or else Is_Integer_Type (Etype (N))
14789 then
14790 return True;
14791 end if;
14792
14793 if Nkind (N) = N_Aggregate
14794 and then List_Length (Expressions (N)) = 3
14795 then
14796 Expr := First (Expressions (N));
14797 while Present (Expr) loop
14798 Analyze_And_Resolve (Expr, Any_Integer);
14799 Next (Expr);
14800 end loop;
14801 return True;
14802 end if;
14803
14804 return False;
14805 end Is_Acceptable_Dim3;
14806
14807 -- Local variables
14808
14809 Block_Dimensions : constant Node_Id := Get_Pragma_Arg (Arg3);
14810 Grid_Dimensions : constant Node_Id := Get_Pragma_Arg (Arg2);
14811 Kernel_Call : constant Node_Id := Get_Pragma_Arg (Arg1);
14812 Shared_Memory : Node_Id;
14813 Stream : Node_Id;
14814
14815 -- Start of processing for CUDA_Execute
14816
14817 begin
14818 GNAT_Pragma;
14819 Check_At_Least_N_Arguments (3);
14820 Check_At_Most_N_Arguments (5);
14821
14822 Analyze_And_Resolve (Kernel_Call);
14823 if Nkind (Kernel_Call) /= N_Function_Call
14824 or else Etype (Kernel_Call) /= Standard_Void_Type
14825 then
14826 -- In `pragma CUDA_Execute (Kernel_Call (...), ...)`,
14827 -- GNAT sees Kernel_Call as an N_Function_Call since
14828 -- Kernel_Call "looks" like an expression. However, only
14829 -- procedures can be kernels, so to make things easier for the
14830 -- user the error message complains about Kernel_Call not being
14831 -- a procedure call.
14832
14833 Error_Msg_N ("first argument of & must be a procedure call", N);
14834 end if;
14835
14836 Analyze (Grid_Dimensions);
14837 if not Is_Acceptable_Dim3 (Grid_Dimensions) then
14838 Error_Msg_N
14839 ("second argument of & must be an Integer, Dim3 or aggregate "
14840 & "containing 3 Integers", N);
14841 end if;
14842
14843 Analyze (Block_Dimensions);
14844 if not Is_Acceptable_Dim3 (Block_Dimensions) then
14845 Error_Msg_N
14846 ("third argument of & must be an Integer, Dim3 or aggregate "
14847 & "containing 3 Integers", N);
14848 end if;
14849
14850 if Present (Arg4) then
14851 Shared_Memory := Get_Pragma_Arg (Arg4);
14852 Analyze_And_Resolve (Shared_Memory, Any_Integer);
14853
14854 if Present (Arg5) then
14855 Stream := Get_Pragma_Arg (Arg5);
14856 Analyze_And_Resolve (Stream, RTE (RE_Stream_T));
14857 end if;
14858 end if;
14859 end CUDA_Execute;
14860
14861 -----------------
14862 -- CUDA_Global --
14863 -----------------
14864
14865 -- pragma CUDA_Global (IDENTIFIER);
14866
14867 when Pragma_CUDA_Global => CUDA_Global : declare
14868 Arg_Node : Node_Id;
14869 Kernel_Proc : Entity_Id;
14870 Pack_Id : Entity_Id;
14871 begin
14872 GNAT_Pragma;
14873 Check_At_Least_N_Arguments (1);
14874 Check_At_Most_N_Arguments (1);
14875 Check_Optional_Identifier (Arg1, Name_Entity);
14876 Check_Arg_Is_Local_Name (Arg1);
14877
14878 Arg_Node := Get_Pragma_Arg (Arg1);
14879 Analyze (Arg_Node);
14880
14881 Kernel_Proc := Entity (Arg_Node);
14882 Pack_Id := Scope (Kernel_Proc);
14883
14884 if Ekind (Kernel_Proc) /= E_Procedure then
14885 Error_Msg_NE ("& must be a procedure", N, Kernel_Proc);
14886
14887 elsif Ekind (Pack_Id) /= E_Package
14888 or else not Is_Library_Level_Entity (Pack_Id)
14889 then
14890 Error_Msg_NE
14891 ("& must reside in a library-level package", N, Kernel_Proc);
14892
14893 else
14894 Set_Is_CUDA_Kernel (Kernel_Proc);
14895 end if;
14896 end CUDA_Global;
14897
14898 ----------------
14899 -- CPP_Vtable --
14900 ----------------
14901
14902 when Pragma_CPP_Vtable =>
14903 GNAT_Pragma;
14904
14905 if Warn_On_Obsolescent_Feature then
14906 Error_Msg_N
14907 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
14908 & "effect?j?", N);
14909 end if;
14910
14911 ---------
14912 -- CPU --
14913 ---------
14914
14915 -- pragma CPU (EXPRESSION);
14916
14917 when Pragma_CPU => CPU : declare
14918 P : constant Node_Id := Parent (N);
14919 Arg : Node_Id;
14920 Ent : Entity_Id;
14921
14922 begin
14923 Ada_2012_Pragma;
14924 Check_No_Identifiers;
14925 Check_Arg_Count (1);
14926 Arg := Get_Pragma_Arg (Arg1);
14927
14928 -- Subprogram case
14929
14930 if Nkind (P) = N_Subprogram_Body then
14931 Check_In_Main_Program;
14932
14933 Analyze_And_Resolve (Arg, Any_Integer);
14934
14935 Ent := Defining_Unit_Name (Specification (P));
14936
14937 if Nkind (Ent) = N_Defining_Program_Unit_Name then
14938 Ent := Defining_Identifier (Ent);
14939 end if;
14940
14941 -- Must be static
14942
14943 if not Is_OK_Static_Expression (Arg) then
14944 Flag_Non_Static_Expr
14945 ("main subprogram affinity is not static!", Arg);
14946 raise Pragma_Exit;
14947
14948 -- If constraint error, then we already signalled an error
14949
14950 elsif Raises_Constraint_Error (Arg) then
14951 null;
14952
14953 -- Otherwise check in range
14954
14955 else
14956 declare
14957 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
14958 -- This is the entity System.Multiprocessors.CPU_Range;
14959
14960 Val : constant Uint := Expr_Value (Arg);
14961
14962 begin
14963 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
14964 or else
14965 Val > Expr_Value (Type_High_Bound (CPU_Id))
14966 then
14967 Error_Pragma_Arg
14968 ("main subprogram CPU is out of range", Arg1);
14969 end if;
14970 end;
14971 end if;
14972
14973 Set_Main_CPU
14974 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
14975
14976 -- Task case
14977
14978 elsif Nkind (P) = N_Task_Definition then
14979 Ent := Defining_Identifier (Parent (P));
14980
14981 -- The expression must be analyzed in the special manner
14982 -- described in "Handling of Default and Per-Object
14983 -- Expressions" in sem.ads.
14984
14985 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
14986
14987 -- See comment in Sem_Ch13 about the following restrictions
14988
14989 if Is_OK_Static_Expression (Arg) then
14990 if Expr_Value (Arg) = Uint_0 then
14991 Check_Restriction (No_Tasks_Unassigned_To_CPU, N);
14992 end if;
14993 else
14994 Check_Restriction (No_Dynamic_CPU_Assignment, N);
14995 end if;
14996
14997 -- Anything else is incorrect
14998
14999 else
15000 Pragma_Misplaced;
15001 end if;
15002
15003 -- Check duplicate pragma before we chain the pragma in the Rep
15004 -- Item chain of Ent.
15005
15006 Check_Duplicate_Pragma (Ent);
15007 Record_Rep_Item (Ent, N);
15008 end CPU;
15009
15010 --------------------
15011 -- Deadline_Floor --
15012 --------------------
15013
15014 -- pragma Deadline_Floor (time_span_EXPRESSION);
15015
15016 when Pragma_Deadline_Floor => Deadline_Floor : declare
15017 P : constant Node_Id := Parent (N);
15018 Arg : Node_Id;
15019 Ent : Entity_Id;
15020
15021 begin
15022 GNAT_Pragma;
15023 Check_No_Identifiers;
15024 Check_Arg_Count (1);
15025
15026 Arg := Get_Pragma_Arg (Arg1);
15027
15028 -- The expression must be analyzed in the special manner described
15029 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
15030
15031 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
15032
15033 -- Only protected types allowed
15034
15035 if Nkind (P) /= N_Protected_Definition then
15036 Pragma_Misplaced;
15037
15038 else
15039 Ent := Defining_Identifier (Parent (P));
15040
15041 -- Check duplicate pragma before we chain the pragma in the Rep
15042 -- Item chain of Ent.
15043
15044 Check_Duplicate_Pragma (Ent);
15045 Record_Rep_Item (Ent, N);
15046 end if;
15047 end Deadline_Floor;
15048
15049 -----------
15050 -- Debug --
15051 -----------
15052
15053 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
15054
15055 when Pragma_Debug => Debug : declare
15056 Cond : Node_Id;
15057 Call : Node_Id;
15058
15059 begin
15060 GNAT_Pragma;
15061
15062 -- The condition for executing the call is that the expander
15063 -- is active and that we are not ignoring this debug pragma.
15064
15065 Cond :=
15066 New_Occurrence_Of
15067 (Boolean_Literals
15068 (Expander_Active and then not Is_Ignored (N)),
15069 Loc);
15070
15071 if not Is_Ignored (N) then
15072 Set_SCO_Pragma_Enabled (Loc);
15073 end if;
15074
15075 if Arg_Count = 2 then
15076 Cond :=
15077 Make_And_Then (Loc,
15078 Left_Opnd => Relocate_Node (Cond),
15079 Right_Opnd => Get_Pragma_Arg (Arg1));
15080 Call := Get_Pragma_Arg (Arg2);
15081 else
15082 Call := Get_Pragma_Arg (Arg1);
15083 end if;
15084
15085 if Nkind (Call) in N_Expanded_Name
15086 | N_Function_Call
15087 | N_Identifier
15088 | N_Indexed_Component
15089 | N_Selected_Component
15090 then
15091 -- If this pragma Debug comes from source, its argument was
15092 -- parsed as a name form (which is syntactically identical).
15093 -- In a generic context a parameterless call will be left as
15094 -- an expanded name (if global) or selected_component if local.
15095 -- Change it to a procedure call statement now.
15096
15097 Change_Name_To_Procedure_Call_Statement (Call);
15098
15099 elsif Nkind (Call) = N_Procedure_Call_Statement then
15100
15101 -- Already in the form of a procedure call statement: nothing
15102 -- to do (could happen in case of an internally generated
15103 -- pragma Debug).
15104
15105 null;
15106
15107 else
15108 -- All other cases: diagnose error
15109
15110 Error_Msg
15111 ("argument of pragma ""Debug"" is not procedure call",
15112 Sloc (Call));
15113 return;
15114 end if;
15115
15116 -- Rewrite into a conditional with an appropriate condition. We
15117 -- wrap the procedure call in a block so that overhead from e.g.
15118 -- use of the secondary stack does not generate execution overhead
15119 -- for suppressed conditions.
15120
15121 -- Normally the analysis that follows will freeze the subprogram
15122 -- being called. However, if the call is to a null procedure,
15123 -- we want to freeze it before creating the block, because the
15124 -- analysis that follows may be done with expansion disabled, in
15125 -- which case the body will not be generated, leading to spurious
15126 -- errors.
15127
15128 if Nkind (Call) = N_Procedure_Call_Statement
15129 and then Is_Entity_Name (Name (Call))
15130 then
15131 Analyze (Name (Call));
15132 Freeze_Before (N, Entity (Name (Call)));
15133 end if;
15134
15135 Rewrite (N,
15136 Make_Implicit_If_Statement (N,
15137 Condition => Cond,
15138 Then_Statements => New_List (
15139 Make_Block_Statement (Loc,
15140 Handled_Statement_Sequence =>
15141 Make_Handled_Sequence_Of_Statements (Loc,
15142 Statements => New_List (Relocate_Node (Call)))))));
15143 Analyze (N);
15144
15145 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
15146 -- after analysis of the normally rewritten node, to capture all
15147 -- references to entities, which avoids issuing wrong warnings
15148 -- about unused entities.
15149
15150 if GNATprove_Mode then
15151 Rewrite (N, Make_Null_Statement (Loc));
15152 end if;
15153 end Debug;
15154
15155 ------------------
15156 -- Debug_Policy --
15157 ------------------
15158
15159 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
15160
15161 when Pragma_Debug_Policy =>
15162 GNAT_Pragma;
15163 Check_Arg_Count (1);
15164 Check_No_Identifiers;
15165 Check_Arg_Is_Identifier (Arg1);
15166
15167 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
15168 -- rewrite it that way, and let the rest of the checking come
15169 -- from analyzing the rewritten pragma.
15170
15171 Rewrite (N,
15172 Make_Pragma (Loc,
15173 Chars => Name_Check_Policy,
15174 Pragma_Argument_Associations => New_List (
15175 Make_Pragma_Argument_Association (Loc,
15176 Expression => Make_Identifier (Loc, Name_Debug)),
15177
15178 Make_Pragma_Argument_Association (Loc,
15179 Expression => Get_Pragma_Arg (Arg1)))));
15180 Analyze (N);
15181
15182 -------------------------------
15183 -- Default_Initial_Condition --
15184 -------------------------------
15185
15186 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
15187
15188 when Pragma_Default_Initial_Condition => DIC : declare
15189 Discard : Boolean;
15190 Stmt : Node_Id;
15191 Typ : Entity_Id;
15192
15193 begin
15194 GNAT_Pragma;
15195 Check_No_Identifiers;
15196 Check_At_Most_N_Arguments (1);
15197
15198 Typ := Empty;
15199 Stmt := Prev (N);
15200 while Present (Stmt) loop
15201
15202 -- Skip prior pragmas, but check for duplicates
15203
15204 if Nkind (Stmt) = N_Pragma then
15205 if Pragma_Name (Stmt) = Pname then
15206 Duplication_Error
15207 (Prag => N,
15208 Prev => Stmt);
15209 raise Pragma_Exit;
15210 end if;
15211
15212 -- Skip internally generated code. Note that derived type
15213 -- declarations of untagged types with discriminants are
15214 -- rewritten as private type declarations.
15215
15216 elsif not Comes_From_Source (Stmt)
15217 and then Nkind (Stmt) /= N_Private_Type_Declaration
15218 then
15219 null;
15220
15221 -- The associated private type [extension] has been found, stop
15222 -- the search.
15223
15224 elsif Nkind (Stmt) in N_Private_Extension_Declaration
15225 | N_Private_Type_Declaration
15226 then
15227 Typ := Defining_Entity (Stmt);
15228 exit;
15229
15230 -- The pragma does not apply to a legal construct, issue an
15231 -- error and stop the analysis.
15232
15233 else
15234 Pragma_Misplaced;
15235 return;
15236 end if;
15237
15238 Stmt := Prev (Stmt);
15239 end loop;
15240
15241 -- The pragma does not apply to a legal construct, issue an error
15242 -- and stop the analysis.
15243
15244 if No (Typ) then
15245 Pragma_Misplaced;
15246 return;
15247 end if;
15248
15249 -- A pragma that applies to a Ghost entity becomes Ghost for the
15250 -- purposes of legality checks and removal of ignored Ghost code.
15251
15252 Mark_Ghost_Pragma (N, Typ);
15253
15254 -- The pragma signals that the type defines its own DIC assertion
15255 -- expression.
15256
15257 Set_Has_Own_DIC (Typ);
15258
15259 -- Chain the pragma on the rep item chain for further processing
15260
15261 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15262
15263 -- Create the declaration of the procedure which verifies the
15264 -- assertion expression of pragma DIC at runtime.
15265
15266 Build_DIC_Procedure_Declaration (Typ);
15267 end DIC;
15268
15269 ----------------------------------
15270 -- Default_Scalar_Storage_Order --
15271 ----------------------------------
15272
15273 -- pragma Default_Scalar_Storage_Order
15274 -- (High_Order_First | Low_Order_First);
15275
15276 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
15277 Default : Character;
15278
15279 begin
15280 GNAT_Pragma;
15281 Check_Arg_Count (1);
15282
15283 -- Default_Scalar_Storage_Order can appear as a configuration
15284 -- pragma, or in a declarative part of a package spec.
15285
15286 if not Is_Configuration_Pragma then
15287 Check_Is_In_Decl_Part_Or_Package_Spec;
15288 end if;
15289
15290 Check_No_Identifiers;
15291 Check_Arg_Is_One_Of
15292 (Arg1, Name_High_Order_First, Name_Low_Order_First);
15293 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15294 Default := Fold_Upper (Name_Buffer (1));
15295
15296 if not Support_Nondefault_SSO_On_Target
15297 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
15298 then
15299 if Warn_On_Unrecognized_Pragma then
15300 Error_Msg_N
15301 ("non-default Scalar_Storage_Order not supported "
15302 & "on target?g?", N);
15303 Error_Msg_N
15304 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
15305 end if;
15306
15307 -- Here set the specified default
15308
15309 else
15310 Opt.Default_SSO := Default;
15311 end if;
15312 end DSSO;
15313
15314 --------------------------
15315 -- Default_Storage_Pool --
15316 --------------------------
15317
15318 -- pragma Default_Storage_Pool (storage_pool_NAME | null | Standard);
15319
15320 when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
15321 Pool : Node_Id;
15322
15323 begin
15324 Ada_2012_Pragma;
15325 Check_Arg_Count (1);
15326
15327 -- Default_Storage_Pool can appear as a configuration pragma, or
15328 -- in a declarative part of a package spec.
15329
15330 if not Is_Configuration_Pragma then
15331 Check_Is_In_Decl_Part_Or_Package_Spec;
15332 end if;
15333
15334 if From_Aspect_Specification (N) then
15335 declare
15336 E : constant Entity_Id := Entity (Corresponding_Aspect (N));
15337 begin
15338 if not In_Open_Scopes (E) then
15339 Error_Msg_N
15340 ("aspect must apply to package or subprogram", N);
15341 end if;
15342 end;
15343 end if;
15344
15345 if Present (Arg1) then
15346 Pool := Get_Pragma_Arg (Arg1);
15347
15348 -- Case of Default_Storage_Pool (null);
15349
15350 if Nkind (Pool) = N_Null then
15351 Analyze (Pool);
15352
15353 -- This is an odd case, this is not really an expression,
15354 -- so we don't have a type for it. So just set the type to
15355 -- Empty.
15356
15357 Set_Etype (Pool, Empty);
15358
15359 -- Case of Default_Storage_Pool (Standard);
15360
15361 elsif Nkind (Pool) = N_Identifier
15362 and then Chars (Pool) = Name_Standard
15363 then
15364 Analyze (Pool);
15365
15366 if Entity (Pool) /= Standard_Standard then
15367 Error_Pragma_Arg
15368 ("package Standard is not directly visible", Arg1);
15369 end if;
15370
15371 -- Case of Default_Storage_Pool (storage_pool_NAME);
15372
15373 else
15374 -- If it's a configuration pragma, then the only allowed
15375 -- argument is "null".
15376
15377 if Is_Configuration_Pragma then
15378 Error_Pragma_Arg ("NULL or Standard expected", Arg1);
15379 end if;
15380
15381 -- The expected type for a non-"null" argument is
15382 -- Root_Storage_Pool'Class, and the pool must be a variable.
15383
15384 Analyze_And_Resolve
15385 (Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
15386
15387 if Is_Variable (Pool) then
15388
15389 -- A pragma that applies to a Ghost entity becomes Ghost
15390 -- for the purposes of legality checks and removal of
15391 -- ignored Ghost code.
15392
15393 Mark_Ghost_Pragma (N, Entity (Pool));
15394
15395 else
15396 Error_Pragma_Arg
15397 ("default storage pool must be a variable", Arg1);
15398 end if;
15399 end if;
15400
15401 -- Record the pool name (or null). Freeze.Freeze_Entity for an
15402 -- access type will use this information to set the appropriate
15403 -- attributes of the access type. If the pragma appears in a
15404 -- generic unit it is ignored, given that it may refer to a
15405 -- local entity.
15406
15407 if not Inside_A_Generic then
15408 Default_Pool := Pool;
15409 end if;
15410 end if;
15411 end Default_Storage_Pool;
15412
15413 -------------
15414 -- Depends --
15415 -------------
15416
15417 -- pragma Depends (DEPENDENCY_RELATION);
15418
15419 -- DEPENDENCY_RELATION ::=
15420 -- null
15421 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
15422
15423 -- DEPENDENCY_CLAUSE ::=
15424 -- OUTPUT_LIST =>[+] INPUT_LIST
15425 -- | NULL_DEPENDENCY_CLAUSE
15426
15427 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
15428
15429 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
15430
15431 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
15432
15433 -- OUTPUT ::= NAME | FUNCTION_RESULT
15434 -- INPUT ::= NAME
15435
15436 -- where FUNCTION_RESULT is a function Result attribute_reference
15437
15438 -- Characteristics:
15439
15440 -- * Analysis - The annotation undergoes initial checks to verify
15441 -- the legal placement and context. Secondary checks fully analyze
15442 -- the dependency clauses in:
15443
15444 -- Analyze_Depends_In_Decl_Part
15445
15446 -- * Expansion - None.
15447
15448 -- * Template - The annotation utilizes the generic template of the
15449 -- related subprogram [body] when it is:
15450
15451 -- aspect on subprogram declaration
15452 -- aspect on stand-alone subprogram body
15453 -- pragma on stand-alone subprogram body
15454
15455 -- The annotation must prepare its own template when it is:
15456
15457 -- pragma on subprogram declaration
15458
15459 -- * Globals - Capture of global references must occur after full
15460 -- analysis.
15461
15462 -- * Instance - The annotation is instantiated automatically when
15463 -- the related generic subprogram [body] is instantiated except for
15464 -- the "pragma on subprogram declaration" case. In that scenario
15465 -- the annotation must instantiate itself.
15466
15467 when Pragma_Depends => Depends : declare
15468 Legal : Boolean;
15469 Spec_Id : Entity_Id;
15470 Subp_Decl : Node_Id;
15471
15472 begin
15473 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
15474
15475 if Legal then
15476
15477 -- Chain the pragma on the contract for further processing by
15478 -- Analyze_Depends_In_Decl_Part.
15479
15480 Add_Contract_Item (N, Spec_Id);
15481
15482 -- Fully analyze the pragma when it appears inside an entry
15483 -- or subprogram body because it cannot benefit from forward
15484 -- references.
15485
15486 if Nkind (Subp_Decl) in N_Entry_Body
15487 | N_Subprogram_Body
15488 | N_Subprogram_Body_Stub
15489 then
15490 -- The legality checks of pragmas Depends and Global are
15491 -- affected by the SPARK mode in effect and the volatility
15492 -- of the context. In addition these two pragmas are subject
15493 -- to an inherent order:
15494
15495 -- 1) Global
15496 -- 2) Depends
15497
15498 -- Analyze all these pragmas in the order outlined above
15499
15500 Analyze_If_Present (Pragma_SPARK_Mode);
15501 Analyze_If_Present (Pragma_Volatile_Function);
15502 Analyze_If_Present (Pragma_Global);
15503 Analyze_Depends_In_Decl_Part (N);
15504 end if;
15505 end if;
15506 end Depends;
15507
15508 ---------------------
15509 -- Detect_Blocking --
15510 ---------------------
15511
15512 -- pragma Detect_Blocking;
15513
15514 when Pragma_Detect_Blocking =>
15515 Ada_2005_Pragma;
15516 Check_Arg_Count (0);
15517 Check_Valid_Configuration_Pragma;
15518 Detect_Blocking := True;
15519
15520 ------------------------------------
15521 -- Disable_Atomic_Synchronization --
15522 ------------------------------------
15523
15524 -- pragma Disable_Atomic_Synchronization [(Entity)];
15525
15526 when Pragma_Disable_Atomic_Synchronization =>
15527 GNAT_Pragma;
15528 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
15529
15530 -------------------
15531 -- Discard_Names --
15532 -------------------
15533
15534 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
15535
15536 when Pragma_Discard_Names => Discard_Names : declare
15537 E : Entity_Id;
15538 E_Id : Node_Id;
15539
15540 begin
15541 Check_Ada_83_Warning;
15542
15543 -- Deal with configuration pragma case
15544
15545 if Arg_Count = 0 and then Is_Configuration_Pragma then
15546 Global_Discard_Names := True;
15547 return;
15548
15549 -- Otherwise, check correct appropriate context
15550
15551 else
15552 Check_Is_In_Decl_Part_Or_Package_Spec;
15553
15554 if Arg_Count = 0 then
15555
15556 -- If there is no parameter, then from now on this pragma
15557 -- applies to any enumeration, exception or tagged type
15558 -- defined in the current declarative part, and recursively
15559 -- to any nested scope.
15560
15561 Set_Discard_Names (Current_Scope);
15562 return;
15563
15564 else
15565 Check_Arg_Count (1);
15566 Check_Optional_Identifier (Arg1, Name_On);
15567 Check_Arg_Is_Local_Name (Arg1);
15568
15569 E_Id := Get_Pragma_Arg (Arg1);
15570
15571 if Etype (E_Id) = Any_Type then
15572 return;
15573 end if;
15574
15575 E := Entity (E_Id);
15576
15577 -- A pragma that applies to a Ghost entity becomes Ghost for
15578 -- the purposes of legality checks and removal of ignored
15579 -- Ghost code.
15580
15581 Mark_Ghost_Pragma (N, E);
15582
15583 if (Is_First_Subtype (E)
15584 and then
15585 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
15586 or else Ekind (E) = E_Exception
15587 then
15588 Set_Discard_Names (E);
15589 Record_Rep_Item (E, N);
15590
15591 else
15592 Error_Pragma_Arg
15593 ("inappropriate entity for pragma%", Arg1);
15594 end if;
15595 end if;
15596 end if;
15597 end Discard_Names;
15598
15599 ------------------------
15600 -- Dispatching_Domain --
15601 ------------------------
15602
15603 -- pragma Dispatching_Domain (EXPRESSION);
15604
15605 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
15606 P : constant Node_Id := Parent (N);
15607 Arg : Node_Id;
15608 Ent : Entity_Id;
15609
15610 begin
15611 Ada_2012_Pragma;
15612 Check_No_Identifiers;
15613 Check_Arg_Count (1);
15614
15615 -- This pragma is born obsolete, but not the aspect
15616
15617 if not From_Aspect_Specification (N) then
15618 Check_Restriction
15619 (No_Obsolescent_Features, Pragma_Identifier (N));
15620 end if;
15621
15622 if Nkind (P) = N_Task_Definition then
15623 Arg := Get_Pragma_Arg (Arg1);
15624 Ent := Defining_Identifier (Parent (P));
15625
15626 -- A pragma that applies to a Ghost entity becomes Ghost for
15627 -- the purposes of legality checks and removal of ignored Ghost
15628 -- code.
15629
15630 Mark_Ghost_Pragma (N, Ent);
15631
15632 -- The expression must be analyzed in the special manner
15633 -- described in "Handling of Default and Per-Object
15634 -- Expressions" in sem.ads.
15635
15636 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
15637
15638 -- Check duplicate pragma before we chain the pragma in the Rep
15639 -- Item chain of Ent.
15640
15641 Check_Duplicate_Pragma (Ent);
15642 Record_Rep_Item (Ent, N);
15643
15644 -- Anything else is incorrect
15645
15646 else
15647 Pragma_Misplaced;
15648 end if;
15649 end Dispatching_Domain;
15650
15651 ---------------
15652 -- Elaborate --
15653 ---------------
15654
15655 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
15656
15657 when Pragma_Elaborate => Elaborate : declare
15658 Arg : Node_Id;
15659 Citem : Node_Id;
15660
15661 begin
15662 -- Pragma must be in context items list of a compilation unit
15663
15664 if not Is_In_Context_Clause then
15665 Pragma_Misplaced;
15666 end if;
15667
15668 -- Must be at least one argument
15669
15670 if Arg_Count = 0 then
15671 Error_Pragma ("pragma% requires at least one argument");
15672 end if;
15673
15674 -- In Ada 83 mode, there can be no items following it in the
15675 -- context list except other pragmas and implicit with clauses
15676 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
15677 -- placement rule does not apply.
15678
15679 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
15680 Citem := Next (N);
15681 while Present (Citem) loop
15682 if Nkind (Citem) = N_Pragma
15683 or else (Nkind (Citem) = N_With_Clause
15684 and then Implicit_With (Citem))
15685 then
15686 null;
15687 else
15688 Error_Pragma
15689 ("(Ada 83) pragma% must be at end of context clause");
15690 end if;
15691
15692 Next (Citem);
15693 end loop;
15694 end if;
15695
15696 -- Finally, the arguments must all be units mentioned in a with
15697 -- clause in the same context clause. Note we already checked (in
15698 -- Par.Prag) that the arguments are all identifiers or selected
15699 -- components.
15700
15701 Arg := Arg1;
15702 Outer : while Present (Arg) loop
15703 Citem := First (List_Containing (N));
15704 Inner : while Citem /= N loop
15705 if Nkind (Citem) = N_With_Clause
15706 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
15707 then
15708 Set_Elaborate_Present (Citem, True);
15709 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
15710
15711 -- With the pragma present, elaboration calls on
15712 -- subprograms from the named unit need no further
15713 -- checks, as long as the pragma appears in the current
15714 -- compilation unit. If the pragma appears in some unit
15715 -- in the context, there might still be a need for an
15716 -- Elaborate_All_Desirable from the current compilation
15717 -- to the named unit, so we keep the check enabled. This
15718 -- does not apply in SPARK mode, where we allow pragma
15719 -- Elaborate, but we don't trust it to be right so we
15720 -- will still insist on the Elaborate_All.
15721
15722 if Legacy_Elaboration_Checks
15723 and then In_Extended_Main_Source_Unit (N)
15724 and then SPARK_Mode /= On
15725 then
15726 Set_Suppress_Elaboration_Warnings
15727 (Entity (Name (Citem)));
15728 end if;
15729
15730 exit Inner;
15731 end if;
15732
15733 Next (Citem);
15734 end loop Inner;
15735
15736 if Citem = N then
15737 Error_Pragma_Arg
15738 ("argument of pragma% is not withed unit", Arg);
15739 end if;
15740
15741 Next (Arg);
15742 end loop Outer;
15743 end Elaborate;
15744
15745 -------------------
15746 -- Elaborate_All --
15747 -------------------
15748
15749 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
15750
15751 when Pragma_Elaborate_All => Elaborate_All : declare
15752 Arg : Node_Id;
15753 Citem : Node_Id;
15754
15755 begin
15756 Check_Ada_83_Warning;
15757
15758 -- Pragma must be in context items list of a compilation unit
15759
15760 if not Is_In_Context_Clause then
15761 Pragma_Misplaced;
15762 end if;
15763
15764 -- Must be at least one argument
15765
15766 if Arg_Count = 0 then
15767 Error_Pragma ("pragma% requires at least one argument");
15768 end if;
15769
15770 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
15771 -- have to appear at the end of the context clause, but may
15772 -- appear mixed in with other items, even in Ada 83 mode.
15773
15774 -- Final check: the arguments must all be units mentioned in
15775 -- a with clause in the same context clause. Note that we
15776 -- already checked (in Par.Prag) that all the arguments are
15777 -- either identifiers or selected components.
15778
15779 Arg := Arg1;
15780 Outr : while Present (Arg) loop
15781 Citem := First (List_Containing (N));
15782 Innr : while Citem /= N loop
15783 if Nkind (Citem) = N_With_Clause
15784 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
15785 then
15786 Set_Elaborate_All_Present (Citem, True);
15787 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
15788
15789 -- Suppress warnings and elaboration checks on the named
15790 -- unit if the pragma is in the current compilation, as
15791 -- for pragma Elaborate.
15792
15793 if Legacy_Elaboration_Checks
15794 and then In_Extended_Main_Source_Unit (N)
15795 then
15796 Set_Suppress_Elaboration_Warnings
15797 (Entity (Name (Citem)));
15798 end if;
15799
15800 exit Innr;
15801 end if;
15802
15803 Next (Citem);
15804 end loop Innr;
15805
15806 if Citem = N then
15807 Set_Error_Posted (N);
15808 Error_Pragma_Arg
15809 ("argument of pragma% is not withed unit", Arg);
15810 end if;
15811
15812 Next (Arg);
15813 end loop Outr;
15814 end Elaborate_All;
15815
15816 --------------------
15817 -- Elaborate_Body --
15818 --------------------
15819
15820 -- pragma Elaborate_Body [( library_unit_NAME )];
15821
15822 when Pragma_Elaborate_Body => Elaborate_Body : declare
15823 Cunit_Node : Node_Id;
15824 Cunit_Ent : Entity_Id;
15825
15826 begin
15827 Check_Ada_83_Warning;
15828 Check_Valid_Library_Unit_Pragma;
15829
15830 if Nkind (N) = N_Null_Statement then
15831 return;
15832 end if;
15833
15834 Cunit_Node := Cunit (Current_Sem_Unit);
15835 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15836
15837 -- A pragma that applies to a Ghost entity becomes Ghost for the
15838 -- purposes of legality checks and removal of ignored Ghost code.
15839
15840 Mark_Ghost_Pragma (N, Cunit_Ent);
15841
15842 if Nkind (Unit (Cunit_Node)) in
15843 N_Package_Body | N_Subprogram_Body
15844 then
15845 Error_Pragma ("pragma% must refer to a spec, not a body");
15846 else
15847 Set_Body_Required (Cunit_Node);
15848 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
15849
15850 -- If we are in dynamic elaboration mode, then we suppress
15851 -- elaboration warnings for the unit, since it is definitely
15852 -- fine NOT to do dynamic checks at the first level (and such
15853 -- checks will be suppressed because no elaboration boolean
15854 -- is created for Elaborate_Body packages).
15855 --
15856 -- But in the static model of elaboration, Elaborate_Body is
15857 -- definitely NOT good enough to ensure elaboration safety on
15858 -- its own, since the body may WITH other units that are not
15859 -- safe from an elaboration point of view, so a client must
15860 -- still do an Elaborate_All on such units.
15861 --
15862 -- Debug flag -gnatdD restores the old behavior of 3.13, where
15863 -- Elaborate_Body always suppressed elab warnings.
15864
15865 if Legacy_Elaboration_Checks
15866 and then (Dynamic_Elaboration_Checks or Debug_Flag_DD)
15867 then
15868 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
15869 end if;
15870 end if;
15871 end Elaborate_Body;
15872
15873 ------------------------
15874 -- Elaboration_Checks --
15875 ------------------------
15876
15877 -- pragma Elaboration_Checks (Static | Dynamic);
15878
15879 when Pragma_Elaboration_Checks => Elaboration_Checks : declare
15880 procedure Check_Duplicate_Elaboration_Checks_Pragma;
15881 -- Emit an error if the current context list already contains
15882 -- a previous Elaboration_Checks pragma. This routine raises
15883 -- Pragma_Exit if a duplicate is found.
15884
15885 procedure Ignore_Elaboration_Checks_Pragma;
15886 -- Warn that the effects of the pragma are ignored. This routine
15887 -- raises Pragma_Exit.
15888
15889 -----------------------------------------------
15890 -- Check_Duplicate_Elaboration_Checks_Pragma --
15891 -----------------------------------------------
15892
15893 procedure Check_Duplicate_Elaboration_Checks_Pragma is
15894 Item : Node_Id;
15895
15896 begin
15897 Item := Prev (N);
15898 while Present (Item) loop
15899 if Nkind (Item) = N_Pragma
15900 and then Pragma_Name (Item) = Name_Elaboration_Checks
15901 then
15902 Duplication_Error
15903 (Prag => N,
15904 Prev => Item);
15905 raise Pragma_Exit;
15906 end if;
15907
15908 Prev (Item);
15909 end loop;
15910 end Check_Duplicate_Elaboration_Checks_Pragma;
15911
15912 --------------------------------------
15913 -- Ignore_Elaboration_Checks_Pragma --
15914 --------------------------------------
15915
15916 procedure Ignore_Elaboration_Checks_Pragma is
15917 begin
15918 Error_Msg_Name_1 := Pname;
15919 Error_Msg_N ("??effects of pragma % are ignored", N);
15920 Error_Msg_N
15921 ("\place pragma on initial declaration of library unit", N);
15922
15923 raise Pragma_Exit;
15924 end Ignore_Elaboration_Checks_Pragma;
15925
15926 -- Local variables
15927
15928 Context : constant Node_Id := Parent (N);
15929 Unt : Node_Id;
15930
15931 -- Start of processing for Elaboration_Checks
15932
15933 begin
15934 GNAT_Pragma;
15935 Check_Arg_Count (1);
15936 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
15937
15938 -- The pragma appears in a configuration file
15939
15940 if No (Context) then
15941 Check_Valid_Configuration_Pragma;
15942 Check_Duplicate_Elaboration_Checks_Pragma;
15943
15944 -- The pragma acts as a configuration pragma in a compilation unit
15945
15946 -- pragma Elaboration_Checks (...);
15947 -- package Pack is ...;
15948
15949 elsif Nkind (Context) = N_Compilation_Unit
15950 and then List_Containing (N) = Context_Items (Context)
15951 then
15952 Check_Valid_Configuration_Pragma;
15953 Check_Duplicate_Elaboration_Checks_Pragma;
15954
15955 Unt := Unit (Context);
15956
15957 -- The pragma must appear on the initial declaration of a unit.
15958 -- If this is not the case, warn that the effects of the pragma
15959 -- are ignored.
15960
15961 if Nkind (Unt) = N_Package_Body then
15962 Ignore_Elaboration_Checks_Pragma;
15963
15964 -- Check the Acts_As_Spec flag of the compilation units itself
15965 -- to determine whether the subprogram body completes since it
15966 -- has not been analyzed yet. This is safe because compilation
15967 -- units are not overloadable.
15968
15969 elsif Nkind (Unt) = N_Subprogram_Body
15970 and then not Acts_As_Spec (Context)
15971 then
15972 Ignore_Elaboration_Checks_Pragma;
15973
15974 elsif Nkind (Unt) = N_Subunit then
15975 Ignore_Elaboration_Checks_Pragma;
15976 end if;
15977
15978 -- Otherwise the pragma does not appear at the configuration level
15979 -- and is illegal.
15980
15981 else
15982 Pragma_Misplaced;
15983 end if;
15984
15985 -- At this point the pragma is not a duplicate, and appears in the
15986 -- proper context. Set the elaboration model in effect.
15987
15988 Dynamic_Elaboration_Checks :=
15989 Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic;
15990 end Elaboration_Checks;
15991
15992 ---------------
15993 -- Eliminate --
15994 ---------------
15995
15996 -- pragma Eliminate (
15997 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
15998 -- [Entity =>] IDENTIFIER |
15999 -- SELECTED_COMPONENT |
16000 -- STRING_LITERAL]
16001 -- [, Source_Location => SOURCE_TRACE]);
16002
16003 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
16004 -- SOURCE_TRACE ::= STRING_LITERAL
16005
16006 when Pragma_Eliminate => Eliminate : declare
16007 Args : Args_List (1 .. 5);
16008 Names : constant Name_List (1 .. 5) := (
16009 Name_Unit_Name,
16010 Name_Entity,
16011 Name_Parameter_Types,
16012 Name_Result_Type,
16013 Name_Source_Location);
16014
16015 -- Note : Parameter_Types and Result_Type are leftovers from
16016 -- prior implementations of the pragma. They are not generated
16017 -- by the gnatelim tool, and play no role in selecting which
16018 -- of a set of overloaded names is chosen for elimination.
16019
16020 Unit_Name : Node_Id renames Args (1);
16021 Entity : Node_Id renames Args (2);
16022 Parameter_Types : Node_Id renames Args (3);
16023 Result_Type : Node_Id renames Args (4);
16024 Source_Location : Node_Id renames Args (5);
16025
16026 begin
16027 GNAT_Pragma;
16028 Check_Valid_Configuration_Pragma;
16029 Gather_Associations (Names, Args);
16030
16031 if No (Unit_Name) then
16032 Error_Pragma ("missing Unit_Name argument for pragma%");
16033 end if;
16034
16035 if No (Entity)
16036 and then (Present (Parameter_Types)
16037 or else
16038 Present (Result_Type)
16039 or else
16040 Present (Source_Location))
16041 then
16042 Error_Pragma ("missing Entity argument for pragma%");
16043 end if;
16044
16045 if (Present (Parameter_Types)
16046 or else
16047 Present (Result_Type))
16048 and then
16049 Present (Source_Location)
16050 then
16051 Error_Pragma
16052 ("parameter profile and source location cannot be used "
16053 & "together in pragma%");
16054 end if;
16055
16056 Process_Eliminate_Pragma
16057 (N,
16058 Unit_Name,
16059 Entity,
16060 Parameter_Types,
16061 Result_Type,
16062 Source_Location);
16063 end Eliminate;
16064
16065 -----------------------------------
16066 -- Enable_Atomic_Synchronization --
16067 -----------------------------------
16068
16069 -- pragma Enable_Atomic_Synchronization [(Entity)];
16070
16071 when Pragma_Enable_Atomic_Synchronization =>
16072 GNAT_Pragma;
16073 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
16074
16075 ------------
16076 -- Export --
16077 ------------
16078
16079 -- pragma Export (
16080 -- [ Convention =>] convention_IDENTIFIER,
16081 -- [ Entity =>] LOCAL_NAME
16082 -- [, [External_Name =>] static_string_EXPRESSION ]
16083 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16084
16085 when Pragma_Export => Export : declare
16086 C : Convention_Id;
16087 Def_Id : Entity_Id;
16088
16089 pragma Warnings (Off, C);
16090
16091 begin
16092 Check_Ada_83_Warning;
16093 Check_Arg_Order
16094 ((Name_Convention,
16095 Name_Entity,
16096 Name_External_Name,
16097 Name_Link_Name));
16098
16099 Check_At_Least_N_Arguments (2);
16100 Check_At_Most_N_Arguments (4);
16101
16102 -- In Relaxed_RM_Semantics, support old Ada 83 style:
16103 -- pragma Export (Entity, "external name");
16104
16105 if Relaxed_RM_Semantics
16106 and then Arg_Count = 2
16107 and then Nkind (Expression (Arg2)) = N_String_Literal
16108 then
16109 C := Convention_C;
16110 Def_Id := Get_Pragma_Arg (Arg1);
16111 Analyze (Def_Id);
16112
16113 if not Is_Entity_Name (Def_Id) then
16114 Error_Pragma_Arg ("entity name required", Arg1);
16115 end if;
16116
16117 Def_Id := Entity (Def_Id);
16118 Set_Exported (Def_Id, Arg1);
16119
16120 else
16121 Process_Convention (C, Def_Id);
16122
16123 -- A pragma that applies to a Ghost entity becomes Ghost for
16124 -- the purposes of legality checks and removal of ignored Ghost
16125 -- code.
16126
16127 Mark_Ghost_Pragma (N, Def_Id);
16128
16129 if Ekind (Def_Id) /= E_Constant then
16130 Note_Possible_Modification
16131 (Get_Pragma_Arg (Arg2), Sure => False);
16132 end if;
16133
16134 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
16135 Set_Exported (Def_Id, Arg2);
16136 end if;
16137
16138 -- If the entity is a deferred constant, propagate the information
16139 -- to the full view, because gigi elaborates the full view only.
16140
16141 if Ekind (Def_Id) = E_Constant
16142 and then Present (Full_View (Def_Id))
16143 then
16144 declare
16145 Id2 : constant Entity_Id := Full_View (Def_Id);
16146 begin
16147 Set_Is_Exported (Id2, Is_Exported (Def_Id));
16148 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
16149 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
16150 end;
16151 end if;
16152 end Export;
16153
16154 ---------------------
16155 -- Export_Function --
16156 ---------------------
16157
16158 -- pragma Export_Function (
16159 -- [Internal =>] LOCAL_NAME
16160 -- [, [External =>] EXTERNAL_SYMBOL]
16161 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16162 -- [, [Result_Type =>] TYPE_DESIGNATOR]
16163 -- [, [Mechanism =>] MECHANISM]
16164 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
16165
16166 -- EXTERNAL_SYMBOL ::=
16167 -- IDENTIFIER
16168 -- | static_string_EXPRESSION
16169
16170 -- PARAMETER_TYPES ::=
16171 -- null
16172 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16173
16174 -- TYPE_DESIGNATOR ::=
16175 -- subtype_NAME
16176 -- | subtype_Name ' Access
16177
16178 -- MECHANISM ::=
16179 -- MECHANISM_NAME
16180 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16181
16182 -- MECHANISM_ASSOCIATION ::=
16183 -- [formal_parameter_NAME =>] MECHANISM_NAME
16184
16185 -- MECHANISM_NAME ::=
16186 -- Value
16187 -- | Reference
16188
16189 when Pragma_Export_Function => Export_Function : declare
16190 Args : Args_List (1 .. 6);
16191 Names : constant Name_List (1 .. 6) := (
16192 Name_Internal,
16193 Name_External,
16194 Name_Parameter_Types,
16195 Name_Result_Type,
16196 Name_Mechanism,
16197 Name_Result_Mechanism);
16198
16199 Internal : Node_Id renames Args (1);
16200 External : Node_Id renames Args (2);
16201 Parameter_Types : Node_Id renames Args (3);
16202 Result_Type : Node_Id renames Args (4);
16203 Mechanism : Node_Id renames Args (5);
16204 Result_Mechanism : Node_Id renames Args (6);
16205
16206 begin
16207 GNAT_Pragma;
16208 Gather_Associations (Names, Args);
16209 Process_Extended_Import_Export_Subprogram_Pragma (
16210 Arg_Internal => Internal,
16211 Arg_External => External,
16212 Arg_Parameter_Types => Parameter_Types,
16213 Arg_Result_Type => Result_Type,
16214 Arg_Mechanism => Mechanism,
16215 Arg_Result_Mechanism => Result_Mechanism);
16216 end Export_Function;
16217
16218 -------------------
16219 -- Export_Object --
16220 -------------------
16221
16222 -- pragma Export_Object (
16223 -- [Internal =>] LOCAL_NAME
16224 -- [, [External =>] EXTERNAL_SYMBOL]
16225 -- [, [Size =>] EXTERNAL_SYMBOL]);
16226
16227 -- EXTERNAL_SYMBOL ::=
16228 -- IDENTIFIER
16229 -- | static_string_EXPRESSION
16230
16231 -- PARAMETER_TYPES ::=
16232 -- null
16233 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16234
16235 -- TYPE_DESIGNATOR ::=
16236 -- subtype_NAME
16237 -- | subtype_Name ' Access
16238
16239 -- MECHANISM ::=
16240 -- MECHANISM_NAME
16241 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16242
16243 -- MECHANISM_ASSOCIATION ::=
16244 -- [formal_parameter_NAME =>] MECHANISM_NAME
16245
16246 -- MECHANISM_NAME ::=
16247 -- Value
16248 -- | Reference
16249
16250 when Pragma_Export_Object => Export_Object : declare
16251 Args : Args_List (1 .. 3);
16252 Names : constant Name_List (1 .. 3) := (
16253 Name_Internal,
16254 Name_External,
16255 Name_Size);
16256
16257 Internal : Node_Id renames Args (1);
16258 External : Node_Id renames Args (2);
16259 Size : Node_Id renames Args (3);
16260
16261 begin
16262 GNAT_Pragma;
16263 Gather_Associations (Names, Args);
16264 Process_Extended_Import_Export_Object_Pragma (
16265 Arg_Internal => Internal,
16266 Arg_External => External,
16267 Arg_Size => Size);
16268 end Export_Object;
16269
16270 ----------------------
16271 -- Export_Procedure --
16272 ----------------------
16273
16274 -- pragma Export_Procedure (
16275 -- [Internal =>] LOCAL_NAME
16276 -- [, [External =>] EXTERNAL_SYMBOL]
16277 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16278 -- [, [Mechanism =>] MECHANISM]);
16279
16280 -- EXTERNAL_SYMBOL ::=
16281 -- IDENTIFIER
16282 -- | static_string_EXPRESSION
16283
16284 -- PARAMETER_TYPES ::=
16285 -- null
16286 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16287
16288 -- TYPE_DESIGNATOR ::=
16289 -- subtype_NAME
16290 -- | subtype_Name ' Access
16291
16292 -- MECHANISM ::=
16293 -- MECHANISM_NAME
16294 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16295
16296 -- MECHANISM_ASSOCIATION ::=
16297 -- [formal_parameter_NAME =>] MECHANISM_NAME
16298
16299 -- MECHANISM_NAME ::=
16300 -- Value
16301 -- | Reference
16302
16303 when Pragma_Export_Procedure => Export_Procedure : declare
16304 Args : Args_List (1 .. 4);
16305 Names : constant Name_List (1 .. 4) := (
16306 Name_Internal,
16307 Name_External,
16308 Name_Parameter_Types,
16309 Name_Mechanism);
16310
16311 Internal : Node_Id renames Args (1);
16312 External : Node_Id renames Args (2);
16313 Parameter_Types : Node_Id renames Args (3);
16314 Mechanism : Node_Id renames Args (4);
16315
16316 begin
16317 GNAT_Pragma;
16318 Gather_Associations (Names, Args);
16319 Process_Extended_Import_Export_Subprogram_Pragma (
16320 Arg_Internal => Internal,
16321 Arg_External => External,
16322 Arg_Parameter_Types => Parameter_Types,
16323 Arg_Mechanism => Mechanism);
16324 end Export_Procedure;
16325
16326 ------------------
16327 -- Export_Value --
16328 ------------------
16329
16330 -- pragma Export_Value (
16331 -- [Value =>] static_integer_EXPRESSION,
16332 -- [Link_Name =>] static_string_EXPRESSION);
16333
16334 when Pragma_Export_Value =>
16335 GNAT_Pragma;
16336 Check_Arg_Order ((Name_Value, Name_Link_Name));
16337 Check_Arg_Count (2);
16338
16339 Check_Optional_Identifier (Arg1, Name_Value);
16340 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
16341
16342 Check_Optional_Identifier (Arg2, Name_Link_Name);
16343 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16344
16345 -----------------------------
16346 -- Export_Valued_Procedure --
16347 -----------------------------
16348
16349 -- pragma Export_Valued_Procedure (
16350 -- [Internal =>] LOCAL_NAME
16351 -- [, [External =>] EXTERNAL_SYMBOL,]
16352 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16353 -- [, [Mechanism =>] MECHANISM]);
16354
16355 -- EXTERNAL_SYMBOL ::=
16356 -- IDENTIFIER
16357 -- | static_string_EXPRESSION
16358
16359 -- PARAMETER_TYPES ::=
16360 -- null
16361 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16362
16363 -- TYPE_DESIGNATOR ::=
16364 -- subtype_NAME
16365 -- | subtype_Name ' Access
16366
16367 -- MECHANISM ::=
16368 -- MECHANISM_NAME
16369 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16370
16371 -- MECHANISM_ASSOCIATION ::=
16372 -- [formal_parameter_NAME =>] MECHANISM_NAME
16373
16374 -- MECHANISM_NAME ::=
16375 -- Value
16376 -- | Reference
16377
16378 when Pragma_Export_Valued_Procedure =>
16379 Export_Valued_Procedure : declare
16380 Args : Args_List (1 .. 4);
16381 Names : constant Name_List (1 .. 4) := (
16382 Name_Internal,
16383 Name_External,
16384 Name_Parameter_Types,
16385 Name_Mechanism);
16386
16387 Internal : Node_Id renames Args (1);
16388 External : Node_Id renames Args (2);
16389 Parameter_Types : Node_Id renames Args (3);
16390 Mechanism : Node_Id renames Args (4);
16391
16392 begin
16393 GNAT_Pragma;
16394 Gather_Associations (Names, Args);
16395 Process_Extended_Import_Export_Subprogram_Pragma (
16396 Arg_Internal => Internal,
16397 Arg_External => External,
16398 Arg_Parameter_Types => Parameter_Types,
16399 Arg_Mechanism => Mechanism);
16400 end Export_Valued_Procedure;
16401
16402 -------------------
16403 -- Extend_System --
16404 -------------------
16405
16406 -- pragma Extend_System ([Name =>] Identifier);
16407
16408 when Pragma_Extend_System =>
16409 GNAT_Pragma;
16410 Check_Valid_Configuration_Pragma;
16411 Check_Arg_Count (1);
16412 Check_Optional_Identifier (Arg1, Name_Name);
16413 Check_Arg_Is_Identifier (Arg1);
16414
16415 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16416
16417 if Name_Len > 4
16418 and then Name_Buffer (1 .. 4) = "aux_"
16419 then
16420 if Present (System_Extend_Pragma_Arg) then
16421 if Chars (Get_Pragma_Arg (Arg1)) =
16422 Chars (Expression (System_Extend_Pragma_Arg))
16423 then
16424 null;
16425 else
16426 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
16427 Error_Pragma ("pragma% conflicts with that #");
16428 end if;
16429
16430 else
16431 System_Extend_Pragma_Arg := Arg1;
16432
16433 if not GNAT_Mode then
16434 System_Extend_Unit := Arg1;
16435 end if;
16436 end if;
16437 else
16438 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
16439 end if;
16440
16441 ------------------------
16442 -- Extensions_Allowed --
16443 ------------------------
16444
16445 -- pragma Extensions_Allowed (ON | OFF);
16446
16447 when Pragma_Extensions_Allowed =>
16448 GNAT_Pragma;
16449 Check_Arg_Count (1);
16450 Check_No_Identifiers;
16451 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16452
16453 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
16454 Extensions_Allowed := True;
16455 Ada_Version := Ada_Version_Type'Last;
16456
16457 else
16458 Extensions_Allowed := False;
16459 Ada_Version := Ada_Version_Explicit;
16460 Ada_Version_Pragma := Empty;
16461 end if;
16462
16463 ------------------------
16464 -- Extensions_Visible --
16465 ------------------------
16466
16467 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
16468
16469 -- Characteristics:
16470
16471 -- * Analysis - The annotation is fully analyzed immediately upon
16472 -- elaboration as its expression must be static.
16473
16474 -- * Expansion - None.
16475
16476 -- * Template - The annotation utilizes the generic template of the
16477 -- related subprogram [body] when it is:
16478
16479 -- aspect on subprogram declaration
16480 -- aspect on stand-alone subprogram body
16481 -- pragma on stand-alone subprogram body
16482
16483 -- The annotation must prepare its own template when it is:
16484
16485 -- pragma on subprogram declaration
16486
16487 -- * Globals - Capture of global references must occur after full
16488 -- analysis.
16489
16490 -- * Instance - The annotation is instantiated automatically when
16491 -- the related generic subprogram [body] is instantiated except for
16492 -- the "pragma on subprogram declaration" case. In that scenario
16493 -- the annotation must instantiate itself.
16494
16495 when Pragma_Extensions_Visible => Extensions_Visible : declare
16496 Formal : Entity_Id;
16497 Has_OK_Formal : Boolean := False;
16498 Spec_Id : Entity_Id;
16499 Subp_Decl : Node_Id;
16500
16501 begin
16502 GNAT_Pragma;
16503 Check_No_Identifiers;
16504 Check_At_Most_N_Arguments (1);
16505
16506 Subp_Decl :=
16507 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
16508
16509 -- Abstract subprogram declaration
16510
16511 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
16512 null;
16513
16514 -- Generic subprogram declaration
16515
16516 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
16517 null;
16518
16519 -- Body acts as spec
16520
16521 elsif Nkind (Subp_Decl) = N_Subprogram_Body
16522 and then No (Corresponding_Spec (Subp_Decl))
16523 then
16524 null;
16525
16526 -- Body stub acts as spec
16527
16528 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
16529 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
16530 then
16531 null;
16532
16533 -- Subprogram declaration
16534
16535 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
16536 null;
16537
16538 -- Otherwise the pragma is associated with an illegal construct
16539
16540 else
16541 Error_Pragma ("pragma % must apply to a subprogram");
16542 return;
16543 end if;
16544
16545 -- Mark the pragma as Ghost if the related subprogram is also
16546 -- Ghost. This also ensures that any expansion performed further
16547 -- below will produce Ghost nodes.
16548
16549 Spec_Id := Unique_Defining_Entity (Subp_Decl);
16550 Mark_Ghost_Pragma (N, Spec_Id);
16551
16552 -- Chain the pragma on the contract for completeness
16553
16554 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
16555
16556 -- The legality checks of pragma Extension_Visible are affected
16557 -- by the SPARK mode in effect. Analyze all pragmas in specific
16558 -- order.
16559
16560 Analyze_If_Present (Pragma_SPARK_Mode);
16561
16562 -- Examine the formals of the related subprogram
16563
16564 Formal := First_Formal (Spec_Id);
16565 while Present (Formal) loop
16566
16567 -- At least one of the formals is of a specific tagged type,
16568 -- the pragma is legal.
16569
16570 if Is_Specific_Tagged_Type (Etype (Formal)) then
16571 Has_OK_Formal := True;
16572 exit;
16573
16574 -- A generic subprogram with at least one formal of a private
16575 -- type ensures the legality of the pragma because the actual
16576 -- may be specifically tagged. Note that this is verified by
16577 -- the check above at instantiation time.
16578
16579 elsif Is_Private_Type (Etype (Formal))
16580 and then Is_Generic_Type (Etype (Formal))
16581 then
16582 Has_OK_Formal := True;
16583 exit;
16584 end if;
16585
16586 Next_Formal (Formal);
16587 end loop;
16588
16589 if not Has_OK_Formal then
16590 Error_Msg_Name_1 := Pname;
16591 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
16592 Error_Msg_NE
16593 ("\subprogram & lacks parameter of specific tagged or "
16594 & "generic private type", N, Spec_Id);
16595
16596 return;
16597 end if;
16598
16599 -- Analyze the Boolean expression (if any)
16600
16601 if Present (Arg1) then
16602 Check_Static_Boolean_Expression
16603 (Expression (Get_Argument (N, Spec_Id)));
16604 end if;
16605 end Extensions_Visible;
16606
16607 --------------
16608 -- External --
16609 --------------
16610
16611 -- pragma External (
16612 -- [ Convention =>] convention_IDENTIFIER,
16613 -- [ Entity =>] LOCAL_NAME
16614 -- [, [External_Name =>] static_string_EXPRESSION ]
16615 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16616
16617 when Pragma_External => External : declare
16618 C : Convention_Id;
16619 E : Entity_Id;
16620 pragma Warnings (Off, C);
16621
16622 begin
16623 GNAT_Pragma;
16624 Check_Arg_Order
16625 ((Name_Convention,
16626 Name_Entity,
16627 Name_External_Name,
16628 Name_Link_Name));
16629 Check_At_Least_N_Arguments (2);
16630 Check_At_Most_N_Arguments (4);
16631 Process_Convention (C, E);
16632
16633 -- A pragma that applies to a Ghost entity becomes Ghost for the
16634 -- purposes of legality checks and removal of ignored Ghost code.
16635
16636 Mark_Ghost_Pragma (N, E);
16637
16638 Note_Possible_Modification
16639 (Get_Pragma_Arg (Arg2), Sure => False);
16640 Process_Interface_Name (E, Arg3, Arg4, N);
16641 Set_Exported (E, Arg2);
16642 end External;
16643
16644 --------------------------
16645 -- External_Name_Casing --
16646 --------------------------
16647
16648 -- pragma External_Name_Casing (
16649 -- UPPERCASE | LOWERCASE
16650 -- [, AS_IS | UPPERCASE | LOWERCASE]);
16651
16652 when Pragma_External_Name_Casing =>
16653 GNAT_Pragma;
16654 Check_No_Identifiers;
16655
16656 if Arg_Count = 2 then
16657 Check_Arg_Is_One_Of
16658 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
16659
16660 case Chars (Get_Pragma_Arg (Arg2)) is
16661 when Name_As_Is =>
16662 Opt.External_Name_Exp_Casing := As_Is;
16663
16664 when Name_Uppercase =>
16665 Opt.External_Name_Exp_Casing := Uppercase;
16666
16667 when Name_Lowercase =>
16668 Opt.External_Name_Exp_Casing := Lowercase;
16669
16670 when others =>
16671 null;
16672 end case;
16673
16674 else
16675 Check_Arg_Count (1);
16676 end if;
16677
16678 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
16679
16680 case Chars (Get_Pragma_Arg (Arg1)) is
16681 when Name_Uppercase =>
16682 Opt.External_Name_Imp_Casing := Uppercase;
16683
16684 when Name_Lowercase =>
16685 Opt.External_Name_Imp_Casing := Lowercase;
16686
16687 when others =>
16688 null;
16689 end case;
16690
16691 ---------------
16692 -- Fast_Math --
16693 ---------------
16694
16695 -- pragma Fast_Math;
16696
16697 when Pragma_Fast_Math =>
16698 GNAT_Pragma;
16699 Check_No_Identifiers;
16700 Check_Valid_Configuration_Pragma;
16701 Fast_Math := True;
16702
16703 --------------------------
16704 -- Favor_Top_Level --
16705 --------------------------
16706
16707 -- pragma Favor_Top_Level (type_NAME);
16708
16709 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
16710 Typ : Entity_Id;
16711
16712 begin
16713 GNAT_Pragma;
16714 Check_No_Identifiers;
16715 Check_Arg_Count (1);
16716 Check_Arg_Is_Local_Name (Arg1);
16717 Typ := Entity (Get_Pragma_Arg (Arg1));
16718
16719 -- A pragma that applies to a Ghost entity becomes Ghost for the
16720 -- purposes of legality checks and removal of ignored Ghost code.
16721
16722 Mark_Ghost_Pragma (N, Typ);
16723
16724 -- If it's an access-to-subprogram type (in particular, not a
16725 -- subtype), set the flag on that type.
16726
16727 if Is_Access_Subprogram_Type (Typ) then
16728 Set_Can_Use_Internal_Rep (Typ, False);
16729
16730 -- Otherwise it's an error (name denotes the wrong sort of entity)
16731
16732 else
16733 Error_Pragma_Arg
16734 ("access-to-subprogram type expected",
16735 Get_Pragma_Arg (Arg1));
16736 end if;
16737 end Favor_Top_Level;
16738
16739 ---------------------------
16740 -- Finalize_Storage_Only --
16741 ---------------------------
16742
16743 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
16744
16745 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
16746 Assoc : constant Node_Id := Arg1;
16747 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
16748 Typ : Entity_Id;
16749
16750 begin
16751 GNAT_Pragma;
16752 Check_No_Identifiers;
16753 Check_Arg_Count (1);
16754 Check_Arg_Is_Local_Name (Arg1);
16755
16756 Find_Type (Type_Id);
16757 Typ := Entity (Type_Id);
16758
16759 if Typ = Any_Type
16760 or else Rep_Item_Too_Early (Typ, N)
16761 then
16762 return;
16763 else
16764 Typ := Underlying_Type (Typ);
16765 end if;
16766
16767 if not Is_Controlled (Typ) then
16768 Error_Pragma ("pragma% must specify controlled type");
16769 end if;
16770
16771 Check_First_Subtype (Arg1);
16772
16773 if Finalize_Storage_Only (Typ) then
16774 Error_Pragma ("duplicate pragma%, only one allowed");
16775
16776 elsif not Rep_Item_Too_Late (Typ, N) then
16777 Set_Finalize_Storage_Only (Base_Type (Typ), True);
16778 end if;
16779 end Finalize_Storage;
16780
16781 -----------
16782 -- Ghost --
16783 -----------
16784
16785 -- pragma Ghost [ (boolean_EXPRESSION) ];
16786
16787 when Pragma_Ghost => Ghost : declare
16788 Context : Node_Id;
16789 Expr : Node_Id;
16790 Id : Entity_Id;
16791 Orig_Stmt : Node_Id;
16792 Prev_Id : Entity_Id;
16793 Stmt : Node_Id;
16794
16795 begin
16796 GNAT_Pragma;
16797 Check_No_Identifiers;
16798 Check_At_Most_N_Arguments (1);
16799
16800 Id := Empty;
16801 Stmt := Prev (N);
16802 while Present (Stmt) loop
16803
16804 -- Skip prior pragmas, but check for duplicates
16805
16806 if Nkind (Stmt) = N_Pragma then
16807 if Pragma_Name (Stmt) = Pname then
16808 Duplication_Error
16809 (Prag => N,
16810 Prev => Stmt);
16811 raise Pragma_Exit;
16812 end if;
16813
16814 -- Task unit declared without a definition cannot be subject to
16815 -- pragma Ghost (SPARK RM 6.9(19)).
16816
16817 elsif Nkind (Stmt) in
16818 N_Single_Task_Declaration | N_Task_Type_Declaration
16819 then
16820 Error_Pragma ("pragma % cannot apply to a task type");
16821 return;
16822
16823 -- Skip internally generated code
16824
16825 elsif not Comes_From_Source (Stmt) then
16826 Orig_Stmt := Original_Node (Stmt);
16827
16828 -- When pragma Ghost applies to an untagged derivation, the
16829 -- derivation is transformed into a [sub]type declaration.
16830
16831 if Nkind (Stmt) in
16832 N_Full_Type_Declaration | N_Subtype_Declaration
16833 and then Comes_From_Source (Orig_Stmt)
16834 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
16835 and then Nkind (Type_Definition (Orig_Stmt)) =
16836 N_Derived_Type_Definition
16837 then
16838 Id := Defining_Entity (Stmt);
16839 exit;
16840
16841 -- When pragma Ghost applies to an object declaration which
16842 -- is initialized by means of a function call that returns
16843 -- on the secondary stack, the object declaration becomes a
16844 -- renaming.
16845
16846 elsif Nkind (Stmt) = N_Object_Renaming_Declaration
16847 and then Comes_From_Source (Orig_Stmt)
16848 and then Nkind (Orig_Stmt) = N_Object_Declaration
16849 then
16850 Id := Defining_Entity (Stmt);
16851 exit;
16852
16853 -- When pragma Ghost applies to an expression function, the
16854 -- expression function is transformed into a subprogram.
16855
16856 elsif Nkind (Stmt) = N_Subprogram_Declaration
16857 and then Comes_From_Source (Orig_Stmt)
16858 and then Nkind (Orig_Stmt) = N_Expression_Function
16859 then
16860 Id := Defining_Entity (Stmt);
16861 exit;
16862 end if;
16863
16864 -- The pragma applies to a legal construct, stop the traversal
16865
16866 elsif Nkind (Stmt) in N_Abstract_Subprogram_Declaration
16867 | N_Full_Type_Declaration
16868 | N_Generic_Subprogram_Declaration
16869 | N_Object_Declaration
16870 | N_Private_Extension_Declaration
16871 | N_Private_Type_Declaration
16872 | N_Subprogram_Declaration
16873 | N_Subtype_Declaration
16874 then
16875 Id := Defining_Entity (Stmt);
16876 exit;
16877
16878 -- The pragma does not apply to a legal construct, issue an
16879 -- error and stop the analysis.
16880
16881 else
16882 Error_Pragma
16883 ("pragma % must apply to an object, package, subprogram "
16884 & "or type");
16885 return;
16886 end if;
16887
16888 Stmt := Prev (Stmt);
16889 end loop;
16890
16891 Context := Parent (N);
16892
16893 -- Handle compilation units
16894
16895 if Nkind (Context) = N_Compilation_Unit_Aux then
16896 Context := Unit (Parent (Context));
16897 end if;
16898
16899 -- Protected and task types cannot be subject to pragma Ghost
16900 -- (SPARK RM 6.9(19)).
16901
16902 if Nkind (Context) in N_Protected_Body | N_Protected_Definition
16903 then
16904 Error_Pragma ("pragma % cannot apply to a protected type");
16905 return;
16906
16907 elsif Nkind (Context) in N_Task_Body | N_Task_Definition then
16908 Error_Pragma ("pragma % cannot apply to a task type");
16909 return;
16910 end if;
16911
16912 if No (Id) then
16913
16914 -- When pragma Ghost is associated with a [generic] package, it
16915 -- appears in the visible declarations.
16916
16917 if Nkind (Context) = N_Package_Specification
16918 and then Present (Visible_Declarations (Context))
16919 and then List_Containing (N) = Visible_Declarations (Context)
16920 then
16921 Id := Defining_Entity (Context);
16922
16923 -- Pragma Ghost applies to a stand-alone subprogram body
16924
16925 elsif Nkind (Context) = N_Subprogram_Body
16926 and then No (Corresponding_Spec (Context))
16927 then
16928 Id := Defining_Entity (Context);
16929
16930 -- Pragma Ghost applies to a subprogram declaration that acts
16931 -- as a compilation unit.
16932
16933 elsif Nkind (Context) = N_Subprogram_Declaration then
16934 Id := Defining_Entity (Context);
16935
16936 -- Pragma Ghost applies to a generic subprogram
16937
16938 elsif Nkind (Context) = N_Generic_Subprogram_Declaration then
16939 Id := Defining_Entity (Specification (Context));
16940 end if;
16941 end if;
16942
16943 if No (Id) then
16944 Error_Pragma
16945 ("pragma % must apply to an object, package, subprogram or "
16946 & "type");
16947 return;
16948 end if;
16949
16950 -- Handle completions of types and constants that are subject to
16951 -- pragma Ghost.
16952
16953 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
16954 Prev_Id := Incomplete_Or_Partial_View (Id);
16955
16956 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
16957 Error_Msg_Name_1 := Pname;
16958
16959 -- The full declaration of a deferred constant cannot be
16960 -- subject to pragma Ghost unless the deferred declaration
16961 -- is also Ghost (SPARK RM 6.9(9)).
16962
16963 if Ekind (Prev_Id) = E_Constant then
16964 Error_Msg_Name_1 := Pname;
16965 Error_Msg_NE (Fix_Error
16966 ("pragma % must apply to declaration of deferred "
16967 & "constant &"), N, Id);
16968 return;
16969
16970 -- Pragma Ghost may appear on the full view of an incomplete
16971 -- type because the incomplete declaration lacks aspects and
16972 -- cannot be subject to pragma Ghost.
16973
16974 elsif Ekind (Prev_Id) = E_Incomplete_Type then
16975 null;
16976
16977 -- The full declaration of a type cannot be subject to
16978 -- pragma Ghost unless the partial view is also Ghost
16979 -- (SPARK RM 6.9(9)).
16980
16981 else
16982 Error_Msg_NE (Fix_Error
16983 ("pragma % must apply to partial view of type &"),
16984 N, Id);
16985 return;
16986 end if;
16987 end if;
16988
16989 -- A synchronized object cannot be subject to pragma Ghost
16990 -- (SPARK RM 6.9(19)).
16991
16992 elsif Ekind (Id) = E_Variable then
16993 if Is_Protected_Type (Etype (Id)) then
16994 Error_Pragma ("pragma % cannot apply to a protected object");
16995 return;
16996
16997 elsif Is_Task_Type (Etype (Id)) then
16998 Error_Pragma ("pragma % cannot apply to a task object");
16999 return;
17000 end if;
17001 end if;
17002
17003 -- Analyze the Boolean expression (if any)
17004
17005 if Present (Arg1) then
17006 Expr := Get_Pragma_Arg (Arg1);
17007
17008 Analyze_And_Resolve (Expr, Standard_Boolean);
17009
17010 if Is_OK_Static_Expression (Expr) then
17011
17012 -- "Ghostness" cannot be turned off once enabled within a
17013 -- region (SPARK RM 6.9(6)).
17014
17015 if Is_False (Expr_Value (Expr))
17016 and then Ghost_Mode > None
17017 then
17018 Error_Pragma
17019 ("pragma % with value False cannot appear in enabled "
17020 & "ghost region");
17021 return;
17022 end if;
17023
17024 -- Otherwise the expression is not static
17025
17026 else
17027 Error_Pragma_Arg
17028 ("expression of pragma % must be static", Expr);
17029 return;
17030 end if;
17031 end if;
17032
17033 Set_Is_Ghost_Entity (Id);
17034 end Ghost;
17035
17036 ------------
17037 -- Global --
17038 ------------
17039
17040 -- pragma Global (GLOBAL_SPECIFICATION);
17041
17042 -- GLOBAL_SPECIFICATION ::=
17043 -- null
17044 -- | (GLOBAL_LIST)
17045 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
17046
17047 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
17048
17049 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
17050 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
17051 -- GLOBAL_ITEM ::= NAME
17052
17053 -- Characteristics:
17054
17055 -- * Analysis - The annotation undergoes initial checks to verify
17056 -- the legal placement and context. Secondary checks fully analyze
17057 -- the dependency clauses in:
17058
17059 -- Analyze_Global_In_Decl_Part
17060
17061 -- * Expansion - None.
17062
17063 -- * Template - The annotation utilizes the generic template of the
17064 -- related subprogram [body] when it is:
17065
17066 -- aspect on subprogram declaration
17067 -- aspect on stand-alone subprogram body
17068 -- pragma on stand-alone subprogram body
17069
17070 -- The annotation must prepare its own template when it is:
17071
17072 -- pragma on subprogram declaration
17073
17074 -- * Globals - Capture of global references must occur after full
17075 -- analysis.
17076
17077 -- * Instance - The annotation is instantiated automatically when
17078 -- the related generic subprogram [body] is instantiated except for
17079 -- the "pragma on subprogram declaration" case. In that scenario
17080 -- the annotation must instantiate itself.
17081
17082 when Pragma_Global => Global : declare
17083 Legal : Boolean;
17084 Spec_Id : Entity_Id;
17085 Subp_Decl : Node_Id;
17086
17087 begin
17088 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
17089
17090 if Legal then
17091
17092 -- Chain the pragma on the contract for further processing by
17093 -- Analyze_Global_In_Decl_Part.
17094
17095 Add_Contract_Item (N, Spec_Id);
17096
17097 -- Fully analyze the pragma when it appears inside an entry
17098 -- or subprogram body because it cannot benefit from forward
17099 -- references.
17100
17101 if Nkind (Subp_Decl) in N_Entry_Body
17102 | N_Subprogram_Body
17103 | N_Subprogram_Body_Stub
17104 then
17105 -- The legality checks of pragmas Depends and Global are
17106 -- affected by the SPARK mode in effect and the volatility
17107 -- of the context. In addition these two pragmas are subject
17108 -- to an inherent order:
17109
17110 -- 1) Global
17111 -- 2) Depends
17112
17113 -- Analyze all these pragmas in the order outlined above
17114
17115 Analyze_If_Present (Pragma_SPARK_Mode);
17116 Analyze_If_Present (Pragma_Volatile_Function);
17117 Analyze_Global_In_Decl_Part (N);
17118 Analyze_If_Present (Pragma_Depends);
17119 end if;
17120 end if;
17121 end Global;
17122
17123 -----------
17124 -- Ident --
17125 -----------
17126
17127 -- pragma Ident (static_string_EXPRESSION)
17128
17129 -- Note: pragma Comment shares this processing. Pragma Ident is
17130 -- identical in effect to pragma Commment.
17131
17132 when Pragma_Comment
17133 | Pragma_Ident
17134 =>
17135 Ident : declare
17136 Str : Node_Id;
17137
17138 begin
17139 GNAT_Pragma;
17140 Check_Arg_Count (1);
17141 Check_No_Identifiers;
17142 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17143 Store_Note (N);
17144
17145 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
17146
17147 declare
17148 CS : Node_Id;
17149 GP : Node_Id;
17150
17151 begin
17152 GP := Parent (Parent (N));
17153
17154 if Nkind (GP) in
17155 N_Package_Declaration | N_Generic_Package_Declaration
17156 then
17157 GP := Parent (GP);
17158 end if;
17159
17160 -- If we have a compilation unit, then record the ident value,
17161 -- checking for improper duplication.
17162
17163 if Nkind (GP) = N_Compilation_Unit then
17164 CS := Ident_String (Current_Sem_Unit);
17165
17166 if Present (CS) then
17167
17168 -- If we have multiple instances, concatenate them.
17169
17170 Start_String (Strval (CS));
17171 Store_String_Char (' ');
17172 Store_String_Chars (Strval (Str));
17173 Set_Strval (CS, End_String);
17174
17175 else
17176 Set_Ident_String (Current_Sem_Unit, Str);
17177 end if;
17178
17179 -- For subunits, we just ignore the Ident, since in GNAT these
17180 -- are not separate object files, and hence not separate units
17181 -- in the unit table.
17182
17183 elsif Nkind (GP) = N_Subunit then
17184 null;
17185 end if;
17186 end;
17187 end Ident;
17188
17189 -------------------
17190 -- Ignore_Pragma --
17191 -------------------
17192
17193 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
17194
17195 -- Entirely handled in the parser, nothing to do here
17196
17197 when Pragma_Ignore_Pragma =>
17198 null;
17199
17200 ----------------------------
17201 -- Implementation_Defined --
17202 ----------------------------
17203
17204 -- pragma Implementation_Defined (LOCAL_NAME);
17205
17206 -- Marks previously declared entity as implementation defined. For
17207 -- an overloaded entity, applies to the most recent homonym.
17208
17209 -- pragma Implementation_Defined;
17210
17211 -- The form with no arguments appears anywhere within a scope, most
17212 -- typically a package spec, and indicates that all entities that are
17213 -- defined within the package spec are Implementation_Defined.
17214
17215 when Pragma_Implementation_Defined => Implementation_Defined : declare
17216 Ent : Entity_Id;
17217
17218 begin
17219 GNAT_Pragma;
17220 Check_No_Identifiers;
17221
17222 -- Form with no arguments
17223
17224 if Arg_Count = 0 then
17225 Set_Is_Implementation_Defined (Current_Scope);
17226
17227 -- Form with one argument
17228
17229 else
17230 Check_Arg_Count (1);
17231 Check_Arg_Is_Local_Name (Arg1);
17232 Ent := Entity (Get_Pragma_Arg (Arg1));
17233 Set_Is_Implementation_Defined (Ent);
17234 end if;
17235 end Implementation_Defined;
17236
17237 -----------------
17238 -- Implemented --
17239 -----------------
17240
17241 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
17242
17243 -- IMPLEMENTATION_KIND ::=
17244 -- By_Entry | By_Protected_Procedure | By_Any | Optional
17245
17246 -- "By_Any" and "Optional" are treated as synonyms in order to
17247 -- support Ada 2012 aspect Synchronization.
17248
17249 when Pragma_Implemented => Implemented : declare
17250 Proc_Id : Entity_Id;
17251 Typ : Entity_Id;
17252
17253 begin
17254 Ada_2012_Pragma;
17255 Check_Arg_Count (2);
17256 Check_No_Identifiers;
17257 Check_Arg_Is_Identifier (Arg1);
17258 Check_Arg_Is_Local_Name (Arg1);
17259 Check_Arg_Is_One_Of (Arg2,
17260 Name_By_Any,
17261 Name_By_Entry,
17262 Name_By_Protected_Procedure,
17263 Name_Optional);
17264
17265 -- Extract the name of the local procedure
17266
17267 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
17268
17269 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
17270 -- primitive procedure of a synchronized tagged type.
17271
17272 if Ekind (Proc_Id) = E_Procedure
17273 and then Is_Primitive (Proc_Id)
17274 and then Present (First_Formal (Proc_Id))
17275 then
17276 Typ := Etype (First_Formal (Proc_Id));
17277
17278 if Is_Tagged_Type (Typ)
17279 and then
17280
17281 -- Check for a protected, a synchronized or a task interface
17282
17283 ((Is_Interface (Typ)
17284 and then Is_Synchronized_Interface (Typ))
17285
17286 -- Check for a protected type or a task type that implements
17287 -- an interface.
17288
17289 or else
17290 (Is_Concurrent_Record_Type (Typ)
17291 and then Present (Interfaces (Typ)))
17292
17293 -- In analysis-only mode, examine original protected type
17294
17295 or else
17296 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
17297 and then Present (Interface_List (Parent (Typ))))
17298
17299 -- Check for a private record extension with keyword
17300 -- "synchronized".
17301
17302 or else
17303 (Ekind (Typ) in E_Record_Type_With_Private
17304 | E_Record_Subtype_With_Private
17305 and then Synchronized_Present (Parent (Typ))))
17306 then
17307 null;
17308 else
17309 Error_Pragma_Arg
17310 ("controlling formal must be of synchronized tagged type",
17311 Arg1);
17312 return;
17313 end if;
17314
17315 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
17316 -- By_Protected_Procedure to the primitive procedure of a task
17317 -- interface.
17318
17319 if Chars (Get_Pragma_Arg (Arg2)) = Name_By_Protected_Procedure
17320 and then Is_Interface (Typ)
17321 and then Is_Task_Interface (Typ)
17322 then
17323 Error_Pragma_Arg
17324 ("implementation kind By_Protected_Procedure cannot be "
17325 & "applied to a task interface primitive", Arg2);
17326 return;
17327 end if;
17328
17329 -- Procedures declared inside a protected type must be accepted
17330
17331 elsif Ekind (Proc_Id) = E_Procedure
17332 and then Is_Protected_Type (Scope (Proc_Id))
17333 then
17334 null;
17335
17336 -- The first argument is not a primitive procedure
17337
17338 else
17339 Error_Pragma_Arg
17340 ("pragma % must be applied to a primitive procedure", Arg1);
17341 return;
17342 end if;
17343
17344 -- Ada 2012 (AI12-0279): Cannot apply the implementation_kind
17345 -- By_Protected_Procedure to a procedure that has aspect Yield
17346
17347 if Chars (Get_Pragma_Arg (Arg2)) = Name_By_Protected_Procedure
17348 and then Has_Yield_Aspect (Proc_Id)
17349 then
17350 Error_Pragma_Arg
17351 ("implementation kind By_Protected_Procedure cannot be "
17352 & "applied to entities with aspect 'Yield", Arg2);
17353 return;
17354 end if;
17355
17356 Record_Rep_Item (Proc_Id, N);
17357 end Implemented;
17358
17359 ----------------------
17360 -- Implicit_Packing --
17361 ----------------------
17362
17363 -- pragma Implicit_Packing;
17364
17365 when Pragma_Implicit_Packing =>
17366 GNAT_Pragma;
17367 Check_Arg_Count (0);
17368 Implicit_Packing := True;
17369
17370 ------------
17371 -- Import --
17372 ------------
17373
17374 -- pragma Import (
17375 -- [Convention =>] convention_IDENTIFIER,
17376 -- [Entity =>] LOCAL_NAME
17377 -- [, [External_Name =>] static_string_EXPRESSION ]
17378 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17379
17380 when Pragma_Import =>
17381 Check_Ada_83_Warning;
17382 Check_Arg_Order
17383 ((Name_Convention,
17384 Name_Entity,
17385 Name_External_Name,
17386 Name_Link_Name));
17387
17388 Check_At_Least_N_Arguments (2);
17389 Check_At_Most_N_Arguments (4);
17390 Process_Import_Or_Interface;
17391
17392 ---------------------
17393 -- Import_Function --
17394 ---------------------
17395
17396 -- pragma Import_Function (
17397 -- [Internal =>] LOCAL_NAME,
17398 -- [, [External =>] EXTERNAL_SYMBOL]
17399 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17400 -- [, [Result_Type =>] SUBTYPE_MARK]
17401 -- [, [Mechanism =>] MECHANISM]
17402 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
17403
17404 -- EXTERNAL_SYMBOL ::=
17405 -- IDENTIFIER
17406 -- | static_string_EXPRESSION
17407
17408 -- PARAMETER_TYPES ::=
17409 -- null
17410 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17411
17412 -- TYPE_DESIGNATOR ::=
17413 -- subtype_NAME
17414 -- | subtype_Name ' Access
17415
17416 -- MECHANISM ::=
17417 -- MECHANISM_NAME
17418 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17419
17420 -- MECHANISM_ASSOCIATION ::=
17421 -- [formal_parameter_NAME =>] MECHANISM_NAME
17422
17423 -- MECHANISM_NAME ::=
17424 -- Value
17425 -- | Reference
17426
17427 when Pragma_Import_Function => Import_Function : declare
17428 Args : Args_List (1 .. 6);
17429 Names : constant Name_List (1 .. 6) := (
17430 Name_Internal,
17431 Name_External,
17432 Name_Parameter_Types,
17433 Name_Result_Type,
17434 Name_Mechanism,
17435 Name_Result_Mechanism);
17436
17437 Internal : Node_Id renames Args (1);
17438 External : Node_Id renames Args (2);
17439 Parameter_Types : Node_Id renames Args (3);
17440 Result_Type : Node_Id renames Args (4);
17441 Mechanism : Node_Id renames Args (5);
17442 Result_Mechanism : Node_Id renames Args (6);
17443
17444 begin
17445 GNAT_Pragma;
17446 Gather_Associations (Names, Args);
17447 Process_Extended_Import_Export_Subprogram_Pragma (
17448 Arg_Internal => Internal,
17449 Arg_External => External,
17450 Arg_Parameter_Types => Parameter_Types,
17451 Arg_Result_Type => Result_Type,
17452 Arg_Mechanism => Mechanism,
17453 Arg_Result_Mechanism => Result_Mechanism);
17454 end Import_Function;
17455
17456 -------------------
17457 -- Import_Object --
17458 -------------------
17459
17460 -- pragma Import_Object (
17461 -- [Internal =>] LOCAL_NAME
17462 -- [, [External =>] EXTERNAL_SYMBOL]
17463 -- [, [Size =>] EXTERNAL_SYMBOL]);
17464
17465 -- EXTERNAL_SYMBOL ::=
17466 -- IDENTIFIER
17467 -- | static_string_EXPRESSION
17468
17469 when Pragma_Import_Object => Import_Object : declare
17470 Args : Args_List (1 .. 3);
17471 Names : constant Name_List (1 .. 3) := (
17472 Name_Internal,
17473 Name_External,
17474 Name_Size);
17475
17476 Internal : Node_Id renames Args (1);
17477 External : Node_Id renames Args (2);
17478 Size : Node_Id renames Args (3);
17479
17480 begin
17481 GNAT_Pragma;
17482 Gather_Associations (Names, Args);
17483 Process_Extended_Import_Export_Object_Pragma (
17484 Arg_Internal => Internal,
17485 Arg_External => External,
17486 Arg_Size => Size);
17487 end Import_Object;
17488
17489 ----------------------
17490 -- Import_Procedure --
17491 ----------------------
17492
17493 -- pragma Import_Procedure (
17494 -- [Internal =>] LOCAL_NAME
17495 -- [, [External =>] EXTERNAL_SYMBOL]
17496 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17497 -- [, [Mechanism =>] MECHANISM]);
17498
17499 -- EXTERNAL_SYMBOL ::=
17500 -- IDENTIFIER
17501 -- | static_string_EXPRESSION
17502
17503 -- PARAMETER_TYPES ::=
17504 -- null
17505 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17506
17507 -- TYPE_DESIGNATOR ::=
17508 -- subtype_NAME
17509 -- | subtype_Name ' Access
17510
17511 -- MECHANISM ::=
17512 -- MECHANISM_NAME
17513 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17514
17515 -- MECHANISM_ASSOCIATION ::=
17516 -- [formal_parameter_NAME =>] MECHANISM_NAME
17517
17518 -- MECHANISM_NAME ::=
17519 -- Value
17520 -- | Reference
17521
17522 when Pragma_Import_Procedure => Import_Procedure : declare
17523 Args : Args_List (1 .. 4);
17524 Names : constant Name_List (1 .. 4) := (
17525 Name_Internal,
17526 Name_External,
17527 Name_Parameter_Types,
17528 Name_Mechanism);
17529
17530 Internal : Node_Id renames Args (1);
17531 External : Node_Id renames Args (2);
17532 Parameter_Types : Node_Id renames Args (3);
17533 Mechanism : Node_Id renames Args (4);
17534
17535 begin
17536 GNAT_Pragma;
17537 Gather_Associations (Names, Args);
17538 Process_Extended_Import_Export_Subprogram_Pragma (
17539 Arg_Internal => Internal,
17540 Arg_External => External,
17541 Arg_Parameter_Types => Parameter_Types,
17542 Arg_Mechanism => Mechanism);
17543 end Import_Procedure;
17544
17545 -----------------------------
17546 -- Import_Valued_Procedure --
17547 -----------------------------
17548
17549 -- pragma Import_Valued_Procedure (
17550 -- [Internal =>] LOCAL_NAME
17551 -- [, [External =>] EXTERNAL_SYMBOL]
17552 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17553 -- [, [Mechanism =>] MECHANISM]);
17554
17555 -- EXTERNAL_SYMBOL ::=
17556 -- IDENTIFIER
17557 -- | static_string_EXPRESSION
17558
17559 -- PARAMETER_TYPES ::=
17560 -- null
17561 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17562
17563 -- TYPE_DESIGNATOR ::=
17564 -- subtype_NAME
17565 -- | subtype_Name ' Access
17566
17567 -- MECHANISM ::=
17568 -- MECHANISM_NAME
17569 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17570
17571 -- MECHANISM_ASSOCIATION ::=
17572 -- [formal_parameter_NAME =>] MECHANISM_NAME
17573
17574 -- MECHANISM_NAME ::=
17575 -- Value
17576 -- | Reference
17577
17578 when Pragma_Import_Valued_Procedure =>
17579 Import_Valued_Procedure : declare
17580 Args : Args_List (1 .. 4);
17581 Names : constant Name_List (1 .. 4) := (
17582 Name_Internal,
17583 Name_External,
17584 Name_Parameter_Types,
17585 Name_Mechanism);
17586
17587 Internal : Node_Id renames Args (1);
17588 External : Node_Id renames Args (2);
17589 Parameter_Types : Node_Id renames Args (3);
17590 Mechanism : Node_Id renames Args (4);
17591
17592 begin
17593 GNAT_Pragma;
17594 Gather_Associations (Names, Args);
17595 Process_Extended_Import_Export_Subprogram_Pragma (
17596 Arg_Internal => Internal,
17597 Arg_External => External,
17598 Arg_Parameter_Types => Parameter_Types,
17599 Arg_Mechanism => Mechanism);
17600 end Import_Valued_Procedure;
17601
17602 -----------------
17603 -- Independent --
17604 -----------------
17605
17606 -- pragma Independent (LOCAL_NAME);
17607
17608 when Pragma_Independent =>
17609 Process_Atomic_Independent_Shared_Volatile;
17610
17611 ----------------------------
17612 -- Independent_Components --
17613 ----------------------------
17614
17615 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
17616
17617 when Pragma_Independent_Components => Independent_Components : declare
17618 C : Node_Id;
17619 D : Node_Id;
17620 E_Id : Node_Id;
17621 E : Entity_Id;
17622
17623 begin
17624 Check_Ada_83_Warning;
17625 Ada_2012_Pragma;
17626 Check_No_Identifiers;
17627 Check_Arg_Count (1);
17628 Check_Arg_Is_Local_Name (Arg1);
17629 E_Id := Get_Pragma_Arg (Arg1);
17630
17631 if Etype (E_Id) = Any_Type then
17632 return;
17633 end if;
17634
17635 E := Entity (E_Id);
17636
17637 -- A record type with a self-referential component of anonymous
17638 -- access type is given an incomplete view in order to handle the
17639 -- self reference:
17640 --
17641 -- type Rec is record
17642 -- Self : access Rec;
17643 -- end record;
17644 --
17645 -- becomes
17646 --
17647 -- type Rec;
17648 -- type Ptr is access Rec;
17649 -- type Rec is record
17650 -- Self : Ptr;
17651 -- end record;
17652 --
17653 -- Since the incomplete view is now the initial view of the type,
17654 -- the argument of the pragma will reference the incomplete view,
17655 -- but this view is illegal according to the semantics of the
17656 -- pragma.
17657 --
17658 -- Obtain the full view of an internally-generated incomplete type
17659 -- only. This way an attempt to associate the pragma with a source
17660 -- incomplete type is still caught.
17661
17662 if Ekind (E) = E_Incomplete_Type
17663 and then not Comes_From_Source (E)
17664 and then Present (Full_View (E))
17665 then
17666 E := Full_View (E);
17667 end if;
17668
17669 -- A pragma that applies to a Ghost entity becomes Ghost for the
17670 -- purposes of legality checks and removal of ignored Ghost code.
17671
17672 Mark_Ghost_Pragma (N, E);
17673
17674 -- Check duplicate before we chain ourselves
17675
17676 Check_Duplicate_Pragma (E);
17677
17678 -- Check appropriate entity
17679
17680 if Rep_Item_Too_Early (E, N)
17681 or else
17682 Rep_Item_Too_Late (E, N)
17683 then
17684 return;
17685 end if;
17686
17687 D := Declaration_Node (E);
17688
17689 -- The flag is set on the base type, or on the object
17690
17691 if Nkind (D) = N_Full_Type_Declaration
17692 and then (Is_Array_Type (E) or else Is_Record_Type (E))
17693 then
17694 Set_Has_Independent_Components (Base_Type (E));
17695 Record_Independence_Check (N, Base_Type (E));
17696
17697 -- For record type, set all components independent
17698
17699 if Is_Record_Type (E) then
17700 C := First_Component (E);
17701 while Present (C) loop
17702 Set_Is_Independent (C);
17703 Next_Component (C);
17704 end loop;
17705 end if;
17706
17707 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
17708 and then Nkind (D) = N_Object_Declaration
17709 and then Nkind (Object_Definition (D)) =
17710 N_Constrained_Array_Definition
17711 then
17712 Set_Has_Independent_Components (E);
17713 Record_Independence_Check (N, E);
17714
17715 else
17716 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
17717 end if;
17718 end Independent_Components;
17719
17720 -----------------------
17721 -- Initial_Condition --
17722 -----------------------
17723
17724 -- pragma Initial_Condition (boolean_EXPRESSION);
17725
17726 -- Characteristics:
17727
17728 -- * Analysis - The annotation undergoes initial checks to verify
17729 -- the legal placement and context. Secondary checks preanalyze the
17730 -- expression in:
17731
17732 -- Analyze_Initial_Condition_In_Decl_Part
17733
17734 -- * Expansion - The annotation is expanded during the expansion of
17735 -- the package body whose declaration is subject to the annotation
17736 -- as done in:
17737
17738 -- Expand_Pragma_Initial_Condition
17739
17740 -- * Template - The annotation utilizes the generic template of the
17741 -- related package declaration.
17742
17743 -- * Globals - Capture of global references must occur after full
17744 -- analysis.
17745
17746 -- * Instance - The annotation is instantiated automatically when
17747 -- the related generic package is instantiated.
17748
17749 when Pragma_Initial_Condition => Initial_Condition : declare
17750 Pack_Decl : Node_Id;
17751 Pack_Id : Entity_Id;
17752
17753 begin
17754 GNAT_Pragma;
17755 Check_No_Identifiers;
17756 Check_Arg_Count (1);
17757
17758 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
17759
17760 if Nkind (Pack_Decl) not in
17761 N_Generic_Package_Declaration | N_Package_Declaration
17762 then
17763 Pragma_Misplaced;
17764 return;
17765 end if;
17766
17767 Pack_Id := Defining_Entity (Pack_Decl);
17768
17769 -- A pragma that applies to a Ghost entity becomes Ghost for the
17770 -- purposes of legality checks and removal of ignored Ghost code.
17771
17772 Mark_Ghost_Pragma (N, Pack_Id);
17773
17774 -- Chain the pragma on the contract for further processing by
17775 -- Analyze_Initial_Condition_In_Decl_Part.
17776
17777 Add_Contract_Item (N, Pack_Id);
17778
17779 -- The legality checks of pragmas Abstract_State, Initializes, and
17780 -- Initial_Condition are affected by the SPARK mode in effect. In
17781 -- addition, these three pragmas are subject to an inherent order:
17782
17783 -- 1) Abstract_State
17784 -- 2) Initializes
17785 -- 3) Initial_Condition
17786
17787 -- Analyze all these pragmas in the order outlined above
17788
17789 Analyze_If_Present (Pragma_SPARK_Mode);
17790 Analyze_If_Present (Pragma_Abstract_State);
17791 Analyze_If_Present (Pragma_Initializes);
17792 end Initial_Condition;
17793
17794 ------------------------
17795 -- Initialize_Scalars --
17796 ------------------------
17797
17798 -- pragma Initialize_Scalars
17799 -- [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ];
17800
17801 -- TYPE_VALUE_PAIR ::=
17802 -- SCALAR_TYPE => static_EXPRESSION
17803
17804 -- SCALAR_TYPE :=
17805 -- Short_Float
17806 -- | Float
17807 -- | Long_Float
17808 -- | Long_Long_Flat
17809 -- | Signed_8
17810 -- | Signed_16
17811 -- | Signed_32
17812 -- | Signed_64
17813 -- | Unsigned_8
17814 -- | Unsigned_16
17815 -- | Unsigned_32
17816 -- | Unsigned_64
17817
17818 when Pragma_Initialize_Scalars => Do_Initialize_Scalars : declare
17819 Seen : array (Scalar_Id) of Node_Id := (others => Empty);
17820 -- This collection holds the individual pairs which specify the
17821 -- invalid values of their respective scalar types.
17822
17823 procedure Analyze_Float_Value
17824 (Scal_Typ : Float_Scalar_Id;
17825 Val_Expr : Node_Id);
17826 -- Analyze a type value pair associated with float type Scal_Typ
17827 -- and expression Val_Expr.
17828
17829 procedure Analyze_Integer_Value
17830 (Scal_Typ : Integer_Scalar_Id;
17831 Val_Expr : Node_Id);
17832 -- Analyze a type value pair associated with integer type Scal_Typ
17833 -- and expression Val_Expr.
17834
17835 procedure Analyze_Type_Value_Pair (Pair : Node_Id);
17836 -- Analyze type value pair Pair
17837
17838 -------------------------
17839 -- Analyze_Float_Value --
17840 -------------------------
17841
17842 procedure Analyze_Float_Value
17843 (Scal_Typ : Float_Scalar_Id;
17844 Val_Expr : Node_Id)
17845 is
17846 begin
17847 Analyze_And_Resolve (Val_Expr, Any_Real);
17848
17849 if Is_OK_Static_Expression (Val_Expr) then
17850 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value_R (Val_Expr));
17851
17852 else
17853 Error_Msg_Name_1 := Scal_Typ;
17854 Error_Msg_N ("value for type % must be static", Val_Expr);
17855 end if;
17856 end Analyze_Float_Value;
17857
17858 ---------------------------
17859 -- Analyze_Integer_Value --
17860 ---------------------------
17861
17862 procedure Analyze_Integer_Value
17863 (Scal_Typ : Integer_Scalar_Id;
17864 Val_Expr : Node_Id)
17865 is
17866 begin
17867 Analyze_And_Resolve (Val_Expr, Any_Integer);
17868
17869 if Is_OK_Static_Expression (Val_Expr) then
17870 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value (Val_Expr));
17871
17872 else
17873 Error_Msg_Name_1 := Scal_Typ;
17874 Error_Msg_N ("value for type % must be static", Val_Expr);
17875 end if;
17876 end Analyze_Integer_Value;
17877
17878 -----------------------------
17879 -- Analyze_Type_Value_Pair --
17880 -----------------------------
17881
17882 procedure Analyze_Type_Value_Pair (Pair : Node_Id) is
17883 Scal_Typ : constant Name_Id := Chars (Pair);
17884 Val_Expr : constant Node_Id := Expression (Pair);
17885 Prev_Pair : Node_Id;
17886
17887 begin
17888 if Scal_Typ in Scalar_Id then
17889 Prev_Pair := Seen (Scal_Typ);
17890
17891 -- Prevent multiple attempts to set a value for a scalar
17892 -- type.
17893
17894 if Present (Prev_Pair) then
17895 Error_Msg_Name_1 := Scal_Typ;
17896 Error_Msg_N
17897 ("cannot specify multiple invalid values for type %",
17898 Pair);
17899
17900 Error_Msg_Sloc := Sloc (Prev_Pair);
17901 Error_Msg_N ("previous value set #", Pair);
17902
17903 -- Ignore the effects of the pair, but do not halt the
17904 -- analysis of the pragma altogether.
17905
17906 return;
17907
17908 -- Otherwise capture the first pair for this scalar type
17909
17910 else
17911 Seen (Scal_Typ) := Pair;
17912 end if;
17913
17914 if Scal_Typ in Float_Scalar_Id then
17915 Analyze_Float_Value (Scal_Typ, Val_Expr);
17916
17917 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
17918 Analyze_Integer_Value (Scal_Typ, Val_Expr);
17919 end if;
17920
17921 -- Otherwise the scalar family is illegal
17922
17923 else
17924 Error_Msg_Name_1 := Pname;
17925 Error_Msg_N
17926 ("argument of pragma % must denote valid scalar family",
17927 Pair);
17928 end if;
17929 end Analyze_Type_Value_Pair;
17930
17931 -- Local variables
17932
17933 Pairs : constant List_Id := Pragma_Argument_Associations (N);
17934 Pair : Node_Id;
17935
17936 -- Start of processing for Do_Initialize_Scalars
17937
17938 begin
17939 GNAT_Pragma;
17940 Check_Valid_Configuration_Pragma;
17941 Check_Restriction (No_Initialize_Scalars, N);
17942
17943 -- Ignore the effects of the pragma when No_Initialize_Scalars is
17944 -- in effect.
17945
17946 if Restriction_Active (No_Initialize_Scalars) then
17947 null;
17948
17949 -- Initialize_Scalars creates false positives in CodePeer, and
17950 -- incorrect negative results in GNATprove mode, so ignore this
17951 -- pragma in these modes.
17952
17953 elsif CodePeer_Mode or GNATprove_Mode then
17954 null;
17955
17956 -- Otherwise analyze the pragma
17957
17958 else
17959 if Present (Pairs) then
17960
17961 -- Install Standard in order to provide access to primitive
17962 -- types in case the expressions contain attributes such as
17963 -- Integer'Last.
17964
17965 Push_Scope (Standard_Standard);
17966
17967 Pair := First (Pairs);
17968 while Present (Pair) loop
17969 Analyze_Type_Value_Pair (Pair);
17970 Next (Pair);
17971 end loop;
17972
17973 -- Remove Standard
17974
17975 Pop_Scope;
17976 end if;
17977
17978 Init_Or_Norm_Scalars := True;
17979 Initialize_Scalars := True;
17980 end if;
17981 end Do_Initialize_Scalars;
17982
17983 -----------------
17984 -- Initializes --
17985 -----------------
17986
17987 -- pragma Initializes (INITIALIZATION_LIST);
17988
17989 -- INITIALIZATION_LIST ::=
17990 -- null
17991 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
17992
17993 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
17994
17995 -- INPUT_LIST ::=
17996 -- null
17997 -- | INPUT
17998 -- | (INPUT {, INPUT})
17999
18000 -- INPUT ::= name
18001
18002 -- Characteristics:
18003
18004 -- * Analysis - The annotation undergoes initial checks to verify
18005 -- the legal placement and context. Secondary checks preanalyze the
18006 -- expression in:
18007
18008 -- Analyze_Initializes_In_Decl_Part
18009
18010 -- * Expansion - None.
18011
18012 -- * Template - The annotation utilizes the generic template of the
18013 -- related package declaration.
18014
18015 -- * Globals - Capture of global references must occur after full
18016 -- analysis.
18017
18018 -- * Instance - The annotation is instantiated automatically when
18019 -- the related generic package is instantiated.
18020
18021 when Pragma_Initializes => Initializes : declare
18022 Pack_Decl : Node_Id;
18023 Pack_Id : Entity_Id;
18024
18025 begin
18026 GNAT_Pragma;
18027 Check_No_Identifiers;
18028 Check_Arg_Count (1);
18029
18030 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
18031
18032 if Nkind (Pack_Decl) not in
18033 N_Generic_Package_Declaration | N_Package_Declaration
18034 then
18035 Pragma_Misplaced;
18036 return;
18037 end if;
18038
18039 Pack_Id := Defining_Entity (Pack_Decl);
18040
18041 -- A pragma that applies to a Ghost entity becomes Ghost for the
18042 -- purposes of legality checks and removal of ignored Ghost code.
18043
18044 Mark_Ghost_Pragma (N, Pack_Id);
18045 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
18046
18047 -- Chain the pragma on the contract for further processing by
18048 -- Analyze_Initializes_In_Decl_Part.
18049
18050 Add_Contract_Item (N, Pack_Id);
18051
18052 -- The legality checks of pragmas Abstract_State, Initializes, and
18053 -- Initial_Condition are affected by the SPARK mode in effect. In
18054 -- addition, these three pragmas are subject to an inherent order:
18055
18056 -- 1) Abstract_State
18057 -- 2) Initializes
18058 -- 3) Initial_Condition
18059
18060 -- Analyze all these pragmas in the order outlined above
18061
18062 Analyze_If_Present (Pragma_SPARK_Mode);
18063 Analyze_If_Present (Pragma_Abstract_State);
18064 Analyze_If_Present (Pragma_Initial_Condition);
18065 end Initializes;
18066
18067 ------------
18068 -- Inline --
18069 ------------
18070
18071 -- pragma Inline ( NAME {, NAME} );
18072
18073 when Pragma_Inline =>
18074
18075 -- Pragma always active unless in GNATprove mode. It is disabled
18076 -- in GNATprove mode because frontend inlining is applied
18077 -- independently of pragmas Inline and Inline_Always for
18078 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
18079 -- in inline.ads.
18080
18081 if not GNATprove_Mode then
18082
18083 -- Inline status is Enabled if option -gnatn is specified.
18084 -- However this status determines only the value of the
18085 -- Is_Inlined flag on the subprogram and does not prevent
18086 -- the pragma itself from being recorded for later use,
18087 -- in particular for a later modification of Is_Inlined
18088 -- independently of the -gnatn option.
18089
18090 -- In other words, if -gnatn is specified for a unit, then
18091 -- all Inline pragmas processed for the compilation of this
18092 -- unit, including those in the spec of other units, are
18093 -- activated, so subprograms will be inlined across units.
18094
18095 -- If -gnatn is not specified, no Inline pragma is activated
18096 -- here, which means that subprograms will not be inlined
18097 -- across units. The Is_Inlined flag will nevertheless be
18098 -- set later when bodies are analyzed, so subprograms will
18099 -- be inlined within the unit.
18100
18101 if Inline_Active then
18102 Process_Inline (Enabled);
18103 else
18104 Process_Inline (Disabled);
18105 end if;
18106 end if;
18107
18108 -------------------
18109 -- Inline_Always --
18110 -------------------
18111
18112 -- pragma Inline_Always ( NAME {, NAME} );
18113
18114 when Pragma_Inline_Always =>
18115 GNAT_Pragma;
18116
18117 -- Pragma always active unless in CodePeer mode or GNATprove
18118 -- mode. It is disabled in CodePeer mode because inlining is
18119 -- not helpful, and enabling it caused walk order issues. It
18120 -- is disabled in GNATprove mode because frontend inlining is
18121 -- applied independently of pragmas Inline and Inline_Always for
18122 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
18123 -- inline.ads.
18124
18125 if not CodePeer_Mode and not GNATprove_Mode then
18126 Process_Inline (Enabled);
18127 end if;
18128
18129 --------------------
18130 -- Inline_Generic --
18131 --------------------
18132
18133 -- pragma Inline_Generic (NAME {, NAME});
18134
18135 when Pragma_Inline_Generic =>
18136 GNAT_Pragma;
18137 Process_Generic_List;
18138
18139 ----------------------
18140 -- Inspection_Point --
18141 ----------------------
18142
18143 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
18144
18145 when Pragma_Inspection_Point => Inspection_Point : declare
18146 Arg : Node_Id;
18147 Exp : Node_Id;
18148
18149 begin
18150 ip;
18151
18152 if Arg_Count > 0 then
18153 Arg := Arg1;
18154 loop
18155 Exp := Get_Pragma_Arg (Arg);
18156 Analyze (Exp);
18157
18158 if not Is_Entity_Name (Exp)
18159 or else not Is_Object (Entity (Exp))
18160 then
18161 Error_Pragma_Arg ("object name required", Arg);
18162 end if;
18163
18164 Next (Arg);
18165 exit when No (Arg);
18166 end loop;
18167 end if;
18168 end Inspection_Point;
18169
18170 ---------------
18171 -- Interface --
18172 ---------------
18173
18174 -- pragma Interface (
18175 -- [ Convention =>] convention_IDENTIFIER,
18176 -- [ Entity =>] LOCAL_NAME
18177 -- [, [External_Name =>] static_string_EXPRESSION ]
18178 -- [, [Link_Name =>] static_string_EXPRESSION ]);
18179
18180 when Pragma_Interface =>
18181 GNAT_Pragma;
18182 Check_Arg_Order
18183 ((Name_Convention,
18184 Name_Entity,
18185 Name_External_Name,
18186 Name_Link_Name));
18187 Check_At_Least_N_Arguments (2);
18188 Check_At_Most_N_Arguments (4);
18189 Process_Import_Or_Interface;
18190
18191 -- In Ada 2005, the permission to use Interface (a reserved word)
18192 -- as a pragma name is considered an obsolescent feature, and this
18193 -- pragma was already obsolescent in Ada 95.
18194
18195 if Ada_Version >= Ada_95 then
18196 Check_Restriction
18197 (No_Obsolescent_Features, Pragma_Identifier (N));
18198
18199 if Warn_On_Obsolescent_Feature then
18200 Error_Msg_N
18201 ("pragma Interface is an obsolescent feature?j?", N);
18202 Error_Msg_N
18203 ("|use pragma Import instead?j?", N);
18204 end if;
18205 end if;
18206
18207 --------------------
18208 -- Interface_Name --
18209 --------------------
18210
18211 -- pragma Interface_Name (
18212 -- [ Entity =>] LOCAL_NAME
18213 -- [,[External_Name =>] static_string_EXPRESSION ]
18214 -- [,[Link_Name =>] static_string_EXPRESSION ]);
18215
18216 when Pragma_Interface_Name => Interface_Name : declare
18217 Id : Node_Id;
18218 Def_Id : Entity_Id;
18219 Hom_Id : Entity_Id;
18220 Found : Boolean;
18221
18222 begin
18223 GNAT_Pragma;
18224 Check_Arg_Order
18225 ((Name_Entity, Name_External_Name, Name_Link_Name));
18226 Check_At_Least_N_Arguments (2);
18227 Check_At_Most_N_Arguments (3);
18228 Id := Get_Pragma_Arg (Arg1);
18229 Analyze (Id);
18230
18231 -- This is obsolete from Ada 95 on, but it is an implementation
18232 -- defined pragma, so we do not consider that it violates the
18233 -- restriction (No_Obsolescent_Features).
18234
18235 if Ada_Version >= Ada_95 then
18236 if Warn_On_Obsolescent_Feature then
18237 Error_Msg_N
18238 ("pragma Interface_Name is an obsolescent feature?j?", N);
18239 Error_Msg_N
18240 ("|use pragma Import instead?j?", N);
18241 end if;
18242 end if;
18243
18244 if not Is_Entity_Name (Id) then
18245 Error_Pragma_Arg
18246 ("first argument for pragma% must be entity name", Arg1);
18247 elsif Etype (Id) = Any_Type then
18248 return;
18249 else
18250 Def_Id := Entity (Id);
18251 end if;
18252
18253 -- Special DEC-compatible processing for the object case, forces
18254 -- object to be imported.
18255
18256 if Ekind (Def_Id) = E_Variable then
18257 Kill_Size_Check_Code (Def_Id);
18258 Note_Possible_Modification (Id, Sure => False);
18259
18260 -- Initialization is not allowed for imported variable
18261
18262 if Present (Expression (Parent (Def_Id)))
18263 and then Comes_From_Source (Expression (Parent (Def_Id)))
18264 then
18265 Error_Msg_Sloc := Sloc (Def_Id);
18266 Error_Pragma_Arg
18267 ("no initialization allowed for declaration of& #",
18268 Arg2);
18269
18270 else
18271 -- For compatibility, support VADS usage of providing both
18272 -- pragmas Interface and Interface_Name to obtain the effect
18273 -- of a single Import pragma.
18274
18275 if Is_Imported (Def_Id)
18276 and then Present (First_Rep_Item (Def_Id))
18277 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
18278 and then Pragma_Name (First_Rep_Item (Def_Id)) =
18279 Name_Interface
18280 then
18281 null;
18282 else
18283 Set_Imported (Def_Id);
18284 end if;
18285
18286 Set_Is_Public (Def_Id);
18287 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
18288 end if;
18289
18290 -- Otherwise must be subprogram
18291
18292 elsif not Is_Subprogram (Def_Id) then
18293 Error_Pragma_Arg
18294 ("argument of pragma% is not subprogram", Arg1);
18295
18296 else
18297 Check_At_Most_N_Arguments (3);
18298 Hom_Id := Def_Id;
18299 Found := False;
18300
18301 -- Loop through homonyms
18302
18303 loop
18304 Def_Id := Get_Base_Subprogram (Hom_Id);
18305
18306 if Is_Imported (Def_Id) then
18307 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
18308 Found := True;
18309 end if;
18310
18311 exit when From_Aspect_Specification (N);
18312 Hom_Id := Homonym (Hom_Id);
18313
18314 exit when No (Hom_Id)
18315 or else Scope (Hom_Id) /= Current_Scope;
18316 end loop;
18317
18318 if not Found then
18319 Error_Pragma_Arg
18320 ("argument of pragma% is not imported subprogram",
18321 Arg1);
18322 end if;
18323 end if;
18324 end Interface_Name;
18325
18326 -----------------------
18327 -- Interrupt_Handler --
18328 -----------------------
18329
18330 -- pragma Interrupt_Handler (handler_NAME);
18331
18332 when Pragma_Interrupt_Handler =>
18333 Check_Ada_83_Warning;
18334 Check_Arg_Count (1);
18335 Check_No_Identifiers;
18336
18337 if No_Run_Time_Mode then
18338 Error_Msg_CRT ("Interrupt_Handler pragma", N);
18339 else
18340 Check_Interrupt_Or_Attach_Handler;
18341 Process_Interrupt_Or_Attach_Handler;
18342 end if;
18343
18344 ------------------------
18345 -- Interrupt_Priority --
18346 ------------------------
18347
18348 -- pragma Interrupt_Priority [(EXPRESSION)];
18349
18350 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
18351 P : constant Node_Id := Parent (N);
18352 Arg : Node_Id;
18353 Ent : Entity_Id;
18354
18355 begin
18356 Check_Ada_83_Warning;
18357
18358 if Arg_Count /= 0 then
18359 Arg := Get_Pragma_Arg (Arg1);
18360 Check_Arg_Count (1);
18361 Check_No_Identifiers;
18362
18363 -- The expression must be analyzed in the special manner
18364 -- described in "Handling of Default and Per-Object
18365 -- Expressions" in sem.ads.
18366
18367 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
18368 end if;
18369
18370 if Nkind (P) not in N_Task_Definition | N_Protected_Definition then
18371 Pragma_Misplaced;
18372 return;
18373
18374 else
18375 Ent := Defining_Identifier (Parent (P));
18376
18377 -- Check duplicate pragma before we chain the pragma in the Rep
18378 -- Item chain of Ent.
18379
18380 Check_Duplicate_Pragma (Ent);
18381 Record_Rep_Item (Ent, N);
18382
18383 -- Check the No_Task_At_Interrupt_Priority restriction
18384
18385 if Nkind (P) = N_Task_Definition then
18386 Check_Restriction (No_Task_At_Interrupt_Priority, N);
18387 end if;
18388 end if;
18389 end Interrupt_Priority;
18390
18391 ---------------------
18392 -- Interrupt_State --
18393 ---------------------
18394
18395 -- pragma Interrupt_State (
18396 -- [Name =>] INTERRUPT_ID,
18397 -- [State =>] INTERRUPT_STATE);
18398
18399 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
18400 -- INTERRUPT_STATE => System | Runtime | User
18401
18402 -- Note: if the interrupt id is given as an identifier, then it must
18403 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
18404 -- given as a static integer expression which must be in the range of
18405 -- Ada.Interrupts.Interrupt_ID.
18406
18407 when Pragma_Interrupt_State => Interrupt_State : declare
18408 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
18409 -- This is the entity Ada.Interrupts.Interrupt_ID;
18410
18411 State_Type : Character;
18412 -- Set to 's'/'r'/'u' for System/Runtime/User
18413
18414 IST_Num : Pos;
18415 -- Index to entry in Interrupt_States table
18416
18417 Int_Val : Uint;
18418 -- Value of interrupt
18419
18420 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
18421 -- The first argument to the pragma
18422
18423 Int_Ent : Entity_Id;
18424 -- Interrupt entity in Ada.Interrupts.Names
18425
18426 begin
18427 GNAT_Pragma;
18428 Check_Arg_Order ((Name_Name, Name_State));
18429 Check_Arg_Count (2);
18430
18431 Check_Optional_Identifier (Arg1, Name_Name);
18432 Check_Optional_Identifier (Arg2, Name_State);
18433 Check_Arg_Is_Identifier (Arg2);
18434
18435 -- First argument is identifier
18436
18437 if Nkind (Arg1X) = N_Identifier then
18438
18439 -- Search list of names in Ada.Interrupts.Names
18440
18441 Int_Ent := First_Entity (RTE (RE_Names));
18442 loop
18443 if No (Int_Ent) then
18444 Error_Pragma_Arg ("invalid interrupt name", Arg1);
18445
18446 elsif Chars (Int_Ent) = Chars (Arg1X) then
18447 Int_Val := Expr_Value (Constant_Value (Int_Ent));
18448 exit;
18449 end if;
18450
18451 Next_Entity (Int_Ent);
18452 end loop;
18453
18454 -- First argument is not an identifier, so it must be a static
18455 -- expression of type Ada.Interrupts.Interrupt_ID.
18456
18457 else
18458 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
18459 Int_Val := Expr_Value (Arg1X);
18460
18461 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
18462 or else
18463 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
18464 then
18465 Error_Pragma_Arg
18466 ("value not in range of type "
18467 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
18468 end if;
18469 end if;
18470
18471 -- Check OK state
18472
18473 case Chars (Get_Pragma_Arg (Arg2)) is
18474 when Name_Runtime => State_Type := 'r';
18475 when Name_System => State_Type := 's';
18476 when Name_User => State_Type := 'u';
18477
18478 when others =>
18479 Error_Pragma_Arg ("invalid interrupt state", Arg2);
18480 end case;
18481
18482 -- Check if entry is already stored
18483
18484 IST_Num := Interrupt_States.First;
18485 loop
18486 -- If entry not found, add it
18487
18488 if IST_Num > Interrupt_States.Last then
18489 Interrupt_States.Append
18490 ((Interrupt_Number => UI_To_Int (Int_Val),
18491 Interrupt_State => State_Type,
18492 Pragma_Loc => Loc));
18493 exit;
18494
18495 -- Case of entry for the same entry
18496
18497 elsif Int_Val = Interrupt_States.Table (IST_Num).
18498 Interrupt_Number
18499 then
18500 -- If state matches, done, no need to make redundant entry
18501
18502 exit when
18503 State_Type = Interrupt_States.Table (IST_Num).
18504 Interrupt_State;
18505
18506 -- Otherwise if state does not match, error
18507
18508 Error_Msg_Sloc :=
18509 Interrupt_States.Table (IST_Num).Pragma_Loc;
18510 Error_Pragma_Arg
18511 ("state conflicts with that given #", Arg2);
18512 exit;
18513 end if;
18514
18515 IST_Num := IST_Num + 1;
18516 end loop;
18517 end Interrupt_State;
18518
18519 ---------------
18520 -- Invariant --
18521 ---------------
18522
18523 -- pragma Invariant
18524 -- ([Entity =>] type_LOCAL_NAME,
18525 -- [Check =>] EXPRESSION
18526 -- [,[Message =>] String_Expression]);
18527
18528 when Pragma_Invariant => Invariant : declare
18529 Discard : Boolean;
18530 Typ : Entity_Id;
18531 Typ_Arg : Node_Id;
18532
18533 begin
18534 GNAT_Pragma;
18535 Check_At_Least_N_Arguments (2);
18536 Check_At_Most_N_Arguments (3);
18537 Check_Optional_Identifier (Arg1, Name_Entity);
18538 Check_Optional_Identifier (Arg2, Name_Check);
18539
18540 if Arg_Count = 3 then
18541 Check_Optional_Identifier (Arg3, Name_Message);
18542 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
18543 end if;
18544
18545 Check_Arg_Is_Local_Name (Arg1);
18546
18547 Typ_Arg := Get_Pragma_Arg (Arg1);
18548 Find_Type (Typ_Arg);
18549 Typ := Entity (Typ_Arg);
18550
18551 -- Nothing to do of the related type is erroneous in some way
18552
18553 if Typ = Any_Type then
18554 return;
18555
18556 -- AI12-0041: Invariants are allowed in interface types
18557
18558 elsif Is_Interface (Typ) then
18559 null;
18560
18561 -- An invariant must apply to a private type, or appear in the
18562 -- private part of a package spec and apply to a completion.
18563 -- a class-wide invariant can only appear on a private declaration
18564 -- or private extension, not a completion.
18565
18566 -- A [class-wide] invariant may be associated a [limited] private
18567 -- type or a private extension.
18568
18569 elsif Ekind (Typ) in E_Limited_Private_Type
18570 | E_Private_Type
18571 | E_Record_Type_With_Private
18572 then
18573 null;
18574
18575 -- A non-class-wide invariant may be associated with the full view
18576 -- of a [limited] private type or a private extension.
18577
18578 elsif Has_Private_Declaration (Typ)
18579 and then not Class_Present (N)
18580 then
18581 null;
18582
18583 -- A class-wide invariant may appear on the partial view only
18584
18585 elsif Class_Present (N) then
18586 Error_Pragma_Arg
18587 ("pragma % only allowed for private type", Arg1);
18588 return;
18589
18590 -- A regular invariant may appear on both views
18591
18592 else
18593 Error_Pragma_Arg
18594 ("pragma % only allowed for private type or corresponding "
18595 & "full view", Arg1);
18596 return;
18597 end if;
18598
18599 -- An invariant associated with an abstract type (this includes
18600 -- interfaces) must be class-wide.
18601
18602 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
18603 Error_Pragma_Arg
18604 ("pragma % not allowed for abstract type", Arg1);
18605 return;
18606 end if;
18607
18608 -- A pragma that applies to a Ghost entity becomes Ghost for the
18609 -- purposes of legality checks and removal of ignored Ghost code.
18610
18611 Mark_Ghost_Pragma (N, Typ);
18612
18613 -- The pragma defines a type-specific invariant, the type is said
18614 -- to have invariants of its "own".
18615
18616 Set_Has_Own_Invariants (Typ);
18617
18618 -- If the invariant is class-wide, then it can be inherited by
18619 -- derived or interface implementing types. The type is said to
18620 -- have "inheritable" invariants.
18621
18622 if Class_Present (N) then
18623 Set_Has_Inheritable_Invariants (Typ);
18624 end if;
18625
18626 -- Chain the pragma on to the rep item chain, for processing when
18627 -- the type is frozen.
18628
18629 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18630
18631 -- Create the declaration of the invariant procedure that will
18632 -- verify the invariant at run time. Interfaces are treated as the
18633 -- partial view of a private type in order to achieve uniformity
18634 -- with the general case. As a result, an interface receives only
18635 -- a "partial" invariant procedure, which is never called.
18636
18637 Build_Invariant_Procedure_Declaration
18638 (Typ => Typ,
18639 Partial_Invariant => Is_Interface (Typ));
18640 end Invariant;
18641
18642 ----------------
18643 -- Keep_Names --
18644 ----------------
18645
18646 -- pragma Keep_Names ([On => ] LOCAL_NAME);
18647
18648 when Pragma_Keep_Names => Keep_Names : declare
18649 Arg : Node_Id;
18650
18651 begin
18652 GNAT_Pragma;
18653 Check_Arg_Count (1);
18654 Check_Optional_Identifier (Arg1, Name_On);
18655 Check_Arg_Is_Local_Name (Arg1);
18656
18657 Arg := Get_Pragma_Arg (Arg1);
18658 Analyze (Arg);
18659
18660 if Etype (Arg) = Any_Type then
18661 return;
18662 end if;
18663
18664 if not Is_Entity_Name (Arg)
18665 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
18666 then
18667 Error_Pragma_Arg
18668 ("pragma% requires a local enumeration type", Arg1);
18669 end if;
18670
18671 Set_Discard_Names (Entity (Arg), False);
18672 end Keep_Names;
18673
18674 -------------
18675 -- License --
18676 -------------
18677
18678 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
18679
18680 when Pragma_License =>
18681 GNAT_Pragma;
18682
18683 -- Do not analyze pragma any further in CodePeer mode, to avoid
18684 -- extraneous errors in this implementation-dependent pragma,
18685 -- which has a different profile on other compilers.
18686
18687 if CodePeer_Mode then
18688 return;
18689 end if;
18690
18691 Check_Arg_Count (1);
18692 Check_No_Identifiers;
18693 Check_Valid_Configuration_Pragma;
18694 Check_Arg_Is_Identifier (Arg1);
18695
18696 declare
18697 Sind : constant Source_File_Index :=
18698 Source_Index (Current_Sem_Unit);
18699
18700 begin
18701 case Chars (Get_Pragma_Arg (Arg1)) is
18702 when Name_GPL =>
18703 Set_License (Sind, GPL);
18704
18705 when Name_Modified_GPL =>
18706 Set_License (Sind, Modified_GPL);
18707
18708 when Name_Restricted =>
18709 Set_License (Sind, Restricted);
18710
18711 when Name_Unrestricted =>
18712 Set_License (Sind, Unrestricted);
18713
18714 when others =>
18715 Error_Pragma_Arg ("invalid license name", Arg1);
18716 end case;
18717 end;
18718
18719 ---------------
18720 -- Link_With --
18721 ---------------
18722
18723 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
18724
18725 when Pragma_Link_With => Link_With : declare
18726 Arg : Node_Id;
18727
18728 begin
18729 GNAT_Pragma;
18730
18731 if Operating_Mode = Generate_Code
18732 and then In_Extended_Main_Source_Unit (N)
18733 then
18734 Check_At_Least_N_Arguments (1);
18735 Check_No_Identifiers;
18736 Check_Is_In_Decl_Part_Or_Package_Spec;
18737 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18738 Start_String;
18739
18740 Arg := Arg1;
18741 while Present (Arg) loop
18742 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
18743
18744 -- Store argument, converting sequences of spaces to a
18745 -- single null character (this is one of the differences
18746 -- in processing between Link_With and Linker_Options).
18747
18748 Arg_Store : declare
18749 C : constant Char_Code := Get_Char_Code (' ');
18750 S : constant String_Id :=
18751 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
18752 L : constant Nat := String_Length (S);
18753 F : Nat := 1;
18754
18755 procedure Skip_Spaces;
18756 -- Advance F past any spaces
18757
18758 -----------------
18759 -- Skip_Spaces --
18760 -----------------
18761
18762 procedure Skip_Spaces is
18763 begin
18764 while F <= L and then Get_String_Char (S, F) = C loop
18765 F := F + 1;
18766 end loop;
18767 end Skip_Spaces;
18768
18769 -- Start of processing for Arg_Store
18770
18771 begin
18772 Skip_Spaces; -- skip leading spaces
18773
18774 -- Loop through characters, changing any embedded
18775 -- sequence of spaces to a single null character (this
18776 -- is how Link_With/Linker_Options differ)
18777
18778 while F <= L loop
18779 if Get_String_Char (S, F) = C then
18780 Skip_Spaces;
18781 exit when F > L;
18782 Store_String_Char (ASCII.NUL);
18783
18784 else
18785 Store_String_Char (Get_String_Char (S, F));
18786 F := F + 1;
18787 end if;
18788 end loop;
18789 end Arg_Store;
18790
18791 Arg := Next (Arg);
18792
18793 if Present (Arg) then
18794 Store_String_Char (ASCII.NUL);
18795 end if;
18796 end loop;
18797
18798 Store_Linker_Option_String (End_String);
18799 end if;
18800 end Link_With;
18801
18802 ------------------
18803 -- Linker_Alias --
18804 ------------------
18805
18806 -- pragma Linker_Alias (
18807 -- [Entity =>] LOCAL_NAME
18808 -- [Target =>] static_string_EXPRESSION);
18809
18810 when Pragma_Linker_Alias =>
18811 GNAT_Pragma;
18812 Check_Arg_Order ((Name_Entity, Name_Target));
18813 Check_Arg_Count (2);
18814 Check_Optional_Identifier (Arg1, Name_Entity);
18815 Check_Optional_Identifier (Arg2, Name_Target);
18816 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18817 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
18818
18819 -- The only processing required is to link this item on to the
18820 -- list of rep items for the given entity. This is accomplished
18821 -- by the call to Rep_Item_Too_Late (when no error is detected
18822 -- and False is returned).
18823
18824 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
18825 return;
18826 else
18827 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
18828 end if;
18829
18830 ------------------------
18831 -- Linker_Constructor --
18832 ------------------------
18833
18834 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
18835
18836 -- Code is shared with Linker_Destructor
18837
18838 -----------------------
18839 -- Linker_Destructor --
18840 -----------------------
18841
18842 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
18843
18844 when Pragma_Linker_Constructor
18845 | Pragma_Linker_Destructor
18846 =>
18847 Linker_Constructor : declare
18848 Arg1_X : Node_Id;
18849 Proc : Entity_Id;
18850
18851 begin
18852 GNAT_Pragma;
18853 Check_Arg_Count (1);
18854 Check_No_Identifiers;
18855 Check_Arg_Is_Local_Name (Arg1);
18856 Arg1_X := Get_Pragma_Arg (Arg1);
18857 Analyze (Arg1_X);
18858 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
18859
18860 if not Is_Library_Level_Entity (Proc) then
18861 Error_Pragma_Arg
18862 ("argument for pragma% must be library level entity", Arg1);
18863 end if;
18864
18865 -- The only processing required is to link this item on to the
18866 -- list of rep items for the given entity. This is accomplished
18867 -- by the call to Rep_Item_Too_Late (when no error is detected
18868 -- and False is returned).
18869
18870 if Rep_Item_Too_Late (Proc, N) then
18871 return;
18872 else
18873 Set_Has_Gigi_Rep_Item (Proc);
18874 end if;
18875 end Linker_Constructor;
18876
18877 --------------------
18878 -- Linker_Options --
18879 --------------------
18880
18881 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
18882
18883 when Pragma_Linker_Options => Linker_Options : declare
18884 Arg : Node_Id;
18885
18886 begin
18887 Check_Ada_83_Warning;
18888 Check_No_Identifiers;
18889 Check_Arg_Count (1);
18890 Check_Is_In_Decl_Part_Or_Package_Spec;
18891 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18892 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
18893
18894 Arg := Arg2;
18895 while Present (Arg) loop
18896 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
18897 Store_String_Char (ASCII.NUL);
18898 Store_String_Chars
18899 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
18900 Arg := Next (Arg);
18901 end loop;
18902
18903 if Operating_Mode = Generate_Code
18904 and then In_Extended_Main_Source_Unit (N)
18905 then
18906 Store_Linker_Option_String (End_String);
18907 end if;
18908 end Linker_Options;
18909
18910 --------------------
18911 -- Linker_Section --
18912 --------------------
18913
18914 -- pragma Linker_Section (
18915 -- [Entity =>] LOCAL_NAME
18916 -- [Section =>] static_string_EXPRESSION);
18917
18918 when Pragma_Linker_Section => Linker_Section : declare
18919 Arg : Node_Id;
18920 Ent : Entity_Id;
18921 LPE : Node_Id;
18922
18923 Ghost_Error_Posted : Boolean := False;
18924 -- Flag set when an error concerning the illegal mix of Ghost and
18925 -- non-Ghost subprograms is emitted.
18926
18927 Ghost_Id : Entity_Id := Empty;
18928 -- The entity of the first Ghost subprogram encountered while
18929 -- processing the arguments of the pragma.
18930
18931 begin
18932 GNAT_Pragma;
18933 Check_Arg_Order ((Name_Entity, Name_Section));
18934 Check_Arg_Count (2);
18935 Check_Optional_Identifier (Arg1, Name_Entity);
18936 Check_Optional_Identifier (Arg2, Name_Section);
18937 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18938 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
18939
18940 -- Check kind of entity
18941
18942 Arg := Get_Pragma_Arg (Arg1);
18943 Ent := Entity (Arg);
18944
18945 case Ekind (Ent) is
18946
18947 -- Objects (constants and variables) and types. For these cases
18948 -- all we need to do is to set the Linker_Section_pragma field,
18949 -- checking that we do not have a duplicate.
18950
18951 when Type_Kind
18952 | E_Constant
18953 | E_Variable
18954 =>
18955 LPE := Linker_Section_Pragma (Ent);
18956
18957 if Present (LPE) then
18958 Error_Msg_Sloc := Sloc (LPE);
18959 Error_Msg_NE
18960 ("Linker_Section already specified for &#", Arg1, Ent);
18961 end if;
18962
18963 Set_Linker_Section_Pragma (Ent, N);
18964
18965 -- A pragma that applies to a Ghost entity becomes Ghost for
18966 -- the purposes of legality checks and removal of ignored
18967 -- Ghost code.
18968
18969 Mark_Ghost_Pragma (N, Ent);
18970
18971 -- Subprograms
18972
18973 when Subprogram_Kind =>
18974
18975 -- Aspect case, entity already set
18976
18977 if From_Aspect_Specification (N) then
18978 Set_Linker_Section_Pragma
18979 (Entity (Corresponding_Aspect (N)), N);
18980
18981 -- Propagate it to its ultimate aliased entity to
18982 -- facilitate the backend processing this attribute
18983 -- in instantiations of generic subprograms.
18984
18985 if Present (Alias (Entity (Corresponding_Aspect (N))))
18986 then
18987 Set_Linker_Section_Pragma
18988 (Ultimate_Alias
18989 (Entity (Corresponding_Aspect (N))), N);
18990 end if;
18991
18992 -- Pragma case, we must climb the homonym chain, but skip
18993 -- any for which the linker section is already set.
18994
18995 else
18996 loop
18997 if No (Linker_Section_Pragma (Ent)) then
18998 Set_Linker_Section_Pragma (Ent, N);
18999
19000 -- Propagate it to its ultimate aliased entity to
19001 -- facilitate the backend processing this attribute
19002 -- in instantiations of generic subprograms.
19003
19004 if Present (Alias (Ent)) then
19005 Set_Linker_Section_Pragma
19006 (Ultimate_Alias (Ent), N);
19007 end if;
19008
19009 -- A pragma that applies to a Ghost entity becomes
19010 -- Ghost for the purposes of legality checks and
19011 -- removal of ignored Ghost code.
19012
19013 Mark_Ghost_Pragma (N, Ent);
19014
19015 -- Capture the entity of the first Ghost subprogram
19016 -- being processed for error detection purposes.
19017
19018 if Is_Ghost_Entity (Ent) then
19019 if No (Ghost_Id) then
19020 Ghost_Id := Ent;
19021 end if;
19022
19023 -- Otherwise the subprogram is non-Ghost. It is
19024 -- illegal to mix references to Ghost and non-Ghost
19025 -- entities (SPARK RM 6.9).
19026
19027 elsif Present (Ghost_Id)
19028 and then not Ghost_Error_Posted
19029 then
19030 Ghost_Error_Posted := True;
19031
19032 Error_Msg_Name_1 := Pname;
19033 Error_Msg_N
19034 ("pragma % cannot mention ghost and "
19035 & "non-ghost subprograms", N);
19036
19037 Error_Msg_Sloc := Sloc (Ghost_Id);
19038 Error_Msg_NE
19039 ("\& # declared as ghost", N, Ghost_Id);
19040
19041 Error_Msg_Sloc := Sloc (Ent);
19042 Error_Msg_NE
19043 ("\& # declared as non-ghost", N, Ent);
19044 end if;
19045 end if;
19046
19047 Ent := Homonym (Ent);
19048 exit when No (Ent)
19049 or else Scope (Ent) /= Current_Scope;
19050 end loop;
19051 end if;
19052
19053 -- All other cases are illegal
19054
19055 when others =>
19056 Error_Pragma_Arg
19057 ("pragma% applies only to objects, subprograms, and types",
19058 Arg1);
19059 end case;
19060 end Linker_Section;
19061
19062 ----------
19063 -- List --
19064 ----------
19065
19066 -- pragma List (On | Off)
19067
19068 -- There is nothing to do here, since we did all the processing for
19069 -- this pragma in Par.Prag (so that it works properly even in syntax
19070 -- only mode).
19071
19072 when Pragma_List =>
19073 null;
19074
19075 ---------------
19076 -- Lock_Free --
19077 ---------------
19078
19079 -- pragma Lock_Free [(Boolean_EXPRESSION)];
19080
19081 when Pragma_Lock_Free => Lock_Free : declare
19082 P : constant Node_Id := Parent (N);
19083 Arg : Node_Id;
19084 Ent : Entity_Id;
19085 Val : Boolean;
19086
19087 begin
19088 Check_No_Identifiers;
19089 Check_At_Most_N_Arguments (1);
19090
19091 -- Protected definition case
19092
19093 if Nkind (P) = N_Protected_Definition then
19094 Ent := Defining_Identifier (Parent (P));
19095
19096 -- One argument
19097
19098 if Arg_Count = 1 then
19099 Arg := Get_Pragma_Arg (Arg1);
19100 Val := Is_True (Static_Boolean (Arg));
19101
19102 -- No arguments (expression is considered to be True)
19103
19104 else
19105 Val := True;
19106 end if;
19107
19108 -- Check duplicate pragma before we chain the pragma in the Rep
19109 -- Item chain of Ent.
19110
19111 Check_Duplicate_Pragma (Ent);
19112 Record_Rep_Item (Ent, N);
19113 Set_Uses_Lock_Free (Ent, Val);
19114
19115 -- Anything else is incorrect placement
19116
19117 else
19118 Pragma_Misplaced;
19119 end if;
19120 end Lock_Free;
19121
19122 --------------------
19123 -- Locking_Policy --
19124 --------------------
19125
19126 -- pragma Locking_Policy (policy_IDENTIFIER);
19127
19128 when Pragma_Locking_Policy => declare
19129 subtype LP_Range is Name_Id
19130 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
19131 LP_Val : LP_Range;
19132 LP : Character;
19133
19134 begin
19135 Check_Ada_83_Warning;
19136 Check_Arg_Count (1);
19137 Check_No_Identifiers;
19138 Check_Arg_Is_Locking_Policy (Arg1);
19139 Check_Valid_Configuration_Pragma;
19140 LP_Val := Chars (Get_Pragma_Arg (Arg1));
19141
19142 case LP_Val is
19143 when Name_Ceiling_Locking => LP := 'C';
19144 when Name_Concurrent_Readers_Locking => LP := 'R';
19145 when Name_Inheritance_Locking => LP := 'I';
19146 end case;
19147
19148 if Locking_Policy /= ' '
19149 and then Locking_Policy /= LP
19150 then
19151 Error_Msg_Sloc := Locking_Policy_Sloc;
19152 Error_Pragma ("locking policy incompatible with policy#");
19153
19154 -- Set new policy, but always preserve System_Location since we
19155 -- like the error message with the run time name.
19156
19157 else
19158 Locking_Policy := LP;
19159
19160 if Locking_Policy_Sloc /= System_Location then
19161 Locking_Policy_Sloc := Loc;
19162 end if;
19163 end if;
19164 end;
19165
19166 -------------------
19167 -- Loop_Optimize --
19168 -------------------
19169
19170 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
19171
19172 -- OPTIMIZATION_HINT ::=
19173 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
19174
19175 when Pragma_Loop_Optimize => Loop_Optimize : declare
19176 Hint : Node_Id;
19177
19178 begin
19179 GNAT_Pragma;
19180 Check_At_Least_N_Arguments (1);
19181 Check_No_Identifiers;
19182
19183 Hint := First (Pragma_Argument_Associations (N));
19184 while Present (Hint) loop
19185 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
19186 Name_No_Unroll,
19187 Name_Unroll,
19188 Name_No_Vector,
19189 Name_Vector);
19190 Next (Hint);
19191 end loop;
19192
19193 Check_Loop_Pragma_Placement;
19194 end Loop_Optimize;
19195
19196 ------------------
19197 -- Loop_Variant --
19198 ------------------
19199
19200 -- pragma Loop_Variant
19201 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
19202
19203 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
19204
19205 -- CHANGE_DIRECTION ::= Increases | Decreases
19206
19207 when Pragma_Loop_Variant => Loop_Variant : declare
19208 Variant : Node_Id;
19209
19210 begin
19211 GNAT_Pragma;
19212 Check_At_Least_N_Arguments (1);
19213 Check_Loop_Pragma_Placement;
19214
19215 -- Process all increasing / decreasing expressions
19216
19217 Variant := First (Pragma_Argument_Associations (N));
19218 while Present (Variant) loop
19219 if Chars (Variant) = No_Name then
19220 Error_Pragma_Arg_Ident ("expect name `Increases`", Variant);
19221
19222 elsif Chars (Variant) not in Name_Decreases | Name_Increases
19223 then
19224 declare
19225 Name : String := Get_Name_String (Chars (Variant));
19226
19227 begin
19228 -- It is a common mistake to write "Increasing" for
19229 -- "Increases" or "Decreasing" for "Decreases". Recognize
19230 -- specially names starting with "incr" or "decr" to
19231 -- suggest the corresponding name.
19232
19233 System.Case_Util.To_Lower (Name);
19234
19235 if Name'Length >= 4
19236 and then Name (1 .. 4) = "incr"
19237 then
19238 Error_Pragma_Arg_Ident
19239 ("expect name `Increases`", Variant);
19240
19241 elsif Name'Length >= 4
19242 and then Name (1 .. 4) = "decr"
19243 then
19244 Error_Pragma_Arg_Ident
19245 ("expect name `Decreases`", Variant);
19246
19247 else
19248 Error_Pragma_Arg_Ident
19249 ("expect name `Increases` or `Decreases`", Variant);
19250 end if;
19251 end;
19252 end if;
19253
19254 Preanalyze_Assert_Expression
19255 (Expression (Variant), Any_Discrete);
19256
19257 Next (Variant);
19258 end loop;
19259 end Loop_Variant;
19260
19261 -----------------------
19262 -- Machine_Attribute --
19263 -----------------------
19264
19265 -- pragma Machine_Attribute (
19266 -- [Entity =>] LOCAL_NAME,
19267 -- [Attribute_Name =>] static_string_EXPRESSION
19268 -- [, [Info =>] static_EXPRESSION {, static_EXPRESSION}] );
19269
19270 when Pragma_Machine_Attribute => Machine_Attribute : declare
19271 Arg : Node_Id;
19272 Def_Id : Entity_Id;
19273
19274 begin
19275 GNAT_Pragma;
19276 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
19277
19278 if Arg_Count >= 3 then
19279 Check_Optional_Identifier (Arg3, Name_Info);
19280 Arg := Arg3;
19281 while Present (Arg) loop
19282 Check_Arg_Is_OK_Static_Expression (Arg);
19283 Arg := Next (Arg);
19284 end loop;
19285 else
19286 Check_Arg_Count (2);
19287 end if;
19288
19289 Check_Optional_Identifier (Arg1, Name_Entity);
19290 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
19291 Check_Arg_Is_Local_Name (Arg1);
19292 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19293 Def_Id := Entity (Get_Pragma_Arg (Arg1));
19294
19295 if Is_Access_Type (Def_Id) then
19296 Def_Id := Designated_Type (Def_Id);
19297 end if;
19298
19299 if Rep_Item_Too_Early (Def_Id, N) then
19300 return;
19301 end if;
19302
19303 Def_Id := Underlying_Type (Def_Id);
19304
19305 -- The only processing required is to link this item on to the
19306 -- list of rep items for the given entity. This is accomplished
19307 -- by the call to Rep_Item_Too_Late (when no error is detected
19308 -- and False is returned).
19309
19310 if Rep_Item_Too_Late (Def_Id, N) then
19311 return;
19312 else
19313 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
19314 end if;
19315 end Machine_Attribute;
19316
19317 ----------
19318 -- Main --
19319 ----------
19320
19321 -- pragma Main
19322 -- (MAIN_OPTION [, MAIN_OPTION]);
19323
19324 -- MAIN_OPTION ::=
19325 -- [STACK_SIZE =>] static_integer_EXPRESSION
19326 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
19327 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
19328
19329 when Pragma_Main => Main : declare
19330 Args : Args_List (1 .. 3);
19331 Names : constant Name_List (1 .. 3) := (
19332 Name_Stack_Size,
19333 Name_Task_Stack_Size_Default,
19334 Name_Time_Slicing_Enabled);
19335
19336 Nod : Node_Id;
19337
19338 begin
19339 GNAT_Pragma;
19340 Gather_Associations (Names, Args);
19341
19342 for J in 1 .. 2 loop
19343 if Present (Args (J)) then
19344 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19345 end if;
19346 end loop;
19347
19348 if Present (Args (3)) then
19349 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
19350 end if;
19351
19352 Nod := Next (N);
19353 while Present (Nod) loop
19354 if Nkind (Nod) = N_Pragma
19355 and then Pragma_Name (Nod) = Name_Main
19356 then
19357 Error_Msg_Name_1 := Pname;
19358 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19359 end if;
19360
19361 Next (Nod);
19362 end loop;
19363 end Main;
19364
19365 ------------------
19366 -- Main_Storage --
19367 ------------------
19368
19369 -- pragma Main_Storage
19370 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
19371
19372 -- MAIN_STORAGE_OPTION ::=
19373 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
19374 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
19375
19376 when Pragma_Main_Storage => Main_Storage : declare
19377 Args : Args_List (1 .. 2);
19378 Names : constant Name_List (1 .. 2) := (
19379 Name_Working_Storage,
19380 Name_Top_Guard);
19381
19382 Nod : Node_Id;
19383
19384 begin
19385 GNAT_Pragma;
19386 Gather_Associations (Names, Args);
19387
19388 for J in 1 .. 2 loop
19389 if Present (Args (J)) then
19390 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19391 end if;
19392 end loop;
19393
19394 Check_In_Main_Program;
19395
19396 Nod := Next (N);
19397 while Present (Nod) loop
19398 if Nkind (Nod) = N_Pragma
19399 and then Pragma_Name (Nod) = Name_Main_Storage
19400 then
19401 Error_Msg_Name_1 := Pname;
19402 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19403 end if;
19404
19405 Next (Nod);
19406 end loop;
19407 end Main_Storage;
19408
19409 ----------------------------
19410 -- Max_Entry_Queue_Length --
19411 ----------------------------
19412
19413 -- pragma Max_Entry_Queue_Length (static_integer_EXPRESSION);
19414
19415 -- This processing is shared by Pragma_Max_Entry_Queue_Depth and
19416 -- Pragma_Max_Queue_Length.
19417
19418 when Pragma_Max_Entry_Queue_Length
19419 | Pragma_Max_Entry_Queue_Depth
19420 | Pragma_Max_Queue_Length
19421 =>
19422 Max_Entry_Queue_Length : declare
19423 Arg : Node_Id;
19424 Entry_Decl : Node_Id;
19425 Entry_Id : Entity_Id;
19426 Val : Uint;
19427
19428 begin
19429 if Prag_Id = Pragma_Max_Entry_Queue_Depth
19430 or else Prag_Id = Pragma_Max_Queue_Length
19431 then
19432 GNAT_Pragma;
19433 end if;
19434
19435 Check_Arg_Count (1);
19436
19437 Entry_Decl :=
19438 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
19439
19440 -- Entry declaration
19441
19442 if Nkind (Entry_Decl) = N_Entry_Declaration then
19443
19444 -- Entry illegally within a task
19445
19446 if Nkind (Parent (N)) = N_Task_Definition then
19447 Error_Pragma ("pragma % cannot apply to task entries");
19448 return;
19449 end if;
19450
19451 Entry_Id := Defining_Entity (Entry_Decl);
19452
19453 -- Otherwise the pragma is associated with an illegal construct
19454
19455 else
19456 Error_Pragma
19457 ("pragma % must apply to a protected entry declaration");
19458 return;
19459 end if;
19460
19461 -- Mark the pragma as Ghost if the related subprogram is also
19462 -- Ghost. This also ensures that any expansion performed further
19463 -- below will produce Ghost nodes.
19464
19465 Mark_Ghost_Pragma (N, Entry_Id);
19466
19467 -- Analyze the Integer expression
19468
19469 Arg := Get_Pragma_Arg (Arg1);
19470 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
19471
19472 Val := Expr_Value (Arg);
19473
19474 if Val < -1 then
19475 Error_Pragma_Arg
19476 ("argument for pragma% cannot be less than -1", Arg1);
19477
19478 elsif not UI_Is_In_Int_Range (Val) then
19479 Error_Pragma_Arg
19480 ("argument for pragma% out of range of Integer", Arg1);
19481
19482 end if;
19483
19484 Record_Rep_Item (Entry_Id, N);
19485 end Max_Entry_Queue_Length;
19486
19487 -----------------
19488 -- Memory_Size --
19489 -----------------
19490
19491 -- pragma Memory_Size (NUMERIC_LITERAL)
19492
19493 when Pragma_Memory_Size =>
19494 GNAT_Pragma;
19495
19496 -- Memory size is simply ignored
19497
19498 Check_No_Identifiers;
19499 Check_Arg_Count (1);
19500 Check_Arg_Is_Integer_Literal (Arg1);
19501
19502 -------------
19503 -- No_Body --
19504 -------------
19505
19506 -- pragma No_Body;
19507
19508 -- The only correct use of this pragma is on its own in a file, in
19509 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
19510 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
19511 -- check for a file containing nothing but a No_Body pragma). If we
19512 -- attempt to process it during normal semantics processing, it means
19513 -- it was misplaced.
19514
19515 when Pragma_No_Body =>
19516 GNAT_Pragma;
19517 Pragma_Misplaced;
19518
19519 -----------------------------
19520 -- No_Elaboration_Code_All --
19521 -----------------------------
19522
19523 -- pragma No_Elaboration_Code_All;
19524
19525 when Pragma_No_Elaboration_Code_All =>
19526 GNAT_Pragma;
19527 Check_Valid_Library_Unit_Pragma;
19528
19529 if Nkind (N) = N_Null_Statement then
19530 return;
19531 end if;
19532
19533 -- Must appear for a spec or generic spec
19534
19535 if Nkind (Unit (Cunit (Current_Sem_Unit))) not in
19536 N_Generic_Package_Declaration |
19537 N_Generic_Subprogram_Declaration |
19538 N_Package_Declaration |
19539 N_Subprogram_Declaration
19540 then
19541 Error_Pragma
19542 (Fix_Error
19543 ("pragma% can only occur for package "
19544 & "or subprogram spec"));
19545 end if;
19546
19547 -- Set flag in unit table
19548
19549 Set_No_Elab_Code_All (Current_Sem_Unit);
19550
19551 -- Set restriction No_Elaboration_Code if this is the main unit
19552
19553 if Current_Sem_Unit = Main_Unit then
19554 Set_Restriction (No_Elaboration_Code, N);
19555 end if;
19556
19557 -- If we are in the main unit or in an extended main source unit,
19558 -- then we also add it to the configuration restrictions so that
19559 -- it will apply to all units in the extended main source.
19560
19561 if Current_Sem_Unit = Main_Unit
19562 or else In_Extended_Main_Source_Unit (N)
19563 then
19564 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
19565 end if;
19566
19567 -- If in main extended unit, activate transitive with test
19568
19569 if In_Extended_Main_Source_Unit (N) then
19570 Opt.No_Elab_Code_All_Pragma := N;
19571 end if;
19572
19573 -----------------------------
19574 -- No_Component_Reordering --
19575 -----------------------------
19576
19577 -- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
19578
19579 when Pragma_No_Component_Reordering => No_Comp_Reordering : declare
19580 E : Entity_Id;
19581 E_Id : Node_Id;
19582
19583 begin
19584 GNAT_Pragma;
19585 Check_At_Most_N_Arguments (1);
19586
19587 if Arg_Count = 0 then
19588 Check_Valid_Configuration_Pragma;
19589 Opt.No_Component_Reordering := True;
19590
19591 else
19592 Check_Optional_Identifier (Arg2, Name_Entity);
19593 Check_Arg_Is_Local_Name (Arg1);
19594 E_Id := Get_Pragma_Arg (Arg1);
19595
19596 if Etype (E_Id) = Any_Type then
19597 return;
19598 end if;
19599
19600 E := Entity (E_Id);
19601
19602 if not Is_Record_Type (E) then
19603 Error_Pragma_Arg ("pragma% requires record type", Arg1);
19604 end if;
19605
19606 Set_No_Reordering (Base_Type (E));
19607 end if;
19608 end No_Comp_Reordering;
19609
19610 --------------------------
19611 -- No_Heap_Finalization --
19612 --------------------------
19613
19614 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
19615
19616 when Pragma_No_Heap_Finalization => No_Heap_Finalization : declare
19617 Context : constant Node_Id := Parent (N);
19618 Typ_Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
19619 Prev : Node_Id;
19620 Typ : Entity_Id;
19621
19622 begin
19623 GNAT_Pragma;
19624 Check_No_Identifiers;
19625
19626 -- The pragma appears in a configuration file
19627
19628 if No (Context) then
19629 Check_Arg_Count (0);
19630 Check_Valid_Configuration_Pragma;
19631
19632 -- Detect a duplicate pragma
19633
19634 if Present (No_Heap_Finalization_Pragma) then
19635 Duplication_Error
19636 (Prag => N,
19637 Prev => No_Heap_Finalization_Pragma);
19638 raise Pragma_Exit;
19639 end if;
19640
19641 No_Heap_Finalization_Pragma := N;
19642
19643 -- Otherwise the pragma should be associated with a library-level
19644 -- named access-to-object type.
19645
19646 else
19647 Check_Arg_Count (1);
19648 Check_Arg_Is_Local_Name (Arg1);
19649
19650 Find_Type (Typ_Arg);
19651 Typ := Entity (Typ_Arg);
19652
19653 -- The type being subjected to the pragma is erroneous
19654
19655 if Typ = Any_Type then
19656 Error_Pragma ("cannot find type referenced by pragma %");
19657
19658 -- The pragma is applied to an incomplete or generic formal
19659 -- type way too early.
19660
19661 elsif Rep_Item_Too_Early (Typ, N) then
19662 return;
19663
19664 else
19665 Typ := Underlying_Type (Typ);
19666 end if;
19667
19668 -- The pragma must apply to an access-to-object type
19669
19670 if Ekind (Typ) in E_Access_Type | E_General_Access_Type then
19671 null;
19672
19673 -- Give a detailed error message on all other access type kinds
19674
19675 elsif Ekind (Typ) = E_Access_Protected_Subprogram_Type then
19676 Error_Pragma
19677 ("pragma % cannot apply to access protected subprogram "
19678 & "type");
19679
19680 elsif Ekind (Typ) = E_Access_Subprogram_Type then
19681 Error_Pragma
19682 ("pragma % cannot apply to access subprogram type");
19683
19684 elsif Is_Anonymous_Access_Type (Typ) then
19685 Error_Pragma
19686 ("pragma % cannot apply to anonymous access type");
19687
19688 -- Give a general error message in case the pragma applies to a
19689 -- non-access type.
19690
19691 else
19692 Error_Pragma
19693 ("pragma % must apply to library level access type");
19694 end if;
19695
19696 -- At this point the argument denotes an access-to-object type.
19697 -- Ensure that the type is declared at the library level.
19698
19699 if Is_Library_Level_Entity (Typ) then
19700 null;
19701
19702 -- Quietly ignore an access-to-object type originally declared
19703 -- at the library level within a generic, but instantiated at
19704 -- a non-library level. As a result the access-to-object type
19705 -- "loses" its No_Heap_Finalization property.
19706
19707 elsif In_Instance then
19708 raise Pragma_Exit;
19709
19710 else
19711 Error_Pragma
19712 ("pragma % must apply to library level access type");
19713 end if;
19714
19715 -- Detect a duplicate pragma
19716
19717 if Present (No_Heap_Finalization_Pragma) then
19718 Duplication_Error
19719 (Prag => N,
19720 Prev => No_Heap_Finalization_Pragma);
19721 raise Pragma_Exit;
19722
19723 else
19724 Prev := Get_Pragma (Typ, Pragma_No_Heap_Finalization);
19725
19726 if Present (Prev) then
19727 Duplication_Error
19728 (Prag => N,
19729 Prev => Prev);
19730 raise Pragma_Exit;
19731 end if;
19732 end if;
19733
19734 Record_Rep_Item (Typ, N);
19735 end if;
19736 end No_Heap_Finalization;
19737
19738 ---------------
19739 -- No_Inline --
19740 ---------------
19741
19742 -- pragma No_Inline ( NAME {, NAME} );
19743
19744 when Pragma_No_Inline =>
19745 GNAT_Pragma;
19746 Process_Inline (Suppressed);
19747
19748 ---------------
19749 -- No_Return --
19750 ---------------
19751
19752 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
19753
19754 when Pragma_No_Return => No_Return : declare
19755 Arg : Node_Id;
19756 E : Entity_Id;
19757 Found : Boolean;
19758 Id : Node_Id;
19759
19760 Ghost_Error_Posted : Boolean := False;
19761 -- Flag set when an error concerning the illegal mix of Ghost and
19762 -- non-Ghost subprograms is emitted.
19763
19764 Ghost_Id : Entity_Id := Empty;
19765 -- The entity of the first Ghost procedure encountered while
19766 -- processing the arguments of the pragma.
19767
19768 begin
19769 Ada_2005_Pragma;
19770 Check_At_Least_N_Arguments (1);
19771
19772 -- Loop through arguments of pragma
19773
19774 Arg := Arg1;
19775 while Present (Arg) loop
19776 Check_Arg_Is_Local_Name (Arg);
19777 Id := Get_Pragma_Arg (Arg);
19778 Analyze (Id);
19779
19780 if not Is_Entity_Name (Id) then
19781 Error_Pragma_Arg ("entity name required", Arg);
19782 end if;
19783
19784 if Etype (Id) = Any_Type then
19785 raise Pragma_Exit;
19786 end if;
19787
19788 -- Loop to find matching procedures or functions (Ada 2020)
19789
19790 E := Entity (Id);
19791
19792 Found := False;
19793 while Present (E)
19794 and then Scope (E) = Current_Scope
19795 loop
19796 -- Ada 2020 (AI12-0269): A function can be No_Return
19797
19798 if Ekind (E) in E_Generic_Procedure | E_Procedure
19799 or else (Ada_Version >= Ada_2020
19800 and then
19801 Ekind (E) in E_Generic_Function | E_Function)
19802 then
19803 -- Check that the pragma is not applied to a body.
19804 -- First check the specless body case, to give a
19805 -- different error message. These checks do not apply
19806 -- if Relaxed_RM_Semantics, to accommodate other Ada
19807 -- compilers. Disable these checks under -gnatd.J.
19808
19809 if not Debug_Flag_Dot_JJ then
19810 if Nkind (Parent (Declaration_Node (E))) =
19811 N_Subprogram_Body
19812 and then not Relaxed_RM_Semantics
19813 then
19814 Error_Pragma
19815 ("pragma% requires separate spec and must come "
19816 & "before body");
19817 end if;
19818
19819 -- Now the "specful" body case
19820
19821 if Rep_Item_Too_Late (E, N) then
19822 raise Pragma_Exit;
19823 end if;
19824 end if;
19825
19826 Set_No_Return (E);
19827
19828 -- A pragma that applies to a Ghost entity becomes Ghost
19829 -- for the purposes of legality checks and removal of
19830 -- ignored Ghost code.
19831
19832 Mark_Ghost_Pragma (N, E);
19833
19834 -- Capture the entity of the first Ghost procedure being
19835 -- processed for error detection purposes.
19836
19837 if Is_Ghost_Entity (E) then
19838 if No (Ghost_Id) then
19839 Ghost_Id := E;
19840 end if;
19841
19842 -- Otherwise the subprogram is non-Ghost. It is illegal
19843 -- to mix references to Ghost and non-Ghost entities
19844 -- (SPARK RM 6.9).
19845
19846 elsif Present (Ghost_Id)
19847 and then not Ghost_Error_Posted
19848 then
19849 Ghost_Error_Posted := True;
19850
19851 Error_Msg_Name_1 := Pname;
19852 Error_Msg_N
19853 ("pragma % cannot mention ghost and non-ghost "
19854 & "procedures", N);
19855
19856 Error_Msg_Sloc := Sloc (Ghost_Id);
19857 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
19858
19859 Error_Msg_Sloc := Sloc (E);
19860 Error_Msg_NE ("\& # declared as non-ghost", N, E);
19861 end if;
19862
19863 -- Set flag on any alias as well
19864
19865 if Is_Overloadable (E) and then Present (Alias (E)) then
19866 Set_No_Return (Alias (E));
19867 end if;
19868
19869 Found := True;
19870 end if;
19871
19872 exit when From_Aspect_Specification (N);
19873 E := Homonym (E);
19874 end loop;
19875
19876 -- If entity in not in current scope it may be the enclosing
19877 -- suprogram body to which the aspect applies.
19878
19879 if not Found then
19880 if Entity (Id) = Current_Scope
19881 and then From_Aspect_Specification (N)
19882 then
19883 Set_No_Return (Entity (Id));
19884
19885 elsif Ada_Version >= Ada_2020 then
19886 Error_Pragma_Arg
19887 ("no subprogram& found for pragma%", Arg);
19888
19889 else
19890 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
19891 end if;
19892 end if;
19893
19894 Next (Arg);
19895 end loop;
19896 end No_Return;
19897
19898 -----------------
19899 -- No_Run_Time --
19900 -----------------
19901
19902 -- pragma No_Run_Time;
19903
19904 -- Note: this pragma is retained for backwards compatibility. See
19905 -- body of Rtsfind for full details on its handling.
19906
19907 when Pragma_No_Run_Time =>
19908 GNAT_Pragma;
19909 Check_Valid_Configuration_Pragma;
19910 Check_Arg_Count (0);
19911
19912 -- Remove backward compatibility if Build_Type is FSF or GPL and
19913 -- generate a warning.
19914
19915 declare
19916 Ignore : constant Boolean := Build_Type in FSF .. GPL;
19917 begin
19918 if Ignore then
19919 Error_Pragma ("pragma% is ignored, has no effect??");
19920 else
19921 No_Run_Time_Mode := True;
19922 Configurable_Run_Time_Mode := True;
19923
19924 -- Set Duration to 32 bits if word size is 32
19925
19926 if Ttypes.System_Word_Size = 32 then
19927 Duration_32_Bits_On_Target := True;
19928 end if;
19929
19930 -- Set appropriate restrictions
19931
19932 Set_Restriction (No_Finalization, N);
19933 Set_Restriction (No_Exception_Handlers, N);
19934 Set_Restriction (Max_Tasks, N, 0);
19935 Set_Restriction (No_Tasking, N);
19936 end if;
19937 end;
19938
19939 -----------------------
19940 -- No_Tagged_Streams --
19941 -----------------------
19942
19943 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
19944
19945 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
19946 E : Entity_Id;
19947 E_Id : Node_Id;
19948
19949 begin
19950 GNAT_Pragma;
19951 Check_At_Most_N_Arguments (1);
19952
19953 -- One argument case
19954
19955 if Arg_Count = 1 then
19956 Check_Optional_Identifier (Arg1, Name_Entity);
19957 Check_Arg_Is_Local_Name (Arg1);
19958 E_Id := Get_Pragma_Arg (Arg1);
19959
19960 if Etype (E_Id) = Any_Type then
19961 return;
19962 end if;
19963
19964 E := Entity (E_Id);
19965
19966 Check_Duplicate_Pragma (E);
19967
19968 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
19969 Error_Pragma_Arg
19970 ("argument for pragma% must be root tagged type", Arg1);
19971 end if;
19972
19973 if Rep_Item_Too_Early (E, N)
19974 or else
19975 Rep_Item_Too_Late (E, N)
19976 then
19977 return;
19978 else
19979 Set_No_Tagged_Streams_Pragma (E, N);
19980 end if;
19981
19982 -- Zero argument case
19983
19984 else
19985 Check_Is_In_Decl_Part_Or_Package_Spec;
19986 No_Tagged_Streams := N;
19987 end if;
19988 end No_Tagged_Strms;
19989
19990 ------------------------
19991 -- No_Strict_Aliasing --
19992 ------------------------
19993
19994 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
19995
19996 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
19997 E : Entity_Id;
19998 E_Id : Node_Id;
19999
20000 begin
20001 GNAT_Pragma;
20002 Check_At_Most_N_Arguments (1);
20003
20004 if Arg_Count = 0 then
20005 Check_Valid_Configuration_Pragma;
20006 Opt.No_Strict_Aliasing := True;
20007
20008 else
20009 Check_Optional_Identifier (Arg2, Name_Entity);
20010 Check_Arg_Is_Local_Name (Arg1);
20011 E_Id := Get_Pragma_Arg (Arg1);
20012
20013 if Etype (E_Id) = Any_Type then
20014 return;
20015 end if;
20016
20017 E := Entity (E_Id);
20018
20019 if not Is_Access_Type (E) then
20020 Error_Pragma_Arg ("pragma% requires access type", Arg1);
20021 end if;
20022
20023 Set_No_Strict_Aliasing (Base_Type (E));
20024 end if;
20025 end No_Strict_Aliasing;
20026
20027 -----------------------
20028 -- Normalize_Scalars --
20029 -----------------------
20030
20031 -- pragma Normalize_Scalars;
20032
20033 when Pragma_Normalize_Scalars =>
20034 Check_Ada_83_Warning;
20035 Check_Arg_Count (0);
20036 Check_Valid_Configuration_Pragma;
20037
20038 -- Normalize_Scalars creates false positives in CodePeer, and
20039 -- incorrect negative results in GNATprove mode, so ignore this
20040 -- pragma in these modes.
20041
20042 if not (CodePeer_Mode or GNATprove_Mode) then
20043 Normalize_Scalars := True;
20044 Init_Or_Norm_Scalars := True;
20045 end if;
20046
20047 -----------------
20048 -- Obsolescent --
20049 -----------------
20050
20051 -- pragma Obsolescent;
20052
20053 -- pragma Obsolescent (
20054 -- [Message =>] static_string_EXPRESSION
20055 -- [,[Version =>] Ada_05]]);
20056
20057 -- pragma Obsolescent (
20058 -- [Entity =>] NAME
20059 -- [,[Message =>] static_string_EXPRESSION
20060 -- [,[Version =>] Ada_05]] );
20061
20062 when Pragma_Obsolescent => Obsolescent : declare
20063 Decl : Node_Id;
20064 Ename : Node_Id;
20065
20066 procedure Set_Obsolescent (E : Entity_Id);
20067 -- Given an entity Ent, mark it as obsolescent if appropriate
20068
20069 ---------------------
20070 -- Set_Obsolescent --
20071 ---------------------
20072
20073 procedure Set_Obsolescent (E : Entity_Id) is
20074 Active : Boolean;
20075 Ent : Entity_Id;
20076 S : String_Id;
20077
20078 begin
20079 Active := True;
20080 Ent := E;
20081
20082 -- A pragma that applies to a Ghost entity becomes Ghost for
20083 -- the purposes of legality checks and removal of ignored Ghost
20084 -- code.
20085
20086 Mark_Ghost_Pragma (N, E);
20087
20088 -- Entity name was given
20089
20090 if Present (Ename) then
20091
20092 -- If entity name matches, we are fine.
20093
20094 if Chars (Ename) = Chars (Ent) then
20095 Set_Entity (Ename, Ent);
20096 Generate_Reference (Ent, Ename);
20097
20098 -- If entity name does not match, only possibility is an
20099 -- enumeration literal from an enumeration type declaration.
20100
20101 elsif Ekind (Ent) /= E_Enumeration_Type then
20102 Error_Pragma
20103 ("pragma % entity name does not match declaration");
20104
20105 else
20106 Ent := First_Literal (E);
20107 loop
20108 if No (Ent) then
20109 Error_Pragma
20110 ("pragma % entity name does not match any "
20111 & "enumeration literal");
20112
20113 elsif Chars (Ent) = Chars (Ename) then
20114 Set_Entity (Ename, Ent);
20115 Generate_Reference (Ent, Ename);
20116 exit;
20117
20118 else
20119 Next_Literal (Ent);
20120 end if;
20121 end loop;
20122 end if;
20123 end if;
20124
20125 -- Ent points to entity to be marked
20126
20127 if Arg_Count >= 1 then
20128
20129 -- Deal with static string argument
20130
20131 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
20132 S := Strval (Get_Pragma_Arg (Arg1));
20133
20134 for J in 1 .. String_Length (S) loop
20135 if not In_Character_Range (Get_String_Char (S, J)) then
20136 Error_Pragma_Arg
20137 ("pragma% argument does not allow wide characters",
20138 Arg1);
20139 end if;
20140 end loop;
20141
20142 Obsolescent_Warnings.Append
20143 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
20144
20145 -- Check for Ada_05 parameter
20146
20147 if Arg_Count /= 1 then
20148 Check_Arg_Count (2);
20149
20150 declare
20151 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
20152
20153 begin
20154 Check_Arg_Is_Identifier (Argx);
20155
20156 if Chars (Argx) /= Name_Ada_05 then
20157 Error_Msg_Name_2 := Name_Ada_05;
20158 Error_Pragma_Arg
20159 ("only allowed argument for pragma% is %", Argx);
20160 end if;
20161
20162 if Ada_Version_Explicit < Ada_2005
20163 or else not Warn_On_Ada_2005_Compatibility
20164 then
20165 Active := False;
20166 end if;
20167 end;
20168 end if;
20169 end if;
20170
20171 -- Set flag if pragma active
20172
20173 if Active then
20174 Set_Is_Obsolescent (Ent);
20175 end if;
20176
20177 return;
20178 end Set_Obsolescent;
20179
20180 -- Start of processing for pragma Obsolescent
20181
20182 begin
20183 GNAT_Pragma;
20184
20185 Check_At_Most_N_Arguments (3);
20186
20187 -- See if first argument specifies an entity name
20188
20189 if Arg_Count >= 1
20190 and then
20191 (Chars (Arg1) = Name_Entity
20192 or else
20193 Nkind (Get_Pragma_Arg (Arg1)) in
20194 N_Character_Literal | N_Identifier | N_Operator_Symbol)
20195 then
20196 Ename := Get_Pragma_Arg (Arg1);
20197
20198 -- Eliminate first argument, so we can share processing
20199
20200 Arg1 := Arg2;
20201 Arg2 := Arg3;
20202 Arg_Count := Arg_Count - 1;
20203
20204 -- No Entity name argument given
20205
20206 else
20207 Ename := Empty;
20208 end if;
20209
20210 if Arg_Count >= 1 then
20211 Check_Optional_Identifier (Arg1, Name_Message);
20212
20213 if Arg_Count = 2 then
20214 Check_Optional_Identifier (Arg2, Name_Version);
20215 end if;
20216 end if;
20217
20218 -- Get immediately preceding declaration
20219
20220 Decl := Prev (N);
20221 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
20222 Prev (Decl);
20223 end loop;
20224
20225 -- Cases where we do not follow anything other than another pragma
20226
20227 if No (Decl) then
20228
20229 -- First case: library level compilation unit declaration with
20230 -- the pragma immediately following the declaration.
20231
20232 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
20233 Set_Obsolescent
20234 (Defining_Entity (Unit (Parent (Parent (N)))));
20235 return;
20236
20237 -- Case 2: library unit placement for package
20238
20239 else
20240 declare
20241 Ent : constant Entity_Id := Find_Lib_Unit_Name;
20242 begin
20243 if Is_Package_Or_Generic_Package (Ent) then
20244 Set_Obsolescent (Ent);
20245 return;
20246 end if;
20247 end;
20248 end if;
20249
20250 -- Cases where we must follow a declaration, including an
20251 -- abstract subprogram declaration, which is not in the
20252 -- other node subtypes.
20253
20254 else
20255 if Nkind (Decl) not in N_Declaration
20256 and then Nkind (Decl) not in N_Later_Decl_Item
20257 and then Nkind (Decl) not in N_Generic_Declaration
20258 and then Nkind (Decl) not in N_Renaming_Declaration
20259 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
20260 then
20261 Error_Pragma
20262 ("pragma% misplaced, "
20263 & "must immediately follow a declaration");
20264
20265 else
20266 Set_Obsolescent (Defining_Entity (Decl));
20267 return;
20268 end if;
20269 end if;
20270 end Obsolescent;
20271
20272 --------------
20273 -- Optimize --
20274 --------------
20275
20276 -- pragma Optimize (Time | Space | Off);
20277
20278 -- The actual check for optimize is done in Gigi. Note that this
20279 -- pragma does not actually change the optimization setting, it
20280 -- simply checks that it is consistent with the pragma.
20281
20282 when Pragma_Optimize =>
20283 Check_No_Identifiers;
20284 Check_Arg_Count (1);
20285 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
20286
20287 ------------------------
20288 -- Optimize_Alignment --
20289 ------------------------
20290
20291 -- pragma Optimize_Alignment (Time | Space | Off);
20292
20293 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
20294 GNAT_Pragma;
20295 Check_No_Identifiers;
20296 Check_Arg_Count (1);
20297 Check_Valid_Configuration_Pragma;
20298
20299 declare
20300 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
20301 begin
20302 case Nam is
20303 when Name_Off => Opt.Optimize_Alignment := 'O';
20304 when Name_Space => Opt.Optimize_Alignment := 'S';
20305 when Name_Time => Opt.Optimize_Alignment := 'T';
20306
20307 when others =>
20308 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
20309 end case;
20310 end;
20311
20312 -- Set indication that mode is set locally. If we are in fact in a
20313 -- configuration pragma file, this setting is harmless since the
20314 -- switch will get reset anyway at the start of each unit.
20315
20316 Optimize_Alignment_Local := True;
20317 end Optimize_Alignment;
20318
20319 -------------
20320 -- Ordered --
20321 -------------
20322
20323 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
20324
20325 when Pragma_Ordered => Ordered : declare
20326 Assoc : constant Node_Id := Arg1;
20327 Type_Id : Node_Id;
20328 Typ : Entity_Id;
20329
20330 begin
20331 GNAT_Pragma;
20332 Check_No_Identifiers;
20333 Check_Arg_Count (1);
20334 Check_Arg_Is_Local_Name (Arg1);
20335
20336 Type_Id := Get_Pragma_Arg (Assoc);
20337 Find_Type (Type_Id);
20338 Typ := Entity (Type_Id);
20339
20340 if Typ = Any_Type then
20341 return;
20342 else
20343 Typ := Underlying_Type (Typ);
20344 end if;
20345
20346 if not Is_Enumeration_Type (Typ) then
20347 Error_Pragma ("pragma% must specify enumeration type");
20348 end if;
20349
20350 Check_First_Subtype (Arg1);
20351 Set_Has_Pragma_Ordered (Base_Type (Typ));
20352 end Ordered;
20353
20354 -------------------
20355 -- Overflow_Mode --
20356 -------------------
20357
20358 -- pragma Overflow_Mode
20359 -- ([General => ] MODE [, [Assertions => ] MODE]);
20360
20361 -- MODE := STRICT | MINIMIZED | ELIMINATED
20362
20363 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
20364 -- since System.Bignums makes this assumption. This is true of nearly
20365 -- all (all?) targets.
20366
20367 when Pragma_Overflow_Mode => Overflow_Mode : declare
20368 function Get_Overflow_Mode
20369 (Name : Name_Id;
20370 Arg : Node_Id) return Overflow_Mode_Type;
20371 -- Function to process one pragma argument, Arg. If an identifier
20372 -- is present, it must be Name. Mode type is returned if a valid
20373 -- argument exists, otherwise an error is signalled.
20374
20375 -----------------------
20376 -- Get_Overflow_Mode --
20377 -----------------------
20378
20379 function Get_Overflow_Mode
20380 (Name : Name_Id;
20381 Arg : Node_Id) return Overflow_Mode_Type
20382 is
20383 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
20384
20385 begin
20386 Check_Optional_Identifier (Arg, Name);
20387 Check_Arg_Is_Identifier (Argx);
20388
20389 if Chars (Argx) = Name_Strict then
20390 return Strict;
20391
20392 elsif Chars (Argx) = Name_Minimized then
20393 return Minimized;
20394
20395 elsif Chars (Argx) = Name_Eliminated then
20396 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
20397 Error_Pragma_Arg
20398 ("Eliminated not implemented on this target", Argx);
20399 else
20400 return Eliminated;
20401 end if;
20402
20403 else
20404 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
20405 end if;
20406 end Get_Overflow_Mode;
20407
20408 -- Start of processing for Overflow_Mode
20409
20410 begin
20411 GNAT_Pragma;
20412 Check_At_Least_N_Arguments (1);
20413 Check_At_Most_N_Arguments (2);
20414
20415 -- Process first argument
20416
20417 Scope_Suppress.Overflow_Mode_General :=
20418 Get_Overflow_Mode (Name_General, Arg1);
20419
20420 -- Case of only one argument
20421
20422 if Arg_Count = 1 then
20423 Scope_Suppress.Overflow_Mode_Assertions :=
20424 Scope_Suppress.Overflow_Mode_General;
20425
20426 -- Case of two arguments present
20427
20428 else
20429 Scope_Suppress.Overflow_Mode_Assertions :=
20430 Get_Overflow_Mode (Name_Assertions, Arg2);
20431 end if;
20432 end Overflow_Mode;
20433
20434 --------------------------
20435 -- Overriding Renamings --
20436 --------------------------
20437
20438 -- pragma Overriding_Renamings;
20439
20440 when Pragma_Overriding_Renamings =>
20441 GNAT_Pragma;
20442 Check_Arg_Count (0);
20443 Check_Valid_Configuration_Pragma;
20444 Overriding_Renamings := True;
20445
20446 ----------
20447 -- Pack --
20448 ----------
20449
20450 -- pragma Pack (first_subtype_LOCAL_NAME);
20451
20452 when Pragma_Pack => Pack : declare
20453 Assoc : constant Node_Id := Arg1;
20454 Ctyp : Entity_Id;
20455 Ignore : Boolean := False;
20456 Typ : Entity_Id;
20457 Type_Id : Node_Id;
20458
20459 begin
20460 Check_No_Identifiers;
20461 Check_Arg_Count (1);
20462 Check_Arg_Is_Local_Name (Arg1);
20463 Type_Id := Get_Pragma_Arg (Assoc);
20464
20465 if not Is_Entity_Name (Type_Id)
20466 or else not Is_Type (Entity (Type_Id))
20467 then
20468 Error_Pragma_Arg
20469 ("argument for pragma% must be type or subtype", Arg1);
20470 end if;
20471
20472 Find_Type (Type_Id);
20473 Typ := Entity (Type_Id);
20474
20475 if Typ = Any_Type
20476 or else Rep_Item_Too_Early (Typ, N)
20477 then
20478 return;
20479 else
20480 Typ := Underlying_Type (Typ);
20481 end if;
20482
20483 -- A pragma that applies to a Ghost entity becomes Ghost for the
20484 -- purposes of legality checks and removal of ignored Ghost code.
20485
20486 Mark_Ghost_Pragma (N, Typ);
20487
20488 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
20489 Error_Pragma ("pragma% must specify array or record type");
20490 end if;
20491
20492 Check_First_Subtype (Arg1);
20493 Check_Duplicate_Pragma (Typ);
20494
20495 -- Array type
20496
20497 if Is_Array_Type (Typ) then
20498 Ctyp := Component_Type (Typ);
20499
20500 -- Ignore pack that does nothing
20501
20502 if Known_Static_Esize (Ctyp)
20503 and then Known_Static_RM_Size (Ctyp)
20504 and then Esize (Ctyp) = RM_Size (Ctyp)
20505 and then Addressable (Esize (Ctyp))
20506 then
20507 Ignore := True;
20508 end if;
20509
20510 -- Process OK pragma Pack. Note that if there is a separate
20511 -- component clause present, the Pack will be cancelled. This
20512 -- processing is in Freeze.
20513
20514 if not Rep_Item_Too_Late (Typ, N) then
20515
20516 -- In CodePeer mode, we do not need complex front-end
20517 -- expansions related to pragma Pack, so disable handling
20518 -- of pragma Pack.
20519
20520 if CodePeer_Mode then
20521 null;
20522
20523 -- Normal case where we do the pack action
20524
20525 else
20526 if not Ignore then
20527 Set_Is_Packed (Base_Type (Typ));
20528 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20529 end if;
20530
20531 Set_Has_Pragma_Pack (Base_Type (Typ));
20532 end if;
20533 end if;
20534
20535 -- For record types, the pack is always effective
20536
20537 else pragma Assert (Is_Record_Type (Typ));
20538 if not Rep_Item_Too_Late (Typ, N) then
20539 Set_Is_Packed (Base_Type (Typ));
20540 Set_Has_Pragma_Pack (Base_Type (Typ));
20541 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20542 end if;
20543 end if;
20544 end Pack;
20545
20546 ----------
20547 -- Page --
20548 ----------
20549
20550 -- pragma Page;
20551
20552 -- There is nothing to do here, since we did all the processing for
20553 -- this pragma in Par.Prag (so that it works properly even in syntax
20554 -- only mode).
20555
20556 when Pragma_Page =>
20557 null;
20558
20559 -------------
20560 -- Part_Of --
20561 -------------
20562
20563 -- pragma Part_Of (ABSTRACT_STATE);
20564
20565 -- ABSTRACT_STATE ::= NAME
20566
20567 when Pragma_Part_Of => Part_Of : declare
20568 procedure Propagate_Part_Of
20569 (Pack_Id : Entity_Id;
20570 State_Id : Entity_Id;
20571 Instance : Node_Id);
20572 -- Propagate the Part_Of indicator to all abstract states and
20573 -- objects declared in the visible state space of a package
20574 -- denoted by Pack_Id. State_Id is the encapsulating state.
20575 -- Instance is the package instantiation node.
20576
20577 -----------------------
20578 -- Propagate_Part_Of --
20579 -----------------------
20580
20581 procedure Propagate_Part_Of
20582 (Pack_Id : Entity_Id;
20583 State_Id : Entity_Id;
20584 Instance : Node_Id)
20585 is
20586 Has_Item : Boolean := False;
20587 -- Flag set when the visible state space contains at least one
20588 -- abstract state or variable.
20589
20590 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
20591 -- Propagate the Part_Of indicator to all abstract states and
20592 -- objects declared in the visible state space of a package
20593 -- denoted by Pack_Id.
20594
20595 -----------------------
20596 -- Propagate_Part_Of --
20597 -----------------------
20598
20599 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
20600 Constits : Elist_Id;
20601 Item_Id : Entity_Id;
20602
20603 begin
20604 -- Traverse the entity chain of the package and set relevant
20605 -- attributes of abstract states and objects declared in the
20606 -- visible state space of the package.
20607
20608 Item_Id := First_Entity (Pack_Id);
20609 while Present (Item_Id)
20610 and then not In_Private_Part (Item_Id)
20611 loop
20612 -- Do not consider internally generated items
20613
20614 if not Comes_From_Source (Item_Id) then
20615 null;
20616
20617 -- Do not consider generic formals or their corresponding
20618 -- actuals because they are not part of a visible state.
20619 -- Note that both entities are marked as hidden.
20620
20621 elsif Is_Hidden (Item_Id) then
20622 null;
20623
20624 -- The Part_Of indicator turns an abstract state or an
20625 -- object into a constituent of the encapsulating state.
20626 -- Note that constants are considered here even though
20627 -- they may not depend on variable input. This check is
20628 -- left to the SPARK prover.
20629
20630 elsif Ekind (Item_Id) in
20631 E_Abstract_State | E_Constant | E_Variable
20632 then
20633 Has_Item := True;
20634 Constits := Part_Of_Constituents (State_Id);
20635
20636 if No (Constits) then
20637 Constits := New_Elmt_List;
20638 Set_Part_Of_Constituents (State_Id, Constits);
20639 end if;
20640
20641 Append_Elmt (Item_Id, Constits);
20642 Set_Encapsulating_State (Item_Id, State_Id);
20643
20644 -- Recursively handle nested packages and instantiations
20645
20646 elsif Ekind (Item_Id) = E_Package then
20647 Propagate_Part_Of (Item_Id);
20648 end if;
20649
20650 Next_Entity (Item_Id);
20651 end loop;
20652 end Propagate_Part_Of;
20653
20654 -- Start of processing for Propagate_Part_Of
20655
20656 begin
20657 Propagate_Part_Of (Pack_Id);
20658
20659 -- Detect a package instantiation that is subject to a Part_Of
20660 -- indicator, but has no visible state.
20661
20662 if not Has_Item then
20663 SPARK_Msg_NE
20664 ("package instantiation & has Part_Of indicator but "
20665 & "lacks visible state", Instance, Pack_Id);
20666 end if;
20667 end Propagate_Part_Of;
20668
20669 -- Local variables
20670
20671 Constits : Elist_Id;
20672 Encap : Node_Id;
20673 Encap_Id : Entity_Id;
20674 Item_Id : Entity_Id;
20675 Legal : Boolean;
20676 Stmt : Node_Id;
20677
20678 -- Start of processing for Part_Of
20679
20680 begin
20681 GNAT_Pragma;
20682 Check_No_Identifiers;
20683 Check_Arg_Count (1);
20684
20685 Stmt := Find_Related_Context (N, Do_Checks => True);
20686
20687 -- Object declaration
20688
20689 if Nkind (Stmt) = N_Object_Declaration then
20690 null;
20691
20692 -- Package instantiation
20693
20694 elsif Nkind (Stmt) = N_Package_Instantiation then
20695 null;
20696
20697 -- Single concurrent type declaration
20698
20699 elsif Is_Single_Concurrent_Type_Declaration (Stmt) then
20700 null;
20701
20702 -- Otherwise the pragma is associated with an illegal construct
20703
20704 else
20705 Pragma_Misplaced;
20706 return;
20707 end if;
20708
20709 -- Extract the entity of the related object declaration or package
20710 -- instantiation. In the case of the instantiation, use the entity
20711 -- of the instance spec.
20712
20713 if Nkind (Stmt) = N_Package_Instantiation then
20714 Stmt := Instance_Spec (Stmt);
20715 end if;
20716
20717 Item_Id := Defining_Entity (Stmt);
20718
20719 -- A pragma that applies to a Ghost entity becomes Ghost for the
20720 -- purposes of legality checks and removal of ignored Ghost code.
20721
20722 Mark_Ghost_Pragma (N, Item_Id);
20723
20724 -- Chain the pragma on the contract for further processing by
20725 -- Analyze_Part_Of_In_Decl_Part or for completeness.
20726
20727 Add_Contract_Item (N, Item_Id);
20728
20729 -- A variable may act as constituent of a single concurrent type
20730 -- which in turn could be declared after the variable. Due to this
20731 -- discrepancy, the full analysis of indicator Part_Of is delayed
20732 -- until the end of the enclosing declarative region (see routine
20733 -- Analyze_Part_Of_In_Decl_Part).
20734
20735 if Ekind (Item_Id) = E_Variable then
20736 null;
20737
20738 -- Otherwise indicator Part_Of applies to a constant or a package
20739 -- instantiation.
20740
20741 else
20742 Encap := Get_Pragma_Arg (Arg1);
20743
20744 -- Detect any discrepancies between the placement of the
20745 -- constant or package instantiation with respect to state
20746 -- space and the encapsulating state.
20747
20748 Analyze_Part_Of
20749 (Indic => N,
20750 Item_Id => Item_Id,
20751 Encap => Encap,
20752 Encap_Id => Encap_Id,
20753 Legal => Legal);
20754
20755 if Legal then
20756 pragma Assert (Present (Encap_Id));
20757
20758 if Ekind (Item_Id) = E_Constant then
20759 Constits := Part_Of_Constituents (Encap_Id);
20760
20761 if No (Constits) then
20762 Constits := New_Elmt_List;
20763 Set_Part_Of_Constituents (Encap_Id, Constits);
20764 end if;
20765
20766 Append_Elmt (Item_Id, Constits);
20767 Set_Encapsulating_State (Item_Id, Encap_Id);
20768
20769 -- Propagate the Part_Of indicator to the visible state
20770 -- space of the package instantiation.
20771
20772 else
20773 Propagate_Part_Of
20774 (Pack_Id => Item_Id,
20775 State_Id => Encap_Id,
20776 Instance => Stmt);
20777 end if;
20778 end if;
20779 end if;
20780 end Part_Of;
20781
20782 ----------------------------------
20783 -- Partition_Elaboration_Policy --
20784 ----------------------------------
20785
20786 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
20787
20788 when Pragma_Partition_Elaboration_Policy => PEP : declare
20789 subtype PEP_Range is Name_Id
20790 range First_Partition_Elaboration_Policy_Name
20791 .. Last_Partition_Elaboration_Policy_Name;
20792 PEP_Val : PEP_Range;
20793 PEP : Character;
20794
20795 begin
20796 Ada_2005_Pragma;
20797 Check_Arg_Count (1);
20798 Check_No_Identifiers;
20799 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
20800 Check_Valid_Configuration_Pragma;
20801 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
20802
20803 case PEP_Val is
20804 when Name_Concurrent => PEP := 'C';
20805 when Name_Sequential => PEP := 'S';
20806 end case;
20807
20808 if Partition_Elaboration_Policy /= ' '
20809 and then Partition_Elaboration_Policy /= PEP
20810 then
20811 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
20812 Error_Pragma
20813 ("partition elaboration policy incompatible with policy#");
20814
20815 -- Set new policy, but always preserve System_Location since we
20816 -- like the error message with the run time name.
20817
20818 else
20819 Partition_Elaboration_Policy := PEP;
20820
20821 if Partition_Elaboration_Policy_Sloc /= System_Location then
20822 Partition_Elaboration_Policy_Sloc := Loc;
20823 end if;
20824 end if;
20825 end PEP;
20826
20827 -------------
20828 -- Passive --
20829 -------------
20830
20831 -- pragma Passive [(PASSIVE_FORM)];
20832
20833 -- PASSIVE_FORM ::= Semaphore | No
20834
20835 when Pragma_Passive =>
20836 GNAT_Pragma;
20837
20838 if Nkind (Parent (N)) /= N_Task_Definition then
20839 Error_Pragma ("pragma% must be within task definition");
20840 end if;
20841
20842 if Arg_Count /= 0 then
20843 Check_Arg_Count (1);
20844 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
20845 end if;
20846
20847 ----------------------------------
20848 -- Preelaborable_Initialization --
20849 ----------------------------------
20850
20851 -- pragma Preelaborable_Initialization (DIRECT_NAME);
20852
20853 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
20854 Ent : Entity_Id;
20855
20856 begin
20857 Ada_2005_Pragma;
20858 Check_Arg_Count (1);
20859 Check_No_Identifiers;
20860 Check_Arg_Is_Identifier (Arg1);
20861 Check_Arg_Is_Local_Name (Arg1);
20862 Check_First_Subtype (Arg1);
20863 Ent := Entity (Get_Pragma_Arg (Arg1));
20864
20865 -- A pragma that applies to a Ghost entity becomes Ghost for the
20866 -- purposes of legality checks and removal of ignored Ghost code.
20867
20868 Mark_Ghost_Pragma (N, Ent);
20869
20870 -- The pragma may come from an aspect on a private declaration,
20871 -- even if the freeze point at which this is analyzed in the
20872 -- private part after the full view.
20873
20874 if Has_Private_Declaration (Ent)
20875 and then From_Aspect_Specification (N)
20876 then
20877 null;
20878
20879 -- Check appropriate type argument
20880
20881 elsif Is_Private_Type (Ent)
20882 or else Is_Protected_Type (Ent)
20883 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
20884
20885 -- AI05-0028: The pragma applies to all composite types. Note
20886 -- that we apply this binding interpretation to earlier versions
20887 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
20888 -- choice since there are other compilers that do the same.
20889
20890 or else Is_Composite_Type (Ent)
20891 then
20892 null;
20893
20894 else
20895 Error_Pragma_Arg
20896 ("pragma % can only be applied to private, formal derived, "
20897 & "protected, or composite type", Arg1);
20898 end if;
20899
20900 -- Give an error if the pragma is applied to a protected type that
20901 -- does not qualify (due to having entries, or due to components
20902 -- that do not qualify).
20903
20904 if Is_Protected_Type (Ent)
20905 and then not Has_Preelaborable_Initialization (Ent)
20906 then
20907 Error_Msg_N
20908 ("protected type & does not have preelaborable "
20909 & "initialization", Ent);
20910
20911 -- Otherwise mark the type as definitely having preelaborable
20912 -- initialization.
20913
20914 else
20915 Set_Known_To_Have_Preelab_Init (Ent);
20916 end if;
20917
20918 if Has_Pragma_Preelab_Init (Ent)
20919 and then Warn_On_Redundant_Constructs
20920 then
20921 Error_Pragma ("?r?duplicate pragma%!");
20922 else
20923 Set_Has_Pragma_Preelab_Init (Ent);
20924 end if;
20925 end Preelab_Init;
20926
20927 --------------------
20928 -- Persistent_BSS --
20929 --------------------
20930
20931 -- pragma Persistent_BSS [(object_NAME)];
20932
20933 when Pragma_Persistent_BSS => Persistent_BSS : declare
20934 Decl : Node_Id;
20935 Ent : Entity_Id;
20936 Prag : Node_Id;
20937
20938 begin
20939 GNAT_Pragma;
20940 Check_At_Most_N_Arguments (1);
20941
20942 -- Case of application to specific object (one argument)
20943
20944 if Arg_Count = 1 then
20945 Check_Arg_Is_Library_Level_Local_Name (Arg1);
20946
20947 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
20948 or else
20949 Ekind (Entity (Get_Pragma_Arg (Arg1))) not in
20950 E_Variable | E_Constant
20951 then
20952 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
20953 end if;
20954
20955 Ent := Entity (Get_Pragma_Arg (Arg1));
20956
20957 -- A pragma that applies to a Ghost entity becomes Ghost for
20958 -- the purposes of legality checks and removal of ignored Ghost
20959 -- code.
20960
20961 Mark_Ghost_Pragma (N, Ent);
20962
20963 -- Check for duplication before inserting in list of
20964 -- representation items.
20965
20966 Check_Duplicate_Pragma (Ent);
20967
20968 if Rep_Item_Too_Late (Ent, N) then
20969 return;
20970 end if;
20971
20972 Decl := Parent (Ent);
20973
20974 if Present (Expression (Decl)) then
20975 -- Variables in Persistent_BSS cannot be initialized, so
20976 -- turn off any initialization that might be caused by
20977 -- pragmas Initialize_Scalars or Normalize_Scalars.
20978
20979 if Kill_Range_Check (Expression (Decl)) then
20980 Prag :=
20981 Make_Pragma (Loc,
20982 Name_Suppress_Initialization,
20983 Pragma_Argument_Associations => New_List (
20984 Make_Pragma_Argument_Association (Loc,
20985 Expression => New_Occurrence_Of (Ent, Loc))));
20986 Insert_Before (N, Prag);
20987 Analyze (Prag);
20988
20989 else
20990 Error_Pragma_Arg
20991 ("object for pragma% cannot have initialization", Arg1);
20992 end if;
20993 end if;
20994
20995 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
20996 Error_Pragma_Arg
20997 ("object type for pragma% is not potentially persistent",
20998 Arg1);
20999 end if;
21000
21001 Prag :=
21002 Make_Linker_Section_Pragma
21003 (Ent, Loc, ".persistent.bss");
21004 Insert_After (N, Prag);
21005 Analyze (Prag);
21006
21007 -- Case of use as configuration pragma with no arguments
21008
21009 else
21010 Check_Valid_Configuration_Pragma;
21011 Persistent_BSS_Mode := True;
21012 end if;
21013 end Persistent_BSS;
21014
21015 --------------------
21016 -- Rename_Pragma --
21017 --------------------
21018
21019 -- pragma Rename_Pragma (
21020 -- [New_Name =>] IDENTIFIER,
21021 -- [Renamed =>] pragma_IDENTIFIER);
21022
21023 when Pragma_Rename_Pragma => Rename_Pragma : declare
21024 New_Name : constant Node_Id := Get_Pragma_Arg (Arg1);
21025 Old_Name : constant Node_Id := Get_Pragma_Arg (Arg2);
21026
21027 begin
21028 GNAT_Pragma;
21029 Check_Valid_Configuration_Pragma;
21030 Check_Arg_Count (2);
21031 Check_Optional_Identifier (Arg1, Name_New_Name);
21032 Check_Optional_Identifier (Arg2, Name_Renamed);
21033
21034 if Nkind (New_Name) /= N_Identifier then
21035 Error_Pragma_Arg ("identifier expected", Arg1);
21036 end if;
21037
21038 if Nkind (Old_Name) /= N_Identifier then
21039 Error_Pragma_Arg ("identifier expected", Arg2);
21040 end if;
21041
21042 -- The New_Name arg should not be an existing pragma (but we allow
21043 -- it; it's just a warning). The Old_Name arg must be an existing
21044 -- pragma.
21045
21046 if Is_Pragma_Name (Chars (New_Name)) then
21047 Error_Pragma_Arg ("??pragma is already defined", Arg1);
21048 end if;
21049
21050 if not Is_Pragma_Name (Chars (Old_Name)) then
21051 Error_Pragma_Arg ("existing pragma name expected", Arg1);
21052 end if;
21053
21054 Map_Pragma_Name (From => Chars (New_Name), To => Chars (Old_Name));
21055 end Rename_Pragma;
21056
21057 -----------------------------------
21058 -- Post/Post_Class/Postcondition --
21059 -----------------------------------
21060
21061 -- pragma Post (Boolean_EXPRESSION);
21062 -- pragma Post_Class (Boolean_EXPRESSION);
21063 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
21064 -- [,[Message =>] String_EXPRESSION]);
21065
21066 -- Characteristics:
21067
21068 -- * Analysis - The annotation undergoes initial checks to verify
21069 -- the legal placement and context. Secondary checks preanalyze the
21070 -- expression in:
21071
21072 -- Analyze_Pre_Post_Condition_In_Decl_Part
21073
21074 -- * Expansion - The annotation is expanded during the expansion of
21075 -- the related subprogram [body] contract as performed in:
21076
21077 -- Expand_Subprogram_Contract
21078
21079 -- * Template - The annotation utilizes the generic template of the
21080 -- related subprogram [body] when it is:
21081
21082 -- aspect on subprogram declaration
21083 -- aspect on stand-alone subprogram body
21084 -- pragma on stand-alone subprogram body
21085
21086 -- The annotation must prepare its own template when it is:
21087
21088 -- pragma on subprogram declaration
21089
21090 -- * Globals - Capture of global references must occur after full
21091 -- analysis.
21092
21093 -- * Instance - The annotation is instantiated automatically when
21094 -- the related generic subprogram [body] is instantiated except for
21095 -- the "pragma on subprogram declaration" case. In that scenario
21096 -- the annotation must instantiate itself.
21097
21098 when Pragma_Post
21099 | Pragma_Post_Class
21100 | Pragma_Postcondition
21101 =>
21102 Analyze_Pre_Post_Condition;
21103
21104 --------------------------------
21105 -- Pre/Pre_Class/Precondition --
21106 --------------------------------
21107
21108 -- pragma Pre (Boolean_EXPRESSION);
21109 -- pragma Pre_Class (Boolean_EXPRESSION);
21110 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
21111 -- [,[Message =>] String_EXPRESSION]);
21112
21113 -- Characteristics:
21114
21115 -- * Analysis - The annotation undergoes initial checks to verify
21116 -- the legal placement and context. Secondary checks preanalyze the
21117 -- expression in:
21118
21119 -- Analyze_Pre_Post_Condition_In_Decl_Part
21120
21121 -- * Expansion - The annotation is expanded during the expansion of
21122 -- the related subprogram [body] contract as performed in:
21123
21124 -- Expand_Subprogram_Contract
21125
21126 -- * Template - The annotation utilizes the generic template of the
21127 -- related subprogram [body] when it is:
21128
21129 -- aspect on subprogram declaration
21130 -- aspect on stand-alone subprogram body
21131 -- pragma on stand-alone subprogram body
21132
21133 -- The annotation must prepare its own template when it is:
21134
21135 -- pragma on subprogram declaration
21136
21137 -- * Globals - Capture of global references must occur after full
21138 -- analysis.
21139
21140 -- * Instance - The annotation is instantiated automatically when
21141 -- the related generic subprogram [body] is instantiated except for
21142 -- the "pragma on subprogram declaration" case. In that scenario
21143 -- the annotation must instantiate itself.
21144
21145 when Pragma_Pre
21146 | Pragma_Pre_Class
21147 | Pragma_Precondition
21148 =>
21149 Analyze_Pre_Post_Condition;
21150
21151 ---------------
21152 -- Predicate --
21153 ---------------
21154
21155 -- pragma Predicate
21156 -- ([Entity =>] type_LOCAL_NAME,
21157 -- [Check =>] boolean_EXPRESSION);
21158
21159 when Pragma_Predicate => Predicate : declare
21160 Discard : Boolean;
21161 Typ : Entity_Id;
21162 Type_Id : Node_Id;
21163
21164 begin
21165 GNAT_Pragma;
21166 Check_Arg_Count (2);
21167 Check_Optional_Identifier (Arg1, Name_Entity);
21168 Check_Optional_Identifier (Arg2, Name_Check);
21169
21170 Check_Arg_Is_Local_Name (Arg1);
21171
21172 Type_Id := Get_Pragma_Arg (Arg1);
21173 Find_Type (Type_Id);
21174 Typ := Entity (Type_Id);
21175
21176 if Typ = Any_Type then
21177 return;
21178 end if;
21179
21180 -- A pragma that applies to a Ghost entity becomes Ghost for the
21181 -- purposes of legality checks and removal of ignored Ghost code.
21182
21183 Mark_Ghost_Pragma (N, Typ);
21184
21185 -- The remaining processing is simply to link the pragma on to
21186 -- the rep item chain, for processing when the type is frozen.
21187 -- This is accomplished by a call to Rep_Item_Too_Late. We also
21188 -- mark the type as having predicates.
21189
21190 -- If the current policy for predicate checking is Ignore mark the
21191 -- subtype accordingly. In the case of predicates we consider them
21192 -- enabled unless Ignore is specified (either directly or with a
21193 -- general Assertion_Policy pragma) to preserve existing warnings.
21194
21195 Set_Has_Predicates (Typ);
21196
21197 -- Indicate that the pragma must be processed at the point the
21198 -- type is frozen, as is done for the corresponding aspect.
21199
21200 Set_Has_Delayed_Aspects (Typ);
21201 Set_Has_Delayed_Freeze (Typ);
21202
21203 Set_Predicates_Ignored (Typ,
21204 Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore);
21205 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
21206 end Predicate;
21207
21208 -----------------------
21209 -- Predicate_Failure --
21210 -----------------------
21211
21212 -- pragma Predicate_Failure
21213 -- ([Entity =>] type_LOCAL_NAME,
21214 -- [Message =>] string_EXPRESSION);
21215
21216 when Pragma_Predicate_Failure => Predicate_Failure : declare
21217 Discard : Boolean;
21218 Typ : Entity_Id;
21219 Type_Id : Node_Id;
21220
21221 begin
21222 GNAT_Pragma;
21223 Check_Arg_Count (2);
21224 Check_Optional_Identifier (Arg1, Name_Entity);
21225 Check_Optional_Identifier (Arg2, Name_Message);
21226
21227 Check_Arg_Is_Local_Name (Arg1);
21228
21229 Type_Id := Get_Pragma_Arg (Arg1);
21230 Find_Type (Type_Id);
21231 Typ := Entity (Type_Id);
21232
21233 if Typ = Any_Type then
21234 return;
21235 end if;
21236
21237 -- A pragma that applies to a Ghost entity becomes Ghost for the
21238 -- purposes of legality checks and removal of ignored Ghost code.
21239
21240 Mark_Ghost_Pragma (N, Typ);
21241
21242 -- The remaining processing is simply to link the pragma on to
21243 -- the rep item chain, for processing when the type is frozen.
21244 -- This is accomplished by a call to Rep_Item_Too_Late.
21245
21246 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
21247 end Predicate_Failure;
21248
21249 ------------------
21250 -- Preelaborate --
21251 ------------------
21252
21253 -- pragma Preelaborate [(library_unit_NAME)];
21254
21255 -- Set the flag Is_Preelaborated of program unit name entity
21256
21257 when Pragma_Preelaborate => Preelaborate : declare
21258 Pa : constant Node_Id := Parent (N);
21259 Pk : constant Node_Kind := Nkind (Pa);
21260 Ent : Entity_Id;
21261
21262 begin
21263 Check_Ada_83_Warning;
21264 Check_Valid_Library_Unit_Pragma;
21265
21266 if Nkind (N) = N_Null_Statement then
21267 return;
21268 end if;
21269
21270 Ent := Find_Lib_Unit_Name;
21271
21272 -- A pragma that applies to a Ghost entity becomes Ghost for the
21273 -- purposes of legality checks and removal of ignored Ghost code.
21274
21275 Mark_Ghost_Pragma (N, Ent);
21276 Check_Duplicate_Pragma (Ent);
21277
21278 -- This filters out pragmas inside generic parents that show up
21279 -- inside instantiations. Pragmas that come from aspects in the
21280 -- unit are not ignored.
21281
21282 if Present (Ent) then
21283 if Pk = N_Package_Specification
21284 and then Present (Generic_Parent (Pa))
21285 and then not From_Aspect_Specification (N)
21286 then
21287 null;
21288
21289 else
21290 if not Debug_Flag_U then
21291 Set_Is_Preelaborated (Ent);
21292
21293 if Legacy_Elaboration_Checks then
21294 Set_Suppress_Elaboration_Warnings (Ent);
21295 end if;
21296 end if;
21297 end if;
21298 end if;
21299 end Preelaborate;
21300
21301 -------------------------------
21302 -- Prefix_Exception_Messages --
21303 -------------------------------
21304
21305 -- pragma Prefix_Exception_Messages;
21306
21307 when Pragma_Prefix_Exception_Messages =>
21308 GNAT_Pragma;
21309 Check_Valid_Configuration_Pragma;
21310 Check_Arg_Count (0);
21311 Prefix_Exception_Messages := True;
21312
21313 --------------
21314 -- Priority --
21315 --------------
21316
21317 -- pragma Priority (EXPRESSION);
21318
21319 when Pragma_Priority => Priority : declare
21320 P : constant Node_Id := Parent (N);
21321 Arg : Node_Id;
21322 Ent : Entity_Id;
21323
21324 begin
21325 Check_No_Identifiers;
21326 Check_Arg_Count (1);
21327
21328 -- Subprogram case
21329
21330 if Nkind (P) = N_Subprogram_Body then
21331 Check_In_Main_Program;
21332
21333 Ent := Defining_Unit_Name (Specification (P));
21334
21335 if Nkind (Ent) = N_Defining_Program_Unit_Name then
21336 Ent := Defining_Identifier (Ent);
21337 end if;
21338
21339 Arg := Get_Pragma_Arg (Arg1);
21340 Analyze_And_Resolve (Arg, Standard_Integer);
21341
21342 -- Must be static
21343
21344 if not Is_OK_Static_Expression (Arg) then
21345 Flag_Non_Static_Expr
21346 ("main subprogram priority is not static!", Arg);
21347 raise Pragma_Exit;
21348
21349 -- If constraint error, then we already signalled an error
21350
21351 elsif Raises_Constraint_Error (Arg) then
21352 null;
21353
21354 -- Otherwise check in range except if Relaxed_RM_Semantics
21355 -- where we ignore the value if out of range.
21356
21357 else
21358 if not Relaxed_RM_Semantics
21359 and then not Is_In_Range (Arg, RTE (RE_Priority))
21360 then
21361 Error_Pragma_Arg
21362 ("main subprogram priority is out of range", Arg1);
21363 else
21364 Set_Main_Priority
21365 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
21366 end if;
21367 end if;
21368
21369 -- Load an arbitrary entity from System.Tasking.Stages or
21370 -- System.Tasking.Restricted.Stages (depending on the
21371 -- supported profile) to make sure that one of these packages
21372 -- is implicitly with'ed, since we need to have the tasking
21373 -- run time active for the pragma Priority to have any effect.
21374 -- Previously we with'ed the package System.Tasking, but this
21375 -- package does not trigger the required initialization of the
21376 -- run-time library.
21377
21378 declare
21379 Discard : Entity_Id;
21380 pragma Warnings (Off, Discard);
21381 begin
21382 if Restricted_Profile then
21383 Discard := RTE (RE_Activate_Restricted_Tasks);
21384 else
21385 Discard := RTE (RE_Activate_Tasks);
21386 end if;
21387 end;
21388
21389 -- Task or Protected, must be of type Integer
21390
21391 elsif Nkind (P) in N_Protected_Definition | N_Task_Definition then
21392 Arg := Get_Pragma_Arg (Arg1);
21393 Ent := Defining_Identifier (Parent (P));
21394
21395 -- The expression must be analyzed in the special manner
21396 -- described in "Handling of Default and Per-Object
21397 -- Expressions" in sem.ads.
21398
21399 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
21400
21401 if not Is_OK_Static_Expression (Arg) then
21402 Check_Restriction (Static_Priorities, Arg);
21403 end if;
21404
21405 -- Anything else is incorrect
21406
21407 else
21408 Pragma_Misplaced;
21409 end if;
21410
21411 -- Check duplicate pragma before we chain the pragma in the Rep
21412 -- Item chain of Ent.
21413
21414 Check_Duplicate_Pragma (Ent);
21415 Record_Rep_Item (Ent, N);
21416 end Priority;
21417
21418 -----------------------------------
21419 -- Priority_Specific_Dispatching --
21420 -----------------------------------
21421
21422 -- pragma Priority_Specific_Dispatching (
21423 -- policy_IDENTIFIER,
21424 -- first_priority_EXPRESSION,
21425 -- last_priority_EXPRESSION);
21426
21427 when Pragma_Priority_Specific_Dispatching =>
21428 Priority_Specific_Dispatching : declare
21429 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
21430 -- This is the entity System.Any_Priority;
21431
21432 DP : Character;
21433 Lower_Bound : Node_Id;
21434 Upper_Bound : Node_Id;
21435 Lower_Val : Uint;
21436 Upper_Val : Uint;
21437
21438 begin
21439 Ada_2005_Pragma;
21440 Check_Arg_Count (3);
21441 Check_No_Identifiers;
21442 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
21443 Check_Valid_Configuration_Pragma;
21444 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21445 DP := Fold_Upper (Name_Buffer (1));
21446
21447 Lower_Bound := Get_Pragma_Arg (Arg2);
21448 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
21449 Lower_Val := Expr_Value (Lower_Bound);
21450
21451 Upper_Bound := Get_Pragma_Arg (Arg3);
21452 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
21453 Upper_Val := Expr_Value (Upper_Bound);
21454
21455 -- It is not allowed to use Task_Dispatching_Policy and
21456 -- Priority_Specific_Dispatching in the same partition.
21457
21458 if Task_Dispatching_Policy /= ' ' then
21459 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21460 Error_Pragma
21461 ("pragma% incompatible with Task_Dispatching_Policy#");
21462
21463 -- Check lower bound in range
21464
21465 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21466 or else
21467 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
21468 then
21469 Error_Pragma_Arg
21470 ("first_priority is out of range", Arg2);
21471
21472 -- Check upper bound in range
21473
21474 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21475 or else
21476 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
21477 then
21478 Error_Pragma_Arg
21479 ("last_priority is out of range", Arg3);
21480
21481 -- Check that the priority range is valid
21482
21483 elsif Lower_Val > Upper_Val then
21484 Error_Pragma
21485 ("last_priority_expression must be greater than or equal to "
21486 & "first_priority_expression");
21487
21488 -- Store the new policy, but always preserve System_Location since
21489 -- we like the error message with the run-time name.
21490
21491 else
21492 -- Check overlapping in the priority ranges specified in other
21493 -- Priority_Specific_Dispatching pragmas within the same
21494 -- partition. We can only check those we know about.
21495
21496 for J in
21497 Specific_Dispatching.First .. Specific_Dispatching.Last
21498 loop
21499 if Specific_Dispatching.Table (J).First_Priority in
21500 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21501 or else Specific_Dispatching.Table (J).Last_Priority in
21502 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21503 then
21504 Error_Msg_Sloc :=
21505 Specific_Dispatching.Table (J).Pragma_Loc;
21506 Error_Pragma
21507 ("priority range overlaps with "
21508 & "Priority_Specific_Dispatching#");
21509 end if;
21510 end loop;
21511
21512 -- The use of Priority_Specific_Dispatching is incompatible
21513 -- with Task_Dispatching_Policy.
21514
21515 if Task_Dispatching_Policy /= ' ' then
21516 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21517 Error_Pragma
21518 ("Priority_Specific_Dispatching incompatible "
21519 & "with Task_Dispatching_Policy#");
21520 end if;
21521
21522 -- The use of Priority_Specific_Dispatching forces ceiling
21523 -- locking policy.
21524
21525 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
21526 Error_Msg_Sloc := Locking_Policy_Sloc;
21527 Error_Pragma
21528 ("Priority_Specific_Dispatching incompatible "
21529 & "with Locking_Policy#");
21530
21531 -- Set the Ceiling_Locking policy, but preserve System_Location
21532 -- since we like the error message with the run time name.
21533
21534 else
21535 Locking_Policy := 'C';
21536
21537 if Locking_Policy_Sloc /= System_Location then
21538 Locking_Policy_Sloc := Loc;
21539 end if;
21540 end if;
21541
21542 -- Add entry in the table
21543
21544 Specific_Dispatching.Append
21545 ((Dispatching_Policy => DP,
21546 First_Priority => UI_To_Int (Lower_Val),
21547 Last_Priority => UI_To_Int (Upper_Val),
21548 Pragma_Loc => Loc));
21549 end if;
21550 end Priority_Specific_Dispatching;
21551
21552 -------------
21553 -- Profile --
21554 -------------
21555
21556 -- pragma Profile (profile_IDENTIFIER);
21557
21558 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
21559
21560 when Pragma_Profile =>
21561 Ada_2005_Pragma;
21562 Check_Arg_Count (1);
21563 Check_Valid_Configuration_Pragma;
21564 Check_No_Identifiers;
21565
21566 declare
21567 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21568
21569 begin
21570 if Chars (Argx) = Name_Ravenscar then
21571 Set_Ravenscar_Profile (Ravenscar, N);
21572
21573 elsif Chars (Argx) = Name_Jorvik then
21574 Set_Ravenscar_Profile (Jorvik, N);
21575
21576 elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then
21577 Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N);
21578
21579 elsif Chars (Argx) = Name_Gnat_Ravenscar_EDF then
21580 Set_Ravenscar_Profile (GNAT_Ravenscar_EDF, N);
21581
21582 elsif Chars (Argx) = Name_Restricted then
21583 Set_Profile_Restrictions
21584 (Restricted,
21585 N, Warn => Treat_Restrictions_As_Warnings);
21586
21587 elsif Chars (Argx) = Name_Rational then
21588 Set_Rational_Profile;
21589
21590 elsif Chars (Argx) = Name_No_Implementation_Extensions then
21591 Set_Profile_Restrictions
21592 (No_Implementation_Extensions,
21593 N, Warn => Treat_Restrictions_As_Warnings);
21594
21595 else
21596 Error_Pragma_Arg ("& is not a valid profile", Argx);
21597 end if;
21598 end;
21599
21600 ----------------------
21601 -- Profile_Warnings --
21602 ----------------------
21603
21604 -- pragma Profile_Warnings (profile_IDENTIFIER);
21605
21606 -- profile_IDENTIFIER => Restricted | Ravenscar
21607
21608 when Pragma_Profile_Warnings =>
21609 GNAT_Pragma;
21610 Check_Arg_Count (1);
21611 Check_Valid_Configuration_Pragma;
21612 Check_No_Identifiers;
21613
21614 declare
21615 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21616
21617 begin
21618 if Chars (Argx) = Name_Ravenscar then
21619 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
21620
21621 elsif Chars (Argx) = Name_Restricted then
21622 Set_Profile_Restrictions (Restricted, N, Warn => True);
21623
21624 elsif Chars (Argx) = Name_No_Implementation_Extensions then
21625 Set_Profile_Restrictions
21626 (No_Implementation_Extensions, N, Warn => True);
21627
21628 else
21629 Error_Pragma_Arg ("& is not a valid profile", Argx);
21630 end if;
21631 end;
21632
21633 --------------------------
21634 -- Propagate_Exceptions --
21635 --------------------------
21636
21637 -- pragma Propagate_Exceptions;
21638
21639 -- Note: this pragma is obsolete and has no effect
21640
21641 when Pragma_Propagate_Exceptions =>
21642 GNAT_Pragma;
21643 Check_Arg_Count (0);
21644
21645 if Warn_On_Obsolescent_Feature then
21646 Error_Msg_N
21647 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
21648 "and has no effect?j?", N);
21649 end if;
21650
21651 -----------------------------
21652 -- Provide_Shift_Operators --
21653 -----------------------------
21654
21655 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
21656
21657 when Pragma_Provide_Shift_Operators =>
21658 Provide_Shift_Operators : declare
21659 Ent : Entity_Id;
21660
21661 procedure Declare_Shift_Operator (Nam : Name_Id);
21662 -- Insert declaration and pragma Instrinsic for named shift op
21663
21664 ----------------------------
21665 -- Declare_Shift_Operator --
21666 ----------------------------
21667
21668 procedure Declare_Shift_Operator (Nam : Name_Id) is
21669 Func : Node_Id;
21670 Import : Node_Id;
21671
21672 begin
21673 Func :=
21674 Make_Subprogram_Declaration (Loc,
21675 Make_Function_Specification (Loc,
21676 Defining_Unit_Name =>
21677 Make_Defining_Identifier (Loc, Chars => Nam),
21678
21679 Result_Definition =>
21680 Make_Identifier (Loc, Chars => Chars (Ent)),
21681
21682 Parameter_Specifications => New_List (
21683 Make_Parameter_Specification (Loc,
21684 Defining_Identifier =>
21685 Make_Defining_Identifier (Loc, Name_Value),
21686 Parameter_Type =>
21687 Make_Identifier (Loc, Chars => Chars (Ent))),
21688
21689 Make_Parameter_Specification (Loc,
21690 Defining_Identifier =>
21691 Make_Defining_Identifier (Loc, Name_Amount),
21692 Parameter_Type =>
21693 New_Occurrence_Of (Standard_Natural, Loc)))));
21694
21695 Import :=
21696 Make_Pragma (Loc,
21697 Chars => Name_Import,
21698 Pragma_Argument_Associations => New_List (
21699 Make_Pragma_Argument_Association (Loc,
21700 Expression => Make_Identifier (Loc, Name_Intrinsic)),
21701 Make_Pragma_Argument_Association (Loc,
21702 Expression => Make_Identifier (Loc, Nam))));
21703
21704 Insert_After (N, Import);
21705 Insert_After (N, Func);
21706 end Declare_Shift_Operator;
21707
21708 -- Start of processing for Provide_Shift_Operators
21709
21710 begin
21711 GNAT_Pragma;
21712 Check_Arg_Count (1);
21713 Check_Arg_Is_Local_Name (Arg1);
21714
21715 Arg1 := Get_Pragma_Arg (Arg1);
21716
21717 -- We must have an entity name
21718
21719 if not Is_Entity_Name (Arg1) then
21720 Error_Pragma_Arg
21721 ("pragma % must apply to integer first subtype", Arg1);
21722 end if;
21723
21724 -- If no Entity, means there was a prior error so ignore
21725
21726 if Present (Entity (Arg1)) then
21727 Ent := Entity (Arg1);
21728
21729 -- Apply error checks
21730
21731 if not Is_First_Subtype (Ent) then
21732 Error_Pragma_Arg
21733 ("cannot apply pragma %",
21734 "\& is not a first subtype",
21735 Arg1);
21736
21737 elsif not Is_Integer_Type (Ent) then
21738 Error_Pragma_Arg
21739 ("cannot apply pragma %",
21740 "\& is not an integer type",
21741 Arg1);
21742
21743 elsif Has_Shift_Operator (Ent) then
21744 Error_Pragma_Arg
21745 ("cannot apply pragma %",
21746 "\& already has declared shift operators",
21747 Arg1);
21748
21749 elsif Is_Frozen (Ent) then
21750 Error_Pragma_Arg
21751 ("pragma % appears too late",
21752 "\& is already frozen",
21753 Arg1);
21754 end if;
21755
21756 -- Now declare the operators. We do this during analysis rather
21757 -- than expansion, since we want the operators available if we
21758 -- are operating in -gnatc mode.
21759
21760 Declare_Shift_Operator (Name_Rotate_Left);
21761 Declare_Shift_Operator (Name_Rotate_Right);
21762 Declare_Shift_Operator (Name_Shift_Left);
21763 Declare_Shift_Operator (Name_Shift_Right);
21764 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
21765 end if;
21766 end Provide_Shift_Operators;
21767
21768 ------------------
21769 -- Psect_Object --
21770 ------------------
21771
21772 -- pragma Psect_Object (
21773 -- [Internal =>] LOCAL_NAME,
21774 -- [, [External =>] EXTERNAL_SYMBOL]
21775 -- [, [Size =>] EXTERNAL_SYMBOL]);
21776
21777 when Pragma_Common_Object
21778 | Pragma_Psect_Object
21779 =>
21780 Psect_Object : declare
21781 Args : Args_List (1 .. 3);
21782 Names : constant Name_List (1 .. 3) := (
21783 Name_Internal,
21784 Name_External,
21785 Name_Size);
21786
21787 Internal : Node_Id renames Args (1);
21788 External : Node_Id renames Args (2);
21789 Size : Node_Id renames Args (3);
21790
21791 Def_Id : Entity_Id;
21792
21793 procedure Check_Arg (Arg : Node_Id);
21794 -- Checks that argument is either a string literal or an
21795 -- identifier, and posts error message if not.
21796
21797 ---------------
21798 -- Check_Arg --
21799 ---------------
21800
21801 procedure Check_Arg (Arg : Node_Id) is
21802 begin
21803 if Nkind (Original_Node (Arg)) not in
21804 N_String_Literal | N_Identifier
21805 then
21806 Error_Pragma_Arg
21807 ("inappropriate argument for pragma %", Arg);
21808 end if;
21809 end Check_Arg;
21810
21811 -- Start of processing for Common_Object/Psect_Object
21812
21813 begin
21814 GNAT_Pragma;
21815 Gather_Associations (Names, Args);
21816 Process_Extended_Import_Export_Internal_Arg (Internal);
21817
21818 Def_Id := Entity (Internal);
21819
21820 if Ekind (Def_Id) not in E_Constant | E_Variable then
21821 Error_Pragma_Arg
21822 ("pragma% must designate an object", Internal);
21823 end if;
21824
21825 Check_Arg (Internal);
21826
21827 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
21828 Error_Pragma_Arg
21829 ("cannot use pragma% for imported/exported object",
21830 Internal);
21831 end if;
21832
21833 if Is_Concurrent_Type (Etype (Internal)) then
21834 Error_Pragma_Arg
21835 ("cannot specify pragma % for task/protected object",
21836 Internal);
21837 end if;
21838
21839 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
21840 or else
21841 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
21842 then
21843 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
21844 end if;
21845
21846 if Ekind (Def_Id) = E_Constant then
21847 Error_Pragma_Arg
21848 ("cannot specify pragma % for a constant", Internal);
21849 end if;
21850
21851 if Is_Record_Type (Etype (Internal)) then
21852 declare
21853 Ent : Entity_Id;
21854 Decl : Entity_Id;
21855
21856 begin
21857 Ent := First_Entity (Etype (Internal));
21858 while Present (Ent) loop
21859 Decl := Declaration_Node (Ent);
21860
21861 if Ekind (Ent) = E_Component
21862 and then Nkind (Decl) = N_Component_Declaration
21863 and then Present (Expression (Decl))
21864 and then Warn_On_Export_Import
21865 then
21866 Error_Msg_N
21867 ("?x?object for pragma % has defaults", Internal);
21868 exit;
21869
21870 else
21871 Next_Entity (Ent);
21872 end if;
21873 end loop;
21874 end;
21875 end if;
21876
21877 if Present (Size) then
21878 Check_Arg (Size);
21879 end if;
21880
21881 if Present (External) then
21882 Check_Arg_Is_External_Name (External);
21883 end if;
21884
21885 -- If all error tests pass, link pragma on to the rep item chain
21886
21887 Record_Rep_Item (Def_Id, N);
21888 end Psect_Object;
21889
21890 ----------
21891 -- Pure --
21892 ----------
21893
21894 -- pragma Pure [(library_unit_NAME)];
21895
21896 when Pragma_Pure => Pure : declare
21897 Ent : Entity_Id;
21898
21899 begin
21900 Check_Ada_83_Warning;
21901
21902 -- If the pragma comes from a subprogram instantiation, nothing to
21903 -- check, this can happen at any level of nesting.
21904
21905 if Is_Wrapper_Package (Current_Scope) then
21906 return;
21907 else
21908 Check_Valid_Library_Unit_Pragma;
21909 end if;
21910
21911 if Nkind (N) = N_Null_Statement then
21912 return;
21913 end if;
21914
21915 Ent := Find_Lib_Unit_Name;
21916
21917 -- A pragma that applies to a Ghost entity becomes Ghost for the
21918 -- purposes of legality checks and removal of ignored Ghost code.
21919
21920 Mark_Ghost_Pragma (N, Ent);
21921
21922 if not Debug_Flag_U then
21923 Set_Is_Pure (Ent);
21924 Set_Has_Pragma_Pure (Ent);
21925
21926 if Legacy_Elaboration_Checks then
21927 Set_Suppress_Elaboration_Warnings (Ent);
21928 end if;
21929 end if;
21930 end Pure;
21931
21932 -------------------
21933 -- Pure_Function --
21934 -------------------
21935
21936 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
21937
21938 when Pragma_Pure_Function => Pure_Function : declare
21939 Def_Id : Entity_Id;
21940 E : Entity_Id;
21941 E_Id : Node_Id;
21942 Effective : Boolean := False;
21943 Orig_Def : Entity_Id;
21944 Same_Decl : Boolean := False;
21945
21946 begin
21947 GNAT_Pragma;
21948 Check_Arg_Count (1);
21949 Check_Optional_Identifier (Arg1, Name_Entity);
21950 Check_Arg_Is_Local_Name (Arg1);
21951 E_Id := Get_Pragma_Arg (Arg1);
21952
21953 if Etype (E_Id) = Any_Type then
21954 return;
21955 end if;
21956
21957 -- Loop through homonyms (overloadings) of referenced entity
21958
21959 E := Entity (E_Id);
21960
21961 -- A pragma that applies to a Ghost entity becomes Ghost for the
21962 -- purposes of legality checks and removal of ignored Ghost code.
21963
21964 Mark_Ghost_Pragma (N, E);
21965
21966 if Present (E) then
21967 loop
21968 Def_Id := Get_Base_Subprogram (E);
21969
21970 if Ekind (Def_Id) not in
21971 E_Function | E_Generic_Function | E_Operator
21972 then
21973 Error_Pragma_Arg
21974 ("pragma% requires a function name", Arg1);
21975 end if;
21976
21977 -- When we have a generic function we must jump up a level
21978 -- to the declaration of the wrapper package itself.
21979
21980 Orig_Def := Def_Id;
21981
21982 if Is_Generic_Instance (Def_Id) then
21983 while Nkind (Orig_Def) /= N_Package_Declaration loop
21984 Orig_Def := Parent (Orig_Def);
21985 end loop;
21986 end if;
21987
21988 if In_Same_Declarative_Part (Parent (N), Orig_Def) then
21989 Same_Decl := True;
21990 Set_Is_Pure (Def_Id);
21991
21992 if not Has_Pragma_Pure_Function (Def_Id) then
21993 Set_Has_Pragma_Pure_Function (Def_Id);
21994 Effective := True;
21995 end if;
21996 end if;
21997
21998 exit when From_Aspect_Specification (N);
21999 E := Homonym (E);
22000 exit when No (E) or else Scope (E) /= Current_Scope;
22001 end loop;
22002
22003 if not Effective
22004 and then Warn_On_Redundant_Constructs
22005 then
22006 Error_Msg_NE
22007 ("pragma Pure_Function on& is redundant?r?",
22008 N, Entity (E_Id));
22009
22010 elsif not Same_Decl then
22011 Error_Pragma_Arg
22012 ("pragma% argument must be in same declarative part",
22013 Arg1);
22014 end if;
22015 end if;
22016 end Pure_Function;
22017
22018 --------------------
22019 -- Queuing_Policy --
22020 --------------------
22021
22022 -- pragma Queuing_Policy (policy_IDENTIFIER);
22023
22024 when Pragma_Queuing_Policy => declare
22025 QP : Character;
22026
22027 begin
22028 Check_Ada_83_Warning;
22029 Check_Arg_Count (1);
22030 Check_No_Identifiers;
22031 Check_Arg_Is_Queuing_Policy (Arg1);
22032 Check_Valid_Configuration_Pragma;
22033 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
22034 QP := Fold_Upper (Name_Buffer (1));
22035
22036 if Queuing_Policy /= ' '
22037 and then Queuing_Policy /= QP
22038 then
22039 Error_Msg_Sloc := Queuing_Policy_Sloc;
22040 Error_Pragma ("queuing policy incompatible with policy#");
22041
22042 -- Set new policy, but always preserve System_Location since we
22043 -- like the error message with the run time name.
22044
22045 else
22046 Queuing_Policy := QP;
22047
22048 if Queuing_Policy_Sloc /= System_Location then
22049 Queuing_Policy_Sloc := Loc;
22050 end if;
22051 end if;
22052 end;
22053
22054 --------------
22055 -- Rational --
22056 --------------
22057
22058 -- pragma Rational, for compatibility with foreign compiler
22059
22060 when Pragma_Rational =>
22061 Set_Rational_Profile;
22062
22063 ---------------------
22064 -- Refined_Depends --
22065 ---------------------
22066
22067 -- pragma Refined_Depends (DEPENDENCY_RELATION);
22068
22069 -- DEPENDENCY_RELATION ::=
22070 -- null
22071 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
22072
22073 -- DEPENDENCY_CLAUSE ::=
22074 -- OUTPUT_LIST =>[+] INPUT_LIST
22075 -- | NULL_DEPENDENCY_CLAUSE
22076
22077 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
22078
22079 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
22080
22081 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
22082
22083 -- OUTPUT ::= NAME | FUNCTION_RESULT
22084 -- INPUT ::= NAME
22085
22086 -- where FUNCTION_RESULT is a function Result attribute_reference
22087
22088 -- Characteristics:
22089
22090 -- * Analysis - The annotation undergoes initial checks to verify
22091 -- the legal placement and context. Secondary checks fully analyze
22092 -- the dependency clauses/global list in:
22093
22094 -- Analyze_Refined_Depends_In_Decl_Part
22095
22096 -- * Expansion - None.
22097
22098 -- * Template - The annotation utilizes the generic template of the
22099 -- related subprogram body.
22100
22101 -- * Globals - Capture of global references must occur after full
22102 -- analysis.
22103
22104 -- * Instance - The annotation is instantiated automatically when
22105 -- the related generic subprogram body is instantiated.
22106
22107 when Pragma_Refined_Depends => Refined_Depends : declare
22108 Body_Id : Entity_Id;
22109 Legal : Boolean;
22110 Spec_Id : Entity_Id;
22111
22112 begin
22113 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22114
22115 if Legal then
22116
22117 -- Chain the pragma on the contract for further processing by
22118 -- Analyze_Refined_Depends_In_Decl_Part.
22119
22120 Add_Contract_Item (N, Body_Id);
22121
22122 -- The legality checks of pragmas Refined_Depends and
22123 -- Refined_Global are affected by the SPARK mode in effect and
22124 -- the volatility of the context. In addition these two pragmas
22125 -- are subject to an inherent order:
22126
22127 -- 1) Refined_Global
22128 -- 2) Refined_Depends
22129
22130 -- Analyze all these pragmas in the order outlined above
22131
22132 Analyze_If_Present (Pragma_SPARK_Mode);
22133 Analyze_If_Present (Pragma_Volatile_Function);
22134 Analyze_If_Present (Pragma_Refined_Global);
22135 Analyze_Refined_Depends_In_Decl_Part (N);
22136 end if;
22137 end Refined_Depends;
22138
22139 --------------------
22140 -- Refined_Global --
22141 --------------------
22142
22143 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
22144
22145 -- GLOBAL_SPECIFICATION ::=
22146 -- null
22147 -- | (GLOBAL_LIST)
22148 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
22149
22150 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
22151
22152 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
22153 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
22154 -- GLOBAL_ITEM ::= NAME
22155
22156 -- Characteristics:
22157
22158 -- * Analysis - The annotation undergoes initial checks to verify
22159 -- the legal placement and context. Secondary checks fully analyze
22160 -- the dependency clauses/global list in:
22161
22162 -- Analyze_Refined_Global_In_Decl_Part
22163
22164 -- * Expansion - None.
22165
22166 -- * Template - The annotation utilizes the generic template of the
22167 -- related subprogram body.
22168
22169 -- * Globals - Capture of global references must occur after full
22170 -- analysis.
22171
22172 -- * Instance - The annotation is instantiated automatically when
22173 -- the related generic subprogram body is instantiated.
22174
22175 when Pragma_Refined_Global => Refined_Global : declare
22176 Body_Id : Entity_Id;
22177 Legal : Boolean;
22178 Spec_Id : Entity_Id;
22179
22180 begin
22181 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22182
22183 if Legal then
22184
22185 -- Chain the pragma on the contract for further processing by
22186 -- Analyze_Refined_Global_In_Decl_Part.
22187
22188 Add_Contract_Item (N, Body_Id);
22189
22190 -- The legality checks of pragmas Refined_Depends and
22191 -- Refined_Global are affected by the SPARK mode in effect and
22192 -- the volatility of the context. In addition these two pragmas
22193 -- are subject to an inherent order:
22194
22195 -- 1) Refined_Global
22196 -- 2) Refined_Depends
22197
22198 -- Analyze all these pragmas in the order outlined above
22199
22200 Analyze_If_Present (Pragma_SPARK_Mode);
22201 Analyze_If_Present (Pragma_Volatile_Function);
22202 Analyze_Refined_Global_In_Decl_Part (N);
22203 Analyze_If_Present (Pragma_Refined_Depends);
22204 end if;
22205 end Refined_Global;
22206
22207 ------------------
22208 -- Refined_Post --
22209 ------------------
22210
22211 -- pragma Refined_Post (boolean_EXPRESSION);
22212
22213 -- Characteristics:
22214
22215 -- * Analysis - The annotation is fully analyzed immediately upon
22216 -- elaboration as it cannot forward reference entities.
22217
22218 -- * Expansion - The annotation is expanded during the expansion of
22219 -- the related subprogram body contract as performed in:
22220
22221 -- Expand_Subprogram_Contract
22222
22223 -- * Template - The annotation utilizes the generic template of the
22224 -- related subprogram body.
22225
22226 -- * Globals - Capture of global references must occur after full
22227 -- analysis.
22228
22229 -- * Instance - The annotation is instantiated automatically when
22230 -- the related generic subprogram body is instantiated.
22231
22232 when Pragma_Refined_Post => Refined_Post : declare
22233 Body_Id : Entity_Id;
22234 Legal : Boolean;
22235 Spec_Id : Entity_Id;
22236
22237 begin
22238 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22239
22240 -- Fully analyze the pragma when it appears inside a subprogram
22241 -- body because it cannot benefit from forward references.
22242
22243 if Legal then
22244
22245 -- Chain the pragma on the contract for completeness
22246
22247 Add_Contract_Item (N, Body_Id);
22248
22249 -- The legality checks of pragma Refined_Post are affected by
22250 -- the SPARK mode in effect and the volatility of the context.
22251 -- Analyze all pragmas in a specific order.
22252
22253 Analyze_If_Present (Pragma_SPARK_Mode);
22254 Analyze_If_Present (Pragma_Volatile_Function);
22255 Analyze_Pre_Post_Condition_In_Decl_Part (N);
22256
22257 -- Currently it is not possible to inline pre/postconditions on
22258 -- a subprogram subject to pragma Inline_Always.
22259
22260 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
22261 end if;
22262 end Refined_Post;
22263
22264 -------------------
22265 -- Refined_State --
22266 -------------------
22267
22268 -- pragma Refined_State (REFINEMENT_LIST);
22269
22270 -- REFINEMENT_LIST ::=
22271 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
22272
22273 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
22274
22275 -- CONSTITUENT_LIST ::=
22276 -- null
22277 -- | CONSTITUENT
22278 -- | (CONSTITUENT {, CONSTITUENT})
22279
22280 -- CONSTITUENT ::= object_NAME | state_NAME
22281
22282 -- Characteristics:
22283
22284 -- * Analysis - The annotation undergoes initial checks to verify
22285 -- the legal placement and context. Secondary checks preanalyze the
22286 -- refinement clauses in:
22287
22288 -- Analyze_Refined_State_In_Decl_Part
22289
22290 -- * Expansion - None.
22291
22292 -- * Template - The annotation utilizes the template of the related
22293 -- package body.
22294
22295 -- * Globals - Capture of global references must occur after full
22296 -- analysis.
22297
22298 -- * Instance - The annotation is instantiated automatically when
22299 -- the related generic package body is instantiated.
22300
22301 when Pragma_Refined_State => Refined_State : declare
22302 Pack_Decl : Node_Id;
22303 Spec_Id : Entity_Id;
22304
22305 begin
22306 GNAT_Pragma;
22307 Check_No_Identifiers;
22308 Check_Arg_Count (1);
22309
22310 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
22311
22312 if Nkind (Pack_Decl) /= N_Package_Body then
22313 Pragma_Misplaced;
22314 return;
22315 end if;
22316
22317 Spec_Id := Corresponding_Spec (Pack_Decl);
22318
22319 -- A pragma that applies to a Ghost entity becomes Ghost for the
22320 -- purposes of legality checks and removal of ignored Ghost code.
22321
22322 Mark_Ghost_Pragma (N, Spec_Id);
22323
22324 -- Chain the pragma on the contract for further processing by
22325 -- Analyze_Refined_State_In_Decl_Part.
22326
22327 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
22328
22329 -- The legality checks of pragma Refined_State are affected by the
22330 -- SPARK mode in effect. Analyze all pragmas in a specific order.
22331
22332 Analyze_If_Present (Pragma_SPARK_Mode);
22333
22334 -- State refinement is allowed only when the corresponding package
22335 -- declaration has non-null pragma Abstract_State. Refinement not
22336 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
22337
22338 if SPARK_Mode /= Off
22339 and then
22340 (No (Abstract_States (Spec_Id))
22341 or else Has_Null_Abstract_State (Spec_Id))
22342 then
22343 Error_Msg_NE
22344 ("useless refinement, package & does not define abstract "
22345 & "states", N, Spec_Id);
22346 return;
22347 end if;
22348 end Refined_State;
22349
22350 -----------------------
22351 -- Relative_Deadline --
22352 -----------------------
22353
22354 -- pragma Relative_Deadline (time_span_EXPRESSION);
22355
22356 when Pragma_Relative_Deadline => Relative_Deadline : declare
22357 P : constant Node_Id := Parent (N);
22358 Arg : Node_Id;
22359
22360 begin
22361 Ada_2005_Pragma;
22362 Check_No_Identifiers;
22363 Check_Arg_Count (1);
22364
22365 Arg := Get_Pragma_Arg (Arg1);
22366
22367 -- The expression must be analyzed in the special manner described
22368 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
22369
22370 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
22371
22372 -- Subprogram case
22373
22374 if Nkind (P) = N_Subprogram_Body then
22375 Check_In_Main_Program;
22376
22377 -- Only Task and subprogram cases allowed
22378
22379 elsif Nkind (P) /= N_Task_Definition then
22380 Pragma_Misplaced;
22381 end if;
22382
22383 -- Check duplicate pragma before we set the corresponding flag
22384
22385 if Has_Relative_Deadline_Pragma (P) then
22386 Error_Pragma ("duplicate pragma% not allowed");
22387 end if;
22388
22389 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
22390 -- Relative_Deadline pragma node cannot be inserted in the Rep
22391 -- Item chain of Ent since it is rewritten by the expander as a
22392 -- procedure call statement that will break the chain.
22393
22394 Set_Has_Relative_Deadline_Pragma (P);
22395 end Relative_Deadline;
22396
22397 ------------------------
22398 -- Remote_Access_Type --
22399 ------------------------
22400
22401 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
22402
22403 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
22404 E : Entity_Id;
22405
22406 begin
22407 GNAT_Pragma;
22408 Check_Arg_Count (1);
22409 Check_Optional_Identifier (Arg1, Name_Entity);
22410 Check_Arg_Is_Local_Name (Arg1);
22411
22412 E := Entity (Get_Pragma_Arg (Arg1));
22413
22414 -- A pragma that applies to a Ghost entity becomes Ghost for the
22415 -- purposes of legality checks and removal of ignored Ghost code.
22416
22417 Mark_Ghost_Pragma (N, E);
22418
22419 if Nkind (Parent (E)) = N_Formal_Type_Declaration
22420 and then Ekind (E) = E_General_Access_Type
22421 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
22422 and then Scope (Root_Type (Directly_Designated_Type (E)))
22423 = Scope (E)
22424 and then Is_Valid_Remote_Object_Type
22425 (Root_Type (Directly_Designated_Type (E)))
22426 then
22427 Set_Is_Remote_Types (E);
22428
22429 else
22430 Error_Pragma_Arg
22431 ("pragma% applies only to formal access-to-class-wide types",
22432 Arg1);
22433 end if;
22434 end Remote_Access_Type;
22435
22436 ---------------------------
22437 -- Remote_Call_Interface --
22438 ---------------------------
22439
22440 -- pragma Remote_Call_Interface [(library_unit_NAME)];
22441
22442 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
22443 Cunit_Node : Node_Id;
22444 Cunit_Ent : Entity_Id;
22445 K : Node_Kind;
22446
22447 begin
22448 Check_Ada_83_Warning;
22449 Check_Valid_Library_Unit_Pragma;
22450
22451 if Nkind (N) = N_Null_Statement then
22452 return;
22453 end if;
22454
22455 Cunit_Node := Cunit (Current_Sem_Unit);
22456 K := Nkind (Unit (Cunit_Node));
22457 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22458
22459 -- A pragma that applies to a Ghost entity becomes Ghost for the
22460 -- purposes of legality checks and removal of ignored Ghost code.
22461
22462 Mark_Ghost_Pragma (N, Cunit_Ent);
22463
22464 if K = N_Package_Declaration
22465 or else K = N_Generic_Package_Declaration
22466 or else K = N_Subprogram_Declaration
22467 or else K = N_Generic_Subprogram_Declaration
22468 or else (K = N_Subprogram_Body
22469 and then Acts_As_Spec (Unit (Cunit_Node)))
22470 then
22471 null;
22472 else
22473 Error_Pragma (
22474 "pragma% must apply to package or subprogram declaration");
22475 end if;
22476
22477 Set_Is_Remote_Call_Interface (Cunit_Ent);
22478 end Remote_Call_Interface;
22479
22480 ------------------
22481 -- Remote_Types --
22482 ------------------
22483
22484 -- pragma Remote_Types [(library_unit_NAME)];
22485
22486 when Pragma_Remote_Types => Remote_Types : declare
22487 Cunit_Node : Node_Id;
22488 Cunit_Ent : Entity_Id;
22489
22490 begin
22491 Check_Ada_83_Warning;
22492 Check_Valid_Library_Unit_Pragma;
22493
22494 if Nkind (N) = N_Null_Statement then
22495 return;
22496 end if;
22497
22498 Cunit_Node := Cunit (Current_Sem_Unit);
22499 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22500
22501 -- A pragma that applies to a Ghost entity becomes Ghost for the
22502 -- purposes of legality checks and removal of ignored Ghost code.
22503
22504 Mark_Ghost_Pragma (N, Cunit_Ent);
22505
22506 if Nkind (Unit (Cunit_Node)) not in
22507 N_Package_Declaration | N_Generic_Package_Declaration
22508 then
22509 Error_Pragma
22510 ("pragma% can only apply to a package declaration");
22511 end if;
22512
22513 Set_Is_Remote_Types (Cunit_Ent);
22514 end Remote_Types;
22515
22516 ---------------
22517 -- Ravenscar --
22518 ---------------
22519
22520 -- pragma Ravenscar;
22521
22522 when Pragma_Ravenscar =>
22523 GNAT_Pragma;
22524 Check_Arg_Count (0);
22525 Check_Valid_Configuration_Pragma;
22526 Set_Ravenscar_Profile (Ravenscar, N);
22527
22528 if Warn_On_Obsolescent_Feature then
22529 Error_Msg_N
22530 ("pragma Ravenscar is an obsolescent feature?j?", N);
22531 Error_Msg_N
22532 ("|use pragma Profile (Ravenscar) instead?j?", N);
22533 end if;
22534
22535 -------------------------
22536 -- Restricted_Run_Time --
22537 -------------------------
22538
22539 -- pragma Restricted_Run_Time;
22540
22541 when Pragma_Restricted_Run_Time =>
22542 GNAT_Pragma;
22543 Check_Arg_Count (0);
22544 Check_Valid_Configuration_Pragma;
22545 Set_Profile_Restrictions
22546 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
22547
22548 if Warn_On_Obsolescent_Feature then
22549 Error_Msg_N
22550 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
22551 N);
22552 Error_Msg_N
22553 ("|use pragma Profile (Restricted) instead?j?", N);
22554 end if;
22555
22556 ------------------
22557 -- Restrictions --
22558 ------------------
22559
22560 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
22561
22562 -- RESTRICTION ::=
22563 -- restriction_IDENTIFIER
22564 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22565
22566 when Pragma_Restrictions =>
22567 Process_Restrictions_Or_Restriction_Warnings
22568 (Warn => Treat_Restrictions_As_Warnings);
22569
22570 --------------------------
22571 -- Restriction_Warnings --
22572 --------------------------
22573
22574 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
22575
22576 -- RESTRICTION ::=
22577 -- restriction_IDENTIFIER
22578 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22579
22580 when Pragma_Restriction_Warnings =>
22581 GNAT_Pragma;
22582 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
22583
22584 ----------------
22585 -- Reviewable --
22586 ----------------
22587
22588 -- pragma Reviewable;
22589
22590 when Pragma_Reviewable =>
22591 Check_Ada_83_Warning;
22592 Check_Arg_Count (0);
22593
22594 -- Call dummy debugging function rv. This is done to assist front
22595 -- end debugging. By placing a Reviewable pragma in the source
22596 -- program, a breakpoint on rv catches this place in the source,
22597 -- allowing convenient stepping to the point of interest.
22598
22599 rv;
22600
22601 --------------------------
22602 -- Secondary_Stack_Size --
22603 --------------------------
22604
22605 -- pragma Secondary_Stack_Size (EXPRESSION);
22606
22607 when Pragma_Secondary_Stack_Size => Secondary_Stack_Size : declare
22608 P : constant Node_Id := Parent (N);
22609 Arg : Node_Id;
22610 Ent : Entity_Id;
22611
22612 begin
22613 GNAT_Pragma;
22614 Check_No_Identifiers;
22615 Check_Arg_Count (1);
22616
22617 if Nkind (P) = N_Task_Definition then
22618 Arg := Get_Pragma_Arg (Arg1);
22619 Ent := Defining_Identifier (Parent (P));
22620
22621 -- The expression must be analyzed in the special manner
22622 -- described in "Handling of Default Expressions" in sem.ads.
22623
22624 Preanalyze_Spec_Expression (Arg, Any_Integer);
22625
22626 -- The pragma cannot appear if the No_Secondary_Stack
22627 -- restriction is in effect.
22628
22629 Check_Restriction (No_Secondary_Stack, Arg);
22630
22631 -- Anything else is incorrect
22632
22633 else
22634 Pragma_Misplaced;
22635 end if;
22636
22637 -- Check duplicate pragma before we chain the pragma in the Rep
22638 -- Item chain of Ent.
22639
22640 Check_Duplicate_Pragma (Ent);
22641 Record_Rep_Item (Ent, N);
22642 end Secondary_Stack_Size;
22643
22644 --------------------------
22645 -- Short_Circuit_And_Or --
22646 --------------------------
22647
22648 -- pragma Short_Circuit_And_Or;
22649
22650 when Pragma_Short_Circuit_And_Or =>
22651 GNAT_Pragma;
22652 Check_Arg_Count (0);
22653 Check_Valid_Configuration_Pragma;
22654 Short_Circuit_And_Or := True;
22655
22656 -------------------
22657 -- Share_Generic --
22658 -------------------
22659
22660 -- pragma Share_Generic (GNAME {, GNAME});
22661
22662 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
22663
22664 when Pragma_Share_Generic =>
22665 GNAT_Pragma;
22666 Process_Generic_List;
22667
22668 ------------
22669 -- Shared --
22670 ------------
22671
22672 -- pragma Shared (LOCAL_NAME);
22673
22674 when Pragma_Shared =>
22675 GNAT_Pragma;
22676 Process_Atomic_Independent_Shared_Volatile;
22677
22678 --------------------
22679 -- Shared_Passive --
22680 --------------------
22681
22682 -- pragma Shared_Passive [(library_unit_NAME)];
22683
22684 -- Set the flag Is_Shared_Passive of program unit name entity
22685
22686 when Pragma_Shared_Passive => Shared_Passive : declare
22687 Cunit_Node : Node_Id;
22688 Cunit_Ent : Entity_Id;
22689
22690 begin
22691 Check_Ada_83_Warning;
22692 Check_Valid_Library_Unit_Pragma;
22693
22694 if Nkind (N) = N_Null_Statement then
22695 return;
22696 end if;
22697
22698 Cunit_Node := Cunit (Current_Sem_Unit);
22699 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22700
22701 -- A pragma that applies to a Ghost entity becomes Ghost for the
22702 -- purposes of legality checks and removal of ignored Ghost code.
22703
22704 Mark_Ghost_Pragma (N, Cunit_Ent);
22705
22706 if Nkind (Unit (Cunit_Node)) not in
22707 N_Package_Declaration | N_Generic_Package_Declaration
22708 then
22709 Error_Pragma
22710 ("pragma% can only apply to a package declaration");
22711 end if;
22712
22713 Set_Is_Shared_Passive (Cunit_Ent);
22714 end Shared_Passive;
22715
22716 -----------------------
22717 -- Short_Descriptors --
22718 -----------------------
22719
22720 -- pragma Short_Descriptors;
22721
22722 -- Recognize and validate, but otherwise ignore
22723
22724 when Pragma_Short_Descriptors =>
22725 GNAT_Pragma;
22726 Check_Arg_Count (0);
22727 Check_Valid_Configuration_Pragma;
22728
22729 ------------------------------
22730 -- Simple_Storage_Pool_Type --
22731 ------------------------------
22732
22733 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
22734
22735 when Pragma_Simple_Storage_Pool_Type =>
22736 Simple_Storage_Pool_Type : declare
22737 Typ : Entity_Id;
22738 Type_Id : Node_Id;
22739
22740 begin
22741 GNAT_Pragma;
22742 Check_Arg_Count (1);
22743 Check_Arg_Is_Library_Level_Local_Name (Arg1);
22744
22745 Type_Id := Get_Pragma_Arg (Arg1);
22746 Find_Type (Type_Id);
22747 Typ := Entity (Type_Id);
22748
22749 if Typ = Any_Type then
22750 return;
22751 end if;
22752
22753 -- A pragma that applies to a Ghost entity becomes Ghost for the
22754 -- purposes of legality checks and removal of ignored Ghost code.
22755
22756 Mark_Ghost_Pragma (N, Typ);
22757
22758 -- We require the pragma to apply to a type declared in a package
22759 -- declaration, but not (immediately) within a package body.
22760
22761 if Ekind (Current_Scope) /= E_Package
22762 or else In_Package_Body (Current_Scope)
22763 then
22764 Error_Pragma
22765 ("pragma% can only apply to type declared immediately "
22766 & "within a package declaration");
22767 end if;
22768
22769 -- A simple storage pool type must be an immutably limited record
22770 -- or private type. If the pragma is given for a private type,
22771 -- the full type is similarly restricted (which is checked later
22772 -- in Freeze_Entity).
22773
22774 if Is_Record_Type (Typ)
22775 and then not Is_Limited_View (Typ)
22776 then
22777 Error_Pragma
22778 ("pragma% can only apply to explicitly limited record type");
22779
22780 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
22781 Error_Pragma
22782 ("pragma% can only apply to a private type that is limited");
22783
22784 elsif not Is_Record_Type (Typ)
22785 and then not Is_Private_Type (Typ)
22786 then
22787 Error_Pragma
22788 ("pragma% can only apply to limited record or private type");
22789 end if;
22790
22791 Record_Rep_Item (Typ, N);
22792 end Simple_Storage_Pool_Type;
22793
22794 ----------------------
22795 -- Source_File_Name --
22796 ----------------------
22797
22798 -- There are five forms for this pragma:
22799
22800 -- pragma Source_File_Name (
22801 -- [UNIT_NAME =>] unit_NAME,
22802 -- BODY_FILE_NAME => STRING_LITERAL
22803 -- [, [INDEX =>] INTEGER_LITERAL]);
22804
22805 -- pragma Source_File_Name (
22806 -- [UNIT_NAME =>] unit_NAME,
22807 -- SPEC_FILE_NAME => STRING_LITERAL
22808 -- [, [INDEX =>] INTEGER_LITERAL]);
22809
22810 -- pragma Source_File_Name (
22811 -- BODY_FILE_NAME => STRING_LITERAL
22812 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22813 -- [, CASING => CASING_SPEC]);
22814
22815 -- pragma Source_File_Name (
22816 -- SPEC_FILE_NAME => STRING_LITERAL
22817 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22818 -- [, CASING => CASING_SPEC]);
22819
22820 -- pragma Source_File_Name (
22821 -- SUBUNIT_FILE_NAME => STRING_LITERAL
22822 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22823 -- [, CASING => CASING_SPEC]);
22824
22825 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
22826
22827 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
22828 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
22829 -- only be used when no project file is used, while SFNP can only be
22830 -- used when a project file is used.
22831
22832 -- No processing here. Processing was completed during parsing, since
22833 -- we need to have file names set as early as possible. Units are
22834 -- loaded well before semantic processing starts.
22835
22836 -- The only processing we defer to this point is the check for
22837 -- correct placement.
22838
22839 when Pragma_Source_File_Name =>
22840 GNAT_Pragma;
22841 Check_Valid_Configuration_Pragma;
22842
22843 ------------------------------
22844 -- Source_File_Name_Project --
22845 ------------------------------
22846
22847 -- See Source_File_Name for syntax
22848
22849 -- No processing here. Processing was completed during parsing, since
22850 -- we need to have file names set as early as possible. Units are
22851 -- loaded well before semantic processing starts.
22852
22853 -- The only processing we defer to this point is the check for
22854 -- correct placement.
22855
22856 when Pragma_Source_File_Name_Project =>
22857 GNAT_Pragma;
22858 Check_Valid_Configuration_Pragma;
22859
22860 -- Check that a pragma Source_File_Name_Project is used only in a
22861 -- configuration pragmas file.
22862
22863 -- Pragmas Source_File_Name_Project should only be generated by
22864 -- the Project Manager in configuration pragmas files.
22865
22866 -- This is really an ugly test. It seems to depend on some
22867 -- accidental and undocumented property. At the very least it
22868 -- needs to be documented, but it would be better to have a
22869 -- clean way of testing if we are in a configuration file???
22870
22871 if Present (Parent (N)) then
22872 Error_Pragma
22873 ("pragma% can only appear in a configuration pragmas file");
22874 end if;
22875
22876 ----------------------
22877 -- Source_Reference --
22878 ----------------------
22879
22880 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
22881
22882 -- Nothing to do, all processing completed in Par.Prag, since we need
22883 -- the information for possible parser messages that are output.
22884
22885 when Pragma_Source_Reference =>
22886 GNAT_Pragma;
22887
22888 ----------------
22889 -- SPARK_Mode --
22890 ----------------
22891
22892 -- pragma SPARK_Mode [(On | Off)];
22893
22894 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
22895 Mode_Id : SPARK_Mode_Type;
22896
22897 procedure Check_Pragma_Conformance
22898 (Context_Pragma : Node_Id;
22899 Entity : Entity_Id;
22900 Entity_Pragma : Node_Id);
22901 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
22902 -- conformance of pragma N depending the following scenarios:
22903 --
22904 -- If pragma Context_Pragma is not Empty, verify that pragma N is
22905 -- compatible with the pragma Context_Pragma that was inherited
22906 -- from the context:
22907 -- * If the mode of Context_Pragma is ON, then the new mode can
22908 -- be anything.
22909 -- * If the mode of Context_Pragma is OFF, then the only allowed
22910 -- new mode is also OFF. Emit error if this is not the case.
22911 --
22912 -- If Entity is not Empty, verify that pragma N is compatible with
22913 -- pragma Entity_Pragma that belongs to Entity.
22914 -- * If Entity_Pragma is Empty, always issue an error as this
22915 -- corresponds to the case where a previous section of Entity
22916 -- has no SPARK_Mode set.
22917 -- * If the mode of Entity_Pragma is ON, then the new mode can
22918 -- be anything.
22919 -- * If the mode of Entity_Pragma is OFF, then the only allowed
22920 -- new mode is also OFF. Emit error if this is not the case.
22921
22922 procedure Check_Library_Level_Entity (E : Entity_Id);
22923 -- Subsidiary to routines Process_xxx. Verify that the related
22924 -- entity E subject to pragma SPARK_Mode is library-level.
22925
22926 procedure Process_Body (Decl : Node_Id);
22927 -- Verify the legality of pragma SPARK_Mode when it appears as the
22928 -- top of the body declarations of entry, package, protected unit,
22929 -- subprogram or task unit body denoted by Decl.
22930
22931 procedure Process_Overloadable (Decl : Node_Id);
22932 -- Verify the legality of pragma SPARK_Mode when it applies to an
22933 -- entry or [generic] subprogram declaration denoted by Decl.
22934
22935 procedure Process_Private_Part (Decl : Node_Id);
22936 -- Verify the legality of pragma SPARK_Mode when it appears at the
22937 -- top of the private declarations of a package spec, protected or
22938 -- task unit declaration denoted by Decl.
22939
22940 procedure Process_Statement_Part (Decl : Node_Id);
22941 -- Verify the legality of pragma SPARK_Mode when it appears at the
22942 -- top of the statement sequence of a package body denoted by node
22943 -- Decl.
22944
22945 procedure Process_Visible_Part (Decl : Node_Id);
22946 -- Verify the legality of pragma SPARK_Mode when it appears at the
22947 -- top of the visible declarations of a package spec, protected or
22948 -- task unit declaration denoted by Decl. The routine is also used
22949 -- on protected or task units declared without a definition.
22950
22951 procedure Set_SPARK_Context;
22952 -- Subsidiary to routines Process_xxx. Set the global variables
22953 -- which represent the mode of the context from pragma N. Ensure
22954 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
22955
22956 ------------------------------
22957 -- Check_Pragma_Conformance --
22958 ------------------------------
22959
22960 procedure Check_Pragma_Conformance
22961 (Context_Pragma : Node_Id;
22962 Entity : Entity_Id;
22963 Entity_Pragma : Node_Id)
22964 is
22965 Err_Id : Entity_Id;
22966 Err_N : Node_Id;
22967
22968 begin
22969 -- The current pragma may appear without an argument. If this
22970 -- is the case, associate all error messages with the pragma
22971 -- itself.
22972
22973 if Present (Arg1) then
22974 Err_N := Arg1;
22975 else
22976 Err_N := N;
22977 end if;
22978
22979 -- The mode of the current pragma is compared against that of
22980 -- an enclosing context.
22981
22982 if Present (Context_Pragma) then
22983 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
22984
22985 -- Issue an error if the new mode is less restrictive than
22986 -- that of the context.
22987
22988 if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off
22989 and then Get_SPARK_Mode_From_Annotation (N) = On
22990 then
22991 Error_Msg_N
22992 ("cannot change SPARK_Mode from Off to On", Err_N);
22993 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
22994 Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N);
22995 raise Pragma_Exit;
22996 end if;
22997 end if;
22998
22999 -- The mode of the current pragma is compared against that of
23000 -- an initial package, protected type, subprogram or task type
23001 -- declaration.
23002
23003 if Present (Entity) then
23004
23005 -- A simple protected or task type is transformed into an
23006 -- anonymous type whose name cannot be used to issue error
23007 -- messages. Recover the original entity of the type.
23008
23009 if Ekind (Entity) in E_Protected_Type | E_Task_Type then
23010 Err_Id :=
23011 Defining_Entity
23012 (Original_Node (Unit_Declaration_Node (Entity)));
23013 else
23014 Err_Id := Entity;
23015 end if;
23016
23017 -- Both the initial declaration and the completion carry
23018 -- SPARK_Mode pragmas.
23019
23020 if Present (Entity_Pragma) then
23021 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
23022
23023 -- Issue an error if the new mode is less restrictive
23024 -- than that of the initial declaration.
23025
23026 if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off
23027 and then Get_SPARK_Mode_From_Annotation (N) = On
23028 then
23029 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
23030 Error_Msg_Sloc := Sloc (Entity_Pragma);
23031 Error_Msg_NE
23032 ("\value Off was set for SPARK_Mode on&#",
23033 Err_N, Err_Id);
23034 raise Pragma_Exit;
23035 end if;
23036
23037 -- Otherwise the initial declaration lacks a SPARK_Mode
23038 -- pragma in which case the current pragma is illegal as
23039 -- it cannot "complete".
23040
23041 elsif Get_SPARK_Mode_From_Annotation (N) = Off
23042 and then (Is_Generic_Unit (Entity) or else In_Instance)
23043 then
23044 null;
23045
23046 else
23047 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
23048 Error_Msg_Sloc := Sloc (Err_Id);
23049 Error_Msg_NE
23050 ("\no value was set for SPARK_Mode on&#",
23051 Err_N, Err_Id);
23052 raise Pragma_Exit;
23053 end if;
23054 end if;
23055 end Check_Pragma_Conformance;
23056
23057 --------------------------------
23058 -- Check_Library_Level_Entity --
23059 --------------------------------
23060
23061 procedure Check_Library_Level_Entity (E : Entity_Id) is
23062 procedure Add_Entity_To_Name_Buffer;
23063 -- Add the E_Kind of entity E to the name buffer
23064
23065 -------------------------------
23066 -- Add_Entity_To_Name_Buffer --
23067 -------------------------------
23068
23069 procedure Add_Entity_To_Name_Buffer is
23070 begin
23071 if Ekind (E) in E_Entry | E_Entry_Family then
23072 Add_Str_To_Name_Buffer ("entry");
23073
23074 elsif Ekind (E) in E_Generic_Package
23075 | E_Package
23076 | E_Package_Body
23077 then
23078 Add_Str_To_Name_Buffer ("package");
23079
23080 elsif Ekind (E) in E_Protected_Body | E_Protected_Type then
23081 Add_Str_To_Name_Buffer ("protected type");
23082
23083 elsif Ekind (E) in E_Function
23084 | E_Generic_Function
23085 | E_Generic_Procedure
23086 | E_Procedure
23087 | E_Subprogram_Body
23088 then
23089 Add_Str_To_Name_Buffer ("subprogram");
23090
23091 else
23092 pragma Assert (Ekind (E) in E_Task_Body | E_Task_Type);
23093 Add_Str_To_Name_Buffer ("task type");
23094 end if;
23095 end Add_Entity_To_Name_Buffer;
23096
23097 -- Local variables
23098
23099 Msg_1 : constant String := "incorrect placement of pragma%";
23100 Msg_2 : Name_Id;
23101
23102 -- Start of processing for Check_Library_Level_Entity
23103
23104 begin
23105 -- A SPARK_Mode of On shall only apply to library-level
23106 -- entities, except for those in generic instances, which are
23107 -- ignored (even if the entity gets SPARK_Mode pragma attached
23108 -- in the AST, its effect is not taken into account unless the
23109 -- context already provides SPARK_Mode of On in GNATprove).
23110
23111 if Get_SPARK_Mode_From_Annotation (N) = On
23112 and then not Is_Library_Level_Entity (E)
23113 and then Instantiation_Location (Sloc (N)) = No_Location
23114 then
23115 Error_Msg_Name_1 := Pname;
23116 Error_Msg_N (Fix_Error (Msg_1), N);
23117
23118 Name_Len := 0;
23119 Add_Str_To_Name_Buffer ("\& is not a library-level ");
23120 Add_Entity_To_Name_Buffer;
23121
23122 Msg_2 := Name_Find;
23123 Error_Msg_NE (Get_Name_String (Msg_2), N, E);
23124
23125 raise Pragma_Exit;
23126 end if;
23127 end Check_Library_Level_Entity;
23128
23129 ------------------
23130 -- Process_Body --
23131 ------------------
23132
23133 procedure Process_Body (Decl : Node_Id) is
23134 Body_Id : constant Entity_Id := Defining_Entity (Decl);
23135 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
23136
23137 begin
23138 -- Ignore pragma when applied to the special body created for
23139 -- inlining, recognized by its internal name _Parent.
23140
23141 if Chars (Body_Id) = Name_uParent then
23142 return;
23143 end if;
23144
23145 Check_Library_Level_Entity (Body_Id);
23146
23147 -- For entry bodies, verify the legality against:
23148 -- * The mode of the context
23149 -- * The mode of the spec (if any)
23150
23151 if Nkind (Decl) in N_Entry_Body | N_Subprogram_Body then
23152
23153 -- A stand-alone subprogram body
23154
23155 if Body_Id = Spec_Id then
23156 Check_Pragma_Conformance
23157 (Context_Pragma => SPARK_Pragma (Body_Id),
23158 Entity => Empty,
23159 Entity_Pragma => Empty);
23160
23161 -- An entry or subprogram body that completes a previous
23162 -- declaration.
23163
23164 else
23165 Check_Pragma_Conformance
23166 (Context_Pragma => SPARK_Pragma (Body_Id),
23167 Entity => Spec_Id,
23168 Entity_Pragma => SPARK_Pragma (Spec_Id));
23169 end if;
23170
23171 Set_SPARK_Context;
23172 Set_SPARK_Pragma (Body_Id, N);
23173 Set_SPARK_Pragma_Inherited (Body_Id, False);
23174
23175 -- For package bodies, verify the legality against:
23176 -- * The mode of the context
23177 -- * The mode of the private part
23178
23179 -- This case is separated from protected and task bodies
23180 -- because the statement part of the package body inherits
23181 -- the mode of the body declarations.
23182
23183 elsif Nkind (Decl) = N_Package_Body then
23184 Check_Pragma_Conformance
23185 (Context_Pragma => SPARK_Pragma (Body_Id),
23186 Entity => Spec_Id,
23187 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
23188
23189 Set_SPARK_Context;
23190 Set_SPARK_Pragma (Body_Id, N);
23191 Set_SPARK_Pragma_Inherited (Body_Id, False);
23192 Set_SPARK_Aux_Pragma (Body_Id, N);
23193 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
23194
23195 -- For protected and task bodies, verify the legality against:
23196 -- * The mode of the context
23197 -- * The mode of the private part
23198
23199 else
23200 pragma Assert
23201 (Nkind (Decl) in N_Protected_Body | N_Task_Body);
23202
23203 Check_Pragma_Conformance
23204 (Context_Pragma => SPARK_Pragma (Body_Id),
23205 Entity => Spec_Id,
23206 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
23207
23208 Set_SPARK_Context;
23209 Set_SPARK_Pragma (Body_Id, N);
23210 Set_SPARK_Pragma_Inherited (Body_Id, False);
23211 end if;
23212 end Process_Body;
23213
23214 --------------------------
23215 -- Process_Overloadable --
23216 --------------------------
23217
23218 procedure Process_Overloadable (Decl : Node_Id) is
23219 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23220 Spec_Typ : constant Entity_Id := Etype (Spec_Id);
23221
23222 begin
23223 Check_Library_Level_Entity (Spec_Id);
23224
23225 -- Verify the legality against:
23226 -- * The mode of the context
23227
23228 Check_Pragma_Conformance
23229 (Context_Pragma => SPARK_Pragma (Spec_Id),
23230 Entity => Empty,
23231 Entity_Pragma => Empty);
23232
23233 Set_SPARK_Pragma (Spec_Id, N);
23234 Set_SPARK_Pragma_Inherited (Spec_Id, False);
23235
23236 -- When the pragma applies to the anonymous object created for
23237 -- a single task type, decorate the type as well. This scenario
23238 -- arises when the single task type lacks a task definition,
23239 -- therefore there is no issue with respect to a potential
23240 -- pragma SPARK_Mode in the private part.
23241
23242 -- task type Anon_Task_Typ;
23243 -- Obj : Anon_Task_Typ;
23244 -- pragma SPARK_Mode ...;
23245
23246 if Is_Single_Task_Object (Spec_Id) then
23247 Set_SPARK_Pragma (Spec_Typ, N);
23248 Set_SPARK_Pragma_Inherited (Spec_Typ, False);
23249 Set_SPARK_Aux_Pragma (Spec_Typ, N);
23250 Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True);
23251 end if;
23252 end Process_Overloadable;
23253
23254 --------------------------
23255 -- Process_Private_Part --
23256 --------------------------
23257
23258 procedure Process_Private_Part (Decl : Node_Id) is
23259 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23260
23261 begin
23262 Check_Library_Level_Entity (Spec_Id);
23263
23264 -- Verify the legality against:
23265 -- * The mode of the visible declarations
23266
23267 Check_Pragma_Conformance
23268 (Context_Pragma => Empty,
23269 Entity => Spec_Id,
23270 Entity_Pragma => SPARK_Pragma (Spec_Id));
23271
23272 Set_SPARK_Context;
23273 Set_SPARK_Aux_Pragma (Spec_Id, N);
23274 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
23275 end Process_Private_Part;
23276
23277 ----------------------------
23278 -- Process_Statement_Part --
23279 ----------------------------
23280
23281 procedure Process_Statement_Part (Decl : Node_Id) is
23282 Body_Id : constant Entity_Id := Defining_Entity (Decl);
23283
23284 begin
23285 Check_Library_Level_Entity (Body_Id);
23286
23287 -- Verify the legality against:
23288 -- * The mode of the body declarations
23289
23290 Check_Pragma_Conformance
23291 (Context_Pragma => Empty,
23292 Entity => Body_Id,
23293 Entity_Pragma => SPARK_Pragma (Body_Id));
23294
23295 Set_SPARK_Context;
23296 Set_SPARK_Aux_Pragma (Body_Id, N);
23297 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
23298 end Process_Statement_Part;
23299
23300 --------------------------
23301 -- Process_Visible_Part --
23302 --------------------------
23303
23304 procedure Process_Visible_Part (Decl : Node_Id) is
23305 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23306 Obj_Id : Entity_Id;
23307
23308 begin
23309 Check_Library_Level_Entity (Spec_Id);
23310
23311 -- Verify the legality against:
23312 -- * The mode of the context
23313
23314 Check_Pragma_Conformance
23315 (Context_Pragma => SPARK_Pragma (Spec_Id),
23316 Entity => Empty,
23317 Entity_Pragma => Empty);
23318
23319 -- A task unit declared without a definition does not set the
23320 -- SPARK_Mode of the context because the task does not have any
23321 -- entries that could inherit the mode.
23322
23323 if Nkind (Decl) not in
23324 N_Single_Task_Declaration | N_Task_Type_Declaration
23325 then
23326 Set_SPARK_Context;
23327 end if;
23328
23329 Set_SPARK_Pragma (Spec_Id, N);
23330 Set_SPARK_Pragma_Inherited (Spec_Id, False);
23331 Set_SPARK_Aux_Pragma (Spec_Id, N);
23332 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
23333
23334 -- When the pragma applies to a single protected or task type,
23335 -- decorate the corresponding anonymous object as well.
23336
23337 -- protected Anon_Prot_Typ is
23338 -- pragma SPARK_Mode ...;
23339 -- ...
23340 -- end Anon_Prot_Typ;
23341
23342 -- Obj : Anon_Prot_Typ;
23343
23344 if Is_Single_Concurrent_Type (Spec_Id) then
23345 Obj_Id := Anonymous_Object (Spec_Id);
23346
23347 Set_SPARK_Pragma (Obj_Id, N);
23348 Set_SPARK_Pragma_Inherited (Obj_Id, False);
23349 end if;
23350 end Process_Visible_Part;
23351
23352 -----------------------
23353 -- Set_SPARK_Context --
23354 -----------------------
23355
23356 procedure Set_SPARK_Context is
23357 begin
23358 SPARK_Mode := Mode_Id;
23359 SPARK_Mode_Pragma := N;
23360 end Set_SPARK_Context;
23361
23362 -- Local variables
23363
23364 Context : Node_Id;
23365 Mode : Name_Id;
23366 Stmt : Node_Id;
23367
23368 -- Start of processing for Do_SPARK_Mode
23369
23370 begin
23371 GNAT_Pragma;
23372 Check_No_Identifiers;
23373 Check_At_Most_N_Arguments (1);
23374
23375 -- Check the legality of the mode (no argument = ON)
23376
23377 if Arg_Count = 1 then
23378 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23379 Mode := Chars (Get_Pragma_Arg (Arg1));
23380 else
23381 Mode := Name_On;
23382 end if;
23383
23384 Mode_Id := Get_SPARK_Mode_Type (Mode);
23385 Context := Parent (N);
23386
23387 -- When a SPARK_Mode pragma appears inside an instantiation whose
23388 -- enclosing context has SPARK_Mode set to "off", the pragma has
23389 -- no semantic effect.
23390
23391 if Ignore_SPARK_Mode_Pragmas_In_Instance
23392 and then Mode_Id /= Off
23393 then
23394 Rewrite (N, Make_Null_Statement (Loc));
23395 Analyze (N);
23396 return;
23397 end if;
23398
23399 -- The pragma appears in a configuration file
23400
23401 if No (Context) then
23402 Check_Valid_Configuration_Pragma;
23403
23404 if Present (SPARK_Mode_Pragma) then
23405 Duplication_Error
23406 (Prag => N,
23407 Prev => SPARK_Mode_Pragma);
23408 raise Pragma_Exit;
23409 end if;
23410
23411 Set_SPARK_Context;
23412
23413 -- The pragma acts as a configuration pragma in a compilation unit
23414
23415 -- pragma SPARK_Mode ...;
23416 -- package Pack is ...;
23417
23418 elsif Nkind (Context) = N_Compilation_Unit
23419 and then List_Containing (N) = Context_Items (Context)
23420 then
23421 Check_Valid_Configuration_Pragma;
23422 Set_SPARK_Context;
23423
23424 -- Otherwise the placement of the pragma within the tree dictates
23425 -- its associated construct. Inspect the declarative list where
23426 -- the pragma resides to find a potential construct.
23427
23428 else
23429 Stmt := Prev (N);
23430 while Present (Stmt) loop
23431
23432 -- Skip prior pragmas, but check for duplicates. Note that
23433 -- this also takes care of pragmas generated for aspects.
23434
23435 if Nkind (Stmt) = N_Pragma then
23436 if Pragma_Name (Stmt) = Pname then
23437 Duplication_Error
23438 (Prag => N,
23439 Prev => Stmt);
23440 raise Pragma_Exit;
23441 end if;
23442
23443 -- The pragma applies to an expression function that has
23444 -- already been rewritten into a subprogram declaration.
23445
23446 -- function Expr_Func return ... is (...);
23447 -- pragma SPARK_Mode ...;
23448
23449 elsif Nkind (Stmt) = N_Subprogram_Declaration
23450 and then Nkind (Original_Node (Stmt)) =
23451 N_Expression_Function
23452 then
23453 Process_Overloadable (Stmt);
23454 return;
23455
23456 -- The pragma applies to the anonymous object created for a
23457 -- single concurrent type.
23458
23459 -- protected type Anon_Prot_Typ ...;
23460 -- Obj : Anon_Prot_Typ;
23461 -- pragma SPARK_Mode ...;
23462
23463 elsif Nkind (Stmt) = N_Object_Declaration
23464 and then Is_Single_Concurrent_Object
23465 (Defining_Entity (Stmt))
23466 then
23467 Process_Overloadable (Stmt);
23468 return;
23469
23470 -- Skip internally generated code
23471
23472 elsif not Comes_From_Source (Stmt) then
23473 null;
23474
23475 -- The pragma applies to an entry or [generic] subprogram
23476 -- declaration.
23477
23478 -- entry Ent ...;
23479 -- pragma SPARK_Mode ...;
23480
23481 -- [generic]
23482 -- procedure Proc ...;
23483 -- pragma SPARK_Mode ...;
23484
23485 elsif Nkind (Stmt) in N_Generic_Subprogram_Declaration
23486 | N_Subprogram_Declaration
23487 or else (Nkind (Stmt) = N_Entry_Declaration
23488 and then Is_Protected_Type
23489 (Scope (Defining_Entity (Stmt))))
23490 then
23491 Process_Overloadable (Stmt);
23492 return;
23493
23494 -- Otherwise the pragma does not apply to a legal construct
23495 -- or it does not appear at the top of a declarative or a
23496 -- statement list. Issue an error and stop the analysis.
23497
23498 else
23499 Pragma_Misplaced;
23500 exit;
23501 end if;
23502
23503 Prev (Stmt);
23504 end loop;
23505
23506 -- The pragma applies to a package or a subprogram that acts as
23507 -- a compilation unit.
23508
23509 -- procedure Proc ...;
23510 -- pragma SPARK_Mode ...;
23511
23512 if Nkind (Context) = N_Compilation_Unit_Aux then
23513 Context := Unit (Parent (Context));
23514 end if;
23515
23516 -- The pragma appears at the top of entry, package, protected
23517 -- unit, subprogram or task unit body declarations.
23518
23519 -- entry Ent when ... is
23520 -- pragma SPARK_Mode ...;
23521
23522 -- package body Pack is
23523 -- pragma SPARK_Mode ...;
23524
23525 -- procedure Proc ... is
23526 -- pragma SPARK_Mode;
23527
23528 -- protected body Prot is
23529 -- pragma SPARK_Mode ...;
23530
23531 if Nkind (Context) in N_Entry_Body
23532 | N_Package_Body
23533 | N_Protected_Body
23534 | N_Subprogram_Body
23535 | N_Task_Body
23536 then
23537 Process_Body (Context);
23538
23539 -- The pragma appears at the top of the visible or private
23540 -- declaration of a package spec, protected or task unit.
23541
23542 -- package Pack is
23543 -- pragma SPARK_Mode ...;
23544 -- private
23545 -- pragma SPARK_Mode ...;
23546
23547 -- protected [type] Prot is
23548 -- pragma SPARK_Mode ...;
23549 -- private
23550 -- pragma SPARK_Mode ...;
23551
23552 elsif Nkind (Context) in N_Package_Specification
23553 | N_Protected_Definition
23554 | N_Task_Definition
23555 then
23556 if List_Containing (N) = Visible_Declarations (Context) then
23557 Process_Visible_Part (Parent (Context));
23558 else
23559 Process_Private_Part (Parent (Context));
23560 end if;
23561
23562 -- The pragma appears at the top of package body statements
23563
23564 -- package body Pack is
23565 -- begin
23566 -- pragma SPARK_Mode;
23567
23568 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
23569 and then Nkind (Parent (Context)) = N_Package_Body
23570 then
23571 Process_Statement_Part (Parent (Context));
23572
23573 -- The pragma appeared as an aspect of a [generic] subprogram
23574 -- declaration that acts as a compilation unit.
23575
23576 -- [generic]
23577 -- procedure Proc ...;
23578 -- pragma SPARK_Mode ...;
23579
23580 elsif Nkind (Context) in N_Generic_Subprogram_Declaration
23581 | N_Subprogram_Declaration
23582 then
23583 Process_Overloadable (Context);
23584
23585 -- The pragma does not apply to a legal construct, issue error
23586
23587 else
23588 Pragma_Misplaced;
23589 end if;
23590 end if;
23591 end Do_SPARK_Mode;
23592
23593 --------------------------------
23594 -- Static_Elaboration_Desired --
23595 --------------------------------
23596
23597 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
23598
23599 when Pragma_Static_Elaboration_Desired =>
23600 GNAT_Pragma;
23601 Check_At_Most_N_Arguments (1);
23602
23603 if Is_Compilation_Unit (Current_Scope)
23604 and then Ekind (Current_Scope) = E_Package
23605 then
23606 Set_Static_Elaboration_Desired (Current_Scope, True);
23607 else
23608 Error_Pragma ("pragma% must apply to a library-level package");
23609 end if;
23610
23611 ------------------
23612 -- Storage_Size --
23613 ------------------
23614
23615 -- pragma Storage_Size (EXPRESSION);
23616
23617 when Pragma_Storage_Size => Storage_Size : declare
23618 P : constant Node_Id := Parent (N);
23619 Arg : Node_Id;
23620
23621 begin
23622 Check_No_Identifiers;
23623 Check_Arg_Count (1);
23624
23625 -- The expression must be analyzed in the special manner described
23626 -- in "Handling of Default Expressions" in sem.ads.
23627
23628 Arg := Get_Pragma_Arg (Arg1);
23629 Preanalyze_Spec_Expression (Arg, Any_Integer);
23630
23631 if not Is_OK_Static_Expression (Arg) then
23632 Check_Restriction (Static_Storage_Size, Arg);
23633 end if;
23634
23635 if Nkind (P) /= N_Task_Definition then
23636 Pragma_Misplaced;
23637 return;
23638
23639 else
23640 if Has_Storage_Size_Pragma (P) then
23641 Error_Pragma ("duplicate pragma% not allowed");
23642 else
23643 Set_Has_Storage_Size_Pragma (P, True);
23644 end if;
23645
23646 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
23647 end if;
23648 end Storage_Size;
23649
23650 ------------------
23651 -- Storage_Unit --
23652 ------------------
23653
23654 -- pragma Storage_Unit (NUMERIC_LITERAL);
23655
23656 -- Only permitted argument is System'Storage_Unit value
23657
23658 when Pragma_Storage_Unit =>
23659 Check_No_Identifiers;
23660 Check_Arg_Count (1);
23661 Check_Arg_Is_Integer_Literal (Arg1);
23662
23663 if Intval (Get_Pragma_Arg (Arg1)) /=
23664 UI_From_Int (Ttypes.System_Storage_Unit)
23665 then
23666 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
23667 Error_Pragma_Arg
23668 ("the only allowed argument for pragma% is ^", Arg1);
23669 end if;
23670
23671 --------------------
23672 -- Stream_Convert --
23673 --------------------
23674
23675 -- pragma Stream_Convert (
23676 -- [Entity =>] type_LOCAL_NAME,
23677 -- [Read =>] function_NAME,
23678 -- [Write =>] function NAME);
23679
23680 when Pragma_Stream_Convert => Stream_Convert : declare
23681 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
23682 -- Check that the given argument is the name of a local function
23683 -- of one argument that is not overloaded earlier in the current
23684 -- local scope. A check is also made that the argument is a
23685 -- function with one parameter.
23686
23687 --------------------------------------
23688 -- Check_OK_Stream_Convert_Function --
23689 --------------------------------------
23690
23691 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
23692 Ent : Entity_Id;
23693
23694 begin
23695 Check_Arg_Is_Local_Name (Arg);
23696 Ent := Entity (Get_Pragma_Arg (Arg));
23697
23698 if Has_Homonym (Ent) then
23699 Error_Pragma_Arg
23700 ("argument for pragma% may not be overloaded", Arg);
23701 end if;
23702
23703 if Ekind (Ent) /= E_Function
23704 or else No (First_Formal (Ent))
23705 or else Present (Next_Formal (First_Formal (Ent)))
23706 then
23707 Error_Pragma_Arg
23708 ("argument for pragma% must be function of one argument",
23709 Arg);
23710 elsif Is_Abstract_Subprogram (Ent) then
23711 Error_Pragma_Arg
23712 ("argument for pragma% cannot be abstract", Arg);
23713 end if;
23714 end Check_OK_Stream_Convert_Function;
23715
23716 -- Start of processing for Stream_Convert
23717
23718 begin
23719 GNAT_Pragma;
23720 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
23721 Check_Arg_Count (3);
23722 Check_Optional_Identifier (Arg1, Name_Entity);
23723 Check_Optional_Identifier (Arg2, Name_Read);
23724 Check_Optional_Identifier (Arg3, Name_Write);
23725 Check_Arg_Is_Local_Name (Arg1);
23726 Check_OK_Stream_Convert_Function (Arg2);
23727 Check_OK_Stream_Convert_Function (Arg3);
23728
23729 declare
23730 Typ : constant Entity_Id :=
23731 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
23732 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
23733 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
23734
23735 begin
23736 Check_First_Subtype (Arg1);
23737
23738 -- Check for too early or too late. Note that we don't enforce
23739 -- the rule about primitive operations in this case, since, as
23740 -- is the case for explicit stream attributes themselves, these
23741 -- restrictions are not appropriate. Note that the chaining of
23742 -- the pragma by Rep_Item_Too_Late is actually the critical
23743 -- processing done for this pragma.
23744
23745 if Rep_Item_Too_Early (Typ, N)
23746 or else
23747 Rep_Item_Too_Late (Typ, N, FOnly => True)
23748 then
23749 return;
23750 end if;
23751
23752 -- Return if previous error
23753
23754 if Etype (Typ) = Any_Type
23755 or else
23756 Etype (Read) = Any_Type
23757 or else
23758 Etype (Write) = Any_Type
23759 then
23760 return;
23761 end if;
23762
23763 -- Error checks
23764
23765 if Underlying_Type (Etype (Read)) /= Typ then
23766 Error_Pragma_Arg
23767 ("incorrect return type for function&", Arg2);
23768 end if;
23769
23770 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
23771 Error_Pragma_Arg
23772 ("incorrect parameter type for function&", Arg3);
23773 end if;
23774
23775 if Underlying_Type (Etype (First_Formal (Read))) /=
23776 Underlying_Type (Etype (Write))
23777 then
23778 Error_Pragma_Arg
23779 ("result type of & does not match Read parameter type",
23780 Arg3);
23781 end if;
23782 end;
23783 end Stream_Convert;
23784
23785 ------------------
23786 -- Style_Checks --
23787 ------------------
23788
23789 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
23790
23791 -- This is processed by the parser since some of the style checks
23792 -- take place during source scanning and parsing. This means that
23793 -- we don't need to issue error messages here.
23794
23795 when Pragma_Style_Checks => Style_Checks : declare
23796 A : constant Node_Id := Get_Pragma_Arg (Arg1);
23797 S : String_Id;
23798 C : Char_Code;
23799
23800 begin
23801 GNAT_Pragma;
23802 Check_No_Identifiers;
23803
23804 -- Two argument form
23805
23806 if Arg_Count = 2 then
23807 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23808
23809 declare
23810 E_Id : Node_Id;
23811 E : Entity_Id;
23812
23813 begin
23814 E_Id := Get_Pragma_Arg (Arg2);
23815 Analyze (E_Id);
23816
23817 if not Is_Entity_Name (E_Id) then
23818 Error_Pragma_Arg
23819 ("second argument of pragma% must be entity name",
23820 Arg2);
23821 end if;
23822
23823 E := Entity (E_Id);
23824
23825 if not Ignore_Style_Checks_Pragmas then
23826 if E = Any_Id then
23827 return;
23828 else
23829 loop
23830 Set_Suppress_Style_Checks
23831 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
23832 exit when No (Homonym (E));
23833 E := Homonym (E);
23834 end loop;
23835 end if;
23836 end if;
23837 end;
23838
23839 -- One argument form
23840
23841 else
23842 Check_Arg_Count (1);
23843
23844 if Nkind (A) = N_String_Literal then
23845 S := Strval (A);
23846
23847 declare
23848 Slen : constant Natural := Natural (String_Length (S));
23849 Options : String (1 .. Slen);
23850 J : Positive;
23851
23852 begin
23853 J := 1;
23854 loop
23855 C := Get_String_Char (S, Pos (J));
23856 exit when not In_Character_Range (C);
23857 Options (J) := Get_Character (C);
23858
23859 -- If at end of string, set options. As per discussion
23860 -- above, no need to check for errors, since we issued
23861 -- them in the parser.
23862
23863 if J = Slen then
23864 if not Ignore_Style_Checks_Pragmas then
23865 Set_Style_Check_Options (Options);
23866 end if;
23867
23868 exit;
23869 end if;
23870
23871 J := J + 1;
23872 end loop;
23873 end;
23874
23875 elsif Nkind (A) = N_Identifier then
23876 if Chars (A) = Name_All_Checks then
23877 if not Ignore_Style_Checks_Pragmas then
23878 if GNAT_Mode then
23879 Set_GNAT_Style_Check_Options;
23880 else
23881 Set_Default_Style_Check_Options;
23882 end if;
23883 end if;
23884
23885 elsif Chars (A) = Name_On then
23886 if not Ignore_Style_Checks_Pragmas then
23887 Style_Check := True;
23888 end if;
23889
23890 elsif Chars (A) = Name_Off then
23891 if not Ignore_Style_Checks_Pragmas then
23892 Style_Check := False;
23893 end if;
23894 end if;
23895 end if;
23896 end if;
23897 end Style_Checks;
23898
23899 --------------
23900 -- Subtitle --
23901 --------------
23902
23903 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
23904
23905 when Pragma_Subtitle =>
23906 GNAT_Pragma;
23907 Check_Arg_Count (1);
23908 Check_Optional_Identifier (Arg1, Name_Subtitle);
23909 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
23910 Store_Note (N);
23911
23912 --------------
23913 -- Suppress --
23914 --------------
23915
23916 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
23917
23918 when Pragma_Suppress =>
23919 Process_Suppress_Unsuppress (Suppress_Case => True);
23920
23921 ------------------
23922 -- Suppress_All --
23923 ------------------
23924
23925 -- pragma Suppress_All;
23926
23927 -- The only check made here is that the pragma has no arguments.
23928 -- There are no placement rules, and the processing required (setting
23929 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
23930 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
23931 -- then creates and inserts a pragma Suppress (All_Checks).
23932
23933 when Pragma_Suppress_All =>
23934 GNAT_Pragma;
23935 Check_Arg_Count (0);
23936
23937 -------------------------
23938 -- Suppress_Debug_Info --
23939 -------------------------
23940
23941 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
23942
23943 when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare
23944 Nam_Id : Entity_Id;
23945
23946 begin
23947 GNAT_Pragma;
23948 Check_Arg_Count (1);
23949 Check_Optional_Identifier (Arg1, Name_Entity);
23950 Check_Arg_Is_Local_Name (Arg1);
23951
23952 Nam_Id := Entity (Get_Pragma_Arg (Arg1));
23953
23954 -- A pragma that applies to a Ghost entity becomes Ghost for the
23955 -- purposes of legality checks and removal of ignored Ghost code.
23956
23957 Mark_Ghost_Pragma (N, Nam_Id);
23958 Set_Debug_Info_Off (Nam_Id);
23959 end Suppress_Debug_Info;
23960
23961 ----------------------------------
23962 -- Suppress_Exception_Locations --
23963 ----------------------------------
23964
23965 -- pragma Suppress_Exception_Locations;
23966
23967 when Pragma_Suppress_Exception_Locations =>
23968 GNAT_Pragma;
23969 Check_Arg_Count (0);
23970 Check_Valid_Configuration_Pragma;
23971 Exception_Locations_Suppressed := True;
23972
23973 -----------------------------
23974 -- Suppress_Initialization --
23975 -----------------------------
23976
23977 -- pragma Suppress_Initialization ([Entity =>] type_Name);
23978
23979 when Pragma_Suppress_Initialization => Suppress_Init : declare
23980 E : Entity_Id;
23981 E_Id : Node_Id;
23982
23983 begin
23984 GNAT_Pragma;
23985 Check_Arg_Count (1);
23986 Check_Optional_Identifier (Arg1, Name_Entity);
23987 Check_Arg_Is_Local_Name (Arg1);
23988
23989 E_Id := Get_Pragma_Arg (Arg1);
23990
23991 if Etype (E_Id) = Any_Type then
23992 return;
23993 end if;
23994
23995 E := Entity (E_Id);
23996
23997 -- A pragma that applies to a Ghost entity becomes Ghost for the
23998 -- purposes of legality checks and removal of ignored Ghost code.
23999
24000 Mark_Ghost_Pragma (N, E);
24001
24002 if not Is_Type (E) and then Ekind (E) /= E_Variable then
24003 Error_Pragma_Arg
24004 ("pragma% requires variable, type or subtype", Arg1);
24005 end if;
24006
24007 if Rep_Item_Too_Early (E, N)
24008 or else
24009 Rep_Item_Too_Late (E, N, FOnly => True)
24010 then
24011 return;
24012 end if;
24013
24014 -- For incomplete/private type, set flag on full view
24015
24016 if Is_Incomplete_Or_Private_Type (E) then
24017 if No (Full_View (Base_Type (E))) then
24018 Error_Pragma_Arg
24019 ("argument of pragma% cannot be an incomplete type", Arg1);
24020 else
24021 Set_Suppress_Initialization (Full_View (E));
24022 end if;
24023
24024 -- For first subtype, set flag on base type
24025
24026 elsif Is_First_Subtype (E) then
24027 Set_Suppress_Initialization (Base_Type (E));
24028
24029 -- For other than first subtype, set flag on subtype or variable
24030
24031 else
24032 Set_Suppress_Initialization (E);
24033 end if;
24034 end Suppress_Init;
24035
24036 -----------------
24037 -- System_Name --
24038 -----------------
24039
24040 -- pragma System_Name (DIRECT_NAME);
24041
24042 -- Syntax check: one argument, which must be the identifier GNAT or
24043 -- the identifier GCC, no other identifiers are acceptable.
24044
24045 when Pragma_System_Name =>
24046 GNAT_Pragma;
24047 Check_No_Identifiers;
24048 Check_Arg_Count (1);
24049 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
24050
24051 -----------------------------
24052 -- Task_Dispatching_Policy --
24053 -----------------------------
24054
24055 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
24056
24057 when Pragma_Task_Dispatching_Policy => declare
24058 DP : Character;
24059
24060 begin
24061 Check_Ada_83_Warning;
24062 Check_Arg_Count (1);
24063 Check_No_Identifiers;
24064 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
24065 Check_Valid_Configuration_Pragma;
24066 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
24067 DP := Fold_Upper (Name_Buffer (1));
24068
24069 if Task_Dispatching_Policy /= ' '
24070 and then Task_Dispatching_Policy /= DP
24071 then
24072 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
24073 Error_Pragma
24074 ("task dispatching policy incompatible with policy#");
24075
24076 -- Set new policy, but always preserve System_Location since we
24077 -- like the error message with the run time name.
24078
24079 else
24080 Task_Dispatching_Policy := DP;
24081
24082 if Task_Dispatching_Policy_Sloc /= System_Location then
24083 Task_Dispatching_Policy_Sloc := Loc;
24084 end if;
24085 end if;
24086 end;
24087
24088 ---------------
24089 -- Task_Info --
24090 ---------------
24091
24092 -- pragma Task_Info (EXPRESSION);
24093
24094 when Pragma_Task_Info => Task_Info : declare
24095 P : constant Node_Id := Parent (N);
24096 Ent : Entity_Id;
24097
24098 begin
24099 GNAT_Pragma;
24100
24101 if Warn_On_Obsolescent_Feature then
24102 Error_Msg_N
24103 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
24104 & "instead?j?", N);
24105 end if;
24106
24107 if Nkind (P) /= N_Task_Definition then
24108 Error_Pragma ("pragma% must appear in task definition");
24109 end if;
24110
24111 Check_No_Identifiers;
24112 Check_Arg_Count (1);
24113
24114 Analyze_And_Resolve
24115 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
24116
24117 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
24118 return;
24119 end if;
24120
24121 Ent := Defining_Identifier (Parent (P));
24122
24123 -- Check duplicate pragma before we chain the pragma in the Rep
24124 -- Item chain of Ent.
24125
24126 if Has_Rep_Pragma
24127 (Ent, Name_Task_Info, Check_Parents => False)
24128 then
24129 Error_Pragma ("duplicate pragma% not allowed");
24130 end if;
24131
24132 Record_Rep_Item (Ent, N);
24133 end Task_Info;
24134
24135 ---------------
24136 -- Task_Name --
24137 ---------------
24138
24139 -- pragma Task_Name (string_EXPRESSION);
24140
24141 when Pragma_Task_Name => Task_Name : declare
24142 P : constant Node_Id := Parent (N);
24143 Arg : Node_Id;
24144 Ent : Entity_Id;
24145
24146 begin
24147 Check_No_Identifiers;
24148 Check_Arg_Count (1);
24149
24150 Arg := Get_Pragma_Arg (Arg1);
24151
24152 -- The expression is used in the call to Create_Task, and must be
24153 -- expanded there, not in the context of the current spec. It must
24154 -- however be analyzed to capture global references, in case it
24155 -- appears in a generic context.
24156
24157 Preanalyze_And_Resolve (Arg, Standard_String);
24158
24159 if Nkind (P) /= N_Task_Definition then
24160 Pragma_Misplaced;
24161 end if;
24162
24163 Ent := Defining_Identifier (Parent (P));
24164
24165 -- Check duplicate pragma before we chain the pragma in the Rep
24166 -- Item chain of Ent.
24167
24168 if Has_Rep_Pragma
24169 (Ent, Name_Task_Name, Check_Parents => False)
24170 then
24171 Error_Pragma ("duplicate pragma% not allowed");
24172 end if;
24173
24174 Record_Rep_Item (Ent, N);
24175 end Task_Name;
24176
24177 ------------------
24178 -- Task_Storage --
24179 ------------------
24180
24181 -- pragma Task_Storage (
24182 -- [Task_Type =>] LOCAL_NAME,
24183 -- [Top_Guard =>] static_integer_EXPRESSION);
24184
24185 when Pragma_Task_Storage => Task_Storage : declare
24186 Args : Args_List (1 .. 2);
24187 Names : constant Name_List (1 .. 2) := (
24188 Name_Task_Type,
24189 Name_Top_Guard);
24190
24191 Task_Type : Node_Id renames Args (1);
24192 Top_Guard : Node_Id renames Args (2);
24193
24194 Ent : Entity_Id;
24195
24196 begin
24197 GNAT_Pragma;
24198 Gather_Associations (Names, Args);
24199
24200 if No (Task_Type) then
24201 Error_Pragma
24202 ("missing task_type argument for pragma%");
24203 end if;
24204
24205 Check_Arg_Is_Local_Name (Task_Type);
24206
24207 Ent := Entity (Task_Type);
24208
24209 if not Is_Task_Type (Ent) then
24210 Error_Pragma_Arg
24211 ("argument for pragma% must be task type", Task_Type);
24212 end if;
24213
24214 if No (Top_Guard) then
24215 Error_Pragma_Arg
24216 ("pragma% takes two arguments", Task_Type);
24217 else
24218 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
24219 end if;
24220
24221 Check_First_Subtype (Task_Type);
24222
24223 if Rep_Item_Too_Late (Ent, N) then
24224 raise Pragma_Exit;
24225 end if;
24226 end Task_Storage;
24227
24228 ---------------
24229 -- Test_Case --
24230 ---------------
24231
24232 -- pragma Test_Case
24233 -- ([Name =>] Static_String_EXPRESSION
24234 -- ,[Mode =>] MODE_TYPE
24235 -- [, Requires => Boolean_EXPRESSION]
24236 -- [, Ensures => Boolean_EXPRESSION]);
24237
24238 -- MODE_TYPE ::= Nominal | Robustness
24239
24240 -- Characteristics:
24241
24242 -- * Analysis - The annotation undergoes initial checks to verify
24243 -- the legal placement and context. Secondary checks preanalyze the
24244 -- expressions in:
24245
24246 -- Analyze_Test_Case_In_Decl_Part
24247
24248 -- * Expansion - None.
24249
24250 -- * Template - The annotation utilizes the generic template of the
24251 -- related subprogram when it is:
24252
24253 -- aspect on subprogram declaration
24254
24255 -- The annotation must prepare its own template when it is:
24256
24257 -- pragma on subprogram declaration
24258
24259 -- * Globals - Capture of global references must occur after full
24260 -- analysis.
24261
24262 -- * Instance - The annotation is instantiated automatically when
24263 -- the related generic subprogram is instantiated except for the
24264 -- "pragma on subprogram declaration" case. In that scenario the
24265 -- annotation must instantiate itself.
24266
24267 when Pragma_Test_Case => Test_Case : declare
24268 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
24269 -- Ensure that the contract of subprogram Subp_Id does not contain
24270 -- another Test_Case pragma with the same Name as the current one.
24271
24272 -------------------------
24273 -- Check_Distinct_Name --
24274 -------------------------
24275
24276 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
24277 Items : constant Node_Id := Contract (Subp_Id);
24278 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
24279 Prag : Node_Id;
24280
24281 begin
24282 -- Inspect all Test_Case pragma of the related subprogram
24283 -- looking for one with a duplicate "Name" argument.
24284
24285 if Present (Items) then
24286 Prag := Contract_Test_Cases (Items);
24287 while Present (Prag) loop
24288 if Pragma_Name (Prag) = Name_Test_Case
24289 and then Prag /= N
24290 and then String_Equal
24291 (Name, Get_Name_From_CTC_Pragma (Prag))
24292 then
24293 Error_Msg_Sloc := Sloc (Prag);
24294 Error_Pragma ("name for pragma % is already used #");
24295 end if;
24296
24297 Prag := Next_Pragma (Prag);
24298 end loop;
24299 end if;
24300 end Check_Distinct_Name;
24301
24302 -- Local variables
24303
24304 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
24305 Asp_Arg : Node_Id;
24306 Context : Node_Id;
24307 Subp_Decl : Node_Id;
24308 Subp_Id : Entity_Id;
24309
24310 -- Start of processing for Test_Case
24311
24312 begin
24313 GNAT_Pragma;
24314 Check_At_Least_N_Arguments (2);
24315 Check_At_Most_N_Arguments (4);
24316 Check_Arg_Order
24317 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
24318
24319 -- Argument "Name"
24320
24321 Check_Optional_Identifier (Arg1, Name_Name);
24322 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
24323
24324 -- Argument "Mode"
24325
24326 Check_Optional_Identifier (Arg2, Name_Mode);
24327 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
24328
24329 -- Arguments "Requires" and "Ensures"
24330
24331 if Present (Arg3) then
24332 if Present (Arg4) then
24333 Check_Identifier (Arg3, Name_Requires);
24334 Check_Identifier (Arg4, Name_Ensures);
24335 else
24336 Check_Identifier_Is_One_Of
24337 (Arg3, Name_Requires, Name_Ensures);
24338 end if;
24339 end if;
24340
24341 -- Pragma Test_Case must be associated with a subprogram declared
24342 -- in a library-level package. First determine whether the current
24343 -- compilation unit is a legal context.
24344
24345 if Nkind (Pack_Decl) in N_Package_Declaration
24346 | N_Generic_Package_Declaration
24347 then
24348 null;
24349
24350 -- Otherwise the placement is illegal
24351
24352 else
24353 Error_Pragma
24354 ("pragma % must be specified within a package declaration");
24355 return;
24356 end if;
24357
24358 Subp_Decl := Find_Related_Declaration_Or_Body (N);
24359
24360 -- Find the enclosing context
24361
24362 Context := Parent (Subp_Decl);
24363
24364 if Present (Context) then
24365 Context := Parent (Context);
24366 end if;
24367
24368 -- Verify the placement of the pragma
24369
24370 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
24371 Error_Pragma
24372 ("pragma % cannot be applied to abstract subprogram");
24373 return;
24374
24375 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
24376 Error_Pragma ("pragma % cannot be applied to entry");
24377 return;
24378
24379 -- The context is a [generic] subprogram declared at the top level
24380 -- of the [generic] package unit.
24381
24382 elsif Nkind (Subp_Decl) in N_Generic_Subprogram_Declaration
24383 | N_Subprogram_Declaration
24384 and then Present (Context)
24385 and then Nkind (Context) in N_Generic_Package_Declaration
24386 | N_Package_Declaration
24387 then
24388 null;
24389
24390 -- Otherwise the placement is illegal
24391
24392 else
24393 Error_Pragma
24394 ("pragma % must be applied to a library-level subprogram "
24395 & "declaration");
24396 return;
24397 end if;
24398
24399 Subp_Id := Defining_Entity (Subp_Decl);
24400
24401 -- A pragma that applies to a Ghost entity becomes Ghost for the
24402 -- purposes of legality checks and removal of ignored Ghost code.
24403
24404 Mark_Ghost_Pragma (N, Subp_Id);
24405
24406 -- Chain the pragma on the contract for further processing by
24407 -- Analyze_Test_Case_In_Decl_Part.
24408
24409 Add_Contract_Item (N, Subp_Id);
24410
24411 -- Preanalyze the original aspect argument "Name" for a generic
24412 -- subprogram to properly capture global references.
24413
24414 if Is_Generic_Subprogram (Subp_Id) then
24415 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
24416
24417 if Present (Asp_Arg) then
24418
24419 -- The argument appears with an identifier in association
24420 -- form.
24421
24422 if Nkind (Asp_Arg) = N_Component_Association then
24423 Asp_Arg := Expression (Asp_Arg);
24424 end if;
24425
24426 Check_Expr_Is_OK_Static_Expression
24427 (Asp_Arg, Standard_String);
24428 end if;
24429 end if;
24430
24431 -- Ensure that the all Test_Case pragmas of the related subprogram
24432 -- have distinct names.
24433
24434 Check_Distinct_Name (Subp_Id);
24435
24436 -- Fully analyze the pragma when it appears inside an entry
24437 -- or subprogram body because it cannot benefit from forward
24438 -- references.
24439
24440 if Nkind (Subp_Decl) in N_Entry_Body
24441 | N_Subprogram_Body
24442 | N_Subprogram_Body_Stub
24443 then
24444 -- The legality checks of pragma Test_Case are affected by the
24445 -- SPARK mode in effect and the volatility of the context.
24446 -- Analyze all pragmas in a specific order.
24447
24448 Analyze_If_Present (Pragma_SPARK_Mode);
24449 Analyze_If_Present (Pragma_Volatile_Function);
24450 Analyze_Test_Case_In_Decl_Part (N);
24451 end if;
24452 end Test_Case;
24453
24454 --------------------------
24455 -- Thread_Local_Storage --
24456 --------------------------
24457
24458 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
24459
24460 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
24461 E : Entity_Id;
24462 Id : Node_Id;
24463
24464 begin
24465 GNAT_Pragma;
24466 Check_Arg_Count (1);
24467 Check_Optional_Identifier (Arg1, Name_Entity);
24468 Check_Arg_Is_Library_Level_Local_Name (Arg1);
24469
24470 Id := Get_Pragma_Arg (Arg1);
24471 Analyze (Id);
24472
24473 if not Is_Entity_Name (Id)
24474 or else Ekind (Entity (Id)) /= E_Variable
24475 then
24476 Error_Pragma_Arg ("local variable name required", Arg1);
24477 end if;
24478
24479 E := Entity (Id);
24480
24481 -- A pragma that applies to a Ghost entity becomes Ghost for the
24482 -- purposes of legality checks and removal of ignored Ghost code.
24483
24484 Mark_Ghost_Pragma (N, E);
24485
24486 if Rep_Item_Too_Early (E, N)
24487 or else
24488 Rep_Item_Too_Late (E, N)
24489 then
24490 raise Pragma_Exit;
24491 end if;
24492
24493 Set_Has_Pragma_Thread_Local_Storage (E);
24494 Set_Has_Gigi_Rep_Item (E);
24495 end Thread_Local_Storage;
24496
24497 ----------------
24498 -- Time_Slice --
24499 ----------------
24500
24501 -- pragma Time_Slice (static_duration_EXPRESSION);
24502
24503 when Pragma_Time_Slice => Time_Slice : declare
24504 Val : Ureal;
24505 Nod : Node_Id;
24506
24507 begin
24508 GNAT_Pragma;
24509 Check_Arg_Count (1);
24510 Check_No_Identifiers;
24511 Check_In_Main_Program;
24512 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
24513
24514 if not Error_Posted (Arg1) then
24515 Nod := Next (N);
24516 while Present (Nod) loop
24517 if Nkind (Nod) = N_Pragma
24518 and then Pragma_Name (Nod) = Name_Time_Slice
24519 then
24520 Error_Msg_Name_1 := Pname;
24521 Error_Msg_N ("duplicate pragma% not permitted", Nod);
24522 end if;
24523
24524 Next (Nod);
24525 end loop;
24526 end if;
24527
24528 -- Process only if in main unit
24529
24530 if Get_Source_Unit (Loc) = Main_Unit then
24531 Opt.Time_Slice_Set := True;
24532 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
24533
24534 if Val <= Ureal_0 then
24535 Opt.Time_Slice_Value := 0;
24536
24537 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
24538 Opt.Time_Slice_Value := 1_000_000_000;
24539
24540 else
24541 Opt.Time_Slice_Value :=
24542 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
24543 end if;
24544 end if;
24545 end Time_Slice;
24546
24547 -----------
24548 -- Title --
24549 -----------
24550
24551 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
24552
24553 -- TITLING_OPTION ::=
24554 -- [Title =>] STRING_LITERAL
24555 -- | [Subtitle =>] STRING_LITERAL
24556
24557 when Pragma_Title => Title : declare
24558 Args : Args_List (1 .. 2);
24559 Names : constant Name_List (1 .. 2) := (
24560 Name_Title,
24561 Name_Subtitle);
24562
24563 begin
24564 GNAT_Pragma;
24565 Gather_Associations (Names, Args);
24566 Store_Note (N);
24567
24568 for J in 1 .. 2 loop
24569 if Present (Args (J)) then
24570 Check_Arg_Is_OK_Static_Expression
24571 (Args (J), Standard_String);
24572 end if;
24573 end loop;
24574 end Title;
24575
24576 ----------------------------
24577 -- Type_Invariant[_Class] --
24578 ----------------------------
24579
24580 -- pragma Type_Invariant[_Class]
24581 -- ([Entity =>] type_LOCAL_NAME,
24582 -- [Check =>] EXPRESSION);
24583
24584 when Pragma_Type_Invariant
24585 | Pragma_Type_Invariant_Class
24586 =>
24587 Type_Invariant : declare
24588 I_Pragma : Node_Id;
24589
24590 begin
24591 Check_Arg_Count (2);
24592
24593 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
24594 -- setting Class_Present for the Type_Invariant_Class case.
24595
24596 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
24597 I_Pragma := New_Copy (N);
24598 Set_Pragma_Identifier
24599 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
24600 Rewrite (N, I_Pragma);
24601 Set_Analyzed (N, False);
24602 Analyze (N);
24603 end Type_Invariant;
24604
24605 ---------------------
24606 -- Unchecked_Union --
24607 ---------------------
24608
24609 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
24610
24611 when Pragma_Unchecked_Union => Unchecked_Union : declare
24612 Assoc : constant Node_Id := Arg1;
24613 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
24614 Clist : Node_Id;
24615 Comp : Node_Id;
24616 Tdef : Node_Id;
24617 Typ : Entity_Id;
24618 Variant : Node_Id;
24619 Vpart : Node_Id;
24620
24621 begin
24622 Ada_2005_Pragma;
24623 Check_No_Identifiers;
24624 Check_Arg_Count (1);
24625 Check_Arg_Is_Local_Name (Arg1);
24626
24627 Find_Type (Type_Id);
24628
24629 Typ := Entity (Type_Id);
24630
24631 -- A pragma that applies to a Ghost entity becomes Ghost for the
24632 -- purposes of legality checks and removal of ignored Ghost code.
24633
24634 Mark_Ghost_Pragma (N, Typ);
24635
24636 if Typ = Any_Type
24637 or else Rep_Item_Too_Early (Typ, N)
24638 then
24639 return;
24640 else
24641 Typ := Underlying_Type (Typ);
24642 end if;
24643
24644 if Rep_Item_Too_Late (Typ, N) then
24645 return;
24646 end if;
24647
24648 Check_First_Subtype (Arg1);
24649
24650 -- Note remaining cases are references to a type in the current
24651 -- declarative part. If we find an error, we post the error on
24652 -- the relevant type declaration at an appropriate point.
24653
24654 if not Is_Record_Type (Typ) then
24655 Error_Msg_N ("unchecked union must be record type", Typ);
24656 return;
24657
24658 elsif Is_Tagged_Type (Typ) then
24659 Error_Msg_N ("unchecked union must not be tagged", Typ);
24660 return;
24661
24662 elsif not Has_Discriminants (Typ) then
24663 Error_Msg_N
24664 ("unchecked union must have one discriminant", Typ);
24665 return;
24666
24667 -- Note: in previous versions of GNAT we used to check for limited
24668 -- types and give an error, but in fact the standard does allow
24669 -- Unchecked_Union on limited types, so this check was removed.
24670
24671 -- Similarly, GNAT used to require that all discriminants have
24672 -- default values, but this is not mandated by the RM.
24673
24674 -- Proceed with basic error checks completed
24675
24676 else
24677 Tdef := Type_Definition (Declaration_Node (Typ));
24678 Clist := Component_List (Tdef);
24679
24680 -- Check presence of component list and variant part
24681
24682 if No (Clist) or else No (Variant_Part (Clist)) then
24683 Error_Msg_N
24684 ("unchecked union must have variant part", Tdef);
24685 return;
24686 end if;
24687
24688 -- Check components
24689
24690 Comp := First_Non_Pragma (Component_Items (Clist));
24691 while Present (Comp) loop
24692 Check_Component (Comp, Typ);
24693 Next_Non_Pragma (Comp);
24694 end loop;
24695
24696 -- Check variant part
24697
24698 Vpart := Variant_Part (Clist);
24699
24700 Variant := First_Non_Pragma (Variants (Vpart));
24701 while Present (Variant) loop
24702 Check_Variant (Variant, Typ);
24703 Next_Non_Pragma (Variant);
24704 end loop;
24705 end if;
24706
24707 Set_Is_Unchecked_Union (Typ);
24708 Set_Convention (Typ, Convention_C);
24709 Set_Has_Unchecked_Union (Base_Type (Typ));
24710 Set_Is_Unchecked_Union (Base_Type (Typ));
24711 end Unchecked_Union;
24712
24713 ----------------------------
24714 -- Unevaluated_Use_Of_Old --
24715 ----------------------------
24716
24717 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
24718
24719 when Pragma_Unevaluated_Use_Of_Old =>
24720 GNAT_Pragma;
24721 Check_Arg_Count (1);
24722 Check_No_Identifiers;
24723 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
24724
24725 -- Suppress/Unsuppress can appear as a configuration pragma, or in
24726 -- a declarative part or a package spec.
24727
24728 if not Is_Configuration_Pragma then
24729 Check_Is_In_Decl_Part_Or_Package_Spec;
24730 end if;
24731
24732 -- Store proper setting of Uneval_Old
24733
24734 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
24735 Uneval_Old := Fold_Upper (Name_Buffer (1));
24736
24737 ------------------------
24738 -- Unimplemented_Unit --
24739 ------------------------
24740
24741 -- pragma Unimplemented_Unit;
24742
24743 -- Note: this only gives an error if we are generating code, or if
24744 -- we are in a generic library unit (where the pragma appears in the
24745 -- body, not in the spec).
24746
24747 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
24748 Cunitent : constant Entity_Id :=
24749 Cunit_Entity (Get_Source_Unit (Loc));
24750 Ent_Kind : constant Entity_Kind := Ekind (Cunitent);
24751
24752 begin
24753 GNAT_Pragma;
24754 Check_Arg_Count (0);
24755
24756 if Operating_Mode = Generate_Code
24757 or else Ent_Kind = E_Generic_Function
24758 or else Ent_Kind = E_Generic_Procedure
24759 or else Ent_Kind = E_Generic_Package
24760 then
24761 Get_Name_String (Chars (Cunitent));
24762 Set_Casing (Mixed_Case);
24763 Write_Str (Name_Buffer (1 .. Name_Len));
24764 Write_Str (" is not supported in this configuration");
24765 Write_Eol;
24766 raise Unrecoverable_Error;
24767 end if;
24768 end Unimplemented_Unit;
24769
24770 ------------------------
24771 -- Universal_Aliasing --
24772 ------------------------
24773
24774 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
24775
24776 when Pragma_Universal_Aliasing => Universal_Alias : declare
24777 E : Entity_Id;
24778 E_Id : Node_Id;
24779
24780 begin
24781 GNAT_Pragma;
24782 Check_Arg_Count (1);
24783 Check_Optional_Identifier (Arg2, Name_Entity);
24784 Check_Arg_Is_Local_Name (Arg1);
24785 E_Id := Get_Pragma_Arg (Arg1);
24786
24787 if Etype (E_Id) = Any_Type then
24788 return;
24789 end if;
24790
24791 E := Entity (E_Id);
24792
24793 if not Is_Type (E) then
24794 Error_Pragma_Arg ("pragma% requires type", Arg1);
24795 end if;
24796
24797 -- A pragma that applies to a Ghost entity becomes Ghost for the
24798 -- purposes of legality checks and removal of ignored Ghost code.
24799
24800 Mark_Ghost_Pragma (N, E);
24801 Set_Universal_Aliasing (Base_Type (E));
24802 Record_Rep_Item (E, N);
24803 end Universal_Alias;
24804
24805 --------------------
24806 -- Universal_Data --
24807 --------------------
24808
24809 -- pragma Universal_Data [(library_unit_NAME)];
24810
24811 when Pragma_Universal_Data =>
24812 GNAT_Pragma;
24813 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
24814
24815 ----------------
24816 -- Unmodified --
24817 ----------------
24818
24819 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
24820
24821 when Pragma_Unmodified =>
24822 Analyze_Unmodified_Or_Unused;
24823
24824 ------------------
24825 -- Unreferenced --
24826 ------------------
24827
24828 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
24829
24830 -- or when used in a context clause:
24831
24832 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
24833
24834 when Pragma_Unreferenced =>
24835 Analyze_Unreferenced_Or_Unused;
24836
24837 --------------------------
24838 -- Unreferenced_Objects --
24839 --------------------------
24840
24841 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
24842
24843 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
24844 Arg : Node_Id;
24845 Arg_Expr : Node_Id;
24846 Arg_Id : Entity_Id;
24847
24848 Ghost_Error_Posted : Boolean := False;
24849 -- Flag set when an error concerning the illegal mix of Ghost and
24850 -- non-Ghost types is emitted.
24851
24852 Ghost_Id : Entity_Id := Empty;
24853 -- The entity of the first Ghost type encountered while processing
24854 -- the arguments of the pragma.
24855
24856 begin
24857 GNAT_Pragma;
24858 Check_At_Least_N_Arguments (1);
24859
24860 Arg := Arg1;
24861 while Present (Arg) loop
24862 Check_No_Identifier (Arg);
24863 Check_Arg_Is_Local_Name (Arg);
24864 Arg_Expr := Get_Pragma_Arg (Arg);
24865
24866 if Is_Entity_Name (Arg_Expr) then
24867 Arg_Id := Entity (Arg_Expr);
24868
24869 if Is_Type (Arg_Id) then
24870 Set_Has_Pragma_Unreferenced_Objects (Arg_Id);
24871
24872 -- A pragma that applies to a Ghost entity becomes Ghost
24873 -- for the purposes of legality checks and removal of
24874 -- ignored Ghost code.
24875
24876 Mark_Ghost_Pragma (N, Arg_Id);
24877
24878 -- Capture the entity of the first Ghost type being
24879 -- processed for error detection purposes.
24880
24881 if Is_Ghost_Entity (Arg_Id) then
24882 if No (Ghost_Id) then
24883 Ghost_Id := Arg_Id;
24884 end if;
24885
24886 -- Otherwise the type is non-Ghost. It is illegal to mix
24887 -- references to Ghost and non-Ghost entities
24888 -- (SPARK RM 6.9).
24889
24890 elsif Present (Ghost_Id)
24891 and then not Ghost_Error_Posted
24892 then
24893 Ghost_Error_Posted := True;
24894
24895 Error_Msg_Name_1 := Pname;
24896 Error_Msg_N
24897 ("pragma % cannot mention ghost and non-ghost types",
24898 N);
24899
24900 Error_Msg_Sloc := Sloc (Ghost_Id);
24901 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
24902
24903 Error_Msg_Sloc := Sloc (Arg_Id);
24904 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
24905 end if;
24906 else
24907 Error_Pragma_Arg
24908 ("argument for pragma% must be type or subtype", Arg);
24909 end if;
24910 else
24911 Error_Pragma_Arg
24912 ("argument for pragma% must be type or subtype", Arg);
24913 end if;
24914
24915 Next (Arg);
24916 end loop;
24917 end Unreferenced_Objects;
24918
24919 ------------------------------
24920 -- Unreserve_All_Interrupts --
24921 ------------------------------
24922
24923 -- pragma Unreserve_All_Interrupts;
24924
24925 when Pragma_Unreserve_All_Interrupts =>
24926 GNAT_Pragma;
24927 Check_Arg_Count (0);
24928
24929 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
24930 Unreserve_All_Interrupts := True;
24931 end if;
24932
24933 ----------------
24934 -- Unsuppress --
24935 ----------------
24936
24937 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
24938
24939 when Pragma_Unsuppress =>
24940 Ada_2005_Pragma;
24941 Process_Suppress_Unsuppress (Suppress_Case => False);
24942
24943 ------------
24944 -- Unused --
24945 ------------
24946
24947 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
24948
24949 when Pragma_Unused =>
24950 Analyze_Unmodified_Or_Unused (Is_Unused => True);
24951 Analyze_Unreferenced_Or_Unused (Is_Unused => True);
24952
24953 -------------------
24954 -- Use_VADS_Size --
24955 -------------------
24956
24957 -- pragma Use_VADS_Size;
24958
24959 when Pragma_Use_VADS_Size =>
24960 GNAT_Pragma;
24961 Check_Arg_Count (0);
24962 Check_Valid_Configuration_Pragma;
24963 Use_VADS_Size := True;
24964
24965 ---------------------
24966 -- Validity_Checks --
24967 ---------------------
24968
24969 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
24970
24971 when Pragma_Validity_Checks => Validity_Checks : declare
24972 A : constant Node_Id := Get_Pragma_Arg (Arg1);
24973 S : String_Id;
24974 C : Char_Code;
24975
24976 begin
24977 GNAT_Pragma;
24978 Check_Arg_Count (1);
24979 Check_No_Identifiers;
24980
24981 -- Pragma always active unless in CodePeer or GNATprove modes,
24982 -- which use a fixed configuration of validity checks.
24983
24984 if not (CodePeer_Mode or GNATprove_Mode) then
24985 if Nkind (A) = N_String_Literal then
24986 S := Strval (A);
24987
24988 declare
24989 Slen : constant Natural := Natural (String_Length (S));
24990 Options : String (1 .. Slen);
24991 J : Positive;
24992
24993 begin
24994 -- Couldn't we use a for loop here over Options'Range???
24995
24996 J := 1;
24997 loop
24998 C := Get_String_Char (S, Pos (J));
24999
25000 -- This is a weird test, it skips setting validity
25001 -- checks entirely if any element of S is out of
25002 -- range of Character, what is that about ???
25003
25004 exit when not In_Character_Range (C);
25005 Options (J) := Get_Character (C);
25006
25007 if J = Slen then
25008 Set_Validity_Check_Options (Options);
25009 exit;
25010 else
25011 J := J + 1;
25012 end if;
25013 end loop;
25014 end;
25015
25016 elsif Nkind (A) = N_Identifier then
25017 if Chars (A) = Name_All_Checks then
25018 Set_Validity_Check_Options ("a");
25019 elsif Chars (A) = Name_On then
25020 Validity_Checks_On := True;
25021 elsif Chars (A) = Name_Off then
25022 Validity_Checks_On := False;
25023 end if;
25024 end if;
25025 end if;
25026 end Validity_Checks;
25027
25028 --------------
25029 -- Volatile --
25030 --------------
25031
25032 -- pragma Volatile (LOCAL_NAME);
25033
25034 when Pragma_Volatile =>
25035 Process_Atomic_Independent_Shared_Volatile;
25036
25037 -------------------------
25038 -- Volatile_Components --
25039 -------------------------
25040
25041 -- pragma Volatile_Components (array_LOCAL_NAME);
25042
25043 -- Volatile is handled by the same circuit as Atomic_Components
25044
25045 --------------------------
25046 -- Volatile_Full_Access --
25047 --------------------------
25048
25049 -- pragma Volatile_Full_Access (LOCAL_NAME);
25050
25051 when Pragma_Volatile_Full_Access =>
25052 GNAT_Pragma;
25053 Process_Atomic_Independent_Shared_Volatile;
25054
25055 -----------------------
25056 -- Volatile_Function --
25057 -----------------------
25058
25059 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
25060
25061 when Pragma_Volatile_Function => Volatile_Function : declare
25062 Over_Id : Entity_Id;
25063 Spec_Id : Entity_Id;
25064 Subp_Decl : Node_Id;
25065
25066 begin
25067 GNAT_Pragma;
25068 Check_No_Identifiers;
25069 Check_At_Most_N_Arguments (1);
25070
25071 Subp_Decl :=
25072 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
25073
25074 -- Generic subprogram
25075
25076 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
25077 null;
25078
25079 -- Body acts as spec
25080
25081 elsif Nkind (Subp_Decl) = N_Subprogram_Body
25082 and then No (Corresponding_Spec (Subp_Decl))
25083 then
25084 null;
25085
25086 -- Body stub acts as spec
25087
25088 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
25089 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
25090 then
25091 null;
25092
25093 -- Subprogram
25094
25095 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
25096 null;
25097
25098 else
25099 Pragma_Misplaced;
25100 return;
25101 end if;
25102
25103 Spec_Id := Unique_Defining_Entity (Subp_Decl);
25104
25105 if Ekind (Spec_Id) not in E_Function | E_Generic_Function then
25106 Pragma_Misplaced;
25107 return;
25108 end if;
25109
25110 -- A pragma that applies to a Ghost entity becomes Ghost for the
25111 -- purposes of legality checks and removal of ignored Ghost code.
25112
25113 Mark_Ghost_Pragma (N, Spec_Id);
25114
25115 -- Chain the pragma on the contract for completeness
25116
25117 Add_Contract_Item (N, Spec_Id);
25118
25119 -- The legality checks of pragma Volatile_Function are affected by
25120 -- the SPARK mode in effect. Analyze all pragmas in a specific
25121 -- order.
25122
25123 Analyze_If_Present (Pragma_SPARK_Mode);
25124
25125 -- A volatile function cannot override a non-volatile function
25126 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
25127 -- in New_Overloaded_Entity, however at that point the pragma has
25128 -- not been processed yet.
25129
25130 Over_Id := Overridden_Operation (Spec_Id);
25131
25132 if Present (Over_Id)
25133 and then not Is_Volatile_Function (Over_Id)
25134 then
25135 Error_Msg_N
25136 ("incompatible volatile function values in effect", Spec_Id);
25137
25138 Error_Msg_Sloc := Sloc (Over_Id);
25139 Error_Msg_N
25140 ("\& declared # with Volatile_Function value False",
25141 Spec_Id);
25142
25143 Error_Msg_Sloc := Sloc (Spec_Id);
25144 Error_Msg_N
25145 ("\overridden # with Volatile_Function value True",
25146 Spec_Id);
25147 end if;
25148
25149 -- Analyze the Boolean expression (if any)
25150
25151 if Present (Arg1) then
25152 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
25153 end if;
25154 end Volatile_Function;
25155
25156 ----------------------
25157 -- Warning_As_Error --
25158 ----------------------
25159
25160 -- pragma Warning_As_Error (static_string_EXPRESSION);
25161
25162 when Pragma_Warning_As_Error =>
25163 GNAT_Pragma;
25164 Check_Arg_Count (1);
25165 Check_No_Identifiers;
25166 Check_Valid_Configuration_Pragma;
25167
25168 if not Is_Static_String_Expression (Arg1) then
25169 Error_Pragma_Arg
25170 ("argument of pragma% must be static string expression",
25171 Arg1);
25172
25173 -- OK static string expression
25174
25175 else
25176 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
25177 Warnings_As_Errors (Warnings_As_Errors_Count) :=
25178 new String'(Acquire_Warning_Match_String
25179 (Expr_Value_S (Get_Pragma_Arg (Arg1))));
25180 end if;
25181
25182 --------------
25183 -- Warnings --
25184 --------------
25185
25186 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
25187
25188 -- DETAILS ::= On | Off
25189 -- DETAILS ::= On | Off, local_NAME
25190 -- DETAILS ::= static_string_EXPRESSION
25191 -- DETAILS ::= On | Off, static_string_EXPRESSION
25192
25193 -- TOOL_NAME ::= GNAT | GNATprove
25194
25195 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
25196
25197 -- Note: If the first argument matches an allowed tool name, it is
25198 -- always considered to be a tool name, even if there is a string
25199 -- variable of that name.
25200
25201 -- Note if the second argument of DETAILS is a local_NAME then the
25202 -- second form is always understood. If the intention is to use
25203 -- the fourth form, then you can write NAME & "" to force the
25204 -- intepretation as a static_string_EXPRESSION.
25205
25206 when Pragma_Warnings => Warnings : declare
25207 Reason : String_Id;
25208
25209 begin
25210 GNAT_Pragma;
25211 Check_At_Least_N_Arguments (1);
25212
25213 -- See if last argument is labeled Reason. If so, make sure we
25214 -- have a string literal or a concatenation of string literals,
25215 -- and acquire the REASON string. Then remove the REASON argument
25216 -- by decreasing Num_Args by one; Remaining processing looks only
25217 -- at first Num_Args arguments).
25218
25219 declare
25220 Last_Arg : constant Node_Id :=
25221 Last (Pragma_Argument_Associations (N));
25222
25223 begin
25224 if Nkind (Last_Arg) = N_Pragma_Argument_Association
25225 and then Chars (Last_Arg) = Name_Reason
25226 then
25227 Start_String;
25228 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
25229 Reason := End_String;
25230 Arg_Count := Arg_Count - 1;
25231
25232 -- Not allowed in compiler units (bootstrap issues)
25233
25234 Check_Compiler_Unit ("Reason for pragma Warnings", N);
25235
25236 -- No REASON string, set null string as reason
25237
25238 else
25239 Reason := Null_String_Id;
25240 end if;
25241 end;
25242
25243 -- Now proceed with REASON taken care of and eliminated
25244
25245 Check_No_Identifiers;
25246
25247 -- If debug flag -gnatd.i is set, pragma is ignored
25248
25249 if Debug_Flag_Dot_I then
25250 return;
25251 end if;
25252
25253 -- Process various forms of the pragma
25254
25255 declare
25256 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
25257 Shifted_Args : List_Id;
25258
25259 begin
25260 -- See if first argument is a tool name, currently either
25261 -- GNAT or GNATprove. If so, either ignore the pragma if the
25262 -- tool used does not match, or continue as if no tool name
25263 -- was given otherwise, by shifting the arguments.
25264
25265 if Nkind (Argx) = N_Identifier
25266 and then Chars (Argx) in Name_Gnat | Name_Gnatprove
25267 then
25268 if Chars (Argx) = Name_Gnat then
25269 if CodePeer_Mode or GNATprove_Mode then
25270 Rewrite (N, Make_Null_Statement (Loc));
25271 Analyze (N);
25272 raise Pragma_Exit;
25273 end if;
25274
25275 elsif Chars (Argx) = Name_Gnatprove then
25276 if not GNATprove_Mode then
25277 Rewrite (N, Make_Null_Statement (Loc));
25278 Analyze (N);
25279 raise Pragma_Exit;
25280 end if;
25281
25282 else
25283 raise Program_Error;
25284 end if;
25285
25286 -- At this point, the pragma Warnings applies to the tool,
25287 -- so continue with shifted arguments.
25288
25289 Arg_Count := Arg_Count - 1;
25290
25291 if Arg_Count = 1 then
25292 Shifted_Args := New_List (New_Copy (Arg2));
25293 elsif Arg_Count = 2 then
25294 Shifted_Args := New_List (New_Copy (Arg2),
25295 New_Copy (Arg3));
25296 elsif Arg_Count = 3 then
25297 Shifted_Args := New_List (New_Copy (Arg2),
25298 New_Copy (Arg3),
25299 New_Copy (Arg4));
25300 else
25301 raise Program_Error;
25302 end if;
25303
25304 Rewrite (N,
25305 Make_Pragma (Loc,
25306 Chars => Name_Warnings,
25307 Pragma_Argument_Associations => Shifted_Args));
25308 Analyze (N);
25309 raise Pragma_Exit;
25310 end if;
25311
25312 -- One argument case
25313
25314 if Arg_Count = 1 then
25315
25316 -- On/Off one argument case was processed by parser
25317
25318 if Nkind (Argx) = N_Identifier
25319 and then Chars (Argx) in Name_On | Name_Off
25320 then
25321 null;
25322
25323 -- One argument case must be ON/OFF or static string expr
25324
25325 elsif not Is_Static_String_Expression (Arg1) then
25326 Error_Pragma_Arg
25327 ("argument of pragma% must be On/Off or static string "
25328 & "expression", Arg1);
25329
25330 -- One argument string expression case
25331
25332 else
25333 declare
25334 Lit : constant Node_Id := Expr_Value_S (Argx);
25335 Str : constant String_Id := Strval (Lit);
25336 Len : constant Nat := String_Length (Str);
25337 C : Char_Code;
25338 J : Nat;
25339 OK : Boolean;
25340 Chr : Character;
25341
25342 begin
25343 J := 1;
25344 while J <= Len loop
25345 C := Get_String_Char (Str, J);
25346 OK := In_Character_Range (C);
25347
25348 if OK then
25349 Chr := Get_Character (C);
25350
25351 -- Dash case: only -Wxxx is accepted
25352
25353 if J = 1
25354 and then J < Len
25355 and then Chr = '-'
25356 then
25357 J := J + 1;
25358 C := Get_String_Char (Str, J);
25359 Chr := Get_Character (C);
25360 exit when Chr = 'W';
25361 OK := False;
25362
25363 -- Dot case
25364
25365 elsif J < Len and then Chr = '.' then
25366 J := J + 1;
25367 C := Get_String_Char (Str, J);
25368 Chr := Get_Character (C);
25369
25370 if not Set_Dot_Warning_Switch (Chr) then
25371 Error_Pragma_Arg
25372 ("invalid warning switch character "
25373 & '.' & Chr, Arg1);
25374 end if;
25375
25376 -- Non-Dot case
25377
25378 else
25379 OK := Set_Warning_Switch (Chr);
25380 end if;
25381
25382 if not OK then
25383 Error_Pragma_Arg
25384 ("invalid warning switch character " & Chr,
25385 Arg1);
25386 end if;
25387
25388 else
25389 Error_Pragma_Arg
25390 ("invalid wide character in warning switch ",
25391 Arg1);
25392 end if;
25393
25394 J := J + 1;
25395 end loop;
25396 end;
25397 end if;
25398
25399 -- Two or more arguments (must be two)
25400
25401 else
25402 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
25403 Check_Arg_Count (2);
25404
25405 declare
25406 E_Id : Node_Id;
25407 E : Entity_Id;
25408 Err : Boolean;
25409
25410 begin
25411 E_Id := Get_Pragma_Arg (Arg2);
25412 Analyze (E_Id);
25413
25414 -- In the expansion of an inlined body, a reference to
25415 -- the formal may be wrapped in a conversion if the
25416 -- actual is a conversion. Retrieve the real entity name.
25417
25418 if (In_Instance_Body or In_Inlined_Body)
25419 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
25420 then
25421 E_Id := Expression (E_Id);
25422 end if;
25423
25424 -- Entity name case
25425
25426 if Is_Entity_Name (E_Id) then
25427 E := Entity (E_Id);
25428
25429 if E = Any_Id then
25430 return;
25431 else
25432 loop
25433 Set_Warnings_Off
25434 (E, (Chars (Get_Pragma_Arg (Arg1)) =
25435 Name_Off));
25436
25437 -- Suppress elaboration warnings if the entity
25438 -- denotes an elaboration target.
25439
25440 if Is_Elaboration_Target (E) then
25441 Set_Is_Elaboration_Warnings_OK_Id (E, False);
25442 end if;
25443
25444 -- For OFF case, make entry in warnings off
25445 -- pragma table for later processing. But we do
25446 -- not do that within an instance, since these
25447 -- warnings are about what is needed in the
25448 -- template, not an instance of it.
25449
25450 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
25451 and then Warn_On_Warnings_Off
25452 and then not In_Instance
25453 then
25454 Warnings_Off_Pragmas.Append ((N, E, Reason));
25455 end if;
25456
25457 if Is_Enumeration_Type (E) then
25458 declare
25459 Lit : Entity_Id;
25460 begin
25461 Lit := First_Literal (E);
25462 while Present (Lit) loop
25463 Set_Warnings_Off (Lit);
25464 Next_Literal (Lit);
25465 end loop;
25466 end;
25467 end if;
25468
25469 exit when No (Homonym (E));
25470 E := Homonym (E);
25471 end loop;
25472 end if;
25473
25474 -- Error if not entity or static string expression case
25475
25476 elsif not Is_Static_String_Expression (Arg2) then
25477 Error_Pragma_Arg
25478 ("second argument of pragma% must be entity name "
25479 & "or static string expression", Arg2);
25480
25481 -- Static string expression case
25482
25483 else
25484 -- Note on configuration pragma case: If this is a
25485 -- configuration pragma, then for an OFF pragma, we
25486 -- just set Config True in the call, which is all
25487 -- that needs to be done. For the case of ON, this
25488 -- is normally an error, unless it is canceling the
25489 -- effect of a previous OFF pragma in the same file.
25490 -- In any other case, an error will be signalled (ON
25491 -- with no matching OFF).
25492
25493 -- Note: We set Used if we are inside a generic to
25494 -- disable the test that the non-config case actually
25495 -- cancels a warning. That's because we can't be sure
25496 -- there isn't an instantiation in some other unit
25497 -- where a warning is suppressed.
25498
25499 -- We could do a little better here by checking if the
25500 -- generic unit we are inside is public, but for now
25501 -- we don't bother with that refinement.
25502
25503 declare
25504 Message : constant String :=
25505 Acquire_Warning_Match_String
25506 (Expr_Value_S (Get_Pragma_Arg (Arg2)));
25507 begin
25508 if Chars (Argx) = Name_Off then
25509 Set_Specific_Warning_Off
25510 (Loc, Message, Reason,
25511 Config => Is_Configuration_Pragma,
25512 Used => Inside_A_Generic or else In_Instance);
25513
25514 elsif Chars (Argx) = Name_On then
25515 Set_Specific_Warning_On (Loc, Message, Err);
25516
25517 if Err then
25518 Error_Msg
25519 ("??pragma Warnings On with no matching "
25520 & "Warnings Off", Loc);
25521 end if;
25522 end if;
25523 end;
25524 end if;
25525 end;
25526 end if;
25527 end;
25528 end Warnings;
25529
25530 -------------------
25531 -- Weak_External --
25532 -------------------
25533
25534 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
25535
25536 when Pragma_Weak_External => Weak_External : declare
25537 Ent : Entity_Id;
25538
25539 begin
25540 GNAT_Pragma;
25541 Check_Arg_Count (1);
25542 Check_Optional_Identifier (Arg1, Name_Entity);
25543 Check_Arg_Is_Library_Level_Local_Name (Arg1);
25544 Ent := Entity (Get_Pragma_Arg (Arg1));
25545
25546 if Rep_Item_Too_Early (Ent, N) then
25547 return;
25548 else
25549 Ent := Underlying_Type (Ent);
25550 end if;
25551
25552 -- The pragma applies to entities with addresses
25553
25554 if Is_Type (Ent) then
25555 Error_Pragma ("pragma applies to objects and subprograms");
25556 end if;
25557
25558 -- The only processing required is to link this item on to the
25559 -- list of rep items for the given entity. This is accomplished
25560 -- by the call to Rep_Item_Too_Late (when no error is detected
25561 -- and False is returned).
25562
25563 if Rep_Item_Too_Late (Ent, N) then
25564 return;
25565 else
25566 Set_Has_Gigi_Rep_Item (Ent);
25567 end if;
25568 end Weak_External;
25569
25570 -----------------------------
25571 -- Wide_Character_Encoding --
25572 -----------------------------
25573
25574 -- pragma Wide_Character_Encoding (IDENTIFIER);
25575
25576 when Pragma_Wide_Character_Encoding =>
25577 GNAT_Pragma;
25578
25579 -- Nothing to do, handled in parser. Note that we do not enforce
25580 -- configuration pragma placement, this pragma can appear at any
25581 -- place in the source, allowing mixed encodings within a single
25582 -- source program.
25583
25584 null;
25585
25586 --------------------
25587 -- Unknown_Pragma --
25588 --------------------
25589
25590 -- Should be impossible, since the case of an unknown pragma is
25591 -- separately processed before the case statement is entered.
25592
25593 when Unknown_Pragma =>
25594 raise Program_Error;
25595 end case;
25596
25597 -- AI05-0144: detect dangerous order dependence. Disabled for now,
25598 -- until AI is formally approved.
25599
25600 -- Check_Order_Dependence;
25601
25602 exception
25603 when Pragma_Exit => null;
25604 end Analyze_Pragma;
25605
25606 ---------------------------------------------
25607 -- Analyze_Pre_Post_Condition_In_Decl_Part --
25608 ---------------------------------------------
25609
25610 -- WARNING: This routine manages Ghost regions. Return statements must be
25611 -- replaced by gotos which jump to the end of the routine and restore the
25612 -- Ghost mode.
25613
25614 procedure Analyze_Pre_Post_Condition_In_Decl_Part
25615 (N : Node_Id;
25616 Freeze_Id : Entity_Id := Empty)
25617 is
25618 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
25619 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
25620
25621 Disp_Typ : Entity_Id;
25622 -- The dispatching type of the subprogram subject to the pre- or
25623 -- postcondition.
25624
25625 function Check_References (Nod : Node_Id) return Traverse_Result;
25626 -- Check that expression Nod does not mention non-primitives of the
25627 -- type, global objects of the type, or other illegalities described
25628 -- and implied by AI12-0113.
25629
25630 ----------------------
25631 -- Check_References --
25632 ----------------------
25633
25634 function Check_References (Nod : Node_Id) return Traverse_Result is
25635 begin
25636 if Nkind (Nod) = N_Function_Call
25637 and then Is_Entity_Name (Name (Nod))
25638 then
25639 declare
25640 Func : constant Entity_Id := Entity (Name (Nod));
25641 Form : Entity_Id;
25642
25643 begin
25644 -- An operation of the type must be a primitive
25645
25646 if No (Find_Dispatching_Type (Func)) then
25647 Form := First_Formal (Func);
25648 while Present (Form) loop
25649 if Etype (Form) = Disp_Typ then
25650 Error_Msg_NE
25651 ("operation in class-wide condition must be "
25652 & "primitive of &", Nod, Disp_Typ);
25653 end if;
25654
25655 Next_Formal (Form);
25656 end loop;
25657
25658 -- A return object of the type is illegal as well
25659
25660 if Etype (Func) = Disp_Typ
25661 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
25662 then
25663 Error_Msg_NE
25664 ("operation in class-wide condition must be primitive "
25665 & "of &", Nod, Disp_Typ);
25666 end if;
25667
25668 -- Otherwise we have a call to an overridden primitive, and we
25669 -- will create a common class-wide clone for the body of
25670 -- original operation and its eventual inherited versions. If
25671 -- the original operation dispatches on result it is never
25672 -- inherited and there is no need for a clone. There is not
25673 -- need for a clone either in GNATprove mode, as cases that
25674 -- would require it are rejected (when an inherited primitive
25675 -- calls an overridden operation in a class-wide contract), and
25676 -- the clone would make proof impossible in some cases.
25677
25678 elsif not Is_Abstract_Subprogram (Spec_Id)
25679 and then No (Class_Wide_Clone (Spec_Id))
25680 and then not Has_Controlling_Result (Spec_Id)
25681 and then not GNATprove_Mode
25682 then
25683 Build_Class_Wide_Clone_Decl (Spec_Id);
25684 end if;
25685 end;
25686
25687 elsif Is_Entity_Name (Nod)
25688 and then
25689 (Etype (Nod) = Disp_Typ
25690 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
25691 and then Ekind (Entity (Nod)) in E_Constant | E_Variable
25692 then
25693 Error_Msg_NE
25694 ("object in class-wide condition must be formal of type &",
25695 Nod, Disp_Typ);
25696
25697 elsif Nkind (Nod) = N_Explicit_Dereference
25698 and then (Etype (Nod) = Disp_Typ
25699 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
25700 and then (not Is_Entity_Name (Prefix (Nod))
25701 or else not Is_Formal (Entity (Prefix (Nod))))
25702 then
25703 Error_Msg_NE
25704 ("operation in class-wide condition must be primitive of &",
25705 Nod, Disp_Typ);
25706 end if;
25707
25708 return OK;
25709 end Check_References;
25710
25711 procedure Check_Class_Wide_Condition is
25712 new Traverse_Proc (Check_References);
25713
25714 -- Local variables
25715
25716 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
25717
25718 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
25719 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
25720 -- Save the Ghost-related attributes to restore on exit
25721
25722 Errors : Nat;
25723 Restore_Scope : Boolean := False;
25724
25725 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
25726
25727 begin
25728 -- Do not analyze the pragma multiple times
25729
25730 if Is_Analyzed_Pragma (N) then
25731 return;
25732 end if;
25733
25734 -- Set the Ghost mode in effect from the pragma. Due to the delayed
25735 -- analysis of the pragma, the Ghost mode at point of declaration and
25736 -- point of analysis may not necessarily be the same. Use the mode in
25737 -- effect at the point of declaration.
25738
25739 Set_Ghost_Mode (N);
25740
25741 -- Ensure that the subprogram and its formals are visible when analyzing
25742 -- the expression of the pragma.
25743
25744 if not In_Open_Scopes (Spec_Id) then
25745 Restore_Scope := True;
25746 Push_Scope (Spec_Id);
25747
25748 if Is_Generic_Subprogram (Spec_Id) then
25749 Install_Generic_Formals (Spec_Id);
25750 else
25751 Install_Formals (Spec_Id);
25752 end if;
25753 end if;
25754
25755 Errors := Serious_Errors_Detected;
25756 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
25757
25758 -- Emit a clarification message when the expression contains at least
25759 -- one undefined reference, possibly due to contract freezing.
25760
25761 if Errors /= Serious_Errors_Detected
25762 and then Present (Freeze_Id)
25763 and then Has_Undefined_Reference (Expr)
25764 then
25765 Contract_Freeze_Error (Spec_Id, Freeze_Id);
25766 end if;
25767
25768 if Class_Present (N) then
25769
25770 -- Verify that a class-wide condition is legal, i.e. the operation is
25771 -- a primitive of a tagged type. Note that a generic subprogram is
25772 -- not a primitive operation.
25773
25774 Disp_Typ := Find_Dispatching_Type (Spec_Id);
25775
25776 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
25777 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
25778
25779 if From_Aspect_Specification (N) then
25780 Error_Msg_N
25781 ("aspect % can only be specified for a primitive operation "
25782 & "of a tagged type", Corresponding_Aspect (N));
25783
25784 -- The pragma is a source construct
25785
25786 else
25787 Error_Msg_N
25788 ("pragma % can only be specified for a primitive operation "
25789 & "of a tagged type", N);
25790 end if;
25791
25792 -- Remaining semantic checks require a full tree traversal
25793
25794 else
25795 Check_Class_Wide_Condition (Expr);
25796 end if;
25797
25798 end if;
25799
25800 if Restore_Scope then
25801 End_Scope;
25802 end if;
25803
25804 -- If analysis of the condition indicates that a class-wide clone
25805 -- has been created, build and analyze its declaration.
25806
25807 if Is_Subprogram (Spec_Id)
25808 and then Present (Class_Wide_Clone (Spec_Id))
25809 then
25810 Analyze (Unit_Declaration_Node (Class_Wide_Clone (Spec_Id)));
25811 end if;
25812
25813 -- Currently it is not possible to inline pre/postconditions on a
25814 -- subprogram subject to pragma Inline_Always.
25815
25816 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
25817 Set_Is_Analyzed_Pragma (N);
25818
25819 Restore_Ghost_Region (Saved_GM, Saved_IGR);
25820 end Analyze_Pre_Post_Condition_In_Decl_Part;
25821
25822 ------------------------------------------
25823 -- Analyze_Refined_Depends_In_Decl_Part --
25824 ------------------------------------------
25825
25826 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
25827 procedure Check_Dependency_Clause
25828 (Spec_Id : Entity_Id;
25829 Dep_Clause : Node_Id;
25830 Dep_States : Elist_Id;
25831 Refinements : List_Id;
25832 Matched_Items : in out Elist_Id);
25833 -- Try to match a single dependency clause Dep_Clause against one or
25834 -- more refinement clauses found in list Refinements. Each successful
25835 -- match eliminates at least one refinement clause from Refinements.
25836 -- Spec_Id denotes the entity of the related subprogram. Dep_States
25837 -- denotes the entities of all abstract states which appear in pragma
25838 -- Depends. Matched_Items contains the entities of all successfully
25839 -- matched items found in pragma Depends.
25840
25841 procedure Check_Output_States
25842 (Spec_Inputs : Elist_Id;
25843 Spec_Outputs : Elist_Id;
25844 Body_Inputs : Elist_Id;
25845 Body_Outputs : Elist_Id);
25846 -- Determine whether pragma Depends contains an output state with a
25847 -- visible refinement and if so, ensure that pragma Refined_Depends
25848 -- mentions all its constituents as outputs. Spec_Inputs and
25849 -- Spec_Outputs denote the inputs and outputs of the subprogram spec
25850 -- synthesized from pragma Depends. Body_Inputs and Body_Outputs denote
25851 -- the inputs and outputs of the subprogram body synthesized from pragma
25852 -- Refined_Depends.
25853
25854 function Collect_States (Clauses : List_Id) return Elist_Id;
25855 -- Given a normalized list of dependencies obtained from calling
25856 -- Normalize_Clauses, return a list containing the entities of all
25857 -- states appearing in dependencies. It helps in checking refinements
25858 -- involving a state and a corresponding constituent which is not a
25859 -- direct constituent of the state.
25860
25861 procedure Normalize_Clauses (Clauses : List_Id);
25862 -- Given a list of dependence or refinement clauses Clauses, normalize
25863 -- each clause by creating multiple dependencies with exactly one input
25864 -- and one output.
25865
25866 procedure Remove_Extra_Clauses
25867 (Clauses : List_Id;
25868 Matched_Items : Elist_Id);
25869 -- Given a list of refinement clauses Clauses, remove all clauses whose
25870 -- inputs and/or outputs have been previously matched. See the body for
25871 -- all special cases. Matched_Items contains the entities of all matched
25872 -- items found in pragma Depends.
25873
25874 procedure Report_Extra_Clauses (Clauses : List_Id);
25875 -- Emit an error for each extra clause found in list Clauses
25876
25877 -----------------------------
25878 -- Check_Dependency_Clause --
25879 -----------------------------
25880
25881 procedure Check_Dependency_Clause
25882 (Spec_Id : Entity_Id;
25883 Dep_Clause : Node_Id;
25884 Dep_States : Elist_Id;
25885 Refinements : List_Id;
25886 Matched_Items : in out Elist_Id)
25887 is
25888 Dep_Input : constant Node_Id := Expression (Dep_Clause);
25889 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
25890
25891 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
25892 -- Determine whether dependency item Dep_Item has been matched in a
25893 -- previous clause.
25894
25895 function Is_In_Out_State_Clause return Boolean;
25896 -- Determine whether dependence clause Dep_Clause denotes an abstract
25897 -- state that depends on itself (State => State).
25898
25899 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
25900 -- Determine whether item Item denotes an abstract state with visible
25901 -- null refinement.
25902
25903 procedure Match_Items
25904 (Dep_Item : Node_Id;
25905 Ref_Item : Node_Id;
25906 Matched : out Boolean);
25907 -- Try to match dependence item Dep_Item against refinement item
25908 -- Ref_Item. To match against a possible null refinement (see 2, 9),
25909 -- set Ref_Item to Empty. Flag Matched is set to True when one of
25910 -- the following conformance scenarios is in effect:
25911 -- 1) Both items denote null
25912 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
25913 -- 3) Both items denote attribute 'Result
25914 -- 4) Both items denote the same object
25915 -- 5) Both items denote the same formal parameter
25916 -- 6) Both items denote the same current instance of a type
25917 -- 7) Both items denote the same discriminant
25918 -- 8) Dep_Item is an abstract state with visible null refinement
25919 -- and Ref_Item denotes null.
25920 -- 9) Dep_Item is an abstract state with visible null refinement
25921 -- and Ref_Item is Empty (special case).
25922 -- 10) Dep_Item is an abstract state with full or partial visible
25923 -- non-null refinement and Ref_Item denotes one of its
25924 -- constituents.
25925 -- 11) Dep_Item is an abstract state without a full visible
25926 -- refinement and Ref_Item denotes the same state.
25927 -- When scenario 10 is in effect, the entity of the abstract state
25928 -- denoted by Dep_Item is added to list Refined_States.
25929
25930 procedure Record_Item (Item_Id : Entity_Id);
25931 -- Store the entity of an item denoted by Item_Id in Matched_Items
25932
25933 ------------------------
25934 -- Is_Already_Matched --
25935 ------------------------
25936
25937 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean is
25938 Item_Id : Entity_Id := Empty;
25939
25940 begin
25941 -- When the dependency item denotes attribute 'Result, check for
25942 -- the entity of the related subprogram.
25943
25944 if Is_Attribute_Result (Dep_Item) then
25945 Item_Id := Spec_Id;
25946
25947 elsif Is_Entity_Name (Dep_Item) then
25948 Item_Id := Available_View (Entity_Of (Dep_Item));
25949 end if;
25950
25951 return
25952 Present (Item_Id) and then Contains (Matched_Items, Item_Id);
25953 end Is_Already_Matched;
25954
25955 ----------------------------
25956 -- Is_In_Out_State_Clause --
25957 ----------------------------
25958
25959 function Is_In_Out_State_Clause return Boolean is
25960 Dep_Input_Id : Entity_Id;
25961 Dep_Output_Id : Entity_Id;
25962
25963 begin
25964 -- Detect the following clause:
25965 -- State => State
25966
25967 if Is_Entity_Name (Dep_Input)
25968 and then Is_Entity_Name (Dep_Output)
25969 then
25970 -- Handle abstract views generated for limited with clauses
25971
25972 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
25973 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
25974
25975 return
25976 Ekind (Dep_Input_Id) = E_Abstract_State
25977 and then Dep_Input_Id = Dep_Output_Id;
25978 else
25979 return False;
25980 end if;
25981 end Is_In_Out_State_Clause;
25982
25983 ---------------------------
25984 -- Is_Null_Refined_State --
25985 ---------------------------
25986
25987 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
25988 Item_Id : Entity_Id;
25989
25990 begin
25991 if Is_Entity_Name (Item) then
25992
25993 -- Handle abstract views generated for limited with clauses
25994
25995 Item_Id := Available_View (Entity_Of (Item));
25996
25997 return
25998 Ekind (Item_Id) = E_Abstract_State
25999 and then Has_Null_Visible_Refinement (Item_Id);
26000 else
26001 return False;
26002 end if;
26003 end Is_Null_Refined_State;
26004
26005 -----------------
26006 -- Match_Items --
26007 -----------------
26008
26009 procedure Match_Items
26010 (Dep_Item : Node_Id;
26011 Ref_Item : Node_Id;
26012 Matched : out Boolean)
26013 is
26014 Dep_Item_Id : Entity_Id;
26015 Ref_Item_Id : Entity_Id;
26016
26017 begin
26018 -- Assume that the two items do not match
26019
26020 Matched := False;
26021
26022 -- A null matches null or Empty (special case)
26023
26024 if Nkind (Dep_Item) = N_Null
26025 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
26026 then
26027 Matched := True;
26028
26029 -- Attribute 'Result matches attribute 'Result
26030
26031 elsif Is_Attribute_Result (Dep_Item)
26032 and then Is_Attribute_Result (Ref_Item)
26033 then
26034 -- Put the entity of the related function on the list of
26035 -- matched items because attribute 'Result does not carry
26036 -- an entity similar to states and constituents.
26037
26038 Record_Item (Spec_Id);
26039 Matched := True;
26040
26041 -- Abstract states, current instances of concurrent types,
26042 -- discriminants, formal parameters and objects.
26043
26044 elsif Is_Entity_Name (Dep_Item) then
26045
26046 -- Handle abstract views generated for limited with clauses
26047
26048 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
26049
26050 if Ekind (Dep_Item_Id) = E_Abstract_State then
26051
26052 -- An abstract state with visible null refinement matches
26053 -- null or Empty (special case).
26054
26055 if Has_Null_Visible_Refinement (Dep_Item_Id)
26056 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
26057 then
26058 Record_Item (Dep_Item_Id);
26059 Matched := True;
26060
26061 -- An abstract state with visible non-null refinement
26062 -- matches one of its constituents, or itself for an
26063 -- abstract state with partial visible refinement.
26064
26065 elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then
26066 if Is_Entity_Name (Ref_Item) then
26067 Ref_Item_Id := Entity_Of (Ref_Item);
26068
26069 if Ekind (Ref_Item_Id) in
26070 E_Abstract_State | E_Constant | E_Variable
26071 and then Present (Encapsulating_State (Ref_Item_Id))
26072 and then Find_Encapsulating_State
26073 (Dep_States, Ref_Item_Id) = Dep_Item_Id
26074 then
26075 Record_Item (Dep_Item_Id);
26076 Matched := True;
26077
26078 elsif not Has_Visible_Refinement (Dep_Item_Id)
26079 and then Ref_Item_Id = Dep_Item_Id
26080 then
26081 Record_Item (Dep_Item_Id);
26082 Matched := True;
26083 end if;
26084 end if;
26085
26086 -- An abstract state without a visible refinement matches
26087 -- itself.
26088
26089 elsif Is_Entity_Name (Ref_Item)
26090 and then Entity_Of (Ref_Item) = Dep_Item_Id
26091 then
26092 Record_Item (Dep_Item_Id);
26093 Matched := True;
26094 end if;
26095
26096 -- A current instance of a concurrent type, discriminant,
26097 -- formal parameter or an object matches itself.
26098
26099 elsif Is_Entity_Name (Ref_Item)
26100 and then Entity_Of (Ref_Item) = Dep_Item_Id
26101 then
26102 Record_Item (Dep_Item_Id);
26103 Matched := True;
26104 end if;
26105 end if;
26106 end Match_Items;
26107
26108 -----------------
26109 -- Record_Item --
26110 -----------------
26111
26112 procedure Record_Item (Item_Id : Entity_Id) is
26113 begin
26114 if No (Matched_Items) then
26115 Matched_Items := New_Elmt_List;
26116 end if;
26117
26118 Append_Unique_Elmt (Item_Id, Matched_Items);
26119 end Record_Item;
26120
26121 -- Local variables
26122
26123 Clause_Matched : Boolean := False;
26124 Dummy : Boolean := False;
26125 Inputs_Match : Boolean;
26126 Next_Ref_Clause : Node_Id;
26127 Outputs_Match : Boolean;
26128 Ref_Clause : Node_Id;
26129 Ref_Input : Node_Id;
26130 Ref_Output : Node_Id;
26131
26132 -- Start of processing for Check_Dependency_Clause
26133
26134 begin
26135 -- Do not perform this check in an instance because it was already
26136 -- performed successfully in the generic template.
26137
26138 if In_Instance then
26139 return;
26140 end if;
26141
26142 -- Examine all refinement clauses and compare them against the
26143 -- dependence clause.
26144
26145 Ref_Clause := First (Refinements);
26146 while Present (Ref_Clause) loop
26147 Next_Ref_Clause := Next (Ref_Clause);
26148
26149 -- Obtain the attributes of the current refinement clause
26150
26151 Ref_Input := Expression (Ref_Clause);
26152 Ref_Output := First (Choices (Ref_Clause));
26153
26154 -- The current refinement clause matches the dependence clause
26155 -- when both outputs match and both inputs match. See routine
26156 -- Match_Items for all possible conformance scenarios.
26157
26158 -- Depends Dep_Output => Dep_Input
26159 -- ^ ^
26160 -- match ? match ?
26161 -- v v
26162 -- Refined_Depends Ref_Output => Ref_Input
26163
26164 Match_Items
26165 (Dep_Item => Dep_Input,
26166 Ref_Item => Ref_Input,
26167 Matched => Inputs_Match);
26168
26169 Match_Items
26170 (Dep_Item => Dep_Output,
26171 Ref_Item => Ref_Output,
26172 Matched => Outputs_Match);
26173
26174 -- An In_Out state clause may be matched against a refinement with
26175 -- a null input or null output as long as the non-null side of the
26176 -- relation contains a valid constituent of the In_Out_State.
26177
26178 if Is_In_Out_State_Clause then
26179
26180 -- Depends => (State => State)
26181 -- Refined_Depends => (null => Constit) -- OK
26182
26183 if Inputs_Match
26184 and then not Outputs_Match
26185 and then Nkind (Ref_Output) = N_Null
26186 then
26187 Outputs_Match := True;
26188 end if;
26189
26190 -- Depends => (State => State)
26191 -- Refined_Depends => (Constit => null) -- OK
26192
26193 if not Inputs_Match
26194 and then Outputs_Match
26195 and then Nkind (Ref_Input) = N_Null
26196 then
26197 Inputs_Match := True;
26198 end if;
26199 end if;
26200
26201 -- The current refinement clause is legally constructed following
26202 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
26203 -- the pool of candidates. The seach continues because a single
26204 -- dependence clause may have multiple matching refinements.
26205
26206 if Inputs_Match and Outputs_Match then
26207 Clause_Matched := True;
26208 Remove (Ref_Clause);
26209 end if;
26210
26211 Ref_Clause := Next_Ref_Clause;
26212 end loop;
26213
26214 -- Depending on the order or composition of refinement clauses, an
26215 -- In_Out state clause may not be directly refinable.
26216
26217 -- Refined_State => (State => (Constit_1, Constit_2))
26218 -- Depends => ((Output, State) => (Input, State))
26219 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
26220
26221 -- Matching normalized clause (State => State) fails because there is
26222 -- no direct refinement capable of satisfying this relation. Another
26223 -- similar case arises when clauses (Constit_1 => Input) and (Output
26224 -- => Constit_2) are matched first, leaving no candidates for clause
26225 -- (State => State). Both scenarios are legal as long as one of the
26226 -- previous clauses mentioned a valid constituent of State.
26227
26228 if not Clause_Matched
26229 and then Is_In_Out_State_Clause
26230 and then Is_Already_Matched (Dep_Input)
26231 then
26232 Clause_Matched := True;
26233 end if;
26234
26235 -- A clause where the input is an abstract state with visible null
26236 -- refinement or a 'Result attribute is implicitly matched when the
26237 -- output has already been matched in a previous clause.
26238
26239 -- Refined_State => (State => null)
26240 -- Depends => (Output => State) -- implicitly OK
26241 -- Refined_Depends => (Output => ...)
26242 -- Depends => (...'Result => State) -- implicitly OK
26243 -- Refined_Depends => (...'Result => ...)
26244
26245 if not Clause_Matched
26246 and then Is_Null_Refined_State (Dep_Input)
26247 and then Is_Already_Matched (Dep_Output)
26248 then
26249 Clause_Matched := True;
26250 end if;
26251
26252 -- A clause where the output is an abstract state with visible null
26253 -- refinement is implicitly matched when the input has already been
26254 -- matched in a previous clause.
26255
26256 -- Refined_State => (State => null)
26257 -- Depends => (State => Input) -- implicitly OK
26258 -- Refined_Depends => (... => Input)
26259
26260 if not Clause_Matched
26261 and then Is_Null_Refined_State (Dep_Output)
26262 and then Is_Already_Matched (Dep_Input)
26263 then
26264 Clause_Matched := True;
26265 end if;
26266
26267 -- At this point either all refinement clauses have been examined or
26268 -- pragma Refined_Depends contains a solitary null. Only an abstract
26269 -- state with null refinement can possibly match these cases.
26270
26271 -- Refined_State => (State => null)
26272 -- Depends => (State => null)
26273 -- Refined_Depends => null -- OK
26274
26275 if not Clause_Matched then
26276 Match_Items
26277 (Dep_Item => Dep_Input,
26278 Ref_Item => Empty,
26279 Matched => Inputs_Match);
26280
26281 Match_Items
26282 (Dep_Item => Dep_Output,
26283 Ref_Item => Empty,
26284 Matched => Outputs_Match);
26285
26286 Clause_Matched := Inputs_Match and Outputs_Match;
26287 end if;
26288
26289 -- If the contents of Refined_Depends are legal, then the current
26290 -- dependence clause should be satisfied either by an explicit match
26291 -- or by one of the special cases.
26292
26293 if not Clause_Matched then
26294 SPARK_Msg_NE
26295 (Fix_Msg (Spec_Id, "dependence clause of subprogram & has no "
26296 & "matching refinement in body"), Dep_Clause, Spec_Id);
26297 end if;
26298 end Check_Dependency_Clause;
26299
26300 -------------------------
26301 -- Check_Output_States --
26302 -------------------------
26303
26304 procedure Check_Output_States
26305 (Spec_Inputs : Elist_Id;
26306 Spec_Outputs : Elist_Id;
26307 Body_Inputs : Elist_Id;
26308 Body_Outputs : Elist_Id)
26309 is
26310 procedure Check_Constituent_Usage (State_Id : Entity_Id);
26311 -- Determine whether all constituents of state State_Id with full
26312 -- visible refinement are used as outputs in pragma Refined_Depends.
26313 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
26314
26315 -----------------------------
26316 -- Check_Constituent_Usage --
26317 -----------------------------
26318
26319 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
26320 Constits : constant Elist_Id :=
26321 Partial_Refinement_Constituents (State_Id);
26322 Constit_Elmt : Elmt_Id;
26323 Constit_Id : Entity_Id;
26324 Only_Partial : constant Boolean :=
26325 not Has_Visible_Refinement (State_Id);
26326 Posted : Boolean := False;
26327
26328 begin
26329 if Present (Constits) then
26330 Constit_Elmt := First_Elmt (Constits);
26331 while Present (Constit_Elmt) loop
26332 Constit_Id := Node (Constit_Elmt);
26333
26334 -- Issue an error when a constituent of State_Id is used,
26335 -- and State_Id has only partial visible refinement
26336 -- (SPARK RM 7.2.4(3d)).
26337
26338 if Only_Partial then
26339 if (Present (Body_Inputs)
26340 and then Appears_In (Body_Inputs, Constit_Id))
26341 or else
26342 (Present (Body_Outputs)
26343 and then Appears_In (Body_Outputs, Constit_Id))
26344 then
26345 Error_Msg_Name_1 := Chars (State_Id);
26346 SPARK_Msg_NE
26347 ("constituent & of state % cannot be used in "
26348 & "dependence refinement", N, Constit_Id);
26349 Error_Msg_Name_1 := Chars (State_Id);
26350 SPARK_Msg_N ("\use state % instead", N);
26351 end if;
26352
26353 -- The constituent acts as an input (SPARK RM 7.2.5(3))
26354
26355 elsif Present (Body_Inputs)
26356 and then Appears_In (Body_Inputs, Constit_Id)
26357 then
26358 Error_Msg_Name_1 := Chars (State_Id);
26359 SPARK_Msg_NE
26360 ("constituent & of state % must act as output in "
26361 & "dependence refinement", N, Constit_Id);
26362
26363 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
26364
26365 elsif No (Body_Outputs)
26366 or else not Appears_In (Body_Outputs, Constit_Id)
26367 then
26368 if not Posted then
26369 Posted := True;
26370 SPARK_Msg_NE
26371 ("output state & must be replaced by all its "
26372 & "constituents in dependence refinement",
26373 N, State_Id);
26374 end if;
26375
26376 SPARK_Msg_NE
26377 ("\constituent & is missing in output list",
26378 N, Constit_Id);
26379 end if;
26380
26381 Next_Elmt (Constit_Elmt);
26382 end loop;
26383 end if;
26384 end Check_Constituent_Usage;
26385
26386 -- Local variables
26387
26388 Item : Node_Id;
26389 Item_Elmt : Elmt_Id;
26390 Item_Id : Entity_Id;
26391
26392 -- Start of processing for Check_Output_States
26393
26394 begin
26395 -- Do not perform this check in an instance because it was already
26396 -- performed successfully in the generic template.
26397
26398 if In_Instance then
26399 null;
26400
26401 -- Inspect the outputs of pragma Depends looking for a state with a
26402 -- visible refinement.
26403
26404 elsif Present (Spec_Outputs) then
26405 Item_Elmt := First_Elmt (Spec_Outputs);
26406 while Present (Item_Elmt) loop
26407 Item := Node (Item_Elmt);
26408
26409 -- Deal with the mixed nature of the input and output lists
26410
26411 if Nkind (Item) = N_Defining_Identifier then
26412 Item_Id := Item;
26413 else
26414 Item_Id := Available_View (Entity_Of (Item));
26415 end if;
26416
26417 if Ekind (Item_Id) = E_Abstract_State then
26418
26419 -- The state acts as an input-output, skip it
26420
26421 if Present (Spec_Inputs)
26422 and then Appears_In (Spec_Inputs, Item_Id)
26423 then
26424 null;
26425
26426 -- Ensure that all of the constituents are utilized as
26427 -- outputs in pragma Refined_Depends.
26428
26429 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
26430 Check_Constituent_Usage (Item_Id);
26431 end if;
26432 end if;
26433
26434 Next_Elmt (Item_Elmt);
26435 end loop;
26436 end if;
26437 end Check_Output_States;
26438
26439 --------------------
26440 -- Collect_States --
26441 --------------------
26442
26443 function Collect_States (Clauses : List_Id) return Elist_Id is
26444 procedure Collect_State
26445 (Item : Node_Id;
26446 States : in out Elist_Id);
26447 -- Add the entity of Item to list States when it denotes to a state
26448
26449 -------------------
26450 -- Collect_State --
26451 -------------------
26452
26453 procedure Collect_State
26454 (Item : Node_Id;
26455 States : in out Elist_Id)
26456 is
26457 Id : Entity_Id;
26458
26459 begin
26460 if Is_Entity_Name (Item) then
26461 Id := Entity_Of (Item);
26462
26463 if Ekind (Id) = E_Abstract_State then
26464 if No (States) then
26465 States := New_Elmt_List;
26466 end if;
26467
26468 Append_Unique_Elmt (Id, States);
26469 end if;
26470 end if;
26471 end Collect_State;
26472
26473 -- Local variables
26474
26475 Clause : Node_Id;
26476 Input : Node_Id;
26477 Output : Node_Id;
26478 States : Elist_Id := No_Elist;
26479
26480 -- Start of processing for Collect_States
26481
26482 begin
26483 Clause := First (Clauses);
26484 while Present (Clause) loop
26485 Input := Expression (Clause);
26486 Output := First (Choices (Clause));
26487
26488 Collect_State (Input, States);
26489 Collect_State (Output, States);
26490
26491 Next (Clause);
26492 end loop;
26493
26494 return States;
26495 end Collect_States;
26496
26497 -----------------------
26498 -- Normalize_Clauses --
26499 -----------------------
26500
26501 procedure Normalize_Clauses (Clauses : List_Id) is
26502 procedure Normalize_Inputs (Clause : Node_Id);
26503 -- Normalize clause Clause by creating multiple clauses for each
26504 -- input item of Clause. It is assumed that Clause has exactly one
26505 -- output. The transformation is as follows:
26506 --
26507 -- Output => (Input_1, Input_2) -- original
26508 --
26509 -- Output => Input_1 -- normalizations
26510 -- Output => Input_2
26511
26512 procedure Normalize_Outputs (Clause : Node_Id);
26513 -- Normalize clause Clause by creating multiple clause for each
26514 -- output item of Clause. The transformation is as follows:
26515 --
26516 -- (Output_1, Output_2) => Input -- original
26517 --
26518 -- Output_1 => Input -- normalization
26519 -- Output_2 => Input
26520
26521 ----------------------
26522 -- Normalize_Inputs --
26523 ----------------------
26524
26525 procedure Normalize_Inputs (Clause : Node_Id) is
26526 Inputs : constant Node_Id := Expression (Clause);
26527 Loc : constant Source_Ptr := Sloc (Clause);
26528 Output : constant List_Id := Choices (Clause);
26529 Last_Input : Node_Id;
26530 Input : Node_Id;
26531 New_Clause : Node_Id;
26532 Next_Input : Node_Id;
26533
26534 begin
26535 -- Normalization is performed only when the original clause has
26536 -- more than one input. Multiple inputs appear as an aggregate.
26537
26538 if Nkind (Inputs) = N_Aggregate then
26539 Last_Input := Last (Expressions (Inputs));
26540
26541 -- Create a new clause for each input
26542
26543 Input := First (Expressions (Inputs));
26544 while Present (Input) loop
26545 Next_Input := Next (Input);
26546
26547 -- Unhook the current input from the original input list
26548 -- because it will be relocated to a new clause.
26549
26550 Remove (Input);
26551
26552 -- Special processing for the last input. At this point the
26553 -- original aggregate has been stripped down to one element.
26554 -- Replace the aggregate by the element itself.
26555
26556 if Input = Last_Input then
26557 Rewrite (Inputs, Input);
26558
26559 -- Generate a clause of the form:
26560 -- Output => Input
26561
26562 else
26563 New_Clause :=
26564 Make_Component_Association (Loc,
26565 Choices => New_Copy_List_Tree (Output),
26566 Expression => Input);
26567
26568 -- The new clause contains replicated content that has
26569 -- already been analyzed, mark the clause as analyzed.
26570
26571 Set_Analyzed (New_Clause);
26572 Insert_After (Clause, New_Clause);
26573 end if;
26574
26575 Input := Next_Input;
26576 end loop;
26577 end if;
26578 end Normalize_Inputs;
26579
26580 -----------------------
26581 -- Normalize_Outputs --
26582 -----------------------
26583
26584 procedure Normalize_Outputs (Clause : Node_Id) is
26585 Inputs : constant Node_Id := Expression (Clause);
26586 Loc : constant Source_Ptr := Sloc (Clause);
26587 Outputs : constant Node_Id := First (Choices (Clause));
26588 Last_Output : Node_Id;
26589 New_Clause : Node_Id;
26590 Next_Output : Node_Id;
26591 Output : Node_Id;
26592
26593 begin
26594 -- Multiple outputs appear as an aggregate. Nothing to do when
26595 -- the clause has exactly one output.
26596
26597 if Nkind (Outputs) = N_Aggregate then
26598 Last_Output := Last (Expressions (Outputs));
26599
26600 -- Create a clause for each output. Note that each time a new
26601 -- clause is created, the original output list slowly shrinks
26602 -- until there is one item left.
26603
26604 Output := First (Expressions (Outputs));
26605 while Present (Output) loop
26606 Next_Output := Next (Output);
26607
26608 -- Unhook the output from the original output list as it
26609 -- will be relocated to a new clause.
26610
26611 Remove (Output);
26612
26613 -- Special processing for the last output. At this point
26614 -- the original aggregate has been stripped down to one
26615 -- element. Replace the aggregate by the element itself.
26616
26617 if Output = Last_Output then
26618 Rewrite (Outputs, Output);
26619
26620 else
26621 -- Generate a clause of the form:
26622 -- (Output => Inputs)
26623
26624 New_Clause :=
26625 Make_Component_Association (Loc,
26626 Choices => New_List (Output),
26627 Expression => New_Copy_Tree (Inputs));
26628
26629 -- The new clause contains replicated content that has
26630 -- already been analyzed. There is not need to reanalyze
26631 -- them.
26632
26633 Set_Analyzed (New_Clause);
26634 Insert_After (Clause, New_Clause);
26635 end if;
26636
26637 Output := Next_Output;
26638 end loop;
26639 end if;
26640 end Normalize_Outputs;
26641
26642 -- Local variables
26643
26644 Clause : Node_Id;
26645
26646 -- Start of processing for Normalize_Clauses
26647
26648 begin
26649 Clause := First (Clauses);
26650 while Present (Clause) loop
26651 Normalize_Outputs (Clause);
26652 Next (Clause);
26653 end loop;
26654
26655 Clause := First (Clauses);
26656 while Present (Clause) loop
26657 Normalize_Inputs (Clause);
26658 Next (Clause);
26659 end loop;
26660 end Normalize_Clauses;
26661
26662 --------------------------
26663 -- Remove_Extra_Clauses --
26664 --------------------------
26665
26666 procedure Remove_Extra_Clauses
26667 (Clauses : List_Id;
26668 Matched_Items : Elist_Id)
26669 is
26670 Clause : Node_Id;
26671 Input : Node_Id;
26672 Input_Id : Entity_Id;
26673 Next_Clause : Node_Id;
26674 Output : Node_Id;
26675 State_Id : Entity_Id;
26676
26677 begin
26678 Clause := First (Clauses);
26679 while Present (Clause) loop
26680 Next_Clause := Next (Clause);
26681
26682 Input := Expression (Clause);
26683 Output := First (Choices (Clause));
26684
26685 -- Recognize a clause of the form
26686
26687 -- null => Input
26688
26689 -- where Input is a constituent of a state which was already
26690 -- successfully matched. This clause must be removed because it
26691 -- simply indicates that some of the constituents of the state
26692 -- are not used.
26693
26694 -- Refined_State => (State => (Constit_1, Constit_2))
26695 -- Depends => (Output => State)
26696 -- Refined_Depends => ((Output => Constit_1), -- State matched
26697 -- (null => Constit_2)) -- OK
26698
26699 if Nkind (Output) = N_Null and then Is_Entity_Name (Input) then
26700
26701 -- Handle abstract views generated for limited with clauses
26702
26703 Input_Id := Available_View (Entity_Of (Input));
26704
26705 -- The input must be a constituent of a state
26706
26707 if Ekind (Input_Id) in
26708 E_Abstract_State | E_Constant | E_Variable
26709 and then Present (Encapsulating_State (Input_Id))
26710 then
26711 State_Id := Encapsulating_State (Input_Id);
26712
26713 -- The state must have a non-null visible refinement and be
26714 -- matched in a previous clause.
26715
26716 if Has_Non_Null_Visible_Refinement (State_Id)
26717 and then Contains (Matched_Items, State_Id)
26718 then
26719 Remove (Clause);
26720 end if;
26721 end if;
26722
26723 -- Recognize a clause of the form
26724
26725 -- Output => null
26726
26727 -- where Output is an arbitrary item. This clause must be removed
26728 -- because a null input legitimately matches anything.
26729
26730 elsif Nkind (Input) = N_Null then
26731 Remove (Clause);
26732 end if;
26733
26734 Clause := Next_Clause;
26735 end loop;
26736 end Remove_Extra_Clauses;
26737
26738 --------------------------
26739 -- Report_Extra_Clauses --
26740 --------------------------
26741
26742 procedure Report_Extra_Clauses (Clauses : List_Id) is
26743 Clause : Node_Id;
26744
26745 begin
26746 -- Do not perform this check in an instance because it was already
26747 -- performed successfully in the generic template.
26748
26749 if In_Instance then
26750 null;
26751
26752 elsif Present (Clauses) then
26753 Clause := First (Clauses);
26754 while Present (Clause) loop
26755 SPARK_Msg_N
26756 ("unmatched or extra clause in dependence refinement",
26757 Clause);
26758
26759 Next (Clause);
26760 end loop;
26761 end if;
26762 end Report_Extra_Clauses;
26763
26764 -- Local variables
26765
26766 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
26767 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
26768 Errors : constant Nat := Serious_Errors_Detected;
26769
26770 Clause : Node_Id;
26771 Deps : Node_Id;
26772 Dummy : Boolean;
26773 Refs : Node_Id;
26774
26775 Body_Inputs : Elist_Id := No_Elist;
26776 Body_Outputs : Elist_Id := No_Elist;
26777 -- The inputs and outputs of the subprogram body synthesized from pragma
26778 -- Refined_Depends.
26779
26780 Dependencies : List_Id := No_List;
26781 Depends : Node_Id;
26782 -- The corresponding Depends pragma along with its clauses
26783
26784 Matched_Items : Elist_Id := No_Elist;
26785 -- A list containing the entities of all successfully matched items
26786 -- found in pragma Depends.
26787
26788 Refinements : List_Id := No_List;
26789 -- The clauses of pragma Refined_Depends
26790
26791 Spec_Id : Entity_Id;
26792 -- The entity of the subprogram subject to pragma Refined_Depends
26793
26794 Spec_Inputs : Elist_Id := No_Elist;
26795 Spec_Outputs : Elist_Id := No_Elist;
26796 -- The inputs and outputs of the subprogram spec synthesized from pragma
26797 -- Depends.
26798
26799 States : Elist_Id := No_Elist;
26800 -- A list containing the entities of all states whose constituents
26801 -- appear in pragma Depends.
26802
26803 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
26804
26805 begin
26806 -- Do not analyze the pragma multiple times
26807
26808 if Is_Analyzed_Pragma (N) then
26809 return;
26810 end if;
26811
26812 Spec_Id := Unique_Defining_Entity (Body_Decl);
26813
26814 -- Use the anonymous object as the proper spec when Refined_Depends
26815 -- applies to the body of a single task type. The object carries the
26816 -- proper Chars as well as all non-refined versions of pragmas.
26817
26818 if Is_Single_Concurrent_Type (Spec_Id) then
26819 Spec_Id := Anonymous_Object (Spec_Id);
26820 end if;
26821
26822 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
26823
26824 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
26825 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
26826
26827 if No (Depends) then
26828 SPARK_Msg_NE
26829 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
26830 & "& lacks aspect or pragma Depends"), N, Spec_Id);
26831 goto Leave;
26832 end if;
26833
26834 Deps := Expression (Get_Argument (Depends, Spec_Id));
26835
26836 -- A null dependency relation renders the refinement useless because it
26837 -- cannot possibly mention abstract states with visible refinement. Note
26838 -- that the inverse is not true as states may be refined to null
26839 -- (SPARK RM 7.2.5(2)).
26840
26841 if Nkind (Deps) = N_Null then
26842 SPARK_Msg_NE
26843 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
26844 & "depend on abstract state with visible refinement"), N, Spec_Id);
26845 goto Leave;
26846 end if;
26847
26848 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
26849 -- This ensures that the categorization of all refined dependency items
26850 -- is consistent with their role.
26851
26852 Analyze_Depends_In_Decl_Part (N);
26853
26854 -- Do not match dependencies against refinements if Refined_Depends is
26855 -- illegal to avoid emitting misleading error.
26856
26857 if Serious_Errors_Detected = Errors then
26858
26859 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
26860 -- the inputs and outputs of the subprogram spec and body to verify
26861 -- the use of states with visible refinement and their constituents.
26862
26863 if No (Get_Pragma (Spec_Id, Pragma_Global))
26864 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
26865 then
26866 Collect_Subprogram_Inputs_Outputs
26867 (Subp_Id => Spec_Id,
26868 Synthesize => True,
26869 Subp_Inputs => Spec_Inputs,
26870 Subp_Outputs => Spec_Outputs,
26871 Global_Seen => Dummy);
26872
26873 Collect_Subprogram_Inputs_Outputs
26874 (Subp_Id => Body_Id,
26875 Synthesize => True,
26876 Subp_Inputs => Body_Inputs,
26877 Subp_Outputs => Body_Outputs,
26878 Global_Seen => Dummy);
26879
26880 -- For an output state with a visible refinement, ensure that all
26881 -- constituents appear as outputs in the dependency refinement.
26882
26883 Check_Output_States
26884 (Spec_Inputs => Spec_Inputs,
26885 Spec_Outputs => Spec_Outputs,
26886 Body_Inputs => Body_Inputs,
26887 Body_Outputs => Body_Outputs);
26888 end if;
26889
26890 -- Multiple dependency clauses appear as component associations of an
26891 -- aggregate. Note that the clauses are copied because the algorithm
26892 -- modifies them and this should not be visible in Depends.
26893
26894 pragma Assert (Nkind (Deps) = N_Aggregate);
26895 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
26896 Normalize_Clauses (Dependencies);
26897
26898 -- Gather all states which appear in Depends
26899
26900 States := Collect_States (Dependencies);
26901
26902 Refs := Expression (Get_Argument (N, Spec_Id));
26903
26904 if Nkind (Refs) = N_Null then
26905 Refinements := No_List;
26906
26907 -- Multiple dependency clauses appear as component associations of an
26908 -- aggregate. Note that the clauses are copied because the algorithm
26909 -- modifies them and this should not be visible in Refined_Depends.
26910
26911 else pragma Assert (Nkind (Refs) = N_Aggregate);
26912 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
26913 Normalize_Clauses (Refinements);
26914 end if;
26915
26916 -- At this point the clauses of pragmas Depends and Refined_Depends
26917 -- have been normalized into simple dependencies between one output
26918 -- and one input. Examine all clauses of pragma Depends looking for
26919 -- matching clauses in pragma Refined_Depends.
26920
26921 Clause := First (Dependencies);
26922 while Present (Clause) loop
26923 Check_Dependency_Clause
26924 (Spec_Id => Spec_Id,
26925 Dep_Clause => Clause,
26926 Dep_States => States,
26927 Refinements => Refinements,
26928 Matched_Items => Matched_Items);
26929
26930 Next (Clause);
26931 end loop;
26932
26933 -- Pragma Refined_Depends may contain multiple clarification clauses
26934 -- which indicate that certain constituents do not influence the data
26935 -- flow in any way. Such clauses must be removed as long as the state
26936 -- has been matched, otherwise they will be incorrectly flagged as
26937 -- unmatched.
26938
26939 -- Refined_State => (State => (Constit_1, Constit_2))
26940 -- Depends => (Output => State)
26941 -- Refined_Depends => ((Output => Constit_1), -- State matched
26942 -- (null => Constit_2)) -- must be removed
26943
26944 Remove_Extra_Clauses (Refinements, Matched_Items);
26945
26946 if Serious_Errors_Detected = Errors then
26947 Report_Extra_Clauses (Refinements);
26948 end if;
26949 end if;
26950
26951 <<Leave>>
26952 Set_Is_Analyzed_Pragma (N);
26953 end Analyze_Refined_Depends_In_Decl_Part;
26954
26955 -----------------------------------------
26956 -- Analyze_Refined_Global_In_Decl_Part --
26957 -----------------------------------------
26958
26959 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
26960 Global : Node_Id;
26961 -- The corresponding Global pragma
26962
26963 Has_In_State : Boolean := False;
26964 Has_In_Out_State : Boolean := False;
26965 Has_Out_State : Boolean := False;
26966 Has_Proof_In_State : Boolean := False;
26967 -- These flags are set when the corresponding Global pragma has a state
26968 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
26969 -- refinement.
26970
26971 Has_Null_State : Boolean := False;
26972 -- This flag is set when the corresponding Global pragma has at least
26973 -- one state with a null refinement.
26974
26975 In_Constits : Elist_Id := No_Elist;
26976 In_Out_Constits : Elist_Id := No_Elist;
26977 Out_Constits : Elist_Id := No_Elist;
26978 Proof_In_Constits : Elist_Id := No_Elist;
26979 -- These lists contain the entities of all Input, In_Out, Output and
26980 -- Proof_In constituents that appear in Refined_Global and participate
26981 -- in state refinement.
26982
26983 In_Items : Elist_Id := No_Elist;
26984 In_Out_Items : Elist_Id := No_Elist;
26985 Out_Items : Elist_Id := No_Elist;
26986 Proof_In_Items : Elist_Id := No_Elist;
26987 -- These lists contain the entities of all Input, In_Out, Output and
26988 -- Proof_In items defined in the corresponding Global pragma.
26989
26990 Repeat_Items : Elist_Id := No_Elist;
26991 -- A list of all global items without full visible refinement found
26992 -- in pragma Global. These states should be repeated in the global
26993 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
26994 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
26995
26996 Spec_Id : Entity_Id;
26997 -- The entity of the subprogram subject to pragma Refined_Global
26998
26999 States : Elist_Id := No_Elist;
27000 -- A list of all states with full or partial visible refinement found in
27001 -- pragma Global.
27002
27003 procedure Check_In_Out_States;
27004 -- Determine whether the corresponding Global pragma mentions In_Out
27005 -- states with visible refinement and if so, ensure that one of the
27006 -- following completions apply to the constituents of the state:
27007 -- 1) there is at least one constituent of mode In_Out
27008 -- 2) there is at least one Input and one Output constituent
27009 -- 3) not all constituents are present and one of them is of mode
27010 -- Output.
27011 -- This routine may remove elements from In_Constits, In_Out_Constits,
27012 -- Out_Constits and Proof_In_Constits.
27013
27014 procedure Check_Input_States;
27015 -- Determine whether the corresponding Global pragma mentions Input
27016 -- states with visible refinement and if so, ensure that at least one of
27017 -- its constituents appears as an Input item in Refined_Global.
27018 -- This routine may remove elements from In_Constits, In_Out_Constits,
27019 -- Out_Constits and Proof_In_Constits.
27020
27021 procedure Check_Output_States;
27022 -- Determine whether the corresponding Global pragma mentions Output
27023 -- states with visible refinement and if so, ensure that all of its
27024 -- constituents appear as Output items in Refined_Global.
27025 -- This routine may remove elements from In_Constits, In_Out_Constits,
27026 -- Out_Constits and Proof_In_Constits.
27027
27028 procedure Check_Proof_In_States;
27029 -- Determine whether the corresponding Global pragma mentions Proof_In
27030 -- states with visible refinement and if so, ensure that at least one of
27031 -- its constituents appears as a Proof_In item in Refined_Global.
27032 -- This routine may remove elements from In_Constits, In_Out_Constits,
27033 -- Out_Constits and Proof_In_Constits.
27034
27035 procedure Check_Refined_Global_List
27036 (List : Node_Id;
27037 Global_Mode : Name_Id := Name_Input);
27038 -- Verify the legality of a single global list declaration. Global_Mode
27039 -- denotes the current mode in effect.
27040
27041 procedure Collect_Global_Items
27042 (List : Node_Id;
27043 Mode : Name_Id := Name_Input);
27044 -- Gather all Input, In_Out, Output and Proof_In items from node List
27045 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
27046 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
27047 -- and Has_Proof_In_State are set when there is at least one abstract
27048 -- state with full or partial visible refinement available in the
27049 -- corresponding mode. Flag Has_Null_State is set when at least state
27050 -- has a null refinement. Mode denotes the current global mode in
27051 -- effect.
27052
27053 function Present_Then_Remove
27054 (List : Elist_Id;
27055 Item : Entity_Id) return Boolean;
27056 -- Search List for a particular entity Item. If Item has been found,
27057 -- remove it from List. This routine is used to strip lists In_Constits,
27058 -- In_Out_Constits and Out_Constits of valid constituents.
27059
27060 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id);
27061 -- Same as function Present_Then_Remove, but do not report the presence
27062 -- of Item in List.
27063
27064 procedure Report_Extra_Constituents;
27065 -- Emit an error for each constituent found in lists In_Constits,
27066 -- In_Out_Constits and Out_Constits.
27067
27068 procedure Report_Missing_Items;
27069 -- Emit an error for each global item not repeated found in list
27070 -- Repeat_Items.
27071
27072 -------------------------
27073 -- Check_In_Out_States --
27074 -------------------------
27075
27076 procedure Check_In_Out_States is
27077 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27078 -- Determine whether one of the following coverage scenarios is in
27079 -- effect:
27080 -- 1) there is at least one constituent of mode In_Out or Output
27081 -- 2) there is at least one pair of constituents with modes Input
27082 -- and Output, or Proof_In and Output.
27083 -- 3) there is at least one constituent of mode Output and not all
27084 -- constituents are present.
27085 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
27086
27087 -----------------------------
27088 -- Check_Constituent_Usage --
27089 -----------------------------
27090
27091 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27092 Constits : constant Elist_Id :=
27093 Partial_Refinement_Constituents (State_Id);
27094 Constit_Elmt : Elmt_Id;
27095 Constit_Id : Entity_Id;
27096 Has_Missing : Boolean := False;
27097 In_Out_Seen : Boolean := False;
27098 Input_Seen : Boolean := False;
27099 Output_Seen : Boolean := False;
27100 Proof_In_Seen : Boolean := False;
27101
27102 begin
27103 -- Process all the constituents of the state and note their modes
27104 -- within the global refinement.
27105
27106 if Present (Constits) then
27107 Constit_Elmt := First_Elmt (Constits);
27108 while Present (Constit_Elmt) loop
27109 Constit_Id := Node (Constit_Elmt);
27110
27111 if Present_Then_Remove (In_Constits, Constit_Id) then
27112 Input_Seen := True;
27113
27114 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
27115 In_Out_Seen := True;
27116
27117 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
27118 Output_Seen := True;
27119
27120 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
27121 then
27122 Proof_In_Seen := True;
27123
27124 else
27125 Has_Missing := True;
27126 end if;
27127
27128 Next_Elmt (Constit_Elmt);
27129 end loop;
27130 end if;
27131
27132 -- An In_Out constituent is a valid completion
27133
27134 if In_Out_Seen then
27135 null;
27136
27137 -- A pair of one Input/Proof_In and one Output constituent is a
27138 -- valid completion.
27139
27140 elsif (Input_Seen or Proof_In_Seen) and Output_Seen then
27141 null;
27142
27143 elsif Output_Seen then
27144
27145 -- A single Output constituent is a valid completion only when
27146 -- some of the other constituents are missing.
27147
27148 if Has_Missing then
27149 null;
27150
27151 -- Otherwise all constituents are of mode Output
27152
27153 else
27154 SPARK_Msg_NE
27155 ("global refinement of state & must include at least one "
27156 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
27157 N, State_Id);
27158 end if;
27159
27160 -- The state lacks a completion. When full refinement is visible,
27161 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
27162 -- refinement is visible, emit an error if the abstract state
27163 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
27164 -- both are utilized, Check_State_And_Constituent_Use. will issue
27165 -- the error.
27166
27167 elsif not Input_Seen
27168 and then not In_Out_Seen
27169 and then not Output_Seen
27170 and then not Proof_In_Seen
27171 then
27172 if Has_Visible_Refinement (State_Id)
27173 or else Contains (Repeat_Items, State_Id)
27174 then
27175 SPARK_Msg_NE
27176 ("missing global refinement of state &", N, State_Id);
27177 end if;
27178
27179 -- Otherwise the state has a malformed completion where at least
27180 -- one of the constituents has a different mode.
27181
27182 else
27183 SPARK_Msg_NE
27184 ("global refinement of state & redefines the mode of its "
27185 & "constituents", N, State_Id);
27186 end if;
27187 end Check_Constituent_Usage;
27188
27189 -- Local variables
27190
27191 Item_Elmt : Elmt_Id;
27192 Item_Id : Entity_Id;
27193
27194 -- Start of processing for Check_In_Out_States
27195
27196 begin
27197 -- Do not perform this check in an instance because it was already
27198 -- performed successfully in the generic template.
27199
27200 if In_Instance then
27201 null;
27202
27203 -- Inspect the In_Out items of the corresponding Global pragma
27204 -- looking for a state with a visible refinement.
27205
27206 elsif Has_In_Out_State and then Present (In_Out_Items) then
27207 Item_Elmt := First_Elmt (In_Out_Items);
27208 while Present (Item_Elmt) loop
27209 Item_Id := Node (Item_Elmt);
27210
27211 -- Ensure that one of the three coverage variants is satisfied
27212
27213 if Ekind (Item_Id) = E_Abstract_State
27214 and then Has_Non_Null_Visible_Refinement (Item_Id)
27215 then
27216 Check_Constituent_Usage (Item_Id);
27217 end if;
27218
27219 Next_Elmt (Item_Elmt);
27220 end loop;
27221 end if;
27222 end Check_In_Out_States;
27223
27224 ------------------------
27225 -- Check_Input_States --
27226 ------------------------
27227
27228 procedure Check_Input_States is
27229 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27230 -- Determine whether at least one constituent of state State_Id with
27231 -- full or partial visible refinement is used and has mode Input.
27232 -- Ensure that the remaining constituents do not have In_Out or
27233 -- Output modes. Emit an error if this is not the case
27234 -- (SPARK RM 7.2.4(5)).
27235
27236 -----------------------------
27237 -- Check_Constituent_Usage --
27238 -----------------------------
27239
27240 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27241 Constits : constant Elist_Id :=
27242 Partial_Refinement_Constituents (State_Id);
27243 Constit_Elmt : Elmt_Id;
27244 Constit_Id : Entity_Id;
27245 In_Seen : Boolean := False;
27246
27247 begin
27248 if Present (Constits) then
27249 Constit_Elmt := First_Elmt (Constits);
27250 while Present (Constit_Elmt) loop
27251 Constit_Id := Node (Constit_Elmt);
27252
27253 -- At least one of the constituents appears as an Input
27254
27255 if Present_Then_Remove (In_Constits, Constit_Id) then
27256 In_Seen := True;
27257
27258 -- A Proof_In constituent can refine an Input state as long
27259 -- as there is at least one Input constituent present.
27260
27261 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
27262 then
27263 null;
27264
27265 -- The constituent appears in the global refinement, but has
27266 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
27267
27268 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
27269 or else Present_Then_Remove (Out_Constits, Constit_Id)
27270 then
27271 Error_Msg_Name_1 := Chars (State_Id);
27272 SPARK_Msg_NE
27273 ("constituent & of state % must have mode `Input` in "
27274 & "global refinement", N, Constit_Id);
27275 end if;
27276
27277 Next_Elmt (Constit_Elmt);
27278 end loop;
27279 end if;
27280
27281 -- Not one of the constituents appeared as Input. Always emit an
27282 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
27283 -- When only partial refinement is visible, emit an error if the
27284 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27285 -- the case where both are utilized, an error will be issued in
27286 -- Check_State_And_Constituent_Use.
27287
27288 if not In_Seen
27289 and then (Has_Visible_Refinement (State_Id)
27290 or else Contains (Repeat_Items, State_Id))
27291 then
27292 SPARK_Msg_NE
27293 ("global refinement of state & must include at least one "
27294 & "constituent of mode `Input`", N, State_Id);
27295 end if;
27296 end Check_Constituent_Usage;
27297
27298 -- Local variables
27299
27300 Item_Elmt : Elmt_Id;
27301 Item_Id : Entity_Id;
27302
27303 -- Start of processing for Check_Input_States
27304
27305 begin
27306 -- Do not perform this check in an instance because it was already
27307 -- performed successfully in the generic template.
27308
27309 if In_Instance then
27310 null;
27311
27312 -- Inspect the Input items of the corresponding Global pragma looking
27313 -- for a state with a visible refinement.
27314
27315 elsif Has_In_State and then Present (In_Items) then
27316 Item_Elmt := First_Elmt (In_Items);
27317 while Present (Item_Elmt) loop
27318 Item_Id := Node (Item_Elmt);
27319
27320 -- When full refinement is visible, ensure that at least one of
27321 -- the constituents is utilized and is of mode Input. When only
27322 -- partial refinement is visible, ensure that either one of
27323 -- the constituents is utilized and is of mode Input, or the
27324 -- abstract state is repeated and no constituent is utilized.
27325
27326 if Ekind (Item_Id) = E_Abstract_State
27327 and then Has_Non_Null_Visible_Refinement (Item_Id)
27328 then
27329 Check_Constituent_Usage (Item_Id);
27330 end if;
27331
27332 Next_Elmt (Item_Elmt);
27333 end loop;
27334 end if;
27335 end Check_Input_States;
27336
27337 -------------------------
27338 -- Check_Output_States --
27339 -------------------------
27340
27341 procedure Check_Output_States is
27342 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27343 -- Determine whether all constituents of state State_Id with full
27344 -- visible refinement are used and have mode Output. Emit an error
27345 -- if this is not the case (SPARK RM 7.2.4(5)).
27346
27347 -----------------------------
27348 -- Check_Constituent_Usage --
27349 -----------------------------
27350
27351 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27352 Constits : constant Elist_Id :=
27353 Partial_Refinement_Constituents (State_Id);
27354 Only_Partial : constant Boolean :=
27355 not Has_Visible_Refinement (State_Id);
27356 Constit_Elmt : Elmt_Id;
27357 Constit_Id : Entity_Id;
27358 Posted : Boolean := False;
27359
27360 begin
27361 if Present (Constits) then
27362 Constit_Elmt := First_Elmt (Constits);
27363 while Present (Constit_Elmt) loop
27364 Constit_Id := Node (Constit_Elmt);
27365
27366 -- Issue an error when a constituent of State_Id is utilized
27367 -- and State_Id has only partial visible refinement
27368 -- (SPARK RM 7.2.4(3d)).
27369
27370 if Only_Partial then
27371 if Present_Then_Remove (Out_Constits, Constit_Id)
27372 or else Present_Then_Remove (In_Constits, Constit_Id)
27373 or else
27374 Present_Then_Remove (In_Out_Constits, Constit_Id)
27375 or else
27376 Present_Then_Remove (Proof_In_Constits, Constit_Id)
27377 then
27378 Error_Msg_Name_1 := Chars (State_Id);
27379 SPARK_Msg_NE
27380 ("constituent & of state % cannot be used in global "
27381 & "refinement", N, Constit_Id);
27382 Error_Msg_Name_1 := Chars (State_Id);
27383 SPARK_Msg_N ("\use state % instead", N);
27384 end if;
27385
27386 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
27387 null;
27388
27389 -- The constituent appears in the global refinement, but has
27390 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
27391
27392 elsif Present_Then_Remove (In_Constits, Constit_Id)
27393 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27394 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
27395 then
27396 Error_Msg_Name_1 := Chars (State_Id);
27397 SPARK_Msg_NE
27398 ("constituent & of state % must have mode `Output` in "
27399 & "global refinement", N, Constit_Id);
27400
27401 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
27402
27403 else
27404 if not Posted then
27405 Posted := True;
27406 SPARK_Msg_NE
27407 ("`Output` state & must be replaced by all its "
27408 & "constituents in global refinement", N, State_Id);
27409 end if;
27410
27411 SPARK_Msg_NE
27412 ("\constituent & is missing in output list",
27413 N, Constit_Id);
27414 end if;
27415
27416 Next_Elmt (Constit_Elmt);
27417 end loop;
27418 end if;
27419 end Check_Constituent_Usage;
27420
27421 -- Local variables
27422
27423 Item_Elmt : Elmt_Id;
27424 Item_Id : Entity_Id;
27425
27426 -- Start of processing for Check_Output_States
27427
27428 begin
27429 -- Do not perform this check in an instance because it was already
27430 -- performed successfully in the generic template.
27431
27432 if In_Instance then
27433 null;
27434
27435 -- Inspect the Output items of the corresponding Global pragma
27436 -- looking for a state with a visible refinement.
27437
27438 elsif Has_Out_State and then Present (Out_Items) then
27439 Item_Elmt := First_Elmt (Out_Items);
27440 while Present (Item_Elmt) loop
27441 Item_Id := Node (Item_Elmt);
27442
27443 -- When full refinement is visible, ensure that all of the
27444 -- constituents are utilized and they have mode Output. When
27445 -- only partial refinement is visible, ensure that no
27446 -- constituent is utilized.
27447
27448 if Ekind (Item_Id) = E_Abstract_State
27449 and then Has_Non_Null_Visible_Refinement (Item_Id)
27450 then
27451 Check_Constituent_Usage (Item_Id);
27452 end if;
27453
27454 Next_Elmt (Item_Elmt);
27455 end loop;
27456 end if;
27457 end Check_Output_States;
27458
27459 ---------------------------
27460 -- Check_Proof_In_States --
27461 ---------------------------
27462
27463 procedure Check_Proof_In_States is
27464 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27465 -- Determine whether at least one constituent of state State_Id with
27466 -- full or partial visible refinement is used and has mode Proof_In.
27467 -- Ensure that the remaining constituents do not have Input, In_Out,
27468 -- or Output modes. Emit an error if this is not the case
27469 -- (SPARK RM 7.2.4(5)).
27470
27471 -----------------------------
27472 -- Check_Constituent_Usage --
27473 -----------------------------
27474
27475 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27476 Constits : constant Elist_Id :=
27477 Partial_Refinement_Constituents (State_Id);
27478 Constit_Elmt : Elmt_Id;
27479 Constit_Id : Entity_Id;
27480 Proof_In_Seen : Boolean := False;
27481
27482 begin
27483 if Present (Constits) then
27484 Constit_Elmt := First_Elmt (Constits);
27485 while Present (Constit_Elmt) loop
27486 Constit_Id := Node (Constit_Elmt);
27487
27488 -- At least one of the constituents appears as Proof_In
27489
27490 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
27491 Proof_In_Seen := True;
27492
27493 -- The constituent appears in the global refinement, but has
27494 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
27495
27496 elsif Present_Then_Remove (In_Constits, Constit_Id)
27497 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27498 or else Present_Then_Remove (Out_Constits, Constit_Id)
27499 then
27500 Error_Msg_Name_1 := Chars (State_Id);
27501 SPARK_Msg_NE
27502 ("constituent & of state % must have mode `Proof_In` "
27503 & "in global refinement", N, Constit_Id);
27504 end if;
27505
27506 Next_Elmt (Constit_Elmt);
27507 end loop;
27508 end if;
27509
27510 -- Not one of the constituents appeared as Proof_In. Always emit
27511 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
27512 -- When only partial refinement is visible, emit an error if the
27513 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27514 -- the case where both are utilized, an error will be issued by
27515 -- Check_State_And_Constituent_Use.
27516
27517 if not Proof_In_Seen
27518 and then (Has_Visible_Refinement (State_Id)
27519 or else Contains (Repeat_Items, State_Id))
27520 then
27521 SPARK_Msg_NE
27522 ("global refinement of state & must include at least one "
27523 & "constituent of mode `Proof_In`", N, State_Id);
27524 end if;
27525 end Check_Constituent_Usage;
27526
27527 -- Local variables
27528
27529 Item_Elmt : Elmt_Id;
27530 Item_Id : Entity_Id;
27531
27532 -- Start of processing for Check_Proof_In_States
27533
27534 begin
27535 -- Do not perform this check in an instance because it was already
27536 -- performed successfully in the generic template.
27537
27538 if In_Instance then
27539 null;
27540
27541 -- Inspect the Proof_In items of the corresponding Global pragma
27542 -- looking for a state with a visible refinement.
27543
27544 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
27545 Item_Elmt := First_Elmt (Proof_In_Items);
27546 while Present (Item_Elmt) loop
27547 Item_Id := Node (Item_Elmt);
27548
27549 -- Ensure that at least one of the constituents is utilized
27550 -- and is of mode Proof_In. When only partial refinement is
27551 -- visible, ensure that either one of the constituents is
27552 -- utilized and is of mode Proof_In, or the abstract state
27553 -- is repeated and no constituent is utilized.
27554
27555 if Ekind (Item_Id) = E_Abstract_State
27556 and then Has_Non_Null_Visible_Refinement (Item_Id)
27557 then
27558 Check_Constituent_Usage (Item_Id);
27559 end if;
27560
27561 Next_Elmt (Item_Elmt);
27562 end loop;
27563 end if;
27564 end Check_Proof_In_States;
27565
27566 -------------------------------
27567 -- Check_Refined_Global_List --
27568 -------------------------------
27569
27570 procedure Check_Refined_Global_List
27571 (List : Node_Id;
27572 Global_Mode : Name_Id := Name_Input)
27573 is
27574 procedure Check_Refined_Global_Item
27575 (Item : Node_Id;
27576 Global_Mode : Name_Id);
27577 -- Verify the legality of a single global item declaration. Parameter
27578 -- Global_Mode denotes the current mode in effect.
27579
27580 -------------------------------
27581 -- Check_Refined_Global_Item --
27582 -------------------------------
27583
27584 procedure Check_Refined_Global_Item
27585 (Item : Node_Id;
27586 Global_Mode : Name_Id)
27587 is
27588 Item_Id : constant Entity_Id := Entity_Of (Item);
27589
27590 procedure Inconsistent_Mode_Error (Expect : Name_Id);
27591 -- Issue a common error message for all mode mismatches. Expect
27592 -- denotes the expected mode.
27593
27594 -----------------------------
27595 -- Inconsistent_Mode_Error --
27596 -----------------------------
27597
27598 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
27599 begin
27600 SPARK_Msg_NE
27601 ("global item & has inconsistent modes", Item, Item_Id);
27602
27603 Error_Msg_Name_1 := Global_Mode;
27604 Error_Msg_Name_2 := Expect;
27605 SPARK_Msg_N ("\expected mode %, found mode %", Item);
27606 end Inconsistent_Mode_Error;
27607
27608 -- Local variables
27609
27610 Enc_State : Entity_Id := Empty;
27611 -- Encapsulating state for constituent, Empty otherwise
27612
27613 -- Start of processing for Check_Refined_Global_Item
27614
27615 begin
27616 if Ekind (Item_Id) in E_Abstract_State | E_Constant | E_Variable
27617 then
27618 Enc_State := Find_Encapsulating_State (States, Item_Id);
27619 end if;
27620
27621 -- When the state or object acts as a constituent of another
27622 -- state with a visible refinement, collect it for the state
27623 -- completeness checks performed later on. Note that the item
27624 -- acts as a constituent only when the encapsulating state is
27625 -- present in pragma Global.
27626
27627 if Present (Enc_State)
27628 and then (Has_Visible_Refinement (Enc_State)
27629 or else Has_Partial_Visible_Refinement (Enc_State))
27630 and then Contains (States, Enc_State)
27631 then
27632 -- If the state has only partial visible refinement, remove it
27633 -- from the list of items that should be repeated from pragma
27634 -- Global.
27635
27636 if not Has_Visible_Refinement (Enc_State) then
27637 Present_Then_Remove (Repeat_Items, Enc_State);
27638 end if;
27639
27640 if Global_Mode = Name_Input then
27641 Append_New_Elmt (Item_Id, In_Constits);
27642
27643 elsif Global_Mode = Name_In_Out then
27644 Append_New_Elmt (Item_Id, In_Out_Constits);
27645
27646 elsif Global_Mode = Name_Output then
27647 Append_New_Elmt (Item_Id, Out_Constits);
27648
27649 elsif Global_Mode = Name_Proof_In then
27650 Append_New_Elmt (Item_Id, Proof_In_Constits);
27651 end if;
27652
27653 -- When not a constituent, ensure that both occurrences of the
27654 -- item in pragmas Global and Refined_Global match. Also remove
27655 -- it when present from the list of items that should be repeated
27656 -- from pragma Global.
27657
27658 else
27659 Present_Then_Remove (Repeat_Items, Item_Id);
27660
27661 if Contains (In_Items, Item_Id) then
27662 if Global_Mode /= Name_Input then
27663 Inconsistent_Mode_Error (Name_Input);
27664 end if;
27665
27666 elsif Contains (In_Out_Items, Item_Id) then
27667 if Global_Mode /= Name_In_Out then
27668 Inconsistent_Mode_Error (Name_In_Out);
27669 end if;
27670
27671 elsif Contains (Out_Items, Item_Id) then
27672 if Global_Mode /= Name_Output then
27673 Inconsistent_Mode_Error (Name_Output);
27674 end if;
27675
27676 elsif Contains (Proof_In_Items, Item_Id) then
27677 null;
27678
27679 -- The item does not appear in the corresponding Global pragma,
27680 -- it must be an extra (SPARK RM 7.2.4(3)).
27681
27682 else
27683 pragma Assert (Present (Global));
27684 Error_Msg_Sloc := Sloc (Global);
27685 SPARK_Msg_NE
27686 ("extra global item & does not refine or repeat any "
27687 & "global item #", Item, Item_Id);
27688 end if;
27689 end if;
27690 end Check_Refined_Global_Item;
27691
27692 -- Local variables
27693
27694 Item : Node_Id;
27695
27696 -- Start of processing for Check_Refined_Global_List
27697
27698 begin
27699 -- Do not perform this check in an instance because it was already
27700 -- performed successfully in the generic template.
27701
27702 if In_Instance then
27703 null;
27704
27705 elsif Nkind (List) = N_Null then
27706 null;
27707
27708 -- Single global item declaration
27709
27710 elsif Nkind (List) in N_Expanded_Name
27711 | N_Identifier
27712 | N_Selected_Component
27713 then
27714 Check_Refined_Global_Item (List, Global_Mode);
27715
27716 -- Simple global list or moded global list declaration
27717
27718 elsif Nkind (List) = N_Aggregate then
27719
27720 -- The declaration of a simple global list appear as a collection
27721 -- of expressions.
27722
27723 if Present (Expressions (List)) then
27724 Item := First (Expressions (List));
27725 while Present (Item) loop
27726 Check_Refined_Global_Item (Item, Global_Mode);
27727 Next (Item);
27728 end loop;
27729
27730 -- The declaration of a moded global list appears as a collection
27731 -- of component associations where individual choices denote
27732 -- modes.
27733
27734 elsif Present (Component_Associations (List)) then
27735 Item := First (Component_Associations (List));
27736 while Present (Item) loop
27737 Check_Refined_Global_List
27738 (List => Expression (Item),
27739 Global_Mode => Chars (First (Choices (Item))));
27740
27741 Next (Item);
27742 end loop;
27743
27744 -- Invalid tree
27745
27746 else
27747 raise Program_Error;
27748 end if;
27749
27750 -- Invalid list
27751
27752 else
27753 raise Program_Error;
27754 end if;
27755 end Check_Refined_Global_List;
27756
27757 --------------------------
27758 -- Collect_Global_Items --
27759 --------------------------
27760
27761 procedure Collect_Global_Items
27762 (List : Node_Id;
27763 Mode : Name_Id := Name_Input)
27764 is
27765 procedure Collect_Global_Item
27766 (Item : Node_Id;
27767 Item_Mode : Name_Id);
27768 -- Add a single item to the appropriate list. Item_Mode denotes the
27769 -- current mode in effect.
27770
27771 -------------------------
27772 -- Collect_Global_Item --
27773 -------------------------
27774
27775 procedure Collect_Global_Item
27776 (Item : Node_Id;
27777 Item_Mode : Name_Id)
27778 is
27779 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
27780 -- The above handles abstract views of variables and states built
27781 -- for limited with clauses.
27782
27783 begin
27784 -- Signal that the global list contains at least one abstract
27785 -- state with a visible refinement. Note that the refinement may
27786 -- be null in which case there are no constituents.
27787
27788 if Ekind (Item_Id) = E_Abstract_State then
27789 if Has_Null_Visible_Refinement (Item_Id) then
27790 Has_Null_State := True;
27791
27792 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
27793 Append_New_Elmt (Item_Id, States);
27794
27795 if Item_Mode = Name_Input then
27796 Has_In_State := True;
27797 elsif Item_Mode = Name_In_Out then
27798 Has_In_Out_State := True;
27799 elsif Item_Mode = Name_Output then
27800 Has_Out_State := True;
27801 elsif Item_Mode = Name_Proof_In then
27802 Has_Proof_In_State := True;
27803 end if;
27804 end if;
27805 end if;
27806
27807 -- Record global items without full visible refinement found in
27808 -- pragma Global which should be repeated in the global refinement
27809 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
27810
27811 if Ekind (Item_Id) /= E_Abstract_State
27812 or else not Has_Visible_Refinement (Item_Id)
27813 then
27814 Append_New_Elmt (Item_Id, Repeat_Items);
27815 end if;
27816
27817 -- Add the item to the proper list
27818
27819 if Item_Mode = Name_Input then
27820 Append_New_Elmt (Item_Id, In_Items);
27821 elsif Item_Mode = Name_In_Out then
27822 Append_New_Elmt (Item_Id, In_Out_Items);
27823 elsif Item_Mode = Name_Output then
27824 Append_New_Elmt (Item_Id, Out_Items);
27825 elsif Item_Mode = Name_Proof_In then
27826 Append_New_Elmt (Item_Id, Proof_In_Items);
27827 end if;
27828 end Collect_Global_Item;
27829
27830 -- Local variables
27831
27832 Item : Node_Id;
27833
27834 -- Start of processing for Collect_Global_Items
27835
27836 begin
27837 if Nkind (List) = N_Null then
27838 null;
27839
27840 -- Single global item declaration
27841
27842 elsif Nkind (List) in N_Expanded_Name
27843 | N_Identifier
27844 | N_Selected_Component
27845 then
27846 Collect_Global_Item (List, Mode);
27847
27848 -- Single global list or moded global list declaration
27849
27850 elsif Nkind (List) = N_Aggregate then
27851
27852 -- The declaration of a simple global list appear as a collection
27853 -- of expressions.
27854
27855 if Present (Expressions (List)) then
27856 Item := First (Expressions (List));
27857 while Present (Item) loop
27858 Collect_Global_Item (Item, Mode);
27859 Next (Item);
27860 end loop;
27861
27862 -- The declaration of a moded global list appears as a collection
27863 -- of component associations where individual choices denote mode.
27864
27865 elsif Present (Component_Associations (List)) then
27866 Item := First (Component_Associations (List));
27867 while Present (Item) loop
27868 Collect_Global_Items
27869 (List => Expression (Item),
27870 Mode => Chars (First (Choices (Item))));
27871
27872 Next (Item);
27873 end loop;
27874
27875 -- Invalid tree
27876
27877 else
27878 raise Program_Error;
27879 end if;
27880
27881 -- To accommodate partial decoration of disabled SPARK features, this
27882 -- routine may be called with illegal input. If this is the case, do
27883 -- not raise Program_Error.
27884
27885 else
27886 null;
27887 end if;
27888 end Collect_Global_Items;
27889
27890 -------------------------
27891 -- Present_Then_Remove --
27892 -------------------------
27893
27894 function Present_Then_Remove
27895 (List : Elist_Id;
27896 Item : Entity_Id) return Boolean
27897 is
27898 Elmt : Elmt_Id;
27899
27900 begin
27901 if Present (List) then
27902 Elmt := First_Elmt (List);
27903 while Present (Elmt) loop
27904 if Node (Elmt) = Item then
27905 Remove_Elmt (List, Elmt);
27906 return True;
27907 end if;
27908
27909 Next_Elmt (Elmt);
27910 end loop;
27911 end if;
27912
27913 return False;
27914 end Present_Then_Remove;
27915
27916 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id) is
27917 Ignore : Boolean;
27918 begin
27919 Ignore := Present_Then_Remove (List, Item);
27920 end Present_Then_Remove;
27921
27922 -------------------------------
27923 -- Report_Extra_Constituents --
27924 -------------------------------
27925
27926 procedure Report_Extra_Constituents is
27927 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
27928 -- Emit an error for every element of List
27929
27930 ---------------------------------------
27931 -- Report_Extra_Constituents_In_List --
27932 ---------------------------------------
27933
27934 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
27935 Constit_Elmt : Elmt_Id;
27936
27937 begin
27938 if Present (List) then
27939 Constit_Elmt := First_Elmt (List);
27940 while Present (Constit_Elmt) loop
27941 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
27942 Next_Elmt (Constit_Elmt);
27943 end loop;
27944 end if;
27945 end Report_Extra_Constituents_In_List;
27946
27947 -- Start of processing for Report_Extra_Constituents
27948
27949 begin
27950 -- Do not perform this check in an instance because it was already
27951 -- performed successfully in the generic template.
27952
27953 if In_Instance then
27954 null;
27955
27956 else
27957 Report_Extra_Constituents_In_List (In_Constits);
27958 Report_Extra_Constituents_In_List (In_Out_Constits);
27959 Report_Extra_Constituents_In_List (Out_Constits);
27960 Report_Extra_Constituents_In_List (Proof_In_Constits);
27961 end if;
27962 end Report_Extra_Constituents;
27963
27964 --------------------------
27965 -- Report_Missing_Items --
27966 --------------------------
27967
27968 procedure Report_Missing_Items is
27969 Item_Elmt : Elmt_Id;
27970 Item_Id : Entity_Id;
27971
27972 begin
27973 -- Do not perform this check in an instance because it was already
27974 -- performed successfully in the generic template.
27975
27976 if In_Instance then
27977 null;
27978
27979 else
27980 if Present (Repeat_Items) then
27981 Item_Elmt := First_Elmt (Repeat_Items);
27982 while Present (Item_Elmt) loop
27983 Item_Id := Node (Item_Elmt);
27984 SPARK_Msg_NE ("missing global item &", N, Item_Id);
27985 Next_Elmt (Item_Elmt);
27986 end loop;
27987 end if;
27988 end if;
27989 end Report_Missing_Items;
27990
27991 -- Local variables
27992
27993 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
27994 Errors : constant Nat := Serious_Errors_Detected;
27995 Items : Node_Id;
27996 No_Constit : Boolean;
27997
27998 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
27999
28000 begin
28001 -- Do not analyze the pragma multiple times
28002
28003 if Is_Analyzed_Pragma (N) then
28004 return;
28005 end if;
28006
28007 Spec_Id := Unique_Defining_Entity (Body_Decl);
28008
28009 -- Use the anonymous object as the proper spec when Refined_Global
28010 -- applies to the body of a single task type. The object carries the
28011 -- proper Chars as well as all non-refined versions of pragmas.
28012
28013 if Is_Single_Concurrent_Type (Spec_Id) then
28014 Spec_Id := Anonymous_Object (Spec_Id);
28015 end if;
28016
28017 Global := Get_Pragma (Spec_Id, Pragma_Global);
28018 Items := Expression (Get_Argument (N, Spec_Id));
28019
28020 -- The subprogram declaration lacks pragma Global. This renders
28021 -- Refined_Global useless as there is nothing to refine.
28022
28023 if No (Global) then
28024 SPARK_Msg_NE
28025 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
28026 & "& lacks aspect or pragma Global"), N, Spec_Id);
28027 goto Leave;
28028 end if;
28029
28030 -- Extract all relevant items from the corresponding Global pragma
28031
28032 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
28033
28034 -- Package and subprogram bodies are instantiated individually in
28035 -- a separate compiler pass. Due to this mode of instantiation, the
28036 -- refinement of a state may no longer be visible when a subprogram
28037 -- body contract is instantiated. Since the generic template is legal,
28038 -- do not perform this check in the instance to circumvent this oddity.
28039
28040 if In_Instance then
28041 null;
28042
28043 -- Non-instance case
28044
28045 else
28046 -- The corresponding Global pragma must mention at least one
28047 -- state with a visible refinement at the point Refined_Global
28048 -- is processed. States with null refinements need Refined_Global
28049 -- pragma (SPARK RM 7.2.4(2)).
28050
28051 if not Has_In_State
28052 and then not Has_In_Out_State
28053 and then not Has_Out_State
28054 and then not Has_Proof_In_State
28055 and then not Has_Null_State
28056 then
28057 SPARK_Msg_NE
28058 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
28059 & "depend on abstract state with visible refinement"),
28060 N, Spec_Id);
28061 goto Leave;
28062
28063 -- The global refinement of inputs and outputs cannot be null when
28064 -- the corresponding Global pragma contains at least one item except
28065 -- in the case where we have states with null refinements.
28066
28067 elsif Nkind (Items) = N_Null
28068 and then
28069 (Present (In_Items)
28070 or else Present (In_Out_Items)
28071 or else Present (Out_Items)
28072 or else Present (Proof_In_Items))
28073 and then not Has_Null_State
28074 then
28075 SPARK_Msg_NE
28076 (Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has "
28077 & "global items"), N, Spec_Id);
28078 goto Leave;
28079 end if;
28080 end if;
28081
28082 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
28083 -- This ensures that the categorization of all refined global items is
28084 -- consistent with their role.
28085
28086 Analyze_Global_In_Decl_Part (N);
28087
28088 -- Perform all refinement checks with respect to completeness and mode
28089 -- matching.
28090
28091 if Serious_Errors_Detected = Errors then
28092 Check_Refined_Global_List (Items);
28093 end if;
28094
28095 -- Store the information that no constituent is used in the global
28096 -- refinement, prior to calling checking procedures which remove items
28097 -- from the list of constituents.
28098
28099 No_Constit :=
28100 No (In_Constits)
28101 and then No (In_Out_Constits)
28102 and then No (Out_Constits)
28103 and then No (Proof_In_Constits);
28104
28105 -- For Input states with visible refinement, at least one constituent
28106 -- must be used as an Input in the global refinement.
28107
28108 if Serious_Errors_Detected = Errors then
28109 Check_Input_States;
28110 end if;
28111
28112 -- Verify all possible completion variants for In_Out states with
28113 -- visible refinement.
28114
28115 if Serious_Errors_Detected = Errors then
28116 Check_In_Out_States;
28117 end if;
28118
28119 -- For Output states with visible refinement, all constituents must be
28120 -- used as Outputs in the global refinement.
28121
28122 if Serious_Errors_Detected = Errors then
28123 Check_Output_States;
28124 end if;
28125
28126 -- For Proof_In states with visible refinement, at least one constituent
28127 -- must be used as Proof_In in the global refinement.
28128
28129 if Serious_Errors_Detected = Errors then
28130 Check_Proof_In_States;
28131 end if;
28132
28133 -- Emit errors for all constituents that belong to other states with
28134 -- visible refinement that do not appear in Global.
28135
28136 if Serious_Errors_Detected = Errors then
28137 Report_Extra_Constituents;
28138 end if;
28139
28140 -- Emit errors for all items in Global that are not repeated in the
28141 -- global refinement and for which there is no full visible refinement
28142 -- and, in the case of states with partial visible refinement, no
28143 -- constituent is mentioned in the global refinement.
28144
28145 if Serious_Errors_Detected = Errors then
28146 Report_Missing_Items;
28147 end if;
28148
28149 -- Emit an error if no constituent is used in the global refinement
28150 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
28151 -- one may be issued by the checking procedures. Do not perform this
28152 -- check in an instance because it was already performed successfully
28153 -- in the generic template.
28154
28155 if Serious_Errors_Detected = Errors
28156 and then not In_Instance
28157 and then not Has_Null_State
28158 and then No_Constit
28159 then
28160 SPARK_Msg_N ("missing refinement", N);
28161 end if;
28162
28163 <<Leave>>
28164 Set_Is_Analyzed_Pragma (N);
28165 end Analyze_Refined_Global_In_Decl_Part;
28166
28167 ----------------------------------------
28168 -- Analyze_Refined_State_In_Decl_Part --
28169 ----------------------------------------
28170
28171 procedure Analyze_Refined_State_In_Decl_Part
28172 (N : Node_Id;
28173 Freeze_Id : Entity_Id := Empty)
28174 is
28175 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
28176 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
28177 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
28178
28179 Available_States : Elist_Id := No_Elist;
28180 -- A list of all abstract states defined in the package declaration that
28181 -- are available for refinement. The list is used to report unrefined
28182 -- states.
28183
28184 Body_States : Elist_Id := No_Elist;
28185 -- A list of all hidden states that appear in the body of the related
28186 -- package. The list is used to report unused hidden states.
28187
28188 Constituents_Seen : Elist_Id := No_Elist;
28189 -- A list that contains all constituents processed so far. The list is
28190 -- used to detect multiple uses of the same constituent.
28191
28192 Freeze_Posted : Boolean := False;
28193 -- A flag that controls the output of a freezing-related error (see use
28194 -- below).
28195
28196 Refined_States_Seen : Elist_Id := No_Elist;
28197 -- A list that contains all refined states processed so far. The list is
28198 -- used to detect duplicate refinements.
28199
28200 procedure Analyze_Refinement_Clause (Clause : Node_Id);
28201 -- Perform full analysis of a single refinement clause
28202
28203 procedure Report_Unrefined_States (States : Elist_Id);
28204 -- Emit errors for all unrefined abstract states found in list States
28205
28206 -------------------------------
28207 -- Analyze_Refinement_Clause --
28208 -------------------------------
28209
28210 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
28211 AR_Constit : Entity_Id := Empty;
28212 AW_Constit : Entity_Id := Empty;
28213 ER_Constit : Entity_Id := Empty;
28214 EW_Constit : Entity_Id := Empty;
28215 -- The entities of external constituents that contain one of the
28216 -- following enabled properties: Async_Readers, Async_Writers,
28217 -- Effective_Reads and Effective_Writes.
28218
28219 External_Constit_Seen : Boolean := False;
28220 -- Flag used to mark when at least one external constituent is part
28221 -- of the state refinement.
28222
28223 Non_Null_Seen : Boolean := False;
28224 Null_Seen : Boolean := False;
28225 -- Flags used to detect multiple uses of null in a single clause or a
28226 -- mixture of null and non-null constituents.
28227
28228 Part_Of_Constits : Elist_Id := No_Elist;
28229 -- A list of all candidate constituents subject to indicator Part_Of
28230 -- where the encapsulating state is the current state.
28231
28232 State : Node_Id;
28233 State_Id : Entity_Id;
28234 -- The current state being refined
28235
28236 procedure Analyze_Constituent (Constit : Node_Id);
28237 -- Perform full analysis of a single constituent
28238
28239 procedure Check_External_Property
28240 (Prop_Nam : Name_Id;
28241 Enabled : Boolean;
28242 Constit : Entity_Id);
28243 -- Determine whether a property denoted by name Prop_Nam is present
28244 -- in the refined state. Emit an error if this is not the case. Flag
28245 -- Enabled should be set when the property applies to the refined
28246 -- state. Constit denotes the constituent (if any) which introduces
28247 -- the property in the refinement.
28248
28249 procedure Match_State;
28250 -- Determine whether the state being refined appears in list
28251 -- Available_States. Emit an error when attempting to re-refine the
28252 -- state or when the state is not defined in the package declaration,
28253 -- otherwise remove the state from Available_States.
28254
28255 procedure Report_Unused_Constituents (Constits : Elist_Id);
28256 -- Emit errors for all unused Part_Of constituents in list Constits
28257
28258 -------------------------
28259 -- Analyze_Constituent --
28260 -------------------------
28261
28262 procedure Analyze_Constituent (Constit : Node_Id) is
28263 procedure Match_Constituent (Constit_Id : Entity_Id);
28264 -- Determine whether constituent Constit denoted by its entity
28265 -- Constit_Id appears in Body_States. Emit an error when the
28266 -- constituent is not a valid hidden state of the related package
28267 -- or when it is used more than once. Otherwise remove the
28268 -- constituent from Body_States.
28269
28270 -----------------------
28271 -- Match_Constituent --
28272 -----------------------
28273
28274 procedure Match_Constituent (Constit_Id : Entity_Id) is
28275 procedure Collect_Constituent;
28276 -- Verify the legality of constituent Constit_Id and add it to
28277 -- the refinements of State_Id.
28278
28279 -------------------------
28280 -- Collect_Constituent --
28281 -------------------------
28282
28283 procedure Collect_Constituent is
28284 Constits : Elist_Id;
28285
28286 begin
28287 -- The Ghost policy in effect at the point of abstract state
28288 -- declaration and constituent must match (SPARK RM 6.9(15))
28289
28290 Check_Ghost_Refinement
28291 (State, State_Id, Constit, Constit_Id);
28292
28293 -- A synchronized state must be refined by a synchronized
28294 -- object or another synchronized state (SPARK RM 9.6).
28295
28296 if Is_Synchronized_State (State_Id)
28297 and then not Is_Synchronized_Object (Constit_Id)
28298 and then not Is_Synchronized_State (Constit_Id)
28299 then
28300 SPARK_Msg_NE
28301 ("constituent of synchronized state & must be "
28302 & "synchronized", Constit, State_Id);
28303 end if;
28304
28305 -- Add the constituent to the list of processed items to aid
28306 -- with the detection of duplicates.
28307
28308 Append_New_Elmt (Constit_Id, Constituents_Seen);
28309
28310 -- Collect the constituent in the list of refinement items
28311 -- and establish a relation between the refined state and
28312 -- the item.
28313
28314 Constits := Refinement_Constituents (State_Id);
28315
28316 if No (Constits) then
28317 Constits := New_Elmt_List;
28318 Set_Refinement_Constituents (State_Id, Constits);
28319 end if;
28320
28321 Append_Elmt (Constit_Id, Constits);
28322 Set_Encapsulating_State (Constit_Id, State_Id);
28323
28324 -- The state has at least one legal constituent, mark the
28325 -- start of the refinement region. The region ends when the
28326 -- body declarations end (see routine Analyze_Declarations).
28327
28328 Set_Has_Visible_Refinement (State_Id);
28329
28330 -- When the constituent is external, save its relevant
28331 -- property for further checks.
28332
28333 if Async_Readers_Enabled (Constit_Id) then
28334 AR_Constit := Constit_Id;
28335 External_Constit_Seen := True;
28336 end if;
28337
28338 if Async_Writers_Enabled (Constit_Id) then
28339 AW_Constit := Constit_Id;
28340 External_Constit_Seen := True;
28341 end if;
28342
28343 if Effective_Reads_Enabled (Constit_Id) then
28344 ER_Constit := Constit_Id;
28345 External_Constit_Seen := True;
28346 end if;
28347
28348 if Effective_Writes_Enabled (Constit_Id) then
28349 EW_Constit := Constit_Id;
28350 External_Constit_Seen := True;
28351 end if;
28352 end Collect_Constituent;
28353
28354 -- Local variables
28355
28356 State_Elmt : Elmt_Id;
28357
28358 -- Start of processing for Match_Constituent
28359
28360 begin
28361 -- Detect a duplicate use of a constituent
28362
28363 if Contains (Constituents_Seen, Constit_Id) then
28364 SPARK_Msg_NE
28365 ("duplicate use of constituent &", Constit, Constit_Id);
28366 return;
28367 end if;
28368
28369 -- The constituent is subject to a Part_Of indicator
28370
28371 if Present (Encapsulating_State (Constit_Id)) then
28372 if Encapsulating_State (Constit_Id) = State_Id then
28373 Remove (Part_Of_Constits, Constit_Id);
28374 Collect_Constituent;
28375
28376 -- The constituent is part of another state and is used
28377 -- incorrectly in the refinement of the current state.
28378
28379 else
28380 Error_Msg_Name_1 := Chars (State_Id);
28381 SPARK_Msg_NE
28382 ("& cannot act as constituent of state %",
28383 Constit, Constit_Id);
28384 SPARK_Msg_NE
28385 ("\Part_Of indicator specifies encapsulator &",
28386 Constit, Encapsulating_State (Constit_Id));
28387 end if;
28388
28389 -- The only other source of legal constituents is the body
28390 -- state space of the related package.
28391
28392 else
28393 if Present (Body_States) then
28394 State_Elmt := First_Elmt (Body_States);
28395 while Present (State_Elmt) loop
28396
28397 -- Consume a valid constituent to signal that it has
28398 -- been encountered.
28399
28400 if Node (State_Elmt) = Constit_Id then
28401 Remove_Elmt (Body_States, State_Elmt);
28402 Collect_Constituent;
28403 return;
28404 end if;
28405
28406 Next_Elmt (State_Elmt);
28407 end loop;
28408 end if;
28409
28410 -- At this point it is known that the constituent is not
28411 -- part of the package hidden state and cannot be used in
28412 -- a refinement (SPARK RM 7.2.2(9)).
28413
28414 Error_Msg_Name_1 := Chars (Spec_Id);
28415 SPARK_Msg_NE
28416 ("cannot use & in refinement, constituent is not a hidden "
28417 & "state of package %", Constit, Constit_Id);
28418 end if;
28419 end Match_Constituent;
28420
28421 -- Local variables
28422
28423 Constit_Id : Entity_Id;
28424 Constits : Elist_Id;
28425
28426 -- Start of processing for Analyze_Constituent
28427
28428 begin
28429 -- Detect multiple uses of null in a single refinement clause or a
28430 -- mixture of null and non-null constituents.
28431
28432 if Nkind (Constit) = N_Null then
28433 if Null_Seen then
28434 SPARK_Msg_N
28435 ("multiple null constituents not allowed", Constit);
28436
28437 elsif Non_Null_Seen then
28438 SPARK_Msg_N
28439 ("cannot mix null and non-null constituents", Constit);
28440
28441 else
28442 Null_Seen := True;
28443
28444 -- Collect the constituent in the list of refinement items
28445
28446 Constits := Refinement_Constituents (State_Id);
28447
28448 if No (Constits) then
28449 Constits := New_Elmt_List;
28450 Set_Refinement_Constituents (State_Id, Constits);
28451 end if;
28452
28453 Append_Elmt (Constit, Constits);
28454
28455 -- The state has at least one legal constituent, mark the
28456 -- start of the refinement region. The region ends when the
28457 -- body declarations end (see Analyze_Declarations).
28458
28459 Set_Has_Visible_Refinement (State_Id);
28460 end if;
28461
28462 -- Non-null constituents
28463
28464 else
28465 Non_Null_Seen := True;
28466
28467 if Null_Seen then
28468 SPARK_Msg_N
28469 ("cannot mix null and non-null constituents", Constit);
28470 end if;
28471
28472 Analyze (Constit);
28473 Resolve_State (Constit);
28474
28475 -- Ensure that the constituent denotes a valid state or a
28476 -- whole object (SPARK RM 7.2.2(5)).
28477
28478 if Is_Entity_Name (Constit) then
28479 Constit_Id := Entity_Of (Constit);
28480
28481 -- When a constituent is declared after a subprogram body
28482 -- that caused freezing of the related contract where
28483 -- pragma Refined_State resides, the constituent appears
28484 -- undefined and carries Any_Id as its entity.
28485
28486 -- package body Pack
28487 -- with Refined_State => (State => Constit)
28488 -- is
28489 -- procedure Proc
28490 -- with Refined_Global => (Input => Constit)
28491 -- is
28492 -- ...
28493 -- end Proc;
28494
28495 -- Constit : ...;
28496 -- end Pack;
28497
28498 if Constit_Id = Any_Id then
28499 SPARK_Msg_NE ("& is undefined", Constit, Constit_Id);
28500
28501 -- Emit a specialized info message when the contract of
28502 -- the related package body was "frozen" by another body.
28503 -- Note that it is not possible to precisely identify why
28504 -- the constituent is undefined because it is not visible
28505 -- when pragma Refined_State is analyzed. This message is
28506 -- a reasonable approximation.
28507
28508 if Present (Freeze_Id) and then not Freeze_Posted then
28509 Freeze_Posted := True;
28510
28511 Error_Msg_Name_1 := Chars (Body_Id);
28512 Error_Msg_Sloc := Sloc (Freeze_Id);
28513 SPARK_Msg_NE
28514 ("body & declared # freezes the contract of %",
28515 N, Freeze_Id);
28516 SPARK_Msg_N
28517 ("\all constituents must be declared before body #",
28518 N);
28519
28520 -- A misplaced constituent is a critical error because
28521 -- pragma Refined_Depends or Refined_Global depends on
28522 -- the proper link between a state and a constituent.
28523 -- Stop the compilation, as this leads to a multitude
28524 -- of misleading cascaded errors.
28525
28526 raise Unrecoverable_Error;
28527 end if;
28528
28529 -- The constituent is a valid state or object
28530
28531 elsif Ekind (Constit_Id) in
28532 E_Abstract_State | E_Constant | E_Variable
28533 then
28534 Match_Constituent (Constit_Id);
28535
28536 -- The variable may eventually become a constituent of a
28537 -- single protected/task type. Record the reference now
28538 -- and verify its legality when analyzing the contract of
28539 -- the variable (SPARK RM 9.3).
28540
28541 if Ekind (Constit_Id) = E_Variable then
28542 Record_Possible_Part_Of_Reference
28543 (Var_Id => Constit_Id,
28544 Ref => Constit);
28545 end if;
28546
28547 -- Otherwise the constituent is illegal
28548
28549 else
28550 SPARK_Msg_NE
28551 ("constituent & must denote object or state",
28552 Constit, Constit_Id);
28553 end if;
28554
28555 -- The constituent is illegal
28556
28557 else
28558 SPARK_Msg_N ("malformed constituent", Constit);
28559 end if;
28560 end if;
28561 end Analyze_Constituent;
28562
28563 -----------------------------
28564 -- Check_External_Property --
28565 -----------------------------
28566
28567 procedure Check_External_Property
28568 (Prop_Nam : Name_Id;
28569 Enabled : Boolean;
28570 Constit : Entity_Id)
28571 is
28572 begin
28573 -- The property is missing in the declaration of the state, but
28574 -- a constituent is introducing it in the state refinement
28575 -- (SPARK RM 7.2.8(2)).
28576
28577 if not Enabled and then Present (Constit) then
28578 Error_Msg_Name_1 := Prop_Nam;
28579 Error_Msg_Name_2 := Chars (State_Id);
28580 SPARK_Msg_NE
28581 ("constituent & introduces external property % in refinement "
28582 & "of state %", State, Constit);
28583
28584 Error_Msg_Sloc := Sloc (State_Id);
28585 SPARK_Msg_N
28586 ("\property is missing in abstract state declaration #",
28587 State);
28588 end if;
28589 end Check_External_Property;
28590
28591 -----------------
28592 -- Match_State --
28593 -----------------
28594
28595 procedure Match_State is
28596 State_Elmt : Elmt_Id;
28597
28598 begin
28599 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
28600
28601 if Contains (Refined_States_Seen, State_Id) then
28602 SPARK_Msg_NE
28603 ("duplicate refinement of state &", State, State_Id);
28604 return;
28605 end if;
28606
28607 -- Inspect the abstract states defined in the package declaration
28608 -- looking for a match.
28609
28610 State_Elmt := First_Elmt (Available_States);
28611 while Present (State_Elmt) loop
28612
28613 -- A valid abstract state is being refined in the body. Add
28614 -- the state to the list of processed refined states to aid
28615 -- with the detection of duplicate refinements. Remove the
28616 -- state from Available_States to signal that it has already
28617 -- been refined.
28618
28619 if Node (State_Elmt) = State_Id then
28620 Append_New_Elmt (State_Id, Refined_States_Seen);
28621 Remove_Elmt (Available_States, State_Elmt);
28622 return;
28623 end if;
28624
28625 Next_Elmt (State_Elmt);
28626 end loop;
28627
28628 -- If we get here, we are refining a state that is not defined in
28629 -- the package declaration.
28630
28631 Error_Msg_Name_1 := Chars (Spec_Id);
28632 SPARK_Msg_NE
28633 ("cannot refine state, & is not defined in package %",
28634 State, State_Id);
28635 end Match_State;
28636
28637 --------------------------------
28638 -- Report_Unused_Constituents --
28639 --------------------------------
28640
28641 procedure Report_Unused_Constituents (Constits : Elist_Id) is
28642 Constit_Elmt : Elmt_Id;
28643 Constit_Id : Entity_Id;
28644 Posted : Boolean := False;
28645
28646 begin
28647 if Present (Constits) then
28648 Constit_Elmt := First_Elmt (Constits);
28649 while Present (Constit_Elmt) loop
28650 Constit_Id := Node (Constit_Elmt);
28651
28652 -- Generate an error message of the form:
28653
28654 -- state ... has unused Part_Of constituents
28655 -- abstract state ... defined at ...
28656 -- constant ... defined at ...
28657 -- variable ... defined at ...
28658
28659 if not Posted then
28660 Posted := True;
28661 SPARK_Msg_NE
28662 ("state & has unused Part_Of constituents",
28663 State, State_Id);
28664 end if;
28665
28666 Error_Msg_Sloc := Sloc (Constit_Id);
28667
28668 if Ekind (Constit_Id) = E_Abstract_State then
28669 SPARK_Msg_NE
28670 ("\abstract state & defined #", State, Constit_Id);
28671
28672 elsif Ekind (Constit_Id) = E_Constant then
28673 SPARK_Msg_NE
28674 ("\constant & defined #", State, Constit_Id);
28675
28676 else
28677 pragma Assert (Ekind (Constit_Id) = E_Variable);
28678 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
28679 end if;
28680
28681 Next_Elmt (Constit_Elmt);
28682 end loop;
28683 end if;
28684 end Report_Unused_Constituents;
28685
28686 -- Local declarations
28687
28688 Body_Ref : Node_Id;
28689 Body_Ref_Elmt : Elmt_Id;
28690 Constit : Node_Id;
28691 Extra_State : Node_Id;
28692
28693 -- Start of processing for Analyze_Refinement_Clause
28694
28695 begin
28696 -- A refinement clause appears as a component association where the
28697 -- sole choice is the state and the expressions are the constituents.
28698 -- This is a syntax error, always report.
28699
28700 if Nkind (Clause) /= N_Component_Association then
28701 Error_Msg_N ("malformed state refinement clause", Clause);
28702 return;
28703 end if;
28704
28705 -- Analyze the state name of a refinement clause
28706
28707 State := First (Choices (Clause));
28708
28709 Analyze (State);
28710 Resolve_State (State);
28711
28712 -- Ensure that the state name denotes a valid abstract state that is
28713 -- defined in the spec of the related package.
28714
28715 if Is_Entity_Name (State) then
28716 State_Id := Entity_Of (State);
28717
28718 -- When the abstract state is undefined, it appears as Any_Id. Do
28719 -- not continue with the analysis of the clause.
28720
28721 if State_Id = Any_Id then
28722 return;
28723
28724 -- Catch any attempts to re-refine a state or refine a state that
28725 -- is not defined in the package declaration.
28726
28727 elsif Ekind (State_Id) = E_Abstract_State then
28728 Match_State;
28729
28730 else
28731 SPARK_Msg_NE ("& must denote abstract state", State, State_Id);
28732 return;
28733 end if;
28734
28735 -- References to a state with visible refinement are illegal.
28736 -- When nested packages are involved, detecting such references is
28737 -- tricky because pragma Refined_State is analyzed later than the
28738 -- offending pragma Depends or Global. References that occur in
28739 -- such nested context are stored in a list. Emit errors for all
28740 -- references found in Body_References (SPARK RM 6.1.4(8)).
28741
28742 if Present (Body_References (State_Id)) then
28743 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
28744 while Present (Body_Ref_Elmt) loop
28745 Body_Ref := Node (Body_Ref_Elmt);
28746
28747 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
28748 Error_Msg_Sloc := Sloc (State);
28749 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
28750
28751 Next_Elmt (Body_Ref_Elmt);
28752 end loop;
28753 end if;
28754
28755 -- The state name is illegal. This is a syntax error, always report.
28756
28757 else
28758 Error_Msg_N ("malformed state name in refinement clause", State);
28759 return;
28760 end if;
28761
28762 -- A refinement clause may only refine one state at a time
28763
28764 Extra_State := Next (State);
28765
28766 if Present (Extra_State) then
28767 SPARK_Msg_N
28768 ("refinement clause cannot cover multiple states", Extra_State);
28769 end if;
28770
28771 -- Replicate the Part_Of constituents of the refined state because
28772 -- the algorithm will consume items.
28773
28774 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
28775
28776 -- Analyze all constituents of the refinement. Multiple constituents
28777 -- appear as an aggregate.
28778
28779 Constit := Expression (Clause);
28780
28781 if Nkind (Constit) = N_Aggregate then
28782 if Present (Component_Associations (Constit)) then
28783 SPARK_Msg_N
28784 ("constituents of refinement clause must appear in "
28785 & "positional form", Constit);
28786
28787 else pragma Assert (Present (Expressions (Constit)));
28788 Constit := First (Expressions (Constit));
28789 while Present (Constit) loop
28790 Analyze_Constituent (Constit);
28791 Next (Constit);
28792 end loop;
28793 end if;
28794
28795 -- Various forms of a single constituent. Note that these may include
28796 -- malformed constituents.
28797
28798 else
28799 Analyze_Constituent (Constit);
28800 end if;
28801
28802 -- Verify that external constituents do not introduce new external
28803 -- property in the state refinement (SPARK RM 7.2.8(2)).
28804
28805 if Is_External_State (State_Id) then
28806 Check_External_Property
28807 (Prop_Nam => Name_Async_Readers,
28808 Enabled => Async_Readers_Enabled (State_Id),
28809 Constit => AR_Constit);
28810
28811 Check_External_Property
28812 (Prop_Nam => Name_Async_Writers,
28813 Enabled => Async_Writers_Enabled (State_Id),
28814 Constit => AW_Constit);
28815
28816 Check_External_Property
28817 (Prop_Nam => Name_Effective_Reads,
28818 Enabled => Effective_Reads_Enabled (State_Id),
28819 Constit => ER_Constit);
28820
28821 Check_External_Property
28822 (Prop_Nam => Name_Effective_Writes,
28823 Enabled => Effective_Writes_Enabled (State_Id),
28824 Constit => EW_Constit);
28825
28826 -- When a refined state is not external, it should not have external
28827 -- constituents (SPARK RM 7.2.8(1)).
28828
28829 elsif External_Constit_Seen then
28830 SPARK_Msg_NE
28831 ("non-external state & cannot contain external constituents in "
28832 & "refinement", State, State_Id);
28833 end if;
28834
28835 -- Ensure that all Part_Of candidate constituents have been mentioned
28836 -- in the refinement clause.
28837
28838 Report_Unused_Constituents (Part_Of_Constits);
28839 end Analyze_Refinement_Clause;
28840
28841 -----------------------------
28842 -- Report_Unrefined_States --
28843 -----------------------------
28844
28845 procedure Report_Unrefined_States (States : Elist_Id) is
28846 State_Elmt : Elmt_Id;
28847
28848 begin
28849 if Present (States) then
28850 State_Elmt := First_Elmt (States);
28851 while Present (State_Elmt) loop
28852 SPARK_Msg_N
28853 ("abstract state & must be refined", Node (State_Elmt));
28854
28855 Next_Elmt (State_Elmt);
28856 end loop;
28857 end if;
28858 end Report_Unrefined_States;
28859
28860 -- Local declarations
28861
28862 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
28863 Clause : Node_Id;
28864
28865 -- Start of processing for Analyze_Refined_State_In_Decl_Part
28866
28867 begin
28868 -- Do not analyze the pragma multiple times
28869
28870 if Is_Analyzed_Pragma (N) then
28871 return;
28872 end if;
28873
28874 -- Save the scenario for examination by the ABE Processing phase
28875
28876 Record_Elaboration_Scenario (N);
28877
28878 -- Replicate the abstract states declared by the package because the
28879 -- matching algorithm will consume states.
28880
28881 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
28882
28883 -- Gather all abstract states and objects declared in the visible
28884 -- state space of the package body. These items must be utilized as
28885 -- constituents in a state refinement.
28886
28887 Body_States := Collect_Body_States (Body_Id);
28888
28889 -- Multiple non-null state refinements appear as an aggregate
28890
28891 if Nkind (Clauses) = N_Aggregate then
28892 if Present (Expressions (Clauses)) then
28893 SPARK_Msg_N
28894 ("state refinements must appear as component associations",
28895 Clauses);
28896
28897 else pragma Assert (Present (Component_Associations (Clauses)));
28898 Clause := First (Component_Associations (Clauses));
28899 while Present (Clause) loop
28900 Analyze_Refinement_Clause (Clause);
28901 Next (Clause);
28902 end loop;
28903 end if;
28904
28905 -- Various forms of a single state refinement. Note that these may
28906 -- include malformed refinements.
28907
28908 else
28909 Analyze_Refinement_Clause (Clauses);
28910 end if;
28911
28912 -- List all abstract states that were left unrefined
28913
28914 Report_Unrefined_States (Available_States);
28915
28916 Set_Is_Analyzed_Pragma (N);
28917 end Analyze_Refined_State_In_Decl_Part;
28918
28919 ------------------------------------
28920 -- Analyze_Test_Case_In_Decl_Part --
28921 ------------------------------------
28922
28923 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
28924 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
28925 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
28926
28927 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
28928 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
28929 -- denoted by Arg_Nam.
28930
28931 ------------------------------
28932 -- Preanalyze_Test_Case_Arg --
28933 ------------------------------
28934
28935 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
28936 Arg : Node_Id;
28937
28938 begin
28939 -- Preanalyze the original aspect argument for a generic subprogram
28940 -- to properly capture global references.
28941
28942 if Is_Generic_Subprogram (Spec_Id) then
28943 Arg :=
28944 Test_Case_Arg
28945 (Prag => N,
28946 Arg_Nam => Arg_Nam,
28947 From_Aspect => True);
28948
28949 if Present (Arg) then
28950 Preanalyze_Assert_Expression
28951 (Expression (Arg), Standard_Boolean);
28952 end if;
28953 end if;
28954
28955 Arg := Test_Case_Arg (N, Arg_Nam);
28956
28957 if Present (Arg) then
28958 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
28959 end if;
28960 end Preanalyze_Test_Case_Arg;
28961
28962 -- Local variables
28963
28964 Restore_Scope : Boolean := False;
28965
28966 -- Start of processing for Analyze_Test_Case_In_Decl_Part
28967
28968 begin
28969 -- Do not analyze the pragma multiple times
28970
28971 if Is_Analyzed_Pragma (N) then
28972 return;
28973 end if;
28974
28975 -- Ensure that the formal parameters are visible when analyzing all
28976 -- clauses. This falls out of the general rule of aspects pertaining
28977 -- to subprogram declarations.
28978
28979 if not In_Open_Scopes (Spec_Id) then
28980 Restore_Scope := True;
28981 Push_Scope (Spec_Id);
28982
28983 if Is_Generic_Subprogram (Spec_Id) then
28984 Install_Generic_Formals (Spec_Id);
28985 else
28986 Install_Formals (Spec_Id);
28987 end if;
28988 end if;
28989
28990 Preanalyze_Test_Case_Arg (Name_Requires);
28991 Preanalyze_Test_Case_Arg (Name_Ensures);
28992
28993 if Restore_Scope then
28994 End_Scope;
28995 end if;
28996
28997 -- Currently it is not possible to inline pre/postconditions on a
28998 -- subprogram subject to pragma Inline_Always.
28999
29000 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
29001
29002 Set_Is_Analyzed_Pragma (N);
29003 end Analyze_Test_Case_In_Decl_Part;
29004
29005 ----------------
29006 -- Appears_In --
29007 ----------------
29008
29009 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
29010 Elmt : Elmt_Id;
29011 Id : Entity_Id;
29012
29013 begin
29014 if Present (List) then
29015 Elmt := First_Elmt (List);
29016 while Present (Elmt) loop
29017 if Nkind (Node (Elmt)) = N_Defining_Identifier then
29018 Id := Node (Elmt);
29019 else
29020 Id := Entity_Of (Node (Elmt));
29021 end if;
29022
29023 if Id = Item_Id then
29024 return True;
29025 end if;
29026
29027 Next_Elmt (Elmt);
29028 end loop;
29029 end if;
29030
29031 return False;
29032 end Appears_In;
29033
29034 -----------------------------------
29035 -- Build_Pragma_Check_Equivalent --
29036 -----------------------------------
29037
29038 function Build_Pragma_Check_Equivalent
29039 (Prag : Node_Id;
29040 Subp_Id : Entity_Id := Empty;
29041 Inher_Id : Entity_Id := Empty;
29042 Keep_Pragma_Id : Boolean := False) return Node_Id
29043 is
29044 function Suppress_Reference (N : Node_Id) return Traverse_Result;
29045 -- Detect whether node N references a formal parameter subject to
29046 -- pragma Unreferenced. If this is the case, set Comes_From_Source
29047 -- to False to suppress the generation of a reference when analyzing
29048 -- N later on.
29049
29050 ------------------------
29051 -- Suppress_Reference --
29052 ------------------------
29053
29054 function Suppress_Reference (N : Node_Id) return Traverse_Result is
29055 Formal : Entity_Id;
29056
29057 begin
29058 if Is_Entity_Name (N) and then Present (Entity (N)) then
29059 Formal := Entity (N);
29060
29061 -- The formal parameter is subject to pragma Unreferenced. Prevent
29062 -- the generation of references by resetting the Comes_From_Source
29063 -- flag.
29064
29065 if Is_Formal (Formal)
29066 and then Has_Pragma_Unreferenced (Formal)
29067 then
29068 Set_Comes_From_Source (N, False);
29069 end if;
29070 end if;
29071
29072 return OK;
29073 end Suppress_Reference;
29074
29075 procedure Suppress_References is
29076 new Traverse_Proc (Suppress_Reference);
29077
29078 -- Local variables
29079
29080 Loc : constant Source_Ptr := Sloc (Prag);
29081 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
29082 Check_Prag : Node_Id;
29083 Msg_Arg : Node_Id;
29084 Nam : Name_Id;
29085
29086 Needs_Wrapper : Boolean;
29087 pragma Unreferenced (Needs_Wrapper);
29088
29089 -- Start of processing for Build_Pragma_Check_Equivalent
29090
29091 begin
29092 -- When the pre- or postcondition is inherited, map the formals of the
29093 -- inherited subprogram to those of the current subprogram. In addition,
29094 -- map primitive operations of the parent type into the corresponding
29095 -- primitive operations of the descendant.
29096
29097 if Present (Inher_Id) then
29098 pragma Assert (Present (Subp_Id));
29099
29100 Update_Primitives_Mapping (Inher_Id, Subp_Id);
29101
29102 -- Use generic machinery to copy inherited pragma, as if it were an
29103 -- instantiation, resetting source locations appropriately, so that
29104 -- expressions inside the inherited pragma use chained locations.
29105 -- This is used in particular in GNATprove to locate precisely
29106 -- messages on a given inherited pragma.
29107
29108 Set_Copied_Sloc_For_Inherited_Pragma
29109 (Unit_Declaration_Node (Subp_Id), Inher_Id);
29110 Check_Prag := New_Copy_Tree (Source => Prag);
29111
29112 -- Build the inherited class-wide condition
29113
29114 Build_Class_Wide_Expression
29115 (Prag => Check_Prag,
29116 Subp => Subp_Id,
29117 Par_Subp => Inher_Id,
29118 Adjust_Sloc => True,
29119 Needs_Wrapper => Needs_Wrapper);
29120
29121 -- If not an inherited condition simply copy the original pragma
29122
29123 else
29124 Check_Prag := New_Copy_Tree (Source => Prag);
29125 end if;
29126
29127 -- Mark the pragma as being internally generated and reset the Analyzed
29128 -- flag.
29129
29130 Set_Analyzed (Check_Prag, False);
29131 Set_Comes_From_Source (Check_Prag, False);
29132
29133 -- The tree of the original pragma may contain references to the
29134 -- formal parameters of the related subprogram. At the same time
29135 -- the corresponding body may mark the formals as unreferenced:
29136
29137 -- procedure Proc (Formal : ...)
29138 -- with Pre => Formal ...;
29139
29140 -- procedure Proc (Formal : ...) is
29141 -- pragma Unreferenced (Formal);
29142 -- ...
29143
29144 -- This creates problems because all pragma Check equivalents are
29145 -- analyzed at the end of the body declarations. Since all source
29146 -- references have already been accounted for, reset any references
29147 -- to such formals in the generated pragma Check equivalent.
29148
29149 Suppress_References (Check_Prag);
29150
29151 if Present (Corresponding_Aspect (Prag)) then
29152 Nam := Chars (Identifier (Corresponding_Aspect (Prag)));
29153 else
29154 Nam := Prag_Nam;
29155 end if;
29156
29157 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
29158 -- the copied pragma in the newly created pragma, convert the copy into
29159 -- pragma Check by correcting the name and adding a check_kind argument.
29160
29161 if not Keep_Pragma_Id then
29162 Set_Class_Present (Check_Prag, False);
29163
29164 Set_Pragma_Identifier
29165 (Check_Prag, Make_Identifier (Loc, Name_Check));
29166
29167 Prepend_To (Pragma_Argument_Associations (Check_Prag),
29168 Make_Pragma_Argument_Association (Loc,
29169 Expression => Make_Identifier (Loc, Nam)));
29170 end if;
29171
29172 -- Update the error message when the pragma is inherited
29173
29174 if Present (Inher_Id) then
29175 Msg_Arg := Last (Pragma_Argument_Associations (Check_Prag));
29176
29177 if Chars (Msg_Arg) = Name_Message then
29178 String_To_Name_Buffer (Strval (Expression (Msg_Arg)));
29179
29180 -- Insert "inherited" to improve the error message
29181
29182 if Name_Buffer (1 .. 8) = "failed p" then
29183 Insert_Str_In_Name_Buffer ("inherited ", 8);
29184 Set_Strval (Expression (Msg_Arg), String_From_Name_Buffer);
29185 end if;
29186 end if;
29187 end if;
29188
29189 return Check_Prag;
29190 end Build_Pragma_Check_Equivalent;
29191
29192 -----------------------------
29193 -- Check_Applicable_Policy --
29194 -----------------------------
29195
29196 procedure Check_Applicable_Policy (N : Node_Id) is
29197 PP : Node_Id;
29198 Policy : Name_Id;
29199
29200 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
29201
29202 begin
29203 -- No effect if not valid assertion kind name
29204
29205 if not Is_Valid_Assertion_Kind (Ename) then
29206 return;
29207 end if;
29208
29209 -- Loop through entries in check policy list
29210
29211 PP := Opt.Check_Policy_List;
29212 while Present (PP) loop
29213 declare
29214 PPA : constant List_Id := Pragma_Argument_Associations (PP);
29215 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
29216
29217 begin
29218 if Ename = Pnm
29219 or else Pnm = Name_Assertion
29220 or else (Pnm = Name_Statement_Assertions
29221 and then Ename in Name_Assert
29222 | Name_Assert_And_Cut
29223 | Name_Assume
29224 | Name_Loop_Invariant
29225 | Name_Loop_Variant)
29226 then
29227 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
29228
29229 case Policy is
29230 when Name_Ignore
29231 | Name_Off
29232 =>
29233 -- In CodePeer mode and GNATprove mode, we need to
29234 -- consider all assertions, unless they are disabled.
29235 -- Force Is_Checked on ignored assertions, in particular
29236 -- because transformations of the AST may depend on
29237 -- assertions being checked (e.g. the translation of
29238 -- attribute 'Loop_Entry).
29239
29240 if CodePeer_Mode or GNATprove_Mode then
29241 Set_Is_Checked (N, True);
29242 Set_Is_Ignored (N, False);
29243 else
29244 Set_Is_Checked (N, False);
29245 Set_Is_Ignored (N, True);
29246 end if;
29247
29248 when Name_Check
29249 | Name_On
29250 =>
29251 Set_Is_Checked (N, True);
29252 Set_Is_Ignored (N, False);
29253
29254 when Name_Disable =>
29255 Set_Is_Ignored (N, True);
29256 Set_Is_Checked (N, False);
29257 Set_Is_Disabled (N, True);
29258
29259 -- That should be exhaustive, the null here is a defence
29260 -- against a malformed tree from previous errors.
29261
29262 when others =>
29263 null;
29264 end case;
29265
29266 return;
29267 end if;
29268
29269 PP := Next_Pragma (PP);
29270 end;
29271 end loop;
29272
29273 -- If there are no specific entries that matched, then we let the
29274 -- setting of assertions govern. Note that this provides the needed
29275 -- compatibility with the RM for the cases of assertion, invariant,
29276 -- precondition, predicate, and postcondition. Note also that
29277 -- Assertions_Enabled is forced in CodePeer mode and GNATprove mode.
29278
29279 if Assertions_Enabled then
29280 Set_Is_Checked (N, True);
29281 Set_Is_Ignored (N, False);
29282 else
29283 Set_Is_Checked (N, False);
29284 Set_Is_Ignored (N, True);
29285 end if;
29286 end Check_Applicable_Policy;
29287
29288 -------------------------------
29289 -- Check_External_Properties --
29290 -------------------------------
29291
29292 procedure Check_External_Properties
29293 (Item : Node_Id;
29294 AR : Boolean;
29295 AW : Boolean;
29296 ER : Boolean;
29297 EW : Boolean)
29298 is
29299 begin
29300 -- All properties enabled
29301
29302 if AR and AW and ER and EW then
29303 null;
29304
29305 -- Async_Readers + Effective_Writes
29306 -- Async_Readers + Async_Writers + Effective_Writes
29307
29308 elsif AR and EW and not ER then
29309 null;
29310
29311 -- Async_Writers + Effective_Reads
29312 -- Async_Readers + Async_Writers + Effective_Reads
29313
29314 elsif AW and ER and not EW then
29315 null;
29316
29317 -- Async_Readers + Async_Writers
29318
29319 elsif AR and AW and not ER and not EW then
29320 null;
29321
29322 -- Async_Readers
29323
29324 elsif AR and not AW and not ER and not EW then
29325 null;
29326
29327 -- Async_Writers
29328
29329 elsif AW and not AR and not ER and not EW then
29330 null;
29331
29332 else
29333 SPARK_Msg_N
29334 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
29335 Item);
29336 end if;
29337 end Check_External_Properties;
29338
29339 ----------------
29340 -- Check_Kind --
29341 ----------------
29342
29343 function Check_Kind (Nam : Name_Id) return Name_Id is
29344 PP : Node_Id;
29345
29346 begin
29347 -- Loop through entries in check policy list
29348
29349 PP := Opt.Check_Policy_List;
29350 while Present (PP) loop
29351 declare
29352 PPA : constant List_Id := Pragma_Argument_Associations (PP);
29353 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
29354
29355 begin
29356 if Nam = Pnm
29357 or else (Pnm = Name_Assertion
29358 and then Is_Valid_Assertion_Kind (Nam))
29359 or else (Pnm = Name_Statement_Assertions
29360 and then Nam in Name_Assert
29361 | Name_Assert_And_Cut
29362 | Name_Assume
29363 | Name_Loop_Invariant
29364 | Name_Loop_Variant)
29365 then
29366 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
29367 when Name_Check
29368 | Name_On
29369 =>
29370 return Name_Check;
29371
29372 when Name_Ignore
29373 | Name_Off
29374 =>
29375 return Name_Ignore;
29376
29377 when Name_Disable =>
29378 return Name_Disable;
29379
29380 when others =>
29381 raise Program_Error;
29382 end case;
29383
29384 else
29385 PP := Next_Pragma (PP);
29386 end if;
29387 end;
29388 end loop;
29389
29390 -- If there are no specific entries that matched, then we let the
29391 -- setting of assertions govern. Note that this provides the needed
29392 -- compatibility with the RM for the cases of assertion, invariant,
29393 -- precondition, predicate, and postcondition.
29394
29395 if Assertions_Enabled then
29396 return Name_Check;
29397 else
29398 return Name_Ignore;
29399 end if;
29400 end Check_Kind;
29401
29402 ---------------------------
29403 -- Check_Missing_Part_Of --
29404 ---------------------------
29405
29406 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
29407 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
29408 -- Determine whether a package denoted by Pack_Id declares at least one
29409 -- visible state.
29410
29411 -----------------------
29412 -- Has_Visible_State --
29413 -----------------------
29414
29415 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
29416 Item_Id : Entity_Id;
29417
29418 begin
29419 -- Traverse the entity chain of the package trying to find at least
29420 -- one visible abstract state, variable or a package [instantiation]
29421 -- that declares a visible state.
29422
29423 Item_Id := First_Entity (Pack_Id);
29424 while Present (Item_Id)
29425 and then not In_Private_Part (Item_Id)
29426 loop
29427 -- Do not consider internally generated items
29428
29429 if not Comes_From_Source (Item_Id) then
29430 null;
29431
29432 -- Do not consider generic formals or their corresponding actuals
29433 -- because they are not part of a visible state. Note that both
29434 -- entities are marked as hidden.
29435
29436 elsif Is_Hidden (Item_Id) then
29437 null;
29438
29439 -- A visible state has been found. Note that constants are not
29440 -- considered here because it is not possible to determine whether
29441 -- they depend on variable input. This check is left to the SPARK
29442 -- prover.
29443
29444 elsif Ekind (Item_Id) in E_Abstract_State | E_Variable then
29445 return True;
29446
29447 -- Recursively peek into nested packages and instantiations
29448
29449 elsif Ekind (Item_Id) = E_Package
29450 and then Has_Visible_State (Item_Id)
29451 then
29452 return True;
29453 end if;
29454
29455 Next_Entity (Item_Id);
29456 end loop;
29457
29458 return False;
29459 end Has_Visible_State;
29460
29461 -- Local variables
29462
29463 Pack_Id : Entity_Id;
29464 Placement : State_Space_Kind;
29465
29466 -- Start of processing for Check_Missing_Part_Of
29467
29468 begin
29469 -- Do not consider abstract states, variables or package instantiations
29470 -- coming from an instance as those always inherit the Part_Of indicator
29471 -- of the instance itself.
29472
29473 if In_Instance then
29474 return;
29475
29476 -- Do not consider internally generated entities as these can never
29477 -- have a Part_Of indicator.
29478
29479 elsif not Comes_From_Source (Item_Id) then
29480 return;
29481
29482 -- Perform these checks only when SPARK_Mode is enabled as they will
29483 -- interfere with standard Ada rules and produce false positives.
29484
29485 elsif SPARK_Mode /= On then
29486 return;
29487
29488 -- Do not consider constants, because the compiler cannot accurately
29489 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
29490 -- act as a hidden state of a package.
29491
29492 elsif Ekind (Item_Id) = E_Constant then
29493 return;
29494 end if;
29495
29496 -- Find where the abstract state, variable or package instantiation
29497 -- lives with respect to the state space.
29498
29499 Find_Placement_In_State_Space
29500 (Item_Id => Item_Id,
29501 Placement => Placement,
29502 Pack_Id => Pack_Id);
29503
29504 -- Items that appear in a non-package construct (subprogram, block, etc)
29505 -- do not require a Part_Of indicator because they can never act as a
29506 -- hidden state.
29507
29508 if Placement = Not_In_Package then
29509 null;
29510
29511 -- An item declared in the body state space of a package always act as a
29512 -- constituent and does not need explicit Part_Of indicator.
29513
29514 elsif Placement = Body_State_Space then
29515 null;
29516
29517 -- In general an item declared in the visible state space of a package
29518 -- does not require a Part_Of indicator. The only exception is when the
29519 -- related package is a nongeneric private child unit, in which case
29520 -- Part_Of must denote a state in the parent unit or in one of its
29521 -- descendants.
29522
29523 elsif Placement = Visible_State_Space then
29524 if Is_Child_Unit (Pack_Id)
29525 and then not Is_Generic_Unit (Pack_Id)
29526 and then Is_Private_Descendant (Pack_Id)
29527 then
29528 -- A package instantiation does not need a Part_Of indicator when
29529 -- the related generic template has no visible state.
29530
29531 if Ekind (Item_Id) = E_Package
29532 and then Is_Generic_Instance (Item_Id)
29533 and then not Has_Visible_State (Item_Id)
29534 then
29535 null;
29536
29537 -- All other cases require Part_Of
29538
29539 else
29540 Error_Msg_N
29541 ("indicator Part_Of is required in this context "
29542 & "(SPARK RM 7.2.6(3))", Item_Id);
29543 Error_Msg_Name_1 := Chars (Pack_Id);
29544 Error_Msg_N
29545 ("\& is declared in the visible part of private child "
29546 & "unit %", Item_Id);
29547 end if;
29548 end if;
29549
29550 -- When the item appears in the private state space of a package, it
29551 -- must be a part of some state declared by the said package.
29552
29553 else pragma Assert (Placement = Private_State_Space);
29554
29555 -- The related package does not declare a state, the item cannot act
29556 -- as a Part_Of constituent.
29557
29558 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
29559 null;
29560
29561 -- A package instantiation does not need a Part_Of indicator when the
29562 -- related generic template has no visible state.
29563
29564 elsif Ekind (Item_Id) = E_Package
29565 and then Is_Generic_Instance (Item_Id)
29566 and then not Has_Visible_State (Item_Id)
29567 then
29568 null;
29569
29570 -- All other cases require Part_Of
29571
29572 else
29573 Error_Msg_N
29574 ("indicator Part_Of is required in this context "
29575 & "(SPARK RM 7.2.6(2))", Item_Id);
29576 Error_Msg_Name_1 := Chars (Pack_Id);
29577 Error_Msg_N
29578 ("\& is declared in the private part of package %", Item_Id);
29579 end if;
29580 end if;
29581 end Check_Missing_Part_Of;
29582
29583 ---------------------------------------------------
29584 -- Check_Postcondition_Use_In_Inlined_Subprogram --
29585 ---------------------------------------------------
29586
29587 procedure Check_Postcondition_Use_In_Inlined_Subprogram
29588 (Prag : Node_Id;
29589 Spec_Id : Entity_Id)
29590 is
29591 begin
29592 if Warn_On_Redundant_Constructs
29593 and then Has_Pragma_Inline_Always (Spec_Id)
29594 and then Assertions_Enabled
29595 then
29596 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
29597
29598 if From_Aspect_Specification (Prag) then
29599 Error_Msg_NE
29600 ("aspect % not enforced on inlined subprogram &?r?",
29601 Corresponding_Aspect (Prag), Spec_Id);
29602 else
29603 Error_Msg_NE
29604 ("pragma % not enforced on inlined subprogram &?r?",
29605 Prag, Spec_Id);
29606 end if;
29607 end if;
29608 end Check_Postcondition_Use_In_Inlined_Subprogram;
29609
29610 -------------------------------------
29611 -- Check_State_And_Constituent_Use --
29612 -------------------------------------
29613
29614 procedure Check_State_And_Constituent_Use
29615 (States : Elist_Id;
29616 Constits : Elist_Id;
29617 Context : Node_Id)
29618 is
29619 Constit_Elmt : Elmt_Id;
29620 Constit_Id : Entity_Id;
29621 State_Id : Entity_Id;
29622
29623 begin
29624 -- Nothing to do if there are no states or constituents
29625
29626 if No (States) or else No (Constits) then
29627 return;
29628 end if;
29629
29630 -- Inspect the list of constituents and try to determine whether its
29631 -- encapsulating state is in list States.
29632
29633 Constit_Elmt := First_Elmt (Constits);
29634 while Present (Constit_Elmt) loop
29635 Constit_Id := Node (Constit_Elmt);
29636
29637 -- Determine whether the constituent is part of an encapsulating
29638 -- state that appears in the same context and if this is the case,
29639 -- emit an error (SPARK RM 7.2.6(7)).
29640
29641 State_Id := Find_Encapsulating_State (States, Constit_Id);
29642
29643 if Present (State_Id) then
29644 Error_Msg_Name_1 := Chars (Constit_Id);
29645 SPARK_Msg_NE
29646 ("cannot mention state & and its constituent % in the same "
29647 & "context", Context, State_Id);
29648 exit;
29649 end if;
29650
29651 Next_Elmt (Constit_Elmt);
29652 end loop;
29653 end Check_State_And_Constituent_Use;
29654
29655 ---------------------------------------------
29656 -- Collect_Inherited_Class_Wide_Conditions --
29657 ---------------------------------------------
29658
29659 procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is
29660 Parent_Subp : constant Entity_Id :=
29661 Ultimate_Alias (Overridden_Operation (Subp));
29662 -- The Overridden_Operation may itself be inherited and as such have no
29663 -- explicit contract.
29664
29665 Prags : constant Node_Id := Contract (Parent_Subp);
29666 In_Spec_Expr : Boolean := In_Spec_Expression;
29667 Installed : Boolean;
29668 Prag : Node_Id;
29669 New_Prag : Node_Id;
29670
29671 begin
29672 Installed := False;
29673
29674 -- Iterate over the contract of the overridden subprogram to find all
29675 -- inherited class-wide pre- and postconditions.
29676
29677 if Present (Prags) then
29678 Prag := Pre_Post_Conditions (Prags);
29679
29680 while Present (Prag) loop
29681 if Pragma_Name_Unmapped (Prag)
29682 in Name_Precondition | Name_Postcondition
29683 and then Class_Present (Prag)
29684 then
29685 -- The generated pragma must be analyzed in the context of
29686 -- the subprogram, to make its formals visible. In addition,
29687 -- we must inhibit freezing and full analysis because the
29688 -- controlling type of the subprogram is not frozen yet, and
29689 -- may have further primitives.
29690
29691 if not Installed then
29692 Installed := True;
29693 Push_Scope (Subp);
29694 Install_Formals (Subp);
29695 In_Spec_Expr := In_Spec_Expression;
29696 In_Spec_Expression := True;
29697 end if;
29698
29699 New_Prag :=
29700 Build_Pragma_Check_Equivalent
29701 (Prag, Subp, Parent_Subp, Keep_Pragma_Id => True);
29702
29703 Insert_After (Unit_Declaration_Node (Subp), New_Prag);
29704 Preanalyze (New_Prag);
29705
29706 -- Prevent further analysis in subsequent processing of the
29707 -- current list of declarations
29708
29709 Set_Analyzed (New_Prag);
29710 end if;
29711
29712 Prag := Next_Pragma (Prag);
29713 end loop;
29714
29715 if Installed then
29716 In_Spec_Expression := In_Spec_Expr;
29717 End_Scope;
29718 end if;
29719 end if;
29720 end Collect_Inherited_Class_Wide_Conditions;
29721
29722 ---------------------------------------
29723 -- Collect_Subprogram_Inputs_Outputs --
29724 ---------------------------------------
29725
29726 procedure Collect_Subprogram_Inputs_Outputs
29727 (Subp_Id : Entity_Id;
29728 Synthesize : Boolean := False;
29729 Subp_Inputs : in out Elist_Id;
29730 Subp_Outputs : in out Elist_Id;
29731 Global_Seen : out Boolean)
29732 is
29733 procedure Collect_Dependency_Clause (Clause : Node_Id);
29734 -- Collect all relevant items from a dependency clause
29735
29736 procedure Collect_Global_List
29737 (List : Node_Id;
29738 Mode : Name_Id := Name_Input);
29739 -- Collect all relevant items from a global list
29740
29741 -------------------------------
29742 -- Collect_Dependency_Clause --
29743 -------------------------------
29744
29745 procedure Collect_Dependency_Clause (Clause : Node_Id) is
29746 procedure Collect_Dependency_Item
29747 (Item : Node_Id;
29748 Is_Input : Boolean);
29749 -- Add an item to the proper subprogram input or output collection
29750
29751 -----------------------------
29752 -- Collect_Dependency_Item --
29753 -----------------------------
29754
29755 procedure Collect_Dependency_Item
29756 (Item : Node_Id;
29757 Is_Input : Boolean)
29758 is
29759 Extra : Node_Id;
29760
29761 begin
29762 -- Nothing to collect when the item is null
29763
29764 if Nkind (Item) = N_Null then
29765 null;
29766
29767 -- Ditto for attribute 'Result
29768
29769 elsif Is_Attribute_Result (Item) then
29770 null;
29771
29772 -- Multiple items appear as an aggregate
29773
29774 elsif Nkind (Item) = N_Aggregate then
29775 Extra := First (Expressions (Item));
29776 while Present (Extra) loop
29777 Collect_Dependency_Item (Extra, Is_Input);
29778 Next (Extra);
29779 end loop;
29780
29781 -- Otherwise this is a solitary item
29782
29783 else
29784 if Is_Input then
29785 Append_New_Elmt (Item, Subp_Inputs);
29786 else
29787 Append_New_Elmt (Item, Subp_Outputs);
29788 end if;
29789 end if;
29790 end Collect_Dependency_Item;
29791
29792 -- Start of processing for Collect_Dependency_Clause
29793
29794 begin
29795 if Nkind (Clause) = N_Null then
29796 null;
29797
29798 -- A dependency clause appears as component association
29799
29800 elsif Nkind (Clause) = N_Component_Association then
29801 Collect_Dependency_Item
29802 (Item => Expression (Clause),
29803 Is_Input => True);
29804
29805 Collect_Dependency_Item
29806 (Item => First (Choices (Clause)),
29807 Is_Input => False);
29808
29809 -- To accommodate partial decoration of disabled SPARK features, this
29810 -- routine may be called with illegal input. If this is the case, do
29811 -- not raise Program_Error.
29812
29813 else
29814 null;
29815 end if;
29816 end Collect_Dependency_Clause;
29817
29818 -------------------------
29819 -- Collect_Global_List --
29820 -------------------------
29821
29822 procedure Collect_Global_List
29823 (List : Node_Id;
29824 Mode : Name_Id := Name_Input)
29825 is
29826 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
29827 -- Add an item to the proper subprogram input or output collection
29828
29829 -------------------------
29830 -- Collect_Global_Item --
29831 -------------------------
29832
29833 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
29834 begin
29835 if Mode in Name_In_Out | Name_Input then
29836 Append_New_Elmt (Item, Subp_Inputs);
29837 end if;
29838
29839 if Mode in Name_In_Out | Name_Output then
29840 Append_New_Elmt (Item, Subp_Outputs);
29841 end if;
29842 end Collect_Global_Item;
29843
29844 -- Local variables
29845
29846 Assoc : Node_Id;
29847 Item : Node_Id;
29848
29849 -- Start of processing for Collect_Global_List
29850
29851 begin
29852 if Nkind (List) = N_Null then
29853 null;
29854
29855 -- Single global item declaration
29856
29857 elsif Nkind (List) in N_Expanded_Name
29858 | N_Identifier
29859 | N_Selected_Component
29860 then
29861 Collect_Global_Item (List, Mode);
29862
29863 -- Simple global list or moded global list declaration
29864
29865 elsif Nkind (List) = N_Aggregate then
29866 if Present (Expressions (List)) then
29867 Item := First (Expressions (List));
29868 while Present (Item) loop
29869 Collect_Global_Item (Item, Mode);
29870 Next (Item);
29871 end loop;
29872
29873 else
29874 Assoc := First (Component_Associations (List));
29875 while Present (Assoc) loop
29876 Collect_Global_List
29877 (List => Expression (Assoc),
29878 Mode => Chars (First (Choices (Assoc))));
29879 Next (Assoc);
29880 end loop;
29881 end if;
29882
29883 -- To accommodate partial decoration of disabled SPARK features, this
29884 -- routine may be called with illegal input. If this is the case, do
29885 -- not raise Program_Error.
29886
29887 else
29888 null;
29889 end if;
29890 end Collect_Global_List;
29891
29892 -- Local variables
29893
29894 Clause : Node_Id;
29895 Clauses : Node_Id;
29896 Depends : Node_Id;
29897 Formal : Entity_Id;
29898 Global : Node_Id;
29899 Spec_Id : Entity_Id := Empty;
29900 Subp_Decl : Node_Id;
29901 Typ : Entity_Id;
29902
29903 -- Start of processing for Collect_Subprogram_Inputs_Outputs
29904
29905 begin
29906 Global_Seen := False;
29907
29908 -- Process all formal parameters of entries, [generic] subprograms, and
29909 -- their bodies.
29910
29911 if Ekind (Subp_Id) in E_Entry
29912 | E_Entry_Family
29913 | E_Function
29914 | E_Generic_Function
29915 | E_Generic_Procedure
29916 | E_Procedure
29917 | E_Subprogram_Body
29918 then
29919 Subp_Decl := Unit_Declaration_Node (Subp_Id);
29920 Spec_Id := Unique_Defining_Entity (Subp_Decl);
29921
29922 -- Process all formal parameters
29923
29924 Formal := First_Entity (Spec_Id);
29925 while Present (Formal) loop
29926 if Ekind (Formal) in E_In_Out_Parameter | E_In_Parameter then
29927 Append_New_Elmt (Formal, Subp_Inputs);
29928 end if;
29929
29930 if Ekind (Formal) in E_In_Out_Parameter | E_Out_Parameter then
29931 Append_New_Elmt (Formal, Subp_Outputs);
29932
29933 -- Out parameters can act as inputs when the related type is
29934 -- tagged, unconstrained array, unconstrained record, or record
29935 -- with unconstrained components.
29936
29937 if Ekind (Formal) = E_Out_Parameter
29938 and then Is_Unconstrained_Or_Tagged_Item (Formal)
29939 then
29940 Append_New_Elmt (Formal, Subp_Inputs);
29941 end if;
29942 end if;
29943
29944 Next_Entity (Formal);
29945 end loop;
29946
29947 -- Otherwise the input denotes a task type, a task body, or the
29948 -- anonymous object created for a single task type.
29949
29950 elsif Ekind (Subp_Id) in E_Task_Type | E_Task_Body
29951 or else Is_Single_Task_Object (Subp_Id)
29952 then
29953 Subp_Decl := Declaration_Node (Subp_Id);
29954 Spec_Id := Unique_Defining_Entity (Subp_Decl);
29955 end if;
29956
29957 -- When processing an entry, subprogram or task body, look for pragmas
29958 -- Refined_Depends and Refined_Global as they specify the inputs and
29959 -- outputs.
29960
29961 if Is_Entry_Body (Subp_Id)
29962 or else Ekind (Subp_Id) in E_Subprogram_Body | E_Task_Body
29963 then
29964 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
29965 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
29966
29967 -- Subprogram declaration or stand-alone body case, look for pragmas
29968 -- Depends and Global
29969
29970 else
29971 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
29972 Global := Get_Pragma (Spec_Id, Pragma_Global);
29973 end if;
29974
29975 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
29976 -- because it provides finer granularity of inputs and outputs.
29977
29978 if Present (Global) then
29979 Global_Seen := True;
29980 Collect_Global_List (Expression (Get_Argument (Global, Spec_Id)));
29981
29982 -- When the related subprogram lacks pragma [Refined_]Global, fall back
29983 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
29984 -- the inputs and outputs from [Refined_]Depends.
29985
29986 elsif Synthesize and then Present (Depends) then
29987 Clauses := Expression (Get_Argument (Depends, Spec_Id));
29988
29989 -- Multiple dependency clauses appear as an aggregate
29990
29991 if Nkind (Clauses) = N_Aggregate then
29992 Clause := First (Component_Associations (Clauses));
29993 while Present (Clause) loop
29994 Collect_Dependency_Clause (Clause);
29995 Next (Clause);
29996 end loop;
29997
29998 -- Otherwise this is a single dependency clause
29999
30000 else
30001 Collect_Dependency_Clause (Clauses);
30002 end if;
30003 end if;
30004
30005 -- The current instance of a protected type acts as a formal parameter
30006 -- of mode IN for functions and IN OUT for entries and procedures
30007 -- (SPARK RM 6.1.4).
30008
30009 if Ekind (Scope (Spec_Id)) = E_Protected_Type then
30010 Typ := Scope (Spec_Id);
30011
30012 -- Use the anonymous object when the type is single protected
30013
30014 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
30015 Typ := Anonymous_Object (Typ);
30016 end if;
30017
30018 Append_New_Elmt (Typ, Subp_Inputs);
30019
30020 if Ekind (Spec_Id) in E_Entry | E_Entry_Family | E_Procedure then
30021 Append_New_Elmt (Typ, Subp_Outputs);
30022 end if;
30023
30024 -- The current instance of a task type acts as a formal parameter of
30025 -- mode IN OUT (SPARK RM 6.1.4).
30026
30027 elsif Ekind (Spec_Id) = E_Task_Type then
30028 Typ := Spec_Id;
30029
30030 -- Use the anonymous object when the type is single task
30031
30032 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
30033 Typ := Anonymous_Object (Typ);
30034 end if;
30035
30036 Append_New_Elmt (Typ, Subp_Inputs);
30037 Append_New_Elmt (Typ, Subp_Outputs);
30038
30039 elsif Is_Single_Task_Object (Spec_Id) then
30040 Append_New_Elmt (Spec_Id, Subp_Inputs);
30041 Append_New_Elmt (Spec_Id, Subp_Outputs);
30042 end if;
30043 end Collect_Subprogram_Inputs_Outputs;
30044
30045 ---------------------------
30046 -- Contract_Freeze_Error --
30047 ---------------------------
30048
30049 procedure Contract_Freeze_Error
30050 (Contract_Id : Entity_Id;
30051 Freeze_Id : Entity_Id)
30052 is
30053 begin
30054 Error_Msg_Name_1 := Chars (Contract_Id);
30055 Error_Msg_Sloc := Sloc (Freeze_Id);
30056
30057 SPARK_Msg_NE
30058 ("body & declared # freezes the contract of%", Contract_Id, Freeze_Id);
30059 SPARK_Msg_N
30060 ("\all contractual items must be declared before body #", Contract_Id);
30061 end Contract_Freeze_Error;
30062
30063 ---------------------------------
30064 -- Delay_Config_Pragma_Analyze --
30065 ---------------------------------
30066
30067 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
30068 begin
30069 return Pragma_Name_Unmapped (N)
30070 in Name_Interrupt_State | Name_Priority_Specific_Dispatching;
30071 end Delay_Config_Pragma_Analyze;
30072
30073 -----------------------
30074 -- Duplication_Error --
30075 -----------------------
30076
30077 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
30078 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
30079 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
30080
30081 begin
30082 Error_Msg_Sloc := Sloc (Prev);
30083 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
30084
30085 -- Emit a precise message to distinguish between source pragmas and
30086 -- pragmas generated from aspects. The ordering of the two pragmas is
30087 -- the following:
30088
30089 -- Prev -- ok
30090 -- Prag -- duplicate
30091
30092 -- No error is emitted when both pragmas come from aspects because this
30093 -- is already detected by the general aspect analysis mechanism.
30094
30095 if Prag_From_Asp and Prev_From_Asp then
30096 null;
30097 elsif Prag_From_Asp then
30098 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
30099 elsif Prev_From_Asp then
30100 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
30101 else
30102 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
30103 end if;
30104 end Duplication_Error;
30105
30106 ------------------------------
30107 -- Find_Encapsulating_State --
30108 ------------------------------
30109
30110 function Find_Encapsulating_State
30111 (States : Elist_Id;
30112 Constit_Id : Entity_Id) return Entity_Id
30113 is
30114 State_Id : Entity_Id;
30115
30116 begin
30117 -- Since a constituent may be part of a larger constituent set, climb
30118 -- the encapsulating state chain looking for a state that appears in
30119 -- States.
30120
30121 State_Id := Encapsulating_State (Constit_Id);
30122 while Present (State_Id) loop
30123 if Contains (States, State_Id) then
30124 return State_Id;
30125 end if;
30126
30127 State_Id := Encapsulating_State (State_Id);
30128 end loop;
30129
30130 return Empty;
30131 end Find_Encapsulating_State;
30132
30133 --------------------------
30134 -- Find_Related_Context --
30135 --------------------------
30136
30137 function Find_Related_Context
30138 (Prag : Node_Id;
30139 Do_Checks : Boolean := False) return Node_Id
30140 is
30141 Stmt : Node_Id;
30142
30143 begin
30144 Stmt := Prev (Prag);
30145 while Present (Stmt) loop
30146
30147 -- Skip prior pragmas, but check for duplicates
30148
30149 if Nkind (Stmt) = N_Pragma then
30150 if Do_Checks
30151 and then Pragma_Name (Stmt) = Pragma_Name (Prag)
30152 then
30153 Duplication_Error
30154 (Prag => Prag,
30155 Prev => Stmt);
30156 end if;
30157
30158 -- Skip internally generated code
30159
30160 elsif not Comes_From_Source (Stmt)
30161 and then not Comes_From_Source (Original_Node (Stmt))
30162 then
30163
30164 -- The anonymous object created for a single concurrent type is a
30165 -- suitable context.
30166
30167 if Nkind (Stmt) = N_Object_Declaration
30168 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
30169 then
30170 return Stmt;
30171 end if;
30172
30173 -- Return the current source construct
30174
30175 else
30176 return Stmt;
30177 end if;
30178
30179 Prev (Stmt);
30180 end loop;
30181
30182 return Empty;
30183 end Find_Related_Context;
30184
30185 --------------------------------------
30186 -- Find_Related_Declaration_Or_Body --
30187 --------------------------------------
30188
30189 function Find_Related_Declaration_Or_Body
30190 (Prag : Node_Id;
30191 Do_Checks : Boolean := False) return Node_Id
30192 is
30193 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
30194
30195 procedure Expression_Function_Error;
30196 -- Emit an error concerning pragma Prag that illegaly applies to an
30197 -- expression function.
30198
30199 -------------------------------
30200 -- Expression_Function_Error --
30201 -------------------------------
30202
30203 procedure Expression_Function_Error is
30204 begin
30205 Error_Msg_Name_1 := Prag_Nam;
30206
30207 -- Emit a precise message to distinguish between source pragmas and
30208 -- pragmas generated from aspects.
30209
30210 if From_Aspect_Specification (Prag) then
30211 Error_Msg_N
30212 ("aspect % cannot apply to a stand alone expression function",
30213 Prag);
30214 else
30215 Error_Msg_N
30216 ("pragma % cannot apply to a stand alone expression function",
30217 Prag);
30218 end if;
30219 end Expression_Function_Error;
30220
30221 -- Local variables
30222
30223 Context : constant Node_Id := Parent (Prag);
30224 Stmt : Node_Id;
30225
30226 Look_For_Body : constant Boolean :=
30227 Prag_Nam in Name_Refined_Depends
30228 | Name_Refined_Global
30229 | Name_Refined_Post
30230 | Name_Refined_State;
30231 -- Refinement pragmas must be associated with a subprogram body [stub]
30232
30233 -- Start of processing for Find_Related_Declaration_Or_Body
30234
30235 begin
30236 Stmt := Prev (Prag);
30237 while Present (Stmt) loop
30238
30239 -- Skip prior pragmas, but check for duplicates. Pragmas produced
30240 -- by splitting a complex pre/postcondition are not considered to
30241 -- be duplicates.
30242
30243 if Nkind (Stmt) = N_Pragma then
30244 if Do_Checks
30245 and then not Split_PPC (Stmt)
30246 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
30247 then
30248 Duplication_Error
30249 (Prag => Prag,
30250 Prev => Stmt);
30251 end if;
30252
30253 -- Emit an error when a refinement pragma appears on an expression
30254 -- function without a completion.
30255
30256 elsif Do_Checks
30257 and then Look_For_Body
30258 and then Nkind (Stmt) = N_Subprogram_Declaration
30259 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
30260 and then not Has_Completion (Defining_Entity (Stmt))
30261 then
30262 Expression_Function_Error;
30263 return Empty;
30264
30265 -- The refinement pragma applies to a subprogram body stub
30266
30267 elsif Look_For_Body
30268 and then Nkind (Stmt) = N_Subprogram_Body_Stub
30269 then
30270 return Stmt;
30271
30272 -- Skip internally generated code
30273
30274 elsif not Comes_From_Source (Stmt) then
30275
30276 -- The anonymous object created for a single concurrent type is a
30277 -- suitable context.
30278
30279 if Nkind (Stmt) = N_Object_Declaration
30280 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
30281 then
30282 return Stmt;
30283
30284 elsif Nkind (Stmt) = N_Subprogram_Declaration then
30285
30286 -- The subprogram declaration is an internally generated spec
30287 -- for an expression function.
30288
30289 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
30290 return Stmt;
30291
30292 -- The subprogram declaration is an internally generated spec
30293 -- for a stand-alone subrogram body declared inside a protected
30294 -- body.
30295
30296 elsif Present (Corresponding_Body (Stmt))
30297 and then Comes_From_Source (Corresponding_Body (Stmt))
30298 and then Is_Protected_Type (Current_Scope)
30299 then
30300 return Stmt;
30301
30302 -- The subprogram is actually an instance housed within an
30303 -- anonymous wrapper package.
30304
30305 elsif Present (Generic_Parent (Specification (Stmt))) then
30306 return Stmt;
30307
30308 -- Ada 2020: contract on formal subprogram or on generated
30309 -- Access_Subprogram_Wrapper, which appears after the related
30310 -- Access_Subprogram declaration.
30311
30312 elsif Is_Generic_Actual_Subprogram (Defining_Entity (Stmt))
30313 and then Ada_Version >= Ada_2020
30314 then
30315 return Stmt;
30316
30317 elsif Is_Access_Subprogram_Wrapper (Defining_Entity (Stmt))
30318 and then Ada_Version >= Ada_2020
30319 then
30320 return Stmt;
30321 end if;
30322 end if;
30323
30324 -- Return the current construct which is either a subprogram body,
30325 -- a subprogram declaration or is illegal.
30326
30327 else
30328 return Stmt;
30329 end if;
30330
30331 Prev (Stmt);
30332 end loop;
30333
30334 -- If we fall through, then the pragma was either the first declaration
30335 -- or it was preceded by other pragmas and no source constructs.
30336
30337 -- The pragma is associated with a library-level subprogram
30338
30339 if Nkind (Context) = N_Compilation_Unit_Aux then
30340 return Unit (Parent (Context));
30341
30342 -- The pragma appears inside the declarations of an entry body
30343
30344 elsif Nkind (Context) = N_Entry_Body then
30345 return Context;
30346
30347 -- The pragma appears inside the statements of a subprogram body. This
30348 -- placement is the result of subprogram contract expansion.
30349
30350 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
30351 return Parent (Context);
30352
30353 -- The pragma appears inside the declarative part of a package body
30354
30355 elsif Nkind (Context) = N_Package_Body then
30356 return Context;
30357
30358 -- The pragma appears inside the declarative part of a subprogram body
30359
30360 elsif Nkind (Context) = N_Subprogram_Body then
30361 return Context;
30362
30363 -- The pragma appears inside the declarative part of a task body
30364
30365 elsif Nkind (Context) = N_Task_Body then
30366 return Context;
30367
30368 -- The pragma appears inside the visible part of a package specification
30369
30370 elsif Nkind (Context) = N_Package_Specification then
30371 return Parent (Context);
30372
30373 -- The pragma is a byproduct of aspect expansion, return the related
30374 -- context of the original aspect. This case has a lower priority as
30375 -- the above circuitry pinpoints precisely the related context.
30376
30377 elsif Present (Corresponding_Aspect (Prag)) then
30378 return Parent (Corresponding_Aspect (Prag));
30379
30380 -- No candidate subprogram [body] found
30381
30382 else
30383 return Empty;
30384 end if;
30385 end Find_Related_Declaration_Or_Body;
30386
30387 ----------------------------------
30388 -- Find_Related_Package_Or_Body --
30389 ----------------------------------
30390
30391 function Find_Related_Package_Or_Body
30392 (Prag : Node_Id;
30393 Do_Checks : Boolean := False) return Node_Id
30394 is
30395 Context : constant Node_Id := Parent (Prag);
30396 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
30397 Stmt : Node_Id;
30398
30399 begin
30400 Stmt := Prev (Prag);
30401 while Present (Stmt) loop
30402
30403 -- Skip prior pragmas, but check for duplicates
30404
30405 if Nkind (Stmt) = N_Pragma then
30406 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
30407 Duplication_Error
30408 (Prag => Prag,
30409 Prev => Stmt);
30410 end if;
30411
30412 -- Skip internally generated code
30413
30414 elsif not Comes_From_Source (Stmt) then
30415 if Nkind (Stmt) = N_Subprogram_Declaration then
30416
30417 -- The subprogram declaration is an internally generated spec
30418 -- for an expression function.
30419
30420 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
30421 return Stmt;
30422
30423 -- The subprogram is actually an instance housed within an
30424 -- anonymous wrapper package.
30425
30426 elsif Present (Generic_Parent (Specification (Stmt))) then
30427 return Stmt;
30428 end if;
30429 end if;
30430
30431 -- Return the current source construct which is illegal
30432
30433 else
30434 return Stmt;
30435 end if;
30436
30437 Prev (Stmt);
30438 end loop;
30439
30440 -- If we fall through, then the pragma was either the first declaration
30441 -- or it was preceded by other pragmas and no source constructs.
30442
30443 -- The pragma is associated with a package. The immediate context in
30444 -- this case is the specification of the package.
30445
30446 if Nkind (Context) = N_Package_Specification then
30447 return Parent (Context);
30448
30449 -- The pragma appears in the declarations of a package body
30450
30451 elsif Nkind (Context) = N_Package_Body then
30452 return Context;
30453
30454 -- The pragma appears in the statements of a package body
30455
30456 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
30457 and then Nkind (Parent (Context)) = N_Package_Body
30458 then
30459 return Parent (Context);
30460
30461 -- The pragma is a byproduct of aspect expansion, return the related
30462 -- context of the original aspect. This case has a lower priority as
30463 -- the above circuitry pinpoints precisely the related context.
30464
30465 elsif Present (Corresponding_Aspect (Prag)) then
30466 return Parent (Corresponding_Aspect (Prag));
30467
30468 -- No candidate package [body] found
30469
30470 else
30471 return Empty;
30472 end if;
30473 end Find_Related_Package_Or_Body;
30474
30475 ------------------
30476 -- Get_Argument --
30477 ------------------
30478
30479 function Get_Argument
30480 (Prag : Node_Id;
30481 Context_Id : Entity_Id := Empty) return Node_Id
30482 is
30483 Args : constant List_Id := Pragma_Argument_Associations (Prag);
30484
30485 begin
30486 -- Use the expression of the original aspect when analyzing the template
30487 -- of a generic unit. In both cases the aspect's tree must be decorated
30488 -- to save the global references in the generic context.
30489
30490 if From_Aspect_Specification (Prag)
30491 and then (Present (Context_Id) and then Is_Generic_Unit (Context_Id))
30492 then
30493 return Corresponding_Aspect (Prag);
30494
30495 -- Otherwise use the expression of the pragma
30496
30497 elsif Present (Args) then
30498 return First (Args);
30499
30500 else
30501 return Empty;
30502 end if;
30503 end Get_Argument;
30504
30505 -------------------------
30506 -- Get_Base_Subprogram --
30507 -------------------------
30508
30509 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
30510 begin
30511 -- Follow subprogram renaming chain
30512
30513 if Is_Subprogram (Def_Id)
30514 and then Nkind (Parent (Declaration_Node (Def_Id))) =
30515 N_Subprogram_Renaming_Declaration
30516 and then Present (Alias (Def_Id))
30517 then
30518 return Alias (Def_Id);
30519 else
30520 return Def_Id;
30521 end if;
30522 end Get_Base_Subprogram;
30523
30524 -----------------------
30525 -- Get_SPARK_Mode_Type --
30526 -----------------------
30527
30528 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
30529 begin
30530 if N = Name_On then
30531 return On;
30532 elsif N = Name_Off then
30533 return Off;
30534
30535 -- Any other argument is illegal. Assume that no SPARK mode applies to
30536 -- avoid potential cascaded errors.
30537
30538 else
30539 return None;
30540 end if;
30541 end Get_SPARK_Mode_Type;
30542
30543 ------------------------------------
30544 -- Get_SPARK_Mode_From_Annotation --
30545 ------------------------------------
30546
30547 function Get_SPARK_Mode_From_Annotation
30548 (N : Node_Id) return SPARK_Mode_Type
30549 is
30550 Mode : Node_Id;
30551
30552 begin
30553 if Nkind (N) = N_Aspect_Specification then
30554 Mode := Expression (N);
30555
30556 else pragma Assert (Nkind (N) = N_Pragma);
30557 Mode := First (Pragma_Argument_Associations (N));
30558
30559 if Present (Mode) then
30560 Mode := Get_Pragma_Arg (Mode);
30561 end if;
30562 end if;
30563
30564 -- Aspect or pragma SPARK_Mode specifies an explicit mode
30565
30566 if Present (Mode) then
30567 if Nkind (Mode) = N_Identifier then
30568 return Get_SPARK_Mode_Type (Chars (Mode));
30569
30570 -- In case of a malformed aspect or pragma, return the default None
30571
30572 else
30573 return None;
30574 end if;
30575
30576 -- Otherwise the lack of an expression defaults SPARK_Mode to On
30577
30578 else
30579 return On;
30580 end if;
30581 end Get_SPARK_Mode_From_Annotation;
30582
30583 ---------------------------
30584 -- Has_Extra_Parentheses --
30585 ---------------------------
30586
30587 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
30588 Expr : Node_Id;
30589
30590 begin
30591 -- The aggregate should not have an expression list because a clause
30592 -- is always interpreted as a component association. The only way an
30593 -- expression list can sneak in is by adding extra parentheses around
30594 -- the individual clauses:
30595
30596 -- Depends (Output => Input) -- proper form
30597 -- Depends ((Output => Input)) -- extra parentheses
30598
30599 -- Since the extra parentheses are not allowed by the syntax of the
30600 -- pragma, flag them now to avoid emitting misleading errors down the
30601 -- line.
30602
30603 if Nkind (Clause) = N_Aggregate
30604 and then Present (Expressions (Clause))
30605 then
30606 Expr := First (Expressions (Clause));
30607 while Present (Expr) loop
30608
30609 -- A dependency clause surrounded by extra parentheses appears
30610 -- as an aggregate of component associations with an optional
30611 -- Paren_Count set.
30612
30613 if Nkind (Expr) = N_Aggregate
30614 and then Present (Component_Associations (Expr))
30615 then
30616 SPARK_Msg_N
30617 ("dependency clause contains extra parentheses", Expr);
30618
30619 -- Otherwise the expression is a malformed construct
30620
30621 else
30622 SPARK_Msg_N ("malformed dependency clause", Expr);
30623 end if;
30624
30625 Next (Expr);
30626 end loop;
30627
30628 return True;
30629 end if;
30630
30631 return False;
30632 end Has_Extra_Parentheses;
30633
30634 ----------------
30635 -- Initialize --
30636 ----------------
30637
30638 procedure Initialize is
30639 begin
30640 Externals.Init;
30641 Compile_Time_Warnings_Errors.Init;
30642 end Initialize;
30643
30644 --------
30645 -- ip --
30646 --------
30647
30648 procedure ip is
30649 begin
30650 Dummy := Dummy + 1;
30651 end ip;
30652
30653 -----------------------------
30654 -- Is_Config_Static_String --
30655 -----------------------------
30656
30657 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
30658
30659 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
30660 -- This is an internal recursive function that is just like the outer
30661 -- function except that it adds the string to the name buffer rather
30662 -- than placing the string in the name buffer.
30663
30664 ------------------------------
30665 -- Add_Config_Static_String --
30666 ------------------------------
30667
30668 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
30669 N : Node_Id;
30670 C : Char_Code;
30671
30672 begin
30673 N := Arg;
30674
30675 if Nkind (N) = N_Op_Concat then
30676 if Add_Config_Static_String (Left_Opnd (N)) then
30677 N := Right_Opnd (N);
30678 else
30679 return False;
30680 end if;
30681 end if;
30682
30683 if Nkind (N) /= N_String_Literal then
30684 Error_Msg_N ("string literal expected for pragma argument", N);
30685 return False;
30686
30687 else
30688 for J in 1 .. String_Length (Strval (N)) loop
30689 C := Get_String_Char (Strval (N), J);
30690
30691 if not In_Character_Range (C) then
30692 Error_Msg
30693 ("string literal contains invalid wide character",
30694 Sloc (N) + 1 + Source_Ptr (J));
30695 return False;
30696 end if;
30697
30698 Add_Char_To_Name_Buffer (Get_Character (C));
30699 end loop;
30700 end if;
30701
30702 return True;
30703 end Add_Config_Static_String;
30704
30705 -- Start of processing for Is_Config_Static_String
30706
30707 begin
30708 Name_Len := 0;
30709
30710 return Add_Config_Static_String (Arg);
30711 end Is_Config_Static_String;
30712
30713 -------------------------------
30714 -- Is_Elaboration_SPARK_Mode --
30715 -------------------------------
30716
30717 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
30718 begin
30719 pragma Assert
30720 (Nkind (N) = N_Pragma
30721 and then Pragma_Name (N) = Name_SPARK_Mode
30722 and then Is_List_Member (N));
30723
30724 -- Pragma SPARK_Mode affects the elaboration of a package body when it
30725 -- appears in the statement part of the body.
30726
30727 return
30728 Present (Parent (N))
30729 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
30730 and then List_Containing (N) = Statements (Parent (N))
30731 and then Present (Parent (Parent (N)))
30732 and then Nkind (Parent (Parent (N))) = N_Package_Body;
30733 end Is_Elaboration_SPARK_Mode;
30734
30735 -----------------------
30736 -- Is_Enabled_Pragma --
30737 -----------------------
30738
30739 function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is
30740 Arg : Node_Id;
30741
30742 begin
30743 if Present (Prag) then
30744 Arg := First (Pragma_Argument_Associations (Prag));
30745
30746 if Present (Arg) then
30747 return Is_True (Expr_Value (Get_Pragma_Arg (Arg)));
30748
30749 -- The lack of a Boolean argument automatically enables the pragma
30750
30751 else
30752 return True;
30753 end if;
30754
30755 -- The pragma is missing, therefore it is not enabled
30756
30757 else
30758 return False;
30759 end if;
30760 end Is_Enabled_Pragma;
30761
30762 -----------------------------------------
30763 -- Is_Non_Significant_Pragma_Reference --
30764 -----------------------------------------
30765
30766 -- This function makes use of the following static table which indicates
30767 -- whether appearance of some name in a given pragma is to be considered
30768 -- as a reference for the purposes of warnings about unreferenced objects.
30769
30770 -- -1 indicates that appearence in any argument is significant
30771 -- 0 indicates that appearance in any argument is not significant
30772 -- +n indicates that appearance as argument n is significant, but all
30773 -- other arguments are not significant
30774 -- 9n arguments from n on are significant, before n insignificant
30775
30776 Sig_Flags : constant array (Pragma_Id) of Int :=
30777 (Pragma_Abort_Defer => -1,
30778 Pragma_Abstract_State => -1,
30779 Pragma_Ada_83 => -1,
30780 Pragma_Ada_95 => -1,
30781 Pragma_Ada_05 => -1,
30782 Pragma_Ada_2005 => -1,
30783 Pragma_Ada_12 => -1,
30784 Pragma_Ada_2012 => -1,
30785 Pragma_Ada_2020 => -1,
30786 Pragma_Aggregate_Individually_Assign => 0,
30787 Pragma_All_Calls_Remote => -1,
30788 Pragma_Allow_Integer_Address => -1,
30789 Pragma_Annotate => 93,
30790 Pragma_Assert => -1,
30791 Pragma_Assert_And_Cut => -1,
30792 Pragma_Assertion_Policy => 0,
30793 Pragma_Assume => -1,
30794 Pragma_Assume_No_Invalid_Values => 0,
30795 Pragma_Async_Readers => 0,
30796 Pragma_Async_Writers => 0,
30797 Pragma_Asynchronous => 0,
30798 Pragma_Atomic => 0,
30799 Pragma_Atomic_Components => 0,
30800 Pragma_Attach_Handler => -1,
30801 Pragma_Attribute_Definition => 92,
30802 Pragma_Check => -1,
30803 Pragma_Check_Float_Overflow => 0,
30804 Pragma_Check_Name => 0,
30805 Pragma_Check_Policy => 0,
30806 Pragma_CPP_Class => 0,
30807 Pragma_CPP_Constructor => 0,
30808 Pragma_CPP_Virtual => 0,
30809 Pragma_CPP_Vtable => 0,
30810 Pragma_CPU => -1,
30811 Pragma_C_Pass_By_Copy => 0,
30812 Pragma_Comment => -1,
30813 Pragma_Common_Object => 0,
30814 Pragma_CUDA_Execute => -1,
30815 Pragma_CUDA_Global => -1,
30816 Pragma_Compile_Time_Error => -1,
30817 Pragma_Compile_Time_Warning => -1,
30818 Pragma_Compiler_Unit => -1,
30819 Pragma_Compiler_Unit_Warning => -1,
30820 Pragma_Complete_Representation => 0,
30821 Pragma_Complex_Representation => 0,
30822 Pragma_Component_Alignment => 0,
30823 Pragma_Constant_After_Elaboration => 0,
30824 Pragma_Contract_Cases => -1,
30825 Pragma_Controlled => 0,
30826 Pragma_Convention => 0,
30827 Pragma_Convention_Identifier => 0,
30828 Pragma_Deadline_Floor => -1,
30829 Pragma_Debug => -1,
30830 Pragma_Debug_Policy => 0,
30831 Pragma_Default_Initial_Condition => -1,
30832 Pragma_Default_Scalar_Storage_Order => 0,
30833 Pragma_Default_Storage_Pool => 0,
30834 Pragma_Depends => -1,
30835 Pragma_Detect_Blocking => 0,
30836 Pragma_Disable_Atomic_Synchronization => 0,
30837 Pragma_Discard_Names => 0,
30838 Pragma_Dispatching_Domain => -1,
30839 Pragma_Effective_Reads => 0,
30840 Pragma_Effective_Writes => 0,
30841 Pragma_Elaborate => 0,
30842 Pragma_Elaborate_All => 0,
30843 Pragma_Elaborate_Body => 0,
30844 Pragma_Elaboration_Checks => 0,
30845 Pragma_Eliminate => 0,
30846 Pragma_Enable_Atomic_Synchronization => 0,
30847 Pragma_Export => -1,
30848 Pragma_Export_Function => -1,
30849 Pragma_Export_Object => -1,
30850 Pragma_Export_Procedure => -1,
30851 Pragma_Export_Value => -1,
30852 Pragma_Export_Valued_Procedure => -1,
30853 Pragma_Extend_System => -1,
30854 Pragma_Extensions_Allowed => 0,
30855 Pragma_Extensions_Visible => 0,
30856 Pragma_External => -1,
30857 Pragma_External_Name_Casing => 0,
30858 Pragma_Fast_Math => 0,
30859 Pragma_Favor_Top_Level => 0,
30860 Pragma_Finalize_Storage_Only => 0,
30861 Pragma_Ghost => 0,
30862 Pragma_Global => -1,
30863 Pragma_Ident => -1,
30864 Pragma_Ignore_Pragma => 0,
30865 Pragma_Implementation_Defined => -1,
30866 Pragma_Implemented => -1,
30867 Pragma_Implicit_Packing => 0,
30868 Pragma_Import => 93,
30869 Pragma_Import_Function => 0,
30870 Pragma_Import_Object => 0,
30871 Pragma_Import_Procedure => 0,
30872 Pragma_Import_Valued_Procedure => 0,
30873 Pragma_Independent => 0,
30874 Pragma_Independent_Components => 0,
30875 Pragma_Initial_Condition => -1,
30876 Pragma_Initialize_Scalars => 0,
30877 Pragma_Initializes => -1,
30878 Pragma_Inline => 0,
30879 Pragma_Inline_Always => 0,
30880 Pragma_Inline_Generic => 0,
30881 Pragma_Inspection_Point => -1,
30882 Pragma_Interface => 92,
30883 Pragma_Interface_Name => 0,
30884 Pragma_Interrupt_Handler => -1,
30885 Pragma_Interrupt_Priority => -1,
30886 Pragma_Interrupt_State => -1,
30887 Pragma_Invariant => -1,
30888 Pragma_Keep_Names => 0,
30889 Pragma_License => 0,
30890 Pragma_Link_With => -1,
30891 Pragma_Linker_Alias => -1,
30892 Pragma_Linker_Constructor => -1,
30893 Pragma_Linker_Destructor => -1,
30894 Pragma_Linker_Options => -1,
30895 Pragma_Linker_Section => -1,
30896 Pragma_List => 0,
30897 Pragma_Lock_Free => 0,
30898 Pragma_Locking_Policy => 0,
30899 Pragma_Loop_Invariant => -1,
30900 Pragma_Loop_Optimize => 0,
30901 Pragma_Loop_Variant => -1,
30902 Pragma_Machine_Attribute => -1,
30903 Pragma_Main => -1,
30904 Pragma_Main_Storage => -1,
30905 Pragma_Max_Entry_Queue_Depth => 0,
30906 Pragma_Max_Entry_Queue_Length => 0,
30907 Pragma_Max_Queue_Length => 0,
30908 Pragma_Memory_Size => 0,
30909 Pragma_No_Body => 0,
30910 Pragma_No_Caching => 0,
30911 Pragma_No_Component_Reordering => -1,
30912 Pragma_No_Elaboration_Code_All => 0,
30913 Pragma_No_Heap_Finalization => 0,
30914 Pragma_No_Inline => 0,
30915 Pragma_No_Return => 0,
30916 Pragma_No_Run_Time => -1,
30917 Pragma_No_Strict_Aliasing => -1,
30918 Pragma_No_Tagged_Streams => 0,
30919 Pragma_Normalize_Scalars => 0,
30920 Pragma_Obsolescent => 0,
30921 Pragma_Optimize => 0,
30922 Pragma_Optimize_Alignment => 0,
30923 Pragma_Ordered => 0,
30924 Pragma_Overflow_Mode => 0,
30925 Pragma_Overriding_Renamings => 0,
30926 Pragma_Pack => 0,
30927 Pragma_Page => 0,
30928 Pragma_Part_Of => 0,
30929 Pragma_Partition_Elaboration_Policy => 0,
30930 Pragma_Passive => 0,
30931 Pragma_Persistent_BSS => 0,
30932 Pragma_Post => -1,
30933 Pragma_Postcondition => -1,
30934 Pragma_Post_Class => -1,
30935 Pragma_Pre => -1,
30936 Pragma_Precondition => -1,
30937 Pragma_Predicate => -1,
30938 Pragma_Predicate_Failure => -1,
30939 Pragma_Preelaborable_Initialization => -1,
30940 Pragma_Preelaborate => 0,
30941 Pragma_Prefix_Exception_Messages => 0,
30942 Pragma_Pre_Class => -1,
30943 Pragma_Priority => -1,
30944 Pragma_Priority_Specific_Dispatching => 0,
30945 Pragma_Profile => 0,
30946 Pragma_Profile_Warnings => 0,
30947 Pragma_Propagate_Exceptions => 0,
30948 Pragma_Provide_Shift_Operators => 0,
30949 Pragma_Psect_Object => 0,
30950 Pragma_Pure => 0,
30951 Pragma_Pure_Function => 0,
30952 Pragma_Queuing_Policy => 0,
30953 Pragma_Rational => 0,
30954 Pragma_Ravenscar => 0,
30955 Pragma_Refined_Depends => -1,
30956 Pragma_Refined_Global => -1,
30957 Pragma_Refined_Post => -1,
30958 Pragma_Refined_State => -1,
30959 Pragma_Relative_Deadline => 0,
30960 Pragma_Remote_Access_Type => -1,
30961 Pragma_Remote_Call_Interface => -1,
30962 Pragma_Remote_Types => -1,
30963 Pragma_Rename_Pragma => 0,
30964 Pragma_Restricted_Run_Time => 0,
30965 Pragma_Restriction_Warnings => 0,
30966 Pragma_Restrictions => 0,
30967 Pragma_Reviewable => -1,
30968 Pragma_Secondary_Stack_Size => -1,
30969 Pragma_Share_Generic => 0,
30970 Pragma_Shared => 0,
30971 Pragma_Shared_Passive => 0,
30972 Pragma_Short_Circuit_And_Or => 0,
30973 Pragma_Short_Descriptors => 0,
30974 Pragma_Simple_Storage_Pool_Type => 0,
30975 Pragma_Source_File_Name => 0,
30976 Pragma_Source_File_Name_Project => 0,
30977 Pragma_Source_Reference => 0,
30978 Pragma_SPARK_Mode => 0,
30979 Pragma_Static_Elaboration_Desired => 0,
30980 Pragma_Storage_Size => -1,
30981 Pragma_Storage_Unit => 0,
30982 Pragma_Stream_Convert => 0,
30983 Pragma_Style_Checks => 0,
30984 Pragma_Subtitle => 0,
30985 Pragma_Suppress => 0,
30986 Pragma_Suppress_All => 0,
30987 Pragma_Suppress_Debug_Info => 0,
30988 Pragma_Suppress_Exception_Locations => 0,
30989 Pragma_Suppress_Initialization => 0,
30990 Pragma_System_Name => 0,
30991 Pragma_Task_Dispatching_Policy => 0,
30992 Pragma_Task_Info => -1,
30993 Pragma_Task_Name => -1,
30994 Pragma_Task_Storage => -1,
30995 Pragma_Test_Case => -1,
30996 Pragma_Thread_Local_Storage => -1,
30997 Pragma_Time_Slice => -1,
30998 Pragma_Title => 0,
30999 Pragma_Type_Invariant => -1,
31000 Pragma_Type_Invariant_Class => -1,
31001 Pragma_Unchecked_Union => 0,
31002 Pragma_Unevaluated_Use_Of_Old => 0,
31003 Pragma_Unimplemented_Unit => 0,
31004 Pragma_Universal_Aliasing => 0,
31005 Pragma_Universal_Data => 0,
31006 Pragma_Unmodified => 0,
31007 Pragma_Unreferenced => 0,
31008 Pragma_Unreferenced_Objects => 0,
31009 Pragma_Unreserve_All_Interrupts => 0,
31010 Pragma_Unsuppress => 0,
31011 Pragma_Unused => 0,
31012 Pragma_Use_VADS_Size => 0,
31013 Pragma_Validity_Checks => 0,
31014 Pragma_Volatile => 0,
31015 Pragma_Volatile_Components => 0,
31016 Pragma_Volatile_Full_Access => 0,
31017 Pragma_Volatile_Function => 0,
31018 Pragma_Warning_As_Error => 0,
31019 Pragma_Warnings => 0,
31020 Pragma_Weak_External => 0,
31021 Pragma_Wide_Character_Encoding => 0,
31022 Unknown_Pragma => 0);
31023
31024 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
31025 Id : Pragma_Id;
31026 P : Node_Id;
31027 C : Int;
31028 AN : Nat;
31029
31030 function Arg_No return Nat;
31031 -- Returns an integer showing what argument we are in. A value of
31032 -- zero means we are not in any of the arguments.
31033
31034 ------------
31035 -- Arg_No --
31036 ------------
31037
31038 function Arg_No return Nat is
31039 A : Node_Id;
31040 N : Nat;
31041
31042 begin
31043 A := First (Pragma_Argument_Associations (Parent (P)));
31044 N := 1;
31045 loop
31046 if No (A) then
31047 return 0;
31048 elsif A = P then
31049 return N;
31050 end if;
31051
31052 Next (A);
31053 N := N + 1;
31054 end loop;
31055 end Arg_No;
31056
31057 -- Start of processing for Non_Significant_Pragma_Reference
31058
31059 begin
31060 P := Parent (N);
31061
31062 if Nkind (P) /= N_Pragma_Argument_Association then
31063 return False;
31064
31065 else
31066 Id := Get_Pragma_Id (Parent (P));
31067 C := Sig_Flags (Id);
31068 AN := Arg_No;
31069
31070 if AN = 0 then
31071 return False;
31072 end if;
31073
31074 case C is
31075 when -1 =>
31076 return False;
31077
31078 when 0 =>
31079 return True;
31080
31081 when 92 .. 99 =>
31082 return AN < (C - 90);
31083
31084 when others =>
31085 return AN /= C;
31086 end case;
31087 end if;
31088 end Is_Non_Significant_Pragma_Reference;
31089
31090 ------------------------------
31091 -- Is_Pragma_String_Literal --
31092 ------------------------------
31093
31094 -- This function returns true if the corresponding pragma argument is a
31095 -- static string expression. These are the only cases in which string
31096 -- literals can appear as pragma arguments. We also allow a string literal
31097 -- as the first argument to pragma Assert (although it will of course
31098 -- always generate a type error).
31099
31100 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
31101 Pragn : constant Node_Id := Parent (Par);
31102 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
31103 Pname : constant Name_Id := Pragma_Name (Pragn);
31104 Argn : Natural;
31105 N : Node_Id;
31106
31107 begin
31108 Argn := 1;
31109 N := First (Assoc);
31110 loop
31111 exit when N = Par;
31112 Argn := Argn + 1;
31113 Next (N);
31114 end loop;
31115
31116 if Pname = Name_Assert then
31117 return True;
31118
31119 elsif Pname = Name_Export then
31120 return Argn > 2;
31121
31122 elsif Pname = Name_Ident then
31123 return Argn = 1;
31124
31125 elsif Pname = Name_Import then
31126 return Argn > 2;
31127
31128 elsif Pname = Name_Interface_Name then
31129 return Argn > 1;
31130
31131 elsif Pname = Name_Linker_Alias then
31132 return Argn = 2;
31133
31134 elsif Pname = Name_Linker_Section then
31135 return Argn = 2;
31136
31137 elsif Pname = Name_Machine_Attribute then
31138 return Argn = 2;
31139
31140 elsif Pname = Name_Source_File_Name then
31141 return True;
31142
31143 elsif Pname = Name_Source_Reference then
31144 return Argn = 2;
31145
31146 elsif Pname = Name_Title then
31147 return True;
31148
31149 elsif Pname = Name_Subtitle then
31150 return True;
31151
31152 else
31153 return False;
31154 end if;
31155 end Is_Pragma_String_Literal;
31156
31157 ---------------------------
31158 -- Is_Private_SPARK_Mode --
31159 ---------------------------
31160
31161 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
31162 begin
31163 pragma Assert
31164 (Nkind (N) = N_Pragma
31165 and then Pragma_Name (N) = Name_SPARK_Mode
31166 and then Is_List_Member (N));
31167
31168 -- For pragma SPARK_Mode to be private, it has to appear in the private
31169 -- declarations of a package.
31170
31171 return
31172 Present (Parent (N))
31173 and then Nkind (Parent (N)) = N_Package_Specification
31174 and then List_Containing (N) = Private_Declarations (Parent (N));
31175 end Is_Private_SPARK_Mode;
31176
31177 -------------------------------------
31178 -- Is_Unconstrained_Or_Tagged_Item --
31179 -------------------------------------
31180
31181 function Is_Unconstrained_Or_Tagged_Item
31182 (Item : Entity_Id) return Boolean
31183 is
31184 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
31185 -- Determine whether record type Typ has at least one unconstrained
31186 -- component.
31187
31188 ---------------------------------
31189 -- Has_Unconstrained_Component --
31190 ---------------------------------
31191
31192 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
31193 Comp : Entity_Id;
31194
31195 begin
31196 Comp := First_Component (Typ);
31197 while Present (Comp) loop
31198 if Is_Unconstrained_Or_Tagged_Item (Comp) then
31199 return True;
31200 end if;
31201
31202 Next_Component (Comp);
31203 end loop;
31204
31205 return False;
31206 end Has_Unconstrained_Component;
31207
31208 -- Local variables
31209
31210 Typ : constant Entity_Id := Etype (Item);
31211
31212 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
31213
31214 begin
31215 if Is_Tagged_Type (Typ) then
31216 return True;
31217
31218 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
31219 return True;
31220
31221 elsif Is_Record_Type (Typ) then
31222 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
31223 return True;
31224 else
31225 return Has_Unconstrained_Component (Typ);
31226 end if;
31227
31228 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
31229 return True;
31230
31231 else
31232 return False;
31233 end if;
31234 end Is_Unconstrained_Or_Tagged_Item;
31235
31236 -----------------------------
31237 -- Is_Valid_Assertion_Kind --
31238 -----------------------------
31239
31240 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
31241 begin
31242 case Nam is
31243 when
31244 -- RM defined
31245
31246 Name_Assert
31247 | Name_Assertion_Policy
31248 | Name_Static_Predicate
31249 | Name_Dynamic_Predicate
31250 | Name_Pre
31251 | Name_uPre
31252 | Name_Post
31253 | Name_uPost
31254 | Name_Type_Invariant
31255 | Name_uType_Invariant
31256
31257 -- Impl defined
31258
31259 | Name_Assert_And_Cut
31260 | Name_Assume
31261 | Name_Contract_Cases
31262 | Name_Debug
31263 | Name_Default_Initial_Condition
31264 | Name_Ghost
31265 | Name_Initial_Condition
31266 | Name_Invariant
31267 | Name_uInvariant
31268 | Name_Loop_Invariant
31269 | Name_Loop_Variant
31270 | Name_Postcondition
31271 | Name_Precondition
31272 | Name_Predicate
31273 | Name_Refined_Post
31274 | Name_Statement_Assertions
31275 =>
31276 return True;
31277
31278 when others =>
31279 return False;
31280 end case;
31281 end Is_Valid_Assertion_Kind;
31282
31283 --------------------------------------
31284 -- Process_Compilation_Unit_Pragmas --
31285 --------------------------------------
31286
31287 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
31288 begin
31289 -- A special check for pragma Suppress_All, a very strange DEC pragma,
31290 -- strange because it comes at the end of the unit. Rational has the
31291 -- same name for a pragma, but treats it as a program unit pragma, In
31292 -- GNAT we just decide to allow it anywhere at all. If it appeared then
31293 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
31294 -- node, and we insert a pragma Suppress (All_Checks) at the start of
31295 -- the context clause to ensure the correct processing.
31296
31297 if Has_Pragma_Suppress_All (N) then
31298 Prepend_To (Context_Items (N),
31299 Make_Pragma (Sloc (N),
31300 Chars => Name_Suppress,
31301 Pragma_Argument_Associations => New_List (
31302 Make_Pragma_Argument_Association (Sloc (N),
31303 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
31304 end if;
31305
31306 -- Nothing else to do at the current time
31307
31308 end Process_Compilation_Unit_Pragmas;
31309
31310 --------------------------------------------
31311 -- Validate_Compile_Time_Warning_Or_Error --
31312 --------------------------------------------
31313
31314 procedure Validate_Compile_Time_Warning_Or_Error
31315 (N : Node_Id;
31316 Eloc : Source_Ptr)
31317 is
31318 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
31319 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
31320 Arg2 : constant Node_Id := Next (Arg1);
31321
31322 Pname : constant Name_Id := Pragma_Name_Unmapped (N);
31323 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
31324
31325 begin
31326 Analyze_And_Resolve (Arg1x, Standard_Boolean);
31327
31328 if Compile_Time_Known_Value (Arg1x) then
31329 if Is_True (Expr_Value (Arg1x)) then
31330
31331 -- We have already verified that the second argument is a static
31332 -- string expression. Its string value must be retrieved
31333 -- explicitly if it is a declared constant, otherwise it has
31334 -- been constant-folded previously.
31335
31336 declare
31337 Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
31338 Str : constant String_Id :=
31339 Strval (Expr_Value_S (Get_Pragma_Arg (Arg2)));
31340 Str_Len : constant Nat := String_Length (Str);
31341
31342 Force : constant Boolean :=
31343 Prag_Id = Pragma_Compile_Time_Warning
31344 and then Is_Spec_Name (Unit_Name (Current_Sem_Unit))
31345 and then (Ekind (Cent) /= E_Package
31346 or else not In_Private_Part (Cent));
31347 -- Set True if this is the warning case, and we are in the
31348 -- visible part of a package spec, or in a subprogram spec,
31349 -- in which case we want to force the client to see the
31350 -- warning, even though it is not in the main unit.
31351
31352 C : Character;
31353 CC : Char_Code;
31354 Cont : Boolean;
31355 Ptr : Nat;
31356
31357 begin
31358 -- Loop through segments of message separated by line feeds.
31359 -- We output these segments as separate messages with
31360 -- continuation marks for all but the first.
31361
31362 Cont := False;
31363 Ptr := 1;
31364 loop
31365 Error_Msg_Strlen := 0;
31366
31367 -- Loop to copy characters from argument to error message
31368 -- string buffer.
31369
31370 loop
31371 exit when Ptr > Str_Len;
31372 CC := Get_String_Char (Str, Ptr);
31373 Ptr := Ptr + 1;
31374
31375 -- Ignore wide chars ??? else store character
31376
31377 if In_Character_Range (CC) then
31378 C := Get_Character (CC);
31379 exit when C = ASCII.LF;
31380 Error_Msg_Strlen := Error_Msg_Strlen + 1;
31381 Error_Msg_String (Error_Msg_Strlen) := C;
31382 end if;
31383 end loop;
31384
31385 -- Here with one line ready to go
31386
31387 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
31388
31389 -- If this is a warning in a spec, then we want clients
31390 -- to see the warning, so mark the message with the
31391 -- special sequence !! to force the warning. In the case
31392 -- of a package spec, we do not force this if we are in
31393 -- the private part of the spec.
31394
31395 if Force then
31396 if Cont = False then
31397 Error_Msg
31398 ("<<~!!", Eloc, Is_Compile_Time_Pragma => True);
31399 Cont := True;
31400 else
31401 Error_Msg
31402 ("\<<~!!", Eloc, Is_Compile_Time_Pragma => True);
31403 end if;
31404
31405 -- Error, rather than warning, or in a body, so we do not
31406 -- need to force visibility for client (error will be
31407 -- output in any case, and this is the situation in which
31408 -- we do not want a client to get a warning, since the
31409 -- warning is in the body or the spec private part).
31410
31411 else
31412 if Cont = False then
31413 Error_Msg
31414 ("<<~", Eloc, Is_Compile_Time_Pragma => True);
31415 Cont := True;
31416 else
31417 Error_Msg
31418 ("\<<~", Eloc, Is_Compile_Time_Pragma => True);
31419 end if;
31420 end if;
31421
31422 exit when Ptr > Str_Len;
31423 end loop;
31424 end;
31425 end if;
31426
31427 -- Arg1x is not known at compile time, so possibly issue an error
31428 -- or warning. This can happen only if the pragma's processing
31429 -- was deferred until after the back end is run (see
31430 -- Process_Compile_Time_Warning_Or_Error). Note that the warning
31431 -- control switch applies to only the warning case.
31432
31433 elsif Prag_Id = Pragma_Compile_Time_Error then
31434 Error_Msg_N ("condition is not known at compile time", Arg1x);
31435
31436 elsif Warn_On_Unknown_Compile_Time_Warning then
31437 Error_Msg_N ("??condition is not known at compile time", Arg1x);
31438 end if;
31439 end Validate_Compile_Time_Warning_Or_Error;
31440
31441 ------------------------------------
31442 -- Record_Possible_Body_Reference --
31443 ------------------------------------
31444
31445 procedure Record_Possible_Body_Reference
31446 (State_Id : Entity_Id;
31447 Ref : Node_Id)
31448 is
31449 Context : Node_Id;
31450 Spec_Id : Entity_Id;
31451
31452 begin
31453 -- Ensure that we are dealing with a reference to a state
31454
31455 pragma Assert (Ekind (State_Id) = E_Abstract_State);
31456
31457 -- Climb the tree starting from the reference looking for a package body
31458 -- whose spec declares the referenced state. This criteria automatically
31459 -- excludes references in package specs which are legal. Note that it is
31460 -- not wise to emit an error now as the package body may lack pragma
31461 -- Refined_State or the referenced state may not be mentioned in the
31462 -- refinement. This approach avoids the generation of misleading errors.
31463
31464 Context := Ref;
31465 while Present (Context) loop
31466 if Nkind (Context) = N_Package_Body then
31467 Spec_Id := Corresponding_Spec (Context);
31468
31469 if Present (Abstract_States (Spec_Id))
31470 and then Contains (Abstract_States (Spec_Id), State_Id)
31471 then
31472 if No (Body_References (State_Id)) then
31473 Set_Body_References (State_Id, New_Elmt_List);
31474 end if;
31475
31476 Append_Elmt (Ref, To => Body_References (State_Id));
31477 exit;
31478 end if;
31479 end if;
31480
31481 Context := Parent (Context);
31482 end loop;
31483 end Record_Possible_Body_Reference;
31484
31485 ------------------------------------------
31486 -- Relocate_Pragmas_To_Anonymous_Object --
31487 ------------------------------------------
31488
31489 procedure Relocate_Pragmas_To_Anonymous_Object
31490 (Typ_Decl : Node_Id;
31491 Obj_Decl : Node_Id)
31492 is
31493 Decl : Node_Id;
31494 Def : Node_Id;
31495 Next_Decl : Node_Id;
31496
31497 begin
31498 if Nkind (Typ_Decl) = N_Protected_Type_Declaration then
31499 Def := Protected_Definition (Typ_Decl);
31500 else
31501 pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration);
31502 Def := Task_Definition (Typ_Decl);
31503 end if;
31504
31505 -- The concurrent definition has a visible declaration list. Inspect it
31506 -- and relocate all canidate pragmas.
31507
31508 if Present (Def) and then Present (Visible_Declarations (Def)) then
31509 Decl := First (Visible_Declarations (Def));
31510 while Present (Decl) loop
31511
31512 -- Preserve the following declaration for iteration purposes due
31513 -- to possible relocation of a pragma.
31514
31515 Next_Decl := Next (Decl);
31516
31517 if Nkind (Decl) = N_Pragma
31518 and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl))
31519 then
31520 Remove (Decl);
31521 Insert_After (Obj_Decl, Decl);
31522
31523 -- Skip internally generated code
31524
31525 elsif not Comes_From_Source (Decl) then
31526 null;
31527
31528 -- No candidate pragmas are available for relocation
31529
31530 else
31531 exit;
31532 end if;
31533
31534 Decl := Next_Decl;
31535 end loop;
31536 end if;
31537 end Relocate_Pragmas_To_Anonymous_Object;
31538
31539 ------------------------------
31540 -- Relocate_Pragmas_To_Body --
31541 ------------------------------
31542
31543 procedure Relocate_Pragmas_To_Body
31544 (Subp_Body : Node_Id;
31545 Target_Body : Node_Id := Empty)
31546 is
31547 procedure Relocate_Pragma (Prag : Node_Id);
31548 -- Remove a single pragma from its current list and add it to the
31549 -- declarations of the proper body (either Subp_Body or Target_Body).
31550
31551 ---------------------
31552 -- Relocate_Pragma --
31553 ---------------------
31554
31555 procedure Relocate_Pragma (Prag : Node_Id) is
31556 Decls : List_Id;
31557 Target : Node_Id;
31558
31559 begin
31560 -- When subprogram stubs or expression functions are involves, the
31561 -- destination declaration list belongs to the proper body.
31562
31563 if Present (Target_Body) then
31564 Target := Target_Body;
31565 else
31566 Target := Subp_Body;
31567 end if;
31568
31569 Decls := Declarations (Target);
31570
31571 if No (Decls) then
31572 Decls := New_List;
31573 Set_Declarations (Target, Decls);
31574 end if;
31575
31576 -- Unhook the pragma from its current list
31577
31578 Remove (Prag);
31579 Prepend (Prag, Decls);
31580 end Relocate_Pragma;
31581
31582 -- Local variables
31583
31584 Body_Id : constant Entity_Id :=
31585 Defining_Unit_Name (Specification (Subp_Body));
31586 Next_Stmt : Node_Id;
31587 Stmt : Node_Id;
31588
31589 -- Start of processing for Relocate_Pragmas_To_Body
31590
31591 begin
31592 -- Do not process a body that comes from a separate unit as no construct
31593 -- can possibly follow it.
31594
31595 if not Is_List_Member (Subp_Body) then
31596 return;
31597
31598 -- Do not relocate pragmas that follow a stub if the stub does not have
31599 -- a proper body.
31600
31601 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
31602 and then No (Target_Body)
31603 then
31604 return;
31605
31606 -- Do not process internally generated routine _Postconditions
31607
31608 elsif Ekind (Body_Id) = E_Procedure
31609 and then Chars (Body_Id) = Name_uPostconditions
31610 then
31611 return;
31612 end if;
31613
31614 -- Look at what is following the body. We are interested in certain kind
31615 -- of pragmas (either from source or byproducts of expansion) that can
31616 -- apply to a body [stub].
31617
31618 Stmt := Next (Subp_Body);
31619 while Present (Stmt) loop
31620
31621 -- Preserve the following statement for iteration purposes due to a
31622 -- possible relocation of a pragma.
31623
31624 Next_Stmt := Next (Stmt);
31625
31626 -- Move a candidate pragma following the body to the declarations of
31627 -- the body.
31628
31629 if Nkind (Stmt) = N_Pragma
31630 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
31631 then
31632
31633 -- If a source pragma Warnings follows the body, it applies to
31634 -- following statements and does not belong in the body.
31635
31636 if Get_Pragma_Id (Stmt) = Pragma_Warnings
31637 and then Comes_From_Source (Stmt)
31638 then
31639 null;
31640 else
31641 Relocate_Pragma (Stmt);
31642 end if;
31643
31644 -- Skip internally generated code
31645
31646 elsif not Comes_From_Source (Stmt) then
31647 null;
31648
31649 -- No candidate pragmas are available for relocation
31650
31651 else
31652 exit;
31653 end if;
31654
31655 Stmt := Next_Stmt;
31656 end loop;
31657 end Relocate_Pragmas_To_Body;
31658
31659 -------------------
31660 -- Resolve_State --
31661 -------------------
31662
31663 procedure Resolve_State (N : Node_Id) is
31664 Func : Entity_Id;
31665 State : Entity_Id;
31666
31667 begin
31668 if Is_Entity_Name (N) and then Present (Entity (N)) then
31669 Func := Entity (N);
31670
31671 -- Handle overloading of state names by functions. Traverse the
31672 -- homonym chain looking for an abstract state.
31673
31674 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
31675 pragma Assert (Is_Overloaded (N));
31676
31677 State := Homonym (Func);
31678 while Present (State) loop
31679 if Ekind (State) = E_Abstract_State then
31680
31681 -- Resolve the overloading by setting the proper entity of
31682 -- the reference to that of the state.
31683
31684 Set_Etype (N, Standard_Void_Type);
31685 Set_Entity (N, State);
31686 Set_Is_Overloaded (N, False);
31687
31688 Generate_Reference (State, N);
31689 return;
31690 end if;
31691
31692 State := Homonym (State);
31693 end loop;
31694
31695 -- A function can never act as a state. If the homonym chain does
31696 -- not contain a corresponding state, then something went wrong in
31697 -- the overloading mechanism.
31698
31699 raise Program_Error;
31700 end if;
31701 end if;
31702 end Resolve_State;
31703
31704 ----------------------------
31705 -- Rewrite_Assertion_Kind --
31706 ----------------------------
31707
31708 procedure Rewrite_Assertion_Kind
31709 (N : Node_Id;
31710 From_Policy : Boolean := False)
31711 is
31712 Nam : Name_Id;
31713
31714 begin
31715 Nam := No_Name;
31716 if Nkind (N) = N_Attribute_Reference
31717 and then Attribute_Name (N) = Name_Class
31718 and then Nkind (Prefix (N)) = N_Identifier
31719 then
31720 case Chars (Prefix (N)) is
31721 when Name_Pre =>
31722 Nam := Name_uPre;
31723
31724 when Name_Post =>
31725 Nam := Name_uPost;
31726
31727 when Name_Type_Invariant =>
31728 Nam := Name_uType_Invariant;
31729
31730 when Name_Invariant =>
31731 Nam := Name_uInvariant;
31732
31733 when others =>
31734 return;
31735 end case;
31736
31737 -- Recommend standard use of aspect names Pre/Post
31738
31739 elsif Nkind (N) = N_Identifier
31740 and then From_Policy
31741 and then Serious_Errors_Detected = 0
31742 then
31743 if Chars (N) = Name_Precondition
31744 or else Chars (N) = Name_Postcondition
31745 then
31746 Error_Msg_N ("Check_Policy is a non-standard pragma??", N);
31747 Error_Msg_N
31748 ("\use Assertion_Policy and aspect names Pre/Post for "
31749 & "Ada2012 conformance?", N);
31750 end if;
31751
31752 return;
31753 end if;
31754
31755 if Nam /= No_Name then
31756 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
31757 end if;
31758 end Rewrite_Assertion_Kind;
31759
31760 --------
31761 -- rv --
31762 --------
31763
31764 procedure rv is
31765 begin
31766 Dummy := Dummy + 1;
31767 end rv;
31768
31769 --------------------------------
31770 -- Set_Encoded_Interface_Name --
31771 --------------------------------
31772
31773 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
31774 Str : constant String_Id := Strval (S);
31775 Len : constant Nat := String_Length (Str);
31776 CC : Char_Code;
31777 C : Character;
31778 J : Pos;
31779
31780 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
31781
31782 procedure Encode;
31783 -- Stores encoded value of character code CC. The encoding we use an
31784 -- underscore followed by four lower case hex digits.
31785
31786 ------------
31787 -- Encode --
31788 ------------
31789
31790 procedure Encode is
31791 begin
31792 Store_String_Char (Get_Char_Code ('_'));
31793 Store_String_Char
31794 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
31795 Store_String_Char
31796 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
31797 Store_String_Char
31798 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
31799 Store_String_Char
31800 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
31801 end Encode;
31802
31803 -- Start of processing for Set_Encoded_Interface_Name
31804
31805 begin
31806 -- If first character is asterisk, this is a link name, and we leave it
31807 -- completely unmodified. We also ignore null strings (the latter case
31808 -- happens only in error cases).
31809
31810 if Len = 0
31811 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
31812 then
31813 Set_Interface_Name (E, S);
31814
31815 else
31816 J := 1;
31817 loop
31818 CC := Get_String_Char (Str, J);
31819
31820 exit when not In_Character_Range (CC);
31821
31822 C := Get_Character (CC);
31823
31824 exit when C /= '_' and then C /= '$'
31825 and then C not in '0' .. '9'
31826 and then C not in 'a' .. 'z'
31827 and then C not in 'A' .. 'Z';
31828
31829 if J = Len then
31830 Set_Interface_Name (E, S);
31831 return;
31832
31833 else
31834 J := J + 1;
31835 end if;
31836 end loop;
31837
31838 -- Here we need to encode. The encoding we use as follows:
31839 -- three underscores + four hex digits (lower case)
31840
31841 Start_String;
31842
31843 for J in 1 .. String_Length (Str) loop
31844 CC := Get_String_Char (Str, J);
31845
31846 if not In_Character_Range (CC) then
31847 Encode;
31848 else
31849 C := Get_Character (CC);
31850
31851 if C = '_' or else C = '$'
31852 or else C in '0' .. '9'
31853 or else C in 'a' .. 'z'
31854 or else C in 'A' .. 'Z'
31855 then
31856 Store_String_Char (CC);
31857 else
31858 Encode;
31859 end if;
31860 end if;
31861 end loop;
31862
31863 Set_Interface_Name (E,
31864 Make_String_Literal (Sloc (S),
31865 Strval => End_String));
31866 end if;
31867 end Set_Encoded_Interface_Name;
31868
31869 ------------------------
31870 -- Set_Elab_Unit_Name --
31871 ------------------------
31872
31873 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
31874 Pref : Node_Id;
31875 Scop : Entity_Id;
31876
31877 begin
31878 if Nkind (N) = N_Identifier
31879 and then Nkind (With_Item) = N_Identifier
31880 then
31881 Set_Entity (N, Entity (With_Item));
31882
31883 elsif Nkind (N) = N_Selected_Component then
31884 Change_Selected_Component_To_Expanded_Name (N);
31885 Set_Entity (N, Entity (With_Item));
31886 Set_Entity (Selector_Name (N), Entity (N));
31887
31888 Pref := Prefix (N);
31889 Scop := Scope (Entity (N));
31890 while Nkind (Pref) = N_Selected_Component loop
31891 Change_Selected_Component_To_Expanded_Name (Pref);
31892 Set_Entity (Selector_Name (Pref), Scop);
31893 Set_Entity (Pref, Scop);
31894 Pref := Prefix (Pref);
31895 Scop := Scope (Scop);
31896 end loop;
31897
31898 Set_Entity (Pref, Scop);
31899 end if;
31900
31901 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
31902 end Set_Elab_Unit_Name;
31903
31904 -----------------------
31905 -- Set_Overflow_Mode --
31906 -----------------------
31907
31908 procedure Set_Overflow_Mode (N : Node_Id) is
31909
31910 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type;
31911 -- Function to process one pragma argument, Arg
31912
31913 -----------------------
31914 -- Get_Overflow_Mode --
31915 -----------------------
31916
31917 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type is
31918 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
31919
31920 begin
31921 if Chars (Argx) = Name_Strict then
31922 return Strict;
31923
31924 elsif Chars (Argx) = Name_Minimized then
31925 return Minimized;
31926
31927 elsif Chars (Argx) = Name_Eliminated then
31928 return Eliminated;
31929
31930 else
31931 raise Program_Error;
31932 end if;
31933 end Get_Overflow_Mode;
31934
31935 -- Local variables
31936
31937 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
31938 Arg2 : constant Node_Id := Next (Arg1);
31939
31940 -- Start of processing for Set_Overflow_Mode
31941
31942 begin
31943 -- Process first argument
31944
31945 Scope_Suppress.Overflow_Mode_General :=
31946 Get_Overflow_Mode (Arg1);
31947
31948 -- Case of only one argument
31949
31950 if No (Arg2) then
31951 Scope_Suppress.Overflow_Mode_Assertions :=
31952 Scope_Suppress.Overflow_Mode_General;
31953
31954 -- Case of two arguments present
31955
31956 else
31957 Scope_Suppress.Overflow_Mode_Assertions :=
31958 Get_Overflow_Mode (Arg2);
31959 end if;
31960 end Set_Overflow_Mode;
31961
31962 -------------------
31963 -- Test_Case_Arg --
31964 -------------------
31965
31966 function Test_Case_Arg
31967 (Prag : Node_Id;
31968 Arg_Nam : Name_Id;
31969 From_Aspect : Boolean := False) return Node_Id
31970 is
31971 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
31972 Arg : Node_Id;
31973 Args : Node_Id;
31974
31975 begin
31976 pragma Assert
31977 (Arg_Nam in Name_Ensures | Name_Mode | Name_Name | Name_Requires);
31978
31979 -- The caller requests the aspect argument
31980
31981 if From_Aspect then
31982 if Present (Aspect)
31983 and then Nkind (Expression (Aspect)) = N_Aggregate
31984 then
31985 Args := Expression (Aspect);
31986
31987 -- "Name" and "Mode" may appear without an identifier as a
31988 -- positional association.
31989
31990 if Present (Expressions (Args)) then
31991 Arg := First (Expressions (Args));
31992
31993 if Present (Arg) and then Arg_Nam = Name_Name then
31994 return Arg;
31995 end if;
31996
31997 -- Skip "Name"
31998
31999 Arg := Next (Arg);
32000
32001 if Present (Arg) and then Arg_Nam = Name_Mode then
32002 return Arg;
32003 end if;
32004 end if;
32005
32006 -- Some or all arguments may appear as component associatons
32007
32008 if Present (Component_Associations (Args)) then
32009 Arg := First (Component_Associations (Args));
32010 while Present (Arg) loop
32011 if Chars (First (Choices (Arg))) = Arg_Nam then
32012 return Arg;
32013 end if;
32014
32015 Next (Arg);
32016 end loop;
32017 end if;
32018 end if;
32019
32020 -- Otherwise retrieve the argument directly from the pragma
32021
32022 else
32023 Arg := First (Pragma_Argument_Associations (Prag));
32024
32025 if Present (Arg) and then Arg_Nam = Name_Name then
32026 return Arg;
32027 end if;
32028
32029 -- Skip argument "Name"
32030
32031 Arg := Next (Arg);
32032
32033 if Present (Arg) and then Arg_Nam = Name_Mode then
32034 return Arg;
32035 end if;
32036
32037 -- Skip argument "Mode"
32038
32039 Arg := Next (Arg);
32040
32041 -- Arguments "Requires" and "Ensures" are optional and may not be
32042 -- present at all.
32043
32044 while Present (Arg) loop
32045 if Chars (Arg) = Arg_Nam then
32046 return Arg;
32047 end if;
32048
32049 Next (Arg);
32050 end loop;
32051 end if;
32052
32053 return Empty;
32054 end Test_Case_Arg;
32055
32056 --------------------------------------------
32057 -- Defer_Compile_Time_Warning_Error_To_BE --
32058 --------------------------------------------
32059
32060 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id) is
32061 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
32062 begin
32063 Compile_Time_Warnings_Errors.Append
32064 (New_Val => CTWE_Entry'(Eloc => Sloc (Arg1),
32065 Scope => Current_Scope,
32066 Prag => N));
32067
32068 -- If the Boolean expression contains T'Size, and we're not in the main
32069 -- unit being compiled, then we need to copy the pragma into the main
32070 -- unit, because otherwise T'Size might never be computed, leaving it
32071 -- as 0.
32072
32073 if not In_Extended_Main_Code_Unit (N) then
32074 Insert_Library_Level_Action (New_Copy_Tree (N));
32075 end if;
32076 end Defer_Compile_Time_Warning_Error_To_BE;
32077
32078 ------------------------------------------
32079 -- Validate_Compile_Time_Warning_Errors --
32080 ------------------------------------------
32081
32082 procedure Validate_Compile_Time_Warning_Errors is
32083 procedure Set_Scope (S : Entity_Id);
32084 -- Install all enclosing scopes of S along with S itself
32085
32086 procedure Unset_Scope (S : Entity_Id);
32087 -- Uninstall all enclosing scopes of S along with S itself
32088
32089 ---------------
32090 -- Set_Scope --
32091 ---------------
32092
32093 procedure Set_Scope (S : Entity_Id) is
32094 begin
32095 if S /= Standard_Standard then
32096 Set_Scope (Scope (S));
32097 end if;
32098
32099 Push_Scope (S);
32100 end Set_Scope;
32101
32102 -----------------
32103 -- Unset_Scope --
32104 -----------------
32105
32106 procedure Unset_Scope (S : Entity_Id) is
32107 begin
32108 if S /= Standard_Standard then
32109 Unset_Scope (Scope (S));
32110 end if;
32111
32112 Pop_Scope;
32113 end Unset_Scope;
32114
32115 -- Start of processing for Validate_Compile_Time_Warning_Errors
32116
32117 begin
32118 Expander_Mode_Save_And_Set (False);
32119 In_Compile_Time_Warning_Or_Error := True;
32120
32121 for N in Compile_Time_Warnings_Errors.First ..
32122 Compile_Time_Warnings_Errors.Last
32123 loop
32124 declare
32125 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
32126
32127 begin
32128 Set_Scope (T.Scope);
32129 Reset_Analyzed_Flags (T.Prag);
32130 Validate_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
32131 Unset_Scope (T.Scope);
32132 end;
32133 end loop;
32134
32135 In_Compile_Time_Warning_Or_Error := False;
32136 Expander_Mode_Restore;
32137 end Validate_Compile_Time_Warning_Errors;
32138
32139 end Sem_Prag;