[multiple changes]
[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-2017, 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 Freeze; use Freeze;
45 with Ghost; use Ghost;
46 with Gnatvsn; use Gnatvsn;
47 with Lib; use Lib;
48 with Lib.Writ; use Lib.Writ;
49 with Lib.Xref; use Lib.Xref;
50 with Namet.Sp; use Namet.Sp;
51 with Nlists; use Nlists;
52 with Nmake; use Nmake;
53 with Output; use Output;
54 with Par_SCO; use Par_SCO;
55 with Restrict; use Restrict;
56 with Rident; use Rident;
57 with Rtsfind; use Rtsfind;
58 with Sem; use Sem;
59 with Sem_Aux; use Sem_Aux;
60 with Sem_Ch3; use Sem_Ch3;
61 with Sem_Ch6; use Sem_Ch6;
62 with Sem_Ch8; use Sem_Ch8;
63 with Sem_Ch12; use Sem_Ch12;
64 with Sem_Ch13; use Sem_Ch13;
65 with Sem_Disp; use Sem_Disp;
66 with Sem_Dist; use Sem_Dist;
67 with Sem_Elim; use Sem_Elim;
68 with Sem_Eval; use Sem_Eval;
69 with Sem_Intr; use Sem_Intr;
70 with Sem_Mech; use Sem_Mech;
71 with Sem_Res; use Sem_Res;
72 with Sem_Type; use Sem_Type;
73 with Sem_Util; use Sem_Util;
74 with Sem_Warn; use Sem_Warn;
75 with Stand; use Stand;
76 with Sinfo; use Sinfo;
77 with Sinfo.CN; use Sinfo.CN;
78 with Sinput; use Sinput;
79 with Stringt; use Stringt;
80 with Stylesw; use Stylesw;
81 with Table;
82 with Targparm; use Targparm;
83 with Tbuild; use Tbuild;
84 with Ttypes;
85 with Uintp; use Uintp;
86 with Uname; use Uname;
87 with Urealp; use Urealp;
88 with Validsw; use Validsw;
89 with Warnsw; use Warnsw;
90
91 package body Sem_Prag is
92
93 ----------------------------------------------
94 -- Common Handling of Import-Export Pragmas --
95 ----------------------------------------------
96
97 -- In the following section, a number of Import_xxx and Export_xxx pragmas
98 -- are defined by GNAT. These are compatible with the DEC pragmas of the
99 -- same name, and all have the following common form and processing:
100
101 -- pragma Export_xxx
102 -- [Internal =>] LOCAL_NAME
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
105
106 -- pragma Import_xxx
107 -- [Internal =>] LOCAL_NAME
108 -- [, [External =>] EXTERNAL_SYMBOL]
109 -- [, other optional parameters ]);
110
111 -- EXTERNAL_SYMBOL ::=
112 -- IDENTIFIER
113 -- | static_string_EXPRESSION
114
115 -- The internal LOCAL_NAME designates the entity that is imported or
116 -- exported, and must refer to an entity in the current declarative
117 -- part (as required by the rules for LOCAL_NAME).
118
119 -- The external linker name is designated by the External parameter if
120 -- given, or the Internal parameter if not (if there is no External
121 -- parameter, the External parameter is a copy of the Internal name).
122
123 -- If the External parameter is given as a string, then this string is
124 -- treated as an external name (exactly as though it had been given as an
125 -- External_Name parameter for a normal Import pragma).
126
127 -- If the External parameter is given as an identifier (or there is no
128 -- External parameter, so that the Internal identifier is used), then
129 -- the external name is the characters of the identifier, translated
130 -- to all lower case letters.
131
132 -- Note: the external name specified or implied by any of these special
133 -- Import_xxx or Export_xxx pragmas override an external or link name
134 -- specified in a previous Import or Export pragma.
135
136 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
137 -- named notation, following the standard rules for subprogram calls, i.e.
138 -- parameters can be given in any order if named notation is used, and
139 -- positional and named notation can be mixed, subject to the rule that all
140 -- positional parameters must appear first.
141
142 -- Note: All these pragmas are implemented exactly following the DEC design
143 -- and implementation and are intended to be fully compatible with the use
144 -- of these pragmas in the DEC Ada compiler.
145
146 --------------------------------------------
147 -- Checking for Duplicated External Names --
148 --------------------------------------------
149
150 -- It is suspicious if two separate Export pragmas use the same external
151 -- name. The following table is used to diagnose this situation so that
152 -- an appropriate warning can be issued.
153
154 -- The Node_Id stored is for the N_String_Literal node created to hold
155 -- the value of the external name. The Sloc of this node is used to
156 -- cross-reference the location of the duplication.
157
158 package Externals is new Table.Table (
159 Table_Component_Type => Node_Id,
160 Table_Index_Type => Int,
161 Table_Low_Bound => 0,
162 Table_Initial => 100,
163 Table_Increment => 100,
164 Table_Name => "Name_Externals");
165
166 -------------------------------------
167 -- Local Subprograms and Variables --
168 -------------------------------------
169
170 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
171 -- This routine is used for possible casing adjustment of an explicit
172 -- external name supplied as a string literal (the node N), according to
173 -- the casing requirement of Opt.External_Name_Casing. If this is set to
174 -- As_Is, then the string literal is returned unchanged, but if it is set
175 -- to Uppercase or Lowercase, then a new string literal with appropriate
176 -- casing is constructed.
177
178 procedure Analyze_Part_Of
179 (Indic : Node_Id;
180 Item_Id : Entity_Id;
181 Encap : Node_Id;
182 Encap_Id : out Entity_Id;
183 Legal : out Boolean);
184 -- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and
185 -- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the
186 -- Part_Of indicator. Item_Id is the entity of an abstract state, object or
187 -- package instantiation. Encap denotes the encapsulating state or single
188 -- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when
189 -- the indicator is legal.
190
191 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
192 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
193 -- Query whether a particular item appears in a mixed list of nodes and
194 -- entities. It is assumed that all nodes in the list have entities.
195
196 procedure Check_Postcondition_Use_In_Inlined_Subprogram
197 (Prag : Node_Id;
198 Spec_Id : Entity_Id);
199 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
200 -- Precondition, Refined_Post and Test_Case. Emit a warning when pragma
201 -- Prag is associated with subprogram Spec_Id subject to Inline_Always.
202
203 procedure Check_State_And_Constituent_Use
204 (States : Elist_Id;
205 Constits : Elist_Id;
206 Context : Node_Id);
207 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
208 -- Global and Initializes. Determine whether a state from list States and a
209 -- corresponding constituent from list Constits (if any) appear in the same
210 -- context denoted by Context. If this is the case, emit an error.
211
212 procedure Contract_Freeze_Error
213 (Contract_Id : Entity_Id;
214 Freeze_Id : Entity_Id);
215 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and
216 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity
217 -- of a body which caused contract "freezing" and Contract_Id denotes the
218 -- entity of the affected contstruct.
219
220 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id);
221 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma
222 -- Prag that duplicates previous pragma Prev.
223
224 function Find_Encapsulating_State
225 (States : Elist_Id;
226 Constit_Id : Entity_Id) return Entity_Id;
227 -- Given the entity of a constituent Constit_Id, find the corresponding
228 -- encapsulating state which appears in States. The routine returns Empty
229 -- if no such state is found.
230
231 function Find_Related_Context
232 (Prag : Node_Id;
233 Do_Checks : Boolean := False) return Node_Id;
234 -- Subsidiary to the analysis of pragmas
235 -- Async_Readers
236 -- Async_Writers
237 -- Constant_After_Elaboration
238 -- Effective_Reads
239 -- Effective_Writers
240 -- Part_Of
241 -- Find the first source declaration or statement found while traversing
242 -- the previous node chain starting from pragma Prag. If flag Do_Checks is
243 -- set, the routine reports duplicate pragmas. The routine returns Empty
244 -- when reaching the start of the node chain.
245
246 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
247 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
248 -- original one, following the renaming chain) is returned. Otherwise the
249 -- entity is returned unchanged. Should be in Einfo???
250
251 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
252 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
253 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
254 -- value of type SPARK_Mode_Type.
255
256 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
257 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
258 -- Determine whether dependency clause Clause is surrounded by extra
259 -- parentheses. If this is the case, issue an error message.
260
261 function Is_CCT_Instance
262 (Ref_Id : Entity_Id;
263 Context_Id : Entity_Id) return Boolean;
264 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
265 -- Global. Determine whether entity Ref_Id denotes the current instance of
266 -- a concurrent type. Context_Id denotes the associated context where the
267 -- pragma appears.
268
269 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
270 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
271 -- pragma Depends. Determine whether the type of dependency item Item is
272 -- tagged, unconstrained array, unconstrained record or a record with at
273 -- least one unconstrained component.
274
275 procedure Record_Possible_Body_Reference
276 (State_Id : Entity_Id;
277 Ref : Node_Id);
278 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
279 -- Global. Given an abstract state denoted by State_Id and a reference Ref
280 -- to it, determine whether the reference appears in a package body that
281 -- will eventually refine the state. If this is the case, record the
282 -- reference for future checks (see Analyze_Refined_State_In_Decls).
283
284 procedure Resolve_State (N : Node_Id);
285 -- Handle the overloading of state names by functions. When N denotes a
286 -- function, this routine finds the corresponding state and sets the entity
287 -- of N to that of the state.
288
289 procedure Rewrite_Assertion_Kind
290 (N : Node_Id;
291 From_Policy : Boolean := False);
292 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
293 -- then it is rewritten as an identifier with the corresponding special
294 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
295 -- and Check_Policy. If the names are Precondition or Postcondition, this
296 -- combination is deprecated in favor of Assertion_Policy and Ada2012
297 -- Aspect names. The parameter From_Policy indicates that the pragma
298 -- is the old non-standard Check_Policy and not a rewritten pragma.
299
300 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
301 -- Place semantic information on the argument of an Elaborate/Elaborate_All
302 -- pragma. Entity name for unit and its parents is taken from item in
303 -- previous with_clause that mentions the unit.
304
305 Dummy : Integer := 0;
306 pragma Volatile (Dummy);
307 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
308
309 procedure ip;
310 pragma No_Inline (ip);
311 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
312 -- is just to help debugging the front end. If a pragma Inspection_Point
313 -- is added to a source program, then breaking on ip will get you to that
314 -- point in the program.
315
316 procedure rv;
317 pragma No_Inline (rv);
318 -- This is a dummy function called by the processing for pragma Reviewable.
319 -- It is there for assisting front end debugging. By placing a Reviewable
320 -- pragma in the source program, a breakpoint on rv catches this place in
321 -- the source, allowing convenient stepping to the point of interest.
322
323 -------------------------------
324 -- Adjust_External_Name_Case --
325 -------------------------------
326
327 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
328 CC : Char_Code;
329
330 begin
331 -- Adjust case of literal if required
332
333 if Opt.External_Name_Exp_Casing = As_Is then
334 return N;
335
336 else
337 -- Copy existing string
338
339 Start_String;
340
341 -- Set proper casing
342
343 for J in 1 .. String_Length (Strval (N)) loop
344 CC := Get_String_Char (Strval (N), J);
345
346 if Opt.External_Name_Exp_Casing = Uppercase
347 and then CC >= Get_Char_Code ('a')
348 and then CC <= Get_Char_Code ('z')
349 then
350 Store_String_Char (CC - 32);
351
352 elsif Opt.External_Name_Exp_Casing = Lowercase
353 and then CC >= Get_Char_Code ('A')
354 and then CC <= Get_Char_Code ('Z')
355 then
356 Store_String_Char (CC + 32);
357
358 else
359 Store_String_Char (CC);
360 end if;
361 end loop;
362
363 return
364 Make_String_Literal (Sloc (N),
365 Strval => End_String);
366 end if;
367 end Adjust_External_Name_Case;
368
369 -----------------------------------------
370 -- Analyze_Contract_Cases_In_Decl_Part --
371 -----------------------------------------
372
373 -- WARNING: This routine manages Ghost regions. Return statements must be
374 -- replaced by gotos which jump to the end of the routine and restore the
375 -- Ghost mode.
376
377 procedure Analyze_Contract_Cases_In_Decl_Part
378 (N : Node_Id;
379 Freeze_Id : Entity_Id := Empty)
380 is
381 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
382 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
383
384 Others_Seen : Boolean := False;
385 -- This flag is set when an "others" choice is encountered. It is used
386 -- to detect multiple illegal occurrences of "others".
387
388 procedure Analyze_Contract_Case (CCase : Node_Id);
389 -- Verify the legality of a single contract case
390
391 ---------------------------
392 -- Analyze_Contract_Case --
393 ---------------------------
394
395 procedure Analyze_Contract_Case (CCase : Node_Id) is
396 Case_Guard : Node_Id;
397 Conseq : Node_Id;
398 Errors : Nat;
399 Extra_Guard : Node_Id;
400
401 begin
402 if Nkind (CCase) = N_Component_Association then
403 Case_Guard := First (Choices (CCase));
404 Conseq := Expression (CCase);
405
406 -- Each contract case must have exactly one case guard
407
408 Extra_Guard := Next (Case_Guard);
409
410 if Present (Extra_Guard) then
411 Error_Msg_N
412 ("contract case must have exactly one case guard",
413 Extra_Guard);
414 end if;
415
416 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
417
418 if Nkind (Case_Guard) = N_Others_Choice then
419 if Others_Seen then
420 Error_Msg_N
421 ("only one others choice allowed in contract cases",
422 Case_Guard);
423 else
424 Others_Seen := True;
425 end if;
426
427 elsif Others_Seen then
428 Error_Msg_N
429 ("others must be the last choice in contract cases", N);
430 end if;
431
432 -- Preanalyze the case guard and consequence
433
434 if Nkind (Case_Guard) /= N_Others_Choice then
435 Errors := Serious_Errors_Detected;
436 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
437
438 -- Emit a clarification message when the case guard contains
439 -- at least one undefined reference, possibly due to contract
440 -- "freezing".
441
442 if Errors /= Serious_Errors_Detected
443 and then Present (Freeze_Id)
444 and then Has_Undefined_Reference (Case_Guard)
445 then
446 Contract_Freeze_Error (Spec_Id, Freeze_Id);
447 end if;
448 end if;
449
450 Errors := Serious_Errors_Detected;
451 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
452
453 -- Emit a clarification message when the consequence contains
454 -- at least one undefined reference, possibly due to contract
455 -- "freezing".
456
457 if Errors /= Serious_Errors_Detected
458 and then Present (Freeze_Id)
459 and then Has_Undefined_Reference (Conseq)
460 then
461 Contract_Freeze_Error (Spec_Id, Freeze_Id);
462 end if;
463
464 -- The contract case is malformed
465
466 else
467 Error_Msg_N ("wrong syntax in contract case", CCase);
468 end if;
469 end Analyze_Contract_Case;
470
471 -- Local variables
472
473 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
474
475 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
476 -- Save the Ghost mode to restore on exit
477
478 CCase : Node_Id;
479 Restore_Scope : Boolean := False;
480
481 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
482
483 begin
484 -- Do not analyze the pragma multiple times
485
486 if Is_Analyzed_Pragma (N) then
487 return;
488 end if;
489
490 -- Set the Ghost mode in effect from the pragma. Due to the delayed
491 -- analysis of the pragma, the Ghost mode at point of declaration and
492 -- point of analysis may not necessarily be the same. Use the mode in
493 -- effect at the point of declaration.
494
495 Set_Ghost_Mode (N);
496
497 -- Single and multiple contract cases must appear in aggregate form. If
498 -- this is not the case, then either the parser of the analysis of the
499 -- pragma failed to produce an aggregate.
500
501 pragma Assert (Nkind (CCases) = N_Aggregate);
502
503 if Present (Component_Associations (CCases)) then
504
505 -- Ensure that the formal parameters are visible when analyzing all
506 -- clauses. This falls out of the general rule of aspects pertaining
507 -- to subprogram declarations.
508
509 if not In_Open_Scopes (Spec_Id) then
510 Restore_Scope := True;
511 Push_Scope (Spec_Id);
512
513 if Is_Generic_Subprogram (Spec_Id) then
514 Install_Generic_Formals (Spec_Id);
515 else
516 Install_Formals (Spec_Id);
517 end if;
518 end if;
519
520 CCase := First (Component_Associations (CCases));
521 while Present (CCase) loop
522 Analyze_Contract_Case (CCase);
523 Next (CCase);
524 end loop;
525
526 if Restore_Scope then
527 End_Scope;
528 end if;
529
530 -- Currently it is not possible to inline pre/postconditions on a
531 -- subprogram subject to pragma Inline_Always.
532
533 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
534
535 -- Otherwise the pragma is illegal
536
537 else
538 Error_Msg_N ("wrong syntax for constract cases", N);
539 end if;
540
541 Set_Is_Analyzed_Pragma (N);
542
543 Restore_Ghost_Mode (Saved_GM);
544 end Analyze_Contract_Cases_In_Decl_Part;
545
546 ----------------------------------
547 -- Analyze_Depends_In_Decl_Part --
548 ----------------------------------
549
550 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
551 Loc : constant Source_Ptr := Sloc (N);
552 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
553 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
554
555 All_Inputs_Seen : Elist_Id := No_Elist;
556 -- A list containing the entities of all the inputs processed so far.
557 -- The list is populated with unique entities because the same input
558 -- may appear in multiple input lists.
559
560 All_Outputs_Seen : Elist_Id := No_Elist;
561 -- A list containing the entities of all the outputs processed so far.
562 -- The list is populated with unique entities because output items are
563 -- unique in a dependence relation.
564
565 Constits_Seen : Elist_Id := No_Elist;
566 -- A list containing the entities of all constituents processed so far.
567 -- It aids in detecting illegal usage of a state and a corresponding
568 -- constituent in pragma [Refinde_]Depends.
569
570 Global_Seen : Boolean := False;
571 -- A flag set when pragma Global has been processed
572
573 Null_Output_Seen : Boolean := False;
574 -- A flag used to track the legality of a null output
575
576 Result_Seen : Boolean := False;
577 -- A flag set when Spec_Id'Result is processed
578
579 States_Seen : Elist_Id := No_Elist;
580 -- A list containing the entities of all states processed so far. It
581 -- helps in detecting illegal usage of a state and a corresponding
582 -- constituent in pragma [Refined_]Depends.
583
584 Subp_Inputs : Elist_Id := No_Elist;
585 Subp_Outputs : Elist_Id := No_Elist;
586 -- Two lists containing the full set of inputs and output of the related
587 -- subprograms. Note that these lists contain both nodes and entities.
588
589 Task_Input_Seen : Boolean := False;
590 Task_Output_Seen : Boolean := False;
591 -- Flags used to track the implicit dependence of a task unit on itself
592
593 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
594 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
595 -- to the name buffer. The individual kinds are as follows:
596 -- E_Abstract_State - "state"
597 -- E_Constant - "constant"
598 -- E_Discriminant - "discriminant"
599 -- E_Generic_In_Out_Parameter - "generic parameter"
600 -- E_Generic_In_Parameter - "generic parameter"
601 -- E_In_Parameter - "parameter"
602 -- E_In_Out_Parameter - "parameter"
603 -- E_Loop_Parameter - "loop parameter"
604 -- E_Out_Parameter - "parameter"
605 -- E_Protected_Type - "current instance of protected type"
606 -- E_Task_Type - "current instance of task type"
607 -- E_Variable - "global"
608
609 procedure Analyze_Dependency_Clause
610 (Clause : Node_Id;
611 Is_Last : Boolean);
612 -- Verify the legality of a single dependency clause. Flag Is_Last
613 -- denotes whether Clause is the last clause in the relation.
614
615 procedure Check_Function_Return;
616 -- Verify that Funtion'Result appears as one of the outputs
617 -- (SPARK RM 6.1.5(10)).
618
619 procedure Check_Role
620 (Item : Node_Id;
621 Item_Id : Entity_Id;
622 Is_Input : Boolean;
623 Self_Ref : Boolean);
624 -- Ensure that an item fulfills its designated input and/or output role
625 -- as specified by pragma Global (if any) or the enclosing context. If
626 -- this is not the case, emit an error. Item and Item_Id denote the
627 -- attributes of an item. Flag Is_Input should be set when item comes
628 -- from an input list. Flag Self_Ref should be set when the item is an
629 -- output and the dependency clause has operator "+".
630
631 procedure Check_Usage
632 (Subp_Items : Elist_Id;
633 Used_Items : Elist_Id;
634 Is_Input : Boolean);
635 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
636 -- error if this is not the case.
637
638 procedure Normalize_Clause (Clause : Node_Id);
639 -- Remove a self-dependency "+" from the input list of a clause
640
641 -----------------------------
642 -- Add_Item_To_Name_Buffer --
643 -----------------------------
644
645 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
646 begin
647 if Ekind (Item_Id) = E_Abstract_State then
648 Add_Str_To_Name_Buffer ("state");
649
650 elsif Ekind (Item_Id) = E_Constant then
651 Add_Str_To_Name_Buffer ("constant");
652
653 elsif Ekind (Item_Id) = E_Discriminant then
654 Add_Str_To_Name_Buffer ("discriminant");
655
656 elsif Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
657 E_Generic_In_Parameter)
658 then
659 Add_Str_To_Name_Buffer ("generic parameter");
660
661 elsif Is_Formal (Item_Id) then
662 Add_Str_To_Name_Buffer ("parameter");
663
664 elsif Ekind (Item_Id) = E_Loop_Parameter then
665 Add_Str_To_Name_Buffer ("loop parameter");
666
667 elsif Ekind (Item_Id) = E_Protected_Type
668 or else Is_Single_Protected_Object (Item_Id)
669 then
670 Add_Str_To_Name_Buffer ("current instance of protected type");
671
672 elsif Ekind (Item_Id) = E_Task_Type
673 or else Is_Single_Task_Object (Item_Id)
674 then
675 Add_Str_To_Name_Buffer ("current instance of task type");
676
677 elsif Ekind (Item_Id) = E_Variable then
678 Add_Str_To_Name_Buffer ("global");
679
680 -- The routine should not be called with non-SPARK items
681
682 else
683 raise Program_Error;
684 end if;
685 end Add_Item_To_Name_Buffer;
686
687 -------------------------------
688 -- Analyze_Dependency_Clause --
689 -------------------------------
690
691 procedure Analyze_Dependency_Clause
692 (Clause : Node_Id;
693 Is_Last : Boolean)
694 is
695 procedure Analyze_Input_List (Inputs : Node_Id);
696 -- Verify the legality of a single input list
697
698 procedure Analyze_Input_Output
699 (Item : Node_Id;
700 Is_Input : Boolean;
701 Self_Ref : Boolean;
702 Top_Level : Boolean;
703 Seen : in out Elist_Id;
704 Null_Seen : in out Boolean;
705 Non_Null_Seen : in out Boolean);
706 -- Verify the legality of a single input or output item. Flag
707 -- Is_Input should be set whenever Item is an input, False when it
708 -- denotes an output. Flag Self_Ref should be set when the item is an
709 -- output and the dependency clause has a "+". Flag Top_Level should
710 -- be set whenever Item appears immediately within an input or output
711 -- list. Seen is a collection of all abstract states, objects and
712 -- formals processed so far. Flag Null_Seen denotes whether a null
713 -- input or output has been encountered. Flag Non_Null_Seen denotes
714 -- whether a non-null input or output has been encountered.
715
716 ------------------------
717 -- Analyze_Input_List --
718 ------------------------
719
720 procedure Analyze_Input_List (Inputs : Node_Id) is
721 Inputs_Seen : Elist_Id := No_Elist;
722 -- A list containing the entities of all inputs that appear in the
723 -- current input list.
724
725 Non_Null_Input_Seen : Boolean := False;
726 Null_Input_Seen : Boolean := False;
727 -- Flags used to check the legality of an input list
728
729 Input : Node_Id;
730
731 begin
732 -- Multiple inputs appear as an aggregate
733
734 if Nkind (Inputs) = N_Aggregate then
735 if Present (Component_Associations (Inputs)) then
736 SPARK_Msg_N
737 ("nested dependency relations not allowed", Inputs);
738
739 elsif Present (Expressions (Inputs)) then
740 Input := First (Expressions (Inputs));
741 while Present (Input) loop
742 Analyze_Input_Output
743 (Item => Input,
744 Is_Input => True,
745 Self_Ref => False,
746 Top_Level => False,
747 Seen => Inputs_Seen,
748 Null_Seen => Null_Input_Seen,
749 Non_Null_Seen => Non_Null_Input_Seen);
750
751 Next (Input);
752 end loop;
753
754 -- Syntax error, always report
755
756 else
757 Error_Msg_N ("malformed input dependency list", Inputs);
758 end if;
759
760 -- Process a solitary input
761
762 else
763 Analyze_Input_Output
764 (Item => Inputs,
765 Is_Input => True,
766 Self_Ref => False,
767 Top_Level => False,
768 Seen => Inputs_Seen,
769 Null_Seen => Null_Input_Seen,
770 Non_Null_Seen => Non_Null_Input_Seen);
771 end if;
772
773 -- Detect an illegal dependency clause of the form
774
775 -- (null =>[+] null)
776
777 if Null_Output_Seen and then Null_Input_Seen then
778 SPARK_Msg_N
779 ("null dependency clause cannot have a null input list",
780 Inputs);
781 end if;
782 end Analyze_Input_List;
783
784 --------------------------
785 -- Analyze_Input_Output --
786 --------------------------
787
788 procedure Analyze_Input_Output
789 (Item : Node_Id;
790 Is_Input : Boolean;
791 Self_Ref : Boolean;
792 Top_Level : Boolean;
793 Seen : in out Elist_Id;
794 Null_Seen : in out Boolean;
795 Non_Null_Seen : in out Boolean)
796 is
797 procedure Current_Task_Instance_Seen;
798 -- Set the appropriate global flag when the current instance of a
799 -- task unit is encountered.
800
801 --------------------------------
802 -- Current_Task_Instance_Seen --
803 --------------------------------
804
805 procedure Current_Task_Instance_Seen is
806 begin
807 if Is_Input then
808 Task_Input_Seen := True;
809 else
810 Task_Output_Seen := True;
811 end if;
812 end Current_Task_Instance_Seen;
813
814 -- Local variables
815
816 Is_Output : constant Boolean := not Is_Input;
817 Grouped : Node_Id;
818 Item_Id : Entity_Id;
819
820 -- Start of processing for Analyze_Input_Output
821
822 begin
823 -- Multiple input or output items appear as an aggregate
824
825 if Nkind (Item) = N_Aggregate then
826 if not Top_Level then
827 SPARK_Msg_N ("nested grouping of items not allowed", Item);
828
829 elsif Present (Component_Associations (Item)) then
830 SPARK_Msg_N
831 ("nested dependency relations not allowed", Item);
832
833 -- Recursively analyze the grouped items
834
835 elsif Present (Expressions (Item)) then
836 Grouped := First (Expressions (Item));
837 while Present (Grouped) loop
838 Analyze_Input_Output
839 (Item => Grouped,
840 Is_Input => Is_Input,
841 Self_Ref => Self_Ref,
842 Top_Level => False,
843 Seen => Seen,
844 Null_Seen => Null_Seen,
845 Non_Null_Seen => Non_Null_Seen);
846
847 Next (Grouped);
848 end loop;
849
850 -- Syntax error, always report
851
852 else
853 Error_Msg_N ("malformed dependency list", Item);
854 end if;
855
856 -- Process attribute 'Result in the context of a dependency clause
857
858 elsif Is_Attribute_Result (Item) then
859 Non_Null_Seen := True;
860
861 Analyze (Item);
862
863 -- Attribute 'Result is allowed to appear on the output side of
864 -- a dependency clause (SPARK RM 6.1.5(6)).
865
866 if Is_Input then
867 SPARK_Msg_N ("function result cannot act as input", Item);
868
869 elsif Null_Seen then
870 SPARK_Msg_N
871 ("cannot mix null and non-null dependency items", Item);
872
873 else
874 Result_Seen := True;
875 end if;
876
877 -- Detect multiple uses of null in a single dependency list or
878 -- throughout the whole relation. Verify the placement of a null
879 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
880
881 elsif Nkind (Item) = N_Null then
882 if Null_Seen then
883 SPARK_Msg_N
884 ("multiple null dependency relations not allowed", Item);
885
886 elsif Non_Null_Seen then
887 SPARK_Msg_N
888 ("cannot mix null and non-null dependency items", Item);
889
890 else
891 Null_Seen := True;
892
893 if Is_Output then
894 if not Is_Last then
895 SPARK_Msg_N
896 ("null output list must be the last clause in a "
897 & "dependency relation", Item);
898
899 -- Catch a useless dependence of the form:
900 -- null =>+ ...
901
902 elsif Self_Ref then
903 SPARK_Msg_N
904 ("useless dependence, null depends on itself", Item);
905 end if;
906 end if;
907 end if;
908
909 -- Default case
910
911 else
912 Non_Null_Seen := True;
913
914 if Null_Seen then
915 SPARK_Msg_N ("cannot mix null and non-null items", Item);
916 end if;
917
918 Analyze (Item);
919 Resolve_State (Item);
920
921 -- Find the entity of the item. If this is a renaming, climb
922 -- the renaming chain to reach the root object. Renamings of
923 -- non-entire objects do not yield an entity (Empty).
924
925 Item_Id := Entity_Of (Item);
926
927 if Present (Item_Id) then
928
929 -- Constants
930
931 if Ekind_In (Item_Id, E_Constant, E_Loop_Parameter)
932 or else
933
934 -- Current instances of concurrent types
935
936 Ekind_In (Item_Id, E_Protected_Type, E_Task_Type)
937 or else
938
939 -- Formal parameters
940
941 Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
942 E_Generic_In_Parameter,
943 E_In_Parameter,
944 E_In_Out_Parameter,
945 E_Out_Parameter)
946 or else
947
948 -- States, variables
949
950 Ekind_In (Item_Id, E_Abstract_State, E_Variable)
951 then
952 -- The item denotes a concurrent type. Note that single
953 -- protected/task types are not considered here because
954 -- they behave as objects in the context of pragma
955 -- [Refined_]Depends.
956
957 if Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
958
959 -- This use is legal as long as the concurrent type is
960 -- the current instance of an enclosing type.
961
962 if Is_CCT_Instance (Item_Id, Spec_Id) then
963
964 -- The dependence of a task unit on itself is
965 -- implicit and may or may not be explicitly
966 -- specified (SPARK RM 6.1.4).
967
968 if Ekind (Item_Id) = E_Task_Type then
969 Current_Task_Instance_Seen;
970 end if;
971
972 -- Otherwise this is not the current instance
973
974 else
975 SPARK_Msg_N
976 ("invalid use of subtype mark in dependency "
977 & "relation", Item);
978 end if;
979
980 -- The dependency of a task unit on itself is implicit
981 -- and may or may not be explicitly specified
982 -- (SPARK RM 6.1.4).
983
984 elsif Is_Single_Task_Object (Item_Id)
985 and then Is_CCT_Instance (Item_Id, Spec_Id)
986 then
987 Current_Task_Instance_Seen;
988 end if;
989
990 -- Ensure that the item fulfills its role as input and/or
991 -- output as specified by pragma Global or the enclosing
992 -- context.
993
994 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
995
996 -- Detect multiple uses of the same state, variable or
997 -- formal parameter. If this is not the case, add the
998 -- item to the list of processed relations.
999
1000 if Contains (Seen, Item_Id) then
1001 SPARK_Msg_NE
1002 ("duplicate use of item &", Item, Item_Id);
1003 else
1004 Append_New_Elmt (Item_Id, Seen);
1005 end if;
1006
1007 -- Detect illegal use of an input related to a null
1008 -- output. Such input items cannot appear in other
1009 -- input lists (SPARK RM 6.1.5(13)).
1010
1011 if Is_Input
1012 and then Null_Output_Seen
1013 and then Contains (All_Inputs_Seen, Item_Id)
1014 then
1015 SPARK_Msg_N
1016 ("input of a null output list cannot appear in "
1017 & "multiple input lists", Item);
1018 end if;
1019
1020 -- Add an input or a self-referential output to the list
1021 -- of all processed inputs.
1022
1023 if Is_Input or else Self_Ref then
1024 Append_New_Elmt (Item_Id, All_Inputs_Seen);
1025 end if;
1026
1027 -- State related checks (SPARK RM 6.1.5(3))
1028
1029 if Ekind (Item_Id) = E_Abstract_State then
1030
1031 -- Package and subprogram bodies are instantiated
1032 -- individually in a separate compiler pass. Due to
1033 -- this mode of instantiation, the refinement of a
1034 -- state may no longer be visible when a subprogram
1035 -- body contract is instantiated. Since the generic
1036 -- template is legal, do not perform this check in
1037 -- the instance to circumvent this oddity.
1038
1039 if Is_Generic_Instance (Spec_Id) then
1040 null;
1041
1042 -- An abstract state with visible refinement cannot
1043 -- appear in pragma [Refined_]Depends as its place
1044 -- must be taken by some of its constituents
1045 -- (SPARK RM 6.1.4(7)).
1046
1047 elsif Has_Visible_Refinement (Item_Id) then
1048 SPARK_Msg_NE
1049 ("cannot mention state & in dependence relation",
1050 Item, Item_Id);
1051 SPARK_Msg_N ("\use its constituents instead", Item);
1052 return;
1053
1054 -- If the reference to the abstract state appears in
1055 -- an enclosing package body that will eventually
1056 -- refine the state, record the reference for future
1057 -- checks.
1058
1059 else
1060 Record_Possible_Body_Reference
1061 (State_Id => Item_Id,
1062 Ref => Item);
1063 end if;
1064 end if;
1065
1066 -- When the item renames an entire object, replace the
1067 -- item with a reference to the object.
1068
1069 if Entity (Item) /= Item_Id then
1070 Rewrite (Item,
1071 New_Occurrence_Of (Item_Id, Sloc (Item)));
1072 Analyze (Item);
1073 end if;
1074
1075 -- Add the entity of the current item to the list of
1076 -- processed items.
1077
1078 if Ekind (Item_Id) = E_Abstract_State then
1079 Append_New_Elmt (Item_Id, States_Seen);
1080
1081 -- The variable may eventually become a constituent of a
1082 -- single protected/task type. Record the reference now
1083 -- and verify its legality when analyzing the contract of
1084 -- the variable (SPARK RM 9.3).
1085
1086 elsif Ekind (Item_Id) = E_Variable then
1087 Record_Possible_Part_Of_Reference
1088 (Var_Id => Item_Id,
1089 Ref => Item);
1090 end if;
1091
1092 if Ekind_In (Item_Id, E_Abstract_State,
1093 E_Constant,
1094 E_Variable)
1095 and then Present (Encapsulating_State (Item_Id))
1096 then
1097 Append_New_Elmt (Item_Id, Constits_Seen);
1098 end if;
1099
1100 -- All other input/output items are illegal
1101 -- (SPARK RM 6.1.5(1)).
1102
1103 else
1104 SPARK_Msg_N
1105 ("item must denote parameter, variable, state or "
1106 & "current instance of concurren type", Item);
1107 end if;
1108
1109 -- All other input/output items are illegal
1110 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1111
1112 else
1113 Error_Msg_N
1114 ("item must denote parameter, variable, state or current "
1115 & "instance of concurrent type", Item);
1116 end if;
1117 end if;
1118 end Analyze_Input_Output;
1119
1120 -- Local variables
1121
1122 Inputs : Node_Id;
1123 Output : Node_Id;
1124 Self_Ref : Boolean;
1125
1126 Non_Null_Output_Seen : Boolean := False;
1127 -- Flag used to check the legality of an output list
1128
1129 -- Start of processing for Analyze_Dependency_Clause
1130
1131 begin
1132 Inputs := Expression (Clause);
1133 Self_Ref := False;
1134
1135 -- An input list with a self-dependency appears as operator "+" where
1136 -- the actuals inputs are the right operand.
1137
1138 if Nkind (Inputs) = N_Op_Plus then
1139 Inputs := Right_Opnd (Inputs);
1140 Self_Ref := True;
1141 end if;
1142
1143 -- Process the output_list of a dependency_clause
1144
1145 Output := First (Choices (Clause));
1146 while Present (Output) loop
1147 Analyze_Input_Output
1148 (Item => Output,
1149 Is_Input => False,
1150 Self_Ref => Self_Ref,
1151 Top_Level => True,
1152 Seen => All_Outputs_Seen,
1153 Null_Seen => Null_Output_Seen,
1154 Non_Null_Seen => Non_Null_Output_Seen);
1155
1156 Next (Output);
1157 end loop;
1158
1159 -- Process the input_list of a dependency_clause
1160
1161 Analyze_Input_List (Inputs);
1162 end Analyze_Dependency_Clause;
1163
1164 ---------------------------
1165 -- Check_Function_Return --
1166 ---------------------------
1167
1168 procedure Check_Function_Return is
1169 begin
1170 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
1171 and then not Result_Seen
1172 then
1173 SPARK_Msg_NE
1174 ("result of & must appear in exactly one output list",
1175 N, Spec_Id);
1176 end if;
1177 end Check_Function_Return;
1178
1179 ----------------
1180 -- Check_Role --
1181 ----------------
1182
1183 procedure Check_Role
1184 (Item : Node_Id;
1185 Item_Id : Entity_Id;
1186 Is_Input : Boolean;
1187 Self_Ref : Boolean)
1188 is
1189 procedure Find_Role
1190 (Item_Is_Input : out Boolean;
1191 Item_Is_Output : out Boolean);
1192 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1193 -- Item_Is_Output are set depending on the role.
1194
1195 procedure Role_Error
1196 (Item_Is_Input : Boolean;
1197 Item_Is_Output : Boolean);
1198 -- Emit an error message concerning the incorrect use of Item in
1199 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1200 -- denote whether the item is an input and/or an output.
1201
1202 ---------------
1203 -- Find_Role --
1204 ---------------
1205
1206 procedure Find_Role
1207 (Item_Is_Input : out Boolean;
1208 Item_Is_Output : out Boolean)
1209 is
1210 begin
1211 Item_Is_Input := False;
1212 Item_Is_Output := False;
1213
1214 -- Abstract states
1215
1216 if Ekind (Item_Id) = E_Abstract_State then
1217
1218 -- When pragma Global is present, the mode of the state may be
1219 -- further constrained by setting a more restrictive mode.
1220
1221 if Global_Seen then
1222 if Appears_In (Subp_Inputs, Item_Id) then
1223 Item_Is_Input := True;
1224 end if;
1225
1226 if Appears_In (Subp_Outputs, Item_Id) then
1227 Item_Is_Output := True;
1228 end if;
1229
1230 -- Otherwise the state has a default IN OUT mode
1231
1232 else
1233 Item_Is_Input := True;
1234 Item_Is_Output := True;
1235 end if;
1236
1237 -- Constants
1238
1239 elsif Ekind_In (Item_Id, E_Constant,
1240 E_Discriminant,
1241 E_Loop_Parameter)
1242 then
1243 Item_Is_Input := True;
1244
1245 -- Parameters
1246
1247 elsif Ekind_In (Item_Id, E_Generic_In_Parameter,
1248 E_In_Parameter)
1249 then
1250 Item_Is_Input := True;
1251
1252 elsif Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
1253 E_In_Out_Parameter)
1254 then
1255 Item_Is_Input := True;
1256 Item_Is_Output := True;
1257
1258 elsif Ekind (Item_Id) = E_Out_Parameter then
1259 if Scope (Item_Id) = Spec_Id then
1260
1261 -- An OUT parameter of the related subprogram has mode IN
1262 -- if its type is unconstrained or tagged because array
1263 -- bounds, discriminants or tags can be read.
1264
1265 if Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1266 Item_Is_Input := True;
1267 end if;
1268
1269 Item_Is_Output := True;
1270
1271 -- An OUT parameter of an enclosing subprogram behaves as a
1272 -- read-write variable in which case the mode is IN OUT.
1273
1274 else
1275 Item_Is_Input := True;
1276 Item_Is_Output := True;
1277 end if;
1278
1279 -- Protected types
1280
1281 elsif Ekind (Item_Id) = E_Protected_Type then
1282
1283 -- A protected type acts as a formal parameter of mode IN when
1284 -- it applies to a protected function.
1285
1286 if Ekind (Spec_Id) = E_Function then
1287 Item_Is_Input := True;
1288
1289 -- Otherwise the protected type acts as a formal of mode IN OUT
1290
1291 else
1292 Item_Is_Input := True;
1293 Item_Is_Output := True;
1294 end if;
1295
1296 -- Task types
1297
1298 elsif Ekind (Item_Id) = E_Task_Type then
1299 Item_Is_Input := True;
1300 Item_Is_Output := True;
1301
1302 -- Variable case
1303
1304 else pragma Assert (Ekind (Item_Id) = E_Variable);
1305
1306 -- When pragma Global is present, the mode of the variable may
1307 -- be further constrained by setting a more restrictive mode.
1308
1309 if Global_Seen then
1310
1311 -- A variable has mode IN when its type is unconstrained or
1312 -- tagged because array bounds, discriminants or tags can be
1313 -- read.
1314
1315 if Appears_In (Subp_Inputs, Item_Id)
1316 or else Is_Unconstrained_Or_Tagged_Item (Item_Id)
1317 then
1318 Item_Is_Input := True;
1319 end if;
1320
1321 if Appears_In (Subp_Outputs, Item_Id) then
1322 Item_Is_Output := True;
1323 end if;
1324
1325 -- Otherwise the variable has a default IN OUT mode
1326
1327 else
1328 Item_Is_Input := True;
1329 Item_Is_Output := True;
1330 end if;
1331 end if;
1332 end Find_Role;
1333
1334 ----------------
1335 -- Role_Error --
1336 ----------------
1337
1338 procedure Role_Error
1339 (Item_Is_Input : Boolean;
1340 Item_Is_Output : Boolean)
1341 is
1342 Error_Msg : Name_Id;
1343
1344 begin
1345 Name_Len := 0;
1346
1347 -- When the item is not part of the input and the output set of
1348 -- the related subprogram, then it appears as extra in pragma
1349 -- [Refined_]Depends.
1350
1351 if not Item_Is_Input and then not Item_Is_Output then
1352 Add_Item_To_Name_Buffer (Item_Id);
1353 Add_Str_To_Name_Buffer
1354 (" & cannot appear in dependence relation");
1355
1356 Error_Msg := Name_Find;
1357 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1358
1359 Error_Msg_Name_1 := Chars (Spec_Id);
1360 SPARK_Msg_NE
1361 (Fix_Msg (Spec_Id, "\& is not part of the input or output "
1362 & "set of subprogram %"), Item, Item_Id);
1363
1364 -- The mode of the item and its role in pragma [Refined_]Depends
1365 -- are in conflict. Construct a detailed message explaining the
1366 -- illegality (SPARK RM 6.1.5(5-6)).
1367
1368 else
1369 if Item_Is_Input then
1370 Add_Str_To_Name_Buffer ("read-only");
1371 else
1372 Add_Str_To_Name_Buffer ("write-only");
1373 end if;
1374
1375 Add_Char_To_Name_Buffer (' ');
1376 Add_Item_To_Name_Buffer (Item_Id);
1377 Add_Str_To_Name_Buffer (" & cannot appear as ");
1378
1379 if Item_Is_Input then
1380 Add_Str_To_Name_Buffer ("output");
1381 else
1382 Add_Str_To_Name_Buffer ("input");
1383 end if;
1384
1385 Add_Str_To_Name_Buffer (" in dependence relation");
1386 Error_Msg := Name_Find;
1387 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1388 end if;
1389 end Role_Error;
1390
1391 -- Local variables
1392
1393 Item_Is_Input : Boolean;
1394 Item_Is_Output : Boolean;
1395
1396 -- Start of processing for Check_Role
1397
1398 begin
1399 Find_Role (Item_Is_Input, Item_Is_Output);
1400
1401 -- Input item
1402
1403 if Is_Input then
1404 if not Item_Is_Input then
1405 Role_Error (Item_Is_Input, Item_Is_Output);
1406 end if;
1407
1408 -- Self-referential item
1409
1410 elsif Self_Ref then
1411 if not Item_Is_Input or else not Item_Is_Output then
1412 Role_Error (Item_Is_Input, Item_Is_Output);
1413 end if;
1414
1415 -- Output item
1416
1417 elsif not Item_Is_Output then
1418 Role_Error (Item_Is_Input, Item_Is_Output);
1419 end if;
1420 end Check_Role;
1421
1422 -----------------
1423 -- Check_Usage --
1424 -----------------
1425
1426 procedure Check_Usage
1427 (Subp_Items : Elist_Id;
1428 Used_Items : Elist_Id;
1429 Is_Input : Boolean)
1430 is
1431 procedure Usage_Error (Item_Id : Entity_Id);
1432 -- Emit an error concerning the illegal usage of an item
1433
1434 -----------------
1435 -- Usage_Error --
1436 -----------------
1437
1438 procedure Usage_Error (Item_Id : Entity_Id) is
1439 Error_Msg : Name_Id;
1440
1441 begin
1442 -- Input case
1443
1444 if Is_Input then
1445
1446 -- Unconstrained and tagged items are not part of the explicit
1447 -- input set of the related subprogram, they do not have to be
1448 -- present in a dependence relation and should not be flagged
1449 -- (SPARK RM 6.1.5(8)).
1450
1451 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1452 Name_Len := 0;
1453
1454 Add_Item_To_Name_Buffer (Item_Id);
1455 Add_Str_To_Name_Buffer
1456 (" & is missing from input dependence list");
1457
1458 Error_Msg := Name_Find;
1459 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1460 SPARK_Msg_NE
1461 ("\add `null ='> &` dependency to ignore this input",
1462 N, Item_Id);
1463 end if;
1464
1465 -- Output case (SPARK RM 6.1.5(10))
1466
1467 else
1468 Name_Len := 0;
1469
1470 Add_Item_To_Name_Buffer (Item_Id);
1471 Add_Str_To_Name_Buffer
1472 (" & is missing from output dependence list");
1473
1474 Error_Msg := Name_Find;
1475 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1476 end if;
1477 end Usage_Error;
1478
1479 -- Local variables
1480
1481 Elmt : Elmt_Id;
1482 Item : Node_Id;
1483 Item_Id : Entity_Id;
1484
1485 -- Start of processing for Check_Usage
1486
1487 begin
1488 if No (Subp_Items) then
1489 return;
1490 end if;
1491
1492 -- Each input or output of the subprogram must appear in a dependency
1493 -- relation.
1494
1495 Elmt := First_Elmt (Subp_Items);
1496 while Present (Elmt) loop
1497 Item := Node (Elmt);
1498
1499 if Nkind (Item) = N_Defining_Identifier then
1500 Item_Id := Item;
1501 else
1502 Item_Id := Entity_Of (Item);
1503 end if;
1504
1505 -- The item does not appear in a dependency
1506
1507 if Present (Item_Id)
1508 and then not Contains (Used_Items, Item_Id)
1509 then
1510 if Is_Formal (Item_Id) then
1511 Usage_Error (Item_Id);
1512
1513 -- The current instance of a protected type behaves as a formal
1514 -- parameter (SPARK RM 6.1.4).
1515
1516 elsif Ekind (Item_Id) = E_Protected_Type
1517 or else Is_Single_Protected_Object (Item_Id)
1518 then
1519 Usage_Error (Item_Id);
1520
1521 -- The current instance of a task type behaves as a formal
1522 -- parameter (SPARK RM 6.1.4).
1523
1524 elsif Ekind (Item_Id) = E_Task_Type
1525 or else Is_Single_Task_Object (Item_Id)
1526 then
1527 -- The dependence of a task unit on itself is implicit and
1528 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1529 -- Emit an error if only one input/output is present.
1530
1531 if Task_Input_Seen /= Task_Output_Seen then
1532 Usage_Error (Item_Id);
1533 end if;
1534
1535 -- States and global objects are not used properly only when
1536 -- the subprogram is subject to pragma Global.
1537
1538 elsif Global_Seen then
1539 Usage_Error (Item_Id);
1540 end if;
1541 end if;
1542
1543 Next_Elmt (Elmt);
1544 end loop;
1545 end Check_Usage;
1546
1547 ----------------------
1548 -- Normalize_Clause --
1549 ----------------------
1550
1551 procedure Normalize_Clause (Clause : Node_Id) is
1552 procedure Create_Or_Modify_Clause
1553 (Output : Node_Id;
1554 Outputs : Node_Id;
1555 Inputs : Node_Id;
1556 After : Node_Id;
1557 In_Place : Boolean;
1558 Multiple : Boolean);
1559 -- Create a brand new clause to represent the self-reference or
1560 -- modify the input and/or output lists of an existing clause. Output
1561 -- denotes a self-referencial output. Outputs is the output list of a
1562 -- clause. Inputs is the input list of a clause. After denotes the
1563 -- clause after which the new clause is to be inserted. Flag In_Place
1564 -- should be set when normalizing the last output of an output list.
1565 -- Flag Multiple should be set when Output comes from a list with
1566 -- multiple items.
1567
1568 -----------------------------
1569 -- Create_Or_Modify_Clause --
1570 -----------------------------
1571
1572 procedure Create_Or_Modify_Clause
1573 (Output : Node_Id;
1574 Outputs : Node_Id;
1575 Inputs : Node_Id;
1576 After : Node_Id;
1577 In_Place : Boolean;
1578 Multiple : Boolean)
1579 is
1580 procedure Propagate_Output
1581 (Output : Node_Id;
1582 Inputs : Node_Id);
1583 -- Handle the various cases of output propagation to the input
1584 -- list. Output denotes a self-referencial output item. Inputs
1585 -- is the input list of a clause.
1586
1587 ----------------------
1588 -- Propagate_Output --
1589 ----------------------
1590
1591 procedure Propagate_Output
1592 (Output : Node_Id;
1593 Inputs : Node_Id)
1594 is
1595 function In_Input_List
1596 (Item : Entity_Id;
1597 Inputs : List_Id) return Boolean;
1598 -- Determine whether a particulat item appears in the input
1599 -- list of a clause.
1600
1601 -------------------
1602 -- In_Input_List --
1603 -------------------
1604
1605 function In_Input_List
1606 (Item : Entity_Id;
1607 Inputs : List_Id) return Boolean
1608 is
1609 Elmt : Node_Id;
1610
1611 begin
1612 Elmt := First (Inputs);
1613 while Present (Elmt) loop
1614 if Entity_Of (Elmt) = Item then
1615 return True;
1616 end if;
1617
1618 Next (Elmt);
1619 end loop;
1620
1621 return False;
1622 end In_Input_List;
1623
1624 -- Local variables
1625
1626 Output_Id : constant Entity_Id := Entity_Of (Output);
1627 Grouped : List_Id;
1628
1629 -- Start of processing for Propagate_Output
1630
1631 begin
1632 -- The clause is of the form:
1633
1634 -- (Output =>+ null)
1635
1636 -- Remove null input and replace it with a copy of the output:
1637
1638 -- (Output => Output)
1639
1640 if Nkind (Inputs) = N_Null then
1641 Rewrite (Inputs, New_Copy_Tree (Output));
1642
1643 -- The clause is of the form:
1644
1645 -- (Output =>+ (Input1, ..., InputN))
1646
1647 -- Determine whether the output is not already mentioned in the
1648 -- input list and if not, add it to the list of inputs:
1649
1650 -- (Output => (Output, Input1, ..., InputN))
1651
1652 elsif Nkind (Inputs) = N_Aggregate then
1653 Grouped := Expressions (Inputs);
1654
1655 if not In_Input_List
1656 (Item => Output_Id,
1657 Inputs => Grouped)
1658 then
1659 Prepend_To (Grouped, New_Copy_Tree (Output));
1660 end if;
1661
1662 -- The clause is of the form:
1663
1664 -- (Output =>+ Input)
1665
1666 -- If the input does not mention the output, group the two
1667 -- together:
1668
1669 -- (Output => (Output, Input))
1670
1671 elsif Entity_Of (Inputs) /= Output_Id then
1672 Rewrite (Inputs,
1673 Make_Aggregate (Loc,
1674 Expressions => New_List (
1675 New_Copy_Tree (Output),
1676 New_Copy_Tree (Inputs))));
1677 end if;
1678 end Propagate_Output;
1679
1680 -- Local variables
1681
1682 Loc : constant Source_Ptr := Sloc (Clause);
1683 New_Clause : Node_Id;
1684
1685 -- Start of processing for Create_Or_Modify_Clause
1686
1687 begin
1688 -- A null output depending on itself does not require any
1689 -- normalization.
1690
1691 if Nkind (Output) = N_Null then
1692 return;
1693
1694 -- A function result cannot depend on itself because it cannot
1695 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1696
1697 elsif Is_Attribute_Result (Output) then
1698 SPARK_Msg_N ("function result cannot depend on itself", Output);
1699 return;
1700 end if;
1701
1702 -- When performing the transformation in place, simply add the
1703 -- output to the list of inputs (if not already there). This
1704 -- case arises when dealing with the last output of an output
1705 -- list. Perform the normalization in place to avoid generating
1706 -- a malformed tree.
1707
1708 if In_Place then
1709 Propagate_Output (Output, Inputs);
1710
1711 -- A list with multiple outputs is slowly trimmed until only
1712 -- one element remains. When this happens, replace aggregate
1713 -- with the element itself.
1714
1715 if Multiple then
1716 Remove (Output);
1717 Rewrite (Outputs, Output);
1718 end if;
1719
1720 -- Default case
1721
1722 else
1723 -- Unchain the output from its output list as it will appear in
1724 -- a new clause. Note that we cannot simply rewrite the output
1725 -- as null because this will violate the semantics of pragma
1726 -- Depends.
1727
1728 Remove (Output);
1729
1730 -- Generate a new clause of the form:
1731 -- (Output => Inputs)
1732
1733 New_Clause :=
1734 Make_Component_Association (Loc,
1735 Choices => New_List (Output),
1736 Expression => New_Copy_Tree (Inputs));
1737
1738 -- The new clause contains replicated content that has already
1739 -- been analyzed. There is not need to reanalyze or renormalize
1740 -- it again.
1741
1742 Set_Analyzed (New_Clause);
1743
1744 Propagate_Output
1745 (Output => First (Choices (New_Clause)),
1746 Inputs => Expression (New_Clause));
1747
1748 Insert_After (After, New_Clause);
1749 end if;
1750 end Create_Or_Modify_Clause;
1751
1752 -- Local variables
1753
1754 Outputs : constant Node_Id := First (Choices (Clause));
1755 Inputs : Node_Id;
1756 Last_Output : Node_Id;
1757 Next_Output : Node_Id;
1758 Output : Node_Id;
1759
1760 -- Start of processing for Normalize_Clause
1761
1762 begin
1763 -- A self-dependency appears as operator "+". Remove the "+" from the
1764 -- tree by moving the real inputs to their proper place.
1765
1766 if Nkind (Expression (Clause)) = N_Op_Plus then
1767 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1768 Inputs := Expression (Clause);
1769
1770 -- Multiple outputs appear as an aggregate
1771
1772 if Nkind (Outputs) = N_Aggregate then
1773 Last_Output := Last (Expressions (Outputs));
1774
1775 Output := First (Expressions (Outputs));
1776 while Present (Output) loop
1777
1778 -- Normalization may remove an output from its list,
1779 -- preserve the subsequent output now.
1780
1781 Next_Output := Next (Output);
1782
1783 Create_Or_Modify_Clause
1784 (Output => Output,
1785 Outputs => Outputs,
1786 Inputs => Inputs,
1787 After => Clause,
1788 In_Place => Output = Last_Output,
1789 Multiple => True);
1790
1791 Output := Next_Output;
1792 end loop;
1793
1794 -- Solitary output
1795
1796 else
1797 Create_Or_Modify_Clause
1798 (Output => Outputs,
1799 Outputs => Empty,
1800 Inputs => Inputs,
1801 After => Empty,
1802 In_Place => True,
1803 Multiple => False);
1804 end if;
1805 end if;
1806 end Normalize_Clause;
1807
1808 -- Local variables
1809
1810 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
1811 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1812
1813 Clause : Node_Id;
1814 Errors : Nat;
1815 Last_Clause : Node_Id;
1816 Restore_Scope : Boolean := False;
1817
1818 -- Start of processing for Analyze_Depends_In_Decl_Part
1819
1820 begin
1821 -- Do not analyze the pragma multiple times
1822
1823 if Is_Analyzed_Pragma (N) then
1824 return;
1825 end if;
1826
1827 -- Empty dependency list
1828
1829 if Nkind (Deps) = N_Null then
1830
1831 -- Gather all states, objects and formal parameters that the
1832 -- subprogram may depend on. These items are obtained from the
1833 -- parameter profile or pragma [Refined_]Global (if available).
1834
1835 Collect_Subprogram_Inputs_Outputs
1836 (Subp_Id => Subp_Id,
1837 Subp_Inputs => Subp_Inputs,
1838 Subp_Outputs => Subp_Outputs,
1839 Global_Seen => Global_Seen);
1840
1841 -- Verify that every input or output of the subprogram appear in a
1842 -- dependency.
1843
1844 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1845 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1846 Check_Function_Return;
1847
1848 -- Dependency clauses appear as component associations of an aggregate
1849
1850 elsif Nkind (Deps) = N_Aggregate then
1851
1852 -- Do not attempt to perform analysis of a syntactically illegal
1853 -- clause as this will lead to misleading errors.
1854
1855 if Has_Extra_Parentheses (Deps) then
1856 return;
1857 end if;
1858
1859 if Present (Component_Associations (Deps)) then
1860 Last_Clause := Last (Component_Associations (Deps));
1861
1862 -- Gather all states, objects and formal parameters that the
1863 -- subprogram may depend on. These items are obtained from the
1864 -- parameter profile or pragma [Refined_]Global (if available).
1865
1866 Collect_Subprogram_Inputs_Outputs
1867 (Subp_Id => Subp_Id,
1868 Subp_Inputs => Subp_Inputs,
1869 Subp_Outputs => Subp_Outputs,
1870 Global_Seen => Global_Seen);
1871
1872 -- When pragma [Refined_]Depends appears on a single concurrent
1873 -- type, it is relocated to the anonymous object.
1874
1875 if Is_Single_Concurrent_Object (Spec_Id) then
1876 null;
1877
1878 -- Ensure that the formal parameters are visible when analyzing
1879 -- all clauses. This falls out of the general rule of aspects
1880 -- pertaining to subprogram declarations.
1881
1882 elsif not In_Open_Scopes (Spec_Id) then
1883 Restore_Scope := True;
1884 Push_Scope (Spec_Id);
1885
1886 if Ekind (Spec_Id) = E_Task_Type then
1887 if Has_Discriminants (Spec_Id) then
1888 Install_Discriminants (Spec_Id);
1889 end if;
1890
1891 elsif Is_Generic_Subprogram (Spec_Id) then
1892 Install_Generic_Formals (Spec_Id);
1893
1894 else
1895 Install_Formals (Spec_Id);
1896 end if;
1897 end if;
1898
1899 Clause := First (Component_Associations (Deps));
1900 while Present (Clause) loop
1901 Errors := Serious_Errors_Detected;
1902
1903 -- The normalization mechanism may create extra clauses that
1904 -- contain replicated input and output names. There is no need
1905 -- to reanalyze them.
1906
1907 if not Analyzed (Clause) then
1908 Set_Analyzed (Clause);
1909
1910 Analyze_Dependency_Clause
1911 (Clause => Clause,
1912 Is_Last => Clause = Last_Clause);
1913 end if;
1914
1915 -- Do not normalize a clause if errors were detected (count
1916 -- of Serious_Errors has increased) because the inputs and/or
1917 -- outputs may denote illegal items. Normalization is disabled
1918 -- in ASIS mode as it alters the tree by introducing new nodes
1919 -- similar to expansion.
1920
1921 if Serious_Errors_Detected = Errors and then not ASIS_Mode then
1922 Normalize_Clause (Clause);
1923 end if;
1924
1925 Next (Clause);
1926 end loop;
1927
1928 if Restore_Scope then
1929 End_Scope;
1930 end if;
1931
1932 -- Verify that every input or output of the subprogram appear in a
1933 -- dependency.
1934
1935 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1936 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1937 Check_Function_Return;
1938
1939 -- The dependency list is malformed. This is a syntax error, always
1940 -- report.
1941
1942 else
1943 Error_Msg_N ("malformed dependency relation", Deps);
1944 return;
1945 end if;
1946
1947 -- The top level dependency relation is malformed. This is a syntax
1948 -- error, always report.
1949
1950 else
1951 Error_Msg_N ("malformed dependency relation", Deps);
1952 goto Leave;
1953 end if;
1954
1955 -- Ensure that a state and a corresponding constituent do not appear
1956 -- together in pragma [Refined_]Depends.
1957
1958 Check_State_And_Constituent_Use
1959 (States => States_Seen,
1960 Constits => Constits_Seen,
1961 Context => N);
1962
1963 <<Leave>>
1964 Set_Is_Analyzed_Pragma (N);
1965 end Analyze_Depends_In_Decl_Part;
1966
1967 --------------------------------------------
1968 -- Analyze_External_Property_In_Decl_Part --
1969 --------------------------------------------
1970
1971 procedure Analyze_External_Property_In_Decl_Part
1972 (N : Node_Id;
1973 Expr_Val : out Boolean)
1974 is
1975 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
1976 Obj_Decl : constant Node_Id := Find_Related_Context (N);
1977 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
1978 Expr : Node_Id;
1979
1980 begin
1981 Expr_Val := False;
1982
1983 -- Do not analyze the pragma multiple times
1984
1985 if Is_Analyzed_Pragma (N) then
1986 return;
1987 end if;
1988
1989 Error_Msg_Name_1 := Pragma_Name (N);
1990
1991 -- An external property pragma must apply to an effectively volatile
1992 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
1993 -- The check is performed at the end of the declarative region due to a
1994 -- possible out-of-order arrangement of pragmas:
1995
1996 -- Obj : ...;
1997 -- pragma Async_Readers (Obj);
1998 -- pragma Volatile (Obj);
1999
2000 if not Is_Effectively_Volatile (Obj_Id) then
2001 SPARK_Msg_N
2002 ("external property % must apply to a volatile object", N);
2003 end if;
2004
2005 -- Ensure that the Boolean expression (if present) is static. A missing
2006 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2007
2008 Expr_Val := True;
2009
2010 if Present (Arg1) then
2011 Expr := Get_Pragma_Arg (Arg1);
2012
2013 if Is_OK_Static_Expression (Expr) then
2014 Expr_Val := Is_True (Expr_Value (Expr));
2015 end if;
2016 end if;
2017
2018 Set_Is_Analyzed_Pragma (N);
2019 end Analyze_External_Property_In_Decl_Part;
2020
2021 ---------------------------------
2022 -- Analyze_Global_In_Decl_Part --
2023 ---------------------------------
2024
2025 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
2026 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2027 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2028 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2029
2030 Constits_Seen : Elist_Id := No_Elist;
2031 -- A list containing the entities of all constituents processed so far.
2032 -- It aids in detecting illegal usage of a state and a corresponding
2033 -- constituent in pragma [Refinde_]Global.
2034
2035 Seen : Elist_Id := No_Elist;
2036 -- A list containing the entities of all the items processed so far. It
2037 -- plays a role in detecting distinct entities.
2038
2039 States_Seen : Elist_Id := No_Elist;
2040 -- A list containing the entities of all states processed so far. It
2041 -- helps in detecting illegal usage of a state and a corresponding
2042 -- constituent in pragma [Refined_]Global.
2043
2044 In_Out_Seen : Boolean := False;
2045 Input_Seen : Boolean := False;
2046 Output_Seen : Boolean := False;
2047 Proof_Seen : Boolean := False;
2048 -- Flags used to verify the consistency of modes
2049
2050 procedure Analyze_Global_List
2051 (List : Node_Id;
2052 Global_Mode : Name_Id := Name_Input);
2053 -- Verify the legality of a single global list declaration. Global_Mode
2054 -- denotes the current mode in effect.
2055
2056 -------------------------
2057 -- Analyze_Global_List --
2058 -------------------------
2059
2060 procedure Analyze_Global_List
2061 (List : Node_Id;
2062 Global_Mode : Name_Id := Name_Input)
2063 is
2064 procedure Analyze_Global_Item
2065 (Item : Node_Id;
2066 Global_Mode : Name_Id);
2067 -- Verify the legality of a single global item declaration denoted by
2068 -- Item. Global_Mode denotes the current mode in effect.
2069
2070 procedure Check_Duplicate_Mode
2071 (Mode : Node_Id;
2072 Status : in out Boolean);
2073 -- Flag Status denotes whether a particular mode has been seen while
2074 -- processing a global list. This routine verifies that Mode is not a
2075 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2076
2077 procedure Check_Mode_Restriction_In_Enclosing_Context
2078 (Item : Node_Id;
2079 Item_Id : Entity_Id);
2080 -- Verify that an item of mode In_Out or Output does not appear as an
2081 -- input in the Global aspect of an enclosing subprogram. If this is
2082 -- the case, emit an error. Item and Item_Id are respectively the
2083 -- item and its entity.
2084
2085 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
2086 -- Mode denotes either In_Out or Output. Depending on the kind of the
2087 -- related subprogram, emit an error if those two modes apply to a
2088 -- function (SPARK RM 6.1.4(10)).
2089
2090 -------------------------
2091 -- Analyze_Global_Item --
2092 -------------------------
2093
2094 procedure Analyze_Global_Item
2095 (Item : Node_Id;
2096 Global_Mode : Name_Id)
2097 is
2098 Item_Id : Entity_Id;
2099
2100 begin
2101 -- Detect one of the following cases
2102
2103 -- with Global => (null, Name)
2104 -- with Global => (Name_1, null, Name_2)
2105 -- with Global => (Name, null)
2106
2107 if Nkind (Item) = N_Null then
2108 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
2109 return;
2110 end if;
2111
2112 Analyze (Item);
2113 Resolve_State (Item);
2114
2115 -- Find the entity of the item. If this is a renaming, climb the
2116 -- renaming chain to reach the root object. Renamings of non-
2117 -- entire objects do not yield an entity (Empty).
2118
2119 Item_Id := Entity_Of (Item);
2120
2121 if Present (Item_Id) then
2122
2123 -- A global item may denote a formal parameter of an enclosing
2124 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2125 -- provide a better error diagnostic.
2126
2127 if Is_Formal (Item_Id) then
2128 if Scope (Item_Id) = Spec_Id then
2129 SPARK_Msg_NE
2130 (Fix_Msg (Spec_Id, "global item cannot reference "
2131 & "parameter of subprogram &"), Item, Spec_Id);
2132 return;
2133 end if;
2134
2135 -- A global item may denote a concurrent type as long as it is
2136 -- the current instance of an enclosing protected or task type
2137 -- (SPARK RM 6.1.4).
2138
2139 elsif Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
2140 if Is_CCT_Instance (Item_Id, Spec_Id) then
2141
2142 -- Pragma [Refined_]Global associated with a protected
2143 -- subprogram cannot mention the current instance of a
2144 -- protected type because the instance behaves as a
2145 -- formal parameter.
2146
2147 if Ekind (Item_Id) = E_Protected_Type then
2148 Error_Msg_Name_1 := Chars (Item_Id);
2149 SPARK_Msg_NE
2150 (Fix_Msg (Spec_Id, "global item of subprogram & "
2151 & "cannot reference current instance of protected "
2152 & "type %"), Item, Spec_Id);
2153 return;
2154
2155 -- Pragma [Refined_]Global associated with a task type
2156 -- cannot mention the current instance of a task type
2157 -- because the instance behaves as a formal parameter.
2158
2159 else pragma Assert (Ekind (Item_Id) = E_Task_Type);
2160 Error_Msg_Name_1 := Chars (Item_Id);
2161 SPARK_Msg_NE
2162 (Fix_Msg (Spec_Id, "global item of subprogram & "
2163 & "cannot reference current instance of task type "
2164 & "%"), Item, Spec_Id);
2165 return;
2166 end if;
2167
2168 -- Otherwise the global item denotes a subtype mark that is
2169 -- not a current instance.
2170
2171 else
2172 SPARK_Msg_N
2173 ("invalid use of subtype mark in global list", Item);
2174 return;
2175 end if;
2176
2177 -- A global item may denote the anonymous object created for a
2178 -- single protected/task type as long as the current instance
2179 -- is the same single type (SPARK RM 6.1.4).
2180
2181 elsif Is_Single_Concurrent_Object (Item_Id)
2182 and then Is_CCT_Instance (Item_Id, Spec_Id)
2183 then
2184 -- Pragma [Refined_]Global associated with a protected
2185 -- subprogram cannot mention the current instance of a
2186 -- protected type because the instance behaves as a formal
2187 -- parameter.
2188
2189 if Is_Single_Protected_Object (Item_Id) then
2190 Error_Msg_Name_1 := Chars (Item_Id);
2191 SPARK_Msg_NE
2192 (Fix_Msg (Spec_Id, "global item of subprogram & cannot "
2193 & "reference current instance of protected type %"),
2194 Item, Spec_Id);
2195 return;
2196
2197 -- Pragma [Refined_]Global associated with a task type
2198 -- cannot mention the current instance of a task type
2199 -- because the instance behaves as a formal parameter.
2200
2201 else pragma Assert (Is_Single_Task_Object (Item_Id));
2202 Error_Msg_Name_1 := Chars (Item_Id);
2203 SPARK_Msg_NE
2204 (Fix_Msg (Spec_Id, "global item of subprogram & cannot "
2205 & "reference current instance of task type %"),
2206 Item, Spec_Id);
2207 return;
2208 end if;
2209
2210 -- A formal object may act as a global item inside a generic
2211
2212 elsif Is_Formal_Object (Item_Id) then
2213 null;
2214
2215 -- The only legal references are those to abstract states,
2216 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2217
2218 elsif not Ekind_In (Item_Id, E_Abstract_State,
2219 E_Constant,
2220 E_Loop_Parameter,
2221 E_Variable)
2222 then
2223 SPARK_Msg_N
2224 ("global item must denote object, state or current "
2225 & "instance of concurrent type", Item);
2226 return;
2227 end if;
2228
2229 -- State related checks
2230
2231 if Ekind (Item_Id) = E_Abstract_State then
2232
2233 -- Package and subprogram bodies are instantiated
2234 -- individually in a separate compiler pass. Due to this
2235 -- mode of instantiation, the refinement of a state may
2236 -- no longer be visible when a subprogram body contract
2237 -- is instantiated. Since the generic template is legal,
2238 -- do not perform this check in the instance to circumvent
2239 -- this oddity.
2240
2241 if Is_Generic_Instance (Spec_Id) then
2242 null;
2243
2244 -- An abstract state with visible refinement cannot appear
2245 -- in pragma [Refined_]Global as its place must be taken by
2246 -- some of its constituents (SPARK RM 6.1.4(7)).
2247
2248 elsif Has_Visible_Refinement (Item_Id) then
2249 SPARK_Msg_NE
2250 ("cannot mention state & in global refinement",
2251 Item, Item_Id);
2252 SPARK_Msg_N ("\use its constituents instead", Item);
2253 return;
2254
2255 -- An external state cannot appear as a global item of a
2256 -- nonvolatile function (SPARK RM 7.1.3(8)).
2257
2258 elsif Is_External_State (Item_Id)
2259 and then Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2260 and then not Is_Volatile_Function (Spec_Id)
2261 then
2262 SPARK_Msg_NE
2263 ("external state & cannot act as global item of "
2264 & "nonvolatile function", Item, Item_Id);
2265 return;
2266
2267 -- If the reference to the abstract state appears in an
2268 -- enclosing package body that will eventually refine the
2269 -- state, record the reference for future checks.
2270
2271 else
2272 Record_Possible_Body_Reference
2273 (State_Id => Item_Id,
2274 Ref => Item);
2275 end if;
2276
2277 -- Constant related checks
2278
2279 elsif Ekind (Item_Id) = E_Constant then
2280
2281 -- A constant is a read-only item, therefore it cannot act
2282 -- as an output.
2283
2284 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2285 SPARK_Msg_NE
2286 ("constant & cannot act as output", Item, Item_Id);
2287 return;
2288 end if;
2289
2290 -- Loop parameter related checks
2291
2292 elsif Ekind (Item_Id) = E_Loop_Parameter then
2293
2294 -- A loop parameter is a read-only item, therefore it cannot
2295 -- act as an output.
2296
2297 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2298 SPARK_Msg_NE
2299 ("loop parameter & cannot act as output",
2300 Item, Item_Id);
2301 return;
2302 end if;
2303
2304 -- Variable related checks. These are only relevant when
2305 -- SPARK_Mode is on as they are not standard Ada legality
2306 -- rules.
2307
2308 elsif SPARK_Mode = On
2309 and then Ekind (Item_Id) = E_Variable
2310 and then Is_Effectively_Volatile (Item_Id)
2311 then
2312 -- An effectively volatile object cannot appear as a global
2313 -- item of a nonvolatile function (SPARK RM 7.1.3(8)).
2314
2315 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2316 and then not Is_Volatile_Function (Spec_Id)
2317 then
2318 Error_Msg_NE
2319 ("volatile object & cannot act as global item of a "
2320 & "function", Item, Item_Id);
2321 return;
2322
2323 -- An effectively volatile object with external property
2324 -- Effective_Reads set to True must have mode Output or
2325 -- In_Out (SPARK RM 7.1.3(10)).
2326
2327 elsif Effective_Reads_Enabled (Item_Id)
2328 and then Global_Mode = Name_Input
2329 then
2330 Error_Msg_NE
2331 ("volatile object & with property Effective_Reads must "
2332 & "have mode In_Out or Output", Item, Item_Id);
2333 return;
2334 end if;
2335 end if;
2336
2337 -- When the item renames an entire object, replace the item
2338 -- with a reference to the object.
2339
2340 if Entity (Item) /= Item_Id then
2341 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2342 Analyze (Item);
2343 end if;
2344
2345 -- Some form of illegal construct masquerading as a name
2346 -- (SPARK RM 6.1.4(4)).
2347
2348 else
2349 Error_Msg_N
2350 ("global item must denote object, state or current instance "
2351 & "of concurrent type", Item);
2352 return;
2353 end if;
2354
2355 -- Verify that an output does not appear as an input in an
2356 -- enclosing subprogram.
2357
2358 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2359 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2360 end if;
2361
2362 -- The same entity might be referenced through various way.
2363 -- Check the entity of the item rather than the item itself
2364 -- (SPARK RM 6.1.4(10)).
2365
2366 if Contains (Seen, Item_Id) then
2367 SPARK_Msg_N ("duplicate global item", Item);
2368
2369 -- Add the entity of the current item to the list of processed
2370 -- items.
2371
2372 else
2373 Append_New_Elmt (Item_Id, Seen);
2374
2375 if Ekind (Item_Id) = E_Abstract_State then
2376 Append_New_Elmt (Item_Id, States_Seen);
2377
2378 -- The variable may eventually become a constituent of a single
2379 -- protected/task type. Record the reference now and verify its
2380 -- legality when analyzing the contract of the variable
2381 -- (SPARK RM 9.3).
2382
2383 elsif Ekind (Item_Id) = E_Variable then
2384 Record_Possible_Part_Of_Reference
2385 (Var_Id => Item_Id,
2386 Ref => Item);
2387 end if;
2388
2389 if Ekind_In (Item_Id, E_Abstract_State, E_Constant, E_Variable)
2390 and then Present (Encapsulating_State (Item_Id))
2391 then
2392 Append_New_Elmt (Item_Id, Constits_Seen);
2393 end if;
2394 end if;
2395 end Analyze_Global_Item;
2396
2397 --------------------------
2398 -- Check_Duplicate_Mode --
2399 --------------------------
2400
2401 procedure Check_Duplicate_Mode
2402 (Mode : Node_Id;
2403 Status : in out Boolean)
2404 is
2405 begin
2406 if Status then
2407 SPARK_Msg_N ("duplicate global mode", Mode);
2408 end if;
2409
2410 Status := True;
2411 end Check_Duplicate_Mode;
2412
2413 -------------------------------------------------
2414 -- Check_Mode_Restriction_In_Enclosing_Context --
2415 -------------------------------------------------
2416
2417 procedure Check_Mode_Restriction_In_Enclosing_Context
2418 (Item : Node_Id;
2419 Item_Id : Entity_Id)
2420 is
2421 Context : Entity_Id;
2422 Dummy : Boolean;
2423 Inputs : Elist_Id := No_Elist;
2424 Outputs : Elist_Id := No_Elist;
2425
2426 begin
2427 -- Traverse the scope stack looking for enclosing subprograms
2428 -- subject to pragma [Refined_]Global.
2429
2430 Context := Scope (Subp_Id);
2431 while Present (Context) and then Context /= Standard_Standard loop
2432 if Is_Subprogram (Context)
2433 and then
2434 (Present (Get_Pragma (Context, Pragma_Global))
2435 or else
2436 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2437 then
2438 Collect_Subprogram_Inputs_Outputs
2439 (Subp_Id => Context,
2440 Subp_Inputs => Inputs,
2441 Subp_Outputs => Outputs,
2442 Global_Seen => Dummy);
2443
2444 -- The item is classified as In_Out or Output but appears as
2445 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(11)).
2446
2447 if Appears_In (Inputs, Item_Id)
2448 and then not Appears_In (Outputs, Item_Id)
2449 then
2450 SPARK_Msg_NE
2451 ("global item & cannot have mode In_Out or Output",
2452 Item, Item_Id);
2453
2454 SPARK_Msg_NE
2455 (Fix_Msg (Subp_Id, "\item already appears as input of "
2456 & "subprogram &"), Item, Context);
2457
2458 -- Stop the traversal once an error has been detected
2459
2460 exit;
2461 end if;
2462 end if;
2463
2464 Context := Scope (Context);
2465 end loop;
2466 end Check_Mode_Restriction_In_Enclosing_Context;
2467
2468 ----------------------------------------
2469 -- Check_Mode_Restriction_In_Function --
2470 ----------------------------------------
2471
2472 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2473 begin
2474 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
2475 SPARK_Msg_N
2476 ("global mode & is not applicable to functions", Mode);
2477 end if;
2478 end Check_Mode_Restriction_In_Function;
2479
2480 -- Local variables
2481
2482 Assoc : Node_Id;
2483 Item : Node_Id;
2484 Mode : Node_Id;
2485
2486 -- Start of processing for Analyze_Global_List
2487
2488 begin
2489 if Nkind (List) = N_Null then
2490 Set_Analyzed (List);
2491
2492 -- Single global item declaration
2493
2494 elsif Nkind_In (List, N_Expanded_Name,
2495 N_Identifier,
2496 N_Selected_Component)
2497 then
2498 Analyze_Global_Item (List, Global_Mode);
2499
2500 -- Simple global list or moded global list declaration
2501
2502 elsif Nkind (List) = N_Aggregate then
2503 Set_Analyzed (List);
2504
2505 -- The declaration of a simple global list appear as a collection
2506 -- of expressions.
2507
2508 if Present (Expressions (List)) then
2509 if Present (Component_Associations (List)) then
2510 SPARK_Msg_N
2511 ("cannot mix moded and non-moded global lists", List);
2512 end if;
2513
2514 Item := First (Expressions (List));
2515 while Present (Item) loop
2516 Analyze_Global_Item (Item, Global_Mode);
2517 Next (Item);
2518 end loop;
2519
2520 -- The declaration of a moded global list appears as a collection
2521 -- of component associations where individual choices denote
2522 -- modes.
2523
2524 elsif Present (Component_Associations (List)) then
2525 if Present (Expressions (List)) then
2526 SPARK_Msg_N
2527 ("cannot mix moded and non-moded global lists", List);
2528 end if;
2529
2530 Assoc := First (Component_Associations (List));
2531 while Present (Assoc) loop
2532 Mode := First (Choices (Assoc));
2533
2534 if Nkind (Mode) = N_Identifier then
2535 if Chars (Mode) = Name_In_Out then
2536 Check_Duplicate_Mode (Mode, In_Out_Seen);
2537 Check_Mode_Restriction_In_Function (Mode);
2538
2539 elsif Chars (Mode) = Name_Input then
2540 Check_Duplicate_Mode (Mode, Input_Seen);
2541
2542 elsif Chars (Mode) = Name_Output then
2543 Check_Duplicate_Mode (Mode, Output_Seen);
2544 Check_Mode_Restriction_In_Function (Mode);
2545
2546 elsif Chars (Mode) = Name_Proof_In then
2547 Check_Duplicate_Mode (Mode, Proof_Seen);
2548
2549 else
2550 SPARK_Msg_N ("invalid mode selector", Mode);
2551 end if;
2552
2553 else
2554 SPARK_Msg_N ("invalid mode selector", Mode);
2555 end if;
2556
2557 -- Items in a moded list appear as a collection of
2558 -- expressions. Reuse the existing machinery to analyze
2559 -- them.
2560
2561 Analyze_Global_List
2562 (List => Expression (Assoc),
2563 Global_Mode => Chars (Mode));
2564
2565 Next (Assoc);
2566 end loop;
2567
2568 -- Invalid tree
2569
2570 else
2571 raise Program_Error;
2572 end if;
2573
2574 -- Any other attempt to declare a global item is illegal. This is a
2575 -- syntax error, always report.
2576
2577 else
2578 Error_Msg_N ("malformed global list", List);
2579 end if;
2580 end Analyze_Global_List;
2581
2582 -- Local variables
2583
2584 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2585
2586 Restore_Scope : Boolean := False;
2587
2588 -- Start of processing for Analyze_Global_In_Decl_Part
2589
2590 begin
2591 -- Do not analyze the pragma multiple times
2592
2593 if Is_Analyzed_Pragma (N) then
2594 return;
2595 end if;
2596
2597 -- There is nothing to be done for a null global list
2598
2599 if Nkind (Items) = N_Null then
2600 Set_Analyzed (Items);
2601
2602 -- Analyze the various forms of global lists and items. Note that some
2603 -- of these may be malformed in which case the analysis emits error
2604 -- messages.
2605
2606 else
2607 -- When pragma [Refined_]Global appears on a single concurrent type,
2608 -- it is relocated to the anonymous object.
2609
2610 if Is_Single_Concurrent_Object (Spec_Id) then
2611 null;
2612
2613 -- Ensure that the formal parameters are visible when processing an
2614 -- item. This falls out of the general rule of aspects pertaining to
2615 -- subprogram declarations.
2616
2617 elsif not In_Open_Scopes (Spec_Id) then
2618 Restore_Scope := True;
2619 Push_Scope (Spec_Id);
2620
2621 if Ekind (Spec_Id) = E_Task_Type then
2622 if Has_Discriminants (Spec_Id) then
2623 Install_Discriminants (Spec_Id);
2624 end if;
2625
2626 elsif Is_Generic_Subprogram (Spec_Id) then
2627 Install_Generic_Formals (Spec_Id);
2628
2629 else
2630 Install_Formals (Spec_Id);
2631 end if;
2632 end if;
2633
2634 Analyze_Global_List (Items);
2635
2636 if Restore_Scope then
2637 End_Scope;
2638 end if;
2639 end if;
2640
2641 -- Ensure that a state and a corresponding constituent do not appear
2642 -- together in pragma [Refined_]Global.
2643
2644 Check_State_And_Constituent_Use
2645 (States => States_Seen,
2646 Constits => Constits_Seen,
2647 Context => N);
2648
2649 Set_Is_Analyzed_Pragma (N);
2650 end Analyze_Global_In_Decl_Part;
2651
2652 --------------------------------------------
2653 -- Analyze_Initial_Condition_In_Decl_Part --
2654 --------------------------------------------
2655
2656 -- WARNING: This routine manages Ghost regions. Return statements must be
2657 -- replaced by gotos which jump to the end of the routine and restore the
2658 -- Ghost mode.
2659
2660 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2661 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2662 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2663 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2664
2665 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
2666 -- Save the Ghost mode to restore on exit
2667
2668 begin
2669 -- Do not analyze the pragma multiple times
2670
2671 if Is_Analyzed_Pragma (N) then
2672 return;
2673 end if;
2674
2675 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2676 -- analysis of the pragma, the Ghost mode at point of declaration and
2677 -- point of analysis may not necessarily be the same. Use the mode in
2678 -- effect at the point of declaration.
2679
2680 Set_Ghost_Mode (N);
2681
2682 -- The expression is preanalyzed because it has not been moved to its
2683 -- final place yet. A direct analysis may generate side effects and this
2684 -- is not desired at this point.
2685
2686 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2687 Set_Is_Analyzed_Pragma (N);
2688
2689 Restore_Ghost_Mode (Saved_GM);
2690 end Analyze_Initial_Condition_In_Decl_Part;
2691
2692 --------------------------------------
2693 -- Analyze_Initializes_In_Decl_Part --
2694 --------------------------------------
2695
2696 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2697 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2698 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2699
2700 Constits_Seen : Elist_Id := No_Elist;
2701 -- A list containing the entities of all constituents processed so far.
2702 -- It aids in detecting illegal usage of a state and a corresponding
2703 -- constituent in pragma Initializes.
2704
2705 Items_Seen : Elist_Id := No_Elist;
2706 -- A list of all initialization items processed so far. This list is
2707 -- used to detect duplicate items.
2708
2709 Non_Null_Seen : Boolean := False;
2710 Null_Seen : Boolean := False;
2711 -- Flags used to check the legality of a null initialization list
2712
2713 States_And_Objs : Elist_Id := No_Elist;
2714 -- A list of all abstract states and objects declared in the visible
2715 -- declarations of the related package. This list is used to detect the
2716 -- legality of initialization items.
2717
2718 States_Seen : Elist_Id := No_Elist;
2719 -- A list containing the entities of all states processed so far. It
2720 -- helps in detecting illegal usage of a state and a corresponding
2721 -- constituent in pragma Initializes.
2722
2723 procedure Analyze_Initialization_Item (Item : Node_Id);
2724 -- Verify the legality of a single initialization item
2725
2726 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2727 -- Verify the legality of a single initialization item followed by a
2728 -- list of input items.
2729
2730 procedure Collect_States_And_Objects;
2731 -- Inspect the visible declarations of the related package and gather
2732 -- the entities of all abstract states and objects in States_And_Objs.
2733
2734 ---------------------------------
2735 -- Analyze_Initialization_Item --
2736 ---------------------------------
2737
2738 procedure Analyze_Initialization_Item (Item : Node_Id) is
2739 Item_Id : Entity_Id;
2740
2741 begin
2742 -- Null initialization list
2743
2744 if Nkind (Item) = N_Null then
2745 if Null_Seen then
2746 SPARK_Msg_N ("multiple null initializations not allowed", Item);
2747
2748 elsif Non_Null_Seen then
2749 SPARK_Msg_N
2750 ("cannot mix null and non-null initialization items", Item);
2751 else
2752 Null_Seen := True;
2753 end if;
2754
2755 -- Initialization item
2756
2757 else
2758 Non_Null_Seen := True;
2759
2760 if Null_Seen then
2761 SPARK_Msg_N
2762 ("cannot mix null and non-null initialization items", Item);
2763 end if;
2764
2765 Analyze (Item);
2766 Resolve_State (Item);
2767
2768 if Is_Entity_Name (Item) then
2769 Item_Id := Entity_Of (Item);
2770
2771 if Ekind_In (Item_Id, E_Abstract_State,
2772 E_Constant,
2773 E_Variable)
2774 then
2775 -- The state or variable must be declared in the visible
2776 -- declarations of the package (SPARK RM 7.1.5(7)).
2777
2778 if not Contains (States_And_Objs, Item_Id) then
2779 Error_Msg_Name_1 := Chars (Pack_Id);
2780 SPARK_Msg_NE
2781 ("initialization item & must appear in the visible "
2782 & "declarations of package %", Item, Item_Id);
2783
2784 -- Detect a duplicate use of the same initialization item
2785 -- (SPARK RM 7.1.5(5)).
2786
2787 elsif Contains (Items_Seen, Item_Id) then
2788 SPARK_Msg_N ("duplicate initialization item", Item);
2789
2790 -- The item is legal, add it to the list of processed states
2791 -- and variables.
2792
2793 else
2794 Append_New_Elmt (Item_Id, Items_Seen);
2795
2796 if Ekind (Item_Id) = E_Abstract_State then
2797 Append_New_Elmt (Item_Id, States_Seen);
2798 end if;
2799
2800 if Present (Encapsulating_State (Item_Id)) then
2801 Append_New_Elmt (Item_Id, Constits_Seen);
2802 end if;
2803 end if;
2804
2805 -- The item references something that is not a state or object
2806 -- (SPARK RM 7.1.5(3)).
2807
2808 else
2809 SPARK_Msg_N
2810 ("initialization item must denote object or state", Item);
2811 end if;
2812
2813 -- Some form of illegal construct masquerading as a name
2814 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2815
2816 else
2817 Error_Msg_N
2818 ("initialization item must denote object or state", Item);
2819 end if;
2820 end if;
2821 end Analyze_Initialization_Item;
2822
2823 ---------------------------------------------
2824 -- Analyze_Initialization_Item_With_Inputs --
2825 ---------------------------------------------
2826
2827 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2828 Inputs_Seen : Elist_Id := No_Elist;
2829 -- A list of all inputs processed so far. This list is used to detect
2830 -- duplicate uses of an input.
2831
2832 Non_Null_Seen : Boolean := False;
2833 Null_Seen : Boolean := False;
2834 -- Flags used to check the legality of an input list
2835
2836 procedure Analyze_Input_Item (Input : Node_Id);
2837 -- Verify the legality of a single input item
2838
2839 ------------------------
2840 -- Analyze_Input_Item --
2841 ------------------------
2842
2843 procedure Analyze_Input_Item (Input : Node_Id) is
2844 Input_Id : Entity_Id;
2845 Input_OK : Boolean := True;
2846
2847 begin
2848 -- Null input list
2849
2850 if Nkind (Input) = N_Null then
2851 if Null_Seen then
2852 SPARK_Msg_N
2853 ("multiple null initializations not allowed", Item);
2854
2855 elsif Non_Null_Seen then
2856 SPARK_Msg_N
2857 ("cannot mix null and non-null initialization item", Item);
2858 else
2859 Null_Seen := True;
2860 end if;
2861
2862 -- Input item
2863
2864 else
2865 Non_Null_Seen := True;
2866
2867 if Null_Seen then
2868 SPARK_Msg_N
2869 ("cannot mix null and non-null initialization item", Item);
2870 end if;
2871
2872 Analyze (Input);
2873 Resolve_State (Input);
2874
2875 if Is_Entity_Name (Input) then
2876 Input_Id := Entity_Of (Input);
2877
2878 if Ekind_In (Input_Id, E_Abstract_State,
2879 E_Constant,
2880 E_Generic_In_Out_Parameter,
2881 E_Generic_In_Parameter,
2882 E_In_Parameter,
2883 E_In_Out_Parameter,
2884 E_Out_Parameter,
2885 E_Variable)
2886 then
2887 -- The input cannot denote states or objects declared
2888 -- within the related package (SPARK RM 7.1.5(4)).
2889
2890 if Within_Scope (Input_Id, Current_Scope) then
2891
2892 -- Do not consider generic formal parameters or their
2893 -- respective mappings to generic formals. Even though
2894 -- the formals appear within the scope of the package,
2895 -- it is allowed for an initialization item to depend
2896 -- on an input item.
2897
2898 if Ekind_In (Input_Id, E_Generic_In_Out_Parameter,
2899 E_Generic_In_Parameter)
2900 then
2901 null;
2902
2903 elsif Ekind_In (Input_Id, E_Constant, E_Variable)
2904 and then Present (Corresponding_Generic_Association
2905 (Declaration_Node (Input_Id)))
2906 then
2907 null;
2908
2909 else
2910 Input_OK := False;
2911 Error_Msg_Name_1 := Chars (Pack_Id);
2912 SPARK_Msg_NE
2913 ("input item & cannot denote a visible object or "
2914 & "state of package %", Input, Input_Id);
2915 end if;
2916 end if;
2917
2918 -- Detect a duplicate use of the same input item
2919 -- (SPARK RM 7.1.5(5)).
2920
2921 if Contains (Inputs_Seen, Input_Id) then
2922 Input_OK := False;
2923 SPARK_Msg_N ("duplicate input item", Input);
2924 end if;
2925
2926 -- Input is legal, add it to the list of processed inputs
2927
2928 if Input_OK then
2929 Append_New_Elmt (Input_Id, Inputs_Seen);
2930
2931 if Ekind (Input_Id) = E_Abstract_State then
2932 Append_New_Elmt (Input_Id, States_Seen);
2933 end if;
2934
2935 if Ekind_In (Input_Id, E_Abstract_State,
2936 E_Constant,
2937 E_Variable)
2938 and then Present (Encapsulating_State (Input_Id))
2939 then
2940 Append_New_Elmt (Input_Id, Constits_Seen);
2941 end if;
2942 end if;
2943
2944 -- The input references something that is not a state or an
2945 -- object (SPARK RM 7.1.5(3)).
2946
2947 else
2948 SPARK_Msg_N
2949 ("input item must denote object or state", Input);
2950 end if;
2951
2952 -- Some form of illegal construct masquerading as a name
2953 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2954
2955 else
2956 Error_Msg_N
2957 ("input item must denote object or state", Input);
2958 end if;
2959 end if;
2960 end Analyze_Input_Item;
2961
2962 -- Local variables
2963
2964 Inputs : constant Node_Id := Expression (Item);
2965 Elmt : Node_Id;
2966 Input : Node_Id;
2967
2968 Name_Seen : Boolean := False;
2969 -- A flag used to detect multiple item names
2970
2971 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2972
2973 begin
2974 -- Inspect the name of an item with inputs
2975
2976 Elmt := First (Choices (Item));
2977 while Present (Elmt) loop
2978 if Name_Seen then
2979 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
2980 else
2981 Name_Seen := True;
2982 Analyze_Initialization_Item (Elmt);
2983 end if;
2984
2985 Next (Elmt);
2986 end loop;
2987
2988 -- Multiple input items appear as an aggregate
2989
2990 if Nkind (Inputs) = N_Aggregate then
2991 if Present (Expressions (Inputs)) then
2992 Input := First (Expressions (Inputs));
2993 while Present (Input) loop
2994 Analyze_Input_Item (Input);
2995 Next (Input);
2996 end loop;
2997 end if;
2998
2999 if Present (Component_Associations (Inputs)) then
3000 SPARK_Msg_N
3001 ("inputs must appear in named association form", Inputs);
3002 end if;
3003
3004 -- Single input item
3005
3006 else
3007 Analyze_Input_Item (Inputs);
3008 end if;
3009 end Analyze_Initialization_Item_With_Inputs;
3010
3011 --------------------------------
3012 -- Collect_States_And_Objects --
3013 --------------------------------
3014
3015 procedure Collect_States_And_Objects is
3016 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
3017 Decl : Node_Id;
3018
3019 begin
3020 -- Collect the abstract states defined in the package (if any)
3021
3022 if Present (Abstract_States (Pack_Id)) then
3023 States_And_Objs := New_Copy_Elist (Abstract_States (Pack_Id));
3024 end if;
3025
3026 -- Collect all objects the appear in the visible declarations of the
3027 -- related package.
3028
3029 if Present (Visible_Declarations (Pack_Spec)) then
3030 Decl := First (Visible_Declarations (Pack_Spec));
3031 while Present (Decl) loop
3032 if Comes_From_Source (Decl)
3033 and then Nkind (Decl) = N_Object_Declaration
3034 then
3035 Append_New_Elmt (Defining_Entity (Decl), States_And_Objs);
3036 end if;
3037
3038 Next (Decl);
3039 end loop;
3040 end if;
3041 end Collect_States_And_Objects;
3042
3043 -- Local variables
3044
3045 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3046 Init : Node_Id;
3047
3048 -- Start of processing for Analyze_Initializes_In_Decl_Part
3049
3050 begin
3051 -- Do not analyze the pragma multiple times
3052
3053 if Is_Analyzed_Pragma (N) then
3054 return;
3055 end if;
3056
3057 -- Nothing to do when the initialization list is empty
3058
3059 if Nkind (Inits) = N_Null then
3060 return;
3061 end if;
3062
3063 -- Single and multiple initialization clauses appear as an aggregate. If
3064 -- this is not the case, then either the parser or the analysis of the
3065 -- pragma failed to produce an aggregate.
3066
3067 pragma Assert (Nkind (Inits) = N_Aggregate);
3068
3069 -- Initialize the various lists used during analysis
3070
3071 Collect_States_And_Objects;
3072
3073 if Present (Expressions (Inits)) then
3074 Init := First (Expressions (Inits));
3075 while Present (Init) loop
3076 Analyze_Initialization_Item (Init);
3077 Next (Init);
3078 end loop;
3079 end if;
3080
3081 if Present (Component_Associations (Inits)) then
3082 Init := First (Component_Associations (Inits));
3083 while Present (Init) loop
3084 Analyze_Initialization_Item_With_Inputs (Init);
3085 Next (Init);
3086 end loop;
3087 end if;
3088
3089 -- Ensure that a state and a corresponding constituent do not appear
3090 -- together in pragma Initializes.
3091
3092 Check_State_And_Constituent_Use
3093 (States => States_Seen,
3094 Constits => Constits_Seen,
3095 Context => N);
3096
3097 Set_Is_Analyzed_Pragma (N);
3098 end Analyze_Initializes_In_Decl_Part;
3099
3100 ---------------------
3101 -- Analyze_Part_Of --
3102 ---------------------
3103
3104 procedure Analyze_Part_Of
3105 (Indic : Node_Id;
3106 Item_Id : Entity_Id;
3107 Encap : Node_Id;
3108 Encap_Id : out Entity_Id;
3109 Legal : out Boolean)
3110 is
3111 Encap_Typ : Entity_Id;
3112 Item_Decl : Node_Id;
3113 Pack_Id : Entity_Id;
3114 Placement : State_Space_Kind;
3115 Parent_Unit : Entity_Id;
3116
3117 begin
3118 -- Assume that the indicator is illegal
3119
3120 Encap_Id := Empty;
3121 Legal := False;
3122
3123 if Nkind_In (Encap, N_Expanded_Name,
3124 N_Identifier,
3125 N_Selected_Component)
3126 then
3127 Analyze (Encap);
3128 Resolve_State (Encap);
3129
3130 Encap_Id := Entity (Encap);
3131
3132 -- The encapsulator is an abstract state
3133
3134 if Ekind (Encap_Id) = E_Abstract_State then
3135 null;
3136
3137 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3138
3139 elsif Is_Single_Concurrent_Object (Encap_Id) then
3140 null;
3141
3142 -- Otherwise the encapsulator is not a legal choice
3143
3144 else
3145 SPARK_Msg_N
3146 ("indicator Part_Of must denote abstract state, single "
3147 & "protected type or single task type", Encap);
3148 return;
3149 end if;
3150
3151 -- This is a syntax error, always report
3152
3153 else
3154 Error_Msg_N
3155 ("indicator Part_Of must denote abstract state, single protected "
3156 & "type or single task type", Encap);
3157 return;
3158 end if;
3159
3160 -- Catch a case where indicator Part_Of denotes the abstract view of a
3161 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3162
3163 if From_Limited_With (Encap_Id)
3164 and then Present (Non_Limited_View (Encap_Id))
3165 and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable
3166 then
3167 SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap);
3168 SPARK_Msg_N ("\& denotes abstract view of object", Encap);
3169 return;
3170 end if;
3171
3172 -- The encapsulator is an abstract state
3173
3174 if Ekind (Encap_Id) = E_Abstract_State then
3175
3176 -- Determine where the object, package instantiation or state lives
3177 -- with respect to the enclosing packages or package bodies.
3178
3179 Find_Placement_In_State_Space
3180 (Item_Id => Item_Id,
3181 Placement => Placement,
3182 Pack_Id => Pack_Id);
3183
3184 -- The item appears in a non-package construct with a declarative
3185 -- part (subprogram, block, etc). As such, the item is not allowed
3186 -- to be a part of an encapsulating state because the item is not
3187 -- visible.
3188
3189 if Placement = Not_In_Package then
3190 SPARK_Msg_N
3191 ("indicator Part_Of cannot appear in this context "
3192 & "(SPARK RM 7.2.6(5))", Indic);
3193 Error_Msg_Name_1 := Chars (Scope (Encap_Id));
3194 SPARK_Msg_NE
3195 ("\& is not part of the hidden state of package %",
3196 Indic, Item_Id);
3197
3198 -- The item appears in the visible state space of some package. In
3199 -- general this scenario does not warrant Part_Of except when the
3200 -- package is a private child unit and the encapsulating state is
3201 -- declared in a parent unit or a public descendant of that parent
3202 -- unit.
3203
3204 elsif Placement = Visible_State_Space then
3205 if Is_Child_Unit (Pack_Id)
3206 and then Is_Private_Descendant (Pack_Id)
3207 then
3208 -- A variable or state abstraction which is part of the visible
3209 -- state of a private child unit (or one of its public
3210 -- descendants) must have its Part_Of indicator specified. The
3211 -- Part_Of indicator must denote a state abstraction declared
3212 -- by either the parent unit of the private unit or by a public
3213 -- descendant of that parent unit.
3214
3215 -- Find nearest private ancestor (which can be the current unit
3216 -- itself).
3217
3218 Parent_Unit := Pack_Id;
3219 while Present (Parent_Unit) loop
3220 exit when
3221 Private_Present
3222 (Parent (Unit_Declaration_Node (Parent_Unit)));
3223 Parent_Unit := Scope (Parent_Unit);
3224 end loop;
3225
3226 Parent_Unit := Scope (Parent_Unit);
3227
3228 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
3229 SPARK_Msg_NE
3230 ("indicator Part_Of must denote abstract state or public "
3231 & "descendant of & (SPARK RM 7.2.6(3))",
3232 Indic, Parent_Unit);
3233
3234 elsif Scope (Encap_Id) = Parent_Unit
3235 or else
3236 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id))
3237 and then not Is_Private_Descendant (Scope (Encap_Id)))
3238 then
3239 null;
3240
3241 else
3242 SPARK_Msg_NE
3243 ("indicator Part_Of must denote abstract state or public "
3244 & "descendant of & (SPARK RM 7.2.6(3))",
3245 Indic, Parent_Unit);
3246 end if;
3247
3248 -- Indicator Part_Of is not needed when the related package is not
3249 -- a private child unit or a public descendant thereof.
3250
3251 else
3252 SPARK_Msg_N
3253 ("indicator Part_Of cannot appear in this context "
3254 & "(SPARK RM 7.2.6(5))", Indic);
3255 Error_Msg_Name_1 := Chars (Pack_Id);
3256 SPARK_Msg_NE
3257 ("\& is declared in the visible part of package %",
3258 Indic, Item_Id);
3259 end if;
3260
3261 -- When the item appears in the private state space of a package, the
3262 -- encapsulating state must be declared in the same package.
3263
3264 elsif Placement = Private_State_Space then
3265 if Scope (Encap_Id) /= Pack_Id then
3266 SPARK_Msg_NE
3267 ("indicator Part_Of must designate an abstract state of "
3268 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3269 Error_Msg_Name_1 := Chars (Pack_Id);
3270 SPARK_Msg_NE
3271 ("\& is declared in the private part of package %",
3272 Indic, Item_Id);
3273 end if;
3274
3275 -- Items declared in the body state space of a package do not need
3276 -- Part_Of indicators as the refinement has already been seen.
3277
3278 else
3279 SPARK_Msg_N
3280 ("indicator Part_Of cannot appear in this context "
3281 & "(SPARK RM 7.2.6(5))", Indic);
3282
3283 if Scope (Encap_Id) = Pack_Id then
3284 Error_Msg_Name_1 := Chars (Pack_Id);
3285 SPARK_Msg_NE
3286 ("\& is declared in the body of package %", Indic, Item_Id);
3287 end if;
3288 end if;
3289
3290 -- The encapsulator is a single concurrent type
3291
3292 else
3293 Encap_Typ := Etype (Encap_Id);
3294
3295 -- Only abstract states and variables can act as constituents of an
3296 -- encapsulating single concurrent type.
3297
3298 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
3299 null;
3300
3301 -- The constituent is a constant
3302
3303 elsif Ekind (Item_Id) = E_Constant then
3304 Error_Msg_Name_1 := Chars (Encap_Id);
3305 SPARK_Msg_NE
3306 (Fix_Msg (Encap_Typ, "constant & cannot act as constituent of "
3307 & "single protected type %"), Indic, Item_Id);
3308
3309 -- The constituent is a package instantiation
3310
3311 else
3312 Error_Msg_Name_1 := Chars (Encap_Id);
3313 SPARK_Msg_NE
3314 (Fix_Msg (Encap_Typ, "package instantiation & cannot act as "
3315 & "constituent of single protected type %"), Indic, Item_Id);
3316 end if;
3317
3318 -- When the item denotes an abstract state of a nested package, use
3319 -- the declaration of the package to detect proper placement.
3320
3321 -- package Pack is
3322 -- task T;
3323 -- package Nested
3324 -- with Abstract_State => (State with Part_Of => T)
3325
3326 if Ekind (Item_Id) = E_Abstract_State then
3327 Item_Decl := Unit_Declaration_Node (Scope (Item_Id));
3328 else
3329 Item_Decl := Declaration_Node (Item_Id);
3330 end if;
3331
3332 -- Both the item and its encapsulating single concurrent type must
3333 -- appear in the same declarative region (SPARK RM 9.3). Note that
3334 -- privacy is ignored.
3335
3336 if Parent (Item_Decl) /= Parent (Declaration_Node (Encap_Id)) then
3337 Error_Msg_Name_1 := Chars (Encap_Id);
3338 SPARK_Msg_NE
3339 (Fix_Msg (Encap_Typ, "constituent & must be declared "
3340 & "immediately within the same region as single protected "
3341 & "type %"), Indic, Item_Id);
3342 end if;
3343 end if;
3344
3345 Legal := True;
3346 end Analyze_Part_Of;
3347
3348 ----------------------------------
3349 -- Analyze_Part_Of_In_Decl_Part --
3350 ----------------------------------
3351
3352 procedure Analyze_Part_Of_In_Decl_Part
3353 (N : Node_Id;
3354 Freeze_Id : Entity_Id := Empty)
3355 is
3356 Encap : constant Node_Id :=
3357 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
3358 Errors : constant Nat := Serious_Errors_Detected;
3359 Var_Decl : constant Node_Id := Find_Related_Context (N);
3360 Var_Id : constant Entity_Id := Defining_Entity (Var_Decl);
3361 Constits : Elist_Id;
3362 Encap_Id : Entity_Id;
3363 Legal : Boolean;
3364
3365 begin
3366 -- Detect any discrepancies between the placement of the variable with
3367 -- respect to general state space and the encapsulating state or single
3368 -- concurrent type.
3369
3370 Analyze_Part_Of
3371 (Indic => N,
3372 Item_Id => Var_Id,
3373 Encap => Encap,
3374 Encap_Id => Encap_Id,
3375 Legal => Legal);
3376
3377 -- The Part_Of indicator turns the variable into a constituent of the
3378 -- encapsulating state or single concurrent type.
3379
3380 if Legal then
3381 pragma Assert (Present (Encap_Id));
3382 Constits := Part_Of_Constituents (Encap_Id);
3383
3384 if No (Constits) then
3385 Constits := New_Elmt_List;
3386 Set_Part_Of_Constituents (Encap_Id, Constits);
3387 end if;
3388
3389 Append_Elmt (Var_Id, Constits);
3390 Set_Encapsulating_State (Var_Id, Encap_Id);
3391
3392 -- A Part_Of constituent partially refines an abstract state. This
3393 -- property does not apply to protected or task units.
3394
3395 if Ekind (Encap_Id) = E_Abstract_State then
3396 Set_Has_Partial_Visible_Refinement (Encap_Id);
3397 end if;
3398 end if;
3399
3400 -- Emit a clarification message when the encapsulator is undefined,
3401 -- possibly due to contract "freezing".
3402
3403 if Errors /= Serious_Errors_Detected
3404 and then Present (Freeze_Id)
3405 and then Has_Undefined_Reference (Encap)
3406 then
3407 Contract_Freeze_Error (Var_Id, Freeze_Id);
3408 end if;
3409 end Analyze_Part_Of_In_Decl_Part;
3410
3411 --------------------
3412 -- Analyze_Pragma --
3413 --------------------
3414
3415 procedure Analyze_Pragma (N : Node_Id) is
3416 Loc : constant Source_Ptr := Sloc (N);
3417
3418 Pname : Name_Id := Pragma_Name (N);
3419 -- Name of the source pragma, or name of the corresponding aspect for
3420 -- pragmas which originate in a source aspect. In the latter case, the
3421 -- name may be different from the pragma name.
3422
3423 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
3424
3425 Pragma_Exit : exception;
3426 -- This exception is used to exit pragma processing completely. It
3427 -- is used when an error is detected, and no further processing is
3428 -- required. It is also used if an earlier error has left the tree in
3429 -- a state where the pragma should not be processed.
3430
3431 Arg_Count : Nat;
3432 -- Number of pragma argument associations
3433
3434 Arg1 : Node_Id;
3435 Arg2 : Node_Id;
3436 Arg3 : Node_Id;
3437 Arg4 : Node_Id;
3438 -- First four pragma arguments (pragma argument association nodes, or
3439 -- Empty if the corresponding argument does not exist).
3440
3441 type Name_List is array (Natural range <>) of Name_Id;
3442 type Args_List is array (Natural range <>) of Node_Id;
3443 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3444
3445 -----------------------
3446 -- Local Subprograms --
3447 -----------------------
3448
3449 procedure Acquire_Warning_Match_String (Arg : Node_Id);
3450 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
3451 -- get the given string argument, and place it in Name_Buffer, adding
3452 -- leading and trailing asterisks if they are not already present. The
3453 -- caller has already checked that Arg is a static string expression.
3454
3455 procedure Ada_2005_Pragma;
3456 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3457 -- Ada 95 mode, these are implementation defined pragmas, so should be
3458 -- caught by the No_Implementation_Pragmas restriction.
3459
3460 procedure Ada_2012_Pragma;
3461 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3462 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3463 -- should be caught by the No_Implementation_Pragmas restriction.
3464
3465 procedure Analyze_Depends_Global
3466 (Spec_Id : out Entity_Id;
3467 Subp_Decl : out Node_Id;
3468 Legal : out Boolean);
3469 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3470 -- legality of the placement and related context of the pragma. Spec_Id
3471 -- is the entity of the related subprogram. Subp_Decl is the declaration
3472 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3473
3474 procedure Analyze_If_Present (Id : Pragma_Id);
3475 -- Inspect the remainder of the list containing pragma N and look for
3476 -- a pragma that matches Id. If found, analyze the pragma.
3477
3478 procedure Analyze_Pre_Post_Condition;
3479 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3480
3481 procedure Analyze_Refined_Depends_Global_Post
3482 (Spec_Id : out Entity_Id;
3483 Body_Id : out Entity_Id;
3484 Legal : out Boolean);
3485 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3486 -- Refined_Global and Refined_Post. Verify the legality of the placement
3487 -- and related context of the pragma. Spec_Id is the entity of the
3488 -- related subprogram. Body_Id is the entity of the subprogram body.
3489 -- Flag Legal is set when the pragma is legal.
3490
3491 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False);
3492 -- Perform full analysis of pragma Unmodified and the write aspect of
3493 -- pragma Unused. Flag Is_Unused should be set when verifying the
3494 -- semantics of pragma Unused.
3495
3496 procedure Analyze_Unreferenced_Or_Unused (Is_Unused : Boolean := False);
3497 -- Perform full analysis of pragma Unreferenced and the read aspect of
3498 -- pragma Unused. Flag Is_Unused should be set when verifying the
3499 -- semantics of pragma Unused.
3500
3501 procedure Check_Ada_83_Warning;
3502 -- Issues a warning message for the current pragma if operating in Ada
3503 -- 83 mode (used for language pragmas that are not a standard part of
3504 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3505 -- of 95 pragma.
3506
3507 procedure Check_Arg_Count (Required : Nat);
3508 -- Check argument count for pragma is equal to given parameter. If not,
3509 -- then issue an error message and raise Pragma_Exit.
3510
3511 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3512 -- Arg which can either be a pragma argument association, in which case
3513 -- the check is applied to the expression of the association or an
3514 -- expression directly.
3515
3516 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
3517 -- Check that an argument has the right form for an EXTERNAL_NAME
3518 -- parameter of an extended import/export pragma. The rule is that the
3519 -- name must be an identifier or string literal (in Ada 83 mode) or a
3520 -- static string expression (in Ada 95 mode).
3521
3522 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
3523 -- Check the specified argument Arg to make sure that it is an
3524 -- identifier. If not give error and raise Pragma_Exit.
3525
3526 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
3527 -- Check the specified argument Arg to make sure that it is an integer
3528 -- literal. If not give error and raise Pragma_Exit.
3529
3530 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
3531 -- Check the specified argument Arg to make sure that it has the proper
3532 -- syntactic form for a local name and meets the semantic requirements
3533 -- for a local name. The local name is analyzed as part of the
3534 -- processing for this call. In addition, the local name is required
3535 -- to represent an entity at the library level.
3536
3537 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
3538 -- Check the specified argument Arg to make sure that it has the proper
3539 -- syntactic form for a local name and meets the semantic requirements
3540 -- for a local name. The local name is analyzed as part of the
3541 -- processing for this call.
3542
3543 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
3544 -- Check the specified argument Arg to make sure that it is a valid
3545 -- locking policy name. If not give error and raise Pragma_Exit.
3546
3547 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
3548 -- Check the specified argument Arg to make sure that it is a valid
3549 -- elaboration policy name. If not give error and raise Pragma_Exit.
3550
3551 procedure Check_Arg_Is_One_Of
3552 (Arg : Node_Id;
3553 N1, N2 : Name_Id);
3554 procedure Check_Arg_Is_One_Of
3555 (Arg : Node_Id;
3556 N1, N2, N3 : Name_Id);
3557 procedure Check_Arg_Is_One_Of
3558 (Arg : Node_Id;
3559 N1, N2, N3, N4 : Name_Id);
3560 procedure Check_Arg_Is_One_Of
3561 (Arg : Node_Id;
3562 N1, N2, N3, N4, N5 : Name_Id);
3563 -- Check the specified argument Arg to make sure that it is an
3564 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3565 -- present). If not then give error and raise Pragma_Exit.
3566
3567 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
3568 -- Check the specified argument Arg to make sure that it is a valid
3569 -- queuing policy name. If not give error and raise Pragma_Exit.
3570
3571 procedure Check_Arg_Is_OK_Static_Expression
3572 (Arg : Node_Id;
3573 Typ : Entity_Id := Empty);
3574 -- Check the specified argument Arg to make sure that it is a static
3575 -- expression of the given type (i.e. it will be analyzed and resolved
3576 -- using this type, which can be any valid argument to Resolve, e.g.
3577 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3578 -- Typ is left Empty, then any static expression is allowed. Includes
3579 -- checking that the argument does not raise Constraint_Error.
3580
3581 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
3582 -- Check the specified argument Arg to make sure that it is a valid task
3583 -- dispatching policy name. If not give error and raise Pragma_Exit.
3584
3585 procedure Check_Arg_Order (Names : Name_List);
3586 -- Checks for an instance of two arguments with identifiers for the
3587 -- current pragma which are not in the sequence indicated by Names,
3588 -- and if so, generates a fatal message about bad order of arguments.
3589
3590 procedure Check_At_Least_N_Arguments (N : Nat);
3591 -- Check there are at least N arguments present
3592
3593 procedure Check_At_Most_N_Arguments (N : Nat);
3594 -- Check there are no more than N arguments present
3595
3596 procedure Check_Component
3597 (Comp : Node_Id;
3598 UU_Typ : Entity_Id;
3599 In_Variant_Part : Boolean := False);
3600 -- Examine an Unchecked_Union component for correct use of per-object
3601 -- constrained subtypes, and for restrictions on finalizable components.
3602 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3603 -- should be set when Comp comes from a record variant.
3604
3605 procedure Check_Duplicate_Pragma (E : Entity_Id);
3606 -- Check if a rep item of the same name as the current pragma is already
3607 -- chained as a rep pragma to the given entity. If so give a message
3608 -- about the duplicate, and then raise Pragma_Exit so does not return.
3609 -- Note that if E is a type, then this routine avoids flagging a pragma
3610 -- which applies to a parent type from which E is derived.
3611
3612 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
3613 -- Nam is an N_String_Literal node containing the external name set by
3614 -- an Import or Export pragma (or extended Import or Export pragma).
3615 -- This procedure checks for possible duplications if this is the export
3616 -- case, and if found, issues an appropriate error message.
3617
3618 procedure Check_Expr_Is_OK_Static_Expression
3619 (Expr : Node_Id;
3620 Typ : Entity_Id := Empty);
3621 -- Check the specified expression Expr to make sure that it is a static
3622 -- expression of the given type (i.e. it will be analyzed and resolved
3623 -- using this type, which can be any valid argument to Resolve, e.g.
3624 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3625 -- Typ is left Empty, then any static expression is allowed. Includes
3626 -- checking that the expression does not raise Constraint_Error.
3627
3628 procedure Check_First_Subtype (Arg : Node_Id);
3629 -- Checks that Arg, whose expression is an entity name, references a
3630 -- first subtype.
3631
3632 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
3633 -- Checks that the given argument has an identifier, and if so, requires
3634 -- it to match the given identifier name. If there is no identifier, or
3635 -- a non-matching identifier, then an error message is given and
3636 -- Pragma_Exit is raised.
3637
3638 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
3639 -- Checks that the given argument has an identifier, and if so, requires
3640 -- it to match one of the given identifier names. If there is no
3641 -- identifier, or a non-matching identifier, then an error message is
3642 -- given and Pragma_Exit is raised.
3643
3644 procedure Check_In_Main_Program;
3645 -- Common checks for pragmas that appear within a main program
3646 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3647
3648 procedure Check_Interrupt_Or_Attach_Handler;
3649 -- Common processing for first argument of pragma Interrupt_Handler or
3650 -- pragma Attach_Handler.
3651
3652 procedure Check_Loop_Pragma_Placement;
3653 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
3654 -- appear immediately within a construct restricted to loops, and that
3655 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
3656
3657 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
3658 -- Check that pragma appears in a declarative part, or in a package
3659 -- specification, i.e. that it does not occur in a statement sequence
3660 -- in a body.
3661
3662 procedure Check_No_Identifier (Arg : Node_Id);
3663 -- Checks that the given argument does not have an identifier. If
3664 -- an identifier is present, then an error message is issued, and
3665 -- Pragma_Exit is raised.
3666
3667 procedure Check_No_Identifiers;
3668 -- Checks that none of the arguments to the pragma has an identifier.
3669 -- If any argument has an identifier, then an error message is issued,
3670 -- and Pragma_Exit is raised.
3671
3672 procedure Check_No_Link_Name;
3673 -- Checks that no link name is specified
3674
3675 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
3676 -- Checks if the given argument has an identifier, and if so, requires
3677 -- it to match the given identifier name. If there is a non-matching
3678 -- identifier, then an error message is given and Pragma_Exit is raised.
3679
3680 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
3681 -- Checks if the given argument has an identifier, and if so, requires
3682 -- it to match the given identifier name. If there is a non-matching
3683 -- identifier, then an error message is given and Pragma_Exit is raised.
3684 -- In this version of the procedure, the identifier name is given as
3685 -- a string with lower case letters.
3686
3687 procedure Check_Static_Boolean_Expression (Expr : Node_Id);
3688 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
3689 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
3690 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
3691 -- is an OK static boolean expression. Emit an error if this is not the
3692 -- case.
3693
3694 procedure Check_Static_Constraint (Constr : Node_Id);
3695 -- Constr is a constraint from an N_Subtype_Indication node from a
3696 -- component constraint in an Unchecked_Union type. This routine checks
3697 -- that the constraint is static as required by the restrictions for
3698 -- Unchecked_Union.
3699
3700 procedure Check_Valid_Configuration_Pragma;
3701 -- Legality checks for placement of a configuration pragma
3702
3703 procedure Check_Valid_Library_Unit_Pragma;
3704 -- Legality checks for library unit pragmas. A special case arises for
3705 -- pragmas in generic instances that come from copies of the original
3706 -- library unit pragmas in the generic templates. In the case of other
3707 -- than library level instantiations these can appear in contexts which
3708 -- would normally be invalid (they only apply to the original template
3709 -- and to library level instantiations), and they are simply ignored,
3710 -- which is implemented by rewriting them as null statements.
3711
3712 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
3713 -- Check an Unchecked_Union variant for lack of nested variants and
3714 -- presence of at least one component. UU_Typ is the related Unchecked_
3715 -- Union type.
3716
3717 procedure Ensure_Aggregate_Form (Arg : Node_Id);
3718 -- Subsidiary routine to the processing of pragmas Abstract_State,
3719 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
3720 -- Refined_Global and Refined_State. Transform argument Arg into
3721 -- an aggregate if not one already. N_Null is never transformed.
3722 -- Arg may denote an aspect specification or a pragma argument
3723 -- association.
3724
3725 procedure Error_Pragma (Msg : String);
3726 pragma No_Return (Error_Pragma);
3727 -- Outputs error message for current pragma. The message contains a %
3728 -- that will be replaced with the pragma name, and the flag is placed
3729 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
3730 -- calls Fix_Error (see spec of that procedure for details).
3731
3732 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
3733 pragma No_Return (Error_Pragma_Arg);
3734 -- Outputs error message for current pragma. The message may contain
3735 -- a % that will be replaced with the pragma name. The parameter Arg
3736 -- may either be a pragma argument association, in which case the flag
3737 -- is placed on the expression of this association, or an expression,
3738 -- in which case the flag is placed directly on the expression. The
3739 -- message is placed using Error_Msg_N, so the message may also contain
3740 -- an & insertion character which will reference the given Arg value.
3741 -- After placing the message, Pragma_Exit is raised. Note: this routine
3742 -- calls Fix_Error (see spec of that procedure for details).
3743
3744 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
3745 pragma No_Return (Error_Pragma_Arg);
3746 -- Similar to above form of Error_Pragma_Arg except that two messages
3747 -- are provided, the second is a continuation comment starting with \.
3748
3749 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
3750 pragma No_Return (Error_Pragma_Arg_Ident);
3751 -- Outputs error message for current pragma. The message may contain a %
3752 -- that will be replaced with the pragma name. The parameter Arg must be
3753 -- a pragma argument association with a non-empty identifier (i.e. its
3754 -- Chars field must be set), and the error message is placed on the
3755 -- identifier. The message is placed using Error_Msg_N so the message
3756 -- may also contain an & insertion character which will reference
3757 -- the identifier. After placing the message, Pragma_Exit is raised.
3758 -- Note: this routine calls Fix_Error (see spec of that procedure for
3759 -- details).
3760
3761 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
3762 pragma No_Return (Error_Pragma_Ref);
3763 -- Outputs error message for current pragma. The message may contain
3764 -- a % that will be replaced with the pragma name. The parameter Ref
3765 -- must be an entity whose name can be referenced by & and sloc by #.
3766 -- After placing the message, Pragma_Exit is raised. Note: this routine
3767 -- calls Fix_Error (see spec of that procedure for details).
3768
3769 function Find_Lib_Unit_Name return Entity_Id;
3770 -- Used for a library unit pragma to find the entity to which the
3771 -- library unit pragma applies, returns the entity found.
3772
3773 procedure Find_Program_Unit_Name (Id : Node_Id);
3774 -- If the pragma is a compilation unit pragma, the id must denote the
3775 -- compilation unit in the same compilation, and the pragma must appear
3776 -- in the list of preceding or trailing pragmas. If it is a program
3777 -- unit pragma that is not a compilation unit pragma, then the
3778 -- identifier must be visible.
3779
3780 function Find_Unique_Parameterless_Procedure
3781 (Name : Entity_Id;
3782 Arg : Node_Id) return Entity_Id;
3783 -- Used for a procedure pragma to find the unique parameterless
3784 -- procedure identified by Name, returns it if it exists, otherwise
3785 -- errors out and uses Arg as the pragma argument for the message.
3786
3787 function Fix_Error (Msg : String) return String;
3788 -- This is called prior to issuing an error message. Msg is the normal
3789 -- error message issued in the pragma case. This routine checks for the
3790 -- case of a pragma coming from an aspect in the source, and returns a
3791 -- message suitable for the aspect case as follows:
3792 --
3793 -- Each substring "pragma" is replaced by "aspect"
3794 --
3795 -- If "argument of" is at the start of the error message text, it is
3796 -- replaced by "entity for".
3797 --
3798 -- If "argument" is at the start of the error message text, it is
3799 -- replaced by "entity".
3800 --
3801 -- So for example, "argument of pragma X must be discrete type"
3802 -- returns "entity for aspect X must be a discrete type".
3803
3804 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
3805 -- be different from the pragma name). If the current pragma results
3806 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
3807 -- original pragma name.
3808
3809 procedure Gather_Associations
3810 (Names : Name_List;
3811 Args : out Args_List);
3812 -- This procedure is used to gather the arguments for a pragma that
3813 -- permits arbitrary ordering of parameters using the normal rules
3814 -- for named and positional parameters. The Names argument is a list
3815 -- of Name_Id values that corresponds to the allowed pragma argument
3816 -- association identifiers in order. The result returned in Args is
3817 -- a list of corresponding expressions that are the pragma arguments.
3818 -- Note that this is a list of expressions, not of pragma argument
3819 -- associations (Gather_Associations has completely checked all the
3820 -- optional identifiers when it returns). An entry in Args is Empty
3821 -- on return if the corresponding argument is not present.
3822
3823 procedure GNAT_Pragma;
3824 -- Called for all GNAT defined pragmas to check the relevant restriction
3825 -- (No_Implementation_Pragmas).
3826
3827 function Is_Before_First_Decl
3828 (Pragma_Node : Node_Id;
3829 Decls : List_Id) return Boolean;
3830 -- Return True if Pragma_Node is before the first declarative item in
3831 -- Decls where Decls is the list of declarative items.
3832
3833 function Is_Configuration_Pragma return Boolean;
3834 -- Determines if the placement of the current pragma is appropriate
3835 -- for a configuration pragma.
3836
3837 function Is_In_Context_Clause return Boolean;
3838 -- Returns True if pragma appears within the context clause of a unit,
3839 -- and False for any other placement (does not generate any messages).
3840
3841 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
3842 -- Analyzes the argument, and determines if it is a static string
3843 -- expression, returns True if so, False if non-static or not String.
3844 -- A special case is that a string literal returns True in Ada 83 mode
3845 -- (which has no such thing as static string expressions). Note that
3846 -- the call analyzes its argument, so this cannot be used for the case
3847 -- where an identifier might not be declared.
3848
3849 procedure Pragma_Misplaced;
3850 pragma No_Return (Pragma_Misplaced);
3851 -- Issue fatal error message for misplaced pragma
3852
3853 procedure Process_Atomic_Independent_Shared_Volatile;
3854 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
3855 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
3856 -- and treated as being identical in effect to pragma Atomic.
3857
3858 procedure Process_Compile_Time_Warning_Or_Error;
3859 -- Common processing for Compile_Time_Error and Compile_Time_Warning
3860
3861 procedure Process_Convention
3862 (C : out Convention_Id;
3863 Ent : out Entity_Id);
3864 -- Common processing for Convention, Interface, Import and Export.
3865 -- Checks first two arguments of pragma, and sets the appropriate
3866 -- convention value in the specified entity or entities. On return
3867 -- C is the convention, Ent is the referenced entity.
3868
3869 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
3870 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
3871 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
3872
3873 procedure Process_Extended_Import_Export_Object_Pragma
3874 (Arg_Internal : Node_Id;
3875 Arg_External : Node_Id;
3876 Arg_Size : Node_Id);
3877 -- Common processing for the pragmas Import/Export_Object. The three
3878 -- arguments correspond to the three named parameters of the pragmas. An
3879 -- argument is empty if the corresponding parameter is not present in
3880 -- the pragma.
3881
3882 procedure Process_Extended_Import_Export_Internal_Arg
3883 (Arg_Internal : Node_Id := Empty);
3884 -- Common processing for all extended Import and Export pragmas. The
3885 -- argument is the pragma parameter for the Internal argument. If
3886 -- Arg_Internal is empty or inappropriate, an error message is posted.
3887 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
3888 -- set to identify the referenced entity.
3889
3890 procedure Process_Extended_Import_Export_Subprogram_Pragma
3891 (Arg_Internal : Node_Id;
3892 Arg_External : Node_Id;
3893 Arg_Parameter_Types : Node_Id;
3894 Arg_Result_Type : Node_Id := Empty;
3895 Arg_Mechanism : Node_Id;
3896 Arg_Result_Mechanism : Node_Id := Empty);
3897 -- Common processing for all extended Import and Export pragmas applying
3898 -- to subprograms. The caller omits any arguments that do not apply to
3899 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
3900 -- only in the Import_Function and Export_Function cases). The argument
3901 -- names correspond to the allowed pragma association identifiers.
3902
3903 procedure Process_Generic_List;
3904 -- Common processing for Share_Generic and Inline_Generic
3905
3906 procedure Process_Import_Or_Interface;
3907 -- Common processing for Import or Interface
3908
3909 procedure Process_Import_Predefined_Type;
3910 -- Processing for completing a type with pragma Import. This is used
3911 -- to declare types that match predefined C types, especially for cases
3912 -- without corresponding Ada predefined type.
3913
3914 type Inline_Status is (Suppressed, Disabled, Enabled);
3915 -- Inline status of a subprogram, indicated as follows:
3916 -- Suppressed: inlining is suppressed for the subprogram
3917 -- Disabled: no inlining is requested for the subprogram
3918 -- Enabled: inlining is requested/required for the subprogram
3919
3920 procedure Process_Inline (Status : Inline_Status);
3921 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
3922 -- indicates the inline status specified by the pragma.
3923
3924 procedure Process_Interface_Name
3925 (Subprogram_Def : Entity_Id;
3926 Ext_Arg : Node_Id;
3927 Link_Arg : Node_Id;
3928 Prag : Node_Id);
3929 -- Given the last two arguments of pragma Import, pragma Export, or
3930 -- pragma Interface_Name, performs validity checks and sets the
3931 -- Interface_Name field of the given subprogram entity to the
3932 -- appropriate external or link name, depending on the arguments given.
3933 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
3934 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
3935 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
3936 -- nor Link_Arg is present, the interface name is set to the default
3937 -- from the subprogram name. In addition, the pragma itself is passed
3938 -- to analyze any expressions in the case the pragma came from an aspect
3939 -- specification.
3940
3941 procedure Process_Interrupt_Or_Attach_Handler;
3942 -- Common processing for Interrupt and Attach_Handler pragmas
3943
3944 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
3945 -- Common processing for Restrictions and Restriction_Warnings pragmas.
3946 -- Warn is True for Restriction_Warnings, or for Restrictions if the
3947 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
3948 -- is not set in the Restrictions case.
3949
3950 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
3951 -- Common processing for Suppress and Unsuppress. The boolean parameter
3952 -- Suppress_Case is True for the Suppress case, and False for the
3953 -- Unsuppress case.
3954
3955 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
3956 -- Subsidiary to the analysis of pragmas Independent[_Components].
3957 -- Record such a pragma N applied to entity E for future checks.
3958
3959 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
3960 -- This procedure sets the Is_Exported flag for the given entity,
3961 -- checking that the entity was not previously imported. Arg is
3962 -- the argument that specified the entity. A check is also made
3963 -- for exporting inappropriate entities.
3964
3965 procedure Set_Extended_Import_Export_External_Name
3966 (Internal_Ent : Entity_Id;
3967 Arg_External : Node_Id);
3968 -- Common processing for all extended import export pragmas. The first
3969 -- argument, Internal_Ent, is the internal entity, which has already
3970 -- been checked for validity by the caller. Arg_External is from the
3971 -- Import or Export pragma, and may be null if no External parameter
3972 -- was present. If Arg_External is present and is a non-null string
3973 -- (a null string is treated as the default), then the Interface_Name
3974 -- field of Internal_Ent is set appropriately.
3975
3976 procedure Set_Imported (E : Entity_Id);
3977 -- This procedure sets the Is_Imported flag for the given entity,
3978 -- checking that it is not previously exported or imported.
3979
3980 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
3981 -- Mech is a parameter passing mechanism (see Import_Function syntax
3982 -- for MECHANISM_NAME). This routine checks that the mechanism argument
3983 -- has the right form, and if not issues an error message. If the
3984 -- argument has the right form then the Mechanism field of Ent is
3985 -- set appropriately.
3986
3987 procedure Set_Rational_Profile;
3988 -- Activate the set of configuration pragmas and permissions that make
3989 -- up the Rational profile.
3990
3991 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id);
3992 -- Activate the set of configuration pragmas and restrictions that make
3993 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
3994 -- GNAT_Ravenscar_EDF, or Ravenscar. N is the corresponding pragma node,
3995 -- which is used for error messages on any constructs violating the
3996 -- profile.
3997
3998 ----------------------------------
3999 -- Acquire_Warning_Match_String --
4000 ----------------------------------
4001
4002 procedure Acquire_Warning_Match_String (Arg : Node_Id) is
4003 begin
4004 String_To_Name_Buffer
4005 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
4006
4007 -- Add asterisk at start if not already there
4008
4009 if Name_Len > 0 and then Name_Buffer (1) /= '*' then
4010 Name_Buffer (2 .. Name_Len + 1) :=
4011 Name_Buffer (1 .. Name_Len);
4012 Name_Buffer (1) := '*';
4013 Name_Len := Name_Len + 1;
4014 end if;
4015
4016 -- Add asterisk at end if not already there
4017
4018 if Name_Buffer (Name_Len) /= '*' then
4019 Name_Len := Name_Len + 1;
4020 Name_Buffer (Name_Len) := '*';
4021 end if;
4022 end Acquire_Warning_Match_String;
4023
4024 ---------------------
4025 -- Ada_2005_Pragma --
4026 ---------------------
4027
4028 procedure Ada_2005_Pragma is
4029 begin
4030 if Ada_Version <= Ada_95 then
4031 Check_Restriction (No_Implementation_Pragmas, N);
4032 end if;
4033 end Ada_2005_Pragma;
4034
4035 ---------------------
4036 -- Ada_2012_Pragma --
4037 ---------------------
4038
4039 procedure Ada_2012_Pragma is
4040 begin
4041 if Ada_Version <= Ada_2005 then
4042 Check_Restriction (No_Implementation_Pragmas, N);
4043 end if;
4044 end Ada_2012_Pragma;
4045
4046 ----------------------------
4047 -- Analyze_Depends_Global --
4048 ----------------------------
4049
4050 procedure Analyze_Depends_Global
4051 (Spec_Id : out Entity_Id;
4052 Subp_Decl : out Node_Id;
4053 Legal : out Boolean)
4054 is
4055 begin
4056 -- Assume that the pragma is illegal
4057
4058 Spec_Id := Empty;
4059 Subp_Decl := Empty;
4060 Legal := False;
4061
4062 GNAT_Pragma;
4063 Check_Arg_Count (1);
4064
4065 -- Ensure the proper placement of the pragma. Depends/Global must be
4066 -- associated with a subprogram declaration or a body that acts as a
4067 -- spec.
4068
4069 Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4070
4071 -- Entry
4072
4073 if Nkind (Subp_Decl) = N_Entry_Declaration then
4074 null;
4075
4076 -- Generic subprogram
4077
4078 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4079 null;
4080
4081 -- Object declaration of a single concurrent type
4082
4083 elsif Nkind (Subp_Decl) = N_Object_Declaration
4084 and then Is_Single_Concurrent_Object
4085 (Unique_Defining_Entity (Subp_Decl))
4086 then
4087 null;
4088
4089 -- Single task type
4090
4091 elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then
4092 null;
4093
4094 -- Subprogram body acts as spec
4095
4096 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4097 and then No (Corresponding_Spec (Subp_Decl))
4098 then
4099 null;
4100
4101 -- Subprogram body stub acts as spec
4102
4103 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4104 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
4105 then
4106 null;
4107
4108 -- Subprogram declaration
4109
4110 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4111 null;
4112
4113 -- Task type
4114
4115 elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then
4116 null;
4117
4118 else
4119 Pragma_Misplaced;
4120 return;
4121 end if;
4122
4123 -- If we get here, then the pragma is legal
4124
4125 Legal := True;
4126 Spec_Id := Unique_Defining_Entity (Subp_Decl);
4127
4128 -- When the related context is an entry, the entry must belong to a
4129 -- protected unit (SPARK RM 6.1.4(6)).
4130
4131 if Is_Entry_Declaration (Spec_Id)
4132 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
4133 then
4134 Pragma_Misplaced;
4135 return;
4136
4137 -- When the related context is an anonymous object created for a
4138 -- simple concurrent type, the type must be a task
4139 -- (SPARK RM 6.1.4(6)).
4140
4141 elsif Is_Single_Concurrent_Object (Spec_Id)
4142 and then Ekind (Etype (Spec_Id)) /= E_Task_Type
4143 then
4144 Pragma_Misplaced;
4145 return;
4146 end if;
4147
4148 -- A pragma that applies to a Ghost entity becomes Ghost for the
4149 -- purposes of legality checks and removal of ignored Ghost code.
4150
4151 Mark_Ghost_Pragma (N, Spec_Id);
4152 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4153 end Analyze_Depends_Global;
4154
4155 ------------------------
4156 -- Analyze_If_Present --
4157 ------------------------
4158
4159 procedure Analyze_If_Present (Id : Pragma_Id) is
4160 Stmt : Node_Id;
4161
4162 begin
4163 pragma Assert (Is_List_Member (N));
4164
4165 -- Inspect the declarations or statements following pragma N looking
4166 -- for another pragma whose Id matches the caller's request. If it is
4167 -- available, analyze it.
4168
4169 Stmt := Next (N);
4170 while Present (Stmt) loop
4171 if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then
4172 Analyze_Pragma (Stmt);
4173 exit;
4174
4175 -- The first source declaration or statement immediately following
4176 -- N ends the region where a pragma may appear.
4177
4178 elsif Comes_From_Source (Stmt) then
4179 exit;
4180 end if;
4181
4182 Next (Stmt);
4183 end loop;
4184 end Analyze_If_Present;
4185
4186 --------------------------------
4187 -- Analyze_Pre_Post_Condition --
4188 --------------------------------
4189
4190 procedure Analyze_Pre_Post_Condition is
4191 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
4192 Subp_Decl : Node_Id;
4193 Subp_Id : Entity_Id;
4194
4195 Duplicates_OK : Boolean := False;
4196 -- Flag set when a pre/postcondition allows multiple pragmas of the
4197 -- same kind.
4198
4199 In_Body_OK : Boolean := False;
4200 -- Flag set when a pre/postcondition is allowed to appear on a body
4201 -- even though the subprogram may have a spec.
4202
4203 Is_Pre_Post : Boolean := False;
4204 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4205 -- Post_Class.
4206
4207 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean;
4208 -- Implement rules in AI12-0131: an overriding operation can have
4209 -- a class-wide precondition only if one of its ancestors has an
4210 -- explicit class-wide precondition.
4211
4212 -----------------------------
4213 -- Inherits_Class_Wide_Pre --
4214 -----------------------------
4215
4216 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean is
4217 Typ : constant Entity_Id := Find_Dispatching_Type (E);
4218 Cont : Node_Id;
4219 Prag : Node_Id;
4220 Prev : Entity_Id := Overridden_Operation (E);
4221
4222 begin
4223 -- Check ancestors on the overriding operation to examine the
4224 -- preconditions that may apply to them.
4225
4226 while Present (Prev) loop
4227 Cont := Contract (Prev);
4228 if Present (Cont) then
4229 Prag := Pre_Post_Conditions (Cont);
4230 while Present (Prag) loop
4231 if Class_Present (Prag) then
4232 return True;
4233 end if;
4234
4235 Prag := Next_Pragma (Prag);
4236 end loop;
4237 end if;
4238
4239 -- For a type derived from a generic formal type, the operation
4240 -- inheriting the condition is a renaming, not an overriding of
4241 -- the operation of the formal. Ditto for an inherited
4242 -- operation which has no explicit contracts.
4243
4244 if Is_Generic_Type (Find_Dispatching_Type (Prev))
4245 or else not Comes_From_Source (Prev)
4246 then
4247 Prev := Alias (Prev);
4248 else
4249 Prev := Overridden_Operation (Prev);
4250 end if;
4251 end loop;
4252
4253 -- If the controlling type of the subprogram has progenitors, an
4254 -- interface operation implemented by the current operation may
4255 -- have a class-wide precondition.
4256
4257 if Has_Interfaces (Typ) then
4258 declare
4259 Elmt : Elmt_Id;
4260 Ints : Elist_Id;
4261 Prim : Entity_Id;
4262 Prim_Elmt : Elmt_Id;
4263 Prim_List : Elist_Id;
4264
4265 begin
4266 Collect_Interfaces (Typ, Ints);
4267 Elmt := First_Elmt (Ints);
4268
4269 -- Iterate over the primitive operations of each interface
4270
4271 while Present (Elmt) loop
4272 Prim_List := Direct_Primitive_Operations (Node (Elmt));
4273 Prim_Elmt := First_Elmt (Prim_List);
4274 while Present (Prim_Elmt) loop
4275 Prim := Node (Prim_Elmt);
4276 if Chars (Prim) = Chars (E)
4277 and then Present (Contract (Prim))
4278 and then Class_Present
4279 (Pre_Post_Conditions (Contract (Prim)))
4280 then
4281 return True;
4282 end if;
4283
4284 Next_Elmt (Prim_Elmt);
4285 end loop;
4286
4287 Next_Elmt (Elmt);
4288 end loop;
4289 end;
4290 end if;
4291
4292 return False;
4293 end Inherits_Class_Wide_Pre;
4294
4295 -- Start of processing for Analyze_Pre_Post_Condition
4296
4297 begin
4298 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4299 -- offer uniformity among the various kinds of pre/postconditions by
4300 -- rewriting the pragma identifier. This allows the retrieval of the
4301 -- original pragma name by routine Original_Aspect_Pragma_Name.
4302
4303 if Comes_From_Source (N) then
4304 if Nam_In (Pname, Name_Pre, Name_Pre_Class) then
4305 Is_Pre_Post := True;
4306 Set_Class_Present (N, Pname = Name_Pre_Class);
4307 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
4308
4309 elsif Nam_In (Pname, Name_Post, Name_Post_Class) then
4310 Is_Pre_Post := True;
4311 Set_Class_Present (N, Pname = Name_Post_Class);
4312 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
4313 end if;
4314 end if;
4315
4316 -- Determine the semantics with respect to duplicates and placement
4317 -- in a body. Pragmas Precondition and Postcondition were introduced
4318 -- before aspects and are not subject to the same aspect-like rules.
4319
4320 if Nam_In (Pname, Name_Precondition, Name_Postcondition) then
4321 Duplicates_OK := True;
4322 In_Body_OK := True;
4323 end if;
4324
4325 GNAT_Pragma;
4326
4327 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4328 -- argument without an identifier.
4329
4330 if Is_Pre_Post then
4331 Check_Arg_Count (1);
4332 Check_No_Identifiers;
4333
4334 -- Pragmas Precondition and Postcondition have complex argument
4335 -- profile.
4336
4337 else
4338 Check_At_Least_N_Arguments (1);
4339 Check_At_Most_N_Arguments (2);
4340 Check_Optional_Identifier (Arg1, Name_Check);
4341
4342 if Present (Arg2) then
4343 Check_Optional_Identifier (Arg2, Name_Message);
4344 Preanalyze_Spec_Expression
4345 (Get_Pragma_Arg (Arg2), Standard_String);
4346 end if;
4347 end if;
4348
4349 -- For a pragma PPC in the extended main source unit, record enabled
4350 -- status in SCO.
4351 -- ??? nothing checks that the pragma is in the main source unit
4352
4353 if Is_Checked (N) and then not Split_PPC (N) then
4354 Set_SCO_Pragma_Enabled (Loc);
4355 end if;
4356
4357 -- Ensure the proper placement of the pragma
4358
4359 Subp_Decl :=
4360 Find_Related_Declaration_Or_Body
4361 (N, Do_Checks => not Duplicates_OK);
4362
4363 -- When a pre/postcondition pragma applies to an abstract subprogram,
4364 -- its original form must be an aspect with 'Class.
4365
4366 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4367 if not From_Aspect_Specification (N) then
4368 Error_Pragma
4369 ("pragma % cannot be applied to abstract subprogram");
4370
4371 elsif not Class_Present (N) then
4372 Error_Pragma
4373 ("aspect % requires ''Class for abstract subprogram");
4374 end if;
4375
4376 -- Entry declaration
4377
4378 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
4379 null;
4380
4381 -- Generic subprogram declaration
4382
4383 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4384 null;
4385
4386 -- Subprogram body
4387
4388 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4389 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
4390 then
4391 null;
4392
4393 -- Subprogram body stub
4394
4395 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4396 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
4397 then
4398 null;
4399
4400 -- Subprogram declaration
4401
4402 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4403
4404 -- AI05-0230: When a pre/postcondition pragma applies to a null
4405 -- procedure, its original form must be an aspect with 'Class.
4406
4407 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4408 and then Null_Present (Specification (Subp_Decl))
4409 and then From_Aspect_Specification (N)
4410 and then not Class_Present (N)
4411 then
4412 Error_Pragma ("aspect % requires ''Class for null procedure");
4413 end if;
4414
4415 -- Implement the legality checks mandated by AI12-0131:
4416 -- Pre'Class shall not be specified for an overriding primitive
4417 -- subprogram of a tagged type T unless the Pre'Class aspect is
4418 -- specified for the corresponding primitive subprogram of some
4419 -- ancestor of T.
4420
4421 declare
4422 E : constant Entity_Id := Defining_Entity (Subp_Decl);
4423
4424 begin
4425 if Class_Present (N)
4426 and then Pragma_Name (N) = Name_Precondition
4427 and then Present (Overridden_Operation (E))
4428 and then not Inherits_Class_Wide_Pre (E)
4429 then
4430 Error_Msg_N
4431 ("illegal class-wide precondition on overriding operation",
4432 Corresponding_Aspect (N));
4433 end if;
4434 end;
4435
4436 -- A renaming declaration may inherit a generated pragma, its
4437 -- placement comes from expansion, not from source.
4438
4439 elsif Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
4440 and then not Comes_From_Source (N)
4441 then
4442 null;
4443
4444 -- Otherwise the placement is illegal
4445
4446 else
4447 Pragma_Misplaced;
4448 return;
4449 end if;
4450
4451 Subp_Id := Defining_Entity (Subp_Decl);
4452
4453 -- A pragma that applies to a Ghost entity becomes Ghost for the
4454 -- purposes of legality checks and removal of ignored Ghost code.
4455
4456 Mark_Ghost_Pragma (N, Subp_Id);
4457
4458 -- Chain the pragma on the contract for further processing by
4459 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4460
4461 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
4462
4463 -- Fully analyze the pragma when it appears inside an entry or
4464 -- subprogram body because it cannot benefit from forward references.
4465
4466 if Nkind_In (Subp_Decl, N_Entry_Body,
4467 N_Subprogram_Body,
4468 N_Subprogram_Body_Stub)
4469 then
4470 -- The legality checks of pragmas Precondition and Postcondition
4471 -- are affected by the SPARK mode in effect and the volatility of
4472 -- the context. Analyze all pragmas in a specific order.
4473
4474 Analyze_If_Present (Pragma_SPARK_Mode);
4475 Analyze_If_Present (Pragma_Volatile_Function);
4476 Analyze_Pre_Post_Condition_In_Decl_Part (N);
4477 end if;
4478 end Analyze_Pre_Post_Condition;
4479
4480 -----------------------------------------
4481 -- Analyze_Refined_Depends_Global_Post --
4482 -----------------------------------------
4483
4484 procedure Analyze_Refined_Depends_Global_Post
4485 (Spec_Id : out Entity_Id;
4486 Body_Id : out Entity_Id;
4487 Legal : out Boolean)
4488 is
4489 Body_Decl : Node_Id;
4490 Spec_Decl : Node_Id;
4491
4492 begin
4493 -- Assume that the pragma is illegal
4494
4495 Spec_Id := Empty;
4496 Body_Id := Empty;
4497 Legal := False;
4498
4499 GNAT_Pragma;
4500 Check_Arg_Count (1);
4501 Check_No_Identifiers;
4502
4503 -- Verify the placement of the pragma and check for duplicates. The
4504 -- pragma must apply to a subprogram body [stub].
4505
4506 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4507
4508 -- Entry body
4509
4510 if Nkind (Body_Decl) = N_Entry_Body then
4511 null;
4512
4513 -- Subprogram body
4514
4515 elsif Nkind (Body_Decl) = N_Subprogram_Body then
4516 null;
4517
4518 -- Subprogram body stub
4519
4520 elsif Nkind (Body_Decl) = N_Subprogram_Body_Stub then
4521 null;
4522
4523 -- Task body
4524
4525 elsif Nkind (Body_Decl) = N_Task_Body then
4526 null;
4527
4528 else
4529 Pragma_Misplaced;
4530 return;
4531 end if;
4532
4533 Body_Id := Defining_Entity (Body_Decl);
4534 Spec_Id := Unique_Defining_Entity (Body_Decl);
4535
4536 -- The pragma must apply to the second declaration of a subprogram.
4537 -- In other words, the body [stub] cannot acts as a spec.
4538
4539 if No (Spec_Id) then
4540 Error_Pragma ("pragma % cannot apply to a stand alone body");
4541 return;
4542
4543 -- Catch the case where the subprogram body is a subunit and acts as
4544 -- the third declaration of the subprogram.
4545
4546 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
4547 Error_Pragma ("pragma % cannot apply to a subunit");
4548 return;
4549 end if;
4550
4551 -- A refined pragma can only apply to the body [stub] of a subprogram
4552 -- declared in the visible part of a package. Retrieve the context of
4553 -- the subprogram declaration.
4554
4555 Spec_Decl := Unit_Declaration_Node (Spec_Id);
4556
4557 -- When dealing with protected entries or protected subprograms, use
4558 -- the enclosing protected type as the proper context.
4559
4560 if Ekind_In (Spec_Id, E_Entry,
4561 E_Entry_Family,
4562 E_Function,
4563 E_Procedure)
4564 and then Ekind (Scope (Spec_Id)) = E_Protected_Type
4565 then
4566 Spec_Decl := Declaration_Node (Scope (Spec_Id));
4567 end if;
4568
4569 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
4570 Error_Pragma
4571 (Fix_Msg (Spec_Id, "pragma % must apply to the body of "
4572 & "subprogram declared in a package specification"));
4573 return;
4574 end if;
4575
4576 -- If we get here, then the pragma is legal
4577
4578 Legal := True;
4579
4580 -- A pragma that applies to a Ghost entity becomes Ghost for the
4581 -- purposes of legality checks and removal of ignored Ghost code.
4582
4583 Mark_Ghost_Pragma (N, Spec_Id);
4584
4585 if Nam_In (Pname, Name_Refined_Depends, Name_Refined_Global) then
4586 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4587 end if;
4588 end Analyze_Refined_Depends_Global_Post;
4589
4590 ----------------------------------
4591 -- Analyze_Unmodified_Or_Unused --
4592 ----------------------------------
4593
4594 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False) is
4595 Arg : Node_Id;
4596 Arg_Expr : Node_Id;
4597 Arg_Id : Entity_Id;
4598
4599 Ghost_Error_Posted : Boolean := False;
4600 -- Flag set when an error concerning the illegal mix of Ghost and
4601 -- non-Ghost variables is emitted.
4602
4603 Ghost_Id : Entity_Id := Empty;
4604 -- The entity of the first Ghost variable encountered while
4605 -- processing the arguments of the pragma.
4606
4607 begin
4608 GNAT_Pragma;
4609 Check_At_Least_N_Arguments (1);
4610
4611 -- Loop through arguments
4612
4613 Arg := Arg1;
4614 while Present (Arg) loop
4615 Check_No_Identifier (Arg);
4616
4617 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4618 -- in fact generate reference, so that the entity will have a
4619 -- reference, which will inhibit any warnings about it not
4620 -- being referenced, and also properly show up in the ali file
4621 -- as a reference. But this reference is recorded before the
4622 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4623 -- generated for this reference.
4624
4625 Check_Arg_Is_Local_Name (Arg);
4626 Arg_Expr := Get_Pragma_Arg (Arg);
4627
4628 if Is_Entity_Name (Arg_Expr) then
4629 Arg_Id := Entity (Arg_Expr);
4630
4631 -- Skip processing the argument if already flagged
4632
4633 if Is_Assignable (Arg_Id)
4634 and then not Has_Pragma_Unmodified (Arg_Id)
4635 and then not Has_Pragma_Unused (Arg_Id)
4636 then
4637 Set_Has_Pragma_Unmodified (Arg_Id);
4638
4639 if Is_Unused then
4640 Set_Has_Pragma_Unused (Arg_Id);
4641 end if;
4642
4643 -- A pragma that applies to a Ghost entity becomes Ghost for
4644 -- the purposes of legality checks and removal of ignored
4645 -- Ghost code.
4646
4647 Mark_Ghost_Pragma (N, Arg_Id);
4648
4649 -- Capture the entity of the first Ghost variable being
4650 -- processed for error detection purposes.
4651
4652 if Is_Ghost_Entity (Arg_Id) then
4653 if No (Ghost_Id) then
4654 Ghost_Id := Arg_Id;
4655 end if;
4656
4657 -- Otherwise the variable is non-Ghost. It is illegal to mix
4658 -- references to Ghost and non-Ghost entities
4659 -- (SPARK RM 6.9).
4660
4661 elsif Present (Ghost_Id)
4662 and then not Ghost_Error_Posted
4663 then
4664 Ghost_Error_Posted := True;
4665
4666 Error_Msg_Name_1 := Pname;
4667 Error_Msg_N
4668 ("pragma % cannot mention ghost and non-ghost "
4669 & "variables", N);
4670
4671 Error_Msg_Sloc := Sloc (Ghost_Id);
4672 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
4673
4674 Error_Msg_Sloc := Sloc (Arg_Id);
4675 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
4676 end if;
4677
4678 -- Warn if already flagged as Unused or Unmodified
4679
4680 elsif Has_Pragma_Unmodified (Arg_Id) then
4681 if Has_Pragma_Unused (Arg_Id) then
4682 Error_Msg_NE
4683 ("??pragma Unused already given for &!", Arg_Expr,
4684 Arg_Id);
4685 else
4686 Error_Msg_NE
4687 ("??pragma Unmodified already given for &!", Arg_Expr,
4688 Arg_Id);
4689 end if;
4690
4691 -- Otherwise the pragma referenced an illegal entity
4692
4693 else
4694 Error_Pragma_Arg
4695 ("pragma% can only be applied to a variable", Arg_Expr);
4696 end if;
4697 end if;
4698
4699 Next (Arg);
4700 end loop;
4701 end Analyze_Unmodified_Or_Unused;
4702
4703 -----------------------------------
4704 -- Analyze_Unreference_Or_Unused --
4705 -----------------------------------
4706
4707 procedure Analyze_Unreferenced_Or_Unused
4708 (Is_Unused : Boolean := False)
4709 is
4710 Arg : Node_Id;
4711 Arg_Expr : Node_Id;
4712 Arg_Id : Entity_Id;
4713 Citem : Node_Id;
4714
4715 Ghost_Error_Posted : Boolean := False;
4716 -- Flag set when an error concerning the illegal mix of Ghost and
4717 -- non-Ghost names is emitted.
4718
4719 Ghost_Id : Entity_Id := Empty;
4720 -- The entity of the first Ghost name encountered while processing
4721 -- the arguments of the pragma.
4722
4723 begin
4724 GNAT_Pragma;
4725 Check_At_Least_N_Arguments (1);
4726
4727 -- Check case of appearing within context clause
4728
4729 if not Is_Unused and then Is_In_Context_Clause then
4730
4731 -- The arguments must all be units mentioned in a with clause in
4732 -- the same context clause. Note that Par.Prag already checked
4733 -- that the arguments are either identifiers or selected
4734 -- components.
4735
4736 Arg := Arg1;
4737 while Present (Arg) loop
4738 Citem := First (List_Containing (N));
4739 while Citem /= N loop
4740 Arg_Expr := Get_Pragma_Arg (Arg);
4741
4742 if Nkind (Citem) = N_With_Clause
4743 and then Same_Name (Name (Citem), Arg_Expr)
4744 then
4745 Set_Has_Pragma_Unreferenced
4746 (Cunit_Entity
4747 (Get_Source_Unit
4748 (Library_Unit (Citem))));
4749 Set_Elab_Unit_Name (Arg_Expr, Name (Citem));
4750 exit;
4751 end if;
4752
4753 Next (Citem);
4754 end loop;
4755
4756 if Citem = N then
4757 Error_Pragma_Arg
4758 ("argument of pragma% is not withed unit", Arg);
4759 end if;
4760
4761 Next (Arg);
4762 end loop;
4763
4764 -- Case of not in list of context items
4765
4766 else
4767 Arg := Arg1;
4768 while Present (Arg) loop
4769 Check_No_Identifier (Arg);
4770
4771 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4772 -- in fact generate reference, so that the entity will have a
4773 -- reference, which will inhibit any warnings about it not
4774 -- being referenced, and also properly show up in the ali file
4775 -- as a reference. But this reference is recorded before the
4776 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4777 -- generated for this reference.
4778
4779 Check_Arg_Is_Local_Name (Arg);
4780 Arg_Expr := Get_Pragma_Arg (Arg);
4781
4782 if Is_Entity_Name (Arg_Expr) then
4783 Arg_Id := Entity (Arg_Expr);
4784
4785 -- Warn if already flagged as Unused or Unreferenced and
4786 -- skip processing the argument.
4787
4788 if Has_Pragma_Unreferenced (Arg_Id) then
4789 if Has_Pragma_Unused (Arg_Id) then
4790 Error_Msg_NE
4791 ("??pragma Unused already given for &!", Arg_Expr,
4792 Arg_Id);
4793 else
4794 Error_Msg_NE
4795 ("??pragma Unreferenced already given for &!",
4796 Arg_Expr, Arg_Id);
4797 end if;
4798
4799 -- Apply Unreferenced to the entity
4800
4801 else
4802 -- If the entity is overloaded, the pragma applies to the
4803 -- most recent overloading, as documented. In this case,
4804 -- name resolution does not generate a reference, so it
4805 -- must be done here explicitly.
4806
4807 if Is_Overloaded (Arg_Expr) then
4808 Generate_Reference (Arg_Id, N);
4809 end if;
4810
4811 Set_Has_Pragma_Unreferenced (Arg_Id);
4812
4813 if Is_Unused then
4814 Set_Has_Pragma_Unused (Arg_Id);
4815 end if;
4816
4817 -- A pragma that applies to a Ghost entity becomes Ghost
4818 -- for the purposes of legality checks and removal of
4819 -- ignored Ghost code.
4820
4821 Mark_Ghost_Pragma (N, Arg_Id);
4822
4823 -- Capture the entity of the first Ghost name being
4824 -- processed for error detection purposes.
4825
4826 if Is_Ghost_Entity (Arg_Id) then
4827 if No (Ghost_Id) then
4828 Ghost_Id := Arg_Id;
4829 end if;
4830
4831 -- Otherwise the name is non-Ghost. It is illegal to mix
4832 -- references to Ghost and non-Ghost entities
4833 -- (SPARK RM 6.9).
4834
4835 elsif Present (Ghost_Id)
4836 and then not Ghost_Error_Posted
4837 then
4838 Ghost_Error_Posted := True;
4839
4840 Error_Msg_Name_1 := Pname;
4841 Error_Msg_N
4842 ("pragma % cannot mention ghost and non-ghost "
4843 & "names", N);
4844
4845 Error_Msg_Sloc := Sloc (Ghost_Id);
4846 Error_Msg_NE
4847 ("\& # declared as ghost", N, Ghost_Id);
4848
4849 Error_Msg_Sloc := Sloc (Arg_Id);
4850 Error_Msg_NE
4851 ("\& # declared as non-ghost", N, Arg_Id);
4852 end if;
4853 end if;
4854 end if;
4855
4856 Next (Arg);
4857 end loop;
4858 end if;
4859 end Analyze_Unreferenced_Or_Unused;
4860
4861 --------------------------
4862 -- Check_Ada_83_Warning --
4863 --------------------------
4864
4865 procedure Check_Ada_83_Warning is
4866 begin
4867 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
4868 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
4869 end if;
4870 end Check_Ada_83_Warning;
4871
4872 ---------------------
4873 -- Check_Arg_Count --
4874 ---------------------
4875
4876 procedure Check_Arg_Count (Required : Nat) is
4877 begin
4878 if Arg_Count /= Required then
4879 Error_Pragma ("wrong number of arguments for pragma%");
4880 end if;
4881 end Check_Arg_Count;
4882
4883 --------------------------------
4884 -- Check_Arg_Is_External_Name --
4885 --------------------------------
4886
4887 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
4888 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4889
4890 begin
4891 if Nkind (Argx) = N_Identifier then
4892 return;
4893
4894 else
4895 Analyze_And_Resolve (Argx, Standard_String);
4896
4897 if Is_OK_Static_Expression (Argx) then
4898 return;
4899
4900 elsif Etype (Argx) = Any_Type then
4901 raise Pragma_Exit;
4902
4903 -- An interesting special case, if we have a string literal and
4904 -- we are in Ada 83 mode, then we allow it even though it will
4905 -- not be flagged as static. This allows expected Ada 83 mode
4906 -- use of external names which are string literals, even though
4907 -- technically these are not static in Ada 83.
4908
4909 elsif Ada_Version = Ada_83
4910 and then Nkind (Argx) = N_String_Literal
4911 then
4912 return;
4913
4914 -- Here we have a real error (non-static expression)
4915
4916 else
4917 Error_Msg_Name_1 := Pname;
4918 Flag_Non_Static_Expr
4919 (Fix_Error ("argument for pragma% must be a identifier or "
4920 & "static string expression!"), Argx);
4921
4922 raise Pragma_Exit;
4923 end if;
4924 end if;
4925 end Check_Arg_Is_External_Name;
4926
4927 -----------------------------
4928 -- Check_Arg_Is_Identifier --
4929 -----------------------------
4930
4931 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
4932 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4933 begin
4934 if Nkind (Argx) /= N_Identifier then
4935 Error_Pragma_Arg ("argument for pragma% must be identifier", Argx);
4936 end if;
4937 end Check_Arg_Is_Identifier;
4938
4939 ----------------------------------
4940 -- Check_Arg_Is_Integer_Literal --
4941 ----------------------------------
4942
4943 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
4944 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4945 begin
4946 if Nkind (Argx) /= N_Integer_Literal then
4947 Error_Pragma_Arg
4948 ("argument for pragma% must be integer literal", Argx);
4949 end if;
4950 end Check_Arg_Is_Integer_Literal;
4951
4952 -------------------------------------------
4953 -- Check_Arg_Is_Library_Level_Local_Name --
4954 -------------------------------------------
4955
4956 -- LOCAL_NAME ::=
4957 -- DIRECT_NAME
4958 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
4959 -- | library_unit_NAME
4960
4961 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
4962 begin
4963 Check_Arg_Is_Local_Name (Arg);
4964
4965 -- If it came from an aspect, we want to give the error just as if it
4966 -- came from source.
4967
4968 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
4969 and then (Comes_From_Source (N)
4970 or else Present (Corresponding_Aspect (Parent (Arg))))
4971 then
4972 Error_Pragma_Arg
4973 ("argument for pragma% must be library level entity", Arg);
4974 end if;
4975 end Check_Arg_Is_Library_Level_Local_Name;
4976
4977 -----------------------------
4978 -- Check_Arg_Is_Local_Name --
4979 -----------------------------
4980
4981 -- LOCAL_NAME ::=
4982 -- DIRECT_NAME
4983 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
4984 -- | library_unit_NAME
4985
4986 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
4987 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4988
4989 begin
4990 -- If this pragma came from an aspect specification, we don't want to
4991 -- check for this error, because that would cause spurious errors, in
4992 -- case a type is frozen in a scope more nested than the type. The
4993 -- aspect itself of course can't be anywhere but on the declaration
4994 -- itself.
4995
4996 if Nkind (Arg) = N_Pragma_Argument_Association then
4997 if From_Aspect_Specification (Parent (Arg)) then
4998 return;
4999 end if;
5000
5001 -- Arg is the Expression of an N_Pragma_Argument_Association
5002
5003 else
5004 if From_Aspect_Specification (Parent (Parent (Arg))) then
5005 return;
5006 end if;
5007 end if;
5008
5009 Analyze (Argx);
5010
5011 if Nkind (Argx) not in N_Direct_Name
5012 and then (Nkind (Argx) /= N_Attribute_Reference
5013 or else Present (Expressions (Argx))
5014 or else Nkind (Prefix (Argx)) /= N_Identifier)
5015 and then (not Is_Entity_Name (Argx)
5016 or else not Is_Compilation_Unit (Entity (Argx)))
5017 then
5018 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
5019 end if;
5020
5021 -- No further check required if not an entity name
5022
5023 if not Is_Entity_Name (Argx) then
5024 null;
5025
5026 else
5027 declare
5028 OK : Boolean;
5029 Ent : constant Entity_Id := Entity (Argx);
5030 Scop : constant Entity_Id := Scope (Ent);
5031
5032 begin
5033 -- Case of a pragma applied to a compilation unit: pragma must
5034 -- occur immediately after the program unit in the compilation.
5035
5036 if Is_Compilation_Unit (Ent) then
5037 declare
5038 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
5039
5040 begin
5041 -- Case of pragma placed immediately after spec
5042
5043 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
5044 OK := True;
5045
5046 -- Case of pragma placed immediately after body
5047
5048 elsif Nkind (Decl) = N_Subprogram_Declaration
5049 and then Present (Corresponding_Body (Decl))
5050 then
5051 OK := Parent (N) =
5052 Aux_Decls_Node
5053 (Parent (Unit_Declaration_Node
5054 (Corresponding_Body (Decl))));
5055
5056 -- All other cases are illegal
5057
5058 else
5059 OK := False;
5060 end if;
5061 end;
5062
5063 -- Special restricted placement rule from 10.2.1(11.8/2)
5064
5065 elsif Is_Generic_Formal (Ent)
5066 and then Prag_Id = Pragma_Preelaborable_Initialization
5067 then
5068 OK := List_Containing (N) =
5069 Generic_Formal_Declarations
5070 (Unit_Declaration_Node (Scop));
5071
5072 -- If this is an aspect applied to a subprogram body, the
5073 -- pragma is inserted in its declarative part.
5074
5075 elsif From_Aspect_Specification (N)
5076 and then Ent = Current_Scope
5077 and then
5078 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
5079 then
5080 OK := True;
5081
5082 -- If the aspect is a predicate (possibly others ???) and the
5083 -- context is a record type, this is a discriminant expression
5084 -- within a type declaration, that freezes the predicated
5085 -- subtype.
5086
5087 elsif From_Aspect_Specification (N)
5088 and then Prag_Id = Pragma_Predicate
5089 and then Ekind (Current_Scope) = E_Record_Type
5090 and then Scop = Scope (Current_Scope)
5091 then
5092 OK := True;
5093
5094 -- Default case, just check that the pragma occurs in the scope
5095 -- of the entity denoted by the name.
5096
5097 else
5098 OK := Current_Scope = Scop;
5099 end if;
5100
5101 if not OK then
5102 Error_Pragma_Arg
5103 ("pragma% argument must be in same declarative part", Arg);
5104 end if;
5105 end;
5106 end if;
5107 end Check_Arg_Is_Local_Name;
5108
5109 ---------------------------------
5110 -- Check_Arg_Is_Locking_Policy --
5111 ---------------------------------
5112
5113 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
5114 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5115
5116 begin
5117 Check_Arg_Is_Identifier (Argx);
5118
5119 if not Is_Locking_Policy_Name (Chars (Argx)) then
5120 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
5121 end if;
5122 end Check_Arg_Is_Locking_Policy;
5123
5124 -----------------------------------------------
5125 -- Check_Arg_Is_Partition_Elaboration_Policy --
5126 -----------------------------------------------
5127
5128 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
5129 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5130
5131 begin
5132 Check_Arg_Is_Identifier (Argx);
5133
5134 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
5135 Error_Pragma_Arg
5136 ("& is not a valid partition elaboration policy name", Argx);
5137 end if;
5138 end Check_Arg_Is_Partition_Elaboration_Policy;
5139
5140 -------------------------
5141 -- Check_Arg_Is_One_Of --
5142 -------------------------
5143
5144 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5145 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5146
5147 begin
5148 Check_Arg_Is_Identifier (Argx);
5149
5150 if not Nam_In (Chars (Argx), N1, N2) then
5151 Error_Msg_Name_2 := N1;
5152 Error_Msg_Name_3 := N2;
5153 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
5154 end if;
5155 end Check_Arg_Is_One_Of;
5156
5157 procedure Check_Arg_Is_One_Of
5158 (Arg : Node_Id;
5159 N1, N2, N3 : Name_Id)
5160 is
5161 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5162
5163 begin
5164 Check_Arg_Is_Identifier (Argx);
5165
5166 if not Nam_In (Chars (Argx), N1, N2, N3) then
5167 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5168 end if;
5169 end Check_Arg_Is_One_Of;
5170
5171 procedure Check_Arg_Is_One_Of
5172 (Arg : Node_Id;
5173 N1, N2, N3, N4 : Name_Id)
5174 is
5175 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5176
5177 begin
5178 Check_Arg_Is_Identifier (Argx);
5179
5180 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
5181 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5182 end if;
5183 end Check_Arg_Is_One_Of;
5184
5185 procedure Check_Arg_Is_One_Of
5186 (Arg : Node_Id;
5187 N1, N2, N3, N4, N5 : Name_Id)
5188 is
5189 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5190
5191 begin
5192 Check_Arg_Is_Identifier (Argx);
5193
5194 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
5195 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5196 end if;
5197 end Check_Arg_Is_One_Of;
5198
5199 ---------------------------------
5200 -- Check_Arg_Is_Queuing_Policy --
5201 ---------------------------------
5202
5203 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
5204 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5205
5206 begin
5207 Check_Arg_Is_Identifier (Argx);
5208
5209 if not Is_Queuing_Policy_Name (Chars (Argx)) then
5210 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
5211 end if;
5212 end Check_Arg_Is_Queuing_Policy;
5213
5214 ---------------------------------------
5215 -- Check_Arg_Is_OK_Static_Expression --
5216 ---------------------------------------
5217
5218 procedure Check_Arg_Is_OK_Static_Expression
5219 (Arg : Node_Id;
5220 Typ : Entity_Id := Empty)
5221 is
5222 begin
5223 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
5224 end Check_Arg_Is_OK_Static_Expression;
5225
5226 ------------------------------------------
5227 -- Check_Arg_Is_Task_Dispatching_Policy --
5228 ------------------------------------------
5229
5230 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
5231 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5232
5233 begin
5234 Check_Arg_Is_Identifier (Argx);
5235
5236 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
5237 Error_Pragma_Arg
5238 ("& is not an allowed task dispatching policy name", Argx);
5239 end if;
5240 end Check_Arg_Is_Task_Dispatching_Policy;
5241
5242 ---------------------
5243 -- Check_Arg_Order --
5244 ---------------------
5245
5246 procedure Check_Arg_Order (Names : Name_List) is
5247 Arg : Node_Id;
5248
5249 Highest_So_Far : Natural := 0;
5250 -- Highest index in Names seen do far
5251
5252 begin
5253 Arg := Arg1;
5254 for J in 1 .. Arg_Count loop
5255 if Chars (Arg) /= No_Name then
5256 for K in Names'Range loop
5257 if Chars (Arg) = Names (K) then
5258 if K < Highest_So_Far then
5259 Error_Msg_Name_1 := Pname;
5260 Error_Msg_N
5261 ("parameters out of order for pragma%", Arg);
5262 Error_Msg_Name_1 := Names (K);
5263 Error_Msg_Name_2 := Names (Highest_So_Far);
5264 Error_Msg_N ("\% must appear before %", Arg);
5265 raise Pragma_Exit;
5266
5267 else
5268 Highest_So_Far := K;
5269 end if;
5270 end if;
5271 end loop;
5272 end if;
5273
5274 Arg := Next (Arg);
5275 end loop;
5276 end Check_Arg_Order;
5277
5278 --------------------------------
5279 -- Check_At_Least_N_Arguments --
5280 --------------------------------
5281
5282 procedure Check_At_Least_N_Arguments (N : Nat) is
5283 begin
5284 if Arg_Count < N then
5285 Error_Pragma ("too few arguments for pragma%");
5286 end if;
5287 end Check_At_Least_N_Arguments;
5288
5289 -------------------------------
5290 -- Check_At_Most_N_Arguments --
5291 -------------------------------
5292
5293 procedure Check_At_Most_N_Arguments (N : Nat) is
5294 Arg : Node_Id;
5295 begin
5296 if Arg_Count > N then
5297 Arg := Arg1;
5298 for J in 1 .. N loop
5299 Next (Arg);
5300 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
5301 end loop;
5302 end if;
5303 end Check_At_Most_N_Arguments;
5304
5305 ---------------------
5306 -- Check_Component --
5307 ---------------------
5308
5309 procedure Check_Component
5310 (Comp : Node_Id;
5311 UU_Typ : Entity_Id;
5312 In_Variant_Part : Boolean := False)
5313 is
5314 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
5315 Sindic : constant Node_Id :=
5316 Subtype_Indication (Component_Definition (Comp));
5317 Typ : constant Entity_Id := Etype (Comp_Id);
5318
5319 begin
5320 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
5321 -- object constraint, then the component type shall be an Unchecked_
5322 -- Union.
5323
5324 if Nkind (Sindic) = N_Subtype_Indication
5325 and then Has_Per_Object_Constraint (Comp_Id)
5326 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
5327 then
5328 Error_Msg_N
5329 ("component subtype subject to per-object constraint "
5330 & "must be an Unchecked_Union", Comp);
5331
5332 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
5333 -- the body of a generic unit, or within the body of any of its
5334 -- descendant library units, no part of the type of a component
5335 -- declared in a variant_part of the unchecked union type shall be of
5336 -- a formal private type or formal private extension declared within
5337 -- the formal part of the generic unit.
5338
5339 elsif Ada_Version >= Ada_2012
5340 and then In_Generic_Body (UU_Typ)
5341 and then In_Variant_Part
5342 and then Is_Private_Type (Typ)
5343 and then Is_Generic_Type (Typ)
5344 then
5345 Error_Msg_N
5346 ("component of unchecked union cannot be of generic type", Comp);
5347
5348 elsif Needs_Finalization (Typ) then
5349 Error_Msg_N
5350 ("component of unchecked union cannot be controlled", Comp);
5351
5352 elsif Has_Task (Typ) then
5353 Error_Msg_N
5354 ("component of unchecked union cannot have tasks", Comp);
5355 end if;
5356 end Check_Component;
5357
5358 ----------------------------
5359 -- Check_Duplicate_Pragma --
5360 ----------------------------
5361
5362 procedure Check_Duplicate_Pragma (E : Entity_Id) is
5363 Id : Entity_Id := E;
5364 P : Node_Id;
5365
5366 begin
5367 -- Nothing to do if this pragma comes from an aspect specification,
5368 -- since we could not be duplicating a pragma, and we dealt with the
5369 -- case of duplicated aspects in Analyze_Aspect_Specifications.
5370
5371 if From_Aspect_Specification (N) then
5372 return;
5373 end if;
5374
5375 -- Otherwise current pragma may duplicate previous pragma or a
5376 -- previously given aspect specification or attribute definition
5377 -- clause for the same pragma.
5378
5379 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
5380
5381 if Present (P) then
5382
5383 -- If the entity is a type, then we have to make sure that the
5384 -- ostensible duplicate is not for a parent type from which this
5385 -- type is derived.
5386
5387 if Is_Type (E) then
5388 if Nkind (P) = N_Pragma then
5389 declare
5390 Args : constant List_Id :=
5391 Pragma_Argument_Associations (P);
5392 begin
5393 if Present (Args)
5394 and then Is_Entity_Name (Expression (First (Args)))
5395 and then Is_Type (Entity (Expression (First (Args))))
5396 and then Entity (Expression (First (Args))) /= E
5397 then
5398 return;
5399 end if;
5400 end;
5401
5402 elsif Nkind (P) = N_Aspect_Specification
5403 and then Is_Type (Entity (P))
5404 and then Entity (P) /= E
5405 then
5406 return;
5407 end if;
5408 end if;
5409
5410 -- Here we have a definite duplicate
5411
5412 Error_Msg_Name_1 := Pragma_Name (N);
5413 Error_Msg_Sloc := Sloc (P);
5414
5415 -- For a single protected or a single task object, the error is
5416 -- issued on the original entity.
5417
5418 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
5419 Id := Defining_Identifier (Original_Node (Parent (Id)));
5420 end if;
5421
5422 if Nkind (P) = N_Aspect_Specification
5423 or else From_Aspect_Specification (P)
5424 then
5425 Error_Msg_NE ("aspect% for & previously given#", N, Id);
5426 else
5427 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
5428 end if;
5429
5430 raise Pragma_Exit;
5431 end if;
5432 end Check_Duplicate_Pragma;
5433
5434 ----------------------------------
5435 -- Check_Duplicated_Export_Name --
5436 ----------------------------------
5437
5438 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
5439 String_Val : constant String_Id := Strval (Nam);
5440
5441 begin
5442 -- We are only interested in the export case, and in the case of
5443 -- generics, it is the instance, not the template, that is the
5444 -- problem (the template will generate a warning in any case).
5445
5446 if not Inside_A_Generic
5447 and then (Prag_Id = Pragma_Export
5448 or else
5449 Prag_Id = Pragma_Export_Procedure
5450 or else
5451 Prag_Id = Pragma_Export_Valued_Procedure
5452 or else
5453 Prag_Id = Pragma_Export_Function)
5454 then
5455 for J in Externals.First .. Externals.Last loop
5456 if String_Equal (String_Val, Strval (Externals.Table (J))) then
5457 Error_Msg_Sloc := Sloc (Externals.Table (J));
5458 Error_Msg_N ("external name duplicates name given#", Nam);
5459 exit;
5460 end if;
5461 end loop;
5462
5463 Externals.Append (Nam);
5464 end if;
5465 end Check_Duplicated_Export_Name;
5466
5467 ----------------------------------------
5468 -- Check_Expr_Is_OK_Static_Expression --
5469 ----------------------------------------
5470
5471 procedure Check_Expr_Is_OK_Static_Expression
5472 (Expr : Node_Id;
5473 Typ : Entity_Id := Empty)
5474 is
5475 begin
5476 if Present (Typ) then
5477 Analyze_And_Resolve (Expr, Typ);
5478 else
5479 Analyze_And_Resolve (Expr);
5480 end if;
5481
5482 -- An expression cannot be considered static if its resolution failed
5483 -- or if it's erroneous. Stop the analysis of the related pragma.
5484
5485 if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
5486 raise Pragma_Exit;
5487
5488 elsif Is_OK_Static_Expression (Expr) then
5489 return;
5490
5491 -- An interesting special case, if we have a string literal and we
5492 -- are in Ada 83 mode, then we allow it even though it will not be
5493 -- flagged as static. This allows the use of Ada 95 pragmas like
5494 -- Import in Ada 83 mode. They will of course be flagged with
5495 -- warnings as usual, but will not cause errors.
5496
5497 elsif Ada_Version = Ada_83
5498 and then Nkind (Expr) = N_String_Literal
5499 then
5500 return;
5501
5502 -- Finally, we have a real error
5503
5504 else
5505 Error_Msg_Name_1 := Pname;
5506 Flag_Non_Static_Expr
5507 (Fix_Error ("argument for pragma% must be a static expression!"),
5508 Expr);
5509 raise Pragma_Exit;
5510 end if;
5511 end Check_Expr_Is_OK_Static_Expression;
5512
5513 -------------------------
5514 -- Check_First_Subtype --
5515 -------------------------
5516
5517 procedure Check_First_Subtype (Arg : Node_Id) is
5518 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5519 Ent : constant Entity_Id := Entity (Argx);
5520
5521 begin
5522 if Is_First_Subtype (Ent) then
5523 null;
5524
5525 elsif Is_Type (Ent) then
5526 Error_Pragma_Arg
5527 ("pragma% cannot apply to subtype", Argx);
5528
5529 elsif Is_Object (Ent) then
5530 Error_Pragma_Arg
5531 ("pragma% cannot apply to object, requires a type", Argx);
5532
5533 else
5534 Error_Pragma_Arg
5535 ("pragma% cannot apply to&, requires a type", Argx);
5536 end if;
5537 end Check_First_Subtype;
5538
5539 ----------------------
5540 -- Check_Identifier --
5541 ----------------------
5542
5543 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
5544 begin
5545 if Present (Arg)
5546 and then Nkind (Arg) = N_Pragma_Argument_Association
5547 then
5548 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
5549 Error_Msg_Name_1 := Pname;
5550 Error_Msg_Name_2 := Id;
5551 Error_Msg_N ("pragma% argument expects identifier%", Arg);
5552 raise Pragma_Exit;
5553 end if;
5554 end if;
5555 end Check_Identifier;
5556
5557 --------------------------------
5558 -- Check_Identifier_Is_One_Of --
5559 --------------------------------
5560
5561 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5562 begin
5563 if Present (Arg)
5564 and then Nkind (Arg) = N_Pragma_Argument_Association
5565 then
5566 if Chars (Arg) = No_Name then
5567 Error_Msg_Name_1 := Pname;
5568 Error_Msg_N ("pragma% argument expects an identifier", Arg);
5569 raise Pragma_Exit;
5570
5571 elsif Chars (Arg) /= N1
5572 and then Chars (Arg) /= N2
5573 then
5574 Error_Msg_Name_1 := Pname;
5575 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
5576 raise Pragma_Exit;
5577 end if;
5578 end if;
5579 end Check_Identifier_Is_One_Of;
5580
5581 ---------------------------
5582 -- Check_In_Main_Program --
5583 ---------------------------
5584
5585 procedure Check_In_Main_Program is
5586 P : constant Node_Id := Parent (N);
5587
5588 begin
5589 -- Must be in subprogram body
5590
5591 if Nkind (P) /= N_Subprogram_Body then
5592 Error_Pragma ("% pragma allowed only in subprogram");
5593
5594 -- Otherwise warn if obviously not main program
5595
5596 elsif Present (Parameter_Specifications (Specification (P)))
5597 or else not Is_Compilation_Unit (Defining_Entity (P))
5598 then
5599 Error_Msg_Name_1 := Pname;
5600 Error_Msg_N
5601 ("??pragma% is only effective in main program", N);
5602 end if;
5603 end Check_In_Main_Program;
5604
5605 ---------------------------------------
5606 -- Check_Interrupt_Or_Attach_Handler --
5607 ---------------------------------------
5608
5609 procedure Check_Interrupt_Or_Attach_Handler is
5610 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5611 Handler_Proc, Proc_Scope : Entity_Id;
5612
5613 begin
5614 Analyze (Arg1_X);
5615
5616 if Prag_Id = Pragma_Interrupt_Handler then
5617 Check_Restriction (No_Dynamic_Attachment, N);
5618 end if;
5619
5620 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
5621 Proc_Scope := Scope (Handler_Proc);
5622
5623 if Ekind (Proc_Scope) /= E_Protected_Type then
5624 Error_Pragma_Arg
5625 ("argument of pragma% must be protected procedure", Arg1);
5626 end if;
5627
5628 -- For pragma case (as opposed to access case), check placement.
5629 -- We don't need to do that for aspects, because we have the
5630 -- check that they aspect applies an appropriate procedure.
5631
5632 if not From_Aspect_Specification (N)
5633 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
5634 then
5635 Error_Pragma ("pragma% must be in protected definition");
5636 end if;
5637
5638 if not Is_Library_Level_Entity (Proc_Scope) then
5639 Error_Pragma_Arg
5640 ("argument for pragma% must be library level entity", Arg1);
5641 end if;
5642
5643 -- AI05-0033: A pragma cannot appear within a generic body, because
5644 -- instance can be in a nested scope. The check that protected type
5645 -- is itself a library-level declaration is done elsewhere.
5646
5647 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
5648 -- handle code prior to AI-0033. Analysis tools typically are not
5649 -- interested in this pragma in any case, so no need to worry too
5650 -- much about its placement.
5651
5652 if Inside_A_Generic then
5653 if Ekind (Scope (Current_Scope)) = E_Generic_Package
5654 and then In_Package_Body (Scope (Current_Scope))
5655 and then not Relaxed_RM_Semantics
5656 then
5657 Error_Pragma ("pragma% cannot be used inside a generic");
5658 end if;
5659 end if;
5660 end Check_Interrupt_Or_Attach_Handler;
5661
5662 ---------------------------------
5663 -- Check_Loop_Pragma_Placement --
5664 ---------------------------------
5665
5666 procedure Check_Loop_Pragma_Placement is
5667 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
5668 -- Verify whether the current pragma is properly grouped with other
5669 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
5670 -- related loop where the pragma appears.
5671
5672 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
5673 -- Determine whether an arbitrary statement Stmt denotes pragma
5674 -- Loop_Invariant or Loop_Variant.
5675
5676 procedure Placement_Error (Constr : Node_Id);
5677 pragma No_Return (Placement_Error);
5678 -- Node Constr denotes the last loop restricted construct before we
5679 -- encountered an illegal relation between enclosing constructs. Emit
5680 -- an error depending on what Constr was.
5681
5682 --------------------------------
5683 -- Check_Loop_Pragma_Grouping --
5684 --------------------------------
5685
5686 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
5687 Stop_Search : exception;
5688 -- This exception is used to terminate the recursive descent of
5689 -- routine Check_Grouping.
5690
5691 procedure Check_Grouping (L : List_Id);
5692 -- Find the first group of pragmas in list L and if successful,
5693 -- ensure that the current pragma is part of that group. The
5694 -- routine raises Stop_Search once such a check is performed to
5695 -- halt the recursive descent.
5696
5697 procedure Grouping_Error (Prag : Node_Id);
5698 pragma No_Return (Grouping_Error);
5699 -- Emit an error concerning the current pragma indicating that it
5700 -- should be placed after pragma Prag.
5701
5702 --------------------
5703 -- Check_Grouping --
5704 --------------------
5705
5706 procedure Check_Grouping (L : List_Id) is
5707 HSS : Node_Id;
5708 Prag : Node_Id;
5709 Stmt : Node_Id;
5710
5711 begin
5712 -- Inspect the list of declarations or statements looking for
5713 -- the first grouping of pragmas:
5714
5715 -- loop
5716 -- pragma Loop_Invariant ...;
5717 -- pragma Loop_Variant ...;
5718 -- . . . -- (1)
5719 -- pragma Loop_Variant ...; -- current pragma
5720
5721 -- If the current pragma is not in the grouping, then it must
5722 -- either appear in a different declarative or statement list
5723 -- or the construct at (1) is separating the pragma from the
5724 -- grouping.
5725
5726 Stmt := First (L);
5727 while Present (Stmt) loop
5728
5729 -- Pragmas Loop_Invariant and Loop_Variant may only appear
5730 -- inside a loop or a block housed inside a loop. Inspect
5731 -- the declarations and statements of the block as they may
5732 -- contain the first grouping.
5733
5734 if Nkind (Stmt) = N_Block_Statement then
5735 HSS := Handled_Statement_Sequence (Stmt);
5736
5737 Check_Grouping (Declarations (Stmt));
5738
5739 if Present (HSS) then
5740 Check_Grouping (Statements (HSS));
5741 end if;
5742
5743 -- First pragma of the first topmost grouping has been found
5744
5745 elsif Is_Loop_Pragma (Stmt) then
5746
5747 -- The group and the current pragma are not in the same
5748 -- declarative or statement list.
5749
5750 if List_Containing (Stmt) /= List_Containing (N) then
5751 Grouping_Error (Stmt);
5752
5753 -- Try to reach the current pragma from the first pragma
5754 -- of the grouping while skipping other members:
5755
5756 -- pragma Loop_Invariant ...; -- first pragma
5757 -- pragma Loop_Variant ...; -- member
5758 -- . . .
5759 -- pragma Loop_Variant ...; -- current pragma
5760
5761 else
5762 while Present (Stmt) loop
5763
5764 -- The current pragma is either the first pragma
5765 -- of the group or is a member of the group. Stop
5766 -- the search as the placement is legal.
5767
5768 if Stmt = N then
5769 raise Stop_Search;
5770
5771 -- Skip group members, but keep track of the last
5772 -- pragma in the group.
5773
5774 elsif Is_Loop_Pragma (Stmt) then
5775 Prag := Stmt;
5776
5777 -- Skip declarations and statements generated by
5778 -- the compiler during expansion.
5779
5780 elsif not Comes_From_Source (Stmt) then
5781 null;
5782
5783 -- A non-pragma is separating the group from the
5784 -- current pragma, the placement is illegal.
5785
5786 else
5787 Grouping_Error (Prag);
5788 end if;
5789
5790 Next (Stmt);
5791 end loop;
5792
5793 -- If the traversal did not reach the current pragma,
5794 -- then the list must be malformed.
5795
5796 raise Program_Error;
5797 end if;
5798 end if;
5799
5800 Next (Stmt);
5801 end loop;
5802 end Check_Grouping;
5803
5804 --------------------
5805 -- Grouping_Error --
5806 --------------------
5807
5808 procedure Grouping_Error (Prag : Node_Id) is
5809 begin
5810 Error_Msg_Sloc := Sloc (Prag);
5811 Error_Pragma ("pragma% must appear next to pragma#");
5812 end Grouping_Error;
5813
5814 -- Start of processing for Check_Loop_Pragma_Grouping
5815
5816 begin
5817 -- Inspect the statements of the loop or nested blocks housed
5818 -- within to determine whether the current pragma is part of the
5819 -- first topmost grouping of Loop_Invariant and Loop_Variant.
5820
5821 Check_Grouping (Statements (Loop_Stmt));
5822
5823 exception
5824 when Stop_Search => null;
5825 end Check_Loop_Pragma_Grouping;
5826
5827 --------------------
5828 -- Is_Loop_Pragma --
5829 --------------------
5830
5831 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
5832 begin
5833 -- Inspect the original node as Loop_Invariant and Loop_Variant
5834 -- pragmas are rewritten to null when assertions are disabled.
5835
5836 if Nkind (Original_Node (Stmt)) = N_Pragma then
5837 return
5838 Nam_In (Pragma_Name_Unmapped (Original_Node (Stmt)),
5839 Name_Loop_Invariant,
5840 Name_Loop_Variant);
5841 else
5842 return False;
5843 end if;
5844 end Is_Loop_Pragma;
5845
5846 ---------------------
5847 -- Placement_Error --
5848 ---------------------
5849
5850 procedure Placement_Error (Constr : Node_Id) is
5851 LA : constant String := " with Loop_Entry";
5852
5853 begin
5854 if Prag_Id = Pragma_Assert then
5855 Error_Msg_String (1 .. LA'Length) := LA;
5856 Error_Msg_Strlen := LA'Length;
5857 else
5858 Error_Msg_Strlen := 0;
5859 end if;
5860
5861 if Nkind (Constr) = N_Pragma then
5862 Error_Pragma
5863 ("pragma %~ must appear immediately within the statements "
5864 & "of a loop");
5865 else
5866 Error_Pragma_Arg
5867 ("block containing pragma %~ must appear immediately within "
5868 & "the statements of a loop", Constr);
5869 end if;
5870 end Placement_Error;
5871
5872 -- Local declarations
5873
5874 Prev : Node_Id;
5875 Stmt : Node_Id;
5876
5877 -- Start of processing for Check_Loop_Pragma_Placement
5878
5879 begin
5880 -- Check that pragma appears immediately within a loop statement,
5881 -- ignoring intervening block statements.
5882
5883 Prev := N;
5884 Stmt := Parent (N);
5885 while Present (Stmt) loop
5886
5887 -- The pragma or previous block must appear immediately within the
5888 -- current block's declarative or statement part.
5889
5890 if Nkind (Stmt) = N_Block_Statement then
5891 if (No (Declarations (Stmt))
5892 or else List_Containing (Prev) /= Declarations (Stmt))
5893 and then
5894 List_Containing (Prev) /=
5895 Statements (Handled_Statement_Sequence (Stmt))
5896 then
5897 Placement_Error (Prev);
5898 return;
5899
5900 -- Keep inspecting the parents because we are now within a
5901 -- chain of nested blocks.
5902
5903 else
5904 Prev := Stmt;
5905 Stmt := Parent (Stmt);
5906 end if;
5907
5908 -- The pragma or previous block must appear immediately within the
5909 -- statements of the loop.
5910
5911 elsif Nkind (Stmt) = N_Loop_Statement then
5912 if List_Containing (Prev) /= Statements (Stmt) then
5913 Placement_Error (Prev);
5914 end if;
5915
5916 -- Stop the traversal because we reached the innermost loop
5917 -- regardless of whether we encountered an error or not.
5918
5919 exit;
5920
5921 -- Ignore a handled statement sequence. Note that this node may
5922 -- be related to a subprogram body in which case we will emit an
5923 -- error on the next iteration of the search.
5924
5925 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
5926 Stmt := Parent (Stmt);
5927
5928 -- Any other statement breaks the chain from the pragma to the
5929 -- loop.
5930
5931 else
5932 Placement_Error (Prev);
5933 return;
5934 end if;
5935 end loop;
5936
5937 -- Check that the current pragma Loop_Invariant or Loop_Variant is
5938 -- grouped together with other such pragmas.
5939
5940 if Is_Loop_Pragma (N) then
5941
5942 -- The previous check should have located the related loop
5943
5944 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
5945 Check_Loop_Pragma_Grouping (Stmt);
5946 end if;
5947 end Check_Loop_Pragma_Placement;
5948
5949 -------------------------------------------
5950 -- Check_Is_In_Decl_Part_Or_Package_Spec --
5951 -------------------------------------------
5952
5953 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
5954 P : Node_Id;
5955
5956 begin
5957 P := Parent (N);
5958 loop
5959 if No (P) then
5960 exit;
5961
5962 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
5963 exit;
5964
5965 elsif Nkind_In (P, N_Package_Specification,
5966 N_Block_Statement)
5967 then
5968 return;
5969
5970 -- Note: the following tests seem a little peculiar, because
5971 -- they test for bodies, but if we were in the statement part
5972 -- of the body, we would already have hit the handled statement
5973 -- sequence, so the only way we get here is by being in the
5974 -- declarative part of the body.
5975
5976 elsif Nkind_In (P, N_Subprogram_Body,
5977 N_Package_Body,
5978 N_Task_Body,
5979 N_Entry_Body)
5980 then
5981 return;
5982 end if;
5983
5984 P := Parent (P);
5985 end loop;
5986
5987 Error_Pragma ("pragma% is not in declarative part or package spec");
5988 end Check_Is_In_Decl_Part_Or_Package_Spec;
5989
5990 -------------------------
5991 -- Check_No_Identifier --
5992 -------------------------
5993
5994 procedure Check_No_Identifier (Arg : Node_Id) is
5995 begin
5996 if Nkind (Arg) = N_Pragma_Argument_Association
5997 and then Chars (Arg) /= No_Name
5998 then
5999 Error_Pragma_Arg_Ident
6000 ("pragma% does not permit identifier& here", Arg);
6001 end if;
6002 end Check_No_Identifier;
6003
6004 --------------------------
6005 -- Check_No_Identifiers --
6006 --------------------------
6007
6008 procedure Check_No_Identifiers is
6009 Arg_Node : Node_Id;
6010 begin
6011 Arg_Node := Arg1;
6012 for J in 1 .. Arg_Count loop
6013 Check_No_Identifier (Arg_Node);
6014 Next (Arg_Node);
6015 end loop;
6016 end Check_No_Identifiers;
6017
6018 ------------------------
6019 -- Check_No_Link_Name --
6020 ------------------------
6021
6022 procedure Check_No_Link_Name is
6023 begin
6024 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
6025 Arg4 := Arg3;
6026 end if;
6027
6028 if Present (Arg4) then
6029 Error_Pragma_Arg
6030 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
6031 end if;
6032 end Check_No_Link_Name;
6033
6034 -------------------------------
6035 -- Check_Optional_Identifier --
6036 -------------------------------
6037
6038 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
6039 begin
6040 if Present (Arg)
6041 and then Nkind (Arg) = N_Pragma_Argument_Association
6042 and then Chars (Arg) /= No_Name
6043 then
6044 if Chars (Arg) /= Id then
6045 Error_Msg_Name_1 := Pname;
6046 Error_Msg_Name_2 := Id;
6047 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6048 raise Pragma_Exit;
6049 end if;
6050 end if;
6051 end Check_Optional_Identifier;
6052
6053 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
6054 begin
6055 Check_Optional_Identifier (Arg, Name_Find (Id));
6056 end Check_Optional_Identifier;
6057
6058 -------------------------------------
6059 -- Check_Static_Boolean_Expression --
6060 -------------------------------------
6061
6062 procedure Check_Static_Boolean_Expression (Expr : Node_Id) is
6063 begin
6064 if Present (Expr) then
6065 Analyze_And_Resolve (Expr, Standard_Boolean);
6066
6067 if not Is_OK_Static_Expression (Expr) then
6068 Error_Pragma_Arg
6069 ("expression of pragma % must be static", Expr);
6070 end if;
6071 end if;
6072 end Check_Static_Boolean_Expression;
6073
6074 -----------------------------
6075 -- Check_Static_Constraint --
6076 -----------------------------
6077
6078 -- Note: for convenience in writing this procedure, in addition to
6079 -- the officially (i.e. by spec) allowed argument which is always a
6080 -- constraint, it also allows ranges and discriminant associations.
6081 -- Above is not clear ???
6082
6083 procedure Check_Static_Constraint (Constr : Node_Id) is
6084
6085 procedure Require_Static (E : Node_Id);
6086 -- Require given expression to be static expression
6087
6088 --------------------
6089 -- Require_Static --
6090 --------------------
6091
6092 procedure Require_Static (E : Node_Id) is
6093 begin
6094 if not Is_OK_Static_Expression (E) then
6095 Flag_Non_Static_Expr
6096 ("non-static constraint not allowed in Unchecked_Union!", E);
6097 raise Pragma_Exit;
6098 end if;
6099 end Require_Static;
6100
6101 -- Start of processing for Check_Static_Constraint
6102
6103 begin
6104 case Nkind (Constr) is
6105 when N_Discriminant_Association =>
6106 Require_Static (Expression (Constr));
6107
6108 when N_Range =>
6109 Require_Static (Low_Bound (Constr));
6110 Require_Static (High_Bound (Constr));
6111
6112 when N_Attribute_Reference =>
6113 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
6114 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
6115
6116 when N_Range_Constraint =>
6117 Check_Static_Constraint (Range_Expression (Constr));
6118
6119 when N_Index_Or_Discriminant_Constraint =>
6120 declare
6121 IDC : Entity_Id;
6122 begin
6123 IDC := First (Constraints (Constr));
6124 while Present (IDC) loop
6125 Check_Static_Constraint (IDC);
6126 Next (IDC);
6127 end loop;
6128 end;
6129
6130 when others =>
6131 null;
6132 end case;
6133 end Check_Static_Constraint;
6134
6135 --------------------------------------
6136 -- Check_Valid_Configuration_Pragma --
6137 --------------------------------------
6138
6139 -- A configuration pragma must appear in the context clause of a
6140 -- compilation unit, and only other pragmas may precede it. Note that
6141 -- the test also allows use in a configuration pragma file.
6142
6143 procedure Check_Valid_Configuration_Pragma is
6144 begin
6145 if not Is_Configuration_Pragma then
6146 Error_Pragma ("incorrect placement for configuration pragma%");
6147 end if;
6148 end Check_Valid_Configuration_Pragma;
6149
6150 -------------------------------------
6151 -- Check_Valid_Library_Unit_Pragma --
6152 -------------------------------------
6153
6154 procedure Check_Valid_Library_Unit_Pragma is
6155 Plist : List_Id;
6156 Parent_Node : Node_Id;
6157 Unit_Name : Entity_Id;
6158 Unit_Kind : Node_Kind;
6159 Unit_Node : Node_Id;
6160 Sindex : Source_File_Index;
6161
6162 begin
6163 if not Is_List_Member (N) then
6164 Pragma_Misplaced;
6165
6166 else
6167 Plist := List_Containing (N);
6168 Parent_Node := Parent (Plist);
6169
6170 if Parent_Node = Empty then
6171 Pragma_Misplaced;
6172
6173 -- Case of pragma appearing after a compilation unit. In this case
6174 -- it must have an argument with the corresponding name and must
6175 -- be part of the following pragmas of its parent.
6176
6177 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
6178 if Plist /= Pragmas_After (Parent_Node) then
6179 Pragma_Misplaced;
6180
6181 elsif Arg_Count = 0 then
6182 Error_Pragma
6183 ("argument required if outside compilation unit");
6184
6185 else
6186 Check_No_Identifiers;
6187 Check_Arg_Count (1);
6188 Unit_Node := Unit (Parent (Parent_Node));
6189 Unit_Kind := Nkind (Unit_Node);
6190
6191 Analyze (Get_Pragma_Arg (Arg1));
6192
6193 if Unit_Kind = N_Generic_Subprogram_Declaration
6194 or else Unit_Kind = N_Subprogram_Declaration
6195 then
6196 Unit_Name := Defining_Entity (Unit_Node);
6197
6198 elsif Unit_Kind in N_Generic_Instantiation then
6199 Unit_Name := Defining_Entity (Unit_Node);
6200
6201 else
6202 Unit_Name := Cunit_Entity (Current_Sem_Unit);
6203 end if;
6204
6205 if Chars (Unit_Name) /=
6206 Chars (Entity (Get_Pragma_Arg (Arg1)))
6207 then
6208 Error_Pragma_Arg
6209 ("pragma% argument is not current unit name", Arg1);
6210 end if;
6211
6212 if Ekind (Unit_Name) = E_Package
6213 and then Present (Renamed_Entity (Unit_Name))
6214 then
6215 Error_Pragma ("pragma% not allowed for renamed package");
6216 end if;
6217 end if;
6218
6219 -- Pragma appears other than after a compilation unit
6220
6221 else
6222 -- Here we check for the generic instantiation case and also
6223 -- for the case of processing a generic formal package. We
6224 -- detect these cases by noting that the Sloc on the node
6225 -- does not belong to the current compilation unit.
6226
6227 Sindex := Source_Index (Current_Sem_Unit);
6228
6229 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
6230 Rewrite (N, Make_Null_Statement (Loc));
6231 return;
6232
6233 -- If before first declaration, the pragma applies to the
6234 -- enclosing unit, and the name if present must be this name.
6235
6236 elsif Is_Before_First_Decl (N, Plist) then
6237 Unit_Node := Unit_Declaration_Node (Current_Scope);
6238 Unit_Kind := Nkind (Unit_Node);
6239
6240 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
6241 Pragma_Misplaced;
6242
6243 elsif Unit_Kind = N_Subprogram_Body
6244 and then not Acts_As_Spec (Unit_Node)
6245 then
6246 Pragma_Misplaced;
6247
6248 elsif Nkind (Parent_Node) = N_Package_Body then
6249 Pragma_Misplaced;
6250
6251 elsif Nkind (Parent_Node) = N_Package_Specification
6252 and then Plist = Private_Declarations (Parent_Node)
6253 then
6254 Pragma_Misplaced;
6255
6256 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
6257 or else Nkind (Parent_Node) =
6258 N_Generic_Subprogram_Declaration)
6259 and then Plist = Generic_Formal_Declarations (Parent_Node)
6260 then
6261 Pragma_Misplaced;
6262
6263 elsif Arg_Count > 0 then
6264 Analyze (Get_Pragma_Arg (Arg1));
6265
6266 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
6267 Error_Pragma_Arg
6268 ("name in pragma% must be enclosing unit", Arg1);
6269 end if;
6270
6271 -- It is legal to have no argument in this context
6272
6273 else
6274 return;
6275 end if;
6276
6277 -- Error if not before first declaration. This is because a
6278 -- library unit pragma argument must be the name of a library
6279 -- unit (RM 10.1.5(7)), but the only names permitted in this
6280 -- context are (RM 10.1.5(6)) names of subprogram declarations,
6281 -- generic subprogram declarations or generic instantiations.
6282
6283 else
6284 Error_Pragma
6285 ("pragma% misplaced, must be before first declaration");
6286 end if;
6287 end if;
6288 end if;
6289 end Check_Valid_Library_Unit_Pragma;
6290
6291 -------------------
6292 -- Check_Variant --
6293 -------------------
6294
6295 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
6296 Clist : constant Node_Id := Component_List (Variant);
6297 Comp : Node_Id;
6298
6299 begin
6300 Comp := First (Component_Items (Clist));
6301 while Present (Comp) loop
6302 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
6303 Next (Comp);
6304 end loop;
6305 end Check_Variant;
6306
6307 ---------------------------
6308 -- Ensure_Aggregate_Form --
6309 ---------------------------
6310
6311 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
6312 CFSD : constant Boolean := Get_Comes_From_Source_Default;
6313 Expr : constant Node_Id := Expression (Arg);
6314 Loc : constant Source_Ptr := Sloc (Expr);
6315 Comps : List_Id := No_List;
6316 Exprs : List_Id := No_List;
6317 Nam : Name_Id := No_Name;
6318 Nam_Loc : Source_Ptr;
6319
6320 begin
6321 -- The pragma argument is in positional form:
6322
6323 -- pragma Depends (Nam => ...)
6324 -- ^
6325 -- Chars field
6326
6327 -- Note that the Sloc of the Chars field is the Sloc of the pragma
6328 -- argument association.
6329
6330 if Nkind (Arg) = N_Pragma_Argument_Association then
6331 Nam := Chars (Arg);
6332 Nam_Loc := Sloc (Arg);
6333
6334 -- Remove the pragma argument name as this will be captured in the
6335 -- aggregate.
6336
6337 Set_Chars (Arg, No_Name);
6338 end if;
6339
6340 -- The argument is already in aggregate form, but the presence of a
6341 -- name causes this to be interpreted as named association which in
6342 -- turn must be converted into an aggregate.
6343
6344 -- pragma Global (In_Out => (A, B, C))
6345 -- ^ ^
6346 -- name aggregate
6347
6348 -- pragma Global ((In_Out => (A, B, C)))
6349 -- ^ ^
6350 -- aggregate aggregate
6351
6352 if Nkind (Expr) = N_Aggregate then
6353 if Nam = No_Name then
6354 return;
6355 end if;
6356
6357 -- Do not transform a null argument into an aggregate as N_Null has
6358 -- special meaning in formal verification pragmas.
6359
6360 elsif Nkind (Expr) = N_Null then
6361 return;
6362 end if;
6363
6364 -- Everything comes from source if the original comes from source
6365
6366 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
6367
6368 -- Positional argument is transformed into an aggregate with an
6369 -- Expressions list.
6370
6371 if Nam = No_Name then
6372 Exprs := New_List (Relocate_Node (Expr));
6373
6374 -- An associative argument is transformed into an aggregate with
6375 -- Component_Associations.
6376
6377 else
6378 Comps := New_List (
6379 Make_Component_Association (Loc,
6380 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
6381 Expression => Relocate_Node (Expr)));
6382 end if;
6383
6384 Set_Expression (Arg,
6385 Make_Aggregate (Loc,
6386 Component_Associations => Comps,
6387 Expressions => Exprs));
6388
6389 -- Restore Comes_From_Source default
6390
6391 Set_Comes_From_Source_Default (CFSD);
6392 end Ensure_Aggregate_Form;
6393
6394 ------------------
6395 -- Error_Pragma --
6396 ------------------
6397
6398 procedure Error_Pragma (Msg : String) is
6399 begin
6400 Error_Msg_Name_1 := Pname;
6401 Error_Msg_N (Fix_Error (Msg), N);
6402 raise Pragma_Exit;
6403 end Error_Pragma;
6404
6405 ----------------------
6406 -- Error_Pragma_Arg --
6407 ----------------------
6408
6409 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
6410 begin
6411 Error_Msg_Name_1 := Pname;
6412 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
6413 raise Pragma_Exit;
6414 end Error_Pragma_Arg;
6415
6416 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
6417 begin
6418 Error_Msg_Name_1 := Pname;
6419 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
6420 Error_Pragma_Arg (Msg2, Arg);
6421 end Error_Pragma_Arg;
6422
6423 ----------------------------
6424 -- Error_Pragma_Arg_Ident --
6425 ----------------------------
6426
6427 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
6428 begin
6429 Error_Msg_Name_1 := Pname;
6430 Error_Msg_N (Fix_Error (Msg), Arg);
6431 raise Pragma_Exit;
6432 end Error_Pragma_Arg_Ident;
6433
6434 ----------------------
6435 -- Error_Pragma_Ref --
6436 ----------------------
6437
6438 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
6439 begin
6440 Error_Msg_Name_1 := Pname;
6441 Error_Msg_Sloc := Sloc (Ref);
6442 Error_Msg_NE (Fix_Error (Msg), N, Ref);
6443 raise Pragma_Exit;
6444 end Error_Pragma_Ref;
6445
6446 ------------------------
6447 -- Find_Lib_Unit_Name --
6448 ------------------------
6449
6450 function Find_Lib_Unit_Name return Entity_Id is
6451 begin
6452 -- Return inner compilation unit entity, for case of nested
6453 -- categorization pragmas. This happens in generic unit.
6454
6455 if Nkind (Parent (N)) = N_Package_Specification
6456 and then Defining_Entity (Parent (N)) /= Current_Scope
6457 then
6458 return Defining_Entity (Parent (N));
6459 else
6460 return Current_Scope;
6461 end if;
6462 end Find_Lib_Unit_Name;
6463
6464 ----------------------------
6465 -- Find_Program_Unit_Name --
6466 ----------------------------
6467
6468 procedure Find_Program_Unit_Name (Id : Node_Id) is
6469 Unit_Name : Entity_Id;
6470 Unit_Kind : Node_Kind;
6471 P : constant Node_Id := Parent (N);
6472
6473 begin
6474 if Nkind (P) = N_Compilation_Unit then
6475 Unit_Kind := Nkind (Unit (P));
6476
6477 if Nkind_In (Unit_Kind, N_Subprogram_Declaration,
6478 N_Package_Declaration)
6479 or else Unit_Kind in N_Generic_Declaration
6480 then
6481 Unit_Name := Defining_Entity (Unit (P));
6482
6483 if Chars (Id) = Chars (Unit_Name) then
6484 Set_Entity (Id, Unit_Name);
6485 Set_Etype (Id, Etype (Unit_Name));
6486 else
6487 Set_Etype (Id, Any_Type);
6488 Error_Pragma
6489 ("cannot find program unit referenced by pragma%");
6490 end if;
6491
6492 else
6493 Set_Etype (Id, Any_Type);
6494 Error_Pragma ("pragma% inapplicable to this unit");
6495 end if;
6496
6497 else
6498 Analyze (Id);
6499 end if;
6500 end Find_Program_Unit_Name;
6501
6502 -----------------------------------------
6503 -- Find_Unique_Parameterless_Procedure --
6504 -----------------------------------------
6505
6506 function Find_Unique_Parameterless_Procedure
6507 (Name : Entity_Id;
6508 Arg : Node_Id) return Entity_Id
6509 is
6510 Proc : Entity_Id := Empty;
6511
6512 begin
6513 -- The body of this procedure needs some comments ???
6514
6515 if not Is_Entity_Name (Name) then
6516 Error_Pragma_Arg
6517 ("argument of pragma% must be entity name", Arg);
6518
6519 elsif not Is_Overloaded (Name) then
6520 Proc := Entity (Name);
6521
6522 if Ekind (Proc) /= E_Procedure
6523 or else Present (First_Formal (Proc))
6524 then
6525 Error_Pragma_Arg
6526 ("argument of pragma% must be parameterless procedure", Arg);
6527 end if;
6528
6529 else
6530 declare
6531 Found : Boolean := False;
6532 It : Interp;
6533 Index : Interp_Index;
6534
6535 begin
6536 Get_First_Interp (Name, Index, It);
6537 while Present (It.Nam) loop
6538 Proc := It.Nam;
6539
6540 if Ekind (Proc) = E_Procedure
6541 and then No (First_Formal (Proc))
6542 then
6543 if not Found then
6544 Found := True;
6545 Set_Entity (Name, Proc);
6546 Set_Is_Overloaded (Name, False);
6547 else
6548 Error_Pragma_Arg
6549 ("ambiguous handler name for pragma% ", Arg);
6550 end if;
6551 end if;
6552
6553 Get_Next_Interp (Index, It);
6554 end loop;
6555
6556 if not Found then
6557 Error_Pragma_Arg
6558 ("argument of pragma% must be parameterless procedure",
6559 Arg);
6560 else
6561 Proc := Entity (Name);
6562 end if;
6563 end;
6564 end if;
6565
6566 return Proc;
6567 end Find_Unique_Parameterless_Procedure;
6568
6569 ---------------
6570 -- Fix_Error --
6571 ---------------
6572
6573 function Fix_Error (Msg : String) return String is
6574 Res : String (Msg'Range) := Msg;
6575 Res_Last : Natural := Msg'Last;
6576 J : Natural;
6577
6578 begin
6579 -- If we have a rewriting of another pragma, go to that pragma
6580
6581 if Is_Rewrite_Substitution (N)
6582 and then Nkind (Original_Node (N)) = N_Pragma
6583 then
6584 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
6585 end if;
6586
6587 -- Case where pragma comes from an aspect specification
6588
6589 if From_Aspect_Specification (N) then
6590
6591 -- Change appearence of "pragma" in message to "aspect"
6592
6593 J := Res'First;
6594 while J <= Res_Last - 5 loop
6595 if Res (J .. J + 5) = "pragma" then
6596 Res (J .. J + 5) := "aspect";
6597 J := J + 6;
6598
6599 else
6600 J := J + 1;
6601 end if;
6602 end loop;
6603
6604 -- Change "argument of" at start of message to "entity for"
6605
6606 if Res'Length > 11
6607 and then Res (Res'First .. Res'First + 10) = "argument of"
6608 then
6609 Res (Res'First .. Res'First + 9) := "entity for";
6610 Res (Res'First + 10 .. Res_Last - 1) :=
6611 Res (Res'First + 11 .. Res_Last);
6612 Res_Last := Res_Last - 1;
6613 end if;
6614
6615 -- Change "argument" at start of message to "entity"
6616
6617 if Res'Length > 8
6618 and then Res (Res'First .. Res'First + 7) = "argument"
6619 then
6620 Res (Res'First .. Res'First + 5) := "entity";
6621 Res (Res'First + 6 .. Res_Last - 2) :=
6622 Res (Res'First + 8 .. Res_Last);
6623 Res_Last := Res_Last - 2;
6624 end if;
6625
6626 -- Get name from corresponding aspect
6627
6628 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
6629 end if;
6630
6631 -- Return possibly modified message
6632
6633 return Res (Res'First .. Res_Last);
6634 end Fix_Error;
6635
6636 -------------------------
6637 -- Gather_Associations --
6638 -------------------------
6639
6640 procedure Gather_Associations
6641 (Names : Name_List;
6642 Args : out Args_List)
6643 is
6644 Arg : Node_Id;
6645
6646 begin
6647 -- Initialize all parameters to Empty
6648
6649 for J in Args'Range loop
6650 Args (J) := Empty;
6651 end loop;
6652
6653 -- That's all we have to do if there are no argument associations
6654
6655 if No (Pragma_Argument_Associations (N)) then
6656 return;
6657 end if;
6658
6659 -- Otherwise first deal with any positional parameters present
6660
6661 Arg := First (Pragma_Argument_Associations (N));
6662 for Index in Args'Range loop
6663 exit when No (Arg) or else Chars (Arg) /= No_Name;
6664 Args (Index) := Get_Pragma_Arg (Arg);
6665 Next (Arg);
6666 end loop;
6667
6668 -- Positional parameters all processed, if any left, then we
6669 -- have too many positional parameters.
6670
6671 if Present (Arg) and then Chars (Arg) = No_Name then
6672 Error_Pragma_Arg
6673 ("too many positional associations for pragma%", Arg);
6674 end if;
6675
6676 -- Process named parameters if any are present
6677
6678 while Present (Arg) loop
6679 if Chars (Arg) = No_Name then
6680 Error_Pragma_Arg
6681 ("positional association cannot follow named association",
6682 Arg);
6683
6684 else
6685 for Index in Names'Range loop
6686 if Names (Index) = Chars (Arg) then
6687 if Present (Args (Index)) then
6688 Error_Pragma_Arg
6689 ("duplicate argument association for pragma%", Arg);
6690 else
6691 Args (Index) := Get_Pragma_Arg (Arg);
6692 exit;
6693 end if;
6694 end if;
6695
6696 if Index = Names'Last then
6697 Error_Msg_Name_1 := Pname;
6698 Error_Msg_N ("pragma% does not allow & argument", Arg);
6699
6700 -- Check for possible misspelling
6701
6702 for Index1 in Names'Range loop
6703 if Is_Bad_Spelling_Of
6704 (Chars (Arg), Names (Index1))
6705 then
6706 Error_Msg_Name_1 := Names (Index1);
6707 Error_Msg_N -- CODEFIX
6708 ("\possible misspelling of%", Arg);
6709 exit;
6710 end if;
6711 end loop;
6712
6713 raise Pragma_Exit;
6714 end if;
6715 end loop;
6716 end if;
6717
6718 Next (Arg);
6719 end loop;
6720 end Gather_Associations;
6721
6722 -----------------
6723 -- GNAT_Pragma --
6724 -----------------
6725
6726 procedure GNAT_Pragma is
6727 begin
6728 -- We need to check the No_Implementation_Pragmas restriction for
6729 -- the case of a pragma from source. Note that the case of aspects
6730 -- generating corresponding pragmas marks these pragmas as not being
6731 -- from source, so this test also catches that case.
6732
6733 if Comes_From_Source (N) then
6734 Check_Restriction (No_Implementation_Pragmas, N);
6735 end if;
6736 end GNAT_Pragma;
6737
6738 --------------------------
6739 -- Is_Before_First_Decl --
6740 --------------------------
6741
6742 function Is_Before_First_Decl
6743 (Pragma_Node : Node_Id;
6744 Decls : List_Id) return Boolean
6745 is
6746 Item : Node_Id := First (Decls);
6747
6748 begin
6749 -- Only other pragmas can come before this pragma
6750
6751 loop
6752 if No (Item) or else Nkind (Item) /= N_Pragma then
6753 return False;
6754
6755 elsif Item = Pragma_Node then
6756 return True;
6757 end if;
6758
6759 Next (Item);
6760 end loop;
6761 end Is_Before_First_Decl;
6762
6763 -----------------------------
6764 -- Is_Configuration_Pragma --
6765 -----------------------------
6766
6767 -- A configuration pragma must appear in the context clause of a
6768 -- compilation unit, and only other pragmas may precede it. Note that
6769 -- the test below also permits use in a configuration pragma file.
6770
6771 function Is_Configuration_Pragma return Boolean is
6772 Lis : constant List_Id := List_Containing (N);
6773 Par : constant Node_Id := Parent (N);
6774 Prg : Node_Id;
6775
6776 begin
6777 -- If no parent, then we are in the configuration pragma file,
6778 -- so the placement is definitely appropriate.
6779
6780 if No (Par) then
6781 return True;
6782
6783 -- Otherwise we must be in the context clause of a compilation unit
6784 -- and the only thing allowed before us in the context list is more
6785 -- configuration pragmas.
6786
6787 elsif Nkind (Par) = N_Compilation_Unit
6788 and then Context_Items (Par) = Lis
6789 then
6790 Prg := First (Lis);
6791
6792 loop
6793 if Prg = N then
6794 return True;
6795 elsif Nkind (Prg) /= N_Pragma then
6796 return False;
6797 end if;
6798
6799 Next (Prg);
6800 end loop;
6801
6802 else
6803 return False;
6804 end if;
6805 end Is_Configuration_Pragma;
6806
6807 --------------------------
6808 -- Is_In_Context_Clause --
6809 --------------------------
6810
6811 function Is_In_Context_Clause return Boolean is
6812 Plist : List_Id;
6813 Parent_Node : Node_Id;
6814
6815 begin
6816 if not Is_List_Member (N) then
6817 return False;
6818
6819 else
6820 Plist := List_Containing (N);
6821 Parent_Node := Parent (Plist);
6822
6823 if Parent_Node = Empty
6824 or else Nkind (Parent_Node) /= N_Compilation_Unit
6825 or else Context_Items (Parent_Node) /= Plist
6826 then
6827 return False;
6828 end if;
6829 end if;
6830
6831 return True;
6832 end Is_In_Context_Clause;
6833
6834 ---------------------------------
6835 -- Is_Static_String_Expression --
6836 ---------------------------------
6837
6838 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
6839 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6840 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
6841
6842 begin
6843 Analyze_And_Resolve (Argx);
6844
6845 -- Special case Ada 83, where the expression will never be static,
6846 -- but we will return true if we had a string literal to start with.
6847
6848 if Ada_Version = Ada_83 then
6849 return Lit;
6850
6851 -- Normal case, true only if we end up with a string literal that
6852 -- is marked as being the result of evaluating a static expression.
6853
6854 else
6855 return Is_OK_Static_Expression (Argx)
6856 and then Nkind (Argx) = N_String_Literal;
6857 end if;
6858
6859 end Is_Static_String_Expression;
6860
6861 ----------------------
6862 -- Pragma_Misplaced --
6863 ----------------------
6864
6865 procedure Pragma_Misplaced is
6866 begin
6867 Error_Pragma ("incorrect placement of pragma%");
6868 end Pragma_Misplaced;
6869
6870 ------------------------------------------------
6871 -- Process_Atomic_Independent_Shared_Volatile --
6872 ------------------------------------------------
6873
6874 procedure Process_Atomic_Independent_Shared_Volatile is
6875 procedure Set_Atomic_VFA (E : Entity_Id);
6876 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
6877 -- no explicit alignment was given, set alignment to unknown, since
6878 -- back end knows what the alignment requirements are for atomic and
6879 -- full access arrays. Note: this is necessary for derived types.
6880
6881 --------------------
6882 -- Set_Atomic_VFA --
6883 --------------------
6884
6885 procedure Set_Atomic_VFA (E : Entity_Id) is
6886 begin
6887 if Prag_Id = Pragma_Volatile_Full_Access then
6888 Set_Is_Volatile_Full_Access (E);
6889 else
6890 Set_Is_Atomic (E);
6891 end if;
6892
6893 if not Has_Alignment_Clause (E) then
6894 Set_Alignment (E, Uint_0);
6895 end if;
6896 end Set_Atomic_VFA;
6897
6898 -- Local variables
6899
6900 Decl : Node_Id;
6901 E : Entity_Id;
6902 E_Arg : Node_Id;
6903
6904 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
6905
6906 begin
6907 Check_Ada_83_Warning;
6908 Check_No_Identifiers;
6909 Check_Arg_Count (1);
6910 Check_Arg_Is_Local_Name (Arg1);
6911 E_Arg := Get_Pragma_Arg (Arg1);
6912
6913 if Etype (E_Arg) = Any_Type then
6914 return;
6915 end if;
6916
6917 E := Entity (E_Arg);
6918
6919 -- A pragma that applies to a Ghost entity becomes Ghost for the
6920 -- purposes of legality checks and removal of ignored Ghost code.
6921
6922 Mark_Ghost_Pragma (N, E);
6923
6924 -- Check duplicate before we chain ourselves
6925
6926 Check_Duplicate_Pragma (E);
6927
6928 -- Check Atomic and VFA used together
6929
6930 if (Is_Atomic (E) and then Prag_Id = Pragma_Volatile_Full_Access)
6931 or else (Is_Volatile_Full_Access (E)
6932 and then (Prag_Id = Pragma_Atomic
6933 or else
6934 Prag_Id = Pragma_Shared))
6935 then
6936 Error_Pragma
6937 ("cannot have Volatile_Full_Access and Atomic for same entity");
6938 end if;
6939
6940 -- Check for applying VFA to an entity which has aliased component
6941
6942 if Prag_Id = Pragma_Volatile_Full_Access then
6943 declare
6944 Comp : Entity_Id;
6945 Aliased_Comp : Boolean := False;
6946 -- Set True if aliased component present
6947
6948 begin
6949 if Is_Array_Type (Etype (E)) then
6950 Aliased_Comp := Has_Aliased_Components (Etype (E));
6951
6952 -- Record case, too bad Has_Aliased_Components is not also
6953 -- set for records, should it be ???
6954
6955 elsif Is_Record_Type (Etype (E)) then
6956 Comp := First_Component_Or_Discriminant (Etype (E));
6957 while Present (Comp) loop
6958 if Is_Aliased (Comp)
6959 or else Is_Aliased (Etype (Comp))
6960 then
6961 Aliased_Comp := True;
6962 exit;
6963 end if;
6964
6965 Next_Component_Or_Discriminant (Comp);
6966 end loop;
6967 end if;
6968
6969 if Aliased_Comp then
6970 Error_Pragma
6971 ("cannot apply Volatile_Full_Access (aliased component "
6972 & "present)");
6973 end if;
6974 end;
6975 end if;
6976
6977 -- Now check appropriateness of the entity
6978
6979 Decl := Declaration_Node (E);
6980
6981 if Is_Type (E) then
6982 if Rep_Item_Too_Early (E, N)
6983 or else
6984 Rep_Item_Too_Late (E, N)
6985 then
6986 return;
6987 else
6988 Check_First_Subtype (Arg1);
6989 end if;
6990
6991 -- Attribute belongs on the base type. If the view of the type is
6992 -- currently private, it also belongs on the underlying type.
6993
6994 if Prag_Id = Pragma_Atomic
6995 or else
6996 Prag_Id = Pragma_Shared
6997 or else
6998 Prag_Id = Pragma_Volatile_Full_Access
6999 then
7000 Set_Atomic_VFA (E);
7001 Set_Atomic_VFA (Base_Type (E));
7002 Set_Atomic_VFA (Underlying_Type (E));
7003 end if;
7004
7005 -- Atomic/Shared/Volatile_Full_Access imply Independent
7006
7007 if Prag_Id /= Pragma_Volatile then
7008 Set_Is_Independent (E);
7009 Set_Is_Independent (Base_Type (E));
7010 Set_Is_Independent (Underlying_Type (E));
7011
7012 if Prag_Id = Pragma_Independent then
7013 Record_Independence_Check (N, Base_Type (E));
7014 end if;
7015 end if;
7016
7017 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7018
7019 if Prag_Id /= Pragma_Independent then
7020 Set_Is_Volatile (E);
7021 Set_Is_Volatile (Base_Type (E));
7022 Set_Is_Volatile (Underlying_Type (E));
7023
7024 Set_Treat_As_Volatile (E);
7025 Set_Treat_As_Volatile (Underlying_Type (E));
7026 end if;
7027
7028 elsif Nkind (Decl) = N_Object_Declaration
7029 or else (Nkind (Decl) = N_Component_Declaration
7030 and then Original_Record_Component (E) = E)
7031 then
7032 if Rep_Item_Too_Late (E, N) then
7033 return;
7034 end if;
7035
7036 if Prag_Id = Pragma_Atomic
7037 or else
7038 Prag_Id = Pragma_Shared
7039 or else
7040 Prag_Id = Pragma_Volatile_Full_Access
7041 then
7042 if Prag_Id = Pragma_Volatile_Full_Access then
7043 Set_Is_Volatile_Full_Access (E);
7044 else
7045 Set_Is_Atomic (E);
7046 end if;
7047
7048 -- If the object declaration has an explicit initialization, a
7049 -- temporary may have to be created to hold the expression, to
7050 -- ensure that access to the object remain atomic.
7051
7052 if Nkind (Parent (E)) = N_Object_Declaration
7053 and then Present (Expression (Parent (E)))
7054 then
7055 Set_Has_Delayed_Freeze (E);
7056 end if;
7057 end if;
7058
7059 -- Atomic/Shared/Volatile_Full_Access imply Independent
7060
7061 if Prag_Id /= Pragma_Volatile then
7062 Set_Is_Independent (E);
7063
7064 if Prag_Id = Pragma_Independent then
7065 Record_Independence_Check (N, E);
7066 end if;
7067 end if;
7068
7069 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7070
7071 if Prag_Id /= Pragma_Independent then
7072 Set_Is_Volatile (E);
7073 Set_Treat_As_Volatile (E);
7074 end if;
7075
7076 else
7077 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7078 end if;
7079
7080 -- The following check is only relevant when SPARK_Mode is on as
7081 -- this is not a standard Ada legality rule. Pragma Volatile can
7082 -- only apply to a full type declaration or an object declaration
7083 -- (SPARK RM 7.1.3(2)). Original_Node is necessary to account for
7084 -- untagged derived types that are rewritten as subtypes of their
7085 -- respective root types.
7086
7087 if SPARK_Mode = On
7088 and then Prag_Id = Pragma_Volatile
7089 and then
7090 not Nkind_In (Original_Node (Decl), N_Full_Type_Declaration,
7091 N_Object_Declaration)
7092 then
7093 Error_Pragma_Arg
7094 ("argument of pragma % must denote a full type or object "
7095 & "declaration", Arg1);
7096 end if;
7097 end Process_Atomic_Independent_Shared_Volatile;
7098
7099 -------------------------------------------
7100 -- Process_Compile_Time_Warning_Or_Error --
7101 -------------------------------------------
7102
7103 procedure Process_Compile_Time_Warning_Or_Error is
7104 Validation_Needed : Boolean := False;
7105
7106 function Check_Node (N : Node_Id) return Traverse_Result;
7107 -- Tree visitor that checks if N is an attribute reference that can
7108 -- be statically computed by the back end. Validation_Needed is set
7109 -- to True if found.
7110
7111 ----------------
7112 -- Check_Node --
7113 ----------------
7114
7115 function Check_Node (N : Node_Id) return Traverse_Result is
7116 begin
7117 if Nkind (N) = N_Attribute_Reference
7118 and then Is_Entity_Name (Prefix (N))
7119 then
7120 declare
7121 Attr_Id : constant Attribute_Id :=
7122 Get_Attribute_Id (Attribute_Name (N));
7123 begin
7124 if Attr_Id = Attribute_Alignment
7125 or else Attr_Id = Attribute_Size
7126 then
7127 Validation_Needed := True;
7128 end if;
7129 end;
7130 end if;
7131
7132 return OK;
7133 end Check_Node;
7134
7135 procedure Check_Expression is new Traverse_Proc (Check_Node);
7136
7137 -- Local variables
7138
7139 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
7140
7141 -- Start of processing for Process_Compile_Time_Warning_Or_Error
7142
7143 begin
7144 Check_Arg_Count (2);
7145 Check_No_Identifiers;
7146 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
7147 Analyze_And_Resolve (Arg1x, Standard_Boolean);
7148
7149 if Compile_Time_Known_Value (Arg1x) then
7150 Process_Compile_Time_Warning_Or_Error (N, Sloc (Arg1));
7151
7152 -- Register the expression for its validation after the back end has
7153 -- been called if it has occurrences of attributes Size or Alignment
7154 -- (because they may be statically computed by the back end and hence
7155 -- the whole expression needs to be reevaluated).
7156
7157 else
7158 Check_Expression (Arg1x);
7159
7160 if Validation_Needed then
7161 Sem_Ch13.Validate_Compile_Time_Warning_Error (N);
7162 end if;
7163 end if;
7164 end Process_Compile_Time_Warning_Or_Error;
7165
7166 ------------------------
7167 -- Process_Convention --
7168 ------------------------
7169
7170 procedure Process_Convention
7171 (C : out Convention_Id;
7172 Ent : out Entity_Id)
7173 is
7174 Cname : Name_Id;
7175
7176 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
7177 -- Called if we have more than one Export/Import/Convention pragma.
7178 -- This is generally illegal, but we have a special case of allowing
7179 -- Import and Interface to coexist if they specify the convention in
7180 -- a consistent manner. We are allowed to do this, since Interface is
7181 -- an implementation defined pragma, and we choose to do it since we
7182 -- know Rational allows this combination. S is the entity id of the
7183 -- subprogram in question. This procedure also sets the special flag
7184 -- Import_Interface_Present in both pragmas in the case where we do
7185 -- have matching Import and Interface pragmas.
7186
7187 procedure Set_Convention_From_Pragma (E : Entity_Id);
7188 -- Set convention in entity E, and also flag that the entity has a
7189 -- convention pragma. If entity is for a private or incomplete type,
7190 -- also set convention and flag on underlying type. This procedure
7191 -- also deals with the special case of C_Pass_By_Copy convention,
7192 -- and error checks for inappropriate convention specification.
7193
7194 -------------------------------
7195 -- Diagnose_Multiple_Pragmas --
7196 -------------------------------
7197
7198 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
7199 Pdec : constant Node_Id := Declaration_Node (S);
7200 Decl : Node_Id;
7201 Err : Boolean;
7202
7203 function Same_Convention (Decl : Node_Id) return Boolean;
7204 -- Decl is a pragma node. This function returns True if this
7205 -- pragma has a first argument that is an identifier with a
7206 -- Chars field corresponding to the Convention_Id C.
7207
7208 function Same_Name (Decl : Node_Id) return Boolean;
7209 -- Decl is a pragma node. This function returns True if this
7210 -- pragma has a second argument that is an identifier with a
7211 -- Chars field that matches the Chars of the current subprogram.
7212
7213 ---------------------
7214 -- Same_Convention --
7215 ---------------------
7216
7217 function Same_Convention (Decl : Node_Id) return Boolean is
7218 Arg1 : constant Node_Id :=
7219 First (Pragma_Argument_Associations (Decl));
7220
7221 begin
7222 if Present (Arg1) then
7223 declare
7224 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
7225 begin
7226 if Nkind (Arg) = N_Identifier
7227 and then Is_Convention_Name (Chars (Arg))
7228 and then Get_Convention_Id (Chars (Arg)) = C
7229 then
7230 return True;
7231 end if;
7232 end;
7233 end if;
7234
7235 return False;
7236 end Same_Convention;
7237
7238 ---------------
7239 -- Same_Name --
7240 ---------------
7241
7242 function Same_Name (Decl : Node_Id) return Boolean is
7243 Arg1 : constant Node_Id :=
7244 First (Pragma_Argument_Associations (Decl));
7245 Arg2 : Node_Id;
7246
7247 begin
7248 if No (Arg1) then
7249 return False;
7250 end if;
7251
7252 Arg2 := Next (Arg1);
7253
7254 if No (Arg2) then
7255 return False;
7256 end if;
7257
7258 declare
7259 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
7260 begin
7261 if Nkind (Arg) = N_Identifier
7262 and then Chars (Arg) = Chars (S)
7263 then
7264 return True;
7265 end if;
7266 end;
7267
7268 return False;
7269 end Same_Name;
7270
7271 -- Start of processing for Diagnose_Multiple_Pragmas
7272
7273 begin
7274 Err := True;
7275
7276 -- Definitely give message if we have Convention/Export here
7277
7278 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
7279 null;
7280
7281 -- If we have an Import or Export, scan back from pragma to
7282 -- find any previous pragma applying to the same procedure.
7283 -- The scan will be terminated by the start of the list, or
7284 -- hitting the subprogram declaration. This won't allow one
7285 -- pragma to appear in the public part and one in the private
7286 -- part, but that seems very unlikely in practice.
7287
7288 else
7289 Decl := Prev (N);
7290 while Present (Decl) and then Decl /= Pdec loop
7291
7292 -- Look for pragma with same name as us
7293
7294 if Nkind (Decl) = N_Pragma
7295 and then Same_Name (Decl)
7296 then
7297 -- Give error if same as our pragma or Export/Convention
7298
7299 if Nam_In (Pragma_Name_Unmapped (Decl),
7300 Name_Export,
7301 Name_Convention,
7302 Pragma_Name_Unmapped (N))
7303 then
7304 exit;
7305
7306 -- Case of Import/Interface or the other way round
7307
7308 elsif Nam_In (Pragma_Name_Unmapped (Decl),
7309 Name_Interface, Name_Import)
7310 then
7311 -- Here we know that we have Import and Interface. It
7312 -- doesn't matter which way round they are. See if
7313 -- they specify the same convention. If so, all OK,
7314 -- and set special flags to stop other messages
7315
7316 if Same_Convention (Decl) then
7317 Set_Import_Interface_Present (N);
7318 Set_Import_Interface_Present (Decl);
7319 Err := False;
7320
7321 -- If different conventions, special message
7322
7323 else
7324 Error_Msg_Sloc := Sloc (Decl);
7325 Error_Pragma_Arg
7326 ("convention differs from that given#", Arg1);
7327 return;
7328 end if;
7329 end if;
7330 end if;
7331
7332 Next (Decl);
7333 end loop;
7334 end if;
7335
7336 -- Give message if needed if we fall through those tests
7337 -- except on Relaxed_RM_Semantics where we let go: either this
7338 -- is a case accepted/ignored by other Ada compilers (e.g.
7339 -- a mix of Convention and Import), or another error will be
7340 -- generated later (e.g. using both Import and Export).
7341
7342 if Err and not Relaxed_RM_Semantics then
7343 Error_Pragma_Arg
7344 ("at most one Convention/Export/Import pragma is allowed",
7345 Arg2);
7346 end if;
7347 end Diagnose_Multiple_Pragmas;
7348
7349 --------------------------------
7350 -- Set_Convention_From_Pragma --
7351 --------------------------------
7352
7353 procedure Set_Convention_From_Pragma (E : Entity_Id) is
7354 begin
7355 -- Ada 2005 (AI-430): Check invalid attempt to change convention
7356 -- for an overridden dispatching operation. Technically this is
7357 -- an amendment and should only be done in Ada 2005 mode. However,
7358 -- this is clearly a mistake, since the problem that is addressed
7359 -- by this AI is that there is a clear gap in the RM.
7360
7361 if Is_Dispatching_Operation (E)
7362 and then Present (Overridden_Operation (E))
7363 and then C /= Convention (Overridden_Operation (E))
7364 then
7365 Error_Pragma_Arg
7366 ("cannot change convention for overridden dispatching "
7367 & "operation", Arg1);
7368 end if;
7369
7370 -- Special checks for Convention_Stdcall
7371
7372 if C = Convention_Stdcall then
7373
7374 -- A dispatching call is not allowed. A dispatching subprogram
7375 -- cannot be used to interface to the Win32 API, so in fact
7376 -- this check does not impose any effective restriction.
7377
7378 if Is_Dispatching_Operation (E) then
7379 Error_Msg_Sloc := Sloc (E);
7380
7381 -- Note: make this unconditional so that if there is more
7382 -- than one call to which the pragma applies, we get a
7383 -- message for each call. Also don't use Error_Pragma,
7384 -- so that we get multiple messages.
7385
7386 Error_Msg_N
7387 ("dispatching subprogram# cannot use Stdcall convention!",
7388 Arg1);
7389
7390 -- Several allowed cases
7391
7392 elsif Is_Subprogram_Or_Generic_Subprogram (E)
7393
7394 -- A variable is OK
7395
7396 or else Ekind (E) = E_Variable
7397
7398 -- A component as well. The entity does not have its Ekind
7399 -- set until the enclosing record declaration is fully
7400 -- analyzed.
7401
7402 or else Nkind (Parent (E)) = N_Component_Declaration
7403
7404 -- An access to subprogram is also allowed
7405
7406 or else
7407 (Is_Access_Type (E)
7408 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
7409
7410 -- Allow internal call to set convention of subprogram type
7411
7412 or else Ekind (E) = E_Subprogram_Type
7413 then
7414 null;
7415
7416 else
7417 Error_Pragma_Arg
7418 ("second argument of pragma% must be subprogram (type)",
7419 Arg2);
7420 end if;
7421 end if;
7422
7423 -- Set the convention
7424
7425 Set_Convention (E, C);
7426 Set_Has_Convention_Pragma (E);
7427
7428 -- For the case of a record base type, also set the convention of
7429 -- any anonymous access types declared in the record which do not
7430 -- currently have a specified convention.
7431
7432 if Is_Record_Type (E) and then Is_Base_Type (E) then
7433 declare
7434 Comp : Node_Id;
7435
7436 begin
7437 Comp := First_Component (E);
7438 while Present (Comp) loop
7439 if Present (Etype (Comp))
7440 and then Ekind_In (Etype (Comp),
7441 E_Anonymous_Access_Type,
7442 E_Anonymous_Access_Subprogram_Type)
7443 and then not Has_Convention_Pragma (Comp)
7444 then
7445 Set_Convention (Comp, C);
7446 end if;
7447
7448 Next_Component (Comp);
7449 end loop;
7450 end;
7451 end if;
7452
7453 -- Deal with incomplete/private type case, where underlying type
7454 -- is available, so set convention of that underlying type.
7455
7456 if Is_Incomplete_Or_Private_Type (E)
7457 and then Present (Underlying_Type (E))
7458 then
7459 Set_Convention (Underlying_Type (E), C);
7460 Set_Has_Convention_Pragma (Underlying_Type (E), True);
7461 end if;
7462
7463 -- A class-wide type should inherit the convention of the specific
7464 -- root type (although this isn't specified clearly by the RM).
7465
7466 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
7467 Set_Convention (Class_Wide_Type (E), C);
7468 end if;
7469
7470 -- If the entity is a record type, then check for special case of
7471 -- C_Pass_By_Copy, which is treated the same as C except that the
7472 -- special record flag is set. This convention is only permitted
7473 -- on record types (see AI95-00131).
7474
7475 if Cname = Name_C_Pass_By_Copy then
7476 if Is_Record_Type (E) then
7477 Set_C_Pass_By_Copy (Base_Type (E));
7478 elsif Is_Incomplete_Or_Private_Type (E)
7479 and then Is_Record_Type (Underlying_Type (E))
7480 then
7481 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
7482 else
7483 Error_Pragma_Arg
7484 ("C_Pass_By_Copy convention allowed only for record type",
7485 Arg2);
7486 end if;
7487 end if;
7488
7489 -- If the entity is a derived boolean type, check for the special
7490 -- case of convention C, C++, or Fortran, where we consider any
7491 -- nonzero value to represent true.
7492
7493 if Is_Discrete_Type (E)
7494 and then Root_Type (Etype (E)) = Standard_Boolean
7495 and then
7496 (C = Convention_C
7497 or else
7498 C = Convention_CPP
7499 or else
7500 C = Convention_Fortran)
7501 then
7502 Set_Nonzero_Is_True (Base_Type (E));
7503 end if;
7504 end Set_Convention_From_Pragma;
7505
7506 -- Local variables
7507
7508 Comp_Unit : Unit_Number_Type;
7509 E : Entity_Id;
7510 E1 : Entity_Id;
7511 Id : Node_Id;
7512
7513 -- Start of processing for Process_Convention
7514
7515 begin
7516 Check_At_Least_N_Arguments (2);
7517 Check_Optional_Identifier (Arg1, Name_Convention);
7518 Check_Arg_Is_Identifier (Arg1);
7519 Cname := Chars (Get_Pragma_Arg (Arg1));
7520
7521 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
7522 -- tested again below to set the critical flag).
7523
7524 if Cname = Name_C_Pass_By_Copy then
7525 C := Convention_C;
7526
7527 -- Otherwise we must have something in the standard convention list
7528
7529 elsif Is_Convention_Name (Cname) then
7530 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
7531
7532 -- Otherwise warn on unrecognized convention
7533
7534 else
7535 if Warn_On_Export_Import then
7536 Error_Msg_N
7537 ("??unrecognized convention name, C assumed",
7538 Get_Pragma_Arg (Arg1));
7539 end if;
7540
7541 C := Convention_C;
7542 end if;
7543
7544 Check_Optional_Identifier (Arg2, Name_Entity);
7545 Check_Arg_Is_Local_Name (Arg2);
7546
7547 Id := Get_Pragma_Arg (Arg2);
7548 Analyze (Id);
7549
7550 if not Is_Entity_Name (Id) then
7551 Error_Pragma_Arg ("entity name required", Arg2);
7552 end if;
7553
7554 E := Entity (Id);
7555
7556 -- Set entity to return
7557
7558 Ent := E;
7559
7560 -- Ada_Pass_By_Copy special checking
7561
7562 if C = Convention_Ada_Pass_By_Copy then
7563 if not Is_First_Subtype (E) then
7564 Error_Pragma_Arg
7565 ("convention `Ada_Pass_By_Copy` only allowed for types",
7566 Arg2);
7567 end if;
7568
7569 if Is_By_Reference_Type (E) then
7570 Error_Pragma_Arg
7571 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
7572 & "type", Arg1);
7573 end if;
7574
7575 -- Ada_Pass_By_Reference special checking
7576
7577 elsif C = Convention_Ada_Pass_By_Reference then
7578 if not Is_First_Subtype (E) then
7579 Error_Pragma_Arg
7580 ("convention `Ada_Pass_By_Reference` only allowed for types",
7581 Arg2);
7582 end if;
7583
7584 if Is_By_Copy_Type (E) then
7585 Error_Pragma_Arg
7586 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
7587 & "type", Arg1);
7588 end if;
7589 end if;
7590
7591 -- Go to renamed subprogram if present, since convention applies to
7592 -- the actual renamed entity, not to the renaming entity. If the
7593 -- subprogram is inherited, go to parent subprogram.
7594
7595 if Is_Subprogram (E)
7596 and then Present (Alias (E))
7597 then
7598 if Nkind (Parent (Declaration_Node (E))) =
7599 N_Subprogram_Renaming_Declaration
7600 then
7601 if Scope (E) /= Scope (Alias (E)) then
7602 Error_Pragma_Ref
7603 ("cannot apply pragma% to non-local entity&#", E);
7604 end if;
7605
7606 E := Alias (E);
7607
7608 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
7609 N_Private_Extension_Declaration)
7610 and then Scope (E) = Scope (Alias (E))
7611 then
7612 E := Alias (E);
7613
7614 -- Return the parent subprogram the entity was inherited from
7615
7616 Ent := E;
7617 end if;
7618 end if;
7619
7620 -- Check that we are not applying this to a specless body. Relax this
7621 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
7622
7623 if Is_Subprogram (E)
7624 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
7625 and then not Relaxed_RM_Semantics
7626 then
7627 Error_Pragma
7628 ("pragma% requires separate spec and must come before body");
7629 end if;
7630
7631 -- Check that we are not applying this to a named constant
7632
7633 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
7634 Error_Msg_Name_1 := Pname;
7635 Error_Msg_N
7636 ("cannot apply pragma% to named constant!",
7637 Get_Pragma_Arg (Arg2));
7638 Error_Pragma_Arg
7639 ("\supply appropriate type for&!", Arg2);
7640 end if;
7641
7642 if Ekind (E) = E_Enumeration_Literal then
7643 Error_Pragma ("enumeration literal not allowed for pragma%");
7644 end if;
7645
7646 -- Check for rep item appearing too early or too late
7647
7648 if Etype (E) = Any_Type
7649 or else Rep_Item_Too_Early (E, N)
7650 then
7651 raise Pragma_Exit;
7652
7653 elsif Present (Underlying_Type (E)) then
7654 E := Underlying_Type (E);
7655 end if;
7656
7657 if Rep_Item_Too_Late (E, N) then
7658 raise Pragma_Exit;
7659 end if;
7660
7661 if Has_Convention_Pragma (E) then
7662 Diagnose_Multiple_Pragmas (E);
7663
7664 elsif Convention (E) = Convention_Protected
7665 or else Ekind (Scope (E)) = E_Protected_Type
7666 then
7667 Error_Pragma_Arg
7668 ("a protected operation cannot be given a different convention",
7669 Arg2);
7670 end if;
7671
7672 -- For Intrinsic, a subprogram is required
7673
7674 if C = Convention_Intrinsic
7675 and then not Is_Subprogram_Or_Generic_Subprogram (E)
7676 then
7677 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
7678
7679 if not (Is_Type (E) and then Relaxed_RM_Semantics) then
7680 Error_Pragma_Arg
7681 ("second argument of pragma% must be a subprogram", Arg2);
7682 end if;
7683 end if;
7684
7685 -- Deal with non-subprogram cases
7686
7687 if not Is_Subprogram_Or_Generic_Subprogram (E) then
7688 Set_Convention_From_Pragma (E);
7689
7690 if Is_Type (E) then
7691
7692 -- The pragma must apply to a first subtype, but it can also
7693 -- apply to a generic type in a generic formal part, in which
7694 -- case it will also appear in the corresponding instance.
7695
7696 if Is_Generic_Type (E) or else In_Instance then
7697 null;
7698 else
7699 Check_First_Subtype (Arg2);
7700 end if;
7701
7702 Set_Convention_From_Pragma (Base_Type (E));
7703
7704 -- For access subprograms, we must set the convention on the
7705 -- internally generated directly designated type as well.
7706
7707 if Ekind (E) = E_Access_Subprogram_Type then
7708 Set_Convention_From_Pragma (Directly_Designated_Type (E));
7709 end if;
7710 end if;
7711
7712 -- For the subprogram case, set proper convention for all homonyms
7713 -- in same scope and the same declarative part, i.e. the same
7714 -- compilation unit.
7715
7716 else
7717 Comp_Unit := Get_Source_Unit (E);
7718 Set_Convention_From_Pragma (E);
7719
7720 -- Treat a pragma Import as an implicit body, and pragma import
7721 -- as implicit reference (for navigation in GPS).
7722
7723 if Prag_Id = Pragma_Import then
7724 Generate_Reference (E, Id, 'b');
7725
7726 -- For exported entities we restrict the generation of references
7727 -- to entities exported to foreign languages since entities
7728 -- exported to Ada do not provide further information to GPS and
7729 -- add undesired references to the output of the gnatxref tool.
7730
7731 elsif Prag_Id = Pragma_Export
7732 and then Convention (E) /= Convention_Ada
7733 then
7734 Generate_Reference (E, Id, 'i');
7735 end if;
7736
7737 -- If the pragma comes from an aspect, it only applies to the
7738 -- given entity, not its homonyms.
7739
7740 if From_Aspect_Specification (N) then
7741 if C = Convention_Intrinsic
7742 and then Nkind (Ent) = N_Defining_Operator_Symbol
7743 then
7744 if Is_Fixed_Point_Type (Etype (Ent))
7745 or else Is_Fixed_Point_Type (Etype (First_Entity (Ent)))
7746 or else Is_Fixed_Point_Type (Etype (Last_Entity (Ent)))
7747 then
7748 Error_Msg_N
7749 ("no intrinsic operator available for this fixed-point "
7750 & "operation", N);
7751 Error_Msg_N
7752 ("\use expression functions with the desired "
7753 & "conversions made explicit", N);
7754 end if;
7755 end if;
7756
7757 return;
7758 end if;
7759
7760 -- Otherwise Loop through the homonyms of the pragma argument's
7761 -- entity, an apply convention to those in the current scope.
7762
7763 E1 := Ent;
7764
7765 loop
7766 E1 := Homonym (E1);
7767 exit when No (E1) or else Scope (E1) /= Current_Scope;
7768
7769 -- Ignore entry for which convention is already set
7770
7771 if Has_Convention_Pragma (E1) then
7772 goto Continue;
7773 end if;
7774
7775 if Is_Subprogram (E1)
7776 and then Nkind (Parent (Declaration_Node (E1))) =
7777 N_Subprogram_Body
7778 and then not Relaxed_RM_Semantics
7779 then
7780 Set_Has_Completion (E); -- to prevent cascaded error
7781 Error_Pragma_Ref
7782 ("pragma% requires separate spec and must come before "
7783 & "body#", E1);
7784 end if;
7785
7786 -- Do not set the pragma on inherited operations or on formal
7787 -- subprograms.
7788
7789 if Comes_From_Source (E1)
7790 and then Comp_Unit = Get_Source_Unit (E1)
7791 and then not Is_Formal_Subprogram (E1)
7792 and then Nkind (Original_Node (Parent (E1))) /=
7793 N_Full_Type_Declaration
7794 then
7795 if Present (Alias (E1))
7796 and then Scope (E1) /= Scope (Alias (E1))
7797 then
7798 Error_Pragma_Ref
7799 ("cannot apply pragma% to non-local entity& declared#",
7800 E1);
7801 end if;
7802
7803 Set_Convention_From_Pragma (E1);
7804
7805 if Prag_Id = Pragma_Import then
7806 Generate_Reference (E1, Id, 'b');
7807 end if;
7808 end if;
7809
7810 <<Continue>>
7811 null;
7812 end loop;
7813 end if;
7814 end Process_Convention;
7815
7816 ----------------------------------------
7817 -- Process_Disable_Enable_Atomic_Sync --
7818 ----------------------------------------
7819
7820 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
7821 begin
7822 Check_No_Identifiers;
7823 Check_At_Most_N_Arguments (1);
7824
7825 -- Modeled internally as
7826 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
7827
7828 Rewrite (N,
7829 Make_Pragma (Loc,
7830 Chars => Nam,
7831 Pragma_Argument_Associations => New_List (
7832 Make_Pragma_Argument_Association (Loc,
7833 Expression =>
7834 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
7835
7836 if Present (Arg1) then
7837 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
7838 end if;
7839
7840 Analyze (N);
7841 end Process_Disable_Enable_Atomic_Sync;
7842
7843 -------------------------------------------------
7844 -- Process_Extended_Import_Export_Internal_Arg --
7845 -------------------------------------------------
7846
7847 procedure Process_Extended_Import_Export_Internal_Arg
7848 (Arg_Internal : Node_Id := Empty)
7849 is
7850 begin
7851 if No (Arg_Internal) then
7852 Error_Pragma ("Internal parameter required for pragma%");
7853 end if;
7854
7855 if Nkind (Arg_Internal) = N_Identifier then
7856 null;
7857
7858 elsif Nkind (Arg_Internal) = N_Operator_Symbol
7859 and then (Prag_Id = Pragma_Import_Function
7860 or else
7861 Prag_Id = Pragma_Export_Function)
7862 then
7863 null;
7864
7865 else
7866 Error_Pragma_Arg
7867 ("wrong form for Internal parameter for pragma%", Arg_Internal);
7868 end if;
7869
7870 Check_Arg_Is_Local_Name (Arg_Internal);
7871 end Process_Extended_Import_Export_Internal_Arg;
7872
7873 --------------------------------------------------
7874 -- Process_Extended_Import_Export_Object_Pragma --
7875 --------------------------------------------------
7876
7877 procedure Process_Extended_Import_Export_Object_Pragma
7878 (Arg_Internal : Node_Id;
7879 Arg_External : Node_Id;
7880 Arg_Size : Node_Id)
7881 is
7882 Def_Id : Entity_Id;
7883
7884 begin
7885 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7886 Def_Id := Entity (Arg_Internal);
7887
7888 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
7889 Error_Pragma_Arg
7890 ("pragma% must designate an object", Arg_Internal);
7891 end if;
7892
7893 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
7894 or else
7895 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
7896 then
7897 Error_Pragma_Arg
7898 ("previous Common/Psect_Object applies, pragma % not permitted",
7899 Arg_Internal);
7900 end if;
7901
7902 if Rep_Item_Too_Late (Def_Id, N) then
7903 raise Pragma_Exit;
7904 end if;
7905
7906 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
7907
7908 if Present (Arg_Size) then
7909 Check_Arg_Is_External_Name (Arg_Size);
7910 end if;
7911
7912 -- Export_Object case
7913
7914 if Prag_Id = Pragma_Export_Object then
7915 if not Is_Library_Level_Entity (Def_Id) then
7916 Error_Pragma_Arg
7917 ("argument for pragma% must be library level entity",
7918 Arg_Internal);
7919 end if;
7920
7921 if Ekind (Current_Scope) = E_Generic_Package then
7922 Error_Pragma ("pragma& cannot appear in a generic unit");
7923 end if;
7924
7925 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
7926 Error_Pragma_Arg
7927 ("exported object must have compile time known size",
7928 Arg_Internal);
7929 end if;
7930
7931 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
7932 Error_Msg_N ("??duplicate Export_Object pragma", N);
7933 else
7934 Set_Exported (Def_Id, Arg_Internal);
7935 end if;
7936
7937 -- Import_Object case
7938
7939 else
7940 if Is_Concurrent_Type (Etype (Def_Id)) then
7941 Error_Pragma_Arg
7942 ("cannot use pragma% for task/protected object",
7943 Arg_Internal);
7944 end if;
7945
7946 if Ekind (Def_Id) = E_Constant then
7947 Error_Pragma_Arg
7948 ("cannot import a constant", Arg_Internal);
7949 end if;
7950
7951 if Warn_On_Export_Import
7952 and then Has_Discriminants (Etype (Def_Id))
7953 then
7954 Error_Msg_N
7955 ("imported value must be initialized??", Arg_Internal);
7956 end if;
7957
7958 if Warn_On_Export_Import
7959 and then Is_Access_Type (Etype (Def_Id))
7960 then
7961 Error_Pragma_Arg
7962 ("cannot import object of an access type??", Arg_Internal);
7963 end if;
7964
7965 if Warn_On_Export_Import
7966 and then Is_Imported (Def_Id)
7967 then
7968 Error_Msg_N ("??duplicate Import_Object pragma", N);
7969
7970 -- Check for explicit initialization present. Note that an
7971 -- initialization generated by the code generator, e.g. for an
7972 -- access type, does not count here.
7973
7974 elsif Present (Expression (Parent (Def_Id)))
7975 and then
7976 Comes_From_Source
7977 (Original_Node (Expression (Parent (Def_Id))))
7978 then
7979 Error_Msg_Sloc := Sloc (Def_Id);
7980 Error_Pragma_Arg
7981 ("imported entities cannot be initialized (RM B.1(24))",
7982 "\no initialization allowed for & declared#", Arg1);
7983 else
7984 Set_Imported (Def_Id);
7985 Note_Possible_Modification (Arg_Internal, Sure => False);
7986 end if;
7987 end if;
7988 end Process_Extended_Import_Export_Object_Pragma;
7989
7990 ------------------------------------------------------
7991 -- Process_Extended_Import_Export_Subprogram_Pragma --
7992 ------------------------------------------------------
7993
7994 procedure Process_Extended_Import_Export_Subprogram_Pragma
7995 (Arg_Internal : Node_Id;
7996 Arg_External : Node_Id;
7997 Arg_Parameter_Types : Node_Id;
7998 Arg_Result_Type : Node_Id := Empty;
7999 Arg_Mechanism : Node_Id;
8000 Arg_Result_Mechanism : Node_Id := Empty)
8001 is
8002 Ent : Entity_Id;
8003 Def_Id : Entity_Id;
8004 Hom_Id : Entity_Id;
8005 Formal : Entity_Id;
8006 Ambiguous : Boolean;
8007 Match : Boolean;
8008
8009 function Same_Base_Type
8010 (Ptype : Node_Id;
8011 Formal : Entity_Id) return Boolean;
8012 -- Determines if Ptype references the type of Formal. Note that only
8013 -- the base types need to match according to the spec. Ptype here is
8014 -- the argument from the pragma, which is either a type name, or an
8015 -- access attribute.
8016
8017 --------------------
8018 -- Same_Base_Type --
8019 --------------------
8020
8021 function Same_Base_Type
8022 (Ptype : Node_Id;
8023 Formal : Entity_Id) return Boolean
8024 is
8025 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
8026 Pref : Node_Id;
8027
8028 begin
8029 -- Case where pragma argument is typ'Access
8030
8031 if Nkind (Ptype) = N_Attribute_Reference
8032 and then Attribute_Name (Ptype) = Name_Access
8033 then
8034 Pref := Prefix (Ptype);
8035 Find_Type (Pref);
8036
8037 if not Is_Entity_Name (Pref)
8038 or else Entity (Pref) = Any_Type
8039 then
8040 raise Pragma_Exit;
8041 end if;
8042
8043 -- We have a match if the corresponding argument is of an
8044 -- anonymous access type, and its designated type matches the
8045 -- type of the prefix of the access attribute
8046
8047 return Ekind (Ftyp) = E_Anonymous_Access_Type
8048 and then Base_Type (Entity (Pref)) =
8049 Base_Type (Etype (Designated_Type (Ftyp)));
8050
8051 -- Case where pragma argument is a type name
8052
8053 else
8054 Find_Type (Ptype);
8055
8056 if not Is_Entity_Name (Ptype)
8057 or else Entity (Ptype) = Any_Type
8058 then
8059 raise Pragma_Exit;
8060 end if;
8061
8062 -- We have a match if the corresponding argument is of the type
8063 -- given in the pragma (comparing base types)
8064
8065 return Base_Type (Entity (Ptype)) = Ftyp;
8066 end if;
8067 end Same_Base_Type;
8068
8069 -- Start of processing for
8070 -- Process_Extended_Import_Export_Subprogram_Pragma
8071
8072 begin
8073 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8074 Ent := Empty;
8075 Ambiguous := False;
8076
8077 -- Loop through homonyms (overloadings) of the entity
8078
8079 Hom_Id := Entity (Arg_Internal);
8080 while Present (Hom_Id) loop
8081 Def_Id := Get_Base_Subprogram (Hom_Id);
8082
8083 -- We need a subprogram in the current scope
8084
8085 if not Is_Subprogram (Def_Id)
8086 or else Scope (Def_Id) /= Current_Scope
8087 then
8088 null;
8089
8090 else
8091 Match := True;
8092
8093 -- Pragma cannot apply to subprogram body
8094
8095 if Is_Subprogram (Def_Id)
8096 and then Nkind (Parent (Declaration_Node (Def_Id))) =
8097 N_Subprogram_Body
8098 then
8099 Error_Pragma
8100 ("pragma% requires separate spec and must come before "
8101 & "body");
8102 end if;
8103
8104 -- Test result type if given, note that the result type
8105 -- parameter can only be present for the function cases.
8106
8107 if Present (Arg_Result_Type)
8108 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
8109 then
8110 Match := False;
8111
8112 elsif Etype (Def_Id) /= Standard_Void_Type
8113 and then Nam_In (Pname, Name_Export_Procedure,
8114 Name_Import_Procedure)
8115 then
8116 Match := False;
8117
8118 -- Test parameter types if given. Note that this parameter has
8119 -- not been analyzed (and must not be, since it is semantic
8120 -- nonsense), so we get it as the parser left it.
8121
8122 elsif Present (Arg_Parameter_Types) then
8123 Check_Matching_Types : declare
8124 Formal : Entity_Id;
8125 Ptype : Node_Id;
8126
8127 begin
8128 Formal := First_Formal (Def_Id);
8129
8130 if Nkind (Arg_Parameter_Types) = N_Null then
8131 if Present (Formal) then
8132 Match := False;
8133 end if;
8134
8135 -- A list of one type, e.g. (List) is parsed as a
8136 -- parenthesized expression.
8137
8138 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
8139 and then Paren_Count (Arg_Parameter_Types) = 1
8140 then
8141 if No (Formal)
8142 or else Present (Next_Formal (Formal))
8143 then
8144 Match := False;
8145 else
8146 Match :=
8147 Same_Base_Type (Arg_Parameter_Types, Formal);
8148 end if;
8149
8150 -- A list of more than one type is parsed as a aggregate
8151
8152 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
8153 and then Paren_Count (Arg_Parameter_Types) = 0
8154 then
8155 Ptype := First (Expressions (Arg_Parameter_Types));
8156 while Present (Ptype) or else Present (Formal) loop
8157 if No (Ptype)
8158 or else No (Formal)
8159 or else not Same_Base_Type (Ptype, Formal)
8160 then
8161 Match := False;
8162 exit;
8163 else
8164 Next_Formal (Formal);
8165 Next (Ptype);
8166 end if;
8167 end loop;
8168
8169 -- Anything else is of the wrong form
8170
8171 else
8172 Error_Pragma_Arg
8173 ("wrong form for Parameter_Types parameter",
8174 Arg_Parameter_Types);
8175 end if;
8176 end Check_Matching_Types;
8177 end if;
8178
8179 -- Match is now False if the entry we found did not match
8180 -- either a supplied Parameter_Types or Result_Types argument
8181
8182 if Match then
8183 if No (Ent) then
8184 Ent := Def_Id;
8185
8186 -- Ambiguous case, the flag Ambiguous shows if we already
8187 -- detected this and output the initial messages.
8188
8189 else
8190 if not Ambiguous then
8191 Ambiguous := True;
8192 Error_Msg_Name_1 := Pname;
8193 Error_Msg_N
8194 ("pragma% does not uniquely identify subprogram!",
8195 N);
8196 Error_Msg_Sloc := Sloc (Ent);
8197 Error_Msg_N ("matching subprogram #!", N);
8198 Ent := Empty;
8199 end if;
8200
8201 Error_Msg_Sloc := Sloc (Def_Id);
8202 Error_Msg_N ("matching subprogram #!", N);
8203 end if;
8204 end if;
8205 end if;
8206
8207 Hom_Id := Homonym (Hom_Id);
8208 end loop;
8209
8210 -- See if we found an entry
8211
8212 if No (Ent) then
8213 if not Ambiguous then
8214 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
8215 Error_Pragma
8216 ("pragma% cannot be given for generic subprogram");
8217 else
8218 Error_Pragma
8219 ("pragma% does not identify local subprogram");
8220 end if;
8221 end if;
8222
8223 return;
8224 end if;
8225
8226 -- Import pragmas must be for imported entities
8227
8228 if Prag_Id = Pragma_Import_Function
8229 or else
8230 Prag_Id = Pragma_Import_Procedure
8231 or else
8232 Prag_Id = Pragma_Import_Valued_Procedure
8233 then
8234 if not Is_Imported (Ent) then
8235 Error_Pragma
8236 ("pragma Import or Interface must precede pragma%");
8237 end if;
8238
8239 -- Here we have the Export case which can set the entity as exported
8240
8241 -- But does not do so if the specified external name is null, since
8242 -- that is taken as a signal in DEC Ada 83 (with which we want to be
8243 -- compatible) to request no external name.
8244
8245 elsif Nkind (Arg_External) = N_String_Literal
8246 and then String_Length (Strval (Arg_External)) = 0
8247 then
8248 null;
8249
8250 -- In all other cases, set entity as exported
8251
8252 else
8253 Set_Exported (Ent, Arg_Internal);
8254 end if;
8255
8256 -- Special processing for Valued_Procedure cases
8257
8258 if Prag_Id = Pragma_Import_Valued_Procedure
8259 or else
8260 Prag_Id = Pragma_Export_Valued_Procedure
8261 then
8262 Formal := First_Formal (Ent);
8263
8264 if No (Formal) then
8265 Error_Pragma ("at least one parameter required for pragma%");
8266
8267 elsif Ekind (Formal) /= E_Out_Parameter then
8268 Error_Pragma ("first parameter must have mode out for pragma%");
8269
8270 else
8271 Set_Is_Valued_Procedure (Ent);
8272 end if;
8273 end if;
8274
8275 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
8276
8277 -- Process Result_Mechanism argument if present. We have already
8278 -- checked that this is only allowed for the function case.
8279
8280 if Present (Arg_Result_Mechanism) then
8281 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
8282 end if;
8283
8284 -- Process Mechanism parameter if present. Note that this parameter
8285 -- is not analyzed, and must not be analyzed since it is semantic
8286 -- nonsense, so we get it in exactly as the parser left it.
8287
8288 if Present (Arg_Mechanism) then
8289 declare
8290 Formal : Entity_Id;
8291 Massoc : Node_Id;
8292 Mname : Node_Id;
8293 Choice : Node_Id;
8294
8295 begin
8296 -- A single mechanism association without a formal parameter
8297 -- name is parsed as a parenthesized expression. All other
8298 -- cases are parsed as aggregates, so we rewrite the single
8299 -- parameter case as an aggregate for consistency.
8300
8301 if Nkind (Arg_Mechanism) /= N_Aggregate
8302 and then Paren_Count (Arg_Mechanism) = 1
8303 then
8304 Rewrite (Arg_Mechanism,
8305 Make_Aggregate (Sloc (Arg_Mechanism),
8306 Expressions => New_List (
8307 Relocate_Node (Arg_Mechanism))));
8308 end if;
8309
8310 -- Case of only mechanism name given, applies to all formals
8311
8312 if Nkind (Arg_Mechanism) /= N_Aggregate then
8313 Formal := First_Formal (Ent);
8314 while Present (Formal) loop
8315 Set_Mechanism_Value (Formal, Arg_Mechanism);
8316 Next_Formal (Formal);
8317 end loop;
8318
8319 -- Case of list of mechanism associations given
8320
8321 else
8322 if Null_Record_Present (Arg_Mechanism) then
8323 Error_Pragma_Arg
8324 ("inappropriate form for Mechanism parameter",
8325 Arg_Mechanism);
8326 end if;
8327
8328 -- Deal with positional ones first
8329
8330 Formal := First_Formal (Ent);
8331
8332 if Present (Expressions (Arg_Mechanism)) then
8333 Mname := First (Expressions (Arg_Mechanism));
8334 while Present (Mname) loop
8335 if No (Formal) then
8336 Error_Pragma_Arg
8337 ("too many mechanism associations", Mname);
8338 end if;
8339
8340 Set_Mechanism_Value (Formal, Mname);
8341 Next_Formal (Formal);
8342 Next (Mname);
8343 end loop;
8344 end if;
8345
8346 -- Deal with named entries
8347
8348 if Present (Component_Associations (Arg_Mechanism)) then
8349 Massoc := First (Component_Associations (Arg_Mechanism));
8350 while Present (Massoc) loop
8351 Choice := First (Choices (Massoc));
8352
8353 if Nkind (Choice) /= N_Identifier
8354 or else Present (Next (Choice))
8355 then
8356 Error_Pragma_Arg
8357 ("incorrect form for mechanism association",
8358 Massoc);
8359 end if;
8360
8361 Formal := First_Formal (Ent);
8362 loop
8363 if No (Formal) then
8364 Error_Pragma_Arg
8365 ("parameter name & not present", Choice);
8366 end if;
8367
8368 if Chars (Choice) = Chars (Formal) then
8369 Set_Mechanism_Value
8370 (Formal, Expression (Massoc));
8371
8372 -- Set entity on identifier (needed by ASIS)
8373
8374 Set_Entity (Choice, Formal);
8375
8376 exit;
8377 end if;
8378
8379 Next_Formal (Formal);
8380 end loop;
8381
8382 Next (Massoc);
8383 end loop;
8384 end if;
8385 end if;
8386 end;
8387 end if;
8388 end Process_Extended_Import_Export_Subprogram_Pragma;
8389
8390 --------------------------
8391 -- Process_Generic_List --
8392 --------------------------
8393
8394 procedure Process_Generic_List is
8395 Arg : Node_Id;
8396 Exp : Node_Id;
8397
8398 begin
8399 Check_No_Identifiers;
8400 Check_At_Least_N_Arguments (1);
8401
8402 -- Check all arguments are names of generic units or instances
8403
8404 Arg := Arg1;
8405 while Present (Arg) loop
8406 Exp := Get_Pragma_Arg (Arg);
8407 Analyze (Exp);
8408
8409 if not Is_Entity_Name (Exp)
8410 or else
8411 (not Is_Generic_Instance (Entity (Exp))
8412 and then
8413 not Is_Generic_Unit (Entity (Exp)))
8414 then
8415 Error_Pragma_Arg
8416 ("pragma% argument must be name of generic unit/instance",
8417 Arg);
8418 end if;
8419
8420 Next (Arg);
8421 end loop;
8422 end Process_Generic_List;
8423
8424 ------------------------------------
8425 -- Process_Import_Predefined_Type --
8426 ------------------------------------
8427
8428 procedure Process_Import_Predefined_Type is
8429 Loc : constant Source_Ptr := Sloc (N);
8430 Elmt : Elmt_Id;
8431 Ftyp : Node_Id := Empty;
8432 Decl : Node_Id;
8433 Def : Node_Id;
8434 Nam : Name_Id;
8435
8436 begin
8437 Nam := String_To_Name (Strval (Expression (Arg3)));
8438
8439 Elmt := First_Elmt (Predefined_Float_Types);
8440 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
8441 Next_Elmt (Elmt);
8442 end loop;
8443
8444 Ftyp := Node (Elmt);
8445
8446 if Present (Ftyp) then
8447
8448 -- Don't build a derived type declaration, because predefined C
8449 -- types have no declaration anywhere, so cannot really be named.
8450 -- Instead build a full type declaration, starting with an
8451 -- appropriate type definition is built
8452
8453 if Is_Floating_Point_Type (Ftyp) then
8454 Def := Make_Floating_Point_Definition (Loc,
8455 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
8456 Make_Real_Range_Specification (Loc,
8457 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
8458 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
8459
8460 -- Should never have a predefined type we cannot handle
8461
8462 else
8463 raise Program_Error;
8464 end if;
8465
8466 -- Build and insert a Full_Type_Declaration, which will be
8467 -- analyzed as soon as this list entry has been analyzed.
8468
8469 Decl := Make_Full_Type_Declaration (Loc,
8470 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
8471 Type_Definition => Def);
8472
8473 Insert_After (N, Decl);
8474 Mark_Rewrite_Insertion (Decl);
8475
8476 else
8477 Error_Pragma_Arg ("no matching type found for pragma%",
8478 Arg2);
8479 end if;
8480 end Process_Import_Predefined_Type;
8481
8482 ---------------------------------
8483 -- Process_Import_Or_Interface --
8484 ---------------------------------
8485
8486 procedure Process_Import_Or_Interface is
8487 C : Convention_Id;
8488 Def_Id : Entity_Id;
8489 Hom_Id : Entity_Id;
8490
8491 begin
8492 -- In Relaxed_RM_Semantics, support old Ada 83 style:
8493 -- pragma Import (Entity, "external name");
8494
8495 if Relaxed_RM_Semantics
8496 and then Arg_Count = 2
8497 and then Prag_Id = Pragma_Import
8498 and then Nkind (Expression (Arg2)) = N_String_Literal
8499 then
8500 C := Convention_C;
8501 Def_Id := Get_Pragma_Arg (Arg1);
8502 Analyze (Def_Id);
8503
8504 if not Is_Entity_Name (Def_Id) then
8505 Error_Pragma_Arg ("entity name required", Arg1);
8506 end if;
8507
8508 Def_Id := Entity (Def_Id);
8509 Kill_Size_Check_Code (Def_Id);
8510 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
8511
8512 else
8513 Process_Convention (C, Def_Id);
8514
8515 -- A pragma that applies to a Ghost entity becomes Ghost for the
8516 -- purposes of legality checks and removal of ignored Ghost code.
8517
8518 Mark_Ghost_Pragma (N, Def_Id);
8519 Kill_Size_Check_Code (Def_Id);
8520 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
8521 end if;
8522
8523 -- Various error checks
8524
8525 if Ekind_In (Def_Id, E_Variable, E_Constant) then
8526
8527 -- We do not permit Import to apply to a renaming declaration
8528
8529 if Present (Renamed_Object (Def_Id)) then
8530 Error_Pragma_Arg
8531 ("pragma% not allowed for object renaming", Arg2);
8532
8533 -- User initialization is not allowed for imported object, but
8534 -- the object declaration may contain a default initialization,
8535 -- that will be discarded. Note that an explicit initialization
8536 -- only counts if it comes from source, otherwise it is simply
8537 -- the code generator making an implicit initialization explicit.
8538
8539 elsif Present (Expression (Parent (Def_Id)))
8540 and then Comes_From_Source
8541 (Original_Node (Expression (Parent (Def_Id))))
8542 then
8543 -- Set imported flag to prevent cascaded errors
8544
8545 Set_Is_Imported (Def_Id);
8546
8547 Error_Msg_Sloc := Sloc (Def_Id);
8548 Error_Pragma_Arg
8549 ("no initialization allowed for declaration of& #",
8550 "\imported entities cannot be initialized (RM B.1(24))",
8551 Arg2);
8552
8553 else
8554 -- If the pragma comes from an aspect specification the
8555 -- Is_Imported flag has already been set.
8556
8557 if not From_Aspect_Specification (N) then
8558 Set_Imported (Def_Id);
8559 end if;
8560
8561 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
8562
8563 -- Note that we do not set Is_Public here. That's because we
8564 -- only want to set it if there is no address clause, and we
8565 -- don't know that yet, so we delay that processing till
8566 -- freeze time.
8567
8568 -- pragma Import completes deferred constants
8569
8570 if Ekind (Def_Id) = E_Constant then
8571 Set_Has_Completion (Def_Id);
8572 end if;
8573
8574 -- It is not possible to import a constant of an unconstrained
8575 -- array type (e.g. string) because there is no simple way to
8576 -- write a meaningful subtype for it.
8577
8578 if Is_Array_Type (Etype (Def_Id))
8579 and then not Is_Constrained (Etype (Def_Id))
8580 then
8581 Error_Msg_NE
8582 ("imported constant& must have a constrained subtype",
8583 N, Def_Id);
8584 end if;
8585 end if;
8586
8587 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
8588
8589 -- If the name is overloaded, pragma applies to all of the denoted
8590 -- entities in the same declarative part, unless the pragma comes
8591 -- from an aspect specification or was generated by the compiler
8592 -- (such as for pragma Provide_Shift_Operators).
8593
8594 Hom_Id := Def_Id;
8595 while Present (Hom_Id) loop
8596
8597 Def_Id := Get_Base_Subprogram (Hom_Id);
8598
8599 -- Ignore inherited subprograms because the pragma will apply
8600 -- to the parent operation, which is the one called.
8601
8602 if Is_Overloadable (Def_Id)
8603 and then Present (Alias (Def_Id))
8604 then
8605 null;
8606
8607 -- If it is not a subprogram, it must be in an outer scope and
8608 -- pragma does not apply.
8609
8610 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
8611 null;
8612
8613 -- The pragma does not apply to primitives of interfaces
8614
8615 elsif Is_Dispatching_Operation (Def_Id)
8616 and then Present (Find_Dispatching_Type (Def_Id))
8617 and then Is_Interface (Find_Dispatching_Type (Def_Id))
8618 then
8619 null;
8620
8621 -- Verify that the homonym is in the same declarative part (not
8622 -- just the same scope). If the pragma comes from an aspect
8623 -- specification we know that it is part of the declaration.
8624
8625 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
8626 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
8627 and then not From_Aspect_Specification (N)
8628 then
8629 exit;
8630
8631 else
8632 -- If the pragma comes from an aspect specification the
8633 -- Is_Imported flag has already been set.
8634
8635 if not From_Aspect_Specification (N) then
8636 Set_Imported (Def_Id);
8637 end if;
8638
8639 -- Reject an Import applied to an abstract subprogram
8640
8641 if Is_Subprogram (Def_Id)
8642 and then Is_Abstract_Subprogram (Def_Id)
8643 then
8644 Error_Msg_Sloc := Sloc (Def_Id);
8645 Error_Msg_NE
8646 ("cannot import abstract subprogram& declared#",
8647 Arg2, Def_Id);
8648 end if;
8649
8650 -- Special processing for Convention_Intrinsic
8651
8652 if C = Convention_Intrinsic then
8653
8654 -- Link_Name argument not allowed for intrinsic
8655
8656 Check_No_Link_Name;
8657
8658 Set_Is_Intrinsic_Subprogram (Def_Id);
8659
8660 -- If no external name is present, then check that this
8661 -- is a valid intrinsic subprogram. If an external name
8662 -- is present, then this is handled by the back end.
8663
8664 if No (Arg3) then
8665 Check_Intrinsic_Subprogram
8666 (Def_Id, Get_Pragma_Arg (Arg2));
8667 end if;
8668 end if;
8669
8670 -- Verify that the subprogram does not have a completion
8671 -- through a renaming declaration. For other completions the
8672 -- pragma appears as a too late representation.
8673
8674 declare
8675 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
8676
8677 begin
8678 if Present (Decl)
8679 and then Nkind (Decl) = N_Subprogram_Declaration
8680 and then Present (Corresponding_Body (Decl))
8681 and then Nkind (Unit_Declaration_Node
8682 (Corresponding_Body (Decl))) =
8683 N_Subprogram_Renaming_Declaration
8684 then
8685 Error_Msg_Sloc := Sloc (Def_Id);
8686 Error_Msg_NE
8687 ("cannot import&, renaming already provided for "
8688 & "declaration #", N, Def_Id);
8689 end if;
8690 end;
8691
8692 -- If the pragma comes from an aspect specification, there
8693 -- must be an Import aspect specified as well. In the rare
8694 -- case where Import is set to False, the suprogram needs to
8695 -- have a local completion.
8696
8697 declare
8698 Imp_Aspect : constant Node_Id :=
8699 Find_Aspect (Def_Id, Aspect_Import);
8700 Expr : Node_Id;
8701
8702 begin
8703 if Present (Imp_Aspect)
8704 and then Present (Expression (Imp_Aspect))
8705 then
8706 Expr := Expression (Imp_Aspect);
8707 Analyze_And_Resolve (Expr, Standard_Boolean);
8708
8709 if Is_Entity_Name (Expr)
8710 and then Entity (Expr) = Standard_True
8711 then
8712 Set_Has_Completion (Def_Id);
8713 end if;
8714
8715 -- If there is no expression, the default is True, as for
8716 -- all boolean aspects. Same for the older pragma.
8717
8718 else
8719 Set_Has_Completion (Def_Id);
8720 end if;
8721 end;
8722
8723 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
8724 end if;
8725
8726 if Is_Compilation_Unit (Hom_Id) then
8727
8728 -- Its possible homonyms are not affected by the pragma.
8729 -- Such homonyms might be present in the context of other
8730 -- units being compiled.
8731
8732 exit;
8733
8734 elsif From_Aspect_Specification (N) then
8735 exit;
8736
8737 -- If the pragma was created by the compiler, then we don't
8738 -- want it to apply to other homonyms. This kind of case can
8739 -- occur when using pragma Provide_Shift_Operators, which
8740 -- generates implicit shift and rotate operators with Import
8741 -- pragmas that might apply to earlier explicit or implicit
8742 -- declarations marked with Import (for example, coming from
8743 -- an earlier pragma Provide_Shift_Operators for another type),
8744 -- and we don't generally want other homonyms being treated
8745 -- as imported or the pragma flagged as an illegal duplicate.
8746
8747 elsif not Comes_From_Source (N) then
8748 exit;
8749
8750 else
8751 Hom_Id := Homonym (Hom_Id);
8752 end if;
8753 end loop;
8754
8755 -- Import a CPP class
8756
8757 elsif C = Convention_CPP
8758 and then (Is_Record_Type (Def_Id)
8759 or else Ekind (Def_Id) = E_Incomplete_Type)
8760 then
8761 if Ekind (Def_Id) = E_Incomplete_Type then
8762 if Present (Full_View (Def_Id)) then
8763 Def_Id := Full_View (Def_Id);
8764
8765 else
8766 Error_Msg_N
8767 ("cannot import 'C'P'P type before full declaration seen",
8768 Get_Pragma_Arg (Arg2));
8769
8770 -- Although we have reported the error we decorate it as
8771 -- CPP_Class to avoid reporting spurious errors
8772
8773 Set_Is_CPP_Class (Def_Id);
8774 return;
8775 end if;
8776 end if;
8777
8778 -- Types treated as CPP classes must be declared limited (note:
8779 -- this used to be a warning but there is no real benefit to it
8780 -- since we did effectively intend to treat the type as limited
8781 -- anyway).
8782
8783 if not Is_Limited_Type (Def_Id) then
8784 Error_Msg_N
8785 ("imported 'C'P'P type must be limited",
8786 Get_Pragma_Arg (Arg2));
8787 end if;
8788
8789 if Etype (Def_Id) /= Def_Id
8790 and then not Is_CPP_Class (Root_Type (Def_Id))
8791 then
8792 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
8793 end if;
8794
8795 Set_Is_CPP_Class (Def_Id);
8796
8797 -- Imported CPP types must not have discriminants (because C++
8798 -- classes do not have discriminants).
8799
8800 if Has_Discriminants (Def_Id) then
8801 Error_Msg_N
8802 ("imported 'C'P'P type cannot have discriminants",
8803 First (Discriminant_Specifications
8804 (Declaration_Node (Def_Id))));
8805 end if;
8806
8807 -- Check that components of imported CPP types do not have default
8808 -- expressions. For private types this check is performed when the
8809 -- full view is analyzed (see Process_Full_View).
8810
8811 if not Is_Private_Type (Def_Id) then
8812 Check_CPP_Type_Has_No_Defaults (Def_Id);
8813 end if;
8814
8815 -- Import a CPP exception
8816
8817 elsif C = Convention_CPP
8818 and then Ekind (Def_Id) = E_Exception
8819 then
8820 if No (Arg3) then
8821 Error_Pragma_Arg
8822 ("'External_'Name arguments is required for 'Cpp exception",
8823 Arg3);
8824 else
8825 -- As only a string is allowed, Check_Arg_Is_External_Name
8826 -- isn't called.
8827
8828 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8829 end if;
8830
8831 if Present (Arg4) then
8832 Error_Pragma_Arg
8833 ("Link_Name argument not allowed for imported Cpp exception",
8834 Arg4);
8835 end if;
8836
8837 -- Do not call Set_Interface_Name as the name of the exception
8838 -- shouldn't be modified (and in particular it shouldn't be
8839 -- the External_Name). For exceptions, the External_Name is the
8840 -- name of the RTTI structure.
8841
8842 -- ??? Emit an error if pragma Import/Export_Exception is present
8843
8844 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
8845 Check_No_Link_Name;
8846 Check_Arg_Count (3);
8847 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8848
8849 Process_Import_Predefined_Type;
8850
8851 else
8852 Error_Pragma_Arg
8853 ("second argument of pragma% must be object, subprogram "
8854 & "or incomplete type",
8855 Arg2);
8856 end if;
8857
8858 -- If this pragma applies to a compilation unit, then the unit, which
8859 -- is a subprogram, does not require (or allow) a body. We also do
8860 -- not need to elaborate imported procedures.
8861
8862 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
8863 declare
8864 Cunit : constant Node_Id := Parent (Parent (N));
8865 begin
8866 Set_Body_Required (Cunit, False);
8867 end;
8868 end if;
8869 end Process_Import_Or_Interface;
8870
8871 --------------------
8872 -- Process_Inline --
8873 --------------------
8874
8875 procedure Process_Inline (Status : Inline_Status) is
8876 Applies : Boolean;
8877 Assoc : Node_Id;
8878 Decl : Node_Id;
8879 Subp : Entity_Id;
8880 Subp_Id : Node_Id;
8881
8882 Ghost_Error_Posted : Boolean := False;
8883 -- Flag set when an error concerning the illegal mix of Ghost and
8884 -- non-Ghost subprograms is emitted.
8885
8886 Ghost_Id : Entity_Id := Empty;
8887 -- The entity of the first Ghost subprogram encountered while
8888 -- processing the arguments of the pragma.
8889
8890 procedure Make_Inline (Subp : Entity_Id);
8891 -- Subp is the defining unit name of the subprogram declaration. If
8892 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
8893 -- the corresponding body, if there is one present.
8894
8895 procedure Set_Inline_Flags (Subp : Entity_Id);
8896 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
8897 -- Also set or clear Is_Inlined flag on Subp depending on Status.
8898
8899 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
8900 -- Returns True if it can be determined at this stage that inlining
8901 -- is not possible, for example if the body is available and contains
8902 -- exception handlers, we prevent inlining, since otherwise we can
8903 -- get undefined symbols at link time. This function also emits a
8904 -- warning if the pragma appears too late.
8905 --
8906 -- ??? is business with link symbols still valid, or does it relate
8907 -- to front end ZCX which is being phased out ???
8908
8909 ---------------------------
8910 -- Inlining_Not_Possible --
8911 ---------------------------
8912
8913 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
8914 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
8915 Stats : Node_Id;
8916
8917 begin
8918 if Nkind (Decl) = N_Subprogram_Body then
8919 Stats := Handled_Statement_Sequence (Decl);
8920 return Present (Exception_Handlers (Stats))
8921 or else Present (At_End_Proc (Stats));
8922
8923 elsif Nkind (Decl) = N_Subprogram_Declaration
8924 and then Present (Corresponding_Body (Decl))
8925 then
8926 if Analyzed (Corresponding_Body (Decl)) then
8927 Error_Msg_N ("pragma appears too late, ignored??", N);
8928 return True;
8929
8930 -- If the subprogram is a renaming as body, the body is just a
8931 -- call to the renamed subprogram, and inlining is trivially
8932 -- possible.
8933
8934 elsif
8935 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
8936 N_Subprogram_Renaming_Declaration
8937 then
8938 return False;
8939
8940 else
8941 Stats :=
8942 Handled_Statement_Sequence
8943 (Unit_Declaration_Node (Corresponding_Body (Decl)));
8944
8945 return
8946 Present (Exception_Handlers (Stats))
8947 or else Present (At_End_Proc (Stats));
8948 end if;
8949
8950 else
8951 -- If body is not available, assume the best, the check is
8952 -- performed again when compiling enclosing package bodies.
8953
8954 return False;
8955 end if;
8956 end Inlining_Not_Possible;
8957
8958 -----------------
8959 -- Make_Inline --
8960 -----------------
8961
8962 procedure Make_Inline (Subp : Entity_Id) is
8963 Kind : constant Entity_Kind := Ekind (Subp);
8964 Inner_Subp : Entity_Id := Subp;
8965
8966 begin
8967 -- Ignore if bad type, avoid cascaded error
8968
8969 if Etype (Subp) = Any_Type then
8970 Applies := True;
8971 return;
8972
8973 -- If inlining is not possible, for now do not treat as an error
8974
8975 elsif Status /= Suppressed
8976 and then Front_End_Inlining
8977 and then Inlining_Not_Possible (Subp)
8978 then
8979 Applies := True;
8980 return;
8981
8982 -- Here we have a candidate for inlining, but we must exclude
8983 -- derived operations. Otherwise we would end up trying to inline
8984 -- a phantom declaration, and the result would be to drag in a
8985 -- body which has no direct inlining associated with it. That
8986 -- would not only be inefficient but would also result in the
8987 -- backend doing cross-unit inlining in cases where it was
8988 -- definitely inappropriate to do so.
8989
8990 -- However, a simple Comes_From_Source test is insufficient, since
8991 -- we do want to allow inlining of generic instances which also do
8992 -- not come from source. We also need to recognize specs generated
8993 -- by the front-end for bodies that carry the pragma. Finally,
8994 -- predefined operators do not come from source but are not
8995 -- inlineable either.
8996
8997 elsif Is_Generic_Instance (Subp)
8998 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
8999 then
9000 null;
9001
9002 elsif not Comes_From_Source (Subp)
9003 and then Scope (Subp) /= Standard_Standard
9004 then
9005 Applies := True;
9006 return;
9007 end if;
9008
9009 -- The referenced entity must either be the enclosing entity, or
9010 -- an entity declared within the current open scope.
9011
9012 if Present (Scope (Subp))
9013 and then Scope (Subp) /= Current_Scope
9014 and then Subp /= Current_Scope
9015 then
9016 Error_Pragma_Arg
9017 ("argument of% must be entity in current scope", Assoc);
9018 return;
9019 end if;
9020
9021 -- Processing for procedure, operator or function. If subprogram
9022 -- is aliased (as for an instance) indicate that the renamed
9023 -- entity (if declared in the same unit) is inlined.
9024 -- If this is the anonymous subprogram created for a subprogram
9025 -- instance, the inlining applies to it directly. Otherwise we
9026 -- retrieve it as the alias of the visible subprogram instance.
9027
9028 if Is_Subprogram (Subp) then
9029 if Is_Wrapper_Package (Scope (Subp)) then
9030 Inner_Subp := Subp;
9031 else
9032 Inner_Subp := Ultimate_Alias (Inner_Subp);
9033 end if;
9034
9035 if In_Same_Source_Unit (Subp, Inner_Subp) then
9036 Set_Inline_Flags (Inner_Subp);
9037
9038 Decl := Parent (Parent (Inner_Subp));
9039
9040 if Nkind (Decl) = N_Subprogram_Declaration
9041 and then Present (Corresponding_Body (Decl))
9042 then
9043 Set_Inline_Flags (Corresponding_Body (Decl));
9044
9045 elsif Is_Generic_Instance (Subp)
9046 and then Comes_From_Source (Subp)
9047 then
9048 -- Indicate that the body needs to be created for
9049 -- inlining subsequent calls. The instantiation node
9050 -- follows the declaration of the wrapper package
9051 -- created for it. The subprogram that requires the
9052 -- body is the anonymous one in the wrapper package.
9053
9054 if Scope (Subp) /= Standard_Standard
9055 and then
9056 Need_Subprogram_Instance_Body
9057 (Next (Unit_Declaration_Node
9058 (Scope (Alias (Subp)))), Subp)
9059 then
9060 null;
9061 end if;
9062
9063 -- Inline is a program unit pragma (RM 10.1.5) and cannot
9064 -- appear in a formal part to apply to a formal subprogram.
9065 -- Do not apply check within an instance or a formal package
9066 -- the test will have been applied to the original generic.
9067
9068 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
9069 and then List_Containing (Decl) = List_Containing (N)
9070 and then not In_Instance
9071 then
9072 Error_Msg_N
9073 ("Inline cannot apply to a formal subprogram", N);
9074
9075 -- If Subp is a renaming, it is the renamed entity that
9076 -- will appear in any call, and be inlined. However, for
9077 -- ASIS uses it is convenient to indicate that the renaming
9078 -- itself is an inlined subprogram, so that some gnatcheck
9079 -- rules can be applied in the absence of expansion.
9080
9081 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
9082 Set_Inline_Flags (Subp);
9083 end if;
9084 end if;
9085
9086 Applies := True;
9087
9088 -- For a generic subprogram set flag as well, for use at the point
9089 -- of instantiation, to determine whether the body should be
9090 -- generated.
9091
9092 elsif Is_Generic_Subprogram (Subp) then
9093 Set_Inline_Flags (Subp);
9094 Applies := True;
9095
9096 -- Literals are by definition inlined
9097
9098 elsif Kind = E_Enumeration_Literal then
9099 null;
9100
9101 -- Anything else is an error
9102
9103 else
9104 Error_Pragma_Arg
9105 ("expect subprogram name for pragma%", Assoc);
9106 end if;
9107 end Make_Inline;
9108
9109 ----------------------
9110 -- Set_Inline_Flags --
9111 ----------------------
9112
9113 procedure Set_Inline_Flags (Subp : Entity_Id) is
9114 begin
9115 -- First set the Has_Pragma_XXX flags and issue the appropriate
9116 -- errors and warnings for suspicious combinations.
9117
9118 if Prag_Id = Pragma_No_Inline then
9119 if Has_Pragma_Inline_Always (Subp) then
9120 Error_Msg_N
9121 ("Inline_Always and No_Inline are mutually exclusive", N);
9122 elsif Has_Pragma_Inline (Subp) then
9123 Error_Msg_NE
9124 ("Inline and No_Inline both specified for& ??",
9125 N, Entity (Subp_Id));
9126 end if;
9127
9128 Set_Has_Pragma_No_Inline (Subp);
9129 else
9130 if Prag_Id = Pragma_Inline_Always then
9131 if Has_Pragma_No_Inline (Subp) then
9132 Error_Msg_N
9133 ("Inline_Always and No_Inline are mutually exclusive",
9134 N);
9135 end if;
9136
9137 Set_Has_Pragma_Inline_Always (Subp);
9138 else
9139 if Has_Pragma_No_Inline (Subp) then
9140 Error_Msg_NE
9141 ("Inline and No_Inline both specified for& ??",
9142 N, Entity (Subp_Id));
9143 end if;
9144 end if;
9145
9146 Set_Has_Pragma_Inline (Subp);
9147 end if;
9148
9149 -- Then adjust the Is_Inlined flag. It can never be set if the
9150 -- subprogram is subject to pragma No_Inline.
9151
9152 case Status is
9153 when Suppressed =>
9154 Set_Is_Inlined (Subp, False);
9155
9156 when Disabled =>
9157 null;
9158
9159 when Enabled =>
9160 if not Has_Pragma_No_Inline (Subp) then
9161 Set_Is_Inlined (Subp, True);
9162 end if;
9163 end case;
9164
9165 -- A pragma that applies to a Ghost entity becomes Ghost for the
9166 -- purposes of legality checks and removal of ignored Ghost code.
9167
9168 Mark_Ghost_Pragma (N, Subp);
9169
9170 -- Capture the entity of the first Ghost subprogram being
9171 -- processed for error detection purposes.
9172
9173 if Is_Ghost_Entity (Subp) then
9174 if No (Ghost_Id) then
9175 Ghost_Id := Subp;
9176 end if;
9177
9178 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
9179 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
9180
9181 elsif Present (Ghost_Id) and then not Ghost_Error_Posted then
9182 Ghost_Error_Posted := True;
9183
9184 Error_Msg_Name_1 := Pname;
9185 Error_Msg_N
9186 ("pragma % cannot mention ghost and non-ghost subprograms",
9187 N);
9188
9189 Error_Msg_Sloc := Sloc (Ghost_Id);
9190 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
9191
9192 Error_Msg_Sloc := Sloc (Subp);
9193 Error_Msg_NE ("\& # declared as non-ghost", N, Subp);
9194 end if;
9195 end Set_Inline_Flags;
9196
9197 -- Start of processing for Process_Inline
9198
9199 begin
9200 Check_No_Identifiers;
9201 Check_At_Least_N_Arguments (1);
9202
9203 if Status = Enabled then
9204 Inline_Processing_Required := True;
9205 end if;
9206
9207 Assoc := Arg1;
9208 while Present (Assoc) loop
9209 Subp_Id := Get_Pragma_Arg (Assoc);
9210 Analyze (Subp_Id);
9211 Applies := False;
9212
9213 if Is_Entity_Name (Subp_Id) then
9214 Subp := Entity (Subp_Id);
9215
9216 if Subp = Any_Id then
9217
9218 -- If previous error, avoid cascaded errors
9219
9220 Check_Error_Detected;
9221 Applies := True;
9222
9223 else
9224 Make_Inline (Subp);
9225
9226 -- For the pragma case, climb homonym chain. This is
9227 -- what implements allowing the pragma in the renaming
9228 -- case, with the result applying to the ancestors, and
9229 -- also allows Inline to apply to all previous homonyms.
9230
9231 if not From_Aspect_Specification (N) then
9232 while Present (Homonym (Subp))
9233 and then Scope (Homonym (Subp)) = Current_Scope
9234 loop
9235 Make_Inline (Homonym (Subp));
9236 Subp := Homonym (Subp);
9237 end loop;
9238 end if;
9239 end if;
9240 end if;
9241
9242 if not Applies then
9243 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
9244 end if;
9245
9246 Next (Assoc);
9247 end loop;
9248
9249 -- If the context is a package declaration, the pragma indicates
9250 -- that inlining will require the presence of the corresponding
9251 -- body. (this may be further refined).
9252
9253 if not In_Instance
9254 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
9255 N_Package_Declaration
9256 then
9257 Set_Body_Needed_For_Inlining (Cunit_Entity (Current_Sem_Unit));
9258 end if;
9259 end Process_Inline;
9260
9261 ----------------------------
9262 -- Process_Interface_Name --
9263 ----------------------------
9264
9265 procedure Process_Interface_Name
9266 (Subprogram_Def : Entity_Id;
9267 Ext_Arg : Node_Id;
9268 Link_Arg : Node_Id;
9269 Prag : Node_Id)
9270 is
9271 Ext_Nam : Node_Id;
9272 Link_Nam : Node_Id;
9273 String_Val : String_Id;
9274
9275 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
9276 -- SN is a string literal node for an interface name. This routine
9277 -- performs some minimal checks that the name is reasonable. In
9278 -- particular that no spaces or other obviously incorrect characters
9279 -- appear. This is only a warning, since any characters are allowed.
9280
9281 ----------------------------------
9282 -- Check_Form_Of_Interface_Name --
9283 ----------------------------------
9284
9285 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
9286 S : constant String_Id := Strval (Expr_Value_S (SN));
9287 SL : constant Nat := String_Length (S);
9288 C : Char_Code;
9289
9290 begin
9291 if SL = 0 then
9292 Error_Msg_N ("interface name cannot be null string", SN);
9293 end if;
9294
9295 for J in 1 .. SL loop
9296 C := Get_String_Char (S, J);
9297
9298 -- Look for dubious character and issue unconditional warning.
9299 -- Definitely dubious if not in character range.
9300
9301 if not In_Character_Range (C)
9302
9303 -- Commas, spaces and (back)slashes are dubious
9304
9305 or else Get_Character (C) = ','
9306 or else Get_Character (C) = '\'
9307 or else Get_Character (C) = ' '
9308 or else Get_Character (C) = '/'
9309 then
9310 Error_Msg
9311 ("??interface name contains illegal character",
9312 Sloc (SN) + Source_Ptr (J));
9313 end if;
9314 end loop;
9315 end Check_Form_Of_Interface_Name;
9316
9317 -- Start of processing for Process_Interface_Name
9318
9319 begin
9320 -- If we are looking at a pragma that comes from an aspect then it
9321 -- needs to have its corresponding aspect argument expressions
9322 -- analyzed in addition to the generated pragma so that aspects
9323 -- within generic units get properly resolved.
9324
9325 if Present (Prag) and then From_Aspect_Specification (Prag) then
9326 declare
9327 Asp : constant Node_Id := Corresponding_Aspect (Prag);
9328 Dummy_1 : Node_Id;
9329 Dummy_2 : Node_Id;
9330 Dummy_3 : Node_Id;
9331 EN : Node_Id;
9332 LN : Node_Id;
9333
9334 begin
9335 -- Obtain all interfacing aspects used to construct the pragma
9336
9337 Get_Interfacing_Aspects
9338 (Asp, Dummy_1, EN, Dummy_2, Dummy_3, LN);
9339
9340 -- Analyze the expression of aspect External_Name
9341
9342 if Present (EN) then
9343 Analyze (Expression (EN));
9344 end if;
9345
9346 -- Analyze the expressio of aspect Link_Name
9347
9348 if Present (LN) then
9349 Analyze (Expression (LN));
9350 end if;
9351 end;
9352 end if;
9353
9354 if No (Link_Arg) then
9355 if No (Ext_Arg) then
9356 return;
9357
9358 elsif Chars (Ext_Arg) = Name_Link_Name then
9359 Ext_Nam := Empty;
9360 Link_Nam := Expression (Ext_Arg);
9361
9362 else
9363 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
9364 Ext_Nam := Expression (Ext_Arg);
9365 Link_Nam := Empty;
9366 end if;
9367
9368 else
9369 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
9370 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
9371 Ext_Nam := Expression (Ext_Arg);
9372 Link_Nam := Expression (Link_Arg);
9373 end if;
9374
9375 -- Check expressions for external name and link name are static
9376
9377 if Present (Ext_Nam) then
9378 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
9379 Check_Form_Of_Interface_Name (Ext_Nam);
9380
9381 -- Verify that external name is not the name of a local entity,
9382 -- which would hide the imported one and could lead to run-time
9383 -- surprises. The problem can only arise for entities declared in
9384 -- a package body (otherwise the external name is fully qualified
9385 -- and will not conflict).
9386
9387 declare
9388 Nam : Name_Id;
9389 E : Entity_Id;
9390 Par : Node_Id;
9391
9392 begin
9393 if Prag_Id = Pragma_Import then
9394 Nam := String_To_Name (Strval (Expr_Value_S (Ext_Nam)));
9395 E := Entity_Id (Get_Name_Table_Int (Nam));
9396
9397 if Nam /= Chars (Subprogram_Def)
9398 and then Present (E)
9399 and then not Is_Overloadable (E)
9400 and then Is_Immediately_Visible (E)
9401 and then not Is_Imported (E)
9402 and then Ekind (Scope (E)) = E_Package
9403 then
9404 Par := Parent (E);
9405 while Present (Par) loop
9406 if Nkind (Par) = N_Package_Body then
9407 Error_Msg_Sloc := Sloc (E);
9408 Error_Msg_NE
9409 ("imported entity is hidden by & declared#",
9410 Ext_Arg, E);
9411 exit;
9412 end if;
9413
9414 Par := Parent (Par);
9415 end loop;
9416 end if;
9417 end if;
9418 end;
9419 end if;
9420
9421 if Present (Link_Nam) then
9422 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
9423 Check_Form_Of_Interface_Name (Link_Nam);
9424 end if;
9425
9426 -- If there is no link name, just set the external name
9427
9428 if No (Link_Nam) then
9429 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
9430
9431 -- For the Link_Name case, the given literal is preceded by an
9432 -- asterisk, which indicates to GCC that the given name should be
9433 -- taken literally, and in particular that no prepending of
9434 -- underlines should occur, even in systems where this is the
9435 -- normal default.
9436
9437 else
9438 Start_String;
9439 Store_String_Char (Get_Char_Code ('*'));
9440 String_Val := Strval (Expr_Value_S (Link_Nam));
9441 Store_String_Chars (String_Val);
9442 Link_Nam :=
9443 Make_String_Literal (Sloc (Link_Nam),
9444 Strval => End_String);
9445 end if;
9446
9447 -- Set the interface name. If the entity is a generic instance, use
9448 -- its alias, which is the callable entity.
9449
9450 if Is_Generic_Instance (Subprogram_Def) then
9451 Set_Encoded_Interface_Name
9452 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
9453 else
9454 Set_Encoded_Interface_Name
9455 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
9456 end if;
9457
9458 Check_Duplicated_Export_Name (Link_Nam);
9459 end Process_Interface_Name;
9460
9461 -----------------------------------------
9462 -- Process_Interrupt_Or_Attach_Handler --
9463 -----------------------------------------
9464
9465 procedure Process_Interrupt_Or_Attach_Handler is
9466 Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
9467 Prot_Typ : constant Entity_Id := Scope (Handler);
9468
9469 begin
9470 -- A pragma that applies to a Ghost entity becomes Ghost for the
9471 -- purposes of legality checks and removal of ignored Ghost code.
9472
9473 Mark_Ghost_Pragma (N, Handler);
9474 Set_Is_Interrupt_Handler (Handler);
9475
9476 pragma Assert (Ekind (Prot_Typ) = E_Protected_Type);
9477
9478 Record_Rep_Item (Prot_Typ, N);
9479
9480 -- Chain the pragma on the contract for completeness
9481
9482 Add_Contract_Item (N, Handler);
9483 end Process_Interrupt_Or_Attach_Handler;
9484
9485 --------------------------------------------------
9486 -- Process_Restrictions_Or_Restriction_Warnings --
9487 --------------------------------------------------
9488
9489 -- Note: some of the simple identifier cases were handled in par-prag,
9490 -- but it is harmless (and more straightforward) to simply handle all
9491 -- cases here, even if it means we repeat a bit of work in some cases.
9492
9493 procedure Process_Restrictions_Or_Restriction_Warnings
9494 (Warn : Boolean)
9495 is
9496 Arg : Node_Id;
9497 R_Id : Restriction_Id;
9498 Id : Name_Id;
9499 Expr : Node_Id;
9500 Val : Uint;
9501
9502 begin
9503 -- Ignore all Restrictions pragmas in CodePeer mode
9504
9505 if CodePeer_Mode then
9506 return;
9507 end if;
9508
9509 Check_Ada_83_Warning;
9510 Check_At_Least_N_Arguments (1);
9511 Check_Valid_Configuration_Pragma;
9512
9513 Arg := Arg1;
9514 while Present (Arg) loop
9515 Id := Chars (Arg);
9516 Expr := Get_Pragma_Arg (Arg);
9517
9518 -- Case of no restriction identifier present
9519
9520 if Id = No_Name then
9521 if Nkind (Expr) /= N_Identifier then
9522 Error_Pragma_Arg
9523 ("invalid form for restriction", Arg);
9524 end if;
9525
9526 R_Id :=
9527 Get_Restriction_Id
9528 (Process_Restriction_Synonyms (Expr));
9529
9530 if R_Id not in All_Boolean_Restrictions then
9531 Error_Msg_Name_1 := Pname;
9532 Error_Msg_N
9533 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
9534
9535 -- Check for possible misspelling
9536
9537 for J in Restriction_Id loop
9538 declare
9539 Rnm : constant String := Restriction_Id'Image (J);
9540
9541 begin
9542 Name_Buffer (1 .. Rnm'Length) := Rnm;
9543 Name_Len := Rnm'Length;
9544 Set_Casing (All_Lower_Case);
9545
9546 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
9547 Set_Casing
9548 (Identifier_Casing
9549 (Source_Index (Current_Sem_Unit)));
9550 Error_Msg_String (1 .. Rnm'Length) :=
9551 Name_Buffer (1 .. Name_Len);
9552 Error_Msg_Strlen := Rnm'Length;
9553 Error_Msg_N -- CODEFIX
9554 ("\possible misspelling of ""~""",
9555 Get_Pragma_Arg (Arg));
9556 exit;
9557 end if;
9558 end;
9559 end loop;
9560
9561 raise Pragma_Exit;
9562 end if;
9563
9564 if Implementation_Restriction (R_Id) then
9565 Check_Restriction (No_Implementation_Restrictions, Arg);
9566 end if;
9567
9568 -- Special processing for No_Elaboration_Code restriction
9569
9570 if R_Id = No_Elaboration_Code then
9571
9572 -- Restriction is only recognized within a configuration
9573 -- pragma file, or within a unit of the main extended
9574 -- program. Note: the test for Main_Unit is needed to
9575 -- properly include the case of configuration pragma files.
9576
9577 if not (Current_Sem_Unit = Main_Unit
9578 or else In_Extended_Main_Source_Unit (N))
9579 then
9580 return;
9581
9582 -- Don't allow in a subunit unless already specified in
9583 -- body or spec.
9584
9585 elsif Nkind (Parent (N)) = N_Compilation_Unit
9586 and then Nkind (Unit (Parent (N))) = N_Subunit
9587 and then not Restriction_Active (No_Elaboration_Code)
9588 then
9589 Error_Msg_N
9590 ("invalid specification of ""No_Elaboration_Code""",
9591 N);
9592 Error_Msg_N
9593 ("\restriction cannot be specified in a subunit", N);
9594 Error_Msg_N
9595 ("\unless also specified in body or spec", N);
9596 return;
9597
9598 -- If we accept a No_Elaboration_Code restriction, then it
9599 -- needs to be added to the configuration restriction set so
9600 -- that we get proper application to other units in the main
9601 -- extended source as required.
9602
9603 else
9604 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
9605 end if;
9606 end if;
9607
9608 -- If this is a warning, then set the warning unless we already
9609 -- have a real restriction active (we never want a warning to
9610 -- override a real restriction).
9611
9612 if Warn then
9613 if not Restriction_Active (R_Id) then
9614 Set_Restriction (R_Id, N);
9615 Restriction_Warnings (R_Id) := True;
9616 end if;
9617
9618 -- If real restriction case, then set it and make sure that the
9619 -- restriction warning flag is off, since a real restriction
9620 -- always overrides a warning.
9621
9622 else
9623 Set_Restriction (R_Id, N);
9624 Restriction_Warnings (R_Id) := False;
9625 end if;
9626
9627 -- Check for obsolescent restrictions in Ada 2005 mode
9628
9629 if not Warn
9630 and then Ada_Version >= Ada_2005
9631 and then (R_Id = No_Asynchronous_Control
9632 or else
9633 R_Id = No_Unchecked_Deallocation
9634 or else
9635 R_Id = No_Unchecked_Conversion)
9636 then
9637 Check_Restriction (No_Obsolescent_Features, N);
9638 end if;
9639
9640 -- A very special case that must be processed here: pragma
9641 -- Restrictions (No_Exceptions) turns off all run-time
9642 -- checking. This is a bit dubious in terms of the formal
9643 -- language definition, but it is what is intended by RM
9644 -- H.4(12). Restriction_Warnings never affects generated code
9645 -- so this is done only in the real restriction case.
9646
9647 -- Atomic_Synchronization is not a real check, so it is not
9648 -- affected by this processing).
9649
9650 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
9651 -- run-time checks in CodePeer and GNATprove modes: we want to
9652 -- generate checks for analysis purposes, as set respectively
9653 -- by -gnatC and -gnatd.F
9654
9655 if not Warn
9656 and then not (CodePeer_Mode or GNATprove_Mode)
9657 and then R_Id = No_Exceptions
9658 then
9659 for J in Scope_Suppress.Suppress'Range loop
9660 if J /= Atomic_Synchronization then
9661 Scope_Suppress.Suppress (J) := True;
9662 end if;
9663 end loop;
9664 end if;
9665
9666 -- Case of No_Dependence => unit-name. Note that the parser
9667 -- already made the necessary entry in the No_Dependence table.
9668
9669 elsif Id = Name_No_Dependence then
9670 if not OK_No_Dependence_Unit_Name (Expr) then
9671 raise Pragma_Exit;
9672 end if;
9673
9674 -- Case of No_Specification_Of_Aspect => aspect-identifier
9675
9676 elsif Id = Name_No_Specification_Of_Aspect then
9677 declare
9678 A_Id : Aspect_Id;
9679
9680 begin
9681 if Nkind (Expr) /= N_Identifier then
9682 A_Id := No_Aspect;
9683 else
9684 A_Id := Get_Aspect_Id (Chars (Expr));
9685 end if;
9686
9687 if A_Id = No_Aspect then
9688 Error_Pragma_Arg ("invalid restriction name", Arg);
9689 else
9690 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
9691 end if;
9692 end;
9693
9694 -- Case of No_Use_Of_Attribute => attribute-identifier
9695
9696 elsif Id = Name_No_Use_Of_Attribute then
9697 if Nkind (Expr) /= N_Identifier
9698 or else not Is_Attribute_Name (Chars (Expr))
9699 then
9700 Error_Msg_N ("unknown attribute name??", Expr);
9701
9702 else
9703 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
9704 end if;
9705
9706 -- Case of No_Use_Of_Entity => fully-qualified-name
9707
9708 elsif Id = Name_No_Use_Of_Entity then
9709
9710 -- Restriction is only recognized within a configuration
9711 -- pragma file, or within a unit of the main extended
9712 -- program. Note: the test for Main_Unit is needed to
9713 -- properly include the case of configuration pragma files.
9714
9715 if Current_Sem_Unit = Main_Unit
9716 or else In_Extended_Main_Source_Unit (N)
9717 then
9718 if not OK_No_Dependence_Unit_Name (Expr) then
9719 Error_Msg_N ("wrong form for entity name", Expr);
9720 else
9721 Set_Restriction_No_Use_Of_Entity
9722 (Expr, Warn, No_Profile);
9723 end if;
9724 end if;
9725
9726 -- Case of No_Use_Of_Pragma => pragma-identifier
9727
9728 elsif Id = Name_No_Use_Of_Pragma then
9729 if Nkind (Expr) /= N_Identifier
9730 or else not Is_Pragma_Name (Chars (Expr))
9731 then
9732 Error_Msg_N ("unknown pragma name??", Expr);
9733 else
9734 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
9735 end if;
9736
9737 -- All other cases of restriction identifier present
9738
9739 else
9740 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
9741 Analyze_And_Resolve (Expr, Any_Integer);
9742
9743 if R_Id not in All_Parameter_Restrictions then
9744 Error_Pragma_Arg
9745 ("invalid restriction parameter identifier", Arg);
9746
9747 elsif not Is_OK_Static_Expression (Expr) then
9748 Flag_Non_Static_Expr
9749 ("value must be static expression!", Expr);
9750 raise Pragma_Exit;
9751
9752 elsif not Is_Integer_Type (Etype (Expr))
9753 or else Expr_Value (Expr) < 0
9754 then
9755 Error_Pragma_Arg
9756 ("value must be non-negative integer", Arg);
9757 end if;
9758
9759 -- Restriction pragma is active
9760
9761 Val := Expr_Value (Expr);
9762
9763 if not UI_Is_In_Int_Range (Val) then
9764 Error_Pragma_Arg
9765 ("pragma ignored, value too large??", Arg);
9766 end if;
9767
9768 -- Warning case. If the real restriction is active, then we
9769 -- ignore the request, since warning never overrides a real
9770 -- restriction. Otherwise we set the proper warning. Note that
9771 -- this circuit sets the warning again if it is already set,
9772 -- which is what we want, since the constant may have changed.
9773
9774 if Warn then
9775 if not Restriction_Active (R_Id) then
9776 Set_Restriction
9777 (R_Id, N, Integer (UI_To_Int (Val)));
9778 Restriction_Warnings (R_Id) := True;
9779 end if;
9780
9781 -- Real restriction case, set restriction and make sure warning
9782 -- flag is off since real restriction always overrides warning.
9783
9784 else
9785 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
9786 Restriction_Warnings (R_Id) := False;
9787 end if;
9788 end if;
9789
9790 Next (Arg);
9791 end loop;
9792 end Process_Restrictions_Or_Restriction_Warnings;
9793
9794 ---------------------------------
9795 -- Process_Suppress_Unsuppress --
9796 ---------------------------------
9797
9798 -- Note: this procedure makes entries in the check suppress data
9799 -- structures managed by Sem. See spec of package Sem for full
9800 -- details on how we handle recording of check suppression.
9801
9802 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
9803 C : Check_Id;
9804 E : Entity_Id;
9805 E_Id : Node_Id;
9806
9807 In_Package_Spec : constant Boolean :=
9808 Is_Package_Or_Generic_Package (Current_Scope)
9809 and then not In_Package_Body (Current_Scope);
9810
9811 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
9812 -- Used to suppress a single check on the given entity
9813
9814 --------------------------------
9815 -- Suppress_Unsuppress_Echeck --
9816 --------------------------------
9817
9818 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
9819 begin
9820 -- Check for error of trying to set atomic synchronization for
9821 -- a non-atomic variable.
9822
9823 if C = Atomic_Synchronization
9824 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
9825 then
9826 Error_Msg_N
9827 ("pragma & requires atomic type or variable",
9828 Pragma_Identifier (Original_Node (N)));
9829 end if;
9830
9831 Set_Checks_May_Be_Suppressed (E);
9832
9833 if In_Package_Spec then
9834 Push_Global_Suppress_Stack_Entry
9835 (Entity => E,
9836 Check => C,
9837 Suppress => Suppress_Case);
9838 else
9839 Push_Local_Suppress_Stack_Entry
9840 (Entity => E,
9841 Check => C,
9842 Suppress => Suppress_Case);
9843 end if;
9844
9845 -- If this is a first subtype, and the base type is distinct,
9846 -- then also set the suppress flags on the base type.
9847
9848 if Is_First_Subtype (E) and then Etype (E) /= E then
9849 Suppress_Unsuppress_Echeck (Etype (E), C);
9850 end if;
9851 end Suppress_Unsuppress_Echeck;
9852
9853 -- Start of processing for Process_Suppress_Unsuppress
9854
9855 begin
9856 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
9857 -- on user code: we want to generate checks for analysis purposes, as
9858 -- set respectively by -gnatC and -gnatd.F
9859
9860 if Comes_From_Source (N)
9861 and then (CodePeer_Mode or GNATprove_Mode)
9862 then
9863 return;
9864 end if;
9865
9866 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
9867 -- declarative part or a package spec (RM 11.5(5)).
9868
9869 if not Is_Configuration_Pragma then
9870 Check_Is_In_Decl_Part_Or_Package_Spec;
9871 end if;
9872
9873 Check_At_Least_N_Arguments (1);
9874 Check_At_Most_N_Arguments (2);
9875 Check_No_Identifier (Arg1);
9876 Check_Arg_Is_Identifier (Arg1);
9877
9878 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
9879
9880 if C = No_Check_Id then
9881 Error_Pragma_Arg
9882 ("argument of pragma% is not valid check name", Arg1);
9883 end if;
9884
9885 -- Warn that suppress of Elaboration_Check has no effect in SPARK
9886
9887 if C = Elaboration_Check and then SPARK_Mode = On then
9888 Error_Pragma_Arg
9889 ("Suppress of Elaboration_Check ignored in SPARK??",
9890 "\elaboration checking rules are statically enforced "
9891 & "(SPARK RM 7.7)", Arg1);
9892 end if;
9893
9894 -- One-argument case
9895
9896 if Arg_Count = 1 then
9897
9898 -- Make an entry in the local scope suppress table. This is the
9899 -- table that directly shows the current value of the scope
9900 -- suppress check for any check id value.
9901
9902 if C = All_Checks then
9903
9904 -- For All_Checks, we set all specific predefined checks with
9905 -- the exception of Elaboration_Check, which is handled
9906 -- specially because of not wanting All_Checks to have the
9907 -- effect of deactivating static elaboration order processing.
9908 -- Atomic_Synchronization is also not affected, since this is
9909 -- not a real check.
9910
9911 for J in Scope_Suppress.Suppress'Range loop
9912 if J /= Elaboration_Check
9913 and then
9914 J /= Atomic_Synchronization
9915 then
9916 Scope_Suppress.Suppress (J) := Suppress_Case;
9917 end if;
9918 end loop;
9919
9920 -- If not All_Checks, and predefined check, then set appropriate
9921 -- scope entry. Note that we will set Elaboration_Check if this
9922 -- is explicitly specified. Atomic_Synchronization is allowed
9923 -- only if internally generated and entity is atomic.
9924
9925 elsif C in Predefined_Check_Id
9926 and then (not Comes_From_Source (N)
9927 or else C /= Atomic_Synchronization)
9928 then
9929 Scope_Suppress.Suppress (C) := Suppress_Case;
9930 end if;
9931
9932 -- Also make an entry in the Local_Entity_Suppress table
9933
9934 Push_Local_Suppress_Stack_Entry
9935 (Entity => Empty,
9936 Check => C,
9937 Suppress => Suppress_Case);
9938
9939 -- Case of two arguments present, where the check is suppressed for
9940 -- a specified entity (given as the second argument of the pragma)
9941
9942 else
9943 -- This is obsolescent in Ada 2005 mode
9944
9945 if Ada_Version >= Ada_2005 then
9946 Check_Restriction (No_Obsolescent_Features, Arg2);
9947 end if;
9948
9949 Check_Optional_Identifier (Arg2, Name_On);
9950 E_Id := Get_Pragma_Arg (Arg2);
9951 Analyze (E_Id);
9952
9953 if not Is_Entity_Name (E_Id) then
9954 Error_Pragma_Arg
9955 ("second argument of pragma% must be entity name", Arg2);
9956 end if;
9957
9958 E := Entity (E_Id);
9959
9960 if E = Any_Id then
9961 return;
9962 end if;
9963
9964 -- A pragma that applies to a Ghost entity becomes Ghost for the
9965 -- purposes of legality checks and removal of ignored Ghost code.
9966
9967 Mark_Ghost_Pragma (N, E);
9968
9969 -- Enforce RM 11.5(7) which requires that for a pragma that
9970 -- appears within a package spec, the named entity must be
9971 -- within the package spec. We allow the package name itself
9972 -- to be mentioned since that makes sense, although it is not
9973 -- strictly allowed by 11.5(7).
9974
9975 if In_Package_Spec
9976 and then E /= Current_Scope
9977 and then Scope (E) /= Current_Scope
9978 then
9979 Error_Pragma_Arg
9980 ("entity in pragma% is not in package spec (RM 11.5(7))",
9981 Arg2);
9982 end if;
9983
9984 -- Loop through homonyms. As noted below, in the case of a package
9985 -- spec, only homonyms within the package spec are considered.
9986
9987 loop
9988 Suppress_Unsuppress_Echeck (E, C);
9989
9990 if Is_Generic_Instance (E)
9991 and then Is_Subprogram (E)
9992 and then Present (Alias (E))
9993 then
9994 Suppress_Unsuppress_Echeck (Alias (E), C);
9995 end if;
9996
9997 -- Move to next homonym if not aspect spec case
9998
9999 exit when From_Aspect_Specification (N);
10000 E := Homonym (E);
10001 exit when No (E);
10002
10003 -- If we are within a package specification, the pragma only
10004 -- applies to homonyms in the same scope.
10005
10006 exit when In_Package_Spec
10007 and then Scope (E) /= Current_Scope;
10008 end loop;
10009 end if;
10010 end Process_Suppress_Unsuppress;
10011
10012 -------------------------------
10013 -- Record_Independence_Check --
10014 -------------------------------
10015
10016 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
10017 begin
10018 -- For GCC back ends the validation is done a priori
10019
10020 if not AAMP_On_Target then
10021 return;
10022 end if;
10023
10024 Independence_Checks.Append ((N, E));
10025 end Record_Independence_Check;
10026
10027 ------------------
10028 -- Set_Exported --
10029 ------------------
10030
10031 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
10032 begin
10033 if Is_Imported (E) then
10034 Error_Pragma_Arg
10035 ("cannot export entity& that was previously imported", Arg);
10036
10037 elsif Present (Address_Clause (E))
10038 and then not Relaxed_RM_Semantics
10039 then
10040 Error_Pragma_Arg
10041 ("cannot export entity& that has an address clause", Arg);
10042 end if;
10043
10044 Set_Is_Exported (E);
10045
10046 -- Generate a reference for entity explicitly, because the
10047 -- identifier may be overloaded and name resolution will not
10048 -- generate one.
10049
10050 Generate_Reference (E, Arg);
10051
10052 -- Deal with exporting non-library level entity
10053
10054 if not Is_Library_Level_Entity (E) then
10055
10056 -- Not allowed at all for subprograms
10057
10058 if Is_Subprogram (E) then
10059 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
10060
10061 -- Otherwise set public and statically allocated
10062
10063 else
10064 Set_Is_Public (E);
10065 Set_Is_Statically_Allocated (E);
10066
10067 -- Warn if the corresponding W flag is set
10068
10069 if Warn_On_Export_Import
10070
10071 -- Only do this for something that was in the source. Not
10072 -- clear if this can be False now (there used for sure to be
10073 -- cases on some systems where it was False), but anyway the
10074 -- test is harmless if not needed, so it is retained.
10075
10076 and then Comes_From_Source (Arg)
10077 then
10078 Error_Msg_NE
10079 ("?x?& has been made static as a result of Export",
10080 Arg, E);
10081 Error_Msg_N
10082 ("\?x?this usage is non-standard and non-portable",
10083 Arg);
10084 end if;
10085 end if;
10086 end if;
10087
10088 if Warn_On_Export_Import and then Is_Type (E) then
10089 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
10090 end if;
10091
10092 if Warn_On_Export_Import and Inside_A_Generic then
10093 Error_Msg_NE
10094 ("all instances of& will have the same external name?x?",
10095 Arg, E);
10096 end if;
10097 end Set_Exported;
10098
10099 ----------------------------------------------
10100 -- Set_Extended_Import_Export_External_Name --
10101 ----------------------------------------------
10102
10103 procedure Set_Extended_Import_Export_External_Name
10104 (Internal_Ent : Entity_Id;
10105 Arg_External : Node_Id)
10106 is
10107 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
10108 New_Name : Node_Id;
10109
10110 begin
10111 if No (Arg_External) then
10112 return;
10113 end if;
10114
10115 Check_Arg_Is_External_Name (Arg_External);
10116
10117 if Nkind (Arg_External) = N_String_Literal then
10118 if String_Length (Strval (Arg_External)) = 0 then
10119 return;
10120 else
10121 New_Name := Adjust_External_Name_Case (Arg_External);
10122 end if;
10123
10124 elsif Nkind (Arg_External) = N_Identifier then
10125 New_Name := Get_Default_External_Name (Arg_External);
10126
10127 -- Check_Arg_Is_External_Name should let through only identifiers and
10128 -- string literals or static string expressions (which are folded to
10129 -- string literals).
10130
10131 else
10132 raise Program_Error;
10133 end if;
10134
10135 -- If we already have an external name set (by a prior normal Import
10136 -- or Export pragma), then the external names must match
10137
10138 if Present (Interface_Name (Internal_Ent)) then
10139
10140 -- Ignore mismatching names in CodePeer mode, to support some
10141 -- old compilers which would export the same procedure under
10142 -- different names, e.g:
10143 -- procedure P;
10144 -- pragma Export_Procedure (P, "a");
10145 -- pragma Export_Procedure (P, "b");
10146
10147 if CodePeer_Mode then
10148 return;
10149 end if;
10150
10151 Check_Matching_Internal_Names : declare
10152 S1 : constant String_Id := Strval (Old_Name);
10153 S2 : constant String_Id := Strval (New_Name);
10154
10155 procedure Mismatch;
10156 pragma No_Return (Mismatch);
10157 -- Called if names do not match
10158
10159 --------------
10160 -- Mismatch --
10161 --------------
10162
10163 procedure Mismatch is
10164 begin
10165 Error_Msg_Sloc := Sloc (Old_Name);
10166 Error_Pragma_Arg
10167 ("external name does not match that given #",
10168 Arg_External);
10169 end Mismatch;
10170
10171 -- Start of processing for Check_Matching_Internal_Names
10172
10173 begin
10174 if String_Length (S1) /= String_Length (S2) then
10175 Mismatch;
10176
10177 else
10178 for J in 1 .. String_Length (S1) loop
10179 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
10180 Mismatch;
10181 end if;
10182 end loop;
10183 end if;
10184 end Check_Matching_Internal_Names;
10185
10186 -- Otherwise set the given name
10187
10188 else
10189 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
10190 Check_Duplicated_Export_Name (New_Name);
10191 end if;
10192 end Set_Extended_Import_Export_External_Name;
10193
10194 ------------------
10195 -- Set_Imported --
10196 ------------------
10197
10198 procedure Set_Imported (E : Entity_Id) is
10199 begin
10200 -- Error message if already imported or exported
10201
10202 if Is_Exported (E) or else Is_Imported (E) then
10203
10204 -- Error if being set Exported twice
10205
10206 if Is_Exported (E) then
10207 Error_Msg_NE ("entity& was previously exported", N, E);
10208
10209 -- Ignore error in CodePeer mode where we treat all imported
10210 -- subprograms as unknown.
10211
10212 elsif CodePeer_Mode then
10213 goto OK;
10214
10215 -- OK if Import/Interface case
10216
10217 elsif Import_Interface_Present (N) then
10218 goto OK;
10219
10220 -- Error if being set Imported twice
10221
10222 else
10223 Error_Msg_NE ("entity& was previously imported", N, E);
10224 end if;
10225
10226 Error_Msg_Name_1 := Pname;
10227 Error_Msg_N
10228 ("\(pragma% applies to all previous entities)", N);
10229
10230 Error_Msg_Sloc := Sloc (E);
10231 Error_Msg_NE ("\import not allowed for& declared#", N, E);
10232
10233 -- Here if not previously imported or exported, OK to import
10234
10235 else
10236 Set_Is_Imported (E);
10237
10238 -- For subprogram, set Import_Pragma field
10239
10240 if Is_Subprogram (E) then
10241 Set_Import_Pragma (E, N);
10242 end if;
10243
10244 -- If the entity is an object that is not at the library level,
10245 -- then it is statically allocated. We do not worry about objects
10246 -- with address clauses in this context since they are not really
10247 -- imported in the linker sense.
10248
10249 if Is_Object (E)
10250 and then not Is_Library_Level_Entity (E)
10251 and then No (Address_Clause (E))
10252 then
10253 Set_Is_Statically_Allocated (E);
10254 end if;
10255 end if;
10256
10257 <<OK>> null;
10258 end Set_Imported;
10259
10260 -------------------------
10261 -- Set_Mechanism_Value --
10262 -------------------------
10263
10264 -- Note: the mechanism name has not been analyzed (and cannot indeed be
10265 -- analyzed, since it is semantic nonsense), so we get it in the exact
10266 -- form created by the parser.
10267
10268 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
10269 procedure Bad_Mechanism;
10270 pragma No_Return (Bad_Mechanism);
10271 -- Signal bad mechanism name
10272
10273 -------------------------
10274 -- Bad_Mechanism_Value --
10275 -------------------------
10276
10277 procedure Bad_Mechanism is
10278 begin
10279 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
10280 end Bad_Mechanism;
10281
10282 -- Start of processing for Set_Mechanism_Value
10283
10284 begin
10285 if Mechanism (Ent) /= Default_Mechanism then
10286 Error_Msg_NE
10287 ("mechanism for & has already been set", Mech_Name, Ent);
10288 end if;
10289
10290 -- MECHANISM_NAME ::= value | reference
10291
10292 if Nkind (Mech_Name) = N_Identifier then
10293 if Chars (Mech_Name) = Name_Value then
10294 Set_Mechanism (Ent, By_Copy);
10295 return;
10296
10297 elsif Chars (Mech_Name) = Name_Reference then
10298 Set_Mechanism (Ent, By_Reference);
10299 return;
10300
10301 elsif Chars (Mech_Name) = Name_Copy then
10302 Error_Pragma_Arg
10303 ("bad mechanism name, Value assumed", Mech_Name);
10304
10305 else
10306 Bad_Mechanism;
10307 end if;
10308
10309 else
10310 Bad_Mechanism;
10311 end if;
10312 end Set_Mechanism_Value;
10313
10314 --------------------------
10315 -- Set_Rational_Profile --
10316 --------------------------
10317
10318 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
10319 -- extension to the semantics of renaming declarations.
10320
10321 procedure Set_Rational_Profile is
10322 begin
10323 Implicit_Packing := True;
10324 Overriding_Renamings := True;
10325 Use_VADS_Size := True;
10326 end Set_Rational_Profile;
10327
10328 ---------------------------
10329 -- Set_Ravenscar_Profile --
10330 ---------------------------
10331
10332 -- The tasks to be done here are
10333
10334 -- Set required policies
10335
10336 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
10337 -- (For Ravenscar and GNAT_Extended_Ravenscar profiles)
10338 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
10339 -- (For GNAT_Ravenscar_EDF profile)
10340 -- pragma Locking_Policy (Ceiling_Locking)
10341
10342 -- Set Detect_Blocking mode
10343
10344 -- Set required restrictions (see System.Rident for detailed list)
10345
10346 -- Set the No_Dependence rules
10347 -- No_Dependence => Ada.Asynchronous_Task_Control
10348 -- No_Dependence => Ada.Calendar
10349 -- No_Dependence => Ada.Execution_Time.Group_Budget
10350 -- No_Dependence => Ada.Execution_Time.Timers
10351 -- No_Dependence => Ada.Task_Attributes
10352 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
10353
10354 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is
10355 procedure Set_Error_Msg_To_Profile_Name;
10356 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
10357 -- profile.
10358
10359 -----------------------------------
10360 -- Set_Error_Msg_To_Profile_Name --
10361 -----------------------------------
10362
10363 procedure Set_Error_Msg_To_Profile_Name is
10364 Prof_Nam : constant Node_Id :=
10365 Get_Pragma_Arg
10366 (First (Pragma_Argument_Associations (N)));
10367
10368 begin
10369 Get_Name_String (Chars (Prof_Nam));
10370 Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam));
10371 Error_Msg_Strlen := Name_Len;
10372 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
10373 end Set_Error_Msg_To_Profile_Name;
10374
10375 -- Local variables
10376
10377 Nod : Node_Id;
10378 Pref : Node_Id;
10379 Pref_Id : Node_Id;
10380 Sel_Id : Node_Id;
10381
10382 Profile_Dispatching_Policy : Character;
10383
10384 -- Start of processing for Set_Ravenscar_Profile
10385
10386 begin
10387 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
10388
10389 if Profile = GNAT_Ravenscar_EDF then
10390 Profile_Dispatching_Policy := 'E';
10391
10392 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
10393
10394 else
10395 Profile_Dispatching_Policy := 'F';
10396 end if;
10397
10398 if Task_Dispatching_Policy /= ' '
10399 and then Task_Dispatching_Policy /= Profile_Dispatching_Policy
10400 then
10401 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10402 Set_Error_Msg_To_Profile_Name;
10403 Error_Pragma ("Profile (~) incompatible with policy#");
10404
10405 -- Set the FIFO_Within_Priorities policy, but always preserve
10406 -- System_Location since we like the error message with the run time
10407 -- name.
10408
10409 else
10410 Task_Dispatching_Policy := Profile_Dispatching_Policy;
10411
10412 if Task_Dispatching_Policy_Sloc /= System_Location then
10413 Task_Dispatching_Policy_Sloc := Loc;
10414 end if;
10415 end if;
10416
10417 -- pragma Locking_Policy (Ceiling_Locking)
10418
10419 if Locking_Policy /= ' '
10420 and then Locking_Policy /= 'C'
10421 then
10422 Error_Msg_Sloc := Locking_Policy_Sloc;
10423 Set_Error_Msg_To_Profile_Name;
10424 Error_Pragma ("Profile (~) incompatible with policy#");
10425
10426 -- Set the Ceiling_Locking policy, but preserve System_Location since
10427 -- we like the error message with the run time name.
10428
10429 else
10430 Locking_Policy := 'C';
10431
10432 if Locking_Policy_Sloc /= System_Location then
10433 Locking_Policy_Sloc := Loc;
10434 end if;
10435 end if;
10436
10437 -- pragma Detect_Blocking
10438
10439 Detect_Blocking := True;
10440
10441 -- Set the corresponding restrictions
10442
10443 Set_Profile_Restrictions
10444 (Profile, N, Warn => Treat_Restrictions_As_Warnings);
10445
10446 -- Set the No_Dependence restrictions
10447
10448 -- The following No_Dependence restrictions:
10449 -- No_Dependence => Ada.Asynchronous_Task_Control
10450 -- No_Dependence => Ada.Calendar
10451 -- No_Dependence => Ada.Task_Attributes
10452 -- are already set by previous call to Set_Profile_Restrictions.
10453
10454 -- Set the following restrictions which were added to Ada 2005:
10455 -- No_Dependence => Ada.Execution_Time.Group_Budget
10456 -- No_Dependence => Ada.Execution_Time.Timers
10457
10458 if Ada_Version >= Ada_2005 then
10459 Pref_Id := Make_Identifier (Loc, Name_Find ("ada"));
10460 Sel_Id := Make_Identifier (Loc, Name_Find ("execution_time"));
10461
10462 Pref :=
10463 Make_Selected_Component
10464 (Sloc => Loc,
10465 Prefix => Pref_Id,
10466 Selector_Name => Sel_Id);
10467
10468 Sel_Id := Make_Identifier (Loc, Name_Find ("group_budgets"));
10469
10470 Nod :=
10471 Make_Selected_Component
10472 (Sloc => Loc,
10473 Prefix => Pref,
10474 Selector_Name => Sel_Id);
10475
10476 Set_Restriction_No_Dependence
10477 (Unit => Nod,
10478 Warn => Treat_Restrictions_As_Warnings,
10479 Profile => Ravenscar);
10480
10481 Sel_Id := Make_Identifier (Loc, Name_Find ("timers"));
10482
10483 Nod :=
10484 Make_Selected_Component
10485 (Sloc => Loc,
10486 Prefix => Pref,
10487 Selector_Name => Sel_Id);
10488
10489 Set_Restriction_No_Dependence
10490 (Unit => Nod,
10491 Warn => Treat_Restrictions_As_Warnings,
10492 Profile => Ravenscar);
10493 end if;
10494
10495 -- Set the following restriction which was added to Ada 2012 (see
10496 -- AI-0171):
10497 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
10498
10499 if Ada_Version >= Ada_2012 then
10500 Pref_Id := Make_Identifier (Loc, Name_Find ("system"));
10501 Sel_Id := Make_Identifier (Loc, Name_Find ("multiprocessors"));
10502
10503 Pref :=
10504 Make_Selected_Component
10505 (Sloc => Loc,
10506 Prefix => Pref_Id,
10507 Selector_Name => Sel_Id);
10508
10509 Sel_Id := Make_Identifier (Loc, Name_Find ("dispatching_domains"));
10510
10511 Nod :=
10512 Make_Selected_Component
10513 (Sloc => Loc,
10514 Prefix => Pref,
10515 Selector_Name => Sel_Id);
10516
10517 Set_Restriction_No_Dependence
10518 (Unit => Nod,
10519 Warn => Treat_Restrictions_As_Warnings,
10520 Profile => Ravenscar);
10521 end if;
10522 end Set_Ravenscar_Profile;
10523
10524 -- Start of processing for Analyze_Pragma
10525
10526 begin
10527 -- The following code is a defense against recursion. Not clear that
10528 -- this can happen legitimately, but perhaps some error situations can
10529 -- cause it, and we did see this recursion during testing.
10530
10531 if Analyzed (N) then
10532 return;
10533 else
10534 Set_Analyzed (N);
10535 end if;
10536
10537 Check_Restriction_No_Use_Of_Pragma (N);
10538
10539 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
10540 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
10541
10542 if Should_Ignore_Pragma_Sem (N)
10543 or else (Prag_Id = Pragma_Default_Scalar_Storage_Order
10544 and then Ignore_Rep_Clauses)
10545 then
10546 return;
10547 end if;
10548
10549 -- Deal with unrecognized pragma
10550
10551 if not Is_Pragma_Name (Pname) then
10552 if Warn_On_Unrecognized_Pragma then
10553 Error_Msg_Name_1 := Pname;
10554 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
10555
10556 for PN in First_Pragma_Name .. Last_Pragma_Name loop
10557 if Is_Bad_Spelling_Of (Pname, PN) then
10558 Error_Msg_Name_1 := PN;
10559 Error_Msg_N -- CODEFIX
10560 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
10561 exit;
10562 end if;
10563 end loop;
10564 end if;
10565
10566 return;
10567 end if;
10568
10569 -- Here to start processing for recognized pragma
10570
10571 Pname := Original_Aspect_Pragma_Name (N);
10572
10573 -- Capture setting of Opt.Uneval_Old
10574
10575 case Opt.Uneval_Old is
10576 when 'A' =>
10577 Set_Uneval_Old_Accept (N);
10578
10579 when 'E' =>
10580 null;
10581
10582 when 'W' =>
10583 Set_Uneval_Old_Warn (N);
10584
10585 when others =>
10586 raise Program_Error;
10587 end case;
10588
10589 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
10590 -- is already set, indicating that we have already checked the policy
10591 -- at the right point. This happens for example in the case of a pragma
10592 -- that is derived from an Aspect.
10593
10594 if Is_Ignored (N) or else Is_Checked (N) then
10595 null;
10596
10597 -- For a pragma that is a rewriting of another pragma, copy the
10598 -- Is_Checked/Is_Ignored status from the rewritten pragma.
10599
10600 elsif Is_Rewrite_Substitution (N)
10601 and then Nkind (Original_Node (N)) = N_Pragma
10602 and then Original_Node (N) /= N
10603 then
10604 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
10605 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
10606
10607 -- Otherwise query the applicable policy at this point
10608
10609 else
10610 Check_Applicable_Policy (N);
10611
10612 -- If pragma is disabled, rewrite as NULL and skip analysis
10613
10614 if Is_Disabled (N) then
10615 Rewrite (N, Make_Null_Statement (Loc));
10616 Analyze (N);
10617 raise Pragma_Exit;
10618 end if;
10619 end if;
10620
10621 -- Preset arguments
10622
10623 Arg_Count := 0;
10624 Arg1 := Empty;
10625 Arg2 := Empty;
10626 Arg3 := Empty;
10627 Arg4 := Empty;
10628
10629 if Present (Pragma_Argument_Associations (N)) then
10630 Arg_Count := List_Length (Pragma_Argument_Associations (N));
10631 Arg1 := First (Pragma_Argument_Associations (N));
10632
10633 if Present (Arg1) then
10634 Arg2 := Next (Arg1);
10635
10636 if Present (Arg2) then
10637 Arg3 := Next (Arg2);
10638
10639 if Present (Arg3) then
10640 Arg4 := Next (Arg3);
10641 end if;
10642 end if;
10643 end if;
10644 end if;
10645
10646 -- An enumeration type defines the pragmas that are supported by the
10647 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
10648 -- into the corresponding enumeration value for the following case.
10649
10650 case Prag_Id is
10651
10652 -----------------
10653 -- Abort_Defer --
10654 -----------------
10655
10656 -- pragma Abort_Defer;
10657
10658 when Pragma_Abort_Defer =>
10659 GNAT_Pragma;
10660 Check_Arg_Count (0);
10661
10662 -- The only required semantic processing is to check the
10663 -- placement. This pragma must appear at the start of the
10664 -- statement sequence of a handled sequence of statements.
10665
10666 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
10667 or else N /= First (Statements (Parent (N)))
10668 then
10669 Pragma_Misplaced;
10670 end if;
10671
10672 --------------------
10673 -- Abstract_State --
10674 --------------------
10675
10676 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
10677
10678 -- ABSTRACT_STATE_LIST ::=
10679 -- null
10680 -- | STATE_NAME_WITH_OPTIONS
10681 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
10682
10683 -- STATE_NAME_WITH_OPTIONS ::=
10684 -- STATE_NAME
10685 -- | (STATE_NAME with OPTION_LIST)
10686
10687 -- OPTION_LIST ::= OPTION {, OPTION}
10688
10689 -- OPTION ::=
10690 -- SIMPLE_OPTION
10691 -- | NAME_VALUE_OPTION
10692
10693 -- SIMPLE_OPTION ::= Ghost | Synchronous
10694
10695 -- NAME_VALUE_OPTION ::=
10696 -- Part_Of => ABSTRACT_STATE
10697 -- | External [=> EXTERNAL_PROPERTY_LIST]
10698
10699 -- EXTERNAL_PROPERTY_LIST ::=
10700 -- EXTERNAL_PROPERTY
10701 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
10702
10703 -- EXTERNAL_PROPERTY ::=
10704 -- Async_Readers [=> boolean_EXPRESSION]
10705 -- | Async_Writers [=> boolean_EXPRESSION]
10706 -- | Effective_Reads [=> boolean_EXPRESSION]
10707 -- | Effective_Writes [=> boolean_EXPRESSION]
10708 -- others => boolean_EXPRESSION
10709
10710 -- STATE_NAME ::= defining_identifier
10711
10712 -- ABSTRACT_STATE ::= name
10713
10714 -- Characteristics:
10715
10716 -- * Analysis - The annotation is fully analyzed immediately upon
10717 -- elaboration as it cannot forward reference entities.
10718
10719 -- * Expansion - None.
10720
10721 -- * Template - The annotation utilizes the generic template of the
10722 -- related package declaration.
10723
10724 -- * Globals - The annotation cannot reference global entities.
10725
10726 -- * Instance - The annotation is instantiated automatically when
10727 -- the related generic package is instantiated.
10728
10729 when Pragma_Abstract_State => Abstract_State : declare
10730 Missing_Parentheses : Boolean := False;
10731 -- Flag set when a state declaration with options is not properly
10732 -- parenthesized.
10733
10734 -- Flags used to verify the consistency of states
10735
10736 Non_Null_Seen : Boolean := False;
10737 Null_Seen : Boolean := False;
10738
10739 procedure Analyze_Abstract_State
10740 (State : Node_Id;
10741 Pack_Id : Entity_Id);
10742 -- Verify the legality of a single state declaration. Create and
10743 -- decorate a state abstraction entity and introduce it into the
10744 -- visibility chain. Pack_Id denotes the entity or the related
10745 -- package where pragma Abstract_State appears.
10746
10747 procedure Malformed_State_Error (State : Node_Id);
10748 -- Emit an error concerning the illegal declaration of abstract
10749 -- state State. This routine diagnoses syntax errors that lead to
10750 -- a different parse tree. The error is issued regardless of the
10751 -- SPARK mode in effect.
10752
10753 ----------------------------
10754 -- Analyze_Abstract_State --
10755 ----------------------------
10756
10757 procedure Analyze_Abstract_State
10758 (State : Node_Id;
10759 Pack_Id : Entity_Id)
10760 is
10761 -- Flags used to verify the consistency of options
10762
10763 AR_Seen : Boolean := False;
10764 AW_Seen : Boolean := False;
10765 ER_Seen : Boolean := False;
10766 EW_Seen : Boolean := False;
10767 External_Seen : Boolean := False;
10768 Ghost_Seen : Boolean := False;
10769 Others_Seen : Boolean := False;
10770 Part_Of_Seen : Boolean := False;
10771 Synchronous_Seen : Boolean := False;
10772
10773 -- Flags used to store the static value of all external states'
10774 -- expressions.
10775
10776 AR_Val : Boolean := False;
10777 AW_Val : Boolean := False;
10778 ER_Val : Boolean := False;
10779 EW_Val : Boolean := False;
10780
10781 State_Id : Entity_Id := Empty;
10782 -- The entity to be generated for the current state declaration
10783
10784 procedure Analyze_External_Option (Opt : Node_Id);
10785 -- Verify the legality of option External
10786
10787 procedure Analyze_External_Property
10788 (Prop : Node_Id;
10789 Expr : Node_Id := Empty);
10790 -- Verify the legailty of a single external property. Prop
10791 -- denotes the external property. Expr is the expression used
10792 -- to set the property.
10793
10794 procedure Analyze_Part_Of_Option (Opt : Node_Id);
10795 -- Verify the legality of option Part_Of
10796
10797 procedure Check_Duplicate_Option
10798 (Opt : Node_Id;
10799 Status : in out Boolean);
10800 -- Flag Status denotes whether a particular option has been
10801 -- seen while processing a state. This routine verifies that
10802 -- Opt is not a duplicate option and sets the flag Status
10803 -- (SPARK RM 7.1.4(1)).
10804
10805 procedure Check_Duplicate_Property
10806 (Prop : Node_Id;
10807 Status : in out Boolean);
10808 -- Flag Status denotes whether a particular property has been
10809 -- seen while processing option External. This routine verifies
10810 -- that Prop is not a duplicate property and sets flag Status.
10811 -- Opt is not a duplicate property and sets the flag Status.
10812 -- (SPARK RM 7.1.4(2))
10813
10814 procedure Check_Ghost_Synchronous;
10815 -- Ensure that the abstract state is not subject to both Ghost
10816 -- and Synchronous simple options. Emit an error if this is the
10817 -- case.
10818
10819 procedure Create_Abstract_State
10820 (Nam : Name_Id;
10821 Decl : Node_Id;
10822 Loc : Source_Ptr;
10823 Is_Null : Boolean);
10824 -- Generate an abstract state entity with name Nam and enter it
10825 -- into visibility. Decl is the "declaration" of the state as
10826 -- it appears in pragma Abstract_State. Loc is the location of
10827 -- the related state "declaration". Flag Is_Null should be set
10828 -- when the associated Abstract_State pragma defines a null
10829 -- state.
10830
10831 -----------------------------
10832 -- Analyze_External_Option --
10833 -----------------------------
10834
10835 procedure Analyze_External_Option (Opt : Node_Id) is
10836 Errors : constant Nat := Serious_Errors_Detected;
10837 Prop : Node_Id;
10838 Props : Node_Id := Empty;
10839
10840 begin
10841 if Nkind (Opt) = N_Component_Association then
10842 Props := Expression (Opt);
10843 end if;
10844
10845 -- External state with properties
10846
10847 if Present (Props) then
10848
10849 -- Multiple properties appear as an aggregate
10850
10851 if Nkind (Props) = N_Aggregate then
10852
10853 -- Simple property form
10854
10855 Prop := First (Expressions (Props));
10856 while Present (Prop) loop
10857 Analyze_External_Property (Prop);
10858 Next (Prop);
10859 end loop;
10860
10861 -- Property with expression form
10862
10863 Prop := First (Component_Associations (Props));
10864 while Present (Prop) loop
10865 Analyze_External_Property
10866 (Prop => First (Choices (Prop)),
10867 Expr => Expression (Prop));
10868
10869 Next (Prop);
10870 end loop;
10871
10872 -- Single property
10873
10874 else
10875 Analyze_External_Property (Props);
10876 end if;
10877
10878 -- An external state defined without any properties defaults
10879 -- all properties to True.
10880
10881 else
10882 AR_Val := True;
10883 AW_Val := True;
10884 ER_Val := True;
10885 EW_Val := True;
10886 end if;
10887
10888 -- Once all external properties have been processed, verify
10889 -- their mutual interaction. Do not perform the check when
10890 -- at least one of the properties is illegal as this will
10891 -- produce a bogus error.
10892
10893 if Errors = Serious_Errors_Detected then
10894 Check_External_Properties
10895 (State, AR_Val, AW_Val, ER_Val, EW_Val);
10896 end if;
10897 end Analyze_External_Option;
10898
10899 -------------------------------
10900 -- Analyze_External_Property --
10901 -------------------------------
10902
10903 procedure Analyze_External_Property
10904 (Prop : Node_Id;
10905 Expr : Node_Id := Empty)
10906 is
10907 Expr_Val : Boolean;
10908
10909 begin
10910 -- Check the placement of "others" (if available)
10911
10912 if Nkind (Prop) = N_Others_Choice then
10913 if Others_Seen then
10914 SPARK_Msg_N
10915 ("only one others choice allowed in option External",
10916 Prop);
10917 else
10918 Others_Seen := True;
10919 end if;
10920
10921 elsif Others_Seen then
10922 SPARK_Msg_N
10923 ("others must be the last property in option External",
10924 Prop);
10925
10926 -- The only remaining legal options are the four predefined
10927 -- external properties.
10928
10929 elsif Nkind (Prop) = N_Identifier
10930 and then Nam_In (Chars (Prop), Name_Async_Readers,
10931 Name_Async_Writers,
10932 Name_Effective_Reads,
10933 Name_Effective_Writes)
10934 then
10935 null;
10936
10937 -- Otherwise the construct is not a valid property
10938
10939 else
10940 SPARK_Msg_N ("invalid external state property", Prop);
10941 return;
10942 end if;
10943
10944 -- Ensure that the expression of the external state property
10945 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
10946
10947 if Present (Expr) then
10948 Analyze_And_Resolve (Expr, Standard_Boolean);
10949
10950 if Is_OK_Static_Expression (Expr) then
10951 Expr_Val := Is_True (Expr_Value (Expr));
10952 else
10953 SPARK_Msg_N
10954 ("expression of external state property must be "
10955 & "static", Expr);
10956 end if;
10957
10958 -- The lack of expression defaults the property to True
10959
10960 else
10961 Expr_Val := True;
10962 end if;
10963
10964 -- Named properties
10965
10966 if Nkind (Prop) = N_Identifier then
10967 if Chars (Prop) = Name_Async_Readers then
10968 Check_Duplicate_Property (Prop, AR_Seen);
10969 AR_Val := Expr_Val;
10970
10971 elsif Chars (Prop) = Name_Async_Writers then
10972 Check_Duplicate_Property (Prop, AW_Seen);
10973 AW_Val := Expr_Val;
10974
10975 elsif Chars (Prop) = Name_Effective_Reads then
10976 Check_Duplicate_Property (Prop, ER_Seen);
10977 ER_Val := Expr_Val;
10978
10979 else
10980 Check_Duplicate_Property (Prop, EW_Seen);
10981 EW_Val := Expr_Val;
10982 end if;
10983
10984 -- The handling of property "others" must take into account
10985 -- all other named properties that have been encountered so
10986 -- far. Only those that have not been seen are affected by
10987 -- "others".
10988
10989 else
10990 if not AR_Seen then
10991 AR_Val := Expr_Val;
10992 end if;
10993
10994 if not AW_Seen then
10995 AW_Val := Expr_Val;
10996 end if;
10997
10998 if not ER_Seen then
10999 ER_Val := Expr_Val;
11000 end if;
11001
11002 if not EW_Seen then
11003 EW_Val := Expr_Val;
11004 end if;
11005 end if;
11006 end Analyze_External_Property;
11007
11008 ----------------------------
11009 -- Analyze_Part_Of_Option --
11010 ----------------------------
11011
11012 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
11013 Encap : constant Node_Id := Expression (Opt);
11014 Constits : Elist_Id;
11015 Encap_Id : Entity_Id;
11016 Legal : Boolean;
11017
11018 begin
11019 Check_Duplicate_Option (Opt, Part_Of_Seen);
11020
11021 Analyze_Part_Of
11022 (Indic => First (Choices (Opt)),
11023 Item_Id => State_Id,
11024 Encap => Encap,
11025 Encap_Id => Encap_Id,
11026 Legal => Legal);
11027
11028 -- The Part_Of indicator transforms the abstract state into
11029 -- a constituent of the encapsulating state or single
11030 -- concurrent type.
11031
11032 if Legal then
11033 pragma Assert (Present (Encap_Id));
11034 Constits := Part_Of_Constituents (Encap_Id);
11035
11036 if No (Constits) then
11037 Constits := New_Elmt_List;
11038 Set_Part_Of_Constituents (Encap_Id, Constits);
11039 end if;
11040
11041 Append_Elmt (State_Id, Constits);
11042 Set_Encapsulating_State (State_Id, Encap_Id);
11043 end if;
11044 end Analyze_Part_Of_Option;
11045
11046 ----------------------------
11047 -- Check_Duplicate_Option --
11048 ----------------------------
11049
11050 procedure Check_Duplicate_Option
11051 (Opt : Node_Id;
11052 Status : in out Boolean)
11053 is
11054 begin
11055 if Status then
11056 SPARK_Msg_N ("duplicate state option", Opt);
11057 end if;
11058
11059 Status := True;
11060 end Check_Duplicate_Option;
11061
11062 ------------------------------
11063 -- Check_Duplicate_Property --
11064 ------------------------------
11065
11066 procedure Check_Duplicate_Property
11067 (Prop : Node_Id;
11068 Status : in out Boolean)
11069 is
11070 begin
11071 if Status then
11072 SPARK_Msg_N ("duplicate external property", Prop);
11073 end if;
11074
11075 Status := True;
11076 end Check_Duplicate_Property;
11077
11078 -----------------------------
11079 -- Check_Ghost_Synchronous --
11080 -----------------------------
11081
11082 procedure Check_Ghost_Synchronous is
11083 begin
11084 -- A synchronized abstract state cannot be Ghost and vice
11085 -- versa (SPARK RM 6.9(19)).
11086
11087 if Ghost_Seen and Synchronous_Seen then
11088 SPARK_Msg_N ("synchronized state cannot be ghost", State);
11089 end if;
11090 end Check_Ghost_Synchronous;
11091
11092 ---------------------------
11093 -- Create_Abstract_State --
11094 ---------------------------
11095
11096 procedure Create_Abstract_State
11097 (Nam : Name_Id;
11098 Decl : Node_Id;
11099 Loc : Source_Ptr;
11100 Is_Null : Boolean)
11101 is
11102 begin
11103 -- The abstract state may be semi-declared when the related
11104 -- package was withed through a limited with clause. In that
11105 -- case reuse the entity to fully declare the state.
11106
11107 if Present (Decl) and then Present (Entity (Decl)) then
11108 State_Id := Entity (Decl);
11109
11110 -- Otherwise the elaboration of pragma Abstract_State
11111 -- declares the state.
11112
11113 else
11114 State_Id := Make_Defining_Identifier (Loc, Nam);
11115
11116 if Present (Decl) then
11117 Set_Entity (Decl, State_Id);
11118 end if;
11119 end if;
11120
11121 -- Null states never come from source
11122
11123 Set_Comes_From_Source (State_Id, not Is_Null);
11124 Set_Parent (State_Id, State);
11125 Set_Ekind (State_Id, E_Abstract_State);
11126 Set_Etype (State_Id, Standard_Void_Type);
11127 Set_Encapsulating_State (State_Id, Empty);
11128
11129 -- An abstract state declared within a Ghost region becomes
11130 -- Ghost (SPARK RM 6.9(2)).
11131
11132 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then
11133 Set_Is_Ghost_Entity (State_Id);
11134 end if;
11135
11136 -- Establish a link between the state declaration and the
11137 -- abstract state entity. Note that a null state remains as
11138 -- N_Null and does not carry any linkages.
11139
11140 if not Is_Null then
11141 if Present (Decl) then
11142 Set_Entity (Decl, State_Id);
11143 Set_Etype (Decl, Standard_Void_Type);
11144 end if;
11145
11146 -- Every non-null state must be defined, nameable and
11147 -- resolvable.
11148
11149 Push_Scope (Pack_Id);
11150 Generate_Definition (State_Id);
11151 Enter_Name (State_Id);
11152 Pop_Scope;
11153 end if;
11154 end Create_Abstract_State;
11155
11156 -- Local variables
11157
11158 Opt : Node_Id;
11159 Opt_Nam : Node_Id;
11160
11161 -- Start of processing for Analyze_Abstract_State
11162
11163 begin
11164 -- A package with a null abstract state is not allowed to
11165 -- declare additional states.
11166
11167 if Null_Seen then
11168 SPARK_Msg_NE
11169 ("package & has null abstract state", State, Pack_Id);
11170
11171 -- Null states appear as internally generated entities
11172
11173 elsif Nkind (State) = N_Null then
11174 Create_Abstract_State
11175 (Nam => New_Internal_Name ('S'),
11176 Decl => Empty,
11177 Loc => Sloc (State),
11178 Is_Null => True);
11179 Null_Seen := True;
11180
11181 -- Catch a case where a null state appears in a list of
11182 -- non-null states.
11183
11184 if Non_Null_Seen then
11185 SPARK_Msg_NE
11186 ("package & has non-null abstract state",
11187 State, Pack_Id);
11188 end if;
11189
11190 -- Simple state declaration
11191
11192 elsif Nkind (State) = N_Identifier then
11193 Create_Abstract_State
11194 (Nam => Chars (State),
11195 Decl => State,
11196 Loc => Sloc (State),
11197 Is_Null => False);
11198 Non_Null_Seen := True;
11199
11200 -- State declaration with various options. This construct
11201 -- appears as an extension aggregate in the tree.
11202
11203 elsif Nkind (State) = N_Extension_Aggregate then
11204 if Nkind (Ancestor_Part (State)) = N_Identifier then
11205 Create_Abstract_State
11206 (Nam => Chars (Ancestor_Part (State)),
11207 Decl => Ancestor_Part (State),
11208 Loc => Sloc (Ancestor_Part (State)),
11209 Is_Null => False);
11210 Non_Null_Seen := True;
11211 else
11212 SPARK_Msg_N
11213 ("state name must be an identifier",
11214 Ancestor_Part (State));
11215 end if;
11216
11217 -- Options External, Ghost and Synchronous appear as
11218 -- expressions.
11219
11220 Opt := First (Expressions (State));
11221 while Present (Opt) loop
11222 if Nkind (Opt) = N_Identifier then
11223
11224 -- External
11225
11226 if Chars (Opt) = Name_External then
11227 Check_Duplicate_Option (Opt, External_Seen);
11228 Analyze_External_Option (Opt);
11229
11230 -- Ghost
11231
11232 elsif Chars (Opt) = Name_Ghost then
11233 Check_Duplicate_Option (Opt, Ghost_Seen);
11234 Check_Ghost_Synchronous;
11235
11236 if Present (State_Id) then
11237 Set_Is_Ghost_Entity (State_Id);
11238 end if;
11239
11240 -- Synchronous
11241
11242 elsif Chars (Opt) = Name_Synchronous then
11243 Check_Duplicate_Option (Opt, Synchronous_Seen);
11244 Check_Ghost_Synchronous;
11245
11246 -- Option Part_Of without an encapsulating state is
11247 -- illegal (SPARK RM 7.1.4(9)).
11248
11249 elsif Chars (Opt) = Name_Part_Of then
11250 SPARK_Msg_N
11251 ("indicator Part_Of must denote abstract state, "
11252 & "single protected type or single task type",
11253 Opt);
11254
11255 -- Do not emit an error message when a previous state
11256 -- declaration with options was not parenthesized as
11257 -- the option is actually another state declaration.
11258 --
11259 -- with Abstract_State
11260 -- (State_1 with ..., -- missing parentheses
11261 -- (State_2 with ...),
11262 -- State_3) -- ok state declaration
11263
11264 elsif Missing_Parentheses then
11265 null;
11266
11267 -- Otherwise the option is not allowed. Note that it
11268 -- is not possible to distinguish between an option
11269 -- and a state declaration when a previous state with
11270 -- options not properly parentheses.
11271 --
11272 -- with Abstract_State
11273 -- (State_1 with ..., -- missing parentheses
11274 -- State_2); -- could be an option
11275
11276 else
11277 SPARK_Msg_N
11278 ("simple option not allowed in state declaration",
11279 Opt);
11280 end if;
11281
11282 -- Catch a case where missing parentheses around a state
11283 -- declaration with options cause a subsequent state
11284 -- declaration with options to be treated as an option.
11285 --
11286 -- with Abstract_State
11287 -- (State_1 with ..., -- missing parentheses
11288 -- (State_2 with ...))
11289
11290 elsif Nkind (Opt) = N_Extension_Aggregate then
11291 Missing_Parentheses := True;
11292 SPARK_Msg_N
11293 ("state declaration must be parenthesized",
11294 Ancestor_Part (State));
11295
11296 -- Otherwise the option is malformed
11297
11298 else
11299 SPARK_Msg_N ("malformed option", Opt);
11300 end if;
11301
11302 Next (Opt);
11303 end loop;
11304
11305 -- Options External and Part_Of appear as component
11306 -- associations.
11307
11308 Opt := First (Component_Associations (State));
11309 while Present (Opt) loop
11310 Opt_Nam := First (Choices (Opt));
11311
11312 if Nkind (Opt_Nam) = N_Identifier then
11313 if Chars (Opt_Nam) = Name_External then
11314 Analyze_External_Option (Opt);
11315
11316 elsif Chars (Opt_Nam) = Name_Part_Of then
11317 Analyze_Part_Of_Option (Opt);
11318
11319 else
11320 SPARK_Msg_N ("invalid state option", Opt);
11321 end if;
11322 else
11323 SPARK_Msg_N ("invalid state option", Opt);
11324 end if;
11325
11326 Next (Opt);
11327 end loop;
11328
11329 -- Any other attempt to declare a state is illegal
11330
11331 else
11332 Malformed_State_Error (State);
11333 return;
11334 end if;
11335
11336 -- Guard against a junk state. In such cases no entity is
11337 -- generated and the subsequent checks cannot be applied.
11338
11339 if Present (State_Id) then
11340
11341 -- Verify whether the state does not introduce an illegal
11342 -- hidden state within a package subject to a null abstract
11343 -- state.
11344
11345 Check_No_Hidden_State (State_Id);
11346
11347 -- Check whether the lack of option Part_Of agrees with the
11348 -- placement of the abstract state with respect to the state
11349 -- space.
11350
11351 if not Part_Of_Seen then
11352 Check_Missing_Part_Of (State_Id);
11353 end if;
11354
11355 -- Associate the state with its related package
11356
11357 if No (Abstract_States (Pack_Id)) then
11358 Set_Abstract_States (Pack_Id, New_Elmt_List);
11359 end if;
11360
11361 Append_Elmt (State_Id, Abstract_States (Pack_Id));
11362 end if;
11363 end Analyze_Abstract_State;
11364
11365 ---------------------------
11366 -- Malformed_State_Error --
11367 ---------------------------
11368
11369 procedure Malformed_State_Error (State : Node_Id) is
11370 begin
11371 Error_Msg_N ("malformed abstract state declaration", State);
11372
11373 -- An abstract state with a simple option is being declared
11374 -- with "=>" rather than the legal "with". The state appears
11375 -- as a component association.
11376
11377 if Nkind (State) = N_Component_Association then
11378 Error_Msg_N ("\use WITH to specify simple option", State);
11379 end if;
11380 end Malformed_State_Error;
11381
11382 -- Local variables
11383
11384 Pack_Decl : Node_Id;
11385 Pack_Id : Entity_Id;
11386 State : Node_Id;
11387 States : Node_Id;
11388
11389 -- Start of processing for Abstract_State
11390
11391 begin
11392 GNAT_Pragma;
11393 Check_No_Identifiers;
11394 Check_Arg_Count (1);
11395
11396 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
11397
11398 -- Ensure the proper placement of the pragma. Abstract states must
11399 -- be associated with a package declaration.
11400
11401 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
11402 N_Package_Declaration)
11403 then
11404 null;
11405
11406 -- Otherwise the pragma is associated with an illegal construct
11407
11408 else
11409 Pragma_Misplaced;
11410 return;
11411 end if;
11412
11413 Pack_Id := Defining_Entity (Pack_Decl);
11414
11415 -- A pragma that applies to a Ghost entity becomes Ghost for the
11416 -- purposes of legality checks and removal of ignored Ghost code.
11417
11418 Mark_Ghost_Pragma (N, Pack_Id);
11419 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
11420
11421 -- Chain the pragma on the contract for completeness
11422
11423 Add_Contract_Item (N, Pack_Id);
11424
11425 -- The legality checks of pragmas Abstract_State, Initializes, and
11426 -- Initial_Condition are affected by the SPARK mode in effect. In
11427 -- addition, these three pragmas are subject to an inherent order:
11428
11429 -- 1) Abstract_State
11430 -- 2) Initializes
11431 -- 3) Initial_Condition
11432
11433 -- Analyze all these pragmas in the order outlined above
11434
11435 Analyze_If_Present (Pragma_SPARK_Mode);
11436 States := Expression (Get_Argument (N, Pack_Id));
11437
11438 -- Multiple non-null abstract states appear as an aggregate
11439
11440 if Nkind (States) = N_Aggregate then
11441 State := First (Expressions (States));
11442 while Present (State) loop
11443 Analyze_Abstract_State (State, Pack_Id);
11444 Next (State);
11445 end loop;
11446
11447 -- An abstract state with a simple option is being illegaly
11448 -- declared with "=>" rather than "with". In this case the
11449 -- state declaration appears as a component association.
11450
11451 if Present (Component_Associations (States)) then
11452 State := First (Component_Associations (States));
11453 while Present (State) loop
11454 Malformed_State_Error (State);
11455 Next (State);
11456 end loop;
11457 end if;
11458
11459 -- Various forms of a single abstract state. Note that these may
11460 -- include malformed state declarations.
11461
11462 else
11463 Analyze_Abstract_State (States, Pack_Id);
11464 end if;
11465
11466 Analyze_If_Present (Pragma_Initializes);
11467 Analyze_If_Present (Pragma_Initial_Condition);
11468 end Abstract_State;
11469
11470 ------------
11471 -- Ada_83 --
11472 ------------
11473
11474 -- pragma Ada_83;
11475
11476 -- Note: this pragma also has some specific processing in Par.Prag
11477 -- because we want to set the Ada version mode during parsing.
11478
11479 when Pragma_Ada_83 =>
11480 GNAT_Pragma;
11481 Check_Arg_Count (0);
11482
11483 -- We really should check unconditionally for proper configuration
11484 -- pragma placement, since we really don't want mixed Ada modes
11485 -- within a single unit, and the GNAT reference manual has always
11486 -- said this was a configuration pragma, but we did not check and
11487 -- are hesitant to add the check now.
11488
11489 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
11490 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
11491 -- or Ada 2012 mode.
11492
11493 if Ada_Version >= Ada_2005 then
11494 Check_Valid_Configuration_Pragma;
11495 end if;
11496
11497 -- Now set Ada 83 mode
11498
11499 if Latest_Ada_Only then
11500 Error_Pragma ("??pragma% ignored");
11501 else
11502 Ada_Version := Ada_83;
11503 Ada_Version_Explicit := Ada_83;
11504 Ada_Version_Pragma := N;
11505 end if;
11506
11507 ------------
11508 -- Ada_95 --
11509 ------------
11510
11511 -- pragma Ada_95;
11512
11513 -- Note: this pragma also has some specific processing in Par.Prag
11514 -- because we want to set the Ada 83 version mode during parsing.
11515
11516 when Pragma_Ada_95 =>
11517 GNAT_Pragma;
11518 Check_Arg_Count (0);
11519
11520 -- We really should check unconditionally for proper configuration
11521 -- pragma placement, since we really don't want mixed Ada modes
11522 -- within a single unit, and the GNAT reference manual has always
11523 -- said this was a configuration pragma, but we did not check and
11524 -- are hesitant to add the check now.
11525
11526 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
11527 -- or Ada 95, so we must check if we are in Ada 2005 mode.
11528
11529 if Ada_Version >= Ada_2005 then
11530 Check_Valid_Configuration_Pragma;
11531 end if;
11532
11533 -- Now set Ada 95 mode
11534
11535 if Latest_Ada_Only then
11536 Error_Pragma ("??pragma% ignored");
11537 else
11538 Ada_Version := Ada_95;
11539 Ada_Version_Explicit := Ada_95;
11540 Ada_Version_Pragma := N;
11541 end if;
11542
11543 ---------------------
11544 -- Ada_05/Ada_2005 --
11545 ---------------------
11546
11547 -- pragma Ada_05;
11548 -- pragma Ada_05 (LOCAL_NAME);
11549
11550 -- pragma Ada_2005;
11551 -- pragma Ada_2005 (LOCAL_NAME):
11552
11553 -- Note: these pragmas also have some specific processing in Par.Prag
11554 -- because we want to set the Ada 2005 version mode during parsing.
11555
11556 -- The one argument form is used for managing the transition from
11557 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
11558 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
11559 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
11560 -- mode, a preference rule is established which does not choose
11561 -- such an entity unless it is unambiguously specified. This avoids
11562 -- extra subprograms marked this way from generating ambiguities in
11563 -- otherwise legal pre-Ada_2005 programs. The one argument form is
11564 -- intended for exclusive use in the GNAT run-time library.
11565
11566 when Pragma_Ada_05
11567 | Pragma_Ada_2005
11568 =>
11569 declare
11570 E_Id : Node_Id;
11571
11572 begin
11573 GNAT_Pragma;
11574
11575 if Arg_Count = 1 then
11576 Check_Arg_Is_Local_Name (Arg1);
11577 E_Id := Get_Pragma_Arg (Arg1);
11578
11579 if Etype (E_Id) = Any_Type then
11580 return;
11581 end if;
11582
11583 Set_Is_Ada_2005_Only (Entity (E_Id));
11584 Record_Rep_Item (Entity (E_Id), N);
11585
11586 else
11587 Check_Arg_Count (0);
11588
11589 -- For Ada_2005 we unconditionally enforce the documented
11590 -- configuration pragma placement, since we do not want to
11591 -- tolerate mixed modes in a unit involving Ada 2005. That
11592 -- would cause real difficulties for those cases where there
11593 -- are incompatibilities between Ada 95 and Ada 2005.
11594
11595 Check_Valid_Configuration_Pragma;
11596
11597 -- Now set appropriate Ada mode
11598
11599 if Latest_Ada_Only then
11600 Error_Pragma ("??pragma% ignored");
11601 else
11602 Ada_Version := Ada_2005;
11603 Ada_Version_Explicit := Ada_2005;
11604 Ada_Version_Pragma := N;
11605 end if;
11606 end if;
11607 end;
11608
11609 ---------------------
11610 -- Ada_12/Ada_2012 --
11611 ---------------------
11612
11613 -- pragma Ada_12;
11614 -- pragma Ada_12 (LOCAL_NAME);
11615
11616 -- pragma Ada_2012;
11617 -- pragma Ada_2012 (LOCAL_NAME):
11618
11619 -- Note: these pragmas also have some specific processing in Par.Prag
11620 -- because we want to set the Ada 2012 version mode during parsing.
11621
11622 -- The one argument form is used for managing the transition from Ada
11623 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
11624 -- as Ada_201 only, then referencing the entity in any pre-Ada_2012
11625 -- mode will generate a warning. In addition, in any pre-Ada_2012
11626 -- mode, a preference rule is established which does not choose
11627 -- such an entity unless it is unambiguously specified. This avoids
11628 -- extra subprograms marked this way from generating ambiguities in
11629 -- otherwise legal pre-Ada_2012 programs. The one argument form is
11630 -- intended for exclusive use in the GNAT run-time library.
11631
11632 when Pragma_Ada_12
11633 | Pragma_Ada_2012
11634 =>
11635 declare
11636 E_Id : Node_Id;
11637
11638 begin
11639 GNAT_Pragma;
11640
11641 if Arg_Count = 1 then
11642 Check_Arg_Is_Local_Name (Arg1);
11643 E_Id := Get_Pragma_Arg (Arg1);
11644
11645 if Etype (E_Id) = Any_Type then
11646 return;
11647 end if;
11648
11649 Set_Is_Ada_2012_Only (Entity (E_Id));
11650 Record_Rep_Item (Entity (E_Id), N);
11651
11652 else
11653 Check_Arg_Count (0);
11654
11655 -- For Ada_2012 we unconditionally enforce the documented
11656 -- configuration pragma placement, since we do not want to
11657 -- tolerate mixed modes in a unit involving Ada 2012. That
11658 -- would cause real difficulties for those cases where there
11659 -- are incompatibilities between Ada 95 and Ada 2012. We could
11660 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
11661
11662 Check_Valid_Configuration_Pragma;
11663
11664 -- Now set appropriate Ada mode
11665
11666 Ada_Version := Ada_2012;
11667 Ada_Version_Explicit := Ada_2012;
11668 Ada_Version_Pragma := N;
11669 end if;
11670 end;
11671
11672 ----------------------
11673 -- All_Calls_Remote --
11674 ----------------------
11675
11676 -- pragma All_Calls_Remote [(library_package_NAME)];
11677
11678 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
11679 Lib_Entity : Entity_Id;
11680
11681 begin
11682 Check_Ada_83_Warning;
11683 Check_Valid_Library_Unit_Pragma;
11684
11685 if Nkind (N) = N_Null_Statement then
11686 return;
11687 end if;
11688
11689 Lib_Entity := Find_Lib_Unit_Name;
11690
11691 -- A pragma that applies to a Ghost entity becomes Ghost for the
11692 -- purposes of legality checks and removal of ignored Ghost code.
11693
11694 Mark_Ghost_Pragma (N, Lib_Entity);
11695
11696 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
11697
11698 if Present (Lib_Entity) and then not Debug_Flag_U then
11699 if not Is_Remote_Call_Interface (Lib_Entity) then
11700 Error_Pragma ("pragma% only apply to rci unit");
11701
11702 -- Set flag for entity of the library unit
11703
11704 else
11705 Set_Has_All_Calls_Remote (Lib_Entity);
11706 end if;
11707 end if;
11708 end All_Calls_Remote;
11709
11710 ---------------------------
11711 -- Allow_Integer_Address --
11712 ---------------------------
11713
11714 -- pragma Allow_Integer_Address;
11715
11716 when Pragma_Allow_Integer_Address =>
11717 GNAT_Pragma;
11718 Check_Valid_Configuration_Pragma;
11719 Check_Arg_Count (0);
11720
11721 -- If Address is a private type, then set the flag to allow
11722 -- integer address values. If Address is not private, then this
11723 -- pragma has no purpose, so it is simply ignored. Not clear if
11724 -- there are any such targets now.
11725
11726 if Opt.Address_Is_Private then
11727 Opt.Allow_Integer_Address := True;
11728 end if;
11729
11730 --------------
11731 -- Annotate --
11732 --------------
11733
11734 -- pragma Annotate
11735 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
11736 -- ARG ::= NAME | EXPRESSION
11737
11738 -- The first two arguments are by convention intended to refer to an
11739 -- external tool and a tool-specific function. These arguments are
11740 -- not analyzed.
11741
11742 when Pragma_Annotate => Annotate : declare
11743 Arg : Node_Id;
11744 Expr : Node_Id;
11745 Nam_Arg : Node_Id;
11746
11747 begin
11748 GNAT_Pragma;
11749 Check_At_Least_N_Arguments (1);
11750
11751 Nam_Arg := Last (Pragma_Argument_Associations (N));
11752
11753 -- Determine whether the last argument is "Entity => local_NAME"
11754 -- and if it is, perform the required semantic checks. Remove the
11755 -- argument from further processing.
11756
11757 if Nkind (Nam_Arg) = N_Pragma_Argument_Association
11758 and then Chars (Nam_Arg) = Name_Entity
11759 then
11760 Check_Arg_Is_Local_Name (Nam_Arg);
11761 Arg_Count := Arg_Count - 1;
11762
11763 -- A pragma that applies to a Ghost entity becomes Ghost for
11764 -- the purposes of legality checks and removal of ignored Ghost
11765 -- code.
11766
11767 if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg))
11768 and then Present (Entity (Get_Pragma_Arg (Nam_Arg)))
11769 then
11770 Mark_Ghost_Pragma (N, Entity (Get_Pragma_Arg (Nam_Arg)));
11771 end if;
11772
11773 -- Not allowed in compiler units (bootstrap issues)
11774
11775 Check_Compiler_Unit ("Entity for pragma Annotate", N);
11776 end if;
11777
11778 -- Continue the processing with last argument removed for now
11779
11780 Check_Arg_Is_Identifier (Arg1);
11781 Check_No_Identifiers;
11782 Store_Note (N);
11783
11784 -- The second parameter is optional, it is never analyzed
11785
11786 if No (Arg2) then
11787 null;
11788
11789 -- Otherwise there is a second parameter
11790
11791 else
11792 -- The second parameter must be an identifier
11793
11794 Check_Arg_Is_Identifier (Arg2);
11795
11796 -- Process the remaining parameters (if any)
11797
11798 Arg := Next (Arg2);
11799 while Present (Arg) loop
11800 Expr := Get_Pragma_Arg (Arg);
11801 Analyze (Expr);
11802
11803 if Is_Entity_Name (Expr) then
11804 null;
11805
11806 -- For string literals, we assume Standard_String as the
11807 -- type, unless the string contains wide or wide_wide
11808 -- characters.
11809
11810 elsif Nkind (Expr) = N_String_Literal then
11811 if Has_Wide_Wide_Character (Expr) then
11812 Resolve (Expr, Standard_Wide_Wide_String);
11813 elsif Has_Wide_Character (Expr) then
11814 Resolve (Expr, Standard_Wide_String);
11815 else
11816 Resolve (Expr, Standard_String);
11817 end if;
11818
11819 elsif Is_Overloaded (Expr) then
11820 Error_Pragma_Arg ("ambiguous argument for pragma%", Expr);
11821
11822 else
11823 Resolve (Expr);
11824 end if;
11825
11826 Next (Arg);
11827 end loop;
11828 end if;
11829 end Annotate;
11830
11831 -------------------------------------------------
11832 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
11833 -------------------------------------------------
11834
11835 -- pragma Assert
11836 -- ( [Check => ] Boolean_EXPRESSION
11837 -- [, [Message =>] Static_String_EXPRESSION]);
11838
11839 -- pragma Assert_And_Cut
11840 -- ( [Check => ] Boolean_EXPRESSION
11841 -- [, [Message =>] Static_String_EXPRESSION]);
11842
11843 -- pragma Assume
11844 -- ( [Check => ] Boolean_EXPRESSION
11845 -- [, [Message =>] Static_String_EXPRESSION]);
11846
11847 -- pragma Loop_Invariant
11848 -- ( [Check => ] Boolean_EXPRESSION
11849 -- [, [Message =>] Static_String_EXPRESSION]);
11850
11851 when Pragma_Assert
11852 | Pragma_Assert_And_Cut
11853 | Pragma_Assume
11854 | Pragma_Loop_Invariant
11855 =>
11856 Assert : declare
11857 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
11858 -- Determine whether expression Expr contains a Loop_Entry
11859 -- attribute reference.
11860
11861 -------------------------
11862 -- Contains_Loop_Entry --
11863 -------------------------
11864
11865 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
11866 Has_Loop_Entry : Boolean := False;
11867
11868 function Process (N : Node_Id) return Traverse_Result;
11869 -- Process function for traversal to look for Loop_Entry
11870
11871 -------------
11872 -- Process --
11873 -------------
11874
11875 function Process (N : Node_Id) return Traverse_Result is
11876 begin
11877 if Nkind (N) = N_Attribute_Reference
11878 and then Attribute_Name (N) = Name_Loop_Entry
11879 then
11880 Has_Loop_Entry := True;
11881 return Abandon;
11882 else
11883 return OK;
11884 end if;
11885 end Process;
11886
11887 procedure Traverse is new Traverse_Proc (Process);
11888
11889 -- Start of processing for Contains_Loop_Entry
11890
11891 begin
11892 Traverse (Expr);
11893 return Has_Loop_Entry;
11894 end Contains_Loop_Entry;
11895
11896 -- Local variables
11897
11898 Expr : Node_Id;
11899 New_Args : List_Id;
11900
11901 -- Start of processing for Assert
11902
11903 begin
11904 -- Assert is an Ada 2005 RM-defined pragma
11905
11906 if Prag_Id = Pragma_Assert then
11907 Ada_2005_Pragma;
11908
11909 -- The remaining ones are GNAT pragmas
11910
11911 else
11912 GNAT_Pragma;
11913 end if;
11914
11915 Check_At_Least_N_Arguments (1);
11916 Check_At_Most_N_Arguments (2);
11917 Check_Arg_Order ((Name_Check, Name_Message));
11918 Check_Optional_Identifier (Arg1, Name_Check);
11919 Expr := Get_Pragma_Arg (Arg1);
11920
11921 -- Special processing for Loop_Invariant, Loop_Variant or for
11922 -- other cases where a Loop_Entry attribute is present. If the
11923 -- assertion pragma contains attribute Loop_Entry, ensure that
11924 -- the related pragma is within a loop.
11925
11926 if Prag_Id = Pragma_Loop_Invariant
11927 or else Prag_Id = Pragma_Loop_Variant
11928 or else Contains_Loop_Entry (Expr)
11929 then
11930 Check_Loop_Pragma_Placement;
11931
11932 -- Perform preanalysis to deal with embedded Loop_Entry
11933 -- attributes.
11934
11935 Preanalyze_Assert_Expression (Expr, Any_Boolean);
11936 end if;
11937
11938 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
11939 -- a corresponding Check pragma:
11940
11941 -- pragma Check (name, condition [, msg]);
11942
11943 -- Where name is the identifier matching the pragma name. So
11944 -- rewrite pragma in this manner, transfer the message argument
11945 -- if present, and analyze the result
11946
11947 -- Note: When dealing with a semantically analyzed tree, the
11948 -- information that a Check node N corresponds to a source Assert,
11949 -- Assume, or Assert_And_Cut pragma can be retrieved from the
11950 -- pragma kind of Original_Node(N).
11951
11952 New_Args := New_List (
11953 Make_Pragma_Argument_Association (Loc,
11954 Expression => Make_Identifier (Loc, Pname)),
11955 Make_Pragma_Argument_Association (Sloc (Expr),
11956 Expression => Expr));
11957
11958 if Arg_Count > 1 then
11959 Check_Optional_Identifier (Arg2, Name_Message);
11960
11961 -- Provide semantic annnotations for optional argument, for
11962 -- ASIS use, before rewriting.
11963
11964 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
11965 Append_To (New_Args, New_Copy_Tree (Arg2));
11966 end if;
11967
11968 -- Rewrite as Check pragma
11969
11970 Rewrite (N,
11971 Make_Pragma (Loc,
11972 Chars => Name_Check,
11973 Pragma_Argument_Associations => New_Args));
11974
11975 Analyze (N);
11976 end Assert;
11977
11978 ----------------------
11979 -- Assertion_Policy --
11980 ----------------------
11981
11982 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
11983
11984 -- The following form is Ada 2012 only, but we allow it in all modes
11985
11986 -- Pragma Assertion_Policy (
11987 -- ASSERTION_KIND => POLICY_IDENTIFIER
11988 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
11989
11990 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
11991
11992 -- RM_ASSERTION_KIND ::= Assert |
11993 -- Static_Predicate |
11994 -- Dynamic_Predicate |
11995 -- Pre |
11996 -- Pre'Class |
11997 -- Post |
11998 -- Post'Class |
11999 -- Type_Invariant |
12000 -- Type_Invariant'Class
12001
12002 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
12003 -- Assume |
12004 -- Contract_Cases |
12005 -- Debug |
12006 -- Default_Initial_Condition |
12007 -- Ghost |
12008 -- Initial_Condition |
12009 -- Loop_Invariant |
12010 -- Loop_Variant |
12011 -- Postcondition |
12012 -- Precondition |
12013 -- Predicate |
12014 -- Refined_Post |
12015 -- Statement_Assertions
12016
12017 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
12018 -- ID_ASSERTION_KIND list contains implementation-defined additions
12019 -- recognized by GNAT. The effect is to control the behavior of
12020 -- identically named aspects and pragmas, depending on the specified
12021 -- policy identifier:
12022
12023 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
12024
12025 -- Note: Check and Ignore are language-defined. Disable is a GNAT
12026 -- implementation-defined addition that results in totally ignoring
12027 -- the corresponding assertion. If Disable is specified, then the
12028 -- argument of the assertion is not even analyzed. This is useful
12029 -- when the aspect/pragma argument references entities in a with'ed
12030 -- package that is replaced by a dummy package in the final build.
12031
12032 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
12033 -- and Type_Invariant'Class were recognized by the parser and
12034 -- transformed into references to the special internal identifiers
12035 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
12036 -- processing is required here.
12037
12038 when Pragma_Assertion_Policy => Assertion_Policy : declare
12039 procedure Resolve_Suppressible (Policy : Node_Id);
12040 -- Converts the assertion policy 'Suppressible' to either Check or
12041 -- Ignore based on whether checks are suppressed via -gnatp.
12042
12043 --------------------------
12044 -- Resolve_Suppressible --
12045 --------------------------
12046
12047 procedure Resolve_Suppressible (Policy : Node_Id) is
12048 Arg : constant Node_Id := Get_Pragma_Arg (Policy);
12049 Nam : Name_Id;
12050
12051 begin
12052 -- Transform policy argument Suppressible into either Ignore or
12053 -- Check depending on whether checks are enabled or suppressed.
12054
12055 if Chars (Arg) = Name_Suppressible then
12056 if Suppress_Checks then
12057 Nam := Name_Ignore;
12058 else
12059 Nam := Name_Check;
12060 end if;
12061
12062 Rewrite (Arg, Make_Identifier (Sloc (Arg), Nam));
12063 end if;
12064 end Resolve_Suppressible;
12065
12066 -- Local variables
12067
12068 Arg : Node_Id;
12069 Kind : Name_Id;
12070 LocP : Source_Ptr;
12071 Policy : Node_Id;
12072
12073 begin
12074 Ada_2005_Pragma;
12075
12076 -- This can always appear as a configuration pragma
12077
12078 if Is_Configuration_Pragma then
12079 null;
12080
12081 -- It can also appear in a declarative part or package spec in Ada
12082 -- 2012 mode. We allow this in other modes, but in that case we
12083 -- consider that we have an Ada 2012 pragma on our hands.
12084
12085 else
12086 Check_Is_In_Decl_Part_Or_Package_Spec;
12087 Ada_2012_Pragma;
12088 end if;
12089
12090 -- One argument case with no identifier (first form above)
12091
12092 if Arg_Count = 1
12093 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
12094 or else Chars (Arg1) = No_Name)
12095 then
12096 Check_Arg_Is_One_Of (Arg1,
12097 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
12098
12099 Resolve_Suppressible (Arg1);
12100
12101 -- Treat one argument Assertion_Policy as equivalent to:
12102
12103 -- pragma Check_Policy (Assertion, policy)
12104
12105 -- So rewrite pragma in that manner and link on to the chain
12106 -- of Check_Policy pragmas, marking the pragma as analyzed.
12107
12108 Policy := Get_Pragma_Arg (Arg1);
12109
12110 Rewrite (N,
12111 Make_Pragma (Loc,
12112 Chars => Name_Check_Policy,
12113 Pragma_Argument_Associations => New_List (
12114 Make_Pragma_Argument_Association (Loc,
12115 Expression => Make_Identifier (Loc, Name_Assertion)),
12116
12117 Make_Pragma_Argument_Association (Loc,
12118 Expression =>
12119 Make_Identifier (Sloc (Policy), Chars (Policy))))));
12120 Analyze (N);
12121
12122 -- Here if we have two or more arguments
12123
12124 else
12125 Check_At_Least_N_Arguments (1);
12126 Ada_2012_Pragma;
12127
12128 -- Loop through arguments
12129
12130 Arg := Arg1;
12131 while Present (Arg) loop
12132 LocP := Sloc (Arg);
12133
12134 -- Kind must be specified
12135
12136 if Nkind (Arg) /= N_Pragma_Argument_Association
12137 or else Chars (Arg) = No_Name
12138 then
12139 Error_Pragma_Arg
12140 ("missing assertion kind for pragma%", Arg);
12141 end if;
12142
12143 -- Check Kind and Policy have allowed forms
12144
12145 Kind := Chars (Arg);
12146 Policy := Get_Pragma_Arg (Arg);
12147
12148 if not Is_Valid_Assertion_Kind (Kind) then
12149 Error_Pragma_Arg
12150 ("invalid assertion kind for pragma%", Arg);
12151 end if;
12152
12153 Check_Arg_Is_One_Of (Arg,
12154 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
12155
12156 Resolve_Suppressible (Arg);
12157
12158 if Kind = Name_Ghost then
12159
12160 -- The Ghost policy must be either Check or Ignore
12161 -- (SPARK RM 6.9(6)).
12162
12163 if not Nam_In (Chars (Policy), Name_Check,
12164 Name_Ignore)
12165 then
12166 Error_Pragma_Arg
12167 ("argument of pragma % Ghost must be Check or "
12168 & "Ignore", Policy);
12169 end if;
12170
12171 -- Pragma Assertion_Policy specifying a Ghost policy
12172 -- cannot occur within a Ghost subprogram or package
12173 -- (SPARK RM 6.9(14)).
12174
12175 if Ghost_Mode > None then
12176 Error_Pragma
12177 ("pragma % cannot appear within ghost subprogram or "
12178 & "package");
12179 end if;
12180 end if;
12181
12182 -- Rewrite the Assertion_Policy pragma as a series of
12183 -- Check_Policy pragmas of the form:
12184
12185 -- Check_Policy (Kind, Policy);
12186
12187 -- Note: the insertion of the pragmas cannot be done with
12188 -- Insert_Action because in the configuration case, there
12189 -- are no scopes on the scope stack and the mechanism will
12190 -- fail.
12191
12192 Insert_Before_And_Analyze (N,
12193 Make_Pragma (LocP,
12194 Chars => Name_Check_Policy,
12195 Pragma_Argument_Associations => New_List (
12196 Make_Pragma_Argument_Association (LocP,
12197 Expression => Make_Identifier (LocP, Kind)),
12198 Make_Pragma_Argument_Association (LocP,
12199 Expression => Policy))));
12200
12201 Arg := Next (Arg);
12202 end loop;
12203
12204 -- Rewrite the Assertion_Policy pragma as null since we have
12205 -- now inserted all the equivalent Check pragmas.
12206
12207 Rewrite (N, Make_Null_Statement (Loc));
12208 Analyze (N);
12209 end if;
12210 end Assertion_Policy;
12211
12212 ------------------------------
12213 -- Assume_No_Invalid_Values --
12214 ------------------------------
12215
12216 -- pragma Assume_No_Invalid_Values (On | Off);
12217
12218 when Pragma_Assume_No_Invalid_Values =>
12219 GNAT_Pragma;
12220 Check_Valid_Configuration_Pragma;
12221 Check_Arg_Count (1);
12222 Check_No_Identifiers;
12223 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12224
12225 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
12226 Assume_No_Invalid_Values := True;
12227 else
12228 Assume_No_Invalid_Values := False;
12229 end if;
12230
12231 --------------------------
12232 -- Attribute_Definition --
12233 --------------------------
12234
12235 -- pragma Attribute_Definition
12236 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
12237 -- [Entity =>] LOCAL_NAME,
12238 -- [Expression =>] EXPRESSION | NAME);
12239
12240 when Pragma_Attribute_Definition => Attribute_Definition : declare
12241 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
12242 Aname : Name_Id;
12243
12244 begin
12245 GNAT_Pragma;
12246 Check_Arg_Count (3);
12247 Check_Optional_Identifier (Arg1, "attribute");
12248 Check_Optional_Identifier (Arg2, "entity");
12249 Check_Optional_Identifier (Arg3, "expression");
12250
12251 if Nkind (Attribute_Designator) /= N_Identifier then
12252 Error_Msg_N ("attribute name expected", Attribute_Designator);
12253 return;
12254 end if;
12255
12256 Check_Arg_Is_Local_Name (Arg2);
12257
12258 -- If the attribute is not recognized, then issue a warning (not
12259 -- an error), and ignore the pragma.
12260
12261 Aname := Chars (Attribute_Designator);
12262
12263 if not Is_Attribute_Name (Aname) then
12264 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
12265 return;
12266 end if;
12267
12268 -- Otherwise, rewrite the pragma as an attribute definition clause
12269
12270 Rewrite (N,
12271 Make_Attribute_Definition_Clause (Loc,
12272 Name => Get_Pragma_Arg (Arg2),
12273 Chars => Aname,
12274 Expression => Get_Pragma_Arg (Arg3)));
12275 Analyze (N);
12276 end Attribute_Definition;
12277
12278 ------------------------------------------------------------------
12279 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
12280 ------------------------------------------------------------------
12281
12282 -- pragma Asynch_Readers [ (boolean_EXPRESSION) ];
12283 -- pragma Asynch_Writers [ (boolean_EXPRESSION) ];
12284 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
12285 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
12286
12287 when Pragma_Async_Readers
12288 | Pragma_Async_Writers
12289 | Pragma_Effective_Reads
12290 | Pragma_Effective_Writes
12291 =>
12292 Async_Effective : declare
12293 Obj_Decl : Node_Id;
12294 Obj_Id : Entity_Id;
12295
12296 begin
12297 GNAT_Pragma;
12298 Check_No_Identifiers;
12299 Check_At_Most_N_Arguments (1);
12300
12301 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
12302
12303 -- Object declaration
12304
12305 if Nkind (Obj_Decl) = N_Object_Declaration then
12306 null;
12307
12308 -- Otherwise the pragma is associated with an illegal construact
12309
12310 else
12311 Pragma_Misplaced;
12312 return;
12313 end if;
12314
12315 Obj_Id := Defining_Entity (Obj_Decl);
12316
12317 -- Perform minimal verification to ensure that the argument is at
12318 -- least a variable. Subsequent finer grained checks will be done
12319 -- at the end of the declarative region the contains the pragma.
12320
12321 if Ekind (Obj_Id) = E_Variable then
12322
12323 -- A pragma that applies to a Ghost entity becomes Ghost for
12324 -- the purposes of legality checks and removal of ignored Ghost
12325 -- code.
12326
12327 Mark_Ghost_Pragma (N, Obj_Id);
12328
12329 -- Chain the pragma on the contract for further processing by
12330 -- Analyze_External_Property_In_Decl_Part.
12331
12332 Add_Contract_Item (N, Obj_Id);
12333
12334 -- Analyze the Boolean expression (if any)
12335
12336 if Present (Arg1) then
12337 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
12338 end if;
12339
12340 -- Otherwise the external property applies to a constant
12341
12342 else
12343 Error_Pragma ("pragma % must apply to a volatile object");
12344 end if;
12345 end Async_Effective;
12346
12347 ------------------
12348 -- Asynchronous --
12349 ------------------
12350
12351 -- pragma Asynchronous (LOCAL_NAME);
12352
12353 when Pragma_Asynchronous => Asynchronous : declare
12354 C_Ent : Entity_Id;
12355 Decl : Node_Id;
12356 Formal : Entity_Id;
12357 L : List_Id;
12358 Nm : Entity_Id;
12359 S : Node_Id;
12360
12361 procedure Process_Async_Pragma;
12362 -- Common processing for procedure and access-to-procedure case
12363
12364 --------------------------
12365 -- Process_Async_Pragma --
12366 --------------------------
12367
12368 procedure Process_Async_Pragma is
12369 begin
12370 if No (L) then
12371 Set_Is_Asynchronous (Nm);
12372 return;
12373 end if;
12374
12375 -- The formals should be of mode IN (RM E.4.1(6))
12376
12377 S := First (L);
12378 while Present (S) loop
12379 Formal := Defining_Identifier (S);
12380
12381 if Nkind (Formal) = N_Defining_Identifier
12382 and then Ekind (Formal) /= E_In_Parameter
12383 then
12384 Error_Pragma_Arg
12385 ("pragma% procedure can only have IN parameter",
12386 Arg1);
12387 end if;
12388
12389 Next (S);
12390 end loop;
12391
12392 Set_Is_Asynchronous (Nm);
12393 end Process_Async_Pragma;
12394
12395 -- Start of processing for pragma Asynchronous
12396
12397 begin
12398 Check_Ada_83_Warning;
12399 Check_No_Identifiers;
12400 Check_Arg_Count (1);
12401 Check_Arg_Is_Local_Name (Arg1);
12402
12403 if Debug_Flag_U then
12404 return;
12405 end if;
12406
12407 C_Ent := Cunit_Entity (Current_Sem_Unit);
12408 Analyze (Get_Pragma_Arg (Arg1));
12409 Nm := Entity (Get_Pragma_Arg (Arg1));
12410
12411 -- A pragma that applies to a Ghost entity becomes Ghost for the
12412 -- purposes of legality checks and removal of ignored Ghost code.
12413
12414 Mark_Ghost_Pragma (N, Nm);
12415
12416 if not Is_Remote_Call_Interface (C_Ent)
12417 and then not Is_Remote_Types (C_Ent)
12418 then
12419 -- This pragma should only appear in an RCI or Remote Types
12420 -- unit (RM E.4.1(4)).
12421
12422 Error_Pragma
12423 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
12424 end if;
12425
12426 if Ekind (Nm) = E_Procedure
12427 and then Nkind (Parent (Nm)) = N_Procedure_Specification
12428 then
12429 if not Is_Remote_Call_Interface (Nm) then
12430 Error_Pragma_Arg
12431 ("pragma% cannot be applied on non-remote procedure",
12432 Arg1);
12433 end if;
12434
12435 L := Parameter_Specifications (Parent (Nm));
12436 Process_Async_Pragma;
12437 return;
12438
12439 elsif Ekind (Nm) = E_Function then
12440 Error_Pragma_Arg
12441 ("pragma% cannot be applied to function", Arg1);
12442
12443 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
12444 if Is_Record_Type (Nm) then
12445
12446 -- A record type that is the Equivalent_Type for a remote
12447 -- access-to-subprogram type.
12448
12449 Decl := Declaration_Node (Corresponding_Remote_Type (Nm));
12450
12451 else
12452 -- A non-expanded RAS type (distribution is not enabled)
12453
12454 Decl := Declaration_Node (Nm);
12455 end if;
12456
12457 if Nkind (Decl) = N_Full_Type_Declaration
12458 and then Nkind (Type_Definition (Decl)) =
12459 N_Access_Procedure_Definition
12460 then
12461 L := Parameter_Specifications (Type_Definition (Decl));
12462 Process_Async_Pragma;
12463
12464 if Is_Asynchronous (Nm)
12465 and then Expander_Active
12466 and then Get_PCS_Name /= Name_No_DSA
12467 then
12468 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
12469 end if;
12470
12471 else
12472 Error_Pragma_Arg
12473 ("pragma% cannot reference access-to-function type",
12474 Arg1);
12475 end if;
12476
12477 -- Only other possibility is Access-to-class-wide type
12478
12479 elsif Is_Access_Type (Nm)
12480 and then Is_Class_Wide_Type (Designated_Type (Nm))
12481 then
12482 Check_First_Subtype (Arg1);
12483 Set_Is_Asynchronous (Nm);
12484 if Expander_Active then
12485 RACW_Type_Is_Asynchronous (Nm);
12486 end if;
12487
12488 else
12489 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
12490 end if;
12491 end Asynchronous;
12492
12493 ------------
12494 -- Atomic --
12495 ------------
12496
12497 -- pragma Atomic (LOCAL_NAME);
12498
12499 when Pragma_Atomic =>
12500 Process_Atomic_Independent_Shared_Volatile;
12501
12502 -----------------------
12503 -- Atomic_Components --
12504 -----------------------
12505
12506 -- pragma Atomic_Components (array_LOCAL_NAME);
12507
12508 -- This processing is shared by Volatile_Components
12509
12510 when Pragma_Atomic_Components
12511 | Pragma_Volatile_Components
12512 =>
12513 Atomic_Components : declare
12514 D : Node_Id;
12515 E : Entity_Id;
12516 E_Id : Node_Id;
12517 K : Node_Kind;
12518
12519 begin
12520 Check_Ada_83_Warning;
12521 Check_No_Identifiers;
12522 Check_Arg_Count (1);
12523 Check_Arg_Is_Local_Name (Arg1);
12524 E_Id := Get_Pragma_Arg (Arg1);
12525
12526 if Etype (E_Id) = Any_Type then
12527 return;
12528 end if;
12529
12530 E := Entity (E_Id);
12531
12532 -- A pragma that applies to a Ghost entity becomes Ghost for the
12533 -- purposes of legality checks and removal of ignored Ghost code.
12534
12535 Mark_Ghost_Pragma (N, E);
12536 Check_Duplicate_Pragma (E);
12537
12538 if Rep_Item_Too_Early (E, N)
12539 or else
12540 Rep_Item_Too_Late (E, N)
12541 then
12542 return;
12543 end if;
12544
12545 D := Declaration_Node (E);
12546 K := Nkind (D);
12547
12548 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
12549 or else
12550 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
12551 and then Nkind (D) = N_Object_Declaration
12552 and then Nkind (Object_Definition (D)) =
12553 N_Constrained_Array_Definition)
12554 then
12555 -- The flag is set on the object, or on the base type
12556
12557 if Nkind (D) /= N_Object_Declaration then
12558 E := Base_Type (E);
12559 end if;
12560
12561 -- Atomic implies both Independent and Volatile
12562
12563 if Prag_Id = Pragma_Atomic_Components then
12564 Set_Has_Atomic_Components (E);
12565 Set_Has_Independent_Components (E);
12566 end if;
12567
12568 Set_Has_Volatile_Components (E);
12569
12570 else
12571 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
12572 end if;
12573 end Atomic_Components;
12574
12575 --------------------
12576 -- Attach_Handler --
12577 --------------------
12578
12579 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
12580
12581 when Pragma_Attach_Handler =>
12582 Check_Ada_83_Warning;
12583 Check_No_Identifiers;
12584 Check_Arg_Count (2);
12585
12586 if No_Run_Time_Mode then
12587 Error_Msg_CRT ("Attach_Handler pragma", N);
12588 else
12589 Check_Interrupt_Or_Attach_Handler;
12590
12591 -- The expression that designates the attribute may depend on a
12592 -- discriminant, and is therefore a per-object expression, to
12593 -- be expanded in the init proc. If expansion is enabled, then
12594 -- perform semantic checks on a copy only.
12595
12596 declare
12597 Temp : Node_Id;
12598 Typ : Node_Id;
12599 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
12600
12601 begin
12602 -- In Relaxed_RM_Semantics mode, we allow any static
12603 -- integer value, for compatibility with other compilers.
12604
12605 if Relaxed_RM_Semantics
12606 and then Nkind (Parg2) = N_Integer_Literal
12607 then
12608 Typ := Standard_Integer;
12609 else
12610 Typ := RTE (RE_Interrupt_ID);
12611 end if;
12612
12613 if Expander_Active then
12614 Temp := New_Copy_Tree (Parg2);
12615 Set_Parent (Temp, N);
12616 Preanalyze_And_Resolve (Temp, Typ);
12617 else
12618 Analyze (Parg2);
12619 Resolve (Parg2, Typ);
12620 end if;
12621 end;
12622
12623 Process_Interrupt_Or_Attach_Handler;
12624 end if;
12625
12626 --------------------
12627 -- C_Pass_By_Copy --
12628 --------------------
12629
12630 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
12631
12632 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
12633 Arg : Node_Id;
12634 Val : Uint;
12635
12636 begin
12637 GNAT_Pragma;
12638 Check_Valid_Configuration_Pragma;
12639 Check_Arg_Count (1);
12640 Check_Optional_Identifier (Arg1, "max_size");
12641
12642 Arg := Get_Pragma_Arg (Arg1);
12643 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
12644
12645 Val := Expr_Value (Arg);
12646
12647 if Val <= 0 then
12648 Error_Pragma_Arg
12649 ("maximum size for pragma% must be positive", Arg1);
12650
12651 elsif UI_Is_In_Int_Range (Val) then
12652 Default_C_Record_Mechanism := UI_To_Int (Val);
12653
12654 -- If a giant value is given, Int'Last will do well enough.
12655 -- If sometime someone complains that a record larger than
12656 -- two gigabytes is not copied, we will worry about it then.
12657
12658 else
12659 Default_C_Record_Mechanism := Mechanism_Type'Last;
12660 end if;
12661 end C_Pass_By_Copy;
12662
12663 -----------
12664 -- Check --
12665 -----------
12666
12667 -- pragma Check ([Name =>] CHECK_KIND,
12668 -- [Check =>] Boolean_EXPRESSION
12669 -- [,[Message =>] String_EXPRESSION]);
12670
12671 -- CHECK_KIND ::= IDENTIFIER |
12672 -- Pre'Class |
12673 -- Post'Class |
12674 -- Invariant'Class |
12675 -- Type_Invariant'Class
12676
12677 -- The identifiers Assertions and Statement_Assertions are not
12678 -- allowed, since they have special meaning for Check_Policy.
12679
12680 -- WARNING: The code below manages Ghost regions. Return statements
12681 -- must be replaced by gotos which jump to the end of the code and
12682 -- restore the Ghost mode.
12683
12684 when Pragma_Check => Check : declare
12685 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
12686 -- Save the Ghost mode to restore on exit
12687
12688 Cname : Name_Id;
12689 Eloc : Source_Ptr;
12690 Expr : Node_Id;
12691 Str : Node_Id;
12692 pragma Warnings (Off, Str);
12693
12694 begin
12695 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
12696 -- the mode now to ensure that any nodes generated during analysis
12697 -- and expansion are marked as Ghost.
12698
12699 Set_Ghost_Mode (N);
12700
12701 GNAT_Pragma;
12702 Check_At_Least_N_Arguments (2);
12703 Check_At_Most_N_Arguments (3);
12704 Check_Optional_Identifier (Arg1, Name_Name);
12705 Check_Optional_Identifier (Arg2, Name_Check);
12706
12707 if Arg_Count = 3 then
12708 Check_Optional_Identifier (Arg3, Name_Message);
12709 Str := Get_Pragma_Arg (Arg3);
12710 end if;
12711
12712 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
12713 Check_Arg_Is_Identifier (Arg1);
12714 Cname := Chars (Get_Pragma_Arg (Arg1));
12715
12716 -- Check forbidden name Assertions or Statement_Assertions
12717
12718 case Cname is
12719 when Name_Assertions =>
12720 Error_Pragma_Arg
12721 ("""Assertions"" is not allowed as a check kind for "
12722 & "pragma%", Arg1);
12723
12724 when Name_Statement_Assertions =>
12725 Error_Pragma_Arg
12726 ("""Statement_Assertions"" is not allowed as a check kind "
12727 & "for pragma%", Arg1);
12728
12729 when others =>
12730 null;
12731 end case;
12732
12733 -- Check applicable policy. We skip this if Checked/Ignored status
12734 -- is already set (e.g. in the case of a pragma from an aspect).
12735
12736 if Is_Checked (N) or else Is_Ignored (N) then
12737 null;
12738
12739 -- For a non-source pragma that is a rewriting of another pragma,
12740 -- copy the Is_Checked/Ignored status from the rewritten pragma.
12741
12742 elsif Is_Rewrite_Substitution (N)
12743 and then Nkind (Original_Node (N)) = N_Pragma
12744 and then Original_Node (N) /= N
12745 then
12746 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
12747 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
12748
12749 -- Otherwise query the applicable policy at this point
12750
12751 else
12752 case Check_Kind (Cname) is
12753 when Name_Ignore =>
12754 Set_Is_Ignored (N, True);
12755 Set_Is_Checked (N, False);
12756
12757 when Name_Check =>
12758 Set_Is_Ignored (N, False);
12759 Set_Is_Checked (N, True);
12760
12761 -- For disable, rewrite pragma as null statement and skip
12762 -- rest of the analysis of the pragma.
12763
12764 when Name_Disable =>
12765 Rewrite (N, Make_Null_Statement (Loc));
12766 Analyze (N);
12767 raise Pragma_Exit;
12768
12769 -- No other possibilities
12770
12771 when others =>
12772 raise Program_Error;
12773 end case;
12774 end if;
12775
12776 -- If check kind was not Disable, then continue pragma analysis
12777
12778 Expr := Get_Pragma_Arg (Arg2);
12779
12780 -- Deal with SCO generation
12781
12782 if Is_Checked (N) and then not Split_PPC (N) then
12783 Set_SCO_Pragma_Enabled (Loc);
12784 end if;
12785
12786 -- Deal with analyzing the string argument
12787
12788 if Arg_Count = 3 then
12789
12790 -- If checks are not on we don't want any expansion (since
12791 -- such expansion would not get properly deleted) but
12792 -- we do want to analyze (to get proper references).
12793 -- The Preanalyze_And_Resolve routine does just what we want
12794
12795 if Is_Ignored (N) then
12796 Preanalyze_And_Resolve (Str, Standard_String);
12797
12798 -- Otherwise we need a proper analysis and expansion
12799
12800 else
12801 Analyze_And_Resolve (Str, Standard_String);
12802 end if;
12803 end if;
12804
12805 -- Now you might think we could just do the same with the Boolean
12806 -- expression if checks are off (and expansion is on) and then
12807 -- rewrite the check as a null statement. This would work but we
12808 -- would lose the useful warnings about an assertion being bound
12809 -- to fail even if assertions are turned off.
12810
12811 -- So instead we wrap the boolean expression in an if statement
12812 -- that looks like:
12813
12814 -- if False and then condition then
12815 -- null;
12816 -- end if;
12817
12818 -- The reason we do this rewriting during semantic analysis rather
12819 -- than as part of normal expansion is that we cannot analyze and
12820 -- expand the code for the boolean expression directly, or it may
12821 -- cause insertion of actions that would escape the attempt to
12822 -- suppress the check code.
12823
12824 -- Note that the Sloc for the if statement corresponds to the
12825 -- argument condition, not the pragma itself. The reason for
12826 -- this is that we may generate a warning if the condition is
12827 -- False at compile time, and we do not want to delete this
12828 -- warning when we delete the if statement.
12829
12830 if Expander_Active and Is_Ignored (N) then
12831 Eloc := Sloc (Expr);
12832
12833 Rewrite (N,
12834 Make_If_Statement (Eloc,
12835 Condition =>
12836 Make_And_Then (Eloc,
12837 Left_Opnd => Make_Identifier (Eloc, Name_False),
12838 Right_Opnd => Expr),
12839 Then_Statements => New_List (
12840 Make_Null_Statement (Eloc))));
12841
12842 -- Now go ahead and analyze the if statement
12843
12844 In_Assertion_Expr := In_Assertion_Expr + 1;
12845
12846 -- One rather special treatment. If we are now in Eliminated
12847 -- overflow mode, then suppress overflow checking since we do
12848 -- not want to drag in the bignum stuff if we are in Ignore
12849 -- mode anyway. This is particularly important if we are using
12850 -- a configurable run time that does not support bignum ops.
12851
12852 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
12853 declare
12854 Svo : constant Boolean :=
12855 Scope_Suppress.Suppress (Overflow_Check);
12856 begin
12857 Scope_Suppress.Overflow_Mode_Assertions := Strict;
12858 Scope_Suppress.Suppress (Overflow_Check) := True;
12859 Analyze (N);
12860 Scope_Suppress.Suppress (Overflow_Check) := Svo;
12861 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
12862 end;
12863
12864 -- Not that special case
12865
12866 else
12867 Analyze (N);
12868 end if;
12869
12870 -- All done with this check
12871
12872 In_Assertion_Expr := In_Assertion_Expr - 1;
12873
12874 -- Check is active or expansion not active. In these cases we can
12875 -- just go ahead and analyze the boolean with no worries.
12876
12877 else
12878 In_Assertion_Expr := In_Assertion_Expr + 1;
12879 Analyze_And_Resolve (Expr, Any_Boolean);
12880 In_Assertion_Expr := In_Assertion_Expr - 1;
12881 end if;
12882
12883 Restore_Ghost_Mode (Saved_GM);
12884 end Check;
12885
12886 --------------------------
12887 -- Check_Float_Overflow --
12888 --------------------------
12889
12890 -- pragma Check_Float_Overflow;
12891
12892 when Pragma_Check_Float_Overflow =>
12893 GNAT_Pragma;
12894 Check_Valid_Configuration_Pragma;
12895 Check_Arg_Count (0);
12896 Check_Float_Overflow := not Machine_Overflows_On_Target;
12897
12898 ----------------
12899 -- Check_Name --
12900 ----------------
12901
12902 -- pragma Check_Name (check_IDENTIFIER);
12903
12904 when Pragma_Check_Name =>
12905 GNAT_Pragma;
12906 Check_No_Identifiers;
12907 Check_Valid_Configuration_Pragma;
12908 Check_Arg_Count (1);
12909 Check_Arg_Is_Identifier (Arg1);
12910
12911 declare
12912 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
12913
12914 begin
12915 for J in Check_Names.First .. Check_Names.Last loop
12916 if Check_Names.Table (J) = Nam then
12917 return;
12918 end if;
12919 end loop;
12920
12921 Check_Names.Append (Nam);
12922 end;
12923
12924 ------------------
12925 -- Check_Policy --
12926 ------------------
12927
12928 -- This is the old style syntax, which is still allowed in all modes:
12929
12930 -- pragma Check_Policy ([Name =>] CHECK_KIND
12931 -- [Policy =>] POLICY_IDENTIFIER);
12932
12933 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
12934
12935 -- CHECK_KIND ::= IDENTIFIER |
12936 -- Pre'Class |
12937 -- Post'Class |
12938 -- Type_Invariant'Class |
12939 -- Invariant'Class
12940
12941 -- This is the new style syntax, compatible with Assertion_Policy
12942 -- and also allowed in all modes.
12943
12944 -- Pragma Check_Policy (
12945 -- CHECK_KIND => POLICY_IDENTIFIER
12946 -- {, CHECK_KIND => POLICY_IDENTIFIER});
12947
12948 -- Note: the identifiers Name and Policy are not allowed as
12949 -- Check_Kind values. This avoids ambiguities between the old and
12950 -- new form syntax.
12951
12952 when Pragma_Check_Policy => Check_Policy : declare
12953 Kind : Node_Id;
12954
12955 begin
12956 GNAT_Pragma;
12957 Check_At_Least_N_Arguments (1);
12958
12959 -- A Check_Policy pragma can appear either as a configuration
12960 -- pragma, or in a declarative part or a package spec (see RM
12961 -- 11.5(5) for rules for Suppress/Unsuppress which are also
12962 -- followed for Check_Policy).
12963
12964 if not Is_Configuration_Pragma then
12965 Check_Is_In_Decl_Part_Or_Package_Spec;
12966 end if;
12967
12968 -- Figure out if we have the old or new syntax. We have the
12969 -- old syntax if the first argument has no identifier, or the
12970 -- identifier is Name.
12971
12972 if Nkind (Arg1) /= N_Pragma_Argument_Association
12973 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
12974 then
12975 -- Old syntax
12976
12977 Check_Arg_Count (2);
12978 Check_Optional_Identifier (Arg1, Name_Name);
12979 Kind := Get_Pragma_Arg (Arg1);
12980 Rewrite_Assertion_Kind (Kind,
12981 From_Policy => Comes_From_Source (N));
12982 Check_Arg_Is_Identifier (Arg1);
12983
12984 -- Check forbidden check kind
12985
12986 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
12987 Error_Msg_Name_2 := Chars (Kind);
12988 Error_Pragma_Arg
12989 ("pragma% does not allow% as check name", Arg1);
12990 end if;
12991
12992 -- Check policy
12993
12994 Check_Optional_Identifier (Arg2, Name_Policy);
12995 Check_Arg_Is_One_Of
12996 (Arg2,
12997 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
12998
12999 -- And chain pragma on the Check_Policy_List for search
13000
13001 Set_Next_Pragma (N, Opt.Check_Policy_List);
13002 Opt.Check_Policy_List := N;
13003
13004 -- For the new syntax, what we do is to convert each argument to
13005 -- an old syntax equivalent. We do that because we want to chain
13006 -- old style Check_Policy pragmas for the search (we don't want
13007 -- to have to deal with multiple arguments in the search).
13008
13009 else
13010 declare
13011 Arg : Node_Id;
13012 Argx : Node_Id;
13013 LocP : Source_Ptr;
13014 New_P : Node_Id;
13015
13016 begin
13017 Arg := Arg1;
13018 while Present (Arg) loop
13019 LocP := Sloc (Arg);
13020 Argx := Get_Pragma_Arg (Arg);
13021
13022 -- Kind must be specified
13023
13024 if Nkind (Arg) /= N_Pragma_Argument_Association
13025 or else Chars (Arg) = No_Name
13026 then
13027 Error_Pragma_Arg
13028 ("missing assertion kind for pragma%", Arg);
13029 end if;
13030
13031 -- Construct equivalent old form syntax Check_Policy
13032 -- pragma and insert it to get remaining checks.
13033
13034 New_P :=
13035 Make_Pragma (LocP,
13036 Chars => Name_Check_Policy,
13037 Pragma_Argument_Associations => New_List (
13038 Make_Pragma_Argument_Association (LocP,
13039 Expression =>
13040 Make_Identifier (LocP, Chars (Arg))),
13041 Make_Pragma_Argument_Association (Sloc (Argx),
13042 Expression => Argx)));
13043
13044 Arg := Next (Arg);
13045
13046 -- For a configuration pragma, insert old form in
13047 -- the corresponding file.
13048
13049 if Is_Configuration_Pragma then
13050 Insert_After (N, New_P);
13051 Analyze (New_P);
13052
13053 else
13054 Insert_Action (N, New_P);
13055 end if;
13056 end loop;
13057
13058 -- Rewrite original Check_Policy pragma to null, since we
13059 -- have converted it into a series of old syntax pragmas.
13060
13061 Rewrite (N, Make_Null_Statement (Loc));
13062 Analyze (N);
13063 end;
13064 end if;
13065 end Check_Policy;
13066
13067 -------------
13068 -- Comment --
13069 -------------
13070
13071 -- pragma Comment (static_string_EXPRESSION)
13072
13073 -- Processing for pragma Comment shares the circuitry for pragma
13074 -- Ident. The only differences are that Ident enforces a limit of 31
13075 -- characters on its argument, and also enforces limitations on
13076 -- placement for DEC compatibility. Pragma Comment shares neither of
13077 -- these restrictions.
13078
13079 -------------------
13080 -- Common_Object --
13081 -------------------
13082
13083 -- pragma Common_Object (
13084 -- [Internal =>] LOCAL_NAME
13085 -- [, [External =>] EXTERNAL_SYMBOL]
13086 -- [, [Size =>] EXTERNAL_SYMBOL]);
13087
13088 -- Processing for this pragma is shared with Psect_Object
13089
13090 ------------------------
13091 -- Compile_Time_Error --
13092 ------------------------
13093
13094 -- pragma Compile_Time_Error
13095 -- (boolean_EXPRESSION, static_string_EXPRESSION);
13096
13097 when Pragma_Compile_Time_Error =>
13098 GNAT_Pragma;
13099 Process_Compile_Time_Warning_Or_Error;
13100
13101 --------------------------
13102 -- Compile_Time_Warning --
13103 --------------------------
13104
13105 -- pragma Compile_Time_Warning
13106 -- (boolean_EXPRESSION, static_string_EXPRESSION);
13107
13108 when Pragma_Compile_Time_Warning =>
13109 GNAT_Pragma;
13110 Process_Compile_Time_Warning_Or_Error;
13111
13112 ---------------------------
13113 -- Compiler_Unit_Warning --
13114 ---------------------------
13115
13116 -- pragma Compiler_Unit_Warning;
13117
13118 -- Historical note
13119
13120 -- Originally, we had only pragma Compiler_Unit, and it resulted in
13121 -- errors not warnings. This means that we had introduced a big extra
13122 -- inertia to compiler changes, since even if we implemented a new
13123 -- feature, and even if all versions to be used for bootstrapping
13124 -- implemented this new feature, we could not use it, since old
13125 -- compilers would give errors for using this feature in units
13126 -- having Compiler_Unit pragmas.
13127
13128 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
13129 -- problem. We no longer have any units mentioning Compiler_Unit,
13130 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
13131 -- and thus generates a warning which can be ignored. So that deals
13132 -- with the problem of old compilers not implementing the newer form
13133 -- of the pragma.
13134
13135 -- Newer compilers recognize the new pragma, but generate warning
13136 -- messages instead of errors, which again can be ignored in the
13137 -- case of an old compiler which implements a wanted new feature
13138 -- but at the time felt like warning about it for older compilers.
13139
13140 -- We retain Compiler_Unit so that new compilers can be used to build
13141 -- older run-times that use this pragma. That's an unusual case, but
13142 -- it's easy enough to handle, so why not?
13143
13144 when Pragma_Compiler_Unit
13145 | Pragma_Compiler_Unit_Warning
13146 =>
13147 GNAT_Pragma;
13148 Check_Arg_Count (0);
13149
13150 -- Only recognized in main unit
13151
13152 if Current_Sem_Unit = Main_Unit then
13153 Compiler_Unit := True;
13154 end if;
13155
13156 -----------------------------
13157 -- Complete_Representation --
13158 -----------------------------
13159
13160 -- pragma Complete_Representation;
13161
13162 when Pragma_Complete_Representation =>
13163 GNAT_Pragma;
13164 Check_Arg_Count (0);
13165
13166 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
13167 Error_Pragma
13168 ("pragma & must appear within record representation clause");
13169 end if;
13170
13171 ----------------------------
13172 -- Complex_Representation --
13173 ----------------------------
13174
13175 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
13176
13177 when Pragma_Complex_Representation => Complex_Representation : declare
13178 E_Id : Entity_Id;
13179 E : Entity_Id;
13180 Ent : Entity_Id;
13181
13182 begin
13183 GNAT_Pragma;
13184 Check_Arg_Count (1);
13185 Check_Optional_Identifier (Arg1, Name_Entity);
13186 Check_Arg_Is_Local_Name (Arg1);
13187 E_Id := Get_Pragma_Arg (Arg1);
13188
13189 if Etype (E_Id) = Any_Type then
13190 return;
13191 end if;
13192
13193 E := Entity (E_Id);
13194
13195 if not Is_Record_Type (E) then
13196 Error_Pragma_Arg
13197 ("argument for pragma% must be record type", Arg1);
13198 end if;
13199
13200 Ent := First_Entity (E);
13201
13202 if No (Ent)
13203 or else No (Next_Entity (Ent))
13204 or else Present (Next_Entity (Next_Entity (Ent)))
13205 or else not Is_Floating_Point_Type (Etype (Ent))
13206 or else Etype (Ent) /= Etype (Next_Entity (Ent))
13207 then
13208 Error_Pragma_Arg
13209 ("record for pragma% must have two fields of the same "
13210 & "floating-point type", Arg1);
13211
13212 else
13213 Set_Has_Complex_Representation (Base_Type (E));
13214
13215 -- We need to treat the type has having a non-standard
13216 -- representation, for back-end purposes, even though in
13217 -- general a complex will have the default representation
13218 -- of a record with two real components.
13219
13220 Set_Has_Non_Standard_Rep (Base_Type (E));
13221 end if;
13222 end Complex_Representation;
13223
13224 -------------------------
13225 -- Component_Alignment --
13226 -------------------------
13227
13228 -- pragma Component_Alignment (
13229 -- [Form =>] ALIGNMENT_CHOICE
13230 -- [, [Name =>] type_LOCAL_NAME]);
13231 --
13232 -- ALIGNMENT_CHOICE ::=
13233 -- Component_Size
13234 -- | Component_Size_4
13235 -- | Storage_Unit
13236 -- | Default
13237
13238 when Pragma_Component_Alignment => Component_AlignmentP : declare
13239 Args : Args_List (1 .. 2);
13240 Names : constant Name_List (1 .. 2) := (
13241 Name_Form,
13242 Name_Name);
13243
13244 Form : Node_Id renames Args (1);
13245 Name : Node_Id renames Args (2);
13246
13247 Atype : Component_Alignment_Kind;
13248 Typ : Entity_Id;
13249
13250 begin
13251 GNAT_Pragma;
13252 Gather_Associations (Names, Args);
13253
13254 if No (Form) then
13255 Error_Pragma ("missing Form argument for pragma%");
13256 end if;
13257
13258 Check_Arg_Is_Identifier (Form);
13259
13260 -- Get proper alignment, note that Default = Component_Size on all
13261 -- machines we have so far, and we want to set this value rather
13262 -- than the default value to indicate that it has been explicitly
13263 -- set (and thus will not get overridden by the default component
13264 -- alignment for the current scope)
13265
13266 if Chars (Form) = Name_Component_Size then
13267 Atype := Calign_Component_Size;
13268
13269 elsif Chars (Form) = Name_Component_Size_4 then
13270 Atype := Calign_Component_Size_4;
13271
13272 elsif Chars (Form) = Name_Default then
13273 Atype := Calign_Component_Size;
13274
13275 elsif Chars (Form) = Name_Storage_Unit then
13276 Atype := Calign_Storage_Unit;
13277
13278 else
13279 Error_Pragma_Arg
13280 ("invalid Form parameter for pragma%", Form);
13281 end if;
13282
13283 -- The pragma appears in a configuration file
13284
13285 if No (Parent (N)) then
13286 Check_Valid_Configuration_Pragma;
13287
13288 -- Capture the component alignment in a global variable when
13289 -- the pragma appears in a configuration file. Note that the
13290 -- scope stack is empty at this point and cannot be used to
13291 -- store the alignment value.
13292
13293 Configuration_Component_Alignment := Atype;
13294
13295 -- Case with no name, supplied, affects scope table entry
13296
13297 elsif No (Name) then
13298 Scope_Stack.Table
13299 (Scope_Stack.Last).Component_Alignment_Default := Atype;
13300
13301 -- Case of name supplied
13302
13303 else
13304 Check_Arg_Is_Local_Name (Name);
13305 Find_Type (Name);
13306 Typ := Entity (Name);
13307
13308 if Typ = Any_Type
13309 or else Rep_Item_Too_Early (Typ, N)
13310 then
13311 return;
13312 else
13313 Typ := Underlying_Type (Typ);
13314 end if;
13315
13316 if not Is_Record_Type (Typ)
13317 and then not Is_Array_Type (Typ)
13318 then
13319 Error_Pragma_Arg
13320 ("Name parameter of pragma% must identify record or "
13321 & "array type", Name);
13322 end if;
13323
13324 -- An explicit Component_Alignment pragma overrides an
13325 -- implicit pragma Pack, but not an explicit one.
13326
13327 if not Has_Pragma_Pack (Base_Type (Typ)) then
13328 Set_Is_Packed (Base_Type (Typ), False);
13329 Set_Component_Alignment (Base_Type (Typ), Atype);
13330 end if;
13331 end if;
13332 end Component_AlignmentP;
13333
13334 --------------------------------
13335 -- Constant_After_Elaboration --
13336 --------------------------------
13337
13338 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
13339
13340 when Pragma_Constant_After_Elaboration => Constant_After_Elaboration :
13341 declare
13342 Obj_Decl : Node_Id;
13343 Obj_Id : Entity_Id;
13344
13345 begin
13346 GNAT_Pragma;
13347 Check_No_Identifiers;
13348 Check_At_Most_N_Arguments (1);
13349
13350 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
13351
13352 -- Object declaration
13353
13354 if Nkind (Obj_Decl) = N_Object_Declaration then
13355 null;
13356
13357 -- Otherwise the pragma is associated with an illegal construct
13358
13359 else
13360 Pragma_Misplaced;
13361 return;
13362 end if;
13363
13364 Obj_Id := Defining_Entity (Obj_Decl);
13365
13366 -- The object declaration must be a library-level variable which
13367 -- is either explicitly initialized or obtains a value during the
13368 -- elaboration of a package body (SPARK RM 3.3.1).
13369
13370 if Ekind (Obj_Id) = E_Variable then
13371 if not Is_Library_Level_Entity (Obj_Id) then
13372 Error_Pragma
13373 ("pragma % must apply to a library level variable");
13374 return;
13375 end if;
13376
13377 -- Otherwise the pragma applies to a constant, which is illegal
13378
13379 else
13380 Error_Pragma ("pragma % must apply to a variable declaration");
13381 return;
13382 end if;
13383
13384 -- A pragma that applies to a Ghost entity becomes Ghost for the
13385 -- purposes of legality checks and removal of ignored Ghost code.
13386
13387 Mark_Ghost_Pragma (N, Obj_Id);
13388
13389 -- Chain the pragma on the contract for completeness
13390
13391 Add_Contract_Item (N, Obj_Id);
13392
13393 -- Analyze the Boolean expression (if any)
13394
13395 if Present (Arg1) then
13396 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
13397 end if;
13398 end Constant_After_Elaboration;
13399
13400 --------------------
13401 -- Contract_Cases --
13402 --------------------
13403
13404 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
13405
13406 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
13407
13408 -- CASE_GUARD ::= boolean_EXPRESSION | others
13409
13410 -- CONSEQUENCE ::= boolean_EXPRESSION
13411
13412 -- Characteristics:
13413
13414 -- * Analysis - The annotation undergoes initial checks to verify
13415 -- the legal placement and context. Secondary checks preanalyze the
13416 -- expressions in:
13417
13418 -- Analyze_Contract_Cases_In_Decl_Part
13419
13420 -- * Expansion - The annotation is expanded during the expansion of
13421 -- the related subprogram [body] contract as performed in:
13422
13423 -- Expand_Subprogram_Contract
13424
13425 -- * Template - The annotation utilizes the generic template of the
13426 -- related subprogram [body] when it is:
13427
13428 -- aspect on subprogram declaration
13429 -- aspect on stand alone subprogram body
13430 -- pragma on stand alone subprogram body
13431
13432 -- The annotation must prepare its own template when it is:
13433
13434 -- pragma on subprogram declaration
13435
13436 -- * Globals - Capture of global references must occur after full
13437 -- analysis.
13438
13439 -- * Instance - The annotation is instantiated automatically when
13440 -- the related generic subprogram [body] is instantiated except for
13441 -- the "pragma on subprogram declaration" case. In that scenario
13442 -- the annotation must instantiate itself.
13443
13444 when Pragma_Contract_Cases => Contract_Cases : declare
13445 Spec_Id : Entity_Id;
13446 Subp_Decl : Node_Id;
13447 Subp_Spec : Node_Id;
13448
13449 begin
13450 GNAT_Pragma;
13451 Check_No_Identifiers;
13452 Check_Arg_Count (1);
13453
13454 -- Ensure the proper placement of the pragma. Contract_Cases must
13455 -- be associated with a subprogram declaration or a body that acts
13456 -- as a spec.
13457
13458 Subp_Decl :=
13459 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
13460
13461 -- Entry
13462
13463 if Nkind (Subp_Decl) = N_Entry_Declaration then
13464 null;
13465
13466 -- Generic subprogram
13467
13468 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
13469 null;
13470
13471 -- Body acts as spec
13472
13473 elsif Nkind (Subp_Decl) = N_Subprogram_Body
13474 and then No (Corresponding_Spec (Subp_Decl))
13475 then
13476 null;
13477
13478 -- Body stub acts as spec
13479
13480 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
13481 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
13482 then
13483 null;
13484
13485 -- Subprogram
13486
13487 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
13488 Subp_Spec := Specification (Subp_Decl);
13489
13490 -- Pragma Contract_Cases is forbidden on null procedures, as
13491 -- this may lead to potential ambiguities in behavior when
13492 -- interface null procedures are involved.
13493
13494 if Nkind (Subp_Spec) = N_Procedure_Specification
13495 and then Null_Present (Subp_Spec)
13496 then
13497 Error_Msg_N (Fix_Error
13498 ("pragma % cannot apply to null procedure"), N);
13499 return;
13500 end if;
13501
13502 else
13503 Pragma_Misplaced;
13504 return;
13505 end if;
13506
13507 Spec_Id := Unique_Defining_Entity (Subp_Decl);
13508
13509 -- A pragma that applies to a Ghost entity becomes Ghost for the
13510 -- purposes of legality checks and removal of ignored Ghost code.
13511
13512 Mark_Ghost_Pragma (N, Spec_Id);
13513 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
13514
13515 -- Chain the pragma on the contract for further processing by
13516 -- Analyze_Contract_Cases_In_Decl_Part.
13517
13518 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
13519
13520 -- Fully analyze the pragma when it appears inside an entry
13521 -- or subprogram body because it cannot benefit from forward
13522 -- references.
13523
13524 if Nkind_In (Subp_Decl, N_Entry_Body,
13525 N_Subprogram_Body,
13526 N_Subprogram_Body_Stub)
13527 then
13528 -- The legality checks of pragma Contract_Cases are affected by
13529 -- the SPARK mode in effect and the volatility of the context.
13530 -- Analyze all pragmas in a specific order.
13531
13532 Analyze_If_Present (Pragma_SPARK_Mode);
13533 Analyze_If_Present (Pragma_Volatile_Function);
13534 Analyze_Contract_Cases_In_Decl_Part (N);
13535 end if;
13536 end Contract_Cases;
13537
13538 ----------------
13539 -- Controlled --
13540 ----------------
13541
13542 -- pragma Controlled (first_subtype_LOCAL_NAME);
13543
13544 when Pragma_Controlled => Controlled : declare
13545 Arg : Node_Id;
13546
13547 begin
13548 Check_No_Identifiers;
13549 Check_Arg_Count (1);
13550 Check_Arg_Is_Local_Name (Arg1);
13551 Arg := Get_Pragma_Arg (Arg1);
13552
13553 if not Is_Entity_Name (Arg)
13554 or else not Is_Access_Type (Entity (Arg))
13555 then
13556 Error_Pragma_Arg ("pragma% requires access type", Arg1);
13557 else
13558 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
13559 end if;
13560 end Controlled;
13561
13562 ----------------
13563 -- Convention --
13564 ----------------
13565
13566 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
13567 -- [Entity =>] LOCAL_NAME);
13568
13569 when Pragma_Convention => Convention : declare
13570 C : Convention_Id;
13571 E : Entity_Id;
13572 pragma Warnings (Off, C);
13573 pragma Warnings (Off, E);
13574
13575 begin
13576 Check_Arg_Order ((Name_Convention, Name_Entity));
13577 Check_Ada_83_Warning;
13578 Check_Arg_Count (2);
13579 Process_Convention (C, E);
13580
13581 -- A pragma that applies to a Ghost entity becomes Ghost for the
13582 -- purposes of legality checks and removal of ignored Ghost code.
13583
13584 Mark_Ghost_Pragma (N, E);
13585 end Convention;
13586
13587 ---------------------------
13588 -- Convention_Identifier --
13589 ---------------------------
13590
13591 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
13592 -- [Convention =>] convention_IDENTIFIER);
13593
13594 when Pragma_Convention_Identifier => Convention_Identifier : declare
13595 Idnam : Name_Id;
13596 Cname : Name_Id;
13597
13598 begin
13599 GNAT_Pragma;
13600 Check_Arg_Order ((Name_Name, Name_Convention));
13601 Check_Arg_Count (2);
13602 Check_Optional_Identifier (Arg1, Name_Name);
13603 Check_Optional_Identifier (Arg2, Name_Convention);
13604 Check_Arg_Is_Identifier (Arg1);
13605 Check_Arg_Is_Identifier (Arg2);
13606 Idnam := Chars (Get_Pragma_Arg (Arg1));
13607 Cname := Chars (Get_Pragma_Arg (Arg2));
13608
13609 if Is_Convention_Name (Cname) then
13610 Record_Convention_Identifier
13611 (Idnam, Get_Convention_Id (Cname));
13612 else
13613 Error_Pragma_Arg
13614 ("second arg for % pragma must be convention", Arg2);
13615 end if;
13616 end Convention_Identifier;
13617
13618 ---------------
13619 -- CPP_Class --
13620 ---------------
13621
13622 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
13623
13624 when Pragma_CPP_Class =>
13625 GNAT_Pragma;
13626
13627 if Warn_On_Obsolescent_Feature then
13628 Error_Msg_N
13629 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
13630 & "effect; replace it by pragma import?j?", N);
13631 end if;
13632
13633 Check_Arg_Count (1);
13634
13635 Rewrite (N,
13636 Make_Pragma (Loc,
13637 Chars => Name_Import,
13638 Pragma_Argument_Associations => New_List (
13639 Make_Pragma_Argument_Association (Loc,
13640 Expression => Make_Identifier (Loc, Name_CPP)),
13641 New_Copy (First (Pragma_Argument_Associations (N))))));
13642 Analyze (N);
13643
13644 ---------------------
13645 -- CPP_Constructor --
13646 ---------------------
13647
13648 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
13649 -- [, [External_Name =>] static_string_EXPRESSION ]
13650 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13651
13652 when Pragma_CPP_Constructor => CPP_Constructor : declare
13653 Elmt : Elmt_Id;
13654 Id : Entity_Id;
13655 Def_Id : Entity_Id;
13656 Tag_Typ : Entity_Id;
13657
13658 begin
13659 GNAT_Pragma;
13660 Check_At_Least_N_Arguments (1);
13661 Check_At_Most_N_Arguments (3);
13662 Check_Optional_Identifier (Arg1, Name_Entity);
13663 Check_Arg_Is_Local_Name (Arg1);
13664
13665 Id := Get_Pragma_Arg (Arg1);
13666 Find_Program_Unit_Name (Id);
13667
13668 -- If we did not find the name, we are done
13669
13670 if Etype (Id) = Any_Type then
13671 return;
13672 end if;
13673
13674 Def_Id := Entity (Id);
13675
13676 -- Check if already defined as constructor
13677
13678 if Is_Constructor (Def_Id) then
13679 Error_Msg_N
13680 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
13681 return;
13682 end if;
13683
13684 if Ekind (Def_Id) = E_Function
13685 and then (Is_CPP_Class (Etype (Def_Id))
13686 or else (Is_Class_Wide_Type (Etype (Def_Id))
13687 and then
13688 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
13689 then
13690 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
13691 Error_Msg_N
13692 ("'C'P'P constructor must be defined in the scope of "
13693 & "its returned type", Arg1);
13694 end if;
13695
13696 if Arg_Count >= 2 then
13697 Set_Imported (Def_Id);
13698 Set_Is_Public (Def_Id);
13699 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
13700 end if;
13701
13702 Set_Has_Completion (Def_Id);
13703 Set_Is_Constructor (Def_Id);
13704 Set_Convention (Def_Id, Convention_CPP);
13705
13706 -- Imported C++ constructors are not dispatching primitives
13707 -- because in C++ they don't have a dispatch table slot.
13708 -- However, in Ada the constructor has the profile of a
13709 -- function that returns a tagged type and therefore it has
13710 -- been treated as a primitive operation during semantic
13711 -- analysis. We now remove it from the list of primitive
13712 -- operations of the type.
13713
13714 if Is_Tagged_Type (Etype (Def_Id))
13715 and then not Is_Class_Wide_Type (Etype (Def_Id))
13716 and then Is_Dispatching_Operation (Def_Id)
13717 then
13718 Tag_Typ := Etype (Def_Id);
13719
13720 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
13721 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
13722 Next_Elmt (Elmt);
13723 end loop;
13724
13725 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
13726 Set_Is_Dispatching_Operation (Def_Id, False);
13727 end if;
13728
13729 -- For backward compatibility, if the constructor returns a
13730 -- class wide type, and we internally change the return type to
13731 -- the corresponding root type.
13732
13733 if Is_Class_Wide_Type (Etype (Def_Id)) then
13734 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
13735 end if;
13736 else
13737 Error_Pragma_Arg
13738 ("pragma% requires function returning a 'C'P'P_Class type",
13739 Arg1);
13740 end if;
13741 end CPP_Constructor;
13742
13743 -----------------
13744 -- CPP_Virtual --
13745 -----------------
13746
13747 when Pragma_CPP_Virtual =>
13748 GNAT_Pragma;
13749
13750 if Warn_On_Obsolescent_Feature then
13751 Error_Msg_N
13752 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
13753 & "effect?j?", N);
13754 end if;
13755
13756 ----------------
13757 -- CPP_Vtable --
13758 ----------------
13759
13760 when Pragma_CPP_Vtable =>
13761 GNAT_Pragma;
13762
13763 if Warn_On_Obsolescent_Feature then
13764 Error_Msg_N
13765 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
13766 & "effect?j?", N);
13767 end if;
13768
13769 ---------
13770 -- CPU --
13771 ---------
13772
13773 -- pragma CPU (EXPRESSION);
13774
13775 when Pragma_CPU => CPU : declare
13776 P : constant Node_Id := Parent (N);
13777 Arg : Node_Id;
13778 Ent : Entity_Id;
13779
13780 begin
13781 Ada_2012_Pragma;
13782 Check_No_Identifiers;
13783 Check_Arg_Count (1);
13784
13785 -- Subprogram case
13786
13787 if Nkind (P) = N_Subprogram_Body then
13788 Check_In_Main_Program;
13789
13790 Arg := Get_Pragma_Arg (Arg1);
13791 Analyze_And_Resolve (Arg, Any_Integer);
13792
13793 Ent := Defining_Unit_Name (Specification (P));
13794
13795 if Nkind (Ent) = N_Defining_Program_Unit_Name then
13796 Ent := Defining_Identifier (Ent);
13797 end if;
13798
13799 -- Must be static
13800
13801 if not Is_OK_Static_Expression (Arg) then
13802 Flag_Non_Static_Expr
13803 ("main subprogram affinity is not static!", Arg);
13804 raise Pragma_Exit;
13805
13806 -- If constraint error, then we already signalled an error
13807
13808 elsif Raises_Constraint_Error (Arg) then
13809 null;
13810
13811 -- Otherwise check in range
13812
13813 else
13814 declare
13815 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
13816 -- This is the entity System.Multiprocessors.CPU_Range;
13817
13818 Val : constant Uint := Expr_Value (Arg);
13819
13820 begin
13821 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
13822 or else
13823 Val > Expr_Value (Type_High_Bound (CPU_Id))
13824 then
13825 Error_Pragma_Arg
13826 ("main subprogram CPU is out of range", Arg1);
13827 end if;
13828 end;
13829 end if;
13830
13831 Set_Main_CPU
13832 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
13833
13834 -- Task case
13835
13836 elsif Nkind (P) = N_Task_Definition then
13837 Arg := Get_Pragma_Arg (Arg1);
13838 Ent := Defining_Identifier (Parent (P));
13839
13840 -- The expression must be analyzed in the special manner
13841 -- described in "Handling of Default and Per-Object
13842 -- Expressions" in sem.ads.
13843
13844 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
13845
13846 -- Anything else is incorrect
13847
13848 else
13849 Pragma_Misplaced;
13850 end if;
13851
13852 -- Check duplicate pragma before we chain the pragma in the Rep
13853 -- Item chain of Ent.
13854
13855 Check_Duplicate_Pragma (Ent);
13856 Record_Rep_Item (Ent, N);
13857 end CPU;
13858
13859 --------------------
13860 -- Deadline_Floor --
13861 --------------------
13862
13863 -- pragma Deadline_Floor (time_span_EXPRESSION);
13864
13865 when Pragma_Deadline_Floor => Deadline_Floor : declare
13866 P : constant Node_Id := Parent (N);
13867 Arg : Node_Id;
13868 Ent : Entity_Id;
13869
13870 begin
13871 GNAT_Pragma;
13872 Check_No_Identifiers;
13873 Check_Arg_Count (1);
13874
13875 Arg := Get_Pragma_Arg (Arg1);
13876
13877 -- The expression must be analyzed in the special manner described
13878 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
13879
13880 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
13881
13882 -- Only protected types allowed
13883
13884 if Nkind (P) /= N_Protected_Definition then
13885 Pragma_Misplaced;
13886
13887 else
13888 Ent := Defining_Identifier (Parent (P));
13889
13890 -- Check duplicate pragma before we chain the pragma in the Rep
13891 -- Item chain of Ent.
13892
13893 Check_Duplicate_Pragma (Ent);
13894 Record_Rep_Item (Ent, N);
13895 end if;
13896 end Deadline_Floor;
13897
13898 -----------
13899 -- Debug --
13900 -----------
13901
13902 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
13903
13904 when Pragma_Debug => Debug : declare
13905 Cond : Node_Id;
13906 Call : Node_Id;
13907
13908 begin
13909 GNAT_Pragma;
13910
13911 -- The condition for executing the call is that the expander
13912 -- is active and that we are not ignoring this debug pragma.
13913
13914 Cond :=
13915 New_Occurrence_Of
13916 (Boolean_Literals
13917 (Expander_Active and then not Is_Ignored (N)),
13918 Loc);
13919
13920 if not Is_Ignored (N) then
13921 Set_SCO_Pragma_Enabled (Loc);
13922 end if;
13923
13924 if Arg_Count = 2 then
13925 Cond :=
13926 Make_And_Then (Loc,
13927 Left_Opnd => Relocate_Node (Cond),
13928 Right_Opnd => Get_Pragma_Arg (Arg1));
13929 Call := Get_Pragma_Arg (Arg2);
13930 else
13931 Call := Get_Pragma_Arg (Arg1);
13932 end if;
13933
13934 if Nkind_In (Call,
13935 N_Indexed_Component,
13936 N_Function_Call,
13937 N_Identifier,
13938 N_Expanded_Name,
13939 N_Selected_Component)
13940 then
13941 -- If this pragma Debug comes from source, its argument was
13942 -- parsed as a name form (which is syntactically identical).
13943 -- In a generic context a parameterless call will be left as
13944 -- an expanded name (if global) or selected_component if local.
13945 -- Change it to a procedure call statement now.
13946
13947 Change_Name_To_Procedure_Call_Statement (Call);
13948
13949 elsif Nkind (Call) = N_Procedure_Call_Statement then
13950
13951 -- Already in the form of a procedure call statement: nothing
13952 -- to do (could happen in case of an internally generated
13953 -- pragma Debug).
13954
13955 null;
13956
13957 else
13958 -- All other cases: diagnose error
13959
13960 Error_Msg
13961 ("argument of pragma ""Debug"" is not procedure call",
13962 Sloc (Call));
13963 return;
13964 end if;
13965
13966 -- Rewrite into a conditional with an appropriate condition. We
13967 -- wrap the procedure call in a block so that overhead from e.g.
13968 -- use of the secondary stack does not generate execution overhead
13969 -- for suppressed conditions.
13970
13971 -- Normally the analysis that follows will freeze the subprogram
13972 -- being called. However, if the call is to a null procedure,
13973 -- we want to freeze it before creating the block, because the
13974 -- analysis that follows may be done with expansion disabled, in
13975 -- which case the body will not be generated, leading to spurious
13976 -- errors.
13977
13978 if Nkind (Call) = N_Procedure_Call_Statement
13979 and then Is_Entity_Name (Name (Call))
13980 then
13981 Analyze (Name (Call));
13982 Freeze_Before (N, Entity (Name (Call)));
13983 end if;
13984
13985 Rewrite (N,
13986 Make_Implicit_If_Statement (N,
13987 Condition => Cond,
13988 Then_Statements => New_List (
13989 Make_Block_Statement (Loc,
13990 Handled_Statement_Sequence =>
13991 Make_Handled_Sequence_Of_Statements (Loc,
13992 Statements => New_List (Relocate_Node (Call)))))));
13993 Analyze (N);
13994
13995 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
13996 -- after analysis of the normally rewritten node, to capture all
13997 -- references to entities, which avoids issuing wrong warnings
13998 -- about unused entities.
13999
14000 if GNATprove_Mode then
14001 Rewrite (N, Make_Null_Statement (Loc));
14002 end if;
14003 end Debug;
14004
14005 ------------------
14006 -- Debug_Policy --
14007 ------------------
14008
14009 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
14010
14011 when Pragma_Debug_Policy =>
14012 GNAT_Pragma;
14013 Check_Arg_Count (1);
14014 Check_No_Identifiers;
14015 Check_Arg_Is_Identifier (Arg1);
14016
14017 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
14018 -- rewrite it that way, and let the rest of the checking come
14019 -- from analyzing the rewritten pragma.
14020
14021 Rewrite (N,
14022 Make_Pragma (Loc,
14023 Chars => Name_Check_Policy,
14024 Pragma_Argument_Associations => New_List (
14025 Make_Pragma_Argument_Association (Loc,
14026 Expression => Make_Identifier (Loc, Name_Debug)),
14027
14028 Make_Pragma_Argument_Association (Loc,
14029 Expression => Get_Pragma_Arg (Arg1)))));
14030 Analyze (N);
14031
14032 -------------------------------
14033 -- Default_Initial_Condition --
14034 -------------------------------
14035
14036 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
14037
14038 when Pragma_Default_Initial_Condition => DIC : declare
14039 Discard : Boolean;
14040 Stmt : Node_Id;
14041 Typ : Entity_Id;
14042
14043 begin
14044 GNAT_Pragma;
14045 Check_No_Identifiers;
14046 Check_At_Most_N_Arguments (1);
14047
14048 Typ := Empty;
14049 Stmt := Prev (N);
14050 while Present (Stmt) loop
14051
14052 -- Skip prior pragmas, but check for duplicates
14053
14054 if Nkind (Stmt) = N_Pragma then
14055 if Pragma_Name (Stmt) = Pname then
14056 Duplication_Error
14057 (Prag => N,
14058 Prev => Stmt);
14059 raise Pragma_Exit;
14060 end if;
14061
14062 -- Skip internally generated code. Note that derived type
14063 -- declarations of untagged types with discriminants are
14064 -- rewritten as private type declarations.
14065
14066 elsif not Comes_From_Source (Stmt)
14067 and then Nkind (Stmt) /= N_Private_Type_Declaration
14068 then
14069 null;
14070
14071 -- The associated private type [extension] has been found, stop
14072 -- the search.
14073
14074 elsif Nkind_In (Stmt, N_Private_Extension_Declaration,
14075 N_Private_Type_Declaration)
14076 then
14077 Typ := Defining_Entity (Stmt);
14078 exit;
14079
14080 -- The pragma does not apply to a legal construct, issue an
14081 -- error and stop the analysis.
14082
14083 else
14084 Pragma_Misplaced;
14085 return;
14086 end if;
14087
14088 Stmt := Prev (Stmt);
14089 end loop;
14090
14091 -- The pragma does not apply to a legal construct, issue an error
14092 -- and stop the analysis.
14093
14094 if No (Typ) then
14095 Pragma_Misplaced;
14096 return;
14097 end if;
14098
14099 -- A pragma that applies to a Ghost entity becomes Ghost for the
14100 -- purposes of legality checks and removal of ignored Ghost code.
14101
14102 Mark_Ghost_Pragma (N, Typ);
14103
14104 -- The pragma signals that the type defines its own DIC assertion
14105 -- expression.
14106
14107 Set_Has_Own_DIC (Typ);
14108
14109 -- Chain the pragma on the rep item chain for further processing
14110
14111 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
14112
14113 -- Create the declaration of the procedure which verifies the
14114 -- assertion expression of pragma DIC at runtime.
14115
14116 Build_DIC_Procedure_Declaration (Typ);
14117 end DIC;
14118
14119 ----------------------------------
14120 -- Default_Scalar_Storage_Order --
14121 ----------------------------------
14122
14123 -- pragma Default_Scalar_Storage_Order
14124 -- (High_Order_First | Low_Order_First);
14125
14126 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
14127 Default : Character;
14128
14129 begin
14130 GNAT_Pragma;
14131 Check_Arg_Count (1);
14132
14133 -- Default_Scalar_Storage_Order can appear as a configuration
14134 -- pragma, or in a declarative part of a package spec.
14135
14136 if not Is_Configuration_Pragma then
14137 Check_Is_In_Decl_Part_Or_Package_Spec;
14138 end if;
14139
14140 Check_No_Identifiers;
14141 Check_Arg_Is_One_Of
14142 (Arg1, Name_High_Order_First, Name_Low_Order_First);
14143 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14144 Default := Fold_Upper (Name_Buffer (1));
14145
14146 if not Support_Nondefault_SSO_On_Target
14147 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
14148 then
14149 if Warn_On_Unrecognized_Pragma then
14150 Error_Msg_N
14151 ("non-default Scalar_Storage_Order not supported "
14152 & "on target?g?", N);
14153 Error_Msg_N
14154 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
14155 end if;
14156
14157 -- Here set the specified default
14158
14159 else
14160 Opt.Default_SSO := Default;
14161 end if;
14162 end DSSO;
14163
14164 --------------------------
14165 -- Default_Storage_Pool --
14166 --------------------------
14167
14168 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
14169
14170 when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
14171 Pool : Node_Id;
14172
14173 begin
14174 Ada_2012_Pragma;
14175 Check_Arg_Count (1);
14176
14177 -- Default_Storage_Pool can appear as a configuration pragma, or
14178 -- in a declarative part of a package spec.
14179
14180 if not Is_Configuration_Pragma then
14181 Check_Is_In_Decl_Part_Or_Package_Spec;
14182 end if;
14183
14184 if From_Aspect_Specification (N) then
14185 declare
14186 E : constant Entity_Id := Entity (Corresponding_Aspect (N));
14187 begin
14188 if not In_Open_Scopes (E) then
14189 Error_Msg_N
14190 ("aspect must apply to package or subprogram", N);
14191 end if;
14192 end;
14193 end if;
14194
14195 if Present (Arg1) then
14196 Pool := Get_Pragma_Arg (Arg1);
14197
14198 -- Case of Default_Storage_Pool (null);
14199
14200 if Nkind (Pool) = N_Null then
14201 Analyze (Pool);
14202
14203 -- This is an odd case, this is not really an expression,
14204 -- so we don't have a type for it. So just set the type to
14205 -- Empty.
14206
14207 Set_Etype (Pool, Empty);
14208
14209 -- Case of Default_Storage_Pool (storage_pool_NAME);
14210
14211 else
14212 -- If it's a configuration pragma, then the only allowed
14213 -- argument is "null".
14214
14215 if Is_Configuration_Pragma then
14216 Error_Pragma_Arg ("NULL expected", Arg1);
14217 end if;
14218
14219 -- The expected type for a non-"null" argument is
14220 -- Root_Storage_Pool'Class, and the pool must be a variable.
14221
14222 Analyze_And_Resolve
14223 (Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
14224
14225 if Is_Variable (Pool) then
14226
14227 -- A pragma that applies to a Ghost entity becomes Ghost
14228 -- for the purposes of legality checks and removal of
14229 -- ignored Ghost code.
14230
14231 Mark_Ghost_Pragma (N, Entity (Pool));
14232
14233 else
14234 Error_Pragma_Arg
14235 ("default storage pool must be a variable", Arg1);
14236 end if;
14237 end if;
14238
14239 -- Record the pool name (or null). Freeze.Freeze_Entity for an
14240 -- access type will use this information to set the appropriate
14241 -- attributes of the access type.
14242
14243 Default_Pool := Pool;
14244 end if;
14245 end Default_Storage_Pool;
14246
14247 -------------
14248 -- Depends --
14249 -------------
14250
14251 -- pragma Depends (DEPENDENCY_RELATION);
14252
14253 -- DEPENDENCY_RELATION ::=
14254 -- null
14255 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
14256
14257 -- DEPENDENCY_CLAUSE ::=
14258 -- OUTPUT_LIST =>[+] INPUT_LIST
14259 -- | NULL_DEPENDENCY_CLAUSE
14260
14261 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
14262
14263 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
14264
14265 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
14266
14267 -- OUTPUT ::= NAME | FUNCTION_RESULT
14268 -- INPUT ::= NAME
14269
14270 -- where FUNCTION_RESULT is a function Result attribute_reference
14271
14272 -- Characteristics:
14273
14274 -- * Analysis - The annotation undergoes initial checks to verify
14275 -- the legal placement and context. Secondary checks fully analyze
14276 -- the dependency clauses in:
14277
14278 -- Analyze_Depends_In_Decl_Part
14279
14280 -- * Expansion - None.
14281
14282 -- * Template - The annotation utilizes the generic template of the
14283 -- related subprogram [body] when it is:
14284
14285 -- aspect on subprogram declaration
14286 -- aspect on stand alone subprogram body
14287 -- pragma on stand alone subprogram body
14288
14289 -- The annotation must prepare its own template when it is:
14290
14291 -- pragma on subprogram declaration
14292
14293 -- * Globals - Capture of global references must occur after full
14294 -- analysis.
14295
14296 -- * Instance - The annotation is instantiated automatically when
14297 -- the related generic subprogram [body] is instantiated except for
14298 -- the "pragma on subprogram declaration" case. In that scenario
14299 -- the annotation must instantiate itself.
14300
14301 when Pragma_Depends => Depends : declare
14302 Legal : Boolean;
14303 Spec_Id : Entity_Id;
14304 Subp_Decl : Node_Id;
14305
14306 begin
14307 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
14308
14309 if Legal then
14310
14311 -- Chain the pragma on the contract for further processing by
14312 -- Analyze_Depends_In_Decl_Part.
14313
14314 Add_Contract_Item (N, Spec_Id);
14315
14316 -- Fully analyze the pragma when it appears inside an entry
14317 -- or subprogram body because it cannot benefit from forward
14318 -- references.
14319
14320 if Nkind_In (Subp_Decl, N_Entry_Body,
14321 N_Subprogram_Body,
14322 N_Subprogram_Body_Stub)
14323 then
14324 -- The legality checks of pragmas Depends and Global are
14325 -- affected by the SPARK mode in effect and the volatility
14326 -- of the context. In addition these two pragmas are subject
14327 -- to an inherent order:
14328
14329 -- 1) Global
14330 -- 2) Depends
14331
14332 -- Analyze all these pragmas in the order outlined above
14333
14334 Analyze_If_Present (Pragma_SPARK_Mode);
14335 Analyze_If_Present (Pragma_Volatile_Function);
14336 Analyze_If_Present (Pragma_Global);
14337 Analyze_Depends_In_Decl_Part (N);
14338 end if;
14339 end if;
14340 end Depends;
14341
14342 ---------------------
14343 -- Detect_Blocking --
14344 ---------------------
14345
14346 -- pragma Detect_Blocking;
14347
14348 when Pragma_Detect_Blocking =>
14349 Ada_2005_Pragma;
14350 Check_Arg_Count (0);
14351 Check_Valid_Configuration_Pragma;
14352 Detect_Blocking := True;
14353
14354 ------------------------------------
14355 -- Disable_Atomic_Synchronization --
14356 ------------------------------------
14357
14358 -- pragma Disable_Atomic_Synchronization [(Entity)];
14359
14360 when Pragma_Disable_Atomic_Synchronization =>
14361 GNAT_Pragma;
14362 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
14363
14364 -------------------
14365 -- Discard_Names --
14366 -------------------
14367
14368 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
14369
14370 when Pragma_Discard_Names => Discard_Names : declare
14371 E : Entity_Id;
14372 E_Id : Node_Id;
14373
14374 begin
14375 Check_Ada_83_Warning;
14376
14377 -- Deal with configuration pragma case
14378
14379 if Arg_Count = 0 and then Is_Configuration_Pragma then
14380 Global_Discard_Names := True;
14381 return;
14382
14383 -- Otherwise, check correct appropriate context
14384
14385 else
14386 Check_Is_In_Decl_Part_Or_Package_Spec;
14387
14388 if Arg_Count = 0 then
14389
14390 -- If there is no parameter, then from now on this pragma
14391 -- applies to any enumeration, exception or tagged type
14392 -- defined in the current declarative part, and recursively
14393 -- to any nested scope.
14394
14395 Set_Discard_Names (Current_Scope);
14396 return;
14397
14398 else
14399 Check_Arg_Count (1);
14400 Check_Optional_Identifier (Arg1, Name_On);
14401 Check_Arg_Is_Local_Name (Arg1);
14402
14403 E_Id := Get_Pragma_Arg (Arg1);
14404
14405 if Etype (E_Id) = Any_Type then
14406 return;
14407 end if;
14408
14409 E := Entity (E_Id);
14410
14411 -- A pragma that applies to a Ghost entity becomes Ghost for
14412 -- the purposes of legality checks and removal of ignored
14413 -- Ghost code.
14414
14415 Mark_Ghost_Pragma (N, E);
14416
14417 if (Is_First_Subtype (E)
14418 and then
14419 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
14420 or else Ekind (E) = E_Exception
14421 then
14422 Set_Discard_Names (E);
14423 Record_Rep_Item (E, N);
14424
14425 else
14426 Error_Pragma_Arg
14427 ("inappropriate entity for pragma%", Arg1);
14428 end if;
14429 end if;
14430 end if;
14431 end Discard_Names;
14432
14433 ------------------------
14434 -- Dispatching_Domain --
14435 ------------------------
14436
14437 -- pragma Dispatching_Domain (EXPRESSION);
14438
14439 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
14440 P : constant Node_Id := Parent (N);
14441 Arg : Node_Id;
14442 Ent : Entity_Id;
14443
14444 begin
14445 Ada_2012_Pragma;
14446 Check_No_Identifiers;
14447 Check_Arg_Count (1);
14448
14449 -- This pragma is born obsolete, but not the aspect
14450
14451 if not From_Aspect_Specification (N) then
14452 Check_Restriction
14453 (No_Obsolescent_Features, Pragma_Identifier (N));
14454 end if;
14455
14456 if Nkind (P) = N_Task_Definition then
14457 Arg := Get_Pragma_Arg (Arg1);
14458 Ent := Defining_Identifier (Parent (P));
14459
14460 -- A pragma that applies to a Ghost entity becomes Ghost for
14461 -- the purposes of legality checks and removal of ignored Ghost
14462 -- code.
14463
14464 Mark_Ghost_Pragma (N, Ent);
14465
14466 -- The expression must be analyzed in the special manner
14467 -- described in "Handling of Default and Per-Object
14468 -- Expressions" in sem.ads.
14469
14470 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
14471
14472 -- Check duplicate pragma before we chain the pragma in the Rep
14473 -- Item chain of Ent.
14474
14475 Check_Duplicate_Pragma (Ent);
14476 Record_Rep_Item (Ent, N);
14477
14478 -- Anything else is incorrect
14479
14480 else
14481 Pragma_Misplaced;
14482 end if;
14483 end Dispatching_Domain;
14484
14485 ---------------
14486 -- Elaborate --
14487 ---------------
14488
14489 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
14490
14491 when Pragma_Elaborate => Elaborate : declare
14492 Arg : Node_Id;
14493 Citem : Node_Id;
14494
14495 begin
14496 -- Pragma must be in context items list of a compilation unit
14497
14498 if not Is_In_Context_Clause then
14499 Pragma_Misplaced;
14500 end if;
14501
14502 -- Must be at least one argument
14503
14504 if Arg_Count = 0 then
14505 Error_Pragma ("pragma% requires at least one argument");
14506 end if;
14507
14508 -- In Ada 83 mode, there can be no items following it in the
14509 -- context list except other pragmas and implicit with clauses
14510 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
14511 -- placement rule does not apply.
14512
14513 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
14514 Citem := Next (N);
14515 while Present (Citem) loop
14516 if Nkind (Citem) = N_Pragma
14517 or else (Nkind (Citem) = N_With_Clause
14518 and then Implicit_With (Citem))
14519 then
14520 null;
14521 else
14522 Error_Pragma
14523 ("(Ada 83) pragma% must be at end of context clause");
14524 end if;
14525
14526 Next (Citem);
14527 end loop;
14528 end if;
14529
14530 -- Finally, the arguments must all be units mentioned in a with
14531 -- clause in the same context clause. Note we already checked (in
14532 -- Par.Prag) that the arguments are all identifiers or selected
14533 -- components.
14534
14535 Arg := Arg1;
14536 Outer : while Present (Arg) loop
14537 Citem := First (List_Containing (N));
14538 Inner : while Citem /= N loop
14539 if Nkind (Citem) = N_With_Clause
14540 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
14541 then
14542 Set_Elaborate_Present (Citem, True);
14543 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
14544
14545 -- With the pragma present, elaboration calls on
14546 -- subprograms from the named unit need no further
14547 -- checks, as long as the pragma appears in the current
14548 -- compilation unit. If the pragma appears in some unit
14549 -- in the context, there might still be a need for an
14550 -- Elaborate_All_Desirable from the current compilation
14551 -- to the named unit, so we keep the check enabled.
14552
14553 if In_Extended_Main_Source_Unit (N) then
14554
14555 -- This does not apply in SPARK mode, where we allow
14556 -- pragma Elaborate, but we don't trust it to be right
14557 -- so we will still insist on the Elaborate_All.
14558
14559 if SPARK_Mode /= On then
14560 Set_Suppress_Elaboration_Warnings
14561 (Entity (Name (Citem)));
14562 end if;
14563 end if;
14564
14565 exit Inner;
14566 end if;
14567
14568 Next (Citem);
14569 end loop Inner;
14570
14571 if Citem = N then
14572 Error_Pragma_Arg
14573 ("argument of pragma% is not withed unit", Arg);
14574 end if;
14575
14576 Next (Arg);
14577 end loop Outer;
14578
14579 -- Give a warning if operating in static mode with one of the
14580 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
14581
14582 if Elab_Warnings
14583 and not Dynamic_Elaboration_Checks
14584
14585 -- pragma Elaborate not allowed in SPARK mode anyway. We
14586 -- already complained about it, no point in generating any
14587 -- further complaint.
14588
14589 and SPARK_Mode /= On
14590 then
14591 Error_Msg_N
14592 ("?l?use of pragma Elaborate may not be safe", N);
14593 Error_Msg_N
14594 ("?l?use pragma Elaborate_All instead if possible", N);
14595 end if;
14596 end Elaborate;
14597
14598 -------------------
14599 -- Elaborate_All --
14600 -------------------
14601
14602 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
14603
14604 when Pragma_Elaborate_All => Elaborate_All : declare
14605 Arg : Node_Id;
14606 Citem : Node_Id;
14607
14608 begin
14609 Check_Ada_83_Warning;
14610
14611 -- Pragma must be in context items list of a compilation unit
14612
14613 if not Is_In_Context_Clause then
14614 Pragma_Misplaced;
14615 end if;
14616
14617 -- Must be at least one argument
14618
14619 if Arg_Count = 0 then
14620 Error_Pragma ("pragma% requires at least one argument");
14621 end if;
14622
14623 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
14624 -- have to appear at the end of the context clause, but may
14625 -- appear mixed in with other items, even in Ada 83 mode.
14626
14627 -- Final check: the arguments must all be units mentioned in
14628 -- a with clause in the same context clause. Note that we
14629 -- already checked (in Par.Prag) that all the arguments are
14630 -- either identifiers or selected components.
14631
14632 Arg := Arg1;
14633 Outr : while Present (Arg) loop
14634 Citem := First (List_Containing (N));
14635 Innr : while Citem /= N loop
14636 if Nkind (Citem) = N_With_Clause
14637 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
14638 then
14639 Set_Elaborate_All_Present (Citem, True);
14640 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
14641
14642 -- Suppress warnings and elaboration checks on the named
14643 -- unit if the pragma is in the current compilation, as
14644 -- for pragma Elaborate.
14645
14646 if In_Extended_Main_Source_Unit (N) then
14647 Set_Suppress_Elaboration_Warnings
14648 (Entity (Name (Citem)));
14649 end if;
14650 exit Innr;
14651 end if;
14652
14653 Next (Citem);
14654 end loop Innr;
14655
14656 if Citem = N then
14657 Set_Error_Posted (N);
14658 Error_Pragma_Arg
14659 ("argument of pragma% is not withed unit", Arg);
14660 end if;
14661
14662 Next (Arg);
14663 end loop Outr;
14664 end Elaborate_All;
14665
14666 --------------------
14667 -- Elaborate_Body --
14668 --------------------
14669
14670 -- pragma Elaborate_Body [( library_unit_NAME )];
14671
14672 when Pragma_Elaborate_Body => Elaborate_Body : declare
14673 Cunit_Node : Node_Id;
14674 Cunit_Ent : Entity_Id;
14675
14676 begin
14677 Check_Ada_83_Warning;
14678 Check_Valid_Library_Unit_Pragma;
14679
14680 if Nkind (N) = N_Null_Statement then
14681 return;
14682 end if;
14683
14684 Cunit_Node := Cunit (Current_Sem_Unit);
14685 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14686
14687 -- A pragma that applies to a Ghost entity becomes Ghost for the
14688 -- purposes of legality checks and removal of ignored Ghost code.
14689
14690 Mark_Ghost_Pragma (N, Cunit_Ent);
14691
14692 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
14693 N_Subprogram_Body)
14694 then
14695 Error_Pragma ("pragma% must refer to a spec, not a body");
14696 else
14697 Set_Body_Required (Cunit_Node, True);
14698 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
14699
14700 -- If we are in dynamic elaboration mode, then we suppress
14701 -- elaboration warnings for the unit, since it is definitely
14702 -- fine NOT to do dynamic checks at the first level (and such
14703 -- checks will be suppressed because no elaboration boolean
14704 -- is created for Elaborate_Body packages).
14705
14706 -- But in the static model of elaboration, Elaborate_Body is
14707 -- definitely NOT good enough to ensure elaboration safety on
14708 -- its own, since the body may WITH other units that are not
14709 -- safe from an elaboration point of view, so a client must
14710 -- still do an Elaborate_All on such units.
14711
14712 -- Debug flag -gnatdD restores the old behavior of 3.13, where
14713 -- Elaborate_Body always suppressed elab warnings.
14714
14715 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
14716 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
14717 end if;
14718 end if;
14719 end Elaborate_Body;
14720
14721 ------------------------
14722 -- Elaboration_Checks --
14723 ------------------------
14724
14725 -- pragma Elaboration_Checks (Static | Dynamic);
14726
14727 when Pragma_Elaboration_Checks =>
14728 GNAT_Pragma;
14729 Check_Arg_Count (1);
14730 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
14731
14732 -- Set flag accordingly (ignore attempt at dynamic elaboration
14733 -- checks in SPARK mode).
14734
14735 Dynamic_Elaboration_Checks :=
14736 Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic;
14737
14738 ---------------
14739 -- Eliminate --
14740 ---------------
14741
14742 -- pragma Eliminate (
14743 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
14744 -- [Entity =>] IDENTIFIER |
14745 -- SELECTED_COMPONENT |
14746 -- STRING_LITERAL]
14747 -- [, Source_Location => SOURCE_TRACE]);
14748
14749 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
14750 -- SOURCE_TRACE ::= STRING_LITERAL
14751
14752 when Pragma_Eliminate => Eliminate : declare
14753 Args : Args_List (1 .. 5);
14754 Names : constant Name_List (1 .. 5) := (
14755 Name_Unit_Name,
14756 Name_Entity,
14757 Name_Parameter_Types,
14758 Name_Result_Type,
14759 Name_Source_Location);
14760
14761 -- Note : Parameter_Types and Result_Type are leftovers from
14762 -- prior implementations of the pragma. They are not generated
14763 -- by the gnatelim tool, and play no role in selecting which
14764 -- of a set of overloaded names is chosen for elimination.
14765
14766 Unit_Name : Node_Id renames Args (1);
14767 Entity : Node_Id renames Args (2);
14768 Parameter_Types : Node_Id renames Args (3);
14769 Result_Type : Node_Id renames Args (4);
14770 Source_Location : Node_Id renames Args (5);
14771
14772 begin
14773 GNAT_Pragma;
14774 Check_Valid_Configuration_Pragma;
14775 Gather_Associations (Names, Args);
14776
14777 if No (Unit_Name) then
14778 Error_Pragma ("missing Unit_Name argument for pragma%");
14779 end if;
14780
14781 if No (Entity)
14782 and then (Present (Parameter_Types)
14783 or else
14784 Present (Result_Type)
14785 or else
14786 Present (Source_Location))
14787 then
14788 Error_Pragma ("missing Entity argument for pragma%");
14789 end if;
14790
14791 if (Present (Parameter_Types)
14792 or else
14793 Present (Result_Type))
14794 and then
14795 Present (Source_Location)
14796 then
14797 Error_Pragma
14798 ("parameter profile and source location cannot be used "
14799 & "together in pragma%");
14800 end if;
14801
14802 Process_Eliminate_Pragma
14803 (N,
14804 Unit_Name,
14805 Entity,
14806 Parameter_Types,
14807 Result_Type,
14808 Source_Location);
14809 end Eliminate;
14810
14811 -----------------------------------
14812 -- Enable_Atomic_Synchronization --
14813 -----------------------------------
14814
14815 -- pragma Enable_Atomic_Synchronization [(Entity)];
14816
14817 when Pragma_Enable_Atomic_Synchronization =>
14818 GNAT_Pragma;
14819 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
14820
14821 ------------
14822 -- Export --
14823 ------------
14824
14825 -- pragma Export (
14826 -- [ Convention =>] convention_IDENTIFIER,
14827 -- [ Entity =>] LOCAL_NAME
14828 -- [, [External_Name =>] static_string_EXPRESSION ]
14829 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14830
14831 when Pragma_Export => Export : declare
14832 C : Convention_Id;
14833 Def_Id : Entity_Id;
14834
14835 pragma Warnings (Off, C);
14836
14837 begin
14838 Check_Ada_83_Warning;
14839 Check_Arg_Order
14840 ((Name_Convention,
14841 Name_Entity,
14842 Name_External_Name,
14843 Name_Link_Name));
14844
14845 Check_At_Least_N_Arguments (2);
14846 Check_At_Most_N_Arguments (4);
14847
14848 -- In Relaxed_RM_Semantics, support old Ada 83 style:
14849 -- pragma Export (Entity, "external name");
14850
14851 if Relaxed_RM_Semantics
14852 and then Arg_Count = 2
14853 and then Nkind (Expression (Arg2)) = N_String_Literal
14854 then
14855 C := Convention_C;
14856 Def_Id := Get_Pragma_Arg (Arg1);
14857 Analyze (Def_Id);
14858
14859 if not Is_Entity_Name (Def_Id) then
14860 Error_Pragma_Arg ("entity name required", Arg1);
14861 end if;
14862
14863 Def_Id := Entity (Def_Id);
14864 Set_Exported (Def_Id, Arg1);
14865
14866 else
14867 Process_Convention (C, Def_Id);
14868
14869 -- A pragma that applies to a Ghost entity becomes Ghost for
14870 -- the purposes of legality checks and removal of ignored Ghost
14871 -- code.
14872
14873 Mark_Ghost_Pragma (N, Def_Id);
14874
14875 if Ekind (Def_Id) /= E_Constant then
14876 Note_Possible_Modification
14877 (Get_Pragma_Arg (Arg2), Sure => False);
14878 end if;
14879
14880 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
14881 Set_Exported (Def_Id, Arg2);
14882 end if;
14883
14884 -- If the entity is a deferred constant, propagate the information
14885 -- to the full view, because gigi elaborates the full view only.
14886
14887 if Ekind (Def_Id) = E_Constant
14888 and then Present (Full_View (Def_Id))
14889 then
14890 declare
14891 Id2 : constant Entity_Id := Full_View (Def_Id);
14892 begin
14893 Set_Is_Exported (Id2, Is_Exported (Def_Id));
14894 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
14895 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
14896 end;
14897 end if;
14898 end Export;
14899
14900 ---------------------
14901 -- Export_Function --
14902 ---------------------
14903
14904 -- pragma Export_Function (
14905 -- [Internal =>] LOCAL_NAME
14906 -- [, [External =>] EXTERNAL_SYMBOL]
14907 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14908 -- [, [Result_Type =>] TYPE_DESIGNATOR]
14909 -- [, [Mechanism =>] MECHANISM]
14910 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
14911
14912 -- EXTERNAL_SYMBOL ::=
14913 -- IDENTIFIER
14914 -- | static_string_EXPRESSION
14915
14916 -- PARAMETER_TYPES ::=
14917 -- null
14918 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14919
14920 -- TYPE_DESIGNATOR ::=
14921 -- subtype_NAME
14922 -- | subtype_Name ' Access
14923
14924 -- MECHANISM ::=
14925 -- MECHANISM_NAME
14926 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14927
14928 -- MECHANISM_ASSOCIATION ::=
14929 -- [formal_parameter_NAME =>] MECHANISM_NAME
14930
14931 -- MECHANISM_NAME ::=
14932 -- Value
14933 -- | Reference
14934
14935 when Pragma_Export_Function => Export_Function : declare
14936 Args : Args_List (1 .. 6);
14937 Names : constant Name_List (1 .. 6) := (
14938 Name_Internal,
14939 Name_External,
14940 Name_Parameter_Types,
14941 Name_Result_Type,
14942 Name_Mechanism,
14943 Name_Result_Mechanism);
14944
14945 Internal : Node_Id renames Args (1);
14946 External : Node_Id renames Args (2);
14947 Parameter_Types : Node_Id renames Args (3);
14948 Result_Type : Node_Id renames Args (4);
14949 Mechanism : Node_Id renames Args (5);
14950 Result_Mechanism : Node_Id renames Args (6);
14951
14952 begin
14953 GNAT_Pragma;
14954 Gather_Associations (Names, Args);
14955 Process_Extended_Import_Export_Subprogram_Pragma (
14956 Arg_Internal => Internal,
14957 Arg_External => External,
14958 Arg_Parameter_Types => Parameter_Types,
14959 Arg_Result_Type => Result_Type,
14960 Arg_Mechanism => Mechanism,
14961 Arg_Result_Mechanism => Result_Mechanism);
14962 end Export_Function;
14963
14964 -------------------
14965 -- Export_Object --
14966 -------------------
14967
14968 -- pragma Export_Object (
14969 -- [Internal =>] LOCAL_NAME
14970 -- [, [External =>] EXTERNAL_SYMBOL]
14971 -- [, [Size =>] EXTERNAL_SYMBOL]);
14972
14973 -- EXTERNAL_SYMBOL ::=
14974 -- IDENTIFIER
14975 -- | static_string_EXPRESSION
14976
14977 -- PARAMETER_TYPES ::=
14978 -- null
14979 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14980
14981 -- TYPE_DESIGNATOR ::=
14982 -- subtype_NAME
14983 -- | subtype_Name ' Access
14984
14985 -- MECHANISM ::=
14986 -- MECHANISM_NAME
14987 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14988
14989 -- MECHANISM_ASSOCIATION ::=
14990 -- [formal_parameter_NAME =>] MECHANISM_NAME
14991
14992 -- MECHANISM_NAME ::=
14993 -- Value
14994 -- | Reference
14995
14996 when Pragma_Export_Object => Export_Object : declare
14997 Args : Args_List (1 .. 3);
14998 Names : constant Name_List (1 .. 3) := (
14999 Name_Internal,
15000 Name_External,
15001 Name_Size);
15002
15003 Internal : Node_Id renames Args (1);
15004 External : Node_Id renames Args (2);
15005 Size : Node_Id renames Args (3);
15006
15007 begin
15008 GNAT_Pragma;
15009 Gather_Associations (Names, Args);
15010 Process_Extended_Import_Export_Object_Pragma (
15011 Arg_Internal => Internal,
15012 Arg_External => External,
15013 Arg_Size => Size);
15014 end Export_Object;
15015
15016 ----------------------
15017 -- Export_Procedure --
15018 ----------------------
15019
15020 -- pragma Export_Procedure (
15021 -- [Internal =>] LOCAL_NAME
15022 -- [, [External =>] EXTERNAL_SYMBOL]
15023 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15024 -- [, [Mechanism =>] MECHANISM]);
15025
15026 -- EXTERNAL_SYMBOL ::=
15027 -- IDENTIFIER
15028 -- | static_string_EXPRESSION
15029
15030 -- PARAMETER_TYPES ::=
15031 -- null
15032 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15033
15034 -- TYPE_DESIGNATOR ::=
15035 -- subtype_NAME
15036 -- | subtype_Name ' Access
15037
15038 -- MECHANISM ::=
15039 -- MECHANISM_NAME
15040 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15041
15042 -- MECHANISM_ASSOCIATION ::=
15043 -- [formal_parameter_NAME =>] MECHANISM_NAME
15044
15045 -- MECHANISM_NAME ::=
15046 -- Value
15047 -- | Reference
15048
15049 when Pragma_Export_Procedure => Export_Procedure : declare
15050 Args : Args_List (1 .. 4);
15051 Names : constant Name_List (1 .. 4) := (
15052 Name_Internal,
15053 Name_External,
15054 Name_Parameter_Types,
15055 Name_Mechanism);
15056
15057 Internal : Node_Id renames Args (1);
15058 External : Node_Id renames Args (2);
15059 Parameter_Types : Node_Id renames Args (3);
15060 Mechanism : Node_Id renames Args (4);
15061
15062 begin
15063 GNAT_Pragma;
15064 Gather_Associations (Names, Args);
15065 Process_Extended_Import_Export_Subprogram_Pragma (
15066 Arg_Internal => Internal,
15067 Arg_External => External,
15068 Arg_Parameter_Types => Parameter_Types,
15069 Arg_Mechanism => Mechanism);
15070 end Export_Procedure;
15071
15072 ------------------
15073 -- Export_Value --
15074 ------------------
15075
15076 -- pragma Export_Value (
15077 -- [Value =>] static_integer_EXPRESSION,
15078 -- [Link_Name =>] static_string_EXPRESSION);
15079
15080 when Pragma_Export_Value =>
15081 GNAT_Pragma;
15082 Check_Arg_Order ((Name_Value, Name_Link_Name));
15083 Check_Arg_Count (2);
15084
15085 Check_Optional_Identifier (Arg1, Name_Value);
15086 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
15087
15088 Check_Optional_Identifier (Arg2, Name_Link_Name);
15089 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
15090
15091 -----------------------------
15092 -- Export_Valued_Procedure --
15093 -----------------------------
15094
15095 -- pragma Export_Valued_Procedure (
15096 -- [Internal =>] LOCAL_NAME
15097 -- [, [External =>] EXTERNAL_SYMBOL,]
15098 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15099 -- [, [Mechanism =>] MECHANISM]);
15100
15101 -- EXTERNAL_SYMBOL ::=
15102 -- IDENTIFIER
15103 -- | static_string_EXPRESSION
15104
15105 -- PARAMETER_TYPES ::=
15106 -- null
15107 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15108
15109 -- TYPE_DESIGNATOR ::=
15110 -- subtype_NAME
15111 -- | subtype_Name ' Access
15112
15113 -- MECHANISM ::=
15114 -- MECHANISM_NAME
15115 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15116
15117 -- MECHANISM_ASSOCIATION ::=
15118 -- [formal_parameter_NAME =>] MECHANISM_NAME
15119
15120 -- MECHANISM_NAME ::=
15121 -- Value
15122 -- | Reference
15123
15124 when Pragma_Export_Valued_Procedure =>
15125 Export_Valued_Procedure : declare
15126 Args : Args_List (1 .. 4);
15127 Names : constant Name_List (1 .. 4) := (
15128 Name_Internal,
15129 Name_External,
15130 Name_Parameter_Types,
15131 Name_Mechanism);
15132
15133 Internal : Node_Id renames Args (1);
15134 External : Node_Id renames Args (2);
15135 Parameter_Types : Node_Id renames Args (3);
15136 Mechanism : Node_Id renames Args (4);
15137
15138 begin
15139 GNAT_Pragma;
15140 Gather_Associations (Names, Args);
15141 Process_Extended_Import_Export_Subprogram_Pragma (
15142 Arg_Internal => Internal,
15143 Arg_External => External,
15144 Arg_Parameter_Types => Parameter_Types,
15145 Arg_Mechanism => Mechanism);
15146 end Export_Valued_Procedure;
15147
15148 -------------------
15149 -- Extend_System --
15150 -------------------
15151
15152 -- pragma Extend_System ([Name =>] Identifier);
15153
15154 when Pragma_Extend_System =>
15155 GNAT_Pragma;
15156 Check_Valid_Configuration_Pragma;
15157 Check_Arg_Count (1);
15158 Check_Optional_Identifier (Arg1, Name_Name);
15159 Check_Arg_Is_Identifier (Arg1);
15160
15161 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15162
15163 if Name_Len > 4
15164 and then Name_Buffer (1 .. 4) = "aux_"
15165 then
15166 if Present (System_Extend_Pragma_Arg) then
15167 if Chars (Get_Pragma_Arg (Arg1)) =
15168 Chars (Expression (System_Extend_Pragma_Arg))
15169 then
15170 null;
15171 else
15172 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
15173 Error_Pragma ("pragma% conflicts with that #");
15174 end if;
15175
15176 else
15177 System_Extend_Pragma_Arg := Arg1;
15178
15179 if not GNAT_Mode then
15180 System_Extend_Unit := Arg1;
15181 end if;
15182 end if;
15183 else
15184 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
15185 end if;
15186
15187 ------------------------
15188 -- Extensions_Allowed --
15189 ------------------------
15190
15191 -- pragma Extensions_Allowed (ON | OFF);
15192
15193 when Pragma_Extensions_Allowed =>
15194 GNAT_Pragma;
15195 Check_Arg_Count (1);
15196 Check_No_Identifiers;
15197 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
15198
15199 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
15200 Extensions_Allowed := True;
15201 Ada_Version := Ada_Version_Type'Last;
15202
15203 else
15204 Extensions_Allowed := False;
15205 Ada_Version := Ada_Version_Explicit;
15206 Ada_Version_Pragma := Empty;
15207 end if;
15208
15209 ------------------------
15210 -- Extensions_Visible --
15211 ------------------------
15212
15213 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
15214
15215 -- Characteristics:
15216
15217 -- * Analysis - The annotation is fully analyzed immediately upon
15218 -- elaboration as its expression must be static.
15219
15220 -- * Expansion - None.
15221
15222 -- * Template - The annotation utilizes the generic template of the
15223 -- related subprogram [body] when it is:
15224
15225 -- aspect on subprogram declaration
15226 -- aspect on stand alone subprogram body
15227 -- pragma on stand alone subprogram body
15228
15229 -- The annotation must prepare its own template when it is:
15230
15231 -- pragma on subprogram declaration
15232
15233 -- * Globals - Capture of global references must occur after full
15234 -- analysis.
15235
15236 -- * Instance - The annotation is instantiated automatically when
15237 -- the related generic subprogram [body] is instantiated except for
15238 -- the "pragma on subprogram declaration" case. In that scenario
15239 -- the annotation must instantiate itself.
15240
15241 when Pragma_Extensions_Visible => Extensions_Visible : declare
15242 Formal : Entity_Id;
15243 Has_OK_Formal : Boolean := False;
15244 Spec_Id : Entity_Id;
15245 Subp_Decl : Node_Id;
15246
15247 begin
15248 GNAT_Pragma;
15249 Check_No_Identifiers;
15250 Check_At_Most_N_Arguments (1);
15251
15252 Subp_Decl :=
15253 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
15254
15255 -- Abstract subprogram declaration
15256
15257 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
15258 null;
15259
15260 -- Generic subprogram declaration
15261
15262 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
15263 null;
15264
15265 -- Body acts as spec
15266
15267 elsif Nkind (Subp_Decl) = N_Subprogram_Body
15268 and then No (Corresponding_Spec (Subp_Decl))
15269 then
15270 null;
15271
15272 -- Body stub acts as spec
15273
15274 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
15275 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
15276 then
15277 null;
15278
15279 -- Subprogram declaration
15280
15281 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
15282 null;
15283
15284 -- Otherwise the pragma is associated with an illegal construct
15285
15286 else
15287 Error_Pragma ("pragma % must apply to a subprogram");
15288 return;
15289 end if;
15290
15291 -- Mark the pragma as Ghost if the related subprogram is also
15292 -- Ghost. This also ensures that any expansion performed further
15293 -- below will produce Ghost nodes.
15294
15295 Spec_Id := Unique_Defining_Entity (Subp_Decl);
15296 Mark_Ghost_Pragma (N, Spec_Id);
15297
15298 -- Chain the pragma on the contract for completeness
15299
15300 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
15301
15302 -- The legality checks of pragma Extension_Visible are affected
15303 -- by the SPARK mode in effect. Analyze all pragmas in specific
15304 -- order.
15305
15306 Analyze_If_Present (Pragma_SPARK_Mode);
15307
15308 -- Examine the formals of the related subprogram
15309
15310 Formal := First_Formal (Spec_Id);
15311 while Present (Formal) loop
15312
15313 -- At least one of the formals is of a specific tagged type,
15314 -- the pragma is legal.
15315
15316 if Is_Specific_Tagged_Type (Etype (Formal)) then
15317 Has_OK_Formal := True;
15318 exit;
15319
15320 -- A generic subprogram with at least one formal of a private
15321 -- type ensures the legality of the pragma because the actual
15322 -- may be specifically tagged. Note that this is verified by
15323 -- the check above at instantiation time.
15324
15325 elsif Is_Private_Type (Etype (Formal))
15326 and then Is_Generic_Type (Etype (Formal))
15327 then
15328 Has_OK_Formal := True;
15329 exit;
15330 end if;
15331
15332 Next_Formal (Formal);
15333 end loop;
15334
15335 if not Has_OK_Formal then
15336 Error_Msg_Name_1 := Pname;
15337 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
15338 Error_Msg_NE
15339 ("\subprogram & lacks parameter of specific tagged or "
15340 & "generic private type", N, Spec_Id);
15341
15342 return;
15343 end if;
15344
15345 -- Analyze the Boolean expression (if any)
15346
15347 if Present (Arg1) then
15348 Check_Static_Boolean_Expression
15349 (Expression (Get_Argument (N, Spec_Id)));
15350 end if;
15351 end Extensions_Visible;
15352
15353 --------------
15354 -- External --
15355 --------------
15356
15357 -- pragma External (
15358 -- [ Convention =>] convention_IDENTIFIER,
15359 -- [ Entity =>] LOCAL_NAME
15360 -- [, [External_Name =>] static_string_EXPRESSION ]
15361 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15362
15363 when Pragma_External => External : declare
15364 C : Convention_Id;
15365 E : Entity_Id;
15366 pragma Warnings (Off, C);
15367
15368 begin
15369 GNAT_Pragma;
15370 Check_Arg_Order
15371 ((Name_Convention,
15372 Name_Entity,
15373 Name_External_Name,
15374 Name_Link_Name));
15375 Check_At_Least_N_Arguments (2);
15376 Check_At_Most_N_Arguments (4);
15377 Process_Convention (C, E);
15378
15379 -- A pragma that applies to a Ghost entity becomes Ghost for the
15380 -- purposes of legality checks and removal of ignored Ghost code.
15381
15382 Mark_Ghost_Pragma (N, E);
15383
15384 Note_Possible_Modification
15385 (Get_Pragma_Arg (Arg2), Sure => False);
15386 Process_Interface_Name (E, Arg3, Arg4, N);
15387 Set_Exported (E, Arg2);
15388 end External;
15389
15390 --------------------------
15391 -- External_Name_Casing --
15392 --------------------------
15393
15394 -- pragma External_Name_Casing (
15395 -- UPPERCASE | LOWERCASE
15396 -- [, AS_IS | UPPERCASE | LOWERCASE]);
15397
15398 when Pragma_External_Name_Casing =>
15399 GNAT_Pragma;
15400 Check_No_Identifiers;
15401
15402 if Arg_Count = 2 then
15403 Check_Arg_Is_One_Of
15404 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
15405
15406 case Chars (Get_Pragma_Arg (Arg2)) is
15407 when Name_As_Is =>
15408 Opt.External_Name_Exp_Casing := As_Is;
15409
15410 when Name_Uppercase =>
15411 Opt.External_Name_Exp_Casing := Uppercase;
15412
15413 when Name_Lowercase =>
15414 Opt.External_Name_Exp_Casing := Lowercase;
15415
15416 when others =>
15417 null;
15418 end case;
15419
15420 else
15421 Check_Arg_Count (1);
15422 end if;
15423
15424 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
15425
15426 case Chars (Get_Pragma_Arg (Arg1)) is
15427 when Name_Uppercase =>
15428 Opt.External_Name_Imp_Casing := Uppercase;
15429
15430 when Name_Lowercase =>
15431 Opt.External_Name_Imp_Casing := Lowercase;
15432
15433 when others =>
15434 null;
15435 end case;
15436
15437 ---------------
15438 -- Fast_Math --
15439 ---------------
15440
15441 -- pragma Fast_Math;
15442
15443 when Pragma_Fast_Math =>
15444 GNAT_Pragma;
15445 Check_No_Identifiers;
15446 Check_Valid_Configuration_Pragma;
15447 Fast_Math := True;
15448
15449 --------------------------
15450 -- Favor_Top_Level --
15451 --------------------------
15452
15453 -- pragma Favor_Top_Level (type_NAME);
15454
15455 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
15456 Typ : Entity_Id;
15457
15458 begin
15459 GNAT_Pragma;
15460 Check_No_Identifiers;
15461 Check_Arg_Count (1);
15462 Check_Arg_Is_Local_Name (Arg1);
15463 Typ := Entity (Get_Pragma_Arg (Arg1));
15464
15465 -- A pragma that applies to a Ghost entity becomes Ghost for the
15466 -- purposes of legality checks and removal of ignored Ghost code.
15467
15468 Mark_Ghost_Pragma (N, Typ);
15469
15470 -- If it's an access-to-subprogram type (in particular, not a
15471 -- subtype), set the flag on that type.
15472
15473 if Is_Access_Subprogram_Type (Typ) then
15474 Set_Can_Use_Internal_Rep (Typ, False);
15475
15476 -- Otherwise it's an error (name denotes the wrong sort of entity)
15477
15478 else
15479 Error_Pragma_Arg
15480 ("access-to-subprogram type expected",
15481 Get_Pragma_Arg (Arg1));
15482 end if;
15483 end Favor_Top_Level;
15484
15485 ---------------------------
15486 -- Finalize_Storage_Only --
15487 ---------------------------
15488
15489 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
15490
15491 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
15492 Assoc : constant Node_Id := Arg1;
15493 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
15494 Typ : Entity_Id;
15495
15496 begin
15497 GNAT_Pragma;
15498 Check_No_Identifiers;
15499 Check_Arg_Count (1);
15500 Check_Arg_Is_Local_Name (Arg1);
15501
15502 Find_Type (Type_Id);
15503 Typ := Entity (Type_Id);
15504
15505 if Typ = Any_Type
15506 or else Rep_Item_Too_Early (Typ, N)
15507 then
15508 return;
15509 else
15510 Typ := Underlying_Type (Typ);
15511 end if;
15512
15513 if not Is_Controlled (Typ) then
15514 Error_Pragma ("pragma% must specify controlled type");
15515 end if;
15516
15517 Check_First_Subtype (Arg1);
15518
15519 if Finalize_Storage_Only (Typ) then
15520 Error_Pragma ("duplicate pragma%, only one allowed");
15521
15522 elsif not Rep_Item_Too_Late (Typ, N) then
15523 Set_Finalize_Storage_Only (Base_Type (Typ), True);
15524 end if;
15525 end Finalize_Storage;
15526
15527 -----------
15528 -- Ghost --
15529 -----------
15530
15531 -- pragma Ghost [ (boolean_EXPRESSION) ];
15532
15533 when Pragma_Ghost => Ghost : declare
15534 Context : Node_Id;
15535 Expr : Node_Id;
15536 Id : Entity_Id;
15537 Orig_Stmt : Node_Id;
15538 Prev_Id : Entity_Id;
15539 Stmt : Node_Id;
15540
15541 begin
15542 GNAT_Pragma;
15543 Check_No_Identifiers;
15544 Check_At_Most_N_Arguments (1);
15545
15546 Id := Empty;
15547 Stmt := Prev (N);
15548 while Present (Stmt) loop
15549
15550 -- Skip prior pragmas, but check for duplicates
15551
15552 if Nkind (Stmt) = N_Pragma then
15553 if Pragma_Name (Stmt) = Pname then
15554 Duplication_Error
15555 (Prag => N,
15556 Prev => Stmt);
15557 raise Pragma_Exit;
15558 end if;
15559
15560 -- Task unit declared without a definition cannot be subject to
15561 -- pragma Ghost (SPARK RM 6.9(19)).
15562
15563 elsif Nkind_In (Stmt, N_Single_Task_Declaration,
15564 N_Task_Type_Declaration)
15565 then
15566 Error_Pragma ("pragma % cannot apply to a task type");
15567 return;
15568
15569 -- Skip internally generated code
15570
15571 elsif not Comes_From_Source (Stmt) then
15572 Orig_Stmt := Original_Node (Stmt);
15573
15574 -- When pragma Ghost applies to an untagged derivation, the
15575 -- derivation is transformed into a [sub]type declaration.
15576
15577 if Nkind_In (Stmt, N_Full_Type_Declaration,
15578 N_Subtype_Declaration)
15579 and then Comes_From_Source (Orig_Stmt)
15580 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
15581 and then Nkind (Type_Definition (Orig_Stmt)) =
15582 N_Derived_Type_Definition
15583 then
15584 Id := Defining_Entity (Stmt);
15585 exit;
15586
15587 -- When pragma Ghost applies to an object declaration which
15588 -- is initialized by means of a function call that returns
15589 -- on the secondary stack, the object declaration becomes a
15590 -- renaming.
15591
15592 elsif Nkind (Stmt) = N_Object_Renaming_Declaration
15593 and then Comes_From_Source (Orig_Stmt)
15594 and then Nkind (Orig_Stmt) = N_Object_Declaration
15595 then
15596 Id := Defining_Entity (Stmt);
15597 exit;
15598
15599 -- When pragma Ghost applies to an expression function, the
15600 -- expression function is transformed into a subprogram.
15601
15602 elsif Nkind (Stmt) = N_Subprogram_Declaration
15603 and then Comes_From_Source (Orig_Stmt)
15604 and then Nkind (Orig_Stmt) = N_Expression_Function
15605 then
15606 Id := Defining_Entity (Stmt);
15607 exit;
15608 end if;
15609
15610 -- The pragma applies to a legal construct, stop the traversal
15611
15612 elsif Nkind_In (Stmt, N_Abstract_Subprogram_Declaration,
15613 N_Full_Type_Declaration,
15614 N_Generic_Subprogram_Declaration,
15615 N_Object_Declaration,
15616 N_Private_Extension_Declaration,
15617 N_Private_Type_Declaration,
15618 N_Subprogram_Declaration,
15619 N_Subtype_Declaration)
15620 then
15621 Id := Defining_Entity (Stmt);
15622 exit;
15623
15624 -- The pragma does not apply to a legal construct, issue an
15625 -- error and stop the analysis.
15626
15627 else
15628 Error_Pragma
15629 ("pragma % must apply to an object, package, subprogram "
15630 & "or type");
15631 return;
15632 end if;
15633
15634 Stmt := Prev (Stmt);
15635 end loop;
15636
15637 Context := Parent (N);
15638
15639 -- Handle compilation units
15640
15641 if Nkind (Context) = N_Compilation_Unit_Aux then
15642 Context := Unit (Parent (Context));
15643 end if;
15644
15645 -- Protected and task types cannot be subject to pragma Ghost
15646 -- (SPARK RM 6.9(19)).
15647
15648 if Nkind_In (Context, N_Protected_Body, N_Protected_Definition)
15649 then
15650 Error_Pragma ("pragma % cannot apply to a protected type");
15651 return;
15652
15653 elsif Nkind_In (Context, N_Task_Body, N_Task_Definition) then
15654 Error_Pragma ("pragma % cannot apply to a task type");
15655 return;
15656 end if;
15657
15658 if No (Id) then
15659
15660 -- When pragma Ghost is associated with a [generic] package, it
15661 -- appears in the visible declarations.
15662
15663 if Nkind (Context) = N_Package_Specification
15664 and then Present (Visible_Declarations (Context))
15665 and then List_Containing (N) = Visible_Declarations (Context)
15666 then
15667 Id := Defining_Entity (Context);
15668
15669 -- Pragma Ghost applies to a stand alone subprogram body
15670
15671 elsif Nkind (Context) = N_Subprogram_Body
15672 and then No (Corresponding_Spec (Context))
15673 then
15674 Id := Defining_Entity (Context);
15675
15676 -- Pragma Ghost applies to a subprogram declaration that acts
15677 -- as a compilation unit.
15678
15679 elsif Nkind (Context) = N_Subprogram_Declaration then
15680 Id := Defining_Entity (Context);
15681 end if;
15682 end if;
15683
15684 if No (Id) then
15685 Error_Pragma
15686 ("pragma % must apply to an object, package, subprogram or "
15687 & "type");
15688 return;
15689 end if;
15690
15691 -- Handle completions of types and constants that are subject to
15692 -- pragma Ghost.
15693
15694 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
15695 Prev_Id := Incomplete_Or_Partial_View (Id);
15696
15697 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
15698 Error_Msg_Name_1 := Pname;
15699
15700 -- The full declaration of a deferred constant cannot be
15701 -- subject to pragma Ghost unless the deferred declaration
15702 -- is also Ghost (SPARK RM 6.9(9)).
15703
15704 if Ekind (Prev_Id) = E_Constant then
15705 Error_Msg_Name_1 := Pname;
15706 Error_Msg_NE (Fix_Error
15707 ("pragma % must apply to declaration of deferred "
15708 & "constant &"), N, Id);
15709 return;
15710
15711 -- Pragma Ghost may appear on the full view of an incomplete
15712 -- type because the incomplete declaration lacks aspects and
15713 -- cannot be subject to pragma Ghost.
15714
15715 elsif Ekind (Prev_Id) = E_Incomplete_Type then
15716 null;
15717
15718 -- The full declaration of a type cannot be subject to
15719 -- pragma Ghost unless the partial view is also Ghost
15720 -- (SPARK RM 6.9(9)).
15721
15722 else
15723 Error_Msg_NE (Fix_Error
15724 ("pragma % must apply to partial view of type &"),
15725 N, Id);
15726 return;
15727 end if;
15728 end if;
15729
15730 -- A synchronized object cannot be subject to pragma Ghost
15731 -- (SPARK RM 6.9(19)).
15732
15733 elsif Ekind (Id) = E_Variable then
15734 if Is_Protected_Type (Etype (Id)) then
15735 Error_Pragma ("pragma % cannot apply to a protected object");
15736 return;
15737
15738 elsif Is_Task_Type (Etype (Id)) then
15739 Error_Pragma ("pragma % cannot apply to a task object");
15740 return;
15741 end if;
15742 end if;
15743
15744 -- Analyze the Boolean expression (if any)
15745
15746 if Present (Arg1) then
15747 Expr := Get_Pragma_Arg (Arg1);
15748
15749 Analyze_And_Resolve (Expr, Standard_Boolean);
15750
15751 if Is_OK_Static_Expression (Expr) then
15752
15753 -- "Ghostness" cannot be turned off once enabled within a
15754 -- region (SPARK RM 6.9(6)).
15755
15756 if Is_False (Expr_Value (Expr))
15757 and then Ghost_Mode > None
15758 then
15759 Error_Pragma
15760 ("pragma % with value False cannot appear in enabled "
15761 & "ghost region");
15762 return;
15763 end if;
15764
15765 -- Otherwie the expression is not static
15766
15767 else
15768 Error_Pragma_Arg
15769 ("expression of pragma % must be static", Expr);
15770 return;
15771 end if;
15772 end if;
15773
15774 Set_Is_Ghost_Entity (Id);
15775 end Ghost;
15776
15777 ------------
15778 -- Global --
15779 ------------
15780
15781 -- pragma Global (GLOBAL_SPECIFICATION);
15782
15783 -- GLOBAL_SPECIFICATION ::=
15784 -- null
15785 -- | (GLOBAL_LIST)
15786 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
15787
15788 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
15789
15790 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
15791 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
15792 -- GLOBAL_ITEM ::= NAME
15793
15794 -- Characteristics:
15795
15796 -- * Analysis - The annotation undergoes initial checks to verify
15797 -- the legal placement and context. Secondary checks fully analyze
15798 -- the dependency clauses in:
15799
15800 -- Analyze_Global_In_Decl_Part
15801
15802 -- * Expansion - None.
15803
15804 -- * Template - The annotation utilizes the generic template of the
15805 -- related subprogram [body] when it is:
15806
15807 -- aspect on subprogram declaration
15808 -- aspect on stand alone subprogram body
15809 -- pragma on stand alone subprogram body
15810
15811 -- The annotation must prepare its own template when it is:
15812
15813 -- pragma on subprogram declaration
15814
15815 -- * Globals - Capture of global references must occur after full
15816 -- analysis.
15817
15818 -- * Instance - The annotation is instantiated automatically when
15819 -- the related generic subprogram [body] is instantiated except for
15820 -- the "pragma on subprogram declaration" case. In that scenario
15821 -- the annotation must instantiate itself.
15822
15823 when Pragma_Global => Global : declare
15824 Legal : Boolean;
15825 Spec_Id : Entity_Id;
15826 Subp_Decl : Node_Id;
15827
15828 begin
15829 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
15830
15831 if Legal then
15832
15833 -- Chain the pragma on the contract for further processing by
15834 -- Analyze_Global_In_Decl_Part.
15835
15836 Add_Contract_Item (N, Spec_Id);
15837
15838 -- Fully analyze the pragma when it appears inside an entry
15839 -- or subprogram body because it cannot benefit from forward
15840 -- references.
15841
15842 if Nkind_In (Subp_Decl, N_Entry_Body,
15843 N_Subprogram_Body,
15844 N_Subprogram_Body_Stub)
15845 then
15846 -- The legality checks of pragmas Depends and Global are
15847 -- affected by the SPARK mode in effect and the volatility
15848 -- of the context. In addition these two pragmas are subject
15849 -- to an inherent order:
15850
15851 -- 1) Global
15852 -- 2) Depends
15853
15854 -- Analyze all these pragmas in the order outlined above
15855
15856 Analyze_If_Present (Pragma_SPARK_Mode);
15857 Analyze_If_Present (Pragma_Volatile_Function);
15858 Analyze_Global_In_Decl_Part (N);
15859 Analyze_If_Present (Pragma_Depends);
15860 end if;
15861 end if;
15862 end Global;
15863
15864 -----------
15865 -- Ident --
15866 -----------
15867
15868 -- pragma Ident (static_string_EXPRESSION)
15869
15870 -- Note: pragma Comment shares this processing. Pragma Ident is
15871 -- identical in effect to pragma Commment.
15872
15873 when Pragma_Comment
15874 | Pragma_Ident
15875 =>
15876 Ident : declare
15877 Str : Node_Id;
15878
15879 begin
15880 GNAT_Pragma;
15881 Check_Arg_Count (1);
15882 Check_No_Identifiers;
15883 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
15884 Store_Note (N);
15885
15886 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
15887
15888 declare
15889 CS : Node_Id;
15890 GP : Node_Id;
15891
15892 begin
15893 GP := Parent (Parent (N));
15894
15895 if Nkind_In (GP, N_Package_Declaration,
15896 N_Generic_Package_Declaration)
15897 then
15898 GP := Parent (GP);
15899 end if;
15900
15901 -- If we have a compilation unit, then record the ident value,
15902 -- checking for improper duplication.
15903
15904 if Nkind (GP) = N_Compilation_Unit then
15905 CS := Ident_String (Current_Sem_Unit);
15906
15907 if Present (CS) then
15908
15909 -- If we have multiple instances, concatenate them, but
15910 -- not in ASIS, where we want the original tree.
15911
15912 if not ASIS_Mode then
15913 Start_String (Strval (CS));
15914 Store_String_Char (' ');
15915 Store_String_Chars (Strval (Str));
15916 Set_Strval (CS, End_String);
15917 end if;
15918
15919 else
15920 Set_Ident_String (Current_Sem_Unit, Str);
15921 end if;
15922
15923 -- For subunits, we just ignore the Ident, since in GNAT these
15924 -- are not separate object files, and hence not separate units
15925 -- in the unit table.
15926
15927 elsif Nkind (GP) = N_Subunit then
15928 null;
15929 end if;
15930 end;
15931 end Ident;
15932
15933 -------------------
15934 -- Ignore_Pragma --
15935 -------------------
15936
15937 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
15938
15939 -- Entirely handled in the parser, nothing to do here
15940
15941 when Pragma_Ignore_Pragma =>
15942 null;
15943
15944 ----------------------------
15945 -- Implementation_Defined --
15946 ----------------------------
15947
15948 -- pragma Implementation_Defined (LOCAL_NAME);
15949
15950 -- Marks previously declared entity as implementation defined. For
15951 -- an overloaded entity, applies to the most recent homonym.
15952
15953 -- pragma Implementation_Defined;
15954
15955 -- The form with no arguments appears anywhere within a scope, most
15956 -- typically a package spec, and indicates that all entities that are
15957 -- defined within the package spec are Implementation_Defined.
15958
15959 when Pragma_Implementation_Defined => Implementation_Defined : declare
15960 Ent : Entity_Id;
15961
15962 begin
15963 GNAT_Pragma;
15964 Check_No_Identifiers;
15965
15966 -- Form with no arguments
15967
15968 if Arg_Count = 0 then
15969 Set_Is_Implementation_Defined (Current_Scope);
15970
15971 -- Form with one argument
15972
15973 else
15974 Check_Arg_Count (1);
15975 Check_Arg_Is_Local_Name (Arg1);
15976 Ent := Entity (Get_Pragma_Arg (Arg1));
15977 Set_Is_Implementation_Defined (Ent);
15978 end if;
15979 end Implementation_Defined;
15980
15981 -----------------
15982 -- Implemented --
15983 -----------------
15984
15985 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
15986
15987 -- IMPLEMENTATION_KIND ::=
15988 -- By_Entry | By_Protected_Procedure | By_Any | Optional
15989
15990 -- "By_Any" and "Optional" are treated as synonyms in order to
15991 -- support Ada 2012 aspect Synchronization.
15992
15993 when Pragma_Implemented => Implemented : declare
15994 Proc_Id : Entity_Id;
15995 Typ : Entity_Id;
15996
15997 begin
15998 Ada_2012_Pragma;
15999 Check_Arg_Count (2);
16000 Check_No_Identifiers;
16001 Check_Arg_Is_Identifier (Arg1);
16002 Check_Arg_Is_Local_Name (Arg1);
16003 Check_Arg_Is_One_Of (Arg2,
16004 Name_By_Any,
16005 Name_By_Entry,
16006 Name_By_Protected_Procedure,
16007 Name_Optional);
16008
16009 -- Extract the name of the local procedure
16010
16011 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
16012
16013 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
16014 -- primitive procedure of a synchronized tagged type.
16015
16016 if Ekind (Proc_Id) = E_Procedure
16017 and then Is_Primitive (Proc_Id)
16018 and then Present (First_Formal (Proc_Id))
16019 then
16020 Typ := Etype (First_Formal (Proc_Id));
16021
16022 if Is_Tagged_Type (Typ)
16023 and then
16024
16025 -- Check for a protected, a synchronized or a task interface
16026
16027 ((Is_Interface (Typ)
16028 and then Is_Synchronized_Interface (Typ))
16029
16030 -- Check for a protected type or a task type that implements
16031 -- an interface.
16032
16033 or else
16034 (Is_Concurrent_Record_Type (Typ)
16035 and then Present (Interfaces (Typ)))
16036
16037 -- In analysis-only mode, examine original protected type
16038
16039 or else
16040 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
16041 and then Present (Interface_List (Parent (Typ))))
16042
16043 -- Check for a private record extension with keyword
16044 -- "synchronized".
16045
16046 or else
16047 (Ekind_In (Typ, E_Record_Type_With_Private,
16048 E_Record_Subtype_With_Private)
16049 and then Synchronized_Present (Parent (Typ))))
16050 then
16051 null;
16052 else
16053 Error_Pragma_Arg
16054 ("controlling formal must be of synchronized tagged type",
16055 Arg1);
16056 return;
16057 end if;
16058
16059 -- Procedures declared inside a protected type must be accepted
16060
16061 elsif Ekind (Proc_Id) = E_Procedure
16062 and then Is_Protected_Type (Scope (Proc_Id))
16063 then
16064 null;
16065
16066 -- The first argument is not a primitive procedure
16067
16068 else
16069 Error_Pragma_Arg
16070 ("pragma % must be applied to a primitive procedure", Arg1);
16071 return;
16072 end if;
16073
16074 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
16075 -- By_Protected_Procedure to the primitive procedure of a task
16076 -- interface.
16077
16078 if Chars (Arg2) = Name_By_Protected_Procedure
16079 and then Is_Interface (Typ)
16080 and then Is_Task_Interface (Typ)
16081 then
16082 Error_Pragma_Arg
16083 ("implementation kind By_Protected_Procedure cannot be "
16084 & "applied to a task interface primitive", Arg2);
16085 return;
16086 end if;
16087
16088 Record_Rep_Item (Proc_Id, N);
16089 end Implemented;
16090
16091 ----------------------
16092 -- Implicit_Packing --
16093 ----------------------
16094
16095 -- pragma Implicit_Packing;
16096
16097 when Pragma_Implicit_Packing =>
16098 GNAT_Pragma;
16099 Check_Arg_Count (0);
16100 Implicit_Packing := True;
16101
16102 ------------
16103 -- Import --
16104 ------------
16105
16106 -- pragma Import (
16107 -- [Convention =>] convention_IDENTIFIER,
16108 -- [Entity =>] LOCAL_NAME
16109 -- [, [External_Name =>] static_string_EXPRESSION ]
16110 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16111
16112 when Pragma_Import =>
16113 Check_Ada_83_Warning;
16114 Check_Arg_Order
16115 ((Name_Convention,
16116 Name_Entity,
16117 Name_External_Name,
16118 Name_Link_Name));
16119
16120 Check_At_Least_N_Arguments (2);
16121 Check_At_Most_N_Arguments (4);
16122 Process_Import_Or_Interface;
16123
16124 ---------------------
16125 -- Import_Function --
16126 ---------------------
16127
16128 -- pragma Import_Function (
16129 -- [Internal =>] LOCAL_NAME,
16130 -- [, [External =>] EXTERNAL_SYMBOL]
16131 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16132 -- [, [Result_Type =>] SUBTYPE_MARK]
16133 -- [, [Mechanism =>] MECHANISM]
16134 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
16135
16136 -- EXTERNAL_SYMBOL ::=
16137 -- IDENTIFIER
16138 -- | static_string_EXPRESSION
16139
16140 -- PARAMETER_TYPES ::=
16141 -- null
16142 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16143
16144 -- TYPE_DESIGNATOR ::=
16145 -- subtype_NAME
16146 -- | subtype_Name ' Access
16147
16148 -- MECHANISM ::=
16149 -- MECHANISM_NAME
16150 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16151
16152 -- MECHANISM_ASSOCIATION ::=
16153 -- [formal_parameter_NAME =>] MECHANISM_NAME
16154
16155 -- MECHANISM_NAME ::=
16156 -- Value
16157 -- | Reference
16158
16159 when Pragma_Import_Function => Import_Function : declare
16160 Args : Args_List (1 .. 6);
16161 Names : constant Name_List (1 .. 6) := (
16162 Name_Internal,
16163 Name_External,
16164 Name_Parameter_Types,
16165 Name_Result_Type,
16166 Name_Mechanism,
16167 Name_Result_Mechanism);
16168
16169 Internal : Node_Id renames Args (1);
16170 External : Node_Id renames Args (2);
16171 Parameter_Types : Node_Id renames Args (3);
16172 Result_Type : Node_Id renames Args (4);
16173 Mechanism : Node_Id renames Args (5);
16174 Result_Mechanism : Node_Id renames Args (6);
16175
16176 begin
16177 GNAT_Pragma;
16178 Gather_Associations (Names, Args);
16179 Process_Extended_Import_Export_Subprogram_Pragma (
16180 Arg_Internal => Internal,
16181 Arg_External => External,
16182 Arg_Parameter_Types => Parameter_Types,
16183 Arg_Result_Type => Result_Type,
16184 Arg_Mechanism => Mechanism,
16185 Arg_Result_Mechanism => Result_Mechanism);
16186 end Import_Function;
16187
16188 -------------------
16189 -- Import_Object --
16190 -------------------
16191
16192 -- pragma Import_Object (
16193 -- [Internal =>] LOCAL_NAME
16194 -- [, [External =>] EXTERNAL_SYMBOL]
16195 -- [, [Size =>] EXTERNAL_SYMBOL]);
16196
16197 -- EXTERNAL_SYMBOL ::=
16198 -- IDENTIFIER
16199 -- | static_string_EXPRESSION
16200
16201 when Pragma_Import_Object => Import_Object : declare
16202 Args : Args_List (1 .. 3);
16203 Names : constant Name_List (1 .. 3) := (
16204 Name_Internal,
16205 Name_External,
16206 Name_Size);
16207
16208 Internal : Node_Id renames Args (1);
16209 External : Node_Id renames Args (2);
16210 Size : Node_Id renames Args (3);
16211
16212 begin
16213 GNAT_Pragma;
16214 Gather_Associations (Names, Args);
16215 Process_Extended_Import_Export_Object_Pragma (
16216 Arg_Internal => Internal,
16217 Arg_External => External,
16218 Arg_Size => Size);
16219 end Import_Object;
16220
16221 ----------------------
16222 -- Import_Procedure --
16223 ----------------------
16224
16225 -- pragma Import_Procedure (
16226 -- [Internal =>] LOCAL_NAME
16227 -- [, [External =>] EXTERNAL_SYMBOL]
16228 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16229 -- [, [Mechanism =>] MECHANISM]);
16230
16231 -- EXTERNAL_SYMBOL ::=
16232 -- IDENTIFIER
16233 -- | static_string_EXPRESSION
16234
16235 -- PARAMETER_TYPES ::=
16236 -- null
16237 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16238
16239 -- TYPE_DESIGNATOR ::=
16240 -- subtype_NAME
16241 -- | subtype_Name ' Access
16242
16243 -- MECHANISM ::=
16244 -- MECHANISM_NAME
16245 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16246
16247 -- MECHANISM_ASSOCIATION ::=
16248 -- [formal_parameter_NAME =>] MECHANISM_NAME
16249
16250 -- MECHANISM_NAME ::=
16251 -- Value
16252 -- | Reference
16253
16254 when Pragma_Import_Procedure => Import_Procedure : declare
16255 Args : Args_List (1 .. 4);
16256 Names : constant Name_List (1 .. 4) := (
16257 Name_Internal,
16258 Name_External,
16259 Name_Parameter_Types,
16260 Name_Mechanism);
16261
16262 Internal : Node_Id renames Args (1);
16263 External : Node_Id renames Args (2);
16264 Parameter_Types : Node_Id renames Args (3);
16265 Mechanism : Node_Id renames Args (4);
16266
16267 begin
16268 GNAT_Pragma;
16269 Gather_Associations (Names, Args);
16270 Process_Extended_Import_Export_Subprogram_Pragma (
16271 Arg_Internal => Internal,
16272 Arg_External => External,
16273 Arg_Parameter_Types => Parameter_Types,
16274 Arg_Mechanism => Mechanism);
16275 end Import_Procedure;
16276
16277 -----------------------------
16278 -- Import_Valued_Procedure --
16279 -----------------------------
16280
16281 -- pragma Import_Valued_Procedure (
16282 -- [Internal =>] LOCAL_NAME
16283 -- [, [External =>] EXTERNAL_SYMBOL]
16284 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16285 -- [, [Mechanism =>] MECHANISM]);
16286
16287 -- EXTERNAL_SYMBOL ::=
16288 -- IDENTIFIER
16289 -- | static_string_EXPRESSION
16290
16291 -- PARAMETER_TYPES ::=
16292 -- null
16293 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16294
16295 -- TYPE_DESIGNATOR ::=
16296 -- subtype_NAME
16297 -- | subtype_Name ' Access
16298
16299 -- MECHANISM ::=
16300 -- MECHANISM_NAME
16301 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16302
16303 -- MECHANISM_ASSOCIATION ::=
16304 -- [formal_parameter_NAME =>] MECHANISM_NAME
16305
16306 -- MECHANISM_NAME ::=
16307 -- Value
16308 -- | Reference
16309
16310 when Pragma_Import_Valued_Procedure =>
16311 Import_Valued_Procedure : declare
16312 Args : Args_List (1 .. 4);
16313 Names : constant Name_List (1 .. 4) := (
16314 Name_Internal,
16315 Name_External,
16316 Name_Parameter_Types,
16317 Name_Mechanism);
16318
16319 Internal : Node_Id renames Args (1);
16320 External : Node_Id renames Args (2);
16321 Parameter_Types : Node_Id renames Args (3);
16322 Mechanism : Node_Id renames Args (4);
16323
16324 begin
16325 GNAT_Pragma;
16326 Gather_Associations (Names, Args);
16327 Process_Extended_Import_Export_Subprogram_Pragma (
16328 Arg_Internal => Internal,
16329 Arg_External => External,
16330 Arg_Parameter_Types => Parameter_Types,
16331 Arg_Mechanism => Mechanism);
16332 end Import_Valued_Procedure;
16333
16334 -----------------
16335 -- Independent --
16336 -----------------
16337
16338 -- pragma Independent (LOCAL_NAME);
16339
16340 when Pragma_Independent =>
16341 Process_Atomic_Independent_Shared_Volatile;
16342
16343 ----------------------------
16344 -- Independent_Components --
16345 ----------------------------
16346
16347 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
16348
16349 when Pragma_Independent_Components => Independent_Components : declare
16350 C : Node_Id;
16351 D : Node_Id;
16352 E_Id : Node_Id;
16353 E : Entity_Id;
16354 K : Node_Kind;
16355
16356 begin
16357 Check_Ada_83_Warning;
16358 Ada_2012_Pragma;
16359 Check_No_Identifiers;
16360 Check_Arg_Count (1);
16361 Check_Arg_Is_Local_Name (Arg1);
16362 E_Id := Get_Pragma_Arg (Arg1);
16363
16364 if Etype (E_Id) = Any_Type then
16365 return;
16366 end if;
16367
16368 E := Entity (E_Id);
16369
16370 -- A pragma that applies to a Ghost entity becomes Ghost for the
16371 -- purposes of legality checks and removal of ignored Ghost code.
16372
16373 Mark_Ghost_Pragma (N, E);
16374
16375 -- Check duplicate before we chain ourselves
16376
16377 Check_Duplicate_Pragma (E);
16378
16379 -- Check appropriate entity
16380
16381 if Rep_Item_Too_Early (E, N)
16382 or else
16383 Rep_Item_Too_Late (E, N)
16384 then
16385 return;
16386 end if;
16387
16388 D := Declaration_Node (E);
16389 K := Nkind (D);
16390
16391 -- The flag is set on the base type, or on the object
16392
16393 if K = N_Full_Type_Declaration
16394 and then (Is_Array_Type (E) or else Is_Record_Type (E))
16395 then
16396 Set_Has_Independent_Components (Base_Type (E));
16397 Record_Independence_Check (N, Base_Type (E));
16398
16399 -- For record type, set all components independent
16400
16401 if Is_Record_Type (E) then
16402 C := First_Component (E);
16403 while Present (C) loop
16404 Set_Is_Independent (C);
16405 Next_Component (C);
16406 end loop;
16407 end if;
16408
16409 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
16410 and then Nkind (D) = N_Object_Declaration
16411 and then Nkind (Object_Definition (D)) =
16412 N_Constrained_Array_Definition
16413 then
16414 Set_Has_Independent_Components (E);
16415 Record_Independence_Check (N, E);
16416
16417 else
16418 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
16419 end if;
16420 end Independent_Components;
16421
16422 -----------------------
16423 -- Initial_Condition --
16424 -----------------------
16425
16426 -- pragma Initial_Condition (boolean_EXPRESSION);
16427
16428 -- Characteristics:
16429
16430 -- * Analysis - The annotation undergoes initial checks to verify
16431 -- the legal placement and context. Secondary checks preanalyze the
16432 -- expression in:
16433
16434 -- Analyze_Initial_Condition_In_Decl_Part
16435
16436 -- * Expansion - The annotation is expanded during the expansion of
16437 -- the package body whose declaration is subject to the annotation
16438 -- as done in:
16439
16440 -- Expand_Pragma_Initial_Condition
16441
16442 -- * Template - The annotation utilizes the generic template of the
16443 -- related package declaration.
16444
16445 -- * Globals - Capture of global references must occur after full
16446 -- analysis.
16447
16448 -- * Instance - The annotation is instantiated automatically when
16449 -- the related generic package is instantiated.
16450
16451 when Pragma_Initial_Condition => Initial_Condition : declare
16452 Pack_Decl : Node_Id;
16453 Pack_Id : Entity_Id;
16454
16455 begin
16456 GNAT_Pragma;
16457 Check_No_Identifiers;
16458 Check_Arg_Count (1);
16459
16460 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
16461
16462 -- Ensure the proper placement of the pragma. Initial_Condition
16463 -- must be associated with a package declaration.
16464
16465 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
16466 N_Package_Declaration)
16467 then
16468 null;
16469
16470 -- Otherwise the pragma is associated with an illegal context
16471
16472 else
16473 Pragma_Misplaced;
16474 return;
16475 end if;
16476
16477 Pack_Id := Defining_Entity (Pack_Decl);
16478
16479 -- A pragma that applies to a Ghost entity becomes Ghost for the
16480 -- purposes of legality checks and removal of ignored Ghost code.
16481
16482 Mark_Ghost_Pragma (N, Pack_Id);
16483
16484 -- Chain the pragma on the contract for further processing by
16485 -- Analyze_Initial_Condition_In_Decl_Part.
16486
16487 Add_Contract_Item (N, Pack_Id);
16488
16489 -- The legality checks of pragmas Abstract_State, Initializes, and
16490 -- Initial_Condition are affected by the SPARK mode in effect. In
16491 -- addition, these three pragmas are subject to an inherent order:
16492
16493 -- 1) Abstract_State
16494 -- 2) Initializes
16495 -- 3) Initial_Condition
16496
16497 -- Analyze all these pragmas in the order outlined above
16498
16499 Analyze_If_Present (Pragma_SPARK_Mode);
16500 Analyze_If_Present (Pragma_Abstract_State);
16501 Analyze_If_Present (Pragma_Initializes);
16502 end Initial_Condition;
16503
16504 ------------------------
16505 -- Initialize_Scalars --
16506 ------------------------
16507
16508 -- pragma Initialize_Scalars;
16509
16510 when Pragma_Initialize_Scalars =>
16511 GNAT_Pragma;
16512 Check_Arg_Count (0);
16513 Check_Valid_Configuration_Pragma;
16514 Check_Restriction (No_Initialize_Scalars, N);
16515
16516 -- Initialize_Scalars creates false positives in CodePeer, and
16517 -- incorrect negative results in GNATprove mode, so ignore this
16518 -- pragma in these modes.
16519
16520 if not Restriction_Active (No_Initialize_Scalars)
16521 and then not (CodePeer_Mode or GNATprove_Mode)
16522 then
16523 Init_Or_Norm_Scalars := True;
16524 Initialize_Scalars := True;
16525 end if;
16526
16527 -----------------
16528 -- Initializes --
16529 -----------------
16530
16531 -- pragma Initializes (INITIALIZATION_LIST);
16532
16533 -- INITIALIZATION_LIST ::=
16534 -- null
16535 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
16536
16537 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
16538
16539 -- INPUT_LIST ::=
16540 -- null
16541 -- | INPUT
16542 -- | (INPUT {, INPUT})
16543
16544 -- INPUT ::= name
16545
16546 -- Characteristics:
16547
16548 -- * Analysis - The annotation undergoes initial checks to verify
16549 -- the legal placement and context. Secondary checks preanalyze the
16550 -- expression in:
16551
16552 -- Analyze_Initializes_In_Decl_Part
16553
16554 -- * Expansion - None.
16555
16556 -- * Template - The annotation utilizes the generic template of the
16557 -- related package declaration.
16558
16559 -- * Globals - Capture of global references must occur after full
16560 -- analysis.
16561
16562 -- * Instance - The annotation is instantiated automatically when
16563 -- the related generic package is instantiated.
16564
16565 when Pragma_Initializes => Initializes : declare
16566 Pack_Decl : Node_Id;
16567 Pack_Id : Entity_Id;
16568
16569 begin
16570 GNAT_Pragma;
16571 Check_No_Identifiers;
16572 Check_Arg_Count (1);
16573
16574 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
16575
16576 -- Ensure the proper placement of the pragma. Initializes must be
16577 -- associated with a package declaration.
16578
16579 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
16580 N_Package_Declaration)
16581 then
16582 null;
16583
16584 -- Otherwise the pragma is associated with an illegal construc
16585
16586 else
16587 Pragma_Misplaced;
16588 return;
16589 end if;
16590
16591 Pack_Id := Defining_Entity (Pack_Decl);
16592
16593 -- A pragma that applies to a Ghost entity becomes Ghost for the
16594 -- purposes of legality checks and removal of ignored Ghost code.
16595
16596 Mark_Ghost_Pragma (N, Pack_Id);
16597 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
16598
16599 -- Chain the pragma on the contract for further processing by
16600 -- Analyze_Initializes_In_Decl_Part.
16601
16602 Add_Contract_Item (N, Pack_Id);
16603
16604 -- The legality checks of pragmas Abstract_State, Initializes, and
16605 -- Initial_Condition are affected by the SPARK mode in effect. In
16606 -- addition, these three pragmas are subject to an inherent order:
16607
16608 -- 1) Abstract_State
16609 -- 2) Initializes
16610 -- 3) Initial_Condition
16611
16612 -- Analyze all these pragmas in the order outlined above
16613
16614 Analyze_If_Present (Pragma_SPARK_Mode);
16615 Analyze_If_Present (Pragma_Abstract_State);
16616 Analyze_If_Present (Pragma_Initial_Condition);
16617 end Initializes;
16618
16619 ------------
16620 -- Inline --
16621 ------------
16622
16623 -- pragma Inline ( NAME {, NAME} );
16624
16625 when Pragma_Inline =>
16626
16627 -- Pragma always active unless in GNATprove mode. It is disabled
16628 -- in GNATprove mode because frontend inlining is applied
16629 -- independently of pragmas Inline and Inline_Always for
16630 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
16631 -- in inline.ads.
16632
16633 if not GNATprove_Mode then
16634
16635 -- Inline status is Enabled if option -gnatn is specified.
16636 -- However this status determines only the value of the
16637 -- Is_Inlined flag on the subprogram and does not prevent
16638 -- the pragma itself from being recorded for later use,
16639 -- in particular for a later modification of Is_Inlined
16640 -- independently of the -gnatn option.
16641
16642 -- In other words, if -gnatn is specified for a unit, then
16643 -- all Inline pragmas processed for the compilation of this
16644 -- unit, including those in the spec of other units, are
16645 -- activated, so subprograms will be inlined across units.
16646
16647 -- If -gnatn is not specified, no Inline pragma is activated
16648 -- here, which means that subprograms will not be inlined
16649 -- across units. The Is_Inlined flag will nevertheless be
16650 -- set later when bodies are analyzed, so subprograms will
16651 -- be inlined within the unit.
16652
16653 if Inline_Active then
16654 Process_Inline (Enabled);
16655 else
16656 Process_Inline (Disabled);
16657 end if;
16658 end if;
16659
16660 -------------------
16661 -- Inline_Always --
16662 -------------------
16663
16664 -- pragma Inline_Always ( NAME {, NAME} );
16665
16666 when Pragma_Inline_Always =>
16667 GNAT_Pragma;
16668
16669 -- Pragma always active unless in CodePeer mode or GNATprove
16670 -- mode. It is disabled in CodePeer mode because inlining is
16671 -- not helpful, and enabling it caused walk order issues. It
16672 -- is disabled in GNATprove mode because frontend inlining is
16673 -- applied independently of pragmas Inline and Inline_Always for
16674 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
16675 -- inline.ads.
16676
16677 if not CodePeer_Mode and not GNATprove_Mode then
16678 Process_Inline (Enabled);
16679 end if;
16680
16681 --------------------
16682 -- Inline_Generic --
16683 --------------------
16684
16685 -- pragma Inline_Generic (NAME {, NAME});
16686
16687 when Pragma_Inline_Generic =>
16688 GNAT_Pragma;
16689 Process_Generic_List;
16690
16691 ----------------------
16692 -- Inspection_Point --
16693 ----------------------
16694
16695 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
16696
16697 when Pragma_Inspection_Point => Inspection_Point : declare
16698 Arg : Node_Id;
16699 Exp : Node_Id;
16700
16701 begin
16702 ip;
16703
16704 if Arg_Count > 0 then
16705 Arg := Arg1;
16706 loop
16707 Exp := Get_Pragma_Arg (Arg);
16708 Analyze (Exp);
16709
16710 if not Is_Entity_Name (Exp)
16711 or else not Is_Object (Entity (Exp))
16712 then
16713 Error_Pragma_Arg ("object name required", Arg);
16714 end if;
16715
16716 Next (Arg);
16717 exit when No (Arg);
16718 end loop;
16719 end if;
16720 end Inspection_Point;
16721
16722 ---------------
16723 -- Interface --
16724 ---------------
16725
16726 -- pragma Interface (
16727 -- [ Convention =>] convention_IDENTIFIER,
16728 -- [ Entity =>] LOCAL_NAME
16729 -- [, [External_Name =>] static_string_EXPRESSION ]
16730 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16731
16732 when Pragma_Interface =>
16733 GNAT_Pragma;
16734 Check_Arg_Order
16735 ((Name_Convention,
16736 Name_Entity,
16737 Name_External_Name,
16738 Name_Link_Name));
16739 Check_At_Least_N_Arguments (2);
16740 Check_At_Most_N_Arguments (4);
16741 Process_Import_Or_Interface;
16742
16743 -- In Ada 2005, the permission to use Interface (a reserved word)
16744 -- as a pragma name is considered an obsolescent feature, and this
16745 -- pragma was already obsolescent in Ada 95.
16746
16747 if Ada_Version >= Ada_95 then
16748 Check_Restriction
16749 (No_Obsolescent_Features, Pragma_Identifier (N));
16750
16751 if Warn_On_Obsolescent_Feature then
16752 Error_Msg_N
16753 ("pragma Interface is an obsolescent feature?j?", N);
16754 Error_Msg_N
16755 ("|use pragma Import instead?j?", N);
16756 end if;
16757 end if;
16758
16759 --------------------
16760 -- Interface_Name --
16761 --------------------
16762
16763 -- pragma Interface_Name (
16764 -- [ Entity =>] LOCAL_NAME
16765 -- [,[External_Name =>] static_string_EXPRESSION ]
16766 -- [,[Link_Name =>] static_string_EXPRESSION ]);
16767
16768 when Pragma_Interface_Name => Interface_Name : declare
16769 Id : Node_Id;
16770 Def_Id : Entity_Id;
16771 Hom_Id : Entity_Id;
16772 Found : Boolean;
16773
16774 begin
16775 GNAT_Pragma;
16776 Check_Arg_Order
16777 ((Name_Entity, Name_External_Name, Name_Link_Name));
16778 Check_At_Least_N_Arguments (2);
16779 Check_At_Most_N_Arguments (3);
16780 Id := Get_Pragma_Arg (Arg1);
16781 Analyze (Id);
16782
16783 -- This is obsolete from Ada 95 on, but it is an implementation
16784 -- defined pragma, so we do not consider that it violates the
16785 -- restriction (No_Obsolescent_Features).
16786
16787 if Ada_Version >= Ada_95 then
16788 if Warn_On_Obsolescent_Feature then
16789 Error_Msg_N
16790 ("pragma Interface_Name is an obsolescent feature?j?", N);
16791 Error_Msg_N
16792 ("|use pragma Import instead?j?", N);
16793 end if;
16794 end if;
16795
16796 if not Is_Entity_Name (Id) then
16797 Error_Pragma_Arg
16798 ("first argument for pragma% must be entity name", Arg1);
16799 elsif Etype (Id) = Any_Type then
16800 return;
16801 else
16802 Def_Id := Entity (Id);
16803 end if;
16804
16805 -- Special DEC-compatible processing for the object case, forces
16806 -- object to be imported.
16807
16808 if Ekind (Def_Id) = E_Variable then
16809 Kill_Size_Check_Code (Def_Id);
16810 Note_Possible_Modification (Id, Sure => False);
16811
16812 -- Initialization is not allowed for imported variable
16813
16814 if Present (Expression (Parent (Def_Id)))
16815 and then Comes_From_Source (Expression (Parent (Def_Id)))
16816 then
16817 Error_Msg_Sloc := Sloc (Def_Id);
16818 Error_Pragma_Arg
16819 ("no initialization allowed for declaration of& #",
16820 Arg2);
16821
16822 else
16823 -- For compatibility, support VADS usage of providing both
16824 -- pragmas Interface and Interface_Name to obtain the effect
16825 -- of a single Import pragma.
16826
16827 if Is_Imported (Def_Id)
16828 and then Present (First_Rep_Item (Def_Id))
16829 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
16830 and then Pragma_Name (First_Rep_Item (Def_Id)) =
16831 Name_Interface
16832 then
16833 null;
16834 else
16835 Set_Imported (Def_Id);
16836 end if;
16837
16838 Set_Is_Public (Def_Id);
16839 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
16840 end if;
16841
16842 -- Otherwise must be subprogram
16843
16844 elsif not Is_Subprogram (Def_Id) then
16845 Error_Pragma_Arg
16846 ("argument of pragma% is not subprogram", Arg1);
16847
16848 else
16849 Check_At_Most_N_Arguments (3);
16850 Hom_Id := Def_Id;
16851 Found := False;
16852
16853 -- Loop through homonyms
16854
16855 loop
16856 Def_Id := Get_Base_Subprogram (Hom_Id);
16857
16858 if Is_Imported (Def_Id) then
16859 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
16860 Found := True;
16861 end if;
16862
16863 exit when From_Aspect_Specification (N);
16864 Hom_Id := Homonym (Hom_Id);
16865
16866 exit when No (Hom_Id)
16867 or else Scope (Hom_Id) /= Current_Scope;
16868 end loop;
16869
16870 if not Found then
16871 Error_Pragma_Arg
16872 ("argument of pragma% is not imported subprogram",
16873 Arg1);
16874 end if;
16875 end if;
16876 end Interface_Name;
16877
16878 -----------------------
16879 -- Interrupt_Handler --
16880 -----------------------
16881
16882 -- pragma Interrupt_Handler (handler_NAME);
16883
16884 when Pragma_Interrupt_Handler =>
16885 Check_Ada_83_Warning;
16886 Check_Arg_Count (1);
16887 Check_No_Identifiers;
16888
16889 if No_Run_Time_Mode then
16890 Error_Msg_CRT ("Interrupt_Handler pragma", N);
16891 else
16892 Check_Interrupt_Or_Attach_Handler;
16893 Process_Interrupt_Or_Attach_Handler;
16894 end if;
16895
16896 ------------------------
16897 -- Interrupt_Priority --
16898 ------------------------
16899
16900 -- pragma Interrupt_Priority [(EXPRESSION)];
16901
16902 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
16903 P : constant Node_Id := Parent (N);
16904 Arg : Node_Id;
16905 Ent : Entity_Id;
16906
16907 begin
16908 Check_Ada_83_Warning;
16909
16910 if Arg_Count /= 0 then
16911 Arg := Get_Pragma_Arg (Arg1);
16912 Check_Arg_Count (1);
16913 Check_No_Identifiers;
16914
16915 -- The expression must be analyzed in the special manner
16916 -- described in "Handling of Default and Per-Object
16917 -- Expressions" in sem.ads.
16918
16919 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
16920 end if;
16921
16922 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
16923 Pragma_Misplaced;
16924 return;
16925
16926 else
16927 Ent := Defining_Identifier (Parent (P));
16928
16929 -- Check duplicate pragma before we chain the pragma in the Rep
16930 -- Item chain of Ent.
16931
16932 Check_Duplicate_Pragma (Ent);
16933 Record_Rep_Item (Ent, N);
16934
16935 -- Check the No_Task_At_Interrupt_Priority restriction
16936
16937 if Nkind (P) = N_Task_Definition then
16938 Check_Restriction (No_Task_At_Interrupt_Priority, N);
16939 end if;
16940 end if;
16941 end Interrupt_Priority;
16942
16943 ---------------------
16944 -- Interrupt_State --
16945 ---------------------
16946
16947 -- pragma Interrupt_State (
16948 -- [Name =>] INTERRUPT_ID,
16949 -- [State =>] INTERRUPT_STATE);
16950
16951 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
16952 -- INTERRUPT_STATE => System | Runtime | User
16953
16954 -- Note: if the interrupt id is given as an identifier, then it must
16955 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
16956 -- given as a static integer expression which must be in the range of
16957 -- Ada.Interrupts.Interrupt_ID.
16958
16959 when Pragma_Interrupt_State => Interrupt_State : declare
16960 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
16961 -- This is the entity Ada.Interrupts.Interrupt_ID;
16962
16963 State_Type : Character;
16964 -- Set to 's'/'r'/'u' for System/Runtime/User
16965
16966 IST_Num : Pos;
16967 -- Index to entry in Interrupt_States table
16968
16969 Int_Val : Uint;
16970 -- Value of interrupt
16971
16972 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
16973 -- The first argument to the pragma
16974
16975 Int_Ent : Entity_Id;
16976 -- Interrupt entity in Ada.Interrupts.Names
16977
16978 begin
16979 GNAT_Pragma;
16980 Check_Arg_Order ((Name_Name, Name_State));
16981 Check_Arg_Count (2);
16982
16983 Check_Optional_Identifier (Arg1, Name_Name);
16984 Check_Optional_Identifier (Arg2, Name_State);
16985 Check_Arg_Is_Identifier (Arg2);
16986
16987 -- First argument is identifier
16988
16989 if Nkind (Arg1X) = N_Identifier then
16990
16991 -- Search list of names in Ada.Interrupts.Names
16992
16993 Int_Ent := First_Entity (RTE (RE_Names));
16994 loop
16995 if No (Int_Ent) then
16996 Error_Pragma_Arg ("invalid interrupt name", Arg1);
16997
16998 elsif Chars (Int_Ent) = Chars (Arg1X) then
16999 Int_Val := Expr_Value (Constant_Value (Int_Ent));
17000 exit;
17001 end if;
17002
17003 Next_Entity (Int_Ent);
17004 end loop;
17005
17006 -- First argument is not an identifier, so it must be a static
17007 -- expression of type Ada.Interrupts.Interrupt_ID.
17008
17009 else
17010 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
17011 Int_Val := Expr_Value (Arg1X);
17012
17013 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
17014 or else
17015 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
17016 then
17017 Error_Pragma_Arg
17018 ("value not in range of type "
17019 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
17020 end if;
17021 end if;
17022
17023 -- Check OK state
17024
17025 case Chars (Get_Pragma_Arg (Arg2)) is
17026 when Name_Runtime => State_Type := 'r';
17027 when Name_System => State_Type := 's';
17028 when Name_User => State_Type := 'u';
17029
17030 when others =>
17031 Error_Pragma_Arg ("invalid interrupt state", Arg2);
17032 end case;
17033
17034 -- Check if entry is already stored
17035
17036 IST_Num := Interrupt_States.First;
17037 loop
17038 -- If entry not found, add it
17039
17040 if IST_Num > Interrupt_States.Last then
17041 Interrupt_States.Append
17042 ((Interrupt_Number => UI_To_Int (Int_Val),
17043 Interrupt_State => State_Type,
17044 Pragma_Loc => Loc));
17045 exit;
17046
17047 -- Case of entry for the same entry
17048
17049 elsif Int_Val = Interrupt_States.Table (IST_Num).
17050 Interrupt_Number
17051 then
17052 -- If state matches, done, no need to make redundant entry
17053
17054 exit when
17055 State_Type = Interrupt_States.Table (IST_Num).
17056 Interrupt_State;
17057
17058 -- Otherwise if state does not match, error
17059
17060 Error_Msg_Sloc :=
17061 Interrupt_States.Table (IST_Num).Pragma_Loc;
17062 Error_Pragma_Arg
17063 ("state conflicts with that given #", Arg2);
17064 exit;
17065 end if;
17066
17067 IST_Num := IST_Num + 1;
17068 end loop;
17069 end Interrupt_State;
17070
17071 ---------------
17072 -- Invariant --
17073 ---------------
17074
17075 -- pragma Invariant
17076 -- ([Entity =>] type_LOCAL_NAME,
17077 -- [Check =>] EXPRESSION
17078 -- [,[Message =>] String_Expression]);
17079
17080 when Pragma_Invariant => Invariant : declare
17081 Discard : Boolean;
17082 Typ : Entity_Id;
17083 Typ_Arg : Node_Id;
17084
17085 begin
17086 GNAT_Pragma;
17087 Check_At_Least_N_Arguments (2);
17088 Check_At_Most_N_Arguments (3);
17089 Check_Optional_Identifier (Arg1, Name_Entity);
17090 Check_Optional_Identifier (Arg2, Name_Check);
17091
17092 if Arg_Count = 3 then
17093 Check_Optional_Identifier (Arg3, Name_Message);
17094 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
17095 end if;
17096
17097 Check_Arg_Is_Local_Name (Arg1);
17098
17099 Typ_Arg := Get_Pragma_Arg (Arg1);
17100 Find_Type (Typ_Arg);
17101 Typ := Entity (Typ_Arg);
17102
17103 -- Nothing to do of the related type is erroneous in some way
17104
17105 if Typ = Any_Type then
17106 return;
17107
17108 -- AI12-0041: Invariants are allowed in interface types
17109
17110 elsif Is_Interface (Typ) then
17111 null;
17112
17113 -- An invariant must apply to a private type, or appear in the
17114 -- private part of a package spec and apply to a completion.
17115 -- a class-wide invariant can only appear on a private declaration
17116 -- or private extension, not a completion.
17117
17118 -- A [class-wide] invariant may be associated a [limited] private
17119 -- type or a private extension.
17120
17121 elsif Ekind_In (Typ, E_Limited_Private_Type,
17122 E_Private_Type,
17123 E_Record_Type_With_Private)
17124 then
17125 null;
17126
17127 -- A non-class-wide invariant may be associated with the full view
17128 -- of a [limited] private type or a private extension.
17129
17130 elsif Has_Private_Declaration (Typ)
17131 and then not Class_Present (N)
17132 then
17133 null;
17134
17135 -- A class-wide invariant may appear on the partial view only
17136
17137 elsif Class_Present (N) then
17138 Error_Pragma_Arg
17139 ("pragma % only allowed for private type", Arg1);
17140 return;
17141
17142 -- A regular invariant may appear on both views
17143
17144 else
17145 Error_Pragma_Arg
17146 ("pragma % only allowed for private type or corresponding "
17147 & "full view", Arg1);
17148 return;
17149 end if;
17150
17151 -- An invariant associated with an abstract type (this includes
17152 -- interfaces) must be class-wide.
17153
17154 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
17155 Error_Pragma_Arg
17156 ("pragma % not allowed for abstract type", Arg1);
17157 return;
17158 end if;
17159
17160 -- A pragma that applies to a Ghost entity becomes Ghost for the
17161 -- purposes of legality checks and removal of ignored Ghost code.
17162
17163 Mark_Ghost_Pragma (N, Typ);
17164
17165 -- The pragma defines a type-specific invariant, the type is said
17166 -- to have invariants of its "own".
17167
17168 Set_Has_Own_Invariants (Typ);
17169
17170 -- If the invariant is class-wide, then it can be inherited by
17171 -- derived or interface implementing types. The type is said to
17172 -- have "inheritable" invariants.
17173
17174 if Class_Present (N) then
17175 Set_Has_Inheritable_Invariants (Typ);
17176 end if;
17177
17178 -- Chain the pragma on to the rep item chain, for processing when
17179 -- the type is frozen.
17180
17181 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
17182
17183 -- Create the declaration of the invariant procedure that will
17184 -- verify the invariant at run time. Interfaces are treated as the
17185 -- partial view of a private type in order to achieve uniformity
17186 -- with the general case. As a result, an interface receives only
17187 -- a "partial" invariant procedure, which is never called.
17188
17189 Build_Invariant_Procedure_Declaration
17190 (Typ => Typ,
17191 Partial_Invariant => Is_Interface (Typ));
17192 end Invariant;
17193
17194 ----------------
17195 -- Keep_Names --
17196 ----------------
17197
17198 -- pragma Keep_Names ([On => ] LOCAL_NAME);
17199
17200 when Pragma_Keep_Names => Keep_Names : declare
17201 Arg : Node_Id;
17202
17203 begin
17204 GNAT_Pragma;
17205 Check_Arg_Count (1);
17206 Check_Optional_Identifier (Arg1, Name_On);
17207 Check_Arg_Is_Local_Name (Arg1);
17208
17209 Arg := Get_Pragma_Arg (Arg1);
17210 Analyze (Arg);
17211
17212 if Etype (Arg) = Any_Type then
17213 return;
17214 end if;
17215
17216 if not Is_Entity_Name (Arg)
17217 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
17218 then
17219 Error_Pragma_Arg
17220 ("pragma% requires a local enumeration type", Arg1);
17221 end if;
17222
17223 Set_Discard_Names (Entity (Arg), False);
17224 end Keep_Names;
17225
17226 -------------
17227 -- License --
17228 -------------
17229
17230 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
17231
17232 when Pragma_License =>
17233 GNAT_Pragma;
17234
17235 -- Do not analyze pragma any further in CodePeer mode, to avoid
17236 -- extraneous errors in this implementation-dependent pragma,
17237 -- which has a different profile on other compilers.
17238
17239 if CodePeer_Mode then
17240 return;
17241 end if;
17242
17243 Check_Arg_Count (1);
17244 Check_No_Identifiers;
17245 Check_Valid_Configuration_Pragma;
17246 Check_Arg_Is_Identifier (Arg1);
17247
17248 declare
17249 Sind : constant Source_File_Index :=
17250 Source_Index (Current_Sem_Unit);
17251
17252 begin
17253 case Chars (Get_Pragma_Arg (Arg1)) is
17254 when Name_GPL =>
17255 Set_License (Sind, GPL);
17256
17257 when Name_Modified_GPL =>
17258 Set_License (Sind, Modified_GPL);
17259
17260 when Name_Restricted =>
17261 Set_License (Sind, Restricted);
17262
17263 when Name_Unrestricted =>
17264 Set_License (Sind, Unrestricted);
17265
17266 when others =>
17267 Error_Pragma_Arg ("invalid license name", Arg1);
17268 end case;
17269 end;
17270
17271 ---------------
17272 -- Link_With --
17273 ---------------
17274
17275 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
17276
17277 when Pragma_Link_With => Link_With : declare
17278 Arg : Node_Id;
17279
17280 begin
17281 GNAT_Pragma;
17282
17283 if Operating_Mode = Generate_Code
17284 and then In_Extended_Main_Source_Unit (N)
17285 then
17286 Check_At_Least_N_Arguments (1);
17287 Check_No_Identifiers;
17288 Check_Is_In_Decl_Part_Or_Package_Spec;
17289 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17290 Start_String;
17291
17292 Arg := Arg1;
17293 while Present (Arg) loop
17294 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
17295
17296 -- Store argument, converting sequences of spaces to a
17297 -- single null character (this is one of the differences
17298 -- in processing between Link_With and Linker_Options).
17299
17300 Arg_Store : declare
17301 C : constant Char_Code := Get_Char_Code (' ');
17302 S : constant String_Id :=
17303 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
17304 L : constant Nat := String_Length (S);
17305 F : Nat := 1;
17306
17307 procedure Skip_Spaces;
17308 -- Advance F past any spaces
17309
17310 -----------------
17311 -- Skip_Spaces --
17312 -----------------
17313
17314 procedure Skip_Spaces is
17315 begin
17316 while F <= L and then Get_String_Char (S, F) = C loop
17317 F := F + 1;
17318 end loop;
17319 end Skip_Spaces;
17320
17321 -- Start of processing for Arg_Store
17322
17323 begin
17324 Skip_Spaces; -- skip leading spaces
17325
17326 -- Loop through characters, changing any embedded
17327 -- sequence of spaces to a single null character (this
17328 -- is how Link_With/Linker_Options differ)
17329
17330 while F <= L loop
17331 if Get_String_Char (S, F) = C then
17332 Skip_Spaces;
17333 exit when F > L;
17334 Store_String_Char (ASCII.NUL);
17335
17336 else
17337 Store_String_Char (Get_String_Char (S, F));
17338 F := F + 1;
17339 end if;
17340 end loop;
17341 end Arg_Store;
17342
17343 Arg := Next (Arg);
17344
17345 if Present (Arg) then
17346 Store_String_Char (ASCII.NUL);
17347 end if;
17348 end loop;
17349
17350 Store_Linker_Option_String (End_String);
17351 end if;
17352 end Link_With;
17353
17354 ------------------
17355 -- Linker_Alias --
17356 ------------------
17357
17358 -- pragma Linker_Alias (
17359 -- [Entity =>] LOCAL_NAME
17360 -- [Target =>] static_string_EXPRESSION);
17361
17362 when Pragma_Linker_Alias =>
17363 GNAT_Pragma;
17364 Check_Arg_Order ((Name_Entity, Name_Target));
17365 Check_Arg_Count (2);
17366 Check_Optional_Identifier (Arg1, Name_Entity);
17367 Check_Optional_Identifier (Arg2, Name_Target);
17368 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17369 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
17370
17371 -- The only processing required is to link this item on to the
17372 -- list of rep items for the given entity. This is accomplished
17373 -- by the call to Rep_Item_Too_Late (when no error is detected
17374 -- and False is returned).
17375
17376 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
17377 return;
17378 else
17379 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
17380 end if;
17381
17382 ------------------------
17383 -- Linker_Constructor --
17384 ------------------------
17385
17386 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
17387
17388 -- Code is shared with Linker_Destructor
17389
17390 -----------------------
17391 -- Linker_Destructor --
17392 -----------------------
17393
17394 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
17395
17396 when Pragma_Linker_Constructor
17397 | Pragma_Linker_Destructor
17398 =>
17399 Linker_Constructor : declare
17400 Arg1_X : Node_Id;
17401 Proc : Entity_Id;
17402
17403 begin
17404 GNAT_Pragma;
17405 Check_Arg_Count (1);
17406 Check_No_Identifiers;
17407 Check_Arg_Is_Local_Name (Arg1);
17408 Arg1_X := Get_Pragma_Arg (Arg1);
17409 Analyze (Arg1_X);
17410 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
17411
17412 if not Is_Library_Level_Entity (Proc) then
17413 Error_Pragma_Arg
17414 ("argument for pragma% must be library level entity", Arg1);
17415 end if;
17416
17417 -- The only processing required is to link this item on to the
17418 -- list of rep items for the given entity. This is accomplished
17419 -- by the call to Rep_Item_Too_Late (when no error is detected
17420 -- and False is returned).
17421
17422 if Rep_Item_Too_Late (Proc, N) then
17423 return;
17424 else
17425 Set_Has_Gigi_Rep_Item (Proc);
17426 end if;
17427 end Linker_Constructor;
17428
17429 --------------------
17430 -- Linker_Options --
17431 --------------------
17432
17433 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
17434
17435 when Pragma_Linker_Options => Linker_Options : declare
17436 Arg : Node_Id;
17437
17438 begin
17439 Check_Ada_83_Warning;
17440 Check_No_Identifiers;
17441 Check_Arg_Count (1);
17442 Check_Is_In_Decl_Part_Or_Package_Spec;
17443 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17444 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
17445
17446 Arg := Arg2;
17447 while Present (Arg) loop
17448 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
17449 Store_String_Char (ASCII.NUL);
17450 Store_String_Chars
17451 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
17452 Arg := Next (Arg);
17453 end loop;
17454
17455 if Operating_Mode = Generate_Code
17456 and then In_Extended_Main_Source_Unit (N)
17457 then
17458 Store_Linker_Option_String (End_String);
17459 end if;
17460 end Linker_Options;
17461
17462 --------------------
17463 -- Linker_Section --
17464 --------------------
17465
17466 -- pragma Linker_Section (
17467 -- [Entity =>] LOCAL_NAME
17468 -- [Section =>] static_string_EXPRESSION);
17469
17470 when Pragma_Linker_Section => Linker_Section : declare
17471 Arg : Node_Id;
17472 Ent : Entity_Id;
17473 LPE : Node_Id;
17474
17475 Ghost_Error_Posted : Boolean := False;
17476 -- Flag set when an error concerning the illegal mix of Ghost and
17477 -- non-Ghost subprograms is emitted.
17478
17479 Ghost_Id : Entity_Id := Empty;
17480 -- The entity of the first Ghost subprogram encountered while
17481 -- processing the arguments of the pragma.
17482
17483 begin
17484 GNAT_Pragma;
17485 Check_Arg_Order ((Name_Entity, Name_Section));
17486 Check_Arg_Count (2);
17487 Check_Optional_Identifier (Arg1, Name_Entity);
17488 Check_Optional_Identifier (Arg2, Name_Section);
17489 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17490 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
17491
17492 -- Check kind of entity
17493
17494 Arg := Get_Pragma_Arg (Arg1);
17495 Ent := Entity (Arg);
17496
17497 case Ekind (Ent) is
17498
17499 -- Objects (constants and variables) and types. For these cases
17500 -- all we need to do is to set the Linker_Section_pragma field,
17501 -- checking that we do not have a duplicate.
17502
17503 when Type_Kind
17504 | E_Constant
17505 | E_Variable
17506 =>
17507 LPE := Linker_Section_Pragma (Ent);
17508
17509 if Present (LPE) then
17510 Error_Msg_Sloc := Sloc (LPE);
17511 Error_Msg_NE
17512 ("Linker_Section already specified for &#", Arg1, Ent);
17513 end if;
17514
17515 Set_Linker_Section_Pragma (Ent, N);
17516
17517 -- A pragma that applies to a Ghost entity becomes Ghost for
17518 -- the purposes of legality checks and removal of ignored
17519 -- Ghost code.
17520
17521 Mark_Ghost_Pragma (N, Ent);
17522
17523 -- Subprograms
17524
17525 when Subprogram_Kind =>
17526
17527 -- Aspect case, entity already set
17528
17529 if From_Aspect_Specification (N) then
17530 Set_Linker_Section_Pragma
17531 (Entity (Corresponding_Aspect (N)), N);
17532
17533 -- Pragma case, we must climb the homonym chain, but skip
17534 -- any for which the linker section is already set.
17535
17536 else
17537 loop
17538 if No (Linker_Section_Pragma (Ent)) then
17539 Set_Linker_Section_Pragma (Ent, N);
17540
17541 -- A pragma that applies to a Ghost entity becomes
17542 -- Ghost for the purposes of legality checks and
17543 -- removal of ignored Ghost code.
17544
17545 Mark_Ghost_Pragma (N, Ent);
17546
17547 -- Capture the entity of the first Ghost subprogram
17548 -- being processed for error detection purposes.
17549
17550 if Is_Ghost_Entity (Ent) then
17551 if No (Ghost_Id) then
17552 Ghost_Id := Ent;
17553 end if;
17554
17555 -- Otherwise the subprogram is non-Ghost. It is
17556 -- illegal to mix references to Ghost and non-Ghost
17557 -- entities (SPARK RM 6.9).
17558
17559 elsif Present (Ghost_Id)
17560 and then not Ghost_Error_Posted
17561 then
17562 Ghost_Error_Posted := True;
17563
17564 Error_Msg_Name_1 := Pname;
17565 Error_Msg_N
17566 ("pragma % cannot mention ghost and "
17567 & "non-ghost subprograms", N);
17568
17569 Error_Msg_Sloc := Sloc (Ghost_Id);
17570 Error_Msg_NE
17571 ("\& # declared as ghost", N, Ghost_Id);
17572
17573 Error_Msg_Sloc := Sloc (Ent);
17574 Error_Msg_NE
17575 ("\& # declared as non-ghost", N, Ent);
17576 end if;
17577 end if;
17578
17579 Ent := Homonym (Ent);
17580 exit when No (Ent)
17581 or else Scope (Ent) /= Current_Scope;
17582 end loop;
17583 end if;
17584
17585 -- All other cases are illegal
17586
17587 when others =>
17588 Error_Pragma_Arg
17589 ("pragma% applies only to objects, subprograms, and types",
17590 Arg1);
17591 end case;
17592 end Linker_Section;
17593
17594 ----------
17595 -- List --
17596 ----------
17597
17598 -- pragma List (On | Off)
17599
17600 -- There is nothing to do here, since we did all the processing for
17601 -- this pragma in Par.Prag (so that it works properly even in syntax
17602 -- only mode).
17603
17604 when Pragma_List =>
17605 null;
17606
17607 ---------------
17608 -- Lock_Free --
17609 ---------------
17610
17611 -- pragma Lock_Free [(Boolean_EXPRESSION)];
17612
17613 when Pragma_Lock_Free => Lock_Free : declare
17614 P : constant Node_Id := Parent (N);
17615 Arg : Node_Id;
17616 Ent : Entity_Id;
17617 Val : Boolean;
17618
17619 begin
17620 Check_No_Identifiers;
17621 Check_At_Most_N_Arguments (1);
17622
17623 -- Protected definition case
17624
17625 if Nkind (P) = N_Protected_Definition then
17626 Ent := Defining_Identifier (Parent (P));
17627
17628 -- One argument
17629
17630 if Arg_Count = 1 then
17631 Arg := Get_Pragma_Arg (Arg1);
17632 Val := Is_True (Static_Boolean (Arg));
17633
17634 -- No arguments (expression is considered to be True)
17635
17636 else
17637 Val := True;
17638 end if;
17639
17640 -- Check duplicate pragma before we chain the pragma in the Rep
17641 -- Item chain of Ent.
17642
17643 Check_Duplicate_Pragma (Ent);
17644 Record_Rep_Item (Ent, N);
17645 Set_Uses_Lock_Free (Ent, Val);
17646
17647 -- Anything else is incorrect placement
17648
17649 else
17650 Pragma_Misplaced;
17651 end if;
17652 end Lock_Free;
17653
17654 --------------------
17655 -- Locking_Policy --
17656 --------------------
17657
17658 -- pragma Locking_Policy (policy_IDENTIFIER);
17659
17660 when Pragma_Locking_Policy => declare
17661 subtype LP_Range is Name_Id
17662 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
17663 LP_Val : LP_Range;
17664 LP : Character;
17665
17666 begin
17667 Check_Ada_83_Warning;
17668 Check_Arg_Count (1);
17669 Check_No_Identifiers;
17670 Check_Arg_Is_Locking_Policy (Arg1);
17671 Check_Valid_Configuration_Pragma;
17672 LP_Val := Chars (Get_Pragma_Arg (Arg1));
17673
17674 case LP_Val is
17675 when Name_Ceiling_Locking => LP := 'C';
17676 when Name_Concurrent_Readers_Locking => LP := 'R';
17677 when Name_Inheritance_Locking => LP := 'I';
17678 end case;
17679
17680 if Locking_Policy /= ' '
17681 and then Locking_Policy /= LP
17682 then
17683 Error_Msg_Sloc := Locking_Policy_Sloc;
17684 Error_Pragma ("locking policy incompatible with policy#");
17685
17686 -- Set new policy, but always preserve System_Location since we
17687 -- like the error message with the run time name.
17688
17689 else
17690 Locking_Policy := LP;
17691
17692 if Locking_Policy_Sloc /= System_Location then
17693 Locking_Policy_Sloc := Loc;
17694 end if;
17695 end if;
17696 end;
17697
17698 -------------------
17699 -- Loop_Optimize --
17700 -------------------
17701
17702 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
17703
17704 -- OPTIMIZATION_HINT ::=
17705 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
17706
17707 when Pragma_Loop_Optimize => Loop_Optimize : declare
17708 Hint : Node_Id;
17709
17710 begin
17711 GNAT_Pragma;
17712 Check_At_Least_N_Arguments (1);
17713 Check_No_Identifiers;
17714
17715 Hint := First (Pragma_Argument_Associations (N));
17716 while Present (Hint) loop
17717 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
17718 Name_No_Unroll,
17719 Name_Unroll,
17720 Name_No_Vector,
17721 Name_Vector);
17722 Next (Hint);
17723 end loop;
17724
17725 Check_Loop_Pragma_Placement;
17726 end Loop_Optimize;
17727
17728 ------------------
17729 -- Loop_Variant --
17730 ------------------
17731
17732 -- pragma Loop_Variant
17733 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
17734
17735 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
17736
17737 -- CHANGE_DIRECTION ::= Increases | Decreases
17738
17739 when Pragma_Loop_Variant => Loop_Variant : declare
17740 Variant : Node_Id;
17741
17742 begin
17743 GNAT_Pragma;
17744 Check_At_Least_N_Arguments (1);
17745 Check_Loop_Pragma_Placement;
17746
17747 -- Process all increasing / decreasing expressions
17748
17749 Variant := First (Pragma_Argument_Associations (N));
17750 while Present (Variant) loop
17751 if not Nam_In (Chars (Variant), Name_Decreases,
17752 Name_Increases)
17753 then
17754 Error_Pragma_Arg ("wrong change modifier", Variant);
17755 end if;
17756
17757 Preanalyze_Assert_Expression
17758 (Expression (Variant), Any_Discrete);
17759
17760 Next (Variant);
17761 end loop;
17762 end Loop_Variant;
17763
17764 -----------------------
17765 -- Machine_Attribute --
17766 -----------------------
17767
17768 -- pragma Machine_Attribute (
17769 -- [Entity =>] LOCAL_NAME,
17770 -- [Attribute_Name =>] static_string_EXPRESSION
17771 -- [, [Info =>] static_EXPRESSION] );
17772
17773 when Pragma_Machine_Attribute => Machine_Attribute : declare
17774 Def_Id : Entity_Id;
17775
17776 begin
17777 GNAT_Pragma;
17778 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
17779
17780 if Arg_Count = 3 then
17781 Check_Optional_Identifier (Arg3, Name_Info);
17782 Check_Arg_Is_OK_Static_Expression (Arg3);
17783 else
17784 Check_Arg_Count (2);
17785 end if;
17786
17787 Check_Optional_Identifier (Arg1, Name_Entity);
17788 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
17789 Check_Arg_Is_Local_Name (Arg1);
17790 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
17791 Def_Id := Entity (Get_Pragma_Arg (Arg1));
17792
17793 if Is_Access_Type (Def_Id) then
17794 Def_Id := Designated_Type (Def_Id);
17795 end if;
17796
17797 if Rep_Item_Too_Early (Def_Id, N) then
17798 return;
17799 end if;
17800
17801 Def_Id := Underlying_Type (Def_Id);
17802
17803 -- The only processing required is to link this item on to the
17804 -- list of rep items for the given entity. This is accomplished
17805 -- by the call to Rep_Item_Too_Late (when no error is detected
17806 -- and False is returned).
17807
17808 if Rep_Item_Too_Late (Def_Id, N) then
17809 return;
17810 else
17811 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
17812 end if;
17813 end Machine_Attribute;
17814
17815 ----------
17816 -- Main --
17817 ----------
17818
17819 -- pragma Main
17820 -- (MAIN_OPTION [, MAIN_OPTION]);
17821
17822 -- MAIN_OPTION ::=
17823 -- [STACK_SIZE =>] static_integer_EXPRESSION
17824 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
17825 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
17826
17827 when Pragma_Main => Main : declare
17828 Args : Args_List (1 .. 3);
17829 Names : constant Name_List (1 .. 3) := (
17830 Name_Stack_Size,
17831 Name_Task_Stack_Size_Default,
17832 Name_Time_Slicing_Enabled);
17833
17834 Nod : Node_Id;
17835
17836 begin
17837 GNAT_Pragma;
17838 Gather_Associations (Names, Args);
17839
17840 for J in 1 .. 2 loop
17841 if Present (Args (J)) then
17842 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
17843 end if;
17844 end loop;
17845
17846 if Present (Args (3)) then
17847 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
17848 end if;
17849
17850 Nod := Next (N);
17851 while Present (Nod) loop
17852 if Nkind (Nod) = N_Pragma
17853 and then Pragma_Name (Nod) = Name_Main
17854 then
17855 Error_Msg_Name_1 := Pname;
17856 Error_Msg_N ("duplicate pragma% not permitted", Nod);
17857 end if;
17858
17859 Next (Nod);
17860 end loop;
17861 end Main;
17862
17863 ------------------
17864 -- Main_Storage --
17865 ------------------
17866
17867 -- pragma Main_Storage
17868 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
17869
17870 -- MAIN_STORAGE_OPTION ::=
17871 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
17872 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
17873
17874 when Pragma_Main_Storage => Main_Storage : declare
17875 Args : Args_List (1 .. 2);
17876 Names : constant Name_List (1 .. 2) := (
17877 Name_Working_Storage,
17878 Name_Top_Guard);
17879
17880 Nod : Node_Id;
17881
17882 begin
17883 GNAT_Pragma;
17884 Gather_Associations (Names, Args);
17885
17886 for J in 1 .. 2 loop
17887 if Present (Args (J)) then
17888 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
17889 end if;
17890 end loop;
17891
17892 Check_In_Main_Program;
17893
17894 Nod := Next (N);
17895 while Present (Nod) loop
17896 if Nkind (Nod) = N_Pragma
17897 and then Pragma_Name (Nod) = Name_Main_Storage
17898 then
17899 Error_Msg_Name_1 := Pname;
17900 Error_Msg_N ("duplicate pragma% not permitted", Nod);
17901 end if;
17902
17903 Next (Nod);
17904 end loop;
17905 end Main_Storage;
17906
17907 ----------------------
17908 -- Max_Queue_Length --
17909 ----------------------
17910
17911 -- pragma Max_Queue_Length (static_integer_EXPRESSION);
17912
17913 when Pragma_Max_Queue_Length => Max_Queue_Length : declare
17914 Arg : Node_Id;
17915 Entry_Decl : Node_Id;
17916 Entry_Id : Entity_Id;
17917 Val : Uint;
17918
17919 begin
17920 GNAT_Pragma;
17921 Check_Arg_Count (1);
17922
17923 Entry_Decl :=
17924 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
17925
17926 -- Entry declaration
17927
17928 if Nkind (Entry_Decl) = N_Entry_Declaration then
17929
17930 -- Entry illegally within a task
17931
17932 if Nkind (Parent (N)) = N_Task_Definition then
17933 Error_Pragma ("pragma % cannot apply to task entries");
17934 return;
17935 end if;
17936
17937 Entry_Id := Unique_Defining_Entity (Entry_Decl);
17938
17939 -- Otherwise the pragma is associated with an illegal construct
17940
17941 else
17942 Error_Pragma ("pragma % must apply to a protected entry");
17943 return;
17944 end if;
17945
17946 -- Mark the pragma as Ghost if the related subprogram is also
17947 -- Ghost. This also ensures that any expansion performed further
17948 -- below will produce Ghost nodes.
17949
17950 Mark_Ghost_Pragma (N, Entry_Id);
17951
17952 -- Analyze the Integer expression
17953
17954 Arg := Get_Pragma_Arg (Arg1);
17955 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
17956
17957 Val := Expr_Value (Arg);
17958
17959 if Val <= 0 then
17960 Error_Pragma_Arg
17961 ("argument for pragma% must be positive", Arg1);
17962
17963 elsif not UI_Is_In_Int_Range (Val) then
17964 Error_Pragma_Arg
17965 ("argument for pragma% out of range of Integer", Arg1);
17966
17967 end if;
17968
17969 -- Manually substitute the expression value of the pragma argument
17970 -- if it's not an integer literal because this is not taken care
17971 -- of automatically elsewhere.
17972
17973 if Nkind (Arg) /= N_Integer_Literal then
17974 Rewrite (Arg, Make_Integer_Literal (Sloc (Arg), Val));
17975 end if;
17976
17977 Record_Rep_Item (Entry_Id, N);
17978 end Max_Queue_Length;
17979
17980 -----------------
17981 -- Memory_Size --
17982 -----------------
17983
17984 -- pragma Memory_Size (NUMERIC_LITERAL)
17985
17986 when Pragma_Memory_Size =>
17987 GNAT_Pragma;
17988
17989 -- Memory size is simply ignored
17990
17991 Check_No_Identifiers;
17992 Check_Arg_Count (1);
17993 Check_Arg_Is_Integer_Literal (Arg1);
17994
17995 -------------
17996 -- No_Body --
17997 -------------
17998
17999 -- pragma No_Body;
18000
18001 -- The only correct use of this pragma is on its own in a file, in
18002 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
18003 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
18004 -- check for a file containing nothing but a No_Body pragma). If we
18005 -- attempt to process it during normal semantics processing, it means
18006 -- it was misplaced.
18007
18008 when Pragma_No_Body =>
18009 GNAT_Pragma;
18010 Pragma_Misplaced;
18011
18012 -----------------------------
18013 -- No_Elaboration_Code_All --
18014 -----------------------------
18015
18016 -- pragma No_Elaboration_Code_All;
18017
18018 when Pragma_No_Elaboration_Code_All =>
18019 GNAT_Pragma;
18020 Check_Valid_Library_Unit_Pragma;
18021
18022 if Nkind (N) = N_Null_Statement then
18023 return;
18024 end if;
18025
18026 -- Must appear for a spec or generic spec
18027
18028 if not Nkind_In (Unit (Cunit (Current_Sem_Unit)),
18029 N_Generic_Package_Declaration,
18030 N_Generic_Subprogram_Declaration,
18031 N_Package_Declaration,
18032 N_Subprogram_Declaration)
18033 then
18034 Error_Pragma
18035 (Fix_Error
18036 ("pragma% can only occur for package "
18037 & "or subprogram spec"));
18038 end if;
18039
18040 -- Set flag in unit table
18041
18042 Set_No_Elab_Code_All (Current_Sem_Unit);
18043
18044 -- Set restriction No_Elaboration_Code if this is the main unit
18045
18046 if Current_Sem_Unit = Main_Unit then
18047 Set_Restriction (No_Elaboration_Code, N);
18048 end if;
18049
18050 -- If we are in the main unit or in an extended main source unit,
18051 -- then we also add it to the configuration restrictions so that
18052 -- it will apply to all units in the extended main source.
18053
18054 if Current_Sem_Unit = Main_Unit
18055 or else In_Extended_Main_Source_Unit (N)
18056 then
18057 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
18058 end if;
18059
18060 -- If in main extended unit, activate transitive with test
18061
18062 if In_Extended_Main_Source_Unit (N) then
18063 Opt.No_Elab_Code_All_Pragma := N;
18064 end if;
18065
18066 -----------------------------
18067 -- No_Component_Reordering --
18068 -----------------------------
18069
18070 -- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
18071
18072 when Pragma_No_Component_Reordering => No_Comp_Reordering : declare
18073 E : Entity_Id;
18074 E_Id : Node_Id;
18075
18076 begin
18077 GNAT_Pragma;
18078 Check_At_Most_N_Arguments (1);
18079
18080 if Arg_Count = 0 then
18081 Check_Valid_Configuration_Pragma;
18082 Opt.No_Component_Reordering := True;
18083
18084 else
18085 Check_Optional_Identifier (Arg2, Name_Entity);
18086 Check_Arg_Is_Local_Name (Arg1);
18087 E_Id := Get_Pragma_Arg (Arg1);
18088
18089 if Etype (E_Id) = Any_Type then
18090 return;
18091 end if;
18092
18093 E := Entity (E_Id);
18094
18095 if not Is_Record_Type (E) then
18096 Error_Pragma_Arg ("pragma% requires record type", Arg1);
18097 end if;
18098
18099 Set_No_Reordering (Base_Type (E));
18100 end if;
18101 end No_Comp_Reordering;
18102
18103 --------------------------
18104 -- No_Heap_Finalization --
18105 --------------------------
18106
18107 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
18108
18109 when Pragma_No_Heap_Finalization => No_Heap_Finalization : declare
18110 Context : constant Node_Id := Parent (N);
18111 Typ_Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
18112 Prev : Node_Id;
18113 Typ : Entity_Id;
18114
18115 begin
18116 GNAT_Pragma;
18117 Check_No_Identifiers;
18118
18119 -- The pragma appears in a configuration file
18120
18121 if No (Context) then
18122 Check_Arg_Count (0);
18123 Check_Valid_Configuration_Pragma;
18124
18125 -- Detect a duplicate pragma
18126
18127 if Present (No_Heap_Finalization_Pragma) then
18128 Duplication_Error
18129 (Prag => N,
18130 Prev => No_Heap_Finalization_Pragma);
18131 raise Pragma_Exit;
18132 end if;
18133
18134 No_Heap_Finalization_Pragma := N;
18135
18136 -- Otherwise the pragma should be associated with a library-level
18137 -- named access-to-object type.
18138
18139 else
18140 Check_Arg_Count (1);
18141 Check_Arg_Is_Local_Name (Arg1);
18142
18143 Find_Type (Typ_Arg);
18144 Typ := Entity (Typ_Arg);
18145
18146 -- The type being subjected to the pragma is erroneous
18147
18148 if Typ = Any_Type then
18149 Error_Pragma ("cannot find type referenced by pragma %");
18150
18151 -- The pragma is applied to an incomplete or generic formal
18152 -- type way too early.
18153
18154 elsif Rep_Item_Too_Early (Typ, N) then
18155 return;
18156
18157 else
18158 Typ := Underlying_Type (Typ);
18159 end if;
18160
18161 -- The pragma must apply to an access-to-object type
18162
18163 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type) then
18164 null;
18165
18166 -- Give a detailed error message on all other access type kinds
18167
18168 elsif Ekind (Typ) = E_Access_Protected_Subprogram_Type then
18169 Error_Pragma
18170 ("pragma % cannot apply to access protected subprogram "
18171 & "type");
18172
18173 elsif Ekind (Typ) = E_Access_Subprogram_Type then
18174 Error_Pragma
18175 ("pragma % cannot apply to access subprogram type");
18176
18177 elsif Is_Anonymous_Access_Type (Typ) then
18178 Error_Pragma
18179 ("pragma % cannot apply to anonymous access type");
18180
18181 -- Give a general error message in case the pragma applies to a
18182 -- non-access type.
18183
18184 else
18185 Error_Pragma
18186 ("pragma % must apply to library level access type");
18187 end if;
18188
18189 -- At this point the argument denotes an access-to-object type.
18190 -- Ensure that the type is declared at the library level.
18191
18192 if Is_Library_Level_Entity (Typ) then
18193 null;
18194
18195 -- Quietly ignore an access-to-object type originally declared
18196 -- at the library level within a generic, but instantiated at
18197 -- a non-library level. As a result the access-to-object type
18198 -- "loses" its No_Heap_Finalization property.
18199
18200 elsif In_Instance then
18201 raise Pragma_Exit;
18202
18203 else
18204 Error_Pragma
18205 ("pragma % must apply to library level access type");
18206 end if;
18207
18208 -- Detect a duplicate pragma
18209
18210 if Present (No_Heap_Finalization_Pragma) then
18211 Duplication_Error
18212 (Prag => N,
18213 Prev => No_Heap_Finalization_Pragma);
18214 raise Pragma_Exit;
18215
18216 else
18217 Prev := Get_Pragma (Typ, Pragma_No_Heap_Finalization);
18218
18219 if Present (Prev) then
18220 Duplication_Error
18221 (Prag => N,
18222 Prev => Prev);
18223 raise Pragma_Exit;
18224 end if;
18225 end if;
18226
18227 Record_Rep_Item (Typ, N);
18228 end if;
18229 end No_Heap_Finalization;
18230
18231 ---------------
18232 -- No_Inline --
18233 ---------------
18234
18235 -- pragma No_Inline ( NAME {, NAME} );
18236
18237 when Pragma_No_Inline =>
18238 GNAT_Pragma;
18239 Process_Inline (Suppressed);
18240
18241 ---------------
18242 -- No_Return --
18243 ---------------
18244
18245 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
18246
18247 when Pragma_No_Return => No_Return : declare
18248 Arg : Node_Id;
18249 E : Entity_Id;
18250 Found : Boolean;
18251 Id : Node_Id;
18252
18253 Ghost_Error_Posted : Boolean := False;
18254 -- Flag set when an error concerning the illegal mix of Ghost and
18255 -- non-Ghost subprograms is emitted.
18256
18257 Ghost_Id : Entity_Id := Empty;
18258 -- The entity of the first Ghost procedure encountered while
18259 -- processing the arguments of the pragma.
18260
18261 begin
18262 Ada_2005_Pragma;
18263 Check_At_Least_N_Arguments (1);
18264
18265 -- Loop through arguments of pragma
18266
18267 Arg := Arg1;
18268 while Present (Arg) loop
18269 Check_Arg_Is_Local_Name (Arg);
18270 Id := Get_Pragma_Arg (Arg);
18271 Analyze (Id);
18272
18273 if not Is_Entity_Name (Id) then
18274 Error_Pragma_Arg ("entity name required", Arg);
18275 end if;
18276
18277 if Etype (Id) = Any_Type then
18278 raise Pragma_Exit;
18279 end if;
18280
18281 -- Loop to find matching procedures
18282
18283 E := Entity (Id);
18284
18285 Found := False;
18286 while Present (E)
18287 and then Scope (E) = Current_Scope
18288 loop
18289 if Ekind_In (E, E_Generic_Procedure, E_Procedure) then
18290
18291 -- Check that the pragma is not applied to a body.
18292 -- First check the specless body case, to give a
18293 -- different error message. These checks do not apply
18294 -- if Relaxed_RM_Semantics, to accommodate other Ada
18295 -- compilers. Disable these checks under -gnatd.J.
18296
18297 if not Debug_Flag_Dot_JJ then
18298 if Nkind (Parent (Declaration_Node (E))) =
18299 N_Subprogram_Body
18300 and then not Relaxed_RM_Semantics
18301 then
18302 Error_Pragma
18303 ("pragma% requires separate spec and must come "
18304 & "before body");
18305 end if;
18306
18307 -- Now the "specful" body case
18308
18309 if Rep_Item_Too_Late (E, N) then
18310 raise Pragma_Exit;
18311 end if;
18312 end if;
18313
18314 Set_No_Return (E);
18315
18316 -- A pragma that applies to a Ghost entity becomes Ghost
18317 -- for the purposes of legality checks and removal of
18318 -- ignored Ghost code.
18319
18320 Mark_Ghost_Pragma (N, E);
18321
18322 -- Capture the entity of the first Ghost procedure being
18323 -- processed for error detection purposes.
18324
18325 if Is_Ghost_Entity (E) then
18326 if No (Ghost_Id) then
18327 Ghost_Id := E;
18328 end if;
18329
18330 -- Otherwise the subprogram is non-Ghost. It is illegal
18331 -- to mix references to Ghost and non-Ghost entities
18332 -- (SPARK RM 6.9).
18333
18334 elsif Present (Ghost_Id)
18335 and then not Ghost_Error_Posted
18336 then
18337 Ghost_Error_Posted := True;
18338
18339 Error_Msg_Name_1 := Pname;
18340 Error_Msg_N
18341 ("pragma % cannot mention ghost and non-ghost "
18342 & "procedures", N);
18343
18344 Error_Msg_Sloc := Sloc (Ghost_Id);
18345 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
18346
18347 Error_Msg_Sloc := Sloc (E);
18348 Error_Msg_NE ("\& # declared as non-ghost", N, E);
18349 end if;
18350
18351 -- Set flag on any alias as well
18352
18353 if Is_Overloadable (E) and then Present (Alias (E)) then
18354 Set_No_Return (Alias (E));
18355 end if;
18356
18357 Found := True;
18358 end if;
18359
18360 exit when From_Aspect_Specification (N);
18361 E := Homonym (E);
18362 end loop;
18363
18364 -- If entity in not in current scope it may be the enclosing
18365 -- suprogram body to which the aspect applies.
18366
18367 if not Found then
18368 if Entity (Id) = Current_Scope
18369 and then From_Aspect_Specification (N)
18370 then
18371 Set_No_Return (Entity (Id));
18372 else
18373 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
18374 end if;
18375 end if;
18376
18377 Next (Arg);
18378 end loop;
18379 end No_Return;
18380
18381 -----------------
18382 -- No_Run_Time --
18383 -----------------
18384
18385 -- pragma No_Run_Time;
18386
18387 -- Note: this pragma is retained for backwards compatibility. See
18388 -- body of Rtsfind for full details on its handling.
18389
18390 when Pragma_No_Run_Time =>
18391 GNAT_Pragma;
18392 Check_Valid_Configuration_Pragma;
18393 Check_Arg_Count (0);
18394
18395 -- Remove backward compatibility if Build_Type is FSF or GPL and
18396 -- generate a warning.
18397
18398 declare
18399 Ignore : constant Boolean := Build_Type in FSF .. GPL;
18400 begin
18401 if Ignore then
18402 Error_Pragma ("pragma% is ignored, has no effect??");
18403 else
18404 No_Run_Time_Mode := True;
18405 Configurable_Run_Time_Mode := True;
18406
18407 -- Set Duration to 32 bits if word size is 32
18408
18409 if Ttypes.System_Word_Size = 32 then
18410 Duration_32_Bits_On_Target := True;
18411 end if;
18412
18413 -- Set appropriate restrictions
18414
18415 Set_Restriction (No_Finalization, N);
18416 Set_Restriction (No_Exception_Handlers, N);
18417 Set_Restriction (Max_Tasks, N, 0);
18418 Set_Restriction (No_Tasking, N);
18419 end if;
18420 end;
18421
18422 -----------------------
18423 -- No_Tagged_Streams --
18424 -----------------------
18425
18426 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
18427
18428 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
18429 E : Entity_Id;
18430 E_Id : Node_Id;
18431
18432 begin
18433 GNAT_Pragma;
18434 Check_At_Most_N_Arguments (1);
18435
18436 -- One argument case
18437
18438 if Arg_Count = 1 then
18439 Check_Optional_Identifier (Arg1, Name_Entity);
18440 Check_Arg_Is_Local_Name (Arg1);
18441 E_Id := Get_Pragma_Arg (Arg1);
18442
18443 if Etype (E_Id) = Any_Type then
18444 return;
18445 end if;
18446
18447 E := Entity (E_Id);
18448
18449 Check_Duplicate_Pragma (E);
18450
18451 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
18452 Error_Pragma_Arg
18453 ("argument for pragma% must be root tagged type", Arg1);
18454 end if;
18455
18456 if Rep_Item_Too_Early (E, N)
18457 or else
18458 Rep_Item_Too_Late (E, N)
18459 then
18460 return;
18461 else
18462 Set_No_Tagged_Streams_Pragma (E, N);
18463 end if;
18464
18465 -- Zero argument case
18466
18467 else
18468 Check_Is_In_Decl_Part_Or_Package_Spec;
18469 No_Tagged_Streams := N;
18470 end if;
18471 end No_Tagged_Strms;
18472
18473 ------------------------
18474 -- No_Strict_Aliasing --
18475 ------------------------
18476
18477 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
18478
18479 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
18480 E : Entity_Id;
18481 E_Id : Node_Id;
18482
18483 begin
18484 GNAT_Pragma;
18485 Check_At_Most_N_Arguments (1);
18486
18487 if Arg_Count = 0 then
18488 Check_Valid_Configuration_Pragma;
18489 Opt.No_Strict_Aliasing := True;
18490
18491 else
18492 Check_Optional_Identifier (Arg2, Name_Entity);
18493 Check_Arg_Is_Local_Name (Arg1);
18494 E_Id := Get_Pragma_Arg (Arg1);
18495
18496 if Etype (E_Id) = Any_Type then
18497 return;
18498 end if;
18499
18500 E := Entity (E_Id);
18501
18502 if not Is_Access_Type (E) then
18503 Error_Pragma_Arg ("pragma% requires access type", Arg1);
18504 end if;
18505
18506 Set_No_Strict_Aliasing (Base_Type (E));
18507 end if;
18508 end No_Strict_Aliasing;
18509
18510 -----------------------
18511 -- Normalize_Scalars --
18512 -----------------------
18513
18514 -- pragma Normalize_Scalars;
18515
18516 when Pragma_Normalize_Scalars =>
18517 Check_Ada_83_Warning;
18518 Check_Arg_Count (0);
18519 Check_Valid_Configuration_Pragma;
18520
18521 -- Normalize_Scalars creates false positives in CodePeer, and
18522 -- incorrect negative results in GNATprove mode, so ignore this
18523 -- pragma in these modes.
18524
18525 if not (CodePeer_Mode or GNATprove_Mode) then
18526 Normalize_Scalars := True;
18527 Init_Or_Norm_Scalars := True;
18528 end if;
18529
18530 -----------------
18531 -- Obsolescent --
18532 -----------------
18533
18534 -- pragma Obsolescent;
18535
18536 -- pragma Obsolescent (
18537 -- [Message =>] static_string_EXPRESSION
18538 -- [,[Version =>] Ada_05]]);
18539
18540 -- pragma Obsolescent (
18541 -- [Entity =>] NAME
18542 -- [,[Message =>] static_string_EXPRESSION
18543 -- [,[Version =>] Ada_05]] );
18544
18545 when Pragma_Obsolescent => Obsolescent : declare
18546 Decl : Node_Id;
18547 Ename : Node_Id;
18548
18549 procedure Set_Obsolescent (E : Entity_Id);
18550 -- Given an entity Ent, mark it as obsolescent if appropriate
18551
18552 ---------------------
18553 -- Set_Obsolescent --
18554 ---------------------
18555
18556 procedure Set_Obsolescent (E : Entity_Id) is
18557 Active : Boolean;
18558 Ent : Entity_Id;
18559 S : String_Id;
18560
18561 begin
18562 Active := True;
18563 Ent := E;
18564
18565 -- A pragma that applies to a Ghost entity becomes Ghost for
18566 -- the purposes of legality checks and removal of ignored Ghost
18567 -- code.
18568
18569 Mark_Ghost_Pragma (N, E);
18570
18571 -- Entity name was given
18572
18573 if Present (Ename) then
18574
18575 -- If entity name matches, we are fine. Save entity in
18576 -- pragma argument, for ASIS use.
18577
18578 if Chars (Ename) = Chars (Ent) then
18579 Set_Entity (Ename, Ent);
18580 Generate_Reference (Ent, Ename);
18581
18582 -- If entity name does not match, only possibility is an
18583 -- enumeration literal from an enumeration type declaration.
18584
18585 elsif Ekind (Ent) /= E_Enumeration_Type then
18586 Error_Pragma
18587 ("pragma % entity name does not match declaration");
18588
18589 else
18590 Ent := First_Literal (E);
18591 loop
18592 if No (Ent) then
18593 Error_Pragma
18594 ("pragma % entity name does not match any "
18595 & "enumeration literal");
18596
18597 elsif Chars (Ent) = Chars (Ename) then
18598 Set_Entity (Ename, Ent);
18599 Generate_Reference (Ent, Ename);
18600 exit;
18601
18602 else
18603 Ent := Next_Literal (Ent);
18604 end if;
18605 end loop;
18606 end if;
18607 end if;
18608
18609 -- Ent points to entity to be marked
18610
18611 if Arg_Count >= 1 then
18612
18613 -- Deal with static string argument
18614
18615 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18616 S := Strval (Get_Pragma_Arg (Arg1));
18617
18618 for J in 1 .. String_Length (S) loop
18619 if not In_Character_Range (Get_String_Char (S, J)) then
18620 Error_Pragma_Arg
18621 ("pragma% argument does not allow wide characters",
18622 Arg1);
18623 end if;
18624 end loop;
18625
18626 Obsolescent_Warnings.Append
18627 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
18628
18629 -- Check for Ada_05 parameter
18630
18631 if Arg_Count /= 1 then
18632 Check_Arg_Count (2);
18633
18634 declare
18635 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
18636
18637 begin
18638 Check_Arg_Is_Identifier (Argx);
18639
18640 if Chars (Argx) /= Name_Ada_05 then
18641 Error_Msg_Name_2 := Name_Ada_05;
18642 Error_Pragma_Arg
18643 ("only allowed argument for pragma% is %", Argx);
18644 end if;
18645
18646 if Ada_Version_Explicit < Ada_2005
18647 or else not Warn_On_Ada_2005_Compatibility
18648 then
18649 Active := False;
18650 end if;
18651 end;
18652 end if;
18653 end if;
18654
18655 -- Set flag if pragma active
18656
18657 if Active then
18658 Set_Is_Obsolescent (Ent);
18659 end if;
18660
18661 return;
18662 end Set_Obsolescent;
18663
18664 -- Start of processing for pragma Obsolescent
18665
18666 begin
18667 GNAT_Pragma;
18668
18669 Check_At_Most_N_Arguments (3);
18670
18671 -- See if first argument specifies an entity name
18672
18673 if Arg_Count >= 1
18674 and then
18675 (Chars (Arg1) = Name_Entity
18676 or else
18677 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
18678 N_Identifier,
18679 N_Operator_Symbol))
18680 then
18681 Ename := Get_Pragma_Arg (Arg1);
18682
18683 -- Eliminate first argument, so we can share processing
18684
18685 Arg1 := Arg2;
18686 Arg2 := Arg3;
18687 Arg_Count := Arg_Count - 1;
18688
18689 -- No Entity name argument given
18690
18691 else
18692 Ename := Empty;
18693 end if;
18694
18695 if Arg_Count >= 1 then
18696 Check_Optional_Identifier (Arg1, Name_Message);
18697
18698 if Arg_Count = 2 then
18699 Check_Optional_Identifier (Arg2, Name_Version);
18700 end if;
18701 end if;
18702
18703 -- Get immediately preceding declaration
18704
18705 Decl := Prev (N);
18706 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
18707 Prev (Decl);
18708 end loop;
18709
18710 -- Cases where we do not follow anything other than another pragma
18711
18712 if No (Decl) then
18713
18714 -- First case: library level compilation unit declaration with
18715 -- the pragma immediately following the declaration.
18716
18717 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
18718 Set_Obsolescent
18719 (Defining_Entity (Unit (Parent (Parent (N)))));
18720 return;
18721
18722 -- Case 2: library unit placement for package
18723
18724 else
18725 declare
18726 Ent : constant Entity_Id := Find_Lib_Unit_Name;
18727 begin
18728 if Is_Package_Or_Generic_Package (Ent) then
18729 Set_Obsolescent (Ent);
18730 return;
18731 end if;
18732 end;
18733 end if;
18734
18735 -- Cases where we must follow a declaration, including an
18736 -- abstract subprogram declaration, which is not in the
18737 -- other node subtypes.
18738
18739 else
18740 if Nkind (Decl) not in N_Declaration
18741 and then Nkind (Decl) not in N_Later_Decl_Item
18742 and then Nkind (Decl) not in N_Generic_Declaration
18743 and then Nkind (Decl) not in N_Renaming_Declaration
18744 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
18745 then
18746 Error_Pragma
18747 ("pragma% misplaced, "
18748 & "must immediately follow a declaration");
18749
18750 else
18751 Set_Obsolescent (Defining_Entity (Decl));
18752 return;
18753 end if;
18754 end if;
18755 end Obsolescent;
18756
18757 --------------
18758 -- Optimize --
18759 --------------
18760
18761 -- pragma Optimize (Time | Space | Off);
18762
18763 -- The actual check for optimize is done in Gigi. Note that this
18764 -- pragma does not actually change the optimization setting, it
18765 -- simply checks that it is consistent with the pragma.
18766
18767 when Pragma_Optimize =>
18768 Check_No_Identifiers;
18769 Check_Arg_Count (1);
18770 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
18771
18772 ------------------------
18773 -- Optimize_Alignment --
18774 ------------------------
18775
18776 -- pragma Optimize_Alignment (Time | Space | Off);
18777
18778 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
18779 GNAT_Pragma;
18780 Check_No_Identifiers;
18781 Check_Arg_Count (1);
18782 Check_Valid_Configuration_Pragma;
18783
18784 declare
18785 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
18786 begin
18787 case Nam is
18788 when Name_Off => Opt.Optimize_Alignment := 'O';
18789 when Name_Space => Opt.Optimize_Alignment := 'S';
18790 when Name_Time => Opt.Optimize_Alignment := 'T';
18791
18792 when others =>
18793 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
18794 end case;
18795 end;
18796
18797 -- Set indication that mode is set locally. If we are in fact in a
18798 -- configuration pragma file, this setting is harmless since the
18799 -- switch will get reset anyway at the start of each unit.
18800
18801 Optimize_Alignment_Local := True;
18802 end Optimize_Alignment;
18803
18804 -------------
18805 -- Ordered --
18806 -------------
18807
18808 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
18809
18810 when Pragma_Ordered => Ordered : declare
18811 Assoc : constant Node_Id := Arg1;
18812 Type_Id : Node_Id;
18813 Typ : Entity_Id;
18814
18815 begin
18816 GNAT_Pragma;
18817 Check_No_Identifiers;
18818 Check_Arg_Count (1);
18819 Check_Arg_Is_Local_Name (Arg1);
18820
18821 Type_Id := Get_Pragma_Arg (Assoc);
18822 Find_Type (Type_Id);
18823 Typ := Entity (Type_Id);
18824
18825 if Typ = Any_Type then
18826 return;
18827 else
18828 Typ := Underlying_Type (Typ);
18829 end if;
18830
18831 if not Is_Enumeration_Type (Typ) then
18832 Error_Pragma ("pragma% must specify enumeration type");
18833 end if;
18834
18835 Check_First_Subtype (Arg1);
18836 Set_Has_Pragma_Ordered (Base_Type (Typ));
18837 end Ordered;
18838
18839 -------------------
18840 -- Overflow_Mode --
18841 -------------------
18842
18843 -- pragma Overflow_Mode
18844 -- ([General => ] MODE [, [Assertions => ] MODE]);
18845
18846 -- MODE := STRICT | MINIMIZED | ELIMINATED
18847
18848 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
18849 -- since System.Bignums makes this assumption. This is true of nearly
18850 -- all (all?) targets.
18851
18852 when Pragma_Overflow_Mode => Overflow_Mode : declare
18853 function Get_Overflow_Mode
18854 (Name : Name_Id;
18855 Arg : Node_Id) return Overflow_Mode_Type;
18856 -- Function to process one pragma argument, Arg. If an identifier
18857 -- is present, it must be Name. Mode type is returned if a valid
18858 -- argument exists, otherwise an error is signalled.
18859
18860 -----------------------
18861 -- Get_Overflow_Mode --
18862 -----------------------
18863
18864 function Get_Overflow_Mode
18865 (Name : Name_Id;
18866 Arg : Node_Id) return Overflow_Mode_Type
18867 is
18868 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
18869
18870 begin
18871 Check_Optional_Identifier (Arg, Name);
18872 Check_Arg_Is_Identifier (Argx);
18873
18874 if Chars (Argx) = Name_Strict then
18875 return Strict;
18876
18877 elsif Chars (Argx) = Name_Minimized then
18878 return Minimized;
18879
18880 elsif Chars (Argx) = Name_Eliminated then
18881 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
18882 Error_Pragma_Arg
18883 ("Eliminated not implemented on this target", Argx);
18884 else
18885 return Eliminated;
18886 end if;
18887
18888 else
18889 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
18890 end if;
18891 end Get_Overflow_Mode;
18892
18893 -- Start of processing for Overflow_Mode
18894
18895 begin
18896 GNAT_Pragma;
18897 Check_At_Least_N_Arguments (1);
18898 Check_At_Most_N_Arguments (2);
18899
18900 -- Process first argument
18901
18902 Scope_Suppress.Overflow_Mode_General :=
18903 Get_Overflow_Mode (Name_General, Arg1);
18904
18905 -- Case of only one argument
18906
18907 if Arg_Count = 1 then
18908 Scope_Suppress.Overflow_Mode_Assertions :=
18909 Scope_Suppress.Overflow_Mode_General;
18910
18911 -- Case of two arguments present
18912
18913 else
18914 Scope_Suppress.Overflow_Mode_Assertions :=
18915 Get_Overflow_Mode (Name_Assertions, Arg2);
18916 end if;
18917 end Overflow_Mode;
18918
18919 --------------------------
18920 -- Overriding Renamings --
18921 --------------------------
18922
18923 -- pragma Overriding_Renamings;
18924
18925 when Pragma_Overriding_Renamings =>
18926 GNAT_Pragma;
18927 Check_Arg_Count (0);
18928 Check_Valid_Configuration_Pragma;
18929 Overriding_Renamings := True;
18930
18931 ----------
18932 -- Pack --
18933 ----------
18934
18935 -- pragma Pack (first_subtype_LOCAL_NAME);
18936
18937 when Pragma_Pack => Pack : declare
18938 Assoc : constant Node_Id := Arg1;
18939 Ctyp : Entity_Id;
18940 Ignore : Boolean := False;
18941 Typ : Entity_Id;
18942 Type_Id : Node_Id;
18943
18944 begin
18945 Check_No_Identifiers;
18946 Check_Arg_Count (1);
18947 Check_Arg_Is_Local_Name (Arg1);
18948 Type_Id := Get_Pragma_Arg (Assoc);
18949
18950 if not Is_Entity_Name (Type_Id)
18951 or else not Is_Type (Entity (Type_Id))
18952 then
18953 Error_Pragma_Arg
18954 ("argument for pragma% must be type or subtype", Arg1);
18955 end if;
18956
18957 Find_Type (Type_Id);
18958 Typ := Entity (Type_Id);
18959
18960 if Typ = Any_Type
18961 or else Rep_Item_Too_Early (Typ, N)
18962 then
18963 return;
18964 else
18965 Typ := Underlying_Type (Typ);
18966 end if;
18967
18968 -- A pragma that applies to a Ghost entity becomes Ghost for the
18969 -- purposes of legality checks and removal of ignored Ghost code.
18970
18971 Mark_Ghost_Pragma (N, Typ);
18972
18973 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
18974 Error_Pragma ("pragma% must specify array or record type");
18975 end if;
18976
18977 Check_First_Subtype (Arg1);
18978 Check_Duplicate_Pragma (Typ);
18979
18980 -- Array type
18981
18982 if Is_Array_Type (Typ) then
18983 Ctyp := Component_Type (Typ);
18984
18985 -- Ignore pack that does nothing
18986
18987 if Known_Static_Esize (Ctyp)
18988 and then Known_Static_RM_Size (Ctyp)
18989 and then Esize (Ctyp) = RM_Size (Ctyp)
18990 and then Addressable (Esize (Ctyp))
18991 then
18992 Ignore := True;
18993 end if;
18994
18995 -- Process OK pragma Pack. Note that if there is a separate
18996 -- component clause present, the Pack will be cancelled. This
18997 -- processing is in Freeze.
18998
18999 if not Rep_Item_Too_Late (Typ, N) then
19000
19001 -- In CodePeer mode, we do not need complex front-end
19002 -- expansions related to pragma Pack, so disable handling
19003 -- of pragma Pack.
19004
19005 if CodePeer_Mode then
19006 null;
19007
19008 -- Normal case where we do the pack action
19009
19010 else
19011 if not Ignore then
19012 Set_Is_Packed (Base_Type (Typ));
19013 Set_Has_Non_Standard_Rep (Base_Type (Typ));
19014 end if;
19015
19016 Set_Has_Pragma_Pack (Base_Type (Typ));
19017 end if;
19018 end if;
19019
19020 -- For record types, the pack is always effective
19021
19022 else pragma Assert (Is_Record_Type (Typ));
19023 if not Rep_Item_Too_Late (Typ, N) then
19024 Set_Is_Packed (Base_Type (Typ));
19025 Set_Has_Pragma_Pack (Base_Type (Typ));
19026 Set_Has_Non_Standard_Rep (Base_Type (Typ));
19027 end if;
19028 end if;
19029 end Pack;
19030
19031 ----------
19032 -- Page --
19033 ----------
19034
19035 -- pragma Page;
19036
19037 -- There is nothing to do here, since we did all the processing for
19038 -- this pragma in Par.Prag (so that it works properly even in syntax
19039 -- only mode).
19040
19041 when Pragma_Page =>
19042 null;
19043
19044 -------------
19045 -- Part_Of --
19046 -------------
19047
19048 -- pragma Part_Of (ABSTRACT_STATE);
19049
19050 -- ABSTRACT_STATE ::= NAME
19051
19052 when Pragma_Part_Of => Part_Of : declare
19053 procedure Propagate_Part_Of
19054 (Pack_Id : Entity_Id;
19055 State_Id : Entity_Id;
19056 Instance : Node_Id);
19057 -- Propagate the Part_Of indicator to all abstract states and
19058 -- objects declared in the visible state space of a package
19059 -- denoted by Pack_Id. State_Id is the encapsulating state.
19060 -- Instance is the package instantiation node.
19061
19062 -----------------------
19063 -- Propagate_Part_Of --
19064 -----------------------
19065
19066 procedure Propagate_Part_Of
19067 (Pack_Id : Entity_Id;
19068 State_Id : Entity_Id;
19069 Instance : Node_Id)
19070 is
19071 Has_Item : Boolean := False;
19072 -- Flag set when the visible state space contains at least one
19073 -- abstract state or variable.
19074
19075 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
19076 -- Propagate the Part_Of indicator to all abstract states and
19077 -- objects declared in the visible state space of a package
19078 -- denoted by Pack_Id.
19079
19080 -----------------------
19081 -- Propagate_Part_Of --
19082 -----------------------
19083
19084 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
19085 Constits : Elist_Id;
19086 Item_Id : Entity_Id;
19087
19088 begin
19089 -- Traverse the entity chain of the package and set relevant
19090 -- attributes of abstract states and objects declared in the
19091 -- visible state space of the package.
19092
19093 Item_Id := First_Entity (Pack_Id);
19094 while Present (Item_Id)
19095 and then not In_Private_Part (Item_Id)
19096 loop
19097 -- Do not consider internally generated items
19098
19099 if not Comes_From_Source (Item_Id) then
19100 null;
19101
19102 -- The Part_Of indicator turns an abstract state or an
19103 -- object into a constituent of the encapsulating state.
19104
19105 elsif Ekind_In (Item_Id, E_Abstract_State,
19106 E_Constant,
19107 E_Variable)
19108 then
19109 Has_Item := True;
19110 Constits := Part_Of_Constituents (State_Id);
19111
19112 if No (Constits) then
19113 Constits := New_Elmt_List;
19114 Set_Part_Of_Constituents (State_Id, Constits);
19115 end if;
19116
19117 Append_Elmt (Item_Id, Constits);
19118 Set_Encapsulating_State (Item_Id, State_Id);
19119
19120 -- Recursively handle nested packages and instantiations
19121
19122 elsif Ekind (Item_Id) = E_Package then
19123 Propagate_Part_Of (Item_Id);
19124 end if;
19125
19126 Next_Entity (Item_Id);
19127 end loop;
19128 end Propagate_Part_Of;
19129
19130 -- Start of processing for Propagate_Part_Of
19131
19132 begin
19133 Propagate_Part_Of (Pack_Id);
19134
19135 -- Detect a package instantiation that is subject to a Part_Of
19136 -- indicator, but has no visible state.
19137
19138 if not Has_Item then
19139 SPARK_Msg_NE
19140 ("package instantiation & has Part_Of indicator but "
19141 & "lacks visible state", Instance, Pack_Id);
19142 end if;
19143 end Propagate_Part_Of;
19144
19145 -- Local variables
19146
19147 Constits : Elist_Id;
19148 Encap : Node_Id;
19149 Encap_Id : Entity_Id;
19150 Item_Id : Entity_Id;
19151 Legal : Boolean;
19152 Stmt : Node_Id;
19153
19154 -- Start of processing for Part_Of
19155
19156 begin
19157 GNAT_Pragma;
19158 Check_No_Identifiers;
19159 Check_Arg_Count (1);
19160
19161 Stmt := Find_Related_Context (N, Do_Checks => True);
19162
19163 -- Object declaration
19164
19165 if Nkind (Stmt) = N_Object_Declaration then
19166 null;
19167
19168 -- Package instantiation
19169
19170 elsif Nkind (Stmt) = N_Package_Instantiation then
19171 null;
19172
19173 -- Single concurrent type declaration
19174
19175 elsif Is_Single_Concurrent_Type_Declaration (Stmt) then
19176 null;
19177
19178 -- Otherwise the pragma is associated with an illegal construct
19179
19180 else
19181 Pragma_Misplaced;
19182 return;
19183 end if;
19184
19185 -- Extract the entity of the related object declaration or package
19186 -- instantiation. In the case of the instantiation, use the entity
19187 -- of the instance spec.
19188
19189 if Nkind (Stmt) = N_Package_Instantiation then
19190 Stmt := Instance_Spec (Stmt);
19191 end if;
19192
19193 Item_Id := Defining_Entity (Stmt);
19194
19195 -- A pragma that applies to a Ghost entity becomes Ghost for the
19196 -- purposes of legality checks and removal of ignored Ghost code.
19197
19198 Mark_Ghost_Pragma (N, Item_Id);
19199
19200 -- Chain the pragma on the contract for further processing by
19201 -- Analyze_Part_Of_In_Decl_Part or for completeness.
19202
19203 Add_Contract_Item (N, Item_Id);
19204
19205 -- A variable may act as constituent of a single concurrent type
19206 -- which in turn could be declared after the variable. Due to this
19207 -- discrepancy, the full analysis of indicator Part_Of is delayed
19208 -- until the end of the enclosing declarative region (see routine
19209 -- Analyze_Part_Of_In_Decl_Part).
19210
19211 if Ekind (Item_Id) = E_Variable then
19212 null;
19213
19214 -- Otherwise indicator Part_Of applies to a constant or a package
19215 -- instantiation.
19216
19217 else
19218 Encap := Get_Pragma_Arg (Arg1);
19219
19220 -- Detect any discrepancies between the placement of the
19221 -- constant or package instantiation with respect to state
19222 -- space and the encapsulating state.
19223
19224 Analyze_Part_Of
19225 (Indic => N,
19226 Item_Id => Item_Id,
19227 Encap => Encap,
19228 Encap_Id => Encap_Id,
19229 Legal => Legal);
19230
19231 if Legal then
19232 pragma Assert (Present (Encap_Id));
19233
19234 if Ekind (Item_Id) = E_Constant then
19235 Constits := Part_Of_Constituents (Encap_Id);
19236
19237 if No (Constits) then
19238 Constits := New_Elmt_List;
19239 Set_Part_Of_Constituents (Encap_Id, Constits);
19240 end if;
19241
19242 Append_Elmt (Item_Id, Constits);
19243 Set_Encapsulating_State (Item_Id, Encap_Id);
19244
19245 -- Propagate the Part_Of indicator to the visible state
19246 -- space of the package instantiation.
19247
19248 else
19249 Propagate_Part_Of
19250 (Pack_Id => Item_Id,
19251 State_Id => Encap_Id,
19252 Instance => Stmt);
19253 end if;
19254 end if;
19255 end if;
19256 end Part_Of;
19257
19258 ----------------------------------
19259 -- Partition_Elaboration_Policy --
19260 ----------------------------------
19261
19262 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
19263
19264 when Pragma_Partition_Elaboration_Policy => PEP : declare
19265 subtype PEP_Range is Name_Id
19266 range First_Partition_Elaboration_Policy_Name
19267 .. Last_Partition_Elaboration_Policy_Name;
19268 PEP_Val : PEP_Range;
19269 PEP : Character;
19270
19271 begin
19272 Ada_2005_Pragma;
19273 Check_Arg_Count (1);
19274 Check_No_Identifiers;
19275 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
19276 Check_Valid_Configuration_Pragma;
19277 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
19278
19279 case PEP_Val is
19280 when Name_Concurrent => PEP := 'C';
19281 when Name_Sequential => PEP := 'S';
19282 end case;
19283
19284 if Partition_Elaboration_Policy /= ' '
19285 and then Partition_Elaboration_Policy /= PEP
19286 then
19287 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
19288 Error_Pragma
19289 ("partition elaboration policy incompatible with policy#");
19290
19291 -- Set new policy, but always preserve System_Location since we
19292 -- like the error message with the run time name.
19293
19294 else
19295 Partition_Elaboration_Policy := PEP;
19296
19297 if Partition_Elaboration_Policy_Sloc /= System_Location then
19298 Partition_Elaboration_Policy_Sloc := Loc;
19299 end if;
19300 end if;
19301 end PEP;
19302
19303 -------------
19304 -- Passive --
19305 -------------
19306
19307 -- pragma Passive [(PASSIVE_FORM)];
19308
19309 -- PASSIVE_FORM ::= Semaphore | No
19310
19311 when Pragma_Passive =>
19312 GNAT_Pragma;
19313
19314 if Nkind (Parent (N)) /= N_Task_Definition then
19315 Error_Pragma ("pragma% must be within task definition");
19316 end if;
19317
19318 if Arg_Count /= 0 then
19319 Check_Arg_Count (1);
19320 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
19321 end if;
19322
19323 ----------------------------------
19324 -- Preelaborable_Initialization --
19325 ----------------------------------
19326
19327 -- pragma Preelaborable_Initialization (DIRECT_NAME);
19328
19329 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
19330 Ent : Entity_Id;
19331
19332 begin
19333 Ada_2005_Pragma;
19334 Check_Arg_Count (1);
19335 Check_No_Identifiers;
19336 Check_Arg_Is_Identifier (Arg1);
19337 Check_Arg_Is_Local_Name (Arg1);
19338 Check_First_Subtype (Arg1);
19339 Ent := Entity (Get_Pragma_Arg (Arg1));
19340
19341 -- A pragma that applies to a Ghost entity becomes Ghost for the
19342 -- purposes of legality checks and removal of ignored Ghost code.
19343
19344 Mark_Ghost_Pragma (N, Ent);
19345
19346 -- The pragma may come from an aspect on a private declaration,
19347 -- even if the freeze point at which this is analyzed in the
19348 -- private part after the full view.
19349
19350 if Has_Private_Declaration (Ent)
19351 and then From_Aspect_Specification (N)
19352 then
19353 null;
19354
19355 -- Check appropriate type argument
19356
19357 elsif Is_Private_Type (Ent)
19358 or else Is_Protected_Type (Ent)
19359 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
19360
19361 -- AI05-0028: The pragma applies to all composite types. Note
19362 -- that we apply this binding interpretation to earlier versions
19363 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
19364 -- choice since there are other compilers that do the same.
19365
19366 or else Is_Composite_Type (Ent)
19367 then
19368 null;
19369
19370 else
19371 Error_Pragma_Arg
19372 ("pragma % can only be applied to private, formal derived, "
19373 & "protected, or composite type", Arg1);
19374 end if;
19375
19376 -- Give an error if the pragma is applied to a protected type that
19377 -- does not qualify (due to having entries, or due to components
19378 -- that do not qualify).
19379
19380 if Is_Protected_Type (Ent)
19381 and then not Has_Preelaborable_Initialization (Ent)
19382 then
19383 Error_Msg_N
19384 ("protected type & does not have preelaborable "
19385 & "initialization", Ent);
19386
19387 -- Otherwise mark the type as definitely having preelaborable
19388 -- initialization.
19389
19390 else
19391 Set_Known_To_Have_Preelab_Init (Ent);
19392 end if;
19393
19394 if Has_Pragma_Preelab_Init (Ent)
19395 and then Warn_On_Redundant_Constructs
19396 then
19397 Error_Pragma ("?r?duplicate pragma%!");
19398 else
19399 Set_Has_Pragma_Preelab_Init (Ent);
19400 end if;
19401 end Preelab_Init;
19402
19403 --------------------
19404 -- Persistent_BSS --
19405 --------------------
19406
19407 -- pragma Persistent_BSS [(object_NAME)];
19408
19409 when Pragma_Persistent_BSS => Persistent_BSS : declare
19410 Decl : Node_Id;
19411 Ent : Entity_Id;
19412 Prag : Node_Id;
19413
19414 begin
19415 GNAT_Pragma;
19416 Check_At_Most_N_Arguments (1);
19417
19418 -- Case of application to specific object (one argument)
19419
19420 if Arg_Count = 1 then
19421 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19422
19423 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
19424 or else not
19425 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
19426 E_Constant)
19427 then
19428 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
19429 end if;
19430
19431 Ent := Entity (Get_Pragma_Arg (Arg1));
19432
19433 -- A pragma that applies to a Ghost entity becomes Ghost for
19434 -- the purposes of legality checks and removal of ignored Ghost
19435 -- code.
19436
19437 Mark_Ghost_Pragma (N, Ent);
19438
19439 -- Check for duplication before inserting in list of
19440 -- representation items.
19441
19442 Check_Duplicate_Pragma (Ent);
19443
19444 if Rep_Item_Too_Late (Ent, N) then
19445 return;
19446 end if;
19447
19448 Decl := Parent (Ent);
19449
19450 if Present (Expression (Decl)) then
19451 Error_Pragma_Arg
19452 ("object for pragma% cannot have initialization", Arg1);
19453 end if;
19454
19455 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
19456 Error_Pragma_Arg
19457 ("object type for pragma% is not potentially persistent",
19458 Arg1);
19459 end if;
19460
19461 Prag :=
19462 Make_Linker_Section_Pragma
19463 (Ent, Sloc (N), ".persistent.bss");
19464 Insert_After (N, Prag);
19465 Analyze (Prag);
19466
19467 -- Case of use as configuration pragma with no arguments
19468
19469 else
19470 Check_Valid_Configuration_Pragma;
19471 Persistent_BSS_Mode := True;
19472 end if;
19473 end Persistent_BSS;
19474
19475 --------------------
19476 -- Rename_Pragma --
19477 --------------------
19478
19479 -- pragma Rename_Pragma (
19480 -- [New_Name =>] IDENTIFIER,
19481 -- [Renamed =>] pragma_IDENTIFIER);
19482
19483 when Pragma_Rename_Pragma => Rename_Pragma : declare
19484 New_Name : constant Node_Id := Get_Pragma_Arg (Arg1);
19485 Old_Name : constant Node_Id := Get_Pragma_Arg (Arg2);
19486
19487 begin
19488 GNAT_Pragma;
19489 Check_Valid_Configuration_Pragma;
19490 Check_Arg_Count (2);
19491 Check_Optional_Identifier (Arg1, Name_New_Name);
19492 Check_Optional_Identifier (Arg2, Name_Renamed);
19493
19494 if Nkind (New_Name) /= N_Identifier then
19495 Error_Pragma_Arg ("identifier expected", Arg1);
19496 end if;
19497
19498 if Nkind (Old_Name) /= N_Identifier then
19499 Error_Pragma_Arg ("identifier expected", Arg2);
19500 end if;
19501
19502 -- The New_Name arg should not be an existing pragma (but we allow
19503 -- it; it's just a warning). The Old_Name arg must be an existing
19504 -- pragma.
19505
19506 if Is_Pragma_Name (Chars (New_Name)) then
19507 Error_Pragma_Arg ("??pragma is already defined", Arg1);
19508 end if;
19509
19510 if not Is_Pragma_Name (Chars (Old_Name)) then
19511 Error_Pragma_Arg ("existing pragma name expected", Arg1);
19512 end if;
19513
19514 Map_Pragma_Name (From => Chars (New_Name), To => Chars (Old_Name));
19515 end Rename_Pragma;
19516
19517 -------------
19518 -- Polling --
19519 -------------
19520
19521 -- pragma Polling (ON | OFF);
19522
19523 when Pragma_Polling =>
19524 GNAT_Pragma;
19525 Check_Arg_Count (1);
19526 Check_No_Identifiers;
19527 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
19528 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
19529
19530 -----------------------------------
19531 -- Post/Post_Class/Postcondition --
19532 -----------------------------------
19533
19534 -- pragma Post (Boolean_EXPRESSION);
19535 -- pragma Post_Class (Boolean_EXPRESSION);
19536 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
19537 -- [,[Message =>] String_EXPRESSION]);
19538
19539 -- Characteristics:
19540
19541 -- * Analysis - The annotation undergoes initial checks to verify
19542 -- the legal placement and context. Secondary checks preanalyze the
19543 -- expression in:
19544
19545 -- Analyze_Pre_Post_Condition_In_Decl_Part
19546
19547 -- * Expansion - The annotation is expanded during the expansion of
19548 -- the related subprogram [body] contract as performed in:
19549
19550 -- Expand_Subprogram_Contract
19551
19552 -- * Template - The annotation utilizes the generic template of the
19553 -- related subprogram [body] when it is:
19554
19555 -- aspect on subprogram declaration
19556 -- aspect on stand alone subprogram body
19557 -- pragma on stand alone subprogram body
19558
19559 -- The annotation must prepare its own template when it is:
19560
19561 -- pragma on subprogram declaration
19562
19563 -- * Globals - Capture of global references must occur after full
19564 -- analysis.
19565
19566 -- * Instance - The annotation is instantiated automatically when
19567 -- the related generic subprogram [body] is instantiated except for
19568 -- the "pragma on subprogram declaration" case. In that scenario
19569 -- the annotation must instantiate itself.
19570
19571 when Pragma_Post
19572 | Pragma_Post_Class
19573 | Pragma_Postcondition
19574 =>
19575 Analyze_Pre_Post_Condition;
19576
19577 --------------------------------
19578 -- Pre/Pre_Class/Precondition --
19579 --------------------------------
19580
19581 -- pragma Pre (Boolean_EXPRESSION);
19582 -- pragma Pre_Class (Boolean_EXPRESSION);
19583 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
19584 -- [,[Message =>] String_EXPRESSION]);
19585
19586 -- Characteristics:
19587
19588 -- * Analysis - The annotation undergoes initial checks to verify
19589 -- the legal placement and context. Secondary checks preanalyze the
19590 -- expression in:
19591
19592 -- Analyze_Pre_Post_Condition_In_Decl_Part
19593
19594 -- * Expansion - The annotation is expanded during the expansion of
19595 -- the related subprogram [body] contract as performed in:
19596
19597 -- Expand_Subprogram_Contract
19598
19599 -- * Template - The annotation utilizes the generic template of the
19600 -- related subprogram [body] when it is:
19601
19602 -- aspect on subprogram declaration
19603 -- aspect on stand alone subprogram body
19604 -- pragma on stand alone subprogram body
19605
19606 -- The annotation must prepare its own template when it is:
19607
19608 -- pragma on subprogram declaration
19609
19610 -- * Globals - Capture of global references must occur after full
19611 -- analysis.
19612
19613 -- * Instance - The annotation is instantiated automatically when
19614 -- the related generic subprogram [body] is instantiated except for
19615 -- the "pragma on subprogram declaration" case. In that scenario
19616 -- the annotation must instantiate itself.
19617
19618 when Pragma_Pre
19619 | Pragma_Pre_Class
19620 | Pragma_Precondition
19621 =>
19622 Analyze_Pre_Post_Condition;
19623
19624 ---------------
19625 -- Predicate --
19626 ---------------
19627
19628 -- pragma Predicate
19629 -- ([Entity =>] type_LOCAL_NAME,
19630 -- [Check =>] boolean_EXPRESSION);
19631
19632 when Pragma_Predicate => Predicate : declare
19633 Discard : Boolean;
19634 Typ : Entity_Id;
19635 Type_Id : Node_Id;
19636
19637 begin
19638 GNAT_Pragma;
19639 Check_Arg_Count (2);
19640 Check_Optional_Identifier (Arg1, Name_Entity);
19641 Check_Optional_Identifier (Arg2, Name_Check);
19642
19643 Check_Arg_Is_Local_Name (Arg1);
19644
19645 Type_Id := Get_Pragma_Arg (Arg1);
19646 Find_Type (Type_Id);
19647 Typ := Entity (Type_Id);
19648
19649 if Typ = Any_Type then
19650 return;
19651 end if;
19652
19653 -- A pragma that applies to a Ghost entity becomes Ghost for the
19654 -- purposes of legality checks and removal of ignored Ghost code.
19655
19656 Mark_Ghost_Pragma (N, Typ);
19657
19658 -- The remaining processing is simply to link the pragma on to
19659 -- the rep item chain, for processing when the type is frozen.
19660 -- This is accomplished by a call to Rep_Item_Too_Late. We also
19661 -- mark the type as having predicates.
19662
19663 -- If the current policy for predicate checking is Ignore mark the
19664 -- subtype accordingly. In the case of predicates we consider them
19665 -- enabled unless Ignore is specified (either directly or with a
19666 -- general Assertion_Policy pragma) to preserve existing warnings.
19667
19668 Set_Has_Predicates (Typ);
19669 Set_Predicates_Ignored (Typ,
19670 Present (Check_Policy_List)
19671 and then
19672 Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore);
19673 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
19674 end Predicate;
19675
19676 -----------------------
19677 -- Predicate_Failure --
19678 -----------------------
19679
19680 -- pragma Predicate_Failure
19681 -- ([Entity =>] type_LOCAL_NAME,
19682 -- [Message =>] string_EXPRESSION);
19683
19684 when Pragma_Predicate_Failure => Predicate_Failure : declare
19685 Discard : Boolean;
19686 Typ : Entity_Id;
19687 Type_Id : Node_Id;
19688
19689 begin
19690 GNAT_Pragma;
19691 Check_Arg_Count (2);
19692 Check_Optional_Identifier (Arg1, Name_Entity);
19693 Check_Optional_Identifier (Arg2, Name_Message);
19694
19695 Check_Arg_Is_Local_Name (Arg1);
19696
19697 Type_Id := Get_Pragma_Arg (Arg1);
19698 Find_Type (Type_Id);
19699 Typ := Entity (Type_Id);
19700
19701 if Typ = Any_Type then
19702 return;
19703 end if;
19704
19705 -- A pragma that applies to a Ghost entity becomes Ghost for the
19706 -- purposes of legality checks and removal of ignored Ghost code.
19707
19708 Mark_Ghost_Pragma (N, Typ);
19709
19710 -- The remaining processing is simply to link the pragma on to
19711 -- the rep item chain, for processing when the type is frozen.
19712 -- This is accomplished by a call to Rep_Item_Too_Late.
19713
19714 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
19715 end Predicate_Failure;
19716
19717 ------------------
19718 -- Preelaborate --
19719 ------------------
19720
19721 -- pragma Preelaborate [(library_unit_NAME)];
19722
19723 -- Set the flag Is_Preelaborated of program unit name entity
19724
19725 when Pragma_Preelaborate => Preelaborate : declare
19726 Pa : constant Node_Id := Parent (N);
19727 Pk : constant Node_Kind := Nkind (Pa);
19728 Ent : Entity_Id;
19729
19730 begin
19731 Check_Ada_83_Warning;
19732 Check_Valid_Library_Unit_Pragma;
19733
19734 if Nkind (N) = N_Null_Statement then
19735 return;
19736 end if;
19737
19738 Ent := Find_Lib_Unit_Name;
19739
19740 -- A pragma that applies to a Ghost entity becomes Ghost for the
19741 -- purposes of legality checks and removal of ignored Ghost code.
19742
19743 Mark_Ghost_Pragma (N, Ent);
19744 Check_Duplicate_Pragma (Ent);
19745
19746 -- This filters out pragmas inside generic parents that show up
19747 -- inside instantiations. Pragmas that come from aspects in the
19748 -- unit are not ignored.
19749
19750 if Present (Ent) then
19751 if Pk = N_Package_Specification
19752 and then Present (Generic_Parent (Pa))
19753 and then not From_Aspect_Specification (N)
19754 then
19755 null;
19756
19757 else
19758 if not Debug_Flag_U then
19759 Set_Is_Preelaborated (Ent);
19760 Set_Suppress_Elaboration_Warnings (Ent);
19761 end if;
19762 end if;
19763 end if;
19764 end Preelaborate;
19765
19766 -------------------------------
19767 -- Prefix_Exception_Messages --
19768 -------------------------------
19769
19770 -- pragma Prefix_Exception_Messages;
19771
19772 when Pragma_Prefix_Exception_Messages =>
19773 GNAT_Pragma;
19774 Check_Valid_Configuration_Pragma;
19775 Check_Arg_Count (0);
19776 Prefix_Exception_Messages := True;
19777
19778 --------------
19779 -- Priority --
19780 --------------
19781
19782 -- pragma Priority (EXPRESSION);
19783
19784 when Pragma_Priority => Priority : declare
19785 P : constant Node_Id := Parent (N);
19786 Arg : Node_Id;
19787 Ent : Entity_Id;
19788
19789 begin
19790 Check_No_Identifiers;
19791 Check_Arg_Count (1);
19792
19793 -- Subprogram case
19794
19795 if Nkind (P) = N_Subprogram_Body then
19796 Check_In_Main_Program;
19797
19798 Ent := Defining_Unit_Name (Specification (P));
19799
19800 if Nkind (Ent) = N_Defining_Program_Unit_Name then
19801 Ent := Defining_Identifier (Ent);
19802 end if;
19803
19804 Arg := Get_Pragma_Arg (Arg1);
19805 Analyze_And_Resolve (Arg, Standard_Integer);
19806
19807 -- Must be static
19808
19809 if not Is_OK_Static_Expression (Arg) then
19810 Flag_Non_Static_Expr
19811 ("main subprogram priority is not static!", Arg);
19812 raise Pragma_Exit;
19813
19814 -- If constraint error, then we already signalled an error
19815
19816 elsif Raises_Constraint_Error (Arg) then
19817 null;
19818
19819 -- Otherwise check in range except if Relaxed_RM_Semantics
19820 -- where we ignore the value if out of range.
19821
19822 else
19823 if not Relaxed_RM_Semantics
19824 and then not Is_In_Range (Arg, RTE (RE_Priority))
19825 then
19826 Error_Pragma_Arg
19827 ("main subprogram priority is out of range", Arg1);
19828 else
19829 Set_Main_Priority
19830 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
19831 end if;
19832 end if;
19833
19834 -- Load an arbitrary entity from System.Tasking.Stages or
19835 -- System.Tasking.Restricted.Stages (depending on the
19836 -- supported profile) to make sure that one of these packages
19837 -- is implicitly with'ed, since we need to have the tasking
19838 -- run time active for the pragma Priority to have any effect.
19839 -- Previously we with'ed the package System.Tasking, but this
19840 -- package does not trigger the required initialization of the
19841 -- run-time library.
19842
19843 declare
19844 Discard : Entity_Id;
19845 pragma Warnings (Off, Discard);
19846 begin
19847 if Restricted_Profile then
19848 Discard := RTE (RE_Activate_Restricted_Tasks);
19849 else
19850 Discard := RTE (RE_Activate_Tasks);
19851 end if;
19852 end;
19853
19854 -- Task or Protected, must be of type Integer
19855
19856 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
19857 Arg := Get_Pragma_Arg (Arg1);
19858 Ent := Defining_Identifier (Parent (P));
19859
19860 -- The expression must be analyzed in the special manner
19861 -- described in "Handling of Default and Per-Object
19862 -- Expressions" in sem.ads.
19863
19864 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
19865
19866 if not Is_OK_Static_Expression (Arg) then
19867 Check_Restriction (Static_Priorities, Arg);
19868 end if;
19869
19870 -- Anything else is incorrect
19871
19872 else
19873 Pragma_Misplaced;
19874 end if;
19875
19876 -- Check duplicate pragma before we chain the pragma in the Rep
19877 -- Item chain of Ent.
19878
19879 Check_Duplicate_Pragma (Ent);
19880 Record_Rep_Item (Ent, N);
19881 end Priority;
19882
19883 -----------------------------------
19884 -- Priority_Specific_Dispatching --
19885 -----------------------------------
19886
19887 -- pragma Priority_Specific_Dispatching (
19888 -- policy_IDENTIFIER,
19889 -- first_priority_EXPRESSION,
19890 -- last_priority_EXPRESSION);
19891
19892 when Pragma_Priority_Specific_Dispatching =>
19893 Priority_Specific_Dispatching : declare
19894 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
19895 -- This is the entity System.Any_Priority;
19896
19897 DP : Character;
19898 Lower_Bound : Node_Id;
19899 Upper_Bound : Node_Id;
19900 Lower_Val : Uint;
19901 Upper_Val : Uint;
19902
19903 begin
19904 Ada_2005_Pragma;
19905 Check_Arg_Count (3);
19906 Check_No_Identifiers;
19907 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
19908 Check_Valid_Configuration_Pragma;
19909 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
19910 DP := Fold_Upper (Name_Buffer (1));
19911
19912 Lower_Bound := Get_Pragma_Arg (Arg2);
19913 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
19914 Lower_Val := Expr_Value (Lower_Bound);
19915
19916 Upper_Bound := Get_Pragma_Arg (Arg3);
19917 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
19918 Upper_Val := Expr_Value (Upper_Bound);
19919
19920 -- It is not allowed to use Task_Dispatching_Policy and
19921 -- Priority_Specific_Dispatching in the same partition.
19922
19923 if Task_Dispatching_Policy /= ' ' then
19924 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
19925 Error_Pragma
19926 ("pragma% incompatible with Task_Dispatching_Policy#");
19927
19928 -- Check lower bound in range
19929
19930 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
19931 or else
19932 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
19933 then
19934 Error_Pragma_Arg
19935 ("first_priority is out of range", Arg2);
19936
19937 -- Check upper bound in range
19938
19939 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
19940 or else
19941 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
19942 then
19943 Error_Pragma_Arg
19944 ("last_priority is out of range", Arg3);
19945
19946 -- Check that the priority range is valid
19947
19948 elsif Lower_Val > Upper_Val then
19949 Error_Pragma
19950 ("last_priority_expression must be greater than or equal to "
19951 & "first_priority_expression");
19952
19953 -- Store the new policy, but always preserve System_Location since
19954 -- we like the error message with the run-time name.
19955
19956 else
19957 -- Check overlapping in the priority ranges specified in other
19958 -- Priority_Specific_Dispatching pragmas within the same
19959 -- partition. We can only check those we know about.
19960
19961 for J in
19962 Specific_Dispatching.First .. Specific_Dispatching.Last
19963 loop
19964 if Specific_Dispatching.Table (J).First_Priority in
19965 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
19966 or else Specific_Dispatching.Table (J).Last_Priority in
19967 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
19968 then
19969 Error_Msg_Sloc :=
19970 Specific_Dispatching.Table (J).Pragma_Loc;
19971 Error_Pragma
19972 ("priority range overlaps with "
19973 & "Priority_Specific_Dispatching#");
19974 end if;
19975 end loop;
19976
19977 -- The use of Priority_Specific_Dispatching is incompatible
19978 -- with Task_Dispatching_Policy.
19979
19980 if Task_Dispatching_Policy /= ' ' then
19981 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
19982 Error_Pragma
19983 ("Priority_Specific_Dispatching incompatible "
19984 & "with Task_Dispatching_Policy#");
19985 end if;
19986
19987 -- The use of Priority_Specific_Dispatching forces ceiling
19988 -- locking policy.
19989
19990 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
19991 Error_Msg_Sloc := Locking_Policy_Sloc;
19992 Error_Pragma
19993 ("Priority_Specific_Dispatching incompatible "
19994 & "with Locking_Policy#");
19995
19996 -- Set the Ceiling_Locking policy, but preserve System_Location
19997 -- since we like the error message with the run time name.
19998
19999 else
20000 Locking_Policy := 'C';
20001
20002 if Locking_Policy_Sloc /= System_Location then
20003 Locking_Policy_Sloc := Loc;
20004 end if;
20005 end if;
20006
20007 -- Add entry in the table
20008
20009 Specific_Dispatching.Append
20010 ((Dispatching_Policy => DP,
20011 First_Priority => UI_To_Int (Lower_Val),
20012 Last_Priority => UI_To_Int (Upper_Val),
20013 Pragma_Loc => Loc));
20014 end if;
20015 end Priority_Specific_Dispatching;
20016
20017 -------------
20018 -- Profile --
20019 -------------
20020
20021 -- pragma Profile (profile_IDENTIFIER);
20022
20023 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
20024
20025 when Pragma_Profile =>
20026 Ada_2005_Pragma;
20027 Check_Arg_Count (1);
20028 Check_Valid_Configuration_Pragma;
20029 Check_No_Identifiers;
20030
20031 declare
20032 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
20033
20034 begin
20035 if Chars (Argx) = Name_Ravenscar then
20036 Set_Ravenscar_Profile (Ravenscar, N);
20037
20038 elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then
20039 Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N);
20040
20041 elsif Chars (Argx) = Name_Gnat_Ravenscar_EDF then
20042 Set_Ravenscar_Profile (GNAT_Ravenscar_EDF, N);
20043
20044 elsif Chars (Argx) = Name_Restricted then
20045 Set_Profile_Restrictions
20046 (Restricted,
20047 N, Warn => Treat_Restrictions_As_Warnings);
20048
20049 elsif Chars (Argx) = Name_Rational then
20050 Set_Rational_Profile;
20051
20052 elsif Chars (Argx) = Name_No_Implementation_Extensions then
20053 Set_Profile_Restrictions
20054 (No_Implementation_Extensions,
20055 N, Warn => Treat_Restrictions_As_Warnings);
20056
20057 else
20058 Error_Pragma_Arg ("& is not a valid profile", Argx);
20059 end if;
20060 end;
20061
20062 ----------------------
20063 -- Profile_Warnings --
20064 ----------------------
20065
20066 -- pragma Profile_Warnings (profile_IDENTIFIER);
20067
20068 -- profile_IDENTIFIER => Restricted | Ravenscar
20069
20070 when Pragma_Profile_Warnings =>
20071 GNAT_Pragma;
20072 Check_Arg_Count (1);
20073 Check_Valid_Configuration_Pragma;
20074 Check_No_Identifiers;
20075
20076 declare
20077 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
20078
20079 begin
20080 if Chars (Argx) = Name_Ravenscar then
20081 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
20082
20083 elsif Chars (Argx) = Name_Restricted then
20084 Set_Profile_Restrictions (Restricted, N, Warn => True);
20085
20086 elsif Chars (Argx) = Name_No_Implementation_Extensions then
20087 Set_Profile_Restrictions
20088 (No_Implementation_Extensions, N, Warn => True);
20089
20090 else
20091 Error_Pragma_Arg ("& is not a valid profile", Argx);
20092 end if;
20093 end;
20094
20095 --------------------------
20096 -- Propagate_Exceptions --
20097 --------------------------
20098
20099 -- pragma Propagate_Exceptions;
20100
20101 -- Note: this pragma is obsolete and has no effect
20102
20103 when Pragma_Propagate_Exceptions =>
20104 GNAT_Pragma;
20105 Check_Arg_Count (0);
20106
20107 if Warn_On_Obsolescent_Feature then
20108 Error_Msg_N
20109 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
20110 "and has no effect?j?", N);
20111 end if;
20112
20113 -----------------------------
20114 -- Provide_Shift_Operators --
20115 -----------------------------
20116
20117 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
20118
20119 when Pragma_Provide_Shift_Operators =>
20120 Provide_Shift_Operators : declare
20121 Ent : Entity_Id;
20122
20123 procedure Declare_Shift_Operator (Nam : Name_Id);
20124 -- Insert declaration and pragma Instrinsic for named shift op
20125
20126 ----------------------------
20127 -- Declare_Shift_Operator --
20128 ----------------------------
20129
20130 procedure Declare_Shift_Operator (Nam : Name_Id) is
20131 Func : Node_Id;
20132 Import : Node_Id;
20133
20134 begin
20135 Func :=
20136 Make_Subprogram_Declaration (Loc,
20137 Make_Function_Specification (Loc,
20138 Defining_Unit_Name =>
20139 Make_Defining_Identifier (Loc, Chars => Nam),
20140
20141 Result_Definition =>
20142 Make_Identifier (Loc, Chars => Chars (Ent)),
20143
20144 Parameter_Specifications => New_List (
20145 Make_Parameter_Specification (Loc,
20146 Defining_Identifier =>
20147 Make_Defining_Identifier (Loc, Name_Value),
20148 Parameter_Type =>
20149 Make_Identifier (Loc, Chars => Chars (Ent))),
20150
20151 Make_Parameter_Specification (Loc,
20152 Defining_Identifier =>
20153 Make_Defining_Identifier (Loc, Name_Amount),
20154 Parameter_Type =>
20155 New_Occurrence_Of (Standard_Natural, Loc)))));
20156
20157 Import :=
20158 Make_Pragma (Loc,
20159 Chars => Name_Import,
20160 Pragma_Argument_Associations => New_List (
20161 Make_Pragma_Argument_Association (Loc,
20162 Expression => Make_Identifier (Loc, Name_Intrinsic)),
20163 Make_Pragma_Argument_Association (Loc,
20164 Expression => Make_Identifier (Loc, Nam))));
20165
20166 Insert_After (N, Import);
20167 Insert_After (N, Func);
20168 end Declare_Shift_Operator;
20169
20170 -- Start of processing for Provide_Shift_Operators
20171
20172 begin
20173 GNAT_Pragma;
20174 Check_Arg_Count (1);
20175 Check_Arg_Is_Local_Name (Arg1);
20176
20177 Arg1 := Get_Pragma_Arg (Arg1);
20178
20179 -- We must have an entity name
20180
20181 if not Is_Entity_Name (Arg1) then
20182 Error_Pragma_Arg
20183 ("pragma % must apply to integer first subtype", Arg1);
20184 end if;
20185
20186 -- If no Entity, means there was a prior error so ignore
20187
20188 if Present (Entity (Arg1)) then
20189 Ent := Entity (Arg1);
20190
20191 -- Apply error checks
20192
20193 if not Is_First_Subtype (Ent) then
20194 Error_Pragma_Arg
20195 ("cannot apply pragma %",
20196 "\& is not a first subtype",
20197 Arg1);
20198
20199 elsif not Is_Integer_Type (Ent) then
20200 Error_Pragma_Arg
20201 ("cannot apply pragma %",
20202 "\& is not an integer type",
20203 Arg1);
20204
20205 elsif Has_Shift_Operator (Ent) then
20206 Error_Pragma_Arg
20207 ("cannot apply pragma %",
20208 "\& already has declared shift operators",
20209 Arg1);
20210
20211 elsif Is_Frozen (Ent) then
20212 Error_Pragma_Arg
20213 ("pragma % appears too late",
20214 "\& is already frozen",
20215 Arg1);
20216 end if;
20217
20218 -- Now declare the operators. We do this during analysis rather
20219 -- than expansion, since we want the operators available if we
20220 -- are operating in -gnatc or ASIS mode.
20221
20222 Declare_Shift_Operator (Name_Rotate_Left);
20223 Declare_Shift_Operator (Name_Rotate_Right);
20224 Declare_Shift_Operator (Name_Shift_Left);
20225 Declare_Shift_Operator (Name_Shift_Right);
20226 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
20227 end if;
20228 end Provide_Shift_Operators;
20229
20230 ------------------
20231 -- Psect_Object --
20232 ------------------
20233
20234 -- pragma Psect_Object (
20235 -- [Internal =>] LOCAL_NAME,
20236 -- [, [External =>] EXTERNAL_SYMBOL]
20237 -- [, [Size =>] EXTERNAL_SYMBOL]);
20238
20239 when Pragma_Common_Object
20240 | Pragma_Psect_Object
20241 =>
20242 Psect_Object : declare
20243 Args : Args_List (1 .. 3);
20244 Names : constant Name_List (1 .. 3) := (
20245 Name_Internal,
20246 Name_External,
20247 Name_Size);
20248
20249 Internal : Node_Id renames Args (1);
20250 External : Node_Id renames Args (2);
20251 Size : Node_Id renames Args (3);
20252
20253 Def_Id : Entity_Id;
20254
20255 procedure Check_Arg (Arg : Node_Id);
20256 -- Checks that argument is either a string literal or an
20257 -- identifier, and posts error message if not.
20258
20259 ---------------
20260 -- Check_Arg --
20261 ---------------
20262
20263 procedure Check_Arg (Arg : Node_Id) is
20264 begin
20265 if not Nkind_In (Original_Node (Arg),
20266 N_String_Literal,
20267 N_Identifier)
20268 then
20269 Error_Pragma_Arg
20270 ("inappropriate argument for pragma %", Arg);
20271 end if;
20272 end Check_Arg;
20273
20274 -- Start of processing for Common_Object/Psect_Object
20275
20276 begin
20277 GNAT_Pragma;
20278 Gather_Associations (Names, Args);
20279 Process_Extended_Import_Export_Internal_Arg (Internal);
20280
20281 Def_Id := Entity (Internal);
20282
20283 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
20284 Error_Pragma_Arg
20285 ("pragma% must designate an object", Internal);
20286 end if;
20287
20288 Check_Arg (Internal);
20289
20290 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
20291 Error_Pragma_Arg
20292 ("cannot use pragma% for imported/exported object",
20293 Internal);
20294 end if;
20295
20296 if Is_Concurrent_Type (Etype (Internal)) then
20297 Error_Pragma_Arg
20298 ("cannot specify pragma % for task/protected object",
20299 Internal);
20300 end if;
20301
20302 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
20303 or else
20304 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
20305 then
20306 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
20307 end if;
20308
20309 if Ekind (Def_Id) = E_Constant then
20310 Error_Pragma_Arg
20311 ("cannot specify pragma % for a constant", Internal);
20312 end if;
20313
20314 if Is_Record_Type (Etype (Internal)) then
20315 declare
20316 Ent : Entity_Id;
20317 Decl : Entity_Id;
20318
20319 begin
20320 Ent := First_Entity (Etype (Internal));
20321 while Present (Ent) loop
20322 Decl := Declaration_Node (Ent);
20323
20324 if Ekind (Ent) = E_Component
20325 and then Nkind (Decl) = N_Component_Declaration
20326 and then Present (Expression (Decl))
20327 and then Warn_On_Export_Import
20328 then
20329 Error_Msg_N
20330 ("?x?object for pragma % has defaults", Internal);
20331 exit;
20332
20333 else
20334 Next_Entity (Ent);
20335 end if;
20336 end loop;
20337 end;
20338 end if;
20339
20340 if Present (Size) then
20341 Check_Arg (Size);
20342 end if;
20343
20344 if Present (External) then
20345 Check_Arg_Is_External_Name (External);
20346 end if;
20347
20348 -- If all error tests pass, link pragma on to the rep item chain
20349
20350 Record_Rep_Item (Def_Id, N);
20351 end Psect_Object;
20352
20353 ----------
20354 -- Pure --
20355 ----------
20356
20357 -- pragma Pure [(library_unit_NAME)];
20358
20359 when Pragma_Pure => Pure : declare
20360 Ent : Entity_Id;
20361
20362 begin
20363 Check_Ada_83_Warning;
20364
20365 -- If the pragma comes from a subprogram instantiation, nothing to
20366 -- check, this can happen at any level of nesting.
20367
20368 if Is_Wrapper_Package (Current_Scope) then
20369 return;
20370 else
20371 Check_Valid_Library_Unit_Pragma;
20372 end if;
20373
20374 if Nkind (N) = N_Null_Statement then
20375 return;
20376 end if;
20377
20378 Ent := Find_Lib_Unit_Name;
20379
20380 -- A pragma that applies to a Ghost entity becomes Ghost for the
20381 -- purposes of legality checks and removal of ignored Ghost code.
20382
20383 Mark_Ghost_Pragma (N, Ent);
20384
20385 if not Debug_Flag_U then
20386 Set_Is_Pure (Ent);
20387 Set_Has_Pragma_Pure (Ent);
20388 Set_Suppress_Elaboration_Warnings (Ent);
20389 end if;
20390 end Pure;
20391
20392 -------------------
20393 -- Pure_Function --
20394 -------------------
20395
20396 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
20397
20398 when Pragma_Pure_Function => Pure_Function : declare
20399 Def_Id : Entity_Id;
20400 E : Entity_Id;
20401 E_Id : Node_Id;
20402 Effective : Boolean := False;
20403
20404 begin
20405 GNAT_Pragma;
20406 Check_Arg_Count (1);
20407 Check_Optional_Identifier (Arg1, Name_Entity);
20408 Check_Arg_Is_Local_Name (Arg1);
20409 E_Id := Get_Pragma_Arg (Arg1);
20410
20411 if Etype (E_Id) = Any_Type then
20412 return;
20413 end if;
20414
20415 -- Loop through homonyms (overloadings) of referenced entity
20416
20417 E := Entity (E_Id);
20418
20419 -- A pragma that applies to a Ghost entity becomes Ghost for the
20420 -- purposes of legality checks and removal of ignored Ghost code.
20421
20422 Mark_Ghost_Pragma (N, E);
20423
20424 if Present (E) then
20425 loop
20426 Def_Id := Get_Base_Subprogram (E);
20427
20428 if not Ekind_In (Def_Id, E_Function,
20429 E_Generic_Function,
20430 E_Operator)
20431 then
20432 Error_Pragma_Arg
20433 ("pragma% requires a function name", Arg1);
20434 end if;
20435
20436 Set_Is_Pure (Def_Id);
20437
20438 if not Has_Pragma_Pure_Function (Def_Id) then
20439 Set_Has_Pragma_Pure_Function (Def_Id);
20440 Effective := True;
20441 end if;
20442
20443 exit when From_Aspect_Specification (N);
20444 E := Homonym (E);
20445 exit when No (E) or else Scope (E) /= Current_Scope;
20446 end loop;
20447
20448 if not Effective
20449 and then Warn_On_Redundant_Constructs
20450 then
20451 Error_Msg_NE
20452 ("pragma Pure_Function on& is redundant?r?",
20453 N, Entity (E_Id));
20454 end if;
20455 end if;
20456 end Pure_Function;
20457
20458 --------------------
20459 -- Queuing_Policy --
20460 --------------------
20461
20462 -- pragma Queuing_Policy (policy_IDENTIFIER);
20463
20464 when Pragma_Queuing_Policy => declare
20465 QP : Character;
20466
20467 begin
20468 Check_Ada_83_Warning;
20469 Check_Arg_Count (1);
20470 Check_No_Identifiers;
20471 Check_Arg_Is_Queuing_Policy (Arg1);
20472 Check_Valid_Configuration_Pragma;
20473 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
20474 QP := Fold_Upper (Name_Buffer (1));
20475
20476 if Queuing_Policy /= ' '
20477 and then Queuing_Policy /= QP
20478 then
20479 Error_Msg_Sloc := Queuing_Policy_Sloc;
20480 Error_Pragma ("queuing policy incompatible with policy#");
20481
20482 -- Set new policy, but always preserve System_Location since we
20483 -- like the error message with the run time name.
20484
20485 else
20486 Queuing_Policy := QP;
20487
20488 if Queuing_Policy_Sloc /= System_Location then
20489 Queuing_Policy_Sloc := Loc;
20490 end if;
20491 end if;
20492 end;
20493
20494 --------------
20495 -- Rational --
20496 --------------
20497
20498 -- pragma Rational, for compatibility with foreign compiler
20499
20500 when Pragma_Rational =>
20501 Set_Rational_Profile;
20502
20503 ---------------------
20504 -- Refined_Depends --
20505 ---------------------
20506
20507 -- pragma Refined_Depends (DEPENDENCY_RELATION);
20508
20509 -- DEPENDENCY_RELATION ::=
20510 -- null
20511 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
20512
20513 -- DEPENDENCY_CLAUSE ::=
20514 -- OUTPUT_LIST =>[+] INPUT_LIST
20515 -- | NULL_DEPENDENCY_CLAUSE
20516
20517 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
20518
20519 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
20520
20521 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
20522
20523 -- OUTPUT ::= NAME | FUNCTION_RESULT
20524 -- INPUT ::= NAME
20525
20526 -- where FUNCTION_RESULT is a function Result attribute_reference
20527
20528 -- Characteristics:
20529
20530 -- * Analysis - The annotation undergoes initial checks to verify
20531 -- the legal placement and context. Secondary checks fully analyze
20532 -- the dependency clauses/global list in:
20533
20534 -- Analyze_Refined_Depends_In_Decl_Part
20535
20536 -- * Expansion - None.
20537
20538 -- * Template - The annotation utilizes the generic template of the
20539 -- related subprogram body.
20540
20541 -- * Globals - Capture of global references must occur after full
20542 -- analysis.
20543
20544 -- * Instance - The annotation is instantiated automatically when
20545 -- the related generic subprogram body is instantiated.
20546
20547 when Pragma_Refined_Depends => Refined_Depends : declare
20548 Body_Id : Entity_Id;
20549 Legal : Boolean;
20550 Spec_Id : Entity_Id;
20551
20552 begin
20553 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
20554
20555 if Legal then
20556
20557 -- Chain the pragma on the contract for further processing by
20558 -- Analyze_Refined_Depends_In_Decl_Part.
20559
20560 Add_Contract_Item (N, Body_Id);
20561
20562 -- The legality checks of pragmas Refined_Depends and
20563 -- Refined_Global are affected by the SPARK mode in effect and
20564 -- the volatility of the context. In addition these two pragmas
20565 -- are subject to an inherent order:
20566
20567 -- 1) Refined_Global
20568 -- 2) Refined_Depends
20569
20570 -- Analyze all these pragmas in the order outlined above
20571
20572 Analyze_If_Present (Pragma_SPARK_Mode);
20573 Analyze_If_Present (Pragma_Volatile_Function);
20574 Analyze_If_Present (Pragma_Refined_Global);
20575 Analyze_Refined_Depends_In_Decl_Part (N);
20576 end if;
20577 end Refined_Depends;
20578
20579 --------------------
20580 -- Refined_Global --
20581 --------------------
20582
20583 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
20584
20585 -- GLOBAL_SPECIFICATION ::=
20586 -- null
20587 -- | (GLOBAL_LIST)
20588 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
20589
20590 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
20591
20592 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
20593 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
20594 -- GLOBAL_ITEM ::= NAME
20595
20596 -- Characteristics:
20597
20598 -- * Analysis - The annotation undergoes initial checks to verify
20599 -- the legal placement and context. Secondary checks fully analyze
20600 -- the dependency clauses/global list in:
20601
20602 -- Analyze_Refined_Global_In_Decl_Part
20603
20604 -- * Expansion - None.
20605
20606 -- * Template - The annotation utilizes the generic template of the
20607 -- related subprogram body.
20608
20609 -- * Globals - Capture of global references must occur after full
20610 -- analysis.
20611
20612 -- * Instance - The annotation is instantiated automatically when
20613 -- the related generic subprogram body is instantiated.
20614
20615 when Pragma_Refined_Global => Refined_Global : declare
20616 Body_Id : Entity_Id;
20617 Legal : Boolean;
20618 Spec_Id : Entity_Id;
20619
20620 begin
20621 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
20622
20623 if Legal then
20624
20625 -- Chain the pragma on the contract for further processing by
20626 -- Analyze_Refined_Global_In_Decl_Part.
20627
20628 Add_Contract_Item (N, Body_Id);
20629
20630 -- The legality checks of pragmas Refined_Depends and
20631 -- Refined_Global are affected by the SPARK mode in effect and
20632 -- the volatility of the context. In addition these two pragmas
20633 -- are subject to an inherent order:
20634
20635 -- 1) Refined_Global
20636 -- 2) Refined_Depends
20637
20638 -- Analyze all these pragmas in the order outlined above
20639
20640 Analyze_If_Present (Pragma_SPARK_Mode);
20641 Analyze_If_Present (Pragma_Volatile_Function);
20642 Analyze_Refined_Global_In_Decl_Part (N);
20643 Analyze_If_Present (Pragma_Refined_Depends);
20644 end if;
20645 end Refined_Global;
20646
20647 ------------------
20648 -- Refined_Post --
20649 ------------------
20650
20651 -- pragma Refined_Post (boolean_EXPRESSION);
20652
20653 -- Characteristics:
20654
20655 -- * Analysis - The annotation is fully analyzed immediately upon
20656 -- elaboration as it cannot forward reference entities.
20657
20658 -- * Expansion - The annotation is expanded during the expansion of
20659 -- the related subprogram body contract as performed in:
20660
20661 -- Expand_Subprogram_Contract
20662
20663 -- * Template - The annotation utilizes the generic template of the
20664 -- related subprogram body.
20665
20666 -- * Globals - Capture of global references must occur after full
20667 -- analysis.
20668
20669 -- * Instance - The annotation is instantiated automatically when
20670 -- the related generic subprogram body is instantiated.
20671
20672 when Pragma_Refined_Post => Refined_Post : declare
20673 Body_Id : Entity_Id;
20674 Legal : Boolean;
20675 Spec_Id : Entity_Id;
20676
20677 begin
20678 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
20679
20680 -- Fully analyze the pragma when it appears inside a subprogram
20681 -- body because it cannot benefit from forward references.
20682
20683 if Legal then
20684
20685 -- Chain the pragma on the contract for completeness
20686
20687 Add_Contract_Item (N, Body_Id);
20688
20689 -- The legality checks of pragma Refined_Post are affected by
20690 -- the SPARK mode in effect and the volatility of the context.
20691 -- Analyze all pragmas in a specific order.
20692
20693 Analyze_If_Present (Pragma_SPARK_Mode);
20694 Analyze_If_Present (Pragma_Volatile_Function);
20695 Analyze_Pre_Post_Condition_In_Decl_Part (N);
20696
20697 -- Currently it is not possible to inline pre/postconditions on
20698 -- a subprogram subject to pragma Inline_Always.
20699
20700 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
20701 end if;
20702 end Refined_Post;
20703
20704 -------------------
20705 -- Refined_State --
20706 -------------------
20707
20708 -- pragma Refined_State (REFINEMENT_LIST);
20709
20710 -- REFINEMENT_LIST ::=
20711 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
20712
20713 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
20714
20715 -- CONSTITUENT_LIST ::=
20716 -- null
20717 -- | CONSTITUENT
20718 -- | (CONSTITUENT {, CONSTITUENT})
20719
20720 -- CONSTITUENT ::= object_NAME | state_NAME
20721
20722 -- Characteristics:
20723
20724 -- * Analysis - The annotation undergoes initial checks to verify
20725 -- the legal placement and context. Secondary checks preanalyze the
20726 -- refinement clauses in:
20727
20728 -- Analyze_Refined_State_In_Decl_Part
20729
20730 -- * Expansion - None.
20731
20732 -- * Template - The annotation utilizes the template of the related
20733 -- package body.
20734
20735 -- * Globals - Capture of global references must occur after full
20736 -- analysis.
20737
20738 -- * Instance - The annotation is instantiated automatically when
20739 -- the related generic package body is instantiated.
20740
20741 when Pragma_Refined_State => Refined_State : declare
20742 Pack_Decl : Node_Id;
20743 Spec_Id : Entity_Id;
20744
20745 begin
20746 GNAT_Pragma;
20747 Check_No_Identifiers;
20748 Check_Arg_Count (1);
20749
20750 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
20751
20752 -- Ensure the proper placement of the pragma. Refined states must
20753 -- be associated with a package body.
20754
20755 if Nkind (Pack_Decl) = N_Package_Body then
20756 null;
20757
20758 -- Otherwise the pragma is associated with an illegal construct
20759
20760 else
20761 Pragma_Misplaced;
20762 return;
20763 end if;
20764
20765 Spec_Id := Corresponding_Spec (Pack_Decl);
20766
20767 -- A pragma that applies to a Ghost entity becomes Ghost for the
20768 -- purposes of legality checks and removal of ignored Ghost code.
20769
20770 Mark_Ghost_Pragma (N, Spec_Id);
20771
20772 -- Chain the pragma on the contract for further processing by
20773 -- Analyze_Refined_State_In_Decl_Part.
20774
20775 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
20776
20777 -- The legality checks of pragma Refined_State are affected by the
20778 -- SPARK mode in effect. Analyze all pragmas in a specific order.
20779
20780 Analyze_If_Present (Pragma_SPARK_Mode);
20781
20782 -- State refinement is allowed only when the corresponding package
20783 -- declaration has non-null pragma Abstract_State. Refinement not
20784 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
20785
20786 if SPARK_Mode /= Off
20787 and then
20788 (No (Abstract_States (Spec_Id))
20789 or else Has_Null_Abstract_State (Spec_Id))
20790 then
20791 Error_Msg_NE
20792 ("useless refinement, package & does not define abstract "
20793 & "states", N, Spec_Id);
20794 return;
20795 end if;
20796 end Refined_State;
20797
20798 -----------------------
20799 -- Relative_Deadline --
20800 -----------------------
20801
20802 -- pragma Relative_Deadline (time_span_EXPRESSION);
20803
20804 when Pragma_Relative_Deadline => Relative_Deadline : declare
20805 P : constant Node_Id := Parent (N);
20806 Arg : Node_Id;
20807
20808 begin
20809 Ada_2005_Pragma;
20810 Check_No_Identifiers;
20811 Check_Arg_Count (1);
20812
20813 Arg := Get_Pragma_Arg (Arg1);
20814
20815 -- The expression must be analyzed in the special manner described
20816 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
20817
20818 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
20819
20820 -- Subprogram case
20821
20822 if Nkind (P) = N_Subprogram_Body then
20823 Check_In_Main_Program;
20824
20825 -- Only Task and subprogram cases allowed
20826
20827 elsif Nkind (P) /= N_Task_Definition then
20828 Pragma_Misplaced;
20829 end if;
20830
20831 -- Check duplicate pragma before we set the corresponding flag
20832
20833 if Has_Relative_Deadline_Pragma (P) then
20834 Error_Pragma ("duplicate pragma% not allowed");
20835 end if;
20836
20837 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
20838 -- Relative_Deadline pragma node cannot be inserted in the Rep
20839 -- Item chain of Ent since it is rewritten by the expander as a
20840 -- procedure call statement that will break the chain.
20841
20842 Set_Has_Relative_Deadline_Pragma (P);
20843 end Relative_Deadline;
20844
20845 ------------------------
20846 -- Remote_Access_Type --
20847 ------------------------
20848
20849 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
20850
20851 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
20852 E : Entity_Id;
20853
20854 begin
20855 GNAT_Pragma;
20856 Check_Arg_Count (1);
20857 Check_Optional_Identifier (Arg1, Name_Entity);
20858 Check_Arg_Is_Local_Name (Arg1);
20859
20860 E := Entity (Get_Pragma_Arg (Arg1));
20861
20862 -- A pragma that applies to a Ghost entity becomes Ghost for the
20863 -- purposes of legality checks and removal of ignored Ghost code.
20864
20865 Mark_Ghost_Pragma (N, E);
20866
20867 if Nkind (Parent (E)) = N_Formal_Type_Declaration
20868 and then Ekind (E) = E_General_Access_Type
20869 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
20870 and then Scope (Root_Type (Directly_Designated_Type (E)))
20871 = Scope (E)
20872 and then Is_Valid_Remote_Object_Type
20873 (Root_Type (Directly_Designated_Type (E)))
20874 then
20875 Set_Is_Remote_Types (E);
20876
20877 else
20878 Error_Pragma_Arg
20879 ("pragma% applies only to formal access-to-class-wide types",
20880 Arg1);
20881 end if;
20882 end Remote_Access_Type;
20883
20884 ---------------------------
20885 -- Remote_Call_Interface --
20886 ---------------------------
20887
20888 -- pragma Remote_Call_Interface [(library_unit_NAME)];
20889
20890 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
20891 Cunit_Node : Node_Id;
20892 Cunit_Ent : Entity_Id;
20893 K : Node_Kind;
20894
20895 begin
20896 Check_Ada_83_Warning;
20897 Check_Valid_Library_Unit_Pragma;
20898
20899 if Nkind (N) = N_Null_Statement then
20900 return;
20901 end if;
20902
20903 Cunit_Node := Cunit (Current_Sem_Unit);
20904 K := Nkind (Unit (Cunit_Node));
20905 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
20906
20907 -- A pragma that applies to a Ghost entity becomes Ghost for the
20908 -- purposes of legality checks and removal of ignored Ghost code.
20909
20910 Mark_Ghost_Pragma (N, Cunit_Ent);
20911
20912 if K = N_Package_Declaration
20913 or else K = N_Generic_Package_Declaration
20914 or else K = N_Subprogram_Declaration
20915 or else K = N_Generic_Subprogram_Declaration
20916 or else (K = N_Subprogram_Body
20917 and then Acts_As_Spec (Unit (Cunit_Node)))
20918 then
20919 null;
20920 else
20921 Error_Pragma (
20922 "pragma% must apply to package or subprogram declaration");
20923 end if;
20924
20925 Set_Is_Remote_Call_Interface (Cunit_Ent);
20926 end Remote_Call_Interface;
20927
20928 ------------------
20929 -- Remote_Types --
20930 ------------------
20931
20932 -- pragma Remote_Types [(library_unit_NAME)];
20933
20934 when Pragma_Remote_Types => Remote_Types : declare
20935 Cunit_Node : Node_Id;
20936 Cunit_Ent : Entity_Id;
20937
20938 begin
20939 Check_Ada_83_Warning;
20940 Check_Valid_Library_Unit_Pragma;
20941
20942 if Nkind (N) = N_Null_Statement then
20943 return;
20944 end if;
20945
20946 Cunit_Node := Cunit (Current_Sem_Unit);
20947 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
20948
20949 -- A pragma that applies to a Ghost entity becomes Ghost for the
20950 -- purposes of legality checks and removal of ignored Ghost code.
20951
20952 Mark_Ghost_Pragma (N, Cunit_Ent);
20953
20954 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
20955 N_Generic_Package_Declaration)
20956 then
20957 Error_Pragma
20958 ("pragma% can only apply to a package declaration");
20959 end if;
20960
20961 Set_Is_Remote_Types (Cunit_Ent);
20962 end Remote_Types;
20963
20964 ---------------
20965 -- Ravenscar --
20966 ---------------
20967
20968 -- pragma Ravenscar;
20969
20970 when Pragma_Ravenscar =>
20971 GNAT_Pragma;
20972 Check_Arg_Count (0);
20973 Check_Valid_Configuration_Pragma;
20974 Set_Ravenscar_Profile (Ravenscar, N);
20975
20976 if Warn_On_Obsolescent_Feature then
20977 Error_Msg_N
20978 ("pragma Ravenscar is an obsolescent feature?j?", N);
20979 Error_Msg_N
20980 ("|use pragma Profile (Ravenscar) instead?j?", N);
20981 end if;
20982
20983 -------------------------
20984 -- Restricted_Run_Time --
20985 -------------------------
20986
20987 -- pragma Restricted_Run_Time;
20988
20989 when Pragma_Restricted_Run_Time =>
20990 GNAT_Pragma;
20991 Check_Arg_Count (0);
20992 Check_Valid_Configuration_Pragma;
20993 Set_Profile_Restrictions
20994 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
20995
20996 if Warn_On_Obsolescent_Feature then
20997 Error_Msg_N
20998 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
20999 N);
21000 Error_Msg_N
21001 ("|use pragma Profile (Restricted) instead?j?", N);
21002 end if;
21003
21004 ------------------
21005 -- Restrictions --
21006 ------------------
21007
21008 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
21009
21010 -- RESTRICTION ::=
21011 -- restriction_IDENTIFIER
21012 -- | restriction_parameter_IDENTIFIER => EXPRESSION
21013
21014 when Pragma_Restrictions =>
21015 Process_Restrictions_Or_Restriction_Warnings
21016 (Warn => Treat_Restrictions_As_Warnings);
21017
21018 --------------------------
21019 -- Restriction_Warnings --
21020 --------------------------
21021
21022 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
21023
21024 -- RESTRICTION ::=
21025 -- restriction_IDENTIFIER
21026 -- | restriction_parameter_IDENTIFIER => EXPRESSION
21027
21028 when Pragma_Restriction_Warnings =>
21029 GNAT_Pragma;
21030 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
21031
21032 ----------------
21033 -- Reviewable --
21034 ----------------
21035
21036 -- pragma Reviewable;
21037
21038 when Pragma_Reviewable =>
21039 Check_Ada_83_Warning;
21040 Check_Arg_Count (0);
21041
21042 -- Call dummy debugging function rv. This is done to assist front
21043 -- end debugging. By placing a Reviewable pragma in the source
21044 -- program, a breakpoint on rv catches this place in the source,
21045 -- allowing convenient stepping to the point of interest.
21046
21047 rv;
21048
21049 --------------------------
21050 -- Secondary_Stack_Size --
21051 --------------------------
21052
21053 -- pragma Secondary_Stack_Size (EXPRESSION);
21054
21055 when Pragma_Secondary_Stack_Size => Secondary_Stack_Size : declare
21056 P : constant Node_Id := Parent (N);
21057 Arg : Node_Id;
21058 Ent : Entity_Id;
21059
21060 begin
21061 GNAT_Pragma;
21062 Check_No_Identifiers;
21063 Check_Arg_Count (1);
21064
21065 if Nkind (P) = N_Task_Definition then
21066 Arg := Get_Pragma_Arg (Arg1);
21067 Ent := Defining_Identifier (Parent (P));
21068
21069 -- The expression must be analyzed in the special manner
21070 -- described in "Handling of Default Expressions" in sem.ads.
21071
21072 Preanalyze_Spec_Expression (Arg, Any_Integer);
21073
21074 -- The pragma cannot appear if the No_Secondary_Stack
21075 -- restriction is in effect.
21076
21077 Check_Restriction (No_Secondary_Stack, Arg);
21078
21079 -- Anything else is incorrect
21080
21081 else
21082 Pragma_Misplaced;
21083 end if;
21084
21085 -- Check duplicate pragma before we chain the pragma in the Rep
21086 -- Item chain of Ent.
21087
21088 Check_Duplicate_Pragma (Ent);
21089 Record_Rep_Item (Ent, N);
21090 end Secondary_Stack_Size;
21091
21092 --------------------------
21093 -- Short_Circuit_And_Or --
21094 --------------------------
21095
21096 -- pragma Short_Circuit_And_Or;
21097
21098 when Pragma_Short_Circuit_And_Or =>
21099 GNAT_Pragma;
21100 Check_Arg_Count (0);
21101 Check_Valid_Configuration_Pragma;
21102 Short_Circuit_And_Or := True;
21103
21104 -------------------
21105 -- Share_Generic --
21106 -------------------
21107
21108 -- pragma Share_Generic (GNAME {, GNAME});
21109
21110 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
21111
21112 when Pragma_Share_Generic =>
21113 GNAT_Pragma;
21114 Process_Generic_List;
21115
21116 ------------
21117 -- Shared --
21118 ------------
21119
21120 -- pragma Shared (LOCAL_NAME);
21121
21122 when Pragma_Shared =>
21123 GNAT_Pragma;
21124 Process_Atomic_Independent_Shared_Volatile;
21125
21126 --------------------
21127 -- Shared_Passive --
21128 --------------------
21129
21130 -- pragma Shared_Passive [(library_unit_NAME)];
21131
21132 -- Set the flag Is_Shared_Passive of program unit name entity
21133
21134 when Pragma_Shared_Passive => Shared_Passive : declare
21135 Cunit_Node : Node_Id;
21136 Cunit_Ent : Entity_Id;
21137
21138 begin
21139 Check_Ada_83_Warning;
21140 Check_Valid_Library_Unit_Pragma;
21141
21142 if Nkind (N) = N_Null_Statement then
21143 return;
21144 end if;
21145
21146 Cunit_Node := Cunit (Current_Sem_Unit);
21147 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
21148
21149 -- A pragma that applies to a Ghost entity becomes Ghost for the
21150 -- purposes of legality checks and removal of ignored Ghost code.
21151
21152 Mark_Ghost_Pragma (N, Cunit_Ent);
21153
21154 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
21155 N_Generic_Package_Declaration)
21156 then
21157 Error_Pragma
21158 ("pragma% can only apply to a package declaration");
21159 end if;
21160
21161 Set_Is_Shared_Passive (Cunit_Ent);
21162 end Shared_Passive;
21163
21164 -----------------------
21165 -- Short_Descriptors --
21166 -----------------------
21167
21168 -- pragma Short_Descriptors;
21169
21170 -- Recognize and validate, but otherwise ignore
21171
21172 when Pragma_Short_Descriptors =>
21173 GNAT_Pragma;
21174 Check_Arg_Count (0);
21175 Check_Valid_Configuration_Pragma;
21176
21177 ------------------------------
21178 -- Simple_Storage_Pool_Type --
21179 ------------------------------
21180
21181 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
21182
21183 when Pragma_Simple_Storage_Pool_Type =>
21184 Simple_Storage_Pool_Type : declare
21185 Typ : Entity_Id;
21186 Type_Id : Node_Id;
21187
21188 begin
21189 GNAT_Pragma;
21190 Check_Arg_Count (1);
21191 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21192
21193 Type_Id := Get_Pragma_Arg (Arg1);
21194 Find_Type (Type_Id);
21195 Typ := Entity (Type_Id);
21196
21197 if Typ = Any_Type then
21198 return;
21199 end if;
21200
21201 -- A pragma that applies to a Ghost entity becomes Ghost for the
21202 -- purposes of legality checks and removal of ignored Ghost code.
21203
21204 Mark_Ghost_Pragma (N, Typ);
21205
21206 -- We require the pragma to apply to a type declared in a package
21207 -- declaration, but not (immediately) within a package body.
21208
21209 if Ekind (Current_Scope) /= E_Package
21210 or else In_Package_Body (Current_Scope)
21211 then
21212 Error_Pragma
21213 ("pragma% can only apply to type declared immediately "
21214 & "within a package declaration");
21215 end if;
21216
21217 -- A simple storage pool type must be an immutably limited record
21218 -- or private type. If the pragma is given for a private type,
21219 -- the full type is similarly restricted (which is checked later
21220 -- in Freeze_Entity).
21221
21222 if Is_Record_Type (Typ)
21223 and then not Is_Limited_View (Typ)
21224 then
21225 Error_Pragma
21226 ("pragma% can only apply to explicitly limited record type");
21227
21228 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
21229 Error_Pragma
21230 ("pragma% can only apply to a private type that is limited");
21231
21232 elsif not Is_Record_Type (Typ)
21233 and then not Is_Private_Type (Typ)
21234 then
21235 Error_Pragma
21236 ("pragma% can only apply to limited record or private type");
21237 end if;
21238
21239 Record_Rep_Item (Typ, N);
21240 end Simple_Storage_Pool_Type;
21241
21242 ----------------------
21243 -- Source_File_Name --
21244 ----------------------
21245
21246 -- There are five forms for this pragma:
21247
21248 -- pragma Source_File_Name (
21249 -- [UNIT_NAME =>] unit_NAME,
21250 -- BODY_FILE_NAME => STRING_LITERAL
21251 -- [, [INDEX =>] INTEGER_LITERAL]);
21252
21253 -- pragma Source_File_Name (
21254 -- [UNIT_NAME =>] unit_NAME,
21255 -- SPEC_FILE_NAME => STRING_LITERAL
21256 -- [, [INDEX =>] INTEGER_LITERAL]);
21257
21258 -- pragma Source_File_Name (
21259 -- BODY_FILE_NAME => STRING_LITERAL
21260 -- [, DOT_REPLACEMENT => STRING_LITERAL]
21261 -- [, CASING => CASING_SPEC]);
21262
21263 -- pragma Source_File_Name (
21264 -- SPEC_FILE_NAME => STRING_LITERAL
21265 -- [, DOT_REPLACEMENT => STRING_LITERAL]
21266 -- [, CASING => CASING_SPEC]);
21267
21268 -- pragma Source_File_Name (
21269 -- SUBUNIT_FILE_NAME => STRING_LITERAL
21270 -- [, DOT_REPLACEMENT => STRING_LITERAL]
21271 -- [, CASING => CASING_SPEC]);
21272
21273 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
21274
21275 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
21276 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
21277 -- only be used when no project file is used, while SFNP can only be
21278 -- used when a project file is used.
21279
21280 -- No processing here. Processing was completed during parsing, since
21281 -- we need to have file names set as early as possible. Units are
21282 -- loaded well before semantic processing starts.
21283
21284 -- The only processing we defer to this point is the check for
21285 -- correct placement.
21286
21287 when Pragma_Source_File_Name =>
21288 GNAT_Pragma;
21289 Check_Valid_Configuration_Pragma;
21290
21291 ------------------------------
21292 -- Source_File_Name_Project --
21293 ------------------------------
21294
21295 -- See Source_File_Name for syntax
21296
21297 -- No processing here. Processing was completed during parsing, since
21298 -- we need to have file names set as early as possible. Units are
21299 -- loaded well before semantic processing starts.
21300
21301 -- The only processing we defer to this point is the check for
21302 -- correct placement.
21303
21304 when Pragma_Source_File_Name_Project =>
21305 GNAT_Pragma;
21306 Check_Valid_Configuration_Pragma;
21307
21308 -- Check that a pragma Source_File_Name_Project is used only in a
21309 -- configuration pragmas file.
21310
21311 -- Pragmas Source_File_Name_Project should only be generated by
21312 -- the Project Manager in configuration pragmas files.
21313
21314 -- This is really an ugly test. It seems to depend on some
21315 -- accidental and undocumented property. At the very least it
21316 -- needs to be documented, but it would be better to have a
21317 -- clean way of testing if we are in a configuration file???
21318
21319 if Present (Parent (N)) then
21320 Error_Pragma
21321 ("pragma% can only appear in a configuration pragmas file");
21322 end if;
21323
21324 ----------------------
21325 -- Source_Reference --
21326 ----------------------
21327
21328 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
21329
21330 -- Nothing to do, all processing completed in Par.Prag, since we need
21331 -- the information for possible parser messages that are output.
21332
21333 when Pragma_Source_Reference =>
21334 GNAT_Pragma;
21335
21336 ----------------
21337 -- SPARK_Mode --
21338 ----------------
21339
21340 -- pragma SPARK_Mode [(On | Off)];
21341
21342 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
21343 Mode_Id : SPARK_Mode_Type;
21344
21345 procedure Check_Pragma_Conformance
21346 (Context_Pragma : Node_Id;
21347 Entity : Entity_Id;
21348 Entity_Pragma : Node_Id);
21349 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
21350 -- conformance of pragma N depending the following scenarios:
21351 --
21352 -- If pragma Context_Pragma is not Empty, verify that pragma N is
21353 -- compatible with the pragma Context_Pragma that was inherited
21354 -- from the context:
21355 -- * If the mode of Context_Pragma is ON, then the new mode can
21356 -- be anything.
21357 -- * If the mode of Context_Pragma is OFF, then the only allowed
21358 -- new mode is also OFF. Emit error if this is not the case.
21359 --
21360 -- If Entity is not Empty, verify that pragma N is compatible with
21361 -- pragma Entity_Pragma that belongs to Entity.
21362 -- * If Entity_Pragma is Empty, always issue an error as this
21363 -- corresponds to the case where a previous section of Entity
21364 -- has no SPARK_Mode set.
21365 -- * If the mode of Entity_Pragma is ON, then the new mode can
21366 -- be anything.
21367 -- * If the mode of Entity_Pragma is OFF, then the only allowed
21368 -- new mode is also OFF. Emit error if this is not the case.
21369
21370 procedure Check_Library_Level_Entity (E : Entity_Id);
21371 -- Subsidiary to routines Process_xxx. Verify that the related
21372 -- entity E subject to pragma SPARK_Mode is library-level.
21373
21374 procedure Process_Body (Decl : Node_Id);
21375 -- Verify the legality of pragma SPARK_Mode when it appears as the
21376 -- top of the body declarations of entry, package, protected unit,
21377 -- subprogram or task unit body denoted by Decl.
21378
21379 procedure Process_Overloadable (Decl : Node_Id);
21380 -- Verify the legality of pragma SPARK_Mode when it applies to an
21381 -- entry or [generic] subprogram declaration denoted by Decl.
21382
21383 procedure Process_Private_Part (Decl : Node_Id);
21384 -- Verify the legality of pragma SPARK_Mode when it appears at the
21385 -- top of the private declarations of a package spec, protected or
21386 -- task unit declaration denoted by Decl.
21387
21388 procedure Process_Statement_Part (Decl : Node_Id);
21389 -- Verify the legality of pragma SPARK_Mode when it appears at the
21390 -- top of the statement sequence of a package body denoted by node
21391 -- Decl.
21392
21393 procedure Process_Visible_Part (Decl : Node_Id);
21394 -- Verify the legality of pragma SPARK_Mode when it appears at the
21395 -- top of the visible declarations of a package spec, protected or
21396 -- task unit declaration denoted by Decl. The routine is also used
21397 -- on protected or task units declared without a definition.
21398
21399 procedure Set_SPARK_Context;
21400 -- Subsidiary to routines Process_xxx. Set the global variables
21401 -- which represent the mode of the context from pragma N. Ensure
21402 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
21403
21404 ------------------------------
21405 -- Check_Pragma_Conformance --
21406 ------------------------------
21407
21408 procedure Check_Pragma_Conformance
21409 (Context_Pragma : Node_Id;
21410 Entity : Entity_Id;
21411 Entity_Pragma : Node_Id)
21412 is
21413 Err_Id : Entity_Id;
21414 Err_N : Node_Id;
21415
21416 begin
21417 -- The current pragma may appear without an argument. If this
21418 -- is the case, associate all error messages with the pragma
21419 -- itself.
21420
21421 if Present (Arg1) then
21422 Err_N := Arg1;
21423 else
21424 Err_N := N;
21425 end if;
21426
21427 -- The mode of the current pragma is compared against that of
21428 -- an enclosing context.
21429
21430 if Present (Context_Pragma) then
21431 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
21432
21433 -- Issue an error if the new mode is less restrictive than
21434 -- that of the context.
21435
21436 if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off
21437 and then Get_SPARK_Mode_From_Annotation (N) = On
21438 then
21439 Error_Msg_N
21440 ("cannot change SPARK_Mode from Off to On", Err_N);
21441 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
21442 Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N);
21443 raise Pragma_Exit;
21444 end if;
21445 end if;
21446
21447 -- The mode of the current pragma is compared against that of
21448 -- an initial package, protected type, subprogram or task type
21449 -- declaration.
21450
21451 if Present (Entity) then
21452
21453 -- A simple protected or task type is transformed into an
21454 -- anonymous type whose name cannot be used to issue error
21455 -- messages. Recover the original entity of the type.
21456
21457 if Ekind_In (Entity, E_Protected_Type, E_Task_Type) then
21458 Err_Id :=
21459 Defining_Entity
21460 (Original_Node (Unit_Declaration_Node (Entity)));
21461 else
21462 Err_Id := Entity;
21463 end if;
21464
21465 -- Both the initial declaration and the completion carry
21466 -- SPARK_Mode pragmas.
21467
21468 if Present (Entity_Pragma) then
21469 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
21470
21471 -- Issue an error if the new mode is less restrictive
21472 -- than that of the initial declaration.
21473
21474 if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off
21475 and then Get_SPARK_Mode_From_Annotation (N) = On
21476 then
21477 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
21478 Error_Msg_Sloc := Sloc (Entity_Pragma);
21479 Error_Msg_NE
21480 ("\value Off was set for SPARK_Mode on&#",
21481 Err_N, Err_Id);
21482 raise Pragma_Exit;
21483 end if;
21484
21485 -- Otherwise the initial declaration lacks a SPARK_Mode
21486 -- pragma in which case the current pragma is illegal as
21487 -- it cannot "complete".
21488
21489 else
21490 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
21491 Error_Msg_Sloc := Sloc (Err_Id);
21492 Error_Msg_NE
21493 ("\no value was set for SPARK_Mode on&#",
21494 Err_N, Err_Id);
21495 raise Pragma_Exit;
21496 end if;
21497 end if;
21498 end Check_Pragma_Conformance;
21499
21500 --------------------------------
21501 -- Check_Library_Level_Entity --
21502 --------------------------------
21503
21504 procedure Check_Library_Level_Entity (E : Entity_Id) is
21505 procedure Add_Entity_To_Name_Buffer;
21506 -- Add the E_Kind of entity E to the name buffer
21507
21508 -------------------------------
21509 -- Add_Entity_To_Name_Buffer --
21510 -------------------------------
21511
21512 procedure Add_Entity_To_Name_Buffer is
21513 begin
21514 if Ekind_In (E, E_Entry, E_Entry_Family) then
21515 Add_Str_To_Name_Buffer ("entry");
21516
21517 elsif Ekind_In (E, E_Generic_Package,
21518 E_Package,
21519 E_Package_Body)
21520 then
21521 Add_Str_To_Name_Buffer ("package");
21522
21523 elsif Ekind_In (E, E_Protected_Body, E_Protected_Type) then
21524 Add_Str_To_Name_Buffer ("protected type");
21525
21526 elsif Ekind_In (E, E_Function,
21527 E_Generic_Function,
21528 E_Generic_Procedure,
21529 E_Procedure,
21530 E_Subprogram_Body)
21531 then
21532 Add_Str_To_Name_Buffer ("subprogram");
21533
21534 else
21535 pragma Assert (Ekind_In (E, E_Task_Body, E_Task_Type));
21536 Add_Str_To_Name_Buffer ("task type");
21537 end if;
21538 end Add_Entity_To_Name_Buffer;
21539
21540 -- Local variables
21541
21542 Msg_1 : constant String := "incorrect placement of pragma%";
21543 Msg_2 : Name_Id;
21544
21545 -- Start of processing for Check_Library_Level_Entity
21546
21547 begin
21548 if not Is_Library_Level_Entity (E) then
21549 Error_Msg_Name_1 := Pname;
21550 Error_Msg_N (Fix_Error (Msg_1), N);
21551
21552 Name_Len := 0;
21553 Add_Str_To_Name_Buffer ("\& is not a library-level ");
21554 Add_Entity_To_Name_Buffer;
21555
21556 Msg_2 := Name_Find;
21557 Error_Msg_NE (Get_Name_String (Msg_2), N, E);
21558
21559 raise Pragma_Exit;
21560 end if;
21561 end Check_Library_Level_Entity;
21562
21563 ------------------
21564 -- Process_Body --
21565 ------------------
21566
21567 procedure Process_Body (Decl : Node_Id) is
21568 Body_Id : constant Entity_Id := Defining_Entity (Decl);
21569 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
21570
21571 begin
21572 -- Ignore pragma when applied to the special body created for
21573 -- inlining, recognized by its internal name _Parent.
21574
21575 if Chars (Body_Id) = Name_uParent then
21576 return;
21577 end if;
21578
21579 Check_Library_Level_Entity (Body_Id);
21580
21581 -- For entry bodies, verify the legality against:
21582 -- * The mode of the context
21583 -- * The mode of the spec (if any)
21584
21585 if Nkind_In (Decl, N_Entry_Body, N_Subprogram_Body) then
21586
21587 -- A stand alone subprogram body
21588
21589 if Body_Id = Spec_Id then
21590 Check_Pragma_Conformance
21591 (Context_Pragma => SPARK_Pragma (Body_Id),
21592 Entity => Empty,
21593 Entity_Pragma => Empty);
21594
21595 -- An entry or subprogram body that completes a previous
21596 -- declaration.
21597
21598 else
21599 Check_Pragma_Conformance
21600 (Context_Pragma => SPARK_Pragma (Body_Id),
21601 Entity => Spec_Id,
21602 Entity_Pragma => SPARK_Pragma (Spec_Id));
21603 end if;
21604
21605 Set_SPARK_Context;
21606 Set_SPARK_Pragma (Body_Id, N);
21607 Set_SPARK_Pragma_Inherited (Body_Id, False);
21608
21609 -- For package bodies, verify the legality against:
21610 -- * The mode of the context
21611 -- * The mode of the private part
21612
21613 -- This case is separated from protected and task bodies
21614 -- because the statement part of the package body inherits
21615 -- the mode of the body declarations.
21616
21617 elsif Nkind (Decl) = N_Package_Body then
21618 Check_Pragma_Conformance
21619 (Context_Pragma => SPARK_Pragma (Body_Id),
21620 Entity => Spec_Id,
21621 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
21622
21623 Set_SPARK_Context;
21624 Set_SPARK_Pragma (Body_Id, N);
21625 Set_SPARK_Pragma_Inherited (Body_Id, False);
21626 Set_SPARK_Aux_Pragma (Body_Id, N);
21627 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
21628
21629 -- For protected and task bodies, verify the legality against:
21630 -- * The mode of the context
21631 -- * The mode of the private part
21632
21633 else
21634 pragma Assert
21635 (Nkind_In (Decl, N_Protected_Body, N_Task_Body));
21636
21637 Check_Pragma_Conformance
21638 (Context_Pragma => SPARK_Pragma (Body_Id),
21639 Entity => Spec_Id,
21640 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
21641
21642 Set_SPARK_Context;
21643 Set_SPARK_Pragma (Body_Id, N);
21644 Set_SPARK_Pragma_Inherited (Body_Id, False);
21645 end if;
21646 end Process_Body;
21647
21648 --------------------------
21649 -- Process_Overloadable --
21650 --------------------------
21651
21652 procedure Process_Overloadable (Decl : Node_Id) is
21653 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
21654 Spec_Typ : constant Entity_Id := Etype (Spec_Id);
21655
21656 begin
21657 Check_Library_Level_Entity (Spec_Id);
21658
21659 -- Verify the legality against:
21660 -- * The mode of the context
21661
21662 Check_Pragma_Conformance
21663 (Context_Pragma => SPARK_Pragma (Spec_Id),
21664 Entity => Empty,
21665 Entity_Pragma => Empty);
21666
21667 Set_SPARK_Pragma (Spec_Id, N);
21668 Set_SPARK_Pragma_Inherited (Spec_Id, False);
21669
21670 -- When the pragma applies to the anonymous object created for
21671 -- a single task type, decorate the type as well. This scenario
21672 -- arises when the single task type lacks a task definition,
21673 -- therefore there is no issue with respect to a potential
21674 -- pragma SPARK_Mode in the private part.
21675
21676 -- task type Anon_Task_Typ;
21677 -- Obj : Anon_Task_Typ;
21678 -- pragma SPARK_Mode ...;
21679
21680 if Is_Single_Task_Object (Spec_Id) then
21681 Set_SPARK_Pragma (Spec_Typ, N);
21682 Set_SPARK_Pragma_Inherited (Spec_Typ, False);
21683 Set_SPARK_Aux_Pragma (Spec_Typ, N);
21684 Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True);
21685 end if;
21686 end Process_Overloadable;
21687
21688 --------------------------
21689 -- Process_Private_Part --
21690 --------------------------
21691
21692 procedure Process_Private_Part (Decl : Node_Id) is
21693 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
21694
21695 begin
21696 Check_Library_Level_Entity (Spec_Id);
21697
21698 -- Verify the legality against:
21699 -- * The mode of the visible declarations
21700
21701 Check_Pragma_Conformance
21702 (Context_Pragma => Empty,
21703 Entity => Spec_Id,
21704 Entity_Pragma => SPARK_Pragma (Spec_Id));
21705
21706 Set_SPARK_Context;
21707 Set_SPARK_Aux_Pragma (Spec_Id, N);
21708 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
21709 end Process_Private_Part;
21710
21711 ----------------------------
21712 -- Process_Statement_Part --
21713 ----------------------------
21714
21715 procedure Process_Statement_Part (Decl : Node_Id) is
21716 Body_Id : constant Entity_Id := Defining_Entity (Decl);
21717
21718 begin
21719 Check_Library_Level_Entity (Body_Id);
21720
21721 -- Verify the legality against:
21722 -- * The mode of the body declarations
21723
21724 Check_Pragma_Conformance
21725 (Context_Pragma => Empty,
21726 Entity => Body_Id,
21727 Entity_Pragma => SPARK_Pragma (Body_Id));
21728
21729 Set_SPARK_Context;
21730 Set_SPARK_Aux_Pragma (Body_Id, N);
21731 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
21732 end Process_Statement_Part;
21733
21734 --------------------------
21735 -- Process_Visible_Part --
21736 --------------------------
21737
21738 procedure Process_Visible_Part (Decl : Node_Id) is
21739 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
21740 Obj_Id : Entity_Id;
21741
21742 begin
21743 Check_Library_Level_Entity (Spec_Id);
21744
21745 -- Verify the legality against:
21746 -- * The mode of the context
21747
21748 Check_Pragma_Conformance
21749 (Context_Pragma => SPARK_Pragma (Spec_Id),
21750 Entity => Empty,
21751 Entity_Pragma => Empty);
21752
21753 -- A task unit declared without a definition does not set the
21754 -- SPARK_Mode of the context because the task does not have any
21755 -- entries that could inherit the mode.
21756
21757 if not Nkind_In (Decl, N_Single_Task_Declaration,
21758 N_Task_Type_Declaration)
21759 then
21760 Set_SPARK_Context;
21761 end if;
21762
21763 Set_SPARK_Pragma (Spec_Id, N);
21764 Set_SPARK_Pragma_Inherited (Spec_Id, False);
21765 Set_SPARK_Aux_Pragma (Spec_Id, N);
21766 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
21767
21768 -- When the pragma applies to a single protected or task type,
21769 -- decorate the corresponding anonymous object as well.
21770
21771 -- protected Anon_Prot_Typ is
21772 -- pragma SPARK_Mode ...;
21773 -- ...
21774 -- end Anon_Prot_Typ;
21775
21776 -- Obj : Anon_Prot_Typ;
21777
21778 if Is_Single_Concurrent_Type (Spec_Id) then
21779 Obj_Id := Anonymous_Object (Spec_Id);
21780
21781 Set_SPARK_Pragma (Obj_Id, N);
21782 Set_SPARK_Pragma_Inherited (Obj_Id, False);
21783 end if;
21784 end Process_Visible_Part;
21785
21786 -----------------------
21787 -- Set_SPARK_Context --
21788 -----------------------
21789
21790 procedure Set_SPARK_Context is
21791 begin
21792 SPARK_Mode := Mode_Id;
21793 SPARK_Mode_Pragma := N;
21794 end Set_SPARK_Context;
21795
21796 -- Local variables
21797
21798 Context : Node_Id;
21799 Mode : Name_Id;
21800 Stmt : Node_Id;
21801
21802 -- Start of processing for Do_SPARK_Mode
21803
21804 begin
21805 -- When a SPARK_Mode pragma appears inside an instantiation whose
21806 -- enclosing context has SPARK_Mode set to "off", the pragma has
21807 -- no semantic effect.
21808
21809 if Ignore_SPARK_Mode_Pragmas_In_Instance then
21810 Rewrite (N, Make_Null_Statement (Loc));
21811 Analyze (N);
21812 return;
21813 end if;
21814
21815 GNAT_Pragma;
21816 Check_No_Identifiers;
21817 Check_At_Most_N_Arguments (1);
21818
21819 -- Check the legality of the mode (no argument = ON)
21820
21821 if Arg_Count = 1 then
21822 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
21823 Mode := Chars (Get_Pragma_Arg (Arg1));
21824 else
21825 Mode := Name_On;
21826 end if;
21827
21828 Mode_Id := Get_SPARK_Mode_Type (Mode);
21829 Context := Parent (N);
21830
21831 -- The pragma appears in a configuration file
21832
21833 if No (Context) then
21834 Check_Valid_Configuration_Pragma;
21835
21836 if Present (SPARK_Mode_Pragma) then
21837 Duplication_Error
21838 (Prag => N,
21839 Prev => SPARK_Mode_Pragma);
21840 raise Pragma_Exit;
21841 end if;
21842
21843 Set_SPARK_Context;
21844
21845 -- The pragma acts as a configuration pragma in a compilation unit
21846
21847 -- pragma SPARK_Mode ...;
21848 -- package Pack is ...;
21849
21850 elsif Nkind (Context) = N_Compilation_Unit
21851 and then List_Containing (N) = Context_Items (Context)
21852 then
21853 Check_Valid_Configuration_Pragma;
21854 Set_SPARK_Context;
21855
21856 -- Otherwise the placement of the pragma within the tree dictates
21857 -- its associated construct. Inspect the declarative list where
21858 -- the pragma resides to find a potential construct.
21859
21860 else
21861 Stmt := Prev (N);
21862 while Present (Stmt) loop
21863
21864 -- Skip prior pragmas, but check for duplicates. Note that
21865 -- this also takes care of pragmas generated for aspects.
21866
21867 if Nkind (Stmt) = N_Pragma then
21868 if Pragma_Name (Stmt) = Pname then
21869 Duplication_Error
21870 (Prag => N,
21871 Prev => Stmt);
21872 raise Pragma_Exit;
21873 end if;
21874
21875 -- The pragma applies to an expression function that has
21876 -- already been rewritten into a subprogram declaration.
21877
21878 -- function Expr_Func return ... is (...);
21879 -- pragma SPARK_Mode ...;
21880
21881 elsif Nkind (Stmt) = N_Subprogram_Declaration
21882 and then Nkind (Original_Node (Stmt)) =
21883 N_Expression_Function
21884 then
21885 Process_Overloadable (Stmt);
21886 return;
21887
21888 -- The pragma applies to the anonymous object created for a
21889 -- single concurrent type.
21890
21891 -- protected type Anon_Prot_Typ ...;
21892 -- Obj : Anon_Prot_Typ;
21893 -- pragma SPARK_Mode ...;
21894
21895 elsif Nkind (Stmt) = N_Object_Declaration
21896 and then Is_Single_Concurrent_Object
21897 (Defining_Entity (Stmt))
21898 then
21899 Process_Overloadable (Stmt);
21900 return;
21901
21902 -- Skip internally generated code
21903
21904 elsif not Comes_From_Source (Stmt) then
21905 null;
21906
21907 -- The pragma applies to an entry or [generic] subprogram
21908 -- declaration.
21909
21910 -- entry Ent ...;
21911 -- pragma SPARK_Mode ...;
21912
21913 -- [generic]
21914 -- procedure Proc ...;
21915 -- pragma SPARK_Mode ...;
21916
21917 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
21918 N_Subprogram_Declaration)
21919 or else (Nkind (Stmt) = N_Entry_Declaration
21920 and then Is_Protected_Type
21921 (Scope (Defining_Entity (Stmt))))
21922 then
21923 Process_Overloadable (Stmt);
21924 return;
21925
21926 -- Otherwise the pragma does not apply to a legal construct
21927 -- or it does not appear at the top of a declarative or a
21928 -- statement list. Issue an error and stop the analysis.
21929
21930 else
21931 Pragma_Misplaced;
21932 exit;
21933 end if;
21934
21935 Prev (Stmt);
21936 end loop;
21937
21938 -- The pragma applies to a package or a subprogram that acts as
21939 -- a compilation unit.
21940
21941 -- procedure Proc ...;
21942 -- pragma SPARK_Mode ...;
21943
21944 if Nkind (Context) = N_Compilation_Unit_Aux then
21945 Context := Unit (Parent (Context));
21946 end if;
21947
21948 -- The pragma appears at the top of entry, package, protected
21949 -- unit, subprogram or task unit body declarations.
21950
21951 -- entry Ent when ... is
21952 -- pragma SPARK_Mode ...;
21953
21954 -- package body Pack is
21955 -- pragma SPARK_Mode ...;
21956
21957 -- procedure Proc ... is
21958 -- pragma SPARK_Mode;
21959
21960 -- protected body Prot is
21961 -- pragma SPARK_Mode ...;
21962
21963 if Nkind_In (Context, N_Entry_Body,
21964 N_Package_Body,
21965 N_Protected_Body,
21966 N_Subprogram_Body,
21967 N_Task_Body)
21968 then
21969 Process_Body (Context);
21970
21971 -- The pragma appears at the top of the visible or private
21972 -- declaration of a package spec, protected or task unit.
21973
21974 -- package Pack is
21975 -- pragma SPARK_Mode ...;
21976 -- private
21977 -- pragma SPARK_Mode ...;
21978
21979 -- protected [type] Prot is
21980 -- pragma SPARK_Mode ...;
21981 -- private
21982 -- pragma SPARK_Mode ...;
21983
21984 elsif Nkind_In (Context, N_Package_Specification,
21985 N_Protected_Definition,
21986 N_Task_Definition)
21987 then
21988 if List_Containing (N) = Visible_Declarations (Context) then
21989 Process_Visible_Part (Parent (Context));
21990 else
21991 Process_Private_Part (Parent (Context));
21992 end if;
21993
21994 -- The pragma appears at the top of package body statements
21995
21996 -- package body Pack is
21997 -- begin
21998 -- pragma SPARK_Mode;
21999
22000 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
22001 and then Nkind (Parent (Context)) = N_Package_Body
22002 then
22003 Process_Statement_Part (Parent (Context));
22004
22005 -- The pragma appeared as an aspect of a [generic] subprogram
22006 -- declaration that acts as a compilation unit.
22007
22008 -- [generic]
22009 -- procedure Proc ...;
22010 -- pragma SPARK_Mode ...;
22011
22012 elsif Nkind_In (Context, N_Generic_Subprogram_Declaration,
22013 N_Subprogram_Declaration)
22014 then
22015 Process_Overloadable (Context);
22016
22017 -- The pragma does not apply to a legal construct, issue error
22018
22019 else
22020 Pragma_Misplaced;
22021 end if;
22022 end if;
22023 end Do_SPARK_Mode;
22024
22025 --------------------------------
22026 -- Static_Elaboration_Desired --
22027 --------------------------------
22028
22029 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
22030
22031 when Pragma_Static_Elaboration_Desired =>
22032 GNAT_Pragma;
22033 Check_At_Most_N_Arguments (1);
22034
22035 if Is_Compilation_Unit (Current_Scope)
22036 and then Ekind (Current_Scope) = E_Package
22037 then
22038 Set_Static_Elaboration_Desired (Current_Scope, True);
22039 else
22040 Error_Pragma ("pragma% must apply to a library-level package");
22041 end if;
22042
22043 ------------------
22044 -- Storage_Size --
22045 ------------------
22046
22047 -- pragma Storage_Size (EXPRESSION);
22048
22049 when Pragma_Storage_Size => Storage_Size : declare
22050 P : constant Node_Id := Parent (N);
22051 Arg : Node_Id;
22052
22053 begin
22054 Check_No_Identifiers;
22055 Check_Arg_Count (1);
22056
22057 -- The expression must be analyzed in the special manner described
22058 -- in "Handling of Default Expressions" in sem.ads.
22059
22060 Arg := Get_Pragma_Arg (Arg1);
22061 Preanalyze_Spec_Expression (Arg, Any_Integer);
22062
22063 if not Is_OK_Static_Expression (Arg) then
22064 Check_Restriction (Static_Storage_Size, Arg);
22065 end if;
22066
22067 if Nkind (P) /= N_Task_Definition then
22068 Pragma_Misplaced;
22069 return;
22070
22071 else
22072 if Has_Storage_Size_Pragma (P) then
22073 Error_Pragma ("duplicate pragma% not allowed");
22074 else
22075 Set_Has_Storage_Size_Pragma (P, True);
22076 end if;
22077
22078 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
22079 end if;
22080 end Storage_Size;
22081
22082 ------------------
22083 -- Storage_Unit --
22084 ------------------
22085
22086 -- pragma Storage_Unit (NUMERIC_LITERAL);
22087
22088 -- Only permitted argument is System'Storage_Unit value
22089
22090 when Pragma_Storage_Unit =>
22091 Check_No_Identifiers;
22092 Check_Arg_Count (1);
22093 Check_Arg_Is_Integer_Literal (Arg1);
22094
22095 if Intval (Get_Pragma_Arg (Arg1)) /=
22096 UI_From_Int (Ttypes.System_Storage_Unit)
22097 then
22098 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
22099 Error_Pragma_Arg
22100 ("the only allowed argument for pragma% is ^", Arg1);
22101 end if;
22102
22103 --------------------
22104 -- Stream_Convert --
22105 --------------------
22106
22107 -- pragma Stream_Convert (
22108 -- [Entity =>] type_LOCAL_NAME,
22109 -- [Read =>] function_NAME,
22110 -- [Write =>] function NAME);
22111
22112 when Pragma_Stream_Convert => Stream_Convert : declare
22113 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
22114 -- Check that the given argument is the name of a local function
22115 -- of one argument that is not overloaded earlier in the current
22116 -- local scope. A check is also made that the argument is a
22117 -- function with one parameter.
22118
22119 --------------------------------------
22120 -- Check_OK_Stream_Convert_Function --
22121 --------------------------------------
22122
22123 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
22124 Ent : Entity_Id;
22125
22126 begin
22127 Check_Arg_Is_Local_Name (Arg);
22128 Ent := Entity (Get_Pragma_Arg (Arg));
22129
22130 if Has_Homonym (Ent) then
22131 Error_Pragma_Arg
22132 ("argument for pragma% may not be overloaded", Arg);
22133 end if;
22134
22135 if Ekind (Ent) /= E_Function
22136 or else No (First_Formal (Ent))
22137 or else Present (Next_Formal (First_Formal (Ent)))
22138 then
22139 Error_Pragma_Arg
22140 ("argument for pragma% must be function of one argument",
22141 Arg);
22142 end if;
22143 end Check_OK_Stream_Convert_Function;
22144
22145 -- Start of processing for Stream_Convert
22146
22147 begin
22148 GNAT_Pragma;
22149 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
22150 Check_Arg_Count (3);
22151 Check_Optional_Identifier (Arg1, Name_Entity);
22152 Check_Optional_Identifier (Arg2, Name_Read);
22153 Check_Optional_Identifier (Arg3, Name_Write);
22154 Check_Arg_Is_Local_Name (Arg1);
22155 Check_OK_Stream_Convert_Function (Arg2);
22156 Check_OK_Stream_Convert_Function (Arg3);
22157
22158 declare
22159 Typ : constant Entity_Id :=
22160 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
22161 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
22162 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
22163
22164 begin
22165 Check_First_Subtype (Arg1);
22166
22167 -- Check for too early or too late. Note that we don't enforce
22168 -- the rule about primitive operations in this case, since, as
22169 -- is the case for explicit stream attributes themselves, these
22170 -- restrictions are not appropriate. Note that the chaining of
22171 -- the pragma by Rep_Item_Too_Late is actually the critical
22172 -- processing done for this pragma.
22173
22174 if Rep_Item_Too_Early (Typ, N)
22175 or else
22176 Rep_Item_Too_Late (Typ, N, FOnly => True)
22177 then
22178 return;
22179 end if;
22180
22181 -- Return if previous error
22182
22183 if Etype (Typ) = Any_Type
22184 or else
22185 Etype (Read) = Any_Type
22186 or else
22187 Etype (Write) = Any_Type
22188 then
22189 return;
22190 end if;
22191
22192 -- Error checks
22193
22194 if Underlying_Type (Etype (Read)) /= Typ then
22195 Error_Pragma_Arg
22196 ("incorrect return type for function&", Arg2);
22197 end if;
22198
22199 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
22200 Error_Pragma_Arg
22201 ("incorrect parameter type for function&", Arg3);
22202 end if;
22203
22204 if Underlying_Type (Etype (First_Formal (Read))) /=
22205 Underlying_Type (Etype (Write))
22206 then
22207 Error_Pragma_Arg
22208 ("result type of & does not match Read parameter type",
22209 Arg3);
22210 end if;
22211 end;
22212 end Stream_Convert;
22213
22214 ------------------
22215 -- Style_Checks --
22216 ------------------
22217
22218 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
22219
22220 -- This is processed by the parser since some of the style checks
22221 -- take place during source scanning and parsing. This means that
22222 -- we don't need to issue error messages here.
22223
22224 when Pragma_Style_Checks => Style_Checks : declare
22225 A : constant Node_Id := Get_Pragma_Arg (Arg1);
22226 S : String_Id;
22227 C : Char_Code;
22228
22229 begin
22230 GNAT_Pragma;
22231 Check_No_Identifiers;
22232
22233 -- Two argument form
22234
22235 if Arg_Count = 2 then
22236 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
22237
22238 declare
22239 E_Id : Node_Id;
22240 E : Entity_Id;
22241
22242 begin
22243 E_Id := Get_Pragma_Arg (Arg2);
22244 Analyze (E_Id);
22245
22246 if not Is_Entity_Name (E_Id) then
22247 Error_Pragma_Arg
22248 ("second argument of pragma% must be entity name",
22249 Arg2);
22250 end if;
22251
22252 E := Entity (E_Id);
22253
22254 if not Ignore_Style_Checks_Pragmas then
22255 if E = Any_Id then
22256 return;
22257 else
22258 loop
22259 Set_Suppress_Style_Checks
22260 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
22261 exit when No (Homonym (E));
22262 E := Homonym (E);
22263 end loop;
22264 end if;
22265 end if;
22266 end;
22267
22268 -- One argument form
22269
22270 else
22271 Check_Arg_Count (1);
22272
22273 if Nkind (A) = N_String_Literal then
22274 S := Strval (A);
22275
22276 declare
22277 Slen : constant Natural := Natural (String_Length (S));
22278 Options : String (1 .. Slen);
22279 J : Positive;
22280
22281 begin
22282 J := 1;
22283 loop
22284 C := Get_String_Char (S, Pos (J));
22285 exit when not In_Character_Range (C);
22286 Options (J) := Get_Character (C);
22287
22288 -- If at end of string, set options. As per discussion
22289 -- above, no need to check for errors, since we issued
22290 -- them in the parser.
22291
22292 if J = Slen then
22293 if not Ignore_Style_Checks_Pragmas then
22294 Set_Style_Check_Options (Options);
22295 end if;
22296
22297 exit;
22298 end if;
22299
22300 J := J + 1;
22301 end loop;
22302 end;
22303
22304 elsif Nkind (A) = N_Identifier then
22305 if Chars (A) = Name_All_Checks then
22306 if not Ignore_Style_Checks_Pragmas then
22307 if GNAT_Mode then
22308 Set_GNAT_Style_Check_Options;
22309 else
22310 Set_Default_Style_Check_Options;
22311 end if;
22312 end if;
22313
22314 elsif Chars (A) = Name_On then
22315 if not Ignore_Style_Checks_Pragmas then
22316 Style_Check := True;
22317 end if;
22318
22319 elsif Chars (A) = Name_Off then
22320 if not Ignore_Style_Checks_Pragmas then
22321 Style_Check := False;
22322 end if;
22323 end if;
22324 end if;
22325 end if;
22326 end Style_Checks;
22327
22328 --------------
22329 -- Subtitle --
22330 --------------
22331
22332 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
22333
22334 when Pragma_Subtitle =>
22335 GNAT_Pragma;
22336 Check_Arg_Count (1);
22337 Check_Optional_Identifier (Arg1, Name_Subtitle);
22338 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
22339 Store_Note (N);
22340
22341 --------------
22342 -- Suppress --
22343 --------------
22344
22345 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
22346
22347 when Pragma_Suppress =>
22348 Process_Suppress_Unsuppress (Suppress_Case => True);
22349
22350 ------------------
22351 -- Suppress_All --
22352 ------------------
22353
22354 -- pragma Suppress_All;
22355
22356 -- The only check made here is that the pragma has no arguments.
22357 -- There are no placement rules, and the processing required (setting
22358 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
22359 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
22360 -- then creates and inserts a pragma Suppress (All_Checks).
22361
22362 when Pragma_Suppress_All =>
22363 GNAT_Pragma;
22364 Check_Arg_Count (0);
22365
22366 -------------------------
22367 -- Suppress_Debug_Info --
22368 -------------------------
22369
22370 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
22371
22372 when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare
22373 Nam_Id : Entity_Id;
22374
22375 begin
22376 GNAT_Pragma;
22377 Check_Arg_Count (1);
22378 Check_Optional_Identifier (Arg1, Name_Entity);
22379 Check_Arg_Is_Local_Name (Arg1);
22380
22381 Nam_Id := Entity (Get_Pragma_Arg (Arg1));
22382
22383 -- A pragma that applies to a Ghost entity becomes Ghost for the
22384 -- purposes of legality checks and removal of ignored Ghost code.
22385
22386 Mark_Ghost_Pragma (N, Nam_Id);
22387 Set_Debug_Info_Off (Nam_Id);
22388 end Suppress_Debug_Info;
22389
22390 ----------------------------------
22391 -- Suppress_Exception_Locations --
22392 ----------------------------------
22393
22394 -- pragma Suppress_Exception_Locations;
22395
22396 when Pragma_Suppress_Exception_Locations =>
22397 GNAT_Pragma;
22398 Check_Arg_Count (0);
22399 Check_Valid_Configuration_Pragma;
22400 Exception_Locations_Suppressed := True;
22401
22402 -----------------------------
22403 -- Suppress_Initialization --
22404 -----------------------------
22405
22406 -- pragma Suppress_Initialization ([Entity =>] type_Name);
22407
22408 when Pragma_Suppress_Initialization => Suppress_Init : declare
22409 E : Entity_Id;
22410 E_Id : Node_Id;
22411
22412 begin
22413 GNAT_Pragma;
22414 Check_Arg_Count (1);
22415 Check_Optional_Identifier (Arg1, Name_Entity);
22416 Check_Arg_Is_Local_Name (Arg1);
22417
22418 E_Id := Get_Pragma_Arg (Arg1);
22419
22420 if Etype (E_Id) = Any_Type then
22421 return;
22422 end if;
22423
22424 E := Entity (E_Id);
22425
22426 -- A pragma that applies to a Ghost entity becomes Ghost for the
22427 -- purposes of legality checks and removal of ignored Ghost code.
22428
22429 Mark_Ghost_Pragma (N, E);
22430
22431 if not Is_Type (E) and then Ekind (E) /= E_Variable then
22432 Error_Pragma_Arg
22433 ("pragma% requires variable, type or subtype", Arg1);
22434 end if;
22435
22436 if Rep_Item_Too_Early (E, N)
22437 or else
22438 Rep_Item_Too_Late (E, N, FOnly => True)
22439 then
22440 return;
22441 end if;
22442
22443 -- For incomplete/private type, set flag on full view
22444
22445 if Is_Incomplete_Or_Private_Type (E) then
22446 if No (Full_View (Base_Type (E))) then
22447 Error_Pragma_Arg
22448 ("argument of pragma% cannot be an incomplete type", Arg1);
22449 else
22450 Set_Suppress_Initialization (Full_View (Base_Type (E)));
22451 end if;
22452
22453 -- For first subtype, set flag on base type
22454
22455 elsif Is_First_Subtype (E) then
22456 Set_Suppress_Initialization (Base_Type (E));
22457
22458 -- For other than first subtype, set flag on subtype or variable
22459
22460 else
22461 Set_Suppress_Initialization (E);
22462 end if;
22463 end Suppress_Init;
22464
22465 -----------------
22466 -- System_Name --
22467 -----------------
22468
22469 -- pragma System_Name (DIRECT_NAME);
22470
22471 -- Syntax check: one argument, which must be the identifier GNAT or
22472 -- the identifier GCC, no other identifiers are acceptable.
22473
22474 when Pragma_System_Name =>
22475 GNAT_Pragma;
22476 Check_No_Identifiers;
22477 Check_Arg_Count (1);
22478 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
22479
22480 -----------------------------
22481 -- Task_Dispatching_Policy --
22482 -----------------------------
22483
22484 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
22485
22486 when Pragma_Task_Dispatching_Policy => declare
22487 DP : Character;
22488
22489 begin
22490 Check_Ada_83_Warning;
22491 Check_Arg_Count (1);
22492 Check_No_Identifiers;
22493 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
22494 Check_Valid_Configuration_Pragma;
22495 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
22496 DP := Fold_Upper (Name_Buffer (1));
22497
22498 if Task_Dispatching_Policy /= ' '
22499 and then Task_Dispatching_Policy /= DP
22500 then
22501 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
22502 Error_Pragma
22503 ("task dispatching policy incompatible with policy#");
22504
22505 -- Set new policy, but always preserve System_Location since we
22506 -- like the error message with the run time name.
22507
22508 else
22509 Task_Dispatching_Policy := DP;
22510
22511 if Task_Dispatching_Policy_Sloc /= System_Location then
22512 Task_Dispatching_Policy_Sloc := Loc;
22513 end if;
22514 end if;
22515 end;
22516
22517 ---------------
22518 -- Task_Info --
22519 ---------------
22520
22521 -- pragma Task_Info (EXPRESSION);
22522
22523 when Pragma_Task_Info => Task_Info : declare
22524 P : constant Node_Id := Parent (N);
22525 Ent : Entity_Id;
22526
22527 begin
22528 GNAT_Pragma;
22529
22530 if Warn_On_Obsolescent_Feature then
22531 Error_Msg_N
22532 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
22533 & "instead?j?", N);
22534 end if;
22535
22536 if Nkind (P) /= N_Task_Definition then
22537 Error_Pragma ("pragma% must appear in task definition");
22538 end if;
22539
22540 Check_No_Identifiers;
22541 Check_Arg_Count (1);
22542
22543 Analyze_And_Resolve
22544 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
22545
22546 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
22547 return;
22548 end if;
22549
22550 Ent := Defining_Identifier (Parent (P));
22551
22552 -- Check duplicate pragma before we chain the pragma in the Rep
22553 -- Item chain of Ent.
22554
22555 if Has_Rep_Pragma
22556 (Ent, Name_Task_Info, Check_Parents => False)
22557 then
22558 Error_Pragma ("duplicate pragma% not allowed");
22559 end if;
22560
22561 Record_Rep_Item (Ent, N);
22562 end Task_Info;
22563
22564 ---------------
22565 -- Task_Name --
22566 ---------------
22567
22568 -- pragma Task_Name (string_EXPRESSION);
22569
22570 when Pragma_Task_Name => Task_Name : declare
22571 P : constant Node_Id := Parent (N);
22572 Arg : Node_Id;
22573 Ent : Entity_Id;
22574
22575 begin
22576 Check_No_Identifiers;
22577 Check_Arg_Count (1);
22578
22579 Arg := Get_Pragma_Arg (Arg1);
22580
22581 -- The expression is used in the call to Create_Task, and must be
22582 -- expanded there, not in the context of the current spec. It must
22583 -- however be analyzed to capture global references, in case it
22584 -- appears in a generic context.
22585
22586 Preanalyze_And_Resolve (Arg, Standard_String);
22587
22588 if Nkind (P) /= N_Task_Definition then
22589 Pragma_Misplaced;
22590 end if;
22591
22592 Ent := Defining_Identifier (Parent (P));
22593
22594 -- Check duplicate pragma before we chain the pragma in the Rep
22595 -- Item chain of Ent.
22596
22597 if Has_Rep_Pragma
22598 (Ent, Name_Task_Name, Check_Parents => False)
22599 then
22600 Error_Pragma ("duplicate pragma% not allowed");
22601 end if;
22602
22603 Record_Rep_Item (Ent, N);
22604 end Task_Name;
22605
22606 ------------------
22607 -- Task_Storage --
22608 ------------------
22609
22610 -- pragma Task_Storage (
22611 -- [Task_Type =>] LOCAL_NAME,
22612 -- [Top_Guard =>] static_integer_EXPRESSION);
22613
22614 when Pragma_Task_Storage => Task_Storage : declare
22615 Args : Args_List (1 .. 2);
22616 Names : constant Name_List (1 .. 2) := (
22617 Name_Task_Type,
22618 Name_Top_Guard);
22619
22620 Task_Type : Node_Id renames Args (1);
22621 Top_Guard : Node_Id renames Args (2);
22622
22623 Ent : Entity_Id;
22624
22625 begin
22626 GNAT_Pragma;
22627 Gather_Associations (Names, Args);
22628
22629 if No (Task_Type) then
22630 Error_Pragma
22631 ("missing task_type argument for pragma%");
22632 end if;
22633
22634 Check_Arg_Is_Local_Name (Task_Type);
22635
22636 Ent := Entity (Task_Type);
22637
22638 if not Is_Task_Type (Ent) then
22639 Error_Pragma_Arg
22640 ("argument for pragma% must be task type", Task_Type);
22641 end if;
22642
22643 if No (Top_Guard) then
22644 Error_Pragma_Arg
22645 ("pragma% takes two arguments", Task_Type);
22646 else
22647 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
22648 end if;
22649
22650 Check_First_Subtype (Task_Type);
22651
22652 if Rep_Item_Too_Late (Ent, N) then
22653 raise Pragma_Exit;
22654 end if;
22655 end Task_Storage;
22656
22657 ---------------
22658 -- Test_Case --
22659 ---------------
22660
22661 -- pragma Test_Case
22662 -- ([Name =>] Static_String_EXPRESSION
22663 -- ,[Mode =>] MODE_TYPE
22664 -- [, Requires => Boolean_EXPRESSION]
22665 -- [, Ensures => Boolean_EXPRESSION]);
22666
22667 -- MODE_TYPE ::= Nominal | Robustness
22668
22669 -- Characteristics:
22670
22671 -- * Analysis - The annotation undergoes initial checks to verify
22672 -- the legal placement and context. Secondary checks preanalyze the
22673 -- expressions in:
22674
22675 -- Analyze_Test_Case_In_Decl_Part
22676
22677 -- * Expansion - None.
22678
22679 -- * Template - The annotation utilizes the generic template of the
22680 -- related subprogram when it is:
22681
22682 -- aspect on subprogram declaration
22683
22684 -- The annotation must prepare its own template when it is:
22685
22686 -- pragma on subprogram declaration
22687
22688 -- * Globals - Capture of global references must occur after full
22689 -- analysis.
22690
22691 -- * Instance - The annotation is instantiated automatically when
22692 -- the related generic subprogram is instantiated except for the
22693 -- "pragma on subprogram declaration" case. In that scenario the
22694 -- annotation must instantiate itself.
22695
22696 when Pragma_Test_Case => Test_Case : declare
22697 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
22698 -- Ensure that the contract of subprogram Subp_Id does not contain
22699 -- another Test_Case pragma with the same Name as the current one.
22700
22701 -------------------------
22702 -- Check_Distinct_Name --
22703 -------------------------
22704
22705 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
22706 Items : constant Node_Id := Contract (Subp_Id);
22707 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
22708 Prag : Node_Id;
22709
22710 begin
22711 -- Inspect all Test_Case pragma of the related subprogram
22712 -- looking for one with a duplicate "Name" argument.
22713
22714 if Present (Items) then
22715 Prag := Contract_Test_Cases (Items);
22716 while Present (Prag) loop
22717 if Pragma_Name (Prag) = Name_Test_Case
22718 and then Prag /= N
22719 and then String_Equal
22720 (Name, Get_Name_From_CTC_Pragma (Prag))
22721 then
22722 Error_Msg_Sloc := Sloc (Prag);
22723 Error_Pragma ("name for pragma % is already used #");
22724 end if;
22725
22726 Prag := Next_Pragma (Prag);
22727 end loop;
22728 end if;
22729 end Check_Distinct_Name;
22730
22731 -- Local variables
22732
22733 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
22734 Asp_Arg : Node_Id;
22735 Context : Node_Id;
22736 Subp_Decl : Node_Id;
22737 Subp_Id : Entity_Id;
22738
22739 -- Start of processing for Test_Case
22740
22741 begin
22742 GNAT_Pragma;
22743 Check_At_Least_N_Arguments (2);
22744 Check_At_Most_N_Arguments (4);
22745 Check_Arg_Order
22746 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
22747
22748 -- Argument "Name"
22749
22750 Check_Optional_Identifier (Arg1, Name_Name);
22751 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
22752
22753 -- Argument "Mode"
22754
22755 Check_Optional_Identifier (Arg2, Name_Mode);
22756 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
22757
22758 -- Arguments "Requires" and "Ensures"
22759
22760 if Present (Arg3) then
22761 if Present (Arg4) then
22762 Check_Identifier (Arg3, Name_Requires);
22763 Check_Identifier (Arg4, Name_Ensures);
22764 else
22765 Check_Identifier_Is_One_Of
22766 (Arg3, Name_Requires, Name_Ensures);
22767 end if;
22768 end if;
22769
22770 -- Pragma Test_Case must be associated with a subprogram declared
22771 -- in a library-level package. First determine whether the current
22772 -- compilation unit is a legal context.
22773
22774 if Nkind_In (Pack_Decl, N_Package_Declaration,
22775 N_Generic_Package_Declaration)
22776 then
22777 null;
22778
22779 -- Otherwise the placement is illegal
22780
22781 else
22782 Error_Pragma
22783 ("pragma % must be specified within a package declaration");
22784 return;
22785 end if;
22786
22787 Subp_Decl := Find_Related_Declaration_Or_Body (N);
22788
22789 -- Find the enclosing context
22790
22791 Context := Parent (Subp_Decl);
22792
22793 if Present (Context) then
22794 Context := Parent (Context);
22795 end if;
22796
22797 -- Verify the placement of the pragma
22798
22799 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
22800 Error_Pragma
22801 ("pragma % cannot be applied to abstract subprogram");
22802 return;
22803
22804 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
22805 Error_Pragma ("pragma % cannot be applied to entry");
22806 return;
22807
22808 -- The context is a [generic] subprogram declared at the top level
22809 -- of the [generic] package unit.
22810
22811 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
22812 N_Subprogram_Declaration)
22813 and then Present (Context)
22814 and then Nkind_In (Context, N_Generic_Package_Declaration,
22815 N_Package_Declaration)
22816 then
22817 null;
22818
22819 -- Otherwise the placement is illegal
22820
22821 else
22822 Error_Pragma
22823 ("pragma % must be applied to a library-level subprogram "
22824 & "declaration");
22825 return;
22826 end if;
22827
22828 Subp_Id := Defining_Entity (Subp_Decl);
22829
22830 -- A pragma that applies to a Ghost entity becomes Ghost for the
22831 -- purposes of legality checks and removal of ignored Ghost code.
22832
22833 Mark_Ghost_Pragma (N, Subp_Id);
22834
22835 -- Chain the pragma on the contract for further processing by
22836 -- Analyze_Test_Case_In_Decl_Part.
22837
22838 Add_Contract_Item (N, Subp_Id);
22839
22840 -- Preanalyze the original aspect argument "Name" for ASIS or for
22841 -- a generic subprogram to properly capture global references.
22842
22843 if ASIS_Mode or else Is_Generic_Subprogram (Subp_Id) then
22844 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
22845
22846 if Present (Asp_Arg) then
22847
22848 -- The argument appears with an identifier in association
22849 -- form.
22850
22851 if Nkind (Asp_Arg) = N_Component_Association then
22852 Asp_Arg := Expression (Asp_Arg);
22853 end if;
22854
22855 Check_Expr_Is_OK_Static_Expression
22856 (Asp_Arg, Standard_String);
22857 end if;
22858 end if;
22859
22860 -- Ensure that the all Test_Case pragmas of the related subprogram
22861 -- have distinct names.
22862
22863 Check_Distinct_Name (Subp_Id);
22864
22865 -- Fully analyze the pragma when it appears inside an entry
22866 -- or subprogram body because it cannot benefit from forward
22867 -- references.
22868
22869 if Nkind_In (Subp_Decl, N_Entry_Body,
22870 N_Subprogram_Body,
22871 N_Subprogram_Body_Stub)
22872 then
22873 -- The legality checks of pragma Test_Case are affected by the
22874 -- SPARK mode in effect and the volatility of the context.
22875 -- Analyze all pragmas in a specific order.
22876
22877 Analyze_If_Present (Pragma_SPARK_Mode);
22878 Analyze_If_Present (Pragma_Volatile_Function);
22879 Analyze_Test_Case_In_Decl_Part (N);
22880 end if;
22881 end Test_Case;
22882
22883 --------------------------
22884 -- Thread_Local_Storage --
22885 --------------------------
22886
22887 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
22888
22889 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
22890 E : Entity_Id;
22891 Id : Node_Id;
22892
22893 begin
22894 GNAT_Pragma;
22895 Check_Arg_Count (1);
22896 Check_Optional_Identifier (Arg1, Name_Entity);
22897 Check_Arg_Is_Library_Level_Local_Name (Arg1);
22898
22899 Id := Get_Pragma_Arg (Arg1);
22900 Analyze (Id);
22901
22902 if not Is_Entity_Name (Id)
22903 or else Ekind (Entity (Id)) /= E_Variable
22904 then
22905 Error_Pragma_Arg ("local variable name required", Arg1);
22906 end if;
22907
22908 E := Entity (Id);
22909
22910 -- A pragma that applies to a Ghost entity becomes Ghost for the
22911 -- purposes of legality checks and removal of ignored Ghost code.
22912
22913 Mark_Ghost_Pragma (N, E);
22914
22915 if Rep_Item_Too_Early (E, N)
22916 or else
22917 Rep_Item_Too_Late (E, N)
22918 then
22919 raise Pragma_Exit;
22920 end if;
22921
22922 Set_Has_Pragma_Thread_Local_Storage (E);
22923 Set_Has_Gigi_Rep_Item (E);
22924 end Thread_Local_Storage;
22925
22926 ----------------
22927 -- Time_Slice --
22928 ----------------
22929
22930 -- pragma Time_Slice (static_duration_EXPRESSION);
22931
22932 when Pragma_Time_Slice => Time_Slice : declare
22933 Val : Ureal;
22934 Nod : Node_Id;
22935
22936 begin
22937 GNAT_Pragma;
22938 Check_Arg_Count (1);
22939 Check_No_Identifiers;
22940 Check_In_Main_Program;
22941 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
22942
22943 if not Error_Posted (Arg1) then
22944 Nod := Next (N);
22945 while Present (Nod) loop
22946 if Nkind (Nod) = N_Pragma
22947 and then Pragma_Name (Nod) = Name_Time_Slice
22948 then
22949 Error_Msg_Name_1 := Pname;
22950 Error_Msg_N ("duplicate pragma% not permitted", Nod);
22951 end if;
22952
22953 Next (Nod);
22954 end loop;
22955 end if;
22956
22957 -- Process only if in main unit
22958
22959 if Get_Source_Unit (Loc) = Main_Unit then
22960 Opt.Time_Slice_Set := True;
22961 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
22962
22963 if Val <= Ureal_0 then
22964 Opt.Time_Slice_Value := 0;
22965
22966 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
22967 Opt.Time_Slice_Value := 1_000_000_000;
22968
22969 else
22970 Opt.Time_Slice_Value :=
22971 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
22972 end if;
22973 end if;
22974 end Time_Slice;
22975
22976 -----------
22977 -- Title --
22978 -----------
22979
22980 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
22981
22982 -- TITLING_OPTION ::=
22983 -- [Title =>] STRING_LITERAL
22984 -- | [Subtitle =>] STRING_LITERAL
22985
22986 when Pragma_Title => Title : declare
22987 Args : Args_List (1 .. 2);
22988 Names : constant Name_List (1 .. 2) := (
22989 Name_Title,
22990 Name_Subtitle);
22991
22992 begin
22993 GNAT_Pragma;
22994 Gather_Associations (Names, Args);
22995 Store_Note (N);
22996
22997 for J in 1 .. 2 loop
22998 if Present (Args (J)) then
22999 Check_Arg_Is_OK_Static_Expression
23000 (Args (J), Standard_String);
23001 end if;
23002 end loop;
23003 end Title;
23004
23005 ----------------------------
23006 -- Type_Invariant[_Class] --
23007 ----------------------------
23008
23009 -- pragma Type_Invariant[_Class]
23010 -- ([Entity =>] type_LOCAL_NAME,
23011 -- [Check =>] EXPRESSION);
23012
23013 when Pragma_Type_Invariant
23014 | Pragma_Type_Invariant_Class
23015 =>
23016 Type_Invariant : declare
23017 I_Pragma : Node_Id;
23018
23019 begin
23020 Check_Arg_Count (2);
23021
23022 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
23023 -- setting Class_Present for the Type_Invariant_Class case.
23024
23025 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
23026 I_Pragma := New_Copy (N);
23027 Set_Pragma_Identifier
23028 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
23029 Rewrite (N, I_Pragma);
23030 Set_Analyzed (N, False);
23031 Analyze (N);
23032 end Type_Invariant;
23033
23034 ---------------------
23035 -- Unchecked_Union --
23036 ---------------------
23037
23038 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
23039
23040 when Pragma_Unchecked_Union => Unchecked_Union : declare
23041 Assoc : constant Node_Id := Arg1;
23042 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
23043 Clist : Node_Id;
23044 Comp : Node_Id;
23045 Tdef : Node_Id;
23046 Typ : Entity_Id;
23047 Variant : Node_Id;
23048 Vpart : Node_Id;
23049
23050 begin
23051 Ada_2005_Pragma;
23052 Check_No_Identifiers;
23053 Check_Arg_Count (1);
23054 Check_Arg_Is_Local_Name (Arg1);
23055
23056 Find_Type (Type_Id);
23057
23058 Typ := Entity (Type_Id);
23059
23060 -- A pragma that applies to a Ghost entity becomes Ghost for the
23061 -- purposes of legality checks and removal of ignored Ghost code.
23062
23063 Mark_Ghost_Pragma (N, Typ);
23064
23065 if Typ = Any_Type
23066 or else Rep_Item_Too_Early (Typ, N)
23067 then
23068 return;
23069 else
23070 Typ := Underlying_Type (Typ);
23071 end if;
23072
23073 if Rep_Item_Too_Late (Typ, N) then
23074 return;
23075 end if;
23076
23077 Check_First_Subtype (Arg1);
23078
23079 -- Note remaining cases are references to a type in the current
23080 -- declarative part. If we find an error, we post the error on
23081 -- the relevant type declaration at an appropriate point.
23082
23083 if not Is_Record_Type (Typ) then
23084 Error_Msg_N ("unchecked union must be record type", Typ);
23085 return;
23086
23087 elsif Is_Tagged_Type (Typ) then
23088 Error_Msg_N ("unchecked union must not be tagged", Typ);
23089 return;
23090
23091 elsif not Has_Discriminants (Typ) then
23092 Error_Msg_N
23093 ("unchecked union must have one discriminant", Typ);
23094 return;
23095
23096 -- Note: in previous versions of GNAT we used to check for limited
23097 -- types and give an error, but in fact the standard does allow
23098 -- Unchecked_Union on limited types, so this check was removed.
23099
23100 -- Similarly, GNAT used to require that all discriminants have
23101 -- default values, but this is not mandated by the RM.
23102
23103 -- Proceed with basic error checks completed
23104
23105 else
23106 Tdef := Type_Definition (Declaration_Node (Typ));
23107 Clist := Component_List (Tdef);
23108
23109 -- Check presence of component list and variant part
23110
23111 if No (Clist) or else No (Variant_Part (Clist)) then
23112 Error_Msg_N
23113 ("unchecked union must have variant part", Tdef);
23114 return;
23115 end if;
23116
23117 -- Check components
23118
23119 Comp := First (Component_Items (Clist));
23120 while Present (Comp) loop
23121 Check_Component (Comp, Typ);
23122 Next (Comp);
23123 end loop;
23124
23125 -- Check variant part
23126
23127 Vpart := Variant_Part (Clist);
23128
23129 Variant := First (Variants (Vpart));
23130 while Present (Variant) loop
23131 Check_Variant (Variant, Typ);
23132 Next (Variant);
23133 end loop;
23134 end if;
23135
23136 Set_Is_Unchecked_Union (Typ);
23137 Set_Convention (Typ, Convention_C);
23138 Set_Has_Unchecked_Union (Base_Type (Typ));
23139 Set_Is_Unchecked_Union (Base_Type (Typ));
23140 end Unchecked_Union;
23141
23142 ----------------------------
23143 -- Unevaluated_Use_Of_Old --
23144 ----------------------------
23145
23146 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
23147
23148 when Pragma_Unevaluated_Use_Of_Old =>
23149 GNAT_Pragma;
23150 Check_Arg_Count (1);
23151 Check_No_Identifiers;
23152 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
23153
23154 -- Suppress/Unsuppress can appear as a configuration pragma, or in
23155 -- a declarative part or a package spec.
23156
23157 if not Is_Configuration_Pragma then
23158 Check_Is_In_Decl_Part_Or_Package_Spec;
23159 end if;
23160
23161 -- Store proper setting of Uneval_Old
23162
23163 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
23164 Uneval_Old := Fold_Upper (Name_Buffer (1));
23165
23166 ------------------------
23167 -- Unimplemented_Unit --
23168 ------------------------
23169
23170 -- pragma Unimplemented_Unit;
23171
23172 -- Note: this only gives an error if we are generating code, or if
23173 -- we are in a generic library unit (where the pragma appears in the
23174 -- body, not in the spec).
23175
23176 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
23177 Cunitent : constant Entity_Id :=
23178 Cunit_Entity (Get_Source_Unit (Loc));
23179 Ent_Kind : constant Entity_Kind := Ekind (Cunitent);
23180
23181 begin
23182 GNAT_Pragma;
23183 Check_Arg_Count (0);
23184
23185 if Operating_Mode = Generate_Code
23186 or else Ent_Kind = E_Generic_Function
23187 or else Ent_Kind = E_Generic_Procedure
23188 or else Ent_Kind = E_Generic_Package
23189 then
23190 Get_Name_String (Chars (Cunitent));
23191 Set_Casing (Mixed_Case);
23192 Write_Str (Name_Buffer (1 .. Name_Len));
23193 Write_Str (" is not supported in this configuration");
23194 Write_Eol;
23195 raise Unrecoverable_Error;
23196 end if;
23197 end Unimplemented_Unit;
23198
23199 ------------------------
23200 -- Universal_Aliasing --
23201 ------------------------
23202
23203 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
23204
23205 when Pragma_Universal_Aliasing => Universal_Alias : declare
23206 E : Entity_Id;
23207 E_Id : Node_Id;
23208
23209 begin
23210 GNAT_Pragma;
23211 Check_Arg_Count (1);
23212 Check_Optional_Identifier (Arg2, Name_Entity);
23213 Check_Arg_Is_Local_Name (Arg1);
23214 E_Id := Get_Pragma_Arg (Arg1);
23215
23216 if Etype (E_Id) = Any_Type then
23217 return;
23218 end if;
23219
23220 E := Entity (E_Id);
23221
23222 if not Is_Type (E) then
23223 Error_Pragma_Arg ("pragma% requires type", Arg1);
23224 end if;
23225
23226 -- A pragma that applies to a Ghost entity becomes Ghost for the
23227 -- purposes of legality checks and removal of ignored Ghost code.
23228
23229 Mark_Ghost_Pragma (N, E);
23230 Set_Universal_Aliasing (Base_Type (E));
23231 Record_Rep_Item (E, N);
23232 end Universal_Alias;
23233
23234 --------------------
23235 -- Universal_Data --
23236 --------------------
23237
23238 -- pragma Universal_Data [(library_unit_NAME)];
23239
23240 when Pragma_Universal_Data =>
23241 GNAT_Pragma;
23242 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
23243
23244 ----------------
23245 -- Unmodified --
23246 ----------------
23247
23248 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
23249
23250 when Pragma_Unmodified =>
23251 Analyze_Unmodified_Or_Unused;
23252
23253 ------------------
23254 -- Unreferenced --
23255 ------------------
23256
23257 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
23258
23259 -- or when used in a context clause:
23260
23261 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
23262
23263 when Pragma_Unreferenced =>
23264 Analyze_Unreferenced_Or_Unused;
23265
23266 --------------------------
23267 -- Unreferenced_Objects --
23268 --------------------------
23269
23270 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
23271
23272 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
23273 Arg : Node_Id;
23274 Arg_Expr : Node_Id;
23275 Arg_Id : Entity_Id;
23276
23277 Ghost_Error_Posted : Boolean := False;
23278 -- Flag set when an error concerning the illegal mix of Ghost and
23279 -- non-Ghost types is emitted.
23280
23281 Ghost_Id : Entity_Id := Empty;
23282 -- The entity of the first Ghost type encountered while processing
23283 -- the arguments of the pragma.
23284
23285 begin
23286 GNAT_Pragma;
23287 Check_At_Least_N_Arguments (1);
23288
23289 Arg := Arg1;
23290 while Present (Arg) loop
23291 Check_No_Identifier (Arg);
23292 Check_Arg_Is_Local_Name (Arg);
23293 Arg_Expr := Get_Pragma_Arg (Arg);
23294
23295 if Is_Entity_Name (Arg_Expr) then
23296 Arg_Id := Entity (Arg_Expr);
23297
23298 if Is_Type (Arg_Id) then
23299 Set_Has_Pragma_Unreferenced_Objects (Arg_Id);
23300
23301 -- A pragma that applies to a Ghost entity becomes Ghost
23302 -- for the purposes of legality checks and removal of
23303 -- ignored Ghost code.
23304
23305 Mark_Ghost_Pragma (N, Arg_Id);
23306
23307 -- Capture the entity of the first Ghost type being
23308 -- processed for error detection purposes.
23309
23310 if Is_Ghost_Entity (Arg_Id) then
23311 if No (Ghost_Id) then
23312 Ghost_Id := Arg_Id;
23313 end if;
23314
23315 -- Otherwise the type is non-Ghost. It is illegal to mix
23316 -- references to Ghost and non-Ghost entities
23317 -- (SPARK RM 6.9).
23318
23319 elsif Present (Ghost_Id)
23320 and then not Ghost_Error_Posted
23321 then
23322 Ghost_Error_Posted := True;
23323
23324 Error_Msg_Name_1 := Pname;
23325 Error_Msg_N
23326 ("pragma % cannot mention ghost and non-ghost types",
23327 N);
23328
23329 Error_Msg_Sloc := Sloc (Ghost_Id);
23330 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
23331
23332 Error_Msg_Sloc := Sloc (Arg_Id);
23333 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
23334 end if;
23335 else
23336 Error_Pragma_Arg
23337 ("argument for pragma% must be type or subtype", Arg);
23338 end if;
23339 else
23340 Error_Pragma_Arg
23341 ("argument for pragma% must be type or subtype", Arg);
23342 end if;
23343
23344 Next (Arg);
23345 end loop;
23346 end Unreferenced_Objects;
23347
23348 ------------------------------
23349 -- Unreserve_All_Interrupts --
23350 ------------------------------
23351
23352 -- pragma Unreserve_All_Interrupts;
23353
23354 when Pragma_Unreserve_All_Interrupts =>
23355 GNAT_Pragma;
23356 Check_Arg_Count (0);
23357
23358 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
23359 Unreserve_All_Interrupts := True;
23360 end if;
23361
23362 ----------------
23363 -- Unsuppress --
23364 ----------------
23365
23366 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
23367
23368 when Pragma_Unsuppress =>
23369 Ada_2005_Pragma;
23370 Process_Suppress_Unsuppress (Suppress_Case => False);
23371
23372 ------------
23373 -- Unused --
23374 ------------
23375
23376 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
23377
23378 when Pragma_Unused =>
23379 Analyze_Unmodified_Or_Unused (Is_Unused => True);
23380 Analyze_Unreferenced_Or_Unused (Is_Unused => True);
23381
23382 -------------------
23383 -- Use_VADS_Size --
23384 -------------------
23385
23386 -- pragma Use_VADS_Size;
23387
23388 when Pragma_Use_VADS_Size =>
23389 GNAT_Pragma;
23390 Check_Arg_Count (0);
23391 Check_Valid_Configuration_Pragma;
23392 Use_VADS_Size := True;
23393
23394 ---------------------
23395 -- Validity_Checks --
23396 ---------------------
23397
23398 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
23399
23400 when Pragma_Validity_Checks => Validity_Checks : declare
23401 A : constant Node_Id := Get_Pragma_Arg (Arg1);
23402 S : String_Id;
23403 C : Char_Code;
23404
23405 begin
23406 GNAT_Pragma;
23407 Check_Arg_Count (1);
23408 Check_No_Identifiers;
23409
23410 -- Pragma always active unless in CodePeer or GNATprove modes,
23411 -- which use a fixed configuration of validity checks.
23412
23413 if not (CodePeer_Mode or GNATprove_Mode) then
23414 if Nkind (A) = N_String_Literal then
23415 S := Strval (A);
23416
23417 declare
23418 Slen : constant Natural := Natural (String_Length (S));
23419 Options : String (1 .. Slen);
23420 J : Positive;
23421
23422 begin
23423 -- Couldn't we use a for loop here over Options'Range???
23424
23425 J := 1;
23426 loop
23427 C := Get_String_Char (S, Pos (J));
23428
23429 -- This is a weird test, it skips setting validity
23430 -- checks entirely if any element of S is out of
23431 -- range of Character, what is that about ???
23432
23433 exit when not In_Character_Range (C);
23434 Options (J) := Get_Character (C);
23435
23436 if J = Slen then
23437 Set_Validity_Check_Options (Options);
23438 exit;
23439 else
23440 J := J + 1;
23441 end if;
23442 end loop;
23443 end;
23444
23445 elsif Nkind (A) = N_Identifier then
23446 if Chars (A) = Name_All_Checks then
23447 Set_Validity_Check_Options ("a");
23448 elsif Chars (A) = Name_On then
23449 Validity_Checks_On := True;
23450 elsif Chars (A) = Name_Off then
23451 Validity_Checks_On := False;
23452 end if;
23453 end if;
23454 end if;
23455 end Validity_Checks;
23456
23457 --------------
23458 -- Volatile --
23459 --------------
23460
23461 -- pragma Volatile (LOCAL_NAME);
23462
23463 when Pragma_Volatile =>
23464 Process_Atomic_Independent_Shared_Volatile;
23465
23466 -------------------------
23467 -- Volatile_Components --
23468 -------------------------
23469
23470 -- pragma Volatile_Components (array_LOCAL_NAME);
23471
23472 -- Volatile is handled by the same circuit as Atomic_Components
23473
23474 --------------------------
23475 -- Volatile_Full_Access --
23476 --------------------------
23477
23478 -- pragma Volatile_Full_Access (LOCAL_NAME);
23479
23480 when Pragma_Volatile_Full_Access =>
23481 GNAT_Pragma;
23482 Process_Atomic_Independent_Shared_Volatile;
23483
23484 -----------------------
23485 -- Volatile_Function --
23486 -----------------------
23487
23488 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
23489
23490 when Pragma_Volatile_Function => Volatile_Function : declare
23491 Over_Id : Entity_Id;
23492 Spec_Id : Entity_Id;
23493 Subp_Decl : Node_Id;
23494
23495 begin
23496 GNAT_Pragma;
23497 Check_No_Identifiers;
23498 Check_At_Most_N_Arguments (1);
23499
23500 Subp_Decl :=
23501 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
23502
23503 -- Generic subprogram
23504
23505 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
23506 null;
23507
23508 -- Body acts as spec
23509
23510 elsif Nkind (Subp_Decl) = N_Subprogram_Body
23511 and then No (Corresponding_Spec (Subp_Decl))
23512 then
23513 null;
23514
23515 -- Body stub acts as spec
23516
23517 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
23518 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
23519 then
23520 null;
23521
23522 -- Subprogram
23523
23524 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
23525 null;
23526
23527 else
23528 Pragma_Misplaced;
23529 return;
23530 end if;
23531
23532 Spec_Id := Unique_Defining_Entity (Subp_Decl);
23533
23534 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
23535 Pragma_Misplaced;
23536 return;
23537 end if;
23538
23539 -- A pragma that applies to a Ghost entity becomes Ghost for the
23540 -- purposes of legality checks and removal of ignored Ghost code.
23541
23542 Mark_Ghost_Pragma (N, Spec_Id);
23543
23544 -- Chain the pragma on the contract for completeness
23545
23546 Add_Contract_Item (N, Spec_Id);
23547
23548 -- The legality checks of pragma Volatile_Function are affected by
23549 -- the SPARK mode in effect. Analyze all pragmas in a specific
23550 -- order.
23551
23552 Analyze_If_Present (Pragma_SPARK_Mode);
23553
23554 -- A volatile function cannot override a non-volatile function
23555 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
23556 -- in New_Overloaded_Entity, however at that point the pragma has
23557 -- not been processed yet.
23558
23559 Over_Id := Overridden_Operation (Spec_Id);
23560
23561 if Present (Over_Id)
23562 and then not Is_Volatile_Function (Over_Id)
23563 then
23564 Error_Msg_N
23565 ("incompatible volatile function values in effect", Spec_Id);
23566
23567 Error_Msg_Sloc := Sloc (Over_Id);
23568 Error_Msg_N
23569 ("\& declared # with Volatile_Function value False",
23570 Spec_Id);
23571
23572 Error_Msg_Sloc := Sloc (Spec_Id);
23573 Error_Msg_N
23574 ("\overridden # with Volatile_Function value True",
23575 Spec_Id);
23576 end if;
23577
23578 -- Analyze the Boolean expression (if any)
23579
23580 if Present (Arg1) then
23581 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
23582 end if;
23583 end Volatile_Function;
23584
23585 ----------------------
23586 -- Warning_As_Error --
23587 ----------------------
23588
23589 -- pragma Warning_As_Error (static_string_EXPRESSION);
23590
23591 when Pragma_Warning_As_Error =>
23592 GNAT_Pragma;
23593 Check_Arg_Count (1);
23594 Check_No_Identifiers;
23595 Check_Valid_Configuration_Pragma;
23596
23597 if not Is_Static_String_Expression (Arg1) then
23598 Error_Pragma_Arg
23599 ("argument of pragma% must be static string expression",
23600 Arg1);
23601
23602 -- OK static string expression
23603
23604 else
23605 Acquire_Warning_Match_String (Arg1);
23606 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
23607 Warnings_As_Errors (Warnings_As_Errors_Count) :=
23608 new String'(Name_Buffer (1 .. Name_Len));
23609 end if;
23610
23611 --------------
23612 -- Warnings --
23613 --------------
23614
23615 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
23616
23617 -- DETAILS ::= On | Off
23618 -- DETAILS ::= On | Off, local_NAME
23619 -- DETAILS ::= static_string_EXPRESSION
23620 -- DETAILS ::= On | Off, static_string_EXPRESSION
23621
23622 -- TOOL_NAME ::= GNAT | GNATProve
23623
23624 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
23625
23626 -- Note: If the first argument matches an allowed tool name, it is
23627 -- always considered to be a tool name, even if there is a string
23628 -- variable of that name.
23629
23630 -- Note if the second argument of DETAILS is a local_NAME then the
23631 -- second form is always understood. If the intention is to use
23632 -- the fourth form, then you can write NAME & "" to force the
23633 -- intepretation as a static_string_EXPRESSION.
23634
23635 when Pragma_Warnings => Warnings : declare
23636 Reason : String_Id;
23637
23638 begin
23639 GNAT_Pragma;
23640 Check_At_Least_N_Arguments (1);
23641
23642 -- See if last argument is labeled Reason. If so, make sure we
23643 -- have a string literal or a concatenation of string literals,
23644 -- and acquire the REASON string. Then remove the REASON argument
23645 -- by decreasing Num_Args by one; Remaining processing looks only
23646 -- at first Num_Args arguments).
23647
23648 declare
23649 Last_Arg : constant Node_Id :=
23650 Last (Pragma_Argument_Associations (N));
23651
23652 begin
23653 if Nkind (Last_Arg) = N_Pragma_Argument_Association
23654 and then Chars (Last_Arg) = Name_Reason
23655 then
23656 Start_String;
23657 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
23658 Reason := End_String;
23659 Arg_Count := Arg_Count - 1;
23660
23661 -- Not allowed in compiler units (bootstrap issues)
23662
23663 Check_Compiler_Unit ("Reason for pragma Warnings", N);
23664
23665 -- No REASON string, set null string as reason
23666
23667 else
23668 Reason := Null_String_Id;
23669 end if;
23670 end;
23671
23672 -- Now proceed with REASON taken care of and eliminated
23673
23674 Check_No_Identifiers;
23675
23676 -- If debug flag -gnatd.i is set, pragma is ignored
23677
23678 if Debug_Flag_Dot_I then
23679 return;
23680 end if;
23681
23682 -- Process various forms of the pragma
23683
23684 declare
23685 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
23686 Shifted_Args : List_Id;
23687
23688 begin
23689 -- See if first argument is a tool name, currently either
23690 -- GNAT or GNATprove. If so, either ignore the pragma if the
23691 -- tool used does not match, or continue as if no tool name
23692 -- was given otherwise, by shifting the arguments.
23693
23694 if Nkind (Argx) = N_Identifier
23695 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
23696 then
23697 if Chars (Argx) = Name_Gnat then
23698 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
23699 Rewrite (N, Make_Null_Statement (Loc));
23700 Analyze (N);
23701 raise Pragma_Exit;
23702 end if;
23703
23704 elsif Chars (Argx) = Name_Gnatprove then
23705 if not GNATprove_Mode then
23706 Rewrite (N, Make_Null_Statement (Loc));
23707 Analyze (N);
23708 raise Pragma_Exit;
23709 end if;
23710
23711 else
23712 raise Program_Error;
23713 end if;
23714
23715 -- At this point, the pragma Warnings applies to the tool,
23716 -- so continue with shifted arguments.
23717
23718 Arg_Count := Arg_Count - 1;
23719
23720 if Arg_Count = 1 then
23721 Shifted_Args := New_List (New_Copy (Arg2));
23722 elsif Arg_Count = 2 then
23723 Shifted_Args := New_List (New_Copy (Arg2),
23724 New_Copy (Arg3));
23725 elsif Arg_Count = 3 then
23726 Shifted_Args := New_List (New_Copy (Arg2),
23727 New_Copy (Arg3),
23728 New_Copy (Arg4));
23729 else
23730 raise Program_Error;
23731 end if;
23732
23733 Rewrite (N,
23734 Make_Pragma (Loc,
23735 Chars => Name_Warnings,
23736 Pragma_Argument_Associations => Shifted_Args));
23737 Analyze (N);
23738 raise Pragma_Exit;
23739 end if;
23740
23741 -- One argument case
23742
23743 if Arg_Count = 1 then
23744
23745 -- On/Off one argument case was processed by parser
23746
23747 if Nkind (Argx) = N_Identifier
23748 and then Nam_In (Chars (Argx), Name_On, Name_Off)
23749 then
23750 null;
23751
23752 -- One argument case must be ON/OFF or static string expr
23753
23754 elsif not Is_Static_String_Expression (Arg1) then
23755 Error_Pragma_Arg
23756 ("argument of pragma% must be On/Off or static string "
23757 & "expression", Arg1);
23758
23759 -- One argument string expression case
23760
23761 else
23762 declare
23763 Lit : constant Node_Id := Expr_Value_S (Argx);
23764 Str : constant String_Id := Strval (Lit);
23765 Len : constant Nat := String_Length (Str);
23766 C : Char_Code;
23767 J : Nat;
23768 OK : Boolean;
23769 Chr : Character;
23770
23771 begin
23772 J := 1;
23773 while J <= Len loop
23774 C := Get_String_Char (Str, J);
23775 OK := In_Character_Range (C);
23776
23777 if OK then
23778 Chr := Get_Character (C);
23779
23780 -- Dash case: only -Wxxx is accepted
23781
23782 if J = 1
23783 and then J < Len
23784 and then Chr = '-'
23785 then
23786 J := J + 1;
23787 C := Get_String_Char (Str, J);
23788 Chr := Get_Character (C);
23789 exit when Chr = 'W';
23790 OK := False;
23791
23792 -- Dot case
23793
23794 elsif J < Len and then Chr = '.' then
23795 J := J + 1;
23796 C := Get_String_Char (Str, J);
23797 Chr := Get_Character (C);
23798
23799 if not Set_Dot_Warning_Switch (Chr) then
23800 Error_Pragma_Arg
23801 ("invalid warning switch character "
23802 & '.' & Chr, Arg1);
23803 end if;
23804
23805 -- Non-Dot case
23806
23807 else
23808 OK := Set_Warning_Switch (Chr);
23809 end if;
23810 end if;
23811
23812 if not OK then
23813 Error_Pragma_Arg
23814 ("invalid warning switch character " & Chr,
23815 Arg1);
23816 end if;
23817
23818 J := J + 1;
23819 end loop;
23820 end;
23821 end if;
23822
23823 -- Two or more arguments (must be two)
23824
23825 else
23826 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23827 Check_Arg_Count (2);
23828
23829 declare
23830 E_Id : Node_Id;
23831 E : Entity_Id;
23832 Err : Boolean;
23833
23834 begin
23835 E_Id := Get_Pragma_Arg (Arg2);
23836 Analyze (E_Id);
23837
23838 -- In the expansion of an inlined body, a reference to
23839 -- the formal may be wrapped in a conversion if the
23840 -- actual is a conversion. Retrieve the real entity name.
23841
23842 if (In_Instance_Body or In_Inlined_Body)
23843 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
23844 then
23845 E_Id := Expression (E_Id);
23846 end if;
23847
23848 -- Entity name case
23849
23850 if Is_Entity_Name (E_Id) then
23851 E := Entity (E_Id);
23852
23853 if E = Any_Id then
23854 return;
23855 else
23856 loop
23857 Set_Warnings_Off
23858 (E, (Chars (Get_Pragma_Arg (Arg1)) =
23859 Name_Off));
23860
23861 -- For OFF case, make entry in warnings off
23862 -- pragma table for later processing. But we do
23863 -- not do that within an instance, since these
23864 -- warnings are about what is needed in the
23865 -- template, not an instance of it.
23866
23867 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
23868 and then Warn_On_Warnings_Off
23869 and then not In_Instance
23870 then
23871 Warnings_Off_Pragmas.Append ((N, E, Reason));
23872 end if;
23873
23874 if Is_Enumeration_Type (E) then
23875 declare
23876 Lit : Entity_Id;
23877 begin
23878 Lit := First_Literal (E);
23879 while Present (Lit) loop
23880 Set_Warnings_Off (Lit);
23881 Next_Literal (Lit);
23882 end loop;
23883 end;
23884 end if;
23885
23886 exit when No (Homonym (E));
23887 E := Homonym (E);
23888 end loop;
23889 end if;
23890
23891 -- Error if not entity or static string expression case
23892
23893 elsif not Is_Static_String_Expression (Arg2) then
23894 Error_Pragma_Arg
23895 ("second argument of pragma% must be entity name "
23896 & "or static string expression", Arg2);
23897
23898 -- Static string expression case
23899
23900 else
23901 Acquire_Warning_Match_String (Arg2);
23902
23903 -- Note on configuration pragma case: If this is a
23904 -- configuration pragma, then for an OFF pragma, we
23905 -- just set Config True in the call, which is all
23906 -- that needs to be done. For the case of ON, this
23907 -- is normally an error, unless it is canceling the
23908 -- effect of a previous OFF pragma in the same file.
23909 -- In any other case, an error will be signalled (ON
23910 -- with no matching OFF).
23911
23912 -- Note: We set Used if we are inside a generic to
23913 -- disable the test that the non-config case actually
23914 -- cancels a warning. That's because we can't be sure
23915 -- there isn't an instantiation in some other unit
23916 -- where a warning is suppressed.
23917
23918 -- We could do a little better here by checking if the
23919 -- generic unit we are inside is public, but for now
23920 -- we don't bother with that refinement.
23921
23922 if Chars (Argx) = Name_Off then
23923 Set_Specific_Warning_Off
23924 (Loc, Name_Buffer (1 .. Name_Len), Reason,
23925 Config => Is_Configuration_Pragma,
23926 Used => Inside_A_Generic or else In_Instance);
23927
23928 elsif Chars (Argx) = Name_On then
23929 Set_Specific_Warning_On
23930 (Loc, Name_Buffer (1 .. Name_Len), Err);
23931
23932 if Err then
23933 Error_Msg
23934 ("??pragma Warnings On with no matching "
23935 & "Warnings Off", Loc);
23936 end if;
23937 end if;
23938 end if;
23939 end;
23940 end if;
23941 end;
23942 end Warnings;
23943
23944 -------------------
23945 -- Weak_External --
23946 -------------------
23947
23948 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
23949
23950 when Pragma_Weak_External => Weak_External : declare
23951 Ent : Entity_Id;
23952
23953 begin
23954 GNAT_Pragma;
23955 Check_Arg_Count (1);
23956 Check_Optional_Identifier (Arg1, Name_Entity);
23957 Check_Arg_Is_Library_Level_Local_Name (Arg1);
23958 Ent := Entity (Get_Pragma_Arg (Arg1));
23959
23960 if Rep_Item_Too_Early (Ent, N) then
23961 return;
23962 else
23963 Ent := Underlying_Type (Ent);
23964 end if;
23965
23966 -- The only processing required is to link this item on to the
23967 -- list of rep items for the given entity. This is accomplished
23968 -- by the call to Rep_Item_Too_Late (when no error is detected
23969 -- and False is returned).
23970
23971 if Rep_Item_Too_Late (Ent, N) then
23972 return;
23973 else
23974 Set_Has_Gigi_Rep_Item (Ent);
23975 end if;
23976 end Weak_External;
23977
23978 -----------------------------
23979 -- Wide_Character_Encoding --
23980 -----------------------------
23981
23982 -- pragma Wide_Character_Encoding (IDENTIFIER);
23983
23984 when Pragma_Wide_Character_Encoding =>
23985 GNAT_Pragma;
23986
23987 -- Nothing to do, handled in parser. Note that we do not enforce
23988 -- configuration pragma placement, this pragma can appear at any
23989 -- place in the source, allowing mixed encodings within a single
23990 -- source program.
23991
23992 null;
23993
23994 --------------------
23995 -- Unknown_Pragma --
23996 --------------------
23997
23998 -- Should be impossible, since the case of an unknown pragma is
23999 -- separately processed before the case statement is entered.
24000
24001 when Unknown_Pragma =>
24002 raise Program_Error;
24003 end case;
24004
24005 -- AI05-0144: detect dangerous order dependence. Disabled for now,
24006 -- until AI is formally approved.
24007
24008 -- Check_Order_Dependence;
24009
24010 exception
24011 when Pragma_Exit => null;
24012 end Analyze_Pragma;
24013
24014 ---------------------------------------------
24015 -- Analyze_Pre_Post_Condition_In_Decl_Part --
24016 ---------------------------------------------
24017
24018 -- WARNING: This routine manages Ghost regions. Return statements must be
24019 -- replaced by gotos which jump to the end of the routine and restore the
24020 -- Ghost mode.
24021
24022 procedure Analyze_Pre_Post_Condition_In_Decl_Part
24023 (N : Node_Id;
24024 Freeze_Id : Entity_Id := Empty)
24025 is
24026 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
24027 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
24028
24029 Disp_Typ : Entity_Id;
24030 -- The dispatching type of the subprogram subject to the pre- or
24031 -- postcondition.
24032
24033 function Check_References (Nod : Node_Id) return Traverse_Result;
24034 -- Check that expression Nod does not mention non-primitives of the
24035 -- type, global objects of the type, or other illegalities described
24036 -- and implied by AI12-0113.
24037
24038 ----------------------
24039 -- Check_References --
24040 ----------------------
24041
24042 function Check_References (Nod : Node_Id) return Traverse_Result is
24043 begin
24044 if Nkind (Nod) = N_Function_Call
24045 and then Is_Entity_Name (Name (Nod))
24046 then
24047 declare
24048 Func : constant Entity_Id := Entity (Name (Nod));
24049 Form : Entity_Id;
24050
24051 begin
24052 -- An operation of the type must be a primitive
24053
24054 if No (Find_Dispatching_Type (Func)) then
24055 Form := First_Formal (Func);
24056 while Present (Form) loop
24057 if Etype (Form) = Disp_Typ then
24058 Error_Msg_NE
24059 ("operation in class-wide condition must be "
24060 & "primitive of &", Nod, Disp_Typ);
24061 end if;
24062
24063 Next_Formal (Form);
24064 end loop;
24065
24066 -- A return object of the type is illegal as well
24067
24068 if Etype (Func) = Disp_Typ
24069 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
24070 then
24071 Error_Msg_NE
24072 ("operation in class-wide condition must be primitive "
24073 & "of &", Nod, Disp_Typ);
24074 end if;
24075
24076 -- Otherwise we have a call to an overridden primitive, and we
24077 -- will create a common class-wide clone for the body of
24078 -- original operation and its eventual inherited versions. If
24079 -- the original operation dispatches on result it is never
24080 -- inherited and there is no need for a clone. There is not
24081 -- need for a clone either in GNATprove mode, as cases that
24082 -- would require it are rejected (when an inherited primitive
24083 -- calls an overridden operation in a class-wide contract), and
24084 -- the clone would make proof impossible in some cases.
24085
24086 elsif not Is_Abstract_Subprogram (Spec_Id)
24087 and then No (Class_Wide_Clone (Spec_Id))
24088 and then not Has_Controlling_Result (Spec_Id)
24089 and then not GNATprove_Mode
24090 then
24091 Build_Class_Wide_Clone_Decl (Spec_Id);
24092 end if;
24093 end;
24094
24095 elsif Is_Entity_Name (Nod)
24096 and then
24097 (Etype (Nod) = Disp_Typ
24098 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
24099 and then Ekind_In (Entity (Nod), E_Constant, E_Variable)
24100 then
24101 Error_Msg_NE
24102 ("object in class-wide condition must be formal of type &",
24103 Nod, Disp_Typ);
24104
24105 elsif Nkind (Nod) = N_Explicit_Dereference
24106 and then (Etype (Nod) = Disp_Typ
24107 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
24108 and then (not Is_Entity_Name (Prefix (Nod))
24109 or else not Is_Formal (Entity (Prefix (Nod))))
24110 then
24111 Error_Msg_NE
24112 ("operation in class-wide condition must be primitive of &",
24113 Nod, Disp_Typ);
24114 end if;
24115
24116 return OK;
24117 end Check_References;
24118
24119 procedure Check_Class_Wide_Condition is
24120 new Traverse_Proc (Check_References);
24121
24122 -- Local variables
24123
24124 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
24125 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
24126 -- Save the Ghost mode to restore on exit
24127
24128 Errors : Nat;
24129 Restore_Scope : Boolean := False;
24130
24131 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
24132
24133 begin
24134 -- Do not analyze the pragma multiple times
24135
24136 if Is_Analyzed_Pragma (N) then
24137 return;
24138 end if;
24139
24140 -- Set the Ghost mode in effect from the pragma. Due to the delayed
24141 -- analysis of the pragma, the Ghost mode at point of declaration and
24142 -- point of analysis may not necessarily be the same. Use the mode in
24143 -- effect at the point of declaration.
24144
24145 Set_Ghost_Mode (N);
24146
24147 -- Ensure that the subprogram and its formals are visible when analyzing
24148 -- the expression of the pragma.
24149
24150 if not In_Open_Scopes (Spec_Id) then
24151 Restore_Scope := True;
24152 Push_Scope (Spec_Id);
24153
24154 if Is_Generic_Subprogram (Spec_Id) then
24155 Install_Generic_Formals (Spec_Id);
24156 else
24157 Install_Formals (Spec_Id);
24158 end if;
24159 end if;
24160
24161 Errors := Serious_Errors_Detected;
24162 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
24163
24164 -- Emit a clarification message when the expression contains at least
24165 -- one undefined reference, possibly due to contract "freezing".
24166
24167 if Errors /= Serious_Errors_Detected
24168 and then Present (Freeze_Id)
24169 and then Has_Undefined_Reference (Expr)
24170 then
24171 Contract_Freeze_Error (Spec_Id, Freeze_Id);
24172 end if;
24173
24174 if Class_Present (N) then
24175
24176 -- Verify that a class-wide condition is legal, i.e. the operation is
24177 -- a primitive of a tagged type. Note that a generic subprogram is
24178 -- not a primitive operation.
24179
24180 Disp_Typ := Find_Dispatching_Type (Spec_Id);
24181
24182 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
24183 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
24184
24185 if From_Aspect_Specification (N) then
24186 Error_Msg_N
24187 ("aspect % can only be specified for a primitive operation "
24188 & "of a tagged type", Corresponding_Aspect (N));
24189
24190 -- The pragma is a source construct
24191
24192 else
24193 Error_Msg_N
24194 ("pragma % can only be specified for a primitive operation "
24195 & "of a tagged type", N);
24196 end if;
24197
24198 -- Remaining semantic checks require a full tree traversal
24199
24200 else
24201 Check_Class_Wide_Condition (Expr);
24202 end if;
24203
24204 end if;
24205
24206 if Restore_Scope then
24207 End_Scope;
24208 end if;
24209
24210 -- If analysis of the condition indicates that a class-wide clone
24211 -- has been created, build and analyze its declaration.
24212
24213 if Is_Subprogram (Spec_Id)
24214 and then Present (Class_Wide_Clone (Spec_Id))
24215 then
24216 Analyze (Unit_Declaration_Node (Class_Wide_Clone (Spec_Id)));
24217 end if;
24218
24219 -- Currently it is not possible to inline pre/postconditions on a
24220 -- subprogram subject to pragma Inline_Always.
24221
24222 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
24223 Set_Is_Analyzed_Pragma (N);
24224
24225 Restore_Ghost_Mode (Saved_GM);
24226 end Analyze_Pre_Post_Condition_In_Decl_Part;
24227
24228 ------------------------------------------
24229 -- Analyze_Refined_Depends_In_Decl_Part --
24230 ------------------------------------------
24231
24232 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
24233 procedure Check_Dependency_Clause
24234 (Spec_Id : Entity_Id;
24235 Dep_Clause : Node_Id;
24236 Dep_States : Elist_Id;
24237 Refinements : List_Id;
24238 Matched_Items : in out Elist_Id);
24239 -- Try to match a single dependency clause Dep_Clause against one or
24240 -- more refinement clauses found in list Refinements. Each successful
24241 -- match eliminates at least one refinement clause from Refinements.
24242 -- Spec_Id denotes the entity of the related subprogram. Dep_States
24243 -- denotes the entities of all abstract states which appear in pragma
24244 -- Depends. Matched_Items contains the entities of all successfully
24245 -- matched items found in pragma Depends.
24246
24247 procedure Check_Output_States
24248 (Spec_Id : Entity_Id;
24249 Spec_Inputs : Elist_Id;
24250 Spec_Outputs : Elist_Id;
24251 Body_Inputs : Elist_Id;
24252 Body_Outputs : Elist_Id);
24253 -- Determine whether pragma Depends contains an output state with a
24254 -- visible refinement and if so, ensure that pragma Refined_Depends
24255 -- mentions all its constituents as outputs. Spec_Id is the entity of
24256 -- the related subprograms. Spec_Inputs and Spec_Outputs denote the
24257 -- inputs and outputs of the subprogram spec synthesized from pragma
24258 -- Depends. Body_Inputs and Body_Outputs denote the inputs and outputs
24259 -- of the subprogram body synthesized from pragma Refined_Depends.
24260
24261 function Collect_States (Clauses : List_Id) return Elist_Id;
24262 -- Given a normalized list of dependencies obtained from calling
24263 -- Normalize_Clauses, return a list containing the entities of all
24264 -- states appearing in dependencies. It helps in checking refinements
24265 -- involving a state and a corresponding constituent which is not a
24266 -- direct constituent of the state.
24267
24268 procedure Normalize_Clauses (Clauses : List_Id);
24269 -- Given a list of dependence or refinement clauses Clauses, normalize
24270 -- each clause by creating multiple dependencies with exactly one input
24271 -- and one output.
24272
24273 procedure Remove_Extra_Clauses
24274 (Clauses : List_Id;
24275 Matched_Items : Elist_Id);
24276 -- Given a list of refinement clauses Clauses, remove all clauses whose
24277 -- inputs and/or outputs have been previously matched. See the body for
24278 -- all special cases. Matched_Items contains the entities of all matched
24279 -- items found in pragma Depends.
24280
24281 procedure Report_Extra_Clauses
24282 (Spec_Id : Entity_Id;
24283 Clauses : List_Id);
24284 -- Emit an error for each extra clause found in list Clauses. Spec_Id
24285 -- denotes the entity of the related subprogram.
24286
24287 -----------------------------
24288 -- Check_Dependency_Clause --
24289 -----------------------------
24290
24291 procedure Check_Dependency_Clause
24292 (Spec_Id : Entity_Id;
24293 Dep_Clause : Node_Id;
24294 Dep_States : Elist_Id;
24295 Refinements : List_Id;
24296 Matched_Items : in out Elist_Id)
24297 is
24298 Dep_Input : constant Node_Id := Expression (Dep_Clause);
24299 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
24300
24301 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
24302 -- Determine whether dependency item Dep_Item has been matched in a
24303 -- previous clause.
24304
24305 function Is_In_Out_State_Clause return Boolean;
24306 -- Determine whether dependence clause Dep_Clause denotes an abstract
24307 -- state that depends on itself (State => State).
24308
24309 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
24310 -- Determine whether item Item denotes an abstract state with visible
24311 -- null refinement.
24312
24313 procedure Match_Items
24314 (Dep_Item : Node_Id;
24315 Ref_Item : Node_Id;
24316 Matched : out Boolean);
24317 -- Try to match dependence item Dep_Item against refinement item
24318 -- Ref_Item. To match against a possible null refinement (see 2, 9),
24319 -- set Ref_Item to Empty. Flag Matched is set to True when one of
24320 -- the following conformance scenarios is in effect:
24321 -- 1) Both items denote null
24322 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
24323 -- 3) Both items denote attribute 'Result
24324 -- 4) Both items denote the same object
24325 -- 5) Both items denote the same formal parameter
24326 -- 6) Both items denote the same current instance of a type
24327 -- 7) Both items denote the same discriminant
24328 -- 8) Dep_Item is an abstract state with visible null refinement
24329 -- and Ref_Item denotes null.
24330 -- 9) Dep_Item is an abstract state with visible null refinement
24331 -- and Ref_Item is Empty (special case).
24332 -- 10) Dep_Item is an abstract state with full or partial visible
24333 -- non-null refinement and Ref_Item denotes one of its
24334 -- constituents.
24335 -- 11) Dep_Item is an abstract state without a full visible
24336 -- refinement and Ref_Item denotes the same state.
24337 -- When scenario 10 is in effect, the entity of the abstract state
24338 -- denoted by Dep_Item is added to list Refined_States.
24339
24340 procedure Record_Item (Item_Id : Entity_Id);
24341 -- Store the entity of an item denoted by Item_Id in Matched_Items
24342
24343 ------------------------
24344 -- Is_Already_Matched --
24345 ------------------------
24346
24347 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean is
24348 Item_Id : Entity_Id := Empty;
24349
24350 begin
24351 -- When the dependency item denotes attribute 'Result, check for
24352 -- the entity of the related subprogram.
24353
24354 if Is_Attribute_Result (Dep_Item) then
24355 Item_Id := Spec_Id;
24356
24357 elsif Is_Entity_Name (Dep_Item) then
24358 Item_Id := Available_View (Entity_Of (Dep_Item));
24359 end if;
24360
24361 return
24362 Present (Item_Id) and then Contains (Matched_Items, Item_Id);
24363 end Is_Already_Matched;
24364
24365 ----------------------------
24366 -- Is_In_Out_State_Clause --
24367 ----------------------------
24368
24369 function Is_In_Out_State_Clause return Boolean is
24370 Dep_Input_Id : Entity_Id;
24371 Dep_Output_Id : Entity_Id;
24372
24373 begin
24374 -- Detect the following clause:
24375 -- State => State
24376
24377 if Is_Entity_Name (Dep_Input)
24378 and then Is_Entity_Name (Dep_Output)
24379 then
24380 -- Handle abstract views generated for limited with clauses
24381
24382 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
24383 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
24384
24385 return
24386 Ekind (Dep_Input_Id) = E_Abstract_State
24387 and then Dep_Input_Id = Dep_Output_Id;
24388 else
24389 return False;
24390 end if;
24391 end Is_In_Out_State_Clause;
24392
24393 ---------------------------
24394 -- Is_Null_Refined_State --
24395 ---------------------------
24396
24397 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
24398 Item_Id : Entity_Id;
24399
24400 begin
24401 if Is_Entity_Name (Item) then
24402
24403 -- Handle abstract views generated for limited with clauses
24404
24405 Item_Id := Available_View (Entity_Of (Item));
24406
24407 return
24408 Ekind (Item_Id) = E_Abstract_State
24409 and then Has_Null_Visible_Refinement (Item_Id);
24410 else
24411 return False;
24412 end if;
24413 end Is_Null_Refined_State;
24414
24415 -----------------
24416 -- Match_Items --
24417 -----------------
24418
24419 procedure Match_Items
24420 (Dep_Item : Node_Id;
24421 Ref_Item : Node_Id;
24422 Matched : out Boolean)
24423 is
24424 Dep_Item_Id : Entity_Id;
24425 Ref_Item_Id : Entity_Id;
24426
24427 begin
24428 -- Assume that the two items do not match
24429
24430 Matched := False;
24431
24432 -- A null matches null or Empty (special case)
24433
24434 if Nkind (Dep_Item) = N_Null
24435 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
24436 then
24437 Matched := True;
24438
24439 -- Attribute 'Result matches attribute 'Result
24440
24441 elsif Is_Attribute_Result (Dep_Item)
24442 and then Is_Attribute_Result (Ref_Item)
24443 then
24444 -- Put the entity of the related function on the list of
24445 -- matched items because attribute 'Result does not carry
24446 -- an entity similar to states and constituents.
24447
24448 Record_Item (Spec_Id);
24449 Matched := True;
24450
24451 -- Abstract states, current instances of concurrent types,
24452 -- discriminants, formal parameters and objects.
24453
24454 elsif Is_Entity_Name (Dep_Item) then
24455
24456 -- Handle abstract views generated for limited with clauses
24457
24458 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
24459
24460 if Ekind (Dep_Item_Id) = E_Abstract_State then
24461
24462 -- An abstract state with visible null refinement matches
24463 -- null or Empty (special case).
24464
24465 if Has_Null_Visible_Refinement (Dep_Item_Id)
24466 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
24467 then
24468 Record_Item (Dep_Item_Id);
24469 Matched := True;
24470
24471 -- An abstract state with visible non-null refinement
24472 -- matches one of its constituents, or itself for an
24473 -- abstract state with partial visible refinement.
24474
24475 elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then
24476 if Is_Entity_Name (Ref_Item) then
24477 Ref_Item_Id := Entity_Of (Ref_Item);
24478
24479 if Ekind_In (Ref_Item_Id, E_Abstract_State,
24480 E_Constant,
24481 E_Variable)
24482 and then Present (Encapsulating_State (Ref_Item_Id))
24483 and then Find_Encapsulating_State
24484 (Dep_States, Ref_Item_Id) = Dep_Item_Id
24485 then
24486 Record_Item (Dep_Item_Id);
24487 Matched := True;
24488
24489 elsif not Has_Visible_Refinement (Dep_Item_Id)
24490 and then Ref_Item_Id = Dep_Item_Id
24491 then
24492 Record_Item (Dep_Item_Id);
24493 Matched := True;
24494 end if;
24495 end if;
24496
24497 -- An abstract state without a visible refinement matches
24498 -- itself.
24499
24500 elsif Is_Entity_Name (Ref_Item)
24501 and then Entity_Of (Ref_Item) = Dep_Item_Id
24502 then
24503 Record_Item (Dep_Item_Id);
24504 Matched := True;
24505 end if;
24506
24507 -- A current instance of a concurrent type, discriminant,
24508 -- formal parameter or an object matches itself.
24509
24510 elsif Is_Entity_Name (Ref_Item)
24511 and then Entity_Of (Ref_Item) = Dep_Item_Id
24512 then
24513 Record_Item (Dep_Item_Id);
24514 Matched := True;
24515 end if;
24516 end if;
24517 end Match_Items;
24518
24519 -----------------
24520 -- Record_Item --
24521 -----------------
24522
24523 procedure Record_Item (Item_Id : Entity_Id) is
24524 begin
24525 if No (Matched_Items) then
24526 Matched_Items := New_Elmt_List;
24527 end if;
24528
24529 Append_Unique_Elmt (Item_Id, Matched_Items);
24530 end Record_Item;
24531
24532 -- Local variables
24533
24534 Clause_Matched : Boolean := False;
24535 Dummy : Boolean := False;
24536 Inputs_Match : Boolean;
24537 Next_Ref_Clause : Node_Id;
24538 Outputs_Match : Boolean;
24539 Ref_Clause : Node_Id;
24540 Ref_Input : Node_Id;
24541 Ref_Output : Node_Id;
24542
24543 -- Start of processing for Check_Dependency_Clause
24544
24545 begin
24546 -- Do not perform this check in an instance because it was already
24547 -- performed successfully in the generic template.
24548
24549 if Is_Generic_Instance (Spec_Id) then
24550 return;
24551 end if;
24552
24553 -- Examine all refinement clauses and compare them against the
24554 -- dependence clause.
24555
24556 Ref_Clause := First (Refinements);
24557 while Present (Ref_Clause) loop
24558 Next_Ref_Clause := Next (Ref_Clause);
24559
24560 -- Obtain the attributes of the current refinement clause
24561
24562 Ref_Input := Expression (Ref_Clause);
24563 Ref_Output := First (Choices (Ref_Clause));
24564
24565 -- The current refinement clause matches the dependence clause
24566 -- when both outputs match and both inputs match. See routine
24567 -- Match_Items for all possible conformance scenarios.
24568
24569 -- Depends Dep_Output => Dep_Input
24570 -- ^ ^
24571 -- match ? match ?
24572 -- v v
24573 -- Refined_Depends Ref_Output => Ref_Input
24574
24575 Match_Items
24576 (Dep_Item => Dep_Input,
24577 Ref_Item => Ref_Input,
24578 Matched => Inputs_Match);
24579
24580 Match_Items
24581 (Dep_Item => Dep_Output,
24582 Ref_Item => Ref_Output,
24583 Matched => Outputs_Match);
24584
24585 -- An In_Out state clause may be matched against a refinement with
24586 -- a null input or null output as long as the non-null side of the
24587 -- relation contains a valid constituent of the In_Out_State.
24588
24589 if Is_In_Out_State_Clause then
24590
24591 -- Depends => (State => State)
24592 -- Refined_Depends => (null => Constit) -- OK
24593
24594 if Inputs_Match
24595 and then not Outputs_Match
24596 and then Nkind (Ref_Output) = N_Null
24597 then
24598 Outputs_Match := True;
24599 end if;
24600
24601 -- Depends => (State => State)
24602 -- Refined_Depends => (Constit => null) -- OK
24603
24604 if not Inputs_Match
24605 and then Outputs_Match
24606 and then Nkind (Ref_Input) = N_Null
24607 then
24608 Inputs_Match := True;
24609 end if;
24610 end if;
24611
24612 -- The current refinement clause is legally constructed following
24613 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
24614 -- the pool of candidates. The seach continues because a single
24615 -- dependence clause may have multiple matching refinements.
24616
24617 if Inputs_Match and Outputs_Match then
24618 Clause_Matched := True;
24619 Remove (Ref_Clause);
24620 end if;
24621
24622 Ref_Clause := Next_Ref_Clause;
24623 end loop;
24624
24625 -- Depending on the order or composition of refinement clauses, an
24626 -- In_Out state clause may not be directly refinable.
24627
24628 -- Refined_State => (State => (Constit_1, Constit_2))
24629 -- Depends => ((Output, State) => (Input, State))
24630 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
24631
24632 -- Matching normalized clause (State => State) fails because there is
24633 -- no direct refinement capable of satisfying this relation. Another
24634 -- similar case arises when clauses (Constit_1 => Input) and (Output
24635 -- => Constit_2) are matched first, leaving no candidates for clause
24636 -- (State => State). Both scenarios are legal as long as one of the
24637 -- previous clauses mentioned a valid constituent of State.
24638
24639 if not Clause_Matched
24640 and then Is_In_Out_State_Clause
24641 and then Is_Already_Matched (Dep_Input)
24642 then
24643 Clause_Matched := True;
24644 end if;
24645
24646 -- A clause where the input is an abstract state with visible null
24647 -- refinement or a 'Result attribute is implicitly matched when the
24648 -- output has already been matched in a previous clause.
24649
24650 -- Refined_State => (State => null)
24651 -- Depends => (Output => State) -- implicitly OK
24652 -- Refined_Depends => (Output => ...)
24653 -- Depends => (...'Result => State) -- implicitly OK
24654 -- Refined_Depends => (...'Result => ...)
24655
24656 if not Clause_Matched
24657 and then Is_Null_Refined_State (Dep_Input)
24658 and then Is_Already_Matched (Dep_Output)
24659 then
24660 Clause_Matched := True;
24661 end if;
24662
24663 -- A clause where the output is an abstract state with visible null
24664 -- refinement is implicitly matched when the input has already been
24665 -- matched in a previous clause.
24666
24667 -- Refined_State => (State => null)
24668 -- Depends => (State => Input) -- implicitly OK
24669 -- Refined_Depends => (... => Input)
24670
24671 if not Clause_Matched
24672 and then Is_Null_Refined_State (Dep_Output)
24673 and then Is_Already_Matched (Dep_Input)
24674 then
24675 Clause_Matched := True;
24676 end if;
24677
24678 -- At this point either all refinement clauses have been examined or
24679 -- pragma Refined_Depends contains a solitary null. Only an abstract
24680 -- state with null refinement can possibly match these cases.
24681
24682 -- Refined_State => (State => null)
24683 -- Depends => (State => null)
24684 -- Refined_Depends => null -- OK
24685
24686 if not Clause_Matched then
24687 Match_Items
24688 (Dep_Item => Dep_Input,
24689 Ref_Item => Empty,
24690 Matched => Inputs_Match);
24691
24692 Match_Items
24693 (Dep_Item => Dep_Output,
24694 Ref_Item => Empty,
24695 Matched => Outputs_Match);
24696
24697 Clause_Matched := Inputs_Match and Outputs_Match;
24698 end if;
24699
24700 -- If the contents of Refined_Depends are legal, then the current
24701 -- dependence clause should be satisfied either by an explicit match
24702 -- or by one of the special cases.
24703
24704 if not Clause_Matched then
24705 SPARK_Msg_NE
24706 (Fix_Msg (Spec_Id, "dependence clause of subprogram & has no "
24707 & "matching refinement in body"), Dep_Clause, Spec_Id);
24708 end if;
24709 end Check_Dependency_Clause;
24710
24711 -------------------------
24712 -- Check_Output_States --
24713 -------------------------
24714
24715 procedure Check_Output_States
24716 (Spec_Id : Entity_Id;
24717 Spec_Inputs : Elist_Id;
24718 Spec_Outputs : Elist_Id;
24719 Body_Inputs : Elist_Id;
24720 Body_Outputs : Elist_Id)
24721 is
24722 procedure Check_Constituent_Usage (State_Id : Entity_Id);
24723 -- Determine whether all constituents of state State_Id with full
24724 -- visible refinement are used as outputs in pragma Refined_Depends.
24725 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
24726
24727 -----------------------------
24728 -- Check_Constituent_Usage --
24729 -----------------------------
24730
24731 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
24732 Constits : constant Elist_Id :=
24733 Partial_Refinement_Constituents (State_Id);
24734 Constit_Elmt : Elmt_Id;
24735 Constit_Id : Entity_Id;
24736 Only_Partial : constant Boolean :=
24737 not Has_Visible_Refinement (State_Id);
24738 Posted : Boolean := False;
24739
24740 begin
24741 if Present (Constits) then
24742 Constit_Elmt := First_Elmt (Constits);
24743 while Present (Constit_Elmt) loop
24744 Constit_Id := Node (Constit_Elmt);
24745
24746 -- Issue an error when a constituent of State_Id is used,
24747 -- and State_Id has only partial visible refinement
24748 -- (SPARK RM 7.2.4(3d)).
24749
24750 if Only_Partial then
24751 if (Present (Body_Inputs)
24752 and then Appears_In (Body_Inputs, Constit_Id))
24753 or else
24754 (Present (Body_Outputs)
24755 and then Appears_In (Body_Outputs, Constit_Id))
24756 then
24757 Error_Msg_Name_1 := Chars (State_Id);
24758 SPARK_Msg_NE
24759 ("constituent & of state % cannot be used in "
24760 & "dependence refinement", N, Constit_Id);
24761 Error_Msg_Name_1 := Chars (State_Id);
24762 SPARK_Msg_N ("\use state % instead", N);
24763 end if;
24764
24765 -- The constituent acts as an input (SPARK RM 7.2.5(3))
24766
24767 elsif Present (Body_Inputs)
24768 and then Appears_In (Body_Inputs, Constit_Id)
24769 then
24770 Error_Msg_Name_1 := Chars (State_Id);
24771 SPARK_Msg_NE
24772 ("constituent & of state % must act as output in "
24773 & "dependence refinement", N, Constit_Id);
24774
24775 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
24776
24777 elsif No (Body_Outputs)
24778 or else not Appears_In (Body_Outputs, Constit_Id)
24779 then
24780 if not Posted then
24781 Posted := True;
24782 SPARK_Msg_NE
24783 ("output state & must be replaced by all its "
24784 & "constituents in dependence refinement",
24785 N, State_Id);
24786 end if;
24787
24788 SPARK_Msg_NE
24789 ("\constituent & is missing in output list",
24790 N, Constit_Id);
24791 end if;
24792
24793 Next_Elmt (Constit_Elmt);
24794 end loop;
24795 end if;
24796 end Check_Constituent_Usage;
24797
24798 -- Local variables
24799
24800 Item : Node_Id;
24801 Item_Elmt : Elmt_Id;
24802 Item_Id : Entity_Id;
24803
24804 -- Start of processing for Check_Output_States
24805
24806 begin
24807 -- Do not perform this check in an instance because it was already
24808 -- performed successfully in the generic template.
24809
24810 if Is_Generic_Instance (Spec_Id) then
24811 null;
24812
24813 -- Inspect the outputs of pragma Depends looking for a state with a
24814 -- visible refinement.
24815
24816 elsif Present (Spec_Outputs) then
24817 Item_Elmt := First_Elmt (Spec_Outputs);
24818 while Present (Item_Elmt) loop
24819 Item := Node (Item_Elmt);
24820
24821 -- Deal with the mixed nature of the input and output lists
24822
24823 if Nkind (Item) = N_Defining_Identifier then
24824 Item_Id := Item;
24825 else
24826 Item_Id := Available_View (Entity_Of (Item));
24827 end if;
24828
24829 if Ekind (Item_Id) = E_Abstract_State then
24830
24831 -- The state acts as an input-output, skip it
24832
24833 if Present (Spec_Inputs)
24834 and then Appears_In (Spec_Inputs, Item_Id)
24835 then
24836 null;
24837
24838 -- Ensure that all of the constituents are utilized as
24839 -- outputs in pragma Refined_Depends.
24840
24841 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
24842 Check_Constituent_Usage (Item_Id);
24843 end if;
24844 end if;
24845
24846 Next_Elmt (Item_Elmt);
24847 end loop;
24848 end if;
24849 end Check_Output_States;
24850
24851 --------------------
24852 -- Collect_States --
24853 --------------------
24854
24855 function Collect_States (Clauses : List_Id) return Elist_Id is
24856 procedure Collect_State
24857 (Item : Node_Id;
24858 States : in out Elist_Id);
24859 -- Add the entity of Item to list States when it denotes to a state
24860
24861 -------------------
24862 -- Collect_State --
24863 -------------------
24864
24865 procedure Collect_State
24866 (Item : Node_Id;
24867 States : in out Elist_Id)
24868 is
24869 Id : Entity_Id;
24870
24871 begin
24872 if Is_Entity_Name (Item) then
24873 Id := Entity_Of (Item);
24874
24875 if Ekind (Id) = E_Abstract_State then
24876 if No (States) then
24877 States := New_Elmt_List;
24878 end if;
24879
24880 Append_Unique_Elmt (Id, States);
24881 end if;
24882 end if;
24883 end Collect_State;
24884
24885 -- Local variables
24886
24887 Clause : Node_Id;
24888 Input : Node_Id;
24889 Output : Node_Id;
24890 States : Elist_Id := No_Elist;
24891
24892 -- Start of processing for Collect_States
24893
24894 begin
24895 Clause := First (Clauses);
24896 while Present (Clause) loop
24897 Input := Expression (Clause);
24898 Output := First (Choices (Clause));
24899
24900 Collect_State (Input, States);
24901 Collect_State (Output, States);
24902
24903 Next (Clause);
24904 end loop;
24905
24906 return States;
24907 end Collect_States;
24908
24909 -----------------------
24910 -- Normalize_Clauses --
24911 -----------------------
24912
24913 procedure Normalize_Clauses (Clauses : List_Id) is
24914 procedure Normalize_Inputs (Clause : Node_Id);
24915 -- Normalize clause Clause by creating multiple clauses for each
24916 -- input item of Clause. It is assumed that Clause has exactly one
24917 -- output. The transformation is as follows:
24918 --
24919 -- Output => (Input_1, Input_2) -- original
24920 --
24921 -- Output => Input_1 -- normalizations
24922 -- Output => Input_2
24923
24924 procedure Normalize_Outputs (Clause : Node_Id);
24925 -- Normalize clause Clause by creating multiple clause for each
24926 -- output item of Clause. The transformation is as follows:
24927 --
24928 -- (Output_1, Output_2) => Input -- original
24929 --
24930 -- Output_1 => Input -- normalization
24931 -- Output_2 => Input
24932
24933 ----------------------
24934 -- Normalize_Inputs --
24935 ----------------------
24936
24937 procedure Normalize_Inputs (Clause : Node_Id) is
24938 Inputs : constant Node_Id := Expression (Clause);
24939 Loc : constant Source_Ptr := Sloc (Clause);
24940 Output : constant List_Id := Choices (Clause);
24941 Last_Input : Node_Id;
24942 Input : Node_Id;
24943 New_Clause : Node_Id;
24944 Next_Input : Node_Id;
24945
24946 begin
24947 -- Normalization is performed only when the original clause has
24948 -- more than one input. Multiple inputs appear as an aggregate.
24949
24950 if Nkind (Inputs) = N_Aggregate then
24951 Last_Input := Last (Expressions (Inputs));
24952
24953 -- Create a new clause for each input
24954
24955 Input := First (Expressions (Inputs));
24956 while Present (Input) loop
24957 Next_Input := Next (Input);
24958
24959 -- Unhook the current input from the original input list
24960 -- because it will be relocated to a new clause.
24961
24962 Remove (Input);
24963
24964 -- Special processing for the last input. At this point the
24965 -- original aggregate has been stripped down to one element.
24966 -- Replace the aggregate by the element itself.
24967
24968 if Input = Last_Input then
24969 Rewrite (Inputs, Input);
24970
24971 -- Generate a clause of the form:
24972 -- Output => Input
24973
24974 else
24975 New_Clause :=
24976 Make_Component_Association (Loc,
24977 Choices => New_Copy_List_Tree (Output),
24978 Expression => Input);
24979
24980 -- The new clause contains replicated content that has
24981 -- already been analyzed, mark the clause as analyzed.
24982
24983 Set_Analyzed (New_Clause);
24984 Insert_After (Clause, New_Clause);
24985 end if;
24986
24987 Input := Next_Input;
24988 end loop;
24989 end if;
24990 end Normalize_Inputs;
24991
24992 -----------------------
24993 -- Normalize_Outputs --
24994 -----------------------
24995
24996 procedure Normalize_Outputs (Clause : Node_Id) is
24997 Inputs : constant Node_Id := Expression (Clause);
24998 Loc : constant Source_Ptr := Sloc (Clause);
24999 Outputs : constant Node_Id := First (Choices (Clause));
25000 Last_Output : Node_Id;
25001 New_Clause : Node_Id;
25002 Next_Output : Node_Id;
25003 Output : Node_Id;
25004
25005 begin
25006 -- Multiple outputs appear as an aggregate. Nothing to do when
25007 -- the clause has exactly one output.
25008
25009 if Nkind (Outputs) = N_Aggregate then
25010 Last_Output := Last (Expressions (Outputs));
25011
25012 -- Create a clause for each output. Note that each time a new
25013 -- clause is created, the original output list slowly shrinks
25014 -- until there is one item left.
25015
25016 Output := First (Expressions (Outputs));
25017 while Present (Output) loop
25018 Next_Output := Next (Output);
25019
25020 -- Unhook the output from the original output list as it
25021 -- will be relocated to a new clause.
25022
25023 Remove (Output);
25024
25025 -- Special processing for the last output. At this point
25026 -- the original aggregate has been stripped down to one
25027 -- element. Replace the aggregate by the element itself.
25028
25029 if Output = Last_Output then
25030 Rewrite (Outputs, Output);
25031
25032 else
25033 -- Generate a clause of the form:
25034 -- (Output => Inputs)
25035
25036 New_Clause :=
25037 Make_Component_Association (Loc,
25038 Choices => New_List (Output),
25039 Expression => New_Copy_Tree (Inputs));
25040
25041 -- The new clause contains replicated content that has
25042 -- already been analyzed. There is not need to reanalyze
25043 -- them.
25044
25045 Set_Analyzed (New_Clause);
25046 Insert_After (Clause, New_Clause);
25047 end if;
25048
25049 Output := Next_Output;
25050 end loop;
25051 end if;
25052 end Normalize_Outputs;
25053
25054 -- Local variables
25055
25056 Clause : Node_Id;
25057
25058 -- Start of processing for Normalize_Clauses
25059
25060 begin
25061 Clause := First (Clauses);
25062 while Present (Clause) loop
25063 Normalize_Outputs (Clause);
25064 Next (Clause);
25065 end loop;
25066
25067 Clause := First (Clauses);
25068 while Present (Clause) loop
25069 Normalize_Inputs (Clause);
25070 Next (Clause);
25071 end loop;
25072 end Normalize_Clauses;
25073
25074 --------------------------
25075 -- Remove_Extra_Clauses --
25076 --------------------------
25077
25078 procedure Remove_Extra_Clauses
25079 (Clauses : List_Id;
25080 Matched_Items : Elist_Id)
25081 is
25082 Clause : Node_Id;
25083 Input : Node_Id;
25084 Input_Id : Entity_Id;
25085 Next_Clause : Node_Id;
25086 Output : Node_Id;
25087 State_Id : Entity_Id;
25088
25089 begin
25090 Clause := First (Clauses);
25091 while Present (Clause) loop
25092 Next_Clause := Next (Clause);
25093
25094 Input := Expression (Clause);
25095 Output := First (Choices (Clause));
25096
25097 -- Recognize a clause of the form
25098
25099 -- null => Input
25100
25101 -- where Input is a constituent of a state which was already
25102 -- successfully matched. This clause must be removed because it
25103 -- simply indicates that some of the constituents of the state
25104 -- are not used.
25105
25106 -- Refined_State => (State => (Constit_1, Constit_2))
25107 -- Depends => (Output => State)
25108 -- Refined_Depends => ((Output => Constit_1), -- State matched
25109 -- (null => Constit_2)) -- OK
25110
25111 if Nkind (Output) = N_Null and then Is_Entity_Name (Input) then
25112
25113 -- Handle abstract views generated for limited with clauses
25114
25115 Input_Id := Available_View (Entity_Of (Input));
25116
25117 -- The input must be a constituent of a state
25118
25119 if Ekind_In (Input_Id, E_Abstract_State,
25120 E_Constant,
25121 E_Variable)
25122 and then Present (Encapsulating_State (Input_Id))
25123 then
25124 State_Id := Encapsulating_State (Input_Id);
25125
25126 -- The state must have a non-null visible refinement and be
25127 -- matched in a previous clause.
25128
25129 if Has_Non_Null_Visible_Refinement (State_Id)
25130 and then Contains (Matched_Items, State_Id)
25131 then
25132 Remove (Clause);
25133 end if;
25134 end if;
25135
25136 -- Recognize a clause of the form
25137
25138 -- Output => null
25139
25140 -- where Output is an arbitrary item. This clause must be removed
25141 -- because a null input legitimately matches anything.
25142
25143 elsif Nkind (Input) = N_Null then
25144 Remove (Clause);
25145 end if;
25146
25147 Clause := Next_Clause;
25148 end loop;
25149 end Remove_Extra_Clauses;
25150
25151 --------------------------
25152 -- Report_Extra_Clauses --
25153 --------------------------
25154
25155 procedure Report_Extra_Clauses
25156 (Spec_Id : Entity_Id;
25157 Clauses : List_Id)
25158 is
25159 Clause : Node_Id;
25160
25161 begin
25162 -- Do not perform this check in an instance because it was already
25163 -- performed successfully in the generic template.
25164
25165 if Is_Generic_Instance (Spec_Id) then
25166 null;
25167
25168 elsif Present (Clauses) then
25169 Clause := First (Clauses);
25170 while Present (Clause) loop
25171 SPARK_Msg_N
25172 ("unmatched or extra clause in dependence refinement",
25173 Clause);
25174
25175 Next (Clause);
25176 end loop;
25177 end if;
25178 end Report_Extra_Clauses;
25179
25180 -- Local variables
25181
25182 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
25183 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
25184 Errors : constant Nat := Serious_Errors_Detected;
25185
25186 Clause : Node_Id;
25187 Deps : Node_Id;
25188 Dummy : Boolean;
25189 Refs : Node_Id;
25190
25191 Body_Inputs : Elist_Id := No_Elist;
25192 Body_Outputs : Elist_Id := No_Elist;
25193 -- The inputs and outputs of the subprogram body synthesized from pragma
25194 -- Refined_Depends.
25195
25196 Dependencies : List_Id := No_List;
25197 Depends : Node_Id;
25198 -- The corresponding Depends pragma along with its clauses
25199
25200 Matched_Items : Elist_Id := No_Elist;
25201 -- A list containing the entities of all successfully matched items
25202 -- found in pragma Depends.
25203
25204 Refinements : List_Id := No_List;
25205 -- The clauses of pragma Refined_Depends
25206
25207 Spec_Id : Entity_Id;
25208 -- The entity of the subprogram subject to pragma Refined_Depends
25209
25210 Spec_Inputs : Elist_Id := No_Elist;
25211 Spec_Outputs : Elist_Id := No_Elist;
25212 -- The inputs and outputs of the subprogram spec synthesized from pragma
25213 -- Depends.
25214
25215 States : Elist_Id := No_Elist;
25216 -- A list containing the entities of all states whose constituents
25217 -- appear in pragma Depends.
25218
25219 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
25220
25221 begin
25222 -- Do not analyze the pragma multiple times
25223
25224 if Is_Analyzed_Pragma (N) then
25225 return;
25226 end if;
25227
25228 Spec_Id := Unique_Defining_Entity (Body_Decl);
25229
25230 -- Use the anonymous object as the proper spec when Refined_Depends
25231 -- applies to the body of a single task type. The object carries the
25232 -- proper Chars as well as all non-refined versions of pragmas.
25233
25234 if Is_Single_Concurrent_Type (Spec_Id) then
25235 Spec_Id := Anonymous_Object (Spec_Id);
25236 end if;
25237
25238 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
25239
25240 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
25241 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
25242
25243 if No (Depends) then
25244 SPARK_Msg_NE
25245 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
25246 & "& lacks aspect or pragma Depends"), N, Spec_Id);
25247 goto Leave;
25248 end if;
25249
25250 Deps := Expression (Get_Argument (Depends, Spec_Id));
25251
25252 -- A null dependency relation renders the refinement useless because it
25253 -- cannot possibly mention abstract states with visible refinement. Note
25254 -- that the inverse is not true as states may be refined to null
25255 -- (SPARK RM 7.2.5(2)).
25256
25257 if Nkind (Deps) = N_Null then
25258 SPARK_Msg_NE
25259 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
25260 & "depend on abstract state with visible refinement"), N, Spec_Id);
25261 goto Leave;
25262 end if;
25263
25264 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
25265 -- This ensures that the categorization of all refined dependency items
25266 -- is consistent with their role.
25267
25268 Analyze_Depends_In_Decl_Part (N);
25269
25270 -- Do not match dependencies against refinements if Refined_Depends is
25271 -- illegal to avoid emitting misleading error.
25272
25273 if Serious_Errors_Detected = Errors then
25274
25275 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
25276 -- the inputs and outputs of the subprogram spec and body to verify
25277 -- the use of states with visible refinement and their constituents.
25278
25279 if No (Get_Pragma (Spec_Id, Pragma_Global))
25280 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
25281 then
25282 Collect_Subprogram_Inputs_Outputs
25283 (Subp_Id => Spec_Id,
25284 Synthesize => True,
25285 Subp_Inputs => Spec_Inputs,
25286 Subp_Outputs => Spec_Outputs,
25287 Global_Seen => Dummy);
25288
25289 Collect_Subprogram_Inputs_Outputs
25290 (Subp_Id => Body_Id,
25291 Synthesize => True,
25292 Subp_Inputs => Body_Inputs,
25293 Subp_Outputs => Body_Outputs,
25294 Global_Seen => Dummy);
25295
25296 -- For an output state with a visible refinement, ensure that all
25297 -- constituents appear as outputs in the dependency refinement.
25298
25299 Check_Output_States
25300 (Spec_Id => Spec_Id,
25301 Spec_Inputs => Spec_Inputs,
25302 Spec_Outputs => Spec_Outputs,
25303 Body_Inputs => Body_Inputs,
25304 Body_Outputs => Body_Outputs);
25305 end if;
25306
25307 -- Matching is disabled in ASIS because clauses are not normalized as
25308 -- this is a tree altering activity similar to expansion.
25309
25310 if ASIS_Mode then
25311 goto Leave;
25312 end if;
25313
25314 -- Multiple dependency clauses appear as component associations of an
25315 -- aggregate. Note that the clauses are copied because the algorithm
25316 -- modifies them and this should not be visible in Depends.
25317
25318 pragma Assert (Nkind (Deps) = N_Aggregate);
25319 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
25320 Normalize_Clauses (Dependencies);
25321
25322 -- Gather all states which appear in Depends
25323
25324 States := Collect_States (Dependencies);
25325
25326 Refs := Expression (Get_Argument (N, Spec_Id));
25327
25328 if Nkind (Refs) = N_Null then
25329 Refinements := No_List;
25330
25331 -- Multiple dependency clauses appear as component associations of an
25332 -- aggregate. Note that the clauses are copied because the algorithm
25333 -- modifies them and this should not be visible in Refined_Depends.
25334
25335 else pragma Assert (Nkind (Refs) = N_Aggregate);
25336 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
25337 Normalize_Clauses (Refinements);
25338 end if;
25339
25340 -- At this point the clauses of pragmas Depends and Refined_Depends
25341 -- have been normalized into simple dependencies between one output
25342 -- and one input. Examine all clauses of pragma Depends looking for
25343 -- matching clauses in pragma Refined_Depends.
25344
25345 Clause := First (Dependencies);
25346 while Present (Clause) loop
25347 Check_Dependency_Clause
25348 (Spec_Id => Spec_Id,
25349 Dep_Clause => Clause,
25350 Dep_States => States,
25351 Refinements => Refinements,
25352 Matched_Items => Matched_Items);
25353
25354 Next (Clause);
25355 end loop;
25356
25357 -- Pragma Refined_Depends may contain multiple clarification clauses
25358 -- which indicate that certain constituents do not influence the data
25359 -- flow in any way. Such clauses must be removed as long as the state
25360 -- has been matched, otherwise they will be incorrectly flagged as
25361 -- unmatched.
25362
25363 -- Refined_State => (State => (Constit_1, Constit_2))
25364 -- Depends => (Output => State)
25365 -- Refined_Depends => ((Output => Constit_1), -- State matched
25366 -- (null => Constit_2)) -- must be removed
25367
25368 Remove_Extra_Clauses (Refinements, Matched_Items);
25369
25370 if Serious_Errors_Detected = Errors then
25371 Report_Extra_Clauses (Spec_Id, Refinements);
25372 end if;
25373 end if;
25374
25375 <<Leave>>
25376 Set_Is_Analyzed_Pragma (N);
25377 end Analyze_Refined_Depends_In_Decl_Part;
25378
25379 -----------------------------------------
25380 -- Analyze_Refined_Global_In_Decl_Part --
25381 -----------------------------------------
25382
25383 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
25384 Global : Node_Id;
25385 -- The corresponding Global pragma
25386
25387 Has_In_State : Boolean := False;
25388 Has_In_Out_State : Boolean := False;
25389 Has_Out_State : Boolean := False;
25390 Has_Proof_In_State : Boolean := False;
25391 -- These flags are set when the corresponding Global pragma has a state
25392 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
25393 -- refinement.
25394
25395 Has_Null_State : Boolean := False;
25396 -- This flag is set when the corresponding Global pragma has at least
25397 -- one state with a null refinement.
25398
25399 In_Constits : Elist_Id := No_Elist;
25400 In_Out_Constits : Elist_Id := No_Elist;
25401 Out_Constits : Elist_Id := No_Elist;
25402 Proof_In_Constits : Elist_Id := No_Elist;
25403 -- These lists contain the entities of all Input, In_Out, Output and
25404 -- Proof_In constituents that appear in Refined_Global and participate
25405 -- in state refinement.
25406
25407 In_Items : Elist_Id := No_Elist;
25408 In_Out_Items : Elist_Id := No_Elist;
25409 Out_Items : Elist_Id := No_Elist;
25410 Proof_In_Items : Elist_Id := No_Elist;
25411 -- These lists contain the entities of all Input, In_Out, Output and
25412 -- Proof_In items defined in the corresponding Global pragma.
25413
25414 Repeat_Items : Elist_Id := No_Elist;
25415 -- A list of all global items without full visible refinement found
25416 -- in pragma Global. These states should be repeated in the global
25417 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
25418 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
25419
25420 Spec_Id : Entity_Id;
25421 -- The entity of the subprogram subject to pragma Refined_Global
25422
25423 States : Elist_Id := No_Elist;
25424 -- A list of all states with full or partial visible refinement found in
25425 -- pragma Global.
25426
25427 procedure Check_In_Out_States;
25428 -- Determine whether the corresponding Global pragma mentions In_Out
25429 -- states with visible refinement and if so, ensure that one of the
25430 -- following completions apply to the constituents of the state:
25431 -- 1) there is at least one constituent of mode In_Out
25432 -- 2) there is at least one Input and one Output constituent
25433 -- 3) not all constituents are present and one of them is of mode
25434 -- Output.
25435 -- This routine may remove elements from In_Constits, In_Out_Constits,
25436 -- Out_Constits and Proof_In_Constits.
25437
25438 procedure Check_Input_States;
25439 -- Determine whether the corresponding Global pragma mentions Input
25440 -- states with visible refinement and if so, ensure that at least one of
25441 -- its constituents appears as an Input item in Refined_Global.
25442 -- This routine may remove elements from In_Constits, In_Out_Constits,
25443 -- Out_Constits and Proof_In_Constits.
25444
25445 procedure Check_Output_States;
25446 -- Determine whether the corresponding Global pragma mentions Output
25447 -- states with visible refinement and if so, ensure that all of its
25448 -- constituents appear as Output items in Refined_Global.
25449 -- This routine may remove elements from In_Constits, In_Out_Constits,
25450 -- Out_Constits and Proof_In_Constits.
25451
25452 procedure Check_Proof_In_States;
25453 -- Determine whether the corresponding Global pragma mentions Proof_In
25454 -- states with visible refinement and if so, ensure that at least one of
25455 -- its constituents appears as a Proof_In item in Refined_Global.
25456 -- This routine may remove elements from In_Constits, In_Out_Constits,
25457 -- Out_Constits and Proof_In_Constits.
25458
25459 procedure Check_Refined_Global_List
25460 (List : Node_Id;
25461 Global_Mode : Name_Id := Name_Input);
25462 -- Verify the legality of a single global list declaration. Global_Mode
25463 -- denotes the current mode in effect.
25464
25465 procedure Collect_Global_Items
25466 (List : Node_Id;
25467 Mode : Name_Id := Name_Input);
25468 -- Gather all Input, In_Out, Output and Proof_In items from node List
25469 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
25470 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
25471 -- and Has_Proof_In_State are set when there is at least one abstract
25472 -- state with full or partial visible refinement available in the
25473 -- corresponding mode. Flag Has_Null_State is set when at least state
25474 -- has a null refinement. Mode denotes the current global mode in
25475 -- effect.
25476
25477 function Present_Then_Remove
25478 (List : Elist_Id;
25479 Item : Entity_Id) return Boolean;
25480 -- Search List for a particular entity Item. If Item has been found,
25481 -- remove it from List. This routine is used to strip lists In_Constits,
25482 -- In_Out_Constits and Out_Constits of valid constituents.
25483
25484 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id);
25485 -- Same as function Present_Then_Remove, but do not report the presence
25486 -- of Item in List.
25487
25488 procedure Report_Extra_Constituents;
25489 -- Emit an error for each constituent found in lists In_Constits,
25490 -- In_Out_Constits and Out_Constits.
25491
25492 procedure Report_Missing_Items;
25493 -- Emit an error for each global item not repeated found in list
25494 -- Repeat_Items.
25495
25496 -------------------------
25497 -- Check_In_Out_States --
25498 -------------------------
25499
25500 procedure Check_In_Out_States is
25501 procedure Check_Constituent_Usage (State_Id : Entity_Id);
25502 -- Determine whether one of the following coverage scenarios is in
25503 -- effect:
25504 -- 1) there is at least one constituent of mode In_Out or Output
25505 -- 2) there is at least one pair of constituents with modes Input
25506 -- and Output, or Proof_In and Output.
25507 -- 3) there is at least one constituent of mode Output and not all
25508 -- constituents are present.
25509 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
25510
25511 -----------------------------
25512 -- Check_Constituent_Usage --
25513 -----------------------------
25514
25515 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
25516 Constits : constant Elist_Id :=
25517 Partial_Refinement_Constituents (State_Id);
25518 Constit_Elmt : Elmt_Id;
25519 Constit_Id : Entity_Id;
25520 Has_Missing : Boolean := False;
25521 In_Out_Seen : Boolean := False;
25522 Input_Seen : Boolean := False;
25523 Output_Seen : Boolean := False;
25524 Proof_In_Seen : Boolean := False;
25525
25526 begin
25527 -- Process all the constituents of the state and note their modes
25528 -- within the global refinement.
25529
25530 if Present (Constits) then
25531 Constit_Elmt := First_Elmt (Constits);
25532 while Present (Constit_Elmt) loop
25533 Constit_Id := Node (Constit_Elmt);
25534
25535 if Present_Then_Remove (In_Constits, Constit_Id) then
25536 Input_Seen := True;
25537
25538 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
25539 In_Out_Seen := True;
25540
25541 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
25542 Output_Seen := True;
25543
25544 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
25545 then
25546 Proof_In_Seen := True;
25547
25548 else
25549 Has_Missing := True;
25550 end if;
25551
25552 Next_Elmt (Constit_Elmt);
25553 end loop;
25554 end if;
25555
25556 -- An In_Out constituent is a valid completion
25557
25558 if In_Out_Seen then
25559 null;
25560
25561 -- A pair of one Input/Proof_In and one Output constituent is a
25562 -- valid completion.
25563
25564 elsif (Input_Seen or Proof_In_Seen) and Output_Seen then
25565 null;
25566
25567 elsif Output_Seen then
25568
25569 -- A single Output constituent is a valid completion only when
25570 -- some of the other constituents are missing.
25571
25572 if Has_Missing then
25573 null;
25574
25575 -- Otherwise all constituents are of mode Output
25576
25577 else
25578 SPARK_Msg_NE
25579 ("global refinement of state & must include at least one "
25580 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
25581 N, State_Id);
25582 end if;
25583
25584 -- The state lacks a completion. When full refinement is visible,
25585 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
25586 -- refinement is visible, emit an error if the abstract state
25587 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
25588 -- both are utilized, Check_State_And_Constituent_Use. will issue
25589 -- the error.
25590
25591 elsif not Input_Seen
25592 and then not In_Out_Seen
25593 and then not Output_Seen
25594 and then not Proof_In_Seen
25595 then
25596 if Has_Visible_Refinement (State_Id)
25597 or else Contains (Repeat_Items, State_Id)
25598 then
25599 SPARK_Msg_NE
25600 ("missing global refinement of state &", N, State_Id);
25601 end if;
25602
25603 -- Otherwise the state has a malformed completion where at least
25604 -- one of the constituents has a different mode.
25605
25606 else
25607 SPARK_Msg_NE
25608 ("global refinement of state & redefines the mode of its "
25609 & "constituents", N, State_Id);
25610 end if;
25611 end Check_Constituent_Usage;
25612
25613 -- Local variables
25614
25615 Item_Elmt : Elmt_Id;
25616 Item_Id : Entity_Id;
25617
25618 -- Start of processing for Check_In_Out_States
25619
25620 begin
25621 -- Do not perform this check in an instance because it was already
25622 -- performed successfully in the generic template.
25623
25624 if Is_Generic_Instance (Spec_Id) then
25625 null;
25626
25627 -- Inspect the In_Out items of the corresponding Global pragma
25628 -- looking for a state with a visible refinement.
25629
25630 elsif Has_In_Out_State and then Present (In_Out_Items) then
25631 Item_Elmt := First_Elmt (In_Out_Items);
25632 while Present (Item_Elmt) loop
25633 Item_Id := Node (Item_Elmt);
25634
25635 -- Ensure that one of the three coverage variants is satisfied
25636
25637 if Ekind (Item_Id) = E_Abstract_State
25638 and then Has_Non_Null_Visible_Refinement (Item_Id)
25639 then
25640 Check_Constituent_Usage (Item_Id);
25641 end if;
25642
25643 Next_Elmt (Item_Elmt);
25644 end loop;
25645 end if;
25646 end Check_In_Out_States;
25647
25648 ------------------------
25649 -- Check_Input_States --
25650 ------------------------
25651
25652 procedure Check_Input_States is
25653 procedure Check_Constituent_Usage (State_Id : Entity_Id);
25654 -- Determine whether at least one constituent of state State_Id with
25655 -- full or partial visible refinement is used and has mode Input.
25656 -- Ensure that the remaining constituents do not have In_Out or
25657 -- Output modes. Emit an error if this is not the case
25658 -- (SPARK RM 7.2.4(5)).
25659
25660 -----------------------------
25661 -- Check_Constituent_Usage --
25662 -----------------------------
25663
25664 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
25665 Constits : constant Elist_Id :=
25666 Partial_Refinement_Constituents (State_Id);
25667 Constit_Elmt : Elmt_Id;
25668 Constit_Id : Entity_Id;
25669 In_Seen : Boolean := False;
25670
25671 begin
25672 if Present (Constits) then
25673 Constit_Elmt := First_Elmt (Constits);
25674 while Present (Constit_Elmt) loop
25675 Constit_Id := Node (Constit_Elmt);
25676
25677 -- At least one of the constituents appears as an Input
25678
25679 if Present_Then_Remove (In_Constits, Constit_Id) then
25680 In_Seen := True;
25681
25682 -- A Proof_In constituent can refine an Input state as long
25683 -- as there is at least one Input constituent present.
25684
25685 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
25686 then
25687 null;
25688
25689 -- The constituent appears in the global refinement, but has
25690 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
25691
25692 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
25693 or else Present_Then_Remove (Out_Constits, Constit_Id)
25694 then
25695 Error_Msg_Name_1 := Chars (State_Id);
25696 SPARK_Msg_NE
25697 ("constituent & of state % must have mode `Input` in "
25698 & "global refinement", N, Constit_Id);
25699 end if;
25700
25701 Next_Elmt (Constit_Elmt);
25702 end loop;
25703 end if;
25704
25705 -- Not one of the constituents appeared as Input. Always emit an
25706 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
25707 -- When only partial refinement is visible, emit an error if the
25708 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
25709 -- the case where both are utilized, an error will be issued in
25710 -- Check_State_And_Constituent_Use.
25711
25712 if not In_Seen
25713 and then (Has_Visible_Refinement (State_Id)
25714 or else Contains (Repeat_Items, State_Id))
25715 then
25716 SPARK_Msg_NE
25717 ("global refinement of state & must include at least one "
25718 & "constituent of mode `Input`", N, State_Id);
25719 end if;
25720 end Check_Constituent_Usage;
25721
25722 -- Local variables
25723
25724 Item_Elmt : Elmt_Id;
25725 Item_Id : Entity_Id;
25726
25727 -- Start of processing for Check_Input_States
25728
25729 begin
25730 -- Do not perform this check in an instance because it was already
25731 -- performed successfully in the generic template.
25732
25733 if Is_Generic_Instance (Spec_Id) then
25734 null;
25735
25736 -- Inspect the Input items of the corresponding Global pragma looking
25737 -- for a state with a visible refinement.
25738
25739 elsif Has_In_State and then Present (In_Items) then
25740 Item_Elmt := First_Elmt (In_Items);
25741 while Present (Item_Elmt) loop
25742 Item_Id := Node (Item_Elmt);
25743
25744 -- When full refinement is visible, ensure that at least one of
25745 -- the constituents is utilized and is of mode Input. When only
25746 -- partial refinement is visible, ensure that either one of
25747 -- the constituents is utilized and is of mode Input, or the
25748 -- abstract state is repeated and no constituent is utilized.
25749
25750 if Ekind (Item_Id) = E_Abstract_State
25751 and then Has_Non_Null_Visible_Refinement (Item_Id)
25752 then
25753 Check_Constituent_Usage (Item_Id);
25754 end if;
25755
25756 Next_Elmt (Item_Elmt);
25757 end loop;
25758 end if;
25759 end Check_Input_States;
25760
25761 -------------------------
25762 -- Check_Output_States --
25763 -------------------------
25764
25765 procedure Check_Output_States is
25766 procedure Check_Constituent_Usage (State_Id : Entity_Id);
25767 -- Determine whether all constituents of state State_Id with full
25768 -- visible refinement are used and have mode Output. Emit an error
25769 -- if this is not the case (SPARK RM 7.2.4(5)).
25770
25771 -----------------------------
25772 -- Check_Constituent_Usage --
25773 -----------------------------
25774
25775 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
25776 Constits : constant Elist_Id :=
25777 Partial_Refinement_Constituents (State_Id);
25778 Only_Partial : constant Boolean :=
25779 not Has_Visible_Refinement (State_Id);
25780 Constit_Elmt : Elmt_Id;
25781 Constit_Id : Entity_Id;
25782 Posted : Boolean := False;
25783
25784 begin
25785 if Present (Constits) then
25786 Constit_Elmt := First_Elmt (Constits);
25787 while Present (Constit_Elmt) loop
25788 Constit_Id := Node (Constit_Elmt);
25789
25790 -- Issue an error when a constituent of State_Id is utilized
25791 -- and State_Id has only partial visible refinement
25792 -- (SPARK RM 7.2.4(3d)).
25793
25794 if Only_Partial then
25795 if Present_Then_Remove (Out_Constits, Constit_Id)
25796 or else Present_Then_Remove (In_Constits, Constit_Id)
25797 or else
25798 Present_Then_Remove (In_Out_Constits, Constit_Id)
25799 or else
25800 Present_Then_Remove (Proof_In_Constits, Constit_Id)
25801 then
25802 Error_Msg_Name_1 := Chars (State_Id);
25803 SPARK_Msg_NE
25804 ("constituent & of state % cannot be used in global "
25805 & "refinement", N, Constit_Id);
25806 Error_Msg_Name_1 := Chars (State_Id);
25807 SPARK_Msg_N ("\use state % instead", N);
25808 end if;
25809
25810 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
25811 null;
25812
25813 -- The constituent appears in the global refinement, but has
25814 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
25815
25816 elsif Present_Then_Remove (In_Constits, Constit_Id)
25817 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
25818 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
25819 then
25820 Error_Msg_Name_1 := Chars (State_Id);
25821 SPARK_Msg_NE
25822 ("constituent & of state % must have mode `Output` in "
25823 & "global refinement", N, Constit_Id);
25824
25825 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
25826
25827 else
25828 if not Posted then
25829 Posted := True;
25830 SPARK_Msg_NE
25831 ("`Output` state & must be replaced by all its "
25832 & "constituents in global refinement", N, State_Id);
25833 end if;
25834
25835 SPARK_Msg_NE
25836 ("\constituent & is missing in output list",
25837 N, Constit_Id);
25838 end if;
25839
25840 Next_Elmt (Constit_Elmt);
25841 end loop;
25842 end if;
25843 end Check_Constituent_Usage;
25844
25845 -- Local variables
25846
25847 Item_Elmt : Elmt_Id;
25848 Item_Id : Entity_Id;
25849
25850 -- Start of processing for Check_Output_States
25851
25852 begin
25853 -- Do not perform this check in an instance because it was already
25854 -- performed successfully in the generic template.
25855
25856 if Is_Generic_Instance (Spec_Id) then
25857 null;
25858
25859 -- Inspect the Output items of the corresponding Global pragma
25860 -- looking for a state with a visible refinement.
25861
25862 elsif Has_Out_State and then Present (Out_Items) then
25863 Item_Elmt := First_Elmt (Out_Items);
25864 while Present (Item_Elmt) loop
25865 Item_Id := Node (Item_Elmt);
25866
25867 -- When full refinement is visible, ensure that all of the
25868 -- constituents are utilized and they have mode Output. When
25869 -- only partial refinement is visible, ensure that no
25870 -- constituent is utilized.
25871
25872 if Ekind (Item_Id) = E_Abstract_State
25873 and then Has_Non_Null_Visible_Refinement (Item_Id)
25874 then
25875 Check_Constituent_Usage (Item_Id);
25876 end if;
25877
25878 Next_Elmt (Item_Elmt);
25879 end loop;
25880 end if;
25881 end Check_Output_States;
25882
25883 ---------------------------
25884 -- Check_Proof_In_States --
25885 ---------------------------
25886
25887 procedure Check_Proof_In_States is
25888 procedure Check_Constituent_Usage (State_Id : Entity_Id);
25889 -- Determine whether at least one constituent of state State_Id with
25890 -- full or partial visible refinement is used and has mode Proof_In.
25891 -- Ensure that the remaining constituents do not have Input, In_Out,
25892 -- or Output modes. Emit an error if this is not the case
25893 -- (SPARK RM 7.2.4(5)).
25894
25895 -----------------------------
25896 -- Check_Constituent_Usage --
25897 -----------------------------
25898
25899 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
25900 Constits : constant Elist_Id :=
25901 Partial_Refinement_Constituents (State_Id);
25902 Constit_Elmt : Elmt_Id;
25903 Constit_Id : Entity_Id;
25904 Proof_In_Seen : Boolean := False;
25905
25906 begin
25907 if Present (Constits) then
25908 Constit_Elmt := First_Elmt (Constits);
25909 while Present (Constit_Elmt) loop
25910 Constit_Id := Node (Constit_Elmt);
25911
25912 -- At least one of the constituents appears as Proof_In
25913
25914 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
25915 Proof_In_Seen := True;
25916
25917 -- The constituent appears in the global refinement, but has
25918 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
25919
25920 elsif Present_Then_Remove (In_Constits, Constit_Id)
25921 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
25922 or else Present_Then_Remove (Out_Constits, Constit_Id)
25923 then
25924 Error_Msg_Name_1 := Chars (State_Id);
25925 SPARK_Msg_NE
25926 ("constituent & of state % must have mode `Proof_In` "
25927 & "in global refinement", N, Constit_Id);
25928 end if;
25929
25930 Next_Elmt (Constit_Elmt);
25931 end loop;
25932 end if;
25933
25934 -- Not one of the constituents appeared as Proof_In. Always emit
25935 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
25936 -- When only partial refinement is visible, emit an error if the
25937 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
25938 -- the case where both are utilized, an error will be issued by
25939 -- Check_State_And_Constituent_Use.
25940
25941 if not Proof_In_Seen
25942 and then (Has_Visible_Refinement (State_Id)
25943 or else Contains (Repeat_Items, State_Id))
25944 then
25945 SPARK_Msg_NE
25946 ("global refinement of state & must include at least one "
25947 & "constituent of mode `Proof_In`", N, State_Id);
25948 end if;
25949 end Check_Constituent_Usage;
25950
25951 -- Local variables
25952
25953 Item_Elmt : Elmt_Id;
25954 Item_Id : Entity_Id;
25955
25956 -- Start of processing for Check_Proof_In_States
25957
25958 begin
25959 -- Do not perform this check in an instance because it was already
25960 -- performed successfully in the generic template.
25961
25962 if Is_Generic_Instance (Spec_Id) then
25963 null;
25964
25965 -- Inspect the Proof_In items of the corresponding Global pragma
25966 -- looking for a state with a visible refinement.
25967
25968 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
25969 Item_Elmt := First_Elmt (Proof_In_Items);
25970 while Present (Item_Elmt) loop
25971 Item_Id := Node (Item_Elmt);
25972
25973 -- Ensure that at least one of the constituents is utilized
25974 -- and is of mode Proof_In. When only partial refinement is
25975 -- visible, ensure that either one of the constituents is
25976 -- utilized and is of mode Proof_In, or the abstract state
25977 -- is repeated and no constituent is utilized.
25978
25979 if Ekind (Item_Id) = E_Abstract_State
25980 and then Has_Non_Null_Visible_Refinement (Item_Id)
25981 then
25982 Check_Constituent_Usage (Item_Id);
25983 end if;
25984
25985 Next_Elmt (Item_Elmt);
25986 end loop;
25987 end if;
25988 end Check_Proof_In_States;
25989
25990 -------------------------------
25991 -- Check_Refined_Global_List --
25992 -------------------------------
25993
25994 procedure Check_Refined_Global_List
25995 (List : Node_Id;
25996 Global_Mode : Name_Id := Name_Input)
25997 is
25998 procedure Check_Refined_Global_Item
25999 (Item : Node_Id;
26000 Global_Mode : Name_Id);
26001 -- Verify the legality of a single global item declaration. Parameter
26002 -- Global_Mode denotes the current mode in effect.
26003
26004 -------------------------------
26005 -- Check_Refined_Global_Item --
26006 -------------------------------
26007
26008 procedure Check_Refined_Global_Item
26009 (Item : Node_Id;
26010 Global_Mode : Name_Id)
26011 is
26012 Item_Id : constant Entity_Id := Entity_Of (Item);
26013
26014 procedure Inconsistent_Mode_Error (Expect : Name_Id);
26015 -- Issue a common error message for all mode mismatches. Expect
26016 -- denotes the expected mode.
26017
26018 -----------------------------
26019 -- Inconsistent_Mode_Error --
26020 -----------------------------
26021
26022 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
26023 begin
26024 SPARK_Msg_NE
26025 ("global item & has inconsistent modes", Item, Item_Id);
26026
26027 Error_Msg_Name_1 := Global_Mode;
26028 Error_Msg_Name_2 := Expect;
26029 SPARK_Msg_N ("\expected mode %, found mode %", Item);
26030 end Inconsistent_Mode_Error;
26031
26032 -- Local variables
26033
26034 Enc_State : Entity_Id := Empty;
26035 -- Encapsulating state for constituent, Empty otherwise
26036
26037 -- Start of processing for Check_Refined_Global_Item
26038
26039 begin
26040 if Ekind_In (Item_Id, E_Abstract_State,
26041 E_Constant,
26042 E_Variable)
26043 then
26044 Enc_State := Find_Encapsulating_State (States, Item_Id);
26045 end if;
26046
26047 -- When the state or object acts as a constituent of another
26048 -- state with a visible refinement, collect it for the state
26049 -- completeness checks performed later on. Note that the item
26050 -- acts as a constituent only when the encapsulating state is
26051 -- present in pragma Global.
26052
26053 if Present (Enc_State)
26054 and then (Has_Visible_Refinement (Enc_State)
26055 or else Has_Partial_Visible_Refinement (Enc_State))
26056 and then Contains (States, Enc_State)
26057 then
26058 -- If the state has only partial visible refinement, remove it
26059 -- from the list of items that should be repeated from pragma
26060 -- Global.
26061
26062 if not Has_Visible_Refinement (Enc_State) then
26063 Present_Then_Remove (Repeat_Items, Enc_State);
26064 end if;
26065
26066 if Global_Mode = Name_Input then
26067 Append_New_Elmt (Item_Id, In_Constits);
26068
26069 elsif Global_Mode = Name_In_Out then
26070 Append_New_Elmt (Item_Id, In_Out_Constits);
26071
26072 elsif Global_Mode = Name_Output then
26073 Append_New_Elmt (Item_Id, Out_Constits);
26074
26075 elsif Global_Mode = Name_Proof_In then
26076 Append_New_Elmt (Item_Id, Proof_In_Constits);
26077 end if;
26078
26079 -- When not a constituent, ensure that both occurrences of the
26080 -- item in pragmas Global and Refined_Global match. Also remove
26081 -- it when present from the list of items that should be repeated
26082 -- from pragma Global.
26083
26084 else
26085 Present_Then_Remove (Repeat_Items, Item_Id);
26086
26087 if Contains (In_Items, Item_Id) then
26088 if Global_Mode /= Name_Input then
26089 Inconsistent_Mode_Error (Name_Input);
26090 end if;
26091
26092 elsif Contains (In_Out_Items, Item_Id) then
26093 if Global_Mode /= Name_In_Out then
26094 Inconsistent_Mode_Error (Name_In_Out);
26095 end if;
26096
26097 elsif Contains (Out_Items, Item_Id) then
26098 if Global_Mode /= Name_Output then
26099 Inconsistent_Mode_Error (Name_Output);
26100 end if;
26101
26102 elsif Contains (Proof_In_Items, Item_Id) then
26103 null;
26104
26105 -- The item does not appear in the corresponding Global pragma,
26106 -- it must be an extra (SPARK RM 7.2.4(3)).
26107
26108 else
26109 SPARK_Msg_NE ("extra global item &", Item, Item_Id);
26110 end if;
26111 end if;
26112 end Check_Refined_Global_Item;
26113
26114 -- Local variables
26115
26116 Item : Node_Id;
26117
26118 -- Start of processing for Check_Refined_Global_List
26119
26120 begin
26121 -- Do not perform this check in an instance because it was already
26122 -- performed successfully in the generic template.
26123
26124 if Is_Generic_Instance (Spec_Id) then
26125 null;
26126
26127 elsif Nkind (List) = N_Null then
26128 null;
26129
26130 -- Single global item declaration
26131
26132 elsif Nkind_In (List, N_Expanded_Name,
26133 N_Identifier,
26134 N_Selected_Component)
26135 then
26136 Check_Refined_Global_Item (List, Global_Mode);
26137
26138 -- Simple global list or moded global list declaration
26139
26140 elsif Nkind (List) = N_Aggregate then
26141
26142 -- The declaration of a simple global list appear as a collection
26143 -- of expressions.
26144
26145 if Present (Expressions (List)) then
26146 Item := First (Expressions (List));
26147 while Present (Item) loop
26148 Check_Refined_Global_Item (Item, Global_Mode);
26149 Next (Item);
26150 end loop;
26151
26152 -- The declaration of a moded global list appears as a collection
26153 -- of component associations where individual choices denote
26154 -- modes.
26155
26156 elsif Present (Component_Associations (List)) then
26157 Item := First (Component_Associations (List));
26158 while Present (Item) loop
26159 Check_Refined_Global_List
26160 (List => Expression (Item),
26161 Global_Mode => Chars (First (Choices (Item))));
26162
26163 Next (Item);
26164 end loop;
26165
26166 -- Invalid tree
26167
26168 else
26169 raise Program_Error;
26170 end if;
26171
26172 -- Invalid list
26173
26174 else
26175 raise Program_Error;
26176 end if;
26177 end Check_Refined_Global_List;
26178
26179 --------------------------
26180 -- Collect_Global_Items --
26181 --------------------------
26182
26183 procedure Collect_Global_Items
26184 (List : Node_Id;
26185 Mode : Name_Id := Name_Input)
26186 is
26187 procedure Collect_Global_Item
26188 (Item : Node_Id;
26189 Item_Mode : Name_Id);
26190 -- Add a single item to the appropriate list. Item_Mode denotes the
26191 -- current mode in effect.
26192
26193 -------------------------
26194 -- Collect_Global_Item --
26195 -------------------------
26196
26197 procedure Collect_Global_Item
26198 (Item : Node_Id;
26199 Item_Mode : Name_Id)
26200 is
26201 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
26202 -- The above handles abstract views of variables and states built
26203 -- for limited with clauses.
26204
26205 begin
26206 -- Signal that the global list contains at least one abstract
26207 -- state with a visible refinement. Note that the refinement may
26208 -- be null in which case there are no constituents.
26209
26210 if Ekind (Item_Id) = E_Abstract_State then
26211 if Has_Null_Visible_Refinement (Item_Id) then
26212 Has_Null_State := True;
26213
26214 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
26215 Append_New_Elmt (Item_Id, States);
26216
26217 if Item_Mode = Name_Input then
26218 Has_In_State := True;
26219 elsif Item_Mode = Name_In_Out then
26220 Has_In_Out_State := True;
26221 elsif Item_Mode = Name_Output then
26222 Has_Out_State := True;
26223 elsif Item_Mode = Name_Proof_In then
26224 Has_Proof_In_State := True;
26225 end if;
26226 end if;
26227 end if;
26228
26229 -- Record global items without full visible refinement found in
26230 -- pragma Global which should be repeated in the global refinement
26231 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
26232
26233 if Ekind (Item_Id) /= E_Abstract_State
26234 or else not Has_Visible_Refinement (Item_Id)
26235 then
26236 Append_New_Elmt (Item_Id, Repeat_Items);
26237 end if;
26238
26239 -- Add the item to the proper list
26240
26241 if Item_Mode = Name_Input then
26242 Append_New_Elmt (Item_Id, In_Items);
26243 elsif Item_Mode = Name_In_Out then
26244 Append_New_Elmt (Item_Id, In_Out_Items);
26245 elsif Item_Mode = Name_Output then
26246 Append_New_Elmt (Item_Id, Out_Items);
26247 elsif Item_Mode = Name_Proof_In then
26248 Append_New_Elmt (Item_Id, Proof_In_Items);
26249 end if;
26250 end Collect_Global_Item;
26251
26252 -- Local variables
26253
26254 Item : Node_Id;
26255
26256 -- Start of processing for Collect_Global_Items
26257
26258 begin
26259 if Nkind (List) = N_Null then
26260 null;
26261
26262 -- Single global item declaration
26263
26264 elsif Nkind_In (List, N_Expanded_Name,
26265 N_Identifier,
26266 N_Selected_Component)
26267 then
26268 Collect_Global_Item (List, Mode);
26269
26270 -- Single global list or moded global list declaration
26271
26272 elsif Nkind (List) = N_Aggregate then
26273
26274 -- The declaration of a simple global list appear as a collection
26275 -- of expressions.
26276
26277 if Present (Expressions (List)) then
26278 Item := First (Expressions (List));
26279 while Present (Item) loop
26280 Collect_Global_Item (Item, Mode);
26281 Next (Item);
26282 end loop;
26283
26284 -- The declaration of a moded global list appears as a collection
26285 -- of component associations where individual choices denote mode.
26286
26287 elsif Present (Component_Associations (List)) then
26288 Item := First (Component_Associations (List));
26289 while Present (Item) loop
26290 Collect_Global_Items
26291 (List => Expression (Item),
26292 Mode => Chars (First (Choices (Item))));
26293
26294 Next (Item);
26295 end loop;
26296
26297 -- Invalid tree
26298
26299 else
26300 raise Program_Error;
26301 end if;
26302
26303 -- To accommodate partial decoration of disabled SPARK features, this
26304 -- routine may be called with illegal input. If this is the case, do
26305 -- not raise Program_Error.
26306
26307 else
26308 null;
26309 end if;
26310 end Collect_Global_Items;
26311
26312 -------------------------
26313 -- Present_Then_Remove --
26314 -------------------------
26315
26316 function Present_Then_Remove
26317 (List : Elist_Id;
26318 Item : Entity_Id) return Boolean
26319 is
26320 Elmt : Elmt_Id;
26321
26322 begin
26323 if Present (List) then
26324 Elmt := First_Elmt (List);
26325 while Present (Elmt) loop
26326 if Node (Elmt) = Item then
26327 Remove_Elmt (List, Elmt);
26328 return True;
26329 end if;
26330
26331 Next_Elmt (Elmt);
26332 end loop;
26333 end if;
26334
26335 return False;
26336 end Present_Then_Remove;
26337
26338 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id) is
26339 Ignore : Boolean;
26340 begin
26341 Ignore := Present_Then_Remove (List, Item);
26342 end Present_Then_Remove;
26343
26344 -------------------------------
26345 -- Report_Extra_Constituents --
26346 -------------------------------
26347
26348 procedure Report_Extra_Constituents is
26349 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
26350 -- Emit an error for every element of List
26351
26352 ---------------------------------------
26353 -- Report_Extra_Constituents_In_List --
26354 ---------------------------------------
26355
26356 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
26357 Constit_Elmt : Elmt_Id;
26358
26359 begin
26360 if Present (List) then
26361 Constit_Elmt := First_Elmt (List);
26362 while Present (Constit_Elmt) loop
26363 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
26364 Next_Elmt (Constit_Elmt);
26365 end loop;
26366 end if;
26367 end Report_Extra_Constituents_In_List;
26368
26369 -- Start of processing for Report_Extra_Constituents
26370
26371 begin
26372 -- Do not perform this check in an instance because it was already
26373 -- performed successfully in the generic template.
26374
26375 if Is_Generic_Instance (Spec_Id) then
26376 null;
26377
26378 else
26379 Report_Extra_Constituents_In_List (In_Constits);
26380 Report_Extra_Constituents_In_List (In_Out_Constits);
26381 Report_Extra_Constituents_In_List (Out_Constits);
26382 Report_Extra_Constituents_In_List (Proof_In_Constits);
26383 end if;
26384 end Report_Extra_Constituents;
26385
26386 --------------------------
26387 -- Report_Missing_Items --
26388 --------------------------
26389
26390 procedure Report_Missing_Items is
26391 Item_Elmt : Elmt_Id;
26392 Item_Id : Entity_Id;
26393
26394 begin
26395 -- Do not perform this check in an instance because it was already
26396 -- performed successfully in the generic template.
26397
26398 if Is_Generic_Instance (Spec_Id) then
26399 null;
26400
26401 else
26402 if Present (Repeat_Items) then
26403 Item_Elmt := First_Elmt (Repeat_Items);
26404 while Present (Item_Elmt) loop
26405 Item_Id := Node (Item_Elmt);
26406 SPARK_Msg_NE ("missing global item &", N, Item_Id);
26407 Next_Elmt (Item_Elmt);
26408 end loop;
26409 end if;
26410 end if;
26411 end Report_Missing_Items;
26412
26413 -- Local variables
26414
26415 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
26416 Errors : constant Nat := Serious_Errors_Detected;
26417 Items : Node_Id;
26418 No_Constit : Boolean;
26419
26420 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
26421
26422 begin
26423 -- Do not analyze the pragma multiple times
26424
26425 if Is_Analyzed_Pragma (N) then
26426 return;
26427 end if;
26428
26429 Spec_Id := Unique_Defining_Entity (Body_Decl);
26430
26431 -- Use the anonymous object as the proper spec when Refined_Global
26432 -- applies to the body of a single task type. The object carries the
26433 -- proper Chars as well as all non-refined versions of pragmas.
26434
26435 if Is_Single_Concurrent_Type (Spec_Id) then
26436 Spec_Id := Anonymous_Object (Spec_Id);
26437 end if;
26438
26439 Global := Get_Pragma (Spec_Id, Pragma_Global);
26440 Items := Expression (Get_Argument (N, Spec_Id));
26441
26442 -- The subprogram declaration lacks pragma Global. This renders
26443 -- Refined_Global useless as there is nothing to refine.
26444
26445 if No (Global) then
26446 SPARK_Msg_NE
26447 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
26448 & "& lacks aspect or pragma Global"), N, Spec_Id);
26449 goto Leave;
26450 end if;
26451
26452 -- Extract all relevant items from the corresponding Global pragma
26453
26454 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
26455
26456 -- Package and subprogram bodies are instantiated individually in
26457 -- a separate compiler pass. Due to this mode of instantiation, the
26458 -- refinement of a state may no longer be visible when a subprogram
26459 -- body contract is instantiated. Since the generic template is legal,
26460 -- do not perform this check in the instance to circumvent this oddity.
26461
26462 if Is_Generic_Instance (Spec_Id) then
26463 null;
26464
26465 -- Non-instance case
26466
26467 else
26468 -- The corresponding Global pragma must mention at least one
26469 -- state with a visible refinement at the point Refined_Global
26470 -- is processed. States with null refinements need Refined_Global
26471 -- pragma (SPARK RM 7.2.4(2)).
26472
26473 if not Has_In_State
26474 and then not Has_In_Out_State
26475 and then not Has_Out_State
26476 and then not Has_Proof_In_State
26477 and then not Has_Null_State
26478 then
26479 SPARK_Msg_NE
26480 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
26481 & "depend on abstract state with visible refinement"),
26482 N, Spec_Id);
26483 goto Leave;
26484
26485 -- The global refinement of inputs and outputs cannot be null when
26486 -- the corresponding Global pragma contains at least one item except
26487 -- in the case where we have states with null refinements.
26488
26489 elsif Nkind (Items) = N_Null
26490 and then
26491 (Present (In_Items)
26492 or else Present (In_Out_Items)
26493 or else Present (Out_Items)
26494 or else Present (Proof_In_Items))
26495 and then not Has_Null_State
26496 then
26497 SPARK_Msg_NE
26498 (Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has "
26499 & "global items"), N, Spec_Id);
26500 goto Leave;
26501 end if;
26502 end if;
26503
26504 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
26505 -- This ensures that the categorization of all refined global items is
26506 -- consistent with their role.
26507
26508 Analyze_Global_In_Decl_Part (N);
26509
26510 -- Perform all refinement checks with respect to completeness and mode
26511 -- matching.
26512
26513 if Serious_Errors_Detected = Errors then
26514 Check_Refined_Global_List (Items);
26515 end if;
26516
26517 -- Store the information that no constituent is used in the global
26518 -- refinement, prior to calling checking procedures which remove items
26519 -- from the list of constituents.
26520
26521 No_Constit :=
26522 No (In_Constits)
26523 and then No (In_Out_Constits)
26524 and then No (Out_Constits)
26525 and then No (Proof_In_Constits);
26526
26527 -- For Input states with visible refinement, at least one constituent
26528 -- must be used as an Input in the global refinement.
26529
26530 if Serious_Errors_Detected = Errors then
26531 Check_Input_States;
26532 end if;
26533
26534 -- Verify all possible completion variants for In_Out states with
26535 -- visible refinement.
26536
26537 if Serious_Errors_Detected = Errors then
26538 Check_In_Out_States;
26539 end if;
26540
26541 -- For Output states with visible refinement, all constituents must be
26542 -- used as Outputs in the global refinement.
26543
26544 if Serious_Errors_Detected = Errors then
26545 Check_Output_States;
26546 end if;
26547
26548 -- For Proof_In states with visible refinement, at least one constituent
26549 -- must be used as Proof_In in the global refinement.
26550
26551 if Serious_Errors_Detected = Errors then
26552 Check_Proof_In_States;
26553 end if;
26554
26555 -- Emit errors for all constituents that belong to other states with
26556 -- visible refinement that do not appear in Global.
26557
26558 if Serious_Errors_Detected = Errors then
26559 Report_Extra_Constituents;
26560 end if;
26561
26562 -- Emit errors for all items in Global that are not repeated in the
26563 -- global refinement and for which there is no full visible refinement
26564 -- and, in the case of states with partial visible refinement, no
26565 -- constituent is mentioned in the global refinement.
26566
26567 if Serious_Errors_Detected = Errors then
26568 Report_Missing_Items;
26569 end if;
26570
26571 -- Emit an error if no constituent is used in the global refinement
26572 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
26573 -- one may be issued by the checking procedures. Do not perform this
26574 -- check in an instance because it was already performed successfully
26575 -- in the generic template.
26576
26577 if Serious_Errors_Detected = Errors
26578 and then not Is_Generic_Instance (Spec_Id)
26579 and then not Has_Null_State
26580 and then No_Constit
26581 then
26582 SPARK_Msg_N ("missing refinement", N);
26583 end if;
26584
26585 <<Leave>>
26586 Set_Is_Analyzed_Pragma (N);
26587 end Analyze_Refined_Global_In_Decl_Part;
26588
26589 ----------------------------------------
26590 -- Analyze_Refined_State_In_Decl_Part --
26591 ----------------------------------------
26592
26593 procedure Analyze_Refined_State_In_Decl_Part
26594 (N : Node_Id;
26595 Freeze_Id : Entity_Id := Empty)
26596 is
26597 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
26598 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
26599 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
26600
26601 Available_States : Elist_Id := No_Elist;
26602 -- A list of all abstract states defined in the package declaration that
26603 -- are available for refinement. The list is used to report unrefined
26604 -- states.
26605
26606 Body_States : Elist_Id := No_Elist;
26607 -- A list of all hidden states that appear in the body of the related
26608 -- package. The list is used to report unused hidden states.
26609
26610 Constituents_Seen : Elist_Id := No_Elist;
26611 -- A list that contains all constituents processed so far. The list is
26612 -- used to detect multiple uses of the same constituent.
26613
26614 Freeze_Posted : Boolean := False;
26615 -- A flag that controls the output of a freezing-related error (see use
26616 -- below).
26617
26618 Refined_States_Seen : Elist_Id := No_Elist;
26619 -- A list that contains all refined states processed so far. The list is
26620 -- used to detect duplicate refinements.
26621
26622 procedure Analyze_Refinement_Clause (Clause : Node_Id);
26623 -- Perform full analysis of a single refinement clause
26624
26625 procedure Report_Unrefined_States (States : Elist_Id);
26626 -- Emit errors for all unrefined abstract states found in list States
26627
26628 -------------------------------
26629 -- Analyze_Refinement_Clause --
26630 -------------------------------
26631
26632 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
26633 AR_Constit : Entity_Id := Empty;
26634 AW_Constit : Entity_Id := Empty;
26635 ER_Constit : Entity_Id := Empty;
26636 EW_Constit : Entity_Id := Empty;
26637 -- The entities of external constituents that contain one of the
26638 -- following enabled properties: Async_Readers, Async_Writers,
26639 -- Effective_Reads and Effective_Writes.
26640
26641 External_Constit_Seen : Boolean := False;
26642 -- Flag used to mark when at least one external constituent is part
26643 -- of the state refinement.
26644
26645 Non_Null_Seen : Boolean := False;
26646 Null_Seen : Boolean := False;
26647 -- Flags used to detect multiple uses of null in a single clause or a
26648 -- mixture of null and non-null constituents.
26649
26650 Part_Of_Constits : Elist_Id := No_Elist;
26651 -- A list of all candidate constituents subject to indicator Part_Of
26652 -- where the encapsulating state is the current state.
26653
26654 State : Node_Id;
26655 State_Id : Entity_Id;
26656 -- The current state being refined
26657
26658 procedure Analyze_Constituent (Constit : Node_Id);
26659 -- Perform full analysis of a single constituent
26660
26661 procedure Check_External_Property
26662 (Prop_Nam : Name_Id;
26663 Enabled : Boolean;
26664 Constit : Entity_Id);
26665 -- Determine whether a property denoted by name Prop_Nam is present
26666 -- in the refined state. Emit an error if this is not the case. Flag
26667 -- Enabled should be set when the property applies to the refined
26668 -- state. Constit denotes the constituent (if any) which introduces
26669 -- the property in the refinement.
26670
26671 procedure Match_State;
26672 -- Determine whether the state being refined appears in list
26673 -- Available_States. Emit an error when attempting to re-refine the
26674 -- state or when the state is not defined in the package declaration,
26675 -- otherwise remove the state from Available_States.
26676
26677 procedure Report_Unused_Constituents (Constits : Elist_Id);
26678 -- Emit errors for all unused Part_Of constituents in list Constits
26679
26680 -------------------------
26681 -- Analyze_Constituent --
26682 -------------------------
26683
26684 procedure Analyze_Constituent (Constit : Node_Id) is
26685 procedure Match_Constituent (Constit_Id : Entity_Id);
26686 -- Determine whether constituent Constit denoted by its entity
26687 -- Constit_Id appears in Body_States. Emit an error when the
26688 -- constituent is not a valid hidden state of the related package
26689 -- or when it is used more than once. Otherwise remove the
26690 -- constituent from Body_States.
26691
26692 -----------------------
26693 -- Match_Constituent --
26694 -----------------------
26695
26696 procedure Match_Constituent (Constit_Id : Entity_Id) is
26697 procedure Collect_Constituent;
26698 -- Verify the legality of constituent Constit_Id and add it to
26699 -- the refinements of State_Id.
26700
26701 -------------------------
26702 -- Collect_Constituent --
26703 -------------------------
26704
26705 procedure Collect_Constituent is
26706 Constits : Elist_Id;
26707
26708 begin
26709 -- The Ghost policy in effect at the point of abstract state
26710 -- declaration and constituent must match (SPARK RM 6.9(15))
26711
26712 Check_Ghost_Refinement
26713 (State, State_Id, Constit, Constit_Id);
26714
26715 -- A synchronized state must be refined by a synchronized
26716 -- object or another synchronized state (SPARK RM 9.6).
26717
26718 if Is_Synchronized_State (State_Id)
26719 and then not Is_Synchronized_Object (Constit_Id)
26720 and then not Is_Synchronized_State (Constit_Id)
26721 then
26722 SPARK_Msg_NE
26723 ("constituent of synchronized state & must be "
26724 & "synchronized", Constit, State_Id);
26725 end if;
26726
26727 -- Add the constituent to the list of processed items to aid
26728 -- with the detection of duplicates.
26729
26730 Append_New_Elmt (Constit_Id, Constituents_Seen);
26731
26732 -- Collect the constituent in the list of refinement items
26733 -- and establish a relation between the refined state and
26734 -- the item.
26735
26736 Constits := Refinement_Constituents (State_Id);
26737
26738 if No (Constits) then
26739 Constits := New_Elmt_List;
26740 Set_Refinement_Constituents (State_Id, Constits);
26741 end if;
26742
26743 Append_Elmt (Constit_Id, Constits);
26744 Set_Encapsulating_State (Constit_Id, State_Id);
26745
26746 -- The state has at least one legal constituent, mark the
26747 -- start of the refinement region. The region ends when the
26748 -- body declarations end (see routine Analyze_Declarations).
26749
26750 Set_Has_Visible_Refinement (State_Id);
26751
26752 -- When the constituent is external, save its relevant
26753 -- property for further checks.
26754
26755 if Async_Readers_Enabled (Constit_Id) then
26756 AR_Constit := Constit_Id;
26757 External_Constit_Seen := True;
26758 end if;
26759
26760 if Async_Writers_Enabled (Constit_Id) then
26761 AW_Constit := Constit_Id;
26762 External_Constit_Seen := True;
26763 end if;
26764
26765 if Effective_Reads_Enabled (Constit_Id) then
26766 ER_Constit := Constit_Id;
26767 External_Constit_Seen := True;
26768 end if;
26769
26770 if Effective_Writes_Enabled (Constit_Id) then
26771 EW_Constit := Constit_Id;
26772 External_Constit_Seen := True;
26773 end if;
26774 end Collect_Constituent;
26775
26776 -- Local variables
26777
26778 State_Elmt : Elmt_Id;
26779
26780 -- Start of processing for Match_Constituent
26781
26782 begin
26783 -- Detect a duplicate use of a constituent
26784
26785 if Contains (Constituents_Seen, Constit_Id) then
26786 SPARK_Msg_NE
26787 ("duplicate use of constituent &", Constit, Constit_Id);
26788 return;
26789 end if;
26790
26791 -- The constituent is subject to a Part_Of indicator
26792
26793 if Present (Encapsulating_State (Constit_Id)) then
26794 if Encapsulating_State (Constit_Id) = State_Id then
26795 Remove (Part_Of_Constits, Constit_Id);
26796 Collect_Constituent;
26797
26798 -- The constituent is part of another state and is used
26799 -- incorrectly in the refinement of the current state.
26800
26801 else
26802 Error_Msg_Name_1 := Chars (State_Id);
26803 SPARK_Msg_NE
26804 ("& cannot act as constituent of state %",
26805 Constit, Constit_Id);
26806 SPARK_Msg_NE
26807 ("\Part_Of indicator specifies encapsulator &",
26808 Constit, Encapsulating_State (Constit_Id));
26809 end if;
26810
26811 -- The only other source of legal constituents is the body
26812 -- state space of the related package.
26813
26814 else
26815 if Present (Body_States) then
26816 State_Elmt := First_Elmt (Body_States);
26817 while Present (State_Elmt) loop
26818
26819 -- Consume a valid constituent to signal that it has
26820 -- been encountered.
26821
26822 if Node (State_Elmt) = Constit_Id then
26823 Remove_Elmt (Body_States, State_Elmt);
26824 Collect_Constituent;
26825 return;
26826 end if;
26827
26828 Next_Elmt (State_Elmt);
26829 end loop;
26830 end if;
26831
26832 -- Constants are part of the hidden state of a package, but
26833 -- the compiler cannot determine whether they have variable
26834 -- input (SPARK RM 7.1.1(2)) and cannot classify them as a
26835 -- hidden state. Accept the constant quietly even if it is
26836 -- a visible state or lacks a Part_Of indicator.
26837
26838 if Ekind (Constit_Id) = E_Constant then
26839 Collect_Constituent;
26840
26841 -- If we get here, then the constituent is not a hidden
26842 -- state of the related package and may not be used in a
26843 -- refinement (SPARK RM 7.2.2(9)).
26844
26845 else
26846 Error_Msg_Name_1 := Chars (Spec_Id);
26847 SPARK_Msg_NE
26848 ("cannot use & in refinement, constituent is not a "
26849 & "hidden state of package %", Constit, Constit_Id);
26850 end if;
26851 end if;
26852 end Match_Constituent;
26853
26854 -- Local variables
26855
26856 Constit_Id : Entity_Id;
26857 Constits : Elist_Id;
26858
26859 -- Start of processing for Analyze_Constituent
26860
26861 begin
26862 -- Detect multiple uses of null in a single refinement clause or a
26863 -- mixture of null and non-null constituents.
26864
26865 if Nkind (Constit) = N_Null then
26866 if Null_Seen then
26867 SPARK_Msg_N
26868 ("multiple null constituents not allowed", Constit);
26869
26870 elsif Non_Null_Seen then
26871 SPARK_Msg_N
26872 ("cannot mix null and non-null constituents", Constit);
26873
26874 else
26875 Null_Seen := True;
26876
26877 -- Collect the constituent in the list of refinement items
26878
26879 Constits := Refinement_Constituents (State_Id);
26880
26881 if No (Constits) then
26882 Constits := New_Elmt_List;
26883 Set_Refinement_Constituents (State_Id, Constits);
26884 end if;
26885
26886 Append_Elmt (Constit, Constits);
26887
26888 -- The state has at least one legal constituent, mark the
26889 -- start of the refinement region. The region ends when the
26890 -- body declarations end (see Analyze_Declarations).
26891
26892 Set_Has_Visible_Refinement (State_Id);
26893 end if;
26894
26895 -- Non-null constituents
26896
26897 else
26898 Non_Null_Seen := True;
26899
26900 if Null_Seen then
26901 SPARK_Msg_N
26902 ("cannot mix null and non-null constituents", Constit);
26903 end if;
26904
26905 Analyze (Constit);
26906 Resolve_State (Constit);
26907
26908 -- Ensure that the constituent denotes a valid state or a
26909 -- whole object (SPARK RM 7.2.2(5)).
26910
26911 if Is_Entity_Name (Constit) then
26912 Constit_Id := Entity_Of (Constit);
26913
26914 -- When a constituent is declared after a subprogram body
26915 -- that caused "freezing" of the related contract where
26916 -- pragma Refined_State resides, the constituent appears
26917 -- undefined and carries Any_Id as its entity.
26918
26919 -- package body Pack
26920 -- with Refined_State => (State => Constit)
26921 -- is
26922 -- procedure Proc
26923 -- with Refined_Global => (Input => Constit)
26924 -- is
26925 -- ...
26926 -- end Proc;
26927
26928 -- Constit : ...;
26929 -- end Pack;
26930
26931 if Constit_Id = Any_Id then
26932 SPARK_Msg_NE ("& is undefined", Constit, Constit_Id);
26933
26934 -- Emit a specialized info message when the contract of
26935 -- the related package body was "frozen" by another body.
26936 -- Note that it is not possible to precisely identify why
26937 -- the constituent is undefined because it is not visible
26938 -- when pragma Refined_State is analyzed. This message is
26939 -- a reasonable approximation.
26940
26941 if Present (Freeze_Id) and then not Freeze_Posted then
26942 Freeze_Posted := True;
26943
26944 Error_Msg_Name_1 := Chars (Body_Id);
26945 Error_Msg_Sloc := Sloc (Freeze_Id);
26946 SPARK_Msg_NE
26947 ("body & declared # freezes the contract of %",
26948 N, Freeze_Id);
26949 SPARK_Msg_N
26950 ("\all constituents must be declared before body #",
26951 N);
26952
26953 -- A misplaced constituent is a critical error because
26954 -- pragma Refined_Depends or Refined_Global depends on
26955 -- the proper link between a state and a constituent.
26956 -- Stop the compilation, as this leads to a multitude
26957 -- of misleading cascaded errors.
26958
26959 raise Program_Error;
26960 end if;
26961
26962 -- The constituent is a valid state or object
26963
26964 elsif Ekind_In (Constit_Id, E_Abstract_State,
26965 E_Constant,
26966 E_Variable)
26967 then
26968 Match_Constituent (Constit_Id);
26969
26970 -- The variable may eventually become a constituent of a
26971 -- single protected/task type. Record the reference now
26972 -- and verify its legality when analyzing the contract of
26973 -- the variable (SPARK RM 9.3).
26974
26975 if Ekind (Constit_Id) = E_Variable then
26976 Record_Possible_Part_Of_Reference
26977 (Var_Id => Constit_Id,
26978 Ref => Constit);
26979 end if;
26980
26981 -- Otherwise the constituent is illegal
26982
26983 else
26984 SPARK_Msg_NE
26985 ("constituent & must denote object or state",
26986 Constit, Constit_Id);
26987 end if;
26988
26989 -- The constituent is illegal
26990
26991 else
26992 SPARK_Msg_N ("malformed constituent", Constit);
26993 end if;
26994 end if;
26995 end Analyze_Constituent;
26996
26997 -----------------------------
26998 -- Check_External_Property --
26999 -----------------------------
27000
27001 procedure Check_External_Property
27002 (Prop_Nam : Name_Id;
27003 Enabled : Boolean;
27004 Constit : Entity_Id)
27005 is
27006 begin
27007 -- The property is missing in the declaration of the state, but
27008 -- a constituent is introducing it in the state refinement
27009 -- (SPARK RM 7.2.8(2)).
27010
27011 if not Enabled and then Present (Constit) then
27012 Error_Msg_Name_1 := Prop_Nam;
27013 Error_Msg_Name_2 := Chars (State_Id);
27014 SPARK_Msg_NE
27015 ("constituent & introduces external property % in refinement "
27016 & "of state %", State, Constit);
27017
27018 Error_Msg_Sloc := Sloc (State_Id);
27019 SPARK_Msg_N
27020 ("\property is missing in abstract state declaration #",
27021 State);
27022 end if;
27023 end Check_External_Property;
27024
27025 -----------------
27026 -- Match_State --
27027 -----------------
27028
27029 procedure Match_State is
27030 State_Elmt : Elmt_Id;
27031
27032 begin
27033 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
27034
27035 if Contains (Refined_States_Seen, State_Id) then
27036 SPARK_Msg_NE
27037 ("duplicate refinement of state &", State, State_Id);
27038 return;
27039 end if;
27040
27041 -- Inspect the abstract states defined in the package declaration
27042 -- looking for a match.
27043
27044 State_Elmt := First_Elmt (Available_States);
27045 while Present (State_Elmt) loop
27046
27047 -- A valid abstract state is being refined in the body. Add
27048 -- the state to the list of processed refined states to aid
27049 -- with the detection of duplicate refinements. Remove the
27050 -- state from Available_States to signal that it has already
27051 -- been refined.
27052
27053 if Node (State_Elmt) = State_Id then
27054 Append_New_Elmt (State_Id, Refined_States_Seen);
27055 Remove_Elmt (Available_States, State_Elmt);
27056 return;
27057 end if;
27058
27059 Next_Elmt (State_Elmt);
27060 end loop;
27061
27062 -- If we get here, we are refining a state that is not defined in
27063 -- the package declaration.
27064
27065 Error_Msg_Name_1 := Chars (Spec_Id);
27066 SPARK_Msg_NE
27067 ("cannot refine state, & is not defined in package %",
27068 State, State_Id);
27069 end Match_State;
27070
27071 --------------------------------
27072 -- Report_Unused_Constituents --
27073 --------------------------------
27074
27075 procedure Report_Unused_Constituents (Constits : Elist_Id) is
27076 Constit_Elmt : Elmt_Id;
27077 Constit_Id : Entity_Id;
27078 Posted : Boolean := False;
27079
27080 begin
27081 if Present (Constits) then
27082 Constit_Elmt := First_Elmt (Constits);
27083 while Present (Constit_Elmt) loop
27084 Constit_Id := Node (Constit_Elmt);
27085
27086 -- Generate an error message of the form:
27087
27088 -- state ... has unused Part_Of constituents
27089 -- abstract state ... defined at ...
27090 -- constant ... defined at ...
27091 -- variable ... defined at ...
27092
27093 if not Posted then
27094 Posted := True;
27095 SPARK_Msg_NE
27096 ("state & has unused Part_Of constituents",
27097 State, State_Id);
27098 end if;
27099
27100 Error_Msg_Sloc := Sloc (Constit_Id);
27101
27102 if Ekind (Constit_Id) = E_Abstract_State then
27103 SPARK_Msg_NE
27104 ("\abstract state & defined #", State, Constit_Id);
27105
27106 elsif Ekind (Constit_Id) = E_Constant then
27107 SPARK_Msg_NE
27108 ("\constant & defined #", State, Constit_Id);
27109
27110 else
27111 pragma Assert (Ekind (Constit_Id) = E_Variable);
27112 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
27113 end if;
27114
27115 Next_Elmt (Constit_Elmt);
27116 end loop;
27117 end if;
27118 end Report_Unused_Constituents;
27119
27120 -- Local declarations
27121
27122 Body_Ref : Node_Id;
27123 Body_Ref_Elmt : Elmt_Id;
27124 Constit : Node_Id;
27125 Extra_State : Node_Id;
27126
27127 -- Start of processing for Analyze_Refinement_Clause
27128
27129 begin
27130 -- A refinement clause appears as a component association where the
27131 -- sole choice is the state and the expressions are the constituents.
27132 -- This is a syntax error, always report.
27133
27134 if Nkind (Clause) /= N_Component_Association then
27135 Error_Msg_N ("malformed state refinement clause", Clause);
27136 return;
27137 end if;
27138
27139 -- Analyze the state name of a refinement clause
27140
27141 State := First (Choices (Clause));
27142
27143 Analyze (State);
27144 Resolve_State (State);
27145
27146 -- Ensure that the state name denotes a valid abstract state that is
27147 -- defined in the spec of the related package.
27148
27149 if Is_Entity_Name (State) then
27150 State_Id := Entity_Of (State);
27151
27152 -- When the abstract state is undefined, it appears as Any_Id. Do
27153 -- not continue with the analysis of the clause.
27154
27155 if State_Id = Any_Id then
27156 return;
27157
27158 -- Catch any attempts to re-refine a state or refine a state that
27159 -- is not defined in the package declaration.
27160
27161 elsif Ekind (State_Id) = E_Abstract_State then
27162 Match_State;
27163
27164 else
27165 SPARK_Msg_NE ("& must denote abstract state", State, State_Id);
27166 return;
27167 end if;
27168
27169 -- References to a state with visible refinement are illegal.
27170 -- When nested packages are involved, detecting such references is
27171 -- tricky because pragma Refined_State is analyzed later than the
27172 -- offending pragma Depends or Global. References that occur in
27173 -- such nested context are stored in a list. Emit errors for all
27174 -- references found in Body_References (SPARK RM 6.1.4(8)).
27175
27176 if Present (Body_References (State_Id)) then
27177 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
27178 while Present (Body_Ref_Elmt) loop
27179 Body_Ref := Node (Body_Ref_Elmt);
27180
27181 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
27182 Error_Msg_Sloc := Sloc (State);
27183 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
27184
27185 Next_Elmt (Body_Ref_Elmt);
27186 end loop;
27187 end if;
27188
27189 -- The state name is illegal. This is a syntax error, always report.
27190
27191 else
27192 Error_Msg_N ("malformed state name in refinement clause", State);
27193 return;
27194 end if;
27195
27196 -- A refinement clause may only refine one state at a time
27197
27198 Extra_State := Next (State);
27199
27200 if Present (Extra_State) then
27201 SPARK_Msg_N
27202 ("refinement clause cannot cover multiple states", Extra_State);
27203 end if;
27204
27205 -- Replicate the Part_Of constituents of the refined state because
27206 -- the algorithm will consume items.
27207
27208 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
27209
27210 -- Analyze all constituents of the refinement. Multiple constituents
27211 -- appear as an aggregate.
27212
27213 Constit := Expression (Clause);
27214
27215 if Nkind (Constit) = N_Aggregate then
27216 if Present (Component_Associations (Constit)) then
27217 SPARK_Msg_N
27218 ("constituents of refinement clause must appear in "
27219 & "positional form", Constit);
27220
27221 else pragma Assert (Present (Expressions (Constit)));
27222 Constit := First (Expressions (Constit));
27223 while Present (Constit) loop
27224 Analyze_Constituent (Constit);
27225 Next (Constit);
27226 end loop;
27227 end if;
27228
27229 -- Various forms of a single constituent. Note that these may include
27230 -- malformed constituents.
27231
27232 else
27233 Analyze_Constituent (Constit);
27234 end if;
27235
27236 -- Verify that external constituents do not introduce new external
27237 -- property in the state refinement (SPARK RM 7.2.8(2)).
27238
27239 if Is_External_State (State_Id) then
27240 Check_External_Property
27241 (Prop_Nam => Name_Async_Readers,
27242 Enabled => Async_Readers_Enabled (State_Id),
27243 Constit => AR_Constit);
27244
27245 Check_External_Property
27246 (Prop_Nam => Name_Async_Writers,
27247 Enabled => Async_Writers_Enabled (State_Id),
27248 Constit => AW_Constit);
27249
27250 Check_External_Property
27251 (Prop_Nam => Name_Effective_Reads,
27252 Enabled => Effective_Reads_Enabled (State_Id),
27253 Constit => ER_Constit);
27254
27255 Check_External_Property
27256 (Prop_Nam => Name_Effective_Writes,
27257 Enabled => Effective_Writes_Enabled (State_Id),
27258 Constit => EW_Constit);
27259
27260 -- When a refined state is not external, it should not have external
27261 -- constituents (SPARK RM 7.2.8(1)).
27262
27263 elsif External_Constit_Seen then
27264 SPARK_Msg_NE
27265 ("non-external state & cannot contain external constituents in "
27266 & "refinement", State, State_Id);
27267 end if;
27268
27269 -- Ensure that all Part_Of candidate constituents have been mentioned
27270 -- in the refinement clause.
27271
27272 Report_Unused_Constituents (Part_Of_Constits);
27273 end Analyze_Refinement_Clause;
27274
27275 -----------------------------
27276 -- Report_Unrefined_States --
27277 -----------------------------
27278
27279 procedure Report_Unrefined_States (States : Elist_Id) is
27280 State_Elmt : Elmt_Id;
27281
27282 begin
27283 if Present (States) then
27284 State_Elmt := First_Elmt (States);
27285 while Present (State_Elmt) loop
27286 SPARK_Msg_N
27287 ("abstract state & must be refined", Node (State_Elmt));
27288
27289 Next_Elmt (State_Elmt);
27290 end loop;
27291 end if;
27292 end Report_Unrefined_States;
27293
27294 -- Local declarations
27295
27296 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
27297 Clause : Node_Id;
27298
27299 -- Start of processing for Analyze_Refined_State_In_Decl_Part
27300
27301 begin
27302 -- Do not analyze the pragma multiple times
27303
27304 if Is_Analyzed_Pragma (N) then
27305 return;
27306 end if;
27307
27308 -- Replicate the abstract states declared by the package because the
27309 -- matching algorithm will consume states.
27310
27311 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
27312
27313 -- Gather all abstract states and objects declared in the visible
27314 -- state space of the package body. These items must be utilized as
27315 -- constituents in a state refinement.
27316
27317 Body_States := Collect_Body_States (Body_Id);
27318
27319 -- Multiple non-null state refinements appear as an aggregate
27320
27321 if Nkind (Clauses) = N_Aggregate then
27322 if Present (Expressions (Clauses)) then
27323 SPARK_Msg_N
27324 ("state refinements must appear as component associations",
27325 Clauses);
27326
27327 else pragma Assert (Present (Component_Associations (Clauses)));
27328 Clause := First (Component_Associations (Clauses));
27329 while Present (Clause) loop
27330 Analyze_Refinement_Clause (Clause);
27331 Next (Clause);
27332 end loop;
27333 end if;
27334
27335 -- Various forms of a single state refinement. Note that these may
27336 -- include malformed refinements.
27337
27338 else
27339 Analyze_Refinement_Clause (Clauses);
27340 end if;
27341
27342 -- List all abstract states that were left unrefined
27343
27344 Report_Unrefined_States (Available_States);
27345
27346 Set_Is_Analyzed_Pragma (N);
27347 end Analyze_Refined_State_In_Decl_Part;
27348
27349 ------------------------------------
27350 -- Analyze_Test_Case_In_Decl_Part --
27351 ------------------------------------
27352
27353 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
27354 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
27355 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
27356
27357 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
27358 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
27359 -- denoted by Arg_Nam.
27360
27361 ------------------------------
27362 -- Preanalyze_Test_Case_Arg --
27363 ------------------------------
27364
27365 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
27366 Arg : Node_Id;
27367
27368 begin
27369 -- Preanalyze the original aspect argument for ASIS or for a generic
27370 -- subprogram to properly capture global references.
27371
27372 if ASIS_Mode or else Is_Generic_Subprogram (Spec_Id) then
27373 Arg :=
27374 Test_Case_Arg
27375 (Prag => N,
27376 Arg_Nam => Arg_Nam,
27377 From_Aspect => True);
27378
27379 if Present (Arg) then
27380 Preanalyze_Assert_Expression
27381 (Expression (Arg), Standard_Boolean);
27382 end if;
27383 end if;
27384
27385 Arg := Test_Case_Arg (N, Arg_Nam);
27386
27387 if Present (Arg) then
27388 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
27389 end if;
27390 end Preanalyze_Test_Case_Arg;
27391
27392 -- Local variables
27393
27394 Restore_Scope : Boolean := False;
27395
27396 -- Start of processing for Analyze_Test_Case_In_Decl_Part
27397
27398 begin
27399 -- Do not analyze the pragma multiple times
27400
27401 if Is_Analyzed_Pragma (N) then
27402 return;
27403 end if;
27404
27405 -- Ensure that the formal parameters are visible when analyzing all
27406 -- clauses. This falls out of the general rule of aspects pertaining
27407 -- to subprogram declarations.
27408
27409 if not In_Open_Scopes (Spec_Id) then
27410 Restore_Scope := True;
27411 Push_Scope (Spec_Id);
27412
27413 if Is_Generic_Subprogram (Spec_Id) then
27414 Install_Generic_Formals (Spec_Id);
27415 else
27416 Install_Formals (Spec_Id);
27417 end if;
27418 end if;
27419
27420 Preanalyze_Test_Case_Arg (Name_Requires);
27421 Preanalyze_Test_Case_Arg (Name_Ensures);
27422
27423 if Restore_Scope then
27424 End_Scope;
27425 end if;
27426
27427 -- Currently it is not possible to inline pre/postconditions on a
27428 -- subprogram subject to pragma Inline_Always.
27429
27430 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
27431
27432 Set_Is_Analyzed_Pragma (N);
27433 end Analyze_Test_Case_In_Decl_Part;
27434
27435 ----------------
27436 -- Appears_In --
27437 ----------------
27438
27439 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
27440 Elmt : Elmt_Id;
27441 Id : Entity_Id;
27442
27443 begin
27444 if Present (List) then
27445 Elmt := First_Elmt (List);
27446 while Present (Elmt) loop
27447 if Nkind (Node (Elmt)) = N_Defining_Identifier then
27448 Id := Node (Elmt);
27449 else
27450 Id := Entity_Of (Node (Elmt));
27451 end if;
27452
27453 if Id = Item_Id then
27454 return True;
27455 end if;
27456
27457 Next_Elmt (Elmt);
27458 end loop;
27459 end if;
27460
27461 return False;
27462 end Appears_In;
27463
27464 -----------------------------------
27465 -- Build_Pragma_Check_Equivalent --
27466 -----------------------------------
27467
27468 function Build_Pragma_Check_Equivalent
27469 (Prag : Node_Id;
27470 Subp_Id : Entity_Id := Empty;
27471 Inher_Id : Entity_Id := Empty;
27472 Keep_Pragma_Id : Boolean := False) return Node_Id
27473 is
27474 function Suppress_Reference (N : Node_Id) return Traverse_Result;
27475 -- Detect whether node N references a formal parameter subject to
27476 -- pragma Unreferenced. If this is the case, set Comes_From_Source
27477 -- to False to suppress the generation of a reference when analyzing
27478 -- N later on.
27479
27480 ------------------------
27481 -- Suppress_Reference --
27482 ------------------------
27483
27484 function Suppress_Reference (N : Node_Id) return Traverse_Result is
27485 Formal : Entity_Id;
27486
27487 begin
27488 if Is_Entity_Name (N) and then Present (Entity (N)) then
27489 Formal := Entity (N);
27490
27491 -- The formal parameter is subject to pragma Unreferenced. Prevent
27492 -- the generation of references by resetting the Comes_From_Source
27493 -- flag.
27494
27495 if Is_Formal (Formal)
27496 and then Has_Pragma_Unreferenced (Formal)
27497 then
27498 Set_Comes_From_Source (N, False);
27499 end if;
27500 end if;
27501
27502 return OK;
27503 end Suppress_Reference;
27504
27505 procedure Suppress_References is
27506 new Traverse_Proc (Suppress_Reference);
27507
27508 -- Local variables
27509
27510 Loc : constant Source_Ptr := Sloc (Prag);
27511 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
27512 Check_Prag : Node_Id;
27513 Msg_Arg : Node_Id;
27514 Nam : Name_Id;
27515
27516 Needs_Wrapper : Boolean;
27517 pragma Unreferenced (Needs_Wrapper);
27518
27519 -- Start of processing for Build_Pragma_Check_Equivalent
27520
27521 begin
27522 -- When the pre- or postcondition is inherited, map the formals of the
27523 -- inherited subprogram to those of the current subprogram. In addition,
27524 -- map primitive operations of the parent type into the corresponding
27525 -- primitive operations of the descendant.
27526
27527 if Present (Inher_Id) then
27528 pragma Assert (Present (Subp_Id));
27529
27530 Update_Primitives_Mapping (Inher_Id, Subp_Id);
27531
27532 -- Use generic machinery to copy inherited pragma, as if it were an
27533 -- instantiation, resetting source locations appropriately, so that
27534 -- expressions inside the inherited pragma use chained locations.
27535 -- This is used in particular in GNATprove to locate precisely
27536 -- messages on a given inherited pragma.
27537
27538 Set_Copied_Sloc_For_Inherited_Pragma
27539 (Unit_Declaration_Node (Subp_Id), Inher_Id);
27540 Check_Prag := New_Copy_Tree (Source => Prag);
27541
27542 -- Build the inherited class-wide condition
27543
27544 Build_Class_Wide_Expression
27545 (Prag => Check_Prag,
27546 Subp => Subp_Id,
27547 Par_Subp => Inher_Id,
27548 Adjust_Sloc => True,
27549 Needs_Wrapper => Needs_Wrapper);
27550
27551 -- If not an inherited condition simply copy the original pragma
27552
27553 else
27554 Check_Prag := New_Copy_Tree (Source => Prag);
27555 end if;
27556
27557 -- Mark the pragma as being internally generated and reset the Analyzed
27558 -- flag.
27559
27560 Set_Analyzed (Check_Prag, False);
27561 Set_Comes_From_Source (Check_Prag, False);
27562
27563 -- The tree of the original pragma may contain references to the
27564 -- formal parameters of the related subprogram. At the same time
27565 -- the corresponding body may mark the formals as unreferenced:
27566
27567 -- procedure Proc (Formal : ...)
27568 -- with Pre => Formal ...;
27569
27570 -- procedure Proc (Formal : ...) is
27571 -- pragma Unreferenced (Formal);
27572 -- ...
27573
27574 -- This creates problems because all pragma Check equivalents are
27575 -- analyzed at the end of the body declarations. Since all source
27576 -- references have already been accounted for, reset any references
27577 -- to such formals in the generated pragma Check equivalent.
27578
27579 Suppress_References (Check_Prag);
27580
27581 if Present (Corresponding_Aspect (Prag)) then
27582 Nam := Chars (Identifier (Corresponding_Aspect (Prag)));
27583 else
27584 Nam := Prag_Nam;
27585 end if;
27586
27587 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
27588 -- the copied pragma in the newly created pragma, convert the copy into
27589 -- pragma Check by correcting the name and adding a check_kind argument.
27590
27591 if not Keep_Pragma_Id then
27592 Set_Class_Present (Check_Prag, False);
27593
27594 Set_Pragma_Identifier
27595 (Check_Prag, Make_Identifier (Loc, Name_Check));
27596
27597 Prepend_To (Pragma_Argument_Associations (Check_Prag),
27598 Make_Pragma_Argument_Association (Loc,
27599 Expression => Make_Identifier (Loc, Nam)));
27600 end if;
27601
27602 -- Update the error message when the pragma is inherited
27603
27604 if Present (Inher_Id) then
27605 Msg_Arg := Last (Pragma_Argument_Associations (Check_Prag));
27606
27607 if Chars (Msg_Arg) = Name_Message then
27608 String_To_Name_Buffer (Strval (Expression (Msg_Arg)));
27609
27610 -- Insert "inherited" to improve the error message
27611
27612 if Name_Buffer (1 .. 8) = "failed p" then
27613 Insert_Str_In_Name_Buffer ("inherited ", 8);
27614 Set_Strval (Expression (Msg_Arg), String_From_Name_Buffer);
27615 end if;
27616 end if;
27617 end if;
27618
27619 return Check_Prag;
27620 end Build_Pragma_Check_Equivalent;
27621
27622 -----------------------------
27623 -- Check_Applicable_Policy --
27624 -----------------------------
27625
27626 procedure Check_Applicable_Policy (N : Node_Id) is
27627 PP : Node_Id;
27628 Policy : Name_Id;
27629
27630 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
27631
27632 begin
27633 -- No effect if not valid assertion kind name
27634
27635 if not Is_Valid_Assertion_Kind (Ename) then
27636 return;
27637 end if;
27638
27639 -- Loop through entries in check policy list
27640
27641 PP := Opt.Check_Policy_List;
27642 while Present (PP) loop
27643 declare
27644 PPA : constant List_Id := Pragma_Argument_Associations (PP);
27645 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
27646
27647 begin
27648 if Ename = Pnm
27649 or else Pnm = Name_Assertion
27650 or else (Pnm = Name_Statement_Assertions
27651 and then Nam_In (Ename, Name_Assert,
27652 Name_Assert_And_Cut,
27653 Name_Assume,
27654 Name_Loop_Invariant,
27655 Name_Loop_Variant))
27656 then
27657 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
27658
27659 case Policy is
27660 when Name_Ignore
27661 | Name_Off
27662 =>
27663 Set_Is_Ignored (N, True);
27664 Set_Is_Checked (N, False);
27665
27666 when Name_Check
27667 | Name_On
27668 =>
27669 Set_Is_Checked (N, True);
27670 Set_Is_Ignored (N, False);
27671
27672 when Name_Disable =>
27673 Set_Is_Ignored (N, True);
27674 Set_Is_Checked (N, False);
27675 Set_Is_Disabled (N, True);
27676
27677 -- That should be exhaustive, the null here is a defence
27678 -- against a malformed tree from previous errors.
27679
27680 when others =>
27681 null;
27682 end case;
27683
27684 return;
27685 end if;
27686
27687 PP := Next_Pragma (PP);
27688 end;
27689 end loop;
27690
27691 -- If there are no specific entries that matched, then we let the
27692 -- setting of assertions govern. Note that this provides the needed
27693 -- compatibility with the RM for the cases of assertion, invariant,
27694 -- precondition, predicate, and postcondition.
27695
27696 if Assertions_Enabled then
27697 Set_Is_Checked (N, True);
27698 Set_Is_Ignored (N, False);
27699 else
27700 Set_Is_Checked (N, False);
27701 Set_Is_Ignored (N, True);
27702 end if;
27703 end Check_Applicable_Policy;
27704
27705 -------------------------------
27706 -- Check_External_Properties --
27707 -------------------------------
27708
27709 procedure Check_External_Properties
27710 (Item : Node_Id;
27711 AR : Boolean;
27712 AW : Boolean;
27713 ER : Boolean;
27714 EW : Boolean)
27715 is
27716 begin
27717 -- All properties enabled
27718
27719 if AR and AW and ER and EW then
27720 null;
27721
27722 -- Async_Readers + Effective_Writes
27723 -- Async_Readers + Async_Writers + Effective_Writes
27724
27725 elsif AR and EW and not ER then
27726 null;
27727
27728 -- Async_Writers + Effective_Reads
27729 -- Async_Readers + Async_Writers + Effective_Reads
27730
27731 elsif AW and ER and not EW then
27732 null;
27733
27734 -- Async_Readers + Async_Writers
27735
27736 elsif AR and AW and not ER and not EW then
27737 null;
27738
27739 -- Async_Readers
27740
27741 elsif AR and not AW and not ER and not EW then
27742 null;
27743
27744 -- Async_Writers
27745
27746 elsif AW and not AR and not ER and not EW then
27747 null;
27748
27749 else
27750 SPARK_Msg_N
27751 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
27752 Item);
27753 end if;
27754 end Check_External_Properties;
27755
27756 ----------------
27757 -- Check_Kind --
27758 ----------------
27759
27760 function Check_Kind (Nam : Name_Id) return Name_Id is
27761 PP : Node_Id;
27762
27763 begin
27764 -- Loop through entries in check policy list
27765
27766 PP := Opt.Check_Policy_List;
27767 while Present (PP) loop
27768 declare
27769 PPA : constant List_Id := Pragma_Argument_Associations (PP);
27770 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
27771
27772 begin
27773 if Nam = Pnm
27774 or else (Pnm = Name_Assertion
27775 and then Is_Valid_Assertion_Kind (Nam))
27776 or else (Pnm = Name_Statement_Assertions
27777 and then Nam_In (Nam, Name_Assert,
27778 Name_Assert_And_Cut,
27779 Name_Assume,
27780 Name_Loop_Invariant,
27781 Name_Loop_Variant))
27782 then
27783 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
27784 when Name_Check
27785 | Name_On
27786 =>
27787 return Name_Check;
27788
27789 when Name_Ignore
27790 | Name_Off
27791 =>
27792 return Name_Ignore;
27793
27794 when Name_Disable =>
27795 return Name_Disable;
27796
27797 when others =>
27798 raise Program_Error;
27799 end case;
27800
27801 else
27802 PP := Next_Pragma (PP);
27803 end if;
27804 end;
27805 end loop;
27806
27807 -- If there are no specific entries that matched, then we let the
27808 -- setting of assertions govern. Note that this provides the needed
27809 -- compatibility with the RM for the cases of assertion, invariant,
27810 -- precondition, predicate, and postcondition.
27811
27812 if Assertions_Enabled then
27813 return Name_Check;
27814 else
27815 return Name_Ignore;
27816 end if;
27817 end Check_Kind;
27818
27819 ---------------------------
27820 -- Check_Missing_Part_Of --
27821 ---------------------------
27822
27823 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
27824 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
27825 -- Determine whether a package denoted by Pack_Id declares at least one
27826 -- visible state.
27827
27828 -----------------------
27829 -- Has_Visible_State --
27830 -----------------------
27831
27832 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
27833 Item_Id : Entity_Id;
27834
27835 begin
27836 -- Traverse the entity chain of the package trying to find at least
27837 -- one visible abstract state, variable or a package [instantiation]
27838 -- that declares a visible state.
27839
27840 Item_Id := First_Entity (Pack_Id);
27841 while Present (Item_Id)
27842 and then not In_Private_Part (Item_Id)
27843 loop
27844 -- Do not consider internally generated items
27845
27846 if not Comes_From_Source (Item_Id) then
27847 null;
27848
27849 -- A visible state has been found
27850
27851 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
27852 return True;
27853
27854 -- Recursively peek into nested packages and instantiations
27855
27856 elsif Ekind (Item_Id) = E_Package
27857 and then Has_Visible_State (Item_Id)
27858 then
27859 return True;
27860 end if;
27861
27862 Next_Entity (Item_Id);
27863 end loop;
27864
27865 return False;
27866 end Has_Visible_State;
27867
27868 -- Local variables
27869
27870 Pack_Id : Entity_Id;
27871 Placement : State_Space_Kind;
27872
27873 -- Start of processing for Check_Missing_Part_Of
27874
27875 begin
27876 -- Do not consider abstract states, variables or package instantiations
27877 -- coming from an instance as those always inherit the Part_Of indicator
27878 -- of the instance itself.
27879
27880 if In_Instance then
27881 return;
27882
27883 -- Do not consider internally generated entities as these can never
27884 -- have a Part_Of indicator.
27885
27886 elsif not Comes_From_Source (Item_Id) then
27887 return;
27888
27889 -- Perform these checks only when SPARK_Mode is enabled as they will
27890 -- interfere with standard Ada rules and produce false positives.
27891
27892 elsif SPARK_Mode /= On then
27893 return;
27894
27895 -- Do not consider constants, because the compiler cannot accurately
27896 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
27897 -- act as a hidden state of a package.
27898
27899 elsif Ekind (Item_Id) = E_Constant then
27900 return;
27901 end if;
27902
27903 -- Find where the abstract state, variable or package instantiation
27904 -- lives with respect to the state space.
27905
27906 Find_Placement_In_State_Space
27907 (Item_Id => Item_Id,
27908 Placement => Placement,
27909 Pack_Id => Pack_Id);
27910
27911 -- Items that appear in a non-package construct (subprogram, block, etc)
27912 -- do not require a Part_Of indicator because they can never act as a
27913 -- hidden state.
27914
27915 if Placement = Not_In_Package then
27916 null;
27917
27918 -- An item declared in the body state space of a package always act as a
27919 -- constituent and does not need explicit Part_Of indicator.
27920
27921 elsif Placement = Body_State_Space then
27922 null;
27923
27924 -- In general an item declared in the visible state space of a package
27925 -- does not require a Part_Of indicator. The only exception is when the
27926 -- related package is a private child unit in which case Part_Of must
27927 -- denote a state in the parent unit or in one of its descendants.
27928
27929 elsif Placement = Visible_State_Space then
27930 if Is_Child_Unit (Pack_Id)
27931 and then Is_Private_Descendant (Pack_Id)
27932 then
27933 -- A package instantiation does not need a Part_Of indicator when
27934 -- the related generic template has no visible state.
27935
27936 if Ekind (Item_Id) = E_Package
27937 and then Is_Generic_Instance (Item_Id)
27938 and then not Has_Visible_State (Item_Id)
27939 then
27940 null;
27941
27942 -- All other cases require Part_Of
27943
27944 else
27945 Error_Msg_N
27946 ("indicator Part_Of is required in this context "
27947 & "(SPARK RM 7.2.6(3))", Item_Id);
27948 Error_Msg_Name_1 := Chars (Pack_Id);
27949 Error_Msg_N
27950 ("\& is declared in the visible part of private child "
27951 & "unit %", Item_Id);
27952 end if;
27953 end if;
27954
27955 -- When the item appears in the private state space of a packge, it must
27956 -- be a part of some state declared by the said package.
27957
27958 else pragma Assert (Placement = Private_State_Space);
27959
27960 -- The related package does not declare a state, the item cannot act
27961 -- as a Part_Of constituent.
27962
27963 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
27964 null;
27965
27966 -- A package instantiation does not need a Part_Of indicator when the
27967 -- related generic template has no visible state.
27968
27969 elsif Ekind (Pack_Id) = E_Package
27970 and then Is_Generic_Instance (Pack_Id)
27971 and then not Has_Visible_State (Pack_Id)
27972 then
27973 null;
27974
27975 -- All other cases require Part_Of
27976
27977 else
27978 Error_Msg_N
27979 ("indicator Part_Of is required in this context "
27980 & "(SPARK RM 7.2.6(2))", Item_Id);
27981 Error_Msg_Name_1 := Chars (Pack_Id);
27982 Error_Msg_N
27983 ("\& is declared in the private part of package %", Item_Id);
27984 end if;
27985 end if;
27986 end Check_Missing_Part_Of;
27987
27988 ---------------------------------------------------
27989 -- Check_Postcondition_Use_In_Inlined_Subprogram --
27990 ---------------------------------------------------
27991
27992 procedure Check_Postcondition_Use_In_Inlined_Subprogram
27993 (Prag : Node_Id;
27994 Spec_Id : Entity_Id)
27995 is
27996 begin
27997 if Warn_On_Redundant_Constructs
27998 and then Has_Pragma_Inline_Always (Spec_Id)
27999 then
28000 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
28001
28002 if From_Aspect_Specification (Prag) then
28003 Error_Msg_NE
28004 ("aspect % not enforced on inlined subprogram &?r?",
28005 Corresponding_Aspect (Prag), Spec_Id);
28006 else
28007 Error_Msg_NE
28008 ("pragma % not enforced on inlined subprogram &?r?",
28009 Prag, Spec_Id);
28010 end if;
28011 end if;
28012 end Check_Postcondition_Use_In_Inlined_Subprogram;
28013
28014 -------------------------------------
28015 -- Check_State_And_Constituent_Use --
28016 -------------------------------------
28017
28018 procedure Check_State_And_Constituent_Use
28019 (States : Elist_Id;
28020 Constits : Elist_Id;
28021 Context : Node_Id)
28022 is
28023 Constit_Elmt : Elmt_Id;
28024 Constit_Id : Entity_Id;
28025 State_Id : Entity_Id;
28026
28027 begin
28028 -- Nothing to do if there are no states or constituents
28029
28030 if No (States) or else No (Constits) then
28031 return;
28032 end if;
28033
28034 -- Inspect the list of constituents and try to determine whether its
28035 -- encapsulating state is in list States.
28036
28037 Constit_Elmt := First_Elmt (Constits);
28038 while Present (Constit_Elmt) loop
28039 Constit_Id := Node (Constit_Elmt);
28040
28041 -- Determine whether the constituent is part of an encapsulating
28042 -- state that appears in the same context and if this is the case,
28043 -- emit an error (SPARK RM 7.2.6(7)).
28044
28045 State_Id := Find_Encapsulating_State (States, Constit_Id);
28046
28047 if Present (State_Id) then
28048 Error_Msg_Name_1 := Chars (Constit_Id);
28049 SPARK_Msg_NE
28050 ("cannot mention state & and its constituent % in the same "
28051 & "context", Context, State_Id);
28052 exit;
28053 end if;
28054
28055 Next_Elmt (Constit_Elmt);
28056 end loop;
28057 end Check_State_And_Constituent_Use;
28058
28059 ---------------------------------------------
28060 -- Collect_Inherited_Class_Wide_Conditions --
28061 ---------------------------------------------
28062
28063 procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is
28064 Parent_Subp : constant Entity_Id :=
28065 Ultimate_Alias (Overridden_Operation (Subp));
28066 -- The Overridden_Operation may itself be inherited and as such have no
28067 -- explicit contract.
28068
28069 Prags : constant Node_Id := Contract (Parent_Subp);
28070 In_Spec_Expr : Boolean;
28071 Installed : Boolean;
28072 Prag : Node_Id;
28073 New_Prag : Node_Id;
28074
28075 begin
28076 Installed := False;
28077
28078 -- Iterate over the contract of the overridden subprogram to find all
28079 -- inherited class-wide pre- and postconditions.
28080
28081 if Present (Prags) then
28082 Prag := Pre_Post_Conditions (Prags);
28083
28084 while Present (Prag) loop
28085 if Nam_In (Pragma_Name_Unmapped (Prag),
28086 Name_Precondition, Name_Postcondition)
28087 and then Class_Present (Prag)
28088 then
28089 -- The generated pragma must be analyzed in the context of
28090 -- the subprogram, to make its formals visible. In addition,
28091 -- we must inhibit freezing and full analysis because the
28092 -- controlling type of the subprogram is not frozen yet, and
28093 -- may have further primitives.
28094
28095 if not Installed then
28096 Installed := True;
28097 Push_Scope (Subp);
28098 Install_Formals (Subp);
28099 In_Spec_Expr := In_Spec_Expression;
28100 In_Spec_Expression := True;
28101 end if;
28102
28103 New_Prag :=
28104 Build_Pragma_Check_Equivalent
28105 (Prag, Subp, Parent_Subp, Keep_Pragma_Id => True);
28106
28107 Insert_After (Unit_Declaration_Node (Subp), New_Prag);
28108 Preanalyze (New_Prag);
28109
28110 -- Prevent further analysis in subsequent processing of the
28111 -- current list of declarations
28112
28113 Set_Analyzed (New_Prag);
28114 end if;
28115
28116 Prag := Next_Pragma (Prag);
28117 end loop;
28118
28119 if Installed then
28120 In_Spec_Expression := In_Spec_Expr;
28121 End_Scope;
28122 end if;
28123 end if;
28124 end Collect_Inherited_Class_Wide_Conditions;
28125
28126 ---------------------------------------
28127 -- Collect_Subprogram_Inputs_Outputs --
28128 ---------------------------------------
28129
28130 procedure Collect_Subprogram_Inputs_Outputs
28131 (Subp_Id : Entity_Id;
28132 Synthesize : Boolean := False;
28133 Subp_Inputs : in out Elist_Id;
28134 Subp_Outputs : in out Elist_Id;
28135 Global_Seen : out Boolean)
28136 is
28137 procedure Collect_Dependency_Clause (Clause : Node_Id);
28138 -- Collect all relevant items from a dependency clause
28139
28140 procedure Collect_Global_List
28141 (List : Node_Id;
28142 Mode : Name_Id := Name_Input);
28143 -- Collect all relevant items from a global list
28144
28145 -------------------------------
28146 -- Collect_Dependency_Clause --
28147 -------------------------------
28148
28149 procedure Collect_Dependency_Clause (Clause : Node_Id) is
28150 procedure Collect_Dependency_Item
28151 (Item : Node_Id;
28152 Is_Input : Boolean);
28153 -- Add an item to the proper subprogram input or output collection
28154
28155 -----------------------------
28156 -- Collect_Dependency_Item --
28157 -----------------------------
28158
28159 procedure Collect_Dependency_Item
28160 (Item : Node_Id;
28161 Is_Input : Boolean)
28162 is
28163 Extra : Node_Id;
28164
28165 begin
28166 -- Nothing to collect when the item is null
28167
28168 if Nkind (Item) = N_Null then
28169 null;
28170
28171 -- Ditto for attribute 'Result
28172
28173 elsif Is_Attribute_Result (Item) then
28174 null;
28175
28176 -- Multiple items appear as an aggregate
28177
28178 elsif Nkind (Item) = N_Aggregate then
28179 Extra := First (Expressions (Item));
28180 while Present (Extra) loop
28181 Collect_Dependency_Item (Extra, Is_Input);
28182 Next (Extra);
28183 end loop;
28184
28185 -- Otherwise this is a solitary item
28186
28187 else
28188 if Is_Input then
28189 Append_New_Elmt (Item, Subp_Inputs);
28190 else
28191 Append_New_Elmt (Item, Subp_Outputs);
28192 end if;
28193 end if;
28194 end Collect_Dependency_Item;
28195
28196 -- Start of processing for Collect_Dependency_Clause
28197
28198 begin
28199 if Nkind (Clause) = N_Null then
28200 null;
28201
28202 -- A dependency cause appears as component association
28203
28204 elsif Nkind (Clause) = N_Component_Association then
28205 Collect_Dependency_Item
28206 (Item => Expression (Clause),
28207 Is_Input => True);
28208
28209 Collect_Dependency_Item
28210 (Item => First (Choices (Clause)),
28211 Is_Input => False);
28212
28213 -- To accommodate partial decoration of disabled SPARK features, this
28214 -- routine may be called with illegal input. If this is the case, do
28215 -- not raise Program_Error.
28216
28217 else
28218 null;
28219 end if;
28220 end Collect_Dependency_Clause;
28221
28222 -------------------------
28223 -- Collect_Global_List --
28224 -------------------------
28225
28226 procedure Collect_Global_List
28227 (List : Node_Id;
28228 Mode : Name_Id := Name_Input)
28229 is
28230 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
28231 -- Add an item to the proper subprogram input or output collection
28232
28233 -------------------------
28234 -- Collect_Global_Item --
28235 -------------------------
28236
28237 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
28238 begin
28239 if Nam_In (Mode, Name_In_Out, Name_Input) then
28240 Append_New_Elmt (Item, Subp_Inputs);
28241 end if;
28242
28243 if Nam_In (Mode, Name_In_Out, Name_Output) then
28244 Append_New_Elmt (Item, Subp_Outputs);
28245 end if;
28246 end Collect_Global_Item;
28247
28248 -- Local variables
28249
28250 Assoc : Node_Id;
28251 Item : Node_Id;
28252
28253 -- Start of processing for Collect_Global_List
28254
28255 begin
28256 if Nkind (List) = N_Null then
28257 null;
28258
28259 -- Single global item declaration
28260
28261 elsif Nkind_In (List, N_Expanded_Name,
28262 N_Identifier,
28263 N_Selected_Component)
28264 then
28265 Collect_Global_Item (List, Mode);
28266
28267 -- Simple global list or moded global list declaration
28268
28269 elsif Nkind (List) = N_Aggregate then
28270 if Present (Expressions (List)) then
28271 Item := First (Expressions (List));
28272 while Present (Item) loop
28273 Collect_Global_Item (Item, Mode);
28274 Next (Item);
28275 end loop;
28276
28277 else
28278 Assoc := First (Component_Associations (List));
28279 while Present (Assoc) loop
28280 Collect_Global_List
28281 (List => Expression (Assoc),
28282 Mode => Chars (First (Choices (Assoc))));
28283 Next (Assoc);
28284 end loop;
28285 end if;
28286
28287 -- To accommodate partial decoration of disabled SPARK features, this
28288 -- routine may be called with illegal input. If this is the case, do
28289 -- not raise Program_Error.
28290
28291 else
28292 null;
28293 end if;
28294 end Collect_Global_List;
28295
28296 -- Local variables
28297
28298 Clause : Node_Id;
28299 Clauses : Node_Id;
28300 Depends : Node_Id;
28301 Formal : Entity_Id;
28302 Global : Node_Id;
28303 Spec_Id : Entity_Id;
28304 Subp_Decl : Node_Id;
28305 Typ : Entity_Id;
28306
28307 -- Start of processing for Collect_Subprogram_Inputs_Outputs
28308
28309 begin
28310 Global_Seen := False;
28311
28312 -- Process all formal parameters of entries, [generic] subprograms, and
28313 -- their bodies.
28314
28315 if Ekind_In (Subp_Id, E_Entry,
28316 E_Entry_Family,
28317 E_Function,
28318 E_Generic_Function,
28319 E_Generic_Procedure,
28320 E_Procedure,
28321 E_Subprogram_Body)
28322 then
28323 Subp_Decl := Unit_Declaration_Node (Subp_Id);
28324 Spec_Id := Unique_Defining_Entity (Subp_Decl);
28325
28326 -- Process all [generic] formal parameters
28327
28328 Formal := First_Entity (Spec_Id);
28329 while Present (Formal) loop
28330 if Ekind_In (Formal, E_Generic_In_Parameter,
28331 E_In_Out_Parameter,
28332 E_In_Parameter)
28333 then
28334 Append_New_Elmt (Formal, Subp_Inputs);
28335 end if;
28336
28337 if Ekind_In (Formal, E_Generic_In_Out_Parameter,
28338 E_In_Out_Parameter,
28339 E_Out_Parameter)
28340 then
28341 Append_New_Elmt (Formal, Subp_Outputs);
28342
28343 -- Out parameters can act as inputs when the related type is
28344 -- tagged, unconstrained array, unconstrained record, or record
28345 -- with unconstrained components.
28346
28347 if Ekind (Formal) = E_Out_Parameter
28348 and then Is_Unconstrained_Or_Tagged_Item (Formal)
28349 then
28350 Append_New_Elmt (Formal, Subp_Inputs);
28351 end if;
28352 end if;
28353
28354 Next_Entity (Formal);
28355 end loop;
28356
28357 -- Otherwise the input denotes a task type, a task body, or the
28358 -- anonymous object created for a single task type.
28359
28360 elsif Ekind_In (Subp_Id, E_Task_Type, E_Task_Body)
28361 or else Is_Single_Task_Object (Subp_Id)
28362 then
28363 Subp_Decl := Declaration_Node (Subp_Id);
28364 Spec_Id := Unique_Defining_Entity (Subp_Decl);
28365 end if;
28366
28367 -- When processing an entry, subprogram or task body, look for pragmas
28368 -- Refined_Depends and Refined_Global as they specify the inputs and
28369 -- outputs.
28370
28371 if Is_Entry_Body (Subp_Id)
28372 or else Ekind_In (Subp_Id, E_Subprogram_Body, E_Task_Body)
28373 then
28374 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
28375 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
28376
28377 -- Subprogram declaration or stand alone body case, look for pragmas
28378 -- Depends and Global
28379
28380 else
28381 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
28382 Global := Get_Pragma (Spec_Id, Pragma_Global);
28383 end if;
28384
28385 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
28386 -- because it provides finer granularity of inputs and outputs.
28387
28388 if Present (Global) then
28389 Global_Seen := True;
28390 Collect_Global_List (Expression (Get_Argument (Global, Spec_Id)));
28391
28392 -- When the related subprogram lacks pragma [Refined_]Global, fall back
28393 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
28394 -- the inputs and outputs from [Refined_]Depends.
28395
28396 elsif Synthesize and then Present (Depends) then
28397 Clauses := Expression (Get_Argument (Depends, Spec_Id));
28398
28399 -- Multiple dependency clauses appear as an aggregate
28400
28401 if Nkind (Clauses) = N_Aggregate then
28402 Clause := First (Component_Associations (Clauses));
28403 while Present (Clause) loop
28404 Collect_Dependency_Clause (Clause);
28405 Next (Clause);
28406 end loop;
28407
28408 -- Otherwise this is a single dependency clause
28409
28410 else
28411 Collect_Dependency_Clause (Clauses);
28412 end if;
28413 end if;
28414
28415 -- The current instance of a protected type acts as a formal parameter
28416 -- of mode IN for functions and IN OUT for entries and procedures
28417 -- (SPARK RM 6.1.4).
28418
28419 if Ekind (Scope (Spec_Id)) = E_Protected_Type then
28420 Typ := Scope (Spec_Id);
28421
28422 -- Use the anonymous object when the type is single protected
28423
28424 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
28425 Typ := Anonymous_Object (Typ);
28426 end if;
28427
28428 Append_New_Elmt (Typ, Subp_Inputs);
28429
28430 if Ekind_In (Spec_Id, E_Entry, E_Entry_Family, E_Procedure) then
28431 Append_New_Elmt (Typ, Subp_Outputs);
28432 end if;
28433
28434 -- The current instance of a task type acts as a formal parameter of
28435 -- mode IN OUT (SPARK RM 6.1.4).
28436
28437 elsif Ekind (Spec_Id) = E_Task_Type then
28438 Typ := Spec_Id;
28439
28440 -- Use the anonymous object when the type is single task
28441
28442 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
28443 Typ := Anonymous_Object (Typ);
28444 end if;
28445
28446 Append_New_Elmt (Typ, Subp_Inputs);
28447 Append_New_Elmt (Typ, Subp_Outputs);
28448
28449 elsif Is_Single_Task_Object (Spec_Id) then
28450 Append_New_Elmt (Spec_Id, Subp_Inputs);
28451 Append_New_Elmt (Spec_Id, Subp_Outputs);
28452 end if;
28453 end Collect_Subprogram_Inputs_Outputs;
28454
28455 ---------------------------
28456 -- Contract_Freeze_Error --
28457 ---------------------------
28458
28459 procedure Contract_Freeze_Error
28460 (Contract_Id : Entity_Id;
28461 Freeze_Id : Entity_Id)
28462 is
28463 begin
28464 Error_Msg_Name_1 := Chars (Contract_Id);
28465 Error_Msg_Sloc := Sloc (Freeze_Id);
28466
28467 SPARK_Msg_NE
28468 ("body & declared # freezes the contract of%", Contract_Id, Freeze_Id);
28469 SPARK_Msg_N
28470 ("\all contractual items must be declared before body #", Contract_Id);
28471 end Contract_Freeze_Error;
28472
28473 ---------------------------------
28474 -- Delay_Config_Pragma_Analyze --
28475 ---------------------------------
28476
28477 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
28478 begin
28479 return Nam_In (Pragma_Name_Unmapped (N),
28480 Name_Interrupt_State, Name_Priority_Specific_Dispatching);
28481 end Delay_Config_Pragma_Analyze;
28482
28483 -----------------------
28484 -- Duplication_Error --
28485 -----------------------
28486
28487 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
28488 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
28489 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
28490
28491 begin
28492 Error_Msg_Sloc := Sloc (Prev);
28493 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
28494
28495 -- Emit a precise message to distinguish between source pragmas and
28496 -- pragmas generated from aspects. The ordering of the two pragmas is
28497 -- the following:
28498
28499 -- Prev -- ok
28500 -- Prag -- duplicate
28501
28502 -- No error is emitted when both pragmas come from aspects because this
28503 -- is already detected by the general aspect analysis mechanism.
28504
28505 if Prag_From_Asp and Prev_From_Asp then
28506 null;
28507 elsif Prag_From_Asp then
28508 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
28509 elsif Prev_From_Asp then
28510 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
28511 else
28512 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
28513 end if;
28514 end Duplication_Error;
28515
28516 ------------------------------
28517 -- Find_Encapsulating_State --
28518 ------------------------------
28519
28520 function Find_Encapsulating_State
28521 (States : Elist_Id;
28522 Constit_Id : Entity_Id) return Entity_Id
28523 is
28524 State_Id : Entity_Id;
28525
28526 begin
28527 -- Since a constituent may be part of a larger constituent set, climb
28528 -- the encapsulating state chain looking for a state that appears in
28529 -- States.
28530
28531 State_Id := Encapsulating_State (Constit_Id);
28532 while Present (State_Id) loop
28533 if Contains (States, State_Id) then
28534 return State_Id;
28535 end if;
28536
28537 State_Id := Encapsulating_State (State_Id);
28538 end loop;
28539
28540 return Empty;
28541 end Find_Encapsulating_State;
28542
28543 --------------------------
28544 -- Find_Related_Context --
28545 --------------------------
28546
28547 function Find_Related_Context
28548 (Prag : Node_Id;
28549 Do_Checks : Boolean := False) return Node_Id
28550 is
28551 Stmt : Node_Id;
28552
28553 begin
28554 Stmt := Prev (Prag);
28555 while Present (Stmt) loop
28556
28557 -- Skip prior pragmas, but check for duplicates
28558
28559 if Nkind (Stmt) = N_Pragma then
28560 if Do_Checks
28561 and then Pragma_Name (Stmt) = Pragma_Name (Prag)
28562 then
28563 Duplication_Error
28564 (Prag => Prag,
28565 Prev => Stmt);
28566 end if;
28567
28568 -- Skip internally generated code
28569
28570 elsif not Comes_From_Source (Stmt) then
28571
28572 -- The anonymous object created for a single concurrent type is a
28573 -- suitable context.
28574
28575 if Nkind (Stmt) = N_Object_Declaration
28576 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
28577 then
28578 return Stmt;
28579 end if;
28580
28581 -- Return the current source construct
28582
28583 else
28584 return Stmt;
28585 end if;
28586
28587 Prev (Stmt);
28588 end loop;
28589
28590 return Empty;
28591 end Find_Related_Context;
28592
28593 --------------------------------------
28594 -- Find_Related_Declaration_Or_Body --
28595 --------------------------------------
28596
28597 function Find_Related_Declaration_Or_Body
28598 (Prag : Node_Id;
28599 Do_Checks : Boolean := False) return Node_Id
28600 is
28601 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
28602
28603 procedure Expression_Function_Error;
28604 -- Emit an error concerning pragma Prag that illegaly applies to an
28605 -- expression function.
28606
28607 -------------------------------
28608 -- Expression_Function_Error --
28609 -------------------------------
28610
28611 procedure Expression_Function_Error is
28612 begin
28613 Error_Msg_Name_1 := Prag_Nam;
28614
28615 -- Emit a precise message to distinguish between source pragmas and
28616 -- pragmas generated from aspects.
28617
28618 if From_Aspect_Specification (Prag) then
28619 Error_Msg_N
28620 ("aspect % cannot apply to a stand alone expression function",
28621 Prag);
28622 else
28623 Error_Msg_N
28624 ("pragma % cannot apply to a stand alone expression function",
28625 Prag);
28626 end if;
28627 end Expression_Function_Error;
28628
28629 -- Local variables
28630
28631 Context : constant Node_Id := Parent (Prag);
28632 Stmt : Node_Id;
28633
28634 Look_For_Body : constant Boolean :=
28635 Nam_In (Prag_Nam, Name_Refined_Depends,
28636 Name_Refined_Global,
28637 Name_Refined_Post);
28638 -- Refinement pragmas must be associated with a subprogram body [stub]
28639
28640 -- Start of processing for Find_Related_Declaration_Or_Body
28641
28642 begin
28643 Stmt := Prev (Prag);
28644 while Present (Stmt) loop
28645
28646 -- Skip prior pragmas, but check for duplicates. Pragmas produced
28647 -- by splitting a complex pre/postcondition are not considered to
28648 -- be duplicates.
28649
28650 if Nkind (Stmt) = N_Pragma then
28651 if Do_Checks
28652 and then not Split_PPC (Stmt)
28653 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
28654 then
28655 Duplication_Error
28656 (Prag => Prag,
28657 Prev => Stmt);
28658 end if;
28659
28660 -- Emit an error when a refinement pragma appears on an expression
28661 -- function without a completion.
28662
28663 elsif Do_Checks
28664 and then Look_For_Body
28665 and then Nkind (Stmt) = N_Subprogram_Declaration
28666 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
28667 and then not Has_Completion (Defining_Entity (Stmt))
28668 then
28669 Expression_Function_Error;
28670 return Empty;
28671
28672 -- The refinement pragma applies to a subprogram body stub
28673
28674 elsif Look_For_Body
28675 and then Nkind (Stmt) = N_Subprogram_Body_Stub
28676 then
28677 return Stmt;
28678
28679 -- Skip internally generated code
28680
28681 elsif not Comes_From_Source (Stmt) then
28682
28683 -- The anonymous object created for a single concurrent type is a
28684 -- suitable context.
28685
28686 if Nkind (Stmt) = N_Object_Declaration
28687 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
28688 then
28689 return Stmt;
28690
28691 elsif Nkind (Stmt) = N_Subprogram_Declaration then
28692
28693 -- The subprogram declaration is an internally generated spec
28694 -- for an expression function.
28695
28696 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
28697 return Stmt;
28698
28699 -- The subprogram is actually an instance housed within an
28700 -- anonymous wrapper package.
28701
28702 elsif Present (Generic_Parent (Specification (Stmt))) then
28703 return Stmt;
28704 end if;
28705 end if;
28706
28707 -- Return the current construct which is either a subprogram body,
28708 -- a subprogram declaration or is illegal.
28709
28710 else
28711 return Stmt;
28712 end if;
28713
28714 Prev (Stmt);
28715 end loop;
28716
28717 -- If we fall through, then the pragma was either the first declaration
28718 -- or it was preceded by other pragmas and no source constructs.
28719
28720 -- The pragma is associated with a library-level subprogram
28721
28722 if Nkind (Context) = N_Compilation_Unit_Aux then
28723 return Unit (Parent (Context));
28724
28725 -- The pragma appears inside the declarations of an entry body
28726
28727 elsif Nkind (Context) = N_Entry_Body then
28728 return Context;
28729
28730 -- The pragma appears inside the statements of a subprogram body. This
28731 -- placement is the result of subprogram contract expansion.
28732
28733 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
28734 return Parent (Context);
28735
28736 -- The pragma appears inside the declarative part of a subprogram body
28737
28738 elsif Nkind (Context) = N_Subprogram_Body then
28739 return Context;
28740
28741 -- The pragma appears inside the declarative part of a task body
28742
28743 elsif Nkind (Context) = N_Task_Body then
28744 return Context;
28745
28746 -- The pragma is a byproduct of aspect expansion, return the related
28747 -- context of the original aspect. This case has a lower priority as
28748 -- the above circuitry pinpoints precisely the related context.
28749
28750 elsif Present (Corresponding_Aspect (Prag)) then
28751 return Parent (Corresponding_Aspect (Prag));
28752
28753 -- No candidate subprogram [body] found
28754
28755 else
28756 return Empty;
28757 end if;
28758 end Find_Related_Declaration_Or_Body;
28759
28760 ----------------------------------
28761 -- Find_Related_Package_Or_Body --
28762 ----------------------------------
28763
28764 function Find_Related_Package_Or_Body
28765 (Prag : Node_Id;
28766 Do_Checks : Boolean := False) return Node_Id
28767 is
28768 Context : constant Node_Id := Parent (Prag);
28769 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
28770 Stmt : Node_Id;
28771
28772 begin
28773 Stmt := Prev (Prag);
28774 while Present (Stmt) loop
28775
28776 -- Skip prior pragmas, but check for duplicates
28777
28778 if Nkind (Stmt) = N_Pragma then
28779 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
28780 Duplication_Error
28781 (Prag => Prag,
28782 Prev => Stmt);
28783 end if;
28784
28785 -- Skip internally generated code
28786
28787 elsif not Comes_From_Source (Stmt) then
28788 if Nkind (Stmt) = N_Subprogram_Declaration then
28789
28790 -- The subprogram declaration is an internally generated spec
28791 -- for an expression function.
28792
28793 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
28794 return Stmt;
28795
28796 -- The subprogram is actually an instance housed within an
28797 -- anonymous wrapper package.
28798
28799 elsif Present (Generic_Parent (Specification (Stmt))) then
28800 return Stmt;
28801 end if;
28802 end if;
28803
28804 -- Return the current source construct which is illegal
28805
28806 else
28807 return Stmt;
28808 end if;
28809
28810 Prev (Stmt);
28811 end loop;
28812
28813 -- If we fall through, then the pragma was either the first declaration
28814 -- or it was preceded by other pragmas and no source constructs.
28815
28816 -- The pragma is associated with a package. The immediate context in
28817 -- this case is the specification of the package.
28818
28819 if Nkind (Context) = N_Package_Specification then
28820 return Parent (Context);
28821
28822 -- The pragma appears in the declarations of a package body
28823
28824 elsif Nkind (Context) = N_Package_Body then
28825 return Context;
28826
28827 -- The pragma appears in the statements of a package body
28828
28829 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
28830 and then Nkind (Parent (Context)) = N_Package_Body
28831 then
28832 return Parent (Context);
28833
28834 -- The pragma is a byproduct of aspect expansion, return the related
28835 -- context of the original aspect. This case has a lower priority as
28836 -- the above circuitry pinpoints precisely the related context.
28837
28838 elsif Present (Corresponding_Aspect (Prag)) then
28839 return Parent (Corresponding_Aspect (Prag));
28840
28841 -- No candidate packge [body] found
28842
28843 else
28844 return Empty;
28845 end if;
28846 end Find_Related_Package_Or_Body;
28847
28848 ------------------
28849 -- Get_Argument --
28850 ------------------
28851
28852 function Get_Argument
28853 (Prag : Node_Id;
28854 Context_Id : Entity_Id := Empty) return Node_Id
28855 is
28856 Args : constant List_Id := Pragma_Argument_Associations (Prag);
28857
28858 begin
28859 -- Use the expression of the original aspect when compiling for ASIS or
28860 -- when analyzing the template of a generic unit. In both cases the
28861 -- aspect's tree must be decorated to allow for ASIS queries or to save
28862 -- the global references in the generic context.
28863
28864 if From_Aspect_Specification (Prag)
28865 and then (ASIS_Mode or else (Present (Context_Id)
28866 and then Is_Generic_Unit (Context_Id)))
28867 then
28868 return Corresponding_Aspect (Prag);
28869
28870 -- Otherwise use the expression of the pragma
28871
28872 elsif Present (Args) then
28873 return First (Args);
28874
28875 else
28876 return Empty;
28877 end if;
28878 end Get_Argument;
28879
28880 -------------------------
28881 -- Get_Base_Subprogram --
28882 -------------------------
28883
28884 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
28885 Result : Entity_Id;
28886
28887 begin
28888 -- Follow subprogram renaming chain
28889
28890 Result := Def_Id;
28891
28892 if Is_Subprogram (Result)
28893 and then
28894 Nkind (Parent (Declaration_Node (Result))) =
28895 N_Subprogram_Renaming_Declaration
28896 and then Present (Alias (Result))
28897 then
28898 Result := Alias (Result);
28899 end if;
28900
28901 return Result;
28902 end Get_Base_Subprogram;
28903
28904 -----------------------
28905 -- Get_SPARK_Mode_Type --
28906 -----------------------
28907
28908 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
28909 begin
28910 if N = Name_On then
28911 return On;
28912 elsif N = Name_Off then
28913 return Off;
28914
28915 -- Any other argument is illegal
28916
28917 else
28918 raise Program_Error;
28919 end if;
28920 end Get_SPARK_Mode_Type;
28921
28922 ------------------------------------
28923 -- Get_SPARK_Mode_From_Annotation --
28924 ------------------------------------
28925
28926 function Get_SPARK_Mode_From_Annotation
28927 (N : Node_Id) return SPARK_Mode_Type
28928 is
28929 Mode : Node_Id;
28930
28931 begin
28932 if Nkind (N) = N_Aspect_Specification then
28933 Mode := Expression (N);
28934
28935 else pragma Assert (Nkind (N) = N_Pragma);
28936 Mode := First (Pragma_Argument_Associations (N));
28937
28938 if Present (Mode) then
28939 Mode := Get_Pragma_Arg (Mode);
28940 end if;
28941 end if;
28942
28943 -- Aspect or pragma SPARK_Mode specifies an explicit mode
28944
28945 if Present (Mode) then
28946 if Nkind (Mode) = N_Identifier then
28947 return Get_SPARK_Mode_Type (Chars (Mode));
28948
28949 -- In case of a malformed aspect or pragma, return the default None
28950
28951 else
28952 return None;
28953 end if;
28954
28955 -- Otherwise the lack of an expression defaults SPARK_Mode to On
28956
28957 else
28958 return On;
28959 end if;
28960 end Get_SPARK_Mode_From_Annotation;
28961
28962 ---------------------------
28963 -- Has_Extra_Parentheses --
28964 ---------------------------
28965
28966 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
28967 Expr : Node_Id;
28968
28969 begin
28970 -- The aggregate should not have an expression list because a clause
28971 -- is always interpreted as a component association. The only way an
28972 -- expression list can sneak in is by adding extra parentheses around
28973 -- the individual clauses:
28974
28975 -- Depends (Output => Input) -- proper form
28976 -- Depends ((Output => Input)) -- extra parentheses
28977
28978 -- Since the extra parentheses are not allowed by the syntax of the
28979 -- pragma, flag them now to avoid emitting misleading errors down the
28980 -- line.
28981
28982 if Nkind (Clause) = N_Aggregate
28983 and then Present (Expressions (Clause))
28984 then
28985 Expr := First (Expressions (Clause));
28986 while Present (Expr) loop
28987
28988 -- A dependency clause surrounded by extra parentheses appears
28989 -- as an aggregate of component associations with an optional
28990 -- Paren_Count set.
28991
28992 if Nkind (Expr) = N_Aggregate
28993 and then Present (Component_Associations (Expr))
28994 then
28995 SPARK_Msg_N
28996 ("dependency clause contains extra parentheses", Expr);
28997
28998 -- Otherwise the expression is a malformed construct
28999
29000 else
29001 SPARK_Msg_N ("malformed dependency clause", Expr);
29002 end if;
29003
29004 Next (Expr);
29005 end loop;
29006
29007 return True;
29008 end if;
29009
29010 return False;
29011 end Has_Extra_Parentheses;
29012
29013 ----------------
29014 -- Initialize --
29015 ----------------
29016
29017 procedure Initialize is
29018 begin
29019 Externals.Init;
29020 end Initialize;
29021
29022 --------
29023 -- ip --
29024 --------
29025
29026 procedure ip is
29027 begin
29028 Dummy := Dummy + 1;
29029 end ip;
29030
29031 -----------------------------
29032 -- Is_Config_Static_String --
29033 -----------------------------
29034
29035 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
29036
29037 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
29038 -- This is an internal recursive function that is just like the outer
29039 -- function except that it adds the string to the name buffer rather
29040 -- than placing the string in the name buffer.
29041
29042 ------------------------------
29043 -- Add_Config_Static_String --
29044 ------------------------------
29045
29046 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
29047 N : Node_Id;
29048 C : Char_Code;
29049
29050 begin
29051 N := Arg;
29052
29053 if Nkind (N) = N_Op_Concat then
29054 if Add_Config_Static_String (Left_Opnd (N)) then
29055 N := Right_Opnd (N);
29056 else
29057 return False;
29058 end if;
29059 end if;
29060
29061 if Nkind (N) /= N_String_Literal then
29062 Error_Msg_N ("string literal expected for pragma argument", N);
29063 return False;
29064
29065 else
29066 for J in 1 .. String_Length (Strval (N)) loop
29067 C := Get_String_Char (Strval (N), J);
29068
29069 if not In_Character_Range (C) then
29070 Error_Msg
29071 ("string literal contains invalid wide character",
29072 Sloc (N) + 1 + Source_Ptr (J));
29073 return False;
29074 end if;
29075
29076 Add_Char_To_Name_Buffer (Get_Character (C));
29077 end loop;
29078 end if;
29079
29080 return True;
29081 end Add_Config_Static_String;
29082
29083 -- Start of processing for Is_Config_Static_String
29084
29085 begin
29086 Name_Len := 0;
29087
29088 return Add_Config_Static_String (Arg);
29089 end Is_Config_Static_String;
29090
29091 ---------------------
29092 -- Is_CCT_Instance --
29093 ---------------------
29094
29095 function Is_CCT_Instance
29096 (Ref_Id : Entity_Id;
29097 Context_Id : Entity_Id) return Boolean
29098 is
29099 S : Entity_Id;
29100 Typ : Entity_Id;
29101
29102 begin
29103 -- When the reference denotes a single protected type, the context is
29104 -- either a protected subprogram or its body.
29105
29106 if Is_Single_Protected_Object (Ref_Id) then
29107 Typ := Scope (Context_Id);
29108
29109 return
29110 Ekind (Typ) = E_Protected_Type
29111 and then Present (Anonymous_Object (Typ))
29112 and then Anonymous_Object (Typ) = Ref_Id;
29113
29114 -- When the reference denotes a single task type, the context is either
29115 -- the same type or if inside the body, the anonymous task type.
29116
29117 elsif Is_Single_Task_Object (Ref_Id) then
29118 if Ekind (Context_Id) = E_Task_Type then
29119 return
29120 Present (Anonymous_Object (Context_Id))
29121 and then Anonymous_Object (Context_Id) = Ref_Id;
29122 else
29123 return Ref_Id = Context_Id;
29124 end if;
29125
29126 -- Otherwise the reference denotes a protected or a task type. Climb the
29127 -- scope chain looking for an enclosing concurrent type that matches the
29128 -- referenced entity.
29129
29130 else
29131 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
29132
29133 S := Current_Scope;
29134 while Present (S) and then S /= Standard_Standard loop
29135 if Ekind_In (S, E_Protected_Type, E_Task_Type)
29136 and then S = Ref_Id
29137 then
29138 return True;
29139 end if;
29140
29141 S := Scope (S);
29142 end loop;
29143 end if;
29144
29145 return False;
29146 end Is_CCT_Instance;
29147
29148 -------------------------------
29149 -- Is_Elaboration_SPARK_Mode --
29150 -------------------------------
29151
29152 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
29153 begin
29154 pragma Assert
29155 (Nkind (N) = N_Pragma
29156 and then Pragma_Name (N) = Name_SPARK_Mode
29157 and then Is_List_Member (N));
29158
29159 -- Pragma SPARK_Mode affects the elaboration of a package body when it
29160 -- appears in the statement part of the body.
29161
29162 return
29163 Present (Parent (N))
29164 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
29165 and then List_Containing (N) = Statements (Parent (N))
29166 and then Present (Parent (Parent (N)))
29167 and then Nkind (Parent (Parent (N))) = N_Package_Body;
29168 end Is_Elaboration_SPARK_Mode;
29169
29170 -----------------------
29171 -- Is_Enabled_Pragma --
29172 -----------------------
29173
29174 function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is
29175 Arg : Node_Id;
29176
29177 begin
29178 if Present (Prag) then
29179 Arg := First (Pragma_Argument_Associations (Prag));
29180
29181 if Present (Arg) then
29182 return Is_True (Expr_Value (Get_Pragma_Arg (Arg)));
29183
29184 -- The lack of a Boolean argument automatically enables the pragma
29185
29186 else
29187 return True;
29188 end if;
29189
29190 -- The pragma is missing, therefore it is not enabled
29191
29192 else
29193 return False;
29194 end if;
29195 end Is_Enabled_Pragma;
29196
29197 -----------------------------------------
29198 -- Is_Non_Significant_Pragma_Reference --
29199 -----------------------------------------
29200
29201 -- This function makes use of the following static table which indicates
29202 -- whether appearance of some name in a given pragma is to be considered
29203 -- as a reference for the purposes of warnings about unreferenced objects.
29204
29205 -- -1 indicates that appearence in any argument is significant
29206 -- 0 indicates that appearance in any argument is not significant
29207 -- +n indicates that appearance as argument n is significant, but all
29208 -- other arguments are not significant
29209 -- 9n arguments from n on are significant, before n insignificant
29210
29211 Sig_Flags : constant array (Pragma_Id) of Int :=
29212 (Pragma_Abort_Defer => -1,
29213 Pragma_Abstract_State => -1,
29214 Pragma_Ada_83 => -1,
29215 Pragma_Ada_95 => -1,
29216 Pragma_Ada_05 => -1,
29217 Pragma_Ada_2005 => -1,
29218 Pragma_Ada_12 => -1,
29219 Pragma_Ada_2012 => -1,
29220 Pragma_All_Calls_Remote => -1,
29221 Pragma_Allow_Integer_Address => -1,
29222 Pragma_Annotate => 93,
29223 Pragma_Assert => -1,
29224 Pragma_Assert_And_Cut => -1,
29225 Pragma_Assertion_Policy => 0,
29226 Pragma_Assume => -1,
29227 Pragma_Assume_No_Invalid_Values => 0,
29228 Pragma_Async_Readers => 0,
29229 Pragma_Async_Writers => 0,
29230 Pragma_Asynchronous => 0,
29231 Pragma_Atomic => 0,
29232 Pragma_Atomic_Components => 0,
29233 Pragma_Attach_Handler => -1,
29234 Pragma_Attribute_Definition => 92,
29235 Pragma_Check => -1,
29236 Pragma_Check_Float_Overflow => 0,
29237 Pragma_Check_Name => 0,
29238 Pragma_Check_Policy => 0,
29239 Pragma_CPP_Class => 0,
29240 Pragma_CPP_Constructor => 0,
29241 Pragma_CPP_Virtual => 0,
29242 Pragma_CPP_Vtable => 0,
29243 Pragma_CPU => -1,
29244 Pragma_C_Pass_By_Copy => 0,
29245 Pragma_Comment => -1,
29246 Pragma_Common_Object => 0,
29247 Pragma_Compile_Time_Error => -1,
29248 Pragma_Compile_Time_Warning => -1,
29249 Pragma_Compiler_Unit => -1,
29250 Pragma_Compiler_Unit_Warning => -1,
29251 Pragma_Complete_Representation => 0,
29252 Pragma_Complex_Representation => 0,
29253 Pragma_Component_Alignment => 0,
29254 Pragma_Constant_After_Elaboration => 0,
29255 Pragma_Contract_Cases => -1,
29256 Pragma_Controlled => 0,
29257 Pragma_Convention => 0,
29258 Pragma_Convention_Identifier => 0,
29259 Pragma_Deadline_Floor => -1,
29260 Pragma_Debug => -1,
29261 Pragma_Debug_Policy => 0,
29262 Pragma_Detect_Blocking => 0,
29263 Pragma_Default_Initial_Condition => -1,
29264 Pragma_Default_Scalar_Storage_Order => 0,
29265 Pragma_Default_Storage_Pool => 0,
29266 Pragma_Depends => -1,
29267 Pragma_Disable_Atomic_Synchronization => 0,
29268 Pragma_Discard_Names => 0,
29269 Pragma_Dispatching_Domain => -1,
29270 Pragma_Effective_Reads => 0,
29271 Pragma_Effective_Writes => 0,
29272 Pragma_Elaborate => 0,
29273 Pragma_Elaborate_All => 0,
29274 Pragma_Elaborate_Body => 0,
29275 Pragma_Elaboration_Checks => 0,
29276 Pragma_Eliminate => 0,
29277 Pragma_Enable_Atomic_Synchronization => 0,
29278 Pragma_Export => -1,
29279 Pragma_Export_Function => -1,
29280 Pragma_Export_Object => -1,
29281 Pragma_Export_Procedure => -1,
29282 Pragma_Export_Value => -1,
29283 Pragma_Export_Valued_Procedure => -1,
29284 Pragma_Extend_System => -1,
29285 Pragma_Extensions_Allowed => 0,
29286 Pragma_Extensions_Visible => 0,
29287 Pragma_External => -1,
29288 Pragma_Favor_Top_Level => 0,
29289 Pragma_External_Name_Casing => 0,
29290 Pragma_Fast_Math => 0,
29291 Pragma_Finalize_Storage_Only => 0,
29292 Pragma_Ghost => 0,
29293 Pragma_Global => -1,
29294 Pragma_Ident => -1,
29295 Pragma_Ignore_Pragma => 0,
29296 Pragma_Implementation_Defined => -1,
29297 Pragma_Implemented => -1,
29298 Pragma_Implicit_Packing => 0,
29299 Pragma_Import => 93,
29300 Pragma_Import_Function => 0,
29301 Pragma_Import_Object => 0,
29302 Pragma_Import_Procedure => 0,
29303 Pragma_Import_Valued_Procedure => 0,
29304 Pragma_Independent => 0,
29305 Pragma_Independent_Components => 0,
29306 Pragma_Initial_Condition => -1,
29307 Pragma_Initialize_Scalars => 0,
29308 Pragma_Initializes => -1,
29309 Pragma_Inline => 0,
29310 Pragma_Inline_Always => 0,
29311 Pragma_Inline_Generic => 0,
29312 Pragma_Inspection_Point => -1,
29313 Pragma_Interface => 92,
29314 Pragma_Interface_Name => 0,
29315 Pragma_Interrupt_Handler => -1,
29316 Pragma_Interrupt_Priority => -1,
29317 Pragma_Interrupt_State => -1,
29318 Pragma_Invariant => -1,
29319 Pragma_Keep_Names => 0,
29320 Pragma_License => 0,
29321 Pragma_Link_With => -1,
29322 Pragma_Linker_Alias => -1,
29323 Pragma_Linker_Constructor => -1,
29324 Pragma_Linker_Destructor => -1,
29325 Pragma_Linker_Options => -1,
29326 Pragma_Linker_Section => 0,
29327 Pragma_List => 0,
29328 Pragma_Lock_Free => 0,
29329 Pragma_Locking_Policy => 0,
29330 Pragma_Loop_Invariant => -1,
29331 Pragma_Loop_Optimize => 0,
29332 Pragma_Loop_Variant => -1,
29333 Pragma_Machine_Attribute => -1,
29334 Pragma_Main => -1,
29335 Pragma_Main_Storage => -1,
29336 Pragma_Max_Queue_Length => 0,
29337 Pragma_Memory_Size => 0,
29338 Pragma_No_Return => 0,
29339 Pragma_No_Body => 0,
29340 Pragma_No_Component_Reordering => -1,
29341 Pragma_No_Elaboration_Code_All => 0,
29342 Pragma_No_Heap_Finalization => 0,
29343 Pragma_No_Inline => 0,
29344 Pragma_No_Run_Time => -1,
29345 Pragma_No_Strict_Aliasing => -1,
29346 Pragma_No_Tagged_Streams => 0,
29347 Pragma_Normalize_Scalars => 0,
29348 Pragma_Obsolescent => 0,
29349 Pragma_Optimize => 0,
29350 Pragma_Optimize_Alignment => 0,
29351 Pragma_Overflow_Mode => 0,
29352 Pragma_Overriding_Renamings => 0,
29353 Pragma_Ordered => 0,
29354 Pragma_Pack => 0,
29355 Pragma_Page => 0,
29356 Pragma_Part_Of => 0,
29357 Pragma_Partition_Elaboration_Policy => 0,
29358 Pragma_Passive => 0,
29359 Pragma_Persistent_BSS => 0,
29360 Pragma_Polling => 0,
29361 Pragma_Prefix_Exception_Messages => 0,
29362 Pragma_Post => -1,
29363 Pragma_Postcondition => -1,
29364 Pragma_Post_Class => -1,
29365 Pragma_Pre => -1,
29366 Pragma_Precondition => -1,
29367 Pragma_Predicate => -1,
29368 Pragma_Predicate_Failure => -1,
29369 Pragma_Preelaborable_Initialization => -1,
29370 Pragma_Preelaborate => 0,
29371 Pragma_Pre_Class => -1,
29372 Pragma_Priority => -1,
29373 Pragma_Priority_Specific_Dispatching => 0,
29374 Pragma_Profile => 0,
29375 Pragma_Profile_Warnings => 0,
29376 Pragma_Propagate_Exceptions => 0,
29377 Pragma_Provide_Shift_Operators => 0,
29378 Pragma_Psect_Object => 0,
29379 Pragma_Pure => 0,
29380 Pragma_Pure_Function => 0,
29381 Pragma_Queuing_Policy => 0,
29382 Pragma_Rational => 0,
29383 Pragma_Ravenscar => 0,
29384 Pragma_Refined_Depends => -1,
29385 Pragma_Refined_Global => -1,
29386 Pragma_Refined_Post => -1,
29387 Pragma_Refined_State => -1,
29388 Pragma_Relative_Deadline => 0,
29389 Pragma_Rename_Pragma => 0,
29390 Pragma_Remote_Access_Type => -1,
29391 Pragma_Remote_Call_Interface => -1,
29392 Pragma_Remote_Types => -1,
29393 Pragma_Restricted_Run_Time => 0,
29394 Pragma_Restriction_Warnings => 0,
29395 Pragma_Restrictions => 0,
29396 Pragma_Reviewable => -1,
29397 Pragma_Secondary_Stack_Size => -1,
29398 Pragma_Short_Circuit_And_Or => 0,
29399 Pragma_Share_Generic => 0,
29400 Pragma_Shared => 0,
29401 Pragma_Shared_Passive => 0,
29402 Pragma_Short_Descriptors => 0,
29403 Pragma_Simple_Storage_Pool_Type => 0,
29404 Pragma_Source_File_Name => 0,
29405 Pragma_Source_File_Name_Project => 0,
29406 Pragma_Source_Reference => 0,
29407 Pragma_SPARK_Mode => 0,
29408 Pragma_Storage_Size => -1,
29409 Pragma_Storage_Unit => 0,
29410 Pragma_Static_Elaboration_Desired => 0,
29411 Pragma_Stream_Convert => 0,
29412 Pragma_Style_Checks => 0,
29413 Pragma_Subtitle => 0,
29414 Pragma_Suppress => 0,
29415 Pragma_Suppress_Exception_Locations => 0,
29416 Pragma_Suppress_All => 0,
29417 Pragma_Suppress_Debug_Info => 0,
29418 Pragma_Suppress_Initialization => 0,
29419 Pragma_System_Name => 0,
29420 Pragma_Task_Dispatching_Policy => 0,
29421 Pragma_Task_Info => -1,
29422 Pragma_Task_Name => -1,
29423 Pragma_Task_Storage => -1,
29424 Pragma_Test_Case => -1,
29425 Pragma_Thread_Local_Storage => -1,
29426 Pragma_Time_Slice => -1,
29427 Pragma_Title => 0,
29428 Pragma_Type_Invariant => -1,
29429 Pragma_Type_Invariant_Class => -1,
29430 Pragma_Unchecked_Union => 0,
29431 Pragma_Unevaluated_Use_Of_Old => 0,
29432 Pragma_Unimplemented_Unit => 0,
29433 Pragma_Universal_Aliasing => 0,
29434 Pragma_Universal_Data => 0,
29435 Pragma_Unmodified => 0,
29436 Pragma_Unreferenced => 0,
29437 Pragma_Unreferenced_Objects => 0,
29438 Pragma_Unreserve_All_Interrupts => 0,
29439 Pragma_Unsuppress => 0,
29440 Pragma_Unused => 0,
29441 Pragma_Use_VADS_Size => 0,
29442 Pragma_Validity_Checks => 0,
29443 Pragma_Volatile => 0,
29444 Pragma_Volatile_Components => 0,
29445 Pragma_Volatile_Full_Access => 0,
29446 Pragma_Volatile_Function => 0,
29447 Pragma_Warning_As_Error => 0,
29448 Pragma_Warnings => 0,
29449 Pragma_Weak_External => 0,
29450 Pragma_Wide_Character_Encoding => 0,
29451 Unknown_Pragma => 0);
29452
29453 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
29454 Id : Pragma_Id;
29455 P : Node_Id;
29456 C : Int;
29457 AN : Nat;
29458
29459 function Arg_No return Nat;
29460 -- Returns an integer showing what argument we are in. A value of
29461 -- zero means we are not in any of the arguments.
29462
29463 ------------
29464 -- Arg_No --
29465 ------------
29466
29467 function Arg_No return Nat is
29468 A : Node_Id;
29469 N : Nat;
29470
29471 begin
29472 A := First (Pragma_Argument_Associations (Parent (P)));
29473 N := 1;
29474 loop
29475 if No (A) then
29476 return 0;
29477 elsif A = P then
29478 return N;
29479 end if;
29480
29481 Next (A);
29482 N := N + 1;
29483 end loop;
29484 end Arg_No;
29485
29486 -- Start of processing for Non_Significant_Pragma_Reference
29487
29488 begin
29489 P := Parent (N);
29490
29491 if Nkind (P) /= N_Pragma_Argument_Association then
29492 return False;
29493
29494 else
29495 Id := Get_Pragma_Id (Parent (P));
29496 C := Sig_Flags (Id);
29497 AN := Arg_No;
29498
29499 if AN = 0 then
29500 return False;
29501 end if;
29502
29503 case C is
29504 when -1 =>
29505 return False;
29506
29507 when 0 =>
29508 return True;
29509
29510 when 92 .. 99 =>
29511 return AN < (C - 90);
29512
29513 when others =>
29514 return AN /= C;
29515 end case;
29516 end if;
29517 end Is_Non_Significant_Pragma_Reference;
29518
29519 ------------------------------
29520 -- Is_Pragma_String_Literal --
29521 ------------------------------
29522
29523 -- This function returns true if the corresponding pragma argument is a
29524 -- static string expression. These are the only cases in which string
29525 -- literals can appear as pragma arguments. We also allow a string literal
29526 -- as the first argument to pragma Assert (although it will of course
29527 -- always generate a type error).
29528
29529 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
29530 Pragn : constant Node_Id := Parent (Par);
29531 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
29532 Pname : constant Name_Id := Pragma_Name (Pragn);
29533 Argn : Natural;
29534 N : Node_Id;
29535
29536 begin
29537 Argn := 1;
29538 N := First (Assoc);
29539 loop
29540 exit when N = Par;
29541 Argn := Argn + 1;
29542 Next (N);
29543 end loop;
29544
29545 if Pname = Name_Assert then
29546 return True;
29547
29548 elsif Pname = Name_Export then
29549 return Argn > 2;
29550
29551 elsif Pname = Name_Ident then
29552 return Argn = 1;
29553
29554 elsif Pname = Name_Import then
29555 return Argn > 2;
29556
29557 elsif Pname = Name_Interface_Name then
29558 return Argn > 1;
29559
29560 elsif Pname = Name_Linker_Alias then
29561 return Argn = 2;
29562
29563 elsif Pname = Name_Linker_Section then
29564 return Argn = 2;
29565
29566 elsif Pname = Name_Machine_Attribute then
29567 return Argn = 2;
29568
29569 elsif Pname = Name_Source_File_Name then
29570 return True;
29571
29572 elsif Pname = Name_Source_Reference then
29573 return Argn = 2;
29574
29575 elsif Pname = Name_Title then
29576 return True;
29577
29578 elsif Pname = Name_Subtitle then
29579 return True;
29580
29581 else
29582 return False;
29583 end if;
29584 end Is_Pragma_String_Literal;
29585
29586 ---------------------------
29587 -- Is_Private_SPARK_Mode --
29588 ---------------------------
29589
29590 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
29591 begin
29592 pragma Assert
29593 (Nkind (N) = N_Pragma
29594 and then Pragma_Name (N) = Name_SPARK_Mode
29595 and then Is_List_Member (N));
29596
29597 -- For pragma SPARK_Mode to be private, it has to appear in the private
29598 -- declarations of a package.
29599
29600 return
29601 Present (Parent (N))
29602 and then Nkind (Parent (N)) = N_Package_Specification
29603 and then List_Containing (N) = Private_Declarations (Parent (N));
29604 end Is_Private_SPARK_Mode;
29605
29606 -------------------------------------
29607 -- Is_Unconstrained_Or_Tagged_Item --
29608 -------------------------------------
29609
29610 function Is_Unconstrained_Or_Tagged_Item
29611 (Item : Entity_Id) return Boolean
29612 is
29613 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
29614 -- Determine whether record type Typ has at least one unconstrained
29615 -- component.
29616
29617 ---------------------------------
29618 -- Has_Unconstrained_Component --
29619 ---------------------------------
29620
29621 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
29622 Comp : Entity_Id;
29623
29624 begin
29625 Comp := First_Component (Typ);
29626 while Present (Comp) loop
29627 if Is_Unconstrained_Or_Tagged_Item (Comp) then
29628 return True;
29629 end if;
29630
29631 Next_Component (Comp);
29632 end loop;
29633
29634 return False;
29635 end Has_Unconstrained_Component;
29636
29637 -- Local variables
29638
29639 Typ : constant Entity_Id := Etype (Item);
29640
29641 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
29642
29643 begin
29644 if Is_Tagged_Type (Typ) then
29645 return True;
29646
29647 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
29648 return True;
29649
29650 elsif Is_Record_Type (Typ) then
29651 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
29652 return True;
29653 else
29654 return Has_Unconstrained_Component (Typ);
29655 end if;
29656
29657 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
29658 return True;
29659
29660 else
29661 return False;
29662 end if;
29663 end Is_Unconstrained_Or_Tagged_Item;
29664
29665 -----------------------------
29666 -- Is_Valid_Assertion_Kind --
29667 -----------------------------
29668
29669 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
29670 begin
29671 case Nam is
29672 when
29673 -- RM defined
29674
29675 Name_Assert
29676 | Name_Assertion_Policy
29677 | Name_Static_Predicate
29678 | Name_Dynamic_Predicate
29679 | Name_Pre
29680 | Name_uPre
29681 | Name_Post
29682 | Name_uPost
29683 | Name_Type_Invariant
29684 | Name_uType_Invariant
29685
29686 -- Impl defined
29687
29688 | Name_Assert_And_Cut
29689 | Name_Assume
29690 | Name_Contract_Cases
29691 | Name_Debug
29692 | Name_Default_Initial_Condition
29693 | Name_Ghost
29694 | Name_Initial_Condition
29695 | Name_Invariant
29696 | Name_uInvariant
29697 | Name_Loop_Invariant
29698 | Name_Loop_Variant
29699 | Name_Postcondition
29700 | Name_Precondition
29701 | Name_Predicate
29702 | Name_Refined_Post
29703 | Name_Statement_Assertions
29704 =>
29705 return True;
29706
29707 when others =>
29708 return False;
29709 end case;
29710 end Is_Valid_Assertion_Kind;
29711
29712 --------------------------------------
29713 -- Process_Compilation_Unit_Pragmas --
29714 --------------------------------------
29715
29716 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
29717 begin
29718 -- A special check for pragma Suppress_All, a very strange DEC pragma,
29719 -- strange because it comes at the end of the unit. Rational has the
29720 -- same name for a pragma, but treats it as a program unit pragma, In
29721 -- GNAT we just decide to allow it anywhere at all. If it appeared then
29722 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
29723 -- node, and we insert a pragma Suppress (All_Checks) at the start of
29724 -- the context clause to ensure the correct processing.
29725
29726 if Has_Pragma_Suppress_All (N) then
29727 Prepend_To (Context_Items (N),
29728 Make_Pragma (Sloc (N),
29729 Chars => Name_Suppress,
29730 Pragma_Argument_Associations => New_List (
29731 Make_Pragma_Argument_Association (Sloc (N),
29732 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
29733 end if;
29734
29735 -- Nothing else to do at the current time
29736
29737 end Process_Compilation_Unit_Pragmas;
29738
29739 -------------------------------------------
29740 -- Process_Compile_Time_Warning_Or_Error --
29741 -------------------------------------------
29742
29743 procedure Process_Compile_Time_Warning_Or_Error
29744 (N : Node_Id;
29745 Eloc : Source_Ptr)
29746 is
29747 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
29748 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
29749 Arg2 : constant Node_Id := Next (Arg1);
29750
29751 begin
29752 Analyze_And_Resolve (Arg1x, Standard_Boolean);
29753
29754 if Compile_Time_Known_Value (Arg1x) then
29755 if Is_True (Expr_Value (Arg1x)) then
29756 declare
29757 Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
29758 Pname : constant Name_Id := Pragma_Name_Unmapped (N);
29759 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
29760 Str : constant String_Id := Strval (Get_Pragma_Arg (Arg2));
29761 Str_Len : constant Nat := String_Length (Str);
29762
29763 Force : constant Boolean :=
29764 Prag_Id = Pragma_Compile_Time_Warning
29765 and then Is_Spec_Name (Unit_Name (Current_Sem_Unit))
29766 and then (Ekind (Cent) /= E_Package
29767 or else not In_Private_Part (Cent));
29768 -- Set True if this is the warning case, and we are in the
29769 -- visible part of a package spec, or in a subprogram spec,
29770 -- in which case we want to force the client to see the
29771 -- warning, even though it is not in the main unit.
29772
29773 C : Character;
29774 CC : Char_Code;
29775 Cont : Boolean;
29776 Ptr : Nat;
29777
29778 begin
29779 -- Loop through segments of message separated by line feeds.
29780 -- We output these segments as separate messages with
29781 -- continuation marks for all but the first.
29782
29783 Cont := False;
29784 Ptr := 1;
29785 loop
29786 Error_Msg_Strlen := 0;
29787
29788 -- Loop to copy characters from argument to error message
29789 -- string buffer.
29790
29791 loop
29792 exit when Ptr > Str_Len;
29793 CC := Get_String_Char (Str, Ptr);
29794 Ptr := Ptr + 1;
29795
29796 -- Ignore wide chars ??? else store character
29797
29798 if In_Character_Range (CC) then
29799 C := Get_Character (CC);
29800 exit when C = ASCII.LF;
29801 Error_Msg_Strlen := Error_Msg_Strlen + 1;
29802 Error_Msg_String (Error_Msg_Strlen) := C;
29803 end if;
29804 end loop;
29805
29806 -- Here with one line ready to go
29807
29808 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
29809
29810 -- If this is a warning in a spec, then we want clients
29811 -- to see the warning, so mark the message with the
29812 -- special sequence !! to force the warning. In the case
29813 -- of a package spec, we do not force this if we are in
29814 -- the private part of the spec.
29815
29816 if Force then
29817 if Cont = False then
29818 Error_Msg ("<<~!!", Eloc);
29819 Cont := True;
29820 else
29821 Error_Msg ("\<<~!!", Eloc);
29822 end if;
29823
29824 -- Error, rather than warning, or in a body, so we do not
29825 -- need to force visibility for client (error will be
29826 -- output in any case, and this is the situation in which
29827 -- we do not want a client to get a warning, since the
29828 -- warning is in the body or the spec private part).
29829
29830 else
29831 if Cont = False then
29832 Error_Msg ("<<~", Eloc);
29833 Cont := True;
29834 else
29835 Error_Msg ("\<<~", Eloc);
29836 end if;
29837 end if;
29838
29839 exit when Ptr > Str_Len;
29840 end loop;
29841 end;
29842 end if;
29843 end if;
29844 end Process_Compile_Time_Warning_Or_Error;
29845
29846 ------------------------------------
29847 -- Record_Possible_Body_Reference --
29848 ------------------------------------
29849
29850 procedure Record_Possible_Body_Reference
29851 (State_Id : Entity_Id;
29852 Ref : Node_Id)
29853 is
29854 Context : Node_Id;
29855 Spec_Id : Entity_Id;
29856
29857 begin
29858 -- Ensure that we are dealing with a reference to a state
29859
29860 pragma Assert (Ekind (State_Id) = E_Abstract_State);
29861
29862 -- Climb the tree starting from the reference looking for a package body
29863 -- whose spec declares the referenced state. This criteria automatically
29864 -- excludes references in package specs which are legal. Note that it is
29865 -- not wise to emit an error now as the package body may lack pragma
29866 -- Refined_State or the referenced state may not be mentioned in the
29867 -- refinement. This approach avoids the generation of misleading errors.
29868
29869 Context := Ref;
29870 while Present (Context) loop
29871 if Nkind (Context) = N_Package_Body then
29872 Spec_Id := Corresponding_Spec (Context);
29873
29874 if Present (Abstract_States (Spec_Id))
29875 and then Contains (Abstract_States (Spec_Id), State_Id)
29876 then
29877 if No (Body_References (State_Id)) then
29878 Set_Body_References (State_Id, New_Elmt_List);
29879 end if;
29880
29881 Append_Elmt (Ref, To => Body_References (State_Id));
29882 exit;
29883 end if;
29884 end if;
29885
29886 Context := Parent (Context);
29887 end loop;
29888 end Record_Possible_Body_Reference;
29889
29890 ------------------------------------------
29891 -- Relocate_Pragmas_To_Anonymous_Object --
29892 ------------------------------------------
29893
29894 procedure Relocate_Pragmas_To_Anonymous_Object
29895 (Typ_Decl : Node_Id;
29896 Obj_Decl : Node_Id)
29897 is
29898 Decl : Node_Id;
29899 Def : Node_Id;
29900 Next_Decl : Node_Id;
29901
29902 begin
29903 if Nkind (Typ_Decl) = N_Protected_Type_Declaration then
29904 Def := Protected_Definition (Typ_Decl);
29905 else
29906 pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration);
29907 Def := Task_Definition (Typ_Decl);
29908 end if;
29909
29910 -- The concurrent definition has a visible declaration list. Inspect it
29911 -- and relocate all canidate pragmas.
29912
29913 if Present (Def) and then Present (Visible_Declarations (Def)) then
29914 Decl := First (Visible_Declarations (Def));
29915 while Present (Decl) loop
29916
29917 -- Preserve the following declaration for iteration purposes due
29918 -- to possible relocation of a pragma.
29919
29920 Next_Decl := Next (Decl);
29921
29922 if Nkind (Decl) = N_Pragma
29923 and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl))
29924 then
29925 Remove (Decl);
29926 Insert_After (Obj_Decl, Decl);
29927
29928 -- Skip internally generated code
29929
29930 elsif not Comes_From_Source (Decl) then
29931 null;
29932
29933 -- No candidate pragmas are available for relocation
29934
29935 else
29936 exit;
29937 end if;
29938
29939 Decl := Next_Decl;
29940 end loop;
29941 end if;
29942 end Relocate_Pragmas_To_Anonymous_Object;
29943
29944 ------------------------------
29945 -- Relocate_Pragmas_To_Body --
29946 ------------------------------
29947
29948 procedure Relocate_Pragmas_To_Body
29949 (Subp_Body : Node_Id;
29950 Target_Body : Node_Id := Empty)
29951 is
29952 procedure Relocate_Pragma (Prag : Node_Id);
29953 -- Remove a single pragma from its current list and add it to the
29954 -- declarations of the proper body (either Subp_Body or Target_Body).
29955
29956 ---------------------
29957 -- Relocate_Pragma --
29958 ---------------------
29959
29960 procedure Relocate_Pragma (Prag : Node_Id) is
29961 Decls : List_Id;
29962 Target : Node_Id;
29963
29964 begin
29965 -- When subprogram stubs or expression functions are involves, the
29966 -- destination declaration list belongs to the proper body.
29967
29968 if Present (Target_Body) then
29969 Target := Target_Body;
29970 else
29971 Target := Subp_Body;
29972 end if;
29973
29974 Decls := Declarations (Target);
29975
29976 if No (Decls) then
29977 Decls := New_List;
29978 Set_Declarations (Target, Decls);
29979 end if;
29980
29981 -- Unhook the pragma from its current list
29982
29983 Remove (Prag);
29984 Prepend (Prag, Decls);
29985 end Relocate_Pragma;
29986
29987 -- Local variables
29988
29989 Body_Id : constant Entity_Id :=
29990 Defining_Unit_Name (Specification (Subp_Body));
29991 Next_Stmt : Node_Id;
29992 Stmt : Node_Id;
29993
29994 -- Start of processing for Relocate_Pragmas_To_Body
29995
29996 begin
29997 -- Do not process a body that comes from a separate unit as no construct
29998 -- can possibly follow it.
29999
30000 if not Is_List_Member (Subp_Body) then
30001 return;
30002
30003 -- Do not relocate pragmas that follow a stub if the stub does not have
30004 -- a proper body.
30005
30006 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
30007 and then No (Target_Body)
30008 then
30009 return;
30010
30011 -- Do not process internally generated routine _Postconditions
30012
30013 elsif Ekind (Body_Id) = E_Procedure
30014 and then Chars (Body_Id) = Name_uPostconditions
30015 then
30016 return;
30017 end if;
30018
30019 -- Look at what is following the body. We are interested in certain kind
30020 -- of pragmas (either from source or byproducts of expansion) that can
30021 -- apply to a body [stub].
30022
30023 Stmt := Next (Subp_Body);
30024 while Present (Stmt) loop
30025
30026 -- Preserve the following statement for iteration purposes due to a
30027 -- possible relocation of a pragma.
30028
30029 Next_Stmt := Next (Stmt);
30030
30031 -- Move a candidate pragma following the body to the declarations of
30032 -- the body.
30033
30034 if Nkind (Stmt) = N_Pragma
30035 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
30036 then
30037
30038 -- If a source pragma Warnings follows the body, it applies to
30039 -- following statements and does not belong in the body.
30040
30041 if Get_Pragma_Id (Stmt) = Pragma_Warnings
30042 and then Comes_From_Source (Stmt)
30043 then
30044 null;
30045 else
30046 Relocate_Pragma (Stmt);
30047 end if;
30048
30049 -- Skip internally generated code
30050
30051 elsif not Comes_From_Source (Stmt) then
30052 null;
30053
30054 -- No candidate pragmas are available for relocation
30055
30056 else
30057 exit;
30058 end if;
30059
30060 Stmt := Next_Stmt;
30061 end loop;
30062 end Relocate_Pragmas_To_Body;
30063
30064 -------------------
30065 -- Resolve_State --
30066 -------------------
30067
30068 procedure Resolve_State (N : Node_Id) is
30069 Func : Entity_Id;
30070 State : Entity_Id;
30071
30072 begin
30073 if Is_Entity_Name (N) and then Present (Entity (N)) then
30074 Func := Entity (N);
30075
30076 -- Handle overloading of state names by functions. Traverse the
30077 -- homonym chain looking for an abstract state.
30078
30079 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
30080 State := Homonym (Func);
30081 while Present (State) loop
30082
30083 -- Resolve the overloading by setting the proper entity of the
30084 -- reference to that of the state.
30085
30086 if Ekind (State) = E_Abstract_State then
30087 Set_Etype (N, Standard_Void_Type);
30088 Set_Entity (N, State);
30089 Set_Associated_Node (N, State);
30090 return;
30091 end if;
30092
30093 State := Homonym (State);
30094 end loop;
30095
30096 -- A function can never act as a state. If the homonym chain does
30097 -- not contain a corresponding state, then something went wrong in
30098 -- the overloading mechanism.
30099
30100 raise Program_Error;
30101 end if;
30102 end if;
30103 end Resolve_State;
30104
30105 ----------------------------
30106 -- Rewrite_Assertion_Kind --
30107 ----------------------------
30108
30109 procedure Rewrite_Assertion_Kind
30110 (N : Node_Id;
30111 From_Policy : Boolean := False)
30112 is
30113 Nam : Name_Id;
30114
30115 begin
30116 Nam := No_Name;
30117 if Nkind (N) = N_Attribute_Reference
30118 and then Attribute_Name (N) = Name_Class
30119 and then Nkind (Prefix (N)) = N_Identifier
30120 then
30121 case Chars (Prefix (N)) is
30122 when Name_Pre =>
30123 Nam := Name_uPre;
30124
30125 when Name_Post =>
30126 Nam := Name_uPost;
30127
30128 when Name_Type_Invariant =>
30129 Nam := Name_uType_Invariant;
30130
30131 when Name_Invariant =>
30132 Nam := Name_uInvariant;
30133
30134 when others =>
30135 return;
30136 end case;
30137
30138 -- Recommend standard use of aspect names Pre/Post
30139
30140 elsif Nkind (N) = N_Identifier
30141 and then From_Policy
30142 and then Serious_Errors_Detected = 0
30143 and then not ASIS_Mode
30144 then
30145 if Chars (N) = Name_Precondition
30146 or else Chars (N) = Name_Postcondition
30147 then
30148 Error_Msg_N ("Check_Policy is a non-standard pragma??", N);
30149 Error_Msg_N
30150 ("\use Assertion_Policy and aspect names Pre/Post for "
30151 & "Ada2012 conformance?", N);
30152 end if;
30153
30154 return;
30155 end if;
30156
30157 if Nam /= No_Name then
30158 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
30159 end if;
30160 end Rewrite_Assertion_Kind;
30161
30162 --------
30163 -- rv --
30164 --------
30165
30166 procedure rv is
30167 begin
30168 Dummy := Dummy + 1;
30169 end rv;
30170
30171 --------------------------------
30172 -- Set_Encoded_Interface_Name --
30173 --------------------------------
30174
30175 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
30176 Str : constant String_Id := Strval (S);
30177 Len : constant Nat := String_Length (Str);
30178 CC : Char_Code;
30179 C : Character;
30180 J : Pos;
30181
30182 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
30183
30184 procedure Encode;
30185 -- Stores encoded value of character code CC. The encoding we use an
30186 -- underscore followed by four lower case hex digits.
30187
30188 ------------
30189 -- Encode --
30190 ------------
30191
30192 procedure Encode is
30193 begin
30194 Store_String_Char (Get_Char_Code ('_'));
30195 Store_String_Char
30196 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
30197 Store_String_Char
30198 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
30199 Store_String_Char
30200 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
30201 Store_String_Char
30202 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
30203 end Encode;
30204
30205 -- Start of processing for Set_Encoded_Interface_Name
30206
30207 begin
30208 -- If first character is asterisk, this is a link name, and we leave it
30209 -- completely unmodified. We also ignore null strings (the latter case
30210 -- happens only in error cases).
30211
30212 if Len = 0
30213 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
30214 then
30215 Set_Interface_Name (E, S);
30216
30217 else
30218 J := 1;
30219 loop
30220 CC := Get_String_Char (Str, J);
30221
30222 exit when not In_Character_Range (CC);
30223
30224 C := Get_Character (CC);
30225
30226 exit when C /= '_' and then C /= '$'
30227 and then C not in '0' .. '9'
30228 and then C not in 'a' .. 'z'
30229 and then C not in 'A' .. 'Z';
30230
30231 if J = Len then
30232 Set_Interface_Name (E, S);
30233 return;
30234
30235 else
30236 J := J + 1;
30237 end if;
30238 end loop;
30239
30240 -- Here we need to encode. The encoding we use as follows:
30241 -- three underscores + four hex digits (lower case)
30242
30243 Start_String;
30244
30245 for J in 1 .. String_Length (Str) loop
30246 CC := Get_String_Char (Str, J);
30247
30248 if not In_Character_Range (CC) then
30249 Encode;
30250 else
30251 C := Get_Character (CC);
30252
30253 if C = '_' or else C = '$'
30254 or else C in '0' .. '9'
30255 or else C in 'a' .. 'z'
30256 or else C in 'A' .. 'Z'
30257 then
30258 Store_String_Char (CC);
30259 else
30260 Encode;
30261 end if;
30262 end if;
30263 end loop;
30264
30265 Set_Interface_Name (E,
30266 Make_String_Literal (Sloc (S),
30267 Strval => End_String));
30268 end if;
30269 end Set_Encoded_Interface_Name;
30270
30271 ------------------------
30272 -- Set_Elab_Unit_Name --
30273 ------------------------
30274
30275 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
30276 Pref : Node_Id;
30277 Scop : Entity_Id;
30278
30279 begin
30280 if Nkind (N) = N_Identifier
30281 and then Nkind (With_Item) = N_Identifier
30282 then
30283 Set_Entity (N, Entity (With_Item));
30284
30285 elsif Nkind (N) = N_Selected_Component then
30286 Change_Selected_Component_To_Expanded_Name (N);
30287 Set_Entity (N, Entity (With_Item));
30288 Set_Entity (Selector_Name (N), Entity (N));
30289
30290 Pref := Prefix (N);
30291 Scop := Scope (Entity (N));
30292 while Nkind (Pref) = N_Selected_Component loop
30293 Change_Selected_Component_To_Expanded_Name (Pref);
30294 Set_Entity (Selector_Name (Pref), Scop);
30295 Set_Entity (Pref, Scop);
30296 Pref := Prefix (Pref);
30297 Scop := Scope (Scop);
30298 end loop;
30299
30300 Set_Entity (Pref, Scop);
30301 end if;
30302
30303 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
30304 end Set_Elab_Unit_Name;
30305
30306 -------------------
30307 -- Test_Case_Arg --
30308 -------------------
30309
30310 function Test_Case_Arg
30311 (Prag : Node_Id;
30312 Arg_Nam : Name_Id;
30313 From_Aspect : Boolean := False) return Node_Id
30314 is
30315 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
30316 Arg : Node_Id;
30317 Args : Node_Id;
30318
30319 begin
30320 pragma Assert (Nam_In (Arg_Nam, Name_Ensures,
30321 Name_Mode,
30322 Name_Name,
30323 Name_Requires));
30324
30325 -- The caller requests the aspect argument
30326
30327 if From_Aspect then
30328 if Present (Aspect)
30329 and then Nkind (Expression (Aspect)) = N_Aggregate
30330 then
30331 Args := Expression (Aspect);
30332
30333 -- "Name" and "Mode" may appear without an identifier as a
30334 -- positional association.
30335
30336 if Present (Expressions (Args)) then
30337 Arg := First (Expressions (Args));
30338
30339 if Present (Arg) and then Arg_Nam = Name_Name then
30340 return Arg;
30341 end if;
30342
30343 -- Skip "Name"
30344
30345 Arg := Next (Arg);
30346
30347 if Present (Arg) and then Arg_Nam = Name_Mode then
30348 return Arg;
30349 end if;
30350 end if;
30351
30352 -- Some or all arguments may appear as component associatons
30353
30354 if Present (Component_Associations (Args)) then
30355 Arg := First (Component_Associations (Args));
30356 while Present (Arg) loop
30357 if Chars (First (Choices (Arg))) = Arg_Nam then
30358 return Arg;
30359 end if;
30360
30361 Next (Arg);
30362 end loop;
30363 end if;
30364 end if;
30365
30366 -- Otherwise retrieve the argument directly from the pragma
30367
30368 else
30369 Arg := First (Pragma_Argument_Associations (Prag));
30370
30371 if Present (Arg) and then Arg_Nam = Name_Name then
30372 return Arg;
30373 end if;
30374
30375 -- Skip argument "Name"
30376
30377 Arg := Next (Arg);
30378
30379 if Present (Arg) and then Arg_Nam = Name_Mode then
30380 return Arg;
30381 end if;
30382
30383 -- Skip argument "Mode"
30384
30385 Arg := Next (Arg);
30386
30387 -- Arguments "Requires" and "Ensures" are optional and may not be
30388 -- present at all.
30389
30390 while Present (Arg) loop
30391 if Chars (Arg) = Arg_Nam then
30392 return Arg;
30393 end if;
30394
30395 Next (Arg);
30396 end loop;
30397 end if;
30398
30399 return Empty;
30400 end Test_Case_Arg;
30401
30402 end Sem_Prag;