[Ada] Postcondition checks performed before finalization
[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 GNAT_CUDA; use GNAT_CUDA;
48 with Gnatvsn; use Gnatvsn;
49 with Lib; use Lib;
50 with Lib.Writ; use Lib.Writ;
51 with Lib.Xref; use Lib.Xref;
52 with Namet.Sp; use Namet.Sp;
53 with Nlists; use Nlists;
54 with Nmake; use Nmake;
55 with Output; use Output;
56 with Par_SCO; use Par_SCO;
57 with Restrict; use Restrict;
58 with Rident; use Rident;
59 with Rtsfind; use Rtsfind;
60 with Sem; use Sem;
61 with Sem_Aux; use Sem_Aux;
62 with Sem_Ch3; use Sem_Ch3;
63 with Sem_Ch6; use Sem_Ch6;
64 with Sem_Ch8; use Sem_Ch8;
65 with Sem_Ch12; use Sem_Ch12;
66 with Sem_Ch13; use Sem_Ch13;
67 with Sem_Disp; use Sem_Disp;
68 with Sem_Dist; use Sem_Dist;
69 with Sem_Elab; use Sem_Elab;
70 with Sem_Elim; use Sem_Elim;
71 with Sem_Eval; use Sem_Eval;
72 with Sem_Intr; use Sem_Intr;
73 with Sem_Mech; use Sem_Mech;
74 with Sem_Res; use Sem_Res;
75 with Sem_Type; use Sem_Type;
76 with Sem_Util; use Sem_Util;
77 with Sem_Warn; use Sem_Warn;
78 with Stand; use Stand;
79 with Sinfo; use Sinfo;
80 with Sinfo.CN; use Sinfo.CN;
81 with Sinput; use Sinput;
82 with Stringt; use Stringt;
83 with Stylesw; use Stylesw;
84 with Table;
85 with Targparm; use Targparm;
86 with Tbuild; use Tbuild;
87 with Ttypes;
88 with Uintp; use Uintp;
89 with Uname; use Uname;
90 with Urealp; use Urealp;
91 with Validsw; use Validsw;
92 with Warnsw; use Warnsw;
93
94 with System.Case_Util;
95
96 package body Sem_Prag is
97
98 ----------------------------------------------
99 -- Common Handling of Import-Export Pragmas --
100 ----------------------------------------------
101
102 -- In the following section, a number of Import_xxx and Export_xxx pragmas
103 -- are defined by GNAT. These are compatible with the DEC pragmas of the
104 -- same name, and all have the following common form and processing:
105
106 -- pragma Export_xxx
107 -- [Internal =>] LOCAL_NAME
108 -- [, [External =>] EXTERNAL_SYMBOL]
109 -- [, other optional parameters ]);
110
111 -- pragma Import_xxx
112 -- [Internal =>] LOCAL_NAME
113 -- [, [External =>] EXTERNAL_SYMBOL]
114 -- [, other optional parameters ]);
115
116 -- EXTERNAL_SYMBOL ::=
117 -- IDENTIFIER
118 -- | static_string_EXPRESSION
119
120 -- The internal LOCAL_NAME designates the entity that is imported or
121 -- exported, and must refer to an entity in the current declarative
122 -- part (as required by the rules for LOCAL_NAME).
123
124 -- The external linker name is designated by the External parameter if
125 -- given, or the Internal parameter if not (if there is no External
126 -- parameter, the External parameter is a copy of the Internal name).
127
128 -- If the External parameter is given as a string, then this string is
129 -- treated as an external name (exactly as though it had been given as an
130 -- External_Name parameter for a normal Import pragma).
131
132 -- If the External parameter is given as an identifier (or there is no
133 -- External parameter, so that the Internal identifier is used), then
134 -- the external name is the characters of the identifier, translated
135 -- to all lower case letters.
136
137 -- Note: the external name specified or implied by any of these special
138 -- Import_xxx or Export_xxx pragmas override an external or link name
139 -- specified in a previous Import or Export pragma.
140
141 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
142 -- named notation, following the standard rules for subprogram calls, i.e.
143 -- parameters can be given in any order if named notation is used, and
144 -- positional and named notation can be mixed, subject to the rule that all
145 -- positional parameters must appear first.
146
147 -- Note: All these pragmas are implemented exactly following the DEC design
148 -- and implementation and are intended to be fully compatible with the use
149 -- of these pragmas in the DEC Ada compiler.
150
151 --------------------------------------------
152 -- Checking for Duplicated External Names --
153 --------------------------------------------
154
155 -- It is suspicious if two separate Export pragmas use the same external
156 -- name. The following table is used to diagnose this situation so that
157 -- an appropriate warning can be issued.
158
159 -- The Node_Id stored is for the N_String_Literal node created to hold
160 -- the value of the external name. The Sloc of this node is used to
161 -- cross-reference the location of the duplication.
162
163 package Externals is new Table.Table (
164 Table_Component_Type => Node_Id,
165 Table_Index_Type => Int,
166 Table_Low_Bound => 0,
167 Table_Initial => 100,
168 Table_Increment => 100,
169 Table_Name => "Name_Externals");
170
171 -------------------------------------
172 -- Local Subprograms and Variables --
173 -------------------------------------
174
175 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
176 -- This routine is used for possible casing adjustment of an explicit
177 -- external name supplied as a string literal (the node N), according to
178 -- the casing requirement of Opt.External_Name_Casing. If this is set to
179 -- As_Is, then the string literal is returned unchanged, but if it is set
180 -- to Uppercase or Lowercase, then a new string literal with appropriate
181 -- casing is constructed.
182
183 procedure Analyze_Part_Of
184 (Indic : Node_Id;
185 Item_Id : Entity_Id;
186 Encap : Node_Id;
187 Encap_Id : out Entity_Id;
188 Legal : out Boolean);
189 -- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and
190 -- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the
191 -- Part_Of indicator. Item_Id is the entity of an abstract state, object or
192 -- package instantiation. Encap denotes the encapsulating state or single
193 -- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when
194 -- the indicator is legal.
195
196 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
197 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
198 -- Query whether a particular item appears in a mixed list of nodes and
199 -- entities. It is assumed that all nodes in the list have entities.
200
201 procedure Check_Postcondition_Use_In_Inlined_Subprogram
202 (Prag : Node_Id;
203 Spec_Id : Entity_Id);
204 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
205 -- Precondition, Refined_Post, and Test_Case. Emit a warning when pragma
206 -- Prag is associated with subprogram Spec_Id subject to Inline_Always,
207 -- and assertions are enabled.
208
209 procedure Check_State_And_Constituent_Use
210 (States : Elist_Id;
211 Constits : Elist_Id;
212 Context : Node_Id);
213 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
214 -- Global and Initializes. Determine whether a state from list States and a
215 -- corresponding constituent from list Constits (if any) appear in the same
216 -- context denoted by Context. If this is the case, emit an error.
217
218 procedure Contract_Freeze_Error
219 (Contract_Id : Entity_Id;
220 Freeze_Id : Entity_Id);
221 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and
222 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity
223 -- of a body which caused contract freezing and Contract_Id denotes the
224 -- entity of the affected contstruct.
225
226 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id);
227 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma
228 -- Prag that duplicates previous pragma Prev.
229
230 function Find_Encapsulating_State
231 (States : Elist_Id;
232 Constit_Id : Entity_Id) return Entity_Id;
233 -- Given the entity of a constituent Constit_Id, find the corresponding
234 -- encapsulating state which appears in States. The routine returns Empty
235 -- if no such state is found.
236
237 function Find_Related_Context
238 (Prag : Node_Id;
239 Do_Checks : Boolean := False) return Node_Id;
240 -- Subsidiary to the analysis of pragmas
241 -- Async_Readers
242 -- Async_Writers
243 -- Constant_After_Elaboration
244 -- Effective_Reads
245 -- Effective_Writers
246 -- Part_Of
247 -- Find the first source declaration or statement found while traversing
248 -- the previous node chain starting from pragma Prag. If flag Do_Checks is
249 -- set, the routine reports duplicate pragmas. The routine returns Empty
250 -- when reaching the start of the node chain.
251
252 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
253 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
254 -- original one, following the renaming chain) is returned. Otherwise the
255 -- entity is returned unchanged. Should be in Einfo???
256
257 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
258 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
259 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
260 -- value of type SPARK_Mode_Type.
261
262 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
263 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
264 -- Determine whether dependency clause Clause is surrounded by extra
265 -- parentheses. If this is the case, issue an error message.
266
267 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
268 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
269 -- pragma Depends. Determine whether the type of dependency item Item is
270 -- tagged, unconstrained array, unconstrained record or a record with at
271 -- least one unconstrained component.
272
273 procedure Record_Possible_Body_Reference
274 (State_Id : Entity_Id;
275 Ref : Node_Id);
276 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
277 -- Global. Given an abstract state denoted by State_Id and a reference Ref
278 -- to it, determine whether the reference appears in a package body that
279 -- will eventually refine the state. If this is the case, record the
280 -- reference for future checks (see Analyze_Refined_State_In_Decls).
281
282 procedure Resolve_State (N : Node_Id);
283 -- Handle the overloading of state names by functions. When N denotes a
284 -- function, this routine finds the corresponding state and sets the entity
285 -- of N to that of the state.
286
287 procedure Rewrite_Assertion_Kind
288 (N : Node_Id;
289 From_Policy : Boolean := False);
290 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
291 -- then it is rewritten as an identifier with the corresponding special
292 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
293 -- and Check_Policy. If the names are Precondition or Postcondition, this
294 -- combination is deprecated in favor of Assertion_Policy and Ada2012
295 -- Aspect names. The parameter From_Policy indicates that the pragma
296 -- is the old non-standard Check_Policy and not a rewritten pragma.
297
298 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
299 -- Place semantic information on the argument of an Elaborate/Elaborate_All
300 -- pragma. Entity name for unit and its parents is taken from item in
301 -- previous with_clause that mentions the unit.
302
303 procedure Validate_Compile_Time_Warning_Or_Error
304 (N : Node_Id;
305 Eloc : Source_Ptr);
306 -- Common processing for Compile_Time_Error and Compile_Time_Warning of
307 -- pragma N. Called when the pragma is processed as part of its regular
308 -- analysis but also called after calling the back end to validate these
309 -- pragmas for size and alignment appropriateness.
310
311 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id);
312 -- N is a pragma Compile_Time_Error or Compile_Warning_Error whose boolean
313 -- expression is not known at compile time during the front end. This
314 -- procedure makes an entry in a table. The actual checking is performed by
315 -- Validate_Compile_Time_Warning_Errors, which is invoked after calling the
316 -- back end.
317
318 Dummy : Integer := 0;
319 pragma Volatile (Dummy);
320 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
321
322 procedure ip;
323 pragma No_Inline (ip);
324 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
325 -- is just to help debugging the front end. If a pragma Inspection_Point
326 -- is added to a source program, then breaking on ip will get you to that
327 -- point in the program.
328
329 procedure rv;
330 pragma No_Inline (rv);
331 -- This is a dummy function called by the processing for pragma Reviewable.
332 -- It is there for assisting front end debugging. By placing a Reviewable
333 -- pragma in the source program, a breakpoint on rv catches this place in
334 -- the source, allowing convenient stepping to the point of interest.
335
336 ------------------------------------------------------
337 -- Table for Defer_Compile_Time_Warning_Error_To_BE --
338 ------------------------------------------------------
339
340 -- The following table collects pragmas Compile_Time_Error and Compile_
341 -- Time_Warning for validation. Entries are made by calls to subprogram
342 -- Defer_Compile_Time_Warning_Error_To_BE, and the call to the procedure
343 -- Validate_Compile_Time_Warning_Errors does the actual error checking
344 -- and posting of warning and error messages. The reason for this delayed
345 -- processing is to take advantage of back-annotations of attributes size
346 -- and alignment values performed by the back end.
347
348 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
349 -- that by the time Validate_Compile_Time_Warning_Errors is called, Sprint
350 -- will already have modified all Sloc values if the -gnatD option is set.
351
352 type CTWE_Entry is record
353 Eloc : Source_Ptr;
354 -- Source location used in warnings and error messages
355
356 Prag : Node_Id;
357 -- Pragma Compile_Time_Error or Compile_Time_Warning
358
359 Scope : Node_Id;
360 -- The scope which encloses the pragma
361 end record;
362
363 package Compile_Time_Warnings_Errors is new Table.Table (
364 Table_Component_Type => CTWE_Entry,
365 Table_Index_Type => Int,
366 Table_Low_Bound => 1,
367 Table_Initial => 50,
368 Table_Increment => 200,
369 Table_Name => "Compile_Time_Warnings_Errors");
370
371 -------------------------------
372 -- Adjust_External_Name_Case --
373 -------------------------------
374
375 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
376 CC : Char_Code;
377
378 begin
379 -- Adjust case of literal if required
380
381 if Opt.External_Name_Exp_Casing = As_Is then
382 return N;
383
384 else
385 -- Copy existing string
386
387 Start_String;
388
389 -- Set proper casing
390
391 for J in 1 .. String_Length (Strval (N)) loop
392 CC := Get_String_Char (Strval (N), J);
393
394 if Opt.External_Name_Exp_Casing = Uppercase
395 and then CC >= Get_Char_Code ('a')
396 and then CC <= Get_Char_Code ('z')
397 then
398 Store_String_Char (CC - 32);
399
400 elsif Opt.External_Name_Exp_Casing = Lowercase
401 and then CC >= Get_Char_Code ('A')
402 and then CC <= Get_Char_Code ('Z')
403 then
404 Store_String_Char (CC + 32);
405
406 else
407 Store_String_Char (CC);
408 end if;
409 end loop;
410
411 return
412 Make_String_Literal (Sloc (N),
413 Strval => End_String);
414 end if;
415 end Adjust_External_Name_Case;
416
417 -----------------------------------------
418 -- Analyze_Contract_Cases_In_Decl_Part --
419 -----------------------------------------
420
421 -- WARNING: This routine manages Ghost regions. Return statements must be
422 -- replaced by gotos which jump to the end of the routine and restore the
423 -- Ghost mode.
424
425 procedure Analyze_Contract_Cases_In_Decl_Part
426 (N : Node_Id;
427 Freeze_Id : Entity_Id := Empty)
428 is
429 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
430 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
431
432 Others_Seen : Boolean := False;
433 -- This flag is set when an "others" choice is encountered. It is used
434 -- to detect multiple illegal occurrences of "others".
435
436 procedure Analyze_Contract_Case (CCase : Node_Id);
437 -- Verify the legality of a single contract case
438
439 ---------------------------
440 -- Analyze_Contract_Case --
441 ---------------------------
442
443 procedure Analyze_Contract_Case (CCase : Node_Id) is
444 Case_Guard : Node_Id;
445 Conseq : Node_Id;
446 Errors : Nat;
447 Extra_Guard : Node_Id;
448
449 begin
450 if Nkind (CCase) = N_Component_Association then
451 Case_Guard := First (Choices (CCase));
452 Conseq := Expression (CCase);
453
454 -- Each contract case must have exactly one case guard
455
456 Extra_Guard := Next (Case_Guard);
457
458 if Present (Extra_Guard) then
459 Error_Msg_N
460 ("contract case must have exactly one case guard",
461 Extra_Guard);
462 end if;
463
464 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
465
466 if Nkind (Case_Guard) = N_Others_Choice then
467 if Others_Seen then
468 Error_Msg_N
469 ("only one others choice allowed in contract cases",
470 Case_Guard);
471 else
472 Others_Seen := True;
473 end if;
474
475 elsif Others_Seen then
476 Error_Msg_N
477 ("others must be the last choice in contract cases", N);
478 end if;
479
480 -- Preanalyze the case guard and consequence
481
482 if Nkind (Case_Guard) /= N_Others_Choice then
483 Errors := Serious_Errors_Detected;
484 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
485
486 -- Emit a clarification message when the case guard contains
487 -- at least one undefined reference, possibly due to contract
488 -- freezing.
489
490 if Errors /= Serious_Errors_Detected
491 and then Present (Freeze_Id)
492 and then Has_Undefined_Reference (Case_Guard)
493 then
494 Contract_Freeze_Error (Spec_Id, Freeze_Id);
495 end if;
496 end if;
497
498 Errors := Serious_Errors_Detected;
499 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
500
501 -- Emit a clarification message when the consequence contains
502 -- at least one undefined reference, possibly due to contract
503 -- freezing.
504
505 if Errors /= Serious_Errors_Detected
506 and then Present (Freeze_Id)
507 and then Has_Undefined_Reference (Conseq)
508 then
509 Contract_Freeze_Error (Spec_Id, Freeze_Id);
510 end if;
511
512 -- The contract case is malformed
513
514 else
515 Error_Msg_N ("wrong syntax in contract case", CCase);
516 end if;
517 end Analyze_Contract_Case;
518
519 -- Local variables
520
521 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
522
523 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
524 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
525 -- Save the Ghost-related attributes to restore on exit
526
527 CCase : Node_Id;
528 Restore_Scope : Boolean := False;
529
530 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
531
532 begin
533 -- Do not analyze the pragma multiple times
534
535 if Is_Analyzed_Pragma (N) then
536 return;
537 end if;
538
539 -- Set the Ghost mode in effect from the pragma. Due to the delayed
540 -- analysis of the pragma, the Ghost mode at point of declaration and
541 -- point of analysis may not necessarily be the same. Use the mode in
542 -- effect at the point of declaration.
543
544 Set_Ghost_Mode (N);
545
546 -- Single and multiple contract cases must appear in aggregate form. If
547 -- this is not the case, then either the parser or the analysis of the
548 -- pragma failed to produce an aggregate.
549
550 pragma Assert (Nkind (CCases) = N_Aggregate);
551
552 -- Only CASE_GUARD => CONSEQUENCE clauses are allowed
553
554 if Present (Component_Associations (CCases))
555 and then No (Expressions (CCases))
556 then
557
558 -- Ensure that the formal parameters are visible when analyzing all
559 -- clauses. This falls out of the general rule of aspects pertaining
560 -- to subprogram declarations.
561
562 if not In_Open_Scopes (Spec_Id) then
563 Restore_Scope := True;
564 Push_Scope (Spec_Id);
565
566 if Is_Generic_Subprogram (Spec_Id) then
567 Install_Generic_Formals (Spec_Id);
568 else
569 Install_Formals (Spec_Id);
570 end if;
571 end if;
572
573 CCase := First (Component_Associations (CCases));
574 while Present (CCase) loop
575 Analyze_Contract_Case (CCase);
576 Next (CCase);
577 end loop;
578
579 if Restore_Scope then
580 End_Scope;
581 end if;
582
583 -- Currently it is not possible to inline pre/postconditions on a
584 -- subprogram subject to pragma Inline_Always.
585
586 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
587
588 -- Otherwise the pragma is illegal
589
590 else
591 Error_Msg_N ("wrong syntax for contract cases", N);
592 end if;
593
594 Set_Is_Analyzed_Pragma (N);
595
596 Restore_Ghost_Region (Saved_GM, Saved_IGR);
597 end Analyze_Contract_Cases_In_Decl_Part;
598
599 ----------------------------------
600 -- Analyze_Depends_In_Decl_Part --
601 ----------------------------------
602
603 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
604 Loc : constant Source_Ptr := Sloc (N);
605 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
606 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
607
608 All_Inputs_Seen : Elist_Id := No_Elist;
609 -- A list containing the entities of all the inputs processed so far.
610 -- The list is populated with unique entities because the same input
611 -- may appear in multiple input lists.
612
613 All_Outputs_Seen : Elist_Id := No_Elist;
614 -- A list containing the entities of all the outputs processed so far.
615 -- The list is populated with unique entities because output items are
616 -- unique in a dependence relation.
617
618 Constits_Seen : Elist_Id := No_Elist;
619 -- A list containing the entities of all constituents processed so far.
620 -- It aids in detecting illegal usage of a state and a corresponding
621 -- constituent in pragma [Refinde_]Depends.
622
623 Global_Seen : Boolean := False;
624 -- A flag set when pragma Global has been processed
625
626 Null_Output_Seen : Boolean := False;
627 -- A flag used to track the legality of a null output
628
629 Result_Seen : Boolean := False;
630 -- A flag set when Spec_Id'Result is processed
631
632 States_Seen : Elist_Id := No_Elist;
633 -- A list containing the entities of all states processed so far. It
634 -- helps in detecting illegal usage of a state and a corresponding
635 -- constituent in pragma [Refined_]Depends.
636
637 Subp_Inputs : Elist_Id := No_Elist;
638 Subp_Outputs : Elist_Id := No_Elist;
639 -- Two lists containing the full set of inputs and output of the related
640 -- subprograms. Note that these lists contain both nodes and entities.
641
642 Task_Input_Seen : Boolean := False;
643 Task_Output_Seen : Boolean := False;
644 -- Flags used to track the implicit dependence of a task unit on itself
645
646 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
647 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
648 -- to the name buffer. The individual kinds are as follows:
649 -- E_Abstract_State - "state"
650 -- E_Constant - "constant"
651 -- E_Generic_In_Out_Parameter - "generic parameter"
652 -- E_Generic_In_Parameter - "generic parameter"
653 -- E_In_Parameter - "parameter"
654 -- E_In_Out_Parameter - "parameter"
655 -- E_Loop_Parameter - "loop parameter"
656 -- E_Out_Parameter - "parameter"
657 -- E_Protected_Type - "current instance of protected type"
658 -- E_Task_Type - "current instance of task type"
659 -- E_Variable - "global"
660
661 procedure Analyze_Dependency_Clause
662 (Clause : Node_Id;
663 Is_Last : Boolean);
664 -- Verify the legality of a single dependency clause. Flag Is_Last
665 -- denotes whether Clause is the last clause in the relation.
666
667 procedure Check_Function_Return;
668 -- Verify that Funtion'Result appears as one of the outputs
669 -- (SPARK RM 6.1.5(10)).
670
671 procedure Check_Role
672 (Item : Node_Id;
673 Item_Id : Entity_Id;
674 Is_Input : Boolean;
675 Self_Ref : Boolean);
676 -- Ensure that an item fulfills its designated input and/or output role
677 -- as specified by pragma Global (if any) or the enclosing context. If
678 -- this is not the case, emit an error. Item and Item_Id denote the
679 -- attributes of an item. Flag Is_Input should be set when item comes
680 -- from an input list. Flag Self_Ref should be set when the item is an
681 -- output and the dependency clause has operator "+".
682
683 procedure Check_Usage
684 (Subp_Items : Elist_Id;
685 Used_Items : Elist_Id;
686 Is_Input : Boolean);
687 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
688 -- error if this is not the case.
689
690 procedure Normalize_Clause (Clause : Node_Id);
691 -- Remove a self-dependency "+" from the input list of a clause
692
693 -----------------------------
694 -- Add_Item_To_Name_Buffer --
695 -----------------------------
696
697 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
698 begin
699 if Ekind (Item_Id) = E_Abstract_State then
700 Add_Str_To_Name_Buffer ("state");
701
702 elsif Ekind (Item_Id) = E_Constant then
703 Add_Str_To_Name_Buffer ("constant");
704
705 elsif Ekind (Item_Id) in
706 E_Generic_In_Out_Parameter | E_Generic_In_Parameter
707 then
708 Add_Str_To_Name_Buffer ("generic parameter");
709
710 elsif Is_Formal (Item_Id) then
711 Add_Str_To_Name_Buffer ("parameter");
712
713 elsif Ekind (Item_Id) = E_Loop_Parameter then
714 Add_Str_To_Name_Buffer ("loop parameter");
715
716 elsif Ekind (Item_Id) = E_Protected_Type
717 or else Is_Single_Protected_Object (Item_Id)
718 then
719 Add_Str_To_Name_Buffer ("current instance of protected type");
720
721 elsif Ekind (Item_Id) = E_Task_Type
722 or else Is_Single_Task_Object (Item_Id)
723 then
724 Add_Str_To_Name_Buffer ("current instance of task type");
725
726 elsif Ekind (Item_Id) = E_Variable then
727 Add_Str_To_Name_Buffer ("global");
728
729 -- The routine should not be called with non-SPARK items
730
731 else
732 raise Program_Error;
733 end if;
734 end Add_Item_To_Name_Buffer;
735
736 -------------------------------
737 -- Analyze_Dependency_Clause --
738 -------------------------------
739
740 procedure Analyze_Dependency_Clause
741 (Clause : Node_Id;
742 Is_Last : Boolean)
743 is
744 procedure Analyze_Input_List (Inputs : Node_Id);
745 -- Verify the legality of a single input list
746
747 procedure Analyze_Input_Output
748 (Item : Node_Id;
749 Is_Input : Boolean;
750 Self_Ref : Boolean;
751 Top_Level : Boolean;
752 Seen : in out Elist_Id;
753 Null_Seen : in out Boolean;
754 Non_Null_Seen : in out Boolean);
755 -- Verify the legality of a single input or output item. Flag
756 -- Is_Input should be set whenever Item is an input, False when it
757 -- denotes an output. Flag Self_Ref should be set when the item is an
758 -- output and the dependency clause has a "+". Flag Top_Level should
759 -- be set whenever Item appears immediately within an input or output
760 -- list. Seen is a collection of all abstract states, objects and
761 -- formals processed so far. Flag Null_Seen denotes whether a null
762 -- input or output has been encountered. Flag Non_Null_Seen denotes
763 -- whether a non-null input or output has been encountered.
764
765 ------------------------
766 -- Analyze_Input_List --
767 ------------------------
768
769 procedure Analyze_Input_List (Inputs : Node_Id) is
770 Inputs_Seen : Elist_Id := No_Elist;
771 -- A list containing the entities of all inputs that appear in the
772 -- current input list.
773
774 Non_Null_Input_Seen : Boolean := False;
775 Null_Input_Seen : Boolean := False;
776 -- Flags used to check the legality of an input list
777
778 Input : Node_Id;
779
780 begin
781 -- Multiple inputs appear as an aggregate
782
783 if Nkind (Inputs) = N_Aggregate then
784 if Present (Component_Associations (Inputs)) then
785 SPARK_Msg_N
786 ("nested dependency relations not allowed", Inputs);
787
788 elsif Present (Expressions (Inputs)) then
789 Input := First (Expressions (Inputs));
790 while Present (Input) loop
791 Analyze_Input_Output
792 (Item => Input,
793 Is_Input => True,
794 Self_Ref => False,
795 Top_Level => False,
796 Seen => Inputs_Seen,
797 Null_Seen => Null_Input_Seen,
798 Non_Null_Seen => Non_Null_Input_Seen);
799
800 Next (Input);
801 end loop;
802
803 -- Syntax error, always report
804
805 else
806 Error_Msg_N ("malformed input dependency list", Inputs);
807 end if;
808
809 -- Process a solitary input
810
811 else
812 Analyze_Input_Output
813 (Item => Inputs,
814 Is_Input => True,
815 Self_Ref => False,
816 Top_Level => False,
817 Seen => Inputs_Seen,
818 Null_Seen => Null_Input_Seen,
819 Non_Null_Seen => Non_Null_Input_Seen);
820 end if;
821
822 -- Detect an illegal dependency clause of the form
823
824 -- (null =>[+] null)
825
826 if Null_Output_Seen and then Null_Input_Seen then
827 SPARK_Msg_N
828 ("null dependency clause cannot have a null input list",
829 Inputs);
830 end if;
831 end Analyze_Input_List;
832
833 --------------------------
834 -- Analyze_Input_Output --
835 --------------------------
836
837 procedure Analyze_Input_Output
838 (Item : Node_Id;
839 Is_Input : Boolean;
840 Self_Ref : Boolean;
841 Top_Level : Boolean;
842 Seen : in out Elist_Id;
843 Null_Seen : in out Boolean;
844 Non_Null_Seen : in out Boolean)
845 is
846 procedure Current_Task_Instance_Seen;
847 -- Set the appropriate global flag when the current instance of a
848 -- task unit is encountered.
849
850 --------------------------------
851 -- Current_Task_Instance_Seen --
852 --------------------------------
853
854 procedure Current_Task_Instance_Seen is
855 begin
856 if Is_Input then
857 Task_Input_Seen := True;
858 else
859 Task_Output_Seen := True;
860 end if;
861 end Current_Task_Instance_Seen;
862
863 -- Local variables
864
865 Is_Output : constant Boolean := not Is_Input;
866 Grouped : Node_Id;
867 Item_Id : Entity_Id;
868
869 -- Start of processing for Analyze_Input_Output
870
871 begin
872 -- Multiple input or output items appear as an aggregate
873
874 if Nkind (Item) = N_Aggregate then
875 if not Top_Level then
876 SPARK_Msg_N ("nested grouping of items not allowed", Item);
877
878 elsif Present (Component_Associations (Item)) then
879 SPARK_Msg_N
880 ("nested dependency relations not allowed", Item);
881
882 -- Recursively analyze the grouped items
883
884 elsif Present (Expressions (Item)) then
885 Grouped := First (Expressions (Item));
886 while Present (Grouped) loop
887 Analyze_Input_Output
888 (Item => Grouped,
889 Is_Input => Is_Input,
890 Self_Ref => Self_Ref,
891 Top_Level => False,
892 Seen => Seen,
893 Null_Seen => Null_Seen,
894 Non_Null_Seen => Non_Null_Seen);
895
896 Next (Grouped);
897 end loop;
898
899 -- Syntax error, always report
900
901 else
902 Error_Msg_N ("malformed dependency list", Item);
903 end if;
904
905 -- Process attribute 'Result in the context of a dependency clause
906
907 elsif Is_Attribute_Result (Item) then
908 Non_Null_Seen := True;
909
910 Analyze (Item);
911
912 -- Attribute 'Result is allowed to appear on the output side of
913 -- a dependency clause (SPARK RM 6.1.5(6)).
914
915 if Is_Input then
916 SPARK_Msg_N ("function result cannot act as input", Item);
917
918 elsif Null_Seen then
919 SPARK_Msg_N
920 ("cannot mix null and non-null dependency items", Item);
921
922 else
923 Result_Seen := True;
924 end if;
925
926 -- Detect multiple uses of null in a single dependency list or
927 -- throughout the whole relation. Verify the placement of a null
928 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
929
930 elsif Nkind (Item) = N_Null then
931 if Null_Seen then
932 SPARK_Msg_N
933 ("multiple null dependency relations not allowed", Item);
934
935 elsif Non_Null_Seen then
936 SPARK_Msg_N
937 ("cannot mix null and non-null dependency items", Item);
938
939 else
940 Null_Seen := True;
941
942 if Is_Output then
943 if not Is_Last then
944 SPARK_Msg_N
945 ("null output list must be the last clause in a "
946 & "dependency relation", Item);
947
948 -- Catch a useless dependence of the form:
949 -- null =>+ ...
950
951 elsif Self_Ref then
952 SPARK_Msg_N
953 ("useless dependence, null depends on itself", Item);
954 end if;
955 end if;
956 end if;
957
958 -- Default case
959
960 else
961 Non_Null_Seen := True;
962
963 if Null_Seen then
964 SPARK_Msg_N ("cannot mix null and non-null items", Item);
965 end if;
966
967 Analyze (Item);
968 Resolve_State (Item);
969
970 -- Find the entity of the item. If this is a renaming, climb
971 -- the renaming chain to reach the root object. Renamings of
972 -- non-entire objects do not yield an entity (Empty).
973
974 Item_Id := Entity_Of (Item);
975
976 if Present (Item_Id) then
977
978 -- Constants
979
980 if Ekind (Item_Id) in E_Constant | E_Loop_Parameter
981 or else
982
983 -- Current instances of concurrent types
984
985 Ekind (Item_Id) in E_Protected_Type | E_Task_Type
986 or else
987
988 -- Formal parameters
989
990 Ekind (Item_Id) in E_Generic_In_Out_Parameter
991 | E_Generic_In_Parameter
992 | E_In_Parameter
993 | E_In_Out_Parameter
994 | E_Out_Parameter
995 or else
996
997 -- States, variables
998
999 Ekind (Item_Id) in E_Abstract_State | E_Variable
1000 then
1001 -- A [generic] function is not allowed to have Output
1002 -- items in its dependency relations. Note that "null"
1003 -- and attribute 'Result are still valid items.
1004
1005 if Ekind (Spec_Id) in E_Function | E_Generic_Function
1006 and then not Is_Input
1007 then
1008 SPARK_Msg_N
1009 ("output item is not applicable to function", Item);
1010 end if;
1011
1012 -- The item denotes a concurrent type. Note that single
1013 -- protected/task types are not considered here because
1014 -- they behave as objects in the context of pragma
1015 -- [Refined_]Depends.
1016
1017 if Ekind (Item_Id) in E_Protected_Type | E_Task_Type then
1018
1019 -- This use is legal as long as the concurrent type is
1020 -- the current instance of an enclosing type.
1021
1022 if Is_CCT_Instance (Item_Id, Spec_Id) then
1023
1024 -- The dependence of a task unit on itself is
1025 -- implicit and may or may not be explicitly
1026 -- specified (SPARK RM 6.1.4).
1027
1028 if Ekind (Item_Id) = E_Task_Type then
1029 Current_Task_Instance_Seen;
1030 end if;
1031
1032 -- Otherwise this is not the current instance
1033
1034 else
1035 SPARK_Msg_N
1036 ("invalid use of subtype mark in dependency "
1037 & "relation", Item);
1038 end if;
1039
1040 -- The dependency of a task unit on itself is implicit
1041 -- and may or may not be explicitly specified
1042 -- (SPARK RM 6.1.4).
1043
1044 elsif Is_Single_Task_Object (Item_Id)
1045 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
1046 then
1047 Current_Task_Instance_Seen;
1048 end if;
1049
1050 -- Ensure that the item fulfills its role as input and/or
1051 -- output as specified by pragma Global or the enclosing
1052 -- context.
1053
1054 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
1055
1056 -- Detect multiple uses of the same state, variable or
1057 -- formal parameter. If this is not the case, add the
1058 -- item to the list of processed relations.
1059
1060 if Contains (Seen, Item_Id) then
1061 SPARK_Msg_NE
1062 ("duplicate use of item &", Item, Item_Id);
1063 else
1064 Append_New_Elmt (Item_Id, Seen);
1065 end if;
1066
1067 -- Detect illegal use of an input related to a null
1068 -- output. Such input items cannot appear in other
1069 -- input lists (SPARK RM 6.1.5(13)).
1070
1071 if Is_Input
1072 and then Null_Output_Seen
1073 and then Contains (All_Inputs_Seen, Item_Id)
1074 then
1075 SPARK_Msg_N
1076 ("input of a null output list cannot appear in "
1077 & "multiple input lists", Item);
1078 end if;
1079
1080 -- Add an input or a self-referential output to the list
1081 -- of all processed inputs.
1082
1083 if Is_Input or else Self_Ref then
1084 Append_New_Elmt (Item_Id, All_Inputs_Seen);
1085 end if;
1086
1087 -- State related checks (SPARK RM 6.1.5(3))
1088
1089 if Ekind (Item_Id) = E_Abstract_State then
1090
1091 -- Package and subprogram bodies are instantiated
1092 -- individually in a separate compiler pass. Due to
1093 -- this mode of instantiation, the refinement of a
1094 -- state may no longer be visible when a subprogram
1095 -- body contract is instantiated. Since the generic
1096 -- template is legal, do not perform this check in
1097 -- the instance to circumvent this oddity.
1098
1099 if In_Instance then
1100 null;
1101
1102 -- An abstract state with visible refinement cannot
1103 -- appear in pragma [Refined_]Depends as its place
1104 -- must be taken by some of its constituents
1105 -- (SPARK RM 6.1.4(7)).
1106
1107 elsif Has_Visible_Refinement (Item_Id) then
1108 SPARK_Msg_NE
1109 ("cannot mention state & in dependence relation",
1110 Item, Item_Id);
1111 SPARK_Msg_N ("\use its constituents instead", Item);
1112 return;
1113
1114 -- If the reference to the abstract state appears in
1115 -- an enclosing package body that will eventually
1116 -- refine the state, record the reference for future
1117 -- checks.
1118
1119 else
1120 Record_Possible_Body_Reference
1121 (State_Id => Item_Id,
1122 Ref => Item);
1123 end if;
1124 end if;
1125
1126 -- When the item renames an entire object, replace the
1127 -- item with a reference to the object.
1128
1129 if Entity (Item) /= Item_Id then
1130 Rewrite (Item,
1131 New_Occurrence_Of (Item_Id, Sloc (Item)));
1132 Analyze (Item);
1133 end if;
1134
1135 -- Add the entity of the current item to the list of
1136 -- processed items.
1137
1138 if Ekind (Item_Id) = E_Abstract_State then
1139 Append_New_Elmt (Item_Id, States_Seen);
1140
1141 -- The variable may eventually become a constituent of a
1142 -- single protected/task type. Record the reference now
1143 -- and verify its legality when analyzing the contract of
1144 -- the variable (SPARK RM 9.3).
1145
1146 elsif Ekind (Item_Id) = E_Variable then
1147 Record_Possible_Part_Of_Reference
1148 (Var_Id => Item_Id,
1149 Ref => Item);
1150 end if;
1151
1152 if Ekind (Item_Id) in E_Abstract_State
1153 | E_Constant
1154 | E_Variable
1155 and then Present (Encapsulating_State (Item_Id))
1156 then
1157 Append_New_Elmt (Item_Id, Constits_Seen);
1158 end if;
1159
1160 -- All other input/output items are illegal
1161 -- (SPARK RM 6.1.5(1)).
1162
1163 else
1164 SPARK_Msg_N
1165 ("item must denote parameter, variable, state or "
1166 & "current instance of concurrent type", Item);
1167 end if;
1168
1169 -- All other input/output items are illegal
1170 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1171
1172 else
1173 Error_Msg_N
1174 ("item must denote parameter, variable, state or current "
1175 & "instance of concurrent type", Item);
1176 end if;
1177 end if;
1178 end Analyze_Input_Output;
1179
1180 -- Local variables
1181
1182 Inputs : Node_Id;
1183 Output : Node_Id;
1184 Self_Ref : Boolean;
1185
1186 Non_Null_Output_Seen : Boolean := False;
1187 -- Flag used to check the legality of an output list
1188
1189 -- Start of processing for Analyze_Dependency_Clause
1190
1191 begin
1192 Inputs := Expression (Clause);
1193 Self_Ref := False;
1194
1195 -- An input list with a self-dependency appears as operator "+" where
1196 -- the actuals inputs are the right operand.
1197
1198 if Nkind (Inputs) = N_Op_Plus then
1199 Inputs := Right_Opnd (Inputs);
1200 Self_Ref := True;
1201 end if;
1202
1203 -- Process the output_list of a dependency_clause
1204
1205 Output := First (Choices (Clause));
1206 while Present (Output) loop
1207 Analyze_Input_Output
1208 (Item => Output,
1209 Is_Input => False,
1210 Self_Ref => Self_Ref,
1211 Top_Level => True,
1212 Seen => All_Outputs_Seen,
1213 Null_Seen => Null_Output_Seen,
1214 Non_Null_Seen => Non_Null_Output_Seen);
1215
1216 Next (Output);
1217 end loop;
1218
1219 -- Process the input_list of a dependency_clause
1220
1221 Analyze_Input_List (Inputs);
1222 end Analyze_Dependency_Clause;
1223
1224 ---------------------------
1225 -- Check_Function_Return --
1226 ---------------------------
1227
1228 procedure Check_Function_Return is
1229 begin
1230 if Ekind (Spec_Id) in E_Function | E_Generic_Function
1231 and then not Result_Seen
1232 then
1233 SPARK_Msg_NE
1234 ("result of & must appear in exactly one output list",
1235 N, Spec_Id);
1236 end if;
1237 end Check_Function_Return;
1238
1239 ----------------
1240 -- Check_Role --
1241 ----------------
1242
1243 procedure Check_Role
1244 (Item : Node_Id;
1245 Item_Id : Entity_Id;
1246 Is_Input : Boolean;
1247 Self_Ref : Boolean)
1248 is
1249 procedure Find_Role
1250 (Item_Is_Input : out Boolean;
1251 Item_Is_Output : out Boolean);
1252 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1253 -- Item_Is_Output are set depending on the role.
1254
1255 procedure Role_Error
1256 (Item_Is_Input : Boolean;
1257 Item_Is_Output : Boolean);
1258 -- Emit an error message concerning the incorrect use of Item in
1259 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1260 -- denote whether the item is an input and/or an output.
1261
1262 ---------------
1263 -- Find_Role --
1264 ---------------
1265
1266 procedure Find_Role
1267 (Item_Is_Input : out Boolean;
1268 Item_Is_Output : out Boolean)
1269 is
1270 -- A constant or IN parameter of access-to-variable type should be
1271 -- handled like a variable, as the underlying memory pointed-to
1272 -- can be modified. Use Adjusted_Kind to do this adjustment.
1273
1274 Adjusted_Kind : Entity_Kind := Ekind (Item_Id);
1275
1276 begin
1277 if Ekind (Item_Id) in E_Constant
1278 | E_Generic_In_Parameter
1279 | E_In_Parameter
1280 and then Is_Access_Variable (Etype (Item_Id))
1281 then
1282 Adjusted_Kind := E_Variable;
1283 end if;
1284
1285 case Adjusted_Kind is
1286
1287 -- Abstract states
1288
1289 when E_Abstract_State =>
1290
1291 -- When pragma Global is present it determines the mode of
1292 -- the abstract state.
1293
1294 if Global_Seen then
1295 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1296 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1297
1298 -- Otherwise the state has a default IN OUT mode, because it
1299 -- behaves as a variable.
1300
1301 else
1302 Item_Is_Input := True;
1303 Item_Is_Output := True;
1304 end if;
1305
1306 -- Constants and IN parameters
1307
1308 when E_Constant
1309 | E_Generic_In_Parameter
1310 | E_In_Parameter
1311 | E_Loop_Parameter
1312 =>
1313 -- When pragma Global is present it determines the mode
1314 -- of constant objects as inputs (and such objects cannot
1315 -- appear as outputs in the Global contract).
1316
1317 if Global_Seen then
1318 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1319 else
1320 Item_Is_Input := True;
1321 end if;
1322
1323 Item_Is_Output := False;
1324
1325 -- Variables and IN OUT parameters, as well as constants and
1326 -- IN parameters of access type which are handled like
1327 -- variables.
1328
1329 when E_Generic_In_Out_Parameter
1330 | E_In_Out_Parameter
1331 | E_Variable
1332 =>
1333 -- When pragma Global is present it determines the mode of
1334 -- the object.
1335
1336 if Global_Seen then
1337
1338 -- A variable has mode IN when its type is unconstrained
1339 -- or tagged because array bounds, discriminants or tags
1340 -- can be read.
1341
1342 Item_Is_Input :=
1343 Appears_In (Subp_Inputs, Item_Id)
1344 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1345
1346 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1347
1348 -- Otherwise the variable has a default IN OUT mode
1349
1350 else
1351 Item_Is_Input := True;
1352 Item_Is_Output := True;
1353 end if;
1354
1355 when E_Out_Parameter =>
1356
1357 -- An OUT parameter of the related subprogram; it cannot
1358 -- appear in Global.
1359
1360 if Scope (Item_Id) = Spec_Id then
1361
1362 -- The parameter has mode IN if its type is unconstrained
1363 -- or tagged because array bounds, discriminants or tags
1364 -- can be read.
1365
1366 Item_Is_Input :=
1367 Is_Unconstrained_Or_Tagged_Item (Item_Id);
1368
1369 Item_Is_Output := True;
1370
1371 -- An OUT parameter of an enclosing subprogram; it can
1372 -- appear in Global and behaves as a read-write variable.
1373
1374 else
1375 -- When pragma Global is present it determines the mode
1376 -- of the object.
1377
1378 if Global_Seen then
1379
1380 -- A variable has mode IN when its type is
1381 -- unconstrained or tagged because array
1382 -- bounds, discriminants or tags can be read.
1383
1384 Item_Is_Input :=
1385 Appears_In (Subp_Inputs, Item_Id)
1386 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1387
1388 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1389
1390 -- Otherwise the variable has a default IN OUT mode
1391
1392 else
1393 Item_Is_Input := True;
1394 Item_Is_Output := True;
1395 end if;
1396 end if;
1397
1398 -- Protected types
1399
1400 when E_Protected_Type =>
1401 if Global_Seen then
1402
1403 -- A variable has mode IN when its type is unconstrained
1404 -- or tagged because array bounds, discriminants or tags
1405 -- can be read.
1406
1407 Item_Is_Input :=
1408 Appears_In (Subp_Inputs, Item_Id)
1409 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1410
1411 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1412
1413 else
1414 -- A protected type acts as a formal parameter of mode IN
1415 -- when it applies to a protected function.
1416
1417 if Ekind (Spec_Id) = E_Function then
1418 Item_Is_Input := True;
1419 Item_Is_Output := False;
1420
1421 -- Otherwise the protected type acts as a formal of mode
1422 -- IN OUT.
1423
1424 else
1425 Item_Is_Input := True;
1426 Item_Is_Output := True;
1427 end if;
1428 end if;
1429
1430 -- Task types
1431
1432 when E_Task_Type =>
1433
1434 -- When pragma Global is present it determines the mode of
1435 -- the object.
1436
1437 if Global_Seen then
1438 Item_Is_Input :=
1439 Appears_In (Subp_Inputs, Item_Id)
1440 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1441
1442 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1443
1444 -- Otherwise task types act as IN OUT parameters
1445
1446 else
1447 Item_Is_Input := True;
1448 Item_Is_Output := True;
1449 end if;
1450
1451 when others =>
1452 raise Program_Error;
1453 end case;
1454 end Find_Role;
1455
1456 ----------------
1457 -- Role_Error --
1458 ----------------
1459
1460 procedure Role_Error
1461 (Item_Is_Input : Boolean;
1462 Item_Is_Output : Boolean)
1463 is
1464 Error_Msg : Name_Id;
1465
1466 begin
1467 Name_Len := 0;
1468
1469 -- When the item is not part of the input and the output set of
1470 -- the related subprogram, then it appears as extra in pragma
1471 -- [Refined_]Depends.
1472
1473 if not Item_Is_Input and then not Item_Is_Output then
1474 Add_Item_To_Name_Buffer (Item_Id);
1475 Add_Str_To_Name_Buffer
1476 (" & cannot appear in dependence relation");
1477
1478 Error_Msg := Name_Find;
1479 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1480
1481 Error_Msg_Name_1 := Chars (Spec_Id);
1482 SPARK_Msg_NE
1483 (Fix_Msg (Spec_Id, "\& is not part of the input or output "
1484 & "set of subprogram %"), Item, Item_Id);
1485
1486 -- The mode of the item and its role in pragma [Refined_]Depends
1487 -- are in conflict. Construct a detailed message explaining the
1488 -- illegality (SPARK RM 6.1.5(5-6)).
1489
1490 else
1491 if Item_Is_Input then
1492 Add_Str_To_Name_Buffer ("read-only");
1493 else
1494 Add_Str_To_Name_Buffer ("write-only");
1495 end if;
1496
1497 Add_Char_To_Name_Buffer (' ');
1498 Add_Item_To_Name_Buffer (Item_Id);
1499 Add_Str_To_Name_Buffer (" & cannot appear as ");
1500
1501 if Item_Is_Input then
1502 Add_Str_To_Name_Buffer ("output");
1503 else
1504 Add_Str_To_Name_Buffer ("input");
1505 end if;
1506
1507 Add_Str_To_Name_Buffer (" in dependence relation");
1508 Error_Msg := Name_Find;
1509 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1510 end if;
1511 end Role_Error;
1512
1513 -- Local variables
1514
1515 Item_Is_Input : Boolean;
1516 Item_Is_Output : Boolean;
1517
1518 -- Start of processing for Check_Role
1519
1520 begin
1521 Find_Role (Item_Is_Input, Item_Is_Output);
1522
1523 -- Input item
1524
1525 if Is_Input then
1526 if not Item_Is_Input then
1527 Role_Error (Item_Is_Input, Item_Is_Output);
1528 end if;
1529
1530 -- Self-referential item
1531
1532 elsif Self_Ref then
1533 if not Item_Is_Input or else not Item_Is_Output then
1534 Role_Error (Item_Is_Input, Item_Is_Output);
1535 end if;
1536
1537 -- Output item
1538
1539 elsif not Item_Is_Output then
1540 Role_Error (Item_Is_Input, Item_Is_Output);
1541 end if;
1542 end Check_Role;
1543
1544 -----------------
1545 -- Check_Usage --
1546 -----------------
1547
1548 procedure Check_Usage
1549 (Subp_Items : Elist_Id;
1550 Used_Items : Elist_Id;
1551 Is_Input : Boolean)
1552 is
1553 procedure Usage_Error (Item_Id : Entity_Id);
1554 -- Emit an error concerning the illegal usage of an item
1555
1556 -----------------
1557 -- Usage_Error --
1558 -----------------
1559
1560 procedure Usage_Error (Item_Id : Entity_Id) is
1561 Error_Msg : Name_Id;
1562
1563 begin
1564 -- Input case
1565
1566 if Is_Input then
1567
1568 -- Unconstrained and tagged items are not part of the explicit
1569 -- input set of the related subprogram, they do not have to be
1570 -- present in a dependence relation and should not be flagged
1571 -- (SPARK RM 6.1.5(5)).
1572
1573 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1574 Name_Len := 0;
1575
1576 Add_Item_To_Name_Buffer (Item_Id);
1577 Add_Str_To_Name_Buffer
1578 (" & is missing from input dependence list");
1579
1580 Error_Msg := Name_Find;
1581 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1582 SPARK_Msg_NE
1583 ("\add `null ='> &` dependency to ignore this input",
1584 N, Item_Id);
1585 end if;
1586
1587 -- Output case (SPARK RM 6.1.5(10))
1588
1589 else
1590 Name_Len := 0;
1591
1592 Add_Item_To_Name_Buffer (Item_Id);
1593 Add_Str_To_Name_Buffer
1594 (" & is missing from output dependence list");
1595
1596 Error_Msg := Name_Find;
1597 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1598 end if;
1599 end Usage_Error;
1600
1601 -- Local variables
1602
1603 Elmt : Elmt_Id;
1604 Item : Node_Id;
1605 Item_Id : Entity_Id;
1606
1607 -- Start of processing for Check_Usage
1608
1609 begin
1610 if No (Subp_Items) then
1611 return;
1612 end if;
1613
1614 -- Each input or output of the subprogram must appear in a dependency
1615 -- relation.
1616
1617 Elmt := First_Elmt (Subp_Items);
1618 while Present (Elmt) loop
1619 Item := Node (Elmt);
1620
1621 if Nkind (Item) = N_Defining_Identifier then
1622 Item_Id := Item;
1623 else
1624 Item_Id := Entity_Of (Item);
1625 end if;
1626
1627 -- The item does not appear in a dependency
1628
1629 if Present (Item_Id)
1630 and then not Contains (Used_Items, Item_Id)
1631 then
1632 if Is_Formal (Item_Id) then
1633 Usage_Error (Item_Id);
1634
1635 -- The current instance of a protected type behaves as a formal
1636 -- parameter (SPARK RM 6.1.4).
1637
1638 elsif Ekind (Item_Id) = E_Protected_Type
1639 or else Is_Single_Protected_Object (Item_Id)
1640 then
1641 Usage_Error (Item_Id);
1642
1643 -- The current instance of a task type behaves as a formal
1644 -- parameter (SPARK RM 6.1.4).
1645
1646 elsif Ekind (Item_Id) = E_Task_Type
1647 or else Is_Single_Task_Object (Item_Id)
1648 then
1649 -- The dependence of a task unit on itself is implicit and
1650 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1651 -- Emit an error if only one input/output is present.
1652
1653 if Task_Input_Seen /= Task_Output_Seen then
1654 Usage_Error (Item_Id);
1655 end if;
1656
1657 -- States and global objects are not used properly only when
1658 -- the subprogram is subject to pragma Global.
1659
1660 elsif Global_Seen then
1661 Usage_Error (Item_Id);
1662 end if;
1663 end if;
1664
1665 Next_Elmt (Elmt);
1666 end loop;
1667 end Check_Usage;
1668
1669 ----------------------
1670 -- Normalize_Clause --
1671 ----------------------
1672
1673 procedure Normalize_Clause (Clause : Node_Id) is
1674 procedure Create_Or_Modify_Clause
1675 (Output : Node_Id;
1676 Outputs : Node_Id;
1677 Inputs : Node_Id;
1678 After : Node_Id;
1679 In_Place : Boolean;
1680 Multiple : Boolean);
1681 -- Create a brand new clause to represent the self-reference or
1682 -- modify the input and/or output lists of an existing clause. Output
1683 -- denotes a self-referencial output. Outputs is the output list of a
1684 -- clause. Inputs is the input list of a clause. After denotes the
1685 -- clause after which the new clause is to be inserted. Flag In_Place
1686 -- should be set when normalizing the last output of an output list.
1687 -- Flag Multiple should be set when Output comes from a list with
1688 -- multiple items.
1689
1690 -----------------------------
1691 -- Create_Or_Modify_Clause --
1692 -----------------------------
1693
1694 procedure Create_Or_Modify_Clause
1695 (Output : Node_Id;
1696 Outputs : Node_Id;
1697 Inputs : Node_Id;
1698 After : Node_Id;
1699 In_Place : Boolean;
1700 Multiple : Boolean)
1701 is
1702 procedure Propagate_Output
1703 (Output : Node_Id;
1704 Inputs : Node_Id);
1705 -- Handle the various cases of output propagation to the input
1706 -- list. Output denotes a self-referencial output item. Inputs
1707 -- is the input list of a clause.
1708
1709 ----------------------
1710 -- Propagate_Output --
1711 ----------------------
1712
1713 procedure Propagate_Output
1714 (Output : Node_Id;
1715 Inputs : Node_Id)
1716 is
1717 function In_Input_List
1718 (Item : Entity_Id;
1719 Inputs : List_Id) return Boolean;
1720 -- Determine whether a particulat item appears in the input
1721 -- list of a clause.
1722
1723 -------------------
1724 -- In_Input_List --
1725 -------------------
1726
1727 function In_Input_List
1728 (Item : Entity_Id;
1729 Inputs : List_Id) return Boolean
1730 is
1731 Elmt : Node_Id;
1732
1733 begin
1734 Elmt := First (Inputs);
1735 while Present (Elmt) loop
1736 if Entity_Of (Elmt) = Item then
1737 return True;
1738 end if;
1739
1740 Next (Elmt);
1741 end loop;
1742
1743 return False;
1744 end In_Input_List;
1745
1746 -- Local variables
1747
1748 Output_Id : constant Entity_Id := Entity_Of (Output);
1749 Grouped : List_Id;
1750
1751 -- Start of processing for Propagate_Output
1752
1753 begin
1754 -- The clause is of the form:
1755
1756 -- (Output =>+ null)
1757
1758 -- Remove null input and replace it with a copy of the output:
1759
1760 -- (Output => Output)
1761
1762 if Nkind (Inputs) = N_Null then
1763 Rewrite (Inputs, New_Copy_Tree (Output));
1764
1765 -- The clause is of the form:
1766
1767 -- (Output =>+ (Input1, ..., InputN))
1768
1769 -- Determine whether the output is not already mentioned in the
1770 -- input list and if not, add it to the list of inputs:
1771
1772 -- (Output => (Output, Input1, ..., InputN))
1773
1774 elsif Nkind (Inputs) = N_Aggregate then
1775 Grouped := Expressions (Inputs);
1776
1777 if not In_Input_List
1778 (Item => Output_Id,
1779 Inputs => Grouped)
1780 then
1781 Prepend_To (Grouped, New_Copy_Tree (Output));
1782 end if;
1783
1784 -- The clause is of the form:
1785
1786 -- (Output =>+ Input)
1787
1788 -- If the input does not mention the output, group the two
1789 -- together:
1790
1791 -- (Output => (Output, Input))
1792
1793 elsif Entity_Of (Inputs) /= Output_Id then
1794 Rewrite (Inputs,
1795 Make_Aggregate (Loc,
1796 Expressions => New_List (
1797 New_Copy_Tree (Output),
1798 New_Copy_Tree (Inputs))));
1799 end if;
1800 end Propagate_Output;
1801
1802 -- Local variables
1803
1804 Loc : constant Source_Ptr := Sloc (Clause);
1805 New_Clause : Node_Id;
1806
1807 -- Start of processing for Create_Or_Modify_Clause
1808
1809 begin
1810 -- A null output depending on itself does not require any
1811 -- normalization.
1812
1813 if Nkind (Output) = N_Null then
1814 return;
1815
1816 -- A function result cannot depend on itself because it cannot
1817 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1818
1819 elsif Is_Attribute_Result (Output) then
1820 SPARK_Msg_N ("function result cannot depend on itself", Output);
1821 return;
1822 end if;
1823
1824 -- When performing the transformation in place, simply add the
1825 -- output to the list of inputs (if not already there). This
1826 -- case arises when dealing with the last output of an output
1827 -- list. Perform the normalization in place to avoid generating
1828 -- a malformed tree.
1829
1830 if In_Place then
1831 Propagate_Output (Output, Inputs);
1832
1833 -- A list with multiple outputs is slowly trimmed until only
1834 -- one element remains. When this happens, replace aggregate
1835 -- with the element itself.
1836
1837 if Multiple then
1838 Remove (Output);
1839 Rewrite (Outputs, Output);
1840 end if;
1841
1842 -- Default case
1843
1844 else
1845 -- Unchain the output from its output list as it will appear in
1846 -- a new clause. Note that we cannot simply rewrite the output
1847 -- as null because this will violate the semantics of pragma
1848 -- Depends.
1849
1850 Remove (Output);
1851
1852 -- Generate a new clause of the form:
1853 -- (Output => Inputs)
1854
1855 New_Clause :=
1856 Make_Component_Association (Loc,
1857 Choices => New_List (Output),
1858 Expression => New_Copy_Tree (Inputs));
1859
1860 -- The new clause contains replicated content that has already
1861 -- been analyzed. There is not need to reanalyze or renormalize
1862 -- it again.
1863
1864 Set_Analyzed (New_Clause);
1865
1866 Propagate_Output
1867 (Output => First (Choices (New_Clause)),
1868 Inputs => Expression (New_Clause));
1869
1870 Insert_After (After, New_Clause);
1871 end if;
1872 end Create_Or_Modify_Clause;
1873
1874 -- Local variables
1875
1876 Outputs : constant Node_Id := First (Choices (Clause));
1877 Inputs : Node_Id;
1878 Last_Output : Node_Id;
1879 Next_Output : Node_Id;
1880 Output : Node_Id;
1881
1882 -- Start of processing for Normalize_Clause
1883
1884 begin
1885 -- A self-dependency appears as operator "+". Remove the "+" from the
1886 -- tree by moving the real inputs to their proper place.
1887
1888 if Nkind (Expression (Clause)) = N_Op_Plus then
1889 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1890 Inputs := Expression (Clause);
1891
1892 -- Multiple outputs appear as an aggregate
1893
1894 if Nkind (Outputs) = N_Aggregate then
1895 Last_Output := Last (Expressions (Outputs));
1896
1897 Output := First (Expressions (Outputs));
1898 while Present (Output) loop
1899
1900 -- Normalization may remove an output from its list,
1901 -- preserve the subsequent output now.
1902
1903 Next_Output := Next (Output);
1904
1905 Create_Or_Modify_Clause
1906 (Output => Output,
1907 Outputs => Outputs,
1908 Inputs => Inputs,
1909 After => Clause,
1910 In_Place => Output = Last_Output,
1911 Multiple => True);
1912
1913 Output := Next_Output;
1914 end loop;
1915
1916 -- Solitary output
1917
1918 else
1919 Create_Or_Modify_Clause
1920 (Output => Outputs,
1921 Outputs => Empty,
1922 Inputs => Inputs,
1923 After => Empty,
1924 In_Place => True,
1925 Multiple => False);
1926 end if;
1927 end if;
1928 end Normalize_Clause;
1929
1930 -- Local variables
1931
1932 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
1933 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1934
1935 Clause : Node_Id;
1936 Errors : Nat;
1937 Last_Clause : Node_Id;
1938 Restore_Scope : Boolean := False;
1939
1940 -- Start of processing for Analyze_Depends_In_Decl_Part
1941
1942 begin
1943 -- Do not analyze the pragma multiple times
1944
1945 if Is_Analyzed_Pragma (N) then
1946 return;
1947 end if;
1948
1949 -- Empty dependency list
1950
1951 if Nkind (Deps) = N_Null then
1952
1953 -- Gather all states, objects and formal parameters that the
1954 -- subprogram may depend on. These items are obtained from the
1955 -- parameter profile or pragma [Refined_]Global (if available).
1956
1957 Collect_Subprogram_Inputs_Outputs
1958 (Subp_Id => Subp_Id,
1959 Subp_Inputs => Subp_Inputs,
1960 Subp_Outputs => Subp_Outputs,
1961 Global_Seen => Global_Seen);
1962
1963 -- Verify that every input or output of the subprogram appear in a
1964 -- dependency.
1965
1966 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1967 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1968 Check_Function_Return;
1969
1970 -- Dependency clauses appear as component associations of an aggregate
1971
1972 elsif Nkind (Deps) = N_Aggregate then
1973
1974 -- Do not attempt to perform analysis of a syntactically illegal
1975 -- clause as this will lead to misleading errors.
1976
1977 if Has_Extra_Parentheses (Deps) then
1978 goto Leave;
1979 end if;
1980
1981 if Present (Component_Associations (Deps)) then
1982 Last_Clause := Last (Component_Associations (Deps));
1983
1984 -- Gather all states, objects and formal parameters that the
1985 -- subprogram may depend on. These items are obtained from the
1986 -- parameter profile or pragma [Refined_]Global (if available).
1987
1988 Collect_Subprogram_Inputs_Outputs
1989 (Subp_Id => Subp_Id,
1990 Subp_Inputs => Subp_Inputs,
1991 Subp_Outputs => Subp_Outputs,
1992 Global_Seen => Global_Seen);
1993
1994 -- When pragma [Refined_]Depends appears on a single concurrent
1995 -- type, it is relocated to the anonymous object.
1996
1997 if Is_Single_Concurrent_Object (Spec_Id) then
1998 null;
1999
2000 -- Ensure that the formal parameters are visible when analyzing
2001 -- all clauses. This falls out of the general rule of aspects
2002 -- pertaining to subprogram declarations.
2003
2004 elsif not In_Open_Scopes (Spec_Id) then
2005 Restore_Scope := True;
2006 Push_Scope (Spec_Id);
2007
2008 if Ekind (Spec_Id) = E_Task_Type then
2009
2010 -- Task discriminants cannot appear in the [Refined_]Depends
2011 -- contract, but must be present for the analysis so that we
2012 -- can reject them with an informative error message.
2013
2014 if Has_Discriminants (Spec_Id) then
2015 Install_Discriminants (Spec_Id);
2016 end if;
2017
2018 elsif Is_Generic_Subprogram (Spec_Id) then
2019 Install_Generic_Formals (Spec_Id);
2020
2021 else
2022 Install_Formals (Spec_Id);
2023 end if;
2024 end if;
2025
2026 Clause := First (Component_Associations (Deps));
2027 while Present (Clause) loop
2028 Errors := Serious_Errors_Detected;
2029
2030 -- The normalization mechanism may create extra clauses that
2031 -- contain replicated input and output names. There is no need
2032 -- to reanalyze them.
2033
2034 if not Analyzed (Clause) then
2035 Set_Analyzed (Clause);
2036
2037 Analyze_Dependency_Clause
2038 (Clause => Clause,
2039 Is_Last => Clause = Last_Clause);
2040 end if;
2041
2042 -- Do not normalize a clause if errors were detected (count
2043 -- of Serious_Errors has increased) because the inputs and/or
2044 -- outputs may denote illegal items.
2045
2046 if Serious_Errors_Detected = Errors then
2047 Normalize_Clause (Clause);
2048 end if;
2049
2050 Next (Clause);
2051 end loop;
2052
2053 if Restore_Scope then
2054 End_Scope;
2055 end if;
2056
2057 -- Verify that every input or output of the subprogram appear in a
2058 -- dependency.
2059
2060 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
2061 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
2062 Check_Function_Return;
2063
2064 -- The dependency list is malformed. This is a syntax error, always
2065 -- report.
2066
2067 else
2068 Error_Msg_N ("malformed dependency relation", Deps);
2069 goto Leave;
2070 end if;
2071
2072 -- The top level dependency relation is malformed. This is a syntax
2073 -- error, always report.
2074
2075 else
2076 Error_Msg_N ("malformed dependency relation", Deps);
2077 goto Leave;
2078 end if;
2079
2080 -- Ensure that a state and a corresponding constituent do not appear
2081 -- together in pragma [Refined_]Depends.
2082
2083 Check_State_And_Constituent_Use
2084 (States => States_Seen,
2085 Constits => Constits_Seen,
2086 Context => N);
2087
2088 <<Leave>>
2089 Set_Is_Analyzed_Pragma (N);
2090 end Analyze_Depends_In_Decl_Part;
2091
2092 --------------------------------------------
2093 -- Analyze_External_Property_In_Decl_Part --
2094 --------------------------------------------
2095
2096 procedure Analyze_External_Property_In_Decl_Part
2097 (N : Node_Id;
2098 Expr_Val : out Boolean)
2099 is
2100 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pragma_Name (N));
2101 Arg1 : constant Node_Id :=
2102 First (Pragma_Argument_Associations (N));
2103 Obj_Decl : constant Node_Id := Find_Related_Context (N);
2104 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
2105 Expr : Node_Id;
2106
2107 begin
2108 -- Do not analyze the pragma multiple times, but set the output
2109 -- parameter to the argument specified by the pragma.
2110
2111 if Is_Analyzed_Pragma (N) then
2112 goto Leave;
2113 end if;
2114
2115 Error_Msg_Name_1 := Pragma_Name (N);
2116
2117 -- An external property pragma must apply to an effectively volatile
2118 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
2119 -- The check is performed at the end of the declarative region due to a
2120 -- possible out-of-order arrangement of pragmas:
2121
2122 -- Obj : ...;
2123 -- pragma Async_Readers (Obj);
2124 -- pragma Volatile (Obj);
2125
2126 if Prag_Id /= Pragma_No_Caching
2127 and then not Is_Effectively_Volatile (Obj_Id)
2128 then
2129 if Ekind (Obj_Id) = E_Variable
2130 and then No_Caching_Enabled (Obj_Id)
2131 then
2132 SPARK_Msg_N
2133 ("illegal combination of external property % and property "
2134 & """No_Caching"" (SPARK RM 7.1.2(6))", N);
2135 else
2136 SPARK_Msg_N
2137 ("external property % must apply to a volatile type or object",
2138 N);
2139 end if;
2140
2141 -- Pragma No_Caching should only apply to volatile variables of
2142 -- a non-effectively volatile type (SPARK RM 7.1.2).
2143
2144 elsif Prag_Id = Pragma_No_Caching then
2145 if Is_Effectively_Volatile (Etype (Obj_Id)) then
2146 SPARK_Msg_N ("property % must not apply to an object of "
2147 & "an effectively volatile type", N);
2148 elsif not Is_Volatile (Obj_Id) then
2149 SPARK_Msg_N ("property % must apply to a volatile object", N);
2150 end if;
2151 end if;
2152
2153 Set_Is_Analyzed_Pragma (N);
2154
2155 <<Leave>>
2156
2157 -- Ensure that the Boolean expression (if present) is static. A missing
2158 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2159
2160 Expr_Val := True;
2161
2162 if Present (Arg1) then
2163 Expr := Get_Pragma_Arg (Arg1);
2164
2165 if Is_OK_Static_Expression (Expr) then
2166 Expr_Val := Is_True (Expr_Value (Expr));
2167 end if;
2168 end if;
2169
2170 end Analyze_External_Property_In_Decl_Part;
2171
2172 ---------------------------------
2173 -- Analyze_Global_In_Decl_Part --
2174 ---------------------------------
2175
2176 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
2177 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2178 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2179 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2180
2181 Constits_Seen : Elist_Id := No_Elist;
2182 -- A list containing the entities of all constituents processed so far.
2183 -- It aids in detecting illegal usage of a state and a corresponding
2184 -- constituent in pragma [Refinde_]Global.
2185
2186 Seen : Elist_Id := No_Elist;
2187 -- A list containing the entities of all the items processed so far. It
2188 -- plays a role in detecting distinct entities.
2189
2190 States_Seen : Elist_Id := No_Elist;
2191 -- A list containing the entities of all states processed so far. It
2192 -- helps in detecting illegal usage of a state and a corresponding
2193 -- constituent in pragma [Refined_]Global.
2194
2195 In_Out_Seen : Boolean := False;
2196 Input_Seen : Boolean := False;
2197 Output_Seen : Boolean := False;
2198 Proof_Seen : Boolean := False;
2199 -- Flags used to verify the consistency of modes
2200
2201 procedure Analyze_Global_List
2202 (List : Node_Id;
2203 Global_Mode : Name_Id := Name_Input);
2204 -- Verify the legality of a single global list declaration. Global_Mode
2205 -- denotes the current mode in effect.
2206
2207 -------------------------
2208 -- Analyze_Global_List --
2209 -------------------------
2210
2211 procedure Analyze_Global_List
2212 (List : Node_Id;
2213 Global_Mode : Name_Id := Name_Input)
2214 is
2215 procedure Analyze_Global_Item
2216 (Item : Node_Id;
2217 Global_Mode : Name_Id);
2218 -- Verify the legality of a single global item declaration denoted by
2219 -- Item. Global_Mode denotes the current mode in effect.
2220
2221 procedure Check_Duplicate_Mode
2222 (Mode : Node_Id;
2223 Status : in out Boolean);
2224 -- Flag Status denotes whether a particular mode has been seen while
2225 -- processing a global list. This routine verifies that Mode is not a
2226 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2227
2228 procedure Check_Mode_Restriction_In_Enclosing_Context
2229 (Item : Node_Id;
2230 Item_Id : Entity_Id);
2231 -- Verify that an item of mode In_Out or Output does not appear as
2232 -- an input in the Global aspect of an enclosing subprogram or task
2233 -- unit. If this is the case, emit an error. Item and Item_Id are
2234 -- respectively the item and its entity.
2235
2236 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
2237 -- Mode denotes either In_Out or Output. Depending on the kind of the
2238 -- related subprogram, emit an error if those two modes apply to a
2239 -- function (SPARK RM 6.1.4(10)).
2240
2241 -------------------------
2242 -- Analyze_Global_Item --
2243 -------------------------
2244
2245 procedure Analyze_Global_Item
2246 (Item : Node_Id;
2247 Global_Mode : Name_Id)
2248 is
2249 Item_Id : Entity_Id;
2250
2251 begin
2252 -- Detect one of the following cases
2253
2254 -- with Global => (null, Name)
2255 -- with Global => (Name_1, null, Name_2)
2256 -- with Global => (Name, null)
2257
2258 if Nkind (Item) = N_Null then
2259 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
2260 return;
2261 end if;
2262
2263 Analyze (Item);
2264 Resolve_State (Item);
2265
2266 -- Find the entity of the item. If this is a renaming, climb the
2267 -- renaming chain to reach the root object. Renamings of non-
2268 -- entire objects do not yield an entity (Empty).
2269
2270 Item_Id := Entity_Of (Item);
2271
2272 if Present (Item_Id) then
2273
2274 -- A global item may denote a formal parameter of an enclosing
2275 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2276 -- provide a better error diagnostic.
2277
2278 if Is_Formal (Item_Id) then
2279 if Scope (Item_Id) = Spec_Id then
2280 SPARK_Msg_NE
2281 (Fix_Msg (Spec_Id, "global item cannot reference "
2282 & "parameter of subprogram &"), Item, Spec_Id);
2283 return;
2284 end if;
2285
2286 -- A global item may denote a concurrent type as long as it is
2287 -- the current instance of an enclosing protected or task type
2288 -- (SPARK RM 6.1.4).
2289
2290 elsif Ekind (Item_Id) in E_Protected_Type | E_Task_Type then
2291 if Is_CCT_Instance (Item_Id, Spec_Id) then
2292
2293 -- Pragma [Refined_]Global associated with a protected
2294 -- subprogram cannot mention the current instance of a
2295 -- protected type because the instance behaves as a
2296 -- formal parameter.
2297
2298 if Ekind (Item_Id) = E_Protected_Type then
2299 if Scope (Spec_Id) = Item_Id then
2300 Error_Msg_Name_1 := Chars (Item_Id);
2301 SPARK_Msg_NE
2302 (Fix_Msg (Spec_Id, "global item of subprogram & "
2303 & "cannot reference current instance of "
2304 & "protected type %"), Item, Spec_Id);
2305 return;
2306 end if;
2307
2308 -- Pragma [Refined_]Global associated with a task type
2309 -- cannot mention the current instance of a task type
2310 -- because the instance behaves as a formal parameter.
2311
2312 else pragma Assert (Ekind (Item_Id) = E_Task_Type);
2313 if Spec_Id = Item_Id then
2314 Error_Msg_Name_1 := Chars (Item_Id);
2315 SPARK_Msg_NE
2316 (Fix_Msg (Spec_Id, "global item of subprogram & "
2317 & "cannot reference current instance of task "
2318 & "type %"), Item, Spec_Id);
2319 return;
2320 end if;
2321 end if;
2322
2323 -- Otherwise the global item denotes a subtype mark that is
2324 -- not a current instance.
2325
2326 else
2327 SPARK_Msg_N
2328 ("invalid use of subtype mark in global list", Item);
2329 return;
2330 end if;
2331
2332 -- A global item may denote the anonymous object created for a
2333 -- single protected/task type as long as the current instance
2334 -- is the same single type (SPARK RM 6.1.4).
2335
2336 elsif Is_Single_Concurrent_Object (Item_Id)
2337 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
2338 then
2339 -- Pragma [Refined_]Global associated with a protected
2340 -- subprogram cannot mention the current instance of a
2341 -- protected type because the instance behaves as a formal
2342 -- parameter.
2343
2344 if Is_Single_Protected_Object (Item_Id) then
2345 if Scope (Spec_Id) = Etype (Item_Id) then
2346 Error_Msg_Name_1 := Chars (Item_Id);
2347 SPARK_Msg_NE
2348 (Fix_Msg (Spec_Id, "global item of subprogram & "
2349 & "cannot reference current instance of protected "
2350 & "type %"), Item, Spec_Id);
2351 return;
2352 end if;
2353
2354 -- Pragma [Refined_]Global associated with a task type
2355 -- cannot mention the current instance of a task type
2356 -- because the instance behaves as a formal parameter.
2357
2358 else pragma Assert (Is_Single_Task_Object (Item_Id));
2359 if Spec_Id = Item_Id then
2360 Error_Msg_Name_1 := Chars (Item_Id);
2361 SPARK_Msg_NE
2362 (Fix_Msg (Spec_Id, "global item of subprogram & "
2363 & "cannot reference current instance of task "
2364 & "type %"), Item, Spec_Id);
2365 return;
2366 end if;
2367 end if;
2368
2369 -- A formal object may act as a global item inside a generic
2370
2371 elsif Is_Formal_Object (Item_Id) then
2372 null;
2373
2374 -- The only legal references are those to abstract states,
2375 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2376
2377 elsif Ekind (Item_Id) not in E_Abstract_State
2378 | E_Constant
2379 | E_Loop_Parameter
2380 | E_Variable
2381 then
2382 SPARK_Msg_N
2383 ("global item must denote object, state or current "
2384 & "instance of concurrent type", Item);
2385
2386 if Is_Named_Number (Item_Id) then
2387 SPARK_Msg_NE
2388 ("\named number & is not an object", Item, Item_Id);
2389 end if;
2390
2391 return;
2392 end if;
2393
2394 -- State related checks
2395
2396 if Ekind (Item_Id) = E_Abstract_State then
2397
2398 -- Package and subprogram bodies are instantiated
2399 -- individually in a separate compiler pass. Due to this
2400 -- mode of instantiation, the refinement of a state may
2401 -- no longer be visible when a subprogram body contract
2402 -- is instantiated. Since the generic template is legal,
2403 -- do not perform this check in the instance to circumvent
2404 -- this oddity.
2405
2406 if In_Instance then
2407 null;
2408
2409 -- An abstract state with visible refinement cannot appear
2410 -- in pragma [Refined_]Global as its place must be taken by
2411 -- some of its constituents (SPARK RM 6.1.4(7)).
2412
2413 elsif Has_Visible_Refinement (Item_Id) then
2414 SPARK_Msg_NE
2415 ("cannot mention state & in global refinement",
2416 Item, Item_Id);
2417 SPARK_Msg_N ("\use its constituents instead", Item);
2418 return;
2419
2420 -- An external state cannot appear as a global item of a
2421 -- nonvolatile function (SPARK RM 7.1.3(8)).
2422
2423 elsif Is_External_State (Item_Id)
2424 and then Ekind (Spec_Id) in E_Function | E_Generic_Function
2425 and then not Is_Volatile_Function (Spec_Id)
2426 then
2427 SPARK_Msg_NE
2428 ("external state & cannot act as global item of "
2429 & "nonvolatile function", Item, Item_Id);
2430 return;
2431
2432 -- If the reference to the abstract state appears in an
2433 -- enclosing package body that will eventually refine the
2434 -- state, record the reference for future checks.
2435
2436 else
2437 Record_Possible_Body_Reference
2438 (State_Id => Item_Id,
2439 Ref => Item);
2440 end if;
2441
2442 -- Constant related checks
2443
2444 elsif Ekind (Item_Id) = E_Constant
2445 and then not Is_Access_Type (Etype (Item_Id))
2446 then
2447
2448 -- Unless it is of an access type, a constant is a read-only
2449 -- item, therefore it cannot act as an output.
2450
2451 if Global_Mode in Name_In_Out | Name_Output then
2452 SPARK_Msg_NE
2453 ("constant & cannot act as output", Item, Item_Id);
2454 return;
2455 end if;
2456
2457 -- Loop parameter related checks
2458
2459 elsif Ekind (Item_Id) = E_Loop_Parameter then
2460
2461 -- A loop parameter is a read-only item, therefore it cannot
2462 -- act as an output.
2463
2464 if Global_Mode in Name_In_Out | Name_Output then
2465 SPARK_Msg_NE
2466 ("loop parameter & cannot act as output",
2467 Item, Item_Id);
2468 return;
2469 end if;
2470
2471 -- Variable related checks. These are only relevant when
2472 -- SPARK_Mode is on as they are not standard Ada legality
2473 -- rules.
2474
2475 elsif SPARK_Mode = On
2476 and then Ekind (Item_Id) = E_Variable
2477 and then Is_Effectively_Volatile_For_Reading (Item_Id)
2478 then
2479 -- The current instance of a protected unit is not an
2480 -- effectively volatile object, unless the protected unit
2481 -- is already volatile for another reason (SPARK RM 7.1.2).
2482
2483 if Is_Single_Protected_Object (Item_Id)
2484 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
2485 and then not Is_Effectively_Volatile_For_Reading
2486 (Item_Id, Ignore_Protected => True)
2487 then
2488 null;
2489
2490 -- An effectively volatile object for reading cannot appear
2491 -- as a global item of a nonvolatile function (SPARK RM
2492 -- 7.1.3(8)).
2493
2494 elsif Ekind (Spec_Id) in E_Function | E_Generic_Function
2495 and then not Is_Volatile_Function (Spec_Id)
2496 then
2497 Error_Msg_NE
2498 ("volatile object & cannot act as global item of a "
2499 & "function", Item, Item_Id);
2500 return;
2501
2502 -- An effectively volatile object with external property
2503 -- Effective_Reads set to True must have mode Output or
2504 -- In_Out (SPARK RM 7.1.3(10)).
2505
2506 elsif Effective_Reads_Enabled (Item_Id)
2507 and then Global_Mode = Name_Input
2508 then
2509 Error_Msg_NE
2510 ("volatile object & with property Effective_Reads must "
2511 & "have mode In_Out or Output", Item, Item_Id);
2512 return;
2513 end if;
2514 end if;
2515
2516 -- When the item renames an entire object, replace the item
2517 -- with a reference to the object.
2518
2519 if Entity (Item) /= Item_Id then
2520 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2521 Analyze (Item);
2522 end if;
2523
2524 -- Some form of illegal construct masquerading as a name
2525 -- (SPARK RM 6.1.4(4)).
2526
2527 else
2528 Error_Msg_N
2529 ("global item must denote object, state or current instance "
2530 & "of concurrent type", Item);
2531 return;
2532 end if;
2533
2534 -- Verify that an output does not appear as an input in an
2535 -- enclosing subprogram.
2536
2537 if Global_Mode in Name_In_Out | Name_Output then
2538 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2539 end if;
2540
2541 -- The same entity might be referenced through various way.
2542 -- Check the entity of the item rather than the item itself
2543 -- (SPARK RM 6.1.4(10)).
2544
2545 if Contains (Seen, Item_Id) then
2546 SPARK_Msg_N ("duplicate global item", Item);
2547
2548 -- Add the entity of the current item to the list of processed
2549 -- items.
2550
2551 else
2552 Append_New_Elmt (Item_Id, Seen);
2553
2554 if Ekind (Item_Id) = E_Abstract_State then
2555 Append_New_Elmt (Item_Id, States_Seen);
2556
2557 -- The variable may eventually become a constituent of a single
2558 -- protected/task type. Record the reference now and verify its
2559 -- legality when analyzing the contract of the variable
2560 -- (SPARK RM 9.3).
2561
2562 elsif Ekind (Item_Id) = E_Variable then
2563 Record_Possible_Part_Of_Reference
2564 (Var_Id => Item_Id,
2565 Ref => Item);
2566 end if;
2567
2568 if Ekind (Item_Id) in E_Abstract_State | E_Constant | E_Variable
2569 and then Present (Encapsulating_State (Item_Id))
2570 then
2571 Append_New_Elmt (Item_Id, Constits_Seen);
2572 end if;
2573 end if;
2574 end Analyze_Global_Item;
2575
2576 --------------------------
2577 -- Check_Duplicate_Mode --
2578 --------------------------
2579
2580 procedure Check_Duplicate_Mode
2581 (Mode : Node_Id;
2582 Status : in out Boolean)
2583 is
2584 begin
2585 if Status then
2586 SPARK_Msg_N ("duplicate global mode", Mode);
2587 end if;
2588
2589 Status := True;
2590 end Check_Duplicate_Mode;
2591
2592 -------------------------------------------------
2593 -- Check_Mode_Restriction_In_Enclosing_Context --
2594 -------------------------------------------------
2595
2596 procedure Check_Mode_Restriction_In_Enclosing_Context
2597 (Item : Node_Id;
2598 Item_Id : Entity_Id)
2599 is
2600 Context : Entity_Id;
2601 Dummy : Boolean;
2602 Inputs : Elist_Id := No_Elist;
2603 Outputs : Elist_Id := No_Elist;
2604
2605 begin
2606 -- Traverse the scope stack looking for enclosing subprograms or
2607 -- tasks subject to pragma [Refined_]Global.
2608
2609 Context := Scope (Subp_Id);
2610 while Present (Context) and then Context /= Standard_Standard loop
2611
2612 -- For a single task type, retrieve the corresponding object to
2613 -- which pragma [Refined_]Global is attached.
2614
2615 if Ekind (Context) = E_Task_Type
2616 and then Is_Single_Concurrent_Type (Context)
2617 then
2618 Context := Anonymous_Object (Context);
2619 end if;
2620
2621 if (Is_Subprogram (Context)
2622 or else Ekind (Context) = E_Task_Type
2623 or else Is_Single_Task_Object (Context))
2624 and then
2625 (Present (Get_Pragma (Context, Pragma_Global))
2626 or else
2627 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2628 then
2629 Collect_Subprogram_Inputs_Outputs
2630 (Subp_Id => Context,
2631 Subp_Inputs => Inputs,
2632 Subp_Outputs => Outputs,
2633 Global_Seen => Dummy);
2634
2635 -- The item is classified as In_Out or Output but appears as
2636 -- an Input in an enclosing subprogram or task unit (SPARK
2637 -- RM 6.1.4(12)).
2638
2639 if Appears_In (Inputs, Item_Id)
2640 and then not Appears_In (Outputs, Item_Id)
2641 then
2642 SPARK_Msg_NE
2643 ("global item & cannot have mode In_Out or Output",
2644 Item, Item_Id);
2645
2646 if Is_Subprogram (Context) then
2647 SPARK_Msg_NE
2648 (Fix_Msg (Subp_Id, "\item already appears as input "
2649 & "of subprogram &"), Item, Context);
2650 else
2651 SPARK_Msg_NE
2652 (Fix_Msg (Subp_Id, "\item already appears as input "
2653 & "of task &"), Item, Context);
2654 end if;
2655
2656 -- Stop the traversal once an error has been detected
2657
2658 exit;
2659 end if;
2660 end if;
2661
2662 Context := Scope (Context);
2663 end loop;
2664 end Check_Mode_Restriction_In_Enclosing_Context;
2665
2666 ----------------------------------------
2667 -- Check_Mode_Restriction_In_Function --
2668 ----------------------------------------
2669
2670 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2671 begin
2672 if Ekind (Spec_Id) in E_Function | E_Generic_Function then
2673 SPARK_Msg_N
2674 ("global mode & is not applicable to functions", Mode);
2675 end if;
2676 end Check_Mode_Restriction_In_Function;
2677
2678 -- Local variables
2679
2680 Assoc : Node_Id;
2681 Item : Node_Id;
2682 Mode : Node_Id;
2683
2684 -- Start of processing for Analyze_Global_List
2685
2686 begin
2687 if Nkind (List) = N_Null then
2688 Set_Analyzed (List);
2689
2690 -- Single global item declaration
2691
2692 elsif Nkind (List) in N_Expanded_Name
2693 | N_Identifier
2694 | N_Selected_Component
2695 then
2696 Analyze_Global_Item (List, Global_Mode);
2697
2698 -- Simple global list or moded global list declaration
2699
2700 elsif Nkind (List) = N_Aggregate then
2701 Set_Analyzed (List);
2702
2703 -- The declaration of a simple global list appear as a collection
2704 -- of expressions.
2705
2706 if Present (Expressions (List)) then
2707 if Present (Component_Associations (List)) then
2708 SPARK_Msg_N
2709 ("cannot mix moded and non-moded global lists", List);
2710 end if;
2711
2712 Item := First (Expressions (List));
2713 while Present (Item) loop
2714 Analyze_Global_Item (Item, Global_Mode);
2715 Next (Item);
2716 end loop;
2717
2718 -- The declaration of a moded global list appears as a collection
2719 -- of component associations where individual choices denote
2720 -- modes.
2721
2722 elsif Present (Component_Associations (List)) then
2723 if Present (Expressions (List)) then
2724 SPARK_Msg_N
2725 ("cannot mix moded and non-moded global lists", List);
2726 end if;
2727
2728 Assoc := First (Component_Associations (List));
2729 while Present (Assoc) loop
2730 Mode := First (Choices (Assoc));
2731
2732 if Nkind (Mode) = N_Identifier then
2733 if Chars (Mode) = Name_In_Out then
2734 Check_Duplicate_Mode (Mode, In_Out_Seen);
2735 Check_Mode_Restriction_In_Function (Mode);
2736
2737 elsif Chars (Mode) = Name_Input then
2738 Check_Duplicate_Mode (Mode, Input_Seen);
2739
2740 elsif Chars (Mode) = Name_Output then
2741 Check_Duplicate_Mode (Mode, Output_Seen);
2742 Check_Mode_Restriction_In_Function (Mode);
2743
2744 elsif Chars (Mode) = Name_Proof_In then
2745 Check_Duplicate_Mode (Mode, Proof_Seen);
2746
2747 else
2748 SPARK_Msg_N ("invalid mode selector", Mode);
2749 end if;
2750
2751 else
2752 SPARK_Msg_N ("invalid mode selector", Mode);
2753 end if;
2754
2755 -- Items in a moded list appear as a collection of
2756 -- expressions. Reuse the existing machinery to analyze
2757 -- them.
2758
2759 Analyze_Global_List
2760 (List => Expression (Assoc),
2761 Global_Mode => Chars (Mode));
2762
2763 Next (Assoc);
2764 end loop;
2765
2766 -- Invalid tree
2767
2768 else
2769 raise Program_Error;
2770 end if;
2771
2772 -- Any other attempt to declare a global item is illegal. This is a
2773 -- syntax error, always report.
2774
2775 else
2776 Error_Msg_N ("malformed global list", List);
2777 end if;
2778 end Analyze_Global_List;
2779
2780 -- Local variables
2781
2782 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2783
2784 Restore_Scope : Boolean := False;
2785
2786 -- Start of processing for Analyze_Global_In_Decl_Part
2787
2788 begin
2789 -- Do not analyze the pragma multiple times
2790
2791 if Is_Analyzed_Pragma (N) then
2792 return;
2793 end if;
2794
2795 -- There is nothing to be done for a null global list
2796
2797 if Nkind (Items) = N_Null then
2798 Set_Analyzed (Items);
2799
2800 -- Analyze the various forms of global lists and items. Note that some
2801 -- of these may be malformed in which case the analysis emits error
2802 -- messages.
2803
2804 else
2805 -- When pragma [Refined_]Global appears on a single concurrent type,
2806 -- it is relocated to the anonymous object.
2807
2808 if Is_Single_Concurrent_Object (Spec_Id) then
2809 null;
2810
2811 -- Ensure that the formal parameters are visible when processing an
2812 -- item. This falls out of the general rule of aspects pertaining to
2813 -- subprogram declarations.
2814
2815 elsif not In_Open_Scopes (Spec_Id) then
2816 Restore_Scope := True;
2817 Push_Scope (Spec_Id);
2818
2819 if Ekind (Spec_Id) = E_Task_Type then
2820
2821 -- Task discriminants cannot appear in the [Refined_]Global
2822 -- contract, but must be present for the analysis so that we
2823 -- can reject them with an informative error message.
2824
2825 if Has_Discriminants (Spec_Id) then
2826 Install_Discriminants (Spec_Id);
2827 end if;
2828
2829 elsif Is_Generic_Subprogram (Spec_Id) then
2830 Install_Generic_Formals (Spec_Id);
2831
2832 else
2833 Install_Formals (Spec_Id);
2834 end if;
2835 end if;
2836
2837 Analyze_Global_List (Items);
2838
2839 if Restore_Scope then
2840 End_Scope;
2841 end if;
2842 end if;
2843
2844 -- Ensure that a state and a corresponding constituent do not appear
2845 -- together in pragma [Refined_]Global.
2846
2847 Check_State_And_Constituent_Use
2848 (States => States_Seen,
2849 Constits => Constits_Seen,
2850 Context => N);
2851
2852 Set_Is_Analyzed_Pragma (N);
2853 end Analyze_Global_In_Decl_Part;
2854
2855 --------------------------------------------
2856 -- Analyze_Initial_Condition_In_Decl_Part --
2857 --------------------------------------------
2858
2859 -- WARNING: This routine manages Ghost regions. Return statements must be
2860 -- replaced by gotos which jump to the end of the routine and restore the
2861 -- Ghost mode.
2862
2863 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2864 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2865 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2866 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2867
2868 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
2869 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
2870 -- Save the Ghost-related attributes to restore on exit
2871
2872 begin
2873 -- Do not analyze the pragma multiple times
2874
2875 if Is_Analyzed_Pragma (N) then
2876 return;
2877 end if;
2878
2879 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2880 -- analysis of the pragma, the Ghost mode at point of declaration and
2881 -- point of analysis may not necessarily be the same. Use the mode in
2882 -- effect at the point of declaration.
2883
2884 Set_Ghost_Mode (N);
2885
2886 -- The expression is preanalyzed because it has not been moved to its
2887 -- final place yet. A direct analysis may generate side effects and this
2888 -- is not desired at this point.
2889
2890 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2891 Set_Is_Analyzed_Pragma (N);
2892
2893 Restore_Ghost_Region (Saved_GM, Saved_IGR);
2894 end Analyze_Initial_Condition_In_Decl_Part;
2895
2896 --------------------------------------
2897 -- Analyze_Initializes_In_Decl_Part --
2898 --------------------------------------
2899
2900 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2901 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2902 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2903
2904 Constits_Seen : Elist_Id := No_Elist;
2905 -- A list containing the entities of all constituents processed so far.
2906 -- It aids in detecting illegal usage of a state and a corresponding
2907 -- constituent in pragma Initializes.
2908
2909 Items_Seen : Elist_Id := No_Elist;
2910 -- A list of all initialization items processed so far. This list is
2911 -- used to detect duplicate items.
2912
2913 States_And_Objs : Elist_Id := No_Elist;
2914 -- A list of all abstract states and objects declared in the visible
2915 -- declarations of the related package. This list is used to detect the
2916 -- legality of initialization items.
2917
2918 States_Seen : Elist_Id := No_Elist;
2919 -- A list containing the entities of all states processed so far. It
2920 -- helps in detecting illegal usage of a state and a corresponding
2921 -- constituent in pragma Initializes.
2922
2923 procedure Analyze_Initialization_Item (Item : Node_Id);
2924 -- Verify the legality of a single initialization item
2925
2926 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2927 -- Verify the legality of a single initialization item followed by a
2928 -- list of input items.
2929
2930 procedure Collect_States_And_Objects (Pack_Decl : Node_Id);
2931 -- Inspect the visible declarations of the related package and gather
2932 -- the entities of all abstract states and objects in States_And_Objs.
2933
2934 ---------------------------------
2935 -- Analyze_Initialization_Item --
2936 ---------------------------------
2937
2938 procedure Analyze_Initialization_Item (Item : Node_Id) is
2939 Item_Id : Entity_Id;
2940
2941 begin
2942 Analyze (Item);
2943 Resolve_State (Item);
2944
2945 if Is_Entity_Name (Item) then
2946 Item_Id := Entity_Of (Item);
2947
2948 if Present (Item_Id)
2949 and then Ekind (Item_Id) in
2950 E_Abstract_State | E_Constant | E_Variable
2951 then
2952 -- When the initialization item is undefined, it appears as
2953 -- Any_Id. Do not continue with the analysis of the item.
2954
2955 if Item_Id = Any_Id then
2956 null;
2957
2958 -- The state or variable must be declared in the visible
2959 -- declarations of the package (SPARK RM 7.1.5(7)).
2960
2961 elsif not Contains (States_And_Objs, Item_Id) then
2962 Error_Msg_Name_1 := Chars (Pack_Id);
2963 SPARK_Msg_NE
2964 ("initialization item & must appear in the visible "
2965 & "declarations of package %", Item, Item_Id);
2966
2967 -- Detect a duplicate use of the same initialization item
2968 -- (SPARK RM 7.1.5(5)).
2969
2970 elsif Contains (Items_Seen, Item_Id) then
2971 SPARK_Msg_N ("duplicate initialization item", Item);
2972
2973 -- The item is legal, add it to the list of processed states
2974 -- and variables.
2975
2976 else
2977 Append_New_Elmt (Item_Id, Items_Seen);
2978
2979 if Ekind (Item_Id) = E_Abstract_State then
2980 Append_New_Elmt (Item_Id, States_Seen);
2981 end if;
2982
2983 if Present (Encapsulating_State (Item_Id)) then
2984 Append_New_Elmt (Item_Id, Constits_Seen);
2985 end if;
2986 end if;
2987
2988 -- The item references something that is not a state or object
2989 -- (SPARK RM 7.1.5(3)).
2990
2991 else
2992 SPARK_Msg_N
2993 ("initialization item must denote object or state", Item);
2994 end if;
2995
2996 -- Some form of illegal construct masquerading as a name
2997 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2998
2999 else
3000 Error_Msg_N
3001 ("initialization item must denote object or state", Item);
3002 end if;
3003 end Analyze_Initialization_Item;
3004
3005 ---------------------------------------------
3006 -- Analyze_Initialization_Item_With_Inputs --
3007 ---------------------------------------------
3008
3009 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
3010 Inputs_Seen : Elist_Id := No_Elist;
3011 -- A list of all inputs processed so far. This list is used to detect
3012 -- duplicate uses of an input.
3013
3014 Non_Null_Seen : Boolean := False;
3015 Null_Seen : Boolean := False;
3016 -- Flags used to check the legality of an input list
3017
3018 procedure Analyze_Input_Item (Input : Node_Id);
3019 -- Verify the legality of a single input item
3020
3021 ------------------------
3022 -- Analyze_Input_Item --
3023 ------------------------
3024
3025 procedure Analyze_Input_Item (Input : Node_Id) is
3026 Input_Id : Entity_Id;
3027
3028 begin
3029 -- Null input list
3030
3031 if Nkind (Input) = N_Null then
3032 if Null_Seen then
3033 SPARK_Msg_N
3034 ("multiple null initializations not allowed", Item);
3035
3036 elsif Non_Null_Seen then
3037 SPARK_Msg_N
3038 ("cannot mix null and non-null initialization item", Item);
3039 else
3040 Null_Seen := True;
3041 end if;
3042
3043 -- Input item
3044
3045 else
3046 Non_Null_Seen := True;
3047
3048 if Null_Seen then
3049 SPARK_Msg_N
3050 ("cannot mix null and non-null initialization item", Item);
3051 end if;
3052
3053 Analyze (Input);
3054 Resolve_State (Input);
3055
3056 if Is_Entity_Name (Input) then
3057 Input_Id := Entity_Of (Input);
3058
3059 if Present (Input_Id)
3060 and then Ekind (Input_Id) in E_Abstract_State
3061 | E_Constant
3062 | E_Generic_In_Out_Parameter
3063 | E_Generic_In_Parameter
3064 | E_In_Parameter
3065 | E_In_Out_Parameter
3066 | E_Out_Parameter
3067 | E_Protected_Type
3068 | E_Task_Type
3069 | E_Variable
3070 then
3071 -- The input cannot denote states or objects declared
3072 -- within the related package (SPARK RM 7.1.5(4)).
3073
3074 if Within_Scope (Input_Id, Current_Scope) then
3075
3076 -- Do not consider generic formal parameters or their
3077 -- respective mappings to generic formals. Even though
3078 -- the formals appear within the scope of the package,
3079 -- it is allowed for an initialization item to depend
3080 -- on an input item.
3081
3082 if Ekind (Input_Id) in E_Generic_In_Out_Parameter
3083 | E_Generic_In_Parameter
3084 then
3085 null;
3086
3087 elsif Ekind (Input_Id) in E_Constant | E_Variable
3088 and then Present (Corresponding_Generic_Association
3089 (Declaration_Node (Input_Id)))
3090 then
3091 null;
3092
3093 else
3094 Error_Msg_Name_1 := Chars (Pack_Id);
3095 SPARK_Msg_NE
3096 ("input item & cannot denote a visible object or "
3097 & "state of package %", Input, Input_Id);
3098 return;
3099 end if;
3100 end if;
3101
3102 -- Detect a duplicate use of the same input item
3103 -- (SPARK RM 7.1.5(5)).
3104
3105 if Contains (Inputs_Seen, Input_Id) then
3106 SPARK_Msg_N ("duplicate input item", Input);
3107 return;
3108 end if;
3109
3110 -- At this point it is known that the input is legal. Add
3111 -- it to the list of processed inputs.
3112
3113 Append_New_Elmt (Input_Id, Inputs_Seen);
3114
3115 if Ekind (Input_Id) = E_Abstract_State then
3116 Append_New_Elmt (Input_Id, States_Seen);
3117 end if;
3118
3119 if Ekind (Input_Id) in E_Abstract_State
3120 | E_Constant
3121 | E_Variable
3122 and then Present (Encapsulating_State (Input_Id))
3123 then
3124 Append_New_Elmt (Input_Id, Constits_Seen);
3125 end if;
3126
3127 -- The input references something that is not a state or an
3128 -- object (SPARK RM 7.1.5(3)).
3129
3130 else
3131 SPARK_Msg_N
3132 ("input item must denote object or state", Input);
3133 end if;
3134
3135 -- Some form of illegal construct masquerading as a name
3136 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
3137
3138 else
3139 Error_Msg_N
3140 ("input item must denote object or state", Input);
3141 end if;
3142 end if;
3143 end Analyze_Input_Item;
3144
3145 -- Local variables
3146
3147 Inputs : constant Node_Id := Expression (Item);
3148 Elmt : Node_Id;
3149 Input : Node_Id;
3150
3151 Name_Seen : Boolean := False;
3152 -- A flag used to detect multiple item names
3153
3154 -- Start of processing for Analyze_Initialization_Item_With_Inputs
3155
3156 begin
3157 -- Inspect the name of an item with inputs
3158
3159 Elmt := First (Choices (Item));
3160 while Present (Elmt) loop
3161 if Name_Seen then
3162 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
3163 else
3164 Name_Seen := True;
3165 Analyze_Initialization_Item (Elmt);
3166 end if;
3167
3168 Next (Elmt);
3169 end loop;
3170
3171 -- Multiple input items appear as an aggregate
3172
3173 if Nkind (Inputs) = N_Aggregate then
3174 if Present (Expressions (Inputs)) then
3175 Input := First (Expressions (Inputs));
3176 while Present (Input) loop
3177 Analyze_Input_Item (Input);
3178 Next (Input);
3179 end loop;
3180 end if;
3181
3182 if Present (Component_Associations (Inputs)) then
3183 SPARK_Msg_N
3184 ("inputs must appear in named association form", Inputs);
3185 end if;
3186
3187 -- Single input item
3188
3189 else
3190 Analyze_Input_Item (Inputs);
3191 end if;
3192 end Analyze_Initialization_Item_With_Inputs;
3193
3194 --------------------------------
3195 -- Collect_States_And_Objects --
3196 --------------------------------
3197
3198 procedure Collect_States_And_Objects (Pack_Decl : Node_Id) is
3199 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
3200 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
3201 Decl : Node_Id;
3202 State_Elmt : Elmt_Id;
3203
3204 begin
3205 -- Collect the abstract states defined in the package (if any)
3206
3207 if Has_Non_Null_Abstract_State (Pack_Id) then
3208 State_Elmt := First_Elmt (Abstract_States (Pack_Id));
3209 while Present (State_Elmt) loop
3210 Append_New_Elmt (Node (State_Elmt), States_And_Objs);
3211 Next_Elmt (State_Elmt);
3212 end loop;
3213 end if;
3214
3215 -- Collect all objects that appear in the visible declarations of the
3216 -- related package.
3217
3218 if Present (Visible_Declarations (Pack_Spec)) then
3219 Decl := First (Visible_Declarations (Pack_Spec));
3220 while Present (Decl) loop
3221 if Comes_From_Source (Decl)
3222 and then Nkind (Decl) in N_Object_Declaration
3223 | N_Object_Renaming_Declaration
3224 then
3225 Append_New_Elmt (Defining_Entity (Decl), States_And_Objs);
3226
3227 elsif Nkind (Decl) = N_Package_Declaration then
3228 Collect_States_And_Objects (Decl);
3229
3230 elsif Is_Single_Concurrent_Type_Declaration (Decl) then
3231 Append_New_Elmt
3232 (Anonymous_Object (Defining_Entity (Decl)),
3233 States_And_Objs);
3234 end if;
3235
3236 Next (Decl);
3237 end loop;
3238 end if;
3239 end Collect_States_And_Objects;
3240
3241 -- Local variables
3242
3243 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3244 Init : Node_Id;
3245
3246 -- Start of processing for Analyze_Initializes_In_Decl_Part
3247
3248 begin
3249 -- Do not analyze the pragma multiple times
3250
3251 if Is_Analyzed_Pragma (N) then
3252 return;
3253 end if;
3254
3255 -- Nothing to do when the initialization list is empty
3256
3257 if Nkind (Inits) = N_Null then
3258 return;
3259 end if;
3260
3261 -- Single and multiple initialization clauses appear as an aggregate. If
3262 -- this is not the case, then either the parser or the analysis of the
3263 -- pragma failed to produce an aggregate.
3264
3265 pragma Assert (Nkind (Inits) = N_Aggregate);
3266
3267 -- Initialize the various lists used during analysis
3268
3269 Collect_States_And_Objects (Pack_Decl);
3270
3271 if Present (Expressions (Inits)) then
3272 Init := First (Expressions (Inits));
3273 while Present (Init) loop
3274 Analyze_Initialization_Item (Init);
3275 Next (Init);
3276 end loop;
3277 end if;
3278
3279 if Present (Component_Associations (Inits)) then
3280 Init := First (Component_Associations (Inits));
3281 while Present (Init) loop
3282 Analyze_Initialization_Item_With_Inputs (Init);
3283 Next (Init);
3284 end loop;
3285 end if;
3286
3287 -- Ensure that a state and a corresponding constituent do not appear
3288 -- together in pragma Initializes.
3289
3290 Check_State_And_Constituent_Use
3291 (States => States_Seen,
3292 Constits => Constits_Seen,
3293 Context => N);
3294
3295 Set_Is_Analyzed_Pragma (N);
3296 end Analyze_Initializes_In_Decl_Part;
3297
3298 ---------------------
3299 -- Analyze_Part_Of --
3300 ---------------------
3301
3302 procedure Analyze_Part_Of
3303 (Indic : Node_Id;
3304 Item_Id : Entity_Id;
3305 Encap : Node_Id;
3306 Encap_Id : out Entity_Id;
3307 Legal : out Boolean)
3308 is
3309 procedure Check_Part_Of_Abstract_State;
3310 pragma Inline (Check_Part_Of_Abstract_State);
3311 -- Verify the legality of indicator Part_Of when the encapsulator is an
3312 -- abstract state.
3313
3314 procedure Check_Part_Of_Concurrent_Type;
3315 pragma Inline (Check_Part_Of_Concurrent_Type);
3316 -- Verify the legality of indicator Part_Of when the encapsulator is a
3317 -- single concurrent type.
3318
3319 ----------------------------------
3320 -- Check_Part_Of_Abstract_State --
3321 ----------------------------------
3322
3323 procedure Check_Part_Of_Abstract_State is
3324 Pack_Id : Entity_Id;
3325 Placement : State_Space_Kind;
3326 Parent_Unit : Entity_Id;
3327
3328 begin
3329 -- Determine where the object, package instantiation or state lives
3330 -- with respect to the enclosing packages or package bodies.
3331
3332 Find_Placement_In_State_Space
3333 (Item_Id => Item_Id,
3334 Placement => Placement,
3335 Pack_Id => Pack_Id);
3336
3337 -- The item appears in a non-package construct with a declarative
3338 -- part (subprogram, block, etc). As such, the item is not allowed
3339 -- to be a part of an encapsulating state because the item is not
3340 -- visible.
3341
3342 if Placement = Not_In_Package then
3343 SPARK_Msg_N
3344 ("indicator Part_Of cannot appear in this context "
3345 & "(SPARK RM 7.2.6(5))", Indic);
3346
3347 Error_Msg_Name_1 := Chars (Scope (Encap_Id));
3348 SPARK_Msg_NE
3349 ("\& is not part of the hidden state of package %",
3350 Indic, Item_Id);
3351 return;
3352
3353 -- The item appears in the visible state space of some package. In
3354 -- general this scenario does not warrant Part_Of except when the
3355 -- package is a nongeneric private child unit and the encapsulating
3356 -- state is declared in a parent unit or a public descendant of that
3357 -- parent unit.
3358
3359 elsif Placement = Visible_State_Space then
3360 if Is_Child_Unit (Pack_Id)
3361 and then not Is_Generic_Unit (Pack_Id)
3362 and then Is_Private_Descendant (Pack_Id)
3363 then
3364 -- A variable or state abstraction which is part of the visible
3365 -- state of a nongeneric private child unit or its public
3366 -- descendants must have its Part_Of indicator specified. The
3367 -- Part_Of indicator must denote a state declared by either the
3368 -- parent unit of the private unit or by a public descendant of
3369 -- that parent unit.
3370
3371 -- Find the nearest private ancestor (which can be the current
3372 -- unit itself).
3373
3374 Parent_Unit := Pack_Id;
3375 while Present (Parent_Unit) loop
3376 exit when
3377 Private_Present
3378 (Parent (Unit_Declaration_Node (Parent_Unit)));
3379 Parent_Unit := Scope (Parent_Unit);
3380 end loop;
3381
3382 Parent_Unit := Scope (Parent_Unit);
3383
3384 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
3385 SPARK_Msg_NE
3386 ("indicator Part_Of must denote abstract state of & or of "
3387 & "its public descendant (SPARK RM 7.2.6(3))",
3388 Indic, Parent_Unit);
3389 return;
3390
3391 elsif Scope (Encap_Id) = Parent_Unit
3392 or else
3393 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id))
3394 and then not Is_Private_Descendant (Scope (Encap_Id)))
3395 then
3396 null;
3397
3398 else
3399 SPARK_Msg_NE
3400 ("indicator Part_Of must denote abstract state of & or of "
3401 & "its public descendant (SPARK RM 7.2.6(3))",
3402 Indic, Parent_Unit);
3403 return;
3404 end if;
3405
3406 -- Indicator Part_Of is not needed when the related package is
3407 -- not a nongeneric private child unit or a public descendant
3408 -- thereof.
3409
3410 else
3411 SPARK_Msg_N
3412 ("indicator Part_Of cannot appear in this context "
3413 & "(SPARK RM 7.2.6(5))", Indic);
3414
3415 Error_Msg_Name_1 := Chars (Pack_Id);
3416 SPARK_Msg_NE
3417 ("\& is declared in the visible part of package %",
3418 Indic, Item_Id);
3419 return;
3420 end if;
3421
3422 -- When the item appears in the private state space of a package, the
3423 -- encapsulating state must be declared in the same package.
3424
3425 elsif Placement = Private_State_Space then
3426 if Scope (Encap_Id) /= Pack_Id then
3427 SPARK_Msg_NE
3428 ("indicator Part_Of must denote an abstract state of "
3429 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3430
3431 Error_Msg_Name_1 := Chars (Pack_Id);
3432 SPARK_Msg_NE
3433 ("\& is declared in the private part of package %",
3434 Indic, Item_Id);
3435 return;
3436 end if;
3437
3438 -- Items declared in the body state space of a package do not need
3439 -- Part_Of indicators as the refinement has already been seen.
3440
3441 else
3442 SPARK_Msg_N
3443 ("indicator Part_Of cannot appear in this context "
3444 & "(SPARK RM 7.2.6(5))", Indic);
3445
3446 if Scope (Encap_Id) = Pack_Id then
3447 Error_Msg_Name_1 := Chars (Pack_Id);
3448 SPARK_Msg_NE
3449 ("\& is declared in the body of package %", Indic, Item_Id);
3450 end if;
3451
3452 return;
3453 end if;
3454
3455 -- At this point it is known that the Part_Of indicator is legal
3456
3457 Legal := True;
3458 end Check_Part_Of_Abstract_State;
3459
3460 -----------------------------------
3461 -- Check_Part_Of_Concurrent_Type --
3462 -----------------------------------
3463
3464 procedure Check_Part_Of_Concurrent_Type is
3465 function In_Proper_Order
3466 (First : Node_Id;
3467 Second : Node_Id) return Boolean;
3468 pragma Inline (In_Proper_Order);
3469 -- Determine whether node First precedes node Second
3470
3471 procedure Placement_Error;
3472 pragma Inline (Placement_Error);
3473 -- Emit an error concerning the illegal placement of the item with
3474 -- respect to the single concurrent type.
3475
3476 ---------------------
3477 -- In_Proper_Order --
3478 ---------------------
3479
3480 function In_Proper_Order
3481 (First : Node_Id;
3482 Second : Node_Id) return Boolean
3483 is
3484 N : Node_Id;
3485
3486 begin
3487 if List_Containing (First) = List_Containing (Second) then
3488 N := First;
3489 while Present (N) loop
3490 if N = Second then
3491 return True;
3492 end if;
3493
3494 Next (N);
3495 end loop;
3496 end if;
3497
3498 return False;
3499 end In_Proper_Order;
3500
3501 ---------------------
3502 -- Placement_Error --
3503 ---------------------
3504
3505 procedure Placement_Error is
3506 begin
3507 SPARK_Msg_N
3508 ("indicator Part_Of must denote a previously declared single "
3509 & "protected type or single task type", Encap);
3510 end Placement_Error;
3511
3512 -- Local variables
3513
3514 Conc_Typ : constant Entity_Id := Etype (Encap_Id);
3515 Encap_Decl : constant Node_Id := Declaration_Node (Encap_Id);
3516 Encap_Context : constant Node_Id := Parent (Encap_Decl);
3517
3518 Item_Context : Node_Id;
3519 Item_Decl : Node_Id;
3520 Prv_Decls : List_Id;
3521 Vis_Decls : List_Id;
3522
3523 -- Start of processing for Check_Part_Of_Concurrent_Type
3524
3525 begin
3526 -- Only abstract states and variables can act as constituents of an
3527 -- encapsulating single concurrent type.
3528
3529 if Ekind (Item_Id) in E_Abstract_State | E_Variable then
3530 null;
3531
3532 -- The constituent is a constant
3533
3534 elsif Ekind (Item_Id) = E_Constant then
3535 Error_Msg_Name_1 := Chars (Encap_Id);
3536 SPARK_Msg_NE
3537 (Fix_Msg (Conc_Typ, "constant & cannot act as constituent of "
3538 & "single protected type %"), Indic, Item_Id);
3539 return;
3540
3541 -- The constituent is a package instantiation
3542
3543 else
3544 Error_Msg_Name_1 := Chars (Encap_Id);
3545 SPARK_Msg_NE
3546 (Fix_Msg (Conc_Typ, "package instantiation & cannot act as "
3547 & "constituent of single protected type %"), Indic, Item_Id);
3548 return;
3549 end if;
3550
3551 -- When the item denotes an abstract state of a nested package, use
3552 -- the declaration of the package to detect proper placement.
3553
3554 -- package Pack is
3555 -- task T;
3556 -- package Nested
3557 -- with Abstract_State => (State with Part_Of => T)
3558
3559 if Ekind (Item_Id) = E_Abstract_State then
3560 Item_Decl := Unit_Declaration_Node (Scope (Item_Id));
3561 else
3562 Item_Decl := Declaration_Node (Item_Id);
3563 end if;
3564
3565 Item_Context := Parent (Item_Decl);
3566
3567 -- The item and the single concurrent type must appear in the same
3568 -- declarative region, with the item following the declaration of
3569 -- the single concurrent type (SPARK RM 9(3)).
3570
3571 if Item_Context = Encap_Context then
3572 if Nkind (Item_Context) in N_Package_Specification
3573 | N_Protected_Definition
3574 | N_Task_Definition
3575 then
3576 Prv_Decls := Private_Declarations (Item_Context);
3577 Vis_Decls := Visible_Declarations (Item_Context);
3578
3579 -- The placement is OK when the single concurrent type appears
3580 -- within the visible declarations and the item in the private
3581 -- declarations.
3582 --
3583 -- package Pack is
3584 -- protected PO ...
3585 -- private
3586 -- Constit : ... with Part_Of => PO;
3587 -- end Pack;
3588
3589 if List_Containing (Encap_Decl) = Vis_Decls
3590 and then List_Containing (Item_Decl) = Prv_Decls
3591 then
3592 null;
3593
3594 -- The placement is illegal when the item appears within the
3595 -- visible declarations and the single concurrent type is in
3596 -- the private declarations.
3597 --
3598 -- package Pack is
3599 -- Constit : ... with Part_Of => PO;
3600 -- private
3601 -- protected PO ...
3602 -- end Pack;
3603
3604 elsif List_Containing (Item_Decl) = Vis_Decls
3605 and then List_Containing (Encap_Decl) = Prv_Decls
3606 then
3607 Placement_Error;
3608 return;
3609
3610 -- Otherwise both the item and the single concurrent type are
3611 -- in the same list. Ensure that the declaration of the single
3612 -- concurrent type precedes that of the item.
3613
3614 elsif not In_Proper_Order
3615 (First => Encap_Decl,
3616 Second => Item_Decl)
3617 then
3618 Placement_Error;
3619 return;
3620 end if;
3621
3622 -- Otherwise both the item and the single concurrent type are
3623 -- in the same list. Ensure that the declaration of the single
3624 -- concurrent type precedes that of the item.
3625
3626 elsif not In_Proper_Order
3627 (First => Encap_Decl,
3628 Second => Item_Decl)
3629 then
3630 Placement_Error;
3631 return;
3632 end if;
3633
3634 -- Otherwise the item and the single concurrent type reside within
3635 -- unrelated regions.
3636
3637 else
3638 Error_Msg_Name_1 := Chars (Encap_Id);
3639 SPARK_Msg_NE
3640 (Fix_Msg (Conc_Typ, "constituent & must be declared "
3641 & "immediately within the same region as single protected "
3642 & "type %"), Indic, Item_Id);
3643 return;
3644 end if;
3645
3646 -- At this point it is known that the Part_Of indicator is legal
3647
3648 Legal := True;
3649 end Check_Part_Of_Concurrent_Type;
3650
3651 -- Start of processing for Analyze_Part_Of
3652
3653 begin
3654 -- Assume that the indicator is illegal
3655
3656 Encap_Id := Empty;
3657 Legal := False;
3658
3659 if Nkind (Encap) in
3660 N_Expanded_Name | N_Identifier | N_Selected_Component
3661 then
3662 Analyze (Encap);
3663 Resolve_State (Encap);
3664
3665 Encap_Id := Entity (Encap);
3666
3667 -- The encapsulator is an abstract state
3668
3669 if Ekind (Encap_Id) = E_Abstract_State then
3670 null;
3671
3672 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3673
3674 elsif Is_Single_Concurrent_Object (Encap_Id) then
3675 null;
3676
3677 -- Otherwise the encapsulator is not a legal choice
3678
3679 else
3680 SPARK_Msg_N
3681 ("indicator Part_Of must denote abstract state, single "
3682 & "protected type or single task type", Encap);
3683 return;
3684 end if;
3685
3686 -- This is a syntax error, always report
3687
3688 else
3689 Error_Msg_N
3690 ("indicator Part_Of must denote abstract state, single protected "
3691 & "type or single task type", Encap);
3692 return;
3693 end if;
3694
3695 -- Catch a case where indicator Part_Of denotes the abstract view of a
3696 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3697
3698 if From_Limited_With (Encap_Id)
3699 and then Present (Non_Limited_View (Encap_Id))
3700 and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable
3701 then
3702 SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap);
3703 SPARK_Msg_N ("\& denotes abstract view of object", Encap);
3704 return;
3705 end if;
3706
3707 -- The encapsulator is an abstract state
3708
3709 if Ekind (Encap_Id) = E_Abstract_State then
3710 Check_Part_Of_Abstract_State;
3711
3712 -- The encapsulator is a single concurrent type
3713
3714 else
3715 Check_Part_Of_Concurrent_Type;
3716 end if;
3717 end Analyze_Part_Of;
3718
3719 ----------------------------------
3720 -- Analyze_Part_Of_In_Decl_Part --
3721 ----------------------------------
3722
3723 procedure Analyze_Part_Of_In_Decl_Part
3724 (N : Node_Id;
3725 Freeze_Id : Entity_Id := Empty)
3726 is
3727 Encap : constant Node_Id :=
3728 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
3729 Errors : constant Nat := Serious_Errors_Detected;
3730 Var_Decl : constant Node_Id := Find_Related_Context (N);
3731 Var_Id : constant Entity_Id := Defining_Entity (Var_Decl);
3732 Constits : Elist_Id;
3733 Encap_Id : Entity_Id;
3734 Legal : Boolean;
3735
3736 begin
3737 -- Detect any discrepancies between the placement of the variable with
3738 -- respect to general state space and the encapsulating state or single
3739 -- concurrent type.
3740
3741 Analyze_Part_Of
3742 (Indic => N,
3743 Item_Id => Var_Id,
3744 Encap => Encap,
3745 Encap_Id => Encap_Id,
3746 Legal => Legal);
3747
3748 -- The Part_Of indicator turns the variable into a constituent of the
3749 -- encapsulating state or single concurrent type.
3750
3751 if Legal then
3752 pragma Assert (Present (Encap_Id));
3753 Constits := Part_Of_Constituents (Encap_Id);
3754
3755 if No (Constits) then
3756 Constits := New_Elmt_List;
3757 Set_Part_Of_Constituents (Encap_Id, Constits);
3758 end if;
3759
3760 Append_Elmt (Var_Id, Constits);
3761 Set_Encapsulating_State (Var_Id, Encap_Id);
3762
3763 -- A Part_Of constituent partially refines an abstract state. This
3764 -- property does not apply to protected or task units.
3765
3766 if Ekind (Encap_Id) = E_Abstract_State then
3767 Set_Has_Partial_Visible_Refinement (Encap_Id);
3768 end if;
3769 end if;
3770
3771 -- Emit a clarification message when the encapsulator is undefined,
3772 -- possibly due to contract freezing.
3773
3774 if Errors /= Serious_Errors_Detected
3775 and then Present (Freeze_Id)
3776 and then Has_Undefined_Reference (Encap)
3777 then
3778 Contract_Freeze_Error (Var_Id, Freeze_Id);
3779 end if;
3780 end Analyze_Part_Of_In_Decl_Part;
3781
3782 --------------------
3783 -- Analyze_Pragma --
3784 --------------------
3785
3786 procedure Analyze_Pragma (N : Node_Id) is
3787 Loc : constant Source_Ptr := Sloc (N);
3788
3789 Pname : Name_Id := Pragma_Name (N);
3790 -- Name of the source pragma, or name of the corresponding aspect for
3791 -- pragmas which originate in a source aspect. In the latter case, the
3792 -- name may be different from the pragma name.
3793
3794 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
3795
3796 Pragma_Exit : exception;
3797 -- This exception is used to exit pragma processing completely. It
3798 -- is used when an error is detected, and no further processing is
3799 -- required. It is also used if an earlier error has left the tree in
3800 -- a state where the pragma should not be processed.
3801
3802 Arg_Count : Nat;
3803 -- Number of pragma argument associations
3804
3805 Arg1 : Node_Id;
3806 Arg2 : Node_Id;
3807 Arg3 : Node_Id;
3808 Arg4 : Node_Id;
3809 Arg5 : Node_Id;
3810 -- First five pragma arguments (pragma argument association nodes, or
3811 -- Empty if the corresponding argument does not exist).
3812
3813 type Name_List is array (Natural range <>) of Name_Id;
3814 type Args_List is array (Natural range <>) of Node_Id;
3815 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3816
3817 -----------------------
3818 -- Local Subprograms --
3819 -----------------------
3820
3821 procedure Ada_2005_Pragma;
3822 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3823 -- Ada 95 mode, these are implementation defined pragmas, so should be
3824 -- caught by the No_Implementation_Pragmas restriction.
3825
3826 procedure Ada_2012_Pragma;
3827 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3828 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3829 -- should be caught by the No_Implementation_Pragmas restriction.
3830
3831 procedure Analyze_Depends_Global
3832 (Spec_Id : out Entity_Id;
3833 Subp_Decl : out Node_Id;
3834 Legal : out Boolean);
3835 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3836 -- legality of the placement and related context of the pragma. Spec_Id
3837 -- is the entity of the related subprogram. Subp_Decl is the declaration
3838 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3839
3840 procedure Analyze_If_Present (Id : Pragma_Id);
3841 -- Inspect the remainder of the list containing pragma N and look for
3842 -- a pragma that matches Id. If found, analyze the pragma.
3843
3844 procedure Analyze_Pre_Post_Condition;
3845 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3846
3847 procedure Analyze_Refined_Depends_Global_Post
3848 (Spec_Id : out Entity_Id;
3849 Body_Id : out Entity_Id;
3850 Legal : out Boolean);
3851 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3852 -- Refined_Global and Refined_Post. Verify the legality of the placement
3853 -- and related context of the pragma. Spec_Id is the entity of the
3854 -- related subprogram. Body_Id is the entity of the subprogram body.
3855 -- Flag Legal is set when the pragma is legal.
3856
3857 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False);
3858 -- Perform full analysis of pragma Unmodified and the write aspect of
3859 -- pragma Unused. Flag Is_Unused should be set when verifying the
3860 -- semantics of pragma Unused.
3861
3862 procedure Analyze_Unreferenced_Or_Unused (Is_Unused : Boolean := False);
3863 -- Perform full analysis of pragma Unreferenced and the read aspect of
3864 -- pragma Unused. Flag Is_Unused should be set when verifying the
3865 -- semantics of pragma Unused.
3866
3867 procedure Check_Ada_83_Warning;
3868 -- Issues a warning message for the current pragma if operating in Ada
3869 -- 83 mode (used for language pragmas that are not a standard part of
3870 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3871 -- of 95 pragma.
3872
3873 procedure Check_Arg_Count (Required : Nat);
3874 -- Check argument count for pragma is equal to given parameter. If not,
3875 -- then issue an error message and raise Pragma_Exit.
3876
3877 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3878 -- Arg which can either be a pragma argument association, in which case
3879 -- the check is applied to the expression of the association or an
3880 -- expression directly.
3881
3882 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
3883 -- Check that an argument has the right form for an EXTERNAL_NAME
3884 -- parameter of an extended import/export pragma. The rule is that the
3885 -- name must be an identifier or string literal (in Ada 83 mode) or a
3886 -- static string expression (in Ada 95 mode).
3887
3888 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
3889 -- Check the specified argument Arg to make sure that it is an
3890 -- identifier. If not give error and raise Pragma_Exit.
3891
3892 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
3893 -- Check the specified argument Arg to make sure that it is an integer
3894 -- literal. If not give error and raise Pragma_Exit.
3895
3896 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
3897 -- Check the specified argument Arg to make sure that it has the proper
3898 -- syntactic form for a local name and meets the semantic requirements
3899 -- for a local name. The local name is analyzed as part of the
3900 -- processing for this call. In addition, the local name is required
3901 -- to represent an entity at the library level.
3902
3903 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
3904 -- Check the specified argument Arg to make sure that it has the proper
3905 -- syntactic form for a local name and meets the semantic requirements
3906 -- for a local name. The local name is analyzed as part of the
3907 -- processing for this call.
3908
3909 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
3910 -- Check the specified argument Arg to make sure that it is a valid
3911 -- locking policy name. If not give error and raise Pragma_Exit.
3912
3913 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
3914 -- Check the specified argument Arg to make sure that it is a valid
3915 -- elaboration policy name. If not give error and raise Pragma_Exit.
3916
3917 procedure Check_Arg_Is_One_Of
3918 (Arg : Node_Id;
3919 N1, N2 : Name_Id);
3920 procedure Check_Arg_Is_One_Of
3921 (Arg : Node_Id;
3922 N1, N2, N3 : Name_Id);
3923 procedure Check_Arg_Is_One_Of
3924 (Arg : Node_Id;
3925 N1, N2, N3, N4 : Name_Id);
3926 procedure Check_Arg_Is_One_Of
3927 (Arg : Node_Id;
3928 N1, N2, N3, N4, N5 : Name_Id);
3929 -- Check the specified argument Arg to make sure that it is an
3930 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3931 -- present). If not then give error and raise Pragma_Exit.
3932
3933 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
3934 -- Check the specified argument Arg to make sure that it is a valid
3935 -- queuing policy name. If not give error and raise Pragma_Exit.
3936
3937 procedure Check_Arg_Is_OK_Static_Expression
3938 (Arg : Node_Id;
3939 Typ : Entity_Id := Empty);
3940 -- Check the specified argument Arg to make sure that it is a static
3941 -- expression of the given type (i.e. it will be analyzed and resolved
3942 -- using this type, which can be any valid argument to Resolve, e.g.
3943 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3944 -- Typ is left Empty, then any static expression is allowed. Includes
3945 -- checking that the argument does not raise Constraint_Error.
3946
3947 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
3948 -- Check the specified argument Arg to make sure that it is a valid task
3949 -- dispatching policy name. If not give error and raise Pragma_Exit.
3950
3951 procedure Check_Arg_Order (Names : Name_List);
3952 -- Checks for an instance of two arguments with identifiers for the
3953 -- current pragma which are not in the sequence indicated by Names,
3954 -- and if so, generates a fatal message about bad order of arguments.
3955
3956 procedure Check_At_Least_N_Arguments (N : Nat);
3957 -- Check there are at least N arguments present
3958
3959 procedure Check_At_Most_N_Arguments (N : Nat);
3960 -- Check there are no more than N arguments present
3961
3962 procedure Check_Component
3963 (Comp : Node_Id;
3964 UU_Typ : Entity_Id;
3965 In_Variant_Part : Boolean := False);
3966 -- Examine an Unchecked_Union component for correct use of per-object
3967 -- constrained subtypes, and for restrictions on finalizable components.
3968 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3969 -- should be set when Comp comes from a record variant.
3970
3971 procedure Check_Duplicate_Pragma (E : Entity_Id);
3972 -- Check if a rep item of the same name as the current pragma is already
3973 -- chained as a rep pragma to the given entity. If so give a message
3974 -- about the duplicate, and then raise Pragma_Exit so does not return.
3975 -- Note that if E is a type, then this routine avoids flagging a pragma
3976 -- which applies to a parent type from which E is derived.
3977
3978 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
3979 -- Nam is an N_String_Literal node containing the external name set by
3980 -- an Import or Export pragma (or extended Import or Export pragma).
3981 -- This procedure checks for possible duplications if this is the export
3982 -- case, and if found, issues an appropriate error message.
3983
3984 procedure Check_Expr_Is_OK_Static_Expression
3985 (Expr : Node_Id;
3986 Typ : Entity_Id := Empty);
3987 -- Check the specified expression Expr to make sure that it is a static
3988 -- expression of the given type (i.e. it will be analyzed and resolved
3989 -- using this type, which can be any valid argument to Resolve, e.g.
3990 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3991 -- Typ is left Empty, then any static expression is allowed. Includes
3992 -- checking that the expression does not raise Constraint_Error.
3993
3994 procedure Check_First_Subtype (Arg : Node_Id);
3995 -- Checks that Arg, whose expression is an entity name, references a
3996 -- first subtype.
3997
3998 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
3999 -- Checks that the given argument has an identifier, and if so, requires
4000 -- it to match the given identifier name. If there is no identifier, or
4001 -- a non-matching identifier, then an error message is given and
4002 -- Pragma_Exit is raised.
4003
4004 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
4005 -- Checks that the given argument has an identifier, and if so, requires
4006 -- it to match one of the given identifier names. If there is no
4007 -- identifier, or a non-matching identifier, then an error message is
4008 -- given and Pragma_Exit is raised.
4009
4010 procedure Check_In_Main_Program;
4011 -- Common checks for pragmas that appear within a main program
4012 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
4013
4014 procedure Check_Interrupt_Or_Attach_Handler;
4015 -- Common processing for first argument of pragma Interrupt_Handler or
4016 -- pragma Attach_Handler.
4017
4018 procedure Check_Loop_Pragma_Placement;
4019 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
4020 -- appear immediately within a construct restricted to loops, and that
4021 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
4022
4023 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
4024 -- Check that pragma appears in a declarative part, or in a package
4025 -- specification, i.e. that it does not occur in a statement sequence
4026 -- in a body.
4027
4028 procedure Check_No_Identifier (Arg : Node_Id);
4029 -- Checks that the given argument does not have an identifier. If
4030 -- an identifier is present, then an error message is issued, and
4031 -- Pragma_Exit is raised.
4032
4033 procedure Check_No_Identifiers;
4034 -- Checks that none of the arguments to the pragma has an identifier.
4035 -- If any argument has an identifier, then an error message is issued,
4036 -- and Pragma_Exit is raised.
4037
4038 procedure Check_No_Link_Name;
4039 -- Checks that no link name is specified
4040
4041 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
4042 -- Checks if the given argument has an identifier, and if so, requires
4043 -- it to match the given identifier name. If there is a non-matching
4044 -- identifier, then an error message is given and Pragma_Exit is raised.
4045
4046 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
4047 -- Checks if the given argument has an identifier, and if so, requires
4048 -- it to match the given identifier name. If there is a non-matching
4049 -- identifier, then an error message is given and Pragma_Exit is raised.
4050 -- In this version of the procedure, the identifier name is given as
4051 -- a string with lower case letters.
4052
4053 procedure Check_Static_Boolean_Expression (Expr : Node_Id);
4054 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
4055 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
4056 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
4057 -- is an OK static boolean expression. Emit an error if this is not the
4058 -- case.
4059
4060 procedure Check_Static_Constraint (Constr : Node_Id);
4061 -- Constr is a constraint from an N_Subtype_Indication node from a
4062 -- component constraint in an Unchecked_Union type. This routine checks
4063 -- that the constraint is static as required by the restrictions for
4064 -- Unchecked_Union.
4065
4066 procedure Check_Valid_Configuration_Pragma;
4067 -- Legality checks for placement of a configuration pragma
4068
4069 procedure Check_Valid_Library_Unit_Pragma;
4070 -- Legality checks for library unit pragmas. A special case arises for
4071 -- pragmas in generic instances that come from copies of the original
4072 -- library unit pragmas in the generic templates. In the case of other
4073 -- than library level instantiations these can appear in contexts which
4074 -- would normally be invalid (they only apply to the original template
4075 -- and to library level instantiations), and they are simply ignored,
4076 -- which is implemented by rewriting them as null statements and raising
4077 -- exception to terminate analysis.
4078
4079 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
4080 -- Check an Unchecked_Union variant for lack of nested variants and
4081 -- presence of at least one component. UU_Typ is the related Unchecked_
4082 -- Union type.
4083
4084 procedure Ensure_Aggregate_Form (Arg : Node_Id);
4085 -- Subsidiary routine to the processing of pragmas Abstract_State,
4086 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
4087 -- Refined_Global, Refined_State and Subprogram_Variant. Transform
4088 -- argument Arg into an aggregate if not one already. N_Null is never
4089 -- transformed. Arg may denote an aspect specification or a pragma
4090 -- argument association.
4091
4092 procedure Error_Pragma (Msg : String);
4093 pragma No_Return (Error_Pragma);
4094 -- Outputs error message for current pragma. The message contains a %
4095 -- that will be replaced with the pragma name, and the flag is placed
4096 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
4097 -- calls Fix_Error (see spec of that procedure for details).
4098
4099 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
4100 pragma No_Return (Error_Pragma_Arg);
4101 -- Outputs error message for current pragma. The message may contain
4102 -- a % that will be replaced with the pragma name. The parameter Arg
4103 -- may either be a pragma argument association, in which case the flag
4104 -- is placed on the expression of this association, or an expression,
4105 -- in which case the flag is placed directly on the expression. The
4106 -- message is placed using Error_Msg_N, so the message may also contain
4107 -- an & insertion character which will reference the given Arg value.
4108 -- After placing the message, Pragma_Exit is raised. Note: this routine
4109 -- calls Fix_Error (see spec of that procedure for details).
4110
4111 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
4112 pragma No_Return (Error_Pragma_Arg);
4113 -- Similar to above form of Error_Pragma_Arg except that two messages
4114 -- are provided, the second is a continuation comment starting with \.
4115
4116 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
4117 pragma No_Return (Error_Pragma_Arg_Ident);
4118 -- Outputs error message for current pragma. The message may contain a %
4119 -- that will be replaced with the pragma name. The parameter Arg must be
4120 -- a pragma argument association with a non-empty identifier (i.e. its
4121 -- Chars field must be set), and the error message is placed on the
4122 -- identifier. The message is placed using Error_Msg_N so the message
4123 -- may also contain an & insertion character which will reference
4124 -- the identifier. After placing the message, Pragma_Exit is raised.
4125 -- Note: this routine calls Fix_Error (see spec of that procedure for
4126 -- details).
4127
4128 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
4129 pragma No_Return (Error_Pragma_Ref);
4130 -- Outputs error message for current pragma. The message may contain
4131 -- a % that will be replaced with the pragma name. The parameter Ref
4132 -- must be an entity whose name can be referenced by & and sloc by #.
4133 -- After placing the message, Pragma_Exit is raised. Note: this routine
4134 -- calls Fix_Error (see spec of that procedure for details).
4135
4136 function Find_Lib_Unit_Name return Entity_Id;
4137 -- Used for a library unit pragma to find the entity to which the
4138 -- library unit pragma applies, returns the entity found.
4139
4140 procedure Find_Program_Unit_Name (Id : Node_Id);
4141 -- If the pragma is a compilation unit pragma, the id must denote the
4142 -- compilation unit in the same compilation, and the pragma must appear
4143 -- in the list of preceding or trailing pragmas. If it is a program
4144 -- unit pragma that is not a compilation unit pragma, then the
4145 -- identifier must be visible.
4146
4147 function Find_Unique_Parameterless_Procedure
4148 (Name : Entity_Id;
4149 Arg : Node_Id) return Entity_Id;
4150 -- Used for a procedure pragma to find the unique parameterless
4151 -- procedure identified by Name, returns it if it exists, otherwise
4152 -- errors out and uses Arg as the pragma argument for the message.
4153
4154 function Fix_Error (Msg : String) return String;
4155 -- This is called prior to issuing an error message. Msg is the normal
4156 -- error message issued in the pragma case. This routine checks for the
4157 -- case of a pragma coming from an aspect in the source, and returns a
4158 -- message suitable for the aspect case as follows:
4159 --
4160 -- Each substring "pragma" is replaced by "aspect"
4161 --
4162 -- If "argument of" is at the start of the error message text, it is
4163 -- replaced by "entity for".
4164 --
4165 -- If "argument" is at the start of the error message text, it is
4166 -- replaced by "entity".
4167 --
4168 -- So for example, "argument of pragma X must be discrete type"
4169 -- returns "entity for aspect X must be a discrete type".
4170
4171 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
4172 -- be different from the pragma name). If the current pragma results
4173 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
4174 -- original pragma name.
4175
4176 procedure Gather_Associations
4177 (Names : Name_List;
4178 Args : out Args_List);
4179 -- This procedure is used to gather the arguments for a pragma that
4180 -- permits arbitrary ordering of parameters using the normal rules
4181 -- for named and positional parameters. The Names argument is a list
4182 -- of Name_Id values that corresponds to the allowed pragma argument
4183 -- association identifiers in order. The result returned in Args is
4184 -- a list of corresponding expressions that are the pragma arguments.
4185 -- Note that this is a list of expressions, not of pragma argument
4186 -- associations (Gather_Associations has completely checked all the
4187 -- optional identifiers when it returns). An entry in Args is Empty
4188 -- on return if the corresponding argument is not present.
4189
4190 procedure GNAT_Pragma;
4191 -- Called for all GNAT defined pragmas to check the relevant restriction
4192 -- (No_Implementation_Pragmas).
4193
4194 function Is_Before_First_Decl
4195 (Pragma_Node : Node_Id;
4196 Decls : List_Id) return Boolean;
4197 -- Return True if Pragma_Node is before the first declarative item in
4198 -- Decls where Decls is the list of declarative items.
4199
4200 function Is_Configuration_Pragma return Boolean;
4201 -- Determines if the placement of the current pragma is appropriate
4202 -- for a configuration pragma.
4203
4204 function Is_In_Context_Clause return Boolean;
4205 -- Returns True if pragma appears within the context clause of a unit,
4206 -- and False for any other placement (does not generate any messages).
4207
4208 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
4209 -- Analyzes the argument, and determines if it is a static string
4210 -- expression, returns True if so, False if non-static or not String.
4211 -- A special case is that a string literal returns True in Ada 83 mode
4212 -- (which has no such thing as static string expressions). Note that
4213 -- the call analyzes its argument, so this cannot be used for the case
4214 -- where an identifier might not be declared.
4215
4216 procedure Pragma_Misplaced;
4217 pragma No_Return (Pragma_Misplaced);
4218 -- Issue fatal error message for misplaced pragma
4219
4220 procedure Process_Atomic_Independent_Shared_Volatile;
4221 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
4222 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
4223 -- and treated as being identical in effect to pragma Atomic.
4224
4225 procedure Process_Compile_Time_Warning_Or_Error;
4226 -- Common processing for Compile_Time_Error and Compile_Time_Warning
4227
4228 procedure Process_Convention
4229 (C : out Convention_Id;
4230 Ent : out Entity_Id);
4231 -- Common processing for Convention, Interface, Import and Export.
4232 -- Checks first two arguments of pragma, and sets the appropriate
4233 -- convention value in the specified entity or entities. On return
4234 -- C is the convention, Ent is the referenced entity.
4235
4236 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
4237 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
4238 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
4239
4240 procedure Process_Extended_Import_Export_Object_Pragma
4241 (Arg_Internal : Node_Id;
4242 Arg_External : Node_Id;
4243 Arg_Size : Node_Id);
4244 -- Common processing for the pragmas Import/Export_Object. The three
4245 -- arguments correspond to the three named parameters of the pragmas. An
4246 -- argument is empty if the corresponding parameter is not present in
4247 -- the pragma.
4248
4249 procedure Process_Extended_Import_Export_Internal_Arg
4250 (Arg_Internal : Node_Id := Empty);
4251 -- Common processing for all extended Import and Export pragmas. The
4252 -- argument is the pragma parameter for the Internal argument. If
4253 -- Arg_Internal is empty or inappropriate, an error message is posted.
4254 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
4255 -- set to identify the referenced entity.
4256
4257 procedure Process_Extended_Import_Export_Subprogram_Pragma
4258 (Arg_Internal : Node_Id;
4259 Arg_External : Node_Id;
4260 Arg_Parameter_Types : Node_Id;
4261 Arg_Result_Type : Node_Id := Empty;
4262 Arg_Mechanism : Node_Id;
4263 Arg_Result_Mechanism : Node_Id := Empty);
4264 -- Common processing for all extended Import and Export pragmas applying
4265 -- to subprograms. The caller omits any arguments that do not apply to
4266 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
4267 -- only in the Import_Function and Export_Function cases). The argument
4268 -- names correspond to the allowed pragma association identifiers.
4269
4270 procedure Process_Generic_List;
4271 -- Common processing for Share_Generic and Inline_Generic
4272
4273 procedure Process_Import_Or_Interface;
4274 -- Common processing for Import or Interface
4275
4276 procedure Process_Import_Predefined_Type;
4277 -- Processing for completing a type with pragma Import. This is used
4278 -- to declare types that match predefined C types, especially for cases
4279 -- without corresponding Ada predefined type.
4280
4281 type Inline_Status is (Suppressed, Disabled, Enabled);
4282 -- Inline status of a subprogram, indicated as follows:
4283 -- Suppressed: inlining is suppressed for the subprogram
4284 -- Disabled: no inlining is requested for the subprogram
4285 -- Enabled: inlining is requested/required for the subprogram
4286
4287 procedure Process_Inline (Status : Inline_Status);
4288 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
4289 -- indicates the inline status specified by the pragma.
4290
4291 procedure Process_Interface_Name
4292 (Subprogram_Def : Entity_Id;
4293 Ext_Arg : Node_Id;
4294 Link_Arg : Node_Id;
4295 Prag : Node_Id);
4296 -- Given the last two arguments of pragma Import, pragma Export, or
4297 -- pragma Interface_Name, performs validity checks and sets the
4298 -- Interface_Name field of the given subprogram entity to the
4299 -- appropriate external or link name, depending on the arguments given.
4300 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
4301 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
4302 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
4303 -- nor Link_Arg is present, the interface name is set to the default
4304 -- from the subprogram name. In addition, the pragma itself is passed
4305 -- to analyze any expressions in the case the pragma came from an aspect
4306 -- specification.
4307
4308 procedure Process_Interrupt_Or_Attach_Handler;
4309 -- Common processing for Interrupt and Attach_Handler pragmas
4310
4311 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
4312 -- Common processing for Restrictions and Restriction_Warnings pragmas.
4313 -- Warn is True for Restriction_Warnings, or for Restrictions if the
4314 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
4315 -- is not set in the Restrictions case.
4316
4317 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
4318 -- Common processing for Suppress and Unsuppress. The boolean parameter
4319 -- Suppress_Case is True for the Suppress case, and False for the
4320 -- Unsuppress case.
4321
4322 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
4323 -- Subsidiary to the analysis of pragmas Independent[_Components].
4324 -- Record such a pragma N applied to entity E for future checks.
4325
4326 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
4327 -- This procedure sets the Is_Exported flag for the given entity,
4328 -- checking that the entity was not previously imported. Arg is
4329 -- the argument that specified the entity. A check is also made
4330 -- for exporting inappropriate entities.
4331
4332 procedure Set_Extended_Import_Export_External_Name
4333 (Internal_Ent : Entity_Id;
4334 Arg_External : Node_Id);
4335 -- Common processing for all extended import export pragmas. The first
4336 -- argument, Internal_Ent, is the internal entity, which has already
4337 -- been checked for validity by the caller. Arg_External is from the
4338 -- Import or Export pragma, and may be null if no External parameter
4339 -- was present. If Arg_External is present and is a non-null string
4340 -- (a null string is treated as the default), then the Interface_Name
4341 -- field of Internal_Ent is set appropriately.
4342
4343 procedure Set_Imported (E : Entity_Id);
4344 -- This procedure sets the Is_Imported flag for the given entity,
4345 -- checking that it is not previously exported or imported.
4346
4347 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
4348 -- Mech is a parameter passing mechanism (see Import_Function syntax
4349 -- for MECHANISM_NAME). This routine checks that the mechanism argument
4350 -- has the right form, and if not issues an error message. If the
4351 -- argument has the right form then the Mechanism field of Ent is
4352 -- set appropriately.
4353
4354 procedure Set_Rational_Profile;
4355 -- Activate the set of configuration pragmas and permissions that make
4356 -- up the Rational profile.
4357
4358 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id);
4359 -- Activate the set of configuration pragmas and restrictions that make
4360 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
4361 -- GNAT_Ravenscar_EDF, Jorvik, or Ravenscar. N is the corresponding
4362 -- pragma node, which is used for error messages on any constructs
4363 -- violating the profile.
4364
4365 ---------------------
4366 -- Ada_2005_Pragma --
4367 ---------------------
4368
4369 procedure Ada_2005_Pragma is
4370 begin
4371 if Ada_Version <= Ada_95 then
4372 Check_Restriction (No_Implementation_Pragmas, N);
4373 end if;
4374 end Ada_2005_Pragma;
4375
4376 ---------------------
4377 -- Ada_2012_Pragma --
4378 ---------------------
4379
4380 procedure Ada_2012_Pragma is
4381 begin
4382 if Ada_Version <= Ada_2005 then
4383 Check_Restriction (No_Implementation_Pragmas, N);
4384 end if;
4385 end Ada_2012_Pragma;
4386
4387 ----------------------------
4388 -- Analyze_Depends_Global --
4389 ----------------------------
4390
4391 procedure Analyze_Depends_Global
4392 (Spec_Id : out Entity_Id;
4393 Subp_Decl : out Node_Id;
4394 Legal : out Boolean)
4395 is
4396 begin
4397 -- Assume that the pragma is illegal
4398
4399 Spec_Id := Empty;
4400 Subp_Decl := Empty;
4401 Legal := False;
4402
4403 GNAT_Pragma;
4404 Check_Arg_Count (1);
4405
4406 -- Ensure the proper placement of the pragma. Depends/Global must be
4407 -- associated with a subprogram declaration or a body that acts as a
4408 -- spec.
4409
4410 Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4411
4412 -- Entry
4413
4414 if Nkind (Subp_Decl) = N_Entry_Declaration then
4415 null;
4416
4417 -- Generic subprogram
4418
4419 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4420 null;
4421
4422 -- Object declaration of a single concurrent type
4423
4424 elsif Nkind (Subp_Decl) = N_Object_Declaration
4425 and then Is_Single_Concurrent_Object
4426 (Unique_Defining_Entity (Subp_Decl))
4427 then
4428 null;
4429
4430 -- Single task type
4431
4432 elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then
4433 null;
4434
4435 -- Subprogram body acts as spec
4436
4437 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4438 and then No (Corresponding_Spec (Subp_Decl))
4439 then
4440 null;
4441
4442 -- Subprogram body stub acts as spec
4443
4444 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4445 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
4446 then
4447 null;
4448
4449 -- Subprogram declaration
4450
4451 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4452
4453 -- Pragmas Global and Depends are forbidden on null procedures
4454 -- (SPARK RM 6.1.2(2)).
4455
4456 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4457 and then Null_Present (Specification (Subp_Decl))
4458 then
4459 Error_Msg_N (Fix_Error
4460 ("pragma % cannot apply to null procedure"), N);
4461 return;
4462 end if;
4463
4464 -- Task type
4465
4466 elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then
4467 null;
4468
4469 else
4470 Pragma_Misplaced;
4471 return;
4472 end if;
4473
4474 -- If we get here, then the pragma is legal
4475
4476 Legal := True;
4477 Spec_Id := Unique_Defining_Entity (Subp_Decl);
4478
4479 -- When the related context is an entry, the entry must belong to a
4480 -- protected unit (SPARK RM 6.1.4(6)).
4481
4482 if Is_Entry_Declaration (Spec_Id)
4483 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
4484 then
4485 Pragma_Misplaced;
4486 return;
4487
4488 -- When the related context is an anonymous object created for a
4489 -- simple concurrent type, the type must be a task
4490 -- (SPARK RM 6.1.4(6)).
4491
4492 elsif Is_Single_Concurrent_Object (Spec_Id)
4493 and then Ekind (Etype (Spec_Id)) /= E_Task_Type
4494 then
4495 Pragma_Misplaced;
4496 return;
4497 end if;
4498
4499 -- A pragma that applies to a Ghost entity becomes Ghost for the
4500 -- purposes of legality checks and removal of ignored Ghost code.
4501
4502 Mark_Ghost_Pragma (N, Spec_Id);
4503 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4504 end Analyze_Depends_Global;
4505
4506 ------------------------
4507 -- Analyze_If_Present --
4508 ------------------------
4509
4510 procedure Analyze_If_Present (Id : Pragma_Id) is
4511 Stmt : Node_Id;
4512
4513 begin
4514 pragma Assert (Is_List_Member (N));
4515
4516 -- Inspect the declarations or statements following pragma N looking
4517 -- for another pragma whose Id matches the caller's request. If it is
4518 -- available, analyze it.
4519
4520 Stmt := Next (N);
4521 while Present (Stmt) loop
4522 if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then
4523 Analyze_Pragma (Stmt);
4524 exit;
4525
4526 -- The first source declaration or statement immediately following
4527 -- N ends the region where a pragma may appear.
4528
4529 elsif Comes_From_Source (Stmt) then
4530 exit;
4531 end if;
4532
4533 Next (Stmt);
4534 end loop;
4535 end Analyze_If_Present;
4536
4537 --------------------------------
4538 -- Analyze_Pre_Post_Condition --
4539 --------------------------------
4540
4541 procedure Analyze_Pre_Post_Condition is
4542 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
4543 Subp_Decl : Node_Id;
4544 Subp_Id : Entity_Id;
4545
4546 Duplicates_OK : Boolean := False;
4547 -- Flag set when a pre/postcondition allows multiple pragmas of the
4548 -- same kind.
4549
4550 In_Body_OK : Boolean := False;
4551 -- Flag set when a pre/postcondition is allowed to appear on a body
4552 -- even though the subprogram may have a spec.
4553
4554 Is_Pre_Post : Boolean := False;
4555 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4556 -- Post_Class.
4557
4558 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean;
4559 -- Implement rules in AI12-0131: an overriding operation can have
4560 -- a class-wide precondition only if one of its ancestors has an
4561 -- explicit class-wide precondition.
4562
4563 -----------------------------
4564 -- Inherits_Class_Wide_Pre --
4565 -----------------------------
4566
4567 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean is
4568 Typ : constant Entity_Id := Find_Dispatching_Type (E);
4569 Cont : Node_Id;
4570 Prag : Node_Id;
4571 Prev : Entity_Id := Overridden_Operation (E);
4572
4573 begin
4574 -- Check ancestors on the overriding operation to examine the
4575 -- preconditions that may apply to them.
4576
4577 while Present (Prev) loop
4578 Cont := Contract (Prev);
4579 if Present (Cont) then
4580 Prag := Pre_Post_Conditions (Cont);
4581 while Present (Prag) loop
4582 if Pragma_Name (Prag) = Name_Precondition
4583 and then Class_Present (Prag)
4584 then
4585 return True;
4586 end if;
4587
4588 Prag := Next_Pragma (Prag);
4589 end loop;
4590 end if;
4591
4592 -- For a type derived from a generic formal type, the operation
4593 -- inheriting the condition is a renaming, not an overriding of
4594 -- the operation of the formal. Ditto for an inherited
4595 -- operation which has no explicit contracts.
4596
4597 if Is_Generic_Type (Find_Dispatching_Type (Prev))
4598 or else not Comes_From_Source (Prev)
4599 then
4600 Prev := Alias (Prev);
4601 else
4602 Prev := Overridden_Operation (Prev);
4603 end if;
4604 end loop;
4605
4606 -- If the controlling type of the subprogram has progenitors, an
4607 -- interface operation implemented by the current operation may
4608 -- have a class-wide precondition.
4609
4610 if Has_Interfaces (Typ) then
4611 declare
4612 Elmt : Elmt_Id;
4613 Ints : Elist_Id;
4614 Prim : Entity_Id;
4615 Prim_Elmt : Elmt_Id;
4616 Prim_List : Elist_Id;
4617
4618 begin
4619 Collect_Interfaces (Typ, Ints);
4620 Elmt := First_Elmt (Ints);
4621
4622 -- Iterate over the primitive operations of each interface
4623
4624 while Present (Elmt) loop
4625 Prim_List := Direct_Primitive_Operations (Node (Elmt));
4626 Prim_Elmt := First_Elmt (Prim_List);
4627 while Present (Prim_Elmt) loop
4628 Prim := Node (Prim_Elmt);
4629 if Chars (Prim) = Chars (E)
4630 and then Present (Contract (Prim))
4631 and then Class_Present
4632 (Pre_Post_Conditions (Contract (Prim)))
4633 then
4634 return True;
4635 end if;
4636
4637 Next_Elmt (Prim_Elmt);
4638 end loop;
4639
4640 Next_Elmt (Elmt);
4641 end loop;
4642 end;
4643 end if;
4644
4645 return False;
4646 end Inherits_Class_Wide_Pre;
4647
4648 -- Start of processing for Analyze_Pre_Post_Condition
4649
4650 begin
4651 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4652 -- offer uniformity among the various kinds of pre/postconditions by
4653 -- rewriting the pragma identifier. This allows the retrieval of the
4654 -- original pragma name by routine Original_Aspect_Pragma_Name.
4655
4656 if Comes_From_Source (N) then
4657 if Pname in Name_Pre | Name_Pre_Class then
4658 Is_Pre_Post := True;
4659 Set_Class_Present (N, Pname = Name_Pre_Class);
4660 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
4661
4662 elsif Pname in Name_Post | Name_Post_Class then
4663 Is_Pre_Post := True;
4664 Set_Class_Present (N, Pname = Name_Post_Class);
4665 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
4666 end if;
4667 end if;
4668
4669 -- Determine the semantics with respect to duplicates and placement
4670 -- in a body. Pragmas Precondition and Postcondition were introduced
4671 -- before aspects and are not subject to the same aspect-like rules.
4672
4673 if Pname in Name_Precondition | Name_Postcondition then
4674 Duplicates_OK := True;
4675 In_Body_OK := True;
4676 end if;
4677
4678 GNAT_Pragma;
4679
4680 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4681 -- argument without an identifier.
4682
4683 if Is_Pre_Post then
4684 Check_Arg_Count (1);
4685 Check_No_Identifiers;
4686
4687 -- Pragmas Precondition and Postcondition have complex argument
4688 -- profile.
4689
4690 else
4691 Check_At_Least_N_Arguments (1);
4692 Check_At_Most_N_Arguments (2);
4693 Check_Optional_Identifier (Arg1, Name_Check);
4694
4695 if Present (Arg2) then
4696 Check_Optional_Identifier (Arg2, Name_Message);
4697 Preanalyze_Spec_Expression
4698 (Get_Pragma_Arg (Arg2), Standard_String);
4699 end if;
4700 end if;
4701
4702 -- For a pragma PPC in the extended main source unit, record enabled
4703 -- status in SCO.
4704 -- ??? nothing checks that the pragma is in the main source unit
4705
4706 if Is_Checked (N) and then not Split_PPC (N) then
4707 Set_SCO_Pragma_Enabled (Loc);
4708 end if;
4709
4710 -- Ensure the proper placement of the pragma
4711
4712 Subp_Decl :=
4713 Find_Related_Declaration_Or_Body
4714 (N, Do_Checks => not Duplicates_OK);
4715
4716 -- When a pre/postcondition pragma applies to an abstract subprogram,
4717 -- its original form must be an aspect with 'Class.
4718
4719 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4720 if not From_Aspect_Specification (N) then
4721 Error_Pragma
4722 ("pragma % cannot be applied to abstract subprogram");
4723
4724 elsif not Class_Present (N) then
4725 Error_Pragma
4726 ("aspect % requires ''Class for abstract subprogram");
4727 end if;
4728
4729 -- Entry declaration
4730
4731 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
4732 null;
4733
4734 -- Generic subprogram declaration
4735
4736 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4737 null;
4738
4739 -- Subprogram body
4740
4741 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4742 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
4743 then
4744 null;
4745
4746 -- Subprogram body stub
4747
4748 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4749 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
4750 then
4751 null;
4752
4753 -- Subprogram declaration
4754
4755 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4756
4757 -- AI05-0230: When a pre/postcondition pragma applies to a null
4758 -- procedure, its original form must be an aspect with 'Class.
4759
4760 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4761 and then Null_Present (Specification (Subp_Decl))
4762 and then From_Aspect_Specification (N)
4763 and then not Class_Present (N)
4764 then
4765 Error_Pragma ("aspect % requires ''Class for null procedure");
4766 end if;
4767
4768 -- Implement the legality checks mandated by AI12-0131:
4769 -- Pre'Class shall not be specified for an overriding primitive
4770 -- subprogram of a tagged type T unless the Pre'Class aspect is
4771 -- specified for the corresponding primitive subprogram of some
4772 -- ancestor of T.
4773
4774 declare
4775 E : constant Entity_Id := Defining_Entity (Subp_Decl);
4776
4777 begin
4778 if Class_Present (N)
4779 and then Pragma_Name (N) = Name_Precondition
4780 and then Present (Overridden_Operation (E))
4781 and then not Inherits_Class_Wide_Pre (E)
4782 then
4783 Error_Msg_N
4784 ("illegal class-wide precondition on overriding operation",
4785 Corresponding_Aspect (N));
4786 end if;
4787 end;
4788
4789 -- A renaming declaration may inherit a generated pragma, its
4790 -- placement comes from expansion, not from source.
4791
4792 elsif Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
4793 and then not Comes_From_Source (N)
4794 then
4795 null;
4796
4797 -- For Ada 2020, pre/postconditions can appear on formal subprograms
4798
4799 elsif Nkind (Subp_Decl) = N_Formal_Concrete_Subprogram_Declaration
4800 and then Ada_Version >= Ada_2020
4801 then
4802 null;
4803
4804 -- An access-to-subprogram type can have pre/postconditions, but
4805 -- these are transferred to the generated subprogram wrapper and
4806 -- analyzed there.
4807
4808 -- Otherwise the placement of the pragma is illegal
4809
4810 else
4811 Pragma_Misplaced;
4812 return;
4813 end if;
4814
4815 Subp_Id := Defining_Entity (Subp_Decl);
4816
4817 -- A pragma that applies to a Ghost entity becomes Ghost for the
4818 -- purposes of legality checks and removal of ignored Ghost code.
4819
4820 Mark_Ghost_Pragma (N, Subp_Id);
4821
4822 -- Chain the pragma on the contract for further processing by
4823 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4824
4825 Add_Contract_Item (N, Subp_Id);
4826
4827 -- Fully analyze the pragma when it appears inside an entry or
4828 -- subprogram body because it cannot benefit from forward references.
4829
4830 if Nkind (Subp_Decl) in N_Entry_Body
4831 | N_Subprogram_Body
4832 | N_Subprogram_Body_Stub
4833 then
4834 -- The legality checks of pragmas Precondition and Postcondition
4835 -- are affected by the SPARK mode in effect and the volatility of
4836 -- the context. Analyze all pragmas in a specific order.
4837
4838 Analyze_If_Present (Pragma_SPARK_Mode);
4839 Analyze_If_Present (Pragma_Volatile_Function);
4840 Analyze_Pre_Post_Condition_In_Decl_Part (N);
4841 end if;
4842 end Analyze_Pre_Post_Condition;
4843
4844 -----------------------------------------
4845 -- Analyze_Refined_Depends_Global_Post --
4846 -----------------------------------------
4847
4848 procedure Analyze_Refined_Depends_Global_Post
4849 (Spec_Id : out Entity_Id;
4850 Body_Id : out Entity_Id;
4851 Legal : out Boolean)
4852 is
4853 Body_Decl : Node_Id;
4854 Spec_Decl : Node_Id;
4855
4856 begin
4857 -- Assume that the pragma is illegal
4858
4859 Spec_Id := Empty;
4860 Body_Id := Empty;
4861 Legal := False;
4862
4863 GNAT_Pragma;
4864 Check_Arg_Count (1);
4865 Check_No_Identifiers;
4866
4867 -- Verify the placement of the pragma and check for duplicates. The
4868 -- pragma must apply to a subprogram body [stub].
4869
4870 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4871
4872 if Nkind (Body_Decl) not in
4873 N_Entry_Body | N_Subprogram_Body | N_Subprogram_Body_Stub |
4874 N_Task_Body | N_Task_Body_Stub
4875 then
4876 Pragma_Misplaced;
4877 return;
4878 end if;
4879
4880 Body_Id := Defining_Entity (Body_Decl);
4881 Spec_Id := Unique_Defining_Entity (Body_Decl);
4882
4883 -- The pragma must apply to the second declaration of a subprogram.
4884 -- In other words, the body [stub] cannot acts as a spec.
4885
4886 if No (Spec_Id) then
4887 Error_Pragma ("pragma % cannot apply to a stand alone body");
4888 return;
4889
4890 -- Catch the case where the subprogram body is a subunit and acts as
4891 -- the third declaration of the subprogram.
4892
4893 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
4894 Error_Pragma ("pragma % cannot apply to a subunit");
4895 return;
4896 end if;
4897
4898 -- A refined pragma can only apply to the body [stub] of a subprogram
4899 -- declared in the visible part of a package. Retrieve the context of
4900 -- the subprogram declaration.
4901
4902 Spec_Decl := Unit_Declaration_Node (Spec_Id);
4903
4904 -- When dealing with protected entries or protected subprograms, use
4905 -- the enclosing protected type as the proper context.
4906
4907 if Ekind (Spec_Id) in E_Entry
4908 | E_Entry_Family
4909 | E_Function
4910 | E_Procedure
4911 and then Ekind (Scope (Spec_Id)) = E_Protected_Type
4912 then
4913 Spec_Decl := Declaration_Node (Scope (Spec_Id));
4914 end if;
4915
4916 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
4917 Error_Pragma
4918 (Fix_Msg (Spec_Id, "pragma % must apply to the body of "
4919 & "subprogram declared in a package specification"));
4920 return;
4921 end if;
4922
4923 -- If we get here, then the pragma is legal
4924
4925 Legal := True;
4926
4927 -- A pragma that applies to a Ghost entity becomes Ghost for the
4928 -- purposes of legality checks and removal of ignored Ghost code.
4929
4930 Mark_Ghost_Pragma (N, Spec_Id);
4931
4932 if Pname in Name_Refined_Depends | Name_Refined_Global then
4933 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4934 end if;
4935 end Analyze_Refined_Depends_Global_Post;
4936
4937 ----------------------------------
4938 -- Analyze_Unmodified_Or_Unused --
4939 ----------------------------------
4940
4941 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False) is
4942 Arg : Node_Id;
4943 Arg_Expr : Node_Id;
4944 Arg_Id : Entity_Id;
4945
4946 Ghost_Error_Posted : Boolean := False;
4947 -- Flag set when an error concerning the illegal mix of Ghost and
4948 -- non-Ghost variables is emitted.
4949
4950 Ghost_Id : Entity_Id := Empty;
4951 -- The entity of the first Ghost variable encountered while
4952 -- processing the arguments of the pragma.
4953
4954 begin
4955 GNAT_Pragma;
4956 Check_At_Least_N_Arguments (1);
4957
4958 -- Loop through arguments
4959
4960 Arg := Arg1;
4961 while Present (Arg) loop
4962 Check_No_Identifier (Arg);
4963
4964 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4965 -- in fact generate reference, so that the entity will have a
4966 -- reference, which will inhibit any warnings about it not
4967 -- being referenced, and also properly show up in the ali file
4968 -- as a reference. But this reference is recorded before the
4969 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4970 -- generated for this reference.
4971
4972 Check_Arg_Is_Local_Name (Arg);
4973 Arg_Expr := Get_Pragma_Arg (Arg);
4974
4975 if Is_Entity_Name (Arg_Expr) then
4976 Arg_Id := Entity (Arg_Expr);
4977
4978 -- Skip processing the argument if already flagged
4979
4980 if Is_Assignable (Arg_Id)
4981 and then not Has_Pragma_Unmodified (Arg_Id)
4982 and then not Has_Pragma_Unused (Arg_Id)
4983 then
4984 Set_Has_Pragma_Unmodified (Arg_Id);
4985
4986 if Is_Unused then
4987 Set_Has_Pragma_Unused (Arg_Id);
4988 end if;
4989
4990 -- A pragma that applies to a Ghost entity becomes Ghost for
4991 -- the purposes of legality checks and removal of ignored
4992 -- Ghost code.
4993
4994 Mark_Ghost_Pragma (N, Arg_Id);
4995
4996 -- Capture the entity of the first Ghost variable being
4997 -- processed for error detection purposes.
4998
4999 if Is_Ghost_Entity (Arg_Id) then
5000 if No (Ghost_Id) then
5001 Ghost_Id := Arg_Id;
5002 end if;
5003
5004 -- Otherwise the variable is non-Ghost. It is illegal to mix
5005 -- references to Ghost and non-Ghost entities
5006 -- (SPARK RM 6.9).
5007
5008 elsif Present (Ghost_Id)
5009 and then not Ghost_Error_Posted
5010 then
5011 Ghost_Error_Posted := True;
5012
5013 Error_Msg_Name_1 := Pname;
5014 Error_Msg_N
5015 ("pragma % cannot mention ghost and non-ghost "
5016 & "variables", N);
5017
5018 Error_Msg_Sloc := Sloc (Ghost_Id);
5019 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
5020
5021 Error_Msg_Sloc := Sloc (Arg_Id);
5022 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
5023 end if;
5024
5025 -- Warn if already flagged as Unused or Unmodified
5026
5027 elsif Has_Pragma_Unmodified (Arg_Id) then
5028 if Has_Pragma_Unused (Arg_Id) then
5029 Error_Msg_NE
5030 ("??pragma Unused already given for &!", Arg_Expr,
5031 Arg_Id);
5032 else
5033 Error_Msg_NE
5034 ("??pragma Unmodified already given for &!", Arg_Expr,
5035 Arg_Id);
5036 end if;
5037
5038 -- Otherwise the pragma referenced an illegal entity
5039
5040 else
5041 Error_Pragma_Arg
5042 ("pragma% can only be applied to a variable", Arg_Expr);
5043 end if;
5044 end if;
5045
5046 Next (Arg);
5047 end loop;
5048 end Analyze_Unmodified_Or_Unused;
5049
5050 ------------------------------------
5051 -- Analyze_Unreferenced_Or_Unused --
5052 ------------------------------------
5053
5054 procedure Analyze_Unreferenced_Or_Unused
5055 (Is_Unused : Boolean := False)
5056 is
5057 Arg : Node_Id;
5058 Arg_Expr : Node_Id;
5059 Arg_Id : Entity_Id;
5060 Citem : Node_Id;
5061
5062 Ghost_Error_Posted : Boolean := False;
5063 -- Flag set when an error concerning the illegal mix of Ghost and
5064 -- non-Ghost names is emitted.
5065
5066 Ghost_Id : Entity_Id := Empty;
5067 -- The entity of the first Ghost name encountered while processing
5068 -- the arguments of the pragma.
5069
5070 begin
5071 GNAT_Pragma;
5072 Check_At_Least_N_Arguments (1);
5073
5074 -- Check case of appearing within context clause
5075
5076 if not Is_Unused and then Is_In_Context_Clause then
5077
5078 -- The arguments must all be units mentioned in a with clause in
5079 -- the same context clause. Note that Par.Prag already checked
5080 -- that the arguments are either identifiers or selected
5081 -- components.
5082
5083 Arg := Arg1;
5084 while Present (Arg) loop
5085 Citem := First (List_Containing (N));
5086 while Citem /= N loop
5087 Arg_Expr := Get_Pragma_Arg (Arg);
5088
5089 if Nkind (Citem) = N_With_Clause
5090 and then Same_Name (Name (Citem), Arg_Expr)
5091 then
5092 Set_Has_Pragma_Unreferenced
5093 (Cunit_Entity
5094 (Get_Source_Unit
5095 (Library_Unit (Citem))));
5096 Set_Elab_Unit_Name (Arg_Expr, Name (Citem));
5097 exit;
5098 end if;
5099
5100 Next (Citem);
5101 end loop;
5102
5103 if Citem = N then
5104 Error_Pragma_Arg
5105 ("argument of pragma% is not withed unit", Arg);
5106 end if;
5107
5108 Next (Arg);
5109 end loop;
5110
5111 -- Case of not in list of context items
5112
5113 else
5114 Arg := Arg1;
5115 while Present (Arg) loop
5116 Check_No_Identifier (Arg);
5117
5118 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
5119 -- in fact generate reference, so that the entity will have a
5120 -- reference, which will inhibit any warnings about it not
5121 -- being referenced, and also properly show up in the ali file
5122 -- as a reference. But this reference is recorded before the
5123 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5124 -- generated for this reference.
5125
5126 Check_Arg_Is_Local_Name (Arg);
5127 Arg_Expr := Get_Pragma_Arg (Arg);
5128
5129 if Is_Entity_Name (Arg_Expr) then
5130 Arg_Id := Entity (Arg_Expr);
5131
5132 -- Warn if already flagged as Unused or Unreferenced and
5133 -- skip processing the argument.
5134
5135 if Has_Pragma_Unreferenced (Arg_Id) then
5136 if Has_Pragma_Unused (Arg_Id) then
5137 Error_Msg_NE
5138 ("??pragma Unused already given for &!", Arg_Expr,
5139 Arg_Id);
5140 else
5141 Error_Msg_NE
5142 ("??pragma Unreferenced already given for &!",
5143 Arg_Expr, Arg_Id);
5144 end if;
5145
5146 -- Apply Unreferenced to the entity
5147
5148 else
5149 -- If the entity is overloaded, the pragma applies to the
5150 -- most recent overloading, as documented. In this case,
5151 -- name resolution does not generate a reference, so it
5152 -- must be done here explicitly.
5153
5154 if Is_Overloaded (Arg_Expr) then
5155 Generate_Reference (Arg_Id, N);
5156 end if;
5157
5158 Set_Has_Pragma_Unreferenced (Arg_Id);
5159
5160 if Is_Unused then
5161 Set_Has_Pragma_Unused (Arg_Id);
5162 end if;
5163
5164 -- A pragma that applies to a Ghost entity becomes Ghost
5165 -- for the purposes of legality checks and removal of
5166 -- ignored Ghost code.
5167
5168 Mark_Ghost_Pragma (N, Arg_Id);
5169
5170 -- Capture the entity of the first Ghost name being
5171 -- processed for error detection purposes.
5172
5173 if Is_Ghost_Entity (Arg_Id) then
5174 if No (Ghost_Id) then
5175 Ghost_Id := Arg_Id;
5176 end if;
5177
5178 -- Otherwise the name is non-Ghost. It is illegal to mix
5179 -- references to Ghost and non-Ghost entities
5180 -- (SPARK RM 6.9).
5181
5182 elsif Present (Ghost_Id)
5183 and then not Ghost_Error_Posted
5184 then
5185 Ghost_Error_Posted := True;
5186
5187 Error_Msg_Name_1 := Pname;
5188 Error_Msg_N
5189 ("pragma % cannot mention ghost and non-ghost "
5190 & "names", N);
5191
5192 Error_Msg_Sloc := Sloc (Ghost_Id);
5193 Error_Msg_NE
5194 ("\& # declared as ghost", N, Ghost_Id);
5195
5196 Error_Msg_Sloc := Sloc (Arg_Id);
5197 Error_Msg_NE
5198 ("\& # declared as non-ghost", N, Arg_Id);
5199 end if;
5200 end if;
5201 end if;
5202
5203 Next (Arg);
5204 end loop;
5205 end if;
5206 end Analyze_Unreferenced_Or_Unused;
5207
5208 --------------------------
5209 -- Check_Ada_83_Warning --
5210 --------------------------
5211
5212 procedure Check_Ada_83_Warning is
5213 begin
5214 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5215 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
5216 end if;
5217 end Check_Ada_83_Warning;
5218
5219 ---------------------
5220 -- Check_Arg_Count --
5221 ---------------------
5222
5223 procedure Check_Arg_Count (Required : Nat) is
5224 begin
5225 if Arg_Count /= Required then
5226 Error_Pragma ("wrong number of arguments for pragma%");
5227 end if;
5228 end Check_Arg_Count;
5229
5230 --------------------------------
5231 -- Check_Arg_Is_External_Name --
5232 --------------------------------
5233
5234 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
5235 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5236
5237 begin
5238 if Nkind (Argx) = N_Identifier then
5239 return;
5240
5241 else
5242 Analyze_And_Resolve (Argx, Standard_String);
5243
5244 if Is_OK_Static_Expression (Argx) then
5245 return;
5246
5247 elsif Etype (Argx) = Any_Type then
5248 raise Pragma_Exit;
5249
5250 -- An interesting special case, if we have a string literal and
5251 -- we are in Ada 83 mode, then we allow it even though it will
5252 -- not be flagged as static. This allows expected Ada 83 mode
5253 -- use of external names which are string literals, even though
5254 -- technically these are not static in Ada 83.
5255
5256 elsif Ada_Version = Ada_83
5257 and then Nkind (Argx) = N_String_Literal
5258 then
5259 return;
5260
5261 -- Here we have a real error (non-static expression)
5262
5263 else
5264 Error_Msg_Name_1 := Pname;
5265 Flag_Non_Static_Expr
5266 (Fix_Error ("argument for pragma% must be a identifier or "
5267 & "static string expression!"), Argx);
5268
5269 raise Pragma_Exit;
5270 end if;
5271 end if;
5272 end Check_Arg_Is_External_Name;
5273
5274 -----------------------------
5275 -- Check_Arg_Is_Identifier --
5276 -----------------------------
5277
5278 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
5279 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5280 begin
5281 if Nkind (Argx) /= N_Identifier then
5282 Error_Pragma_Arg ("argument for pragma% must be identifier", Argx);
5283 end if;
5284 end Check_Arg_Is_Identifier;
5285
5286 ----------------------------------
5287 -- Check_Arg_Is_Integer_Literal --
5288 ----------------------------------
5289
5290 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
5291 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5292 begin
5293 if Nkind (Argx) /= N_Integer_Literal then
5294 Error_Pragma_Arg
5295 ("argument for pragma% must be integer literal", Argx);
5296 end if;
5297 end Check_Arg_Is_Integer_Literal;
5298
5299 -------------------------------------------
5300 -- Check_Arg_Is_Library_Level_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_Library_Level_Local_Name (Arg : Node_Id) is
5309 begin
5310 Check_Arg_Is_Local_Name (Arg);
5311
5312 -- If it came from an aspect, we want to give the error just as if it
5313 -- came from source.
5314
5315 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
5316 and then (Comes_From_Source (N)
5317 or else Present (Corresponding_Aspect (Parent (Arg))))
5318 then
5319 Error_Pragma_Arg
5320 ("argument for pragma% must be library level entity", Arg);
5321 end if;
5322 end Check_Arg_Is_Library_Level_Local_Name;
5323
5324 -----------------------------
5325 -- Check_Arg_Is_Local_Name --
5326 -----------------------------
5327
5328 -- LOCAL_NAME ::=
5329 -- DIRECT_NAME
5330 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5331 -- | library_unit_NAME
5332
5333 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
5334 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5335
5336 begin
5337 -- If this pragma came from an aspect specification, we don't want to
5338 -- check for this error, because that would cause spurious errors, in
5339 -- case a type is frozen in a scope more nested than the type. The
5340 -- aspect itself of course can't be anywhere but on the declaration
5341 -- itself.
5342
5343 if Nkind (Arg) = N_Pragma_Argument_Association then
5344 if From_Aspect_Specification (Parent (Arg)) then
5345 return;
5346 end if;
5347
5348 -- Arg is the Expression of an N_Pragma_Argument_Association
5349
5350 else
5351 if From_Aspect_Specification (Parent (Parent (Arg))) then
5352 return;
5353 end if;
5354 end if;
5355
5356 Analyze (Argx);
5357
5358 if Nkind (Argx) not in N_Direct_Name
5359 and then (Nkind (Argx) /= N_Attribute_Reference
5360 or else Present (Expressions (Argx))
5361 or else Nkind (Prefix (Argx)) /= N_Identifier)
5362 and then (not Is_Entity_Name (Argx)
5363 or else not Is_Compilation_Unit (Entity (Argx)))
5364 then
5365 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
5366 end if;
5367
5368 -- No further check required if not an entity name
5369
5370 if not Is_Entity_Name (Argx) then
5371 null;
5372
5373 else
5374 declare
5375 OK : Boolean;
5376 Ent : constant Entity_Id := Entity (Argx);
5377 Scop : constant Entity_Id := Scope (Ent);
5378
5379 begin
5380 -- Case of a pragma applied to a compilation unit: pragma must
5381 -- occur immediately after the program unit in the compilation.
5382
5383 if Is_Compilation_Unit (Ent) then
5384 declare
5385 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
5386
5387 begin
5388 -- Case of pragma placed immediately after spec
5389
5390 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
5391 OK := True;
5392
5393 -- Case of pragma placed immediately after body
5394
5395 elsif Nkind (Decl) = N_Subprogram_Declaration
5396 and then Present (Corresponding_Body (Decl))
5397 then
5398 OK := Parent (N) =
5399 Aux_Decls_Node
5400 (Parent (Unit_Declaration_Node
5401 (Corresponding_Body (Decl))));
5402
5403 -- All other cases are illegal
5404
5405 else
5406 OK := False;
5407 end if;
5408 end;
5409
5410 -- Special restricted placement rule from 10.2.1(11.8/2)
5411
5412 elsif Is_Generic_Formal (Ent)
5413 and then Prag_Id = Pragma_Preelaborable_Initialization
5414 then
5415 OK := List_Containing (N) =
5416 Generic_Formal_Declarations
5417 (Unit_Declaration_Node (Scop));
5418
5419 -- If this is an aspect applied to a subprogram body, the
5420 -- pragma is inserted in its declarative part.
5421
5422 elsif From_Aspect_Specification (N)
5423 and then Ent = Current_Scope
5424 and then
5425 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
5426 then
5427 OK := True;
5428
5429 -- If the aspect is a predicate (possibly others ???) and the
5430 -- context is a record type, this is a discriminant expression
5431 -- within a type declaration, that freezes the predicated
5432 -- subtype.
5433
5434 elsif From_Aspect_Specification (N)
5435 and then Prag_Id = Pragma_Predicate
5436 and then Ekind (Current_Scope) = E_Record_Type
5437 and then Scop = Scope (Current_Scope)
5438 then
5439 OK := True;
5440
5441 -- Default case, just check that the pragma occurs in the scope
5442 -- of the entity denoted by the name.
5443
5444 else
5445 OK := Current_Scope = Scop;
5446 end if;
5447
5448 if not OK then
5449 Error_Pragma_Arg
5450 ("pragma% argument must be in same declarative part", Arg);
5451 end if;
5452 end;
5453 end if;
5454 end Check_Arg_Is_Local_Name;
5455
5456 ---------------------------------
5457 -- Check_Arg_Is_Locking_Policy --
5458 ---------------------------------
5459
5460 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
5461 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5462
5463 begin
5464 Check_Arg_Is_Identifier (Argx);
5465
5466 if not Is_Locking_Policy_Name (Chars (Argx)) then
5467 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
5468 end if;
5469 end Check_Arg_Is_Locking_Policy;
5470
5471 -----------------------------------------------
5472 -- Check_Arg_Is_Partition_Elaboration_Policy --
5473 -----------------------------------------------
5474
5475 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
5476 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5477
5478 begin
5479 Check_Arg_Is_Identifier (Argx);
5480
5481 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
5482 Error_Pragma_Arg
5483 ("& is not a valid partition elaboration policy name", Argx);
5484 end if;
5485 end Check_Arg_Is_Partition_Elaboration_Policy;
5486
5487 -------------------------
5488 -- Check_Arg_Is_One_Of --
5489 -------------------------
5490
5491 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5492 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5493
5494 begin
5495 Check_Arg_Is_Identifier (Argx);
5496
5497 if Chars (Argx) not in N1 | N2 then
5498 Error_Msg_Name_2 := N1;
5499 Error_Msg_Name_3 := N2;
5500 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
5501 end if;
5502 end Check_Arg_Is_One_Of;
5503
5504 procedure Check_Arg_Is_One_Of
5505 (Arg : Node_Id;
5506 N1, N2, N3 : Name_Id)
5507 is
5508 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5509
5510 begin
5511 Check_Arg_Is_Identifier (Argx);
5512
5513 if Chars (Argx) not in N1 | N2 | N3 then
5514 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5515 end if;
5516 end Check_Arg_Is_One_Of;
5517
5518 procedure Check_Arg_Is_One_Of
5519 (Arg : Node_Id;
5520 N1, N2, N3, N4 : Name_Id)
5521 is
5522 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5523
5524 begin
5525 Check_Arg_Is_Identifier (Argx);
5526
5527 if Chars (Argx) not in N1 | N2 | N3 | N4 then
5528 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5529 end if;
5530 end Check_Arg_Is_One_Of;
5531
5532 procedure Check_Arg_Is_One_Of
5533 (Arg : Node_Id;
5534 N1, N2, N3, N4, N5 : Name_Id)
5535 is
5536 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5537
5538 begin
5539 Check_Arg_Is_Identifier (Argx);
5540
5541 if Chars (Argx) not in N1 | N2 | N3 | N4 | N5 then
5542 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5543 end if;
5544 end Check_Arg_Is_One_Of;
5545
5546 ---------------------------------
5547 -- Check_Arg_Is_Queuing_Policy --
5548 ---------------------------------
5549
5550 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
5551 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5552
5553 begin
5554 Check_Arg_Is_Identifier (Argx);
5555
5556 if not Is_Queuing_Policy_Name (Chars (Argx)) then
5557 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
5558 end if;
5559 end Check_Arg_Is_Queuing_Policy;
5560
5561 ---------------------------------------
5562 -- Check_Arg_Is_OK_Static_Expression --
5563 ---------------------------------------
5564
5565 procedure Check_Arg_Is_OK_Static_Expression
5566 (Arg : Node_Id;
5567 Typ : Entity_Id := Empty)
5568 is
5569 begin
5570 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
5571 end Check_Arg_Is_OK_Static_Expression;
5572
5573 ------------------------------------------
5574 -- Check_Arg_Is_Task_Dispatching_Policy --
5575 ------------------------------------------
5576
5577 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
5578 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5579
5580 begin
5581 Check_Arg_Is_Identifier (Argx);
5582
5583 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
5584 Error_Pragma_Arg
5585 ("& is not an allowed task dispatching policy name", Argx);
5586 end if;
5587 end Check_Arg_Is_Task_Dispatching_Policy;
5588
5589 ---------------------
5590 -- Check_Arg_Order --
5591 ---------------------
5592
5593 procedure Check_Arg_Order (Names : Name_List) is
5594 Arg : Node_Id;
5595
5596 Highest_So_Far : Natural := 0;
5597 -- Highest index in Names seen do far
5598
5599 begin
5600 Arg := Arg1;
5601 for J in 1 .. Arg_Count loop
5602 if Chars (Arg) /= No_Name then
5603 for K in Names'Range loop
5604 if Chars (Arg) = Names (K) then
5605 if K < Highest_So_Far then
5606 Error_Msg_Name_1 := Pname;
5607 Error_Msg_N
5608 ("parameters out of order for pragma%", Arg);
5609 Error_Msg_Name_1 := Names (K);
5610 Error_Msg_Name_2 := Names (Highest_So_Far);
5611 Error_Msg_N ("\% must appear before %", Arg);
5612 raise Pragma_Exit;
5613
5614 else
5615 Highest_So_Far := K;
5616 end if;
5617 end if;
5618 end loop;
5619 end if;
5620
5621 Arg := Next (Arg);
5622 end loop;
5623 end Check_Arg_Order;
5624
5625 --------------------------------
5626 -- Check_At_Least_N_Arguments --
5627 --------------------------------
5628
5629 procedure Check_At_Least_N_Arguments (N : Nat) is
5630 begin
5631 if Arg_Count < N then
5632 Error_Pragma ("too few arguments for pragma%");
5633 end if;
5634 end Check_At_Least_N_Arguments;
5635
5636 -------------------------------
5637 -- Check_At_Most_N_Arguments --
5638 -------------------------------
5639
5640 procedure Check_At_Most_N_Arguments (N : Nat) is
5641 Arg : Node_Id;
5642 begin
5643 if Arg_Count > N then
5644 Arg := Arg1;
5645 for J in 1 .. N loop
5646 Next (Arg);
5647 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
5648 end loop;
5649 end if;
5650 end Check_At_Most_N_Arguments;
5651
5652 ---------------------
5653 -- Check_Component --
5654 ---------------------
5655
5656 procedure Check_Component
5657 (Comp : Node_Id;
5658 UU_Typ : Entity_Id;
5659 In_Variant_Part : Boolean := False)
5660 is
5661 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
5662 Sindic : constant Node_Id :=
5663 Subtype_Indication (Component_Definition (Comp));
5664 Typ : constant Entity_Id := Etype (Comp_Id);
5665
5666 begin
5667 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
5668 -- object constraint, then the component type shall be an Unchecked_
5669 -- Union.
5670
5671 if Nkind (Sindic) = N_Subtype_Indication
5672 and then Has_Per_Object_Constraint (Comp_Id)
5673 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
5674 then
5675 Error_Msg_N
5676 ("component subtype subject to per-object constraint "
5677 & "must be an Unchecked_Union", Comp);
5678
5679 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
5680 -- the body of a generic unit, or within the body of any of its
5681 -- descendant library units, no part of the type of a component
5682 -- declared in a variant_part of the unchecked union type shall be of
5683 -- a formal private type or formal private extension declared within
5684 -- the formal part of the generic unit.
5685
5686 elsif Ada_Version >= Ada_2012
5687 and then In_Generic_Body (UU_Typ)
5688 and then In_Variant_Part
5689 and then Is_Private_Type (Typ)
5690 and then Is_Generic_Type (Typ)
5691 then
5692 Error_Msg_N
5693 ("component of unchecked union cannot be of generic type", Comp);
5694
5695 elsif Needs_Finalization (Typ) then
5696 Error_Msg_N
5697 ("component of unchecked union cannot be controlled", Comp);
5698
5699 elsif Has_Task (Typ) then
5700 Error_Msg_N
5701 ("component of unchecked union cannot have tasks", Comp);
5702 end if;
5703 end Check_Component;
5704
5705 ----------------------------
5706 -- Check_Duplicate_Pragma --
5707 ----------------------------
5708
5709 procedure Check_Duplicate_Pragma (E : Entity_Id) is
5710 Id : Entity_Id := E;
5711 P : Node_Id;
5712
5713 begin
5714 -- Nothing to do if this pragma comes from an aspect specification,
5715 -- since we could not be duplicating a pragma, and we dealt with the
5716 -- case of duplicated aspects in Analyze_Aspect_Specifications.
5717
5718 if From_Aspect_Specification (N) then
5719 return;
5720 end if;
5721
5722 -- Otherwise current pragma may duplicate previous pragma or a
5723 -- previously given aspect specification or attribute definition
5724 -- clause for the same pragma.
5725
5726 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
5727
5728 if Present (P) then
5729
5730 -- If the entity is a type, then we have to make sure that the
5731 -- ostensible duplicate is not for a parent type from which this
5732 -- type is derived.
5733
5734 if Is_Type (E) then
5735 if Nkind (P) = N_Pragma then
5736 declare
5737 Args : constant List_Id :=
5738 Pragma_Argument_Associations (P);
5739 begin
5740 if Present (Args)
5741 and then Is_Entity_Name (Expression (First (Args)))
5742 and then Is_Type (Entity (Expression (First (Args))))
5743 and then Entity (Expression (First (Args))) /= E
5744 then
5745 return;
5746 end if;
5747 end;
5748
5749 elsif Nkind (P) = N_Aspect_Specification
5750 and then Is_Type (Entity (P))
5751 and then Entity (P) /= E
5752 then
5753 return;
5754 end if;
5755 end if;
5756
5757 -- Here we have a definite duplicate
5758
5759 Error_Msg_Name_1 := Pragma_Name (N);
5760 Error_Msg_Sloc := Sloc (P);
5761
5762 -- For a single protected or a single task object, the error is
5763 -- issued on the original entity.
5764
5765 if Ekind (Id) in E_Task_Type | E_Protected_Type then
5766 Id := Defining_Identifier (Original_Node (Parent (Id)));
5767 end if;
5768
5769 if Nkind (P) = N_Aspect_Specification
5770 or else From_Aspect_Specification (P)
5771 then
5772 Error_Msg_NE ("aspect% for & previously given#", N, Id);
5773 else
5774 -- If -gnatwr is set, warn in case of a duplicate pragma
5775 -- [No_]Inline which is suspicious but not an error, generate
5776 -- an error for other pragmas.
5777
5778 if Pragma_Name (N) in Name_Inline | Name_No_Inline then
5779 if Warn_On_Redundant_Constructs then
5780 Error_Msg_NE
5781 ("?r?pragma% for & duplicates pragma#", N, Id);
5782 end if;
5783 else
5784 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
5785 end if;
5786 end if;
5787
5788 raise Pragma_Exit;
5789 end if;
5790 end Check_Duplicate_Pragma;
5791
5792 ----------------------------------
5793 -- Check_Duplicated_Export_Name --
5794 ----------------------------------
5795
5796 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
5797 String_Val : constant String_Id := Strval (Nam);
5798
5799 begin
5800 -- We are only interested in the export case, and in the case of
5801 -- generics, it is the instance, not the template, that is the
5802 -- problem (the template will generate a warning in any case).
5803
5804 if not Inside_A_Generic
5805 and then (Prag_Id = Pragma_Export
5806 or else
5807 Prag_Id = Pragma_Export_Procedure
5808 or else
5809 Prag_Id = Pragma_Export_Valued_Procedure
5810 or else
5811 Prag_Id = Pragma_Export_Function)
5812 then
5813 for J in Externals.First .. Externals.Last loop
5814 if String_Equal (String_Val, Strval (Externals.Table (J))) then
5815 Error_Msg_Sloc := Sloc (Externals.Table (J));
5816 Error_Msg_N ("external name duplicates name given#", Nam);
5817 exit;
5818 end if;
5819 end loop;
5820
5821 Externals.Append (Nam);
5822 end if;
5823 end Check_Duplicated_Export_Name;
5824
5825 ----------------------------------------
5826 -- Check_Expr_Is_OK_Static_Expression --
5827 ----------------------------------------
5828
5829 procedure Check_Expr_Is_OK_Static_Expression
5830 (Expr : Node_Id;
5831 Typ : Entity_Id := Empty)
5832 is
5833 begin
5834 if Present (Typ) then
5835 Analyze_And_Resolve (Expr, Typ);
5836 else
5837 Analyze_And_Resolve (Expr);
5838 end if;
5839
5840 -- An expression cannot be considered static if its resolution failed
5841 -- or if it's erroneous. Stop the analysis of the related pragma.
5842
5843 if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
5844 raise Pragma_Exit;
5845
5846 elsif Is_OK_Static_Expression (Expr) then
5847 return;
5848
5849 -- An interesting special case, if we have a string literal and we
5850 -- are in Ada 83 mode, then we allow it even though it will not be
5851 -- flagged as static. This allows the use of Ada 95 pragmas like
5852 -- Import in Ada 83 mode. They will of course be flagged with
5853 -- warnings as usual, but will not cause errors.
5854
5855 elsif Ada_Version = Ada_83
5856 and then Nkind (Expr) = N_String_Literal
5857 then
5858 return;
5859
5860 -- Finally, we have a real error
5861
5862 else
5863 Error_Msg_Name_1 := Pname;
5864 Flag_Non_Static_Expr
5865 (Fix_Error ("argument for pragma% must be a static expression!"),
5866 Expr);
5867 raise Pragma_Exit;
5868 end if;
5869 end Check_Expr_Is_OK_Static_Expression;
5870
5871 -------------------------
5872 -- Check_First_Subtype --
5873 -------------------------
5874
5875 procedure Check_First_Subtype (Arg : Node_Id) is
5876 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5877 Ent : constant Entity_Id := Entity (Argx);
5878
5879 begin
5880 if Is_First_Subtype (Ent) then
5881 null;
5882
5883 elsif Is_Type (Ent) then
5884 Error_Pragma_Arg
5885 ("pragma% cannot apply to subtype", Argx);
5886
5887 elsif Is_Object (Ent) then
5888 Error_Pragma_Arg
5889 ("pragma% cannot apply to object, requires a type", Argx);
5890
5891 else
5892 Error_Pragma_Arg
5893 ("pragma% cannot apply to&, requires a type", Argx);
5894 end if;
5895 end Check_First_Subtype;
5896
5897 ----------------------
5898 -- Check_Identifier --
5899 ----------------------
5900
5901 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
5902 begin
5903 if Present (Arg)
5904 and then Nkind (Arg) = N_Pragma_Argument_Association
5905 then
5906 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
5907 Error_Msg_Name_1 := Pname;
5908 Error_Msg_Name_2 := Id;
5909 Error_Msg_N ("pragma% argument expects identifier%", Arg);
5910 raise Pragma_Exit;
5911 end if;
5912 end if;
5913 end Check_Identifier;
5914
5915 --------------------------------
5916 -- Check_Identifier_Is_One_Of --
5917 --------------------------------
5918
5919 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5920 begin
5921 if Present (Arg)
5922 and then Nkind (Arg) = N_Pragma_Argument_Association
5923 then
5924 if Chars (Arg) = No_Name then
5925 Error_Msg_Name_1 := Pname;
5926 Error_Msg_N ("pragma% argument expects an identifier", Arg);
5927 raise Pragma_Exit;
5928
5929 elsif Chars (Arg) /= N1
5930 and then Chars (Arg) /= N2
5931 then
5932 Error_Msg_Name_1 := Pname;
5933 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
5934 raise Pragma_Exit;
5935 end if;
5936 end if;
5937 end Check_Identifier_Is_One_Of;
5938
5939 ---------------------------
5940 -- Check_In_Main_Program --
5941 ---------------------------
5942
5943 procedure Check_In_Main_Program is
5944 P : constant Node_Id := Parent (N);
5945
5946 begin
5947 -- Must be in subprogram body
5948
5949 if Nkind (P) /= N_Subprogram_Body then
5950 Error_Pragma ("% pragma allowed only in subprogram");
5951
5952 -- Otherwise warn if obviously not main program
5953
5954 elsif Present (Parameter_Specifications (Specification (P)))
5955 or else not Is_Compilation_Unit (Defining_Entity (P))
5956 then
5957 Error_Msg_Name_1 := Pname;
5958 Error_Msg_N
5959 ("??pragma% is only effective in main program", N);
5960 end if;
5961 end Check_In_Main_Program;
5962
5963 ---------------------------------------
5964 -- Check_Interrupt_Or_Attach_Handler --
5965 ---------------------------------------
5966
5967 procedure Check_Interrupt_Or_Attach_Handler is
5968 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5969 Handler_Proc, Proc_Scope : Entity_Id;
5970
5971 begin
5972 Analyze (Arg1_X);
5973
5974 if Prag_Id = Pragma_Interrupt_Handler then
5975 Check_Restriction (No_Dynamic_Attachment, N);
5976 end if;
5977
5978 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
5979 Proc_Scope := Scope (Handler_Proc);
5980
5981 if Ekind (Proc_Scope) /= E_Protected_Type then
5982 Error_Pragma_Arg
5983 ("argument of pragma% must be protected procedure", Arg1);
5984 end if;
5985
5986 -- For pragma case (as opposed to access case), check placement.
5987 -- We don't need to do that for aspects, because we have the
5988 -- check that they aspect applies an appropriate procedure.
5989
5990 if not From_Aspect_Specification (N)
5991 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
5992 then
5993 Error_Pragma ("pragma% must be in protected definition");
5994 end if;
5995
5996 if not Is_Library_Level_Entity (Proc_Scope) then
5997 Error_Pragma_Arg
5998 ("argument for pragma% must be library level entity", Arg1);
5999 end if;
6000
6001 -- AI05-0033: A pragma cannot appear within a generic body, because
6002 -- instance can be in a nested scope. The check that protected type
6003 -- is itself a library-level declaration is done elsewhere.
6004
6005 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
6006 -- handle code prior to AI-0033. Analysis tools typically are not
6007 -- interested in this pragma in any case, so no need to worry too
6008 -- much about its placement.
6009
6010 if Inside_A_Generic then
6011 if Ekind (Scope (Current_Scope)) = E_Generic_Package
6012 and then In_Package_Body (Scope (Current_Scope))
6013 and then not Relaxed_RM_Semantics
6014 then
6015 Error_Pragma ("pragma% cannot be used inside a generic");
6016 end if;
6017 end if;
6018 end Check_Interrupt_Or_Attach_Handler;
6019
6020 ---------------------------------
6021 -- Check_Loop_Pragma_Placement --
6022 ---------------------------------
6023
6024 procedure Check_Loop_Pragma_Placement is
6025 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
6026 -- Verify whether the current pragma is properly grouped with other
6027 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
6028 -- related loop where the pragma appears.
6029
6030 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
6031 -- Determine whether an arbitrary statement Stmt denotes pragma
6032 -- Loop_Invariant or Loop_Variant.
6033
6034 procedure Placement_Error (Constr : Node_Id);
6035 pragma No_Return (Placement_Error);
6036 -- Node Constr denotes the last loop restricted construct before we
6037 -- encountered an illegal relation between enclosing constructs. Emit
6038 -- an error depending on what Constr was.
6039
6040 --------------------------------
6041 -- Check_Loop_Pragma_Grouping --
6042 --------------------------------
6043
6044 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
6045 Stop_Search : exception;
6046 -- This exception is used to terminate the recursive descent of
6047 -- routine Check_Grouping.
6048
6049 procedure Check_Grouping (L : List_Id);
6050 -- Find the first group of pragmas in list L and if successful,
6051 -- ensure that the current pragma is part of that group. The
6052 -- routine raises Stop_Search once such a check is performed to
6053 -- halt the recursive descent.
6054
6055 procedure Grouping_Error (Prag : Node_Id);
6056 pragma No_Return (Grouping_Error);
6057 -- Emit an error concerning the current pragma indicating that it
6058 -- should be placed after pragma Prag.
6059
6060 --------------------
6061 -- Check_Grouping --
6062 --------------------
6063
6064 procedure Check_Grouping (L : List_Id) is
6065 HSS : Node_Id;
6066 Stmt : Node_Id;
6067 Prag : Node_Id := Empty; -- init to avoid warning
6068
6069 begin
6070 -- Inspect the list of declarations or statements looking for
6071 -- the first grouping of pragmas:
6072
6073 -- loop
6074 -- pragma Loop_Invariant ...;
6075 -- pragma Loop_Variant ...;
6076 -- . . . -- (1)
6077 -- pragma Loop_Variant ...; -- current pragma
6078
6079 -- If the current pragma is not in the grouping, then it must
6080 -- either appear in a different declarative or statement list
6081 -- or the construct at (1) is separating the pragma from the
6082 -- grouping.
6083
6084 Stmt := First (L);
6085 while Present (Stmt) loop
6086
6087 -- First pragma of the first topmost grouping has been found
6088
6089 if Is_Loop_Pragma (Stmt) then
6090
6091 -- The group and the current pragma are not in the same
6092 -- declarative or statement list.
6093
6094 if not In_Same_List (Stmt, N) then
6095 Grouping_Error (Stmt);
6096
6097 -- Try to reach the current pragma from the first pragma
6098 -- of the grouping while skipping other members:
6099
6100 -- pragma Loop_Invariant ...; -- first pragma
6101 -- pragma Loop_Variant ...; -- member
6102 -- . . .
6103 -- pragma Loop_Variant ...; -- current pragma
6104
6105 else
6106 while Present (Stmt) loop
6107 -- The current pragma is either the first pragma
6108 -- of the group or is a member of the group.
6109 -- Stop the search as the placement is legal.
6110
6111 if Stmt = N then
6112 raise Stop_Search;
6113
6114 -- Skip group members, but keep track of the
6115 -- last pragma in the group.
6116
6117 elsif Is_Loop_Pragma (Stmt) then
6118 Prag := Stmt;
6119
6120 -- Skip declarations and statements generated by
6121 -- the compiler during expansion. Note that some
6122 -- source statements (e.g. pragma Assert) may have
6123 -- been transformed so that they do not appear as
6124 -- coming from source anymore, so we instead look
6125 -- at their Original_Node.
6126
6127 elsif not Comes_From_Source (Original_Node (Stmt))
6128 then
6129 null;
6130
6131 -- A non-pragma is separating the group from the
6132 -- current pragma, the placement is illegal.
6133
6134 else
6135 Grouping_Error (Prag);
6136 end if;
6137
6138 Next (Stmt);
6139 end loop;
6140
6141 -- If the traversal did not reach the current pragma,
6142 -- then the list must be malformed.
6143
6144 raise Program_Error;
6145 end if;
6146
6147 -- Pragmas Loop_Invariant and Loop_Variant may only appear
6148 -- inside a loop or a block housed inside a loop. Inspect
6149 -- the declarations and statements of the block as they may
6150 -- contain the first grouping. This case follows the one for
6151 -- loop pragmas, as block statements which originate in a
6152 -- loop pragma (and so Is_Loop_Pragma will return True on
6153 -- that block statement) should be treated in the previous
6154 -- case.
6155
6156 elsif Nkind (Stmt) = N_Block_Statement then
6157 HSS := Handled_Statement_Sequence (Stmt);
6158
6159 Check_Grouping (Declarations (Stmt));
6160
6161 if Present (HSS) then
6162 Check_Grouping (Statements (HSS));
6163 end if;
6164 end if;
6165
6166 Next (Stmt);
6167 end loop;
6168 end Check_Grouping;
6169
6170 --------------------
6171 -- Grouping_Error --
6172 --------------------
6173
6174 procedure Grouping_Error (Prag : Node_Id) is
6175 begin
6176 Error_Msg_Sloc := Sloc (Prag);
6177 Error_Pragma ("pragma% must appear next to pragma#");
6178 end Grouping_Error;
6179
6180 -- Start of processing for Check_Loop_Pragma_Grouping
6181
6182 begin
6183 -- Inspect the statements of the loop or nested blocks housed
6184 -- within to determine whether the current pragma is part of the
6185 -- first topmost grouping of Loop_Invariant and Loop_Variant.
6186
6187 Check_Grouping (Statements (Loop_Stmt));
6188
6189 exception
6190 when Stop_Search => null;
6191 end Check_Loop_Pragma_Grouping;
6192
6193 --------------------
6194 -- Is_Loop_Pragma --
6195 --------------------
6196
6197 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
6198 Original_Stmt : constant Node_Id := Original_Node (Stmt);
6199
6200 begin
6201 -- Inspect the original node as Loop_Invariant and Loop_Variant
6202 -- pragmas are rewritten to null when assertions are disabled.
6203
6204 return Nkind (Original_Stmt) = N_Pragma
6205 and then Pragma_Name_Unmapped (Original_Stmt)
6206 in Name_Loop_Invariant | Name_Loop_Variant;
6207 end Is_Loop_Pragma;
6208
6209 ---------------------
6210 -- Placement_Error --
6211 ---------------------
6212
6213 procedure Placement_Error (Constr : Node_Id) is
6214 LA : constant String := " with Loop_Entry";
6215
6216 begin
6217 if Prag_Id = Pragma_Assert then
6218 Error_Msg_String (1 .. LA'Length) := LA;
6219 Error_Msg_Strlen := LA'Length;
6220 else
6221 Error_Msg_Strlen := 0;
6222 end if;
6223
6224 if Nkind (Constr) = N_Pragma then
6225 Error_Pragma
6226 ("pragma %~ must appear immediately within the statements "
6227 & "of a loop");
6228 else
6229 Error_Pragma_Arg
6230 ("block containing pragma %~ must appear immediately within "
6231 & "the statements of a loop", Constr);
6232 end if;
6233 end Placement_Error;
6234
6235 -- Local declarations
6236
6237 Prev : Node_Id;
6238 Stmt : Node_Id;
6239
6240 -- Start of processing for Check_Loop_Pragma_Placement
6241
6242 begin
6243 -- Check that pragma appears immediately within a loop statement,
6244 -- ignoring intervening block statements.
6245
6246 Prev := N;
6247 Stmt := Parent (N);
6248 while Present (Stmt) loop
6249
6250 -- The pragma or previous block must appear immediately within the
6251 -- current block's declarative or statement part.
6252
6253 if Nkind (Stmt) = N_Block_Statement then
6254 if (No (Declarations (Stmt))
6255 or else List_Containing (Prev) /= Declarations (Stmt))
6256 and then
6257 List_Containing (Prev) /=
6258 Statements (Handled_Statement_Sequence (Stmt))
6259 then
6260 Placement_Error (Prev);
6261 return;
6262
6263 -- Keep inspecting the parents because we are now within a
6264 -- chain of nested blocks.
6265
6266 else
6267 Prev := Stmt;
6268 Stmt := Parent (Stmt);
6269 end if;
6270
6271 -- The pragma or previous block must appear immediately within the
6272 -- statements of the loop.
6273
6274 elsif Nkind (Stmt) = N_Loop_Statement then
6275 if List_Containing (Prev) /= Statements (Stmt) then
6276 Placement_Error (Prev);
6277 end if;
6278
6279 -- Stop the traversal because we reached the innermost loop
6280 -- regardless of whether we encountered an error or not.
6281
6282 exit;
6283
6284 -- Ignore a handled statement sequence. Note that this node may
6285 -- be related to a subprogram body in which case we will emit an
6286 -- error on the next iteration of the search.
6287
6288 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
6289 Stmt := Parent (Stmt);
6290
6291 -- Any other statement breaks the chain from the pragma to the
6292 -- loop.
6293
6294 else
6295 Placement_Error (Prev);
6296 return;
6297 end if;
6298 end loop;
6299
6300 -- Check that the current pragma Loop_Invariant or Loop_Variant is
6301 -- grouped together with other such pragmas.
6302
6303 if Is_Loop_Pragma (N) then
6304
6305 -- The previous check should have located the related loop
6306
6307 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
6308 Check_Loop_Pragma_Grouping (Stmt);
6309 end if;
6310 end Check_Loop_Pragma_Placement;
6311
6312 -------------------------------------------
6313 -- Check_Is_In_Decl_Part_Or_Package_Spec --
6314 -------------------------------------------
6315
6316 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
6317 P : Node_Id;
6318
6319 begin
6320 P := Parent (N);
6321 loop
6322 if No (P) then
6323 exit;
6324
6325 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
6326 exit;
6327
6328 elsif Nkind (P) in N_Package_Specification | N_Block_Statement then
6329 return;
6330
6331 -- Note: the following tests seem a little peculiar, because
6332 -- they test for bodies, but if we were in the statement part
6333 -- of the body, we would already have hit the handled statement
6334 -- sequence, so the only way we get here is by being in the
6335 -- declarative part of the body.
6336
6337 elsif Nkind (P) in
6338 N_Subprogram_Body | N_Package_Body | N_Task_Body | N_Entry_Body
6339 then
6340 return;
6341 end if;
6342
6343 P := Parent (P);
6344 end loop;
6345
6346 Error_Pragma ("pragma% is not in declarative part or package spec");
6347 end Check_Is_In_Decl_Part_Or_Package_Spec;
6348
6349 -------------------------
6350 -- Check_No_Identifier --
6351 -------------------------
6352
6353 procedure Check_No_Identifier (Arg : Node_Id) is
6354 begin
6355 if Nkind (Arg) = N_Pragma_Argument_Association
6356 and then Chars (Arg) /= No_Name
6357 then
6358 Error_Pragma_Arg_Ident
6359 ("pragma% does not permit identifier& here", Arg);
6360 end if;
6361 end Check_No_Identifier;
6362
6363 --------------------------
6364 -- Check_No_Identifiers --
6365 --------------------------
6366
6367 procedure Check_No_Identifiers is
6368 Arg_Node : Node_Id;
6369 begin
6370 Arg_Node := Arg1;
6371 for J in 1 .. Arg_Count loop
6372 Check_No_Identifier (Arg_Node);
6373 Next (Arg_Node);
6374 end loop;
6375 end Check_No_Identifiers;
6376
6377 ------------------------
6378 -- Check_No_Link_Name --
6379 ------------------------
6380
6381 procedure Check_No_Link_Name is
6382 begin
6383 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
6384 Arg4 := Arg3;
6385 end if;
6386
6387 if Present (Arg4) then
6388 Error_Pragma_Arg
6389 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
6390 end if;
6391 end Check_No_Link_Name;
6392
6393 -------------------------------
6394 -- Check_Optional_Identifier --
6395 -------------------------------
6396
6397 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
6398 begin
6399 if Present (Arg)
6400 and then Nkind (Arg) = N_Pragma_Argument_Association
6401 and then Chars (Arg) /= No_Name
6402 then
6403 if Chars (Arg) /= Id then
6404 Error_Msg_Name_1 := Pname;
6405 Error_Msg_Name_2 := Id;
6406 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6407 raise Pragma_Exit;
6408 end if;
6409 end if;
6410 end Check_Optional_Identifier;
6411
6412 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
6413 begin
6414 Check_Optional_Identifier (Arg, Name_Find (Id));
6415 end Check_Optional_Identifier;
6416
6417 -------------------------------------
6418 -- Check_Static_Boolean_Expression --
6419 -------------------------------------
6420
6421 procedure Check_Static_Boolean_Expression (Expr : Node_Id) is
6422 begin
6423 if Present (Expr) then
6424 Analyze_And_Resolve (Expr, Standard_Boolean);
6425
6426 if not Is_OK_Static_Expression (Expr) then
6427 Error_Pragma_Arg
6428 ("expression of pragma % must be static", Expr);
6429 end if;
6430 end if;
6431 end Check_Static_Boolean_Expression;
6432
6433 -----------------------------
6434 -- Check_Static_Constraint --
6435 -----------------------------
6436
6437 -- Note: for convenience in writing this procedure, in addition to
6438 -- the officially (i.e. by spec) allowed argument which is always a
6439 -- constraint, it also allows ranges and discriminant associations.
6440 -- Above is not clear ???
6441
6442 procedure Check_Static_Constraint (Constr : Node_Id) is
6443
6444 procedure Require_Static (E : Node_Id);
6445 -- Require given expression to be static expression
6446
6447 --------------------
6448 -- Require_Static --
6449 --------------------
6450
6451 procedure Require_Static (E : Node_Id) is
6452 begin
6453 if not Is_OK_Static_Expression (E) then
6454 Flag_Non_Static_Expr
6455 ("non-static constraint not allowed in Unchecked_Union!", E);
6456 raise Pragma_Exit;
6457 end if;
6458 end Require_Static;
6459
6460 -- Start of processing for Check_Static_Constraint
6461
6462 begin
6463 case Nkind (Constr) is
6464 when N_Discriminant_Association =>
6465 Require_Static (Expression (Constr));
6466
6467 when N_Range =>
6468 Require_Static (Low_Bound (Constr));
6469 Require_Static (High_Bound (Constr));
6470
6471 when N_Attribute_Reference =>
6472 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
6473 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
6474
6475 when N_Range_Constraint =>
6476 Check_Static_Constraint (Range_Expression (Constr));
6477
6478 when N_Index_Or_Discriminant_Constraint =>
6479 declare
6480 IDC : Entity_Id;
6481 begin
6482 IDC := First (Constraints (Constr));
6483 while Present (IDC) loop
6484 Check_Static_Constraint (IDC);
6485 Next (IDC);
6486 end loop;
6487 end;
6488
6489 when others =>
6490 null;
6491 end case;
6492 end Check_Static_Constraint;
6493
6494 --------------------------------------
6495 -- Check_Valid_Configuration_Pragma --
6496 --------------------------------------
6497
6498 -- A configuration pragma must appear in the context clause of a
6499 -- compilation unit, and only other pragmas may precede it. Note that
6500 -- the test also allows use in a configuration pragma file.
6501
6502 procedure Check_Valid_Configuration_Pragma is
6503 begin
6504 if not Is_Configuration_Pragma then
6505 Error_Pragma ("incorrect placement for configuration pragma%");
6506 end if;
6507 end Check_Valid_Configuration_Pragma;
6508
6509 -------------------------------------
6510 -- Check_Valid_Library_Unit_Pragma --
6511 -------------------------------------
6512
6513 procedure Check_Valid_Library_Unit_Pragma is
6514 Plist : List_Id;
6515 Parent_Node : Node_Id;
6516 Unit_Name : Entity_Id;
6517 Unit_Kind : Node_Kind;
6518 Unit_Node : Node_Id;
6519 Sindex : Source_File_Index;
6520
6521 begin
6522 if not Is_List_Member (N) then
6523 Pragma_Misplaced;
6524
6525 else
6526 Plist := List_Containing (N);
6527 Parent_Node := Parent (Plist);
6528
6529 if Parent_Node = Empty then
6530 Pragma_Misplaced;
6531
6532 -- Case of pragma appearing after a compilation unit. In this case
6533 -- it must have an argument with the corresponding name and must
6534 -- be part of the following pragmas of its parent.
6535
6536 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
6537 if Plist /= Pragmas_After (Parent_Node) then
6538 Pragma_Misplaced;
6539
6540 elsif Arg_Count = 0 then
6541 Error_Pragma
6542 ("argument required if outside compilation unit");
6543
6544 else
6545 Check_No_Identifiers;
6546 Check_Arg_Count (1);
6547 Unit_Node := Unit (Parent (Parent_Node));
6548 Unit_Kind := Nkind (Unit_Node);
6549
6550 Analyze (Get_Pragma_Arg (Arg1));
6551
6552 if Unit_Kind = N_Generic_Subprogram_Declaration
6553 or else Unit_Kind = N_Subprogram_Declaration
6554 then
6555 Unit_Name := Defining_Entity (Unit_Node);
6556
6557 elsif Unit_Kind in N_Generic_Instantiation then
6558 Unit_Name := Defining_Entity (Unit_Node);
6559
6560 else
6561 Unit_Name := Cunit_Entity (Current_Sem_Unit);
6562 end if;
6563
6564 if Chars (Unit_Name) /=
6565 Chars (Entity (Get_Pragma_Arg (Arg1)))
6566 then
6567 Error_Pragma_Arg
6568 ("pragma% argument is not current unit name", Arg1);
6569 end if;
6570
6571 if Ekind (Unit_Name) = E_Package
6572 and then Present (Renamed_Entity (Unit_Name))
6573 then
6574 Error_Pragma ("pragma% not allowed for renamed package");
6575 end if;
6576 end if;
6577
6578 -- Pragma appears other than after a compilation unit
6579
6580 else
6581 -- Here we check for the generic instantiation case and also
6582 -- for the case of processing a generic formal package. We
6583 -- detect these cases by noting that the Sloc on the node
6584 -- does not belong to the current compilation unit.
6585
6586 Sindex := Source_Index (Current_Sem_Unit);
6587
6588 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
6589 Rewrite (N, Make_Null_Statement (Loc));
6590 raise Pragma_Exit;
6591
6592 -- If before first declaration, the pragma applies to the
6593 -- enclosing unit, and the name if present must be this name.
6594
6595 elsif Is_Before_First_Decl (N, Plist) then
6596 Unit_Node := Unit_Declaration_Node (Current_Scope);
6597 Unit_Kind := Nkind (Unit_Node);
6598
6599 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
6600 Pragma_Misplaced;
6601
6602 elsif Unit_Kind = N_Subprogram_Body
6603 and then not Acts_As_Spec (Unit_Node)
6604 then
6605 Pragma_Misplaced;
6606
6607 elsif Nkind (Parent_Node) = N_Package_Body then
6608 Pragma_Misplaced;
6609
6610 elsif Nkind (Parent_Node) = N_Package_Specification
6611 and then Plist = Private_Declarations (Parent_Node)
6612 then
6613 Pragma_Misplaced;
6614
6615 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
6616 or else Nkind (Parent_Node) =
6617 N_Generic_Subprogram_Declaration)
6618 and then Plist = Generic_Formal_Declarations (Parent_Node)
6619 then
6620 Pragma_Misplaced;
6621
6622 elsif Arg_Count > 0 then
6623 Analyze (Get_Pragma_Arg (Arg1));
6624
6625 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
6626 Error_Pragma_Arg
6627 ("name in pragma% must be enclosing unit", Arg1);
6628 end if;
6629
6630 -- It is legal to have no argument in this context
6631
6632 else
6633 return;
6634 end if;
6635
6636 -- Error if not before first declaration. This is because a
6637 -- library unit pragma argument must be the name of a library
6638 -- unit (RM 10.1.5(7)), but the only names permitted in this
6639 -- context are (RM 10.1.5(6)) names of subprogram declarations,
6640 -- generic subprogram declarations or generic instantiations.
6641
6642 else
6643 Error_Pragma
6644 ("pragma% misplaced, must be before first declaration");
6645 end if;
6646 end if;
6647 end if;
6648 end Check_Valid_Library_Unit_Pragma;
6649
6650 -------------------
6651 -- Check_Variant --
6652 -------------------
6653
6654 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
6655 Clist : constant Node_Id := Component_List (Variant);
6656 Comp : Node_Id;
6657
6658 begin
6659 Comp := First_Non_Pragma (Component_Items (Clist));
6660 while Present (Comp) loop
6661 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
6662 Next_Non_Pragma (Comp);
6663 end loop;
6664 end Check_Variant;
6665
6666 ---------------------------
6667 -- Ensure_Aggregate_Form --
6668 ---------------------------
6669
6670 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
6671 CFSD : constant Boolean := Get_Comes_From_Source_Default;
6672 Expr : constant Node_Id := Expression (Arg);
6673 Loc : constant Source_Ptr := Sloc (Expr);
6674 Comps : List_Id := No_List;
6675 Exprs : List_Id := No_List;
6676 Nam : Name_Id := No_Name;
6677 Nam_Loc : Source_Ptr;
6678
6679 begin
6680 -- The pragma argument is in positional form:
6681
6682 -- pragma Depends (Nam => ...)
6683 -- ^
6684 -- Chars field
6685
6686 -- Note that the Sloc of the Chars field is the Sloc of the pragma
6687 -- argument association.
6688
6689 if Nkind (Arg) = N_Pragma_Argument_Association then
6690 Nam := Chars (Arg);
6691 Nam_Loc := Sloc (Arg);
6692
6693 -- Remove the pragma argument name as this will be captured in the
6694 -- aggregate.
6695
6696 Set_Chars (Arg, No_Name);
6697 end if;
6698
6699 -- The argument is already in aggregate form, but the presence of a
6700 -- name causes this to be interpreted as named association which in
6701 -- turn must be converted into an aggregate.
6702
6703 -- pragma Global (In_Out => (A, B, C))
6704 -- ^ ^
6705 -- name aggregate
6706
6707 -- pragma Global ((In_Out => (A, B, C)))
6708 -- ^ ^
6709 -- aggregate aggregate
6710
6711 if Nkind (Expr) = N_Aggregate then
6712 if Nam = No_Name then
6713 return;
6714 end if;
6715
6716 -- Do not transform a null argument into an aggregate as N_Null has
6717 -- special meaning in formal verification pragmas.
6718
6719 elsif Nkind (Expr) = N_Null then
6720 return;
6721 end if;
6722
6723 -- Everything comes from source if the original comes from source
6724
6725 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
6726
6727 -- Positional argument is transformed into an aggregate with an
6728 -- Expressions list.
6729
6730 if Nam = No_Name then
6731 Exprs := New_List (Relocate_Node (Expr));
6732
6733 -- An associative argument is transformed into an aggregate with
6734 -- Component_Associations.
6735
6736 else
6737 Comps := New_List (
6738 Make_Component_Association (Loc,
6739 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
6740 Expression => Relocate_Node (Expr)));
6741 end if;
6742
6743 Set_Expression (Arg,
6744 Make_Aggregate (Loc,
6745 Component_Associations => Comps,
6746 Expressions => Exprs));
6747
6748 -- Restore Comes_From_Source default
6749
6750 Set_Comes_From_Source_Default (CFSD);
6751 end Ensure_Aggregate_Form;
6752
6753 ------------------
6754 -- Error_Pragma --
6755 ------------------
6756
6757 procedure Error_Pragma (Msg : String) is
6758 begin
6759 Error_Msg_Name_1 := Pname;
6760 Error_Msg_N (Fix_Error (Msg), N);
6761 raise Pragma_Exit;
6762 end Error_Pragma;
6763
6764 ----------------------
6765 -- Error_Pragma_Arg --
6766 ----------------------
6767
6768 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
6769 begin
6770 Error_Msg_Name_1 := Pname;
6771 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
6772 raise Pragma_Exit;
6773 end Error_Pragma_Arg;
6774
6775 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
6776 begin
6777 Error_Msg_Name_1 := Pname;
6778 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
6779 Error_Pragma_Arg (Msg2, Arg);
6780 end Error_Pragma_Arg;
6781
6782 ----------------------------
6783 -- Error_Pragma_Arg_Ident --
6784 ----------------------------
6785
6786 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
6787 begin
6788 Error_Msg_Name_1 := Pname;
6789 Error_Msg_N (Fix_Error (Msg), Arg);
6790 raise Pragma_Exit;
6791 end Error_Pragma_Arg_Ident;
6792
6793 ----------------------
6794 -- Error_Pragma_Ref --
6795 ----------------------
6796
6797 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
6798 begin
6799 Error_Msg_Name_1 := Pname;
6800 Error_Msg_Sloc := Sloc (Ref);
6801 Error_Msg_NE (Fix_Error (Msg), N, Ref);
6802 raise Pragma_Exit;
6803 end Error_Pragma_Ref;
6804
6805 ------------------------
6806 -- Find_Lib_Unit_Name --
6807 ------------------------
6808
6809 function Find_Lib_Unit_Name return Entity_Id is
6810 begin
6811 -- Return inner compilation unit entity, for case of nested
6812 -- categorization pragmas. This happens in generic unit.
6813
6814 if Nkind (Parent (N)) = N_Package_Specification
6815 and then Defining_Entity (Parent (N)) /= Current_Scope
6816 then
6817 return Defining_Entity (Parent (N));
6818 else
6819 return Current_Scope;
6820 end if;
6821 end Find_Lib_Unit_Name;
6822
6823 ----------------------------
6824 -- Find_Program_Unit_Name --
6825 ----------------------------
6826
6827 procedure Find_Program_Unit_Name (Id : Node_Id) is
6828 Unit_Name : Entity_Id;
6829 Unit_Kind : Node_Kind;
6830 P : constant Node_Id := Parent (N);
6831
6832 begin
6833 if Nkind (P) = N_Compilation_Unit then
6834 Unit_Kind := Nkind (Unit (P));
6835
6836 if Unit_Kind in N_Subprogram_Declaration
6837 | N_Package_Declaration
6838 | N_Generic_Declaration
6839 then
6840 Unit_Name := Defining_Entity (Unit (P));
6841
6842 if Chars (Id) = Chars (Unit_Name) then
6843 Set_Entity (Id, Unit_Name);
6844 Set_Etype (Id, Etype (Unit_Name));
6845 else
6846 Set_Etype (Id, Any_Type);
6847 Error_Pragma
6848 ("cannot find program unit referenced by pragma%");
6849 end if;
6850
6851 else
6852 Set_Etype (Id, Any_Type);
6853 Error_Pragma ("pragma% inapplicable to this unit");
6854 end if;
6855
6856 else
6857 Analyze (Id);
6858 end if;
6859 end Find_Program_Unit_Name;
6860
6861 -----------------------------------------
6862 -- Find_Unique_Parameterless_Procedure --
6863 -----------------------------------------
6864
6865 function Find_Unique_Parameterless_Procedure
6866 (Name : Entity_Id;
6867 Arg : Node_Id) return Entity_Id
6868 is
6869 Proc : Entity_Id := Empty;
6870
6871 begin
6872 -- The body of this procedure needs some comments ???
6873
6874 if not Is_Entity_Name (Name) then
6875 Error_Pragma_Arg
6876 ("argument of pragma% must be entity name", Arg);
6877
6878 elsif not Is_Overloaded (Name) then
6879 Proc := Entity (Name);
6880
6881 if Ekind (Proc) /= E_Procedure
6882 or else Present (First_Formal (Proc))
6883 then
6884 Error_Pragma_Arg
6885 ("argument of pragma% must be parameterless procedure", Arg);
6886 end if;
6887
6888 else
6889 declare
6890 Found : Boolean := False;
6891 It : Interp;
6892 Index : Interp_Index;
6893
6894 begin
6895 Get_First_Interp (Name, Index, It);
6896 while Present (It.Nam) loop
6897 Proc := It.Nam;
6898
6899 if Ekind (Proc) = E_Procedure
6900 and then No (First_Formal (Proc))
6901 then
6902 if not Found then
6903 Found := True;
6904 Set_Entity (Name, Proc);
6905 Set_Is_Overloaded (Name, False);
6906 else
6907 Error_Pragma_Arg
6908 ("ambiguous handler name for pragma% ", Arg);
6909 end if;
6910 end if;
6911
6912 Get_Next_Interp (Index, It);
6913 end loop;
6914
6915 if not Found then
6916 Error_Pragma_Arg
6917 ("argument of pragma% must be parameterless procedure",
6918 Arg);
6919 else
6920 Proc := Entity (Name);
6921 end if;
6922 end;
6923 end if;
6924
6925 return Proc;
6926 end Find_Unique_Parameterless_Procedure;
6927
6928 ---------------
6929 -- Fix_Error --
6930 ---------------
6931
6932 function Fix_Error (Msg : String) return String is
6933 Res : String (Msg'Range) := Msg;
6934 Res_Last : Natural := Msg'Last;
6935 J : Natural;
6936
6937 begin
6938 -- If we have a rewriting of another pragma, go to that pragma
6939
6940 if Is_Rewrite_Substitution (N)
6941 and then Nkind (Original_Node (N)) = N_Pragma
6942 then
6943 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
6944 end if;
6945
6946 -- Case where pragma comes from an aspect specification
6947
6948 if From_Aspect_Specification (N) then
6949
6950 -- Change appearence of "pragma" in message to "aspect"
6951
6952 J := Res'First;
6953 while J <= Res_Last - 5 loop
6954 if Res (J .. J + 5) = "pragma" then
6955 Res (J .. J + 5) := "aspect";
6956 J := J + 6;
6957
6958 else
6959 J := J + 1;
6960 end if;
6961 end loop;
6962
6963 -- Change "argument of" at start of message to "entity for"
6964
6965 if Res'Length > 11
6966 and then Res (Res'First .. Res'First + 10) = "argument of"
6967 then
6968 Res (Res'First .. Res'First + 9) := "entity for";
6969 Res (Res'First + 10 .. Res_Last - 1) :=
6970 Res (Res'First + 11 .. Res_Last);
6971 Res_Last := Res_Last - 1;
6972 end if;
6973
6974 -- Change "argument" at start of message to "entity"
6975
6976 if Res'Length > 8
6977 and then Res (Res'First .. Res'First + 7) = "argument"
6978 then
6979 Res (Res'First .. Res'First + 5) := "entity";
6980 Res (Res'First + 6 .. Res_Last - 2) :=
6981 Res (Res'First + 8 .. Res_Last);
6982 Res_Last := Res_Last - 2;
6983 end if;
6984
6985 -- Get name from corresponding aspect
6986
6987 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
6988 end if;
6989
6990 -- Return possibly modified message
6991
6992 return Res (Res'First .. Res_Last);
6993 end Fix_Error;
6994
6995 -------------------------
6996 -- Gather_Associations --
6997 -------------------------
6998
6999 procedure Gather_Associations
7000 (Names : Name_List;
7001 Args : out Args_List)
7002 is
7003 Arg : Node_Id;
7004
7005 begin
7006 -- Initialize all parameters to Empty
7007
7008 for J in Args'Range loop
7009 Args (J) := Empty;
7010 end loop;
7011
7012 -- That's all we have to do if there are no argument associations
7013
7014 if No (Pragma_Argument_Associations (N)) then
7015 return;
7016 end if;
7017
7018 -- Otherwise first deal with any positional parameters present
7019
7020 Arg := First (Pragma_Argument_Associations (N));
7021 for Index in Args'Range loop
7022 exit when No (Arg) or else Chars (Arg) /= No_Name;
7023 Args (Index) := Get_Pragma_Arg (Arg);
7024 Next (Arg);
7025 end loop;
7026
7027 -- Positional parameters all processed, if any left, then we
7028 -- have too many positional parameters.
7029
7030 if Present (Arg) and then Chars (Arg) = No_Name then
7031 Error_Pragma_Arg
7032 ("too many positional associations for pragma%", Arg);
7033 end if;
7034
7035 -- Process named parameters if any are present
7036
7037 while Present (Arg) loop
7038 if Chars (Arg) = No_Name then
7039 Error_Pragma_Arg
7040 ("positional association cannot follow named association",
7041 Arg);
7042
7043 else
7044 for Index in Names'Range loop
7045 if Names (Index) = Chars (Arg) then
7046 if Present (Args (Index)) then
7047 Error_Pragma_Arg
7048 ("duplicate argument association for pragma%", Arg);
7049 else
7050 Args (Index) := Get_Pragma_Arg (Arg);
7051 exit;
7052 end if;
7053 end if;
7054
7055 if Index = Names'Last then
7056 Error_Msg_Name_1 := Pname;
7057 Error_Msg_N ("pragma% does not allow & argument", Arg);
7058
7059 -- Check for possible misspelling
7060
7061 for Index1 in Names'Range loop
7062 if Is_Bad_Spelling_Of
7063 (Chars (Arg), Names (Index1))
7064 then
7065 Error_Msg_Name_1 := Names (Index1);
7066 Error_Msg_N -- CODEFIX
7067 ("\possible misspelling of%", Arg);
7068 exit;
7069 end if;
7070 end loop;
7071
7072 raise Pragma_Exit;
7073 end if;
7074 end loop;
7075 end if;
7076
7077 Next (Arg);
7078 end loop;
7079 end Gather_Associations;
7080
7081 -----------------
7082 -- GNAT_Pragma --
7083 -----------------
7084
7085 procedure GNAT_Pragma is
7086 begin
7087 -- We need to check the No_Implementation_Pragmas restriction for
7088 -- the case of a pragma from source. Note that the case of aspects
7089 -- generating corresponding pragmas marks these pragmas as not being
7090 -- from source, so this test also catches that case.
7091
7092 if Comes_From_Source (N) then
7093 Check_Restriction (No_Implementation_Pragmas, N);
7094 end if;
7095 end GNAT_Pragma;
7096
7097 --------------------------
7098 -- Is_Before_First_Decl --
7099 --------------------------
7100
7101 function Is_Before_First_Decl
7102 (Pragma_Node : Node_Id;
7103 Decls : List_Id) return Boolean
7104 is
7105 Item : Node_Id := First (Decls);
7106
7107 begin
7108 -- Only other pragmas can come before this pragma, but they might
7109 -- have been rewritten so check the original node.
7110
7111 loop
7112 if No (Item) or else Nkind (Original_Node (Item)) /= N_Pragma then
7113 return False;
7114
7115 elsif Item = Pragma_Node then
7116 return True;
7117 end if;
7118
7119 Next (Item);
7120 end loop;
7121 end Is_Before_First_Decl;
7122
7123 -----------------------------
7124 -- Is_Configuration_Pragma --
7125 -----------------------------
7126
7127 -- A configuration pragma must appear in the context clause of a
7128 -- compilation unit, and only other pragmas may precede it. Note that
7129 -- the test below also permits use in a configuration pragma file.
7130
7131 function Is_Configuration_Pragma return Boolean is
7132 Lis : constant List_Id := List_Containing (N);
7133 Par : constant Node_Id := Parent (N);
7134 Prg : Node_Id;
7135
7136 begin
7137 -- If no parent, then we are in the configuration pragma file,
7138 -- so the placement is definitely appropriate.
7139
7140 if No (Par) then
7141 return True;
7142
7143 -- Otherwise we must be in the context clause of a compilation unit
7144 -- and the only thing allowed before us in the context list is more
7145 -- configuration pragmas.
7146
7147 elsif Nkind (Par) = N_Compilation_Unit
7148 and then Context_Items (Par) = Lis
7149 then
7150 Prg := First (Lis);
7151
7152 loop
7153 if Prg = N then
7154 return True;
7155 elsif Nkind (Prg) /= N_Pragma then
7156 return False;
7157 end if;
7158
7159 Next (Prg);
7160 end loop;
7161
7162 else
7163 return False;
7164 end if;
7165 end Is_Configuration_Pragma;
7166
7167 --------------------------
7168 -- Is_In_Context_Clause --
7169 --------------------------
7170
7171 function Is_In_Context_Clause return Boolean is
7172 Plist : List_Id;
7173 Parent_Node : Node_Id;
7174
7175 begin
7176 if not Is_List_Member (N) then
7177 return False;
7178
7179 else
7180 Plist := List_Containing (N);
7181 Parent_Node := Parent (Plist);
7182
7183 if Parent_Node = Empty
7184 or else Nkind (Parent_Node) /= N_Compilation_Unit
7185 or else Context_Items (Parent_Node) /= Plist
7186 then
7187 return False;
7188 end if;
7189 end if;
7190
7191 return True;
7192 end Is_In_Context_Clause;
7193
7194 ---------------------------------
7195 -- Is_Static_String_Expression --
7196 ---------------------------------
7197
7198 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
7199 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
7200 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
7201
7202 begin
7203 Analyze_And_Resolve (Argx);
7204
7205 -- Special case Ada 83, where the expression will never be static,
7206 -- but we will return true if we had a string literal to start with.
7207
7208 if Ada_Version = Ada_83 then
7209 return Lit;
7210
7211 -- Normal case, true only if we end up with a string literal that
7212 -- is marked as being the result of evaluating a static expression.
7213
7214 else
7215 return Is_OK_Static_Expression (Argx)
7216 and then Nkind (Argx) = N_String_Literal;
7217 end if;
7218
7219 end Is_Static_String_Expression;
7220
7221 ----------------------
7222 -- Pragma_Misplaced --
7223 ----------------------
7224
7225 procedure Pragma_Misplaced is
7226 begin
7227 Error_Pragma ("incorrect placement of pragma%");
7228 end Pragma_Misplaced;
7229
7230 ------------------------------------------------
7231 -- Process_Atomic_Independent_Shared_Volatile --
7232 ------------------------------------------------
7233
7234 procedure Process_Atomic_Independent_Shared_Volatile is
7235 procedure Check_Full_Access_Only (Ent : Entity_Id);
7236 -- Apply legality checks to type or object Ent subject to the
7237 -- Full_Access_Only aspect in Ada 2020 (RM C.6(8.2)).
7238
7239 procedure Mark_Component_Or_Object (Ent : Entity_Id);
7240 -- Appropriately set flags on the given entity, either an array or
7241 -- record component, or an object declaration) according to the
7242 -- current pragma.
7243
7244 procedure Mark_Type (Ent : Entity_Id);
7245 -- Appropriately set flags on the given entity, a type
7246
7247 procedure Set_Atomic_VFA (Ent : Entity_Id);
7248 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
7249 -- no explicit alignment was given, set alignment to unknown, since
7250 -- back end knows what the alignment requirements are for atomic and
7251 -- full access arrays. Note: this is necessary for derived types.
7252
7253 -------------------------
7254 -- Check_Full_Access_Only --
7255 -------------------------
7256
7257 procedure Check_Full_Access_Only (Ent : Entity_Id) is
7258 Typ : Entity_Id;
7259
7260 Full_Access_Subcomponent : exception;
7261 -- Exception raised if a full access subcomponent is found
7262
7263 Generic_Type_Subcomponent : exception;
7264 -- Exception raised if a subcomponent with generic type is found
7265
7266 procedure Check_Subcomponents (Typ : Entity_Id);
7267 -- Apply checks to subcomponents recursively
7268
7269 -------------------------
7270 -- Check_Subcomponents --
7271 -------------------------
7272
7273 procedure Check_Subcomponents (Typ : Entity_Id) is
7274 Comp : Entity_Id;
7275
7276 begin
7277 if Is_Array_Type (Typ) then
7278 Comp := Component_Type (Typ);
7279
7280 if Has_Atomic_Components (Typ)
7281 or else Is_Full_Access (Comp)
7282 then
7283 raise Full_Access_Subcomponent;
7284
7285 elsif Is_Generic_Type (Comp) then
7286 raise Generic_Type_Subcomponent;
7287 end if;
7288
7289 -- Recurse on the component type
7290
7291 Check_Subcomponents (Comp);
7292
7293 elsif Is_Record_Type (Typ) then
7294 Comp := First_Component_Or_Discriminant (Typ);
7295 while Present (Comp) loop
7296
7297 if Is_Full_Access (Comp)
7298 or else Is_Full_Access (Etype (Comp))
7299 then
7300 raise Full_Access_Subcomponent;
7301
7302 elsif Is_Generic_Type (Etype (Comp)) then
7303 raise Generic_Type_Subcomponent;
7304 end if;
7305
7306 -- Recurse on the component type
7307
7308 Check_Subcomponents (Etype (Comp));
7309
7310 Next_Component_Or_Discriminant (Comp);
7311 end loop;
7312 end if;
7313 end Check_Subcomponents;
7314
7315 -- Start of processing for Check_Full_Access_Only
7316
7317 begin
7318 -- Fetch the type in case we are dealing with an object or
7319 -- component.
7320
7321 if Is_Type (Ent) then
7322 Typ := Ent;
7323 else
7324 pragma Assert (Is_Object (Ent)
7325 or else
7326 Nkind (Declaration_Node (Ent)) = N_Component_Declaration);
7327
7328 Typ := Etype (Ent);
7329 end if;
7330
7331 if not Is_Volatile (Ent) and then not Is_Volatile (Typ) then
7332 Error_Pragma
7333 ("cannot have Full_Access_Only without Volatile/Atomic "
7334 & "(RM C.6(8.2))");
7335 return;
7336 end if;
7337
7338 -- Check all the subcomponents of the type recursively, if any
7339
7340 Check_Subcomponents (Typ);
7341
7342 exception
7343 when Full_Access_Subcomponent =>
7344 Error_Pragma
7345 ("cannot have Full_Access_Only with full access subcomponent "
7346 & "(RM C.6(8.2))");
7347
7348 when Generic_Type_Subcomponent =>
7349 Error_Pragma
7350 ("cannot have Full_Access_Only with subcomponent of generic "
7351 & "type (RM C.6(8.2))");
7352
7353 end Check_Full_Access_Only;
7354
7355 ------------------------------
7356 -- Mark_Component_Or_Object --
7357 ------------------------------
7358
7359 procedure Mark_Component_Or_Object (Ent : Entity_Id) is
7360 begin
7361 if Prag_Id = Pragma_Atomic
7362 or else Prag_Id = Pragma_Shared
7363 or else Prag_Id = Pragma_Volatile_Full_Access
7364 then
7365 if Prag_Id = Pragma_Volatile_Full_Access then
7366 Set_Is_Volatile_Full_Access (Ent);
7367 else
7368 Set_Is_Atomic (Ent);
7369 end if;
7370
7371 -- If the object declaration has an explicit initialization, a
7372 -- temporary may have to be created to hold the expression, to
7373 -- ensure that access to the object remains atomic.
7374
7375 if Nkind (Parent (Ent)) = N_Object_Declaration
7376 and then Present (Expression (Parent (Ent)))
7377 then
7378 Set_Has_Delayed_Freeze (Ent);
7379 end if;
7380 end if;
7381
7382 -- Atomic/Shared/Volatile_Full_Access imply Independent
7383
7384 if Prag_Id /= Pragma_Volatile then
7385 Set_Is_Independent (Ent);
7386
7387 if Prag_Id = Pragma_Independent then
7388 Record_Independence_Check (N, Ent);
7389 end if;
7390 end if;
7391
7392 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7393
7394 if Prag_Id /= Pragma_Independent then
7395 Set_Is_Volatile (Ent);
7396 Set_Treat_As_Volatile (Ent);
7397 end if;
7398 end Mark_Component_Or_Object;
7399
7400 ---------------
7401 -- Mark_Type --
7402 ---------------
7403
7404 procedure Mark_Type (Ent : Entity_Id) is
7405 begin
7406 -- Attribute belongs on the base type. If the view of the type is
7407 -- currently private, it also belongs on the underlying type.
7408
7409 -- In Ada 2020, the pragma can apply to a formal type, for which
7410 -- there may be no underlying type.
7411
7412 if Prag_Id = Pragma_Atomic
7413 or else Prag_Id = Pragma_Shared
7414 or else Prag_Id = Pragma_Volatile_Full_Access
7415 then
7416 Set_Atomic_VFA (Ent);
7417 Set_Atomic_VFA (Base_Type (Ent));
7418
7419 if not Is_Generic_Type (Ent) then
7420 Set_Atomic_VFA (Underlying_Type (Ent));
7421 end if;
7422 end if;
7423
7424 -- Atomic/Shared/Volatile_Full_Access imply Independent
7425
7426 if Prag_Id /= Pragma_Volatile then
7427 Set_Is_Independent (Ent);
7428 Set_Is_Independent (Base_Type (Ent));
7429
7430 if not Is_Generic_Type (Ent) then
7431 Set_Is_Independent (Underlying_Type (Ent));
7432
7433 if Prag_Id = Pragma_Independent then
7434 Record_Independence_Check (N, Base_Type (Ent));
7435 end if;
7436 end if;
7437 end if;
7438
7439 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7440
7441 if Prag_Id /= Pragma_Independent then
7442 Set_Is_Volatile (Ent);
7443 Set_Is_Volatile (Base_Type (Ent));
7444
7445 if not Is_Generic_Type (Ent) then
7446 Set_Is_Volatile (Underlying_Type (Ent));
7447 Set_Treat_As_Volatile (Underlying_Type (Ent));
7448 end if;
7449
7450 Set_Treat_As_Volatile (Ent);
7451 end if;
7452
7453 -- Apply Volatile to the composite type's individual components,
7454 -- (RM C.6(8/3)).
7455
7456 if Prag_Id = Pragma_Volatile
7457 and then Is_Record_Type (Etype (Ent))
7458 then
7459 declare
7460 Comp : Entity_Id;
7461 begin
7462 Comp := First_Component (Ent);
7463 while Present (Comp) loop
7464 Mark_Component_Or_Object (Comp);
7465
7466 Next_Component (Comp);
7467 end loop;
7468 end;
7469 end if;
7470 end Mark_Type;
7471
7472 --------------------
7473 -- Set_Atomic_VFA --
7474 --------------------
7475
7476 procedure Set_Atomic_VFA (Ent : Entity_Id) is
7477 begin
7478 if Prag_Id = Pragma_Volatile_Full_Access then
7479 Set_Is_Volatile_Full_Access (Ent);
7480 else
7481 Set_Is_Atomic (Ent);
7482 end if;
7483
7484 if not Has_Alignment_Clause (Ent) then
7485 Set_Alignment (Ent, Uint_0);
7486 end if;
7487 end Set_Atomic_VFA;
7488
7489 -- Local variables
7490
7491 Decl : Node_Id;
7492 E : Entity_Id;
7493 E_Arg : Node_Id;
7494
7495 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
7496
7497 begin
7498 Check_Ada_83_Warning;
7499 Check_No_Identifiers;
7500 Check_Arg_Count (1);
7501 Check_Arg_Is_Local_Name (Arg1);
7502 E_Arg := Get_Pragma_Arg (Arg1);
7503
7504 if Etype (E_Arg) = Any_Type then
7505 return;
7506 end if;
7507
7508 E := Entity (E_Arg);
7509 Decl := Declaration_Node (E);
7510
7511 -- A pragma that applies to a Ghost entity becomes Ghost for the
7512 -- purposes of legality checks and removal of ignored Ghost code.
7513
7514 Mark_Ghost_Pragma (N, E);
7515
7516 -- Check duplicate before we chain ourselves
7517
7518 Check_Duplicate_Pragma (E);
7519
7520 -- Check the constraints of Full_Access_Only in Ada 2020. Note that
7521 -- they do not apply to GNAT's Volatile_Full_Access because 1) this
7522 -- aspect subsumes the Volatile aspect and 2) nesting is supported
7523 -- for this aspect and the outermost enclosing VFA object prevails.
7524
7525 -- Note also that we used to forbid specifying both Atomic and VFA on
7526 -- the same type or object, but the restriction has been lifted in
7527 -- light of the semantics of Full_Access_Only and Atomic in Ada 2020.
7528
7529 if Prag_Id = Pragma_Volatile_Full_Access
7530 and then From_Aspect_Specification (N)
7531 and then
7532 Get_Aspect_Id (Corresponding_Aspect (N)) = Aspect_Full_Access_Only
7533 then
7534 Check_Full_Access_Only (E);
7535 end if;
7536
7537 -- The following check is only relevant when SPARK_Mode is on as
7538 -- this is not a standard Ada legality rule. Pragma Volatile can
7539 -- only apply to a full type declaration or an object declaration
7540 -- (SPARK RM 7.1.3(2)). Original_Node is necessary to account for
7541 -- untagged derived types that are rewritten as subtypes of their
7542 -- respective root types.
7543
7544 if SPARK_Mode = On
7545 and then Prag_Id = Pragma_Volatile
7546 and then Nkind (Original_Node (Decl)) not in
7547 N_Full_Type_Declaration |
7548 N_Formal_Type_Declaration |
7549 N_Object_Declaration |
7550 N_Single_Protected_Declaration |
7551 N_Single_Task_Declaration
7552 then
7553 Error_Pragma_Arg
7554 ("argument of pragma % must denote a full type or object "
7555 & "declaration", Arg1);
7556 end if;
7557
7558 -- Deal with the case where the pragma/attribute is applied to a type
7559
7560 if Is_Type (E) then
7561 if Rep_Item_Too_Early (E, N)
7562 or else Rep_Item_Too_Late (E, N)
7563 then
7564 return;
7565 else
7566 Check_First_Subtype (Arg1);
7567 end if;
7568
7569 Mark_Type (E);
7570
7571 -- Deal with the case where the pragma/attribute applies to a
7572 -- component or object declaration.
7573
7574 elsif Nkind (Decl) = N_Object_Declaration
7575 or else (Nkind (Decl) = N_Component_Declaration
7576 and then Original_Record_Component (E) = E)
7577 then
7578 if Rep_Item_Too_Late (E, N) then
7579 return;
7580 end if;
7581
7582 Mark_Component_Or_Object (E);
7583
7584 -- In other cases give an error
7585
7586 else
7587 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7588 end if;
7589 end Process_Atomic_Independent_Shared_Volatile;
7590
7591 -------------------------------------------
7592 -- Process_Compile_Time_Warning_Or_Error --
7593 -------------------------------------------
7594
7595 procedure Process_Compile_Time_Warning_Or_Error is
7596 P : Node_Id := Parent (N);
7597 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
7598
7599 begin
7600 Check_Arg_Count (2);
7601 Check_No_Identifiers;
7602 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
7603 Analyze_And_Resolve (Arg1x, Standard_Boolean);
7604
7605 -- In GNATprove mode, pragma Compile_Time_Error is translated as
7606 -- a Check pragma in GNATprove mode, handled as an assumption in
7607 -- GNATprove. This is correct as the compiler will issue an error
7608 -- if the condition cannot be statically evaluated to False.
7609 -- Compile_Time_Warning are ignored, as the analyzer may not have the
7610 -- same information as the compiler (in particular regarding size of
7611 -- objects decided in gigi) so it makes no sense to issue a warning
7612 -- in GNATprove.
7613
7614 if GNATprove_Mode then
7615 if Prag_Id = Pragma_Compile_Time_Error then
7616 declare
7617 New_Args : List_Id;
7618 begin
7619 -- Implement Compile_Time_Error by generating
7620 -- a corresponding Check pragma:
7621
7622 -- pragma Check (name, condition);
7623
7624 -- where name is the identifier matching the pragma name. So
7625 -- rewrite pragma in this manner and analyze the result.
7626
7627 New_Args := New_List
7628 (Make_Pragma_Argument_Association
7629 (Loc,
7630 Expression => Make_Identifier (Loc, Pname)),
7631 Make_Pragma_Argument_Association
7632 (Sloc (Arg1x),
7633 Expression => Arg1x));
7634
7635 -- Rewrite as Check pragma
7636
7637 Rewrite (N,
7638 Make_Pragma (Loc,
7639 Chars => Name_Check,
7640 Pragma_Argument_Associations => New_Args));
7641
7642 Analyze (N);
7643 end;
7644
7645 else
7646 Rewrite (N, Make_Null_Statement (Loc));
7647 end if;
7648
7649 return;
7650 end if;
7651
7652 -- If the condition is known at compile time (now), validate it now.
7653 -- Otherwise, register the expression for validation after the back
7654 -- end has been called, because it might be known at compile time
7655 -- then. For example, if the expression is "Record_Type'Size /= 32"
7656 -- it might be known after the back end has determined the size of
7657 -- Record_Type. We do not defer validation if we're inside a generic
7658 -- unit, because we will have more information in the instances.
7659
7660 if Compile_Time_Known_Value (Arg1x) then
7661 Validate_Compile_Time_Warning_Or_Error (N, Sloc (Arg1));
7662 else
7663 while Present (P) and then Nkind (P) not in N_Generic_Declaration
7664 loop
7665 if Nkind (P) in N_Package_Body | N_Subprogram_Body then
7666 P := Corresponding_Spec (P);
7667 else
7668 P := Parent (P);
7669 end if;
7670 end loop;
7671
7672 if No (P) then
7673 Defer_Compile_Time_Warning_Error_To_BE (N);
7674 end if;
7675 end if;
7676 end Process_Compile_Time_Warning_Or_Error;
7677
7678 ------------------------
7679 -- Process_Convention --
7680 ------------------------
7681
7682 procedure Process_Convention
7683 (C : out Convention_Id;
7684 Ent : out Entity_Id)
7685 is
7686 Cname : Name_Id;
7687
7688 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
7689 -- Called if we have more than one Export/Import/Convention pragma.
7690 -- This is generally illegal, but we have a special case of allowing
7691 -- Import and Interface to coexist if they specify the convention in
7692 -- a consistent manner. We are allowed to do this, since Interface is
7693 -- an implementation defined pragma, and we choose to do it since we
7694 -- know Rational allows this combination. S is the entity id of the
7695 -- subprogram in question. This procedure also sets the special flag
7696 -- Import_Interface_Present in both pragmas in the case where we do
7697 -- have matching Import and Interface pragmas.
7698
7699 procedure Set_Convention_From_Pragma (E : Entity_Id);
7700 -- Set convention in entity E, and also flag that the entity has a
7701 -- convention pragma. If entity is for a private or incomplete type,
7702 -- also set convention and flag on underlying type. This procedure
7703 -- also deals with the special case of C_Pass_By_Copy convention,
7704 -- and error checks for inappropriate convention specification.
7705
7706 -------------------------------
7707 -- Diagnose_Multiple_Pragmas --
7708 -------------------------------
7709
7710 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
7711 Pdec : constant Node_Id := Declaration_Node (S);
7712 Decl : Node_Id;
7713 Err : Boolean;
7714
7715 function Same_Convention (Decl : Node_Id) return Boolean;
7716 -- Decl is a pragma node. This function returns True if this
7717 -- pragma has a first argument that is an identifier with a
7718 -- Chars field corresponding to the Convention_Id C.
7719
7720 function Same_Name (Decl : Node_Id) return Boolean;
7721 -- Decl is a pragma node. This function returns True if this
7722 -- pragma has a second argument that is an identifier with a
7723 -- Chars field that matches the Chars of the current subprogram.
7724
7725 ---------------------
7726 -- Same_Convention --
7727 ---------------------
7728
7729 function Same_Convention (Decl : Node_Id) return Boolean is
7730 Arg1 : constant Node_Id :=
7731 First (Pragma_Argument_Associations (Decl));
7732
7733 begin
7734 if Present (Arg1) then
7735 declare
7736 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
7737 begin
7738 if Nkind (Arg) = N_Identifier
7739 and then Is_Convention_Name (Chars (Arg))
7740 and then Get_Convention_Id (Chars (Arg)) = C
7741 then
7742 return True;
7743 end if;
7744 end;
7745 end if;
7746
7747 return False;
7748 end Same_Convention;
7749
7750 ---------------
7751 -- Same_Name --
7752 ---------------
7753
7754 function Same_Name (Decl : Node_Id) return Boolean is
7755 Arg1 : constant Node_Id :=
7756 First (Pragma_Argument_Associations (Decl));
7757 Arg2 : Node_Id;
7758
7759 begin
7760 if No (Arg1) then
7761 return False;
7762 end if;
7763
7764 Arg2 := Next (Arg1);
7765
7766 if No (Arg2) then
7767 return False;
7768 end if;
7769
7770 declare
7771 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
7772 begin
7773 if Nkind (Arg) = N_Identifier
7774 and then Chars (Arg) = Chars (S)
7775 then
7776 return True;
7777 end if;
7778 end;
7779
7780 return False;
7781 end Same_Name;
7782
7783 -- Start of processing for Diagnose_Multiple_Pragmas
7784
7785 begin
7786 Err := True;
7787
7788 -- Definitely give message if we have Convention/Export here
7789
7790 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
7791 null;
7792
7793 -- If we have an Import or Export, scan back from pragma to
7794 -- find any previous pragma applying to the same procedure.
7795 -- The scan will be terminated by the start of the list, or
7796 -- hitting the subprogram declaration. This won't allow one
7797 -- pragma to appear in the public part and one in the private
7798 -- part, but that seems very unlikely in practice.
7799
7800 else
7801 Decl := Prev (N);
7802 while Present (Decl) and then Decl /= Pdec loop
7803
7804 -- Look for pragma with same name as us
7805
7806 if Nkind (Decl) = N_Pragma
7807 and then Same_Name (Decl)
7808 then
7809 -- Give error if same as our pragma or Export/Convention
7810
7811 if Pragma_Name_Unmapped (Decl)
7812 in Name_Export
7813 | Name_Convention
7814 | Pragma_Name_Unmapped (N)
7815 then
7816 exit;
7817
7818 -- Case of Import/Interface or the other way round
7819
7820 elsif Pragma_Name_Unmapped (Decl)
7821 in Name_Interface | Name_Import
7822 then
7823 -- Here we know that we have Import and Interface. It
7824 -- doesn't matter which way round they are. See if
7825 -- they specify the same convention. If so, all OK,
7826 -- and set special flags to stop other messages
7827
7828 if Same_Convention (Decl) then
7829 Set_Import_Interface_Present (N);
7830 Set_Import_Interface_Present (Decl);
7831 Err := False;
7832
7833 -- If different conventions, special message
7834
7835 else
7836 Error_Msg_Sloc := Sloc (Decl);
7837 Error_Pragma_Arg
7838 ("convention differs from that given#", Arg1);
7839 return;
7840 end if;
7841 end if;
7842 end if;
7843
7844 Next (Decl);
7845 end loop;
7846 end if;
7847
7848 -- Give message if needed if we fall through those tests
7849 -- except on Relaxed_RM_Semantics where we let go: either this
7850 -- is a case accepted/ignored by other Ada compilers (e.g.
7851 -- a mix of Convention and Import), or another error will be
7852 -- generated later (e.g. using both Import and Export).
7853
7854 if Err and not Relaxed_RM_Semantics then
7855 Error_Pragma_Arg
7856 ("at most one Convention/Export/Import pragma is allowed",
7857 Arg2);
7858 end if;
7859 end Diagnose_Multiple_Pragmas;
7860
7861 --------------------------------
7862 -- Set_Convention_From_Pragma --
7863 --------------------------------
7864
7865 procedure Set_Convention_From_Pragma (E : Entity_Id) is
7866 begin
7867 -- Ada 2005 (AI-430): Check invalid attempt to change convention
7868 -- for an overridden dispatching operation. Technically this is
7869 -- an amendment and should only be done in Ada 2005 mode. However,
7870 -- this is clearly a mistake, since the problem that is addressed
7871 -- by this AI is that there is a clear gap in the RM.
7872
7873 if Is_Dispatching_Operation (E)
7874 and then Present (Overridden_Operation (E))
7875 and then C /= Convention (Overridden_Operation (E))
7876 then
7877 Error_Pragma_Arg
7878 ("cannot change convention for overridden dispatching "
7879 & "operation", Arg1);
7880
7881 -- Special check for convention Stdcall: a dispatching call is not
7882 -- allowed. A dispatching subprogram cannot be used to interface
7883 -- to the Win32 API, so this check actually does not impose any
7884 -- effective restriction.
7885
7886 elsif Is_Dispatching_Operation (E)
7887 and then C = Convention_Stdcall
7888 then
7889 -- Note: make this unconditional so that if there is more
7890 -- than one call to which the pragma applies, we get a
7891 -- message for each call. Also don't use Error_Pragma,
7892 -- so that we get multiple messages.
7893
7894 Error_Msg_Sloc := Sloc (E);
7895 Error_Msg_N
7896 ("dispatching subprogram# cannot use Stdcall convention!",
7897 Get_Pragma_Arg (Arg1));
7898 end if;
7899
7900 -- Set the convention
7901
7902 Set_Convention (E, C);
7903 Set_Has_Convention_Pragma (E);
7904
7905 -- For the case of a record base type, also set the convention of
7906 -- any anonymous access types declared in the record which do not
7907 -- currently have a specified convention.
7908 -- Similarly for an array base type and anonymous access types
7909 -- components.
7910
7911 if Is_Base_Type (E) then
7912 if Is_Record_Type (E) then
7913 declare
7914 Comp : Node_Id;
7915
7916 begin
7917 Comp := First_Component (E);
7918 while Present (Comp) loop
7919 if Present (Etype (Comp))
7920 and then
7921 Ekind (Etype (Comp)) in
7922 E_Anonymous_Access_Type |
7923 E_Anonymous_Access_Subprogram_Type
7924 and then not Has_Convention_Pragma (Comp)
7925 then
7926 Set_Convention (Comp, C);
7927 end if;
7928
7929 Next_Component (Comp);
7930 end loop;
7931 end;
7932
7933 elsif Is_Array_Type (E)
7934 and then Ekind (Component_Type (E)) in
7935 E_Anonymous_Access_Type |
7936 E_Anonymous_Access_Subprogram_Type
7937 then
7938 Set_Convention (Designated_Type (Component_Type (E)), C);
7939 end if;
7940 end if;
7941
7942 -- Deal with incomplete/private type case, where underlying type
7943 -- is available, so set convention of that underlying type.
7944
7945 if Is_Incomplete_Or_Private_Type (E)
7946 and then Present (Underlying_Type (E))
7947 then
7948 Set_Convention (Underlying_Type (E), C);
7949 Set_Has_Convention_Pragma (Underlying_Type (E), True);
7950 end if;
7951
7952 -- A class-wide type should inherit the convention of the specific
7953 -- root type (although this isn't specified clearly by the RM).
7954
7955 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
7956 Set_Convention (Class_Wide_Type (E), C);
7957 end if;
7958
7959 -- If the entity is a record type, then check for special case of
7960 -- C_Pass_By_Copy, which is treated the same as C except that the
7961 -- special record flag is set. This convention is only permitted
7962 -- on record types (see AI95-00131).
7963
7964 if Cname = Name_C_Pass_By_Copy then
7965 if Is_Record_Type (E) then
7966 Set_C_Pass_By_Copy (Base_Type (E));
7967 elsif Is_Incomplete_Or_Private_Type (E)
7968 and then Is_Record_Type (Underlying_Type (E))
7969 then
7970 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
7971 else
7972 Error_Pragma_Arg
7973 ("C_Pass_By_Copy convention allowed only for record type",
7974 Arg2);
7975 end if;
7976 end if;
7977
7978 -- If the entity is a derived boolean type, check for the special
7979 -- case of convention C, C++, or Fortran, where we consider any
7980 -- nonzero value to represent true.
7981
7982 if Is_Discrete_Type (E)
7983 and then Root_Type (Etype (E)) = Standard_Boolean
7984 and then
7985 (C = Convention_C
7986 or else
7987 C = Convention_CPP
7988 or else
7989 C = Convention_Fortran)
7990 then
7991 Set_Nonzero_Is_True (Base_Type (E));
7992 end if;
7993 end Set_Convention_From_Pragma;
7994
7995 -- Local variables
7996
7997 Comp_Unit : Unit_Number_Type;
7998 E : Entity_Id;
7999 E1 : Entity_Id;
8000 Id : Node_Id;
8001 Subp : Entity_Id;
8002
8003 -- Start of processing for Process_Convention
8004
8005 begin
8006 Check_At_Least_N_Arguments (2);
8007 Check_Optional_Identifier (Arg1, Name_Convention);
8008 Check_Arg_Is_Identifier (Arg1);
8009 Cname := Chars (Get_Pragma_Arg (Arg1));
8010
8011 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
8012 -- tested again below to set the critical flag).
8013
8014 if Cname = Name_C_Pass_By_Copy then
8015 C := Convention_C;
8016
8017 -- Otherwise we must have something in the standard convention list
8018
8019 elsif Is_Convention_Name (Cname) then
8020 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
8021
8022 -- Otherwise warn on unrecognized convention
8023
8024 else
8025 if Warn_On_Export_Import then
8026 Error_Msg_N
8027 ("??unrecognized convention name, C assumed",
8028 Get_Pragma_Arg (Arg1));
8029 end if;
8030
8031 C := Convention_C;
8032 end if;
8033
8034 Check_Optional_Identifier (Arg2, Name_Entity);
8035 Check_Arg_Is_Local_Name (Arg2);
8036
8037 Id := Get_Pragma_Arg (Arg2);
8038 Analyze (Id);
8039
8040 if not Is_Entity_Name (Id) then
8041 Error_Pragma_Arg ("entity name required", Arg2);
8042 end if;
8043
8044 E := Entity (Id);
8045
8046 -- Set entity to return
8047
8048 Ent := E;
8049
8050 -- Ada_Pass_By_Copy special checking
8051
8052 if C = Convention_Ada_Pass_By_Copy then
8053 if not Is_First_Subtype (E) then
8054 Error_Pragma_Arg
8055 ("convention `Ada_Pass_By_Copy` only allowed for types",
8056 Arg2);
8057 end if;
8058
8059 if Is_By_Reference_Type (E) then
8060 Error_Pragma_Arg
8061 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
8062 & "type", Arg1);
8063 end if;
8064
8065 -- Ada_Pass_By_Reference special checking
8066
8067 elsif C = Convention_Ada_Pass_By_Reference then
8068 if not Is_First_Subtype (E) then
8069 Error_Pragma_Arg
8070 ("convention `Ada_Pass_By_Reference` only allowed for types",
8071 Arg2);
8072 end if;
8073
8074 if Is_By_Copy_Type (E) then
8075 Error_Pragma_Arg
8076 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
8077 & "type", Arg1);
8078 end if;
8079 end if;
8080
8081 -- Go to renamed subprogram if present, since convention applies to
8082 -- the actual renamed entity, not to the renaming entity. If the
8083 -- subprogram is inherited, go to parent subprogram.
8084
8085 if Is_Subprogram (E)
8086 and then Present (Alias (E))
8087 then
8088 if Nkind (Parent (Declaration_Node (E))) =
8089 N_Subprogram_Renaming_Declaration
8090 then
8091 if Scope (E) /= Scope (Alias (E)) then
8092 Error_Pragma_Ref
8093 ("cannot apply pragma% to non-local entity&#", E);
8094 end if;
8095
8096 E := Alias (E);
8097
8098 elsif Nkind (Parent (E)) in
8099 N_Full_Type_Declaration | N_Private_Extension_Declaration
8100 and then Scope (E) = Scope (Alias (E))
8101 then
8102 E := Alias (E);
8103
8104 -- Return the parent subprogram the entity was inherited from
8105
8106 Ent := E;
8107 end if;
8108 end if;
8109
8110 -- Check that we are not applying this to a specless body. Relax this
8111 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
8112
8113 if Is_Subprogram (E)
8114 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
8115 and then not Relaxed_RM_Semantics
8116 then
8117 Error_Pragma
8118 ("pragma% requires separate spec and must come before body");
8119 end if;
8120
8121 -- Check that we are not applying this to a named constant
8122
8123 if Is_Named_Number (E) then
8124 Error_Msg_Name_1 := Pname;
8125 Error_Msg_N
8126 ("cannot apply pragma% to named constant!",
8127 Get_Pragma_Arg (Arg2));
8128 Error_Pragma_Arg
8129 ("\supply appropriate type for&!", Arg2);
8130 end if;
8131
8132 if Ekind (E) = E_Enumeration_Literal then
8133 Error_Pragma ("enumeration literal not allowed for pragma%");
8134 end if;
8135
8136 -- Check for rep item appearing too early or too late
8137
8138 if Etype (E) = Any_Type
8139 or else Rep_Item_Too_Early (E, N)
8140 then
8141 raise Pragma_Exit;
8142
8143 elsif Present (Underlying_Type (E)) then
8144 E := Underlying_Type (E);
8145 end if;
8146
8147 if Rep_Item_Too_Late (E, N) then
8148 raise Pragma_Exit;
8149 end if;
8150
8151 if Has_Convention_Pragma (E) then
8152 Diagnose_Multiple_Pragmas (E);
8153
8154 elsif Convention (E) = Convention_Protected
8155 or else Ekind (Scope (E)) = E_Protected_Type
8156 then
8157 Error_Pragma_Arg
8158 ("a protected operation cannot be given a different convention",
8159 Arg2);
8160 end if;
8161
8162 -- For Intrinsic, a subprogram is required
8163
8164 if C = Convention_Intrinsic
8165 and then not Is_Subprogram_Or_Generic_Subprogram (E)
8166 then
8167 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
8168
8169 if not (Is_Type (E) and then Relaxed_RM_Semantics) then
8170 if From_Aspect_Specification (N) then
8171 Error_Pragma_Arg
8172 ("entity for aspect% must be a subprogram", Arg2);
8173 else
8174 Error_Pragma_Arg
8175 ("second argument of pragma% must be a subprogram", Arg2);
8176 end if;
8177 end if;
8178
8179 -- Special checks for C_Variadic_n
8180
8181 elsif C in Convention_C_Variadic then
8182
8183 -- Several allowed cases
8184
8185 if Is_Subprogram_Or_Generic_Subprogram (E) then
8186 Subp := E;
8187
8188 -- An access to subprogram is also allowed
8189
8190 elsif Is_Access_Type (E)
8191 and then Ekind (Designated_Type (E)) = E_Subprogram_Type
8192 then
8193 Subp := Designated_Type (E);
8194
8195 -- Allow internal call to set convention of subprogram type
8196
8197 elsif Ekind (E) = E_Subprogram_Type then
8198 Subp := E;
8199
8200 else
8201 Error_Pragma_Arg
8202 ("argument of pragma% must be subprogram or access type",
8203 Arg2);
8204 Subp := Empty;
8205 end if;
8206
8207 -- ISO C requires a named parameter before the ellipsis, so a
8208 -- variadic C function taking 0 fixed parameter cannot exist.
8209
8210 if C = Convention_C_Variadic_0 then
8211
8212 Error_Msg_N
8213 ("??C_Variadic_0 cannot be used for an 'I'S'O C function",
8214 Get_Pragma_Arg (Arg2));
8215
8216 -- Now check the number of parameters of the subprogram and give
8217 -- an error if it is lower than n.
8218
8219 elsif Present (Subp) then
8220 declare
8221 Minimum : constant Nat :=
8222 Convention_Id'Pos (C) -
8223 Convention_Id'Pos (Convention_C_Variadic_0);
8224
8225 Count : Nat;
8226 Formal : Entity_Id;
8227
8228 begin
8229 Count := 0;
8230 Formal := First_Formal (Subp);
8231 while Present (Formal) loop
8232 Count := Count + 1;
8233 Next_Formal (Formal);
8234 end loop;
8235
8236 if Count < Minimum then
8237 Error_Msg_Uint_1 := UI_From_Int (Minimum);
8238 Error_Pragma_Arg
8239 ("argument of pragma% must have at least"
8240 & "^ parameters", Arg2);
8241 end if;
8242 end;
8243 end if;
8244
8245 -- Special checks for Stdcall
8246
8247 elsif C = Convention_Stdcall then
8248
8249 -- Several allowed cases
8250
8251 if Is_Subprogram_Or_Generic_Subprogram (E)
8252
8253 -- A variable is OK
8254
8255 or else Ekind (E) = E_Variable
8256
8257 -- A component as well. The entity does not have its Ekind
8258 -- set until the enclosing record declaration is fully
8259 -- analyzed.
8260
8261 or else Nkind (Parent (E)) = N_Component_Declaration
8262
8263 -- An access to subprogram is also allowed
8264
8265 or else
8266 (Is_Access_Type (E)
8267 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
8268
8269 -- Allow internal call to set convention of subprogram type
8270
8271 or else Ekind (E) = E_Subprogram_Type
8272 then
8273 null;
8274
8275 else
8276 Error_Pragma_Arg
8277 ("argument of pragma% must be subprogram or access type",
8278 Arg2);
8279 end if;
8280 end if;
8281
8282 Set_Convention_From_Pragma (E);
8283
8284 -- Deal with non-subprogram cases
8285
8286 if not Is_Subprogram_Or_Generic_Subprogram (E) then
8287 if Is_Type (E) then
8288
8289 -- The pragma must apply to a first subtype, but it can also
8290 -- apply to a generic type in a generic formal part, in which
8291 -- case it will also appear in the corresponding instance.
8292
8293 if Is_Generic_Type (E) or else In_Instance then
8294 null;
8295 else
8296 Check_First_Subtype (Arg2);
8297 end if;
8298
8299 Set_Convention_From_Pragma (Base_Type (E));
8300
8301 -- For access subprograms, we must set the convention on the
8302 -- internally generated directly designated type as well.
8303
8304 if Ekind (E) = E_Access_Subprogram_Type then
8305 Set_Convention_From_Pragma (Directly_Designated_Type (E));
8306 end if;
8307 end if;
8308
8309 -- For the subprogram case, set proper convention for all homonyms
8310 -- in same scope and the same declarative part, i.e. the same
8311 -- compilation unit.
8312
8313 else
8314 -- Treat a pragma Import as an implicit body, and pragma import
8315 -- as implicit reference (for navigation in GNAT Studio).
8316
8317 if Prag_Id = Pragma_Import then
8318 Generate_Reference (E, Id, 'b');
8319
8320 -- For exported entities we restrict the generation of references
8321 -- to entities exported to foreign languages since entities
8322 -- exported to Ada do not provide further information to
8323 -- GNAT Studio and add undesired references to the output of the
8324 -- gnatxref tool.
8325
8326 elsif Prag_Id = Pragma_Export
8327 and then Convention (E) /= Convention_Ada
8328 then
8329 Generate_Reference (E, Id, 'i');
8330 end if;
8331
8332 -- If the pragma comes from an aspect, it only applies to the
8333 -- given entity, not its homonyms.
8334
8335 if From_Aspect_Specification (N) then
8336 if C = Convention_Intrinsic
8337 and then Nkind (Ent) = N_Defining_Operator_Symbol
8338 then
8339 if Is_Fixed_Point_Type (Etype (Ent))
8340 or else Is_Fixed_Point_Type (Etype (First_Entity (Ent)))
8341 or else Is_Fixed_Point_Type (Etype (Last_Entity (Ent)))
8342 then
8343 Error_Msg_N
8344 ("no intrinsic operator available for this fixed-point "
8345 & "operation", N);
8346 Error_Msg_N
8347 ("\use expression functions with the desired "
8348 & "conversions made explicit", N);
8349 end if;
8350 end if;
8351
8352 return;
8353 end if;
8354
8355 -- Otherwise Loop through the homonyms of the pragma argument's
8356 -- entity, an apply convention to those in the current scope.
8357
8358 Comp_Unit := Get_Source_Unit (E);
8359 E1 := Ent;
8360
8361 loop
8362 E1 := Homonym (E1);
8363 exit when No (E1) or else Scope (E1) /= Current_Scope;
8364
8365 -- Ignore entry for which convention is already set
8366
8367 if Has_Convention_Pragma (E1) then
8368 goto Continue;
8369 end if;
8370
8371 if Is_Subprogram (E1)
8372 and then Nkind (Parent (Declaration_Node (E1))) =
8373 N_Subprogram_Body
8374 and then not Relaxed_RM_Semantics
8375 then
8376 Set_Has_Completion (E); -- to prevent cascaded error
8377 Error_Pragma_Ref
8378 ("pragma% requires separate spec and must come before "
8379 & "body#", E1);
8380 end if;
8381
8382 -- Do not set the pragma on inherited operations or on formal
8383 -- subprograms.
8384
8385 if Comes_From_Source (E1)
8386 and then Comp_Unit = Get_Source_Unit (E1)
8387 and then not Is_Formal_Subprogram (E1)
8388 and then Nkind (Original_Node (Parent (E1))) /=
8389 N_Full_Type_Declaration
8390 then
8391 if Present (Alias (E1))
8392 and then Scope (E1) /= Scope (Alias (E1))
8393 then
8394 Error_Pragma_Ref
8395 ("cannot apply pragma% to non-local entity& declared#",
8396 E1);
8397 end if;
8398
8399 Set_Convention_From_Pragma (E1);
8400
8401 if Prag_Id = Pragma_Import then
8402 Generate_Reference (E1, Id, 'b');
8403 end if;
8404 end if;
8405
8406 <<Continue>>
8407 null;
8408 end loop;
8409 end if;
8410 end Process_Convention;
8411
8412 ----------------------------------------
8413 -- Process_Disable_Enable_Atomic_Sync --
8414 ----------------------------------------
8415
8416 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
8417 begin
8418 Check_No_Identifiers;
8419 Check_At_Most_N_Arguments (1);
8420
8421 -- Modeled internally as
8422 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
8423
8424 Rewrite (N,
8425 Make_Pragma (Loc,
8426 Chars => Nam,
8427 Pragma_Argument_Associations => New_List (
8428 Make_Pragma_Argument_Association (Loc,
8429 Expression =>
8430 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
8431
8432 if Present (Arg1) then
8433 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
8434 end if;
8435
8436 Analyze (N);
8437 end Process_Disable_Enable_Atomic_Sync;
8438
8439 -------------------------------------------------
8440 -- Process_Extended_Import_Export_Internal_Arg --
8441 -------------------------------------------------
8442
8443 procedure Process_Extended_Import_Export_Internal_Arg
8444 (Arg_Internal : Node_Id := Empty)
8445 is
8446 begin
8447 if No (Arg_Internal) then
8448 Error_Pragma ("Internal parameter required for pragma%");
8449 end if;
8450
8451 if Nkind (Arg_Internal) = N_Identifier then
8452 null;
8453
8454 elsif Nkind (Arg_Internal) = N_Operator_Symbol
8455 and then (Prag_Id = Pragma_Import_Function
8456 or else
8457 Prag_Id = Pragma_Export_Function)
8458 then
8459 null;
8460
8461 else
8462 Error_Pragma_Arg
8463 ("wrong form for Internal parameter for pragma%", Arg_Internal);
8464 end if;
8465
8466 Check_Arg_Is_Local_Name (Arg_Internal);
8467 end Process_Extended_Import_Export_Internal_Arg;
8468
8469 --------------------------------------------------
8470 -- Process_Extended_Import_Export_Object_Pragma --
8471 --------------------------------------------------
8472
8473 procedure Process_Extended_Import_Export_Object_Pragma
8474 (Arg_Internal : Node_Id;
8475 Arg_External : Node_Id;
8476 Arg_Size : Node_Id)
8477 is
8478 Def_Id : Entity_Id;
8479
8480 begin
8481 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8482 Def_Id := Entity (Arg_Internal);
8483
8484 if Ekind (Def_Id) not in E_Constant | E_Variable then
8485 Error_Pragma_Arg
8486 ("pragma% must designate an object", Arg_Internal);
8487 end if;
8488
8489 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
8490 or else
8491 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
8492 then
8493 Error_Pragma_Arg
8494 ("previous Common/Psect_Object applies, pragma % not permitted",
8495 Arg_Internal);
8496 end if;
8497
8498 if Rep_Item_Too_Late (Def_Id, N) then
8499 raise Pragma_Exit;
8500 end if;
8501
8502 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
8503
8504 if Present (Arg_Size) then
8505 Check_Arg_Is_External_Name (Arg_Size);
8506 end if;
8507
8508 -- Export_Object case
8509
8510 if Prag_Id = Pragma_Export_Object then
8511 if not Is_Library_Level_Entity (Def_Id) then
8512 Error_Pragma_Arg
8513 ("argument for pragma% must be library level entity",
8514 Arg_Internal);
8515 end if;
8516
8517 if Ekind (Current_Scope) = E_Generic_Package then
8518 Error_Pragma ("pragma& cannot appear in a generic unit");
8519 end if;
8520
8521 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
8522 Error_Pragma_Arg
8523 ("exported object must have compile time known size",
8524 Arg_Internal);
8525 end if;
8526
8527 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
8528 Error_Msg_N ("??duplicate Export_Object pragma", N);
8529 else
8530 Set_Exported (Def_Id, Arg_Internal);
8531 end if;
8532
8533 -- Import_Object case
8534
8535 else
8536 if Is_Concurrent_Type (Etype (Def_Id)) then
8537 Error_Pragma_Arg
8538 ("cannot use pragma% for task/protected object",
8539 Arg_Internal);
8540 end if;
8541
8542 if Ekind (Def_Id) = E_Constant then
8543 Error_Pragma_Arg
8544 ("cannot import a constant", Arg_Internal);
8545 end if;
8546
8547 if Warn_On_Export_Import
8548 and then Has_Discriminants (Etype (Def_Id))
8549 then
8550 Error_Msg_N
8551 ("imported value must be initialized??", Arg_Internal);
8552 end if;
8553
8554 if Warn_On_Export_Import
8555 and then Is_Access_Type (Etype (Def_Id))
8556 then
8557 Error_Pragma_Arg
8558 ("cannot import object of an access type??", Arg_Internal);
8559 end if;
8560
8561 if Warn_On_Export_Import
8562 and then Is_Imported (Def_Id)
8563 then
8564 Error_Msg_N ("??duplicate Import_Object pragma", N);
8565
8566 -- Check for explicit initialization present. Note that an
8567 -- initialization generated by the code generator, e.g. for an
8568 -- access type, does not count here.
8569
8570 elsif Present (Expression (Parent (Def_Id)))
8571 and then
8572 Comes_From_Source
8573 (Original_Node (Expression (Parent (Def_Id))))
8574 then
8575 Error_Msg_Sloc := Sloc (Def_Id);
8576 Error_Pragma_Arg
8577 ("imported entities cannot be initialized (RM B.1(24))",
8578 "\no initialization allowed for & declared#", Arg1);
8579 else
8580 Set_Imported (Def_Id);
8581 Note_Possible_Modification (Arg_Internal, Sure => False);
8582 end if;
8583 end if;
8584 end Process_Extended_Import_Export_Object_Pragma;
8585
8586 ------------------------------------------------------
8587 -- Process_Extended_Import_Export_Subprogram_Pragma --
8588 ------------------------------------------------------
8589
8590 procedure Process_Extended_Import_Export_Subprogram_Pragma
8591 (Arg_Internal : Node_Id;
8592 Arg_External : Node_Id;
8593 Arg_Parameter_Types : Node_Id;
8594 Arg_Result_Type : Node_Id := Empty;
8595 Arg_Mechanism : Node_Id;
8596 Arg_Result_Mechanism : Node_Id := Empty)
8597 is
8598 Ent : Entity_Id;
8599 Def_Id : Entity_Id;
8600 Hom_Id : Entity_Id;
8601 Formal : Entity_Id;
8602 Ambiguous : Boolean;
8603 Match : Boolean;
8604
8605 function Same_Base_Type
8606 (Ptype : Node_Id;
8607 Formal : Entity_Id) return Boolean;
8608 -- Determines if Ptype references the type of Formal. Note that only
8609 -- the base types need to match according to the spec. Ptype here is
8610 -- the argument from the pragma, which is either a type name, or an
8611 -- access attribute.
8612
8613 --------------------
8614 -- Same_Base_Type --
8615 --------------------
8616
8617 function Same_Base_Type
8618 (Ptype : Node_Id;
8619 Formal : Entity_Id) return Boolean
8620 is
8621 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
8622 Pref : Node_Id;
8623
8624 begin
8625 -- Case where pragma argument is typ'Access
8626
8627 if Nkind (Ptype) = N_Attribute_Reference
8628 and then Attribute_Name (Ptype) = Name_Access
8629 then
8630 Pref := Prefix (Ptype);
8631 Find_Type (Pref);
8632
8633 if not Is_Entity_Name (Pref)
8634 or else Entity (Pref) = Any_Type
8635 then
8636 raise Pragma_Exit;
8637 end if;
8638
8639 -- We have a match if the corresponding argument is of an
8640 -- anonymous access type, and its designated type matches the
8641 -- type of the prefix of the access attribute
8642
8643 return Ekind (Ftyp) = E_Anonymous_Access_Type
8644 and then Base_Type (Entity (Pref)) =
8645 Base_Type (Etype (Designated_Type (Ftyp)));
8646
8647 -- Case where pragma argument is a type name
8648
8649 else
8650 Find_Type (Ptype);
8651
8652 if not Is_Entity_Name (Ptype)
8653 or else Entity (Ptype) = Any_Type
8654 then
8655 raise Pragma_Exit;
8656 end if;
8657
8658 -- We have a match if the corresponding argument is of the type
8659 -- given in the pragma (comparing base types)
8660
8661 return Base_Type (Entity (Ptype)) = Ftyp;
8662 end if;
8663 end Same_Base_Type;
8664
8665 -- Start of processing for
8666 -- Process_Extended_Import_Export_Subprogram_Pragma
8667
8668 begin
8669 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8670 Ent := Empty;
8671 Ambiguous := False;
8672
8673 -- Loop through homonyms (overloadings) of the entity
8674
8675 Hom_Id := Entity (Arg_Internal);
8676 while Present (Hom_Id) loop
8677 Def_Id := Get_Base_Subprogram (Hom_Id);
8678
8679 -- We need a subprogram in the current scope
8680
8681 if not Is_Subprogram (Def_Id)
8682 or else Scope (Def_Id) /= Current_Scope
8683 then
8684 null;
8685
8686 else
8687 Match := True;
8688
8689 -- Pragma cannot apply to subprogram body
8690
8691 if Is_Subprogram (Def_Id)
8692 and then Nkind (Parent (Declaration_Node (Def_Id))) =
8693 N_Subprogram_Body
8694 then
8695 Error_Pragma
8696 ("pragma% requires separate spec and must come before "
8697 & "body");
8698 end if;
8699
8700 -- Test result type if given, note that the result type
8701 -- parameter can only be present for the function cases.
8702
8703 if Present (Arg_Result_Type)
8704 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
8705 then
8706 Match := False;
8707
8708 elsif Etype (Def_Id) /= Standard_Void_Type
8709 and then
8710 Pname in Name_Export_Procedure | Name_Import_Procedure
8711 then
8712 Match := False;
8713
8714 -- Test parameter types if given. Note that this parameter has
8715 -- not been analyzed (and must not be, since it is semantic
8716 -- nonsense), so we get it as the parser left it.
8717
8718 elsif Present (Arg_Parameter_Types) then
8719 Check_Matching_Types : declare
8720 Formal : Entity_Id;
8721 Ptype : Node_Id;
8722
8723 begin
8724 Formal := First_Formal (Def_Id);
8725
8726 if Nkind (Arg_Parameter_Types) = N_Null then
8727 if Present (Formal) then
8728 Match := False;
8729 end if;
8730
8731 -- A list of one type, e.g. (List) is parsed as a
8732 -- parenthesized expression.
8733
8734 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
8735 and then Paren_Count (Arg_Parameter_Types) = 1
8736 then
8737 if No (Formal)
8738 or else Present (Next_Formal (Formal))
8739 then
8740 Match := False;
8741 else
8742 Match :=
8743 Same_Base_Type (Arg_Parameter_Types, Formal);
8744 end if;
8745
8746 -- A list of more than one type is parsed as a aggregate
8747
8748 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
8749 and then Paren_Count (Arg_Parameter_Types) = 0
8750 then
8751 Ptype := First (Expressions (Arg_Parameter_Types));
8752 while Present (Ptype) or else Present (Formal) loop
8753 if No (Ptype)
8754 or else No (Formal)
8755 or else not Same_Base_Type (Ptype, Formal)
8756 then
8757 Match := False;
8758 exit;
8759 else
8760 Next_Formal (Formal);
8761 Next (Ptype);
8762 end if;
8763 end loop;
8764
8765 -- Anything else is of the wrong form
8766
8767 else
8768 Error_Pragma_Arg
8769 ("wrong form for Parameter_Types parameter",
8770 Arg_Parameter_Types);
8771 end if;
8772 end Check_Matching_Types;
8773 end if;
8774
8775 -- Match is now False if the entry we found did not match
8776 -- either a supplied Parameter_Types or Result_Types argument
8777
8778 if Match then
8779 if No (Ent) then
8780 Ent := Def_Id;
8781
8782 -- Ambiguous case, the flag Ambiguous shows if we already
8783 -- detected this and output the initial messages.
8784
8785 else
8786 if not Ambiguous then
8787 Ambiguous := True;
8788 Error_Msg_Name_1 := Pname;
8789 Error_Msg_N
8790 ("pragma% does not uniquely identify subprogram!",
8791 N);
8792 Error_Msg_Sloc := Sloc (Ent);
8793 Error_Msg_N ("matching subprogram #!", N);
8794 Ent := Empty;
8795 end if;
8796
8797 Error_Msg_Sloc := Sloc (Def_Id);
8798 Error_Msg_N ("matching subprogram #!", N);
8799 end if;
8800 end if;
8801 end if;
8802
8803 Hom_Id := Homonym (Hom_Id);
8804 end loop;
8805
8806 -- See if we found an entry
8807
8808 if No (Ent) then
8809 if not Ambiguous then
8810 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
8811 Error_Pragma
8812 ("pragma% cannot be given for generic subprogram");
8813 else
8814 Error_Pragma
8815 ("pragma% does not identify local subprogram");
8816 end if;
8817 end if;
8818
8819 return;
8820 end if;
8821
8822 -- Import pragmas must be for imported entities
8823
8824 if Prag_Id = Pragma_Import_Function
8825 or else
8826 Prag_Id = Pragma_Import_Procedure
8827 or else
8828 Prag_Id = Pragma_Import_Valued_Procedure
8829 then
8830 if not Is_Imported (Ent) then
8831 Error_Pragma
8832 ("pragma Import or Interface must precede pragma%");
8833 end if;
8834
8835 -- Here we have the Export case which can set the entity as exported
8836
8837 -- But does not do so if the specified external name is null, since
8838 -- that is taken as a signal in DEC Ada 83 (with which we want to be
8839 -- compatible) to request no external name.
8840
8841 elsif Nkind (Arg_External) = N_String_Literal
8842 and then String_Length (Strval (Arg_External)) = 0
8843 then
8844 null;
8845
8846 -- In all other cases, set entity as exported
8847
8848 else
8849 Set_Exported (Ent, Arg_Internal);
8850 end if;
8851
8852 -- Special processing for Valued_Procedure cases
8853
8854 if Prag_Id = Pragma_Import_Valued_Procedure
8855 or else
8856 Prag_Id = Pragma_Export_Valued_Procedure
8857 then
8858 Formal := First_Formal (Ent);
8859
8860 if No (Formal) then
8861 Error_Pragma ("at least one parameter required for pragma%");
8862
8863 elsif Ekind (Formal) /= E_Out_Parameter then
8864 Error_Pragma ("first parameter must have mode out for pragma%");
8865
8866 else
8867 Set_Is_Valued_Procedure (Ent);
8868 end if;
8869 end if;
8870
8871 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
8872
8873 -- Process Result_Mechanism argument if present. We have already
8874 -- checked that this is only allowed for the function case.
8875
8876 if Present (Arg_Result_Mechanism) then
8877 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
8878 end if;
8879
8880 -- Process Mechanism parameter if present. Note that this parameter
8881 -- is not analyzed, and must not be analyzed since it is semantic
8882 -- nonsense, so we get it in exactly as the parser left it.
8883
8884 if Present (Arg_Mechanism) then
8885 declare
8886 Formal : Entity_Id;
8887 Massoc : Node_Id;
8888 Mname : Node_Id;
8889 Choice : Node_Id;
8890
8891 begin
8892 -- A single mechanism association without a formal parameter
8893 -- name is parsed as a parenthesized expression. All other
8894 -- cases are parsed as aggregates, so we rewrite the single
8895 -- parameter case as an aggregate for consistency.
8896
8897 if Nkind (Arg_Mechanism) /= N_Aggregate
8898 and then Paren_Count (Arg_Mechanism) = 1
8899 then
8900 Rewrite (Arg_Mechanism,
8901 Make_Aggregate (Sloc (Arg_Mechanism),
8902 Expressions => New_List (
8903 Relocate_Node (Arg_Mechanism))));
8904 end if;
8905
8906 -- Case of only mechanism name given, applies to all formals
8907
8908 if Nkind (Arg_Mechanism) /= N_Aggregate then
8909 Formal := First_Formal (Ent);
8910 while Present (Formal) loop
8911 Set_Mechanism_Value (Formal, Arg_Mechanism);
8912 Next_Formal (Formal);
8913 end loop;
8914
8915 -- Case of list of mechanism associations given
8916
8917 else
8918 if Null_Record_Present (Arg_Mechanism) then
8919 Error_Pragma_Arg
8920 ("inappropriate form for Mechanism parameter",
8921 Arg_Mechanism);
8922 end if;
8923
8924 -- Deal with positional ones first
8925
8926 Formal := First_Formal (Ent);
8927
8928 if Present (Expressions (Arg_Mechanism)) then
8929 Mname := First (Expressions (Arg_Mechanism));
8930 while Present (Mname) loop
8931 if No (Formal) then
8932 Error_Pragma_Arg
8933 ("too many mechanism associations", Mname);
8934 end if;
8935
8936 Set_Mechanism_Value (Formal, Mname);
8937 Next_Formal (Formal);
8938 Next (Mname);
8939 end loop;
8940 end if;
8941
8942 -- Deal with named entries
8943
8944 if Present (Component_Associations (Arg_Mechanism)) then
8945 Massoc := First (Component_Associations (Arg_Mechanism));
8946 while Present (Massoc) loop
8947 Choice := First (Choices (Massoc));
8948
8949 if Nkind (Choice) /= N_Identifier
8950 or else Present (Next (Choice))
8951 then
8952 Error_Pragma_Arg
8953 ("incorrect form for mechanism association",
8954 Massoc);
8955 end if;
8956
8957 Formal := First_Formal (Ent);
8958 loop
8959 if No (Formal) then
8960 Error_Pragma_Arg
8961 ("parameter name & not present", Choice);
8962 end if;
8963
8964 if Chars (Choice) = Chars (Formal) then
8965 Set_Mechanism_Value
8966 (Formal, Expression (Massoc));
8967
8968 -- Set entity on identifier for proper tree
8969 -- structure.
8970
8971 Set_Entity (Choice, Formal);
8972
8973 exit;
8974 end if;
8975
8976 Next_Formal (Formal);
8977 end loop;
8978
8979 Next (Massoc);
8980 end loop;
8981 end if;
8982 end if;
8983 end;
8984 end if;
8985 end Process_Extended_Import_Export_Subprogram_Pragma;
8986
8987 --------------------------
8988 -- Process_Generic_List --
8989 --------------------------
8990
8991 procedure Process_Generic_List is
8992 Arg : Node_Id;
8993 Exp : Node_Id;
8994
8995 begin
8996 Check_No_Identifiers;
8997 Check_At_Least_N_Arguments (1);
8998
8999 -- Check all arguments are names of generic units or instances
9000
9001 Arg := Arg1;
9002 while Present (Arg) loop
9003 Exp := Get_Pragma_Arg (Arg);
9004 Analyze (Exp);
9005
9006 if not Is_Entity_Name (Exp)
9007 or else
9008 (not Is_Generic_Instance (Entity (Exp))
9009 and then
9010 not Is_Generic_Unit (Entity (Exp)))
9011 then
9012 Error_Pragma_Arg
9013 ("pragma% argument must be name of generic unit/instance",
9014 Arg);
9015 end if;
9016
9017 Next (Arg);
9018 end loop;
9019 end Process_Generic_List;
9020
9021 ------------------------------------
9022 -- Process_Import_Predefined_Type --
9023 ------------------------------------
9024
9025 procedure Process_Import_Predefined_Type is
9026 Loc : constant Source_Ptr := Sloc (N);
9027 Elmt : Elmt_Id;
9028 Ftyp : Node_Id := Empty;
9029 Decl : Node_Id;
9030 Def : Node_Id;
9031 Nam : Name_Id;
9032
9033 begin
9034 Nam := String_To_Name (Strval (Expression (Arg3)));
9035
9036 Elmt := First_Elmt (Predefined_Float_Types);
9037 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
9038 Next_Elmt (Elmt);
9039 end loop;
9040
9041 Ftyp := Node (Elmt);
9042
9043 if Present (Ftyp) then
9044
9045 -- Don't build a derived type declaration, because predefined C
9046 -- types have no declaration anywhere, so cannot really be named.
9047 -- Instead build a full type declaration, starting with an
9048 -- appropriate type definition is built
9049
9050 if Is_Floating_Point_Type (Ftyp) then
9051 Def := Make_Floating_Point_Definition (Loc,
9052 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
9053 Make_Real_Range_Specification (Loc,
9054 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
9055 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
9056
9057 -- Should never have a predefined type we cannot handle
9058
9059 else
9060 raise Program_Error;
9061 end if;
9062
9063 -- Build and insert a Full_Type_Declaration, which will be
9064 -- analyzed as soon as this list entry has been analyzed.
9065
9066 Decl := Make_Full_Type_Declaration (Loc,
9067 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
9068 Type_Definition => Def);
9069
9070 Insert_After (N, Decl);
9071 Mark_Rewrite_Insertion (Decl);
9072
9073 else
9074 Error_Pragma_Arg ("no matching type found for pragma%", Arg2);
9075 end if;
9076 end Process_Import_Predefined_Type;
9077
9078 ---------------------------------
9079 -- Process_Import_Or_Interface --
9080 ---------------------------------
9081
9082 procedure Process_Import_Or_Interface is
9083 C : Convention_Id;
9084 Def_Id : Entity_Id;
9085 Hom_Id : Entity_Id;
9086
9087 begin
9088 -- In Relaxed_RM_Semantics, support old Ada 83 style:
9089 -- pragma Import (Entity, "external name");
9090
9091 if Relaxed_RM_Semantics
9092 and then Arg_Count = 2
9093 and then Prag_Id = Pragma_Import
9094 and then Nkind (Expression (Arg2)) = N_String_Literal
9095 then
9096 C := Convention_C;
9097 Def_Id := Get_Pragma_Arg (Arg1);
9098 Analyze (Def_Id);
9099
9100 if not Is_Entity_Name (Def_Id) then
9101 Error_Pragma_Arg ("entity name required", Arg1);
9102 end if;
9103
9104 Def_Id := Entity (Def_Id);
9105 Kill_Size_Check_Code (Def_Id);
9106 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
9107
9108 else
9109 Process_Convention (C, Def_Id);
9110
9111 -- A pragma that applies to a Ghost entity becomes Ghost for the
9112 -- purposes of legality checks and removal of ignored Ghost code.
9113
9114 Mark_Ghost_Pragma (N, Def_Id);
9115 Kill_Size_Check_Code (Def_Id);
9116 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
9117 end if;
9118
9119 -- Various error checks
9120
9121 if Ekind (Def_Id) in E_Variable | E_Constant then
9122
9123 -- We do not permit Import to apply to a renaming declaration
9124
9125 if Present (Renamed_Object (Def_Id)) then
9126 Error_Pragma_Arg
9127 ("pragma% not allowed for object renaming", Arg2);
9128
9129 -- User initialization is not allowed for imported object, but
9130 -- the object declaration may contain a default initialization,
9131 -- that will be discarded. Note that an explicit initialization
9132 -- only counts if it comes from source, otherwise it is simply
9133 -- the code generator making an implicit initialization explicit.
9134
9135 elsif Present (Expression (Parent (Def_Id)))
9136 and then Comes_From_Source
9137 (Original_Node (Expression (Parent (Def_Id))))
9138 then
9139 -- Set imported flag to prevent cascaded errors
9140
9141 Set_Is_Imported (Def_Id);
9142
9143 Error_Msg_Sloc := Sloc (Def_Id);
9144 Error_Pragma_Arg
9145 ("no initialization allowed for declaration of& #",
9146 "\imported entities cannot be initialized (RM B.1(24))",
9147 Arg2);
9148
9149 else
9150 -- If the pragma comes from an aspect specification the
9151 -- Is_Imported flag has already been set.
9152
9153 if not From_Aspect_Specification (N) then
9154 Set_Imported (Def_Id);
9155 end if;
9156
9157 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9158
9159 -- Note that we do not set Is_Public here. That's because we
9160 -- only want to set it if there is no address clause, and we
9161 -- don't know that yet, so we delay that processing till
9162 -- freeze time.
9163
9164 -- pragma Import completes deferred constants
9165
9166 if Ekind (Def_Id) = E_Constant then
9167 Set_Has_Completion (Def_Id);
9168 end if;
9169
9170 -- It is not possible to import a constant of an unconstrained
9171 -- array type (e.g. string) because there is no simple way to
9172 -- write a meaningful subtype for it.
9173
9174 if Is_Array_Type (Etype (Def_Id))
9175 and then not Is_Constrained (Etype (Def_Id))
9176 then
9177 Error_Msg_NE
9178 ("imported constant& must have a constrained subtype",
9179 N, Def_Id);
9180 end if;
9181 end if;
9182
9183 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9184
9185 -- If the name is overloaded, pragma applies to all of the denoted
9186 -- entities in the same declarative part, unless the pragma comes
9187 -- from an aspect specification or was generated by the compiler
9188 -- (such as for pragma Provide_Shift_Operators).
9189
9190 Hom_Id := Def_Id;
9191 while Present (Hom_Id) loop
9192
9193 Def_Id := Get_Base_Subprogram (Hom_Id);
9194
9195 -- Ignore inherited subprograms because the pragma will apply
9196 -- to the parent operation, which is the one called.
9197
9198 if Is_Overloadable (Def_Id)
9199 and then Present (Alias (Def_Id))
9200 then
9201 null;
9202
9203 -- If it is not a subprogram, it must be in an outer scope and
9204 -- pragma does not apply.
9205
9206 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9207 null;
9208
9209 -- The pragma does not apply to primitives of interfaces
9210
9211 elsif Is_Dispatching_Operation (Def_Id)
9212 and then Present (Find_Dispatching_Type (Def_Id))
9213 and then Is_Interface (Find_Dispatching_Type (Def_Id))
9214 then
9215 null;
9216
9217 -- Verify that the homonym is in the same declarative part (not
9218 -- just the same scope). If the pragma comes from an aspect
9219 -- specification we know that it is part of the declaration.
9220
9221 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
9222 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9223 and then not From_Aspect_Specification (N)
9224 then
9225 exit;
9226
9227 else
9228 -- If the pragma comes from an aspect specification the
9229 -- Is_Imported flag has already been set.
9230
9231 if not From_Aspect_Specification (N) then
9232 Set_Imported (Def_Id);
9233 end if;
9234
9235 -- Reject an Import applied to an abstract subprogram
9236
9237 if Is_Subprogram (Def_Id)
9238 and then Is_Abstract_Subprogram (Def_Id)
9239 then
9240 Error_Msg_Sloc := Sloc (Def_Id);
9241 Error_Msg_NE
9242 ("cannot import abstract subprogram& declared#",
9243 Arg2, Def_Id);
9244 end if;
9245
9246 -- Special processing for Convention_Intrinsic
9247
9248 if C = Convention_Intrinsic then
9249
9250 -- Link_Name argument not allowed for intrinsic
9251
9252 Check_No_Link_Name;
9253
9254 Set_Is_Intrinsic_Subprogram (Def_Id);
9255
9256 -- If no external name is present, then check that this
9257 -- is a valid intrinsic subprogram. If an external name
9258 -- is present, then this is handled by the back end.
9259
9260 if No (Arg3) then
9261 Check_Intrinsic_Subprogram
9262 (Def_Id, Get_Pragma_Arg (Arg2));
9263 end if;
9264 end if;
9265
9266 -- Verify that the subprogram does not have a completion
9267 -- through a renaming declaration. For other completions the
9268 -- pragma appears as a too late representation.
9269
9270 declare
9271 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
9272
9273 begin
9274 if Present (Decl)
9275 and then Nkind (Decl) = N_Subprogram_Declaration
9276 and then Present (Corresponding_Body (Decl))
9277 and then Nkind (Unit_Declaration_Node
9278 (Corresponding_Body (Decl))) =
9279 N_Subprogram_Renaming_Declaration
9280 then
9281 Error_Msg_Sloc := Sloc (Def_Id);
9282 Error_Msg_NE
9283 ("cannot import&, renaming already provided for "
9284 & "declaration #", N, Def_Id);
9285 end if;
9286 end;
9287
9288 -- If the pragma comes from an aspect specification, there
9289 -- must be an Import aspect specified as well. In the rare
9290 -- case where Import is set to False, the suprogram needs to
9291 -- have a local completion.
9292
9293 declare
9294 Imp_Aspect : constant Node_Id :=
9295 Find_Aspect (Def_Id, Aspect_Import);
9296 Expr : Node_Id;
9297
9298 begin
9299 if Present (Imp_Aspect)
9300 and then Present (Expression (Imp_Aspect))
9301 then
9302 Expr := Expression (Imp_Aspect);
9303 Analyze_And_Resolve (Expr, Standard_Boolean);
9304
9305 if Is_Entity_Name (Expr)
9306 and then Entity (Expr) = Standard_True
9307 then
9308 Set_Has_Completion (Def_Id);
9309 end if;
9310
9311 -- If there is no expression, the default is True, as for
9312 -- all boolean aspects. Same for the older pragma.
9313
9314 else
9315 Set_Has_Completion (Def_Id);
9316 end if;
9317 end;
9318
9319 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9320 end if;
9321
9322 if Is_Compilation_Unit (Hom_Id) then
9323
9324 -- Its possible homonyms are not affected by the pragma.
9325 -- Such homonyms might be present in the context of other
9326 -- units being compiled.
9327
9328 exit;
9329
9330 elsif From_Aspect_Specification (N) then
9331 exit;
9332
9333 -- If the pragma was created by the compiler, then we don't
9334 -- want it to apply to other homonyms. This kind of case can
9335 -- occur when using pragma Provide_Shift_Operators, which
9336 -- generates implicit shift and rotate operators with Import
9337 -- pragmas that might apply to earlier explicit or implicit
9338 -- declarations marked with Import (for example, coming from
9339 -- an earlier pragma Provide_Shift_Operators for another type),
9340 -- and we don't generally want other homonyms being treated
9341 -- as imported or the pragma flagged as an illegal duplicate.
9342
9343 elsif not Comes_From_Source (N) then
9344 exit;
9345
9346 else
9347 Hom_Id := Homonym (Hom_Id);
9348 end if;
9349 end loop;
9350
9351 -- Import a CPP class
9352
9353 elsif C = Convention_CPP
9354 and then (Is_Record_Type (Def_Id)
9355 or else Ekind (Def_Id) = E_Incomplete_Type)
9356 then
9357 if Ekind (Def_Id) = E_Incomplete_Type then
9358 if Present (Full_View (Def_Id)) then
9359 Def_Id := Full_View (Def_Id);
9360
9361 else
9362 Error_Msg_N
9363 ("cannot import 'C'P'P type before full declaration seen",
9364 Get_Pragma_Arg (Arg2));
9365
9366 -- Although we have reported the error we decorate it as
9367 -- CPP_Class to avoid reporting spurious errors
9368
9369 Set_Is_CPP_Class (Def_Id);
9370 return;
9371 end if;
9372 end if;
9373
9374 -- Types treated as CPP classes must be declared limited (note:
9375 -- this used to be a warning but there is no real benefit to it
9376 -- since we did effectively intend to treat the type as limited
9377 -- anyway).
9378
9379 if not Is_Limited_Type (Def_Id) then
9380 Error_Msg_N
9381 ("imported 'C'P'P type must be limited",
9382 Get_Pragma_Arg (Arg2));
9383 end if;
9384
9385 if Etype (Def_Id) /= Def_Id
9386 and then not Is_CPP_Class (Root_Type (Def_Id))
9387 then
9388 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
9389 end if;
9390
9391 Set_Is_CPP_Class (Def_Id);
9392
9393 -- Imported CPP types must not have discriminants (because C++
9394 -- classes do not have discriminants).
9395
9396 if Has_Discriminants (Def_Id) then
9397 Error_Msg_N
9398 ("imported 'C'P'P type cannot have discriminants",
9399 First (Discriminant_Specifications
9400 (Declaration_Node (Def_Id))));
9401 end if;
9402
9403 -- Check that components of imported CPP types do not have default
9404 -- expressions. For private types this check is performed when the
9405 -- full view is analyzed (see Process_Full_View).
9406
9407 if not Is_Private_Type (Def_Id) then
9408 Check_CPP_Type_Has_No_Defaults (Def_Id);
9409 end if;
9410
9411 -- Import a CPP exception
9412
9413 elsif C = Convention_CPP
9414 and then Ekind (Def_Id) = E_Exception
9415 then
9416 if No (Arg3) then
9417 Error_Pragma_Arg
9418 ("'External_'Name arguments is required for 'Cpp exception",
9419 Arg3);
9420 else
9421 -- As only a string is allowed, Check_Arg_Is_External_Name
9422 -- isn't called.
9423
9424 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9425 end if;
9426
9427 if Present (Arg4) then
9428 Error_Pragma_Arg
9429 ("Link_Name argument not allowed for imported Cpp exception",
9430 Arg4);
9431 end if;
9432
9433 -- Do not call Set_Interface_Name as the name of the exception
9434 -- shouldn't be modified (and in particular it shouldn't be
9435 -- the External_Name). For exceptions, the External_Name is the
9436 -- name of the RTTI structure.
9437
9438 -- ??? Emit an error if pragma Import/Export_Exception is present
9439
9440 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
9441 Check_No_Link_Name;
9442 Check_Arg_Count (3);
9443 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9444
9445 Process_Import_Predefined_Type;
9446
9447 else
9448 if From_Aspect_Specification (N) then
9449 Error_Pragma_Arg
9450 ("entity for aspect% must be object, subprogram "
9451 & "or incomplete type",
9452 Arg2);
9453 else
9454 Error_Pragma_Arg
9455 ("second argument of pragma% must be object, subprogram "
9456 & "or incomplete type",
9457 Arg2);
9458 end if;
9459 end if;
9460
9461 -- If this pragma applies to a compilation unit, then the unit, which
9462 -- is a subprogram, does not require (or allow) a body. We also do
9463 -- not need to elaborate imported procedures.
9464
9465 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9466 declare
9467 Cunit : constant Node_Id := Parent (Parent (N));
9468 begin
9469 Set_Body_Required (Cunit, False);
9470 end;
9471 end if;
9472 end Process_Import_Or_Interface;
9473
9474 --------------------
9475 -- Process_Inline --
9476 --------------------
9477
9478 procedure Process_Inline (Status : Inline_Status) is
9479 Applies : Boolean;
9480 Assoc : Node_Id;
9481 Decl : Node_Id;
9482 Subp : Entity_Id;
9483 Subp_Id : Node_Id;
9484
9485 Ghost_Error_Posted : Boolean := False;
9486 -- Flag set when an error concerning the illegal mix of Ghost and
9487 -- non-Ghost subprograms is emitted.
9488
9489 Ghost_Id : Entity_Id := Empty;
9490 -- The entity of the first Ghost subprogram encountered while
9491 -- processing the arguments of the pragma.
9492
9493 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id);
9494 -- Verify the placement of pragma Inline_Always with respect to the
9495 -- initial declaration of subprogram Spec_Id.
9496
9497 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
9498 -- Returns True if it can be determined at this stage that inlining
9499 -- is not possible, for example if the body is available and contains
9500 -- exception handlers, we prevent inlining, since otherwise we can
9501 -- get undefined symbols at link time. This function also emits a
9502 -- warning if the pragma appears too late.
9503 --
9504 -- ??? is business with link symbols still valid, or does it relate
9505 -- to front end ZCX which is being phased out ???
9506
9507 procedure Make_Inline (Subp : Entity_Id);
9508 -- Subp is the defining unit name of the subprogram declaration. If
9509 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
9510 -- the corresponding body, if there is one present.
9511
9512 procedure Set_Inline_Flags (Subp : Entity_Id);
9513 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
9514 -- Also set or clear Is_Inlined flag on Subp depending on Status.
9515
9516 -----------------------------------
9517 -- Check_Inline_Always_Placement --
9518 -----------------------------------
9519
9520 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id) is
9521 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id);
9522
9523 function Compilation_Unit_OK return Boolean;
9524 pragma Inline (Compilation_Unit_OK);
9525 -- Determine whether pragma Inline_Always applies to a compatible
9526 -- compilation unit denoted by Spec_Id.
9527
9528 function Declarative_List_OK return Boolean;
9529 pragma Inline (Declarative_List_OK);
9530 -- Determine whether the initial declaration of subprogram Spec_Id
9531 -- and the pragma appear in compatible declarative lists.
9532
9533 function Subprogram_Body_OK return Boolean;
9534 pragma Inline (Subprogram_Body_OK);
9535 -- Determine whether pragma Inline_Always applies to a compatible
9536 -- subprogram body denoted by Spec_Id.
9537
9538 -------------------------
9539 -- Compilation_Unit_OK --
9540 -------------------------
9541
9542 function Compilation_Unit_OK return Boolean is
9543 Comp_Unit : constant Node_Id := Parent (Spec_Decl);
9544
9545 begin
9546 -- The pragma appears after the initial declaration of a
9547 -- compilation unit.
9548
9549 -- procedure Comp_Unit;
9550 -- pragma Inline_Always (Comp_Unit);
9551
9552 -- Note that for compatibility reasons, the following case is
9553 -- also accepted.
9554
9555 -- procedure Stand_Alone_Body_Comp_Unit is
9556 -- ...
9557 -- end Stand_Alone_Body_Comp_Unit;
9558 -- pragma Inline_Always (Stand_Alone_Body_Comp_Unit);
9559
9560 return
9561 Nkind (Comp_Unit) = N_Compilation_Unit
9562 and then Present (Aux_Decls_Node (Comp_Unit))
9563 and then Is_List_Member (N)
9564 and then List_Containing (N) =
9565 Pragmas_After (Aux_Decls_Node (Comp_Unit));
9566 end Compilation_Unit_OK;
9567
9568 -------------------------
9569 -- Declarative_List_OK --
9570 -------------------------
9571
9572 function Declarative_List_OK return Boolean is
9573 Context : constant Node_Id := Parent (Spec_Decl);
9574
9575 Init_Decl : Node_Id;
9576 Init_List : List_Id;
9577 Prag_List : List_Id;
9578
9579 begin
9580 -- Determine the proper initial declaration. In general this is
9581 -- the declaration node of the subprogram except when the input
9582 -- denotes a generic instantiation.
9583
9584 -- procedure Inst is new Gen;
9585 -- pragma Inline_Always (Inst);
9586
9587 -- In this case the original subprogram is moved inside an
9588 -- anonymous package while pragma Inline_Always remains at the
9589 -- level of the anonymous package. Use the declaration of the
9590 -- package because it reflects the placement of the original
9591 -- instantiation.
9592
9593 -- package Anon_Pack is
9594 -- procedure Inst is ... end Inst; -- original
9595 -- end Anon_Pack;
9596
9597 -- procedure Inst renames Anon_Pack.Inst;
9598 -- pragma Inline_Always (Inst);
9599
9600 if Is_Generic_Instance (Spec_Id) then
9601 Init_Decl := Parent (Parent (Spec_Decl));
9602 pragma Assert (Nkind (Init_Decl) = N_Package_Declaration);
9603 else
9604 Init_Decl := Spec_Decl;
9605 end if;
9606
9607 if Is_List_Member (Init_Decl) and then Is_List_Member (N) then
9608 Init_List := List_Containing (Init_Decl);
9609 Prag_List := List_Containing (N);
9610
9611 -- The pragma and then initial declaration appear within the
9612 -- same declarative list.
9613
9614 if Init_List = Prag_List then
9615 return True;
9616
9617 -- A special case of the above is when both the pragma and
9618 -- the initial declaration appear in different lists of a
9619 -- package spec, protected definition, or a task definition.
9620
9621 -- package Pack is
9622 -- procedure Proc;
9623 -- private
9624 -- pragma Inline_Always (Proc);
9625 -- end Pack;
9626
9627 elsif Nkind (Context) in N_Package_Specification
9628 | N_Protected_Definition
9629 | N_Task_Definition
9630 and then Init_List = Visible_Declarations (Context)
9631 and then Prag_List = Private_Declarations (Context)
9632 then
9633 return True;
9634 end if;
9635 end if;
9636
9637 return False;
9638 end Declarative_List_OK;
9639
9640 ------------------------
9641 -- Subprogram_Body_OK --
9642 ------------------------
9643
9644 function Subprogram_Body_OK return Boolean is
9645 Body_Decl : Node_Id;
9646
9647 begin
9648 -- The pragma appears within the declarative list of a stand-
9649 -- alone subprogram body.
9650
9651 -- procedure Stand_Alone_Body is
9652 -- pragma Inline_Always (Stand_Alone_Body);
9653 -- begin
9654 -- ...
9655 -- end Stand_Alone_Body;
9656
9657 -- The compiler creates a dummy spec in this case, however the
9658 -- pragma remains within the declarative list of the body.
9659
9660 if Nkind (Spec_Decl) = N_Subprogram_Declaration
9661 and then not Comes_From_Source (Spec_Decl)
9662 and then Present (Corresponding_Body (Spec_Decl))
9663 then
9664 Body_Decl :=
9665 Unit_Declaration_Node (Corresponding_Body (Spec_Decl));
9666
9667 if Present (Declarations (Body_Decl))
9668 and then Is_List_Member (N)
9669 and then List_Containing (N) = Declarations (Body_Decl)
9670 then
9671 return True;
9672 end if;
9673 end if;
9674
9675 return False;
9676 end Subprogram_Body_OK;
9677
9678 -- Start of processing for Check_Inline_Always_Placement
9679
9680 begin
9681 -- This check is relevant only for pragma Inline_Always
9682
9683 if Pname /= Name_Inline_Always then
9684 return;
9685
9686 -- Nothing to do when the pragma is internally generated on the
9687 -- assumption that it is properly placed.
9688
9689 elsif not Comes_From_Source (N) then
9690 return;
9691
9692 -- Nothing to do for internally generated subprograms that act
9693 -- as accidental homonyms of a source subprogram being inlined.
9694
9695 elsif not Comes_From_Source (Spec_Id) then
9696 return;
9697
9698 -- Nothing to do for generic formal subprograms that act as
9699 -- homonyms of another source subprogram being inlined.
9700
9701 elsif Is_Formal_Subprogram (Spec_Id) then
9702 return;
9703
9704 elsif Compilation_Unit_OK
9705 or else Declarative_List_OK
9706 or else Subprogram_Body_OK
9707 then
9708 return;
9709 end if;
9710
9711 -- At this point it is known that the pragma applies to or appears
9712 -- within a completing body, a completing stub, or a subunit.
9713
9714 Error_Msg_Name_1 := Pname;
9715 Error_Msg_Name_2 := Chars (Spec_Id);
9716 Error_Msg_Sloc := Sloc (Spec_Id);
9717
9718 Error_Msg_N
9719 ("pragma % must appear on initial declaration of subprogram "
9720 & "% defined #", N);
9721 end Check_Inline_Always_Placement;
9722
9723 ---------------------------
9724 -- Inlining_Not_Possible --
9725 ---------------------------
9726
9727 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
9728 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
9729 Stats : Node_Id;
9730
9731 begin
9732 if Nkind (Decl) = N_Subprogram_Body then
9733 Stats := Handled_Statement_Sequence (Decl);
9734 return Present (Exception_Handlers (Stats))
9735 or else Present (At_End_Proc (Stats));
9736
9737 elsif Nkind (Decl) = N_Subprogram_Declaration
9738 and then Present (Corresponding_Body (Decl))
9739 then
9740 if Analyzed (Corresponding_Body (Decl)) then
9741 Error_Msg_N ("pragma appears too late, ignored??", N);
9742 return True;
9743
9744 -- If the subprogram is a renaming as body, the body is just a
9745 -- call to the renamed subprogram, and inlining is trivially
9746 -- possible.
9747
9748 elsif
9749 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
9750 N_Subprogram_Renaming_Declaration
9751 then
9752 return False;
9753
9754 else
9755 Stats :=
9756 Handled_Statement_Sequence
9757 (Unit_Declaration_Node (Corresponding_Body (Decl)));
9758
9759 return
9760 Present (Exception_Handlers (Stats))
9761 or else Present (At_End_Proc (Stats));
9762 end if;
9763
9764 else
9765 -- If body is not available, assume the best, the check is
9766 -- performed again when compiling enclosing package bodies.
9767
9768 return False;
9769 end if;
9770 end Inlining_Not_Possible;
9771
9772 -----------------
9773 -- Make_Inline --
9774 -----------------
9775
9776 procedure Make_Inline (Subp : Entity_Id) is
9777 Kind : constant Entity_Kind := Ekind (Subp);
9778 Inner_Subp : Entity_Id := Subp;
9779
9780 begin
9781 -- Ignore if bad type, avoid cascaded error
9782
9783 if Etype (Subp) = Any_Type then
9784 Applies := True;
9785 return;
9786
9787 -- If inlining is not possible, for now do not treat as an error
9788
9789 elsif Status /= Suppressed
9790 and then Front_End_Inlining
9791 and then Inlining_Not_Possible (Subp)
9792 then
9793 Applies := True;
9794 return;
9795
9796 -- Here we have a candidate for inlining, but we must exclude
9797 -- derived operations. Otherwise we would end up trying to inline
9798 -- a phantom declaration, and the result would be to drag in a
9799 -- body which has no direct inlining associated with it. That
9800 -- would not only be inefficient but would also result in the
9801 -- backend doing cross-unit inlining in cases where it was
9802 -- definitely inappropriate to do so.
9803
9804 -- However, a simple Comes_From_Source test is insufficient, since
9805 -- we do want to allow inlining of generic instances which also do
9806 -- not come from source. We also need to recognize specs generated
9807 -- by the front-end for bodies that carry the pragma. Finally,
9808 -- predefined operators do not come from source but are not
9809 -- inlineable either.
9810
9811 elsif Is_Generic_Instance (Subp)
9812 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
9813 then
9814 null;
9815
9816 elsif not Comes_From_Source (Subp)
9817 and then Scope (Subp) /= Standard_Standard
9818 then
9819 Applies := True;
9820 return;
9821 end if;
9822
9823 -- The referenced entity must either be the enclosing entity, or
9824 -- an entity declared within the current open scope.
9825
9826 if Present (Scope (Subp))
9827 and then Scope (Subp) /= Current_Scope
9828 and then Subp /= Current_Scope
9829 then
9830 Error_Pragma_Arg
9831 ("argument of% must be entity in current scope", Assoc);
9832 return;
9833 end if;
9834
9835 -- Processing for procedure, operator or function. If subprogram
9836 -- is aliased (as for an instance) indicate that the renamed
9837 -- entity (if declared in the same unit) is inlined.
9838 -- If this is the anonymous subprogram created for a subprogram
9839 -- instance, the inlining applies to it directly. Otherwise we
9840 -- retrieve it as the alias of the visible subprogram instance.
9841
9842 if Is_Subprogram (Subp) then
9843
9844 -- Ensure that pragma Inline_Always is associated with the
9845 -- initial declaration of the subprogram.
9846
9847 Check_Inline_Always_Placement (Subp);
9848
9849 if Is_Wrapper_Package (Scope (Subp)) then
9850 Inner_Subp := Subp;
9851 else
9852 Inner_Subp := Ultimate_Alias (Inner_Subp);
9853 end if;
9854
9855 if In_Same_Source_Unit (Subp, Inner_Subp) then
9856 Set_Inline_Flags (Inner_Subp);
9857
9858 Decl := Parent (Parent (Inner_Subp));
9859
9860 if Nkind (Decl) = N_Subprogram_Declaration
9861 and then Present (Corresponding_Body (Decl))
9862 then
9863 Set_Inline_Flags (Corresponding_Body (Decl));
9864
9865 elsif Is_Generic_Instance (Subp)
9866 and then Comes_From_Source (Subp)
9867 then
9868 -- Indicate that the body needs to be created for
9869 -- inlining subsequent calls. The instantiation node
9870 -- follows the declaration of the wrapper package
9871 -- created for it. The subprogram that requires the
9872 -- body is the anonymous one in the wrapper package.
9873
9874 if Scope (Subp) /= Standard_Standard
9875 and then
9876 Need_Subprogram_Instance_Body
9877 (Next (Unit_Declaration_Node
9878 (Scope (Alias (Subp)))), Subp)
9879 then
9880 null;
9881 end if;
9882
9883 -- Inline is a program unit pragma (RM 10.1.5) and cannot
9884 -- appear in a formal part to apply to a formal subprogram.
9885 -- Do not apply check within an instance or a formal package
9886 -- the test will have been applied to the original generic.
9887
9888 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
9889 and then In_Same_List (Decl, N)
9890 and then not In_Instance
9891 then
9892 Error_Msg_N
9893 ("Inline cannot apply to a formal subprogram", N);
9894 end if;
9895 end if;
9896
9897 Applies := True;
9898
9899 -- For a generic subprogram set flag as well, for use at the point
9900 -- of instantiation, to determine whether the body should be
9901 -- generated.
9902
9903 elsif Is_Generic_Subprogram (Subp) then
9904 Set_Inline_Flags (Subp);
9905 Applies := True;
9906
9907 -- Literals are by definition inlined
9908
9909 elsif Kind = E_Enumeration_Literal then
9910 null;
9911
9912 -- Anything else is an error
9913
9914 else
9915 Error_Pragma_Arg
9916 ("expect subprogram name for pragma%", Assoc);
9917 end if;
9918 end Make_Inline;
9919
9920 ----------------------
9921 -- Set_Inline_Flags --
9922 ----------------------
9923
9924 procedure Set_Inline_Flags (Subp : Entity_Id) is
9925 begin
9926 -- First set the Has_Pragma_XXX flags and issue the appropriate
9927 -- errors and warnings for suspicious combinations.
9928
9929 if Prag_Id = Pragma_No_Inline then
9930 if Has_Pragma_Inline_Always (Subp) then
9931 Error_Msg_N
9932 ("Inline_Always and No_Inline are mutually exclusive", N);
9933 elsif Has_Pragma_Inline (Subp) then
9934 Error_Msg_NE
9935 ("Inline and No_Inline both specified for& ??",
9936 N, Entity (Subp_Id));
9937 end if;
9938
9939 Set_Has_Pragma_No_Inline (Subp);
9940 else
9941 if Prag_Id = Pragma_Inline_Always then
9942 if Has_Pragma_No_Inline (Subp) then
9943 Error_Msg_N
9944 ("Inline_Always and No_Inline are mutually exclusive",
9945 N);
9946 end if;
9947
9948 Set_Has_Pragma_Inline_Always (Subp);
9949 else
9950 if Has_Pragma_No_Inline (Subp) then
9951 Error_Msg_NE
9952 ("Inline and No_Inline both specified for& ??",
9953 N, Entity (Subp_Id));
9954 end if;
9955 end if;
9956
9957 Set_Has_Pragma_Inline (Subp);
9958 end if;
9959
9960 -- Then adjust the Is_Inlined flag. It can never be set if the
9961 -- subprogram is subject to pragma No_Inline.
9962
9963 case Status is
9964 when Suppressed =>
9965 Set_Is_Inlined (Subp, False);
9966
9967 when Disabled =>
9968 null;
9969
9970 when Enabled =>
9971 if not Has_Pragma_No_Inline (Subp) then
9972 Set_Is_Inlined (Subp, True);
9973 end if;
9974 end case;
9975
9976 -- A pragma that applies to a Ghost entity becomes Ghost for the
9977 -- purposes of legality checks and removal of ignored Ghost code.
9978
9979 Mark_Ghost_Pragma (N, Subp);
9980
9981 -- Capture the entity of the first Ghost subprogram being
9982 -- processed for error detection purposes.
9983
9984 if Is_Ghost_Entity (Subp) then
9985 if No (Ghost_Id) then
9986 Ghost_Id := Subp;
9987 end if;
9988
9989 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
9990 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
9991
9992 elsif Present (Ghost_Id) and then not Ghost_Error_Posted then
9993 Ghost_Error_Posted := True;
9994
9995 Error_Msg_Name_1 := Pname;
9996 Error_Msg_N
9997 ("pragma % cannot mention ghost and non-ghost subprograms",
9998 N);
9999
10000 Error_Msg_Sloc := Sloc (Ghost_Id);
10001 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
10002
10003 Error_Msg_Sloc := Sloc (Subp);
10004 Error_Msg_NE ("\& # declared as non-ghost", N, Subp);
10005 end if;
10006 end Set_Inline_Flags;
10007
10008 -- Start of processing for Process_Inline
10009
10010 begin
10011 -- An inlined subprogram may grant access to its private enclosing
10012 -- context depending on the placement of its body. From elaboration
10013 -- point of view, the flow of execution may enter this private
10014 -- context, and then reach an external unit, thus producing a
10015 -- dependency on that external unit. For such a path to be properly
10016 -- discovered and encoded in the ALI file of the main unit, let the
10017 -- ABE mechanism process the body of the main unit, and encode all
10018 -- relevant invocation constructs and the relations between them.
10019
10020 Mark_Save_Invocation_Graph_Of_Body;
10021
10022 Check_No_Identifiers;
10023 Check_At_Least_N_Arguments (1);
10024
10025 if Status = Enabled then
10026 Inline_Processing_Required := True;
10027 end if;
10028
10029 Assoc := Arg1;
10030 while Present (Assoc) loop
10031 Subp_Id := Get_Pragma_Arg (Assoc);
10032 Analyze (Subp_Id);
10033 Applies := False;
10034
10035 if Is_Entity_Name (Subp_Id) then
10036 Subp := Entity (Subp_Id);
10037
10038 if Subp = Any_Id then
10039
10040 -- If previous error, avoid cascaded errors
10041
10042 Check_Error_Detected;
10043 Applies := True;
10044
10045 else
10046 -- Check for RM 13.1(9.2/4): If a [...] aspect_specification
10047 -- is given that directly specifies an aspect of an entity,
10048 -- then it is illegal to give another [...]
10049 -- aspect_specification that directly specifies the same
10050 -- aspect of the entity.
10051 -- We only check Subp directly as per "directly specifies"
10052 -- above and because the case of pragma Inline is really
10053 -- special given its pre aspect usage.
10054
10055 Check_Duplicate_Pragma (Subp);
10056 Record_Rep_Item (Subp, N);
10057
10058 Make_Inline (Subp);
10059
10060 -- For the pragma case, climb homonym chain. This is
10061 -- what implements allowing the pragma in the renaming
10062 -- case, with the result applying to the ancestors, and
10063 -- also allows Inline to apply to all previous homonyms.
10064
10065 if not From_Aspect_Specification (N) then
10066 while Present (Homonym (Subp))
10067 and then Scope (Homonym (Subp)) = Current_Scope
10068 loop
10069 Subp := Homonym (Subp);
10070 Make_Inline (Subp);
10071 end loop;
10072 end if;
10073 end if;
10074 end if;
10075
10076 if not Applies then
10077 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
10078 end if;
10079
10080 Next (Assoc);
10081 end loop;
10082
10083 -- If the context is a package declaration, the pragma indicates
10084 -- that inlining will require the presence of the corresponding
10085 -- body. (this may be further refined).
10086
10087 if not In_Instance
10088 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
10089 N_Package_Declaration
10090 then
10091 Set_Body_Needed_For_Inlining (Cunit_Entity (Current_Sem_Unit));
10092 end if;
10093 end Process_Inline;
10094
10095 ----------------------------
10096 -- Process_Interface_Name --
10097 ----------------------------
10098
10099 procedure Process_Interface_Name
10100 (Subprogram_Def : Entity_Id;
10101 Ext_Arg : Node_Id;
10102 Link_Arg : Node_Id;
10103 Prag : Node_Id)
10104 is
10105 Ext_Nam : Node_Id;
10106 Link_Nam : Node_Id;
10107 String_Val : String_Id;
10108
10109 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
10110 -- SN is a string literal node for an interface name. This routine
10111 -- performs some minimal checks that the name is reasonable. In
10112 -- particular that no spaces or other obviously incorrect characters
10113 -- appear. This is only a warning, since any characters are allowed.
10114
10115 ----------------------------------
10116 -- Check_Form_Of_Interface_Name --
10117 ----------------------------------
10118
10119 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
10120 S : constant String_Id := Strval (Expr_Value_S (SN));
10121 SL : constant Nat := String_Length (S);
10122 C : Char_Code;
10123
10124 begin
10125 if SL = 0 then
10126 Error_Msg_N ("interface name cannot be null string", SN);
10127 end if;
10128
10129 for J in 1 .. SL loop
10130 C := Get_String_Char (S, J);
10131
10132 -- Look for dubious character and issue unconditional warning.
10133 -- Definitely dubious if not in character range.
10134
10135 if not In_Character_Range (C)
10136
10137 -- Commas, spaces and (back)slashes are dubious
10138
10139 or else Get_Character (C) = ','
10140 or else Get_Character (C) = '\'
10141 or else Get_Character (C) = ' '
10142 or else Get_Character (C) = '/'
10143 then
10144 Error_Msg
10145 ("??interface name contains illegal character",
10146 Sloc (SN) + Source_Ptr (J));
10147 end if;
10148 end loop;
10149 end Check_Form_Of_Interface_Name;
10150
10151 -- Start of processing for Process_Interface_Name
10152
10153 begin
10154 -- If we are looking at a pragma that comes from an aspect then it
10155 -- needs to have its corresponding aspect argument expressions
10156 -- analyzed in addition to the generated pragma so that aspects
10157 -- within generic units get properly resolved.
10158
10159 if Present (Prag) and then From_Aspect_Specification (Prag) then
10160 declare
10161 Asp : constant Node_Id := Corresponding_Aspect (Prag);
10162 Dummy_1 : Node_Id;
10163 Dummy_2 : Node_Id;
10164 Dummy_3 : Node_Id;
10165 EN : Node_Id;
10166 LN : Node_Id;
10167
10168 begin
10169 -- Obtain all interfacing aspects used to construct the pragma
10170
10171 Get_Interfacing_Aspects
10172 (Asp, Dummy_1, EN, Dummy_2, Dummy_3, LN);
10173
10174 -- Analyze the expression of aspect External_Name
10175
10176 if Present (EN) then
10177 Analyze (Expression (EN));
10178 end if;
10179
10180 -- Analyze the expressio of aspect Link_Name
10181
10182 if Present (LN) then
10183 Analyze (Expression (LN));
10184 end if;
10185 end;
10186 end if;
10187
10188 if No (Link_Arg) then
10189 if No (Ext_Arg) then
10190 return;
10191
10192 elsif Chars (Ext_Arg) = Name_Link_Name then
10193 Ext_Nam := Empty;
10194 Link_Nam := Expression (Ext_Arg);
10195
10196 else
10197 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10198 Ext_Nam := Expression (Ext_Arg);
10199 Link_Nam := Empty;
10200 end if;
10201
10202 else
10203 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10204 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
10205 Ext_Nam := Expression (Ext_Arg);
10206 Link_Nam := Expression (Link_Arg);
10207 end if;
10208
10209 -- Check expressions for external name and link name are static
10210
10211 if Present (Ext_Nam) then
10212 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
10213 Check_Form_Of_Interface_Name (Ext_Nam);
10214
10215 -- Verify that external name is not the name of a local entity,
10216 -- which would hide the imported one and could lead to run-time
10217 -- surprises. The problem can only arise for entities declared in
10218 -- a package body (otherwise the external name is fully qualified
10219 -- and will not conflict).
10220
10221 declare
10222 Nam : Name_Id;
10223 E : Entity_Id;
10224 Par : Node_Id;
10225
10226 begin
10227 if Prag_Id = Pragma_Import then
10228 Nam := String_To_Name (Strval (Expr_Value_S (Ext_Nam)));
10229 E := Entity_Id (Get_Name_Table_Int (Nam));
10230
10231 if Nam /= Chars (Subprogram_Def)
10232 and then Present (E)
10233 and then not Is_Overloadable (E)
10234 and then Is_Immediately_Visible (E)
10235 and then not Is_Imported (E)
10236 and then Ekind (Scope (E)) = E_Package
10237 then
10238 Par := Parent (E);
10239 while Present (Par) loop
10240 if Nkind (Par) = N_Package_Body then
10241 Error_Msg_Sloc := Sloc (E);
10242 Error_Msg_NE
10243 ("imported entity is hidden by & declared#",
10244 Ext_Arg, E);
10245 exit;
10246 end if;
10247
10248 Par := Parent (Par);
10249 end loop;
10250 end if;
10251 end if;
10252 end;
10253 end if;
10254
10255 if Present (Link_Nam) then
10256 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
10257 Check_Form_Of_Interface_Name (Link_Nam);
10258 end if;
10259
10260 -- If there is no link name, just set the external name
10261
10262 if No (Link_Nam) then
10263 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
10264
10265 -- For the Link_Name case, the given literal is preceded by an
10266 -- asterisk, which indicates to GCC that the given name should be
10267 -- taken literally, and in particular that no prepending of
10268 -- underlines should occur, even in systems where this is the
10269 -- normal default.
10270
10271 else
10272 Start_String;
10273 Store_String_Char (Get_Char_Code ('*'));
10274 String_Val := Strval (Expr_Value_S (Link_Nam));
10275 Store_String_Chars (String_Val);
10276 Link_Nam :=
10277 Make_String_Literal (Sloc (Link_Nam),
10278 Strval => End_String);
10279 end if;
10280
10281 -- Set the interface name. If the entity is a generic instance, use
10282 -- its alias, which is the callable entity.
10283
10284 if Is_Generic_Instance (Subprogram_Def) then
10285 Set_Encoded_Interface_Name
10286 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
10287 else
10288 Set_Encoded_Interface_Name
10289 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
10290 end if;
10291
10292 Check_Duplicated_Export_Name (Link_Nam);
10293 end Process_Interface_Name;
10294
10295 -----------------------------------------
10296 -- Process_Interrupt_Or_Attach_Handler --
10297 -----------------------------------------
10298
10299 procedure Process_Interrupt_Or_Attach_Handler is
10300 Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
10301 Prot_Typ : constant Entity_Id := Scope (Handler);
10302
10303 begin
10304 -- A pragma that applies to a Ghost entity becomes Ghost for the
10305 -- purposes of legality checks and removal of ignored Ghost code.
10306
10307 Mark_Ghost_Pragma (N, Handler);
10308 Set_Is_Interrupt_Handler (Handler);
10309
10310 pragma Assert (Ekind (Prot_Typ) = E_Protected_Type);
10311
10312 Record_Rep_Item (Prot_Typ, N);
10313
10314 -- Chain the pragma on the contract for completeness
10315
10316 Add_Contract_Item (N, Handler);
10317 end Process_Interrupt_Or_Attach_Handler;
10318
10319 --------------------------------------------------
10320 -- Process_Restrictions_Or_Restriction_Warnings --
10321 --------------------------------------------------
10322
10323 -- Note: some of the simple identifier cases were handled in par-prag,
10324 -- but it is harmless (and more straightforward) to simply handle all
10325 -- cases here, even if it means we repeat a bit of work in some cases.
10326
10327 procedure Process_Restrictions_Or_Restriction_Warnings
10328 (Warn : Boolean)
10329 is
10330 Arg : Node_Id;
10331 R_Id : Restriction_Id;
10332 Id : Name_Id;
10333 Expr : Node_Id;
10334 Val : Uint;
10335
10336 begin
10337 -- Ignore all Restrictions pragmas in CodePeer mode
10338
10339 if CodePeer_Mode then
10340 return;
10341 end if;
10342
10343 Check_Ada_83_Warning;
10344 Check_At_Least_N_Arguments (1);
10345 Check_Valid_Configuration_Pragma;
10346
10347 Arg := Arg1;
10348 while Present (Arg) loop
10349 Id := Chars (Arg);
10350 Expr := Get_Pragma_Arg (Arg);
10351
10352 -- Case of no restriction identifier present
10353
10354 if Id = No_Name then
10355 if Nkind (Expr) /= N_Identifier then
10356 Error_Pragma_Arg
10357 ("invalid form for restriction", Arg);
10358 end if;
10359
10360 R_Id :=
10361 Get_Restriction_Id
10362 (Process_Restriction_Synonyms (Expr));
10363
10364 if R_Id not in All_Boolean_Restrictions then
10365 Error_Msg_Name_1 := Pname;
10366 Error_Msg_N
10367 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
10368
10369 -- Check for possible misspelling
10370
10371 for J in Restriction_Id loop
10372 declare
10373 Rnm : constant String := Restriction_Id'Image (J);
10374
10375 begin
10376 Name_Buffer (1 .. Rnm'Length) := Rnm;
10377 Name_Len := Rnm'Length;
10378 Set_Casing (All_Lower_Case);
10379
10380 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
10381 Set_Casing
10382 (Identifier_Casing
10383 (Source_Index (Current_Sem_Unit)));
10384 Error_Msg_String (1 .. Rnm'Length) :=
10385 Name_Buffer (1 .. Name_Len);
10386 Error_Msg_Strlen := Rnm'Length;
10387 Error_Msg_N -- CODEFIX
10388 ("\possible misspelling of ""~""",
10389 Get_Pragma_Arg (Arg));
10390 exit;
10391 end if;
10392 end;
10393 end loop;
10394
10395 raise Pragma_Exit;
10396 end if;
10397
10398 if Implementation_Restriction (R_Id) then
10399 Check_Restriction (No_Implementation_Restrictions, Arg);
10400 end if;
10401
10402 -- Special processing for No_Elaboration_Code restriction
10403
10404 if R_Id = No_Elaboration_Code then
10405
10406 -- Restriction is only recognized within a configuration
10407 -- pragma file, or within a unit of the main extended
10408 -- program. Note: the test for Main_Unit is needed to
10409 -- properly include the case of configuration pragma files.
10410
10411 if not (Current_Sem_Unit = Main_Unit
10412 or else In_Extended_Main_Source_Unit (N))
10413 then
10414 return;
10415
10416 -- Don't allow in a subunit unless already specified in
10417 -- body or spec.
10418
10419 elsif Nkind (Parent (N)) = N_Compilation_Unit
10420 and then Nkind (Unit (Parent (N))) = N_Subunit
10421 and then not Restriction_Active (No_Elaboration_Code)
10422 then
10423 Error_Msg_N
10424 ("invalid specification of ""No_Elaboration_Code""",
10425 N);
10426 Error_Msg_N
10427 ("\restriction cannot be specified in a subunit", N);
10428 Error_Msg_N
10429 ("\unless also specified in body or spec", N);
10430 return;
10431
10432 -- If we accept a No_Elaboration_Code restriction, then it
10433 -- needs to be added to the configuration restriction set so
10434 -- that we get proper application to other units in the main
10435 -- extended source as required.
10436
10437 else
10438 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
10439 end if;
10440
10441 -- Special processing for No_Tasking restriction (not just a
10442 -- warning) when it appears as a configuration pragma.
10443
10444 elsif R_Id = No_Tasking
10445 and then No (Cunit (Main_Unit))
10446 and then not Warn
10447 then
10448 Set_Global_No_Tasking;
10449 end if;
10450
10451 Set_Restriction (R_Id, N, Warn);
10452
10453 if R_Id = No_Dynamic_CPU_Assignment
10454 or else R_Id = No_Tasks_Unassigned_To_CPU
10455 then
10456 -- These imply No_Dependence =>
10457 -- "System.Multiprocessors.Dispatching_Domains".
10458 -- This is not strictly what the AI says, but it eliminates
10459 -- the need for run-time checks, which are undesirable in
10460 -- this context.
10461
10462 Set_Restriction_No_Dependence
10463 (Sel_Comp
10464 (Sel_Comp ("system", "multiprocessors", Loc),
10465 "dispatching_domains"),
10466 Warn);
10467 end if;
10468
10469 if R_Id = No_Tasks_Unassigned_To_CPU then
10470 -- Likewise, imply No_Dynamic_CPU_Assignment
10471
10472 Set_Restriction (No_Dynamic_CPU_Assignment, N, Warn);
10473 end if;
10474
10475 -- Check for obsolescent restrictions in Ada 2005 mode
10476
10477 if not Warn
10478 and then Ada_Version >= Ada_2005
10479 and then (R_Id = No_Asynchronous_Control
10480 or else
10481 R_Id = No_Unchecked_Deallocation
10482 or else
10483 R_Id = No_Unchecked_Conversion)
10484 then
10485 Check_Restriction (No_Obsolescent_Features, N);
10486 end if;
10487
10488 -- A very special case that must be processed here: pragma
10489 -- Restrictions (No_Exceptions) turns off all run-time
10490 -- checking. This is a bit dubious in terms of the formal
10491 -- language definition, but it is what is intended by RM
10492 -- H.4(12). Restriction_Warnings never affects generated code
10493 -- so this is done only in the real restriction case.
10494
10495 -- Atomic_Synchronization is not a real check, so it is not
10496 -- affected by this processing).
10497
10498 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
10499 -- run-time checks in CodePeer and GNATprove modes: we want to
10500 -- generate checks for analysis purposes, as set respectively
10501 -- by -gnatC and -gnatd.F
10502
10503 if not Warn
10504 and then not (CodePeer_Mode or GNATprove_Mode)
10505 and then R_Id = No_Exceptions
10506 then
10507 for J in Scope_Suppress.Suppress'Range loop
10508 if J /= Atomic_Synchronization then
10509 Scope_Suppress.Suppress (J) := True;
10510 end if;
10511 end loop;
10512 end if;
10513
10514 -- Case of No_Dependence => unit-name. Note that the parser
10515 -- already made the necessary entry in the No_Dependence table.
10516
10517 elsif Id = Name_No_Dependence then
10518 if not OK_No_Dependence_Unit_Name (Expr) then
10519 raise Pragma_Exit;
10520 end if;
10521
10522 -- Case of No_Specification_Of_Aspect => aspect-identifier
10523
10524 elsif Id = Name_No_Specification_Of_Aspect then
10525 declare
10526 A_Id : Aspect_Id;
10527
10528 begin
10529 if Nkind (Expr) /= N_Identifier then
10530 A_Id := No_Aspect;
10531 else
10532 A_Id := Get_Aspect_Id (Chars (Expr));
10533 end if;
10534
10535 if A_Id = No_Aspect then
10536 Error_Pragma_Arg ("invalid restriction name", Arg);
10537 else
10538 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
10539 end if;
10540 end;
10541
10542 -- Case of No_Use_Of_Attribute => attribute-identifier
10543
10544 elsif Id = Name_No_Use_Of_Attribute then
10545 if Nkind (Expr) /= N_Identifier
10546 or else not Is_Attribute_Name (Chars (Expr))
10547 then
10548 Error_Msg_N ("unknown attribute name??", Expr);
10549
10550 else
10551 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
10552 end if;
10553
10554 -- Case of No_Use_Of_Entity => fully-qualified-name
10555
10556 elsif Id = Name_No_Use_Of_Entity then
10557
10558 -- Restriction is only recognized within a configuration
10559 -- pragma file, or within a unit of the main extended
10560 -- program. Note: the test for Main_Unit is needed to
10561 -- properly include the case of configuration pragma files.
10562
10563 if Current_Sem_Unit = Main_Unit
10564 or else In_Extended_Main_Source_Unit (N)
10565 then
10566 if not OK_No_Dependence_Unit_Name (Expr) then
10567 Error_Msg_N ("wrong form for entity name", Expr);
10568 else
10569 Set_Restriction_No_Use_Of_Entity
10570 (Expr, Warn, No_Profile);
10571 end if;
10572 end if;
10573
10574 -- Case of No_Use_Of_Pragma => pragma-identifier
10575
10576 elsif Id = Name_No_Use_Of_Pragma then
10577 if Nkind (Expr) /= N_Identifier
10578 or else not Is_Pragma_Name (Chars (Expr))
10579 then
10580 Error_Msg_N ("unknown pragma name??", Expr);
10581 else
10582 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
10583 end if;
10584
10585 -- All other cases of restriction identifier present
10586
10587 else
10588 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
10589 Analyze_And_Resolve (Expr, Any_Integer);
10590
10591 if R_Id not in All_Parameter_Restrictions then
10592 Error_Pragma_Arg
10593 ("invalid restriction parameter identifier", Arg);
10594
10595 elsif not Is_OK_Static_Expression (Expr) then
10596 Flag_Non_Static_Expr
10597 ("value must be static expression!", Expr);
10598 raise Pragma_Exit;
10599
10600 elsif not Is_Integer_Type (Etype (Expr))
10601 or else Expr_Value (Expr) < 0
10602 then
10603 Error_Pragma_Arg
10604 ("value must be non-negative integer", Arg);
10605 end if;
10606
10607 -- Restriction pragma is active
10608
10609 Val := Expr_Value (Expr);
10610
10611 if not UI_Is_In_Int_Range (Val) then
10612 Error_Pragma_Arg
10613 ("pragma ignored, value too large??", Arg);
10614 end if;
10615
10616 Set_Restriction (R_Id, N, Warn, Integer (UI_To_Int (Val)));
10617 end if;
10618
10619 Next (Arg);
10620 end loop;
10621 end Process_Restrictions_Or_Restriction_Warnings;
10622
10623 ---------------------------------
10624 -- Process_Suppress_Unsuppress --
10625 ---------------------------------
10626
10627 -- Note: this procedure makes entries in the check suppress data
10628 -- structures managed by Sem. See spec of package Sem for full
10629 -- details on how we handle recording of check suppression.
10630
10631 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
10632 C : Check_Id;
10633 E : Entity_Id;
10634 E_Id : Node_Id;
10635
10636 In_Package_Spec : constant Boolean :=
10637 Is_Package_Or_Generic_Package (Current_Scope)
10638 and then not In_Package_Body (Current_Scope);
10639
10640 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
10641 -- Used to suppress a single check on the given entity
10642
10643 --------------------------------
10644 -- Suppress_Unsuppress_Echeck --
10645 --------------------------------
10646
10647 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
10648 begin
10649 -- Check for error of trying to set atomic synchronization for
10650 -- a non-atomic variable.
10651
10652 if C = Atomic_Synchronization
10653 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
10654 then
10655 Error_Msg_N
10656 ("pragma & requires atomic type or variable",
10657 Pragma_Identifier (Original_Node (N)));
10658 end if;
10659
10660 Set_Checks_May_Be_Suppressed (E);
10661
10662 if In_Package_Spec then
10663 Push_Global_Suppress_Stack_Entry
10664 (Entity => E,
10665 Check => C,
10666 Suppress => Suppress_Case);
10667 else
10668 Push_Local_Suppress_Stack_Entry
10669 (Entity => E,
10670 Check => C,
10671 Suppress => Suppress_Case);
10672 end if;
10673
10674 -- If this is a first subtype, and the base type is distinct,
10675 -- then also set the suppress flags on the base type.
10676
10677 if Is_First_Subtype (E) and then Etype (E) /= E then
10678 Suppress_Unsuppress_Echeck (Etype (E), C);
10679 end if;
10680 end Suppress_Unsuppress_Echeck;
10681
10682 -- Start of processing for Process_Suppress_Unsuppress
10683
10684 begin
10685 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
10686 -- on user code: we want to generate checks for analysis purposes, as
10687 -- set respectively by -gnatC and -gnatd.F
10688
10689 if Comes_From_Source (N)
10690 and then (CodePeer_Mode or GNATprove_Mode)
10691 then
10692 return;
10693 end if;
10694
10695 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
10696 -- declarative part or a package spec (RM 11.5(5)).
10697
10698 if not Is_Configuration_Pragma then
10699 Check_Is_In_Decl_Part_Or_Package_Spec;
10700 end if;
10701
10702 Check_At_Least_N_Arguments (1);
10703 Check_At_Most_N_Arguments (2);
10704 Check_No_Identifier (Arg1);
10705 Check_Arg_Is_Identifier (Arg1);
10706
10707 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
10708
10709 if C = No_Check_Id then
10710 Error_Pragma_Arg
10711 ("argument of pragma% is not valid check name", Arg1);
10712 end if;
10713
10714 -- Warn that suppress of Elaboration_Check has no effect in SPARK
10715
10716 if C = Elaboration_Check and then SPARK_Mode = On then
10717 Error_Pragma_Arg
10718 ("Suppress of Elaboration_Check ignored in SPARK??",
10719 "\elaboration checking rules are statically enforced "
10720 & "(SPARK RM 7.7)", Arg1);
10721 end if;
10722
10723 -- One-argument case
10724
10725 if Arg_Count = 1 then
10726
10727 -- Make an entry in the local scope suppress table. This is the
10728 -- table that directly shows the current value of the scope
10729 -- suppress check for any check id value.
10730
10731 if C = All_Checks then
10732
10733 -- For All_Checks, we set all specific predefined checks with
10734 -- the exception of Elaboration_Check, which is handled
10735 -- specially because of not wanting All_Checks to have the
10736 -- effect of deactivating static elaboration order processing.
10737 -- Atomic_Synchronization is also not affected, since this is
10738 -- not a real check.
10739
10740 for J in Scope_Suppress.Suppress'Range loop
10741 if J /= Elaboration_Check
10742 and then
10743 J /= Atomic_Synchronization
10744 then
10745 Scope_Suppress.Suppress (J) := Suppress_Case;
10746 end if;
10747 end loop;
10748
10749 -- If not All_Checks, and predefined check, then set appropriate
10750 -- scope entry. Note that we will set Elaboration_Check if this
10751 -- is explicitly specified. Atomic_Synchronization is allowed
10752 -- only if internally generated and entity is atomic.
10753
10754 elsif C in Predefined_Check_Id
10755 and then (not Comes_From_Source (N)
10756 or else C /= Atomic_Synchronization)
10757 then
10758 Scope_Suppress.Suppress (C) := Suppress_Case;
10759 end if;
10760
10761 -- Also make an entry in the Local_Entity_Suppress table
10762
10763 Push_Local_Suppress_Stack_Entry
10764 (Entity => Empty,
10765 Check => C,
10766 Suppress => Suppress_Case);
10767
10768 -- Case of two arguments present, where the check is suppressed for
10769 -- a specified entity (given as the second argument of the pragma)
10770
10771 else
10772 -- This is obsolescent in Ada 2005 mode
10773
10774 if Ada_Version >= Ada_2005 then
10775 Check_Restriction (No_Obsolescent_Features, Arg2);
10776 end if;
10777
10778 Check_Optional_Identifier (Arg2, Name_On);
10779 E_Id := Get_Pragma_Arg (Arg2);
10780 Analyze (E_Id);
10781
10782 if not Is_Entity_Name (E_Id) then
10783 Error_Pragma_Arg
10784 ("second argument of pragma% must be entity name", Arg2);
10785 end if;
10786
10787 E := Entity (E_Id);
10788
10789 if E = Any_Id then
10790 return;
10791 end if;
10792
10793 -- A pragma that applies to a Ghost entity becomes Ghost for the
10794 -- purposes of legality checks and removal of ignored Ghost code.
10795
10796 Mark_Ghost_Pragma (N, E);
10797
10798 -- Enforce RM 11.5(7) which requires that for a pragma that
10799 -- appears within a package spec, the named entity must be
10800 -- within the package spec. We allow the package name itself
10801 -- to be mentioned since that makes sense, although it is not
10802 -- strictly allowed by 11.5(7).
10803
10804 if In_Package_Spec
10805 and then E /= Current_Scope
10806 and then Scope (E) /= Current_Scope
10807 then
10808 Error_Pragma_Arg
10809 ("entity in pragma% is not in package spec (RM 11.5(7))",
10810 Arg2);
10811 end if;
10812
10813 -- Loop through homonyms. As noted below, in the case of a package
10814 -- spec, only homonyms within the package spec are considered.
10815
10816 loop
10817 Suppress_Unsuppress_Echeck (E, C);
10818
10819 if Is_Generic_Instance (E)
10820 and then Is_Subprogram (E)
10821 and then Present (Alias (E))
10822 then
10823 Suppress_Unsuppress_Echeck (Alias (E), C);
10824 end if;
10825
10826 -- Move to next homonym if not aspect spec case
10827
10828 exit when From_Aspect_Specification (N);
10829 E := Homonym (E);
10830 exit when No (E);
10831
10832 -- If we are within a package specification, the pragma only
10833 -- applies to homonyms in the same scope.
10834
10835 exit when In_Package_Spec
10836 and then Scope (E) /= Current_Scope;
10837 end loop;
10838 end if;
10839 end Process_Suppress_Unsuppress;
10840
10841 -------------------------------
10842 -- Record_Independence_Check --
10843 -------------------------------
10844
10845 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
10846 pragma Unreferenced (N, E);
10847 begin
10848 -- For GCC back ends the validation is done a priori
10849 -- ??? This code is dead, might be useful in the future
10850
10851 -- if not AAMP_On_Target then
10852 -- return;
10853 -- end if;
10854
10855 -- Independence_Checks.Append ((N, E));
10856
10857 return;
10858 end Record_Independence_Check;
10859
10860 ------------------
10861 -- Set_Exported --
10862 ------------------
10863
10864 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
10865 begin
10866 if Is_Imported (E) then
10867 Error_Pragma_Arg
10868 ("cannot export entity& that was previously imported", Arg);
10869
10870 elsif Present (Address_Clause (E))
10871 and then not Relaxed_RM_Semantics
10872 then
10873 Error_Pragma_Arg
10874 ("cannot export entity& that has an address clause", Arg);
10875 end if;
10876
10877 Set_Is_Exported (E);
10878
10879 -- Generate a reference for entity explicitly, because the
10880 -- identifier may be overloaded and name resolution will not
10881 -- generate one.
10882
10883 Generate_Reference (E, Arg);
10884
10885 -- Deal with exporting non-library level entity
10886
10887 if not Is_Library_Level_Entity (E) then
10888
10889 -- Not allowed at all for subprograms
10890
10891 if Is_Subprogram (E) then
10892 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
10893
10894 -- Otherwise set public and statically allocated
10895
10896 else
10897 Set_Is_Public (E);
10898 Set_Is_Statically_Allocated (E);
10899
10900 -- Warn if the corresponding W flag is set
10901
10902 if Warn_On_Export_Import
10903
10904 -- Only do this for something that was in the source. Not
10905 -- clear if this can be False now (there used for sure to be
10906 -- cases on some systems where it was False), but anyway the
10907 -- test is harmless if not needed, so it is retained.
10908
10909 and then Comes_From_Source (Arg)
10910 then
10911 Error_Msg_NE
10912 ("?x?& has been made static as a result of Export",
10913 Arg, E);
10914 Error_Msg_N
10915 ("\?x?this usage is non-standard and non-portable",
10916 Arg);
10917 end if;
10918 end if;
10919 end if;
10920
10921 if Warn_On_Export_Import and then Is_Type (E) then
10922 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
10923 end if;
10924
10925 if Warn_On_Export_Import and Inside_A_Generic then
10926 Error_Msg_NE
10927 ("all instances of& will have the same external name?x?",
10928 Arg, E);
10929 end if;
10930 end Set_Exported;
10931
10932 ----------------------------------------------
10933 -- Set_Extended_Import_Export_External_Name --
10934 ----------------------------------------------
10935
10936 procedure Set_Extended_Import_Export_External_Name
10937 (Internal_Ent : Entity_Id;
10938 Arg_External : Node_Id)
10939 is
10940 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
10941 New_Name : Node_Id;
10942
10943 begin
10944 if No (Arg_External) then
10945 return;
10946 end if;
10947
10948 Check_Arg_Is_External_Name (Arg_External);
10949
10950 if Nkind (Arg_External) = N_String_Literal then
10951 if String_Length (Strval (Arg_External)) = 0 then
10952 return;
10953 else
10954 New_Name := Adjust_External_Name_Case (Arg_External);
10955 end if;
10956
10957 elsif Nkind (Arg_External) = N_Identifier then
10958 New_Name := Get_Default_External_Name (Arg_External);
10959
10960 -- Check_Arg_Is_External_Name should let through only identifiers and
10961 -- string literals or static string expressions (which are folded to
10962 -- string literals).
10963
10964 else
10965 raise Program_Error;
10966 end if;
10967
10968 -- If we already have an external name set (by a prior normal Import
10969 -- or Export pragma), then the external names must match
10970
10971 if Present (Interface_Name (Internal_Ent)) then
10972
10973 -- Ignore mismatching names in CodePeer mode, to support some
10974 -- old compilers which would export the same procedure under
10975 -- different names, e.g:
10976 -- procedure P;
10977 -- pragma Export_Procedure (P, "a");
10978 -- pragma Export_Procedure (P, "b");
10979
10980 if CodePeer_Mode then
10981 return;
10982 end if;
10983
10984 Check_Matching_Internal_Names : declare
10985 S1 : constant String_Id := Strval (Old_Name);
10986 S2 : constant String_Id := Strval (New_Name);
10987
10988 procedure Mismatch;
10989 pragma No_Return (Mismatch);
10990 -- Called if names do not match
10991
10992 --------------
10993 -- Mismatch --
10994 --------------
10995
10996 procedure Mismatch is
10997 begin
10998 Error_Msg_Sloc := Sloc (Old_Name);
10999 Error_Pragma_Arg
11000 ("external name does not match that given #",
11001 Arg_External);
11002 end Mismatch;
11003
11004 -- Start of processing for Check_Matching_Internal_Names
11005
11006 begin
11007 if String_Length (S1) /= String_Length (S2) then
11008 Mismatch;
11009
11010 else
11011 for J in 1 .. String_Length (S1) loop
11012 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
11013 Mismatch;
11014 end if;
11015 end loop;
11016 end if;
11017 end Check_Matching_Internal_Names;
11018
11019 -- Otherwise set the given name
11020
11021 else
11022 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
11023 Check_Duplicated_Export_Name (New_Name);
11024 end if;
11025 end Set_Extended_Import_Export_External_Name;
11026
11027 ------------------
11028 -- Set_Imported --
11029 ------------------
11030
11031 procedure Set_Imported (E : Entity_Id) is
11032 begin
11033 -- Error message if already imported or exported
11034
11035 if Is_Exported (E) or else Is_Imported (E) then
11036
11037 -- Error if being set Exported twice
11038
11039 if Is_Exported (E) then
11040 Error_Msg_NE ("entity& was previously exported", N, E);
11041
11042 -- Ignore error in CodePeer mode where we treat all imported
11043 -- subprograms as unknown.
11044
11045 elsif CodePeer_Mode then
11046 goto OK;
11047
11048 -- OK if Import/Interface case
11049
11050 elsif Import_Interface_Present (N) then
11051 goto OK;
11052
11053 -- Error if being set Imported twice
11054
11055 else
11056 Error_Msg_NE ("entity& was previously imported", N, E);
11057 end if;
11058
11059 Error_Msg_Name_1 := Pname;
11060 Error_Msg_N
11061 ("\(pragma% applies to all previous entities)", N);
11062
11063 Error_Msg_Sloc := Sloc (E);
11064 Error_Msg_NE ("\import not allowed for& declared#", N, E);
11065
11066 -- Here if not previously imported or exported, OK to import
11067
11068 else
11069 Set_Is_Imported (E);
11070
11071 -- For subprogram, set Import_Pragma field
11072
11073 if Is_Subprogram (E) then
11074 Set_Import_Pragma (E, N);
11075 end if;
11076
11077 -- If the entity is an object that is not at the library level,
11078 -- then it is statically allocated. We do not worry about objects
11079 -- with address clauses in this context since they are not really
11080 -- imported in the linker sense.
11081
11082 if Is_Object (E)
11083 and then not Is_Library_Level_Entity (E)
11084 and then No (Address_Clause (E))
11085 then
11086 Set_Is_Statically_Allocated (E);
11087 end if;
11088 end if;
11089
11090 <<OK>> null;
11091 end Set_Imported;
11092
11093 -------------------------
11094 -- Set_Mechanism_Value --
11095 -------------------------
11096
11097 -- Note: the mechanism name has not been analyzed (and cannot indeed be
11098 -- analyzed, since it is semantic nonsense), so we get it in the exact
11099 -- form created by the parser.
11100
11101 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
11102 procedure Bad_Mechanism;
11103 pragma No_Return (Bad_Mechanism);
11104 -- Signal bad mechanism name
11105
11106 -------------------
11107 -- Bad_Mechanism --
11108 -------------------
11109
11110 procedure Bad_Mechanism is
11111 begin
11112 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
11113 end Bad_Mechanism;
11114
11115 -- Start of processing for Set_Mechanism_Value
11116
11117 begin
11118 if Mechanism (Ent) /= Default_Mechanism then
11119 Error_Msg_NE
11120 ("mechanism for & has already been set", Mech_Name, Ent);
11121 end if;
11122
11123 -- MECHANISM_NAME ::= value | reference
11124
11125 if Nkind (Mech_Name) = N_Identifier then
11126 if Chars (Mech_Name) = Name_Value then
11127 Set_Mechanism (Ent, By_Copy);
11128 return;
11129
11130 elsif Chars (Mech_Name) = Name_Reference then
11131 Set_Mechanism (Ent, By_Reference);
11132 return;
11133
11134 elsif Chars (Mech_Name) = Name_Copy then
11135 Error_Pragma_Arg
11136 ("bad mechanism name, Value assumed", Mech_Name);
11137
11138 else
11139 Bad_Mechanism;
11140 end if;
11141
11142 else
11143 Bad_Mechanism;
11144 end if;
11145 end Set_Mechanism_Value;
11146
11147 --------------------------
11148 -- Set_Rational_Profile --
11149 --------------------------
11150
11151 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
11152 -- extension to the semantics of renaming declarations.
11153
11154 procedure Set_Rational_Profile is
11155 begin
11156 Implicit_Packing := True;
11157 Overriding_Renamings := True;
11158 Use_VADS_Size := True;
11159 end Set_Rational_Profile;
11160
11161 ---------------------------
11162 -- Set_Ravenscar_Profile --
11163 ---------------------------
11164
11165 -- The tasks to be done here are
11166
11167 -- Set required policies
11168
11169 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11170 -- (For Ravenscar, Jorvik, and GNAT_Extended_Ravenscar profiles)
11171 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11172 -- (For GNAT_Ravenscar_EDF profile)
11173 -- pragma Locking_Policy (Ceiling_Locking)
11174
11175 -- Set Detect_Blocking mode
11176
11177 -- Set required restrictions (see System.Rident for detailed list)
11178
11179 -- Set the No_Dependence rules
11180 -- No_Dependence => Ada.Asynchronous_Task_Control
11181 -- No_Dependence => Ada.Calendar
11182 -- No_Dependence => Ada.Execution_Time.Group_Budget
11183 -- No_Dependence => Ada.Execution_Time.Timers
11184 -- No_Dependence => Ada.Task_Attributes
11185 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11186
11187 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is
11188 procedure Set_Error_Msg_To_Profile_Name;
11189 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
11190 -- profile.
11191
11192 -----------------------------------
11193 -- Set_Error_Msg_To_Profile_Name --
11194 -----------------------------------
11195
11196 procedure Set_Error_Msg_To_Profile_Name is
11197 Prof_Nam : constant Node_Id :=
11198 Get_Pragma_Arg
11199 (First (Pragma_Argument_Associations (N)));
11200
11201 begin
11202 Get_Name_String (Chars (Prof_Nam));
11203 Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam));
11204 Error_Msg_Strlen := Name_Len;
11205 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
11206 end Set_Error_Msg_To_Profile_Name;
11207
11208 Profile_Dispatching_Policy : Character;
11209
11210 -- Start of processing for Set_Ravenscar_Profile
11211
11212 begin
11213 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11214
11215 if Profile = GNAT_Ravenscar_EDF then
11216 Profile_Dispatching_Policy := 'E';
11217
11218 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11219
11220 else
11221 Profile_Dispatching_Policy := 'F';
11222 end if;
11223
11224 if Task_Dispatching_Policy /= ' '
11225 and then Task_Dispatching_Policy /= Profile_Dispatching_Policy
11226 then
11227 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11228 Set_Error_Msg_To_Profile_Name;
11229 Error_Pragma ("Profile (~) incompatible with policy#");
11230
11231 -- Set the FIFO_Within_Priorities policy, but always preserve
11232 -- System_Location since we like the error message with the run time
11233 -- name.
11234
11235 else
11236 Task_Dispatching_Policy := Profile_Dispatching_Policy;
11237
11238 if Task_Dispatching_Policy_Sloc /= System_Location then
11239 Task_Dispatching_Policy_Sloc := Loc;
11240 end if;
11241 end if;
11242
11243 -- pragma Locking_Policy (Ceiling_Locking)
11244
11245 if Locking_Policy /= ' '
11246 and then Locking_Policy /= 'C'
11247 then
11248 Error_Msg_Sloc := Locking_Policy_Sloc;
11249 Set_Error_Msg_To_Profile_Name;
11250 Error_Pragma ("Profile (~) incompatible with policy#");
11251
11252 -- Set the Ceiling_Locking policy, but preserve System_Location since
11253 -- we like the error message with the run time name.
11254
11255 else
11256 Locking_Policy := 'C';
11257
11258 if Locking_Policy_Sloc /= System_Location then
11259 Locking_Policy_Sloc := Loc;
11260 end if;
11261 end if;
11262
11263 -- pragma Detect_Blocking
11264
11265 Detect_Blocking := True;
11266
11267 -- Set the corresponding restrictions
11268
11269 Set_Profile_Restrictions
11270 (Profile, N, Warn => Treat_Restrictions_As_Warnings);
11271
11272 -- Set the No_Dependence restrictions
11273
11274 -- The following No_Dependence restrictions:
11275 -- No_Dependence => Ada.Asynchronous_Task_Control
11276 -- No_Dependence => Ada.Calendar
11277 -- No_Dependence => Ada.Task_Attributes
11278 -- are already set by previous call to Set_Profile_Restrictions.
11279 -- Really???
11280
11281 -- Set the following restrictions which were added to Ada 2005:
11282 -- No_Dependence => Ada.Execution_Time.Group_Budget
11283 -- No_Dependence => Ada.Execution_Time.Timers
11284
11285 if Ada_Version >= Ada_2005 then
11286 declare
11287 Execution_Time : constant Node_Id :=
11288 Sel_Comp ("ada", "execution_time", Loc);
11289 Group_Budgets : constant Node_Id :=
11290 Sel_Comp (Execution_Time, "group_budgets");
11291 Timers : constant Node_Id :=
11292 Sel_Comp (Execution_Time, "timers");
11293 begin
11294 Set_Restriction_No_Dependence
11295 (Unit => Group_Budgets,
11296 Warn => Treat_Restrictions_As_Warnings,
11297 Profile => Ravenscar);
11298 Set_Restriction_No_Dependence
11299 (Unit => Timers,
11300 Warn => Treat_Restrictions_As_Warnings,
11301 Profile => Ravenscar);
11302 end;
11303 end if;
11304
11305 -- Set the following restriction which was added to Ada 2012 (see
11306 -- AI05-0171):
11307 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11308
11309 if Ada_Version >= Ada_2012 then
11310 Set_Restriction_No_Dependence
11311 (Sel_Comp
11312 (Sel_Comp ("system", "multiprocessors", Loc),
11313 "dispatching_domains"),
11314 Warn => Treat_Restrictions_As_Warnings,
11315 Profile => Ravenscar);
11316
11317 -- Set the following restriction which was added to Ada 2020,
11318 -- but as a binding interpretation:
11319 -- No_Dependence => Ada.Synchronous_Barriers
11320 -- for Ravenscar (and therefore for Ravenscar variants) but not
11321 -- for Jorvik. The unit Ada.Synchronous_Barriers was introduced
11322 -- in Ada2012 (AI05-0174).
11323
11324 if Profile /= Jorvik then
11325 Set_Restriction_No_Dependence
11326 (Sel_Comp ("ada", "synchronous_barriers", Loc),
11327 Warn => Treat_Restrictions_As_Warnings,
11328 Profile => Ravenscar);
11329 end if;
11330 end if;
11331
11332 end Set_Ravenscar_Profile;
11333
11334 -- Start of processing for Analyze_Pragma
11335
11336 begin
11337 -- The following code is a defense against recursion. Not clear that
11338 -- this can happen legitimately, but perhaps some error situations can
11339 -- cause it, and we did see this recursion during testing.
11340
11341 if Analyzed (N) then
11342 return;
11343 else
11344 Set_Analyzed (N);
11345 end if;
11346
11347 Check_Restriction_No_Use_Of_Pragma (N);
11348
11349 if Get_Aspect_Id (Chars (Pragma_Identifier (N))) /= No_Aspect then
11350 -- 6.1/3 No_Specification_of_Aspect: Identifies an aspect for which
11351 -- no aspect_specification, attribute_definition_clause, or pragma
11352 -- is given.
11353 Check_Restriction_No_Specification_Of_Aspect (N);
11354 end if;
11355
11356 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
11357 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
11358
11359 if Should_Ignore_Pragma_Sem (N)
11360 or else (Prag_Id = Pragma_Default_Scalar_Storage_Order
11361 and then Ignore_Rep_Clauses)
11362 then
11363 return;
11364 end if;
11365
11366 -- Deal with unrecognized pragma
11367
11368 if not Is_Pragma_Name (Pname) then
11369 declare
11370 Msg_Issued : Boolean := False;
11371 begin
11372 Check_Restriction
11373 (Msg_Issued, No_Unrecognized_Pragmas, Pragma_Identifier (N));
11374 if not Msg_Issued and then Warn_On_Unrecognized_Pragma then
11375 Error_Msg_Name_1 := Pname;
11376 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
11377
11378 for PN in First_Pragma_Name .. Last_Pragma_Name loop
11379 if Is_Bad_Spelling_Of (Pname, PN) then
11380 Error_Msg_Name_1 := PN;
11381 Error_Msg_N -- CODEFIX
11382 ("\?g?possible misspelling of %!",
11383 Pragma_Identifier (N));
11384 exit;
11385 end if;
11386 end loop;
11387 end if;
11388 end;
11389
11390 return;
11391 end if;
11392
11393 -- Here to start processing for recognized pragma
11394
11395 Pname := Original_Aspect_Pragma_Name (N);
11396
11397 -- Capture setting of Opt.Uneval_Old
11398
11399 case Opt.Uneval_Old is
11400 when 'A' =>
11401 Set_Uneval_Old_Accept (N);
11402
11403 when 'E' =>
11404 null;
11405
11406 when 'W' =>
11407 Set_Uneval_Old_Warn (N);
11408
11409 when others =>
11410 raise Program_Error;
11411 end case;
11412
11413 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
11414 -- is already set, indicating that we have already checked the policy
11415 -- at the right point. This happens for example in the case of a pragma
11416 -- that is derived from an Aspect.
11417
11418 if Is_Ignored (N) or else Is_Checked (N) then
11419 null;
11420
11421 -- For a pragma that is a rewriting of another pragma, copy the
11422 -- Is_Checked/Is_Ignored status from the rewritten pragma.
11423
11424 elsif Is_Rewrite_Substitution (N)
11425 and then Nkind (Original_Node (N)) = N_Pragma
11426 then
11427 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
11428 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
11429
11430 -- Otherwise query the applicable policy at this point
11431
11432 else
11433 Check_Applicable_Policy (N);
11434
11435 -- If pragma is disabled, rewrite as NULL and skip analysis
11436
11437 if Is_Disabled (N) then
11438 Rewrite (N, Make_Null_Statement (Loc));
11439 Analyze (N);
11440 raise Pragma_Exit;
11441 end if;
11442 end if;
11443
11444 -- Mark assertion pragmas as Ghost depending on their enclosing context
11445
11446 if Assertion_Expression_Pragma (Prag_Id) then
11447 Mark_Ghost_Pragma (N, Current_Scope);
11448 end if;
11449
11450 -- Preset arguments
11451
11452 Arg_Count := 0;
11453 Arg1 := Empty;
11454 Arg2 := Empty;
11455 Arg3 := Empty;
11456 Arg4 := Empty;
11457 Arg5 := Empty;
11458
11459 if Present (Pragma_Argument_Associations (N)) then
11460 Arg_Count := List_Length (Pragma_Argument_Associations (N));
11461 Arg1 := First (Pragma_Argument_Associations (N));
11462
11463 if Present (Arg1) then
11464 Arg2 := Next (Arg1);
11465
11466 if Present (Arg2) then
11467 Arg3 := Next (Arg2);
11468
11469 if Present (Arg3) then
11470 Arg4 := Next (Arg3);
11471
11472 if Present (Arg4) then
11473 Arg5 := Next (Arg4);
11474 end if;
11475 end if;
11476 end if;
11477 end if;
11478 end if;
11479
11480 -- An enumeration type defines the pragmas that are supported by the
11481 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
11482 -- into the corresponding enumeration value for the following case.
11483
11484 case Prag_Id is
11485
11486 -----------------
11487 -- Abort_Defer --
11488 -----------------
11489
11490 -- pragma Abort_Defer;
11491
11492 when Pragma_Abort_Defer =>
11493 GNAT_Pragma;
11494 Check_Arg_Count (0);
11495
11496 -- The only required semantic processing is to check the
11497 -- placement. This pragma must appear at the start of the
11498 -- statement sequence of a handled sequence of statements.
11499
11500 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
11501 or else N /= First (Statements (Parent (N)))
11502 then
11503 Pragma_Misplaced;
11504 end if;
11505
11506 --------------------
11507 -- Abstract_State --
11508 --------------------
11509
11510 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
11511
11512 -- ABSTRACT_STATE_LIST ::=
11513 -- null
11514 -- | STATE_NAME_WITH_OPTIONS
11515 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
11516
11517 -- STATE_NAME_WITH_OPTIONS ::=
11518 -- STATE_NAME
11519 -- | (STATE_NAME with OPTION_LIST)
11520
11521 -- OPTION_LIST ::= OPTION {, OPTION}
11522
11523 -- OPTION ::=
11524 -- SIMPLE_OPTION
11525 -- | NAME_VALUE_OPTION
11526
11527 -- SIMPLE_OPTION ::= Ghost | Relaxed_Initialization | Synchronous
11528
11529 -- NAME_VALUE_OPTION ::=
11530 -- Part_Of => ABSTRACT_STATE
11531 -- | External [=> EXTERNAL_PROPERTY_LIST]
11532
11533 -- EXTERNAL_PROPERTY_LIST ::=
11534 -- EXTERNAL_PROPERTY
11535 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
11536
11537 -- EXTERNAL_PROPERTY ::=
11538 -- Async_Readers [=> boolean_EXPRESSION]
11539 -- | Async_Writers [=> boolean_EXPRESSION]
11540 -- | Effective_Reads [=> boolean_EXPRESSION]
11541 -- | Effective_Writes [=> boolean_EXPRESSION]
11542 -- others => boolean_EXPRESSION
11543
11544 -- STATE_NAME ::= defining_identifier
11545
11546 -- ABSTRACT_STATE ::= name
11547
11548 -- Characteristics:
11549
11550 -- * Analysis - The annotation is fully analyzed immediately upon
11551 -- elaboration as it cannot forward reference entities.
11552
11553 -- * Expansion - None.
11554
11555 -- * Template - The annotation utilizes the generic template of the
11556 -- related package declaration.
11557
11558 -- * Globals - The annotation cannot reference global entities.
11559
11560 -- * Instance - The annotation is instantiated automatically when
11561 -- the related generic package is instantiated.
11562
11563 when Pragma_Abstract_State => Abstract_State : declare
11564 Missing_Parentheses : Boolean := False;
11565 -- Flag set when a state declaration with options is not properly
11566 -- parenthesized.
11567
11568 -- Flags used to verify the consistency of states
11569
11570 Non_Null_Seen : Boolean := False;
11571 Null_Seen : Boolean := False;
11572
11573 procedure Analyze_Abstract_State
11574 (State : Node_Id;
11575 Pack_Id : Entity_Id);
11576 -- Verify the legality of a single state declaration. Create and
11577 -- decorate a state abstraction entity and introduce it into the
11578 -- visibility chain. Pack_Id denotes the entity or the related
11579 -- package where pragma Abstract_State appears.
11580
11581 procedure Malformed_State_Error (State : Node_Id);
11582 -- Emit an error concerning the illegal declaration of abstract
11583 -- state State. This routine diagnoses syntax errors that lead to
11584 -- a different parse tree. The error is issued regardless of the
11585 -- SPARK mode in effect.
11586
11587 ----------------------------
11588 -- Analyze_Abstract_State --
11589 ----------------------------
11590
11591 procedure Analyze_Abstract_State
11592 (State : Node_Id;
11593 Pack_Id : Entity_Id)
11594 is
11595 -- Flags used to verify the consistency of options
11596
11597 AR_Seen : Boolean := False;
11598 AW_Seen : Boolean := False;
11599 ER_Seen : Boolean := False;
11600 EW_Seen : Boolean := False;
11601 External_Seen : Boolean := False;
11602 Ghost_Seen : Boolean := False;
11603 Others_Seen : Boolean := False;
11604 Part_Of_Seen : Boolean := False;
11605 Relaxed_Initialization_Seen : Boolean := False;
11606 Synchronous_Seen : Boolean := False;
11607
11608 -- Flags used to store the static value of all external states'
11609 -- expressions.
11610
11611 AR_Val : Boolean := False;
11612 AW_Val : Boolean := False;
11613 ER_Val : Boolean := False;
11614 EW_Val : Boolean := False;
11615
11616 State_Id : Entity_Id := Empty;
11617 -- The entity to be generated for the current state declaration
11618
11619 procedure Analyze_External_Option (Opt : Node_Id);
11620 -- Verify the legality of option External
11621
11622 procedure Analyze_External_Property
11623 (Prop : Node_Id;
11624 Expr : Node_Id := Empty);
11625 -- Verify the legailty of a single external property. Prop
11626 -- denotes the external property. Expr is the expression used
11627 -- to set the property.
11628
11629 procedure Analyze_Part_Of_Option (Opt : Node_Id);
11630 -- Verify the legality of option Part_Of
11631
11632 procedure Check_Duplicate_Option
11633 (Opt : Node_Id;
11634 Status : in out Boolean);
11635 -- Flag Status denotes whether a particular option has been
11636 -- seen while processing a state. This routine verifies that
11637 -- Opt is not a duplicate option and sets the flag Status
11638 -- (SPARK RM 7.1.4(1)).
11639
11640 procedure Check_Duplicate_Property
11641 (Prop : Node_Id;
11642 Status : in out Boolean);
11643 -- Flag Status denotes whether a particular property has been
11644 -- seen while processing option External. This routine verifies
11645 -- that Prop is not a duplicate property and sets flag Status.
11646 -- Opt is not a duplicate property and sets the flag Status.
11647 -- (SPARK RM 7.1.4(2))
11648
11649 procedure Check_Ghost_Synchronous;
11650 -- Ensure that the abstract state is not subject to both Ghost
11651 -- and Synchronous simple options. Emit an error if this is the
11652 -- case.
11653
11654 procedure Create_Abstract_State
11655 (Nam : Name_Id;
11656 Decl : Node_Id;
11657 Loc : Source_Ptr;
11658 Is_Null : Boolean);
11659 -- Generate an abstract state entity with name Nam and enter it
11660 -- into visibility. Decl is the "declaration" of the state as
11661 -- it appears in pragma Abstract_State. Loc is the location of
11662 -- the related state "declaration". Flag Is_Null should be set
11663 -- when the associated Abstract_State pragma defines a null
11664 -- state.
11665
11666 -----------------------------
11667 -- Analyze_External_Option --
11668 -----------------------------
11669
11670 procedure Analyze_External_Option (Opt : Node_Id) is
11671 Errors : constant Nat := Serious_Errors_Detected;
11672 Prop : Node_Id;
11673 Props : Node_Id := Empty;
11674
11675 begin
11676 if Nkind (Opt) = N_Component_Association then
11677 Props := Expression (Opt);
11678 end if;
11679
11680 -- External state with properties
11681
11682 if Present (Props) then
11683
11684 -- Multiple properties appear as an aggregate
11685
11686 if Nkind (Props) = N_Aggregate then
11687
11688 -- Simple property form
11689
11690 Prop := First (Expressions (Props));
11691 while Present (Prop) loop
11692 Analyze_External_Property (Prop);
11693 Next (Prop);
11694 end loop;
11695
11696 -- Property with expression form
11697
11698 Prop := First (Component_Associations (Props));
11699 while Present (Prop) loop
11700 Analyze_External_Property
11701 (Prop => First (Choices (Prop)),
11702 Expr => Expression (Prop));
11703
11704 Next (Prop);
11705 end loop;
11706
11707 -- Single property
11708
11709 else
11710 Analyze_External_Property (Props);
11711 end if;
11712
11713 -- An external state defined without any properties defaults
11714 -- all properties to True.
11715
11716 else
11717 AR_Val := True;
11718 AW_Val := True;
11719 ER_Val := True;
11720 EW_Val := True;
11721 end if;
11722
11723 -- Once all external properties have been processed, verify
11724 -- their mutual interaction. Do not perform the check when
11725 -- at least one of the properties is illegal as this will
11726 -- produce a bogus error.
11727
11728 if Errors = Serious_Errors_Detected then
11729 Check_External_Properties
11730 (State, AR_Val, AW_Val, ER_Val, EW_Val);
11731 end if;
11732 end Analyze_External_Option;
11733
11734 -------------------------------
11735 -- Analyze_External_Property --
11736 -------------------------------
11737
11738 procedure Analyze_External_Property
11739 (Prop : Node_Id;
11740 Expr : Node_Id := Empty)
11741 is
11742 Expr_Val : Boolean;
11743
11744 begin
11745 -- Check the placement of "others" (if available)
11746
11747 if Nkind (Prop) = N_Others_Choice then
11748 if Others_Seen then
11749 SPARK_Msg_N
11750 ("only one others choice allowed in option External",
11751 Prop);
11752 else
11753 Others_Seen := True;
11754 end if;
11755
11756 elsif Others_Seen then
11757 SPARK_Msg_N
11758 ("others must be the last property in option External",
11759 Prop);
11760
11761 -- The only remaining legal options are the four predefined
11762 -- external properties.
11763
11764 elsif Nkind (Prop) = N_Identifier
11765 and then Chars (Prop) in Name_Async_Readers
11766 | Name_Async_Writers
11767 | Name_Effective_Reads
11768 | Name_Effective_Writes
11769 then
11770 null;
11771
11772 -- Otherwise the construct is not a valid property
11773
11774 else
11775 SPARK_Msg_N ("invalid external state property", Prop);
11776 return;
11777 end if;
11778
11779 -- Ensure that the expression of the external state property
11780 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
11781
11782 if Present (Expr) then
11783 Analyze_And_Resolve (Expr, Standard_Boolean);
11784
11785 if Is_OK_Static_Expression (Expr) then
11786 Expr_Val := Is_True (Expr_Value (Expr));
11787 else
11788 SPARK_Msg_N
11789 ("expression of external state property must be "
11790 & "static", Expr);
11791 return;
11792 end if;
11793
11794 -- The lack of expression defaults the property to True
11795
11796 else
11797 Expr_Val := True;
11798 end if;
11799
11800 -- Named properties
11801
11802 if Nkind (Prop) = N_Identifier then
11803 if Chars (Prop) = Name_Async_Readers then
11804 Check_Duplicate_Property (Prop, AR_Seen);
11805 AR_Val := Expr_Val;
11806
11807 elsif Chars (Prop) = Name_Async_Writers then
11808 Check_Duplicate_Property (Prop, AW_Seen);
11809 AW_Val := Expr_Val;
11810
11811 elsif Chars (Prop) = Name_Effective_Reads then
11812 Check_Duplicate_Property (Prop, ER_Seen);
11813 ER_Val := Expr_Val;
11814
11815 else
11816 Check_Duplicate_Property (Prop, EW_Seen);
11817 EW_Val := Expr_Val;
11818 end if;
11819
11820 -- The handling of property "others" must take into account
11821 -- all other named properties that have been encountered so
11822 -- far. Only those that have not been seen are affected by
11823 -- "others".
11824
11825 else
11826 if not AR_Seen then
11827 AR_Val := Expr_Val;
11828 end if;
11829
11830 if not AW_Seen then
11831 AW_Val := Expr_Val;
11832 end if;
11833
11834 if not ER_Seen then
11835 ER_Val := Expr_Val;
11836 end if;
11837
11838 if not EW_Seen then
11839 EW_Val := Expr_Val;
11840 end if;
11841 end if;
11842 end Analyze_External_Property;
11843
11844 ----------------------------
11845 -- Analyze_Part_Of_Option --
11846 ----------------------------
11847
11848 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
11849 Encap : constant Node_Id := Expression (Opt);
11850 Constits : Elist_Id;
11851 Encap_Id : Entity_Id;
11852 Legal : Boolean;
11853
11854 begin
11855 Check_Duplicate_Option (Opt, Part_Of_Seen);
11856
11857 Analyze_Part_Of
11858 (Indic => First (Choices (Opt)),
11859 Item_Id => State_Id,
11860 Encap => Encap,
11861 Encap_Id => Encap_Id,
11862 Legal => Legal);
11863
11864 -- The Part_Of indicator transforms the abstract state into
11865 -- a constituent of the encapsulating state or single
11866 -- concurrent type.
11867
11868 if Legal then
11869 pragma Assert (Present (Encap_Id));
11870 Constits := Part_Of_Constituents (Encap_Id);
11871
11872 if No (Constits) then
11873 Constits := New_Elmt_List;
11874 Set_Part_Of_Constituents (Encap_Id, Constits);
11875 end if;
11876
11877 Append_Elmt (State_Id, Constits);
11878 Set_Encapsulating_State (State_Id, Encap_Id);
11879 end if;
11880 end Analyze_Part_Of_Option;
11881
11882 ----------------------------
11883 -- Check_Duplicate_Option --
11884 ----------------------------
11885
11886 procedure Check_Duplicate_Option
11887 (Opt : Node_Id;
11888 Status : in out Boolean)
11889 is
11890 begin
11891 if Status then
11892 SPARK_Msg_N ("duplicate state option", Opt);
11893 end if;
11894
11895 Status := True;
11896 end Check_Duplicate_Option;
11897
11898 ------------------------------
11899 -- Check_Duplicate_Property --
11900 ------------------------------
11901
11902 procedure Check_Duplicate_Property
11903 (Prop : Node_Id;
11904 Status : in out Boolean)
11905 is
11906 begin
11907 if Status then
11908 SPARK_Msg_N ("duplicate external property", Prop);
11909 end if;
11910
11911 Status := True;
11912 end Check_Duplicate_Property;
11913
11914 -----------------------------
11915 -- Check_Ghost_Synchronous --
11916 -----------------------------
11917
11918 procedure Check_Ghost_Synchronous is
11919 begin
11920 -- A synchronized abstract state cannot be Ghost and vice
11921 -- versa (SPARK RM 6.9(19)).
11922
11923 if Ghost_Seen and Synchronous_Seen then
11924 SPARK_Msg_N ("synchronized state cannot be ghost", State);
11925 end if;
11926 end Check_Ghost_Synchronous;
11927
11928 ---------------------------
11929 -- Create_Abstract_State --
11930 ---------------------------
11931
11932 procedure Create_Abstract_State
11933 (Nam : Name_Id;
11934 Decl : Node_Id;
11935 Loc : Source_Ptr;
11936 Is_Null : Boolean)
11937 is
11938 begin
11939 -- The abstract state may be semi-declared when the related
11940 -- package was withed through a limited with clause. In that
11941 -- case reuse the entity to fully declare the state.
11942
11943 if Present (Decl) and then Present (Entity (Decl)) then
11944 State_Id := Entity (Decl);
11945
11946 -- Otherwise the elaboration of pragma Abstract_State
11947 -- declares the state.
11948
11949 else
11950 State_Id := Make_Defining_Identifier (Loc, Nam);
11951
11952 if Present (Decl) then
11953 Set_Entity (Decl, State_Id);
11954 end if;
11955 end if;
11956
11957 -- Null states never come from source
11958
11959 Set_Comes_From_Source (State_Id, not Is_Null);
11960 Set_Parent (State_Id, State);
11961 Set_Ekind (State_Id, E_Abstract_State);
11962 Set_Etype (State_Id, Standard_Void_Type);
11963 Set_Encapsulating_State (State_Id, Empty);
11964
11965 -- Set the SPARK mode from the current context
11966
11967 Set_SPARK_Pragma (State_Id, SPARK_Mode_Pragma);
11968 Set_SPARK_Pragma_Inherited (State_Id);
11969
11970 -- An abstract state declared within a Ghost region becomes
11971 -- Ghost (SPARK RM 6.9(2)).
11972
11973 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then
11974 Set_Is_Ghost_Entity (State_Id);
11975 end if;
11976
11977 -- Establish a link between the state declaration and the
11978 -- abstract state entity. Note that a null state remains as
11979 -- N_Null and does not carry any linkages.
11980
11981 if not Is_Null then
11982 if Present (Decl) then
11983 Set_Entity (Decl, State_Id);
11984 Set_Etype (Decl, Standard_Void_Type);
11985 end if;
11986
11987 -- Every non-null state must be defined, nameable and
11988 -- resolvable.
11989
11990 Push_Scope (Pack_Id);
11991 Generate_Definition (State_Id);
11992 Enter_Name (State_Id);
11993 Pop_Scope;
11994 end if;
11995 end Create_Abstract_State;
11996
11997 -- Local variables
11998
11999 Opt : Node_Id;
12000 Opt_Nam : Node_Id;
12001
12002 -- Start of processing for Analyze_Abstract_State
12003
12004 begin
12005 -- A package with a null abstract state is not allowed to
12006 -- declare additional states.
12007
12008 if Null_Seen then
12009 SPARK_Msg_NE
12010 ("package & has null abstract state", State, Pack_Id);
12011
12012 -- Null states appear as internally generated entities
12013
12014 elsif Nkind (State) = N_Null then
12015 Create_Abstract_State
12016 (Nam => New_Internal_Name ('S'),
12017 Decl => Empty,
12018 Loc => Sloc (State),
12019 Is_Null => True);
12020 Null_Seen := True;
12021
12022 -- Catch a case where a null state appears in a list of
12023 -- non-null states.
12024
12025 if Non_Null_Seen then
12026 SPARK_Msg_NE
12027 ("package & has non-null abstract state",
12028 State, Pack_Id);
12029 end if;
12030
12031 -- Simple state declaration
12032
12033 elsif Nkind (State) = N_Identifier then
12034 Create_Abstract_State
12035 (Nam => Chars (State),
12036 Decl => State,
12037 Loc => Sloc (State),
12038 Is_Null => False);
12039 Non_Null_Seen := True;
12040
12041 -- State declaration with various options. This construct
12042 -- appears as an extension aggregate in the tree.
12043
12044 elsif Nkind (State) = N_Extension_Aggregate then
12045 if Nkind (Ancestor_Part (State)) = N_Identifier then
12046 Create_Abstract_State
12047 (Nam => Chars (Ancestor_Part (State)),
12048 Decl => Ancestor_Part (State),
12049 Loc => Sloc (Ancestor_Part (State)),
12050 Is_Null => False);
12051 Non_Null_Seen := True;
12052 else
12053 SPARK_Msg_N
12054 ("state name must be an identifier",
12055 Ancestor_Part (State));
12056 end if;
12057
12058 -- Options External, Ghost and Synchronous appear as
12059 -- expressions.
12060
12061 Opt := First (Expressions (State));
12062 while Present (Opt) loop
12063 if Nkind (Opt) = N_Identifier then
12064
12065 -- External
12066
12067 if Chars (Opt) = Name_External then
12068 Check_Duplicate_Option (Opt, External_Seen);
12069 Analyze_External_Option (Opt);
12070
12071 -- Ghost
12072
12073 elsif Chars (Opt) = Name_Ghost then
12074 Check_Duplicate_Option (Opt, Ghost_Seen);
12075 Check_Ghost_Synchronous;
12076
12077 if Present (State_Id) then
12078 Set_Is_Ghost_Entity (State_Id);
12079 end if;
12080
12081 -- Synchronous
12082
12083 elsif Chars (Opt) = Name_Synchronous then
12084 Check_Duplicate_Option (Opt, Synchronous_Seen);
12085 Check_Ghost_Synchronous;
12086
12087 -- Relaxed_Initialization
12088
12089 elsif Chars (Opt) = Name_Relaxed_Initialization then
12090 Check_Duplicate_Option
12091 (Opt, Relaxed_Initialization_Seen);
12092
12093 -- Option Part_Of without an encapsulating state is
12094 -- illegal (SPARK RM 7.1.4(8)).
12095
12096 elsif Chars (Opt) = Name_Part_Of then
12097 SPARK_Msg_N
12098 ("indicator Part_Of must denote abstract state, "
12099 & "single protected type or single task type",
12100 Opt);
12101
12102 -- Do not emit an error message when a previous state
12103 -- declaration with options was not parenthesized as
12104 -- the option is actually another state declaration.
12105 --
12106 -- with Abstract_State
12107 -- (State_1 with ..., -- missing parentheses
12108 -- (State_2 with ...),
12109 -- State_3) -- ok state declaration
12110
12111 elsif Missing_Parentheses then
12112 null;
12113
12114 -- Otherwise the option is not allowed. Note that it
12115 -- is not possible to distinguish between an option
12116 -- and a state declaration when a previous state with
12117 -- options not properly parentheses.
12118 --
12119 -- with Abstract_State
12120 -- (State_1 with ..., -- missing parentheses
12121 -- State_2); -- could be an option
12122
12123 else
12124 SPARK_Msg_N
12125 ("simple option not allowed in state declaration",
12126 Opt);
12127 end if;
12128
12129 -- Catch a case where missing parentheses around a state
12130 -- declaration with options cause a subsequent state
12131 -- declaration with options to be treated as an option.
12132 --
12133 -- with Abstract_State
12134 -- (State_1 with ..., -- missing parentheses
12135 -- (State_2 with ...))
12136
12137 elsif Nkind (Opt) = N_Extension_Aggregate then
12138 Missing_Parentheses := True;
12139 SPARK_Msg_N
12140 ("state declaration must be parenthesized",
12141 Ancestor_Part (State));
12142
12143 -- Otherwise the option is malformed
12144
12145 else
12146 SPARK_Msg_N ("malformed option", Opt);
12147 end if;
12148
12149 Next (Opt);
12150 end loop;
12151
12152 -- Options External and Part_Of appear as component
12153 -- associations.
12154
12155 Opt := First (Component_Associations (State));
12156 while Present (Opt) loop
12157 Opt_Nam := First (Choices (Opt));
12158
12159 if Nkind (Opt_Nam) = N_Identifier then
12160 if Chars (Opt_Nam) = Name_External then
12161 Analyze_External_Option (Opt);
12162
12163 elsif Chars (Opt_Nam) = Name_Part_Of then
12164 Analyze_Part_Of_Option (Opt);
12165
12166 else
12167 SPARK_Msg_N ("invalid state option", Opt);
12168 end if;
12169 else
12170 SPARK_Msg_N ("invalid state option", Opt);
12171 end if;
12172
12173 Next (Opt);
12174 end loop;
12175
12176 -- Any other attempt to declare a state is illegal
12177
12178 else
12179 Malformed_State_Error (State);
12180 return;
12181 end if;
12182
12183 -- Guard against a junk state. In such cases no entity is
12184 -- generated and the subsequent checks cannot be applied.
12185
12186 if Present (State_Id) then
12187
12188 -- Verify whether the state does not introduce an illegal
12189 -- hidden state within a package subject to a null abstract
12190 -- state.
12191
12192 Check_No_Hidden_State (State_Id);
12193
12194 -- Check whether the lack of option Part_Of agrees with the
12195 -- placement of the abstract state with respect to the state
12196 -- space.
12197
12198 if not Part_Of_Seen then
12199 Check_Missing_Part_Of (State_Id);
12200 end if;
12201
12202 -- Associate the state with its related package
12203
12204 if No (Abstract_States (Pack_Id)) then
12205 Set_Abstract_States (Pack_Id, New_Elmt_List);
12206 end if;
12207
12208 Append_Elmt (State_Id, Abstract_States (Pack_Id));
12209 end if;
12210 end Analyze_Abstract_State;
12211
12212 ---------------------------
12213 -- Malformed_State_Error --
12214 ---------------------------
12215
12216 procedure Malformed_State_Error (State : Node_Id) is
12217 begin
12218 Error_Msg_N ("malformed abstract state declaration", State);
12219
12220 -- An abstract state with a simple option is being declared
12221 -- with "=>" rather than the legal "with". The state appears
12222 -- as a component association.
12223
12224 if Nkind (State) = N_Component_Association then
12225 Error_Msg_N ("\use WITH to specify simple option", State);
12226 end if;
12227 end Malformed_State_Error;
12228
12229 -- Local variables
12230
12231 Pack_Decl : Node_Id;
12232 Pack_Id : Entity_Id;
12233 State : Node_Id;
12234 States : Node_Id;
12235
12236 -- Start of processing for Abstract_State
12237
12238 begin
12239 GNAT_Pragma;
12240 Check_No_Identifiers;
12241 Check_Arg_Count (1);
12242
12243 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
12244
12245 if Nkind (Pack_Decl) not in
12246 N_Generic_Package_Declaration | N_Package_Declaration
12247 then
12248 Pragma_Misplaced;
12249 return;
12250 end if;
12251
12252 Pack_Id := Defining_Entity (Pack_Decl);
12253
12254 -- A pragma that applies to a Ghost entity becomes Ghost for the
12255 -- purposes of legality checks and removal of ignored Ghost code.
12256
12257 Mark_Ghost_Pragma (N, Pack_Id);
12258 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
12259
12260 -- Chain the pragma on the contract for completeness
12261
12262 Add_Contract_Item (N, Pack_Id);
12263
12264 -- The legality checks of pragmas Abstract_State, Initializes, and
12265 -- Initial_Condition are affected by the SPARK mode in effect. In
12266 -- addition, these three pragmas are subject to an inherent order:
12267
12268 -- 1) Abstract_State
12269 -- 2) Initializes
12270 -- 3) Initial_Condition
12271
12272 -- Analyze all these pragmas in the order outlined above
12273
12274 Analyze_If_Present (Pragma_SPARK_Mode);
12275 States := Expression (Get_Argument (N, Pack_Id));
12276
12277 -- Multiple non-null abstract states appear as an aggregate
12278
12279 if Nkind (States) = N_Aggregate then
12280 State := First (Expressions (States));
12281 while Present (State) loop
12282 Analyze_Abstract_State (State, Pack_Id);
12283 Next (State);
12284 end loop;
12285
12286 -- An abstract state with a simple option is being illegaly
12287 -- declared with "=>" rather than "with". In this case the
12288 -- state declaration appears as a component association.
12289
12290 if Present (Component_Associations (States)) then
12291 State := First (Component_Associations (States));
12292 while Present (State) loop
12293 Malformed_State_Error (State);
12294 Next (State);
12295 end loop;
12296 end if;
12297
12298 -- Various forms of a single abstract state. Note that these may
12299 -- include malformed state declarations.
12300
12301 else
12302 Analyze_Abstract_State (States, Pack_Id);
12303 end if;
12304
12305 Analyze_If_Present (Pragma_Initializes);
12306 Analyze_If_Present (Pragma_Initial_Condition);
12307 end Abstract_State;
12308
12309 ------------
12310 -- Ada_83 --
12311 ------------
12312
12313 -- pragma Ada_83;
12314
12315 -- Note: this pragma also has some specific processing in Par.Prag
12316 -- because we want to set the Ada version mode during parsing.
12317
12318 when Pragma_Ada_83 =>
12319 GNAT_Pragma;
12320 Check_Arg_Count (0);
12321
12322 -- We really should check unconditionally for proper configuration
12323 -- pragma placement, since we really don't want mixed Ada modes
12324 -- within a single unit, and the GNAT reference manual has always
12325 -- said this was a configuration pragma, but we did not check and
12326 -- are hesitant to add the check now.
12327
12328 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
12329 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
12330 -- or Ada 2012 mode.
12331
12332 if Ada_Version >= Ada_2005 then
12333 Check_Valid_Configuration_Pragma;
12334 end if;
12335
12336 -- Now set Ada 83 mode
12337
12338 if Latest_Ada_Only then
12339 Error_Pragma ("??pragma% ignored");
12340 else
12341 Ada_Version := Ada_83;
12342 Ada_Version_Explicit := Ada_83;
12343 Ada_Version_Pragma := N;
12344 end if;
12345
12346 ------------
12347 -- Ada_95 --
12348 ------------
12349
12350 -- pragma Ada_95;
12351
12352 -- Note: this pragma also has some specific processing in Par.Prag
12353 -- because we want to set the Ada 83 version mode during parsing.
12354
12355 when Pragma_Ada_95 =>
12356 GNAT_Pragma;
12357 Check_Arg_Count (0);
12358
12359 -- We really should check unconditionally for proper configuration
12360 -- pragma placement, since we really don't want mixed Ada modes
12361 -- within a single unit, and the GNAT reference manual has always
12362 -- said this was a configuration pragma, but we did not check and
12363 -- are hesitant to add the check now.
12364
12365 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
12366 -- or Ada 95, so we must check if we are in Ada 2005 mode.
12367
12368 if Ada_Version >= Ada_2005 then
12369 Check_Valid_Configuration_Pragma;
12370 end if;
12371
12372 -- Now set Ada 95 mode
12373
12374 if Latest_Ada_Only then
12375 Error_Pragma ("??pragma% ignored");
12376 else
12377 Ada_Version := Ada_95;
12378 Ada_Version_Explicit := Ada_95;
12379 Ada_Version_Pragma := N;
12380 end if;
12381
12382 ---------------------
12383 -- Ada_05/Ada_2005 --
12384 ---------------------
12385
12386 -- pragma Ada_05;
12387 -- pragma Ada_05 (LOCAL_NAME);
12388
12389 -- pragma Ada_2005;
12390 -- pragma Ada_2005 (LOCAL_NAME):
12391
12392 -- Note: these pragmas also have some specific processing in Par.Prag
12393 -- because we want to set the Ada 2005 version mode during parsing.
12394
12395 -- The one argument form is used for managing the transition from
12396 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
12397 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
12398 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
12399 -- mode, a preference rule is established which does not choose
12400 -- such an entity unless it is unambiguously specified. This avoids
12401 -- extra subprograms marked this way from generating ambiguities in
12402 -- otherwise legal pre-Ada_2005 programs. The one argument form is
12403 -- intended for exclusive use in the GNAT run-time library.
12404
12405 when Pragma_Ada_05
12406 | Pragma_Ada_2005
12407 =>
12408 declare
12409 E_Id : Node_Id;
12410
12411 begin
12412 GNAT_Pragma;
12413
12414 if Arg_Count = 1 then
12415 Check_Arg_Is_Local_Name (Arg1);
12416 E_Id := Get_Pragma_Arg (Arg1);
12417
12418 if Etype (E_Id) = Any_Type then
12419 return;
12420 end if;
12421
12422 Set_Is_Ada_2005_Only (Entity (E_Id));
12423 Record_Rep_Item (Entity (E_Id), N);
12424
12425 else
12426 Check_Arg_Count (0);
12427
12428 -- For Ada_2005 we unconditionally enforce the documented
12429 -- configuration pragma placement, since we do not want to
12430 -- tolerate mixed modes in a unit involving Ada 2005. That
12431 -- would cause real difficulties for those cases where there
12432 -- are incompatibilities between Ada 95 and Ada 2005.
12433
12434 Check_Valid_Configuration_Pragma;
12435
12436 -- Now set appropriate Ada mode
12437
12438 if Latest_Ada_Only then
12439 Error_Pragma ("??pragma% ignored");
12440 else
12441 Ada_Version := Ada_2005;
12442 Ada_Version_Explicit := Ada_2005;
12443 Ada_Version_Pragma := N;
12444 end if;
12445 end if;
12446 end;
12447
12448 ---------------------
12449 -- Ada_12/Ada_2012 --
12450 ---------------------
12451
12452 -- pragma Ada_12;
12453 -- pragma Ada_12 (LOCAL_NAME);
12454
12455 -- pragma Ada_2012;
12456 -- pragma Ada_2012 (LOCAL_NAME):
12457
12458 -- Note: these pragmas also have some specific processing in Par.Prag
12459 -- because we want to set the Ada 2012 version mode during parsing.
12460
12461 -- The one argument form is used for managing the transition from Ada
12462 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
12463 -- as Ada_2012 only, then referencing the entity in any pre-Ada_2012
12464 -- mode will generate a warning. In addition, in any pre-Ada_2012
12465 -- mode, a preference rule is established which does not choose
12466 -- such an entity unless it is unambiguously specified. This avoids
12467 -- extra subprograms marked this way from generating ambiguities in
12468 -- otherwise legal pre-Ada_2012 programs. The one argument form is
12469 -- intended for exclusive use in the GNAT run-time library.
12470
12471 when Pragma_Ada_12
12472 | Pragma_Ada_2012
12473 =>
12474 declare
12475 E_Id : Node_Id;
12476
12477 begin
12478 GNAT_Pragma;
12479
12480 if Arg_Count = 1 then
12481 Check_Arg_Is_Local_Name (Arg1);
12482 E_Id := Get_Pragma_Arg (Arg1);
12483
12484 if Etype (E_Id) = Any_Type then
12485 return;
12486 end if;
12487
12488 Set_Is_Ada_2012_Only (Entity (E_Id));
12489 Record_Rep_Item (Entity (E_Id), N);
12490
12491 else
12492 Check_Arg_Count (0);
12493
12494 -- For Ada_2012 we unconditionally enforce the documented
12495 -- configuration pragma placement, since we do not want to
12496 -- tolerate mixed modes in a unit involving Ada 2012. That
12497 -- would cause real difficulties for those cases where there
12498 -- are incompatibilities between Ada 95 and Ada 2012. We could
12499 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
12500
12501 Check_Valid_Configuration_Pragma;
12502
12503 -- Now set appropriate Ada mode
12504
12505 Ada_Version := Ada_2012;
12506 Ada_Version_Explicit := Ada_2012;
12507 Ada_Version_Pragma := N;
12508 end if;
12509 end;
12510
12511 --------------
12512 -- Ada_2020 --
12513 --------------
12514
12515 -- pragma Ada_2020;
12516
12517 -- Note: this pragma also has some specific processing in Par.Prag
12518 -- because we want to set the Ada 2020 version mode during parsing.
12519
12520 when Pragma_Ada_2020 =>
12521 GNAT_Pragma;
12522
12523 Check_Arg_Count (0);
12524
12525 Check_Valid_Configuration_Pragma;
12526
12527 -- Now set appropriate Ada mode
12528
12529 Ada_Version := Ada_2020;
12530 Ada_Version_Explicit := Ada_2020;
12531 Ada_Version_Pragma := N;
12532
12533 -------------------------------------
12534 -- Aggregate_Individually_Assign --
12535 -------------------------------------
12536
12537 -- pragma Aggregate_Individually_Assign;
12538
12539 when Pragma_Aggregate_Individually_Assign =>
12540 GNAT_Pragma;
12541 Check_Arg_Count (0);
12542 Check_Valid_Configuration_Pragma;
12543 Aggregate_Individually_Assign := True;
12544
12545 ----------------------
12546 -- All_Calls_Remote --
12547 ----------------------
12548
12549 -- pragma All_Calls_Remote [(library_package_NAME)];
12550
12551 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
12552 Lib_Entity : Entity_Id;
12553
12554 begin
12555 Check_Ada_83_Warning;
12556 Check_Valid_Library_Unit_Pragma;
12557
12558 Lib_Entity := Find_Lib_Unit_Name;
12559
12560 -- A pragma that applies to a Ghost entity becomes Ghost for the
12561 -- purposes of legality checks and removal of ignored Ghost code.
12562
12563 Mark_Ghost_Pragma (N, Lib_Entity);
12564
12565 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
12566
12567 if Present (Lib_Entity) and then not Debug_Flag_U then
12568 if not Is_Remote_Call_Interface (Lib_Entity) then
12569 Error_Pragma ("pragma% only apply to rci unit");
12570
12571 -- Set flag for entity of the library unit
12572
12573 else
12574 Set_Has_All_Calls_Remote (Lib_Entity);
12575 end if;
12576 end if;
12577 end All_Calls_Remote;
12578
12579 ---------------------------
12580 -- Allow_Integer_Address --
12581 ---------------------------
12582
12583 -- pragma Allow_Integer_Address;
12584
12585 when Pragma_Allow_Integer_Address =>
12586 GNAT_Pragma;
12587 Check_Valid_Configuration_Pragma;
12588 Check_Arg_Count (0);
12589
12590 -- If Address is a private type, then set the flag to allow
12591 -- integer address values. If Address is not private, then this
12592 -- pragma has no purpose, so it is simply ignored. Not clear if
12593 -- there are any such targets now.
12594
12595 if Opt.Address_Is_Private then
12596 Opt.Allow_Integer_Address := True;
12597 end if;
12598
12599 --------------
12600 -- Annotate --
12601 --------------
12602
12603 -- pragma Annotate
12604 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
12605 -- ARG ::= NAME | EXPRESSION
12606
12607 -- The first two arguments are by convention intended to refer to an
12608 -- external tool and a tool-specific function. These arguments are
12609 -- not analyzed.
12610
12611 when Pragma_Annotate => Annotate : declare
12612 Arg : Node_Id;
12613 Expr : Node_Id;
12614 Nam_Arg : Node_Id;
12615
12616 --------------------------
12617 -- Inferred_String_Type --
12618 --------------------------
12619
12620 function Preferred_String_Type (Expr : Node_Id) return Entity_Id;
12621 -- Infer the type to use for a string literal or a concatentation
12622 -- of operands whose types can be inferred. For such expressions,
12623 -- returns the "narrowest" of the three predefined string types
12624 -- that can represent the characters occurring in the expression.
12625 -- For other expressions, returns Empty.
12626
12627 function Preferred_String_Type (Expr : Node_Id) return Entity_Id is
12628 begin
12629 case Nkind (Expr) is
12630 when N_String_Literal =>
12631 if Has_Wide_Wide_Character (Expr) then
12632 return Standard_Wide_Wide_String;
12633 elsif Has_Wide_Character (Expr) then
12634 return Standard_Wide_String;
12635 else
12636 return Standard_String;
12637 end if;
12638
12639 when N_Op_Concat =>
12640 declare
12641 L_Type : constant Entity_Id
12642 := Preferred_String_Type (Left_Opnd (Expr));
12643 R_Type : constant Entity_Id
12644 := Preferred_String_Type (Right_Opnd (Expr));
12645
12646 Type_Table : constant array (1 .. 4) of Entity_Id
12647 := (Empty,
12648 Standard_Wide_Wide_String,
12649 Standard_Wide_String,
12650 Standard_String);
12651 begin
12652 for Idx in Type_Table'Range loop
12653 if (L_Type = Type_Table (Idx)) or
12654 (R_Type = Type_Table (Idx))
12655 then
12656 return Type_Table (Idx);
12657 end if;
12658 end loop;
12659 raise Program_Error;
12660 end;
12661
12662 when others =>
12663 return Empty;
12664 end case;
12665 end Preferred_String_Type;
12666 begin
12667 GNAT_Pragma;
12668 Check_At_Least_N_Arguments (1);
12669
12670 Nam_Arg := Last (Pragma_Argument_Associations (N));
12671
12672 -- Determine whether the last argument is "Entity => local_NAME"
12673 -- and if it is, perform the required semantic checks. Remove the
12674 -- argument from further processing.
12675
12676 if Nkind (Nam_Arg) = N_Pragma_Argument_Association
12677 and then Chars (Nam_Arg) = Name_Entity
12678 then
12679 Check_Arg_Is_Local_Name (Nam_Arg);
12680 Arg_Count := Arg_Count - 1;
12681
12682 -- A pragma that applies to a Ghost entity becomes Ghost for
12683 -- the purposes of legality checks and removal of ignored Ghost
12684 -- code.
12685
12686 if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg))
12687 and then Present (Entity (Get_Pragma_Arg (Nam_Arg)))
12688 then
12689 Mark_Ghost_Pragma (N, Entity (Get_Pragma_Arg (Nam_Arg)));
12690 end if;
12691
12692 -- Not allowed in compiler units (bootstrap issues)
12693
12694 Check_Compiler_Unit ("Entity for pragma Annotate", N);
12695 end if;
12696
12697 -- Continue the processing with last argument removed for now
12698
12699 Check_Arg_Is_Identifier (Arg1);
12700 Check_No_Identifiers;
12701 Store_Note (N);
12702
12703 -- The second parameter is optional, it is never analyzed
12704
12705 if No (Arg2) then
12706 null;
12707
12708 -- Otherwise there is a second parameter
12709
12710 else
12711 -- The second parameter must be an identifier
12712
12713 Check_Arg_Is_Identifier (Arg2);
12714
12715 -- Process the remaining parameters (if any)
12716
12717 Arg := Next (Arg2);
12718 while Present (Arg) loop
12719 Expr := Get_Pragma_Arg (Arg);
12720 Analyze (Expr);
12721
12722 if Is_Entity_Name (Expr) then
12723 null;
12724
12725 -- For string literals and concatenations of string literals
12726 -- we assume Standard_String as the type, unless the string
12727 -- contains wide or wide_wide characters.
12728
12729 elsif Present (Preferred_String_Type (Expr)) then
12730 Resolve (Expr, Preferred_String_Type (Expr));
12731
12732 elsif Is_Overloaded (Expr) then
12733 Error_Pragma_Arg ("ambiguous argument for pragma%", Expr);
12734
12735 else
12736 Resolve (Expr);
12737 end if;
12738
12739 Next (Arg);
12740 end loop;
12741 end if;
12742 end Annotate;
12743
12744 -------------------------------------------------
12745 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
12746 -------------------------------------------------
12747
12748 -- pragma Assert
12749 -- ( [Check => ] Boolean_EXPRESSION
12750 -- [, [Message =>] Static_String_EXPRESSION]);
12751
12752 -- pragma Assert_And_Cut
12753 -- ( [Check => ] Boolean_EXPRESSION
12754 -- [, [Message =>] Static_String_EXPRESSION]);
12755
12756 -- pragma Assume
12757 -- ( [Check => ] Boolean_EXPRESSION
12758 -- [, [Message =>] Static_String_EXPRESSION]);
12759
12760 -- pragma Loop_Invariant
12761 -- ( [Check => ] Boolean_EXPRESSION
12762 -- [, [Message =>] Static_String_EXPRESSION]);
12763
12764 when Pragma_Assert
12765 | Pragma_Assert_And_Cut
12766 | Pragma_Assume
12767 | Pragma_Loop_Invariant
12768 =>
12769 Assert : declare
12770 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
12771 -- Determine whether expression Expr contains a Loop_Entry
12772 -- attribute reference.
12773
12774 -------------------------
12775 -- Contains_Loop_Entry --
12776 -------------------------
12777
12778 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
12779 Has_Loop_Entry : Boolean := False;
12780
12781 function Process (N : Node_Id) return Traverse_Result;
12782 -- Process function for traversal to look for Loop_Entry
12783
12784 -------------
12785 -- Process --
12786 -------------
12787
12788 function Process (N : Node_Id) return Traverse_Result is
12789 begin
12790 if Nkind (N) = N_Attribute_Reference
12791 and then Attribute_Name (N) = Name_Loop_Entry
12792 then
12793 Has_Loop_Entry := True;
12794 return Abandon;
12795 else
12796 return OK;
12797 end if;
12798 end Process;
12799
12800 procedure Traverse is new Traverse_Proc (Process);
12801
12802 -- Start of processing for Contains_Loop_Entry
12803
12804 begin
12805 Traverse (Expr);
12806 return Has_Loop_Entry;
12807 end Contains_Loop_Entry;
12808
12809 -- Local variables
12810
12811 Expr : Node_Id;
12812 New_Args : List_Id;
12813
12814 -- Start of processing for Assert
12815
12816 begin
12817 -- Assert is an Ada 2005 RM-defined pragma
12818
12819 if Prag_Id = Pragma_Assert then
12820 Ada_2005_Pragma;
12821
12822 -- The remaining ones are GNAT pragmas
12823
12824 else
12825 GNAT_Pragma;
12826 end if;
12827
12828 Check_At_Least_N_Arguments (1);
12829 Check_At_Most_N_Arguments (2);
12830 Check_Arg_Order ((Name_Check, Name_Message));
12831 Check_Optional_Identifier (Arg1, Name_Check);
12832 Expr := Get_Pragma_Arg (Arg1);
12833
12834 -- Special processing for Loop_Invariant, Loop_Variant or for
12835 -- other cases where a Loop_Entry attribute is present. If the
12836 -- assertion pragma contains attribute Loop_Entry, ensure that
12837 -- the related pragma is within a loop.
12838
12839 if Prag_Id = Pragma_Loop_Invariant
12840 or else Prag_Id = Pragma_Loop_Variant
12841 or else Contains_Loop_Entry (Expr)
12842 then
12843 Check_Loop_Pragma_Placement;
12844
12845 -- Perform preanalysis to deal with embedded Loop_Entry
12846 -- attributes.
12847
12848 Preanalyze_Assert_Expression (Expr, Any_Boolean);
12849 end if;
12850
12851 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
12852 -- a corresponding Check pragma:
12853
12854 -- pragma Check (name, condition [, msg]);
12855
12856 -- Where name is the identifier matching the pragma name. So
12857 -- rewrite pragma in this manner, transfer the message argument
12858 -- if present, and analyze the result
12859
12860 -- Note: When dealing with a semantically analyzed tree, the
12861 -- information that a Check node N corresponds to a source Assert,
12862 -- Assume, or Assert_And_Cut pragma can be retrieved from the
12863 -- pragma kind of Original_Node(N).
12864
12865 New_Args := New_List (
12866 Make_Pragma_Argument_Association (Loc,
12867 Expression => Make_Identifier (Loc, Pname)),
12868 Make_Pragma_Argument_Association (Sloc (Expr),
12869 Expression => Expr));
12870
12871 if Arg_Count > 1 then
12872 Check_Optional_Identifier (Arg2, Name_Message);
12873
12874 -- Provide semantic annotations for optional argument, for
12875 -- ASIS use, before rewriting.
12876 -- Is this still needed???
12877
12878 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
12879 Append_To (New_Args, New_Copy_Tree (Arg2));
12880 end if;
12881
12882 -- Rewrite as Check pragma
12883
12884 Rewrite (N,
12885 Make_Pragma (Loc,
12886 Chars => Name_Check,
12887 Pragma_Argument_Associations => New_Args));
12888
12889 Analyze (N);
12890 end Assert;
12891
12892 ----------------------
12893 -- Assertion_Policy --
12894 ----------------------
12895
12896 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
12897
12898 -- The following form is Ada 2012 only, but we allow it in all modes
12899
12900 -- Pragma Assertion_Policy (
12901 -- ASSERTION_KIND => POLICY_IDENTIFIER
12902 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
12903
12904 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
12905
12906 -- RM_ASSERTION_KIND ::= Assert |
12907 -- Static_Predicate |
12908 -- Dynamic_Predicate |
12909 -- Pre |
12910 -- Pre'Class |
12911 -- Post |
12912 -- Post'Class |
12913 -- Type_Invariant |
12914 -- Type_Invariant'Class |
12915 -- Default_Initial_Condition
12916
12917 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
12918 -- Assume |
12919 -- Contract_Cases |
12920 -- Debug |
12921 -- Ghost |
12922 -- Initial_Condition |
12923 -- Loop_Invariant |
12924 -- Loop_Variant |
12925 -- Postcondition |
12926 -- Precondition |
12927 -- Predicate |
12928 -- Refined_Post |
12929 -- Statement_Assertions |
12930 -- Subprogram_Variant
12931
12932 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
12933 -- ID_ASSERTION_KIND list contains implementation-defined additions
12934 -- recognized by GNAT. The effect is to control the behavior of
12935 -- identically named aspects and pragmas, depending on the specified
12936 -- policy identifier:
12937
12938 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
12939
12940 -- Note: Check and Ignore are language-defined. Disable is a GNAT
12941 -- implementation-defined addition that results in totally ignoring
12942 -- the corresponding assertion. If Disable is specified, then the
12943 -- argument of the assertion is not even analyzed. This is useful
12944 -- when the aspect/pragma argument references entities in a with'ed
12945 -- package that is replaced by a dummy package in the final build.
12946
12947 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
12948 -- and Type_Invariant'Class were recognized by the parser and
12949 -- transformed into references to the special internal identifiers
12950 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
12951 -- processing is required here.
12952
12953 when Pragma_Assertion_Policy => Assertion_Policy : declare
12954 procedure Resolve_Suppressible (Policy : Node_Id);
12955 -- Converts the assertion policy 'Suppressible' to either Check or
12956 -- Ignore based on whether checks are suppressed via -gnatp.
12957
12958 --------------------------
12959 -- Resolve_Suppressible --
12960 --------------------------
12961
12962 procedure Resolve_Suppressible (Policy : Node_Id) is
12963 Arg : constant Node_Id := Get_Pragma_Arg (Policy);
12964 Nam : Name_Id;
12965
12966 begin
12967 -- Transform policy argument Suppressible into either Ignore or
12968 -- Check depending on whether checks are enabled or suppressed.
12969
12970 if Chars (Arg) = Name_Suppressible then
12971 if Suppress_Checks then
12972 Nam := Name_Ignore;
12973 else
12974 Nam := Name_Check;
12975 end if;
12976
12977 Rewrite (Arg, Make_Identifier (Sloc (Arg), Nam));
12978 end if;
12979 end Resolve_Suppressible;
12980
12981 -- Local variables
12982
12983 Arg : Node_Id;
12984 Kind : Name_Id;
12985 LocP : Source_Ptr;
12986 Policy : Node_Id;
12987
12988 begin
12989 Ada_2005_Pragma;
12990
12991 -- This can always appear as a configuration pragma
12992
12993 if Is_Configuration_Pragma then
12994 null;
12995
12996 -- It can also appear in a declarative part or package spec in Ada
12997 -- 2012 mode. We allow this in other modes, but in that case we
12998 -- consider that we have an Ada 2012 pragma on our hands.
12999
13000 else
13001 Check_Is_In_Decl_Part_Or_Package_Spec;
13002 Ada_2012_Pragma;
13003 end if;
13004
13005 -- One argument case with no identifier (first form above)
13006
13007 if Arg_Count = 1
13008 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
13009 or else Chars (Arg1) = No_Name)
13010 then
13011 Check_Arg_Is_One_Of (Arg1,
13012 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13013
13014 Resolve_Suppressible (Arg1);
13015
13016 -- Treat one argument Assertion_Policy as equivalent to:
13017
13018 -- pragma Check_Policy (Assertion, policy)
13019
13020 -- So rewrite pragma in that manner and link on to the chain
13021 -- of Check_Policy pragmas, marking the pragma as analyzed.
13022
13023 Policy := Get_Pragma_Arg (Arg1);
13024
13025 Rewrite (N,
13026 Make_Pragma (Loc,
13027 Chars => Name_Check_Policy,
13028 Pragma_Argument_Associations => New_List (
13029 Make_Pragma_Argument_Association (Loc,
13030 Expression => Make_Identifier (Loc, Name_Assertion)),
13031
13032 Make_Pragma_Argument_Association (Loc,
13033 Expression =>
13034 Make_Identifier (Sloc (Policy), Chars (Policy))))));
13035 Analyze (N);
13036
13037 -- Here if we have two or more arguments
13038
13039 else
13040 Check_At_Least_N_Arguments (1);
13041 Ada_2012_Pragma;
13042
13043 -- Loop through arguments
13044
13045 Arg := Arg1;
13046 while Present (Arg) loop
13047 LocP := Sloc (Arg);
13048
13049 -- Kind must be specified
13050
13051 if Nkind (Arg) /= N_Pragma_Argument_Association
13052 or else Chars (Arg) = No_Name
13053 then
13054 Error_Pragma_Arg
13055 ("missing assertion kind for pragma%", Arg);
13056 end if;
13057
13058 -- Check Kind and Policy have allowed forms
13059
13060 Kind := Chars (Arg);
13061 Policy := Get_Pragma_Arg (Arg);
13062
13063 if not Is_Valid_Assertion_Kind (Kind) then
13064 Error_Pragma_Arg
13065 ("invalid assertion kind for pragma%", Arg);
13066 end if;
13067
13068 Check_Arg_Is_One_Of (Arg,
13069 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13070
13071 Resolve_Suppressible (Arg);
13072
13073 if Kind = Name_Ghost then
13074
13075 -- The Ghost policy must be either Check or Ignore
13076 -- (SPARK RM 6.9(6)).
13077
13078 if Chars (Policy) not in Name_Check | Name_Ignore then
13079 Error_Pragma_Arg
13080 ("argument of pragma % Ghost must be Check or "
13081 & "Ignore", Policy);
13082 end if;
13083
13084 -- Pragma Assertion_Policy specifying a Ghost policy
13085 -- cannot occur within a Ghost subprogram or package
13086 -- (SPARK RM 6.9(14)).
13087
13088 if Ghost_Mode > None then
13089 Error_Pragma
13090 ("pragma % cannot appear within ghost subprogram or "
13091 & "package");
13092 end if;
13093 end if;
13094
13095 -- Rewrite the Assertion_Policy pragma as a series of
13096 -- Check_Policy pragmas of the form:
13097
13098 -- Check_Policy (Kind, Policy);
13099
13100 -- Note: the insertion of the pragmas cannot be done with
13101 -- Insert_Action because in the configuration case, there
13102 -- are no scopes on the scope stack and the mechanism will
13103 -- fail.
13104
13105 Insert_Before_And_Analyze (N,
13106 Make_Pragma (LocP,
13107 Chars => Name_Check_Policy,
13108 Pragma_Argument_Associations => New_List (
13109 Make_Pragma_Argument_Association (LocP,
13110 Expression => Make_Identifier (LocP, Kind)),
13111 Make_Pragma_Argument_Association (LocP,
13112 Expression => Policy))));
13113
13114 Arg := Next (Arg);
13115 end loop;
13116
13117 -- Rewrite the Assertion_Policy pragma as null since we have
13118 -- now inserted all the equivalent Check pragmas.
13119
13120 Rewrite (N, Make_Null_Statement (Loc));
13121 Analyze (N);
13122 end if;
13123 end Assertion_Policy;
13124
13125 ------------------------------
13126 -- Assume_No_Invalid_Values --
13127 ------------------------------
13128
13129 -- pragma Assume_No_Invalid_Values (On | Off);
13130
13131 when Pragma_Assume_No_Invalid_Values =>
13132 GNAT_Pragma;
13133 Check_Valid_Configuration_Pragma;
13134 Check_Arg_Count (1);
13135 Check_No_Identifiers;
13136 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13137
13138 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
13139 Assume_No_Invalid_Values := True;
13140 else
13141 Assume_No_Invalid_Values := False;
13142 end if;
13143
13144 --------------------------
13145 -- Attribute_Definition --
13146 --------------------------
13147
13148 -- pragma Attribute_Definition
13149 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
13150 -- [Entity =>] LOCAL_NAME,
13151 -- [Expression =>] EXPRESSION | NAME);
13152
13153 when Pragma_Attribute_Definition => Attribute_Definition : declare
13154 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
13155 Aname : Name_Id;
13156
13157 begin
13158 GNAT_Pragma;
13159 Check_Arg_Count (3);
13160 Check_Optional_Identifier (Arg1, "attribute");
13161 Check_Optional_Identifier (Arg2, "entity");
13162 Check_Optional_Identifier (Arg3, "expression");
13163
13164 if Nkind (Attribute_Designator) /= N_Identifier then
13165 Error_Msg_N ("attribute name expected", Attribute_Designator);
13166 return;
13167 end if;
13168
13169 Check_Arg_Is_Local_Name (Arg2);
13170
13171 -- If the attribute is not recognized, then issue a warning (not
13172 -- an error), and ignore the pragma.
13173
13174 Aname := Chars (Attribute_Designator);
13175
13176 if not Is_Attribute_Name (Aname) then
13177 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
13178 return;
13179 end if;
13180
13181 -- Otherwise, rewrite the pragma as an attribute definition clause
13182
13183 Rewrite (N,
13184 Make_Attribute_Definition_Clause (Loc,
13185 Name => Get_Pragma_Arg (Arg2),
13186 Chars => Aname,
13187 Expression => Get_Pragma_Arg (Arg3)));
13188 Analyze (N);
13189 end Attribute_Definition;
13190
13191 ------------------------------------------------------------------
13192 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
13193 -- No_Caching --
13194 ------------------------------------------------------------------
13195
13196 -- pragma Async_Readers [ (boolean_EXPRESSION) ];
13197 -- pragma Async_Writers [ (boolean_EXPRESSION) ];
13198 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
13199 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
13200 -- pragma No_Caching [ (boolean_EXPRESSION) ];
13201
13202 when Pragma_Async_Readers
13203 | Pragma_Async_Writers
13204 | Pragma_Effective_Reads
13205 | Pragma_Effective_Writes
13206 | Pragma_No_Caching
13207 =>
13208 Async_Effective : declare
13209 Obj_Or_Type_Decl : Node_Id;
13210 Obj_Or_Type_Id : Entity_Id;
13211 begin
13212 GNAT_Pragma;
13213 Check_No_Identifiers;
13214 Check_At_Most_N_Arguments (1);
13215
13216 Obj_Or_Type_Decl := Find_Related_Context (N, Do_Checks => True);
13217
13218 -- Pragma must apply to a object declaration or to a type
13219 -- declaration (only the former in the No_Caching case).
13220 -- Original_Node is necessary to account for untagged derived
13221 -- types that are rewritten as subtypes of their
13222 -- respective root types.
13223
13224 if Nkind (Obj_Or_Type_Decl) /= N_Object_Declaration then
13225 if Prag_Id = Pragma_No_Caching
13226 or else Nkind (Original_Node (Obj_Or_Type_Decl)) not in
13227 N_Full_Type_Declaration |
13228 N_Private_Type_Declaration |
13229 N_Formal_Type_Declaration |
13230 N_Task_Type_Declaration |
13231 N_Protected_Type_Declaration
13232 then
13233 Pragma_Misplaced;
13234 return;
13235 end if;
13236 end if;
13237
13238 Obj_Or_Type_Id := Defining_Entity (Obj_Or_Type_Decl);
13239
13240 -- Perform minimal verification to ensure that the argument is at
13241 -- least a variable or a type. Subsequent finer grained checks
13242 -- will be done at the end of the declarative region that
13243 -- contains the pragma.
13244
13245 if Ekind (Obj_Or_Type_Id) = E_Variable
13246 or else Is_Type (Obj_Or_Type_Id)
13247 then
13248
13249 -- In the case of a type, pragma is a type-related
13250 -- representation item and so requires checks common to
13251 -- all type-related representation items.
13252
13253 if Is_Type (Obj_Or_Type_Id)
13254 and then Rep_Item_Too_Late (Obj_Or_Type_Id, N)
13255 then
13256 return;
13257 end if;
13258
13259 -- A pragma that applies to a Ghost entity becomes Ghost for
13260 -- the purposes of legality checks and removal of ignored Ghost
13261 -- code.
13262
13263 Mark_Ghost_Pragma (N, Obj_Or_Type_Id);
13264
13265 -- Chain the pragma on the contract for further processing by
13266 -- Analyze_External_Property_In_Decl_Part.
13267
13268 Add_Contract_Item (N, Obj_Or_Type_Id);
13269
13270 -- Analyze the Boolean expression (if any)
13271
13272 if Present (Arg1) then
13273 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
13274 end if;
13275
13276 -- Otherwise the external property applies to a constant
13277
13278 else
13279 Error_Pragma
13280 ("pragma % must apply to a volatile type or object");
13281 end if;
13282 end Async_Effective;
13283
13284 ------------------
13285 -- Asynchronous --
13286 ------------------
13287
13288 -- pragma Asynchronous (LOCAL_NAME);
13289
13290 when Pragma_Asynchronous => Asynchronous : declare
13291 C_Ent : Entity_Id;
13292 Decl : Node_Id;
13293 Formal : Entity_Id;
13294 L : List_Id;
13295 Nm : Entity_Id;
13296 S : Node_Id;
13297
13298 procedure Process_Async_Pragma;
13299 -- Common processing for procedure and access-to-procedure case
13300
13301 --------------------------
13302 -- Process_Async_Pragma --
13303 --------------------------
13304
13305 procedure Process_Async_Pragma is
13306 begin
13307 if No (L) then
13308 Set_Is_Asynchronous (Nm);
13309 return;
13310 end if;
13311
13312 -- The formals should be of mode IN (RM E.4.1(6))
13313
13314 S := First (L);
13315 while Present (S) loop
13316 Formal := Defining_Identifier (S);
13317
13318 if Nkind (Formal) = N_Defining_Identifier
13319 and then Ekind (Formal) /= E_In_Parameter
13320 then
13321 Error_Pragma_Arg
13322 ("pragma% procedure can only have IN parameter",
13323 Arg1);
13324 end if;
13325
13326 Next (S);
13327 end loop;
13328
13329 Set_Is_Asynchronous (Nm);
13330 end Process_Async_Pragma;
13331
13332 -- Start of processing for pragma Asynchronous
13333
13334 begin
13335 Check_Ada_83_Warning;
13336 Check_No_Identifiers;
13337 Check_Arg_Count (1);
13338 Check_Arg_Is_Local_Name (Arg1);
13339
13340 if Debug_Flag_U then
13341 return;
13342 end if;
13343
13344 C_Ent := Cunit_Entity (Current_Sem_Unit);
13345 Analyze (Get_Pragma_Arg (Arg1));
13346 Nm := Entity (Get_Pragma_Arg (Arg1));
13347
13348 -- A pragma that applies to a Ghost entity becomes Ghost for the
13349 -- purposes of legality checks and removal of ignored Ghost code.
13350
13351 Mark_Ghost_Pragma (N, Nm);
13352
13353 if not Is_Remote_Call_Interface (C_Ent)
13354 and then not Is_Remote_Types (C_Ent)
13355 then
13356 -- This pragma should only appear in an RCI or Remote Types
13357 -- unit (RM E.4.1(4)).
13358
13359 Error_Pragma
13360 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
13361 end if;
13362
13363 if Ekind (Nm) = E_Procedure
13364 and then Nkind (Parent (Nm)) = N_Procedure_Specification
13365 then
13366 if not Is_Remote_Call_Interface (Nm) then
13367 Error_Pragma_Arg
13368 ("pragma% cannot be applied on non-remote procedure",
13369 Arg1);
13370 end if;
13371
13372 L := Parameter_Specifications (Parent (Nm));
13373 Process_Async_Pragma;
13374 return;
13375
13376 elsif Ekind (Nm) = E_Function then
13377 Error_Pragma_Arg
13378 ("pragma% cannot be applied to function", Arg1);
13379
13380 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
13381 if Is_Record_Type (Nm) then
13382
13383 -- A record type that is the Equivalent_Type for a remote
13384 -- access-to-subprogram type.
13385
13386 Decl := Declaration_Node (Corresponding_Remote_Type (Nm));
13387
13388 else
13389 -- A non-expanded RAS type (distribution is not enabled)
13390
13391 Decl := Declaration_Node (Nm);
13392 end if;
13393
13394 if Nkind (Decl) = N_Full_Type_Declaration
13395 and then Nkind (Type_Definition (Decl)) =
13396 N_Access_Procedure_Definition
13397 then
13398 L := Parameter_Specifications (Type_Definition (Decl));
13399 Process_Async_Pragma;
13400
13401 if Is_Asynchronous (Nm)
13402 and then Expander_Active
13403 and then Get_PCS_Name /= Name_No_DSA
13404 then
13405 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
13406 end if;
13407
13408 else
13409 Error_Pragma_Arg
13410 ("pragma% cannot reference access-to-function type",
13411 Arg1);
13412 end if;
13413
13414 -- Only other possibility is Access-to-class-wide type
13415
13416 elsif Is_Access_Type (Nm)
13417 and then Is_Class_Wide_Type (Designated_Type (Nm))
13418 then
13419 Check_First_Subtype (Arg1);
13420 Set_Is_Asynchronous (Nm);
13421 if Expander_Active then
13422 RACW_Type_Is_Asynchronous (Nm);
13423 end if;
13424
13425 else
13426 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
13427 end if;
13428 end Asynchronous;
13429
13430 ------------
13431 -- Atomic --
13432 ------------
13433
13434 -- pragma Atomic (LOCAL_NAME);
13435
13436 when Pragma_Atomic =>
13437 Process_Atomic_Independent_Shared_Volatile;
13438
13439 -----------------------
13440 -- Atomic_Components --
13441 -----------------------
13442
13443 -- pragma Atomic_Components (array_LOCAL_NAME);
13444
13445 -- This processing is shared by Volatile_Components
13446
13447 when Pragma_Atomic_Components
13448 | Pragma_Volatile_Components
13449 =>
13450 Atomic_Components : declare
13451 D : Node_Id;
13452 E : Entity_Id;
13453 E_Id : Node_Id;
13454
13455 begin
13456 Check_Ada_83_Warning;
13457 Check_No_Identifiers;
13458 Check_Arg_Count (1);
13459 Check_Arg_Is_Local_Name (Arg1);
13460 E_Id := Get_Pragma_Arg (Arg1);
13461
13462 if Etype (E_Id) = Any_Type then
13463 return;
13464 end if;
13465
13466 E := Entity (E_Id);
13467
13468 -- A pragma that applies to a Ghost entity becomes Ghost for the
13469 -- purposes of legality checks and removal of ignored Ghost code.
13470
13471 Mark_Ghost_Pragma (N, E);
13472 Check_Duplicate_Pragma (E);
13473
13474 if Rep_Item_Too_Early (E, N)
13475 or else
13476 Rep_Item_Too_Late (E, N)
13477 then
13478 return;
13479 end if;
13480
13481 D := Declaration_Node (E);
13482
13483 if (Nkind (D) = N_Full_Type_Declaration and then Is_Array_Type (E))
13484 or else
13485 (Nkind (D) = N_Object_Declaration
13486 and then Ekind (E) in E_Constant | E_Variable
13487 and then Nkind (Object_Definition (D)) =
13488 N_Constrained_Array_Definition)
13489 or else
13490 (Ada_Version >= Ada_2020
13491 and then Nkind (D) = N_Formal_Type_Declaration)
13492 then
13493 -- The flag is set on the base type, or on the object
13494
13495 if Nkind (D) = N_Full_Type_Declaration then
13496 E := Base_Type (E);
13497 end if;
13498
13499 -- Atomic implies both Independent and Volatile
13500
13501 if Prag_Id = Pragma_Atomic_Components then
13502 Set_Has_Atomic_Components (E);
13503 Set_Has_Independent_Components (E);
13504 end if;
13505
13506 Set_Has_Volatile_Components (E);
13507
13508 else
13509 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
13510 end if;
13511 end Atomic_Components;
13512
13513 --------------------
13514 -- Attach_Handler --
13515 --------------------
13516
13517 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
13518
13519 when Pragma_Attach_Handler =>
13520 Check_Ada_83_Warning;
13521 Check_No_Identifiers;
13522 Check_Arg_Count (2);
13523
13524 if No_Run_Time_Mode then
13525 Error_Msg_CRT ("Attach_Handler pragma", N);
13526 else
13527 Check_Interrupt_Or_Attach_Handler;
13528
13529 -- The expression that designates the attribute may depend on a
13530 -- discriminant, and is therefore a per-object expression, to
13531 -- be expanded in the init proc. If expansion is enabled, then
13532 -- perform semantic checks on a copy only.
13533
13534 declare
13535 Temp : Node_Id;
13536 Typ : Node_Id;
13537 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
13538
13539 begin
13540 -- In Relaxed_RM_Semantics mode, we allow any static
13541 -- integer value, for compatibility with other compilers.
13542
13543 if Relaxed_RM_Semantics
13544 and then Nkind (Parg2) = N_Integer_Literal
13545 then
13546 Typ := Standard_Integer;
13547 else
13548 Typ := RTE (RE_Interrupt_ID);
13549 end if;
13550
13551 if Expander_Active then
13552 Temp := New_Copy_Tree (Parg2);
13553 Set_Parent (Temp, N);
13554 Preanalyze_And_Resolve (Temp, Typ);
13555 else
13556 Analyze (Parg2);
13557 Resolve (Parg2, Typ);
13558 end if;
13559 end;
13560
13561 Process_Interrupt_Or_Attach_Handler;
13562 end if;
13563
13564 --------------------
13565 -- C_Pass_By_Copy --
13566 --------------------
13567
13568 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
13569
13570 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
13571 Arg : Node_Id;
13572 Val : Uint;
13573
13574 begin
13575 GNAT_Pragma;
13576 Check_Valid_Configuration_Pragma;
13577 Check_Arg_Count (1);
13578 Check_Optional_Identifier (Arg1, "max_size");
13579
13580 Arg := Get_Pragma_Arg (Arg1);
13581 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
13582
13583 Val := Expr_Value (Arg);
13584
13585 if Val <= 0 then
13586 Error_Pragma_Arg
13587 ("maximum size for pragma% must be positive", Arg1);
13588
13589 elsif UI_Is_In_Int_Range (Val) then
13590 Default_C_Record_Mechanism := UI_To_Int (Val);
13591
13592 -- If a giant value is given, Int'Last will do well enough.
13593 -- If sometime someone complains that a record larger than
13594 -- two gigabytes is not copied, we will worry about it then.
13595
13596 else
13597 Default_C_Record_Mechanism := Mechanism_Type'Last;
13598 end if;
13599 end C_Pass_By_Copy;
13600
13601 -----------
13602 -- Check --
13603 -----------
13604
13605 -- pragma Check ([Name =>] CHECK_KIND,
13606 -- [Check =>] Boolean_EXPRESSION
13607 -- [,[Message =>] String_EXPRESSION]);
13608
13609 -- CHECK_KIND ::= IDENTIFIER |
13610 -- Pre'Class |
13611 -- Post'Class |
13612 -- Invariant'Class |
13613 -- Type_Invariant'Class
13614
13615 -- The identifiers Assertions and Statement_Assertions are not
13616 -- allowed, since they have special meaning for Check_Policy.
13617
13618 -- WARNING: The code below manages Ghost regions. Return statements
13619 -- must be replaced by gotos which jump to the end of the code and
13620 -- restore the Ghost mode.
13621
13622 when Pragma_Check => Check : declare
13623 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
13624 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
13625 -- Save the Ghost-related attributes to restore on exit
13626
13627 Cname : Name_Id;
13628 Eloc : Source_Ptr;
13629 Expr : Node_Id;
13630 Str : Node_Id;
13631 pragma Warnings (Off, Str);
13632
13633 begin
13634 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
13635 -- the mode now to ensure that any nodes generated during analysis
13636 -- and expansion are marked as Ghost.
13637
13638 Set_Ghost_Mode (N);
13639
13640 GNAT_Pragma;
13641 Check_At_Least_N_Arguments (2);
13642 Check_At_Most_N_Arguments (3);
13643 Check_Optional_Identifier (Arg1, Name_Name);
13644 Check_Optional_Identifier (Arg2, Name_Check);
13645
13646 if Arg_Count = 3 then
13647 Check_Optional_Identifier (Arg3, Name_Message);
13648 Str := Get_Pragma_Arg (Arg3);
13649 end if;
13650
13651 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
13652 Check_Arg_Is_Identifier (Arg1);
13653 Cname := Chars (Get_Pragma_Arg (Arg1));
13654
13655 -- Check forbidden name Assertions or Statement_Assertions
13656
13657 case Cname is
13658 when Name_Assertions =>
13659 Error_Pragma_Arg
13660 ("""Assertions"" is not allowed as a check kind for "
13661 & "pragma%", Arg1);
13662
13663 when Name_Statement_Assertions =>
13664 Error_Pragma_Arg
13665 ("""Statement_Assertions"" is not allowed as a check kind "
13666 & "for pragma%", Arg1);
13667
13668 when others =>
13669 null;
13670 end case;
13671
13672 -- Check applicable policy. We skip this if Checked/Ignored status
13673 -- is already set (e.g. in the case of a pragma from an aspect).
13674
13675 if Is_Checked (N) or else Is_Ignored (N) then
13676 null;
13677
13678 -- For a non-source pragma that is a rewriting of another pragma,
13679 -- copy the Is_Checked/Ignored status from the rewritten pragma.
13680
13681 elsif Is_Rewrite_Substitution (N)
13682 and then Nkind (Original_Node (N)) = N_Pragma
13683 then
13684 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
13685 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
13686
13687 -- Otherwise query the applicable policy at this point
13688
13689 else
13690 case Check_Kind (Cname) is
13691 when Name_Ignore =>
13692 Set_Is_Ignored (N, True);
13693 Set_Is_Checked (N, False);
13694
13695 when Name_Check =>
13696 Set_Is_Ignored (N, False);
13697 Set_Is_Checked (N, True);
13698
13699 -- For disable, rewrite pragma as null statement and skip
13700 -- rest of the analysis of the pragma.
13701
13702 when Name_Disable =>
13703 Rewrite (N, Make_Null_Statement (Loc));
13704 Analyze (N);
13705 raise Pragma_Exit;
13706
13707 -- No other possibilities
13708
13709 when others =>
13710 raise Program_Error;
13711 end case;
13712 end if;
13713
13714 -- If check kind was not Disable, then continue pragma analysis
13715
13716 Expr := Get_Pragma_Arg (Arg2);
13717
13718 -- Mark the pragma (or, if rewritten from an aspect, the original
13719 -- aspect) as enabled. Nothing to do for an internally generated
13720 -- check for a dynamic predicate.
13721
13722 if Is_Checked (N)
13723 and then not Split_PPC (N)
13724 and then Cname /= Name_Dynamic_Predicate
13725 then
13726 Set_SCO_Pragma_Enabled (Loc);
13727 end if;
13728
13729 -- Deal with analyzing the string argument. If checks are not
13730 -- on we don't want any expansion (since such expansion would
13731 -- not get properly deleted) but we do want to analyze (to get
13732 -- proper references). The Preanalyze_And_Resolve routine does
13733 -- just what we want. Ditto if pragma is active, because it will
13734 -- be rewritten as an if-statement whose analysis will complete
13735 -- analysis and expansion of the string message. This makes a
13736 -- difference in the unusual case where the expression for the
13737 -- string may have a side effect, such as raising an exception.
13738 -- This is mandated by RM 11.4.2, which specifies that the string
13739 -- expression is only evaluated if the check fails and
13740 -- Assertion_Error is to be raised.
13741
13742 if Arg_Count = 3 then
13743 Preanalyze_And_Resolve (Str, Standard_String);
13744 end if;
13745
13746 -- Now you might think we could just do the same with the Boolean
13747 -- expression if checks are off (and expansion is on) and then
13748 -- rewrite the check as a null statement. This would work but we
13749 -- would lose the useful warnings about an assertion being bound
13750 -- to fail even if assertions are turned off.
13751
13752 -- So instead we wrap the boolean expression in an if statement
13753 -- that looks like:
13754
13755 -- if False and then condition then
13756 -- null;
13757 -- end if;
13758
13759 -- The reason we do this rewriting during semantic analysis rather
13760 -- than as part of normal expansion is that we cannot analyze and
13761 -- expand the code for the boolean expression directly, or it may
13762 -- cause insertion of actions that would escape the attempt to
13763 -- suppress the check code.
13764
13765 -- Note that the Sloc for the if statement corresponds to the
13766 -- argument condition, not the pragma itself. The reason for
13767 -- this is that we may generate a warning if the condition is
13768 -- False at compile time, and we do not want to delete this
13769 -- warning when we delete the if statement.
13770
13771 if Expander_Active and Is_Ignored (N) then
13772 Eloc := Sloc (Expr);
13773
13774 Rewrite (N,
13775 Make_If_Statement (Eloc,
13776 Condition =>
13777 Make_And_Then (Eloc,
13778 Left_Opnd => Make_Identifier (Eloc, Name_False),
13779 Right_Opnd => Expr),
13780 Then_Statements => New_List (
13781 Make_Null_Statement (Eloc))));
13782
13783 -- Now go ahead and analyze the if statement
13784
13785 In_Assertion_Expr := In_Assertion_Expr + 1;
13786
13787 -- One rather special treatment. If we are now in Eliminated
13788 -- overflow mode, then suppress overflow checking since we do
13789 -- not want to drag in the bignum stuff if we are in Ignore
13790 -- mode anyway. This is particularly important if we are using
13791 -- a configurable run time that does not support bignum ops.
13792
13793 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
13794 declare
13795 Svo : constant Boolean :=
13796 Scope_Suppress.Suppress (Overflow_Check);
13797 begin
13798 Scope_Suppress.Overflow_Mode_Assertions := Strict;
13799 Scope_Suppress.Suppress (Overflow_Check) := True;
13800 Analyze (N);
13801 Scope_Suppress.Suppress (Overflow_Check) := Svo;
13802 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
13803 end;
13804
13805 -- Not that special case
13806
13807 else
13808 Analyze (N);
13809 end if;
13810
13811 -- All done with this check
13812
13813 In_Assertion_Expr := In_Assertion_Expr - 1;
13814
13815 -- Check is active or expansion not active. In these cases we can
13816 -- just go ahead and analyze the boolean with no worries.
13817
13818 else
13819 In_Assertion_Expr := In_Assertion_Expr + 1;
13820 Analyze_And_Resolve (Expr, Any_Boolean);
13821 In_Assertion_Expr := In_Assertion_Expr - 1;
13822 end if;
13823
13824 Restore_Ghost_Region (Saved_GM, Saved_IGR);
13825 end Check;
13826
13827 --------------------------
13828 -- Check_Float_Overflow --
13829 --------------------------
13830
13831 -- pragma Check_Float_Overflow;
13832
13833 when Pragma_Check_Float_Overflow =>
13834 GNAT_Pragma;
13835 Check_Valid_Configuration_Pragma;
13836 Check_Arg_Count (0);
13837 Check_Float_Overflow := not Machine_Overflows_On_Target;
13838
13839 ----------------
13840 -- Check_Name --
13841 ----------------
13842
13843 -- pragma Check_Name (check_IDENTIFIER);
13844
13845 when Pragma_Check_Name =>
13846 GNAT_Pragma;
13847 Check_No_Identifiers;
13848 Check_Valid_Configuration_Pragma;
13849 Check_Arg_Count (1);
13850 Check_Arg_Is_Identifier (Arg1);
13851
13852 declare
13853 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
13854
13855 begin
13856 for J in Check_Names.First .. Check_Names.Last loop
13857 if Check_Names.Table (J) = Nam then
13858 return;
13859 end if;
13860 end loop;
13861
13862 Check_Names.Append (Nam);
13863 end;
13864
13865 ------------------
13866 -- Check_Policy --
13867 ------------------
13868
13869 -- This is the old style syntax, which is still allowed in all modes:
13870
13871 -- pragma Check_Policy ([Name =>] CHECK_KIND
13872 -- [Policy =>] POLICY_IDENTIFIER);
13873
13874 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
13875
13876 -- CHECK_KIND ::= IDENTIFIER |
13877 -- Pre'Class |
13878 -- Post'Class |
13879 -- Type_Invariant'Class |
13880 -- Invariant'Class
13881
13882 -- This is the new style syntax, compatible with Assertion_Policy
13883 -- and also allowed in all modes.
13884
13885 -- Pragma Check_Policy (
13886 -- CHECK_KIND => POLICY_IDENTIFIER
13887 -- {, CHECK_KIND => POLICY_IDENTIFIER});
13888
13889 -- Note: the identifiers Name and Policy are not allowed as
13890 -- Check_Kind values. This avoids ambiguities between the old and
13891 -- new form syntax.
13892
13893 when Pragma_Check_Policy => Check_Policy : declare
13894 Kind : Node_Id;
13895
13896 begin
13897 GNAT_Pragma;
13898 Check_At_Least_N_Arguments (1);
13899
13900 -- A Check_Policy pragma can appear either as a configuration
13901 -- pragma, or in a declarative part or a package spec (see RM
13902 -- 11.5(5) for rules for Suppress/Unsuppress which are also
13903 -- followed for Check_Policy).
13904
13905 if not Is_Configuration_Pragma then
13906 Check_Is_In_Decl_Part_Or_Package_Spec;
13907 end if;
13908
13909 -- Figure out if we have the old or new syntax. We have the
13910 -- old syntax if the first argument has no identifier, or the
13911 -- identifier is Name.
13912
13913 if Nkind (Arg1) /= N_Pragma_Argument_Association
13914 or else Chars (Arg1) in No_Name | Name_Name
13915 then
13916 -- Old syntax
13917
13918 Check_Arg_Count (2);
13919 Check_Optional_Identifier (Arg1, Name_Name);
13920 Kind := Get_Pragma_Arg (Arg1);
13921 Rewrite_Assertion_Kind (Kind,
13922 From_Policy => Comes_From_Source (N));
13923 Check_Arg_Is_Identifier (Arg1);
13924
13925 -- Check forbidden check kind
13926
13927 if Chars (Kind) in Name_Name | Name_Policy then
13928 Error_Msg_Name_2 := Chars (Kind);
13929 Error_Pragma_Arg
13930 ("pragma% does not allow% as check name", Arg1);
13931 end if;
13932
13933 -- Check policy
13934
13935 Check_Optional_Identifier (Arg2, Name_Policy);
13936 Check_Arg_Is_One_Of
13937 (Arg2,
13938 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
13939
13940 -- And chain pragma on the Check_Policy_List for search
13941
13942 Set_Next_Pragma (N, Opt.Check_Policy_List);
13943 Opt.Check_Policy_List := N;
13944
13945 -- For the new syntax, what we do is to convert each argument to
13946 -- an old syntax equivalent. We do that because we want to chain
13947 -- old style Check_Policy pragmas for the search (we don't want
13948 -- to have to deal with multiple arguments in the search).
13949
13950 else
13951 declare
13952 Arg : Node_Id;
13953 Argx : Node_Id;
13954 LocP : Source_Ptr;
13955 New_P : Node_Id;
13956
13957 begin
13958 Arg := Arg1;
13959 while Present (Arg) loop
13960 LocP := Sloc (Arg);
13961 Argx := Get_Pragma_Arg (Arg);
13962
13963 -- Kind must be specified
13964
13965 if Nkind (Arg) /= N_Pragma_Argument_Association
13966 or else Chars (Arg) = No_Name
13967 then
13968 Error_Pragma_Arg
13969 ("missing assertion kind for pragma%", Arg);
13970 end if;
13971
13972 -- Construct equivalent old form syntax Check_Policy
13973 -- pragma and insert it to get remaining checks.
13974
13975 New_P :=
13976 Make_Pragma (LocP,
13977 Chars => Name_Check_Policy,
13978 Pragma_Argument_Associations => New_List (
13979 Make_Pragma_Argument_Association (LocP,
13980 Expression =>
13981 Make_Identifier (LocP, Chars (Arg))),
13982 Make_Pragma_Argument_Association (Sloc (Argx),
13983 Expression => Argx)));
13984
13985 Arg := Next (Arg);
13986
13987 -- For a configuration pragma, insert old form in
13988 -- the corresponding file.
13989
13990 if Is_Configuration_Pragma then
13991 Insert_After (N, New_P);
13992 Analyze (New_P);
13993
13994 else
13995 Insert_Action (N, New_P);
13996 end if;
13997 end loop;
13998
13999 -- Rewrite original Check_Policy pragma to null, since we
14000 -- have converted it into a series of old syntax pragmas.
14001
14002 Rewrite (N, Make_Null_Statement (Loc));
14003 Analyze (N);
14004 end;
14005 end if;
14006 end Check_Policy;
14007
14008 -------------
14009 -- Comment --
14010 -------------
14011
14012 -- pragma Comment (static_string_EXPRESSION)
14013
14014 -- Processing for pragma Comment shares the circuitry for pragma
14015 -- Ident. The only differences are that Ident enforces a limit of 31
14016 -- characters on its argument, and also enforces limitations on
14017 -- placement for DEC compatibility. Pragma Comment shares neither of
14018 -- these restrictions.
14019
14020 -------------------
14021 -- Common_Object --
14022 -------------------
14023
14024 -- pragma Common_Object (
14025 -- [Internal =>] LOCAL_NAME
14026 -- [, [External =>] EXTERNAL_SYMBOL]
14027 -- [, [Size =>] EXTERNAL_SYMBOL]);
14028
14029 -- Processing for this pragma is shared with Psect_Object
14030
14031 ----------------------------------------------
14032 -- Compile_Time_Error, Compile_Time_Warning --
14033 ----------------------------------------------
14034
14035 -- pragma Compile_Time_Error
14036 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14037
14038 -- pragma Compile_Time_Warning
14039 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14040
14041 when Pragma_Compile_Time_Error | Pragma_Compile_Time_Warning =>
14042 GNAT_Pragma;
14043 Process_Compile_Time_Warning_Or_Error;
14044
14045 ---------------------------
14046 -- Compiler_Unit_Warning --
14047 ---------------------------
14048
14049 -- pragma Compiler_Unit_Warning;
14050
14051 -- Historical note
14052
14053 -- Originally, we had only pragma Compiler_Unit, and it resulted in
14054 -- errors not warnings. This means that we had introduced a big extra
14055 -- inertia to compiler changes, since even if we implemented a new
14056 -- feature, and even if all versions to be used for bootstrapping
14057 -- implemented this new feature, we could not use it, since old
14058 -- compilers would give errors for using this feature in units
14059 -- having Compiler_Unit pragmas.
14060
14061 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
14062 -- problem. We no longer have any units mentioning Compiler_Unit,
14063 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
14064 -- and thus generates a warning which can be ignored. So that deals
14065 -- with the problem of old compilers not implementing the newer form
14066 -- of the pragma.
14067
14068 -- Newer compilers recognize the new pragma, but generate warning
14069 -- messages instead of errors, which again can be ignored in the
14070 -- case of an old compiler which implements a wanted new feature
14071 -- but at the time felt like warning about it for older compilers.
14072
14073 -- We retain Compiler_Unit so that new compilers can be used to build
14074 -- older run-times that use this pragma. That's an unusual case, but
14075 -- it's easy enough to handle, so why not?
14076
14077 when Pragma_Compiler_Unit
14078 | Pragma_Compiler_Unit_Warning
14079 =>
14080 GNAT_Pragma;
14081 Check_Arg_Count (0);
14082
14083 -- Only recognized in main unit
14084
14085 if Current_Sem_Unit = Main_Unit then
14086 Compiler_Unit := True;
14087 end if;
14088
14089 -----------------------------
14090 -- Complete_Representation --
14091 -----------------------------
14092
14093 -- pragma Complete_Representation;
14094
14095 when Pragma_Complete_Representation =>
14096 GNAT_Pragma;
14097 Check_Arg_Count (0);
14098
14099 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
14100 Error_Pragma
14101 ("pragma & must appear within record representation clause");
14102 end if;
14103
14104 ----------------------------
14105 -- Complex_Representation --
14106 ----------------------------
14107
14108 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
14109
14110 when Pragma_Complex_Representation => Complex_Representation : declare
14111 E_Id : Node_Id;
14112 E : Entity_Id;
14113 Ent : Entity_Id;
14114
14115 begin
14116 GNAT_Pragma;
14117 Check_Arg_Count (1);
14118 Check_Optional_Identifier (Arg1, Name_Entity);
14119 Check_Arg_Is_Local_Name (Arg1);
14120 E_Id := Get_Pragma_Arg (Arg1);
14121
14122 if Etype (E_Id) = Any_Type then
14123 return;
14124 end if;
14125
14126 E := Entity (E_Id);
14127
14128 if not Is_Record_Type (E) then
14129 Error_Pragma_Arg
14130 ("argument for pragma% must be record type", Arg1);
14131 end if;
14132
14133 Ent := First_Entity (E);
14134
14135 if No (Ent)
14136 or else No (Next_Entity (Ent))
14137 or else Present (Next_Entity (Next_Entity (Ent)))
14138 or else not Is_Floating_Point_Type (Etype (Ent))
14139 or else Etype (Ent) /= Etype (Next_Entity (Ent))
14140 then
14141 Error_Pragma_Arg
14142 ("record for pragma% must have two fields of the same "
14143 & "floating-point type", Arg1);
14144
14145 else
14146 Set_Has_Complex_Representation (Base_Type (E));
14147
14148 -- We need to treat the type has having a non-standard
14149 -- representation, for back-end purposes, even though in
14150 -- general a complex will have the default representation
14151 -- of a record with two real components.
14152
14153 Set_Has_Non_Standard_Rep (Base_Type (E));
14154 end if;
14155 end Complex_Representation;
14156
14157 -------------------------
14158 -- Component_Alignment --
14159 -------------------------
14160
14161 -- pragma Component_Alignment (
14162 -- [Form =>] ALIGNMENT_CHOICE
14163 -- [, [Name =>] type_LOCAL_NAME]);
14164 --
14165 -- ALIGNMENT_CHOICE ::=
14166 -- Component_Size
14167 -- | Component_Size_4
14168 -- | Storage_Unit
14169 -- | Default
14170
14171 when Pragma_Component_Alignment => Component_AlignmentP : declare
14172 Args : Args_List (1 .. 2);
14173 Names : constant Name_List (1 .. 2) := (
14174 Name_Form,
14175 Name_Name);
14176
14177 Form : Node_Id renames Args (1);
14178 Name : Node_Id renames Args (2);
14179
14180 Atype : Component_Alignment_Kind;
14181 Typ : Entity_Id;
14182
14183 begin
14184 GNAT_Pragma;
14185 Gather_Associations (Names, Args);
14186
14187 if No (Form) then
14188 Error_Pragma ("missing Form argument for pragma%");
14189 end if;
14190
14191 Check_Arg_Is_Identifier (Form);
14192
14193 -- Get proper alignment, note that Default = Component_Size on all
14194 -- machines we have so far, and we want to set this value rather
14195 -- than the default value to indicate that it has been explicitly
14196 -- set (and thus will not get overridden by the default component
14197 -- alignment for the current scope)
14198
14199 if Chars (Form) = Name_Component_Size then
14200 Atype := Calign_Component_Size;
14201
14202 elsif Chars (Form) = Name_Component_Size_4 then
14203 Atype := Calign_Component_Size_4;
14204
14205 elsif Chars (Form) = Name_Default then
14206 Atype := Calign_Component_Size;
14207
14208 elsif Chars (Form) = Name_Storage_Unit then
14209 Atype := Calign_Storage_Unit;
14210
14211 else
14212 Error_Pragma_Arg
14213 ("invalid Form parameter for pragma%", Form);
14214 end if;
14215
14216 -- The pragma appears in a configuration file
14217
14218 if No (Parent (N)) then
14219 Check_Valid_Configuration_Pragma;
14220
14221 -- Capture the component alignment in a global variable when
14222 -- the pragma appears in a configuration file. Note that the
14223 -- scope stack is empty at this point and cannot be used to
14224 -- store the alignment value.
14225
14226 Configuration_Component_Alignment := Atype;
14227
14228 -- Case with no name, supplied, affects scope table entry
14229
14230 elsif No (Name) then
14231 Scope_Stack.Table
14232 (Scope_Stack.Last).Component_Alignment_Default := Atype;
14233
14234 -- Case of name supplied
14235
14236 else
14237 Check_Arg_Is_Local_Name (Name);
14238 Find_Type (Name);
14239 Typ := Entity (Name);
14240
14241 if Typ = Any_Type
14242 or else Rep_Item_Too_Early (Typ, N)
14243 then
14244 return;
14245 else
14246 Typ := Underlying_Type (Typ);
14247 end if;
14248
14249 if not Is_Record_Type (Typ)
14250 and then not Is_Array_Type (Typ)
14251 then
14252 Error_Pragma_Arg
14253 ("Name parameter of pragma% must identify record or "
14254 & "array type", Name);
14255 end if;
14256
14257 -- An explicit Component_Alignment pragma overrides an
14258 -- implicit pragma Pack, but not an explicit one.
14259
14260 if not Has_Pragma_Pack (Base_Type (Typ)) then
14261 Set_Is_Packed (Base_Type (Typ), False);
14262 Set_Component_Alignment (Base_Type (Typ), Atype);
14263 end if;
14264 end if;
14265 end Component_AlignmentP;
14266
14267 --------------------------------
14268 -- Constant_After_Elaboration --
14269 --------------------------------
14270
14271 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
14272
14273 when Pragma_Constant_After_Elaboration => Constant_After_Elaboration :
14274 declare
14275 Obj_Decl : Node_Id;
14276 Obj_Id : Entity_Id;
14277
14278 begin
14279 GNAT_Pragma;
14280 Check_No_Identifiers;
14281 Check_At_Most_N_Arguments (1);
14282
14283 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
14284
14285 if Nkind (Obj_Decl) /= N_Object_Declaration then
14286 Pragma_Misplaced;
14287 return;
14288 end if;
14289
14290 Obj_Id := Defining_Entity (Obj_Decl);
14291
14292 -- The object declaration must be a library-level variable which
14293 -- is either explicitly initialized or obtains a value during the
14294 -- elaboration of a package body (SPARK RM 3.3.1).
14295
14296 if Ekind (Obj_Id) = E_Variable then
14297 if not Is_Library_Level_Entity (Obj_Id) then
14298 Error_Pragma
14299 ("pragma % must apply to a library level variable");
14300 return;
14301 end if;
14302
14303 -- Otherwise the pragma applies to a constant, which is illegal
14304
14305 else
14306 Error_Pragma ("pragma % must apply to a variable declaration");
14307 return;
14308 end if;
14309
14310 -- A pragma that applies to a Ghost entity becomes Ghost for the
14311 -- purposes of legality checks and removal of ignored Ghost code.
14312
14313 Mark_Ghost_Pragma (N, Obj_Id);
14314
14315 -- Chain the pragma on the contract for completeness
14316
14317 Add_Contract_Item (N, Obj_Id);
14318
14319 -- Analyze the Boolean expression (if any)
14320
14321 if Present (Arg1) then
14322 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
14323 end if;
14324 end Constant_After_Elaboration;
14325
14326 --------------------
14327 -- Contract_Cases --
14328 --------------------
14329
14330 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
14331
14332 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
14333
14334 -- CASE_GUARD ::= boolean_EXPRESSION | others
14335
14336 -- CONSEQUENCE ::= boolean_EXPRESSION
14337
14338 -- Characteristics:
14339
14340 -- * Analysis - The annotation undergoes initial checks to verify
14341 -- the legal placement and context. Secondary checks preanalyze the
14342 -- expressions in:
14343
14344 -- Analyze_Contract_Cases_In_Decl_Part
14345
14346 -- * Expansion - The annotation is expanded during the expansion of
14347 -- the related subprogram [body] contract as performed in:
14348
14349 -- Expand_Subprogram_Contract
14350
14351 -- * Template - The annotation utilizes the generic template of the
14352 -- related subprogram [body] when it is:
14353
14354 -- aspect on subprogram declaration
14355 -- aspect on stand-alone subprogram body
14356 -- pragma on stand-alone subprogram body
14357
14358 -- The annotation must prepare its own template when it is:
14359
14360 -- pragma on subprogram declaration
14361
14362 -- * Globals - Capture of global references must occur after full
14363 -- analysis.
14364
14365 -- * Instance - The annotation is instantiated automatically when
14366 -- the related generic subprogram [body] is instantiated except for
14367 -- the "pragma on subprogram declaration" case. In that scenario
14368 -- the annotation must instantiate itself.
14369
14370 when Pragma_Contract_Cases => Contract_Cases : declare
14371 Spec_Id : Entity_Id;
14372 Subp_Decl : Node_Id;
14373 Subp_Spec : Node_Id;
14374
14375 begin
14376 GNAT_Pragma;
14377 Check_No_Identifiers;
14378 Check_Arg_Count (1);
14379
14380 -- Ensure the proper placement of the pragma. Contract_Cases must
14381 -- be associated with a subprogram declaration or a body that acts
14382 -- as a spec.
14383
14384 Subp_Decl :=
14385 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
14386
14387 -- Entry
14388
14389 if Nkind (Subp_Decl) = N_Entry_Declaration then
14390 null;
14391
14392 -- Generic subprogram
14393
14394 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
14395 null;
14396
14397 -- Body acts as spec
14398
14399 elsif Nkind (Subp_Decl) = N_Subprogram_Body
14400 and then No (Corresponding_Spec (Subp_Decl))
14401 then
14402 null;
14403
14404 -- Body stub acts as spec
14405
14406 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
14407 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
14408 then
14409 null;
14410
14411 -- Subprogram
14412
14413 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
14414 Subp_Spec := Specification (Subp_Decl);
14415
14416 -- Pragma Contract_Cases is forbidden on null procedures, as
14417 -- this may lead to potential ambiguities in behavior when
14418 -- interface null procedures are involved.
14419
14420 if Nkind (Subp_Spec) = N_Procedure_Specification
14421 and then Null_Present (Subp_Spec)
14422 then
14423 Error_Msg_N (Fix_Error
14424 ("pragma % cannot apply to null procedure"), N);
14425 return;
14426 end if;
14427
14428 else
14429 Pragma_Misplaced;
14430 return;
14431 end if;
14432
14433 Spec_Id := Unique_Defining_Entity (Subp_Decl);
14434
14435 -- A pragma that applies to a Ghost entity becomes Ghost for the
14436 -- purposes of legality checks and removal of ignored Ghost code.
14437
14438 Mark_Ghost_Pragma (N, Spec_Id);
14439 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
14440
14441 -- Chain the pragma on the contract for further processing by
14442 -- Analyze_Contract_Cases_In_Decl_Part.
14443
14444 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
14445
14446 -- Fully analyze the pragma when it appears inside an entry
14447 -- or subprogram body because it cannot benefit from forward
14448 -- references.
14449
14450 if Nkind (Subp_Decl) in N_Entry_Body
14451 | N_Subprogram_Body
14452 | N_Subprogram_Body_Stub
14453 then
14454 -- The legality checks of pragma Contract_Cases are affected by
14455 -- the SPARK mode in effect and the volatility of the context.
14456 -- Analyze all pragmas in a specific order.
14457
14458 Analyze_If_Present (Pragma_SPARK_Mode);
14459 Analyze_If_Present (Pragma_Volatile_Function);
14460 Analyze_Contract_Cases_In_Decl_Part (N);
14461 end if;
14462 end Contract_Cases;
14463
14464 ----------------
14465 -- Controlled --
14466 ----------------
14467
14468 -- pragma Controlled (first_subtype_LOCAL_NAME);
14469
14470 when Pragma_Controlled => Controlled : declare
14471 Arg : Node_Id;
14472
14473 begin
14474 Check_No_Identifiers;
14475 Check_Arg_Count (1);
14476 Check_Arg_Is_Local_Name (Arg1);
14477 Arg := Get_Pragma_Arg (Arg1);
14478
14479 if not Is_Entity_Name (Arg)
14480 or else not Is_Access_Type (Entity (Arg))
14481 then
14482 Error_Pragma_Arg ("pragma% requires access type", Arg1);
14483 else
14484 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
14485 end if;
14486 end Controlled;
14487
14488 ----------------
14489 -- Convention --
14490 ----------------
14491
14492 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
14493 -- [Entity =>] LOCAL_NAME);
14494
14495 when Pragma_Convention => Convention : declare
14496 C : Convention_Id;
14497 E : Entity_Id;
14498 pragma Warnings (Off, C);
14499 pragma Warnings (Off, E);
14500
14501 begin
14502 Check_Arg_Order ((Name_Convention, Name_Entity));
14503 Check_Ada_83_Warning;
14504 Check_Arg_Count (2);
14505 Process_Convention (C, E);
14506
14507 -- A pragma that applies to a Ghost entity becomes Ghost for the
14508 -- purposes of legality checks and removal of ignored Ghost code.
14509
14510 Mark_Ghost_Pragma (N, E);
14511 end Convention;
14512
14513 ---------------------------
14514 -- Convention_Identifier --
14515 ---------------------------
14516
14517 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
14518 -- [Convention =>] convention_IDENTIFIER);
14519
14520 when Pragma_Convention_Identifier => Convention_Identifier : declare
14521 Idnam : Name_Id;
14522 Cname : Name_Id;
14523
14524 begin
14525 GNAT_Pragma;
14526 Check_Arg_Order ((Name_Name, Name_Convention));
14527 Check_Arg_Count (2);
14528 Check_Optional_Identifier (Arg1, Name_Name);
14529 Check_Optional_Identifier (Arg2, Name_Convention);
14530 Check_Arg_Is_Identifier (Arg1);
14531 Check_Arg_Is_Identifier (Arg2);
14532 Idnam := Chars (Get_Pragma_Arg (Arg1));
14533 Cname := Chars (Get_Pragma_Arg (Arg2));
14534
14535 if Is_Convention_Name (Cname) then
14536 Record_Convention_Identifier
14537 (Idnam, Get_Convention_Id (Cname));
14538 else
14539 Error_Pragma_Arg
14540 ("second arg for % pragma must be convention", Arg2);
14541 end if;
14542 end Convention_Identifier;
14543
14544 ---------------
14545 -- CPP_Class --
14546 ---------------
14547
14548 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
14549
14550 when Pragma_CPP_Class =>
14551 GNAT_Pragma;
14552
14553 if Warn_On_Obsolescent_Feature then
14554 Error_Msg_N
14555 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
14556 & "effect; replace it by pragma import?j?", N);
14557 end if;
14558
14559 Check_Arg_Count (1);
14560
14561 Rewrite (N,
14562 Make_Pragma (Loc,
14563 Chars => Name_Import,
14564 Pragma_Argument_Associations => New_List (
14565 Make_Pragma_Argument_Association (Loc,
14566 Expression => Make_Identifier (Loc, Name_CPP)),
14567 New_Copy (First (Pragma_Argument_Associations (N))))));
14568 Analyze (N);
14569
14570 ---------------------
14571 -- CPP_Constructor --
14572 ---------------------
14573
14574 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
14575 -- [, [External_Name =>] static_string_EXPRESSION ]
14576 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14577
14578 when Pragma_CPP_Constructor => CPP_Constructor : declare
14579 Elmt : Elmt_Id;
14580 Id : Entity_Id;
14581 Def_Id : Entity_Id;
14582 Tag_Typ : Entity_Id;
14583
14584 begin
14585 GNAT_Pragma;
14586 Check_At_Least_N_Arguments (1);
14587 Check_At_Most_N_Arguments (3);
14588 Check_Optional_Identifier (Arg1, Name_Entity);
14589 Check_Arg_Is_Local_Name (Arg1);
14590
14591 Id := Get_Pragma_Arg (Arg1);
14592 Find_Program_Unit_Name (Id);
14593
14594 -- If we did not find the name, we are done
14595
14596 if Etype (Id) = Any_Type then
14597 return;
14598 end if;
14599
14600 Def_Id := Entity (Id);
14601
14602 -- Check if already defined as constructor
14603
14604 if Is_Constructor (Def_Id) then
14605 Error_Msg_N
14606 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
14607 return;
14608 end if;
14609
14610 if Ekind (Def_Id) = E_Function
14611 and then (Is_CPP_Class (Etype (Def_Id))
14612 or else (Is_Class_Wide_Type (Etype (Def_Id))
14613 and then
14614 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
14615 then
14616 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
14617 Error_Msg_N
14618 ("'C'P'P constructor must be defined in the scope of "
14619 & "its returned type", Arg1);
14620 end if;
14621
14622 if Arg_Count >= 2 then
14623 Set_Imported (Def_Id);
14624 Set_Is_Public (Def_Id);
14625 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
14626 end if;
14627
14628 Set_Has_Completion (Def_Id);
14629 Set_Is_Constructor (Def_Id);
14630 Set_Convention (Def_Id, Convention_CPP);
14631
14632 -- Imported C++ constructors are not dispatching primitives
14633 -- because in C++ they don't have a dispatch table slot.
14634 -- However, in Ada the constructor has the profile of a
14635 -- function that returns a tagged type and therefore it has
14636 -- been treated as a primitive operation during semantic
14637 -- analysis. We now remove it from the list of primitive
14638 -- operations of the type.
14639
14640 if Is_Tagged_Type (Etype (Def_Id))
14641 and then not Is_Class_Wide_Type (Etype (Def_Id))
14642 and then Is_Dispatching_Operation (Def_Id)
14643 then
14644 Tag_Typ := Etype (Def_Id);
14645
14646 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
14647 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
14648 Next_Elmt (Elmt);
14649 end loop;
14650
14651 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
14652 Set_Is_Dispatching_Operation (Def_Id, False);
14653 end if;
14654
14655 -- For backward compatibility, if the constructor returns a
14656 -- class wide type, and we internally change the return type to
14657 -- the corresponding root type.
14658
14659 if Is_Class_Wide_Type (Etype (Def_Id)) then
14660 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
14661 end if;
14662 else
14663 Error_Pragma_Arg
14664 ("pragma% requires function returning a 'C'P'P_Class type",
14665 Arg1);
14666 end if;
14667 end CPP_Constructor;
14668
14669 -----------------
14670 -- CPP_Virtual --
14671 -----------------
14672
14673 when Pragma_CPP_Virtual =>
14674 GNAT_Pragma;
14675
14676 if Warn_On_Obsolescent_Feature then
14677 Error_Msg_N
14678 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
14679 & "effect?j?", N);
14680 end if;
14681
14682 --------------------
14683 -- CUDA_Execute --
14684 --------------------
14685
14686 -- pragma CUDA_Execute (PROCEDURE_CALL_STATEMENT,
14687 -- EXPRESSION,
14688 -- EXPRESSION,
14689 -- [, EXPRESSION
14690 -- [, EXPRESSION]]);
14691
14692 when Pragma_CUDA_Execute => CUDA_Execute : declare
14693
14694 function Is_Acceptable_Dim3 (N : Node_Id) return Boolean;
14695 -- Returns True if N is an acceptable argument for CUDA_Execute,
14696 -- False otherwise.
14697
14698 ------------------------
14699 -- Is_Acceptable_Dim3 --
14700 ------------------------
14701
14702 function Is_Acceptable_Dim3 (N : Node_Id) return Boolean is
14703 Expr : Node_Id;
14704 begin
14705 if Is_RTE (Etype (N), RE_Dim3)
14706 or else Is_Integer_Type (Etype (N))
14707 then
14708 return True;
14709 end if;
14710
14711 if Nkind (N) = N_Aggregate
14712 and then List_Length (Expressions (N)) = 3
14713 then
14714 Expr := First (Expressions (N));
14715 while Present (Expr) loop
14716 Analyze_And_Resolve (Expr, Any_Integer);
14717 Next (Expr);
14718 end loop;
14719 return True;
14720 end if;
14721
14722 return False;
14723 end Is_Acceptable_Dim3;
14724
14725 -- Local variables
14726
14727 Block_Dimensions : constant Node_Id := Get_Pragma_Arg (Arg3);
14728 Grid_Dimensions : constant Node_Id := Get_Pragma_Arg (Arg2);
14729 Kernel_Call : constant Node_Id := Get_Pragma_Arg (Arg1);
14730 Shared_Memory : Node_Id;
14731 Stream : Node_Id;
14732
14733 -- Start of processing for CUDA_Execute
14734
14735 begin
14736 GNAT_Pragma;
14737 Check_At_Least_N_Arguments (3);
14738 Check_At_Most_N_Arguments (5);
14739
14740 Analyze_And_Resolve (Kernel_Call);
14741 if Nkind (Kernel_Call) /= N_Function_Call
14742 or else Etype (Kernel_Call) /= Standard_Void_Type
14743 then
14744 -- In `pragma CUDA_Execute (Kernel_Call (...), ...)`,
14745 -- GNAT sees Kernel_Call as an N_Function_Call since
14746 -- Kernel_Call "looks" like an expression. However, only
14747 -- procedures can be kernels, so to make things easier for the
14748 -- user the error message complains about Kernel_Call not being
14749 -- a procedure call.
14750
14751 Error_Msg_N ("first argument of & must be a procedure call", N);
14752 end if;
14753
14754 Analyze (Grid_Dimensions);
14755 if not Is_Acceptable_Dim3 (Grid_Dimensions) then
14756 Error_Msg_N
14757 ("second argument of & must be an Integer, Dim3 or aggregate "
14758 & "containing 3 Integers", N);
14759 end if;
14760
14761 Analyze (Block_Dimensions);
14762 if not Is_Acceptable_Dim3 (Block_Dimensions) then
14763 Error_Msg_N
14764 ("third argument of & must be an Integer, Dim3 or aggregate "
14765 & "containing 3 Integers", N);
14766 end if;
14767
14768 if Present (Arg4) then
14769 Shared_Memory := Get_Pragma_Arg (Arg4);
14770 Analyze_And_Resolve (Shared_Memory, Any_Integer);
14771
14772 if Present (Arg5) then
14773 Stream := Get_Pragma_Arg (Arg5);
14774 Analyze_And_Resolve (Stream, RTE (RE_Stream_T));
14775 end if;
14776 end if;
14777 end CUDA_Execute;
14778
14779 -----------------
14780 -- CUDA_Global --
14781 -----------------
14782
14783 -- pragma CUDA_Global (IDENTIFIER);
14784
14785 when Pragma_CUDA_Global => CUDA_Global : declare
14786 Arg_Node : Node_Id;
14787 Kernel_Proc : Entity_Id;
14788 Pack_Id : Entity_Id;
14789 begin
14790 GNAT_Pragma;
14791 Check_At_Least_N_Arguments (1);
14792 Check_At_Most_N_Arguments (1);
14793 Check_Optional_Identifier (Arg1, Name_Entity);
14794 Check_Arg_Is_Local_Name (Arg1);
14795
14796 Arg_Node := Get_Pragma_Arg (Arg1);
14797 Analyze (Arg_Node);
14798
14799 Kernel_Proc := Entity (Arg_Node);
14800 Pack_Id := Scope (Kernel_Proc);
14801
14802 if Ekind (Kernel_Proc) /= E_Procedure then
14803 Error_Msg_NE ("& must be a procedure", N, Kernel_Proc);
14804
14805 elsif Ekind (Pack_Id) /= E_Package
14806 or else not Is_Library_Level_Entity (Pack_Id)
14807 then
14808 Error_Msg_NE
14809 ("& must reside in a library-level package", N, Kernel_Proc);
14810
14811 else
14812 Set_Is_CUDA_Kernel (Kernel_Proc);
14813 Add_CUDA_Kernel (Pack_Id, Kernel_Proc);
14814 end if;
14815 end CUDA_Global;
14816
14817 ----------------
14818 -- CPP_Vtable --
14819 ----------------
14820
14821 when Pragma_CPP_Vtable =>
14822 GNAT_Pragma;
14823
14824 if Warn_On_Obsolescent_Feature then
14825 Error_Msg_N
14826 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
14827 & "effect?j?", N);
14828 end if;
14829
14830 ---------
14831 -- CPU --
14832 ---------
14833
14834 -- pragma CPU (EXPRESSION);
14835
14836 when Pragma_CPU => CPU : declare
14837 P : constant Node_Id := Parent (N);
14838 Arg : Node_Id;
14839 Ent : Entity_Id;
14840
14841 begin
14842 Ada_2012_Pragma;
14843 Check_No_Identifiers;
14844 Check_Arg_Count (1);
14845 Arg := Get_Pragma_Arg (Arg1);
14846
14847 -- Subprogram case
14848
14849 if Nkind (P) = N_Subprogram_Body then
14850 Check_In_Main_Program;
14851
14852 Analyze_And_Resolve (Arg, Any_Integer);
14853
14854 Ent := Defining_Unit_Name (Specification (P));
14855
14856 if Nkind (Ent) = N_Defining_Program_Unit_Name then
14857 Ent := Defining_Identifier (Ent);
14858 end if;
14859
14860 -- Must be static
14861
14862 if not Is_OK_Static_Expression (Arg) then
14863 Flag_Non_Static_Expr
14864 ("main subprogram affinity is not static!", Arg);
14865 raise Pragma_Exit;
14866
14867 -- If constraint error, then we already signalled an error
14868
14869 elsif Raises_Constraint_Error (Arg) then
14870 null;
14871
14872 -- Otherwise check in range
14873
14874 else
14875 declare
14876 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
14877 -- This is the entity System.Multiprocessors.CPU_Range;
14878
14879 Val : constant Uint := Expr_Value (Arg);
14880
14881 begin
14882 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
14883 or else
14884 Val > Expr_Value (Type_High_Bound (CPU_Id))
14885 then
14886 Error_Pragma_Arg
14887 ("main subprogram CPU is out of range", Arg1);
14888 end if;
14889 end;
14890 end if;
14891
14892 Set_Main_CPU
14893 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
14894
14895 -- Task case
14896
14897 elsif Nkind (P) = N_Task_Definition then
14898 Ent := Defining_Identifier (Parent (P));
14899
14900 -- The expression must be analyzed in the special manner
14901 -- described in "Handling of Default and Per-Object
14902 -- Expressions" in sem.ads.
14903
14904 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
14905
14906 -- See comment in Sem_Ch13 about the following restrictions
14907
14908 if Is_OK_Static_Expression (Arg) then
14909 if Expr_Value (Arg) = Uint_0 then
14910 Check_Restriction (No_Tasks_Unassigned_To_CPU, N);
14911 end if;
14912 else
14913 Check_Restriction (No_Dynamic_CPU_Assignment, N);
14914 end if;
14915
14916 -- Anything else is incorrect
14917
14918 else
14919 Pragma_Misplaced;
14920 end if;
14921
14922 -- Check duplicate pragma before we chain the pragma in the Rep
14923 -- Item chain of Ent.
14924
14925 Check_Duplicate_Pragma (Ent);
14926 Record_Rep_Item (Ent, N);
14927 end CPU;
14928
14929 --------------------
14930 -- Deadline_Floor --
14931 --------------------
14932
14933 -- pragma Deadline_Floor (time_span_EXPRESSION);
14934
14935 when Pragma_Deadline_Floor => Deadline_Floor : declare
14936 P : constant Node_Id := Parent (N);
14937 Arg : Node_Id;
14938 Ent : Entity_Id;
14939
14940 begin
14941 GNAT_Pragma;
14942 Check_No_Identifiers;
14943 Check_Arg_Count (1);
14944
14945 Arg := Get_Pragma_Arg (Arg1);
14946
14947 -- The expression must be analyzed in the special manner described
14948 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
14949
14950 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
14951
14952 -- Only protected types allowed
14953
14954 if Nkind (P) /= N_Protected_Definition then
14955 Pragma_Misplaced;
14956
14957 else
14958 Ent := Defining_Identifier (Parent (P));
14959
14960 -- Check duplicate pragma before we chain the pragma in the Rep
14961 -- Item chain of Ent.
14962
14963 Check_Duplicate_Pragma (Ent);
14964 Record_Rep_Item (Ent, N);
14965 end if;
14966 end Deadline_Floor;
14967
14968 -----------
14969 -- Debug --
14970 -----------
14971
14972 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
14973
14974 when Pragma_Debug => Debug : declare
14975 Cond : Node_Id;
14976 Call : Node_Id;
14977
14978 begin
14979 GNAT_Pragma;
14980
14981 -- The condition for executing the call is that the expander
14982 -- is active and that we are not ignoring this debug pragma.
14983
14984 Cond :=
14985 New_Occurrence_Of
14986 (Boolean_Literals
14987 (Expander_Active and then not Is_Ignored (N)),
14988 Loc);
14989
14990 if not Is_Ignored (N) then
14991 Set_SCO_Pragma_Enabled (Loc);
14992 end if;
14993
14994 if Arg_Count = 2 then
14995 Cond :=
14996 Make_And_Then (Loc,
14997 Left_Opnd => Relocate_Node (Cond),
14998 Right_Opnd => Get_Pragma_Arg (Arg1));
14999 Call := Get_Pragma_Arg (Arg2);
15000 else
15001 Call := Get_Pragma_Arg (Arg1);
15002 end if;
15003
15004 if Nkind (Call) in N_Expanded_Name
15005 | N_Function_Call
15006 | N_Identifier
15007 | N_Indexed_Component
15008 | N_Selected_Component
15009 then
15010 -- If this pragma Debug comes from source, its argument was
15011 -- parsed as a name form (which is syntactically identical).
15012 -- In a generic context a parameterless call will be left as
15013 -- an expanded name (if global) or selected_component if local.
15014 -- Change it to a procedure call statement now.
15015
15016 Change_Name_To_Procedure_Call_Statement (Call);
15017
15018 elsif Nkind (Call) = N_Procedure_Call_Statement then
15019
15020 -- Already in the form of a procedure call statement: nothing
15021 -- to do (could happen in case of an internally generated
15022 -- pragma Debug).
15023
15024 null;
15025
15026 else
15027 -- All other cases: diagnose error
15028
15029 Error_Msg
15030 ("argument of pragma ""Debug"" is not procedure call",
15031 Sloc (Call));
15032 return;
15033 end if;
15034
15035 -- Rewrite into a conditional with an appropriate condition. We
15036 -- wrap the procedure call in a block so that overhead from e.g.
15037 -- use of the secondary stack does not generate execution overhead
15038 -- for suppressed conditions.
15039
15040 -- Normally the analysis that follows will freeze the subprogram
15041 -- being called. However, if the call is to a null procedure,
15042 -- we want to freeze it before creating the block, because the
15043 -- analysis that follows may be done with expansion disabled, in
15044 -- which case the body will not be generated, leading to spurious
15045 -- errors.
15046
15047 if Nkind (Call) = N_Procedure_Call_Statement
15048 and then Is_Entity_Name (Name (Call))
15049 then
15050 Analyze (Name (Call));
15051 Freeze_Before (N, Entity (Name (Call)));
15052 end if;
15053
15054 Rewrite (N,
15055 Make_Implicit_If_Statement (N,
15056 Condition => Cond,
15057 Then_Statements => New_List (
15058 Make_Block_Statement (Loc,
15059 Handled_Statement_Sequence =>
15060 Make_Handled_Sequence_Of_Statements (Loc,
15061 Statements => New_List (Relocate_Node (Call)))))));
15062 Analyze (N);
15063
15064 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
15065 -- after analysis of the normally rewritten node, to capture all
15066 -- references to entities, which avoids issuing wrong warnings
15067 -- about unused entities.
15068
15069 if GNATprove_Mode then
15070 Rewrite (N, Make_Null_Statement (Loc));
15071 end if;
15072 end Debug;
15073
15074 ------------------
15075 -- Debug_Policy --
15076 ------------------
15077
15078 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
15079
15080 when Pragma_Debug_Policy =>
15081 GNAT_Pragma;
15082 Check_Arg_Count (1);
15083 Check_No_Identifiers;
15084 Check_Arg_Is_Identifier (Arg1);
15085
15086 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
15087 -- rewrite it that way, and let the rest of the checking come
15088 -- from analyzing the rewritten pragma.
15089
15090 Rewrite (N,
15091 Make_Pragma (Loc,
15092 Chars => Name_Check_Policy,
15093 Pragma_Argument_Associations => New_List (
15094 Make_Pragma_Argument_Association (Loc,
15095 Expression => Make_Identifier (Loc, Name_Debug)),
15096
15097 Make_Pragma_Argument_Association (Loc,
15098 Expression => Get_Pragma_Arg (Arg1)))));
15099 Analyze (N);
15100
15101 -------------------------------
15102 -- Default_Initial_Condition --
15103 -------------------------------
15104
15105 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
15106
15107 when Pragma_Default_Initial_Condition => DIC : declare
15108 Discard : Boolean;
15109 Stmt : Node_Id;
15110 Typ : Entity_Id;
15111
15112 begin
15113 GNAT_Pragma;
15114 Check_No_Identifiers;
15115 Check_At_Most_N_Arguments (2); -- Accounts for implicit type arg
15116
15117 Typ := Empty;
15118 Stmt := Prev (N);
15119 while Present (Stmt) loop
15120
15121 -- Skip prior pragmas, but check for duplicates
15122
15123 if Nkind (Stmt) = N_Pragma then
15124 if Pragma_Name (Stmt) = Pname then
15125 Duplication_Error
15126 (Prag => N,
15127 Prev => Stmt);
15128 raise Pragma_Exit;
15129 end if;
15130
15131 -- Skip internally generated code. Note that derived type
15132 -- declarations of untagged types with discriminants are
15133 -- rewritten as private type declarations.
15134
15135 elsif not Comes_From_Source (Stmt)
15136 and then Nkind (Stmt) /= N_Private_Type_Declaration
15137 then
15138 null;
15139
15140 -- The associated private type [extension] has been found, stop
15141 -- the search.
15142
15143 elsif Nkind (Stmt) in N_Private_Extension_Declaration
15144 | N_Private_Type_Declaration
15145 then
15146 Typ := Defining_Entity (Stmt);
15147 exit;
15148
15149 -- The pragma does not apply to a legal construct, issue an
15150 -- error and stop the analysis.
15151
15152 else
15153 Pragma_Misplaced;
15154 return;
15155 end if;
15156
15157 Stmt := Prev (Stmt);
15158 end loop;
15159
15160 -- The pragma does not apply to a legal construct, issue an error
15161 -- and stop the analysis.
15162
15163 if No (Typ) then
15164 Pragma_Misplaced;
15165 return;
15166 end if;
15167
15168 -- A pragma that applies to a Ghost entity becomes Ghost for the
15169 -- purposes of legality checks and removal of ignored Ghost code.
15170
15171 Mark_Ghost_Pragma (N, Typ);
15172
15173 -- The pragma signals that the type defines its own DIC assertion
15174 -- expression.
15175
15176 Set_Has_Own_DIC (Typ);
15177
15178 -- A type entity argument is appended to facilitate inheriting the
15179 -- aspect/pragma from parent types (see Build_DIC_Procedure_Body),
15180 -- though that extra argument isn't documented for the pragma.
15181
15182 if not Present (Arg2) then
15183 -- When the pragma has no arguments, create an argument with
15184 -- the value Empty, so the type name argument can be appended
15185 -- following it (since it's expected as the second argument).
15186
15187 if not Present (Arg1) then
15188 Set_Pragma_Argument_Associations (N, New_List (
15189 Make_Pragma_Argument_Association (Sloc (Typ),
15190 Expression => Empty)));
15191 end if;
15192
15193 Append_To
15194 (Pragma_Argument_Associations (N),
15195 Make_Pragma_Argument_Association (Sloc (Typ),
15196 Expression => New_Occurrence_Of (Typ, Sloc (Typ))));
15197 end if;
15198
15199 -- Chain the pragma on the rep item chain for further processing
15200
15201 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15202
15203 -- Create the declaration of the procedure which verifies the
15204 -- assertion expression of pragma DIC at runtime.
15205
15206 Build_DIC_Procedure_Declaration (Typ);
15207 end DIC;
15208
15209 ----------------------------------
15210 -- Default_Scalar_Storage_Order --
15211 ----------------------------------
15212
15213 -- pragma Default_Scalar_Storage_Order
15214 -- (High_Order_First | Low_Order_First);
15215
15216 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
15217 Default : Character;
15218
15219 begin
15220 GNAT_Pragma;
15221 Check_Arg_Count (1);
15222
15223 -- Default_Scalar_Storage_Order can appear as a configuration
15224 -- pragma, or in a declarative part of a package spec.
15225
15226 if not Is_Configuration_Pragma then
15227 Check_Is_In_Decl_Part_Or_Package_Spec;
15228 end if;
15229
15230 Check_No_Identifiers;
15231 Check_Arg_Is_One_Of
15232 (Arg1, Name_High_Order_First, Name_Low_Order_First);
15233 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15234 Default := Fold_Upper (Name_Buffer (1));
15235
15236 if not Support_Nondefault_SSO_On_Target
15237 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
15238 then
15239 if Warn_On_Unrecognized_Pragma then
15240 Error_Msg_N
15241 ("non-default Scalar_Storage_Order not supported "
15242 & "on target?g?", N);
15243 Error_Msg_N
15244 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
15245 end if;
15246
15247 -- Here set the specified default
15248
15249 else
15250 Opt.Default_SSO := Default;
15251 end if;
15252 end DSSO;
15253
15254 --------------------------
15255 -- Default_Storage_Pool --
15256 --------------------------
15257
15258 -- pragma Default_Storage_Pool (storage_pool_NAME | null | Standard);
15259
15260 when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
15261 Pool : Node_Id;
15262
15263 begin
15264 Ada_2012_Pragma;
15265 Check_Arg_Count (1);
15266
15267 -- Default_Storage_Pool can appear as a configuration pragma, or
15268 -- in a declarative part of a package spec.
15269
15270 if not Is_Configuration_Pragma then
15271 Check_Is_In_Decl_Part_Or_Package_Spec;
15272 end if;
15273
15274 if From_Aspect_Specification (N) then
15275 declare
15276 E : constant Entity_Id := Entity (Corresponding_Aspect (N));
15277 begin
15278 if not In_Open_Scopes (E) then
15279 Error_Msg_N
15280 ("aspect must apply to package or subprogram", N);
15281 end if;
15282 end;
15283 end if;
15284
15285 if Present (Arg1) then
15286 Pool := Get_Pragma_Arg (Arg1);
15287
15288 -- Case of Default_Storage_Pool (null);
15289
15290 if Nkind (Pool) = N_Null then
15291 Analyze (Pool);
15292
15293 -- This is an odd case, this is not really an expression,
15294 -- so we don't have a type for it. So just set the type to
15295 -- Empty.
15296
15297 Set_Etype (Pool, Empty);
15298
15299 -- Case of Default_Storage_Pool (Standard);
15300
15301 elsif Nkind (Pool) = N_Identifier
15302 and then Chars (Pool) = Name_Standard
15303 then
15304 Analyze (Pool);
15305
15306 if Entity (Pool) /= Standard_Standard then
15307 Error_Pragma_Arg
15308 ("package Standard is not directly visible", Arg1);
15309 end if;
15310
15311 -- Case of Default_Storage_Pool (storage_pool_NAME);
15312
15313 else
15314 -- If it's a configuration pragma, then the only allowed
15315 -- argument is "null".
15316
15317 if Is_Configuration_Pragma then
15318 Error_Pragma_Arg ("NULL or Standard expected", Arg1);
15319 end if;
15320
15321 -- The expected type for a non-"null" argument is
15322 -- Root_Storage_Pool'Class, and the pool must be a variable.
15323
15324 Analyze_And_Resolve
15325 (Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
15326
15327 if Is_Variable (Pool) then
15328
15329 -- A pragma that applies to a Ghost entity becomes Ghost
15330 -- for the purposes of legality checks and removal of
15331 -- ignored Ghost code.
15332
15333 Mark_Ghost_Pragma (N, Entity (Pool));
15334
15335 else
15336 Error_Pragma_Arg
15337 ("default storage pool must be a variable", Arg1);
15338 end if;
15339 end if;
15340
15341 -- Record the pool name (or null). Freeze.Freeze_Entity for an
15342 -- access type will use this information to set the appropriate
15343 -- attributes of the access type. If the pragma appears in a
15344 -- generic unit it is ignored, given that it may refer to a
15345 -- local entity.
15346
15347 if not Inside_A_Generic then
15348 Default_Pool := Pool;
15349 end if;
15350 end if;
15351 end Default_Storage_Pool;
15352
15353 -------------
15354 -- Depends --
15355 -------------
15356
15357 -- pragma Depends (DEPENDENCY_RELATION);
15358
15359 -- DEPENDENCY_RELATION ::=
15360 -- null
15361 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
15362
15363 -- DEPENDENCY_CLAUSE ::=
15364 -- OUTPUT_LIST =>[+] INPUT_LIST
15365 -- | NULL_DEPENDENCY_CLAUSE
15366
15367 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
15368
15369 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
15370
15371 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
15372
15373 -- OUTPUT ::= NAME | FUNCTION_RESULT
15374 -- INPUT ::= NAME
15375
15376 -- where FUNCTION_RESULT is a function Result attribute_reference
15377
15378 -- Characteristics:
15379
15380 -- * Analysis - The annotation undergoes initial checks to verify
15381 -- the legal placement and context. Secondary checks fully analyze
15382 -- the dependency clauses in:
15383
15384 -- Analyze_Depends_In_Decl_Part
15385
15386 -- * Expansion - None.
15387
15388 -- * Template - The annotation utilizes the generic template of the
15389 -- related subprogram [body] when it is:
15390
15391 -- aspect on subprogram declaration
15392 -- aspect on stand-alone subprogram body
15393 -- pragma on stand-alone subprogram body
15394
15395 -- The annotation must prepare its own template when it is:
15396
15397 -- pragma on subprogram declaration
15398
15399 -- * Globals - Capture of global references must occur after full
15400 -- analysis.
15401
15402 -- * Instance - The annotation is instantiated automatically when
15403 -- the related generic subprogram [body] is instantiated except for
15404 -- the "pragma on subprogram declaration" case. In that scenario
15405 -- the annotation must instantiate itself.
15406
15407 when Pragma_Depends => Depends : declare
15408 Legal : Boolean;
15409 Spec_Id : Entity_Id;
15410 Subp_Decl : Node_Id;
15411
15412 begin
15413 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
15414
15415 if Legal then
15416
15417 -- Chain the pragma on the contract for further processing by
15418 -- Analyze_Depends_In_Decl_Part.
15419
15420 Add_Contract_Item (N, Spec_Id);
15421
15422 -- Fully analyze the pragma when it appears inside an entry
15423 -- or subprogram body because it cannot benefit from forward
15424 -- references.
15425
15426 if Nkind (Subp_Decl) in N_Entry_Body
15427 | N_Subprogram_Body
15428 | N_Subprogram_Body_Stub
15429 then
15430 -- The legality checks of pragmas Depends and Global are
15431 -- affected by the SPARK mode in effect and the volatility
15432 -- of the context. In addition these two pragmas are subject
15433 -- to an inherent order:
15434
15435 -- 1) Global
15436 -- 2) Depends
15437
15438 -- Analyze all these pragmas in the order outlined above
15439
15440 Analyze_If_Present (Pragma_SPARK_Mode);
15441 Analyze_If_Present (Pragma_Volatile_Function);
15442 Analyze_If_Present (Pragma_Global);
15443 Analyze_Depends_In_Decl_Part (N);
15444 end if;
15445 end if;
15446 end Depends;
15447
15448 ---------------------
15449 -- Detect_Blocking --
15450 ---------------------
15451
15452 -- pragma Detect_Blocking;
15453
15454 when Pragma_Detect_Blocking =>
15455 Ada_2005_Pragma;
15456 Check_Arg_Count (0);
15457 Check_Valid_Configuration_Pragma;
15458 Detect_Blocking := True;
15459
15460 ------------------------------------
15461 -- Disable_Atomic_Synchronization --
15462 ------------------------------------
15463
15464 -- pragma Disable_Atomic_Synchronization [(Entity)];
15465
15466 when Pragma_Disable_Atomic_Synchronization =>
15467 GNAT_Pragma;
15468 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
15469
15470 -------------------
15471 -- Discard_Names --
15472 -------------------
15473
15474 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
15475
15476 when Pragma_Discard_Names => Discard_Names : declare
15477 E : Entity_Id;
15478 E_Id : Node_Id;
15479
15480 begin
15481 Check_Ada_83_Warning;
15482
15483 -- Deal with configuration pragma case
15484
15485 if Arg_Count = 0 and then Is_Configuration_Pragma then
15486 Global_Discard_Names := True;
15487 return;
15488
15489 -- Otherwise, check correct appropriate context
15490
15491 else
15492 Check_Is_In_Decl_Part_Or_Package_Spec;
15493
15494 if Arg_Count = 0 then
15495
15496 -- If there is no parameter, then from now on this pragma
15497 -- applies to any enumeration, exception or tagged type
15498 -- defined in the current declarative part, and recursively
15499 -- to any nested scope.
15500
15501 Set_Discard_Names (Current_Scope);
15502 return;
15503
15504 else
15505 Check_Arg_Count (1);
15506 Check_Optional_Identifier (Arg1, Name_On);
15507 Check_Arg_Is_Local_Name (Arg1);
15508
15509 E_Id := Get_Pragma_Arg (Arg1);
15510
15511 if Etype (E_Id) = Any_Type then
15512 return;
15513 end if;
15514
15515 E := Entity (E_Id);
15516
15517 -- A pragma that applies to a Ghost entity becomes Ghost for
15518 -- the purposes of legality checks and removal of ignored
15519 -- Ghost code.
15520
15521 Mark_Ghost_Pragma (N, E);
15522
15523 if (Is_First_Subtype (E)
15524 and then
15525 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
15526 or else Ekind (E) = E_Exception
15527 then
15528 Set_Discard_Names (E);
15529 Record_Rep_Item (E, N);
15530
15531 else
15532 Error_Pragma_Arg
15533 ("inappropriate entity for pragma%", Arg1);
15534 end if;
15535 end if;
15536 end if;
15537 end Discard_Names;
15538
15539 ------------------------
15540 -- Dispatching_Domain --
15541 ------------------------
15542
15543 -- pragma Dispatching_Domain (EXPRESSION);
15544
15545 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
15546 P : constant Node_Id := Parent (N);
15547 Arg : Node_Id;
15548 Ent : Entity_Id;
15549
15550 begin
15551 Ada_2012_Pragma;
15552 Check_No_Identifiers;
15553 Check_Arg_Count (1);
15554
15555 -- This pragma is born obsolete, but not the aspect
15556
15557 if not From_Aspect_Specification (N) then
15558 Check_Restriction
15559 (No_Obsolescent_Features, Pragma_Identifier (N));
15560 end if;
15561
15562 if Nkind (P) = N_Task_Definition then
15563 Arg := Get_Pragma_Arg (Arg1);
15564 Ent := Defining_Identifier (Parent (P));
15565
15566 -- A pragma that applies to a Ghost entity becomes Ghost for
15567 -- the purposes of legality checks and removal of ignored Ghost
15568 -- code.
15569
15570 Mark_Ghost_Pragma (N, Ent);
15571
15572 -- The expression must be analyzed in the special manner
15573 -- described in "Handling of Default and Per-Object
15574 -- Expressions" in sem.ads.
15575
15576 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
15577
15578 -- Check duplicate pragma before we chain the pragma in the Rep
15579 -- Item chain of Ent.
15580
15581 Check_Duplicate_Pragma (Ent);
15582 Record_Rep_Item (Ent, N);
15583
15584 -- Anything else is incorrect
15585
15586 else
15587 Pragma_Misplaced;
15588 end if;
15589 end Dispatching_Domain;
15590
15591 ---------------
15592 -- Elaborate --
15593 ---------------
15594
15595 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
15596
15597 when Pragma_Elaborate => Elaborate : declare
15598 Arg : Node_Id;
15599 Citem : Node_Id;
15600
15601 begin
15602 -- Pragma must be in context items list of a compilation unit
15603
15604 if not Is_In_Context_Clause then
15605 Pragma_Misplaced;
15606 end if;
15607
15608 -- Must be at least one argument
15609
15610 if Arg_Count = 0 then
15611 Error_Pragma ("pragma% requires at least one argument");
15612 end if;
15613
15614 -- In Ada 83 mode, there can be no items following it in the
15615 -- context list except other pragmas and implicit with clauses
15616 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
15617 -- placement rule does not apply.
15618
15619 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
15620 Citem := Next (N);
15621 while Present (Citem) loop
15622 if Nkind (Citem) = N_Pragma
15623 or else (Nkind (Citem) = N_With_Clause
15624 and then Implicit_With (Citem))
15625 then
15626 null;
15627 else
15628 Error_Pragma
15629 ("(Ada 83) pragma% must be at end of context clause");
15630 end if;
15631
15632 Next (Citem);
15633 end loop;
15634 end if;
15635
15636 -- Finally, the arguments must all be units mentioned in a with
15637 -- clause in the same context clause. Note we already checked (in
15638 -- Par.Prag) that the arguments are all identifiers or selected
15639 -- components.
15640
15641 Arg := Arg1;
15642 Outer : while Present (Arg) loop
15643 Citem := First (List_Containing (N));
15644 Inner : while Citem /= N loop
15645 if Nkind (Citem) = N_With_Clause
15646 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
15647 then
15648 Set_Elaborate_Present (Citem, True);
15649 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
15650
15651 -- With the pragma present, elaboration calls on
15652 -- subprograms from the named unit need no further
15653 -- checks, as long as the pragma appears in the current
15654 -- compilation unit. If the pragma appears in some unit
15655 -- in the context, there might still be a need for an
15656 -- Elaborate_All_Desirable from the current compilation
15657 -- to the named unit, so we keep the check enabled. This
15658 -- does not apply in SPARK mode, where we allow pragma
15659 -- Elaborate, but we don't trust it to be right so we
15660 -- will still insist on the Elaborate_All.
15661
15662 if Legacy_Elaboration_Checks
15663 and then In_Extended_Main_Source_Unit (N)
15664 and then SPARK_Mode /= On
15665 then
15666 Set_Suppress_Elaboration_Warnings
15667 (Entity (Name (Citem)));
15668 end if;
15669
15670 exit Inner;
15671 end if;
15672
15673 Next (Citem);
15674 end loop Inner;
15675
15676 if Citem = N then
15677 Error_Pragma_Arg
15678 ("argument of pragma% is not withed unit", Arg);
15679 end if;
15680
15681 Next (Arg);
15682 end loop Outer;
15683 end Elaborate;
15684
15685 -------------------
15686 -- Elaborate_All --
15687 -------------------
15688
15689 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
15690
15691 when Pragma_Elaborate_All => Elaborate_All : declare
15692 Arg : Node_Id;
15693 Citem : Node_Id;
15694
15695 begin
15696 Check_Ada_83_Warning;
15697
15698 -- Pragma must be in context items list of a compilation unit
15699
15700 if not Is_In_Context_Clause then
15701 Pragma_Misplaced;
15702 end if;
15703
15704 -- Must be at least one argument
15705
15706 if Arg_Count = 0 then
15707 Error_Pragma ("pragma% requires at least one argument");
15708 end if;
15709
15710 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
15711 -- have to appear at the end of the context clause, but may
15712 -- appear mixed in with other items, even in Ada 83 mode.
15713
15714 -- Final check: the arguments must all be units mentioned in
15715 -- a with clause in the same context clause. Note that we
15716 -- already checked (in Par.Prag) that all the arguments are
15717 -- either identifiers or selected components.
15718
15719 Arg := Arg1;
15720 Outr : while Present (Arg) loop
15721 Citem := First (List_Containing (N));
15722 Innr : while Citem /= N loop
15723 if Nkind (Citem) = N_With_Clause
15724 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
15725 then
15726 Set_Elaborate_All_Present (Citem, True);
15727 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
15728
15729 -- Suppress warnings and elaboration checks on the named
15730 -- unit if the pragma is in the current compilation, as
15731 -- for pragma Elaborate.
15732
15733 if Legacy_Elaboration_Checks
15734 and then In_Extended_Main_Source_Unit (N)
15735 then
15736 Set_Suppress_Elaboration_Warnings
15737 (Entity (Name (Citem)));
15738 end if;
15739
15740 exit Innr;
15741 end if;
15742
15743 Next (Citem);
15744 end loop Innr;
15745
15746 if Citem = N then
15747 Set_Error_Posted (N);
15748 Error_Pragma_Arg
15749 ("argument of pragma% is not withed unit", Arg);
15750 end if;
15751
15752 Next (Arg);
15753 end loop Outr;
15754 end Elaborate_All;
15755
15756 --------------------
15757 -- Elaborate_Body --
15758 --------------------
15759
15760 -- pragma Elaborate_Body [( library_unit_NAME )];
15761
15762 when Pragma_Elaborate_Body => Elaborate_Body : declare
15763 Cunit_Node : Node_Id;
15764 Cunit_Ent : Entity_Id;
15765
15766 begin
15767 Check_Ada_83_Warning;
15768 Check_Valid_Library_Unit_Pragma;
15769
15770 Cunit_Node := Cunit (Current_Sem_Unit);
15771 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15772
15773 -- A pragma that applies to a Ghost entity becomes Ghost for the
15774 -- purposes of legality checks and removal of ignored Ghost code.
15775
15776 Mark_Ghost_Pragma (N, Cunit_Ent);
15777
15778 if Nkind (Unit (Cunit_Node)) in
15779 N_Package_Body | N_Subprogram_Body
15780 then
15781 Error_Pragma ("pragma% must refer to a spec, not a body");
15782 else
15783 Set_Body_Required (Cunit_Node);
15784 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
15785
15786 -- If we are in dynamic elaboration mode, then we suppress
15787 -- elaboration warnings for the unit, since it is definitely
15788 -- fine NOT to do dynamic checks at the first level (and such
15789 -- checks will be suppressed because no elaboration boolean
15790 -- is created for Elaborate_Body packages).
15791 --
15792 -- But in the static model of elaboration, Elaborate_Body is
15793 -- definitely NOT good enough to ensure elaboration safety on
15794 -- its own, since the body may WITH other units that are not
15795 -- safe from an elaboration point of view, so a client must
15796 -- still do an Elaborate_All on such units.
15797 --
15798 -- Debug flag -gnatdD restores the old behavior of 3.13, where
15799 -- Elaborate_Body always suppressed elab warnings.
15800
15801 if Legacy_Elaboration_Checks
15802 and then (Dynamic_Elaboration_Checks or Debug_Flag_DD)
15803 then
15804 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
15805 end if;
15806 end if;
15807 end Elaborate_Body;
15808
15809 ------------------------
15810 -- Elaboration_Checks --
15811 ------------------------
15812
15813 -- pragma Elaboration_Checks (Static | Dynamic);
15814
15815 when Pragma_Elaboration_Checks => Elaboration_Checks : declare
15816 procedure Check_Duplicate_Elaboration_Checks_Pragma;
15817 -- Emit an error if the current context list already contains
15818 -- a previous Elaboration_Checks pragma. This routine raises
15819 -- Pragma_Exit if a duplicate is found.
15820
15821 procedure Ignore_Elaboration_Checks_Pragma;
15822 -- Warn that the effects of the pragma are ignored. This routine
15823 -- raises Pragma_Exit.
15824
15825 -----------------------------------------------
15826 -- Check_Duplicate_Elaboration_Checks_Pragma --
15827 -----------------------------------------------
15828
15829 procedure Check_Duplicate_Elaboration_Checks_Pragma is
15830 Item : Node_Id;
15831
15832 begin
15833 Item := Prev (N);
15834 while Present (Item) loop
15835 if Nkind (Item) = N_Pragma
15836 and then Pragma_Name (Item) = Name_Elaboration_Checks
15837 then
15838 Duplication_Error
15839 (Prag => N,
15840 Prev => Item);
15841 raise Pragma_Exit;
15842 end if;
15843
15844 Prev (Item);
15845 end loop;
15846 end Check_Duplicate_Elaboration_Checks_Pragma;
15847
15848 --------------------------------------
15849 -- Ignore_Elaboration_Checks_Pragma --
15850 --------------------------------------
15851
15852 procedure Ignore_Elaboration_Checks_Pragma is
15853 begin
15854 Error_Msg_Name_1 := Pname;
15855 Error_Msg_N ("??effects of pragma % are ignored", N);
15856 Error_Msg_N
15857 ("\place pragma on initial declaration of library unit", N);
15858
15859 raise Pragma_Exit;
15860 end Ignore_Elaboration_Checks_Pragma;
15861
15862 -- Local variables
15863
15864 Context : constant Node_Id := Parent (N);
15865 Unt : Node_Id;
15866
15867 -- Start of processing for Elaboration_Checks
15868
15869 begin
15870 GNAT_Pragma;
15871 Check_Arg_Count (1);
15872 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
15873
15874 -- The pragma appears in a configuration file
15875
15876 if No (Context) then
15877 Check_Valid_Configuration_Pragma;
15878 Check_Duplicate_Elaboration_Checks_Pragma;
15879
15880 -- The pragma acts as a configuration pragma in a compilation unit
15881
15882 -- pragma Elaboration_Checks (...);
15883 -- package Pack is ...;
15884
15885 elsif Nkind (Context) = N_Compilation_Unit
15886 and then List_Containing (N) = Context_Items (Context)
15887 then
15888 Check_Valid_Configuration_Pragma;
15889 Check_Duplicate_Elaboration_Checks_Pragma;
15890
15891 Unt := Unit (Context);
15892
15893 -- The pragma must appear on the initial declaration of a unit.
15894 -- If this is not the case, warn that the effects of the pragma
15895 -- are ignored.
15896
15897 if Nkind (Unt) = N_Package_Body then
15898 Ignore_Elaboration_Checks_Pragma;
15899
15900 -- Check the Acts_As_Spec flag of the compilation units itself
15901 -- to determine whether the subprogram body completes since it
15902 -- has not been analyzed yet. This is safe because compilation
15903 -- units are not overloadable.
15904
15905 elsif Nkind (Unt) = N_Subprogram_Body
15906 and then not Acts_As_Spec (Context)
15907 then
15908 Ignore_Elaboration_Checks_Pragma;
15909
15910 elsif Nkind (Unt) = N_Subunit then
15911 Ignore_Elaboration_Checks_Pragma;
15912 end if;
15913
15914 -- Otherwise the pragma does not appear at the configuration level
15915 -- and is illegal.
15916
15917 else
15918 Pragma_Misplaced;
15919 end if;
15920
15921 -- At this point the pragma is not a duplicate, and appears in the
15922 -- proper context. Set the elaboration model in effect.
15923
15924 Dynamic_Elaboration_Checks :=
15925 Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic;
15926 end Elaboration_Checks;
15927
15928 ---------------
15929 -- Eliminate --
15930 ---------------
15931
15932 -- pragma Eliminate (
15933 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
15934 -- [Entity =>] IDENTIFIER |
15935 -- SELECTED_COMPONENT |
15936 -- STRING_LITERAL]
15937 -- [, Source_Location => SOURCE_TRACE]);
15938
15939 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
15940 -- SOURCE_TRACE ::= STRING_LITERAL
15941
15942 when Pragma_Eliminate => Eliminate : declare
15943 Args : Args_List (1 .. 5);
15944 Names : constant Name_List (1 .. 5) := (
15945 Name_Unit_Name,
15946 Name_Entity,
15947 Name_Parameter_Types,
15948 Name_Result_Type,
15949 Name_Source_Location);
15950
15951 -- Note : Parameter_Types and Result_Type are leftovers from
15952 -- prior implementations of the pragma. They are not generated
15953 -- by the gnatelim tool, and play no role in selecting which
15954 -- of a set of overloaded names is chosen for elimination.
15955
15956 Unit_Name : Node_Id renames Args (1);
15957 Entity : Node_Id renames Args (2);
15958 Parameter_Types : Node_Id renames Args (3);
15959 Result_Type : Node_Id renames Args (4);
15960 Source_Location : Node_Id renames Args (5);
15961
15962 begin
15963 GNAT_Pragma;
15964 Check_Valid_Configuration_Pragma;
15965 Gather_Associations (Names, Args);
15966
15967 if No (Unit_Name) then
15968 Error_Pragma ("missing Unit_Name argument for pragma%");
15969 end if;
15970
15971 if No (Entity)
15972 and then (Present (Parameter_Types)
15973 or else
15974 Present (Result_Type)
15975 or else
15976 Present (Source_Location))
15977 then
15978 Error_Pragma ("missing Entity argument for pragma%");
15979 end if;
15980
15981 if (Present (Parameter_Types)
15982 or else
15983 Present (Result_Type))
15984 and then
15985 Present (Source_Location)
15986 then
15987 Error_Pragma
15988 ("parameter profile and source location cannot be used "
15989 & "together in pragma%");
15990 end if;
15991
15992 Process_Eliminate_Pragma
15993 (N,
15994 Unit_Name,
15995 Entity,
15996 Parameter_Types,
15997 Result_Type,
15998 Source_Location);
15999 end Eliminate;
16000
16001 -----------------------------------
16002 -- Enable_Atomic_Synchronization --
16003 -----------------------------------
16004
16005 -- pragma Enable_Atomic_Synchronization [(Entity)];
16006
16007 when Pragma_Enable_Atomic_Synchronization =>
16008 GNAT_Pragma;
16009 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
16010
16011 ------------
16012 -- Export --
16013 ------------
16014
16015 -- pragma Export (
16016 -- [ Convention =>] convention_IDENTIFIER,
16017 -- [ Entity =>] LOCAL_NAME
16018 -- [, [External_Name =>] static_string_EXPRESSION ]
16019 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16020
16021 when Pragma_Export => Export : declare
16022 C : Convention_Id;
16023 Def_Id : Entity_Id;
16024
16025 pragma Warnings (Off, C);
16026
16027 begin
16028 Check_Ada_83_Warning;
16029 Check_Arg_Order
16030 ((Name_Convention,
16031 Name_Entity,
16032 Name_External_Name,
16033 Name_Link_Name));
16034
16035 Check_At_Least_N_Arguments (2);
16036 Check_At_Most_N_Arguments (4);
16037
16038 -- In Relaxed_RM_Semantics, support old Ada 83 style:
16039 -- pragma Export (Entity, "external name");
16040
16041 if Relaxed_RM_Semantics
16042 and then Arg_Count = 2
16043 and then Nkind (Expression (Arg2)) = N_String_Literal
16044 then
16045 C := Convention_C;
16046 Def_Id := Get_Pragma_Arg (Arg1);
16047 Analyze (Def_Id);
16048
16049 if not Is_Entity_Name (Def_Id) then
16050 Error_Pragma_Arg ("entity name required", Arg1);
16051 end if;
16052
16053 Def_Id := Entity (Def_Id);
16054 Set_Exported (Def_Id, Arg1);
16055
16056 else
16057 Process_Convention (C, Def_Id);
16058
16059 -- A pragma that applies to a Ghost entity becomes Ghost for
16060 -- the purposes of legality checks and removal of ignored Ghost
16061 -- code.
16062
16063 Mark_Ghost_Pragma (N, Def_Id);
16064
16065 if Ekind (Def_Id) /= E_Constant then
16066 Note_Possible_Modification
16067 (Get_Pragma_Arg (Arg2), Sure => False);
16068 end if;
16069
16070 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
16071 Set_Exported (Def_Id, Arg2);
16072 end if;
16073
16074 -- If the entity is a deferred constant, propagate the information
16075 -- to the full view, because gigi elaborates the full view only.
16076
16077 if Ekind (Def_Id) = E_Constant
16078 and then Present (Full_View (Def_Id))
16079 then
16080 declare
16081 Id2 : constant Entity_Id := Full_View (Def_Id);
16082 begin
16083 Set_Is_Exported (Id2, Is_Exported (Def_Id));
16084 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
16085 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
16086 end;
16087 end if;
16088 end Export;
16089
16090 ---------------------
16091 -- Export_Function --
16092 ---------------------
16093
16094 -- pragma Export_Function (
16095 -- [Internal =>] LOCAL_NAME
16096 -- [, [External =>] EXTERNAL_SYMBOL]
16097 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16098 -- [, [Result_Type =>] TYPE_DESIGNATOR]
16099 -- [, [Mechanism =>] MECHANISM]
16100 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
16101
16102 -- EXTERNAL_SYMBOL ::=
16103 -- IDENTIFIER
16104 -- | static_string_EXPRESSION
16105
16106 -- PARAMETER_TYPES ::=
16107 -- null
16108 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16109
16110 -- TYPE_DESIGNATOR ::=
16111 -- subtype_NAME
16112 -- | subtype_Name ' Access
16113
16114 -- MECHANISM ::=
16115 -- MECHANISM_NAME
16116 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16117
16118 -- MECHANISM_ASSOCIATION ::=
16119 -- [formal_parameter_NAME =>] MECHANISM_NAME
16120
16121 -- MECHANISM_NAME ::=
16122 -- Value
16123 -- | Reference
16124
16125 when Pragma_Export_Function => Export_Function : declare
16126 Args : Args_List (1 .. 6);
16127 Names : constant Name_List (1 .. 6) := (
16128 Name_Internal,
16129 Name_External,
16130 Name_Parameter_Types,
16131 Name_Result_Type,
16132 Name_Mechanism,
16133 Name_Result_Mechanism);
16134
16135 Internal : Node_Id renames Args (1);
16136 External : Node_Id renames Args (2);
16137 Parameter_Types : Node_Id renames Args (3);
16138 Result_Type : Node_Id renames Args (4);
16139 Mechanism : Node_Id renames Args (5);
16140 Result_Mechanism : Node_Id renames Args (6);
16141
16142 begin
16143 GNAT_Pragma;
16144 Gather_Associations (Names, Args);
16145 Process_Extended_Import_Export_Subprogram_Pragma (
16146 Arg_Internal => Internal,
16147 Arg_External => External,
16148 Arg_Parameter_Types => Parameter_Types,
16149 Arg_Result_Type => Result_Type,
16150 Arg_Mechanism => Mechanism,
16151 Arg_Result_Mechanism => Result_Mechanism);
16152 end Export_Function;
16153
16154 -------------------
16155 -- Export_Object --
16156 -------------------
16157
16158 -- pragma Export_Object (
16159 -- [Internal =>] LOCAL_NAME
16160 -- [, [External =>] EXTERNAL_SYMBOL]
16161 -- [, [Size =>] EXTERNAL_SYMBOL]);
16162
16163 -- EXTERNAL_SYMBOL ::=
16164 -- IDENTIFIER
16165 -- | static_string_EXPRESSION
16166
16167 -- PARAMETER_TYPES ::=
16168 -- null
16169 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16170
16171 -- TYPE_DESIGNATOR ::=
16172 -- subtype_NAME
16173 -- | subtype_Name ' Access
16174
16175 -- MECHANISM ::=
16176 -- MECHANISM_NAME
16177 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16178
16179 -- MECHANISM_ASSOCIATION ::=
16180 -- [formal_parameter_NAME =>] MECHANISM_NAME
16181
16182 -- MECHANISM_NAME ::=
16183 -- Value
16184 -- | Reference
16185
16186 when Pragma_Export_Object => Export_Object : declare
16187 Args : Args_List (1 .. 3);
16188 Names : constant Name_List (1 .. 3) := (
16189 Name_Internal,
16190 Name_External,
16191 Name_Size);
16192
16193 Internal : Node_Id renames Args (1);
16194 External : Node_Id renames Args (2);
16195 Size : Node_Id renames Args (3);
16196
16197 begin
16198 GNAT_Pragma;
16199 Gather_Associations (Names, Args);
16200 Process_Extended_Import_Export_Object_Pragma (
16201 Arg_Internal => Internal,
16202 Arg_External => External,
16203 Arg_Size => Size);
16204 end Export_Object;
16205
16206 ----------------------
16207 -- Export_Procedure --
16208 ----------------------
16209
16210 -- pragma Export_Procedure (
16211 -- [Internal =>] LOCAL_NAME
16212 -- [, [External =>] EXTERNAL_SYMBOL]
16213 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16214 -- [, [Mechanism =>] MECHANISM]);
16215
16216 -- EXTERNAL_SYMBOL ::=
16217 -- IDENTIFIER
16218 -- | static_string_EXPRESSION
16219
16220 -- PARAMETER_TYPES ::=
16221 -- null
16222 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16223
16224 -- TYPE_DESIGNATOR ::=
16225 -- subtype_NAME
16226 -- | subtype_Name ' Access
16227
16228 -- MECHANISM ::=
16229 -- MECHANISM_NAME
16230 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16231
16232 -- MECHANISM_ASSOCIATION ::=
16233 -- [formal_parameter_NAME =>] MECHANISM_NAME
16234
16235 -- MECHANISM_NAME ::=
16236 -- Value
16237 -- | Reference
16238
16239 when Pragma_Export_Procedure => Export_Procedure : declare
16240 Args : Args_List (1 .. 4);
16241 Names : constant Name_List (1 .. 4) := (
16242 Name_Internal,
16243 Name_External,
16244 Name_Parameter_Types,
16245 Name_Mechanism);
16246
16247 Internal : Node_Id renames Args (1);
16248 External : Node_Id renames Args (2);
16249 Parameter_Types : Node_Id renames Args (3);
16250 Mechanism : Node_Id renames Args (4);
16251
16252 begin
16253 GNAT_Pragma;
16254 Gather_Associations (Names, Args);
16255 Process_Extended_Import_Export_Subprogram_Pragma (
16256 Arg_Internal => Internal,
16257 Arg_External => External,
16258 Arg_Parameter_Types => Parameter_Types,
16259 Arg_Mechanism => Mechanism);
16260 end Export_Procedure;
16261
16262 ------------------
16263 -- Export_Value --
16264 ------------------
16265
16266 -- pragma Export_Value (
16267 -- [Value =>] static_integer_EXPRESSION,
16268 -- [Link_Name =>] static_string_EXPRESSION);
16269
16270 when Pragma_Export_Value =>
16271 GNAT_Pragma;
16272 Check_Arg_Order ((Name_Value, Name_Link_Name));
16273 Check_Arg_Count (2);
16274
16275 Check_Optional_Identifier (Arg1, Name_Value);
16276 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
16277
16278 Check_Optional_Identifier (Arg2, Name_Link_Name);
16279 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16280
16281 -----------------------------
16282 -- Export_Valued_Procedure --
16283 -----------------------------
16284
16285 -- pragma Export_Valued_Procedure (
16286 -- [Internal =>] LOCAL_NAME
16287 -- [, [External =>] EXTERNAL_SYMBOL,]
16288 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16289 -- [, [Mechanism =>] MECHANISM]);
16290
16291 -- EXTERNAL_SYMBOL ::=
16292 -- IDENTIFIER
16293 -- | static_string_EXPRESSION
16294
16295 -- PARAMETER_TYPES ::=
16296 -- null
16297 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16298
16299 -- TYPE_DESIGNATOR ::=
16300 -- subtype_NAME
16301 -- | subtype_Name ' Access
16302
16303 -- MECHANISM ::=
16304 -- MECHANISM_NAME
16305 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16306
16307 -- MECHANISM_ASSOCIATION ::=
16308 -- [formal_parameter_NAME =>] MECHANISM_NAME
16309
16310 -- MECHANISM_NAME ::=
16311 -- Value
16312 -- | Reference
16313
16314 when Pragma_Export_Valued_Procedure =>
16315 Export_Valued_Procedure : declare
16316 Args : Args_List (1 .. 4);
16317 Names : constant Name_List (1 .. 4) := (
16318 Name_Internal,
16319 Name_External,
16320 Name_Parameter_Types,
16321 Name_Mechanism);
16322
16323 Internal : Node_Id renames Args (1);
16324 External : Node_Id renames Args (2);
16325 Parameter_Types : Node_Id renames Args (3);
16326 Mechanism : Node_Id renames Args (4);
16327
16328 begin
16329 GNAT_Pragma;
16330 Gather_Associations (Names, Args);
16331 Process_Extended_Import_Export_Subprogram_Pragma (
16332 Arg_Internal => Internal,
16333 Arg_External => External,
16334 Arg_Parameter_Types => Parameter_Types,
16335 Arg_Mechanism => Mechanism);
16336 end Export_Valued_Procedure;
16337
16338 -------------------
16339 -- Extend_System --
16340 -------------------
16341
16342 -- pragma Extend_System ([Name =>] Identifier);
16343
16344 when Pragma_Extend_System =>
16345 GNAT_Pragma;
16346 Check_Valid_Configuration_Pragma;
16347 Check_Arg_Count (1);
16348 Check_Optional_Identifier (Arg1, Name_Name);
16349 Check_Arg_Is_Identifier (Arg1);
16350
16351 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16352
16353 if Name_Len > 4
16354 and then Name_Buffer (1 .. 4) = "aux_"
16355 then
16356 if Present (System_Extend_Pragma_Arg) then
16357 if Chars (Get_Pragma_Arg (Arg1)) =
16358 Chars (Expression (System_Extend_Pragma_Arg))
16359 then
16360 null;
16361 else
16362 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
16363 Error_Pragma ("pragma% conflicts with that #");
16364 end if;
16365
16366 else
16367 System_Extend_Pragma_Arg := Arg1;
16368
16369 if not GNAT_Mode then
16370 System_Extend_Unit := Arg1;
16371 end if;
16372 end if;
16373 else
16374 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
16375 end if;
16376
16377 ------------------------
16378 -- Extensions_Allowed --
16379 ------------------------
16380
16381 -- pragma Extensions_Allowed (ON | OFF);
16382
16383 when Pragma_Extensions_Allowed =>
16384 GNAT_Pragma;
16385 Check_Arg_Count (1);
16386 Check_No_Identifiers;
16387 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16388
16389 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
16390 Extensions_Allowed := True;
16391 Ada_Version := Ada_Version_Type'Last;
16392
16393 else
16394 Extensions_Allowed := False;
16395 Ada_Version := Ada_Version_Explicit;
16396 Ada_Version_Pragma := Empty;
16397 end if;
16398
16399 ------------------------
16400 -- Extensions_Visible --
16401 ------------------------
16402
16403 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
16404
16405 -- Characteristics:
16406
16407 -- * Analysis - The annotation is fully analyzed immediately upon
16408 -- elaboration as its expression must be static.
16409
16410 -- * Expansion - None.
16411
16412 -- * Template - The annotation utilizes the generic template of the
16413 -- related subprogram [body] when it is:
16414
16415 -- aspect on subprogram declaration
16416 -- aspect on stand-alone subprogram body
16417 -- pragma on stand-alone subprogram body
16418
16419 -- The annotation must prepare its own template when it is:
16420
16421 -- pragma on subprogram declaration
16422
16423 -- * Globals - Capture of global references must occur after full
16424 -- analysis.
16425
16426 -- * Instance - The annotation is instantiated automatically when
16427 -- the related generic subprogram [body] is instantiated except for
16428 -- the "pragma on subprogram declaration" case. In that scenario
16429 -- the annotation must instantiate itself.
16430
16431 when Pragma_Extensions_Visible => Extensions_Visible : declare
16432 Formal : Entity_Id;
16433 Has_OK_Formal : Boolean := False;
16434 Spec_Id : Entity_Id;
16435 Subp_Decl : Node_Id;
16436
16437 begin
16438 GNAT_Pragma;
16439 Check_No_Identifiers;
16440 Check_At_Most_N_Arguments (1);
16441
16442 Subp_Decl :=
16443 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
16444
16445 -- Abstract subprogram declaration
16446
16447 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
16448 null;
16449
16450 -- Generic subprogram declaration
16451
16452 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
16453 null;
16454
16455 -- Body acts as spec
16456
16457 elsif Nkind (Subp_Decl) = N_Subprogram_Body
16458 and then No (Corresponding_Spec (Subp_Decl))
16459 then
16460 null;
16461
16462 -- Body stub acts as spec
16463
16464 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
16465 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
16466 then
16467 null;
16468
16469 -- Subprogram declaration
16470
16471 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
16472 null;
16473
16474 -- Otherwise the pragma is associated with an illegal construct
16475
16476 else
16477 Error_Pragma ("pragma % must apply to a subprogram");
16478 return;
16479 end if;
16480
16481 -- Mark the pragma as Ghost if the related subprogram is also
16482 -- Ghost. This also ensures that any expansion performed further
16483 -- below will produce Ghost nodes.
16484
16485 Spec_Id := Unique_Defining_Entity (Subp_Decl);
16486 Mark_Ghost_Pragma (N, Spec_Id);
16487
16488 -- Chain the pragma on the contract for completeness
16489
16490 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
16491
16492 -- The legality checks of pragma Extension_Visible are affected
16493 -- by the SPARK mode in effect. Analyze all pragmas in specific
16494 -- order.
16495
16496 Analyze_If_Present (Pragma_SPARK_Mode);
16497
16498 -- Examine the formals of the related subprogram
16499
16500 Formal := First_Formal (Spec_Id);
16501 while Present (Formal) loop
16502
16503 -- At least one of the formals is of a specific tagged type,
16504 -- the pragma is legal.
16505
16506 if Is_Specific_Tagged_Type (Etype (Formal)) then
16507 Has_OK_Formal := True;
16508 exit;
16509
16510 -- A generic subprogram with at least one formal of a private
16511 -- type ensures the legality of the pragma because the actual
16512 -- may be specifically tagged. Note that this is verified by
16513 -- the check above at instantiation time.
16514
16515 elsif Is_Private_Type (Etype (Formal))
16516 and then Is_Generic_Type (Etype (Formal))
16517 then
16518 Has_OK_Formal := True;
16519 exit;
16520 end if;
16521
16522 Next_Formal (Formal);
16523 end loop;
16524
16525 if not Has_OK_Formal then
16526 Error_Msg_Name_1 := Pname;
16527 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
16528 Error_Msg_NE
16529 ("\subprogram & lacks parameter of specific tagged or "
16530 & "generic private type", N, Spec_Id);
16531
16532 return;
16533 end if;
16534
16535 -- Analyze the Boolean expression (if any)
16536
16537 if Present (Arg1) then
16538 Check_Static_Boolean_Expression
16539 (Expression (Get_Argument (N, Spec_Id)));
16540 end if;
16541 end Extensions_Visible;
16542
16543 --------------
16544 -- External --
16545 --------------
16546
16547 -- pragma External (
16548 -- [ Convention =>] convention_IDENTIFIER,
16549 -- [ Entity =>] LOCAL_NAME
16550 -- [, [External_Name =>] static_string_EXPRESSION ]
16551 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16552
16553 when Pragma_External => External : declare
16554 C : Convention_Id;
16555 E : Entity_Id;
16556 pragma Warnings (Off, C);
16557
16558 begin
16559 GNAT_Pragma;
16560 Check_Arg_Order
16561 ((Name_Convention,
16562 Name_Entity,
16563 Name_External_Name,
16564 Name_Link_Name));
16565 Check_At_Least_N_Arguments (2);
16566 Check_At_Most_N_Arguments (4);
16567 Process_Convention (C, E);
16568
16569 -- A pragma that applies to a Ghost entity becomes Ghost for the
16570 -- purposes of legality checks and removal of ignored Ghost code.
16571
16572 Mark_Ghost_Pragma (N, E);
16573
16574 Note_Possible_Modification
16575 (Get_Pragma_Arg (Arg2), Sure => False);
16576 Process_Interface_Name (E, Arg3, Arg4, N);
16577 Set_Exported (E, Arg2);
16578 end External;
16579
16580 --------------------------
16581 -- External_Name_Casing --
16582 --------------------------
16583
16584 -- pragma External_Name_Casing (
16585 -- UPPERCASE | LOWERCASE
16586 -- [, AS_IS | UPPERCASE | LOWERCASE]);
16587
16588 when Pragma_External_Name_Casing =>
16589 GNAT_Pragma;
16590 Check_No_Identifiers;
16591
16592 if Arg_Count = 2 then
16593 Check_Arg_Is_One_Of
16594 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
16595
16596 case Chars (Get_Pragma_Arg (Arg2)) is
16597 when Name_As_Is =>
16598 Opt.External_Name_Exp_Casing := As_Is;
16599
16600 when Name_Uppercase =>
16601 Opt.External_Name_Exp_Casing := Uppercase;
16602
16603 when Name_Lowercase =>
16604 Opt.External_Name_Exp_Casing := Lowercase;
16605
16606 when others =>
16607 null;
16608 end case;
16609
16610 else
16611 Check_Arg_Count (1);
16612 end if;
16613
16614 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
16615
16616 case Chars (Get_Pragma_Arg (Arg1)) is
16617 when Name_Uppercase =>
16618 Opt.External_Name_Imp_Casing := Uppercase;
16619
16620 when Name_Lowercase =>
16621 Opt.External_Name_Imp_Casing := Lowercase;
16622
16623 when others =>
16624 null;
16625 end case;
16626
16627 ---------------
16628 -- Fast_Math --
16629 ---------------
16630
16631 -- pragma Fast_Math;
16632
16633 when Pragma_Fast_Math =>
16634 GNAT_Pragma;
16635 Check_No_Identifiers;
16636 Check_Valid_Configuration_Pragma;
16637 Fast_Math := True;
16638
16639 --------------------------
16640 -- Favor_Top_Level --
16641 --------------------------
16642
16643 -- pragma Favor_Top_Level (type_NAME);
16644
16645 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
16646 Typ : Entity_Id;
16647
16648 begin
16649 GNAT_Pragma;
16650 Check_No_Identifiers;
16651 Check_Arg_Count (1);
16652 Check_Arg_Is_Local_Name (Arg1);
16653 Typ := Entity (Get_Pragma_Arg (Arg1));
16654
16655 -- A pragma that applies to a Ghost entity becomes Ghost for the
16656 -- purposes of legality checks and removal of ignored Ghost code.
16657
16658 Mark_Ghost_Pragma (N, Typ);
16659
16660 -- If it's an access-to-subprogram type (in particular, not a
16661 -- subtype), set the flag on that type.
16662
16663 if Is_Access_Subprogram_Type (Typ) then
16664 Set_Can_Use_Internal_Rep (Typ, False);
16665
16666 -- Otherwise it's an error (name denotes the wrong sort of entity)
16667
16668 else
16669 Error_Pragma_Arg
16670 ("access-to-subprogram type expected",
16671 Get_Pragma_Arg (Arg1));
16672 end if;
16673 end Favor_Top_Level;
16674
16675 ---------------------------
16676 -- Finalize_Storage_Only --
16677 ---------------------------
16678
16679 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
16680
16681 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
16682 Assoc : constant Node_Id := Arg1;
16683 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
16684 Typ : Entity_Id;
16685
16686 begin
16687 GNAT_Pragma;
16688 Check_No_Identifiers;
16689 Check_Arg_Count (1);
16690 Check_Arg_Is_Local_Name (Arg1);
16691
16692 Find_Type (Type_Id);
16693 Typ := Entity (Type_Id);
16694
16695 if Typ = Any_Type
16696 or else Rep_Item_Too_Early (Typ, N)
16697 then
16698 return;
16699 else
16700 Typ := Underlying_Type (Typ);
16701 end if;
16702
16703 if not Is_Controlled (Typ) then
16704 Error_Pragma ("pragma% must specify controlled type");
16705 end if;
16706
16707 Check_First_Subtype (Arg1);
16708
16709 if Finalize_Storage_Only (Typ) then
16710 Error_Pragma ("duplicate pragma%, only one allowed");
16711
16712 elsif not Rep_Item_Too_Late (Typ, N) then
16713 Set_Finalize_Storage_Only (Base_Type (Typ), True);
16714 end if;
16715 end Finalize_Storage;
16716
16717 -----------
16718 -- Ghost --
16719 -----------
16720
16721 -- pragma Ghost [ (boolean_EXPRESSION) ];
16722
16723 when Pragma_Ghost => Ghost : declare
16724 Context : Node_Id;
16725 Expr : Node_Id;
16726 Id : Entity_Id;
16727 Orig_Stmt : Node_Id;
16728 Prev_Id : Entity_Id;
16729 Stmt : Node_Id;
16730
16731 begin
16732 GNAT_Pragma;
16733 Check_No_Identifiers;
16734 Check_At_Most_N_Arguments (1);
16735
16736 Id := Empty;
16737 Stmt := Prev (N);
16738 while Present (Stmt) loop
16739
16740 -- Skip prior pragmas, but check for duplicates
16741
16742 if Nkind (Stmt) = N_Pragma then
16743 if Pragma_Name (Stmt) = Pname then
16744 Duplication_Error
16745 (Prag => N,
16746 Prev => Stmt);
16747 raise Pragma_Exit;
16748 end if;
16749
16750 -- Task unit declared without a definition cannot be subject to
16751 -- pragma Ghost (SPARK RM 6.9(19)).
16752
16753 elsif Nkind (Stmt) in
16754 N_Single_Task_Declaration | N_Task_Type_Declaration
16755 then
16756 Error_Pragma ("pragma % cannot apply to a task type");
16757 return;
16758
16759 -- Skip internally generated code
16760
16761 elsif not Comes_From_Source (Stmt) then
16762 Orig_Stmt := Original_Node (Stmt);
16763
16764 -- When pragma Ghost applies to an untagged derivation, the
16765 -- derivation is transformed into a [sub]type declaration.
16766
16767 if Nkind (Stmt) in
16768 N_Full_Type_Declaration | N_Subtype_Declaration
16769 and then Comes_From_Source (Orig_Stmt)
16770 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
16771 and then Nkind (Type_Definition (Orig_Stmt)) =
16772 N_Derived_Type_Definition
16773 then
16774 Id := Defining_Entity (Stmt);
16775 exit;
16776
16777 -- When pragma Ghost applies to an object declaration which
16778 -- is initialized by means of a function call that returns
16779 -- on the secondary stack, the object declaration becomes a
16780 -- renaming.
16781
16782 elsif Nkind (Stmt) = N_Object_Renaming_Declaration
16783 and then Comes_From_Source (Orig_Stmt)
16784 and then Nkind (Orig_Stmt) = N_Object_Declaration
16785 then
16786 Id := Defining_Entity (Stmt);
16787 exit;
16788
16789 -- When pragma Ghost applies to an expression function, the
16790 -- expression function is transformed into a subprogram.
16791
16792 elsif Nkind (Stmt) = N_Subprogram_Declaration
16793 and then Comes_From_Source (Orig_Stmt)
16794 and then Nkind (Orig_Stmt) = N_Expression_Function
16795 then
16796 Id := Defining_Entity (Stmt);
16797 exit;
16798 end if;
16799
16800 -- The pragma applies to a legal construct, stop the traversal
16801
16802 elsif Nkind (Stmt) in N_Abstract_Subprogram_Declaration
16803 | N_Full_Type_Declaration
16804 | N_Generic_Subprogram_Declaration
16805 | N_Object_Declaration
16806 | N_Private_Extension_Declaration
16807 | N_Private_Type_Declaration
16808 | N_Subprogram_Declaration
16809 | N_Subtype_Declaration
16810 then
16811 Id := Defining_Entity (Stmt);
16812 exit;
16813
16814 -- The pragma does not apply to a legal construct, issue an
16815 -- error and stop the analysis.
16816
16817 else
16818 Error_Pragma
16819 ("pragma % must apply to an object, package, subprogram "
16820 & "or type");
16821 return;
16822 end if;
16823
16824 Stmt := Prev (Stmt);
16825 end loop;
16826
16827 Context := Parent (N);
16828
16829 -- Handle compilation units
16830
16831 if Nkind (Context) = N_Compilation_Unit_Aux then
16832 Context := Unit (Parent (Context));
16833 end if;
16834
16835 -- Protected and task types cannot be subject to pragma Ghost
16836 -- (SPARK RM 6.9(19)).
16837
16838 if Nkind (Context) in N_Protected_Body | N_Protected_Definition
16839 then
16840 Error_Pragma ("pragma % cannot apply to a protected type");
16841 return;
16842
16843 elsif Nkind (Context) in N_Task_Body | N_Task_Definition then
16844 Error_Pragma ("pragma % cannot apply to a task type");
16845 return;
16846 end if;
16847
16848 if No (Id) then
16849
16850 -- When pragma Ghost is associated with a [generic] package, it
16851 -- appears in the visible declarations.
16852
16853 if Nkind (Context) = N_Package_Specification
16854 and then Present (Visible_Declarations (Context))
16855 and then List_Containing (N) = Visible_Declarations (Context)
16856 then
16857 Id := Defining_Entity (Context);
16858
16859 -- Pragma Ghost applies to a stand-alone subprogram body
16860
16861 elsif Nkind (Context) = N_Subprogram_Body
16862 and then No (Corresponding_Spec (Context))
16863 then
16864 Id := Defining_Entity (Context);
16865
16866 -- Pragma Ghost applies to a subprogram declaration that acts
16867 -- as a compilation unit.
16868
16869 elsif Nkind (Context) = N_Subprogram_Declaration then
16870 Id := Defining_Entity (Context);
16871
16872 -- Pragma Ghost applies to a generic subprogram
16873
16874 elsif Nkind (Context) = N_Generic_Subprogram_Declaration then
16875 Id := Defining_Entity (Specification (Context));
16876 end if;
16877 end if;
16878
16879 if No (Id) then
16880 Error_Pragma
16881 ("pragma % must apply to an object, package, subprogram or "
16882 & "type");
16883 return;
16884 end if;
16885
16886 -- Handle completions of types and constants that are subject to
16887 -- pragma Ghost.
16888
16889 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
16890 Prev_Id := Incomplete_Or_Partial_View (Id);
16891
16892 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
16893 Error_Msg_Name_1 := Pname;
16894
16895 -- The full declaration of a deferred constant cannot be
16896 -- subject to pragma Ghost unless the deferred declaration
16897 -- is also Ghost (SPARK RM 6.9(9)).
16898
16899 if Ekind (Prev_Id) = E_Constant then
16900 Error_Msg_Name_1 := Pname;
16901 Error_Msg_NE (Fix_Error
16902 ("pragma % must apply to declaration of deferred "
16903 & "constant &"), N, Id);
16904 return;
16905
16906 -- Pragma Ghost may appear on the full view of an incomplete
16907 -- type because the incomplete declaration lacks aspects and
16908 -- cannot be subject to pragma Ghost.
16909
16910 elsif Ekind (Prev_Id) = E_Incomplete_Type then
16911 null;
16912
16913 -- The full declaration of a type cannot be subject to
16914 -- pragma Ghost unless the partial view is also Ghost
16915 -- (SPARK RM 6.9(9)).
16916
16917 else
16918 Error_Msg_NE (Fix_Error
16919 ("pragma % must apply to partial view of type &"),
16920 N, Id);
16921 return;
16922 end if;
16923 end if;
16924
16925 -- A synchronized object cannot be subject to pragma Ghost
16926 -- (SPARK RM 6.9(19)).
16927
16928 elsif Ekind (Id) = E_Variable then
16929 if Is_Protected_Type (Etype (Id)) then
16930 Error_Pragma ("pragma % cannot apply to a protected object");
16931 return;
16932
16933 elsif Is_Task_Type (Etype (Id)) then
16934 Error_Pragma ("pragma % cannot apply to a task object");
16935 return;
16936 end if;
16937 end if;
16938
16939 -- Analyze the Boolean expression (if any)
16940
16941 if Present (Arg1) then
16942 Expr := Get_Pragma_Arg (Arg1);
16943
16944 Analyze_And_Resolve (Expr, Standard_Boolean);
16945
16946 if Is_OK_Static_Expression (Expr) then
16947
16948 -- "Ghostness" cannot be turned off once enabled within a
16949 -- region (SPARK RM 6.9(6)).
16950
16951 if Is_False (Expr_Value (Expr))
16952 and then Ghost_Mode > None
16953 then
16954 Error_Pragma
16955 ("pragma % with value False cannot appear in enabled "
16956 & "ghost region");
16957 return;
16958 end if;
16959
16960 -- Otherwise the expression is not static
16961
16962 else
16963 Error_Pragma_Arg
16964 ("expression of pragma % must be static", Expr);
16965 return;
16966 end if;
16967 end if;
16968
16969 Set_Is_Ghost_Entity (Id);
16970 end Ghost;
16971
16972 ------------
16973 -- Global --
16974 ------------
16975
16976 -- pragma Global (GLOBAL_SPECIFICATION);
16977
16978 -- GLOBAL_SPECIFICATION ::=
16979 -- null
16980 -- | (GLOBAL_LIST)
16981 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
16982
16983 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
16984
16985 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
16986 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
16987 -- GLOBAL_ITEM ::= NAME
16988
16989 -- Characteristics:
16990
16991 -- * Analysis - The annotation undergoes initial checks to verify
16992 -- the legal placement and context. Secondary checks fully analyze
16993 -- the dependency clauses in:
16994
16995 -- Analyze_Global_In_Decl_Part
16996
16997 -- * Expansion - None.
16998
16999 -- * Template - The annotation utilizes the generic template of the
17000 -- related subprogram [body] when it is:
17001
17002 -- aspect on subprogram declaration
17003 -- aspect on stand-alone subprogram body
17004 -- pragma on stand-alone subprogram body
17005
17006 -- The annotation must prepare its own template when it is:
17007
17008 -- pragma on subprogram declaration
17009
17010 -- * Globals - Capture of global references must occur after full
17011 -- analysis.
17012
17013 -- * Instance - The annotation is instantiated automatically when
17014 -- the related generic subprogram [body] is instantiated except for
17015 -- the "pragma on subprogram declaration" case. In that scenario
17016 -- the annotation must instantiate itself.
17017
17018 when Pragma_Global => Global : declare
17019 Legal : Boolean;
17020 Spec_Id : Entity_Id;
17021 Subp_Decl : Node_Id;
17022
17023 begin
17024 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
17025
17026 if Legal then
17027
17028 -- Chain the pragma on the contract for further processing by
17029 -- Analyze_Global_In_Decl_Part.
17030
17031 Add_Contract_Item (N, Spec_Id);
17032
17033 -- Fully analyze the pragma when it appears inside an entry
17034 -- or subprogram body because it cannot benefit from forward
17035 -- references.
17036
17037 if Nkind (Subp_Decl) in N_Entry_Body
17038 | N_Subprogram_Body
17039 | N_Subprogram_Body_Stub
17040 then
17041 -- The legality checks of pragmas Depends and Global are
17042 -- affected by the SPARK mode in effect and the volatility
17043 -- of the context. In addition these two pragmas are subject
17044 -- to an inherent order:
17045
17046 -- 1) Global
17047 -- 2) Depends
17048
17049 -- Analyze all these pragmas in the order outlined above
17050
17051 Analyze_If_Present (Pragma_SPARK_Mode);
17052 Analyze_If_Present (Pragma_Volatile_Function);
17053 Analyze_Global_In_Decl_Part (N);
17054 Analyze_If_Present (Pragma_Depends);
17055 end if;
17056 end if;
17057 end Global;
17058
17059 -----------
17060 -- Ident --
17061 -----------
17062
17063 -- pragma Ident (static_string_EXPRESSION)
17064
17065 -- Note: pragma Comment shares this processing. Pragma Ident is
17066 -- identical in effect to pragma Commment.
17067
17068 when Pragma_Comment
17069 | Pragma_Ident
17070 =>
17071 Ident : declare
17072 Str : Node_Id;
17073
17074 begin
17075 GNAT_Pragma;
17076 Check_Arg_Count (1);
17077 Check_No_Identifiers;
17078 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17079 Store_Note (N);
17080
17081 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
17082
17083 declare
17084 CS : Node_Id;
17085 GP : Node_Id;
17086
17087 begin
17088 GP := Parent (Parent (N));
17089
17090 if Nkind (GP) in
17091 N_Package_Declaration | N_Generic_Package_Declaration
17092 then
17093 GP := Parent (GP);
17094 end if;
17095
17096 -- If we have a compilation unit, then record the ident value,
17097 -- checking for improper duplication.
17098
17099 if Nkind (GP) = N_Compilation_Unit then
17100 CS := Ident_String (Current_Sem_Unit);
17101
17102 if Present (CS) then
17103
17104 -- If we have multiple instances, concatenate them.
17105
17106 Start_String (Strval (CS));
17107 Store_String_Char (' ');
17108 Store_String_Chars (Strval (Str));
17109 Set_Strval (CS, End_String);
17110
17111 else
17112 Set_Ident_String (Current_Sem_Unit, Str);
17113 end if;
17114
17115 -- For subunits, we just ignore the Ident, since in GNAT these
17116 -- are not separate object files, and hence not separate units
17117 -- in the unit table.
17118
17119 elsif Nkind (GP) = N_Subunit then
17120 null;
17121 end if;
17122 end;
17123 end Ident;
17124
17125 -------------------
17126 -- Ignore_Pragma --
17127 -------------------
17128
17129 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
17130
17131 -- Entirely handled in the parser, nothing to do here
17132
17133 when Pragma_Ignore_Pragma =>
17134 null;
17135
17136 ----------------------------
17137 -- Implementation_Defined --
17138 ----------------------------
17139
17140 -- pragma Implementation_Defined (LOCAL_NAME);
17141
17142 -- Marks previously declared entity as implementation defined. For
17143 -- an overloaded entity, applies to the most recent homonym.
17144
17145 -- pragma Implementation_Defined;
17146
17147 -- The form with no arguments appears anywhere within a scope, most
17148 -- typically a package spec, and indicates that all entities that are
17149 -- defined within the package spec are Implementation_Defined.
17150
17151 when Pragma_Implementation_Defined => Implementation_Defined : declare
17152 Ent : Entity_Id;
17153
17154 begin
17155 GNAT_Pragma;
17156 Check_No_Identifiers;
17157
17158 -- Form with no arguments
17159
17160 if Arg_Count = 0 then
17161 Set_Is_Implementation_Defined (Current_Scope);
17162
17163 -- Form with one argument
17164
17165 else
17166 Check_Arg_Count (1);
17167 Check_Arg_Is_Local_Name (Arg1);
17168 Ent := Entity (Get_Pragma_Arg (Arg1));
17169 Set_Is_Implementation_Defined (Ent);
17170 end if;
17171 end Implementation_Defined;
17172
17173 -----------------
17174 -- Implemented --
17175 -----------------
17176
17177 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
17178
17179 -- IMPLEMENTATION_KIND ::=
17180 -- By_Entry | By_Protected_Procedure | By_Any | Optional
17181
17182 -- "By_Any" and "Optional" are treated as synonyms in order to
17183 -- support Ada 2012 aspect Synchronization.
17184
17185 when Pragma_Implemented => Implemented : declare
17186 Proc_Id : Entity_Id;
17187 Typ : Entity_Id;
17188
17189 begin
17190 Ada_2012_Pragma;
17191 Check_Arg_Count (2);
17192 Check_No_Identifiers;
17193 Check_Arg_Is_Identifier (Arg1);
17194 Check_Arg_Is_Local_Name (Arg1);
17195 Check_Arg_Is_One_Of (Arg2,
17196 Name_By_Any,
17197 Name_By_Entry,
17198 Name_By_Protected_Procedure,
17199 Name_Optional);
17200
17201 -- Extract the name of the local procedure
17202
17203 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
17204
17205 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
17206 -- primitive procedure of a synchronized tagged type.
17207
17208 if Ekind (Proc_Id) = E_Procedure
17209 and then Is_Primitive (Proc_Id)
17210 and then Present (First_Formal (Proc_Id))
17211 then
17212 Typ := Etype (First_Formal (Proc_Id));
17213
17214 if Is_Tagged_Type (Typ)
17215 and then
17216
17217 -- Check for a protected, a synchronized or a task interface
17218
17219 ((Is_Interface (Typ)
17220 and then Is_Synchronized_Interface (Typ))
17221
17222 -- Check for a protected type or a task type that implements
17223 -- an interface.
17224
17225 or else
17226 (Is_Concurrent_Record_Type (Typ)
17227 and then Present (Interfaces (Typ)))
17228
17229 -- In analysis-only mode, examine original protected type
17230
17231 or else
17232 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
17233 and then Present (Interface_List (Parent (Typ))))
17234
17235 -- Check for a private record extension with keyword
17236 -- "synchronized".
17237
17238 or else
17239 (Ekind (Typ) in E_Record_Type_With_Private
17240 | E_Record_Subtype_With_Private
17241 and then Synchronized_Present (Parent (Typ))))
17242 then
17243 null;
17244 else
17245 Error_Pragma_Arg
17246 ("controlling formal must be of synchronized tagged type",
17247 Arg1);
17248 return;
17249 end if;
17250
17251 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
17252 -- By_Protected_Procedure to the primitive procedure of a task
17253 -- interface.
17254
17255 if Chars (Get_Pragma_Arg (Arg2)) = Name_By_Protected_Procedure
17256 and then Is_Interface (Typ)
17257 and then Is_Task_Interface (Typ)
17258 then
17259 Error_Pragma_Arg
17260 ("implementation kind By_Protected_Procedure cannot be "
17261 & "applied to a task interface primitive", Arg2);
17262 return;
17263 end if;
17264
17265 -- Procedures declared inside a protected type must be accepted
17266
17267 elsif Ekind (Proc_Id) = E_Procedure
17268 and then Is_Protected_Type (Scope (Proc_Id))
17269 then
17270 null;
17271
17272 -- The first argument is not a primitive procedure
17273
17274 else
17275 Error_Pragma_Arg
17276 ("pragma % must be applied to a primitive procedure", Arg1);
17277 return;
17278 end if;
17279
17280 -- Ada 2012 (AI12-0279): Cannot apply the implementation_kind
17281 -- By_Protected_Procedure to a procedure that has aspect Yield
17282
17283 if Chars (Get_Pragma_Arg (Arg2)) = Name_By_Protected_Procedure
17284 and then Has_Yield_Aspect (Proc_Id)
17285 then
17286 Error_Pragma_Arg
17287 ("implementation kind By_Protected_Procedure cannot be "
17288 & "applied to entities with aspect 'Yield", Arg2);
17289 return;
17290 end if;
17291
17292 Record_Rep_Item (Proc_Id, N);
17293 end Implemented;
17294
17295 ----------------------
17296 -- Implicit_Packing --
17297 ----------------------
17298
17299 -- pragma Implicit_Packing;
17300
17301 when Pragma_Implicit_Packing =>
17302 GNAT_Pragma;
17303 Check_Arg_Count (0);
17304 Implicit_Packing := True;
17305
17306 ------------
17307 -- Import --
17308 ------------
17309
17310 -- pragma Import (
17311 -- [Convention =>] convention_IDENTIFIER,
17312 -- [Entity =>] LOCAL_NAME
17313 -- [, [External_Name =>] static_string_EXPRESSION ]
17314 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17315
17316 when Pragma_Import =>
17317 Check_Ada_83_Warning;
17318 Check_Arg_Order
17319 ((Name_Convention,
17320 Name_Entity,
17321 Name_External_Name,
17322 Name_Link_Name));
17323
17324 Check_At_Least_N_Arguments (2);
17325 Check_At_Most_N_Arguments (4);
17326 Process_Import_Or_Interface;
17327
17328 ---------------------
17329 -- Import_Function --
17330 ---------------------
17331
17332 -- pragma Import_Function (
17333 -- [Internal =>] LOCAL_NAME,
17334 -- [, [External =>] EXTERNAL_SYMBOL]
17335 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17336 -- [, [Result_Type =>] SUBTYPE_MARK]
17337 -- [, [Mechanism =>] MECHANISM]
17338 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
17339
17340 -- EXTERNAL_SYMBOL ::=
17341 -- IDENTIFIER
17342 -- | static_string_EXPRESSION
17343
17344 -- PARAMETER_TYPES ::=
17345 -- null
17346 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17347
17348 -- TYPE_DESIGNATOR ::=
17349 -- subtype_NAME
17350 -- | subtype_Name ' Access
17351
17352 -- MECHANISM ::=
17353 -- MECHANISM_NAME
17354 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17355
17356 -- MECHANISM_ASSOCIATION ::=
17357 -- [formal_parameter_NAME =>] MECHANISM_NAME
17358
17359 -- MECHANISM_NAME ::=
17360 -- Value
17361 -- | Reference
17362
17363 when Pragma_Import_Function => Import_Function : declare
17364 Args : Args_List (1 .. 6);
17365 Names : constant Name_List (1 .. 6) := (
17366 Name_Internal,
17367 Name_External,
17368 Name_Parameter_Types,
17369 Name_Result_Type,
17370 Name_Mechanism,
17371 Name_Result_Mechanism);
17372
17373 Internal : Node_Id renames Args (1);
17374 External : Node_Id renames Args (2);
17375 Parameter_Types : Node_Id renames Args (3);
17376 Result_Type : Node_Id renames Args (4);
17377 Mechanism : Node_Id renames Args (5);
17378 Result_Mechanism : Node_Id renames Args (6);
17379
17380 begin
17381 GNAT_Pragma;
17382 Gather_Associations (Names, Args);
17383 Process_Extended_Import_Export_Subprogram_Pragma (
17384 Arg_Internal => Internal,
17385 Arg_External => External,
17386 Arg_Parameter_Types => Parameter_Types,
17387 Arg_Result_Type => Result_Type,
17388 Arg_Mechanism => Mechanism,
17389 Arg_Result_Mechanism => Result_Mechanism);
17390 end Import_Function;
17391
17392 -------------------
17393 -- Import_Object --
17394 -------------------
17395
17396 -- pragma Import_Object (
17397 -- [Internal =>] LOCAL_NAME
17398 -- [, [External =>] EXTERNAL_SYMBOL]
17399 -- [, [Size =>] EXTERNAL_SYMBOL]);
17400
17401 -- EXTERNAL_SYMBOL ::=
17402 -- IDENTIFIER
17403 -- | static_string_EXPRESSION
17404
17405 when Pragma_Import_Object => Import_Object : declare
17406 Args : Args_List (1 .. 3);
17407 Names : constant Name_List (1 .. 3) := (
17408 Name_Internal,
17409 Name_External,
17410 Name_Size);
17411
17412 Internal : Node_Id renames Args (1);
17413 External : Node_Id renames Args (2);
17414 Size : Node_Id renames Args (3);
17415
17416 begin
17417 GNAT_Pragma;
17418 Gather_Associations (Names, Args);
17419 Process_Extended_Import_Export_Object_Pragma (
17420 Arg_Internal => Internal,
17421 Arg_External => External,
17422 Arg_Size => Size);
17423 end Import_Object;
17424
17425 ----------------------
17426 -- Import_Procedure --
17427 ----------------------
17428
17429 -- pragma Import_Procedure (
17430 -- [Internal =>] LOCAL_NAME
17431 -- [, [External =>] EXTERNAL_SYMBOL]
17432 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17433 -- [, [Mechanism =>] MECHANISM]);
17434
17435 -- EXTERNAL_SYMBOL ::=
17436 -- IDENTIFIER
17437 -- | static_string_EXPRESSION
17438
17439 -- PARAMETER_TYPES ::=
17440 -- null
17441 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17442
17443 -- TYPE_DESIGNATOR ::=
17444 -- subtype_NAME
17445 -- | subtype_Name ' Access
17446
17447 -- MECHANISM ::=
17448 -- MECHANISM_NAME
17449 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17450
17451 -- MECHANISM_ASSOCIATION ::=
17452 -- [formal_parameter_NAME =>] MECHANISM_NAME
17453
17454 -- MECHANISM_NAME ::=
17455 -- Value
17456 -- | Reference
17457
17458 when Pragma_Import_Procedure => Import_Procedure : declare
17459 Args : Args_List (1 .. 4);
17460 Names : constant Name_List (1 .. 4) := (
17461 Name_Internal,
17462 Name_External,
17463 Name_Parameter_Types,
17464 Name_Mechanism);
17465
17466 Internal : Node_Id renames Args (1);
17467 External : Node_Id renames Args (2);
17468 Parameter_Types : Node_Id renames Args (3);
17469 Mechanism : Node_Id renames Args (4);
17470
17471 begin
17472 GNAT_Pragma;
17473 Gather_Associations (Names, Args);
17474 Process_Extended_Import_Export_Subprogram_Pragma (
17475 Arg_Internal => Internal,
17476 Arg_External => External,
17477 Arg_Parameter_Types => Parameter_Types,
17478 Arg_Mechanism => Mechanism);
17479 end Import_Procedure;
17480
17481 -----------------------------
17482 -- Import_Valued_Procedure --
17483 -----------------------------
17484
17485 -- pragma Import_Valued_Procedure (
17486 -- [Internal =>] LOCAL_NAME
17487 -- [, [External =>] EXTERNAL_SYMBOL]
17488 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17489 -- [, [Mechanism =>] MECHANISM]);
17490
17491 -- EXTERNAL_SYMBOL ::=
17492 -- IDENTIFIER
17493 -- | static_string_EXPRESSION
17494
17495 -- PARAMETER_TYPES ::=
17496 -- null
17497 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17498
17499 -- TYPE_DESIGNATOR ::=
17500 -- subtype_NAME
17501 -- | subtype_Name ' Access
17502
17503 -- MECHANISM ::=
17504 -- MECHANISM_NAME
17505 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17506
17507 -- MECHANISM_ASSOCIATION ::=
17508 -- [formal_parameter_NAME =>] MECHANISM_NAME
17509
17510 -- MECHANISM_NAME ::=
17511 -- Value
17512 -- | Reference
17513
17514 when Pragma_Import_Valued_Procedure =>
17515 Import_Valued_Procedure : declare
17516 Args : Args_List (1 .. 4);
17517 Names : constant Name_List (1 .. 4) := (
17518 Name_Internal,
17519 Name_External,
17520 Name_Parameter_Types,
17521 Name_Mechanism);
17522
17523 Internal : Node_Id renames Args (1);
17524 External : Node_Id renames Args (2);
17525 Parameter_Types : Node_Id renames Args (3);
17526 Mechanism : Node_Id renames Args (4);
17527
17528 begin
17529 GNAT_Pragma;
17530 Gather_Associations (Names, Args);
17531 Process_Extended_Import_Export_Subprogram_Pragma (
17532 Arg_Internal => Internal,
17533 Arg_External => External,
17534 Arg_Parameter_Types => Parameter_Types,
17535 Arg_Mechanism => Mechanism);
17536 end Import_Valued_Procedure;
17537
17538 -----------------
17539 -- Independent --
17540 -----------------
17541
17542 -- pragma Independent (LOCAL_NAME);
17543
17544 when Pragma_Independent =>
17545 Process_Atomic_Independent_Shared_Volatile;
17546
17547 ----------------------------
17548 -- Independent_Components --
17549 ----------------------------
17550
17551 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
17552
17553 when Pragma_Independent_Components => Independent_Components : declare
17554 C : Node_Id;
17555 D : Node_Id;
17556 E_Id : Node_Id;
17557 E : Entity_Id;
17558
17559 begin
17560 Check_Ada_83_Warning;
17561 Ada_2012_Pragma;
17562 Check_No_Identifiers;
17563 Check_Arg_Count (1);
17564 Check_Arg_Is_Local_Name (Arg1);
17565 E_Id := Get_Pragma_Arg (Arg1);
17566
17567 if Etype (E_Id) = Any_Type then
17568 return;
17569 end if;
17570
17571 E := Entity (E_Id);
17572
17573 -- A record type with a self-referential component of anonymous
17574 -- access type is given an incomplete view in order to handle the
17575 -- self reference:
17576 --
17577 -- type Rec is record
17578 -- Self : access Rec;
17579 -- end record;
17580 --
17581 -- becomes
17582 --
17583 -- type Rec;
17584 -- type Ptr is access Rec;
17585 -- type Rec is record
17586 -- Self : Ptr;
17587 -- end record;
17588 --
17589 -- Since the incomplete view is now the initial view of the type,
17590 -- the argument of the pragma will reference the incomplete view,
17591 -- but this view is illegal according to the semantics of the
17592 -- pragma.
17593 --
17594 -- Obtain the full view of an internally-generated incomplete type
17595 -- only. This way an attempt to associate the pragma with a source
17596 -- incomplete type is still caught.
17597
17598 if Ekind (E) = E_Incomplete_Type
17599 and then not Comes_From_Source (E)
17600 and then Present (Full_View (E))
17601 then
17602 E := Full_View (E);
17603 end if;
17604
17605 -- A pragma that applies to a Ghost entity becomes Ghost for the
17606 -- purposes of legality checks and removal of ignored Ghost code.
17607
17608 Mark_Ghost_Pragma (N, E);
17609
17610 -- Check duplicate before we chain ourselves
17611
17612 Check_Duplicate_Pragma (E);
17613
17614 -- Check appropriate entity
17615
17616 if Rep_Item_Too_Early (E, N)
17617 or else
17618 Rep_Item_Too_Late (E, N)
17619 then
17620 return;
17621 end if;
17622
17623 D := Declaration_Node (E);
17624
17625 -- The flag is set on the base type, or on the object
17626
17627 if Nkind (D) = N_Full_Type_Declaration
17628 and then (Is_Array_Type (E) or else Is_Record_Type (E))
17629 then
17630 Set_Has_Independent_Components (Base_Type (E));
17631 Record_Independence_Check (N, Base_Type (E));
17632
17633 -- For record type, set all components independent
17634
17635 if Is_Record_Type (E) then
17636 C := First_Component (E);
17637 while Present (C) loop
17638 Set_Is_Independent (C);
17639 Next_Component (C);
17640 end loop;
17641 end if;
17642
17643 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
17644 and then Nkind (D) = N_Object_Declaration
17645 and then Nkind (Object_Definition (D)) =
17646 N_Constrained_Array_Definition
17647 then
17648 Set_Has_Independent_Components (E);
17649 Record_Independence_Check (N, E);
17650
17651 else
17652 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
17653 end if;
17654 end Independent_Components;
17655
17656 -----------------------
17657 -- Initial_Condition --
17658 -----------------------
17659
17660 -- pragma Initial_Condition (boolean_EXPRESSION);
17661
17662 -- Characteristics:
17663
17664 -- * Analysis - The annotation undergoes initial checks to verify
17665 -- the legal placement and context. Secondary checks preanalyze the
17666 -- expression in:
17667
17668 -- Analyze_Initial_Condition_In_Decl_Part
17669
17670 -- * Expansion - The annotation is expanded during the expansion of
17671 -- the package body whose declaration is subject to the annotation
17672 -- as done in:
17673
17674 -- Expand_Pragma_Initial_Condition
17675
17676 -- * Template - The annotation utilizes the generic template of the
17677 -- related package declaration.
17678
17679 -- * Globals - Capture of global references must occur after full
17680 -- analysis.
17681
17682 -- * Instance - The annotation is instantiated automatically when
17683 -- the related generic package is instantiated.
17684
17685 when Pragma_Initial_Condition => Initial_Condition : declare
17686 Pack_Decl : Node_Id;
17687 Pack_Id : Entity_Id;
17688
17689 begin
17690 GNAT_Pragma;
17691 Check_No_Identifiers;
17692 Check_Arg_Count (1);
17693
17694 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
17695
17696 if Nkind (Pack_Decl) not in
17697 N_Generic_Package_Declaration | N_Package_Declaration
17698 then
17699 Pragma_Misplaced;
17700 return;
17701 end if;
17702
17703 Pack_Id := Defining_Entity (Pack_Decl);
17704
17705 -- A pragma that applies to a Ghost entity becomes Ghost for the
17706 -- purposes of legality checks and removal of ignored Ghost code.
17707
17708 Mark_Ghost_Pragma (N, Pack_Id);
17709
17710 -- Chain the pragma on the contract for further processing by
17711 -- Analyze_Initial_Condition_In_Decl_Part.
17712
17713 Add_Contract_Item (N, Pack_Id);
17714
17715 -- The legality checks of pragmas Abstract_State, Initializes, and
17716 -- Initial_Condition are affected by the SPARK mode in effect. In
17717 -- addition, these three pragmas are subject to an inherent order:
17718
17719 -- 1) Abstract_State
17720 -- 2) Initializes
17721 -- 3) Initial_Condition
17722
17723 -- Analyze all these pragmas in the order outlined above
17724
17725 Analyze_If_Present (Pragma_SPARK_Mode);
17726 Analyze_If_Present (Pragma_Abstract_State);
17727 Analyze_If_Present (Pragma_Initializes);
17728 end Initial_Condition;
17729
17730 ------------------------
17731 -- Initialize_Scalars --
17732 ------------------------
17733
17734 -- pragma Initialize_Scalars
17735 -- [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ];
17736
17737 -- TYPE_VALUE_PAIR ::=
17738 -- SCALAR_TYPE => static_EXPRESSION
17739
17740 -- SCALAR_TYPE :=
17741 -- Short_Float
17742 -- | Float
17743 -- | Long_Float
17744 -- | Long_Long_Float
17745 -- | Signed_8
17746 -- | Signed_16
17747 -- | Signed_32
17748 -- | Signed_64
17749 -- | Signed_128
17750 -- | Unsigned_8
17751 -- | Unsigned_16
17752 -- | Unsigned_32
17753 -- | Unsigned_64
17754 -- | Unsigned_128
17755
17756 when Pragma_Initialize_Scalars => Do_Initialize_Scalars : declare
17757 Seen : array (Scalar_Id) of Node_Id := (others => Empty);
17758 -- This collection holds the individual pairs which specify the
17759 -- invalid values of their respective scalar types.
17760
17761 procedure Analyze_Float_Value
17762 (Scal_Typ : Float_Scalar_Id;
17763 Val_Expr : Node_Id);
17764 -- Analyze a type value pair associated with float type Scal_Typ
17765 -- and expression Val_Expr.
17766
17767 procedure Analyze_Integer_Value
17768 (Scal_Typ : Integer_Scalar_Id;
17769 Val_Expr : Node_Id);
17770 -- Analyze a type value pair associated with integer type Scal_Typ
17771 -- and expression Val_Expr.
17772
17773 procedure Analyze_Type_Value_Pair (Pair : Node_Id);
17774 -- Analyze type value pair Pair
17775
17776 -------------------------
17777 -- Analyze_Float_Value --
17778 -------------------------
17779
17780 procedure Analyze_Float_Value
17781 (Scal_Typ : Float_Scalar_Id;
17782 Val_Expr : Node_Id)
17783 is
17784 begin
17785 Analyze_And_Resolve (Val_Expr, Any_Real);
17786
17787 if Is_OK_Static_Expression (Val_Expr) then
17788 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value_R (Val_Expr));
17789
17790 else
17791 Error_Msg_Name_1 := Scal_Typ;
17792 Error_Msg_N ("value for type % must be static", Val_Expr);
17793 end if;
17794 end Analyze_Float_Value;
17795
17796 ---------------------------
17797 -- Analyze_Integer_Value --
17798 ---------------------------
17799
17800 procedure Analyze_Integer_Value
17801 (Scal_Typ : Integer_Scalar_Id;
17802 Val_Expr : Node_Id)
17803 is
17804 begin
17805 Analyze_And_Resolve (Val_Expr, Any_Integer);
17806
17807 if (Scal_Typ = Name_Signed_128
17808 or else Scal_Typ = Name_Unsigned_128)
17809 and then Ttypes.System_Max_Integer_Size < 128
17810 then
17811 Error_Msg_Name_1 := Scal_Typ;
17812 Error_Msg_N ("value cannot be set for type %", Val_Expr);
17813
17814 elsif Is_OK_Static_Expression (Val_Expr) then
17815 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value (Val_Expr));
17816
17817 else
17818 Error_Msg_Name_1 := Scal_Typ;
17819 Error_Msg_N ("value for type % must be static", Val_Expr);
17820 end if;
17821 end Analyze_Integer_Value;
17822
17823 -----------------------------
17824 -- Analyze_Type_Value_Pair --
17825 -----------------------------
17826
17827 procedure Analyze_Type_Value_Pair (Pair : Node_Id) is
17828 Scal_Typ : constant Name_Id := Chars (Pair);
17829 Val_Expr : constant Node_Id := Expression (Pair);
17830 Prev_Pair : Node_Id;
17831
17832 begin
17833 if Scal_Typ in Scalar_Id then
17834 Prev_Pair := Seen (Scal_Typ);
17835
17836 -- Prevent multiple attempts to set a value for a scalar
17837 -- type.
17838
17839 if Present (Prev_Pair) then
17840 Error_Msg_Name_1 := Scal_Typ;
17841 Error_Msg_N
17842 ("cannot specify multiple invalid values for type %",
17843 Pair);
17844
17845 Error_Msg_Sloc := Sloc (Prev_Pair);
17846 Error_Msg_N ("previous value set #", Pair);
17847
17848 -- Ignore the effects of the pair, but do not halt the
17849 -- analysis of the pragma altogether.
17850
17851 return;
17852
17853 -- Otherwise capture the first pair for this scalar type
17854
17855 else
17856 Seen (Scal_Typ) := Pair;
17857 end if;
17858
17859 if Scal_Typ in Float_Scalar_Id then
17860 Analyze_Float_Value (Scal_Typ, Val_Expr);
17861
17862 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
17863 Analyze_Integer_Value (Scal_Typ, Val_Expr);
17864 end if;
17865
17866 -- Otherwise the scalar family is illegal
17867
17868 else
17869 Error_Msg_Name_1 := Pname;
17870 Error_Msg_N
17871 ("argument of pragma % must denote valid scalar family",
17872 Pair);
17873 end if;
17874 end Analyze_Type_Value_Pair;
17875
17876 -- Local variables
17877
17878 Pairs : constant List_Id := Pragma_Argument_Associations (N);
17879 Pair : Node_Id;
17880
17881 -- Start of processing for Do_Initialize_Scalars
17882
17883 begin
17884 GNAT_Pragma;
17885 Check_Valid_Configuration_Pragma;
17886 Check_Restriction (No_Initialize_Scalars, N);
17887
17888 -- Ignore the effects of the pragma when No_Initialize_Scalars is
17889 -- in effect.
17890
17891 if Restriction_Active (No_Initialize_Scalars) then
17892 null;
17893
17894 -- Initialize_Scalars creates false positives in CodePeer, and
17895 -- incorrect negative results in GNATprove mode, so ignore this
17896 -- pragma in these modes.
17897
17898 elsif CodePeer_Mode or GNATprove_Mode then
17899 null;
17900
17901 -- Otherwise analyze the pragma
17902
17903 else
17904 if Present (Pairs) then
17905
17906 -- Install Standard in order to provide access to primitive
17907 -- types in case the expressions contain attributes such as
17908 -- Integer'Last.
17909
17910 Push_Scope (Standard_Standard);
17911
17912 Pair := First (Pairs);
17913 while Present (Pair) loop
17914 Analyze_Type_Value_Pair (Pair);
17915 Next (Pair);
17916 end loop;
17917
17918 -- Remove Standard
17919
17920 Pop_Scope;
17921 end if;
17922
17923 Init_Or_Norm_Scalars := True;
17924 Initialize_Scalars := True;
17925 end if;
17926 end Do_Initialize_Scalars;
17927
17928 -----------------
17929 -- Initializes --
17930 -----------------
17931
17932 -- pragma Initializes (INITIALIZATION_LIST);
17933
17934 -- INITIALIZATION_LIST ::=
17935 -- null
17936 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
17937
17938 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
17939
17940 -- INPUT_LIST ::=
17941 -- null
17942 -- | INPUT
17943 -- | (INPUT {, INPUT})
17944
17945 -- INPUT ::= name
17946
17947 -- Characteristics:
17948
17949 -- * Analysis - The annotation undergoes initial checks to verify
17950 -- the legal placement and context. Secondary checks preanalyze the
17951 -- expression in:
17952
17953 -- Analyze_Initializes_In_Decl_Part
17954
17955 -- * Expansion - None.
17956
17957 -- * Template - The annotation utilizes the generic template of the
17958 -- related package declaration.
17959
17960 -- * Globals - Capture of global references must occur after full
17961 -- analysis.
17962
17963 -- * Instance - The annotation is instantiated automatically when
17964 -- the related generic package is instantiated.
17965
17966 when Pragma_Initializes => Initializes : declare
17967 Pack_Decl : Node_Id;
17968 Pack_Id : Entity_Id;
17969
17970 begin
17971 GNAT_Pragma;
17972 Check_No_Identifiers;
17973 Check_Arg_Count (1);
17974
17975 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
17976
17977 if Nkind (Pack_Decl) not in
17978 N_Generic_Package_Declaration | N_Package_Declaration
17979 then
17980 Pragma_Misplaced;
17981 return;
17982 end if;
17983
17984 Pack_Id := Defining_Entity (Pack_Decl);
17985
17986 -- A pragma that applies to a Ghost entity becomes Ghost for the
17987 -- purposes of legality checks and removal of ignored Ghost code.
17988
17989 Mark_Ghost_Pragma (N, Pack_Id);
17990 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
17991
17992 -- Chain the pragma on the contract for further processing by
17993 -- Analyze_Initializes_In_Decl_Part.
17994
17995 Add_Contract_Item (N, Pack_Id);
17996
17997 -- The legality checks of pragmas Abstract_State, Initializes, and
17998 -- Initial_Condition are affected by the SPARK mode in effect. In
17999 -- addition, these three pragmas are subject to an inherent order:
18000
18001 -- 1) Abstract_State
18002 -- 2) Initializes
18003 -- 3) Initial_Condition
18004
18005 -- Analyze all these pragmas in the order outlined above
18006
18007 Analyze_If_Present (Pragma_SPARK_Mode);
18008 Analyze_If_Present (Pragma_Abstract_State);
18009 Analyze_If_Present (Pragma_Initial_Condition);
18010 end Initializes;
18011
18012 ------------
18013 -- Inline --
18014 ------------
18015
18016 -- pragma Inline ( NAME {, NAME} );
18017
18018 when Pragma_Inline =>
18019
18020 -- Pragma always active unless in GNATprove mode. It is disabled
18021 -- in GNATprove mode because frontend inlining is applied
18022 -- independently of pragmas Inline and Inline_Always for
18023 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
18024 -- in inline.ads.
18025
18026 if not GNATprove_Mode then
18027
18028 -- Inline status is Enabled if option -gnatn is specified.
18029 -- However this status determines only the value of the
18030 -- Is_Inlined flag on the subprogram and does not prevent
18031 -- the pragma itself from being recorded for later use,
18032 -- in particular for a later modification of Is_Inlined
18033 -- independently of the -gnatn option.
18034
18035 -- In other words, if -gnatn is specified for a unit, then
18036 -- all Inline pragmas processed for the compilation of this
18037 -- unit, including those in the spec of other units, are
18038 -- activated, so subprograms will be inlined across units.
18039
18040 -- If -gnatn is not specified, no Inline pragma is activated
18041 -- here, which means that subprograms will not be inlined
18042 -- across units. The Is_Inlined flag will nevertheless be
18043 -- set later when bodies are analyzed, so subprograms will
18044 -- be inlined within the unit.
18045
18046 if Inline_Active then
18047 Process_Inline (Enabled);
18048 else
18049 Process_Inline (Disabled);
18050 end if;
18051 end if;
18052
18053 -------------------
18054 -- Inline_Always --
18055 -------------------
18056
18057 -- pragma Inline_Always ( NAME {, NAME} );
18058
18059 when Pragma_Inline_Always =>
18060 GNAT_Pragma;
18061
18062 -- Pragma always active unless in CodePeer mode or GNATprove
18063 -- mode. It is disabled in CodePeer mode because inlining is
18064 -- not helpful, and enabling it caused walk order issues. It
18065 -- is disabled in GNATprove mode because frontend inlining is
18066 -- applied independently of pragmas Inline and Inline_Always for
18067 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
18068 -- inline.ads.
18069
18070 if not CodePeer_Mode and not GNATprove_Mode then
18071 Process_Inline (Enabled);
18072 end if;
18073
18074 --------------------
18075 -- Inline_Generic --
18076 --------------------
18077
18078 -- pragma Inline_Generic (NAME {, NAME});
18079
18080 when Pragma_Inline_Generic =>
18081 GNAT_Pragma;
18082 Process_Generic_List;
18083
18084 ----------------------
18085 -- Inspection_Point --
18086 ----------------------
18087
18088 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
18089
18090 when Pragma_Inspection_Point => Inspection_Point : declare
18091 Arg : Node_Id;
18092 Exp : Node_Id;
18093
18094 begin
18095 ip;
18096
18097 if Arg_Count > 0 then
18098 Arg := Arg1;
18099 loop
18100 Exp := Get_Pragma_Arg (Arg);
18101 Analyze (Exp);
18102
18103 if not Is_Entity_Name (Exp)
18104 or else not Is_Object (Entity (Exp))
18105 then
18106 Error_Pragma_Arg ("object name required", Arg);
18107 end if;
18108
18109 Next (Arg);
18110 exit when No (Arg);
18111 end loop;
18112 end if;
18113 end Inspection_Point;
18114
18115 ---------------
18116 -- Interface --
18117 ---------------
18118
18119 -- pragma Interface (
18120 -- [ Convention =>] convention_IDENTIFIER,
18121 -- [ Entity =>] LOCAL_NAME
18122 -- [, [External_Name =>] static_string_EXPRESSION ]
18123 -- [, [Link_Name =>] static_string_EXPRESSION ]);
18124
18125 when Pragma_Interface =>
18126 GNAT_Pragma;
18127 Check_Arg_Order
18128 ((Name_Convention,
18129 Name_Entity,
18130 Name_External_Name,
18131 Name_Link_Name));
18132 Check_At_Least_N_Arguments (2);
18133 Check_At_Most_N_Arguments (4);
18134 Process_Import_Or_Interface;
18135
18136 -- In Ada 2005, the permission to use Interface (a reserved word)
18137 -- as a pragma name is considered an obsolescent feature, and this
18138 -- pragma was already obsolescent in Ada 95.
18139
18140 if Ada_Version >= Ada_95 then
18141 Check_Restriction
18142 (No_Obsolescent_Features, Pragma_Identifier (N));
18143
18144 if Warn_On_Obsolescent_Feature then
18145 Error_Msg_N
18146 ("pragma Interface is an obsolescent feature?j?", N);
18147 Error_Msg_N
18148 ("|use pragma Import instead?j?", N);
18149 end if;
18150 end if;
18151
18152 --------------------
18153 -- Interface_Name --
18154 --------------------
18155
18156 -- pragma Interface_Name (
18157 -- [ Entity =>] LOCAL_NAME
18158 -- [,[External_Name =>] static_string_EXPRESSION ]
18159 -- [,[Link_Name =>] static_string_EXPRESSION ]);
18160
18161 when Pragma_Interface_Name => Interface_Name : declare
18162 Id : Node_Id;
18163 Def_Id : Entity_Id;
18164 Hom_Id : Entity_Id;
18165 Found : Boolean;
18166
18167 begin
18168 GNAT_Pragma;
18169 Check_Arg_Order
18170 ((Name_Entity, Name_External_Name, Name_Link_Name));
18171 Check_At_Least_N_Arguments (2);
18172 Check_At_Most_N_Arguments (3);
18173 Id := Get_Pragma_Arg (Arg1);
18174 Analyze (Id);
18175
18176 -- This is obsolete from Ada 95 on, but it is an implementation
18177 -- defined pragma, so we do not consider that it violates the
18178 -- restriction (No_Obsolescent_Features).
18179
18180 if Ada_Version >= Ada_95 then
18181 if Warn_On_Obsolescent_Feature then
18182 Error_Msg_N
18183 ("pragma Interface_Name is an obsolescent feature?j?", N);
18184 Error_Msg_N
18185 ("|use pragma Import instead?j?", N);
18186 end if;
18187 end if;
18188
18189 if not Is_Entity_Name (Id) then
18190 Error_Pragma_Arg
18191 ("first argument for pragma% must be entity name", Arg1);
18192 elsif Etype (Id) = Any_Type then
18193 return;
18194 else
18195 Def_Id := Entity (Id);
18196 end if;
18197
18198 -- Special DEC-compatible processing for the object case, forces
18199 -- object to be imported.
18200
18201 if Ekind (Def_Id) = E_Variable then
18202 Kill_Size_Check_Code (Def_Id);
18203 Note_Possible_Modification (Id, Sure => False);
18204
18205 -- Initialization is not allowed for imported variable
18206
18207 if Present (Expression (Parent (Def_Id)))
18208 and then Comes_From_Source (Expression (Parent (Def_Id)))
18209 then
18210 Error_Msg_Sloc := Sloc (Def_Id);
18211 Error_Pragma_Arg
18212 ("no initialization allowed for declaration of& #",
18213 Arg2);
18214
18215 else
18216 -- For compatibility, support VADS usage of providing both
18217 -- pragmas Interface and Interface_Name to obtain the effect
18218 -- of a single Import pragma.
18219
18220 if Is_Imported (Def_Id)
18221 and then Present (First_Rep_Item (Def_Id))
18222 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
18223 and then Pragma_Name (First_Rep_Item (Def_Id)) =
18224 Name_Interface
18225 then
18226 null;
18227 else
18228 Set_Imported (Def_Id);
18229 end if;
18230
18231 Set_Is_Public (Def_Id);
18232 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
18233 end if;
18234
18235 -- Otherwise must be subprogram
18236
18237 elsif not Is_Subprogram (Def_Id) then
18238 Error_Pragma_Arg
18239 ("argument of pragma% is not subprogram", Arg1);
18240
18241 else
18242 Check_At_Most_N_Arguments (3);
18243 Hom_Id := Def_Id;
18244 Found := False;
18245
18246 -- Loop through homonyms
18247
18248 loop
18249 Def_Id := Get_Base_Subprogram (Hom_Id);
18250
18251 if Is_Imported (Def_Id) then
18252 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
18253 Found := True;
18254 end if;
18255
18256 exit when From_Aspect_Specification (N);
18257 Hom_Id := Homonym (Hom_Id);
18258
18259 exit when No (Hom_Id)
18260 or else Scope (Hom_Id) /= Current_Scope;
18261 end loop;
18262
18263 if not Found then
18264 Error_Pragma_Arg
18265 ("argument of pragma% is not imported subprogram",
18266 Arg1);
18267 end if;
18268 end if;
18269 end Interface_Name;
18270
18271 -----------------------
18272 -- Interrupt_Handler --
18273 -----------------------
18274
18275 -- pragma Interrupt_Handler (handler_NAME);
18276
18277 when Pragma_Interrupt_Handler =>
18278 Check_Ada_83_Warning;
18279 Check_Arg_Count (1);
18280 Check_No_Identifiers;
18281
18282 if No_Run_Time_Mode then
18283 Error_Msg_CRT ("Interrupt_Handler pragma", N);
18284 else
18285 Check_Interrupt_Or_Attach_Handler;
18286 Process_Interrupt_Or_Attach_Handler;
18287 end if;
18288
18289 ------------------------
18290 -- Interrupt_Priority --
18291 ------------------------
18292
18293 -- pragma Interrupt_Priority [(EXPRESSION)];
18294
18295 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
18296 P : constant Node_Id := Parent (N);
18297 Arg : Node_Id;
18298 Ent : Entity_Id;
18299
18300 begin
18301 Check_Ada_83_Warning;
18302
18303 if Arg_Count /= 0 then
18304 Arg := Get_Pragma_Arg (Arg1);
18305 Check_Arg_Count (1);
18306 Check_No_Identifiers;
18307
18308 -- The expression must be analyzed in the special manner
18309 -- described in "Handling of Default and Per-Object
18310 -- Expressions" in sem.ads.
18311
18312 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
18313 end if;
18314
18315 if Nkind (P) not in N_Task_Definition | N_Protected_Definition then
18316 Pragma_Misplaced;
18317 return;
18318
18319 else
18320 Ent := Defining_Identifier (Parent (P));
18321
18322 -- Check duplicate pragma before we chain the pragma in the Rep
18323 -- Item chain of Ent.
18324
18325 Check_Duplicate_Pragma (Ent);
18326 Record_Rep_Item (Ent, N);
18327
18328 -- Check the No_Task_At_Interrupt_Priority restriction
18329
18330 if Nkind (P) = N_Task_Definition then
18331 Check_Restriction (No_Task_At_Interrupt_Priority, N);
18332 end if;
18333 end if;
18334 end Interrupt_Priority;
18335
18336 ---------------------
18337 -- Interrupt_State --
18338 ---------------------
18339
18340 -- pragma Interrupt_State (
18341 -- [Name =>] INTERRUPT_ID,
18342 -- [State =>] INTERRUPT_STATE);
18343
18344 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
18345 -- INTERRUPT_STATE => System | Runtime | User
18346
18347 -- Note: if the interrupt id is given as an identifier, then it must
18348 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
18349 -- given as a static integer expression which must be in the range of
18350 -- Ada.Interrupts.Interrupt_ID.
18351
18352 when Pragma_Interrupt_State => Interrupt_State : declare
18353 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
18354 -- This is the entity Ada.Interrupts.Interrupt_ID;
18355
18356 State_Type : Character;
18357 -- Set to 's'/'r'/'u' for System/Runtime/User
18358
18359 IST_Num : Pos;
18360 -- Index to entry in Interrupt_States table
18361
18362 Int_Val : Uint;
18363 -- Value of interrupt
18364
18365 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
18366 -- The first argument to the pragma
18367
18368 Int_Ent : Entity_Id;
18369 -- Interrupt entity in Ada.Interrupts.Names
18370
18371 begin
18372 GNAT_Pragma;
18373 Check_Arg_Order ((Name_Name, Name_State));
18374 Check_Arg_Count (2);
18375
18376 Check_Optional_Identifier (Arg1, Name_Name);
18377 Check_Optional_Identifier (Arg2, Name_State);
18378 Check_Arg_Is_Identifier (Arg2);
18379
18380 -- First argument is identifier
18381
18382 if Nkind (Arg1X) = N_Identifier then
18383
18384 -- Search list of names in Ada.Interrupts.Names
18385
18386 Int_Ent := First_Entity (RTE (RE_Names));
18387 loop
18388 if No (Int_Ent) then
18389 Error_Pragma_Arg ("invalid interrupt name", Arg1);
18390
18391 elsif Chars (Int_Ent) = Chars (Arg1X) then
18392 Int_Val := Expr_Value (Constant_Value (Int_Ent));
18393 exit;
18394 end if;
18395
18396 Next_Entity (Int_Ent);
18397 end loop;
18398
18399 -- First argument is not an identifier, so it must be a static
18400 -- expression of type Ada.Interrupts.Interrupt_ID.
18401
18402 else
18403 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
18404 Int_Val := Expr_Value (Arg1X);
18405
18406 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
18407 or else
18408 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
18409 then
18410 Error_Pragma_Arg
18411 ("value not in range of type "
18412 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
18413 end if;
18414 end if;
18415
18416 -- Check OK state
18417
18418 case Chars (Get_Pragma_Arg (Arg2)) is
18419 when Name_Runtime => State_Type := 'r';
18420 when Name_System => State_Type := 's';
18421 when Name_User => State_Type := 'u';
18422
18423 when others =>
18424 Error_Pragma_Arg ("invalid interrupt state", Arg2);
18425 end case;
18426
18427 -- Check if entry is already stored
18428
18429 IST_Num := Interrupt_States.First;
18430 loop
18431 -- If entry not found, add it
18432
18433 if IST_Num > Interrupt_States.Last then
18434 Interrupt_States.Append
18435 ((Interrupt_Number => UI_To_Int (Int_Val),
18436 Interrupt_State => State_Type,
18437 Pragma_Loc => Loc));
18438 exit;
18439
18440 -- Case of entry for the same entry
18441
18442 elsif Int_Val = Interrupt_States.Table (IST_Num).
18443 Interrupt_Number
18444 then
18445 -- If state matches, done, no need to make redundant entry
18446
18447 exit when
18448 State_Type = Interrupt_States.Table (IST_Num).
18449 Interrupt_State;
18450
18451 -- Otherwise if state does not match, error
18452
18453 Error_Msg_Sloc :=
18454 Interrupt_States.Table (IST_Num).Pragma_Loc;
18455 Error_Pragma_Arg
18456 ("state conflicts with that given #", Arg2);
18457 exit;
18458 end if;
18459
18460 IST_Num := IST_Num + 1;
18461 end loop;
18462 end Interrupt_State;
18463
18464 ---------------
18465 -- Invariant --
18466 ---------------
18467
18468 -- pragma Invariant
18469 -- ([Entity =>] type_LOCAL_NAME,
18470 -- [Check =>] EXPRESSION
18471 -- [,[Message =>] String_Expression]);
18472
18473 when Pragma_Invariant => Invariant : declare
18474 Discard : Boolean;
18475 Typ : Entity_Id;
18476 Typ_Arg : Node_Id;
18477
18478 begin
18479 GNAT_Pragma;
18480 Check_At_Least_N_Arguments (2);
18481 Check_At_Most_N_Arguments (3);
18482 Check_Optional_Identifier (Arg1, Name_Entity);
18483 Check_Optional_Identifier (Arg2, Name_Check);
18484
18485 if Arg_Count = 3 then
18486 Check_Optional_Identifier (Arg3, Name_Message);
18487 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
18488 end if;
18489
18490 Check_Arg_Is_Local_Name (Arg1);
18491
18492 Typ_Arg := Get_Pragma_Arg (Arg1);
18493 Find_Type (Typ_Arg);
18494 Typ := Entity (Typ_Arg);
18495
18496 -- Nothing to do of the related type is erroneous in some way
18497
18498 if Typ = Any_Type then
18499 return;
18500
18501 -- AI12-0041: Invariants are allowed in interface types
18502
18503 elsif Is_Interface (Typ) then
18504 null;
18505
18506 -- An invariant must apply to a private type, or appear in the
18507 -- private part of a package spec and apply to a completion.
18508 -- a class-wide invariant can only appear on a private declaration
18509 -- or private extension, not a completion.
18510
18511 -- A [class-wide] invariant may be associated a [limited] private
18512 -- type or a private extension.
18513
18514 elsif Ekind (Typ) in E_Limited_Private_Type
18515 | E_Private_Type
18516 | E_Record_Type_With_Private
18517 then
18518 null;
18519
18520 -- A non-class-wide invariant may be associated with the full view
18521 -- of a [limited] private type or a private extension.
18522
18523 elsif Has_Private_Declaration (Typ)
18524 and then not Class_Present (N)
18525 then
18526 null;
18527
18528 -- A class-wide invariant may appear on the partial view only
18529
18530 elsif Class_Present (N) then
18531 Error_Pragma_Arg
18532 ("pragma % only allowed for private type", Arg1);
18533 return;
18534
18535 -- A regular invariant may appear on both views
18536
18537 else
18538 Error_Pragma_Arg
18539 ("pragma % only allowed for private type or corresponding "
18540 & "full view", Arg1);
18541 return;
18542 end if;
18543
18544 -- An invariant associated with an abstract type (this includes
18545 -- interfaces) must be class-wide.
18546
18547 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
18548 Error_Pragma_Arg
18549 ("pragma % not allowed for abstract type", Arg1);
18550 return;
18551 end if;
18552
18553 -- A pragma that applies to a Ghost entity becomes Ghost for the
18554 -- purposes of legality checks and removal of ignored Ghost code.
18555
18556 Mark_Ghost_Pragma (N, Typ);
18557
18558 -- The pragma defines a type-specific invariant, the type is said
18559 -- to have invariants of its "own".
18560
18561 Set_Has_Own_Invariants (Base_Type (Typ));
18562
18563 -- If the invariant is class-wide, then it can be inherited by
18564 -- derived or interface implementing types. The type is said to
18565 -- have "inheritable" invariants.
18566
18567 if Class_Present (N) then
18568 Set_Has_Inheritable_Invariants (Typ);
18569 end if;
18570
18571 -- Chain the pragma on to the rep item chain, for processing when
18572 -- the type is frozen.
18573
18574 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18575
18576 -- Create the declaration of the invariant procedure that will
18577 -- verify the invariant at run time. Interfaces are treated as the
18578 -- partial view of a private type in order to achieve uniformity
18579 -- with the general case. As a result, an interface receives only
18580 -- a "partial" invariant procedure, which is never called.
18581
18582 Build_Invariant_Procedure_Declaration
18583 (Typ => Typ,
18584 Partial_Invariant => Is_Interface (Typ));
18585 end Invariant;
18586
18587 ----------------
18588 -- Keep_Names --
18589 ----------------
18590
18591 -- pragma Keep_Names ([On => ] LOCAL_NAME);
18592
18593 when Pragma_Keep_Names => Keep_Names : declare
18594 Arg : Node_Id;
18595
18596 begin
18597 GNAT_Pragma;
18598 Check_Arg_Count (1);
18599 Check_Optional_Identifier (Arg1, Name_On);
18600 Check_Arg_Is_Local_Name (Arg1);
18601
18602 Arg := Get_Pragma_Arg (Arg1);
18603 Analyze (Arg);
18604
18605 if Etype (Arg) = Any_Type then
18606 return;
18607 end if;
18608
18609 if not Is_Entity_Name (Arg)
18610 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
18611 then
18612 Error_Pragma_Arg
18613 ("pragma% requires a local enumeration type", Arg1);
18614 end if;
18615
18616 Set_Discard_Names (Entity (Arg), False);
18617 end Keep_Names;
18618
18619 -------------
18620 -- License --
18621 -------------
18622
18623 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
18624
18625 when Pragma_License =>
18626 GNAT_Pragma;
18627
18628 -- Do not analyze pragma any further in CodePeer mode, to avoid
18629 -- extraneous errors in this implementation-dependent pragma,
18630 -- which has a different profile on other compilers.
18631
18632 if CodePeer_Mode then
18633 return;
18634 end if;
18635
18636 Check_Arg_Count (1);
18637 Check_No_Identifiers;
18638 Check_Valid_Configuration_Pragma;
18639 Check_Arg_Is_Identifier (Arg1);
18640
18641 declare
18642 Sind : constant Source_File_Index :=
18643 Source_Index (Current_Sem_Unit);
18644
18645 begin
18646 case Chars (Get_Pragma_Arg (Arg1)) is
18647 when Name_GPL =>
18648 Set_License (Sind, GPL);
18649
18650 when Name_Modified_GPL =>
18651 Set_License (Sind, Modified_GPL);
18652
18653 when Name_Restricted =>
18654 Set_License (Sind, Restricted);
18655
18656 when Name_Unrestricted =>
18657 Set_License (Sind, Unrestricted);
18658
18659 when others =>
18660 Error_Pragma_Arg ("invalid license name", Arg1);
18661 end case;
18662 end;
18663
18664 ---------------
18665 -- Link_With --
18666 ---------------
18667
18668 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
18669
18670 when Pragma_Link_With => Link_With : declare
18671 Arg : Node_Id;
18672
18673 begin
18674 GNAT_Pragma;
18675
18676 if Operating_Mode = Generate_Code
18677 and then In_Extended_Main_Source_Unit (N)
18678 then
18679 Check_At_Least_N_Arguments (1);
18680 Check_No_Identifiers;
18681 Check_Is_In_Decl_Part_Or_Package_Spec;
18682 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18683 Start_String;
18684
18685 Arg := Arg1;
18686 while Present (Arg) loop
18687 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
18688
18689 -- Store argument, converting sequences of spaces to a
18690 -- single null character (this is one of the differences
18691 -- in processing between Link_With and Linker_Options).
18692
18693 Arg_Store : declare
18694 C : constant Char_Code := Get_Char_Code (' ');
18695 S : constant String_Id :=
18696 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
18697 L : constant Nat := String_Length (S);
18698 F : Nat := 1;
18699
18700 procedure Skip_Spaces;
18701 -- Advance F past any spaces
18702
18703 -----------------
18704 -- Skip_Spaces --
18705 -----------------
18706
18707 procedure Skip_Spaces is
18708 begin
18709 while F <= L and then Get_String_Char (S, F) = C loop
18710 F := F + 1;
18711 end loop;
18712 end Skip_Spaces;
18713
18714 -- Start of processing for Arg_Store
18715
18716 begin
18717 Skip_Spaces; -- skip leading spaces
18718
18719 -- Loop through characters, changing any embedded
18720 -- sequence of spaces to a single null character (this
18721 -- is how Link_With/Linker_Options differ)
18722
18723 while F <= L loop
18724 if Get_String_Char (S, F) = C then
18725 Skip_Spaces;
18726 exit when F > L;
18727 Store_String_Char (ASCII.NUL);
18728
18729 else
18730 Store_String_Char (Get_String_Char (S, F));
18731 F := F + 1;
18732 end if;
18733 end loop;
18734 end Arg_Store;
18735
18736 Arg := Next (Arg);
18737
18738 if Present (Arg) then
18739 Store_String_Char (ASCII.NUL);
18740 end if;
18741 end loop;
18742
18743 Store_Linker_Option_String (End_String);
18744 end if;
18745 end Link_With;
18746
18747 ------------------
18748 -- Linker_Alias --
18749 ------------------
18750
18751 -- pragma Linker_Alias (
18752 -- [Entity =>] LOCAL_NAME
18753 -- [Target =>] static_string_EXPRESSION);
18754
18755 when Pragma_Linker_Alias =>
18756 GNAT_Pragma;
18757 Check_Arg_Order ((Name_Entity, Name_Target));
18758 Check_Arg_Count (2);
18759 Check_Optional_Identifier (Arg1, Name_Entity);
18760 Check_Optional_Identifier (Arg2, Name_Target);
18761 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18762 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
18763
18764 -- The only processing required is to link this item on to the
18765 -- list of rep items for the given entity. This is accomplished
18766 -- by the call to Rep_Item_Too_Late (when no error is detected
18767 -- and False is returned).
18768
18769 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
18770 return;
18771 else
18772 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
18773 end if;
18774
18775 ------------------------
18776 -- Linker_Constructor --
18777 ------------------------
18778
18779 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
18780
18781 -- Code is shared with Linker_Destructor
18782
18783 -----------------------
18784 -- Linker_Destructor --
18785 -----------------------
18786
18787 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
18788
18789 when Pragma_Linker_Constructor
18790 | Pragma_Linker_Destructor
18791 =>
18792 Linker_Constructor : declare
18793 Arg1_X : Node_Id;
18794 Proc : Entity_Id;
18795
18796 begin
18797 GNAT_Pragma;
18798 Check_Arg_Count (1);
18799 Check_No_Identifiers;
18800 Check_Arg_Is_Local_Name (Arg1);
18801 Arg1_X := Get_Pragma_Arg (Arg1);
18802 Analyze (Arg1_X);
18803 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
18804
18805 if not Is_Library_Level_Entity (Proc) then
18806 Error_Pragma_Arg
18807 ("argument for pragma% must be library level entity", Arg1);
18808 end if;
18809
18810 -- The only processing required is to link this item on to the
18811 -- list of rep items for the given entity. This is accomplished
18812 -- by the call to Rep_Item_Too_Late (when no error is detected
18813 -- and False is returned).
18814
18815 if Rep_Item_Too_Late (Proc, N) then
18816 return;
18817 else
18818 Set_Has_Gigi_Rep_Item (Proc);
18819 end if;
18820 end Linker_Constructor;
18821
18822 --------------------
18823 -- Linker_Options --
18824 --------------------
18825
18826 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
18827
18828 when Pragma_Linker_Options => Linker_Options : declare
18829 Arg : Node_Id;
18830
18831 begin
18832 Check_Ada_83_Warning;
18833 Check_No_Identifiers;
18834 Check_Arg_Count (1);
18835 Check_Is_In_Decl_Part_Or_Package_Spec;
18836 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18837 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
18838
18839 Arg := Arg2;
18840 while Present (Arg) loop
18841 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
18842 Store_String_Char (ASCII.NUL);
18843 Store_String_Chars
18844 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
18845 Arg := Next (Arg);
18846 end loop;
18847
18848 if Operating_Mode = Generate_Code
18849 and then In_Extended_Main_Source_Unit (N)
18850 then
18851 Store_Linker_Option_String (End_String);
18852 end if;
18853 end Linker_Options;
18854
18855 --------------------
18856 -- Linker_Section --
18857 --------------------
18858
18859 -- pragma Linker_Section (
18860 -- [Entity =>] LOCAL_NAME
18861 -- [Section =>] static_string_EXPRESSION);
18862
18863 when Pragma_Linker_Section => Linker_Section : declare
18864 Arg : Node_Id;
18865 Ent : Entity_Id;
18866 LPE : Node_Id;
18867
18868 Ghost_Error_Posted : Boolean := False;
18869 -- Flag set when an error concerning the illegal mix of Ghost and
18870 -- non-Ghost subprograms is emitted.
18871
18872 Ghost_Id : Entity_Id := Empty;
18873 -- The entity of the first Ghost subprogram encountered while
18874 -- processing the arguments of the pragma.
18875
18876 begin
18877 GNAT_Pragma;
18878 Check_Arg_Order ((Name_Entity, Name_Section));
18879 Check_Arg_Count (2);
18880 Check_Optional_Identifier (Arg1, Name_Entity);
18881 Check_Optional_Identifier (Arg2, Name_Section);
18882 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18883 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
18884
18885 -- Check kind of entity
18886
18887 Arg := Get_Pragma_Arg (Arg1);
18888 Ent := Entity (Arg);
18889
18890 case Ekind (Ent) is
18891
18892 -- Objects (constants and variables) and types. For these cases
18893 -- all we need to do is to set the Linker_Section_pragma field,
18894 -- checking that we do not have a duplicate.
18895
18896 when Type_Kind
18897 | E_Constant
18898 | E_Variable
18899 =>
18900 LPE := Linker_Section_Pragma (Ent);
18901
18902 if Present (LPE) then
18903 Error_Msg_Sloc := Sloc (LPE);
18904 Error_Msg_NE
18905 ("Linker_Section already specified for &#", Arg1, Ent);
18906 end if;
18907
18908 Set_Linker_Section_Pragma (Ent, N);
18909
18910 -- A pragma that applies to a Ghost entity becomes Ghost for
18911 -- the purposes of legality checks and removal of ignored
18912 -- Ghost code.
18913
18914 Mark_Ghost_Pragma (N, Ent);
18915
18916 -- Subprograms
18917
18918 when Subprogram_Kind =>
18919
18920 -- Aspect case, entity already set
18921
18922 if From_Aspect_Specification (N) then
18923 Set_Linker_Section_Pragma
18924 (Entity (Corresponding_Aspect (N)), N);
18925
18926 -- Propagate it to its ultimate aliased entity to
18927 -- facilitate the backend processing this attribute
18928 -- in instantiations of generic subprograms.
18929
18930 if Present (Alias (Entity (Corresponding_Aspect (N))))
18931 then
18932 Set_Linker_Section_Pragma
18933 (Ultimate_Alias
18934 (Entity (Corresponding_Aspect (N))), N);
18935 end if;
18936
18937 -- Pragma case, we must climb the homonym chain, but skip
18938 -- any for which the linker section is already set.
18939
18940 else
18941 loop
18942 if No (Linker_Section_Pragma (Ent)) then
18943 Set_Linker_Section_Pragma (Ent, N);
18944
18945 -- Propagate it to its ultimate aliased entity to
18946 -- facilitate the backend processing this attribute
18947 -- in instantiations of generic subprograms.
18948
18949 if Present (Alias (Ent)) then
18950 Set_Linker_Section_Pragma
18951 (Ultimate_Alias (Ent), N);
18952 end if;
18953
18954 -- A pragma that applies to a Ghost entity becomes
18955 -- Ghost for the purposes of legality checks and
18956 -- removal of ignored Ghost code.
18957
18958 Mark_Ghost_Pragma (N, Ent);
18959
18960 -- Capture the entity of the first Ghost subprogram
18961 -- being processed for error detection purposes.
18962
18963 if Is_Ghost_Entity (Ent) then
18964 if No (Ghost_Id) then
18965 Ghost_Id := Ent;
18966 end if;
18967
18968 -- Otherwise the subprogram is non-Ghost. It is
18969 -- illegal to mix references to Ghost and non-Ghost
18970 -- entities (SPARK RM 6.9).
18971
18972 elsif Present (Ghost_Id)
18973 and then not Ghost_Error_Posted
18974 then
18975 Ghost_Error_Posted := True;
18976
18977 Error_Msg_Name_1 := Pname;
18978 Error_Msg_N
18979 ("pragma % cannot mention ghost and "
18980 & "non-ghost subprograms", N);
18981
18982 Error_Msg_Sloc := Sloc (Ghost_Id);
18983 Error_Msg_NE
18984 ("\& # declared as ghost", N, Ghost_Id);
18985
18986 Error_Msg_Sloc := Sloc (Ent);
18987 Error_Msg_NE
18988 ("\& # declared as non-ghost", N, Ent);
18989 end if;
18990 end if;
18991
18992 Ent := Homonym (Ent);
18993 exit when No (Ent)
18994 or else Scope (Ent) /= Current_Scope;
18995 end loop;
18996 end if;
18997
18998 -- All other cases are illegal
18999
19000 when others =>
19001 Error_Pragma_Arg
19002 ("pragma% applies only to objects, subprograms, and types",
19003 Arg1);
19004 end case;
19005 end Linker_Section;
19006
19007 ----------
19008 -- List --
19009 ----------
19010
19011 -- pragma List (On | Off)
19012
19013 -- There is nothing to do here, since we did all the processing for
19014 -- this pragma in Par.Prag (so that it works properly even in syntax
19015 -- only mode).
19016
19017 when Pragma_List =>
19018 null;
19019
19020 ---------------
19021 -- Lock_Free --
19022 ---------------
19023
19024 -- pragma Lock_Free [(Boolean_EXPRESSION)];
19025
19026 when Pragma_Lock_Free => Lock_Free : declare
19027 P : constant Node_Id := Parent (N);
19028 Arg : Node_Id;
19029 Ent : Entity_Id;
19030 Val : Boolean;
19031
19032 begin
19033 Check_No_Identifiers;
19034 Check_At_Most_N_Arguments (1);
19035
19036 -- Protected definition case
19037
19038 if Nkind (P) = N_Protected_Definition then
19039 Ent := Defining_Identifier (Parent (P));
19040
19041 -- One argument
19042
19043 if Arg_Count = 1 then
19044 Arg := Get_Pragma_Arg (Arg1);
19045 Val := Is_True (Static_Boolean (Arg));
19046
19047 -- No arguments (expression is considered to be True)
19048
19049 else
19050 Val := True;
19051 end if;
19052
19053 -- Check duplicate pragma before we chain the pragma in the Rep
19054 -- Item chain of Ent.
19055
19056 Check_Duplicate_Pragma (Ent);
19057 Record_Rep_Item (Ent, N);
19058 Set_Uses_Lock_Free (Ent, Val);
19059
19060 -- Anything else is incorrect placement
19061
19062 else
19063 Pragma_Misplaced;
19064 end if;
19065 end Lock_Free;
19066
19067 --------------------
19068 -- Locking_Policy --
19069 --------------------
19070
19071 -- pragma Locking_Policy (policy_IDENTIFIER);
19072
19073 when Pragma_Locking_Policy => declare
19074 subtype LP_Range is Name_Id
19075 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
19076 LP_Val : LP_Range;
19077 LP : Character;
19078
19079 begin
19080 Check_Ada_83_Warning;
19081 Check_Arg_Count (1);
19082 Check_No_Identifiers;
19083 Check_Arg_Is_Locking_Policy (Arg1);
19084 Check_Valid_Configuration_Pragma;
19085 LP_Val := Chars (Get_Pragma_Arg (Arg1));
19086
19087 case LP_Val is
19088 when Name_Ceiling_Locking => LP := 'C';
19089 when Name_Concurrent_Readers_Locking => LP := 'R';
19090 when Name_Inheritance_Locking => LP := 'I';
19091 end case;
19092
19093 if Locking_Policy /= ' '
19094 and then Locking_Policy /= LP
19095 then
19096 Error_Msg_Sloc := Locking_Policy_Sloc;
19097 Error_Pragma ("locking policy incompatible with policy#");
19098
19099 -- Set new policy, but always preserve System_Location since we
19100 -- like the error message with the run time name.
19101
19102 else
19103 Locking_Policy := LP;
19104
19105 if Locking_Policy_Sloc /= System_Location then
19106 Locking_Policy_Sloc := Loc;
19107 end if;
19108 end if;
19109 end;
19110
19111 -------------------
19112 -- Loop_Optimize --
19113 -------------------
19114
19115 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
19116
19117 -- OPTIMIZATION_HINT ::=
19118 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
19119
19120 when Pragma_Loop_Optimize => Loop_Optimize : declare
19121 Hint : Node_Id;
19122
19123 begin
19124 GNAT_Pragma;
19125 Check_At_Least_N_Arguments (1);
19126 Check_No_Identifiers;
19127
19128 Hint := First (Pragma_Argument_Associations (N));
19129 while Present (Hint) loop
19130 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
19131 Name_No_Unroll,
19132 Name_Unroll,
19133 Name_No_Vector,
19134 Name_Vector);
19135 Next (Hint);
19136 end loop;
19137
19138 Check_Loop_Pragma_Placement;
19139 end Loop_Optimize;
19140
19141 ------------------
19142 -- Loop_Variant --
19143 ------------------
19144
19145 -- pragma Loop_Variant
19146 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
19147
19148 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
19149
19150 -- CHANGE_DIRECTION ::= Increases | Decreases
19151
19152 when Pragma_Loop_Variant => Loop_Variant : declare
19153 Variant : Node_Id;
19154
19155 begin
19156 GNAT_Pragma;
19157 Check_At_Least_N_Arguments (1);
19158 Check_Loop_Pragma_Placement;
19159
19160 -- Process all increasing / decreasing expressions
19161
19162 Variant := First (Pragma_Argument_Associations (N));
19163 while Present (Variant) loop
19164 if Chars (Variant) = No_Name then
19165 Error_Pragma_Arg_Ident ("expect name `Increases`", Variant);
19166
19167 elsif Chars (Variant) not in Name_Decreases | Name_Increases
19168 then
19169 declare
19170 Name : String := Get_Name_String (Chars (Variant));
19171
19172 begin
19173 -- It is a common mistake to write "Increasing" for
19174 -- "Increases" or "Decreasing" for "Decreases". Recognize
19175 -- specially names starting with "incr" or "decr" to
19176 -- suggest the corresponding name.
19177
19178 System.Case_Util.To_Lower (Name);
19179
19180 if Name'Length >= 4
19181 and then Name (1 .. 4) = "incr"
19182 then
19183 Error_Pragma_Arg_Ident
19184 ("expect name `Increases`", Variant);
19185
19186 elsif Name'Length >= 4
19187 and then Name (1 .. 4) = "decr"
19188 then
19189 Error_Pragma_Arg_Ident
19190 ("expect name `Decreases`", Variant);
19191
19192 else
19193 Error_Pragma_Arg_Ident
19194 ("expect name `Increases` or `Decreases`", Variant);
19195 end if;
19196 end;
19197 end if;
19198
19199 Preanalyze_Assert_Expression
19200 (Expression (Variant), Any_Discrete);
19201
19202 Next (Variant);
19203 end loop;
19204 end Loop_Variant;
19205
19206 -----------------------
19207 -- Machine_Attribute --
19208 -----------------------
19209
19210 -- pragma Machine_Attribute (
19211 -- [Entity =>] LOCAL_NAME,
19212 -- [Attribute_Name =>] static_string_EXPRESSION
19213 -- [, [Info =>] static_EXPRESSION {, static_EXPRESSION}] );
19214
19215 when Pragma_Machine_Attribute => Machine_Attribute : declare
19216 Arg : Node_Id;
19217 Def_Id : Entity_Id;
19218
19219 begin
19220 GNAT_Pragma;
19221 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
19222
19223 if Arg_Count >= 3 then
19224 Check_Optional_Identifier (Arg3, Name_Info);
19225 Arg := Arg3;
19226 while Present (Arg) loop
19227 Check_Arg_Is_OK_Static_Expression (Arg);
19228 Arg := Next (Arg);
19229 end loop;
19230 else
19231 Check_Arg_Count (2);
19232 end if;
19233
19234 Check_Optional_Identifier (Arg1, Name_Entity);
19235 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
19236 Check_Arg_Is_Local_Name (Arg1);
19237 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19238 Def_Id := Entity (Get_Pragma_Arg (Arg1));
19239
19240 if Is_Access_Type (Def_Id) then
19241 Def_Id := Designated_Type (Def_Id);
19242 end if;
19243
19244 if Rep_Item_Too_Early (Def_Id, N) then
19245 return;
19246 end if;
19247
19248 Def_Id := Underlying_Type (Def_Id);
19249
19250 -- The only processing required is to link this item on to the
19251 -- list of rep items for the given entity. This is accomplished
19252 -- by the call to Rep_Item_Too_Late (when no error is detected
19253 -- and False is returned).
19254
19255 if Rep_Item_Too_Late (Def_Id, N) then
19256 return;
19257 else
19258 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
19259 end if;
19260 end Machine_Attribute;
19261
19262 ----------
19263 -- Main --
19264 ----------
19265
19266 -- pragma Main
19267 -- (MAIN_OPTION [, MAIN_OPTION]);
19268
19269 -- MAIN_OPTION ::=
19270 -- [STACK_SIZE =>] static_integer_EXPRESSION
19271 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
19272 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
19273
19274 when Pragma_Main => Main : declare
19275 Args : Args_List (1 .. 3);
19276 Names : constant Name_List (1 .. 3) := (
19277 Name_Stack_Size,
19278 Name_Task_Stack_Size_Default,
19279 Name_Time_Slicing_Enabled);
19280
19281 Nod : Node_Id;
19282
19283 begin
19284 GNAT_Pragma;
19285 Gather_Associations (Names, Args);
19286
19287 for J in 1 .. 2 loop
19288 if Present (Args (J)) then
19289 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19290 end if;
19291 end loop;
19292
19293 if Present (Args (3)) then
19294 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
19295 end if;
19296
19297 Nod := Next (N);
19298 while Present (Nod) loop
19299 if Nkind (Nod) = N_Pragma
19300 and then Pragma_Name (Nod) = Name_Main
19301 then
19302 Error_Msg_Name_1 := Pname;
19303 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19304 end if;
19305
19306 Next (Nod);
19307 end loop;
19308 end Main;
19309
19310 ------------------
19311 -- Main_Storage --
19312 ------------------
19313
19314 -- pragma Main_Storage
19315 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
19316
19317 -- MAIN_STORAGE_OPTION ::=
19318 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
19319 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
19320
19321 when Pragma_Main_Storage => Main_Storage : declare
19322 Args : Args_List (1 .. 2);
19323 Names : constant Name_List (1 .. 2) := (
19324 Name_Working_Storage,
19325 Name_Top_Guard);
19326
19327 Nod : Node_Id;
19328
19329 begin
19330 GNAT_Pragma;
19331 Gather_Associations (Names, Args);
19332
19333 for J in 1 .. 2 loop
19334 if Present (Args (J)) then
19335 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19336 end if;
19337 end loop;
19338
19339 Check_In_Main_Program;
19340
19341 Nod := Next (N);
19342 while Present (Nod) loop
19343 if Nkind (Nod) = N_Pragma
19344 and then Pragma_Name (Nod) = Name_Main_Storage
19345 then
19346 Error_Msg_Name_1 := Pname;
19347 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19348 end if;
19349
19350 Next (Nod);
19351 end loop;
19352 end Main_Storage;
19353
19354 ----------------------------
19355 -- Max_Entry_Queue_Length --
19356 ----------------------------
19357
19358 -- pragma Max_Entry_Queue_Length (static_integer_EXPRESSION);
19359
19360 -- This processing is shared by Pragma_Max_Entry_Queue_Depth and
19361 -- Pragma_Max_Queue_Length.
19362
19363 when Pragma_Max_Entry_Queue_Length
19364 | Pragma_Max_Entry_Queue_Depth
19365 | Pragma_Max_Queue_Length
19366 =>
19367 Max_Entry_Queue_Length : declare
19368 Arg : Node_Id;
19369 Entry_Decl : Node_Id;
19370 Entry_Id : Entity_Id;
19371 Val : Uint;
19372
19373 begin
19374 if Prag_Id = Pragma_Max_Entry_Queue_Depth
19375 or else Prag_Id = Pragma_Max_Queue_Length
19376 then
19377 GNAT_Pragma;
19378 end if;
19379
19380 Check_Arg_Count (1);
19381
19382 Entry_Decl :=
19383 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
19384
19385 -- Entry declaration
19386
19387 if Nkind (Entry_Decl) = N_Entry_Declaration then
19388
19389 -- Entry illegally within a task
19390
19391 if Nkind (Parent (N)) = N_Task_Definition then
19392 Error_Pragma ("pragma % cannot apply to task entries");
19393 return;
19394 end if;
19395
19396 Entry_Id := Defining_Entity (Entry_Decl);
19397
19398 -- Otherwise the pragma is associated with an illegal construct
19399
19400 else
19401 Error_Pragma
19402 ("pragma % must apply to a protected entry declaration");
19403 return;
19404 end if;
19405
19406 -- Mark the pragma as Ghost if the related subprogram is also
19407 -- Ghost. This also ensures that any expansion performed further
19408 -- below will produce Ghost nodes.
19409
19410 Mark_Ghost_Pragma (N, Entry_Id);
19411
19412 -- Analyze the Integer expression
19413
19414 Arg := Get_Pragma_Arg (Arg1);
19415 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
19416
19417 Val := Expr_Value (Arg);
19418
19419 if Val < -1 then
19420 Error_Pragma_Arg
19421 ("argument for pragma% cannot be less than -1", Arg1);
19422
19423 elsif not UI_Is_In_Int_Range (Val) then
19424 Error_Pragma_Arg
19425 ("argument for pragma% out of range of Integer", Arg1);
19426
19427 end if;
19428
19429 Record_Rep_Item (Entry_Id, N);
19430 end Max_Entry_Queue_Length;
19431
19432 -----------------
19433 -- Memory_Size --
19434 -----------------
19435
19436 -- pragma Memory_Size (NUMERIC_LITERAL)
19437
19438 when Pragma_Memory_Size =>
19439 GNAT_Pragma;
19440
19441 -- Memory size is simply ignored
19442
19443 Check_No_Identifiers;
19444 Check_Arg_Count (1);
19445 Check_Arg_Is_Integer_Literal (Arg1);
19446
19447 -------------
19448 -- No_Body --
19449 -------------
19450
19451 -- pragma No_Body;
19452
19453 -- The only correct use of this pragma is on its own in a file, in
19454 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
19455 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
19456 -- check for a file containing nothing but a No_Body pragma). If we
19457 -- attempt to process it during normal semantics processing, it means
19458 -- it was misplaced.
19459
19460 when Pragma_No_Body =>
19461 GNAT_Pragma;
19462 Pragma_Misplaced;
19463
19464 -----------------------------
19465 -- No_Elaboration_Code_All --
19466 -----------------------------
19467
19468 -- pragma No_Elaboration_Code_All;
19469
19470 when Pragma_No_Elaboration_Code_All =>
19471 GNAT_Pragma;
19472 Check_Valid_Library_Unit_Pragma;
19473
19474 -- Must appear for a spec or generic spec
19475
19476 if Nkind (Unit (Cunit (Current_Sem_Unit))) not in
19477 N_Generic_Package_Declaration |
19478 N_Generic_Subprogram_Declaration |
19479 N_Package_Declaration |
19480 N_Subprogram_Declaration
19481 then
19482 Error_Pragma
19483 (Fix_Error
19484 ("pragma% can only occur for package "
19485 & "or subprogram spec"));
19486 end if;
19487
19488 -- Set flag in unit table
19489
19490 Set_No_Elab_Code_All (Current_Sem_Unit);
19491
19492 -- Set restriction No_Elaboration_Code if this is the main unit
19493
19494 if Current_Sem_Unit = Main_Unit then
19495 Set_Restriction (No_Elaboration_Code, N);
19496 end if;
19497
19498 -- If we are in the main unit or in an extended main source unit,
19499 -- then we also add it to the configuration restrictions so that
19500 -- it will apply to all units in the extended main source.
19501
19502 if Current_Sem_Unit = Main_Unit
19503 or else In_Extended_Main_Source_Unit (N)
19504 then
19505 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
19506 end if;
19507
19508 -- If in main extended unit, activate transitive with test
19509
19510 if In_Extended_Main_Source_Unit (N) then
19511 Opt.No_Elab_Code_All_Pragma := N;
19512 end if;
19513
19514 -----------------------------
19515 -- No_Component_Reordering --
19516 -----------------------------
19517
19518 -- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
19519
19520 when Pragma_No_Component_Reordering => No_Comp_Reordering : declare
19521 E : Entity_Id;
19522 E_Id : Node_Id;
19523
19524 begin
19525 GNAT_Pragma;
19526 Check_At_Most_N_Arguments (1);
19527
19528 if Arg_Count = 0 then
19529 Check_Valid_Configuration_Pragma;
19530 Opt.No_Component_Reordering := True;
19531
19532 else
19533 Check_Optional_Identifier (Arg2, Name_Entity);
19534 Check_Arg_Is_Local_Name (Arg1);
19535 E_Id := Get_Pragma_Arg (Arg1);
19536
19537 if Etype (E_Id) = Any_Type then
19538 return;
19539 end if;
19540
19541 E := Entity (E_Id);
19542
19543 if not Is_Record_Type (E) then
19544 Error_Pragma_Arg ("pragma% requires record type", Arg1);
19545 end if;
19546
19547 Set_No_Reordering (Base_Type (E));
19548 end if;
19549 end No_Comp_Reordering;
19550
19551 --------------------------
19552 -- No_Heap_Finalization --
19553 --------------------------
19554
19555 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
19556
19557 when Pragma_No_Heap_Finalization => No_Heap_Finalization : declare
19558 Context : constant Node_Id := Parent (N);
19559 Typ_Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
19560 Prev : Node_Id;
19561 Typ : Entity_Id;
19562
19563 begin
19564 GNAT_Pragma;
19565 Check_No_Identifiers;
19566
19567 -- The pragma appears in a configuration file
19568
19569 if No (Context) then
19570 Check_Arg_Count (0);
19571 Check_Valid_Configuration_Pragma;
19572
19573 -- Detect a duplicate pragma
19574
19575 if Present (No_Heap_Finalization_Pragma) then
19576 Duplication_Error
19577 (Prag => N,
19578 Prev => No_Heap_Finalization_Pragma);
19579 raise Pragma_Exit;
19580 end if;
19581
19582 No_Heap_Finalization_Pragma := N;
19583
19584 -- Otherwise the pragma should be associated with a library-level
19585 -- named access-to-object type.
19586
19587 else
19588 Check_Arg_Count (1);
19589 Check_Arg_Is_Local_Name (Arg1);
19590
19591 Find_Type (Typ_Arg);
19592 Typ := Entity (Typ_Arg);
19593
19594 -- The type being subjected to the pragma is erroneous
19595
19596 if Typ = Any_Type then
19597 Error_Pragma ("cannot find type referenced by pragma %");
19598
19599 -- The pragma is applied to an incomplete or generic formal
19600 -- type way too early.
19601
19602 elsif Rep_Item_Too_Early (Typ, N) then
19603 return;
19604
19605 else
19606 Typ := Underlying_Type (Typ);
19607 end if;
19608
19609 -- The pragma must apply to an access-to-object type
19610
19611 if Ekind (Typ) in E_Access_Type | E_General_Access_Type then
19612 null;
19613
19614 -- Give a detailed error message on all other access type kinds
19615
19616 elsif Ekind (Typ) = E_Access_Protected_Subprogram_Type then
19617 Error_Pragma
19618 ("pragma % cannot apply to access protected subprogram "
19619 & "type");
19620
19621 elsif Ekind (Typ) = E_Access_Subprogram_Type then
19622 Error_Pragma
19623 ("pragma % cannot apply to access subprogram type");
19624
19625 elsif Is_Anonymous_Access_Type (Typ) then
19626 Error_Pragma
19627 ("pragma % cannot apply to anonymous access type");
19628
19629 -- Give a general error message in case the pragma applies to a
19630 -- non-access type.
19631
19632 else
19633 Error_Pragma
19634 ("pragma % must apply to library level access type");
19635 end if;
19636
19637 -- At this point the argument denotes an access-to-object type.
19638 -- Ensure that the type is declared at the library level.
19639
19640 if Is_Library_Level_Entity (Typ) then
19641 null;
19642
19643 -- Quietly ignore an access-to-object type originally declared
19644 -- at the library level within a generic, but instantiated at
19645 -- a non-library level. As a result the access-to-object type
19646 -- "loses" its No_Heap_Finalization property.
19647
19648 elsif In_Instance then
19649 raise Pragma_Exit;
19650
19651 else
19652 Error_Pragma
19653 ("pragma % must apply to library level access type");
19654 end if;
19655
19656 -- Detect a duplicate pragma
19657
19658 if Present (No_Heap_Finalization_Pragma) then
19659 Duplication_Error
19660 (Prag => N,
19661 Prev => No_Heap_Finalization_Pragma);
19662 raise Pragma_Exit;
19663
19664 else
19665 Prev := Get_Pragma (Typ, Pragma_No_Heap_Finalization);
19666
19667 if Present (Prev) then
19668 Duplication_Error
19669 (Prag => N,
19670 Prev => Prev);
19671 raise Pragma_Exit;
19672 end if;
19673 end if;
19674
19675 Record_Rep_Item (Typ, N);
19676 end if;
19677 end No_Heap_Finalization;
19678
19679 ---------------
19680 -- No_Inline --
19681 ---------------
19682
19683 -- pragma No_Inline ( NAME {, NAME} );
19684
19685 when Pragma_No_Inline =>
19686 GNAT_Pragma;
19687 Process_Inline (Suppressed);
19688
19689 ---------------
19690 -- No_Return --
19691 ---------------
19692
19693 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
19694
19695 when Pragma_No_Return => Prag_No_Return : declare
19696
19697 function Check_No_Return
19698 (E : Entity_Id;
19699 N : Node_Id) return Boolean;
19700 -- Check rule 6.5.1(4/3) of the Ada RM. If the rule is violated,
19701 -- emit an error message and return False, otherwise return True.
19702 -- 6.5.1 Nonreturning procedures:
19703 -- 4/3 "Aspect No_Return shall not be specified for a null
19704 -- procedure nor an instance of a generic unit."
19705
19706 ---------------------
19707 -- Check_No_Return --
19708 ---------------------
19709
19710 function Check_No_Return
19711 (E : Entity_Id;
19712 N : Node_Id) return Boolean
19713 is
19714 begin
19715 if Ekind (E) = E_Procedure then
19716
19717 -- If E is a generic instance, marking it with No_Return
19718 -- is forbidden, but having it inherit the No_Return of
19719 -- the generic is allowed. We check if E is inheriting its
19720 -- No_Return flag from the generic by checking if No_Return
19721 -- is already set.
19722
19723 if Is_Generic_Instance (E) and then not No_Return (E) then
19724 Error_Msg_NE
19725 ("generic instance & is marked as No_Return", N, E);
19726 Error_Msg_NE
19727 ("\generic procedure & must be marked No_Return",
19728 N,
19729 Generic_Parent (Parent (E)));
19730 return False;
19731
19732 elsif Null_Present (Subprogram_Specification (E)) then
19733 Error_Msg_NE
19734 ("null procedure & cannot be marked No_Return", N, E);
19735 return False;
19736 end if;
19737 end if;
19738
19739 return True;
19740 end Check_No_Return;
19741
19742 Arg : Node_Id;
19743 E : Entity_Id;
19744 Found : Boolean;
19745 Id : Node_Id;
19746
19747 Ghost_Error_Posted : Boolean := False;
19748 -- Flag set when an error concerning the illegal mix of Ghost and
19749 -- non-Ghost subprograms is emitted.
19750
19751 Ghost_Id : Entity_Id := Empty;
19752 -- The entity of the first Ghost procedure encountered while
19753 -- processing the arguments of the pragma.
19754
19755 begin
19756 Ada_2005_Pragma;
19757 Check_At_Least_N_Arguments (1);
19758
19759 -- Loop through arguments of pragma
19760
19761 Arg := Arg1;
19762 while Present (Arg) loop
19763 Check_Arg_Is_Local_Name (Arg);
19764 Id := Get_Pragma_Arg (Arg);
19765 Analyze (Id);
19766
19767 if not Is_Entity_Name (Id) then
19768 Error_Pragma_Arg ("entity name required", Arg);
19769 end if;
19770
19771 if Etype (Id) = Any_Type then
19772 raise Pragma_Exit;
19773 end if;
19774
19775 -- Loop to find matching procedures or functions (Ada 2020)
19776
19777 E := Entity (Id);
19778
19779 Found := False;
19780 while Present (E)
19781 and then Scope (E) = Current_Scope
19782 loop
19783 -- Ada 2020 (AI12-0269): A function can be No_Return
19784
19785 if Ekind (E) in E_Generic_Procedure | E_Procedure
19786 or else (Ada_Version >= Ada_2020
19787 and then
19788 Ekind (E) in E_Generic_Function | E_Function)
19789 then
19790 -- Check that the pragma is not applied to a body.
19791 -- First check the specless body case, to give a
19792 -- different error message. These checks do not apply
19793 -- if Relaxed_RM_Semantics, to accommodate other Ada
19794 -- compilers. Disable these checks under -gnatd.J.
19795
19796 if not Debug_Flag_Dot_JJ then
19797 if Nkind (Parent (Declaration_Node (E))) =
19798 N_Subprogram_Body
19799 and then not Relaxed_RM_Semantics
19800 then
19801 Error_Pragma
19802 ("pragma% requires separate spec and must come "
19803 & "before body");
19804 end if;
19805
19806 -- Now the "specful" body case
19807
19808 if Rep_Item_Too_Late (E, N) then
19809 raise Pragma_Exit;
19810 end if;
19811 end if;
19812
19813 if Check_No_Return (E, N) then
19814 Set_No_Return (E);
19815 end if;
19816
19817 -- A pragma that applies to a Ghost entity becomes Ghost
19818 -- for the purposes of legality checks and removal of
19819 -- ignored Ghost code.
19820
19821 Mark_Ghost_Pragma (N, E);
19822
19823 -- Capture the entity of the first Ghost procedure being
19824 -- processed for error detection purposes.
19825
19826 if Is_Ghost_Entity (E) then
19827 if No (Ghost_Id) then
19828 Ghost_Id := E;
19829 end if;
19830
19831 -- Otherwise the subprogram is non-Ghost. It is illegal
19832 -- to mix references to Ghost and non-Ghost entities
19833 -- (SPARK RM 6.9).
19834
19835 elsif Present (Ghost_Id)
19836 and then not Ghost_Error_Posted
19837 then
19838 Ghost_Error_Posted := True;
19839
19840 Error_Msg_Name_1 := Pname;
19841 Error_Msg_N
19842 ("pragma % cannot mention ghost and non-ghost "
19843 & "procedures", N);
19844
19845 Error_Msg_Sloc := Sloc (Ghost_Id);
19846 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
19847
19848 Error_Msg_Sloc := Sloc (E);
19849 Error_Msg_NE ("\& # declared as non-ghost", N, E);
19850 end if;
19851
19852 -- Set flag on any alias as well
19853
19854 if Is_Overloadable (E)
19855 and then Present (Alias (E))
19856 and then Check_No_Return (Alias (E), N)
19857 then
19858 Set_No_Return (Alias (E));
19859 end if;
19860
19861 Found := True;
19862 end if;
19863
19864 exit when From_Aspect_Specification (N);
19865 E := Homonym (E);
19866 end loop;
19867
19868 -- If entity in not in current scope it may be the enclosing
19869 -- suprogram body to which the aspect applies.
19870
19871 if not Found then
19872 if Entity (Id) = Current_Scope
19873 and then From_Aspect_Specification (N)
19874 and then Check_No_Return (Entity (Id), N)
19875 then
19876 Set_No_Return (Entity (Id));
19877
19878 elsif Ada_Version >= Ada_2020 then
19879 Error_Pragma_Arg
19880 ("no subprogram& found for pragma%", Arg);
19881
19882 else
19883 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
19884 end if;
19885 end if;
19886
19887 Next (Arg);
19888 end loop;
19889 end Prag_No_Return;
19890
19891 -----------------
19892 -- No_Run_Time --
19893 -----------------
19894
19895 -- pragma No_Run_Time;
19896
19897 -- Note: this pragma is retained for backwards compatibility. See
19898 -- body of Rtsfind for full details on its handling.
19899
19900 when Pragma_No_Run_Time =>
19901 GNAT_Pragma;
19902 Check_Valid_Configuration_Pragma;
19903 Check_Arg_Count (0);
19904
19905 -- Remove backward compatibility if Build_Type is FSF or GPL and
19906 -- generate a warning.
19907
19908 declare
19909 Ignore : constant Boolean := Build_Type in FSF .. GPL;
19910 begin
19911 if Ignore then
19912 Error_Pragma ("pragma% is ignored, has no effect??");
19913 else
19914 No_Run_Time_Mode := True;
19915 Configurable_Run_Time_Mode := True;
19916
19917 -- Set Duration to 32 bits if word size is 32
19918
19919 if Ttypes.System_Word_Size = 32 then
19920 Duration_32_Bits_On_Target := True;
19921 end if;
19922
19923 -- Set appropriate restrictions
19924
19925 Set_Restriction (No_Finalization, N);
19926 Set_Restriction (No_Exception_Handlers, N);
19927 Set_Restriction (Max_Tasks, N, 0);
19928 Set_Restriction (No_Tasking, N);
19929 end if;
19930 end;
19931
19932 -----------------------
19933 -- No_Tagged_Streams --
19934 -----------------------
19935
19936 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
19937
19938 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
19939 E : Entity_Id;
19940 E_Id : Node_Id;
19941
19942 begin
19943 GNAT_Pragma;
19944 Check_At_Most_N_Arguments (1);
19945
19946 -- One argument case
19947
19948 if Arg_Count = 1 then
19949 Check_Optional_Identifier (Arg1, Name_Entity);
19950 Check_Arg_Is_Local_Name (Arg1);
19951 E_Id := Get_Pragma_Arg (Arg1);
19952
19953 if Etype (E_Id) = Any_Type then
19954 return;
19955 end if;
19956
19957 E := Entity (E_Id);
19958
19959 Check_Duplicate_Pragma (E);
19960
19961 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
19962 Error_Pragma_Arg
19963 ("argument for pragma% must be root tagged type", Arg1);
19964 end if;
19965
19966 if Rep_Item_Too_Early (E, N)
19967 or else
19968 Rep_Item_Too_Late (E, N)
19969 then
19970 return;
19971 else
19972 Set_No_Tagged_Streams_Pragma (E, N);
19973 end if;
19974
19975 -- Zero argument case
19976
19977 else
19978 Check_Is_In_Decl_Part_Or_Package_Spec;
19979 No_Tagged_Streams := N;
19980 end if;
19981 end No_Tagged_Strms;
19982
19983 ------------------------
19984 -- No_Strict_Aliasing --
19985 ------------------------
19986
19987 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
19988
19989 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
19990 E : Entity_Id;
19991 E_Id : Node_Id;
19992
19993 begin
19994 GNAT_Pragma;
19995 Check_At_Most_N_Arguments (1);
19996
19997 if Arg_Count = 0 then
19998 Check_Valid_Configuration_Pragma;
19999 Opt.No_Strict_Aliasing := True;
20000
20001 else
20002 Check_Optional_Identifier (Arg2, Name_Entity);
20003 Check_Arg_Is_Local_Name (Arg1);
20004 E_Id := Get_Pragma_Arg (Arg1);
20005
20006 if Etype (E_Id) = Any_Type then
20007 return;
20008 end if;
20009
20010 E := Entity (E_Id);
20011
20012 if not Is_Access_Type (E) then
20013 Error_Pragma_Arg ("pragma% requires access type", Arg1);
20014 end if;
20015
20016 Set_No_Strict_Aliasing (Base_Type (E));
20017 end if;
20018 end No_Strict_Aliasing;
20019
20020 -----------------------
20021 -- Normalize_Scalars --
20022 -----------------------
20023
20024 -- pragma Normalize_Scalars;
20025
20026 when Pragma_Normalize_Scalars =>
20027 Check_Ada_83_Warning;
20028 Check_Arg_Count (0);
20029 Check_Valid_Configuration_Pragma;
20030
20031 -- Normalize_Scalars creates false positives in CodePeer, and
20032 -- incorrect negative results in GNATprove mode, so ignore this
20033 -- pragma in these modes.
20034
20035 if not (CodePeer_Mode or GNATprove_Mode) then
20036 Normalize_Scalars := True;
20037 Init_Or_Norm_Scalars := True;
20038 end if;
20039
20040 -----------------
20041 -- Obsolescent --
20042 -----------------
20043
20044 -- pragma Obsolescent;
20045
20046 -- pragma Obsolescent (
20047 -- [Message =>] static_string_EXPRESSION
20048 -- [,[Version =>] Ada_05]]);
20049
20050 -- pragma Obsolescent (
20051 -- [Entity =>] NAME
20052 -- [,[Message =>] static_string_EXPRESSION
20053 -- [,[Version =>] Ada_05]] );
20054
20055 when Pragma_Obsolescent => Obsolescent : declare
20056 Decl : Node_Id;
20057 Ename : Node_Id;
20058
20059 procedure Set_Obsolescent (E : Entity_Id);
20060 -- Given an entity Ent, mark it as obsolescent if appropriate
20061
20062 ---------------------
20063 -- Set_Obsolescent --
20064 ---------------------
20065
20066 procedure Set_Obsolescent (E : Entity_Id) is
20067 Active : Boolean;
20068 Ent : Entity_Id;
20069 S : String_Id;
20070
20071 begin
20072 Active := True;
20073 Ent := E;
20074
20075 -- A pragma that applies to a Ghost entity becomes Ghost for
20076 -- the purposes of legality checks and removal of ignored Ghost
20077 -- code.
20078
20079 Mark_Ghost_Pragma (N, E);
20080
20081 -- Entity name was given
20082
20083 if Present (Ename) then
20084
20085 -- If entity name matches, we are fine.
20086
20087 if Chars (Ename) = Chars (Ent) then
20088 Set_Entity (Ename, Ent);
20089 Generate_Reference (Ent, Ename);
20090
20091 -- If entity name does not match, only possibility is an
20092 -- enumeration literal from an enumeration type declaration.
20093
20094 elsif Ekind (Ent) /= E_Enumeration_Type then
20095 Error_Pragma
20096 ("pragma % entity name does not match declaration");
20097
20098 else
20099 Ent := First_Literal (E);
20100 loop
20101 if No (Ent) then
20102 Error_Pragma
20103 ("pragma % entity name does not match any "
20104 & "enumeration literal");
20105
20106 elsif Chars (Ent) = Chars (Ename) then
20107 Set_Entity (Ename, Ent);
20108 Generate_Reference (Ent, Ename);
20109 exit;
20110
20111 else
20112 Next_Literal (Ent);
20113 end if;
20114 end loop;
20115 end if;
20116 end if;
20117
20118 -- Ent points to entity to be marked
20119
20120 if Arg_Count >= 1 then
20121
20122 -- Deal with static string argument
20123
20124 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
20125 S := Strval (Get_Pragma_Arg (Arg1));
20126
20127 for J in 1 .. String_Length (S) loop
20128 if not In_Character_Range (Get_String_Char (S, J)) then
20129 Error_Pragma_Arg
20130 ("pragma% argument does not allow wide characters",
20131 Arg1);
20132 end if;
20133 end loop;
20134
20135 Obsolescent_Warnings.Append
20136 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
20137
20138 -- Check for Ada_05 parameter
20139
20140 if Arg_Count /= 1 then
20141 Check_Arg_Count (2);
20142
20143 declare
20144 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
20145
20146 begin
20147 Check_Arg_Is_Identifier (Argx);
20148
20149 if Chars (Argx) /= Name_Ada_05 then
20150 Error_Msg_Name_2 := Name_Ada_05;
20151 Error_Pragma_Arg
20152 ("only allowed argument for pragma% is %", Argx);
20153 end if;
20154
20155 if Ada_Version_Explicit < Ada_2005
20156 or else not Warn_On_Ada_2005_Compatibility
20157 then
20158 Active := False;
20159 end if;
20160 end;
20161 end if;
20162 end if;
20163
20164 -- Set flag if pragma active
20165
20166 if Active then
20167 Set_Is_Obsolescent (Ent);
20168 end if;
20169
20170 return;
20171 end Set_Obsolescent;
20172
20173 -- Start of processing for pragma Obsolescent
20174
20175 begin
20176 GNAT_Pragma;
20177
20178 Check_At_Most_N_Arguments (3);
20179
20180 -- See if first argument specifies an entity name
20181
20182 if Arg_Count >= 1
20183 and then
20184 (Chars (Arg1) = Name_Entity
20185 or else
20186 Nkind (Get_Pragma_Arg (Arg1)) in
20187 N_Character_Literal | N_Identifier | N_Operator_Symbol)
20188 then
20189 Ename := Get_Pragma_Arg (Arg1);
20190
20191 -- Eliminate first argument, so we can share processing
20192
20193 Arg1 := Arg2;
20194 Arg2 := Arg3;
20195 Arg_Count := Arg_Count - 1;
20196
20197 -- No Entity name argument given
20198
20199 else
20200 Ename := Empty;
20201 end if;
20202
20203 if Arg_Count >= 1 then
20204 Check_Optional_Identifier (Arg1, Name_Message);
20205
20206 if Arg_Count = 2 then
20207 Check_Optional_Identifier (Arg2, Name_Version);
20208 end if;
20209 end if;
20210
20211 -- Get immediately preceding declaration
20212
20213 Decl := Prev (N);
20214 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
20215 Prev (Decl);
20216 end loop;
20217
20218 -- Cases where we do not follow anything other than another pragma
20219
20220 if No (Decl) then
20221
20222 -- First case: library level compilation unit declaration with
20223 -- the pragma immediately following the declaration.
20224
20225 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
20226 Set_Obsolescent
20227 (Defining_Entity (Unit (Parent (Parent (N)))));
20228 return;
20229
20230 -- Case 2: library unit placement for package
20231
20232 else
20233 declare
20234 Ent : constant Entity_Id := Find_Lib_Unit_Name;
20235 begin
20236 if Is_Package_Or_Generic_Package (Ent) then
20237 Set_Obsolescent (Ent);
20238 return;
20239 end if;
20240 end;
20241 end if;
20242
20243 -- Cases where we must follow a declaration, including an
20244 -- abstract subprogram declaration, which is not in the
20245 -- other node subtypes.
20246
20247 else
20248 if Nkind (Decl) not in N_Declaration
20249 and then Nkind (Decl) not in N_Later_Decl_Item
20250 and then Nkind (Decl) not in N_Generic_Declaration
20251 and then Nkind (Decl) not in N_Renaming_Declaration
20252 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
20253 then
20254 Error_Pragma
20255 ("pragma% misplaced, "
20256 & "must immediately follow a declaration");
20257
20258 else
20259 Set_Obsolescent (Defining_Entity (Decl));
20260 return;
20261 end if;
20262 end if;
20263 end Obsolescent;
20264
20265 --------------
20266 -- Optimize --
20267 --------------
20268
20269 -- pragma Optimize (Time | Space | Off);
20270
20271 -- The actual check for optimize is done in Gigi. Note that this
20272 -- pragma does not actually change the optimization setting, it
20273 -- simply checks that it is consistent with the pragma.
20274
20275 when Pragma_Optimize =>
20276 Check_No_Identifiers;
20277 Check_Arg_Count (1);
20278 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
20279
20280 ------------------------
20281 -- Optimize_Alignment --
20282 ------------------------
20283
20284 -- pragma Optimize_Alignment (Time | Space | Off);
20285
20286 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
20287 GNAT_Pragma;
20288 Check_No_Identifiers;
20289 Check_Arg_Count (1);
20290 Check_Valid_Configuration_Pragma;
20291
20292 declare
20293 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
20294 begin
20295 case Nam is
20296 when Name_Off => Opt.Optimize_Alignment := 'O';
20297 when Name_Space => Opt.Optimize_Alignment := 'S';
20298 when Name_Time => Opt.Optimize_Alignment := 'T';
20299
20300 when others =>
20301 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
20302 end case;
20303 end;
20304
20305 -- Set indication that mode is set locally. If we are in fact in a
20306 -- configuration pragma file, this setting is harmless since the
20307 -- switch will get reset anyway at the start of each unit.
20308
20309 Optimize_Alignment_Local := True;
20310 end Optimize_Alignment;
20311
20312 -------------
20313 -- Ordered --
20314 -------------
20315
20316 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
20317
20318 when Pragma_Ordered => Ordered : declare
20319 Assoc : constant Node_Id := Arg1;
20320 Type_Id : Node_Id;
20321 Typ : Entity_Id;
20322
20323 begin
20324 GNAT_Pragma;
20325 Check_No_Identifiers;
20326 Check_Arg_Count (1);
20327 Check_Arg_Is_Local_Name (Arg1);
20328
20329 Type_Id := Get_Pragma_Arg (Assoc);
20330 Find_Type (Type_Id);
20331 Typ := Entity (Type_Id);
20332
20333 if Typ = Any_Type then
20334 return;
20335 else
20336 Typ := Underlying_Type (Typ);
20337 end if;
20338
20339 if not Is_Enumeration_Type (Typ) then
20340 Error_Pragma ("pragma% must specify enumeration type");
20341 end if;
20342
20343 Check_First_Subtype (Arg1);
20344 Set_Has_Pragma_Ordered (Base_Type (Typ));
20345 end Ordered;
20346
20347 -------------------
20348 -- Overflow_Mode --
20349 -------------------
20350
20351 -- pragma Overflow_Mode
20352 -- ([General => ] MODE [, [Assertions => ] MODE]);
20353
20354 -- MODE := STRICT | MINIMIZED | ELIMINATED
20355
20356 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
20357 -- since System.Bignums makes this assumption. This is true of nearly
20358 -- all (all?) targets.
20359
20360 when Pragma_Overflow_Mode => Overflow_Mode : declare
20361 function Get_Overflow_Mode
20362 (Name : Name_Id;
20363 Arg : Node_Id) return Overflow_Mode_Type;
20364 -- Function to process one pragma argument, Arg. If an identifier
20365 -- is present, it must be Name. Mode type is returned if a valid
20366 -- argument exists, otherwise an error is signalled.
20367
20368 -----------------------
20369 -- Get_Overflow_Mode --
20370 -----------------------
20371
20372 function Get_Overflow_Mode
20373 (Name : Name_Id;
20374 Arg : Node_Id) return Overflow_Mode_Type
20375 is
20376 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
20377
20378 begin
20379 Check_Optional_Identifier (Arg, Name);
20380 Check_Arg_Is_Identifier (Argx);
20381
20382 if Chars (Argx) = Name_Strict then
20383 return Strict;
20384
20385 elsif Chars (Argx) = Name_Minimized then
20386 return Minimized;
20387
20388 elsif Chars (Argx) = Name_Eliminated then
20389 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
20390 Error_Pragma_Arg
20391 ("Eliminated not implemented on this target", Argx);
20392 else
20393 return Eliminated;
20394 end if;
20395
20396 else
20397 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
20398 end if;
20399 end Get_Overflow_Mode;
20400
20401 -- Start of processing for Overflow_Mode
20402
20403 begin
20404 GNAT_Pragma;
20405 Check_At_Least_N_Arguments (1);
20406 Check_At_Most_N_Arguments (2);
20407
20408 -- Process first argument
20409
20410 Scope_Suppress.Overflow_Mode_General :=
20411 Get_Overflow_Mode (Name_General, Arg1);
20412
20413 -- Case of only one argument
20414
20415 if Arg_Count = 1 then
20416 Scope_Suppress.Overflow_Mode_Assertions :=
20417 Scope_Suppress.Overflow_Mode_General;
20418
20419 -- Case of two arguments present
20420
20421 else
20422 Scope_Suppress.Overflow_Mode_Assertions :=
20423 Get_Overflow_Mode (Name_Assertions, Arg2);
20424 end if;
20425 end Overflow_Mode;
20426
20427 --------------------------
20428 -- Overriding Renamings --
20429 --------------------------
20430
20431 -- pragma Overriding_Renamings;
20432
20433 when Pragma_Overriding_Renamings =>
20434 GNAT_Pragma;
20435 Check_Arg_Count (0);
20436 Check_Valid_Configuration_Pragma;
20437 Overriding_Renamings := True;
20438
20439 ----------
20440 -- Pack --
20441 ----------
20442
20443 -- pragma Pack (first_subtype_LOCAL_NAME);
20444
20445 when Pragma_Pack => Pack : declare
20446 Assoc : constant Node_Id := Arg1;
20447 Ctyp : Entity_Id;
20448 Ignore : Boolean := False;
20449 Typ : Entity_Id;
20450 Type_Id : Node_Id;
20451
20452 begin
20453 Check_No_Identifiers;
20454 Check_Arg_Count (1);
20455 Check_Arg_Is_Local_Name (Arg1);
20456 Type_Id := Get_Pragma_Arg (Assoc);
20457
20458 if not Is_Entity_Name (Type_Id)
20459 or else not Is_Type (Entity (Type_Id))
20460 then
20461 Error_Pragma_Arg
20462 ("argument for pragma% must be type or subtype", Arg1);
20463 end if;
20464
20465 Find_Type (Type_Id);
20466 Typ := Entity (Type_Id);
20467
20468 if Typ = Any_Type
20469 or else Rep_Item_Too_Early (Typ, N)
20470 then
20471 return;
20472 else
20473 Typ := Underlying_Type (Typ);
20474 end if;
20475
20476 -- A pragma that applies to a Ghost entity becomes Ghost for the
20477 -- purposes of legality checks and removal of ignored Ghost code.
20478
20479 Mark_Ghost_Pragma (N, Typ);
20480
20481 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
20482 Error_Pragma ("pragma% must specify array or record type");
20483 end if;
20484
20485 Check_First_Subtype (Arg1);
20486 Check_Duplicate_Pragma (Typ);
20487
20488 -- Array type
20489
20490 if Is_Array_Type (Typ) then
20491 Ctyp := Component_Type (Typ);
20492
20493 -- Ignore pack that does nothing
20494
20495 if Known_Static_Esize (Ctyp)
20496 and then Known_Static_RM_Size (Ctyp)
20497 and then Esize (Ctyp) = RM_Size (Ctyp)
20498 and then Addressable (Esize (Ctyp))
20499 then
20500 Ignore := True;
20501 end if;
20502
20503 -- Process OK pragma Pack. Note that if there is a separate
20504 -- component clause present, the Pack will be cancelled. This
20505 -- processing is in Freeze.
20506
20507 if not Rep_Item_Too_Late (Typ, N) then
20508
20509 -- In CodePeer mode, we do not need complex front-end
20510 -- expansions related to pragma Pack, so disable handling
20511 -- of pragma Pack.
20512
20513 if CodePeer_Mode then
20514 null;
20515
20516 -- Normal case where we do the pack action
20517
20518 else
20519 if not Ignore then
20520 Set_Is_Packed (Base_Type (Typ));
20521 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20522 end if;
20523
20524 Set_Has_Pragma_Pack (Base_Type (Typ));
20525 end if;
20526 end if;
20527
20528 -- For record types, the pack is always effective
20529
20530 else pragma Assert (Is_Record_Type (Typ));
20531 if not Rep_Item_Too_Late (Typ, N) then
20532 Set_Is_Packed (Base_Type (Typ));
20533 Set_Has_Pragma_Pack (Base_Type (Typ));
20534 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20535 end if;
20536 end if;
20537 end Pack;
20538
20539 ----------
20540 -- Page --
20541 ----------
20542
20543 -- pragma Page;
20544
20545 -- There is nothing to do here, since we did all the processing for
20546 -- this pragma in Par.Prag (so that it works properly even in syntax
20547 -- only mode).
20548
20549 when Pragma_Page =>
20550 null;
20551
20552 -------------
20553 -- Part_Of --
20554 -------------
20555
20556 -- pragma Part_Of (ABSTRACT_STATE);
20557
20558 -- ABSTRACT_STATE ::= NAME
20559
20560 when Pragma_Part_Of => Part_Of : declare
20561 procedure Propagate_Part_Of
20562 (Pack_Id : Entity_Id;
20563 State_Id : Entity_Id;
20564 Instance : Node_Id);
20565 -- Propagate the Part_Of indicator to all abstract states and
20566 -- objects declared in the visible state space of a package
20567 -- denoted by Pack_Id. State_Id is the encapsulating state.
20568 -- Instance is the package instantiation node.
20569
20570 -----------------------
20571 -- Propagate_Part_Of --
20572 -----------------------
20573
20574 procedure Propagate_Part_Of
20575 (Pack_Id : Entity_Id;
20576 State_Id : Entity_Id;
20577 Instance : Node_Id)
20578 is
20579 Has_Item : Boolean := False;
20580 -- Flag set when the visible state space contains at least one
20581 -- abstract state or variable.
20582
20583 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
20584 -- Propagate the Part_Of indicator to all abstract states and
20585 -- objects declared in the visible state space of a package
20586 -- denoted by Pack_Id.
20587
20588 -----------------------
20589 -- Propagate_Part_Of --
20590 -----------------------
20591
20592 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
20593 Constits : Elist_Id;
20594 Item_Id : Entity_Id;
20595
20596 begin
20597 -- Traverse the entity chain of the package and set relevant
20598 -- attributes of abstract states and objects declared in the
20599 -- visible state space of the package.
20600
20601 Item_Id := First_Entity (Pack_Id);
20602 while Present (Item_Id)
20603 and then not In_Private_Part (Item_Id)
20604 loop
20605 -- Do not consider internally generated items
20606
20607 if not Comes_From_Source (Item_Id) then
20608 null;
20609
20610 -- Do not consider generic formals or their corresponding
20611 -- actuals because they are not part of a visible state.
20612 -- Note that both entities are marked as hidden.
20613
20614 elsif Is_Hidden (Item_Id) then
20615 null;
20616
20617 -- The Part_Of indicator turns an abstract state or an
20618 -- object into a constituent of the encapsulating state.
20619 -- Note that constants are considered here even though
20620 -- they may not depend on variable input. This check is
20621 -- left to the SPARK prover.
20622
20623 elsif Ekind (Item_Id) in
20624 E_Abstract_State | E_Constant | E_Variable
20625 then
20626 Has_Item := True;
20627 Constits := Part_Of_Constituents (State_Id);
20628
20629 if No (Constits) then
20630 Constits := New_Elmt_List;
20631 Set_Part_Of_Constituents (State_Id, Constits);
20632 end if;
20633
20634 Append_Elmt (Item_Id, Constits);
20635 Set_Encapsulating_State (Item_Id, State_Id);
20636
20637 -- Recursively handle nested packages and instantiations
20638
20639 elsif Ekind (Item_Id) = E_Package then
20640 Propagate_Part_Of (Item_Id);
20641 end if;
20642
20643 Next_Entity (Item_Id);
20644 end loop;
20645 end Propagate_Part_Of;
20646
20647 -- Start of processing for Propagate_Part_Of
20648
20649 begin
20650 Propagate_Part_Of (Pack_Id);
20651
20652 -- Detect a package instantiation that is subject to a Part_Of
20653 -- indicator, but has no visible state.
20654
20655 if not Has_Item then
20656 SPARK_Msg_NE
20657 ("package instantiation & has Part_Of indicator but "
20658 & "lacks visible state", Instance, Pack_Id);
20659 end if;
20660 end Propagate_Part_Of;
20661
20662 -- Local variables
20663
20664 Constits : Elist_Id;
20665 Encap : Node_Id;
20666 Encap_Id : Entity_Id;
20667 Item_Id : Entity_Id;
20668 Legal : Boolean;
20669 Stmt : Node_Id;
20670
20671 -- Start of processing for Part_Of
20672
20673 begin
20674 GNAT_Pragma;
20675 Check_No_Identifiers;
20676 Check_Arg_Count (1);
20677
20678 Stmt := Find_Related_Context (N, Do_Checks => True);
20679
20680 -- Object declaration
20681
20682 if Nkind (Stmt) = N_Object_Declaration then
20683 null;
20684
20685 -- Package instantiation
20686
20687 elsif Nkind (Stmt) = N_Package_Instantiation then
20688 null;
20689
20690 -- Single concurrent type declaration
20691
20692 elsif Is_Single_Concurrent_Type_Declaration (Stmt) then
20693 null;
20694
20695 -- Otherwise the pragma is associated with an illegal construct
20696
20697 else
20698 Pragma_Misplaced;
20699 return;
20700 end if;
20701
20702 -- Extract the entity of the related object declaration or package
20703 -- instantiation. In the case of the instantiation, use the entity
20704 -- of the instance spec.
20705
20706 if Nkind (Stmt) = N_Package_Instantiation then
20707 Stmt := Instance_Spec (Stmt);
20708 end if;
20709
20710 Item_Id := Defining_Entity (Stmt);
20711
20712 -- A pragma that applies to a Ghost entity becomes Ghost for the
20713 -- purposes of legality checks and removal of ignored Ghost code.
20714
20715 Mark_Ghost_Pragma (N, Item_Id);
20716
20717 -- Chain the pragma on the contract for further processing by
20718 -- Analyze_Part_Of_In_Decl_Part or for completeness.
20719
20720 Add_Contract_Item (N, Item_Id);
20721
20722 -- A variable may act as constituent of a single concurrent type
20723 -- which in turn could be declared after the variable. Due to this
20724 -- discrepancy, the full analysis of indicator Part_Of is delayed
20725 -- until the end of the enclosing declarative region (see routine
20726 -- Analyze_Part_Of_In_Decl_Part).
20727
20728 if Ekind (Item_Id) = E_Variable then
20729 null;
20730
20731 -- Otherwise indicator Part_Of applies to a constant or a package
20732 -- instantiation.
20733
20734 else
20735 Encap := Get_Pragma_Arg (Arg1);
20736
20737 -- Detect any discrepancies between the placement of the
20738 -- constant or package instantiation with respect to state
20739 -- space and the encapsulating state.
20740
20741 Analyze_Part_Of
20742 (Indic => N,
20743 Item_Id => Item_Id,
20744 Encap => Encap,
20745 Encap_Id => Encap_Id,
20746 Legal => Legal);
20747
20748 if Legal then
20749 pragma Assert (Present (Encap_Id));
20750
20751 if Ekind (Item_Id) = E_Constant then
20752 Constits := Part_Of_Constituents (Encap_Id);
20753
20754 if No (Constits) then
20755 Constits := New_Elmt_List;
20756 Set_Part_Of_Constituents (Encap_Id, Constits);
20757 end if;
20758
20759 Append_Elmt (Item_Id, Constits);
20760 Set_Encapsulating_State (Item_Id, Encap_Id);
20761
20762 -- Propagate the Part_Of indicator to the visible state
20763 -- space of the package instantiation.
20764
20765 else
20766 Propagate_Part_Of
20767 (Pack_Id => Item_Id,
20768 State_Id => Encap_Id,
20769 Instance => Stmt);
20770 end if;
20771 end if;
20772 end if;
20773 end Part_Of;
20774
20775 ----------------------------------
20776 -- Partition_Elaboration_Policy --
20777 ----------------------------------
20778
20779 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
20780
20781 when Pragma_Partition_Elaboration_Policy => PEP : declare
20782 subtype PEP_Range is Name_Id
20783 range First_Partition_Elaboration_Policy_Name
20784 .. Last_Partition_Elaboration_Policy_Name;
20785 PEP_Val : PEP_Range;
20786 PEP : Character;
20787
20788 begin
20789 Ada_2005_Pragma;
20790 Check_Arg_Count (1);
20791 Check_No_Identifiers;
20792 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
20793 Check_Valid_Configuration_Pragma;
20794 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
20795
20796 case PEP_Val is
20797 when Name_Concurrent => PEP := 'C';
20798 when Name_Sequential => PEP := 'S';
20799 end case;
20800
20801 if Partition_Elaboration_Policy /= ' '
20802 and then Partition_Elaboration_Policy /= PEP
20803 then
20804 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
20805 Error_Pragma
20806 ("partition elaboration policy incompatible with policy#");
20807
20808 -- Set new policy, but always preserve System_Location since we
20809 -- like the error message with the run time name.
20810
20811 else
20812 Partition_Elaboration_Policy := PEP;
20813
20814 if Partition_Elaboration_Policy_Sloc /= System_Location then
20815 Partition_Elaboration_Policy_Sloc := Loc;
20816 end if;
20817 end if;
20818 end PEP;
20819
20820 -------------
20821 -- Passive --
20822 -------------
20823
20824 -- pragma Passive [(PASSIVE_FORM)];
20825
20826 -- PASSIVE_FORM ::= Semaphore | No
20827
20828 when Pragma_Passive =>
20829 GNAT_Pragma;
20830
20831 if Nkind (Parent (N)) /= N_Task_Definition then
20832 Error_Pragma ("pragma% must be within task definition");
20833 end if;
20834
20835 if Arg_Count /= 0 then
20836 Check_Arg_Count (1);
20837 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
20838 end if;
20839
20840 ----------------------------------
20841 -- Preelaborable_Initialization --
20842 ----------------------------------
20843
20844 -- pragma Preelaborable_Initialization (DIRECT_NAME);
20845
20846 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
20847 Ent : Entity_Id;
20848
20849 begin
20850 Ada_2005_Pragma;
20851 Check_Arg_Count (1);
20852 Check_No_Identifiers;
20853 Check_Arg_Is_Identifier (Arg1);
20854 Check_Arg_Is_Local_Name (Arg1);
20855 Check_First_Subtype (Arg1);
20856 Ent := Entity (Get_Pragma_Arg (Arg1));
20857
20858 -- A pragma that applies to a Ghost entity becomes Ghost for the
20859 -- purposes of legality checks and removal of ignored Ghost code.
20860
20861 Mark_Ghost_Pragma (N, Ent);
20862
20863 -- The pragma may come from an aspect on a private declaration,
20864 -- even if the freeze point at which this is analyzed in the
20865 -- private part after the full view.
20866
20867 if Has_Private_Declaration (Ent)
20868 and then From_Aspect_Specification (N)
20869 then
20870 null;
20871
20872 -- Check appropriate type argument
20873
20874 elsif Is_Private_Type (Ent)
20875 or else Is_Protected_Type (Ent)
20876 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
20877
20878 -- AI05-0028: The pragma applies to all composite types. Note
20879 -- that we apply this binding interpretation to earlier versions
20880 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
20881 -- choice since there are other compilers that do the same.
20882
20883 or else Is_Composite_Type (Ent)
20884 then
20885 null;
20886
20887 else
20888 Error_Pragma_Arg
20889 ("pragma % can only be applied to private, formal derived, "
20890 & "protected, or composite type", Arg1);
20891 end if;
20892
20893 -- Give an error if the pragma is applied to a protected type that
20894 -- does not qualify (due to having entries, or due to components
20895 -- that do not qualify).
20896
20897 if Is_Protected_Type (Ent)
20898 and then not Has_Preelaborable_Initialization (Ent)
20899 then
20900 Error_Msg_N
20901 ("protected type & does not have preelaborable "
20902 & "initialization", Ent);
20903
20904 -- Otherwise mark the type as definitely having preelaborable
20905 -- initialization.
20906
20907 else
20908 Set_Known_To_Have_Preelab_Init (Ent);
20909 end if;
20910
20911 if Has_Pragma_Preelab_Init (Ent)
20912 and then Warn_On_Redundant_Constructs
20913 then
20914 Error_Pragma ("?r?duplicate pragma%!");
20915 else
20916 Set_Has_Pragma_Preelab_Init (Ent);
20917 end if;
20918 end Preelab_Init;
20919
20920 --------------------
20921 -- Persistent_BSS --
20922 --------------------
20923
20924 -- pragma Persistent_BSS [(object_NAME)];
20925
20926 when Pragma_Persistent_BSS => Persistent_BSS : declare
20927 Decl : Node_Id;
20928 Ent : Entity_Id;
20929 Prag : Node_Id;
20930
20931 begin
20932 GNAT_Pragma;
20933 Check_At_Most_N_Arguments (1);
20934
20935 -- Case of application to specific object (one argument)
20936
20937 if Arg_Count = 1 then
20938 Check_Arg_Is_Library_Level_Local_Name (Arg1);
20939
20940 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
20941 or else
20942 Ekind (Entity (Get_Pragma_Arg (Arg1))) not in
20943 E_Variable | E_Constant
20944 then
20945 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
20946 end if;
20947
20948 Ent := Entity (Get_Pragma_Arg (Arg1));
20949
20950 -- A pragma that applies to a Ghost entity becomes Ghost for
20951 -- the purposes of legality checks and removal of ignored Ghost
20952 -- code.
20953
20954 Mark_Ghost_Pragma (N, Ent);
20955
20956 -- Check for duplication before inserting in list of
20957 -- representation items.
20958
20959 Check_Duplicate_Pragma (Ent);
20960
20961 if Rep_Item_Too_Late (Ent, N) then
20962 return;
20963 end if;
20964
20965 Decl := Parent (Ent);
20966
20967 if Present (Expression (Decl)) then
20968 -- Variables in Persistent_BSS cannot be initialized, so
20969 -- turn off any initialization that might be caused by
20970 -- pragmas Initialize_Scalars or Normalize_Scalars.
20971
20972 if Kill_Range_Check (Expression (Decl)) then
20973 Prag :=
20974 Make_Pragma (Loc,
20975 Name_Suppress_Initialization,
20976 Pragma_Argument_Associations => New_List (
20977 Make_Pragma_Argument_Association (Loc,
20978 Expression => New_Occurrence_Of (Ent, Loc))));
20979 Insert_Before (N, Prag);
20980 Analyze (Prag);
20981
20982 else
20983 Error_Pragma_Arg
20984 ("object for pragma% cannot have initialization", Arg1);
20985 end if;
20986 end if;
20987
20988 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
20989 Error_Pragma_Arg
20990 ("object type for pragma% is not potentially persistent",
20991 Arg1);
20992 end if;
20993
20994 Prag :=
20995 Make_Linker_Section_Pragma
20996 (Ent, Loc, ".persistent.bss");
20997 Insert_After (N, Prag);
20998 Analyze (Prag);
20999
21000 -- Case of use as configuration pragma with no arguments
21001
21002 else
21003 Check_Valid_Configuration_Pragma;
21004 Persistent_BSS_Mode := True;
21005 end if;
21006 end Persistent_BSS;
21007
21008 --------------------
21009 -- Rename_Pragma --
21010 --------------------
21011
21012 -- pragma Rename_Pragma (
21013 -- [New_Name =>] IDENTIFIER,
21014 -- [Renamed =>] pragma_IDENTIFIER);
21015
21016 when Pragma_Rename_Pragma => Rename_Pragma : declare
21017 New_Name : constant Node_Id := Get_Pragma_Arg (Arg1);
21018 Old_Name : constant Node_Id := Get_Pragma_Arg (Arg2);
21019
21020 begin
21021 GNAT_Pragma;
21022 Check_Valid_Configuration_Pragma;
21023 Check_Arg_Count (2);
21024 Check_Optional_Identifier (Arg1, Name_New_Name);
21025 Check_Optional_Identifier (Arg2, Name_Renamed);
21026
21027 if Nkind (New_Name) /= N_Identifier then
21028 Error_Pragma_Arg ("identifier expected", Arg1);
21029 end if;
21030
21031 if Nkind (Old_Name) /= N_Identifier then
21032 Error_Pragma_Arg ("identifier expected", Arg2);
21033 end if;
21034
21035 -- The New_Name arg should not be an existing pragma (but we allow
21036 -- it; it's just a warning). The Old_Name arg must be an existing
21037 -- pragma.
21038
21039 if Is_Pragma_Name (Chars (New_Name)) then
21040 Error_Pragma_Arg ("??pragma is already defined", Arg1);
21041 end if;
21042
21043 if not Is_Pragma_Name (Chars (Old_Name)) then
21044 Error_Pragma_Arg ("existing pragma name expected", Arg1);
21045 end if;
21046
21047 Map_Pragma_Name (From => Chars (New_Name), To => Chars (Old_Name));
21048 end Rename_Pragma;
21049
21050 -----------------------------------
21051 -- Post/Post_Class/Postcondition --
21052 -----------------------------------
21053
21054 -- pragma Post (Boolean_EXPRESSION);
21055 -- pragma Post_Class (Boolean_EXPRESSION);
21056 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
21057 -- [,[Message =>] String_EXPRESSION]);
21058
21059 -- Characteristics:
21060
21061 -- * Analysis - The annotation undergoes initial checks to verify
21062 -- the legal placement and context. Secondary checks preanalyze the
21063 -- expression in:
21064
21065 -- Analyze_Pre_Post_Condition_In_Decl_Part
21066
21067 -- * Expansion - The annotation is expanded during the expansion of
21068 -- the related subprogram [body] contract as performed in:
21069
21070 -- Expand_Subprogram_Contract
21071
21072 -- * Template - The annotation utilizes the generic template of the
21073 -- related subprogram [body] when it is:
21074
21075 -- aspect on subprogram declaration
21076 -- aspect on stand-alone subprogram body
21077 -- pragma on stand-alone subprogram body
21078
21079 -- The annotation must prepare its own template when it is:
21080
21081 -- pragma on subprogram declaration
21082
21083 -- * Globals - Capture of global references must occur after full
21084 -- analysis.
21085
21086 -- * Instance - The annotation is instantiated automatically when
21087 -- the related generic subprogram [body] is instantiated except for
21088 -- the "pragma on subprogram declaration" case. In that scenario
21089 -- the annotation must instantiate itself.
21090
21091 when Pragma_Post
21092 | Pragma_Post_Class
21093 | Pragma_Postcondition
21094 =>
21095 Analyze_Pre_Post_Condition;
21096
21097 --------------------------------
21098 -- Pre/Pre_Class/Precondition --
21099 --------------------------------
21100
21101 -- pragma Pre (Boolean_EXPRESSION);
21102 -- pragma Pre_Class (Boolean_EXPRESSION);
21103 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
21104 -- [,[Message =>] String_EXPRESSION]);
21105
21106 -- Characteristics:
21107
21108 -- * Analysis - The annotation undergoes initial checks to verify
21109 -- the legal placement and context. Secondary checks preanalyze the
21110 -- expression in:
21111
21112 -- Analyze_Pre_Post_Condition_In_Decl_Part
21113
21114 -- * Expansion - The annotation is expanded during the expansion of
21115 -- the related subprogram [body] contract as performed in:
21116
21117 -- Expand_Subprogram_Contract
21118
21119 -- * Template - The annotation utilizes the generic template of the
21120 -- related subprogram [body] when it is:
21121
21122 -- aspect on subprogram declaration
21123 -- aspect on stand-alone subprogram body
21124 -- pragma on stand-alone subprogram body
21125
21126 -- The annotation must prepare its own template when it is:
21127
21128 -- pragma on subprogram declaration
21129
21130 -- * Globals - Capture of global references must occur after full
21131 -- analysis.
21132
21133 -- * Instance - The annotation is instantiated automatically when
21134 -- the related generic subprogram [body] is instantiated except for
21135 -- the "pragma on subprogram declaration" case. In that scenario
21136 -- the annotation must instantiate itself.
21137
21138 when Pragma_Pre
21139 | Pragma_Pre_Class
21140 | Pragma_Precondition
21141 =>
21142 Analyze_Pre_Post_Condition;
21143
21144 ---------------
21145 -- Predicate --
21146 ---------------
21147
21148 -- pragma Predicate
21149 -- ([Entity =>] type_LOCAL_NAME,
21150 -- [Check =>] boolean_EXPRESSION);
21151
21152 when Pragma_Predicate => Predicate : declare
21153 Discard : Boolean;
21154 Typ : Entity_Id;
21155 Type_Id : Node_Id;
21156
21157 begin
21158 GNAT_Pragma;
21159 Check_Arg_Count (2);
21160 Check_Optional_Identifier (Arg1, Name_Entity);
21161 Check_Optional_Identifier (Arg2, Name_Check);
21162
21163 Check_Arg_Is_Local_Name (Arg1);
21164
21165 Type_Id := Get_Pragma_Arg (Arg1);
21166 Find_Type (Type_Id);
21167 Typ := Entity (Type_Id);
21168
21169 if Typ = Any_Type then
21170 return;
21171 end if;
21172
21173 -- A pragma that applies to a Ghost entity becomes Ghost for the
21174 -- purposes of legality checks and removal of ignored Ghost code.
21175
21176 Mark_Ghost_Pragma (N, Typ);
21177
21178 -- The remaining processing is simply to link the pragma on to
21179 -- the rep item chain, for processing when the type is frozen.
21180 -- This is accomplished by a call to Rep_Item_Too_Late. We also
21181 -- mark the type as having predicates.
21182
21183 -- If the current policy for predicate checking is Ignore mark the
21184 -- subtype accordingly. In the case of predicates we consider them
21185 -- enabled unless Ignore is specified (either directly or with a
21186 -- general Assertion_Policy pragma) to preserve existing warnings.
21187
21188 Set_Has_Predicates (Typ);
21189
21190 -- Indicate that the pragma must be processed at the point the
21191 -- type is frozen, as is done for the corresponding aspect.
21192
21193 Set_Has_Delayed_Aspects (Typ);
21194 Set_Has_Delayed_Freeze (Typ);
21195
21196 Set_Predicates_Ignored (Typ,
21197 Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore);
21198 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
21199 end Predicate;
21200
21201 -----------------------
21202 -- Predicate_Failure --
21203 -----------------------
21204
21205 -- pragma Predicate_Failure
21206 -- ([Entity =>] type_LOCAL_NAME,
21207 -- [Message =>] string_EXPRESSION);
21208
21209 when Pragma_Predicate_Failure => Predicate_Failure : declare
21210 Discard : Boolean;
21211 Typ : Entity_Id;
21212 Type_Id : Node_Id;
21213
21214 begin
21215 GNAT_Pragma;
21216 Check_Arg_Count (2);
21217 Check_Optional_Identifier (Arg1, Name_Entity);
21218 Check_Optional_Identifier (Arg2, Name_Message);
21219
21220 Check_Arg_Is_Local_Name (Arg1);
21221
21222 Type_Id := Get_Pragma_Arg (Arg1);
21223 Find_Type (Type_Id);
21224 Typ := Entity (Type_Id);
21225
21226 if Typ = Any_Type then
21227 return;
21228 end if;
21229
21230 -- A pragma that applies to a Ghost entity becomes Ghost for the
21231 -- purposes of legality checks and removal of ignored Ghost code.
21232
21233 Mark_Ghost_Pragma (N, Typ);
21234
21235 -- The remaining processing is simply to link the pragma on to
21236 -- the rep item chain, for processing when the type is frozen.
21237 -- This is accomplished by a call to Rep_Item_Too_Late.
21238
21239 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
21240 end Predicate_Failure;
21241
21242 ------------------
21243 -- Preelaborate --
21244 ------------------
21245
21246 -- pragma Preelaborate [(library_unit_NAME)];
21247
21248 -- Set the flag Is_Preelaborated of program unit name entity
21249
21250 when Pragma_Preelaborate => Preelaborate : declare
21251 Pa : constant Node_Id := Parent (N);
21252 Pk : constant Node_Kind := Nkind (Pa);
21253 Ent : Entity_Id;
21254
21255 begin
21256 Check_Ada_83_Warning;
21257 Check_Valid_Library_Unit_Pragma;
21258
21259 Ent := Find_Lib_Unit_Name;
21260
21261 -- A pragma that applies to a Ghost entity becomes Ghost for the
21262 -- purposes of legality checks and removal of ignored Ghost code.
21263
21264 Mark_Ghost_Pragma (N, Ent);
21265 Check_Duplicate_Pragma (Ent);
21266
21267 -- This filters out pragmas inside generic parents that show up
21268 -- inside instantiations. Pragmas that come from aspects in the
21269 -- unit are not ignored.
21270
21271 if Present (Ent) then
21272 if Pk = N_Package_Specification
21273 and then Present (Generic_Parent (Pa))
21274 and then not From_Aspect_Specification (N)
21275 then
21276 null;
21277
21278 else
21279 if not Debug_Flag_U then
21280 Set_Is_Preelaborated (Ent);
21281
21282 if Legacy_Elaboration_Checks then
21283 Set_Suppress_Elaboration_Warnings (Ent);
21284 end if;
21285 end if;
21286 end if;
21287 end if;
21288 end Preelaborate;
21289
21290 -------------------------------
21291 -- Prefix_Exception_Messages --
21292 -------------------------------
21293
21294 -- pragma Prefix_Exception_Messages;
21295
21296 when Pragma_Prefix_Exception_Messages =>
21297 GNAT_Pragma;
21298 Check_Valid_Configuration_Pragma;
21299 Check_Arg_Count (0);
21300 Prefix_Exception_Messages := True;
21301
21302 --------------
21303 -- Priority --
21304 --------------
21305
21306 -- pragma Priority (EXPRESSION);
21307
21308 when Pragma_Priority => Priority : declare
21309 P : constant Node_Id := Parent (N);
21310 Arg : Node_Id;
21311 Ent : Entity_Id;
21312
21313 begin
21314 Check_No_Identifiers;
21315 Check_Arg_Count (1);
21316
21317 -- Subprogram case
21318
21319 if Nkind (P) = N_Subprogram_Body then
21320 Check_In_Main_Program;
21321
21322 Ent := Defining_Unit_Name (Specification (P));
21323
21324 if Nkind (Ent) = N_Defining_Program_Unit_Name then
21325 Ent := Defining_Identifier (Ent);
21326 end if;
21327
21328 Arg := Get_Pragma_Arg (Arg1);
21329 Analyze_And_Resolve (Arg, Standard_Integer);
21330
21331 -- Must be static
21332
21333 if not Is_OK_Static_Expression (Arg) then
21334 Flag_Non_Static_Expr
21335 ("main subprogram priority is not static!", Arg);
21336 raise Pragma_Exit;
21337
21338 -- If constraint error, then we already signalled an error
21339
21340 elsif Raises_Constraint_Error (Arg) then
21341 null;
21342
21343 -- Otherwise check in range except if Relaxed_RM_Semantics
21344 -- where we ignore the value if out of range.
21345
21346 else
21347 if not Relaxed_RM_Semantics
21348 and then not Is_In_Range (Arg, RTE (RE_Priority))
21349 then
21350 Error_Pragma_Arg
21351 ("main subprogram priority is out of range", Arg1);
21352 else
21353 Set_Main_Priority
21354 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
21355 end if;
21356 end if;
21357
21358 -- Load an arbitrary entity from System.Tasking.Stages or
21359 -- System.Tasking.Restricted.Stages (depending on the
21360 -- supported profile) to make sure that one of these packages
21361 -- is implicitly with'ed, since we need to have the tasking
21362 -- run time active for the pragma Priority to have any effect.
21363 -- Previously we with'ed the package System.Tasking, but this
21364 -- package does not trigger the required initialization of the
21365 -- run-time library.
21366
21367 if Restricted_Profile then
21368 Discard_Node (RTE (RE_Activate_Restricted_Tasks));
21369 else
21370 Discard_Node (RTE (RE_Activate_Tasks));
21371 end if;
21372
21373 -- Task or Protected, must be of type Integer
21374
21375 elsif Nkind (P) in N_Protected_Definition | N_Task_Definition then
21376 Arg := Get_Pragma_Arg (Arg1);
21377 Ent := Defining_Identifier (Parent (P));
21378
21379 -- The expression must be analyzed in the special manner
21380 -- described in "Handling of Default and Per-Object
21381 -- Expressions" in sem.ads.
21382
21383 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
21384
21385 if not Is_OK_Static_Expression (Arg) then
21386 Check_Restriction (Static_Priorities, Arg);
21387 end if;
21388
21389 -- Anything else is incorrect
21390
21391 else
21392 Pragma_Misplaced;
21393 end if;
21394
21395 -- Check duplicate pragma before we chain the pragma in the Rep
21396 -- Item chain of Ent.
21397
21398 Check_Duplicate_Pragma (Ent);
21399 Record_Rep_Item (Ent, N);
21400 end Priority;
21401
21402 -----------------------------------
21403 -- Priority_Specific_Dispatching --
21404 -----------------------------------
21405
21406 -- pragma Priority_Specific_Dispatching (
21407 -- policy_IDENTIFIER,
21408 -- first_priority_EXPRESSION,
21409 -- last_priority_EXPRESSION);
21410
21411 when Pragma_Priority_Specific_Dispatching =>
21412 Priority_Specific_Dispatching : declare
21413 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
21414 -- This is the entity System.Any_Priority;
21415
21416 DP : Character;
21417 Lower_Bound : Node_Id;
21418 Upper_Bound : Node_Id;
21419 Lower_Val : Uint;
21420 Upper_Val : Uint;
21421
21422 begin
21423 Ada_2005_Pragma;
21424 Check_Arg_Count (3);
21425 Check_No_Identifiers;
21426 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
21427 Check_Valid_Configuration_Pragma;
21428 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21429 DP := Fold_Upper (Name_Buffer (1));
21430
21431 Lower_Bound := Get_Pragma_Arg (Arg2);
21432 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
21433 Lower_Val := Expr_Value (Lower_Bound);
21434
21435 Upper_Bound := Get_Pragma_Arg (Arg3);
21436 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
21437 Upper_Val := Expr_Value (Upper_Bound);
21438
21439 -- It is not allowed to use Task_Dispatching_Policy and
21440 -- Priority_Specific_Dispatching in the same partition.
21441
21442 if Task_Dispatching_Policy /= ' ' then
21443 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21444 Error_Pragma
21445 ("pragma% incompatible with Task_Dispatching_Policy#");
21446
21447 -- Check lower bound in range
21448
21449 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21450 or else
21451 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
21452 then
21453 Error_Pragma_Arg
21454 ("first_priority is out of range", Arg2);
21455
21456 -- Check upper bound in range
21457
21458 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21459 or else
21460 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
21461 then
21462 Error_Pragma_Arg
21463 ("last_priority is out of range", Arg3);
21464
21465 -- Check that the priority range is valid
21466
21467 elsif Lower_Val > Upper_Val then
21468 Error_Pragma
21469 ("last_priority_expression must be greater than or equal to "
21470 & "first_priority_expression");
21471
21472 -- Store the new policy, but always preserve System_Location since
21473 -- we like the error message with the run-time name.
21474
21475 else
21476 -- Check overlapping in the priority ranges specified in other
21477 -- Priority_Specific_Dispatching pragmas within the same
21478 -- partition. We can only check those we know about.
21479
21480 for J in
21481 Specific_Dispatching.First .. Specific_Dispatching.Last
21482 loop
21483 if Specific_Dispatching.Table (J).First_Priority in
21484 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21485 or else Specific_Dispatching.Table (J).Last_Priority in
21486 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21487 then
21488 Error_Msg_Sloc :=
21489 Specific_Dispatching.Table (J).Pragma_Loc;
21490 Error_Pragma
21491 ("priority range overlaps with "
21492 & "Priority_Specific_Dispatching#");
21493 end if;
21494 end loop;
21495
21496 -- The use of Priority_Specific_Dispatching is incompatible
21497 -- with Task_Dispatching_Policy.
21498
21499 if Task_Dispatching_Policy /= ' ' then
21500 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21501 Error_Pragma
21502 ("Priority_Specific_Dispatching incompatible "
21503 & "with Task_Dispatching_Policy#");
21504 end if;
21505
21506 -- The use of Priority_Specific_Dispatching forces ceiling
21507 -- locking policy.
21508
21509 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
21510 Error_Msg_Sloc := Locking_Policy_Sloc;
21511 Error_Pragma
21512 ("Priority_Specific_Dispatching incompatible "
21513 & "with Locking_Policy#");
21514
21515 -- Set the Ceiling_Locking policy, but preserve System_Location
21516 -- since we like the error message with the run time name.
21517
21518 else
21519 Locking_Policy := 'C';
21520
21521 if Locking_Policy_Sloc /= System_Location then
21522 Locking_Policy_Sloc := Loc;
21523 end if;
21524 end if;
21525
21526 -- Add entry in the table
21527
21528 Specific_Dispatching.Append
21529 ((Dispatching_Policy => DP,
21530 First_Priority => UI_To_Int (Lower_Val),
21531 Last_Priority => UI_To_Int (Upper_Val),
21532 Pragma_Loc => Loc));
21533 end if;
21534 end Priority_Specific_Dispatching;
21535
21536 -------------
21537 -- Profile --
21538 -------------
21539
21540 -- pragma Profile (profile_IDENTIFIER);
21541
21542 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
21543
21544 when Pragma_Profile =>
21545 Ada_2005_Pragma;
21546 Check_Arg_Count (1);
21547 Check_Valid_Configuration_Pragma;
21548 Check_No_Identifiers;
21549
21550 declare
21551 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21552
21553 begin
21554 if Nkind (Argx) /= N_Identifier then
21555 Error_Msg_N
21556 ("argument of pragma Profile must be an identifier", N);
21557
21558 elsif Chars (Argx) = Name_Ravenscar then
21559 Set_Ravenscar_Profile (Ravenscar, N);
21560
21561 elsif Chars (Argx) = Name_Jorvik then
21562 Set_Ravenscar_Profile (Jorvik, N);
21563
21564 elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then
21565 Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N);
21566
21567 elsif Chars (Argx) = Name_Gnat_Ravenscar_EDF then
21568 Set_Ravenscar_Profile (GNAT_Ravenscar_EDF, N);
21569
21570 elsif Chars (Argx) = Name_Restricted then
21571 Set_Profile_Restrictions
21572 (Restricted,
21573 N, Warn => Treat_Restrictions_As_Warnings);
21574
21575 elsif Chars (Argx) = Name_Rational then
21576 Set_Rational_Profile;
21577
21578 elsif Chars (Argx) = Name_No_Implementation_Extensions then
21579 Set_Profile_Restrictions
21580 (No_Implementation_Extensions,
21581 N, Warn => Treat_Restrictions_As_Warnings);
21582
21583 else
21584 Error_Pragma_Arg ("& is not a valid profile", Argx);
21585 end if;
21586 end;
21587
21588 ----------------------
21589 -- Profile_Warnings --
21590 ----------------------
21591
21592 -- pragma Profile_Warnings (profile_IDENTIFIER);
21593
21594 -- profile_IDENTIFIER => Restricted | Ravenscar
21595
21596 when Pragma_Profile_Warnings =>
21597 GNAT_Pragma;
21598 Check_Arg_Count (1);
21599 Check_Valid_Configuration_Pragma;
21600 Check_No_Identifiers;
21601
21602 declare
21603 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21604
21605 begin
21606 if Chars (Argx) = Name_Ravenscar then
21607 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
21608
21609 elsif Chars (Argx) = Name_Restricted then
21610 Set_Profile_Restrictions (Restricted, N, Warn => True);
21611
21612 elsif Chars (Argx) = Name_No_Implementation_Extensions then
21613 Set_Profile_Restrictions
21614 (No_Implementation_Extensions, N, Warn => True);
21615
21616 else
21617 Error_Pragma_Arg ("& is not a valid profile", Argx);
21618 end if;
21619 end;
21620
21621 --------------------------
21622 -- Propagate_Exceptions --
21623 --------------------------
21624
21625 -- pragma Propagate_Exceptions;
21626
21627 -- Note: this pragma is obsolete and has no effect
21628
21629 when Pragma_Propagate_Exceptions =>
21630 GNAT_Pragma;
21631 Check_Arg_Count (0);
21632
21633 if Warn_On_Obsolescent_Feature then
21634 Error_Msg_N
21635 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
21636 "and has no effect?j?", N);
21637 end if;
21638
21639 -----------------------------
21640 -- Provide_Shift_Operators --
21641 -----------------------------
21642
21643 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
21644
21645 when Pragma_Provide_Shift_Operators =>
21646 Provide_Shift_Operators : declare
21647 Ent : Entity_Id;
21648
21649 procedure Declare_Shift_Operator (Nam : Name_Id);
21650 -- Insert declaration and pragma Instrinsic for named shift op
21651
21652 ----------------------------
21653 -- Declare_Shift_Operator --
21654 ----------------------------
21655
21656 procedure Declare_Shift_Operator (Nam : Name_Id) is
21657 Func : Node_Id;
21658 Import : Node_Id;
21659
21660 begin
21661 Func :=
21662 Make_Subprogram_Declaration (Loc,
21663 Make_Function_Specification (Loc,
21664 Defining_Unit_Name =>
21665 Make_Defining_Identifier (Loc, Chars => Nam),
21666
21667 Result_Definition =>
21668 Make_Identifier (Loc, Chars => Chars (Ent)),
21669
21670 Parameter_Specifications => New_List (
21671 Make_Parameter_Specification (Loc,
21672 Defining_Identifier =>
21673 Make_Defining_Identifier (Loc, Name_Value),
21674 Parameter_Type =>
21675 Make_Identifier (Loc, Chars => Chars (Ent))),
21676
21677 Make_Parameter_Specification (Loc,
21678 Defining_Identifier =>
21679 Make_Defining_Identifier (Loc, Name_Amount),
21680 Parameter_Type =>
21681 New_Occurrence_Of (Standard_Natural, Loc)))));
21682
21683 Import :=
21684 Make_Pragma (Loc,
21685 Chars => Name_Import,
21686 Pragma_Argument_Associations => New_List (
21687 Make_Pragma_Argument_Association (Loc,
21688 Expression => Make_Identifier (Loc, Name_Intrinsic)),
21689 Make_Pragma_Argument_Association (Loc,
21690 Expression => Make_Identifier (Loc, Nam))));
21691
21692 Insert_After (N, Import);
21693 Insert_After (N, Func);
21694 end Declare_Shift_Operator;
21695
21696 -- Start of processing for Provide_Shift_Operators
21697
21698 begin
21699 GNAT_Pragma;
21700 Check_Arg_Count (1);
21701 Check_Arg_Is_Local_Name (Arg1);
21702
21703 Arg1 := Get_Pragma_Arg (Arg1);
21704
21705 -- We must have an entity name
21706
21707 if not Is_Entity_Name (Arg1) then
21708 Error_Pragma_Arg
21709 ("pragma % must apply to integer first subtype", Arg1);
21710 end if;
21711
21712 -- If no Entity, means there was a prior error so ignore
21713
21714 if Present (Entity (Arg1)) then
21715 Ent := Entity (Arg1);
21716
21717 -- Apply error checks
21718
21719 if not Is_First_Subtype (Ent) then
21720 Error_Pragma_Arg
21721 ("cannot apply pragma %",
21722 "\& is not a first subtype",
21723 Arg1);
21724
21725 elsif not Is_Integer_Type (Ent) then
21726 Error_Pragma_Arg
21727 ("cannot apply pragma %",
21728 "\& is not an integer type",
21729 Arg1);
21730
21731 elsif Has_Shift_Operator (Ent) then
21732 Error_Pragma_Arg
21733 ("cannot apply pragma %",
21734 "\& already has declared shift operators",
21735 Arg1);
21736
21737 elsif Is_Frozen (Ent) then
21738 Error_Pragma_Arg
21739 ("pragma % appears too late",
21740 "\& is already frozen",
21741 Arg1);
21742 end if;
21743
21744 -- Now declare the operators. We do this during analysis rather
21745 -- than expansion, since we want the operators available if we
21746 -- are operating in -gnatc mode.
21747
21748 Declare_Shift_Operator (Name_Rotate_Left);
21749 Declare_Shift_Operator (Name_Rotate_Right);
21750 Declare_Shift_Operator (Name_Shift_Left);
21751 Declare_Shift_Operator (Name_Shift_Right);
21752 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
21753 end if;
21754 end Provide_Shift_Operators;
21755
21756 ------------------
21757 -- Psect_Object --
21758 ------------------
21759
21760 -- pragma Psect_Object (
21761 -- [Internal =>] LOCAL_NAME,
21762 -- [, [External =>] EXTERNAL_SYMBOL]
21763 -- [, [Size =>] EXTERNAL_SYMBOL]);
21764
21765 when Pragma_Common_Object
21766 | Pragma_Psect_Object
21767 =>
21768 Psect_Object : declare
21769 Args : Args_List (1 .. 3);
21770 Names : constant Name_List (1 .. 3) := (
21771 Name_Internal,
21772 Name_External,
21773 Name_Size);
21774
21775 Internal : Node_Id renames Args (1);
21776 External : Node_Id renames Args (2);
21777 Size : Node_Id renames Args (3);
21778
21779 Def_Id : Entity_Id;
21780
21781 procedure Check_Arg (Arg : Node_Id);
21782 -- Checks that argument is either a string literal or an
21783 -- identifier, and posts error message if not.
21784
21785 ---------------
21786 -- Check_Arg --
21787 ---------------
21788
21789 procedure Check_Arg (Arg : Node_Id) is
21790 begin
21791 if Nkind (Original_Node (Arg)) not in
21792 N_String_Literal | N_Identifier
21793 then
21794 Error_Pragma_Arg
21795 ("inappropriate argument for pragma %", Arg);
21796 end if;
21797 end Check_Arg;
21798
21799 -- Start of processing for Common_Object/Psect_Object
21800
21801 begin
21802 GNAT_Pragma;
21803 Gather_Associations (Names, Args);
21804 Process_Extended_Import_Export_Internal_Arg (Internal);
21805
21806 Def_Id := Entity (Internal);
21807
21808 if Ekind (Def_Id) not in E_Constant | E_Variable then
21809 Error_Pragma_Arg
21810 ("pragma% must designate an object", Internal);
21811 end if;
21812
21813 Check_Arg (Internal);
21814
21815 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
21816 Error_Pragma_Arg
21817 ("cannot use pragma% for imported/exported object",
21818 Internal);
21819 end if;
21820
21821 if Is_Concurrent_Type (Etype (Internal)) then
21822 Error_Pragma_Arg
21823 ("cannot specify pragma % for task/protected object",
21824 Internal);
21825 end if;
21826
21827 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
21828 or else
21829 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
21830 then
21831 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
21832 end if;
21833
21834 if Ekind (Def_Id) = E_Constant then
21835 Error_Pragma_Arg
21836 ("cannot specify pragma % for a constant", Internal);
21837 end if;
21838
21839 if Is_Record_Type (Etype (Internal)) then
21840 declare
21841 Ent : Entity_Id;
21842 Decl : Entity_Id;
21843
21844 begin
21845 Ent := First_Entity (Etype (Internal));
21846 while Present (Ent) loop
21847 Decl := Declaration_Node (Ent);
21848
21849 if Ekind (Ent) = E_Component
21850 and then Nkind (Decl) = N_Component_Declaration
21851 and then Present (Expression (Decl))
21852 and then Warn_On_Export_Import
21853 then
21854 Error_Msg_N
21855 ("?x?object for pragma % has defaults", Internal);
21856 exit;
21857
21858 else
21859 Next_Entity (Ent);
21860 end if;
21861 end loop;
21862 end;
21863 end if;
21864
21865 if Present (Size) then
21866 Check_Arg (Size);
21867 end if;
21868
21869 if Present (External) then
21870 Check_Arg_Is_External_Name (External);
21871 end if;
21872
21873 -- If all error tests pass, link pragma on to the rep item chain
21874
21875 Record_Rep_Item (Def_Id, N);
21876 end Psect_Object;
21877
21878 ----------
21879 -- Pure --
21880 ----------
21881
21882 -- pragma Pure [(library_unit_NAME)];
21883
21884 when Pragma_Pure => Pure : declare
21885 Ent : Entity_Id;
21886
21887 begin
21888 Check_Ada_83_Warning;
21889
21890 -- If the pragma comes from a subprogram instantiation, nothing to
21891 -- check, this can happen at any level of nesting.
21892
21893 if Is_Wrapper_Package (Current_Scope) then
21894 return;
21895 else
21896 Check_Valid_Library_Unit_Pragma;
21897 end if;
21898
21899 Ent := Find_Lib_Unit_Name;
21900
21901 -- A pragma that applies to a Ghost entity becomes Ghost for the
21902 -- purposes of legality checks and removal of ignored Ghost code.
21903
21904 Mark_Ghost_Pragma (N, Ent);
21905
21906 if not Debug_Flag_U then
21907 Set_Is_Pure (Ent);
21908 Set_Has_Pragma_Pure (Ent);
21909
21910 if Legacy_Elaboration_Checks then
21911 Set_Suppress_Elaboration_Warnings (Ent);
21912 end if;
21913 end if;
21914 end Pure;
21915
21916 -------------------
21917 -- Pure_Function --
21918 -------------------
21919
21920 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
21921
21922 when Pragma_Pure_Function => Pure_Function : declare
21923 Def_Id : Entity_Id;
21924 E : Entity_Id;
21925 E_Id : Node_Id;
21926 Effective : Boolean := False;
21927 Orig_Def : Entity_Id;
21928 Same_Decl : Boolean := False;
21929
21930 begin
21931 GNAT_Pragma;
21932 Check_Arg_Count (1);
21933 Check_Optional_Identifier (Arg1, Name_Entity);
21934 Check_Arg_Is_Local_Name (Arg1);
21935 E_Id := Get_Pragma_Arg (Arg1);
21936
21937 if Etype (E_Id) = Any_Type then
21938 return;
21939 end if;
21940
21941 -- Loop through homonyms (overloadings) of referenced entity
21942
21943 E := Entity (E_Id);
21944
21945 -- A pragma that applies to a Ghost entity becomes Ghost for the
21946 -- purposes of legality checks and removal of ignored Ghost code.
21947
21948 Mark_Ghost_Pragma (N, E);
21949
21950 if Present (E) then
21951 loop
21952 Def_Id := Get_Base_Subprogram (E);
21953
21954 if Ekind (Def_Id) not in
21955 E_Function | E_Generic_Function | E_Operator
21956 then
21957 Error_Pragma_Arg
21958 ("pragma% requires a function name", Arg1);
21959 end if;
21960
21961 -- When we have a generic function we must jump up a level
21962 -- to the declaration of the wrapper package itself.
21963
21964 Orig_Def := Def_Id;
21965
21966 if Is_Generic_Instance (Def_Id) then
21967 while Nkind (Orig_Def) /= N_Package_Declaration loop
21968 Orig_Def := Parent (Orig_Def);
21969 end loop;
21970 end if;
21971
21972 if In_Same_Declarative_Part (Parent (N), Orig_Def) then
21973 Same_Decl := True;
21974 Set_Is_Pure (Def_Id);
21975
21976 if not Has_Pragma_Pure_Function (Def_Id) then
21977 Set_Has_Pragma_Pure_Function (Def_Id);
21978 Effective := True;
21979 end if;
21980 end if;
21981
21982 exit when From_Aspect_Specification (N);
21983 E := Homonym (E);
21984 exit when No (E) or else Scope (E) /= Current_Scope;
21985 end loop;
21986
21987 if not Effective
21988 and then Warn_On_Redundant_Constructs
21989 then
21990 Error_Msg_NE
21991 ("pragma Pure_Function on& is redundant?r?",
21992 N, Entity (E_Id));
21993
21994 elsif not Same_Decl then
21995 Error_Pragma_Arg
21996 ("pragma% argument must be in same declarative part",
21997 Arg1);
21998 end if;
21999 end if;
22000 end Pure_Function;
22001
22002 --------------------
22003 -- Queuing_Policy --
22004 --------------------
22005
22006 -- pragma Queuing_Policy (policy_IDENTIFIER);
22007
22008 when Pragma_Queuing_Policy => declare
22009 QP : Character;
22010
22011 begin
22012 Check_Ada_83_Warning;
22013 Check_Arg_Count (1);
22014 Check_No_Identifiers;
22015 Check_Arg_Is_Queuing_Policy (Arg1);
22016 Check_Valid_Configuration_Pragma;
22017 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
22018 QP := Fold_Upper (Name_Buffer (1));
22019
22020 if Queuing_Policy /= ' '
22021 and then Queuing_Policy /= QP
22022 then
22023 Error_Msg_Sloc := Queuing_Policy_Sloc;
22024 Error_Pragma ("queuing policy incompatible with policy#");
22025
22026 -- Set new policy, but always preserve System_Location since we
22027 -- like the error message with the run time name.
22028
22029 else
22030 Queuing_Policy := QP;
22031
22032 if Queuing_Policy_Sloc /= System_Location then
22033 Queuing_Policy_Sloc := Loc;
22034 end if;
22035 end if;
22036 end;
22037
22038 --------------
22039 -- Rational --
22040 --------------
22041
22042 -- pragma Rational, for compatibility with foreign compiler
22043
22044 when Pragma_Rational =>
22045 Set_Rational_Profile;
22046
22047 ---------------------
22048 -- Refined_Depends --
22049 ---------------------
22050
22051 -- pragma Refined_Depends (DEPENDENCY_RELATION);
22052
22053 -- DEPENDENCY_RELATION ::=
22054 -- null
22055 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
22056
22057 -- DEPENDENCY_CLAUSE ::=
22058 -- OUTPUT_LIST =>[+] INPUT_LIST
22059 -- | NULL_DEPENDENCY_CLAUSE
22060
22061 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
22062
22063 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
22064
22065 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
22066
22067 -- OUTPUT ::= NAME | FUNCTION_RESULT
22068 -- INPUT ::= NAME
22069
22070 -- where FUNCTION_RESULT is a function Result attribute_reference
22071
22072 -- Characteristics:
22073
22074 -- * Analysis - The annotation undergoes initial checks to verify
22075 -- the legal placement and context. Secondary checks fully analyze
22076 -- the dependency clauses/global list in:
22077
22078 -- Analyze_Refined_Depends_In_Decl_Part
22079
22080 -- * Expansion - None.
22081
22082 -- * Template - The annotation utilizes the generic template of the
22083 -- related subprogram body.
22084
22085 -- * Globals - Capture of global references must occur after full
22086 -- analysis.
22087
22088 -- * Instance - The annotation is instantiated automatically when
22089 -- the related generic subprogram body is instantiated.
22090
22091 when Pragma_Refined_Depends => Refined_Depends : declare
22092 Body_Id : Entity_Id;
22093 Legal : Boolean;
22094 Spec_Id : Entity_Id;
22095
22096 begin
22097 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22098
22099 if Legal then
22100
22101 -- Chain the pragma on the contract for further processing by
22102 -- Analyze_Refined_Depends_In_Decl_Part.
22103
22104 Add_Contract_Item (N, Body_Id);
22105
22106 -- The legality checks of pragmas Refined_Depends and
22107 -- Refined_Global are affected by the SPARK mode in effect and
22108 -- the volatility of the context. In addition these two pragmas
22109 -- are subject to an inherent order:
22110
22111 -- 1) Refined_Global
22112 -- 2) Refined_Depends
22113
22114 -- Analyze all these pragmas in the order outlined above
22115
22116 Analyze_If_Present (Pragma_SPARK_Mode);
22117 Analyze_If_Present (Pragma_Volatile_Function);
22118 Analyze_If_Present (Pragma_Refined_Global);
22119 Analyze_Refined_Depends_In_Decl_Part (N);
22120 end if;
22121 end Refined_Depends;
22122
22123 --------------------
22124 -- Refined_Global --
22125 --------------------
22126
22127 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
22128
22129 -- GLOBAL_SPECIFICATION ::=
22130 -- null
22131 -- | (GLOBAL_LIST)
22132 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
22133
22134 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
22135
22136 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
22137 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
22138 -- GLOBAL_ITEM ::= NAME
22139
22140 -- Characteristics:
22141
22142 -- * Analysis - The annotation undergoes initial checks to verify
22143 -- the legal placement and context. Secondary checks fully analyze
22144 -- the dependency clauses/global list in:
22145
22146 -- Analyze_Refined_Global_In_Decl_Part
22147
22148 -- * Expansion - None.
22149
22150 -- * Template - The annotation utilizes the generic template of the
22151 -- related subprogram body.
22152
22153 -- * Globals - Capture of global references must occur after full
22154 -- analysis.
22155
22156 -- * Instance - The annotation is instantiated automatically when
22157 -- the related generic subprogram body is instantiated.
22158
22159 when Pragma_Refined_Global => Refined_Global : declare
22160 Body_Id : Entity_Id;
22161 Legal : Boolean;
22162 Spec_Id : Entity_Id;
22163
22164 begin
22165 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22166
22167 if Legal then
22168
22169 -- Chain the pragma on the contract for further processing by
22170 -- Analyze_Refined_Global_In_Decl_Part.
22171
22172 Add_Contract_Item (N, Body_Id);
22173
22174 -- The legality checks of pragmas Refined_Depends and
22175 -- Refined_Global are affected by the SPARK mode in effect and
22176 -- the volatility of the context. In addition these two pragmas
22177 -- are subject to an inherent order:
22178
22179 -- 1) Refined_Global
22180 -- 2) Refined_Depends
22181
22182 -- Analyze all these pragmas in the order outlined above
22183
22184 Analyze_If_Present (Pragma_SPARK_Mode);
22185 Analyze_If_Present (Pragma_Volatile_Function);
22186 Analyze_Refined_Global_In_Decl_Part (N);
22187 Analyze_If_Present (Pragma_Refined_Depends);
22188 end if;
22189 end Refined_Global;
22190
22191 ------------------
22192 -- Refined_Post --
22193 ------------------
22194
22195 -- pragma Refined_Post (boolean_EXPRESSION);
22196
22197 -- Characteristics:
22198
22199 -- * Analysis - The annotation is fully analyzed immediately upon
22200 -- elaboration as it cannot forward reference entities.
22201
22202 -- * Expansion - The annotation is expanded during the expansion of
22203 -- the related subprogram body contract as performed in:
22204
22205 -- Expand_Subprogram_Contract
22206
22207 -- * Template - The annotation utilizes the generic template of the
22208 -- related subprogram body.
22209
22210 -- * Globals - Capture of global references must occur after full
22211 -- analysis.
22212
22213 -- * Instance - The annotation is instantiated automatically when
22214 -- the related generic subprogram body is instantiated.
22215
22216 when Pragma_Refined_Post => Refined_Post : declare
22217 Body_Id : Entity_Id;
22218 Legal : Boolean;
22219 Spec_Id : Entity_Id;
22220
22221 begin
22222 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22223
22224 -- Fully analyze the pragma when it appears inside a subprogram
22225 -- body because it cannot benefit from forward references.
22226
22227 if Legal then
22228
22229 -- Chain the pragma on the contract for completeness
22230
22231 Add_Contract_Item (N, Body_Id);
22232
22233 -- The legality checks of pragma Refined_Post are affected by
22234 -- the SPARK mode in effect and the volatility of the context.
22235 -- Analyze all pragmas in a specific order.
22236
22237 Analyze_If_Present (Pragma_SPARK_Mode);
22238 Analyze_If_Present (Pragma_Volatile_Function);
22239 Analyze_Pre_Post_Condition_In_Decl_Part (N);
22240
22241 -- Currently it is not possible to inline pre/postconditions on
22242 -- a subprogram subject to pragma Inline_Always.
22243
22244 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
22245 end if;
22246 end Refined_Post;
22247
22248 -------------------
22249 -- Refined_State --
22250 -------------------
22251
22252 -- pragma Refined_State (REFINEMENT_LIST);
22253
22254 -- REFINEMENT_LIST ::=
22255 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
22256
22257 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
22258
22259 -- CONSTITUENT_LIST ::=
22260 -- null
22261 -- | CONSTITUENT
22262 -- | (CONSTITUENT {, CONSTITUENT})
22263
22264 -- CONSTITUENT ::= object_NAME | state_NAME
22265
22266 -- Characteristics:
22267
22268 -- * Analysis - The annotation undergoes initial checks to verify
22269 -- the legal placement and context. Secondary checks preanalyze the
22270 -- refinement clauses in:
22271
22272 -- Analyze_Refined_State_In_Decl_Part
22273
22274 -- * Expansion - None.
22275
22276 -- * Template - The annotation utilizes the template of the related
22277 -- package body.
22278
22279 -- * Globals - Capture of global references must occur after full
22280 -- analysis.
22281
22282 -- * Instance - The annotation is instantiated automatically when
22283 -- the related generic package body is instantiated.
22284
22285 when Pragma_Refined_State => Refined_State : declare
22286 Pack_Decl : Node_Id;
22287 Spec_Id : Entity_Id;
22288
22289 begin
22290 GNAT_Pragma;
22291 Check_No_Identifiers;
22292 Check_Arg_Count (1);
22293
22294 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
22295
22296 if Nkind (Pack_Decl) /= N_Package_Body then
22297 Pragma_Misplaced;
22298 return;
22299 end if;
22300
22301 Spec_Id := Corresponding_Spec (Pack_Decl);
22302
22303 -- A pragma that applies to a Ghost entity becomes Ghost for the
22304 -- purposes of legality checks and removal of ignored Ghost code.
22305
22306 Mark_Ghost_Pragma (N, Spec_Id);
22307
22308 -- Chain the pragma on the contract for further processing by
22309 -- Analyze_Refined_State_In_Decl_Part.
22310
22311 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
22312
22313 -- The legality checks of pragma Refined_State are affected by the
22314 -- SPARK mode in effect. Analyze all pragmas in a specific order.
22315
22316 Analyze_If_Present (Pragma_SPARK_Mode);
22317
22318 -- State refinement is allowed only when the corresponding package
22319 -- declaration has non-null pragma Abstract_State. Refinement not
22320 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
22321
22322 if SPARK_Mode /= Off
22323 and then
22324 (No (Abstract_States (Spec_Id))
22325 or else Has_Null_Abstract_State (Spec_Id))
22326 then
22327 Error_Msg_NE
22328 ("useless refinement, package & does not define abstract "
22329 & "states", N, Spec_Id);
22330 return;
22331 end if;
22332 end Refined_State;
22333
22334 -----------------------
22335 -- Relative_Deadline --
22336 -----------------------
22337
22338 -- pragma Relative_Deadline (time_span_EXPRESSION);
22339
22340 when Pragma_Relative_Deadline => Relative_Deadline : declare
22341 P : constant Node_Id := Parent (N);
22342 Arg : Node_Id;
22343
22344 begin
22345 Ada_2005_Pragma;
22346 Check_No_Identifiers;
22347 Check_Arg_Count (1);
22348
22349 Arg := Get_Pragma_Arg (Arg1);
22350
22351 -- The expression must be analyzed in the special manner described
22352 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
22353
22354 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
22355
22356 -- Subprogram case
22357
22358 if Nkind (P) = N_Subprogram_Body then
22359 Check_In_Main_Program;
22360
22361 -- Only Task and subprogram cases allowed
22362
22363 elsif Nkind (P) /= N_Task_Definition then
22364 Pragma_Misplaced;
22365 end if;
22366
22367 -- Check duplicate pragma before we set the corresponding flag
22368
22369 if Has_Relative_Deadline_Pragma (P) then
22370 Error_Pragma ("duplicate pragma% not allowed");
22371 end if;
22372
22373 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
22374 -- Relative_Deadline pragma node cannot be inserted in the Rep
22375 -- Item chain of Ent since it is rewritten by the expander as a
22376 -- procedure call statement that will break the chain.
22377
22378 Set_Has_Relative_Deadline_Pragma (P);
22379 end Relative_Deadline;
22380
22381 ------------------------
22382 -- Remote_Access_Type --
22383 ------------------------
22384
22385 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
22386
22387 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
22388 E : Entity_Id;
22389
22390 begin
22391 GNAT_Pragma;
22392 Check_Arg_Count (1);
22393 Check_Optional_Identifier (Arg1, Name_Entity);
22394 Check_Arg_Is_Local_Name (Arg1);
22395
22396 E := Entity (Get_Pragma_Arg (Arg1));
22397
22398 -- A pragma that applies to a Ghost entity becomes Ghost for the
22399 -- purposes of legality checks and removal of ignored Ghost code.
22400
22401 Mark_Ghost_Pragma (N, E);
22402
22403 if Nkind (Parent (E)) = N_Formal_Type_Declaration
22404 and then Ekind (E) = E_General_Access_Type
22405 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
22406 and then Scope (Root_Type (Directly_Designated_Type (E)))
22407 = Scope (E)
22408 and then Is_Valid_Remote_Object_Type
22409 (Root_Type (Directly_Designated_Type (E)))
22410 then
22411 Set_Is_Remote_Types (E);
22412
22413 else
22414 Error_Pragma_Arg
22415 ("pragma% applies only to formal access-to-class-wide types",
22416 Arg1);
22417 end if;
22418 end Remote_Access_Type;
22419
22420 ---------------------------
22421 -- Remote_Call_Interface --
22422 ---------------------------
22423
22424 -- pragma Remote_Call_Interface [(library_unit_NAME)];
22425
22426 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
22427 Cunit_Node : Node_Id;
22428 Cunit_Ent : Entity_Id;
22429 K : Node_Kind;
22430
22431 begin
22432 Check_Ada_83_Warning;
22433 Check_Valid_Library_Unit_Pragma;
22434
22435 Cunit_Node := Cunit (Current_Sem_Unit);
22436 K := Nkind (Unit (Cunit_Node));
22437 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22438
22439 -- A pragma that applies to a Ghost entity becomes Ghost for the
22440 -- purposes of legality checks and removal of ignored Ghost code.
22441
22442 Mark_Ghost_Pragma (N, Cunit_Ent);
22443
22444 if K = N_Package_Declaration
22445 or else K = N_Generic_Package_Declaration
22446 or else K = N_Subprogram_Declaration
22447 or else K = N_Generic_Subprogram_Declaration
22448 or else (K = N_Subprogram_Body
22449 and then Acts_As_Spec (Unit (Cunit_Node)))
22450 then
22451 null;
22452 else
22453 Error_Pragma (
22454 "pragma% must apply to package or subprogram declaration");
22455 end if;
22456
22457 Set_Is_Remote_Call_Interface (Cunit_Ent);
22458 end Remote_Call_Interface;
22459
22460 ------------------
22461 -- Remote_Types --
22462 ------------------
22463
22464 -- pragma Remote_Types [(library_unit_NAME)];
22465
22466 when Pragma_Remote_Types => Remote_Types : declare
22467 Cunit_Node : Node_Id;
22468 Cunit_Ent : Entity_Id;
22469
22470 begin
22471 Check_Ada_83_Warning;
22472 Check_Valid_Library_Unit_Pragma;
22473
22474 Cunit_Node := Cunit (Current_Sem_Unit);
22475 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22476
22477 -- A pragma that applies to a Ghost entity becomes Ghost for the
22478 -- purposes of legality checks and removal of ignored Ghost code.
22479
22480 Mark_Ghost_Pragma (N, Cunit_Ent);
22481
22482 if Nkind (Unit (Cunit_Node)) not in
22483 N_Package_Declaration | N_Generic_Package_Declaration
22484 then
22485 Error_Pragma
22486 ("pragma% can only apply to a package declaration");
22487 end if;
22488
22489 Set_Is_Remote_Types (Cunit_Ent);
22490 end Remote_Types;
22491
22492 ---------------
22493 -- Ravenscar --
22494 ---------------
22495
22496 -- pragma Ravenscar;
22497
22498 when Pragma_Ravenscar =>
22499 GNAT_Pragma;
22500 Check_Arg_Count (0);
22501 Check_Valid_Configuration_Pragma;
22502 Set_Ravenscar_Profile (Ravenscar, N);
22503
22504 if Warn_On_Obsolescent_Feature then
22505 Error_Msg_N
22506 ("pragma Ravenscar is an obsolescent feature?j?", N);
22507 Error_Msg_N
22508 ("|use pragma Profile (Ravenscar) instead?j?", N);
22509 end if;
22510
22511 -------------------------
22512 -- Restricted_Run_Time --
22513 -------------------------
22514
22515 -- pragma Restricted_Run_Time;
22516
22517 when Pragma_Restricted_Run_Time =>
22518 GNAT_Pragma;
22519 Check_Arg_Count (0);
22520 Check_Valid_Configuration_Pragma;
22521 Set_Profile_Restrictions
22522 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
22523
22524 if Warn_On_Obsolescent_Feature then
22525 Error_Msg_N
22526 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
22527 N);
22528 Error_Msg_N
22529 ("|use pragma Profile (Restricted) instead?j?", N);
22530 end if;
22531
22532 ------------------
22533 -- Restrictions --
22534 ------------------
22535
22536 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
22537
22538 -- RESTRICTION ::=
22539 -- restriction_IDENTIFIER
22540 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22541
22542 when Pragma_Restrictions =>
22543 Process_Restrictions_Or_Restriction_Warnings
22544 (Warn => Treat_Restrictions_As_Warnings);
22545
22546 --------------------------
22547 -- Restriction_Warnings --
22548 --------------------------
22549
22550 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
22551
22552 -- RESTRICTION ::=
22553 -- restriction_IDENTIFIER
22554 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22555
22556 when Pragma_Restriction_Warnings =>
22557 GNAT_Pragma;
22558 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
22559
22560 ----------------
22561 -- Reviewable --
22562 ----------------
22563
22564 -- pragma Reviewable;
22565
22566 when Pragma_Reviewable =>
22567 Check_Ada_83_Warning;
22568 Check_Arg_Count (0);
22569
22570 -- Call dummy debugging function rv. This is done to assist front
22571 -- end debugging. By placing a Reviewable pragma in the source
22572 -- program, a breakpoint on rv catches this place in the source,
22573 -- allowing convenient stepping to the point of interest.
22574
22575 rv;
22576
22577 --------------------------
22578 -- Secondary_Stack_Size --
22579 --------------------------
22580
22581 -- pragma Secondary_Stack_Size (EXPRESSION);
22582
22583 when Pragma_Secondary_Stack_Size => Secondary_Stack_Size : declare
22584 P : constant Node_Id := Parent (N);
22585 Arg : Node_Id;
22586 Ent : Entity_Id;
22587
22588 begin
22589 GNAT_Pragma;
22590 Check_No_Identifiers;
22591 Check_Arg_Count (1);
22592
22593 if Nkind (P) = N_Task_Definition then
22594 Arg := Get_Pragma_Arg (Arg1);
22595 Ent := Defining_Identifier (Parent (P));
22596
22597 -- The expression must be analyzed in the special manner
22598 -- described in "Handling of Default Expressions" in sem.ads.
22599
22600 Preanalyze_Spec_Expression (Arg, Any_Integer);
22601
22602 -- The pragma cannot appear if the No_Secondary_Stack
22603 -- restriction is in effect.
22604
22605 Check_Restriction (No_Secondary_Stack, Arg);
22606
22607 -- Anything else is incorrect
22608
22609 else
22610 Pragma_Misplaced;
22611 end if;
22612
22613 -- Check duplicate pragma before we chain the pragma in the Rep
22614 -- Item chain of Ent.
22615
22616 Check_Duplicate_Pragma (Ent);
22617 Record_Rep_Item (Ent, N);
22618 end Secondary_Stack_Size;
22619
22620 --------------------------
22621 -- Short_Circuit_And_Or --
22622 --------------------------
22623
22624 -- pragma Short_Circuit_And_Or;
22625
22626 when Pragma_Short_Circuit_And_Or =>
22627 GNAT_Pragma;
22628 Check_Arg_Count (0);
22629 Check_Valid_Configuration_Pragma;
22630 Short_Circuit_And_Or := True;
22631
22632 -------------------
22633 -- Share_Generic --
22634 -------------------
22635
22636 -- pragma Share_Generic (GNAME {, GNAME});
22637
22638 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
22639
22640 when Pragma_Share_Generic =>
22641 GNAT_Pragma;
22642 Process_Generic_List;
22643
22644 ------------
22645 -- Shared --
22646 ------------
22647
22648 -- pragma Shared (LOCAL_NAME);
22649
22650 when Pragma_Shared =>
22651 GNAT_Pragma;
22652 Process_Atomic_Independent_Shared_Volatile;
22653
22654 --------------------
22655 -- Shared_Passive --
22656 --------------------
22657
22658 -- pragma Shared_Passive [(library_unit_NAME)];
22659
22660 -- Set the flag Is_Shared_Passive of program unit name entity
22661
22662 when Pragma_Shared_Passive => Shared_Passive : declare
22663 Cunit_Node : Node_Id;
22664 Cunit_Ent : Entity_Id;
22665
22666 begin
22667 Check_Ada_83_Warning;
22668 Check_Valid_Library_Unit_Pragma;
22669
22670 Cunit_Node := Cunit (Current_Sem_Unit);
22671 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22672
22673 -- A pragma that applies to a Ghost entity becomes Ghost for the
22674 -- purposes of legality checks and removal of ignored Ghost code.
22675
22676 Mark_Ghost_Pragma (N, Cunit_Ent);
22677
22678 if Nkind (Unit (Cunit_Node)) not in
22679 N_Package_Declaration | N_Generic_Package_Declaration
22680 then
22681 Error_Pragma
22682 ("pragma% can only apply to a package declaration");
22683 end if;
22684
22685 Set_Is_Shared_Passive (Cunit_Ent);
22686 end Shared_Passive;
22687
22688 -----------------------
22689 -- Short_Descriptors --
22690 -----------------------
22691
22692 -- pragma Short_Descriptors;
22693
22694 -- Recognize and validate, but otherwise ignore
22695
22696 when Pragma_Short_Descriptors =>
22697 GNAT_Pragma;
22698 Check_Arg_Count (0);
22699 Check_Valid_Configuration_Pragma;
22700
22701 ------------------------------
22702 -- Simple_Storage_Pool_Type --
22703 ------------------------------
22704
22705 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
22706
22707 when Pragma_Simple_Storage_Pool_Type =>
22708 Simple_Storage_Pool_Type : declare
22709 Typ : Entity_Id;
22710 Type_Id : Node_Id;
22711
22712 begin
22713 GNAT_Pragma;
22714 Check_Arg_Count (1);
22715 Check_Arg_Is_Library_Level_Local_Name (Arg1);
22716
22717 Type_Id := Get_Pragma_Arg (Arg1);
22718 Find_Type (Type_Id);
22719 Typ := Entity (Type_Id);
22720
22721 if Typ = Any_Type then
22722 return;
22723 end if;
22724
22725 -- A pragma that applies to a Ghost entity becomes Ghost for the
22726 -- purposes of legality checks and removal of ignored Ghost code.
22727
22728 Mark_Ghost_Pragma (N, Typ);
22729
22730 -- We require the pragma to apply to a type declared in a package
22731 -- declaration, but not (immediately) within a package body.
22732
22733 if Ekind (Current_Scope) /= E_Package
22734 or else In_Package_Body (Current_Scope)
22735 then
22736 Error_Pragma
22737 ("pragma% can only apply to type declared immediately "
22738 & "within a package declaration");
22739 end if;
22740
22741 -- A simple storage pool type must be an immutably limited record
22742 -- or private type. If the pragma is given for a private type,
22743 -- the full type is similarly restricted (which is checked later
22744 -- in Freeze_Entity).
22745
22746 if Is_Record_Type (Typ)
22747 and then not Is_Limited_View (Typ)
22748 then
22749 Error_Pragma
22750 ("pragma% can only apply to explicitly limited record type");
22751
22752 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
22753 Error_Pragma
22754 ("pragma% can only apply to a private type that is limited");
22755
22756 elsif not Is_Record_Type (Typ)
22757 and then not Is_Private_Type (Typ)
22758 then
22759 Error_Pragma
22760 ("pragma% can only apply to limited record or private type");
22761 end if;
22762
22763 Record_Rep_Item (Typ, N);
22764 end Simple_Storage_Pool_Type;
22765
22766 ----------------------
22767 -- Source_File_Name --
22768 ----------------------
22769
22770 -- There are five forms for this pragma:
22771
22772 -- pragma Source_File_Name (
22773 -- [UNIT_NAME =>] unit_NAME,
22774 -- BODY_FILE_NAME => STRING_LITERAL
22775 -- [, [INDEX =>] INTEGER_LITERAL]);
22776
22777 -- pragma Source_File_Name (
22778 -- [UNIT_NAME =>] unit_NAME,
22779 -- SPEC_FILE_NAME => STRING_LITERAL
22780 -- [, [INDEX =>] INTEGER_LITERAL]);
22781
22782 -- pragma Source_File_Name (
22783 -- BODY_FILE_NAME => STRING_LITERAL
22784 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22785 -- [, CASING => CASING_SPEC]);
22786
22787 -- pragma Source_File_Name (
22788 -- SPEC_FILE_NAME => STRING_LITERAL
22789 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22790 -- [, CASING => CASING_SPEC]);
22791
22792 -- pragma Source_File_Name (
22793 -- SUBUNIT_FILE_NAME => STRING_LITERAL
22794 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22795 -- [, CASING => CASING_SPEC]);
22796
22797 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
22798
22799 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
22800 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
22801 -- only be used when no project file is used, while SFNP can only be
22802 -- used when a project file is used.
22803
22804 -- No processing here. Processing was completed during parsing, since
22805 -- we need to have file names set as early as possible. Units are
22806 -- loaded well before semantic processing starts.
22807
22808 -- The only processing we defer to this point is the check for
22809 -- correct placement.
22810
22811 when Pragma_Source_File_Name =>
22812 GNAT_Pragma;
22813 Check_Valid_Configuration_Pragma;
22814
22815 ------------------------------
22816 -- Source_File_Name_Project --
22817 ------------------------------
22818
22819 -- See Source_File_Name for syntax
22820
22821 -- No processing here. Processing was completed during parsing, since
22822 -- we need to have file names set as early as possible. Units are
22823 -- loaded well before semantic processing starts.
22824
22825 -- The only processing we defer to this point is the check for
22826 -- correct placement.
22827
22828 when Pragma_Source_File_Name_Project =>
22829 GNAT_Pragma;
22830 Check_Valid_Configuration_Pragma;
22831
22832 -- Check that a pragma Source_File_Name_Project is used only in a
22833 -- configuration pragmas file.
22834
22835 -- Pragmas Source_File_Name_Project should only be generated by
22836 -- the Project Manager in configuration pragmas files.
22837
22838 -- This is really an ugly test. It seems to depend on some
22839 -- accidental and undocumented property. At the very least it
22840 -- needs to be documented, but it would be better to have a
22841 -- clean way of testing if we are in a configuration file???
22842
22843 if Present (Parent (N)) then
22844 Error_Pragma
22845 ("pragma% can only appear in a configuration pragmas file");
22846 end if;
22847
22848 ----------------------
22849 -- Source_Reference --
22850 ----------------------
22851
22852 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
22853
22854 -- Nothing to do, all processing completed in Par.Prag, since we need
22855 -- the information for possible parser messages that are output.
22856
22857 when Pragma_Source_Reference =>
22858 GNAT_Pragma;
22859
22860 ----------------
22861 -- SPARK_Mode --
22862 ----------------
22863
22864 -- pragma SPARK_Mode [(On | Off)];
22865
22866 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
22867 Mode_Id : SPARK_Mode_Type;
22868
22869 procedure Check_Pragma_Conformance
22870 (Context_Pragma : Node_Id;
22871 Entity : Entity_Id;
22872 Entity_Pragma : Node_Id);
22873 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
22874 -- conformance of pragma N depending the following scenarios:
22875 --
22876 -- If pragma Context_Pragma is not Empty, verify that pragma N is
22877 -- compatible with the pragma Context_Pragma that was inherited
22878 -- from the context:
22879 -- * If the mode of Context_Pragma is ON, then the new mode can
22880 -- be anything.
22881 -- * If the mode of Context_Pragma is OFF, then the only allowed
22882 -- new mode is also OFF. Emit error if this is not the case.
22883 --
22884 -- If Entity is not Empty, verify that pragma N is compatible with
22885 -- pragma Entity_Pragma that belongs to Entity.
22886 -- * If Entity_Pragma is Empty, always issue an error as this
22887 -- corresponds to the case where a previous section of Entity
22888 -- has no SPARK_Mode set.
22889 -- * If the mode of Entity_Pragma is ON, then the new mode can
22890 -- be anything.
22891 -- * If the mode of Entity_Pragma is OFF, then the only allowed
22892 -- new mode is also OFF. Emit error if this is not the case.
22893
22894 procedure Check_Library_Level_Entity (E : Entity_Id);
22895 -- Subsidiary to routines Process_xxx. Verify that the related
22896 -- entity E subject to pragma SPARK_Mode is library-level.
22897
22898 procedure Process_Body (Decl : Node_Id);
22899 -- Verify the legality of pragma SPARK_Mode when it appears as the
22900 -- top of the body declarations of entry, package, protected unit,
22901 -- subprogram or task unit body denoted by Decl.
22902
22903 procedure Process_Overloadable (Decl : Node_Id);
22904 -- Verify the legality of pragma SPARK_Mode when it applies to an
22905 -- entry or [generic] subprogram declaration denoted by Decl.
22906
22907 procedure Process_Private_Part (Decl : Node_Id);
22908 -- Verify the legality of pragma SPARK_Mode when it appears at the
22909 -- top of the private declarations of a package spec, protected or
22910 -- task unit declaration denoted by Decl.
22911
22912 procedure Process_Statement_Part (Decl : Node_Id);
22913 -- Verify the legality of pragma SPARK_Mode when it appears at the
22914 -- top of the statement sequence of a package body denoted by node
22915 -- Decl.
22916
22917 procedure Process_Visible_Part (Decl : Node_Id);
22918 -- Verify the legality of pragma SPARK_Mode when it appears at the
22919 -- top of the visible declarations of a package spec, protected or
22920 -- task unit declaration denoted by Decl. The routine is also used
22921 -- on protected or task units declared without a definition.
22922
22923 procedure Set_SPARK_Context;
22924 -- Subsidiary to routines Process_xxx. Set the global variables
22925 -- which represent the mode of the context from pragma N. Ensure
22926 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
22927
22928 ------------------------------
22929 -- Check_Pragma_Conformance --
22930 ------------------------------
22931
22932 procedure Check_Pragma_Conformance
22933 (Context_Pragma : Node_Id;
22934 Entity : Entity_Id;
22935 Entity_Pragma : Node_Id)
22936 is
22937 Err_Id : Entity_Id;
22938 Err_N : Node_Id;
22939
22940 begin
22941 -- The current pragma may appear without an argument. If this
22942 -- is the case, associate all error messages with the pragma
22943 -- itself.
22944
22945 if Present (Arg1) then
22946 Err_N := Arg1;
22947 else
22948 Err_N := N;
22949 end if;
22950
22951 -- The mode of the current pragma is compared against that of
22952 -- an enclosing context.
22953
22954 if Present (Context_Pragma) then
22955 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
22956
22957 -- Issue an error if the new mode is less restrictive than
22958 -- that of the context.
22959
22960 if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off
22961 and then Get_SPARK_Mode_From_Annotation (N) = On
22962 then
22963 Error_Msg_N
22964 ("cannot change SPARK_Mode from Off to On", Err_N);
22965 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
22966 Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N);
22967 raise Pragma_Exit;
22968 end if;
22969 end if;
22970
22971 -- The mode of the current pragma is compared against that of
22972 -- an initial package, protected type, subprogram or task type
22973 -- declaration.
22974
22975 if Present (Entity) then
22976
22977 -- A simple protected or task type is transformed into an
22978 -- anonymous type whose name cannot be used to issue error
22979 -- messages. Recover the original entity of the type.
22980
22981 if Ekind (Entity) in E_Protected_Type | E_Task_Type then
22982 Err_Id :=
22983 Defining_Entity
22984 (Original_Node (Unit_Declaration_Node (Entity)));
22985 else
22986 Err_Id := Entity;
22987 end if;
22988
22989 -- Both the initial declaration and the completion carry
22990 -- SPARK_Mode pragmas.
22991
22992 if Present (Entity_Pragma) then
22993 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
22994
22995 -- Issue an error if the new mode is less restrictive
22996 -- than that of the initial declaration.
22997
22998 if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off
22999 and then Get_SPARK_Mode_From_Annotation (N) = On
23000 then
23001 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
23002 Error_Msg_Sloc := Sloc (Entity_Pragma);
23003 Error_Msg_NE
23004 ("\value Off was set for SPARK_Mode on&#",
23005 Err_N, Err_Id);
23006 raise Pragma_Exit;
23007 end if;
23008
23009 -- Otherwise the initial declaration lacks a SPARK_Mode
23010 -- pragma in which case the current pragma is illegal as
23011 -- it cannot "complete".
23012
23013 elsif Get_SPARK_Mode_From_Annotation (N) = Off
23014 and then (Is_Generic_Unit (Entity) or else In_Instance)
23015 then
23016 null;
23017
23018 else
23019 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
23020 Error_Msg_Sloc := Sloc (Err_Id);
23021 Error_Msg_NE
23022 ("\no value was set for SPARK_Mode on&#",
23023 Err_N, Err_Id);
23024 raise Pragma_Exit;
23025 end if;
23026 end if;
23027 end Check_Pragma_Conformance;
23028
23029 --------------------------------
23030 -- Check_Library_Level_Entity --
23031 --------------------------------
23032
23033 procedure Check_Library_Level_Entity (E : Entity_Id) is
23034 procedure Add_Entity_To_Name_Buffer;
23035 -- Add the E_Kind of entity E to the name buffer
23036
23037 -------------------------------
23038 -- Add_Entity_To_Name_Buffer --
23039 -------------------------------
23040
23041 procedure Add_Entity_To_Name_Buffer is
23042 begin
23043 if Ekind (E) in E_Entry | E_Entry_Family then
23044 Add_Str_To_Name_Buffer ("entry");
23045
23046 elsif Ekind (E) in E_Generic_Package
23047 | E_Package
23048 | E_Package_Body
23049 then
23050 Add_Str_To_Name_Buffer ("package");
23051
23052 elsif Ekind (E) in E_Protected_Body | E_Protected_Type then
23053 Add_Str_To_Name_Buffer ("protected type");
23054
23055 elsif Ekind (E) in E_Function
23056 | E_Generic_Function
23057 | E_Generic_Procedure
23058 | E_Procedure
23059 | E_Subprogram_Body
23060 then
23061 Add_Str_To_Name_Buffer ("subprogram");
23062
23063 else
23064 pragma Assert (Ekind (E) in E_Task_Body | E_Task_Type);
23065 Add_Str_To_Name_Buffer ("task type");
23066 end if;
23067 end Add_Entity_To_Name_Buffer;
23068
23069 -- Local variables
23070
23071 Msg_1 : constant String := "incorrect placement of pragma%";
23072 Msg_2 : Name_Id;
23073
23074 -- Start of processing for Check_Library_Level_Entity
23075
23076 begin
23077 -- A SPARK_Mode of On shall only apply to library-level
23078 -- entities, except for those in generic instances, which are
23079 -- ignored (even if the entity gets SPARK_Mode pragma attached
23080 -- in the AST, its effect is not taken into account unless the
23081 -- context already provides SPARK_Mode of On in GNATprove).
23082
23083 if Get_SPARK_Mode_From_Annotation (N) = On
23084 and then not Is_Library_Level_Entity (E)
23085 and then Instantiation_Location (Sloc (N)) = No_Location
23086 then
23087 Error_Msg_Name_1 := Pname;
23088 Error_Msg_N (Fix_Error (Msg_1), N);
23089
23090 Name_Len := 0;
23091 Add_Str_To_Name_Buffer ("\& is not a library-level ");
23092 Add_Entity_To_Name_Buffer;
23093
23094 Msg_2 := Name_Find;
23095 Error_Msg_NE (Get_Name_String (Msg_2), N, E);
23096
23097 raise Pragma_Exit;
23098 end if;
23099 end Check_Library_Level_Entity;
23100
23101 ------------------
23102 -- Process_Body --
23103 ------------------
23104
23105 procedure Process_Body (Decl : Node_Id) is
23106 Body_Id : constant Entity_Id := Defining_Entity (Decl);
23107 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
23108
23109 begin
23110 -- Ignore pragma when applied to the special body created for
23111 -- inlining, recognized by its internal name _Parent.
23112
23113 if Chars (Body_Id) = Name_uParent then
23114 return;
23115 end if;
23116
23117 Check_Library_Level_Entity (Body_Id);
23118
23119 -- For entry bodies, verify the legality against:
23120 -- * The mode of the context
23121 -- * The mode of the spec (if any)
23122
23123 if Nkind (Decl) in N_Entry_Body | N_Subprogram_Body then
23124
23125 -- A stand-alone subprogram body
23126
23127 if Body_Id = Spec_Id then
23128 Check_Pragma_Conformance
23129 (Context_Pragma => SPARK_Pragma (Body_Id),
23130 Entity => Empty,
23131 Entity_Pragma => Empty);
23132
23133 -- An entry or subprogram body that completes a previous
23134 -- declaration.
23135
23136 else
23137 Check_Pragma_Conformance
23138 (Context_Pragma => SPARK_Pragma (Body_Id),
23139 Entity => Spec_Id,
23140 Entity_Pragma => SPARK_Pragma (Spec_Id));
23141 end if;
23142
23143 Set_SPARK_Context;
23144 Set_SPARK_Pragma (Body_Id, N);
23145 Set_SPARK_Pragma_Inherited (Body_Id, False);
23146
23147 -- For package bodies, verify the legality against:
23148 -- * The mode of the context
23149 -- * The mode of the private part
23150
23151 -- This case is separated from protected and task bodies
23152 -- because the statement part of the package body inherits
23153 -- the mode of the body declarations.
23154
23155 elsif Nkind (Decl) = N_Package_Body then
23156 Check_Pragma_Conformance
23157 (Context_Pragma => SPARK_Pragma (Body_Id),
23158 Entity => Spec_Id,
23159 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
23160
23161 Set_SPARK_Context;
23162 Set_SPARK_Pragma (Body_Id, N);
23163 Set_SPARK_Pragma_Inherited (Body_Id, False);
23164 Set_SPARK_Aux_Pragma (Body_Id, N);
23165 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
23166
23167 -- For protected and task bodies, verify the legality against:
23168 -- * The mode of the context
23169 -- * The mode of the private part
23170
23171 else
23172 pragma Assert
23173 (Nkind (Decl) in N_Protected_Body | N_Task_Body);
23174
23175 Check_Pragma_Conformance
23176 (Context_Pragma => SPARK_Pragma (Body_Id),
23177 Entity => Spec_Id,
23178 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
23179
23180 Set_SPARK_Context;
23181 Set_SPARK_Pragma (Body_Id, N);
23182 Set_SPARK_Pragma_Inherited (Body_Id, False);
23183 end if;
23184 end Process_Body;
23185
23186 --------------------------
23187 -- Process_Overloadable --
23188 --------------------------
23189
23190 procedure Process_Overloadable (Decl : Node_Id) is
23191 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23192 Spec_Typ : constant Entity_Id := Etype (Spec_Id);
23193
23194 begin
23195 Check_Library_Level_Entity (Spec_Id);
23196
23197 -- Verify the legality against:
23198 -- * The mode of the context
23199
23200 Check_Pragma_Conformance
23201 (Context_Pragma => SPARK_Pragma (Spec_Id),
23202 Entity => Empty,
23203 Entity_Pragma => Empty);
23204
23205 Set_SPARK_Pragma (Spec_Id, N);
23206 Set_SPARK_Pragma_Inherited (Spec_Id, False);
23207
23208 -- When the pragma applies to the anonymous object created for
23209 -- a single task type, decorate the type as well. This scenario
23210 -- arises when the single task type lacks a task definition,
23211 -- therefore there is no issue with respect to a potential
23212 -- pragma SPARK_Mode in the private part.
23213
23214 -- task type Anon_Task_Typ;
23215 -- Obj : Anon_Task_Typ;
23216 -- pragma SPARK_Mode ...;
23217
23218 if Is_Single_Task_Object (Spec_Id) then
23219 Set_SPARK_Pragma (Spec_Typ, N);
23220 Set_SPARK_Pragma_Inherited (Spec_Typ, False);
23221 Set_SPARK_Aux_Pragma (Spec_Typ, N);
23222 Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True);
23223 end if;
23224 end Process_Overloadable;
23225
23226 --------------------------
23227 -- Process_Private_Part --
23228 --------------------------
23229
23230 procedure Process_Private_Part (Decl : Node_Id) is
23231 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23232
23233 begin
23234 Check_Library_Level_Entity (Spec_Id);
23235
23236 -- Verify the legality against:
23237 -- * The mode of the visible declarations
23238
23239 Check_Pragma_Conformance
23240 (Context_Pragma => Empty,
23241 Entity => Spec_Id,
23242 Entity_Pragma => SPARK_Pragma (Spec_Id));
23243
23244 Set_SPARK_Context;
23245 Set_SPARK_Aux_Pragma (Spec_Id, N);
23246 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
23247 end Process_Private_Part;
23248
23249 ----------------------------
23250 -- Process_Statement_Part --
23251 ----------------------------
23252
23253 procedure Process_Statement_Part (Decl : Node_Id) is
23254 Body_Id : constant Entity_Id := Defining_Entity (Decl);
23255
23256 begin
23257 Check_Library_Level_Entity (Body_Id);
23258
23259 -- Verify the legality against:
23260 -- * The mode of the body declarations
23261
23262 Check_Pragma_Conformance
23263 (Context_Pragma => Empty,
23264 Entity => Body_Id,
23265 Entity_Pragma => SPARK_Pragma (Body_Id));
23266
23267 Set_SPARK_Context;
23268 Set_SPARK_Aux_Pragma (Body_Id, N);
23269 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
23270 end Process_Statement_Part;
23271
23272 --------------------------
23273 -- Process_Visible_Part --
23274 --------------------------
23275
23276 procedure Process_Visible_Part (Decl : Node_Id) is
23277 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23278 Obj_Id : Entity_Id;
23279
23280 begin
23281 Check_Library_Level_Entity (Spec_Id);
23282
23283 -- Verify the legality against:
23284 -- * The mode of the context
23285
23286 Check_Pragma_Conformance
23287 (Context_Pragma => SPARK_Pragma (Spec_Id),
23288 Entity => Empty,
23289 Entity_Pragma => Empty);
23290
23291 -- A task unit declared without a definition does not set the
23292 -- SPARK_Mode of the context because the task does not have any
23293 -- entries that could inherit the mode.
23294
23295 if Nkind (Decl) not in
23296 N_Single_Task_Declaration | N_Task_Type_Declaration
23297 then
23298 Set_SPARK_Context;
23299 end if;
23300
23301 Set_SPARK_Pragma (Spec_Id, N);
23302 Set_SPARK_Pragma_Inherited (Spec_Id, False);
23303 Set_SPARK_Aux_Pragma (Spec_Id, N);
23304 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
23305
23306 -- When the pragma applies to a single protected or task type,
23307 -- decorate the corresponding anonymous object as well.
23308
23309 -- protected Anon_Prot_Typ is
23310 -- pragma SPARK_Mode ...;
23311 -- ...
23312 -- end Anon_Prot_Typ;
23313
23314 -- Obj : Anon_Prot_Typ;
23315
23316 if Is_Single_Concurrent_Type (Spec_Id) then
23317 Obj_Id := Anonymous_Object (Spec_Id);
23318
23319 Set_SPARK_Pragma (Obj_Id, N);
23320 Set_SPARK_Pragma_Inherited (Obj_Id, False);
23321 end if;
23322 end Process_Visible_Part;
23323
23324 -----------------------
23325 -- Set_SPARK_Context --
23326 -----------------------
23327
23328 procedure Set_SPARK_Context is
23329 begin
23330 SPARK_Mode := Mode_Id;
23331 SPARK_Mode_Pragma := N;
23332 end Set_SPARK_Context;
23333
23334 -- Local variables
23335
23336 Context : Node_Id;
23337 Mode : Name_Id;
23338 Stmt : Node_Id;
23339
23340 -- Start of processing for Do_SPARK_Mode
23341
23342 begin
23343 GNAT_Pragma;
23344 Check_No_Identifiers;
23345 Check_At_Most_N_Arguments (1);
23346
23347 -- Check the legality of the mode (no argument = ON)
23348
23349 if Arg_Count = 1 then
23350 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23351 Mode := Chars (Get_Pragma_Arg (Arg1));
23352 else
23353 Mode := Name_On;
23354 end if;
23355
23356 Mode_Id := Get_SPARK_Mode_Type (Mode);
23357 Context := Parent (N);
23358
23359 -- When a SPARK_Mode pragma appears inside an instantiation whose
23360 -- enclosing context has SPARK_Mode set to "off", the pragma has
23361 -- no semantic effect.
23362
23363 if Ignore_SPARK_Mode_Pragmas_In_Instance
23364 and then Mode_Id /= Off
23365 then
23366 Rewrite (N, Make_Null_Statement (Loc));
23367 Analyze (N);
23368 return;
23369 end if;
23370
23371 -- The pragma appears in a configuration file
23372
23373 if No (Context) then
23374 Check_Valid_Configuration_Pragma;
23375
23376 if Present (SPARK_Mode_Pragma) then
23377 Duplication_Error
23378 (Prag => N,
23379 Prev => SPARK_Mode_Pragma);
23380 raise Pragma_Exit;
23381 end if;
23382
23383 Set_SPARK_Context;
23384
23385 -- The pragma acts as a configuration pragma in a compilation unit
23386
23387 -- pragma SPARK_Mode ...;
23388 -- package Pack is ...;
23389
23390 elsif Nkind (Context) = N_Compilation_Unit
23391 and then List_Containing (N) = Context_Items (Context)
23392 then
23393 Check_Valid_Configuration_Pragma;
23394 Set_SPARK_Context;
23395
23396 -- Otherwise the placement of the pragma within the tree dictates
23397 -- its associated construct. Inspect the declarative list where
23398 -- the pragma resides to find a potential construct.
23399
23400 else
23401 Stmt := Prev (N);
23402 while Present (Stmt) loop
23403
23404 -- Skip prior pragmas, but check for duplicates. Note that
23405 -- this also takes care of pragmas generated for aspects.
23406
23407 if Nkind (Stmt) = N_Pragma then
23408 if Pragma_Name (Stmt) = Pname then
23409 Duplication_Error
23410 (Prag => N,
23411 Prev => Stmt);
23412 raise Pragma_Exit;
23413 end if;
23414
23415 -- The pragma applies to an expression function that has
23416 -- already been rewritten into a subprogram declaration.
23417
23418 -- function Expr_Func return ... is (...);
23419 -- pragma SPARK_Mode ...;
23420
23421 elsif Nkind (Stmt) = N_Subprogram_Declaration
23422 and then Nkind (Original_Node (Stmt)) =
23423 N_Expression_Function
23424 then
23425 Process_Overloadable (Stmt);
23426 return;
23427
23428 -- The pragma applies to the anonymous object created for a
23429 -- single concurrent type.
23430
23431 -- protected type Anon_Prot_Typ ...;
23432 -- Obj : Anon_Prot_Typ;
23433 -- pragma SPARK_Mode ...;
23434
23435 elsif Nkind (Stmt) = N_Object_Declaration
23436 and then Is_Single_Concurrent_Object
23437 (Defining_Entity (Stmt))
23438 then
23439 Process_Overloadable (Stmt);
23440 return;
23441
23442 -- Skip internally generated code
23443
23444 elsif not Comes_From_Source (Stmt) then
23445 null;
23446
23447 -- The pragma applies to an entry or [generic] subprogram
23448 -- declaration.
23449
23450 -- entry Ent ...;
23451 -- pragma SPARK_Mode ...;
23452
23453 -- [generic]
23454 -- procedure Proc ...;
23455 -- pragma SPARK_Mode ...;
23456
23457 elsif Nkind (Stmt) in N_Generic_Subprogram_Declaration
23458 | N_Subprogram_Declaration
23459 or else (Nkind (Stmt) = N_Entry_Declaration
23460 and then Is_Protected_Type
23461 (Scope (Defining_Entity (Stmt))))
23462 then
23463 Process_Overloadable (Stmt);
23464 return;
23465
23466 -- Otherwise the pragma does not apply to a legal construct
23467 -- or it does not appear at the top of a declarative or a
23468 -- statement list. Issue an error and stop the analysis.
23469
23470 else
23471 Pragma_Misplaced;
23472 exit;
23473 end if;
23474
23475 Prev (Stmt);
23476 end loop;
23477
23478 -- The pragma applies to a package or a subprogram that acts as
23479 -- a compilation unit.
23480
23481 -- procedure Proc ...;
23482 -- pragma SPARK_Mode ...;
23483
23484 if Nkind (Context) = N_Compilation_Unit_Aux then
23485 Context := Unit (Parent (Context));
23486 end if;
23487
23488 -- The pragma appears at the top of entry, package, protected
23489 -- unit, subprogram or task unit body declarations.
23490
23491 -- entry Ent when ... is
23492 -- pragma SPARK_Mode ...;
23493
23494 -- package body Pack is
23495 -- pragma SPARK_Mode ...;
23496
23497 -- procedure Proc ... is
23498 -- pragma SPARK_Mode;
23499
23500 -- protected body Prot is
23501 -- pragma SPARK_Mode ...;
23502
23503 if Nkind (Context) in N_Entry_Body
23504 | N_Package_Body
23505 | N_Protected_Body
23506 | N_Subprogram_Body
23507 | N_Task_Body
23508 then
23509 Process_Body (Context);
23510
23511 -- The pragma appears at the top of the visible or private
23512 -- declaration of a package spec, protected or task unit.
23513
23514 -- package Pack is
23515 -- pragma SPARK_Mode ...;
23516 -- private
23517 -- pragma SPARK_Mode ...;
23518
23519 -- protected [type] Prot is
23520 -- pragma SPARK_Mode ...;
23521 -- private
23522 -- pragma SPARK_Mode ...;
23523
23524 elsif Nkind (Context) in N_Package_Specification
23525 | N_Protected_Definition
23526 | N_Task_Definition
23527 then
23528 if List_Containing (N) = Visible_Declarations (Context) then
23529 Process_Visible_Part (Parent (Context));
23530 else
23531 Process_Private_Part (Parent (Context));
23532 end if;
23533
23534 -- The pragma appears at the top of package body statements
23535
23536 -- package body Pack is
23537 -- begin
23538 -- pragma SPARK_Mode;
23539
23540 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
23541 and then Nkind (Parent (Context)) = N_Package_Body
23542 then
23543 Process_Statement_Part (Parent (Context));
23544
23545 -- The pragma appeared as an aspect of a [generic] subprogram
23546 -- declaration that acts as a compilation unit.
23547
23548 -- [generic]
23549 -- procedure Proc ...;
23550 -- pragma SPARK_Mode ...;
23551
23552 elsif Nkind (Context) in N_Generic_Subprogram_Declaration
23553 | N_Subprogram_Declaration
23554 then
23555 Process_Overloadable (Context);
23556
23557 -- The pragma does not apply to a legal construct, issue error
23558
23559 else
23560 Pragma_Misplaced;
23561 end if;
23562 end if;
23563 end Do_SPARK_Mode;
23564
23565 --------------------------------
23566 -- Static_Elaboration_Desired --
23567 --------------------------------
23568
23569 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
23570
23571 when Pragma_Static_Elaboration_Desired =>
23572 GNAT_Pragma;
23573 Check_At_Most_N_Arguments (1);
23574
23575 if Is_Compilation_Unit (Current_Scope)
23576 and then Ekind (Current_Scope) = E_Package
23577 then
23578 Set_Static_Elaboration_Desired (Current_Scope, True);
23579 else
23580 Error_Pragma ("pragma% must apply to a library-level package");
23581 end if;
23582
23583 ------------------
23584 -- Storage_Size --
23585 ------------------
23586
23587 -- pragma Storage_Size (EXPRESSION);
23588
23589 when Pragma_Storage_Size => Storage_Size : declare
23590 P : constant Node_Id := Parent (N);
23591 Arg : Node_Id;
23592
23593 begin
23594 Check_No_Identifiers;
23595 Check_Arg_Count (1);
23596
23597 -- The expression must be analyzed in the special manner described
23598 -- in "Handling of Default Expressions" in sem.ads.
23599
23600 Arg := Get_Pragma_Arg (Arg1);
23601 Preanalyze_Spec_Expression (Arg, Any_Integer);
23602
23603 if not Is_OK_Static_Expression (Arg) then
23604 Check_Restriction (Static_Storage_Size, Arg);
23605 end if;
23606
23607 if Nkind (P) /= N_Task_Definition then
23608 Pragma_Misplaced;
23609 return;
23610
23611 else
23612 if Has_Storage_Size_Pragma (P) then
23613 Error_Pragma ("duplicate pragma% not allowed");
23614 else
23615 Set_Has_Storage_Size_Pragma (P, True);
23616 end if;
23617
23618 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
23619 end if;
23620 end Storage_Size;
23621
23622 ------------------
23623 -- Storage_Unit --
23624 ------------------
23625
23626 -- pragma Storage_Unit (NUMERIC_LITERAL);
23627
23628 -- Only permitted argument is System'Storage_Unit value
23629
23630 when Pragma_Storage_Unit =>
23631 Check_No_Identifiers;
23632 Check_Arg_Count (1);
23633 Check_Arg_Is_Integer_Literal (Arg1);
23634
23635 if Intval (Get_Pragma_Arg (Arg1)) /=
23636 UI_From_Int (Ttypes.System_Storage_Unit)
23637 then
23638 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
23639 Error_Pragma_Arg
23640 ("the only allowed argument for pragma% is ^", Arg1);
23641 end if;
23642
23643 --------------------
23644 -- Stream_Convert --
23645 --------------------
23646
23647 -- pragma Stream_Convert (
23648 -- [Entity =>] type_LOCAL_NAME,
23649 -- [Read =>] function_NAME,
23650 -- [Write =>] function NAME);
23651
23652 when Pragma_Stream_Convert => Stream_Convert : declare
23653 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
23654 -- Check that the given argument is the name of a local function
23655 -- of one argument that is not overloaded earlier in the current
23656 -- local scope. A check is also made that the argument is a
23657 -- function with one parameter.
23658
23659 --------------------------------------
23660 -- Check_OK_Stream_Convert_Function --
23661 --------------------------------------
23662
23663 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
23664 Ent : Entity_Id;
23665
23666 begin
23667 Check_Arg_Is_Local_Name (Arg);
23668 Ent := Entity (Get_Pragma_Arg (Arg));
23669
23670 if Has_Homonym (Ent) then
23671 Error_Pragma_Arg
23672 ("argument for pragma% may not be overloaded", Arg);
23673 end if;
23674
23675 if Ekind (Ent) /= E_Function
23676 or else No (First_Formal (Ent))
23677 or else Present (Next_Formal (First_Formal (Ent)))
23678 then
23679 Error_Pragma_Arg
23680 ("argument for pragma% must be function of one argument",
23681 Arg);
23682 elsif Is_Abstract_Subprogram (Ent) then
23683 Error_Pragma_Arg
23684 ("argument for pragma% cannot be abstract", Arg);
23685 end if;
23686 end Check_OK_Stream_Convert_Function;
23687
23688 -- Start of processing for Stream_Convert
23689
23690 begin
23691 GNAT_Pragma;
23692 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
23693 Check_Arg_Count (3);
23694 Check_Optional_Identifier (Arg1, Name_Entity);
23695 Check_Optional_Identifier (Arg2, Name_Read);
23696 Check_Optional_Identifier (Arg3, Name_Write);
23697 Check_Arg_Is_Local_Name (Arg1);
23698 Check_OK_Stream_Convert_Function (Arg2);
23699 Check_OK_Stream_Convert_Function (Arg3);
23700
23701 declare
23702 Typ : constant Entity_Id :=
23703 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
23704 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
23705 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
23706
23707 begin
23708 Check_First_Subtype (Arg1);
23709
23710 -- Check for too early or too late. Note that we don't enforce
23711 -- the rule about primitive operations in this case, since, as
23712 -- is the case for explicit stream attributes themselves, these
23713 -- restrictions are not appropriate. Note that the chaining of
23714 -- the pragma by Rep_Item_Too_Late is actually the critical
23715 -- processing done for this pragma.
23716
23717 if Rep_Item_Too_Early (Typ, N)
23718 or else
23719 Rep_Item_Too_Late (Typ, N, FOnly => True)
23720 then
23721 return;
23722 end if;
23723
23724 -- Return if previous error
23725
23726 if Etype (Typ) = Any_Type
23727 or else
23728 Etype (Read) = Any_Type
23729 or else
23730 Etype (Write) = Any_Type
23731 then
23732 return;
23733 end if;
23734
23735 -- Error checks
23736
23737 if Underlying_Type (Etype (Read)) /= Typ then
23738 Error_Pragma_Arg
23739 ("incorrect return type for function&", Arg2);
23740 end if;
23741
23742 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
23743 Error_Pragma_Arg
23744 ("incorrect parameter type for function&", Arg3);
23745 end if;
23746
23747 if Underlying_Type (Etype (First_Formal (Read))) /=
23748 Underlying_Type (Etype (Write))
23749 then
23750 Error_Pragma_Arg
23751 ("result type of & does not match Read parameter type",
23752 Arg3);
23753 end if;
23754 end;
23755 end Stream_Convert;
23756
23757 ------------------
23758 -- Style_Checks --
23759 ------------------
23760
23761 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
23762
23763 -- This is processed by the parser since some of the style checks
23764 -- take place during source scanning and parsing. This means that
23765 -- we don't need to issue error messages here.
23766
23767 when Pragma_Style_Checks => Style_Checks : declare
23768 A : constant Node_Id := Get_Pragma_Arg (Arg1);
23769 S : String_Id;
23770 C : Char_Code;
23771
23772 begin
23773 GNAT_Pragma;
23774 Check_No_Identifiers;
23775
23776 -- Two argument form
23777
23778 if Arg_Count = 2 then
23779 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23780
23781 declare
23782 E_Id : Node_Id;
23783 E : Entity_Id;
23784
23785 begin
23786 E_Id := Get_Pragma_Arg (Arg2);
23787 Analyze (E_Id);
23788
23789 if not Is_Entity_Name (E_Id) then
23790 Error_Pragma_Arg
23791 ("second argument of pragma% must be entity name",
23792 Arg2);
23793 end if;
23794
23795 E := Entity (E_Id);
23796
23797 if not Ignore_Style_Checks_Pragmas then
23798 if E = Any_Id then
23799 return;
23800 else
23801 loop
23802 Set_Suppress_Style_Checks
23803 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
23804 exit when No (Homonym (E));
23805 E := Homonym (E);
23806 end loop;
23807 end if;
23808 end if;
23809 end;
23810
23811 -- One argument form
23812
23813 else
23814 Check_Arg_Count (1);
23815
23816 if Nkind (A) = N_String_Literal then
23817 S := Strval (A);
23818
23819 declare
23820 Slen : constant Natural := Natural (String_Length (S));
23821 Options : String (1 .. Slen);
23822 J : Positive;
23823
23824 begin
23825 J := 1;
23826 loop
23827 C := Get_String_Char (S, Pos (J));
23828 exit when not In_Character_Range (C);
23829 Options (J) := Get_Character (C);
23830
23831 -- If at end of string, set options. As per discussion
23832 -- above, no need to check for errors, since we issued
23833 -- them in the parser.
23834
23835 if J = Slen then
23836 if not Ignore_Style_Checks_Pragmas then
23837 Set_Style_Check_Options (Options);
23838 end if;
23839
23840 exit;
23841 end if;
23842
23843 J := J + 1;
23844 end loop;
23845 end;
23846
23847 elsif Nkind (A) = N_Identifier then
23848 if Chars (A) = Name_All_Checks then
23849 if not Ignore_Style_Checks_Pragmas then
23850 if GNAT_Mode then
23851 Set_GNAT_Style_Check_Options;
23852 else
23853 Set_Default_Style_Check_Options;
23854 end if;
23855 end if;
23856
23857 elsif Chars (A) = Name_On then
23858 if not Ignore_Style_Checks_Pragmas then
23859 Style_Check := True;
23860 end if;
23861
23862 elsif Chars (A) = Name_Off then
23863 if not Ignore_Style_Checks_Pragmas then
23864 Style_Check := False;
23865 end if;
23866 end if;
23867 end if;
23868 end if;
23869 end Style_Checks;
23870
23871 ------------------------
23872 -- Subprogram_Variant --
23873 ------------------------
23874
23875 -- pragma Subprogram_Variant ( SUBPROGRAM_VARIANT_ITEM
23876 -- {, SUBPROGRAM_VARIANT_ITEM } );
23877
23878 -- SUBPROGRAM_VARIANT_ITEM ::=
23879 -- CHANGE_DIRECTION => discrete_EXPRESSION
23880
23881 -- CHANGE_DIRECTION ::= Increases | Decreases
23882
23883 -- Characteristics:
23884
23885 -- * Analysis - The annotation undergoes initial checks to verify
23886 -- the legal placement and context. Secondary checks preanalyze the
23887 -- expressions in:
23888
23889 -- Analyze_Subprogram_Variant_In_Decl_Part
23890
23891 -- * Expansion - The annotation is expanded during the expansion of
23892 -- the related subprogram [body] contract as performed in:
23893
23894 -- Expand_Subprogram_Contract
23895
23896 -- * Template - The annotation utilizes the generic template of the
23897 -- related subprogram [body] when it is:
23898
23899 -- aspect on subprogram declaration
23900 -- aspect on stand-alone subprogram body
23901 -- pragma on stand-alone subprogram body
23902
23903 -- The annotation must prepare its own template when it is:
23904
23905 -- pragma on subprogram declaration
23906
23907 -- * Globals - Capture of global references must occur after full
23908 -- analysis.
23909
23910 -- * Instance - The annotation is instantiated automatically when
23911 -- the related generic subprogram [body] is instantiated except for
23912 -- the "pragma on subprogram declaration" case. In that scenario
23913 -- the annotation must instantiate itself.
23914
23915 when Pragma_Subprogram_Variant => Subprogram_Variant : declare
23916 Spec_Id : Entity_Id;
23917 Subp_Decl : Node_Id;
23918 Subp_Spec : Node_Id;
23919
23920 begin
23921 GNAT_Pragma;
23922 Check_No_Identifiers;
23923 Check_Arg_Count (1);
23924
23925 -- Ensure the proper placement of the pragma. Subprogram_Variant
23926 -- must be associated with a subprogram declaration or a body that
23927 -- acts as a spec.
23928
23929 Subp_Decl :=
23930 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
23931
23932 -- Generic subprogram
23933
23934 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
23935 null;
23936
23937 -- Body acts as spec
23938
23939 elsif Nkind (Subp_Decl) = N_Subprogram_Body
23940 and then No (Corresponding_Spec (Subp_Decl))
23941 then
23942 null;
23943
23944 -- Body stub acts as spec
23945
23946 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
23947 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
23948 then
23949 null;
23950
23951 -- Subprogram
23952
23953 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
23954 Subp_Spec := Specification (Subp_Decl);
23955
23956 -- Pragma Subprogram_Variant is forbidden on null procedures,
23957 -- as this may lead to potential ambiguities in behavior when
23958 -- interface null procedures are involved. Also, it just
23959 -- wouldn't make sense, because null procedure is not
23960 -- recursive.
23961
23962 if Nkind (Subp_Spec) = N_Procedure_Specification
23963 and then Null_Present (Subp_Spec)
23964 then
23965 Error_Msg_N (Fix_Error
23966 ("pragma % cannot apply to null procedure"), N);
23967 return;
23968 end if;
23969
23970 else
23971 Pragma_Misplaced;
23972 return;
23973 end if;
23974
23975 Spec_Id := Unique_Defining_Entity (Subp_Decl);
23976
23977 -- A pragma that applies to a Ghost entity becomes Ghost for the
23978 -- purposes of legality checks and removal of ignored Ghost code.
23979
23980 Mark_Ghost_Pragma (N, Spec_Id);
23981 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
23982
23983 -- Chain the pragma on the contract for further processing by
23984 -- Analyze_Subprogram_Variant_In_Decl_Part.
23985
23986 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
23987
23988 -- Fully analyze the pragma when it appears inside a subprogram
23989 -- body because it cannot benefit from forward references.
23990
23991 if Nkind (Subp_Decl) in N_Subprogram_Body
23992 | N_Subprogram_Body_Stub
23993 then
23994 -- The legality checks of pragma Subprogram_Variant are
23995 -- affected by the SPARK mode in effect and the volatility
23996 -- of the context. Analyze all pragmas in a specific order.
23997
23998 Analyze_If_Present (Pragma_SPARK_Mode);
23999 Analyze_If_Present (Pragma_Volatile_Function);
24000 Analyze_Subprogram_Variant_In_Decl_Part (N);
24001 end if;
24002 end Subprogram_Variant;
24003
24004 --------------
24005 -- Subtitle --
24006 --------------
24007
24008 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
24009
24010 when Pragma_Subtitle =>
24011 GNAT_Pragma;
24012 Check_Arg_Count (1);
24013 Check_Optional_Identifier (Arg1, Name_Subtitle);
24014 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
24015 Store_Note (N);
24016
24017 --------------
24018 -- Suppress --
24019 --------------
24020
24021 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
24022
24023 when Pragma_Suppress =>
24024 Process_Suppress_Unsuppress (Suppress_Case => True);
24025
24026 ------------------
24027 -- Suppress_All --
24028 ------------------
24029
24030 -- pragma Suppress_All;
24031
24032 -- The only check made here is that the pragma has no arguments.
24033 -- There are no placement rules, and the processing required (setting
24034 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
24035 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
24036 -- then creates and inserts a pragma Suppress (All_Checks).
24037
24038 when Pragma_Suppress_All =>
24039 GNAT_Pragma;
24040 Check_Arg_Count (0);
24041
24042 -------------------------
24043 -- Suppress_Debug_Info --
24044 -------------------------
24045
24046 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
24047
24048 when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare
24049 Nam_Id : Entity_Id;
24050
24051 begin
24052 GNAT_Pragma;
24053 Check_Arg_Count (1);
24054 Check_Optional_Identifier (Arg1, Name_Entity);
24055 Check_Arg_Is_Local_Name (Arg1);
24056
24057 Nam_Id := Entity (Get_Pragma_Arg (Arg1));
24058
24059 -- A pragma that applies to a Ghost entity becomes Ghost for the
24060 -- purposes of legality checks and removal of ignored Ghost code.
24061
24062 Mark_Ghost_Pragma (N, Nam_Id);
24063 Set_Debug_Info_Off (Nam_Id);
24064 end Suppress_Debug_Info;
24065
24066 ----------------------------------
24067 -- Suppress_Exception_Locations --
24068 ----------------------------------
24069
24070 -- pragma Suppress_Exception_Locations;
24071
24072 when Pragma_Suppress_Exception_Locations =>
24073 GNAT_Pragma;
24074 Check_Arg_Count (0);
24075 Check_Valid_Configuration_Pragma;
24076 Exception_Locations_Suppressed := True;
24077
24078 -----------------------------
24079 -- Suppress_Initialization --
24080 -----------------------------
24081
24082 -- pragma Suppress_Initialization ([Entity =>] type_Name);
24083
24084 when Pragma_Suppress_Initialization => Suppress_Init : declare
24085 E : Entity_Id;
24086 E_Id : Node_Id;
24087
24088 begin
24089 GNAT_Pragma;
24090 Check_Arg_Count (1);
24091 Check_Optional_Identifier (Arg1, Name_Entity);
24092 Check_Arg_Is_Local_Name (Arg1);
24093
24094 E_Id := Get_Pragma_Arg (Arg1);
24095
24096 if Etype (E_Id) = Any_Type then
24097 return;
24098 end if;
24099
24100 E := Entity (E_Id);
24101
24102 -- A pragma that applies to a Ghost entity becomes Ghost for the
24103 -- purposes of legality checks and removal of ignored Ghost code.
24104
24105 Mark_Ghost_Pragma (N, E);
24106
24107 if not Is_Type (E) and then Ekind (E) /= E_Variable then
24108 Error_Pragma_Arg
24109 ("pragma% requires variable, type or subtype", Arg1);
24110 end if;
24111
24112 if Rep_Item_Too_Early (E, N)
24113 or else
24114 Rep_Item_Too_Late (E, N, FOnly => True)
24115 then
24116 return;
24117 end if;
24118
24119 -- For incomplete/private type, set flag on full view
24120
24121 if Is_Incomplete_Or_Private_Type (E) then
24122 if No (Full_View (Base_Type (E))) then
24123 Error_Pragma_Arg
24124 ("argument of pragma% cannot be an incomplete type", Arg1);
24125 else
24126 Set_Suppress_Initialization (Full_View (E));
24127 end if;
24128
24129 -- For first subtype, set flag on base type
24130
24131 elsif Is_First_Subtype (E) then
24132 Set_Suppress_Initialization (Base_Type (E));
24133
24134 -- For other than first subtype, set flag on subtype or variable
24135
24136 else
24137 Set_Suppress_Initialization (E);
24138 end if;
24139 end Suppress_Init;
24140
24141 -----------------
24142 -- System_Name --
24143 -----------------
24144
24145 -- pragma System_Name (DIRECT_NAME);
24146
24147 -- Syntax check: one argument, which must be the identifier GNAT or
24148 -- the identifier GCC, no other identifiers are acceptable.
24149
24150 when Pragma_System_Name =>
24151 GNAT_Pragma;
24152 Check_No_Identifiers;
24153 Check_Arg_Count (1);
24154 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
24155
24156 -----------------------------
24157 -- Task_Dispatching_Policy --
24158 -----------------------------
24159
24160 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
24161
24162 when Pragma_Task_Dispatching_Policy => declare
24163 DP : Character;
24164
24165 begin
24166 Check_Ada_83_Warning;
24167 Check_Arg_Count (1);
24168 Check_No_Identifiers;
24169 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
24170 Check_Valid_Configuration_Pragma;
24171 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
24172 DP := Fold_Upper (Name_Buffer (1));
24173
24174 if Task_Dispatching_Policy /= ' '
24175 and then Task_Dispatching_Policy /= DP
24176 then
24177 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
24178 Error_Pragma
24179 ("task dispatching policy incompatible with policy#");
24180
24181 -- Set new policy, but always preserve System_Location since we
24182 -- like the error message with the run time name.
24183
24184 else
24185 Task_Dispatching_Policy := DP;
24186
24187 if Task_Dispatching_Policy_Sloc /= System_Location then
24188 Task_Dispatching_Policy_Sloc := Loc;
24189 end if;
24190 end if;
24191 end;
24192
24193 ---------------
24194 -- Task_Info --
24195 ---------------
24196
24197 -- pragma Task_Info (EXPRESSION);
24198
24199 when Pragma_Task_Info => Task_Info : declare
24200 P : constant Node_Id := Parent (N);
24201 Ent : Entity_Id;
24202
24203 begin
24204 GNAT_Pragma;
24205
24206 if Warn_On_Obsolescent_Feature then
24207 Error_Msg_N
24208 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
24209 & "instead?j?", N);
24210 end if;
24211
24212 if Nkind (P) /= N_Task_Definition then
24213 Error_Pragma ("pragma% must appear in task definition");
24214 end if;
24215
24216 Check_No_Identifiers;
24217 Check_Arg_Count (1);
24218
24219 Analyze_And_Resolve
24220 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
24221
24222 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
24223 return;
24224 end if;
24225
24226 Ent := Defining_Identifier (Parent (P));
24227
24228 -- Check duplicate pragma before we chain the pragma in the Rep
24229 -- Item chain of Ent.
24230
24231 if Has_Rep_Pragma
24232 (Ent, Name_Task_Info, Check_Parents => False)
24233 then
24234 Error_Pragma ("duplicate pragma% not allowed");
24235 end if;
24236
24237 Record_Rep_Item (Ent, N);
24238 end Task_Info;
24239
24240 ---------------
24241 -- Task_Name --
24242 ---------------
24243
24244 -- pragma Task_Name (string_EXPRESSION);
24245
24246 when Pragma_Task_Name => Task_Name : declare
24247 P : constant Node_Id := Parent (N);
24248 Arg : Node_Id;
24249 Ent : Entity_Id;
24250
24251 begin
24252 Check_No_Identifiers;
24253 Check_Arg_Count (1);
24254
24255 Arg := Get_Pragma_Arg (Arg1);
24256
24257 -- The expression is used in the call to Create_Task, and must be
24258 -- expanded there, not in the context of the current spec. It must
24259 -- however be analyzed to capture global references, in case it
24260 -- appears in a generic context.
24261
24262 Preanalyze_And_Resolve (Arg, Standard_String);
24263
24264 if Nkind (P) /= N_Task_Definition then
24265 Pragma_Misplaced;
24266 end if;
24267
24268 Ent := Defining_Identifier (Parent (P));
24269
24270 -- Check duplicate pragma before we chain the pragma in the Rep
24271 -- Item chain of Ent.
24272
24273 if Has_Rep_Pragma
24274 (Ent, Name_Task_Name, Check_Parents => False)
24275 then
24276 Error_Pragma ("duplicate pragma% not allowed");
24277 end if;
24278
24279 Record_Rep_Item (Ent, N);
24280 end Task_Name;
24281
24282 ------------------
24283 -- Task_Storage --
24284 ------------------
24285
24286 -- pragma Task_Storage (
24287 -- [Task_Type =>] LOCAL_NAME,
24288 -- [Top_Guard =>] static_integer_EXPRESSION);
24289
24290 when Pragma_Task_Storage => Task_Storage : declare
24291 Args : Args_List (1 .. 2);
24292 Names : constant Name_List (1 .. 2) := (
24293 Name_Task_Type,
24294 Name_Top_Guard);
24295
24296 Task_Type : Node_Id renames Args (1);
24297 Top_Guard : Node_Id renames Args (2);
24298
24299 Ent : Entity_Id;
24300
24301 begin
24302 GNAT_Pragma;
24303 Gather_Associations (Names, Args);
24304
24305 if No (Task_Type) then
24306 Error_Pragma
24307 ("missing task_type argument for pragma%");
24308 end if;
24309
24310 Check_Arg_Is_Local_Name (Task_Type);
24311
24312 Ent := Entity (Task_Type);
24313
24314 if not Is_Task_Type (Ent) then
24315 Error_Pragma_Arg
24316 ("argument for pragma% must be task type", Task_Type);
24317 end if;
24318
24319 if No (Top_Guard) then
24320 Error_Pragma_Arg
24321 ("pragma% takes two arguments", Task_Type);
24322 else
24323 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
24324 end if;
24325
24326 Check_First_Subtype (Task_Type);
24327
24328 if Rep_Item_Too_Late (Ent, N) then
24329 raise Pragma_Exit;
24330 end if;
24331 end Task_Storage;
24332
24333 ---------------
24334 -- Test_Case --
24335 ---------------
24336
24337 -- pragma Test_Case
24338 -- ([Name =>] Static_String_EXPRESSION
24339 -- ,[Mode =>] MODE_TYPE
24340 -- [, Requires => Boolean_EXPRESSION]
24341 -- [, Ensures => Boolean_EXPRESSION]);
24342
24343 -- MODE_TYPE ::= Nominal | Robustness
24344
24345 -- Characteristics:
24346
24347 -- * Analysis - The annotation undergoes initial checks to verify
24348 -- the legal placement and context. Secondary checks preanalyze the
24349 -- expressions in:
24350
24351 -- Analyze_Test_Case_In_Decl_Part
24352
24353 -- * Expansion - None.
24354
24355 -- * Template - The annotation utilizes the generic template of the
24356 -- related subprogram when it is:
24357
24358 -- aspect on subprogram declaration
24359
24360 -- The annotation must prepare its own template when it is:
24361
24362 -- pragma on subprogram declaration
24363
24364 -- * Globals - Capture of global references must occur after full
24365 -- analysis.
24366
24367 -- * Instance - The annotation is instantiated automatically when
24368 -- the related generic subprogram is instantiated except for the
24369 -- "pragma on subprogram declaration" case. In that scenario the
24370 -- annotation must instantiate itself.
24371
24372 when Pragma_Test_Case => Test_Case : declare
24373 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
24374 -- Ensure that the contract of subprogram Subp_Id does not contain
24375 -- another Test_Case pragma with the same Name as the current one.
24376
24377 -------------------------
24378 -- Check_Distinct_Name --
24379 -------------------------
24380
24381 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
24382 Items : constant Node_Id := Contract (Subp_Id);
24383 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
24384 Prag : Node_Id;
24385
24386 begin
24387 -- Inspect all Test_Case pragma of the related subprogram
24388 -- looking for one with a duplicate "Name" argument.
24389
24390 if Present (Items) then
24391 Prag := Contract_Test_Cases (Items);
24392 while Present (Prag) loop
24393 if Pragma_Name (Prag) = Name_Test_Case
24394 and then Prag /= N
24395 and then String_Equal
24396 (Name, Get_Name_From_CTC_Pragma (Prag))
24397 then
24398 Error_Msg_Sloc := Sloc (Prag);
24399 Error_Pragma ("name for pragma % is already used #");
24400 end if;
24401
24402 Prag := Next_Pragma (Prag);
24403 end loop;
24404 end if;
24405 end Check_Distinct_Name;
24406
24407 -- Local variables
24408
24409 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
24410 Asp_Arg : Node_Id;
24411 Context : Node_Id;
24412 Subp_Decl : Node_Id;
24413 Subp_Id : Entity_Id;
24414
24415 -- Start of processing for Test_Case
24416
24417 begin
24418 GNAT_Pragma;
24419 Check_At_Least_N_Arguments (2);
24420 Check_At_Most_N_Arguments (4);
24421 Check_Arg_Order
24422 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
24423
24424 -- Argument "Name"
24425
24426 Check_Optional_Identifier (Arg1, Name_Name);
24427 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
24428
24429 -- Argument "Mode"
24430
24431 Check_Optional_Identifier (Arg2, Name_Mode);
24432 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
24433
24434 -- Arguments "Requires" and "Ensures"
24435
24436 if Present (Arg3) then
24437 if Present (Arg4) then
24438 Check_Identifier (Arg3, Name_Requires);
24439 Check_Identifier (Arg4, Name_Ensures);
24440 else
24441 Check_Identifier_Is_One_Of
24442 (Arg3, Name_Requires, Name_Ensures);
24443 end if;
24444 end if;
24445
24446 -- Pragma Test_Case must be associated with a subprogram declared
24447 -- in a library-level package. First determine whether the current
24448 -- compilation unit is a legal context.
24449
24450 if Nkind (Pack_Decl) in N_Package_Declaration
24451 | N_Generic_Package_Declaration
24452 then
24453 null;
24454
24455 -- Otherwise the placement is illegal
24456
24457 else
24458 Error_Pragma
24459 ("pragma % must be specified within a package declaration");
24460 return;
24461 end if;
24462
24463 Subp_Decl := Find_Related_Declaration_Or_Body (N);
24464
24465 -- Find the enclosing context
24466
24467 Context := Parent (Subp_Decl);
24468
24469 if Present (Context) then
24470 Context := Parent (Context);
24471 end if;
24472
24473 -- Verify the placement of the pragma
24474
24475 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
24476 Error_Pragma
24477 ("pragma % cannot be applied to abstract subprogram");
24478 return;
24479
24480 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
24481 Error_Pragma ("pragma % cannot be applied to entry");
24482 return;
24483
24484 -- The context is a [generic] subprogram declared at the top level
24485 -- of the [generic] package unit.
24486
24487 elsif Nkind (Subp_Decl) in N_Generic_Subprogram_Declaration
24488 | N_Subprogram_Declaration
24489 and then Present (Context)
24490 and then Nkind (Context) in N_Generic_Package_Declaration
24491 | N_Package_Declaration
24492 then
24493 null;
24494
24495 -- Otherwise the placement is illegal
24496
24497 else
24498 Error_Pragma
24499 ("pragma % must be applied to a library-level subprogram "
24500 & "declaration");
24501 return;
24502 end if;
24503
24504 Subp_Id := Defining_Entity (Subp_Decl);
24505
24506 -- A pragma that applies to a Ghost entity becomes Ghost for the
24507 -- purposes of legality checks and removal of ignored Ghost code.
24508
24509 Mark_Ghost_Pragma (N, Subp_Id);
24510
24511 -- Chain the pragma on the contract for further processing by
24512 -- Analyze_Test_Case_In_Decl_Part.
24513
24514 Add_Contract_Item (N, Subp_Id);
24515
24516 -- Preanalyze the original aspect argument "Name" for a generic
24517 -- subprogram to properly capture global references.
24518
24519 if Is_Generic_Subprogram (Subp_Id) then
24520 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
24521
24522 if Present (Asp_Arg) then
24523
24524 -- The argument appears with an identifier in association
24525 -- form.
24526
24527 if Nkind (Asp_Arg) = N_Component_Association then
24528 Asp_Arg := Expression (Asp_Arg);
24529 end if;
24530
24531 Check_Expr_Is_OK_Static_Expression
24532 (Asp_Arg, Standard_String);
24533 end if;
24534 end if;
24535
24536 -- Ensure that the all Test_Case pragmas of the related subprogram
24537 -- have distinct names.
24538
24539 Check_Distinct_Name (Subp_Id);
24540
24541 -- Fully analyze the pragma when it appears inside an entry
24542 -- or subprogram body because it cannot benefit from forward
24543 -- references.
24544
24545 if Nkind (Subp_Decl) in N_Entry_Body
24546 | N_Subprogram_Body
24547 | N_Subprogram_Body_Stub
24548 then
24549 -- The legality checks of pragma Test_Case are affected by the
24550 -- SPARK mode in effect and the volatility of the context.
24551 -- Analyze all pragmas in a specific order.
24552
24553 Analyze_If_Present (Pragma_SPARK_Mode);
24554 Analyze_If_Present (Pragma_Volatile_Function);
24555 Analyze_Test_Case_In_Decl_Part (N);
24556 end if;
24557 end Test_Case;
24558
24559 --------------------------
24560 -- Thread_Local_Storage --
24561 --------------------------
24562
24563 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
24564
24565 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
24566 E : Entity_Id;
24567 Id : Node_Id;
24568
24569 begin
24570 GNAT_Pragma;
24571 Check_Arg_Count (1);
24572 Check_Optional_Identifier (Arg1, Name_Entity);
24573 Check_Arg_Is_Library_Level_Local_Name (Arg1);
24574
24575 Id := Get_Pragma_Arg (Arg1);
24576 Analyze (Id);
24577
24578 if not Is_Entity_Name (Id)
24579 or else Ekind (Entity (Id)) /= E_Variable
24580 then
24581 Error_Pragma_Arg ("local variable name required", Arg1);
24582 end if;
24583
24584 E := Entity (Id);
24585
24586 -- A pragma that applies to a Ghost entity becomes Ghost for the
24587 -- purposes of legality checks and removal of ignored Ghost code.
24588
24589 Mark_Ghost_Pragma (N, E);
24590
24591 if Rep_Item_Too_Early (E, N)
24592 or else
24593 Rep_Item_Too_Late (E, N)
24594 then
24595 raise Pragma_Exit;
24596 end if;
24597
24598 Set_Has_Pragma_Thread_Local_Storage (E);
24599 Set_Has_Gigi_Rep_Item (E);
24600 end Thread_Local_Storage;
24601
24602 ----------------
24603 -- Time_Slice --
24604 ----------------
24605
24606 -- pragma Time_Slice (static_duration_EXPRESSION);
24607
24608 when Pragma_Time_Slice => Time_Slice : declare
24609 Val : Ureal;
24610 Nod : Node_Id;
24611
24612 begin
24613 GNAT_Pragma;
24614 Check_Arg_Count (1);
24615 Check_No_Identifiers;
24616 Check_In_Main_Program;
24617 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
24618
24619 if not Error_Posted (Arg1) then
24620 Nod := Next (N);
24621 while Present (Nod) loop
24622 if Nkind (Nod) = N_Pragma
24623 and then Pragma_Name (Nod) = Name_Time_Slice
24624 then
24625 Error_Msg_Name_1 := Pname;
24626 Error_Msg_N ("duplicate pragma% not permitted", Nod);
24627 end if;
24628
24629 Next (Nod);
24630 end loop;
24631 end if;
24632
24633 -- Process only if in main unit
24634
24635 if Get_Source_Unit (Loc) = Main_Unit then
24636 Opt.Time_Slice_Set := True;
24637 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
24638
24639 if Val <= Ureal_0 then
24640 Opt.Time_Slice_Value := 0;
24641
24642 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
24643 Opt.Time_Slice_Value := 1_000_000_000;
24644
24645 else
24646 Opt.Time_Slice_Value :=
24647 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
24648 end if;
24649 end if;
24650 end Time_Slice;
24651
24652 -----------
24653 -- Title --
24654 -----------
24655
24656 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
24657
24658 -- TITLING_OPTION ::=
24659 -- [Title =>] STRING_LITERAL
24660 -- | [Subtitle =>] STRING_LITERAL
24661
24662 when Pragma_Title => Title : declare
24663 Args : Args_List (1 .. 2);
24664 Names : constant Name_List (1 .. 2) := (
24665 Name_Title,
24666 Name_Subtitle);
24667
24668 begin
24669 GNAT_Pragma;
24670 Gather_Associations (Names, Args);
24671 Store_Note (N);
24672
24673 for J in 1 .. 2 loop
24674 if Present (Args (J)) then
24675 Check_Arg_Is_OK_Static_Expression
24676 (Args (J), Standard_String);
24677 end if;
24678 end loop;
24679 end Title;
24680
24681 ----------------------------
24682 -- Type_Invariant[_Class] --
24683 ----------------------------
24684
24685 -- pragma Type_Invariant[_Class]
24686 -- ([Entity =>] type_LOCAL_NAME,
24687 -- [Check =>] EXPRESSION);
24688
24689 when Pragma_Type_Invariant
24690 | Pragma_Type_Invariant_Class
24691 =>
24692 Type_Invariant : declare
24693 I_Pragma : Node_Id;
24694
24695 begin
24696 Check_Arg_Count (2);
24697
24698 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
24699 -- setting Class_Present for the Type_Invariant_Class case.
24700
24701 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
24702 I_Pragma := New_Copy (N);
24703 Set_Pragma_Identifier
24704 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
24705 Rewrite (N, I_Pragma);
24706 Set_Analyzed (N, False);
24707 Analyze (N);
24708 end Type_Invariant;
24709
24710 ---------------------
24711 -- Unchecked_Union --
24712 ---------------------
24713
24714 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
24715
24716 when Pragma_Unchecked_Union => Unchecked_Union : declare
24717 Assoc : constant Node_Id := Arg1;
24718 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
24719 Clist : Node_Id;
24720 Comp : Node_Id;
24721 Tdef : Node_Id;
24722 Typ : Entity_Id;
24723 Variant : Node_Id;
24724 Vpart : Node_Id;
24725
24726 begin
24727 Ada_2005_Pragma;
24728 Check_No_Identifiers;
24729 Check_Arg_Count (1);
24730 Check_Arg_Is_Local_Name (Arg1);
24731
24732 Find_Type (Type_Id);
24733
24734 Typ := Entity (Type_Id);
24735
24736 -- A pragma that applies to a Ghost entity becomes Ghost for the
24737 -- purposes of legality checks and removal of ignored Ghost code.
24738
24739 Mark_Ghost_Pragma (N, Typ);
24740
24741 if Typ = Any_Type
24742 or else Rep_Item_Too_Early (Typ, N)
24743 then
24744 return;
24745 else
24746 Typ := Underlying_Type (Typ);
24747 end if;
24748
24749 if Rep_Item_Too_Late (Typ, N) then
24750 return;
24751 end if;
24752
24753 Check_First_Subtype (Arg1);
24754
24755 -- Note remaining cases are references to a type in the current
24756 -- declarative part. If we find an error, we post the error on
24757 -- the relevant type declaration at an appropriate point.
24758
24759 if not Is_Record_Type (Typ) then
24760 Error_Msg_N ("unchecked union must be record type", Typ);
24761 return;
24762
24763 elsif Is_Tagged_Type (Typ) then
24764 Error_Msg_N ("unchecked union must not be tagged", Typ);
24765 return;
24766
24767 elsif not Has_Discriminants (Typ) then
24768 Error_Msg_N
24769 ("unchecked union must have one discriminant", Typ);
24770 return;
24771
24772 -- Note: in previous versions of GNAT we used to check for limited
24773 -- types and give an error, but in fact the standard does allow
24774 -- Unchecked_Union on limited types, so this check was removed.
24775
24776 -- Similarly, GNAT used to require that all discriminants have
24777 -- default values, but this is not mandated by the RM.
24778
24779 -- Proceed with basic error checks completed
24780
24781 else
24782 Tdef := Type_Definition (Declaration_Node (Typ));
24783 Clist := Component_List (Tdef);
24784
24785 -- Check presence of component list and variant part
24786
24787 if No (Clist) or else No (Variant_Part (Clist)) then
24788 Error_Msg_N
24789 ("unchecked union must have variant part", Tdef);
24790 return;
24791 end if;
24792
24793 -- Check components
24794
24795 Comp := First_Non_Pragma (Component_Items (Clist));
24796 while Present (Comp) loop
24797 Check_Component (Comp, Typ);
24798 Next_Non_Pragma (Comp);
24799 end loop;
24800
24801 -- Check variant part
24802
24803 Vpart := Variant_Part (Clist);
24804
24805 Variant := First_Non_Pragma (Variants (Vpart));
24806 while Present (Variant) loop
24807 Check_Variant (Variant, Typ);
24808 Next_Non_Pragma (Variant);
24809 end loop;
24810 end if;
24811
24812 Set_Is_Unchecked_Union (Typ);
24813 Set_Convention (Typ, Convention_C);
24814 Set_Has_Unchecked_Union (Base_Type (Typ));
24815 Set_Is_Unchecked_Union (Base_Type (Typ));
24816 end Unchecked_Union;
24817
24818 ----------------------------
24819 -- Unevaluated_Use_Of_Old --
24820 ----------------------------
24821
24822 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
24823
24824 when Pragma_Unevaluated_Use_Of_Old =>
24825 GNAT_Pragma;
24826 Check_Arg_Count (1);
24827 Check_No_Identifiers;
24828 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
24829
24830 -- Suppress/Unsuppress can appear as a configuration pragma, or in
24831 -- a declarative part or a package spec.
24832
24833 if not Is_Configuration_Pragma then
24834 Check_Is_In_Decl_Part_Or_Package_Spec;
24835 end if;
24836
24837 -- Store proper setting of Uneval_Old
24838
24839 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
24840 Uneval_Old := Fold_Upper (Name_Buffer (1));
24841
24842 ------------------------
24843 -- Unimplemented_Unit --
24844 ------------------------
24845
24846 -- pragma Unimplemented_Unit;
24847
24848 -- Note: this only gives an error if we are generating code, or if
24849 -- we are in a generic library unit (where the pragma appears in the
24850 -- body, not in the spec).
24851
24852 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
24853 Cunitent : constant Entity_Id :=
24854 Cunit_Entity (Get_Source_Unit (Loc));
24855
24856 begin
24857 GNAT_Pragma;
24858 Check_Arg_Count (0);
24859
24860 if Operating_Mode = Generate_Code
24861 or else Is_Generic_Unit (Cunitent)
24862 then
24863 Get_Name_String (Chars (Cunitent));
24864 Set_Casing (Mixed_Case);
24865 Write_Str (Name_Buffer (1 .. Name_Len));
24866 Write_Str (" is not supported in this configuration");
24867 Write_Eol;
24868 raise Unrecoverable_Error;
24869 end if;
24870 end Unimplemented_Unit;
24871
24872 ------------------------
24873 -- Universal_Aliasing --
24874 ------------------------
24875
24876 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
24877
24878 when Pragma_Universal_Aliasing => Universal_Alias : declare
24879 E : Entity_Id;
24880 E_Id : Node_Id;
24881
24882 begin
24883 GNAT_Pragma;
24884 Check_Arg_Count (1);
24885 Check_Optional_Identifier (Arg2, Name_Entity);
24886 Check_Arg_Is_Local_Name (Arg1);
24887 E_Id := Get_Pragma_Arg (Arg1);
24888
24889 if Etype (E_Id) = Any_Type then
24890 return;
24891 end if;
24892
24893 E := Entity (E_Id);
24894
24895 if not Is_Type (E) then
24896 Error_Pragma_Arg ("pragma% requires type", Arg1);
24897 end if;
24898
24899 -- A pragma that applies to a Ghost entity becomes Ghost for the
24900 -- purposes of legality checks and removal of ignored Ghost code.
24901
24902 Mark_Ghost_Pragma (N, E);
24903 Set_Universal_Aliasing (Base_Type (E));
24904 Record_Rep_Item (E, N);
24905 end Universal_Alias;
24906
24907 --------------------
24908 -- Universal_Data --
24909 --------------------
24910
24911 -- pragma Universal_Data [(library_unit_NAME)];
24912
24913 when Pragma_Universal_Data =>
24914 GNAT_Pragma;
24915 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
24916
24917 ----------------
24918 -- Unmodified --
24919 ----------------
24920
24921 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
24922
24923 when Pragma_Unmodified =>
24924 Analyze_Unmodified_Or_Unused;
24925
24926 ------------------
24927 -- Unreferenced --
24928 ------------------
24929
24930 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
24931
24932 -- or when used in a context clause:
24933
24934 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
24935
24936 when Pragma_Unreferenced =>
24937 Analyze_Unreferenced_Or_Unused;
24938
24939 --------------------------
24940 -- Unreferenced_Objects --
24941 --------------------------
24942
24943 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
24944
24945 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
24946 Arg : Node_Id;
24947 Arg_Expr : Node_Id;
24948 Arg_Id : Entity_Id;
24949
24950 Ghost_Error_Posted : Boolean := False;
24951 -- Flag set when an error concerning the illegal mix of Ghost and
24952 -- non-Ghost types is emitted.
24953
24954 Ghost_Id : Entity_Id := Empty;
24955 -- The entity of the first Ghost type encountered while processing
24956 -- the arguments of the pragma.
24957
24958 begin
24959 GNAT_Pragma;
24960 Check_At_Least_N_Arguments (1);
24961
24962 Arg := Arg1;
24963 while Present (Arg) loop
24964 Check_No_Identifier (Arg);
24965 Check_Arg_Is_Local_Name (Arg);
24966 Arg_Expr := Get_Pragma_Arg (Arg);
24967
24968 if Is_Entity_Name (Arg_Expr) then
24969 Arg_Id := Entity (Arg_Expr);
24970
24971 if Is_Type (Arg_Id) then
24972 Set_Has_Pragma_Unreferenced_Objects (Arg_Id);
24973
24974 -- A pragma that applies to a Ghost entity becomes Ghost
24975 -- for the purposes of legality checks and removal of
24976 -- ignored Ghost code.
24977
24978 Mark_Ghost_Pragma (N, Arg_Id);
24979
24980 -- Capture the entity of the first Ghost type being
24981 -- processed for error detection purposes.
24982
24983 if Is_Ghost_Entity (Arg_Id) then
24984 if No (Ghost_Id) then
24985 Ghost_Id := Arg_Id;
24986 end if;
24987
24988 -- Otherwise the type is non-Ghost. It is illegal to mix
24989 -- references to Ghost and non-Ghost entities
24990 -- (SPARK RM 6.9).
24991
24992 elsif Present (Ghost_Id)
24993 and then not Ghost_Error_Posted
24994 then
24995 Ghost_Error_Posted := True;
24996
24997 Error_Msg_Name_1 := Pname;
24998 Error_Msg_N
24999 ("pragma % cannot mention ghost and non-ghost types",
25000 N);
25001
25002 Error_Msg_Sloc := Sloc (Ghost_Id);
25003 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
25004
25005 Error_Msg_Sloc := Sloc (Arg_Id);
25006 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
25007 end if;
25008 else
25009 Error_Pragma_Arg
25010 ("argument for pragma% must be type or subtype", Arg);
25011 end if;
25012 else
25013 Error_Pragma_Arg
25014 ("argument for pragma% must be type or subtype", Arg);
25015 end if;
25016
25017 Next (Arg);
25018 end loop;
25019 end Unreferenced_Objects;
25020
25021 ------------------------------
25022 -- Unreserve_All_Interrupts --
25023 ------------------------------
25024
25025 -- pragma Unreserve_All_Interrupts;
25026
25027 when Pragma_Unreserve_All_Interrupts =>
25028 GNAT_Pragma;
25029 Check_Arg_Count (0);
25030
25031 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
25032 Unreserve_All_Interrupts := True;
25033 end if;
25034
25035 ----------------
25036 -- Unsuppress --
25037 ----------------
25038
25039 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
25040
25041 when Pragma_Unsuppress =>
25042 Ada_2005_Pragma;
25043 Process_Suppress_Unsuppress (Suppress_Case => False);
25044
25045 ------------
25046 -- Unused --
25047 ------------
25048
25049 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
25050
25051 when Pragma_Unused =>
25052 Analyze_Unmodified_Or_Unused (Is_Unused => True);
25053 Analyze_Unreferenced_Or_Unused (Is_Unused => True);
25054
25055 -------------------
25056 -- Use_VADS_Size --
25057 -------------------
25058
25059 -- pragma Use_VADS_Size;
25060
25061 when Pragma_Use_VADS_Size =>
25062 GNAT_Pragma;
25063 Check_Arg_Count (0);
25064 Check_Valid_Configuration_Pragma;
25065 Use_VADS_Size := True;
25066
25067 ---------------------
25068 -- Validity_Checks --
25069 ---------------------
25070
25071 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
25072
25073 when Pragma_Validity_Checks => Validity_Checks : declare
25074 A : constant Node_Id := Get_Pragma_Arg (Arg1);
25075 S : String_Id;
25076 C : Char_Code;
25077
25078 begin
25079 GNAT_Pragma;
25080 Check_Arg_Count (1);
25081 Check_No_Identifiers;
25082
25083 -- Pragma always active unless in CodePeer or GNATprove modes,
25084 -- which use a fixed configuration of validity checks.
25085
25086 if not (CodePeer_Mode or GNATprove_Mode) then
25087 if Nkind (A) = N_String_Literal then
25088 S := Strval (A);
25089
25090 declare
25091 Slen : constant Natural := Natural (String_Length (S));
25092 Options : String (1 .. Slen);
25093 J : Positive;
25094
25095 begin
25096 -- Couldn't we use a for loop here over Options'Range???
25097
25098 J := 1;
25099 loop
25100 C := Get_String_Char (S, Pos (J));
25101
25102 -- This is a weird test, it skips setting validity
25103 -- checks entirely if any element of S is out of
25104 -- range of Character, what is that about ???
25105
25106 exit when not In_Character_Range (C);
25107 Options (J) := Get_Character (C);
25108
25109 if J = Slen then
25110 Set_Validity_Check_Options (Options);
25111 exit;
25112 else
25113 J := J + 1;
25114 end if;
25115 end loop;
25116 end;
25117
25118 elsif Nkind (A) = N_Identifier then
25119 if Chars (A) = Name_All_Checks then
25120 Set_Validity_Check_Options ("a");
25121 elsif Chars (A) = Name_On then
25122 Validity_Checks_On := True;
25123 elsif Chars (A) = Name_Off then
25124 Validity_Checks_On := False;
25125 end if;
25126 end if;
25127 end if;
25128 end Validity_Checks;
25129
25130 --------------
25131 -- Volatile --
25132 --------------
25133
25134 -- pragma Volatile (LOCAL_NAME);
25135
25136 when Pragma_Volatile =>
25137 Process_Atomic_Independent_Shared_Volatile;
25138
25139 -------------------------
25140 -- Volatile_Components --
25141 -------------------------
25142
25143 -- pragma Volatile_Components (array_LOCAL_NAME);
25144
25145 -- Volatile is handled by the same circuit as Atomic_Components
25146
25147 --------------------------
25148 -- Volatile_Full_Access --
25149 --------------------------
25150
25151 -- pragma Volatile_Full_Access (LOCAL_NAME);
25152
25153 when Pragma_Volatile_Full_Access =>
25154 GNAT_Pragma;
25155 Process_Atomic_Independent_Shared_Volatile;
25156
25157 -----------------------
25158 -- Volatile_Function --
25159 -----------------------
25160
25161 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
25162
25163 when Pragma_Volatile_Function => Volatile_Function : declare
25164 Over_Id : Entity_Id;
25165 Spec_Id : Entity_Id;
25166 Subp_Decl : Node_Id;
25167
25168 begin
25169 GNAT_Pragma;
25170 Check_No_Identifiers;
25171 Check_At_Most_N_Arguments (1);
25172
25173 Subp_Decl :=
25174 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
25175
25176 -- Generic subprogram
25177
25178 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
25179 null;
25180
25181 -- Body acts as spec
25182
25183 elsif Nkind (Subp_Decl) = N_Subprogram_Body
25184 and then No (Corresponding_Spec (Subp_Decl))
25185 then
25186 null;
25187
25188 -- Body stub acts as spec
25189
25190 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
25191 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
25192 then
25193 null;
25194
25195 -- Subprogram
25196
25197 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
25198 null;
25199
25200 else
25201 Pragma_Misplaced;
25202 return;
25203 end if;
25204
25205 Spec_Id := Unique_Defining_Entity (Subp_Decl);
25206
25207 if Ekind (Spec_Id) not in E_Function | E_Generic_Function then
25208 Pragma_Misplaced;
25209 return;
25210 end if;
25211
25212 -- A pragma that applies to a Ghost entity becomes Ghost for the
25213 -- purposes of legality checks and removal of ignored Ghost code.
25214
25215 Mark_Ghost_Pragma (N, Spec_Id);
25216
25217 -- Chain the pragma on the contract for completeness
25218
25219 Add_Contract_Item (N, Spec_Id);
25220
25221 -- The legality checks of pragma Volatile_Function are affected by
25222 -- the SPARK mode in effect. Analyze all pragmas in a specific
25223 -- order.
25224
25225 Analyze_If_Present (Pragma_SPARK_Mode);
25226
25227 -- A volatile function cannot override a non-volatile function
25228 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
25229 -- in New_Overloaded_Entity, however at that point the pragma has
25230 -- not been processed yet.
25231
25232 Over_Id := Overridden_Operation (Spec_Id);
25233
25234 if Present (Over_Id)
25235 and then not Is_Volatile_Function (Over_Id)
25236 then
25237 Error_Msg_N
25238 ("incompatible volatile function values in effect", Spec_Id);
25239
25240 Error_Msg_Sloc := Sloc (Over_Id);
25241 Error_Msg_N
25242 ("\& declared # with Volatile_Function value False",
25243 Spec_Id);
25244
25245 Error_Msg_Sloc := Sloc (Spec_Id);
25246 Error_Msg_N
25247 ("\overridden # with Volatile_Function value True",
25248 Spec_Id);
25249 end if;
25250
25251 -- Analyze the Boolean expression (if any)
25252
25253 if Present (Arg1) then
25254 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
25255 end if;
25256 end Volatile_Function;
25257
25258 ----------------------
25259 -- Warning_As_Error --
25260 ----------------------
25261
25262 -- pragma Warning_As_Error (static_string_EXPRESSION);
25263
25264 when Pragma_Warning_As_Error =>
25265 GNAT_Pragma;
25266 Check_Arg_Count (1);
25267 Check_No_Identifiers;
25268 Check_Valid_Configuration_Pragma;
25269
25270 if not Is_Static_String_Expression (Arg1) then
25271 Error_Pragma_Arg
25272 ("argument of pragma% must be static string expression",
25273 Arg1);
25274
25275 -- OK static string expression
25276
25277 else
25278 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
25279 Warnings_As_Errors (Warnings_As_Errors_Count) :=
25280 new String'(Acquire_Warning_Match_String
25281 (Expr_Value_S (Get_Pragma_Arg (Arg1))));
25282 end if;
25283
25284 --------------
25285 -- Warnings --
25286 --------------
25287
25288 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
25289
25290 -- DETAILS ::= On | Off
25291 -- DETAILS ::= On | Off, local_NAME
25292 -- DETAILS ::= static_string_EXPRESSION
25293 -- DETAILS ::= On | Off, static_string_EXPRESSION
25294
25295 -- TOOL_NAME ::= GNAT | GNATprove
25296
25297 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
25298
25299 -- Note: If the first argument matches an allowed tool name, it is
25300 -- always considered to be a tool name, even if there is a string
25301 -- variable of that name.
25302
25303 -- Note if the second argument of DETAILS is a local_NAME then the
25304 -- second form is always understood. If the intention is to use
25305 -- the fourth form, then you can write NAME & "" to force the
25306 -- intepretation as a static_string_EXPRESSION.
25307
25308 when Pragma_Warnings => Warnings : declare
25309 Reason : String_Id;
25310
25311 begin
25312 GNAT_Pragma;
25313 Check_At_Least_N_Arguments (1);
25314
25315 -- See if last argument is labeled Reason. If so, make sure we
25316 -- have a string literal or a concatenation of string literals,
25317 -- and acquire the REASON string. Then remove the REASON argument
25318 -- by decreasing Num_Args by one; Remaining processing looks only
25319 -- at first Num_Args arguments).
25320
25321 declare
25322 Last_Arg : constant Node_Id :=
25323 Last (Pragma_Argument_Associations (N));
25324
25325 begin
25326 if Nkind (Last_Arg) = N_Pragma_Argument_Association
25327 and then Chars (Last_Arg) = Name_Reason
25328 then
25329 Start_String;
25330 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
25331 Reason := End_String;
25332 Arg_Count := Arg_Count - 1;
25333
25334 -- Not allowed in compiler units (bootstrap issues)
25335
25336 Check_Compiler_Unit ("Reason for pragma Warnings", N);
25337
25338 -- No REASON string, set null string as reason
25339
25340 else
25341 Reason := Null_String_Id;
25342 end if;
25343 end;
25344
25345 -- Now proceed with REASON taken care of and eliminated
25346
25347 Check_No_Identifiers;
25348
25349 -- If debug flag -gnatd.i is set, pragma is ignored
25350
25351 if Debug_Flag_Dot_I then
25352 return;
25353 end if;
25354
25355 -- Process various forms of the pragma
25356
25357 declare
25358 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
25359 Shifted_Args : List_Id;
25360
25361 begin
25362 -- See if first argument is a tool name, currently either
25363 -- GNAT or GNATprove. If so, either ignore the pragma if the
25364 -- tool used does not match, or continue as if no tool name
25365 -- was given otherwise, by shifting the arguments.
25366
25367 if Nkind (Argx) = N_Identifier
25368 and then Chars (Argx) in Name_Gnat | Name_Gnatprove
25369 then
25370 if Chars (Argx) = Name_Gnat then
25371 if CodePeer_Mode or GNATprove_Mode then
25372 Rewrite (N, Make_Null_Statement (Loc));
25373 Analyze (N);
25374 raise Pragma_Exit;
25375 end if;
25376
25377 elsif Chars (Argx) = Name_Gnatprove then
25378 if not GNATprove_Mode then
25379 Rewrite (N, Make_Null_Statement (Loc));
25380 Analyze (N);
25381 raise Pragma_Exit;
25382 end if;
25383
25384 else
25385 raise Program_Error;
25386 end if;
25387
25388 -- At this point, the pragma Warnings applies to the tool,
25389 -- so continue with shifted arguments.
25390
25391 Arg_Count := Arg_Count - 1;
25392
25393 if Arg_Count = 1 then
25394 Shifted_Args := New_List (New_Copy (Arg2));
25395 elsif Arg_Count = 2 then
25396 Shifted_Args := New_List (New_Copy (Arg2),
25397 New_Copy (Arg3));
25398 elsif Arg_Count = 3 then
25399 Shifted_Args := New_List (New_Copy (Arg2),
25400 New_Copy (Arg3),
25401 New_Copy (Arg4));
25402 else
25403 raise Program_Error;
25404 end if;
25405
25406 Rewrite (N,
25407 Make_Pragma (Loc,
25408 Chars => Name_Warnings,
25409 Pragma_Argument_Associations => Shifted_Args));
25410 Analyze (N);
25411 raise Pragma_Exit;
25412 end if;
25413
25414 -- One argument case
25415
25416 if Arg_Count = 1 then
25417
25418 -- On/Off one argument case was processed by parser
25419
25420 if Nkind (Argx) = N_Identifier
25421 and then Chars (Argx) in Name_On | Name_Off
25422 then
25423 null;
25424
25425 -- One argument case must be ON/OFF or static string expr
25426
25427 elsif not Is_Static_String_Expression (Arg1) then
25428 Error_Pragma_Arg
25429 ("argument of pragma% must be On/Off or static string "
25430 & "expression", Arg1);
25431
25432 -- One argument string expression case
25433
25434 else
25435 declare
25436 Lit : constant Node_Id := Expr_Value_S (Argx);
25437 Str : constant String_Id := Strval (Lit);
25438 Len : constant Nat := String_Length (Str);
25439 C : Char_Code;
25440 J : Nat;
25441 OK : Boolean;
25442 Chr : Character;
25443
25444 begin
25445 J := 1;
25446 while J <= Len loop
25447 C := Get_String_Char (Str, J);
25448 OK := In_Character_Range (C);
25449
25450 if OK then
25451 Chr := Get_Character (C);
25452
25453 -- Dash case: only -Wxxx is accepted
25454
25455 if J = 1
25456 and then J < Len
25457 and then Chr = '-'
25458 then
25459 J := J + 1;
25460 C := Get_String_Char (Str, J);
25461 Chr := Get_Character (C);
25462 exit when Chr = 'W';
25463 OK := False;
25464
25465 -- Dot case
25466
25467 elsif J < Len and then Chr = '.' then
25468 J := J + 1;
25469 C := Get_String_Char (Str, J);
25470 Chr := Get_Character (C);
25471
25472 if not Set_Dot_Warning_Switch (Chr) then
25473 Error_Pragma_Arg
25474 ("invalid warning switch character "
25475 & '.' & Chr, Arg1);
25476 end if;
25477
25478 -- Non-Dot case
25479
25480 else
25481 OK := Set_Warning_Switch (Chr);
25482 end if;
25483
25484 if not OK then
25485 Error_Pragma_Arg
25486 ("invalid warning switch character " & Chr,
25487 Arg1);
25488 end if;
25489
25490 else
25491 Error_Pragma_Arg
25492 ("invalid wide character in warning switch ",
25493 Arg1);
25494 end if;
25495
25496 J := J + 1;
25497 end loop;
25498 end;
25499 end if;
25500
25501 -- Two or more arguments (must be two)
25502
25503 else
25504 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
25505 Check_Arg_Count (2);
25506
25507 declare
25508 E_Id : Node_Id;
25509 E : Entity_Id;
25510 Err : Boolean;
25511
25512 begin
25513 E_Id := Get_Pragma_Arg (Arg2);
25514 Analyze (E_Id);
25515
25516 -- In the expansion of an inlined body, a reference to
25517 -- the formal may be wrapped in a conversion if the
25518 -- actual is a conversion. Retrieve the real entity name.
25519
25520 if (In_Instance_Body or In_Inlined_Body)
25521 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
25522 then
25523 E_Id := Expression (E_Id);
25524 end if;
25525
25526 -- Entity name case
25527
25528 if Is_Entity_Name (E_Id) then
25529 E := Entity (E_Id);
25530
25531 if E = Any_Id then
25532 return;
25533 else
25534 loop
25535 Set_Warnings_Off
25536 (E, (Chars (Get_Pragma_Arg (Arg1)) =
25537 Name_Off));
25538
25539 -- Suppress elaboration warnings if the entity
25540 -- denotes an elaboration target.
25541
25542 if Is_Elaboration_Target (E) then
25543 Set_Is_Elaboration_Warnings_OK_Id (E, False);
25544 end if;
25545
25546 -- For OFF case, make entry in warnings off
25547 -- pragma table for later processing. But we do
25548 -- not do that within an instance, since these
25549 -- warnings are about what is needed in the
25550 -- template, not an instance of it.
25551
25552 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
25553 and then Warn_On_Warnings_Off
25554 and then not In_Instance
25555 then
25556 Warnings_Off_Pragmas.Append ((N, E, Reason));
25557 end if;
25558
25559 if Is_Enumeration_Type (E) then
25560 declare
25561 Lit : Entity_Id;
25562 begin
25563 Lit := First_Literal (E);
25564 while Present (Lit) loop
25565 Set_Warnings_Off (Lit);
25566 Next_Literal (Lit);
25567 end loop;
25568 end;
25569 end if;
25570
25571 exit when No (Homonym (E));
25572 E := Homonym (E);
25573 end loop;
25574 end if;
25575
25576 -- Error if not entity or static string expression case
25577
25578 elsif not Is_Static_String_Expression (Arg2) then
25579 Error_Pragma_Arg
25580 ("second argument of pragma% must be entity name "
25581 & "or static string expression", Arg2);
25582
25583 -- Static string expression case
25584
25585 else
25586 -- Note on configuration pragma case: If this is a
25587 -- configuration pragma, then for an OFF pragma, we
25588 -- just set Config True in the call, which is all
25589 -- that needs to be done. For the case of ON, this
25590 -- is normally an error, unless it is canceling the
25591 -- effect of a previous OFF pragma in the same file.
25592 -- In any other case, an error will be signalled (ON
25593 -- with no matching OFF).
25594
25595 -- Note: We set Used if we are inside a generic to
25596 -- disable the test that the non-config case actually
25597 -- cancels a warning. That's because we can't be sure
25598 -- there isn't an instantiation in some other unit
25599 -- where a warning is suppressed.
25600
25601 -- We could do a little better here by checking if the
25602 -- generic unit we are inside is public, but for now
25603 -- we don't bother with that refinement.
25604
25605 declare
25606 Message : constant String :=
25607 Acquire_Warning_Match_String
25608 (Expr_Value_S (Get_Pragma_Arg (Arg2)));
25609 begin
25610 if Chars (Argx) = Name_Off then
25611 Set_Specific_Warning_Off
25612 (Loc, Message, Reason,
25613 Config => Is_Configuration_Pragma,
25614 Used => Inside_A_Generic or else In_Instance);
25615
25616 elsif Chars (Argx) = Name_On then
25617 Set_Specific_Warning_On (Loc, Message, Err);
25618
25619 if Err then
25620 Error_Msg
25621 ("??pragma Warnings On with no matching "
25622 & "Warnings Off", Loc);
25623 end if;
25624 end if;
25625 end;
25626 end if;
25627 end;
25628 end if;
25629 end;
25630 end Warnings;
25631
25632 -------------------
25633 -- Weak_External --
25634 -------------------
25635
25636 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
25637
25638 when Pragma_Weak_External => Weak_External : declare
25639 Ent : Entity_Id;
25640
25641 begin
25642 GNAT_Pragma;
25643 Check_Arg_Count (1);
25644 Check_Optional_Identifier (Arg1, Name_Entity);
25645 Check_Arg_Is_Library_Level_Local_Name (Arg1);
25646 Ent := Entity (Get_Pragma_Arg (Arg1));
25647
25648 if Rep_Item_Too_Early (Ent, N) then
25649 return;
25650 else
25651 Ent := Underlying_Type (Ent);
25652 end if;
25653
25654 -- The pragma applies to entities with addresses
25655
25656 if Is_Type (Ent) then
25657 Error_Pragma ("pragma applies to objects and subprograms");
25658 end if;
25659
25660 -- The only processing required is to link this item on to the
25661 -- list of rep items for the given entity. This is accomplished
25662 -- by the call to Rep_Item_Too_Late (when no error is detected
25663 -- and False is returned).
25664
25665 if Rep_Item_Too_Late (Ent, N) then
25666 return;
25667 else
25668 Set_Has_Gigi_Rep_Item (Ent);
25669 end if;
25670 end Weak_External;
25671
25672 -----------------------------
25673 -- Wide_Character_Encoding --
25674 -----------------------------
25675
25676 -- pragma Wide_Character_Encoding (IDENTIFIER);
25677
25678 when Pragma_Wide_Character_Encoding =>
25679 GNAT_Pragma;
25680
25681 -- Nothing to do, handled in parser. Note that we do not enforce
25682 -- configuration pragma placement, this pragma can appear at any
25683 -- place in the source, allowing mixed encodings within a single
25684 -- source program.
25685
25686 null;
25687
25688 --------------------
25689 -- Unknown_Pragma --
25690 --------------------
25691
25692 -- Should be impossible, since the case of an unknown pragma is
25693 -- separately processed before the case statement is entered.
25694
25695 when Unknown_Pragma =>
25696 raise Program_Error;
25697 end case;
25698
25699 -- AI05-0144: detect dangerous order dependence. Disabled for now,
25700 -- until AI is formally approved.
25701
25702 -- Check_Order_Dependence;
25703
25704 exception
25705 when Pragma_Exit => null;
25706 end Analyze_Pragma;
25707
25708 ---------------------------------------------
25709 -- Analyze_Pre_Post_Condition_In_Decl_Part --
25710 ---------------------------------------------
25711
25712 -- WARNING: This routine manages Ghost regions. Return statements must be
25713 -- replaced by gotos which jump to the end of the routine and restore the
25714 -- Ghost mode.
25715
25716 procedure Analyze_Pre_Post_Condition_In_Decl_Part
25717 (N : Node_Id;
25718 Freeze_Id : Entity_Id := Empty)
25719 is
25720 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
25721 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
25722
25723 Disp_Typ : Entity_Id;
25724 -- The dispatching type of the subprogram subject to the pre- or
25725 -- postcondition.
25726
25727 function Check_References (Nod : Node_Id) return Traverse_Result;
25728 -- Check that expression Nod does not mention non-primitives of the
25729 -- type, global objects of the type, or other illegalities described
25730 -- and implied by AI12-0113.
25731
25732 ----------------------
25733 -- Check_References --
25734 ----------------------
25735
25736 function Check_References (Nod : Node_Id) return Traverse_Result is
25737 begin
25738 if Nkind (Nod) = N_Function_Call
25739 and then Is_Entity_Name (Name (Nod))
25740 then
25741 declare
25742 Func : constant Entity_Id := Entity (Name (Nod));
25743 Form : Entity_Id;
25744
25745 begin
25746 -- An operation of the type must be a primitive
25747
25748 if No (Find_Dispatching_Type (Func)) then
25749 Form := First_Formal (Func);
25750 while Present (Form) loop
25751 if Etype (Form) = Disp_Typ then
25752 Error_Msg_NE
25753 ("operation in class-wide condition must be "
25754 & "primitive of &", Nod, Disp_Typ);
25755 end if;
25756
25757 Next_Formal (Form);
25758 end loop;
25759
25760 -- A return object of the type is illegal as well
25761
25762 if Etype (Func) = Disp_Typ
25763 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
25764 then
25765 Error_Msg_NE
25766 ("operation in class-wide condition must be primitive "
25767 & "of &", Nod, Disp_Typ);
25768 end if;
25769
25770 -- Otherwise we have a call to an overridden primitive, and we
25771 -- will create a common class-wide clone for the body of
25772 -- original operation and its eventual inherited versions. If
25773 -- the original operation dispatches on result it is never
25774 -- inherited and there is no need for a clone. There is not
25775 -- need for a clone either in GNATprove mode, as cases that
25776 -- would require it are rejected (when an inherited primitive
25777 -- calls an overridden operation in a class-wide contract), and
25778 -- the clone would make proof impossible in some cases.
25779
25780 elsif not Is_Abstract_Subprogram (Spec_Id)
25781 and then No (Class_Wide_Clone (Spec_Id))
25782 and then not Has_Controlling_Result (Spec_Id)
25783 and then not GNATprove_Mode
25784 then
25785 Build_Class_Wide_Clone_Decl (Spec_Id);
25786 end if;
25787 end;
25788
25789 elsif Is_Entity_Name (Nod)
25790 and then
25791 (Etype (Nod) = Disp_Typ
25792 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
25793 and then Ekind (Entity (Nod)) in E_Constant | E_Variable
25794 then
25795 Error_Msg_NE
25796 ("object in class-wide condition must be formal of type &",
25797 Nod, Disp_Typ);
25798
25799 elsif Nkind (Nod) = N_Explicit_Dereference
25800 and then (Etype (Nod) = Disp_Typ
25801 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
25802 and then (not Is_Entity_Name (Prefix (Nod))
25803 or else not Is_Formal (Entity (Prefix (Nod))))
25804 then
25805 Error_Msg_NE
25806 ("operation in class-wide condition must be primitive of &",
25807 Nod, Disp_Typ);
25808 end if;
25809
25810 return OK;
25811 end Check_References;
25812
25813 procedure Check_Class_Wide_Condition is
25814 new Traverse_Proc (Check_References);
25815
25816 -- Local variables
25817
25818 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
25819
25820 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
25821 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
25822 -- Save the Ghost-related attributes to restore on exit
25823
25824 Errors : Nat;
25825 Restore_Scope : Boolean := False;
25826
25827 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
25828
25829 begin
25830 -- Do not analyze the pragma multiple times
25831
25832 if Is_Analyzed_Pragma (N) then
25833 return;
25834 end if;
25835
25836 -- Set the Ghost mode in effect from the pragma. Due to the delayed
25837 -- analysis of the pragma, the Ghost mode at point of declaration and
25838 -- point of analysis may not necessarily be the same. Use the mode in
25839 -- effect at the point of declaration.
25840
25841 Set_Ghost_Mode (N);
25842
25843 -- Ensure that the subprogram and its formals are visible when analyzing
25844 -- the expression of the pragma.
25845
25846 if not In_Open_Scopes (Spec_Id) then
25847 Restore_Scope := True;
25848 Push_Scope (Spec_Id);
25849
25850 if Is_Generic_Subprogram (Spec_Id) then
25851 Install_Generic_Formals (Spec_Id);
25852 else
25853 Install_Formals (Spec_Id);
25854 end if;
25855 end if;
25856
25857 Errors := Serious_Errors_Detected;
25858 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
25859
25860 -- Emit a clarification message when the expression contains at least
25861 -- one undefined reference, possibly due to contract freezing.
25862
25863 if Errors /= Serious_Errors_Detected
25864 and then Present (Freeze_Id)
25865 and then Has_Undefined_Reference (Expr)
25866 then
25867 Contract_Freeze_Error (Spec_Id, Freeze_Id);
25868 end if;
25869
25870 if Class_Present (N) then
25871
25872 -- Verify that a class-wide condition is legal, i.e. the operation is
25873 -- a primitive of a tagged type. Note that a generic subprogram is
25874 -- not a primitive operation.
25875
25876 Disp_Typ := Find_Dispatching_Type (Spec_Id);
25877
25878 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
25879 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
25880
25881 if From_Aspect_Specification (N) then
25882 Error_Msg_N
25883 ("aspect % can only be specified for a primitive operation "
25884 & "of a tagged type", Corresponding_Aspect (N));
25885
25886 -- The pragma is a source construct
25887
25888 else
25889 Error_Msg_N
25890 ("pragma % can only be specified for a primitive operation "
25891 & "of a tagged type", N);
25892 end if;
25893
25894 -- Remaining semantic checks require a full tree traversal
25895
25896 else
25897 Check_Class_Wide_Condition (Expr);
25898 end if;
25899
25900 end if;
25901
25902 if Restore_Scope then
25903 End_Scope;
25904 end if;
25905
25906 -- If analysis of the condition indicates that a class-wide clone
25907 -- has been created, build and analyze its declaration.
25908
25909 if Is_Subprogram (Spec_Id)
25910 and then Present (Class_Wide_Clone (Spec_Id))
25911 then
25912 Analyze (Unit_Declaration_Node (Class_Wide_Clone (Spec_Id)));
25913 end if;
25914
25915 -- Currently it is not possible to inline pre/postconditions on a
25916 -- subprogram subject to pragma Inline_Always.
25917
25918 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
25919 Set_Is_Analyzed_Pragma (N);
25920
25921 Restore_Ghost_Region (Saved_GM, Saved_IGR);
25922 end Analyze_Pre_Post_Condition_In_Decl_Part;
25923
25924 ------------------------------------------
25925 -- Analyze_Refined_Depends_In_Decl_Part --
25926 ------------------------------------------
25927
25928 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
25929 procedure Check_Dependency_Clause
25930 (Spec_Id : Entity_Id;
25931 Dep_Clause : Node_Id;
25932 Dep_States : Elist_Id;
25933 Refinements : List_Id;
25934 Matched_Items : in out Elist_Id);
25935 -- Try to match a single dependency clause Dep_Clause against one or
25936 -- more refinement clauses found in list Refinements. Each successful
25937 -- match eliminates at least one refinement clause from Refinements.
25938 -- Spec_Id denotes the entity of the related subprogram. Dep_States
25939 -- denotes the entities of all abstract states which appear in pragma
25940 -- Depends. Matched_Items contains the entities of all successfully
25941 -- matched items found in pragma Depends.
25942
25943 procedure Check_Output_States
25944 (Spec_Inputs : Elist_Id;
25945 Spec_Outputs : Elist_Id;
25946 Body_Inputs : Elist_Id;
25947 Body_Outputs : Elist_Id);
25948 -- Determine whether pragma Depends contains an output state with a
25949 -- visible refinement and if so, ensure that pragma Refined_Depends
25950 -- mentions all its constituents as outputs. Spec_Inputs and
25951 -- Spec_Outputs denote the inputs and outputs of the subprogram spec
25952 -- synthesized from pragma Depends. Body_Inputs and Body_Outputs denote
25953 -- the inputs and outputs of the subprogram body synthesized from pragma
25954 -- Refined_Depends.
25955
25956 function Collect_States (Clauses : List_Id) return Elist_Id;
25957 -- Given a normalized list of dependencies obtained from calling
25958 -- Normalize_Clauses, return a list containing the entities of all
25959 -- states appearing in dependencies. It helps in checking refinements
25960 -- involving a state and a corresponding constituent which is not a
25961 -- direct constituent of the state.
25962
25963 procedure Normalize_Clauses (Clauses : List_Id);
25964 -- Given a list of dependence or refinement clauses Clauses, normalize
25965 -- each clause by creating multiple dependencies with exactly one input
25966 -- and one output.
25967
25968 procedure Remove_Extra_Clauses
25969 (Clauses : List_Id;
25970 Matched_Items : Elist_Id);
25971 -- Given a list of refinement clauses Clauses, remove all clauses whose
25972 -- inputs and/or outputs have been previously matched. See the body for
25973 -- all special cases. Matched_Items contains the entities of all matched
25974 -- items found in pragma Depends.
25975
25976 procedure Report_Extra_Clauses (Clauses : List_Id);
25977 -- Emit an error for each extra clause found in list Clauses
25978
25979 -----------------------------
25980 -- Check_Dependency_Clause --
25981 -----------------------------
25982
25983 procedure Check_Dependency_Clause
25984 (Spec_Id : Entity_Id;
25985 Dep_Clause : Node_Id;
25986 Dep_States : Elist_Id;
25987 Refinements : List_Id;
25988 Matched_Items : in out Elist_Id)
25989 is
25990 Dep_Input : constant Node_Id := Expression (Dep_Clause);
25991 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
25992
25993 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
25994 -- Determine whether dependency item Dep_Item has been matched in a
25995 -- previous clause.
25996
25997 function Is_In_Out_State_Clause return Boolean;
25998 -- Determine whether dependence clause Dep_Clause denotes an abstract
25999 -- state that depends on itself (State => State).
26000
26001 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
26002 -- Determine whether item Item denotes an abstract state with visible
26003 -- null refinement.
26004
26005 procedure Match_Items
26006 (Dep_Item : Node_Id;
26007 Ref_Item : Node_Id;
26008 Matched : out Boolean);
26009 -- Try to match dependence item Dep_Item against refinement item
26010 -- Ref_Item. To match against a possible null refinement (see 2, 9),
26011 -- set Ref_Item to Empty. Flag Matched is set to True when one of
26012 -- the following conformance scenarios is in effect:
26013 -- 1) Both items denote null
26014 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
26015 -- 3) Both items denote attribute 'Result
26016 -- 4) Both items denote the same object
26017 -- 5) Both items denote the same formal parameter
26018 -- 6) Both items denote the same current instance of a type
26019 -- 7) Both items denote the same discriminant
26020 -- 8) Dep_Item is an abstract state with visible null refinement
26021 -- and Ref_Item denotes null.
26022 -- 9) Dep_Item is an abstract state with visible null refinement
26023 -- and Ref_Item is Empty (special case).
26024 -- 10) Dep_Item is an abstract state with full or partial visible
26025 -- non-null refinement and Ref_Item denotes one of its
26026 -- constituents.
26027 -- 11) Dep_Item is an abstract state without a full visible
26028 -- refinement and Ref_Item denotes the same state.
26029 -- When scenario 10 is in effect, the entity of the abstract state
26030 -- denoted by Dep_Item is added to list Refined_States.
26031
26032 procedure Record_Item (Item_Id : Entity_Id);
26033 -- Store the entity of an item denoted by Item_Id in Matched_Items
26034
26035 ------------------------
26036 -- Is_Already_Matched --
26037 ------------------------
26038
26039 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean is
26040 Item_Id : Entity_Id := Empty;
26041
26042 begin
26043 -- When the dependency item denotes attribute 'Result, check for
26044 -- the entity of the related subprogram.
26045
26046 if Is_Attribute_Result (Dep_Item) then
26047 Item_Id := Spec_Id;
26048
26049 elsif Is_Entity_Name (Dep_Item) then
26050 Item_Id := Available_View (Entity_Of (Dep_Item));
26051 end if;
26052
26053 return
26054 Present (Item_Id) and then Contains (Matched_Items, Item_Id);
26055 end Is_Already_Matched;
26056
26057 ----------------------------
26058 -- Is_In_Out_State_Clause --
26059 ----------------------------
26060
26061 function Is_In_Out_State_Clause return Boolean is
26062 Dep_Input_Id : Entity_Id;
26063 Dep_Output_Id : Entity_Id;
26064
26065 begin
26066 -- Detect the following clause:
26067 -- State => State
26068
26069 if Is_Entity_Name (Dep_Input)
26070 and then Is_Entity_Name (Dep_Output)
26071 then
26072 -- Handle abstract views generated for limited with clauses
26073
26074 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
26075 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
26076
26077 return
26078 Ekind (Dep_Input_Id) = E_Abstract_State
26079 and then Dep_Input_Id = Dep_Output_Id;
26080 else
26081 return False;
26082 end if;
26083 end Is_In_Out_State_Clause;
26084
26085 ---------------------------
26086 -- Is_Null_Refined_State --
26087 ---------------------------
26088
26089 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
26090 Item_Id : Entity_Id;
26091
26092 begin
26093 if Is_Entity_Name (Item) then
26094
26095 -- Handle abstract views generated for limited with clauses
26096
26097 Item_Id := Available_View (Entity_Of (Item));
26098
26099 return
26100 Ekind (Item_Id) = E_Abstract_State
26101 and then Has_Null_Visible_Refinement (Item_Id);
26102 else
26103 return False;
26104 end if;
26105 end Is_Null_Refined_State;
26106
26107 -----------------
26108 -- Match_Items --
26109 -----------------
26110
26111 procedure Match_Items
26112 (Dep_Item : Node_Id;
26113 Ref_Item : Node_Id;
26114 Matched : out Boolean)
26115 is
26116 Dep_Item_Id : Entity_Id;
26117 Ref_Item_Id : Entity_Id;
26118
26119 begin
26120 -- Assume that the two items do not match
26121
26122 Matched := False;
26123
26124 -- A null matches null or Empty (special case)
26125
26126 if Nkind (Dep_Item) = N_Null
26127 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
26128 then
26129 Matched := True;
26130
26131 -- Attribute 'Result matches attribute 'Result
26132
26133 elsif Is_Attribute_Result (Dep_Item)
26134 and then Is_Attribute_Result (Ref_Item)
26135 then
26136 -- Put the entity of the related function on the list of
26137 -- matched items because attribute 'Result does not carry
26138 -- an entity similar to states and constituents.
26139
26140 Record_Item (Spec_Id);
26141 Matched := True;
26142
26143 -- Abstract states, current instances of concurrent types,
26144 -- discriminants, formal parameters and objects.
26145
26146 elsif Is_Entity_Name (Dep_Item) then
26147
26148 -- Handle abstract views generated for limited with clauses
26149
26150 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
26151
26152 if Ekind (Dep_Item_Id) = E_Abstract_State then
26153
26154 -- An abstract state with visible null refinement matches
26155 -- null or Empty (special case).
26156
26157 if Has_Null_Visible_Refinement (Dep_Item_Id)
26158 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
26159 then
26160 Record_Item (Dep_Item_Id);
26161 Matched := True;
26162
26163 -- An abstract state with visible non-null refinement
26164 -- matches one of its constituents, or itself for an
26165 -- abstract state with partial visible refinement.
26166
26167 elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then
26168 if Is_Entity_Name (Ref_Item) then
26169 Ref_Item_Id := Entity_Of (Ref_Item);
26170
26171 if Ekind (Ref_Item_Id) in
26172 E_Abstract_State | E_Constant | E_Variable
26173 and then Present (Encapsulating_State (Ref_Item_Id))
26174 and then Find_Encapsulating_State
26175 (Dep_States, Ref_Item_Id) = Dep_Item_Id
26176 then
26177 Record_Item (Dep_Item_Id);
26178 Matched := True;
26179
26180 elsif not Has_Visible_Refinement (Dep_Item_Id)
26181 and then Ref_Item_Id = Dep_Item_Id
26182 then
26183 Record_Item (Dep_Item_Id);
26184 Matched := True;
26185 end if;
26186 end if;
26187
26188 -- An abstract state without a visible refinement matches
26189 -- itself.
26190
26191 elsif Is_Entity_Name (Ref_Item)
26192 and then Entity_Of (Ref_Item) = Dep_Item_Id
26193 then
26194 Record_Item (Dep_Item_Id);
26195 Matched := True;
26196 end if;
26197
26198 -- A current instance of a concurrent type, discriminant,
26199 -- formal parameter or an object matches itself.
26200
26201 elsif Is_Entity_Name (Ref_Item)
26202 and then Entity_Of (Ref_Item) = Dep_Item_Id
26203 then
26204 Record_Item (Dep_Item_Id);
26205 Matched := True;
26206 end if;
26207 end if;
26208 end Match_Items;
26209
26210 -----------------
26211 -- Record_Item --
26212 -----------------
26213
26214 procedure Record_Item (Item_Id : Entity_Id) is
26215 begin
26216 if No (Matched_Items) then
26217 Matched_Items := New_Elmt_List;
26218 end if;
26219
26220 Append_Unique_Elmt (Item_Id, Matched_Items);
26221 end Record_Item;
26222
26223 -- Local variables
26224
26225 Clause_Matched : Boolean := False;
26226 Dummy : Boolean := False;
26227 Inputs_Match : Boolean;
26228 Next_Ref_Clause : Node_Id;
26229 Outputs_Match : Boolean;
26230 Ref_Clause : Node_Id;
26231 Ref_Input : Node_Id;
26232 Ref_Output : Node_Id;
26233
26234 -- Start of processing for Check_Dependency_Clause
26235
26236 begin
26237 -- Do not perform this check in an instance because it was already
26238 -- performed successfully in the generic template.
26239
26240 if In_Instance then
26241 return;
26242 end if;
26243
26244 -- Examine all refinement clauses and compare them against the
26245 -- dependence clause.
26246
26247 Ref_Clause := First (Refinements);
26248 while Present (Ref_Clause) loop
26249 Next_Ref_Clause := Next (Ref_Clause);
26250
26251 -- Obtain the attributes of the current refinement clause
26252
26253 Ref_Input := Expression (Ref_Clause);
26254 Ref_Output := First (Choices (Ref_Clause));
26255
26256 -- The current refinement clause matches the dependence clause
26257 -- when both outputs match and both inputs match. See routine
26258 -- Match_Items for all possible conformance scenarios.
26259
26260 -- Depends Dep_Output => Dep_Input
26261 -- ^ ^
26262 -- match ? match ?
26263 -- v v
26264 -- Refined_Depends Ref_Output => Ref_Input
26265
26266 Match_Items
26267 (Dep_Item => Dep_Input,
26268 Ref_Item => Ref_Input,
26269 Matched => Inputs_Match);
26270
26271 Match_Items
26272 (Dep_Item => Dep_Output,
26273 Ref_Item => Ref_Output,
26274 Matched => Outputs_Match);
26275
26276 -- An In_Out state clause may be matched against a refinement with
26277 -- a null input or null output as long as the non-null side of the
26278 -- relation contains a valid constituent of the In_Out_State.
26279
26280 if Is_In_Out_State_Clause then
26281
26282 -- Depends => (State => State)
26283 -- Refined_Depends => (null => Constit) -- OK
26284
26285 if Inputs_Match
26286 and then not Outputs_Match
26287 and then Nkind (Ref_Output) = N_Null
26288 then
26289 Outputs_Match := True;
26290 end if;
26291
26292 -- Depends => (State => State)
26293 -- Refined_Depends => (Constit => null) -- OK
26294
26295 if not Inputs_Match
26296 and then Outputs_Match
26297 and then Nkind (Ref_Input) = N_Null
26298 then
26299 Inputs_Match := True;
26300 end if;
26301 end if;
26302
26303 -- The current refinement clause is legally constructed following
26304 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
26305 -- the pool of candidates. The seach continues because a single
26306 -- dependence clause may have multiple matching refinements.
26307
26308 if Inputs_Match and Outputs_Match then
26309 Clause_Matched := True;
26310 Remove (Ref_Clause);
26311 end if;
26312
26313 Ref_Clause := Next_Ref_Clause;
26314 end loop;
26315
26316 -- Depending on the order or composition of refinement clauses, an
26317 -- In_Out state clause may not be directly refinable.
26318
26319 -- Refined_State => (State => (Constit_1, Constit_2))
26320 -- Depends => ((Output, State) => (Input, State))
26321 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
26322
26323 -- Matching normalized clause (State => State) fails because there is
26324 -- no direct refinement capable of satisfying this relation. Another
26325 -- similar case arises when clauses (Constit_1 => Input) and (Output
26326 -- => Constit_2) are matched first, leaving no candidates for clause
26327 -- (State => State). Both scenarios are legal as long as one of the
26328 -- previous clauses mentioned a valid constituent of State.
26329
26330 if not Clause_Matched
26331 and then Is_In_Out_State_Clause
26332 and then Is_Already_Matched (Dep_Input)
26333 then
26334 Clause_Matched := True;
26335 end if;
26336
26337 -- A clause where the input is an abstract state with visible null
26338 -- refinement or a 'Result attribute is implicitly matched when the
26339 -- output has already been matched in a previous clause.
26340
26341 -- Refined_State => (State => null)
26342 -- Depends => (Output => State) -- implicitly OK
26343 -- Refined_Depends => (Output => ...)
26344 -- Depends => (...'Result => State) -- implicitly OK
26345 -- Refined_Depends => (...'Result => ...)
26346
26347 if not Clause_Matched
26348 and then Is_Null_Refined_State (Dep_Input)
26349 and then Is_Already_Matched (Dep_Output)
26350 then
26351 Clause_Matched := True;
26352 end if;
26353
26354 -- A clause where the output is an abstract state with visible null
26355 -- refinement is implicitly matched when the input has already been
26356 -- matched in a previous clause.
26357
26358 -- Refined_State => (State => null)
26359 -- Depends => (State => Input) -- implicitly OK
26360 -- Refined_Depends => (... => Input)
26361
26362 if not Clause_Matched
26363 and then Is_Null_Refined_State (Dep_Output)
26364 and then Is_Already_Matched (Dep_Input)
26365 then
26366 Clause_Matched := True;
26367 end if;
26368
26369 -- At this point either all refinement clauses have been examined or
26370 -- pragma Refined_Depends contains a solitary null. Only an abstract
26371 -- state with null refinement can possibly match these cases.
26372
26373 -- Refined_State => (State => null)
26374 -- Depends => (State => null)
26375 -- Refined_Depends => null -- OK
26376
26377 if not Clause_Matched then
26378 Match_Items
26379 (Dep_Item => Dep_Input,
26380 Ref_Item => Empty,
26381 Matched => Inputs_Match);
26382
26383 Match_Items
26384 (Dep_Item => Dep_Output,
26385 Ref_Item => Empty,
26386 Matched => Outputs_Match);
26387
26388 Clause_Matched := Inputs_Match and Outputs_Match;
26389 end if;
26390
26391 -- If the contents of Refined_Depends are legal, then the current
26392 -- dependence clause should be satisfied either by an explicit match
26393 -- or by one of the special cases.
26394
26395 if not Clause_Matched then
26396 SPARK_Msg_NE
26397 (Fix_Msg (Spec_Id, "dependence clause of subprogram & has no "
26398 & "matching refinement in body"), Dep_Clause, Spec_Id);
26399 end if;
26400 end Check_Dependency_Clause;
26401
26402 -------------------------
26403 -- Check_Output_States --
26404 -------------------------
26405
26406 procedure Check_Output_States
26407 (Spec_Inputs : Elist_Id;
26408 Spec_Outputs : Elist_Id;
26409 Body_Inputs : Elist_Id;
26410 Body_Outputs : Elist_Id)
26411 is
26412 procedure Check_Constituent_Usage (State_Id : Entity_Id);
26413 -- Determine whether all constituents of state State_Id with full
26414 -- visible refinement are used as outputs in pragma Refined_Depends.
26415 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
26416
26417 -----------------------------
26418 -- Check_Constituent_Usage --
26419 -----------------------------
26420
26421 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
26422 Constits : constant Elist_Id :=
26423 Partial_Refinement_Constituents (State_Id);
26424 Constit_Elmt : Elmt_Id;
26425 Constit_Id : Entity_Id;
26426 Only_Partial : constant Boolean :=
26427 not Has_Visible_Refinement (State_Id);
26428 Posted : Boolean := False;
26429
26430 begin
26431 if Present (Constits) then
26432 Constit_Elmt := First_Elmt (Constits);
26433 while Present (Constit_Elmt) loop
26434 Constit_Id := Node (Constit_Elmt);
26435
26436 -- Issue an error when a constituent of State_Id is used,
26437 -- and State_Id has only partial visible refinement
26438 -- (SPARK RM 7.2.4(3d)).
26439
26440 if Only_Partial then
26441 if (Present (Body_Inputs)
26442 and then Appears_In (Body_Inputs, Constit_Id))
26443 or else
26444 (Present (Body_Outputs)
26445 and then Appears_In (Body_Outputs, Constit_Id))
26446 then
26447 Error_Msg_Name_1 := Chars (State_Id);
26448 SPARK_Msg_NE
26449 ("constituent & of state % cannot be used in "
26450 & "dependence refinement", N, Constit_Id);
26451 Error_Msg_Name_1 := Chars (State_Id);
26452 SPARK_Msg_N ("\use state % instead", N);
26453 end if;
26454
26455 -- The constituent acts as an input (SPARK RM 7.2.5(3))
26456
26457 elsif Present (Body_Inputs)
26458 and then Appears_In (Body_Inputs, Constit_Id)
26459 then
26460 Error_Msg_Name_1 := Chars (State_Id);
26461 SPARK_Msg_NE
26462 ("constituent & of state % must act as output in "
26463 & "dependence refinement", N, Constit_Id);
26464
26465 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
26466
26467 elsif No (Body_Outputs)
26468 or else not Appears_In (Body_Outputs, Constit_Id)
26469 then
26470 if not Posted then
26471 Posted := True;
26472 SPARK_Msg_NE
26473 ("output state & must be replaced by all its "
26474 & "constituents in dependence refinement",
26475 N, State_Id);
26476 end if;
26477
26478 SPARK_Msg_NE
26479 ("\constituent & is missing in output list",
26480 N, Constit_Id);
26481 end if;
26482
26483 Next_Elmt (Constit_Elmt);
26484 end loop;
26485 end if;
26486 end Check_Constituent_Usage;
26487
26488 -- Local variables
26489
26490 Item : Node_Id;
26491 Item_Elmt : Elmt_Id;
26492 Item_Id : Entity_Id;
26493
26494 -- Start of processing for Check_Output_States
26495
26496 begin
26497 -- Do not perform this check in an instance because it was already
26498 -- performed successfully in the generic template.
26499
26500 if In_Instance then
26501 null;
26502
26503 -- Inspect the outputs of pragma Depends looking for a state with a
26504 -- visible refinement.
26505
26506 elsif Present (Spec_Outputs) then
26507 Item_Elmt := First_Elmt (Spec_Outputs);
26508 while Present (Item_Elmt) loop
26509 Item := Node (Item_Elmt);
26510
26511 -- Deal with the mixed nature of the input and output lists
26512
26513 if Nkind (Item) = N_Defining_Identifier then
26514 Item_Id := Item;
26515 else
26516 Item_Id := Available_View (Entity_Of (Item));
26517 end if;
26518
26519 if Ekind (Item_Id) = E_Abstract_State then
26520
26521 -- The state acts as an input-output, skip it
26522
26523 if Present (Spec_Inputs)
26524 and then Appears_In (Spec_Inputs, Item_Id)
26525 then
26526 null;
26527
26528 -- Ensure that all of the constituents are utilized as
26529 -- outputs in pragma Refined_Depends.
26530
26531 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
26532 Check_Constituent_Usage (Item_Id);
26533 end if;
26534 end if;
26535
26536 Next_Elmt (Item_Elmt);
26537 end loop;
26538 end if;
26539 end Check_Output_States;
26540
26541 --------------------
26542 -- Collect_States --
26543 --------------------
26544
26545 function Collect_States (Clauses : List_Id) return Elist_Id is
26546 procedure Collect_State
26547 (Item : Node_Id;
26548 States : in out Elist_Id);
26549 -- Add the entity of Item to list States when it denotes to a state
26550
26551 -------------------
26552 -- Collect_State --
26553 -------------------
26554
26555 procedure Collect_State
26556 (Item : Node_Id;
26557 States : in out Elist_Id)
26558 is
26559 Id : Entity_Id;
26560
26561 begin
26562 if Is_Entity_Name (Item) then
26563 Id := Entity_Of (Item);
26564
26565 if Ekind (Id) = E_Abstract_State then
26566 if No (States) then
26567 States := New_Elmt_List;
26568 end if;
26569
26570 Append_Unique_Elmt (Id, States);
26571 end if;
26572 end if;
26573 end Collect_State;
26574
26575 -- Local variables
26576
26577 Clause : Node_Id;
26578 Input : Node_Id;
26579 Output : Node_Id;
26580 States : Elist_Id := No_Elist;
26581
26582 -- Start of processing for Collect_States
26583
26584 begin
26585 Clause := First (Clauses);
26586 while Present (Clause) loop
26587 Input := Expression (Clause);
26588 Output := First (Choices (Clause));
26589
26590 Collect_State (Input, States);
26591 Collect_State (Output, States);
26592
26593 Next (Clause);
26594 end loop;
26595
26596 return States;
26597 end Collect_States;
26598
26599 -----------------------
26600 -- Normalize_Clauses --
26601 -----------------------
26602
26603 procedure Normalize_Clauses (Clauses : List_Id) is
26604 procedure Normalize_Inputs (Clause : Node_Id);
26605 -- Normalize clause Clause by creating multiple clauses for each
26606 -- input item of Clause. It is assumed that Clause has exactly one
26607 -- output. The transformation is as follows:
26608 --
26609 -- Output => (Input_1, Input_2) -- original
26610 --
26611 -- Output => Input_1 -- normalizations
26612 -- Output => Input_2
26613
26614 procedure Normalize_Outputs (Clause : Node_Id);
26615 -- Normalize clause Clause by creating multiple clause for each
26616 -- output item of Clause. The transformation is as follows:
26617 --
26618 -- (Output_1, Output_2) => Input -- original
26619 --
26620 -- Output_1 => Input -- normalization
26621 -- Output_2 => Input
26622
26623 ----------------------
26624 -- Normalize_Inputs --
26625 ----------------------
26626
26627 procedure Normalize_Inputs (Clause : Node_Id) is
26628 Inputs : constant Node_Id := Expression (Clause);
26629 Loc : constant Source_Ptr := Sloc (Clause);
26630 Output : constant List_Id := Choices (Clause);
26631 Last_Input : Node_Id;
26632 Input : Node_Id;
26633 New_Clause : Node_Id;
26634 Next_Input : Node_Id;
26635
26636 begin
26637 -- Normalization is performed only when the original clause has
26638 -- more than one input. Multiple inputs appear as an aggregate.
26639
26640 if Nkind (Inputs) = N_Aggregate then
26641 Last_Input := Last (Expressions (Inputs));
26642
26643 -- Create a new clause for each input
26644
26645 Input := First (Expressions (Inputs));
26646 while Present (Input) loop
26647 Next_Input := Next (Input);
26648
26649 -- Unhook the current input from the original input list
26650 -- because it will be relocated to a new clause.
26651
26652 Remove (Input);
26653
26654 -- Special processing for the last input. At this point the
26655 -- original aggregate has been stripped down to one element.
26656 -- Replace the aggregate by the element itself.
26657
26658 if Input = Last_Input then
26659 Rewrite (Inputs, Input);
26660
26661 -- Generate a clause of the form:
26662 -- Output => Input
26663
26664 else
26665 New_Clause :=
26666 Make_Component_Association (Loc,
26667 Choices => New_Copy_List_Tree (Output),
26668 Expression => Input);
26669
26670 -- The new clause contains replicated content that has
26671 -- already been analyzed, mark the clause as analyzed.
26672
26673 Set_Analyzed (New_Clause);
26674 Insert_After (Clause, New_Clause);
26675 end if;
26676
26677 Input := Next_Input;
26678 end loop;
26679 end if;
26680 end Normalize_Inputs;
26681
26682 -----------------------
26683 -- Normalize_Outputs --
26684 -----------------------
26685
26686 procedure Normalize_Outputs (Clause : Node_Id) is
26687 Inputs : constant Node_Id := Expression (Clause);
26688 Loc : constant Source_Ptr := Sloc (Clause);
26689 Outputs : constant Node_Id := First (Choices (Clause));
26690 Last_Output : Node_Id;
26691 New_Clause : Node_Id;
26692 Next_Output : Node_Id;
26693 Output : Node_Id;
26694
26695 begin
26696 -- Multiple outputs appear as an aggregate. Nothing to do when
26697 -- the clause has exactly one output.
26698
26699 if Nkind (Outputs) = N_Aggregate then
26700 Last_Output := Last (Expressions (Outputs));
26701
26702 -- Create a clause for each output. Note that each time a new
26703 -- clause is created, the original output list slowly shrinks
26704 -- until there is one item left.
26705
26706 Output := First (Expressions (Outputs));
26707 while Present (Output) loop
26708 Next_Output := Next (Output);
26709
26710 -- Unhook the output from the original output list as it
26711 -- will be relocated to a new clause.
26712
26713 Remove (Output);
26714
26715 -- Special processing for the last output. At this point
26716 -- the original aggregate has been stripped down to one
26717 -- element. Replace the aggregate by the element itself.
26718
26719 if Output = Last_Output then
26720 Rewrite (Outputs, Output);
26721
26722 else
26723 -- Generate a clause of the form:
26724 -- (Output => Inputs)
26725
26726 New_Clause :=
26727 Make_Component_Association (Loc,
26728 Choices => New_List (Output),
26729 Expression => New_Copy_Tree (Inputs));
26730
26731 -- The new clause contains replicated content that has
26732 -- already been analyzed. There is not need to reanalyze
26733 -- them.
26734
26735 Set_Analyzed (New_Clause);
26736 Insert_After (Clause, New_Clause);
26737 end if;
26738
26739 Output := Next_Output;
26740 end loop;
26741 end if;
26742 end Normalize_Outputs;
26743
26744 -- Local variables
26745
26746 Clause : Node_Id;
26747
26748 -- Start of processing for Normalize_Clauses
26749
26750 begin
26751 Clause := First (Clauses);
26752 while Present (Clause) loop
26753 Normalize_Outputs (Clause);
26754 Next (Clause);
26755 end loop;
26756
26757 Clause := First (Clauses);
26758 while Present (Clause) loop
26759 Normalize_Inputs (Clause);
26760 Next (Clause);
26761 end loop;
26762 end Normalize_Clauses;
26763
26764 --------------------------
26765 -- Remove_Extra_Clauses --
26766 --------------------------
26767
26768 procedure Remove_Extra_Clauses
26769 (Clauses : List_Id;
26770 Matched_Items : Elist_Id)
26771 is
26772 Clause : Node_Id;
26773 Input : Node_Id;
26774 Input_Id : Entity_Id;
26775 Next_Clause : Node_Id;
26776 Output : Node_Id;
26777 State_Id : Entity_Id;
26778
26779 begin
26780 Clause := First (Clauses);
26781 while Present (Clause) loop
26782 Next_Clause := Next (Clause);
26783
26784 Input := Expression (Clause);
26785 Output := First (Choices (Clause));
26786
26787 -- Recognize a clause of the form
26788
26789 -- null => Input
26790
26791 -- where Input is a constituent of a state which was already
26792 -- successfully matched. This clause must be removed because it
26793 -- simply indicates that some of the constituents of the state
26794 -- are not used.
26795
26796 -- Refined_State => (State => (Constit_1, Constit_2))
26797 -- Depends => (Output => State)
26798 -- Refined_Depends => ((Output => Constit_1), -- State matched
26799 -- (null => Constit_2)) -- OK
26800
26801 if Nkind (Output) = N_Null and then Is_Entity_Name (Input) then
26802
26803 -- Handle abstract views generated for limited with clauses
26804
26805 Input_Id := Available_View (Entity_Of (Input));
26806
26807 -- The input must be a constituent of a state
26808
26809 if Ekind (Input_Id) in
26810 E_Abstract_State | E_Constant | E_Variable
26811 and then Present (Encapsulating_State (Input_Id))
26812 then
26813 State_Id := Encapsulating_State (Input_Id);
26814
26815 -- The state must have a non-null visible refinement and be
26816 -- matched in a previous clause.
26817
26818 if Has_Non_Null_Visible_Refinement (State_Id)
26819 and then Contains (Matched_Items, State_Id)
26820 then
26821 Remove (Clause);
26822 end if;
26823 end if;
26824
26825 -- Recognize a clause of the form
26826
26827 -- Output => null
26828
26829 -- where Output is an arbitrary item. This clause must be removed
26830 -- because a null input legitimately matches anything.
26831
26832 elsif Nkind (Input) = N_Null then
26833 Remove (Clause);
26834 end if;
26835
26836 Clause := Next_Clause;
26837 end loop;
26838 end Remove_Extra_Clauses;
26839
26840 --------------------------
26841 -- Report_Extra_Clauses --
26842 --------------------------
26843
26844 procedure Report_Extra_Clauses (Clauses : List_Id) is
26845 Clause : Node_Id;
26846
26847 begin
26848 -- Do not perform this check in an instance because it was already
26849 -- performed successfully in the generic template.
26850
26851 if In_Instance then
26852 null;
26853
26854 elsif Present (Clauses) then
26855 Clause := First (Clauses);
26856 while Present (Clause) loop
26857 SPARK_Msg_N
26858 ("unmatched or extra clause in dependence refinement",
26859 Clause);
26860
26861 Next (Clause);
26862 end loop;
26863 end if;
26864 end Report_Extra_Clauses;
26865
26866 -- Local variables
26867
26868 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
26869 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
26870 Errors : constant Nat := Serious_Errors_Detected;
26871
26872 Clause : Node_Id;
26873 Deps : Node_Id;
26874 Dummy : Boolean;
26875 Refs : Node_Id;
26876
26877 Body_Inputs : Elist_Id := No_Elist;
26878 Body_Outputs : Elist_Id := No_Elist;
26879 -- The inputs and outputs of the subprogram body synthesized from pragma
26880 -- Refined_Depends.
26881
26882 Dependencies : List_Id := No_List;
26883 Depends : Node_Id;
26884 -- The corresponding Depends pragma along with its clauses
26885
26886 Matched_Items : Elist_Id := No_Elist;
26887 -- A list containing the entities of all successfully matched items
26888 -- found in pragma Depends.
26889
26890 Refinements : List_Id := No_List;
26891 -- The clauses of pragma Refined_Depends
26892
26893 Spec_Id : Entity_Id;
26894 -- The entity of the subprogram subject to pragma Refined_Depends
26895
26896 Spec_Inputs : Elist_Id := No_Elist;
26897 Spec_Outputs : Elist_Id := No_Elist;
26898 -- The inputs and outputs of the subprogram spec synthesized from pragma
26899 -- Depends.
26900
26901 States : Elist_Id := No_Elist;
26902 -- A list containing the entities of all states whose constituents
26903 -- appear in pragma Depends.
26904
26905 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
26906
26907 begin
26908 -- Do not analyze the pragma multiple times
26909
26910 if Is_Analyzed_Pragma (N) then
26911 return;
26912 end if;
26913
26914 Spec_Id := Unique_Defining_Entity (Body_Decl);
26915
26916 -- Use the anonymous object as the proper spec when Refined_Depends
26917 -- applies to the body of a single task type. The object carries the
26918 -- proper Chars as well as all non-refined versions of pragmas.
26919
26920 if Is_Single_Concurrent_Type (Spec_Id) then
26921 Spec_Id := Anonymous_Object (Spec_Id);
26922 end if;
26923
26924 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
26925
26926 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
26927 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
26928
26929 if No (Depends) then
26930 SPARK_Msg_NE
26931 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
26932 & "& lacks aspect or pragma Depends"), N, Spec_Id);
26933 goto Leave;
26934 end if;
26935
26936 Deps := Expression (Get_Argument (Depends, Spec_Id));
26937
26938 -- A null dependency relation renders the refinement useless because it
26939 -- cannot possibly mention abstract states with visible refinement. Note
26940 -- that the inverse is not true as states may be refined to null
26941 -- (SPARK RM 7.2.5(2)).
26942
26943 if Nkind (Deps) = N_Null then
26944 SPARK_Msg_NE
26945 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
26946 & "depend on abstract state with visible refinement"), N, Spec_Id);
26947 goto Leave;
26948 end if;
26949
26950 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
26951 -- This ensures that the categorization of all refined dependency items
26952 -- is consistent with their role.
26953
26954 Analyze_Depends_In_Decl_Part (N);
26955
26956 -- Do not match dependencies against refinements if Refined_Depends is
26957 -- illegal to avoid emitting misleading error.
26958
26959 if Serious_Errors_Detected = Errors then
26960
26961 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
26962 -- the inputs and outputs of the subprogram spec and body to verify
26963 -- the use of states with visible refinement and their constituents.
26964
26965 if No (Get_Pragma (Spec_Id, Pragma_Global))
26966 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
26967 then
26968 Collect_Subprogram_Inputs_Outputs
26969 (Subp_Id => Spec_Id,
26970 Synthesize => True,
26971 Subp_Inputs => Spec_Inputs,
26972 Subp_Outputs => Spec_Outputs,
26973 Global_Seen => Dummy);
26974
26975 Collect_Subprogram_Inputs_Outputs
26976 (Subp_Id => Body_Id,
26977 Synthesize => True,
26978 Subp_Inputs => Body_Inputs,
26979 Subp_Outputs => Body_Outputs,
26980 Global_Seen => Dummy);
26981
26982 -- For an output state with a visible refinement, ensure that all
26983 -- constituents appear as outputs in the dependency refinement.
26984
26985 Check_Output_States
26986 (Spec_Inputs => Spec_Inputs,
26987 Spec_Outputs => Spec_Outputs,
26988 Body_Inputs => Body_Inputs,
26989 Body_Outputs => Body_Outputs);
26990 end if;
26991
26992 -- Multiple dependency clauses appear as component associations of an
26993 -- aggregate. Note that the clauses are copied because the algorithm
26994 -- modifies them and this should not be visible in Depends.
26995
26996 pragma Assert (Nkind (Deps) = N_Aggregate);
26997 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
26998 Normalize_Clauses (Dependencies);
26999
27000 -- Gather all states which appear in Depends
27001
27002 States := Collect_States (Dependencies);
27003
27004 Refs := Expression (Get_Argument (N, Spec_Id));
27005
27006 if Nkind (Refs) = N_Null then
27007 Refinements := No_List;
27008
27009 -- Multiple dependency clauses appear as component associations of an
27010 -- aggregate. Note that the clauses are copied because the algorithm
27011 -- modifies them and this should not be visible in Refined_Depends.
27012
27013 else pragma Assert (Nkind (Refs) = N_Aggregate);
27014 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
27015 Normalize_Clauses (Refinements);
27016 end if;
27017
27018 -- At this point the clauses of pragmas Depends and Refined_Depends
27019 -- have been normalized into simple dependencies between one output
27020 -- and one input. Examine all clauses of pragma Depends looking for
27021 -- matching clauses in pragma Refined_Depends.
27022
27023 Clause := First (Dependencies);
27024 while Present (Clause) loop
27025 Check_Dependency_Clause
27026 (Spec_Id => Spec_Id,
27027 Dep_Clause => Clause,
27028 Dep_States => States,
27029 Refinements => Refinements,
27030 Matched_Items => Matched_Items);
27031
27032 Next (Clause);
27033 end loop;
27034
27035 -- Pragma Refined_Depends may contain multiple clarification clauses
27036 -- which indicate that certain constituents do not influence the data
27037 -- flow in any way. Such clauses must be removed as long as the state
27038 -- has been matched, otherwise they will be incorrectly flagged as
27039 -- unmatched.
27040
27041 -- Refined_State => (State => (Constit_1, Constit_2))
27042 -- Depends => (Output => State)
27043 -- Refined_Depends => ((Output => Constit_1), -- State matched
27044 -- (null => Constit_2)) -- must be removed
27045
27046 Remove_Extra_Clauses (Refinements, Matched_Items);
27047
27048 if Serious_Errors_Detected = Errors then
27049 Report_Extra_Clauses (Refinements);
27050 end if;
27051 end if;
27052
27053 <<Leave>>
27054 Set_Is_Analyzed_Pragma (N);
27055 end Analyze_Refined_Depends_In_Decl_Part;
27056
27057 -----------------------------------------
27058 -- Analyze_Refined_Global_In_Decl_Part --
27059 -----------------------------------------
27060
27061 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
27062 Global : Node_Id;
27063 -- The corresponding Global pragma
27064
27065 Has_In_State : Boolean := False;
27066 Has_In_Out_State : Boolean := False;
27067 Has_Out_State : Boolean := False;
27068 Has_Proof_In_State : Boolean := False;
27069 -- These flags are set when the corresponding Global pragma has a state
27070 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
27071 -- refinement.
27072
27073 Has_Null_State : Boolean := False;
27074 -- This flag is set when the corresponding Global pragma has at least
27075 -- one state with a null refinement.
27076
27077 In_Constits : Elist_Id := No_Elist;
27078 In_Out_Constits : Elist_Id := No_Elist;
27079 Out_Constits : Elist_Id := No_Elist;
27080 Proof_In_Constits : Elist_Id := No_Elist;
27081 -- These lists contain the entities of all Input, In_Out, Output and
27082 -- Proof_In constituents that appear in Refined_Global and participate
27083 -- in state refinement.
27084
27085 In_Items : Elist_Id := No_Elist;
27086 In_Out_Items : Elist_Id := No_Elist;
27087 Out_Items : Elist_Id := No_Elist;
27088 Proof_In_Items : Elist_Id := No_Elist;
27089 -- These lists contain the entities of all Input, In_Out, Output and
27090 -- Proof_In items defined in the corresponding Global pragma.
27091
27092 Repeat_Items : Elist_Id := No_Elist;
27093 -- A list of all global items without full visible refinement found
27094 -- in pragma Global. These states should be repeated in the global
27095 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
27096 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
27097
27098 Spec_Id : Entity_Id;
27099 -- The entity of the subprogram subject to pragma Refined_Global
27100
27101 States : Elist_Id := No_Elist;
27102 -- A list of all states with full or partial visible refinement found in
27103 -- pragma Global.
27104
27105 procedure Check_In_Out_States;
27106 -- Determine whether the corresponding Global pragma mentions In_Out
27107 -- states with visible refinement and if so, ensure that one of the
27108 -- following completions apply to the constituents of the state:
27109 -- 1) there is at least one constituent of mode In_Out
27110 -- 2) there is at least one Input and one Output constituent
27111 -- 3) not all constituents are present and one of them is of mode
27112 -- Output.
27113 -- This routine may remove elements from In_Constits, In_Out_Constits,
27114 -- Out_Constits and Proof_In_Constits.
27115
27116 procedure Check_Input_States;
27117 -- Determine whether the corresponding Global pragma mentions Input
27118 -- states with visible refinement and if so, ensure that at least one of
27119 -- its constituents appears as an Input item in Refined_Global.
27120 -- This routine may remove elements from In_Constits, In_Out_Constits,
27121 -- Out_Constits and Proof_In_Constits.
27122
27123 procedure Check_Output_States;
27124 -- Determine whether the corresponding Global pragma mentions Output
27125 -- states with visible refinement and if so, ensure that all of its
27126 -- constituents appear as Output items in Refined_Global.
27127 -- This routine may remove elements from In_Constits, In_Out_Constits,
27128 -- Out_Constits and Proof_In_Constits.
27129
27130 procedure Check_Proof_In_States;
27131 -- Determine whether the corresponding Global pragma mentions Proof_In
27132 -- states with visible refinement and if so, ensure that at least one of
27133 -- its constituents appears as a Proof_In item in Refined_Global.
27134 -- This routine may remove elements from In_Constits, In_Out_Constits,
27135 -- Out_Constits and Proof_In_Constits.
27136
27137 procedure Check_Refined_Global_List
27138 (List : Node_Id;
27139 Global_Mode : Name_Id := Name_Input);
27140 -- Verify the legality of a single global list declaration. Global_Mode
27141 -- denotes the current mode in effect.
27142
27143 procedure Collect_Global_Items
27144 (List : Node_Id;
27145 Mode : Name_Id := Name_Input);
27146 -- Gather all Input, In_Out, Output and Proof_In items from node List
27147 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
27148 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
27149 -- and Has_Proof_In_State are set when there is at least one abstract
27150 -- state with full or partial visible refinement available in the
27151 -- corresponding mode. Flag Has_Null_State is set when at least state
27152 -- has a null refinement. Mode denotes the current global mode in
27153 -- effect.
27154
27155 function Present_Then_Remove
27156 (List : Elist_Id;
27157 Item : Entity_Id) return Boolean;
27158 -- Search List for a particular entity Item. If Item has been found,
27159 -- remove it from List. This routine is used to strip lists In_Constits,
27160 -- In_Out_Constits and Out_Constits of valid constituents.
27161
27162 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id);
27163 -- Same as function Present_Then_Remove, but do not report the presence
27164 -- of Item in List.
27165
27166 procedure Report_Extra_Constituents;
27167 -- Emit an error for each constituent found in lists In_Constits,
27168 -- In_Out_Constits and Out_Constits.
27169
27170 procedure Report_Missing_Items;
27171 -- Emit an error for each global item not repeated found in list
27172 -- Repeat_Items.
27173
27174 -------------------------
27175 -- Check_In_Out_States --
27176 -------------------------
27177
27178 procedure Check_In_Out_States is
27179 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27180 -- Determine whether one of the following coverage scenarios is in
27181 -- effect:
27182 -- 1) there is at least one constituent of mode In_Out or Output
27183 -- 2) there is at least one pair of constituents with modes Input
27184 -- and Output, or Proof_In and Output.
27185 -- 3) there is at least one constituent of mode Output and not all
27186 -- constituents are present.
27187 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
27188
27189 -----------------------------
27190 -- Check_Constituent_Usage --
27191 -----------------------------
27192
27193 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27194 Constits : constant Elist_Id :=
27195 Partial_Refinement_Constituents (State_Id);
27196 Constit_Elmt : Elmt_Id;
27197 Constit_Id : Entity_Id;
27198 Has_Missing : Boolean := False;
27199 In_Out_Seen : Boolean := False;
27200 Input_Seen : Boolean := False;
27201 Output_Seen : Boolean := False;
27202 Proof_In_Seen : Boolean := False;
27203
27204 begin
27205 -- Process all the constituents of the state and note their modes
27206 -- within the global refinement.
27207
27208 if Present (Constits) then
27209 Constit_Elmt := First_Elmt (Constits);
27210 while Present (Constit_Elmt) loop
27211 Constit_Id := Node (Constit_Elmt);
27212
27213 if Present_Then_Remove (In_Constits, Constit_Id) then
27214 Input_Seen := True;
27215
27216 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
27217 In_Out_Seen := True;
27218
27219 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
27220 Output_Seen := True;
27221
27222 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
27223 then
27224 Proof_In_Seen := True;
27225
27226 else
27227 Has_Missing := True;
27228 end if;
27229
27230 Next_Elmt (Constit_Elmt);
27231 end loop;
27232 end if;
27233
27234 -- An In_Out constituent is a valid completion
27235
27236 if In_Out_Seen then
27237 null;
27238
27239 -- A pair of one Input/Proof_In and one Output constituent is a
27240 -- valid completion.
27241
27242 elsif (Input_Seen or Proof_In_Seen) and Output_Seen then
27243 null;
27244
27245 elsif Output_Seen then
27246
27247 -- A single Output constituent is a valid completion only when
27248 -- some of the other constituents are missing.
27249
27250 if Has_Missing then
27251 null;
27252
27253 -- Otherwise all constituents are of mode Output
27254
27255 else
27256 SPARK_Msg_NE
27257 ("global refinement of state & must include at least one "
27258 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
27259 N, State_Id);
27260 end if;
27261
27262 -- The state lacks a completion. When full refinement is visible,
27263 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
27264 -- refinement is visible, emit an error if the abstract state
27265 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
27266 -- both are utilized, Check_State_And_Constituent_Use. will issue
27267 -- the error.
27268
27269 elsif not Input_Seen
27270 and then not In_Out_Seen
27271 and then not Output_Seen
27272 and then not Proof_In_Seen
27273 then
27274 if Has_Visible_Refinement (State_Id)
27275 or else Contains (Repeat_Items, State_Id)
27276 then
27277 SPARK_Msg_NE
27278 ("missing global refinement of state &", N, State_Id);
27279 end if;
27280
27281 -- Otherwise the state has a malformed completion where at least
27282 -- one of the constituents has a different mode.
27283
27284 else
27285 SPARK_Msg_NE
27286 ("global refinement of state & redefines the mode of its "
27287 & "constituents", N, State_Id);
27288 end if;
27289 end Check_Constituent_Usage;
27290
27291 -- Local variables
27292
27293 Item_Elmt : Elmt_Id;
27294 Item_Id : Entity_Id;
27295
27296 -- Start of processing for Check_In_Out_States
27297
27298 begin
27299 -- Do not perform this check in an instance because it was already
27300 -- performed successfully in the generic template.
27301
27302 if In_Instance then
27303 null;
27304
27305 -- Inspect the In_Out items of the corresponding Global pragma
27306 -- looking for a state with a visible refinement.
27307
27308 elsif Has_In_Out_State and then Present (In_Out_Items) then
27309 Item_Elmt := First_Elmt (In_Out_Items);
27310 while Present (Item_Elmt) loop
27311 Item_Id := Node (Item_Elmt);
27312
27313 -- Ensure that one of the three coverage variants is satisfied
27314
27315 if Ekind (Item_Id) = E_Abstract_State
27316 and then Has_Non_Null_Visible_Refinement (Item_Id)
27317 then
27318 Check_Constituent_Usage (Item_Id);
27319 end if;
27320
27321 Next_Elmt (Item_Elmt);
27322 end loop;
27323 end if;
27324 end Check_In_Out_States;
27325
27326 ------------------------
27327 -- Check_Input_States --
27328 ------------------------
27329
27330 procedure Check_Input_States is
27331 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27332 -- Determine whether at least one constituent of state State_Id with
27333 -- full or partial visible refinement is used and has mode Input.
27334 -- Ensure that the remaining constituents do not have In_Out or
27335 -- Output modes. Emit an error if this is not the case
27336 -- (SPARK RM 7.2.4(5)).
27337
27338 -----------------------------
27339 -- Check_Constituent_Usage --
27340 -----------------------------
27341
27342 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27343 Constits : constant Elist_Id :=
27344 Partial_Refinement_Constituents (State_Id);
27345 Constit_Elmt : Elmt_Id;
27346 Constit_Id : Entity_Id;
27347 In_Seen : Boolean := False;
27348
27349 begin
27350 if Present (Constits) then
27351 Constit_Elmt := First_Elmt (Constits);
27352 while Present (Constit_Elmt) loop
27353 Constit_Id := Node (Constit_Elmt);
27354
27355 -- At least one of the constituents appears as an Input
27356
27357 if Present_Then_Remove (In_Constits, Constit_Id) then
27358 In_Seen := True;
27359
27360 -- A Proof_In constituent can refine an Input state as long
27361 -- as there is at least one Input constituent present.
27362
27363 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
27364 then
27365 null;
27366
27367 -- The constituent appears in the global refinement, but has
27368 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
27369
27370 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
27371 or else Present_Then_Remove (Out_Constits, Constit_Id)
27372 then
27373 Error_Msg_Name_1 := Chars (State_Id);
27374 SPARK_Msg_NE
27375 ("constituent & of state % must have mode `Input` in "
27376 & "global refinement", N, Constit_Id);
27377 end if;
27378
27379 Next_Elmt (Constit_Elmt);
27380 end loop;
27381 end if;
27382
27383 -- Not one of the constituents appeared as Input. Always emit an
27384 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
27385 -- When only partial refinement is visible, emit an error if the
27386 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27387 -- the case where both are utilized, an error will be issued in
27388 -- Check_State_And_Constituent_Use.
27389
27390 if not In_Seen
27391 and then (Has_Visible_Refinement (State_Id)
27392 or else Contains (Repeat_Items, State_Id))
27393 then
27394 SPARK_Msg_NE
27395 ("global refinement of state & must include at least one "
27396 & "constituent of mode `Input`", N, State_Id);
27397 end if;
27398 end Check_Constituent_Usage;
27399
27400 -- Local variables
27401
27402 Item_Elmt : Elmt_Id;
27403 Item_Id : Entity_Id;
27404
27405 -- Start of processing for Check_Input_States
27406
27407 begin
27408 -- Do not perform this check in an instance because it was already
27409 -- performed successfully in the generic template.
27410
27411 if In_Instance then
27412 null;
27413
27414 -- Inspect the Input items of the corresponding Global pragma looking
27415 -- for a state with a visible refinement.
27416
27417 elsif Has_In_State and then Present (In_Items) then
27418 Item_Elmt := First_Elmt (In_Items);
27419 while Present (Item_Elmt) loop
27420 Item_Id := Node (Item_Elmt);
27421
27422 -- When full refinement is visible, ensure that at least one of
27423 -- the constituents is utilized and is of mode Input. When only
27424 -- partial refinement is visible, ensure that either one of
27425 -- the constituents is utilized and is of mode Input, or the
27426 -- abstract state is repeated and no constituent is utilized.
27427
27428 if Ekind (Item_Id) = E_Abstract_State
27429 and then Has_Non_Null_Visible_Refinement (Item_Id)
27430 then
27431 Check_Constituent_Usage (Item_Id);
27432 end if;
27433
27434 Next_Elmt (Item_Elmt);
27435 end loop;
27436 end if;
27437 end Check_Input_States;
27438
27439 -------------------------
27440 -- Check_Output_States --
27441 -------------------------
27442
27443 procedure Check_Output_States is
27444 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27445 -- Determine whether all constituents of state State_Id with full
27446 -- visible refinement are used and have mode Output. Emit an error
27447 -- if this is not the case (SPARK RM 7.2.4(5)).
27448
27449 -----------------------------
27450 -- Check_Constituent_Usage --
27451 -----------------------------
27452
27453 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27454 Constits : constant Elist_Id :=
27455 Partial_Refinement_Constituents (State_Id);
27456 Only_Partial : constant Boolean :=
27457 not Has_Visible_Refinement (State_Id);
27458 Constit_Elmt : Elmt_Id;
27459 Constit_Id : Entity_Id;
27460 Posted : Boolean := False;
27461
27462 begin
27463 if Present (Constits) then
27464 Constit_Elmt := First_Elmt (Constits);
27465 while Present (Constit_Elmt) loop
27466 Constit_Id := Node (Constit_Elmt);
27467
27468 -- Issue an error when a constituent of State_Id is utilized
27469 -- and State_Id has only partial visible refinement
27470 -- (SPARK RM 7.2.4(3d)).
27471
27472 if Only_Partial then
27473 if Present_Then_Remove (Out_Constits, Constit_Id)
27474 or else Present_Then_Remove (In_Constits, Constit_Id)
27475 or else
27476 Present_Then_Remove (In_Out_Constits, Constit_Id)
27477 or else
27478 Present_Then_Remove (Proof_In_Constits, Constit_Id)
27479 then
27480 Error_Msg_Name_1 := Chars (State_Id);
27481 SPARK_Msg_NE
27482 ("constituent & of state % cannot be used in global "
27483 & "refinement", N, Constit_Id);
27484 Error_Msg_Name_1 := Chars (State_Id);
27485 SPARK_Msg_N ("\use state % instead", N);
27486 end if;
27487
27488 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
27489 null;
27490
27491 -- The constituent appears in the global refinement, but has
27492 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
27493
27494 elsif Present_Then_Remove (In_Constits, Constit_Id)
27495 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27496 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
27497 then
27498 Error_Msg_Name_1 := Chars (State_Id);
27499 SPARK_Msg_NE
27500 ("constituent & of state % must have mode `Output` in "
27501 & "global refinement", N, Constit_Id);
27502
27503 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
27504
27505 else
27506 if not Posted then
27507 Posted := True;
27508 SPARK_Msg_NE
27509 ("`Output` state & must be replaced by all its "
27510 & "constituents in global refinement", N, State_Id);
27511 end if;
27512
27513 SPARK_Msg_NE
27514 ("\constituent & is missing in output list",
27515 N, Constit_Id);
27516 end if;
27517
27518 Next_Elmt (Constit_Elmt);
27519 end loop;
27520 end if;
27521 end Check_Constituent_Usage;
27522
27523 -- Local variables
27524
27525 Item_Elmt : Elmt_Id;
27526 Item_Id : Entity_Id;
27527
27528 -- Start of processing for Check_Output_States
27529
27530 begin
27531 -- Do not perform this check in an instance because it was already
27532 -- performed successfully in the generic template.
27533
27534 if In_Instance then
27535 null;
27536
27537 -- Inspect the Output items of the corresponding Global pragma
27538 -- looking for a state with a visible refinement.
27539
27540 elsif Has_Out_State and then Present (Out_Items) then
27541 Item_Elmt := First_Elmt (Out_Items);
27542 while Present (Item_Elmt) loop
27543 Item_Id := Node (Item_Elmt);
27544
27545 -- When full refinement is visible, ensure that all of the
27546 -- constituents are utilized and they have mode Output. When
27547 -- only partial refinement is visible, ensure that no
27548 -- constituent is utilized.
27549
27550 if Ekind (Item_Id) = E_Abstract_State
27551 and then Has_Non_Null_Visible_Refinement (Item_Id)
27552 then
27553 Check_Constituent_Usage (Item_Id);
27554 end if;
27555
27556 Next_Elmt (Item_Elmt);
27557 end loop;
27558 end if;
27559 end Check_Output_States;
27560
27561 ---------------------------
27562 -- Check_Proof_In_States --
27563 ---------------------------
27564
27565 procedure Check_Proof_In_States is
27566 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27567 -- Determine whether at least one constituent of state State_Id with
27568 -- full or partial visible refinement is used and has mode Proof_In.
27569 -- Ensure that the remaining constituents do not have Input, In_Out,
27570 -- or Output modes. Emit an error if this is not the case
27571 -- (SPARK RM 7.2.4(5)).
27572
27573 -----------------------------
27574 -- Check_Constituent_Usage --
27575 -----------------------------
27576
27577 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27578 Constits : constant Elist_Id :=
27579 Partial_Refinement_Constituents (State_Id);
27580 Constit_Elmt : Elmt_Id;
27581 Constit_Id : Entity_Id;
27582 Proof_In_Seen : Boolean := False;
27583
27584 begin
27585 if Present (Constits) then
27586 Constit_Elmt := First_Elmt (Constits);
27587 while Present (Constit_Elmt) loop
27588 Constit_Id := Node (Constit_Elmt);
27589
27590 -- At least one of the constituents appears as Proof_In
27591
27592 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
27593 Proof_In_Seen := True;
27594
27595 -- The constituent appears in the global refinement, but has
27596 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
27597
27598 elsif Present_Then_Remove (In_Constits, Constit_Id)
27599 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27600 or else Present_Then_Remove (Out_Constits, Constit_Id)
27601 then
27602 Error_Msg_Name_1 := Chars (State_Id);
27603 SPARK_Msg_NE
27604 ("constituent & of state % must have mode `Proof_In` "
27605 & "in global refinement", N, Constit_Id);
27606 end if;
27607
27608 Next_Elmt (Constit_Elmt);
27609 end loop;
27610 end if;
27611
27612 -- Not one of the constituents appeared as Proof_In. Always emit
27613 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
27614 -- When only partial refinement is visible, emit an error if the
27615 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27616 -- the case where both are utilized, an error will be issued by
27617 -- Check_State_And_Constituent_Use.
27618
27619 if not Proof_In_Seen
27620 and then (Has_Visible_Refinement (State_Id)
27621 or else Contains (Repeat_Items, State_Id))
27622 then
27623 SPARK_Msg_NE
27624 ("global refinement of state & must include at least one "
27625 & "constituent of mode `Proof_In`", N, State_Id);
27626 end if;
27627 end Check_Constituent_Usage;
27628
27629 -- Local variables
27630
27631 Item_Elmt : Elmt_Id;
27632 Item_Id : Entity_Id;
27633
27634 -- Start of processing for Check_Proof_In_States
27635
27636 begin
27637 -- Do not perform this check in an instance because it was already
27638 -- performed successfully in the generic template.
27639
27640 if In_Instance then
27641 null;
27642
27643 -- Inspect the Proof_In items of the corresponding Global pragma
27644 -- looking for a state with a visible refinement.
27645
27646 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
27647 Item_Elmt := First_Elmt (Proof_In_Items);
27648 while Present (Item_Elmt) loop
27649 Item_Id := Node (Item_Elmt);
27650
27651 -- Ensure that at least one of the constituents is utilized
27652 -- and is of mode Proof_In. When only partial refinement is
27653 -- visible, ensure that either one of the constituents is
27654 -- utilized and is of mode Proof_In, or the abstract state
27655 -- is repeated and no constituent is utilized.
27656
27657 if Ekind (Item_Id) = E_Abstract_State
27658 and then Has_Non_Null_Visible_Refinement (Item_Id)
27659 then
27660 Check_Constituent_Usage (Item_Id);
27661 end if;
27662
27663 Next_Elmt (Item_Elmt);
27664 end loop;
27665 end if;
27666 end Check_Proof_In_States;
27667
27668 -------------------------------
27669 -- Check_Refined_Global_List --
27670 -------------------------------
27671
27672 procedure Check_Refined_Global_List
27673 (List : Node_Id;
27674 Global_Mode : Name_Id := Name_Input)
27675 is
27676 procedure Check_Refined_Global_Item
27677 (Item : Node_Id;
27678 Global_Mode : Name_Id);
27679 -- Verify the legality of a single global item declaration. Parameter
27680 -- Global_Mode denotes the current mode in effect.
27681
27682 -------------------------------
27683 -- Check_Refined_Global_Item --
27684 -------------------------------
27685
27686 procedure Check_Refined_Global_Item
27687 (Item : Node_Id;
27688 Global_Mode : Name_Id)
27689 is
27690 Item_Id : constant Entity_Id := Entity_Of (Item);
27691
27692 procedure Inconsistent_Mode_Error (Expect : Name_Id);
27693 -- Issue a common error message for all mode mismatches. Expect
27694 -- denotes the expected mode.
27695
27696 -----------------------------
27697 -- Inconsistent_Mode_Error --
27698 -----------------------------
27699
27700 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
27701 begin
27702 SPARK_Msg_NE
27703 ("global item & has inconsistent modes", Item, Item_Id);
27704
27705 Error_Msg_Name_1 := Global_Mode;
27706 Error_Msg_Name_2 := Expect;
27707 SPARK_Msg_N ("\expected mode %, found mode %", Item);
27708 end Inconsistent_Mode_Error;
27709
27710 -- Local variables
27711
27712 Enc_State : Entity_Id := Empty;
27713 -- Encapsulating state for constituent, Empty otherwise
27714
27715 -- Start of processing for Check_Refined_Global_Item
27716
27717 begin
27718 if Ekind (Item_Id) in E_Abstract_State | E_Constant | E_Variable
27719 then
27720 Enc_State := Find_Encapsulating_State (States, Item_Id);
27721 end if;
27722
27723 -- When the state or object acts as a constituent of another
27724 -- state with a visible refinement, collect it for the state
27725 -- completeness checks performed later on. Note that the item
27726 -- acts as a constituent only when the encapsulating state is
27727 -- present in pragma Global.
27728
27729 if Present (Enc_State)
27730 and then (Has_Visible_Refinement (Enc_State)
27731 or else Has_Partial_Visible_Refinement (Enc_State))
27732 and then Contains (States, Enc_State)
27733 then
27734 -- If the state has only partial visible refinement, remove it
27735 -- from the list of items that should be repeated from pragma
27736 -- Global.
27737
27738 if not Has_Visible_Refinement (Enc_State) then
27739 Present_Then_Remove (Repeat_Items, Enc_State);
27740 end if;
27741
27742 if Global_Mode = Name_Input then
27743 Append_New_Elmt (Item_Id, In_Constits);
27744
27745 elsif Global_Mode = Name_In_Out then
27746 Append_New_Elmt (Item_Id, In_Out_Constits);
27747
27748 elsif Global_Mode = Name_Output then
27749 Append_New_Elmt (Item_Id, Out_Constits);
27750
27751 elsif Global_Mode = Name_Proof_In then
27752 Append_New_Elmt (Item_Id, Proof_In_Constits);
27753 end if;
27754
27755 -- When not a constituent, ensure that both occurrences of the
27756 -- item in pragmas Global and Refined_Global match. Also remove
27757 -- it when present from the list of items that should be repeated
27758 -- from pragma Global.
27759
27760 else
27761 Present_Then_Remove (Repeat_Items, Item_Id);
27762
27763 if Contains (In_Items, Item_Id) then
27764 if Global_Mode /= Name_Input then
27765 Inconsistent_Mode_Error (Name_Input);
27766 end if;
27767
27768 elsif Contains (In_Out_Items, Item_Id) then
27769 if Global_Mode /= Name_In_Out then
27770 Inconsistent_Mode_Error (Name_In_Out);
27771 end if;
27772
27773 elsif Contains (Out_Items, Item_Id) then
27774 if Global_Mode /= Name_Output then
27775 Inconsistent_Mode_Error (Name_Output);
27776 end if;
27777
27778 elsif Contains (Proof_In_Items, Item_Id) then
27779 null;
27780
27781 -- The item does not appear in the corresponding Global pragma,
27782 -- it must be an extra (SPARK RM 7.2.4(3)).
27783
27784 else
27785 pragma Assert (Present (Global));
27786 Error_Msg_Sloc := Sloc (Global);
27787 SPARK_Msg_NE
27788 ("extra global item & does not refine or repeat any "
27789 & "global item #", Item, Item_Id);
27790 end if;
27791 end if;
27792 end Check_Refined_Global_Item;
27793
27794 -- Local variables
27795
27796 Item : Node_Id;
27797
27798 -- Start of processing for Check_Refined_Global_List
27799
27800 begin
27801 -- Do not perform this check in an instance because it was already
27802 -- performed successfully in the generic template.
27803
27804 if In_Instance then
27805 null;
27806
27807 elsif Nkind (List) = N_Null then
27808 null;
27809
27810 -- Single global item declaration
27811
27812 elsif Nkind (List) in N_Expanded_Name
27813 | N_Identifier
27814 | N_Selected_Component
27815 then
27816 Check_Refined_Global_Item (List, Global_Mode);
27817
27818 -- Simple global list or moded global list declaration
27819
27820 elsif Nkind (List) = N_Aggregate then
27821
27822 -- The declaration of a simple global list appear as a collection
27823 -- of expressions.
27824
27825 if Present (Expressions (List)) then
27826 Item := First (Expressions (List));
27827 while Present (Item) loop
27828 Check_Refined_Global_Item (Item, Global_Mode);
27829 Next (Item);
27830 end loop;
27831
27832 -- The declaration of a moded global list appears as a collection
27833 -- of component associations where individual choices denote
27834 -- modes.
27835
27836 elsif Present (Component_Associations (List)) then
27837 Item := First (Component_Associations (List));
27838 while Present (Item) loop
27839 Check_Refined_Global_List
27840 (List => Expression (Item),
27841 Global_Mode => Chars (First (Choices (Item))));
27842
27843 Next (Item);
27844 end loop;
27845
27846 -- Invalid tree
27847
27848 else
27849 raise Program_Error;
27850 end if;
27851
27852 -- Invalid list
27853
27854 else
27855 raise Program_Error;
27856 end if;
27857 end Check_Refined_Global_List;
27858
27859 --------------------------
27860 -- Collect_Global_Items --
27861 --------------------------
27862
27863 procedure Collect_Global_Items
27864 (List : Node_Id;
27865 Mode : Name_Id := Name_Input)
27866 is
27867 procedure Collect_Global_Item
27868 (Item : Node_Id;
27869 Item_Mode : Name_Id);
27870 -- Add a single item to the appropriate list. Item_Mode denotes the
27871 -- current mode in effect.
27872
27873 -------------------------
27874 -- Collect_Global_Item --
27875 -------------------------
27876
27877 procedure Collect_Global_Item
27878 (Item : Node_Id;
27879 Item_Mode : Name_Id)
27880 is
27881 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
27882 -- The above handles abstract views of variables and states built
27883 -- for limited with clauses.
27884
27885 begin
27886 -- Signal that the global list contains at least one abstract
27887 -- state with a visible refinement. Note that the refinement may
27888 -- be null in which case there are no constituents.
27889
27890 if Ekind (Item_Id) = E_Abstract_State then
27891 if Has_Null_Visible_Refinement (Item_Id) then
27892 Has_Null_State := True;
27893
27894 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
27895 Append_New_Elmt (Item_Id, States);
27896
27897 if Item_Mode = Name_Input then
27898 Has_In_State := True;
27899 elsif Item_Mode = Name_In_Out then
27900 Has_In_Out_State := True;
27901 elsif Item_Mode = Name_Output then
27902 Has_Out_State := True;
27903 elsif Item_Mode = Name_Proof_In then
27904 Has_Proof_In_State := True;
27905 end if;
27906 end if;
27907 end if;
27908
27909 -- Record global items without full visible refinement found in
27910 -- pragma Global which should be repeated in the global refinement
27911 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
27912
27913 if Ekind (Item_Id) /= E_Abstract_State
27914 or else not Has_Visible_Refinement (Item_Id)
27915 then
27916 Append_New_Elmt (Item_Id, Repeat_Items);
27917 end if;
27918
27919 -- Add the item to the proper list
27920
27921 if Item_Mode = Name_Input then
27922 Append_New_Elmt (Item_Id, In_Items);
27923 elsif Item_Mode = Name_In_Out then
27924 Append_New_Elmt (Item_Id, In_Out_Items);
27925 elsif Item_Mode = Name_Output then
27926 Append_New_Elmt (Item_Id, Out_Items);
27927 elsif Item_Mode = Name_Proof_In then
27928 Append_New_Elmt (Item_Id, Proof_In_Items);
27929 end if;
27930 end Collect_Global_Item;
27931
27932 -- Local variables
27933
27934 Item : Node_Id;
27935
27936 -- Start of processing for Collect_Global_Items
27937
27938 begin
27939 if Nkind (List) = N_Null then
27940 null;
27941
27942 -- Single global item declaration
27943
27944 elsif Nkind (List) in N_Expanded_Name
27945 | N_Identifier
27946 | N_Selected_Component
27947 then
27948 Collect_Global_Item (List, Mode);
27949
27950 -- Single global list or moded global list declaration
27951
27952 elsif Nkind (List) = N_Aggregate then
27953
27954 -- The declaration of a simple global list appear as a collection
27955 -- of expressions.
27956
27957 if Present (Expressions (List)) then
27958 Item := First (Expressions (List));
27959 while Present (Item) loop
27960 Collect_Global_Item (Item, Mode);
27961 Next (Item);
27962 end loop;
27963
27964 -- The declaration of a moded global list appears as a collection
27965 -- of component associations where individual choices denote mode.
27966
27967 elsif Present (Component_Associations (List)) then
27968 Item := First (Component_Associations (List));
27969 while Present (Item) loop
27970 Collect_Global_Items
27971 (List => Expression (Item),
27972 Mode => Chars (First (Choices (Item))));
27973
27974 Next (Item);
27975 end loop;
27976
27977 -- Invalid tree
27978
27979 else
27980 raise Program_Error;
27981 end if;
27982
27983 -- To accommodate partial decoration of disabled SPARK features, this
27984 -- routine may be called with illegal input. If this is the case, do
27985 -- not raise Program_Error.
27986
27987 else
27988 null;
27989 end if;
27990 end Collect_Global_Items;
27991
27992 -------------------------
27993 -- Present_Then_Remove --
27994 -------------------------
27995
27996 function Present_Then_Remove
27997 (List : Elist_Id;
27998 Item : Entity_Id) return Boolean
27999 is
28000 Elmt : Elmt_Id;
28001
28002 begin
28003 if Present (List) then
28004 Elmt := First_Elmt (List);
28005 while Present (Elmt) loop
28006 if Node (Elmt) = Item then
28007 Remove_Elmt (List, Elmt);
28008 return True;
28009 end if;
28010
28011 Next_Elmt (Elmt);
28012 end loop;
28013 end if;
28014
28015 return False;
28016 end Present_Then_Remove;
28017
28018 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id) is
28019 Ignore : Boolean;
28020 begin
28021 Ignore := Present_Then_Remove (List, Item);
28022 end Present_Then_Remove;
28023
28024 -------------------------------
28025 -- Report_Extra_Constituents --
28026 -------------------------------
28027
28028 procedure Report_Extra_Constituents is
28029 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
28030 -- Emit an error for every element of List
28031
28032 ---------------------------------------
28033 -- Report_Extra_Constituents_In_List --
28034 ---------------------------------------
28035
28036 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
28037 Constit_Elmt : Elmt_Id;
28038
28039 begin
28040 if Present (List) then
28041 Constit_Elmt := First_Elmt (List);
28042 while Present (Constit_Elmt) loop
28043 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
28044 Next_Elmt (Constit_Elmt);
28045 end loop;
28046 end if;
28047 end Report_Extra_Constituents_In_List;
28048
28049 -- Start of processing for Report_Extra_Constituents
28050
28051 begin
28052 -- Do not perform this check in an instance because it was already
28053 -- performed successfully in the generic template.
28054
28055 if In_Instance then
28056 null;
28057
28058 else
28059 Report_Extra_Constituents_In_List (In_Constits);
28060 Report_Extra_Constituents_In_List (In_Out_Constits);
28061 Report_Extra_Constituents_In_List (Out_Constits);
28062 Report_Extra_Constituents_In_List (Proof_In_Constits);
28063 end if;
28064 end Report_Extra_Constituents;
28065
28066 --------------------------
28067 -- Report_Missing_Items --
28068 --------------------------
28069
28070 procedure Report_Missing_Items is
28071 Item_Elmt : Elmt_Id;
28072 Item_Id : Entity_Id;
28073
28074 begin
28075 -- Do not perform this check in an instance because it was already
28076 -- performed successfully in the generic template.
28077
28078 if In_Instance then
28079 null;
28080
28081 else
28082 if Present (Repeat_Items) then
28083 Item_Elmt := First_Elmt (Repeat_Items);
28084 while Present (Item_Elmt) loop
28085 Item_Id := Node (Item_Elmt);
28086 SPARK_Msg_NE ("missing global item &", N, Item_Id);
28087 Next_Elmt (Item_Elmt);
28088 end loop;
28089 end if;
28090 end if;
28091 end Report_Missing_Items;
28092
28093 -- Local variables
28094
28095 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
28096 Errors : constant Nat := Serious_Errors_Detected;
28097 Items : Node_Id;
28098 No_Constit : Boolean;
28099
28100 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
28101
28102 begin
28103 -- Do not analyze the pragma multiple times
28104
28105 if Is_Analyzed_Pragma (N) then
28106 return;
28107 end if;
28108
28109 Spec_Id := Unique_Defining_Entity (Body_Decl);
28110
28111 -- Use the anonymous object as the proper spec when Refined_Global
28112 -- applies to the body of a single task type. The object carries the
28113 -- proper Chars as well as all non-refined versions of pragmas.
28114
28115 if Is_Single_Concurrent_Type (Spec_Id) then
28116 Spec_Id := Anonymous_Object (Spec_Id);
28117 end if;
28118
28119 Global := Get_Pragma (Spec_Id, Pragma_Global);
28120 Items := Expression (Get_Argument (N, Spec_Id));
28121
28122 -- The subprogram declaration lacks pragma Global. This renders
28123 -- Refined_Global useless as there is nothing to refine.
28124
28125 if No (Global) then
28126 SPARK_Msg_NE
28127 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
28128 & "& lacks aspect or pragma Global"), N, Spec_Id);
28129 goto Leave;
28130 end if;
28131
28132 -- Extract all relevant items from the corresponding Global pragma
28133
28134 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
28135
28136 -- Package and subprogram bodies are instantiated individually in
28137 -- a separate compiler pass. Due to this mode of instantiation, the
28138 -- refinement of a state may no longer be visible when a subprogram
28139 -- body contract is instantiated. Since the generic template is legal,
28140 -- do not perform this check in the instance to circumvent this oddity.
28141
28142 if In_Instance then
28143 null;
28144
28145 -- Non-instance case
28146
28147 else
28148 -- The corresponding Global pragma must mention at least one
28149 -- state with a visible refinement at the point Refined_Global
28150 -- is processed. States with null refinements need Refined_Global
28151 -- pragma (SPARK RM 7.2.4(2)).
28152
28153 if not Has_In_State
28154 and then not Has_In_Out_State
28155 and then not Has_Out_State
28156 and then not Has_Proof_In_State
28157 and then not Has_Null_State
28158 then
28159 SPARK_Msg_NE
28160 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
28161 & "depend on abstract state with visible refinement"),
28162 N, Spec_Id);
28163 goto Leave;
28164
28165 -- The global refinement of inputs and outputs cannot be null when
28166 -- the corresponding Global pragma contains at least one item except
28167 -- in the case where we have states with null refinements.
28168
28169 elsif Nkind (Items) = N_Null
28170 and then
28171 (Present (In_Items)
28172 or else Present (In_Out_Items)
28173 or else Present (Out_Items)
28174 or else Present (Proof_In_Items))
28175 and then not Has_Null_State
28176 then
28177 SPARK_Msg_NE
28178 (Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has "
28179 & "global items"), N, Spec_Id);
28180 goto Leave;
28181 end if;
28182 end if;
28183
28184 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
28185 -- This ensures that the categorization of all refined global items is
28186 -- consistent with their role.
28187
28188 Analyze_Global_In_Decl_Part (N);
28189
28190 -- Perform all refinement checks with respect to completeness and mode
28191 -- matching.
28192
28193 if Serious_Errors_Detected = Errors then
28194 Check_Refined_Global_List (Items);
28195 end if;
28196
28197 -- Store the information that no constituent is used in the global
28198 -- refinement, prior to calling checking procedures which remove items
28199 -- from the list of constituents.
28200
28201 No_Constit :=
28202 No (In_Constits)
28203 and then No (In_Out_Constits)
28204 and then No (Out_Constits)
28205 and then No (Proof_In_Constits);
28206
28207 -- For Input states with visible refinement, at least one constituent
28208 -- must be used as an Input in the global refinement.
28209
28210 if Serious_Errors_Detected = Errors then
28211 Check_Input_States;
28212 end if;
28213
28214 -- Verify all possible completion variants for In_Out states with
28215 -- visible refinement.
28216
28217 if Serious_Errors_Detected = Errors then
28218 Check_In_Out_States;
28219 end if;
28220
28221 -- For Output states with visible refinement, all constituents must be
28222 -- used as Outputs in the global refinement.
28223
28224 if Serious_Errors_Detected = Errors then
28225 Check_Output_States;
28226 end if;
28227
28228 -- For Proof_In states with visible refinement, at least one constituent
28229 -- must be used as Proof_In in the global refinement.
28230
28231 if Serious_Errors_Detected = Errors then
28232 Check_Proof_In_States;
28233 end if;
28234
28235 -- Emit errors for all constituents that belong to other states with
28236 -- visible refinement that do not appear in Global.
28237
28238 if Serious_Errors_Detected = Errors then
28239 Report_Extra_Constituents;
28240 end if;
28241
28242 -- Emit errors for all items in Global that are not repeated in the
28243 -- global refinement and for which there is no full visible refinement
28244 -- and, in the case of states with partial visible refinement, no
28245 -- constituent is mentioned in the global refinement.
28246
28247 if Serious_Errors_Detected = Errors then
28248 Report_Missing_Items;
28249 end if;
28250
28251 -- Emit an error if no constituent is used in the global refinement
28252 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
28253 -- one may be issued by the checking procedures. Do not perform this
28254 -- check in an instance because it was already performed successfully
28255 -- in the generic template.
28256
28257 if Serious_Errors_Detected = Errors
28258 and then not In_Instance
28259 and then not Has_Null_State
28260 and then No_Constit
28261 then
28262 SPARK_Msg_N ("missing refinement", N);
28263 end if;
28264
28265 <<Leave>>
28266 Set_Is_Analyzed_Pragma (N);
28267 end Analyze_Refined_Global_In_Decl_Part;
28268
28269 ----------------------------------------
28270 -- Analyze_Refined_State_In_Decl_Part --
28271 ----------------------------------------
28272
28273 procedure Analyze_Refined_State_In_Decl_Part
28274 (N : Node_Id;
28275 Freeze_Id : Entity_Id := Empty)
28276 is
28277 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
28278 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
28279 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
28280
28281 Available_States : Elist_Id := No_Elist;
28282 -- A list of all abstract states defined in the package declaration that
28283 -- are available for refinement. The list is used to report unrefined
28284 -- states.
28285
28286 Body_States : Elist_Id := No_Elist;
28287 -- A list of all hidden states that appear in the body of the related
28288 -- package. The list is used to report unused hidden states.
28289
28290 Constituents_Seen : Elist_Id := No_Elist;
28291 -- A list that contains all constituents processed so far. The list is
28292 -- used to detect multiple uses of the same constituent.
28293
28294 Freeze_Posted : Boolean := False;
28295 -- A flag that controls the output of a freezing-related error (see use
28296 -- below).
28297
28298 Refined_States_Seen : Elist_Id := No_Elist;
28299 -- A list that contains all refined states processed so far. The list is
28300 -- used to detect duplicate refinements.
28301
28302 procedure Analyze_Refinement_Clause (Clause : Node_Id);
28303 -- Perform full analysis of a single refinement clause
28304
28305 procedure Report_Unrefined_States (States : Elist_Id);
28306 -- Emit errors for all unrefined abstract states found in list States
28307
28308 -------------------------------
28309 -- Analyze_Refinement_Clause --
28310 -------------------------------
28311
28312 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
28313 AR_Constit : Entity_Id := Empty;
28314 AW_Constit : Entity_Id := Empty;
28315 ER_Constit : Entity_Id := Empty;
28316 EW_Constit : Entity_Id := Empty;
28317 -- The entities of external constituents that contain one of the
28318 -- following enabled properties: Async_Readers, Async_Writers,
28319 -- Effective_Reads and Effective_Writes.
28320
28321 External_Constit_Seen : Boolean := False;
28322 -- Flag used to mark when at least one external constituent is part
28323 -- of the state refinement.
28324
28325 Non_Null_Seen : Boolean := False;
28326 Null_Seen : Boolean := False;
28327 -- Flags used to detect multiple uses of null in a single clause or a
28328 -- mixture of null and non-null constituents.
28329
28330 Part_Of_Constits : Elist_Id := No_Elist;
28331 -- A list of all candidate constituents subject to indicator Part_Of
28332 -- where the encapsulating state is the current state.
28333
28334 State : Node_Id;
28335 State_Id : Entity_Id;
28336 -- The current state being refined
28337
28338 procedure Analyze_Constituent (Constit : Node_Id);
28339 -- Perform full analysis of a single constituent
28340
28341 procedure Check_External_Property
28342 (Prop_Nam : Name_Id;
28343 Enabled : Boolean;
28344 Constit : Entity_Id);
28345 -- Determine whether a property denoted by name Prop_Nam is present
28346 -- in the refined state. Emit an error if this is not the case. Flag
28347 -- Enabled should be set when the property applies to the refined
28348 -- state. Constit denotes the constituent (if any) which introduces
28349 -- the property in the refinement.
28350
28351 procedure Match_State;
28352 -- Determine whether the state being refined appears in list
28353 -- Available_States. Emit an error when attempting to re-refine the
28354 -- state or when the state is not defined in the package declaration,
28355 -- otherwise remove the state from Available_States.
28356
28357 procedure Report_Unused_Constituents (Constits : Elist_Id);
28358 -- Emit errors for all unused Part_Of constituents in list Constits
28359
28360 -------------------------
28361 -- Analyze_Constituent --
28362 -------------------------
28363
28364 procedure Analyze_Constituent (Constit : Node_Id) is
28365 procedure Match_Constituent (Constit_Id : Entity_Id);
28366 -- Determine whether constituent Constit denoted by its entity
28367 -- Constit_Id appears in Body_States. Emit an error when the
28368 -- constituent is not a valid hidden state of the related package
28369 -- or when it is used more than once. Otherwise remove the
28370 -- constituent from Body_States.
28371
28372 -----------------------
28373 -- Match_Constituent --
28374 -----------------------
28375
28376 procedure Match_Constituent (Constit_Id : Entity_Id) is
28377 procedure Collect_Constituent;
28378 -- Verify the legality of constituent Constit_Id and add it to
28379 -- the refinements of State_Id.
28380
28381 -------------------------
28382 -- Collect_Constituent --
28383 -------------------------
28384
28385 procedure Collect_Constituent is
28386 Constits : Elist_Id;
28387
28388 begin
28389 -- The Ghost policy in effect at the point of abstract state
28390 -- declaration and constituent must match (SPARK RM 6.9(15))
28391
28392 Check_Ghost_Refinement
28393 (State, State_Id, Constit, Constit_Id);
28394
28395 -- A synchronized state must be refined by a synchronized
28396 -- object or another synchronized state (SPARK RM 9.6).
28397
28398 if Is_Synchronized_State (State_Id)
28399 and then not Is_Synchronized_Object (Constit_Id)
28400 and then not Is_Synchronized_State (Constit_Id)
28401 then
28402 SPARK_Msg_NE
28403 ("constituent of synchronized state & must be "
28404 & "synchronized", Constit, State_Id);
28405 end if;
28406
28407 -- Add the constituent to the list of processed items to aid
28408 -- with the detection of duplicates.
28409
28410 Append_New_Elmt (Constit_Id, Constituents_Seen);
28411
28412 -- Collect the constituent in the list of refinement items
28413 -- and establish a relation between the refined state and
28414 -- the item.
28415
28416 Constits := Refinement_Constituents (State_Id);
28417
28418 if No (Constits) then
28419 Constits := New_Elmt_List;
28420 Set_Refinement_Constituents (State_Id, Constits);
28421 end if;
28422
28423 Append_Elmt (Constit_Id, Constits);
28424 Set_Encapsulating_State (Constit_Id, State_Id);
28425
28426 -- The state has at least one legal constituent, mark the
28427 -- start of the refinement region. The region ends when the
28428 -- body declarations end (see routine Analyze_Declarations).
28429
28430 Set_Has_Visible_Refinement (State_Id);
28431
28432 -- When the constituent is external, save its relevant
28433 -- property for further checks.
28434
28435 if Async_Readers_Enabled (Constit_Id) then
28436 AR_Constit := Constit_Id;
28437 External_Constit_Seen := True;
28438 end if;
28439
28440 if Async_Writers_Enabled (Constit_Id) then
28441 AW_Constit := Constit_Id;
28442 External_Constit_Seen := True;
28443 end if;
28444
28445 if Effective_Reads_Enabled (Constit_Id) then
28446 ER_Constit := Constit_Id;
28447 External_Constit_Seen := True;
28448 end if;
28449
28450 if Effective_Writes_Enabled (Constit_Id) then
28451 EW_Constit := Constit_Id;
28452 External_Constit_Seen := True;
28453 end if;
28454 end Collect_Constituent;
28455
28456 -- Local variables
28457
28458 State_Elmt : Elmt_Id;
28459
28460 -- Start of processing for Match_Constituent
28461
28462 begin
28463 -- Detect a duplicate use of a constituent
28464
28465 if Contains (Constituents_Seen, Constit_Id) then
28466 SPARK_Msg_NE
28467 ("duplicate use of constituent &", Constit, Constit_Id);
28468 return;
28469 end if;
28470
28471 -- The constituent is subject to a Part_Of indicator
28472
28473 if Present (Encapsulating_State (Constit_Id)) then
28474 if Encapsulating_State (Constit_Id) = State_Id then
28475 Remove (Part_Of_Constits, Constit_Id);
28476 Collect_Constituent;
28477
28478 -- The constituent is part of another state and is used
28479 -- incorrectly in the refinement of the current state.
28480
28481 else
28482 Error_Msg_Name_1 := Chars (State_Id);
28483 SPARK_Msg_NE
28484 ("& cannot act as constituent of state %",
28485 Constit, Constit_Id);
28486 SPARK_Msg_NE
28487 ("\Part_Of indicator specifies encapsulator &",
28488 Constit, Encapsulating_State (Constit_Id));
28489 end if;
28490
28491 else
28492 declare
28493 Pack_Id : Entity_Id;
28494 Placement : State_Space_Kind;
28495 begin
28496 -- Find where the constituent lives with respect to the
28497 -- state space.
28498
28499 Find_Placement_In_State_Space
28500 (Item_Id => Constit_Id,
28501 Placement => Placement,
28502 Pack_Id => Pack_Id);
28503
28504 -- The constituent is part of the visible state of a
28505 -- private child package, but lacks a Part_Of indicator.
28506
28507 if Placement = Visible_State_Space
28508 and then Is_Child_Unit (Pack_Id)
28509 and then not Is_Generic_Unit (Pack_Id)
28510 and then Is_Private_Descendant (Pack_Id)
28511 then
28512 Error_Msg_Name_1 := Chars (State_Id);
28513 SPARK_Msg_NE
28514 ("& cannot act as constituent of state %",
28515 Constit, Constit_Id);
28516 Error_Msg_Sloc :=
28517 Sloc (Enclosing_Declaration (Constit_Id));
28518 SPARK_Msg_NE
28519 ("\missing Part_Of indicator # should specify "
28520 & "encapsulator &",
28521 Constit, State_Id);
28522
28523 -- The only other source of legal constituents is the
28524 -- body state space of the related package.
28525
28526 else
28527 if Present (Body_States) then
28528 State_Elmt := First_Elmt (Body_States);
28529 while Present (State_Elmt) loop
28530
28531 -- Consume a valid constituent to signal that it
28532 -- has been encountered.
28533
28534 if Node (State_Elmt) = Constit_Id then
28535 Remove_Elmt (Body_States, State_Elmt);
28536 Collect_Constituent;
28537 return;
28538 end if;
28539
28540 Next_Elmt (State_Elmt);
28541 end loop;
28542 end if;
28543
28544 -- At this point it is known that the constituent is
28545 -- not part of the package hidden state and cannot be
28546 -- used in a refinement (SPARK RM 7.2.2(9)).
28547
28548 Error_Msg_Name_1 := Chars (Spec_Id);
28549 SPARK_Msg_NE
28550 ("cannot use & in refinement, constituent is not a "
28551 & "hidden state of package %", Constit, Constit_Id);
28552 end if;
28553 end;
28554 end if;
28555 end Match_Constituent;
28556
28557 -- Local variables
28558
28559 Constit_Id : Entity_Id;
28560 Constits : Elist_Id;
28561
28562 -- Start of processing for Analyze_Constituent
28563
28564 begin
28565 -- Detect multiple uses of null in a single refinement clause or a
28566 -- mixture of null and non-null constituents.
28567
28568 if Nkind (Constit) = N_Null then
28569 if Null_Seen then
28570 SPARK_Msg_N
28571 ("multiple null constituents not allowed", Constit);
28572
28573 elsif Non_Null_Seen then
28574 SPARK_Msg_N
28575 ("cannot mix null and non-null constituents", Constit);
28576
28577 else
28578 Null_Seen := True;
28579
28580 -- Collect the constituent in the list of refinement items
28581
28582 Constits := Refinement_Constituents (State_Id);
28583
28584 if No (Constits) then
28585 Constits := New_Elmt_List;
28586 Set_Refinement_Constituents (State_Id, Constits);
28587 end if;
28588
28589 Append_Elmt (Constit, Constits);
28590
28591 -- The state has at least one legal constituent, mark the
28592 -- start of the refinement region. The region ends when the
28593 -- body declarations end (see Analyze_Declarations).
28594
28595 Set_Has_Visible_Refinement (State_Id);
28596 end if;
28597
28598 -- Non-null constituents
28599
28600 else
28601 Non_Null_Seen := True;
28602
28603 if Null_Seen then
28604 SPARK_Msg_N
28605 ("cannot mix null and non-null constituents", Constit);
28606 end if;
28607
28608 Analyze (Constit);
28609 Resolve_State (Constit);
28610
28611 -- Ensure that the constituent denotes a valid state or a
28612 -- whole object (SPARK RM 7.2.2(5)).
28613
28614 if Is_Entity_Name (Constit) then
28615 Constit_Id := Entity_Of (Constit);
28616
28617 -- When a constituent is declared after a subprogram body
28618 -- that caused freezing of the related contract where
28619 -- pragma Refined_State resides, the constituent appears
28620 -- undefined and carries Any_Id as its entity.
28621
28622 -- package body Pack
28623 -- with Refined_State => (State => Constit)
28624 -- is
28625 -- procedure Proc
28626 -- with Refined_Global => (Input => Constit)
28627 -- is
28628 -- ...
28629 -- end Proc;
28630
28631 -- Constit : ...;
28632 -- end Pack;
28633
28634 if Constit_Id = Any_Id then
28635 SPARK_Msg_NE ("& is undefined", Constit, Constit_Id);
28636
28637 -- Emit a specialized info message when the contract of
28638 -- the related package body was "frozen" by another body.
28639 -- Note that it is not possible to precisely identify why
28640 -- the constituent is undefined because it is not visible
28641 -- when pragma Refined_State is analyzed. This message is
28642 -- a reasonable approximation.
28643
28644 if Present (Freeze_Id) and then not Freeze_Posted then
28645 Freeze_Posted := True;
28646
28647 Error_Msg_Name_1 := Chars (Body_Id);
28648 Error_Msg_Sloc := Sloc (Freeze_Id);
28649 SPARK_Msg_NE
28650 ("body & declared # freezes the contract of %",
28651 N, Freeze_Id);
28652 SPARK_Msg_N
28653 ("\all constituents must be declared before body #",
28654 N);
28655
28656 -- A misplaced constituent is a critical error because
28657 -- pragma Refined_Depends or Refined_Global depends on
28658 -- the proper link between a state and a constituent.
28659 -- Stop the compilation, as this leads to a multitude
28660 -- of misleading cascaded errors.
28661
28662 raise Unrecoverable_Error;
28663 end if;
28664
28665 -- The constituent is a valid state or object
28666
28667 elsif Ekind (Constit_Id) in
28668 E_Abstract_State | E_Constant | E_Variable
28669 then
28670 Match_Constituent (Constit_Id);
28671
28672 -- The variable may eventually become a constituent of a
28673 -- single protected/task type. Record the reference now
28674 -- and verify its legality when analyzing the contract of
28675 -- the variable (SPARK RM 9.3).
28676
28677 if Ekind (Constit_Id) = E_Variable then
28678 Record_Possible_Part_Of_Reference
28679 (Var_Id => Constit_Id,
28680 Ref => Constit);
28681 end if;
28682
28683 -- Otherwise the constituent is illegal
28684
28685 else
28686 SPARK_Msg_NE
28687 ("constituent & must denote object or state",
28688 Constit, Constit_Id);
28689 end if;
28690
28691 -- The constituent is illegal
28692
28693 else
28694 SPARK_Msg_N ("malformed constituent", Constit);
28695 end if;
28696 end if;
28697 end Analyze_Constituent;
28698
28699 -----------------------------
28700 -- Check_External_Property --
28701 -----------------------------
28702
28703 procedure Check_External_Property
28704 (Prop_Nam : Name_Id;
28705 Enabled : Boolean;
28706 Constit : Entity_Id)
28707 is
28708 begin
28709 -- The property is missing in the declaration of the state, but
28710 -- a constituent is introducing it in the state refinement
28711 -- (SPARK RM 7.2.8(2)).
28712
28713 if not Enabled and then Present (Constit) then
28714 Error_Msg_Name_1 := Prop_Nam;
28715 Error_Msg_Name_2 := Chars (State_Id);
28716 SPARK_Msg_NE
28717 ("constituent & introduces external property % in refinement "
28718 & "of state %", State, Constit);
28719
28720 Error_Msg_Sloc := Sloc (State_Id);
28721 SPARK_Msg_N
28722 ("\property is missing in abstract state declaration #",
28723 State);
28724 end if;
28725 end Check_External_Property;
28726
28727 -----------------
28728 -- Match_State --
28729 -----------------
28730
28731 procedure Match_State is
28732 State_Elmt : Elmt_Id;
28733
28734 begin
28735 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
28736
28737 if Contains (Refined_States_Seen, State_Id) then
28738 SPARK_Msg_NE
28739 ("duplicate refinement of state &", State, State_Id);
28740 return;
28741 end if;
28742
28743 -- Inspect the abstract states defined in the package declaration
28744 -- looking for a match.
28745
28746 State_Elmt := First_Elmt (Available_States);
28747 while Present (State_Elmt) loop
28748
28749 -- A valid abstract state is being refined in the body. Add
28750 -- the state to the list of processed refined states to aid
28751 -- with the detection of duplicate refinements. Remove the
28752 -- state from Available_States to signal that it has already
28753 -- been refined.
28754
28755 if Node (State_Elmt) = State_Id then
28756 Append_New_Elmt (State_Id, Refined_States_Seen);
28757 Remove_Elmt (Available_States, State_Elmt);
28758 return;
28759 end if;
28760
28761 Next_Elmt (State_Elmt);
28762 end loop;
28763
28764 -- If we get here, we are refining a state that is not defined in
28765 -- the package declaration.
28766
28767 Error_Msg_Name_1 := Chars (Spec_Id);
28768 SPARK_Msg_NE
28769 ("cannot refine state, & is not defined in package %",
28770 State, State_Id);
28771 end Match_State;
28772
28773 --------------------------------
28774 -- Report_Unused_Constituents --
28775 --------------------------------
28776
28777 procedure Report_Unused_Constituents (Constits : Elist_Id) is
28778 Constit_Elmt : Elmt_Id;
28779 Constit_Id : Entity_Id;
28780 Posted : Boolean := False;
28781
28782 begin
28783 if Present (Constits) then
28784 Constit_Elmt := First_Elmt (Constits);
28785 while Present (Constit_Elmt) loop
28786 Constit_Id := Node (Constit_Elmt);
28787
28788 -- Generate an error message of the form:
28789
28790 -- state ... has unused Part_Of constituents
28791 -- abstract state ... defined at ...
28792 -- constant ... defined at ...
28793 -- variable ... defined at ...
28794
28795 if not Posted then
28796 Posted := True;
28797 SPARK_Msg_NE
28798 ("state & has unused Part_Of constituents",
28799 State, State_Id);
28800 end if;
28801
28802 Error_Msg_Sloc := Sloc (Constit_Id);
28803
28804 if Ekind (Constit_Id) = E_Abstract_State then
28805 SPARK_Msg_NE
28806 ("\abstract state & defined #", State, Constit_Id);
28807
28808 elsif Ekind (Constit_Id) = E_Constant then
28809 SPARK_Msg_NE
28810 ("\constant & defined #", State, Constit_Id);
28811
28812 else
28813 pragma Assert (Ekind (Constit_Id) = E_Variable);
28814 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
28815 end if;
28816
28817 Next_Elmt (Constit_Elmt);
28818 end loop;
28819 end if;
28820 end Report_Unused_Constituents;
28821
28822 -- Local declarations
28823
28824 Body_Ref : Node_Id;
28825 Body_Ref_Elmt : Elmt_Id;
28826 Constit : Node_Id;
28827 Extra_State : Node_Id;
28828
28829 -- Start of processing for Analyze_Refinement_Clause
28830
28831 begin
28832 -- A refinement clause appears as a component association where the
28833 -- sole choice is the state and the expressions are the constituents.
28834 -- This is a syntax error, always report.
28835
28836 if Nkind (Clause) /= N_Component_Association then
28837 Error_Msg_N ("malformed state refinement clause", Clause);
28838 return;
28839 end if;
28840
28841 -- Analyze the state name of a refinement clause
28842
28843 State := First (Choices (Clause));
28844
28845 Analyze (State);
28846 Resolve_State (State);
28847
28848 -- Ensure that the state name denotes a valid abstract state that is
28849 -- defined in the spec of the related package.
28850
28851 if Is_Entity_Name (State) then
28852 State_Id := Entity_Of (State);
28853
28854 -- When the abstract state is undefined, it appears as Any_Id. Do
28855 -- not continue with the analysis of the clause.
28856
28857 if State_Id = Any_Id then
28858 return;
28859
28860 -- Catch any attempts to re-refine a state or refine a state that
28861 -- is not defined in the package declaration.
28862
28863 elsif Ekind (State_Id) = E_Abstract_State then
28864 Match_State;
28865
28866 else
28867 SPARK_Msg_NE ("& must denote abstract state", State, State_Id);
28868 return;
28869 end if;
28870
28871 -- References to a state with visible refinement are illegal.
28872 -- When nested packages are involved, detecting such references is
28873 -- tricky because pragma Refined_State is analyzed later than the
28874 -- offending pragma Depends or Global. References that occur in
28875 -- such nested context are stored in a list. Emit errors for all
28876 -- references found in Body_References (SPARK RM 6.1.4(8)).
28877
28878 if Present (Body_References (State_Id)) then
28879 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
28880 while Present (Body_Ref_Elmt) loop
28881 Body_Ref := Node (Body_Ref_Elmt);
28882
28883 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
28884 Error_Msg_Sloc := Sloc (State);
28885 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
28886
28887 Next_Elmt (Body_Ref_Elmt);
28888 end loop;
28889 end if;
28890
28891 -- The state name is illegal. This is a syntax error, always report.
28892
28893 else
28894 Error_Msg_N ("malformed state name in refinement clause", State);
28895 return;
28896 end if;
28897
28898 -- A refinement clause may only refine one state at a time
28899
28900 Extra_State := Next (State);
28901
28902 if Present (Extra_State) then
28903 SPARK_Msg_N
28904 ("refinement clause cannot cover multiple states", Extra_State);
28905 end if;
28906
28907 -- Replicate the Part_Of constituents of the refined state because
28908 -- the algorithm will consume items.
28909
28910 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
28911
28912 -- Analyze all constituents of the refinement. Multiple constituents
28913 -- appear as an aggregate.
28914
28915 Constit := Expression (Clause);
28916
28917 if Nkind (Constit) = N_Aggregate then
28918 if Present (Component_Associations (Constit)) then
28919 SPARK_Msg_N
28920 ("constituents of refinement clause must appear in "
28921 & "positional form", Constit);
28922
28923 else pragma Assert (Present (Expressions (Constit)));
28924 Constit := First (Expressions (Constit));
28925 while Present (Constit) loop
28926 Analyze_Constituent (Constit);
28927 Next (Constit);
28928 end loop;
28929 end if;
28930
28931 -- Various forms of a single constituent. Note that these may include
28932 -- malformed constituents.
28933
28934 else
28935 Analyze_Constituent (Constit);
28936 end if;
28937
28938 -- Verify that external constituents do not introduce new external
28939 -- property in the state refinement (SPARK RM 7.2.8(2)).
28940
28941 if Is_External_State (State_Id) then
28942 Check_External_Property
28943 (Prop_Nam => Name_Async_Readers,
28944 Enabled => Async_Readers_Enabled (State_Id),
28945 Constit => AR_Constit);
28946
28947 Check_External_Property
28948 (Prop_Nam => Name_Async_Writers,
28949 Enabled => Async_Writers_Enabled (State_Id),
28950 Constit => AW_Constit);
28951
28952 Check_External_Property
28953 (Prop_Nam => Name_Effective_Reads,
28954 Enabled => Effective_Reads_Enabled (State_Id),
28955 Constit => ER_Constit);
28956
28957 Check_External_Property
28958 (Prop_Nam => Name_Effective_Writes,
28959 Enabled => Effective_Writes_Enabled (State_Id),
28960 Constit => EW_Constit);
28961
28962 -- When a refined state is not external, it should not have external
28963 -- constituents (SPARK RM 7.2.8(1)).
28964
28965 elsif External_Constit_Seen then
28966 SPARK_Msg_NE
28967 ("non-external state & cannot contain external constituents in "
28968 & "refinement", State, State_Id);
28969 end if;
28970
28971 -- Ensure that all Part_Of candidate constituents have been mentioned
28972 -- in the refinement clause.
28973
28974 Report_Unused_Constituents (Part_Of_Constits);
28975
28976 -- Avoid a cascading error reporting a missing refinement by adding a
28977 -- dummy constituent.
28978
28979 if No (Refinement_Constituents (State_Id)) then
28980 Set_Refinement_Constituents (State_Id, New_Elmt_List (Any_Id));
28981 end if;
28982
28983 -- At this point the refinement might be dummy, but must be
28984 -- well-formed, to prevent cascaded errors.
28985
28986 pragma Assert (Has_Null_Refinement (State_Id)
28987 xor
28988 Has_Non_Null_Refinement (State_Id));
28989 end Analyze_Refinement_Clause;
28990
28991 -----------------------------
28992 -- Report_Unrefined_States --
28993 -----------------------------
28994
28995 procedure Report_Unrefined_States (States : Elist_Id) is
28996 State_Elmt : Elmt_Id;
28997
28998 begin
28999 if Present (States) then
29000 State_Elmt := First_Elmt (States);
29001 while Present (State_Elmt) loop
29002 SPARK_Msg_N
29003 ("abstract state & must be refined", Node (State_Elmt));
29004
29005 Next_Elmt (State_Elmt);
29006 end loop;
29007 end if;
29008 end Report_Unrefined_States;
29009
29010 -- Local declarations
29011
29012 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
29013 Clause : Node_Id;
29014
29015 -- Start of processing for Analyze_Refined_State_In_Decl_Part
29016
29017 begin
29018 -- Do not analyze the pragma multiple times
29019
29020 if Is_Analyzed_Pragma (N) then
29021 return;
29022 end if;
29023
29024 -- Save the scenario for examination by the ABE Processing phase
29025
29026 Record_Elaboration_Scenario (N);
29027
29028 -- Replicate the abstract states declared by the package because the
29029 -- matching algorithm will consume states.
29030
29031 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
29032
29033 -- Gather all abstract states and objects declared in the visible
29034 -- state space of the package body. These items must be utilized as
29035 -- constituents in a state refinement.
29036
29037 Body_States := Collect_Body_States (Body_Id);
29038
29039 -- Multiple non-null state refinements appear as an aggregate
29040
29041 if Nkind (Clauses) = N_Aggregate then
29042 if Present (Expressions (Clauses)) then
29043 SPARK_Msg_N
29044 ("state refinements must appear as component associations",
29045 Clauses);
29046
29047 else pragma Assert (Present (Component_Associations (Clauses)));
29048 Clause := First (Component_Associations (Clauses));
29049 while Present (Clause) loop
29050 Analyze_Refinement_Clause (Clause);
29051 Next (Clause);
29052 end loop;
29053 end if;
29054
29055 -- Various forms of a single state refinement. Note that these may
29056 -- include malformed refinements.
29057
29058 else
29059 Analyze_Refinement_Clause (Clauses);
29060 end if;
29061
29062 -- List all abstract states that were left unrefined
29063
29064 Report_Unrefined_States (Available_States);
29065
29066 Set_Is_Analyzed_Pragma (N);
29067 end Analyze_Refined_State_In_Decl_Part;
29068
29069 ---------------------------------------------
29070 -- Analyze_Subprogram_Variant_In_Decl_Part --
29071 ---------------------------------------------
29072
29073 -- WARNING: This routine manages Ghost regions. Return statements must be
29074 -- replaced by gotos which jump to the end of the routine and restore the
29075 -- Ghost mode.
29076
29077 procedure Analyze_Subprogram_Variant_In_Decl_Part
29078 (N : Node_Id;
29079 Freeze_Id : Entity_Id := Empty)
29080 is
29081 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
29082 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
29083
29084 procedure Analyze_Variant (Variant : Node_Id);
29085 -- Verify the legality of a single contract case
29086
29087 ---------------------
29088 -- Analyze_Variant --
29089 ---------------------
29090
29091 procedure Analyze_Variant (Variant : Node_Id) is
29092 Direction : Node_Id;
29093 Expr : Node_Id;
29094 Errors : Nat;
29095 Extra_Direction : Node_Id;
29096
29097 begin
29098 if Nkind (Variant) /= N_Component_Association then
29099 Error_Msg_N ("wrong syntax in subprogram variant", Variant);
29100 return;
29101 end if;
29102
29103 Direction := First (Choices (Variant));
29104 Expr := Expression (Variant);
29105
29106 -- Each variant must have exactly one direction
29107
29108 Extra_Direction := Next (Direction);
29109
29110 if Present (Extra_Direction) then
29111 Error_Msg_N
29112 ("subprogram variant case must have exactly one direction",
29113 Extra_Direction);
29114 end if;
29115
29116 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
29117
29118 if Nkind (Direction) = N_Identifier then
29119 if Chars (Direction) /= Name_Decreases
29120 and then
29121 Chars (Direction) /= Name_Increases
29122 then
29123 Error_Msg_N ("wrong direction", Direction);
29124 end if;
29125 else
29126 Error_Msg_N ("wrong syntax", Direction);
29127 end if;
29128
29129 Errors := Serious_Errors_Detected;
29130 Preanalyze_Assert_Expression (Expr, Any_Discrete);
29131
29132 -- Emit a clarification message when the variant expression
29133 -- contains at least one undefined reference, possibly due
29134 -- to contract freezing.
29135
29136 if Errors /= Serious_Errors_Detected
29137 and then Present (Freeze_Id)
29138 and then Has_Undefined_Reference (Expr)
29139 then
29140 Contract_Freeze_Error (Spec_Id, Freeze_Id);
29141 end if;
29142 end Analyze_Variant;
29143
29144 -- Local variables
29145
29146 Variants : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
29147
29148 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
29149 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
29150 -- Save the Ghost-related attributes to restore on exit
29151
29152 Variant : Node_Id;
29153 Restore_Scope : Boolean := False;
29154
29155 -- Start of processing for Analyze_Subprogram_Variant_In_Decl_Part
29156
29157 begin
29158 -- Do not analyze the pragma multiple times
29159
29160 if Is_Analyzed_Pragma (N) then
29161 return;
29162 end if;
29163
29164 -- Set the Ghost mode in effect from the pragma. Due to the delayed
29165 -- analysis of the pragma, the Ghost mode at point of declaration and
29166 -- point of analysis may not necessarily be the same. Use the mode in
29167 -- effect at the point of declaration.
29168
29169 Set_Ghost_Mode (N);
29170
29171 -- Single and multiple contract cases must appear in aggregate form. If
29172 -- this is not the case, then either the parser of the analysis of the
29173 -- pragma failed to produce an aggregate.
29174
29175 pragma Assert (Nkind (Variants) = N_Aggregate);
29176
29177 -- Only "change_direction => discrete_expression" clauses are allowed
29178
29179 if Present (Component_Associations (Variants))
29180 and then No (Expressions (Variants))
29181 then
29182
29183 -- Ensure that the formal parameters are visible when analyzing all
29184 -- clauses. This falls out of the general rule of aspects pertaining
29185 -- to subprogram declarations.
29186
29187 if not In_Open_Scopes (Spec_Id) then
29188 Restore_Scope := True;
29189 Push_Scope (Spec_Id);
29190
29191 if Is_Generic_Subprogram (Spec_Id) then
29192 Install_Generic_Formals (Spec_Id);
29193 else
29194 Install_Formals (Spec_Id);
29195 end if;
29196 end if;
29197
29198 Variant := First (Component_Associations (Variants));
29199 while Present (Variant) loop
29200 Analyze_Variant (Variant);
29201 Next (Variant);
29202 end loop;
29203
29204 if Restore_Scope then
29205 End_Scope;
29206 end if;
29207
29208 -- Otherwise the pragma is illegal
29209
29210 else
29211 Error_Msg_N ("wrong syntax for subprogram variant", N);
29212 end if;
29213
29214 Set_Is_Analyzed_Pragma (N);
29215
29216 Restore_Ghost_Region (Saved_GM, Saved_IGR);
29217 end Analyze_Subprogram_Variant_In_Decl_Part;
29218
29219 ------------------------------------
29220 -- Analyze_Test_Case_In_Decl_Part --
29221 ------------------------------------
29222
29223 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
29224 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
29225 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
29226
29227 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
29228 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
29229 -- denoted by Arg_Nam.
29230
29231 ------------------------------
29232 -- Preanalyze_Test_Case_Arg --
29233 ------------------------------
29234
29235 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
29236 Arg : Node_Id;
29237
29238 begin
29239 -- Preanalyze the original aspect argument for a generic subprogram
29240 -- to properly capture global references.
29241
29242 if Is_Generic_Subprogram (Spec_Id) then
29243 Arg :=
29244 Test_Case_Arg
29245 (Prag => N,
29246 Arg_Nam => Arg_Nam,
29247 From_Aspect => True);
29248
29249 if Present (Arg) then
29250 Preanalyze_Assert_Expression
29251 (Expression (Arg), Standard_Boolean);
29252 end if;
29253 end if;
29254
29255 Arg := Test_Case_Arg (N, Arg_Nam);
29256
29257 if Present (Arg) then
29258 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
29259 end if;
29260 end Preanalyze_Test_Case_Arg;
29261
29262 -- Local variables
29263
29264 Restore_Scope : Boolean := False;
29265
29266 -- Start of processing for Analyze_Test_Case_In_Decl_Part
29267
29268 begin
29269 -- Do not analyze the pragma multiple times
29270
29271 if Is_Analyzed_Pragma (N) then
29272 return;
29273 end if;
29274
29275 -- Ensure that the formal parameters are visible when analyzing all
29276 -- clauses. This falls out of the general rule of aspects pertaining
29277 -- to subprogram declarations.
29278
29279 if not In_Open_Scopes (Spec_Id) then
29280 Restore_Scope := True;
29281 Push_Scope (Spec_Id);
29282
29283 if Is_Generic_Subprogram (Spec_Id) then
29284 Install_Generic_Formals (Spec_Id);
29285 else
29286 Install_Formals (Spec_Id);
29287 end if;
29288 end if;
29289
29290 Preanalyze_Test_Case_Arg (Name_Requires);
29291 Preanalyze_Test_Case_Arg (Name_Ensures);
29292
29293 if Restore_Scope then
29294 End_Scope;
29295 end if;
29296
29297 -- Currently it is not possible to inline pre/postconditions on a
29298 -- subprogram subject to pragma Inline_Always.
29299
29300 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
29301
29302 Set_Is_Analyzed_Pragma (N);
29303 end Analyze_Test_Case_In_Decl_Part;
29304
29305 ----------------
29306 -- Appears_In --
29307 ----------------
29308
29309 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
29310 Elmt : Elmt_Id;
29311 Id : Entity_Id;
29312
29313 begin
29314 if Present (List) then
29315 Elmt := First_Elmt (List);
29316 while Present (Elmt) loop
29317 if Nkind (Node (Elmt)) = N_Defining_Identifier then
29318 Id := Node (Elmt);
29319 else
29320 Id := Entity_Of (Node (Elmt));
29321 end if;
29322
29323 if Id = Item_Id then
29324 return True;
29325 end if;
29326
29327 Next_Elmt (Elmt);
29328 end loop;
29329 end if;
29330
29331 return False;
29332 end Appears_In;
29333
29334 -----------------------------------
29335 -- Build_Pragma_Check_Equivalent --
29336 -----------------------------------
29337
29338 function Build_Pragma_Check_Equivalent
29339 (Prag : Node_Id;
29340 Subp_Id : Entity_Id := Empty;
29341 Inher_Id : Entity_Id := Empty;
29342 Keep_Pragma_Id : Boolean := False) return Node_Id
29343 is
29344 function Suppress_Reference (N : Node_Id) return Traverse_Result;
29345 -- Detect whether node N references a formal parameter subject to
29346 -- pragma Unreferenced. If this is the case, set Comes_From_Source
29347 -- to False to suppress the generation of a reference when analyzing
29348 -- N later on.
29349
29350 ------------------------
29351 -- Suppress_Reference --
29352 ------------------------
29353
29354 function Suppress_Reference (N : Node_Id) return Traverse_Result is
29355 Formal : Entity_Id;
29356
29357 begin
29358 if Is_Entity_Name (N) and then Present (Entity (N)) then
29359 Formal := Entity (N);
29360
29361 -- The formal parameter is subject to pragma Unreferenced. Prevent
29362 -- the generation of references by resetting the Comes_From_Source
29363 -- flag.
29364
29365 if Is_Formal (Formal)
29366 and then Has_Pragma_Unreferenced (Formal)
29367 then
29368 Set_Comes_From_Source (N, False);
29369 end if;
29370 end if;
29371
29372 return OK;
29373 end Suppress_Reference;
29374
29375 procedure Suppress_References is
29376 new Traverse_Proc (Suppress_Reference);
29377
29378 -- Local variables
29379
29380 Loc : constant Source_Ptr := Sloc (Prag);
29381 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
29382 Check_Prag : Node_Id;
29383 Msg_Arg : Node_Id;
29384 Nam : Name_Id;
29385
29386 Needs_Wrapper : Boolean;
29387 pragma Unreferenced (Needs_Wrapper);
29388
29389 -- Start of processing for Build_Pragma_Check_Equivalent
29390
29391 begin
29392 -- When the pre- or postcondition is inherited, map the formals of the
29393 -- inherited subprogram to those of the current subprogram. In addition,
29394 -- map primitive operations of the parent type into the corresponding
29395 -- primitive operations of the descendant.
29396
29397 if Present (Inher_Id) then
29398 pragma Assert (Present (Subp_Id));
29399
29400 Update_Primitives_Mapping (Inher_Id, Subp_Id);
29401
29402 -- Use generic machinery to copy inherited pragma, as if it were an
29403 -- instantiation, resetting source locations appropriately, so that
29404 -- expressions inside the inherited pragma use chained locations.
29405 -- This is used in particular in GNATprove to locate precisely
29406 -- messages on a given inherited pragma.
29407
29408 Set_Copied_Sloc_For_Inherited_Pragma
29409 (Unit_Declaration_Node (Subp_Id), Inher_Id);
29410 Check_Prag := New_Copy_Tree (Source => Prag);
29411
29412 -- Build the inherited class-wide condition
29413
29414 Build_Class_Wide_Expression
29415 (Prag => Check_Prag,
29416 Subp => Subp_Id,
29417 Par_Subp => Inher_Id,
29418 Adjust_Sloc => True,
29419 Needs_Wrapper => Needs_Wrapper);
29420
29421 -- If not an inherited condition simply copy the original pragma
29422
29423 else
29424 Check_Prag := New_Copy_Tree (Source => Prag);
29425 end if;
29426
29427 -- Mark the pragma as being internally generated and reset the Analyzed
29428 -- flag.
29429
29430 Set_Analyzed (Check_Prag, False);
29431 Set_Comes_From_Source (Check_Prag, False);
29432
29433 -- The tree of the original pragma may contain references to the
29434 -- formal parameters of the related subprogram. At the same time
29435 -- the corresponding body may mark the formals as unreferenced:
29436
29437 -- procedure Proc (Formal : ...)
29438 -- with Pre => Formal ...;
29439
29440 -- procedure Proc (Formal : ...) is
29441 -- pragma Unreferenced (Formal);
29442 -- ...
29443
29444 -- This creates problems because all pragma Check equivalents are
29445 -- analyzed at the end of the body declarations. Since all source
29446 -- references have already been accounted for, reset any references
29447 -- to such formals in the generated pragma Check equivalent.
29448
29449 Suppress_References (Check_Prag);
29450
29451 if Present (Corresponding_Aspect (Prag)) then
29452 Nam := Chars (Identifier (Corresponding_Aspect (Prag)));
29453 else
29454 Nam := Prag_Nam;
29455 end if;
29456
29457 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
29458 -- the copied pragma in the newly created pragma, convert the copy into
29459 -- pragma Check by correcting the name and adding a check_kind argument.
29460
29461 if not Keep_Pragma_Id then
29462 Set_Class_Present (Check_Prag, False);
29463
29464 Set_Pragma_Identifier
29465 (Check_Prag, Make_Identifier (Loc, Name_Check));
29466
29467 Prepend_To (Pragma_Argument_Associations (Check_Prag),
29468 Make_Pragma_Argument_Association (Loc,
29469 Expression => Make_Identifier (Loc, Nam)));
29470 end if;
29471
29472 -- Update the error message when the pragma is inherited
29473
29474 if Present (Inher_Id) then
29475 Msg_Arg := Last (Pragma_Argument_Associations (Check_Prag));
29476
29477 if Chars (Msg_Arg) = Name_Message then
29478 String_To_Name_Buffer (Strval (Expression (Msg_Arg)));
29479
29480 -- Insert "inherited" to improve the error message
29481
29482 if Name_Buffer (1 .. 8) = "failed p" then
29483 Insert_Str_In_Name_Buffer ("inherited ", 8);
29484 Set_Strval (Expression (Msg_Arg), String_From_Name_Buffer);
29485 end if;
29486 end if;
29487 end if;
29488
29489 return Check_Prag;
29490 end Build_Pragma_Check_Equivalent;
29491
29492 -----------------------------
29493 -- Check_Applicable_Policy --
29494 -----------------------------
29495
29496 procedure Check_Applicable_Policy (N : Node_Id) is
29497 PP : Node_Id;
29498 Policy : Name_Id;
29499
29500 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
29501
29502 begin
29503 -- No effect if not valid assertion kind name
29504
29505 if not Is_Valid_Assertion_Kind (Ename) then
29506 return;
29507 end if;
29508
29509 -- Loop through entries in check policy list
29510
29511 PP := Opt.Check_Policy_List;
29512 while Present (PP) loop
29513 declare
29514 PPA : constant List_Id := Pragma_Argument_Associations (PP);
29515 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
29516
29517 begin
29518 if Ename = Pnm
29519 or else Pnm = Name_Assertion
29520 or else (Pnm = Name_Statement_Assertions
29521 and then Ename in Name_Assert
29522 | Name_Assert_And_Cut
29523 | Name_Assume
29524 | Name_Loop_Invariant
29525 | Name_Loop_Variant)
29526 then
29527 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
29528
29529 case Policy is
29530 when Name_Ignore
29531 | Name_Off
29532 =>
29533 -- In CodePeer mode and GNATprove mode, we need to
29534 -- consider all assertions, unless they are disabled.
29535 -- Force Is_Checked on ignored assertions, in particular
29536 -- because transformations of the AST may depend on
29537 -- assertions being checked (e.g. the translation of
29538 -- attribute 'Loop_Entry).
29539
29540 if CodePeer_Mode or GNATprove_Mode then
29541 Set_Is_Checked (N, True);
29542 Set_Is_Ignored (N, False);
29543 else
29544 Set_Is_Checked (N, False);
29545 Set_Is_Ignored (N, True);
29546 end if;
29547
29548 when Name_Check
29549 | Name_On
29550 =>
29551 Set_Is_Checked (N, True);
29552 Set_Is_Ignored (N, False);
29553
29554 when Name_Disable =>
29555 Set_Is_Ignored (N, True);
29556 Set_Is_Checked (N, False);
29557 Set_Is_Disabled (N, True);
29558
29559 -- That should be exhaustive, the null here is a defence
29560 -- against a malformed tree from previous errors.
29561
29562 when others =>
29563 null;
29564 end case;
29565
29566 return;
29567 end if;
29568
29569 PP := Next_Pragma (PP);
29570 end;
29571 end loop;
29572
29573 -- If there are no specific entries that matched, then we let the
29574 -- setting of assertions govern. Note that this provides the needed
29575 -- compatibility with the RM for the cases of assertion, invariant,
29576 -- precondition, predicate, and postcondition. Note also that
29577 -- Assertions_Enabled is forced in CodePeer mode and GNATprove mode.
29578
29579 if Assertions_Enabled then
29580 Set_Is_Checked (N, True);
29581 Set_Is_Ignored (N, False);
29582 else
29583 Set_Is_Checked (N, False);
29584 Set_Is_Ignored (N, True);
29585 end if;
29586 end Check_Applicable_Policy;
29587
29588 -------------------------------
29589 -- Check_External_Properties --
29590 -------------------------------
29591
29592 procedure Check_External_Properties
29593 (Item : Node_Id;
29594 AR : Boolean;
29595 AW : Boolean;
29596 ER : Boolean;
29597 EW : Boolean)
29598 is
29599 type Properties is array (Positive range 1 .. 4) of Boolean;
29600 type Combinations is array (Positive range <>) of Properties;
29601 -- Arrays of Async_Readers, Async_Writers, Effective_Writes and
29602 -- Effective_Reads properties and their combinations, respectively.
29603
29604 Specified : constant Properties := (AR, AW, EW, ER);
29605 -- External properties, as given by the Item pragma
29606
29607 Allowed : constant Combinations :=
29608 (1 => (True, False, True, False),
29609 2 => (False, True, False, True),
29610 3 => (True, False, False, False),
29611 4 => (False, True, False, False),
29612 5 => (True, True, True, False),
29613 6 => (True, True, False, True),
29614 7 => (True, True, False, False),
29615 8 => (True, True, True, True));
29616 -- Allowed combinations, as listed in the SPARK RM 7.1.2(6) table
29617
29618 begin
29619 -- Check if the specified properties match any of the allowed
29620 -- combination; if not, then emit an error.
29621
29622 for J in Allowed'Range loop
29623 if Specified = Allowed (J) then
29624 return;
29625 end if;
29626 end loop;
29627
29628 SPARK_Msg_N
29629 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
29630 Item);
29631 end Check_External_Properties;
29632
29633 ----------------
29634 -- Check_Kind --
29635 ----------------
29636
29637 function Check_Kind (Nam : Name_Id) return Name_Id is
29638 PP : Node_Id;
29639
29640 begin
29641 -- Loop through entries in check policy list
29642
29643 PP := Opt.Check_Policy_List;
29644 while Present (PP) loop
29645 declare
29646 PPA : constant List_Id := Pragma_Argument_Associations (PP);
29647 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
29648
29649 begin
29650 if Nam = Pnm
29651 or else (Pnm = Name_Assertion
29652 and then Is_Valid_Assertion_Kind (Nam))
29653 or else (Pnm = Name_Statement_Assertions
29654 and then Nam in Name_Assert
29655 | Name_Assert_And_Cut
29656 | Name_Assume
29657 | Name_Loop_Invariant
29658 | Name_Loop_Variant)
29659 then
29660 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
29661 when Name_Check
29662 | Name_On
29663 =>
29664 return Name_Check;
29665
29666 when Name_Ignore
29667 | Name_Off
29668 =>
29669 return Name_Ignore;
29670
29671 when Name_Disable =>
29672 return Name_Disable;
29673
29674 when others =>
29675 raise Program_Error;
29676 end case;
29677
29678 else
29679 PP := Next_Pragma (PP);
29680 end if;
29681 end;
29682 end loop;
29683
29684 -- If there are no specific entries that matched, then we let the
29685 -- setting of assertions govern. Note that this provides the needed
29686 -- compatibility with the RM for the cases of assertion, invariant,
29687 -- precondition, predicate, and postcondition.
29688
29689 if Assertions_Enabled then
29690 return Name_Check;
29691 else
29692 return Name_Ignore;
29693 end if;
29694 end Check_Kind;
29695
29696 ---------------------------
29697 -- Check_Missing_Part_Of --
29698 ---------------------------
29699
29700 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
29701 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
29702 -- Determine whether a package denoted by Pack_Id declares at least one
29703 -- visible state.
29704
29705 -----------------------
29706 -- Has_Visible_State --
29707 -----------------------
29708
29709 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
29710 Item_Id : Entity_Id;
29711
29712 begin
29713 -- Traverse the entity chain of the package trying to find at least
29714 -- one visible abstract state, variable or a package [instantiation]
29715 -- that declares a visible state.
29716
29717 Item_Id := First_Entity (Pack_Id);
29718 while Present (Item_Id)
29719 and then not In_Private_Part (Item_Id)
29720 loop
29721 -- Do not consider internally generated items
29722
29723 if not Comes_From_Source (Item_Id) then
29724 null;
29725
29726 -- Do not consider generic formals or their corresponding actuals
29727 -- because they are not part of a visible state. Note that both
29728 -- entities are marked as hidden.
29729
29730 elsif Is_Hidden (Item_Id) then
29731 null;
29732
29733 -- A visible state has been found. Note that constants are not
29734 -- considered here because it is not possible to determine whether
29735 -- they depend on variable input. This check is left to the SPARK
29736 -- prover.
29737
29738 elsif Ekind (Item_Id) in E_Abstract_State | E_Variable then
29739 return True;
29740
29741 -- Recursively peek into nested packages and instantiations
29742
29743 elsif Ekind (Item_Id) = E_Package
29744 and then Has_Visible_State (Item_Id)
29745 then
29746 return True;
29747 end if;
29748
29749 Next_Entity (Item_Id);
29750 end loop;
29751
29752 return False;
29753 end Has_Visible_State;
29754
29755 -- Local variables
29756
29757 Pack_Id : Entity_Id;
29758 Placement : State_Space_Kind;
29759
29760 -- Start of processing for Check_Missing_Part_Of
29761
29762 begin
29763 -- Do not consider abstract states, variables or package instantiations
29764 -- coming from an instance as those always inherit the Part_Of indicator
29765 -- of the instance itself.
29766
29767 if In_Instance then
29768 return;
29769
29770 -- Do not consider internally generated entities as these can never
29771 -- have a Part_Of indicator.
29772
29773 elsif not Comes_From_Source (Item_Id) then
29774 return;
29775
29776 -- Perform these checks only when SPARK_Mode is enabled as they will
29777 -- interfere with standard Ada rules and produce false positives.
29778
29779 elsif SPARK_Mode /= On then
29780 return;
29781
29782 -- Do not consider constants, because the compiler cannot accurately
29783 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
29784 -- act as a hidden state of a package.
29785
29786 elsif Ekind (Item_Id) = E_Constant then
29787 return;
29788 end if;
29789
29790 -- Find where the abstract state, variable or package instantiation
29791 -- lives with respect to the state space.
29792
29793 Find_Placement_In_State_Space
29794 (Item_Id => Item_Id,
29795 Placement => Placement,
29796 Pack_Id => Pack_Id);
29797
29798 -- Items that appear in a non-package construct (subprogram, block, etc)
29799 -- do not require a Part_Of indicator because they can never act as a
29800 -- hidden state.
29801
29802 if Placement = Not_In_Package then
29803 null;
29804
29805 -- An item declared in the body state space of a package always act as a
29806 -- constituent and does not need explicit Part_Of indicator.
29807
29808 elsif Placement = Body_State_Space then
29809 null;
29810
29811 -- In general an item declared in the visible state space of a package
29812 -- does not require a Part_Of indicator. The only exception is when the
29813 -- related package is a nongeneric private child unit, in which case
29814 -- Part_Of must denote a state in the parent unit or in one of its
29815 -- descendants.
29816
29817 elsif Placement = Visible_State_Space then
29818 if Is_Child_Unit (Pack_Id)
29819 and then not Is_Generic_Unit (Pack_Id)
29820 and then Is_Private_Descendant (Pack_Id)
29821 then
29822 -- A package instantiation does not need a Part_Of indicator when
29823 -- the related generic template has no visible state.
29824
29825 if Ekind (Item_Id) = E_Package
29826 and then Is_Generic_Instance (Item_Id)
29827 and then not Has_Visible_State (Item_Id)
29828 then
29829 null;
29830
29831 -- All other cases require Part_Of
29832
29833 else
29834 Error_Msg_N
29835 ("indicator Part_Of is required in this context "
29836 & "(SPARK RM 7.2.6(3))", Item_Id);
29837 Error_Msg_Name_1 := Chars (Pack_Id);
29838 Error_Msg_N
29839 ("\& is declared in the visible part of private child "
29840 & "unit %", Item_Id);
29841 end if;
29842 end if;
29843
29844 -- When the item appears in the private state space of a package, it
29845 -- must be a part of some state declared by the said package.
29846
29847 else pragma Assert (Placement = Private_State_Space);
29848
29849 -- The related package does not declare a state, the item cannot act
29850 -- as a Part_Of constituent.
29851
29852 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
29853 null;
29854
29855 -- A package instantiation does not need a Part_Of indicator when the
29856 -- related generic template has no visible state.
29857
29858 elsif Ekind (Item_Id) = E_Package
29859 and then Is_Generic_Instance (Item_Id)
29860 and then not Has_Visible_State (Item_Id)
29861 then
29862 null;
29863
29864 -- All other cases require Part_Of
29865
29866 else
29867 Error_Msg_N
29868 ("indicator Part_Of is required in this context "
29869 & "(SPARK RM 7.2.6(2))", Item_Id);
29870 Error_Msg_Name_1 := Chars (Pack_Id);
29871 Error_Msg_N
29872 ("\& is declared in the private part of package %", Item_Id);
29873 end if;
29874 end if;
29875 end Check_Missing_Part_Of;
29876
29877 ---------------------------------------------------
29878 -- Check_Postcondition_Use_In_Inlined_Subprogram --
29879 ---------------------------------------------------
29880
29881 procedure Check_Postcondition_Use_In_Inlined_Subprogram
29882 (Prag : Node_Id;
29883 Spec_Id : Entity_Id)
29884 is
29885 begin
29886 if Warn_On_Redundant_Constructs
29887 and then Has_Pragma_Inline_Always (Spec_Id)
29888 and then Assertions_Enabled
29889 then
29890 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
29891
29892 if From_Aspect_Specification (Prag) then
29893 Error_Msg_NE
29894 ("aspect % not enforced on inlined subprogram &?r?",
29895 Corresponding_Aspect (Prag), Spec_Id);
29896 else
29897 Error_Msg_NE
29898 ("pragma % not enforced on inlined subprogram &?r?",
29899 Prag, Spec_Id);
29900 end if;
29901 end if;
29902 end Check_Postcondition_Use_In_Inlined_Subprogram;
29903
29904 -------------------------------------
29905 -- Check_State_And_Constituent_Use --
29906 -------------------------------------
29907
29908 procedure Check_State_And_Constituent_Use
29909 (States : Elist_Id;
29910 Constits : Elist_Id;
29911 Context : Node_Id)
29912 is
29913 Constit_Elmt : Elmt_Id;
29914 Constit_Id : Entity_Id;
29915 State_Id : Entity_Id;
29916
29917 begin
29918 -- Nothing to do if there are no states or constituents
29919
29920 if No (States) or else No (Constits) then
29921 return;
29922 end if;
29923
29924 -- Inspect the list of constituents and try to determine whether its
29925 -- encapsulating state is in list States.
29926
29927 Constit_Elmt := First_Elmt (Constits);
29928 while Present (Constit_Elmt) loop
29929 Constit_Id := Node (Constit_Elmt);
29930
29931 -- Determine whether the constituent is part of an encapsulating
29932 -- state that appears in the same context and if this is the case,
29933 -- emit an error (SPARK RM 7.2.6(7)).
29934
29935 State_Id := Find_Encapsulating_State (States, Constit_Id);
29936
29937 if Present (State_Id) then
29938 Error_Msg_Name_1 := Chars (Constit_Id);
29939 SPARK_Msg_NE
29940 ("cannot mention state & and its constituent % in the same "
29941 & "context", Context, State_Id);
29942 exit;
29943 end if;
29944
29945 Next_Elmt (Constit_Elmt);
29946 end loop;
29947 end Check_State_And_Constituent_Use;
29948
29949 ---------------------------------------------
29950 -- Collect_Inherited_Class_Wide_Conditions --
29951 ---------------------------------------------
29952
29953 procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is
29954 Parent_Subp : constant Entity_Id :=
29955 Ultimate_Alias (Overridden_Operation (Subp));
29956 -- The Overridden_Operation may itself be inherited and as such have no
29957 -- explicit contract.
29958
29959 Prags : constant Node_Id := Contract (Parent_Subp);
29960 In_Spec_Expr : Boolean := In_Spec_Expression;
29961 Installed : Boolean;
29962 Prag : Node_Id;
29963 New_Prag : Node_Id;
29964
29965 begin
29966 Installed := False;
29967
29968 -- Iterate over the contract of the overridden subprogram to find all
29969 -- inherited class-wide pre- and postconditions.
29970
29971 if Present (Prags) then
29972 Prag := Pre_Post_Conditions (Prags);
29973
29974 while Present (Prag) loop
29975 if Pragma_Name_Unmapped (Prag)
29976 in Name_Precondition | Name_Postcondition
29977 and then Class_Present (Prag)
29978 then
29979 -- The generated pragma must be analyzed in the context of
29980 -- the subprogram, to make its formals visible. In addition,
29981 -- we must inhibit freezing and full analysis because the
29982 -- controlling type of the subprogram is not frozen yet, and
29983 -- may have further primitives.
29984
29985 if not Installed then
29986 Installed := True;
29987 Push_Scope (Subp);
29988 Install_Formals (Subp);
29989 In_Spec_Expr := In_Spec_Expression;
29990 In_Spec_Expression := True;
29991 end if;
29992
29993 New_Prag :=
29994 Build_Pragma_Check_Equivalent
29995 (Prag, Subp, Parent_Subp, Keep_Pragma_Id => True);
29996
29997 Insert_After (Unit_Declaration_Node (Subp), New_Prag);
29998 Preanalyze (New_Prag);
29999
30000 -- Prevent further analysis in subsequent processing of the
30001 -- current list of declarations
30002
30003 Set_Analyzed (New_Prag);
30004 end if;
30005
30006 Prag := Next_Pragma (Prag);
30007 end loop;
30008
30009 if Installed then
30010 In_Spec_Expression := In_Spec_Expr;
30011 End_Scope;
30012 end if;
30013 end if;
30014 end Collect_Inherited_Class_Wide_Conditions;
30015
30016 ---------------------------------------
30017 -- Collect_Subprogram_Inputs_Outputs --
30018 ---------------------------------------
30019
30020 procedure Collect_Subprogram_Inputs_Outputs
30021 (Subp_Id : Entity_Id;
30022 Synthesize : Boolean := False;
30023 Subp_Inputs : in out Elist_Id;
30024 Subp_Outputs : in out Elist_Id;
30025 Global_Seen : out Boolean)
30026 is
30027 procedure Collect_Dependency_Clause (Clause : Node_Id);
30028 -- Collect all relevant items from a dependency clause
30029
30030 procedure Collect_Global_List
30031 (List : Node_Id;
30032 Mode : Name_Id := Name_Input);
30033 -- Collect all relevant items from a global list
30034
30035 -------------------------------
30036 -- Collect_Dependency_Clause --
30037 -------------------------------
30038
30039 procedure Collect_Dependency_Clause (Clause : Node_Id) is
30040 procedure Collect_Dependency_Item
30041 (Item : Node_Id;
30042 Is_Input : Boolean);
30043 -- Add an item to the proper subprogram input or output collection
30044
30045 -----------------------------
30046 -- Collect_Dependency_Item --
30047 -----------------------------
30048
30049 procedure Collect_Dependency_Item
30050 (Item : Node_Id;
30051 Is_Input : Boolean)
30052 is
30053 Extra : Node_Id;
30054
30055 begin
30056 -- Nothing to collect when the item is null
30057
30058 if Nkind (Item) = N_Null then
30059 null;
30060
30061 -- Ditto for attribute 'Result
30062
30063 elsif Is_Attribute_Result (Item) then
30064 null;
30065
30066 -- Multiple items appear as an aggregate
30067
30068 elsif Nkind (Item) = N_Aggregate then
30069 Extra := First (Expressions (Item));
30070 while Present (Extra) loop
30071 Collect_Dependency_Item (Extra, Is_Input);
30072 Next (Extra);
30073 end loop;
30074
30075 -- Otherwise this is a solitary item
30076
30077 else
30078 if Is_Input then
30079 Append_New_Elmt (Item, Subp_Inputs);
30080 else
30081 Append_New_Elmt (Item, Subp_Outputs);
30082 end if;
30083 end if;
30084 end Collect_Dependency_Item;
30085
30086 -- Start of processing for Collect_Dependency_Clause
30087
30088 begin
30089 if Nkind (Clause) = N_Null then
30090 null;
30091
30092 -- A dependency clause appears as component association
30093
30094 elsif Nkind (Clause) = N_Component_Association then
30095 Collect_Dependency_Item
30096 (Item => Expression (Clause),
30097 Is_Input => True);
30098
30099 Collect_Dependency_Item
30100 (Item => First (Choices (Clause)),
30101 Is_Input => False);
30102
30103 -- To accommodate partial decoration of disabled SPARK features, this
30104 -- routine may be called with illegal input. If this is the case, do
30105 -- not raise Program_Error.
30106
30107 else
30108 null;
30109 end if;
30110 end Collect_Dependency_Clause;
30111
30112 -------------------------
30113 -- Collect_Global_List --
30114 -------------------------
30115
30116 procedure Collect_Global_List
30117 (List : Node_Id;
30118 Mode : Name_Id := Name_Input)
30119 is
30120 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
30121 -- Add an item to the proper subprogram input or output collection
30122
30123 -------------------------
30124 -- Collect_Global_Item --
30125 -------------------------
30126
30127 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
30128 begin
30129 if Mode in Name_In_Out | Name_Input then
30130 Append_New_Elmt (Item, Subp_Inputs);
30131 end if;
30132
30133 if Mode in Name_In_Out | Name_Output then
30134 Append_New_Elmt (Item, Subp_Outputs);
30135 end if;
30136 end Collect_Global_Item;
30137
30138 -- Local variables
30139
30140 Assoc : Node_Id;
30141 Item : Node_Id;
30142
30143 -- Start of processing for Collect_Global_List
30144
30145 begin
30146 if Nkind (List) = N_Null then
30147 null;
30148
30149 -- Single global item declaration
30150
30151 elsif Nkind (List) in N_Expanded_Name
30152 | N_Identifier
30153 | N_Selected_Component
30154 then
30155 Collect_Global_Item (List, Mode);
30156
30157 -- Simple global list or moded global list declaration
30158
30159 elsif Nkind (List) = N_Aggregate then
30160 if Present (Expressions (List)) then
30161 Item := First (Expressions (List));
30162 while Present (Item) loop
30163 Collect_Global_Item (Item, Mode);
30164 Next (Item);
30165 end loop;
30166
30167 else
30168 Assoc := First (Component_Associations (List));
30169 while Present (Assoc) loop
30170 Collect_Global_List
30171 (List => Expression (Assoc),
30172 Mode => Chars (First (Choices (Assoc))));
30173 Next (Assoc);
30174 end loop;
30175 end if;
30176
30177 -- To accommodate partial decoration of disabled SPARK features, this
30178 -- routine may be called with illegal input. If this is the case, do
30179 -- not raise Program_Error.
30180
30181 else
30182 null;
30183 end if;
30184 end Collect_Global_List;
30185
30186 -- Local variables
30187
30188 Clause : Node_Id;
30189 Clauses : Node_Id;
30190 Depends : Node_Id;
30191 Formal : Entity_Id;
30192 Global : Node_Id;
30193 Spec_Id : Entity_Id := Empty;
30194 Subp_Decl : Node_Id;
30195 Typ : Entity_Id;
30196
30197 -- Start of processing for Collect_Subprogram_Inputs_Outputs
30198
30199 begin
30200 Global_Seen := False;
30201
30202 -- Process all formal parameters of entries, [generic] subprograms, and
30203 -- their bodies.
30204
30205 if Ekind (Subp_Id) in E_Entry
30206 | E_Entry_Family
30207 | E_Function
30208 | E_Generic_Function
30209 | E_Generic_Procedure
30210 | E_Procedure
30211 | E_Subprogram_Body
30212 then
30213 Subp_Decl := Unit_Declaration_Node (Subp_Id);
30214 Spec_Id := Unique_Defining_Entity (Subp_Decl);
30215
30216 -- Process all formal parameters
30217
30218 Formal := First_Entity (Spec_Id);
30219 while Present (Formal) loop
30220 if Ekind (Formal) in E_In_Out_Parameter | E_In_Parameter then
30221
30222 -- IN parameters can act as output when the related type is
30223 -- access-to-variable.
30224
30225 if Ekind (Formal) = E_In_Parameter
30226 and then Is_Access_Variable (Etype (Formal))
30227 then
30228 Append_New_Elmt (Formal, Subp_Outputs);
30229 end if;
30230
30231 Append_New_Elmt (Formal, Subp_Inputs);
30232 end if;
30233
30234 if Ekind (Formal) in E_In_Out_Parameter | E_Out_Parameter then
30235 Append_New_Elmt (Formal, Subp_Outputs);
30236
30237 -- OUT parameters can act as inputs when the related type is
30238 -- tagged, unconstrained array, unconstrained record, or record
30239 -- with unconstrained components.
30240
30241 if Ekind (Formal) = E_Out_Parameter
30242 and then Is_Unconstrained_Or_Tagged_Item (Formal)
30243 then
30244 Append_New_Elmt (Formal, Subp_Inputs);
30245 end if;
30246 end if;
30247
30248 Next_Entity (Formal);
30249 end loop;
30250
30251 -- Otherwise the input denotes a task type, a task body, or the
30252 -- anonymous object created for a single task type.
30253
30254 elsif Ekind (Subp_Id) in E_Task_Type | E_Task_Body
30255 or else Is_Single_Task_Object (Subp_Id)
30256 then
30257 Subp_Decl := Declaration_Node (Subp_Id);
30258 Spec_Id := Unique_Defining_Entity (Subp_Decl);
30259 end if;
30260
30261 -- When processing an entry, subprogram or task body, look for pragmas
30262 -- Refined_Depends and Refined_Global as they specify the inputs and
30263 -- outputs.
30264
30265 if Is_Entry_Body (Subp_Id)
30266 or else Ekind (Subp_Id) in E_Subprogram_Body | E_Task_Body
30267 then
30268 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
30269 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
30270
30271 -- Subprogram declaration or stand-alone body case, look for pragmas
30272 -- Depends and Global.
30273
30274 else
30275 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
30276 Global := Get_Pragma (Spec_Id, Pragma_Global);
30277 end if;
30278
30279 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
30280 -- because it provides finer granularity of inputs and outputs.
30281
30282 if Present (Global) then
30283 Global_Seen := True;
30284 Collect_Global_List (Expression (Get_Argument (Global, Spec_Id)));
30285
30286 -- When the related subprogram lacks pragma [Refined_]Global, fall back
30287 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
30288 -- the inputs and outputs from [Refined_]Depends.
30289
30290 elsif Synthesize and then Present (Depends) then
30291 Clauses := Expression (Get_Argument (Depends, Spec_Id));
30292
30293 -- Multiple dependency clauses appear as an aggregate
30294
30295 if Nkind (Clauses) = N_Aggregate then
30296 Clause := First (Component_Associations (Clauses));
30297 while Present (Clause) loop
30298 Collect_Dependency_Clause (Clause);
30299 Next (Clause);
30300 end loop;
30301
30302 -- Otherwise this is a single dependency clause
30303
30304 else
30305 Collect_Dependency_Clause (Clauses);
30306 end if;
30307 end if;
30308
30309 -- The current instance of a protected type acts as a formal parameter
30310 -- of mode IN for functions and IN OUT for entries and procedures
30311 -- (SPARK RM 6.1.4).
30312
30313 if Ekind (Scope (Spec_Id)) = E_Protected_Type then
30314 Typ := Scope (Spec_Id);
30315
30316 -- Use the anonymous object when the type is single protected
30317
30318 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
30319 Typ := Anonymous_Object (Typ);
30320 end if;
30321
30322 Append_New_Elmt (Typ, Subp_Inputs);
30323
30324 if Ekind (Spec_Id) in E_Entry | E_Entry_Family | E_Procedure then
30325 Append_New_Elmt (Typ, Subp_Outputs);
30326 end if;
30327
30328 -- The current instance of a task type acts as a formal parameter of
30329 -- mode IN OUT (SPARK RM 6.1.4).
30330
30331 elsif Ekind (Spec_Id) = E_Task_Type then
30332 Typ := Spec_Id;
30333
30334 -- Use the anonymous object when the type is single task
30335
30336 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
30337 Typ := Anonymous_Object (Typ);
30338 end if;
30339
30340 Append_New_Elmt (Typ, Subp_Inputs);
30341 Append_New_Elmt (Typ, Subp_Outputs);
30342
30343 elsif Is_Single_Task_Object (Spec_Id) then
30344 Append_New_Elmt (Spec_Id, Subp_Inputs);
30345 Append_New_Elmt (Spec_Id, Subp_Outputs);
30346 end if;
30347 end Collect_Subprogram_Inputs_Outputs;
30348
30349 ---------------------------
30350 -- Contract_Freeze_Error --
30351 ---------------------------
30352
30353 procedure Contract_Freeze_Error
30354 (Contract_Id : Entity_Id;
30355 Freeze_Id : Entity_Id)
30356 is
30357 begin
30358 Error_Msg_Name_1 := Chars (Contract_Id);
30359 Error_Msg_Sloc := Sloc (Freeze_Id);
30360
30361 SPARK_Msg_NE
30362 ("body & declared # freezes the contract of%", Contract_Id, Freeze_Id);
30363 SPARK_Msg_N
30364 ("\all contractual items must be declared before body #", Contract_Id);
30365 end Contract_Freeze_Error;
30366
30367 ---------------------------------
30368 -- Delay_Config_Pragma_Analyze --
30369 ---------------------------------
30370
30371 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
30372 begin
30373 return Pragma_Name_Unmapped (N)
30374 in Name_Interrupt_State | Name_Priority_Specific_Dispatching;
30375 end Delay_Config_Pragma_Analyze;
30376
30377 -----------------------
30378 -- Duplication_Error --
30379 -----------------------
30380
30381 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
30382 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
30383 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
30384
30385 begin
30386 Error_Msg_Sloc := Sloc (Prev);
30387 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
30388
30389 -- Emit a precise message to distinguish between source pragmas and
30390 -- pragmas generated from aspects. The ordering of the two pragmas is
30391 -- the following:
30392
30393 -- Prev -- ok
30394 -- Prag -- duplicate
30395
30396 -- No error is emitted when both pragmas come from aspects because this
30397 -- is already detected by the general aspect analysis mechanism.
30398
30399 if Prag_From_Asp and Prev_From_Asp then
30400 null;
30401 elsif Prag_From_Asp then
30402 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
30403 elsif Prev_From_Asp then
30404 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
30405 else
30406 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
30407 end if;
30408 end Duplication_Error;
30409
30410 ------------------------------
30411 -- Find_Encapsulating_State --
30412 ------------------------------
30413
30414 function Find_Encapsulating_State
30415 (States : Elist_Id;
30416 Constit_Id : Entity_Id) return Entity_Id
30417 is
30418 State_Id : Entity_Id;
30419
30420 begin
30421 -- Since a constituent may be part of a larger constituent set, climb
30422 -- the encapsulating state chain looking for a state that appears in
30423 -- States.
30424
30425 State_Id := Encapsulating_State (Constit_Id);
30426 while Present (State_Id) loop
30427 if Contains (States, State_Id) then
30428 return State_Id;
30429 end if;
30430
30431 State_Id := Encapsulating_State (State_Id);
30432 end loop;
30433
30434 return Empty;
30435 end Find_Encapsulating_State;
30436
30437 --------------------------
30438 -- Find_Related_Context --
30439 --------------------------
30440
30441 function Find_Related_Context
30442 (Prag : Node_Id;
30443 Do_Checks : Boolean := False) return Node_Id
30444 is
30445 Stmt : Node_Id;
30446
30447 begin
30448 Stmt := Prev (Prag);
30449 while Present (Stmt) loop
30450
30451 -- Skip prior pragmas, but check for duplicates
30452
30453 if Nkind (Stmt) = N_Pragma then
30454 if Do_Checks
30455 and then Pragma_Name (Stmt) = Pragma_Name (Prag)
30456 then
30457 Duplication_Error
30458 (Prag => Prag,
30459 Prev => Stmt);
30460 end if;
30461
30462 -- Skip internally generated code
30463
30464 elsif not Comes_From_Source (Stmt)
30465 and then not Comes_From_Source (Original_Node (Stmt))
30466 then
30467
30468 -- The anonymous object created for a single concurrent type is a
30469 -- suitable context.
30470
30471 if Nkind (Stmt) = N_Object_Declaration
30472 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
30473 then
30474 return Stmt;
30475 end if;
30476
30477 -- Return the current source construct
30478
30479 else
30480 return Stmt;
30481 end if;
30482
30483 Prev (Stmt);
30484 end loop;
30485
30486 return Empty;
30487 end Find_Related_Context;
30488
30489 --------------------------------------
30490 -- Find_Related_Declaration_Or_Body --
30491 --------------------------------------
30492
30493 function Find_Related_Declaration_Or_Body
30494 (Prag : Node_Id;
30495 Do_Checks : Boolean := False) return Node_Id
30496 is
30497 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
30498
30499 procedure Expression_Function_Error;
30500 -- Emit an error concerning pragma Prag that illegaly applies to an
30501 -- expression function.
30502
30503 -------------------------------
30504 -- Expression_Function_Error --
30505 -------------------------------
30506
30507 procedure Expression_Function_Error is
30508 begin
30509 Error_Msg_Name_1 := Prag_Nam;
30510
30511 -- Emit a precise message to distinguish between source pragmas and
30512 -- pragmas generated from aspects.
30513
30514 if From_Aspect_Specification (Prag) then
30515 Error_Msg_N
30516 ("aspect % cannot apply to a stand alone expression function",
30517 Prag);
30518 else
30519 Error_Msg_N
30520 ("pragma % cannot apply to a stand alone expression function",
30521 Prag);
30522 end if;
30523 end Expression_Function_Error;
30524
30525 -- Local variables
30526
30527 Context : constant Node_Id := Parent (Prag);
30528 Stmt : Node_Id;
30529
30530 Look_For_Body : constant Boolean :=
30531 Prag_Nam in Name_Refined_Depends
30532 | Name_Refined_Global
30533 | Name_Refined_Post
30534 | Name_Refined_State;
30535 -- Refinement pragmas must be associated with a subprogram body [stub]
30536
30537 -- Start of processing for Find_Related_Declaration_Or_Body
30538
30539 begin
30540 Stmt := Prev (Prag);
30541 while Present (Stmt) loop
30542
30543 -- Skip prior pragmas, but check for duplicates. Pragmas produced
30544 -- by splitting a complex pre/postcondition are not considered to
30545 -- be duplicates.
30546
30547 if Nkind (Stmt) = N_Pragma then
30548 if Do_Checks
30549 and then not Split_PPC (Stmt)
30550 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
30551 then
30552 Duplication_Error
30553 (Prag => Prag,
30554 Prev => Stmt);
30555 end if;
30556
30557 -- Emit an error when a refinement pragma appears on an expression
30558 -- function without a completion.
30559
30560 elsif Do_Checks
30561 and then Look_For_Body
30562 and then Nkind (Stmt) = N_Subprogram_Declaration
30563 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
30564 and then not Has_Completion (Defining_Entity (Stmt))
30565 then
30566 Expression_Function_Error;
30567 return Empty;
30568
30569 -- The refinement pragma applies to a subprogram body stub
30570
30571 elsif Look_For_Body
30572 and then Nkind (Stmt) = N_Subprogram_Body_Stub
30573 then
30574 return Stmt;
30575
30576 -- Skip internally generated code
30577
30578 elsif not Comes_From_Source (Stmt) then
30579
30580 -- The anonymous object created for a single concurrent type is a
30581 -- suitable context.
30582
30583 if Nkind (Stmt) = N_Object_Declaration
30584 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
30585 then
30586 return Stmt;
30587
30588 elsif Nkind (Stmt) = N_Subprogram_Declaration then
30589
30590 -- The subprogram declaration is an internally generated spec
30591 -- for an expression function.
30592
30593 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
30594 return Stmt;
30595
30596 -- The subprogram declaration is an internally generated spec
30597 -- for a stand-alone subrogram body declared inside a protected
30598 -- body.
30599
30600 elsif Present (Corresponding_Body (Stmt))
30601 and then Comes_From_Source (Corresponding_Body (Stmt))
30602 and then Is_Protected_Type (Current_Scope)
30603 then
30604 return Stmt;
30605
30606 -- The subprogram is actually an instance housed within an
30607 -- anonymous wrapper package.
30608
30609 elsif Present (Generic_Parent (Specification (Stmt))) then
30610 return Stmt;
30611
30612 -- Ada 2020: contract on formal subprogram or on generated
30613 -- Access_Subprogram_Wrapper, which appears after the related
30614 -- Access_Subprogram declaration.
30615
30616 elsif Is_Generic_Actual_Subprogram (Defining_Entity (Stmt))
30617 and then Ada_Version >= Ada_2020
30618 then
30619 return Stmt;
30620
30621 elsif Is_Access_Subprogram_Wrapper (Defining_Entity (Stmt))
30622 and then Ada_Version >= Ada_2020
30623 then
30624 return Stmt;
30625 end if;
30626 end if;
30627
30628 -- Return the current construct which is either a subprogram body,
30629 -- a subprogram declaration or is illegal.
30630
30631 else
30632 return Stmt;
30633 end if;
30634
30635 Prev (Stmt);
30636 end loop;
30637
30638 -- If we fall through, then the pragma was either the first declaration
30639 -- or it was preceded by other pragmas and no source constructs.
30640
30641 -- The pragma is associated with a library-level subprogram
30642
30643 if Nkind (Context) = N_Compilation_Unit_Aux then
30644 return Unit (Parent (Context));
30645
30646 -- The pragma appears inside the declarations of an entry body
30647
30648 elsif Nkind (Context) = N_Entry_Body then
30649 return Context;
30650
30651 -- The pragma appears inside the statements of a subprogram body. This
30652 -- placement is the result of subprogram contract expansion.
30653
30654 elsif Is_Statement (Context)
30655 and then Present (Enclosing_HSS (Context))
30656 then
30657 return Parent (Enclosing_HSS (Context));
30658
30659 -- The pragma appears inside the declarative part of a package body
30660
30661 elsif Nkind (Context) = N_Package_Body then
30662 return Context;
30663
30664 -- The pragma appears inside the declarative part of a subprogram body
30665
30666 elsif Nkind (Context) = N_Subprogram_Body then
30667 return Context;
30668
30669 -- The pragma appears inside the declarative part of a task body
30670
30671 elsif Nkind (Context) = N_Task_Body then
30672 return Context;
30673
30674 -- The pragma appears inside the visible part of a package specification
30675
30676 elsif Nkind (Context) = N_Package_Specification then
30677 return Parent (Context);
30678
30679 -- The pragma is a byproduct of aspect expansion, return the related
30680 -- context of the original aspect. This case has a lower priority as
30681 -- the above circuitry pinpoints precisely the related context.
30682
30683 elsif Present (Corresponding_Aspect (Prag)) then
30684 return Parent (Corresponding_Aspect (Prag));
30685
30686 -- No candidate subprogram [body] found
30687
30688 else
30689 return Empty;
30690 end if;
30691 end Find_Related_Declaration_Or_Body;
30692
30693 ----------------------------------
30694 -- Find_Related_Package_Or_Body --
30695 ----------------------------------
30696
30697 function Find_Related_Package_Or_Body
30698 (Prag : Node_Id;
30699 Do_Checks : Boolean := False) return Node_Id
30700 is
30701 Context : constant Node_Id := Parent (Prag);
30702 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
30703 Stmt : Node_Id;
30704
30705 begin
30706 Stmt := Prev (Prag);
30707 while Present (Stmt) loop
30708
30709 -- Skip prior pragmas, but check for duplicates
30710
30711 if Nkind (Stmt) = N_Pragma then
30712 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
30713 Duplication_Error
30714 (Prag => Prag,
30715 Prev => Stmt);
30716 end if;
30717
30718 -- Skip internally generated code
30719
30720 elsif not Comes_From_Source (Stmt) then
30721 if Nkind (Stmt) = N_Subprogram_Declaration then
30722
30723 -- The subprogram declaration is an internally generated spec
30724 -- for an expression function.
30725
30726 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
30727 return Stmt;
30728
30729 -- The subprogram is actually an instance housed within an
30730 -- anonymous wrapper package.
30731
30732 elsif Present (Generic_Parent (Specification (Stmt))) then
30733 return Stmt;
30734 end if;
30735 end if;
30736
30737 -- Return the current source construct which is illegal
30738
30739 else
30740 return Stmt;
30741 end if;
30742
30743 Prev (Stmt);
30744 end loop;
30745
30746 -- If we fall through, then the pragma was either the first declaration
30747 -- or it was preceded by other pragmas and no source constructs.
30748
30749 -- The pragma is associated with a package. The immediate context in
30750 -- this case is the specification of the package.
30751
30752 if Nkind (Context) = N_Package_Specification then
30753 return Parent (Context);
30754
30755 -- The pragma appears in the declarations of a package body
30756
30757 elsif Nkind (Context) = N_Package_Body then
30758 return Context;
30759
30760 -- The pragma appears in the statements of a package body
30761
30762 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
30763 and then Nkind (Parent (Context)) = N_Package_Body
30764 then
30765 return Parent (Context);
30766
30767 -- The pragma is a byproduct of aspect expansion, return the related
30768 -- context of the original aspect. This case has a lower priority as
30769 -- the above circuitry pinpoints precisely the related context.
30770
30771 elsif Present (Corresponding_Aspect (Prag)) then
30772 return Parent (Corresponding_Aspect (Prag));
30773
30774 -- No candidate package [body] found
30775
30776 else
30777 return Empty;
30778 end if;
30779 end Find_Related_Package_Or_Body;
30780
30781 ------------------
30782 -- Get_Argument --
30783 ------------------
30784
30785 function Get_Argument
30786 (Prag : Node_Id;
30787 Context_Id : Entity_Id := Empty) return Node_Id
30788 is
30789 Args : constant List_Id := Pragma_Argument_Associations (Prag);
30790
30791 begin
30792 -- Use the expression of the original aspect when analyzing the template
30793 -- of a generic unit. In both cases the aspect's tree must be decorated
30794 -- to save the global references in the generic context.
30795
30796 if From_Aspect_Specification (Prag)
30797 and then (Present (Context_Id) and then Is_Generic_Unit (Context_Id))
30798 then
30799 return Corresponding_Aspect (Prag);
30800
30801 -- Otherwise use the expression of the pragma
30802
30803 elsif Present (Args) then
30804 return First (Args);
30805
30806 else
30807 return Empty;
30808 end if;
30809 end Get_Argument;
30810
30811 -------------------------
30812 -- Get_Base_Subprogram --
30813 -------------------------
30814
30815 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
30816 begin
30817 -- Follow subprogram renaming chain
30818
30819 if Is_Subprogram (Def_Id)
30820 and then Nkind (Parent (Declaration_Node (Def_Id))) =
30821 N_Subprogram_Renaming_Declaration
30822 and then Present (Alias (Def_Id))
30823 then
30824 return Alias (Def_Id);
30825 else
30826 return Def_Id;
30827 end if;
30828 end Get_Base_Subprogram;
30829
30830 -----------------------
30831 -- Get_SPARK_Mode_Type --
30832 -----------------------
30833
30834 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
30835 begin
30836 if N = Name_On then
30837 return On;
30838 elsif N = Name_Off then
30839 return Off;
30840
30841 -- Any other argument is illegal. Assume that no SPARK mode applies to
30842 -- avoid potential cascaded errors.
30843
30844 else
30845 return None;
30846 end if;
30847 end Get_SPARK_Mode_Type;
30848
30849 ------------------------------------
30850 -- Get_SPARK_Mode_From_Annotation --
30851 ------------------------------------
30852
30853 function Get_SPARK_Mode_From_Annotation
30854 (N : Node_Id) return SPARK_Mode_Type
30855 is
30856 Mode : Node_Id;
30857
30858 begin
30859 if Nkind (N) = N_Aspect_Specification then
30860 Mode := Expression (N);
30861
30862 else pragma Assert (Nkind (N) = N_Pragma);
30863 Mode := First (Pragma_Argument_Associations (N));
30864
30865 if Present (Mode) then
30866 Mode := Get_Pragma_Arg (Mode);
30867 end if;
30868 end if;
30869
30870 -- Aspect or pragma SPARK_Mode specifies an explicit mode
30871
30872 if Present (Mode) then
30873 if Nkind (Mode) = N_Identifier then
30874 return Get_SPARK_Mode_Type (Chars (Mode));
30875
30876 -- In case of a malformed aspect or pragma, return the default None
30877
30878 else
30879 return None;
30880 end if;
30881
30882 -- Otherwise the lack of an expression defaults SPARK_Mode to On
30883
30884 else
30885 return On;
30886 end if;
30887 end Get_SPARK_Mode_From_Annotation;
30888
30889 ---------------------------
30890 -- Has_Extra_Parentheses --
30891 ---------------------------
30892
30893 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
30894 Expr : Node_Id;
30895
30896 begin
30897 -- The aggregate should not have an expression list because a clause
30898 -- is always interpreted as a component association. The only way an
30899 -- expression list can sneak in is by adding extra parentheses around
30900 -- the individual clauses:
30901
30902 -- Depends (Output => Input) -- proper form
30903 -- Depends ((Output => Input)) -- extra parentheses
30904
30905 -- Since the extra parentheses are not allowed by the syntax of the
30906 -- pragma, flag them now to avoid emitting misleading errors down the
30907 -- line.
30908
30909 if Nkind (Clause) = N_Aggregate
30910 and then Present (Expressions (Clause))
30911 then
30912 Expr := First (Expressions (Clause));
30913 while Present (Expr) loop
30914
30915 -- A dependency clause surrounded by extra parentheses appears
30916 -- as an aggregate of component associations with an optional
30917 -- Paren_Count set.
30918
30919 if Nkind (Expr) = N_Aggregate
30920 and then Present (Component_Associations (Expr))
30921 then
30922 SPARK_Msg_N
30923 ("dependency clause contains extra parentheses", Expr);
30924
30925 -- Otherwise the expression is a malformed construct
30926
30927 else
30928 SPARK_Msg_N ("malformed dependency clause", Expr);
30929 end if;
30930
30931 Next (Expr);
30932 end loop;
30933
30934 return True;
30935 end if;
30936
30937 return False;
30938 end Has_Extra_Parentheses;
30939
30940 ----------------
30941 -- Initialize --
30942 ----------------
30943
30944 procedure Initialize is
30945 begin
30946 Externals.Init;
30947 Compile_Time_Warnings_Errors.Init;
30948 end Initialize;
30949
30950 --------
30951 -- ip --
30952 --------
30953
30954 procedure ip is
30955 begin
30956 Dummy := Dummy + 1;
30957 end ip;
30958
30959 -----------------------------
30960 -- Is_Config_Static_String --
30961 -----------------------------
30962
30963 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
30964
30965 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
30966 -- This is an internal recursive function that is just like the outer
30967 -- function except that it adds the string to the name buffer rather
30968 -- than placing the string in the name buffer.
30969
30970 ------------------------------
30971 -- Add_Config_Static_String --
30972 ------------------------------
30973
30974 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
30975 N : Node_Id;
30976 C : Char_Code;
30977
30978 begin
30979 N := Arg;
30980
30981 if Nkind (N) = N_Op_Concat then
30982 if Add_Config_Static_String (Left_Opnd (N)) then
30983 N := Right_Opnd (N);
30984 else
30985 return False;
30986 end if;
30987 end if;
30988
30989 if Nkind (N) /= N_String_Literal then
30990 Error_Msg_N ("string literal expected for pragma argument", N);
30991 return False;
30992
30993 else
30994 for J in 1 .. String_Length (Strval (N)) loop
30995 C := Get_String_Char (Strval (N), J);
30996
30997 if not In_Character_Range (C) then
30998 Error_Msg
30999 ("string literal contains invalid wide character",
31000 Sloc (N) + 1 + Source_Ptr (J));
31001 return False;
31002 end if;
31003
31004 Add_Char_To_Name_Buffer (Get_Character (C));
31005 end loop;
31006 end if;
31007
31008 return True;
31009 end Add_Config_Static_String;
31010
31011 -- Start of processing for Is_Config_Static_String
31012
31013 begin
31014 Name_Len := 0;
31015
31016 return Add_Config_Static_String (Arg);
31017 end Is_Config_Static_String;
31018
31019 -------------------------------
31020 -- Is_Elaboration_SPARK_Mode --
31021 -------------------------------
31022
31023 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
31024 begin
31025 pragma Assert
31026 (Nkind (N) = N_Pragma
31027 and then Pragma_Name (N) = Name_SPARK_Mode
31028 and then Is_List_Member (N));
31029
31030 -- Pragma SPARK_Mode affects the elaboration of a package body when it
31031 -- appears in the statement part of the body.
31032
31033 return
31034 Present (Parent (N))
31035 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
31036 and then List_Containing (N) = Statements (Parent (N))
31037 and then Present (Parent (Parent (N)))
31038 and then Nkind (Parent (Parent (N))) = N_Package_Body;
31039 end Is_Elaboration_SPARK_Mode;
31040
31041 -----------------------
31042 -- Is_Enabled_Pragma --
31043 -----------------------
31044
31045 function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is
31046 Arg : Node_Id;
31047
31048 begin
31049 if Present (Prag) then
31050 Arg := First (Pragma_Argument_Associations (Prag));
31051
31052 if Present (Arg) then
31053 return Is_True (Expr_Value (Get_Pragma_Arg (Arg)));
31054
31055 -- The lack of a Boolean argument automatically enables the pragma
31056
31057 else
31058 return True;
31059 end if;
31060
31061 -- The pragma is missing, therefore it is not enabled
31062
31063 else
31064 return False;
31065 end if;
31066 end Is_Enabled_Pragma;
31067
31068 -----------------------------------------
31069 -- Is_Non_Significant_Pragma_Reference --
31070 -----------------------------------------
31071
31072 -- This function makes use of the following static table which indicates
31073 -- whether appearance of some name in a given pragma is to be considered
31074 -- as a reference for the purposes of warnings about unreferenced objects.
31075
31076 -- -1 indicates that appearence in any argument is significant
31077 -- 0 indicates that appearance in any argument is not significant
31078 -- +n indicates that appearance as argument n is significant, but all
31079 -- other arguments are not significant
31080 -- 9n arguments from n on are significant, before n insignificant
31081
31082 Sig_Flags : constant array (Pragma_Id) of Int :=
31083 (Pragma_Abort_Defer => -1,
31084 Pragma_Abstract_State => -1,
31085 Pragma_Ada_83 => -1,
31086 Pragma_Ada_95 => -1,
31087 Pragma_Ada_05 => -1,
31088 Pragma_Ada_2005 => -1,
31089 Pragma_Ada_12 => -1,
31090 Pragma_Ada_2012 => -1,
31091 Pragma_Ada_2020 => -1,
31092 Pragma_Aggregate_Individually_Assign => 0,
31093 Pragma_All_Calls_Remote => -1,
31094 Pragma_Allow_Integer_Address => -1,
31095 Pragma_Annotate => 93,
31096 Pragma_Assert => -1,
31097 Pragma_Assert_And_Cut => -1,
31098 Pragma_Assertion_Policy => 0,
31099 Pragma_Assume => -1,
31100 Pragma_Assume_No_Invalid_Values => 0,
31101 Pragma_Async_Readers => 0,
31102 Pragma_Async_Writers => 0,
31103 Pragma_Asynchronous => 0,
31104 Pragma_Atomic => 0,
31105 Pragma_Atomic_Components => 0,
31106 Pragma_Attach_Handler => -1,
31107 Pragma_Attribute_Definition => 92,
31108 Pragma_Check => -1,
31109 Pragma_Check_Float_Overflow => 0,
31110 Pragma_Check_Name => 0,
31111 Pragma_Check_Policy => 0,
31112 Pragma_CPP_Class => 0,
31113 Pragma_CPP_Constructor => 0,
31114 Pragma_CPP_Virtual => 0,
31115 Pragma_CPP_Vtable => 0,
31116 Pragma_CPU => -1,
31117 Pragma_C_Pass_By_Copy => 0,
31118 Pragma_Comment => -1,
31119 Pragma_Common_Object => 0,
31120 Pragma_CUDA_Execute => -1,
31121 Pragma_CUDA_Global => -1,
31122 Pragma_Compile_Time_Error => -1,
31123 Pragma_Compile_Time_Warning => -1,
31124 Pragma_Compiler_Unit => -1,
31125 Pragma_Compiler_Unit_Warning => -1,
31126 Pragma_Complete_Representation => 0,
31127 Pragma_Complex_Representation => 0,
31128 Pragma_Component_Alignment => 0,
31129 Pragma_Constant_After_Elaboration => 0,
31130 Pragma_Contract_Cases => -1,
31131 Pragma_Controlled => 0,
31132 Pragma_Convention => 0,
31133 Pragma_Convention_Identifier => 0,
31134 Pragma_Deadline_Floor => -1,
31135 Pragma_Debug => -1,
31136 Pragma_Debug_Policy => 0,
31137 Pragma_Default_Initial_Condition => -1,
31138 Pragma_Default_Scalar_Storage_Order => 0,
31139 Pragma_Default_Storage_Pool => 0,
31140 Pragma_Depends => -1,
31141 Pragma_Detect_Blocking => 0,
31142 Pragma_Disable_Atomic_Synchronization => 0,
31143 Pragma_Discard_Names => 0,
31144 Pragma_Dispatching_Domain => -1,
31145 Pragma_Effective_Reads => 0,
31146 Pragma_Effective_Writes => 0,
31147 Pragma_Elaborate => 0,
31148 Pragma_Elaborate_All => 0,
31149 Pragma_Elaborate_Body => 0,
31150 Pragma_Elaboration_Checks => 0,
31151 Pragma_Eliminate => 0,
31152 Pragma_Enable_Atomic_Synchronization => 0,
31153 Pragma_Export => -1,
31154 Pragma_Export_Function => -1,
31155 Pragma_Export_Object => -1,
31156 Pragma_Export_Procedure => -1,
31157 Pragma_Export_Value => -1,
31158 Pragma_Export_Valued_Procedure => -1,
31159 Pragma_Extend_System => -1,
31160 Pragma_Extensions_Allowed => 0,
31161 Pragma_Extensions_Visible => 0,
31162 Pragma_External => -1,
31163 Pragma_External_Name_Casing => 0,
31164 Pragma_Fast_Math => 0,
31165 Pragma_Favor_Top_Level => 0,
31166 Pragma_Finalize_Storage_Only => 0,
31167 Pragma_Ghost => 0,
31168 Pragma_Global => -1,
31169 Pragma_Ident => -1,
31170 Pragma_Ignore_Pragma => 0,
31171 Pragma_Implementation_Defined => -1,
31172 Pragma_Implemented => -1,
31173 Pragma_Implicit_Packing => 0,
31174 Pragma_Import => 93,
31175 Pragma_Import_Function => 0,
31176 Pragma_Import_Object => 0,
31177 Pragma_Import_Procedure => 0,
31178 Pragma_Import_Valued_Procedure => 0,
31179 Pragma_Independent => 0,
31180 Pragma_Independent_Components => 0,
31181 Pragma_Initial_Condition => -1,
31182 Pragma_Initialize_Scalars => 0,
31183 Pragma_Initializes => -1,
31184 Pragma_Inline => 0,
31185 Pragma_Inline_Always => 0,
31186 Pragma_Inline_Generic => 0,
31187 Pragma_Inspection_Point => -1,
31188 Pragma_Interface => 92,
31189 Pragma_Interface_Name => 0,
31190 Pragma_Interrupt_Handler => -1,
31191 Pragma_Interrupt_Priority => -1,
31192 Pragma_Interrupt_State => -1,
31193 Pragma_Invariant => -1,
31194 Pragma_Keep_Names => 0,
31195 Pragma_License => 0,
31196 Pragma_Link_With => -1,
31197 Pragma_Linker_Alias => -1,
31198 Pragma_Linker_Constructor => -1,
31199 Pragma_Linker_Destructor => -1,
31200 Pragma_Linker_Options => -1,
31201 Pragma_Linker_Section => -1,
31202 Pragma_List => 0,
31203 Pragma_Lock_Free => 0,
31204 Pragma_Locking_Policy => 0,
31205 Pragma_Loop_Invariant => -1,
31206 Pragma_Loop_Optimize => 0,
31207 Pragma_Loop_Variant => -1,
31208 Pragma_Machine_Attribute => -1,
31209 Pragma_Main => -1,
31210 Pragma_Main_Storage => -1,
31211 Pragma_Max_Entry_Queue_Depth => 0,
31212 Pragma_Max_Entry_Queue_Length => 0,
31213 Pragma_Max_Queue_Length => 0,
31214 Pragma_Memory_Size => 0,
31215 Pragma_No_Body => 0,
31216 Pragma_No_Caching => 0,
31217 Pragma_No_Component_Reordering => -1,
31218 Pragma_No_Elaboration_Code_All => 0,
31219 Pragma_No_Heap_Finalization => 0,
31220 Pragma_No_Inline => 0,
31221 Pragma_No_Return => 0,
31222 Pragma_No_Run_Time => -1,
31223 Pragma_No_Strict_Aliasing => -1,
31224 Pragma_No_Tagged_Streams => 0,
31225 Pragma_Normalize_Scalars => 0,
31226 Pragma_Obsolescent => 0,
31227 Pragma_Optimize => 0,
31228 Pragma_Optimize_Alignment => 0,
31229 Pragma_Ordered => 0,
31230 Pragma_Overflow_Mode => 0,
31231 Pragma_Overriding_Renamings => 0,
31232 Pragma_Pack => 0,
31233 Pragma_Page => 0,
31234 Pragma_Part_Of => 0,
31235 Pragma_Partition_Elaboration_Policy => 0,
31236 Pragma_Passive => 0,
31237 Pragma_Persistent_BSS => 0,
31238 Pragma_Post => -1,
31239 Pragma_Postcondition => -1,
31240 Pragma_Post_Class => -1,
31241 Pragma_Pre => -1,
31242 Pragma_Precondition => -1,
31243 Pragma_Predicate => -1,
31244 Pragma_Predicate_Failure => -1,
31245 Pragma_Preelaborable_Initialization => -1,
31246 Pragma_Preelaborate => 0,
31247 Pragma_Prefix_Exception_Messages => 0,
31248 Pragma_Pre_Class => -1,
31249 Pragma_Priority => -1,
31250 Pragma_Priority_Specific_Dispatching => 0,
31251 Pragma_Profile => 0,
31252 Pragma_Profile_Warnings => 0,
31253 Pragma_Propagate_Exceptions => 0,
31254 Pragma_Provide_Shift_Operators => 0,
31255 Pragma_Psect_Object => 0,
31256 Pragma_Pure => 0,
31257 Pragma_Pure_Function => 0,
31258 Pragma_Queuing_Policy => 0,
31259 Pragma_Rational => 0,
31260 Pragma_Ravenscar => 0,
31261 Pragma_Refined_Depends => -1,
31262 Pragma_Refined_Global => -1,
31263 Pragma_Refined_Post => -1,
31264 Pragma_Refined_State => -1,
31265 Pragma_Relative_Deadline => 0,
31266 Pragma_Remote_Access_Type => -1,
31267 Pragma_Remote_Call_Interface => -1,
31268 Pragma_Remote_Types => -1,
31269 Pragma_Rename_Pragma => 0,
31270 Pragma_Restricted_Run_Time => 0,
31271 Pragma_Restriction_Warnings => 0,
31272 Pragma_Restrictions => 0,
31273 Pragma_Reviewable => -1,
31274 Pragma_Secondary_Stack_Size => -1,
31275 Pragma_Share_Generic => 0,
31276 Pragma_Shared => 0,
31277 Pragma_Shared_Passive => 0,
31278 Pragma_Short_Circuit_And_Or => 0,
31279 Pragma_Short_Descriptors => 0,
31280 Pragma_Simple_Storage_Pool_Type => 0,
31281 Pragma_Source_File_Name => 0,
31282 Pragma_Source_File_Name_Project => 0,
31283 Pragma_Source_Reference => 0,
31284 Pragma_SPARK_Mode => 0,
31285 Pragma_Static_Elaboration_Desired => 0,
31286 Pragma_Storage_Size => -1,
31287 Pragma_Storage_Unit => 0,
31288 Pragma_Stream_Convert => 0,
31289 Pragma_Style_Checks => 0,
31290 Pragma_Subprogram_Variant => -1,
31291 Pragma_Subtitle => 0,
31292 Pragma_Suppress => 0,
31293 Pragma_Suppress_All => 0,
31294 Pragma_Suppress_Debug_Info => 0,
31295 Pragma_Suppress_Exception_Locations => 0,
31296 Pragma_Suppress_Initialization => 0,
31297 Pragma_System_Name => 0,
31298 Pragma_Task_Dispatching_Policy => 0,
31299 Pragma_Task_Info => -1,
31300 Pragma_Task_Name => -1,
31301 Pragma_Task_Storage => -1,
31302 Pragma_Test_Case => -1,
31303 Pragma_Thread_Local_Storage => -1,
31304 Pragma_Time_Slice => -1,
31305 Pragma_Title => 0,
31306 Pragma_Type_Invariant => -1,
31307 Pragma_Type_Invariant_Class => -1,
31308 Pragma_Unchecked_Union => 0,
31309 Pragma_Unevaluated_Use_Of_Old => 0,
31310 Pragma_Unimplemented_Unit => 0,
31311 Pragma_Universal_Aliasing => 0,
31312 Pragma_Universal_Data => 0,
31313 Pragma_Unmodified => 0,
31314 Pragma_Unreferenced => 0,
31315 Pragma_Unreferenced_Objects => 0,
31316 Pragma_Unreserve_All_Interrupts => 0,
31317 Pragma_Unsuppress => 0,
31318 Pragma_Unused => 0,
31319 Pragma_Use_VADS_Size => 0,
31320 Pragma_Validity_Checks => 0,
31321 Pragma_Volatile => 0,
31322 Pragma_Volatile_Components => 0,
31323 Pragma_Volatile_Full_Access => 0,
31324 Pragma_Volatile_Function => 0,
31325 Pragma_Warning_As_Error => 0,
31326 Pragma_Warnings => 0,
31327 Pragma_Weak_External => 0,
31328 Pragma_Wide_Character_Encoding => 0,
31329 Unknown_Pragma => 0);
31330
31331 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
31332 Id : Pragma_Id;
31333 P : Node_Id;
31334 C : Int;
31335 AN : Nat;
31336
31337 function Arg_No return Nat;
31338 -- Returns an integer showing what argument we are in. A value of
31339 -- zero means we are not in any of the arguments.
31340
31341 ------------
31342 -- Arg_No --
31343 ------------
31344
31345 function Arg_No return Nat is
31346 A : Node_Id;
31347 N : Nat;
31348
31349 begin
31350 A := First (Pragma_Argument_Associations (Parent (P)));
31351 N := 1;
31352 loop
31353 if No (A) then
31354 return 0;
31355 elsif A = P then
31356 return N;
31357 end if;
31358
31359 Next (A);
31360 N := N + 1;
31361 end loop;
31362 end Arg_No;
31363
31364 -- Start of processing for Non_Significant_Pragma_Reference
31365
31366 begin
31367 P := Parent (N);
31368
31369 if Nkind (P) /= N_Pragma_Argument_Association then
31370 return False;
31371
31372 else
31373 Id := Get_Pragma_Id (Parent (P));
31374 C := Sig_Flags (Id);
31375 AN := Arg_No;
31376
31377 if AN = 0 then
31378 return False;
31379 end if;
31380
31381 case C is
31382 when -1 =>
31383 return False;
31384
31385 when 0 =>
31386 return True;
31387
31388 when 92 .. 99 =>
31389 return AN < (C - 90);
31390
31391 when others =>
31392 return AN /= C;
31393 end case;
31394 end if;
31395 end Is_Non_Significant_Pragma_Reference;
31396
31397 ------------------------------
31398 -- Is_Pragma_String_Literal --
31399 ------------------------------
31400
31401 -- This function returns true if the corresponding pragma argument is a
31402 -- static string expression. These are the only cases in which string
31403 -- literals can appear as pragma arguments. We also allow a string literal
31404 -- as the first argument to pragma Assert (although it will of course
31405 -- always generate a type error).
31406
31407 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
31408 Pragn : constant Node_Id := Parent (Par);
31409 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
31410 Pname : constant Name_Id := Pragma_Name (Pragn);
31411 Argn : Natural;
31412 N : Node_Id;
31413
31414 begin
31415 Argn := 1;
31416 N := First (Assoc);
31417 loop
31418 exit when N = Par;
31419 Argn := Argn + 1;
31420 Next (N);
31421 end loop;
31422
31423 if Pname = Name_Assert then
31424 return True;
31425
31426 elsif Pname = Name_Export then
31427 return Argn > 2;
31428
31429 elsif Pname = Name_Ident then
31430 return Argn = 1;
31431
31432 elsif Pname = Name_Import then
31433 return Argn > 2;
31434
31435 elsif Pname = Name_Interface_Name then
31436 return Argn > 1;
31437
31438 elsif Pname = Name_Linker_Alias then
31439 return Argn = 2;
31440
31441 elsif Pname = Name_Linker_Section then
31442 return Argn = 2;
31443
31444 elsif Pname = Name_Machine_Attribute then
31445 return Argn = 2;
31446
31447 elsif Pname = Name_Source_File_Name then
31448 return True;
31449
31450 elsif Pname = Name_Source_Reference then
31451 return Argn = 2;
31452
31453 elsif Pname = Name_Title then
31454 return True;
31455
31456 elsif Pname = Name_Subtitle then
31457 return True;
31458
31459 else
31460 return False;
31461 end if;
31462 end Is_Pragma_String_Literal;
31463
31464 ---------------------------
31465 -- Is_Private_SPARK_Mode --
31466 ---------------------------
31467
31468 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
31469 begin
31470 pragma Assert
31471 (Nkind (N) = N_Pragma
31472 and then Pragma_Name (N) = Name_SPARK_Mode
31473 and then Is_List_Member (N));
31474
31475 -- For pragma SPARK_Mode to be private, it has to appear in the private
31476 -- declarations of a package.
31477
31478 return
31479 Present (Parent (N))
31480 and then Nkind (Parent (N)) = N_Package_Specification
31481 and then List_Containing (N) = Private_Declarations (Parent (N));
31482 end Is_Private_SPARK_Mode;
31483
31484 -------------------------------------
31485 -- Is_Unconstrained_Or_Tagged_Item --
31486 -------------------------------------
31487
31488 function Is_Unconstrained_Or_Tagged_Item
31489 (Item : Entity_Id) return Boolean
31490 is
31491 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
31492 -- Determine whether record type Typ has at least one unconstrained
31493 -- component.
31494
31495 ---------------------------------
31496 -- Has_Unconstrained_Component --
31497 ---------------------------------
31498
31499 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
31500 Comp : Entity_Id;
31501
31502 begin
31503 Comp := First_Component (Typ);
31504 while Present (Comp) loop
31505 if Is_Unconstrained_Or_Tagged_Item (Comp) then
31506 return True;
31507 end if;
31508
31509 Next_Component (Comp);
31510 end loop;
31511
31512 return False;
31513 end Has_Unconstrained_Component;
31514
31515 -- Local variables
31516
31517 Typ : constant Entity_Id := Etype (Item);
31518
31519 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
31520
31521 begin
31522 if Is_Tagged_Type (Typ) then
31523 return True;
31524
31525 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
31526 return True;
31527
31528 elsif Is_Record_Type (Typ) then
31529 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
31530 return True;
31531 else
31532 return Has_Unconstrained_Component (Typ);
31533 end if;
31534
31535 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
31536 return True;
31537
31538 else
31539 return False;
31540 end if;
31541 end Is_Unconstrained_Or_Tagged_Item;
31542
31543 -----------------------------
31544 -- Is_Valid_Assertion_Kind --
31545 -----------------------------
31546
31547 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
31548 begin
31549 case Nam is
31550 when
31551 -- RM defined
31552
31553 Name_Assert
31554 | Name_Static_Predicate
31555 | Name_Dynamic_Predicate
31556 | Name_Pre
31557 | Name_uPre
31558 | Name_Post
31559 | Name_uPost
31560 | Name_Type_Invariant
31561 | Name_uType_Invariant
31562
31563 -- Impl defined
31564
31565 | Name_Assert_And_Cut
31566 | Name_Assume
31567 | Name_Contract_Cases
31568 | Name_Debug
31569 | Name_Default_Initial_Condition
31570 | Name_Ghost
31571 | Name_Initial_Condition
31572 | Name_Invariant
31573 | Name_uInvariant
31574 | Name_Loop_Invariant
31575 | Name_Loop_Variant
31576 | Name_Postcondition
31577 | Name_Precondition
31578 | Name_Predicate
31579 | Name_Refined_Post
31580 | Name_Statement_Assertions
31581 | Name_Subprogram_Variant
31582 =>
31583 return True;
31584
31585 when others =>
31586 return False;
31587 end case;
31588 end Is_Valid_Assertion_Kind;
31589
31590 --------------------------------------
31591 -- Process_Compilation_Unit_Pragmas --
31592 --------------------------------------
31593
31594 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
31595 begin
31596 -- A special check for pragma Suppress_All, a very strange DEC pragma,
31597 -- strange because it comes at the end of the unit. Rational has the
31598 -- same name for a pragma, but treats it as a program unit pragma, In
31599 -- GNAT we just decide to allow it anywhere at all. If it appeared then
31600 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
31601 -- node, and we insert a pragma Suppress (All_Checks) at the start of
31602 -- the context clause to ensure the correct processing.
31603
31604 if Has_Pragma_Suppress_All (N) then
31605 Prepend_To (Context_Items (N),
31606 Make_Pragma (Sloc (N),
31607 Chars => Name_Suppress,
31608 Pragma_Argument_Associations => New_List (
31609 Make_Pragma_Argument_Association (Sloc (N),
31610 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
31611 end if;
31612
31613 -- Nothing else to do at the current time
31614
31615 end Process_Compilation_Unit_Pragmas;
31616
31617 --------------------------------------------
31618 -- Validate_Compile_Time_Warning_Or_Error --
31619 --------------------------------------------
31620
31621 procedure Validate_Compile_Time_Warning_Or_Error
31622 (N : Node_Id;
31623 Eloc : Source_Ptr)
31624 is
31625 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
31626 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
31627 Arg2 : constant Node_Id := Next (Arg1);
31628
31629 Pname : constant Name_Id := Pragma_Name_Unmapped (N);
31630 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
31631
31632 begin
31633 Analyze_And_Resolve (Arg1x, Standard_Boolean);
31634
31635 if Compile_Time_Known_Value (Arg1x) then
31636 if Is_True (Expr_Value (Arg1x)) then
31637
31638 -- We have already verified that the second argument is a static
31639 -- string expression. Its string value must be retrieved
31640 -- explicitly if it is a declared constant, otherwise it has
31641 -- been constant-folded previously.
31642
31643 declare
31644 Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
31645 Str : constant String_Id :=
31646 Strval (Expr_Value_S (Get_Pragma_Arg (Arg2)));
31647 Str_Len : constant Nat := String_Length (Str);
31648
31649 Force : constant Boolean :=
31650 Prag_Id = Pragma_Compile_Time_Warning
31651 and then Is_Spec_Name (Unit_Name (Current_Sem_Unit))
31652 and then (Ekind (Cent) /= E_Package
31653 or else not In_Private_Part (Cent));
31654 -- Set True if this is the warning case, and we are in the
31655 -- visible part of a package spec, or in a subprogram spec,
31656 -- in which case we want to force the client to see the
31657 -- warning, even though it is not in the main unit.
31658
31659 C : Character;
31660 CC : Char_Code;
31661 Cont : Boolean;
31662 Ptr : Nat;
31663
31664 begin
31665 -- Loop through segments of message separated by line feeds.
31666 -- We output these segments as separate messages with
31667 -- continuation marks for all but the first.
31668
31669 Cont := False;
31670 Ptr := 1;
31671 loop
31672 Error_Msg_Strlen := 0;
31673
31674 -- Loop to copy characters from argument to error message
31675 -- string buffer.
31676
31677 loop
31678 exit when Ptr > Str_Len;
31679 CC := Get_String_Char (Str, Ptr);
31680 Ptr := Ptr + 1;
31681
31682 -- Ignore wide chars ??? else store character
31683
31684 if In_Character_Range (CC) then
31685 C := Get_Character (CC);
31686 exit when C = ASCII.LF;
31687 Error_Msg_Strlen := Error_Msg_Strlen + 1;
31688 Error_Msg_String (Error_Msg_Strlen) := C;
31689 end if;
31690 end loop;
31691
31692 -- Here with one line ready to go
31693
31694 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
31695
31696 -- If this is a warning in a spec, then we want clients
31697 -- to see the warning, so mark the message with the
31698 -- special sequence !! to force the warning. In the case
31699 -- of a package spec, we do not force this if we are in
31700 -- the private part of the spec.
31701
31702 if Force then
31703 if Cont = False then
31704 Error_Msg
31705 ("<<~!!", Eloc, Is_Compile_Time_Pragma => True);
31706 Cont := True;
31707 else
31708 Error_Msg
31709 ("\<<~!!", Eloc, Is_Compile_Time_Pragma => True);
31710 end if;
31711
31712 -- Error, rather than warning, or in a body, so we do not
31713 -- need to force visibility for client (error will be
31714 -- output in any case, and this is the situation in which
31715 -- we do not want a client to get a warning, since the
31716 -- warning is in the body or the spec private part).
31717
31718 else
31719 if Cont = False then
31720 Error_Msg
31721 ("<<~", Eloc, Is_Compile_Time_Pragma => True);
31722 Cont := True;
31723 else
31724 Error_Msg
31725 ("\<<~", Eloc, Is_Compile_Time_Pragma => True);
31726 end if;
31727 end if;
31728
31729 exit when Ptr > Str_Len;
31730 end loop;
31731 end;
31732 end if;
31733
31734 -- Arg1x is not known at compile time, so possibly issue an error
31735 -- or warning. This can happen only if the pragma's processing
31736 -- was deferred until after the back end is run (see
31737 -- Process_Compile_Time_Warning_Or_Error). Note that the warning
31738 -- control switch applies to only the warning case.
31739
31740 elsif Prag_Id = Pragma_Compile_Time_Error then
31741 Error_Msg_N ("condition is not known at compile time", Arg1x);
31742
31743 elsif Warn_On_Unknown_Compile_Time_Warning then
31744 Error_Msg_N ("??condition is not known at compile time", Arg1x);
31745 end if;
31746 end Validate_Compile_Time_Warning_Or_Error;
31747
31748 ------------------------------------
31749 -- Record_Possible_Body_Reference --
31750 ------------------------------------
31751
31752 procedure Record_Possible_Body_Reference
31753 (State_Id : Entity_Id;
31754 Ref : Node_Id)
31755 is
31756 Context : Node_Id;
31757 Spec_Id : Entity_Id;
31758
31759 begin
31760 -- Ensure that we are dealing with a reference to a state
31761
31762 pragma Assert (Ekind (State_Id) = E_Abstract_State);
31763
31764 -- Climb the tree starting from the reference looking for a package body
31765 -- whose spec declares the referenced state. This criteria automatically
31766 -- excludes references in package specs which are legal. Note that it is
31767 -- not wise to emit an error now as the package body may lack pragma
31768 -- Refined_State or the referenced state may not be mentioned in the
31769 -- refinement. This approach avoids the generation of misleading errors.
31770
31771 Context := Ref;
31772 while Present (Context) loop
31773 if Nkind (Context) = N_Package_Body then
31774 Spec_Id := Corresponding_Spec (Context);
31775
31776 if Present (Abstract_States (Spec_Id))
31777 and then Contains (Abstract_States (Spec_Id), State_Id)
31778 then
31779 if No (Body_References (State_Id)) then
31780 Set_Body_References (State_Id, New_Elmt_List);
31781 end if;
31782
31783 Append_Elmt (Ref, To => Body_References (State_Id));
31784 exit;
31785 end if;
31786 end if;
31787
31788 Context := Parent (Context);
31789 end loop;
31790 end Record_Possible_Body_Reference;
31791
31792 ------------------------------------------
31793 -- Relocate_Pragmas_To_Anonymous_Object --
31794 ------------------------------------------
31795
31796 procedure Relocate_Pragmas_To_Anonymous_Object
31797 (Typ_Decl : Node_Id;
31798 Obj_Decl : Node_Id)
31799 is
31800 Decl : Node_Id;
31801 Def : Node_Id;
31802 Next_Decl : Node_Id;
31803
31804 begin
31805 if Nkind (Typ_Decl) = N_Protected_Type_Declaration then
31806 Def := Protected_Definition (Typ_Decl);
31807 else
31808 pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration);
31809 Def := Task_Definition (Typ_Decl);
31810 end if;
31811
31812 -- The concurrent definition has a visible declaration list. Inspect it
31813 -- and relocate all canidate pragmas.
31814
31815 if Present (Def) and then Present (Visible_Declarations (Def)) then
31816 Decl := First (Visible_Declarations (Def));
31817 while Present (Decl) loop
31818
31819 -- Preserve the following declaration for iteration purposes due
31820 -- to possible relocation of a pragma.
31821
31822 Next_Decl := Next (Decl);
31823
31824 if Nkind (Decl) = N_Pragma
31825 and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl))
31826 then
31827 Remove (Decl);
31828 Insert_After (Obj_Decl, Decl);
31829
31830 -- Skip internally generated code
31831
31832 elsif not Comes_From_Source (Decl) then
31833 null;
31834
31835 -- No candidate pragmas are available for relocation
31836
31837 else
31838 exit;
31839 end if;
31840
31841 Decl := Next_Decl;
31842 end loop;
31843 end if;
31844 end Relocate_Pragmas_To_Anonymous_Object;
31845
31846 ------------------------------
31847 -- Relocate_Pragmas_To_Body --
31848 ------------------------------
31849
31850 procedure Relocate_Pragmas_To_Body
31851 (Subp_Body : Node_Id;
31852 Target_Body : Node_Id := Empty)
31853 is
31854 procedure Relocate_Pragma (Prag : Node_Id);
31855 -- Remove a single pragma from its current list and add it to the
31856 -- declarations of the proper body (either Subp_Body or Target_Body).
31857
31858 ---------------------
31859 -- Relocate_Pragma --
31860 ---------------------
31861
31862 procedure Relocate_Pragma (Prag : Node_Id) is
31863 Decls : List_Id;
31864 Target : Node_Id;
31865
31866 begin
31867 -- When subprogram stubs or expression functions are involves, the
31868 -- destination declaration list belongs to the proper body.
31869
31870 if Present (Target_Body) then
31871 Target := Target_Body;
31872 else
31873 Target := Subp_Body;
31874 end if;
31875
31876 Decls := Declarations (Target);
31877
31878 if No (Decls) then
31879 Decls := New_List;
31880 Set_Declarations (Target, Decls);
31881 end if;
31882
31883 -- Unhook the pragma from its current list
31884
31885 Remove (Prag);
31886 Prepend (Prag, Decls);
31887 end Relocate_Pragma;
31888
31889 -- Local variables
31890
31891 Body_Id : constant Entity_Id :=
31892 Defining_Unit_Name (Specification (Subp_Body));
31893 Next_Stmt : Node_Id;
31894 Stmt : Node_Id;
31895
31896 -- Start of processing for Relocate_Pragmas_To_Body
31897
31898 begin
31899 -- Do not process a body that comes from a separate unit as no construct
31900 -- can possibly follow it.
31901
31902 if not Is_List_Member (Subp_Body) then
31903 return;
31904
31905 -- Do not relocate pragmas that follow a stub if the stub does not have
31906 -- a proper body.
31907
31908 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
31909 and then No (Target_Body)
31910 then
31911 return;
31912
31913 -- Do not process internally generated routine _Postconditions
31914
31915 elsif Ekind (Body_Id) = E_Procedure
31916 and then Chars (Body_Id) = Name_uPostconditions
31917 then
31918 return;
31919 end if;
31920
31921 -- Look at what is following the body. We are interested in certain kind
31922 -- of pragmas (either from source or byproducts of expansion) that can
31923 -- apply to a body [stub].
31924
31925 Stmt := Next (Subp_Body);
31926 while Present (Stmt) loop
31927
31928 -- Preserve the following statement for iteration purposes due to a
31929 -- possible relocation of a pragma.
31930
31931 Next_Stmt := Next (Stmt);
31932
31933 -- Move a candidate pragma following the body to the declarations of
31934 -- the body.
31935
31936 if Nkind (Stmt) = N_Pragma
31937 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
31938 then
31939
31940 -- If a source pragma Warnings follows the body, it applies to
31941 -- following statements and does not belong in the body.
31942
31943 if Get_Pragma_Id (Stmt) = Pragma_Warnings
31944 and then Comes_From_Source (Stmt)
31945 then
31946 null;
31947 else
31948 Relocate_Pragma (Stmt);
31949 end if;
31950
31951 -- Skip internally generated code
31952
31953 elsif not Comes_From_Source (Stmt) then
31954 null;
31955
31956 -- No candidate pragmas are available for relocation
31957
31958 else
31959 exit;
31960 end if;
31961
31962 Stmt := Next_Stmt;
31963 end loop;
31964 end Relocate_Pragmas_To_Body;
31965
31966 -------------------
31967 -- Resolve_State --
31968 -------------------
31969
31970 procedure Resolve_State (N : Node_Id) is
31971 Func : Entity_Id;
31972 State : Entity_Id;
31973
31974 begin
31975 if Is_Entity_Name (N) and then Present (Entity (N)) then
31976 Func := Entity (N);
31977
31978 -- Handle overloading of state names by functions. Traverse the
31979 -- homonym chain looking for an abstract state.
31980
31981 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
31982 pragma Assert (Is_Overloaded (N));
31983
31984 State := Homonym (Func);
31985 while Present (State) loop
31986 if Ekind (State) = E_Abstract_State then
31987
31988 -- Resolve the overloading by setting the proper entity of
31989 -- the reference to that of the state.
31990
31991 Set_Etype (N, Standard_Void_Type);
31992 Set_Entity (N, State);
31993 Set_Is_Overloaded (N, False);
31994
31995 Generate_Reference (State, N);
31996 return;
31997 end if;
31998
31999 State := Homonym (State);
32000 end loop;
32001
32002 -- A function can never act as a state. If the homonym chain does
32003 -- not contain a corresponding state, then something went wrong in
32004 -- the overloading mechanism.
32005
32006 raise Program_Error;
32007 end if;
32008 end if;
32009 end Resolve_State;
32010
32011 ----------------------------
32012 -- Rewrite_Assertion_Kind --
32013 ----------------------------
32014
32015 procedure Rewrite_Assertion_Kind
32016 (N : Node_Id;
32017 From_Policy : Boolean := False)
32018 is
32019 Nam : Name_Id;
32020
32021 begin
32022 Nam := No_Name;
32023 if Nkind (N) = N_Attribute_Reference
32024 and then Attribute_Name (N) = Name_Class
32025 and then Nkind (Prefix (N)) = N_Identifier
32026 then
32027 case Chars (Prefix (N)) is
32028 when Name_Pre =>
32029 Nam := Name_uPre;
32030
32031 when Name_Post =>
32032 Nam := Name_uPost;
32033
32034 when Name_Type_Invariant =>
32035 Nam := Name_uType_Invariant;
32036
32037 when Name_Invariant =>
32038 Nam := Name_uInvariant;
32039
32040 when others =>
32041 return;
32042 end case;
32043
32044 -- Recommend standard use of aspect names Pre/Post
32045
32046 elsif Nkind (N) = N_Identifier
32047 and then From_Policy
32048 and then Serious_Errors_Detected = 0
32049 then
32050 if Chars (N) = Name_Precondition
32051 or else Chars (N) = Name_Postcondition
32052 then
32053 Error_Msg_N ("Check_Policy is a non-standard pragma??", N);
32054 Error_Msg_N
32055 ("\use Assertion_Policy and aspect names Pre/Post for "
32056 & "Ada2012 conformance?", N);
32057 end if;
32058
32059 return;
32060 end if;
32061
32062 if Nam /= No_Name then
32063 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
32064 end if;
32065 end Rewrite_Assertion_Kind;
32066
32067 --------
32068 -- rv --
32069 --------
32070
32071 procedure rv is
32072 begin
32073 Dummy := Dummy + 1;
32074 end rv;
32075
32076 --------------------------------
32077 -- Set_Encoded_Interface_Name --
32078 --------------------------------
32079
32080 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
32081 Str : constant String_Id := Strval (S);
32082 Len : constant Nat := String_Length (Str);
32083 CC : Char_Code;
32084 C : Character;
32085 J : Pos;
32086
32087 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
32088
32089 procedure Encode;
32090 -- Stores encoded value of character code CC. The encoding we use an
32091 -- underscore followed by four lower case hex digits.
32092
32093 ------------
32094 -- Encode --
32095 ------------
32096
32097 procedure Encode is
32098 begin
32099 Store_String_Char (Get_Char_Code ('_'));
32100 Store_String_Char
32101 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
32102 Store_String_Char
32103 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
32104 Store_String_Char
32105 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
32106 Store_String_Char
32107 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
32108 end Encode;
32109
32110 -- Start of processing for Set_Encoded_Interface_Name
32111
32112 begin
32113 -- If first character is asterisk, this is a link name, and we leave it
32114 -- completely unmodified. We also ignore null strings (the latter case
32115 -- happens only in error cases).
32116
32117 if Len = 0
32118 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
32119 then
32120 Set_Interface_Name (E, S);
32121
32122 else
32123 J := 1;
32124 loop
32125 CC := Get_String_Char (Str, J);
32126
32127 exit when not In_Character_Range (CC);
32128
32129 C := Get_Character (CC);
32130
32131 exit when C /= '_' and then C /= '$'
32132 and then C not in '0' .. '9'
32133 and then C not in 'a' .. 'z'
32134 and then C not in 'A' .. 'Z';
32135
32136 if J = Len then
32137 Set_Interface_Name (E, S);
32138 return;
32139
32140 else
32141 J := J + 1;
32142 end if;
32143 end loop;
32144
32145 -- Here we need to encode. The encoding we use as follows:
32146 -- three underscores + four hex digits (lower case)
32147
32148 Start_String;
32149
32150 for J in 1 .. String_Length (Str) loop
32151 CC := Get_String_Char (Str, J);
32152
32153 if not In_Character_Range (CC) then
32154 Encode;
32155 else
32156 C := Get_Character (CC);
32157
32158 if C = '_' or else C = '$'
32159 or else C in '0' .. '9'
32160 or else C in 'a' .. 'z'
32161 or else C in 'A' .. 'Z'
32162 then
32163 Store_String_Char (CC);
32164 else
32165 Encode;
32166 end if;
32167 end if;
32168 end loop;
32169
32170 Set_Interface_Name (E,
32171 Make_String_Literal (Sloc (S),
32172 Strval => End_String));
32173 end if;
32174 end Set_Encoded_Interface_Name;
32175
32176 ------------------------
32177 -- Set_Elab_Unit_Name --
32178 ------------------------
32179
32180 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
32181 Pref : Node_Id;
32182 Scop : Entity_Id;
32183
32184 begin
32185 if Nkind (N) = N_Identifier
32186 and then Nkind (With_Item) = N_Identifier
32187 then
32188 Set_Entity (N, Entity (With_Item));
32189
32190 elsif Nkind (N) = N_Selected_Component then
32191 Change_Selected_Component_To_Expanded_Name (N);
32192 Set_Entity (N, Entity (With_Item));
32193 Set_Entity (Selector_Name (N), Entity (N));
32194
32195 Pref := Prefix (N);
32196 Scop := Scope (Entity (N));
32197 while Nkind (Pref) = N_Selected_Component loop
32198 Change_Selected_Component_To_Expanded_Name (Pref);
32199 Set_Entity (Selector_Name (Pref), Scop);
32200 Set_Entity (Pref, Scop);
32201 Pref := Prefix (Pref);
32202 Scop := Scope (Scop);
32203 end loop;
32204
32205 Set_Entity (Pref, Scop);
32206 end if;
32207
32208 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
32209 end Set_Elab_Unit_Name;
32210
32211 -----------------------
32212 -- Set_Overflow_Mode --
32213 -----------------------
32214
32215 procedure Set_Overflow_Mode (N : Node_Id) is
32216
32217 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type;
32218 -- Function to process one pragma argument, Arg
32219
32220 -----------------------
32221 -- Get_Overflow_Mode --
32222 -----------------------
32223
32224 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type is
32225 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
32226
32227 begin
32228 if Chars (Argx) = Name_Strict then
32229 return Strict;
32230
32231 elsif Chars (Argx) = Name_Minimized then
32232 return Minimized;
32233
32234 elsif Chars (Argx) = Name_Eliminated then
32235 return Eliminated;
32236
32237 else
32238 raise Program_Error;
32239 end if;
32240 end Get_Overflow_Mode;
32241
32242 -- Local variables
32243
32244 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
32245 Arg2 : constant Node_Id := Next (Arg1);
32246
32247 -- Start of processing for Set_Overflow_Mode
32248
32249 begin
32250 -- Process first argument
32251
32252 Scope_Suppress.Overflow_Mode_General :=
32253 Get_Overflow_Mode (Arg1);
32254
32255 -- Case of only one argument
32256
32257 if No (Arg2) then
32258 Scope_Suppress.Overflow_Mode_Assertions :=
32259 Scope_Suppress.Overflow_Mode_General;
32260
32261 -- Case of two arguments present
32262
32263 else
32264 Scope_Suppress.Overflow_Mode_Assertions :=
32265 Get_Overflow_Mode (Arg2);
32266 end if;
32267 end Set_Overflow_Mode;
32268
32269 -------------------
32270 -- Test_Case_Arg --
32271 -------------------
32272
32273 function Test_Case_Arg
32274 (Prag : Node_Id;
32275 Arg_Nam : Name_Id;
32276 From_Aspect : Boolean := False) return Node_Id
32277 is
32278 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
32279 Arg : Node_Id;
32280 Args : Node_Id;
32281
32282 begin
32283 pragma Assert
32284 (Arg_Nam in Name_Ensures | Name_Mode | Name_Name | Name_Requires);
32285
32286 -- The caller requests the aspect argument
32287
32288 if From_Aspect then
32289 if Present (Aspect)
32290 and then Nkind (Expression (Aspect)) = N_Aggregate
32291 then
32292 Args := Expression (Aspect);
32293
32294 -- "Name" and "Mode" may appear without an identifier as a
32295 -- positional association.
32296
32297 if Present (Expressions (Args)) then
32298 Arg := First (Expressions (Args));
32299
32300 if Present (Arg) and then Arg_Nam = Name_Name then
32301 return Arg;
32302 end if;
32303
32304 -- Skip "Name"
32305
32306 Arg := Next (Arg);
32307
32308 if Present (Arg) and then Arg_Nam = Name_Mode then
32309 return Arg;
32310 end if;
32311 end if;
32312
32313 -- Some or all arguments may appear as component associatons
32314
32315 if Present (Component_Associations (Args)) then
32316 Arg := First (Component_Associations (Args));
32317 while Present (Arg) loop
32318 if Chars (First (Choices (Arg))) = Arg_Nam then
32319 return Arg;
32320 end if;
32321
32322 Next (Arg);
32323 end loop;
32324 end if;
32325 end if;
32326
32327 -- Otherwise retrieve the argument directly from the pragma
32328
32329 else
32330 Arg := First (Pragma_Argument_Associations (Prag));
32331
32332 if Present (Arg) and then Arg_Nam = Name_Name then
32333 return Arg;
32334 end if;
32335
32336 -- Skip argument "Name"
32337
32338 Arg := Next (Arg);
32339
32340 if Present (Arg) and then Arg_Nam = Name_Mode then
32341 return Arg;
32342 end if;
32343
32344 -- Skip argument "Mode"
32345
32346 Arg := Next (Arg);
32347
32348 -- Arguments "Requires" and "Ensures" are optional and may not be
32349 -- present at all.
32350
32351 while Present (Arg) loop
32352 if Chars (Arg) = Arg_Nam then
32353 return Arg;
32354 end if;
32355
32356 Next (Arg);
32357 end loop;
32358 end if;
32359
32360 return Empty;
32361 end Test_Case_Arg;
32362
32363 --------------------------------------------
32364 -- Defer_Compile_Time_Warning_Error_To_BE --
32365 --------------------------------------------
32366
32367 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id) is
32368 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
32369 begin
32370 Compile_Time_Warnings_Errors.Append
32371 (New_Val => CTWE_Entry'(Eloc => Sloc (Arg1),
32372 Scope => Current_Scope,
32373 Prag => N));
32374
32375 -- If the Boolean expression contains T'Size, and we're not in the main
32376 -- unit being compiled, then we need to copy the pragma into the main
32377 -- unit, because otherwise T'Size might never be computed, leaving it
32378 -- as 0.
32379
32380 if not In_Extended_Main_Code_Unit (N) then
32381 Insert_Library_Level_Action (New_Copy_Tree (N));
32382 end if;
32383 end Defer_Compile_Time_Warning_Error_To_BE;
32384
32385 ------------------------------------------
32386 -- Validate_Compile_Time_Warning_Errors --
32387 ------------------------------------------
32388
32389 procedure Validate_Compile_Time_Warning_Errors is
32390 procedure Set_Scope (S : Entity_Id);
32391 -- Install all enclosing scopes of S along with S itself
32392
32393 procedure Unset_Scope (S : Entity_Id);
32394 -- Uninstall all enclosing scopes of S along with S itself
32395
32396 ---------------
32397 -- Set_Scope --
32398 ---------------
32399
32400 procedure Set_Scope (S : Entity_Id) is
32401 begin
32402 if S /= Standard_Standard then
32403 Set_Scope (Scope (S));
32404 end if;
32405
32406 Push_Scope (S);
32407 end Set_Scope;
32408
32409 -----------------
32410 -- Unset_Scope --
32411 -----------------
32412
32413 procedure Unset_Scope (S : Entity_Id) is
32414 begin
32415 if S /= Standard_Standard then
32416 Unset_Scope (Scope (S));
32417 end if;
32418
32419 Pop_Scope;
32420 end Unset_Scope;
32421
32422 -- Start of processing for Validate_Compile_Time_Warning_Errors
32423
32424 begin
32425 Expander_Mode_Save_And_Set (False);
32426 In_Compile_Time_Warning_Or_Error := True;
32427
32428 for N in Compile_Time_Warnings_Errors.First ..
32429 Compile_Time_Warnings_Errors.Last
32430 loop
32431 declare
32432 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
32433
32434 begin
32435 Set_Scope (T.Scope);
32436 Reset_Analyzed_Flags (T.Prag);
32437 Validate_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
32438 Unset_Scope (T.Scope);
32439 end;
32440 end loop;
32441
32442 In_Compile_Time_Warning_Or_Error := False;
32443 Expander_Mode_Restore;
32444 end Validate_Compile_Time_Warning_Errors;
32445
32446 end Sem_Prag;