[Ada] Minor wording changes wrt Ada 202x
[gcc.git] / gcc / ada / sem_prag.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ P R A G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
31
32 with Aspects; use Aspects;
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Checks; use Checks;
36 with Contracts; use Contracts;
37 with Csets; use Csets;
38 with Debug; use Debug;
39 with Einfo; use Einfo;
40 with Elists; use Elists;
41 with Errout; use Errout;
42 with Exp_Dist; use Exp_Dist;
43 with Exp_Util; use Exp_Util;
44 with Expander; use Expander;
45 with Freeze; use Freeze;
46 with Ghost; use Ghost;
47 with Gnatvsn; use Gnatvsn;
48 with Lib; use Lib;
49 with Lib.Writ; use Lib.Writ;
50 with Lib.Xref; use Lib.Xref;
51 with Namet.Sp; use Namet.Sp;
52 with Nlists; use Nlists;
53 with Nmake; use Nmake;
54 with Output; use Output;
55 with Par_SCO; use Par_SCO;
56 with Restrict; use Restrict;
57 with Rident; use Rident;
58 with Rtsfind; use Rtsfind;
59 with Sem; use Sem;
60 with Sem_Aux; use Sem_Aux;
61 with Sem_Ch3; use Sem_Ch3;
62 with Sem_Ch6; use Sem_Ch6;
63 with Sem_Ch8; use Sem_Ch8;
64 with Sem_Ch12; use Sem_Ch12;
65 with Sem_Ch13; use Sem_Ch13;
66 with Sem_Disp; use Sem_Disp;
67 with Sem_Dist; use Sem_Dist;
68 with Sem_Elab; use Sem_Elab;
69 with Sem_Elim; use Sem_Elim;
70 with Sem_Eval; use Sem_Eval;
71 with Sem_Intr; use Sem_Intr;
72 with Sem_Mech; use Sem_Mech;
73 with Sem_Res; use Sem_Res;
74 with Sem_Type; use Sem_Type;
75 with Sem_Util; use Sem_Util;
76 with Sem_Warn; use Sem_Warn;
77 with Stand; use Stand;
78 with Sinfo; use Sinfo;
79 with Sinfo.CN; use Sinfo.CN;
80 with Sinput; use Sinput;
81 with Stringt; use Stringt;
82 with Stylesw; use Stylesw;
83 with Table;
84 with Targparm; use Targparm;
85 with Tbuild; use Tbuild;
86 with Ttypes;
87 with Uintp; use Uintp;
88 with Uname; use Uname;
89 with Urealp; use Urealp;
90 with Validsw; use Validsw;
91 with Warnsw; use Warnsw;
92
93 with System.Case_Util;
94
95 package body Sem_Prag is
96
97 ----------------------------------------------
98 -- Common Handling of Import-Export Pragmas --
99 ----------------------------------------------
100
101 -- In the following section, a number of Import_xxx and Export_xxx pragmas
102 -- are defined by GNAT. These are compatible with the DEC pragmas of the
103 -- same name, and all have the following common form and processing:
104
105 -- pragma Export_xxx
106 -- [Internal =>] LOCAL_NAME
107 -- [, [External =>] EXTERNAL_SYMBOL]
108 -- [, other optional parameters ]);
109
110 -- pragma Import_xxx
111 -- [Internal =>] LOCAL_NAME
112 -- [, [External =>] EXTERNAL_SYMBOL]
113 -- [, other optional parameters ]);
114
115 -- EXTERNAL_SYMBOL ::=
116 -- IDENTIFIER
117 -- | static_string_EXPRESSION
118
119 -- The internal LOCAL_NAME designates the entity that is imported or
120 -- exported, and must refer to an entity in the current declarative
121 -- part (as required by the rules for LOCAL_NAME).
122
123 -- The external linker name is designated by the External parameter if
124 -- given, or the Internal parameter if not (if there is no External
125 -- parameter, the External parameter is a copy of the Internal name).
126
127 -- If the External parameter is given as a string, then this string is
128 -- treated as an external name (exactly as though it had been given as an
129 -- External_Name parameter for a normal Import pragma).
130
131 -- If the External parameter is given as an identifier (or there is no
132 -- External parameter, so that the Internal identifier is used), then
133 -- the external name is the characters of the identifier, translated
134 -- to all lower case letters.
135
136 -- Note: the external name specified or implied by any of these special
137 -- Import_xxx or Export_xxx pragmas override an external or link name
138 -- specified in a previous Import or Export pragma.
139
140 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
141 -- named notation, following the standard rules for subprogram calls, i.e.
142 -- parameters can be given in any order if named notation is used, and
143 -- positional and named notation can be mixed, subject to the rule that all
144 -- positional parameters must appear first.
145
146 -- Note: All these pragmas are implemented exactly following the DEC design
147 -- and implementation and are intended to be fully compatible with the use
148 -- of these pragmas in the DEC Ada compiler.
149
150 --------------------------------------------
151 -- Checking for Duplicated External Names --
152 --------------------------------------------
153
154 -- It is suspicious if two separate Export pragmas use the same external
155 -- name. The following table is used to diagnose this situation so that
156 -- an appropriate warning can be issued.
157
158 -- The Node_Id stored is for the N_String_Literal node created to hold
159 -- the value of the external name. The Sloc of this node is used to
160 -- cross-reference the location of the duplication.
161
162 package Externals is new Table.Table (
163 Table_Component_Type => Node_Id,
164 Table_Index_Type => Int,
165 Table_Low_Bound => 0,
166 Table_Initial => 100,
167 Table_Increment => 100,
168 Table_Name => "Name_Externals");
169
170 -------------------------------------
171 -- Local Subprograms and Variables --
172 -------------------------------------
173
174 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
175 -- This routine is used for possible casing adjustment of an explicit
176 -- external name supplied as a string literal (the node N), according to
177 -- the casing requirement of Opt.External_Name_Casing. If this is set to
178 -- As_Is, then the string literal is returned unchanged, but if it is set
179 -- to Uppercase or Lowercase, then a new string literal with appropriate
180 -- casing is constructed.
181
182 procedure Analyze_Part_Of
183 (Indic : Node_Id;
184 Item_Id : Entity_Id;
185 Encap : Node_Id;
186 Encap_Id : out Entity_Id;
187 Legal : out Boolean);
188 -- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and
189 -- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the
190 -- Part_Of indicator. Item_Id is the entity of an abstract state, object or
191 -- package instantiation. Encap denotes the encapsulating state or single
192 -- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when
193 -- the indicator is legal.
194
195 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
196 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
197 -- Query whether a particular item appears in a mixed list of nodes and
198 -- entities. It is assumed that all nodes in the list have entities.
199
200 procedure Check_Postcondition_Use_In_Inlined_Subprogram
201 (Prag : Node_Id;
202 Spec_Id : Entity_Id);
203 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
204 -- Precondition, Refined_Post, and Test_Case. Emit a warning when pragma
205 -- Prag is associated with subprogram Spec_Id subject to Inline_Always,
206 -- and assertions are enabled.
207
208 procedure Check_State_And_Constituent_Use
209 (States : Elist_Id;
210 Constits : Elist_Id;
211 Context : Node_Id);
212 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
213 -- Global and Initializes. Determine whether a state from list States and a
214 -- corresponding constituent from list Constits (if any) appear in the same
215 -- context denoted by Context. If this is the case, emit an error.
216
217 procedure Contract_Freeze_Error
218 (Contract_Id : Entity_Id;
219 Freeze_Id : Entity_Id);
220 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and
221 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity
222 -- of a body which caused contract freezing and Contract_Id denotes the
223 -- entity of the affected contstruct.
224
225 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id);
226 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma
227 -- Prag that duplicates previous pragma Prev.
228
229 function Find_Encapsulating_State
230 (States : Elist_Id;
231 Constit_Id : Entity_Id) return Entity_Id;
232 -- Given the entity of a constituent Constit_Id, find the corresponding
233 -- encapsulating state which appears in States. The routine returns Empty
234 -- if no such state is found.
235
236 function Find_Related_Context
237 (Prag : Node_Id;
238 Do_Checks : Boolean := False) return Node_Id;
239 -- Subsidiary to the analysis of pragmas
240 -- Async_Readers
241 -- Async_Writers
242 -- Constant_After_Elaboration
243 -- Effective_Reads
244 -- Effective_Writers
245 -- Part_Of
246 -- Find the first source declaration or statement found while traversing
247 -- the previous node chain starting from pragma Prag. If flag Do_Checks is
248 -- set, the routine reports duplicate pragmas. The routine returns Empty
249 -- when reaching the start of the node chain.
250
251 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
252 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
253 -- original one, following the renaming chain) is returned. Otherwise the
254 -- entity is returned unchanged. Should be in Einfo???
255
256 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
257 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
258 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
259 -- value of type SPARK_Mode_Type.
260
261 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
262 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
263 -- Determine whether dependency clause Clause is surrounded by extra
264 -- parentheses. If this is the case, issue an error message.
265
266 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
267 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
268 -- pragma Depends. Determine whether the type of dependency item Item is
269 -- tagged, unconstrained array, unconstrained record or a record with at
270 -- least one unconstrained component.
271
272 procedure Record_Possible_Body_Reference
273 (State_Id : Entity_Id;
274 Ref : Node_Id);
275 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
276 -- Global. Given an abstract state denoted by State_Id and a reference Ref
277 -- to it, determine whether the reference appears in a package body that
278 -- will eventually refine the state. If this is the case, record the
279 -- reference for future checks (see Analyze_Refined_State_In_Decls).
280
281 procedure Resolve_State (N : Node_Id);
282 -- Handle the overloading of state names by functions. When N denotes a
283 -- function, this routine finds the corresponding state and sets the entity
284 -- of N to that of the state.
285
286 procedure Rewrite_Assertion_Kind
287 (N : Node_Id;
288 From_Policy : Boolean := False);
289 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
290 -- then it is rewritten as an identifier with the corresponding special
291 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
292 -- and Check_Policy. If the names are Precondition or Postcondition, this
293 -- combination is deprecated in favor of Assertion_Policy and Ada2012
294 -- Aspect names. The parameter From_Policy indicates that the pragma
295 -- is the old non-standard Check_Policy and not a rewritten pragma.
296
297 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
298 -- Place semantic information on the argument of an Elaborate/Elaborate_All
299 -- pragma. Entity name for unit and its parents is taken from item in
300 -- previous with_clause that mentions the unit.
301
302 procedure Validate_Compile_Time_Warning_Or_Error
303 (N : Node_Id;
304 Eloc : Source_Ptr);
305 -- Common processing for Compile_Time_Error and Compile_Time_Warning of
306 -- pragma N. Called when the pragma is processed as part of its regular
307 -- analysis but also called after calling the back end to validate these
308 -- pragmas for size and alignment appropriateness.
309
310 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id);
311 -- N is a pragma Compile_Time_Error or Compile_Warning_Error whose boolean
312 -- expression is not known at compile time during the front end. This
313 -- procedure makes an entry in a table. The actual checking is performed by
314 -- Validate_Compile_Time_Warning_Errors, which is invoked after calling the
315 -- back end.
316
317 Dummy : Integer := 0;
318 pragma Volatile (Dummy);
319 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
320
321 procedure ip;
322 pragma No_Inline (ip);
323 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
324 -- is just to help debugging the front end. If a pragma Inspection_Point
325 -- is added to a source program, then breaking on ip will get you to that
326 -- point in the program.
327
328 procedure rv;
329 pragma No_Inline (rv);
330 -- This is a dummy function called by the processing for pragma Reviewable.
331 -- It is there for assisting front end debugging. By placing a Reviewable
332 -- pragma in the source program, a breakpoint on rv catches this place in
333 -- the source, allowing convenient stepping to the point of interest.
334
335 ------------------------------------------------------
336 -- Table for Defer_Compile_Time_Warning_Error_To_BE --
337 ------------------------------------------------------
338
339 -- The following table collects pragmas Compile_Time_Error and Compile_
340 -- Time_Warning for validation. Entries are made by calls to subprogram
341 -- Defer_Compile_Time_Warning_Error_To_BE, and the call to the procedure
342 -- Validate_Compile_Time_Warning_Errors does the actual error checking
343 -- and posting of warning and error messages. The reason for this delayed
344 -- processing is to take advantage of back-annotations of attributes size
345 -- and alignment values performed by the back end.
346
347 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
348 -- that by the time Validate_Compile_Time_Warning_Errors is called, Sprint
349 -- will already have modified all Sloc values if the -gnatD option is set.
350
351 type CTWE_Entry is record
352 Eloc : Source_Ptr;
353 -- Source location used in warnings and error messages
354
355 Prag : Node_Id;
356 -- Pragma Compile_Time_Error or Compile_Time_Warning
357
358 Scope : Node_Id;
359 -- The scope which encloses the pragma
360 end record;
361
362 package Compile_Time_Warnings_Errors is new Table.Table (
363 Table_Component_Type => CTWE_Entry,
364 Table_Index_Type => Int,
365 Table_Low_Bound => 1,
366 Table_Initial => 50,
367 Table_Increment => 200,
368 Table_Name => "Compile_Time_Warnings_Errors");
369
370 -------------------------------
371 -- Adjust_External_Name_Case --
372 -------------------------------
373
374 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
375 CC : Char_Code;
376
377 begin
378 -- Adjust case of literal if required
379
380 if Opt.External_Name_Exp_Casing = As_Is then
381 return N;
382
383 else
384 -- Copy existing string
385
386 Start_String;
387
388 -- Set proper casing
389
390 for J in 1 .. String_Length (Strval (N)) loop
391 CC := Get_String_Char (Strval (N), J);
392
393 if Opt.External_Name_Exp_Casing = Uppercase
394 and then CC >= Get_Char_Code ('a')
395 and then CC <= Get_Char_Code ('z')
396 then
397 Store_String_Char (CC - 32);
398
399 elsif Opt.External_Name_Exp_Casing = Lowercase
400 and then CC >= Get_Char_Code ('A')
401 and then CC <= Get_Char_Code ('Z')
402 then
403 Store_String_Char (CC + 32);
404
405 else
406 Store_String_Char (CC);
407 end if;
408 end loop;
409
410 return
411 Make_String_Literal (Sloc (N),
412 Strval => End_String);
413 end if;
414 end Adjust_External_Name_Case;
415
416 -----------------------------------------
417 -- Analyze_Contract_Cases_In_Decl_Part --
418 -----------------------------------------
419
420 -- WARNING: This routine manages Ghost regions. Return statements must be
421 -- replaced by gotos which jump to the end of the routine and restore the
422 -- Ghost mode.
423
424 procedure Analyze_Contract_Cases_In_Decl_Part
425 (N : Node_Id;
426 Freeze_Id : Entity_Id := Empty)
427 is
428 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
429 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
430
431 Others_Seen : Boolean := False;
432 -- This flag is set when an "others" choice is encountered. It is used
433 -- to detect multiple illegal occurrences of "others".
434
435 procedure Analyze_Contract_Case (CCase : Node_Id);
436 -- Verify the legality of a single contract case
437
438 ---------------------------
439 -- Analyze_Contract_Case --
440 ---------------------------
441
442 procedure Analyze_Contract_Case (CCase : Node_Id) is
443 Case_Guard : Node_Id;
444 Conseq : Node_Id;
445 Errors : Nat;
446 Extra_Guard : Node_Id;
447
448 begin
449 if Nkind (CCase) = N_Component_Association then
450 Case_Guard := First (Choices (CCase));
451 Conseq := Expression (CCase);
452
453 -- Each contract case must have exactly one case guard
454
455 Extra_Guard := Next (Case_Guard);
456
457 if Present (Extra_Guard) then
458 Error_Msg_N
459 ("contract case must have exactly one case guard",
460 Extra_Guard);
461 end if;
462
463 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
464
465 if Nkind (Case_Guard) = N_Others_Choice then
466 if Others_Seen then
467 Error_Msg_N
468 ("only one others choice allowed in contract cases",
469 Case_Guard);
470 else
471 Others_Seen := True;
472 end if;
473
474 elsif Others_Seen then
475 Error_Msg_N
476 ("others must be the last choice in contract cases", N);
477 end if;
478
479 -- Preanalyze the case guard and consequence
480
481 if Nkind (Case_Guard) /= N_Others_Choice then
482 Errors := Serious_Errors_Detected;
483 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
484
485 -- Emit a clarification message when the case guard contains
486 -- at least one undefined reference, possibly due to contract
487 -- freezing.
488
489 if Errors /= Serious_Errors_Detected
490 and then Present (Freeze_Id)
491 and then Has_Undefined_Reference (Case_Guard)
492 then
493 Contract_Freeze_Error (Spec_Id, Freeze_Id);
494 end if;
495 end if;
496
497 Errors := Serious_Errors_Detected;
498 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
499
500 -- Emit a clarification message when the consequence contains
501 -- at least one undefined reference, possibly due to contract
502 -- freezing.
503
504 if Errors /= Serious_Errors_Detected
505 and then Present (Freeze_Id)
506 and then Has_Undefined_Reference (Conseq)
507 then
508 Contract_Freeze_Error (Spec_Id, Freeze_Id);
509 end if;
510
511 -- The contract case is malformed
512
513 else
514 Error_Msg_N ("wrong syntax in contract case", CCase);
515 end if;
516 end Analyze_Contract_Case;
517
518 -- Local variables
519
520 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
521
522 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
523 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
524 -- Save the Ghost-related attributes to restore on exit
525
526 CCase : Node_Id;
527 Restore_Scope : Boolean := False;
528
529 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
530
531 begin
532 -- Do not analyze the pragma multiple times
533
534 if Is_Analyzed_Pragma (N) then
535 return;
536 end if;
537
538 -- Set the Ghost mode in effect from the pragma. Due to the delayed
539 -- analysis of the pragma, the Ghost mode at point of declaration and
540 -- point of analysis may not necessarily be the same. Use the mode in
541 -- effect at the point of declaration.
542
543 Set_Ghost_Mode (N);
544
545 -- Single and multiple contract cases must appear in aggregate form. If
546 -- this is not the case, then either the parser of the analysis of the
547 -- pragma failed to produce an aggregate.
548
549 pragma Assert (Nkind (CCases) = N_Aggregate);
550
551 if Present (Component_Associations (CCases)) then
552
553 -- Ensure that the formal parameters are visible when analyzing all
554 -- clauses. This falls out of the general rule of aspects pertaining
555 -- to subprogram declarations.
556
557 if not In_Open_Scopes (Spec_Id) then
558 Restore_Scope := True;
559 Push_Scope (Spec_Id);
560
561 if Is_Generic_Subprogram (Spec_Id) then
562 Install_Generic_Formals (Spec_Id);
563 else
564 Install_Formals (Spec_Id);
565 end if;
566 end if;
567
568 CCase := First (Component_Associations (CCases));
569 while Present (CCase) loop
570 Analyze_Contract_Case (CCase);
571 Next (CCase);
572 end loop;
573
574 if Restore_Scope then
575 End_Scope;
576 end if;
577
578 -- Currently it is not possible to inline pre/postconditions on a
579 -- subprogram subject to pragma Inline_Always.
580
581 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
582
583 -- Otherwise the pragma is illegal
584
585 else
586 Error_Msg_N ("wrong syntax for constract cases", N);
587 end if;
588
589 Set_Is_Analyzed_Pragma (N);
590
591 Restore_Ghost_Region (Saved_GM, Saved_IGR);
592 end Analyze_Contract_Cases_In_Decl_Part;
593
594 ----------------------------------
595 -- Analyze_Depends_In_Decl_Part --
596 ----------------------------------
597
598 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
599 Loc : constant Source_Ptr := Sloc (N);
600 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
601 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
602
603 All_Inputs_Seen : Elist_Id := No_Elist;
604 -- A list containing the entities of all the inputs processed so far.
605 -- The list is populated with unique entities because the same input
606 -- may appear in multiple input lists.
607
608 All_Outputs_Seen : Elist_Id := No_Elist;
609 -- A list containing the entities of all the outputs processed so far.
610 -- The list is populated with unique entities because output items are
611 -- unique in a dependence relation.
612
613 Constits_Seen : Elist_Id := No_Elist;
614 -- A list containing the entities of all constituents processed so far.
615 -- It aids in detecting illegal usage of a state and a corresponding
616 -- constituent in pragma [Refinde_]Depends.
617
618 Global_Seen : Boolean := False;
619 -- A flag set when pragma Global has been processed
620
621 Null_Output_Seen : Boolean := False;
622 -- A flag used to track the legality of a null output
623
624 Result_Seen : Boolean := False;
625 -- A flag set when Spec_Id'Result is processed
626
627 States_Seen : Elist_Id := No_Elist;
628 -- A list containing the entities of all states processed so far. It
629 -- helps in detecting illegal usage of a state and a corresponding
630 -- constituent in pragma [Refined_]Depends.
631
632 Subp_Inputs : Elist_Id := No_Elist;
633 Subp_Outputs : Elist_Id := No_Elist;
634 -- Two lists containing the full set of inputs and output of the related
635 -- subprograms. Note that these lists contain both nodes and entities.
636
637 Task_Input_Seen : Boolean := False;
638 Task_Output_Seen : Boolean := False;
639 -- Flags used to track the implicit dependence of a task unit on itself
640
641 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
642 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
643 -- to the name buffer. The individual kinds are as follows:
644 -- E_Abstract_State - "state"
645 -- E_Constant - "constant"
646 -- E_Generic_In_Out_Parameter - "generic parameter"
647 -- E_Generic_In_Parameter - "generic parameter"
648 -- E_In_Parameter - "parameter"
649 -- E_In_Out_Parameter - "parameter"
650 -- E_Loop_Parameter - "loop parameter"
651 -- E_Out_Parameter - "parameter"
652 -- E_Protected_Type - "current instance of protected type"
653 -- E_Task_Type - "current instance of task type"
654 -- E_Variable - "global"
655
656 procedure Analyze_Dependency_Clause
657 (Clause : Node_Id;
658 Is_Last : Boolean);
659 -- Verify the legality of a single dependency clause. Flag Is_Last
660 -- denotes whether Clause is the last clause in the relation.
661
662 procedure Check_Function_Return;
663 -- Verify that Funtion'Result appears as one of the outputs
664 -- (SPARK RM 6.1.5(10)).
665
666 procedure Check_Role
667 (Item : Node_Id;
668 Item_Id : Entity_Id;
669 Is_Input : Boolean;
670 Self_Ref : Boolean);
671 -- Ensure that an item fulfills its designated input and/or output role
672 -- as specified by pragma Global (if any) or the enclosing context. If
673 -- this is not the case, emit an error. Item and Item_Id denote the
674 -- attributes of an item. Flag Is_Input should be set when item comes
675 -- from an input list. Flag Self_Ref should be set when the item is an
676 -- output and the dependency clause has operator "+".
677
678 procedure Check_Usage
679 (Subp_Items : Elist_Id;
680 Used_Items : Elist_Id;
681 Is_Input : Boolean);
682 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
683 -- error if this is not the case.
684
685 procedure Normalize_Clause (Clause : Node_Id);
686 -- Remove a self-dependency "+" from the input list of a clause
687
688 -----------------------------
689 -- Add_Item_To_Name_Buffer --
690 -----------------------------
691
692 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
693 begin
694 if Ekind (Item_Id) = E_Abstract_State then
695 Add_Str_To_Name_Buffer ("state");
696
697 elsif Ekind (Item_Id) = E_Constant then
698 Add_Str_To_Name_Buffer ("constant");
699
700 elsif Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
701 E_Generic_In_Parameter)
702 then
703 Add_Str_To_Name_Buffer ("generic parameter");
704
705 elsif Is_Formal (Item_Id) then
706 Add_Str_To_Name_Buffer ("parameter");
707
708 elsif Ekind (Item_Id) = E_Loop_Parameter then
709 Add_Str_To_Name_Buffer ("loop parameter");
710
711 elsif Ekind (Item_Id) = E_Protected_Type
712 or else Is_Single_Protected_Object (Item_Id)
713 then
714 Add_Str_To_Name_Buffer ("current instance of protected type");
715
716 elsif Ekind (Item_Id) = E_Task_Type
717 or else Is_Single_Task_Object (Item_Id)
718 then
719 Add_Str_To_Name_Buffer ("current instance of task type");
720
721 elsif Ekind (Item_Id) = E_Variable then
722 Add_Str_To_Name_Buffer ("global");
723
724 -- The routine should not be called with non-SPARK items
725
726 else
727 raise Program_Error;
728 end if;
729 end Add_Item_To_Name_Buffer;
730
731 -------------------------------
732 -- Analyze_Dependency_Clause --
733 -------------------------------
734
735 procedure Analyze_Dependency_Clause
736 (Clause : Node_Id;
737 Is_Last : Boolean)
738 is
739 procedure Analyze_Input_List (Inputs : Node_Id);
740 -- Verify the legality of a single input list
741
742 procedure Analyze_Input_Output
743 (Item : Node_Id;
744 Is_Input : Boolean;
745 Self_Ref : Boolean;
746 Top_Level : Boolean;
747 Seen : in out Elist_Id;
748 Null_Seen : in out Boolean;
749 Non_Null_Seen : in out Boolean);
750 -- Verify the legality of a single input or output item. Flag
751 -- Is_Input should be set whenever Item is an input, False when it
752 -- denotes an output. Flag Self_Ref should be set when the item is an
753 -- output and the dependency clause has a "+". Flag Top_Level should
754 -- be set whenever Item appears immediately within an input or output
755 -- list. Seen is a collection of all abstract states, objects and
756 -- formals processed so far. Flag Null_Seen denotes whether a null
757 -- input or output has been encountered. Flag Non_Null_Seen denotes
758 -- whether a non-null input or output has been encountered.
759
760 ------------------------
761 -- Analyze_Input_List --
762 ------------------------
763
764 procedure Analyze_Input_List (Inputs : Node_Id) is
765 Inputs_Seen : Elist_Id := No_Elist;
766 -- A list containing the entities of all inputs that appear in the
767 -- current input list.
768
769 Non_Null_Input_Seen : Boolean := False;
770 Null_Input_Seen : Boolean := False;
771 -- Flags used to check the legality of an input list
772
773 Input : Node_Id;
774
775 begin
776 -- Multiple inputs appear as an aggregate
777
778 if Nkind (Inputs) = N_Aggregate then
779 if Present (Component_Associations (Inputs)) then
780 SPARK_Msg_N
781 ("nested dependency relations not allowed", Inputs);
782
783 elsif Present (Expressions (Inputs)) then
784 Input := First (Expressions (Inputs));
785 while Present (Input) loop
786 Analyze_Input_Output
787 (Item => Input,
788 Is_Input => True,
789 Self_Ref => False,
790 Top_Level => False,
791 Seen => Inputs_Seen,
792 Null_Seen => Null_Input_Seen,
793 Non_Null_Seen => Non_Null_Input_Seen);
794
795 Next (Input);
796 end loop;
797
798 -- Syntax error, always report
799
800 else
801 Error_Msg_N ("malformed input dependency list", Inputs);
802 end if;
803
804 -- Process a solitary input
805
806 else
807 Analyze_Input_Output
808 (Item => Inputs,
809 Is_Input => True,
810 Self_Ref => False,
811 Top_Level => False,
812 Seen => Inputs_Seen,
813 Null_Seen => Null_Input_Seen,
814 Non_Null_Seen => Non_Null_Input_Seen);
815 end if;
816
817 -- Detect an illegal dependency clause of the form
818
819 -- (null =>[+] null)
820
821 if Null_Output_Seen and then Null_Input_Seen then
822 SPARK_Msg_N
823 ("null dependency clause cannot have a null input list",
824 Inputs);
825 end if;
826 end Analyze_Input_List;
827
828 --------------------------
829 -- Analyze_Input_Output --
830 --------------------------
831
832 procedure Analyze_Input_Output
833 (Item : Node_Id;
834 Is_Input : Boolean;
835 Self_Ref : Boolean;
836 Top_Level : Boolean;
837 Seen : in out Elist_Id;
838 Null_Seen : in out Boolean;
839 Non_Null_Seen : in out Boolean)
840 is
841 procedure Current_Task_Instance_Seen;
842 -- Set the appropriate global flag when the current instance of a
843 -- task unit is encountered.
844
845 --------------------------------
846 -- Current_Task_Instance_Seen --
847 --------------------------------
848
849 procedure Current_Task_Instance_Seen is
850 begin
851 if Is_Input then
852 Task_Input_Seen := True;
853 else
854 Task_Output_Seen := True;
855 end if;
856 end Current_Task_Instance_Seen;
857
858 -- Local variables
859
860 Is_Output : constant Boolean := not Is_Input;
861 Grouped : Node_Id;
862 Item_Id : Entity_Id;
863
864 -- Start of processing for Analyze_Input_Output
865
866 begin
867 -- Multiple input or output items appear as an aggregate
868
869 if Nkind (Item) = N_Aggregate then
870 if not Top_Level then
871 SPARK_Msg_N ("nested grouping of items not allowed", Item);
872
873 elsif Present (Component_Associations (Item)) then
874 SPARK_Msg_N
875 ("nested dependency relations not allowed", Item);
876
877 -- Recursively analyze the grouped items
878
879 elsif Present (Expressions (Item)) then
880 Grouped := First (Expressions (Item));
881 while Present (Grouped) loop
882 Analyze_Input_Output
883 (Item => Grouped,
884 Is_Input => Is_Input,
885 Self_Ref => Self_Ref,
886 Top_Level => False,
887 Seen => Seen,
888 Null_Seen => Null_Seen,
889 Non_Null_Seen => Non_Null_Seen);
890
891 Next (Grouped);
892 end loop;
893
894 -- Syntax error, always report
895
896 else
897 Error_Msg_N ("malformed dependency list", Item);
898 end if;
899
900 -- Process attribute 'Result in the context of a dependency clause
901
902 elsif Is_Attribute_Result (Item) then
903 Non_Null_Seen := True;
904
905 Analyze (Item);
906
907 -- Attribute 'Result is allowed to appear on the output side of
908 -- a dependency clause (SPARK RM 6.1.5(6)).
909
910 if Is_Input then
911 SPARK_Msg_N ("function result cannot act as input", Item);
912
913 elsif Null_Seen then
914 SPARK_Msg_N
915 ("cannot mix null and non-null dependency items", Item);
916
917 else
918 Result_Seen := True;
919 end if;
920
921 -- Detect multiple uses of null in a single dependency list or
922 -- throughout the whole relation. Verify the placement of a null
923 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
924
925 elsif Nkind (Item) = N_Null then
926 if Null_Seen then
927 SPARK_Msg_N
928 ("multiple null dependency relations not allowed", Item);
929
930 elsif Non_Null_Seen then
931 SPARK_Msg_N
932 ("cannot mix null and non-null dependency items", Item);
933
934 else
935 Null_Seen := True;
936
937 if Is_Output then
938 if not Is_Last then
939 SPARK_Msg_N
940 ("null output list must be the last clause in a "
941 & "dependency relation", Item);
942
943 -- Catch a useless dependence of the form:
944 -- null =>+ ...
945
946 elsif Self_Ref then
947 SPARK_Msg_N
948 ("useless dependence, null depends on itself", Item);
949 end if;
950 end if;
951 end if;
952
953 -- Default case
954
955 else
956 Non_Null_Seen := True;
957
958 if Null_Seen then
959 SPARK_Msg_N ("cannot mix null and non-null items", Item);
960 end if;
961
962 Analyze (Item);
963 Resolve_State (Item);
964
965 -- Find the entity of the item. If this is a renaming, climb
966 -- the renaming chain to reach the root object. Renamings of
967 -- non-entire objects do not yield an entity (Empty).
968
969 Item_Id := Entity_Of (Item);
970
971 if Present (Item_Id) then
972
973 -- Constants
974
975 if Ekind_In (Item_Id, E_Constant, E_Loop_Parameter)
976 or else
977
978 -- Current instances of concurrent types
979
980 Ekind_In (Item_Id, E_Protected_Type, E_Task_Type)
981 or else
982
983 -- Formal parameters
984
985 Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
986 E_Generic_In_Parameter,
987 E_In_Parameter,
988 E_In_Out_Parameter,
989 E_Out_Parameter)
990 or else
991
992 -- States, variables
993
994 Ekind_In (Item_Id, E_Abstract_State, E_Variable)
995 then
996 -- A [generic] function is not allowed to have Output
997 -- items in its dependency relations. Note that "null"
998 -- and attribute 'Result are still valid items.
999
1000 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
1001 and then not Is_Input
1002 then
1003 SPARK_Msg_N
1004 ("output item is not applicable to function", Item);
1005 end if;
1006
1007 -- The item denotes a concurrent type. Note that single
1008 -- protected/task types are not considered here because
1009 -- they behave as objects in the context of pragma
1010 -- [Refined_]Depends.
1011
1012 if Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
1013
1014 -- This use is legal as long as the concurrent type is
1015 -- the current instance of an enclosing type.
1016
1017 if Is_CCT_Instance (Item_Id, Spec_Id) then
1018
1019 -- The dependence of a task unit on itself is
1020 -- implicit and may or may not be explicitly
1021 -- specified (SPARK RM 6.1.4).
1022
1023 if Ekind (Item_Id) = E_Task_Type then
1024 Current_Task_Instance_Seen;
1025 end if;
1026
1027 -- Otherwise this is not the current instance
1028
1029 else
1030 SPARK_Msg_N
1031 ("invalid use of subtype mark in dependency "
1032 & "relation", Item);
1033 end if;
1034
1035 -- The dependency of a task unit on itself is implicit
1036 -- and may or may not be explicitly specified
1037 -- (SPARK RM 6.1.4).
1038
1039 elsif Is_Single_Task_Object (Item_Id)
1040 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
1041 then
1042 Current_Task_Instance_Seen;
1043 end if;
1044
1045 -- Ensure that the item fulfills its role as input and/or
1046 -- output as specified by pragma Global or the enclosing
1047 -- context.
1048
1049 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
1050
1051 -- Detect multiple uses of the same state, variable or
1052 -- formal parameter. If this is not the case, add the
1053 -- item to the list of processed relations.
1054
1055 if Contains (Seen, Item_Id) then
1056 SPARK_Msg_NE
1057 ("duplicate use of item &", Item, Item_Id);
1058 else
1059 Append_New_Elmt (Item_Id, Seen);
1060 end if;
1061
1062 -- Detect illegal use of an input related to a null
1063 -- output. Such input items cannot appear in other
1064 -- input lists (SPARK RM 6.1.5(13)).
1065
1066 if Is_Input
1067 and then Null_Output_Seen
1068 and then Contains (All_Inputs_Seen, Item_Id)
1069 then
1070 SPARK_Msg_N
1071 ("input of a null output list cannot appear in "
1072 & "multiple input lists", Item);
1073 end if;
1074
1075 -- Add an input or a self-referential output to the list
1076 -- of all processed inputs.
1077
1078 if Is_Input or else Self_Ref then
1079 Append_New_Elmt (Item_Id, All_Inputs_Seen);
1080 end if;
1081
1082 -- State related checks (SPARK RM 6.1.5(3))
1083
1084 if Ekind (Item_Id) = E_Abstract_State then
1085
1086 -- Package and subprogram bodies are instantiated
1087 -- individually in a separate compiler pass. Due to
1088 -- this mode of instantiation, the refinement of a
1089 -- state may no longer be visible when a subprogram
1090 -- body contract is instantiated. Since the generic
1091 -- template is legal, do not perform this check in
1092 -- the instance to circumvent this oddity.
1093
1094 if In_Instance then
1095 null;
1096
1097 -- An abstract state with visible refinement cannot
1098 -- appear in pragma [Refined_]Depends as its place
1099 -- must be taken by some of its constituents
1100 -- (SPARK RM 6.1.4(7)).
1101
1102 elsif Has_Visible_Refinement (Item_Id) then
1103 SPARK_Msg_NE
1104 ("cannot mention state & in dependence relation",
1105 Item, Item_Id);
1106 SPARK_Msg_N ("\use its constituents instead", Item);
1107 return;
1108
1109 -- If the reference to the abstract state appears in
1110 -- an enclosing package body that will eventually
1111 -- refine the state, record the reference for future
1112 -- checks.
1113
1114 else
1115 Record_Possible_Body_Reference
1116 (State_Id => Item_Id,
1117 Ref => Item);
1118 end if;
1119 end if;
1120
1121 -- When the item renames an entire object, replace the
1122 -- item with a reference to the object.
1123
1124 if Entity (Item) /= Item_Id then
1125 Rewrite (Item,
1126 New_Occurrence_Of (Item_Id, Sloc (Item)));
1127 Analyze (Item);
1128 end if;
1129
1130 -- Add the entity of the current item to the list of
1131 -- processed items.
1132
1133 if Ekind (Item_Id) = E_Abstract_State then
1134 Append_New_Elmt (Item_Id, States_Seen);
1135
1136 -- The variable may eventually become a constituent of a
1137 -- single protected/task type. Record the reference now
1138 -- and verify its legality when analyzing the contract of
1139 -- the variable (SPARK RM 9.3).
1140
1141 elsif Ekind (Item_Id) = E_Variable then
1142 Record_Possible_Part_Of_Reference
1143 (Var_Id => Item_Id,
1144 Ref => Item);
1145 end if;
1146
1147 if Ekind_In (Item_Id, E_Abstract_State,
1148 E_Constant,
1149 E_Variable)
1150 and then Present (Encapsulating_State (Item_Id))
1151 then
1152 Append_New_Elmt (Item_Id, Constits_Seen);
1153 end if;
1154
1155 -- All other input/output items are illegal
1156 -- (SPARK RM 6.1.5(1)).
1157
1158 else
1159 SPARK_Msg_N
1160 ("item must denote parameter, variable, state or "
1161 & "current instance of concurrent type", Item);
1162 end if;
1163
1164 -- All other input/output items are illegal
1165 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1166
1167 else
1168 Error_Msg_N
1169 ("item must denote parameter, variable, state or current "
1170 & "instance of concurrent type", Item);
1171 end if;
1172 end if;
1173 end Analyze_Input_Output;
1174
1175 -- Local variables
1176
1177 Inputs : Node_Id;
1178 Output : Node_Id;
1179 Self_Ref : Boolean;
1180
1181 Non_Null_Output_Seen : Boolean := False;
1182 -- Flag used to check the legality of an output list
1183
1184 -- Start of processing for Analyze_Dependency_Clause
1185
1186 begin
1187 Inputs := Expression (Clause);
1188 Self_Ref := False;
1189
1190 -- An input list with a self-dependency appears as operator "+" where
1191 -- the actuals inputs are the right operand.
1192
1193 if Nkind (Inputs) = N_Op_Plus then
1194 Inputs := Right_Opnd (Inputs);
1195 Self_Ref := True;
1196 end if;
1197
1198 -- Process the output_list of a dependency_clause
1199
1200 Output := First (Choices (Clause));
1201 while Present (Output) loop
1202 Analyze_Input_Output
1203 (Item => Output,
1204 Is_Input => False,
1205 Self_Ref => Self_Ref,
1206 Top_Level => True,
1207 Seen => All_Outputs_Seen,
1208 Null_Seen => Null_Output_Seen,
1209 Non_Null_Seen => Non_Null_Output_Seen);
1210
1211 Next (Output);
1212 end loop;
1213
1214 -- Process the input_list of a dependency_clause
1215
1216 Analyze_Input_List (Inputs);
1217 end Analyze_Dependency_Clause;
1218
1219 ---------------------------
1220 -- Check_Function_Return --
1221 ---------------------------
1222
1223 procedure Check_Function_Return is
1224 begin
1225 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
1226 and then not Result_Seen
1227 then
1228 SPARK_Msg_NE
1229 ("result of & must appear in exactly one output list",
1230 N, Spec_Id);
1231 end if;
1232 end Check_Function_Return;
1233
1234 ----------------
1235 -- Check_Role --
1236 ----------------
1237
1238 procedure Check_Role
1239 (Item : Node_Id;
1240 Item_Id : Entity_Id;
1241 Is_Input : Boolean;
1242 Self_Ref : Boolean)
1243 is
1244 procedure Find_Role
1245 (Item_Is_Input : out Boolean;
1246 Item_Is_Output : out Boolean);
1247 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1248 -- Item_Is_Output are set depending on the role.
1249
1250 procedure Role_Error
1251 (Item_Is_Input : Boolean;
1252 Item_Is_Output : Boolean);
1253 -- Emit an error message concerning the incorrect use of Item in
1254 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1255 -- denote whether the item is an input and/or an output.
1256
1257 ---------------
1258 -- Find_Role --
1259 ---------------
1260
1261 procedure Find_Role
1262 (Item_Is_Input : out Boolean;
1263 Item_Is_Output : out Boolean)
1264 is
1265 -- A constant or IN parameter of access type should be handled
1266 -- like a variable, as the underlying memory pointed-to can be
1267 -- modified. Use Adjusted_Kind to do this adjustment.
1268
1269 Adjusted_Kind : Entity_Kind := Ekind (Item_Id);
1270
1271 begin
1272 if Ekind_In (Item_Id, E_Constant,
1273 E_Generic_In_Parameter,
1274 E_In_Parameter)
1275 and then Is_Access_Type (Etype (Item_Id))
1276 then
1277 Adjusted_Kind := E_Variable;
1278 end if;
1279
1280 case Adjusted_Kind is
1281
1282 -- Abstract states
1283
1284 when E_Abstract_State =>
1285
1286 -- When pragma Global is present it determines the mode of
1287 -- the abstract state.
1288
1289 if Global_Seen then
1290 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1291 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1292
1293 -- Otherwise the state has a default IN OUT mode, because it
1294 -- behaves as a variable.
1295
1296 else
1297 Item_Is_Input := True;
1298 Item_Is_Output := True;
1299 end if;
1300
1301 -- Constants and IN parameters
1302
1303 when E_Constant
1304 | E_Generic_In_Parameter
1305 | E_In_Parameter
1306 | E_Loop_Parameter
1307 =>
1308 -- When pragma Global is present it determines the mode
1309 -- of constant objects as inputs (and such objects cannot
1310 -- appear as outputs in the Global contract).
1311
1312 if Global_Seen then
1313 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1314 else
1315 Item_Is_Input := True;
1316 end if;
1317
1318 Item_Is_Output := False;
1319
1320 -- Variables and IN OUT parameters, as well as constants and
1321 -- IN parameters of access type which are handled like
1322 -- variables.
1323
1324 when E_Generic_In_Out_Parameter
1325 | E_In_Out_Parameter
1326 | E_Variable
1327 =>
1328 -- When pragma Global is present it determines the mode of
1329 -- the object.
1330
1331 if Global_Seen then
1332
1333 -- A variable has mode IN when its type is unconstrained
1334 -- or tagged because array bounds, discriminants or tags
1335 -- can be read.
1336
1337 Item_Is_Input :=
1338 Appears_In (Subp_Inputs, Item_Id)
1339 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1340
1341 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1342
1343 -- Otherwise the variable has a default IN OUT mode
1344
1345 else
1346 Item_Is_Input := True;
1347 Item_Is_Output := True;
1348 end if;
1349
1350 when E_Out_Parameter =>
1351
1352 -- An OUT parameter of the related subprogram; it cannot
1353 -- appear in Global.
1354
1355 if Scope (Item_Id) = Spec_Id then
1356
1357 -- The parameter has mode IN if its type is unconstrained
1358 -- or tagged because array bounds, discriminants or tags
1359 -- can be read.
1360
1361 Item_Is_Input :=
1362 Is_Unconstrained_Or_Tagged_Item (Item_Id);
1363
1364 Item_Is_Output := True;
1365
1366 -- An OUT parameter of an enclosing subprogram; it can
1367 -- appear in Global and behaves as a read-write variable.
1368
1369 else
1370 -- When pragma Global is present it determines the mode
1371 -- of the object.
1372
1373 if Global_Seen then
1374
1375 -- A variable has mode IN when its type is
1376 -- unconstrained or tagged because array
1377 -- bounds, discriminants or tags can be read.
1378
1379 Item_Is_Input :=
1380 Appears_In (Subp_Inputs, Item_Id)
1381 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1382
1383 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1384
1385 -- Otherwise the variable has a default IN OUT mode
1386
1387 else
1388 Item_Is_Input := True;
1389 Item_Is_Output := True;
1390 end if;
1391 end if;
1392
1393 -- Protected types
1394
1395 when E_Protected_Type =>
1396 if Global_Seen then
1397
1398 -- A variable has mode IN when its type is unconstrained
1399 -- or tagged because array bounds, discriminants or tags
1400 -- can be read.
1401
1402 Item_Is_Input :=
1403 Appears_In (Subp_Inputs, Item_Id)
1404 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1405
1406 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1407
1408 else
1409 -- A protected type acts as a formal parameter of mode IN
1410 -- when it applies to a protected function.
1411
1412 if Ekind (Spec_Id) = E_Function then
1413 Item_Is_Input := True;
1414 Item_Is_Output := False;
1415
1416 -- Otherwise the protected type acts as a formal of mode
1417 -- IN OUT.
1418
1419 else
1420 Item_Is_Input := True;
1421 Item_Is_Output := True;
1422 end if;
1423 end if;
1424
1425 -- Task types
1426
1427 when E_Task_Type =>
1428
1429 -- When pragma Global is present it determines the mode of
1430 -- the object.
1431
1432 if Global_Seen then
1433 Item_Is_Input :=
1434 Appears_In (Subp_Inputs, Item_Id)
1435 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1436
1437 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1438
1439 -- Otherwise task types act as IN OUT parameters
1440
1441 else
1442 Item_Is_Input := True;
1443 Item_Is_Output := True;
1444 end if;
1445
1446 when others =>
1447 raise Program_Error;
1448 end case;
1449 end Find_Role;
1450
1451 ----------------
1452 -- Role_Error --
1453 ----------------
1454
1455 procedure Role_Error
1456 (Item_Is_Input : Boolean;
1457 Item_Is_Output : Boolean)
1458 is
1459 Error_Msg : Name_Id;
1460
1461 begin
1462 Name_Len := 0;
1463
1464 -- When the item is not part of the input and the output set of
1465 -- the related subprogram, then it appears as extra in pragma
1466 -- [Refined_]Depends.
1467
1468 if not Item_Is_Input and then not Item_Is_Output then
1469 Add_Item_To_Name_Buffer (Item_Id);
1470 Add_Str_To_Name_Buffer
1471 (" & cannot appear in dependence relation");
1472
1473 Error_Msg := Name_Find;
1474 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1475
1476 Error_Msg_Name_1 := Chars (Spec_Id);
1477 SPARK_Msg_NE
1478 (Fix_Msg (Spec_Id, "\& is not part of the input or output "
1479 & "set of subprogram %"), Item, Item_Id);
1480
1481 -- The mode of the item and its role in pragma [Refined_]Depends
1482 -- are in conflict. Construct a detailed message explaining the
1483 -- illegality (SPARK RM 6.1.5(5-6)).
1484
1485 else
1486 if Item_Is_Input then
1487 Add_Str_To_Name_Buffer ("read-only");
1488 else
1489 Add_Str_To_Name_Buffer ("write-only");
1490 end if;
1491
1492 Add_Char_To_Name_Buffer (' ');
1493 Add_Item_To_Name_Buffer (Item_Id);
1494 Add_Str_To_Name_Buffer (" & cannot appear as ");
1495
1496 if Item_Is_Input then
1497 Add_Str_To_Name_Buffer ("output");
1498 else
1499 Add_Str_To_Name_Buffer ("input");
1500 end if;
1501
1502 Add_Str_To_Name_Buffer (" in dependence relation");
1503 Error_Msg := Name_Find;
1504 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1505 end if;
1506 end Role_Error;
1507
1508 -- Local variables
1509
1510 Item_Is_Input : Boolean;
1511 Item_Is_Output : Boolean;
1512
1513 -- Start of processing for Check_Role
1514
1515 begin
1516 Find_Role (Item_Is_Input, Item_Is_Output);
1517
1518 -- Input item
1519
1520 if Is_Input then
1521 if not Item_Is_Input then
1522 Role_Error (Item_Is_Input, Item_Is_Output);
1523 end if;
1524
1525 -- Self-referential item
1526
1527 elsif Self_Ref then
1528 if not Item_Is_Input or else not Item_Is_Output then
1529 Role_Error (Item_Is_Input, Item_Is_Output);
1530 end if;
1531
1532 -- Output item
1533
1534 elsif not Item_Is_Output then
1535 Role_Error (Item_Is_Input, Item_Is_Output);
1536 end if;
1537 end Check_Role;
1538
1539 -----------------
1540 -- Check_Usage --
1541 -----------------
1542
1543 procedure Check_Usage
1544 (Subp_Items : Elist_Id;
1545 Used_Items : Elist_Id;
1546 Is_Input : Boolean)
1547 is
1548 procedure Usage_Error (Item_Id : Entity_Id);
1549 -- Emit an error concerning the illegal usage of an item
1550
1551 -----------------
1552 -- Usage_Error --
1553 -----------------
1554
1555 procedure Usage_Error (Item_Id : Entity_Id) is
1556 Error_Msg : Name_Id;
1557
1558 begin
1559 -- Input case
1560
1561 if Is_Input then
1562
1563 -- Unconstrained and tagged items are not part of the explicit
1564 -- input set of the related subprogram, they do not have to be
1565 -- present in a dependence relation and should not be flagged
1566 -- (SPARK RM 6.1.5(5)).
1567
1568 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1569 Name_Len := 0;
1570
1571 Add_Item_To_Name_Buffer (Item_Id);
1572 Add_Str_To_Name_Buffer
1573 (" & is missing from input dependence list");
1574
1575 Error_Msg := Name_Find;
1576 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1577 SPARK_Msg_NE
1578 ("\add `null ='> &` dependency to ignore this input",
1579 N, Item_Id);
1580 end if;
1581
1582 -- Output case (SPARK RM 6.1.5(10))
1583
1584 else
1585 Name_Len := 0;
1586
1587 Add_Item_To_Name_Buffer (Item_Id);
1588 Add_Str_To_Name_Buffer
1589 (" & is missing from output dependence list");
1590
1591 Error_Msg := Name_Find;
1592 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1593 end if;
1594 end Usage_Error;
1595
1596 -- Local variables
1597
1598 Elmt : Elmt_Id;
1599 Item : Node_Id;
1600 Item_Id : Entity_Id;
1601
1602 -- Start of processing for Check_Usage
1603
1604 begin
1605 if No (Subp_Items) then
1606 return;
1607 end if;
1608
1609 -- Each input or output of the subprogram must appear in a dependency
1610 -- relation.
1611
1612 Elmt := First_Elmt (Subp_Items);
1613 while Present (Elmt) loop
1614 Item := Node (Elmt);
1615
1616 if Nkind (Item) = N_Defining_Identifier then
1617 Item_Id := Item;
1618 else
1619 Item_Id := Entity_Of (Item);
1620 end if;
1621
1622 -- The item does not appear in a dependency
1623
1624 if Present (Item_Id)
1625 and then not Contains (Used_Items, Item_Id)
1626 then
1627 if Is_Formal (Item_Id) then
1628 Usage_Error (Item_Id);
1629
1630 -- The current instance of a protected type behaves as a formal
1631 -- parameter (SPARK RM 6.1.4).
1632
1633 elsif Ekind (Item_Id) = E_Protected_Type
1634 or else Is_Single_Protected_Object (Item_Id)
1635 then
1636 Usage_Error (Item_Id);
1637
1638 -- The current instance of a task type behaves as a formal
1639 -- parameter (SPARK RM 6.1.4).
1640
1641 elsif Ekind (Item_Id) = E_Task_Type
1642 or else Is_Single_Task_Object (Item_Id)
1643 then
1644 -- The dependence of a task unit on itself is implicit and
1645 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1646 -- Emit an error if only one input/output is present.
1647
1648 if Task_Input_Seen /= Task_Output_Seen then
1649 Usage_Error (Item_Id);
1650 end if;
1651
1652 -- States and global objects are not used properly only when
1653 -- the subprogram is subject to pragma Global.
1654
1655 elsif Global_Seen then
1656 Usage_Error (Item_Id);
1657 end if;
1658 end if;
1659
1660 Next_Elmt (Elmt);
1661 end loop;
1662 end Check_Usage;
1663
1664 ----------------------
1665 -- Normalize_Clause --
1666 ----------------------
1667
1668 procedure Normalize_Clause (Clause : Node_Id) is
1669 procedure Create_Or_Modify_Clause
1670 (Output : Node_Id;
1671 Outputs : Node_Id;
1672 Inputs : Node_Id;
1673 After : Node_Id;
1674 In_Place : Boolean;
1675 Multiple : Boolean);
1676 -- Create a brand new clause to represent the self-reference or
1677 -- modify the input and/or output lists of an existing clause. Output
1678 -- denotes a self-referencial output. Outputs is the output list of a
1679 -- clause. Inputs is the input list of a clause. After denotes the
1680 -- clause after which the new clause is to be inserted. Flag In_Place
1681 -- should be set when normalizing the last output of an output list.
1682 -- Flag Multiple should be set when Output comes from a list with
1683 -- multiple items.
1684
1685 -----------------------------
1686 -- Create_Or_Modify_Clause --
1687 -----------------------------
1688
1689 procedure Create_Or_Modify_Clause
1690 (Output : Node_Id;
1691 Outputs : Node_Id;
1692 Inputs : Node_Id;
1693 After : Node_Id;
1694 In_Place : Boolean;
1695 Multiple : Boolean)
1696 is
1697 procedure Propagate_Output
1698 (Output : Node_Id;
1699 Inputs : Node_Id);
1700 -- Handle the various cases of output propagation to the input
1701 -- list. Output denotes a self-referencial output item. Inputs
1702 -- is the input list of a clause.
1703
1704 ----------------------
1705 -- Propagate_Output --
1706 ----------------------
1707
1708 procedure Propagate_Output
1709 (Output : Node_Id;
1710 Inputs : Node_Id)
1711 is
1712 function In_Input_List
1713 (Item : Entity_Id;
1714 Inputs : List_Id) return Boolean;
1715 -- Determine whether a particulat item appears in the input
1716 -- list of a clause.
1717
1718 -------------------
1719 -- In_Input_List --
1720 -------------------
1721
1722 function In_Input_List
1723 (Item : Entity_Id;
1724 Inputs : List_Id) return Boolean
1725 is
1726 Elmt : Node_Id;
1727
1728 begin
1729 Elmt := First (Inputs);
1730 while Present (Elmt) loop
1731 if Entity_Of (Elmt) = Item then
1732 return True;
1733 end if;
1734
1735 Next (Elmt);
1736 end loop;
1737
1738 return False;
1739 end In_Input_List;
1740
1741 -- Local variables
1742
1743 Output_Id : constant Entity_Id := Entity_Of (Output);
1744 Grouped : List_Id;
1745
1746 -- Start of processing for Propagate_Output
1747
1748 begin
1749 -- The clause is of the form:
1750
1751 -- (Output =>+ null)
1752
1753 -- Remove null input and replace it with a copy of the output:
1754
1755 -- (Output => Output)
1756
1757 if Nkind (Inputs) = N_Null then
1758 Rewrite (Inputs, New_Copy_Tree (Output));
1759
1760 -- The clause is of the form:
1761
1762 -- (Output =>+ (Input1, ..., InputN))
1763
1764 -- Determine whether the output is not already mentioned in the
1765 -- input list and if not, add it to the list of inputs:
1766
1767 -- (Output => (Output, Input1, ..., InputN))
1768
1769 elsif Nkind (Inputs) = N_Aggregate then
1770 Grouped := Expressions (Inputs);
1771
1772 if not In_Input_List
1773 (Item => Output_Id,
1774 Inputs => Grouped)
1775 then
1776 Prepend_To (Grouped, New_Copy_Tree (Output));
1777 end if;
1778
1779 -- The clause is of the form:
1780
1781 -- (Output =>+ Input)
1782
1783 -- If the input does not mention the output, group the two
1784 -- together:
1785
1786 -- (Output => (Output, Input))
1787
1788 elsif Entity_Of (Inputs) /= Output_Id then
1789 Rewrite (Inputs,
1790 Make_Aggregate (Loc,
1791 Expressions => New_List (
1792 New_Copy_Tree (Output),
1793 New_Copy_Tree (Inputs))));
1794 end if;
1795 end Propagate_Output;
1796
1797 -- Local variables
1798
1799 Loc : constant Source_Ptr := Sloc (Clause);
1800 New_Clause : Node_Id;
1801
1802 -- Start of processing for Create_Or_Modify_Clause
1803
1804 begin
1805 -- A null output depending on itself does not require any
1806 -- normalization.
1807
1808 if Nkind (Output) = N_Null then
1809 return;
1810
1811 -- A function result cannot depend on itself because it cannot
1812 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1813
1814 elsif Is_Attribute_Result (Output) then
1815 SPARK_Msg_N ("function result cannot depend on itself", Output);
1816 return;
1817 end if;
1818
1819 -- When performing the transformation in place, simply add the
1820 -- output to the list of inputs (if not already there). This
1821 -- case arises when dealing with the last output of an output
1822 -- list. Perform the normalization in place to avoid generating
1823 -- a malformed tree.
1824
1825 if In_Place then
1826 Propagate_Output (Output, Inputs);
1827
1828 -- A list with multiple outputs is slowly trimmed until only
1829 -- one element remains. When this happens, replace aggregate
1830 -- with the element itself.
1831
1832 if Multiple then
1833 Remove (Output);
1834 Rewrite (Outputs, Output);
1835 end if;
1836
1837 -- Default case
1838
1839 else
1840 -- Unchain the output from its output list as it will appear in
1841 -- a new clause. Note that we cannot simply rewrite the output
1842 -- as null because this will violate the semantics of pragma
1843 -- Depends.
1844
1845 Remove (Output);
1846
1847 -- Generate a new clause of the form:
1848 -- (Output => Inputs)
1849
1850 New_Clause :=
1851 Make_Component_Association (Loc,
1852 Choices => New_List (Output),
1853 Expression => New_Copy_Tree (Inputs));
1854
1855 -- The new clause contains replicated content that has already
1856 -- been analyzed. There is not need to reanalyze or renormalize
1857 -- it again.
1858
1859 Set_Analyzed (New_Clause);
1860
1861 Propagate_Output
1862 (Output => First (Choices (New_Clause)),
1863 Inputs => Expression (New_Clause));
1864
1865 Insert_After (After, New_Clause);
1866 end if;
1867 end Create_Or_Modify_Clause;
1868
1869 -- Local variables
1870
1871 Outputs : constant Node_Id := First (Choices (Clause));
1872 Inputs : Node_Id;
1873 Last_Output : Node_Id;
1874 Next_Output : Node_Id;
1875 Output : Node_Id;
1876
1877 -- Start of processing for Normalize_Clause
1878
1879 begin
1880 -- A self-dependency appears as operator "+". Remove the "+" from the
1881 -- tree by moving the real inputs to their proper place.
1882
1883 if Nkind (Expression (Clause)) = N_Op_Plus then
1884 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1885 Inputs := Expression (Clause);
1886
1887 -- Multiple outputs appear as an aggregate
1888
1889 if Nkind (Outputs) = N_Aggregate then
1890 Last_Output := Last (Expressions (Outputs));
1891
1892 Output := First (Expressions (Outputs));
1893 while Present (Output) loop
1894
1895 -- Normalization may remove an output from its list,
1896 -- preserve the subsequent output now.
1897
1898 Next_Output := Next (Output);
1899
1900 Create_Or_Modify_Clause
1901 (Output => Output,
1902 Outputs => Outputs,
1903 Inputs => Inputs,
1904 After => Clause,
1905 In_Place => Output = Last_Output,
1906 Multiple => True);
1907
1908 Output := Next_Output;
1909 end loop;
1910
1911 -- Solitary output
1912
1913 else
1914 Create_Or_Modify_Clause
1915 (Output => Outputs,
1916 Outputs => Empty,
1917 Inputs => Inputs,
1918 After => Empty,
1919 In_Place => True,
1920 Multiple => False);
1921 end if;
1922 end if;
1923 end Normalize_Clause;
1924
1925 -- Local variables
1926
1927 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
1928 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1929
1930 Clause : Node_Id;
1931 Errors : Nat;
1932 Last_Clause : Node_Id;
1933 Restore_Scope : Boolean := False;
1934
1935 -- Start of processing for Analyze_Depends_In_Decl_Part
1936
1937 begin
1938 -- Do not analyze the pragma multiple times
1939
1940 if Is_Analyzed_Pragma (N) then
1941 return;
1942 end if;
1943
1944 -- Empty dependency list
1945
1946 if Nkind (Deps) = N_Null then
1947
1948 -- Gather all states, objects and formal parameters that the
1949 -- subprogram may depend on. These items are obtained from the
1950 -- parameter profile or pragma [Refined_]Global (if available).
1951
1952 Collect_Subprogram_Inputs_Outputs
1953 (Subp_Id => Subp_Id,
1954 Subp_Inputs => Subp_Inputs,
1955 Subp_Outputs => Subp_Outputs,
1956 Global_Seen => Global_Seen);
1957
1958 -- Verify that every input or output of the subprogram appear in a
1959 -- dependency.
1960
1961 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1962 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1963 Check_Function_Return;
1964
1965 -- Dependency clauses appear as component associations of an aggregate
1966
1967 elsif Nkind (Deps) = N_Aggregate then
1968
1969 -- Do not attempt to perform analysis of a syntactically illegal
1970 -- clause as this will lead to misleading errors.
1971
1972 if Has_Extra_Parentheses (Deps) then
1973 return;
1974 end if;
1975
1976 if Present (Component_Associations (Deps)) then
1977 Last_Clause := Last (Component_Associations (Deps));
1978
1979 -- Gather all states, objects and formal parameters that the
1980 -- subprogram may depend on. These items are obtained from the
1981 -- parameter profile or pragma [Refined_]Global (if available).
1982
1983 Collect_Subprogram_Inputs_Outputs
1984 (Subp_Id => Subp_Id,
1985 Subp_Inputs => Subp_Inputs,
1986 Subp_Outputs => Subp_Outputs,
1987 Global_Seen => Global_Seen);
1988
1989 -- When pragma [Refined_]Depends appears on a single concurrent
1990 -- type, it is relocated to the anonymous object.
1991
1992 if Is_Single_Concurrent_Object (Spec_Id) then
1993 null;
1994
1995 -- Ensure that the formal parameters are visible when analyzing
1996 -- all clauses. This falls out of the general rule of aspects
1997 -- pertaining to subprogram declarations.
1998
1999 elsif not In_Open_Scopes (Spec_Id) then
2000 Restore_Scope := True;
2001 Push_Scope (Spec_Id);
2002
2003 if Ekind (Spec_Id) = E_Task_Type then
2004 if Has_Discriminants (Spec_Id) then
2005 Install_Discriminants (Spec_Id);
2006 end if;
2007
2008 elsif Is_Generic_Subprogram (Spec_Id) then
2009 Install_Generic_Formals (Spec_Id);
2010
2011 else
2012 Install_Formals (Spec_Id);
2013 end if;
2014 end if;
2015
2016 Clause := First (Component_Associations (Deps));
2017 while Present (Clause) loop
2018 Errors := Serious_Errors_Detected;
2019
2020 -- The normalization mechanism may create extra clauses that
2021 -- contain replicated input and output names. There is no need
2022 -- to reanalyze them.
2023
2024 if not Analyzed (Clause) then
2025 Set_Analyzed (Clause);
2026
2027 Analyze_Dependency_Clause
2028 (Clause => Clause,
2029 Is_Last => Clause = Last_Clause);
2030 end if;
2031
2032 -- Do not normalize a clause if errors were detected (count
2033 -- of Serious_Errors has increased) because the inputs and/or
2034 -- outputs may denote illegal items.
2035
2036 if Serious_Errors_Detected = Errors then
2037 Normalize_Clause (Clause);
2038 end if;
2039
2040 Next (Clause);
2041 end loop;
2042
2043 if Restore_Scope then
2044 End_Scope;
2045 end if;
2046
2047 -- Verify that every input or output of the subprogram appear in a
2048 -- dependency.
2049
2050 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
2051 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
2052 Check_Function_Return;
2053
2054 -- The dependency list is malformed. This is a syntax error, always
2055 -- report.
2056
2057 else
2058 Error_Msg_N ("malformed dependency relation", Deps);
2059 return;
2060 end if;
2061
2062 -- The top level dependency relation is malformed. This is a syntax
2063 -- error, always report.
2064
2065 else
2066 Error_Msg_N ("malformed dependency relation", Deps);
2067 goto Leave;
2068 end if;
2069
2070 -- Ensure that a state and a corresponding constituent do not appear
2071 -- together in pragma [Refined_]Depends.
2072
2073 Check_State_And_Constituent_Use
2074 (States => States_Seen,
2075 Constits => Constits_Seen,
2076 Context => N);
2077
2078 <<Leave>>
2079 Set_Is_Analyzed_Pragma (N);
2080 end Analyze_Depends_In_Decl_Part;
2081
2082 --------------------------------------------
2083 -- Analyze_External_Property_In_Decl_Part --
2084 --------------------------------------------
2085
2086 procedure Analyze_External_Property_In_Decl_Part
2087 (N : Node_Id;
2088 Expr_Val : out Boolean)
2089 is
2090 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pragma_Name (N));
2091 Arg1 : constant Node_Id :=
2092 First (Pragma_Argument_Associations (N));
2093 Obj_Decl : constant Node_Id := Find_Related_Context (N);
2094 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
2095 Expr : Node_Id;
2096
2097 begin
2098 Expr_Val := False;
2099
2100 -- Do not analyze the pragma multiple times
2101
2102 if Is_Analyzed_Pragma (N) then
2103 return;
2104 end if;
2105
2106 Error_Msg_Name_1 := Pragma_Name (N);
2107
2108 -- An external property pragma must apply to an effectively volatile
2109 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
2110 -- The check is performed at the end of the declarative region due to a
2111 -- possible out-of-order arrangement of pragmas:
2112
2113 -- Obj : ...;
2114 -- pragma Async_Readers (Obj);
2115 -- pragma Volatile (Obj);
2116
2117 if Prag_Id /= Pragma_No_Caching
2118 and then not Is_Effectively_Volatile (Obj_Id)
2119 then
2120 if No_Caching_Enabled (Obj_Id) then
2121 SPARK_Msg_N
2122 ("illegal combination of external property % and property "
2123 & """No_Caching"" (SPARK RM 7.1.2(6))", N);
2124 else
2125 SPARK_Msg_N
2126 ("external property % must apply to a volatile object", N);
2127 end if;
2128
2129 -- Pragma No_Caching should only apply to volatile variables of
2130 -- a non-effectively volatile type (SPARK RM 7.1.2).
2131
2132 elsif Prag_Id = Pragma_No_Caching then
2133 if Is_Effectively_Volatile (Etype (Obj_Id)) then
2134 SPARK_Msg_N ("property % must not apply to an object of "
2135 & "an effectively volatile type", N);
2136 elsif not Is_Volatile (Obj_Id) then
2137 SPARK_Msg_N ("property % must apply to a volatile object", N);
2138 end if;
2139 end if;
2140
2141 -- Ensure that the Boolean expression (if present) is static. A missing
2142 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2143
2144 Expr_Val := True;
2145
2146 if Present (Arg1) then
2147 Expr := Get_Pragma_Arg (Arg1);
2148
2149 if Is_OK_Static_Expression (Expr) then
2150 Expr_Val := Is_True (Expr_Value (Expr));
2151 end if;
2152 end if;
2153
2154 Set_Is_Analyzed_Pragma (N);
2155 end Analyze_External_Property_In_Decl_Part;
2156
2157 ---------------------------------
2158 -- Analyze_Global_In_Decl_Part --
2159 ---------------------------------
2160
2161 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
2162 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2163 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2164 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2165
2166 Constits_Seen : Elist_Id := No_Elist;
2167 -- A list containing the entities of all constituents processed so far.
2168 -- It aids in detecting illegal usage of a state and a corresponding
2169 -- constituent in pragma [Refinde_]Global.
2170
2171 Seen : Elist_Id := No_Elist;
2172 -- A list containing the entities of all the items processed so far. It
2173 -- plays a role in detecting distinct entities.
2174
2175 States_Seen : Elist_Id := No_Elist;
2176 -- A list containing the entities of all states processed so far. It
2177 -- helps in detecting illegal usage of a state and a corresponding
2178 -- constituent in pragma [Refined_]Global.
2179
2180 In_Out_Seen : Boolean := False;
2181 Input_Seen : Boolean := False;
2182 Output_Seen : Boolean := False;
2183 Proof_Seen : Boolean := False;
2184 -- Flags used to verify the consistency of modes
2185
2186 procedure Analyze_Global_List
2187 (List : Node_Id;
2188 Global_Mode : Name_Id := Name_Input);
2189 -- Verify the legality of a single global list declaration. Global_Mode
2190 -- denotes the current mode in effect.
2191
2192 -------------------------
2193 -- Analyze_Global_List --
2194 -------------------------
2195
2196 procedure Analyze_Global_List
2197 (List : Node_Id;
2198 Global_Mode : Name_Id := Name_Input)
2199 is
2200 procedure Analyze_Global_Item
2201 (Item : Node_Id;
2202 Global_Mode : Name_Id);
2203 -- Verify the legality of a single global item declaration denoted by
2204 -- Item. Global_Mode denotes the current mode in effect.
2205
2206 procedure Check_Duplicate_Mode
2207 (Mode : Node_Id;
2208 Status : in out Boolean);
2209 -- Flag Status denotes whether a particular mode has been seen while
2210 -- processing a global list. This routine verifies that Mode is not a
2211 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2212
2213 procedure Check_Mode_Restriction_In_Enclosing_Context
2214 (Item : Node_Id;
2215 Item_Id : Entity_Id);
2216 -- Verify that an item of mode In_Out or Output does not appear as
2217 -- an input in the Global aspect of an enclosing subprogram or task
2218 -- unit. If this is the case, emit an error. Item and Item_Id are
2219 -- respectively the item and its entity.
2220
2221 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
2222 -- Mode denotes either In_Out or Output. Depending on the kind of the
2223 -- related subprogram, emit an error if those two modes apply to a
2224 -- function (SPARK RM 6.1.4(10)).
2225
2226 -------------------------
2227 -- Analyze_Global_Item --
2228 -------------------------
2229
2230 procedure Analyze_Global_Item
2231 (Item : Node_Id;
2232 Global_Mode : Name_Id)
2233 is
2234 Item_Id : Entity_Id;
2235
2236 begin
2237 -- Detect one of the following cases
2238
2239 -- with Global => (null, Name)
2240 -- with Global => (Name_1, null, Name_2)
2241 -- with Global => (Name, null)
2242
2243 if Nkind (Item) = N_Null then
2244 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
2245 return;
2246 end if;
2247
2248 Analyze (Item);
2249 Resolve_State (Item);
2250
2251 -- Find the entity of the item. If this is a renaming, climb the
2252 -- renaming chain to reach the root object. Renamings of non-
2253 -- entire objects do not yield an entity (Empty).
2254
2255 Item_Id := Entity_Of (Item);
2256
2257 if Present (Item_Id) then
2258
2259 -- A global item may denote a formal parameter of an enclosing
2260 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2261 -- provide a better error diagnostic.
2262
2263 if Is_Formal (Item_Id) then
2264 if Scope (Item_Id) = Spec_Id then
2265 SPARK_Msg_NE
2266 (Fix_Msg (Spec_Id, "global item cannot reference "
2267 & "parameter of subprogram &"), Item, Spec_Id);
2268 return;
2269 end if;
2270
2271 -- A global item may denote a concurrent type as long as it is
2272 -- the current instance of an enclosing protected or task type
2273 -- (SPARK RM 6.1.4).
2274
2275 elsif Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
2276 if Is_CCT_Instance (Item_Id, Spec_Id) then
2277
2278 -- Pragma [Refined_]Global associated with a protected
2279 -- subprogram cannot mention the current instance of a
2280 -- protected type because the instance behaves as a
2281 -- formal parameter.
2282
2283 if Ekind (Item_Id) = E_Protected_Type then
2284 if Scope (Spec_Id) = Item_Id then
2285 Error_Msg_Name_1 := Chars (Item_Id);
2286 SPARK_Msg_NE
2287 (Fix_Msg (Spec_Id, "global item of subprogram & "
2288 & "cannot reference current instance of "
2289 & "protected type %"), Item, Spec_Id);
2290 return;
2291 end if;
2292
2293 -- Pragma [Refined_]Global associated with a task type
2294 -- cannot mention the current instance of a task type
2295 -- because the instance behaves as a formal parameter.
2296
2297 else pragma Assert (Ekind (Item_Id) = E_Task_Type);
2298 if Spec_Id = Item_Id then
2299 Error_Msg_Name_1 := Chars (Item_Id);
2300 SPARK_Msg_NE
2301 (Fix_Msg (Spec_Id, "global item of subprogram & "
2302 & "cannot reference current instance of task "
2303 & "type %"), Item, Spec_Id);
2304 return;
2305 end if;
2306 end if;
2307
2308 -- Otherwise the global item denotes a subtype mark that is
2309 -- not a current instance.
2310
2311 else
2312 SPARK_Msg_N
2313 ("invalid use of subtype mark in global list", Item);
2314 return;
2315 end if;
2316
2317 -- A global item may denote the anonymous object created for a
2318 -- single protected/task type as long as the current instance
2319 -- is the same single type (SPARK RM 6.1.4).
2320
2321 elsif Is_Single_Concurrent_Object (Item_Id)
2322 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
2323 then
2324 -- Pragma [Refined_]Global associated with a protected
2325 -- subprogram cannot mention the current instance of a
2326 -- protected type because the instance behaves as a formal
2327 -- parameter.
2328
2329 if Is_Single_Protected_Object (Item_Id) then
2330 if Scope (Spec_Id) = Etype (Item_Id) then
2331 Error_Msg_Name_1 := Chars (Item_Id);
2332 SPARK_Msg_NE
2333 (Fix_Msg (Spec_Id, "global item of subprogram & "
2334 & "cannot reference current instance of protected "
2335 & "type %"), Item, Spec_Id);
2336 return;
2337 end if;
2338
2339 -- Pragma [Refined_]Global associated with a task type
2340 -- cannot mention the current instance of a task type
2341 -- because the instance behaves as a formal parameter.
2342
2343 else pragma Assert (Is_Single_Task_Object (Item_Id));
2344 if Spec_Id = Item_Id then
2345 Error_Msg_Name_1 := Chars (Item_Id);
2346 SPARK_Msg_NE
2347 (Fix_Msg (Spec_Id, "global item of subprogram & "
2348 & "cannot reference current instance of task "
2349 & "type %"), Item, Spec_Id);
2350 return;
2351 end if;
2352 end if;
2353
2354 -- A formal object may act as a global item inside a generic
2355
2356 elsif Is_Formal_Object (Item_Id) then
2357 null;
2358
2359 -- The only legal references are those to abstract states,
2360 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2361
2362 elsif not Ekind_In (Item_Id, E_Abstract_State,
2363 E_Constant,
2364 E_Loop_Parameter,
2365 E_Variable)
2366 then
2367 SPARK_Msg_N
2368 ("global item must denote object, state or current "
2369 & "instance of concurrent type", Item);
2370
2371 if Ekind (Item_Id) in Named_Kind then
2372 SPARK_Msg_NE
2373 ("\named number & is not an object", Item, Item);
2374 end if;
2375
2376 return;
2377 end if;
2378
2379 -- State related checks
2380
2381 if Ekind (Item_Id) = E_Abstract_State then
2382
2383 -- Package and subprogram bodies are instantiated
2384 -- individually in a separate compiler pass. Due to this
2385 -- mode of instantiation, the refinement of a state may
2386 -- no longer be visible when a subprogram body contract
2387 -- is instantiated. Since the generic template is legal,
2388 -- do not perform this check in the instance to circumvent
2389 -- this oddity.
2390
2391 if In_Instance then
2392 null;
2393
2394 -- An abstract state with visible refinement cannot appear
2395 -- in pragma [Refined_]Global as its place must be taken by
2396 -- some of its constituents (SPARK RM 6.1.4(7)).
2397
2398 elsif Has_Visible_Refinement (Item_Id) then
2399 SPARK_Msg_NE
2400 ("cannot mention state & in global refinement",
2401 Item, Item_Id);
2402 SPARK_Msg_N ("\use its constituents instead", Item);
2403 return;
2404
2405 -- An external state cannot appear as a global item of a
2406 -- nonvolatile function (SPARK RM 7.1.3(8)).
2407
2408 elsif Is_External_State (Item_Id)
2409 and then Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2410 and then not Is_Volatile_Function (Spec_Id)
2411 then
2412 SPARK_Msg_NE
2413 ("external state & cannot act as global item of "
2414 & "nonvolatile function", Item, Item_Id);
2415 return;
2416
2417 -- If the reference to the abstract state appears in an
2418 -- enclosing package body that will eventually refine the
2419 -- state, record the reference for future checks.
2420
2421 else
2422 Record_Possible_Body_Reference
2423 (State_Id => Item_Id,
2424 Ref => Item);
2425 end if;
2426
2427 -- Constant related checks
2428
2429 elsif Ekind (Item_Id) = E_Constant
2430 and then not Is_Access_Type (Etype (Item_Id))
2431 then
2432
2433 -- Unless it is of an access type, a constant is a read-only
2434 -- item, therefore it cannot act as an output.
2435
2436 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2437 SPARK_Msg_NE
2438 ("constant & cannot act as output", Item, Item_Id);
2439 return;
2440 end if;
2441
2442 -- Loop parameter related checks
2443
2444 elsif Ekind (Item_Id) = E_Loop_Parameter then
2445
2446 -- A loop parameter is a read-only item, therefore it cannot
2447 -- act as an output.
2448
2449 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2450 SPARK_Msg_NE
2451 ("loop parameter & cannot act as output",
2452 Item, Item_Id);
2453 return;
2454 end if;
2455
2456 -- Variable related checks. These are only relevant when
2457 -- SPARK_Mode is on as they are not standard Ada legality
2458 -- rules.
2459
2460 elsif SPARK_Mode = On
2461 and then Ekind (Item_Id) = E_Variable
2462 and then Is_Effectively_Volatile (Item_Id)
2463 then
2464 -- An effectively volatile object cannot appear as a global
2465 -- item of a nonvolatile function (SPARK RM 7.1.3(8)).
2466
2467 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2468 and then not Is_Volatile_Function (Spec_Id)
2469 then
2470 Error_Msg_NE
2471 ("volatile object & cannot act as global item of a "
2472 & "function", Item, Item_Id);
2473 return;
2474
2475 -- An effectively volatile object with external property
2476 -- Effective_Reads set to True must have mode Output or
2477 -- In_Out (SPARK RM 7.1.3(10)).
2478
2479 elsif Effective_Reads_Enabled (Item_Id)
2480 and then Global_Mode = Name_Input
2481 then
2482 Error_Msg_NE
2483 ("volatile object & with property Effective_Reads must "
2484 & "have mode In_Out or Output", Item, Item_Id);
2485 return;
2486 end if;
2487 end if;
2488
2489 -- When the item renames an entire object, replace the item
2490 -- with a reference to the object.
2491
2492 if Entity (Item) /= Item_Id then
2493 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2494 Analyze (Item);
2495 end if;
2496
2497 -- Some form of illegal construct masquerading as a name
2498 -- (SPARK RM 6.1.4(4)).
2499
2500 else
2501 Error_Msg_N
2502 ("global item must denote object, state or current instance "
2503 & "of concurrent type", Item);
2504 return;
2505 end if;
2506
2507 -- Verify that an output does not appear as an input in an
2508 -- enclosing subprogram.
2509
2510 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2511 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2512 end if;
2513
2514 -- The same entity might be referenced through various way.
2515 -- Check the entity of the item rather than the item itself
2516 -- (SPARK RM 6.1.4(10)).
2517
2518 if Contains (Seen, Item_Id) then
2519 SPARK_Msg_N ("duplicate global item", Item);
2520
2521 -- Add the entity of the current item to the list of processed
2522 -- items.
2523
2524 else
2525 Append_New_Elmt (Item_Id, Seen);
2526
2527 if Ekind (Item_Id) = E_Abstract_State then
2528 Append_New_Elmt (Item_Id, States_Seen);
2529
2530 -- The variable may eventually become a constituent of a single
2531 -- protected/task type. Record the reference now and verify its
2532 -- legality when analyzing the contract of the variable
2533 -- (SPARK RM 9.3).
2534
2535 elsif Ekind (Item_Id) = E_Variable then
2536 Record_Possible_Part_Of_Reference
2537 (Var_Id => Item_Id,
2538 Ref => Item);
2539 end if;
2540
2541 if Ekind_In (Item_Id, E_Abstract_State, E_Constant, E_Variable)
2542 and then Present (Encapsulating_State (Item_Id))
2543 then
2544 Append_New_Elmt (Item_Id, Constits_Seen);
2545 end if;
2546 end if;
2547 end Analyze_Global_Item;
2548
2549 --------------------------
2550 -- Check_Duplicate_Mode --
2551 --------------------------
2552
2553 procedure Check_Duplicate_Mode
2554 (Mode : Node_Id;
2555 Status : in out Boolean)
2556 is
2557 begin
2558 if Status then
2559 SPARK_Msg_N ("duplicate global mode", Mode);
2560 end if;
2561
2562 Status := True;
2563 end Check_Duplicate_Mode;
2564
2565 -------------------------------------------------
2566 -- Check_Mode_Restriction_In_Enclosing_Context --
2567 -------------------------------------------------
2568
2569 procedure Check_Mode_Restriction_In_Enclosing_Context
2570 (Item : Node_Id;
2571 Item_Id : Entity_Id)
2572 is
2573 Context : Entity_Id;
2574 Dummy : Boolean;
2575 Inputs : Elist_Id := No_Elist;
2576 Outputs : Elist_Id := No_Elist;
2577
2578 begin
2579 -- Traverse the scope stack looking for enclosing subprograms or
2580 -- tasks subject to pragma [Refined_]Global.
2581
2582 Context := Scope (Subp_Id);
2583 while Present (Context) and then Context /= Standard_Standard loop
2584
2585 -- For a single task type, retrieve the corresponding object to
2586 -- which pragma [Refined_]Global is attached.
2587
2588 if Ekind (Context) = E_Task_Type
2589 and then Is_Single_Concurrent_Type (Context)
2590 then
2591 Context := Anonymous_Object (Context);
2592 end if;
2593
2594 if (Is_Subprogram (Context)
2595 or else Ekind (Context) = E_Task_Type
2596 or else Is_Single_Task_Object (Context))
2597 and then
2598 (Present (Get_Pragma (Context, Pragma_Global))
2599 or else
2600 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2601 then
2602 Collect_Subprogram_Inputs_Outputs
2603 (Subp_Id => Context,
2604 Subp_Inputs => Inputs,
2605 Subp_Outputs => Outputs,
2606 Global_Seen => Dummy);
2607
2608 -- The item is classified as In_Out or Output but appears as
2609 -- an Input in an enclosing subprogram or task unit (SPARK
2610 -- RM 6.1.4(12)).
2611
2612 if Appears_In (Inputs, Item_Id)
2613 and then not Appears_In (Outputs, Item_Id)
2614 then
2615 SPARK_Msg_NE
2616 ("global item & cannot have mode In_Out or Output",
2617 Item, Item_Id);
2618
2619 if Is_Subprogram (Context) then
2620 SPARK_Msg_NE
2621 (Fix_Msg (Subp_Id, "\item already appears as input "
2622 & "of subprogram &"), Item, Context);
2623 else
2624 SPARK_Msg_NE
2625 (Fix_Msg (Subp_Id, "\item already appears as input "
2626 & "of task &"), Item, Context);
2627 end if;
2628
2629 -- Stop the traversal once an error has been detected
2630
2631 exit;
2632 end if;
2633 end if;
2634
2635 Context := Scope (Context);
2636 end loop;
2637 end Check_Mode_Restriction_In_Enclosing_Context;
2638
2639 ----------------------------------------
2640 -- Check_Mode_Restriction_In_Function --
2641 ----------------------------------------
2642
2643 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2644 begin
2645 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
2646 SPARK_Msg_N
2647 ("global mode & is not applicable to functions", Mode);
2648 end if;
2649 end Check_Mode_Restriction_In_Function;
2650
2651 -- Local variables
2652
2653 Assoc : Node_Id;
2654 Item : Node_Id;
2655 Mode : Node_Id;
2656
2657 -- Start of processing for Analyze_Global_List
2658
2659 begin
2660 if Nkind (List) = N_Null then
2661 Set_Analyzed (List);
2662
2663 -- Single global item declaration
2664
2665 elsif Nkind_In (List, N_Expanded_Name,
2666 N_Identifier,
2667 N_Selected_Component)
2668 then
2669 Analyze_Global_Item (List, Global_Mode);
2670
2671 -- Simple global list or moded global list declaration
2672
2673 elsif Nkind (List) = N_Aggregate then
2674 Set_Analyzed (List);
2675
2676 -- The declaration of a simple global list appear as a collection
2677 -- of expressions.
2678
2679 if Present (Expressions (List)) then
2680 if Present (Component_Associations (List)) then
2681 SPARK_Msg_N
2682 ("cannot mix moded and non-moded global lists", List);
2683 end if;
2684
2685 Item := First (Expressions (List));
2686 while Present (Item) loop
2687 Analyze_Global_Item (Item, Global_Mode);
2688 Next (Item);
2689 end loop;
2690
2691 -- The declaration of a moded global list appears as a collection
2692 -- of component associations where individual choices denote
2693 -- modes.
2694
2695 elsif Present (Component_Associations (List)) then
2696 if Present (Expressions (List)) then
2697 SPARK_Msg_N
2698 ("cannot mix moded and non-moded global lists", List);
2699 end if;
2700
2701 Assoc := First (Component_Associations (List));
2702 while Present (Assoc) loop
2703 Mode := First (Choices (Assoc));
2704
2705 if Nkind (Mode) = N_Identifier then
2706 if Chars (Mode) = Name_In_Out then
2707 Check_Duplicate_Mode (Mode, In_Out_Seen);
2708 Check_Mode_Restriction_In_Function (Mode);
2709
2710 elsif Chars (Mode) = Name_Input then
2711 Check_Duplicate_Mode (Mode, Input_Seen);
2712
2713 elsif Chars (Mode) = Name_Output then
2714 Check_Duplicate_Mode (Mode, Output_Seen);
2715 Check_Mode_Restriction_In_Function (Mode);
2716
2717 elsif Chars (Mode) = Name_Proof_In then
2718 Check_Duplicate_Mode (Mode, Proof_Seen);
2719
2720 else
2721 SPARK_Msg_N ("invalid mode selector", Mode);
2722 end if;
2723
2724 else
2725 SPARK_Msg_N ("invalid mode selector", Mode);
2726 end if;
2727
2728 -- Items in a moded list appear as a collection of
2729 -- expressions. Reuse the existing machinery to analyze
2730 -- them.
2731
2732 Analyze_Global_List
2733 (List => Expression (Assoc),
2734 Global_Mode => Chars (Mode));
2735
2736 Next (Assoc);
2737 end loop;
2738
2739 -- Invalid tree
2740
2741 else
2742 raise Program_Error;
2743 end if;
2744
2745 -- Any other attempt to declare a global item is illegal. This is a
2746 -- syntax error, always report.
2747
2748 else
2749 Error_Msg_N ("malformed global list", List);
2750 end if;
2751 end Analyze_Global_List;
2752
2753 -- Local variables
2754
2755 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2756
2757 Restore_Scope : Boolean := False;
2758
2759 -- Start of processing for Analyze_Global_In_Decl_Part
2760
2761 begin
2762 -- Do not analyze the pragma multiple times
2763
2764 if Is_Analyzed_Pragma (N) then
2765 return;
2766 end if;
2767
2768 -- There is nothing to be done for a null global list
2769
2770 if Nkind (Items) = N_Null then
2771 Set_Analyzed (Items);
2772
2773 -- Analyze the various forms of global lists and items. Note that some
2774 -- of these may be malformed in which case the analysis emits error
2775 -- messages.
2776
2777 else
2778 -- When pragma [Refined_]Global appears on a single concurrent type,
2779 -- it is relocated to the anonymous object.
2780
2781 if Is_Single_Concurrent_Object (Spec_Id) then
2782 null;
2783
2784 -- Ensure that the formal parameters are visible when processing an
2785 -- item. This falls out of the general rule of aspects pertaining to
2786 -- subprogram declarations.
2787
2788 elsif not In_Open_Scopes (Spec_Id) then
2789 Restore_Scope := True;
2790 Push_Scope (Spec_Id);
2791
2792 if Ekind (Spec_Id) = E_Task_Type then
2793 if Has_Discriminants (Spec_Id) then
2794 Install_Discriminants (Spec_Id);
2795 end if;
2796
2797 elsif Is_Generic_Subprogram (Spec_Id) then
2798 Install_Generic_Formals (Spec_Id);
2799
2800 else
2801 Install_Formals (Spec_Id);
2802 end if;
2803 end if;
2804
2805 Analyze_Global_List (Items);
2806
2807 if Restore_Scope then
2808 End_Scope;
2809 end if;
2810 end if;
2811
2812 -- Ensure that a state and a corresponding constituent do not appear
2813 -- together in pragma [Refined_]Global.
2814
2815 Check_State_And_Constituent_Use
2816 (States => States_Seen,
2817 Constits => Constits_Seen,
2818 Context => N);
2819
2820 Set_Is_Analyzed_Pragma (N);
2821 end Analyze_Global_In_Decl_Part;
2822
2823 --------------------------------------------
2824 -- Analyze_Initial_Condition_In_Decl_Part --
2825 --------------------------------------------
2826
2827 -- WARNING: This routine manages Ghost regions. Return statements must be
2828 -- replaced by gotos which jump to the end of the routine and restore the
2829 -- Ghost mode.
2830
2831 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2832 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2833 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2834 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2835
2836 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
2837 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
2838 -- Save the Ghost-related attributes to restore on exit
2839
2840 begin
2841 -- Do not analyze the pragma multiple times
2842
2843 if Is_Analyzed_Pragma (N) then
2844 return;
2845 end if;
2846
2847 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2848 -- analysis of the pragma, the Ghost mode at point of declaration and
2849 -- point of analysis may not necessarily be the same. Use the mode in
2850 -- effect at the point of declaration.
2851
2852 Set_Ghost_Mode (N);
2853
2854 -- The expression is preanalyzed because it has not been moved to its
2855 -- final place yet. A direct analysis may generate side effects and this
2856 -- is not desired at this point.
2857
2858 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2859 Set_Is_Analyzed_Pragma (N);
2860
2861 Restore_Ghost_Region (Saved_GM, Saved_IGR);
2862 end Analyze_Initial_Condition_In_Decl_Part;
2863
2864 --------------------------------------
2865 -- Analyze_Initializes_In_Decl_Part --
2866 --------------------------------------
2867
2868 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2869 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2870 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2871
2872 Constits_Seen : Elist_Id := No_Elist;
2873 -- A list containing the entities of all constituents processed so far.
2874 -- It aids in detecting illegal usage of a state and a corresponding
2875 -- constituent in pragma Initializes.
2876
2877 Items_Seen : Elist_Id := No_Elist;
2878 -- A list of all initialization items processed so far. This list is
2879 -- used to detect duplicate items.
2880
2881 States_And_Objs : Elist_Id := No_Elist;
2882 -- A list of all abstract states and objects declared in the visible
2883 -- declarations of the related package. This list is used to detect the
2884 -- legality of initialization items.
2885
2886 States_Seen : Elist_Id := No_Elist;
2887 -- A list containing the entities of all states processed so far. It
2888 -- helps in detecting illegal usage of a state and a corresponding
2889 -- constituent in pragma Initializes.
2890
2891 procedure Analyze_Initialization_Item (Item : Node_Id);
2892 -- Verify the legality of a single initialization item
2893
2894 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2895 -- Verify the legality of a single initialization item followed by a
2896 -- list of input items.
2897
2898 procedure Collect_States_And_Objects (Pack_Decl : Node_Id);
2899 -- Inspect the visible declarations of the related package and gather
2900 -- the entities of all abstract states and objects in States_And_Objs.
2901
2902 ---------------------------------
2903 -- Analyze_Initialization_Item --
2904 ---------------------------------
2905
2906 procedure Analyze_Initialization_Item (Item : Node_Id) is
2907 Item_Id : Entity_Id;
2908
2909 begin
2910 Analyze (Item);
2911 Resolve_State (Item);
2912
2913 if Is_Entity_Name (Item) then
2914 Item_Id := Entity_Of (Item);
2915
2916 if Present (Item_Id)
2917 and then Ekind_In (Item_Id, E_Abstract_State,
2918 E_Constant,
2919 E_Variable)
2920 then
2921 -- When the initialization item is undefined, it appears as
2922 -- Any_Id. Do not continue with the analysis of the item.
2923
2924 if Item_Id = Any_Id then
2925 null;
2926
2927 -- The state or variable must be declared in the visible
2928 -- declarations of the package (SPARK RM 7.1.5(7)).
2929
2930 elsif not Contains (States_And_Objs, Item_Id) then
2931 Error_Msg_Name_1 := Chars (Pack_Id);
2932 SPARK_Msg_NE
2933 ("initialization item & must appear in the visible "
2934 & "declarations of package %", Item, Item_Id);
2935
2936 -- Detect a duplicate use of the same initialization item
2937 -- (SPARK RM 7.1.5(5)).
2938
2939 elsif Contains (Items_Seen, Item_Id) then
2940 SPARK_Msg_N ("duplicate initialization item", Item);
2941
2942 -- The item is legal, add it to the list of processed states
2943 -- and variables.
2944
2945 else
2946 Append_New_Elmt (Item_Id, Items_Seen);
2947
2948 if Ekind (Item_Id) = E_Abstract_State then
2949 Append_New_Elmt (Item_Id, States_Seen);
2950 end if;
2951
2952 if Present (Encapsulating_State (Item_Id)) then
2953 Append_New_Elmt (Item_Id, Constits_Seen);
2954 end if;
2955 end if;
2956
2957 -- The item references something that is not a state or object
2958 -- (SPARK RM 7.1.5(3)).
2959
2960 else
2961 SPARK_Msg_N
2962 ("initialization item must denote object or state", Item);
2963 end if;
2964
2965 -- Some form of illegal construct masquerading as a name
2966 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2967
2968 else
2969 Error_Msg_N
2970 ("initialization item must denote object or state", Item);
2971 end if;
2972 end Analyze_Initialization_Item;
2973
2974 ---------------------------------------------
2975 -- Analyze_Initialization_Item_With_Inputs --
2976 ---------------------------------------------
2977
2978 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2979 Inputs_Seen : Elist_Id := No_Elist;
2980 -- A list of all inputs processed so far. This list is used to detect
2981 -- duplicate uses of an input.
2982
2983 Non_Null_Seen : Boolean := False;
2984 Null_Seen : Boolean := False;
2985 -- Flags used to check the legality of an input list
2986
2987 procedure Analyze_Input_Item (Input : Node_Id);
2988 -- Verify the legality of a single input item
2989
2990 ------------------------
2991 -- Analyze_Input_Item --
2992 ------------------------
2993
2994 procedure Analyze_Input_Item (Input : Node_Id) is
2995 Input_Id : Entity_Id;
2996
2997 begin
2998 -- Null input list
2999
3000 if Nkind (Input) = N_Null then
3001 if Null_Seen then
3002 SPARK_Msg_N
3003 ("multiple null initializations not allowed", Item);
3004
3005 elsif Non_Null_Seen then
3006 SPARK_Msg_N
3007 ("cannot mix null and non-null initialization item", Item);
3008 else
3009 Null_Seen := True;
3010 end if;
3011
3012 -- Input item
3013
3014 else
3015 Non_Null_Seen := True;
3016
3017 if Null_Seen then
3018 SPARK_Msg_N
3019 ("cannot mix null and non-null initialization item", Item);
3020 end if;
3021
3022 Analyze (Input);
3023 Resolve_State (Input);
3024
3025 if Is_Entity_Name (Input) then
3026 Input_Id := Entity_Of (Input);
3027
3028 if Present (Input_Id)
3029 and then Ekind_In (Input_Id, E_Abstract_State,
3030 E_Constant,
3031 E_Generic_In_Out_Parameter,
3032 E_Generic_In_Parameter,
3033 E_In_Parameter,
3034 E_In_Out_Parameter,
3035 E_Out_Parameter,
3036 E_Protected_Type,
3037 E_Task_Type,
3038 E_Variable)
3039 then
3040 -- The input cannot denote states or objects declared
3041 -- within the related package (SPARK RM 7.1.5(4)).
3042
3043 if Within_Scope (Input_Id, Current_Scope) then
3044
3045 -- Do not consider generic formal parameters or their
3046 -- respective mappings to generic formals. Even though
3047 -- the formals appear within the scope of the package,
3048 -- it is allowed for an initialization item to depend
3049 -- on an input item.
3050
3051 if Ekind_In (Input_Id, E_Generic_In_Out_Parameter,
3052 E_Generic_In_Parameter)
3053 then
3054 null;
3055
3056 elsif Ekind_In (Input_Id, E_Constant, E_Variable)
3057 and then Present (Corresponding_Generic_Association
3058 (Declaration_Node (Input_Id)))
3059 then
3060 null;
3061
3062 else
3063 Error_Msg_Name_1 := Chars (Pack_Id);
3064 SPARK_Msg_NE
3065 ("input item & cannot denote a visible object or "
3066 & "state of package %", Input, Input_Id);
3067 return;
3068 end if;
3069 end if;
3070
3071 -- Detect a duplicate use of the same input item
3072 -- (SPARK RM 7.1.5(5)).
3073
3074 if Contains (Inputs_Seen, Input_Id) then
3075 SPARK_Msg_N ("duplicate input item", Input);
3076 return;
3077 end if;
3078
3079 -- At this point it is known that the input is legal. Add
3080 -- it to the list of processed inputs.
3081
3082 Append_New_Elmt (Input_Id, Inputs_Seen);
3083
3084 if Ekind (Input_Id) = E_Abstract_State then
3085 Append_New_Elmt (Input_Id, States_Seen);
3086 end if;
3087
3088 if Ekind_In (Input_Id, E_Abstract_State,
3089 E_Constant,
3090 E_Variable)
3091 and then Present (Encapsulating_State (Input_Id))
3092 then
3093 Append_New_Elmt (Input_Id, Constits_Seen);
3094 end if;
3095
3096 -- The input references something that is not a state or an
3097 -- object (SPARK RM 7.1.5(3)).
3098
3099 else
3100 SPARK_Msg_N
3101 ("input item must denote object or state", Input);
3102 end if;
3103
3104 -- Some form of illegal construct masquerading as a name
3105 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
3106
3107 else
3108 Error_Msg_N
3109 ("input item must denote object or state", Input);
3110 end if;
3111 end if;
3112 end Analyze_Input_Item;
3113
3114 -- Local variables
3115
3116 Inputs : constant Node_Id := Expression (Item);
3117 Elmt : Node_Id;
3118 Input : Node_Id;
3119
3120 Name_Seen : Boolean := False;
3121 -- A flag used to detect multiple item names
3122
3123 -- Start of processing for Analyze_Initialization_Item_With_Inputs
3124
3125 begin
3126 -- Inspect the name of an item with inputs
3127
3128 Elmt := First (Choices (Item));
3129 while Present (Elmt) loop
3130 if Name_Seen then
3131 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
3132 else
3133 Name_Seen := True;
3134 Analyze_Initialization_Item (Elmt);
3135 end if;
3136
3137 Next (Elmt);
3138 end loop;
3139
3140 -- Multiple input items appear as an aggregate
3141
3142 if Nkind (Inputs) = N_Aggregate then
3143 if Present (Expressions (Inputs)) then
3144 Input := First (Expressions (Inputs));
3145 while Present (Input) loop
3146 Analyze_Input_Item (Input);
3147 Next (Input);
3148 end loop;
3149 end if;
3150
3151 if Present (Component_Associations (Inputs)) then
3152 SPARK_Msg_N
3153 ("inputs must appear in named association form", Inputs);
3154 end if;
3155
3156 -- Single input item
3157
3158 else
3159 Analyze_Input_Item (Inputs);
3160 end if;
3161 end Analyze_Initialization_Item_With_Inputs;
3162
3163 --------------------------------
3164 -- Collect_States_And_Objects --
3165 --------------------------------
3166
3167 procedure Collect_States_And_Objects (Pack_Decl : Node_Id) is
3168 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
3169 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
3170 Decl : Node_Id;
3171 State_Elmt : Elmt_Id;
3172
3173 begin
3174 -- Collect the abstract states defined in the package (if any)
3175
3176 if Has_Non_Null_Abstract_State (Pack_Id) then
3177 State_Elmt := First_Elmt (Abstract_States (Pack_Id));
3178 while Present (State_Elmt) loop
3179 Append_New_Elmt (Node (State_Elmt), States_And_Objs);
3180 Next_Elmt (State_Elmt);
3181 end loop;
3182 end if;
3183
3184 -- Collect all objects that appear in the visible declarations of the
3185 -- related package.
3186
3187 if Present (Visible_Declarations (Pack_Spec)) then
3188 Decl := First (Visible_Declarations (Pack_Spec));
3189 while Present (Decl) loop
3190 if Comes_From_Source (Decl)
3191 and then Nkind_In (Decl, N_Object_Declaration,
3192 N_Object_Renaming_Declaration)
3193 then
3194 Append_New_Elmt (Defining_Entity (Decl), States_And_Objs);
3195
3196 elsif Nkind (Decl) = N_Package_Declaration then
3197 Collect_States_And_Objects (Decl);
3198
3199 elsif Is_Single_Concurrent_Type_Declaration (Decl) then
3200 Append_New_Elmt
3201 (Anonymous_Object (Defining_Entity (Decl)),
3202 States_And_Objs);
3203 end if;
3204
3205 Next (Decl);
3206 end loop;
3207 end if;
3208 end Collect_States_And_Objects;
3209
3210 -- Local variables
3211
3212 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3213 Init : Node_Id;
3214
3215 -- Start of processing for Analyze_Initializes_In_Decl_Part
3216
3217 begin
3218 -- Do not analyze the pragma multiple times
3219
3220 if Is_Analyzed_Pragma (N) then
3221 return;
3222 end if;
3223
3224 -- Nothing to do when the initialization list is empty
3225
3226 if Nkind (Inits) = N_Null then
3227 return;
3228 end if;
3229
3230 -- Single and multiple initialization clauses appear as an aggregate. If
3231 -- this is not the case, then either the parser or the analysis of the
3232 -- pragma failed to produce an aggregate.
3233
3234 pragma Assert (Nkind (Inits) = N_Aggregate);
3235
3236 -- Initialize the various lists used during analysis
3237
3238 Collect_States_And_Objects (Pack_Decl);
3239
3240 if Present (Expressions (Inits)) then
3241 Init := First (Expressions (Inits));
3242 while Present (Init) loop
3243 Analyze_Initialization_Item (Init);
3244 Next (Init);
3245 end loop;
3246 end if;
3247
3248 if Present (Component_Associations (Inits)) then
3249 Init := First (Component_Associations (Inits));
3250 while Present (Init) loop
3251 Analyze_Initialization_Item_With_Inputs (Init);
3252 Next (Init);
3253 end loop;
3254 end if;
3255
3256 -- Ensure that a state and a corresponding constituent do not appear
3257 -- together in pragma Initializes.
3258
3259 Check_State_And_Constituent_Use
3260 (States => States_Seen,
3261 Constits => Constits_Seen,
3262 Context => N);
3263
3264 Set_Is_Analyzed_Pragma (N);
3265 end Analyze_Initializes_In_Decl_Part;
3266
3267 ---------------------
3268 -- Analyze_Part_Of --
3269 ---------------------
3270
3271 procedure Analyze_Part_Of
3272 (Indic : Node_Id;
3273 Item_Id : Entity_Id;
3274 Encap : Node_Id;
3275 Encap_Id : out Entity_Id;
3276 Legal : out Boolean)
3277 is
3278 procedure Check_Part_Of_Abstract_State;
3279 pragma Inline (Check_Part_Of_Abstract_State);
3280 -- Verify the legality of indicator Part_Of when the encapsulator is an
3281 -- abstract state.
3282
3283 procedure Check_Part_Of_Concurrent_Type;
3284 pragma Inline (Check_Part_Of_Concurrent_Type);
3285 -- Verify the legality of indicator Part_Of when the encapsulator is a
3286 -- single concurrent type.
3287
3288 ----------------------------------
3289 -- Check_Part_Of_Abstract_State --
3290 ----------------------------------
3291
3292 procedure Check_Part_Of_Abstract_State is
3293 Pack_Id : Entity_Id;
3294 Placement : State_Space_Kind;
3295 Parent_Unit : Entity_Id;
3296
3297 begin
3298 -- Determine where the object, package instantiation or state lives
3299 -- with respect to the enclosing packages or package bodies.
3300
3301 Find_Placement_In_State_Space
3302 (Item_Id => Item_Id,
3303 Placement => Placement,
3304 Pack_Id => Pack_Id);
3305
3306 -- The item appears in a non-package construct with a declarative
3307 -- part (subprogram, block, etc). As such, the item is not allowed
3308 -- to be a part of an encapsulating state because the item is not
3309 -- visible.
3310
3311 if Placement = Not_In_Package then
3312 SPARK_Msg_N
3313 ("indicator Part_Of cannot appear in this context "
3314 & "(SPARK RM 7.2.6(5))", Indic);
3315
3316 Error_Msg_Name_1 := Chars (Scope (Encap_Id));
3317 SPARK_Msg_NE
3318 ("\& is not part of the hidden state of package %",
3319 Indic, Item_Id);
3320 return;
3321
3322 -- The item appears in the visible state space of some package. In
3323 -- general this scenario does not warrant Part_Of except when the
3324 -- package is a nongeneric private child unit and the encapsulating
3325 -- state is declared in a parent unit or a public descendant of that
3326 -- parent unit.
3327
3328 elsif Placement = Visible_State_Space then
3329 if Is_Child_Unit (Pack_Id)
3330 and then not Is_Generic_Unit (Pack_Id)
3331 and then Is_Private_Descendant (Pack_Id)
3332 then
3333 -- A variable or state abstraction which is part of the visible
3334 -- state of a nongeneric private child unit or its public
3335 -- descendants must have its Part_Of indicator specified. The
3336 -- Part_Of indicator must denote a state declared by either the
3337 -- parent unit of the private unit or by a public descendant of
3338 -- that parent unit.
3339
3340 -- Find the nearest private ancestor (which can be the current
3341 -- unit itself).
3342
3343 Parent_Unit := Pack_Id;
3344 while Present (Parent_Unit) loop
3345 exit when
3346 Private_Present
3347 (Parent (Unit_Declaration_Node (Parent_Unit)));
3348 Parent_Unit := Scope (Parent_Unit);
3349 end loop;
3350
3351 Parent_Unit := Scope (Parent_Unit);
3352
3353 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
3354 SPARK_Msg_NE
3355 ("indicator Part_Of must denote abstract state of & or of "
3356 & "its public descendant (SPARK RM 7.2.6(3))",
3357 Indic, Parent_Unit);
3358 return;
3359
3360 elsif Scope (Encap_Id) = Parent_Unit
3361 or else
3362 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id))
3363 and then not Is_Private_Descendant (Scope (Encap_Id)))
3364 then
3365 null;
3366
3367 else
3368 SPARK_Msg_NE
3369 ("indicator Part_Of must denote abstract state of & or of "
3370 & "its public descendant (SPARK RM 7.2.6(3))",
3371 Indic, Parent_Unit);
3372 return;
3373 end if;
3374
3375 -- Indicator Part_Of is not needed when the related package is
3376 -- not a nongeneric private child unit or a public descendant
3377 -- thereof.
3378
3379 else
3380 SPARK_Msg_N
3381 ("indicator Part_Of cannot appear in this context "
3382 & "(SPARK RM 7.2.6(5))", Indic);
3383
3384 Error_Msg_Name_1 := Chars (Pack_Id);
3385 SPARK_Msg_NE
3386 ("\& is declared in the visible part of package %",
3387 Indic, Item_Id);
3388 return;
3389 end if;
3390
3391 -- When the item appears in the private state space of a package, the
3392 -- encapsulating state must be declared in the same package.
3393
3394 elsif Placement = Private_State_Space then
3395 if Scope (Encap_Id) /= Pack_Id then
3396 SPARK_Msg_NE
3397 ("indicator Part_Of must denote an abstract state of "
3398 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3399
3400 Error_Msg_Name_1 := Chars (Pack_Id);
3401 SPARK_Msg_NE
3402 ("\& is declared in the private part of package %",
3403 Indic, Item_Id);
3404 return;
3405 end if;
3406
3407 -- Items declared in the body state space of a package do not need
3408 -- Part_Of indicators as the refinement has already been seen.
3409
3410 else
3411 SPARK_Msg_N
3412 ("indicator Part_Of cannot appear in this context "
3413 & "(SPARK RM 7.2.6(5))", Indic);
3414
3415 if Scope (Encap_Id) = Pack_Id then
3416 Error_Msg_Name_1 := Chars (Pack_Id);
3417 SPARK_Msg_NE
3418 ("\& is declared in the body of package %", Indic, Item_Id);
3419 end if;
3420
3421 return;
3422 end if;
3423
3424 -- At this point it is known that the Part_Of indicator is legal
3425
3426 Legal := True;
3427 end Check_Part_Of_Abstract_State;
3428
3429 -----------------------------------
3430 -- Check_Part_Of_Concurrent_Type --
3431 -----------------------------------
3432
3433 procedure Check_Part_Of_Concurrent_Type is
3434 function In_Proper_Order
3435 (First : Node_Id;
3436 Second : Node_Id) return Boolean;
3437 pragma Inline (In_Proper_Order);
3438 -- Determine whether node First precedes node Second
3439
3440 procedure Placement_Error;
3441 pragma Inline (Placement_Error);
3442 -- Emit an error concerning the illegal placement of the item with
3443 -- respect to the single concurrent type.
3444
3445 ---------------------
3446 -- In_Proper_Order --
3447 ---------------------
3448
3449 function In_Proper_Order
3450 (First : Node_Id;
3451 Second : Node_Id) return Boolean
3452 is
3453 N : Node_Id;
3454
3455 begin
3456 if List_Containing (First) = List_Containing (Second) then
3457 N := First;
3458 while Present (N) loop
3459 if N = Second then
3460 return True;
3461 end if;
3462
3463 Next (N);
3464 end loop;
3465 end if;
3466
3467 return False;
3468 end In_Proper_Order;
3469
3470 ---------------------
3471 -- Placement_Error --
3472 ---------------------
3473
3474 procedure Placement_Error is
3475 begin
3476 SPARK_Msg_N
3477 ("indicator Part_Of must denote a previously declared single "
3478 & "protected type or single task type", Encap);
3479 end Placement_Error;
3480
3481 -- Local variables
3482
3483 Conc_Typ : constant Entity_Id := Etype (Encap_Id);
3484 Encap_Decl : constant Node_Id := Declaration_Node (Encap_Id);
3485 Encap_Context : constant Node_Id := Parent (Encap_Decl);
3486
3487 Item_Context : Node_Id;
3488 Item_Decl : Node_Id;
3489 Prv_Decls : List_Id;
3490 Vis_Decls : List_Id;
3491
3492 -- Start of processing for Check_Part_Of_Concurrent_Type
3493
3494 begin
3495 -- Only abstract states and variables can act as constituents of an
3496 -- encapsulating single concurrent type.
3497
3498 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
3499 null;
3500
3501 -- The constituent is a constant
3502
3503 elsif Ekind (Item_Id) = E_Constant then
3504 Error_Msg_Name_1 := Chars (Encap_Id);
3505 SPARK_Msg_NE
3506 (Fix_Msg (Conc_Typ, "constant & cannot act as constituent of "
3507 & "single protected type %"), Indic, Item_Id);
3508 return;
3509
3510 -- The constituent is a package instantiation
3511
3512 else
3513 Error_Msg_Name_1 := Chars (Encap_Id);
3514 SPARK_Msg_NE
3515 (Fix_Msg (Conc_Typ, "package instantiation & cannot act as "
3516 & "constituent of single protected type %"), Indic, Item_Id);
3517 return;
3518 end if;
3519
3520 -- When the item denotes an abstract state of a nested package, use
3521 -- the declaration of the package to detect proper placement.
3522
3523 -- package Pack is
3524 -- task T;
3525 -- package Nested
3526 -- with Abstract_State => (State with Part_Of => T)
3527
3528 if Ekind (Item_Id) = E_Abstract_State then
3529 Item_Decl := Unit_Declaration_Node (Scope (Item_Id));
3530 else
3531 Item_Decl := Declaration_Node (Item_Id);
3532 end if;
3533
3534 Item_Context := Parent (Item_Decl);
3535
3536 -- The item and the single concurrent type must appear in the same
3537 -- declarative region, with the item following the declaration of
3538 -- the single concurrent type (SPARK RM 9(3)).
3539
3540 if Item_Context = Encap_Context then
3541 if Nkind_In (Item_Context, N_Package_Specification,
3542 N_Protected_Definition,
3543 N_Task_Definition)
3544 then
3545 Prv_Decls := Private_Declarations (Item_Context);
3546 Vis_Decls := Visible_Declarations (Item_Context);
3547
3548 -- The placement is OK when the single concurrent type appears
3549 -- within the visible declarations and the item in the private
3550 -- declarations.
3551 --
3552 -- package Pack is
3553 -- protected PO ...
3554 -- private
3555 -- Constit : ... with Part_Of => PO;
3556 -- end Pack;
3557
3558 if List_Containing (Encap_Decl) = Vis_Decls
3559 and then List_Containing (Item_Decl) = Prv_Decls
3560 then
3561 null;
3562
3563 -- The placement is illegal when the item appears within the
3564 -- visible declarations and the single concurrent type is in
3565 -- the private declarations.
3566 --
3567 -- package Pack is
3568 -- Constit : ... with Part_Of => PO;
3569 -- private
3570 -- protected PO ...
3571 -- end Pack;
3572
3573 elsif List_Containing (Item_Decl) = Vis_Decls
3574 and then List_Containing (Encap_Decl) = Prv_Decls
3575 then
3576 Placement_Error;
3577 return;
3578
3579 -- Otherwise both the item and the single concurrent type are
3580 -- in the same list. Ensure that the declaration of the single
3581 -- concurrent type precedes that of the item.
3582
3583 elsif not In_Proper_Order
3584 (First => Encap_Decl,
3585 Second => Item_Decl)
3586 then
3587 Placement_Error;
3588 return;
3589 end if;
3590
3591 -- Otherwise both the item and the single concurrent type are
3592 -- in the same list. Ensure that the declaration of the single
3593 -- concurrent type precedes that of the item.
3594
3595 elsif not In_Proper_Order
3596 (First => Encap_Decl,
3597 Second => Item_Decl)
3598 then
3599 Placement_Error;
3600 return;
3601 end if;
3602
3603 -- Otherwise the item and the single concurrent type reside within
3604 -- unrelated regions.
3605
3606 else
3607 Error_Msg_Name_1 := Chars (Encap_Id);
3608 SPARK_Msg_NE
3609 (Fix_Msg (Conc_Typ, "constituent & must be declared "
3610 & "immediately within the same region as single protected "
3611 & "type %"), Indic, Item_Id);
3612 return;
3613 end if;
3614
3615 -- At this point it is known that the Part_Of indicator is legal
3616
3617 Legal := True;
3618 end Check_Part_Of_Concurrent_Type;
3619
3620 -- Start of processing for Analyze_Part_Of
3621
3622 begin
3623 -- Assume that the indicator is illegal
3624
3625 Encap_Id := Empty;
3626 Legal := False;
3627
3628 if Nkind_In (Encap, N_Expanded_Name,
3629 N_Identifier,
3630 N_Selected_Component)
3631 then
3632 Analyze (Encap);
3633 Resolve_State (Encap);
3634
3635 Encap_Id := Entity (Encap);
3636
3637 -- The encapsulator is an abstract state
3638
3639 if Ekind (Encap_Id) = E_Abstract_State then
3640 null;
3641
3642 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3643
3644 elsif Is_Single_Concurrent_Object (Encap_Id) then
3645 null;
3646
3647 -- Otherwise the encapsulator is not a legal choice
3648
3649 else
3650 SPARK_Msg_N
3651 ("indicator Part_Of must denote abstract state, single "
3652 & "protected type or single task type", Encap);
3653 return;
3654 end if;
3655
3656 -- This is a syntax error, always report
3657
3658 else
3659 Error_Msg_N
3660 ("indicator Part_Of must denote abstract state, single protected "
3661 & "type or single task type", Encap);
3662 return;
3663 end if;
3664
3665 -- Catch a case where indicator Part_Of denotes the abstract view of a
3666 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3667
3668 if From_Limited_With (Encap_Id)
3669 and then Present (Non_Limited_View (Encap_Id))
3670 and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable
3671 then
3672 SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap);
3673 SPARK_Msg_N ("\& denotes abstract view of object", Encap);
3674 return;
3675 end if;
3676
3677 -- The encapsulator is an abstract state
3678
3679 if Ekind (Encap_Id) = E_Abstract_State then
3680 Check_Part_Of_Abstract_State;
3681
3682 -- The encapsulator is a single concurrent type
3683
3684 else
3685 Check_Part_Of_Concurrent_Type;
3686 end if;
3687 end Analyze_Part_Of;
3688
3689 ----------------------------------
3690 -- Analyze_Part_Of_In_Decl_Part --
3691 ----------------------------------
3692
3693 procedure Analyze_Part_Of_In_Decl_Part
3694 (N : Node_Id;
3695 Freeze_Id : Entity_Id := Empty)
3696 is
3697 Encap : constant Node_Id :=
3698 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
3699 Errors : constant Nat := Serious_Errors_Detected;
3700 Var_Decl : constant Node_Id := Find_Related_Context (N);
3701 Var_Id : constant Entity_Id := Defining_Entity (Var_Decl);
3702 Constits : Elist_Id;
3703 Encap_Id : Entity_Id;
3704 Legal : Boolean;
3705
3706 begin
3707 -- Detect any discrepancies between the placement of the variable with
3708 -- respect to general state space and the encapsulating state or single
3709 -- concurrent type.
3710
3711 Analyze_Part_Of
3712 (Indic => N,
3713 Item_Id => Var_Id,
3714 Encap => Encap,
3715 Encap_Id => Encap_Id,
3716 Legal => Legal);
3717
3718 -- The Part_Of indicator turns the variable into a constituent of the
3719 -- encapsulating state or single concurrent type.
3720
3721 if Legal then
3722 pragma Assert (Present (Encap_Id));
3723 Constits := Part_Of_Constituents (Encap_Id);
3724
3725 if No (Constits) then
3726 Constits := New_Elmt_List;
3727 Set_Part_Of_Constituents (Encap_Id, Constits);
3728 end if;
3729
3730 Append_Elmt (Var_Id, Constits);
3731 Set_Encapsulating_State (Var_Id, Encap_Id);
3732
3733 -- A Part_Of constituent partially refines an abstract state. This
3734 -- property does not apply to protected or task units.
3735
3736 if Ekind (Encap_Id) = E_Abstract_State then
3737 Set_Has_Partial_Visible_Refinement (Encap_Id);
3738 end if;
3739 end if;
3740
3741 -- Emit a clarification message when the encapsulator is undefined,
3742 -- possibly due to contract freezing.
3743
3744 if Errors /= Serious_Errors_Detected
3745 and then Present (Freeze_Id)
3746 and then Has_Undefined_Reference (Encap)
3747 then
3748 Contract_Freeze_Error (Var_Id, Freeze_Id);
3749 end if;
3750 end Analyze_Part_Of_In_Decl_Part;
3751
3752 --------------------
3753 -- Analyze_Pragma --
3754 --------------------
3755
3756 procedure Analyze_Pragma (N : Node_Id) is
3757 Loc : constant Source_Ptr := Sloc (N);
3758
3759 Pname : Name_Id := Pragma_Name (N);
3760 -- Name of the source pragma, or name of the corresponding aspect for
3761 -- pragmas which originate in a source aspect. In the latter case, the
3762 -- name may be different from the pragma name.
3763
3764 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
3765
3766 Pragma_Exit : exception;
3767 -- This exception is used to exit pragma processing completely. It
3768 -- is used when an error is detected, and no further processing is
3769 -- required. It is also used if an earlier error has left the tree in
3770 -- a state where the pragma should not be processed.
3771
3772 Arg_Count : Nat;
3773 -- Number of pragma argument associations
3774
3775 Arg1 : Node_Id;
3776 Arg2 : Node_Id;
3777 Arg3 : Node_Id;
3778 Arg4 : Node_Id;
3779 -- First four pragma arguments (pragma argument association nodes, or
3780 -- Empty if the corresponding argument does not exist).
3781
3782 type Name_List is array (Natural range <>) of Name_Id;
3783 type Args_List is array (Natural range <>) of Node_Id;
3784 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3785
3786 -----------------------
3787 -- Local Subprograms --
3788 -----------------------
3789
3790 procedure Ada_2005_Pragma;
3791 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3792 -- Ada 95 mode, these are implementation defined pragmas, so should be
3793 -- caught by the No_Implementation_Pragmas restriction.
3794
3795 procedure Ada_2012_Pragma;
3796 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3797 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3798 -- should be caught by the No_Implementation_Pragmas restriction.
3799
3800 procedure Analyze_Depends_Global
3801 (Spec_Id : out Entity_Id;
3802 Subp_Decl : out Node_Id;
3803 Legal : out Boolean);
3804 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3805 -- legality of the placement and related context of the pragma. Spec_Id
3806 -- is the entity of the related subprogram. Subp_Decl is the declaration
3807 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3808
3809 procedure Analyze_If_Present (Id : Pragma_Id);
3810 -- Inspect the remainder of the list containing pragma N and look for
3811 -- a pragma that matches Id. If found, analyze the pragma.
3812
3813 procedure Analyze_Pre_Post_Condition;
3814 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3815
3816 procedure Analyze_Refined_Depends_Global_Post
3817 (Spec_Id : out Entity_Id;
3818 Body_Id : out Entity_Id;
3819 Legal : out Boolean);
3820 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3821 -- Refined_Global and Refined_Post. Verify the legality of the placement
3822 -- and related context of the pragma. Spec_Id is the entity of the
3823 -- related subprogram. Body_Id is the entity of the subprogram body.
3824 -- Flag Legal is set when the pragma is legal.
3825
3826 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False);
3827 -- Perform full analysis of pragma Unmodified and the write aspect of
3828 -- pragma Unused. Flag Is_Unused should be set when verifying the
3829 -- semantics of pragma Unused.
3830
3831 procedure Analyze_Unreferenced_Or_Unused (Is_Unused : Boolean := False);
3832 -- Perform full analysis of pragma Unreferenced and the read aspect of
3833 -- pragma Unused. Flag Is_Unused should be set when verifying the
3834 -- semantics of pragma Unused.
3835
3836 procedure Check_Ada_83_Warning;
3837 -- Issues a warning message for the current pragma if operating in Ada
3838 -- 83 mode (used for language pragmas that are not a standard part of
3839 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3840 -- of 95 pragma.
3841
3842 procedure Check_Arg_Count (Required : Nat);
3843 -- Check argument count for pragma is equal to given parameter. If not,
3844 -- then issue an error message and raise Pragma_Exit.
3845
3846 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3847 -- Arg which can either be a pragma argument association, in which case
3848 -- the check is applied to the expression of the association or an
3849 -- expression directly.
3850
3851 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
3852 -- Check that an argument has the right form for an EXTERNAL_NAME
3853 -- parameter of an extended import/export pragma. The rule is that the
3854 -- name must be an identifier or string literal (in Ada 83 mode) or a
3855 -- static string expression (in Ada 95 mode).
3856
3857 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
3858 -- Check the specified argument Arg to make sure that it is an
3859 -- identifier. If not give error and raise Pragma_Exit.
3860
3861 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
3862 -- Check the specified argument Arg to make sure that it is an integer
3863 -- literal. If not give error and raise Pragma_Exit.
3864
3865 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
3866 -- Check the specified argument Arg to make sure that it has the proper
3867 -- syntactic form for a local name and meets the semantic requirements
3868 -- for a local name. The local name is analyzed as part of the
3869 -- processing for this call. In addition, the local name is required
3870 -- to represent an entity at the library level.
3871
3872 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
3873 -- Check the specified argument Arg to make sure that it has the proper
3874 -- syntactic form for a local name and meets the semantic requirements
3875 -- for a local name. The local name is analyzed as part of the
3876 -- processing for this call.
3877
3878 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
3879 -- Check the specified argument Arg to make sure that it is a valid
3880 -- locking policy name. If not give error and raise Pragma_Exit.
3881
3882 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
3883 -- Check the specified argument Arg to make sure that it is a valid
3884 -- elaboration policy name. If not give error and raise Pragma_Exit.
3885
3886 procedure Check_Arg_Is_One_Of
3887 (Arg : Node_Id;
3888 N1, N2 : Name_Id);
3889 procedure Check_Arg_Is_One_Of
3890 (Arg : Node_Id;
3891 N1, N2, N3 : Name_Id);
3892 procedure Check_Arg_Is_One_Of
3893 (Arg : Node_Id;
3894 N1, N2, N3, N4 : Name_Id);
3895 procedure Check_Arg_Is_One_Of
3896 (Arg : Node_Id;
3897 N1, N2, N3, N4, N5 : Name_Id);
3898 -- Check the specified argument Arg to make sure that it is an
3899 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3900 -- present). If not then give error and raise Pragma_Exit.
3901
3902 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
3903 -- Check the specified argument Arg to make sure that it is a valid
3904 -- queuing policy name. If not give error and raise Pragma_Exit.
3905
3906 procedure Check_Arg_Is_OK_Static_Expression
3907 (Arg : Node_Id;
3908 Typ : Entity_Id := Empty);
3909 -- Check the specified argument Arg to make sure that it is a static
3910 -- expression of the given type (i.e. it will be analyzed and resolved
3911 -- using this type, which can be any valid argument to Resolve, e.g.
3912 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3913 -- Typ is left Empty, then any static expression is allowed. Includes
3914 -- checking that the argument does not raise Constraint_Error.
3915
3916 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
3917 -- Check the specified argument Arg to make sure that it is a valid task
3918 -- dispatching policy name. If not give error and raise Pragma_Exit.
3919
3920 procedure Check_Arg_Order (Names : Name_List);
3921 -- Checks for an instance of two arguments with identifiers for the
3922 -- current pragma which are not in the sequence indicated by Names,
3923 -- and if so, generates a fatal message about bad order of arguments.
3924
3925 procedure Check_At_Least_N_Arguments (N : Nat);
3926 -- Check there are at least N arguments present
3927
3928 procedure Check_At_Most_N_Arguments (N : Nat);
3929 -- Check there are no more than N arguments present
3930
3931 procedure Check_Atomic_VFA (E : Entity_Id; VFA : Boolean);
3932 -- Apply legality checks to type or object E subject to an Atomic aspect
3933 -- in Ada 2020 (RM C.6(13)) or to a Volatile_Full_Access aspect.
3934
3935 procedure Check_Component
3936 (Comp : Node_Id;
3937 UU_Typ : Entity_Id;
3938 In_Variant_Part : Boolean := False);
3939 -- Examine an Unchecked_Union component for correct use of per-object
3940 -- constrained subtypes, and for restrictions on finalizable components.
3941 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3942 -- should be set when Comp comes from a record variant.
3943
3944 procedure Check_Duplicate_Pragma (E : Entity_Id);
3945 -- Check if a rep item of the same name as the current pragma is already
3946 -- chained as a rep pragma to the given entity. If so give a message
3947 -- about the duplicate, and then raise Pragma_Exit so does not return.
3948 -- Note that if E is a type, then this routine avoids flagging a pragma
3949 -- which applies to a parent type from which E is derived.
3950
3951 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
3952 -- Nam is an N_String_Literal node containing the external name set by
3953 -- an Import or Export pragma (or extended Import or Export pragma).
3954 -- This procedure checks for possible duplications if this is the export
3955 -- case, and if found, issues an appropriate error message.
3956
3957 procedure Check_Expr_Is_OK_Static_Expression
3958 (Expr : Node_Id;
3959 Typ : Entity_Id := Empty);
3960 -- Check the specified expression Expr to make sure that it is a static
3961 -- expression of the given type (i.e. it will be analyzed and resolved
3962 -- using this type, which can be any valid argument to Resolve, e.g.
3963 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3964 -- Typ is left Empty, then any static expression is allowed. Includes
3965 -- checking that the expression does not raise Constraint_Error.
3966
3967 procedure Check_First_Subtype (Arg : Node_Id);
3968 -- Checks that Arg, whose expression is an entity name, references a
3969 -- first subtype.
3970
3971 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
3972 -- Checks that the given argument has an identifier, and if so, requires
3973 -- it to match the given identifier name. If there is no identifier, or
3974 -- a non-matching identifier, then an error message is given and
3975 -- Pragma_Exit is raised.
3976
3977 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
3978 -- Checks that the given argument has an identifier, and if so, requires
3979 -- it to match one of the given identifier names. If there is no
3980 -- identifier, or a non-matching identifier, then an error message is
3981 -- given and Pragma_Exit is raised.
3982
3983 procedure Check_In_Main_Program;
3984 -- Common checks for pragmas that appear within a main program
3985 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3986
3987 procedure Check_Interrupt_Or_Attach_Handler;
3988 -- Common processing for first argument of pragma Interrupt_Handler or
3989 -- pragma Attach_Handler.
3990
3991 procedure Check_Loop_Pragma_Placement;
3992 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
3993 -- appear immediately within a construct restricted to loops, and that
3994 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
3995
3996 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
3997 -- Check that pragma appears in a declarative part, or in a package
3998 -- specification, i.e. that it does not occur in a statement sequence
3999 -- in a body.
4000
4001 procedure Check_No_Identifier (Arg : Node_Id);
4002 -- Checks that the given argument does not have an identifier. If
4003 -- an identifier is present, then an error message is issued, and
4004 -- Pragma_Exit is raised.
4005
4006 procedure Check_No_Identifiers;
4007 -- Checks that none of the arguments to the pragma has an identifier.
4008 -- If any argument has an identifier, then an error message is issued,
4009 -- and Pragma_Exit is raised.
4010
4011 procedure Check_No_Link_Name;
4012 -- Checks that no link name is specified
4013
4014 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
4015 -- Checks if the given argument has an identifier, and if so, requires
4016 -- it to match the given identifier name. If there is a non-matching
4017 -- identifier, then an error message is given and Pragma_Exit is raised.
4018
4019 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
4020 -- Checks if the given argument has an identifier, and if so, requires
4021 -- it to match the given identifier name. If there is a non-matching
4022 -- identifier, then an error message is given and Pragma_Exit is raised.
4023 -- In this version of the procedure, the identifier name is given as
4024 -- a string with lower case letters.
4025
4026 procedure Check_Static_Boolean_Expression (Expr : Node_Id);
4027 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
4028 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
4029 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
4030 -- is an OK static boolean expression. Emit an error if this is not the
4031 -- case.
4032
4033 procedure Check_Static_Constraint (Constr : Node_Id);
4034 -- Constr is a constraint from an N_Subtype_Indication node from a
4035 -- component constraint in an Unchecked_Union type. This routine checks
4036 -- that the constraint is static as required by the restrictions for
4037 -- Unchecked_Union.
4038
4039 procedure Check_Valid_Configuration_Pragma;
4040 -- Legality checks for placement of a configuration pragma
4041
4042 procedure Check_Valid_Library_Unit_Pragma;
4043 -- Legality checks for library unit pragmas. A special case arises for
4044 -- pragmas in generic instances that come from copies of the original
4045 -- library unit pragmas in the generic templates. In the case of other
4046 -- than library level instantiations these can appear in contexts which
4047 -- would normally be invalid (they only apply to the original template
4048 -- and to library level instantiations), and they are simply ignored,
4049 -- which is implemented by rewriting them as null statements.
4050
4051 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
4052 -- Check an Unchecked_Union variant for lack of nested variants and
4053 -- presence of at least one component. UU_Typ is the related Unchecked_
4054 -- Union type.
4055
4056 procedure Ensure_Aggregate_Form (Arg : Node_Id);
4057 -- Subsidiary routine to the processing of pragmas Abstract_State,
4058 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
4059 -- Refined_Global and Refined_State. Transform argument Arg into
4060 -- an aggregate if not one already. N_Null is never transformed.
4061 -- Arg may denote an aspect specification or a pragma argument
4062 -- association.
4063
4064 procedure Error_Pragma (Msg : String);
4065 pragma No_Return (Error_Pragma);
4066 -- Outputs error message for current pragma. The message contains a %
4067 -- that will be replaced with the pragma name, and the flag is placed
4068 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
4069 -- calls Fix_Error (see spec of that procedure for details).
4070
4071 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
4072 pragma No_Return (Error_Pragma_Arg);
4073 -- Outputs error message for current pragma. The message may contain
4074 -- a % that will be replaced with the pragma name. The parameter Arg
4075 -- may either be a pragma argument association, in which case the flag
4076 -- is placed on the expression of this association, or an expression,
4077 -- in which case the flag is placed directly on the expression. The
4078 -- message is placed using Error_Msg_N, so the message may also contain
4079 -- an & insertion character which will reference the given Arg value.
4080 -- After placing the message, Pragma_Exit is raised. Note: this routine
4081 -- calls Fix_Error (see spec of that procedure for details).
4082
4083 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
4084 pragma No_Return (Error_Pragma_Arg);
4085 -- Similar to above form of Error_Pragma_Arg except that two messages
4086 -- are provided, the second is a continuation comment starting with \.
4087
4088 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
4089 pragma No_Return (Error_Pragma_Arg_Ident);
4090 -- Outputs error message for current pragma. The message may contain a %
4091 -- that will be replaced with the pragma name. The parameter Arg must be
4092 -- a pragma argument association with a non-empty identifier (i.e. its
4093 -- Chars field must be set), and the error message is placed on the
4094 -- identifier. The message is placed using Error_Msg_N so the message
4095 -- may also contain an & insertion character which will reference
4096 -- the identifier. After placing the message, Pragma_Exit is raised.
4097 -- Note: this routine calls Fix_Error (see spec of that procedure for
4098 -- details).
4099
4100 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
4101 pragma No_Return (Error_Pragma_Ref);
4102 -- Outputs error message for current pragma. The message may contain
4103 -- a % that will be replaced with the pragma name. The parameter Ref
4104 -- must be an entity whose name can be referenced by & and sloc by #.
4105 -- After placing the message, Pragma_Exit is raised. Note: this routine
4106 -- calls Fix_Error (see spec of that procedure for details).
4107
4108 function Find_Lib_Unit_Name return Entity_Id;
4109 -- Used for a library unit pragma to find the entity to which the
4110 -- library unit pragma applies, returns the entity found.
4111
4112 procedure Find_Program_Unit_Name (Id : Node_Id);
4113 -- If the pragma is a compilation unit pragma, the id must denote the
4114 -- compilation unit in the same compilation, and the pragma must appear
4115 -- in the list of preceding or trailing pragmas. If it is a program
4116 -- unit pragma that is not a compilation unit pragma, then the
4117 -- identifier must be visible.
4118
4119 function Find_Unique_Parameterless_Procedure
4120 (Name : Entity_Id;
4121 Arg : Node_Id) return Entity_Id;
4122 -- Used for a procedure pragma to find the unique parameterless
4123 -- procedure identified by Name, returns it if it exists, otherwise
4124 -- errors out and uses Arg as the pragma argument for the message.
4125
4126 function Fix_Error (Msg : String) return String;
4127 -- This is called prior to issuing an error message. Msg is the normal
4128 -- error message issued in the pragma case. This routine checks for the
4129 -- case of a pragma coming from an aspect in the source, and returns a
4130 -- message suitable for the aspect case as follows:
4131 --
4132 -- Each substring "pragma" is replaced by "aspect"
4133 --
4134 -- If "argument of" is at the start of the error message text, it is
4135 -- replaced by "entity for".
4136 --
4137 -- If "argument" is at the start of the error message text, it is
4138 -- replaced by "entity".
4139 --
4140 -- So for example, "argument of pragma X must be discrete type"
4141 -- returns "entity for aspect X must be a discrete type".
4142
4143 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
4144 -- be different from the pragma name). If the current pragma results
4145 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
4146 -- original pragma name.
4147
4148 procedure Gather_Associations
4149 (Names : Name_List;
4150 Args : out Args_List);
4151 -- This procedure is used to gather the arguments for a pragma that
4152 -- permits arbitrary ordering of parameters using the normal rules
4153 -- for named and positional parameters. The Names argument is a list
4154 -- of Name_Id values that corresponds to the allowed pragma argument
4155 -- association identifiers in order. The result returned in Args is
4156 -- a list of corresponding expressions that are the pragma arguments.
4157 -- Note that this is a list of expressions, not of pragma argument
4158 -- associations (Gather_Associations has completely checked all the
4159 -- optional identifiers when it returns). An entry in Args is Empty
4160 -- on return if the corresponding argument is not present.
4161
4162 procedure GNAT_Pragma;
4163 -- Called for all GNAT defined pragmas to check the relevant restriction
4164 -- (No_Implementation_Pragmas).
4165
4166 function Is_Before_First_Decl
4167 (Pragma_Node : Node_Id;
4168 Decls : List_Id) return Boolean;
4169 -- Return True if Pragma_Node is before the first declarative item in
4170 -- Decls where Decls is the list of declarative items.
4171
4172 function Is_Configuration_Pragma return Boolean;
4173 -- Determines if the placement of the current pragma is appropriate
4174 -- for a configuration pragma.
4175
4176 function Is_In_Context_Clause return Boolean;
4177 -- Returns True if pragma appears within the context clause of a unit,
4178 -- and False for any other placement (does not generate any messages).
4179
4180 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
4181 -- Analyzes the argument, and determines if it is a static string
4182 -- expression, returns True if so, False if non-static or not String.
4183 -- A special case is that a string literal returns True in Ada 83 mode
4184 -- (which has no such thing as static string expressions). Note that
4185 -- the call analyzes its argument, so this cannot be used for the case
4186 -- where an identifier might not be declared.
4187
4188 procedure Pragma_Misplaced;
4189 pragma No_Return (Pragma_Misplaced);
4190 -- Issue fatal error message for misplaced pragma
4191
4192 procedure Process_Atomic_Independent_Shared_Volatile;
4193 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
4194 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
4195 -- and treated as being identical in effect to pragma Atomic.
4196
4197 procedure Process_Compile_Time_Warning_Or_Error;
4198 -- Common processing for Compile_Time_Error and Compile_Time_Warning
4199
4200 procedure Process_Convention
4201 (C : out Convention_Id;
4202 Ent : out Entity_Id);
4203 -- Common processing for Convention, Interface, Import and Export.
4204 -- Checks first two arguments of pragma, and sets the appropriate
4205 -- convention value in the specified entity or entities. On return
4206 -- C is the convention, Ent is the referenced entity.
4207
4208 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
4209 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
4210 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
4211
4212 procedure Process_Extended_Import_Export_Object_Pragma
4213 (Arg_Internal : Node_Id;
4214 Arg_External : Node_Id;
4215 Arg_Size : Node_Id);
4216 -- Common processing for the pragmas Import/Export_Object. The three
4217 -- arguments correspond to the three named parameters of the pragmas. An
4218 -- argument is empty if the corresponding parameter is not present in
4219 -- the pragma.
4220
4221 procedure Process_Extended_Import_Export_Internal_Arg
4222 (Arg_Internal : Node_Id := Empty);
4223 -- Common processing for all extended Import and Export pragmas. The
4224 -- argument is the pragma parameter for the Internal argument. If
4225 -- Arg_Internal is empty or inappropriate, an error message is posted.
4226 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
4227 -- set to identify the referenced entity.
4228
4229 procedure Process_Extended_Import_Export_Subprogram_Pragma
4230 (Arg_Internal : Node_Id;
4231 Arg_External : Node_Id;
4232 Arg_Parameter_Types : Node_Id;
4233 Arg_Result_Type : Node_Id := Empty;
4234 Arg_Mechanism : Node_Id;
4235 Arg_Result_Mechanism : Node_Id := Empty);
4236 -- Common processing for all extended Import and Export pragmas applying
4237 -- to subprograms. The caller omits any arguments that do not apply to
4238 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
4239 -- only in the Import_Function and Export_Function cases). The argument
4240 -- names correspond to the allowed pragma association identifiers.
4241
4242 procedure Process_Generic_List;
4243 -- Common processing for Share_Generic and Inline_Generic
4244
4245 procedure Process_Import_Or_Interface;
4246 -- Common processing for Import or Interface
4247
4248 procedure Process_Import_Predefined_Type;
4249 -- Processing for completing a type with pragma Import. This is used
4250 -- to declare types that match predefined C types, especially for cases
4251 -- without corresponding Ada predefined type.
4252
4253 type Inline_Status is (Suppressed, Disabled, Enabled);
4254 -- Inline status of a subprogram, indicated as follows:
4255 -- Suppressed: inlining is suppressed for the subprogram
4256 -- Disabled: no inlining is requested for the subprogram
4257 -- Enabled: inlining is requested/required for the subprogram
4258
4259 procedure Process_Inline (Status : Inline_Status);
4260 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
4261 -- indicates the inline status specified by the pragma.
4262
4263 procedure Process_Interface_Name
4264 (Subprogram_Def : Entity_Id;
4265 Ext_Arg : Node_Id;
4266 Link_Arg : Node_Id;
4267 Prag : Node_Id);
4268 -- Given the last two arguments of pragma Import, pragma Export, or
4269 -- pragma Interface_Name, performs validity checks and sets the
4270 -- Interface_Name field of the given subprogram entity to the
4271 -- appropriate external or link name, depending on the arguments given.
4272 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
4273 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
4274 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
4275 -- nor Link_Arg is present, the interface name is set to the default
4276 -- from the subprogram name. In addition, the pragma itself is passed
4277 -- to analyze any expressions in the case the pragma came from an aspect
4278 -- specification.
4279
4280 procedure Process_Interrupt_Or_Attach_Handler;
4281 -- Common processing for Interrupt and Attach_Handler pragmas
4282
4283 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
4284 -- Common processing for Restrictions and Restriction_Warnings pragmas.
4285 -- Warn is True for Restriction_Warnings, or for Restrictions if the
4286 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
4287 -- is not set in the Restrictions case.
4288
4289 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
4290 -- Common processing for Suppress and Unsuppress. The boolean parameter
4291 -- Suppress_Case is True for the Suppress case, and False for the
4292 -- Unsuppress case.
4293
4294 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
4295 -- Subsidiary to the analysis of pragmas Independent[_Components].
4296 -- Record such a pragma N applied to entity E for future checks.
4297
4298 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
4299 -- This procedure sets the Is_Exported flag for the given entity,
4300 -- checking that the entity was not previously imported. Arg is
4301 -- the argument that specified the entity. A check is also made
4302 -- for exporting inappropriate entities.
4303
4304 procedure Set_Extended_Import_Export_External_Name
4305 (Internal_Ent : Entity_Id;
4306 Arg_External : Node_Id);
4307 -- Common processing for all extended import export pragmas. The first
4308 -- argument, Internal_Ent, is the internal entity, which has already
4309 -- been checked for validity by the caller. Arg_External is from the
4310 -- Import or Export pragma, and may be null if no External parameter
4311 -- was present. If Arg_External is present and is a non-null string
4312 -- (a null string is treated as the default), then the Interface_Name
4313 -- field of Internal_Ent is set appropriately.
4314
4315 procedure Set_Imported (E : Entity_Id);
4316 -- This procedure sets the Is_Imported flag for the given entity,
4317 -- checking that it is not previously exported or imported.
4318
4319 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
4320 -- Mech is a parameter passing mechanism (see Import_Function syntax
4321 -- for MECHANISM_NAME). This routine checks that the mechanism argument
4322 -- has the right form, and if not issues an error message. If the
4323 -- argument has the right form then the Mechanism field of Ent is
4324 -- set appropriately.
4325
4326 procedure Set_Rational_Profile;
4327 -- Activate the set of configuration pragmas and permissions that make
4328 -- up the Rational profile.
4329
4330 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id);
4331 -- Activate the set of configuration pragmas and restrictions that make
4332 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
4333 -- GNAT_Ravenscar_EDF, or Ravenscar. N is the corresponding pragma node,
4334 -- which is used for error messages on any constructs violating the
4335 -- profile.
4336
4337 ---------------------
4338 -- Ada_2005_Pragma --
4339 ---------------------
4340
4341 procedure Ada_2005_Pragma is
4342 begin
4343 if Ada_Version <= Ada_95 then
4344 Check_Restriction (No_Implementation_Pragmas, N);
4345 end if;
4346 end Ada_2005_Pragma;
4347
4348 ---------------------
4349 -- Ada_2012_Pragma --
4350 ---------------------
4351
4352 procedure Ada_2012_Pragma is
4353 begin
4354 if Ada_Version <= Ada_2005 then
4355 Check_Restriction (No_Implementation_Pragmas, N);
4356 end if;
4357 end Ada_2012_Pragma;
4358
4359 ----------------------------
4360 -- Analyze_Depends_Global --
4361 ----------------------------
4362
4363 procedure Analyze_Depends_Global
4364 (Spec_Id : out Entity_Id;
4365 Subp_Decl : out Node_Id;
4366 Legal : out Boolean)
4367 is
4368 begin
4369 -- Assume that the pragma is illegal
4370
4371 Spec_Id := Empty;
4372 Subp_Decl := Empty;
4373 Legal := False;
4374
4375 GNAT_Pragma;
4376 Check_Arg_Count (1);
4377
4378 -- Ensure the proper placement of the pragma. Depends/Global must be
4379 -- associated with a subprogram declaration or a body that acts as a
4380 -- spec.
4381
4382 Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4383
4384 -- Entry
4385
4386 if Nkind (Subp_Decl) = N_Entry_Declaration then
4387 null;
4388
4389 -- Generic subprogram
4390
4391 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4392 null;
4393
4394 -- Object declaration of a single concurrent type
4395
4396 elsif Nkind (Subp_Decl) = N_Object_Declaration
4397 and then Is_Single_Concurrent_Object
4398 (Unique_Defining_Entity (Subp_Decl))
4399 then
4400 null;
4401
4402 -- Single task type
4403
4404 elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then
4405 null;
4406
4407 -- Subprogram body acts as spec
4408
4409 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4410 and then No (Corresponding_Spec (Subp_Decl))
4411 then
4412 null;
4413
4414 -- Subprogram body stub acts as spec
4415
4416 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4417 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
4418 then
4419 null;
4420
4421 -- Subprogram declaration
4422
4423 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4424 null;
4425
4426 -- Task type
4427
4428 elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then
4429 null;
4430
4431 else
4432 Pragma_Misplaced;
4433 return;
4434 end if;
4435
4436 -- If we get here, then the pragma is legal
4437
4438 Legal := True;
4439 Spec_Id := Unique_Defining_Entity (Subp_Decl);
4440
4441 -- When the related context is an entry, the entry must belong to a
4442 -- protected unit (SPARK RM 6.1.4(6)).
4443
4444 if Is_Entry_Declaration (Spec_Id)
4445 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
4446 then
4447 Pragma_Misplaced;
4448 return;
4449
4450 -- When the related context is an anonymous object created for a
4451 -- simple concurrent type, the type must be a task
4452 -- (SPARK RM 6.1.4(6)).
4453
4454 elsif Is_Single_Concurrent_Object (Spec_Id)
4455 and then Ekind (Etype (Spec_Id)) /= E_Task_Type
4456 then
4457 Pragma_Misplaced;
4458 return;
4459 end if;
4460
4461 -- A pragma that applies to a Ghost entity becomes Ghost for the
4462 -- purposes of legality checks and removal of ignored Ghost code.
4463
4464 Mark_Ghost_Pragma (N, Spec_Id);
4465 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4466 end Analyze_Depends_Global;
4467
4468 ------------------------
4469 -- Analyze_If_Present --
4470 ------------------------
4471
4472 procedure Analyze_If_Present (Id : Pragma_Id) is
4473 Stmt : Node_Id;
4474
4475 begin
4476 pragma Assert (Is_List_Member (N));
4477
4478 -- Inspect the declarations or statements following pragma N looking
4479 -- for another pragma whose Id matches the caller's request. If it is
4480 -- available, analyze it.
4481
4482 Stmt := Next (N);
4483 while Present (Stmt) loop
4484 if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then
4485 Analyze_Pragma (Stmt);
4486 exit;
4487
4488 -- The first source declaration or statement immediately following
4489 -- N ends the region where a pragma may appear.
4490
4491 elsif Comes_From_Source (Stmt) then
4492 exit;
4493 end if;
4494
4495 Next (Stmt);
4496 end loop;
4497 end Analyze_If_Present;
4498
4499 --------------------------------
4500 -- Analyze_Pre_Post_Condition --
4501 --------------------------------
4502
4503 procedure Analyze_Pre_Post_Condition is
4504 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
4505 Subp_Decl : Node_Id;
4506 Subp_Id : Entity_Id;
4507
4508 Duplicates_OK : Boolean := False;
4509 -- Flag set when a pre/postcondition allows multiple pragmas of the
4510 -- same kind.
4511
4512 In_Body_OK : Boolean := False;
4513 -- Flag set when a pre/postcondition is allowed to appear on a body
4514 -- even though the subprogram may have a spec.
4515
4516 Is_Pre_Post : Boolean := False;
4517 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4518 -- Post_Class.
4519
4520 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean;
4521 -- Implement rules in AI12-0131: an overriding operation can have
4522 -- a class-wide precondition only if one of its ancestors has an
4523 -- explicit class-wide precondition.
4524
4525 -----------------------------
4526 -- Inherits_Class_Wide_Pre --
4527 -----------------------------
4528
4529 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean is
4530 Typ : constant Entity_Id := Find_Dispatching_Type (E);
4531 Cont : Node_Id;
4532 Prag : Node_Id;
4533 Prev : Entity_Id := Overridden_Operation (E);
4534
4535 begin
4536 -- Check ancestors on the overriding operation to examine the
4537 -- preconditions that may apply to them.
4538
4539 while Present (Prev) loop
4540 Cont := Contract (Prev);
4541 if Present (Cont) then
4542 Prag := Pre_Post_Conditions (Cont);
4543 while Present (Prag) loop
4544 if Pragma_Name (Prag) = Name_Precondition
4545 and then Class_Present (Prag)
4546 then
4547 return True;
4548 end if;
4549
4550 Prag := Next_Pragma (Prag);
4551 end loop;
4552 end if;
4553
4554 -- For a type derived from a generic formal type, the operation
4555 -- inheriting the condition is a renaming, not an overriding of
4556 -- the operation of the formal. Ditto for an inherited
4557 -- operation which has no explicit contracts.
4558
4559 if Is_Generic_Type (Find_Dispatching_Type (Prev))
4560 or else not Comes_From_Source (Prev)
4561 then
4562 Prev := Alias (Prev);
4563 else
4564 Prev := Overridden_Operation (Prev);
4565 end if;
4566 end loop;
4567
4568 -- If the controlling type of the subprogram has progenitors, an
4569 -- interface operation implemented by the current operation may
4570 -- have a class-wide precondition.
4571
4572 if Has_Interfaces (Typ) then
4573 declare
4574 Elmt : Elmt_Id;
4575 Ints : Elist_Id;
4576 Prim : Entity_Id;
4577 Prim_Elmt : Elmt_Id;
4578 Prim_List : Elist_Id;
4579
4580 begin
4581 Collect_Interfaces (Typ, Ints);
4582 Elmt := First_Elmt (Ints);
4583
4584 -- Iterate over the primitive operations of each interface
4585
4586 while Present (Elmt) loop
4587 Prim_List := Direct_Primitive_Operations (Node (Elmt));
4588 Prim_Elmt := First_Elmt (Prim_List);
4589 while Present (Prim_Elmt) loop
4590 Prim := Node (Prim_Elmt);
4591 if Chars (Prim) = Chars (E)
4592 and then Present (Contract (Prim))
4593 and then Class_Present
4594 (Pre_Post_Conditions (Contract (Prim)))
4595 then
4596 return True;
4597 end if;
4598
4599 Next_Elmt (Prim_Elmt);
4600 end loop;
4601
4602 Next_Elmt (Elmt);
4603 end loop;
4604 end;
4605 end if;
4606
4607 return False;
4608 end Inherits_Class_Wide_Pre;
4609
4610 -- Start of processing for Analyze_Pre_Post_Condition
4611
4612 begin
4613 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4614 -- offer uniformity among the various kinds of pre/postconditions by
4615 -- rewriting the pragma identifier. This allows the retrieval of the
4616 -- original pragma name by routine Original_Aspect_Pragma_Name.
4617
4618 if Comes_From_Source (N) then
4619 if Nam_In (Pname, Name_Pre, Name_Pre_Class) then
4620 Is_Pre_Post := True;
4621 Set_Class_Present (N, Pname = Name_Pre_Class);
4622 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
4623
4624 elsif Nam_In (Pname, Name_Post, Name_Post_Class) then
4625 Is_Pre_Post := True;
4626 Set_Class_Present (N, Pname = Name_Post_Class);
4627 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
4628 end if;
4629 end if;
4630
4631 -- Determine the semantics with respect to duplicates and placement
4632 -- in a body. Pragmas Precondition and Postcondition were introduced
4633 -- before aspects and are not subject to the same aspect-like rules.
4634
4635 if Nam_In (Pname, Name_Precondition, Name_Postcondition) then
4636 Duplicates_OK := True;
4637 In_Body_OK := True;
4638 end if;
4639
4640 GNAT_Pragma;
4641
4642 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4643 -- argument without an identifier.
4644
4645 if Is_Pre_Post then
4646 Check_Arg_Count (1);
4647 Check_No_Identifiers;
4648
4649 -- Pragmas Precondition and Postcondition have complex argument
4650 -- profile.
4651
4652 else
4653 Check_At_Least_N_Arguments (1);
4654 Check_At_Most_N_Arguments (2);
4655 Check_Optional_Identifier (Arg1, Name_Check);
4656
4657 if Present (Arg2) then
4658 Check_Optional_Identifier (Arg2, Name_Message);
4659 Preanalyze_Spec_Expression
4660 (Get_Pragma_Arg (Arg2), Standard_String);
4661 end if;
4662 end if;
4663
4664 -- For a pragma PPC in the extended main source unit, record enabled
4665 -- status in SCO.
4666 -- ??? nothing checks that the pragma is in the main source unit
4667
4668 if Is_Checked (N) and then not Split_PPC (N) then
4669 Set_SCO_Pragma_Enabled (Loc);
4670 end if;
4671
4672 -- Ensure the proper placement of the pragma
4673
4674 Subp_Decl :=
4675 Find_Related_Declaration_Or_Body
4676 (N, Do_Checks => not Duplicates_OK);
4677
4678 -- When a pre/postcondition pragma applies to an abstract subprogram,
4679 -- its original form must be an aspect with 'Class.
4680
4681 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4682 if not From_Aspect_Specification (N) then
4683 Error_Pragma
4684 ("pragma % cannot be applied to abstract subprogram");
4685
4686 elsif not Class_Present (N) then
4687 Error_Pragma
4688 ("aspect % requires ''Class for abstract subprogram");
4689 end if;
4690
4691 -- Entry declaration
4692
4693 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
4694 null;
4695
4696 -- Generic subprogram declaration
4697
4698 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4699 null;
4700
4701 -- Subprogram body
4702
4703 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4704 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
4705 then
4706 null;
4707
4708 -- Subprogram body stub
4709
4710 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4711 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
4712 then
4713 null;
4714
4715 -- Subprogram declaration
4716
4717 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4718
4719 -- AI05-0230: When a pre/postcondition pragma applies to a null
4720 -- procedure, its original form must be an aspect with 'Class.
4721
4722 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4723 and then Null_Present (Specification (Subp_Decl))
4724 and then From_Aspect_Specification (N)
4725 and then not Class_Present (N)
4726 then
4727 Error_Pragma ("aspect % requires ''Class for null procedure");
4728 end if;
4729
4730 -- Implement the legality checks mandated by AI12-0131:
4731 -- Pre'Class shall not be specified for an overriding primitive
4732 -- subprogram of a tagged type T unless the Pre'Class aspect is
4733 -- specified for the corresponding primitive subprogram of some
4734 -- ancestor of T.
4735
4736 declare
4737 E : constant Entity_Id := Defining_Entity (Subp_Decl);
4738
4739 begin
4740 if Class_Present (N)
4741 and then Pragma_Name (N) = Name_Precondition
4742 and then Present (Overridden_Operation (E))
4743 and then not Inherits_Class_Wide_Pre (E)
4744 then
4745 Error_Msg_N
4746 ("illegal class-wide precondition on overriding operation",
4747 Corresponding_Aspect (N));
4748 end if;
4749 end;
4750
4751 -- A renaming declaration may inherit a generated pragma, its
4752 -- placement comes from expansion, not from source.
4753
4754 elsif Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
4755 and then not Comes_From_Source (N)
4756 then
4757 null;
4758
4759 -- For Ada 2020, pre/postconditions can appear on formal subprograms
4760
4761 elsif Nkind (Subp_Decl) = N_Formal_Concrete_Subprogram_Declaration
4762 and then Ada_Version >= Ada_2020
4763 then
4764 null;
4765
4766 -- Otherwise the placement is illegal
4767
4768 else
4769 Pragma_Misplaced;
4770 return;
4771 end if;
4772
4773 Subp_Id := Defining_Entity (Subp_Decl);
4774
4775 -- A pragma that applies to a Ghost entity becomes Ghost for the
4776 -- purposes of legality checks and removal of ignored Ghost code.
4777
4778 Mark_Ghost_Pragma (N, Subp_Id);
4779
4780 -- Chain the pragma on the contract for further processing by
4781 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4782
4783 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
4784
4785 -- Fully analyze the pragma when it appears inside an entry or
4786 -- subprogram body because it cannot benefit from forward references.
4787
4788 if Nkind_In (Subp_Decl, N_Entry_Body,
4789 N_Subprogram_Body,
4790 N_Subprogram_Body_Stub)
4791 then
4792 -- The legality checks of pragmas Precondition and Postcondition
4793 -- are affected by the SPARK mode in effect and the volatility of
4794 -- the context. Analyze all pragmas in a specific order.
4795
4796 Analyze_If_Present (Pragma_SPARK_Mode);
4797 Analyze_If_Present (Pragma_Volatile_Function);
4798 Analyze_Pre_Post_Condition_In_Decl_Part (N);
4799 end if;
4800 end Analyze_Pre_Post_Condition;
4801
4802 -----------------------------------------
4803 -- Analyze_Refined_Depends_Global_Post --
4804 -----------------------------------------
4805
4806 procedure Analyze_Refined_Depends_Global_Post
4807 (Spec_Id : out Entity_Id;
4808 Body_Id : out Entity_Id;
4809 Legal : out Boolean)
4810 is
4811 Body_Decl : Node_Id;
4812 Spec_Decl : Node_Id;
4813
4814 begin
4815 -- Assume that the pragma is illegal
4816
4817 Spec_Id := Empty;
4818 Body_Id := Empty;
4819 Legal := False;
4820
4821 GNAT_Pragma;
4822 Check_Arg_Count (1);
4823 Check_No_Identifiers;
4824
4825 -- Verify the placement of the pragma and check for duplicates. The
4826 -- pragma must apply to a subprogram body [stub].
4827
4828 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4829
4830 if not Nkind_In (Body_Decl, N_Entry_Body,
4831 N_Subprogram_Body,
4832 N_Subprogram_Body_Stub,
4833 N_Task_Body,
4834 N_Task_Body_Stub)
4835 then
4836 Pragma_Misplaced;
4837 return;
4838 end if;
4839
4840 Body_Id := Defining_Entity (Body_Decl);
4841 Spec_Id := Unique_Defining_Entity (Body_Decl);
4842
4843 -- The pragma must apply to the second declaration of a subprogram.
4844 -- In other words, the body [stub] cannot acts as a spec.
4845
4846 if No (Spec_Id) then
4847 Error_Pragma ("pragma % cannot apply to a stand alone body");
4848 return;
4849
4850 -- Catch the case where the subprogram body is a subunit and acts as
4851 -- the third declaration of the subprogram.
4852
4853 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
4854 Error_Pragma ("pragma % cannot apply to a subunit");
4855 return;
4856 end if;
4857
4858 -- A refined pragma can only apply to the body [stub] of a subprogram
4859 -- declared in the visible part of a package. Retrieve the context of
4860 -- the subprogram declaration.
4861
4862 Spec_Decl := Unit_Declaration_Node (Spec_Id);
4863
4864 -- When dealing with protected entries or protected subprograms, use
4865 -- the enclosing protected type as the proper context.
4866
4867 if Ekind_In (Spec_Id, E_Entry,
4868 E_Entry_Family,
4869 E_Function,
4870 E_Procedure)
4871 and then Ekind (Scope (Spec_Id)) = E_Protected_Type
4872 then
4873 Spec_Decl := Declaration_Node (Scope (Spec_Id));
4874 end if;
4875
4876 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
4877 Error_Pragma
4878 (Fix_Msg (Spec_Id, "pragma % must apply to the body of "
4879 & "subprogram declared in a package specification"));
4880 return;
4881 end if;
4882
4883 -- If we get here, then the pragma is legal
4884
4885 Legal := True;
4886
4887 -- A pragma that applies to a Ghost entity becomes Ghost for the
4888 -- purposes of legality checks and removal of ignored Ghost code.
4889
4890 Mark_Ghost_Pragma (N, Spec_Id);
4891
4892 if Nam_In (Pname, Name_Refined_Depends, Name_Refined_Global) then
4893 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4894 end if;
4895 end Analyze_Refined_Depends_Global_Post;
4896
4897 ----------------------------------
4898 -- Analyze_Unmodified_Or_Unused --
4899 ----------------------------------
4900
4901 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False) is
4902 Arg : Node_Id;
4903 Arg_Expr : Node_Id;
4904 Arg_Id : Entity_Id;
4905
4906 Ghost_Error_Posted : Boolean := False;
4907 -- Flag set when an error concerning the illegal mix of Ghost and
4908 -- non-Ghost variables is emitted.
4909
4910 Ghost_Id : Entity_Id := Empty;
4911 -- The entity of the first Ghost variable encountered while
4912 -- processing the arguments of the pragma.
4913
4914 begin
4915 GNAT_Pragma;
4916 Check_At_Least_N_Arguments (1);
4917
4918 -- Loop through arguments
4919
4920 Arg := Arg1;
4921 while Present (Arg) loop
4922 Check_No_Identifier (Arg);
4923
4924 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4925 -- in fact generate reference, so that the entity will have a
4926 -- reference, which will inhibit any warnings about it not
4927 -- being referenced, and also properly show up in the ali file
4928 -- as a reference. But this reference is recorded before the
4929 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4930 -- generated for this reference.
4931
4932 Check_Arg_Is_Local_Name (Arg);
4933 Arg_Expr := Get_Pragma_Arg (Arg);
4934
4935 if Is_Entity_Name (Arg_Expr) then
4936 Arg_Id := Entity (Arg_Expr);
4937
4938 -- Skip processing the argument if already flagged
4939
4940 if Is_Assignable (Arg_Id)
4941 and then not Has_Pragma_Unmodified (Arg_Id)
4942 and then not Has_Pragma_Unused (Arg_Id)
4943 then
4944 Set_Has_Pragma_Unmodified (Arg_Id);
4945
4946 if Is_Unused then
4947 Set_Has_Pragma_Unused (Arg_Id);
4948 end if;
4949
4950 -- A pragma that applies to a Ghost entity becomes Ghost for
4951 -- the purposes of legality checks and removal of ignored
4952 -- Ghost code.
4953
4954 Mark_Ghost_Pragma (N, Arg_Id);
4955
4956 -- Capture the entity of the first Ghost variable being
4957 -- processed for error detection purposes.
4958
4959 if Is_Ghost_Entity (Arg_Id) then
4960 if No (Ghost_Id) then
4961 Ghost_Id := Arg_Id;
4962 end if;
4963
4964 -- Otherwise the variable is non-Ghost. It is illegal to mix
4965 -- references to Ghost and non-Ghost entities
4966 -- (SPARK RM 6.9).
4967
4968 elsif Present (Ghost_Id)
4969 and then not Ghost_Error_Posted
4970 then
4971 Ghost_Error_Posted := True;
4972
4973 Error_Msg_Name_1 := Pname;
4974 Error_Msg_N
4975 ("pragma % cannot mention ghost and non-ghost "
4976 & "variables", N);
4977
4978 Error_Msg_Sloc := Sloc (Ghost_Id);
4979 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
4980
4981 Error_Msg_Sloc := Sloc (Arg_Id);
4982 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
4983 end if;
4984
4985 -- Warn if already flagged as Unused or Unmodified
4986
4987 elsif Has_Pragma_Unmodified (Arg_Id) then
4988 if Has_Pragma_Unused (Arg_Id) then
4989 Error_Msg_NE
4990 ("??pragma Unused already given for &!", Arg_Expr,
4991 Arg_Id);
4992 else
4993 Error_Msg_NE
4994 ("??pragma Unmodified already given for &!", Arg_Expr,
4995 Arg_Id);
4996 end if;
4997
4998 -- Otherwise the pragma referenced an illegal entity
4999
5000 else
5001 Error_Pragma_Arg
5002 ("pragma% can only be applied to a variable", Arg_Expr);
5003 end if;
5004 end if;
5005
5006 Next (Arg);
5007 end loop;
5008 end Analyze_Unmodified_Or_Unused;
5009
5010 ------------------------------------
5011 -- Analyze_Unreferenced_Or_Unused --
5012 ------------------------------------
5013
5014 procedure Analyze_Unreferenced_Or_Unused
5015 (Is_Unused : Boolean := False)
5016 is
5017 Arg : Node_Id;
5018 Arg_Expr : Node_Id;
5019 Arg_Id : Entity_Id;
5020 Citem : Node_Id;
5021
5022 Ghost_Error_Posted : Boolean := False;
5023 -- Flag set when an error concerning the illegal mix of Ghost and
5024 -- non-Ghost names is emitted.
5025
5026 Ghost_Id : Entity_Id := Empty;
5027 -- The entity of the first Ghost name encountered while processing
5028 -- the arguments of the pragma.
5029
5030 begin
5031 GNAT_Pragma;
5032 Check_At_Least_N_Arguments (1);
5033
5034 -- Check case of appearing within context clause
5035
5036 if not Is_Unused and then Is_In_Context_Clause then
5037
5038 -- The arguments must all be units mentioned in a with clause in
5039 -- the same context clause. Note that Par.Prag already checked
5040 -- that the arguments are either identifiers or selected
5041 -- components.
5042
5043 Arg := Arg1;
5044 while Present (Arg) loop
5045 Citem := First (List_Containing (N));
5046 while Citem /= N loop
5047 Arg_Expr := Get_Pragma_Arg (Arg);
5048
5049 if Nkind (Citem) = N_With_Clause
5050 and then Same_Name (Name (Citem), Arg_Expr)
5051 then
5052 Set_Has_Pragma_Unreferenced
5053 (Cunit_Entity
5054 (Get_Source_Unit
5055 (Library_Unit (Citem))));
5056 Set_Elab_Unit_Name (Arg_Expr, Name (Citem));
5057 exit;
5058 end if;
5059
5060 Next (Citem);
5061 end loop;
5062
5063 if Citem = N then
5064 Error_Pragma_Arg
5065 ("argument of pragma% is not withed unit", Arg);
5066 end if;
5067
5068 Next (Arg);
5069 end loop;
5070
5071 -- Case of not in list of context items
5072
5073 else
5074 Arg := Arg1;
5075 while Present (Arg) loop
5076 Check_No_Identifier (Arg);
5077
5078 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
5079 -- in fact generate reference, so that the entity will have a
5080 -- reference, which will inhibit any warnings about it not
5081 -- being referenced, and also properly show up in the ali file
5082 -- as a reference. But this reference is recorded before the
5083 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5084 -- generated for this reference.
5085
5086 Check_Arg_Is_Local_Name (Arg);
5087 Arg_Expr := Get_Pragma_Arg (Arg);
5088
5089 if Is_Entity_Name (Arg_Expr) then
5090 Arg_Id := Entity (Arg_Expr);
5091
5092 -- Warn if already flagged as Unused or Unreferenced and
5093 -- skip processing the argument.
5094
5095 if Has_Pragma_Unreferenced (Arg_Id) then
5096 if Has_Pragma_Unused (Arg_Id) then
5097 Error_Msg_NE
5098 ("??pragma Unused already given for &!", Arg_Expr,
5099 Arg_Id);
5100 else
5101 Error_Msg_NE
5102 ("??pragma Unreferenced already given for &!",
5103 Arg_Expr, Arg_Id);
5104 end if;
5105
5106 -- Apply Unreferenced to the entity
5107
5108 else
5109 -- If the entity is overloaded, the pragma applies to the
5110 -- most recent overloading, as documented. In this case,
5111 -- name resolution does not generate a reference, so it
5112 -- must be done here explicitly.
5113
5114 if Is_Overloaded (Arg_Expr) then
5115 Generate_Reference (Arg_Id, N);
5116 end if;
5117
5118 Set_Has_Pragma_Unreferenced (Arg_Id);
5119
5120 if Is_Unused then
5121 Set_Has_Pragma_Unused (Arg_Id);
5122 end if;
5123
5124 -- A pragma that applies to a Ghost entity becomes Ghost
5125 -- for the purposes of legality checks and removal of
5126 -- ignored Ghost code.
5127
5128 Mark_Ghost_Pragma (N, Arg_Id);
5129
5130 -- Capture the entity of the first Ghost name being
5131 -- processed for error detection purposes.
5132
5133 if Is_Ghost_Entity (Arg_Id) then
5134 if No (Ghost_Id) then
5135 Ghost_Id := Arg_Id;
5136 end if;
5137
5138 -- Otherwise the name is non-Ghost. It is illegal to mix
5139 -- references to Ghost and non-Ghost entities
5140 -- (SPARK RM 6.9).
5141
5142 elsif Present (Ghost_Id)
5143 and then not Ghost_Error_Posted
5144 then
5145 Ghost_Error_Posted := True;
5146
5147 Error_Msg_Name_1 := Pname;
5148 Error_Msg_N
5149 ("pragma % cannot mention ghost and non-ghost "
5150 & "names", N);
5151
5152 Error_Msg_Sloc := Sloc (Ghost_Id);
5153 Error_Msg_NE
5154 ("\& # declared as ghost", N, Ghost_Id);
5155
5156 Error_Msg_Sloc := Sloc (Arg_Id);
5157 Error_Msg_NE
5158 ("\& # declared as non-ghost", N, Arg_Id);
5159 end if;
5160 end if;
5161 end if;
5162
5163 Next (Arg);
5164 end loop;
5165 end if;
5166 end Analyze_Unreferenced_Or_Unused;
5167
5168 --------------------------
5169 -- Check_Ada_83_Warning --
5170 --------------------------
5171
5172 procedure Check_Ada_83_Warning is
5173 begin
5174 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5175 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
5176 end if;
5177 end Check_Ada_83_Warning;
5178
5179 ---------------------
5180 -- Check_Arg_Count --
5181 ---------------------
5182
5183 procedure Check_Arg_Count (Required : Nat) is
5184 begin
5185 if Arg_Count /= Required then
5186 Error_Pragma ("wrong number of arguments for pragma%");
5187 end if;
5188 end Check_Arg_Count;
5189
5190 --------------------------------
5191 -- Check_Arg_Is_External_Name --
5192 --------------------------------
5193
5194 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
5195 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5196
5197 begin
5198 if Nkind (Argx) = N_Identifier then
5199 return;
5200
5201 else
5202 Analyze_And_Resolve (Argx, Standard_String);
5203
5204 if Is_OK_Static_Expression (Argx) then
5205 return;
5206
5207 elsif Etype (Argx) = Any_Type then
5208 raise Pragma_Exit;
5209
5210 -- An interesting special case, if we have a string literal and
5211 -- we are in Ada 83 mode, then we allow it even though it will
5212 -- not be flagged as static. This allows expected Ada 83 mode
5213 -- use of external names which are string literals, even though
5214 -- technically these are not static in Ada 83.
5215
5216 elsif Ada_Version = Ada_83
5217 and then Nkind (Argx) = N_String_Literal
5218 then
5219 return;
5220
5221 -- Here we have a real error (non-static expression)
5222
5223 else
5224 Error_Msg_Name_1 := Pname;
5225 Flag_Non_Static_Expr
5226 (Fix_Error ("argument for pragma% must be a identifier or "
5227 & "static string expression!"), Argx);
5228
5229 raise Pragma_Exit;
5230 end if;
5231 end if;
5232 end Check_Arg_Is_External_Name;
5233
5234 -----------------------------
5235 -- Check_Arg_Is_Identifier --
5236 -----------------------------
5237
5238 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
5239 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5240 begin
5241 if Nkind (Argx) /= N_Identifier then
5242 Error_Pragma_Arg ("argument for pragma% must be identifier", Argx);
5243 end if;
5244 end Check_Arg_Is_Identifier;
5245
5246 ----------------------------------
5247 -- Check_Arg_Is_Integer_Literal --
5248 ----------------------------------
5249
5250 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
5251 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5252 begin
5253 if Nkind (Argx) /= N_Integer_Literal then
5254 Error_Pragma_Arg
5255 ("argument for pragma% must be integer literal", Argx);
5256 end if;
5257 end Check_Arg_Is_Integer_Literal;
5258
5259 -------------------------------------------
5260 -- Check_Arg_Is_Library_Level_Local_Name --
5261 -------------------------------------------
5262
5263 -- LOCAL_NAME ::=
5264 -- DIRECT_NAME
5265 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5266 -- | library_unit_NAME
5267
5268 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
5269 begin
5270 Check_Arg_Is_Local_Name (Arg);
5271
5272 -- If it came from an aspect, we want to give the error just as if it
5273 -- came from source.
5274
5275 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
5276 and then (Comes_From_Source (N)
5277 or else Present (Corresponding_Aspect (Parent (Arg))))
5278 then
5279 Error_Pragma_Arg
5280 ("argument for pragma% must be library level entity", Arg);
5281 end if;
5282 end Check_Arg_Is_Library_Level_Local_Name;
5283
5284 -----------------------------
5285 -- Check_Arg_Is_Local_Name --
5286 -----------------------------
5287
5288 -- LOCAL_NAME ::=
5289 -- DIRECT_NAME
5290 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5291 -- | library_unit_NAME
5292
5293 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
5294 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5295
5296 begin
5297 -- If this pragma came from an aspect specification, we don't want to
5298 -- check for this error, because that would cause spurious errors, in
5299 -- case a type is frozen in a scope more nested than the type. The
5300 -- aspect itself of course can't be anywhere but on the declaration
5301 -- itself.
5302
5303 if Nkind (Arg) = N_Pragma_Argument_Association then
5304 if From_Aspect_Specification (Parent (Arg)) then
5305 return;
5306 end if;
5307
5308 -- Arg is the Expression of an N_Pragma_Argument_Association
5309
5310 else
5311 if From_Aspect_Specification (Parent (Parent (Arg))) then
5312 return;
5313 end if;
5314 end if;
5315
5316 Analyze (Argx);
5317
5318 if Nkind (Argx) not in N_Direct_Name
5319 and then (Nkind (Argx) /= N_Attribute_Reference
5320 or else Present (Expressions (Argx))
5321 or else Nkind (Prefix (Argx)) /= N_Identifier)
5322 and then (not Is_Entity_Name (Argx)
5323 or else not Is_Compilation_Unit (Entity (Argx)))
5324 then
5325 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
5326 end if;
5327
5328 -- No further check required if not an entity name
5329
5330 if not Is_Entity_Name (Argx) then
5331 null;
5332
5333 else
5334 declare
5335 OK : Boolean;
5336 Ent : constant Entity_Id := Entity (Argx);
5337 Scop : constant Entity_Id := Scope (Ent);
5338
5339 begin
5340 -- Case of a pragma applied to a compilation unit: pragma must
5341 -- occur immediately after the program unit in the compilation.
5342
5343 if Is_Compilation_Unit (Ent) then
5344 declare
5345 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
5346
5347 begin
5348 -- Case of pragma placed immediately after spec
5349
5350 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
5351 OK := True;
5352
5353 -- Case of pragma placed immediately after body
5354
5355 elsif Nkind (Decl) = N_Subprogram_Declaration
5356 and then Present (Corresponding_Body (Decl))
5357 then
5358 OK := Parent (N) =
5359 Aux_Decls_Node
5360 (Parent (Unit_Declaration_Node
5361 (Corresponding_Body (Decl))));
5362
5363 -- All other cases are illegal
5364
5365 else
5366 OK := False;
5367 end if;
5368 end;
5369
5370 -- Special restricted placement rule from 10.2.1(11.8/2)
5371
5372 elsif Is_Generic_Formal (Ent)
5373 and then Prag_Id = Pragma_Preelaborable_Initialization
5374 then
5375 OK := List_Containing (N) =
5376 Generic_Formal_Declarations
5377 (Unit_Declaration_Node (Scop));
5378
5379 -- If this is an aspect applied to a subprogram body, the
5380 -- pragma is inserted in its declarative part.
5381
5382 elsif From_Aspect_Specification (N)
5383 and then Ent = Current_Scope
5384 and then
5385 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
5386 then
5387 OK := True;
5388
5389 -- If the aspect is a predicate (possibly others ???) and the
5390 -- context is a record type, this is a discriminant expression
5391 -- within a type declaration, that freezes the predicated
5392 -- subtype.
5393
5394 elsif From_Aspect_Specification (N)
5395 and then Prag_Id = Pragma_Predicate
5396 and then Ekind (Current_Scope) = E_Record_Type
5397 and then Scop = Scope (Current_Scope)
5398 then
5399 OK := True;
5400
5401 -- Default case, just check that the pragma occurs in the scope
5402 -- of the entity denoted by the name.
5403
5404 else
5405 OK := Current_Scope = Scop;
5406 end if;
5407
5408 if not OK then
5409 Error_Pragma_Arg
5410 ("pragma% argument must be in same declarative part", Arg);
5411 end if;
5412 end;
5413 end if;
5414 end Check_Arg_Is_Local_Name;
5415
5416 ---------------------------------
5417 -- Check_Arg_Is_Locking_Policy --
5418 ---------------------------------
5419
5420 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
5421 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5422
5423 begin
5424 Check_Arg_Is_Identifier (Argx);
5425
5426 if not Is_Locking_Policy_Name (Chars (Argx)) then
5427 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
5428 end if;
5429 end Check_Arg_Is_Locking_Policy;
5430
5431 -----------------------------------------------
5432 -- Check_Arg_Is_Partition_Elaboration_Policy --
5433 -----------------------------------------------
5434
5435 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
5436 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5437
5438 begin
5439 Check_Arg_Is_Identifier (Argx);
5440
5441 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
5442 Error_Pragma_Arg
5443 ("& is not a valid partition elaboration policy name", Argx);
5444 end if;
5445 end Check_Arg_Is_Partition_Elaboration_Policy;
5446
5447 -------------------------
5448 -- Check_Arg_Is_One_Of --
5449 -------------------------
5450
5451 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5452 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5453
5454 begin
5455 Check_Arg_Is_Identifier (Argx);
5456
5457 if not Nam_In (Chars (Argx), N1, N2) then
5458 Error_Msg_Name_2 := N1;
5459 Error_Msg_Name_3 := N2;
5460 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
5461 end if;
5462 end Check_Arg_Is_One_Of;
5463
5464 procedure Check_Arg_Is_One_Of
5465 (Arg : Node_Id;
5466 N1, N2, N3 : Name_Id)
5467 is
5468 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5469
5470 begin
5471 Check_Arg_Is_Identifier (Argx);
5472
5473 if not Nam_In (Chars (Argx), N1, N2, N3) then
5474 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5475 end if;
5476 end Check_Arg_Is_One_Of;
5477
5478 procedure Check_Arg_Is_One_Of
5479 (Arg : Node_Id;
5480 N1, N2, N3, N4 : Name_Id)
5481 is
5482 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5483
5484 begin
5485 Check_Arg_Is_Identifier (Argx);
5486
5487 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
5488 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5489 end if;
5490 end Check_Arg_Is_One_Of;
5491
5492 procedure Check_Arg_Is_One_Of
5493 (Arg : Node_Id;
5494 N1, N2, N3, N4, N5 : Name_Id)
5495 is
5496 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5497
5498 begin
5499 Check_Arg_Is_Identifier (Argx);
5500
5501 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
5502 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5503 end if;
5504 end Check_Arg_Is_One_Of;
5505
5506 ---------------------------------
5507 -- Check_Arg_Is_Queuing_Policy --
5508 ---------------------------------
5509
5510 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
5511 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5512
5513 begin
5514 Check_Arg_Is_Identifier (Argx);
5515
5516 if not Is_Queuing_Policy_Name (Chars (Argx)) then
5517 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
5518 end if;
5519 end Check_Arg_Is_Queuing_Policy;
5520
5521 ---------------------------------------
5522 -- Check_Arg_Is_OK_Static_Expression --
5523 ---------------------------------------
5524
5525 procedure Check_Arg_Is_OK_Static_Expression
5526 (Arg : Node_Id;
5527 Typ : Entity_Id := Empty)
5528 is
5529 begin
5530 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
5531 end Check_Arg_Is_OK_Static_Expression;
5532
5533 ------------------------------------------
5534 -- Check_Arg_Is_Task_Dispatching_Policy --
5535 ------------------------------------------
5536
5537 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
5538 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5539
5540 begin
5541 Check_Arg_Is_Identifier (Argx);
5542
5543 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
5544 Error_Pragma_Arg
5545 ("& is not an allowed task dispatching policy name", Argx);
5546 end if;
5547 end Check_Arg_Is_Task_Dispatching_Policy;
5548
5549 ---------------------
5550 -- Check_Arg_Order --
5551 ---------------------
5552
5553 procedure Check_Arg_Order (Names : Name_List) is
5554 Arg : Node_Id;
5555
5556 Highest_So_Far : Natural := 0;
5557 -- Highest index in Names seen do far
5558
5559 begin
5560 Arg := Arg1;
5561 for J in 1 .. Arg_Count loop
5562 if Chars (Arg) /= No_Name then
5563 for K in Names'Range loop
5564 if Chars (Arg) = Names (K) then
5565 if K < Highest_So_Far then
5566 Error_Msg_Name_1 := Pname;
5567 Error_Msg_N
5568 ("parameters out of order for pragma%", Arg);
5569 Error_Msg_Name_1 := Names (K);
5570 Error_Msg_Name_2 := Names (Highest_So_Far);
5571 Error_Msg_N ("\% must appear before %", Arg);
5572 raise Pragma_Exit;
5573
5574 else
5575 Highest_So_Far := K;
5576 end if;
5577 end if;
5578 end loop;
5579 end if;
5580
5581 Arg := Next (Arg);
5582 end loop;
5583 end Check_Arg_Order;
5584
5585 --------------------------------
5586 -- Check_At_Least_N_Arguments --
5587 --------------------------------
5588
5589 procedure Check_At_Least_N_Arguments (N : Nat) is
5590 begin
5591 if Arg_Count < N then
5592 Error_Pragma ("too few arguments for pragma%");
5593 end if;
5594 end Check_At_Least_N_Arguments;
5595
5596 -------------------------------
5597 -- Check_At_Most_N_Arguments --
5598 -------------------------------
5599
5600 procedure Check_At_Most_N_Arguments (N : Nat) is
5601 Arg : Node_Id;
5602 begin
5603 if Arg_Count > N then
5604 Arg := Arg1;
5605 for J in 1 .. N loop
5606 Next (Arg);
5607 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
5608 end loop;
5609 end if;
5610 end Check_At_Most_N_Arguments;
5611
5612 ------------------------
5613 -- Check_Atomic_VFA --
5614 ------------------------
5615
5616 procedure Check_Atomic_VFA (E : Entity_Id; VFA : Boolean) is
5617
5618 Aliased_Subcomponent : exception;
5619 -- Exception raised if an aliased subcomponent is found in E
5620
5621 Independent_Subcomponent : exception;
5622 -- Exception raised if an independent subcomponent is found in E
5623
5624 procedure Check_Subcomponents (Typ : Entity_Id);
5625 -- Apply checks to subcomponents for Atomic and Volatile_Full_Access
5626
5627 -------------------------
5628 -- Check_Subcomponents --
5629 -------------------------
5630
5631 procedure Check_Subcomponents (Typ : Entity_Id) is
5632 Comp : Entity_Id;
5633
5634 begin
5635 if Is_Array_Type (Typ) then
5636 Comp := Component_Type (Typ);
5637
5638 -- For Atomic we accept any atomic subcomponents
5639
5640 if not VFA
5641 and then (Has_Atomic_Components (Typ)
5642 or else Is_Atomic (Comp))
5643 then
5644 null;
5645
5646 -- Give an error if the components are aliased
5647
5648 elsif Has_Aliased_Components (Typ)
5649 or else Is_Aliased (Comp)
5650 then
5651 raise Aliased_Subcomponent;
5652
5653 -- For VFA we accept non-aliased VFA subcomponents
5654
5655 elsif VFA
5656 and then Is_Volatile_Full_Access (Comp)
5657 then
5658 null;
5659
5660 -- Give an error if the components are independent
5661
5662 elsif Has_Independent_Components (Typ)
5663 or else Is_Independent (Comp)
5664 then
5665 raise Independent_Subcomponent;
5666 end if;
5667
5668 -- Recurse on the component type
5669
5670 Check_Subcomponents (Comp);
5671
5672 -- Note: Has_Aliased_Components, like Has_Atomic_Components,
5673 -- and Has_Independent_Components, applies only to arrays.
5674 -- However, this flag does not have a corresponding pragma, so
5675 -- perhaps it should be possible to apply it to record types as
5676 -- well. Should this be done ???
5677
5678 elsif Is_Record_Type (Typ) then
5679 -- It is possible to have an aliased discriminant, so they
5680 -- must be checked along with normal components.
5681
5682 Comp := First_Component_Or_Discriminant (Typ);
5683 while Present (Comp) loop
5684
5685 -- For Atomic we accept any atomic subcomponents
5686
5687 if not VFA
5688 and then (Is_Atomic (Comp)
5689 or else Is_Atomic (Etype (Comp)))
5690 then
5691 null;
5692
5693 -- Give an error if the component is aliased
5694
5695 elsif Is_Aliased (Comp)
5696 or else Is_Aliased (Etype (Comp))
5697 then
5698 raise Aliased_Subcomponent;
5699
5700 -- For VFA we accept non-aliased VFA subcomponents
5701
5702 elsif VFA
5703 and then (Is_Volatile_Full_Access (Comp)
5704 or else Is_Volatile_Full_Access (Etype (Comp)))
5705 then
5706 null;
5707
5708 -- Give an error if the component is independent
5709
5710 elsif Is_Independent (Comp)
5711 or else Is_Independent (Etype (Comp))
5712 then
5713 raise Independent_Subcomponent;
5714 end if;
5715
5716 -- Recurse on the component type
5717
5718 Check_Subcomponents (Etype (Comp));
5719
5720 Next_Component_Or_Discriminant (Comp);
5721 end loop;
5722 end if;
5723 end Check_Subcomponents;
5724
5725 Typ : Entity_Id;
5726
5727 begin
5728 -- Fetch the type in case we are dealing with an object or component
5729
5730 if Is_Type (E) then
5731 Typ := E;
5732 else
5733 pragma Assert (Is_Object (E)
5734 or else
5735 Nkind (Declaration_Node (E)) = N_Component_Declaration);
5736
5737 Typ := Etype (E);
5738 end if;
5739
5740 -- Check all the subcomponents of the type recursively, if any
5741
5742 Check_Subcomponents (Typ);
5743
5744 exception
5745 when Aliased_Subcomponent =>
5746 if VFA then
5747 Error_Pragma
5748 ("cannot apply Volatile_Full_Access with aliased "
5749 & "subcomponent ");
5750 else
5751 Error_Pragma
5752 ("cannot apply Atomic with aliased subcomponent "
5753 & "(RM C.6(13))");
5754 end if;
5755
5756 when Independent_Subcomponent =>
5757 if VFA then
5758 Error_Pragma
5759 ("cannot apply Volatile_Full_Access with independent "
5760 & "subcomponent ");
5761 else
5762 Error_Pragma
5763 ("cannot apply Atomic with independent subcomponent "
5764 & "(RM C.6(13))");
5765 end if;
5766
5767 when others =>
5768 raise Program_Error;
5769 end Check_Atomic_VFA;
5770
5771 ---------------------
5772 -- Check_Component --
5773 ---------------------
5774
5775 procedure Check_Component
5776 (Comp : Node_Id;
5777 UU_Typ : Entity_Id;
5778 In_Variant_Part : Boolean := False)
5779 is
5780 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
5781 Sindic : constant Node_Id :=
5782 Subtype_Indication (Component_Definition (Comp));
5783 Typ : constant Entity_Id := Etype (Comp_Id);
5784
5785 begin
5786 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
5787 -- object constraint, then the component type shall be an Unchecked_
5788 -- Union.
5789
5790 if Nkind (Sindic) = N_Subtype_Indication
5791 and then Has_Per_Object_Constraint (Comp_Id)
5792 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
5793 then
5794 Error_Msg_N
5795 ("component subtype subject to per-object constraint "
5796 & "must be an Unchecked_Union", Comp);
5797
5798 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
5799 -- the body of a generic unit, or within the body of any of its
5800 -- descendant library units, no part of the type of a component
5801 -- declared in a variant_part of the unchecked union type shall be of
5802 -- a formal private type or formal private extension declared within
5803 -- the formal part of the generic unit.
5804
5805 elsif Ada_Version >= Ada_2012
5806 and then In_Generic_Body (UU_Typ)
5807 and then In_Variant_Part
5808 and then Is_Private_Type (Typ)
5809 and then Is_Generic_Type (Typ)
5810 then
5811 Error_Msg_N
5812 ("component of unchecked union cannot be of generic type", Comp);
5813
5814 elsif Needs_Finalization (Typ) then
5815 Error_Msg_N
5816 ("component of unchecked union cannot be controlled", Comp);
5817
5818 elsif Has_Task (Typ) then
5819 Error_Msg_N
5820 ("component of unchecked union cannot have tasks", Comp);
5821 end if;
5822 end Check_Component;
5823
5824 ----------------------------
5825 -- Check_Duplicate_Pragma --
5826 ----------------------------
5827
5828 procedure Check_Duplicate_Pragma (E : Entity_Id) is
5829 Id : Entity_Id := E;
5830 P : Node_Id;
5831
5832 begin
5833 -- Nothing to do if this pragma comes from an aspect specification,
5834 -- since we could not be duplicating a pragma, and we dealt with the
5835 -- case of duplicated aspects in Analyze_Aspect_Specifications.
5836
5837 if From_Aspect_Specification (N) then
5838 return;
5839 end if;
5840
5841 -- Otherwise current pragma may duplicate previous pragma or a
5842 -- previously given aspect specification or attribute definition
5843 -- clause for the same pragma.
5844
5845 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
5846
5847 if Present (P) then
5848
5849 -- If the entity is a type, then we have to make sure that the
5850 -- ostensible duplicate is not for a parent type from which this
5851 -- type is derived.
5852
5853 if Is_Type (E) then
5854 if Nkind (P) = N_Pragma then
5855 declare
5856 Args : constant List_Id :=
5857 Pragma_Argument_Associations (P);
5858 begin
5859 if Present (Args)
5860 and then Is_Entity_Name (Expression (First (Args)))
5861 and then Is_Type (Entity (Expression (First (Args))))
5862 and then Entity (Expression (First (Args))) /= E
5863 then
5864 return;
5865 end if;
5866 end;
5867
5868 elsif Nkind (P) = N_Aspect_Specification
5869 and then Is_Type (Entity (P))
5870 and then Entity (P) /= E
5871 then
5872 return;
5873 end if;
5874 end if;
5875
5876 -- Here we have a definite duplicate
5877
5878 Error_Msg_Name_1 := Pragma_Name (N);
5879 Error_Msg_Sloc := Sloc (P);
5880
5881 -- For a single protected or a single task object, the error is
5882 -- issued on the original entity.
5883
5884 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
5885 Id := Defining_Identifier (Original_Node (Parent (Id)));
5886 end if;
5887
5888 if Nkind (P) = N_Aspect_Specification
5889 or else From_Aspect_Specification (P)
5890 then
5891 Error_Msg_NE ("aspect% for & previously given#", N, Id);
5892 else
5893 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
5894 end if;
5895
5896 raise Pragma_Exit;
5897 end if;
5898 end Check_Duplicate_Pragma;
5899
5900 ----------------------------------
5901 -- Check_Duplicated_Export_Name --
5902 ----------------------------------
5903
5904 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
5905 String_Val : constant String_Id := Strval (Nam);
5906
5907 begin
5908 -- We are only interested in the export case, and in the case of
5909 -- generics, it is the instance, not the template, that is the
5910 -- problem (the template will generate a warning in any case).
5911
5912 if not Inside_A_Generic
5913 and then (Prag_Id = Pragma_Export
5914 or else
5915 Prag_Id = Pragma_Export_Procedure
5916 or else
5917 Prag_Id = Pragma_Export_Valued_Procedure
5918 or else
5919 Prag_Id = Pragma_Export_Function)
5920 then
5921 for J in Externals.First .. Externals.Last loop
5922 if String_Equal (String_Val, Strval (Externals.Table (J))) then
5923 Error_Msg_Sloc := Sloc (Externals.Table (J));
5924 Error_Msg_N ("external name duplicates name given#", Nam);
5925 exit;
5926 end if;
5927 end loop;
5928
5929 Externals.Append (Nam);
5930 end if;
5931 end Check_Duplicated_Export_Name;
5932
5933 ----------------------------------------
5934 -- Check_Expr_Is_OK_Static_Expression --
5935 ----------------------------------------
5936
5937 procedure Check_Expr_Is_OK_Static_Expression
5938 (Expr : Node_Id;
5939 Typ : Entity_Id := Empty)
5940 is
5941 begin
5942 if Present (Typ) then
5943 Analyze_And_Resolve (Expr, Typ);
5944 else
5945 Analyze_And_Resolve (Expr);
5946 end if;
5947
5948 -- An expression cannot be considered static if its resolution failed
5949 -- or if it's erroneous. Stop the analysis of the related pragma.
5950
5951 if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
5952 raise Pragma_Exit;
5953
5954 elsif Is_OK_Static_Expression (Expr) then
5955 return;
5956
5957 -- An interesting special case, if we have a string literal and we
5958 -- are in Ada 83 mode, then we allow it even though it will not be
5959 -- flagged as static. This allows the use of Ada 95 pragmas like
5960 -- Import in Ada 83 mode. They will of course be flagged with
5961 -- warnings as usual, but will not cause errors.
5962
5963 elsif Ada_Version = Ada_83
5964 and then Nkind (Expr) = N_String_Literal
5965 then
5966 return;
5967
5968 -- Finally, we have a real error
5969
5970 else
5971 Error_Msg_Name_1 := Pname;
5972 Flag_Non_Static_Expr
5973 (Fix_Error ("argument for pragma% must be a static expression!"),
5974 Expr);
5975 raise Pragma_Exit;
5976 end if;
5977 end Check_Expr_Is_OK_Static_Expression;
5978
5979 -------------------------
5980 -- Check_First_Subtype --
5981 -------------------------
5982
5983 procedure Check_First_Subtype (Arg : Node_Id) is
5984 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5985 Ent : constant Entity_Id := Entity (Argx);
5986
5987 begin
5988 if Is_First_Subtype (Ent) then
5989 null;
5990
5991 elsif Is_Type (Ent) then
5992 Error_Pragma_Arg
5993 ("pragma% cannot apply to subtype", Argx);
5994
5995 elsif Is_Object (Ent) then
5996 Error_Pragma_Arg
5997 ("pragma% cannot apply to object, requires a type", Argx);
5998
5999 else
6000 Error_Pragma_Arg
6001 ("pragma% cannot apply to&, requires a type", Argx);
6002 end if;
6003 end Check_First_Subtype;
6004
6005 ----------------------
6006 -- Check_Identifier --
6007 ----------------------
6008
6009 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
6010 begin
6011 if Present (Arg)
6012 and then Nkind (Arg) = N_Pragma_Argument_Association
6013 then
6014 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
6015 Error_Msg_Name_1 := Pname;
6016 Error_Msg_Name_2 := Id;
6017 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6018 raise Pragma_Exit;
6019 end if;
6020 end if;
6021 end Check_Identifier;
6022
6023 --------------------------------
6024 -- Check_Identifier_Is_One_Of --
6025 --------------------------------
6026
6027 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
6028 begin
6029 if Present (Arg)
6030 and then Nkind (Arg) = N_Pragma_Argument_Association
6031 then
6032 if Chars (Arg) = No_Name then
6033 Error_Msg_Name_1 := Pname;
6034 Error_Msg_N ("pragma% argument expects an identifier", Arg);
6035 raise Pragma_Exit;
6036
6037 elsif Chars (Arg) /= N1
6038 and then Chars (Arg) /= N2
6039 then
6040 Error_Msg_Name_1 := Pname;
6041 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
6042 raise Pragma_Exit;
6043 end if;
6044 end if;
6045 end Check_Identifier_Is_One_Of;
6046
6047 ---------------------------
6048 -- Check_In_Main_Program --
6049 ---------------------------
6050
6051 procedure Check_In_Main_Program is
6052 P : constant Node_Id := Parent (N);
6053
6054 begin
6055 -- Must be in subprogram body
6056
6057 if Nkind (P) /= N_Subprogram_Body then
6058 Error_Pragma ("% pragma allowed only in subprogram");
6059
6060 -- Otherwise warn if obviously not main program
6061
6062 elsif Present (Parameter_Specifications (Specification (P)))
6063 or else not Is_Compilation_Unit (Defining_Entity (P))
6064 then
6065 Error_Msg_Name_1 := Pname;
6066 Error_Msg_N
6067 ("??pragma% is only effective in main program", N);
6068 end if;
6069 end Check_In_Main_Program;
6070
6071 ---------------------------------------
6072 -- Check_Interrupt_Or_Attach_Handler --
6073 ---------------------------------------
6074
6075 procedure Check_Interrupt_Or_Attach_Handler is
6076 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
6077 Handler_Proc, Proc_Scope : Entity_Id;
6078
6079 begin
6080 Analyze (Arg1_X);
6081
6082 if Prag_Id = Pragma_Interrupt_Handler then
6083 Check_Restriction (No_Dynamic_Attachment, N);
6084 end if;
6085
6086 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
6087 Proc_Scope := Scope (Handler_Proc);
6088
6089 if Ekind (Proc_Scope) /= E_Protected_Type then
6090 Error_Pragma_Arg
6091 ("argument of pragma% must be protected procedure", Arg1);
6092 end if;
6093
6094 -- For pragma case (as opposed to access case), check placement.
6095 -- We don't need to do that for aspects, because we have the
6096 -- check that they aspect applies an appropriate procedure.
6097
6098 if not From_Aspect_Specification (N)
6099 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
6100 then
6101 Error_Pragma ("pragma% must be in protected definition");
6102 end if;
6103
6104 if not Is_Library_Level_Entity (Proc_Scope) then
6105 Error_Pragma_Arg
6106 ("argument for pragma% must be library level entity", Arg1);
6107 end if;
6108
6109 -- AI05-0033: A pragma cannot appear within a generic body, because
6110 -- instance can be in a nested scope. The check that protected type
6111 -- is itself a library-level declaration is done elsewhere.
6112
6113 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
6114 -- handle code prior to AI-0033. Analysis tools typically are not
6115 -- interested in this pragma in any case, so no need to worry too
6116 -- much about its placement.
6117
6118 if Inside_A_Generic then
6119 if Ekind (Scope (Current_Scope)) = E_Generic_Package
6120 and then In_Package_Body (Scope (Current_Scope))
6121 and then not Relaxed_RM_Semantics
6122 then
6123 Error_Pragma ("pragma% cannot be used inside a generic");
6124 end if;
6125 end if;
6126 end Check_Interrupt_Or_Attach_Handler;
6127
6128 ---------------------------------
6129 -- Check_Loop_Pragma_Placement --
6130 ---------------------------------
6131
6132 procedure Check_Loop_Pragma_Placement is
6133 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
6134 -- Verify whether the current pragma is properly grouped with other
6135 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
6136 -- related loop where the pragma appears.
6137
6138 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
6139 -- Determine whether an arbitrary statement Stmt denotes pragma
6140 -- Loop_Invariant or Loop_Variant.
6141
6142 procedure Placement_Error (Constr : Node_Id);
6143 pragma No_Return (Placement_Error);
6144 -- Node Constr denotes the last loop restricted construct before we
6145 -- encountered an illegal relation between enclosing constructs. Emit
6146 -- an error depending on what Constr was.
6147
6148 --------------------------------
6149 -- Check_Loop_Pragma_Grouping --
6150 --------------------------------
6151
6152 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
6153 Stop_Search : exception;
6154 -- This exception is used to terminate the recursive descent of
6155 -- routine Check_Grouping.
6156
6157 procedure Check_Grouping (L : List_Id);
6158 -- Find the first group of pragmas in list L and if successful,
6159 -- ensure that the current pragma is part of that group. The
6160 -- routine raises Stop_Search once such a check is performed to
6161 -- halt the recursive descent.
6162
6163 procedure Grouping_Error (Prag : Node_Id);
6164 pragma No_Return (Grouping_Error);
6165 -- Emit an error concerning the current pragma indicating that it
6166 -- should be placed after pragma Prag.
6167
6168 --------------------
6169 -- Check_Grouping --
6170 --------------------
6171
6172 procedure Check_Grouping (L : List_Id) is
6173 HSS : Node_Id;
6174 Stmt : Node_Id;
6175 Prag : Node_Id := Empty; -- init to avoid warning
6176
6177 begin
6178 -- Inspect the list of declarations or statements looking for
6179 -- the first grouping of pragmas:
6180
6181 -- loop
6182 -- pragma Loop_Invariant ...;
6183 -- pragma Loop_Variant ...;
6184 -- . . . -- (1)
6185 -- pragma Loop_Variant ...; -- current pragma
6186
6187 -- If the current pragma is not in the grouping, then it must
6188 -- either appear in a different declarative or statement list
6189 -- or the construct at (1) is separating the pragma from the
6190 -- grouping.
6191
6192 Stmt := First (L);
6193 while Present (Stmt) loop
6194
6195 -- First pragma of the first topmost grouping has been found
6196
6197 if Is_Loop_Pragma (Stmt) then
6198
6199 -- The group and the current pragma are not in the same
6200 -- declarative or statement list.
6201
6202 if List_Containing (Stmt) /= List_Containing (N) then
6203 Grouping_Error (Stmt);
6204
6205 -- Try to reach the current pragma from the first pragma
6206 -- of the grouping while skipping other members:
6207
6208 -- pragma Loop_Invariant ...; -- first pragma
6209 -- pragma Loop_Variant ...; -- member
6210 -- . . .
6211 -- pragma Loop_Variant ...; -- current pragma
6212
6213 else
6214 while Present (Stmt) loop
6215 -- The current pragma is either the first pragma
6216 -- of the group or is a member of the group.
6217 -- Stop the search as the placement is legal.
6218
6219 if Stmt = N then
6220 raise Stop_Search;
6221
6222 -- Skip group members, but keep track of the
6223 -- last pragma in the group.
6224
6225 elsif Is_Loop_Pragma (Stmt) then
6226 Prag := Stmt;
6227
6228 -- Skip declarations and statements generated by
6229 -- the compiler during expansion. Note that some
6230 -- source statements (e.g. pragma Assert) may have
6231 -- been transformed so that they do not appear as
6232 -- coming from source anymore, so we instead look
6233 -- at their Original_Node.
6234
6235 elsif not Comes_From_Source (Original_Node (Stmt))
6236 then
6237 null;
6238
6239 -- A non-pragma is separating the group from the
6240 -- current pragma, the placement is illegal.
6241
6242 else
6243 Grouping_Error (Prag);
6244 end if;
6245
6246 Next (Stmt);
6247 end loop;
6248
6249 -- If the traversal did not reach the current pragma,
6250 -- then the list must be malformed.
6251
6252 raise Program_Error;
6253 end if;
6254
6255 -- Pragmas Loop_Invariant and Loop_Variant may only appear
6256 -- inside a loop or a block housed inside a loop. Inspect
6257 -- the declarations and statements of the block as they may
6258 -- contain the first grouping. This case follows the one for
6259 -- loop pragmas, as block statements which originate in a
6260 -- loop pragma (and so Is_Loop_Pragma will return True on
6261 -- that block statement) should be treated in the previous
6262 -- case.
6263
6264 elsif Nkind (Stmt) = N_Block_Statement then
6265 HSS := Handled_Statement_Sequence (Stmt);
6266
6267 Check_Grouping (Declarations (Stmt));
6268
6269 if Present (HSS) then
6270 Check_Grouping (Statements (HSS));
6271 end if;
6272 end if;
6273
6274 Next (Stmt);
6275 end loop;
6276 end Check_Grouping;
6277
6278 --------------------
6279 -- Grouping_Error --
6280 --------------------
6281
6282 procedure Grouping_Error (Prag : Node_Id) is
6283 begin
6284 Error_Msg_Sloc := Sloc (Prag);
6285 Error_Pragma ("pragma% must appear next to pragma#");
6286 end Grouping_Error;
6287
6288 -- Start of processing for Check_Loop_Pragma_Grouping
6289
6290 begin
6291 -- Inspect the statements of the loop or nested blocks housed
6292 -- within to determine whether the current pragma is part of the
6293 -- first topmost grouping of Loop_Invariant and Loop_Variant.
6294
6295 Check_Grouping (Statements (Loop_Stmt));
6296
6297 exception
6298 when Stop_Search => null;
6299 end Check_Loop_Pragma_Grouping;
6300
6301 --------------------
6302 -- Is_Loop_Pragma --
6303 --------------------
6304
6305 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
6306 begin
6307 -- Inspect the original node as Loop_Invariant and Loop_Variant
6308 -- pragmas are rewritten to null when assertions are disabled.
6309
6310 if Nkind (Original_Node (Stmt)) = N_Pragma then
6311 return
6312 Nam_In (Pragma_Name_Unmapped (Original_Node (Stmt)),
6313 Name_Loop_Invariant,
6314 Name_Loop_Variant);
6315 else
6316 return False;
6317 end if;
6318 end Is_Loop_Pragma;
6319
6320 ---------------------
6321 -- Placement_Error --
6322 ---------------------
6323
6324 procedure Placement_Error (Constr : Node_Id) is
6325 LA : constant String := " with Loop_Entry";
6326
6327 begin
6328 if Prag_Id = Pragma_Assert then
6329 Error_Msg_String (1 .. LA'Length) := LA;
6330 Error_Msg_Strlen := LA'Length;
6331 else
6332 Error_Msg_Strlen := 0;
6333 end if;
6334
6335 if Nkind (Constr) = N_Pragma then
6336 Error_Pragma
6337 ("pragma %~ must appear immediately within the statements "
6338 & "of a loop");
6339 else
6340 Error_Pragma_Arg
6341 ("block containing pragma %~ must appear immediately within "
6342 & "the statements of a loop", Constr);
6343 end if;
6344 end Placement_Error;
6345
6346 -- Local declarations
6347
6348 Prev : Node_Id;
6349 Stmt : Node_Id;
6350
6351 -- Start of processing for Check_Loop_Pragma_Placement
6352
6353 begin
6354 -- Check that pragma appears immediately within a loop statement,
6355 -- ignoring intervening block statements.
6356
6357 Prev := N;
6358 Stmt := Parent (N);
6359 while Present (Stmt) loop
6360
6361 -- The pragma or previous block must appear immediately within the
6362 -- current block's declarative or statement part.
6363
6364 if Nkind (Stmt) = N_Block_Statement then
6365 if (No (Declarations (Stmt))
6366 or else List_Containing (Prev) /= Declarations (Stmt))
6367 and then
6368 List_Containing (Prev) /=
6369 Statements (Handled_Statement_Sequence (Stmt))
6370 then
6371 Placement_Error (Prev);
6372 return;
6373
6374 -- Keep inspecting the parents because we are now within a
6375 -- chain of nested blocks.
6376
6377 else
6378 Prev := Stmt;
6379 Stmt := Parent (Stmt);
6380 end if;
6381
6382 -- The pragma or previous block must appear immediately within the
6383 -- statements of the loop.
6384
6385 elsif Nkind (Stmt) = N_Loop_Statement then
6386 if List_Containing (Prev) /= Statements (Stmt) then
6387 Placement_Error (Prev);
6388 end if;
6389
6390 -- Stop the traversal because we reached the innermost loop
6391 -- regardless of whether we encountered an error or not.
6392
6393 exit;
6394
6395 -- Ignore a handled statement sequence. Note that this node may
6396 -- be related to a subprogram body in which case we will emit an
6397 -- error on the next iteration of the search.
6398
6399 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
6400 Stmt := Parent (Stmt);
6401
6402 -- Any other statement breaks the chain from the pragma to the
6403 -- loop.
6404
6405 else
6406 Placement_Error (Prev);
6407 return;
6408 end if;
6409 end loop;
6410
6411 -- Check that the current pragma Loop_Invariant or Loop_Variant is
6412 -- grouped together with other such pragmas.
6413
6414 if Is_Loop_Pragma (N) then
6415
6416 -- The previous check should have located the related loop
6417
6418 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
6419 Check_Loop_Pragma_Grouping (Stmt);
6420 end if;
6421 end Check_Loop_Pragma_Placement;
6422
6423 -------------------------------------------
6424 -- Check_Is_In_Decl_Part_Or_Package_Spec --
6425 -------------------------------------------
6426
6427 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
6428 P : Node_Id;
6429
6430 begin
6431 P := Parent (N);
6432 loop
6433 if No (P) then
6434 exit;
6435
6436 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
6437 exit;
6438
6439 elsif Nkind_In (P, N_Package_Specification,
6440 N_Block_Statement)
6441 then
6442 return;
6443
6444 -- Note: the following tests seem a little peculiar, because
6445 -- they test for bodies, but if we were in the statement part
6446 -- of the body, we would already have hit the handled statement
6447 -- sequence, so the only way we get here is by being in the
6448 -- declarative part of the body.
6449
6450 elsif Nkind_In (P, N_Subprogram_Body,
6451 N_Package_Body,
6452 N_Task_Body,
6453 N_Entry_Body)
6454 then
6455 return;
6456 end if;
6457
6458 P := Parent (P);
6459 end loop;
6460
6461 Error_Pragma ("pragma% is not in declarative part or package spec");
6462 end Check_Is_In_Decl_Part_Or_Package_Spec;
6463
6464 -------------------------
6465 -- Check_No_Identifier --
6466 -------------------------
6467
6468 procedure Check_No_Identifier (Arg : Node_Id) is
6469 begin
6470 if Nkind (Arg) = N_Pragma_Argument_Association
6471 and then Chars (Arg) /= No_Name
6472 then
6473 Error_Pragma_Arg_Ident
6474 ("pragma% does not permit identifier& here", Arg);
6475 end if;
6476 end Check_No_Identifier;
6477
6478 --------------------------
6479 -- Check_No_Identifiers --
6480 --------------------------
6481
6482 procedure Check_No_Identifiers is
6483 Arg_Node : Node_Id;
6484 begin
6485 Arg_Node := Arg1;
6486 for J in 1 .. Arg_Count loop
6487 Check_No_Identifier (Arg_Node);
6488 Next (Arg_Node);
6489 end loop;
6490 end Check_No_Identifiers;
6491
6492 ------------------------
6493 -- Check_No_Link_Name --
6494 ------------------------
6495
6496 procedure Check_No_Link_Name is
6497 begin
6498 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
6499 Arg4 := Arg3;
6500 end if;
6501
6502 if Present (Arg4) then
6503 Error_Pragma_Arg
6504 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
6505 end if;
6506 end Check_No_Link_Name;
6507
6508 -------------------------------
6509 -- Check_Optional_Identifier --
6510 -------------------------------
6511
6512 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
6513 begin
6514 if Present (Arg)
6515 and then Nkind (Arg) = N_Pragma_Argument_Association
6516 and then Chars (Arg) /= No_Name
6517 then
6518 if Chars (Arg) /= Id then
6519 Error_Msg_Name_1 := Pname;
6520 Error_Msg_Name_2 := Id;
6521 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6522 raise Pragma_Exit;
6523 end if;
6524 end if;
6525 end Check_Optional_Identifier;
6526
6527 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
6528 begin
6529 Check_Optional_Identifier (Arg, Name_Find (Id));
6530 end Check_Optional_Identifier;
6531
6532 -------------------------------------
6533 -- Check_Static_Boolean_Expression --
6534 -------------------------------------
6535
6536 procedure Check_Static_Boolean_Expression (Expr : Node_Id) is
6537 begin
6538 if Present (Expr) then
6539 Analyze_And_Resolve (Expr, Standard_Boolean);
6540
6541 if not Is_OK_Static_Expression (Expr) then
6542 Error_Pragma_Arg
6543 ("expression of pragma % must be static", Expr);
6544 end if;
6545 end if;
6546 end Check_Static_Boolean_Expression;
6547
6548 -----------------------------
6549 -- Check_Static_Constraint --
6550 -----------------------------
6551
6552 -- Note: for convenience in writing this procedure, in addition to
6553 -- the officially (i.e. by spec) allowed argument which is always a
6554 -- constraint, it also allows ranges and discriminant associations.
6555 -- Above is not clear ???
6556
6557 procedure Check_Static_Constraint (Constr : Node_Id) is
6558
6559 procedure Require_Static (E : Node_Id);
6560 -- Require given expression to be static expression
6561
6562 --------------------
6563 -- Require_Static --
6564 --------------------
6565
6566 procedure Require_Static (E : Node_Id) is
6567 begin
6568 if not Is_OK_Static_Expression (E) then
6569 Flag_Non_Static_Expr
6570 ("non-static constraint not allowed in Unchecked_Union!", E);
6571 raise Pragma_Exit;
6572 end if;
6573 end Require_Static;
6574
6575 -- Start of processing for Check_Static_Constraint
6576
6577 begin
6578 case Nkind (Constr) is
6579 when N_Discriminant_Association =>
6580 Require_Static (Expression (Constr));
6581
6582 when N_Range =>
6583 Require_Static (Low_Bound (Constr));
6584 Require_Static (High_Bound (Constr));
6585
6586 when N_Attribute_Reference =>
6587 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
6588 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
6589
6590 when N_Range_Constraint =>
6591 Check_Static_Constraint (Range_Expression (Constr));
6592
6593 when N_Index_Or_Discriminant_Constraint =>
6594 declare
6595 IDC : Entity_Id;
6596 begin
6597 IDC := First (Constraints (Constr));
6598 while Present (IDC) loop
6599 Check_Static_Constraint (IDC);
6600 Next (IDC);
6601 end loop;
6602 end;
6603
6604 when others =>
6605 null;
6606 end case;
6607 end Check_Static_Constraint;
6608
6609 --------------------------------------
6610 -- Check_Valid_Configuration_Pragma --
6611 --------------------------------------
6612
6613 -- A configuration pragma must appear in the context clause of a
6614 -- compilation unit, and only other pragmas may precede it. Note that
6615 -- the test also allows use in a configuration pragma file.
6616
6617 procedure Check_Valid_Configuration_Pragma is
6618 begin
6619 if not Is_Configuration_Pragma then
6620 Error_Pragma ("incorrect placement for configuration pragma%");
6621 end if;
6622 end Check_Valid_Configuration_Pragma;
6623
6624 -------------------------------------
6625 -- Check_Valid_Library_Unit_Pragma --
6626 -------------------------------------
6627
6628 procedure Check_Valid_Library_Unit_Pragma is
6629 Plist : List_Id;
6630 Parent_Node : Node_Id;
6631 Unit_Name : Entity_Id;
6632 Unit_Kind : Node_Kind;
6633 Unit_Node : Node_Id;
6634 Sindex : Source_File_Index;
6635
6636 begin
6637 if not Is_List_Member (N) then
6638 Pragma_Misplaced;
6639
6640 else
6641 Plist := List_Containing (N);
6642 Parent_Node := Parent (Plist);
6643
6644 if Parent_Node = Empty then
6645 Pragma_Misplaced;
6646
6647 -- Case of pragma appearing after a compilation unit. In this case
6648 -- it must have an argument with the corresponding name and must
6649 -- be part of the following pragmas of its parent.
6650
6651 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
6652 if Plist /= Pragmas_After (Parent_Node) then
6653 Pragma_Misplaced;
6654
6655 elsif Arg_Count = 0 then
6656 Error_Pragma
6657 ("argument required if outside compilation unit");
6658
6659 else
6660 Check_No_Identifiers;
6661 Check_Arg_Count (1);
6662 Unit_Node := Unit (Parent (Parent_Node));
6663 Unit_Kind := Nkind (Unit_Node);
6664
6665 Analyze (Get_Pragma_Arg (Arg1));
6666
6667 if Unit_Kind = N_Generic_Subprogram_Declaration
6668 or else Unit_Kind = N_Subprogram_Declaration
6669 then
6670 Unit_Name := Defining_Entity (Unit_Node);
6671
6672 elsif Unit_Kind in N_Generic_Instantiation then
6673 Unit_Name := Defining_Entity (Unit_Node);
6674
6675 else
6676 Unit_Name := Cunit_Entity (Current_Sem_Unit);
6677 end if;
6678
6679 if Chars (Unit_Name) /=
6680 Chars (Entity (Get_Pragma_Arg (Arg1)))
6681 then
6682 Error_Pragma_Arg
6683 ("pragma% argument is not current unit name", Arg1);
6684 end if;
6685
6686 if Ekind (Unit_Name) = E_Package
6687 and then Present (Renamed_Entity (Unit_Name))
6688 then
6689 Error_Pragma ("pragma% not allowed for renamed package");
6690 end if;
6691 end if;
6692
6693 -- Pragma appears other than after a compilation unit
6694
6695 else
6696 -- Here we check for the generic instantiation case and also
6697 -- for the case of processing a generic formal package. We
6698 -- detect these cases by noting that the Sloc on the node
6699 -- does not belong to the current compilation unit.
6700
6701 Sindex := Source_Index (Current_Sem_Unit);
6702
6703 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
6704 Rewrite (N, Make_Null_Statement (Loc));
6705 return;
6706
6707 -- If before first declaration, the pragma applies to the
6708 -- enclosing unit, and the name if present must be this name.
6709
6710 elsif Is_Before_First_Decl (N, Plist) then
6711 Unit_Node := Unit_Declaration_Node (Current_Scope);
6712 Unit_Kind := Nkind (Unit_Node);
6713
6714 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
6715 Pragma_Misplaced;
6716
6717 elsif Unit_Kind = N_Subprogram_Body
6718 and then not Acts_As_Spec (Unit_Node)
6719 then
6720 Pragma_Misplaced;
6721
6722 elsif Nkind (Parent_Node) = N_Package_Body then
6723 Pragma_Misplaced;
6724
6725 elsif Nkind (Parent_Node) = N_Package_Specification
6726 and then Plist = Private_Declarations (Parent_Node)
6727 then
6728 Pragma_Misplaced;
6729
6730 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
6731 or else Nkind (Parent_Node) =
6732 N_Generic_Subprogram_Declaration)
6733 and then Plist = Generic_Formal_Declarations (Parent_Node)
6734 then
6735 Pragma_Misplaced;
6736
6737 elsif Arg_Count > 0 then
6738 Analyze (Get_Pragma_Arg (Arg1));
6739
6740 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
6741 Error_Pragma_Arg
6742 ("name in pragma% must be enclosing unit", Arg1);
6743 end if;
6744
6745 -- It is legal to have no argument in this context
6746
6747 else
6748 return;
6749 end if;
6750
6751 -- Error if not before first declaration. This is because a
6752 -- library unit pragma argument must be the name of a library
6753 -- unit (RM 10.1.5(7)), but the only names permitted in this
6754 -- context are (RM 10.1.5(6)) names of subprogram declarations,
6755 -- generic subprogram declarations or generic instantiations.
6756
6757 else
6758 Error_Pragma
6759 ("pragma% misplaced, must be before first declaration");
6760 end if;
6761 end if;
6762 end if;
6763 end Check_Valid_Library_Unit_Pragma;
6764
6765 -------------------
6766 -- Check_Variant --
6767 -------------------
6768
6769 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
6770 Clist : constant Node_Id := Component_List (Variant);
6771 Comp : Node_Id;
6772
6773 begin
6774 Comp := First_Non_Pragma (Component_Items (Clist));
6775 while Present (Comp) loop
6776 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
6777 Next_Non_Pragma (Comp);
6778 end loop;
6779 end Check_Variant;
6780
6781 ---------------------------
6782 -- Ensure_Aggregate_Form --
6783 ---------------------------
6784
6785 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
6786 CFSD : constant Boolean := Get_Comes_From_Source_Default;
6787 Expr : constant Node_Id := Expression (Arg);
6788 Loc : constant Source_Ptr := Sloc (Expr);
6789 Comps : List_Id := No_List;
6790 Exprs : List_Id := No_List;
6791 Nam : Name_Id := No_Name;
6792 Nam_Loc : Source_Ptr;
6793
6794 begin
6795 -- The pragma argument is in positional form:
6796
6797 -- pragma Depends (Nam => ...)
6798 -- ^
6799 -- Chars field
6800
6801 -- Note that the Sloc of the Chars field is the Sloc of the pragma
6802 -- argument association.
6803
6804 if Nkind (Arg) = N_Pragma_Argument_Association then
6805 Nam := Chars (Arg);
6806 Nam_Loc := Sloc (Arg);
6807
6808 -- Remove the pragma argument name as this will be captured in the
6809 -- aggregate.
6810
6811 Set_Chars (Arg, No_Name);
6812 end if;
6813
6814 -- The argument is already in aggregate form, but the presence of a
6815 -- name causes this to be interpreted as named association which in
6816 -- turn must be converted into an aggregate.
6817
6818 -- pragma Global (In_Out => (A, B, C))
6819 -- ^ ^
6820 -- name aggregate
6821
6822 -- pragma Global ((In_Out => (A, B, C)))
6823 -- ^ ^
6824 -- aggregate aggregate
6825
6826 if Nkind (Expr) = N_Aggregate then
6827 if Nam = No_Name then
6828 return;
6829 end if;
6830
6831 -- Do not transform a null argument into an aggregate as N_Null has
6832 -- special meaning in formal verification pragmas.
6833
6834 elsif Nkind (Expr) = N_Null then
6835 return;
6836 end if;
6837
6838 -- Everything comes from source if the original comes from source
6839
6840 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
6841
6842 -- Positional argument is transformed into an aggregate with an
6843 -- Expressions list.
6844
6845 if Nam = No_Name then
6846 Exprs := New_List (Relocate_Node (Expr));
6847
6848 -- An associative argument is transformed into an aggregate with
6849 -- Component_Associations.
6850
6851 else
6852 Comps := New_List (
6853 Make_Component_Association (Loc,
6854 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
6855 Expression => Relocate_Node (Expr)));
6856 end if;
6857
6858 Set_Expression (Arg,
6859 Make_Aggregate (Loc,
6860 Component_Associations => Comps,
6861 Expressions => Exprs));
6862
6863 -- Restore Comes_From_Source default
6864
6865 Set_Comes_From_Source_Default (CFSD);
6866 end Ensure_Aggregate_Form;
6867
6868 ------------------
6869 -- Error_Pragma --
6870 ------------------
6871
6872 procedure Error_Pragma (Msg : String) is
6873 begin
6874 Error_Msg_Name_1 := Pname;
6875 Error_Msg_N (Fix_Error (Msg), N);
6876 raise Pragma_Exit;
6877 end Error_Pragma;
6878
6879 ----------------------
6880 -- Error_Pragma_Arg --
6881 ----------------------
6882
6883 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
6884 begin
6885 Error_Msg_Name_1 := Pname;
6886 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
6887 raise Pragma_Exit;
6888 end Error_Pragma_Arg;
6889
6890 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
6891 begin
6892 Error_Msg_Name_1 := Pname;
6893 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
6894 Error_Pragma_Arg (Msg2, Arg);
6895 end Error_Pragma_Arg;
6896
6897 ----------------------------
6898 -- Error_Pragma_Arg_Ident --
6899 ----------------------------
6900
6901 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
6902 begin
6903 Error_Msg_Name_1 := Pname;
6904 Error_Msg_N (Fix_Error (Msg), Arg);
6905 raise Pragma_Exit;
6906 end Error_Pragma_Arg_Ident;
6907
6908 ----------------------
6909 -- Error_Pragma_Ref --
6910 ----------------------
6911
6912 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
6913 begin
6914 Error_Msg_Name_1 := Pname;
6915 Error_Msg_Sloc := Sloc (Ref);
6916 Error_Msg_NE (Fix_Error (Msg), N, Ref);
6917 raise Pragma_Exit;
6918 end Error_Pragma_Ref;
6919
6920 ------------------------
6921 -- Find_Lib_Unit_Name --
6922 ------------------------
6923
6924 function Find_Lib_Unit_Name return Entity_Id is
6925 begin
6926 -- Return inner compilation unit entity, for case of nested
6927 -- categorization pragmas. This happens in generic unit.
6928
6929 if Nkind (Parent (N)) = N_Package_Specification
6930 and then Defining_Entity (Parent (N)) /= Current_Scope
6931 then
6932 return Defining_Entity (Parent (N));
6933 else
6934 return Current_Scope;
6935 end if;
6936 end Find_Lib_Unit_Name;
6937
6938 ----------------------------
6939 -- Find_Program_Unit_Name --
6940 ----------------------------
6941
6942 procedure Find_Program_Unit_Name (Id : Node_Id) is
6943 Unit_Name : Entity_Id;
6944 Unit_Kind : Node_Kind;
6945 P : constant Node_Id := Parent (N);
6946
6947 begin
6948 if Nkind (P) = N_Compilation_Unit then
6949 Unit_Kind := Nkind (Unit (P));
6950
6951 if Nkind_In (Unit_Kind, N_Subprogram_Declaration,
6952 N_Package_Declaration)
6953 or else Unit_Kind in N_Generic_Declaration
6954 then
6955 Unit_Name := Defining_Entity (Unit (P));
6956
6957 if Chars (Id) = Chars (Unit_Name) then
6958 Set_Entity (Id, Unit_Name);
6959 Set_Etype (Id, Etype (Unit_Name));
6960 else
6961 Set_Etype (Id, Any_Type);
6962 Error_Pragma
6963 ("cannot find program unit referenced by pragma%");
6964 end if;
6965
6966 else
6967 Set_Etype (Id, Any_Type);
6968 Error_Pragma ("pragma% inapplicable to this unit");
6969 end if;
6970
6971 else
6972 Analyze (Id);
6973 end if;
6974 end Find_Program_Unit_Name;
6975
6976 -----------------------------------------
6977 -- Find_Unique_Parameterless_Procedure --
6978 -----------------------------------------
6979
6980 function Find_Unique_Parameterless_Procedure
6981 (Name : Entity_Id;
6982 Arg : Node_Id) return Entity_Id
6983 is
6984 Proc : Entity_Id := Empty;
6985
6986 begin
6987 -- The body of this procedure needs some comments ???
6988
6989 if not Is_Entity_Name (Name) then
6990 Error_Pragma_Arg
6991 ("argument of pragma% must be entity name", Arg);
6992
6993 elsif not Is_Overloaded (Name) then
6994 Proc := Entity (Name);
6995
6996 if Ekind (Proc) /= E_Procedure
6997 or else Present (First_Formal (Proc))
6998 then
6999 Error_Pragma_Arg
7000 ("argument of pragma% must be parameterless procedure", Arg);
7001 end if;
7002
7003 else
7004 declare
7005 Found : Boolean := False;
7006 It : Interp;
7007 Index : Interp_Index;
7008
7009 begin
7010 Get_First_Interp (Name, Index, It);
7011 while Present (It.Nam) loop
7012 Proc := It.Nam;
7013
7014 if Ekind (Proc) = E_Procedure
7015 and then No (First_Formal (Proc))
7016 then
7017 if not Found then
7018 Found := True;
7019 Set_Entity (Name, Proc);
7020 Set_Is_Overloaded (Name, False);
7021 else
7022 Error_Pragma_Arg
7023 ("ambiguous handler name for pragma% ", Arg);
7024 end if;
7025 end if;
7026
7027 Get_Next_Interp (Index, It);
7028 end loop;
7029
7030 if not Found then
7031 Error_Pragma_Arg
7032 ("argument of pragma% must be parameterless procedure",
7033 Arg);
7034 else
7035 Proc := Entity (Name);
7036 end if;
7037 end;
7038 end if;
7039
7040 return Proc;
7041 end Find_Unique_Parameterless_Procedure;
7042
7043 ---------------
7044 -- Fix_Error --
7045 ---------------
7046
7047 function Fix_Error (Msg : String) return String is
7048 Res : String (Msg'Range) := Msg;
7049 Res_Last : Natural := Msg'Last;
7050 J : Natural;
7051
7052 begin
7053 -- If we have a rewriting of another pragma, go to that pragma
7054
7055 if Is_Rewrite_Substitution (N)
7056 and then Nkind (Original_Node (N)) = N_Pragma
7057 then
7058 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
7059 end if;
7060
7061 -- Case where pragma comes from an aspect specification
7062
7063 if From_Aspect_Specification (N) then
7064
7065 -- Change appearence of "pragma" in message to "aspect"
7066
7067 J := Res'First;
7068 while J <= Res_Last - 5 loop
7069 if Res (J .. J + 5) = "pragma" then
7070 Res (J .. J + 5) := "aspect";
7071 J := J + 6;
7072
7073 else
7074 J := J + 1;
7075 end if;
7076 end loop;
7077
7078 -- Change "argument of" at start of message to "entity for"
7079
7080 if Res'Length > 11
7081 and then Res (Res'First .. Res'First + 10) = "argument of"
7082 then
7083 Res (Res'First .. Res'First + 9) := "entity for";
7084 Res (Res'First + 10 .. Res_Last - 1) :=
7085 Res (Res'First + 11 .. Res_Last);
7086 Res_Last := Res_Last - 1;
7087 end if;
7088
7089 -- Change "argument" at start of message to "entity"
7090
7091 if Res'Length > 8
7092 and then Res (Res'First .. Res'First + 7) = "argument"
7093 then
7094 Res (Res'First .. Res'First + 5) := "entity";
7095 Res (Res'First + 6 .. Res_Last - 2) :=
7096 Res (Res'First + 8 .. Res_Last);
7097 Res_Last := Res_Last - 2;
7098 end if;
7099
7100 -- Get name from corresponding aspect
7101
7102 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
7103 end if;
7104
7105 -- Return possibly modified message
7106
7107 return Res (Res'First .. Res_Last);
7108 end Fix_Error;
7109
7110 -------------------------
7111 -- Gather_Associations --
7112 -------------------------
7113
7114 procedure Gather_Associations
7115 (Names : Name_List;
7116 Args : out Args_List)
7117 is
7118 Arg : Node_Id;
7119
7120 begin
7121 -- Initialize all parameters to Empty
7122
7123 for J in Args'Range loop
7124 Args (J) := Empty;
7125 end loop;
7126
7127 -- That's all we have to do if there are no argument associations
7128
7129 if No (Pragma_Argument_Associations (N)) then
7130 return;
7131 end if;
7132
7133 -- Otherwise first deal with any positional parameters present
7134
7135 Arg := First (Pragma_Argument_Associations (N));
7136 for Index in Args'Range loop
7137 exit when No (Arg) or else Chars (Arg) /= No_Name;
7138 Args (Index) := Get_Pragma_Arg (Arg);
7139 Next (Arg);
7140 end loop;
7141
7142 -- Positional parameters all processed, if any left, then we
7143 -- have too many positional parameters.
7144
7145 if Present (Arg) and then Chars (Arg) = No_Name then
7146 Error_Pragma_Arg
7147 ("too many positional associations for pragma%", Arg);
7148 end if;
7149
7150 -- Process named parameters if any are present
7151
7152 while Present (Arg) loop
7153 if Chars (Arg) = No_Name then
7154 Error_Pragma_Arg
7155 ("positional association cannot follow named association",
7156 Arg);
7157
7158 else
7159 for Index in Names'Range loop
7160 if Names (Index) = Chars (Arg) then
7161 if Present (Args (Index)) then
7162 Error_Pragma_Arg
7163 ("duplicate argument association for pragma%", Arg);
7164 else
7165 Args (Index) := Get_Pragma_Arg (Arg);
7166 exit;
7167 end if;
7168 end if;
7169
7170 if Index = Names'Last then
7171 Error_Msg_Name_1 := Pname;
7172 Error_Msg_N ("pragma% does not allow & argument", Arg);
7173
7174 -- Check for possible misspelling
7175
7176 for Index1 in Names'Range loop
7177 if Is_Bad_Spelling_Of
7178 (Chars (Arg), Names (Index1))
7179 then
7180 Error_Msg_Name_1 := Names (Index1);
7181 Error_Msg_N -- CODEFIX
7182 ("\possible misspelling of%", Arg);
7183 exit;
7184 end if;
7185 end loop;
7186
7187 raise Pragma_Exit;
7188 end if;
7189 end loop;
7190 end if;
7191
7192 Next (Arg);
7193 end loop;
7194 end Gather_Associations;
7195
7196 -----------------
7197 -- GNAT_Pragma --
7198 -----------------
7199
7200 procedure GNAT_Pragma is
7201 begin
7202 -- We need to check the No_Implementation_Pragmas restriction for
7203 -- the case of a pragma from source. Note that the case of aspects
7204 -- generating corresponding pragmas marks these pragmas as not being
7205 -- from source, so this test also catches that case.
7206
7207 if Comes_From_Source (N) then
7208 Check_Restriction (No_Implementation_Pragmas, N);
7209 end if;
7210 end GNAT_Pragma;
7211
7212 --------------------------
7213 -- Is_Before_First_Decl --
7214 --------------------------
7215
7216 function Is_Before_First_Decl
7217 (Pragma_Node : Node_Id;
7218 Decls : List_Id) return Boolean
7219 is
7220 Item : Node_Id := First (Decls);
7221
7222 begin
7223 -- Only other pragmas can come before this pragma, but they might
7224 -- have been rewritten so check the original node.
7225
7226 loop
7227 if No (Item) or else Nkind (Original_Node (Item)) /= N_Pragma then
7228 return False;
7229
7230 elsif Item = Pragma_Node then
7231 return True;
7232 end if;
7233
7234 Next (Item);
7235 end loop;
7236 end Is_Before_First_Decl;
7237
7238 -----------------------------
7239 -- Is_Configuration_Pragma --
7240 -----------------------------
7241
7242 -- A configuration pragma must appear in the context clause of a
7243 -- compilation unit, and only other pragmas may precede it. Note that
7244 -- the test below also permits use in a configuration pragma file.
7245
7246 function Is_Configuration_Pragma return Boolean is
7247 Lis : constant List_Id := List_Containing (N);
7248 Par : constant Node_Id := Parent (N);
7249 Prg : Node_Id;
7250
7251 begin
7252 -- If no parent, then we are in the configuration pragma file,
7253 -- so the placement is definitely appropriate.
7254
7255 if No (Par) then
7256 return True;
7257
7258 -- Otherwise we must be in the context clause of a compilation unit
7259 -- and the only thing allowed before us in the context list is more
7260 -- configuration pragmas.
7261
7262 elsif Nkind (Par) = N_Compilation_Unit
7263 and then Context_Items (Par) = Lis
7264 then
7265 Prg := First (Lis);
7266
7267 loop
7268 if Prg = N then
7269 return True;
7270 elsif Nkind (Prg) /= N_Pragma then
7271 return False;
7272 end if;
7273
7274 Next (Prg);
7275 end loop;
7276
7277 else
7278 return False;
7279 end if;
7280 end Is_Configuration_Pragma;
7281
7282 --------------------------
7283 -- Is_In_Context_Clause --
7284 --------------------------
7285
7286 function Is_In_Context_Clause return Boolean is
7287 Plist : List_Id;
7288 Parent_Node : Node_Id;
7289
7290 begin
7291 if not Is_List_Member (N) then
7292 return False;
7293
7294 else
7295 Plist := List_Containing (N);
7296 Parent_Node := Parent (Plist);
7297
7298 if Parent_Node = Empty
7299 or else Nkind (Parent_Node) /= N_Compilation_Unit
7300 or else Context_Items (Parent_Node) /= Plist
7301 then
7302 return False;
7303 end if;
7304 end if;
7305
7306 return True;
7307 end Is_In_Context_Clause;
7308
7309 ---------------------------------
7310 -- Is_Static_String_Expression --
7311 ---------------------------------
7312
7313 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
7314 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
7315 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
7316
7317 begin
7318 Analyze_And_Resolve (Argx);
7319
7320 -- Special case Ada 83, where the expression will never be static,
7321 -- but we will return true if we had a string literal to start with.
7322
7323 if Ada_Version = Ada_83 then
7324 return Lit;
7325
7326 -- Normal case, true only if we end up with a string literal that
7327 -- is marked as being the result of evaluating a static expression.
7328
7329 else
7330 return Is_OK_Static_Expression (Argx)
7331 and then Nkind (Argx) = N_String_Literal;
7332 end if;
7333
7334 end Is_Static_String_Expression;
7335
7336 ----------------------
7337 -- Pragma_Misplaced --
7338 ----------------------
7339
7340 procedure Pragma_Misplaced is
7341 begin
7342 Error_Pragma ("incorrect placement of pragma%");
7343 end Pragma_Misplaced;
7344
7345 ------------------------------------------------
7346 -- Process_Atomic_Independent_Shared_Volatile --
7347 ------------------------------------------------
7348
7349 procedure Process_Atomic_Independent_Shared_Volatile is
7350 procedure Check_VFA_Conflicts (Ent : Entity_Id);
7351 -- Check that Volatile_Full_Access and VFA do not conflict
7352
7353 procedure Mark_Component_Or_Object (Ent : Entity_Id);
7354 -- Appropriately set flags on the given entity, either an array or
7355 -- record component, or an object declaration) according to the
7356 -- current pragma.
7357
7358 procedure Mark_Type (Ent : Entity_Id);
7359 -- Appropriately set flags on the given entity, a type
7360
7361 procedure Set_Atomic_VFA (Ent : Entity_Id);
7362 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
7363 -- no explicit alignment was given, set alignment to unknown, since
7364 -- back end knows what the alignment requirements are for atomic and
7365 -- full access arrays. Note: this is necessary for derived types.
7366
7367 -------------------------
7368 -- Check_VFA_Conflicts --
7369 -------------------------
7370
7371 procedure Check_VFA_Conflicts (Ent : Entity_Id) is
7372 Comp : Entity_Id;
7373 Typ : Entity_Id;
7374
7375 VFA_And_Atomic : Boolean := False;
7376 -- Set True if both VFA and Atomic present
7377
7378 begin
7379 -- Fetch the type in case we are dealing with an object or
7380 -- component.
7381
7382 if Is_Type (Ent) then
7383 Typ := Ent;
7384 else
7385 pragma Assert (Is_Object (Ent)
7386 or else
7387 Nkind (Declaration_Node (Ent)) = N_Component_Declaration);
7388
7389 Typ := Etype (Ent);
7390 end if;
7391
7392 -- Check Atomic and VFA used together
7393
7394 if Prag_Id = Pragma_Volatile_Full_Access
7395 or else Is_Volatile_Full_Access (Ent)
7396 then
7397 if Prag_Id = Pragma_Atomic
7398 or else Prag_Id = Pragma_Shared
7399 or else Is_Atomic (Ent)
7400 then
7401 VFA_And_Atomic := True;
7402
7403 elsif Is_Array_Type (Typ) then
7404 VFA_And_Atomic := Has_Atomic_Components (Typ);
7405
7406 -- Note: Has_Atomic_Components is not used below, as this flag
7407 -- represents the pragma of the same name, Atomic_Components,
7408 -- which only applies to arrays.
7409
7410 elsif Is_Record_Type (Typ) then
7411 -- Attributes cannot be applied to discriminants, only
7412 -- regular record components.
7413
7414 Comp := First_Component (Typ);
7415 while Present (Comp) loop
7416 if Is_Atomic (Comp)
7417 or else Is_Atomic (Typ)
7418 then
7419 VFA_And_Atomic := True;
7420
7421 exit;
7422 end if;
7423
7424 Next_Component (Comp);
7425 end loop;
7426 end if;
7427
7428 if VFA_And_Atomic then
7429 Error_Pragma
7430 ("cannot have Volatile_Full_Access and Atomic for same "
7431 & "entity");
7432 end if;
7433 end if;
7434 end Check_VFA_Conflicts;
7435
7436 ------------------------------
7437 -- Mark_Component_Or_Object --
7438 ------------------------------
7439
7440 procedure Mark_Component_Or_Object (Ent : Entity_Id) is
7441 begin
7442 if Prag_Id = Pragma_Atomic
7443 or else Prag_Id = Pragma_Shared
7444 or else Prag_Id = Pragma_Volatile_Full_Access
7445 then
7446 if Prag_Id = Pragma_Volatile_Full_Access then
7447 Set_Is_Volatile_Full_Access (Ent);
7448 else
7449 Set_Is_Atomic (Ent);
7450 end if;
7451
7452 -- If the object declaration has an explicit initialization, a
7453 -- temporary may have to be created to hold the expression, to
7454 -- ensure that access to the object remains atomic.
7455
7456 if Nkind (Parent (Ent)) = N_Object_Declaration
7457 and then Present (Expression (Parent (Ent)))
7458 then
7459 Set_Has_Delayed_Freeze (Ent);
7460 end if;
7461 end if;
7462
7463 -- Atomic/Shared/Volatile_Full_Access imply Independent
7464
7465 if Prag_Id /= Pragma_Volatile then
7466 Set_Is_Independent (Ent);
7467
7468 if Prag_Id = Pragma_Independent then
7469 Record_Independence_Check (N, Ent);
7470 end if;
7471 end if;
7472
7473 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7474
7475 if Prag_Id /= Pragma_Independent then
7476 Set_Is_Volatile (Ent);
7477 Set_Treat_As_Volatile (Ent);
7478 end if;
7479 end Mark_Component_Or_Object;
7480
7481 ---------------
7482 -- Mark_Type --
7483 ---------------
7484
7485 procedure Mark_Type (Ent : Entity_Id) is
7486 begin
7487 -- Attribute belongs on the base type. If the view of the type is
7488 -- currently private, it also belongs on the underlying type.
7489
7490 -- In Ada 2020, the pragma can apply to a formal type, for which
7491 -- there may be no underlying type.
7492
7493 if Prag_Id = Pragma_Atomic
7494 or else Prag_Id = Pragma_Shared
7495 or else Prag_Id = Pragma_Volatile_Full_Access
7496 then
7497 Set_Atomic_VFA (Ent);
7498 Set_Atomic_VFA (Base_Type (Ent));
7499
7500 if not Is_Generic_Type (Ent) then
7501 Set_Atomic_VFA (Underlying_Type (Ent));
7502 end if;
7503 end if;
7504
7505 -- Atomic/Shared/Volatile_Full_Access imply Independent
7506
7507 if Prag_Id /= Pragma_Volatile then
7508 Set_Is_Independent (Ent);
7509 Set_Is_Independent (Base_Type (Ent));
7510
7511 if not Is_Generic_Type (Ent) then
7512 Set_Is_Independent (Underlying_Type (Ent));
7513
7514 if Prag_Id = Pragma_Independent then
7515 Record_Independence_Check (N, Base_Type (Ent));
7516 end if;
7517 end if;
7518 end if;
7519
7520 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7521
7522 if Prag_Id /= Pragma_Independent then
7523 Set_Is_Volatile (Ent);
7524 Set_Is_Volatile (Base_Type (Ent));
7525
7526 if not Is_Generic_Type (Ent) then
7527 Set_Is_Volatile (Underlying_Type (Ent));
7528 Set_Treat_As_Volatile (Underlying_Type (Ent));
7529 end if;
7530
7531 Set_Treat_As_Volatile (Ent);
7532 end if;
7533
7534 -- Apply Volatile to the composite type's individual components,
7535 -- (RM C.6(8/3)).
7536
7537 if Prag_Id = Pragma_Volatile
7538 and then Is_Record_Type (Etype (Ent))
7539 then
7540 declare
7541 Comp : Entity_Id;
7542 begin
7543 Comp := First_Component (Ent);
7544 while Present (Comp) loop
7545 Mark_Component_Or_Object (Comp);
7546
7547 Next_Component (Comp);
7548 end loop;
7549 end;
7550 end if;
7551 end Mark_Type;
7552
7553 --------------------
7554 -- Set_Atomic_VFA --
7555 --------------------
7556
7557 procedure Set_Atomic_VFA (Ent : Entity_Id) is
7558 begin
7559 if Prag_Id = Pragma_Volatile_Full_Access then
7560 Set_Is_Volatile_Full_Access (Ent);
7561 else
7562 Set_Is_Atomic (Ent);
7563 end if;
7564
7565 if not Has_Alignment_Clause (Ent) then
7566 Set_Alignment (Ent, Uint_0);
7567 end if;
7568 end Set_Atomic_VFA;
7569
7570 -- Local variables
7571
7572 Decl : Node_Id;
7573 E : Entity_Id;
7574 E_Arg : Node_Id;
7575
7576 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
7577
7578 begin
7579 Check_Ada_83_Warning;
7580 Check_No_Identifiers;
7581 Check_Arg_Count (1);
7582 Check_Arg_Is_Local_Name (Arg1);
7583 E_Arg := Get_Pragma_Arg (Arg1);
7584
7585 if Etype (E_Arg) = Any_Type then
7586 return;
7587 end if;
7588
7589 E := Entity (E_Arg);
7590
7591 -- A pragma that applies to a Ghost entity becomes Ghost for the
7592 -- purposes of legality checks and removal of ignored Ghost code.
7593
7594 Mark_Ghost_Pragma (N, E);
7595
7596 -- Check duplicate before we chain ourselves
7597
7598 Check_Duplicate_Pragma (E);
7599
7600 -- Check appropriateness of the entity
7601
7602 Decl := Declaration_Node (E);
7603
7604 -- Deal with the case where the pragma/attribute is applied to a type
7605
7606 if Is_Type (E) then
7607 if Rep_Item_Too_Early (E, N)
7608 or else Rep_Item_Too_Late (E, N)
7609 then
7610 return;
7611 else
7612 Check_First_Subtype (Arg1);
7613 end if;
7614
7615 Mark_Type (E);
7616
7617 -- Deal with the case where the pragma/attribute applies to a
7618 -- component or object declaration.
7619
7620 elsif Nkind (Decl) = N_Object_Declaration
7621 or else (Nkind (Decl) = N_Component_Declaration
7622 and then Original_Record_Component (E) = E)
7623 then
7624 if Rep_Item_Too_Late (E, N) then
7625 return;
7626 end if;
7627
7628 Mark_Component_Or_Object (E);
7629
7630 -- In other cases give an error
7631
7632 else
7633 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7634 end if;
7635
7636 -- Check that Volatile_Full_Access and Atomic do not conflict
7637
7638 Check_VFA_Conflicts (E);
7639
7640 -- Check for the application of Atomic or Volatile_Full_Access to
7641 -- an entity that has [nonatomic] aliased, or else specified to be
7642 -- independently addressable, subcomponents.
7643
7644 if (Prag_Id = Pragma_Atomic and then Ada_Version >= Ada_2020)
7645 or else Prag_Id = Pragma_Volatile_Full_Access
7646 then
7647 Check_Atomic_VFA (E, VFA => Prag_Id = Pragma_Volatile_Full_Access);
7648 end if;
7649
7650 -- The following check is only relevant when SPARK_Mode is on as
7651 -- this is not a standard Ada legality rule. Pragma Volatile can
7652 -- only apply to a full type declaration or an object declaration
7653 -- (SPARK RM 7.1.3(2)). Original_Node is necessary to account for
7654 -- untagged derived types that are rewritten as subtypes of their
7655 -- respective root types.
7656
7657 if SPARK_Mode = On
7658 and then Prag_Id = Pragma_Volatile
7659 and then not Nkind_In (Original_Node (Decl),
7660 N_Full_Type_Declaration,
7661 N_Object_Declaration,
7662 N_Single_Protected_Declaration,
7663 N_Single_Task_Declaration)
7664 then
7665 Error_Pragma_Arg
7666 ("argument of pragma % must denote a full type or object "
7667 & "declaration", Arg1);
7668 end if;
7669 end Process_Atomic_Independent_Shared_Volatile;
7670
7671 -------------------------------------------
7672 -- Process_Compile_Time_Warning_Or_Error --
7673 -------------------------------------------
7674
7675 procedure Process_Compile_Time_Warning_Or_Error is
7676 P : Node_Id := Parent (N);
7677 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
7678
7679 begin
7680 Check_Arg_Count (2);
7681 Check_No_Identifiers;
7682 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
7683 Analyze_And_Resolve (Arg1x, Standard_Boolean);
7684
7685 -- In GNATprove mode, pragma Compile_Time_Error is translated as
7686 -- a Check pragma in GNATprove mode, handled as an assumption in
7687 -- GNATprove. This is correct as the compiler will issue an error
7688 -- if the condition cannot be statically evaluated to False.
7689 -- Compile_Time_Warning are ignored, as the analyzer may not have the
7690 -- same information as the compiler (in particular regarding size of
7691 -- objects decided in gigi) so it makes no sense to issue a warning
7692 -- in GNATprove.
7693
7694 if GNATprove_Mode then
7695 if Prag_Id = Pragma_Compile_Time_Error then
7696 declare
7697 New_Args : List_Id;
7698 begin
7699 -- Implement Compile_Time_Error by generating
7700 -- a corresponding Check pragma:
7701
7702 -- pragma Check (name, condition);
7703
7704 -- where name is the identifier matching the pragma name. So
7705 -- rewrite pragma in this manner and analyze the result.
7706
7707 New_Args := New_List
7708 (Make_Pragma_Argument_Association
7709 (Loc,
7710 Expression => Make_Identifier (Loc, Pname)),
7711 Make_Pragma_Argument_Association
7712 (Sloc (Arg1x),
7713 Expression => Arg1x));
7714
7715 -- Rewrite as Check pragma
7716
7717 Rewrite (N,
7718 Make_Pragma (Loc,
7719 Chars => Name_Check,
7720 Pragma_Argument_Associations => New_Args));
7721
7722 Analyze (N);
7723 end;
7724
7725 else
7726 Rewrite (N, Make_Null_Statement (Loc));
7727 end if;
7728
7729 return;
7730 end if;
7731
7732 -- If the condition is known at compile time (now), validate it now.
7733 -- Otherwise, register the expression for validation after the back
7734 -- end has been called, because it might be known at compile time
7735 -- then. For example, if the expression is "Record_Type'Size /= 32"
7736 -- it might be known after the back end has determined the size of
7737 -- Record_Type. We do not defer validation if we're inside a generic
7738 -- unit, because we will have more information in the instances.
7739
7740 if Compile_Time_Known_Value (Arg1x) then
7741 Validate_Compile_Time_Warning_Or_Error (N, Sloc (Arg1));
7742 else
7743 while Present (P) and then Nkind (P) not in N_Generic_Declaration
7744 loop
7745 if Nkind_In (P, N_Package_Body, N_Subprogram_Body) then
7746 P := Corresponding_Spec (P);
7747 else
7748 P := Parent (P);
7749 end if;
7750 end loop;
7751
7752 if No (P) then
7753 Defer_Compile_Time_Warning_Error_To_BE (N);
7754 end if;
7755 end if;
7756 end Process_Compile_Time_Warning_Or_Error;
7757
7758 ------------------------
7759 -- Process_Convention --
7760 ------------------------
7761
7762 procedure Process_Convention
7763 (C : out Convention_Id;
7764 Ent : out Entity_Id)
7765 is
7766 Cname : Name_Id;
7767
7768 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
7769 -- Called if we have more than one Export/Import/Convention pragma.
7770 -- This is generally illegal, but we have a special case of allowing
7771 -- Import and Interface to coexist if they specify the convention in
7772 -- a consistent manner. We are allowed to do this, since Interface is
7773 -- an implementation defined pragma, and we choose to do it since we
7774 -- know Rational allows this combination. S is the entity id of the
7775 -- subprogram in question. This procedure also sets the special flag
7776 -- Import_Interface_Present in both pragmas in the case where we do
7777 -- have matching Import and Interface pragmas.
7778
7779 procedure Set_Convention_From_Pragma (E : Entity_Id);
7780 -- Set convention in entity E, and also flag that the entity has a
7781 -- convention pragma. If entity is for a private or incomplete type,
7782 -- also set convention and flag on underlying type. This procedure
7783 -- also deals with the special case of C_Pass_By_Copy convention,
7784 -- and error checks for inappropriate convention specification.
7785
7786 -------------------------------
7787 -- Diagnose_Multiple_Pragmas --
7788 -------------------------------
7789
7790 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
7791 Pdec : constant Node_Id := Declaration_Node (S);
7792 Decl : Node_Id;
7793 Err : Boolean;
7794
7795 function Same_Convention (Decl : Node_Id) return Boolean;
7796 -- Decl is a pragma node. This function returns True if this
7797 -- pragma has a first argument that is an identifier with a
7798 -- Chars field corresponding to the Convention_Id C.
7799
7800 function Same_Name (Decl : Node_Id) return Boolean;
7801 -- Decl is a pragma node. This function returns True if this
7802 -- pragma has a second argument that is an identifier with a
7803 -- Chars field that matches the Chars of the current subprogram.
7804
7805 ---------------------
7806 -- Same_Convention --
7807 ---------------------
7808
7809 function Same_Convention (Decl : Node_Id) return Boolean is
7810 Arg1 : constant Node_Id :=
7811 First (Pragma_Argument_Associations (Decl));
7812
7813 begin
7814 if Present (Arg1) then
7815 declare
7816 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
7817 begin
7818 if Nkind (Arg) = N_Identifier
7819 and then Is_Convention_Name (Chars (Arg))
7820 and then Get_Convention_Id (Chars (Arg)) = C
7821 then
7822 return True;
7823 end if;
7824 end;
7825 end if;
7826
7827 return False;
7828 end Same_Convention;
7829
7830 ---------------
7831 -- Same_Name --
7832 ---------------
7833
7834 function Same_Name (Decl : Node_Id) return Boolean is
7835 Arg1 : constant Node_Id :=
7836 First (Pragma_Argument_Associations (Decl));
7837 Arg2 : Node_Id;
7838
7839 begin
7840 if No (Arg1) then
7841 return False;
7842 end if;
7843
7844 Arg2 := Next (Arg1);
7845
7846 if No (Arg2) then
7847 return False;
7848 end if;
7849
7850 declare
7851 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
7852 begin
7853 if Nkind (Arg) = N_Identifier
7854 and then Chars (Arg) = Chars (S)
7855 then
7856 return True;
7857 end if;
7858 end;
7859
7860 return False;
7861 end Same_Name;
7862
7863 -- Start of processing for Diagnose_Multiple_Pragmas
7864
7865 begin
7866 Err := True;
7867
7868 -- Definitely give message if we have Convention/Export here
7869
7870 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
7871 null;
7872
7873 -- If we have an Import or Export, scan back from pragma to
7874 -- find any previous pragma applying to the same procedure.
7875 -- The scan will be terminated by the start of the list, or
7876 -- hitting the subprogram declaration. This won't allow one
7877 -- pragma to appear in the public part and one in the private
7878 -- part, but that seems very unlikely in practice.
7879
7880 else
7881 Decl := Prev (N);
7882 while Present (Decl) and then Decl /= Pdec loop
7883
7884 -- Look for pragma with same name as us
7885
7886 if Nkind (Decl) = N_Pragma
7887 and then Same_Name (Decl)
7888 then
7889 -- Give error if same as our pragma or Export/Convention
7890
7891 if Nam_In (Pragma_Name_Unmapped (Decl),
7892 Name_Export,
7893 Name_Convention,
7894 Pragma_Name_Unmapped (N))
7895 then
7896 exit;
7897
7898 -- Case of Import/Interface or the other way round
7899
7900 elsif Nam_In (Pragma_Name_Unmapped (Decl),
7901 Name_Interface, Name_Import)
7902 then
7903 -- Here we know that we have Import and Interface. It
7904 -- doesn't matter which way round they are. See if
7905 -- they specify the same convention. If so, all OK,
7906 -- and set special flags to stop other messages
7907
7908 if Same_Convention (Decl) then
7909 Set_Import_Interface_Present (N);
7910 Set_Import_Interface_Present (Decl);
7911 Err := False;
7912
7913 -- If different conventions, special message
7914
7915 else
7916 Error_Msg_Sloc := Sloc (Decl);
7917 Error_Pragma_Arg
7918 ("convention differs from that given#", Arg1);
7919 return;
7920 end if;
7921 end if;
7922 end if;
7923
7924 Next (Decl);
7925 end loop;
7926 end if;
7927
7928 -- Give message if needed if we fall through those tests
7929 -- except on Relaxed_RM_Semantics where we let go: either this
7930 -- is a case accepted/ignored by other Ada compilers (e.g.
7931 -- a mix of Convention and Import), or another error will be
7932 -- generated later (e.g. using both Import and Export).
7933
7934 if Err and not Relaxed_RM_Semantics then
7935 Error_Pragma_Arg
7936 ("at most one Convention/Export/Import pragma is allowed",
7937 Arg2);
7938 end if;
7939 end Diagnose_Multiple_Pragmas;
7940
7941 --------------------------------
7942 -- Set_Convention_From_Pragma --
7943 --------------------------------
7944
7945 procedure Set_Convention_From_Pragma (E : Entity_Id) is
7946 begin
7947 -- Ada 2005 (AI-430): Check invalid attempt to change convention
7948 -- for an overridden dispatching operation. Technically this is
7949 -- an amendment and should only be done in Ada 2005 mode. However,
7950 -- this is clearly a mistake, since the problem that is addressed
7951 -- by this AI is that there is a clear gap in the RM.
7952
7953 if Is_Dispatching_Operation (E)
7954 and then Present (Overridden_Operation (E))
7955 and then C /= Convention (Overridden_Operation (E))
7956 then
7957 Error_Pragma_Arg
7958 ("cannot change convention for overridden dispatching "
7959 & "operation", Arg1);
7960 end if;
7961
7962 -- Special checks for Convention_Stdcall
7963
7964 if C = Convention_Stdcall then
7965
7966 -- A dispatching call is not allowed. A dispatching subprogram
7967 -- cannot be used to interface to the Win32 API, so in fact
7968 -- this check does not impose any effective restriction.
7969
7970 if Is_Dispatching_Operation (E) then
7971 Error_Msg_Sloc := Sloc (E);
7972
7973 -- Note: make this unconditional so that if there is more
7974 -- than one call to which the pragma applies, we get a
7975 -- message for each call. Also don't use Error_Pragma,
7976 -- so that we get multiple messages.
7977
7978 Error_Msg_N
7979 ("dispatching subprogram# cannot use Stdcall convention!",
7980 Arg1);
7981
7982 -- Several allowed cases
7983
7984 elsif Is_Subprogram_Or_Generic_Subprogram (E)
7985
7986 -- A variable is OK
7987
7988 or else Ekind (E) = E_Variable
7989
7990 -- A component as well. The entity does not have its Ekind
7991 -- set until the enclosing record declaration is fully
7992 -- analyzed.
7993
7994 or else Nkind (Parent (E)) = N_Component_Declaration
7995
7996 -- An access to subprogram is also allowed
7997
7998 or else
7999 (Is_Access_Type (E)
8000 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
8001
8002 -- Allow internal call to set convention of subprogram type
8003
8004 or else Ekind (E) = E_Subprogram_Type
8005 then
8006 null;
8007
8008 else
8009 Error_Pragma_Arg
8010 ("second argument of pragma% must be subprogram (type)",
8011 Arg2);
8012 end if;
8013 end if;
8014
8015 -- Set the convention
8016
8017 Set_Convention (E, C);
8018 Set_Has_Convention_Pragma (E);
8019
8020 -- For the case of a record base type, also set the convention of
8021 -- any anonymous access types declared in the record which do not
8022 -- currently have a specified convention.
8023
8024 if Is_Record_Type (E) and then Is_Base_Type (E) then
8025 declare
8026 Comp : Node_Id;
8027
8028 begin
8029 Comp := First_Component (E);
8030 while Present (Comp) loop
8031 if Present (Etype (Comp))
8032 and then Ekind_In (Etype (Comp),
8033 E_Anonymous_Access_Type,
8034 E_Anonymous_Access_Subprogram_Type)
8035 and then not Has_Convention_Pragma (Comp)
8036 then
8037 Set_Convention (Comp, C);
8038 end if;
8039
8040 Next_Component (Comp);
8041 end loop;
8042 end;
8043 end if;
8044
8045 -- Deal with incomplete/private type case, where underlying type
8046 -- is available, so set convention of that underlying type.
8047
8048 if Is_Incomplete_Or_Private_Type (E)
8049 and then Present (Underlying_Type (E))
8050 then
8051 Set_Convention (Underlying_Type (E), C);
8052 Set_Has_Convention_Pragma (Underlying_Type (E), True);
8053 end if;
8054
8055 -- A class-wide type should inherit the convention of the specific
8056 -- root type (although this isn't specified clearly by the RM).
8057
8058 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
8059 Set_Convention (Class_Wide_Type (E), C);
8060 end if;
8061
8062 -- If the entity is a record type, then check for special case of
8063 -- C_Pass_By_Copy, which is treated the same as C except that the
8064 -- special record flag is set. This convention is only permitted
8065 -- on record types (see AI95-00131).
8066
8067 if Cname = Name_C_Pass_By_Copy then
8068 if Is_Record_Type (E) then
8069 Set_C_Pass_By_Copy (Base_Type (E));
8070 elsif Is_Incomplete_Or_Private_Type (E)
8071 and then Is_Record_Type (Underlying_Type (E))
8072 then
8073 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
8074 else
8075 Error_Pragma_Arg
8076 ("C_Pass_By_Copy convention allowed only for record type",
8077 Arg2);
8078 end if;
8079 end if;
8080
8081 -- If the entity is a derived boolean type, check for the special
8082 -- case of convention C, C++, or Fortran, where we consider any
8083 -- nonzero value to represent true.
8084
8085 if Is_Discrete_Type (E)
8086 and then Root_Type (Etype (E)) = Standard_Boolean
8087 and then
8088 (C = Convention_C
8089 or else
8090 C = Convention_CPP
8091 or else
8092 C = Convention_Fortran)
8093 then
8094 Set_Nonzero_Is_True (Base_Type (E));
8095 end if;
8096 end Set_Convention_From_Pragma;
8097
8098 -- Local variables
8099
8100 Comp_Unit : Unit_Number_Type;
8101 E : Entity_Id;
8102 E1 : Entity_Id;
8103 Id : Node_Id;
8104
8105 -- Start of processing for Process_Convention
8106
8107 begin
8108 Check_At_Least_N_Arguments (2);
8109 Check_Optional_Identifier (Arg1, Name_Convention);
8110 Check_Arg_Is_Identifier (Arg1);
8111 Cname := Chars (Get_Pragma_Arg (Arg1));
8112
8113 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
8114 -- tested again below to set the critical flag).
8115
8116 if Cname = Name_C_Pass_By_Copy then
8117 C := Convention_C;
8118
8119 -- Otherwise we must have something in the standard convention list
8120
8121 elsif Is_Convention_Name (Cname) then
8122 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
8123
8124 -- Otherwise warn on unrecognized convention
8125
8126 else
8127 if Warn_On_Export_Import then
8128 Error_Msg_N
8129 ("??unrecognized convention name, C assumed",
8130 Get_Pragma_Arg (Arg1));
8131 end if;
8132
8133 C := Convention_C;
8134 end if;
8135
8136 Check_Optional_Identifier (Arg2, Name_Entity);
8137 Check_Arg_Is_Local_Name (Arg2);
8138
8139 Id := Get_Pragma_Arg (Arg2);
8140 Analyze (Id);
8141
8142 if not Is_Entity_Name (Id) then
8143 Error_Pragma_Arg ("entity name required", Arg2);
8144 end if;
8145
8146 E := Entity (Id);
8147
8148 -- Set entity to return
8149
8150 Ent := E;
8151
8152 -- Ada_Pass_By_Copy special checking
8153
8154 if C = Convention_Ada_Pass_By_Copy then
8155 if not Is_First_Subtype (E) then
8156 Error_Pragma_Arg
8157 ("convention `Ada_Pass_By_Copy` only allowed for types",
8158 Arg2);
8159 end if;
8160
8161 if Is_By_Reference_Type (E) then
8162 Error_Pragma_Arg
8163 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
8164 & "type", Arg1);
8165 end if;
8166
8167 -- Ada_Pass_By_Reference special checking
8168
8169 elsif C = Convention_Ada_Pass_By_Reference then
8170 if not Is_First_Subtype (E) then
8171 Error_Pragma_Arg
8172 ("convention `Ada_Pass_By_Reference` only allowed for types",
8173 Arg2);
8174 end if;
8175
8176 if Is_By_Copy_Type (E) then
8177 Error_Pragma_Arg
8178 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
8179 & "type", Arg1);
8180 end if;
8181 end if;
8182
8183 -- Go to renamed subprogram if present, since convention applies to
8184 -- the actual renamed entity, not to the renaming entity. If the
8185 -- subprogram is inherited, go to parent subprogram.
8186
8187 if Is_Subprogram (E)
8188 and then Present (Alias (E))
8189 then
8190 if Nkind (Parent (Declaration_Node (E))) =
8191 N_Subprogram_Renaming_Declaration
8192 then
8193 if Scope (E) /= Scope (Alias (E)) then
8194 Error_Pragma_Ref
8195 ("cannot apply pragma% to non-local entity&#", E);
8196 end if;
8197
8198 E := Alias (E);
8199
8200 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
8201 N_Private_Extension_Declaration)
8202 and then Scope (E) = Scope (Alias (E))
8203 then
8204 E := Alias (E);
8205
8206 -- Return the parent subprogram the entity was inherited from
8207
8208 Ent := E;
8209 end if;
8210 end if;
8211
8212 -- Check that we are not applying this to a specless body. Relax this
8213 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
8214
8215 if Is_Subprogram (E)
8216 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
8217 and then not Relaxed_RM_Semantics
8218 then
8219 Error_Pragma
8220 ("pragma% requires separate spec and must come before body");
8221 end if;
8222
8223 -- Check that we are not applying this to a named constant
8224
8225 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
8226 Error_Msg_Name_1 := Pname;
8227 Error_Msg_N
8228 ("cannot apply pragma% to named constant!",
8229 Get_Pragma_Arg (Arg2));
8230 Error_Pragma_Arg
8231 ("\supply appropriate type for&!", Arg2);
8232 end if;
8233
8234 if Ekind (E) = E_Enumeration_Literal then
8235 Error_Pragma ("enumeration literal not allowed for pragma%");
8236 end if;
8237
8238 -- Check for rep item appearing too early or too late
8239
8240 if Etype (E) = Any_Type
8241 or else Rep_Item_Too_Early (E, N)
8242 then
8243 raise Pragma_Exit;
8244
8245 elsif Present (Underlying_Type (E)) then
8246 E := Underlying_Type (E);
8247 end if;
8248
8249 if Rep_Item_Too_Late (E, N) then
8250 raise Pragma_Exit;
8251 end if;
8252
8253 if Has_Convention_Pragma (E) then
8254 Diagnose_Multiple_Pragmas (E);
8255
8256 elsif Convention (E) = Convention_Protected
8257 or else Ekind (Scope (E)) = E_Protected_Type
8258 then
8259 Error_Pragma_Arg
8260 ("a protected operation cannot be given a different convention",
8261 Arg2);
8262 end if;
8263
8264 -- For Intrinsic, a subprogram is required
8265
8266 if C = Convention_Intrinsic
8267 and then not Is_Subprogram_Or_Generic_Subprogram (E)
8268 then
8269 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
8270
8271 if not (Is_Type (E) and then Relaxed_RM_Semantics) then
8272 Error_Pragma_Arg
8273 ("second argument of pragma% must be a subprogram", Arg2);
8274 end if;
8275 end if;
8276
8277 -- Deal with non-subprogram cases
8278
8279 if not Is_Subprogram_Or_Generic_Subprogram (E) then
8280 Set_Convention_From_Pragma (E);
8281
8282 if Is_Type (E) then
8283
8284 -- The pragma must apply to a first subtype, but it can also
8285 -- apply to a generic type in a generic formal part, in which
8286 -- case it will also appear in the corresponding instance.
8287
8288 if Is_Generic_Type (E) or else In_Instance then
8289 null;
8290 else
8291 Check_First_Subtype (Arg2);
8292 end if;
8293
8294 Set_Convention_From_Pragma (Base_Type (E));
8295
8296 -- For access subprograms, we must set the convention on the
8297 -- internally generated directly designated type as well.
8298
8299 if Ekind (E) = E_Access_Subprogram_Type then
8300 Set_Convention_From_Pragma (Directly_Designated_Type (E));
8301 end if;
8302 end if;
8303
8304 -- For the subprogram case, set proper convention for all homonyms
8305 -- in same scope and the same declarative part, i.e. the same
8306 -- compilation unit.
8307
8308 else
8309 Comp_Unit := Get_Source_Unit (E);
8310 Set_Convention_From_Pragma (E);
8311
8312 -- Treat a pragma Import as an implicit body, and pragma import
8313 -- as implicit reference (for navigation in GNAT Studio).
8314
8315 if Prag_Id = Pragma_Import then
8316 Generate_Reference (E, Id, 'b');
8317
8318 -- For exported entities we restrict the generation of references
8319 -- to entities exported to foreign languages since entities
8320 -- exported to Ada do not provide further information to
8321 -- GNAT Studio and add undesired references to the output of the
8322 -- gnatxref tool.
8323
8324 elsif Prag_Id = Pragma_Export
8325 and then Convention (E) /= Convention_Ada
8326 then
8327 Generate_Reference (E, Id, 'i');
8328 end if;
8329
8330 -- If the pragma comes from an aspect, it only applies to the
8331 -- given entity, not its homonyms.
8332
8333 if From_Aspect_Specification (N) then
8334 if C = Convention_Intrinsic
8335 and then Nkind (Ent) = N_Defining_Operator_Symbol
8336 then
8337 if Is_Fixed_Point_Type (Etype (Ent))
8338 or else Is_Fixed_Point_Type (Etype (First_Entity (Ent)))
8339 or else Is_Fixed_Point_Type (Etype (Last_Entity (Ent)))
8340 then
8341 Error_Msg_N
8342 ("no intrinsic operator available for this fixed-point "
8343 & "operation", N);
8344 Error_Msg_N
8345 ("\use expression functions with the desired "
8346 & "conversions made explicit", N);
8347 end if;
8348 end if;
8349
8350 return;
8351 end if;
8352
8353 -- Otherwise Loop through the homonyms of the pragma argument's
8354 -- entity, an apply convention to those in the current scope.
8355
8356 E1 := Ent;
8357
8358 loop
8359 E1 := Homonym (E1);
8360 exit when No (E1) or else Scope (E1) /= Current_Scope;
8361
8362 -- Ignore entry for which convention is already set
8363
8364 if Has_Convention_Pragma (E1) then
8365 goto Continue;
8366 end if;
8367
8368 if Is_Subprogram (E1)
8369 and then Nkind (Parent (Declaration_Node (E1))) =
8370 N_Subprogram_Body
8371 and then not Relaxed_RM_Semantics
8372 then
8373 Set_Has_Completion (E); -- to prevent cascaded error
8374 Error_Pragma_Ref
8375 ("pragma% requires separate spec and must come before "
8376 & "body#", E1);
8377 end if;
8378
8379 -- Do not set the pragma on inherited operations or on formal
8380 -- subprograms.
8381
8382 if Comes_From_Source (E1)
8383 and then Comp_Unit = Get_Source_Unit (E1)
8384 and then not Is_Formal_Subprogram (E1)
8385 and then Nkind (Original_Node (Parent (E1))) /=
8386 N_Full_Type_Declaration
8387 then
8388 if Present (Alias (E1))
8389 and then Scope (E1) /= Scope (Alias (E1))
8390 then
8391 Error_Pragma_Ref
8392 ("cannot apply pragma% to non-local entity& declared#",
8393 E1);
8394 end if;
8395
8396 Set_Convention_From_Pragma (E1);
8397
8398 if Prag_Id = Pragma_Import then
8399 Generate_Reference (E1, Id, 'b');
8400 end if;
8401 end if;
8402
8403 <<Continue>>
8404 null;
8405 end loop;
8406 end if;
8407 end Process_Convention;
8408
8409 ----------------------------------------
8410 -- Process_Disable_Enable_Atomic_Sync --
8411 ----------------------------------------
8412
8413 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
8414 begin
8415 Check_No_Identifiers;
8416 Check_At_Most_N_Arguments (1);
8417
8418 -- Modeled internally as
8419 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
8420
8421 Rewrite (N,
8422 Make_Pragma (Loc,
8423 Chars => Nam,
8424 Pragma_Argument_Associations => New_List (
8425 Make_Pragma_Argument_Association (Loc,
8426 Expression =>
8427 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
8428
8429 if Present (Arg1) then
8430 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
8431 end if;
8432
8433 Analyze (N);
8434 end Process_Disable_Enable_Atomic_Sync;
8435
8436 -------------------------------------------------
8437 -- Process_Extended_Import_Export_Internal_Arg --
8438 -------------------------------------------------
8439
8440 procedure Process_Extended_Import_Export_Internal_Arg
8441 (Arg_Internal : Node_Id := Empty)
8442 is
8443 begin
8444 if No (Arg_Internal) then
8445 Error_Pragma ("Internal parameter required for pragma%");
8446 end if;
8447
8448 if Nkind (Arg_Internal) = N_Identifier then
8449 null;
8450
8451 elsif Nkind (Arg_Internal) = N_Operator_Symbol
8452 and then (Prag_Id = Pragma_Import_Function
8453 or else
8454 Prag_Id = Pragma_Export_Function)
8455 then
8456 null;
8457
8458 else
8459 Error_Pragma_Arg
8460 ("wrong form for Internal parameter for pragma%", Arg_Internal);
8461 end if;
8462
8463 Check_Arg_Is_Local_Name (Arg_Internal);
8464 end Process_Extended_Import_Export_Internal_Arg;
8465
8466 --------------------------------------------------
8467 -- Process_Extended_Import_Export_Object_Pragma --
8468 --------------------------------------------------
8469
8470 procedure Process_Extended_Import_Export_Object_Pragma
8471 (Arg_Internal : Node_Id;
8472 Arg_External : Node_Id;
8473 Arg_Size : Node_Id)
8474 is
8475 Def_Id : Entity_Id;
8476
8477 begin
8478 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8479 Def_Id := Entity (Arg_Internal);
8480
8481 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
8482 Error_Pragma_Arg
8483 ("pragma% must designate an object", Arg_Internal);
8484 end if;
8485
8486 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
8487 or else
8488 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
8489 then
8490 Error_Pragma_Arg
8491 ("previous Common/Psect_Object applies, pragma % not permitted",
8492 Arg_Internal);
8493 end if;
8494
8495 if Rep_Item_Too_Late (Def_Id, N) then
8496 raise Pragma_Exit;
8497 end if;
8498
8499 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
8500
8501 if Present (Arg_Size) then
8502 Check_Arg_Is_External_Name (Arg_Size);
8503 end if;
8504
8505 -- Export_Object case
8506
8507 if Prag_Id = Pragma_Export_Object then
8508 if not Is_Library_Level_Entity (Def_Id) then
8509 Error_Pragma_Arg
8510 ("argument for pragma% must be library level entity",
8511 Arg_Internal);
8512 end if;
8513
8514 if Ekind (Current_Scope) = E_Generic_Package then
8515 Error_Pragma ("pragma& cannot appear in a generic unit");
8516 end if;
8517
8518 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
8519 Error_Pragma_Arg
8520 ("exported object must have compile time known size",
8521 Arg_Internal);
8522 end if;
8523
8524 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
8525 Error_Msg_N ("??duplicate Export_Object pragma", N);
8526 else
8527 Set_Exported (Def_Id, Arg_Internal);
8528 end if;
8529
8530 -- Import_Object case
8531
8532 else
8533 if Is_Concurrent_Type (Etype (Def_Id)) then
8534 Error_Pragma_Arg
8535 ("cannot use pragma% for task/protected object",
8536 Arg_Internal);
8537 end if;
8538
8539 if Ekind (Def_Id) = E_Constant then
8540 Error_Pragma_Arg
8541 ("cannot import a constant", Arg_Internal);
8542 end if;
8543
8544 if Warn_On_Export_Import
8545 and then Has_Discriminants (Etype (Def_Id))
8546 then
8547 Error_Msg_N
8548 ("imported value must be initialized??", Arg_Internal);
8549 end if;
8550
8551 if Warn_On_Export_Import
8552 and then Is_Access_Type (Etype (Def_Id))
8553 then
8554 Error_Pragma_Arg
8555 ("cannot import object of an access type??", Arg_Internal);
8556 end if;
8557
8558 if Warn_On_Export_Import
8559 and then Is_Imported (Def_Id)
8560 then
8561 Error_Msg_N ("??duplicate Import_Object pragma", N);
8562
8563 -- Check for explicit initialization present. Note that an
8564 -- initialization generated by the code generator, e.g. for an
8565 -- access type, does not count here.
8566
8567 elsif Present (Expression (Parent (Def_Id)))
8568 and then
8569 Comes_From_Source
8570 (Original_Node (Expression (Parent (Def_Id))))
8571 then
8572 Error_Msg_Sloc := Sloc (Def_Id);
8573 Error_Pragma_Arg
8574 ("imported entities cannot be initialized (RM B.1(24))",
8575 "\no initialization allowed for & declared#", Arg1);
8576 else
8577 Set_Imported (Def_Id);
8578 Note_Possible_Modification (Arg_Internal, Sure => False);
8579 end if;
8580 end if;
8581 end Process_Extended_Import_Export_Object_Pragma;
8582
8583 ------------------------------------------------------
8584 -- Process_Extended_Import_Export_Subprogram_Pragma --
8585 ------------------------------------------------------
8586
8587 procedure Process_Extended_Import_Export_Subprogram_Pragma
8588 (Arg_Internal : Node_Id;
8589 Arg_External : Node_Id;
8590 Arg_Parameter_Types : Node_Id;
8591 Arg_Result_Type : Node_Id := Empty;
8592 Arg_Mechanism : Node_Id;
8593 Arg_Result_Mechanism : Node_Id := Empty)
8594 is
8595 Ent : Entity_Id;
8596 Def_Id : Entity_Id;
8597 Hom_Id : Entity_Id;
8598 Formal : Entity_Id;
8599 Ambiguous : Boolean;
8600 Match : Boolean;
8601
8602 function Same_Base_Type
8603 (Ptype : Node_Id;
8604 Formal : Entity_Id) return Boolean;
8605 -- Determines if Ptype references the type of Formal. Note that only
8606 -- the base types need to match according to the spec. Ptype here is
8607 -- the argument from the pragma, which is either a type name, or an
8608 -- access attribute.
8609
8610 --------------------
8611 -- Same_Base_Type --
8612 --------------------
8613
8614 function Same_Base_Type
8615 (Ptype : Node_Id;
8616 Formal : Entity_Id) return Boolean
8617 is
8618 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
8619 Pref : Node_Id;
8620
8621 begin
8622 -- Case where pragma argument is typ'Access
8623
8624 if Nkind (Ptype) = N_Attribute_Reference
8625 and then Attribute_Name (Ptype) = Name_Access
8626 then
8627 Pref := Prefix (Ptype);
8628 Find_Type (Pref);
8629
8630 if not Is_Entity_Name (Pref)
8631 or else Entity (Pref) = Any_Type
8632 then
8633 raise Pragma_Exit;
8634 end if;
8635
8636 -- We have a match if the corresponding argument is of an
8637 -- anonymous access type, and its designated type matches the
8638 -- type of the prefix of the access attribute
8639
8640 return Ekind (Ftyp) = E_Anonymous_Access_Type
8641 and then Base_Type (Entity (Pref)) =
8642 Base_Type (Etype (Designated_Type (Ftyp)));
8643
8644 -- Case where pragma argument is a type name
8645
8646 else
8647 Find_Type (Ptype);
8648
8649 if not Is_Entity_Name (Ptype)
8650 or else Entity (Ptype) = Any_Type
8651 then
8652 raise Pragma_Exit;
8653 end if;
8654
8655 -- We have a match if the corresponding argument is of the type
8656 -- given in the pragma (comparing base types)
8657
8658 return Base_Type (Entity (Ptype)) = Ftyp;
8659 end if;
8660 end Same_Base_Type;
8661
8662 -- Start of processing for
8663 -- Process_Extended_Import_Export_Subprogram_Pragma
8664
8665 begin
8666 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8667 Ent := Empty;
8668 Ambiguous := False;
8669
8670 -- Loop through homonyms (overloadings) of the entity
8671
8672 Hom_Id := Entity (Arg_Internal);
8673 while Present (Hom_Id) loop
8674 Def_Id := Get_Base_Subprogram (Hom_Id);
8675
8676 -- We need a subprogram in the current scope
8677
8678 if not Is_Subprogram (Def_Id)
8679 or else Scope (Def_Id) /= Current_Scope
8680 then
8681 null;
8682
8683 else
8684 Match := True;
8685
8686 -- Pragma cannot apply to subprogram body
8687
8688 if Is_Subprogram (Def_Id)
8689 and then Nkind (Parent (Declaration_Node (Def_Id))) =
8690 N_Subprogram_Body
8691 then
8692 Error_Pragma
8693 ("pragma% requires separate spec and must come before "
8694 & "body");
8695 end if;
8696
8697 -- Test result type if given, note that the result type
8698 -- parameter can only be present for the function cases.
8699
8700 if Present (Arg_Result_Type)
8701 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
8702 then
8703 Match := False;
8704
8705 elsif Etype (Def_Id) /= Standard_Void_Type
8706 and then Nam_In (Pname, Name_Export_Procedure,
8707 Name_Import_Procedure)
8708 then
8709 Match := False;
8710
8711 -- Test parameter types if given. Note that this parameter has
8712 -- not been analyzed (and must not be, since it is semantic
8713 -- nonsense), so we get it as the parser left it.
8714
8715 elsif Present (Arg_Parameter_Types) then
8716 Check_Matching_Types : declare
8717 Formal : Entity_Id;
8718 Ptype : Node_Id;
8719
8720 begin
8721 Formal := First_Formal (Def_Id);
8722
8723 if Nkind (Arg_Parameter_Types) = N_Null then
8724 if Present (Formal) then
8725 Match := False;
8726 end if;
8727
8728 -- A list of one type, e.g. (List) is parsed as a
8729 -- parenthesized expression.
8730
8731 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
8732 and then Paren_Count (Arg_Parameter_Types) = 1
8733 then
8734 if No (Formal)
8735 or else Present (Next_Formal (Formal))
8736 then
8737 Match := False;
8738 else
8739 Match :=
8740 Same_Base_Type (Arg_Parameter_Types, Formal);
8741 end if;
8742
8743 -- A list of more than one type is parsed as a aggregate
8744
8745 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
8746 and then Paren_Count (Arg_Parameter_Types) = 0
8747 then
8748 Ptype := First (Expressions (Arg_Parameter_Types));
8749 while Present (Ptype) or else Present (Formal) loop
8750 if No (Ptype)
8751 or else No (Formal)
8752 or else not Same_Base_Type (Ptype, Formal)
8753 then
8754 Match := False;
8755 exit;
8756 else
8757 Next_Formal (Formal);
8758 Next (Ptype);
8759 end if;
8760 end loop;
8761
8762 -- Anything else is of the wrong form
8763
8764 else
8765 Error_Pragma_Arg
8766 ("wrong form for Parameter_Types parameter",
8767 Arg_Parameter_Types);
8768 end if;
8769 end Check_Matching_Types;
8770 end if;
8771
8772 -- Match is now False if the entry we found did not match
8773 -- either a supplied Parameter_Types or Result_Types argument
8774
8775 if Match then
8776 if No (Ent) then
8777 Ent := Def_Id;
8778
8779 -- Ambiguous case, the flag Ambiguous shows if we already
8780 -- detected this and output the initial messages.
8781
8782 else
8783 if not Ambiguous then
8784 Ambiguous := True;
8785 Error_Msg_Name_1 := Pname;
8786 Error_Msg_N
8787 ("pragma% does not uniquely identify subprogram!",
8788 N);
8789 Error_Msg_Sloc := Sloc (Ent);
8790 Error_Msg_N ("matching subprogram #!", N);
8791 Ent := Empty;
8792 end if;
8793
8794 Error_Msg_Sloc := Sloc (Def_Id);
8795 Error_Msg_N ("matching subprogram #!", N);
8796 end if;
8797 end if;
8798 end if;
8799
8800 Hom_Id := Homonym (Hom_Id);
8801 end loop;
8802
8803 -- See if we found an entry
8804
8805 if No (Ent) then
8806 if not Ambiguous then
8807 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
8808 Error_Pragma
8809 ("pragma% cannot be given for generic subprogram");
8810 else
8811 Error_Pragma
8812 ("pragma% does not identify local subprogram");
8813 end if;
8814 end if;
8815
8816 return;
8817 end if;
8818
8819 -- Import pragmas must be for imported entities
8820
8821 if Prag_Id = Pragma_Import_Function
8822 or else
8823 Prag_Id = Pragma_Import_Procedure
8824 or else
8825 Prag_Id = Pragma_Import_Valued_Procedure
8826 then
8827 if not Is_Imported (Ent) then
8828 Error_Pragma
8829 ("pragma Import or Interface must precede pragma%");
8830 end if;
8831
8832 -- Here we have the Export case which can set the entity as exported
8833
8834 -- But does not do so if the specified external name is null, since
8835 -- that is taken as a signal in DEC Ada 83 (with which we want to be
8836 -- compatible) to request no external name.
8837
8838 elsif Nkind (Arg_External) = N_String_Literal
8839 and then String_Length (Strval (Arg_External)) = 0
8840 then
8841 null;
8842
8843 -- In all other cases, set entity as exported
8844
8845 else
8846 Set_Exported (Ent, Arg_Internal);
8847 end if;
8848
8849 -- Special processing for Valued_Procedure cases
8850
8851 if Prag_Id = Pragma_Import_Valued_Procedure
8852 or else
8853 Prag_Id = Pragma_Export_Valued_Procedure
8854 then
8855 Formal := First_Formal (Ent);
8856
8857 if No (Formal) then
8858 Error_Pragma ("at least one parameter required for pragma%");
8859
8860 elsif Ekind (Formal) /= E_Out_Parameter then
8861 Error_Pragma ("first parameter must have mode out for pragma%");
8862
8863 else
8864 Set_Is_Valued_Procedure (Ent);
8865 end if;
8866 end if;
8867
8868 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
8869
8870 -- Process Result_Mechanism argument if present. We have already
8871 -- checked that this is only allowed for the function case.
8872
8873 if Present (Arg_Result_Mechanism) then
8874 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
8875 end if;
8876
8877 -- Process Mechanism parameter if present. Note that this parameter
8878 -- is not analyzed, and must not be analyzed since it is semantic
8879 -- nonsense, so we get it in exactly as the parser left it.
8880
8881 if Present (Arg_Mechanism) then
8882 declare
8883 Formal : Entity_Id;
8884 Massoc : Node_Id;
8885 Mname : Node_Id;
8886 Choice : Node_Id;
8887
8888 begin
8889 -- A single mechanism association without a formal parameter
8890 -- name is parsed as a parenthesized expression. All other
8891 -- cases are parsed as aggregates, so we rewrite the single
8892 -- parameter case as an aggregate for consistency.
8893
8894 if Nkind (Arg_Mechanism) /= N_Aggregate
8895 and then Paren_Count (Arg_Mechanism) = 1
8896 then
8897 Rewrite (Arg_Mechanism,
8898 Make_Aggregate (Sloc (Arg_Mechanism),
8899 Expressions => New_List (
8900 Relocate_Node (Arg_Mechanism))));
8901 end if;
8902
8903 -- Case of only mechanism name given, applies to all formals
8904
8905 if Nkind (Arg_Mechanism) /= N_Aggregate then
8906 Formal := First_Formal (Ent);
8907 while Present (Formal) loop
8908 Set_Mechanism_Value (Formal, Arg_Mechanism);
8909 Next_Formal (Formal);
8910 end loop;
8911
8912 -- Case of list of mechanism associations given
8913
8914 else
8915 if Null_Record_Present (Arg_Mechanism) then
8916 Error_Pragma_Arg
8917 ("inappropriate form for Mechanism parameter",
8918 Arg_Mechanism);
8919 end if;
8920
8921 -- Deal with positional ones first
8922
8923 Formal := First_Formal (Ent);
8924
8925 if Present (Expressions (Arg_Mechanism)) then
8926 Mname := First (Expressions (Arg_Mechanism));
8927 while Present (Mname) loop
8928 if No (Formal) then
8929 Error_Pragma_Arg
8930 ("too many mechanism associations", Mname);
8931 end if;
8932
8933 Set_Mechanism_Value (Formal, Mname);
8934 Next_Formal (Formal);
8935 Next (Mname);
8936 end loop;
8937 end if;
8938
8939 -- Deal with named entries
8940
8941 if Present (Component_Associations (Arg_Mechanism)) then
8942 Massoc := First (Component_Associations (Arg_Mechanism));
8943 while Present (Massoc) loop
8944 Choice := First (Choices (Massoc));
8945
8946 if Nkind (Choice) /= N_Identifier
8947 or else Present (Next (Choice))
8948 then
8949 Error_Pragma_Arg
8950 ("incorrect form for mechanism association",
8951 Massoc);
8952 end if;
8953
8954 Formal := First_Formal (Ent);
8955 loop
8956 if No (Formal) then
8957 Error_Pragma_Arg
8958 ("parameter name & not present", Choice);
8959 end if;
8960
8961 if Chars (Choice) = Chars (Formal) then
8962 Set_Mechanism_Value
8963 (Formal, Expression (Massoc));
8964
8965 -- Set entity on identifier for proper tree
8966 -- structure.
8967
8968 Set_Entity (Choice, Formal);
8969
8970 exit;
8971 end if;
8972
8973 Next_Formal (Formal);
8974 end loop;
8975
8976 Next (Massoc);
8977 end loop;
8978 end if;
8979 end if;
8980 end;
8981 end if;
8982 end Process_Extended_Import_Export_Subprogram_Pragma;
8983
8984 --------------------------
8985 -- Process_Generic_List --
8986 --------------------------
8987
8988 procedure Process_Generic_List is
8989 Arg : Node_Id;
8990 Exp : Node_Id;
8991
8992 begin
8993 Check_No_Identifiers;
8994 Check_At_Least_N_Arguments (1);
8995
8996 -- Check all arguments are names of generic units or instances
8997
8998 Arg := Arg1;
8999 while Present (Arg) loop
9000 Exp := Get_Pragma_Arg (Arg);
9001 Analyze (Exp);
9002
9003 if not Is_Entity_Name (Exp)
9004 or else
9005 (not Is_Generic_Instance (Entity (Exp))
9006 and then
9007 not Is_Generic_Unit (Entity (Exp)))
9008 then
9009 Error_Pragma_Arg
9010 ("pragma% argument must be name of generic unit/instance",
9011 Arg);
9012 end if;
9013
9014 Next (Arg);
9015 end loop;
9016 end Process_Generic_List;
9017
9018 ------------------------------------
9019 -- Process_Import_Predefined_Type --
9020 ------------------------------------
9021
9022 procedure Process_Import_Predefined_Type is
9023 Loc : constant Source_Ptr := Sloc (N);
9024 Elmt : Elmt_Id;
9025 Ftyp : Node_Id := Empty;
9026 Decl : Node_Id;
9027 Def : Node_Id;
9028 Nam : Name_Id;
9029
9030 begin
9031 Nam := String_To_Name (Strval (Expression (Arg3)));
9032
9033 Elmt := First_Elmt (Predefined_Float_Types);
9034 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
9035 Next_Elmt (Elmt);
9036 end loop;
9037
9038 Ftyp := Node (Elmt);
9039
9040 if Present (Ftyp) then
9041
9042 -- Don't build a derived type declaration, because predefined C
9043 -- types have no declaration anywhere, so cannot really be named.
9044 -- Instead build a full type declaration, starting with an
9045 -- appropriate type definition is built
9046
9047 if Is_Floating_Point_Type (Ftyp) then
9048 Def := Make_Floating_Point_Definition (Loc,
9049 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
9050 Make_Real_Range_Specification (Loc,
9051 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
9052 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
9053
9054 -- Should never have a predefined type we cannot handle
9055
9056 else
9057 raise Program_Error;
9058 end if;
9059
9060 -- Build and insert a Full_Type_Declaration, which will be
9061 -- analyzed as soon as this list entry has been analyzed.
9062
9063 Decl := Make_Full_Type_Declaration (Loc,
9064 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
9065 Type_Definition => Def);
9066
9067 Insert_After (N, Decl);
9068 Mark_Rewrite_Insertion (Decl);
9069
9070 else
9071 Error_Pragma_Arg ("no matching type found for pragma%", Arg2);
9072 end if;
9073 end Process_Import_Predefined_Type;
9074
9075 ---------------------------------
9076 -- Process_Import_Or_Interface --
9077 ---------------------------------
9078
9079 procedure Process_Import_Or_Interface is
9080 C : Convention_Id;
9081 Def_Id : Entity_Id;
9082 Hom_Id : Entity_Id;
9083
9084 begin
9085 -- In Relaxed_RM_Semantics, support old Ada 83 style:
9086 -- pragma Import (Entity, "external name");
9087
9088 if Relaxed_RM_Semantics
9089 and then Arg_Count = 2
9090 and then Prag_Id = Pragma_Import
9091 and then Nkind (Expression (Arg2)) = N_String_Literal
9092 then
9093 C := Convention_C;
9094 Def_Id := Get_Pragma_Arg (Arg1);
9095 Analyze (Def_Id);
9096
9097 if not Is_Entity_Name (Def_Id) then
9098 Error_Pragma_Arg ("entity name required", Arg1);
9099 end if;
9100
9101 Def_Id := Entity (Def_Id);
9102 Kill_Size_Check_Code (Def_Id);
9103 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
9104
9105 else
9106 Process_Convention (C, Def_Id);
9107
9108 -- A pragma that applies to a Ghost entity becomes Ghost for the
9109 -- purposes of legality checks and removal of ignored Ghost code.
9110
9111 Mark_Ghost_Pragma (N, Def_Id);
9112 Kill_Size_Check_Code (Def_Id);
9113 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
9114 end if;
9115
9116 -- Various error checks
9117
9118 if Ekind_In (Def_Id, E_Variable, E_Constant) then
9119
9120 -- We do not permit Import to apply to a renaming declaration
9121
9122 if Present (Renamed_Object (Def_Id)) then
9123 Error_Pragma_Arg
9124 ("pragma% not allowed for object renaming", Arg2);
9125
9126 -- User initialization is not allowed for imported object, but
9127 -- the object declaration may contain a default initialization,
9128 -- that will be discarded. Note that an explicit initialization
9129 -- only counts if it comes from source, otherwise it is simply
9130 -- the code generator making an implicit initialization explicit.
9131
9132 elsif Present (Expression (Parent (Def_Id)))
9133 and then Comes_From_Source
9134 (Original_Node (Expression (Parent (Def_Id))))
9135 then
9136 -- Set imported flag to prevent cascaded errors
9137
9138 Set_Is_Imported (Def_Id);
9139
9140 Error_Msg_Sloc := Sloc (Def_Id);
9141 Error_Pragma_Arg
9142 ("no initialization allowed for declaration of& #",
9143 "\imported entities cannot be initialized (RM B.1(24))",
9144 Arg2);
9145
9146 else
9147 -- If the pragma comes from an aspect specification the
9148 -- Is_Imported flag has already been set.
9149
9150 if not From_Aspect_Specification (N) then
9151 Set_Imported (Def_Id);
9152 end if;
9153
9154 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9155
9156 -- Note that we do not set Is_Public here. That's because we
9157 -- only want to set it if there is no address clause, and we
9158 -- don't know that yet, so we delay that processing till
9159 -- freeze time.
9160
9161 -- pragma Import completes deferred constants
9162
9163 if Ekind (Def_Id) = E_Constant then
9164 Set_Has_Completion (Def_Id);
9165 end if;
9166
9167 -- It is not possible to import a constant of an unconstrained
9168 -- array type (e.g. string) because there is no simple way to
9169 -- write a meaningful subtype for it.
9170
9171 if Is_Array_Type (Etype (Def_Id))
9172 and then not Is_Constrained (Etype (Def_Id))
9173 then
9174 Error_Msg_NE
9175 ("imported constant& must have a constrained subtype",
9176 N, Def_Id);
9177 end if;
9178 end if;
9179
9180 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9181
9182 -- If the name is overloaded, pragma applies to all of the denoted
9183 -- entities in the same declarative part, unless the pragma comes
9184 -- from an aspect specification or was generated by the compiler
9185 -- (such as for pragma Provide_Shift_Operators).
9186
9187 Hom_Id := Def_Id;
9188 while Present (Hom_Id) loop
9189
9190 Def_Id := Get_Base_Subprogram (Hom_Id);
9191
9192 -- Ignore inherited subprograms because the pragma will apply
9193 -- to the parent operation, which is the one called.
9194
9195 if Is_Overloadable (Def_Id)
9196 and then Present (Alias (Def_Id))
9197 then
9198 null;
9199
9200 -- If it is not a subprogram, it must be in an outer scope and
9201 -- pragma does not apply.
9202
9203 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9204 null;
9205
9206 -- The pragma does not apply to primitives of interfaces
9207
9208 elsif Is_Dispatching_Operation (Def_Id)
9209 and then Present (Find_Dispatching_Type (Def_Id))
9210 and then Is_Interface (Find_Dispatching_Type (Def_Id))
9211 then
9212 null;
9213
9214 -- Verify that the homonym is in the same declarative part (not
9215 -- just the same scope). If the pragma comes from an aspect
9216 -- specification we know that it is part of the declaration.
9217
9218 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
9219 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9220 and then not From_Aspect_Specification (N)
9221 then
9222 exit;
9223
9224 else
9225 -- If the pragma comes from an aspect specification the
9226 -- Is_Imported flag has already been set.
9227
9228 if not From_Aspect_Specification (N) then
9229 Set_Imported (Def_Id);
9230 end if;
9231
9232 -- Reject an Import applied to an abstract subprogram
9233
9234 if Is_Subprogram (Def_Id)
9235 and then Is_Abstract_Subprogram (Def_Id)
9236 then
9237 Error_Msg_Sloc := Sloc (Def_Id);
9238 Error_Msg_NE
9239 ("cannot import abstract subprogram& declared#",
9240 Arg2, Def_Id);
9241 end if;
9242
9243 -- Special processing for Convention_Intrinsic
9244
9245 if C = Convention_Intrinsic then
9246
9247 -- Link_Name argument not allowed for intrinsic
9248
9249 Check_No_Link_Name;
9250
9251 Set_Is_Intrinsic_Subprogram (Def_Id);
9252
9253 -- If no external name is present, then check that this
9254 -- is a valid intrinsic subprogram. If an external name
9255 -- is present, then this is handled by the back end.
9256
9257 if No (Arg3) then
9258 Check_Intrinsic_Subprogram
9259 (Def_Id, Get_Pragma_Arg (Arg2));
9260 end if;
9261 end if;
9262
9263 -- Verify that the subprogram does not have a completion
9264 -- through a renaming declaration. For other completions the
9265 -- pragma appears as a too late representation.
9266
9267 declare
9268 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
9269
9270 begin
9271 if Present (Decl)
9272 and then Nkind (Decl) = N_Subprogram_Declaration
9273 and then Present (Corresponding_Body (Decl))
9274 and then Nkind (Unit_Declaration_Node
9275 (Corresponding_Body (Decl))) =
9276 N_Subprogram_Renaming_Declaration
9277 then
9278 Error_Msg_Sloc := Sloc (Def_Id);
9279 Error_Msg_NE
9280 ("cannot import&, renaming already provided for "
9281 & "declaration #", N, Def_Id);
9282 end if;
9283 end;
9284
9285 -- If the pragma comes from an aspect specification, there
9286 -- must be an Import aspect specified as well. In the rare
9287 -- case where Import is set to False, the suprogram needs to
9288 -- have a local completion.
9289
9290 declare
9291 Imp_Aspect : constant Node_Id :=
9292 Find_Aspect (Def_Id, Aspect_Import);
9293 Expr : Node_Id;
9294
9295 begin
9296 if Present (Imp_Aspect)
9297 and then Present (Expression (Imp_Aspect))
9298 then
9299 Expr := Expression (Imp_Aspect);
9300 Analyze_And_Resolve (Expr, Standard_Boolean);
9301
9302 if Is_Entity_Name (Expr)
9303 and then Entity (Expr) = Standard_True
9304 then
9305 Set_Has_Completion (Def_Id);
9306 end if;
9307
9308 -- If there is no expression, the default is True, as for
9309 -- all boolean aspects. Same for the older pragma.
9310
9311 else
9312 Set_Has_Completion (Def_Id);
9313 end if;
9314 end;
9315
9316 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9317 end if;
9318
9319 if Is_Compilation_Unit (Hom_Id) then
9320
9321 -- Its possible homonyms are not affected by the pragma.
9322 -- Such homonyms might be present in the context of other
9323 -- units being compiled.
9324
9325 exit;
9326
9327 elsif From_Aspect_Specification (N) then
9328 exit;
9329
9330 -- If the pragma was created by the compiler, then we don't
9331 -- want it to apply to other homonyms. This kind of case can
9332 -- occur when using pragma Provide_Shift_Operators, which
9333 -- generates implicit shift and rotate operators with Import
9334 -- pragmas that might apply to earlier explicit or implicit
9335 -- declarations marked with Import (for example, coming from
9336 -- an earlier pragma Provide_Shift_Operators for another type),
9337 -- and we don't generally want other homonyms being treated
9338 -- as imported or the pragma flagged as an illegal duplicate.
9339
9340 elsif not Comes_From_Source (N) then
9341 exit;
9342
9343 else
9344 Hom_Id := Homonym (Hom_Id);
9345 end if;
9346 end loop;
9347
9348 -- Import a CPP class
9349
9350 elsif C = Convention_CPP
9351 and then (Is_Record_Type (Def_Id)
9352 or else Ekind (Def_Id) = E_Incomplete_Type)
9353 then
9354 if Ekind (Def_Id) = E_Incomplete_Type then
9355 if Present (Full_View (Def_Id)) then
9356 Def_Id := Full_View (Def_Id);
9357
9358 else
9359 Error_Msg_N
9360 ("cannot import 'C'P'P type before full declaration seen",
9361 Get_Pragma_Arg (Arg2));
9362
9363 -- Although we have reported the error we decorate it as
9364 -- CPP_Class to avoid reporting spurious errors
9365
9366 Set_Is_CPP_Class (Def_Id);
9367 return;
9368 end if;
9369 end if;
9370
9371 -- Types treated as CPP classes must be declared limited (note:
9372 -- this used to be a warning but there is no real benefit to it
9373 -- since we did effectively intend to treat the type as limited
9374 -- anyway).
9375
9376 if not Is_Limited_Type (Def_Id) then
9377 Error_Msg_N
9378 ("imported 'C'P'P type must be limited",
9379 Get_Pragma_Arg (Arg2));
9380 end if;
9381
9382 if Etype (Def_Id) /= Def_Id
9383 and then not Is_CPP_Class (Root_Type (Def_Id))
9384 then
9385 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
9386 end if;
9387
9388 Set_Is_CPP_Class (Def_Id);
9389
9390 -- Imported CPP types must not have discriminants (because C++
9391 -- classes do not have discriminants).
9392
9393 if Has_Discriminants (Def_Id) then
9394 Error_Msg_N
9395 ("imported 'C'P'P type cannot have discriminants",
9396 First (Discriminant_Specifications
9397 (Declaration_Node (Def_Id))));
9398 end if;
9399
9400 -- Check that components of imported CPP types do not have default
9401 -- expressions. For private types this check is performed when the
9402 -- full view is analyzed (see Process_Full_View).
9403
9404 if not Is_Private_Type (Def_Id) then
9405 Check_CPP_Type_Has_No_Defaults (Def_Id);
9406 end if;
9407
9408 -- Import a CPP exception
9409
9410 elsif C = Convention_CPP
9411 and then Ekind (Def_Id) = E_Exception
9412 then
9413 if No (Arg3) then
9414 Error_Pragma_Arg
9415 ("'External_'Name arguments is required for 'Cpp exception",
9416 Arg3);
9417 else
9418 -- As only a string is allowed, Check_Arg_Is_External_Name
9419 -- isn't called.
9420
9421 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9422 end if;
9423
9424 if Present (Arg4) then
9425 Error_Pragma_Arg
9426 ("Link_Name argument not allowed for imported Cpp exception",
9427 Arg4);
9428 end if;
9429
9430 -- Do not call Set_Interface_Name as the name of the exception
9431 -- shouldn't be modified (and in particular it shouldn't be
9432 -- the External_Name). For exceptions, the External_Name is the
9433 -- name of the RTTI structure.
9434
9435 -- ??? Emit an error if pragma Import/Export_Exception is present
9436
9437 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
9438 Check_No_Link_Name;
9439 Check_Arg_Count (3);
9440 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9441
9442 Process_Import_Predefined_Type;
9443
9444 else
9445 Error_Pragma_Arg
9446 ("second argument of pragma% must be object, subprogram "
9447 & "or incomplete type",
9448 Arg2);
9449 end if;
9450
9451 -- If this pragma applies to a compilation unit, then the unit, which
9452 -- is a subprogram, does not require (or allow) a body. We also do
9453 -- not need to elaborate imported procedures.
9454
9455 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9456 declare
9457 Cunit : constant Node_Id := Parent (Parent (N));
9458 begin
9459 Set_Body_Required (Cunit, False);
9460 end;
9461 end if;
9462 end Process_Import_Or_Interface;
9463
9464 --------------------
9465 -- Process_Inline --
9466 --------------------
9467
9468 procedure Process_Inline (Status : Inline_Status) is
9469 Applies : Boolean;
9470 Assoc : Node_Id;
9471 Decl : Node_Id;
9472 Subp : Entity_Id;
9473 Subp_Id : Node_Id;
9474
9475 Ghost_Error_Posted : Boolean := False;
9476 -- Flag set when an error concerning the illegal mix of Ghost and
9477 -- non-Ghost subprograms is emitted.
9478
9479 Ghost_Id : Entity_Id := Empty;
9480 -- The entity of the first Ghost subprogram encountered while
9481 -- processing the arguments of the pragma.
9482
9483 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id);
9484 -- Verify the placement of pragma Inline_Always with respect to the
9485 -- initial declaration of subprogram Spec_Id.
9486
9487 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
9488 -- Returns True if it can be determined at this stage that inlining
9489 -- is not possible, for example if the body is available and contains
9490 -- exception handlers, we prevent inlining, since otherwise we can
9491 -- get undefined symbols at link time. This function also emits a
9492 -- warning if the pragma appears too late.
9493 --
9494 -- ??? is business with link symbols still valid, or does it relate
9495 -- to front end ZCX which is being phased out ???
9496
9497 procedure Make_Inline (Subp : Entity_Id);
9498 -- Subp is the defining unit name of the subprogram declaration. If
9499 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
9500 -- the corresponding body, if there is one present.
9501
9502 procedure Set_Inline_Flags (Subp : Entity_Id);
9503 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
9504 -- Also set or clear Is_Inlined flag on Subp depending on Status.
9505
9506 -----------------------------------
9507 -- Check_Inline_Always_Placement --
9508 -----------------------------------
9509
9510 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id) is
9511 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id);
9512
9513 function Compilation_Unit_OK return Boolean;
9514 pragma Inline (Compilation_Unit_OK);
9515 -- Determine whether pragma Inline_Always applies to a compatible
9516 -- compilation unit denoted by Spec_Id.
9517
9518 function Declarative_List_OK return Boolean;
9519 pragma Inline (Declarative_List_OK);
9520 -- Determine whether the initial declaration of subprogram Spec_Id
9521 -- and the pragma appear in compatible declarative lists.
9522
9523 function Subprogram_Body_OK return Boolean;
9524 pragma Inline (Subprogram_Body_OK);
9525 -- Determine whether pragma Inline_Always applies to a compatible
9526 -- subprogram body denoted by Spec_Id.
9527
9528 -------------------------
9529 -- Compilation_Unit_OK --
9530 -------------------------
9531
9532 function Compilation_Unit_OK return Boolean is
9533 Comp_Unit : constant Node_Id := Parent (Spec_Decl);
9534
9535 begin
9536 -- The pragma appears after the initial declaration of a
9537 -- compilation unit.
9538
9539 -- procedure Comp_Unit;
9540 -- pragma Inline_Always (Comp_Unit);
9541
9542 -- Note that for compatibility reasons, the following case is
9543 -- also accepted.
9544
9545 -- procedure Stand_Alone_Body_Comp_Unit is
9546 -- ...
9547 -- end Stand_Alone_Body_Comp_Unit;
9548 -- pragma Inline_Always (Stand_Alone_Body_Comp_Unit);
9549
9550 return
9551 Nkind (Comp_Unit) = N_Compilation_Unit
9552 and then Present (Aux_Decls_Node (Comp_Unit))
9553 and then Is_List_Member (N)
9554 and then List_Containing (N) =
9555 Pragmas_After (Aux_Decls_Node (Comp_Unit));
9556 end Compilation_Unit_OK;
9557
9558 -------------------------
9559 -- Declarative_List_OK --
9560 -------------------------
9561
9562 function Declarative_List_OK return Boolean is
9563 Context : constant Node_Id := Parent (Spec_Decl);
9564
9565 Init_Decl : Node_Id;
9566 Init_List : List_Id;
9567 Prag_List : List_Id;
9568
9569 begin
9570 -- Determine the proper initial declaration. In general this is
9571 -- the declaration node of the subprogram except when the input
9572 -- denotes a generic instantiation.
9573
9574 -- procedure Inst is new Gen;
9575 -- pragma Inline_Always (Inst);
9576
9577 -- In this case the original subprogram is moved inside an
9578 -- anonymous package while pragma Inline_Always remains at the
9579 -- level of the anonymous package. Use the declaration of the
9580 -- package because it reflects the placement of the original
9581 -- instantiation.
9582
9583 -- package Anon_Pack is
9584 -- procedure Inst is ... end Inst; -- original
9585 -- end Anon_Pack;
9586
9587 -- procedure Inst renames Anon_Pack.Inst;
9588 -- pragma Inline_Always (Inst);
9589
9590 if Is_Generic_Instance (Spec_Id) then
9591 Init_Decl := Parent (Parent (Spec_Decl));
9592 pragma Assert (Nkind (Init_Decl) = N_Package_Declaration);
9593 else
9594 Init_Decl := Spec_Decl;
9595 end if;
9596
9597 if Is_List_Member (Init_Decl) and then Is_List_Member (N) then
9598 Init_List := List_Containing (Init_Decl);
9599 Prag_List := List_Containing (N);
9600
9601 -- The pragma and then initial declaration appear within the
9602 -- same declarative list.
9603
9604 if Init_List = Prag_List then
9605 return True;
9606
9607 -- A special case of the above is when both the pragma and
9608 -- the initial declaration appear in different lists of a
9609 -- package spec, protected definition, or a task definition.
9610
9611 -- package Pack is
9612 -- procedure Proc;
9613 -- private
9614 -- pragma Inline_Always (Proc);
9615 -- end Pack;
9616
9617 elsif Nkind_In (Context, N_Package_Specification,
9618 N_Protected_Definition,
9619 N_Task_Definition)
9620 and then Init_List = Visible_Declarations (Context)
9621 and then Prag_List = Private_Declarations (Context)
9622 then
9623 return True;
9624 end if;
9625 end if;
9626
9627 return False;
9628 end Declarative_List_OK;
9629
9630 ------------------------
9631 -- Subprogram_Body_OK --
9632 ------------------------
9633
9634 function Subprogram_Body_OK return Boolean is
9635 Body_Decl : Node_Id;
9636
9637 begin
9638 -- The pragma appears within the declarative list of a stand-
9639 -- alone subprogram body.
9640
9641 -- procedure Stand_Alone_Body is
9642 -- pragma Inline_Always (Stand_Alone_Body);
9643 -- begin
9644 -- ...
9645 -- end Stand_Alone_Body;
9646
9647 -- The compiler creates a dummy spec in this case, however the
9648 -- pragma remains within the declarative list of the body.
9649
9650 if Nkind (Spec_Decl) = N_Subprogram_Declaration
9651 and then not Comes_From_Source (Spec_Decl)
9652 and then Present (Corresponding_Body (Spec_Decl))
9653 then
9654 Body_Decl :=
9655 Unit_Declaration_Node (Corresponding_Body (Spec_Decl));
9656
9657 if Present (Declarations (Body_Decl))
9658 and then Is_List_Member (N)
9659 and then List_Containing (N) = Declarations (Body_Decl)
9660 then
9661 return True;
9662 end if;
9663 end if;
9664
9665 return False;
9666 end Subprogram_Body_OK;
9667
9668 -- Start of processing for Check_Inline_Always_Placement
9669
9670 begin
9671 -- This check is relevant only for pragma Inline_Always
9672
9673 if Pname /= Name_Inline_Always then
9674 return;
9675
9676 -- Nothing to do when the pragma is internally generated on the
9677 -- assumption that it is properly placed.
9678
9679 elsif not Comes_From_Source (N) then
9680 return;
9681
9682 -- Nothing to do for internally generated subprograms that act
9683 -- as accidental homonyms of a source subprogram being inlined.
9684
9685 elsif not Comes_From_Source (Spec_Id) then
9686 return;
9687
9688 -- Nothing to do for generic formal subprograms that act as
9689 -- homonyms of another source subprogram being inlined.
9690
9691 elsif Is_Formal_Subprogram (Spec_Id) then
9692 return;
9693
9694 elsif Compilation_Unit_OK
9695 or else Declarative_List_OK
9696 or else Subprogram_Body_OK
9697 then
9698 return;
9699 end if;
9700
9701 -- At this point it is known that the pragma applies to or appears
9702 -- within a completing body, a completing stub, or a subunit.
9703
9704 Error_Msg_Name_1 := Pname;
9705 Error_Msg_Name_2 := Chars (Spec_Id);
9706 Error_Msg_Sloc := Sloc (Spec_Id);
9707
9708 Error_Msg_N
9709 ("pragma % must appear on initial declaration of subprogram "
9710 & "% defined #", N);
9711 end Check_Inline_Always_Placement;
9712
9713 ---------------------------
9714 -- Inlining_Not_Possible --
9715 ---------------------------
9716
9717 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
9718 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
9719 Stats : Node_Id;
9720
9721 begin
9722 if Nkind (Decl) = N_Subprogram_Body then
9723 Stats := Handled_Statement_Sequence (Decl);
9724 return Present (Exception_Handlers (Stats))
9725 or else Present (At_End_Proc (Stats));
9726
9727 elsif Nkind (Decl) = N_Subprogram_Declaration
9728 and then Present (Corresponding_Body (Decl))
9729 then
9730 if Analyzed (Corresponding_Body (Decl)) then
9731 Error_Msg_N ("pragma appears too late, ignored??", N);
9732 return True;
9733
9734 -- If the subprogram is a renaming as body, the body is just a
9735 -- call to the renamed subprogram, and inlining is trivially
9736 -- possible.
9737
9738 elsif
9739 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
9740 N_Subprogram_Renaming_Declaration
9741 then
9742 return False;
9743
9744 else
9745 Stats :=
9746 Handled_Statement_Sequence
9747 (Unit_Declaration_Node (Corresponding_Body (Decl)));
9748
9749 return
9750 Present (Exception_Handlers (Stats))
9751 or else Present (At_End_Proc (Stats));
9752 end if;
9753
9754 else
9755 -- If body is not available, assume the best, the check is
9756 -- performed again when compiling enclosing package bodies.
9757
9758 return False;
9759 end if;
9760 end Inlining_Not_Possible;
9761
9762 -----------------
9763 -- Make_Inline --
9764 -----------------
9765
9766 procedure Make_Inline (Subp : Entity_Id) is
9767 Kind : constant Entity_Kind := Ekind (Subp);
9768 Inner_Subp : Entity_Id := Subp;
9769
9770 begin
9771 -- Ignore if bad type, avoid cascaded error
9772
9773 if Etype (Subp) = Any_Type then
9774 Applies := True;
9775 return;
9776
9777 -- If inlining is not possible, for now do not treat as an error
9778
9779 elsif Status /= Suppressed
9780 and then Front_End_Inlining
9781 and then Inlining_Not_Possible (Subp)
9782 then
9783 Applies := True;
9784 return;
9785
9786 -- Here we have a candidate for inlining, but we must exclude
9787 -- derived operations. Otherwise we would end up trying to inline
9788 -- a phantom declaration, and the result would be to drag in a
9789 -- body which has no direct inlining associated with it. That
9790 -- would not only be inefficient but would also result in the
9791 -- backend doing cross-unit inlining in cases where it was
9792 -- definitely inappropriate to do so.
9793
9794 -- However, a simple Comes_From_Source test is insufficient, since
9795 -- we do want to allow inlining of generic instances which also do
9796 -- not come from source. We also need to recognize specs generated
9797 -- by the front-end for bodies that carry the pragma. Finally,
9798 -- predefined operators do not come from source but are not
9799 -- inlineable either.
9800
9801 elsif Is_Generic_Instance (Subp)
9802 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
9803 then
9804 null;
9805
9806 elsif not Comes_From_Source (Subp)
9807 and then Scope (Subp) /= Standard_Standard
9808 then
9809 Applies := True;
9810 return;
9811 end if;
9812
9813 -- The referenced entity must either be the enclosing entity, or
9814 -- an entity declared within the current open scope.
9815
9816 if Present (Scope (Subp))
9817 and then Scope (Subp) /= Current_Scope
9818 and then Subp /= Current_Scope
9819 then
9820 Error_Pragma_Arg
9821 ("argument of% must be entity in current scope", Assoc);
9822 return;
9823 end if;
9824
9825 -- Processing for procedure, operator or function. If subprogram
9826 -- is aliased (as for an instance) indicate that the renamed
9827 -- entity (if declared in the same unit) is inlined.
9828 -- If this is the anonymous subprogram created for a subprogram
9829 -- instance, the inlining applies to it directly. Otherwise we
9830 -- retrieve it as the alias of the visible subprogram instance.
9831
9832 if Is_Subprogram (Subp) then
9833
9834 -- Ensure that pragma Inline_Always is associated with the
9835 -- initial declaration of the subprogram.
9836
9837 Check_Inline_Always_Placement (Subp);
9838
9839 if Is_Wrapper_Package (Scope (Subp)) then
9840 Inner_Subp := Subp;
9841 else
9842 Inner_Subp := Ultimate_Alias (Inner_Subp);
9843 end if;
9844
9845 if In_Same_Source_Unit (Subp, Inner_Subp) then
9846 Set_Inline_Flags (Inner_Subp);
9847
9848 Decl := Parent (Parent (Inner_Subp));
9849
9850 if Nkind (Decl) = N_Subprogram_Declaration
9851 and then Present (Corresponding_Body (Decl))
9852 then
9853 Set_Inline_Flags (Corresponding_Body (Decl));
9854
9855 elsif Is_Generic_Instance (Subp)
9856 and then Comes_From_Source (Subp)
9857 then
9858 -- Indicate that the body needs to be created for
9859 -- inlining subsequent calls. The instantiation node
9860 -- follows the declaration of the wrapper package
9861 -- created for it. The subprogram that requires the
9862 -- body is the anonymous one in the wrapper package.
9863
9864 if Scope (Subp) /= Standard_Standard
9865 and then
9866 Need_Subprogram_Instance_Body
9867 (Next (Unit_Declaration_Node
9868 (Scope (Alias (Subp)))), Subp)
9869 then
9870 null;
9871 end if;
9872
9873 -- Inline is a program unit pragma (RM 10.1.5) and cannot
9874 -- appear in a formal part to apply to a formal subprogram.
9875 -- Do not apply check within an instance or a formal package
9876 -- the test will have been applied to the original generic.
9877
9878 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
9879 and then List_Containing (Decl) = List_Containing (N)
9880 and then not In_Instance
9881 then
9882 Error_Msg_N
9883 ("Inline cannot apply to a formal subprogram", N);
9884 end if;
9885 end if;
9886
9887 Applies := True;
9888
9889 -- For a generic subprogram set flag as well, for use at the point
9890 -- of instantiation, to determine whether the body should be
9891 -- generated.
9892
9893 elsif Is_Generic_Subprogram (Subp) then
9894 Set_Inline_Flags (Subp);
9895 Applies := True;
9896
9897 -- Literals are by definition inlined
9898
9899 elsif Kind = E_Enumeration_Literal then
9900 null;
9901
9902 -- Anything else is an error
9903
9904 else
9905 Error_Pragma_Arg
9906 ("expect subprogram name for pragma%", Assoc);
9907 end if;
9908 end Make_Inline;
9909
9910 ----------------------
9911 -- Set_Inline_Flags --
9912 ----------------------
9913
9914 procedure Set_Inline_Flags (Subp : Entity_Id) is
9915 begin
9916 -- First set the Has_Pragma_XXX flags and issue the appropriate
9917 -- errors and warnings for suspicious combinations.
9918
9919 if Prag_Id = Pragma_No_Inline then
9920 if Has_Pragma_Inline_Always (Subp) then
9921 Error_Msg_N
9922 ("Inline_Always and No_Inline are mutually exclusive", N);
9923 elsif Has_Pragma_Inline (Subp) then
9924 Error_Msg_NE
9925 ("Inline and No_Inline both specified for& ??",
9926 N, Entity (Subp_Id));
9927 end if;
9928
9929 Set_Has_Pragma_No_Inline (Subp);
9930 else
9931 if Prag_Id = Pragma_Inline_Always then
9932 if Has_Pragma_No_Inline (Subp) then
9933 Error_Msg_N
9934 ("Inline_Always and No_Inline are mutually exclusive",
9935 N);
9936 end if;
9937
9938 Set_Has_Pragma_Inline_Always (Subp);
9939 else
9940 if Has_Pragma_No_Inline (Subp) then
9941 Error_Msg_NE
9942 ("Inline and No_Inline both specified for& ??",
9943 N, Entity (Subp_Id));
9944 end if;
9945 end if;
9946
9947 Set_Has_Pragma_Inline (Subp);
9948 end if;
9949
9950 -- Then adjust the Is_Inlined flag. It can never be set if the
9951 -- subprogram is subject to pragma No_Inline.
9952
9953 case Status is
9954 when Suppressed =>
9955 Set_Is_Inlined (Subp, False);
9956
9957 when Disabled =>
9958 null;
9959
9960 when Enabled =>
9961 if not Has_Pragma_No_Inline (Subp) then
9962 Set_Is_Inlined (Subp, True);
9963 end if;
9964 end case;
9965
9966 -- A pragma that applies to a Ghost entity becomes Ghost for the
9967 -- purposes of legality checks and removal of ignored Ghost code.
9968
9969 Mark_Ghost_Pragma (N, Subp);
9970
9971 -- Capture the entity of the first Ghost subprogram being
9972 -- processed for error detection purposes.
9973
9974 if Is_Ghost_Entity (Subp) then
9975 if No (Ghost_Id) then
9976 Ghost_Id := Subp;
9977 end if;
9978
9979 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
9980 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
9981
9982 elsif Present (Ghost_Id) and then not Ghost_Error_Posted then
9983 Ghost_Error_Posted := True;
9984
9985 Error_Msg_Name_1 := Pname;
9986 Error_Msg_N
9987 ("pragma % cannot mention ghost and non-ghost subprograms",
9988 N);
9989
9990 Error_Msg_Sloc := Sloc (Ghost_Id);
9991 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
9992
9993 Error_Msg_Sloc := Sloc (Subp);
9994 Error_Msg_NE ("\& # declared as non-ghost", N, Subp);
9995 end if;
9996 end Set_Inline_Flags;
9997
9998 -- Start of processing for Process_Inline
9999
10000 begin
10001 -- An inlined subprogram may grant access to its private enclosing
10002 -- context depending on the placement of its body. From elaboration
10003 -- point of view, the flow of execution may enter this private
10004 -- context, and then reach an external unit, thus producing a
10005 -- dependency on that external unit. For such a path to be properly
10006 -- discovered and encoded in the ALI file of the main unit, let the
10007 -- ABE mechanism process the body of the main unit, and encode all
10008 -- relevant invocation constructs and the relations between them.
10009
10010 Mark_Save_Invocation_Graph_Of_Body;
10011
10012 Check_No_Identifiers;
10013 Check_At_Least_N_Arguments (1);
10014
10015 if Status = Enabled then
10016 Inline_Processing_Required := True;
10017 end if;
10018
10019 Assoc := Arg1;
10020 while Present (Assoc) loop
10021 Subp_Id := Get_Pragma_Arg (Assoc);
10022 Analyze (Subp_Id);
10023 Applies := False;
10024
10025 if Is_Entity_Name (Subp_Id) then
10026 Subp := Entity (Subp_Id);
10027
10028 if Subp = Any_Id then
10029
10030 -- If previous error, avoid cascaded errors
10031
10032 Check_Error_Detected;
10033 Applies := True;
10034
10035 else
10036 Make_Inline (Subp);
10037
10038 -- For the pragma case, climb homonym chain. This is
10039 -- what implements allowing the pragma in the renaming
10040 -- case, with the result applying to the ancestors, and
10041 -- also allows Inline to apply to all previous homonyms.
10042
10043 if not From_Aspect_Specification (N) then
10044 while Present (Homonym (Subp))
10045 and then Scope (Homonym (Subp)) = Current_Scope
10046 loop
10047 Make_Inline (Homonym (Subp));
10048 Subp := Homonym (Subp);
10049 end loop;
10050 end if;
10051 end if;
10052 end if;
10053
10054 if not Applies then
10055 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
10056 end if;
10057
10058 Next (Assoc);
10059 end loop;
10060
10061 -- If the context is a package declaration, the pragma indicates
10062 -- that inlining will require the presence of the corresponding
10063 -- body. (this may be further refined).
10064
10065 if not In_Instance
10066 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
10067 N_Package_Declaration
10068 then
10069 Set_Body_Needed_For_Inlining (Cunit_Entity (Current_Sem_Unit));
10070 end if;
10071 end Process_Inline;
10072
10073 ----------------------------
10074 -- Process_Interface_Name --
10075 ----------------------------
10076
10077 procedure Process_Interface_Name
10078 (Subprogram_Def : Entity_Id;
10079 Ext_Arg : Node_Id;
10080 Link_Arg : Node_Id;
10081 Prag : Node_Id)
10082 is
10083 Ext_Nam : Node_Id;
10084 Link_Nam : Node_Id;
10085 String_Val : String_Id;
10086
10087 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
10088 -- SN is a string literal node for an interface name. This routine
10089 -- performs some minimal checks that the name is reasonable. In
10090 -- particular that no spaces or other obviously incorrect characters
10091 -- appear. This is only a warning, since any characters are allowed.
10092
10093 ----------------------------------
10094 -- Check_Form_Of_Interface_Name --
10095 ----------------------------------
10096
10097 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
10098 S : constant String_Id := Strval (Expr_Value_S (SN));
10099 SL : constant Nat := String_Length (S);
10100 C : Char_Code;
10101
10102 begin
10103 if SL = 0 then
10104 Error_Msg_N ("interface name cannot be null string", SN);
10105 end if;
10106
10107 for J in 1 .. SL loop
10108 C := Get_String_Char (S, J);
10109
10110 -- Look for dubious character and issue unconditional warning.
10111 -- Definitely dubious if not in character range.
10112
10113 if not In_Character_Range (C)
10114
10115 -- Commas, spaces and (back)slashes are dubious
10116
10117 or else Get_Character (C) = ','
10118 or else Get_Character (C) = '\'
10119 or else Get_Character (C) = ' '
10120 or else Get_Character (C) = '/'
10121 then
10122 Error_Msg
10123 ("??interface name contains illegal character",
10124 Sloc (SN) + Source_Ptr (J));
10125 end if;
10126 end loop;
10127 end Check_Form_Of_Interface_Name;
10128
10129 -- Start of processing for Process_Interface_Name
10130
10131 begin
10132 -- If we are looking at a pragma that comes from an aspect then it
10133 -- needs to have its corresponding aspect argument expressions
10134 -- analyzed in addition to the generated pragma so that aspects
10135 -- within generic units get properly resolved.
10136
10137 if Present (Prag) and then From_Aspect_Specification (Prag) then
10138 declare
10139 Asp : constant Node_Id := Corresponding_Aspect (Prag);
10140 Dummy_1 : Node_Id;
10141 Dummy_2 : Node_Id;
10142 Dummy_3 : Node_Id;
10143 EN : Node_Id;
10144 LN : Node_Id;
10145
10146 begin
10147 -- Obtain all interfacing aspects used to construct the pragma
10148
10149 Get_Interfacing_Aspects
10150 (Asp, Dummy_1, EN, Dummy_2, Dummy_3, LN);
10151
10152 -- Analyze the expression of aspect External_Name
10153
10154 if Present (EN) then
10155 Analyze (Expression (EN));
10156 end if;
10157
10158 -- Analyze the expressio of aspect Link_Name
10159
10160 if Present (LN) then
10161 Analyze (Expression (LN));
10162 end if;
10163 end;
10164 end if;
10165
10166 if No (Link_Arg) then
10167 if No (Ext_Arg) then
10168 return;
10169
10170 elsif Chars (Ext_Arg) = Name_Link_Name then
10171 Ext_Nam := Empty;
10172 Link_Nam := Expression (Ext_Arg);
10173
10174 else
10175 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10176 Ext_Nam := Expression (Ext_Arg);
10177 Link_Nam := Empty;
10178 end if;
10179
10180 else
10181 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10182 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
10183 Ext_Nam := Expression (Ext_Arg);
10184 Link_Nam := Expression (Link_Arg);
10185 end if;
10186
10187 -- Check expressions for external name and link name are static
10188
10189 if Present (Ext_Nam) then
10190 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
10191 Check_Form_Of_Interface_Name (Ext_Nam);
10192
10193 -- Verify that external name is not the name of a local entity,
10194 -- which would hide the imported one and could lead to run-time
10195 -- surprises. The problem can only arise for entities declared in
10196 -- a package body (otherwise the external name is fully qualified
10197 -- and will not conflict).
10198
10199 declare
10200 Nam : Name_Id;
10201 E : Entity_Id;
10202 Par : Node_Id;
10203
10204 begin
10205 if Prag_Id = Pragma_Import then
10206 Nam := String_To_Name (Strval (Expr_Value_S (Ext_Nam)));
10207 E := Entity_Id (Get_Name_Table_Int (Nam));
10208
10209 if Nam /= Chars (Subprogram_Def)
10210 and then Present (E)
10211 and then not Is_Overloadable (E)
10212 and then Is_Immediately_Visible (E)
10213 and then not Is_Imported (E)
10214 and then Ekind (Scope (E)) = E_Package
10215 then
10216 Par := Parent (E);
10217 while Present (Par) loop
10218 if Nkind (Par) = N_Package_Body then
10219 Error_Msg_Sloc := Sloc (E);
10220 Error_Msg_NE
10221 ("imported entity is hidden by & declared#",
10222 Ext_Arg, E);
10223 exit;
10224 end if;
10225
10226 Par := Parent (Par);
10227 end loop;
10228 end if;
10229 end if;
10230 end;
10231 end if;
10232
10233 if Present (Link_Nam) then
10234 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
10235 Check_Form_Of_Interface_Name (Link_Nam);
10236 end if;
10237
10238 -- If there is no link name, just set the external name
10239
10240 if No (Link_Nam) then
10241 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
10242
10243 -- For the Link_Name case, the given literal is preceded by an
10244 -- asterisk, which indicates to GCC that the given name should be
10245 -- taken literally, and in particular that no prepending of
10246 -- underlines should occur, even in systems where this is the
10247 -- normal default.
10248
10249 else
10250 Start_String;
10251 Store_String_Char (Get_Char_Code ('*'));
10252 String_Val := Strval (Expr_Value_S (Link_Nam));
10253 Store_String_Chars (String_Val);
10254 Link_Nam :=
10255 Make_String_Literal (Sloc (Link_Nam),
10256 Strval => End_String);
10257 end if;
10258
10259 -- Set the interface name. If the entity is a generic instance, use
10260 -- its alias, which is the callable entity.
10261
10262 if Is_Generic_Instance (Subprogram_Def) then
10263 Set_Encoded_Interface_Name
10264 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
10265 else
10266 Set_Encoded_Interface_Name
10267 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
10268 end if;
10269
10270 Check_Duplicated_Export_Name (Link_Nam);
10271 end Process_Interface_Name;
10272
10273 -----------------------------------------
10274 -- Process_Interrupt_Or_Attach_Handler --
10275 -----------------------------------------
10276
10277 procedure Process_Interrupt_Or_Attach_Handler is
10278 Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
10279 Prot_Typ : constant Entity_Id := Scope (Handler);
10280
10281 begin
10282 -- A pragma that applies to a Ghost entity becomes Ghost for the
10283 -- purposes of legality checks and removal of ignored Ghost code.
10284
10285 Mark_Ghost_Pragma (N, Handler);
10286 Set_Is_Interrupt_Handler (Handler);
10287
10288 pragma Assert (Ekind (Prot_Typ) = E_Protected_Type);
10289
10290 Record_Rep_Item (Prot_Typ, N);
10291
10292 -- Chain the pragma on the contract for completeness
10293
10294 Add_Contract_Item (N, Handler);
10295 end Process_Interrupt_Or_Attach_Handler;
10296
10297 --------------------------------------------------
10298 -- Process_Restrictions_Or_Restriction_Warnings --
10299 --------------------------------------------------
10300
10301 -- Note: some of the simple identifier cases were handled in par-prag,
10302 -- but it is harmless (and more straightforward) to simply handle all
10303 -- cases here, even if it means we repeat a bit of work in some cases.
10304
10305 procedure Process_Restrictions_Or_Restriction_Warnings
10306 (Warn : Boolean)
10307 is
10308 Arg : Node_Id;
10309 R_Id : Restriction_Id;
10310 Id : Name_Id;
10311 Expr : Node_Id;
10312 Val : Uint;
10313
10314 begin
10315 -- Ignore all Restrictions pragmas in CodePeer mode
10316
10317 if CodePeer_Mode then
10318 return;
10319 end if;
10320
10321 Check_Ada_83_Warning;
10322 Check_At_Least_N_Arguments (1);
10323 Check_Valid_Configuration_Pragma;
10324
10325 Arg := Arg1;
10326 while Present (Arg) loop
10327 Id := Chars (Arg);
10328 Expr := Get_Pragma_Arg (Arg);
10329
10330 -- Case of no restriction identifier present
10331
10332 if Id = No_Name then
10333 if Nkind (Expr) /= N_Identifier then
10334 Error_Pragma_Arg
10335 ("invalid form for restriction", Arg);
10336 end if;
10337
10338 R_Id :=
10339 Get_Restriction_Id
10340 (Process_Restriction_Synonyms (Expr));
10341
10342 if R_Id not in All_Boolean_Restrictions then
10343 Error_Msg_Name_1 := Pname;
10344 Error_Msg_N
10345 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
10346
10347 -- Check for possible misspelling
10348
10349 for J in Restriction_Id loop
10350 declare
10351 Rnm : constant String := Restriction_Id'Image (J);
10352
10353 begin
10354 Name_Buffer (1 .. Rnm'Length) := Rnm;
10355 Name_Len := Rnm'Length;
10356 Set_Casing (All_Lower_Case);
10357
10358 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
10359 Set_Casing
10360 (Identifier_Casing
10361 (Source_Index (Current_Sem_Unit)));
10362 Error_Msg_String (1 .. Rnm'Length) :=
10363 Name_Buffer (1 .. Name_Len);
10364 Error_Msg_Strlen := Rnm'Length;
10365 Error_Msg_N -- CODEFIX
10366 ("\possible misspelling of ""~""",
10367 Get_Pragma_Arg (Arg));
10368 exit;
10369 end if;
10370 end;
10371 end loop;
10372
10373 raise Pragma_Exit;
10374 end if;
10375
10376 if Implementation_Restriction (R_Id) then
10377 Check_Restriction (No_Implementation_Restrictions, Arg);
10378 end if;
10379
10380 -- Special processing for No_Elaboration_Code restriction
10381
10382 if R_Id = No_Elaboration_Code then
10383
10384 -- Restriction is only recognized within a configuration
10385 -- pragma file, or within a unit of the main extended
10386 -- program. Note: the test for Main_Unit is needed to
10387 -- properly include the case of configuration pragma files.
10388
10389 if not (Current_Sem_Unit = Main_Unit
10390 or else In_Extended_Main_Source_Unit (N))
10391 then
10392 return;
10393
10394 -- Don't allow in a subunit unless already specified in
10395 -- body or spec.
10396
10397 elsif Nkind (Parent (N)) = N_Compilation_Unit
10398 and then Nkind (Unit (Parent (N))) = N_Subunit
10399 and then not Restriction_Active (No_Elaboration_Code)
10400 then
10401 Error_Msg_N
10402 ("invalid specification of ""No_Elaboration_Code""",
10403 N);
10404 Error_Msg_N
10405 ("\restriction cannot be specified in a subunit", N);
10406 Error_Msg_N
10407 ("\unless also specified in body or spec", N);
10408 return;
10409
10410 -- If we accept a No_Elaboration_Code restriction, then it
10411 -- needs to be added to the configuration restriction set so
10412 -- that we get proper application to other units in the main
10413 -- extended source as required.
10414
10415 else
10416 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
10417 end if;
10418 end if;
10419
10420 -- If this is a warning, then set the warning unless we already
10421 -- have a real restriction active (we never want a warning to
10422 -- override a real restriction).
10423
10424 if Warn then
10425 if not Restriction_Active (R_Id) then
10426 Set_Restriction (R_Id, N);
10427 Restriction_Warnings (R_Id) := True;
10428 end if;
10429
10430 -- If real restriction case, then set it and make sure that the
10431 -- restriction warning flag is off, since a real restriction
10432 -- always overrides a warning.
10433
10434 else
10435 Set_Restriction (R_Id, N);
10436 Restriction_Warnings (R_Id) := False;
10437 end if;
10438
10439 -- Check for obsolescent restrictions in Ada 2005 mode
10440
10441 if not Warn
10442 and then Ada_Version >= Ada_2005
10443 and then (R_Id = No_Asynchronous_Control
10444 or else
10445 R_Id = No_Unchecked_Deallocation
10446 or else
10447 R_Id = No_Unchecked_Conversion)
10448 then
10449 Check_Restriction (No_Obsolescent_Features, N);
10450 end if;
10451
10452 -- A very special case that must be processed here: pragma
10453 -- Restrictions (No_Exceptions) turns off all run-time
10454 -- checking. This is a bit dubious in terms of the formal
10455 -- language definition, but it is what is intended by RM
10456 -- H.4(12). Restriction_Warnings never affects generated code
10457 -- so this is done only in the real restriction case.
10458
10459 -- Atomic_Synchronization is not a real check, so it is not
10460 -- affected by this processing).
10461
10462 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
10463 -- run-time checks in CodePeer and GNATprove modes: we want to
10464 -- generate checks for analysis purposes, as set respectively
10465 -- by -gnatC and -gnatd.F
10466
10467 if not Warn
10468 and then not (CodePeer_Mode or GNATprove_Mode)
10469 and then R_Id = No_Exceptions
10470 then
10471 for J in Scope_Suppress.Suppress'Range loop
10472 if J /= Atomic_Synchronization then
10473 Scope_Suppress.Suppress (J) := True;
10474 end if;
10475 end loop;
10476 end if;
10477
10478 -- Case of No_Dependence => unit-name. Note that the parser
10479 -- already made the necessary entry in the No_Dependence table.
10480
10481 elsif Id = Name_No_Dependence then
10482 if not OK_No_Dependence_Unit_Name (Expr) then
10483 raise Pragma_Exit;
10484 end if;
10485
10486 -- Case of No_Specification_Of_Aspect => aspect-identifier
10487
10488 elsif Id = Name_No_Specification_Of_Aspect then
10489 declare
10490 A_Id : Aspect_Id;
10491
10492 begin
10493 if Nkind (Expr) /= N_Identifier then
10494 A_Id := No_Aspect;
10495 else
10496 A_Id := Get_Aspect_Id (Chars (Expr));
10497 end if;
10498
10499 if A_Id = No_Aspect then
10500 Error_Pragma_Arg ("invalid restriction name", Arg);
10501 else
10502 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
10503 end if;
10504 end;
10505
10506 -- Case of No_Use_Of_Attribute => attribute-identifier
10507
10508 elsif Id = Name_No_Use_Of_Attribute then
10509 if Nkind (Expr) /= N_Identifier
10510 or else not Is_Attribute_Name (Chars (Expr))
10511 then
10512 Error_Msg_N ("unknown attribute name??", Expr);
10513
10514 else
10515 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
10516 end if;
10517
10518 -- Case of No_Use_Of_Entity => fully-qualified-name
10519
10520 elsif Id = Name_No_Use_Of_Entity then
10521
10522 -- Restriction is only recognized within a configuration
10523 -- pragma file, or within a unit of the main extended
10524 -- program. Note: the test for Main_Unit is needed to
10525 -- properly include the case of configuration pragma files.
10526
10527 if Current_Sem_Unit = Main_Unit
10528 or else In_Extended_Main_Source_Unit (N)
10529 then
10530 if not OK_No_Dependence_Unit_Name (Expr) then
10531 Error_Msg_N ("wrong form for entity name", Expr);
10532 else
10533 Set_Restriction_No_Use_Of_Entity
10534 (Expr, Warn, No_Profile);
10535 end if;
10536 end if;
10537
10538 -- Case of No_Use_Of_Pragma => pragma-identifier
10539
10540 elsif Id = Name_No_Use_Of_Pragma then
10541 if Nkind (Expr) /= N_Identifier
10542 or else not Is_Pragma_Name (Chars (Expr))
10543 then
10544 Error_Msg_N ("unknown pragma name??", Expr);
10545 else
10546 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
10547 end if;
10548
10549 -- All other cases of restriction identifier present
10550
10551 else
10552 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
10553 Analyze_And_Resolve (Expr, Any_Integer);
10554
10555 if R_Id not in All_Parameter_Restrictions then
10556 Error_Pragma_Arg
10557 ("invalid restriction parameter identifier", Arg);
10558
10559 elsif not Is_OK_Static_Expression (Expr) then
10560 Flag_Non_Static_Expr
10561 ("value must be static expression!", Expr);
10562 raise Pragma_Exit;
10563
10564 elsif not Is_Integer_Type (Etype (Expr))
10565 or else Expr_Value (Expr) < 0
10566 then
10567 Error_Pragma_Arg
10568 ("value must be non-negative integer", Arg);
10569 end if;
10570
10571 -- Restriction pragma is active
10572
10573 Val := Expr_Value (Expr);
10574
10575 if not UI_Is_In_Int_Range (Val) then
10576 Error_Pragma_Arg
10577 ("pragma ignored, value too large??", Arg);
10578 end if;
10579
10580 -- Warning case. If the real restriction is active, then we
10581 -- ignore the request, since warning never overrides a real
10582 -- restriction. Otherwise we set the proper warning. Note that
10583 -- this circuit sets the warning again if it is already set,
10584 -- which is what we want, since the constant may have changed.
10585
10586 if Warn then
10587 if not Restriction_Active (R_Id) then
10588 Set_Restriction
10589 (R_Id, N, Integer (UI_To_Int (Val)));
10590 Restriction_Warnings (R_Id) := True;
10591 end if;
10592
10593 -- Real restriction case, set restriction and make sure warning
10594 -- flag is off since real restriction always overrides warning.
10595
10596 else
10597 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
10598 Restriction_Warnings (R_Id) := False;
10599 end if;
10600 end if;
10601
10602 Next (Arg);
10603 end loop;
10604 end Process_Restrictions_Or_Restriction_Warnings;
10605
10606 ---------------------------------
10607 -- Process_Suppress_Unsuppress --
10608 ---------------------------------
10609
10610 -- Note: this procedure makes entries in the check suppress data
10611 -- structures managed by Sem. See spec of package Sem for full
10612 -- details on how we handle recording of check suppression.
10613
10614 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
10615 C : Check_Id;
10616 E : Entity_Id;
10617 E_Id : Node_Id;
10618
10619 In_Package_Spec : constant Boolean :=
10620 Is_Package_Or_Generic_Package (Current_Scope)
10621 and then not In_Package_Body (Current_Scope);
10622
10623 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
10624 -- Used to suppress a single check on the given entity
10625
10626 --------------------------------
10627 -- Suppress_Unsuppress_Echeck --
10628 --------------------------------
10629
10630 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
10631 begin
10632 -- Check for error of trying to set atomic synchronization for
10633 -- a non-atomic variable.
10634
10635 if C = Atomic_Synchronization
10636 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
10637 then
10638 Error_Msg_N
10639 ("pragma & requires atomic type or variable",
10640 Pragma_Identifier (Original_Node (N)));
10641 end if;
10642
10643 Set_Checks_May_Be_Suppressed (E);
10644
10645 if In_Package_Spec then
10646 Push_Global_Suppress_Stack_Entry
10647 (Entity => E,
10648 Check => C,
10649 Suppress => Suppress_Case);
10650 else
10651 Push_Local_Suppress_Stack_Entry
10652 (Entity => E,
10653 Check => C,
10654 Suppress => Suppress_Case);
10655 end if;
10656
10657 -- If this is a first subtype, and the base type is distinct,
10658 -- then also set the suppress flags on the base type.
10659
10660 if Is_First_Subtype (E) and then Etype (E) /= E then
10661 Suppress_Unsuppress_Echeck (Etype (E), C);
10662 end if;
10663 end Suppress_Unsuppress_Echeck;
10664
10665 -- Start of processing for Process_Suppress_Unsuppress
10666
10667 begin
10668 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
10669 -- on user code: we want to generate checks for analysis purposes, as
10670 -- set respectively by -gnatC and -gnatd.F
10671
10672 if Comes_From_Source (N)
10673 and then (CodePeer_Mode or GNATprove_Mode)
10674 then
10675 return;
10676 end if;
10677
10678 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
10679 -- declarative part or a package spec (RM 11.5(5)).
10680
10681 if not Is_Configuration_Pragma then
10682 Check_Is_In_Decl_Part_Or_Package_Spec;
10683 end if;
10684
10685 Check_At_Least_N_Arguments (1);
10686 Check_At_Most_N_Arguments (2);
10687 Check_No_Identifier (Arg1);
10688 Check_Arg_Is_Identifier (Arg1);
10689
10690 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
10691
10692 if C = No_Check_Id then
10693 Error_Pragma_Arg
10694 ("argument of pragma% is not valid check name", Arg1);
10695 end if;
10696
10697 -- Warn that suppress of Elaboration_Check has no effect in SPARK
10698
10699 if C = Elaboration_Check and then SPARK_Mode = On then
10700 Error_Pragma_Arg
10701 ("Suppress of Elaboration_Check ignored in SPARK??",
10702 "\elaboration checking rules are statically enforced "
10703 & "(SPARK RM 7.7)", Arg1);
10704 end if;
10705
10706 -- One-argument case
10707
10708 if Arg_Count = 1 then
10709
10710 -- Make an entry in the local scope suppress table. This is the
10711 -- table that directly shows the current value of the scope
10712 -- suppress check for any check id value.
10713
10714 if C = All_Checks then
10715
10716 -- For All_Checks, we set all specific predefined checks with
10717 -- the exception of Elaboration_Check, which is handled
10718 -- specially because of not wanting All_Checks to have the
10719 -- effect of deactivating static elaboration order processing.
10720 -- Atomic_Synchronization is also not affected, since this is
10721 -- not a real check.
10722
10723 for J in Scope_Suppress.Suppress'Range loop
10724 if J /= Elaboration_Check
10725 and then
10726 J /= Atomic_Synchronization
10727 then
10728 Scope_Suppress.Suppress (J) := Suppress_Case;
10729 end if;
10730 end loop;
10731
10732 -- If not All_Checks, and predefined check, then set appropriate
10733 -- scope entry. Note that we will set Elaboration_Check if this
10734 -- is explicitly specified. Atomic_Synchronization is allowed
10735 -- only if internally generated and entity is atomic.
10736
10737 elsif C in Predefined_Check_Id
10738 and then (not Comes_From_Source (N)
10739 or else C /= Atomic_Synchronization)
10740 then
10741 Scope_Suppress.Suppress (C) := Suppress_Case;
10742 end if;
10743
10744 -- Also make an entry in the Local_Entity_Suppress table
10745
10746 Push_Local_Suppress_Stack_Entry
10747 (Entity => Empty,
10748 Check => C,
10749 Suppress => Suppress_Case);
10750
10751 -- Case of two arguments present, where the check is suppressed for
10752 -- a specified entity (given as the second argument of the pragma)
10753
10754 else
10755 -- This is obsolescent in Ada 2005 mode
10756
10757 if Ada_Version >= Ada_2005 then
10758 Check_Restriction (No_Obsolescent_Features, Arg2);
10759 end if;
10760
10761 Check_Optional_Identifier (Arg2, Name_On);
10762 E_Id := Get_Pragma_Arg (Arg2);
10763 Analyze (E_Id);
10764
10765 if not Is_Entity_Name (E_Id) then
10766 Error_Pragma_Arg
10767 ("second argument of pragma% must be entity name", Arg2);
10768 end if;
10769
10770 E := Entity (E_Id);
10771
10772 if E = Any_Id then
10773 return;
10774 end if;
10775
10776 -- A pragma that applies to a Ghost entity becomes Ghost for the
10777 -- purposes of legality checks and removal of ignored Ghost code.
10778
10779 Mark_Ghost_Pragma (N, E);
10780
10781 -- Enforce RM 11.5(7) which requires that for a pragma that
10782 -- appears within a package spec, the named entity must be
10783 -- within the package spec. We allow the package name itself
10784 -- to be mentioned since that makes sense, although it is not
10785 -- strictly allowed by 11.5(7).
10786
10787 if In_Package_Spec
10788 and then E /= Current_Scope
10789 and then Scope (E) /= Current_Scope
10790 then
10791 Error_Pragma_Arg
10792 ("entity in pragma% is not in package spec (RM 11.5(7))",
10793 Arg2);
10794 end if;
10795
10796 -- Loop through homonyms. As noted below, in the case of a package
10797 -- spec, only homonyms within the package spec are considered.
10798
10799 loop
10800 Suppress_Unsuppress_Echeck (E, C);
10801
10802 if Is_Generic_Instance (E)
10803 and then Is_Subprogram (E)
10804 and then Present (Alias (E))
10805 then
10806 Suppress_Unsuppress_Echeck (Alias (E), C);
10807 end if;
10808
10809 -- Move to next homonym if not aspect spec case
10810
10811 exit when From_Aspect_Specification (N);
10812 E := Homonym (E);
10813 exit when No (E);
10814
10815 -- If we are within a package specification, the pragma only
10816 -- applies to homonyms in the same scope.
10817
10818 exit when In_Package_Spec
10819 and then Scope (E) /= Current_Scope;
10820 end loop;
10821 end if;
10822 end Process_Suppress_Unsuppress;
10823
10824 -------------------------------
10825 -- Record_Independence_Check --
10826 -------------------------------
10827
10828 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
10829 pragma Unreferenced (N, E);
10830 begin
10831 -- For GCC back ends the validation is done a priori
10832 -- ??? This code is dead, might be useful in the future
10833
10834 -- if not AAMP_On_Target then
10835 -- return;
10836 -- end if;
10837
10838 -- Independence_Checks.Append ((N, E));
10839
10840 return;
10841 end Record_Independence_Check;
10842
10843 ------------------
10844 -- Set_Exported --
10845 ------------------
10846
10847 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
10848 begin
10849 if Is_Imported (E) then
10850 Error_Pragma_Arg
10851 ("cannot export entity& that was previously imported", Arg);
10852
10853 elsif Present (Address_Clause (E))
10854 and then not Relaxed_RM_Semantics
10855 then
10856 Error_Pragma_Arg
10857 ("cannot export entity& that has an address clause", Arg);
10858 end if;
10859
10860 Set_Is_Exported (E);
10861
10862 -- Generate a reference for entity explicitly, because the
10863 -- identifier may be overloaded and name resolution will not
10864 -- generate one.
10865
10866 Generate_Reference (E, Arg);
10867
10868 -- Deal with exporting non-library level entity
10869
10870 if not Is_Library_Level_Entity (E) then
10871
10872 -- Not allowed at all for subprograms
10873
10874 if Is_Subprogram (E) then
10875 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
10876
10877 -- Otherwise set public and statically allocated
10878
10879 else
10880 Set_Is_Public (E);
10881 Set_Is_Statically_Allocated (E);
10882
10883 -- Warn if the corresponding W flag is set
10884
10885 if Warn_On_Export_Import
10886
10887 -- Only do this for something that was in the source. Not
10888 -- clear if this can be False now (there used for sure to be
10889 -- cases on some systems where it was False), but anyway the
10890 -- test is harmless if not needed, so it is retained.
10891
10892 and then Comes_From_Source (Arg)
10893 then
10894 Error_Msg_NE
10895 ("?x?& has been made static as a result of Export",
10896 Arg, E);
10897 Error_Msg_N
10898 ("\?x?this usage is non-standard and non-portable",
10899 Arg);
10900 end if;
10901 end if;
10902 end if;
10903
10904 if Warn_On_Export_Import and then Is_Type (E) then
10905 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
10906 end if;
10907
10908 if Warn_On_Export_Import and Inside_A_Generic then
10909 Error_Msg_NE
10910 ("all instances of& will have the same external name?x?",
10911 Arg, E);
10912 end if;
10913 end Set_Exported;
10914
10915 ----------------------------------------------
10916 -- Set_Extended_Import_Export_External_Name --
10917 ----------------------------------------------
10918
10919 procedure Set_Extended_Import_Export_External_Name
10920 (Internal_Ent : Entity_Id;
10921 Arg_External : Node_Id)
10922 is
10923 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
10924 New_Name : Node_Id;
10925
10926 begin
10927 if No (Arg_External) then
10928 return;
10929 end if;
10930
10931 Check_Arg_Is_External_Name (Arg_External);
10932
10933 if Nkind (Arg_External) = N_String_Literal then
10934 if String_Length (Strval (Arg_External)) = 0 then
10935 return;
10936 else
10937 New_Name := Adjust_External_Name_Case (Arg_External);
10938 end if;
10939
10940 elsif Nkind (Arg_External) = N_Identifier then
10941 New_Name := Get_Default_External_Name (Arg_External);
10942
10943 -- Check_Arg_Is_External_Name should let through only identifiers and
10944 -- string literals or static string expressions (which are folded to
10945 -- string literals).
10946
10947 else
10948 raise Program_Error;
10949 end if;
10950
10951 -- If we already have an external name set (by a prior normal Import
10952 -- or Export pragma), then the external names must match
10953
10954 if Present (Interface_Name (Internal_Ent)) then
10955
10956 -- Ignore mismatching names in CodePeer mode, to support some
10957 -- old compilers which would export the same procedure under
10958 -- different names, e.g:
10959 -- procedure P;
10960 -- pragma Export_Procedure (P, "a");
10961 -- pragma Export_Procedure (P, "b");
10962
10963 if CodePeer_Mode then
10964 return;
10965 end if;
10966
10967 Check_Matching_Internal_Names : declare
10968 S1 : constant String_Id := Strval (Old_Name);
10969 S2 : constant String_Id := Strval (New_Name);
10970
10971 procedure Mismatch;
10972 pragma No_Return (Mismatch);
10973 -- Called if names do not match
10974
10975 --------------
10976 -- Mismatch --
10977 --------------
10978
10979 procedure Mismatch is
10980 begin
10981 Error_Msg_Sloc := Sloc (Old_Name);
10982 Error_Pragma_Arg
10983 ("external name does not match that given #",
10984 Arg_External);
10985 end Mismatch;
10986
10987 -- Start of processing for Check_Matching_Internal_Names
10988
10989 begin
10990 if String_Length (S1) /= String_Length (S2) then
10991 Mismatch;
10992
10993 else
10994 for J in 1 .. String_Length (S1) loop
10995 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
10996 Mismatch;
10997 end if;
10998 end loop;
10999 end if;
11000 end Check_Matching_Internal_Names;
11001
11002 -- Otherwise set the given name
11003
11004 else
11005 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
11006 Check_Duplicated_Export_Name (New_Name);
11007 end if;
11008 end Set_Extended_Import_Export_External_Name;
11009
11010 ------------------
11011 -- Set_Imported --
11012 ------------------
11013
11014 procedure Set_Imported (E : Entity_Id) is
11015 begin
11016 -- Error message if already imported or exported
11017
11018 if Is_Exported (E) or else Is_Imported (E) then
11019
11020 -- Error if being set Exported twice
11021
11022 if Is_Exported (E) then
11023 Error_Msg_NE ("entity& was previously exported", N, E);
11024
11025 -- Ignore error in CodePeer mode where we treat all imported
11026 -- subprograms as unknown.
11027
11028 elsif CodePeer_Mode then
11029 goto OK;
11030
11031 -- OK if Import/Interface case
11032
11033 elsif Import_Interface_Present (N) then
11034 goto OK;
11035
11036 -- Error if being set Imported twice
11037
11038 else
11039 Error_Msg_NE ("entity& was previously imported", N, E);
11040 end if;
11041
11042 Error_Msg_Name_1 := Pname;
11043 Error_Msg_N
11044 ("\(pragma% applies to all previous entities)", N);
11045
11046 Error_Msg_Sloc := Sloc (E);
11047 Error_Msg_NE ("\import not allowed for& declared#", N, E);
11048
11049 -- Here if not previously imported or exported, OK to import
11050
11051 else
11052 Set_Is_Imported (E);
11053
11054 -- For subprogram, set Import_Pragma field
11055
11056 if Is_Subprogram (E) then
11057 Set_Import_Pragma (E, N);
11058 end if;
11059
11060 -- If the entity is an object that is not at the library level,
11061 -- then it is statically allocated. We do not worry about objects
11062 -- with address clauses in this context since they are not really
11063 -- imported in the linker sense.
11064
11065 if Is_Object (E)
11066 and then not Is_Library_Level_Entity (E)
11067 and then No (Address_Clause (E))
11068 then
11069 Set_Is_Statically_Allocated (E);
11070 end if;
11071 end if;
11072
11073 <<OK>> null;
11074 end Set_Imported;
11075
11076 -------------------------
11077 -- Set_Mechanism_Value --
11078 -------------------------
11079
11080 -- Note: the mechanism name has not been analyzed (and cannot indeed be
11081 -- analyzed, since it is semantic nonsense), so we get it in the exact
11082 -- form created by the parser.
11083
11084 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
11085 procedure Bad_Mechanism;
11086 pragma No_Return (Bad_Mechanism);
11087 -- Signal bad mechanism name
11088
11089 -------------------
11090 -- Bad_Mechanism --
11091 -------------------
11092
11093 procedure Bad_Mechanism is
11094 begin
11095 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
11096 end Bad_Mechanism;
11097
11098 -- Start of processing for Set_Mechanism_Value
11099
11100 begin
11101 if Mechanism (Ent) /= Default_Mechanism then
11102 Error_Msg_NE
11103 ("mechanism for & has already been set", Mech_Name, Ent);
11104 end if;
11105
11106 -- MECHANISM_NAME ::= value | reference
11107
11108 if Nkind (Mech_Name) = N_Identifier then
11109 if Chars (Mech_Name) = Name_Value then
11110 Set_Mechanism (Ent, By_Copy);
11111 return;
11112
11113 elsif Chars (Mech_Name) = Name_Reference then
11114 Set_Mechanism (Ent, By_Reference);
11115 return;
11116
11117 elsif Chars (Mech_Name) = Name_Copy then
11118 Error_Pragma_Arg
11119 ("bad mechanism name, Value assumed", Mech_Name);
11120
11121 else
11122 Bad_Mechanism;
11123 end if;
11124
11125 else
11126 Bad_Mechanism;
11127 end if;
11128 end Set_Mechanism_Value;
11129
11130 --------------------------
11131 -- Set_Rational_Profile --
11132 --------------------------
11133
11134 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
11135 -- extension to the semantics of renaming declarations.
11136
11137 procedure Set_Rational_Profile is
11138 begin
11139 Implicit_Packing := True;
11140 Overriding_Renamings := True;
11141 Use_VADS_Size := True;
11142 end Set_Rational_Profile;
11143
11144 ---------------------------
11145 -- Set_Ravenscar_Profile --
11146 ---------------------------
11147
11148 -- The tasks to be done here are
11149
11150 -- Set required policies
11151
11152 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11153 -- (For Ravenscar and GNAT_Extended_Ravenscar profiles)
11154 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11155 -- (For GNAT_Ravenscar_EDF profile)
11156 -- pragma Locking_Policy (Ceiling_Locking)
11157
11158 -- Set Detect_Blocking mode
11159
11160 -- Set required restrictions (see System.Rident for detailed list)
11161
11162 -- Set the No_Dependence rules
11163 -- No_Dependence => Ada.Asynchronous_Task_Control
11164 -- No_Dependence => Ada.Calendar
11165 -- No_Dependence => Ada.Execution_Time.Group_Budget
11166 -- No_Dependence => Ada.Execution_Time.Timers
11167 -- No_Dependence => Ada.Task_Attributes
11168 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11169
11170 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is
11171 procedure Set_Error_Msg_To_Profile_Name;
11172 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
11173 -- profile.
11174
11175 -----------------------------------
11176 -- Set_Error_Msg_To_Profile_Name --
11177 -----------------------------------
11178
11179 procedure Set_Error_Msg_To_Profile_Name is
11180 Prof_Nam : constant Node_Id :=
11181 Get_Pragma_Arg
11182 (First (Pragma_Argument_Associations (N)));
11183
11184 begin
11185 Get_Name_String (Chars (Prof_Nam));
11186 Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam));
11187 Error_Msg_Strlen := Name_Len;
11188 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
11189 end Set_Error_Msg_To_Profile_Name;
11190
11191 -- Local variables
11192
11193 Nod : Node_Id;
11194 Pref : Node_Id;
11195 Pref_Id : Node_Id;
11196 Sel_Id : Node_Id;
11197
11198 Profile_Dispatching_Policy : Character;
11199
11200 -- Start of processing for Set_Ravenscar_Profile
11201
11202 begin
11203 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11204
11205 if Profile = GNAT_Ravenscar_EDF then
11206 Profile_Dispatching_Policy := 'E';
11207
11208 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11209
11210 else
11211 Profile_Dispatching_Policy := 'F';
11212 end if;
11213
11214 if Task_Dispatching_Policy /= ' '
11215 and then Task_Dispatching_Policy /= Profile_Dispatching_Policy
11216 then
11217 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11218 Set_Error_Msg_To_Profile_Name;
11219 Error_Pragma ("Profile (~) incompatible with policy#");
11220
11221 -- Set the FIFO_Within_Priorities policy, but always preserve
11222 -- System_Location since we like the error message with the run time
11223 -- name.
11224
11225 else
11226 Task_Dispatching_Policy := Profile_Dispatching_Policy;
11227
11228 if Task_Dispatching_Policy_Sloc /= System_Location then
11229 Task_Dispatching_Policy_Sloc := Loc;
11230 end if;
11231 end if;
11232
11233 -- pragma Locking_Policy (Ceiling_Locking)
11234
11235 if Locking_Policy /= ' '
11236 and then Locking_Policy /= 'C'
11237 then
11238 Error_Msg_Sloc := Locking_Policy_Sloc;
11239 Set_Error_Msg_To_Profile_Name;
11240 Error_Pragma ("Profile (~) incompatible with policy#");
11241
11242 -- Set the Ceiling_Locking policy, but preserve System_Location since
11243 -- we like the error message with the run time name.
11244
11245 else
11246 Locking_Policy := 'C';
11247
11248 if Locking_Policy_Sloc /= System_Location then
11249 Locking_Policy_Sloc := Loc;
11250 end if;
11251 end if;
11252
11253 -- pragma Detect_Blocking
11254
11255 Detect_Blocking := True;
11256
11257 -- Set the corresponding restrictions
11258
11259 Set_Profile_Restrictions
11260 (Profile, N, Warn => Treat_Restrictions_As_Warnings);
11261
11262 -- Set the No_Dependence restrictions
11263
11264 -- The following No_Dependence restrictions:
11265 -- No_Dependence => Ada.Asynchronous_Task_Control
11266 -- No_Dependence => Ada.Calendar
11267 -- No_Dependence => Ada.Task_Attributes
11268 -- are already set by previous call to Set_Profile_Restrictions.
11269
11270 -- Set the following restrictions which were added to Ada 2005:
11271 -- No_Dependence => Ada.Execution_Time.Group_Budget
11272 -- No_Dependence => Ada.Execution_Time.Timers
11273
11274 if Ada_Version >= Ada_2005 then
11275 Pref_Id := Make_Identifier (Loc, Name_Find ("ada"));
11276 Sel_Id := Make_Identifier (Loc, Name_Find ("execution_time"));
11277
11278 Pref :=
11279 Make_Selected_Component
11280 (Sloc => Loc,
11281 Prefix => Pref_Id,
11282 Selector_Name => Sel_Id);
11283
11284 Sel_Id := Make_Identifier (Loc, Name_Find ("group_budgets"));
11285
11286 Nod :=
11287 Make_Selected_Component
11288 (Sloc => Loc,
11289 Prefix => Pref,
11290 Selector_Name => Sel_Id);
11291
11292 Set_Restriction_No_Dependence
11293 (Unit => Nod,
11294 Warn => Treat_Restrictions_As_Warnings,
11295 Profile => Ravenscar);
11296
11297 Sel_Id := Make_Identifier (Loc, Name_Find ("timers"));
11298
11299 Nod :=
11300 Make_Selected_Component
11301 (Sloc => Loc,
11302 Prefix => Pref,
11303 Selector_Name => Sel_Id);
11304
11305 Set_Restriction_No_Dependence
11306 (Unit => Nod,
11307 Warn => Treat_Restrictions_As_Warnings,
11308 Profile => Ravenscar);
11309 end if;
11310
11311 -- Set the following restriction which was added to Ada 2012 (see
11312 -- AI-0171):
11313 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11314
11315 if Ada_Version >= Ada_2012 then
11316 Pref_Id := Make_Identifier (Loc, Name_Find ("system"));
11317 Sel_Id := Make_Identifier (Loc, Name_Find ("multiprocessors"));
11318
11319 Pref :=
11320 Make_Selected_Component
11321 (Sloc => Loc,
11322 Prefix => Pref_Id,
11323 Selector_Name => Sel_Id);
11324
11325 Sel_Id := Make_Identifier (Loc, Name_Find ("dispatching_domains"));
11326
11327 Nod :=
11328 Make_Selected_Component
11329 (Sloc => Loc,
11330 Prefix => Pref,
11331 Selector_Name => Sel_Id);
11332
11333 Set_Restriction_No_Dependence
11334 (Unit => Nod,
11335 Warn => Treat_Restrictions_As_Warnings,
11336 Profile => Ravenscar);
11337 end if;
11338 end Set_Ravenscar_Profile;
11339
11340 -- Start of processing for Analyze_Pragma
11341
11342 begin
11343 -- The following code is a defense against recursion. Not clear that
11344 -- this can happen legitimately, but perhaps some error situations can
11345 -- cause it, and we did see this recursion during testing.
11346
11347 if Analyzed (N) then
11348 return;
11349 else
11350 Set_Analyzed (N);
11351 end if;
11352
11353 Check_Restriction_No_Use_Of_Pragma (N);
11354
11355 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
11356 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
11357
11358 if Should_Ignore_Pragma_Sem (N)
11359 or else (Prag_Id = Pragma_Default_Scalar_Storage_Order
11360 and then Ignore_Rep_Clauses)
11361 then
11362 return;
11363 end if;
11364
11365 -- Deal with unrecognized pragma
11366
11367 if not Is_Pragma_Name (Pname) then
11368 if Warn_On_Unrecognized_Pragma then
11369 Error_Msg_Name_1 := Pname;
11370 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
11371
11372 for PN in First_Pragma_Name .. Last_Pragma_Name loop
11373 if Is_Bad_Spelling_Of (Pname, PN) then
11374 Error_Msg_Name_1 := PN;
11375 Error_Msg_N -- CODEFIX
11376 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
11377 exit;
11378 end if;
11379 end loop;
11380 end if;
11381
11382 return;
11383 end if;
11384
11385 -- Here to start processing for recognized pragma
11386
11387 Pname := Original_Aspect_Pragma_Name (N);
11388
11389 -- Capture setting of Opt.Uneval_Old
11390
11391 case Opt.Uneval_Old is
11392 when 'A' =>
11393 Set_Uneval_Old_Accept (N);
11394
11395 when 'E' =>
11396 null;
11397
11398 when 'W' =>
11399 Set_Uneval_Old_Warn (N);
11400
11401 when others =>
11402 raise Program_Error;
11403 end case;
11404
11405 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
11406 -- is already set, indicating that we have already checked the policy
11407 -- at the right point. This happens for example in the case of a pragma
11408 -- that is derived from an Aspect.
11409
11410 if Is_Ignored (N) or else Is_Checked (N) then
11411 null;
11412
11413 -- For a pragma that is a rewriting of another pragma, copy the
11414 -- Is_Checked/Is_Ignored status from the rewritten pragma.
11415
11416 elsif Is_Rewrite_Substitution (N)
11417 and then Nkind (Original_Node (N)) = N_Pragma
11418 then
11419 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
11420 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
11421
11422 -- Otherwise query the applicable policy at this point
11423
11424 else
11425 Check_Applicable_Policy (N);
11426
11427 -- If pragma is disabled, rewrite as NULL and skip analysis
11428
11429 if Is_Disabled (N) then
11430 Rewrite (N, Make_Null_Statement (Loc));
11431 Analyze (N);
11432 raise Pragma_Exit;
11433 end if;
11434 end if;
11435
11436 -- Preset arguments
11437
11438 Arg_Count := 0;
11439 Arg1 := Empty;
11440 Arg2 := Empty;
11441 Arg3 := Empty;
11442 Arg4 := Empty;
11443
11444 if Present (Pragma_Argument_Associations (N)) then
11445 Arg_Count := List_Length (Pragma_Argument_Associations (N));
11446 Arg1 := First (Pragma_Argument_Associations (N));
11447
11448 if Present (Arg1) then
11449 Arg2 := Next (Arg1);
11450
11451 if Present (Arg2) then
11452 Arg3 := Next (Arg2);
11453
11454 if Present (Arg3) then
11455 Arg4 := Next (Arg3);
11456 end if;
11457 end if;
11458 end if;
11459 end if;
11460
11461 -- An enumeration type defines the pragmas that are supported by the
11462 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
11463 -- into the corresponding enumeration value for the following case.
11464
11465 case Prag_Id is
11466
11467 -----------------
11468 -- Abort_Defer --
11469 -----------------
11470
11471 -- pragma Abort_Defer;
11472
11473 when Pragma_Abort_Defer =>
11474 GNAT_Pragma;
11475 Check_Arg_Count (0);
11476
11477 -- The only required semantic processing is to check the
11478 -- placement. This pragma must appear at the start of the
11479 -- statement sequence of a handled sequence of statements.
11480
11481 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
11482 or else N /= First (Statements (Parent (N)))
11483 then
11484 Pragma_Misplaced;
11485 end if;
11486
11487 --------------------
11488 -- Abstract_State --
11489 --------------------
11490
11491 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
11492
11493 -- ABSTRACT_STATE_LIST ::=
11494 -- null
11495 -- | STATE_NAME_WITH_OPTIONS
11496 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
11497
11498 -- STATE_NAME_WITH_OPTIONS ::=
11499 -- STATE_NAME
11500 -- | (STATE_NAME with OPTION_LIST)
11501
11502 -- OPTION_LIST ::= OPTION {, OPTION}
11503
11504 -- OPTION ::=
11505 -- SIMPLE_OPTION
11506 -- | NAME_VALUE_OPTION
11507
11508 -- SIMPLE_OPTION ::= Ghost | Synchronous
11509
11510 -- NAME_VALUE_OPTION ::=
11511 -- Part_Of => ABSTRACT_STATE
11512 -- | External [=> EXTERNAL_PROPERTY_LIST]
11513
11514 -- EXTERNAL_PROPERTY_LIST ::=
11515 -- EXTERNAL_PROPERTY
11516 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
11517
11518 -- EXTERNAL_PROPERTY ::=
11519 -- Async_Readers [=> boolean_EXPRESSION]
11520 -- | Async_Writers [=> boolean_EXPRESSION]
11521 -- | Effective_Reads [=> boolean_EXPRESSION]
11522 -- | Effective_Writes [=> boolean_EXPRESSION]
11523 -- others => boolean_EXPRESSION
11524
11525 -- STATE_NAME ::= defining_identifier
11526
11527 -- ABSTRACT_STATE ::= name
11528
11529 -- Characteristics:
11530
11531 -- * Analysis - The annotation is fully analyzed immediately upon
11532 -- elaboration as it cannot forward reference entities.
11533
11534 -- * Expansion - None.
11535
11536 -- * Template - The annotation utilizes the generic template of the
11537 -- related package declaration.
11538
11539 -- * Globals - The annotation cannot reference global entities.
11540
11541 -- * Instance - The annotation is instantiated automatically when
11542 -- the related generic package is instantiated.
11543
11544 when Pragma_Abstract_State => Abstract_State : declare
11545 Missing_Parentheses : Boolean := False;
11546 -- Flag set when a state declaration with options is not properly
11547 -- parenthesized.
11548
11549 -- Flags used to verify the consistency of states
11550
11551 Non_Null_Seen : Boolean := False;
11552 Null_Seen : Boolean := False;
11553
11554 procedure Analyze_Abstract_State
11555 (State : Node_Id;
11556 Pack_Id : Entity_Id);
11557 -- Verify the legality of a single state declaration. Create and
11558 -- decorate a state abstraction entity and introduce it into the
11559 -- visibility chain. Pack_Id denotes the entity or the related
11560 -- package where pragma Abstract_State appears.
11561
11562 procedure Malformed_State_Error (State : Node_Id);
11563 -- Emit an error concerning the illegal declaration of abstract
11564 -- state State. This routine diagnoses syntax errors that lead to
11565 -- a different parse tree. The error is issued regardless of the
11566 -- SPARK mode in effect.
11567
11568 ----------------------------
11569 -- Analyze_Abstract_State --
11570 ----------------------------
11571
11572 procedure Analyze_Abstract_State
11573 (State : Node_Id;
11574 Pack_Id : Entity_Id)
11575 is
11576 -- Flags used to verify the consistency of options
11577
11578 AR_Seen : Boolean := False;
11579 AW_Seen : Boolean := False;
11580 ER_Seen : Boolean := False;
11581 EW_Seen : Boolean := False;
11582 External_Seen : Boolean := False;
11583 Ghost_Seen : Boolean := False;
11584 Others_Seen : Boolean := False;
11585 Part_Of_Seen : Boolean := False;
11586 Synchronous_Seen : Boolean := False;
11587
11588 -- Flags used to store the static value of all external states'
11589 -- expressions.
11590
11591 AR_Val : Boolean := False;
11592 AW_Val : Boolean := False;
11593 ER_Val : Boolean := False;
11594 EW_Val : Boolean := False;
11595
11596 State_Id : Entity_Id := Empty;
11597 -- The entity to be generated for the current state declaration
11598
11599 procedure Analyze_External_Option (Opt : Node_Id);
11600 -- Verify the legality of option External
11601
11602 procedure Analyze_External_Property
11603 (Prop : Node_Id;
11604 Expr : Node_Id := Empty);
11605 -- Verify the legailty of a single external property. Prop
11606 -- denotes the external property. Expr is the expression used
11607 -- to set the property.
11608
11609 procedure Analyze_Part_Of_Option (Opt : Node_Id);
11610 -- Verify the legality of option Part_Of
11611
11612 procedure Check_Duplicate_Option
11613 (Opt : Node_Id;
11614 Status : in out Boolean);
11615 -- Flag Status denotes whether a particular option has been
11616 -- seen while processing a state. This routine verifies that
11617 -- Opt is not a duplicate option and sets the flag Status
11618 -- (SPARK RM 7.1.4(1)).
11619
11620 procedure Check_Duplicate_Property
11621 (Prop : Node_Id;
11622 Status : in out Boolean);
11623 -- Flag Status denotes whether a particular property has been
11624 -- seen while processing option External. This routine verifies
11625 -- that Prop is not a duplicate property and sets flag Status.
11626 -- Opt is not a duplicate property and sets the flag Status.
11627 -- (SPARK RM 7.1.4(2))
11628
11629 procedure Check_Ghost_Synchronous;
11630 -- Ensure that the abstract state is not subject to both Ghost
11631 -- and Synchronous simple options. Emit an error if this is the
11632 -- case.
11633
11634 procedure Create_Abstract_State
11635 (Nam : Name_Id;
11636 Decl : Node_Id;
11637 Loc : Source_Ptr;
11638 Is_Null : Boolean);
11639 -- Generate an abstract state entity with name Nam and enter it
11640 -- into visibility. Decl is the "declaration" of the state as
11641 -- it appears in pragma Abstract_State. Loc is the location of
11642 -- the related state "declaration". Flag Is_Null should be set
11643 -- when the associated Abstract_State pragma defines a null
11644 -- state.
11645
11646 -----------------------------
11647 -- Analyze_External_Option --
11648 -----------------------------
11649
11650 procedure Analyze_External_Option (Opt : Node_Id) is
11651 Errors : constant Nat := Serious_Errors_Detected;
11652 Prop : Node_Id;
11653 Props : Node_Id := Empty;
11654
11655 begin
11656 if Nkind (Opt) = N_Component_Association then
11657 Props := Expression (Opt);
11658 end if;
11659
11660 -- External state with properties
11661
11662 if Present (Props) then
11663
11664 -- Multiple properties appear as an aggregate
11665
11666 if Nkind (Props) = N_Aggregate then
11667
11668 -- Simple property form
11669
11670 Prop := First (Expressions (Props));
11671 while Present (Prop) loop
11672 Analyze_External_Property (Prop);
11673 Next (Prop);
11674 end loop;
11675
11676 -- Property with expression form
11677
11678 Prop := First (Component_Associations (Props));
11679 while Present (Prop) loop
11680 Analyze_External_Property
11681 (Prop => First (Choices (Prop)),
11682 Expr => Expression (Prop));
11683
11684 Next (Prop);
11685 end loop;
11686
11687 -- Single property
11688
11689 else
11690 Analyze_External_Property (Props);
11691 end if;
11692
11693 -- An external state defined without any properties defaults
11694 -- all properties to True.
11695
11696 else
11697 AR_Val := True;
11698 AW_Val := True;
11699 ER_Val := True;
11700 EW_Val := True;
11701 end if;
11702
11703 -- Once all external properties have been processed, verify
11704 -- their mutual interaction. Do not perform the check when
11705 -- at least one of the properties is illegal as this will
11706 -- produce a bogus error.
11707
11708 if Errors = Serious_Errors_Detected then
11709 Check_External_Properties
11710 (State, AR_Val, AW_Val, ER_Val, EW_Val);
11711 end if;
11712 end Analyze_External_Option;
11713
11714 -------------------------------
11715 -- Analyze_External_Property --
11716 -------------------------------
11717
11718 procedure Analyze_External_Property
11719 (Prop : Node_Id;
11720 Expr : Node_Id := Empty)
11721 is
11722 Expr_Val : Boolean;
11723
11724 begin
11725 -- Check the placement of "others" (if available)
11726
11727 if Nkind (Prop) = N_Others_Choice then
11728 if Others_Seen then
11729 SPARK_Msg_N
11730 ("only one others choice allowed in option External",
11731 Prop);
11732 else
11733 Others_Seen := True;
11734 end if;
11735
11736 elsif Others_Seen then
11737 SPARK_Msg_N
11738 ("others must be the last property in option External",
11739 Prop);
11740
11741 -- The only remaining legal options are the four predefined
11742 -- external properties.
11743
11744 elsif Nkind (Prop) = N_Identifier
11745 and then Nam_In (Chars (Prop), Name_Async_Readers,
11746 Name_Async_Writers,
11747 Name_Effective_Reads,
11748 Name_Effective_Writes)
11749 then
11750 null;
11751
11752 -- Otherwise the construct is not a valid property
11753
11754 else
11755 SPARK_Msg_N ("invalid external state property", Prop);
11756 return;
11757 end if;
11758
11759 -- Ensure that the expression of the external state property
11760 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
11761
11762 if Present (Expr) then
11763 Analyze_And_Resolve (Expr, Standard_Boolean);
11764
11765 if Is_OK_Static_Expression (Expr) then
11766 Expr_Val := Is_True (Expr_Value (Expr));
11767 else
11768 SPARK_Msg_N
11769 ("expression of external state property must be "
11770 & "static", Expr);
11771 return;
11772 end if;
11773
11774 -- The lack of expression defaults the property to True
11775
11776 else
11777 Expr_Val := True;
11778 end if;
11779
11780 -- Named properties
11781
11782 if Nkind (Prop) = N_Identifier then
11783 if Chars (Prop) = Name_Async_Readers then
11784 Check_Duplicate_Property (Prop, AR_Seen);
11785 AR_Val := Expr_Val;
11786
11787 elsif Chars (Prop) = Name_Async_Writers then
11788 Check_Duplicate_Property (Prop, AW_Seen);
11789 AW_Val := Expr_Val;
11790
11791 elsif Chars (Prop) = Name_Effective_Reads then
11792 Check_Duplicate_Property (Prop, ER_Seen);
11793 ER_Val := Expr_Val;
11794
11795 else
11796 Check_Duplicate_Property (Prop, EW_Seen);
11797 EW_Val := Expr_Val;
11798 end if;
11799
11800 -- The handling of property "others" must take into account
11801 -- all other named properties that have been encountered so
11802 -- far. Only those that have not been seen are affected by
11803 -- "others".
11804
11805 else
11806 if not AR_Seen then
11807 AR_Val := Expr_Val;
11808 end if;
11809
11810 if not AW_Seen then
11811 AW_Val := Expr_Val;
11812 end if;
11813
11814 if not ER_Seen then
11815 ER_Val := Expr_Val;
11816 end if;
11817
11818 if not EW_Seen then
11819 EW_Val := Expr_Val;
11820 end if;
11821 end if;
11822 end Analyze_External_Property;
11823
11824 ----------------------------
11825 -- Analyze_Part_Of_Option --
11826 ----------------------------
11827
11828 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
11829 Encap : constant Node_Id := Expression (Opt);
11830 Constits : Elist_Id;
11831 Encap_Id : Entity_Id;
11832 Legal : Boolean;
11833
11834 begin
11835 Check_Duplicate_Option (Opt, Part_Of_Seen);
11836
11837 Analyze_Part_Of
11838 (Indic => First (Choices (Opt)),
11839 Item_Id => State_Id,
11840 Encap => Encap,
11841 Encap_Id => Encap_Id,
11842 Legal => Legal);
11843
11844 -- The Part_Of indicator transforms the abstract state into
11845 -- a constituent of the encapsulating state or single
11846 -- concurrent type.
11847
11848 if Legal then
11849 pragma Assert (Present (Encap_Id));
11850 Constits := Part_Of_Constituents (Encap_Id);
11851
11852 if No (Constits) then
11853 Constits := New_Elmt_List;
11854 Set_Part_Of_Constituents (Encap_Id, Constits);
11855 end if;
11856
11857 Append_Elmt (State_Id, Constits);
11858 Set_Encapsulating_State (State_Id, Encap_Id);
11859 end if;
11860 end Analyze_Part_Of_Option;
11861
11862 ----------------------------
11863 -- Check_Duplicate_Option --
11864 ----------------------------
11865
11866 procedure Check_Duplicate_Option
11867 (Opt : Node_Id;
11868 Status : in out Boolean)
11869 is
11870 begin
11871 if Status then
11872 SPARK_Msg_N ("duplicate state option", Opt);
11873 end if;
11874
11875 Status := True;
11876 end Check_Duplicate_Option;
11877
11878 ------------------------------
11879 -- Check_Duplicate_Property --
11880 ------------------------------
11881
11882 procedure Check_Duplicate_Property
11883 (Prop : Node_Id;
11884 Status : in out Boolean)
11885 is
11886 begin
11887 if Status then
11888 SPARK_Msg_N ("duplicate external property", Prop);
11889 end if;
11890
11891 Status := True;
11892 end Check_Duplicate_Property;
11893
11894 -----------------------------
11895 -- Check_Ghost_Synchronous --
11896 -----------------------------
11897
11898 procedure Check_Ghost_Synchronous is
11899 begin
11900 -- A synchronized abstract state cannot be Ghost and vice
11901 -- versa (SPARK RM 6.9(19)).
11902
11903 if Ghost_Seen and Synchronous_Seen then
11904 SPARK_Msg_N ("synchronized state cannot be ghost", State);
11905 end if;
11906 end Check_Ghost_Synchronous;
11907
11908 ---------------------------
11909 -- Create_Abstract_State --
11910 ---------------------------
11911
11912 procedure Create_Abstract_State
11913 (Nam : Name_Id;
11914 Decl : Node_Id;
11915 Loc : Source_Ptr;
11916 Is_Null : Boolean)
11917 is
11918 begin
11919 -- The abstract state may be semi-declared when the related
11920 -- package was withed through a limited with clause. In that
11921 -- case reuse the entity to fully declare the state.
11922
11923 if Present (Decl) and then Present (Entity (Decl)) then
11924 State_Id := Entity (Decl);
11925
11926 -- Otherwise the elaboration of pragma Abstract_State
11927 -- declares the state.
11928
11929 else
11930 State_Id := Make_Defining_Identifier (Loc, Nam);
11931
11932 if Present (Decl) then
11933 Set_Entity (Decl, State_Id);
11934 end if;
11935 end if;
11936
11937 -- Null states never come from source
11938
11939 Set_Comes_From_Source (State_Id, not Is_Null);
11940 Set_Parent (State_Id, State);
11941 Set_Ekind (State_Id, E_Abstract_State);
11942 Set_Etype (State_Id, Standard_Void_Type);
11943 Set_Encapsulating_State (State_Id, Empty);
11944
11945 -- Set the SPARK mode from the current context
11946
11947 Set_SPARK_Pragma (State_Id, SPARK_Mode_Pragma);
11948 Set_SPARK_Pragma_Inherited (State_Id);
11949
11950 -- An abstract state declared within a Ghost region becomes
11951 -- Ghost (SPARK RM 6.9(2)).
11952
11953 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then
11954 Set_Is_Ghost_Entity (State_Id);
11955 end if;
11956
11957 -- Establish a link between the state declaration and the
11958 -- abstract state entity. Note that a null state remains as
11959 -- N_Null and does not carry any linkages.
11960
11961 if not Is_Null then
11962 if Present (Decl) then
11963 Set_Entity (Decl, State_Id);
11964 Set_Etype (Decl, Standard_Void_Type);
11965 end if;
11966
11967 -- Every non-null state must be defined, nameable and
11968 -- resolvable.
11969
11970 Push_Scope (Pack_Id);
11971 Generate_Definition (State_Id);
11972 Enter_Name (State_Id);
11973 Pop_Scope;
11974 end if;
11975 end Create_Abstract_State;
11976
11977 -- Local variables
11978
11979 Opt : Node_Id;
11980 Opt_Nam : Node_Id;
11981
11982 -- Start of processing for Analyze_Abstract_State
11983
11984 begin
11985 -- A package with a null abstract state is not allowed to
11986 -- declare additional states.
11987
11988 if Null_Seen then
11989 SPARK_Msg_NE
11990 ("package & has null abstract state", State, Pack_Id);
11991
11992 -- Null states appear as internally generated entities
11993
11994 elsif Nkind (State) = N_Null then
11995 Create_Abstract_State
11996 (Nam => New_Internal_Name ('S'),
11997 Decl => Empty,
11998 Loc => Sloc (State),
11999 Is_Null => True);
12000 Null_Seen := True;
12001
12002 -- Catch a case where a null state appears in a list of
12003 -- non-null states.
12004
12005 if Non_Null_Seen then
12006 SPARK_Msg_NE
12007 ("package & has non-null abstract state",
12008 State, Pack_Id);
12009 end if;
12010
12011 -- Simple state declaration
12012
12013 elsif Nkind (State) = N_Identifier then
12014 Create_Abstract_State
12015 (Nam => Chars (State),
12016 Decl => State,
12017 Loc => Sloc (State),
12018 Is_Null => False);
12019 Non_Null_Seen := True;
12020
12021 -- State declaration with various options. This construct
12022 -- appears as an extension aggregate in the tree.
12023
12024 elsif Nkind (State) = N_Extension_Aggregate then
12025 if Nkind (Ancestor_Part (State)) = N_Identifier then
12026 Create_Abstract_State
12027 (Nam => Chars (Ancestor_Part (State)),
12028 Decl => Ancestor_Part (State),
12029 Loc => Sloc (Ancestor_Part (State)),
12030 Is_Null => False);
12031 Non_Null_Seen := True;
12032 else
12033 SPARK_Msg_N
12034 ("state name must be an identifier",
12035 Ancestor_Part (State));
12036 end if;
12037
12038 -- Options External, Ghost and Synchronous appear as
12039 -- expressions.
12040
12041 Opt := First (Expressions (State));
12042 while Present (Opt) loop
12043 if Nkind (Opt) = N_Identifier then
12044
12045 -- External
12046
12047 if Chars (Opt) = Name_External then
12048 Check_Duplicate_Option (Opt, External_Seen);
12049 Analyze_External_Option (Opt);
12050
12051 -- Ghost
12052
12053 elsif Chars (Opt) = Name_Ghost then
12054 Check_Duplicate_Option (Opt, Ghost_Seen);
12055 Check_Ghost_Synchronous;
12056
12057 if Present (State_Id) then
12058 Set_Is_Ghost_Entity (State_Id);
12059 end if;
12060
12061 -- Synchronous
12062
12063 elsif Chars (Opt) = Name_Synchronous then
12064 Check_Duplicate_Option (Opt, Synchronous_Seen);
12065 Check_Ghost_Synchronous;
12066
12067 -- Option Part_Of without an encapsulating state is
12068 -- illegal (SPARK RM 7.1.4(8)).
12069
12070 elsif Chars (Opt) = Name_Part_Of then
12071 SPARK_Msg_N
12072 ("indicator Part_Of must denote abstract state, "
12073 & "single protected type or single task type",
12074 Opt);
12075
12076 -- Do not emit an error message when a previous state
12077 -- declaration with options was not parenthesized as
12078 -- the option is actually another state declaration.
12079 --
12080 -- with Abstract_State
12081 -- (State_1 with ..., -- missing parentheses
12082 -- (State_2 with ...),
12083 -- State_3) -- ok state declaration
12084
12085 elsif Missing_Parentheses then
12086 null;
12087
12088 -- Otherwise the option is not allowed. Note that it
12089 -- is not possible to distinguish between an option
12090 -- and a state declaration when a previous state with
12091 -- options not properly parentheses.
12092 --
12093 -- with Abstract_State
12094 -- (State_1 with ..., -- missing parentheses
12095 -- State_2); -- could be an option
12096
12097 else
12098 SPARK_Msg_N
12099 ("simple option not allowed in state declaration",
12100 Opt);
12101 end if;
12102
12103 -- Catch a case where missing parentheses around a state
12104 -- declaration with options cause a subsequent state
12105 -- declaration with options to be treated as an option.
12106 --
12107 -- with Abstract_State
12108 -- (State_1 with ..., -- missing parentheses
12109 -- (State_2 with ...))
12110
12111 elsif Nkind (Opt) = N_Extension_Aggregate then
12112 Missing_Parentheses := True;
12113 SPARK_Msg_N
12114 ("state declaration must be parenthesized",
12115 Ancestor_Part (State));
12116
12117 -- Otherwise the option is malformed
12118
12119 else
12120 SPARK_Msg_N ("malformed option", Opt);
12121 end if;
12122
12123 Next (Opt);
12124 end loop;
12125
12126 -- Options External and Part_Of appear as component
12127 -- associations.
12128
12129 Opt := First (Component_Associations (State));
12130 while Present (Opt) loop
12131 Opt_Nam := First (Choices (Opt));
12132
12133 if Nkind (Opt_Nam) = N_Identifier then
12134 if Chars (Opt_Nam) = Name_External then
12135 Analyze_External_Option (Opt);
12136
12137 elsif Chars (Opt_Nam) = Name_Part_Of then
12138 Analyze_Part_Of_Option (Opt);
12139
12140 else
12141 SPARK_Msg_N ("invalid state option", Opt);
12142 end if;
12143 else
12144 SPARK_Msg_N ("invalid state option", Opt);
12145 end if;
12146
12147 Next (Opt);
12148 end loop;
12149
12150 -- Any other attempt to declare a state is illegal
12151
12152 else
12153 Malformed_State_Error (State);
12154 return;
12155 end if;
12156
12157 -- Guard against a junk state. In such cases no entity is
12158 -- generated and the subsequent checks cannot be applied.
12159
12160 if Present (State_Id) then
12161
12162 -- Verify whether the state does not introduce an illegal
12163 -- hidden state within a package subject to a null abstract
12164 -- state.
12165
12166 Check_No_Hidden_State (State_Id);
12167
12168 -- Check whether the lack of option Part_Of agrees with the
12169 -- placement of the abstract state with respect to the state
12170 -- space.
12171
12172 if not Part_Of_Seen then
12173 Check_Missing_Part_Of (State_Id);
12174 end if;
12175
12176 -- Associate the state with its related package
12177
12178 if No (Abstract_States (Pack_Id)) then
12179 Set_Abstract_States (Pack_Id, New_Elmt_List);
12180 end if;
12181
12182 Append_Elmt (State_Id, Abstract_States (Pack_Id));
12183 end if;
12184 end Analyze_Abstract_State;
12185
12186 ---------------------------
12187 -- Malformed_State_Error --
12188 ---------------------------
12189
12190 procedure Malformed_State_Error (State : Node_Id) is
12191 begin
12192 Error_Msg_N ("malformed abstract state declaration", State);
12193
12194 -- An abstract state with a simple option is being declared
12195 -- with "=>" rather than the legal "with". The state appears
12196 -- as a component association.
12197
12198 if Nkind (State) = N_Component_Association then
12199 Error_Msg_N ("\use WITH to specify simple option", State);
12200 end if;
12201 end Malformed_State_Error;
12202
12203 -- Local variables
12204
12205 Pack_Decl : Node_Id;
12206 Pack_Id : Entity_Id;
12207 State : Node_Id;
12208 States : Node_Id;
12209
12210 -- Start of processing for Abstract_State
12211
12212 begin
12213 GNAT_Pragma;
12214 Check_No_Identifiers;
12215 Check_Arg_Count (1);
12216
12217 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
12218
12219 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
12220 N_Package_Declaration)
12221 then
12222 Pragma_Misplaced;
12223 return;
12224 end if;
12225
12226 Pack_Id := Defining_Entity (Pack_Decl);
12227
12228 -- A pragma that applies to a Ghost entity becomes Ghost for the
12229 -- purposes of legality checks and removal of ignored Ghost code.
12230
12231 Mark_Ghost_Pragma (N, Pack_Id);
12232 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
12233
12234 -- Chain the pragma on the contract for completeness
12235
12236 Add_Contract_Item (N, Pack_Id);
12237
12238 -- The legality checks of pragmas Abstract_State, Initializes, and
12239 -- Initial_Condition are affected by the SPARK mode in effect. In
12240 -- addition, these three pragmas are subject to an inherent order:
12241
12242 -- 1) Abstract_State
12243 -- 2) Initializes
12244 -- 3) Initial_Condition
12245
12246 -- Analyze all these pragmas in the order outlined above
12247
12248 Analyze_If_Present (Pragma_SPARK_Mode);
12249 States := Expression (Get_Argument (N, Pack_Id));
12250
12251 -- Multiple non-null abstract states appear as an aggregate
12252
12253 if Nkind (States) = N_Aggregate then
12254 State := First (Expressions (States));
12255 while Present (State) loop
12256 Analyze_Abstract_State (State, Pack_Id);
12257 Next (State);
12258 end loop;
12259
12260 -- An abstract state with a simple option is being illegaly
12261 -- declared with "=>" rather than "with". In this case the
12262 -- state declaration appears as a component association.
12263
12264 if Present (Component_Associations (States)) then
12265 State := First (Component_Associations (States));
12266 while Present (State) loop
12267 Malformed_State_Error (State);
12268 Next (State);
12269 end loop;
12270 end if;
12271
12272 -- Various forms of a single abstract state. Note that these may
12273 -- include malformed state declarations.
12274
12275 else
12276 Analyze_Abstract_State (States, Pack_Id);
12277 end if;
12278
12279 Analyze_If_Present (Pragma_Initializes);
12280 Analyze_If_Present (Pragma_Initial_Condition);
12281 end Abstract_State;
12282
12283 ------------
12284 -- Ada_83 --
12285 ------------
12286
12287 -- pragma Ada_83;
12288
12289 -- Note: this pragma also has some specific processing in Par.Prag
12290 -- because we want to set the Ada version mode during parsing.
12291
12292 when Pragma_Ada_83 =>
12293 GNAT_Pragma;
12294 Check_Arg_Count (0);
12295
12296 -- We really should check unconditionally for proper configuration
12297 -- pragma placement, since we really don't want mixed Ada modes
12298 -- within a single unit, and the GNAT reference manual has always
12299 -- said this was a configuration pragma, but we did not check and
12300 -- are hesitant to add the check now.
12301
12302 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
12303 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
12304 -- or Ada 2012 mode.
12305
12306 if Ada_Version >= Ada_2005 then
12307 Check_Valid_Configuration_Pragma;
12308 end if;
12309
12310 -- Now set Ada 83 mode
12311
12312 if Latest_Ada_Only then
12313 Error_Pragma ("??pragma% ignored");
12314 else
12315 Ada_Version := Ada_83;
12316 Ada_Version_Explicit := Ada_83;
12317 Ada_Version_Pragma := N;
12318 end if;
12319
12320 ------------
12321 -- Ada_95 --
12322 ------------
12323
12324 -- pragma Ada_95;
12325
12326 -- Note: this pragma also has some specific processing in Par.Prag
12327 -- because we want to set the Ada 83 version mode during parsing.
12328
12329 when Pragma_Ada_95 =>
12330 GNAT_Pragma;
12331 Check_Arg_Count (0);
12332
12333 -- We really should check unconditionally for proper configuration
12334 -- pragma placement, since we really don't want mixed Ada modes
12335 -- within a single unit, and the GNAT reference manual has always
12336 -- said this was a configuration pragma, but we did not check and
12337 -- are hesitant to add the check now.
12338
12339 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
12340 -- or Ada 95, so we must check if we are in Ada 2005 mode.
12341
12342 if Ada_Version >= Ada_2005 then
12343 Check_Valid_Configuration_Pragma;
12344 end if;
12345
12346 -- Now set Ada 95 mode
12347
12348 if Latest_Ada_Only then
12349 Error_Pragma ("??pragma% ignored");
12350 else
12351 Ada_Version := Ada_95;
12352 Ada_Version_Explicit := Ada_95;
12353 Ada_Version_Pragma := N;
12354 end if;
12355
12356 ---------------------
12357 -- Ada_05/Ada_2005 --
12358 ---------------------
12359
12360 -- pragma Ada_05;
12361 -- pragma Ada_05 (LOCAL_NAME);
12362
12363 -- pragma Ada_2005;
12364 -- pragma Ada_2005 (LOCAL_NAME):
12365
12366 -- Note: these pragmas also have some specific processing in Par.Prag
12367 -- because we want to set the Ada 2005 version mode during parsing.
12368
12369 -- The one argument form is used for managing the transition from
12370 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
12371 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
12372 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
12373 -- mode, a preference rule is established which does not choose
12374 -- such an entity unless it is unambiguously specified. This avoids
12375 -- extra subprograms marked this way from generating ambiguities in
12376 -- otherwise legal pre-Ada_2005 programs. The one argument form is
12377 -- intended for exclusive use in the GNAT run-time library.
12378
12379 when Pragma_Ada_05
12380 | Pragma_Ada_2005
12381 =>
12382 declare
12383 E_Id : Node_Id;
12384
12385 begin
12386 GNAT_Pragma;
12387
12388 if Arg_Count = 1 then
12389 Check_Arg_Is_Local_Name (Arg1);
12390 E_Id := Get_Pragma_Arg (Arg1);
12391
12392 if Etype (E_Id) = Any_Type then
12393 return;
12394 end if;
12395
12396 Set_Is_Ada_2005_Only (Entity (E_Id));
12397 Record_Rep_Item (Entity (E_Id), N);
12398
12399 else
12400 Check_Arg_Count (0);
12401
12402 -- For Ada_2005 we unconditionally enforce the documented
12403 -- configuration pragma placement, since we do not want to
12404 -- tolerate mixed modes in a unit involving Ada 2005. That
12405 -- would cause real difficulties for those cases where there
12406 -- are incompatibilities between Ada 95 and Ada 2005.
12407
12408 Check_Valid_Configuration_Pragma;
12409
12410 -- Now set appropriate Ada mode
12411
12412 if Latest_Ada_Only then
12413 Error_Pragma ("??pragma% ignored");
12414 else
12415 Ada_Version := Ada_2005;
12416 Ada_Version_Explicit := Ada_2005;
12417 Ada_Version_Pragma := N;
12418 end if;
12419 end if;
12420 end;
12421
12422 ---------------------
12423 -- Ada_12/Ada_2012 --
12424 ---------------------
12425
12426 -- pragma Ada_12;
12427 -- pragma Ada_12 (LOCAL_NAME);
12428
12429 -- pragma Ada_2012;
12430 -- pragma Ada_2012 (LOCAL_NAME):
12431
12432 -- Note: these pragmas also have some specific processing in Par.Prag
12433 -- because we want to set the Ada 2012 version mode during parsing.
12434
12435 -- The one argument form is used for managing the transition from Ada
12436 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
12437 -- as Ada_2012 only, then referencing the entity in any pre-Ada_2012
12438 -- mode will generate a warning. In addition, in any pre-Ada_2012
12439 -- mode, a preference rule is established which does not choose
12440 -- such an entity unless it is unambiguously specified. This avoids
12441 -- extra subprograms marked this way from generating ambiguities in
12442 -- otherwise legal pre-Ada_2012 programs. The one argument form is
12443 -- intended for exclusive use in the GNAT run-time library.
12444
12445 when Pragma_Ada_12
12446 | Pragma_Ada_2012
12447 =>
12448 declare
12449 E_Id : Node_Id;
12450
12451 begin
12452 GNAT_Pragma;
12453
12454 if Arg_Count = 1 then
12455 Check_Arg_Is_Local_Name (Arg1);
12456 E_Id := Get_Pragma_Arg (Arg1);
12457
12458 if Etype (E_Id) = Any_Type then
12459 return;
12460 end if;
12461
12462 Set_Is_Ada_2012_Only (Entity (E_Id));
12463 Record_Rep_Item (Entity (E_Id), N);
12464
12465 else
12466 Check_Arg_Count (0);
12467
12468 -- For Ada_2012 we unconditionally enforce the documented
12469 -- configuration pragma placement, since we do not want to
12470 -- tolerate mixed modes in a unit involving Ada 2012. That
12471 -- would cause real difficulties for those cases where there
12472 -- are incompatibilities between Ada 95 and Ada 2012. We could
12473 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
12474
12475 Check_Valid_Configuration_Pragma;
12476
12477 -- Now set appropriate Ada mode
12478
12479 Ada_Version := Ada_2012;
12480 Ada_Version_Explicit := Ada_2012;
12481 Ada_Version_Pragma := N;
12482 end if;
12483 end;
12484
12485 --------------
12486 -- Ada_2020 --
12487 --------------
12488
12489 -- pragma Ada_2020;
12490
12491 -- Note: this pragma also has some specific processing in Par.Prag
12492 -- because we want to set the Ada 2020 version mode during parsing.
12493
12494 when Pragma_Ada_2020 =>
12495 GNAT_Pragma;
12496
12497 Check_Arg_Count (0);
12498
12499 Check_Valid_Configuration_Pragma;
12500
12501 -- Now set appropriate Ada mode
12502
12503 Ada_Version := Ada_2020;
12504 Ada_Version_Explicit := Ada_2020;
12505 Ada_Version_Pragma := N;
12506
12507 -------------------------------------
12508 -- Aggregate_Individually_Assign --
12509 -------------------------------------
12510
12511 -- pragma Aggregate_Individually_Assign;
12512
12513 when Pragma_Aggregate_Individually_Assign =>
12514 GNAT_Pragma;
12515 Check_Arg_Count (0);
12516 Check_Valid_Configuration_Pragma;
12517 Aggregate_Individually_Assign := True;
12518
12519 ----------------------
12520 -- All_Calls_Remote --
12521 ----------------------
12522
12523 -- pragma All_Calls_Remote [(library_package_NAME)];
12524
12525 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
12526 Lib_Entity : Entity_Id;
12527
12528 begin
12529 Check_Ada_83_Warning;
12530 Check_Valid_Library_Unit_Pragma;
12531
12532 if Nkind (N) = N_Null_Statement then
12533 return;
12534 end if;
12535
12536 Lib_Entity := Find_Lib_Unit_Name;
12537
12538 -- A pragma that applies to a Ghost entity becomes Ghost for the
12539 -- purposes of legality checks and removal of ignored Ghost code.
12540
12541 Mark_Ghost_Pragma (N, Lib_Entity);
12542
12543 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
12544
12545 if Present (Lib_Entity) and then not Debug_Flag_U then
12546 if not Is_Remote_Call_Interface (Lib_Entity) then
12547 Error_Pragma ("pragma% only apply to rci unit");
12548
12549 -- Set flag for entity of the library unit
12550
12551 else
12552 Set_Has_All_Calls_Remote (Lib_Entity);
12553 end if;
12554 end if;
12555 end All_Calls_Remote;
12556
12557 ---------------------------
12558 -- Allow_Integer_Address --
12559 ---------------------------
12560
12561 -- pragma Allow_Integer_Address;
12562
12563 when Pragma_Allow_Integer_Address =>
12564 GNAT_Pragma;
12565 Check_Valid_Configuration_Pragma;
12566 Check_Arg_Count (0);
12567
12568 -- If Address is a private type, then set the flag to allow
12569 -- integer address values. If Address is not private, then this
12570 -- pragma has no purpose, so it is simply ignored. Not clear if
12571 -- there are any such targets now.
12572
12573 if Opt.Address_Is_Private then
12574 Opt.Allow_Integer_Address := True;
12575 end if;
12576
12577 --------------
12578 -- Annotate --
12579 --------------
12580
12581 -- pragma Annotate
12582 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
12583 -- ARG ::= NAME | EXPRESSION
12584
12585 -- The first two arguments are by convention intended to refer to an
12586 -- external tool and a tool-specific function. These arguments are
12587 -- not analyzed.
12588
12589 when Pragma_Annotate => Annotate : declare
12590 Arg : Node_Id;
12591 Expr : Node_Id;
12592 Nam_Arg : Node_Id;
12593
12594 --------------------------
12595 -- Inferred_String_Type --
12596 --------------------------
12597
12598 function Preferred_String_Type (Expr : Node_Id) return Entity_Id;
12599 -- Infer the type to use for a string literal or a concatentation
12600 -- of operands whose types can be inferred. For such expressions,
12601 -- returns the "narrowest" of the three predefined string types
12602 -- that can represent the characters occurring in the expression.
12603 -- For other expressions, returns Empty.
12604
12605 function Preferred_String_Type (Expr : Node_Id) return Entity_Id is
12606 begin
12607 case Nkind (Expr) is
12608 when N_String_Literal =>
12609 if Has_Wide_Wide_Character (Expr) then
12610 return Standard_Wide_Wide_String;
12611 elsif Has_Wide_Character (Expr) then
12612 return Standard_Wide_String;
12613 else
12614 return Standard_String;
12615 end if;
12616
12617 when N_Op_Concat =>
12618 declare
12619 L_Type : constant Entity_Id
12620 := Preferred_String_Type (Left_Opnd (Expr));
12621 R_Type : constant Entity_Id
12622 := Preferred_String_Type (Right_Opnd (Expr));
12623
12624 Type_Table : constant array (1 .. 4) of Entity_Id
12625 := (Empty,
12626 Standard_Wide_Wide_String,
12627 Standard_Wide_String,
12628 Standard_String);
12629 begin
12630 for Idx in Type_Table'Range loop
12631 if (L_Type = Type_Table (Idx)) or
12632 (R_Type = Type_Table (Idx))
12633 then
12634 return Type_Table (Idx);
12635 end if;
12636 end loop;
12637 raise Program_Error;
12638 end;
12639
12640 when others =>
12641 return Empty;
12642 end case;
12643 end Preferred_String_Type;
12644 begin
12645 GNAT_Pragma;
12646 Check_At_Least_N_Arguments (1);
12647
12648 Nam_Arg := Last (Pragma_Argument_Associations (N));
12649
12650 -- Determine whether the last argument is "Entity => local_NAME"
12651 -- and if it is, perform the required semantic checks. Remove the
12652 -- argument from further processing.
12653
12654 if Nkind (Nam_Arg) = N_Pragma_Argument_Association
12655 and then Chars (Nam_Arg) = Name_Entity
12656 then
12657 Check_Arg_Is_Local_Name (Nam_Arg);
12658 Arg_Count := Arg_Count - 1;
12659
12660 -- A pragma that applies to a Ghost entity becomes Ghost for
12661 -- the purposes of legality checks and removal of ignored Ghost
12662 -- code.
12663
12664 if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg))
12665 and then Present (Entity (Get_Pragma_Arg (Nam_Arg)))
12666 then
12667 Mark_Ghost_Pragma (N, Entity (Get_Pragma_Arg (Nam_Arg)));
12668 end if;
12669
12670 -- Not allowed in compiler units (bootstrap issues)
12671
12672 Check_Compiler_Unit ("Entity for pragma Annotate", N);
12673 end if;
12674
12675 -- Continue the processing with last argument removed for now
12676
12677 Check_Arg_Is_Identifier (Arg1);
12678 Check_No_Identifiers;
12679 Store_Note (N);
12680
12681 -- The second parameter is optional, it is never analyzed
12682
12683 if No (Arg2) then
12684 null;
12685
12686 -- Otherwise there is a second parameter
12687
12688 else
12689 -- The second parameter must be an identifier
12690
12691 Check_Arg_Is_Identifier (Arg2);
12692
12693 -- Process the remaining parameters (if any)
12694
12695 Arg := Next (Arg2);
12696 while Present (Arg) loop
12697 Expr := Get_Pragma_Arg (Arg);
12698 Analyze (Expr);
12699
12700 if Is_Entity_Name (Expr) then
12701 null;
12702
12703 -- For string literals and concatenations of string literals
12704 -- we assume Standard_String as the type, unless the string
12705 -- contains wide or wide_wide characters.
12706
12707 elsif Present (Preferred_String_Type (Expr)) then
12708 Resolve (Expr, Preferred_String_Type (Expr));
12709
12710 elsif Is_Overloaded (Expr) then
12711 Error_Pragma_Arg ("ambiguous argument for pragma%", Expr);
12712
12713 else
12714 Resolve (Expr);
12715 end if;
12716
12717 Next (Arg);
12718 end loop;
12719 end if;
12720 end Annotate;
12721
12722 -------------------------------------------------
12723 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
12724 -------------------------------------------------
12725
12726 -- pragma Assert
12727 -- ( [Check => ] Boolean_EXPRESSION
12728 -- [, [Message =>] Static_String_EXPRESSION]);
12729
12730 -- pragma Assert_And_Cut
12731 -- ( [Check => ] Boolean_EXPRESSION
12732 -- [, [Message =>] Static_String_EXPRESSION]);
12733
12734 -- pragma Assume
12735 -- ( [Check => ] Boolean_EXPRESSION
12736 -- [, [Message =>] Static_String_EXPRESSION]);
12737
12738 -- pragma Loop_Invariant
12739 -- ( [Check => ] Boolean_EXPRESSION
12740 -- [, [Message =>] Static_String_EXPRESSION]);
12741
12742 when Pragma_Assert
12743 | Pragma_Assert_And_Cut
12744 | Pragma_Assume
12745 | Pragma_Loop_Invariant
12746 =>
12747 Assert : declare
12748 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
12749 -- Determine whether expression Expr contains a Loop_Entry
12750 -- attribute reference.
12751
12752 -------------------------
12753 -- Contains_Loop_Entry --
12754 -------------------------
12755
12756 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
12757 Has_Loop_Entry : Boolean := False;
12758
12759 function Process (N : Node_Id) return Traverse_Result;
12760 -- Process function for traversal to look for Loop_Entry
12761
12762 -------------
12763 -- Process --
12764 -------------
12765
12766 function Process (N : Node_Id) return Traverse_Result is
12767 begin
12768 if Nkind (N) = N_Attribute_Reference
12769 and then Attribute_Name (N) = Name_Loop_Entry
12770 then
12771 Has_Loop_Entry := True;
12772 return Abandon;
12773 else
12774 return OK;
12775 end if;
12776 end Process;
12777
12778 procedure Traverse is new Traverse_Proc (Process);
12779
12780 -- Start of processing for Contains_Loop_Entry
12781
12782 begin
12783 Traverse (Expr);
12784 return Has_Loop_Entry;
12785 end Contains_Loop_Entry;
12786
12787 -- Local variables
12788
12789 Expr : Node_Id;
12790 New_Args : List_Id;
12791
12792 -- Start of processing for Assert
12793
12794 begin
12795 -- Assert is an Ada 2005 RM-defined pragma
12796
12797 if Prag_Id = Pragma_Assert then
12798 Ada_2005_Pragma;
12799
12800 -- The remaining ones are GNAT pragmas
12801
12802 else
12803 GNAT_Pragma;
12804 end if;
12805
12806 Check_At_Least_N_Arguments (1);
12807 Check_At_Most_N_Arguments (2);
12808 Check_Arg_Order ((Name_Check, Name_Message));
12809 Check_Optional_Identifier (Arg1, Name_Check);
12810 Expr := Get_Pragma_Arg (Arg1);
12811
12812 -- Special processing for Loop_Invariant, Loop_Variant or for
12813 -- other cases where a Loop_Entry attribute is present. If the
12814 -- assertion pragma contains attribute Loop_Entry, ensure that
12815 -- the related pragma is within a loop.
12816
12817 if Prag_Id = Pragma_Loop_Invariant
12818 or else Prag_Id = Pragma_Loop_Variant
12819 or else Contains_Loop_Entry (Expr)
12820 then
12821 Check_Loop_Pragma_Placement;
12822
12823 -- Perform preanalysis to deal with embedded Loop_Entry
12824 -- attributes.
12825
12826 Preanalyze_Assert_Expression (Expr, Any_Boolean);
12827 end if;
12828
12829 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
12830 -- a corresponding Check pragma:
12831
12832 -- pragma Check (name, condition [, msg]);
12833
12834 -- Where name is the identifier matching the pragma name. So
12835 -- rewrite pragma in this manner, transfer the message argument
12836 -- if present, and analyze the result
12837
12838 -- Note: When dealing with a semantically analyzed tree, the
12839 -- information that a Check node N corresponds to a source Assert,
12840 -- Assume, or Assert_And_Cut pragma can be retrieved from the
12841 -- pragma kind of Original_Node(N).
12842
12843 New_Args := New_List (
12844 Make_Pragma_Argument_Association (Loc,
12845 Expression => Make_Identifier (Loc, Pname)),
12846 Make_Pragma_Argument_Association (Sloc (Expr),
12847 Expression => Expr));
12848
12849 if Arg_Count > 1 then
12850 Check_Optional_Identifier (Arg2, Name_Message);
12851
12852 -- Provide semantic annotations for optional argument, for
12853 -- ASIS use, before rewriting.
12854 -- Is this still needed???
12855
12856 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
12857 Append_To (New_Args, New_Copy_Tree (Arg2));
12858 end if;
12859
12860 -- Rewrite as Check pragma
12861
12862 Rewrite (N,
12863 Make_Pragma (Loc,
12864 Chars => Name_Check,
12865 Pragma_Argument_Associations => New_Args));
12866
12867 Analyze (N);
12868 end Assert;
12869
12870 ----------------------
12871 -- Assertion_Policy --
12872 ----------------------
12873
12874 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
12875
12876 -- The following form is Ada 2012 only, but we allow it in all modes
12877
12878 -- Pragma Assertion_Policy (
12879 -- ASSERTION_KIND => POLICY_IDENTIFIER
12880 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
12881
12882 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
12883
12884 -- RM_ASSERTION_KIND ::= Assert |
12885 -- Static_Predicate |
12886 -- Dynamic_Predicate |
12887 -- Pre |
12888 -- Pre'Class |
12889 -- Post |
12890 -- Post'Class |
12891 -- Type_Invariant |
12892 -- Type_Invariant'Class
12893
12894 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
12895 -- Assume |
12896 -- Contract_Cases |
12897 -- Debug |
12898 -- Default_Initial_Condition |
12899 -- Ghost |
12900 -- Initial_Condition |
12901 -- Loop_Invariant |
12902 -- Loop_Variant |
12903 -- Postcondition |
12904 -- Precondition |
12905 -- Predicate |
12906 -- Refined_Post |
12907 -- Statement_Assertions
12908
12909 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
12910 -- ID_ASSERTION_KIND list contains implementation-defined additions
12911 -- recognized by GNAT. The effect is to control the behavior of
12912 -- identically named aspects and pragmas, depending on the specified
12913 -- policy identifier:
12914
12915 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
12916
12917 -- Note: Check and Ignore are language-defined. Disable is a GNAT
12918 -- implementation-defined addition that results in totally ignoring
12919 -- the corresponding assertion. If Disable is specified, then the
12920 -- argument of the assertion is not even analyzed. This is useful
12921 -- when the aspect/pragma argument references entities in a with'ed
12922 -- package that is replaced by a dummy package in the final build.
12923
12924 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
12925 -- and Type_Invariant'Class were recognized by the parser and
12926 -- transformed into references to the special internal identifiers
12927 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
12928 -- processing is required here.
12929
12930 when Pragma_Assertion_Policy => Assertion_Policy : declare
12931 procedure Resolve_Suppressible (Policy : Node_Id);
12932 -- Converts the assertion policy 'Suppressible' to either Check or
12933 -- Ignore based on whether checks are suppressed via -gnatp.
12934
12935 --------------------------
12936 -- Resolve_Suppressible --
12937 --------------------------
12938
12939 procedure Resolve_Suppressible (Policy : Node_Id) is
12940 Arg : constant Node_Id := Get_Pragma_Arg (Policy);
12941 Nam : Name_Id;
12942
12943 begin
12944 -- Transform policy argument Suppressible into either Ignore or
12945 -- Check depending on whether checks are enabled or suppressed.
12946
12947 if Chars (Arg) = Name_Suppressible then
12948 if Suppress_Checks then
12949 Nam := Name_Ignore;
12950 else
12951 Nam := Name_Check;
12952 end if;
12953
12954 Rewrite (Arg, Make_Identifier (Sloc (Arg), Nam));
12955 end if;
12956 end Resolve_Suppressible;
12957
12958 -- Local variables
12959
12960 Arg : Node_Id;
12961 Kind : Name_Id;
12962 LocP : Source_Ptr;
12963 Policy : Node_Id;
12964
12965 begin
12966 Ada_2005_Pragma;
12967
12968 -- This can always appear as a configuration pragma
12969
12970 if Is_Configuration_Pragma then
12971 null;
12972
12973 -- It can also appear in a declarative part or package spec in Ada
12974 -- 2012 mode. We allow this in other modes, but in that case we
12975 -- consider that we have an Ada 2012 pragma on our hands.
12976
12977 else
12978 Check_Is_In_Decl_Part_Or_Package_Spec;
12979 Ada_2012_Pragma;
12980 end if;
12981
12982 -- One argument case with no identifier (first form above)
12983
12984 if Arg_Count = 1
12985 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
12986 or else Chars (Arg1) = No_Name)
12987 then
12988 Check_Arg_Is_One_Of (Arg1,
12989 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
12990
12991 Resolve_Suppressible (Arg1);
12992
12993 -- Treat one argument Assertion_Policy as equivalent to:
12994
12995 -- pragma Check_Policy (Assertion, policy)
12996
12997 -- So rewrite pragma in that manner and link on to the chain
12998 -- of Check_Policy pragmas, marking the pragma as analyzed.
12999
13000 Policy := Get_Pragma_Arg (Arg1);
13001
13002 Rewrite (N,
13003 Make_Pragma (Loc,
13004 Chars => Name_Check_Policy,
13005 Pragma_Argument_Associations => New_List (
13006 Make_Pragma_Argument_Association (Loc,
13007 Expression => Make_Identifier (Loc, Name_Assertion)),
13008
13009 Make_Pragma_Argument_Association (Loc,
13010 Expression =>
13011 Make_Identifier (Sloc (Policy), Chars (Policy))))));
13012 Analyze (N);
13013
13014 -- Here if we have two or more arguments
13015
13016 else
13017 Check_At_Least_N_Arguments (1);
13018 Ada_2012_Pragma;
13019
13020 -- Loop through arguments
13021
13022 Arg := Arg1;
13023 while Present (Arg) loop
13024 LocP := Sloc (Arg);
13025
13026 -- Kind must be specified
13027
13028 if Nkind (Arg) /= N_Pragma_Argument_Association
13029 or else Chars (Arg) = No_Name
13030 then
13031 Error_Pragma_Arg
13032 ("missing assertion kind for pragma%", Arg);
13033 end if;
13034
13035 -- Check Kind and Policy have allowed forms
13036
13037 Kind := Chars (Arg);
13038 Policy := Get_Pragma_Arg (Arg);
13039
13040 if not Is_Valid_Assertion_Kind (Kind) then
13041 Error_Pragma_Arg
13042 ("invalid assertion kind for pragma%", Arg);
13043 end if;
13044
13045 Check_Arg_Is_One_Of (Arg,
13046 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13047
13048 Resolve_Suppressible (Arg);
13049
13050 if Kind = Name_Ghost then
13051
13052 -- The Ghost policy must be either Check or Ignore
13053 -- (SPARK RM 6.9(6)).
13054
13055 if not Nam_In (Chars (Policy), Name_Check,
13056 Name_Ignore)
13057 then
13058 Error_Pragma_Arg
13059 ("argument of pragma % Ghost must be Check or "
13060 & "Ignore", Policy);
13061 end if;
13062
13063 -- Pragma Assertion_Policy specifying a Ghost policy
13064 -- cannot occur within a Ghost subprogram or package
13065 -- (SPARK RM 6.9(14)).
13066
13067 if Ghost_Mode > None then
13068 Error_Pragma
13069 ("pragma % cannot appear within ghost subprogram or "
13070 & "package");
13071 end if;
13072 end if;
13073
13074 -- Rewrite the Assertion_Policy pragma as a series of
13075 -- Check_Policy pragmas of the form:
13076
13077 -- Check_Policy (Kind, Policy);
13078
13079 -- Note: the insertion of the pragmas cannot be done with
13080 -- Insert_Action because in the configuration case, there
13081 -- are no scopes on the scope stack and the mechanism will
13082 -- fail.
13083
13084 Insert_Before_And_Analyze (N,
13085 Make_Pragma (LocP,
13086 Chars => Name_Check_Policy,
13087 Pragma_Argument_Associations => New_List (
13088 Make_Pragma_Argument_Association (LocP,
13089 Expression => Make_Identifier (LocP, Kind)),
13090 Make_Pragma_Argument_Association (LocP,
13091 Expression => Policy))));
13092
13093 Arg := Next (Arg);
13094 end loop;
13095
13096 -- Rewrite the Assertion_Policy pragma as null since we have
13097 -- now inserted all the equivalent Check pragmas.
13098
13099 Rewrite (N, Make_Null_Statement (Loc));
13100 Analyze (N);
13101 end if;
13102 end Assertion_Policy;
13103
13104 ------------------------------
13105 -- Assume_No_Invalid_Values --
13106 ------------------------------
13107
13108 -- pragma Assume_No_Invalid_Values (On | Off);
13109
13110 when Pragma_Assume_No_Invalid_Values =>
13111 GNAT_Pragma;
13112 Check_Valid_Configuration_Pragma;
13113 Check_Arg_Count (1);
13114 Check_No_Identifiers;
13115 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13116
13117 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
13118 Assume_No_Invalid_Values := True;
13119 else
13120 Assume_No_Invalid_Values := False;
13121 end if;
13122
13123 --------------------------
13124 -- Attribute_Definition --
13125 --------------------------
13126
13127 -- pragma Attribute_Definition
13128 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
13129 -- [Entity =>] LOCAL_NAME,
13130 -- [Expression =>] EXPRESSION | NAME);
13131
13132 when Pragma_Attribute_Definition => Attribute_Definition : declare
13133 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
13134 Aname : Name_Id;
13135
13136 begin
13137 GNAT_Pragma;
13138 Check_Arg_Count (3);
13139 Check_Optional_Identifier (Arg1, "attribute");
13140 Check_Optional_Identifier (Arg2, "entity");
13141 Check_Optional_Identifier (Arg3, "expression");
13142
13143 if Nkind (Attribute_Designator) /= N_Identifier then
13144 Error_Msg_N ("attribute name expected", Attribute_Designator);
13145 return;
13146 end if;
13147
13148 Check_Arg_Is_Local_Name (Arg2);
13149
13150 -- If the attribute is not recognized, then issue a warning (not
13151 -- an error), and ignore the pragma.
13152
13153 Aname := Chars (Attribute_Designator);
13154
13155 if not Is_Attribute_Name (Aname) then
13156 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
13157 return;
13158 end if;
13159
13160 -- Otherwise, rewrite the pragma as an attribute definition clause
13161
13162 Rewrite (N,
13163 Make_Attribute_Definition_Clause (Loc,
13164 Name => Get_Pragma_Arg (Arg2),
13165 Chars => Aname,
13166 Expression => Get_Pragma_Arg (Arg3)));
13167 Analyze (N);
13168 end Attribute_Definition;
13169
13170 ------------------------------------------------------------------
13171 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
13172 -- No_Caching --
13173 ------------------------------------------------------------------
13174
13175 -- pragma Async_Readers [ (boolean_EXPRESSION) ];
13176 -- pragma Async_Writers [ (boolean_EXPRESSION) ];
13177 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
13178 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
13179 -- pragma No_Caching [ (boolean_EXPRESSION) ];
13180
13181 when Pragma_Async_Readers
13182 | Pragma_Async_Writers
13183 | Pragma_Effective_Reads
13184 | Pragma_Effective_Writes
13185 | Pragma_No_Caching
13186 =>
13187 Async_Effective : declare
13188 Obj_Decl : Node_Id;
13189 Obj_Id : Entity_Id;
13190
13191 begin
13192 GNAT_Pragma;
13193 Check_No_Identifiers;
13194 Check_At_Most_N_Arguments (1);
13195
13196 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
13197
13198 -- Object declaration
13199
13200 if Nkind (Obj_Decl) /= N_Object_Declaration then
13201 Pragma_Misplaced;
13202 return;
13203 end if;
13204
13205 Obj_Id := Defining_Entity (Obj_Decl);
13206
13207 -- Perform minimal verification to ensure that the argument is at
13208 -- least a variable. Subsequent finer grained checks will be done
13209 -- at the end of the declarative region the contains the pragma.
13210
13211 if Ekind (Obj_Id) = E_Variable then
13212
13213 -- A pragma that applies to a Ghost entity becomes Ghost for
13214 -- the purposes of legality checks and removal of ignored Ghost
13215 -- code.
13216
13217 Mark_Ghost_Pragma (N, Obj_Id);
13218
13219 -- Chain the pragma on the contract for further processing by
13220 -- Analyze_External_Property_In_Decl_Part.
13221
13222 Add_Contract_Item (N, Obj_Id);
13223
13224 -- Analyze the Boolean expression (if any)
13225
13226 if Present (Arg1) then
13227 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
13228 end if;
13229
13230 -- Otherwise the external property applies to a constant
13231
13232 else
13233 Error_Pragma ("pragma % must apply to a volatile object");
13234 end if;
13235 end Async_Effective;
13236
13237 ------------------
13238 -- Asynchronous --
13239 ------------------
13240
13241 -- pragma Asynchronous (LOCAL_NAME);
13242
13243 when Pragma_Asynchronous => Asynchronous : declare
13244 C_Ent : Entity_Id;
13245 Decl : Node_Id;
13246 Formal : Entity_Id;
13247 L : List_Id;
13248 Nm : Entity_Id;
13249 S : Node_Id;
13250
13251 procedure Process_Async_Pragma;
13252 -- Common processing for procedure and access-to-procedure case
13253
13254 --------------------------
13255 -- Process_Async_Pragma --
13256 --------------------------
13257
13258 procedure Process_Async_Pragma is
13259 begin
13260 if No (L) then
13261 Set_Is_Asynchronous (Nm);
13262 return;
13263 end if;
13264
13265 -- The formals should be of mode IN (RM E.4.1(6))
13266
13267 S := First (L);
13268 while Present (S) loop
13269 Formal := Defining_Identifier (S);
13270
13271 if Nkind (Formal) = N_Defining_Identifier
13272 and then Ekind (Formal) /= E_In_Parameter
13273 then
13274 Error_Pragma_Arg
13275 ("pragma% procedure can only have IN parameter",
13276 Arg1);
13277 end if;
13278
13279 Next (S);
13280 end loop;
13281
13282 Set_Is_Asynchronous (Nm);
13283 end Process_Async_Pragma;
13284
13285 -- Start of processing for pragma Asynchronous
13286
13287 begin
13288 Check_Ada_83_Warning;
13289 Check_No_Identifiers;
13290 Check_Arg_Count (1);
13291 Check_Arg_Is_Local_Name (Arg1);
13292
13293 if Debug_Flag_U then
13294 return;
13295 end if;
13296
13297 C_Ent := Cunit_Entity (Current_Sem_Unit);
13298 Analyze (Get_Pragma_Arg (Arg1));
13299 Nm := Entity (Get_Pragma_Arg (Arg1));
13300
13301 -- A pragma that applies to a Ghost entity becomes Ghost for the
13302 -- purposes of legality checks and removal of ignored Ghost code.
13303
13304 Mark_Ghost_Pragma (N, Nm);
13305
13306 if not Is_Remote_Call_Interface (C_Ent)
13307 and then not Is_Remote_Types (C_Ent)
13308 then
13309 -- This pragma should only appear in an RCI or Remote Types
13310 -- unit (RM E.4.1(4)).
13311
13312 Error_Pragma
13313 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
13314 end if;
13315
13316 if Ekind (Nm) = E_Procedure
13317 and then Nkind (Parent (Nm)) = N_Procedure_Specification
13318 then
13319 if not Is_Remote_Call_Interface (Nm) then
13320 Error_Pragma_Arg
13321 ("pragma% cannot be applied on non-remote procedure",
13322 Arg1);
13323 end if;
13324
13325 L := Parameter_Specifications (Parent (Nm));
13326 Process_Async_Pragma;
13327 return;
13328
13329 elsif Ekind (Nm) = E_Function then
13330 Error_Pragma_Arg
13331 ("pragma% cannot be applied to function", Arg1);
13332
13333 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
13334 if Is_Record_Type (Nm) then
13335
13336 -- A record type that is the Equivalent_Type for a remote
13337 -- access-to-subprogram type.
13338
13339 Decl := Declaration_Node (Corresponding_Remote_Type (Nm));
13340
13341 else
13342 -- A non-expanded RAS type (distribution is not enabled)
13343
13344 Decl := Declaration_Node (Nm);
13345 end if;
13346
13347 if Nkind (Decl) = N_Full_Type_Declaration
13348 and then Nkind (Type_Definition (Decl)) =
13349 N_Access_Procedure_Definition
13350 then
13351 L := Parameter_Specifications (Type_Definition (Decl));
13352 Process_Async_Pragma;
13353
13354 if Is_Asynchronous (Nm)
13355 and then Expander_Active
13356 and then Get_PCS_Name /= Name_No_DSA
13357 then
13358 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
13359 end if;
13360
13361 else
13362 Error_Pragma_Arg
13363 ("pragma% cannot reference access-to-function type",
13364 Arg1);
13365 end if;
13366
13367 -- Only other possibility is Access-to-class-wide type
13368
13369 elsif Is_Access_Type (Nm)
13370 and then Is_Class_Wide_Type (Designated_Type (Nm))
13371 then
13372 Check_First_Subtype (Arg1);
13373 Set_Is_Asynchronous (Nm);
13374 if Expander_Active then
13375 RACW_Type_Is_Asynchronous (Nm);
13376 end if;
13377
13378 else
13379 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
13380 end if;
13381 end Asynchronous;
13382
13383 ------------
13384 -- Atomic --
13385 ------------
13386
13387 -- pragma Atomic (LOCAL_NAME);
13388
13389 when Pragma_Atomic =>
13390 Process_Atomic_Independent_Shared_Volatile;
13391
13392 -----------------------
13393 -- Atomic_Components --
13394 -----------------------
13395
13396 -- pragma Atomic_Components (array_LOCAL_NAME);
13397
13398 -- This processing is shared by Volatile_Components
13399
13400 when Pragma_Atomic_Components
13401 | Pragma_Volatile_Components
13402 =>
13403 Atomic_Components : declare
13404 D : Node_Id;
13405 E : Entity_Id;
13406 E_Id : Node_Id;
13407
13408 begin
13409 Check_Ada_83_Warning;
13410 Check_No_Identifiers;
13411 Check_Arg_Count (1);
13412 Check_Arg_Is_Local_Name (Arg1);
13413 E_Id := Get_Pragma_Arg (Arg1);
13414
13415 if Etype (E_Id) = Any_Type then
13416 return;
13417 end if;
13418
13419 E := Entity (E_Id);
13420
13421 -- A pragma that applies to a Ghost entity becomes Ghost for the
13422 -- purposes of legality checks and removal of ignored Ghost code.
13423
13424 Mark_Ghost_Pragma (N, E);
13425 Check_Duplicate_Pragma (E);
13426
13427 if Rep_Item_Too_Early (E, N)
13428 or else
13429 Rep_Item_Too_Late (E, N)
13430 then
13431 return;
13432 end if;
13433
13434 D := Declaration_Node (E);
13435
13436 if (Nkind (D) = N_Full_Type_Declaration and then Is_Array_Type (E))
13437 or else
13438 (Nkind (D) = N_Object_Declaration
13439 and then (Ekind (E) = E_Constant
13440 or else
13441 Ekind (E) = E_Variable)
13442 and then Nkind (Object_Definition (D)) =
13443 N_Constrained_Array_Definition)
13444 or else
13445 (Ada_Version >= Ada_2020
13446 and then Nkind (D) = N_Formal_Type_Declaration)
13447 then
13448 -- The flag is set on the base type, or on the object
13449
13450 if Nkind (D) = N_Full_Type_Declaration then
13451 E := Base_Type (E);
13452 end if;
13453
13454 -- Atomic implies both Independent and Volatile
13455
13456 if Prag_Id = Pragma_Atomic_Components then
13457 if Ada_Version >= Ada_2020 then
13458 Check_Atomic_VFA
13459 (Component_Type (Etype (E)), VFA => False);
13460 end if;
13461
13462 Set_Has_Atomic_Components (E);
13463 Set_Has_Independent_Components (E);
13464 end if;
13465
13466 Set_Has_Volatile_Components (E);
13467
13468 else
13469 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
13470 end if;
13471 end Atomic_Components;
13472
13473 --------------------
13474 -- Attach_Handler --
13475 --------------------
13476
13477 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
13478
13479 when Pragma_Attach_Handler =>
13480 Check_Ada_83_Warning;
13481 Check_No_Identifiers;
13482 Check_Arg_Count (2);
13483
13484 if No_Run_Time_Mode then
13485 Error_Msg_CRT ("Attach_Handler pragma", N);
13486 else
13487 Check_Interrupt_Or_Attach_Handler;
13488
13489 -- The expression that designates the attribute may depend on a
13490 -- discriminant, and is therefore a per-object expression, to
13491 -- be expanded in the init proc. If expansion is enabled, then
13492 -- perform semantic checks on a copy only.
13493
13494 declare
13495 Temp : Node_Id;
13496 Typ : Node_Id;
13497 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
13498
13499 begin
13500 -- In Relaxed_RM_Semantics mode, we allow any static
13501 -- integer value, for compatibility with other compilers.
13502
13503 if Relaxed_RM_Semantics
13504 and then Nkind (Parg2) = N_Integer_Literal
13505 then
13506 Typ := Standard_Integer;
13507 else
13508 Typ := RTE (RE_Interrupt_ID);
13509 end if;
13510
13511 if Expander_Active then
13512 Temp := New_Copy_Tree (Parg2);
13513 Set_Parent (Temp, N);
13514 Preanalyze_And_Resolve (Temp, Typ);
13515 else
13516 Analyze (Parg2);
13517 Resolve (Parg2, Typ);
13518 end if;
13519 end;
13520
13521 Process_Interrupt_Or_Attach_Handler;
13522 end if;
13523
13524 --------------------
13525 -- C_Pass_By_Copy --
13526 --------------------
13527
13528 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
13529
13530 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
13531 Arg : Node_Id;
13532 Val : Uint;
13533
13534 begin
13535 GNAT_Pragma;
13536 Check_Valid_Configuration_Pragma;
13537 Check_Arg_Count (1);
13538 Check_Optional_Identifier (Arg1, "max_size");
13539
13540 Arg := Get_Pragma_Arg (Arg1);
13541 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
13542
13543 Val := Expr_Value (Arg);
13544
13545 if Val <= 0 then
13546 Error_Pragma_Arg
13547 ("maximum size for pragma% must be positive", Arg1);
13548
13549 elsif UI_Is_In_Int_Range (Val) then
13550 Default_C_Record_Mechanism := UI_To_Int (Val);
13551
13552 -- If a giant value is given, Int'Last will do well enough.
13553 -- If sometime someone complains that a record larger than
13554 -- two gigabytes is not copied, we will worry about it then.
13555
13556 else
13557 Default_C_Record_Mechanism := Mechanism_Type'Last;
13558 end if;
13559 end C_Pass_By_Copy;
13560
13561 -----------
13562 -- Check --
13563 -----------
13564
13565 -- pragma Check ([Name =>] CHECK_KIND,
13566 -- [Check =>] Boolean_EXPRESSION
13567 -- [,[Message =>] String_EXPRESSION]);
13568
13569 -- CHECK_KIND ::= IDENTIFIER |
13570 -- Pre'Class |
13571 -- Post'Class |
13572 -- Invariant'Class |
13573 -- Type_Invariant'Class
13574
13575 -- The identifiers Assertions and Statement_Assertions are not
13576 -- allowed, since they have special meaning for Check_Policy.
13577
13578 -- WARNING: The code below manages Ghost regions. Return statements
13579 -- must be replaced by gotos which jump to the end of the code and
13580 -- restore the Ghost mode.
13581
13582 when Pragma_Check => Check : declare
13583 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
13584 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
13585 -- Save the Ghost-related attributes to restore on exit
13586
13587 Cname : Name_Id;
13588 Eloc : Source_Ptr;
13589 Expr : Node_Id;
13590 Str : Node_Id;
13591 pragma Warnings (Off, Str);
13592
13593 begin
13594 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
13595 -- the mode now to ensure that any nodes generated during analysis
13596 -- and expansion are marked as Ghost.
13597
13598 Set_Ghost_Mode (N);
13599
13600 GNAT_Pragma;
13601 Check_At_Least_N_Arguments (2);
13602 Check_At_Most_N_Arguments (3);
13603 Check_Optional_Identifier (Arg1, Name_Name);
13604 Check_Optional_Identifier (Arg2, Name_Check);
13605
13606 if Arg_Count = 3 then
13607 Check_Optional_Identifier (Arg3, Name_Message);
13608 Str := Get_Pragma_Arg (Arg3);
13609 end if;
13610
13611 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
13612 Check_Arg_Is_Identifier (Arg1);
13613 Cname := Chars (Get_Pragma_Arg (Arg1));
13614
13615 -- Check forbidden name Assertions or Statement_Assertions
13616
13617 case Cname is
13618 when Name_Assertions =>
13619 Error_Pragma_Arg
13620 ("""Assertions"" is not allowed as a check kind for "
13621 & "pragma%", Arg1);
13622
13623 when Name_Statement_Assertions =>
13624 Error_Pragma_Arg
13625 ("""Statement_Assertions"" is not allowed as a check kind "
13626 & "for pragma%", Arg1);
13627
13628 when others =>
13629 null;
13630 end case;
13631
13632 -- Check applicable policy. We skip this if Checked/Ignored status
13633 -- is already set (e.g. in the case of a pragma from an aspect).
13634
13635 if Is_Checked (N) or else Is_Ignored (N) then
13636 null;
13637
13638 -- For a non-source pragma that is a rewriting of another pragma,
13639 -- copy the Is_Checked/Ignored status from the rewritten pragma.
13640
13641 elsif Is_Rewrite_Substitution (N)
13642 and then Nkind (Original_Node (N)) = N_Pragma
13643 then
13644 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
13645 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
13646
13647 -- Otherwise query the applicable policy at this point
13648
13649 else
13650 case Check_Kind (Cname) is
13651 when Name_Ignore =>
13652 Set_Is_Ignored (N, True);
13653 Set_Is_Checked (N, False);
13654
13655 when Name_Check =>
13656 Set_Is_Ignored (N, False);
13657 Set_Is_Checked (N, True);
13658
13659 -- For disable, rewrite pragma as null statement and skip
13660 -- rest of the analysis of the pragma.
13661
13662 when Name_Disable =>
13663 Rewrite (N, Make_Null_Statement (Loc));
13664 Analyze (N);
13665 raise Pragma_Exit;
13666
13667 -- No other possibilities
13668
13669 when others =>
13670 raise Program_Error;
13671 end case;
13672 end if;
13673
13674 -- If check kind was not Disable, then continue pragma analysis
13675
13676 Expr := Get_Pragma_Arg (Arg2);
13677
13678 -- Mark the pragma (or, if rewritten from an aspect, the original
13679 -- aspect) as enabled. Nothing to do for an internally generated
13680 -- check for a dynamic predicate.
13681
13682 if Is_Checked (N)
13683 and then not Split_PPC (N)
13684 and then Cname /= Name_Dynamic_Predicate
13685 then
13686 Set_SCO_Pragma_Enabled (Loc);
13687 end if;
13688
13689 -- Deal with analyzing the string argument. If checks are not
13690 -- on we don't want any expansion (since such expansion would
13691 -- not get properly deleted) but we do want to analyze (to get
13692 -- proper references). The Preanalyze_And_Resolve routine does
13693 -- just what we want. Ditto if pragma is active, because it will
13694 -- be rewritten as an if-statement whose analysis will complete
13695 -- analysis and expansion of the string message. This makes a
13696 -- difference in the unusual case where the expression for the
13697 -- string may have a side effect, such as raising an exception.
13698 -- This is mandated by RM 11.4.2, which specifies that the string
13699 -- expression is only evaluated if the check fails and
13700 -- Assertion_Error is to be raised.
13701
13702 if Arg_Count = 3 then
13703 Preanalyze_And_Resolve (Str, Standard_String);
13704 end if;
13705
13706 -- Now you might think we could just do the same with the Boolean
13707 -- expression if checks are off (and expansion is on) and then
13708 -- rewrite the check as a null statement. This would work but we
13709 -- would lose the useful warnings about an assertion being bound
13710 -- to fail even if assertions are turned off.
13711
13712 -- So instead we wrap the boolean expression in an if statement
13713 -- that looks like:
13714
13715 -- if False and then condition then
13716 -- null;
13717 -- end if;
13718
13719 -- The reason we do this rewriting during semantic analysis rather
13720 -- than as part of normal expansion is that we cannot analyze and
13721 -- expand the code for the boolean expression directly, or it may
13722 -- cause insertion of actions that would escape the attempt to
13723 -- suppress the check code.
13724
13725 -- Note that the Sloc for the if statement corresponds to the
13726 -- argument condition, not the pragma itself. The reason for
13727 -- this is that we may generate a warning if the condition is
13728 -- False at compile time, and we do not want to delete this
13729 -- warning when we delete the if statement.
13730
13731 if Expander_Active and Is_Ignored (N) then
13732 Eloc := Sloc (Expr);
13733
13734 Rewrite (N,
13735 Make_If_Statement (Eloc,
13736 Condition =>
13737 Make_And_Then (Eloc,
13738 Left_Opnd => Make_Identifier (Eloc, Name_False),
13739 Right_Opnd => Expr),
13740 Then_Statements => New_List (
13741 Make_Null_Statement (Eloc))));
13742
13743 -- Now go ahead and analyze the if statement
13744
13745 In_Assertion_Expr := In_Assertion_Expr + 1;
13746
13747 -- One rather special treatment. If we are now in Eliminated
13748 -- overflow mode, then suppress overflow checking since we do
13749 -- not want to drag in the bignum stuff if we are in Ignore
13750 -- mode anyway. This is particularly important if we are using
13751 -- a configurable run time that does not support bignum ops.
13752
13753 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
13754 declare
13755 Svo : constant Boolean :=
13756 Scope_Suppress.Suppress (Overflow_Check);
13757 begin
13758 Scope_Suppress.Overflow_Mode_Assertions := Strict;
13759 Scope_Suppress.Suppress (Overflow_Check) := True;
13760 Analyze (N);
13761 Scope_Suppress.Suppress (Overflow_Check) := Svo;
13762 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
13763 end;
13764
13765 -- Not that special case
13766
13767 else
13768 Analyze (N);
13769 end if;
13770
13771 -- All done with this check
13772
13773 In_Assertion_Expr := In_Assertion_Expr - 1;
13774
13775 -- Check is active or expansion not active. In these cases we can
13776 -- just go ahead and analyze the boolean with no worries.
13777
13778 else
13779 In_Assertion_Expr := In_Assertion_Expr + 1;
13780 Analyze_And_Resolve (Expr, Any_Boolean);
13781 In_Assertion_Expr := In_Assertion_Expr - 1;
13782 end if;
13783
13784 Restore_Ghost_Region (Saved_GM, Saved_IGR);
13785 end Check;
13786
13787 --------------------------
13788 -- Check_Float_Overflow --
13789 --------------------------
13790
13791 -- pragma Check_Float_Overflow;
13792
13793 when Pragma_Check_Float_Overflow =>
13794 GNAT_Pragma;
13795 Check_Valid_Configuration_Pragma;
13796 Check_Arg_Count (0);
13797 Check_Float_Overflow := not Machine_Overflows_On_Target;
13798
13799 ----------------
13800 -- Check_Name --
13801 ----------------
13802
13803 -- pragma Check_Name (check_IDENTIFIER);
13804
13805 when Pragma_Check_Name =>
13806 GNAT_Pragma;
13807 Check_No_Identifiers;
13808 Check_Valid_Configuration_Pragma;
13809 Check_Arg_Count (1);
13810 Check_Arg_Is_Identifier (Arg1);
13811
13812 declare
13813 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
13814
13815 begin
13816 for J in Check_Names.First .. Check_Names.Last loop
13817 if Check_Names.Table (J) = Nam then
13818 return;
13819 end if;
13820 end loop;
13821
13822 Check_Names.Append (Nam);
13823 end;
13824
13825 ------------------
13826 -- Check_Policy --
13827 ------------------
13828
13829 -- This is the old style syntax, which is still allowed in all modes:
13830
13831 -- pragma Check_Policy ([Name =>] CHECK_KIND
13832 -- [Policy =>] POLICY_IDENTIFIER);
13833
13834 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
13835
13836 -- CHECK_KIND ::= IDENTIFIER |
13837 -- Pre'Class |
13838 -- Post'Class |
13839 -- Type_Invariant'Class |
13840 -- Invariant'Class
13841
13842 -- This is the new style syntax, compatible with Assertion_Policy
13843 -- and also allowed in all modes.
13844
13845 -- Pragma Check_Policy (
13846 -- CHECK_KIND => POLICY_IDENTIFIER
13847 -- {, CHECK_KIND => POLICY_IDENTIFIER});
13848
13849 -- Note: the identifiers Name and Policy are not allowed as
13850 -- Check_Kind values. This avoids ambiguities between the old and
13851 -- new form syntax.
13852
13853 when Pragma_Check_Policy => Check_Policy : declare
13854 Kind : Node_Id;
13855
13856 begin
13857 GNAT_Pragma;
13858 Check_At_Least_N_Arguments (1);
13859
13860 -- A Check_Policy pragma can appear either as a configuration
13861 -- pragma, or in a declarative part or a package spec (see RM
13862 -- 11.5(5) for rules for Suppress/Unsuppress which are also
13863 -- followed for Check_Policy).
13864
13865 if not Is_Configuration_Pragma then
13866 Check_Is_In_Decl_Part_Or_Package_Spec;
13867 end if;
13868
13869 -- Figure out if we have the old or new syntax. We have the
13870 -- old syntax if the first argument has no identifier, or the
13871 -- identifier is Name.
13872
13873 if Nkind (Arg1) /= N_Pragma_Argument_Association
13874 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
13875 then
13876 -- Old syntax
13877
13878 Check_Arg_Count (2);
13879 Check_Optional_Identifier (Arg1, Name_Name);
13880 Kind := Get_Pragma_Arg (Arg1);
13881 Rewrite_Assertion_Kind (Kind,
13882 From_Policy => Comes_From_Source (N));
13883 Check_Arg_Is_Identifier (Arg1);
13884
13885 -- Check forbidden check kind
13886
13887 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
13888 Error_Msg_Name_2 := Chars (Kind);
13889 Error_Pragma_Arg
13890 ("pragma% does not allow% as check name", Arg1);
13891 end if;
13892
13893 -- Check policy
13894
13895 Check_Optional_Identifier (Arg2, Name_Policy);
13896 Check_Arg_Is_One_Of
13897 (Arg2,
13898 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
13899
13900 -- And chain pragma on the Check_Policy_List for search
13901
13902 Set_Next_Pragma (N, Opt.Check_Policy_List);
13903 Opt.Check_Policy_List := N;
13904
13905 -- For the new syntax, what we do is to convert each argument to
13906 -- an old syntax equivalent. We do that because we want to chain
13907 -- old style Check_Policy pragmas for the search (we don't want
13908 -- to have to deal with multiple arguments in the search).
13909
13910 else
13911 declare
13912 Arg : Node_Id;
13913 Argx : Node_Id;
13914 LocP : Source_Ptr;
13915 New_P : Node_Id;
13916
13917 begin
13918 Arg := Arg1;
13919 while Present (Arg) loop
13920 LocP := Sloc (Arg);
13921 Argx := Get_Pragma_Arg (Arg);
13922
13923 -- Kind must be specified
13924
13925 if Nkind (Arg) /= N_Pragma_Argument_Association
13926 or else Chars (Arg) = No_Name
13927 then
13928 Error_Pragma_Arg
13929 ("missing assertion kind for pragma%", Arg);
13930 end if;
13931
13932 -- Construct equivalent old form syntax Check_Policy
13933 -- pragma and insert it to get remaining checks.
13934
13935 New_P :=
13936 Make_Pragma (LocP,
13937 Chars => Name_Check_Policy,
13938 Pragma_Argument_Associations => New_List (
13939 Make_Pragma_Argument_Association (LocP,
13940 Expression =>
13941 Make_Identifier (LocP, Chars (Arg))),
13942 Make_Pragma_Argument_Association (Sloc (Argx),
13943 Expression => Argx)));
13944
13945 Arg := Next (Arg);
13946
13947 -- For a configuration pragma, insert old form in
13948 -- the corresponding file.
13949
13950 if Is_Configuration_Pragma then
13951 Insert_After (N, New_P);
13952 Analyze (New_P);
13953
13954 else
13955 Insert_Action (N, New_P);
13956 end if;
13957 end loop;
13958
13959 -- Rewrite original Check_Policy pragma to null, since we
13960 -- have converted it into a series of old syntax pragmas.
13961
13962 Rewrite (N, Make_Null_Statement (Loc));
13963 Analyze (N);
13964 end;
13965 end if;
13966 end Check_Policy;
13967
13968 -------------
13969 -- Comment --
13970 -------------
13971
13972 -- pragma Comment (static_string_EXPRESSION)
13973
13974 -- Processing for pragma Comment shares the circuitry for pragma
13975 -- Ident. The only differences are that Ident enforces a limit of 31
13976 -- characters on its argument, and also enforces limitations on
13977 -- placement for DEC compatibility. Pragma Comment shares neither of
13978 -- these restrictions.
13979
13980 -------------------
13981 -- Common_Object --
13982 -------------------
13983
13984 -- pragma Common_Object (
13985 -- [Internal =>] LOCAL_NAME
13986 -- [, [External =>] EXTERNAL_SYMBOL]
13987 -- [, [Size =>] EXTERNAL_SYMBOL]);
13988
13989 -- Processing for this pragma is shared with Psect_Object
13990
13991 ----------------------------------------------
13992 -- Compile_Time_Error, Compile_Time_Warning --
13993 ----------------------------------------------
13994
13995 -- pragma Compile_Time_Error
13996 -- (boolean_EXPRESSION, static_string_EXPRESSION);
13997
13998 -- pragma Compile_Time_Warning
13999 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14000
14001 when Pragma_Compile_Time_Error | Pragma_Compile_Time_Warning =>
14002 GNAT_Pragma;
14003 Process_Compile_Time_Warning_Or_Error;
14004
14005 ---------------------------
14006 -- Compiler_Unit_Warning --
14007 ---------------------------
14008
14009 -- pragma Compiler_Unit_Warning;
14010
14011 -- Historical note
14012
14013 -- Originally, we had only pragma Compiler_Unit, and it resulted in
14014 -- errors not warnings. This means that we had introduced a big extra
14015 -- inertia to compiler changes, since even if we implemented a new
14016 -- feature, and even if all versions to be used for bootstrapping
14017 -- implemented this new feature, we could not use it, since old
14018 -- compilers would give errors for using this feature in units
14019 -- having Compiler_Unit pragmas.
14020
14021 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
14022 -- problem. We no longer have any units mentioning Compiler_Unit,
14023 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
14024 -- and thus generates a warning which can be ignored. So that deals
14025 -- with the problem of old compilers not implementing the newer form
14026 -- of the pragma.
14027
14028 -- Newer compilers recognize the new pragma, but generate warning
14029 -- messages instead of errors, which again can be ignored in the
14030 -- case of an old compiler which implements a wanted new feature
14031 -- but at the time felt like warning about it for older compilers.
14032
14033 -- We retain Compiler_Unit so that new compilers can be used to build
14034 -- older run-times that use this pragma. That's an unusual case, but
14035 -- it's easy enough to handle, so why not?
14036
14037 when Pragma_Compiler_Unit
14038 | Pragma_Compiler_Unit_Warning
14039 =>
14040 GNAT_Pragma;
14041 Check_Arg_Count (0);
14042
14043 -- Only recognized in main unit
14044
14045 if Current_Sem_Unit = Main_Unit then
14046 Compiler_Unit := True;
14047 end if;
14048
14049 -----------------------------
14050 -- Complete_Representation --
14051 -----------------------------
14052
14053 -- pragma Complete_Representation;
14054
14055 when Pragma_Complete_Representation =>
14056 GNAT_Pragma;
14057 Check_Arg_Count (0);
14058
14059 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
14060 Error_Pragma
14061 ("pragma & must appear within record representation clause");
14062 end if;
14063
14064 ----------------------------
14065 -- Complex_Representation --
14066 ----------------------------
14067
14068 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
14069
14070 when Pragma_Complex_Representation => Complex_Representation : declare
14071 E_Id : Entity_Id;
14072 E : Entity_Id;
14073 Ent : Entity_Id;
14074
14075 begin
14076 GNAT_Pragma;
14077 Check_Arg_Count (1);
14078 Check_Optional_Identifier (Arg1, Name_Entity);
14079 Check_Arg_Is_Local_Name (Arg1);
14080 E_Id := Get_Pragma_Arg (Arg1);
14081
14082 if Etype (E_Id) = Any_Type then
14083 return;
14084 end if;
14085
14086 E := Entity (E_Id);
14087
14088 if not Is_Record_Type (E) then
14089 Error_Pragma_Arg
14090 ("argument for pragma% must be record type", Arg1);
14091 end if;
14092
14093 Ent := First_Entity (E);
14094
14095 if No (Ent)
14096 or else No (Next_Entity (Ent))
14097 or else Present (Next_Entity (Next_Entity (Ent)))
14098 or else not Is_Floating_Point_Type (Etype (Ent))
14099 or else Etype (Ent) /= Etype (Next_Entity (Ent))
14100 then
14101 Error_Pragma_Arg
14102 ("record for pragma% must have two fields of the same "
14103 & "floating-point type", Arg1);
14104
14105 else
14106 Set_Has_Complex_Representation (Base_Type (E));
14107
14108 -- We need to treat the type has having a non-standard
14109 -- representation, for back-end purposes, even though in
14110 -- general a complex will have the default representation
14111 -- of a record with two real components.
14112
14113 Set_Has_Non_Standard_Rep (Base_Type (E));
14114 end if;
14115 end Complex_Representation;
14116
14117 -------------------------
14118 -- Component_Alignment --
14119 -------------------------
14120
14121 -- pragma Component_Alignment (
14122 -- [Form =>] ALIGNMENT_CHOICE
14123 -- [, [Name =>] type_LOCAL_NAME]);
14124 --
14125 -- ALIGNMENT_CHOICE ::=
14126 -- Component_Size
14127 -- | Component_Size_4
14128 -- | Storage_Unit
14129 -- | Default
14130
14131 when Pragma_Component_Alignment => Component_AlignmentP : declare
14132 Args : Args_List (1 .. 2);
14133 Names : constant Name_List (1 .. 2) := (
14134 Name_Form,
14135 Name_Name);
14136
14137 Form : Node_Id renames Args (1);
14138 Name : Node_Id renames Args (2);
14139
14140 Atype : Component_Alignment_Kind;
14141 Typ : Entity_Id;
14142
14143 begin
14144 GNAT_Pragma;
14145 Gather_Associations (Names, Args);
14146
14147 if No (Form) then
14148 Error_Pragma ("missing Form argument for pragma%");
14149 end if;
14150
14151 Check_Arg_Is_Identifier (Form);
14152
14153 -- Get proper alignment, note that Default = Component_Size on all
14154 -- machines we have so far, and we want to set this value rather
14155 -- than the default value to indicate that it has been explicitly
14156 -- set (and thus will not get overridden by the default component
14157 -- alignment for the current scope)
14158
14159 if Chars (Form) = Name_Component_Size then
14160 Atype := Calign_Component_Size;
14161
14162 elsif Chars (Form) = Name_Component_Size_4 then
14163 Atype := Calign_Component_Size_4;
14164
14165 elsif Chars (Form) = Name_Default then
14166 Atype := Calign_Component_Size;
14167
14168 elsif Chars (Form) = Name_Storage_Unit then
14169 Atype := Calign_Storage_Unit;
14170
14171 else
14172 Error_Pragma_Arg
14173 ("invalid Form parameter for pragma%", Form);
14174 end if;
14175
14176 -- The pragma appears in a configuration file
14177
14178 if No (Parent (N)) then
14179 Check_Valid_Configuration_Pragma;
14180
14181 -- Capture the component alignment in a global variable when
14182 -- the pragma appears in a configuration file. Note that the
14183 -- scope stack is empty at this point and cannot be used to
14184 -- store the alignment value.
14185
14186 Configuration_Component_Alignment := Atype;
14187
14188 -- Case with no name, supplied, affects scope table entry
14189
14190 elsif No (Name) then
14191 Scope_Stack.Table
14192 (Scope_Stack.Last).Component_Alignment_Default := Atype;
14193
14194 -- Case of name supplied
14195
14196 else
14197 Check_Arg_Is_Local_Name (Name);
14198 Find_Type (Name);
14199 Typ := Entity (Name);
14200
14201 if Typ = Any_Type
14202 or else Rep_Item_Too_Early (Typ, N)
14203 then
14204 return;
14205 else
14206 Typ := Underlying_Type (Typ);
14207 end if;
14208
14209 if not Is_Record_Type (Typ)
14210 and then not Is_Array_Type (Typ)
14211 then
14212 Error_Pragma_Arg
14213 ("Name parameter of pragma% must identify record or "
14214 & "array type", Name);
14215 end if;
14216
14217 -- An explicit Component_Alignment pragma overrides an
14218 -- implicit pragma Pack, but not an explicit one.
14219
14220 if not Has_Pragma_Pack (Base_Type (Typ)) then
14221 Set_Is_Packed (Base_Type (Typ), False);
14222 Set_Component_Alignment (Base_Type (Typ), Atype);
14223 end if;
14224 end if;
14225 end Component_AlignmentP;
14226
14227 --------------------------------
14228 -- Constant_After_Elaboration --
14229 --------------------------------
14230
14231 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
14232
14233 when Pragma_Constant_After_Elaboration => Constant_After_Elaboration :
14234 declare
14235 Obj_Decl : Node_Id;
14236 Obj_Id : Entity_Id;
14237
14238 begin
14239 GNAT_Pragma;
14240 Check_No_Identifiers;
14241 Check_At_Most_N_Arguments (1);
14242
14243 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
14244
14245 if Nkind (Obj_Decl) /= N_Object_Declaration then
14246 Pragma_Misplaced;
14247 return;
14248 end if;
14249
14250 Obj_Id := Defining_Entity (Obj_Decl);
14251
14252 -- The object declaration must be a library-level variable which
14253 -- is either explicitly initialized or obtains a value during the
14254 -- elaboration of a package body (SPARK RM 3.3.1).
14255
14256 if Ekind (Obj_Id) = E_Variable then
14257 if not Is_Library_Level_Entity (Obj_Id) then
14258 Error_Pragma
14259 ("pragma % must apply to a library level variable");
14260 return;
14261 end if;
14262
14263 -- Otherwise the pragma applies to a constant, which is illegal
14264
14265 else
14266 Error_Pragma ("pragma % must apply to a variable declaration");
14267 return;
14268 end if;
14269
14270 -- A pragma that applies to a Ghost entity becomes Ghost for the
14271 -- purposes of legality checks and removal of ignored Ghost code.
14272
14273 Mark_Ghost_Pragma (N, Obj_Id);
14274
14275 -- Chain the pragma on the contract for completeness
14276
14277 Add_Contract_Item (N, Obj_Id);
14278
14279 -- Analyze the Boolean expression (if any)
14280
14281 if Present (Arg1) then
14282 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
14283 end if;
14284 end Constant_After_Elaboration;
14285
14286 --------------------
14287 -- Contract_Cases --
14288 --------------------
14289
14290 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
14291
14292 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
14293
14294 -- CASE_GUARD ::= boolean_EXPRESSION | others
14295
14296 -- CONSEQUENCE ::= boolean_EXPRESSION
14297
14298 -- Characteristics:
14299
14300 -- * Analysis - The annotation undergoes initial checks to verify
14301 -- the legal placement and context. Secondary checks preanalyze the
14302 -- expressions in:
14303
14304 -- Analyze_Contract_Cases_In_Decl_Part
14305
14306 -- * Expansion - The annotation is expanded during the expansion of
14307 -- the related subprogram [body] contract as performed in:
14308
14309 -- Expand_Subprogram_Contract
14310
14311 -- * Template - The annotation utilizes the generic template of the
14312 -- related subprogram [body] when it is:
14313
14314 -- aspect on subprogram declaration
14315 -- aspect on stand-alone subprogram body
14316 -- pragma on stand-alone subprogram body
14317
14318 -- The annotation must prepare its own template when it is:
14319
14320 -- pragma on subprogram declaration
14321
14322 -- * Globals - Capture of global references must occur after full
14323 -- analysis.
14324
14325 -- * Instance - The annotation is instantiated automatically when
14326 -- the related generic subprogram [body] is instantiated except for
14327 -- the "pragma on subprogram declaration" case. In that scenario
14328 -- the annotation must instantiate itself.
14329
14330 when Pragma_Contract_Cases => Contract_Cases : declare
14331 Spec_Id : Entity_Id;
14332 Subp_Decl : Node_Id;
14333 Subp_Spec : Node_Id;
14334
14335 begin
14336 GNAT_Pragma;
14337 Check_No_Identifiers;
14338 Check_Arg_Count (1);
14339
14340 -- Ensure the proper placement of the pragma. Contract_Cases must
14341 -- be associated with a subprogram declaration or a body that acts
14342 -- as a spec.
14343
14344 Subp_Decl :=
14345 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
14346
14347 -- Entry
14348
14349 if Nkind (Subp_Decl) = N_Entry_Declaration then
14350 null;
14351
14352 -- Generic subprogram
14353
14354 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
14355 null;
14356
14357 -- Body acts as spec
14358
14359 elsif Nkind (Subp_Decl) = N_Subprogram_Body
14360 and then No (Corresponding_Spec (Subp_Decl))
14361 then
14362 null;
14363
14364 -- Body stub acts as spec
14365
14366 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
14367 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
14368 then
14369 null;
14370
14371 -- Subprogram
14372
14373 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
14374 Subp_Spec := Specification (Subp_Decl);
14375
14376 -- Pragma Contract_Cases is forbidden on null procedures, as
14377 -- this may lead to potential ambiguities in behavior when
14378 -- interface null procedures are involved.
14379
14380 if Nkind (Subp_Spec) = N_Procedure_Specification
14381 and then Null_Present (Subp_Spec)
14382 then
14383 Error_Msg_N (Fix_Error
14384 ("pragma % cannot apply to null procedure"), N);
14385 return;
14386 end if;
14387
14388 else
14389 Pragma_Misplaced;
14390 return;
14391 end if;
14392
14393 Spec_Id := Unique_Defining_Entity (Subp_Decl);
14394
14395 -- A pragma that applies to a Ghost entity becomes Ghost for the
14396 -- purposes of legality checks and removal of ignored Ghost code.
14397
14398 Mark_Ghost_Pragma (N, Spec_Id);
14399 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
14400
14401 -- Chain the pragma on the contract for further processing by
14402 -- Analyze_Contract_Cases_In_Decl_Part.
14403
14404 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
14405
14406 -- Fully analyze the pragma when it appears inside an entry
14407 -- or subprogram body because it cannot benefit from forward
14408 -- references.
14409
14410 if Nkind_In (Subp_Decl, N_Entry_Body,
14411 N_Subprogram_Body,
14412 N_Subprogram_Body_Stub)
14413 then
14414 -- The legality checks of pragma Contract_Cases are affected by
14415 -- the SPARK mode in effect and the volatility of the context.
14416 -- Analyze all pragmas in a specific order.
14417
14418 Analyze_If_Present (Pragma_SPARK_Mode);
14419 Analyze_If_Present (Pragma_Volatile_Function);
14420 Analyze_Contract_Cases_In_Decl_Part (N);
14421 end if;
14422 end Contract_Cases;
14423
14424 ----------------
14425 -- Controlled --
14426 ----------------
14427
14428 -- pragma Controlled (first_subtype_LOCAL_NAME);
14429
14430 when Pragma_Controlled => Controlled : declare
14431 Arg : Node_Id;
14432
14433 begin
14434 Check_No_Identifiers;
14435 Check_Arg_Count (1);
14436 Check_Arg_Is_Local_Name (Arg1);
14437 Arg := Get_Pragma_Arg (Arg1);
14438
14439 if not Is_Entity_Name (Arg)
14440 or else not Is_Access_Type (Entity (Arg))
14441 then
14442 Error_Pragma_Arg ("pragma% requires access type", Arg1);
14443 else
14444 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
14445 end if;
14446 end Controlled;
14447
14448 ----------------
14449 -- Convention --
14450 ----------------
14451
14452 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
14453 -- [Entity =>] LOCAL_NAME);
14454
14455 when Pragma_Convention => Convention : declare
14456 C : Convention_Id;
14457 E : Entity_Id;
14458 pragma Warnings (Off, C);
14459 pragma Warnings (Off, E);
14460
14461 begin
14462 Check_Arg_Order ((Name_Convention, Name_Entity));
14463 Check_Ada_83_Warning;
14464 Check_Arg_Count (2);
14465 Process_Convention (C, E);
14466
14467 -- A pragma that applies to a Ghost entity becomes Ghost for the
14468 -- purposes of legality checks and removal of ignored Ghost code.
14469
14470 Mark_Ghost_Pragma (N, E);
14471 end Convention;
14472
14473 ---------------------------
14474 -- Convention_Identifier --
14475 ---------------------------
14476
14477 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
14478 -- [Convention =>] convention_IDENTIFIER);
14479
14480 when Pragma_Convention_Identifier => Convention_Identifier : declare
14481 Idnam : Name_Id;
14482 Cname : Name_Id;
14483
14484 begin
14485 GNAT_Pragma;
14486 Check_Arg_Order ((Name_Name, Name_Convention));
14487 Check_Arg_Count (2);
14488 Check_Optional_Identifier (Arg1, Name_Name);
14489 Check_Optional_Identifier (Arg2, Name_Convention);
14490 Check_Arg_Is_Identifier (Arg1);
14491 Check_Arg_Is_Identifier (Arg2);
14492 Idnam := Chars (Get_Pragma_Arg (Arg1));
14493 Cname := Chars (Get_Pragma_Arg (Arg2));
14494
14495 if Is_Convention_Name (Cname) then
14496 Record_Convention_Identifier
14497 (Idnam, Get_Convention_Id (Cname));
14498 else
14499 Error_Pragma_Arg
14500 ("second arg for % pragma must be convention", Arg2);
14501 end if;
14502 end Convention_Identifier;
14503
14504 ---------------
14505 -- CPP_Class --
14506 ---------------
14507
14508 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
14509
14510 when Pragma_CPP_Class =>
14511 GNAT_Pragma;
14512
14513 if Warn_On_Obsolescent_Feature then
14514 Error_Msg_N
14515 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
14516 & "effect; replace it by pragma import?j?", N);
14517 end if;
14518
14519 Check_Arg_Count (1);
14520
14521 Rewrite (N,
14522 Make_Pragma (Loc,
14523 Chars => Name_Import,
14524 Pragma_Argument_Associations => New_List (
14525 Make_Pragma_Argument_Association (Loc,
14526 Expression => Make_Identifier (Loc, Name_CPP)),
14527 New_Copy (First (Pragma_Argument_Associations (N))))));
14528 Analyze (N);
14529
14530 ---------------------
14531 -- CPP_Constructor --
14532 ---------------------
14533
14534 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
14535 -- [, [External_Name =>] static_string_EXPRESSION ]
14536 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14537
14538 when Pragma_CPP_Constructor => CPP_Constructor : declare
14539 Elmt : Elmt_Id;
14540 Id : Entity_Id;
14541 Def_Id : Entity_Id;
14542 Tag_Typ : Entity_Id;
14543
14544 begin
14545 GNAT_Pragma;
14546 Check_At_Least_N_Arguments (1);
14547 Check_At_Most_N_Arguments (3);
14548 Check_Optional_Identifier (Arg1, Name_Entity);
14549 Check_Arg_Is_Local_Name (Arg1);
14550
14551 Id := Get_Pragma_Arg (Arg1);
14552 Find_Program_Unit_Name (Id);
14553
14554 -- If we did not find the name, we are done
14555
14556 if Etype (Id) = Any_Type then
14557 return;
14558 end if;
14559
14560 Def_Id := Entity (Id);
14561
14562 -- Check if already defined as constructor
14563
14564 if Is_Constructor (Def_Id) then
14565 Error_Msg_N
14566 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
14567 return;
14568 end if;
14569
14570 if Ekind (Def_Id) = E_Function
14571 and then (Is_CPP_Class (Etype (Def_Id))
14572 or else (Is_Class_Wide_Type (Etype (Def_Id))
14573 and then
14574 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
14575 then
14576 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
14577 Error_Msg_N
14578 ("'C'P'P constructor must be defined in the scope of "
14579 & "its returned type", Arg1);
14580 end if;
14581
14582 if Arg_Count >= 2 then
14583 Set_Imported (Def_Id);
14584 Set_Is_Public (Def_Id);
14585 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
14586 end if;
14587
14588 Set_Has_Completion (Def_Id);
14589 Set_Is_Constructor (Def_Id);
14590 Set_Convention (Def_Id, Convention_CPP);
14591
14592 -- Imported C++ constructors are not dispatching primitives
14593 -- because in C++ they don't have a dispatch table slot.
14594 -- However, in Ada the constructor has the profile of a
14595 -- function that returns a tagged type and therefore it has
14596 -- been treated as a primitive operation during semantic
14597 -- analysis. We now remove it from the list of primitive
14598 -- operations of the type.
14599
14600 if Is_Tagged_Type (Etype (Def_Id))
14601 and then not Is_Class_Wide_Type (Etype (Def_Id))
14602 and then Is_Dispatching_Operation (Def_Id)
14603 then
14604 Tag_Typ := Etype (Def_Id);
14605
14606 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
14607 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
14608 Next_Elmt (Elmt);
14609 end loop;
14610
14611 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
14612 Set_Is_Dispatching_Operation (Def_Id, False);
14613 end if;
14614
14615 -- For backward compatibility, if the constructor returns a
14616 -- class wide type, and we internally change the return type to
14617 -- the corresponding root type.
14618
14619 if Is_Class_Wide_Type (Etype (Def_Id)) then
14620 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
14621 end if;
14622 else
14623 Error_Pragma_Arg
14624 ("pragma% requires function returning a 'C'P'P_Class type",
14625 Arg1);
14626 end if;
14627 end CPP_Constructor;
14628
14629 -----------------
14630 -- CPP_Virtual --
14631 -----------------
14632
14633 when Pragma_CPP_Virtual =>
14634 GNAT_Pragma;
14635
14636 if Warn_On_Obsolescent_Feature then
14637 Error_Msg_N
14638 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
14639 & "effect?j?", N);
14640 end if;
14641
14642 ----------------
14643 -- CPP_Vtable --
14644 ----------------
14645
14646 when Pragma_CPP_Vtable =>
14647 GNAT_Pragma;
14648
14649 if Warn_On_Obsolescent_Feature then
14650 Error_Msg_N
14651 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
14652 & "effect?j?", N);
14653 end if;
14654
14655 ---------
14656 -- CPU --
14657 ---------
14658
14659 -- pragma CPU (EXPRESSION);
14660
14661 when Pragma_CPU => CPU : declare
14662 P : constant Node_Id := Parent (N);
14663 Arg : Node_Id;
14664 Ent : Entity_Id;
14665
14666 begin
14667 Ada_2012_Pragma;
14668 Check_No_Identifiers;
14669 Check_Arg_Count (1);
14670
14671 -- Subprogram case
14672
14673 if Nkind (P) = N_Subprogram_Body then
14674 Check_In_Main_Program;
14675
14676 Arg := Get_Pragma_Arg (Arg1);
14677 Analyze_And_Resolve (Arg, Any_Integer);
14678
14679 Ent := Defining_Unit_Name (Specification (P));
14680
14681 if Nkind (Ent) = N_Defining_Program_Unit_Name then
14682 Ent := Defining_Identifier (Ent);
14683 end if;
14684
14685 -- Must be static
14686
14687 if not Is_OK_Static_Expression (Arg) then
14688 Flag_Non_Static_Expr
14689 ("main subprogram affinity is not static!", Arg);
14690 raise Pragma_Exit;
14691
14692 -- If constraint error, then we already signalled an error
14693
14694 elsif Raises_Constraint_Error (Arg) then
14695 null;
14696
14697 -- Otherwise check in range
14698
14699 else
14700 declare
14701 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
14702 -- This is the entity System.Multiprocessors.CPU_Range;
14703
14704 Val : constant Uint := Expr_Value (Arg);
14705
14706 begin
14707 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
14708 or else
14709 Val > Expr_Value (Type_High_Bound (CPU_Id))
14710 then
14711 Error_Pragma_Arg
14712 ("main subprogram CPU is out of range", Arg1);
14713 end if;
14714 end;
14715 end if;
14716
14717 Set_Main_CPU
14718 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
14719
14720 -- Task case
14721
14722 elsif Nkind (P) = N_Task_Definition then
14723 Arg := Get_Pragma_Arg (Arg1);
14724 Ent := Defining_Identifier (Parent (P));
14725
14726 -- The expression must be analyzed in the special manner
14727 -- described in "Handling of Default and Per-Object
14728 -- Expressions" in sem.ads.
14729
14730 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
14731
14732 -- Anything else is incorrect
14733
14734 else
14735 Pragma_Misplaced;
14736 end if;
14737
14738 -- Check duplicate pragma before we chain the pragma in the Rep
14739 -- Item chain of Ent.
14740
14741 Check_Duplicate_Pragma (Ent);
14742 Record_Rep_Item (Ent, N);
14743 end CPU;
14744
14745 --------------------
14746 -- Deadline_Floor --
14747 --------------------
14748
14749 -- pragma Deadline_Floor (time_span_EXPRESSION);
14750
14751 when Pragma_Deadline_Floor => Deadline_Floor : declare
14752 P : constant Node_Id := Parent (N);
14753 Arg : Node_Id;
14754 Ent : Entity_Id;
14755
14756 begin
14757 GNAT_Pragma;
14758 Check_No_Identifiers;
14759 Check_Arg_Count (1);
14760
14761 Arg := Get_Pragma_Arg (Arg1);
14762
14763 -- The expression must be analyzed in the special manner described
14764 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
14765
14766 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
14767
14768 -- Only protected types allowed
14769
14770 if Nkind (P) /= N_Protected_Definition then
14771 Pragma_Misplaced;
14772
14773 else
14774 Ent := Defining_Identifier (Parent (P));
14775
14776 -- Check duplicate pragma before we chain the pragma in the Rep
14777 -- Item chain of Ent.
14778
14779 Check_Duplicate_Pragma (Ent);
14780 Record_Rep_Item (Ent, N);
14781 end if;
14782 end Deadline_Floor;
14783
14784 -----------
14785 -- Debug --
14786 -----------
14787
14788 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
14789
14790 when Pragma_Debug => Debug : declare
14791 Cond : Node_Id;
14792 Call : Node_Id;
14793
14794 begin
14795 GNAT_Pragma;
14796
14797 -- The condition for executing the call is that the expander
14798 -- is active and that we are not ignoring this debug pragma.
14799
14800 Cond :=
14801 New_Occurrence_Of
14802 (Boolean_Literals
14803 (Expander_Active and then not Is_Ignored (N)),
14804 Loc);
14805
14806 if not Is_Ignored (N) then
14807 Set_SCO_Pragma_Enabled (Loc);
14808 end if;
14809
14810 if Arg_Count = 2 then
14811 Cond :=
14812 Make_And_Then (Loc,
14813 Left_Opnd => Relocate_Node (Cond),
14814 Right_Opnd => Get_Pragma_Arg (Arg1));
14815 Call := Get_Pragma_Arg (Arg2);
14816 else
14817 Call := Get_Pragma_Arg (Arg1);
14818 end if;
14819
14820 if Nkind_In (Call, N_Expanded_Name,
14821 N_Function_Call,
14822 N_Identifier,
14823 N_Indexed_Component,
14824 N_Selected_Component)
14825 then
14826 -- If this pragma Debug comes from source, its argument was
14827 -- parsed as a name form (which is syntactically identical).
14828 -- In a generic context a parameterless call will be left as
14829 -- an expanded name (if global) or selected_component if local.
14830 -- Change it to a procedure call statement now.
14831
14832 Change_Name_To_Procedure_Call_Statement (Call);
14833
14834 elsif Nkind (Call) = N_Procedure_Call_Statement then
14835
14836 -- Already in the form of a procedure call statement: nothing
14837 -- to do (could happen in case of an internally generated
14838 -- pragma Debug).
14839
14840 null;
14841
14842 else
14843 -- All other cases: diagnose error
14844
14845 Error_Msg
14846 ("argument of pragma ""Debug"" is not procedure call",
14847 Sloc (Call));
14848 return;
14849 end if;
14850
14851 -- Rewrite into a conditional with an appropriate condition. We
14852 -- wrap the procedure call in a block so that overhead from e.g.
14853 -- use of the secondary stack does not generate execution overhead
14854 -- for suppressed conditions.
14855
14856 -- Normally the analysis that follows will freeze the subprogram
14857 -- being called. However, if the call is to a null procedure,
14858 -- we want to freeze it before creating the block, because the
14859 -- analysis that follows may be done with expansion disabled, in
14860 -- which case the body will not be generated, leading to spurious
14861 -- errors.
14862
14863 if Nkind (Call) = N_Procedure_Call_Statement
14864 and then Is_Entity_Name (Name (Call))
14865 then
14866 Analyze (Name (Call));
14867 Freeze_Before (N, Entity (Name (Call)));
14868 end if;
14869
14870 Rewrite (N,
14871 Make_Implicit_If_Statement (N,
14872 Condition => Cond,
14873 Then_Statements => New_List (
14874 Make_Block_Statement (Loc,
14875 Handled_Statement_Sequence =>
14876 Make_Handled_Sequence_Of_Statements (Loc,
14877 Statements => New_List (Relocate_Node (Call)))))));
14878 Analyze (N);
14879
14880 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
14881 -- after analysis of the normally rewritten node, to capture all
14882 -- references to entities, which avoids issuing wrong warnings
14883 -- about unused entities.
14884
14885 if GNATprove_Mode then
14886 Rewrite (N, Make_Null_Statement (Loc));
14887 end if;
14888 end Debug;
14889
14890 ------------------
14891 -- Debug_Policy --
14892 ------------------
14893
14894 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
14895
14896 when Pragma_Debug_Policy =>
14897 GNAT_Pragma;
14898 Check_Arg_Count (1);
14899 Check_No_Identifiers;
14900 Check_Arg_Is_Identifier (Arg1);
14901
14902 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
14903 -- rewrite it that way, and let the rest of the checking come
14904 -- from analyzing the rewritten pragma.
14905
14906 Rewrite (N,
14907 Make_Pragma (Loc,
14908 Chars => Name_Check_Policy,
14909 Pragma_Argument_Associations => New_List (
14910 Make_Pragma_Argument_Association (Loc,
14911 Expression => Make_Identifier (Loc, Name_Debug)),
14912
14913 Make_Pragma_Argument_Association (Loc,
14914 Expression => Get_Pragma_Arg (Arg1)))));
14915 Analyze (N);
14916
14917 -------------------------------
14918 -- Default_Initial_Condition --
14919 -------------------------------
14920
14921 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
14922
14923 when Pragma_Default_Initial_Condition => DIC : declare
14924 Discard : Boolean;
14925 Stmt : Node_Id;
14926 Typ : Entity_Id;
14927
14928 begin
14929 GNAT_Pragma;
14930 Check_No_Identifiers;
14931 Check_At_Most_N_Arguments (1);
14932
14933 Typ := Empty;
14934 Stmt := Prev (N);
14935 while Present (Stmt) loop
14936
14937 -- Skip prior pragmas, but check for duplicates
14938
14939 if Nkind (Stmt) = N_Pragma then
14940 if Pragma_Name (Stmt) = Pname then
14941 Duplication_Error
14942 (Prag => N,
14943 Prev => Stmt);
14944 raise Pragma_Exit;
14945 end if;
14946
14947 -- Skip internally generated code. Note that derived type
14948 -- declarations of untagged types with discriminants are
14949 -- rewritten as private type declarations.
14950
14951 elsif not Comes_From_Source (Stmt)
14952 and then Nkind (Stmt) /= N_Private_Type_Declaration
14953 then
14954 null;
14955
14956 -- The associated private type [extension] has been found, stop
14957 -- the search.
14958
14959 elsif Nkind_In (Stmt, N_Private_Extension_Declaration,
14960 N_Private_Type_Declaration)
14961 then
14962 Typ := Defining_Entity (Stmt);
14963 exit;
14964
14965 -- The pragma does not apply to a legal construct, issue an
14966 -- error and stop the analysis.
14967
14968 else
14969 Pragma_Misplaced;
14970 return;
14971 end if;
14972
14973 Stmt := Prev (Stmt);
14974 end loop;
14975
14976 -- The pragma does not apply to a legal construct, issue an error
14977 -- and stop the analysis.
14978
14979 if No (Typ) then
14980 Pragma_Misplaced;
14981 return;
14982 end if;
14983
14984 -- A pragma that applies to a Ghost entity becomes Ghost for the
14985 -- purposes of legality checks and removal of ignored Ghost code.
14986
14987 Mark_Ghost_Pragma (N, Typ);
14988
14989 -- The pragma signals that the type defines its own DIC assertion
14990 -- expression.
14991
14992 Set_Has_Own_DIC (Typ);
14993
14994 -- Chain the pragma on the rep item chain for further processing
14995
14996 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
14997
14998 -- Create the declaration of the procedure which verifies the
14999 -- assertion expression of pragma DIC at runtime.
15000
15001 Build_DIC_Procedure_Declaration (Typ);
15002 end DIC;
15003
15004 ----------------------------------
15005 -- Default_Scalar_Storage_Order --
15006 ----------------------------------
15007
15008 -- pragma Default_Scalar_Storage_Order
15009 -- (High_Order_First | Low_Order_First);
15010
15011 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
15012 Default : Character;
15013
15014 begin
15015 GNAT_Pragma;
15016 Check_Arg_Count (1);
15017
15018 -- Default_Scalar_Storage_Order can appear as a configuration
15019 -- pragma, or in a declarative part of a package spec.
15020
15021 if not Is_Configuration_Pragma then
15022 Check_Is_In_Decl_Part_Or_Package_Spec;
15023 end if;
15024
15025 Check_No_Identifiers;
15026 Check_Arg_Is_One_Of
15027 (Arg1, Name_High_Order_First, Name_Low_Order_First);
15028 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15029 Default := Fold_Upper (Name_Buffer (1));
15030
15031 if not Support_Nondefault_SSO_On_Target
15032 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
15033 then
15034 if Warn_On_Unrecognized_Pragma then
15035 Error_Msg_N
15036 ("non-default Scalar_Storage_Order not supported "
15037 & "on target?g?", N);
15038 Error_Msg_N
15039 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
15040 end if;
15041
15042 -- Here set the specified default
15043
15044 else
15045 Opt.Default_SSO := Default;
15046 end if;
15047 end DSSO;
15048
15049 --------------------------
15050 -- Default_Storage_Pool --
15051 --------------------------
15052
15053 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
15054
15055 when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
15056 Pool : Node_Id;
15057
15058 begin
15059 Ada_2012_Pragma;
15060 Check_Arg_Count (1);
15061
15062 -- Default_Storage_Pool can appear as a configuration pragma, or
15063 -- in a declarative part of a package spec.
15064
15065 if not Is_Configuration_Pragma then
15066 Check_Is_In_Decl_Part_Or_Package_Spec;
15067 end if;
15068
15069 if From_Aspect_Specification (N) then
15070 declare
15071 E : constant Entity_Id := Entity (Corresponding_Aspect (N));
15072 begin
15073 if not In_Open_Scopes (E) then
15074 Error_Msg_N
15075 ("aspect must apply to package or subprogram", N);
15076 end if;
15077 end;
15078 end if;
15079
15080 if Present (Arg1) then
15081 Pool := Get_Pragma_Arg (Arg1);
15082
15083 -- Case of Default_Storage_Pool (null);
15084
15085 if Nkind (Pool) = N_Null then
15086 Analyze (Pool);
15087
15088 -- This is an odd case, this is not really an expression,
15089 -- so we don't have a type for it. So just set the type to
15090 -- Empty.
15091
15092 Set_Etype (Pool, Empty);
15093
15094 -- Case of Default_Storage_Pool (storage_pool_NAME);
15095
15096 else
15097 -- If it's a configuration pragma, then the only allowed
15098 -- argument is "null".
15099
15100 if Is_Configuration_Pragma then
15101 Error_Pragma_Arg ("NULL expected", Arg1);
15102 end if;
15103
15104 -- The expected type for a non-"null" argument is
15105 -- Root_Storage_Pool'Class, and the pool must be a variable.
15106
15107 Analyze_And_Resolve
15108 (Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
15109
15110 if Is_Variable (Pool) then
15111
15112 -- A pragma that applies to a Ghost entity becomes Ghost
15113 -- for the purposes of legality checks and removal of
15114 -- ignored Ghost code.
15115
15116 Mark_Ghost_Pragma (N, Entity (Pool));
15117
15118 else
15119 Error_Pragma_Arg
15120 ("default storage pool must be a variable", Arg1);
15121 end if;
15122 end if;
15123
15124 -- Record the pool name (or null). Freeze.Freeze_Entity for an
15125 -- access type will use this information to set the appropriate
15126 -- attributes of the access type. If the pragma appears in a
15127 -- generic unit it is ignored, given that it may refer to a
15128 -- local entity.
15129
15130 if not Inside_A_Generic then
15131 Default_Pool := Pool;
15132 end if;
15133 end if;
15134 end Default_Storage_Pool;
15135
15136 -------------
15137 -- Depends --
15138 -------------
15139
15140 -- pragma Depends (DEPENDENCY_RELATION);
15141
15142 -- DEPENDENCY_RELATION ::=
15143 -- null
15144 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
15145
15146 -- DEPENDENCY_CLAUSE ::=
15147 -- OUTPUT_LIST =>[+] INPUT_LIST
15148 -- | NULL_DEPENDENCY_CLAUSE
15149
15150 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
15151
15152 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
15153
15154 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
15155
15156 -- OUTPUT ::= NAME | FUNCTION_RESULT
15157 -- INPUT ::= NAME
15158
15159 -- where FUNCTION_RESULT is a function Result attribute_reference
15160
15161 -- Characteristics:
15162
15163 -- * Analysis - The annotation undergoes initial checks to verify
15164 -- the legal placement and context. Secondary checks fully analyze
15165 -- the dependency clauses in:
15166
15167 -- Analyze_Depends_In_Decl_Part
15168
15169 -- * Expansion - None.
15170
15171 -- * Template - The annotation utilizes the generic template of the
15172 -- related subprogram [body] when it is:
15173
15174 -- aspect on subprogram declaration
15175 -- aspect on stand-alone subprogram body
15176 -- pragma on stand-alone subprogram body
15177
15178 -- The annotation must prepare its own template when it is:
15179
15180 -- pragma on subprogram declaration
15181
15182 -- * Globals - Capture of global references must occur after full
15183 -- analysis.
15184
15185 -- * Instance - The annotation is instantiated automatically when
15186 -- the related generic subprogram [body] is instantiated except for
15187 -- the "pragma on subprogram declaration" case. In that scenario
15188 -- the annotation must instantiate itself.
15189
15190 when Pragma_Depends => Depends : declare
15191 Legal : Boolean;
15192 Spec_Id : Entity_Id;
15193 Subp_Decl : Node_Id;
15194
15195 begin
15196 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
15197
15198 if Legal then
15199
15200 -- Chain the pragma on the contract for further processing by
15201 -- Analyze_Depends_In_Decl_Part.
15202
15203 Add_Contract_Item (N, Spec_Id);
15204
15205 -- Fully analyze the pragma when it appears inside an entry
15206 -- or subprogram body because it cannot benefit from forward
15207 -- references.
15208
15209 if Nkind_In (Subp_Decl, N_Entry_Body,
15210 N_Subprogram_Body,
15211 N_Subprogram_Body_Stub)
15212 then
15213 -- The legality checks of pragmas Depends and Global are
15214 -- affected by the SPARK mode in effect and the volatility
15215 -- of the context. In addition these two pragmas are subject
15216 -- to an inherent order:
15217
15218 -- 1) Global
15219 -- 2) Depends
15220
15221 -- Analyze all these pragmas in the order outlined above
15222
15223 Analyze_If_Present (Pragma_SPARK_Mode);
15224 Analyze_If_Present (Pragma_Volatile_Function);
15225 Analyze_If_Present (Pragma_Global);
15226 Analyze_Depends_In_Decl_Part (N);
15227 end if;
15228 end if;
15229 end Depends;
15230
15231 ---------------------
15232 -- Detect_Blocking --
15233 ---------------------
15234
15235 -- pragma Detect_Blocking;
15236
15237 when Pragma_Detect_Blocking =>
15238 Ada_2005_Pragma;
15239 Check_Arg_Count (0);
15240 Check_Valid_Configuration_Pragma;
15241 Detect_Blocking := True;
15242
15243 ------------------------------------
15244 -- Disable_Atomic_Synchronization --
15245 ------------------------------------
15246
15247 -- pragma Disable_Atomic_Synchronization [(Entity)];
15248
15249 when Pragma_Disable_Atomic_Synchronization =>
15250 GNAT_Pragma;
15251 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
15252
15253 -------------------
15254 -- Discard_Names --
15255 -------------------
15256
15257 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
15258
15259 when Pragma_Discard_Names => Discard_Names : declare
15260 E : Entity_Id;
15261 E_Id : Node_Id;
15262
15263 begin
15264 Check_Ada_83_Warning;
15265
15266 -- Deal with configuration pragma case
15267
15268 if Arg_Count = 0 and then Is_Configuration_Pragma then
15269 Global_Discard_Names := True;
15270 return;
15271
15272 -- Otherwise, check correct appropriate context
15273
15274 else
15275 Check_Is_In_Decl_Part_Or_Package_Spec;
15276
15277 if Arg_Count = 0 then
15278
15279 -- If there is no parameter, then from now on this pragma
15280 -- applies to any enumeration, exception or tagged type
15281 -- defined in the current declarative part, and recursively
15282 -- to any nested scope.
15283
15284 Set_Discard_Names (Current_Scope);
15285 return;
15286
15287 else
15288 Check_Arg_Count (1);
15289 Check_Optional_Identifier (Arg1, Name_On);
15290 Check_Arg_Is_Local_Name (Arg1);
15291
15292 E_Id := Get_Pragma_Arg (Arg1);
15293
15294 if Etype (E_Id) = Any_Type then
15295 return;
15296 end if;
15297
15298 E := Entity (E_Id);
15299
15300 -- A pragma that applies to a Ghost entity becomes Ghost for
15301 -- the purposes of legality checks and removal of ignored
15302 -- Ghost code.
15303
15304 Mark_Ghost_Pragma (N, E);
15305
15306 if (Is_First_Subtype (E)
15307 and then
15308 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
15309 or else Ekind (E) = E_Exception
15310 then
15311 Set_Discard_Names (E);
15312 Record_Rep_Item (E, N);
15313
15314 else
15315 Error_Pragma_Arg
15316 ("inappropriate entity for pragma%", Arg1);
15317 end if;
15318 end if;
15319 end if;
15320 end Discard_Names;
15321
15322 ------------------------
15323 -- Dispatching_Domain --
15324 ------------------------
15325
15326 -- pragma Dispatching_Domain (EXPRESSION);
15327
15328 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
15329 P : constant Node_Id := Parent (N);
15330 Arg : Node_Id;
15331 Ent : Entity_Id;
15332
15333 begin
15334 Ada_2012_Pragma;
15335 Check_No_Identifiers;
15336 Check_Arg_Count (1);
15337
15338 -- This pragma is born obsolete, but not the aspect
15339
15340 if not From_Aspect_Specification (N) then
15341 Check_Restriction
15342 (No_Obsolescent_Features, Pragma_Identifier (N));
15343 end if;
15344
15345 if Nkind (P) = N_Task_Definition then
15346 Arg := Get_Pragma_Arg (Arg1);
15347 Ent := Defining_Identifier (Parent (P));
15348
15349 -- A pragma that applies to a Ghost entity becomes Ghost for
15350 -- the purposes of legality checks and removal of ignored Ghost
15351 -- code.
15352
15353 Mark_Ghost_Pragma (N, Ent);
15354
15355 -- The expression must be analyzed in the special manner
15356 -- described in "Handling of Default and Per-Object
15357 -- Expressions" in sem.ads.
15358
15359 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
15360
15361 -- Check duplicate pragma before we chain the pragma in the Rep
15362 -- Item chain of Ent.
15363
15364 Check_Duplicate_Pragma (Ent);
15365 Record_Rep_Item (Ent, N);
15366
15367 -- Anything else is incorrect
15368
15369 else
15370 Pragma_Misplaced;
15371 end if;
15372 end Dispatching_Domain;
15373
15374 ---------------
15375 -- Elaborate --
15376 ---------------
15377
15378 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
15379
15380 when Pragma_Elaborate => Elaborate : declare
15381 Arg : Node_Id;
15382 Citem : Node_Id;
15383
15384 begin
15385 -- Pragma must be in context items list of a compilation unit
15386
15387 if not Is_In_Context_Clause then
15388 Pragma_Misplaced;
15389 end if;
15390
15391 -- Must be at least one argument
15392
15393 if Arg_Count = 0 then
15394 Error_Pragma ("pragma% requires at least one argument");
15395 end if;
15396
15397 -- In Ada 83 mode, there can be no items following it in the
15398 -- context list except other pragmas and implicit with clauses
15399 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
15400 -- placement rule does not apply.
15401
15402 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
15403 Citem := Next (N);
15404 while Present (Citem) loop
15405 if Nkind (Citem) = N_Pragma
15406 or else (Nkind (Citem) = N_With_Clause
15407 and then Implicit_With (Citem))
15408 then
15409 null;
15410 else
15411 Error_Pragma
15412 ("(Ada 83) pragma% must be at end of context clause");
15413 end if;
15414
15415 Next (Citem);
15416 end loop;
15417 end if;
15418
15419 -- Finally, the arguments must all be units mentioned in a with
15420 -- clause in the same context clause. Note we already checked (in
15421 -- Par.Prag) that the arguments are all identifiers or selected
15422 -- components.
15423
15424 Arg := Arg1;
15425 Outer : while Present (Arg) loop
15426 Citem := First (List_Containing (N));
15427 Inner : while Citem /= N loop
15428 if Nkind (Citem) = N_With_Clause
15429 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
15430 then
15431 Set_Elaborate_Present (Citem, True);
15432 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
15433
15434 -- With the pragma present, elaboration calls on
15435 -- subprograms from the named unit need no further
15436 -- checks, as long as the pragma appears in the current
15437 -- compilation unit. If the pragma appears in some unit
15438 -- in the context, there might still be a need for an
15439 -- Elaborate_All_Desirable from the current compilation
15440 -- to the named unit, so we keep the check enabled. This
15441 -- does not apply in SPARK mode, where we allow pragma
15442 -- Elaborate, but we don't trust it to be right so we
15443 -- will still insist on the Elaborate_All.
15444
15445 if Legacy_Elaboration_Checks
15446 and then In_Extended_Main_Source_Unit (N)
15447 and then SPARK_Mode /= On
15448 then
15449 Set_Suppress_Elaboration_Warnings
15450 (Entity (Name (Citem)));
15451 end if;
15452
15453 exit Inner;
15454 end if;
15455
15456 Next (Citem);
15457 end loop Inner;
15458
15459 if Citem = N then
15460 Error_Pragma_Arg
15461 ("argument of pragma% is not withed unit", Arg);
15462 end if;
15463
15464 Next (Arg);
15465 end loop Outer;
15466 end Elaborate;
15467
15468 -------------------
15469 -- Elaborate_All --
15470 -------------------
15471
15472 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
15473
15474 when Pragma_Elaborate_All => Elaborate_All : declare
15475 Arg : Node_Id;
15476 Citem : Node_Id;
15477
15478 begin
15479 Check_Ada_83_Warning;
15480
15481 -- Pragma must be in context items list of a compilation unit
15482
15483 if not Is_In_Context_Clause then
15484 Pragma_Misplaced;
15485 end if;
15486
15487 -- Must be at least one argument
15488
15489 if Arg_Count = 0 then
15490 Error_Pragma ("pragma% requires at least one argument");
15491 end if;
15492
15493 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
15494 -- have to appear at the end of the context clause, but may
15495 -- appear mixed in with other items, even in Ada 83 mode.
15496
15497 -- Final check: the arguments must all be units mentioned in
15498 -- a with clause in the same context clause. Note that we
15499 -- already checked (in Par.Prag) that all the arguments are
15500 -- either identifiers or selected components.
15501
15502 Arg := Arg1;
15503 Outr : while Present (Arg) loop
15504 Citem := First (List_Containing (N));
15505 Innr : while Citem /= N loop
15506 if Nkind (Citem) = N_With_Clause
15507 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
15508 then
15509 Set_Elaborate_All_Present (Citem, True);
15510 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
15511
15512 -- Suppress warnings and elaboration checks on the named
15513 -- unit if the pragma is in the current compilation, as
15514 -- for pragma Elaborate.
15515
15516 if Legacy_Elaboration_Checks
15517 and then In_Extended_Main_Source_Unit (N)
15518 then
15519 Set_Suppress_Elaboration_Warnings
15520 (Entity (Name (Citem)));
15521 end if;
15522
15523 exit Innr;
15524 end if;
15525
15526 Next (Citem);
15527 end loop Innr;
15528
15529 if Citem = N then
15530 Set_Error_Posted (N);
15531 Error_Pragma_Arg
15532 ("argument of pragma% is not withed unit", Arg);
15533 end if;
15534
15535 Next (Arg);
15536 end loop Outr;
15537 end Elaborate_All;
15538
15539 --------------------
15540 -- Elaborate_Body --
15541 --------------------
15542
15543 -- pragma Elaborate_Body [( library_unit_NAME )];
15544
15545 when Pragma_Elaborate_Body => Elaborate_Body : declare
15546 Cunit_Node : Node_Id;
15547 Cunit_Ent : Entity_Id;
15548
15549 begin
15550 Check_Ada_83_Warning;
15551 Check_Valid_Library_Unit_Pragma;
15552
15553 if Nkind (N) = N_Null_Statement then
15554 return;
15555 end if;
15556
15557 Cunit_Node := Cunit (Current_Sem_Unit);
15558 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15559
15560 -- A pragma that applies to a Ghost entity becomes Ghost for the
15561 -- purposes of legality checks and removal of ignored Ghost code.
15562
15563 Mark_Ghost_Pragma (N, Cunit_Ent);
15564
15565 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
15566 N_Subprogram_Body)
15567 then
15568 Error_Pragma ("pragma% must refer to a spec, not a body");
15569 else
15570 Set_Body_Required (Cunit_Node);
15571 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
15572
15573 -- If we are in dynamic elaboration mode, then we suppress
15574 -- elaboration warnings for the unit, since it is definitely
15575 -- fine NOT to do dynamic checks at the first level (and such
15576 -- checks will be suppressed because no elaboration boolean
15577 -- is created for Elaborate_Body packages).
15578 --
15579 -- But in the static model of elaboration, Elaborate_Body is
15580 -- definitely NOT good enough to ensure elaboration safety on
15581 -- its own, since the body may WITH other units that are not
15582 -- safe from an elaboration point of view, so a client must
15583 -- still do an Elaborate_All on such units.
15584 --
15585 -- Debug flag -gnatdD restores the old behavior of 3.13, where
15586 -- Elaborate_Body always suppressed elab warnings.
15587
15588 if Legacy_Elaboration_Checks
15589 and then (Dynamic_Elaboration_Checks or Debug_Flag_DD)
15590 then
15591 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
15592 end if;
15593 end if;
15594 end Elaborate_Body;
15595
15596 ------------------------
15597 -- Elaboration_Checks --
15598 ------------------------
15599
15600 -- pragma Elaboration_Checks (Static | Dynamic);
15601
15602 when Pragma_Elaboration_Checks => Elaboration_Checks : declare
15603 procedure Check_Duplicate_Elaboration_Checks_Pragma;
15604 -- Emit an error if the current context list already contains
15605 -- a previous Elaboration_Checks pragma. This routine raises
15606 -- Pragma_Exit if a duplicate is found.
15607
15608 procedure Ignore_Elaboration_Checks_Pragma;
15609 -- Warn that the effects of the pragma are ignored. This routine
15610 -- raises Pragma_Exit.
15611
15612 -----------------------------------------------
15613 -- Check_Duplicate_Elaboration_Checks_Pragma --
15614 -----------------------------------------------
15615
15616 procedure Check_Duplicate_Elaboration_Checks_Pragma is
15617 Item : Node_Id;
15618
15619 begin
15620 Item := Prev (N);
15621 while Present (Item) loop
15622 if Nkind (Item) = N_Pragma
15623 and then Pragma_Name (Item) = Name_Elaboration_Checks
15624 then
15625 Duplication_Error
15626 (Prag => N,
15627 Prev => Item);
15628 raise Pragma_Exit;
15629 end if;
15630
15631 Prev (Item);
15632 end loop;
15633 end Check_Duplicate_Elaboration_Checks_Pragma;
15634
15635 --------------------------------------
15636 -- Ignore_Elaboration_Checks_Pragma --
15637 --------------------------------------
15638
15639 procedure Ignore_Elaboration_Checks_Pragma is
15640 begin
15641 Error_Msg_Name_1 := Pname;
15642 Error_Msg_N ("??effects of pragma % are ignored", N);
15643 Error_Msg_N
15644 ("\place pragma on initial declaration of library unit", N);
15645
15646 raise Pragma_Exit;
15647 end Ignore_Elaboration_Checks_Pragma;
15648
15649 -- Local variables
15650
15651 Context : constant Node_Id := Parent (N);
15652 Unt : Node_Id;
15653
15654 -- Start of processing for Elaboration_Checks
15655
15656 begin
15657 GNAT_Pragma;
15658 Check_Arg_Count (1);
15659 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
15660
15661 -- The pragma appears in a configuration file
15662
15663 if No (Context) then
15664 Check_Valid_Configuration_Pragma;
15665 Check_Duplicate_Elaboration_Checks_Pragma;
15666
15667 -- The pragma acts as a configuration pragma in a compilation unit
15668
15669 -- pragma Elaboration_Checks (...);
15670 -- package Pack is ...;
15671
15672 elsif Nkind (Context) = N_Compilation_Unit
15673 and then List_Containing (N) = Context_Items (Context)
15674 then
15675 Check_Valid_Configuration_Pragma;
15676 Check_Duplicate_Elaboration_Checks_Pragma;
15677
15678 Unt := Unit (Context);
15679
15680 -- The pragma must appear on the initial declaration of a unit.
15681 -- If this is not the case, warn that the effects of the pragma
15682 -- are ignored.
15683
15684 if Nkind (Unt) = N_Package_Body then
15685 Ignore_Elaboration_Checks_Pragma;
15686
15687 -- Check the Acts_As_Spec flag of the compilation units itself
15688 -- to determine whether the subprogram body completes since it
15689 -- has not been analyzed yet. This is safe because compilation
15690 -- units are not overloadable.
15691
15692 elsif Nkind (Unt) = N_Subprogram_Body
15693 and then not Acts_As_Spec (Context)
15694 then
15695 Ignore_Elaboration_Checks_Pragma;
15696
15697 elsif Nkind (Unt) = N_Subunit then
15698 Ignore_Elaboration_Checks_Pragma;
15699 end if;
15700
15701 -- Otherwise the pragma does not appear at the configuration level
15702 -- and is illegal.
15703
15704 else
15705 Pragma_Misplaced;
15706 end if;
15707
15708 -- At this point the pragma is not a duplicate, and appears in the
15709 -- proper context. Set the elaboration model in effect.
15710
15711 Dynamic_Elaboration_Checks :=
15712 Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic;
15713 end Elaboration_Checks;
15714
15715 ---------------
15716 -- Eliminate --
15717 ---------------
15718
15719 -- pragma Eliminate (
15720 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
15721 -- [Entity =>] IDENTIFIER |
15722 -- SELECTED_COMPONENT |
15723 -- STRING_LITERAL]
15724 -- [, Source_Location => SOURCE_TRACE]);
15725
15726 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
15727 -- SOURCE_TRACE ::= STRING_LITERAL
15728
15729 when Pragma_Eliminate => Eliminate : declare
15730 Args : Args_List (1 .. 5);
15731 Names : constant Name_List (1 .. 5) := (
15732 Name_Unit_Name,
15733 Name_Entity,
15734 Name_Parameter_Types,
15735 Name_Result_Type,
15736 Name_Source_Location);
15737
15738 -- Note : Parameter_Types and Result_Type are leftovers from
15739 -- prior implementations of the pragma. They are not generated
15740 -- by the gnatelim tool, and play no role in selecting which
15741 -- of a set of overloaded names is chosen for elimination.
15742
15743 Unit_Name : Node_Id renames Args (1);
15744 Entity : Node_Id renames Args (2);
15745 Parameter_Types : Node_Id renames Args (3);
15746 Result_Type : Node_Id renames Args (4);
15747 Source_Location : Node_Id renames Args (5);
15748
15749 begin
15750 GNAT_Pragma;
15751 Check_Valid_Configuration_Pragma;
15752 Gather_Associations (Names, Args);
15753
15754 if No (Unit_Name) then
15755 Error_Pragma ("missing Unit_Name argument for pragma%");
15756 end if;
15757
15758 if No (Entity)
15759 and then (Present (Parameter_Types)
15760 or else
15761 Present (Result_Type)
15762 or else
15763 Present (Source_Location))
15764 then
15765 Error_Pragma ("missing Entity argument for pragma%");
15766 end if;
15767
15768 if (Present (Parameter_Types)
15769 or else
15770 Present (Result_Type))
15771 and then
15772 Present (Source_Location)
15773 then
15774 Error_Pragma
15775 ("parameter profile and source location cannot be used "
15776 & "together in pragma%");
15777 end if;
15778
15779 Process_Eliminate_Pragma
15780 (N,
15781 Unit_Name,
15782 Entity,
15783 Parameter_Types,
15784 Result_Type,
15785 Source_Location);
15786 end Eliminate;
15787
15788 -----------------------------------
15789 -- Enable_Atomic_Synchronization --
15790 -----------------------------------
15791
15792 -- pragma Enable_Atomic_Synchronization [(Entity)];
15793
15794 when Pragma_Enable_Atomic_Synchronization =>
15795 GNAT_Pragma;
15796 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
15797
15798 ------------
15799 -- Export --
15800 ------------
15801
15802 -- pragma Export (
15803 -- [ Convention =>] convention_IDENTIFIER,
15804 -- [ Entity =>] LOCAL_NAME
15805 -- [, [External_Name =>] static_string_EXPRESSION ]
15806 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15807
15808 when Pragma_Export => Export : declare
15809 C : Convention_Id;
15810 Def_Id : Entity_Id;
15811
15812 pragma Warnings (Off, C);
15813
15814 begin
15815 Check_Ada_83_Warning;
15816 Check_Arg_Order
15817 ((Name_Convention,
15818 Name_Entity,
15819 Name_External_Name,
15820 Name_Link_Name));
15821
15822 Check_At_Least_N_Arguments (2);
15823 Check_At_Most_N_Arguments (4);
15824
15825 -- In Relaxed_RM_Semantics, support old Ada 83 style:
15826 -- pragma Export (Entity, "external name");
15827
15828 if Relaxed_RM_Semantics
15829 and then Arg_Count = 2
15830 and then Nkind (Expression (Arg2)) = N_String_Literal
15831 then
15832 C := Convention_C;
15833 Def_Id := Get_Pragma_Arg (Arg1);
15834 Analyze (Def_Id);
15835
15836 if not Is_Entity_Name (Def_Id) then
15837 Error_Pragma_Arg ("entity name required", Arg1);
15838 end if;
15839
15840 Def_Id := Entity (Def_Id);
15841 Set_Exported (Def_Id, Arg1);
15842
15843 else
15844 Process_Convention (C, Def_Id);
15845
15846 -- A pragma that applies to a Ghost entity becomes Ghost for
15847 -- the purposes of legality checks and removal of ignored Ghost
15848 -- code.
15849
15850 Mark_Ghost_Pragma (N, Def_Id);
15851
15852 if Ekind (Def_Id) /= E_Constant then
15853 Note_Possible_Modification
15854 (Get_Pragma_Arg (Arg2), Sure => False);
15855 end if;
15856
15857 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
15858 Set_Exported (Def_Id, Arg2);
15859 end if;
15860
15861 -- If the entity is a deferred constant, propagate the information
15862 -- to the full view, because gigi elaborates the full view only.
15863
15864 if Ekind (Def_Id) = E_Constant
15865 and then Present (Full_View (Def_Id))
15866 then
15867 declare
15868 Id2 : constant Entity_Id := Full_View (Def_Id);
15869 begin
15870 Set_Is_Exported (Id2, Is_Exported (Def_Id));
15871 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
15872 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
15873 end;
15874 end if;
15875 end Export;
15876
15877 ---------------------
15878 -- Export_Function --
15879 ---------------------
15880
15881 -- pragma Export_Function (
15882 -- [Internal =>] LOCAL_NAME
15883 -- [, [External =>] EXTERNAL_SYMBOL]
15884 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15885 -- [, [Result_Type =>] TYPE_DESIGNATOR]
15886 -- [, [Mechanism =>] MECHANISM]
15887 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
15888
15889 -- EXTERNAL_SYMBOL ::=
15890 -- IDENTIFIER
15891 -- | static_string_EXPRESSION
15892
15893 -- PARAMETER_TYPES ::=
15894 -- null
15895 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15896
15897 -- TYPE_DESIGNATOR ::=
15898 -- subtype_NAME
15899 -- | subtype_Name ' Access
15900
15901 -- MECHANISM ::=
15902 -- MECHANISM_NAME
15903 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15904
15905 -- MECHANISM_ASSOCIATION ::=
15906 -- [formal_parameter_NAME =>] MECHANISM_NAME
15907
15908 -- MECHANISM_NAME ::=
15909 -- Value
15910 -- | Reference
15911
15912 when Pragma_Export_Function => Export_Function : declare
15913 Args : Args_List (1 .. 6);
15914 Names : constant Name_List (1 .. 6) := (
15915 Name_Internal,
15916 Name_External,
15917 Name_Parameter_Types,
15918 Name_Result_Type,
15919 Name_Mechanism,
15920 Name_Result_Mechanism);
15921
15922 Internal : Node_Id renames Args (1);
15923 External : Node_Id renames Args (2);
15924 Parameter_Types : Node_Id renames Args (3);
15925 Result_Type : Node_Id renames Args (4);
15926 Mechanism : Node_Id renames Args (5);
15927 Result_Mechanism : Node_Id renames Args (6);
15928
15929 begin
15930 GNAT_Pragma;
15931 Gather_Associations (Names, Args);
15932 Process_Extended_Import_Export_Subprogram_Pragma (
15933 Arg_Internal => Internal,
15934 Arg_External => External,
15935 Arg_Parameter_Types => Parameter_Types,
15936 Arg_Result_Type => Result_Type,
15937 Arg_Mechanism => Mechanism,
15938 Arg_Result_Mechanism => Result_Mechanism);
15939 end Export_Function;
15940
15941 -------------------
15942 -- Export_Object --
15943 -------------------
15944
15945 -- pragma Export_Object (
15946 -- [Internal =>] LOCAL_NAME
15947 -- [, [External =>] EXTERNAL_SYMBOL]
15948 -- [, [Size =>] EXTERNAL_SYMBOL]);
15949
15950 -- EXTERNAL_SYMBOL ::=
15951 -- IDENTIFIER
15952 -- | static_string_EXPRESSION
15953
15954 -- PARAMETER_TYPES ::=
15955 -- null
15956 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15957
15958 -- TYPE_DESIGNATOR ::=
15959 -- subtype_NAME
15960 -- | subtype_Name ' Access
15961
15962 -- MECHANISM ::=
15963 -- MECHANISM_NAME
15964 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15965
15966 -- MECHANISM_ASSOCIATION ::=
15967 -- [formal_parameter_NAME =>] MECHANISM_NAME
15968
15969 -- MECHANISM_NAME ::=
15970 -- Value
15971 -- | Reference
15972
15973 when Pragma_Export_Object => Export_Object : declare
15974 Args : Args_List (1 .. 3);
15975 Names : constant Name_List (1 .. 3) := (
15976 Name_Internal,
15977 Name_External,
15978 Name_Size);
15979
15980 Internal : Node_Id renames Args (1);
15981 External : Node_Id renames Args (2);
15982 Size : Node_Id renames Args (3);
15983
15984 begin
15985 GNAT_Pragma;
15986 Gather_Associations (Names, Args);
15987 Process_Extended_Import_Export_Object_Pragma (
15988 Arg_Internal => Internal,
15989 Arg_External => External,
15990 Arg_Size => Size);
15991 end Export_Object;
15992
15993 ----------------------
15994 -- Export_Procedure --
15995 ----------------------
15996
15997 -- pragma Export_Procedure (
15998 -- [Internal =>] LOCAL_NAME
15999 -- [, [External =>] EXTERNAL_SYMBOL]
16000 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16001 -- [, [Mechanism =>] MECHANISM]);
16002
16003 -- EXTERNAL_SYMBOL ::=
16004 -- IDENTIFIER
16005 -- | static_string_EXPRESSION
16006
16007 -- PARAMETER_TYPES ::=
16008 -- null
16009 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16010
16011 -- TYPE_DESIGNATOR ::=
16012 -- subtype_NAME
16013 -- | subtype_Name ' Access
16014
16015 -- MECHANISM ::=
16016 -- MECHANISM_NAME
16017 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16018
16019 -- MECHANISM_ASSOCIATION ::=
16020 -- [formal_parameter_NAME =>] MECHANISM_NAME
16021
16022 -- MECHANISM_NAME ::=
16023 -- Value
16024 -- | Reference
16025
16026 when Pragma_Export_Procedure => Export_Procedure : declare
16027 Args : Args_List (1 .. 4);
16028 Names : constant Name_List (1 .. 4) := (
16029 Name_Internal,
16030 Name_External,
16031 Name_Parameter_Types,
16032 Name_Mechanism);
16033
16034 Internal : Node_Id renames Args (1);
16035 External : Node_Id renames Args (2);
16036 Parameter_Types : Node_Id renames Args (3);
16037 Mechanism : Node_Id renames Args (4);
16038
16039 begin
16040 GNAT_Pragma;
16041 Gather_Associations (Names, Args);
16042 Process_Extended_Import_Export_Subprogram_Pragma (
16043 Arg_Internal => Internal,
16044 Arg_External => External,
16045 Arg_Parameter_Types => Parameter_Types,
16046 Arg_Mechanism => Mechanism);
16047 end Export_Procedure;
16048
16049 ------------------
16050 -- Export_Value --
16051 ------------------
16052
16053 -- pragma Export_Value (
16054 -- [Value =>] static_integer_EXPRESSION,
16055 -- [Link_Name =>] static_string_EXPRESSION);
16056
16057 when Pragma_Export_Value =>
16058 GNAT_Pragma;
16059 Check_Arg_Order ((Name_Value, Name_Link_Name));
16060 Check_Arg_Count (2);
16061
16062 Check_Optional_Identifier (Arg1, Name_Value);
16063 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
16064
16065 Check_Optional_Identifier (Arg2, Name_Link_Name);
16066 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16067
16068 -----------------------------
16069 -- Export_Valued_Procedure --
16070 -----------------------------
16071
16072 -- pragma Export_Valued_Procedure (
16073 -- [Internal =>] LOCAL_NAME
16074 -- [, [External =>] EXTERNAL_SYMBOL,]
16075 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16076 -- [, [Mechanism =>] MECHANISM]);
16077
16078 -- EXTERNAL_SYMBOL ::=
16079 -- IDENTIFIER
16080 -- | static_string_EXPRESSION
16081
16082 -- PARAMETER_TYPES ::=
16083 -- null
16084 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16085
16086 -- TYPE_DESIGNATOR ::=
16087 -- subtype_NAME
16088 -- | subtype_Name ' Access
16089
16090 -- MECHANISM ::=
16091 -- MECHANISM_NAME
16092 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16093
16094 -- MECHANISM_ASSOCIATION ::=
16095 -- [formal_parameter_NAME =>] MECHANISM_NAME
16096
16097 -- MECHANISM_NAME ::=
16098 -- Value
16099 -- | Reference
16100
16101 when Pragma_Export_Valued_Procedure =>
16102 Export_Valued_Procedure : declare
16103 Args : Args_List (1 .. 4);
16104 Names : constant Name_List (1 .. 4) := (
16105 Name_Internal,
16106 Name_External,
16107 Name_Parameter_Types,
16108 Name_Mechanism);
16109
16110 Internal : Node_Id renames Args (1);
16111 External : Node_Id renames Args (2);
16112 Parameter_Types : Node_Id renames Args (3);
16113 Mechanism : Node_Id renames Args (4);
16114
16115 begin
16116 GNAT_Pragma;
16117 Gather_Associations (Names, Args);
16118 Process_Extended_Import_Export_Subprogram_Pragma (
16119 Arg_Internal => Internal,
16120 Arg_External => External,
16121 Arg_Parameter_Types => Parameter_Types,
16122 Arg_Mechanism => Mechanism);
16123 end Export_Valued_Procedure;
16124
16125 -------------------
16126 -- Extend_System --
16127 -------------------
16128
16129 -- pragma Extend_System ([Name =>] Identifier);
16130
16131 when Pragma_Extend_System =>
16132 GNAT_Pragma;
16133 Check_Valid_Configuration_Pragma;
16134 Check_Arg_Count (1);
16135 Check_Optional_Identifier (Arg1, Name_Name);
16136 Check_Arg_Is_Identifier (Arg1);
16137
16138 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16139
16140 if Name_Len > 4
16141 and then Name_Buffer (1 .. 4) = "aux_"
16142 then
16143 if Present (System_Extend_Pragma_Arg) then
16144 if Chars (Get_Pragma_Arg (Arg1)) =
16145 Chars (Expression (System_Extend_Pragma_Arg))
16146 then
16147 null;
16148 else
16149 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
16150 Error_Pragma ("pragma% conflicts with that #");
16151 end if;
16152
16153 else
16154 System_Extend_Pragma_Arg := Arg1;
16155
16156 if not GNAT_Mode then
16157 System_Extend_Unit := Arg1;
16158 end if;
16159 end if;
16160 else
16161 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
16162 end if;
16163
16164 ------------------------
16165 -- Extensions_Allowed --
16166 ------------------------
16167
16168 -- pragma Extensions_Allowed (ON | OFF);
16169
16170 when Pragma_Extensions_Allowed =>
16171 GNAT_Pragma;
16172 Check_Arg_Count (1);
16173 Check_No_Identifiers;
16174 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16175
16176 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
16177 Extensions_Allowed := True;
16178 Ada_Version := Ada_Version_Type'Last;
16179
16180 else
16181 Extensions_Allowed := False;
16182 Ada_Version := Ada_Version_Explicit;
16183 Ada_Version_Pragma := Empty;
16184 end if;
16185
16186 ------------------------
16187 -- Extensions_Visible --
16188 ------------------------
16189
16190 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
16191
16192 -- Characteristics:
16193
16194 -- * Analysis - The annotation is fully analyzed immediately upon
16195 -- elaboration as its expression must be static.
16196
16197 -- * Expansion - None.
16198
16199 -- * Template - The annotation utilizes the generic template of the
16200 -- related subprogram [body] when it is:
16201
16202 -- aspect on subprogram declaration
16203 -- aspect on stand-alone subprogram body
16204 -- pragma on stand-alone subprogram body
16205
16206 -- The annotation must prepare its own template when it is:
16207
16208 -- pragma on subprogram declaration
16209
16210 -- * Globals - Capture of global references must occur after full
16211 -- analysis.
16212
16213 -- * Instance - The annotation is instantiated automatically when
16214 -- the related generic subprogram [body] is instantiated except for
16215 -- the "pragma on subprogram declaration" case. In that scenario
16216 -- the annotation must instantiate itself.
16217
16218 when Pragma_Extensions_Visible => Extensions_Visible : declare
16219 Formal : Entity_Id;
16220 Has_OK_Formal : Boolean := False;
16221 Spec_Id : Entity_Id;
16222 Subp_Decl : Node_Id;
16223
16224 begin
16225 GNAT_Pragma;
16226 Check_No_Identifiers;
16227 Check_At_Most_N_Arguments (1);
16228
16229 Subp_Decl :=
16230 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
16231
16232 -- Abstract subprogram declaration
16233
16234 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
16235 null;
16236
16237 -- Generic subprogram declaration
16238
16239 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
16240 null;
16241
16242 -- Body acts as spec
16243
16244 elsif Nkind (Subp_Decl) = N_Subprogram_Body
16245 and then No (Corresponding_Spec (Subp_Decl))
16246 then
16247 null;
16248
16249 -- Body stub acts as spec
16250
16251 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
16252 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
16253 then
16254 null;
16255
16256 -- Subprogram declaration
16257
16258 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
16259 null;
16260
16261 -- Otherwise the pragma is associated with an illegal construct
16262
16263 else
16264 Error_Pragma ("pragma % must apply to a subprogram");
16265 return;
16266 end if;
16267
16268 -- Mark the pragma as Ghost if the related subprogram is also
16269 -- Ghost. This also ensures that any expansion performed further
16270 -- below will produce Ghost nodes.
16271
16272 Spec_Id := Unique_Defining_Entity (Subp_Decl);
16273 Mark_Ghost_Pragma (N, Spec_Id);
16274
16275 -- Chain the pragma on the contract for completeness
16276
16277 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
16278
16279 -- The legality checks of pragma Extension_Visible are affected
16280 -- by the SPARK mode in effect. Analyze all pragmas in specific
16281 -- order.
16282
16283 Analyze_If_Present (Pragma_SPARK_Mode);
16284
16285 -- Examine the formals of the related subprogram
16286
16287 Formal := First_Formal (Spec_Id);
16288 while Present (Formal) loop
16289
16290 -- At least one of the formals is of a specific tagged type,
16291 -- the pragma is legal.
16292
16293 if Is_Specific_Tagged_Type (Etype (Formal)) then
16294 Has_OK_Formal := True;
16295 exit;
16296
16297 -- A generic subprogram with at least one formal of a private
16298 -- type ensures the legality of the pragma because the actual
16299 -- may be specifically tagged. Note that this is verified by
16300 -- the check above at instantiation time.
16301
16302 elsif Is_Private_Type (Etype (Formal))
16303 and then Is_Generic_Type (Etype (Formal))
16304 then
16305 Has_OK_Formal := True;
16306 exit;
16307 end if;
16308
16309 Next_Formal (Formal);
16310 end loop;
16311
16312 if not Has_OK_Formal then
16313 Error_Msg_Name_1 := Pname;
16314 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
16315 Error_Msg_NE
16316 ("\subprogram & lacks parameter of specific tagged or "
16317 & "generic private type", N, Spec_Id);
16318
16319 return;
16320 end if;
16321
16322 -- Analyze the Boolean expression (if any)
16323
16324 if Present (Arg1) then
16325 Check_Static_Boolean_Expression
16326 (Expression (Get_Argument (N, Spec_Id)));
16327 end if;
16328 end Extensions_Visible;
16329
16330 --------------
16331 -- External --
16332 --------------
16333
16334 -- pragma External (
16335 -- [ Convention =>] convention_IDENTIFIER,
16336 -- [ Entity =>] LOCAL_NAME
16337 -- [, [External_Name =>] static_string_EXPRESSION ]
16338 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16339
16340 when Pragma_External => External : declare
16341 C : Convention_Id;
16342 E : Entity_Id;
16343 pragma Warnings (Off, C);
16344
16345 begin
16346 GNAT_Pragma;
16347 Check_Arg_Order
16348 ((Name_Convention,
16349 Name_Entity,
16350 Name_External_Name,
16351 Name_Link_Name));
16352 Check_At_Least_N_Arguments (2);
16353 Check_At_Most_N_Arguments (4);
16354 Process_Convention (C, E);
16355
16356 -- A pragma that applies to a Ghost entity becomes Ghost for the
16357 -- purposes of legality checks and removal of ignored Ghost code.
16358
16359 Mark_Ghost_Pragma (N, E);
16360
16361 Note_Possible_Modification
16362 (Get_Pragma_Arg (Arg2), Sure => False);
16363 Process_Interface_Name (E, Arg3, Arg4, N);
16364 Set_Exported (E, Arg2);
16365 end External;
16366
16367 --------------------------
16368 -- External_Name_Casing --
16369 --------------------------
16370
16371 -- pragma External_Name_Casing (
16372 -- UPPERCASE | LOWERCASE
16373 -- [, AS_IS | UPPERCASE | LOWERCASE]);
16374
16375 when Pragma_External_Name_Casing =>
16376 GNAT_Pragma;
16377 Check_No_Identifiers;
16378
16379 if Arg_Count = 2 then
16380 Check_Arg_Is_One_Of
16381 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
16382
16383 case Chars (Get_Pragma_Arg (Arg2)) is
16384 when Name_As_Is =>
16385 Opt.External_Name_Exp_Casing := As_Is;
16386
16387 when Name_Uppercase =>
16388 Opt.External_Name_Exp_Casing := Uppercase;
16389
16390 when Name_Lowercase =>
16391 Opt.External_Name_Exp_Casing := Lowercase;
16392
16393 when others =>
16394 null;
16395 end case;
16396
16397 else
16398 Check_Arg_Count (1);
16399 end if;
16400
16401 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
16402
16403 case Chars (Get_Pragma_Arg (Arg1)) is
16404 when Name_Uppercase =>
16405 Opt.External_Name_Imp_Casing := Uppercase;
16406
16407 when Name_Lowercase =>
16408 Opt.External_Name_Imp_Casing := Lowercase;
16409
16410 when others =>
16411 null;
16412 end case;
16413
16414 ---------------
16415 -- Fast_Math --
16416 ---------------
16417
16418 -- pragma Fast_Math;
16419
16420 when Pragma_Fast_Math =>
16421 GNAT_Pragma;
16422 Check_No_Identifiers;
16423 Check_Valid_Configuration_Pragma;
16424 Fast_Math := True;
16425
16426 --------------------------
16427 -- Favor_Top_Level --
16428 --------------------------
16429
16430 -- pragma Favor_Top_Level (type_NAME);
16431
16432 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
16433 Typ : Entity_Id;
16434
16435 begin
16436 GNAT_Pragma;
16437 Check_No_Identifiers;
16438 Check_Arg_Count (1);
16439 Check_Arg_Is_Local_Name (Arg1);
16440 Typ := Entity (Get_Pragma_Arg (Arg1));
16441
16442 -- A pragma that applies to a Ghost entity becomes Ghost for the
16443 -- purposes of legality checks and removal of ignored Ghost code.
16444
16445 Mark_Ghost_Pragma (N, Typ);
16446
16447 -- If it's an access-to-subprogram type (in particular, not a
16448 -- subtype), set the flag on that type.
16449
16450 if Is_Access_Subprogram_Type (Typ) then
16451 Set_Can_Use_Internal_Rep (Typ, False);
16452
16453 -- Otherwise it's an error (name denotes the wrong sort of entity)
16454
16455 else
16456 Error_Pragma_Arg
16457 ("access-to-subprogram type expected",
16458 Get_Pragma_Arg (Arg1));
16459 end if;
16460 end Favor_Top_Level;
16461
16462 ---------------------------
16463 -- Finalize_Storage_Only --
16464 ---------------------------
16465
16466 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
16467
16468 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
16469 Assoc : constant Node_Id := Arg1;
16470 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
16471 Typ : Entity_Id;
16472
16473 begin
16474 GNAT_Pragma;
16475 Check_No_Identifiers;
16476 Check_Arg_Count (1);
16477 Check_Arg_Is_Local_Name (Arg1);
16478
16479 Find_Type (Type_Id);
16480 Typ := Entity (Type_Id);
16481
16482 if Typ = Any_Type
16483 or else Rep_Item_Too_Early (Typ, N)
16484 then
16485 return;
16486 else
16487 Typ := Underlying_Type (Typ);
16488 end if;
16489
16490 if not Is_Controlled (Typ) then
16491 Error_Pragma ("pragma% must specify controlled type");
16492 end if;
16493
16494 Check_First_Subtype (Arg1);
16495
16496 if Finalize_Storage_Only (Typ) then
16497 Error_Pragma ("duplicate pragma%, only one allowed");
16498
16499 elsif not Rep_Item_Too_Late (Typ, N) then
16500 Set_Finalize_Storage_Only (Base_Type (Typ), True);
16501 end if;
16502 end Finalize_Storage;
16503
16504 -----------
16505 -- Ghost --
16506 -----------
16507
16508 -- pragma Ghost [ (boolean_EXPRESSION) ];
16509
16510 when Pragma_Ghost => Ghost : declare
16511 Context : Node_Id;
16512 Expr : Node_Id;
16513 Id : Entity_Id;
16514 Orig_Stmt : Node_Id;
16515 Prev_Id : Entity_Id;
16516 Stmt : Node_Id;
16517
16518 begin
16519 GNAT_Pragma;
16520 Check_No_Identifiers;
16521 Check_At_Most_N_Arguments (1);
16522
16523 Id := Empty;
16524 Stmt := Prev (N);
16525 while Present (Stmt) loop
16526
16527 -- Skip prior pragmas, but check for duplicates
16528
16529 if Nkind (Stmt) = N_Pragma then
16530 if Pragma_Name (Stmt) = Pname then
16531 Duplication_Error
16532 (Prag => N,
16533 Prev => Stmt);
16534 raise Pragma_Exit;
16535 end if;
16536
16537 -- Task unit declared without a definition cannot be subject to
16538 -- pragma Ghost (SPARK RM 6.9(19)).
16539
16540 elsif Nkind_In (Stmt, N_Single_Task_Declaration,
16541 N_Task_Type_Declaration)
16542 then
16543 Error_Pragma ("pragma % cannot apply to a task type");
16544 return;
16545
16546 -- Skip internally generated code
16547
16548 elsif not Comes_From_Source (Stmt) then
16549 Orig_Stmt := Original_Node (Stmt);
16550
16551 -- When pragma Ghost applies to an untagged derivation, the
16552 -- derivation is transformed into a [sub]type declaration.
16553
16554 if Nkind_In (Stmt, N_Full_Type_Declaration,
16555 N_Subtype_Declaration)
16556 and then Comes_From_Source (Orig_Stmt)
16557 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
16558 and then Nkind (Type_Definition (Orig_Stmt)) =
16559 N_Derived_Type_Definition
16560 then
16561 Id := Defining_Entity (Stmt);
16562 exit;
16563
16564 -- When pragma Ghost applies to an object declaration which
16565 -- is initialized by means of a function call that returns
16566 -- on the secondary stack, the object declaration becomes a
16567 -- renaming.
16568
16569 elsif Nkind (Stmt) = N_Object_Renaming_Declaration
16570 and then Comes_From_Source (Orig_Stmt)
16571 and then Nkind (Orig_Stmt) = N_Object_Declaration
16572 then
16573 Id := Defining_Entity (Stmt);
16574 exit;
16575
16576 -- When pragma Ghost applies to an expression function, the
16577 -- expression function is transformed into a subprogram.
16578
16579 elsif Nkind (Stmt) = N_Subprogram_Declaration
16580 and then Comes_From_Source (Orig_Stmt)
16581 and then Nkind (Orig_Stmt) = N_Expression_Function
16582 then
16583 Id := Defining_Entity (Stmt);
16584 exit;
16585 end if;
16586
16587 -- The pragma applies to a legal construct, stop the traversal
16588
16589 elsif Nkind_In (Stmt, N_Abstract_Subprogram_Declaration,
16590 N_Full_Type_Declaration,
16591 N_Generic_Subprogram_Declaration,
16592 N_Object_Declaration,
16593 N_Private_Extension_Declaration,
16594 N_Private_Type_Declaration,
16595 N_Subprogram_Declaration,
16596 N_Subtype_Declaration)
16597 then
16598 Id := Defining_Entity (Stmt);
16599 exit;
16600
16601 -- The pragma does not apply to a legal construct, issue an
16602 -- error and stop the analysis.
16603
16604 else
16605 Error_Pragma
16606 ("pragma % must apply to an object, package, subprogram "
16607 & "or type");
16608 return;
16609 end if;
16610
16611 Stmt := Prev (Stmt);
16612 end loop;
16613
16614 Context := Parent (N);
16615
16616 -- Handle compilation units
16617
16618 if Nkind (Context) = N_Compilation_Unit_Aux then
16619 Context := Unit (Parent (Context));
16620 end if;
16621
16622 -- Protected and task types cannot be subject to pragma Ghost
16623 -- (SPARK RM 6.9(19)).
16624
16625 if Nkind_In (Context, N_Protected_Body, N_Protected_Definition)
16626 then
16627 Error_Pragma ("pragma % cannot apply to a protected type");
16628 return;
16629
16630 elsif Nkind_In (Context, N_Task_Body, N_Task_Definition) then
16631 Error_Pragma ("pragma % cannot apply to a task type");
16632 return;
16633 end if;
16634
16635 if No (Id) then
16636
16637 -- When pragma Ghost is associated with a [generic] package, it
16638 -- appears in the visible declarations.
16639
16640 if Nkind (Context) = N_Package_Specification
16641 and then Present (Visible_Declarations (Context))
16642 and then List_Containing (N) = Visible_Declarations (Context)
16643 then
16644 Id := Defining_Entity (Context);
16645
16646 -- Pragma Ghost applies to a stand-alone subprogram body
16647
16648 elsif Nkind (Context) = N_Subprogram_Body
16649 and then No (Corresponding_Spec (Context))
16650 then
16651 Id := Defining_Entity (Context);
16652
16653 -- Pragma Ghost applies to a subprogram declaration that acts
16654 -- as a compilation unit.
16655
16656 elsif Nkind (Context) = N_Subprogram_Declaration then
16657 Id := Defining_Entity (Context);
16658
16659 -- Pragma Ghost applies to a generic subprogram
16660
16661 elsif Nkind (Context) = N_Generic_Subprogram_Declaration then
16662 Id := Defining_Entity (Specification (Context));
16663 end if;
16664 end if;
16665
16666 if No (Id) then
16667 Error_Pragma
16668 ("pragma % must apply to an object, package, subprogram or "
16669 & "type");
16670 return;
16671 end if;
16672
16673 -- Handle completions of types and constants that are subject to
16674 -- pragma Ghost.
16675
16676 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
16677 Prev_Id := Incomplete_Or_Partial_View (Id);
16678
16679 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
16680 Error_Msg_Name_1 := Pname;
16681
16682 -- The full declaration of a deferred constant cannot be
16683 -- subject to pragma Ghost unless the deferred declaration
16684 -- is also Ghost (SPARK RM 6.9(9)).
16685
16686 if Ekind (Prev_Id) = E_Constant then
16687 Error_Msg_Name_1 := Pname;
16688 Error_Msg_NE (Fix_Error
16689 ("pragma % must apply to declaration of deferred "
16690 & "constant &"), N, Id);
16691 return;
16692
16693 -- Pragma Ghost may appear on the full view of an incomplete
16694 -- type because the incomplete declaration lacks aspects and
16695 -- cannot be subject to pragma Ghost.
16696
16697 elsif Ekind (Prev_Id) = E_Incomplete_Type then
16698 null;
16699
16700 -- The full declaration of a type cannot be subject to
16701 -- pragma Ghost unless the partial view is also Ghost
16702 -- (SPARK RM 6.9(9)).
16703
16704 else
16705 Error_Msg_NE (Fix_Error
16706 ("pragma % must apply to partial view of type &"),
16707 N, Id);
16708 return;
16709 end if;
16710 end if;
16711
16712 -- A synchronized object cannot be subject to pragma Ghost
16713 -- (SPARK RM 6.9(19)).
16714
16715 elsif Ekind (Id) = E_Variable then
16716 if Is_Protected_Type (Etype (Id)) then
16717 Error_Pragma ("pragma % cannot apply to a protected object");
16718 return;
16719
16720 elsif Is_Task_Type (Etype (Id)) then
16721 Error_Pragma ("pragma % cannot apply to a task object");
16722 return;
16723 end if;
16724 end if;
16725
16726 -- Analyze the Boolean expression (if any)
16727
16728 if Present (Arg1) then
16729 Expr := Get_Pragma_Arg (Arg1);
16730
16731 Analyze_And_Resolve (Expr, Standard_Boolean);
16732
16733 if Is_OK_Static_Expression (Expr) then
16734
16735 -- "Ghostness" cannot be turned off once enabled within a
16736 -- region (SPARK RM 6.9(6)).
16737
16738 if Is_False (Expr_Value (Expr))
16739 and then Ghost_Mode > None
16740 then
16741 Error_Pragma
16742 ("pragma % with value False cannot appear in enabled "
16743 & "ghost region");
16744 return;
16745 end if;
16746
16747 -- Otherwie the expression is not static
16748
16749 else
16750 Error_Pragma_Arg
16751 ("expression of pragma % must be static", Expr);
16752 return;
16753 end if;
16754 end if;
16755
16756 Set_Is_Ghost_Entity (Id);
16757 end Ghost;
16758
16759 ------------
16760 -- Global --
16761 ------------
16762
16763 -- pragma Global (GLOBAL_SPECIFICATION);
16764
16765 -- GLOBAL_SPECIFICATION ::=
16766 -- null
16767 -- | (GLOBAL_LIST)
16768 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
16769
16770 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
16771
16772 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
16773 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
16774 -- GLOBAL_ITEM ::= NAME
16775
16776 -- Characteristics:
16777
16778 -- * Analysis - The annotation undergoes initial checks to verify
16779 -- the legal placement and context. Secondary checks fully analyze
16780 -- the dependency clauses in:
16781
16782 -- Analyze_Global_In_Decl_Part
16783
16784 -- * Expansion - None.
16785
16786 -- * Template - The annotation utilizes the generic template of the
16787 -- related subprogram [body] when it is:
16788
16789 -- aspect on subprogram declaration
16790 -- aspect on stand-alone subprogram body
16791 -- pragma on stand-alone subprogram body
16792
16793 -- The annotation must prepare its own template when it is:
16794
16795 -- pragma on subprogram declaration
16796
16797 -- * Globals - Capture of global references must occur after full
16798 -- analysis.
16799
16800 -- * Instance - The annotation is instantiated automatically when
16801 -- the related generic subprogram [body] is instantiated except for
16802 -- the "pragma on subprogram declaration" case. In that scenario
16803 -- the annotation must instantiate itself.
16804
16805 when Pragma_Global => Global : declare
16806 Legal : Boolean;
16807 Spec_Id : Entity_Id;
16808 Subp_Decl : Node_Id;
16809
16810 begin
16811 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
16812
16813 if Legal then
16814
16815 -- Chain the pragma on the contract for further processing by
16816 -- Analyze_Global_In_Decl_Part.
16817
16818 Add_Contract_Item (N, Spec_Id);
16819
16820 -- Fully analyze the pragma when it appears inside an entry
16821 -- or subprogram body because it cannot benefit from forward
16822 -- references.
16823
16824 if Nkind_In (Subp_Decl, N_Entry_Body,
16825 N_Subprogram_Body,
16826 N_Subprogram_Body_Stub)
16827 then
16828 -- The legality checks of pragmas Depends and Global are
16829 -- affected by the SPARK mode in effect and the volatility
16830 -- of the context. In addition these two pragmas are subject
16831 -- to an inherent order:
16832
16833 -- 1) Global
16834 -- 2) Depends
16835
16836 -- Analyze all these pragmas in the order outlined above
16837
16838 Analyze_If_Present (Pragma_SPARK_Mode);
16839 Analyze_If_Present (Pragma_Volatile_Function);
16840 Analyze_Global_In_Decl_Part (N);
16841 Analyze_If_Present (Pragma_Depends);
16842 end if;
16843 end if;
16844 end Global;
16845
16846 -----------
16847 -- Ident --
16848 -----------
16849
16850 -- pragma Ident (static_string_EXPRESSION)
16851
16852 -- Note: pragma Comment shares this processing. Pragma Ident is
16853 -- identical in effect to pragma Commment.
16854
16855 when Pragma_Comment
16856 | Pragma_Ident
16857 =>
16858 Ident : declare
16859 Str : Node_Id;
16860
16861 begin
16862 GNAT_Pragma;
16863 Check_Arg_Count (1);
16864 Check_No_Identifiers;
16865 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16866 Store_Note (N);
16867
16868 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
16869
16870 declare
16871 CS : Node_Id;
16872 GP : Node_Id;
16873
16874 begin
16875 GP := Parent (Parent (N));
16876
16877 if Nkind_In (GP, N_Package_Declaration,
16878 N_Generic_Package_Declaration)
16879 then
16880 GP := Parent (GP);
16881 end if;
16882
16883 -- If we have a compilation unit, then record the ident value,
16884 -- checking for improper duplication.
16885
16886 if Nkind (GP) = N_Compilation_Unit then
16887 CS := Ident_String (Current_Sem_Unit);
16888
16889 if Present (CS) then
16890
16891 -- If we have multiple instances, concatenate them.
16892
16893 Start_String (Strval (CS));
16894 Store_String_Char (' ');
16895 Store_String_Chars (Strval (Str));
16896 Set_Strval (CS, End_String);
16897
16898 else
16899 Set_Ident_String (Current_Sem_Unit, Str);
16900 end if;
16901
16902 -- For subunits, we just ignore the Ident, since in GNAT these
16903 -- are not separate object files, and hence not separate units
16904 -- in the unit table.
16905
16906 elsif Nkind (GP) = N_Subunit then
16907 null;
16908 end if;
16909 end;
16910 end Ident;
16911
16912 -------------------
16913 -- Ignore_Pragma --
16914 -------------------
16915
16916 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
16917
16918 -- Entirely handled in the parser, nothing to do here
16919
16920 when Pragma_Ignore_Pragma =>
16921 null;
16922
16923 ----------------------------
16924 -- Implementation_Defined --
16925 ----------------------------
16926
16927 -- pragma Implementation_Defined (LOCAL_NAME);
16928
16929 -- Marks previously declared entity as implementation defined. For
16930 -- an overloaded entity, applies to the most recent homonym.
16931
16932 -- pragma Implementation_Defined;
16933
16934 -- The form with no arguments appears anywhere within a scope, most
16935 -- typically a package spec, and indicates that all entities that are
16936 -- defined within the package spec are Implementation_Defined.
16937
16938 when Pragma_Implementation_Defined => Implementation_Defined : declare
16939 Ent : Entity_Id;
16940
16941 begin
16942 GNAT_Pragma;
16943 Check_No_Identifiers;
16944
16945 -- Form with no arguments
16946
16947 if Arg_Count = 0 then
16948 Set_Is_Implementation_Defined (Current_Scope);
16949
16950 -- Form with one argument
16951
16952 else
16953 Check_Arg_Count (1);
16954 Check_Arg_Is_Local_Name (Arg1);
16955 Ent := Entity (Get_Pragma_Arg (Arg1));
16956 Set_Is_Implementation_Defined (Ent);
16957 end if;
16958 end Implementation_Defined;
16959
16960 -----------------
16961 -- Implemented --
16962 -----------------
16963
16964 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
16965
16966 -- IMPLEMENTATION_KIND ::=
16967 -- By_Entry | By_Protected_Procedure | By_Any | Optional
16968
16969 -- "By_Any" and "Optional" are treated as synonyms in order to
16970 -- support Ada 2012 aspect Synchronization.
16971
16972 when Pragma_Implemented => Implemented : declare
16973 Proc_Id : Entity_Id;
16974 Typ : Entity_Id;
16975
16976 begin
16977 Ada_2012_Pragma;
16978 Check_Arg_Count (2);
16979 Check_No_Identifiers;
16980 Check_Arg_Is_Identifier (Arg1);
16981 Check_Arg_Is_Local_Name (Arg1);
16982 Check_Arg_Is_One_Of (Arg2,
16983 Name_By_Any,
16984 Name_By_Entry,
16985 Name_By_Protected_Procedure,
16986 Name_Optional);
16987
16988 -- Extract the name of the local procedure
16989
16990 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
16991
16992 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
16993 -- primitive procedure of a synchronized tagged type.
16994
16995 if Ekind (Proc_Id) = E_Procedure
16996 and then Is_Primitive (Proc_Id)
16997 and then Present (First_Formal (Proc_Id))
16998 then
16999 Typ := Etype (First_Formal (Proc_Id));
17000
17001 if Is_Tagged_Type (Typ)
17002 and then
17003
17004 -- Check for a protected, a synchronized or a task interface
17005
17006 ((Is_Interface (Typ)
17007 and then Is_Synchronized_Interface (Typ))
17008
17009 -- Check for a protected type or a task type that implements
17010 -- an interface.
17011
17012 or else
17013 (Is_Concurrent_Record_Type (Typ)
17014 and then Present (Interfaces (Typ)))
17015
17016 -- In analysis-only mode, examine original protected type
17017
17018 or else
17019 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
17020 and then Present (Interface_List (Parent (Typ))))
17021
17022 -- Check for a private record extension with keyword
17023 -- "synchronized".
17024
17025 or else
17026 (Ekind_In (Typ, E_Record_Type_With_Private,
17027 E_Record_Subtype_With_Private)
17028 and then Synchronized_Present (Parent (Typ))))
17029 then
17030 null;
17031 else
17032 Error_Pragma_Arg
17033 ("controlling formal must be of synchronized tagged type",
17034 Arg1);
17035 return;
17036 end if;
17037
17038 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
17039 -- By_Protected_Procedure to the primitive procedure of a task
17040 -- interface.
17041
17042 if Chars (Arg2) = Name_By_Protected_Procedure
17043 and then Is_Interface (Typ)
17044 and then Is_Task_Interface (Typ)
17045 then
17046 Error_Pragma_Arg
17047 ("implementation kind By_Protected_Procedure cannot be "
17048 & "applied to a task interface primitive", Arg2);
17049 return;
17050 end if;
17051
17052 -- Procedures declared inside a protected type must be accepted
17053
17054 elsif Ekind (Proc_Id) = E_Procedure
17055 and then Is_Protected_Type (Scope (Proc_Id))
17056 then
17057 null;
17058
17059 -- The first argument is not a primitive procedure
17060
17061 else
17062 Error_Pragma_Arg
17063 ("pragma % must be applied to a primitive procedure", Arg1);
17064 return;
17065 end if;
17066
17067 Record_Rep_Item (Proc_Id, N);
17068 end Implemented;
17069
17070 ----------------------
17071 -- Implicit_Packing --
17072 ----------------------
17073
17074 -- pragma Implicit_Packing;
17075
17076 when Pragma_Implicit_Packing =>
17077 GNAT_Pragma;
17078 Check_Arg_Count (0);
17079 Implicit_Packing := True;
17080
17081 ------------
17082 -- Import --
17083 ------------
17084
17085 -- pragma Import (
17086 -- [Convention =>] convention_IDENTIFIER,
17087 -- [Entity =>] LOCAL_NAME
17088 -- [, [External_Name =>] static_string_EXPRESSION ]
17089 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17090
17091 when Pragma_Import =>
17092 Check_Ada_83_Warning;
17093 Check_Arg_Order
17094 ((Name_Convention,
17095 Name_Entity,
17096 Name_External_Name,
17097 Name_Link_Name));
17098
17099 Check_At_Least_N_Arguments (2);
17100 Check_At_Most_N_Arguments (4);
17101 Process_Import_Or_Interface;
17102
17103 ---------------------
17104 -- Import_Function --
17105 ---------------------
17106
17107 -- pragma Import_Function (
17108 -- [Internal =>] LOCAL_NAME,
17109 -- [, [External =>] EXTERNAL_SYMBOL]
17110 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17111 -- [, [Result_Type =>] SUBTYPE_MARK]
17112 -- [, [Mechanism =>] MECHANISM]
17113 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
17114
17115 -- EXTERNAL_SYMBOL ::=
17116 -- IDENTIFIER
17117 -- | static_string_EXPRESSION
17118
17119 -- PARAMETER_TYPES ::=
17120 -- null
17121 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17122
17123 -- TYPE_DESIGNATOR ::=
17124 -- subtype_NAME
17125 -- | subtype_Name ' Access
17126
17127 -- MECHANISM ::=
17128 -- MECHANISM_NAME
17129 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17130
17131 -- MECHANISM_ASSOCIATION ::=
17132 -- [formal_parameter_NAME =>] MECHANISM_NAME
17133
17134 -- MECHANISM_NAME ::=
17135 -- Value
17136 -- | Reference
17137
17138 when Pragma_Import_Function => Import_Function : declare
17139 Args : Args_List (1 .. 6);
17140 Names : constant Name_List (1 .. 6) := (
17141 Name_Internal,
17142 Name_External,
17143 Name_Parameter_Types,
17144 Name_Result_Type,
17145 Name_Mechanism,
17146 Name_Result_Mechanism);
17147
17148 Internal : Node_Id renames Args (1);
17149 External : Node_Id renames Args (2);
17150 Parameter_Types : Node_Id renames Args (3);
17151 Result_Type : Node_Id renames Args (4);
17152 Mechanism : Node_Id renames Args (5);
17153 Result_Mechanism : Node_Id renames Args (6);
17154
17155 begin
17156 GNAT_Pragma;
17157 Gather_Associations (Names, Args);
17158 Process_Extended_Import_Export_Subprogram_Pragma (
17159 Arg_Internal => Internal,
17160 Arg_External => External,
17161 Arg_Parameter_Types => Parameter_Types,
17162 Arg_Result_Type => Result_Type,
17163 Arg_Mechanism => Mechanism,
17164 Arg_Result_Mechanism => Result_Mechanism);
17165 end Import_Function;
17166
17167 -------------------
17168 -- Import_Object --
17169 -------------------
17170
17171 -- pragma Import_Object (
17172 -- [Internal =>] LOCAL_NAME
17173 -- [, [External =>] EXTERNAL_SYMBOL]
17174 -- [, [Size =>] EXTERNAL_SYMBOL]);
17175
17176 -- EXTERNAL_SYMBOL ::=
17177 -- IDENTIFIER
17178 -- | static_string_EXPRESSION
17179
17180 when Pragma_Import_Object => Import_Object : declare
17181 Args : Args_List (1 .. 3);
17182 Names : constant Name_List (1 .. 3) := (
17183 Name_Internal,
17184 Name_External,
17185 Name_Size);
17186
17187 Internal : Node_Id renames Args (1);
17188 External : Node_Id renames Args (2);
17189 Size : Node_Id renames Args (3);
17190
17191 begin
17192 GNAT_Pragma;
17193 Gather_Associations (Names, Args);
17194 Process_Extended_Import_Export_Object_Pragma (
17195 Arg_Internal => Internal,
17196 Arg_External => External,
17197 Arg_Size => Size);
17198 end Import_Object;
17199
17200 ----------------------
17201 -- Import_Procedure --
17202 ----------------------
17203
17204 -- pragma Import_Procedure (
17205 -- [Internal =>] LOCAL_NAME
17206 -- [, [External =>] EXTERNAL_SYMBOL]
17207 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17208 -- [, [Mechanism =>] MECHANISM]);
17209
17210 -- EXTERNAL_SYMBOL ::=
17211 -- IDENTIFIER
17212 -- | static_string_EXPRESSION
17213
17214 -- PARAMETER_TYPES ::=
17215 -- null
17216 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17217
17218 -- TYPE_DESIGNATOR ::=
17219 -- subtype_NAME
17220 -- | subtype_Name ' Access
17221
17222 -- MECHANISM ::=
17223 -- MECHANISM_NAME
17224 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17225
17226 -- MECHANISM_ASSOCIATION ::=
17227 -- [formal_parameter_NAME =>] MECHANISM_NAME
17228
17229 -- MECHANISM_NAME ::=
17230 -- Value
17231 -- | Reference
17232
17233 when Pragma_Import_Procedure => Import_Procedure : declare
17234 Args : Args_List (1 .. 4);
17235 Names : constant Name_List (1 .. 4) := (
17236 Name_Internal,
17237 Name_External,
17238 Name_Parameter_Types,
17239 Name_Mechanism);
17240
17241 Internal : Node_Id renames Args (1);
17242 External : Node_Id renames Args (2);
17243 Parameter_Types : Node_Id renames Args (3);
17244 Mechanism : Node_Id renames Args (4);
17245
17246 begin
17247 GNAT_Pragma;
17248 Gather_Associations (Names, Args);
17249 Process_Extended_Import_Export_Subprogram_Pragma (
17250 Arg_Internal => Internal,
17251 Arg_External => External,
17252 Arg_Parameter_Types => Parameter_Types,
17253 Arg_Mechanism => Mechanism);
17254 end Import_Procedure;
17255
17256 -----------------------------
17257 -- Import_Valued_Procedure --
17258 -----------------------------
17259
17260 -- pragma Import_Valued_Procedure (
17261 -- [Internal =>] LOCAL_NAME
17262 -- [, [External =>] EXTERNAL_SYMBOL]
17263 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17264 -- [, [Mechanism =>] MECHANISM]);
17265
17266 -- EXTERNAL_SYMBOL ::=
17267 -- IDENTIFIER
17268 -- | static_string_EXPRESSION
17269
17270 -- PARAMETER_TYPES ::=
17271 -- null
17272 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17273
17274 -- TYPE_DESIGNATOR ::=
17275 -- subtype_NAME
17276 -- | subtype_Name ' Access
17277
17278 -- MECHANISM ::=
17279 -- MECHANISM_NAME
17280 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17281
17282 -- MECHANISM_ASSOCIATION ::=
17283 -- [formal_parameter_NAME =>] MECHANISM_NAME
17284
17285 -- MECHANISM_NAME ::=
17286 -- Value
17287 -- | Reference
17288
17289 when Pragma_Import_Valued_Procedure =>
17290 Import_Valued_Procedure : declare
17291 Args : Args_List (1 .. 4);
17292 Names : constant Name_List (1 .. 4) := (
17293 Name_Internal,
17294 Name_External,
17295 Name_Parameter_Types,
17296 Name_Mechanism);
17297
17298 Internal : Node_Id renames Args (1);
17299 External : Node_Id renames Args (2);
17300 Parameter_Types : Node_Id renames Args (3);
17301 Mechanism : Node_Id renames Args (4);
17302
17303 begin
17304 GNAT_Pragma;
17305 Gather_Associations (Names, Args);
17306 Process_Extended_Import_Export_Subprogram_Pragma (
17307 Arg_Internal => Internal,
17308 Arg_External => External,
17309 Arg_Parameter_Types => Parameter_Types,
17310 Arg_Mechanism => Mechanism);
17311 end Import_Valued_Procedure;
17312
17313 -----------------
17314 -- Independent --
17315 -----------------
17316
17317 -- pragma Independent (LOCAL_NAME);
17318
17319 when Pragma_Independent =>
17320 Process_Atomic_Independent_Shared_Volatile;
17321
17322 ----------------------------
17323 -- Independent_Components --
17324 ----------------------------
17325
17326 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
17327
17328 when Pragma_Independent_Components => Independent_Components : declare
17329 C : Node_Id;
17330 D : Node_Id;
17331 E_Id : Node_Id;
17332 E : Entity_Id;
17333
17334 begin
17335 Check_Ada_83_Warning;
17336 Ada_2012_Pragma;
17337 Check_No_Identifiers;
17338 Check_Arg_Count (1);
17339 Check_Arg_Is_Local_Name (Arg1);
17340 E_Id := Get_Pragma_Arg (Arg1);
17341
17342 if Etype (E_Id) = Any_Type then
17343 return;
17344 end if;
17345
17346 E := Entity (E_Id);
17347
17348 -- A record type with a self-referential component of anonymous
17349 -- access type is given an incomplete view in order to handle the
17350 -- self reference:
17351 --
17352 -- type Rec is record
17353 -- Self : access Rec;
17354 -- end record;
17355 --
17356 -- becomes
17357 --
17358 -- type Rec;
17359 -- type Ptr is access Rec;
17360 -- type Rec is record
17361 -- Self : Ptr;
17362 -- end record;
17363 --
17364 -- Since the incomplete view is now the initial view of the type,
17365 -- the argument of the pragma will reference the incomplete view,
17366 -- but this view is illegal according to the semantics of the
17367 -- pragma.
17368 --
17369 -- Obtain the full view of an internally-generated incomplete type
17370 -- only. This way an attempt to associate the pragma with a source
17371 -- incomplete type is still caught.
17372
17373 if Ekind (E) = E_Incomplete_Type
17374 and then not Comes_From_Source (E)
17375 and then Present (Full_View (E))
17376 then
17377 E := Full_View (E);
17378 end if;
17379
17380 -- A pragma that applies to a Ghost entity becomes Ghost for the
17381 -- purposes of legality checks and removal of ignored Ghost code.
17382
17383 Mark_Ghost_Pragma (N, E);
17384
17385 -- Check duplicate before we chain ourselves
17386
17387 Check_Duplicate_Pragma (E);
17388
17389 -- Check appropriate entity
17390
17391 if Rep_Item_Too_Early (E, N)
17392 or else
17393 Rep_Item_Too_Late (E, N)
17394 then
17395 return;
17396 end if;
17397
17398 D := Declaration_Node (E);
17399
17400 -- The flag is set on the base type, or on the object
17401
17402 if Nkind (D) = N_Full_Type_Declaration
17403 and then (Is_Array_Type (E) or else Is_Record_Type (E))
17404 then
17405 Set_Has_Independent_Components (Base_Type (E));
17406 Record_Independence_Check (N, Base_Type (E));
17407
17408 -- For record type, set all components independent
17409
17410 if Is_Record_Type (E) then
17411 C := First_Component (E);
17412 while Present (C) loop
17413 Set_Is_Independent (C);
17414 Next_Component (C);
17415 end loop;
17416 end if;
17417
17418 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
17419 and then Nkind (D) = N_Object_Declaration
17420 and then Nkind (Object_Definition (D)) =
17421 N_Constrained_Array_Definition
17422 then
17423 Set_Has_Independent_Components (E);
17424 Record_Independence_Check (N, E);
17425
17426 else
17427 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
17428 end if;
17429 end Independent_Components;
17430
17431 -----------------------
17432 -- Initial_Condition --
17433 -----------------------
17434
17435 -- pragma Initial_Condition (boolean_EXPRESSION);
17436
17437 -- Characteristics:
17438
17439 -- * Analysis - The annotation undergoes initial checks to verify
17440 -- the legal placement and context. Secondary checks preanalyze the
17441 -- expression in:
17442
17443 -- Analyze_Initial_Condition_In_Decl_Part
17444
17445 -- * Expansion - The annotation is expanded during the expansion of
17446 -- the package body whose declaration is subject to the annotation
17447 -- as done in:
17448
17449 -- Expand_Pragma_Initial_Condition
17450
17451 -- * Template - The annotation utilizes the generic template of the
17452 -- related package declaration.
17453
17454 -- * Globals - Capture of global references must occur after full
17455 -- analysis.
17456
17457 -- * Instance - The annotation is instantiated automatically when
17458 -- the related generic package is instantiated.
17459
17460 when Pragma_Initial_Condition => Initial_Condition : declare
17461 Pack_Decl : Node_Id;
17462 Pack_Id : Entity_Id;
17463
17464 begin
17465 GNAT_Pragma;
17466 Check_No_Identifiers;
17467 Check_Arg_Count (1);
17468
17469 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
17470
17471 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
17472 N_Package_Declaration)
17473 then
17474 Pragma_Misplaced;
17475 return;
17476 end if;
17477
17478 Pack_Id := Defining_Entity (Pack_Decl);
17479
17480 -- A pragma that applies to a Ghost entity becomes Ghost for the
17481 -- purposes of legality checks and removal of ignored Ghost code.
17482
17483 Mark_Ghost_Pragma (N, Pack_Id);
17484
17485 -- Chain the pragma on the contract for further processing by
17486 -- Analyze_Initial_Condition_In_Decl_Part.
17487
17488 Add_Contract_Item (N, Pack_Id);
17489
17490 -- The legality checks of pragmas Abstract_State, Initializes, and
17491 -- Initial_Condition are affected by the SPARK mode in effect. In
17492 -- addition, these three pragmas are subject to an inherent order:
17493
17494 -- 1) Abstract_State
17495 -- 2) Initializes
17496 -- 3) Initial_Condition
17497
17498 -- Analyze all these pragmas in the order outlined above
17499
17500 Analyze_If_Present (Pragma_SPARK_Mode);
17501 Analyze_If_Present (Pragma_Abstract_State);
17502 Analyze_If_Present (Pragma_Initializes);
17503 end Initial_Condition;
17504
17505 ------------------------
17506 -- Initialize_Scalars --
17507 ------------------------
17508
17509 -- pragma Initialize_Scalars
17510 -- [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ];
17511
17512 -- TYPE_VALUE_PAIR ::=
17513 -- SCALAR_TYPE => static_EXPRESSION
17514
17515 -- SCALAR_TYPE :=
17516 -- Short_Float
17517 -- | Float
17518 -- | Long_Float
17519 -- | Long_Long_Flat
17520 -- | Signed_8
17521 -- | Signed_16
17522 -- | Signed_32
17523 -- | Signed_64
17524 -- | Unsigned_8
17525 -- | Unsigned_16
17526 -- | Unsigned_32
17527 -- | Unsigned_64
17528
17529 when Pragma_Initialize_Scalars => Do_Initialize_Scalars : declare
17530 Seen : array (Scalar_Id) of Node_Id := (others => Empty);
17531 -- This collection holds the individual pairs which specify the
17532 -- invalid values of their respective scalar types.
17533
17534 procedure Analyze_Float_Value
17535 (Scal_Typ : Float_Scalar_Id;
17536 Val_Expr : Node_Id);
17537 -- Analyze a type value pair associated with float type Scal_Typ
17538 -- and expression Val_Expr.
17539
17540 procedure Analyze_Integer_Value
17541 (Scal_Typ : Integer_Scalar_Id;
17542 Val_Expr : Node_Id);
17543 -- Analyze a type value pair associated with integer type Scal_Typ
17544 -- and expression Val_Expr.
17545
17546 procedure Analyze_Type_Value_Pair (Pair : Node_Id);
17547 -- Analyze type value pair Pair
17548
17549 -------------------------
17550 -- Analyze_Float_Value --
17551 -------------------------
17552
17553 procedure Analyze_Float_Value
17554 (Scal_Typ : Float_Scalar_Id;
17555 Val_Expr : Node_Id)
17556 is
17557 begin
17558 Analyze_And_Resolve (Val_Expr, Any_Real);
17559
17560 if Is_OK_Static_Expression (Val_Expr) then
17561 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value_R (Val_Expr));
17562
17563 else
17564 Error_Msg_Name_1 := Scal_Typ;
17565 Error_Msg_N ("value for type % must be static", Val_Expr);
17566 end if;
17567 end Analyze_Float_Value;
17568
17569 ---------------------------
17570 -- Analyze_Integer_Value --
17571 ---------------------------
17572
17573 procedure Analyze_Integer_Value
17574 (Scal_Typ : Integer_Scalar_Id;
17575 Val_Expr : Node_Id)
17576 is
17577 begin
17578 Analyze_And_Resolve (Val_Expr, Any_Integer);
17579
17580 if Is_OK_Static_Expression (Val_Expr) then
17581 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value (Val_Expr));
17582
17583 else
17584 Error_Msg_Name_1 := Scal_Typ;
17585 Error_Msg_N ("value for type % must be static", Val_Expr);
17586 end if;
17587 end Analyze_Integer_Value;
17588
17589 -----------------------------
17590 -- Analyze_Type_Value_Pair --
17591 -----------------------------
17592
17593 procedure Analyze_Type_Value_Pair (Pair : Node_Id) is
17594 Scal_Typ : constant Name_Id := Chars (Pair);
17595 Val_Expr : constant Node_Id := Expression (Pair);
17596 Prev_Pair : Node_Id;
17597
17598 begin
17599 if Scal_Typ in Scalar_Id then
17600 Prev_Pair := Seen (Scal_Typ);
17601
17602 -- Prevent multiple attempts to set a value for a scalar
17603 -- type.
17604
17605 if Present (Prev_Pair) then
17606 Error_Msg_Name_1 := Scal_Typ;
17607 Error_Msg_N
17608 ("cannot specify multiple invalid values for type %",
17609 Pair);
17610
17611 Error_Msg_Sloc := Sloc (Prev_Pair);
17612 Error_Msg_N ("previous value set #", Pair);
17613
17614 -- Ignore the effects of the pair, but do not halt the
17615 -- analysis of the pragma altogether.
17616
17617 return;
17618
17619 -- Otherwise capture the first pair for this scalar type
17620
17621 else
17622 Seen (Scal_Typ) := Pair;
17623 end if;
17624
17625 if Scal_Typ in Float_Scalar_Id then
17626 Analyze_Float_Value (Scal_Typ, Val_Expr);
17627
17628 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
17629 Analyze_Integer_Value (Scal_Typ, Val_Expr);
17630 end if;
17631
17632 -- Otherwise the scalar family is illegal
17633
17634 else
17635 Error_Msg_Name_1 := Pname;
17636 Error_Msg_N
17637 ("argument of pragma % must denote valid scalar family",
17638 Pair);
17639 end if;
17640 end Analyze_Type_Value_Pair;
17641
17642 -- Local variables
17643
17644 Pairs : constant List_Id := Pragma_Argument_Associations (N);
17645 Pair : Node_Id;
17646
17647 -- Start of processing for Do_Initialize_Scalars
17648
17649 begin
17650 GNAT_Pragma;
17651 Check_Valid_Configuration_Pragma;
17652 Check_Restriction (No_Initialize_Scalars, N);
17653
17654 -- Ignore the effects of the pragma when No_Initialize_Scalars is
17655 -- in effect.
17656
17657 if Restriction_Active (No_Initialize_Scalars) then
17658 null;
17659
17660 -- Initialize_Scalars creates false positives in CodePeer, and
17661 -- incorrect negative results in GNATprove mode, so ignore this
17662 -- pragma in these modes.
17663
17664 elsif CodePeer_Mode or GNATprove_Mode then
17665 null;
17666
17667 -- Otherwise analyze the pragma
17668
17669 else
17670 if Present (Pairs) then
17671
17672 -- Install Standard in order to provide access to primitive
17673 -- types in case the expressions contain attributes such as
17674 -- Integer'Last.
17675
17676 Push_Scope (Standard_Standard);
17677
17678 Pair := First (Pairs);
17679 while Present (Pair) loop
17680 Analyze_Type_Value_Pair (Pair);
17681 Next (Pair);
17682 end loop;
17683
17684 -- Remove Standard
17685
17686 Pop_Scope;
17687 end if;
17688
17689 Init_Or_Norm_Scalars := True;
17690 Initialize_Scalars := True;
17691 end if;
17692 end Do_Initialize_Scalars;
17693
17694 -----------------
17695 -- Initializes --
17696 -----------------
17697
17698 -- pragma Initializes (INITIALIZATION_LIST);
17699
17700 -- INITIALIZATION_LIST ::=
17701 -- null
17702 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
17703
17704 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
17705
17706 -- INPUT_LIST ::=
17707 -- null
17708 -- | INPUT
17709 -- | (INPUT {, INPUT})
17710
17711 -- INPUT ::= name
17712
17713 -- Characteristics:
17714
17715 -- * Analysis - The annotation undergoes initial checks to verify
17716 -- the legal placement and context. Secondary checks preanalyze the
17717 -- expression in:
17718
17719 -- Analyze_Initializes_In_Decl_Part
17720
17721 -- * Expansion - None.
17722
17723 -- * Template - The annotation utilizes the generic template of the
17724 -- related package declaration.
17725
17726 -- * Globals - Capture of global references must occur after full
17727 -- analysis.
17728
17729 -- * Instance - The annotation is instantiated automatically when
17730 -- the related generic package is instantiated.
17731
17732 when Pragma_Initializes => Initializes : declare
17733 Pack_Decl : Node_Id;
17734 Pack_Id : Entity_Id;
17735
17736 begin
17737 GNAT_Pragma;
17738 Check_No_Identifiers;
17739 Check_Arg_Count (1);
17740
17741 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
17742
17743 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
17744 N_Package_Declaration)
17745 then
17746 Pragma_Misplaced;
17747 return;
17748 end if;
17749
17750 Pack_Id := Defining_Entity (Pack_Decl);
17751
17752 -- A pragma that applies to a Ghost entity becomes Ghost for the
17753 -- purposes of legality checks and removal of ignored Ghost code.
17754
17755 Mark_Ghost_Pragma (N, Pack_Id);
17756 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
17757
17758 -- Chain the pragma on the contract for further processing by
17759 -- Analyze_Initializes_In_Decl_Part.
17760
17761 Add_Contract_Item (N, Pack_Id);
17762
17763 -- The legality checks of pragmas Abstract_State, Initializes, and
17764 -- Initial_Condition are affected by the SPARK mode in effect. In
17765 -- addition, these three pragmas are subject to an inherent order:
17766
17767 -- 1) Abstract_State
17768 -- 2) Initializes
17769 -- 3) Initial_Condition
17770
17771 -- Analyze all these pragmas in the order outlined above
17772
17773 Analyze_If_Present (Pragma_SPARK_Mode);
17774 Analyze_If_Present (Pragma_Abstract_State);
17775 Analyze_If_Present (Pragma_Initial_Condition);
17776 end Initializes;
17777
17778 ------------
17779 -- Inline --
17780 ------------
17781
17782 -- pragma Inline ( NAME {, NAME} );
17783
17784 when Pragma_Inline =>
17785
17786 -- Pragma always active unless in GNATprove mode. It is disabled
17787 -- in GNATprove mode because frontend inlining is applied
17788 -- independently of pragmas Inline and Inline_Always for
17789 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
17790 -- in inline.ads.
17791
17792 if not GNATprove_Mode then
17793
17794 -- Inline status is Enabled if option -gnatn is specified.
17795 -- However this status determines only the value of the
17796 -- Is_Inlined flag on the subprogram and does not prevent
17797 -- the pragma itself from being recorded for later use,
17798 -- in particular for a later modification of Is_Inlined
17799 -- independently of the -gnatn option.
17800
17801 -- In other words, if -gnatn is specified for a unit, then
17802 -- all Inline pragmas processed for the compilation of this
17803 -- unit, including those in the spec of other units, are
17804 -- activated, so subprograms will be inlined across units.
17805
17806 -- If -gnatn is not specified, no Inline pragma is activated
17807 -- here, which means that subprograms will not be inlined
17808 -- across units. The Is_Inlined flag will nevertheless be
17809 -- set later when bodies are analyzed, so subprograms will
17810 -- be inlined within the unit.
17811
17812 if Inline_Active then
17813 Process_Inline (Enabled);
17814 else
17815 Process_Inline (Disabled);
17816 end if;
17817 end if;
17818
17819 -------------------
17820 -- Inline_Always --
17821 -------------------
17822
17823 -- pragma Inline_Always ( NAME {, NAME} );
17824
17825 when Pragma_Inline_Always =>
17826 GNAT_Pragma;
17827
17828 -- Pragma always active unless in CodePeer mode or GNATprove
17829 -- mode. It is disabled in CodePeer mode because inlining is
17830 -- not helpful, and enabling it caused walk order issues. It
17831 -- is disabled in GNATprove mode because frontend inlining is
17832 -- applied independently of pragmas Inline and Inline_Always for
17833 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
17834 -- inline.ads.
17835
17836 if not CodePeer_Mode and not GNATprove_Mode then
17837 Process_Inline (Enabled);
17838 end if;
17839
17840 --------------------
17841 -- Inline_Generic --
17842 --------------------
17843
17844 -- pragma Inline_Generic (NAME {, NAME});
17845
17846 when Pragma_Inline_Generic =>
17847 GNAT_Pragma;
17848 Process_Generic_List;
17849
17850 ----------------------
17851 -- Inspection_Point --
17852 ----------------------
17853
17854 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
17855
17856 when Pragma_Inspection_Point => Inspection_Point : declare
17857 Arg : Node_Id;
17858 Exp : Node_Id;
17859
17860 begin
17861 ip;
17862
17863 if Arg_Count > 0 then
17864 Arg := Arg1;
17865 loop
17866 Exp := Get_Pragma_Arg (Arg);
17867 Analyze (Exp);
17868
17869 if not Is_Entity_Name (Exp)
17870 or else not Is_Object (Entity (Exp))
17871 then
17872 Error_Pragma_Arg ("object name required", Arg);
17873 end if;
17874
17875 Next (Arg);
17876 exit when No (Arg);
17877 end loop;
17878 end if;
17879 end Inspection_Point;
17880
17881 ---------------
17882 -- Interface --
17883 ---------------
17884
17885 -- pragma Interface (
17886 -- [ Convention =>] convention_IDENTIFIER,
17887 -- [ Entity =>] LOCAL_NAME
17888 -- [, [External_Name =>] static_string_EXPRESSION ]
17889 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17890
17891 when Pragma_Interface =>
17892 GNAT_Pragma;
17893 Check_Arg_Order
17894 ((Name_Convention,
17895 Name_Entity,
17896 Name_External_Name,
17897 Name_Link_Name));
17898 Check_At_Least_N_Arguments (2);
17899 Check_At_Most_N_Arguments (4);
17900 Process_Import_Or_Interface;
17901
17902 -- In Ada 2005, the permission to use Interface (a reserved word)
17903 -- as a pragma name is considered an obsolescent feature, and this
17904 -- pragma was already obsolescent in Ada 95.
17905
17906 if Ada_Version >= Ada_95 then
17907 Check_Restriction
17908 (No_Obsolescent_Features, Pragma_Identifier (N));
17909
17910 if Warn_On_Obsolescent_Feature then
17911 Error_Msg_N
17912 ("pragma Interface is an obsolescent feature?j?", N);
17913 Error_Msg_N
17914 ("|use pragma Import instead?j?", N);
17915 end if;
17916 end if;
17917
17918 --------------------
17919 -- Interface_Name --
17920 --------------------
17921
17922 -- pragma Interface_Name (
17923 -- [ Entity =>] LOCAL_NAME
17924 -- [,[External_Name =>] static_string_EXPRESSION ]
17925 -- [,[Link_Name =>] static_string_EXPRESSION ]);
17926
17927 when Pragma_Interface_Name => Interface_Name : declare
17928 Id : Node_Id;
17929 Def_Id : Entity_Id;
17930 Hom_Id : Entity_Id;
17931 Found : Boolean;
17932
17933 begin
17934 GNAT_Pragma;
17935 Check_Arg_Order
17936 ((Name_Entity, Name_External_Name, Name_Link_Name));
17937 Check_At_Least_N_Arguments (2);
17938 Check_At_Most_N_Arguments (3);
17939 Id := Get_Pragma_Arg (Arg1);
17940 Analyze (Id);
17941
17942 -- This is obsolete from Ada 95 on, but it is an implementation
17943 -- defined pragma, so we do not consider that it violates the
17944 -- restriction (No_Obsolescent_Features).
17945
17946 if Ada_Version >= Ada_95 then
17947 if Warn_On_Obsolescent_Feature then
17948 Error_Msg_N
17949 ("pragma Interface_Name is an obsolescent feature?j?", N);
17950 Error_Msg_N
17951 ("|use pragma Import instead?j?", N);
17952 end if;
17953 end if;
17954
17955 if not Is_Entity_Name (Id) then
17956 Error_Pragma_Arg
17957 ("first argument for pragma% must be entity name", Arg1);
17958 elsif Etype (Id) = Any_Type then
17959 return;
17960 else
17961 Def_Id := Entity (Id);
17962 end if;
17963
17964 -- Special DEC-compatible processing for the object case, forces
17965 -- object to be imported.
17966
17967 if Ekind (Def_Id) = E_Variable then
17968 Kill_Size_Check_Code (Def_Id);
17969 Note_Possible_Modification (Id, Sure => False);
17970
17971 -- Initialization is not allowed for imported variable
17972
17973 if Present (Expression (Parent (Def_Id)))
17974 and then Comes_From_Source (Expression (Parent (Def_Id)))
17975 then
17976 Error_Msg_Sloc := Sloc (Def_Id);
17977 Error_Pragma_Arg
17978 ("no initialization allowed for declaration of& #",
17979 Arg2);
17980
17981 else
17982 -- For compatibility, support VADS usage of providing both
17983 -- pragmas Interface and Interface_Name to obtain the effect
17984 -- of a single Import pragma.
17985
17986 if Is_Imported (Def_Id)
17987 and then Present (First_Rep_Item (Def_Id))
17988 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
17989 and then Pragma_Name (First_Rep_Item (Def_Id)) =
17990 Name_Interface
17991 then
17992 null;
17993 else
17994 Set_Imported (Def_Id);
17995 end if;
17996
17997 Set_Is_Public (Def_Id);
17998 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
17999 end if;
18000
18001 -- Otherwise must be subprogram
18002
18003 elsif not Is_Subprogram (Def_Id) then
18004 Error_Pragma_Arg
18005 ("argument of pragma% is not subprogram", Arg1);
18006
18007 else
18008 Check_At_Most_N_Arguments (3);
18009 Hom_Id := Def_Id;
18010 Found := False;
18011
18012 -- Loop through homonyms
18013
18014 loop
18015 Def_Id := Get_Base_Subprogram (Hom_Id);
18016
18017 if Is_Imported (Def_Id) then
18018 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
18019 Found := True;
18020 end if;
18021
18022 exit when From_Aspect_Specification (N);
18023 Hom_Id := Homonym (Hom_Id);
18024
18025 exit when No (Hom_Id)
18026 or else Scope (Hom_Id) /= Current_Scope;
18027 end loop;
18028
18029 if not Found then
18030 Error_Pragma_Arg
18031 ("argument of pragma% is not imported subprogram",
18032 Arg1);
18033 end if;
18034 end if;
18035 end Interface_Name;
18036
18037 -----------------------
18038 -- Interrupt_Handler --
18039 -----------------------
18040
18041 -- pragma Interrupt_Handler (handler_NAME);
18042
18043 when Pragma_Interrupt_Handler =>
18044 Check_Ada_83_Warning;
18045 Check_Arg_Count (1);
18046 Check_No_Identifiers;
18047
18048 if No_Run_Time_Mode then
18049 Error_Msg_CRT ("Interrupt_Handler pragma", N);
18050 else
18051 Check_Interrupt_Or_Attach_Handler;
18052 Process_Interrupt_Or_Attach_Handler;
18053 end if;
18054
18055 ------------------------
18056 -- Interrupt_Priority --
18057 ------------------------
18058
18059 -- pragma Interrupt_Priority [(EXPRESSION)];
18060
18061 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
18062 P : constant Node_Id := Parent (N);
18063 Arg : Node_Id;
18064 Ent : Entity_Id;
18065
18066 begin
18067 Check_Ada_83_Warning;
18068
18069 if Arg_Count /= 0 then
18070 Arg := Get_Pragma_Arg (Arg1);
18071 Check_Arg_Count (1);
18072 Check_No_Identifiers;
18073
18074 -- The expression must be analyzed in the special manner
18075 -- described in "Handling of Default and Per-Object
18076 -- Expressions" in sem.ads.
18077
18078 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
18079 end if;
18080
18081 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
18082 Pragma_Misplaced;
18083 return;
18084
18085 else
18086 Ent := Defining_Identifier (Parent (P));
18087
18088 -- Check duplicate pragma before we chain the pragma in the Rep
18089 -- Item chain of Ent.
18090
18091 Check_Duplicate_Pragma (Ent);
18092 Record_Rep_Item (Ent, N);
18093
18094 -- Check the No_Task_At_Interrupt_Priority restriction
18095
18096 if Nkind (P) = N_Task_Definition then
18097 Check_Restriction (No_Task_At_Interrupt_Priority, N);
18098 end if;
18099 end if;
18100 end Interrupt_Priority;
18101
18102 ---------------------
18103 -- Interrupt_State --
18104 ---------------------
18105
18106 -- pragma Interrupt_State (
18107 -- [Name =>] INTERRUPT_ID,
18108 -- [State =>] INTERRUPT_STATE);
18109
18110 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
18111 -- INTERRUPT_STATE => System | Runtime | User
18112
18113 -- Note: if the interrupt id is given as an identifier, then it must
18114 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
18115 -- given as a static integer expression which must be in the range of
18116 -- Ada.Interrupts.Interrupt_ID.
18117
18118 when Pragma_Interrupt_State => Interrupt_State : declare
18119 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
18120 -- This is the entity Ada.Interrupts.Interrupt_ID;
18121
18122 State_Type : Character;
18123 -- Set to 's'/'r'/'u' for System/Runtime/User
18124
18125 IST_Num : Pos;
18126 -- Index to entry in Interrupt_States table
18127
18128 Int_Val : Uint;
18129 -- Value of interrupt
18130
18131 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
18132 -- The first argument to the pragma
18133
18134 Int_Ent : Entity_Id;
18135 -- Interrupt entity in Ada.Interrupts.Names
18136
18137 begin
18138 GNAT_Pragma;
18139 Check_Arg_Order ((Name_Name, Name_State));
18140 Check_Arg_Count (2);
18141
18142 Check_Optional_Identifier (Arg1, Name_Name);
18143 Check_Optional_Identifier (Arg2, Name_State);
18144 Check_Arg_Is_Identifier (Arg2);
18145
18146 -- First argument is identifier
18147
18148 if Nkind (Arg1X) = N_Identifier then
18149
18150 -- Search list of names in Ada.Interrupts.Names
18151
18152 Int_Ent := First_Entity (RTE (RE_Names));
18153 loop
18154 if No (Int_Ent) then
18155 Error_Pragma_Arg ("invalid interrupt name", Arg1);
18156
18157 elsif Chars (Int_Ent) = Chars (Arg1X) then
18158 Int_Val := Expr_Value (Constant_Value (Int_Ent));
18159 exit;
18160 end if;
18161
18162 Next_Entity (Int_Ent);
18163 end loop;
18164
18165 -- First argument is not an identifier, so it must be a static
18166 -- expression of type Ada.Interrupts.Interrupt_ID.
18167
18168 else
18169 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
18170 Int_Val := Expr_Value (Arg1X);
18171
18172 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
18173 or else
18174 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
18175 then
18176 Error_Pragma_Arg
18177 ("value not in range of type "
18178 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
18179 end if;
18180 end if;
18181
18182 -- Check OK state
18183
18184 case Chars (Get_Pragma_Arg (Arg2)) is
18185 when Name_Runtime => State_Type := 'r';
18186 when Name_System => State_Type := 's';
18187 when Name_User => State_Type := 'u';
18188
18189 when others =>
18190 Error_Pragma_Arg ("invalid interrupt state", Arg2);
18191 end case;
18192
18193 -- Check if entry is already stored
18194
18195 IST_Num := Interrupt_States.First;
18196 loop
18197 -- If entry not found, add it
18198
18199 if IST_Num > Interrupt_States.Last then
18200 Interrupt_States.Append
18201 ((Interrupt_Number => UI_To_Int (Int_Val),
18202 Interrupt_State => State_Type,
18203 Pragma_Loc => Loc));
18204 exit;
18205
18206 -- Case of entry for the same entry
18207
18208 elsif Int_Val = Interrupt_States.Table (IST_Num).
18209 Interrupt_Number
18210 then
18211 -- If state matches, done, no need to make redundant entry
18212
18213 exit when
18214 State_Type = Interrupt_States.Table (IST_Num).
18215 Interrupt_State;
18216
18217 -- Otherwise if state does not match, error
18218
18219 Error_Msg_Sloc :=
18220 Interrupt_States.Table (IST_Num).Pragma_Loc;
18221 Error_Pragma_Arg
18222 ("state conflicts with that given #", Arg2);
18223 exit;
18224 end if;
18225
18226 IST_Num := IST_Num + 1;
18227 end loop;
18228 end Interrupt_State;
18229
18230 ---------------
18231 -- Invariant --
18232 ---------------
18233
18234 -- pragma Invariant
18235 -- ([Entity =>] type_LOCAL_NAME,
18236 -- [Check =>] EXPRESSION
18237 -- [,[Message =>] String_Expression]);
18238
18239 when Pragma_Invariant => Invariant : declare
18240 Discard : Boolean;
18241 Typ : Entity_Id;
18242 Typ_Arg : Node_Id;
18243
18244 begin
18245 GNAT_Pragma;
18246 Check_At_Least_N_Arguments (2);
18247 Check_At_Most_N_Arguments (3);
18248 Check_Optional_Identifier (Arg1, Name_Entity);
18249 Check_Optional_Identifier (Arg2, Name_Check);
18250
18251 if Arg_Count = 3 then
18252 Check_Optional_Identifier (Arg3, Name_Message);
18253 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
18254 end if;
18255
18256 Check_Arg_Is_Local_Name (Arg1);
18257
18258 Typ_Arg := Get_Pragma_Arg (Arg1);
18259 Find_Type (Typ_Arg);
18260 Typ := Entity (Typ_Arg);
18261
18262 -- Nothing to do of the related type is erroneous in some way
18263
18264 if Typ = Any_Type then
18265 return;
18266
18267 -- AI12-0041: Invariants are allowed in interface types
18268
18269 elsif Is_Interface (Typ) then
18270 null;
18271
18272 -- An invariant must apply to a private type, or appear in the
18273 -- private part of a package spec and apply to a completion.
18274 -- a class-wide invariant can only appear on a private declaration
18275 -- or private extension, not a completion.
18276
18277 -- A [class-wide] invariant may be associated a [limited] private
18278 -- type or a private extension.
18279
18280 elsif Ekind_In (Typ, E_Limited_Private_Type,
18281 E_Private_Type,
18282 E_Record_Type_With_Private)
18283 then
18284 null;
18285
18286 -- A non-class-wide invariant may be associated with the full view
18287 -- of a [limited] private type or a private extension.
18288
18289 elsif Has_Private_Declaration (Typ)
18290 and then not Class_Present (N)
18291 then
18292 null;
18293
18294 -- A class-wide invariant may appear on the partial view only
18295
18296 elsif Class_Present (N) then
18297 Error_Pragma_Arg
18298 ("pragma % only allowed for private type", Arg1);
18299 return;
18300
18301 -- A regular invariant may appear on both views
18302
18303 else
18304 Error_Pragma_Arg
18305 ("pragma % only allowed for private type or corresponding "
18306 & "full view", Arg1);
18307 return;
18308 end if;
18309
18310 -- An invariant associated with an abstract type (this includes
18311 -- interfaces) must be class-wide.
18312
18313 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
18314 Error_Pragma_Arg
18315 ("pragma % not allowed for abstract type", Arg1);
18316 return;
18317 end if;
18318
18319 -- A pragma that applies to a Ghost entity becomes Ghost for the
18320 -- purposes of legality checks and removal of ignored Ghost code.
18321
18322 Mark_Ghost_Pragma (N, Typ);
18323
18324 -- The pragma defines a type-specific invariant, the type is said
18325 -- to have invariants of its "own".
18326
18327 Set_Has_Own_Invariants (Typ);
18328
18329 -- Set the Invariants_Ignored flag if that policy is in effect
18330
18331 Set_Invariants_Ignored (Typ,
18332 Present (Check_Policy_List)
18333 and then
18334 (Policy_In_Effect (Name_Invariant) = Name_Ignore
18335 and then
18336 Policy_In_Effect (Name_Type_Invariant) = Name_Ignore));
18337
18338 -- If the invariant is class-wide, then it can be inherited by
18339 -- derived or interface implementing types. The type is said to
18340 -- have "inheritable" invariants.
18341
18342 if Class_Present (N) then
18343 Set_Has_Inheritable_Invariants (Typ);
18344 end if;
18345
18346 -- Chain the pragma on to the rep item chain, for processing when
18347 -- the type is frozen.
18348
18349 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18350
18351 -- Create the declaration of the invariant procedure that will
18352 -- verify the invariant at run time. Interfaces are treated as the
18353 -- partial view of a private type in order to achieve uniformity
18354 -- with the general case. As a result, an interface receives only
18355 -- a "partial" invariant procedure, which is never called.
18356
18357 Build_Invariant_Procedure_Declaration
18358 (Typ => Typ,
18359 Partial_Invariant => Is_Interface (Typ));
18360 end Invariant;
18361
18362 ----------------
18363 -- Keep_Names --
18364 ----------------
18365
18366 -- pragma Keep_Names ([On => ] LOCAL_NAME);
18367
18368 when Pragma_Keep_Names => Keep_Names : declare
18369 Arg : Node_Id;
18370
18371 begin
18372 GNAT_Pragma;
18373 Check_Arg_Count (1);
18374 Check_Optional_Identifier (Arg1, Name_On);
18375 Check_Arg_Is_Local_Name (Arg1);
18376
18377 Arg := Get_Pragma_Arg (Arg1);
18378 Analyze (Arg);
18379
18380 if Etype (Arg) = Any_Type then
18381 return;
18382 end if;
18383
18384 if not Is_Entity_Name (Arg)
18385 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
18386 then
18387 Error_Pragma_Arg
18388 ("pragma% requires a local enumeration type", Arg1);
18389 end if;
18390
18391 Set_Discard_Names (Entity (Arg), False);
18392 end Keep_Names;
18393
18394 -------------
18395 -- License --
18396 -------------
18397
18398 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
18399
18400 when Pragma_License =>
18401 GNAT_Pragma;
18402
18403 -- Do not analyze pragma any further in CodePeer mode, to avoid
18404 -- extraneous errors in this implementation-dependent pragma,
18405 -- which has a different profile on other compilers.
18406
18407 if CodePeer_Mode then
18408 return;
18409 end if;
18410
18411 Check_Arg_Count (1);
18412 Check_No_Identifiers;
18413 Check_Valid_Configuration_Pragma;
18414 Check_Arg_Is_Identifier (Arg1);
18415
18416 declare
18417 Sind : constant Source_File_Index :=
18418 Source_Index (Current_Sem_Unit);
18419
18420 begin
18421 case Chars (Get_Pragma_Arg (Arg1)) is
18422 when Name_GPL =>
18423 Set_License (Sind, GPL);
18424
18425 when Name_Modified_GPL =>
18426 Set_License (Sind, Modified_GPL);
18427
18428 when Name_Restricted =>
18429 Set_License (Sind, Restricted);
18430
18431 when Name_Unrestricted =>
18432 Set_License (Sind, Unrestricted);
18433
18434 when others =>
18435 Error_Pragma_Arg ("invalid license name", Arg1);
18436 end case;
18437 end;
18438
18439 ---------------
18440 -- Link_With --
18441 ---------------
18442
18443 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
18444
18445 when Pragma_Link_With => Link_With : declare
18446 Arg : Node_Id;
18447
18448 begin
18449 GNAT_Pragma;
18450
18451 if Operating_Mode = Generate_Code
18452 and then In_Extended_Main_Source_Unit (N)
18453 then
18454 Check_At_Least_N_Arguments (1);
18455 Check_No_Identifiers;
18456 Check_Is_In_Decl_Part_Or_Package_Spec;
18457 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18458 Start_String;
18459
18460 Arg := Arg1;
18461 while Present (Arg) loop
18462 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
18463
18464 -- Store argument, converting sequences of spaces to a
18465 -- single null character (this is one of the differences
18466 -- in processing between Link_With and Linker_Options).
18467
18468 Arg_Store : declare
18469 C : constant Char_Code := Get_Char_Code (' ');
18470 S : constant String_Id :=
18471 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
18472 L : constant Nat := String_Length (S);
18473 F : Nat := 1;
18474
18475 procedure Skip_Spaces;
18476 -- Advance F past any spaces
18477
18478 -----------------
18479 -- Skip_Spaces --
18480 -----------------
18481
18482 procedure Skip_Spaces is
18483 begin
18484 while F <= L and then Get_String_Char (S, F) = C loop
18485 F := F + 1;
18486 end loop;
18487 end Skip_Spaces;
18488
18489 -- Start of processing for Arg_Store
18490
18491 begin
18492 Skip_Spaces; -- skip leading spaces
18493
18494 -- Loop through characters, changing any embedded
18495 -- sequence of spaces to a single null character (this
18496 -- is how Link_With/Linker_Options differ)
18497
18498 while F <= L loop
18499 if Get_String_Char (S, F) = C then
18500 Skip_Spaces;
18501 exit when F > L;
18502 Store_String_Char (ASCII.NUL);
18503
18504 else
18505 Store_String_Char (Get_String_Char (S, F));
18506 F := F + 1;
18507 end if;
18508 end loop;
18509 end Arg_Store;
18510
18511 Arg := Next (Arg);
18512
18513 if Present (Arg) then
18514 Store_String_Char (ASCII.NUL);
18515 end if;
18516 end loop;
18517
18518 Store_Linker_Option_String (End_String);
18519 end if;
18520 end Link_With;
18521
18522 ------------------
18523 -- Linker_Alias --
18524 ------------------
18525
18526 -- pragma Linker_Alias (
18527 -- [Entity =>] LOCAL_NAME
18528 -- [Target =>] static_string_EXPRESSION);
18529
18530 when Pragma_Linker_Alias =>
18531 GNAT_Pragma;
18532 Check_Arg_Order ((Name_Entity, Name_Target));
18533 Check_Arg_Count (2);
18534 Check_Optional_Identifier (Arg1, Name_Entity);
18535 Check_Optional_Identifier (Arg2, Name_Target);
18536 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18537 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
18538
18539 -- The only processing required is to link this item on to the
18540 -- list of rep items for the given entity. This is accomplished
18541 -- by the call to Rep_Item_Too_Late (when no error is detected
18542 -- and False is returned).
18543
18544 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
18545 return;
18546 else
18547 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
18548 end if;
18549
18550 ------------------------
18551 -- Linker_Constructor --
18552 ------------------------
18553
18554 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
18555
18556 -- Code is shared with Linker_Destructor
18557
18558 -----------------------
18559 -- Linker_Destructor --
18560 -----------------------
18561
18562 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
18563
18564 when Pragma_Linker_Constructor
18565 | Pragma_Linker_Destructor
18566 =>
18567 Linker_Constructor : declare
18568 Arg1_X : Node_Id;
18569 Proc : Entity_Id;
18570
18571 begin
18572 GNAT_Pragma;
18573 Check_Arg_Count (1);
18574 Check_No_Identifiers;
18575 Check_Arg_Is_Local_Name (Arg1);
18576 Arg1_X := Get_Pragma_Arg (Arg1);
18577 Analyze (Arg1_X);
18578 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
18579
18580 if not Is_Library_Level_Entity (Proc) then
18581 Error_Pragma_Arg
18582 ("argument for pragma% must be library level entity", Arg1);
18583 end if;
18584
18585 -- The only processing required is to link this item on to the
18586 -- list of rep items for the given entity. This is accomplished
18587 -- by the call to Rep_Item_Too_Late (when no error is detected
18588 -- and False is returned).
18589
18590 if Rep_Item_Too_Late (Proc, N) then
18591 return;
18592 else
18593 Set_Has_Gigi_Rep_Item (Proc);
18594 end if;
18595 end Linker_Constructor;
18596
18597 --------------------
18598 -- Linker_Options --
18599 --------------------
18600
18601 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
18602
18603 when Pragma_Linker_Options => Linker_Options : declare
18604 Arg : Node_Id;
18605
18606 begin
18607 Check_Ada_83_Warning;
18608 Check_No_Identifiers;
18609 Check_Arg_Count (1);
18610 Check_Is_In_Decl_Part_Or_Package_Spec;
18611 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18612 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
18613
18614 Arg := Arg2;
18615 while Present (Arg) loop
18616 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
18617 Store_String_Char (ASCII.NUL);
18618 Store_String_Chars
18619 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
18620 Arg := Next (Arg);
18621 end loop;
18622
18623 if Operating_Mode = Generate_Code
18624 and then In_Extended_Main_Source_Unit (N)
18625 then
18626 Store_Linker_Option_String (End_String);
18627 end if;
18628 end Linker_Options;
18629
18630 --------------------
18631 -- Linker_Section --
18632 --------------------
18633
18634 -- pragma Linker_Section (
18635 -- [Entity =>] LOCAL_NAME
18636 -- [Section =>] static_string_EXPRESSION);
18637
18638 when Pragma_Linker_Section => Linker_Section : declare
18639 Arg : Node_Id;
18640 Ent : Entity_Id;
18641 LPE : Node_Id;
18642
18643 Ghost_Error_Posted : Boolean := False;
18644 -- Flag set when an error concerning the illegal mix of Ghost and
18645 -- non-Ghost subprograms is emitted.
18646
18647 Ghost_Id : Entity_Id := Empty;
18648 -- The entity of the first Ghost subprogram encountered while
18649 -- processing the arguments of the pragma.
18650
18651 begin
18652 GNAT_Pragma;
18653 Check_Arg_Order ((Name_Entity, Name_Section));
18654 Check_Arg_Count (2);
18655 Check_Optional_Identifier (Arg1, Name_Entity);
18656 Check_Optional_Identifier (Arg2, Name_Section);
18657 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18658 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
18659
18660 -- Check kind of entity
18661
18662 Arg := Get_Pragma_Arg (Arg1);
18663 Ent := Entity (Arg);
18664
18665 case Ekind (Ent) is
18666
18667 -- Objects (constants and variables) and types. For these cases
18668 -- all we need to do is to set the Linker_Section_pragma field,
18669 -- checking that we do not have a duplicate.
18670
18671 when Type_Kind
18672 | E_Constant
18673 | E_Variable
18674 =>
18675 LPE := Linker_Section_Pragma (Ent);
18676
18677 if Present (LPE) then
18678 Error_Msg_Sloc := Sloc (LPE);
18679 Error_Msg_NE
18680 ("Linker_Section already specified for &#", Arg1, Ent);
18681 end if;
18682
18683 Set_Linker_Section_Pragma (Ent, N);
18684
18685 -- A pragma that applies to a Ghost entity becomes Ghost for
18686 -- the purposes of legality checks and removal of ignored
18687 -- Ghost code.
18688
18689 Mark_Ghost_Pragma (N, Ent);
18690
18691 -- Subprograms
18692
18693 when Subprogram_Kind =>
18694
18695 -- Aspect case, entity already set
18696
18697 if From_Aspect_Specification (N) then
18698 Set_Linker_Section_Pragma
18699 (Entity (Corresponding_Aspect (N)), N);
18700
18701 -- Propagate it to its ultimate aliased entity to
18702 -- facilitate the backend processing this attribute
18703 -- in instantiations of generic subprograms.
18704
18705 if Present (Alias (Entity (Corresponding_Aspect (N))))
18706 then
18707 Set_Linker_Section_Pragma
18708 (Ultimate_Alias
18709 (Entity (Corresponding_Aspect (N))), N);
18710 end if;
18711
18712 -- Pragma case, we must climb the homonym chain, but skip
18713 -- any for which the linker section is already set.
18714
18715 else
18716 loop
18717 if No (Linker_Section_Pragma (Ent)) then
18718 Set_Linker_Section_Pragma (Ent, N);
18719
18720 -- Propagate it to its ultimate aliased entity to
18721 -- facilitate the backend processing this attribute
18722 -- in instantiations of generic subprograms.
18723
18724 if Present (Alias (Ent)) then
18725 Set_Linker_Section_Pragma
18726 (Ultimate_Alias (Ent), N);
18727 end if;
18728
18729 -- A pragma that applies to a Ghost entity becomes
18730 -- Ghost for the purposes of legality checks and
18731 -- removal of ignored Ghost code.
18732
18733 Mark_Ghost_Pragma (N, Ent);
18734
18735 -- Capture the entity of the first Ghost subprogram
18736 -- being processed for error detection purposes.
18737
18738 if Is_Ghost_Entity (Ent) then
18739 if No (Ghost_Id) then
18740 Ghost_Id := Ent;
18741 end if;
18742
18743 -- Otherwise the subprogram is non-Ghost. It is
18744 -- illegal to mix references to Ghost and non-Ghost
18745 -- entities (SPARK RM 6.9).
18746
18747 elsif Present (Ghost_Id)
18748 and then not Ghost_Error_Posted
18749 then
18750 Ghost_Error_Posted := True;
18751
18752 Error_Msg_Name_1 := Pname;
18753 Error_Msg_N
18754 ("pragma % cannot mention ghost and "
18755 & "non-ghost subprograms", N);
18756
18757 Error_Msg_Sloc := Sloc (Ghost_Id);
18758 Error_Msg_NE
18759 ("\& # declared as ghost", N, Ghost_Id);
18760
18761 Error_Msg_Sloc := Sloc (Ent);
18762 Error_Msg_NE
18763 ("\& # declared as non-ghost", N, Ent);
18764 end if;
18765 end if;
18766
18767 Ent := Homonym (Ent);
18768 exit when No (Ent)
18769 or else Scope (Ent) /= Current_Scope;
18770 end loop;
18771 end if;
18772
18773 -- All other cases are illegal
18774
18775 when others =>
18776 Error_Pragma_Arg
18777 ("pragma% applies only to objects, subprograms, and types",
18778 Arg1);
18779 end case;
18780 end Linker_Section;
18781
18782 ----------
18783 -- List --
18784 ----------
18785
18786 -- pragma List (On | Off)
18787
18788 -- There is nothing to do here, since we did all the processing for
18789 -- this pragma in Par.Prag (so that it works properly even in syntax
18790 -- only mode).
18791
18792 when Pragma_List =>
18793 null;
18794
18795 ---------------
18796 -- Lock_Free --
18797 ---------------
18798
18799 -- pragma Lock_Free [(Boolean_EXPRESSION)];
18800
18801 when Pragma_Lock_Free => Lock_Free : declare
18802 P : constant Node_Id := Parent (N);
18803 Arg : Node_Id;
18804 Ent : Entity_Id;
18805 Val : Boolean;
18806
18807 begin
18808 Check_No_Identifiers;
18809 Check_At_Most_N_Arguments (1);
18810
18811 -- Protected definition case
18812
18813 if Nkind (P) = N_Protected_Definition then
18814 Ent := Defining_Identifier (Parent (P));
18815
18816 -- One argument
18817
18818 if Arg_Count = 1 then
18819 Arg := Get_Pragma_Arg (Arg1);
18820 Val := Is_True (Static_Boolean (Arg));
18821
18822 -- No arguments (expression is considered to be True)
18823
18824 else
18825 Val := True;
18826 end if;
18827
18828 -- Check duplicate pragma before we chain the pragma in the Rep
18829 -- Item chain of Ent.
18830
18831 Check_Duplicate_Pragma (Ent);
18832 Record_Rep_Item (Ent, N);
18833 Set_Uses_Lock_Free (Ent, Val);
18834
18835 -- Anything else is incorrect placement
18836
18837 else
18838 Pragma_Misplaced;
18839 end if;
18840 end Lock_Free;
18841
18842 --------------------
18843 -- Locking_Policy --
18844 --------------------
18845
18846 -- pragma Locking_Policy (policy_IDENTIFIER);
18847
18848 when Pragma_Locking_Policy => declare
18849 subtype LP_Range is Name_Id
18850 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
18851 LP_Val : LP_Range;
18852 LP : Character;
18853
18854 begin
18855 Check_Ada_83_Warning;
18856 Check_Arg_Count (1);
18857 Check_No_Identifiers;
18858 Check_Arg_Is_Locking_Policy (Arg1);
18859 Check_Valid_Configuration_Pragma;
18860 LP_Val := Chars (Get_Pragma_Arg (Arg1));
18861
18862 case LP_Val is
18863 when Name_Ceiling_Locking => LP := 'C';
18864 when Name_Concurrent_Readers_Locking => LP := 'R';
18865 when Name_Inheritance_Locking => LP := 'I';
18866 end case;
18867
18868 if Locking_Policy /= ' '
18869 and then Locking_Policy /= LP
18870 then
18871 Error_Msg_Sloc := Locking_Policy_Sloc;
18872 Error_Pragma ("locking policy incompatible with policy#");
18873
18874 -- Set new policy, but always preserve System_Location since we
18875 -- like the error message with the run time name.
18876
18877 else
18878 Locking_Policy := LP;
18879
18880 if Locking_Policy_Sloc /= System_Location then
18881 Locking_Policy_Sloc := Loc;
18882 end if;
18883 end if;
18884 end;
18885
18886 -------------------
18887 -- Loop_Optimize --
18888 -------------------
18889
18890 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
18891
18892 -- OPTIMIZATION_HINT ::=
18893 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
18894
18895 when Pragma_Loop_Optimize => Loop_Optimize : declare
18896 Hint : Node_Id;
18897
18898 begin
18899 GNAT_Pragma;
18900 Check_At_Least_N_Arguments (1);
18901 Check_No_Identifiers;
18902
18903 Hint := First (Pragma_Argument_Associations (N));
18904 while Present (Hint) loop
18905 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
18906 Name_No_Unroll,
18907 Name_Unroll,
18908 Name_No_Vector,
18909 Name_Vector);
18910 Next (Hint);
18911 end loop;
18912
18913 Check_Loop_Pragma_Placement;
18914 end Loop_Optimize;
18915
18916 ------------------
18917 -- Loop_Variant --
18918 ------------------
18919
18920 -- pragma Loop_Variant
18921 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
18922
18923 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
18924
18925 -- CHANGE_DIRECTION ::= Increases | Decreases
18926
18927 when Pragma_Loop_Variant => Loop_Variant : declare
18928 Variant : Node_Id;
18929
18930 begin
18931 GNAT_Pragma;
18932 Check_At_Least_N_Arguments (1);
18933 Check_Loop_Pragma_Placement;
18934
18935 -- Process all increasing / decreasing expressions
18936
18937 Variant := First (Pragma_Argument_Associations (N));
18938 while Present (Variant) loop
18939 if Chars (Variant) = No_Name then
18940 Error_Pragma_Arg_Ident ("expect name `Increases`", Variant);
18941
18942 elsif not Nam_In (Chars (Variant), Name_Decreases,
18943 Name_Increases)
18944 then
18945 declare
18946 Name : String := Get_Name_String (Chars (Variant));
18947
18948 begin
18949 -- It is a common mistake to write "Increasing" for
18950 -- "Increases" or "Decreasing" for "Decreases". Recognize
18951 -- specially names starting with "incr" or "decr" to
18952 -- suggest the corresponding name.
18953
18954 System.Case_Util.To_Lower (Name);
18955
18956 if Name'Length >= 4
18957 and then Name (1 .. 4) = "incr"
18958 then
18959 Error_Pragma_Arg_Ident
18960 ("expect name `Increases`", Variant);
18961
18962 elsif Name'Length >= 4
18963 and then Name (1 .. 4) = "decr"
18964 then
18965 Error_Pragma_Arg_Ident
18966 ("expect name `Decreases`", Variant);
18967
18968 else
18969 Error_Pragma_Arg_Ident
18970 ("expect name `Increases` or `Decreases`", Variant);
18971 end if;
18972 end;
18973 end if;
18974
18975 Preanalyze_Assert_Expression
18976 (Expression (Variant), Any_Discrete);
18977
18978 Next (Variant);
18979 end loop;
18980 end Loop_Variant;
18981
18982 -----------------------
18983 -- Machine_Attribute --
18984 -----------------------
18985
18986 -- pragma Machine_Attribute (
18987 -- [Entity =>] LOCAL_NAME,
18988 -- [Attribute_Name =>] static_string_EXPRESSION
18989 -- [, [Info =>] static_EXPRESSION {, static_EXPRESSION}] );
18990
18991 when Pragma_Machine_Attribute => Machine_Attribute : declare
18992 Arg : Node_Id;
18993 Def_Id : Entity_Id;
18994
18995 begin
18996 GNAT_Pragma;
18997 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
18998
18999 if Arg_Count >= 3 then
19000 Check_Optional_Identifier (Arg3, Name_Info);
19001 Arg := Arg3;
19002 while Present (Arg) loop
19003 Check_Arg_Is_OK_Static_Expression (Arg);
19004 Arg := Next (Arg);
19005 end loop;
19006 else
19007 Check_Arg_Count (2);
19008 end if;
19009
19010 Check_Optional_Identifier (Arg1, Name_Entity);
19011 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
19012 Check_Arg_Is_Local_Name (Arg1);
19013 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19014 Def_Id := Entity (Get_Pragma_Arg (Arg1));
19015
19016 if Is_Access_Type (Def_Id) then
19017 Def_Id := Designated_Type (Def_Id);
19018 end if;
19019
19020 if Rep_Item_Too_Early (Def_Id, N) then
19021 return;
19022 end if;
19023
19024 Def_Id := Underlying_Type (Def_Id);
19025
19026 -- The only processing required is to link this item on to the
19027 -- list of rep items for the given entity. This is accomplished
19028 -- by the call to Rep_Item_Too_Late (when no error is detected
19029 -- and False is returned).
19030
19031 if Rep_Item_Too_Late (Def_Id, N) then
19032 return;
19033 else
19034 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
19035 end if;
19036 end Machine_Attribute;
19037
19038 ----------
19039 -- Main --
19040 ----------
19041
19042 -- pragma Main
19043 -- (MAIN_OPTION [, MAIN_OPTION]);
19044
19045 -- MAIN_OPTION ::=
19046 -- [STACK_SIZE =>] static_integer_EXPRESSION
19047 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
19048 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
19049
19050 when Pragma_Main => Main : declare
19051 Args : Args_List (1 .. 3);
19052 Names : constant Name_List (1 .. 3) := (
19053 Name_Stack_Size,
19054 Name_Task_Stack_Size_Default,
19055 Name_Time_Slicing_Enabled);
19056
19057 Nod : Node_Id;
19058
19059 begin
19060 GNAT_Pragma;
19061 Gather_Associations (Names, Args);
19062
19063 for J in 1 .. 2 loop
19064 if Present (Args (J)) then
19065 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19066 end if;
19067 end loop;
19068
19069 if Present (Args (3)) then
19070 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
19071 end if;
19072
19073 Nod := Next (N);
19074 while Present (Nod) loop
19075 if Nkind (Nod) = N_Pragma
19076 and then Pragma_Name (Nod) = Name_Main
19077 then
19078 Error_Msg_Name_1 := Pname;
19079 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19080 end if;
19081
19082 Next (Nod);
19083 end loop;
19084 end Main;
19085
19086 ------------------
19087 -- Main_Storage --
19088 ------------------
19089
19090 -- pragma Main_Storage
19091 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
19092
19093 -- MAIN_STORAGE_OPTION ::=
19094 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
19095 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
19096
19097 when Pragma_Main_Storage => Main_Storage : declare
19098 Args : Args_List (1 .. 2);
19099 Names : constant Name_List (1 .. 2) := (
19100 Name_Working_Storage,
19101 Name_Top_Guard);
19102
19103 Nod : Node_Id;
19104
19105 begin
19106 GNAT_Pragma;
19107 Gather_Associations (Names, Args);
19108
19109 for J in 1 .. 2 loop
19110 if Present (Args (J)) then
19111 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19112 end if;
19113 end loop;
19114
19115 Check_In_Main_Program;
19116
19117 Nod := Next (N);
19118 while Present (Nod) loop
19119 if Nkind (Nod) = N_Pragma
19120 and then Pragma_Name (Nod) = Name_Main_Storage
19121 then
19122 Error_Msg_Name_1 := Pname;
19123 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19124 end if;
19125
19126 Next (Nod);
19127 end loop;
19128 end Main_Storage;
19129
19130 ----------------------------
19131 -- Max_Entry_Queue_Length --
19132 ----------------------------
19133
19134 -- pragma Max_Entry_Queue_Length (static_integer_EXPRESSION);
19135
19136 -- This processing is shared by Pragma_Max_Entry_Queue_Depth and
19137 -- Pragma_Max_Queue_Length.
19138
19139 when Pragma_Max_Entry_Queue_Length
19140 | Pragma_Max_Entry_Queue_Depth
19141 | Pragma_Max_Queue_Length
19142 =>
19143 Max_Entry_Queue_Length : declare
19144 Arg : Node_Id;
19145 Entry_Decl : Node_Id;
19146 Entry_Id : Entity_Id;
19147 Val : Uint;
19148
19149 begin
19150 if Prag_Id = Pragma_Max_Entry_Queue_Depth
19151 or else Prag_Id = Pragma_Max_Queue_Length
19152 then
19153 GNAT_Pragma;
19154 end if;
19155
19156 Check_Arg_Count (1);
19157
19158 Entry_Decl :=
19159 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
19160
19161 -- Entry declaration
19162
19163 if Nkind (Entry_Decl) = N_Entry_Declaration then
19164
19165 -- Entry illegally within a task
19166
19167 if Nkind (Parent (N)) = N_Task_Definition then
19168 Error_Pragma ("pragma % cannot apply to task entries");
19169 return;
19170 end if;
19171
19172 Entry_Id := Defining_Entity (Entry_Decl);
19173
19174 -- Otherwise the pragma is associated with an illegal construct
19175
19176 else
19177 Error_Pragma ("pragma % must apply to a protected entry");
19178 return;
19179 end if;
19180
19181 -- Mark the pragma as Ghost if the related subprogram is also
19182 -- Ghost. This also ensures that any expansion performed further
19183 -- below will produce Ghost nodes.
19184
19185 Mark_Ghost_Pragma (N, Entry_Id);
19186
19187 -- Analyze the Integer expression
19188
19189 Arg := Get_Pragma_Arg (Arg1);
19190 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
19191
19192 Val := Expr_Value (Arg);
19193
19194 if Val < -1 then
19195 Error_Pragma_Arg
19196 ("argument for pragma% cannot be less than -1", Arg1);
19197
19198 elsif not UI_Is_In_Int_Range (Val) then
19199 Error_Pragma_Arg
19200 ("argument for pragma% out of range of Integer", Arg1);
19201
19202 end if;
19203
19204 Record_Rep_Item (Entry_Id, N);
19205 end Max_Entry_Queue_Length;
19206
19207 -----------------
19208 -- Memory_Size --
19209 -----------------
19210
19211 -- pragma Memory_Size (NUMERIC_LITERAL)
19212
19213 when Pragma_Memory_Size =>
19214 GNAT_Pragma;
19215
19216 -- Memory size is simply ignored
19217
19218 Check_No_Identifiers;
19219 Check_Arg_Count (1);
19220 Check_Arg_Is_Integer_Literal (Arg1);
19221
19222 -------------
19223 -- No_Body --
19224 -------------
19225
19226 -- pragma No_Body;
19227
19228 -- The only correct use of this pragma is on its own in a file, in
19229 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
19230 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
19231 -- check for a file containing nothing but a No_Body pragma). If we
19232 -- attempt to process it during normal semantics processing, it means
19233 -- it was misplaced.
19234
19235 when Pragma_No_Body =>
19236 GNAT_Pragma;
19237 Pragma_Misplaced;
19238
19239 -----------------------------
19240 -- No_Elaboration_Code_All --
19241 -----------------------------
19242
19243 -- pragma No_Elaboration_Code_All;
19244
19245 when Pragma_No_Elaboration_Code_All =>
19246 GNAT_Pragma;
19247 Check_Valid_Library_Unit_Pragma;
19248
19249 if Nkind (N) = N_Null_Statement then
19250 return;
19251 end if;
19252
19253 -- Must appear for a spec or generic spec
19254
19255 if not Nkind_In (Unit (Cunit (Current_Sem_Unit)),
19256 N_Generic_Package_Declaration,
19257 N_Generic_Subprogram_Declaration,
19258 N_Package_Declaration,
19259 N_Subprogram_Declaration)
19260 then
19261 Error_Pragma
19262 (Fix_Error
19263 ("pragma% can only occur for package "
19264 & "or subprogram spec"));
19265 end if;
19266
19267 -- Set flag in unit table
19268
19269 Set_No_Elab_Code_All (Current_Sem_Unit);
19270
19271 -- Set restriction No_Elaboration_Code if this is the main unit
19272
19273 if Current_Sem_Unit = Main_Unit then
19274 Set_Restriction (No_Elaboration_Code, N);
19275 end if;
19276
19277 -- If we are in the main unit or in an extended main source unit,
19278 -- then we also add it to the configuration restrictions so that
19279 -- it will apply to all units in the extended main source.
19280
19281 if Current_Sem_Unit = Main_Unit
19282 or else In_Extended_Main_Source_Unit (N)
19283 then
19284 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
19285 end if;
19286
19287 -- If in main extended unit, activate transitive with test
19288
19289 if In_Extended_Main_Source_Unit (N) then
19290 Opt.No_Elab_Code_All_Pragma := N;
19291 end if;
19292
19293 -----------------------------
19294 -- No_Component_Reordering --
19295 -----------------------------
19296
19297 -- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
19298
19299 when Pragma_No_Component_Reordering => No_Comp_Reordering : declare
19300 E : Entity_Id;
19301 E_Id : Node_Id;
19302
19303 begin
19304 GNAT_Pragma;
19305 Check_At_Most_N_Arguments (1);
19306
19307 if Arg_Count = 0 then
19308 Check_Valid_Configuration_Pragma;
19309 Opt.No_Component_Reordering := True;
19310
19311 else
19312 Check_Optional_Identifier (Arg2, Name_Entity);
19313 Check_Arg_Is_Local_Name (Arg1);
19314 E_Id := Get_Pragma_Arg (Arg1);
19315
19316 if Etype (E_Id) = Any_Type then
19317 return;
19318 end if;
19319
19320 E := Entity (E_Id);
19321
19322 if not Is_Record_Type (E) then
19323 Error_Pragma_Arg ("pragma% requires record type", Arg1);
19324 end if;
19325
19326 Set_No_Reordering (Base_Type (E));
19327 end if;
19328 end No_Comp_Reordering;
19329
19330 --------------------------
19331 -- No_Heap_Finalization --
19332 --------------------------
19333
19334 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
19335
19336 when Pragma_No_Heap_Finalization => No_Heap_Finalization : declare
19337 Context : constant Node_Id := Parent (N);
19338 Typ_Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
19339 Prev : Node_Id;
19340 Typ : Entity_Id;
19341
19342 begin
19343 GNAT_Pragma;
19344 Check_No_Identifiers;
19345
19346 -- The pragma appears in a configuration file
19347
19348 if No (Context) then
19349 Check_Arg_Count (0);
19350 Check_Valid_Configuration_Pragma;
19351
19352 -- Detect a duplicate pragma
19353
19354 if Present (No_Heap_Finalization_Pragma) then
19355 Duplication_Error
19356 (Prag => N,
19357 Prev => No_Heap_Finalization_Pragma);
19358 raise Pragma_Exit;
19359 end if;
19360
19361 No_Heap_Finalization_Pragma := N;
19362
19363 -- Otherwise the pragma should be associated with a library-level
19364 -- named access-to-object type.
19365
19366 else
19367 Check_Arg_Count (1);
19368 Check_Arg_Is_Local_Name (Arg1);
19369
19370 Find_Type (Typ_Arg);
19371 Typ := Entity (Typ_Arg);
19372
19373 -- The type being subjected to the pragma is erroneous
19374
19375 if Typ = Any_Type then
19376 Error_Pragma ("cannot find type referenced by pragma %");
19377
19378 -- The pragma is applied to an incomplete or generic formal
19379 -- type way too early.
19380
19381 elsif Rep_Item_Too_Early (Typ, N) then
19382 return;
19383
19384 else
19385 Typ := Underlying_Type (Typ);
19386 end if;
19387
19388 -- The pragma must apply to an access-to-object type
19389
19390 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type) then
19391 null;
19392
19393 -- Give a detailed error message on all other access type kinds
19394
19395 elsif Ekind (Typ) = E_Access_Protected_Subprogram_Type then
19396 Error_Pragma
19397 ("pragma % cannot apply to access protected subprogram "
19398 & "type");
19399
19400 elsif Ekind (Typ) = E_Access_Subprogram_Type then
19401 Error_Pragma
19402 ("pragma % cannot apply to access subprogram type");
19403
19404 elsif Is_Anonymous_Access_Type (Typ) then
19405 Error_Pragma
19406 ("pragma % cannot apply to anonymous access type");
19407
19408 -- Give a general error message in case the pragma applies to a
19409 -- non-access type.
19410
19411 else
19412 Error_Pragma
19413 ("pragma % must apply to library level access type");
19414 end if;
19415
19416 -- At this point the argument denotes an access-to-object type.
19417 -- Ensure that the type is declared at the library level.
19418
19419 if Is_Library_Level_Entity (Typ) then
19420 null;
19421
19422 -- Quietly ignore an access-to-object type originally declared
19423 -- at the library level within a generic, but instantiated at
19424 -- a non-library level. As a result the access-to-object type
19425 -- "loses" its No_Heap_Finalization property.
19426
19427 elsif In_Instance then
19428 raise Pragma_Exit;
19429
19430 else
19431 Error_Pragma
19432 ("pragma % must apply to library level access type");
19433 end if;
19434
19435 -- Detect a duplicate pragma
19436
19437 if Present (No_Heap_Finalization_Pragma) then
19438 Duplication_Error
19439 (Prag => N,
19440 Prev => No_Heap_Finalization_Pragma);
19441 raise Pragma_Exit;
19442
19443 else
19444 Prev := Get_Pragma (Typ, Pragma_No_Heap_Finalization);
19445
19446 if Present (Prev) then
19447 Duplication_Error
19448 (Prag => N,
19449 Prev => Prev);
19450 raise Pragma_Exit;
19451 end if;
19452 end if;
19453
19454 Record_Rep_Item (Typ, N);
19455 end if;
19456 end No_Heap_Finalization;
19457
19458 ---------------
19459 -- No_Inline --
19460 ---------------
19461
19462 -- pragma No_Inline ( NAME {, NAME} );
19463
19464 when Pragma_No_Inline =>
19465 GNAT_Pragma;
19466 Process_Inline (Suppressed);
19467
19468 ---------------
19469 -- No_Return --
19470 ---------------
19471
19472 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
19473
19474 when Pragma_No_Return => No_Return : declare
19475 Arg : Node_Id;
19476 E : Entity_Id;
19477 Found : Boolean;
19478 Id : Node_Id;
19479
19480 Ghost_Error_Posted : Boolean := False;
19481 -- Flag set when an error concerning the illegal mix of Ghost and
19482 -- non-Ghost subprograms is emitted.
19483
19484 Ghost_Id : Entity_Id := Empty;
19485 -- The entity of the first Ghost procedure encountered while
19486 -- processing the arguments of the pragma.
19487
19488 begin
19489 Ada_2005_Pragma;
19490 Check_At_Least_N_Arguments (1);
19491
19492 -- Loop through arguments of pragma
19493
19494 Arg := Arg1;
19495 while Present (Arg) loop
19496 Check_Arg_Is_Local_Name (Arg);
19497 Id := Get_Pragma_Arg (Arg);
19498 Analyze (Id);
19499
19500 if not Is_Entity_Name (Id) then
19501 Error_Pragma_Arg ("entity name required", Arg);
19502 end if;
19503
19504 if Etype (Id) = Any_Type then
19505 raise Pragma_Exit;
19506 end if;
19507
19508 -- Loop to find matching procedures
19509
19510 E := Entity (Id);
19511
19512 Found := False;
19513 while Present (E)
19514 and then Scope (E) = Current_Scope
19515 loop
19516 if Ekind_In (E, E_Generic_Procedure, E_Procedure) then
19517
19518 -- Check that the pragma is not applied to a body.
19519 -- First check the specless body case, to give a
19520 -- different error message. These checks do not apply
19521 -- if Relaxed_RM_Semantics, to accommodate other Ada
19522 -- compilers. Disable these checks under -gnatd.J.
19523
19524 if not Debug_Flag_Dot_JJ then
19525 if Nkind (Parent (Declaration_Node (E))) =
19526 N_Subprogram_Body
19527 and then not Relaxed_RM_Semantics
19528 then
19529 Error_Pragma
19530 ("pragma% requires separate spec and must come "
19531 & "before body");
19532 end if;
19533
19534 -- Now the "specful" body case
19535
19536 if Rep_Item_Too_Late (E, N) then
19537 raise Pragma_Exit;
19538 end if;
19539 end if;
19540
19541 Set_No_Return (E);
19542
19543 -- A pragma that applies to a Ghost entity becomes Ghost
19544 -- for the purposes of legality checks and removal of
19545 -- ignored Ghost code.
19546
19547 Mark_Ghost_Pragma (N, E);
19548
19549 -- Capture the entity of the first Ghost procedure being
19550 -- processed for error detection purposes.
19551
19552 if Is_Ghost_Entity (E) then
19553 if No (Ghost_Id) then
19554 Ghost_Id := E;
19555 end if;
19556
19557 -- Otherwise the subprogram is non-Ghost. It is illegal
19558 -- to mix references to Ghost and non-Ghost entities
19559 -- (SPARK RM 6.9).
19560
19561 elsif Present (Ghost_Id)
19562 and then not Ghost_Error_Posted
19563 then
19564 Ghost_Error_Posted := True;
19565
19566 Error_Msg_Name_1 := Pname;
19567 Error_Msg_N
19568 ("pragma % cannot mention ghost and non-ghost "
19569 & "procedures", N);
19570
19571 Error_Msg_Sloc := Sloc (Ghost_Id);
19572 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
19573
19574 Error_Msg_Sloc := Sloc (E);
19575 Error_Msg_NE ("\& # declared as non-ghost", N, E);
19576 end if;
19577
19578 -- Set flag on any alias as well
19579
19580 if Is_Overloadable (E) and then Present (Alias (E)) then
19581 Set_No_Return (Alias (E));
19582 end if;
19583
19584 Found := True;
19585 end if;
19586
19587 exit when From_Aspect_Specification (N);
19588 E := Homonym (E);
19589 end loop;
19590
19591 -- If entity in not in current scope it may be the enclosing
19592 -- suprogram body to which the aspect applies.
19593
19594 if not Found then
19595 if Entity (Id) = Current_Scope
19596 and then From_Aspect_Specification (N)
19597 then
19598 Set_No_Return (Entity (Id));
19599 else
19600 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
19601 end if;
19602 end if;
19603
19604 Next (Arg);
19605 end loop;
19606 end No_Return;
19607
19608 -----------------
19609 -- No_Run_Time --
19610 -----------------
19611
19612 -- pragma No_Run_Time;
19613
19614 -- Note: this pragma is retained for backwards compatibility. See
19615 -- body of Rtsfind for full details on its handling.
19616
19617 when Pragma_No_Run_Time =>
19618 GNAT_Pragma;
19619 Check_Valid_Configuration_Pragma;
19620 Check_Arg_Count (0);
19621
19622 -- Remove backward compatibility if Build_Type is FSF or GPL and
19623 -- generate a warning.
19624
19625 declare
19626 Ignore : constant Boolean := Build_Type in FSF .. GPL;
19627 begin
19628 if Ignore then
19629 Error_Pragma ("pragma% is ignored, has no effect??");
19630 else
19631 No_Run_Time_Mode := True;
19632 Configurable_Run_Time_Mode := True;
19633
19634 -- Set Duration to 32 bits if word size is 32
19635
19636 if Ttypes.System_Word_Size = 32 then
19637 Duration_32_Bits_On_Target := True;
19638 end if;
19639
19640 -- Set appropriate restrictions
19641
19642 Set_Restriction (No_Finalization, N);
19643 Set_Restriction (No_Exception_Handlers, N);
19644 Set_Restriction (Max_Tasks, N, 0);
19645 Set_Restriction (No_Tasking, N);
19646 end if;
19647 end;
19648
19649 -----------------------
19650 -- No_Tagged_Streams --
19651 -----------------------
19652
19653 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
19654
19655 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
19656 E : Entity_Id;
19657 E_Id : Node_Id;
19658
19659 begin
19660 GNAT_Pragma;
19661 Check_At_Most_N_Arguments (1);
19662
19663 -- One argument case
19664
19665 if Arg_Count = 1 then
19666 Check_Optional_Identifier (Arg1, Name_Entity);
19667 Check_Arg_Is_Local_Name (Arg1);
19668 E_Id := Get_Pragma_Arg (Arg1);
19669
19670 if Etype (E_Id) = Any_Type then
19671 return;
19672 end if;
19673
19674 E := Entity (E_Id);
19675
19676 Check_Duplicate_Pragma (E);
19677
19678 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
19679 Error_Pragma_Arg
19680 ("argument for pragma% must be root tagged type", Arg1);
19681 end if;
19682
19683 if Rep_Item_Too_Early (E, N)
19684 or else
19685 Rep_Item_Too_Late (E, N)
19686 then
19687 return;
19688 else
19689 Set_No_Tagged_Streams_Pragma (E, N);
19690 end if;
19691
19692 -- Zero argument case
19693
19694 else
19695 Check_Is_In_Decl_Part_Or_Package_Spec;
19696 No_Tagged_Streams := N;
19697 end if;
19698 end No_Tagged_Strms;
19699
19700 ------------------------
19701 -- No_Strict_Aliasing --
19702 ------------------------
19703
19704 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
19705
19706 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
19707 E : Entity_Id;
19708 E_Id : Node_Id;
19709
19710 begin
19711 GNAT_Pragma;
19712 Check_At_Most_N_Arguments (1);
19713
19714 if Arg_Count = 0 then
19715 Check_Valid_Configuration_Pragma;
19716 Opt.No_Strict_Aliasing := True;
19717
19718 else
19719 Check_Optional_Identifier (Arg2, Name_Entity);
19720 Check_Arg_Is_Local_Name (Arg1);
19721 E_Id := Get_Pragma_Arg (Arg1);
19722
19723 if Etype (E_Id) = Any_Type then
19724 return;
19725 end if;
19726
19727 E := Entity (E_Id);
19728
19729 if not Is_Access_Type (E) then
19730 Error_Pragma_Arg ("pragma% requires access type", Arg1);
19731 end if;
19732
19733 Set_No_Strict_Aliasing (Base_Type (E));
19734 end if;
19735 end No_Strict_Aliasing;
19736
19737 -----------------------
19738 -- Normalize_Scalars --
19739 -----------------------
19740
19741 -- pragma Normalize_Scalars;
19742
19743 when Pragma_Normalize_Scalars =>
19744 Check_Ada_83_Warning;
19745 Check_Arg_Count (0);
19746 Check_Valid_Configuration_Pragma;
19747
19748 -- Normalize_Scalars creates false positives in CodePeer, and
19749 -- incorrect negative results in GNATprove mode, so ignore this
19750 -- pragma in these modes.
19751
19752 if not (CodePeer_Mode or GNATprove_Mode) then
19753 Normalize_Scalars := True;
19754 Init_Or_Norm_Scalars := True;
19755 end if;
19756
19757 -----------------
19758 -- Obsolescent --
19759 -----------------
19760
19761 -- pragma Obsolescent;
19762
19763 -- pragma Obsolescent (
19764 -- [Message =>] static_string_EXPRESSION
19765 -- [,[Version =>] Ada_05]]);
19766
19767 -- pragma Obsolescent (
19768 -- [Entity =>] NAME
19769 -- [,[Message =>] static_string_EXPRESSION
19770 -- [,[Version =>] Ada_05]] );
19771
19772 when Pragma_Obsolescent => Obsolescent : declare
19773 Decl : Node_Id;
19774 Ename : Node_Id;
19775
19776 procedure Set_Obsolescent (E : Entity_Id);
19777 -- Given an entity Ent, mark it as obsolescent if appropriate
19778
19779 ---------------------
19780 -- Set_Obsolescent --
19781 ---------------------
19782
19783 procedure Set_Obsolescent (E : Entity_Id) is
19784 Active : Boolean;
19785 Ent : Entity_Id;
19786 S : String_Id;
19787
19788 begin
19789 Active := True;
19790 Ent := E;
19791
19792 -- A pragma that applies to a Ghost entity becomes Ghost for
19793 -- the purposes of legality checks and removal of ignored Ghost
19794 -- code.
19795
19796 Mark_Ghost_Pragma (N, E);
19797
19798 -- Entity name was given
19799
19800 if Present (Ename) then
19801
19802 -- If entity name matches, we are fine.
19803
19804 if Chars (Ename) = Chars (Ent) then
19805 Set_Entity (Ename, Ent);
19806 Generate_Reference (Ent, Ename);
19807
19808 -- If entity name does not match, only possibility is an
19809 -- enumeration literal from an enumeration type declaration.
19810
19811 elsif Ekind (Ent) /= E_Enumeration_Type then
19812 Error_Pragma
19813 ("pragma % entity name does not match declaration");
19814
19815 else
19816 Ent := First_Literal (E);
19817 loop
19818 if No (Ent) then
19819 Error_Pragma
19820 ("pragma % entity name does not match any "
19821 & "enumeration literal");
19822
19823 elsif Chars (Ent) = Chars (Ename) then
19824 Set_Entity (Ename, Ent);
19825 Generate_Reference (Ent, Ename);
19826 exit;
19827
19828 else
19829 Next_Literal (Ent);
19830 end if;
19831 end loop;
19832 end if;
19833 end if;
19834
19835 -- Ent points to entity to be marked
19836
19837 if Arg_Count >= 1 then
19838
19839 -- Deal with static string argument
19840
19841 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
19842 S := Strval (Get_Pragma_Arg (Arg1));
19843
19844 for J in 1 .. String_Length (S) loop
19845 if not In_Character_Range (Get_String_Char (S, J)) then
19846 Error_Pragma_Arg
19847 ("pragma% argument does not allow wide characters",
19848 Arg1);
19849 end if;
19850 end loop;
19851
19852 Obsolescent_Warnings.Append
19853 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
19854
19855 -- Check for Ada_05 parameter
19856
19857 if Arg_Count /= 1 then
19858 Check_Arg_Count (2);
19859
19860 declare
19861 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
19862
19863 begin
19864 Check_Arg_Is_Identifier (Argx);
19865
19866 if Chars (Argx) /= Name_Ada_05 then
19867 Error_Msg_Name_2 := Name_Ada_05;
19868 Error_Pragma_Arg
19869 ("only allowed argument for pragma% is %", Argx);
19870 end if;
19871
19872 if Ada_Version_Explicit < Ada_2005
19873 or else not Warn_On_Ada_2005_Compatibility
19874 then
19875 Active := False;
19876 end if;
19877 end;
19878 end if;
19879 end if;
19880
19881 -- Set flag if pragma active
19882
19883 if Active then
19884 Set_Is_Obsolescent (Ent);
19885 end if;
19886
19887 return;
19888 end Set_Obsolescent;
19889
19890 -- Start of processing for pragma Obsolescent
19891
19892 begin
19893 GNAT_Pragma;
19894
19895 Check_At_Most_N_Arguments (3);
19896
19897 -- See if first argument specifies an entity name
19898
19899 if Arg_Count >= 1
19900 and then
19901 (Chars (Arg1) = Name_Entity
19902 or else
19903 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
19904 N_Identifier,
19905 N_Operator_Symbol))
19906 then
19907 Ename := Get_Pragma_Arg (Arg1);
19908
19909 -- Eliminate first argument, so we can share processing
19910
19911 Arg1 := Arg2;
19912 Arg2 := Arg3;
19913 Arg_Count := Arg_Count - 1;
19914
19915 -- No Entity name argument given
19916
19917 else
19918 Ename := Empty;
19919 end if;
19920
19921 if Arg_Count >= 1 then
19922 Check_Optional_Identifier (Arg1, Name_Message);
19923
19924 if Arg_Count = 2 then
19925 Check_Optional_Identifier (Arg2, Name_Version);
19926 end if;
19927 end if;
19928
19929 -- Get immediately preceding declaration
19930
19931 Decl := Prev (N);
19932 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
19933 Prev (Decl);
19934 end loop;
19935
19936 -- Cases where we do not follow anything other than another pragma
19937
19938 if No (Decl) then
19939
19940 -- First case: library level compilation unit declaration with
19941 -- the pragma immediately following the declaration.
19942
19943 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
19944 Set_Obsolescent
19945 (Defining_Entity (Unit (Parent (Parent (N)))));
19946 return;
19947
19948 -- Case 2: library unit placement for package
19949
19950 else
19951 declare
19952 Ent : constant Entity_Id := Find_Lib_Unit_Name;
19953 begin
19954 if Is_Package_Or_Generic_Package (Ent) then
19955 Set_Obsolescent (Ent);
19956 return;
19957 end if;
19958 end;
19959 end if;
19960
19961 -- Cases where we must follow a declaration, including an
19962 -- abstract subprogram declaration, which is not in the
19963 -- other node subtypes.
19964
19965 else
19966 if Nkind (Decl) not in N_Declaration
19967 and then Nkind (Decl) not in N_Later_Decl_Item
19968 and then Nkind (Decl) not in N_Generic_Declaration
19969 and then Nkind (Decl) not in N_Renaming_Declaration
19970 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
19971 then
19972 Error_Pragma
19973 ("pragma% misplaced, "
19974 & "must immediately follow a declaration");
19975
19976 else
19977 Set_Obsolescent (Defining_Entity (Decl));
19978 return;
19979 end if;
19980 end if;
19981 end Obsolescent;
19982
19983 --------------
19984 -- Optimize --
19985 --------------
19986
19987 -- pragma Optimize (Time | Space | Off);
19988
19989 -- The actual check for optimize is done in Gigi. Note that this
19990 -- pragma does not actually change the optimization setting, it
19991 -- simply checks that it is consistent with the pragma.
19992
19993 when Pragma_Optimize =>
19994 Check_No_Identifiers;
19995 Check_Arg_Count (1);
19996 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
19997
19998 ------------------------
19999 -- Optimize_Alignment --
20000 ------------------------
20001
20002 -- pragma Optimize_Alignment (Time | Space | Off);
20003
20004 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
20005 GNAT_Pragma;
20006 Check_No_Identifiers;
20007 Check_Arg_Count (1);
20008 Check_Valid_Configuration_Pragma;
20009
20010 declare
20011 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
20012 begin
20013 case Nam is
20014 when Name_Off => Opt.Optimize_Alignment := 'O';
20015 when Name_Space => Opt.Optimize_Alignment := 'S';
20016 when Name_Time => Opt.Optimize_Alignment := 'T';
20017
20018 when others =>
20019 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
20020 end case;
20021 end;
20022
20023 -- Set indication that mode is set locally. If we are in fact in a
20024 -- configuration pragma file, this setting is harmless since the
20025 -- switch will get reset anyway at the start of each unit.
20026
20027 Optimize_Alignment_Local := True;
20028 end Optimize_Alignment;
20029
20030 -------------
20031 -- Ordered --
20032 -------------
20033
20034 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
20035
20036 when Pragma_Ordered => Ordered : declare
20037 Assoc : constant Node_Id := Arg1;
20038 Type_Id : Node_Id;
20039 Typ : Entity_Id;
20040
20041 begin
20042 GNAT_Pragma;
20043 Check_No_Identifiers;
20044 Check_Arg_Count (1);
20045 Check_Arg_Is_Local_Name (Arg1);
20046
20047 Type_Id := Get_Pragma_Arg (Assoc);
20048 Find_Type (Type_Id);
20049 Typ := Entity (Type_Id);
20050
20051 if Typ = Any_Type then
20052 return;
20053 else
20054 Typ := Underlying_Type (Typ);
20055 end if;
20056
20057 if not Is_Enumeration_Type (Typ) then
20058 Error_Pragma ("pragma% must specify enumeration type");
20059 end if;
20060
20061 Check_First_Subtype (Arg1);
20062 Set_Has_Pragma_Ordered (Base_Type (Typ));
20063 end Ordered;
20064
20065 -------------------
20066 -- Overflow_Mode --
20067 -------------------
20068
20069 -- pragma Overflow_Mode
20070 -- ([General => ] MODE [, [Assertions => ] MODE]);
20071
20072 -- MODE := STRICT | MINIMIZED | ELIMINATED
20073
20074 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
20075 -- since System.Bignums makes this assumption. This is true of nearly
20076 -- all (all?) targets.
20077
20078 when Pragma_Overflow_Mode => Overflow_Mode : declare
20079 function Get_Overflow_Mode
20080 (Name : Name_Id;
20081 Arg : Node_Id) return Overflow_Mode_Type;
20082 -- Function to process one pragma argument, Arg. If an identifier
20083 -- is present, it must be Name. Mode type is returned if a valid
20084 -- argument exists, otherwise an error is signalled.
20085
20086 -----------------------
20087 -- Get_Overflow_Mode --
20088 -----------------------
20089
20090 function Get_Overflow_Mode
20091 (Name : Name_Id;
20092 Arg : Node_Id) return Overflow_Mode_Type
20093 is
20094 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
20095
20096 begin
20097 Check_Optional_Identifier (Arg, Name);
20098 Check_Arg_Is_Identifier (Argx);
20099
20100 if Chars (Argx) = Name_Strict then
20101 return Strict;
20102
20103 elsif Chars (Argx) = Name_Minimized then
20104 return Minimized;
20105
20106 elsif Chars (Argx) = Name_Eliminated then
20107 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
20108 Error_Pragma_Arg
20109 ("Eliminated not implemented on this target", Argx);
20110 else
20111 return Eliminated;
20112 end if;
20113
20114 else
20115 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
20116 end if;
20117 end Get_Overflow_Mode;
20118
20119 -- Start of processing for Overflow_Mode
20120
20121 begin
20122 GNAT_Pragma;
20123 Check_At_Least_N_Arguments (1);
20124 Check_At_Most_N_Arguments (2);
20125
20126 -- Process first argument
20127
20128 Scope_Suppress.Overflow_Mode_General :=
20129 Get_Overflow_Mode (Name_General, Arg1);
20130
20131 -- Case of only one argument
20132
20133 if Arg_Count = 1 then
20134 Scope_Suppress.Overflow_Mode_Assertions :=
20135 Scope_Suppress.Overflow_Mode_General;
20136
20137 -- Case of two arguments present
20138
20139 else
20140 Scope_Suppress.Overflow_Mode_Assertions :=
20141 Get_Overflow_Mode (Name_Assertions, Arg2);
20142 end if;
20143 end Overflow_Mode;
20144
20145 --------------------------
20146 -- Overriding Renamings --
20147 --------------------------
20148
20149 -- pragma Overriding_Renamings;
20150
20151 when Pragma_Overriding_Renamings =>
20152 GNAT_Pragma;
20153 Check_Arg_Count (0);
20154 Check_Valid_Configuration_Pragma;
20155 Overriding_Renamings := True;
20156
20157 ----------
20158 -- Pack --
20159 ----------
20160
20161 -- pragma Pack (first_subtype_LOCAL_NAME);
20162
20163 when Pragma_Pack => Pack : declare
20164 Assoc : constant Node_Id := Arg1;
20165 Ctyp : Entity_Id;
20166 Ignore : Boolean := False;
20167 Typ : Entity_Id;
20168 Type_Id : Node_Id;
20169
20170 begin
20171 Check_No_Identifiers;
20172 Check_Arg_Count (1);
20173 Check_Arg_Is_Local_Name (Arg1);
20174 Type_Id := Get_Pragma_Arg (Assoc);
20175
20176 if not Is_Entity_Name (Type_Id)
20177 or else not Is_Type (Entity (Type_Id))
20178 then
20179 Error_Pragma_Arg
20180 ("argument for pragma% must be type or subtype", Arg1);
20181 end if;
20182
20183 Find_Type (Type_Id);
20184 Typ := Entity (Type_Id);
20185
20186 if Typ = Any_Type
20187 or else Rep_Item_Too_Early (Typ, N)
20188 then
20189 return;
20190 else
20191 Typ := Underlying_Type (Typ);
20192 end if;
20193
20194 -- A pragma that applies to a Ghost entity becomes Ghost for the
20195 -- purposes of legality checks and removal of ignored Ghost code.
20196
20197 Mark_Ghost_Pragma (N, Typ);
20198
20199 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
20200 Error_Pragma ("pragma% must specify array or record type");
20201 end if;
20202
20203 Check_First_Subtype (Arg1);
20204 Check_Duplicate_Pragma (Typ);
20205
20206 -- Array type
20207
20208 if Is_Array_Type (Typ) then
20209 Ctyp := Component_Type (Typ);
20210
20211 -- Ignore pack that does nothing
20212
20213 if Known_Static_Esize (Ctyp)
20214 and then Known_Static_RM_Size (Ctyp)
20215 and then Esize (Ctyp) = RM_Size (Ctyp)
20216 and then Addressable (Esize (Ctyp))
20217 then
20218 Ignore := True;
20219 end if;
20220
20221 -- Process OK pragma Pack. Note that if there is a separate
20222 -- component clause present, the Pack will be cancelled. This
20223 -- processing is in Freeze.
20224
20225 if not Rep_Item_Too_Late (Typ, N) then
20226
20227 -- In CodePeer mode, we do not need complex front-end
20228 -- expansions related to pragma Pack, so disable handling
20229 -- of pragma Pack.
20230
20231 if CodePeer_Mode then
20232 null;
20233
20234 -- Normal case where we do the pack action
20235
20236 else
20237 if not Ignore then
20238 Set_Is_Packed (Base_Type (Typ));
20239 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20240 end if;
20241
20242 Set_Has_Pragma_Pack (Base_Type (Typ));
20243 end if;
20244 end if;
20245
20246 -- For record types, the pack is always effective
20247
20248 else pragma Assert (Is_Record_Type (Typ));
20249 if not Rep_Item_Too_Late (Typ, N) then
20250 Set_Is_Packed (Base_Type (Typ));
20251 Set_Has_Pragma_Pack (Base_Type (Typ));
20252 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20253 end if;
20254 end if;
20255 end Pack;
20256
20257 ----------
20258 -- Page --
20259 ----------
20260
20261 -- pragma Page;
20262
20263 -- There is nothing to do here, since we did all the processing for
20264 -- this pragma in Par.Prag (so that it works properly even in syntax
20265 -- only mode).
20266
20267 when Pragma_Page =>
20268 null;
20269
20270 -------------
20271 -- Part_Of --
20272 -------------
20273
20274 -- pragma Part_Of (ABSTRACT_STATE);
20275
20276 -- ABSTRACT_STATE ::= NAME
20277
20278 when Pragma_Part_Of => Part_Of : declare
20279 procedure Propagate_Part_Of
20280 (Pack_Id : Entity_Id;
20281 State_Id : Entity_Id;
20282 Instance : Node_Id);
20283 -- Propagate the Part_Of indicator to all abstract states and
20284 -- objects declared in the visible state space of a package
20285 -- denoted by Pack_Id. State_Id is the encapsulating state.
20286 -- Instance is the package instantiation node.
20287
20288 -----------------------
20289 -- Propagate_Part_Of --
20290 -----------------------
20291
20292 procedure Propagate_Part_Of
20293 (Pack_Id : Entity_Id;
20294 State_Id : Entity_Id;
20295 Instance : Node_Id)
20296 is
20297 Has_Item : Boolean := False;
20298 -- Flag set when the visible state space contains at least one
20299 -- abstract state or variable.
20300
20301 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
20302 -- Propagate the Part_Of indicator to all abstract states and
20303 -- objects declared in the visible state space of a package
20304 -- denoted by Pack_Id.
20305
20306 -----------------------
20307 -- Propagate_Part_Of --
20308 -----------------------
20309
20310 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
20311 Constits : Elist_Id;
20312 Item_Id : Entity_Id;
20313
20314 begin
20315 -- Traverse the entity chain of the package and set relevant
20316 -- attributes of abstract states and objects declared in the
20317 -- visible state space of the package.
20318
20319 Item_Id := First_Entity (Pack_Id);
20320 while Present (Item_Id)
20321 and then not In_Private_Part (Item_Id)
20322 loop
20323 -- Do not consider internally generated items
20324
20325 if not Comes_From_Source (Item_Id) then
20326 null;
20327
20328 -- Do not consider generic formals or their corresponding
20329 -- actuals because they are not part of a visible state.
20330 -- Note that both entities are marked as hidden.
20331
20332 elsif Is_Hidden (Item_Id) then
20333 null;
20334
20335 -- The Part_Of indicator turns an abstract state or an
20336 -- object into a constituent of the encapsulating state.
20337 -- Note that constants are considered here even though
20338 -- they may not depend on variable input. This check is
20339 -- left to the SPARK prover.
20340
20341 elsif Ekind_In (Item_Id, E_Abstract_State,
20342 E_Constant,
20343 E_Variable)
20344 then
20345 Has_Item := True;
20346 Constits := Part_Of_Constituents (State_Id);
20347
20348 if No (Constits) then
20349 Constits := New_Elmt_List;
20350 Set_Part_Of_Constituents (State_Id, Constits);
20351 end if;
20352
20353 Append_Elmt (Item_Id, Constits);
20354 Set_Encapsulating_State (Item_Id, State_Id);
20355
20356 -- Recursively handle nested packages and instantiations
20357
20358 elsif Ekind (Item_Id) = E_Package then
20359 Propagate_Part_Of (Item_Id);
20360 end if;
20361
20362 Next_Entity (Item_Id);
20363 end loop;
20364 end Propagate_Part_Of;
20365
20366 -- Start of processing for Propagate_Part_Of
20367
20368 begin
20369 Propagate_Part_Of (Pack_Id);
20370
20371 -- Detect a package instantiation that is subject to a Part_Of
20372 -- indicator, but has no visible state.
20373
20374 if not Has_Item then
20375 SPARK_Msg_NE
20376 ("package instantiation & has Part_Of indicator but "
20377 & "lacks visible state", Instance, Pack_Id);
20378 end if;
20379 end Propagate_Part_Of;
20380
20381 -- Local variables
20382
20383 Constits : Elist_Id;
20384 Encap : Node_Id;
20385 Encap_Id : Entity_Id;
20386 Item_Id : Entity_Id;
20387 Legal : Boolean;
20388 Stmt : Node_Id;
20389
20390 -- Start of processing for Part_Of
20391
20392 begin
20393 GNAT_Pragma;
20394 Check_No_Identifiers;
20395 Check_Arg_Count (1);
20396
20397 Stmt := Find_Related_Context (N, Do_Checks => True);
20398
20399 -- Object declaration
20400
20401 if Nkind (Stmt) = N_Object_Declaration then
20402 null;
20403
20404 -- Package instantiation
20405
20406 elsif Nkind (Stmt) = N_Package_Instantiation then
20407 null;
20408
20409 -- Single concurrent type declaration
20410
20411 elsif Is_Single_Concurrent_Type_Declaration (Stmt) then
20412 null;
20413
20414 -- Otherwise the pragma is associated with an illegal construct
20415
20416 else
20417 Pragma_Misplaced;
20418 return;
20419 end if;
20420
20421 -- Extract the entity of the related object declaration or package
20422 -- instantiation. In the case of the instantiation, use the entity
20423 -- of the instance spec.
20424
20425 if Nkind (Stmt) = N_Package_Instantiation then
20426 Stmt := Instance_Spec (Stmt);
20427 end if;
20428
20429 Item_Id := Defining_Entity (Stmt);
20430
20431 -- A pragma that applies to a Ghost entity becomes Ghost for the
20432 -- purposes of legality checks and removal of ignored Ghost code.
20433
20434 Mark_Ghost_Pragma (N, Item_Id);
20435
20436 -- Chain the pragma on the contract for further processing by
20437 -- Analyze_Part_Of_In_Decl_Part or for completeness.
20438
20439 Add_Contract_Item (N, Item_Id);
20440
20441 -- A variable may act as constituent of a single concurrent type
20442 -- which in turn could be declared after the variable. Due to this
20443 -- discrepancy, the full analysis of indicator Part_Of is delayed
20444 -- until the end of the enclosing declarative region (see routine
20445 -- Analyze_Part_Of_In_Decl_Part).
20446
20447 if Ekind (Item_Id) = E_Variable then
20448 null;
20449
20450 -- Otherwise indicator Part_Of applies to a constant or a package
20451 -- instantiation.
20452
20453 else
20454 Encap := Get_Pragma_Arg (Arg1);
20455
20456 -- Detect any discrepancies between the placement of the
20457 -- constant or package instantiation with respect to state
20458 -- space and the encapsulating state.
20459
20460 Analyze_Part_Of
20461 (Indic => N,
20462 Item_Id => Item_Id,
20463 Encap => Encap,
20464 Encap_Id => Encap_Id,
20465 Legal => Legal);
20466
20467 if Legal then
20468 pragma Assert (Present (Encap_Id));
20469
20470 if Ekind (Item_Id) = E_Constant then
20471 Constits := Part_Of_Constituents (Encap_Id);
20472
20473 if No (Constits) then
20474 Constits := New_Elmt_List;
20475 Set_Part_Of_Constituents (Encap_Id, Constits);
20476 end if;
20477
20478 Append_Elmt (Item_Id, Constits);
20479 Set_Encapsulating_State (Item_Id, Encap_Id);
20480
20481 -- Propagate the Part_Of indicator to the visible state
20482 -- space of the package instantiation.
20483
20484 else
20485 Propagate_Part_Of
20486 (Pack_Id => Item_Id,
20487 State_Id => Encap_Id,
20488 Instance => Stmt);
20489 end if;
20490 end if;
20491 end if;
20492 end Part_Of;
20493
20494 ----------------------------------
20495 -- Partition_Elaboration_Policy --
20496 ----------------------------------
20497
20498 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
20499
20500 when Pragma_Partition_Elaboration_Policy => PEP : declare
20501 subtype PEP_Range is Name_Id
20502 range First_Partition_Elaboration_Policy_Name
20503 .. Last_Partition_Elaboration_Policy_Name;
20504 PEP_Val : PEP_Range;
20505 PEP : Character;
20506
20507 begin
20508 Ada_2005_Pragma;
20509 Check_Arg_Count (1);
20510 Check_No_Identifiers;
20511 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
20512 Check_Valid_Configuration_Pragma;
20513 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
20514
20515 case PEP_Val is
20516 when Name_Concurrent => PEP := 'C';
20517 when Name_Sequential => PEP := 'S';
20518 end case;
20519
20520 if Partition_Elaboration_Policy /= ' '
20521 and then Partition_Elaboration_Policy /= PEP
20522 then
20523 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
20524 Error_Pragma
20525 ("partition elaboration policy incompatible with policy#");
20526
20527 -- Set new policy, but always preserve System_Location since we
20528 -- like the error message with the run time name.
20529
20530 else
20531 Partition_Elaboration_Policy := PEP;
20532
20533 if Partition_Elaboration_Policy_Sloc /= System_Location then
20534 Partition_Elaboration_Policy_Sloc := Loc;
20535 end if;
20536 end if;
20537 end PEP;
20538
20539 -------------
20540 -- Passive --
20541 -------------
20542
20543 -- pragma Passive [(PASSIVE_FORM)];
20544
20545 -- PASSIVE_FORM ::= Semaphore | No
20546
20547 when Pragma_Passive =>
20548 GNAT_Pragma;
20549
20550 if Nkind (Parent (N)) /= N_Task_Definition then
20551 Error_Pragma ("pragma% must be within task definition");
20552 end if;
20553
20554 if Arg_Count /= 0 then
20555 Check_Arg_Count (1);
20556 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
20557 end if;
20558
20559 ----------------------------------
20560 -- Preelaborable_Initialization --
20561 ----------------------------------
20562
20563 -- pragma Preelaborable_Initialization (DIRECT_NAME);
20564
20565 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
20566 Ent : Entity_Id;
20567
20568 begin
20569 Ada_2005_Pragma;
20570 Check_Arg_Count (1);
20571 Check_No_Identifiers;
20572 Check_Arg_Is_Identifier (Arg1);
20573 Check_Arg_Is_Local_Name (Arg1);
20574 Check_First_Subtype (Arg1);
20575 Ent := Entity (Get_Pragma_Arg (Arg1));
20576
20577 -- A pragma that applies to a Ghost entity becomes Ghost for the
20578 -- purposes of legality checks and removal of ignored Ghost code.
20579
20580 Mark_Ghost_Pragma (N, Ent);
20581
20582 -- The pragma may come from an aspect on a private declaration,
20583 -- even if the freeze point at which this is analyzed in the
20584 -- private part after the full view.
20585
20586 if Has_Private_Declaration (Ent)
20587 and then From_Aspect_Specification (N)
20588 then
20589 null;
20590
20591 -- Check appropriate type argument
20592
20593 elsif Is_Private_Type (Ent)
20594 or else Is_Protected_Type (Ent)
20595 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
20596
20597 -- AI05-0028: The pragma applies to all composite types. Note
20598 -- that we apply this binding interpretation to earlier versions
20599 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
20600 -- choice since there are other compilers that do the same.
20601
20602 or else Is_Composite_Type (Ent)
20603 then
20604 null;
20605
20606 else
20607 Error_Pragma_Arg
20608 ("pragma % can only be applied to private, formal derived, "
20609 & "protected, or composite type", Arg1);
20610 end if;
20611
20612 -- Give an error if the pragma is applied to a protected type that
20613 -- does not qualify (due to having entries, or due to components
20614 -- that do not qualify).
20615
20616 if Is_Protected_Type (Ent)
20617 and then not Has_Preelaborable_Initialization (Ent)
20618 then
20619 Error_Msg_N
20620 ("protected type & does not have preelaborable "
20621 & "initialization", Ent);
20622
20623 -- Otherwise mark the type as definitely having preelaborable
20624 -- initialization.
20625
20626 else
20627 Set_Known_To_Have_Preelab_Init (Ent);
20628 end if;
20629
20630 if Has_Pragma_Preelab_Init (Ent)
20631 and then Warn_On_Redundant_Constructs
20632 then
20633 Error_Pragma ("?r?duplicate pragma%!");
20634 else
20635 Set_Has_Pragma_Preelab_Init (Ent);
20636 end if;
20637 end Preelab_Init;
20638
20639 --------------------
20640 -- Persistent_BSS --
20641 --------------------
20642
20643 -- pragma Persistent_BSS [(object_NAME)];
20644
20645 when Pragma_Persistent_BSS => Persistent_BSS : declare
20646 Decl : Node_Id;
20647 Ent : Entity_Id;
20648 Prag : Node_Id;
20649
20650 begin
20651 GNAT_Pragma;
20652 Check_At_Most_N_Arguments (1);
20653
20654 -- Case of application to specific object (one argument)
20655
20656 if Arg_Count = 1 then
20657 Check_Arg_Is_Library_Level_Local_Name (Arg1);
20658
20659 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
20660 or else not
20661 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
20662 E_Constant)
20663 then
20664 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
20665 end if;
20666
20667 Ent := Entity (Get_Pragma_Arg (Arg1));
20668
20669 -- A pragma that applies to a Ghost entity becomes Ghost for
20670 -- the purposes of legality checks and removal of ignored Ghost
20671 -- code.
20672
20673 Mark_Ghost_Pragma (N, Ent);
20674
20675 -- Check for duplication before inserting in list of
20676 -- representation items.
20677
20678 Check_Duplicate_Pragma (Ent);
20679
20680 if Rep_Item_Too_Late (Ent, N) then
20681 return;
20682 end if;
20683
20684 Decl := Parent (Ent);
20685
20686 if Present (Expression (Decl)) then
20687 -- Variables in Persistent_BSS cannot be initialized, so
20688 -- turn off any initialization that might be caused by
20689 -- pragmas Initialize_Scalars or Normalize_Scalars.
20690
20691 if Kill_Range_Check (Expression (Decl)) then
20692 Prag :=
20693 Make_Pragma (Loc,
20694 Name_Suppress_Initialization,
20695 Pragma_Argument_Associations => New_List (
20696 Make_Pragma_Argument_Association (Loc,
20697 Expression => New_Occurrence_Of (Ent, Loc))));
20698 Insert_Before (N, Prag);
20699 Analyze (Prag);
20700
20701 else
20702 Error_Pragma_Arg
20703 ("object for pragma% cannot have initialization", Arg1);
20704 end if;
20705 end if;
20706
20707 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
20708 Error_Pragma_Arg
20709 ("object type for pragma% is not potentially persistent",
20710 Arg1);
20711 end if;
20712
20713 Prag :=
20714 Make_Linker_Section_Pragma
20715 (Ent, Loc, ".persistent.bss");
20716 Insert_After (N, Prag);
20717 Analyze (Prag);
20718
20719 -- Case of use as configuration pragma with no arguments
20720
20721 else
20722 Check_Valid_Configuration_Pragma;
20723 Persistent_BSS_Mode := True;
20724 end if;
20725 end Persistent_BSS;
20726
20727 --------------------
20728 -- Rename_Pragma --
20729 --------------------
20730
20731 -- pragma Rename_Pragma (
20732 -- [New_Name =>] IDENTIFIER,
20733 -- [Renamed =>] pragma_IDENTIFIER);
20734
20735 when Pragma_Rename_Pragma => Rename_Pragma : declare
20736 New_Name : constant Node_Id := Get_Pragma_Arg (Arg1);
20737 Old_Name : constant Node_Id := Get_Pragma_Arg (Arg2);
20738
20739 begin
20740 GNAT_Pragma;
20741 Check_Valid_Configuration_Pragma;
20742 Check_Arg_Count (2);
20743 Check_Optional_Identifier (Arg1, Name_New_Name);
20744 Check_Optional_Identifier (Arg2, Name_Renamed);
20745
20746 if Nkind (New_Name) /= N_Identifier then
20747 Error_Pragma_Arg ("identifier expected", Arg1);
20748 end if;
20749
20750 if Nkind (Old_Name) /= N_Identifier then
20751 Error_Pragma_Arg ("identifier expected", Arg2);
20752 end if;
20753
20754 -- The New_Name arg should not be an existing pragma (but we allow
20755 -- it; it's just a warning). The Old_Name arg must be an existing
20756 -- pragma.
20757
20758 if Is_Pragma_Name (Chars (New_Name)) then
20759 Error_Pragma_Arg ("??pragma is already defined", Arg1);
20760 end if;
20761
20762 if not Is_Pragma_Name (Chars (Old_Name)) then
20763 Error_Pragma_Arg ("existing pragma name expected", Arg1);
20764 end if;
20765
20766 Map_Pragma_Name (From => Chars (New_Name), To => Chars (Old_Name));
20767 end Rename_Pragma;
20768
20769 -------------
20770 -- Polling --
20771 -------------
20772
20773 -- pragma Polling (ON | OFF);
20774
20775 when Pragma_Polling =>
20776 GNAT_Pragma;
20777 Check_Arg_Count (1);
20778 Check_No_Identifiers;
20779 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
20780 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
20781
20782 -----------------------------------
20783 -- Post/Post_Class/Postcondition --
20784 -----------------------------------
20785
20786 -- pragma Post (Boolean_EXPRESSION);
20787 -- pragma Post_Class (Boolean_EXPRESSION);
20788 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
20789 -- [,[Message =>] String_EXPRESSION]);
20790
20791 -- Characteristics:
20792
20793 -- * Analysis - The annotation undergoes initial checks to verify
20794 -- the legal placement and context. Secondary checks preanalyze the
20795 -- expression in:
20796
20797 -- Analyze_Pre_Post_Condition_In_Decl_Part
20798
20799 -- * Expansion - The annotation is expanded during the expansion of
20800 -- the related subprogram [body] contract as performed in:
20801
20802 -- Expand_Subprogram_Contract
20803
20804 -- * Template - The annotation utilizes the generic template of the
20805 -- related subprogram [body] when it is:
20806
20807 -- aspect on subprogram declaration
20808 -- aspect on stand-alone subprogram body
20809 -- pragma on stand-alone subprogram body
20810
20811 -- The annotation must prepare its own template when it is:
20812
20813 -- pragma on subprogram declaration
20814
20815 -- * Globals - Capture of global references must occur after full
20816 -- analysis.
20817
20818 -- * Instance - The annotation is instantiated automatically when
20819 -- the related generic subprogram [body] is instantiated except for
20820 -- the "pragma on subprogram declaration" case. In that scenario
20821 -- the annotation must instantiate itself.
20822
20823 when Pragma_Post
20824 | Pragma_Post_Class
20825 | Pragma_Postcondition
20826 =>
20827 Analyze_Pre_Post_Condition;
20828
20829 --------------------------------
20830 -- Pre/Pre_Class/Precondition --
20831 --------------------------------
20832
20833 -- pragma Pre (Boolean_EXPRESSION);
20834 -- pragma Pre_Class (Boolean_EXPRESSION);
20835 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
20836 -- [,[Message =>] String_EXPRESSION]);
20837
20838 -- Characteristics:
20839
20840 -- * Analysis - The annotation undergoes initial checks to verify
20841 -- the legal placement and context. Secondary checks preanalyze the
20842 -- expression in:
20843
20844 -- Analyze_Pre_Post_Condition_In_Decl_Part
20845
20846 -- * Expansion - The annotation is expanded during the expansion of
20847 -- the related subprogram [body] contract as performed in:
20848
20849 -- Expand_Subprogram_Contract
20850
20851 -- * Template - The annotation utilizes the generic template of the
20852 -- related subprogram [body] when it is:
20853
20854 -- aspect on subprogram declaration
20855 -- aspect on stand-alone subprogram body
20856 -- pragma on stand-alone subprogram body
20857
20858 -- The annotation must prepare its own template when it is:
20859
20860 -- pragma on subprogram declaration
20861
20862 -- * Globals - Capture of global references must occur after full
20863 -- analysis.
20864
20865 -- * Instance - The annotation is instantiated automatically when
20866 -- the related generic subprogram [body] is instantiated except for
20867 -- the "pragma on subprogram declaration" case. In that scenario
20868 -- the annotation must instantiate itself.
20869
20870 when Pragma_Pre
20871 | Pragma_Pre_Class
20872 | Pragma_Precondition
20873 =>
20874 Analyze_Pre_Post_Condition;
20875
20876 ---------------
20877 -- Predicate --
20878 ---------------
20879
20880 -- pragma Predicate
20881 -- ([Entity =>] type_LOCAL_NAME,
20882 -- [Check =>] boolean_EXPRESSION);
20883
20884 when Pragma_Predicate => Predicate : declare
20885 Discard : Boolean;
20886 Typ : Entity_Id;
20887 Type_Id : Node_Id;
20888
20889 begin
20890 GNAT_Pragma;
20891 Check_Arg_Count (2);
20892 Check_Optional_Identifier (Arg1, Name_Entity);
20893 Check_Optional_Identifier (Arg2, Name_Check);
20894
20895 Check_Arg_Is_Local_Name (Arg1);
20896
20897 Type_Id := Get_Pragma_Arg (Arg1);
20898 Find_Type (Type_Id);
20899 Typ := Entity (Type_Id);
20900
20901 if Typ = Any_Type then
20902 return;
20903 end if;
20904
20905 -- A pragma that applies to a Ghost entity becomes Ghost for the
20906 -- purposes of legality checks and removal of ignored Ghost code.
20907
20908 Mark_Ghost_Pragma (N, Typ);
20909
20910 -- The remaining processing is simply to link the pragma on to
20911 -- the rep item chain, for processing when the type is frozen.
20912 -- This is accomplished by a call to Rep_Item_Too_Late. We also
20913 -- mark the type as having predicates.
20914
20915 -- If the current policy for predicate checking is Ignore mark the
20916 -- subtype accordingly. In the case of predicates we consider them
20917 -- enabled unless Ignore is specified (either directly or with a
20918 -- general Assertion_Policy pragma) to preserve existing warnings.
20919
20920 Set_Has_Predicates (Typ);
20921
20922 -- Indicate that the pragma must be processed at the point the
20923 -- type is frozen, as is done for the corresponding aspect.
20924
20925 Set_Has_Delayed_Aspects (Typ);
20926 Set_Has_Delayed_Freeze (Typ);
20927
20928 Set_Predicates_Ignored (Typ,
20929 Present (Check_Policy_List)
20930 and then
20931 Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore);
20932 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
20933 end Predicate;
20934
20935 -----------------------
20936 -- Predicate_Failure --
20937 -----------------------
20938
20939 -- pragma Predicate_Failure
20940 -- ([Entity =>] type_LOCAL_NAME,
20941 -- [Message =>] string_EXPRESSION);
20942
20943 when Pragma_Predicate_Failure => Predicate_Failure : declare
20944 Discard : Boolean;
20945 Typ : Entity_Id;
20946 Type_Id : Node_Id;
20947
20948 begin
20949 GNAT_Pragma;
20950 Check_Arg_Count (2);
20951 Check_Optional_Identifier (Arg1, Name_Entity);
20952 Check_Optional_Identifier (Arg2, Name_Message);
20953
20954 Check_Arg_Is_Local_Name (Arg1);
20955
20956 Type_Id := Get_Pragma_Arg (Arg1);
20957 Find_Type (Type_Id);
20958 Typ := Entity (Type_Id);
20959
20960 if Typ = Any_Type then
20961 return;
20962 end if;
20963
20964 -- A pragma that applies to a Ghost entity becomes Ghost for the
20965 -- purposes of legality checks and removal of ignored Ghost code.
20966
20967 Mark_Ghost_Pragma (N, Typ);
20968
20969 -- The remaining processing is simply to link the pragma on to
20970 -- the rep item chain, for processing when the type is frozen.
20971 -- This is accomplished by a call to Rep_Item_Too_Late.
20972
20973 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
20974 end Predicate_Failure;
20975
20976 ------------------
20977 -- Preelaborate --
20978 ------------------
20979
20980 -- pragma Preelaborate [(library_unit_NAME)];
20981
20982 -- Set the flag Is_Preelaborated of program unit name entity
20983
20984 when Pragma_Preelaborate => Preelaborate : declare
20985 Pa : constant Node_Id := Parent (N);
20986 Pk : constant Node_Kind := Nkind (Pa);
20987 Ent : Entity_Id;
20988
20989 begin
20990 Check_Ada_83_Warning;
20991 Check_Valid_Library_Unit_Pragma;
20992
20993 if Nkind (N) = N_Null_Statement then
20994 return;
20995 end if;
20996
20997 Ent := Find_Lib_Unit_Name;
20998
20999 -- A pragma that applies to a Ghost entity becomes Ghost for the
21000 -- purposes of legality checks and removal of ignored Ghost code.
21001
21002 Mark_Ghost_Pragma (N, Ent);
21003 Check_Duplicate_Pragma (Ent);
21004
21005 -- This filters out pragmas inside generic parents that show up
21006 -- inside instantiations. Pragmas that come from aspects in the
21007 -- unit are not ignored.
21008
21009 if Present (Ent) then
21010 if Pk = N_Package_Specification
21011 and then Present (Generic_Parent (Pa))
21012 and then not From_Aspect_Specification (N)
21013 then
21014 null;
21015
21016 else
21017 if not Debug_Flag_U then
21018 Set_Is_Preelaborated (Ent);
21019
21020 if Legacy_Elaboration_Checks then
21021 Set_Suppress_Elaboration_Warnings (Ent);
21022 end if;
21023 end if;
21024 end if;
21025 end if;
21026 end Preelaborate;
21027
21028 -------------------------------
21029 -- Prefix_Exception_Messages --
21030 -------------------------------
21031
21032 -- pragma Prefix_Exception_Messages;
21033
21034 when Pragma_Prefix_Exception_Messages =>
21035 GNAT_Pragma;
21036 Check_Valid_Configuration_Pragma;
21037 Check_Arg_Count (0);
21038 Prefix_Exception_Messages := True;
21039
21040 --------------
21041 -- Priority --
21042 --------------
21043
21044 -- pragma Priority (EXPRESSION);
21045
21046 when Pragma_Priority => Priority : declare
21047 P : constant Node_Id := Parent (N);
21048 Arg : Node_Id;
21049 Ent : Entity_Id;
21050
21051 begin
21052 Check_No_Identifiers;
21053 Check_Arg_Count (1);
21054
21055 -- Subprogram case
21056
21057 if Nkind (P) = N_Subprogram_Body then
21058 Check_In_Main_Program;
21059
21060 Ent := Defining_Unit_Name (Specification (P));
21061
21062 if Nkind (Ent) = N_Defining_Program_Unit_Name then
21063 Ent := Defining_Identifier (Ent);
21064 end if;
21065
21066 Arg := Get_Pragma_Arg (Arg1);
21067 Analyze_And_Resolve (Arg, Standard_Integer);
21068
21069 -- Must be static
21070
21071 if not Is_OK_Static_Expression (Arg) then
21072 Flag_Non_Static_Expr
21073 ("main subprogram priority is not static!", Arg);
21074 raise Pragma_Exit;
21075
21076 -- If constraint error, then we already signalled an error
21077
21078 elsif Raises_Constraint_Error (Arg) then
21079 null;
21080
21081 -- Otherwise check in range except if Relaxed_RM_Semantics
21082 -- where we ignore the value if out of range.
21083
21084 else
21085 if not Relaxed_RM_Semantics
21086 and then not Is_In_Range (Arg, RTE (RE_Priority))
21087 then
21088 Error_Pragma_Arg
21089 ("main subprogram priority is out of range", Arg1);
21090 else
21091 Set_Main_Priority
21092 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
21093 end if;
21094 end if;
21095
21096 -- Load an arbitrary entity from System.Tasking.Stages or
21097 -- System.Tasking.Restricted.Stages (depending on the
21098 -- supported profile) to make sure that one of these packages
21099 -- is implicitly with'ed, since we need to have the tasking
21100 -- run time active for the pragma Priority to have any effect.
21101 -- Previously we with'ed the package System.Tasking, but this
21102 -- package does not trigger the required initialization of the
21103 -- run-time library.
21104
21105 declare
21106 Discard : Entity_Id;
21107 pragma Warnings (Off, Discard);
21108 begin
21109 if Restricted_Profile then
21110 Discard := RTE (RE_Activate_Restricted_Tasks);
21111 else
21112 Discard := RTE (RE_Activate_Tasks);
21113 end if;
21114 end;
21115
21116 -- Task or Protected, must be of type Integer
21117
21118 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
21119 Arg := Get_Pragma_Arg (Arg1);
21120 Ent := Defining_Identifier (Parent (P));
21121
21122 -- The expression must be analyzed in the special manner
21123 -- described in "Handling of Default and Per-Object
21124 -- Expressions" in sem.ads.
21125
21126 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
21127
21128 if not Is_OK_Static_Expression (Arg) then
21129 Check_Restriction (Static_Priorities, Arg);
21130 end if;
21131
21132 -- Anything else is incorrect
21133
21134 else
21135 Pragma_Misplaced;
21136 end if;
21137
21138 -- Check duplicate pragma before we chain the pragma in the Rep
21139 -- Item chain of Ent.
21140
21141 Check_Duplicate_Pragma (Ent);
21142 Record_Rep_Item (Ent, N);
21143 end Priority;
21144
21145 -----------------------------------
21146 -- Priority_Specific_Dispatching --
21147 -----------------------------------
21148
21149 -- pragma Priority_Specific_Dispatching (
21150 -- policy_IDENTIFIER,
21151 -- first_priority_EXPRESSION,
21152 -- last_priority_EXPRESSION);
21153
21154 when Pragma_Priority_Specific_Dispatching =>
21155 Priority_Specific_Dispatching : declare
21156 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
21157 -- This is the entity System.Any_Priority;
21158
21159 DP : Character;
21160 Lower_Bound : Node_Id;
21161 Upper_Bound : Node_Id;
21162 Lower_Val : Uint;
21163 Upper_Val : Uint;
21164
21165 begin
21166 Ada_2005_Pragma;
21167 Check_Arg_Count (3);
21168 Check_No_Identifiers;
21169 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
21170 Check_Valid_Configuration_Pragma;
21171 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21172 DP := Fold_Upper (Name_Buffer (1));
21173
21174 Lower_Bound := Get_Pragma_Arg (Arg2);
21175 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
21176 Lower_Val := Expr_Value (Lower_Bound);
21177
21178 Upper_Bound := Get_Pragma_Arg (Arg3);
21179 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
21180 Upper_Val := Expr_Value (Upper_Bound);
21181
21182 -- It is not allowed to use Task_Dispatching_Policy and
21183 -- Priority_Specific_Dispatching in the same partition.
21184
21185 if Task_Dispatching_Policy /= ' ' then
21186 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21187 Error_Pragma
21188 ("pragma% incompatible with Task_Dispatching_Policy#");
21189
21190 -- Check lower bound in range
21191
21192 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21193 or else
21194 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
21195 then
21196 Error_Pragma_Arg
21197 ("first_priority is out of range", Arg2);
21198
21199 -- Check upper bound in range
21200
21201 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21202 or else
21203 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
21204 then
21205 Error_Pragma_Arg
21206 ("last_priority is out of range", Arg3);
21207
21208 -- Check that the priority range is valid
21209
21210 elsif Lower_Val > Upper_Val then
21211 Error_Pragma
21212 ("last_priority_expression must be greater than or equal to "
21213 & "first_priority_expression");
21214
21215 -- Store the new policy, but always preserve System_Location since
21216 -- we like the error message with the run-time name.
21217
21218 else
21219 -- Check overlapping in the priority ranges specified in other
21220 -- Priority_Specific_Dispatching pragmas within the same
21221 -- partition. We can only check those we know about.
21222
21223 for J in
21224 Specific_Dispatching.First .. Specific_Dispatching.Last
21225 loop
21226 if Specific_Dispatching.Table (J).First_Priority in
21227 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21228 or else Specific_Dispatching.Table (J).Last_Priority in
21229 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21230 then
21231 Error_Msg_Sloc :=
21232 Specific_Dispatching.Table (J).Pragma_Loc;
21233 Error_Pragma
21234 ("priority range overlaps with "
21235 & "Priority_Specific_Dispatching#");
21236 end if;
21237 end loop;
21238
21239 -- The use of Priority_Specific_Dispatching is incompatible
21240 -- with Task_Dispatching_Policy.
21241
21242 if Task_Dispatching_Policy /= ' ' then
21243 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21244 Error_Pragma
21245 ("Priority_Specific_Dispatching incompatible "
21246 & "with Task_Dispatching_Policy#");
21247 end if;
21248
21249 -- The use of Priority_Specific_Dispatching forces ceiling
21250 -- locking policy.
21251
21252 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
21253 Error_Msg_Sloc := Locking_Policy_Sloc;
21254 Error_Pragma
21255 ("Priority_Specific_Dispatching incompatible "
21256 & "with Locking_Policy#");
21257
21258 -- Set the Ceiling_Locking policy, but preserve System_Location
21259 -- since we like the error message with the run time name.
21260
21261 else
21262 Locking_Policy := 'C';
21263
21264 if Locking_Policy_Sloc /= System_Location then
21265 Locking_Policy_Sloc := Loc;
21266 end if;
21267 end if;
21268
21269 -- Add entry in the table
21270
21271 Specific_Dispatching.Append
21272 ((Dispatching_Policy => DP,
21273 First_Priority => UI_To_Int (Lower_Val),
21274 Last_Priority => UI_To_Int (Upper_Val),
21275 Pragma_Loc => Loc));
21276 end if;
21277 end Priority_Specific_Dispatching;
21278
21279 -------------
21280 -- Profile --
21281 -------------
21282
21283 -- pragma Profile (profile_IDENTIFIER);
21284
21285 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
21286
21287 when Pragma_Profile =>
21288 Ada_2005_Pragma;
21289 Check_Arg_Count (1);
21290 Check_Valid_Configuration_Pragma;
21291 Check_No_Identifiers;
21292
21293 declare
21294 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21295
21296 begin
21297 if Chars (Argx) = Name_Ravenscar then
21298 Set_Ravenscar_Profile (Ravenscar, N);
21299
21300 elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then
21301 Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N);
21302
21303 elsif Chars (Argx) = Name_Gnat_Ravenscar_EDF then
21304 Set_Ravenscar_Profile (GNAT_Ravenscar_EDF, N);
21305
21306 elsif Chars (Argx) = Name_Restricted then
21307 Set_Profile_Restrictions
21308 (Restricted,
21309 N, Warn => Treat_Restrictions_As_Warnings);
21310
21311 elsif Chars (Argx) = Name_Rational then
21312 Set_Rational_Profile;
21313
21314 elsif Chars (Argx) = Name_No_Implementation_Extensions then
21315 Set_Profile_Restrictions
21316 (No_Implementation_Extensions,
21317 N, Warn => Treat_Restrictions_As_Warnings);
21318
21319 else
21320 Error_Pragma_Arg ("& is not a valid profile", Argx);
21321 end if;
21322 end;
21323
21324 ----------------------
21325 -- Profile_Warnings --
21326 ----------------------
21327
21328 -- pragma Profile_Warnings (profile_IDENTIFIER);
21329
21330 -- profile_IDENTIFIER => Restricted | Ravenscar
21331
21332 when Pragma_Profile_Warnings =>
21333 GNAT_Pragma;
21334 Check_Arg_Count (1);
21335 Check_Valid_Configuration_Pragma;
21336 Check_No_Identifiers;
21337
21338 declare
21339 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21340
21341 begin
21342 if Chars (Argx) = Name_Ravenscar then
21343 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
21344
21345 elsif Chars (Argx) = Name_Restricted then
21346 Set_Profile_Restrictions (Restricted, N, Warn => True);
21347
21348 elsif Chars (Argx) = Name_No_Implementation_Extensions then
21349 Set_Profile_Restrictions
21350 (No_Implementation_Extensions, N, Warn => True);
21351
21352 else
21353 Error_Pragma_Arg ("& is not a valid profile", Argx);
21354 end if;
21355 end;
21356
21357 --------------------------
21358 -- Propagate_Exceptions --
21359 --------------------------
21360
21361 -- pragma Propagate_Exceptions;
21362
21363 -- Note: this pragma is obsolete and has no effect
21364
21365 when Pragma_Propagate_Exceptions =>
21366 GNAT_Pragma;
21367 Check_Arg_Count (0);
21368
21369 if Warn_On_Obsolescent_Feature then
21370 Error_Msg_N
21371 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
21372 "and has no effect?j?", N);
21373 end if;
21374
21375 -----------------------------
21376 -- Provide_Shift_Operators --
21377 -----------------------------
21378
21379 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
21380
21381 when Pragma_Provide_Shift_Operators =>
21382 Provide_Shift_Operators : declare
21383 Ent : Entity_Id;
21384
21385 procedure Declare_Shift_Operator (Nam : Name_Id);
21386 -- Insert declaration and pragma Instrinsic for named shift op
21387
21388 ----------------------------
21389 -- Declare_Shift_Operator --
21390 ----------------------------
21391
21392 procedure Declare_Shift_Operator (Nam : Name_Id) is
21393 Func : Node_Id;
21394 Import : Node_Id;
21395
21396 begin
21397 Func :=
21398 Make_Subprogram_Declaration (Loc,
21399 Make_Function_Specification (Loc,
21400 Defining_Unit_Name =>
21401 Make_Defining_Identifier (Loc, Chars => Nam),
21402
21403 Result_Definition =>
21404 Make_Identifier (Loc, Chars => Chars (Ent)),
21405
21406 Parameter_Specifications => New_List (
21407 Make_Parameter_Specification (Loc,
21408 Defining_Identifier =>
21409 Make_Defining_Identifier (Loc, Name_Value),
21410 Parameter_Type =>
21411 Make_Identifier (Loc, Chars => Chars (Ent))),
21412
21413 Make_Parameter_Specification (Loc,
21414 Defining_Identifier =>
21415 Make_Defining_Identifier (Loc, Name_Amount),
21416 Parameter_Type =>
21417 New_Occurrence_Of (Standard_Natural, Loc)))));
21418
21419 Import :=
21420 Make_Pragma (Loc,
21421 Chars => Name_Import,
21422 Pragma_Argument_Associations => New_List (
21423 Make_Pragma_Argument_Association (Loc,
21424 Expression => Make_Identifier (Loc, Name_Intrinsic)),
21425 Make_Pragma_Argument_Association (Loc,
21426 Expression => Make_Identifier (Loc, Nam))));
21427
21428 Insert_After (N, Import);
21429 Insert_After (N, Func);
21430 end Declare_Shift_Operator;
21431
21432 -- Start of processing for Provide_Shift_Operators
21433
21434 begin
21435 GNAT_Pragma;
21436 Check_Arg_Count (1);
21437 Check_Arg_Is_Local_Name (Arg1);
21438
21439 Arg1 := Get_Pragma_Arg (Arg1);
21440
21441 -- We must have an entity name
21442
21443 if not Is_Entity_Name (Arg1) then
21444 Error_Pragma_Arg
21445 ("pragma % must apply to integer first subtype", Arg1);
21446 end if;
21447
21448 -- If no Entity, means there was a prior error so ignore
21449
21450 if Present (Entity (Arg1)) then
21451 Ent := Entity (Arg1);
21452
21453 -- Apply error checks
21454
21455 if not Is_First_Subtype (Ent) then
21456 Error_Pragma_Arg
21457 ("cannot apply pragma %",
21458 "\& is not a first subtype",
21459 Arg1);
21460
21461 elsif not Is_Integer_Type (Ent) then
21462 Error_Pragma_Arg
21463 ("cannot apply pragma %",
21464 "\& is not an integer type",
21465 Arg1);
21466
21467 elsif Has_Shift_Operator (Ent) then
21468 Error_Pragma_Arg
21469 ("cannot apply pragma %",
21470 "\& already has declared shift operators",
21471 Arg1);
21472
21473 elsif Is_Frozen (Ent) then
21474 Error_Pragma_Arg
21475 ("pragma % appears too late",
21476 "\& is already frozen",
21477 Arg1);
21478 end if;
21479
21480 -- Now declare the operators. We do this during analysis rather
21481 -- than expansion, since we want the operators available if we
21482 -- are operating in -gnatc mode.
21483
21484 Declare_Shift_Operator (Name_Rotate_Left);
21485 Declare_Shift_Operator (Name_Rotate_Right);
21486 Declare_Shift_Operator (Name_Shift_Left);
21487 Declare_Shift_Operator (Name_Shift_Right);
21488 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
21489 end if;
21490 end Provide_Shift_Operators;
21491
21492 ------------------
21493 -- Psect_Object --
21494 ------------------
21495
21496 -- pragma Psect_Object (
21497 -- [Internal =>] LOCAL_NAME,
21498 -- [, [External =>] EXTERNAL_SYMBOL]
21499 -- [, [Size =>] EXTERNAL_SYMBOL]);
21500
21501 when Pragma_Common_Object
21502 | Pragma_Psect_Object
21503 =>
21504 Psect_Object : declare
21505 Args : Args_List (1 .. 3);
21506 Names : constant Name_List (1 .. 3) := (
21507 Name_Internal,
21508 Name_External,
21509 Name_Size);
21510
21511 Internal : Node_Id renames Args (1);
21512 External : Node_Id renames Args (2);
21513 Size : Node_Id renames Args (3);
21514
21515 Def_Id : Entity_Id;
21516
21517 procedure Check_Arg (Arg : Node_Id);
21518 -- Checks that argument is either a string literal or an
21519 -- identifier, and posts error message if not.
21520
21521 ---------------
21522 -- Check_Arg --
21523 ---------------
21524
21525 procedure Check_Arg (Arg : Node_Id) is
21526 begin
21527 if not Nkind_In (Original_Node (Arg),
21528 N_String_Literal,
21529 N_Identifier)
21530 then
21531 Error_Pragma_Arg
21532 ("inappropriate argument for pragma %", Arg);
21533 end if;
21534 end Check_Arg;
21535
21536 -- Start of processing for Common_Object/Psect_Object
21537
21538 begin
21539 GNAT_Pragma;
21540 Gather_Associations (Names, Args);
21541 Process_Extended_Import_Export_Internal_Arg (Internal);
21542
21543 Def_Id := Entity (Internal);
21544
21545 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
21546 Error_Pragma_Arg
21547 ("pragma% must designate an object", Internal);
21548 end if;
21549
21550 Check_Arg (Internal);
21551
21552 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
21553 Error_Pragma_Arg
21554 ("cannot use pragma% for imported/exported object",
21555 Internal);
21556 end if;
21557
21558 if Is_Concurrent_Type (Etype (Internal)) then
21559 Error_Pragma_Arg
21560 ("cannot specify pragma % for task/protected object",
21561 Internal);
21562 end if;
21563
21564 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
21565 or else
21566 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
21567 then
21568 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
21569 end if;
21570
21571 if Ekind (Def_Id) = E_Constant then
21572 Error_Pragma_Arg
21573 ("cannot specify pragma % for a constant", Internal);
21574 end if;
21575
21576 if Is_Record_Type (Etype (Internal)) then
21577 declare
21578 Ent : Entity_Id;
21579 Decl : Entity_Id;
21580
21581 begin
21582 Ent := First_Entity (Etype (Internal));
21583 while Present (Ent) loop
21584 Decl := Declaration_Node (Ent);
21585
21586 if Ekind (Ent) = E_Component
21587 and then Nkind (Decl) = N_Component_Declaration
21588 and then Present (Expression (Decl))
21589 and then Warn_On_Export_Import
21590 then
21591 Error_Msg_N
21592 ("?x?object for pragma % has defaults", Internal);
21593 exit;
21594
21595 else
21596 Next_Entity (Ent);
21597 end if;
21598 end loop;
21599 end;
21600 end if;
21601
21602 if Present (Size) then
21603 Check_Arg (Size);
21604 end if;
21605
21606 if Present (External) then
21607 Check_Arg_Is_External_Name (External);
21608 end if;
21609
21610 -- If all error tests pass, link pragma on to the rep item chain
21611
21612 Record_Rep_Item (Def_Id, N);
21613 end Psect_Object;
21614
21615 ----------
21616 -- Pure --
21617 ----------
21618
21619 -- pragma Pure [(library_unit_NAME)];
21620
21621 when Pragma_Pure => Pure : declare
21622 Ent : Entity_Id;
21623
21624 begin
21625 Check_Ada_83_Warning;
21626
21627 -- If the pragma comes from a subprogram instantiation, nothing to
21628 -- check, this can happen at any level of nesting.
21629
21630 if Is_Wrapper_Package (Current_Scope) then
21631 return;
21632 else
21633 Check_Valid_Library_Unit_Pragma;
21634 end if;
21635
21636 if Nkind (N) = N_Null_Statement then
21637 return;
21638 end if;
21639
21640 Ent := Find_Lib_Unit_Name;
21641
21642 -- A pragma that applies to a Ghost entity becomes Ghost for the
21643 -- purposes of legality checks and removal of ignored Ghost code.
21644
21645 Mark_Ghost_Pragma (N, Ent);
21646
21647 if not Debug_Flag_U then
21648 Set_Is_Pure (Ent);
21649 Set_Has_Pragma_Pure (Ent);
21650
21651 if Legacy_Elaboration_Checks then
21652 Set_Suppress_Elaboration_Warnings (Ent);
21653 end if;
21654 end if;
21655 end Pure;
21656
21657 -------------------
21658 -- Pure_Function --
21659 -------------------
21660
21661 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
21662
21663 when Pragma_Pure_Function => Pure_Function : declare
21664 Def_Id : Entity_Id;
21665 E : Entity_Id;
21666 E_Id : Node_Id;
21667 Effective : Boolean := False;
21668 Orig_Def : Entity_Id;
21669 Same_Decl : Boolean := False;
21670
21671 begin
21672 GNAT_Pragma;
21673 Check_Arg_Count (1);
21674 Check_Optional_Identifier (Arg1, Name_Entity);
21675 Check_Arg_Is_Local_Name (Arg1);
21676 E_Id := Get_Pragma_Arg (Arg1);
21677
21678 if Etype (E_Id) = Any_Type then
21679 return;
21680 end if;
21681
21682 -- Loop through homonyms (overloadings) of referenced entity
21683
21684 E := Entity (E_Id);
21685
21686 -- A pragma that applies to a Ghost entity becomes Ghost for the
21687 -- purposes of legality checks and removal of ignored Ghost code.
21688
21689 Mark_Ghost_Pragma (N, E);
21690
21691 if Present (E) then
21692 loop
21693 Def_Id := Get_Base_Subprogram (E);
21694
21695 if not Ekind_In (Def_Id, E_Function,
21696 E_Generic_Function,
21697 E_Operator)
21698 then
21699 Error_Pragma_Arg
21700 ("pragma% requires a function name", Arg1);
21701 end if;
21702
21703 -- When we have a generic function we must jump up a level
21704 -- to the declaration of the wrapper package itself.
21705
21706 Orig_Def := Def_Id;
21707
21708 if Is_Generic_Instance (Def_Id) then
21709 while Nkind (Orig_Def) /= N_Package_Declaration loop
21710 Orig_Def := Parent (Orig_Def);
21711 end loop;
21712 end if;
21713
21714 if In_Same_Declarative_Part (Parent (N), Orig_Def) then
21715 Same_Decl := True;
21716 Set_Is_Pure (Def_Id);
21717
21718 if not Has_Pragma_Pure_Function (Def_Id) then
21719 Set_Has_Pragma_Pure_Function (Def_Id);
21720 Effective := True;
21721 end if;
21722 end if;
21723
21724 exit when From_Aspect_Specification (N);
21725 E := Homonym (E);
21726 exit when No (E) or else Scope (E) /= Current_Scope;
21727 end loop;
21728
21729 if not Effective
21730 and then Warn_On_Redundant_Constructs
21731 then
21732 Error_Msg_NE
21733 ("pragma Pure_Function on& is redundant?r?",
21734 N, Entity (E_Id));
21735
21736 elsif not Same_Decl then
21737 Error_Pragma_Arg
21738 ("pragma% argument must be in same declarative part",
21739 Arg1);
21740 end if;
21741 end if;
21742 end Pure_Function;
21743
21744 --------------------
21745 -- Queuing_Policy --
21746 --------------------
21747
21748 -- pragma Queuing_Policy (policy_IDENTIFIER);
21749
21750 when Pragma_Queuing_Policy => declare
21751 QP : Character;
21752
21753 begin
21754 Check_Ada_83_Warning;
21755 Check_Arg_Count (1);
21756 Check_No_Identifiers;
21757 Check_Arg_Is_Queuing_Policy (Arg1);
21758 Check_Valid_Configuration_Pragma;
21759 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21760 QP := Fold_Upper (Name_Buffer (1));
21761
21762 if Queuing_Policy /= ' '
21763 and then Queuing_Policy /= QP
21764 then
21765 Error_Msg_Sloc := Queuing_Policy_Sloc;
21766 Error_Pragma ("queuing policy incompatible with policy#");
21767
21768 -- Set new policy, but always preserve System_Location since we
21769 -- like the error message with the run time name.
21770
21771 else
21772 Queuing_Policy := QP;
21773
21774 if Queuing_Policy_Sloc /= System_Location then
21775 Queuing_Policy_Sloc := Loc;
21776 end if;
21777 end if;
21778 end;
21779
21780 --------------
21781 -- Rational --
21782 --------------
21783
21784 -- pragma Rational, for compatibility with foreign compiler
21785
21786 when Pragma_Rational =>
21787 Set_Rational_Profile;
21788
21789 ---------------------
21790 -- Refined_Depends --
21791 ---------------------
21792
21793 -- pragma Refined_Depends (DEPENDENCY_RELATION);
21794
21795 -- DEPENDENCY_RELATION ::=
21796 -- null
21797 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
21798
21799 -- DEPENDENCY_CLAUSE ::=
21800 -- OUTPUT_LIST =>[+] INPUT_LIST
21801 -- | NULL_DEPENDENCY_CLAUSE
21802
21803 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
21804
21805 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
21806
21807 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
21808
21809 -- OUTPUT ::= NAME | FUNCTION_RESULT
21810 -- INPUT ::= NAME
21811
21812 -- where FUNCTION_RESULT is a function Result attribute_reference
21813
21814 -- Characteristics:
21815
21816 -- * Analysis - The annotation undergoes initial checks to verify
21817 -- the legal placement and context. Secondary checks fully analyze
21818 -- the dependency clauses/global list in:
21819
21820 -- Analyze_Refined_Depends_In_Decl_Part
21821
21822 -- * Expansion - None.
21823
21824 -- * Template - The annotation utilizes the generic template of the
21825 -- related subprogram body.
21826
21827 -- * Globals - Capture of global references must occur after full
21828 -- analysis.
21829
21830 -- * Instance - The annotation is instantiated automatically when
21831 -- the related generic subprogram body is instantiated.
21832
21833 when Pragma_Refined_Depends => Refined_Depends : declare
21834 Body_Id : Entity_Id;
21835 Legal : Boolean;
21836 Spec_Id : Entity_Id;
21837
21838 begin
21839 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
21840
21841 if Legal then
21842
21843 -- Chain the pragma on the contract for further processing by
21844 -- Analyze_Refined_Depends_In_Decl_Part.
21845
21846 Add_Contract_Item (N, Body_Id);
21847
21848 -- The legality checks of pragmas Refined_Depends and
21849 -- Refined_Global are affected by the SPARK mode in effect and
21850 -- the volatility of the context. In addition these two pragmas
21851 -- are subject to an inherent order:
21852
21853 -- 1) Refined_Global
21854 -- 2) Refined_Depends
21855
21856 -- Analyze all these pragmas in the order outlined above
21857
21858 Analyze_If_Present (Pragma_SPARK_Mode);
21859 Analyze_If_Present (Pragma_Volatile_Function);
21860 Analyze_If_Present (Pragma_Refined_Global);
21861 Analyze_Refined_Depends_In_Decl_Part (N);
21862 end if;
21863 end Refined_Depends;
21864
21865 --------------------
21866 -- Refined_Global --
21867 --------------------
21868
21869 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
21870
21871 -- GLOBAL_SPECIFICATION ::=
21872 -- null
21873 -- | (GLOBAL_LIST)
21874 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
21875
21876 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
21877
21878 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
21879 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
21880 -- GLOBAL_ITEM ::= NAME
21881
21882 -- Characteristics:
21883
21884 -- * Analysis - The annotation undergoes initial checks to verify
21885 -- the legal placement and context. Secondary checks fully analyze
21886 -- the dependency clauses/global list in:
21887
21888 -- Analyze_Refined_Global_In_Decl_Part
21889
21890 -- * Expansion - None.
21891
21892 -- * Template - The annotation utilizes the generic template of the
21893 -- related subprogram body.
21894
21895 -- * Globals - Capture of global references must occur after full
21896 -- analysis.
21897
21898 -- * Instance - The annotation is instantiated automatically when
21899 -- the related generic subprogram body is instantiated.
21900
21901 when Pragma_Refined_Global => Refined_Global : declare
21902 Body_Id : Entity_Id;
21903 Legal : Boolean;
21904 Spec_Id : Entity_Id;
21905
21906 begin
21907 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
21908
21909 if Legal then
21910
21911 -- Chain the pragma on the contract for further processing by
21912 -- Analyze_Refined_Global_In_Decl_Part.
21913
21914 Add_Contract_Item (N, Body_Id);
21915
21916 -- The legality checks of pragmas Refined_Depends and
21917 -- Refined_Global are affected by the SPARK mode in effect and
21918 -- the volatility of the context. In addition these two pragmas
21919 -- are subject to an inherent order:
21920
21921 -- 1) Refined_Global
21922 -- 2) Refined_Depends
21923
21924 -- Analyze all these pragmas in the order outlined above
21925
21926 Analyze_If_Present (Pragma_SPARK_Mode);
21927 Analyze_If_Present (Pragma_Volatile_Function);
21928 Analyze_Refined_Global_In_Decl_Part (N);
21929 Analyze_If_Present (Pragma_Refined_Depends);
21930 end if;
21931 end Refined_Global;
21932
21933 ------------------
21934 -- Refined_Post --
21935 ------------------
21936
21937 -- pragma Refined_Post (boolean_EXPRESSION);
21938
21939 -- Characteristics:
21940
21941 -- * Analysis - The annotation is fully analyzed immediately upon
21942 -- elaboration as it cannot forward reference entities.
21943
21944 -- * Expansion - The annotation is expanded during the expansion of
21945 -- the related subprogram body contract as performed in:
21946
21947 -- Expand_Subprogram_Contract
21948
21949 -- * Template - The annotation utilizes the generic template of the
21950 -- related subprogram body.
21951
21952 -- * Globals - Capture of global references must occur after full
21953 -- analysis.
21954
21955 -- * Instance - The annotation is instantiated automatically when
21956 -- the related generic subprogram body is instantiated.
21957
21958 when Pragma_Refined_Post => Refined_Post : declare
21959 Body_Id : Entity_Id;
21960 Legal : Boolean;
21961 Spec_Id : Entity_Id;
21962
21963 begin
21964 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
21965
21966 -- Fully analyze the pragma when it appears inside a subprogram
21967 -- body because it cannot benefit from forward references.
21968
21969 if Legal then
21970
21971 -- Chain the pragma on the contract for completeness
21972
21973 Add_Contract_Item (N, Body_Id);
21974
21975 -- The legality checks of pragma Refined_Post are affected by
21976 -- the SPARK mode in effect and the volatility of the context.
21977 -- Analyze all pragmas in a specific order.
21978
21979 Analyze_If_Present (Pragma_SPARK_Mode);
21980 Analyze_If_Present (Pragma_Volatile_Function);
21981 Analyze_Pre_Post_Condition_In_Decl_Part (N);
21982
21983 -- Currently it is not possible to inline pre/postconditions on
21984 -- a subprogram subject to pragma Inline_Always.
21985
21986 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
21987 end if;
21988 end Refined_Post;
21989
21990 -------------------
21991 -- Refined_State --
21992 -------------------
21993
21994 -- pragma Refined_State (REFINEMENT_LIST);
21995
21996 -- REFINEMENT_LIST ::=
21997 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
21998
21999 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
22000
22001 -- CONSTITUENT_LIST ::=
22002 -- null
22003 -- | CONSTITUENT
22004 -- | (CONSTITUENT {, CONSTITUENT})
22005
22006 -- CONSTITUENT ::= object_NAME | state_NAME
22007
22008 -- Characteristics:
22009
22010 -- * Analysis - The annotation undergoes initial checks to verify
22011 -- the legal placement and context. Secondary checks preanalyze the
22012 -- refinement clauses in:
22013
22014 -- Analyze_Refined_State_In_Decl_Part
22015
22016 -- * Expansion - None.
22017
22018 -- * Template - The annotation utilizes the template of the related
22019 -- package body.
22020
22021 -- * Globals - Capture of global references must occur after full
22022 -- analysis.
22023
22024 -- * Instance - The annotation is instantiated automatically when
22025 -- the related generic package body is instantiated.
22026
22027 when Pragma_Refined_State => Refined_State : declare
22028 Pack_Decl : Node_Id;
22029 Spec_Id : Entity_Id;
22030
22031 begin
22032 GNAT_Pragma;
22033 Check_No_Identifiers;
22034 Check_Arg_Count (1);
22035
22036 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
22037
22038 if Nkind (Pack_Decl) /= N_Package_Body then
22039 Pragma_Misplaced;
22040 return;
22041 end if;
22042
22043 Spec_Id := Corresponding_Spec (Pack_Decl);
22044
22045 -- A pragma that applies to a Ghost entity becomes Ghost for the
22046 -- purposes of legality checks and removal of ignored Ghost code.
22047
22048 Mark_Ghost_Pragma (N, Spec_Id);
22049
22050 -- Chain the pragma on the contract for further processing by
22051 -- Analyze_Refined_State_In_Decl_Part.
22052
22053 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
22054
22055 -- The legality checks of pragma Refined_State are affected by the
22056 -- SPARK mode in effect. Analyze all pragmas in a specific order.
22057
22058 Analyze_If_Present (Pragma_SPARK_Mode);
22059
22060 -- State refinement is allowed only when the corresponding package
22061 -- declaration has non-null pragma Abstract_State. Refinement not
22062 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
22063
22064 if SPARK_Mode /= Off
22065 and then
22066 (No (Abstract_States (Spec_Id))
22067 or else Has_Null_Abstract_State (Spec_Id))
22068 then
22069 Error_Msg_NE
22070 ("useless refinement, package & does not define abstract "
22071 & "states", N, Spec_Id);
22072 return;
22073 end if;
22074 end Refined_State;
22075
22076 -----------------------
22077 -- Relative_Deadline --
22078 -----------------------
22079
22080 -- pragma Relative_Deadline (time_span_EXPRESSION);
22081
22082 when Pragma_Relative_Deadline => Relative_Deadline : declare
22083 P : constant Node_Id := Parent (N);
22084 Arg : Node_Id;
22085
22086 begin
22087 Ada_2005_Pragma;
22088 Check_No_Identifiers;
22089 Check_Arg_Count (1);
22090
22091 Arg := Get_Pragma_Arg (Arg1);
22092
22093 -- The expression must be analyzed in the special manner described
22094 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
22095
22096 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
22097
22098 -- Subprogram case
22099
22100 if Nkind (P) = N_Subprogram_Body then
22101 Check_In_Main_Program;
22102
22103 -- Only Task and subprogram cases allowed
22104
22105 elsif Nkind (P) /= N_Task_Definition then
22106 Pragma_Misplaced;
22107 end if;
22108
22109 -- Check duplicate pragma before we set the corresponding flag
22110
22111 if Has_Relative_Deadline_Pragma (P) then
22112 Error_Pragma ("duplicate pragma% not allowed");
22113 end if;
22114
22115 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
22116 -- Relative_Deadline pragma node cannot be inserted in the Rep
22117 -- Item chain of Ent since it is rewritten by the expander as a
22118 -- procedure call statement that will break the chain.
22119
22120 Set_Has_Relative_Deadline_Pragma (P);
22121 end Relative_Deadline;
22122
22123 ------------------------
22124 -- Remote_Access_Type --
22125 ------------------------
22126
22127 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
22128
22129 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
22130 E : Entity_Id;
22131
22132 begin
22133 GNAT_Pragma;
22134 Check_Arg_Count (1);
22135 Check_Optional_Identifier (Arg1, Name_Entity);
22136 Check_Arg_Is_Local_Name (Arg1);
22137
22138 E := Entity (Get_Pragma_Arg (Arg1));
22139
22140 -- A pragma that applies to a Ghost entity becomes Ghost for the
22141 -- purposes of legality checks and removal of ignored Ghost code.
22142
22143 Mark_Ghost_Pragma (N, E);
22144
22145 if Nkind (Parent (E)) = N_Formal_Type_Declaration
22146 and then Ekind (E) = E_General_Access_Type
22147 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
22148 and then Scope (Root_Type (Directly_Designated_Type (E)))
22149 = Scope (E)
22150 and then Is_Valid_Remote_Object_Type
22151 (Root_Type (Directly_Designated_Type (E)))
22152 then
22153 Set_Is_Remote_Types (E);
22154
22155 else
22156 Error_Pragma_Arg
22157 ("pragma% applies only to formal access-to-class-wide types",
22158 Arg1);
22159 end if;
22160 end Remote_Access_Type;
22161
22162 ---------------------------
22163 -- Remote_Call_Interface --
22164 ---------------------------
22165
22166 -- pragma Remote_Call_Interface [(library_unit_NAME)];
22167
22168 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
22169 Cunit_Node : Node_Id;
22170 Cunit_Ent : Entity_Id;
22171 K : Node_Kind;
22172
22173 begin
22174 Check_Ada_83_Warning;
22175 Check_Valid_Library_Unit_Pragma;
22176
22177 if Nkind (N) = N_Null_Statement then
22178 return;
22179 end if;
22180
22181 Cunit_Node := Cunit (Current_Sem_Unit);
22182 K := Nkind (Unit (Cunit_Node));
22183 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22184
22185 -- A pragma that applies to a Ghost entity becomes Ghost for the
22186 -- purposes of legality checks and removal of ignored Ghost code.
22187
22188 Mark_Ghost_Pragma (N, Cunit_Ent);
22189
22190 if K = N_Package_Declaration
22191 or else K = N_Generic_Package_Declaration
22192 or else K = N_Subprogram_Declaration
22193 or else K = N_Generic_Subprogram_Declaration
22194 or else (K = N_Subprogram_Body
22195 and then Acts_As_Spec (Unit (Cunit_Node)))
22196 then
22197 null;
22198 else
22199 Error_Pragma (
22200 "pragma% must apply to package or subprogram declaration");
22201 end if;
22202
22203 Set_Is_Remote_Call_Interface (Cunit_Ent);
22204 end Remote_Call_Interface;
22205
22206 ------------------
22207 -- Remote_Types --
22208 ------------------
22209
22210 -- pragma Remote_Types [(library_unit_NAME)];
22211
22212 when Pragma_Remote_Types => Remote_Types : declare
22213 Cunit_Node : Node_Id;
22214 Cunit_Ent : Entity_Id;
22215
22216 begin
22217 Check_Ada_83_Warning;
22218 Check_Valid_Library_Unit_Pragma;
22219
22220 if Nkind (N) = N_Null_Statement then
22221 return;
22222 end if;
22223
22224 Cunit_Node := Cunit (Current_Sem_Unit);
22225 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22226
22227 -- A pragma that applies to a Ghost entity becomes Ghost for the
22228 -- purposes of legality checks and removal of ignored Ghost code.
22229
22230 Mark_Ghost_Pragma (N, Cunit_Ent);
22231
22232 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
22233 N_Generic_Package_Declaration)
22234 then
22235 Error_Pragma
22236 ("pragma% can only apply to a package declaration");
22237 end if;
22238
22239 Set_Is_Remote_Types (Cunit_Ent);
22240 end Remote_Types;
22241
22242 ---------------
22243 -- Ravenscar --
22244 ---------------
22245
22246 -- pragma Ravenscar;
22247
22248 when Pragma_Ravenscar =>
22249 GNAT_Pragma;
22250 Check_Arg_Count (0);
22251 Check_Valid_Configuration_Pragma;
22252 Set_Ravenscar_Profile (Ravenscar, N);
22253
22254 if Warn_On_Obsolescent_Feature then
22255 Error_Msg_N
22256 ("pragma Ravenscar is an obsolescent feature?j?", N);
22257 Error_Msg_N
22258 ("|use pragma Profile (Ravenscar) instead?j?", N);
22259 end if;
22260
22261 -------------------------
22262 -- Restricted_Run_Time --
22263 -------------------------
22264
22265 -- pragma Restricted_Run_Time;
22266
22267 when Pragma_Restricted_Run_Time =>
22268 GNAT_Pragma;
22269 Check_Arg_Count (0);
22270 Check_Valid_Configuration_Pragma;
22271 Set_Profile_Restrictions
22272 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
22273
22274 if Warn_On_Obsolescent_Feature then
22275 Error_Msg_N
22276 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
22277 N);
22278 Error_Msg_N
22279 ("|use pragma Profile (Restricted) instead?j?", N);
22280 end if;
22281
22282 ------------------
22283 -- Restrictions --
22284 ------------------
22285
22286 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
22287
22288 -- RESTRICTION ::=
22289 -- restriction_IDENTIFIER
22290 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22291
22292 when Pragma_Restrictions =>
22293 Process_Restrictions_Or_Restriction_Warnings
22294 (Warn => Treat_Restrictions_As_Warnings);
22295
22296 --------------------------
22297 -- Restriction_Warnings --
22298 --------------------------
22299
22300 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
22301
22302 -- RESTRICTION ::=
22303 -- restriction_IDENTIFIER
22304 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22305
22306 when Pragma_Restriction_Warnings =>
22307 GNAT_Pragma;
22308 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
22309
22310 ----------------
22311 -- Reviewable --
22312 ----------------
22313
22314 -- pragma Reviewable;
22315
22316 when Pragma_Reviewable =>
22317 Check_Ada_83_Warning;
22318 Check_Arg_Count (0);
22319
22320 -- Call dummy debugging function rv. This is done to assist front
22321 -- end debugging. By placing a Reviewable pragma in the source
22322 -- program, a breakpoint on rv catches this place in the source,
22323 -- allowing convenient stepping to the point of interest.
22324
22325 rv;
22326
22327 --------------------------
22328 -- Secondary_Stack_Size --
22329 --------------------------
22330
22331 -- pragma Secondary_Stack_Size (EXPRESSION);
22332
22333 when Pragma_Secondary_Stack_Size => Secondary_Stack_Size : declare
22334 P : constant Node_Id := Parent (N);
22335 Arg : Node_Id;
22336 Ent : Entity_Id;
22337
22338 begin
22339 GNAT_Pragma;
22340 Check_No_Identifiers;
22341 Check_Arg_Count (1);
22342
22343 if Nkind (P) = N_Task_Definition then
22344 Arg := Get_Pragma_Arg (Arg1);
22345 Ent := Defining_Identifier (Parent (P));
22346
22347 -- The expression must be analyzed in the special manner
22348 -- described in "Handling of Default Expressions" in sem.ads.
22349
22350 Preanalyze_Spec_Expression (Arg, Any_Integer);
22351
22352 -- The pragma cannot appear if the No_Secondary_Stack
22353 -- restriction is in effect.
22354
22355 Check_Restriction (No_Secondary_Stack, Arg);
22356
22357 -- Anything else is incorrect
22358
22359 else
22360 Pragma_Misplaced;
22361 end if;
22362
22363 -- Check duplicate pragma before we chain the pragma in the Rep
22364 -- Item chain of Ent.
22365
22366 Check_Duplicate_Pragma (Ent);
22367 Record_Rep_Item (Ent, N);
22368 end Secondary_Stack_Size;
22369
22370 --------------------------
22371 -- Short_Circuit_And_Or --
22372 --------------------------
22373
22374 -- pragma Short_Circuit_And_Or;
22375
22376 when Pragma_Short_Circuit_And_Or =>
22377 GNAT_Pragma;
22378 Check_Arg_Count (0);
22379 Check_Valid_Configuration_Pragma;
22380 Short_Circuit_And_Or := True;
22381
22382 -------------------
22383 -- Share_Generic --
22384 -------------------
22385
22386 -- pragma Share_Generic (GNAME {, GNAME});
22387
22388 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
22389
22390 when Pragma_Share_Generic =>
22391 GNAT_Pragma;
22392 Process_Generic_List;
22393
22394 ------------
22395 -- Shared --
22396 ------------
22397
22398 -- pragma Shared (LOCAL_NAME);
22399
22400 when Pragma_Shared =>
22401 GNAT_Pragma;
22402 Process_Atomic_Independent_Shared_Volatile;
22403
22404 --------------------
22405 -- Shared_Passive --
22406 --------------------
22407
22408 -- pragma Shared_Passive [(library_unit_NAME)];
22409
22410 -- Set the flag Is_Shared_Passive of program unit name entity
22411
22412 when Pragma_Shared_Passive => Shared_Passive : declare
22413 Cunit_Node : Node_Id;
22414 Cunit_Ent : Entity_Id;
22415
22416 begin
22417 Check_Ada_83_Warning;
22418 Check_Valid_Library_Unit_Pragma;
22419
22420 if Nkind (N) = N_Null_Statement then
22421 return;
22422 end if;
22423
22424 Cunit_Node := Cunit (Current_Sem_Unit);
22425 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22426
22427 -- A pragma that applies to a Ghost entity becomes Ghost for the
22428 -- purposes of legality checks and removal of ignored Ghost code.
22429
22430 Mark_Ghost_Pragma (N, Cunit_Ent);
22431
22432 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
22433 N_Generic_Package_Declaration)
22434 then
22435 Error_Pragma
22436 ("pragma% can only apply to a package declaration");
22437 end if;
22438
22439 Set_Is_Shared_Passive (Cunit_Ent);
22440 end Shared_Passive;
22441
22442 -----------------------
22443 -- Short_Descriptors --
22444 -----------------------
22445
22446 -- pragma Short_Descriptors;
22447
22448 -- Recognize and validate, but otherwise ignore
22449
22450 when Pragma_Short_Descriptors =>
22451 GNAT_Pragma;
22452 Check_Arg_Count (0);
22453 Check_Valid_Configuration_Pragma;
22454
22455 ------------------------------
22456 -- Simple_Storage_Pool_Type --
22457 ------------------------------
22458
22459 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
22460
22461 when Pragma_Simple_Storage_Pool_Type =>
22462 Simple_Storage_Pool_Type : declare
22463 Typ : Entity_Id;
22464 Type_Id : Node_Id;
22465
22466 begin
22467 GNAT_Pragma;
22468 Check_Arg_Count (1);
22469 Check_Arg_Is_Library_Level_Local_Name (Arg1);
22470
22471 Type_Id := Get_Pragma_Arg (Arg1);
22472 Find_Type (Type_Id);
22473 Typ := Entity (Type_Id);
22474
22475 if Typ = Any_Type then
22476 return;
22477 end if;
22478
22479 -- A pragma that applies to a Ghost entity becomes Ghost for the
22480 -- purposes of legality checks and removal of ignored Ghost code.
22481
22482 Mark_Ghost_Pragma (N, Typ);
22483
22484 -- We require the pragma to apply to a type declared in a package
22485 -- declaration, but not (immediately) within a package body.
22486
22487 if Ekind (Current_Scope) /= E_Package
22488 or else In_Package_Body (Current_Scope)
22489 then
22490 Error_Pragma
22491 ("pragma% can only apply to type declared immediately "
22492 & "within a package declaration");
22493 end if;
22494
22495 -- A simple storage pool type must be an immutably limited record
22496 -- or private type. If the pragma is given for a private type,
22497 -- the full type is similarly restricted (which is checked later
22498 -- in Freeze_Entity).
22499
22500 if Is_Record_Type (Typ)
22501 and then not Is_Limited_View (Typ)
22502 then
22503 Error_Pragma
22504 ("pragma% can only apply to explicitly limited record type");
22505
22506 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
22507 Error_Pragma
22508 ("pragma% can only apply to a private type that is limited");
22509
22510 elsif not Is_Record_Type (Typ)
22511 and then not Is_Private_Type (Typ)
22512 then
22513 Error_Pragma
22514 ("pragma% can only apply to limited record or private type");
22515 end if;
22516
22517 Record_Rep_Item (Typ, N);
22518 end Simple_Storage_Pool_Type;
22519
22520 ----------------------
22521 -- Source_File_Name --
22522 ----------------------
22523
22524 -- There are five forms for this pragma:
22525
22526 -- pragma Source_File_Name (
22527 -- [UNIT_NAME =>] unit_NAME,
22528 -- BODY_FILE_NAME => STRING_LITERAL
22529 -- [, [INDEX =>] INTEGER_LITERAL]);
22530
22531 -- pragma Source_File_Name (
22532 -- [UNIT_NAME =>] unit_NAME,
22533 -- SPEC_FILE_NAME => STRING_LITERAL
22534 -- [, [INDEX =>] INTEGER_LITERAL]);
22535
22536 -- pragma Source_File_Name (
22537 -- BODY_FILE_NAME => STRING_LITERAL
22538 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22539 -- [, CASING => CASING_SPEC]);
22540
22541 -- pragma Source_File_Name (
22542 -- SPEC_FILE_NAME => STRING_LITERAL
22543 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22544 -- [, CASING => CASING_SPEC]);
22545
22546 -- pragma Source_File_Name (
22547 -- SUBUNIT_FILE_NAME => STRING_LITERAL
22548 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22549 -- [, CASING => CASING_SPEC]);
22550
22551 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
22552
22553 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
22554 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
22555 -- only be used when no project file is used, while SFNP can only be
22556 -- used when a project file is used.
22557
22558 -- No processing here. Processing was completed during parsing, since
22559 -- we need to have file names set as early as possible. Units are
22560 -- loaded well before semantic processing starts.
22561
22562 -- The only processing we defer to this point is the check for
22563 -- correct placement.
22564
22565 when Pragma_Source_File_Name =>
22566 GNAT_Pragma;
22567 Check_Valid_Configuration_Pragma;
22568
22569 ------------------------------
22570 -- Source_File_Name_Project --
22571 ------------------------------
22572
22573 -- See Source_File_Name for syntax
22574
22575 -- No processing here. Processing was completed during parsing, since
22576 -- we need to have file names set as early as possible. Units are
22577 -- loaded well before semantic processing starts.
22578
22579 -- The only processing we defer to this point is the check for
22580 -- correct placement.
22581
22582 when Pragma_Source_File_Name_Project =>
22583 GNAT_Pragma;
22584 Check_Valid_Configuration_Pragma;
22585
22586 -- Check that a pragma Source_File_Name_Project is used only in a
22587 -- configuration pragmas file.
22588
22589 -- Pragmas Source_File_Name_Project should only be generated by
22590 -- the Project Manager in configuration pragmas files.
22591
22592 -- This is really an ugly test. It seems to depend on some
22593 -- accidental and undocumented property. At the very least it
22594 -- needs to be documented, but it would be better to have a
22595 -- clean way of testing if we are in a configuration file???
22596
22597 if Present (Parent (N)) then
22598 Error_Pragma
22599 ("pragma% can only appear in a configuration pragmas file");
22600 end if;
22601
22602 ----------------------
22603 -- Source_Reference --
22604 ----------------------
22605
22606 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
22607
22608 -- Nothing to do, all processing completed in Par.Prag, since we need
22609 -- the information for possible parser messages that are output.
22610
22611 when Pragma_Source_Reference =>
22612 GNAT_Pragma;
22613
22614 ----------------
22615 -- SPARK_Mode --
22616 ----------------
22617
22618 -- pragma SPARK_Mode [(On | Off)];
22619
22620 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
22621 Mode_Id : SPARK_Mode_Type;
22622
22623 procedure Check_Pragma_Conformance
22624 (Context_Pragma : Node_Id;
22625 Entity : Entity_Id;
22626 Entity_Pragma : Node_Id);
22627 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
22628 -- conformance of pragma N depending the following scenarios:
22629 --
22630 -- If pragma Context_Pragma is not Empty, verify that pragma N is
22631 -- compatible with the pragma Context_Pragma that was inherited
22632 -- from the context:
22633 -- * If the mode of Context_Pragma is ON, then the new mode can
22634 -- be anything.
22635 -- * If the mode of Context_Pragma is OFF, then the only allowed
22636 -- new mode is also OFF. Emit error if this is not the case.
22637 --
22638 -- If Entity is not Empty, verify that pragma N is compatible with
22639 -- pragma Entity_Pragma that belongs to Entity.
22640 -- * If Entity_Pragma is Empty, always issue an error as this
22641 -- corresponds to the case where a previous section of Entity
22642 -- has no SPARK_Mode set.
22643 -- * If the mode of Entity_Pragma is ON, then the new mode can
22644 -- be anything.
22645 -- * If the mode of Entity_Pragma is OFF, then the only allowed
22646 -- new mode is also OFF. Emit error if this is not the case.
22647
22648 procedure Check_Library_Level_Entity (E : Entity_Id);
22649 -- Subsidiary to routines Process_xxx. Verify that the related
22650 -- entity E subject to pragma SPARK_Mode is library-level.
22651
22652 procedure Process_Body (Decl : Node_Id);
22653 -- Verify the legality of pragma SPARK_Mode when it appears as the
22654 -- top of the body declarations of entry, package, protected unit,
22655 -- subprogram or task unit body denoted by Decl.
22656
22657 procedure Process_Overloadable (Decl : Node_Id);
22658 -- Verify the legality of pragma SPARK_Mode when it applies to an
22659 -- entry or [generic] subprogram declaration denoted by Decl.
22660
22661 procedure Process_Private_Part (Decl : Node_Id);
22662 -- Verify the legality of pragma SPARK_Mode when it appears at the
22663 -- top of the private declarations of a package spec, protected or
22664 -- task unit declaration denoted by Decl.
22665
22666 procedure Process_Statement_Part (Decl : Node_Id);
22667 -- Verify the legality of pragma SPARK_Mode when it appears at the
22668 -- top of the statement sequence of a package body denoted by node
22669 -- Decl.
22670
22671 procedure Process_Visible_Part (Decl : Node_Id);
22672 -- Verify the legality of pragma SPARK_Mode when it appears at the
22673 -- top of the visible declarations of a package spec, protected or
22674 -- task unit declaration denoted by Decl. The routine is also used
22675 -- on protected or task units declared without a definition.
22676
22677 procedure Set_SPARK_Context;
22678 -- Subsidiary to routines Process_xxx. Set the global variables
22679 -- which represent the mode of the context from pragma N. Ensure
22680 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
22681
22682 ------------------------------
22683 -- Check_Pragma_Conformance --
22684 ------------------------------
22685
22686 procedure Check_Pragma_Conformance
22687 (Context_Pragma : Node_Id;
22688 Entity : Entity_Id;
22689 Entity_Pragma : Node_Id)
22690 is
22691 Err_Id : Entity_Id;
22692 Err_N : Node_Id;
22693
22694 begin
22695 -- The current pragma may appear without an argument. If this
22696 -- is the case, associate all error messages with the pragma
22697 -- itself.
22698
22699 if Present (Arg1) then
22700 Err_N := Arg1;
22701 else
22702 Err_N := N;
22703 end if;
22704
22705 -- The mode of the current pragma is compared against that of
22706 -- an enclosing context.
22707
22708 if Present (Context_Pragma) then
22709 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
22710
22711 -- Issue an error if the new mode is less restrictive than
22712 -- that of the context.
22713
22714 if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off
22715 and then Get_SPARK_Mode_From_Annotation (N) = On
22716 then
22717 Error_Msg_N
22718 ("cannot change SPARK_Mode from Off to On", Err_N);
22719 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
22720 Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N);
22721 raise Pragma_Exit;
22722 end if;
22723 end if;
22724
22725 -- The mode of the current pragma is compared against that of
22726 -- an initial package, protected type, subprogram or task type
22727 -- declaration.
22728
22729 if Present (Entity) then
22730
22731 -- A simple protected or task type is transformed into an
22732 -- anonymous type whose name cannot be used to issue error
22733 -- messages. Recover the original entity of the type.
22734
22735 if Ekind_In (Entity, E_Protected_Type, E_Task_Type) then
22736 Err_Id :=
22737 Defining_Entity
22738 (Original_Node (Unit_Declaration_Node (Entity)));
22739 else
22740 Err_Id := Entity;
22741 end if;
22742
22743 -- Both the initial declaration and the completion carry
22744 -- SPARK_Mode pragmas.
22745
22746 if Present (Entity_Pragma) then
22747 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
22748
22749 -- Issue an error if the new mode is less restrictive
22750 -- than that of the initial declaration.
22751
22752 if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off
22753 and then Get_SPARK_Mode_From_Annotation (N) = On
22754 then
22755 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
22756 Error_Msg_Sloc := Sloc (Entity_Pragma);
22757 Error_Msg_NE
22758 ("\value Off was set for SPARK_Mode on&#",
22759 Err_N, Err_Id);
22760 raise Pragma_Exit;
22761 end if;
22762
22763 -- Otherwise the initial declaration lacks a SPARK_Mode
22764 -- pragma in which case the current pragma is illegal as
22765 -- it cannot "complete".
22766
22767 elsif Get_SPARK_Mode_From_Annotation (N) = Off
22768 and then (Is_Generic_Unit (Entity) or else In_Instance)
22769 then
22770 null;
22771
22772 else
22773 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
22774 Error_Msg_Sloc := Sloc (Err_Id);
22775 Error_Msg_NE
22776 ("\no value was set for SPARK_Mode on&#",
22777 Err_N, Err_Id);
22778 raise Pragma_Exit;
22779 end if;
22780 end if;
22781 end Check_Pragma_Conformance;
22782
22783 --------------------------------
22784 -- Check_Library_Level_Entity --
22785 --------------------------------
22786
22787 procedure Check_Library_Level_Entity (E : Entity_Id) is
22788 procedure Add_Entity_To_Name_Buffer;
22789 -- Add the E_Kind of entity E to the name buffer
22790
22791 -------------------------------
22792 -- Add_Entity_To_Name_Buffer --
22793 -------------------------------
22794
22795 procedure Add_Entity_To_Name_Buffer is
22796 begin
22797 if Ekind_In (E, E_Entry, E_Entry_Family) then
22798 Add_Str_To_Name_Buffer ("entry");
22799
22800 elsif Ekind_In (E, E_Generic_Package,
22801 E_Package,
22802 E_Package_Body)
22803 then
22804 Add_Str_To_Name_Buffer ("package");
22805
22806 elsif Ekind_In (E, E_Protected_Body, E_Protected_Type) then
22807 Add_Str_To_Name_Buffer ("protected type");
22808
22809 elsif Ekind_In (E, E_Function,
22810 E_Generic_Function,
22811 E_Generic_Procedure,
22812 E_Procedure,
22813 E_Subprogram_Body)
22814 then
22815 Add_Str_To_Name_Buffer ("subprogram");
22816
22817 else
22818 pragma Assert (Ekind_In (E, E_Task_Body, E_Task_Type));
22819 Add_Str_To_Name_Buffer ("task type");
22820 end if;
22821 end Add_Entity_To_Name_Buffer;
22822
22823 -- Local variables
22824
22825 Msg_1 : constant String := "incorrect placement of pragma%";
22826 Msg_2 : Name_Id;
22827
22828 -- Start of processing for Check_Library_Level_Entity
22829
22830 begin
22831 -- A SPARK_Mode of On shall only apply to library-level
22832 -- entities, except for those in generic instances, which are
22833 -- ignored (even if the entity gets SPARK_Mode pragma attached
22834 -- in the AST, its effect is not taken into account unless the
22835 -- context already provides SPARK_Mode of On in GNATprove).
22836
22837 if Get_SPARK_Mode_From_Annotation (N) = On
22838 and then not Is_Library_Level_Entity (E)
22839 and then Instantiation_Location (Sloc (N)) = No_Location
22840 then
22841 Error_Msg_Name_1 := Pname;
22842 Error_Msg_N (Fix_Error (Msg_1), N);
22843
22844 Name_Len := 0;
22845 Add_Str_To_Name_Buffer ("\& is not a library-level ");
22846 Add_Entity_To_Name_Buffer;
22847
22848 Msg_2 := Name_Find;
22849 Error_Msg_NE (Get_Name_String (Msg_2), N, E);
22850
22851 raise Pragma_Exit;
22852 end if;
22853 end Check_Library_Level_Entity;
22854
22855 ------------------
22856 -- Process_Body --
22857 ------------------
22858
22859 procedure Process_Body (Decl : Node_Id) is
22860 Body_Id : constant Entity_Id := Defining_Entity (Decl);
22861 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
22862
22863 begin
22864 -- Ignore pragma when applied to the special body created for
22865 -- inlining, recognized by its internal name _Parent.
22866
22867 if Chars (Body_Id) = Name_uParent then
22868 return;
22869 end if;
22870
22871 Check_Library_Level_Entity (Body_Id);
22872
22873 -- For entry bodies, verify the legality against:
22874 -- * The mode of the context
22875 -- * The mode of the spec (if any)
22876
22877 if Nkind_In (Decl, N_Entry_Body, N_Subprogram_Body) then
22878
22879 -- A stand-alone subprogram body
22880
22881 if Body_Id = Spec_Id then
22882 Check_Pragma_Conformance
22883 (Context_Pragma => SPARK_Pragma (Body_Id),
22884 Entity => Empty,
22885 Entity_Pragma => Empty);
22886
22887 -- An entry or subprogram body that completes a previous
22888 -- declaration.
22889
22890 else
22891 Check_Pragma_Conformance
22892 (Context_Pragma => SPARK_Pragma (Body_Id),
22893 Entity => Spec_Id,
22894 Entity_Pragma => SPARK_Pragma (Spec_Id));
22895 end if;
22896
22897 Set_SPARK_Context;
22898 Set_SPARK_Pragma (Body_Id, N);
22899 Set_SPARK_Pragma_Inherited (Body_Id, False);
22900
22901 -- For package bodies, verify the legality against:
22902 -- * The mode of the context
22903 -- * The mode of the private part
22904
22905 -- This case is separated from protected and task bodies
22906 -- because the statement part of the package body inherits
22907 -- the mode of the body declarations.
22908
22909 elsif Nkind (Decl) = N_Package_Body then
22910 Check_Pragma_Conformance
22911 (Context_Pragma => SPARK_Pragma (Body_Id),
22912 Entity => Spec_Id,
22913 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
22914
22915 Set_SPARK_Context;
22916 Set_SPARK_Pragma (Body_Id, N);
22917 Set_SPARK_Pragma_Inherited (Body_Id, False);
22918 Set_SPARK_Aux_Pragma (Body_Id, N);
22919 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
22920
22921 -- For protected and task bodies, verify the legality against:
22922 -- * The mode of the context
22923 -- * The mode of the private part
22924
22925 else
22926 pragma Assert
22927 (Nkind_In (Decl, N_Protected_Body, N_Task_Body));
22928
22929 Check_Pragma_Conformance
22930 (Context_Pragma => SPARK_Pragma (Body_Id),
22931 Entity => Spec_Id,
22932 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
22933
22934 Set_SPARK_Context;
22935 Set_SPARK_Pragma (Body_Id, N);
22936 Set_SPARK_Pragma_Inherited (Body_Id, False);
22937 end if;
22938 end Process_Body;
22939
22940 --------------------------
22941 -- Process_Overloadable --
22942 --------------------------
22943
22944 procedure Process_Overloadable (Decl : Node_Id) is
22945 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
22946 Spec_Typ : constant Entity_Id := Etype (Spec_Id);
22947
22948 begin
22949 Check_Library_Level_Entity (Spec_Id);
22950
22951 -- Verify the legality against:
22952 -- * The mode of the context
22953
22954 Check_Pragma_Conformance
22955 (Context_Pragma => SPARK_Pragma (Spec_Id),
22956 Entity => Empty,
22957 Entity_Pragma => Empty);
22958
22959 Set_SPARK_Pragma (Spec_Id, N);
22960 Set_SPARK_Pragma_Inherited (Spec_Id, False);
22961
22962 -- When the pragma applies to the anonymous object created for
22963 -- a single task type, decorate the type as well. This scenario
22964 -- arises when the single task type lacks a task definition,
22965 -- therefore there is no issue with respect to a potential
22966 -- pragma SPARK_Mode in the private part.
22967
22968 -- task type Anon_Task_Typ;
22969 -- Obj : Anon_Task_Typ;
22970 -- pragma SPARK_Mode ...;
22971
22972 if Is_Single_Task_Object (Spec_Id) then
22973 Set_SPARK_Pragma (Spec_Typ, N);
22974 Set_SPARK_Pragma_Inherited (Spec_Typ, False);
22975 Set_SPARK_Aux_Pragma (Spec_Typ, N);
22976 Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True);
22977 end if;
22978 end Process_Overloadable;
22979
22980 --------------------------
22981 -- Process_Private_Part --
22982 --------------------------
22983
22984 procedure Process_Private_Part (Decl : Node_Id) is
22985 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
22986
22987 begin
22988 Check_Library_Level_Entity (Spec_Id);
22989
22990 -- Verify the legality against:
22991 -- * The mode of the visible declarations
22992
22993 Check_Pragma_Conformance
22994 (Context_Pragma => Empty,
22995 Entity => Spec_Id,
22996 Entity_Pragma => SPARK_Pragma (Spec_Id));
22997
22998 Set_SPARK_Context;
22999 Set_SPARK_Aux_Pragma (Spec_Id, N);
23000 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
23001 end Process_Private_Part;
23002
23003 ----------------------------
23004 -- Process_Statement_Part --
23005 ----------------------------
23006
23007 procedure Process_Statement_Part (Decl : Node_Id) is
23008 Body_Id : constant Entity_Id := Defining_Entity (Decl);
23009
23010 begin
23011 Check_Library_Level_Entity (Body_Id);
23012
23013 -- Verify the legality against:
23014 -- * The mode of the body declarations
23015
23016 Check_Pragma_Conformance
23017 (Context_Pragma => Empty,
23018 Entity => Body_Id,
23019 Entity_Pragma => SPARK_Pragma (Body_Id));
23020
23021 Set_SPARK_Context;
23022 Set_SPARK_Aux_Pragma (Body_Id, N);
23023 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
23024 end Process_Statement_Part;
23025
23026 --------------------------
23027 -- Process_Visible_Part --
23028 --------------------------
23029
23030 procedure Process_Visible_Part (Decl : Node_Id) is
23031 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23032 Obj_Id : Entity_Id;
23033
23034 begin
23035 Check_Library_Level_Entity (Spec_Id);
23036
23037 -- Verify the legality against:
23038 -- * The mode of the context
23039
23040 Check_Pragma_Conformance
23041 (Context_Pragma => SPARK_Pragma (Spec_Id),
23042 Entity => Empty,
23043 Entity_Pragma => Empty);
23044
23045 -- A task unit declared without a definition does not set the
23046 -- SPARK_Mode of the context because the task does not have any
23047 -- entries that could inherit the mode.
23048
23049 if not Nkind_In (Decl, N_Single_Task_Declaration,
23050 N_Task_Type_Declaration)
23051 then
23052 Set_SPARK_Context;
23053 end if;
23054
23055 Set_SPARK_Pragma (Spec_Id, N);
23056 Set_SPARK_Pragma_Inherited (Spec_Id, False);
23057 Set_SPARK_Aux_Pragma (Spec_Id, N);
23058 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
23059
23060 -- When the pragma applies to a single protected or task type,
23061 -- decorate the corresponding anonymous object as well.
23062
23063 -- protected Anon_Prot_Typ is
23064 -- pragma SPARK_Mode ...;
23065 -- ...
23066 -- end Anon_Prot_Typ;
23067
23068 -- Obj : Anon_Prot_Typ;
23069
23070 if Is_Single_Concurrent_Type (Spec_Id) then
23071 Obj_Id := Anonymous_Object (Spec_Id);
23072
23073 Set_SPARK_Pragma (Obj_Id, N);
23074 Set_SPARK_Pragma_Inherited (Obj_Id, False);
23075 end if;
23076 end Process_Visible_Part;
23077
23078 -----------------------
23079 -- Set_SPARK_Context --
23080 -----------------------
23081
23082 procedure Set_SPARK_Context is
23083 begin
23084 SPARK_Mode := Mode_Id;
23085 SPARK_Mode_Pragma := N;
23086 end Set_SPARK_Context;
23087
23088 -- Local variables
23089
23090 Context : Node_Id;
23091 Mode : Name_Id;
23092 Stmt : Node_Id;
23093
23094 -- Start of processing for Do_SPARK_Mode
23095
23096 begin
23097 GNAT_Pragma;
23098 Check_No_Identifiers;
23099 Check_At_Most_N_Arguments (1);
23100
23101 -- Check the legality of the mode (no argument = ON)
23102
23103 if Arg_Count = 1 then
23104 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23105 Mode := Chars (Get_Pragma_Arg (Arg1));
23106 else
23107 Mode := Name_On;
23108 end if;
23109
23110 Mode_Id := Get_SPARK_Mode_Type (Mode);
23111 Context := Parent (N);
23112
23113 -- When a SPARK_Mode pragma appears inside an instantiation whose
23114 -- enclosing context has SPARK_Mode set to "off", the pragma has
23115 -- no semantic effect.
23116
23117 if Ignore_SPARK_Mode_Pragmas_In_Instance
23118 and then Mode_Id /= Off
23119 then
23120 Rewrite (N, Make_Null_Statement (Loc));
23121 Analyze (N);
23122 return;
23123 end if;
23124
23125 -- The pragma appears in a configuration file
23126
23127 if No (Context) then
23128 Check_Valid_Configuration_Pragma;
23129
23130 if Present (SPARK_Mode_Pragma) then
23131 Duplication_Error
23132 (Prag => N,
23133 Prev => SPARK_Mode_Pragma);
23134 raise Pragma_Exit;
23135 end if;
23136
23137 Set_SPARK_Context;
23138
23139 -- The pragma acts as a configuration pragma in a compilation unit
23140
23141 -- pragma SPARK_Mode ...;
23142 -- package Pack is ...;
23143
23144 elsif Nkind (Context) = N_Compilation_Unit
23145 and then List_Containing (N) = Context_Items (Context)
23146 then
23147 Check_Valid_Configuration_Pragma;
23148 Set_SPARK_Context;
23149
23150 -- Otherwise the placement of the pragma within the tree dictates
23151 -- its associated construct. Inspect the declarative list where
23152 -- the pragma resides to find a potential construct.
23153
23154 else
23155 Stmt := Prev (N);
23156 while Present (Stmt) loop
23157
23158 -- Skip prior pragmas, but check for duplicates. Note that
23159 -- this also takes care of pragmas generated for aspects.
23160
23161 if Nkind (Stmt) = N_Pragma then
23162 if Pragma_Name (Stmt) = Pname then
23163 Duplication_Error
23164 (Prag => N,
23165 Prev => Stmt);
23166 raise Pragma_Exit;
23167 end if;
23168
23169 -- The pragma applies to an expression function that has
23170 -- already been rewritten into a subprogram declaration.
23171
23172 -- function Expr_Func return ... is (...);
23173 -- pragma SPARK_Mode ...;
23174
23175 elsif Nkind (Stmt) = N_Subprogram_Declaration
23176 and then Nkind (Original_Node (Stmt)) =
23177 N_Expression_Function
23178 then
23179 Process_Overloadable (Stmt);
23180 return;
23181
23182 -- The pragma applies to the anonymous object created for a
23183 -- single concurrent type.
23184
23185 -- protected type Anon_Prot_Typ ...;
23186 -- Obj : Anon_Prot_Typ;
23187 -- pragma SPARK_Mode ...;
23188
23189 elsif Nkind (Stmt) = N_Object_Declaration
23190 and then Is_Single_Concurrent_Object
23191 (Defining_Entity (Stmt))
23192 then
23193 Process_Overloadable (Stmt);
23194 return;
23195
23196 -- Skip internally generated code
23197
23198 elsif not Comes_From_Source (Stmt) then
23199 null;
23200
23201 -- The pragma applies to an entry or [generic] subprogram
23202 -- declaration.
23203
23204 -- entry Ent ...;
23205 -- pragma SPARK_Mode ...;
23206
23207 -- [generic]
23208 -- procedure Proc ...;
23209 -- pragma SPARK_Mode ...;
23210
23211 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
23212 N_Subprogram_Declaration)
23213 or else (Nkind (Stmt) = N_Entry_Declaration
23214 and then Is_Protected_Type
23215 (Scope (Defining_Entity (Stmt))))
23216 then
23217 Process_Overloadable (Stmt);
23218 return;
23219
23220 -- Otherwise the pragma does not apply to a legal construct
23221 -- or it does not appear at the top of a declarative or a
23222 -- statement list. Issue an error and stop the analysis.
23223
23224 else
23225 Pragma_Misplaced;
23226 exit;
23227 end if;
23228
23229 Prev (Stmt);
23230 end loop;
23231
23232 -- The pragma applies to a package or a subprogram that acts as
23233 -- a compilation unit.
23234
23235 -- procedure Proc ...;
23236 -- pragma SPARK_Mode ...;
23237
23238 if Nkind (Context) = N_Compilation_Unit_Aux then
23239 Context := Unit (Parent (Context));
23240 end if;
23241
23242 -- The pragma appears at the top of entry, package, protected
23243 -- unit, subprogram or task unit body declarations.
23244
23245 -- entry Ent when ... is
23246 -- pragma SPARK_Mode ...;
23247
23248 -- package body Pack is
23249 -- pragma SPARK_Mode ...;
23250
23251 -- procedure Proc ... is
23252 -- pragma SPARK_Mode;
23253
23254 -- protected body Prot is
23255 -- pragma SPARK_Mode ...;
23256
23257 if Nkind_In (Context, N_Entry_Body,
23258 N_Package_Body,
23259 N_Protected_Body,
23260 N_Subprogram_Body,
23261 N_Task_Body)
23262 then
23263 Process_Body (Context);
23264
23265 -- The pragma appears at the top of the visible or private
23266 -- declaration of a package spec, protected or task unit.
23267
23268 -- package Pack is
23269 -- pragma SPARK_Mode ...;
23270 -- private
23271 -- pragma SPARK_Mode ...;
23272
23273 -- protected [type] Prot is
23274 -- pragma SPARK_Mode ...;
23275 -- private
23276 -- pragma SPARK_Mode ...;
23277
23278 elsif Nkind_In (Context, N_Package_Specification,
23279 N_Protected_Definition,
23280 N_Task_Definition)
23281 then
23282 if List_Containing (N) = Visible_Declarations (Context) then
23283 Process_Visible_Part (Parent (Context));
23284 else
23285 Process_Private_Part (Parent (Context));
23286 end if;
23287
23288 -- The pragma appears at the top of package body statements
23289
23290 -- package body Pack is
23291 -- begin
23292 -- pragma SPARK_Mode;
23293
23294 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
23295 and then Nkind (Parent (Context)) = N_Package_Body
23296 then
23297 Process_Statement_Part (Parent (Context));
23298
23299 -- The pragma appeared as an aspect of a [generic] subprogram
23300 -- declaration that acts as a compilation unit.
23301
23302 -- [generic]
23303 -- procedure Proc ...;
23304 -- pragma SPARK_Mode ...;
23305
23306 elsif Nkind_In (Context, N_Generic_Subprogram_Declaration,
23307 N_Subprogram_Declaration)
23308 then
23309 Process_Overloadable (Context);
23310
23311 -- The pragma does not apply to a legal construct, issue error
23312
23313 else
23314 Pragma_Misplaced;
23315 end if;
23316 end if;
23317 end Do_SPARK_Mode;
23318
23319 --------------------------------
23320 -- Static_Elaboration_Desired --
23321 --------------------------------
23322
23323 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
23324
23325 when Pragma_Static_Elaboration_Desired =>
23326 GNAT_Pragma;
23327 Check_At_Most_N_Arguments (1);
23328
23329 if Is_Compilation_Unit (Current_Scope)
23330 and then Ekind (Current_Scope) = E_Package
23331 then
23332 Set_Static_Elaboration_Desired (Current_Scope, True);
23333 else
23334 Error_Pragma ("pragma% must apply to a library-level package");
23335 end if;
23336
23337 ------------------
23338 -- Storage_Size --
23339 ------------------
23340
23341 -- pragma Storage_Size (EXPRESSION);
23342
23343 when Pragma_Storage_Size => Storage_Size : declare
23344 P : constant Node_Id := Parent (N);
23345 Arg : Node_Id;
23346
23347 begin
23348 Check_No_Identifiers;
23349 Check_Arg_Count (1);
23350
23351 -- The expression must be analyzed in the special manner described
23352 -- in "Handling of Default Expressions" in sem.ads.
23353
23354 Arg := Get_Pragma_Arg (Arg1);
23355 Preanalyze_Spec_Expression (Arg, Any_Integer);
23356
23357 if not Is_OK_Static_Expression (Arg) then
23358 Check_Restriction (Static_Storage_Size, Arg);
23359 end if;
23360
23361 if Nkind (P) /= N_Task_Definition then
23362 Pragma_Misplaced;
23363 return;
23364
23365 else
23366 if Has_Storage_Size_Pragma (P) then
23367 Error_Pragma ("duplicate pragma% not allowed");
23368 else
23369 Set_Has_Storage_Size_Pragma (P, True);
23370 end if;
23371
23372 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
23373 end if;
23374 end Storage_Size;
23375
23376 ------------------
23377 -- Storage_Unit --
23378 ------------------
23379
23380 -- pragma Storage_Unit (NUMERIC_LITERAL);
23381
23382 -- Only permitted argument is System'Storage_Unit value
23383
23384 when Pragma_Storage_Unit =>
23385 Check_No_Identifiers;
23386 Check_Arg_Count (1);
23387 Check_Arg_Is_Integer_Literal (Arg1);
23388
23389 if Intval (Get_Pragma_Arg (Arg1)) /=
23390 UI_From_Int (Ttypes.System_Storage_Unit)
23391 then
23392 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
23393 Error_Pragma_Arg
23394 ("the only allowed argument for pragma% is ^", Arg1);
23395 end if;
23396
23397 --------------------
23398 -- Stream_Convert --
23399 --------------------
23400
23401 -- pragma Stream_Convert (
23402 -- [Entity =>] type_LOCAL_NAME,
23403 -- [Read =>] function_NAME,
23404 -- [Write =>] function NAME);
23405
23406 when Pragma_Stream_Convert => Stream_Convert : declare
23407 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
23408 -- Check that the given argument is the name of a local function
23409 -- of one argument that is not overloaded earlier in the current
23410 -- local scope. A check is also made that the argument is a
23411 -- function with one parameter.
23412
23413 --------------------------------------
23414 -- Check_OK_Stream_Convert_Function --
23415 --------------------------------------
23416
23417 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
23418 Ent : Entity_Id;
23419
23420 begin
23421 Check_Arg_Is_Local_Name (Arg);
23422 Ent := Entity (Get_Pragma_Arg (Arg));
23423
23424 if Has_Homonym (Ent) then
23425 Error_Pragma_Arg
23426 ("argument for pragma% may not be overloaded", Arg);
23427 end if;
23428
23429 if Ekind (Ent) /= E_Function
23430 or else No (First_Formal (Ent))
23431 or else Present (Next_Formal (First_Formal (Ent)))
23432 then
23433 Error_Pragma_Arg
23434 ("argument for pragma% must be function of one argument",
23435 Arg);
23436 end if;
23437 end Check_OK_Stream_Convert_Function;
23438
23439 -- Start of processing for Stream_Convert
23440
23441 begin
23442 GNAT_Pragma;
23443 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
23444 Check_Arg_Count (3);
23445 Check_Optional_Identifier (Arg1, Name_Entity);
23446 Check_Optional_Identifier (Arg2, Name_Read);
23447 Check_Optional_Identifier (Arg3, Name_Write);
23448 Check_Arg_Is_Local_Name (Arg1);
23449 Check_OK_Stream_Convert_Function (Arg2);
23450 Check_OK_Stream_Convert_Function (Arg3);
23451
23452 declare
23453 Typ : constant Entity_Id :=
23454 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
23455 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
23456 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
23457
23458 begin
23459 Check_First_Subtype (Arg1);
23460
23461 -- Check for too early or too late. Note that we don't enforce
23462 -- the rule about primitive operations in this case, since, as
23463 -- is the case for explicit stream attributes themselves, these
23464 -- restrictions are not appropriate. Note that the chaining of
23465 -- the pragma by Rep_Item_Too_Late is actually the critical
23466 -- processing done for this pragma.
23467
23468 if Rep_Item_Too_Early (Typ, N)
23469 or else
23470 Rep_Item_Too_Late (Typ, N, FOnly => True)
23471 then
23472 return;
23473 end if;
23474
23475 -- Return if previous error
23476
23477 if Etype (Typ) = Any_Type
23478 or else
23479 Etype (Read) = Any_Type
23480 or else
23481 Etype (Write) = Any_Type
23482 then
23483 return;
23484 end if;
23485
23486 -- Error checks
23487
23488 if Underlying_Type (Etype (Read)) /= Typ then
23489 Error_Pragma_Arg
23490 ("incorrect return type for function&", Arg2);
23491 end if;
23492
23493 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
23494 Error_Pragma_Arg
23495 ("incorrect parameter type for function&", Arg3);
23496 end if;
23497
23498 if Underlying_Type (Etype (First_Formal (Read))) /=
23499 Underlying_Type (Etype (Write))
23500 then
23501 Error_Pragma_Arg
23502 ("result type of & does not match Read parameter type",
23503 Arg3);
23504 end if;
23505 end;
23506 end Stream_Convert;
23507
23508 ------------------
23509 -- Style_Checks --
23510 ------------------
23511
23512 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
23513
23514 -- This is processed by the parser since some of the style checks
23515 -- take place during source scanning and parsing. This means that
23516 -- we don't need to issue error messages here.
23517
23518 when Pragma_Style_Checks => Style_Checks : declare
23519 A : constant Node_Id := Get_Pragma_Arg (Arg1);
23520 S : String_Id;
23521 C : Char_Code;
23522
23523 begin
23524 GNAT_Pragma;
23525 Check_No_Identifiers;
23526
23527 -- Two argument form
23528
23529 if Arg_Count = 2 then
23530 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23531
23532 declare
23533 E_Id : Node_Id;
23534 E : Entity_Id;
23535
23536 begin
23537 E_Id := Get_Pragma_Arg (Arg2);
23538 Analyze (E_Id);
23539
23540 if not Is_Entity_Name (E_Id) then
23541 Error_Pragma_Arg
23542 ("second argument of pragma% must be entity name",
23543 Arg2);
23544 end if;
23545
23546 E := Entity (E_Id);
23547
23548 if not Ignore_Style_Checks_Pragmas then
23549 if E = Any_Id then
23550 return;
23551 else
23552 loop
23553 Set_Suppress_Style_Checks
23554 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
23555 exit when No (Homonym (E));
23556 E := Homonym (E);
23557 end loop;
23558 end if;
23559 end if;
23560 end;
23561
23562 -- One argument form
23563
23564 else
23565 Check_Arg_Count (1);
23566
23567 if Nkind (A) = N_String_Literal then
23568 S := Strval (A);
23569
23570 declare
23571 Slen : constant Natural := Natural (String_Length (S));
23572 Options : String (1 .. Slen);
23573 J : Positive;
23574
23575 begin
23576 J := 1;
23577 loop
23578 C := Get_String_Char (S, Pos (J));
23579 exit when not In_Character_Range (C);
23580 Options (J) := Get_Character (C);
23581
23582 -- If at end of string, set options. As per discussion
23583 -- above, no need to check for errors, since we issued
23584 -- them in the parser.
23585
23586 if J = Slen then
23587 if not Ignore_Style_Checks_Pragmas then
23588 Set_Style_Check_Options (Options);
23589 end if;
23590
23591 exit;
23592 end if;
23593
23594 J := J + 1;
23595 end loop;
23596 end;
23597
23598 elsif Nkind (A) = N_Identifier then
23599 if Chars (A) = Name_All_Checks then
23600 if not Ignore_Style_Checks_Pragmas then
23601 if GNAT_Mode then
23602 Set_GNAT_Style_Check_Options;
23603 else
23604 Set_Default_Style_Check_Options;
23605 end if;
23606 end if;
23607
23608 elsif Chars (A) = Name_On then
23609 if not Ignore_Style_Checks_Pragmas then
23610 Style_Check := True;
23611 end if;
23612
23613 elsif Chars (A) = Name_Off then
23614 if not Ignore_Style_Checks_Pragmas then
23615 Style_Check := False;
23616 end if;
23617 end if;
23618 end if;
23619 end if;
23620 end Style_Checks;
23621
23622 --------------
23623 -- Subtitle --
23624 --------------
23625
23626 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
23627
23628 when Pragma_Subtitle =>
23629 GNAT_Pragma;
23630 Check_Arg_Count (1);
23631 Check_Optional_Identifier (Arg1, Name_Subtitle);
23632 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
23633 Store_Note (N);
23634
23635 --------------
23636 -- Suppress --
23637 --------------
23638
23639 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
23640
23641 when Pragma_Suppress =>
23642 Process_Suppress_Unsuppress (Suppress_Case => True);
23643
23644 ------------------
23645 -- Suppress_All --
23646 ------------------
23647
23648 -- pragma Suppress_All;
23649
23650 -- The only check made here is that the pragma has no arguments.
23651 -- There are no placement rules, and the processing required (setting
23652 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
23653 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
23654 -- then creates and inserts a pragma Suppress (All_Checks).
23655
23656 when Pragma_Suppress_All =>
23657 GNAT_Pragma;
23658 Check_Arg_Count (0);
23659
23660 -------------------------
23661 -- Suppress_Debug_Info --
23662 -------------------------
23663
23664 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
23665
23666 when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare
23667 Nam_Id : Entity_Id;
23668
23669 begin
23670 GNAT_Pragma;
23671 Check_Arg_Count (1);
23672 Check_Optional_Identifier (Arg1, Name_Entity);
23673 Check_Arg_Is_Local_Name (Arg1);
23674
23675 Nam_Id := Entity (Get_Pragma_Arg (Arg1));
23676
23677 -- A pragma that applies to a Ghost entity becomes Ghost for the
23678 -- purposes of legality checks and removal of ignored Ghost code.
23679
23680 Mark_Ghost_Pragma (N, Nam_Id);
23681 Set_Debug_Info_Off (Nam_Id);
23682 end Suppress_Debug_Info;
23683
23684 ----------------------------------
23685 -- Suppress_Exception_Locations --
23686 ----------------------------------
23687
23688 -- pragma Suppress_Exception_Locations;
23689
23690 when Pragma_Suppress_Exception_Locations =>
23691 GNAT_Pragma;
23692 Check_Arg_Count (0);
23693 Check_Valid_Configuration_Pragma;
23694 Exception_Locations_Suppressed := True;
23695
23696 -----------------------------
23697 -- Suppress_Initialization --
23698 -----------------------------
23699
23700 -- pragma Suppress_Initialization ([Entity =>] type_Name);
23701
23702 when Pragma_Suppress_Initialization => Suppress_Init : declare
23703 E : Entity_Id;
23704 E_Id : Node_Id;
23705
23706 begin
23707 GNAT_Pragma;
23708 Check_Arg_Count (1);
23709 Check_Optional_Identifier (Arg1, Name_Entity);
23710 Check_Arg_Is_Local_Name (Arg1);
23711
23712 E_Id := Get_Pragma_Arg (Arg1);
23713
23714 if Etype (E_Id) = Any_Type then
23715 return;
23716 end if;
23717
23718 E := Entity (E_Id);
23719
23720 -- A pragma that applies to a Ghost entity becomes Ghost for the
23721 -- purposes of legality checks and removal of ignored Ghost code.
23722
23723 Mark_Ghost_Pragma (N, E);
23724
23725 if not Is_Type (E) and then Ekind (E) /= E_Variable then
23726 Error_Pragma_Arg
23727 ("pragma% requires variable, type or subtype", Arg1);
23728 end if;
23729
23730 if Rep_Item_Too_Early (E, N)
23731 or else
23732 Rep_Item_Too_Late (E, N, FOnly => True)
23733 then
23734 return;
23735 end if;
23736
23737 -- For incomplete/private type, set flag on full view
23738
23739 if Is_Incomplete_Or_Private_Type (E) then
23740 if No (Full_View (Base_Type (E))) then
23741 Error_Pragma_Arg
23742 ("argument of pragma% cannot be an incomplete type", Arg1);
23743 else
23744 Set_Suppress_Initialization (Full_View (E));
23745 end if;
23746
23747 -- For first subtype, set flag on base type
23748
23749 elsif Is_First_Subtype (E) then
23750 Set_Suppress_Initialization (Base_Type (E));
23751
23752 -- For other than first subtype, set flag on subtype or variable
23753
23754 else
23755 Set_Suppress_Initialization (E);
23756 end if;
23757 end Suppress_Init;
23758
23759 -----------------
23760 -- System_Name --
23761 -----------------
23762
23763 -- pragma System_Name (DIRECT_NAME);
23764
23765 -- Syntax check: one argument, which must be the identifier GNAT or
23766 -- the identifier GCC, no other identifiers are acceptable.
23767
23768 when Pragma_System_Name =>
23769 GNAT_Pragma;
23770 Check_No_Identifiers;
23771 Check_Arg_Count (1);
23772 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
23773
23774 -----------------------------
23775 -- Task_Dispatching_Policy --
23776 -----------------------------
23777
23778 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
23779
23780 when Pragma_Task_Dispatching_Policy => declare
23781 DP : Character;
23782
23783 begin
23784 Check_Ada_83_Warning;
23785 Check_Arg_Count (1);
23786 Check_No_Identifiers;
23787 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
23788 Check_Valid_Configuration_Pragma;
23789 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
23790 DP := Fold_Upper (Name_Buffer (1));
23791
23792 if Task_Dispatching_Policy /= ' '
23793 and then Task_Dispatching_Policy /= DP
23794 then
23795 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
23796 Error_Pragma
23797 ("task dispatching policy incompatible with policy#");
23798
23799 -- Set new policy, but always preserve System_Location since we
23800 -- like the error message with the run time name.
23801
23802 else
23803 Task_Dispatching_Policy := DP;
23804
23805 if Task_Dispatching_Policy_Sloc /= System_Location then
23806 Task_Dispatching_Policy_Sloc := Loc;
23807 end if;
23808 end if;
23809 end;
23810
23811 ---------------
23812 -- Task_Info --
23813 ---------------
23814
23815 -- pragma Task_Info (EXPRESSION);
23816
23817 when Pragma_Task_Info => Task_Info : declare
23818 P : constant Node_Id := Parent (N);
23819 Ent : Entity_Id;
23820
23821 begin
23822 GNAT_Pragma;
23823
23824 if Warn_On_Obsolescent_Feature then
23825 Error_Msg_N
23826 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
23827 & "instead?j?", N);
23828 end if;
23829
23830 if Nkind (P) /= N_Task_Definition then
23831 Error_Pragma ("pragma% must appear in task definition");
23832 end if;
23833
23834 Check_No_Identifiers;
23835 Check_Arg_Count (1);
23836
23837 Analyze_And_Resolve
23838 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
23839
23840 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
23841 return;
23842 end if;
23843
23844 Ent := Defining_Identifier (Parent (P));
23845
23846 -- Check duplicate pragma before we chain the pragma in the Rep
23847 -- Item chain of Ent.
23848
23849 if Has_Rep_Pragma
23850 (Ent, Name_Task_Info, Check_Parents => False)
23851 then
23852 Error_Pragma ("duplicate pragma% not allowed");
23853 end if;
23854
23855 Record_Rep_Item (Ent, N);
23856 end Task_Info;
23857
23858 ---------------
23859 -- Task_Name --
23860 ---------------
23861
23862 -- pragma Task_Name (string_EXPRESSION);
23863
23864 when Pragma_Task_Name => Task_Name : declare
23865 P : constant Node_Id := Parent (N);
23866 Arg : Node_Id;
23867 Ent : Entity_Id;
23868
23869 begin
23870 Check_No_Identifiers;
23871 Check_Arg_Count (1);
23872
23873 Arg := Get_Pragma_Arg (Arg1);
23874
23875 -- The expression is used in the call to Create_Task, and must be
23876 -- expanded there, not in the context of the current spec. It must
23877 -- however be analyzed to capture global references, in case it
23878 -- appears in a generic context.
23879
23880 Preanalyze_And_Resolve (Arg, Standard_String);
23881
23882 if Nkind (P) /= N_Task_Definition then
23883 Pragma_Misplaced;
23884 end if;
23885
23886 Ent := Defining_Identifier (Parent (P));
23887
23888 -- Check duplicate pragma before we chain the pragma in the Rep
23889 -- Item chain of Ent.
23890
23891 if Has_Rep_Pragma
23892 (Ent, Name_Task_Name, Check_Parents => False)
23893 then
23894 Error_Pragma ("duplicate pragma% not allowed");
23895 end if;
23896
23897 Record_Rep_Item (Ent, N);
23898 end Task_Name;
23899
23900 ------------------
23901 -- Task_Storage --
23902 ------------------
23903
23904 -- pragma Task_Storage (
23905 -- [Task_Type =>] LOCAL_NAME,
23906 -- [Top_Guard =>] static_integer_EXPRESSION);
23907
23908 when Pragma_Task_Storage => Task_Storage : declare
23909 Args : Args_List (1 .. 2);
23910 Names : constant Name_List (1 .. 2) := (
23911 Name_Task_Type,
23912 Name_Top_Guard);
23913
23914 Task_Type : Node_Id renames Args (1);
23915 Top_Guard : Node_Id renames Args (2);
23916
23917 Ent : Entity_Id;
23918
23919 begin
23920 GNAT_Pragma;
23921 Gather_Associations (Names, Args);
23922
23923 if No (Task_Type) then
23924 Error_Pragma
23925 ("missing task_type argument for pragma%");
23926 end if;
23927
23928 Check_Arg_Is_Local_Name (Task_Type);
23929
23930 Ent := Entity (Task_Type);
23931
23932 if not Is_Task_Type (Ent) then
23933 Error_Pragma_Arg
23934 ("argument for pragma% must be task type", Task_Type);
23935 end if;
23936
23937 if No (Top_Guard) then
23938 Error_Pragma_Arg
23939 ("pragma% takes two arguments", Task_Type);
23940 else
23941 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
23942 end if;
23943
23944 Check_First_Subtype (Task_Type);
23945
23946 if Rep_Item_Too_Late (Ent, N) then
23947 raise Pragma_Exit;
23948 end if;
23949 end Task_Storage;
23950
23951 ---------------
23952 -- Test_Case --
23953 ---------------
23954
23955 -- pragma Test_Case
23956 -- ([Name =>] Static_String_EXPRESSION
23957 -- ,[Mode =>] MODE_TYPE
23958 -- [, Requires => Boolean_EXPRESSION]
23959 -- [, Ensures => Boolean_EXPRESSION]);
23960
23961 -- MODE_TYPE ::= Nominal | Robustness
23962
23963 -- Characteristics:
23964
23965 -- * Analysis - The annotation undergoes initial checks to verify
23966 -- the legal placement and context. Secondary checks preanalyze the
23967 -- expressions in:
23968
23969 -- Analyze_Test_Case_In_Decl_Part
23970
23971 -- * Expansion - None.
23972
23973 -- * Template - The annotation utilizes the generic template of the
23974 -- related subprogram when it is:
23975
23976 -- aspect on subprogram declaration
23977
23978 -- The annotation must prepare its own template when it is:
23979
23980 -- pragma on subprogram declaration
23981
23982 -- * Globals - Capture of global references must occur after full
23983 -- analysis.
23984
23985 -- * Instance - The annotation is instantiated automatically when
23986 -- the related generic subprogram is instantiated except for the
23987 -- "pragma on subprogram declaration" case. In that scenario the
23988 -- annotation must instantiate itself.
23989
23990 when Pragma_Test_Case => Test_Case : declare
23991 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
23992 -- Ensure that the contract of subprogram Subp_Id does not contain
23993 -- another Test_Case pragma with the same Name as the current one.
23994
23995 -------------------------
23996 -- Check_Distinct_Name --
23997 -------------------------
23998
23999 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
24000 Items : constant Node_Id := Contract (Subp_Id);
24001 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
24002 Prag : Node_Id;
24003
24004 begin
24005 -- Inspect all Test_Case pragma of the related subprogram
24006 -- looking for one with a duplicate "Name" argument.
24007
24008 if Present (Items) then
24009 Prag := Contract_Test_Cases (Items);
24010 while Present (Prag) loop
24011 if Pragma_Name (Prag) = Name_Test_Case
24012 and then Prag /= N
24013 and then String_Equal
24014 (Name, Get_Name_From_CTC_Pragma (Prag))
24015 then
24016 Error_Msg_Sloc := Sloc (Prag);
24017 Error_Pragma ("name for pragma % is already used #");
24018 end if;
24019
24020 Prag := Next_Pragma (Prag);
24021 end loop;
24022 end if;
24023 end Check_Distinct_Name;
24024
24025 -- Local variables
24026
24027 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
24028 Asp_Arg : Node_Id;
24029 Context : Node_Id;
24030 Subp_Decl : Node_Id;
24031 Subp_Id : Entity_Id;
24032
24033 -- Start of processing for Test_Case
24034
24035 begin
24036 GNAT_Pragma;
24037 Check_At_Least_N_Arguments (2);
24038 Check_At_Most_N_Arguments (4);
24039 Check_Arg_Order
24040 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
24041
24042 -- Argument "Name"
24043
24044 Check_Optional_Identifier (Arg1, Name_Name);
24045 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
24046
24047 -- Argument "Mode"
24048
24049 Check_Optional_Identifier (Arg2, Name_Mode);
24050 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
24051
24052 -- Arguments "Requires" and "Ensures"
24053
24054 if Present (Arg3) then
24055 if Present (Arg4) then
24056 Check_Identifier (Arg3, Name_Requires);
24057 Check_Identifier (Arg4, Name_Ensures);
24058 else
24059 Check_Identifier_Is_One_Of
24060 (Arg3, Name_Requires, Name_Ensures);
24061 end if;
24062 end if;
24063
24064 -- Pragma Test_Case must be associated with a subprogram declared
24065 -- in a library-level package. First determine whether the current
24066 -- compilation unit is a legal context.
24067
24068 if Nkind_In (Pack_Decl, N_Package_Declaration,
24069 N_Generic_Package_Declaration)
24070 then
24071 null;
24072
24073 -- Otherwise the placement is illegal
24074
24075 else
24076 Error_Pragma
24077 ("pragma % must be specified within a package declaration");
24078 return;
24079 end if;
24080
24081 Subp_Decl := Find_Related_Declaration_Or_Body (N);
24082
24083 -- Find the enclosing context
24084
24085 Context := Parent (Subp_Decl);
24086
24087 if Present (Context) then
24088 Context := Parent (Context);
24089 end if;
24090
24091 -- Verify the placement of the pragma
24092
24093 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
24094 Error_Pragma
24095 ("pragma % cannot be applied to abstract subprogram");
24096 return;
24097
24098 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
24099 Error_Pragma ("pragma % cannot be applied to entry");
24100 return;
24101
24102 -- The context is a [generic] subprogram declared at the top level
24103 -- of the [generic] package unit.
24104
24105 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
24106 N_Subprogram_Declaration)
24107 and then Present (Context)
24108 and then Nkind_In (Context, N_Generic_Package_Declaration,
24109 N_Package_Declaration)
24110 then
24111 null;
24112
24113 -- Otherwise the placement is illegal
24114
24115 else
24116 Error_Pragma
24117 ("pragma % must be applied to a library-level subprogram "
24118 & "declaration");
24119 return;
24120 end if;
24121
24122 Subp_Id := Defining_Entity (Subp_Decl);
24123
24124 -- A pragma that applies to a Ghost entity becomes Ghost for the
24125 -- purposes of legality checks and removal of ignored Ghost code.
24126
24127 Mark_Ghost_Pragma (N, Subp_Id);
24128
24129 -- Chain the pragma on the contract for further processing by
24130 -- Analyze_Test_Case_In_Decl_Part.
24131
24132 Add_Contract_Item (N, Subp_Id);
24133
24134 -- Preanalyze the original aspect argument "Name" for a generic
24135 -- subprogram to properly capture global references.
24136
24137 if Is_Generic_Subprogram (Subp_Id) then
24138 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
24139
24140 if Present (Asp_Arg) then
24141
24142 -- The argument appears with an identifier in association
24143 -- form.
24144
24145 if Nkind (Asp_Arg) = N_Component_Association then
24146 Asp_Arg := Expression (Asp_Arg);
24147 end if;
24148
24149 Check_Expr_Is_OK_Static_Expression
24150 (Asp_Arg, Standard_String);
24151 end if;
24152 end if;
24153
24154 -- Ensure that the all Test_Case pragmas of the related subprogram
24155 -- have distinct names.
24156
24157 Check_Distinct_Name (Subp_Id);
24158
24159 -- Fully analyze the pragma when it appears inside an entry
24160 -- or subprogram body because it cannot benefit from forward
24161 -- references.
24162
24163 if Nkind_In (Subp_Decl, N_Entry_Body,
24164 N_Subprogram_Body,
24165 N_Subprogram_Body_Stub)
24166 then
24167 -- The legality checks of pragma Test_Case are affected by the
24168 -- SPARK mode in effect and the volatility of the context.
24169 -- Analyze all pragmas in a specific order.
24170
24171 Analyze_If_Present (Pragma_SPARK_Mode);
24172 Analyze_If_Present (Pragma_Volatile_Function);
24173 Analyze_Test_Case_In_Decl_Part (N);
24174 end if;
24175 end Test_Case;
24176
24177 --------------------------
24178 -- Thread_Local_Storage --
24179 --------------------------
24180
24181 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
24182
24183 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
24184 E : Entity_Id;
24185 Id : Node_Id;
24186
24187 begin
24188 GNAT_Pragma;
24189 Check_Arg_Count (1);
24190 Check_Optional_Identifier (Arg1, Name_Entity);
24191 Check_Arg_Is_Library_Level_Local_Name (Arg1);
24192
24193 Id := Get_Pragma_Arg (Arg1);
24194 Analyze (Id);
24195
24196 if not Is_Entity_Name (Id)
24197 or else Ekind (Entity (Id)) /= E_Variable
24198 then
24199 Error_Pragma_Arg ("local variable name required", Arg1);
24200 end if;
24201
24202 E := Entity (Id);
24203
24204 -- A pragma that applies to a Ghost entity becomes Ghost for the
24205 -- purposes of legality checks and removal of ignored Ghost code.
24206
24207 Mark_Ghost_Pragma (N, E);
24208
24209 if Rep_Item_Too_Early (E, N)
24210 or else
24211 Rep_Item_Too_Late (E, N)
24212 then
24213 raise Pragma_Exit;
24214 end if;
24215
24216 Set_Has_Pragma_Thread_Local_Storage (E);
24217 Set_Has_Gigi_Rep_Item (E);
24218 end Thread_Local_Storage;
24219
24220 ----------------
24221 -- Time_Slice --
24222 ----------------
24223
24224 -- pragma Time_Slice (static_duration_EXPRESSION);
24225
24226 when Pragma_Time_Slice => Time_Slice : declare
24227 Val : Ureal;
24228 Nod : Node_Id;
24229
24230 begin
24231 GNAT_Pragma;
24232 Check_Arg_Count (1);
24233 Check_No_Identifiers;
24234 Check_In_Main_Program;
24235 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
24236
24237 if not Error_Posted (Arg1) then
24238 Nod := Next (N);
24239 while Present (Nod) loop
24240 if Nkind (Nod) = N_Pragma
24241 and then Pragma_Name (Nod) = Name_Time_Slice
24242 then
24243 Error_Msg_Name_1 := Pname;
24244 Error_Msg_N ("duplicate pragma% not permitted", Nod);
24245 end if;
24246
24247 Next (Nod);
24248 end loop;
24249 end if;
24250
24251 -- Process only if in main unit
24252
24253 if Get_Source_Unit (Loc) = Main_Unit then
24254 Opt.Time_Slice_Set := True;
24255 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
24256
24257 if Val <= Ureal_0 then
24258 Opt.Time_Slice_Value := 0;
24259
24260 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
24261 Opt.Time_Slice_Value := 1_000_000_000;
24262
24263 else
24264 Opt.Time_Slice_Value :=
24265 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
24266 end if;
24267 end if;
24268 end Time_Slice;
24269
24270 -----------
24271 -- Title --
24272 -----------
24273
24274 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
24275
24276 -- TITLING_OPTION ::=
24277 -- [Title =>] STRING_LITERAL
24278 -- | [Subtitle =>] STRING_LITERAL
24279
24280 when Pragma_Title => Title : declare
24281 Args : Args_List (1 .. 2);
24282 Names : constant Name_List (1 .. 2) := (
24283 Name_Title,
24284 Name_Subtitle);
24285
24286 begin
24287 GNAT_Pragma;
24288 Gather_Associations (Names, Args);
24289 Store_Note (N);
24290
24291 for J in 1 .. 2 loop
24292 if Present (Args (J)) then
24293 Check_Arg_Is_OK_Static_Expression
24294 (Args (J), Standard_String);
24295 end if;
24296 end loop;
24297 end Title;
24298
24299 ----------------------------
24300 -- Type_Invariant[_Class] --
24301 ----------------------------
24302
24303 -- pragma Type_Invariant[_Class]
24304 -- ([Entity =>] type_LOCAL_NAME,
24305 -- [Check =>] EXPRESSION);
24306
24307 when Pragma_Type_Invariant
24308 | Pragma_Type_Invariant_Class
24309 =>
24310 Type_Invariant : declare
24311 I_Pragma : Node_Id;
24312
24313 begin
24314 Check_Arg_Count (2);
24315
24316 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
24317 -- setting Class_Present for the Type_Invariant_Class case.
24318
24319 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
24320 I_Pragma := New_Copy (N);
24321 Set_Pragma_Identifier
24322 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
24323 Rewrite (N, I_Pragma);
24324 Set_Analyzed (N, False);
24325 Analyze (N);
24326 end Type_Invariant;
24327
24328 ---------------------
24329 -- Unchecked_Union --
24330 ---------------------
24331
24332 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
24333
24334 when Pragma_Unchecked_Union => Unchecked_Union : declare
24335 Assoc : constant Node_Id := Arg1;
24336 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
24337 Clist : Node_Id;
24338 Comp : Node_Id;
24339 Tdef : Node_Id;
24340 Typ : Entity_Id;
24341 Variant : Node_Id;
24342 Vpart : Node_Id;
24343
24344 begin
24345 Ada_2005_Pragma;
24346 Check_No_Identifiers;
24347 Check_Arg_Count (1);
24348 Check_Arg_Is_Local_Name (Arg1);
24349
24350 Find_Type (Type_Id);
24351
24352 Typ := Entity (Type_Id);
24353
24354 -- A pragma that applies to a Ghost entity becomes Ghost for the
24355 -- purposes of legality checks and removal of ignored Ghost code.
24356
24357 Mark_Ghost_Pragma (N, Typ);
24358
24359 if Typ = Any_Type
24360 or else Rep_Item_Too_Early (Typ, N)
24361 then
24362 return;
24363 else
24364 Typ := Underlying_Type (Typ);
24365 end if;
24366
24367 if Rep_Item_Too_Late (Typ, N) then
24368 return;
24369 end if;
24370
24371 Check_First_Subtype (Arg1);
24372
24373 -- Note remaining cases are references to a type in the current
24374 -- declarative part. If we find an error, we post the error on
24375 -- the relevant type declaration at an appropriate point.
24376
24377 if not Is_Record_Type (Typ) then
24378 Error_Msg_N ("unchecked union must be record type", Typ);
24379 return;
24380
24381 elsif Is_Tagged_Type (Typ) then
24382 Error_Msg_N ("unchecked union must not be tagged", Typ);
24383 return;
24384
24385 elsif not Has_Discriminants (Typ) then
24386 Error_Msg_N
24387 ("unchecked union must have one discriminant", Typ);
24388 return;
24389
24390 -- Note: in previous versions of GNAT we used to check for limited
24391 -- types and give an error, but in fact the standard does allow
24392 -- Unchecked_Union on limited types, so this check was removed.
24393
24394 -- Similarly, GNAT used to require that all discriminants have
24395 -- default values, but this is not mandated by the RM.
24396
24397 -- Proceed with basic error checks completed
24398
24399 else
24400 Tdef := Type_Definition (Declaration_Node (Typ));
24401 Clist := Component_List (Tdef);
24402
24403 -- Check presence of component list and variant part
24404
24405 if No (Clist) or else No (Variant_Part (Clist)) then
24406 Error_Msg_N
24407 ("unchecked union must have variant part", Tdef);
24408 return;
24409 end if;
24410
24411 -- Check components
24412
24413 Comp := First_Non_Pragma (Component_Items (Clist));
24414 while Present (Comp) loop
24415 Check_Component (Comp, Typ);
24416 Next_Non_Pragma (Comp);
24417 end loop;
24418
24419 -- Check variant part
24420
24421 Vpart := Variant_Part (Clist);
24422
24423 Variant := First_Non_Pragma (Variants (Vpart));
24424 while Present (Variant) loop
24425 Check_Variant (Variant, Typ);
24426 Next_Non_Pragma (Variant);
24427 end loop;
24428 end if;
24429
24430 Set_Is_Unchecked_Union (Typ);
24431 Set_Convention (Typ, Convention_C);
24432 Set_Has_Unchecked_Union (Base_Type (Typ));
24433 Set_Is_Unchecked_Union (Base_Type (Typ));
24434 end Unchecked_Union;
24435
24436 ----------------------------
24437 -- Unevaluated_Use_Of_Old --
24438 ----------------------------
24439
24440 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
24441
24442 when Pragma_Unevaluated_Use_Of_Old =>
24443 GNAT_Pragma;
24444 Check_Arg_Count (1);
24445 Check_No_Identifiers;
24446 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
24447
24448 -- Suppress/Unsuppress can appear as a configuration pragma, or in
24449 -- a declarative part or a package spec.
24450
24451 if not Is_Configuration_Pragma then
24452 Check_Is_In_Decl_Part_Or_Package_Spec;
24453 end if;
24454
24455 -- Store proper setting of Uneval_Old
24456
24457 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
24458 Uneval_Old := Fold_Upper (Name_Buffer (1));
24459
24460 ------------------------
24461 -- Unimplemented_Unit --
24462 ------------------------
24463
24464 -- pragma Unimplemented_Unit;
24465
24466 -- Note: this only gives an error if we are generating code, or if
24467 -- we are in a generic library unit (where the pragma appears in the
24468 -- body, not in the spec).
24469
24470 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
24471 Cunitent : constant Entity_Id :=
24472 Cunit_Entity (Get_Source_Unit (Loc));
24473 Ent_Kind : constant Entity_Kind := Ekind (Cunitent);
24474
24475 begin
24476 GNAT_Pragma;
24477 Check_Arg_Count (0);
24478
24479 if Operating_Mode = Generate_Code
24480 or else Ent_Kind = E_Generic_Function
24481 or else Ent_Kind = E_Generic_Procedure
24482 or else Ent_Kind = E_Generic_Package
24483 then
24484 Get_Name_String (Chars (Cunitent));
24485 Set_Casing (Mixed_Case);
24486 Write_Str (Name_Buffer (1 .. Name_Len));
24487 Write_Str (" is not supported in this configuration");
24488 Write_Eol;
24489 raise Unrecoverable_Error;
24490 end if;
24491 end Unimplemented_Unit;
24492
24493 ------------------------
24494 -- Universal_Aliasing --
24495 ------------------------
24496
24497 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
24498
24499 when Pragma_Universal_Aliasing => Universal_Alias : declare
24500 E : Entity_Id;
24501 E_Id : Node_Id;
24502
24503 begin
24504 GNAT_Pragma;
24505 Check_Arg_Count (1);
24506 Check_Optional_Identifier (Arg2, Name_Entity);
24507 Check_Arg_Is_Local_Name (Arg1);
24508 E_Id := Get_Pragma_Arg (Arg1);
24509
24510 if Etype (E_Id) = Any_Type then
24511 return;
24512 end if;
24513
24514 E := Entity (E_Id);
24515
24516 if not Is_Type (E) then
24517 Error_Pragma_Arg ("pragma% requires type", Arg1);
24518 end if;
24519
24520 -- A pragma that applies to a Ghost entity becomes Ghost for the
24521 -- purposes of legality checks and removal of ignored Ghost code.
24522
24523 Mark_Ghost_Pragma (N, E);
24524 Set_Universal_Aliasing (Base_Type (E));
24525 Record_Rep_Item (E, N);
24526 end Universal_Alias;
24527
24528 --------------------
24529 -- Universal_Data --
24530 --------------------
24531
24532 -- pragma Universal_Data [(library_unit_NAME)];
24533
24534 when Pragma_Universal_Data =>
24535 GNAT_Pragma;
24536 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
24537
24538 ----------------
24539 -- Unmodified --
24540 ----------------
24541
24542 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
24543
24544 when Pragma_Unmodified =>
24545 Analyze_Unmodified_Or_Unused;
24546
24547 ------------------
24548 -- Unreferenced --
24549 ------------------
24550
24551 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
24552
24553 -- or when used in a context clause:
24554
24555 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
24556
24557 when Pragma_Unreferenced =>
24558 Analyze_Unreferenced_Or_Unused;
24559
24560 --------------------------
24561 -- Unreferenced_Objects --
24562 --------------------------
24563
24564 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
24565
24566 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
24567 Arg : Node_Id;
24568 Arg_Expr : Node_Id;
24569 Arg_Id : Entity_Id;
24570
24571 Ghost_Error_Posted : Boolean := False;
24572 -- Flag set when an error concerning the illegal mix of Ghost and
24573 -- non-Ghost types is emitted.
24574
24575 Ghost_Id : Entity_Id := Empty;
24576 -- The entity of the first Ghost type encountered while processing
24577 -- the arguments of the pragma.
24578
24579 begin
24580 GNAT_Pragma;
24581 Check_At_Least_N_Arguments (1);
24582
24583 Arg := Arg1;
24584 while Present (Arg) loop
24585 Check_No_Identifier (Arg);
24586 Check_Arg_Is_Local_Name (Arg);
24587 Arg_Expr := Get_Pragma_Arg (Arg);
24588
24589 if Is_Entity_Name (Arg_Expr) then
24590 Arg_Id := Entity (Arg_Expr);
24591
24592 if Is_Type (Arg_Id) then
24593 Set_Has_Pragma_Unreferenced_Objects (Arg_Id);
24594
24595 -- A pragma that applies to a Ghost entity becomes Ghost
24596 -- for the purposes of legality checks and removal of
24597 -- ignored Ghost code.
24598
24599 Mark_Ghost_Pragma (N, Arg_Id);
24600
24601 -- Capture the entity of the first Ghost type being
24602 -- processed for error detection purposes.
24603
24604 if Is_Ghost_Entity (Arg_Id) then
24605 if No (Ghost_Id) then
24606 Ghost_Id := Arg_Id;
24607 end if;
24608
24609 -- Otherwise the type is non-Ghost. It is illegal to mix
24610 -- references to Ghost and non-Ghost entities
24611 -- (SPARK RM 6.9).
24612
24613 elsif Present (Ghost_Id)
24614 and then not Ghost_Error_Posted
24615 then
24616 Ghost_Error_Posted := True;
24617
24618 Error_Msg_Name_1 := Pname;
24619 Error_Msg_N
24620 ("pragma % cannot mention ghost and non-ghost types",
24621 N);
24622
24623 Error_Msg_Sloc := Sloc (Ghost_Id);
24624 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
24625
24626 Error_Msg_Sloc := Sloc (Arg_Id);
24627 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
24628 end if;
24629 else
24630 Error_Pragma_Arg
24631 ("argument for pragma% must be type or subtype", Arg);
24632 end if;
24633 else
24634 Error_Pragma_Arg
24635 ("argument for pragma% must be type or subtype", Arg);
24636 end if;
24637
24638 Next (Arg);
24639 end loop;
24640 end Unreferenced_Objects;
24641
24642 ------------------------------
24643 -- Unreserve_All_Interrupts --
24644 ------------------------------
24645
24646 -- pragma Unreserve_All_Interrupts;
24647
24648 when Pragma_Unreserve_All_Interrupts =>
24649 GNAT_Pragma;
24650 Check_Arg_Count (0);
24651
24652 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
24653 Unreserve_All_Interrupts := True;
24654 end if;
24655
24656 ----------------
24657 -- Unsuppress --
24658 ----------------
24659
24660 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
24661
24662 when Pragma_Unsuppress =>
24663 Ada_2005_Pragma;
24664 Process_Suppress_Unsuppress (Suppress_Case => False);
24665
24666 ------------
24667 -- Unused --
24668 ------------
24669
24670 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
24671
24672 when Pragma_Unused =>
24673 Analyze_Unmodified_Or_Unused (Is_Unused => True);
24674 Analyze_Unreferenced_Or_Unused (Is_Unused => True);
24675
24676 -------------------
24677 -- Use_VADS_Size --
24678 -------------------
24679
24680 -- pragma Use_VADS_Size;
24681
24682 when Pragma_Use_VADS_Size =>
24683 GNAT_Pragma;
24684 Check_Arg_Count (0);
24685 Check_Valid_Configuration_Pragma;
24686 Use_VADS_Size := True;
24687
24688 ---------------------
24689 -- Validity_Checks --
24690 ---------------------
24691
24692 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
24693
24694 when Pragma_Validity_Checks => Validity_Checks : declare
24695 A : constant Node_Id := Get_Pragma_Arg (Arg1);
24696 S : String_Id;
24697 C : Char_Code;
24698
24699 begin
24700 GNAT_Pragma;
24701 Check_Arg_Count (1);
24702 Check_No_Identifiers;
24703
24704 -- Pragma always active unless in CodePeer or GNATprove modes,
24705 -- which use a fixed configuration of validity checks.
24706
24707 if not (CodePeer_Mode or GNATprove_Mode) then
24708 if Nkind (A) = N_String_Literal then
24709 S := Strval (A);
24710
24711 declare
24712 Slen : constant Natural := Natural (String_Length (S));
24713 Options : String (1 .. Slen);
24714 J : Positive;
24715
24716 begin
24717 -- Couldn't we use a for loop here over Options'Range???
24718
24719 J := 1;
24720 loop
24721 C := Get_String_Char (S, Pos (J));
24722
24723 -- This is a weird test, it skips setting validity
24724 -- checks entirely if any element of S is out of
24725 -- range of Character, what is that about ???
24726
24727 exit when not In_Character_Range (C);
24728 Options (J) := Get_Character (C);
24729
24730 if J = Slen then
24731 Set_Validity_Check_Options (Options);
24732 exit;
24733 else
24734 J := J + 1;
24735 end if;
24736 end loop;
24737 end;
24738
24739 elsif Nkind (A) = N_Identifier then
24740 if Chars (A) = Name_All_Checks then
24741 Set_Validity_Check_Options ("a");
24742 elsif Chars (A) = Name_On then
24743 Validity_Checks_On := True;
24744 elsif Chars (A) = Name_Off then
24745 Validity_Checks_On := False;
24746 end if;
24747 end if;
24748 end if;
24749 end Validity_Checks;
24750
24751 --------------
24752 -- Volatile --
24753 --------------
24754
24755 -- pragma Volatile (LOCAL_NAME);
24756
24757 when Pragma_Volatile =>
24758 Process_Atomic_Independent_Shared_Volatile;
24759
24760 -------------------------
24761 -- Volatile_Components --
24762 -------------------------
24763
24764 -- pragma Volatile_Components (array_LOCAL_NAME);
24765
24766 -- Volatile is handled by the same circuit as Atomic_Components
24767
24768 --------------------------
24769 -- Volatile_Full_Access --
24770 --------------------------
24771
24772 -- pragma Volatile_Full_Access (LOCAL_NAME);
24773
24774 when Pragma_Volatile_Full_Access =>
24775 GNAT_Pragma;
24776 Process_Atomic_Independent_Shared_Volatile;
24777
24778 -----------------------
24779 -- Volatile_Function --
24780 -----------------------
24781
24782 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
24783
24784 when Pragma_Volatile_Function => Volatile_Function : declare
24785 Over_Id : Entity_Id;
24786 Spec_Id : Entity_Id;
24787 Subp_Decl : Node_Id;
24788
24789 begin
24790 GNAT_Pragma;
24791 Check_No_Identifiers;
24792 Check_At_Most_N_Arguments (1);
24793
24794 Subp_Decl :=
24795 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
24796
24797 -- Generic subprogram
24798
24799 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
24800 null;
24801
24802 -- Body acts as spec
24803
24804 elsif Nkind (Subp_Decl) = N_Subprogram_Body
24805 and then No (Corresponding_Spec (Subp_Decl))
24806 then
24807 null;
24808
24809 -- Body stub acts as spec
24810
24811 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
24812 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
24813 then
24814 null;
24815
24816 -- Subprogram
24817
24818 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
24819 null;
24820
24821 else
24822 Pragma_Misplaced;
24823 return;
24824 end if;
24825
24826 Spec_Id := Unique_Defining_Entity (Subp_Decl);
24827
24828 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
24829 Pragma_Misplaced;
24830 return;
24831 end if;
24832
24833 -- A pragma that applies to a Ghost entity becomes Ghost for the
24834 -- purposes of legality checks and removal of ignored Ghost code.
24835
24836 Mark_Ghost_Pragma (N, Spec_Id);
24837
24838 -- Chain the pragma on the contract for completeness
24839
24840 Add_Contract_Item (N, Spec_Id);
24841
24842 -- The legality checks of pragma Volatile_Function are affected by
24843 -- the SPARK mode in effect. Analyze all pragmas in a specific
24844 -- order.
24845
24846 Analyze_If_Present (Pragma_SPARK_Mode);
24847
24848 -- A volatile function cannot override a non-volatile function
24849 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
24850 -- in New_Overloaded_Entity, however at that point the pragma has
24851 -- not been processed yet.
24852
24853 Over_Id := Overridden_Operation (Spec_Id);
24854
24855 if Present (Over_Id)
24856 and then not Is_Volatile_Function (Over_Id)
24857 then
24858 Error_Msg_N
24859 ("incompatible volatile function values in effect", Spec_Id);
24860
24861 Error_Msg_Sloc := Sloc (Over_Id);
24862 Error_Msg_N
24863 ("\& declared # with Volatile_Function value False",
24864 Spec_Id);
24865
24866 Error_Msg_Sloc := Sloc (Spec_Id);
24867 Error_Msg_N
24868 ("\overridden # with Volatile_Function value True",
24869 Spec_Id);
24870 end if;
24871
24872 -- Analyze the Boolean expression (if any)
24873
24874 if Present (Arg1) then
24875 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
24876 end if;
24877 end Volatile_Function;
24878
24879 ----------------------
24880 -- Warning_As_Error --
24881 ----------------------
24882
24883 -- pragma Warning_As_Error (static_string_EXPRESSION);
24884
24885 when Pragma_Warning_As_Error =>
24886 GNAT_Pragma;
24887 Check_Arg_Count (1);
24888 Check_No_Identifiers;
24889 Check_Valid_Configuration_Pragma;
24890
24891 if not Is_Static_String_Expression (Arg1) then
24892 Error_Pragma_Arg
24893 ("argument of pragma% must be static string expression",
24894 Arg1);
24895
24896 -- OK static string expression
24897
24898 else
24899 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
24900 Warnings_As_Errors (Warnings_As_Errors_Count) :=
24901 new String'(Acquire_Warning_Match_String
24902 (Expr_Value_S (Get_Pragma_Arg (Arg1))));
24903 end if;
24904
24905 --------------
24906 -- Warnings --
24907 --------------
24908
24909 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
24910
24911 -- DETAILS ::= On | Off
24912 -- DETAILS ::= On | Off, local_NAME
24913 -- DETAILS ::= static_string_EXPRESSION
24914 -- DETAILS ::= On | Off, static_string_EXPRESSION
24915
24916 -- TOOL_NAME ::= GNAT | GNATProve
24917
24918 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
24919
24920 -- Note: If the first argument matches an allowed tool name, it is
24921 -- always considered to be a tool name, even if there is a string
24922 -- variable of that name.
24923
24924 -- Note if the second argument of DETAILS is a local_NAME then the
24925 -- second form is always understood. If the intention is to use
24926 -- the fourth form, then you can write NAME & "" to force the
24927 -- intepretation as a static_string_EXPRESSION.
24928
24929 when Pragma_Warnings => Warnings : declare
24930 Reason : String_Id;
24931
24932 begin
24933 GNAT_Pragma;
24934 Check_At_Least_N_Arguments (1);
24935
24936 -- See if last argument is labeled Reason. If so, make sure we
24937 -- have a string literal or a concatenation of string literals,
24938 -- and acquire the REASON string. Then remove the REASON argument
24939 -- by decreasing Num_Args by one; Remaining processing looks only
24940 -- at first Num_Args arguments).
24941
24942 declare
24943 Last_Arg : constant Node_Id :=
24944 Last (Pragma_Argument_Associations (N));
24945
24946 begin
24947 if Nkind (Last_Arg) = N_Pragma_Argument_Association
24948 and then Chars (Last_Arg) = Name_Reason
24949 then
24950 Start_String;
24951 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
24952 Reason := End_String;
24953 Arg_Count := Arg_Count - 1;
24954
24955 -- Not allowed in compiler units (bootstrap issues)
24956
24957 Check_Compiler_Unit ("Reason for pragma Warnings", N);
24958
24959 -- No REASON string, set null string as reason
24960
24961 else
24962 Reason := Null_String_Id;
24963 end if;
24964 end;
24965
24966 -- Now proceed with REASON taken care of and eliminated
24967
24968 Check_No_Identifiers;
24969
24970 -- If debug flag -gnatd.i is set, pragma is ignored
24971
24972 if Debug_Flag_Dot_I then
24973 return;
24974 end if;
24975
24976 -- Process various forms of the pragma
24977
24978 declare
24979 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
24980 Shifted_Args : List_Id;
24981
24982 begin
24983 -- See if first argument is a tool name, currently either
24984 -- GNAT or GNATprove. If so, either ignore the pragma if the
24985 -- tool used does not match, or continue as if no tool name
24986 -- was given otherwise, by shifting the arguments.
24987
24988 if Nkind (Argx) = N_Identifier
24989 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
24990 then
24991 if Chars (Argx) = Name_Gnat then
24992 if CodePeer_Mode or GNATprove_Mode then
24993 Rewrite (N, Make_Null_Statement (Loc));
24994 Analyze (N);
24995 raise Pragma_Exit;
24996 end if;
24997
24998 elsif Chars (Argx) = Name_Gnatprove then
24999 if not GNATprove_Mode then
25000 Rewrite (N, Make_Null_Statement (Loc));
25001 Analyze (N);
25002 raise Pragma_Exit;
25003 end if;
25004
25005 else
25006 raise Program_Error;
25007 end if;
25008
25009 -- At this point, the pragma Warnings applies to the tool,
25010 -- so continue with shifted arguments.
25011
25012 Arg_Count := Arg_Count - 1;
25013
25014 if Arg_Count = 1 then
25015 Shifted_Args := New_List (New_Copy (Arg2));
25016 elsif Arg_Count = 2 then
25017 Shifted_Args := New_List (New_Copy (Arg2),
25018 New_Copy (Arg3));
25019 elsif Arg_Count = 3 then
25020 Shifted_Args := New_List (New_Copy (Arg2),
25021 New_Copy (Arg3),
25022 New_Copy (Arg4));
25023 else
25024 raise Program_Error;
25025 end if;
25026
25027 Rewrite (N,
25028 Make_Pragma (Loc,
25029 Chars => Name_Warnings,
25030 Pragma_Argument_Associations => Shifted_Args));
25031 Analyze (N);
25032 raise Pragma_Exit;
25033 end if;
25034
25035 -- One argument case
25036
25037 if Arg_Count = 1 then
25038
25039 -- On/Off one argument case was processed by parser
25040
25041 if Nkind (Argx) = N_Identifier
25042 and then Nam_In (Chars (Argx), Name_On, Name_Off)
25043 then
25044 null;
25045
25046 -- One argument case must be ON/OFF or static string expr
25047
25048 elsif not Is_Static_String_Expression (Arg1) then
25049 Error_Pragma_Arg
25050 ("argument of pragma% must be On/Off or static string "
25051 & "expression", Arg1);
25052
25053 -- One argument string expression case
25054
25055 else
25056 declare
25057 Lit : constant Node_Id := Expr_Value_S (Argx);
25058 Str : constant String_Id := Strval (Lit);
25059 Len : constant Nat := String_Length (Str);
25060 C : Char_Code;
25061 J : Nat;
25062 OK : Boolean;
25063 Chr : Character;
25064
25065 begin
25066 J := 1;
25067 while J <= Len loop
25068 C := Get_String_Char (Str, J);
25069 OK := In_Character_Range (C);
25070
25071 if OK then
25072 Chr := Get_Character (C);
25073
25074 -- Dash case: only -Wxxx is accepted
25075
25076 if J = 1
25077 and then J < Len
25078 and then Chr = '-'
25079 then
25080 J := J + 1;
25081 C := Get_String_Char (Str, J);
25082 Chr := Get_Character (C);
25083 exit when Chr = 'W';
25084 OK := False;
25085
25086 -- Dot case
25087
25088 elsif J < Len and then Chr = '.' then
25089 J := J + 1;
25090 C := Get_String_Char (Str, J);
25091 Chr := Get_Character (C);
25092
25093 if not Set_Dot_Warning_Switch (Chr) then
25094 Error_Pragma_Arg
25095 ("invalid warning switch character "
25096 & '.' & Chr, Arg1);
25097 end if;
25098
25099 -- Non-Dot case
25100
25101 else
25102 OK := Set_Warning_Switch (Chr);
25103 end if;
25104
25105 if not OK then
25106 Error_Pragma_Arg
25107 ("invalid warning switch character " & Chr,
25108 Arg1);
25109 end if;
25110
25111 else
25112 Error_Pragma_Arg
25113 ("invalid wide character in warning switch ",
25114 Arg1);
25115 end if;
25116
25117 J := J + 1;
25118 end loop;
25119 end;
25120 end if;
25121
25122 -- Two or more arguments (must be two)
25123
25124 else
25125 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
25126 Check_Arg_Count (2);
25127
25128 declare
25129 E_Id : Node_Id;
25130 E : Entity_Id;
25131 Err : Boolean;
25132
25133 begin
25134 E_Id := Get_Pragma_Arg (Arg2);
25135 Analyze (E_Id);
25136
25137 -- In the expansion of an inlined body, a reference to
25138 -- the formal may be wrapped in a conversion if the
25139 -- actual is a conversion. Retrieve the real entity name.
25140
25141 if (In_Instance_Body or In_Inlined_Body)
25142 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
25143 then
25144 E_Id := Expression (E_Id);
25145 end if;
25146
25147 -- Entity name case
25148
25149 if Is_Entity_Name (E_Id) then
25150 E := Entity (E_Id);
25151
25152 if E = Any_Id then
25153 return;
25154 else
25155 loop
25156 Set_Warnings_Off
25157 (E, (Chars (Get_Pragma_Arg (Arg1)) =
25158 Name_Off));
25159
25160 -- Suppress elaboration warnings if the entity
25161 -- denotes an elaboration target.
25162
25163 if Is_Elaboration_Target (E) then
25164 Set_Is_Elaboration_Warnings_OK_Id (E, False);
25165 end if;
25166
25167 -- For OFF case, make entry in warnings off
25168 -- pragma table for later processing. But we do
25169 -- not do that within an instance, since these
25170 -- warnings are about what is needed in the
25171 -- template, not an instance of it.
25172
25173 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
25174 and then Warn_On_Warnings_Off
25175 and then not In_Instance
25176 then
25177 Warnings_Off_Pragmas.Append ((N, E, Reason));
25178 end if;
25179
25180 if Is_Enumeration_Type (E) then
25181 declare
25182 Lit : Entity_Id;
25183 begin
25184 Lit := First_Literal (E);
25185 while Present (Lit) loop
25186 Set_Warnings_Off (Lit);
25187 Next_Literal (Lit);
25188 end loop;
25189 end;
25190 end if;
25191
25192 exit when No (Homonym (E));
25193 E := Homonym (E);
25194 end loop;
25195 end if;
25196
25197 -- Error if not entity or static string expression case
25198
25199 elsif not Is_Static_String_Expression (Arg2) then
25200 Error_Pragma_Arg
25201 ("second argument of pragma% must be entity name "
25202 & "or static string expression", Arg2);
25203
25204 -- Static string expression case
25205
25206 else
25207 -- Note on configuration pragma case: If this is a
25208 -- configuration pragma, then for an OFF pragma, we
25209 -- just set Config True in the call, which is all
25210 -- that needs to be done. For the case of ON, this
25211 -- is normally an error, unless it is canceling the
25212 -- effect of a previous OFF pragma in the same file.
25213 -- In any other case, an error will be signalled (ON
25214 -- with no matching OFF).
25215
25216 -- Note: We set Used if we are inside a generic to
25217 -- disable the test that the non-config case actually
25218 -- cancels a warning. That's because we can't be sure
25219 -- there isn't an instantiation in some other unit
25220 -- where a warning is suppressed.
25221
25222 -- We could do a little better here by checking if the
25223 -- generic unit we are inside is public, but for now
25224 -- we don't bother with that refinement.
25225
25226 declare
25227 Message : constant String :=
25228 Acquire_Warning_Match_String
25229 (Expr_Value_S (Get_Pragma_Arg (Arg2)));
25230 begin
25231 if Chars (Argx) = Name_Off then
25232 Set_Specific_Warning_Off
25233 (Loc, Message, Reason,
25234 Config => Is_Configuration_Pragma,
25235 Used => Inside_A_Generic or else In_Instance);
25236
25237 elsif Chars (Argx) = Name_On then
25238 Set_Specific_Warning_On (Loc, Message, Err);
25239
25240 if Err then
25241 Error_Msg
25242 ("??pragma Warnings On with no matching "
25243 & "Warnings Off", Loc);
25244 end if;
25245 end if;
25246 end;
25247 end if;
25248 end;
25249 end if;
25250 end;
25251 end Warnings;
25252
25253 -------------------
25254 -- Weak_External --
25255 -------------------
25256
25257 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
25258
25259 when Pragma_Weak_External => Weak_External : declare
25260 Ent : Entity_Id;
25261
25262 begin
25263 GNAT_Pragma;
25264 Check_Arg_Count (1);
25265 Check_Optional_Identifier (Arg1, Name_Entity);
25266 Check_Arg_Is_Library_Level_Local_Name (Arg1);
25267 Ent := Entity (Get_Pragma_Arg (Arg1));
25268
25269 if Rep_Item_Too_Early (Ent, N) then
25270 return;
25271 else
25272 Ent := Underlying_Type (Ent);
25273 end if;
25274
25275 -- The pragma applies to entities with addresses
25276
25277 if Is_Type (Ent) then
25278 Error_Pragma ("pragma applies to objects and subprograms");
25279 end if;
25280
25281 -- The only processing required is to link this item on to the
25282 -- list of rep items for the given entity. This is accomplished
25283 -- by the call to Rep_Item_Too_Late (when no error is detected
25284 -- and False is returned).
25285
25286 if Rep_Item_Too_Late (Ent, N) then
25287 return;
25288 else
25289 Set_Has_Gigi_Rep_Item (Ent);
25290 end if;
25291 end Weak_External;
25292
25293 -----------------------------
25294 -- Wide_Character_Encoding --
25295 -----------------------------
25296
25297 -- pragma Wide_Character_Encoding (IDENTIFIER);
25298
25299 when Pragma_Wide_Character_Encoding =>
25300 GNAT_Pragma;
25301
25302 -- Nothing to do, handled in parser. Note that we do not enforce
25303 -- configuration pragma placement, this pragma can appear at any
25304 -- place in the source, allowing mixed encodings within a single
25305 -- source program.
25306
25307 null;
25308
25309 --------------------
25310 -- Unknown_Pragma --
25311 --------------------
25312
25313 -- Should be impossible, since the case of an unknown pragma is
25314 -- separately processed before the case statement is entered.
25315
25316 when Unknown_Pragma =>
25317 raise Program_Error;
25318 end case;
25319
25320 -- AI05-0144: detect dangerous order dependence. Disabled for now,
25321 -- until AI is formally approved.
25322
25323 -- Check_Order_Dependence;
25324
25325 exception
25326 when Pragma_Exit => null;
25327 end Analyze_Pragma;
25328
25329 ---------------------------------------------
25330 -- Analyze_Pre_Post_Condition_In_Decl_Part --
25331 ---------------------------------------------
25332
25333 -- WARNING: This routine manages Ghost regions. Return statements must be
25334 -- replaced by gotos which jump to the end of the routine and restore the
25335 -- Ghost mode.
25336
25337 procedure Analyze_Pre_Post_Condition_In_Decl_Part
25338 (N : Node_Id;
25339 Freeze_Id : Entity_Id := Empty)
25340 is
25341 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
25342 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
25343
25344 Disp_Typ : Entity_Id;
25345 -- The dispatching type of the subprogram subject to the pre- or
25346 -- postcondition.
25347
25348 function Check_References (Nod : Node_Id) return Traverse_Result;
25349 -- Check that expression Nod does not mention non-primitives of the
25350 -- type, global objects of the type, or other illegalities described
25351 -- and implied by AI12-0113.
25352
25353 ----------------------
25354 -- Check_References --
25355 ----------------------
25356
25357 function Check_References (Nod : Node_Id) return Traverse_Result is
25358 begin
25359 if Nkind (Nod) = N_Function_Call
25360 and then Is_Entity_Name (Name (Nod))
25361 then
25362 declare
25363 Func : constant Entity_Id := Entity (Name (Nod));
25364 Form : Entity_Id;
25365
25366 begin
25367 -- An operation of the type must be a primitive
25368
25369 if No (Find_Dispatching_Type (Func)) then
25370 Form := First_Formal (Func);
25371 while Present (Form) loop
25372 if Etype (Form) = Disp_Typ then
25373 Error_Msg_NE
25374 ("operation in class-wide condition must be "
25375 & "primitive of &", Nod, Disp_Typ);
25376 end if;
25377
25378 Next_Formal (Form);
25379 end loop;
25380
25381 -- A return object of the type is illegal as well
25382
25383 if Etype (Func) = Disp_Typ
25384 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
25385 then
25386 Error_Msg_NE
25387 ("operation in class-wide condition must be primitive "
25388 & "of &", Nod, Disp_Typ);
25389 end if;
25390
25391 -- Otherwise we have a call to an overridden primitive, and we
25392 -- will create a common class-wide clone for the body of
25393 -- original operation and its eventual inherited versions. If
25394 -- the original operation dispatches on result it is never
25395 -- inherited and there is no need for a clone. There is not
25396 -- need for a clone either in GNATprove mode, as cases that
25397 -- would require it are rejected (when an inherited primitive
25398 -- calls an overridden operation in a class-wide contract), and
25399 -- the clone would make proof impossible in some cases.
25400
25401 elsif not Is_Abstract_Subprogram (Spec_Id)
25402 and then No (Class_Wide_Clone (Spec_Id))
25403 and then not Has_Controlling_Result (Spec_Id)
25404 and then not GNATprove_Mode
25405 then
25406 Build_Class_Wide_Clone_Decl (Spec_Id);
25407 end if;
25408 end;
25409
25410 elsif Is_Entity_Name (Nod)
25411 and then
25412 (Etype (Nod) = Disp_Typ
25413 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
25414 and then Ekind_In (Entity (Nod), E_Constant, E_Variable)
25415 then
25416 Error_Msg_NE
25417 ("object in class-wide condition must be formal of type &",
25418 Nod, Disp_Typ);
25419
25420 elsif Nkind (Nod) = N_Explicit_Dereference
25421 and then (Etype (Nod) = Disp_Typ
25422 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
25423 and then (not Is_Entity_Name (Prefix (Nod))
25424 or else not Is_Formal (Entity (Prefix (Nod))))
25425 then
25426 Error_Msg_NE
25427 ("operation in class-wide condition must be primitive of &",
25428 Nod, Disp_Typ);
25429 end if;
25430
25431 return OK;
25432 end Check_References;
25433
25434 procedure Check_Class_Wide_Condition is
25435 new Traverse_Proc (Check_References);
25436
25437 -- Local variables
25438
25439 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
25440
25441 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
25442 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
25443 -- Save the Ghost-related attributes to restore on exit
25444
25445 Errors : Nat;
25446 Restore_Scope : Boolean := False;
25447
25448 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
25449
25450 begin
25451 -- Do not analyze the pragma multiple times
25452
25453 if Is_Analyzed_Pragma (N) then
25454 return;
25455 end if;
25456
25457 -- Set the Ghost mode in effect from the pragma. Due to the delayed
25458 -- analysis of the pragma, the Ghost mode at point of declaration and
25459 -- point of analysis may not necessarily be the same. Use the mode in
25460 -- effect at the point of declaration.
25461
25462 Set_Ghost_Mode (N);
25463
25464 -- Ensure that the subprogram and its formals are visible when analyzing
25465 -- the expression of the pragma.
25466
25467 if not In_Open_Scopes (Spec_Id) then
25468 Restore_Scope := True;
25469 Push_Scope (Spec_Id);
25470
25471 if Is_Generic_Subprogram (Spec_Id) then
25472 Install_Generic_Formals (Spec_Id);
25473 else
25474 Install_Formals (Spec_Id);
25475 end if;
25476 end if;
25477
25478 Errors := Serious_Errors_Detected;
25479 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
25480
25481 -- Emit a clarification message when the expression contains at least
25482 -- one undefined reference, possibly due to contract freezing.
25483
25484 if Errors /= Serious_Errors_Detected
25485 and then Present (Freeze_Id)
25486 and then Has_Undefined_Reference (Expr)
25487 then
25488 Contract_Freeze_Error (Spec_Id, Freeze_Id);
25489 end if;
25490
25491 if Class_Present (N) then
25492
25493 -- Verify that a class-wide condition is legal, i.e. the operation is
25494 -- a primitive of a tagged type. Note that a generic subprogram is
25495 -- not a primitive operation.
25496
25497 Disp_Typ := Find_Dispatching_Type (Spec_Id);
25498
25499 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
25500 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
25501
25502 if From_Aspect_Specification (N) then
25503 Error_Msg_N
25504 ("aspect % can only be specified for a primitive operation "
25505 & "of a tagged type", Corresponding_Aspect (N));
25506
25507 -- The pragma is a source construct
25508
25509 else
25510 Error_Msg_N
25511 ("pragma % can only be specified for a primitive operation "
25512 & "of a tagged type", N);
25513 end if;
25514
25515 -- Remaining semantic checks require a full tree traversal
25516
25517 else
25518 Check_Class_Wide_Condition (Expr);
25519 end if;
25520
25521 end if;
25522
25523 if Restore_Scope then
25524 End_Scope;
25525 end if;
25526
25527 -- If analysis of the condition indicates that a class-wide clone
25528 -- has been created, build and analyze its declaration.
25529
25530 if Is_Subprogram (Spec_Id)
25531 and then Present (Class_Wide_Clone (Spec_Id))
25532 then
25533 Analyze (Unit_Declaration_Node (Class_Wide_Clone (Spec_Id)));
25534 end if;
25535
25536 -- Currently it is not possible to inline pre/postconditions on a
25537 -- subprogram subject to pragma Inline_Always.
25538
25539 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
25540 Set_Is_Analyzed_Pragma (N);
25541
25542 Restore_Ghost_Region (Saved_GM, Saved_IGR);
25543 end Analyze_Pre_Post_Condition_In_Decl_Part;
25544
25545 ------------------------------------------
25546 -- Analyze_Refined_Depends_In_Decl_Part --
25547 ------------------------------------------
25548
25549 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
25550 procedure Check_Dependency_Clause
25551 (Spec_Id : Entity_Id;
25552 Dep_Clause : Node_Id;
25553 Dep_States : Elist_Id;
25554 Refinements : List_Id;
25555 Matched_Items : in out Elist_Id);
25556 -- Try to match a single dependency clause Dep_Clause against one or
25557 -- more refinement clauses found in list Refinements. Each successful
25558 -- match eliminates at least one refinement clause from Refinements.
25559 -- Spec_Id denotes the entity of the related subprogram. Dep_States
25560 -- denotes the entities of all abstract states which appear in pragma
25561 -- Depends. Matched_Items contains the entities of all successfully
25562 -- matched items found in pragma Depends.
25563
25564 procedure Check_Output_States
25565 (Spec_Inputs : Elist_Id;
25566 Spec_Outputs : Elist_Id;
25567 Body_Inputs : Elist_Id;
25568 Body_Outputs : Elist_Id);
25569 -- Determine whether pragma Depends contains an output state with a
25570 -- visible refinement and if so, ensure that pragma Refined_Depends
25571 -- mentions all its constituents as outputs. Spec_Inputs and
25572 -- Spec_Outputs denote the inputs and outputs of the subprogram spec
25573 -- synthesized from pragma Depends. Body_Inputs and Body_Outputs denote
25574 -- the inputs and outputs of the subprogram body synthesized from pragma
25575 -- Refined_Depends.
25576
25577 function Collect_States (Clauses : List_Id) return Elist_Id;
25578 -- Given a normalized list of dependencies obtained from calling
25579 -- Normalize_Clauses, return a list containing the entities of all
25580 -- states appearing in dependencies. It helps in checking refinements
25581 -- involving a state and a corresponding constituent which is not a
25582 -- direct constituent of the state.
25583
25584 procedure Normalize_Clauses (Clauses : List_Id);
25585 -- Given a list of dependence or refinement clauses Clauses, normalize
25586 -- each clause by creating multiple dependencies with exactly one input
25587 -- and one output.
25588
25589 procedure Remove_Extra_Clauses
25590 (Clauses : List_Id;
25591 Matched_Items : Elist_Id);
25592 -- Given a list of refinement clauses Clauses, remove all clauses whose
25593 -- inputs and/or outputs have been previously matched. See the body for
25594 -- all special cases. Matched_Items contains the entities of all matched
25595 -- items found in pragma Depends.
25596
25597 procedure Report_Extra_Clauses (Clauses : List_Id);
25598 -- Emit an error for each extra clause found in list Clauses
25599
25600 -----------------------------
25601 -- Check_Dependency_Clause --
25602 -----------------------------
25603
25604 procedure Check_Dependency_Clause
25605 (Spec_Id : Entity_Id;
25606 Dep_Clause : Node_Id;
25607 Dep_States : Elist_Id;
25608 Refinements : List_Id;
25609 Matched_Items : in out Elist_Id)
25610 is
25611 Dep_Input : constant Node_Id := Expression (Dep_Clause);
25612 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
25613
25614 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
25615 -- Determine whether dependency item Dep_Item has been matched in a
25616 -- previous clause.
25617
25618 function Is_In_Out_State_Clause return Boolean;
25619 -- Determine whether dependence clause Dep_Clause denotes an abstract
25620 -- state that depends on itself (State => State).
25621
25622 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
25623 -- Determine whether item Item denotes an abstract state with visible
25624 -- null refinement.
25625
25626 procedure Match_Items
25627 (Dep_Item : Node_Id;
25628 Ref_Item : Node_Id;
25629 Matched : out Boolean);
25630 -- Try to match dependence item Dep_Item against refinement item
25631 -- Ref_Item. To match against a possible null refinement (see 2, 9),
25632 -- set Ref_Item to Empty. Flag Matched is set to True when one of
25633 -- the following conformance scenarios is in effect:
25634 -- 1) Both items denote null
25635 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
25636 -- 3) Both items denote attribute 'Result
25637 -- 4) Both items denote the same object
25638 -- 5) Both items denote the same formal parameter
25639 -- 6) Both items denote the same current instance of a type
25640 -- 7) Both items denote the same discriminant
25641 -- 8) Dep_Item is an abstract state with visible null refinement
25642 -- and Ref_Item denotes null.
25643 -- 9) Dep_Item is an abstract state with visible null refinement
25644 -- and Ref_Item is Empty (special case).
25645 -- 10) Dep_Item is an abstract state with full or partial visible
25646 -- non-null refinement and Ref_Item denotes one of its
25647 -- constituents.
25648 -- 11) Dep_Item is an abstract state without a full visible
25649 -- refinement and Ref_Item denotes the same state.
25650 -- When scenario 10 is in effect, the entity of the abstract state
25651 -- denoted by Dep_Item is added to list Refined_States.
25652
25653 procedure Record_Item (Item_Id : Entity_Id);
25654 -- Store the entity of an item denoted by Item_Id in Matched_Items
25655
25656 ------------------------
25657 -- Is_Already_Matched --
25658 ------------------------
25659
25660 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean is
25661 Item_Id : Entity_Id := Empty;
25662
25663 begin
25664 -- When the dependency item denotes attribute 'Result, check for
25665 -- the entity of the related subprogram.
25666
25667 if Is_Attribute_Result (Dep_Item) then
25668 Item_Id := Spec_Id;
25669
25670 elsif Is_Entity_Name (Dep_Item) then
25671 Item_Id := Available_View (Entity_Of (Dep_Item));
25672 end if;
25673
25674 return
25675 Present (Item_Id) and then Contains (Matched_Items, Item_Id);
25676 end Is_Already_Matched;
25677
25678 ----------------------------
25679 -- Is_In_Out_State_Clause --
25680 ----------------------------
25681
25682 function Is_In_Out_State_Clause return Boolean is
25683 Dep_Input_Id : Entity_Id;
25684 Dep_Output_Id : Entity_Id;
25685
25686 begin
25687 -- Detect the following clause:
25688 -- State => State
25689
25690 if Is_Entity_Name (Dep_Input)
25691 and then Is_Entity_Name (Dep_Output)
25692 then
25693 -- Handle abstract views generated for limited with clauses
25694
25695 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
25696 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
25697
25698 return
25699 Ekind (Dep_Input_Id) = E_Abstract_State
25700 and then Dep_Input_Id = Dep_Output_Id;
25701 else
25702 return False;
25703 end if;
25704 end Is_In_Out_State_Clause;
25705
25706 ---------------------------
25707 -- Is_Null_Refined_State --
25708 ---------------------------
25709
25710 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
25711 Item_Id : Entity_Id;
25712
25713 begin
25714 if Is_Entity_Name (Item) then
25715
25716 -- Handle abstract views generated for limited with clauses
25717
25718 Item_Id := Available_View (Entity_Of (Item));
25719
25720 return
25721 Ekind (Item_Id) = E_Abstract_State
25722 and then Has_Null_Visible_Refinement (Item_Id);
25723 else
25724 return False;
25725 end if;
25726 end Is_Null_Refined_State;
25727
25728 -----------------
25729 -- Match_Items --
25730 -----------------
25731
25732 procedure Match_Items
25733 (Dep_Item : Node_Id;
25734 Ref_Item : Node_Id;
25735 Matched : out Boolean)
25736 is
25737 Dep_Item_Id : Entity_Id;
25738 Ref_Item_Id : Entity_Id;
25739
25740 begin
25741 -- Assume that the two items do not match
25742
25743 Matched := False;
25744
25745 -- A null matches null or Empty (special case)
25746
25747 if Nkind (Dep_Item) = N_Null
25748 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
25749 then
25750 Matched := True;
25751
25752 -- Attribute 'Result matches attribute 'Result
25753
25754 elsif Is_Attribute_Result (Dep_Item)
25755 and then Is_Attribute_Result (Ref_Item)
25756 then
25757 -- Put the entity of the related function on the list of
25758 -- matched items because attribute 'Result does not carry
25759 -- an entity similar to states and constituents.
25760
25761 Record_Item (Spec_Id);
25762 Matched := True;
25763
25764 -- Abstract states, current instances of concurrent types,
25765 -- discriminants, formal parameters and objects.
25766
25767 elsif Is_Entity_Name (Dep_Item) then
25768
25769 -- Handle abstract views generated for limited with clauses
25770
25771 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
25772
25773 if Ekind (Dep_Item_Id) = E_Abstract_State then
25774
25775 -- An abstract state with visible null refinement matches
25776 -- null or Empty (special case).
25777
25778 if Has_Null_Visible_Refinement (Dep_Item_Id)
25779 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
25780 then
25781 Record_Item (Dep_Item_Id);
25782 Matched := True;
25783
25784 -- An abstract state with visible non-null refinement
25785 -- matches one of its constituents, or itself for an
25786 -- abstract state with partial visible refinement.
25787
25788 elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then
25789 if Is_Entity_Name (Ref_Item) then
25790 Ref_Item_Id := Entity_Of (Ref_Item);
25791
25792 if Ekind_In (Ref_Item_Id, E_Abstract_State,
25793 E_Constant,
25794 E_Variable)
25795 and then Present (Encapsulating_State (Ref_Item_Id))
25796 and then Find_Encapsulating_State
25797 (Dep_States, Ref_Item_Id) = Dep_Item_Id
25798 then
25799 Record_Item (Dep_Item_Id);
25800 Matched := True;
25801
25802 elsif not Has_Visible_Refinement (Dep_Item_Id)
25803 and then Ref_Item_Id = Dep_Item_Id
25804 then
25805 Record_Item (Dep_Item_Id);
25806 Matched := True;
25807 end if;
25808 end if;
25809
25810 -- An abstract state without a visible refinement matches
25811 -- itself.
25812
25813 elsif Is_Entity_Name (Ref_Item)
25814 and then Entity_Of (Ref_Item) = Dep_Item_Id
25815 then
25816 Record_Item (Dep_Item_Id);
25817 Matched := True;
25818 end if;
25819
25820 -- A current instance of a concurrent type, discriminant,
25821 -- formal parameter or an object matches itself.
25822
25823 elsif Is_Entity_Name (Ref_Item)
25824 and then Entity_Of (Ref_Item) = Dep_Item_Id
25825 then
25826 Record_Item (Dep_Item_Id);
25827 Matched := True;
25828 end if;
25829 end if;
25830 end Match_Items;
25831
25832 -----------------
25833 -- Record_Item --
25834 -----------------
25835
25836 procedure Record_Item (Item_Id : Entity_Id) is
25837 begin
25838 if No (Matched_Items) then
25839 Matched_Items := New_Elmt_List;
25840 end if;
25841
25842 Append_Unique_Elmt (Item_Id, Matched_Items);
25843 end Record_Item;
25844
25845 -- Local variables
25846
25847 Clause_Matched : Boolean := False;
25848 Dummy : Boolean := False;
25849 Inputs_Match : Boolean;
25850 Next_Ref_Clause : Node_Id;
25851 Outputs_Match : Boolean;
25852 Ref_Clause : Node_Id;
25853 Ref_Input : Node_Id;
25854 Ref_Output : Node_Id;
25855
25856 -- Start of processing for Check_Dependency_Clause
25857
25858 begin
25859 -- Do not perform this check in an instance because it was already
25860 -- performed successfully in the generic template.
25861
25862 if In_Instance then
25863 return;
25864 end if;
25865
25866 -- Examine all refinement clauses and compare them against the
25867 -- dependence clause.
25868
25869 Ref_Clause := First (Refinements);
25870 while Present (Ref_Clause) loop
25871 Next_Ref_Clause := Next (Ref_Clause);
25872
25873 -- Obtain the attributes of the current refinement clause
25874
25875 Ref_Input := Expression (Ref_Clause);
25876 Ref_Output := First (Choices (Ref_Clause));
25877
25878 -- The current refinement clause matches the dependence clause
25879 -- when both outputs match and both inputs match. See routine
25880 -- Match_Items for all possible conformance scenarios.
25881
25882 -- Depends Dep_Output => Dep_Input
25883 -- ^ ^
25884 -- match ? match ?
25885 -- v v
25886 -- Refined_Depends Ref_Output => Ref_Input
25887
25888 Match_Items
25889 (Dep_Item => Dep_Input,
25890 Ref_Item => Ref_Input,
25891 Matched => Inputs_Match);
25892
25893 Match_Items
25894 (Dep_Item => Dep_Output,
25895 Ref_Item => Ref_Output,
25896 Matched => Outputs_Match);
25897
25898 -- An In_Out state clause may be matched against a refinement with
25899 -- a null input or null output as long as the non-null side of the
25900 -- relation contains a valid constituent of the In_Out_State.
25901
25902 if Is_In_Out_State_Clause then
25903
25904 -- Depends => (State => State)
25905 -- Refined_Depends => (null => Constit) -- OK
25906
25907 if Inputs_Match
25908 and then not Outputs_Match
25909 and then Nkind (Ref_Output) = N_Null
25910 then
25911 Outputs_Match := True;
25912 end if;
25913
25914 -- Depends => (State => State)
25915 -- Refined_Depends => (Constit => null) -- OK
25916
25917 if not Inputs_Match
25918 and then Outputs_Match
25919 and then Nkind (Ref_Input) = N_Null
25920 then
25921 Inputs_Match := True;
25922 end if;
25923 end if;
25924
25925 -- The current refinement clause is legally constructed following
25926 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
25927 -- the pool of candidates. The seach continues because a single
25928 -- dependence clause may have multiple matching refinements.
25929
25930 if Inputs_Match and Outputs_Match then
25931 Clause_Matched := True;
25932 Remove (Ref_Clause);
25933 end if;
25934
25935 Ref_Clause := Next_Ref_Clause;
25936 end loop;
25937
25938 -- Depending on the order or composition of refinement clauses, an
25939 -- In_Out state clause may not be directly refinable.
25940
25941 -- Refined_State => (State => (Constit_1, Constit_2))
25942 -- Depends => ((Output, State) => (Input, State))
25943 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
25944
25945 -- Matching normalized clause (State => State) fails because there is
25946 -- no direct refinement capable of satisfying this relation. Another
25947 -- similar case arises when clauses (Constit_1 => Input) and (Output
25948 -- => Constit_2) are matched first, leaving no candidates for clause
25949 -- (State => State). Both scenarios are legal as long as one of the
25950 -- previous clauses mentioned a valid constituent of State.
25951
25952 if not Clause_Matched
25953 and then Is_In_Out_State_Clause
25954 and then Is_Already_Matched (Dep_Input)
25955 then
25956 Clause_Matched := True;
25957 end if;
25958
25959 -- A clause where the input is an abstract state with visible null
25960 -- refinement or a 'Result attribute is implicitly matched when the
25961 -- output has already been matched in a previous clause.
25962
25963 -- Refined_State => (State => null)
25964 -- Depends => (Output => State) -- implicitly OK
25965 -- Refined_Depends => (Output => ...)
25966 -- Depends => (...'Result => State) -- implicitly OK
25967 -- Refined_Depends => (...'Result => ...)
25968
25969 if not Clause_Matched
25970 and then Is_Null_Refined_State (Dep_Input)
25971 and then Is_Already_Matched (Dep_Output)
25972 then
25973 Clause_Matched := True;
25974 end if;
25975
25976 -- A clause where the output is an abstract state with visible null
25977 -- refinement is implicitly matched when the input has already been
25978 -- matched in a previous clause.
25979
25980 -- Refined_State => (State => null)
25981 -- Depends => (State => Input) -- implicitly OK
25982 -- Refined_Depends => (... => Input)
25983
25984 if not Clause_Matched
25985 and then Is_Null_Refined_State (Dep_Output)
25986 and then Is_Already_Matched (Dep_Input)
25987 then
25988 Clause_Matched := True;
25989 end if;
25990
25991 -- At this point either all refinement clauses have been examined or
25992 -- pragma Refined_Depends contains a solitary null. Only an abstract
25993 -- state with null refinement can possibly match these cases.
25994
25995 -- Refined_State => (State => null)
25996 -- Depends => (State => null)
25997 -- Refined_Depends => null -- OK
25998
25999 if not Clause_Matched then
26000 Match_Items
26001 (Dep_Item => Dep_Input,
26002 Ref_Item => Empty,
26003 Matched => Inputs_Match);
26004
26005 Match_Items
26006 (Dep_Item => Dep_Output,
26007 Ref_Item => Empty,
26008 Matched => Outputs_Match);
26009
26010 Clause_Matched := Inputs_Match and Outputs_Match;
26011 end if;
26012
26013 -- If the contents of Refined_Depends are legal, then the current
26014 -- dependence clause should be satisfied either by an explicit match
26015 -- or by one of the special cases.
26016
26017 if not Clause_Matched then
26018 SPARK_Msg_NE
26019 (Fix_Msg (Spec_Id, "dependence clause of subprogram & has no "
26020 & "matching refinement in body"), Dep_Clause, Spec_Id);
26021 end if;
26022 end Check_Dependency_Clause;
26023
26024 -------------------------
26025 -- Check_Output_States --
26026 -------------------------
26027
26028 procedure Check_Output_States
26029 (Spec_Inputs : Elist_Id;
26030 Spec_Outputs : Elist_Id;
26031 Body_Inputs : Elist_Id;
26032 Body_Outputs : Elist_Id)
26033 is
26034 procedure Check_Constituent_Usage (State_Id : Entity_Id);
26035 -- Determine whether all constituents of state State_Id with full
26036 -- visible refinement are used as outputs in pragma Refined_Depends.
26037 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
26038
26039 -----------------------------
26040 -- Check_Constituent_Usage --
26041 -----------------------------
26042
26043 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
26044 Constits : constant Elist_Id :=
26045 Partial_Refinement_Constituents (State_Id);
26046 Constit_Elmt : Elmt_Id;
26047 Constit_Id : Entity_Id;
26048 Only_Partial : constant Boolean :=
26049 not Has_Visible_Refinement (State_Id);
26050 Posted : Boolean := False;
26051
26052 begin
26053 if Present (Constits) then
26054 Constit_Elmt := First_Elmt (Constits);
26055 while Present (Constit_Elmt) loop
26056 Constit_Id := Node (Constit_Elmt);
26057
26058 -- Issue an error when a constituent of State_Id is used,
26059 -- and State_Id has only partial visible refinement
26060 -- (SPARK RM 7.2.4(3d)).
26061
26062 if Only_Partial then
26063 if (Present (Body_Inputs)
26064 and then Appears_In (Body_Inputs, Constit_Id))
26065 or else
26066 (Present (Body_Outputs)
26067 and then Appears_In (Body_Outputs, Constit_Id))
26068 then
26069 Error_Msg_Name_1 := Chars (State_Id);
26070 SPARK_Msg_NE
26071 ("constituent & of state % cannot be used in "
26072 & "dependence refinement", N, Constit_Id);
26073 Error_Msg_Name_1 := Chars (State_Id);
26074 SPARK_Msg_N ("\use state % instead", N);
26075 end if;
26076
26077 -- The constituent acts as an input (SPARK RM 7.2.5(3))
26078
26079 elsif Present (Body_Inputs)
26080 and then Appears_In (Body_Inputs, Constit_Id)
26081 then
26082 Error_Msg_Name_1 := Chars (State_Id);
26083 SPARK_Msg_NE
26084 ("constituent & of state % must act as output in "
26085 & "dependence refinement", N, Constit_Id);
26086
26087 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
26088
26089 elsif No (Body_Outputs)
26090 or else not Appears_In (Body_Outputs, Constit_Id)
26091 then
26092 if not Posted then
26093 Posted := True;
26094 SPARK_Msg_NE
26095 ("output state & must be replaced by all its "
26096 & "constituents in dependence refinement",
26097 N, State_Id);
26098 end if;
26099
26100 SPARK_Msg_NE
26101 ("\constituent & is missing in output list",
26102 N, Constit_Id);
26103 end if;
26104
26105 Next_Elmt (Constit_Elmt);
26106 end loop;
26107 end if;
26108 end Check_Constituent_Usage;
26109
26110 -- Local variables
26111
26112 Item : Node_Id;
26113 Item_Elmt : Elmt_Id;
26114 Item_Id : Entity_Id;
26115
26116 -- Start of processing for Check_Output_States
26117
26118 begin
26119 -- Do not perform this check in an instance because it was already
26120 -- performed successfully in the generic template.
26121
26122 if In_Instance then
26123 null;
26124
26125 -- Inspect the outputs of pragma Depends looking for a state with a
26126 -- visible refinement.
26127
26128 elsif Present (Spec_Outputs) then
26129 Item_Elmt := First_Elmt (Spec_Outputs);
26130 while Present (Item_Elmt) loop
26131 Item := Node (Item_Elmt);
26132
26133 -- Deal with the mixed nature of the input and output lists
26134
26135 if Nkind (Item) = N_Defining_Identifier then
26136 Item_Id := Item;
26137 else
26138 Item_Id := Available_View (Entity_Of (Item));
26139 end if;
26140
26141 if Ekind (Item_Id) = E_Abstract_State then
26142
26143 -- The state acts as an input-output, skip it
26144
26145 if Present (Spec_Inputs)
26146 and then Appears_In (Spec_Inputs, Item_Id)
26147 then
26148 null;
26149
26150 -- Ensure that all of the constituents are utilized as
26151 -- outputs in pragma Refined_Depends.
26152
26153 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
26154 Check_Constituent_Usage (Item_Id);
26155 end if;
26156 end if;
26157
26158 Next_Elmt (Item_Elmt);
26159 end loop;
26160 end if;
26161 end Check_Output_States;
26162
26163 --------------------
26164 -- Collect_States --
26165 --------------------
26166
26167 function Collect_States (Clauses : List_Id) return Elist_Id is
26168 procedure Collect_State
26169 (Item : Node_Id;
26170 States : in out Elist_Id);
26171 -- Add the entity of Item to list States when it denotes to a state
26172
26173 -------------------
26174 -- Collect_State --
26175 -------------------
26176
26177 procedure Collect_State
26178 (Item : Node_Id;
26179 States : in out Elist_Id)
26180 is
26181 Id : Entity_Id;
26182
26183 begin
26184 if Is_Entity_Name (Item) then
26185 Id := Entity_Of (Item);
26186
26187 if Ekind (Id) = E_Abstract_State then
26188 if No (States) then
26189 States := New_Elmt_List;
26190 end if;
26191
26192 Append_Unique_Elmt (Id, States);
26193 end if;
26194 end if;
26195 end Collect_State;
26196
26197 -- Local variables
26198
26199 Clause : Node_Id;
26200 Input : Node_Id;
26201 Output : Node_Id;
26202 States : Elist_Id := No_Elist;
26203
26204 -- Start of processing for Collect_States
26205
26206 begin
26207 Clause := First (Clauses);
26208 while Present (Clause) loop
26209 Input := Expression (Clause);
26210 Output := First (Choices (Clause));
26211
26212 Collect_State (Input, States);
26213 Collect_State (Output, States);
26214
26215 Next (Clause);
26216 end loop;
26217
26218 return States;
26219 end Collect_States;
26220
26221 -----------------------
26222 -- Normalize_Clauses --
26223 -----------------------
26224
26225 procedure Normalize_Clauses (Clauses : List_Id) is
26226 procedure Normalize_Inputs (Clause : Node_Id);
26227 -- Normalize clause Clause by creating multiple clauses for each
26228 -- input item of Clause. It is assumed that Clause has exactly one
26229 -- output. The transformation is as follows:
26230 --
26231 -- Output => (Input_1, Input_2) -- original
26232 --
26233 -- Output => Input_1 -- normalizations
26234 -- Output => Input_2
26235
26236 procedure Normalize_Outputs (Clause : Node_Id);
26237 -- Normalize clause Clause by creating multiple clause for each
26238 -- output item of Clause. The transformation is as follows:
26239 --
26240 -- (Output_1, Output_2) => Input -- original
26241 --
26242 -- Output_1 => Input -- normalization
26243 -- Output_2 => Input
26244
26245 ----------------------
26246 -- Normalize_Inputs --
26247 ----------------------
26248
26249 procedure Normalize_Inputs (Clause : Node_Id) is
26250 Inputs : constant Node_Id := Expression (Clause);
26251 Loc : constant Source_Ptr := Sloc (Clause);
26252 Output : constant List_Id := Choices (Clause);
26253 Last_Input : Node_Id;
26254 Input : Node_Id;
26255 New_Clause : Node_Id;
26256 Next_Input : Node_Id;
26257
26258 begin
26259 -- Normalization is performed only when the original clause has
26260 -- more than one input. Multiple inputs appear as an aggregate.
26261
26262 if Nkind (Inputs) = N_Aggregate then
26263 Last_Input := Last (Expressions (Inputs));
26264
26265 -- Create a new clause for each input
26266
26267 Input := First (Expressions (Inputs));
26268 while Present (Input) loop
26269 Next_Input := Next (Input);
26270
26271 -- Unhook the current input from the original input list
26272 -- because it will be relocated to a new clause.
26273
26274 Remove (Input);
26275
26276 -- Special processing for the last input. At this point the
26277 -- original aggregate has been stripped down to one element.
26278 -- Replace the aggregate by the element itself.
26279
26280 if Input = Last_Input then
26281 Rewrite (Inputs, Input);
26282
26283 -- Generate a clause of the form:
26284 -- Output => Input
26285
26286 else
26287 New_Clause :=
26288 Make_Component_Association (Loc,
26289 Choices => New_Copy_List_Tree (Output),
26290 Expression => Input);
26291
26292 -- The new clause contains replicated content that has
26293 -- already been analyzed, mark the clause as analyzed.
26294
26295 Set_Analyzed (New_Clause);
26296 Insert_After (Clause, New_Clause);
26297 end if;
26298
26299 Input := Next_Input;
26300 end loop;
26301 end if;
26302 end Normalize_Inputs;
26303
26304 -----------------------
26305 -- Normalize_Outputs --
26306 -----------------------
26307
26308 procedure Normalize_Outputs (Clause : Node_Id) is
26309 Inputs : constant Node_Id := Expression (Clause);
26310 Loc : constant Source_Ptr := Sloc (Clause);
26311 Outputs : constant Node_Id := First (Choices (Clause));
26312 Last_Output : Node_Id;
26313 New_Clause : Node_Id;
26314 Next_Output : Node_Id;
26315 Output : Node_Id;
26316
26317 begin
26318 -- Multiple outputs appear as an aggregate. Nothing to do when
26319 -- the clause has exactly one output.
26320
26321 if Nkind (Outputs) = N_Aggregate then
26322 Last_Output := Last (Expressions (Outputs));
26323
26324 -- Create a clause for each output. Note that each time a new
26325 -- clause is created, the original output list slowly shrinks
26326 -- until there is one item left.
26327
26328 Output := First (Expressions (Outputs));
26329 while Present (Output) loop
26330 Next_Output := Next (Output);
26331
26332 -- Unhook the output from the original output list as it
26333 -- will be relocated to a new clause.
26334
26335 Remove (Output);
26336
26337 -- Special processing for the last output. At this point
26338 -- the original aggregate has been stripped down to one
26339 -- element. Replace the aggregate by the element itself.
26340
26341 if Output = Last_Output then
26342 Rewrite (Outputs, Output);
26343
26344 else
26345 -- Generate a clause of the form:
26346 -- (Output => Inputs)
26347
26348 New_Clause :=
26349 Make_Component_Association (Loc,
26350 Choices => New_List (Output),
26351 Expression => New_Copy_Tree (Inputs));
26352
26353 -- The new clause contains replicated content that has
26354 -- already been analyzed. There is not need to reanalyze
26355 -- them.
26356
26357 Set_Analyzed (New_Clause);
26358 Insert_After (Clause, New_Clause);
26359 end if;
26360
26361 Output := Next_Output;
26362 end loop;
26363 end if;
26364 end Normalize_Outputs;
26365
26366 -- Local variables
26367
26368 Clause : Node_Id;
26369
26370 -- Start of processing for Normalize_Clauses
26371
26372 begin
26373 Clause := First (Clauses);
26374 while Present (Clause) loop
26375 Normalize_Outputs (Clause);
26376 Next (Clause);
26377 end loop;
26378
26379 Clause := First (Clauses);
26380 while Present (Clause) loop
26381 Normalize_Inputs (Clause);
26382 Next (Clause);
26383 end loop;
26384 end Normalize_Clauses;
26385
26386 --------------------------
26387 -- Remove_Extra_Clauses --
26388 --------------------------
26389
26390 procedure Remove_Extra_Clauses
26391 (Clauses : List_Id;
26392 Matched_Items : Elist_Id)
26393 is
26394 Clause : Node_Id;
26395 Input : Node_Id;
26396 Input_Id : Entity_Id;
26397 Next_Clause : Node_Id;
26398 Output : Node_Id;
26399 State_Id : Entity_Id;
26400
26401 begin
26402 Clause := First (Clauses);
26403 while Present (Clause) loop
26404 Next_Clause := Next (Clause);
26405
26406 Input := Expression (Clause);
26407 Output := First (Choices (Clause));
26408
26409 -- Recognize a clause of the form
26410
26411 -- null => Input
26412
26413 -- where Input is a constituent of a state which was already
26414 -- successfully matched. This clause must be removed because it
26415 -- simply indicates that some of the constituents of the state
26416 -- are not used.
26417
26418 -- Refined_State => (State => (Constit_1, Constit_2))
26419 -- Depends => (Output => State)
26420 -- Refined_Depends => ((Output => Constit_1), -- State matched
26421 -- (null => Constit_2)) -- OK
26422
26423 if Nkind (Output) = N_Null and then Is_Entity_Name (Input) then
26424
26425 -- Handle abstract views generated for limited with clauses
26426
26427 Input_Id := Available_View (Entity_Of (Input));
26428
26429 -- The input must be a constituent of a state
26430
26431 if Ekind_In (Input_Id, E_Abstract_State,
26432 E_Constant,
26433 E_Variable)
26434 and then Present (Encapsulating_State (Input_Id))
26435 then
26436 State_Id := Encapsulating_State (Input_Id);
26437
26438 -- The state must have a non-null visible refinement and be
26439 -- matched in a previous clause.
26440
26441 if Has_Non_Null_Visible_Refinement (State_Id)
26442 and then Contains (Matched_Items, State_Id)
26443 then
26444 Remove (Clause);
26445 end if;
26446 end if;
26447
26448 -- Recognize a clause of the form
26449
26450 -- Output => null
26451
26452 -- where Output is an arbitrary item. This clause must be removed
26453 -- because a null input legitimately matches anything.
26454
26455 elsif Nkind (Input) = N_Null then
26456 Remove (Clause);
26457 end if;
26458
26459 Clause := Next_Clause;
26460 end loop;
26461 end Remove_Extra_Clauses;
26462
26463 --------------------------
26464 -- Report_Extra_Clauses --
26465 --------------------------
26466
26467 procedure Report_Extra_Clauses (Clauses : List_Id) is
26468 Clause : Node_Id;
26469
26470 begin
26471 -- Do not perform this check in an instance because it was already
26472 -- performed successfully in the generic template.
26473
26474 if In_Instance then
26475 null;
26476
26477 elsif Present (Clauses) then
26478 Clause := First (Clauses);
26479 while Present (Clause) loop
26480 SPARK_Msg_N
26481 ("unmatched or extra clause in dependence refinement",
26482 Clause);
26483
26484 Next (Clause);
26485 end loop;
26486 end if;
26487 end Report_Extra_Clauses;
26488
26489 -- Local variables
26490
26491 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
26492 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
26493 Errors : constant Nat := Serious_Errors_Detected;
26494
26495 Clause : Node_Id;
26496 Deps : Node_Id;
26497 Dummy : Boolean;
26498 Refs : Node_Id;
26499
26500 Body_Inputs : Elist_Id := No_Elist;
26501 Body_Outputs : Elist_Id := No_Elist;
26502 -- The inputs and outputs of the subprogram body synthesized from pragma
26503 -- Refined_Depends.
26504
26505 Dependencies : List_Id := No_List;
26506 Depends : Node_Id;
26507 -- The corresponding Depends pragma along with its clauses
26508
26509 Matched_Items : Elist_Id := No_Elist;
26510 -- A list containing the entities of all successfully matched items
26511 -- found in pragma Depends.
26512
26513 Refinements : List_Id := No_List;
26514 -- The clauses of pragma Refined_Depends
26515
26516 Spec_Id : Entity_Id;
26517 -- The entity of the subprogram subject to pragma Refined_Depends
26518
26519 Spec_Inputs : Elist_Id := No_Elist;
26520 Spec_Outputs : Elist_Id := No_Elist;
26521 -- The inputs and outputs of the subprogram spec synthesized from pragma
26522 -- Depends.
26523
26524 States : Elist_Id := No_Elist;
26525 -- A list containing the entities of all states whose constituents
26526 -- appear in pragma Depends.
26527
26528 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
26529
26530 begin
26531 -- Do not analyze the pragma multiple times
26532
26533 if Is_Analyzed_Pragma (N) then
26534 return;
26535 end if;
26536
26537 Spec_Id := Unique_Defining_Entity (Body_Decl);
26538
26539 -- Use the anonymous object as the proper spec when Refined_Depends
26540 -- applies to the body of a single task type. The object carries the
26541 -- proper Chars as well as all non-refined versions of pragmas.
26542
26543 if Is_Single_Concurrent_Type (Spec_Id) then
26544 Spec_Id := Anonymous_Object (Spec_Id);
26545 end if;
26546
26547 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
26548
26549 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
26550 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
26551
26552 if No (Depends) then
26553 SPARK_Msg_NE
26554 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
26555 & "& lacks aspect or pragma Depends"), N, Spec_Id);
26556 goto Leave;
26557 end if;
26558
26559 Deps := Expression (Get_Argument (Depends, Spec_Id));
26560
26561 -- A null dependency relation renders the refinement useless because it
26562 -- cannot possibly mention abstract states with visible refinement. Note
26563 -- that the inverse is not true as states may be refined to null
26564 -- (SPARK RM 7.2.5(2)).
26565
26566 if Nkind (Deps) = N_Null then
26567 SPARK_Msg_NE
26568 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
26569 & "depend on abstract state with visible refinement"), N, Spec_Id);
26570 goto Leave;
26571 end if;
26572
26573 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
26574 -- This ensures that the categorization of all refined dependency items
26575 -- is consistent with their role.
26576
26577 Analyze_Depends_In_Decl_Part (N);
26578
26579 -- Do not match dependencies against refinements if Refined_Depends is
26580 -- illegal to avoid emitting misleading error.
26581
26582 if Serious_Errors_Detected = Errors then
26583
26584 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
26585 -- the inputs and outputs of the subprogram spec and body to verify
26586 -- the use of states with visible refinement and their constituents.
26587
26588 if No (Get_Pragma (Spec_Id, Pragma_Global))
26589 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
26590 then
26591 Collect_Subprogram_Inputs_Outputs
26592 (Subp_Id => Spec_Id,
26593 Synthesize => True,
26594 Subp_Inputs => Spec_Inputs,
26595 Subp_Outputs => Spec_Outputs,
26596 Global_Seen => Dummy);
26597
26598 Collect_Subprogram_Inputs_Outputs
26599 (Subp_Id => Body_Id,
26600 Synthesize => True,
26601 Subp_Inputs => Body_Inputs,
26602 Subp_Outputs => Body_Outputs,
26603 Global_Seen => Dummy);
26604
26605 -- For an output state with a visible refinement, ensure that all
26606 -- constituents appear as outputs in the dependency refinement.
26607
26608 Check_Output_States
26609 (Spec_Inputs => Spec_Inputs,
26610 Spec_Outputs => Spec_Outputs,
26611 Body_Inputs => Body_Inputs,
26612 Body_Outputs => Body_Outputs);
26613 end if;
26614
26615 -- Multiple dependency clauses appear as component associations of an
26616 -- aggregate. Note that the clauses are copied because the algorithm
26617 -- modifies them and this should not be visible in Depends.
26618
26619 pragma Assert (Nkind (Deps) = N_Aggregate);
26620 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
26621 Normalize_Clauses (Dependencies);
26622
26623 -- Gather all states which appear in Depends
26624
26625 States := Collect_States (Dependencies);
26626
26627 Refs := Expression (Get_Argument (N, Spec_Id));
26628
26629 if Nkind (Refs) = N_Null then
26630 Refinements := No_List;
26631
26632 -- Multiple dependency clauses appear as component associations of an
26633 -- aggregate. Note that the clauses are copied because the algorithm
26634 -- modifies them and this should not be visible in Refined_Depends.
26635
26636 else pragma Assert (Nkind (Refs) = N_Aggregate);
26637 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
26638 Normalize_Clauses (Refinements);
26639 end if;
26640
26641 -- At this point the clauses of pragmas Depends and Refined_Depends
26642 -- have been normalized into simple dependencies between one output
26643 -- and one input. Examine all clauses of pragma Depends looking for
26644 -- matching clauses in pragma Refined_Depends.
26645
26646 Clause := First (Dependencies);
26647 while Present (Clause) loop
26648 Check_Dependency_Clause
26649 (Spec_Id => Spec_Id,
26650 Dep_Clause => Clause,
26651 Dep_States => States,
26652 Refinements => Refinements,
26653 Matched_Items => Matched_Items);
26654
26655 Next (Clause);
26656 end loop;
26657
26658 -- Pragma Refined_Depends may contain multiple clarification clauses
26659 -- which indicate that certain constituents do not influence the data
26660 -- flow in any way. Such clauses must be removed as long as the state
26661 -- has been matched, otherwise they will be incorrectly flagged as
26662 -- unmatched.
26663
26664 -- Refined_State => (State => (Constit_1, Constit_2))
26665 -- Depends => (Output => State)
26666 -- Refined_Depends => ((Output => Constit_1), -- State matched
26667 -- (null => Constit_2)) -- must be removed
26668
26669 Remove_Extra_Clauses (Refinements, Matched_Items);
26670
26671 if Serious_Errors_Detected = Errors then
26672 Report_Extra_Clauses (Refinements);
26673 end if;
26674 end if;
26675
26676 <<Leave>>
26677 Set_Is_Analyzed_Pragma (N);
26678 end Analyze_Refined_Depends_In_Decl_Part;
26679
26680 -----------------------------------------
26681 -- Analyze_Refined_Global_In_Decl_Part --
26682 -----------------------------------------
26683
26684 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
26685 Global : Node_Id;
26686 -- The corresponding Global pragma
26687
26688 Has_In_State : Boolean := False;
26689 Has_In_Out_State : Boolean := False;
26690 Has_Out_State : Boolean := False;
26691 Has_Proof_In_State : Boolean := False;
26692 -- These flags are set when the corresponding Global pragma has a state
26693 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
26694 -- refinement.
26695
26696 Has_Null_State : Boolean := False;
26697 -- This flag is set when the corresponding Global pragma has at least
26698 -- one state with a null refinement.
26699
26700 In_Constits : Elist_Id := No_Elist;
26701 In_Out_Constits : Elist_Id := No_Elist;
26702 Out_Constits : Elist_Id := No_Elist;
26703 Proof_In_Constits : Elist_Id := No_Elist;
26704 -- These lists contain the entities of all Input, In_Out, Output and
26705 -- Proof_In constituents that appear in Refined_Global and participate
26706 -- in state refinement.
26707
26708 In_Items : Elist_Id := No_Elist;
26709 In_Out_Items : Elist_Id := No_Elist;
26710 Out_Items : Elist_Id := No_Elist;
26711 Proof_In_Items : Elist_Id := No_Elist;
26712 -- These lists contain the entities of all Input, In_Out, Output and
26713 -- Proof_In items defined in the corresponding Global pragma.
26714
26715 Repeat_Items : Elist_Id := No_Elist;
26716 -- A list of all global items without full visible refinement found
26717 -- in pragma Global. These states should be repeated in the global
26718 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
26719 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
26720
26721 Spec_Id : Entity_Id;
26722 -- The entity of the subprogram subject to pragma Refined_Global
26723
26724 States : Elist_Id := No_Elist;
26725 -- A list of all states with full or partial visible refinement found in
26726 -- pragma Global.
26727
26728 procedure Check_In_Out_States;
26729 -- Determine whether the corresponding Global pragma mentions In_Out
26730 -- states with visible refinement and if so, ensure that one of the
26731 -- following completions apply to the constituents of the state:
26732 -- 1) there is at least one constituent of mode In_Out
26733 -- 2) there is at least one Input and one Output constituent
26734 -- 3) not all constituents are present and one of them is of mode
26735 -- Output.
26736 -- This routine may remove elements from In_Constits, In_Out_Constits,
26737 -- Out_Constits and Proof_In_Constits.
26738
26739 procedure Check_Input_States;
26740 -- Determine whether the corresponding Global pragma mentions Input
26741 -- states with visible refinement and if so, ensure that at least one of
26742 -- its constituents appears as an Input item in Refined_Global.
26743 -- This routine may remove elements from In_Constits, In_Out_Constits,
26744 -- Out_Constits and Proof_In_Constits.
26745
26746 procedure Check_Output_States;
26747 -- Determine whether the corresponding Global pragma mentions Output
26748 -- states with visible refinement and if so, ensure that all of its
26749 -- constituents appear as Output items in Refined_Global.
26750 -- This routine may remove elements from In_Constits, In_Out_Constits,
26751 -- Out_Constits and Proof_In_Constits.
26752
26753 procedure Check_Proof_In_States;
26754 -- Determine whether the corresponding Global pragma mentions Proof_In
26755 -- states with visible refinement and if so, ensure that at least one of
26756 -- its constituents appears as a Proof_In item in Refined_Global.
26757 -- This routine may remove elements from In_Constits, In_Out_Constits,
26758 -- Out_Constits and Proof_In_Constits.
26759
26760 procedure Check_Refined_Global_List
26761 (List : Node_Id;
26762 Global_Mode : Name_Id := Name_Input);
26763 -- Verify the legality of a single global list declaration. Global_Mode
26764 -- denotes the current mode in effect.
26765
26766 procedure Collect_Global_Items
26767 (List : Node_Id;
26768 Mode : Name_Id := Name_Input);
26769 -- Gather all Input, In_Out, Output and Proof_In items from node List
26770 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
26771 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
26772 -- and Has_Proof_In_State are set when there is at least one abstract
26773 -- state with full or partial visible refinement available in the
26774 -- corresponding mode. Flag Has_Null_State is set when at least state
26775 -- has a null refinement. Mode denotes the current global mode in
26776 -- effect.
26777
26778 function Present_Then_Remove
26779 (List : Elist_Id;
26780 Item : Entity_Id) return Boolean;
26781 -- Search List for a particular entity Item. If Item has been found,
26782 -- remove it from List. This routine is used to strip lists In_Constits,
26783 -- In_Out_Constits and Out_Constits of valid constituents.
26784
26785 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id);
26786 -- Same as function Present_Then_Remove, but do not report the presence
26787 -- of Item in List.
26788
26789 procedure Report_Extra_Constituents;
26790 -- Emit an error for each constituent found in lists In_Constits,
26791 -- In_Out_Constits and Out_Constits.
26792
26793 procedure Report_Missing_Items;
26794 -- Emit an error for each global item not repeated found in list
26795 -- Repeat_Items.
26796
26797 -------------------------
26798 -- Check_In_Out_States --
26799 -------------------------
26800
26801 procedure Check_In_Out_States is
26802 procedure Check_Constituent_Usage (State_Id : Entity_Id);
26803 -- Determine whether one of the following coverage scenarios is in
26804 -- effect:
26805 -- 1) there is at least one constituent of mode In_Out or Output
26806 -- 2) there is at least one pair of constituents with modes Input
26807 -- and Output, or Proof_In and Output.
26808 -- 3) there is at least one constituent of mode Output and not all
26809 -- constituents are present.
26810 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
26811
26812 -----------------------------
26813 -- Check_Constituent_Usage --
26814 -----------------------------
26815
26816 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
26817 Constits : constant Elist_Id :=
26818 Partial_Refinement_Constituents (State_Id);
26819 Constit_Elmt : Elmt_Id;
26820 Constit_Id : Entity_Id;
26821 Has_Missing : Boolean := False;
26822 In_Out_Seen : Boolean := False;
26823 Input_Seen : Boolean := False;
26824 Output_Seen : Boolean := False;
26825 Proof_In_Seen : Boolean := False;
26826
26827 begin
26828 -- Process all the constituents of the state and note their modes
26829 -- within the global refinement.
26830
26831 if Present (Constits) then
26832 Constit_Elmt := First_Elmt (Constits);
26833 while Present (Constit_Elmt) loop
26834 Constit_Id := Node (Constit_Elmt);
26835
26836 if Present_Then_Remove (In_Constits, Constit_Id) then
26837 Input_Seen := True;
26838
26839 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
26840 In_Out_Seen := True;
26841
26842 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
26843 Output_Seen := True;
26844
26845 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
26846 then
26847 Proof_In_Seen := True;
26848
26849 else
26850 Has_Missing := True;
26851 end if;
26852
26853 Next_Elmt (Constit_Elmt);
26854 end loop;
26855 end if;
26856
26857 -- An In_Out constituent is a valid completion
26858
26859 if In_Out_Seen then
26860 null;
26861
26862 -- A pair of one Input/Proof_In and one Output constituent is a
26863 -- valid completion.
26864
26865 elsif (Input_Seen or Proof_In_Seen) and Output_Seen then
26866 null;
26867
26868 elsif Output_Seen then
26869
26870 -- A single Output constituent is a valid completion only when
26871 -- some of the other constituents are missing.
26872
26873 if Has_Missing then
26874 null;
26875
26876 -- Otherwise all constituents are of mode Output
26877
26878 else
26879 SPARK_Msg_NE
26880 ("global refinement of state & must include at least one "
26881 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
26882 N, State_Id);
26883 end if;
26884
26885 -- The state lacks a completion. When full refinement is visible,
26886 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
26887 -- refinement is visible, emit an error if the abstract state
26888 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
26889 -- both are utilized, Check_State_And_Constituent_Use. will issue
26890 -- the error.
26891
26892 elsif not Input_Seen
26893 and then not In_Out_Seen
26894 and then not Output_Seen
26895 and then not Proof_In_Seen
26896 then
26897 if Has_Visible_Refinement (State_Id)
26898 or else Contains (Repeat_Items, State_Id)
26899 then
26900 SPARK_Msg_NE
26901 ("missing global refinement of state &", N, State_Id);
26902 end if;
26903
26904 -- Otherwise the state has a malformed completion where at least
26905 -- one of the constituents has a different mode.
26906
26907 else
26908 SPARK_Msg_NE
26909 ("global refinement of state & redefines the mode of its "
26910 & "constituents", N, State_Id);
26911 end if;
26912 end Check_Constituent_Usage;
26913
26914 -- Local variables
26915
26916 Item_Elmt : Elmt_Id;
26917 Item_Id : Entity_Id;
26918
26919 -- Start of processing for Check_In_Out_States
26920
26921 begin
26922 -- Do not perform this check in an instance because it was already
26923 -- performed successfully in the generic template.
26924
26925 if In_Instance then
26926 null;
26927
26928 -- Inspect the In_Out items of the corresponding Global pragma
26929 -- looking for a state with a visible refinement.
26930
26931 elsif Has_In_Out_State and then Present (In_Out_Items) then
26932 Item_Elmt := First_Elmt (In_Out_Items);
26933 while Present (Item_Elmt) loop
26934 Item_Id := Node (Item_Elmt);
26935
26936 -- Ensure that one of the three coverage variants is satisfied
26937
26938 if Ekind (Item_Id) = E_Abstract_State
26939 and then Has_Non_Null_Visible_Refinement (Item_Id)
26940 then
26941 Check_Constituent_Usage (Item_Id);
26942 end if;
26943
26944 Next_Elmt (Item_Elmt);
26945 end loop;
26946 end if;
26947 end Check_In_Out_States;
26948
26949 ------------------------
26950 -- Check_Input_States --
26951 ------------------------
26952
26953 procedure Check_Input_States is
26954 procedure Check_Constituent_Usage (State_Id : Entity_Id);
26955 -- Determine whether at least one constituent of state State_Id with
26956 -- full or partial visible refinement is used and has mode Input.
26957 -- Ensure that the remaining constituents do not have In_Out or
26958 -- Output modes. Emit an error if this is not the case
26959 -- (SPARK RM 7.2.4(5)).
26960
26961 -----------------------------
26962 -- Check_Constituent_Usage --
26963 -----------------------------
26964
26965 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
26966 Constits : constant Elist_Id :=
26967 Partial_Refinement_Constituents (State_Id);
26968 Constit_Elmt : Elmt_Id;
26969 Constit_Id : Entity_Id;
26970 In_Seen : Boolean := False;
26971
26972 begin
26973 if Present (Constits) then
26974 Constit_Elmt := First_Elmt (Constits);
26975 while Present (Constit_Elmt) loop
26976 Constit_Id := Node (Constit_Elmt);
26977
26978 -- At least one of the constituents appears as an Input
26979
26980 if Present_Then_Remove (In_Constits, Constit_Id) then
26981 In_Seen := True;
26982
26983 -- A Proof_In constituent can refine an Input state as long
26984 -- as there is at least one Input constituent present.
26985
26986 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
26987 then
26988 null;
26989
26990 -- The constituent appears in the global refinement, but has
26991 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
26992
26993 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
26994 or else Present_Then_Remove (Out_Constits, Constit_Id)
26995 then
26996 Error_Msg_Name_1 := Chars (State_Id);
26997 SPARK_Msg_NE
26998 ("constituent & of state % must have mode `Input` in "
26999 & "global refinement", N, Constit_Id);
27000 end if;
27001
27002 Next_Elmt (Constit_Elmt);
27003 end loop;
27004 end if;
27005
27006 -- Not one of the constituents appeared as Input. Always emit an
27007 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
27008 -- When only partial refinement is visible, emit an error if the
27009 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27010 -- the case where both are utilized, an error will be issued in
27011 -- Check_State_And_Constituent_Use.
27012
27013 if not In_Seen
27014 and then (Has_Visible_Refinement (State_Id)
27015 or else Contains (Repeat_Items, State_Id))
27016 then
27017 SPARK_Msg_NE
27018 ("global refinement of state & must include at least one "
27019 & "constituent of mode `Input`", N, State_Id);
27020 end if;
27021 end Check_Constituent_Usage;
27022
27023 -- Local variables
27024
27025 Item_Elmt : Elmt_Id;
27026 Item_Id : Entity_Id;
27027
27028 -- Start of processing for Check_Input_States
27029
27030 begin
27031 -- Do not perform this check in an instance because it was already
27032 -- performed successfully in the generic template.
27033
27034 if In_Instance then
27035 null;
27036
27037 -- Inspect the Input items of the corresponding Global pragma looking
27038 -- for a state with a visible refinement.
27039
27040 elsif Has_In_State and then Present (In_Items) then
27041 Item_Elmt := First_Elmt (In_Items);
27042 while Present (Item_Elmt) loop
27043 Item_Id := Node (Item_Elmt);
27044
27045 -- When full refinement is visible, ensure that at least one of
27046 -- the constituents is utilized and is of mode Input. When only
27047 -- partial refinement is visible, ensure that either one of
27048 -- the constituents is utilized and is of mode Input, or the
27049 -- abstract state is repeated and no constituent is utilized.
27050
27051 if Ekind (Item_Id) = E_Abstract_State
27052 and then Has_Non_Null_Visible_Refinement (Item_Id)
27053 then
27054 Check_Constituent_Usage (Item_Id);
27055 end if;
27056
27057 Next_Elmt (Item_Elmt);
27058 end loop;
27059 end if;
27060 end Check_Input_States;
27061
27062 -------------------------
27063 -- Check_Output_States --
27064 -------------------------
27065
27066 procedure Check_Output_States is
27067 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27068 -- Determine whether all constituents of state State_Id with full
27069 -- visible refinement are used and have mode Output. Emit an error
27070 -- if this is not the case (SPARK RM 7.2.4(5)).
27071
27072 -----------------------------
27073 -- Check_Constituent_Usage --
27074 -----------------------------
27075
27076 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27077 Constits : constant Elist_Id :=
27078 Partial_Refinement_Constituents (State_Id);
27079 Only_Partial : constant Boolean :=
27080 not Has_Visible_Refinement (State_Id);
27081 Constit_Elmt : Elmt_Id;
27082 Constit_Id : Entity_Id;
27083 Posted : Boolean := False;
27084
27085 begin
27086 if Present (Constits) then
27087 Constit_Elmt := First_Elmt (Constits);
27088 while Present (Constit_Elmt) loop
27089 Constit_Id := Node (Constit_Elmt);
27090
27091 -- Issue an error when a constituent of State_Id is utilized
27092 -- and State_Id has only partial visible refinement
27093 -- (SPARK RM 7.2.4(3d)).
27094
27095 if Only_Partial then
27096 if Present_Then_Remove (Out_Constits, Constit_Id)
27097 or else Present_Then_Remove (In_Constits, Constit_Id)
27098 or else
27099 Present_Then_Remove (In_Out_Constits, Constit_Id)
27100 or else
27101 Present_Then_Remove (Proof_In_Constits, Constit_Id)
27102 then
27103 Error_Msg_Name_1 := Chars (State_Id);
27104 SPARK_Msg_NE
27105 ("constituent & of state % cannot be used in global "
27106 & "refinement", N, Constit_Id);
27107 Error_Msg_Name_1 := Chars (State_Id);
27108 SPARK_Msg_N ("\use state % instead", N);
27109 end if;
27110
27111 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
27112 null;
27113
27114 -- The constituent appears in the global refinement, but has
27115 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
27116
27117 elsif Present_Then_Remove (In_Constits, Constit_Id)
27118 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27119 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
27120 then
27121 Error_Msg_Name_1 := Chars (State_Id);
27122 SPARK_Msg_NE
27123 ("constituent & of state % must have mode `Output` in "
27124 & "global refinement", N, Constit_Id);
27125
27126 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
27127
27128 else
27129 if not Posted then
27130 Posted := True;
27131 SPARK_Msg_NE
27132 ("`Output` state & must be replaced by all its "
27133 & "constituents in global refinement", N, State_Id);
27134 end if;
27135
27136 SPARK_Msg_NE
27137 ("\constituent & is missing in output list",
27138 N, Constit_Id);
27139 end if;
27140
27141 Next_Elmt (Constit_Elmt);
27142 end loop;
27143 end if;
27144 end Check_Constituent_Usage;
27145
27146 -- Local variables
27147
27148 Item_Elmt : Elmt_Id;
27149 Item_Id : Entity_Id;
27150
27151 -- Start of processing for Check_Output_States
27152
27153 begin
27154 -- Do not perform this check in an instance because it was already
27155 -- performed successfully in the generic template.
27156
27157 if In_Instance then
27158 null;
27159
27160 -- Inspect the Output items of the corresponding Global pragma
27161 -- looking for a state with a visible refinement.
27162
27163 elsif Has_Out_State and then Present (Out_Items) then
27164 Item_Elmt := First_Elmt (Out_Items);
27165 while Present (Item_Elmt) loop
27166 Item_Id := Node (Item_Elmt);
27167
27168 -- When full refinement is visible, ensure that all of the
27169 -- constituents are utilized and they have mode Output. When
27170 -- only partial refinement is visible, ensure that no
27171 -- constituent is utilized.
27172
27173 if Ekind (Item_Id) = E_Abstract_State
27174 and then Has_Non_Null_Visible_Refinement (Item_Id)
27175 then
27176 Check_Constituent_Usage (Item_Id);
27177 end if;
27178
27179 Next_Elmt (Item_Elmt);
27180 end loop;
27181 end if;
27182 end Check_Output_States;
27183
27184 ---------------------------
27185 -- Check_Proof_In_States --
27186 ---------------------------
27187
27188 procedure Check_Proof_In_States is
27189 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27190 -- Determine whether at least one constituent of state State_Id with
27191 -- full or partial visible refinement is used and has mode Proof_In.
27192 -- Ensure that the remaining constituents do not have Input, In_Out,
27193 -- or Output modes. Emit an error if this is not the case
27194 -- (SPARK RM 7.2.4(5)).
27195
27196 -----------------------------
27197 -- Check_Constituent_Usage --
27198 -----------------------------
27199
27200 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27201 Constits : constant Elist_Id :=
27202 Partial_Refinement_Constituents (State_Id);
27203 Constit_Elmt : Elmt_Id;
27204 Constit_Id : Entity_Id;
27205 Proof_In_Seen : Boolean := False;
27206
27207 begin
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 -- At least one of the constituents appears as Proof_In
27214
27215 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
27216 Proof_In_Seen := True;
27217
27218 -- The constituent appears in the global refinement, but has
27219 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
27220
27221 elsif Present_Then_Remove (In_Constits, Constit_Id)
27222 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27223 or else Present_Then_Remove (Out_Constits, Constit_Id)
27224 then
27225 Error_Msg_Name_1 := Chars (State_Id);
27226 SPARK_Msg_NE
27227 ("constituent & of state % must have mode `Proof_In` "
27228 & "in global refinement", N, Constit_Id);
27229 end if;
27230
27231 Next_Elmt (Constit_Elmt);
27232 end loop;
27233 end if;
27234
27235 -- Not one of the constituents appeared as Proof_In. Always emit
27236 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
27237 -- When only partial refinement is visible, emit an error if the
27238 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27239 -- the case where both are utilized, an error will be issued by
27240 -- Check_State_And_Constituent_Use.
27241
27242 if not Proof_In_Seen
27243 and then (Has_Visible_Refinement (State_Id)
27244 or else Contains (Repeat_Items, State_Id))
27245 then
27246 SPARK_Msg_NE
27247 ("global refinement of state & must include at least one "
27248 & "constituent of mode `Proof_In`", N, State_Id);
27249 end if;
27250 end Check_Constituent_Usage;
27251
27252 -- Local variables
27253
27254 Item_Elmt : Elmt_Id;
27255 Item_Id : Entity_Id;
27256
27257 -- Start of processing for Check_Proof_In_States
27258
27259 begin
27260 -- Do not perform this check in an instance because it was already
27261 -- performed successfully in the generic template.
27262
27263 if In_Instance then
27264 null;
27265
27266 -- Inspect the Proof_In items of the corresponding Global pragma
27267 -- looking for a state with a visible refinement.
27268
27269 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
27270 Item_Elmt := First_Elmt (Proof_In_Items);
27271 while Present (Item_Elmt) loop
27272 Item_Id := Node (Item_Elmt);
27273
27274 -- Ensure that at least one of the constituents is utilized
27275 -- and is of mode Proof_In. When only partial refinement is
27276 -- visible, ensure that either one of the constituents is
27277 -- utilized and is of mode Proof_In, or the abstract state
27278 -- is repeated and no constituent is utilized.
27279
27280 if Ekind (Item_Id) = E_Abstract_State
27281 and then Has_Non_Null_Visible_Refinement (Item_Id)
27282 then
27283 Check_Constituent_Usage (Item_Id);
27284 end if;
27285
27286 Next_Elmt (Item_Elmt);
27287 end loop;
27288 end if;
27289 end Check_Proof_In_States;
27290
27291 -------------------------------
27292 -- Check_Refined_Global_List --
27293 -------------------------------
27294
27295 procedure Check_Refined_Global_List
27296 (List : Node_Id;
27297 Global_Mode : Name_Id := Name_Input)
27298 is
27299 procedure Check_Refined_Global_Item
27300 (Item : Node_Id;
27301 Global_Mode : Name_Id);
27302 -- Verify the legality of a single global item declaration. Parameter
27303 -- Global_Mode denotes the current mode in effect.
27304
27305 -------------------------------
27306 -- Check_Refined_Global_Item --
27307 -------------------------------
27308
27309 procedure Check_Refined_Global_Item
27310 (Item : Node_Id;
27311 Global_Mode : Name_Id)
27312 is
27313 Item_Id : constant Entity_Id := Entity_Of (Item);
27314
27315 procedure Inconsistent_Mode_Error (Expect : Name_Id);
27316 -- Issue a common error message for all mode mismatches. Expect
27317 -- denotes the expected mode.
27318
27319 -----------------------------
27320 -- Inconsistent_Mode_Error --
27321 -----------------------------
27322
27323 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
27324 begin
27325 SPARK_Msg_NE
27326 ("global item & has inconsistent modes", Item, Item_Id);
27327
27328 Error_Msg_Name_1 := Global_Mode;
27329 Error_Msg_Name_2 := Expect;
27330 SPARK_Msg_N ("\expected mode %, found mode %", Item);
27331 end Inconsistent_Mode_Error;
27332
27333 -- Local variables
27334
27335 Enc_State : Entity_Id := Empty;
27336 -- Encapsulating state for constituent, Empty otherwise
27337
27338 -- Start of processing for Check_Refined_Global_Item
27339
27340 begin
27341 if Ekind_In (Item_Id, E_Abstract_State,
27342 E_Constant,
27343 E_Variable)
27344 then
27345 Enc_State := Find_Encapsulating_State (States, Item_Id);
27346 end if;
27347
27348 -- When the state or object acts as a constituent of another
27349 -- state with a visible refinement, collect it for the state
27350 -- completeness checks performed later on. Note that the item
27351 -- acts as a constituent only when the encapsulating state is
27352 -- present in pragma Global.
27353
27354 if Present (Enc_State)
27355 and then (Has_Visible_Refinement (Enc_State)
27356 or else Has_Partial_Visible_Refinement (Enc_State))
27357 and then Contains (States, Enc_State)
27358 then
27359 -- If the state has only partial visible refinement, remove it
27360 -- from the list of items that should be repeated from pragma
27361 -- Global.
27362
27363 if not Has_Visible_Refinement (Enc_State) then
27364 Present_Then_Remove (Repeat_Items, Enc_State);
27365 end if;
27366
27367 if Global_Mode = Name_Input then
27368 Append_New_Elmt (Item_Id, In_Constits);
27369
27370 elsif Global_Mode = Name_In_Out then
27371 Append_New_Elmt (Item_Id, In_Out_Constits);
27372
27373 elsif Global_Mode = Name_Output then
27374 Append_New_Elmt (Item_Id, Out_Constits);
27375
27376 elsif Global_Mode = Name_Proof_In then
27377 Append_New_Elmt (Item_Id, Proof_In_Constits);
27378 end if;
27379
27380 -- When not a constituent, ensure that both occurrences of the
27381 -- item in pragmas Global and Refined_Global match. Also remove
27382 -- it when present from the list of items that should be repeated
27383 -- from pragma Global.
27384
27385 else
27386 Present_Then_Remove (Repeat_Items, Item_Id);
27387
27388 if Contains (In_Items, Item_Id) then
27389 if Global_Mode /= Name_Input then
27390 Inconsistent_Mode_Error (Name_Input);
27391 end if;
27392
27393 elsif Contains (In_Out_Items, Item_Id) then
27394 if Global_Mode /= Name_In_Out then
27395 Inconsistent_Mode_Error (Name_In_Out);
27396 end if;
27397
27398 elsif Contains (Out_Items, Item_Id) then
27399 if Global_Mode /= Name_Output then
27400 Inconsistent_Mode_Error (Name_Output);
27401 end if;
27402
27403 elsif Contains (Proof_In_Items, Item_Id) then
27404 null;
27405
27406 -- The item does not appear in the corresponding Global pragma,
27407 -- it must be an extra (SPARK RM 7.2.4(3)).
27408
27409 else
27410 pragma Assert (Present (Global));
27411 Error_Msg_Sloc := Sloc (Global);
27412 SPARK_Msg_NE
27413 ("extra global item & does not refine or repeat any "
27414 & "global item #", Item, Item_Id);
27415 end if;
27416 end if;
27417 end Check_Refined_Global_Item;
27418
27419 -- Local variables
27420
27421 Item : Node_Id;
27422
27423 -- Start of processing for Check_Refined_Global_List
27424
27425 begin
27426 -- Do not perform this check in an instance because it was already
27427 -- performed successfully in the generic template.
27428
27429 if In_Instance then
27430 null;
27431
27432 elsif Nkind (List) = N_Null then
27433 null;
27434
27435 -- Single global item declaration
27436
27437 elsif Nkind_In (List, N_Expanded_Name,
27438 N_Identifier,
27439 N_Selected_Component)
27440 then
27441 Check_Refined_Global_Item (List, Global_Mode);
27442
27443 -- Simple global list or moded global list declaration
27444
27445 elsif Nkind (List) = N_Aggregate then
27446
27447 -- The declaration of a simple global list appear as a collection
27448 -- of expressions.
27449
27450 if Present (Expressions (List)) then
27451 Item := First (Expressions (List));
27452 while Present (Item) loop
27453 Check_Refined_Global_Item (Item, Global_Mode);
27454 Next (Item);
27455 end loop;
27456
27457 -- The declaration of a moded global list appears as a collection
27458 -- of component associations where individual choices denote
27459 -- modes.
27460
27461 elsif Present (Component_Associations (List)) then
27462 Item := First (Component_Associations (List));
27463 while Present (Item) loop
27464 Check_Refined_Global_List
27465 (List => Expression (Item),
27466 Global_Mode => Chars (First (Choices (Item))));
27467
27468 Next (Item);
27469 end loop;
27470
27471 -- Invalid tree
27472
27473 else
27474 raise Program_Error;
27475 end if;
27476
27477 -- Invalid list
27478
27479 else
27480 raise Program_Error;
27481 end if;
27482 end Check_Refined_Global_List;
27483
27484 --------------------------
27485 -- Collect_Global_Items --
27486 --------------------------
27487
27488 procedure Collect_Global_Items
27489 (List : Node_Id;
27490 Mode : Name_Id := Name_Input)
27491 is
27492 procedure Collect_Global_Item
27493 (Item : Node_Id;
27494 Item_Mode : Name_Id);
27495 -- Add a single item to the appropriate list. Item_Mode denotes the
27496 -- current mode in effect.
27497
27498 -------------------------
27499 -- Collect_Global_Item --
27500 -------------------------
27501
27502 procedure Collect_Global_Item
27503 (Item : Node_Id;
27504 Item_Mode : Name_Id)
27505 is
27506 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
27507 -- The above handles abstract views of variables and states built
27508 -- for limited with clauses.
27509
27510 begin
27511 -- Signal that the global list contains at least one abstract
27512 -- state with a visible refinement. Note that the refinement may
27513 -- be null in which case there are no constituents.
27514
27515 if Ekind (Item_Id) = E_Abstract_State then
27516 if Has_Null_Visible_Refinement (Item_Id) then
27517 Has_Null_State := True;
27518
27519 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
27520 Append_New_Elmt (Item_Id, States);
27521
27522 if Item_Mode = Name_Input then
27523 Has_In_State := True;
27524 elsif Item_Mode = Name_In_Out then
27525 Has_In_Out_State := True;
27526 elsif Item_Mode = Name_Output then
27527 Has_Out_State := True;
27528 elsif Item_Mode = Name_Proof_In then
27529 Has_Proof_In_State := True;
27530 end if;
27531 end if;
27532 end if;
27533
27534 -- Record global items without full visible refinement found in
27535 -- pragma Global which should be repeated in the global refinement
27536 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
27537
27538 if Ekind (Item_Id) /= E_Abstract_State
27539 or else not Has_Visible_Refinement (Item_Id)
27540 then
27541 Append_New_Elmt (Item_Id, Repeat_Items);
27542 end if;
27543
27544 -- Add the item to the proper list
27545
27546 if Item_Mode = Name_Input then
27547 Append_New_Elmt (Item_Id, In_Items);
27548 elsif Item_Mode = Name_In_Out then
27549 Append_New_Elmt (Item_Id, In_Out_Items);
27550 elsif Item_Mode = Name_Output then
27551 Append_New_Elmt (Item_Id, Out_Items);
27552 elsif Item_Mode = Name_Proof_In then
27553 Append_New_Elmt (Item_Id, Proof_In_Items);
27554 end if;
27555 end Collect_Global_Item;
27556
27557 -- Local variables
27558
27559 Item : Node_Id;
27560
27561 -- Start of processing for Collect_Global_Items
27562
27563 begin
27564 if Nkind (List) = N_Null then
27565 null;
27566
27567 -- Single global item declaration
27568
27569 elsif Nkind_In (List, N_Expanded_Name,
27570 N_Identifier,
27571 N_Selected_Component)
27572 then
27573 Collect_Global_Item (List, Mode);
27574
27575 -- Single global list or moded global list declaration
27576
27577 elsif Nkind (List) = N_Aggregate then
27578
27579 -- The declaration of a simple global list appear as a collection
27580 -- of expressions.
27581
27582 if Present (Expressions (List)) then
27583 Item := First (Expressions (List));
27584 while Present (Item) loop
27585 Collect_Global_Item (Item, Mode);
27586 Next (Item);
27587 end loop;
27588
27589 -- The declaration of a moded global list appears as a collection
27590 -- of component associations where individual choices denote mode.
27591
27592 elsif Present (Component_Associations (List)) then
27593 Item := First (Component_Associations (List));
27594 while Present (Item) loop
27595 Collect_Global_Items
27596 (List => Expression (Item),
27597 Mode => Chars (First (Choices (Item))));
27598
27599 Next (Item);
27600 end loop;
27601
27602 -- Invalid tree
27603
27604 else
27605 raise Program_Error;
27606 end if;
27607
27608 -- To accommodate partial decoration of disabled SPARK features, this
27609 -- routine may be called with illegal input. If this is the case, do
27610 -- not raise Program_Error.
27611
27612 else
27613 null;
27614 end if;
27615 end Collect_Global_Items;
27616
27617 -------------------------
27618 -- Present_Then_Remove --
27619 -------------------------
27620
27621 function Present_Then_Remove
27622 (List : Elist_Id;
27623 Item : Entity_Id) return Boolean
27624 is
27625 Elmt : Elmt_Id;
27626
27627 begin
27628 if Present (List) then
27629 Elmt := First_Elmt (List);
27630 while Present (Elmt) loop
27631 if Node (Elmt) = Item then
27632 Remove_Elmt (List, Elmt);
27633 return True;
27634 end if;
27635
27636 Next_Elmt (Elmt);
27637 end loop;
27638 end if;
27639
27640 return False;
27641 end Present_Then_Remove;
27642
27643 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id) is
27644 Ignore : Boolean;
27645 begin
27646 Ignore := Present_Then_Remove (List, Item);
27647 end Present_Then_Remove;
27648
27649 -------------------------------
27650 -- Report_Extra_Constituents --
27651 -------------------------------
27652
27653 procedure Report_Extra_Constituents is
27654 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
27655 -- Emit an error for every element of List
27656
27657 ---------------------------------------
27658 -- Report_Extra_Constituents_In_List --
27659 ---------------------------------------
27660
27661 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
27662 Constit_Elmt : Elmt_Id;
27663
27664 begin
27665 if Present (List) then
27666 Constit_Elmt := First_Elmt (List);
27667 while Present (Constit_Elmt) loop
27668 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
27669 Next_Elmt (Constit_Elmt);
27670 end loop;
27671 end if;
27672 end Report_Extra_Constituents_In_List;
27673
27674 -- Start of processing for Report_Extra_Constituents
27675
27676 begin
27677 -- Do not perform this check in an instance because it was already
27678 -- performed successfully in the generic template.
27679
27680 if In_Instance then
27681 null;
27682
27683 else
27684 Report_Extra_Constituents_In_List (In_Constits);
27685 Report_Extra_Constituents_In_List (In_Out_Constits);
27686 Report_Extra_Constituents_In_List (Out_Constits);
27687 Report_Extra_Constituents_In_List (Proof_In_Constits);
27688 end if;
27689 end Report_Extra_Constituents;
27690
27691 --------------------------
27692 -- Report_Missing_Items --
27693 --------------------------
27694
27695 procedure Report_Missing_Items is
27696 Item_Elmt : Elmt_Id;
27697 Item_Id : Entity_Id;
27698
27699 begin
27700 -- Do not perform this check in an instance because it was already
27701 -- performed successfully in the generic template.
27702
27703 if In_Instance then
27704 null;
27705
27706 else
27707 if Present (Repeat_Items) then
27708 Item_Elmt := First_Elmt (Repeat_Items);
27709 while Present (Item_Elmt) loop
27710 Item_Id := Node (Item_Elmt);
27711 SPARK_Msg_NE ("missing global item &", N, Item_Id);
27712 Next_Elmt (Item_Elmt);
27713 end loop;
27714 end if;
27715 end if;
27716 end Report_Missing_Items;
27717
27718 -- Local variables
27719
27720 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
27721 Errors : constant Nat := Serious_Errors_Detected;
27722 Items : Node_Id;
27723 No_Constit : Boolean;
27724
27725 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
27726
27727 begin
27728 -- Do not analyze the pragma multiple times
27729
27730 if Is_Analyzed_Pragma (N) then
27731 return;
27732 end if;
27733
27734 Spec_Id := Unique_Defining_Entity (Body_Decl);
27735
27736 -- Use the anonymous object as the proper spec when Refined_Global
27737 -- applies to the body of a single task type. The object carries the
27738 -- proper Chars as well as all non-refined versions of pragmas.
27739
27740 if Is_Single_Concurrent_Type (Spec_Id) then
27741 Spec_Id := Anonymous_Object (Spec_Id);
27742 end if;
27743
27744 Global := Get_Pragma (Spec_Id, Pragma_Global);
27745 Items := Expression (Get_Argument (N, Spec_Id));
27746
27747 -- The subprogram declaration lacks pragma Global. This renders
27748 -- Refined_Global useless as there is nothing to refine.
27749
27750 if No (Global) then
27751 SPARK_Msg_NE
27752 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
27753 & "& lacks aspect or pragma Global"), N, Spec_Id);
27754 goto Leave;
27755 end if;
27756
27757 -- Extract all relevant items from the corresponding Global pragma
27758
27759 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
27760
27761 -- Package and subprogram bodies are instantiated individually in
27762 -- a separate compiler pass. Due to this mode of instantiation, the
27763 -- refinement of a state may no longer be visible when a subprogram
27764 -- body contract is instantiated. Since the generic template is legal,
27765 -- do not perform this check in the instance to circumvent this oddity.
27766
27767 if In_Instance then
27768 null;
27769
27770 -- Non-instance case
27771
27772 else
27773 -- The corresponding Global pragma must mention at least one
27774 -- state with a visible refinement at the point Refined_Global
27775 -- is processed. States with null refinements need Refined_Global
27776 -- pragma (SPARK RM 7.2.4(2)).
27777
27778 if not Has_In_State
27779 and then not Has_In_Out_State
27780 and then not Has_Out_State
27781 and then not Has_Proof_In_State
27782 and then not Has_Null_State
27783 then
27784 SPARK_Msg_NE
27785 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
27786 & "depend on abstract state with visible refinement"),
27787 N, Spec_Id);
27788 goto Leave;
27789
27790 -- The global refinement of inputs and outputs cannot be null when
27791 -- the corresponding Global pragma contains at least one item except
27792 -- in the case where we have states with null refinements.
27793
27794 elsif Nkind (Items) = N_Null
27795 and then
27796 (Present (In_Items)
27797 or else Present (In_Out_Items)
27798 or else Present (Out_Items)
27799 or else Present (Proof_In_Items))
27800 and then not Has_Null_State
27801 then
27802 SPARK_Msg_NE
27803 (Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has "
27804 & "global items"), N, Spec_Id);
27805 goto Leave;
27806 end if;
27807 end if;
27808
27809 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
27810 -- This ensures that the categorization of all refined global items is
27811 -- consistent with their role.
27812
27813 Analyze_Global_In_Decl_Part (N);
27814
27815 -- Perform all refinement checks with respect to completeness and mode
27816 -- matching.
27817
27818 if Serious_Errors_Detected = Errors then
27819 Check_Refined_Global_List (Items);
27820 end if;
27821
27822 -- Store the information that no constituent is used in the global
27823 -- refinement, prior to calling checking procedures which remove items
27824 -- from the list of constituents.
27825
27826 No_Constit :=
27827 No (In_Constits)
27828 and then No (In_Out_Constits)
27829 and then No (Out_Constits)
27830 and then No (Proof_In_Constits);
27831
27832 -- For Input states with visible refinement, at least one constituent
27833 -- must be used as an Input in the global refinement.
27834
27835 if Serious_Errors_Detected = Errors then
27836 Check_Input_States;
27837 end if;
27838
27839 -- Verify all possible completion variants for In_Out states with
27840 -- visible refinement.
27841
27842 if Serious_Errors_Detected = Errors then
27843 Check_In_Out_States;
27844 end if;
27845
27846 -- For Output states with visible refinement, all constituents must be
27847 -- used as Outputs in the global refinement.
27848
27849 if Serious_Errors_Detected = Errors then
27850 Check_Output_States;
27851 end if;
27852
27853 -- For Proof_In states with visible refinement, at least one constituent
27854 -- must be used as Proof_In in the global refinement.
27855
27856 if Serious_Errors_Detected = Errors then
27857 Check_Proof_In_States;
27858 end if;
27859
27860 -- Emit errors for all constituents that belong to other states with
27861 -- visible refinement that do not appear in Global.
27862
27863 if Serious_Errors_Detected = Errors then
27864 Report_Extra_Constituents;
27865 end if;
27866
27867 -- Emit errors for all items in Global that are not repeated in the
27868 -- global refinement and for which there is no full visible refinement
27869 -- and, in the case of states with partial visible refinement, no
27870 -- constituent is mentioned in the global refinement.
27871
27872 if Serious_Errors_Detected = Errors then
27873 Report_Missing_Items;
27874 end if;
27875
27876 -- Emit an error if no constituent is used in the global refinement
27877 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
27878 -- one may be issued by the checking procedures. Do not perform this
27879 -- check in an instance because it was already performed successfully
27880 -- in the generic template.
27881
27882 if Serious_Errors_Detected = Errors
27883 and then not In_Instance
27884 and then not Has_Null_State
27885 and then No_Constit
27886 then
27887 SPARK_Msg_N ("missing refinement", N);
27888 end if;
27889
27890 <<Leave>>
27891 Set_Is_Analyzed_Pragma (N);
27892 end Analyze_Refined_Global_In_Decl_Part;
27893
27894 ----------------------------------------
27895 -- Analyze_Refined_State_In_Decl_Part --
27896 ----------------------------------------
27897
27898 procedure Analyze_Refined_State_In_Decl_Part
27899 (N : Node_Id;
27900 Freeze_Id : Entity_Id := Empty)
27901 is
27902 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
27903 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
27904 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
27905
27906 Available_States : Elist_Id := No_Elist;
27907 -- A list of all abstract states defined in the package declaration that
27908 -- are available for refinement. The list is used to report unrefined
27909 -- states.
27910
27911 Body_States : Elist_Id := No_Elist;
27912 -- A list of all hidden states that appear in the body of the related
27913 -- package. The list is used to report unused hidden states.
27914
27915 Constituents_Seen : Elist_Id := No_Elist;
27916 -- A list that contains all constituents processed so far. The list is
27917 -- used to detect multiple uses of the same constituent.
27918
27919 Freeze_Posted : Boolean := False;
27920 -- A flag that controls the output of a freezing-related error (see use
27921 -- below).
27922
27923 Refined_States_Seen : Elist_Id := No_Elist;
27924 -- A list that contains all refined states processed so far. The list is
27925 -- used to detect duplicate refinements.
27926
27927 procedure Analyze_Refinement_Clause (Clause : Node_Id);
27928 -- Perform full analysis of a single refinement clause
27929
27930 procedure Report_Unrefined_States (States : Elist_Id);
27931 -- Emit errors for all unrefined abstract states found in list States
27932
27933 -------------------------------
27934 -- Analyze_Refinement_Clause --
27935 -------------------------------
27936
27937 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
27938 AR_Constit : Entity_Id := Empty;
27939 AW_Constit : Entity_Id := Empty;
27940 ER_Constit : Entity_Id := Empty;
27941 EW_Constit : Entity_Id := Empty;
27942 -- The entities of external constituents that contain one of the
27943 -- following enabled properties: Async_Readers, Async_Writers,
27944 -- Effective_Reads and Effective_Writes.
27945
27946 External_Constit_Seen : Boolean := False;
27947 -- Flag used to mark when at least one external constituent is part
27948 -- of the state refinement.
27949
27950 Non_Null_Seen : Boolean := False;
27951 Null_Seen : Boolean := False;
27952 -- Flags used to detect multiple uses of null in a single clause or a
27953 -- mixture of null and non-null constituents.
27954
27955 Part_Of_Constits : Elist_Id := No_Elist;
27956 -- A list of all candidate constituents subject to indicator Part_Of
27957 -- where the encapsulating state is the current state.
27958
27959 State : Node_Id;
27960 State_Id : Entity_Id;
27961 -- The current state being refined
27962
27963 procedure Analyze_Constituent (Constit : Node_Id);
27964 -- Perform full analysis of a single constituent
27965
27966 procedure Check_External_Property
27967 (Prop_Nam : Name_Id;
27968 Enabled : Boolean;
27969 Constit : Entity_Id);
27970 -- Determine whether a property denoted by name Prop_Nam is present
27971 -- in the refined state. Emit an error if this is not the case. Flag
27972 -- Enabled should be set when the property applies to the refined
27973 -- state. Constit denotes the constituent (if any) which introduces
27974 -- the property in the refinement.
27975
27976 procedure Match_State;
27977 -- Determine whether the state being refined appears in list
27978 -- Available_States. Emit an error when attempting to re-refine the
27979 -- state or when the state is not defined in the package declaration,
27980 -- otherwise remove the state from Available_States.
27981
27982 procedure Report_Unused_Constituents (Constits : Elist_Id);
27983 -- Emit errors for all unused Part_Of constituents in list Constits
27984
27985 -------------------------
27986 -- Analyze_Constituent --
27987 -------------------------
27988
27989 procedure Analyze_Constituent (Constit : Node_Id) is
27990 procedure Match_Constituent (Constit_Id : Entity_Id);
27991 -- Determine whether constituent Constit denoted by its entity
27992 -- Constit_Id appears in Body_States. Emit an error when the
27993 -- constituent is not a valid hidden state of the related package
27994 -- or when it is used more than once. Otherwise remove the
27995 -- constituent from Body_States.
27996
27997 -----------------------
27998 -- Match_Constituent --
27999 -----------------------
28000
28001 procedure Match_Constituent (Constit_Id : Entity_Id) is
28002 procedure Collect_Constituent;
28003 -- Verify the legality of constituent Constit_Id and add it to
28004 -- the refinements of State_Id.
28005
28006 -------------------------
28007 -- Collect_Constituent --
28008 -------------------------
28009
28010 procedure Collect_Constituent is
28011 Constits : Elist_Id;
28012
28013 begin
28014 -- The Ghost policy in effect at the point of abstract state
28015 -- declaration and constituent must match (SPARK RM 6.9(15))
28016
28017 Check_Ghost_Refinement
28018 (State, State_Id, Constit, Constit_Id);
28019
28020 -- A synchronized state must be refined by a synchronized
28021 -- object or another synchronized state (SPARK RM 9.6).
28022
28023 if Is_Synchronized_State (State_Id)
28024 and then not Is_Synchronized_Object (Constit_Id)
28025 and then not Is_Synchronized_State (Constit_Id)
28026 then
28027 SPARK_Msg_NE
28028 ("constituent of synchronized state & must be "
28029 & "synchronized", Constit, State_Id);
28030 end if;
28031
28032 -- Add the constituent to the list of processed items to aid
28033 -- with the detection of duplicates.
28034
28035 Append_New_Elmt (Constit_Id, Constituents_Seen);
28036
28037 -- Collect the constituent in the list of refinement items
28038 -- and establish a relation between the refined state and
28039 -- the item.
28040
28041 Constits := Refinement_Constituents (State_Id);
28042
28043 if No (Constits) then
28044 Constits := New_Elmt_List;
28045 Set_Refinement_Constituents (State_Id, Constits);
28046 end if;
28047
28048 Append_Elmt (Constit_Id, Constits);
28049 Set_Encapsulating_State (Constit_Id, State_Id);
28050
28051 -- The state has at least one legal constituent, mark the
28052 -- start of the refinement region. The region ends when the
28053 -- body declarations end (see routine Analyze_Declarations).
28054
28055 Set_Has_Visible_Refinement (State_Id);
28056
28057 -- When the constituent is external, save its relevant
28058 -- property for further checks.
28059
28060 if Async_Readers_Enabled (Constit_Id) then
28061 AR_Constit := Constit_Id;
28062 External_Constit_Seen := True;
28063 end if;
28064
28065 if Async_Writers_Enabled (Constit_Id) then
28066 AW_Constit := Constit_Id;
28067 External_Constit_Seen := True;
28068 end if;
28069
28070 if Effective_Reads_Enabled (Constit_Id) then
28071 ER_Constit := Constit_Id;
28072 External_Constit_Seen := True;
28073 end if;
28074
28075 if Effective_Writes_Enabled (Constit_Id) then
28076 EW_Constit := Constit_Id;
28077 External_Constit_Seen := True;
28078 end if;
28079 end Collect_Constituent;
28080
28081 -- Local variables
28082
28083 State_Elmt : Elmt_Id;
28084
28085 -- Start of processing for Match_Constituent
28086
28087 begin
28088 -- Detect a duplicate use of a constituent
28089
28090 if Contains (Constituents_Seen, Constit_Id) then
28091 SPARK_Msg_NE
28092 ("duplicate use of constituent &", Constit, Constit_Id);
28093 return;
28094 end if;
28095
28096 -- The constituent is subject to a Part_Of indicator
28097
28098 if Present (Encapsulating_State (Constit_Id)) then
28099 if Encapsulating_State (Constit_Id) = State_Id then
28100 Remove (Part_Of_Constits, Constit_Id);
28101 Collect_Constituent;
28102
28103 -- The constituent is part of another state and is used
28104 -- incorrectly in the refinement of the current state.
28105
28106 else
28107 Error_Msg_Name_1 := Chars (State_Id);
28108 SPARK_Msg_NE
28109 ("& cannot act as constituent of state %",
28110 Constit, Constit_Id);
28111 SPARK_Msg_NE
28112 ("\Part_Of indicator specifies encapsulator &",
28113 Constit, Encapsulating_State (Constit_Id));
28114 end if;
28115
28116 -- The only other source of legal constituents is the body
28117 -- state space of the related package.
28118
28119 else
28120 if Present (Body_States) then
28121 State_Elmt := First_Elmt (Body_States);
28122 while Present (State_Elmt) loop
28123
28124 -- Consume a valid constituent to signal that it has
28125 -- been encountered.
28126
28127 if Node (State_Elmt) = Constit_Id then
28128 Remove_Elmt (Body_States, State_Elmt);
28129 Collect_Constituent;
28130 return;
28131 end if;
28132
28133 Next_Elmt (State_Elmt);
28134 end loop;
28135 end if;
28136
28137 -- At this point it is known that the constituent is not
28138 -- part of the package hidden state and cannot be used in
28139 -- a refinement (SPARK RM 7.2.2(9)).
28140
28141 Error_Msg_Name_1 := Chars (Spec_Id);
28142 SPARK_Msg_NE
28143 ("cannot use & in refinement, constituent is not a hidden "
28144 & "state of package %", Constit, Constit_Id);
28145 end if;
28146 end Match_Constituent;
28147
28148 -- Local variables
28149
28150 Constit_Id : Entity_Id;
28151 Constits : Elist_Id;
28152
28153 -- Start of processing for Analyze_Constituent
28154
28155 begin
28156 -- Detect multiple uses of null in a single refinement clause or a
28157 -- mixture of null and non-null constituents.
28158
28159 if Nkind (Constit) = N_Null then
28160 if Null_Seen then
28161 SPARK_Msg_N
28162 ("multiple null constituents not allowed", Constit);
28163
28164 elsif Non_Null_Seen then
28165 SPARK_Msg_N
28166 ("cannot mix null and non-null constituents", Constit);
28167
28168 else
28169 Null_Seen := True;
28170
28171 -- Collect the constituent in the list of refinement items
28172
28173 Constits := Refinement_Constituents (State_Id);
28174
28175 if No (Constits) then
28176 Constits := New_Elmt_List;
28177 Set_Refinement_Constituents (State_Id, Constits);
28178 end if;
28179
28180 Append_Elmt (Constit, Constits);
28181
28182 -- The state has at least one legal constituent, mark the
28183 -- start of the refinement region. The region ends when the
28184 -- body declarations end (see Analyze_Declarations).
28185
28186 Set_Has_Visible_Refinement (State_Id);
28187 end if;
28188
28189 -- Non-null constituents
28190
28191 else
28192 Non_Null_Seen := True;
28193
28194 if Null_Seen then
28195 SPARK_Msg_N
28196 ("cannot mix null and non-null constituents", Constit);
28197 end if;
28198
28199 Analyze (Constit);
28200 Resolve_State (Constit);
28201
28202 -- Ensure that the constituent denotes a valid state or a
28203 -- whole object (SPARK RM 7.2.2(5)).
28204
28205 if Is_Entity_Name (Constit) then
28206 Constit_Id := Entity_Of (Constit);
28207
28208 -- When a constituent is declared after a subprogram body
28209 -- that caused freezing of the related contract where
28210 -- pragma Refined_State resides, the constituent appears
28211 -- undefined and carries Any_Id as its entity.
28212
28213 -- package body Pack
28214 -- with Refined_State => (State => Constit)
28215 -- is
28216 -- procedure Proc
28217 -- with Refined_Global => (Input => Constit)
28218 -- is
28219 -- ...
28220 -- end Proc;
28221
28222 -- Constit : ...;
28223 -- end Pack;
28224
28225 if Constit_Id = Any_Id then
28226 SPARK_Msg_NE ("& is undefined", Constit, Constit_Id);
28227
28228 -- Emit a specialized info message when the contract of
28229 -- the related package body was "frozen" by another body.
28230 -- Note that it is not possible to precisely identify why
28231 -- the constituent is undefined because it is not visible
28232 -- when pragma Refined_State is analyzed. This message is
28233 -- a reasonable approximation.
28234
28235 if Present (Freeze_Id) and then not Freeze_Posted then
28236 Freeze_Posted := True;
28237
28238 Error_Msg_Name_1 := Chars (Body_Id);
28239 Error_Msg_Sloc := Sloc (Freeze_Id);
28240 SPARK_Msg_NE
28241 ("body & declared # freezes the contract of %",
28242 N, Freeze_Id);
28243 SPARK_Msg_N
28244 ("\all constituents must be declared before body #",
28245 N);
28246
28247 -- A misplaced constituent is a critical error because
28248 -- pragma Refined_Depends or Refined_Global depends on
28249 -- the proper link between a state and a constituent.
28250 -- Stop the compilation, as this leads to a multitude
28251 -- of misleading cascaded errors.
28252
28253 raise Unrecoverable_Error;
28254 end if;
28255
28256 -- The constituent is a valid state or object
28257
28258 elsif Ekind_In (Constit_Id, E_Abstract_State,
28259 E_Constant,
28260 E_Variable)
28261 then
28262 Match_Constituent (Constit_Id);
28263
28264 -- The variable may eventually become a constituent of a
28265 -- single protected/task type. Record the reference now
28266 -- and verify its legality when analyzing the contract of
28267 -- the variable (SPARK RM 9.3).
28268
28269 if Ekind (Constit_Id) = E_Variable then
28270 Record_Possible_Part_Of_Reference
28271 (Var_Id => Constit_Id,
28272 Ref => Constit);
28273 end if;
28274
28275 -- Otherwise the constituent is illegal
28276
28277 else
28278 SPARK_Msg_NE
28279 ("constituent & must denote object or state",
28280 Constit, Constit_Id);
28281 end if;
28282
28283 -- The constituent is illegal
28284
28285 else
28286 SPARK_Msg_N ("malformed constituent", Constit);
28287 end if;
28288 end if;
28289 end Analyze_Constituent;
28290
28291 -----------------------------
28292 -- Check_External_Property --
28293 -----------------------------
28294
28295 procedure Check_External_Property
28296 (Prop_Nam : Name_Id;
28297 Enabled : Boolean;
28298 Constit : Entity_Id)
28299 is
28300 begin
28301 -- The property is missing in the declaration of the state, but
28302 -- a constituent is introducing it in the state refinement
28303 -- (SPARK RM 7.2.8(2)).
28304
28305 if not Enabled and then Present (Constit) then
28306 Error_Msg_Name_1 := Prop_Nam;
28307 Error_Msg_Name_2 := Chars (State_Id);
28308 SPARK_Msg_NE
28309 ("constituent & introduces external property % in refinement "
28310 & "of state %", State, Constit);
28311
28312 Error_Msg_Sloc := Sloc (State_Id);
28313 SPARK_Msg_N
28314 ("\property is missing in abstract state declaration #",
28315 State);
28316 end if;
28317 end Check_External_Property;
28318
28319 -----------------
28320 -- Match_State --
28321 -----------------
28322
28323 procedure Match_State is
28324 State_Elmt : Elmt_Id;
28325
28326 begin
28327 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
28328
28329 if Contains (Refined_States_Seen, State_Id) then
28330 SPARK_Msg_NE
28331 ("duplicate refinement of state &", State, State_Id);
28332 return;
28333 end if;
28334
28335 -- Inspect the abstract states defined in the package declaration
28336 -- looking for a match.
28337
28338 State_Elmt := First_Elmt (Available_States);
28339 while Present (State_Elmt) loop
28340
28341 -- A valid abstract state is being refined in the body. Add
28342 -- the state to the list of processed refined states to aid
28343 -- with the detection of duplicate refinements. Remove the
28344 -- state from Available_States to signal that it has already
28345 -- been refined.
28346
28347 if Node (State_Elmt) = State_Id then
28348 Append_New_Elmt (State_Id, Refined_States_Seen);
28349 Remove_Elmt (Available_States, State_Elmt);
28350 return;
28351 end if;
28352
28353 Next_Elmt (State_Elmt);
28354 end loop;
28355
28356 -- If we get here, we are refining a state that is not defined in
28357 -- the package declaration.
28358
28359 Error_Msg_Name_1 := Chars (Spec_Id);
28360 SPARK_Msg_NE
28361 ("cannot refine state, & is not defined in package %",
28362 State, State_Id);
28363 end Match_State;
28364
28365 --------------------------------
28366 -- Report_Unused_Constituents --
28367 --------------------------------
28368
28369 procedure Report_Unused_Constituents (Constits : Elist_Id) is
28370 Constit_Elmt : Elmt_Id;
28371 Constit_Id : Entity_Id;
28372 Posted : Boolean := False;
28373
28374 begin
28375 if Present (Constits) then
28376 Constit_Elmt := First_Elmt (Constits);
28377 while Present (Constit_Elmt) loop
28378 Constit_Id := Node (Constit_Elmt);
28379
28380 -- Generate an error message of the form:
28381
28382 -- state ... has unused Part_Of constituents
28383 -- abstract state ... defined at ...
28384 -- constant ... defined at ...
28385 -- variable ... defined at ...
28386
28387 if not Posted then
28388 Posted := True;
28389 SPARK_Msg_NE
28390 ("state & has unused Part_Of constituents",
28391 State, State_Id);
28392 end if;
28393
28394 Error_Msg_Sloc := Sloc (Constit_Id);
28395
28396 if Ekind (Constit_Id) = E_Abstract_State then
28397 SPARK_Msg_NE
28398 ("\abstract state & defined #", State, Constit_Id);
28399
28400 elsif Ekind (Constit_Id) = E_Constant then
28401 SPARK_Msg_NE
28402 ("\constant & defined #", State, Constit_Id);
28403
28404 else
28405 pragma Assert (Ekind (Constit_Id) = E_Variable);
28406 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
28407 end if;
28408
28409 Next_Elmt (Constit_Elmt);
28410 end loop;
28411 end if;
28412 end Report_Unused_Constituents;
28413
28414 -- Local declarations
28415
28416 Body_Ref : Node_Id;
28417 Body_Ref_Elmt : Elmt_Id;
28418 Constit : Node_Id;
28419 Extra_State : Node_Id;
28420
28421 -- Start of processing for Analyze_Refinement_Clause
28422
28423 begin
28424 -- A refinement clause appears as a component association where the
28425 -- sole choice is the state and the expressions are the constituents.
28426 -- This is a syntax error, always report.
28427
28428 if Nkind (Clause) /= N_Component_Association then
28429 Error_Msg_N ("malformed state refinement clause", Clause);
28430 return;
28431 end if;
28432
28433 -- Analyze the state name of a refinement clause
28434
28435 State := First (Choices (Clause));
28436
28437 Analyze (State);
28438 Resolve_State (State);
28439
28440 -- Ensure that the state name denotes a valid abstract state that is
28441 -- defined in the spec of the related package.
28442
28443 if Is_Entity_Name (State) then
28444 State_Id := Entity_Of (State);
28445
28446 -- When the abstract state is undefined, it appears as Any_Id. Do
28447 -- not continue with the analysis of the clause.
28448
28449 if State_Id = Any_Id then
28450 return;
28451
28452 -- Catch any attempts to re-refine a state or refine a state that
28453 -- is not defined in the package declaration.
28454
28455 elsif Ekind (State_Id) = E_Abstract_State then
28456 Match_State;
28457
28458 else
28459 SPARK_Msg_NE ("& must denote abstract state", State, State_Id);
28460 return;
28461 end if;
28462
28463 -- References to a state with visible refinement are illegal.
28464 -- When nested packages are involved, detecting such references is
28465 -- tricky because pragma Refined_State is analyzed later than the
28466 -- offending pragma Depends or Global. References that occur in
28467 -- such nested context are stored in a list. Emit errors for all
28468 -- references found in Body_References (SPARK RM 6.1.4(8)).
28469
28470 if Present (Body_References (State_Id)) then
28471 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
28472 while Present (Body_Ref_Elmt) loop
28473 Body_Ref := Node (Body_Ref_Elmt);
28474
28475 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
28476 Error_Msg_Sloc := Sloc (State);
28477 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
28478
28479 Next_Elmt (Body_Ref_Elmt);
28480 end loop;
28481 end if;
28482
28483 -- The state name is illegal. This is a syntax error, always report.
28484
28485 else
28486 Error_Msg_N ("malformed state name in refinement clause", State);
28487 return;
28488 end if;
28489
28490 -- A refinement clause may only refine one state at a time
28491
28492 Extra_State := Next (State);
28493
28494 if Present (Extra_State) then
28495 SPARK_Msg_N
28496 ("refinement clause cannot cover multiple states", Extra_State);
28497 end if;
28498
28499 -- Replicate the Part_Of constituents of the refined state because
28500 -- the algorithm will consume items.
28501
28502 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
28503
28504 -- Analyze all constituents of the refinement. Multiple constituents
28505 -- appear as an aggregate.
28506
28507 Constit := Expression (Clause);
28508
28509 if Nkind (Constit) = N_Aggregate then
28510 if Present (Component_Associations (Constit)) then
28511 SPARK_Msg_N
28512 ("constituents of refinement clause must appear in "
28513 & "positional form", Constit);
28514
28515 else pragma Assert (Present (Expressions (Constit)));
28516 Constit := First (Expressions (Constit));
28517 while Present (Constit) loop
28518 Analyze_Constituent (Constit);
28519 Next (Constit);
28520 end loop;
28521 end if;
28522
28523 -- Various forms of a single constituent. Note that these may include
28524 -- malformed constituents.
28525
28526 else
28527 Analyze_Constituent (Constit);
28528 end if;
28529
28530 -- Verify that external constituents do not introduce new external
28531 -- property in the state refinement (SPARK RM 7.2.8(2)).
28532
28533 if Is_External_State (State_Id) then
28534 Check_External_Property
28535 (Prop_Nam => Name_Async_Readers,
28536 Enabled => Async_Readers_Enabled (State_Id),
28537 Constit => AR_Constit);
28538
28539 Check_External_Property
28540 (Prop_Nam => Name_Async_Writers,
28541 Enabled => Async_Writers_Enabled (State_Id),
28542 Constit => AW_Constit);
28543
28544 Check_External_Property
28545 (Prop_Nam => Name_Effective_Reads,
28546 Enabled => Effective_Reads_Enabled (State_Id),
28547 Constit => ER_Constit);
28548
28549 Check_External_Property
28550 (Prop_Nam => Name_Effective_Writes,
28551 Enabled => Effective_Writes_Enabled (State_Id),
28552 Constit => EW_Constit);
28553
28554 -- When a refined state is not external, it should not have external
28555 -- constituents (SPARK RM 7.2.8(1)).
28556
28557 elsif External_Constit_Seen then
28558 SPARK_Msg_NE
28559 ("non-external state & cannot contain external constituents in "
28560 & "refinement", State, State_Id);
28561 end if;
28562
28563 -- Ensure that all Part_Of candidate constituents have been mentioned
28564 -- in the refinement clause.
28565
28566 Report_Unused_Constituents (Part_Of_Constits);
28567 end Analyze_Refinement_Clause;
28568
28569 -----------------------------
28570 -- Report_Unrefined_States --
28571 -----------------------------
28572
28573 procedure Report_Unrefined_States (States : Elist_Id) is
28574 State_Elmt : Elmt_Id;
28575
28576 begin
28577 if Present (States) then
28578 State_Elmt := First_Elmt (States);
28579 while Present (State_Elmt) loop
28580 SPARK_Msg_N
28581 ("abstract state & must be refined", Node (State_Elmt));
28582
28583 Next_Elmt (State_Elmt);
28584 end loop;
28585 end if;
28586 end Report_Unrefined_States;
28587
28588 -- Local declarations
28589
28590 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
28591 Clause : Node_Id;
28592
28593 -- Start of processing for Analyze_Refined_State_In_Decl_Part
28594
28595 begin
28596 -- Do not analyze the pragma multiple times
28597
28598 if Is_Analyzed_Pragma (N) then
28599 return;
28600 end if;
28601
28602 -- Save the scenario for examination by the ABE Processing phase
28603
28604 Record_Elaboration_Scenario (N);
28605
28606 -- Replicate the abstract states declared by the package because the
28607 -- matching algorithm will consume states.
28608
28609 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
28610
28611 -- Gather all abstract states and objects declared in the visible
28612 -- state space of the package body. These items must be utilized as
28613 -- constituents in a state refinement.
28614
28615 Body_States := Collect_Body_States (Body_Id);
28616
28617 -- Multiple non-null state refinements appear as an aggregate
28618
28619 if Nkind (Clauses) = N_Aggregate then
28620 if Present (Expressions (Clauses)) then
28621 SPARK_Msg_N
28622 ("state refinements must appear as component associations",
28623 Clauses);
28624
28625 else pragma Assert (Present (Component_Associations (Clauses)));
28626 Clause := First (Component_Associations (Clauses));
28627 while Present (Clause) loop
28628 Analyze_Refinement_Clause (Clause);
28629 Next (Clause);
28630 end loop;
28631 end if;
28632
28633 -- Various forms of a single state refinement. Note that these may
28634 -- include malformed refinements.
28635
28636 else
28637 Analyze_Refinement_Clause (Clauses);
28638 end if;
28639
28640 -- List all abstract states that were left unrefined
28641
28642 Report_Unrefined_States (Available_States);
28643
28644 Set_Is_Analyzed_Pragma (N);
28645 end Analyze_Refined_State_In_Decl_Part;
28646
28647 ------------------------------------
28648 -- Analyze_Test_Case_In_Decl_Part --
28649 ------------------------------------
28650
28651 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
28652 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
28653 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
28654
28655 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
28656 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
28657 -- denoted by Arg_Nam.
28658
28659 ------------------------------
28660 -- Preanalyze_Test_Case_Arg --
28661 ------------------------------
28662
28663 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
28664 Arg : Node_Id;
28665
28666 begin
28667 -- Preanalyze the original aspect argument for a generic subprogram
28668 -- to properly capture global references.
28669
28670 if Is_Generic_Subprogram (Spec_Id) then
28671 Arg :=
28672 Test_Case_Arg
28673 (Prag => N,
28674 Arg_Nam => Arg_Nam,
28675 From_Aspect => True);
28676
28677 if Present (Arg) then
28678 Preanalyze_Assert_Expression
28679 (Expression (Arg), Standard_Boolean);
28680 end if;
28681 end if;
28682
28683 Arg := Test_Case_Arg (N, Arg_Nam);
28684
28685 if Present (Arg) then
28686 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
28687 end if;
28688 end Preanalyze_Test_Case_Arg;
28689
28690 -- Local variables
28691
28692 Restore_Scope : Boolean := False;
28693
28694 -- Start of processing for Analyze_Test_Case_In_Decl_Part
28695
28696 begin
28697 -- Do not analyze the pragma multiple times
28698
28699 if Is_Analyzed_Pragma (N) then
28700 return;
28701 end if;
28702
28703 -- Ensure that the formal parameters are visible when analyzing all
28704 -- clauses. This falls out of the general rule of aspects pertaining
28705 -- to subprogram declarations.
28706
28707 if not In_Open_Scopes (Spec_Id) then
28708 Restore_Scope := True;
28709 Push_Scope (Spec_Id);
28710
28711 if Is_Generic_Subprogram (Spec_Id) then
28712 Install_Generic_Formals (Spec_Id);
28713 else
28714 Install_Formals (Spec_Id);
28715 end if;
28716 end if;
28717
28718 Preanalyze_Test_Case_Arg (Name_Requires);
28719 Preanalyze_Test_Case_Arg (Name_Ensures);
28720
28721 if Restore_Scope then
28722 End_Scope;
28723 end if;
28724
28725 -- Currently it is not possible to inline pre/postconditions on a
28726 -- subprogram subject to pragma Inline_Always.
28727
28728 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
28729
28730 Set_Is_Analyzed_Pragma (N);
28731 end Analyze_Test_Case_In_Decl_Part;
28732
28733 ----------------
28734 -- Appears_In --
28735 ----------------
28736
28737 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
28738 Elmt : Elmt_Id;
28739 Id : Entity_Id;
28740
28741 begin
28742 if Present (List) then
28743 Elmt := First_Elmt (List);
28744 while Present (Elmt) loop
28745 if Nkind (Node (Elmt)) = N_Defining_Identifier then
28746 Id := Node (Elmt);
28747 else
28748 Id := Entity_Of (Node (Elmt));
28749 end if;
28750
28751 if Id = Item_Id then
28752 return True;
28753 end if;
28754
28755 Next_Elmt (Elmt);
28756 end loop;
28757 end if;
28758
28759 return False;
28760 end Appears_In;
28761
28762 -----------------------------------
28763 -- Build_Pragma_Check_Equivalent --
28764 -----------------------------------
28765
28766 function Build_Pragma_Check_Equivalent
28767 (Prag : Node_Id;
28768 Subp_Id : Entity_Id := Empty;
28769 Inher_Id : Entity_Id := Empty;
28770 Keep_Pragma_Id : Boolean := False) return Node_Id
28771 is
28772 function Suppress_Reference (N : Node_Id) return Traverse_Result;
28773 -- Detect whether node N references a formal parameter subject to
28774 -- pragma Unreferenced. If this is the case, set Comes_From_Source
28775 -- to False to suppress the generation of a reference when analyzing
28776 -- N later on.
28777
28778 ------------------------
28779 -- Suppress_Reference --
28780 ------------------------
28781
28782 function Suppress_Reference (N : Node_Id) return Traverse_Result is
28783 Formal : Entity_Id;
28784
28785 begin
28786 if Is_Entity_Name (N) and then Present (Entity (N)) then
28787 Formal := Entity (N);
28788
28789 -- The formal parameter is subject to pragma Unreferenced. Prevent
28790 -- the generation of references by resetting the Comes_From_Source
28791 -- flag.
28792
28793 if Is_Formal (Formal)
28794 and then Has_Pragma_Unreferenced (Formal)
28795 then
28796 Set_Comes_From_Source (N, False);
28797 end if;
28798 end if;
28799
28800 return OK;
28801 end Suppress_Reference;
28802
28803 procedure Suppress_References is
28804 new Traverse_Proc (Suppress_Reference);
28805
28806 -- Local variables
28807
28808 Loc : constant Source_Ptr := Sloc (Prag);
28809 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
28810 Check_Prag : Node_Id;
28811 Msg_Arg : Node_Id;
28812 Nam : Name_Id;
28813
28814 Needs_Wrapper : Boolean;
28815 pragma Unreferenced (Needs_Wrapper);
28816
28817 -- Start of processing for Build_Pragma_Check_Equivalent
28818
28819 begin
28820 -- When the pre- or postcondition is inherited, map the formals of the
28821 -- inherited subprogram to those of the current subprogram. In addition,
28822 -- map primitive operations of the parent type into the corresponding
28823 -- primitive operations of the descendant.
28824
28825 if Present (Inher_Id) then
28826 pragma Assert (Present (Subp_Id));
28827
28828 Update_Primitives_Mapping (Inher_Id, Subp_Id);
28829
28830 -- Use generic machinery to copy inherited pragma, as if it were an
28831 -- instantiation, resetting source locations appropriately, so that
28832 -- expressions inside the inherited pragma use chained locations.
28833 -- This is used in particular in GNATprove to locate precisely
28834 -- messages on a given inherited pragma.
28835
28836 Set_Copied_Sloc_For_Inherited_Pragma
28837 (Unit_Declaration_Node (Subp_Id), Inher_Id);
28838 Check_Prag := New_Copy_Tree (Source => Prag);
28839
28840 -- Build the inherited class-wide condition
28841
28842 Build_Class_Wide_Expression
28843 (Prag => Check_Prag,
28844 Subp => Subp_Id,
28845 Par_Subp => Inher_Id,
28846 Adjust_Sloc => True,
28847 Needs_Wrapper => Needs_Wrapper);
28848
28849 -- If not an inherited condition simply copy the original pragma
28850
28851 else
28852 Check_Prag := New_Copy_Tree (Source => Prag);
28853 end if;
28854
28855 -- Mark the pragma as being internally generated and reset the Analyzed
28856 -- flag.
28857
28858 Set_Analyzed (Check_Prag, False);
28859 Set_Comes_From_Source (Check_Prag, False);
28860
28861 -- The tree of the original pragma may contain references to the
28862 -- formal parameters of the related subprogram. At the same time
28863 -- the corresponding body may mark the formals as unreferenced:
28864
28865 -- procedure Proc (Formal : ...)
28866 -- with Pre => Formal ...;
28867
28868 -- procedure Proc (Formal : ...) is
28869 -- pragma Unreferenced (Formal);
28870 -- ...
28871
28872 -- This creates problems because all pragma Check equivalents are
28873 -- analyzed at the end of the body declarations. Since all source
28874 -- references have already been accounted for, reset any references
28875 -- to such formals in the generated pragma Check equivalent.
28876
28877 Suppress_References (Check_Prag);
28878
28879 if Present (Corresponding_Aspect (Prag)) then
28880 Nam := Chars (Identifier (Corresponding_Aspect (Prag)));
28881 else
28882 Nam := Prag_Nam;
28883 end if;
28884
28885 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
28886 -- the copied pragma in the newly created pragma, convert the copy into
28887 -- pragma Check by correcting the name and adding a check_kind argument.
28888
28889 if not Keep_Pragma_Id then
28890 Set_Class_Present (Check_Prag, False);
28891
28892 Set_Pragma_Identifier
28893 (Check_Prag, Make_Identifier (Loc, Name_Check));
28894
28895 Prepend_To (Pragma_Argument_Associations (Check_Prag),
28896 Make_Pragma_Argument_Association (Loc,
28897 Expression => Make_Identifier (Loc, Nam)));
28898 end if;
28899
28900 -- Update the error message when the pragma is inherited
28901
28902 if Present (Inher_Id) then
28903 Msg_Arg := Last (Pragma_Argument_Associations (Check_Prag));
28904
28905 if Chars (Msg_Arg) = Name_Message then
28906 String_To_Name_Buffer (Strval (Expression (Msg_Arg)));
28907
28908 -- Insert "inherited" to improve the error message
28909
28910 if Name_Buffer (1 .. 8) = "failed p" then
28911 Insert_Str_In_Name_Buffer ("inherited ", 8);
28912 Set_Strval (Expression (Msg_Arg), String_From_Name_Buffer);
28913 end if;
28914 end if;
28915 end if;
28916
28917 return Check_Prag;
28918 end Build_Pragma_Check_Equivalent;
28919
28920 -----------------------------
28921 -- Check_Applicable_Policy --
28922 -----------------------------
28923
28924 procedure Check_Applicable_Policy (N : Node_Id) is
28925 PP : Node_Id;
28926 Policy : Name_Id;
28927
28928 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
28929
28930 begin
28931 -- No effect if not valid assertion kind name
28932
28933 if not Is_Valid_Assertion_Kind (Ename) then
28934 return;
28935 end if;
28936
28937 -- Loop through entries in check policy list
28938
28939 PP := Opt.Check_Policy_List;
28940 while Present (PP) loop
28941 declare
28942 PPA : constant List_Id := Pragma_Argument_Associations (PP);
28943 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
28944
28945 begin
28946 if Ename = Pnm
28947 or else Pnm = Name_Assertion
28948 or else (Pnm = Name_Statement_Assertions
28949 and then Nam_In (Ename, Name_Assert,
28950 Name_Assert_And_Cut,
28951 Name_Assume,
28952 Name_Loop_Invariant,
28953 Name_Loop_Variant))
28954 then
28955 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
28956
28957 case Policy is
28958 when Name_Ignore
28959 | Name_Off
28960 =>
28961 -- In CodePeer mode and GNATprove mode, we need to
28962 -- consider all assertions, unless they are disabled.
28963 -- Force Is_Checked on ignored assertions, in particular
28964 -- because transformations of the AST may depend on
28965 -- assertions being checked (e.g. the translation of
28966 -- attribute 'Loop_Entry).
28967
28968 if CodePeer_Mode or GNATprove_Mode then
28969 Set_Is_Checked (N, True);
28970 Set_Is_Ignored (N, False);
28971 else
28972 Set_Is_Checked (N, False);
28973 Set_Is_Ignored (N, True);
28974 end if;
28975
28976 when Name_Check
28977 | Name_On
28978 =>
28979 Set_Is_Checked (N, True);
28980 Set_Is_Ignored (N, False);
28981
28982 when Name_Disable =>
28983 Set_Is_Ignored (N, True);
28984 Set_Is_Checked (N, False);
28985 Set_Is_Disabled (N, True);
28986
28987 -- That should be exhaustive, the null here is a defence
28988 -- against a malformed tree from previous errors.
28989
28990 when others =>
28991 null;
28992 end case;
28993
28994 return;
28995 end if;
28996
28997 PP := Next_Pragma (PP);
28998 end;
28999 end loop;
29000
29001 -- If there are no specific entries that matched, then we let the
29002 -- setting of assertions govern. Note that this provides the needed
29003 -- compatibility with the RM for the cases of assertion, invariant,
29004 -- precondition, predicate, and postcondition. Note also that
29005 -- Assertions_Enabled is forced in CodePeer mode and GNATprove mode.
29006
29007 if Assertions_Enabled then
29008 Set_Is_Checked (N, True);
29009 Set_Is_Ignored (N, False);
29010 else
29011 Set_Is_Checked (N, False);
29012 Set_Is_Ignored (N, True);
29013 end if;
29014 end Check_Applicable_Policy;
29015
29016 -------------------------------
29017 -- Check_External_Properties --
29018 -------------------------------
29019
29020 procedure Check_External_Properties
29021 (Item : Node_Id;
29022 AR : Boolean;
29023 AW : Boolean;
29024 ER : Boolean;
29025 EW : Boolean)
29026 is
29027 begin
29028 -- All properties enabled
29029
29030 if AR and AW and ER and EW then
29031 null;
29032
29033 -- Async_Readers + Effective_Writes
29034 -- Async_Readers + Async_Writers + Effective_Writes
29035
29036 elsif AR and EW and not ER then
29037 null;
29038
29039 -- Async_Writers + Effective_Reads
29040 -- Async_Readers + Async_Writers + Effective_Reads
29041
29042 elsif AW and ER and not EW then
29043 null;
29044
29045 -- Async_Readers + Async_Writers
29046
29047 elsif AR and AW and not ER and not EW then
29048 null;
29049
29050 -- Async_Readers
29051
29052 elsif AR and not AW and not ER and not EW then
29053 null;
29054
29055 -- Async_Writers
29056
29057 elsif AW and not AR and not ER and not EW then
29058 null;
29059
29060 else
29061 SPARK_Msg_N
29062 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
29063 Item);
29064 end if;
29065 end Check_External_Properties;
29066
29067 ----------------
29068 -- Check_Kind --
29069 ----------------
29070
29071 function Check_Kind (Nam : Name_Id) return Name_Id is
29072 PP : Node_Id;
29073
29074 begin
29075 -- Loop through entries in check policy list
29076
29077 PP := Opt.Check_Policy_List;
29078 while Present (PP) loop
29079 declare
29080 PPA : constant List_Id := Pragma_Argument_Associations (PP);
29081 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
29082
29083 begin
29084 if Nam = Pnm
29085 or else (Pnm = Name_Assertion
29086 and then Is_Valid_Assertion_Kind (Nam))
29087 or else (Pnm = Name_Statement_Assertions
29088 and then Nam_In (Nam, Name_Assert,
29089 Name_Assert_And_Cut,
29090 Name_Assume,
29091 Name_Loop_Invariant,
29092 Name_Loop_Variant))
29093 then
29094 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
29095 when Name_Check
29096 | Name_On
29097 =>
29098 return Name_Check;
29099
29100 when Name_Ignore
29101 | Name_Off
29102 =>
29103 return Name_Ignore;
29104
29105 when Name_Disable =>
29106 return Name_Disable;
29107
29108 when others =>
29109 raise Program_Error;
29110 end case;
29111
29112 else
29113 PP := Next_Pragma (PP);
29114 end if;
29115 end;
29116 end loop;
29117
29118 -- If there are no specific entries that matched, then we let the
29119 -- setting of assertions govern. Note that this provides the needed
29120 -- compatibility with the RM for the cases of assertion, invariant,
29121 -- precondition, predicate, and postcondition.
29122
29123 if Assertions_Enabled then
29124 return Name_Check;
29125 else
29126 return Name_Ignore;
29127 end if;
29128 end Check_Kind;
29129
29130 ---------------------------
29131 -- Check_Missing_Part_Of --
29132 ---------------------------
29133
29134 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
29135 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
29136 -- Determine whether a package denoted by Pack_Id declares at least one
29137 -- visible state.
29138
29139 -----------------------
29140 -- Has_Visible_State --
29141 -----------------------
29142
29143 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
29144 Item_Id : Entity_Id;
29145
29146 begin
29147 -- Traverse the entity chain of the package trying to find at least
29148 -- one visible abstract state, variable or a package [instantiation]
29149 -- that declares a visible state.
29150
29151 Item_Id := First_Entity (Pack_Id);
29152 while Present (Item_Id)
29153 and then not In_Private_Part (Item_Id)
29154 loop
29155 -- Do not consider internally generated items
29156
29157 if not Comes_From_Source (Item_Id) then
29158 null;
29159
29160 -- Do not consider generic formals or their corresponding actuals
29161 -- because they are not part of a visible state. Note that both
29162 -- entities are marked as hidden.
29163
29164 elsif Is_Hidden (Item_Id) then
29165 null;
29166
29167 -- A visible state has been found. Note that constants are not
29168 -- considered here because it is not possible to determine whether
29169 -- they depend on variable input. This check is left to the SPARK
29170 -- prover.
29171
29172 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
29173 return True;
29174
29175 -- Recursively peek into nested packages and instantiations
29176
29177 elsif Ekind (Item_Id) = E_Package
29178 and then Has_Visible_State (Item_Id)
29179 then
29180 return True;
29181 end if;
29182
29183 Next_Entity (Item_Id);
29184 end loop;
29185
29186 return False;
29187 end Has_Visible_State;
29188
29189 -- Local variables
29190
29191 Pack_Id : Entity_Id;
29192 Placement : State_Space_Kind;
29193
29194 -- Start of processing for Check_Missing_Part_Of
29195
29196 begin
29197 -- Do not consider abstract states, variables or package instantiations
29198 -- coming from an instance as those always inherit the Part_Of indicator
29199 -- of the instance itself.
29200
29201 if In_Instance then
29202 return;
29203
29204 -- Do not consider internally generated entities as these can never
29205 -- have a Part_Of indicator.
29206
29207 elsif not Comes_From_Source (Item_Id) then
29208 return;
29209
29210 -- Perform these checks only when SPARK_Mode is enabled as they will
29211 -- interfere with standard Ada rules and produce false positives.
29212
29213 elsif SPARK_Mode /= On then
29214 return;
29215
29216 -- Do not consider constants, because the compiler cannot accurately
29217 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
29218 -- act as a hidden state of a package.
29219
29220 elsif Ekind (Item_Id) = E_Constant then
29221 return;
29222 end if;
29223
29224 -- Find where the abstract state, variable or package instantiation
29225 -- lives with respect to the state space.
29226
29227 Find_Placement_In_State_Space
29228 (Item_Id => Item_Id,
29229 Placement => Placement,
29230 Pack_Id => Pack_Id);
29231
29232 -- Items that appear in a non-package construct (subprogram, block, etc)
29233 -- do not require a Part_Of indicator because they can never act as a
29234 -- hidden state.
29235
29236 if Placement = Not_In_Package then
29237 null;
29238
29239 -- An item declared in the body state space of a package always act as a
29240 -- constituent and does not need explicit Part_Of indicator.
29241
29242 elsif Placement = Body_State_Space then
29243 null;
29244
29245 -- In general an item declared in the visible state space of a package
29246 -- does not require a Part_Of indicator. The only exception is when the
29247 -- related package is a nongeneric private child unit, in which case
29248 -- Part_Of must denote a state in the parent unit or in one of its
29249 -- descendants.
29250
29251 elsif Placement = Visible_State_Space then
29252 if Is_Child_Unit (Pack_Id)
29253 and then not Is_Generic_Unit (Pack_Id)
29254 and then Is_Private_Descendant (Pack_Id)
29255 then
29256 -- A package instantiation does not need a Part_Of indicator when
29257 -- the related generic template has no visible state.
29258
29259 if Ekind (Item_Id) = E_Package
29260 and then Is_Generic_Instance (Item_Id)
29261 and then not Has_Visible_State (Item_Id)
29262 then
29263 null;
29264
29265 -- All other cases require Part_Of
29266
29267 else
29268 Error_Msg_N
29269 ("indicator Part_Of is required in this context "
29270 & "(SPARK RM 7.2.6(3))", Item_Id);
29271 Error_Msg_Name_1 := Chars (Pack_Id);
29272 Error_Msg_N
29273 ("\& is declared in the visible part of private child "
29274 & "unit %", Item_Id);
29275 end if;
29276 end if;
29277
29278 -- When the item appears in the private state space of a package, it
29279 -- must be a part of some state declared by the said package.
29280
29281 else pragma Assert (Placement = Private_State_Space);
29282
29283 -- The related package does not declare a state, the item cannot act
29284 -- as a Part_Of constituent.
29285
29286 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
29287 null;
29288
29289 -- A package instantiation does not need a Part_Of indicator when the
29290 -- related generic template has no visible state.
29291
29292 elsif Ekind (Item_Id) = E_Package
29293 and then Is_Generic_Instance (Item_Id)
29294 and then not Has_Visible_State (Item_Id)
29295 then
29296 null;
29297
29298 -- All other cases require Part_Of
29299
29300 else
29301 Error_Msg_N
29302 ("indicator Part_Of is required in this context "
29303 & "(SPARK RM 7.2.6(2))", Item_Id);
29304 Error_Msg_Name_1 := Chars (Pack_Id);
29305 Error_Msg_N
29306 ("\& is declared in the private part of package %", Item_Id);
29307 end if;
29308 end if;
29309 end Check_Missing_Part_Of;
29310
29311 ---------------------------------------------------
29312 -- Check_Postcondition_Use_In_Inlined_Subprogram --
29313 ---------------------------------------------------
29314
29315 procedure Check_Postcondition_Use_In_Inlined_Subprogram
29316 (Prag : Node_Id;
29317 Spec_Id : Entity_Id)
29318 is
29319 begin
29320 if Warn_On_Redundant_Constructs
29321 and then Has_Pragma_Inline_Always (Spec_Id)
29322 and then Assertions_Enabled
29323 then
29324 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
29325
29326 if From_Aspect_Specification (Prag) then
29327 Error_Msg_NE
29328 ("aspect % not enforced on inlined subprogram &?r?",
29329 Corresponding_Aspect (Prag), Spec_Id);
29330 else
29331 Error_Msg_NE
29332 ("pragma % not enforced on inlined subprogram &?r?",
29333 Prag, Spec_Id);
29334 end if;
29335 end if;
29336 end Check_Postcondition_Use_In_Inlined_Subprogram;
29337
29338 -------------------------------------
29339 -- Check_State_And_Constituent_Use --
29340 -------------------------------------
29341
29342 procedure Check_State_And_Constituent_Use
29343 (States : Elist_Id;
29344 Constits : Elist_Id;
29345 Context : Node_Id)
29346 is
29347 Constit_Elmt : Elmt_Id;
29348 Constit_Id : Entity_Id;
29349 State_Id : Entity_Id;
29350
29351 begin
29352 -- Nothing to do if there are no states or constituents
29353
29354 if No (States) or else No (Constits) then
29355 return;
29356 end if;
29357
29358 -- Inspect the list of constituents and try to determine whether its
29359 -- encapsulating state is in list States.
29360
29361 Constit_Elmt := First_Elmt (Constits);
29362 while Present (Constit_Elmt) loop
29363 Constit_Id := Node (Constit_Elmt);
29364
29365 -- Determine whether the constituent is part of an encapsulating
29366 -- state that appears in the same context and if this is the case,
29367 -- emit an error (SPARK RM 7.2.6(7)).
29368
29369 State_Id := Find_Encapsulating_State (States, Constit_Id);
29370
29371 if Present (State_Id) then
29372 Error_Msg_Name_1 := Chars (Constit_Id);
29373 SPARK_Msg_NE
29374 ("cannot mention state & and its constituent % in the same "
29375 & "context", Context, State_Id);
29376 exit;
29377 end if;
29378
29379 Next_Elmt (Constit_Elmt);
29380 end loop;
29381 end Check_State_And_Constituent_Use;
29382
29383 ---------------------------------------------
29384 -- Collect_Inherited_Class_Wide_Conditions --
29385 ---------------------------------------------
29386
29387 procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is
29388 Parent_Subp : constant Entity_Id :=
29389 Ultimate_Alias (Overridden_Operation (Subp));
29390 -- The Overridden_Operation may itself be inherited and as such have no
29391 -- explicit contract.
29392
29393 Prags : constant Node_Id := Contract (Parent_Subp);
29394 In_Spec_Expr : Boolean := In_Spec_Expression;
29395 Installed : Boolean;
29396 Prag : Node_Id;
29397 New_Prag : Node_Id;
29398
29399 begin
29400 Installed := False;
29401
29402 -- Iterate over the contract of the overridden subprogram to find all
29403 -- inherited class-wide pre- and postconditions.
29404
29405 if Present (Prags) then
29406 Prag := Pre_Post_Conditions (Prags);
29407
29408 while Present (Prag) loop
29409 if Nam_In (Pragma_Name_Unmapped (Prag),
29410 Name_Precondition, Name_Postcondition)
29411 and then Class_Present (Prag)
29412 then
29413 -- The generated pragma must be analyzed in the context of
29414 -- the subprogram, to make its formals visible. In addition,
29415 -- we must inhibit freezing and full analysis because the
29416 -- controlling type of the subprogram is not frozen yet, and
29417 -- may have further primitives.
29418
29419 if not Installed then
29420 Installed := True;
29421 Push_Scope (Subp);
29422 Install_Formals (Subp);
29423 In_Spec_Expr := In_Spec_Expression;
29424 In_Spec_Expression := True;
29425 end if;
29426
29427 New_Prag :=
29428 Build_Pragma_Check_Equivalent
29429 (Prag, Subp, Parent_Subp, Keep_Pragma_Id => True);
29430
29431 Insert_After (Unit_Declaration_Node (Subp), New_Prag);
29432 Preanalyze (New_Prag);
29433
29434 -- Prevent further analysis in subsequent processing of the
29435 -- current list of declarations
29436
29437 Set_Analyzed (New_Prag);
29438 end if;
29439
29440 Prag := Next_Pragma (Prag);
29441 end loop;
29442
29443 if Installed then
29444 In_Spec_Expression := In_Spec_Expr;
29445 End_Scope;
29446 end if;
29447 end if;
29448 end Collect_Inherited_Class_Wide_Conditions;
29449
29450 ---------------------------------------
29451 -- Collect_Subprogram_Inputs_Outputs --
29452 ---------------------------------------
29453
29454 procedure Collect_Subprogram_Inputs_Outputs
29455 (Subp_Id : Entity_Id;
29456 Synthesize : Boolean := False;
29457 Subp_Inputs : in out Elist_Id;
29458 Subp_Outputs : in out Elist_Id;
29459 Global_Seen : out Boolean)
29460 is
29461 procedure Collect_Dependency_Clause (Clause : Node_Id);
29462 -- Collect all relevant items from a dependency clause
29463
29464 procedure Collect_Global_List
29465 (List : Node_Id;
29466 Mode : Name_Id := Name_Input);
29467 -- Collect all relevant items from a global list
29468
29469 -------------------------------
29470 -- Collect_Dependency_Clause --
29471 -------------------------------
29472
29473 procedure Collect_Dependency_Clause (Clause : Node_Id) is
29474 procedure Collect_Dependency_Item
29475 (Item : Node_Id;
29476 Is_Input : Boolean);
29477 -- Add an item to the proper subprogram input or output collection
29478
29479 -----------------------------
29480 -- Collect_Dependency_Item --
29481 -----------------------------
29482
29483 procedure Collect_Dependency_Item
29484 (Item : Node_Id;
29485 Is_Input : Boolean)
29486 is
29487 Extra : Node_Id;
29488
29489 begin
29490 -- Nothing to collect when the item is null
29491
29492 if Nkind (Item) = N_Null then
29493 null;
29494
29495 -- Ditto for attribute 'Result
29496
29497 elsif Is_Attribute_Result (Item) then
29498 null;
29499
29500 -- Multiple items appear as an aggregate
29501
29502 elsif Nkind (Item) = N_Aggregate then
29503 Extra := First (Expressions (Item));
29504 while Present (Extra) loop
29505 Collect_Dependency_Item (Extra, Is_Input);
29506 Next (Extra);
29507 end loop;
29508
29509 -- Otherwise this is a solitary item
29510
29511 else
29512 if Is_Input then
29513 Append_New_Elmt (Item, Subp_Inputs);
29514 else
29515 Append_New_Elmt (Item, Subp_Outputs);
29516 end if;
29517 end if;
29518 end Collect_Dependency_Item;
29519
29520 -- Start of processing for Collect_Dependency_Clause
29521
29522 begin
29523 if Nkind (Clause) = N_Null then
29524 null;
29525
29526 -- A dependency clause appears as component association
29527
29528 elsif Nkind (Clause) = N_Component_Association then
29529 Collect_Dependency_Item
29530 (Item => Expression (Clause),
29531 Is_Input => True);
29532
29533 Collect_Dependency_Item
29534 (Item => First (Choices (Clause)),
29535 Is_Input => False);
29536
29537 -- To accommodate partial decoration of disabled SPARK features, this
29538 -- routine may be called with illegal input. If this is the case, do
29539 -- not raise Program_Error.
29540
29541 else
29542 null;
29543 end if;
29544 end Collect_Dependency_Clause;
29545
29546 -------------------------
29547 -- Collect_Global_List --
29548 -------------------------
29549
29550 procedure Collect_Global_List
29551 (List : Node_Id;
29552 Mode : Name_Id := Name_Input)
29553 is
29554 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
29555 -- Add an item to the proper subprogram input or output collection
29556
29557 -------------------------
29558 -- Collect_Global_Item --
29559 -------------------------
29560
29561 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
29562 begin
29563 if Nam_In (Mode, Name_In_Out, Name_Input) then
29564 Append_New_Elmt (Item, Subp_Inputs);
29565 end if;
29566
29567 if Nam_In (Mode, Name_In_Out, Name_Output) then
29568 Append_New_Elmt (Item, Subp_Outputs);
29569 end if;
29570 end Collect_Global_Item;
29571
29572 -- Local variables
29573
29574 Assoc : Node_Id;
29575 Item : Node_Id;
29576
29577 -- Start of processing for Collect_Global_List
29578
29579 begin
29580 if Nkind (List) = N_Null then
29581 null;
29582
29583 -- Single global item declaration
29584
29585 elsif Nkind_In (List, N_Expanded_Name,
29586 N_Identifier,
29587 N_Selected_Component)
29588 then
29589 Collect_Global_Item (List, Mode);
29590
29591 -- Simple global list or moded global list declaration
29592
29593 elsif Nkind (List) = N_Aggregate then
29594 if Present (Expressions (List)) then
29595 Item := First (Expressions (List));
29596 while Present (Item) loop
29597 Collect_Global_Item (Item, Mode);
29598 Next (Item);
29599 end loop;
29600
29601 else
29602 Assoc := First (Component_Associations (List));
29603 while Present (Assoc) loop
29604 Collect_Global_List
29605 (List => Expression (Assoc),
29606 Mode => Chars (First (Choices (Assoc))));
29607 Next (Assoc);
29608 end loop;
29609 end if;
29610
29611 -- To accommodate partial decoration of disabled SPARK features, this
29612 -- routine may be called with illegal input. If this is the case, do
29613 -- not raise Program_Error.
29614
29615 else
29616 null;
29617 end if;
29618 end Collect_Global_List;
29619
29620 -- Local variables
29621
29622 Clause : Node_Id;
29623 Clauses : Node_Id;
29624 Depends : Node_Id;
29625 Formal : Entity_Id;
29626 Global : Node_Id;
29627 Spec_Id : Entity_Id := Empty;
29628 Subp_Decl : Node_Id;
29629 Typ : Entity_Id;
29630
29631 -- Start of processing for Collect_Subprogram_Inputs_Outputs
29632
29633 begin
29634 Global_Seen := False;
29635
29636 -- Process all formal parameters of entries, [generic] subprograms, and
29637 -- their bodies.
29638
29639 if Ekind_In (Subp_Id, E_Entry,
29640 E_Entry_Family,
29641 E_Function,
29642 E_Generic_Function,
29643 E_Generic_Procedure,
29644 E_Procedure,
29645 E_Subprogram_Body)
29646 then
29647 Subp_Decl := Unit_Declaration_Node (Subp_Id);
29648 Spec_Id := Unique_Defining_Entity (Subp_Decl);
29649
29650 -- Process all formal parameters
29651
29652 Formal := First_Entity (Spec_Id);
29653 while Present (Formal) loop
29654 if Ekind_In (Formal, E_In_Out_Parameter, E_In_Parameter) then
29655 Append_New_Elmt (Formal, Subp_Inputs);
29656 end if;
29657
29658 if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
29659 Append_New_Elmt (Formal, Subp_Outputs);
29660
29661 -- Out parameters can act as inputs when the related type is
29662 -- tagged, unconstrained array, unconstrained record, or record
29663 -- with unconstrained components.
29664
29665 if Ekind (Formal) = E_Out_Parameter
29666 and then Is_Unconstrained_Or_Tagged_Item (Formal)
29667 then
29668 Append_New_Elmt (Formal, Subp_Inputs);
29669 end if;
29670 end if;
29671
29672 Next_Entity (Formal);
29673 end loop;
29674
29675 -- Otherwise the input denotes a task type, a task body, or the
29676 -- anonymous object created for a single task type.
29677
29678 elsif Ekind_In (Subp_Id, E_Task_Type, E_Task_Body)
29679 or else Is_Single_Task_Object (Subp_Id)
29680 then
29681 Subp_Decl := Declaration_Node (Subp_Id);
29682 Spec_Id := Unique_Defining_Entity (Subp_Decl);
29683 end if;
29684
29685 -- When processing an entry, subprogram or task body, look for pragmas
29686 -- Refined_Depends and Refined_Global as they specify the inputs and
29687 -- outputs.
29688
29689 if Is_Entry_Body (Subp_Id)
29690 or else Ekind_In (Subp_Id, E_Subprogram_Body, E_Task_Body)
29691 then
29692 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
29693 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
29694
29695 -- Subprogram declaration or stand-alone body case, look for pragmas
29696 -- Depends and Global
29697
29698 else
29699 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
29700 Global := Get_Pragma (Spec_Id, Pragma_Global);
29701 end if;
29702
29703 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
29704 -- because it provides finer granularity of inputs and outputs.
29705
29706 if Present (Global) then
29707 Global_Seen := True;
29708 Collect_Global_List (Expression (Get_Argument (Global, Spec_Id)));
29709
29710 -- When the related subprogram lacks pragma [Refined_]Global, fall back
29711 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
29712 -- the inputs and outputs from [Refined_]Depends.
29713
29714 elsif Synthesize and then Present (Depends) then
29715 Clauses := Expression (Get_Argument (Depends, Spec_Id));
29716
29717 -- Multiple dependency clauses appear as an aggregate
29718
29719 if Nkind (Clauses) = N_Aggregate then
29720 Clause := First (Component_Associations (Clauses));
29721 while Present (Clause) loop
29722 Collect_Dependency_Clause (Clause);
29723 Next (Clause);
29724 end loop;
29725
29726 -- Otherwise this is a single dependency clause
29727
29728 else
29729 Collect_Dependency_Clause (Clauses);
29730 end if;
29731 end if;
29732
29733 -- The current instance of a protected type acts as a formal parameter
29734 -- of mode IN for functions and IN OUT for entries and procedures
29735 -- (SPARK RM 6.1.4).
29736
29737 if Ekind (Scope (Spec_Id)) = E_Protected_Type then
29738 Typ := Scope (Spec_Id);
29739
29740 -- Use the anonymous object when the type is single protected
29741
29742 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
29743 Typ := Anonymous_Object (Typ);
29744 end if;
29745
29746 Append_New_Elmt (Typ, Subp_Inputs);
29747
29748 if Ekind_In (Spec_Id, E_Entry, E_Entry_Family, E_Procedure) then
29749 Append_New_Elmt (Typ, Subp_Outputs);
29750 end if;
29751
29752 -- The current instance of a task type acts as a formal parameter of
29753 -- mode IN OUT (SPARK RM 6.1.4).
29754
29755 elsif Ekind (Spec_Id) = E_Task_Type then
29756 Typ := Spec_Id;
29757
29758 -- Use the anonymous object when the type is single task
29759
29760 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
29761 Typ := Anonymous_Object (Typ);
29762 end if;
29763
29764 Append_New_Elmt (Typ, Subp_Inputs);
29765 Append_New_Elmt (Typ, Subp_Outputs);
29766
29767 elsif Is_Single_Task_Object (Spec_Id) then
29768 Append_New_Elmt (Spec_Id, Subp_Inputs);
29769 Append_New_Elmt (Spec_Id, Subp_Outputs);
29770 end if;
29771 end Collect_Subprogram_Inputs_Outputs;
29772
29773 ---------------------------
29774 -- Contract_Freeze_Error --
29775 ---------------------------
29776
29777 procedure Contract_Freeze_Error
29778 (Contract_Id : Entity_Id;
29779 Freeze_Id : Entity_Id)
29780 is
29781 begin
29782 Error_Msg_Name_1 := Chars (Contract_Id);
29783 Error_Msg_Sloc := Sloc (Freeze_Id);
29784
29785 SPARK_Msg_NE
29786 ("body & declared # freezes the contract of%", Contract_Id, Freeze_Id);
29787 SPARK_Msg_N
29788 ("\all contractual items must be declared before body #", Contract_Id);
29789 end Contract_Freeze_Error;
29790
29791 ---------------------------------
29792 -- Delay_Config_Pragma_Analyze --
29793 ---------------------------------
29794
29795 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
29796 begin
29797 return Nam_In (Pragma_Name_Unmapped (N),
29798 Name_Interrupt_State, Name_Priority_Specific_Dispatching);
29799 end Delay_Config_Pragma_Analyze;
29800
29801 -----------------------
29802 -- Duplication_Error --
29803 -----------------------
29804
29805 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
29806 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
29807 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
29808
29809 begin
29810 Error_Msg_Sloc := Sloc (Prev);
29811 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
29812
29813 -- Emit a precise message to distinguish between source pragmas and
29814 -- pragmas generated from aspects. The ordering of the two pragmas is
29815 -- the following:
29816
29817 -- Prev -- ok
29818 -- Prag -- duplicate
29819
29820 -- No error is emitted when both pragmas come from aspects because this
29821 -- is already detected by the general aspect analysis mechanism.
29822
29823 if Prag_From_Asp and Prev_From_Asp then
29824 null;
29825 elsif Prag_From_Asp then
29826 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
29827 elsif Prev_From_Asp then
29828 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
29829 else
29830 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
29831 end if;
29832 end Duplication_Error;
29833
29834 ------------------------------
29835 -- Find_Encapsulating_State --
29836 ------------------------------
29837
29838 function Find_Encapsulating_State
29839 (States : Elist_Id;
29840 Constit_Id : Entity_Id) return Entity_Id
29841 is
29842 State_Id : Entity_Id;
29843
29844 begin
29845 -- Since a constituent may be part of a larger constituent set, climb
29846 -- the encapsulating state chain looking for a state that appears in
29847 -- States.
29848
29849 State_Id := Encapsulating_State (Constit_Id);
29850 while Present (State_Id) loop
29851 if Contains (States, State_Id) then
29852 return State_Id;
29853 end if;
29854
29855 State_Id := Encapsulating_State (State_Id);
29856 end loop;
29857
29858 return Empty;
29859 end Find_Encapsulating_State;
29860
29861 --------------------------
29862 -- Find_Related_Context --
29863 --------------------------
29864
29865 function Find_Related_Context
29866 (Prag : Node_Id;
29867 Do_Checks : Boolean := False) return Node_Id
29868 is
29869 Stmt : Node_Id;
29870
29871 begin
29872 Stmt := Prev (Prag);
29873 while Present (Stmt) loop
29874
29875 -- Skip prior pragmas, but check for duplicates
29876
29877 if Nkind (Stmt) = N_Pragma then
29878 if Do_Checks
29879 and then Pragma_Name (Stmt) = Pragma_Name (Prag)
29880 then
29881 Duplication_Error
29882 (Prag => Prag,
29883 Prev => Stmt);
29884 end if;
29885
29886 -- Skip internally generated code
29887
29888 elsif not Comes_From_Source (Stmt) then
29889
29890 -- The anonymous object created for a single concurrent type is a
29891 -- suitable context.
29892
29893 if Nkind (Stmt) = N_Object_Declaration
29894 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
29895 then
29896 return Stmt;
29897 end if;
29898
29899 -- Return the current source construct
29900
29901 else
29902 return Stmt;
29903 end if;
29904
29905 Prev (Stmt);
29906 end loop;
29907
29908 return Empty;
29909 end Find_Related_Context;
29910
29911 --------------------------------------
29912 -- Find_Related_Declaration_Or_Body --
29913 --------------------------------------
29914
29915 function Find_Related_Declaration_Or_Body
29916 (Prag : Node_Id;
29917 Do_Checks : Boolean := False) return Node_Id
29918 is
29919 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
29920
29921 procedure Expression_Function_Error;
29922 -- Emit an error concerning pragma Prag that illegaly applies to an
29923 -- expression function.
29924
29925 -------------------------------
29926 -- Expression_Function_Error --
29927 -------------------------------
29928
29929 procedure Expression_Function_Error is
29930 begin
29931 Error_Msg_Name_1 := Prag_Nam;
29932
29933 -- Emit a precise message to distinguish between source pragmas and
29934 -- pragmas generated from aspects.
29935
29936 if From_Aspect_Specification (Prag) then
29937 Error_Msg_N
29938 ("aspect % cannot apply to a stand alone expression function",
29939 Prag);
29940 else
29941 Error_Msg_N
29942 ("pragma % cannot apply to a stand alone expression function",
29943 Prag);
29944 end if;
29945 end Expression_Function_Error;
29946
29947 -- Local variables
29948
29949 Context : constant Node_Id := Parent (Prag);
29950 Stmt : Node_Id;
29951
29952 Look_For_Body : constant Boolean :=
29953 Nam_In (Prag_Nam, Name_Refined_Depends,
29954 Name_Refined_Global,
29955 Name_Refined_Post,
29956 Name_Refined_State);
29957 -- Refinement pragmas must be associated with a subprogram body [stub]
29958
29959 -- Start of processing for Find_Related_Declaration_Or_Body
29960
29961 begin
29962 Stmt := Prev (Prag);
29963 while Present (Stmt) loop
29964
29965 -- Skip prior pragmas, but check for duplicates. Pragmas produced
29966 -- by splitting a complex pre/postcondition are not considered to
29967 -- be duplicates.
29968
29969 if Nkind (Stmt) = N_Pragma then
29970 if Do_Checks
29971 and then not Split_PPC (Stmt)
29972 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
29973 then
29974 Duplication_Error
29975 (Prag => Prag,
29976 Prev => Stmt);
29977 end if;
29978
29979 -- Emit an error when a refinement pragma appears on an expression
29980 -- function without a completion.
29981
29982 elsif Do_Checks
29983 and then Look_For_Body
29984 and then Nkind (Stmt) = N_Subprogram_Declaration
29985 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
29986 and then not Has_Completion (Defining_Entity (Stmt))
29987 then
29988 Expression_Function_Error;
29989 return Empty;
29990
29991 -- The refinement pragma applies to a subprogram body stub
29992
29993 elsif Look_For_Body
29994 and then Nkind (Stmt) = N_Subprogram_Body_Stub
29995 then
29996 return Stmt;
29997
29998 -- Skip internally generated code
29999
30000 elsif not Comes_From_Source (Stmt) then
30001
30002 -- The anonymous object created for a single concurrent type is a
30003 -- suitable context.
30004
30005 if Nkind (Stmt) = N_Object_Declaration
30006 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
30007 then
30008 return Stmt;
30009
30010 elsif Nkind (Stmt) = N_Subprogram_Declaration then
30011
30012 -- The subprogram declaration is an internally generated spec
30013 -- for an expression function.
30014
30015 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
30016 return Stmt;
30017
30018 -- The subprogram declaration is an internally generated spec
30019 -- for a stand-alone subrogram body declared inside a protected
30020 -- body.
30021
30022 elsif Present (Corresponding_Body (Stmt))
30023 and then Comes_From_Source (Corresponding_Body (Stmt))
30024 and then Is_Protected_Type (Current_Scope)
30025 then
30026 return Stmt;
30027
30028 -- The subprogram is actually an instance housed within an
30029 -- anonymous wrapper package.
30030
30031 elsif Present (Generic_Parent (Specification (Stmt))) then
30032 return Stmt;
30033
30034 -- Ada 2020: contract on formal subprogram
30035
30036 elsif Is_Generic_Actual_Subprogram (Defining_Entity (Stmt))
30037 and then Ada_Version >= Ada_2020
30038 then
30039 return Stmt;
30040 end if;
30041 end if;
30042
30043 -- Return the current construct which is either a subprogram body,
30044 -- a subprogram declaration or is illegal.
30045
30046 else
30047 return Stmt;
30048 end if;
30049
30050 Prev (Stmt);
30051 end loop;
30052
30053 -- If we fall through, then the pragma was either the first declaration
30054 -- or it was preceded by other pragmas and no source constructs.
30055
30056 -- The pragma is associated with a library-level subprogram
30057
30058 if Nkind (Context) = N_Compilation_Unit_Aux then
30059 return Unit (Parent (Context));
30060
30061 -- The pragma appears inside the declarations of an entry body
30062
30063 elsif Nkind (Context) = N_Entry_Body then
30064 return Context;
30065
30066 -- The pragma appears inside the statements of a subprogram body. This
30067 -- placement is the result of subprogram contract expansion.
30068
30069 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
30070 return Parent (Context);
30071
30072 -- The pragma appears inside the declarative part of a package body
30073
30074 elsif Nkind (Context) = N_Package_Body then
30075 return Context;
30076
30077 -- The pragma appears inside the declarative part of a subprogram body
30078
30079 elsif Nkind (Context) = N_Subprogram_Body then
30080 return Context;
30081
30082 -- The pragma appears inside the declarative part of a task body
30083
30084 elsif Nkind (Context) = N_Task_Body then
30085 return Context;
30086
30087 -- The pragma appears inside the visible part of a package specification
30088
30089 elsif Nkind (Context) = N_Package_Specification then
30090 return Parent (Context);
30091
30092 -- The pragma is a byproduct of aspect expansion, return the related
30093 -- context of the original aspect. This case has a lower priority as
30094 -- the above circuitry pinpoints precisely the related context.
30095
30096 elsif Present (Corresponding_Aspect (Prag)) then
30097 return Parent (Corresponding_Aspect (Prag));
30098
30099 -- No candidate subprogram [body] found
30100
30101 else
30102 return Empty;
30103 end if;
30104 end Find_Related_Declaration_Or_Body;
30105
30106 ----------------------------------
30107 -- Find_Related_Package_Or_Body --
30108 ----------------------------------
30109
30110 function Find_Related_Package_Or_Body
30111 (Prag : Node_Id;
30112 Do_Checks : Boolean := False) return Node_Id
30113 is
30114 Context : constant Node_Id := Parent (Prag);
30115 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
30116 Stmt : Node_Id;
30117
30118 begin
30119 Stmt := Prev (Prag);
30120 while Present (Stmt) loop
30121
30122 -- Skip prior pragmas, but check for duplicates
30123
30124 if Nkind (Stmt) = N_Pragma then
30125 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
30126 Duplication_Error
30127 (Prag => Prag,
30128 Prev => Stmt);
30129 end if;
30130
30131 -- Skip internally generated code
30132
30133 elsif not Comes_From_Source (Stmt) then
30134 if Nkind (Stmt) = N_Subprogram_Declaration then
30135
30136 -- The subprogram declaration is an internally generated spec
30137 -- for an expression function.
30138
30139 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
30140 return Stmt;
30141
30142 -- The subprogram is actually an instance housed within an
30143 -- anonymous wrapper package.
30144
30145 elsif Present (Generic_Parent (Specification (Stmt))) then
30146 return Stmt;
30147 end if;
30148 end if;
30149
30150 -- Return the current source construct which is illegal
30151
30152 else
30153 return Stmt;
30154 end if;
30155
30156 Prev (Stmt);
30157 end loop;
30158
30159 -- If we fall through, then the pragma was either the first declaration
30160 -- or it was preceded by other pragmas and no source constructs.
30161
30162 -- The pragma is associated with a package. The immediate context in
30163 -- this case is the specification of the package.
30164
30165 if Nkind (Context) = N_Package_Specification then
30166 return Parent (Context);
30167
30168 -- The pragma appears in the declarations of a package body
30169
30170 elsif Nkind (Context) = N_Package_Body then
30171 return Context;
30172
30173 -- The pragma appears in the statements of a package body
30174
30175 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
30176 and then Nkind (Parent (Context)) = N_Package_Body
30177 then
30178 return Parent (Context);
30179
30180 -- The pragma is a byproduct of aspect expansion, return the related
30181 -- context of the original aspect. This case has a lower priority as
30182 -- the above circuitry pinpoints precisely the related context.
30183
30184 elsif Present (Corresponding_Aspect (Prag)) then
30185 return Parent (Corresponding_Aspect (Prag));
30186
30187 -- No candidate package [body] found
30188
30189 else
30190 return Empty;
30191 end if;
30192 end Find_Related_Package_Or_Body;
30193
30194 ------------------
30195 -- Get_Argument --
30196 ------------------
30197
30198 function Get_Argument
30199 (Prag : Node_Id;
30200 Context_Id : Entity_Id := Empty) return Node_Id
30201 is
30202 Args : constant List_Id := Pragma_Argument_Associations (Prag);
30203
30204 begin
30205 -- Use the expression of the original aspect when analyzing the template
30206 -- of a generic unit. In both cases the aspect's tree must be decorated
30207 -- to allow for ASIS queries or to save the global references in the
30208 -- generic context.
30209
30210 if From_Aspect_Specification (Prag)
30211 and then (Present (Context_Id) and then Is_Generic_Unit (Context_Id))
30212 then
30213 return Corresponding_Aspect (Prag);
30214
30215 -- Otherwise use the expression of the pragma
30216
30217 elsif Present (Args) then
30218 return First (Args);
30219
30220 else
30221 return Empty;
30222 end if;
30223 end Get_Argument;
30224
30225 -------------------------
30226 -- Get_Base_Subprogram --
30227 -------------------------
30228
30229 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
30230 begin
30231 -- Follow subprogram renaming chain
30232
30233 if Is_Subprogram (Def_Id)
30234 and then Nkind (Parent (Declaration_Node (Def_Id))) =
30235 N_Subprogram_Renaming_Declaration
30236 and then Present (Alias (Def_Id))
30237 then
30238 return Alias (Def_Id);
30239 else
30240 return Def_Id;
30241 end if;
30242 end Get_Base_Subprogram;
30243
30244 -----------------------
30245 -- Get_SPARK_Mode_Type --
30246 -----------------------
30247
30248 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
30249 begin
30250 if N = Name_On then
30251 return On;
30252 elsif N = Name_Off then
30253 return Off;
30254
30255 -- Any other argument is illegal. Assume that no SPARK mode applies to
30256 -- avoid potential cascaded errors.
30257
30258 else
30259 return None;
30260 end if;
30261 end Get_SPARK_Mode_Type;
30262
30263 ------------------------------------
30264 -- Get_SPARK_Mode_From_Annotation --
30265 ------------------------------------
30266
30267 function Get_SPARK_Mode_From_Annotation
30268 (N : Node_Id) return SPARK_Mode_Type
30269 is
30270 Mode : Node_Id;
30271
30272 begin
30273 if Nkind (N) = N_Aspect_Specification then
30274 Mode := Expression (N);
30275
30276 else pragma Assert (Nkind (N) = N_Pragma);
30277 Mode := First (Pragma_Argument_Associations (N));
30278
30279 if Present (Mode) then
30280 Mode := Get_Pragma_Arg (Mode);
30281 end if;
30282 end if;
30283
30284 -- Aspect or pragma SPARK_Mode specifies an explicit mode
30285
30286 if Present (Mode) then
30287 if Nkind (Mode) = N_Identifier then
30288 return Get_SPARK_Mode_Type (Chars (Mode));
30289
30290 -- In case of a malformed aspect or pragma, return the default None
30291
30292 else
30293 return None;
30294 end if;
30295
30296 -- Otherwise the lack of an expression defaults SPARK_Mode to On
30297
30298 else
30299 return On;
30300 end if;
30301 end Get_SPARK_Mode_From_Annotation;
30302
30303 ---------------------------
30304 -- Has_Extra_Parentheses --
30305 ---------------------------
30306
30307 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
30308 Expr : Node_Id;
30309
30310 begin
30311 -- The aggregate should not have an expression list because a clause
30312 -- is always interpreted as a component association. The only way an
30313 -- expression list can sneak in is by adding extra parentheses around
30314 -- the individual clauses:
30315
30316 -- Depends (Output => Input) -- proper form
30317 -- Depends ((Output => Input)) -- extra parentheses
30318
30319 -- Since the extra parentheses are not allowed by the syntax of the
30320 -- pragma, flag them now to avoid emitting misleading errors down the
30321 -- line.
30322
30323 if Nkind (Clause) = N_Aggregate
30324 and then Present (Expressions (Clause))
30325 then
30326 Expr := First (Expressions (Clause));
30327 while Present (Expr) loop
30328
30329 -- A dependency clause surrounded by extra parentheses appears
30330 -- as an aggregate of component associations with an optional
30331 -- Paren_Count set.
30332
30333 if Nkind (Expr) = N_Aggregate
30334 and then Present (Component_Associations (Expr))
30335 then
30336 SPARK_Msg_N
30337 ("dependency clause contains extra parentheses", Expr);
30338
30339 -- Otherwise the expression is a malformed construct
30340
30341 else
30342 SPARK_Msg_N ("malformed dependency clause", Expr);
30343 end if;
30344
30345 Next (Expr);
30346 end loop;
30347
30348 return True;
30349 end if;
30350
30351 return False;
30352 end Has_Extra_Parentheses;
30353
30354 ----------------
30355 -- Initialize --
30356 ----------------
30357
30358 procedure Initialize is
30359 begin
30360 Externals.Init;
30361 Compile_Time_Warnings_Errors.Init;
30362 end Initialize;
30363
30364 --------
30365 -- ip --
30366 --------
30367
30368 procedure ip is
30369 begin
30370 Dummy := Dummy + 1;
30371 end ip;
30372
30373 -----------------------------
30374 -- Is_Config_Static_String --
30375 -----------------------------
30376
30377 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
30378
30379 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
30380 -- This is an internal recursive function that is just like the outer
30381 -- function except that it adds the string to the name buffer rather
30382 -- than placing the string in the name buffer.
30383
30384 ------------------------------
30385 -- Add_Config_Static_String --
30386 ------------------------------
30387
30388 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
30389 N : Node_Id;
30390 C : Char_Code;
30391
30392 begin
30393 N := Arg;
30394
30395 if Nkind (N) = N_Op_Concat then
30396 if Add_Config_Static_String (Left_Opnd (N)) then
30397 N := Right_Opnd (N);
30398 else
30399 return False;
30400 end if;
30401 end if;
30402
30403 if Nkind (N) /= N_String_Literal then
30404 Error_Msg_N ("string literal expected for pragma argument", N);
30405 return False;
30406
30407 else
30408 for J in 1 .. String_Length (Strval (N)) loop
30409 C := Get_String_Char (Strval (N), J);
30410
30411 if not In_Character_Range (C) then
30412 Error_Msg
30413 ("string literal contains invalid wide character",
30414 Sloc (N) + 1 + Source_Ptr (J));
30415 return False;
30416 end if;
30417
30418 Add_Char_To_Name_Buffer (Get_Character (C));
30419 end loop;
30420 end if;
30421
30422 return True;
30423 end Add_Config_Static_String;
30424
30425 -- Start of processing for Is_Config_Static_String
30426
30427 begin
30428 Name_Len := 0;
30429
30430 return Add_Config_Static_String (Arg);
30431 end Is_Config_Static_String;
30432
30433 -------------------------------
30434 -- Is_Elaboration_SPARK_Mode --
30435 -------------------------------
30436
30437 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
30438 begin
30439 pragma Assert
30440 (Nkind (N) = N_Pragma
30441 and then Pragma_Name (N) = Name_SPARK_Mode
30442 and then Is_List_Member (N));
30443
30444 -- Pragma SPARK_Mode affects the elaboration of a package body when it
30445 -- appears in the statement part of the body.
30446
30447 return
30448 Present (Parent (N))
30449 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
30450 and then List_Containing (N) = Statements (Parent (N))
30451 and then Present (Parent (Parent (N)))
30452 and then Nkind (Parent (Parent (N))) = N_Package_Body;
30453 end Is_Elaboration_SPARK_Mode;
30454
30455 -----------------------
30456 -- Is_Enabled_Pragma --
30457 -----------------------
30458
30459 function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is
30460 Arg : Node_Id;
30461
30462 begin
30463 if Present (Prag) then
30464 Arg := First (Pragma_Argument_Associations (Prag));
30465
30466 if Present (Arg) then
30467 return Is_True (Expr_Value (Get_Pragma_Arg (Arg)));
30468
30469 -- The lack of a Boolean argument automatically enables the pragma
30470
30471 else
30472 return True;
30473 end if;
30474
30475 -- The pragma is missing, therefore it is not enabled
30476
30477 else
30478 return False;
30479 end if;
30480 end Is_Enabled_Pragma;
30481
30482 -----------------------------------------
30483 -- Is_Non_Significant_Pragma_Reference --
30484 -----------------------------------------
30485
30486 -- This function makes use of the following static table which indicates
30487 -- whether appearance of some name in a given pragma is to be considered
30488 -- as a reference for the purposes of warnings about unreferenced objects.
30489
30490 -- -1 indicates that appearence in any argument is significant
30491 -- 0 indicates that appearance in any argument is not significant
30492 -- +n indicates that appearance as argument n is significant, but all
30493 -- other arguments are not significant
30494 -- 9n arguments from n on are significant, before n insignificant
30495
30496 Sig_Flags : constant array (Pragma_Id) of Int :=
30497 (Pragma_Abort_Defer => -1,
30498 Pragma_Abstract_State => -1,
30499 Pragma_Ada_83 => -1,
30500 Pragma_Ada_95 => -1,
30501 Pragma_Ada_05 => -1,
30502 Pragma_Ada_2005 => -1,
30503 Pragma_Ada_12 => -1,
30504 Pragma_Ada_2012 => -1,
30505 Pragma_Ada_2020 => -1,
30506 Pragma_Aggregate_Individually_Assign => 0,
30507 Pragma_All_Calls_Remote => -1,
30508 Pragma_Allow_Integer_Address => -1,
30509 Pragma_Annotate => 93,
30510 Pragma_Assert => -1,
30511 Pragma_Assert_And_Cut => -1,
30512 Pragma_Assertion_Policy => 0,
30513 Pragma_Assume => -1,
30514 Pragma_Assume_No_Invalid_Values => 0,
30515 Pragma_Async_Readers => 0,
30516 Pragma_Async_Writers => 0,
30517 Pragma_Asynchronous => 0,
30518 Pragma_Atomic => 0,
30519 Pragma_Atomic_Components => 0,
30520 Pragma_Attach_Handler => -1,
30521 Pragma_Attribute_Definition => 92,
30522 Pragma_Check => -1,
30523 Pragma_Check_Float_Overflow => 0,
30524 Pragma_Check_Name => 0,
30525 Pragma_Check_Policy => 0,
30526 Pragma_CPP_Class => 0,
30527 Pragma_CPP_Constructor => 0,
30528 Pragma_CPP_Virtual => 0,
30529 Pragma_CPP_Vtable => 0,
30530 Pragma_CPU => -1,
30531 Pragma_C_Pass_By_Copy => 0,
30532 Pragma_Comment => -1,
30533 Pragma_Common_Object => 0,
30534 Pragma_Compile_Time_Error => -1,
30535 Pragma_Compile_Time_Warning => -1,
30536 Pragma_Compiler_Unit => -1,
30537 Pragma_Compiler_Unit_Warning => -1,
30538 Pragma_Complete_Representation => 0,
30539 Pragma_Complex_Representation => 0,
30540 Pragma_Component_Alignment => 0,
30541 Pragma_Constant_After_Elaboration => 0,
30542 Pragma_Contract_Cases => -1,
30543 Pragma_Controlled => 0,
30544 Pragma_Convention => 0,
30545 Pragma_Convention_Identifier => 0,
30546 Pragma_Deadline_Floor => -1,
30547 Pragma_Debug => -1,
30548 Pragma_Debug_Policy => 0,
30549 Pragma_Detect_Blocking => 0,
30550 Pragma_Default_Initial_Condition => -1,
30551 Pragma_Default_Scalar_Storage_Order => 0,
30552 Pragma_Default_Storage_Pool => 0,
30553 Pragma_Depends => -1,
30554 Pragma_Disable_Atomic_Synchronization => 0,
30555 Pragma_Discard_Names => 0,
30556 Pragma_Dispatching_Domain => -1,
30557 Pragma_Effective_Reads => 0,
30558 Pragma_Effective_Writes => 0,
30559 Pragma_Elaborate => 0,
30560 Pragma_Elaborate_All => 0,
30561 Pragma_Elaborate_Body => 0,
30562 Pragma_Elaboration_Checks => 0,
30563 Pragma_Eliminate => 0,
30564 Pragma_Enable_Atomic_Synchronization => 0,
30565 Pragma_Export => -1,
30566 Pragma_Export_Function => -1,
30567 Pragma_Export_Object => -1,
30568 Pragma_Export_Procedure => -1,
30569 Pragma_Export_Value => -1,
30570 Pragma_Export_Valued_Procedure => -1,
30571 Pragma_Extend_System => -1,
30572 Pragma_Extensions_Allowed => 0,
30573 Pragma_Extensions_Visible => 0,
30574 Pragma_External => -1,
30575 Pragma_Favor_Top_Level => 0,
30576 Pragma_External_Name_Casing => 0,
30577 Pragma_Fast_Math => 0,
30578 Pragma_Finalize_Storage_Only => 0,
30579 Pragma_Ghost => 0,
30580 Pragma_Global => -1,
30581 Pragma_Ident => -1,
30582 Pragma_Ignore_Pragma => 0,
30583 Pragma_Implementation_Defined => -1,
30584 Pragma_Implemented => -1,
30585 Pragma_Implicit_Packing => 0,
30586 Pragma_Import => 93,
30587 Pragma_Import_Function => 0,
30588 Pragma_Import_Object => 0,
30589 Pragma_Import_Procedure => 0,
30590 Pragma_Import_Valued_Procedure => 0,
30591 Pragma_Independent => 0,
30592 Pragma_Independent_Components => 0,
30593 Pragma_Initial_Condition => -1,
30594 Pragma_Initialize_Scalars => 0,
30595 Pragma_Initializes => -1,
30596 Pragma_Inline => 0,
30597 Pragma_Inline_Always => 0,
30598 Pragma_Inline_Generic => 0,
30599 Pragma_Inspection_Point => -1,
30600 Pragma_Interface => 92,
30601 Pragma_Interface_Name => 0,
30602 Pragma_Interrupt_Handler => -1,
30603 Pragma_Interrupt_Priority => -1,
30604 Pragma_Interrupt_State => -1,
30605 Pragma_Invariant => -1,
30606 Pragma_Keep_Names => 0,
30607 Pragma_License => 0,
30608 Pragma_Link_With => -1,
30609 Pragma_Linker_Alias => -1,
30610 Pragma_Linker_Constructor => -1,
30611 Pragma_Linker_Destructor => -1,
30612 Pragma_Linker_Options => -1,
30613 Pragma_Linker_Section => -1,
30614 Pragma_List => 0,
30615 Pragma_Lock_Free => 0,
30616 Pragma_Locking_Policy => 0,
30617 Pragma_Loop_Invariant => -1,
30618 Pragma_Loop_Optimize => 0,
30619 Pragma_Loop_Variant => -1,
30620 Pragma_Machine_Attribute => -1,
30621 Pragma_Main => -1,
30622 Pragma_Main_Storage => -1,
30623 Pragma_Max_Entry_Queue_Depth => 0,
30624 Pragma_Max_Entry_Queue_Length => 0,
30625 Pragma_Max_Queue_Length => 0,
30626 Pragma_Memory_Size => 0,
30627 Pragma_No_Body => 0,
30628 Pragma_No_Caching => 0,
30629 Pragma_No_Component_Reordering => -1,
30630 Pragma_No_Elaboration_Code_All => 0,
30631 Pragma_No_Heap_Finalization => 0,
30632 Pragma_No_Inline => 0,
30633 Pragma_No_Return => 0,
30634 Pragma_No_Run_Time => -1,
30635 Pragma_No_Strict_Aliasing => -1,
30636 Pragma_No_Tagged_Streams => 0,
30637 Pragma_Normalize_Scalars => 0,
30638 Pragma_Obsolescent => 0,
30639 Pragma_Optimize => 0,
30640 Pragma_Optimize_Alignment => 0,
30641 Pragma_Overflow_Mode => 0,
30642 Pragma_Overriding_Renamings => 0,
30643 Pragma_Ordered => 0,
30644 Pragma_Pack => 0,
30645 Pragma_Page => 0,
30646 Pragma_Part_Of => 0,
30647 Pragma_Partition_Elaboration_Policy => 0,
30648 Pragma_Passive => 0,
30649 Pragma_Persistent_BSS => 0,
30650 Pragma_Polling => 0,
30651 Pragma_Prefix_Exception_Messages => 0,
30652 Pragma_Post => -1,
30653 Pragma_Postcondition => -1,
30654 Pragma_Post_Class => -1,
30655 Pragma_Pre => -1,
30656 Pragma_Precondition => -1,
30657 Pragma_Predicate => -1,
30658 Pragma_Predicate_Failure => -1,
30659 Pragma_Preelaborable_Initialization => -1,
30660 Pragma_Preelaborate => 0,
30661 Pragma_Pre_Class => -1,
30662 Pragma_Priority => -1,
30663 Pragma_Priority_Specific_Dispatching => 0,
30664 Pragma_Profile => 0,
30665 Pragma_Profile_Warnings => 0,
30666 Pragma_Propagate_Exceptions => 0,
30667 Pragma_Provide_Shift_Operators => 0,
30668 Pragma_Psect_Object => 0,
30669 Pragma_Pure => 0,
30670 Pragma_Pure_Function => 0,
30671 Pragma_Queuing_Policy => 0,
30672 Pragma_Rational => 0,
30673 Pragma_Ravenscar => 0,
30674 Pragma_Refined_Depends => -1,
30675 Pragma_Refined_Global => -1,
30676 Pragma_Refined_Post => -1,
30677 Pragma_Refined_State => -1,
30678 Pragma_Relative_Deadline => 0,
30679 Pragma_Rename_Pragma => 0,
30680 Pragma_Remote_Access_Type => -1,
30681 Pragma_Remote_Call_Interface => -1,
30682 Pragma_Remote_Types => -1,
30683 Pragma_Restricted_Run_Time => 0,
30684 Pragma_Restriction_Warnings => 0,
30685 Pragma_Restrictions => 0,
30686 Pragma_Reviewable => -1,
30687 Pragma_Secondary_Stack_Size => -1,
30688 Pragma_Short_Circuit_And_Or => 0,
30689 Pragma_Share_Generic => 0,
30690 Pragma_Shared => 0,
30691 Pragma_Shared_Passive => 0,
30692 Pragma_Short_Descriptors => 0,
30693 Pragma_Simple_Storage_Pool_Type => 0,
30694 Pragma_Source_File_Name => 0,
30695 Pragma_Source_File_Name_Project => 0,
30696 Pragma_Source_Reference => 0,
30697 Pragma_SPARK_Mode => 0,
30698 Pragma_Storage_Size => -1,
30699 Pragma_Storage_Unit => 0,
30700 Pragma_Static_Elaboration_Desired => 0,
30701 Pragma_Stream_Convert => 0,
30702 Pragma_Style_Checks => 0,
30703 Pragma_Subtitle => 0,
30704 Pragma_Suppress => 0,
30705 Pragma_Suppress_Exception_Locations => 0,
30706 Pragma_Suppress_All => 0,
30707 Pragma_Suppress_Debug_Info => 0,
30708 Pragma_Suppress_Initialization => 0,
30709 Pragma_System_Name => 0,
30710 Pragma_Task_Dispatching_Policy => 0,
30711 Pragma_Task_Info => -1,
30712 Pragma_Task_Name => -1,
30713 Pragma_Task_Storage => -1,
30714 Pragma_Test_Case => -1,
30715 Pragma_Thread_Local_Storage => -1,
30716 Pragma_Time_Slice => -1,
30717 Pragma_Title => 0,
30718 Pragma_Type_Invariant => -1,
30719 Pragma_Type_Invariant_Class => -1,
30720 Pragma_Unchecked_Union => 0,
30721 Pragma_Unevaluated_Use_Of_Old => 0,
30722 Pragma_Unimplemented_Unit => 0,
30723 Pragma_Universal_Aliasing => 0,
30724 Pragma_Universal_Data => 0,
30725 Pragma_Unmodified => 0,
30726 Pragma_Unreferenced => 0,
30727 Pragma_Unreferenced_Objects => 0,
30728 Pragma_Unreserve_All_Interrupts => 0,
30729 Pragma_Unsuppress => 0,
30730 Pragma_Unused => 0,
30731 Pragma_Use_VADS_Size => 0,
30732 Pragma_Validity_Checks => 0,
30733 Pragma_Volatile => 0,
30734 Pragma_Volatile_Components => 0,
30735 Pragma_Volatile_Full_Access => 0,
30736 Pragma_Volatile_Function => 0,
30737 Pragma_Warning_As_Error => 0,
30738 Pragma_Warnings => 0,
30739 Pragma_Weak_External => 0,
30740 Pragma_Wide_Character_Encoding => 0,
30741 Unknown_Pragma => 0);
30742
30743 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
30744 Id : Pragma_Id;
30745 P : Node_Id;
30746 C : Int;
30747 AN : Nat;
30748
30749 function Arg_No return Nat;
30750 -- Returns an integer showing what argument we are in. A value of
30751 -- zero means we are not in any of the arguments.
30752
30753 ------------
30754 -- Arg_No --
30755 ------------
30756
30757 function Arg_No return Nat is
30758 A : Node_Id;
30759 N : Nat;
30760
30761 begin
30762 A := First (Pragma_Argument_Associations (Parent (P)));
30763 N := 1;
30764 loop
30765 if No (A) then
30766 return 0;
30767 elsif A = P then
30768 return N;
30769 end if;
30770
30771 Next (A);
30772 N := N + 1;
30773 end loop;
30774 end Arg_No;
30775
30776 -- Start of processing for Non_Significant_Pragma_Reference
30777
30778 begin
30779 P := Parent (N);
30780
30781 if Nkind (P) /= N_Pragma_Argument_Association then
30782 return False;
30783
30784 else
30785 Id := Get_Pragma_Id (Parent (P));
30786 C := Sig_Flags (Id);
30787 AN := Arg_No;
30788
30789 if AN = 0 then
30790 return False;
30791 end if;
30792
30793 case C is
30794 when -1 =>
30795 return False;
30796
30797 when 0 =>
30798 return True;
30799
30800 when 92 .. 99 =>
30801 return AN < (C - 90);
30802
30803 when others =>
30804 return AN /= C;
30805 end case;
30806 end if;
30807 end Is_Non_Significant_Pragma_Reference;
30808
30809 ------------------------------
30810 -- Is_Pragma_String_Literal --
30811 ------------------------------
30812
30813 -- This function returns true if the corresponding pragma argument is a
30814 -- static string expression. These are the only cases in which string
30815 -- literals can appear as pragma arguments. We also allow a string literal
30816 -- as the first argument to pragma Assert (although it will of course
30817 -- always generate a type error).
30818
30819 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
30820 Pragn : constant Node_Id := Parent (Par);
30821 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
30822 Pname : constant Name_Id := Pragma_Name (Pragn);
30823 Argn : Natural;
30824 N : Node_Id;
30825
30826 begin
30827 Argn := 1;
30828 N := First (Assoc);
30829 loop
30830 exit when N = Par;
30831 Argn := Argn + 1;
30832 Next (N);
30833 end loop;
30834
30835 if Pname = Name_Assert then
30836 return True;
30837
30838 elsif Pname = Name_Export then
30839 return Argn > 2;
30840
30841 elsif Pname = Name_Ident then
30842 return Argn = 1;
30843
30844 elsif Pname = Name_Import then
30845 return Argn > 2;
30846
30847 elsif Pname = Name_Interface_Name then
30848 return Argn > 1;
30849
30850 elsif Pname = Name_Linker_Alias then
30851 return Argn = 2;
30852
30853 elsif Pname = Name_Linker_Section then
30854 return Argn = 2;
30855
30856 elsif Pname = Name_Machine_Attribute then
30857 return Argn = 2;
30858
30859 elsif Pname = Name_Source_File_Name then
30860 return True;
30861
30862 elsif Pname = Name_Source_Reference then
30863 return Argn = 2;
30864
30865 elsif Pname = Name_Title then
30866 return True;
30867
30868 elsif Pname = Name_Subtitle then
30869 return True;
30870
30871 else
30872 return False;
30873 end if;
30874 end Is_Pragma_String_Literal;
30875
30876 ---------------------------
30877 -- Is_Private_SPARK_Mode --
30878 ---------------------------
30879
30880 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
30881 begin
30882 pragma Assert
30883 (Nkind (N) = N_Pragma
30884 and then Pragma_Name (N) = Name_SPARK_Mode
30885 and then Is_List_Member (N));
30886
30887 -- For pragma SPARK_Mode to be private, it has to appear in the private
30888 -- declarations of a package.
30889
30890 return
30891 Present (Parent (N))
30892 and then Nkind (Parent (N)) = N_Package_Specification
30893 and then List_Containing (N) = Private_Declarations (Parent (N));
30894 end Is_Private_SPARK_Mode;
30895
30896 -------------------------------------
30897 -- Is_Unconstrained_Or_Tagged_Item --
30898 -------------------------------------
30899
30900 function Is_Unconstrained_Or_Tagged_Item
30901 (Item : Entity_Id) return Boolean
30902 is
30903 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
30904 -- Determine whether record type Typ has at least one unconstrained
30905 -- component.
30906
30907 ---------------------------------
30908 -- Has_Unconstrained_Component --
30909 ---------------------------------
30910
30911 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
30912 Comp : Entity_Id;
30913
30914 begin
30915 Comp := First_Component (Typ);
30916 while Present (Comp) loop
30917 if Is_Unconstrained_Or_Tagged_Item (Comp) then
30918 return True;
30919 end if;
30920
30921 Next_Component (Comp);
30922 end loop;
30923
30924 return False;
30925 end Has_Unconstrained_Component;
30926
30927 -- Local variables
30928
30929 Typ : constant Entity_Id := Etype (Item);
30930
30931 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
30932
30933 begin
30934 if Is_Tagged_Type (Typ) then
30935 return True;
30936
30937 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
30938 return True;
30939
30940 elsif Is_Record_Type (Typ) then
30941 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
30942 return True;
30943 else
30944 return Has_Unconstrained_Component (Typ);
30945 end if;
30946
30947 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
30948 return True;
30949
30950 else
30951 return False;
30952 end if;
30953 end Is_Unconstrained_Or_Tagged_Item;
30954
30955 -----------------------------
30956 -- Is_Valid_Assertion_Kind --
30957 -----------------------------
30958
30959 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
30960 begin
30961 case Nam is
30962 when
30963 -- RM defined
30964
30965 Name_Assert
30966 | Name_Assertion_Policy
30967 | Name_Static_Predicate
30968 | Name_Dynamic_Predicate
30969 | Name_Pre
30970 | Name_uPre
30971 | Name_Post
30972 | Name_uPost
30973 | Name_Type_Invariant
30974 | Name_uType_Invariant
30975
30976 -- Impl defined
30977
30978 | Name_Assert_And_Cut
30979 | Name_Assume
30980 | Name_Contract_Cases
30981 | Name_Debug
30982 | Name_Default_Initial_Condition
30983 | Name_Ghost
30984 | Name_Initial_Condition
30985 | Name_Invariant
30986 | Name_uInvariant
30987 | Name_Loop_Invariant
30988 | Name_Loop_Variant
30989 | Name_Postcondition
30990 | Name_Precondition
30991 | Name_Predicate
30992 | Name_Refined_Post
30993 | Name_Statement_Assertions
30994 =>
30995 return True;
30996
30997 when others =>
30998 return False;
30999 end case;
31000 end Is_Valid_Assertion_Kind;
31001
31002 --------------------------------------
31003 -- Process_Compilation_Unit_Pragmas --
31004 --------------------------------------
31005
31006 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
31007 begin
31008 -- A special check for pragma Suppress_All, a very strange DEC pragma,
31009 -- strange because it comes at the end of the unit. Rational has the
31010 -- same name for a pragma, but treats it as a program unit pragma, In
31011 -- GNAT we just decide to allow it anywhere at all. If it appeared then
31012 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
31013 -- node, and we insert a pragma Suppress (All_Checks) at the start of
31014 -- the context clause to ensure the correct processing.
31015
31016 if Has_Pragma_Suppress_All (N) then
31017 Prepend_To (Context_Items (N),
31018 Make_Pragma (Sloc (N),
31019 Chars => Name_Suppress,
31020 Pragma_Argument_Associations => New_List (
31021 Make_Pragma_Argument_Association (Sloc (N),
31022 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
31023 end if;
31024
31025 -- Nothing else to do at the current time
31026
31027 end Process_Compilation_Unit_Pragmas;
31028
31029 --------------------------------------------
31030 -- Validate_Compile_Time_Warning_Or_Error --
31031 --------------------------------------------
31032
31033 procedure Validate_Compile_Time_Warning_Or_Error
31034 (N : Node_Id;
31035 Eloc : Source_Ptr)
31036 is
31037 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
31038 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
31039 Arg2 : constant Node_Id := Next (Arg1);
31040
31041 Pname : constant Name_Id := Pragma_Name_Unmapped (N);
31042 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
31043
31044 begin
31045 Analyze_And_Resolve (Arg1x, Standard_Boolean);
31046
31047 if Compile_Time_Known_Value (Arg1x) then
31048 if Is_True (Expr_Value (Arg1x)) then
31049
31050 -- We have already verified that the second argument is a static
31051 -- string expression. Its string value must be retrieved
31052 -- explicitly if it is a declared constant, otherwise it has
31053 -- been constant-folded previously.
31054
31055 declare
31056 Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
31057 Str : constant String_Id :=
31058 Strval (Expr_Value_S (Get_Pragma_Arg (Arg2)));
31059 Str_Len : constant Nat := String_Length (Str);
31060
31061 Force : constant Boolean :=
31062 Prag_Id = Pragma_Compile_Time_Warning
31063 and then Is_Spec_Name (Unit_Name (Current_Sem_Unit))
31064 and then (Ekind (Cent) /= E_Package
31065 or else not In_Private_Part (Cent));
31066 -- Set True if this is the warning case, and we are in the
31067 -- visible part of a package spec, or in a subprogram spec,
31068 -- in which case we want to force the client to see the
31069 -- warning, even though it is not in the main unit.
31070
31071 C : Character;
31072 CC : Char_Code;
31073 Cont : Boolean;
31074 Ptr : Nat;
31075
31076 begin
31077 -- Loop through segments of message separated by line feeds.
31078 -- We output these segments as separate messages with
31079 -- continuation marks for all but the first.
31080
31081 Cont := False;
31082 Ptr := 1;
31083 loop
31084 Error_Msg_Strlen := 0;
31085
31086 -- Loop to copy characters from argument to error message
31087 -- string buffer.
31088
31089 loop
31090 exit when Ptr > Str_Len;
31091 CC := Get_String_Char (Str, Ptr);
31092 Ptr := Ptr + 1;
31093
31094 -- Ignore wide chars ??? else store character
31095
31096 if In_Character_Range (CC) then
31097 C := Get_Character (CC);
31098 exit when C = ASCII.LF;
31099 Error_Msg_Strlen := Error_Msg_Strlen + 1;
31100 Error_Msg_String (Error_Msg_Strlen) := C;
31101 end if;
31102 end loop;
31103
31104 -- Here with one line ready to go
31105
31106 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
31107
31108 -- If this is a warning in a spec, then we want clients
31109 -- to see the warning, so mark the message with the
31110 -- special sequence !! to force the warning. In the case
31111 -- of a package spec, we do not force this if we are in
31112 -- the private part of the spec.
31113
31114 if Force then
31115 if Cont = False then
31116 Error_Msg ("<<~!!", Eloc);
31117 Cont := True;
31118 else
31119 Error_Msg ("\<<~!!", Eloc);
31120 end if;
31121
31122 -- Error, rather than warning, or in a body, so we do not
31123 -- need to force visibility for client (error will be
31124 -- output in any case, and this is the situation in which
31125 -- we do not want a client to get a warning, since the
31126 -- warning is in the body or the spec private part).
31127
31128 else
31129 if Cont = False then
31130 Error_Msg ("<<~", Eloc);
31131 Cont := True;
31132 else
31133 Error_Msg ("\<<~", Eloc);
31134 end if;
31135 end if;
31136
31137 exit when Ptr > Str_Len;
31138 end loop;
31139 end;
31140 end if;
31141
31142 -- Arg1x is not known at compile time, so possibly issue an error
31143 -- or warning. This can happen only if the pragma's processing
31144 -- was deferred until after the back end is run (see
31145 -- Process_Compile_Time_Warning_Or_Error). Note that the warning
31146 -- control switch applies to only the warning case.
31147
31148 elsif Prag_Id = Pragma_Compile_Time_Error then
31149 Error_Msg_N ("condition is not known at compile time", Arg1x);
31150
31151 elsif Warn_On_Unknown_Compile_Time_Warning then
31152 Error_Msg_N ("?condition is not known at compile time", Arg1x);
31153 end if;
31154 end Validate_Compile_Time_Warning_Or_Error;
31155
31156 ------------------------------------
31157 -- Record_Possible_Body_Reference --
31158 ------------------------------------
31159
31160 procedure Record_Possible_Body_Reference
31161 (State_Id : Entity_Id;
31162 Ref : Node_Id)
31163 is
31164 Context : Node_Id;
31165 Spec_Id : Entity_Id;
31166
31167 begin
31168 -- Ensure that we are dealing with a reference to a state
31169
31170 pragma Assert (Ekind (State_Id) = E_Abstract_State);
31171
31172 -- Climb the tree starting from the reference looking for a package body
31173 -- whose spec declares the referenced state. This criteria automatically
31174 -- excludes references in package specs which are legal. Note that it is
31175 -- not wise to emit an error now as the package body may lack pragma
31176 -- Refined_State or the referenced state may not be mentioned in the
31177 -- refinement. This approach avoids the generation of misleading errors.
31178
31179 Context := Ref;
31180 while Present (Context) loop
31181 if Nkind (Context) = N_Package_Body then
31182 Spec_Id := Corresponding_Spec (Context);
31183
31184 if Present (Abstract_States (Spec_Id))
31185 and then Contains (Abstract_States (Spec_Id), State_Id)
31186 then
31187 if No (Body_References (State_Id)) then
31188 Set_Body_References (State_Id, New_Elmt_List);
31189 end if;
31190
31191 Append_Elmt (Ref, To => Body_References (State_Id));
31192 exit;
31193 end if;
31194 end if;
31195
31196 Context := Parent (Context);
31197 end loop;
31198 end Record_Possible_Body_Reference;
31199
31200 ------------------------------------------
31201 -- Relocate_Pragmas_To_Anonymous_Object --
31202 ------------------------------------------
31203
31204 procedure Relocate_Pragmas_To_Anonymous_Object
31205 (Typ_Decl : Node_Id;
31206 Obj_Decl : Node_Id)
31207 is
31208 Decl : Node_Id;
31209 Def : Node_Id;
31210 Next_Decl : Node_Id;
31211
31212 begin
31213 if Nkind (Typ_Decl) = N_Protected_Type_Declaration then
31214 Def := Protected_Definition (Typ_Decl);
31215 else
31216 pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration);
31217 Def := Task_Definition (Typ_Decl);
31218 end if;
31219
31220 -- The concurrent definition has a visible declaration list. Inspect it
31221 -- and relocate all canidate pragmas.
31222
31223 if Present (Def) and then Present (Visible_Declarations (Def)) then
31224 Decl := First (Visible_Declarations (Def));
31225 while Present (Decl) loop
31226
31227 -- Preserve the following declaration for iteration purposes due
31228 -- to possible relocation of a pragma.
31229
31230 Next_Decl := Next (Decl);
31231
31232 if Nkind (Decl) = N_Pragma
31233 and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl))
31234 then
31235 Remove (Decl);
31236 Insert_After (Obj_Decl, Decl);
31237
31238 -- Skip internally generated code
31239
31240 elsif not Comes_From_Source (Decl) then
31241 null;
31242
31243 -- No candidate pragmas are available for relocation
31244
31245 else
31246 exit;
31247 end if;
31248
31249 Decl := Next_Decl;
31250 end loop;
31251 end if;
31252 end Relocate_Pragmas_To_Anonymous_Object;
31253
31254 ------------------------------
31255 -- Relocate_Pragmas_To_Body --
31256 ------------------------------
31257
31258 procedure Relocate_Pragmas_To_Body
31259 (Subp_Body : Node_Id;
31260 Target_Body : Node_Id := Empty)
31261 is
31262 procedure Relocate_Pragma (Prag : Node_Id);
31263 -- Remove a single pragma from its current list and add it to the
31264 -- declarations of the proper body (either Subp_Body or Target_Body).
31265
31266 ---------------------
31267 -- Relocate_Pragma --
31268 ---------------------
31269
31270 procedure Relocate_Pragma (Prag : Node_Id) is
31271 Decls : List_Id;
31272 Target : Node_Id;
31273
31274 begin
31275 -- When subprogram stubs or expression functions are involves, the
31276 -- destination declaration list belongs to the proper body.
31277
31278 if Present (Target_Body) then
31279 Target := Target_Body;
31280 else
31281 Target := Subp_Body;
31282 end if;
31283
31284 Decls := Declarations (Target);
31285
31286 if No (Decls) then
31287 Decls := New_List;
31288 Set_Declarations (Target, Decls);
31289 end if;
31290
31291 -- Unhook the pragma from its current list
31292
31293 Remove (Prag);
31294 Prepend (Prag, Decls);
31295 end Relocate_Pragma;
31296
31297 -- Local variables
31298
31299 Body_Id : constant Entity_Id :=
31300 Defining_Unit_Name (Specification (Subp_Body));
31301 Next_Stmt : Node_Id;
31302 Stmt : Node_Id;
31303
31304 -- Start of processing for Relocate_Pragmas_To_Body
31305
31306 begin
31307 -- Do not process a body that comes from a separate unit as no construct
31308 -- can possibly follow it.
31309
31310 if not Is_List_Member (Subp_Body) then
31311 return;
31312
31313 -- Do not relocate pragmas that follow a stub if the stub does not have
31314 -- a proper body.
31315
31316 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
31317 and then No (Target_Body)
31318 then
31319 return;
31320
31321 -- Do not process internally generated routine _Postconditions
31322
31323 elsif Ekind (Body_Id) = E_Procedure
31324 and then Chars (Body_Id) = Name_uPostconditions
31325 then
31326 return;
31327 end if;
31328
31329 -- Look at what is following the body. We are interested in certain kind
31330 -- of pragmas (either from source or byproducts of expansion) that can
31331 -- apply to a body [stub].
31332
31333 Stmt := Next (Subp_Body);
31334 while Present (Stmt) loop
31335
31336 -- Preserve the following statement for iteration purposes due to a
31337 -- possible relocation of a pragma.
31338
31339 Next_Stmt := Next (Stmt);
31340
31341 -- Move a candidate pragma following the body to the declarations of
31342 -- the body.
31343
31344 if Nkind (Stmt) = N_Pragma
31345 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
31346 then
31347
31348 -- If a source pragma Warnings follows the body, it applies to
31349 -- following statements and does not belong in the body.
31350
31351 if Get_Pragma_Id (Stmt) = Pragma_Warnings
31352 and then Comes_From_Source (Stmt)
31353 then
31354 null;
31355 else
31356 Relocate_Pragma (Stmt);
31357 end if;
31358
31359 -- Skip internally generated code
31360
31361 elsif not Comes_From_Source (Stmt) then
31362 null;
31363
31364 -- No candidate pragmas are available for relocation
31365
31366 else
31367 exit;
31368 end if;
31369
31370 Stmt := Next_Stmt;
31371 end loop;
31372 end Relocate_Pragmas_To_Body;
31373
31374 -------------------
31375 -- Resolve_State --
31376 -------------------
31377
31378 procedure Resolve_State (N : Node_Id) is
31379 Func : Entity_Id;
31380 State : Entity_Id;
31381
31382 begin
31383 if Is_Entity_Name (N) and then Present (Entity (N)) then
31384 Func := Entity (N);
31385
31386 -- Handle overloading of state names by functions. Traverse the
31387 -- homonym chain looking for an abstract state.
31388
31389 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
31390 pragma Assert (Is_Overloaded (N));
31391
31392 State := Homonym (Func);
31393 while Present (State) loop
31394 if Ekind (State) = E_Abstract_State then
31395
31396 -- Resolve the overloading by setting the proper entity of
31397 -- the reference to that of the state.
31398
31399 Set_Etype (N, Standard_Void_Type);
31400 Set_Entity (N, State);
31401 Set_Is_Overloaded (N, False);
31402
31403 Generate_Reference (State, N);
31404 return;
31405 end if;
31406
31407 State := Homonym (State);
31408 end loop;
31409
31410 -- A function can never act as a state. If the homonym chain does
31411 -- not contain a corresponding state, then something went wrong in
31412 -- the overloading mechanism.
31413
31414 raise Program_Error;
31415 end if;
31416 end if;
31417 end Resolve_State;
31418
31419 ----------------------------
31420 -- Rewrite_Assertion_Kind --
31421 ----------------------------
31422
31423 procedure Rewrite_Assertion_Kind
31424 (N : Node_Id;
31425 From_Policy : Boolean := False)
31426 is
31427 Nam : Name_Id;
31428
31429 begin
31430 Nam := No_Name;
31431 if Nkind (N) = N_Attribute_Reference
31432 and then Attribute_Name (N) = Name_Class
31433 and then Nkind (Prefix (N)) = N_Identifier
31434 then
31435 case Chars (Prefix (N)) is
31436 when Name_Pre =>
31437 Nam := Name_uPre;
31438
31439 when Name_Post =>
31440 Nam := Name_uPost;
31441
31442 when Name_Type_Invariant =>
31443 Nam := Name_uType_Invariant;
31444
31445 when Name_Invariant =>
31446 Nam := Name_uInvariant;
31447
31448 when others =>
31449 return;
31450 end case;
31451
31452 -- Recommend standard use of aspect names Pre/Post
31453
31454 elsif Nkind (N) = N_Identifier
31455 and then From_Policy
31456 and then Serious_Errors_Detected = 0
31457 then
31458 if Chars (N) = Name_Precondition
31459 or else Chars (N) = Name_Postcondition
31460 then
31461 Error_Msg_N ("Check_Policy is a non-standard pragma??", N);
31462 Error_Msg_N
31463 ("\use Assertion_Policy and aspect names Pre/Post for "
31464 & "Ada2012 conformance?", N);
31465 end if;
31466
31467 return;
31468 end if;
31469
31470 if Nam /= No_Name then
31471 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
31472 end if;
31473 end Rewrite_Assertion_Kind;
31474
31475 --------
31476 -- rv --
31477 --------
31478
31479 procedure rv is
31480 begin
31481 Dummy := Dummy + 1;
31482 end rv;
31483
31484 --------------------------------
31485 -- Set_Encoded_Interface_Name --
31486 --------------------------------
31487
31488 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
31489 Str : constant String_Id := Strval (S);
31490 Len : constant Nat := String_Length (Str);
31491 CC : Char_Code;
31492 C : Character;
31493 J : Pos;
31494
31495 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
31496
31497 procedure Encode;
31498 -- Stores encoded value of character code CC. The encoding we use an
31499 -- underscore followed by four lower case hex digits.
31500
31501 ------------
31502 -- Encode --
31503 ------------
31504
31505 procedure Encode is
31506 begin
31507 Store_String_Char (Get_Char_Code ('_'));
31508 Store_String_Char
31509 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
31510 Store_String_Char
31511 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
31512 Store_String_Char
31513 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
31514 Store_String_Char
31515 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
31516 end Encode;
31517
31518 -- Start of processing for Set_Encoded_Interface_Name
31519
31520 begin
31521 -- If first character is asterisk, this is a link name, and we leave it
31522 -- completely unmodified. We also ignore null strings (the latter case
31523 -- happens only in error cases).
31524
31525 if Len = 0
31526 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
31527 then
31528 Set_Interface_Name (E, S);
31529
31530 else
31531 J := 1;
31532 loop
31533 CC := Get_String_Char (Str, J);
31534
31535 exit when not In_Character_Range (CC);
31536
31537 C := Get_Character (CC);
31538
31539 exit when C /= '_' and then C /= '$'
31540 and then C not in '0' .. '9'
31541 and then C not in 'a' .. 'z'
31542 and then C not in 'A' .. 'Z';
31543
31544 if J = Len then
31545 Set_Interface_Name (E, S);
31546 return;
31547
31548 else
31549 J := J + 1;
31550 end if;
31551 end loop;
31552
31553 -- Here we need to encode. The encoding we use as follows:
31554 -- three underscores + four hex digits (lower case)
31555
31556 Start_String;
31557
31558 for J in 1 .. String_Length (Str) loop
31559 CC := Get_String_Char (Str, J);
31560
31561 if not In_Character_Range (CC) then
31562 Encode;
31563 else
31564 C := Get_Character (CC);
31565
31566 if C = '_' or else C = '$'
31567 or else C in '0' .. '9'
31568 or else C in 'a' .. 'z'
31569 or else C in 'A' .. 'Z'
31570 then
31571 Store_String_Char (CC);
31572 else
31573 Encode;
31574 end if;
31575 end if;
31576 end loop;
31577
31578 Set_Interface_Name (E,
31579 Make_String_Literal (Sloc (S),
31580 Strval => End_String));
31581 end if;
31582 end Set_Encoded_Interface_Name;
31583
31584 ------------------------
31585 -- Set_Elab_Unit_Name --
31586 ------------------------
31587
31588 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
31589 Pref : Node_Id;
31590 Scop : Entity_Id;
31591
31592 begin
31593 if Nkind (N) = N_Identifier
31594 and then Nkind (With_Item) = N_Identifier
31595 then
31596 Set_Entity (N, Entity (With_Item));
31597
31598 elsif Nkind (N) = N_Selected_Component then
31599 Change_Selected_Component_To_Expanded_Name (N);
31600 Set_Entity (N, Entity (With_Item));
31601 Set_Entity (Selector_Name (N), Entity (N));
31602
31603 Pref := Prefix (N);
31604 Scop := Scope (Entity (N));
31605 while Nkind (Pref) = N_Selected_Component loop
31606 Change_Selected_Component_To_Expanded_Name (Pref);
31607 Set_Entity (Selector_Name (Pref), Scop);
31608 Set_Entity (Pref, Scop);
31609 Pref := Prefix (Pref);
31610 Scop := Scope (Scop);
31611 end loop;
31612
31613 Set_Entity (Pref, Scop);
31614 end if;
31615
31616 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
31617 end Set_Elab_Unit_Name;
31618
31619 -----------------------
31620 -- Set_Overflow_Mode --
31621 -----------------------
31622
31623 procedure Set_Overflow_Mode (N : Node_Id) is
31624
31625 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type;
31626 -- Function to process one pragma argument, Arg
31627
31628 -----------------------
31629 -- Get_Overflow_Mode --
31630 -----------------------
31631
31632 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type is
31633 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
31634
31635 begin
31636 if Chars (Argx) = Name_Strict then
31637 return Strict;
31638
31639 elsif Chars (Argx) = Name_Minimized then
31640 return Minimized;
31641
31642 elsif Chars (Argx) = Name_Eliminated then
31643 return Eliminated;
31644
31645 else
31646 raise Program_Error;
31647 end if;
31648 end Get_Overflow_Mode;
31649
31650 -- Local variables
31651
31652 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
31653 Arg2 : constant Node_Id := Next (Arg1);
31654
31655 -- Start of processing for Set_Overflow_Mode
31656
31657 begin
31658 -- Process first argument
31659
31660 Scope_Suppress.Overflow_Mode_General :=
31661 Get_Overflow_Mode (Arg1);
31662
31663 -- Case of only one argument
31664
31665 if No (Arg2) then
31666 Scope_Suppress.Overflow_Mode_Assertions :=
31667 Scope_Suppress.Overflow_Mode_General;
31668
31669 -- Case of two arguments present
31670
31671 else
31672 Scope_Suppress.Overflow_Mode_Assertions :=
31673 Get_Overflow_Mode (Arg2);
31674 end if;
31675 end Set_Overflow_Mode;
31676
31677 -------------------
31678 -- Test_Case_Arg --
31679 -------------------
31680
31681 function Test_Case_Arg
31682 (Prag : Node_Id;
31683 Arg_Nam : Name_Id;
31684 From_Aspect : Boolean := False) return Node_Id
31685 is
31686 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
31687 Arg : Node_Id;
31688 Args : Node_Id;
31689
31690 begin
31691 pragma Assert (Nam_In (Arg_Nam, Name_Ensures,
31692 Name_Mode,
31693 Name_Name,
31694 Name_Requires));
31695
31696 -- The caller requests the aspect argument
31697
31698 if From_Aspect then
31699 if Present (Aspect)
31700 and then Nkind (Expression (Aspect)) = N_Aggregate
31701 then
31702 Args := Expression (Aspect);
31703
31704 -- "Name" and "Mode" may appear without an identifier as a
31705 -- positional association.
31706
31707 if Present (Expressions (Args)) then
31708 Arg := First (Expressions (Args));
31709
31710 if Present (Arg) and then Arg_Nam = Name_Name then
31711 return Arg;
31712 end if;
31713
31714 -- Skip "Name"
31715
31716 Arg := Next (Arg);
31717
31718 if Present (Arg) and then Arg_Nam = Name_Mode then
31719 return Arg;
31720 end if;
31721 end if;
31722
31723 -- Some or all arguments may appear as component associatons
31724
31725 if Present (Component_Associations (Args)) then
31726 Arg := First (Component_Associations (Args));
31727 while Present (Arg) loop
31728 if Chars (First (Choices (Arg))) = Arg_Nam then
31729 return Arg;
31730 end if;
31731
31732 Next (Arg);
31733 end loop;
31734 end if;
31735 end if;
31736
31737 -- Otherwise retrieve the argument directly from the pragma
31738
31739 else
31740 Arg := First (Pragma_Argument_Associations (Prag));
31741
31742 if Present (Arg) and then Arg_Nam = Name_Name then
31743 return Arg;
31744 end if;
31745
31746 -- Skip argument "Name"
31747
31748 Arg := Next (Arg);
31749
31750 if Present (Arg) and then Arg_Nam = Name_Mode then
31751 return Arg;
31752 end if;
31753
31754 -- Skip argument "Mode"
31755
31756 Arg := Next (Arg);
31757
31758 -- Arguments "Requires" and "Ensures" are optional and may not be
31759 -- present at all.
31760
31761 while Present (Arg) loop
31762 if Chars (Arg) = Arg_Nam then
31763 return Arg;
31764 end if;
31765
31766 Next (Arg);
31767 end loop;
31768 end if;
31769
31770 return Empty;
31771 end Test_Case_Arg;
31772
31773 --------------------------------------------
31774 -- Defer_Compile_Time_Warning_Error_To_BE --
31775 --------------------------------------------
31776
31777 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id) is
31778 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
31779 begin
31780 Compile_Time_Warnings_Errors.Append
31781 (New_Val => CTWE_Entry'(Eloc => Sloc (Arg1),
31782 Scope => Current_Scope,
31783 Prag => N));
31784
31785 -- If the Boolean expression contains T'Size, and we're not in the main
31786 -- unit being compiled, then we need to copy the pragma into the main
31787 -- unit, because otherwise T'Size might never be computed, leaving it
31788 -- as 0.
31789
31790 if not In_Extended_Main_Code_Unit (N) then
31791 Insert_Library_Level_Action (New_Copy_Tree (N));
31792 end if;
31793 end Defer_Compile_Time_Warning_Error_To_BE;
31794
31795 ------------------------------------------
31796 -- Validate_Compile_Time_Warning_Errors --
31797 ------------------------------------------
31798
31799 procedure Validate_Compile_Time_Warning_Errors is
31800 procedure Set_Scope (S : Entity_Id);
31801 -- Install all enclosing scopes of S along with S itself
31802
31803 procedure Unset_Scope (S : Entity_Id);
31804 -- Uninstall all enclosing scopes of S along with S itself
31805
31806 ---------------
31807 -- Set_Scope --
31808 ---------------
31809
31810 procedure Set_Scope (S : Entity_Id) is
31811 begin
31812 if S /= Standard_Standard then
31813 Set_Scope (Scope (S));
31814 end if;
31815
31816 Push_Scope (S);
31817 end Set_Scope;
31818
31819 -----------------
31820 -- Unset_Scope --
31821 -----------------
31822
31823 procedure Unset_Scope (S : Entity_Id) is
31824 begin
31825 if S /= Standard_Standard then
31826 Unset_Scope (Scope (S));
31827 end if;
31828
31829 Pop_Scope;
31830 end Unset_Scope;
31831
31832 -- Start of processing for Validate_Compile_Time_Warning_Errors
31833
31834 begin
31835 Expander_Mode_Save_And_Set (False);
31836 In_Compile_Time_Warning_Or_Error := True;
31837
31838 for N in Compile_Time_Warnings_Errors.First ..
31839 Compile_Time_Warnings_Errors.Last
31840 loop
31841 declare
31842 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
31843
31844 begin
31845 Set_Scope (T.Scope);
31846 Reset_Analyzed_Flags (T.Prag);
31847 Validate_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
31848 Unset_Scope (T.Scope);
31849 end;
31850 end loop;
31851
31852 In_Compile_Time_Warning_Or_Error := False;
31853 Expander_Mode_Restore;
31854 end Validate_Compile_Time_Warning_Errors;
31855
31856 end Sem_Prag;